-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86cb5a2
commit bf3f8fb
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
|
||
import RedirectPage from './RedirectPage'; | ||
import { REDIRECT_MODES } from '../constants'; | ||
|
||
const BASE_URL = getConfig().LMS_BASE_URL; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useParams: () => ({ | ||
courseId: 'course-id-123', | ||
}), | ||
useLocation: () => ({ | ||
search: '?consentPath=/some-path', | ||
}), | ||
})); | ||
|
||
describe('RedirectPage component', () => { | ||
beforeEach(() => { | ||
Object.defineProperty(window, 'location', { | ||
writable: true, | ||
value: { assign: jest.fn() }, | ||
}); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should handle DASHBOARD_REDIRECT correctly', () => { | ||
render( | ||
<MemoryRouter> | ||
<RedirectPage mode={REDIRECT_MODES.DASHBOARD_REDIRECT} pattern="/dashboard" /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(global.location.assign).toHaveBeenCalledWith(`${BASE_URL}/dashboard?consentPath=/some-path`); | ||
}); | ||
|
||
it('should handle CONSENT_REDIRECT correctly', () => { | ||
render( | ||
<MemoryRouter> | ||
<RedirectPage mode={REDIRECT_MODES.CONSENT_REDIRECT} /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(global.location.assign).toHaveBeenCalledWith(`${BASE_URL}/some-path`); | ||
}); | ||
|
||
it('should handle HOME_REDIRECT correctly', () => { | ||
render( | ||
<MemoryRouter> | ||
<RedirectPage mode={REDIRECT_MODES.HOME_REDIRECT} pattern="/course/:courseId/home" /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(global.location.assign).toHaveBeenCalledWith('/course/course-id-123/home'); | ||
}); | ||
|
||
it('should handle the default case correctly', () => { | ||
render( | ||
<MemoryRouter> | ||
<RedirectPage pattern="/default/:courseId" /> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(global.location.assign).toHaveBeenCalledWith(`${BASE_URL}/default/course-id-123`); | ||
}); | ||
}); |