* feat: Course outline Top level page (#36) * feat: [2u-259] add components * feat: [2u-259] fix sidebar * feat: [2u-259] add tests, fix links * feat: [2u-259] fix messages * feat: [2u-159] fix reducer and sidebar * feat: [2u-259] fix reducer * feat: [2u-259] remove warning from selectors * feat: [2u-259] remove indents --------- Co-authored-by: Vladislav Keblysh <vladislavkeblysh@Vladislavs-MacBook-Pro.local> feat: Course outline Status Bar (#50) * feat: [2u-259] add components * feat: [2u-259] fix sidebar * feat: [2u-259] add tests, fix links * feat: [2u-259] fix messages * feat: [2u-159] fix reducer and sidebar * feat: add checklist * feat: [2u-259] fix reducer * feat: [2u-259] remove warning from selectors * feat: [2u-259] remove indents * feat: [2u-259] add api, enable modal * feat: [2u-259] add tests * feat: [2u-259] add translates * feat: [2u-271] fix transalates * feat: [2u-281] fix isQuery pending, utils, hooks * feat: [2u-281] fix useScrollToHashElement * feat: [2u-271] fix imports --------- Co-authored-by: Vladislav Keblysh <vladislavkeblysh@Vladislavs-MacBook-Pro.local> feat: Course Outline Reindex (#55) * feat: [2u-277] add alerts * feat: [2u-277] add translates * feat: [2u-277] fix tests * fix: [2u-277] fix slice and hook --------- Co-authored-by: Vladislav Keblysh <vladislavkeblysh@Vladislavs-MacBook-Pro.local> fix: Course outline tests (#56) * fix: fixed course outline status bar tests * fix: fixed course outline status bar tests * fix: fixed course outline enable highlights modal tests * fix: enable modal tests fix: increase code coverage on the page * refactor: improve course outline page feat: lms live link chore: update outline link fix: course outline link refactor: remove unnecessary css and rename test file refactor: remove unnecessary css from outlineSidebar test: make use of message variable instead of hardcoded text refactor: remove unnecessary h5 class test: use test id for detecting component refactor: update course outline url and some default messages --------- Co-authored-by: vladislavkeblysh <138868841+vladislavkeblysh@users.noreply.github.com>
151 lines
4.5 KiB
JavaScript
151 lines
4.5 KiB
JavaScript
import React from 'react';
|
|
import { render, waitFor } from '@testing-library/react';
|
|
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
|
import { AppProvider } from '@edx/frontend-platform/react';
|
|
import { initializeMockApp } from '@edx/frontend-platform';
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
|
|
|
import {
|
|
getCourseBestPracticesApiUrl,
|
|
getCourseLaunchApiUrl,
|
|
getCourseOutlineIndexApiUrl,
|
|
getCourseReindexApiUrl,
|
|
getEnableHighlightsEmailsApiUrl,
|
|
} from './data/api';
|
|
import {
|
|
enableCourseHighlightsEmailsQuery,
|
|
fetchCourseBestPracticesQuery,
|
|
fetchCourseLaunchQuery,
|
|
fetchCourseOutlineIndexQuery,
|
|
fetchCourseReindexQuery,
|
|
} from './data/thunk';
|
|
import initializeStore from '../store';
|
|
import {
|
|
courseOutlineIndexMock,
|
|
courseBestPracticesMock,
|
|
courseLaunchMock,
|
|
} from './__mocks__';
|
|
import { executeThunk } from '../utils';
|
|
import CourseOutline from './CourseOutline';
|
|
import messages from './messages';
|
|
|
|
let axiosMock;
|
|
let store;
|
|
const mockPathname = '/foo-bar';
|
|
const courseId = '123';
|
|
|
|
jest.mock('react-router-dom', () => ({
|
|
...jest.requireActual('react-router-dom'),
|
|
useLocation: () => ({
|
|
pathname: mockPathname,
|
|
}),
|
|
}));
|
|
|
|
const RootWrapper = () => (
|
|
<AppProvider store={store}>
|
|
<IntlProvider locale="en">
|
|
<CourseOutline courseId={courseId} />
|
|
</IntlProvider>
|
|
</AppProvider>
|
|
);
|
|
|
|
describe('<CourseOutline />', () => {
|
|
beforeEach(async () => {
|
|
initializeMockApp({
|
|
authenticatedUser: {
|
|
userId: 3,
|
|
username: 'abc123',
|
|
administrator: true,
|
|
roles: [],
|
|
},
|
|
});
|
|
|
|
store = initializeStore();
|
|
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
|
|
axiosMock
|
|
.onGet(getCourseOutlineIndexApiUrl(courseId))
|
|
.reply(200, courseOutlineIndexMock);
|
|
await executeThunk(fetchCourseOutlineIndexQuery(courseId), store.dispatch);
|
|
});
|
|
|
|
it('render CourseOutline component correctly', async () => {
|
|
const { getByText } = render(<RootWrapper />);
|
|
|
|
await waitFor(() => {
|
|
expect(getByText(messages.headingTitle.defaultMessage)).toBeInTheDocument();
|
|
expect(getByText(messages.headingSubtitle.defaultMessage)).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it('check reindex and render success alert is correctly', async () => {
|
|
const { getByText } = render(<RootWrapper />);
|
|
|
|
axiosMock
|
|
.onGet(getCourseReindexApiUrl(courseOutlineIndexMock.reindexLink))
|
|
.reply(200);
|
|
await executeThunk(fetchCourseReindexQuery(courseId, courseOutlineIndexMock.reindexLink), store.dispatch);
|
|
|
|
expect(getByText(messages.alertSuccessDescription.defaultMessage)).toBeInTheDocument();
|
|
});
|
|
|
|
it('render error alert after failed reindex correctly', async () => {
|
|
const { getByText } = render(<RootWrapper />);
|
|
|
|
axiosMock
|
|
.onGet(getCourseReindexApiUrl('some link'))
|
|
.reply(500);
|
|
await executeThunk(fetchCourseReindexQuery(courseId, 'some link'), store.dispatch);
|
|
|
|
expect(getByText(messages.alertErrorTitle.defaultMessage)).toBeInTheDocument();
|
|
});
|
|
|
|
it('render checklist value correctly', async () => {
|
|
const { getByText } = render(<RootWrapper />);
|
|
|
|
axiosMock
|
|
.onGet(getCourseBestPracticesApiUrl({
|
|
courseId, excludeGraded: true, all: true,
|
|
}))
|
|
.reply(200, courseBestPracticesMock);
|
|
|
|
axiosMock
|
|
.onGet(getCourseLaunchApiUrl({
|
|
courseId, gradedOnly: true, validateOras: true, all: true,
|
|
}))
|
|
.reply(200, courseLaunchMock);
|
|
|
|
await executeThunk(fetchCourseLaunchQuery({
|
|
courseId, gradedOnly: true, validateOras: true, all: true,
|
|
}), store.dispatch);
|
|
await executeThunk(fetchCourseBestPracticesQuery({
|
|
courseId, excludeGraded: true, all: true,
|
|
}), store.dispatch);
|
|
|
|
expect(getByText('4/9 completed')).toBeInTheDocument();
|
|
});
|
|
|
|
it('check highlights are enabled after enable highlights query is successful', async () => {
|
|
const { findByTestId } = render(<RootWrapper />);
|
|
|
|
axiosMock
|
|
.onGet(getCourseOutlineIndexApiUrl(courseId))
|
|
.reply(200, {
|
|
...courseOutlineIndexMock,
|
|
highlightsEnabledForMessaging: false,
|
|
});
|
|
|
|
axiosMock
|
|
.onPost(getEnableHighlightsEmailsApiUrl(courseId), {
|
|
publish: 'republish',
|
|
metadata: {
|
|
highlights_enabled_for_messaging: true,
|
|
},
|
|
})
|
|
.reply(200);
|
|
|
|
await executeThunk(enableCourseHighlightsEmailsQuery(courseId), store.dispatch);
|
|
expect(await findByTestId('highlights-enabled-span')).toBeInTheDocument();
|
|
});
|
|
});
|