From 7c7dee3c0ecd2441bbff5b5a468a0dd20edc34d1 Mon Sep 17 00:00:00 2001 From: Braden MacDonald Date: Wed, 11 Sep 2024 09:51:17 -0700 Subject: [PATCH] test: cleanups to AddContentContainer test (from review comments) --- .../add-content/AddContentContainer.test.tsx | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/library-authoring/add-content/AddContentContainer.test.tsx b/src/library-authoring/add-content/AddContentContainer.test.tsx index 5a386f01aa..f0f721c393 100644 --- a/src/library-authoring/add-content/AddContentContainer.test.tsx +++ b/src/library-authoring/add-content/AddContentContainer.test.tsx @@ -1,6 +1,7 @@ import { fireEvent, render, + screen, waitFor, initializeMocks, } from '../../testUtils'; @@ -18,15 +19,15 @@ describe('', () => { it('should render content buttons', () => { initializeMocks(); mockClipboardEmpty.applyMock(); - const doc = render(); - expect(doc.getByRole('button', { name: /collection/i })).toBeInTheDocument(); - expect(doc.getByRole('button', { name: /text/i })).toBeInTheDocument(); - expect(doc.getByRole('button', { name: /problem/i })).toBeInTheDocument(); - expect(doc.getByRole('button', { name: /open reponse/i })).toBeInTheDocument(); - expect(doc.getByRole('button', { name: /drag drop/i })).toBeInTheDocument(); - expect(doc.getByRole('button', { name: /video/i })).toBeInTheDocument(); - expect(doc.getByRole('button', { name: /advanced \/ other/i })).toBeInTheDocument(); - expect(doc.queryByRole('button', { name: /copy from clipboard/i })).not.toBeInTheDocument(); + render(); + expect(screen.getByRole('button', { name: /collection/i })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: /text/i })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: /problem/i })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: /open reponse/i })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: /drag drop/i })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: /video/i })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: /advanced \/ other/i })).toBeInTheDocument(); + expect(screen.queryByRole('button', { name: /copy from clipboard/i })).not.toBeInTheDocument(); }); it('should create a content', async () => { @@ -35,9 +36,9 @@ describe('', () => { const url = getCreateLibraryBlockUrl(libraryId); axiosMock.onPost(url).reply(200); - const doc = render(, renderOpts); + render(, renderOpts); - const textButton = doc.getByRole('button', { name: /text/i }); + const textButton = screen.getByRole('button', { name: /text/i }); fireEvent.click(textButton); await waitFor(() => expect(axiosMock.history.post[0].url).toEqual(url)); @@ -60,12 +61,11 @@ describe('', () => { const pasteUrl = getLibraryPasteClipboardUrl(libraryId); axiosMock.onPost(pasteUrl).reply(200); - const doc = render(, renderOpts); + render(, renderOpts); expect(getClipboardSpy).toHaveBeenCalled(); // Hmm, this is getting called four times! Refactor to use react-query. - await waitFor(() => expect(doc.queryByRole('button', { name: /paste from clipboard/i })).toBeInTheDocument()); - const pasteButton = doc.getByRole('button', { name: /paste from clipboard/i }); + const pasteButton = await screen.findByRole('button', { name: /paste from clipboard/i }); fireEvent.click(pasteButton); await waitFor(() => expect(axiosMock.history.post[0].url).toEqual(pasteUrl)); @@ -79,10 +79,9 @@ describe('', () => { const pasteUrl = getLibraryPasteClipboardUrl(libraryId); axiosMock.onPost(pasteUrl).reply(400); - const doc = render(, renderOpts); + render(, renderOpts); - await waitFor(() => expect(doc.queryByRole('button', { name: /paste from clipboard/i })).toBeInTheDocument()); - const pasteButton = doc.getByRole('button', { name: /paste from clipboard/i }); + const pasteButton = await screen.findByRole('button', { name: /paste from clipboard/i }); fireEvent.click(pasteButton); await waitFor(() => expect(axiosMock.history.post[0].url).toEqual(pasteUrl));