Skip to content

Commit

Permalink
fix: increase code coverage on the page
Browse files Browse the repository at this point in the history
  • Loading branch information
vladislavkeblysh authored and navinkarkera committed Nov 22, 2023
1 parent 86e5c97 commit 8f32194
Show file tree
Hide file tree
Showing 13 changed files with 3,553 additions and 39 deletions.
105 changes: 98 additions & 7 deletions src/course-outline/CourseOutline.test.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import {
render, waitFor, cleanup,
} 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 } from './__mocks__';
import { getCourseOutlineIndexApiUrl } from './data/api';
import {
courseOutlineIndexMock,
courseBestPracticesMock,
courseLaunchMock,
} from './__mocks__';
import { executeThunk } from '../utils';
import CourseOutline from './CourseOutline';
import messages from './messages';

Expand All @@ -33,7 +53,7 @@ const RootWrapper = () => (
);

describe('<CourseOutline />', () => {
beforeEach(() => {
beforeEach(async () => {
initializeMockApp({
authenticatedUser: {
userId: 3,
Expand All @@ -45,18 +65,89 @@ describe('<CourseOutline />', () => {

store = initializeStore();
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
});

it('render CourseOutline component correctly', async () => {
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 enable highlights when enable highlights query is successfully', async () => {
cleanup();
const { getByText } = 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(getByText('Enabled')).toBeInTheDocument();
});
});
43 changes: 43 additions & 0 deletions src/course-outline/__mocks__/courseBestPractices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
isSelfPaced: false,
sections: {
totalNumber: 6,
totalVisible: 4,
numberWithHighlights: 2,
highlightsActiveForCourse: true,
highlightsEnabled: true,
},
subsections: {
totalVisible: 5,
numWithOneBlockType: 2,
numBlockTypes: {
min: 0,
max: 3,
mean: 1,
median: 1,
mode: 1,
},
},
units: {
totalVisible: 9,
numBlocks: {
min: 1,
max: 2,
mean: 2,
median: 2,
mode: 2,
},
},
videos: {
totalNumber: 7,
numMobileEncoded: 0,
numWithValId: 3,
durations: {
min: null,
max: null,
mean: null,
median: null,
mode: null,
},
},
};
31 changes: 31 additions & 0 deletions src/course-outline/__mocks__/courseLaunch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
isSelfPaced: false,
dates: {
hasStartDate: true,
hasEndDate: false,
},
assignments: {
totalNumber: 11,
totalVisible: 7,
assignmentsWithDatesBeforeStart: [],
assignmentsWithDatesAfterEnd: [],
assignmentsWithOraDatesBeforeStart: [],
assignmentsWithOraDatesAfterEnd: [],
},
grades: {
hasGradingPolicy: true,
sumOfWeights: 1,
},
certificates: {
isActivated: false,
hasCertificate: false,
isEnabled: true,
},
updates: {
hasUpdate: true,
},
proctoring: {
needsProctoringEscalationEmail: false,
hasProctoringEscalationEmail: false,
},
};
Loading

0 comments on commit 8f32194

Please sign in to comment.