Skip to content

Commit

Permalink
test: update test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Sep 10, 2024
1 parent 3ef8fce commit 0972265
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/editors/EditorContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const EditorContainer: React.FC<Props> = ({
}) => {
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 <div>Error: missing URL parameters</div>;
}
return (
Expand Down
1 change: 1 addition & 0 deletions src/library-authoring/LibraryAuthoringPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/library-authoring/LibraryLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions src/library-authoring/add-content/AddContentWorkflow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,21 @@ describe('AddContentWorkflow test', () => {
fireEvent.click(saveButton);
expect(saveSpy).toHaveBeenCalledTimes(1);
});

it('can create a Problem component', async () => {
render(<LibraryLayout />, 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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Props {
usageKey: string;
}

/* istanbul ignore next */
export const ComponentDeveloperInfo: React.FC<Props> = ({ usageKey }) => {
const { data: olx, isLoading: isOLXLoading } = useXBlockOLX(usageKey);
return (
Expand Down
1 change: 1 addition & 0 deletions src/library-authoring/data/apiHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 0972265

Please sign in to comment.