Skip to content

Commit

Permalink
test: improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Sep 17, 2024
1 parent 64be177 commit 8b5a4c6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/editors/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import type { EditorComponent } from './EditorComponent';

export interface Props extends EditorComponent {
blockType: string;
blockId?: string | null;
learningContextId?: string | null;
lmsEndpointUrl?: string | null;
studioEndpointUrl?: string | null;
blockId: string | null;
learningContextId: string | null;
lmsEndpointUrl: string | null;
studioEndpointUrl: string | null;
}

const Editor: React.FC<Props> = ({
learningContextId = null,
learningContextId,
blockType,
blockId = null,
lmsEndpointUrl = null,
studioEndpointUrl = null,
blockId,
lmsEndpointUrl,
studioEndpointUrl,
onClose = null,
returnFunction = null,
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import {
import messages from './messages';

interface Props {
selected: AdvancedProblemType | null;
selected: AdvancedProblemType;
setSelected: React.Dispatch<ProblemType | AdvancedProblemType>;
}

const AdvanceTypeSelect: React.FC<Props> = ({
selected = null,
selected,
setSelected,
}) => {
const intl = useIntl();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import 'CourseAuthoring/editors/setupEditorTest';
import React from 'react';

import { shallow } from '@edx/react-unit-test-utils';
import { ProblemTypeKeys } from '../../../../../data/constants/problem';
import ProblemTypeSelect from './ProblemTypeSelect';

describe('ProblemTypeSelect', () => {
const props = {
selected: null,
setSelected: jest.fn(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import messages from './messages';

interface Props {
selected: string;
selected: ProblemType;
setSelected: (selected: ProblemType | AdvancedProblemType) => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SelectTypeWrapper from './SelectTypeWrapper';
import * as hooks from './hooks';
import {
AdvancedProblemType,
AdvanceProblemKeys,
isAdvancedProblemType,
ProblemType,
ProblemTypeKeys,
} from '../../../../data/constants/problem';
Expand All @@ -26,12 +26,12 @@ const SelectTypeModal: React.FC<Props> = ({
return (
<SelectTypeWrapper onClose={onClose} selected={selected}>
<Row className="justify-content-center">
{(!Object.values(AdvanceProblemKeys).includes(selected as any)) ? (
{(!isAdvancedProblemType(selected)) ? (
<Stack direction="horizontal" gap={4} className="flex-wrap mb-6">
<ProblemTypeSelect selected={selected} setSelected={setSelected} />
<Preview problemType={selected} />
</Stack>
) : <AdvanceTypeSelect selected={selected as AdvancedProblemType} setSelected={setSelected} />}
) : <AdvanceTypeSelect selected={selected} setSelected={setSelected} />}
</Row>
</SelectTypeWrapper>
);
Expand Down
4 changes: 4 additions & 0 deletions src/editors/data/constants/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export const AdvanceProblemKeys = StrictDict({
} as const);
export type AdvancedProblemType = typeof AdvanceProblemKeys[keyof typeof AdvanceProblemKeys];

export function isAdvancedProblemType(pt: ProblemType | AdvancedProblemType): pt is AdvancedProblemType {
return Object.values(AdvanceProblemKeys).includes(pt as any);
}

export const AdvanceProblems = StrictDict({
[AdvanceProblemKeys.BLANK]: {
title: 'Blank problem',
Expand Down

0 comments on commit 8b5a4c6

Please sign in to comment.