Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Oct 2, 2024
1 parent 19df26f commit fe44d65
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
17 changes: 11 additions & 6 deletions src/course-outline/CourseOutline.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('<CourseOutline />', () => {
});

it('check video sharing option shows error on failure', async () => {
const { findByLabelText, queryByRole } = render(<RootWrapper />);
const { findByLabelText, queryAllByRole } = render(<RootWrapper />);

axiosMock
.onPost(getCourseBlockApiUrl(courseId), {
Expand All @@ -247,8 +247,10 @@ describe('<CourseOutline />', () => {
},
}));

const alertElement = queryByRole('alert');
expect(alertElement).toHaveTextContent(
const alertElements = queryAllByRole('alert');
expect(alertElements.find(
(el) => el.classList.contains('alert-content')

Check failure on line 252 in src/course-outline/CourseOutline.test.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Missing trailing comma
)).toHaveTextContent(
pageAlertMessages.alertFailedGeneric.defaultMessage,
);
});
Expand Down Expand Up @@ -511,8 +513,9 @@ describe('<CourseOutline />', () => {
notificationDismissUrl: '/some/url',
});

const { findByRole } = render(<RootWrapper />);
expect(await findByRole('alert')).toBeInTheDocument();
const { findByRole, findByText } = render(<RootWrapper />);
const alert = await findByText(pageAlertMessages.configurationErrorTitle.defaultMessage);
expect(alert).toBeInTheDocument();
const dismissBtn = await findByRole('button', { name: 'Dismiss' });
axiosMock
.onDelete('/some/url')
Expand Down Expand Up @@ -2233,8 +2236,10 @@ describe('<CourseOutline />', () => {
errorFiles: ['error.css'],
});

let alerts = await findAllByRole('alert');
// Exclude processing notification toast
alerts = alerts.filter((el) => !el.classList.contains('toast-container'));
// 3 alerts should be present
const alerts = await findAllByRole('alert');
expect(alerts.length).toEqual(3);

// check alerts for errorFiles
Expand Down
14 changes: 9 additions & 5 deletions src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,19 @@ describe('<CourseUnit />', () => {
});

it('should display a warning alert for unpublished course unit version', async () => {
const { getByRole } = render(<RootWrapper />);
const { getAllByRole } = render(<RootWrapper />);

await waitFor(() => {
const unpublishedAlert = getByRole('alert', { class: 'course-unit-unpublished-alert' });
const unpublishedAlert = getAllByRole('alert').find(
(el) => el.classList.contains('alert-content')

Check failure on line 532 in src/course-unit/CourseUnit.test.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Missing trailing comma
);
expect(unpublishedAlert).toHaveTextContent(messages.alertUnpublishedVersion.defaultMessage);
expect(unpublishedAlert).toHaveClass('alert-warning');
});
});

it('should not display an unpublished alert for a course unit with explicit staff lock and unpublished status', async () => {
const { queryByRole } = render(<RootWrapper />);
const { queryAllByRole } = render(<RootWrapper />);

axiosMock
.onGet(getCourseUnitApiUrl(courseId))
Expand All @@ -547,8 +549,10 @@ describe('<CourseUnit />', () => {
await executeThunk(fetchCourseUnitQuery(courseId), store.dispatch);

await waitFor(() => {
const unpublishedAlert = queryByRole('alert', { class: 'course-unit-unpublished-alert' });
expect(unpublishedAlert).toBeNull();
const alert = queryAllByRole('alert').find(
(el) => el.classList.contains('alert-content')

Check failure on line 553 in src/course-unit/CourseUnit.test.jsx

View workflow job for this annotation

GitHub Actions / tests (20)

Missing trailing comma
);
expect(alert).toBeUndefined();
});
});

Expand Down

0 comments on commit fe44d65

Please sign in to comment.