fix: display programs only if the url is configured (#479)
Removes the link of programs from the Header if the service is not configured.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import { logError } from '@edx/frontend-platform/logging';
|
||||
import { AppContext } from '@edx/frontend-platform/react';
|
||||
import { keyStore } from 'utils';
|
||||
import { RequestKeys } from 'data/constants/requests';
|
||||
@@ -10,9 +11,14 @@ import * as apiHooks from './api';
|
||||
|
||||
const reduxKeys = keyStore(reduxHooks);
|
||||
|
||||
jest.mock('@edx/frontend-platform/logging', () => ({
|
||||
logError: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('data/services/lms/utils', () => ({
|
||||
post: jest.fn((...args) => ({ post: args })),
|
||||
}));
|
||||
|
||||
jest.mock('data/services/lms/api', () => ({
|
||||
initializeList: jest.fn(),
|
||||
updateEntitlementEnrollment: jest.fn(),
|
||||
@@ -20,7 +26,9 @@ jest.mock('data/services/lms/api', () => ({
|
||||
deleteEntitlementEnrollment: jest.fn(),
|
||||
updateEmailSettings: jest.fn(),
|
||||
createCreditRequest: jest.fn(),
|
||||
getProgramsConfig: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('data/redux/hooks', () => ({
|
||||
useCardCourseRunData: jest.fn(),
|
||||
useCardCreditData: jest.fn(),
|
||||
@@ -110,6 +118,34 @@ describe('api hooks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('useProgramsConfig', () => {
|
||||
let mockState;
|
||||
const setState = jest.fn((newState) => { Object.assign(mockState, newState); });
|
||||
beforeEach(() => {
|
||||
mockState = {};
|
||||
React.useState.mockReturnValue([mockState, setState]);
|
||||
});
|
||||
|
||||
it('should return the programs configuration when the API call is successful', async () => {
|
||||
api.getProgramsConfig.mockResolvedValue({ data: { enabled: true } });
|
||||
const config = apiHooks.useProgramsConfig();
|
||||
const [cb] = React.useEffect.mock.calls[0];
|
||||
await cb();
|
||||
expect(setState).toHaveBeenCalled();
|
||||
expect(config).toEqual({ enabled: true });
|
||||
});
|
||||
|
||||
it('should return an empty object if the api call fails', async () => {
|
||||
mockState = {};
|
||||
api.getProgramsConfig.mockRejectedValue(new Error('error test'));
|
||||
const config = apiHooks.useProgramsConfig();
|
||||
const [cb] = React.useEffect.mock.calls[0];
|
||||
await cb();
|
||||
expect(config).toEqual({});
|
||||
expect(logError).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('entitlement enrollment hooks', () => {
|
||||
beforeEach(() => {
|
||||
jest.spyOn(apiHooks, moduleKeys.useInitializeApp).mockReturnValue(initializeApp);
|
||||
|
||||
Reference in New Issue
Block a user