From 09722657e44588176674db00cbfd38a543cdeabb Mon Sep 17 00:00:00 2001 From: Braden MacDonald Date: Tue, 10 Sep 2024 10:35:18 -0700 Subject: [PATCH] test: update test coverage --- src/editors/EditorContainer.tsx | 2 +- src/library-authoring/LibraryAuthoringPage.tsx | 1 + src/library-authoring/LibraryLayout.tsx | 3 ++- .../add-content/AddContentWorkflow.test.tsx | 17 +++++++++++++++++ .../component-info/ComponentDeveloperInfo.tsx | 1 + src/library-authoring/data/apiHooks.ts | 1 + 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/editors/EditorContainer.tsx b/src/editors/EditorContainer.tsx index aaa8680b61..8d26f24901 100644 --- a/src/editors/EditorContainer.tsx +++ b/src/editors/EditorContainer.tsx @@ -21,7 +21,7 @@ const EditorContainer: React.FC = ({ }) => { const { blockType, blockId } = useParams(); if (blockType === undefined || blockId === undefined) { - // This shouldn't be possible; it's just here to satisfy the type checker. + // istanbul ignore next - This shouldn't be possible; it's just here to satisfy the type checker. return
Error: missing URL parameters
; } return ( diff --git a/src/library-authoring/LibraryAuthoringPage.tsx b/src/library-authoring/LibraryAuthoringPage.tsx index 9c5d85c629..6e5bbc647e 100644 --- a/src/library-authoring/LibraryAuthoringPage.tsx +++ b/src/library-authoring/LibraryAuthoringPage.tsx @@ -120,6 +120,7 @@ const LibraryAuthoringPage = () => { const { libraryId } = useParams(); if (!libraryId) { + // istanbul ignore next - This shouldn't be possible; it's just here to satisfy the type checker. throw new Error('Rendered without libraryId URL parameter'); } const { data: libraryData, isLoading } = useContentLibrary(libraryId); diff --git a/src/library-authoring/LibraryLayout.tsx b/src/library-authoring/LibraryLayout.tsx index 65ad125b92..f956f96533 100644 --- a/src/library-authoring/LibraryLayout.tsx +++ b/src/library-authoring/LibraryLayout.tsx @@ -18,7 +18,8 @@ const LibraryLayout = () => { const queryClient = useQueryClient(); if (libraryId === undefined) { - throw new Error('Error: route is missing libraryId.'); // Should never happen + // istanbul ignore next - This shouldn't be possible; it's just here to satisfy the type checker. + throw new Error('Error: route is missing libraryId.'); } const navigate = useNavigate(); diff --git a/src/library-authoring/add-content/AddContentWorkflow.test.tsx b/src/library-authoring/add-content/AddContentWorkflow.test.tsx index 555174e2fd..3216b89607 100644 --- a/src/library-authoring/add-content/AddContentWorkflow.test.tsx +++ b/src/library-authoring/add-content/AddContentWorkflow.test.tsx @@ -86,4 +86,21 @@ describe('AddContentWorkflow test', () => { fireEvent.click(saveButton); expect(saveSpy).toHaveBeenCalledTimes(1); }); + + it('can create a Problem component', async () => { + render(, renderOpts); + + // Click "New [Component]" + const newComponentButton = await screen.findByRole('button', { name: /New/ }); + fireEvent.click(newComponentButton); + + // Pre-condition - this is NOT shown yet: + expect(screen.queryByText('Content created successfully.')).not.toBeInTheDocument(); + + // Click "Problem" to create a capa problem component + fireEvent.click(await screen.findByRole('button', { name: /Problem/ })); + + // We haven't yet implemented the editor, so we expect only a toast to appear + expect(screen.findByText('Content created successfully.')).toBeInTheDocument(); + }); }); diff --git a/src/library-authoring/component-info/ComponentDeveloperInfo.tsx b/src/library-authoring/component-info/ComponentDeveloperInfo.tsx index 983b2034ea..430d9a7636 100644 --- a/src/library-authoring/component-info/ComponentDeveloperInfo.tsx +++ b/src/library-authoring/component-info/ComponentDeveloperInfo.tsx @@ -9,6 +9,7 @@ interface Props { usageKey: string; } +/* istanbul ignore next */ export const ComponentDeveloperInfo: React.FC = ({ usageKey }) => { const { data: olx, isLoading: isOLXLoading } = useXBlockOLX(usageKey); return ( diff --git a/src/library-authoring/data/apiHooks.ts b/src/library-authoring/data/apiHooks.ts index 1ffe488774..983a197819 100644 --- a/src/library-authoring/data/apiHooks.ts +++ b/src/library-authoring/data/apiHooks.ts @@ -242,6 +242,7 @@ export const useUpdateXBlockFields = (usageKey: string) => { }); }; +/* istanbul ignore next */ // This is only used in developer builds, and the associated UI doesn't work in test or prod export const useXBlockOLX = (usageKey: string) => ( useQuery({ queryKey: libraryAuthoringQueryKeys.xblockOLX(usageKey),