Skip to content

Commit

Permalink
fix: course redirect unit to sequnce unit redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
KristinAoki committed Oct 25, 2024
1 parent 501da9d commit a4b20c7
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/courseware/CoursewareContainer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,13 @@ describe('Course redirect functions', () => {

it('calls navigate with parentId and sequenceId', () => {
axiosMock.onGet(apiUrl).reply(200, {
parent: { id: 'sequence_1' },
blocks: {
id: 'sequence_1',
type: 'seuenctial',
children: ['unit_1'],
},
});

checkUnitToSequenceUnitRedirect(
'loaded',
'courseId',
Expand All @@ -696,6 +701,7 @@ describe('Course redirect functions', () => {
it('calls navigate to course page when getSequenceForUnitDeprecated errors', () => {
const getSequenceForUnitDeprecated = jest.fn();
axiosMock.onGet(apiUrl).reply(404);

checkUnitToSequenceUnitRedirect(
'loaded',
'courseId',
Expand All @@ -718,8 +724,9 @@ describe('Course redirect functions', () => {
it('calls navigate to course page when no parent id is returned', () => {
const getSequenceForUnitDeprecated = jest.fn();
axiosMock.onGet(apiUrl).reply(200, {
parent: { children: ['block_1'] },
block: { type: 'sequential', children: ['block_1'] },
});

checkUnitToSequenceUnitRedirect(
'loaded',
'courseId',
Expand All @@ -739,6 +746,28 @@ describe('Course redirect functions', () => {
});
});

it('calls navigate to course page when sequnce is not unit', () => {
const getSequenceForUnitDeprecated = jest.fn();

checkUnitToSequenceUnitRedirect(
'loaded',
'courseId',
'failed',
false,
'unit_1',
false,
null,
navigate,
true,
);
const expectedUrl = '/course/courseId';

waitFor(() => {
expect(getSequenceForUnitDeprecated).not.toHaveBeenCalled();
expect(navigate).toHaveBeenCalledWith(expectedUrl, { replace: true });
});
});

it('returns when course status is loading', () => {
checkUnitToSequenceUnitRedirect(
'loading',
Expand Down

0 comments on commit a4b20c7

Please sign in to comment.