Skip to content

Commit

Permalink
test: add tests for checking the API that sets the ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
steff456 committed Dec 11, 2023
1 parent 6760328 commit a638cac
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/course-outline/CourseOutline.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
fetchCourseSectionQuery,
publishCourseSectionQuery,
updateCourseSectionHighlightsQuery,
setSectionOrderListQuery,
} from './data/thunk';
import initializeStore from '../store';
import {
Expand Down Expand Up @@ -358,4 +359,47 @@ describe('<CourseOutline />', () => {

expect(getByRole('button', { name: '5 Section highlights' })).toBeInTheDocument();
});

it('check section order list when set section order query is successful', async () => {
const { getAllByTestId } = render(<RootWrapper />);
const courseBlockId = courseOutlineIndexMock.courseStructure.id;
let { children } = courseOutlineIndexMock.courseStructure.childInfo;
children = children.splice(2, 0, children.splice(0, 1)[0]);

axiosMock
.onPut(getEnableHighlightsEmailsApiUrl(courseBlockId), children)
.reply(200);

await executeThunk(setSectionOrderListQuery(courseBlockId, children, () => {}), store.dispatch);

await waitFor(() => {
expect(getAllByTestId('section-card')).toHaveLength(4);
const newSections = getAllByTestId('section-card');
for (let i; i < children.length; i++) {
expect(children[i].id === newSections[i].id);
}
});
});

it('check section order list when set section order query is unsuccessful', async () => {
const { getAllByTestId } = render(<RootWrapper />);
const courseBlockId = courseOutlineIndexMock.courseStructure.id;
const { children } = courseOutlineIndexMock.courseStructure.childInfo;
const newChildren = children.splice(2, 0, children.splice(0, 1)[0]);

axiosMock
.onPut(getEnableHighlightsEmailsApiUrl(courseBlockId), undefined)
.reply(500);

await executeThunk(setSectionOrderListQuery(courseBlockId, undefined, () => children), store.dispatch);

await waitFor(() => {
expect(getAllByTestId('section-card')).toHaveLength(4);
const newSections = getAllByTestId('section-card');
for (let i; i < children.length; i++) {
expect(children[i].id === newSections[i].id);
expect(newChildren[i].id !== newSections[i].id);
}
});
});
});
1 change: 0 additions & 1 deletion src/course-outline/section-card/SectionCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ const SectionCard = ({
onEditSubmit={handleEditSubmit}
isDisabledEditField={savingStatus === RequestStatus.IN_PROGRESS}
onClickDuplicate={onDuplicateSubmit}
className="nodrag"
/>
<div className="section-card__content" data-testid="section-card__content">
<div className="outline-section__status">
Expand Down

0 comments on commit a638cac

Please sign in to comment.