Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add redirect to enterprise learner dashboard #1251

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions global-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Force all tests to run in UTC to prevent tests from being sensitive to host timezone.
module.exports = async () => {
process.env.TZ = 'UTC';
};
Comment on lines +1 to +4
Copy link
Contributor Author

@pwnage101 pwnage101 Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spent 25 minutes scratching my head on a failing js test until I realized it was sensitive to the time zone of the host machine, and running TZ=UTC npm run test fixed it. This addition causes all tests to always run in UTC, regardless of host TZ.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, does setting process.env.TZ in the existing setupTest.js file work (in an attempt to avoid needing to setup the globalSetup config).

Copy link
Contributor Author

@pwnage101 pwnage101 Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it would have! I figured just do it for the whole project but happy to revert back to just doing it for one test class if you feel like it's too heavy-handed. This was the failing test (date off by one day):

https://github.com/openedx/frontend-app-learning/pull/1251/files#diff-729c9dcf69224055c50e2364be6ba2387aada65cd0929bf928271c8b3e1c561aR511

3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ module.exports = createConfig('jest', {
'react-markdown': '<rootDir>/node_modules/react-markdown/react-markdown.min.js',
},
testTimeout: 30000,
testEnvironment: 'jsdom'
testEnvironment: 'jsdom',
globalSetup: "./global-setup.js"
});
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ export const ROUTES = {
UNSUBSCRIBE: '/goal-unsubscribe/:token',
REDIRECT: '/redirect/*',
DASHBOARD: 'dashboard',
ENTERPRISE_LEARNER_DASHBOARD: 'enterprise-learner-dashboard',
CONSENT: 'consent',
};

export const REDIRECT_MODES = {
DASHBOARD_REDIRECT: 'dashboard-redirect',
ENTERPRISE_LEARNER_DASHBOARD_REDIRECT: 'enterprise-learner-dashboard-redirect',
CONSENT_REDIRECT: 'consent-redirect',
HOME_REDIRECT: 'home-redirect',
SURVEY_REDIRECT: 'survey-redirect',
Expand Down
7 changes: 7 additions & 0 deletions src/courseware/CoursewareContainer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -515,5 +515,12 @@ describe('CoursewareContainer', () => {
const startDate = '2/5/2013'; // This date is based on our courseMetadata factory's sample data.
expect(global.location.href).toEqual(`http://localhost/redirect/dashboard?notlive=${startDate}`);
});

it('should go to the enterprise learner dashboard for a course_not_started_enterprise_learner error code', async () => {
setUpWithDeniedStatus('course_not_started_enterprise_learner');
await loadContainer();

expect(global.location.href).toEqual('http://localhost/redirect/enterprise-learner-dashboard');
});
});
});
4 changes: 4 additions & 0 deletions src/courseware/CoursewareRedirectLandingPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const CoursewareRedirectLandingPage = () => (
path={ROUTES.DASHBOARD}
element={<PageWrap><RedirectPage pattern="/dashboard" mode={REDIRECT_MODES.DASHBOARD_REDIRECT} /></PageWrap>}
/>
<Route
path={ROUTES.ENTERPRISE_LEARNER_DASHBOARD}
element={<PageWrap><RedirectPage mode={REDIRECT_MODES.ENTERPRISE_LEARNER_DASHBOARD_REDIRECT} /></PageWrap>}
/>
<Route
path={ROUTES.CONSENT}
element={<PageWrap><RedirectPage mode={REDIRECT_MODES.CONSENT_REDIRECT} /></PageWrap>}
Expand Down
14 changes: 14 additions & 0 deletions src/courseware/CoursewareRedirectLandingPage.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { MemoryRouter as Router } from 'react-router-dom';
import { mergeConfig } from '@edx/frontend-platform';
import { render, initializeMockApp } from '../setupTest';
import CoursewareRedirectLandingPage from './CoursewareRedirectLandingPage';

Expand All @@ -11,6 +12,9 @@ jest.mock('../decode-page-route', () => jest.fn(({ children }) => <div>{children
describe('CoursewareRedirectLandingPage', () => {
beforeEach(async () => {
await initializeMockApp();
mergeConfig({
ENTERPRISE_LEARNER_PORTAL_URL: 'http://localhost:8734',
}, 'Add configs for URLs');
delete global.location;
global.location = { assign: redirectUrl };
});
Expand All @@ -34,4 +38,14 @@ describe('CoursewareRedirectLandingPage', () => {

expect(redirectUrl).toHaveBeenCalledWith('/course/course-v1:edX+DemoX+Demo_Course/home');
});

it('Redirects to correct enterprise dashboard URL', () => {
render(
<Router initialEntries={['/enterprise-learner-dashboard']}>
<CoursewareRedirectLandingPage />
</Router>,
);

expect(redirectUrl).toHaveBeenCalledWith('http://localhost:8734');
});
});
14 changes: 10 additions & 4 deletions src/courseware/RedirectPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@ const RedirectPage = ({
const location = useLocation();
const { consentPath } = queryString.parse(location?.search);

const BASE_URL = getConfig().LMS_BASE_URL;
const {
LMS_BASE_URL,
ENTERPRISE_LEARNER_PORTAL_URL,
} = getConfig();

switch (mode) {
case REDIRECT_MODES.DASHBOARD_REDIRECT:
global.location.assign(`${BASE_URL}${pattern}${location?.search}`);
global.location.assign(`${LMS_BASE_URL}${pattern}${location?.search}`);
break;
case REDIRECT_MODES.ENTERPRISE_LEARNER_DASHBOARD_REDIRECT:
global.location.assign(ENTERPRISE_LEARNER_PORTAL_URL);
break;
case REDIRECT_MODES.CONSENT_REDIRECT:
global.location.assign(`${BASE_URL}${consentPath}`);
global.location.assign(`${LMS_BASE_URL}${consentPath}`);
break;
case REDIRECT_MODES.HOME_REDIRECT:
global.location.assign(generatePath(pattern, { courseId }));
break;
default:
global.location.assign(`${BASE_URL}${generatePath(pattern, { courseId })}`);
global.location.assign(`${LMS_BASE_URL}${generatePath(pattern, { courseId })}`);
}

return null;
Expand Down
3 changes: 3 additions & 0 deletions src/shared/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export function getAccessDeniedRedirectUrl(courseId, activeTabSlug, courseAccess
const startDate = (new Intl.DateTimeFormat(getLocale())).format(new Date(start));
url = `/redirect/dashboard?notlive=${startDate}`;
break;
case 'course_not_started_enterprise_learner':
url = '/redirect/enterprise-learner-dashboard';
break;
case 'survey_required':
url = `/redirect/survey/${courseId}`;
break;
Expand Down