Skip to content

Commit 64aa28c

Browse files
test: fix completely broken tests
1 parent 6a07ead commit 64aa28c

2 files changed

Lines changed: 27 additions & 29 deletions

File tree

src/course-unit/CourseUnit.test.jsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,41 +2291,38 @@ describe('<CourseUnit />', () => {
22912291
});
22922292

22932293
it('renders and navigates to the new HTML XBlock editor after xblock duplicating', async () => {
2294-
render(<RootWrapper />);
22952294
const updatedCourseVerticalChildrenMock = JSON.parse(JSON.stringify(courseVerticalChildrenMock));
2296-
const targetBlockId = updatedCourseVerticalChildrenMock.children[1].block_id;
2297-
2298-
updatedCourseVerticalChildrenMock.children = updatedCourseVerticalChildrenMock.children
2299-
.map((child) => (child.block_id === targetBlockId
2300-
? { ...child, block_type: 'html' }
2301-
: child));
2295+
// Convert the second child from drag and drop to HTML:
2296+
const targetChild = updatedCourseVerticalChildrenMock.children[1];
2297+
targetChild.block_type = 'html';
2298+
targetChild.name = 'Test HTML Block';
2299+
targetChild.block_id = 'block-v1:OpenedX+L153+3T2023+type@html+block@test123original';
23022300

23032301
axiosMock
23042302
.onPost(postXBlockBaseApiUrl({
23052303
parent_locator: blockId,
2306-
duplicate_source_locator: courseVerticalChildrenMock.children[0].block_id,
2304+
duplicate_source_locator: targetChild.block_id,
23072305
}))
23082306
.replyOnce(200, { locator: '1234567890' });
23092307

23102308
axiosMock
23112309
.onGet(getCourseVerticalChildrenApiUrl(blockId))
23122310
.reply(200, updatedCourseVerticalChildrenMock);
23132311

2312+
render(<RootWrapper />);
23142313
await executeThunk(fetchCourseVerticalChildrenData(blockId), store.dispatch);
23152314

23162315
await waitFor(() => {
23172316
const iframe = screen.getByTitle(xblockContainerIframeMessages.xblockIframeTitle.defaultMessage);
23182317
expect(iframe).toBeInTheDocument();
2319-
simulatePostMessageEvent(messageTypes.currentXBlockId, {
2320-
id: targetBlockId,
2321-
});
23222318
});
23232319

2320+
// After duplicating, the editor modal will open:
2321+
expect(screen.queryByRole("dialog")).not.toBeInTheDocument()
2322+
simulatePostMessageEvent(messageTypes.duplicateXBlock, { usageId: targetChild.block_id });
2323+
simulatePostMessageEvent(messageTypes.newXBlockEditor, { blockType: 'html', usageId: targetChild.block_id });
23242324
await waitFor(() => {
2325-
simulatePostMessageEvent(messageTypes.duplicateXBlock, {});
2326-
simulatePostMessageEvent(messageTypes.newXBlockEditor, {});
2327-
expect(mockedUsedNavigate)
2328-
.toHaveBeenCalledWith(`/course/${courseId}/editor/html/${targetBlockId}`, { replace: true });
2325+
expect(screen.queryByRole("dialog")).toBeInTheDocument()
23292326
});
23302327
});
23312328

src/schedule-and-details/requirements-section/entrance-exam/EntranceExam.test.jsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import React from 'react';
21
import {
3-
render, fireEvent, waitFor,
2+
render, screen, waitFor,
43
} from '@testing-library/react';
4+
import userEvent from '@testing-library/user-event';
55
import { IntlProvider } from '@edx/frontend-platform/i18n';
66

77
import { courseDetailsMock } from '../../__mocks__';
8-
import gradeRequirementsMessages from '../grade-requirements/messages';
98
import messages from './messages';
109
import EntranceExam from '.';
1110

@@ -42,18 +41,20 @@ describe('<EntranceExam />', () => {
4241
});
4342

4443
it('should toggle grade requirements after checkbox click', async () => {
45-
const { getByText, queryAllByText, getAllByRole } = render(
46-
<RootWrapper {...props} />,
47-
);
48-
const checkbox = getAllByRole('checkbox')[0];
49-
expect(
50-
getByText(gradeRequirementsMessages.requirementsEntranceCollapseLabel.defaultMessage),
51-
).toBeInTheDocument();
52-
fireEvent.click(checkbox);
44+
onChangeMock.mockClear();
45+
const ui = render(<RootWrapper {...props} />);
46+
const user = userEvent.setup();
47+
const checkbox = screen.getByRole('checkbox', { name: 'Require students to pass an exam before beginning the course.' });
48+
49+
expect(checkbox).toBeChecked();
50+
expect(screen.queryByText('Grade requirements')).toBeInTheDocument();
51+
52+
await user.click(checkbox);
53+
expect(onChangeMock).toHaveBeenCalledWith('false', 'entranceExamEnabled');
54+
ui.rerender(<RootWrapper {...props} isCheckedString="false" />);
5355
await waitFor(() => {
54-
expect(
55-
queryAllByText(gradeRequirementsMessages.requirementsEntranceCollapseLabel.defaultMessage).length,
56-
).toBe(0);
56+
expect(checkbox).not.toBeChecked();
57+
expect(screen.queryByText('Grade requirements')).not.toBeInTheDocument();
5758
});
5859
});
5960
});

0 commit comments

Comments
 (0)