From a638cac07afb278ef8b4b514f693bedd7aa43527 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Mon, 11 Dec 2023 11:21:26 -0500 Subject: [PATCH] test: add tests for checking the API that sets the ordering --- src/course-outline/CourseOutline.test.jsx | 44 +++++++++++++++++++ .../section-card/SectionCard.jsx | 1 - 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/course-outline/CourseOutline.test.jsx b/src/course-outline/CourseOutline.test.jsx index 83c215f927..9b27bca1e9 100644 --- a/src/course-outline/CourseOutline.test.jsx +++ b/src/course-outline/CourseOutline.test.jsx @@ -31,6 +31,7 @@ import { fetchCourseSectionQuery, publishCourseSectionQuery, updateCourseSectionHighlightsQuery, + setSectionOrderListQuery, } from './data/thunk'; import initializeStore from '../store'; import { @@ -358,4 +359,47 @@ describe('', () => { expect(getByRole('button', { name: '5 Section highlights' })).toBeInTheDocument(); }); + + it('check section order list when set section order query is successful', async () => { + const { getAllByTestId } = render(); + 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(); + 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); + } + }); + }); }); diff --git a/src/course-outline/section-card/SectionCard.jsx b/src/course-outline/section-card/SectionCard.jsx index da56daf238..430bf85eb2 100644 --- a/src/course-outline/section-card/SectionCard.jsx +++ b/src/course-outline/section-card/SectionCard.jsx @@ -174,7 +174,6 @@ const SectionCard = ({ onEditSubmit={handleEditSubmit} isDisabledEditField={savingStatus === RequestStatus.IN_PROGRESS} onClickDuplicate={onDuplicateSubmit} - className="nodrag" />