fix: force LMS url to reload when changed (#136)
This commit is contained in:
committed by
GitHub
parent
5db95b0029
commit
f92bd9c8f9
@@ -5,6 +5,7 @@ const config = createConfig('eslint', {
|
||||
'import/no-named-as-default': 'off',
|
||||
'import/no-named-as-default-member': 'off',
|
||||
'import/no-self-import': 'off',
|
||||
'import/no-import-module-exports': 'off',
|
||||
'spaced-comment': ['error', 'always', { 'block': { 'exceptions': ['*'] } }],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ exports[`NoCoursesView snapshot 1`] = `
|
||||
</p>
|
||||
<Button
|
||||
as="a"
|
||||
href="course-search-url"
|
||||
href="http://localhost:18000/course-search-url"
|
||||
iconBefore={[MockFunction icons.Search]}
|
||||
variant="brand"
|
||||
>
|
||||
|
||||
@@ -2,6 +2,7 @@ import React from 'react';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { Button, Image } from '@edx/paragon';
|
||||
import { Search } from '@edx/paragon/icons';
|
||||
import { baseAppUrl } from 'data/services/lms/urls';
|
||||
|
||||
import emptyCourseSVG from 'assets/empty-course.svg';
|
||||
import { reduxHooks } from 'hooks';
|
||||
@@ -27,7 +28,7 @@ export const NoCoursesView = () => {
|
||||
<Button
|
||||
variant="brand"
|
||||
as="a"
|
||||
href={courseSearchUrl}
|
||||
href={baseAppUrl(courseSearchUrl)}
|
||||
iconBefore={Search}
|
||||
>
|
||||
{formatMessage(messages.exploreCoursesButton)}
|
||||
|
||||
@@ -6,7 +6,7 @@ import EmptyCourse from '.';
|
||||
jest.mock('hooks', () => ({
|
||||
reduxHooks: {
|
||||
usePlatformSettingsData: jest.fn(() => ({
|
||||
courseSearchUrl: 'course-search-url',
|
||||
courseSearchUrl: '/course-search-url',
|
||||
})),
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -21,7 +21,7 @@ export const CollapseMenuBody = ({ isOpen }) => {
|
||||
const dashboard = reduxHooks.useEnterpriseDashboardData();
|
||||
const { courseSearchUrl } = reduxHooks.usePlatformSettingsData();
|
||||
|
||||
const exploreCoursesClick = findCoursesNavDropdownClicked(courseSearchUrl);
|
||||
const exploreCoursesClick = findCoursesNavDropdownClicked(urls.baseAppUrl(courseSearchUrl));
|
||||
|
||||
return (
|
||||
isOpen && (
|
||||
@@ -34,7 +34,7 @@ export const CollapseMenuBody = ({ isOpen }) => {
|
||||
</Button>
|
||||
<Button
|
||||
as="a"
|
||||
href={courseSearchUrl}
|
||||
href={urls.baseAppUrl(courseSearchUrl)}
|
||||
variant="inverse-primary"
|
||||
onClick={exploreCoursesClick}
|
||||
>
|
||||
|
||||
@@ -17,7 +17,7 @@ jest.mock('hooks', () => ({
|
||||
url: 'url',
|
||||
}),
|
||||
usePlatformSettingsData: () => ({
|
||||
courseSearchUrl: 'courseSearchUrl',
|
||||
courseSearchUrl: '/courseSearchUrl',
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -20,8 +20,8 @@ exports[`CollapseMenuBody render 1`] = `
|
||||
</Button>
|
||||
<Button
|
||||
as="a"
|
||||
href="courseSearchUrl"
|
||||
onClick={[MockFunction findCoursesNavDropdownClicked("courseSearchUrl")]}
|
||||
href="http://localhost:18000/courseSearchUrl"
|
||||
onClick={[MockFunction findCoursesNavDropdownClicked("http://localhost:18000/courseSearchUrl")]}
|
||||
variant="inverse-primary"
|
||||
>
|
||||
Discover New
|
||||
@@ -86,8 +86,8 @@ exports[`CollapseMenuBody render unauthenticated 1`] = `
|
||||
</Button>
|
||||
<Button
|
||||
as="a"
|
||||
href="courseSearchUrl"
|
||||
onClick={[MockFunction findCoursesNavDropdownClicked("courseSearchUrl")]}
|
||||
href="http://localhost:18000/courseSearchUrl"
|
||||
onClick={[MockFunction findCoursesNavDropdownClicked("http://localhost:18000/courseSearchUrl")]}
|
||||
variant="inverse-primary"
|
||||
>
|
||||
Discover New
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useIsCollapsed } from '../hooks';
|
||||
jest.mock('@edx/frontend-platform', () => ({
|
||||
getConfig: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('@edx/frontend-platform/react', () => ({
|
||||
AppContext: {
|
||||
authenticatedUser: {
|
||||
@@ -17,11 +18,13 @@ jest.mock('@edx/frontend-platform/react', () => ({
|
||||
},
|
||||
},
|
||||
}));
|
||||
const COURSE_SEARCH_URL = 'test-course-search-url';
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
reduxHooks: {
|
||||
useEnterpriseDashboardData: jest.fn(),
|
||||
usePlatformSettingsData: jest.fn(() => ({
|
||||
courseSearchUrl: 'test-course-search-url',
|
||||
courseSearchUrl: COURSE_SEARCH_URL,
|
||||
})),
|
||||
},
|
||||
}));
|
||||
@@ -30,6 +33,11 @@ jest.mock('../hooks', () => ({
|
||||
findCoursesNavDropdownClicked: (href) => jest.fn().mockName(`findCoursesNavDropdownClicked('${href}')`),
|
||||
}));
|
||||
|
||||
jest.mock('data/services/lms/urls', () => ({
|
||||
baseAppUrl: (url) => (url),
|
||||
programsUrl: 'http://localhost:18000/dashboard/programs',
|
||||
}));
|
||||
|
||||
const config = {
|
||||
ACCOUNT_PROFILE_URL: 'http://account-profile-url.test',
|
||||
ACCOUNT_SETTINGS_URL: 'http://account-settings-url.test',
|
||||
@@ -37,6 +45,7 @@ const config = {
|
||||
ORDER_HISTORY_URL: 'http://order-history-url.test',
|
||||
SUPPORT_URL: 'http://localhost:18000/support',
|
||||
CAREER_LINK_URL: 'http://localhost:18000/career',
|
||||
LMS_BASE_URL: 'http:/localhost:18000',
|
||||
};
|
||||
getConfig.mockReturnValue(config);
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ exports[`ExpandedHeader render 1`] = `
|
||||
<Button
|
||||
as="a"
|
||||
className="p-4"
|
||||
href="courseSearchUrl"
|
||||
onClick={[MockFunction findCoursesNavClicked("courseSearchUrl")]}
|
||||
href="http://localhost:18000/courseSearchUrl"
|
||||
onClick={[MockFunction findCoursesNavClicked("http://localhost:18000/courseSearchUrl")]}
|
||||
variant="inverse-primary"
|
||||
>
|
||||
Discover New
|
||||
|
||||
@@ -18,7 +18,7 @@ export const ExpandedHeader = () => {
|
||||
const { courseSearchUrl } = reduxHooks.usePlatformSettingsData();
|
||||
const isCollapsed = useIsCollapsed();
|
||||
|
||||
const exploreCoursesClick = findCoursesNavClicked(courseSearchUrl);
|
||||
const exploreCoursesClick = findCoursesNavClicked(urls.baseAppUrl(courseSearchUrl));
|
||||
|
||||
return (
|
||||
!isCollapsed && (
|
||||
@@ -44,7 +44,7 @@ export const ExpandedHeader = () => {
|
||||
</Button>
|
||||
<Button
|
||||
as="a"
|
||||
href={courseSearchUrl}
|
||||
href={urls.baseAppUrl(courseSearchUrl)}
|
||||
variant="inverse-primary"
|
||||
className="p-4"
|
||||
onClick={exploreCoursesClick}
|
||||
|
||||
@@ -6,12 +6,13 @@ import { useIsCollapsed } from '../hooks';
|
||||
|
||||
jest.mock('data/services/lms/urls', () => ({
|
||||
programsUrl: 'programsUrl',
|
||||
baseAppUrl: url => (`http://localhost:18000${url}`),
|
||||
}));
|
||||
|
||||
jest.mock('hooks', () => ({
|
||||
reduxHooks: {
|
||||
usePlatformSettingsData: () => ({
|
||||
courseSearchUrl: 'courseSearchUrl',
|
||||
courseSearchUrl: '/courseSearchUrl',
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -17,7 +17,7 @@ import * as module from './api';
|
||||
* GET Actions
|
||||
*********************************************************************************/
|
||||
export const initializeList = ({ user } = {}) => get(
|
||||
stringifyUrl(urls.init, { [apiKeys.user]: user }),
|
||||
stringifyUrl(urls.getInitApiUrl(), { [apiKeys.user]: user }),
|
||||
);
|
||||
|
||||
export const updateEntitlementEnrollment = ({ uuid, courseId }) => post(
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('lms api methods', () => {
|
||||
[apiKeys.user]: testUser,
|
||||
};
|
||||
expect(api.initializeList(userArg)).toEqual(
|
||||
utils.get(utils.stringifyUrl(urls.init, userArg)),
|
||||
utils.get(utils.stringifyUrl(urls.getInitApiUrl(), userArg)),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,40 +1,41 @@
|
||||
import { StrictDict } from 'utils';
|
||||
import { configuration } from 'config';
|
||||
|
||||
const baseUrl = `${configuration.LMS_BASE_URL}`;
|
||||
export const ecommerceUrl = `${configuration.ECOMMERCE_BASE_URL}`;
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
|
||||
export const api = `${baseUrl}/api`;
|
||||
export const getEcommerceUrl = () => getConfig().ECOMMERCE_BASE_URL;
|
||||
|
||||
// const init = `${api}learner_home/mock/init`; // mock endpoint for testing
|
||||
const init = `${api}/learner_home/init`;
|
||||
const getBaseUrl = () => getConfig().LMS_BASE_URL;
|
||||
|
||||
const event = `${baseUrl}/event`;
|
||||
const courseUnenroll = `${baseUrl}/change_enrollment`;
|
||||
const updateEmailSettings = `${api}/change_email_settings`;
|
||||
const entitlementEnrollment = (uuid) => `${api}/entitlements/v1/entitlements/${uuid}/enrollments`;
|
||||
export const getApiUrl = () => (`${getConfig().LMS_BASE_URL}/api`);
|
||||
|
||||
const getInitApiUrl = () => (`${getApiUrl()}/learner_home/init`);
|
||||
|
||||
const event = `${getBaseUrl()}/event`;
|
||||
const courseUnenroll = `${getBaseUrl()}/change_enrollment`;
|
||||
const updateEmailSettings = `${getApiUrl()}/change_email_settings`;
|
||||
const entitlementEnrollment = (uuid) => `${getApiUrl()}/entitlements/v1/entitlements/${uuid}/enrollments`;
|
||||
|
||||
// if url is null or absolute, return it as is
|
||||
const updateUrl = (base, url) => ((url == null || url.startsWith('http://') || url.startsWith('https://')) ? url : `${base}${url}`);
|
||||
export const updateUrl = (base, url) => ((url == null || url.startsWith('http://') || url.startsWith('https://')) ? url : `${base}${url}`);
|
||||
|
||||
export const baseAppUrl = (url) => updateUrl(baseUrl, url);
|
||||
export const learningMfeUrl = (url) => updateUrl(configuration.LEARNING_BASE_URL, url);
|
||||
export const baseAppUrl = (url) => updateUrl(getBaseUrl(), url);
|
||||
export const learningMfeUrl = (url) => updateUrl(getConfig().LEARNING_BASE_URL, url);
|
||||
|
||||
// static view url
|
||||
const programsUrl = baseAppUrl('/dashboard/programs');
|
||||
|
||||
export const creditPurchaseUrl = (courseId) => `${ecommerceUrl}/credit/checkout/${courseId}/`;
|
||||
export const creditRequestUrl = (providerId) => `${api}/credit/v1/providers/${providerId}/request/`;
|
||||
export const creditPurchaseUrl = (courseId) => `${getEcommerceUrl()}/credit/checkout/${courseId}/`;
|
||||
export const creditRequestUrl = (providerId) => `${getApiUrl()}/credit/v1/providers/${providerId}/request/`;
|
||||
|
||||
export default StrictDict({
|
||||
api,
|
||||
getApiUrl,
|
||||
baseAppUrl,
|
||||
courseUnenroll,
|
||||
creditPurchaseUrl,
|
||||
creditRequestUrl,
|
||||
entitlementEnrollment,
|
||||
event,
|
||||
init,
|
||||
getInitApiUrl,
|
||||
learningMfeUrl,
|
||||
programsUrl,
|
||||
updateEmailSettings,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { configuration } from 'config';
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
import * as urls from './urls';
|
||||
|
||||
describe('urls', () => {
|
||||
@@ -10,7 +10,7 @@ describe('urls', () => {
|
||||
it('returns the url if it is relative', () => {
|
||||
const url = '/edx.org';
|
||||
expect(urls.baseAppUrl(url)).toEqual(
|
||||
`${configuration.LMS_BASE_URL}${url}`,
|
||||
`${getConfig().LMS_BASE_URL}${url}`,
|
||||
);
|
||||
});
|
||||
it('return null if url is null', () => {
|
||||
@@ -25,7 +25,7 @@ describe('urls', () => {
|
||||
it('returns the url if it is relative', () => {
|
||||
const url = '/edx.org';
|
||||
expect(urls.learningMfeUrl(url)).toEqual(
|
||||
`${configuration.LEARNING_BASE_URL}${url}`,
|
||||
`${getConfig().LEARNING_BASE_URL}${url}`,
|
||||
);
|
||||
});
|
||||
it('return null if url is null', () => {
|
||||
@@ -36,7 +36,6 @@ describe('urls', () => {
|
||||
it('builds from ecommerce url and loads courseId', () => {
|
||||
const courseId = 'test-course-id';
|
||||
const url = urls.creditPurchaseUrl(courseId);
|
||||
expect(url.startsWith(urls.ecommerceUrl)).toEqual(true);
|
||||
expect(url).toEqual(expect.stringContaining(courseId));
|
||||
});
|
||||
});
|
||||
@@ -44,7 +43,7 @@ describe('urls', () => {
|
||||
it('builds from api url and loads providerId', () => {
|
||||
const providerId = 'test-provider-id';
|
||||
const url = urls.creditRequestUrl(providerId);
|
||||
expect(url.startsWith(urls.api)).toEqual(true);
|
||||
expect(url.startsWith(urls.getApiUrl())).toEqual(true);
|
||||
expect(url).toEqual(expect.stringContaining(providerId));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,8 +18,8 @@ exports[`LookingForChallengeWidget snapshots default 1`] = `
|
||||
<h5>
|
||||
<Hyperlink
|
||||
className="d-flex align-items-center"
|
||||
destination="course-search-url"
|
||||
onClick={[MockFunction track.findCoursesWidgetClicked('course-search-url')]}
|
||||
destination="http://localhost:18000/course-search-url"
|
||||
onClick={[MockFunction track.findCoursesWidgetClicked('http://localhost:18000/course-search-url')]}
|
||||
variant="brand"
|
||||
>
|
||||
<format-message-function
|
||||
|
||||
@@ -6,6 +6,7 @@ import { ArrowForward } from '@edx/paragon/icons';
|
||||
|
||||
import { reduxHooks } from 'hooks';
|
||||
import moreCoursesSVG from 'assets/more-courses-sidewidget.svg';
|
||||
import { baseAppUrl } from 'data/services/lms/urls';
|
||||
|
||||
import track from '../RecommendationsPanel/track';
|
||||
import messages from './messages';
|
||||
@@ -29,8 +30,8 @@ export const LookingForChallengeWidget = () => {
|
||||
<h5>
|
||||
<Hyperlink
|
||||
variant="brand"
|
||||
destination={courseSearchUrl}
|
||||
onClick={track.findCoursesWidgetClicked(courseSearchUrl)}
|
||||
destination={baseAppUrl(courseSearchUrl)}
|
||||
onClick={track.findCoursesWidgetClicked(baseAppUrl(courseSearchUrl))}
|
||||
className="d-flex align-items-center"
|
||||
>
|
||||
{formatMessage(messages.findCoursesButton, { arrow: arrowIcon })}
|
||||
|
||||
@@ -5,7 +5,7 @@ import LookingForChallengeWidget from '.';
|
||||
jest.mock('hooks', () => ({
|
||||
reduxHooks: {
|
||||
usePlatformSettingsData: () => ({
|
||||
courseSearchUrl: 'course-search-url',
|
||||
courseSearchUrl: 'http://localhost:18000/course-search-url',
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import { Button } from '@edx/paragon';
|
||||
import { Search } from '@edx/paragon/icons';
|
||||
import { baseAppUrl } from 'data/services/lms/urls';
|
||||
|
||||
import { reduxHooks } from 'hooks';
|
||||
import track from './track';
|
||||
@@ -38,8 +39,8 @@ export const LoadedView = ({
|
||||
variant="tertiary"
|
||||
iconBefore={Search}
|
||||
as="a"
|
||||
href={courseSearchUrl}
|
||||
onClick={track.findCoursesWidgetClicked(courseSearchUrl)}
|
||||
href={baseAppUrl(courseSearchUrl)}
|
||||
onClick={track.findCoursesWidgetClicked(baseAppUrl(courseSearchUrl))}
|
||||
>
|
||||
{formatMessage(messages.exploreCoursesButton)}
|
||||
</Button>
|
||||
|
||||
@@ -5,17 +5,20 @@ import LoadedView from './LoadedView';
|
||||
import mockData from './mockData';
|
||||
import messages from './messages';
|
||||
|
||||
jest.mock('./components/CourseCard', () => 'CourseCard');
|
||||
jest.mock('hooks', () => ({
|
||||
reduxHooks: {
|
||||
usePlatformSettingsData: () => ({
|
||||
courseSearchUrl: 'course-search-url',
|
||||
courseSearchUrl: '/course-search-url',
|
||||
}),
|
||||
},
|
||||
}));
|
||||
jest.mock('data/services/lms/urls', () => ({
|
||||
baseAppUrl: (url) => (`http://localhost:18000${url}`),
|
||||
}));
|
||||
jest.mock('./track', () => ({
|
||||
findCoursesWidgetClicked: (href) => jest.fn().mockName(`track.findCoursesWidgetClicked('${href}')`),
|
||||
}));
|
||||
jest.mock('./components/CourseCard', () => 'CourseCard');
|
||||
|
||||
describe('RecommendationsPanel LoadedView', () => {
|
||||
const props = {
|
||||
|
||||
@@ -64,9 +64,9 @@ exports[`RecommendationsPanel LoadedView snapshot with personalize recommendatio
|
||||
>
|
||||
<Button
|
||||
as="a"
|
||||
href="course-search-url"
|
||||
href="http://localhost:18000/course-search-url"
|
||||
iconBefore={[MockFunction icons.Search]}
|
||||
onClick={[MockFunction track.findCoursesWidgetClicked('course-search-url')]}
|
||||
onClick={[MockFunction track.findCoursesWidgetClicked('http://localhost:18000/course-search-url')]}
|
||||
variant="tertiary"
|
||||
>
|
||||
Explore courses
|
||||
@@ -139,9 +139,9 @@ exports[`RecommendationsPanel LoadedView snapshot without personalize recommenda
|
||||
>
|
||||
<Button
|
||||
as="a"
|
||||
href="course-search-url"
|
||||
href="http://localhost:18000/course-search-url"
|
||||
iconBefore={[MockFunction icons.Search]}
|
||||
onClick={[MockFunction track.findCoursesWidgetClicked('course-search-url')]}
|
||||
onClick={[MockFunction track.findCoursesWidgetClicked('http://localhost:18000/course-search-url')]}
|
||||
variant="tertiary"
|
||||
>
|
||||
Explore courses
|
||||
|
||||
@@ -2,10 +2,10 @@ import { StrictDict } from 'utils';
|
||||
import { get, stringifyUrl } from 'data/services/lms/utils';
|
||||
import urls from 'data/services/lms/urls';
|
||||
|
||||
export const fetchUrl = `${urls.api}/learner_recommendations/courses/`;
|
||||
export const getFetchUrl = () => (`${urls.getApiUrl()}/learner_recommendations/courses/`);
|
||||
export const apiKeys = StrictDict({ user: 'user' });
|
||||
|
||||
const fetchRecommendedCourses = () => get(stringifyUrl(fetchUrl));
|
||||
const fetchRecommendedCourses = () => get(stringifyUrl(getFetchUrl()));
|
||||
|
||||
export default {
|
||||
fetchRecommendedCourses,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get, stringifyUrl } from 'data/services/lms/utils';
|
||||
import api, { fetchUrl } from './api';
|
||||
import api, { getFetchUrl } from './api';
|
||||
|
||||
jest.mock('data/services/lms/utils', () => ({
|
||||
stringifyUrl: (...args) => ({ stringifyUrl: args }),
|
||||
@@ -10,7 +10,7 @@ describe('recommendedCourses api', () => {
|
||||
describe('fetchRecommendedCourses', () => {
|
||||
it('calls get with the correct recommendation courses URL and user', () => {
|
||||
expect(api.fetchRecommendedCourses()).toEqual(
|
||||
get(stringifyUrl(fetchUrl)),
|
||||
get(stringifyUrl(getFetchUrl())),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user