Skip to content

Commit

Permalink
fix: Course outline tests (#56)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vladislavkeblysh authored and navinkarkera committed Nov 22, 2023
1 parent ab94d6d commit 86e5c97
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ describe('<EnableHighlightsModal />', () => {

const cancelButton = getByRole('button', { name: messages.cancelButton.defaultMessage });
fireEvent.click(cancelButton);
expect(closeMock).toHaveBeenCalledTimes(1);
expect(closeMock).toHaveBeenCalled();
});
});
12 changes: 6 additions & 6 deletions src/course-outline/outline-sidebar/OutlineSidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import React from 'react';
import PropTypes from 'prop-types';
import { Hyperlink } from '@edx/paragon';
import { useIntl } from '@edx/frontend-platform/i18n';
import { useSelector } from 'react-redux';

import HelpSidebar from '../../generic/help-sidebar';
import { getOutlineIndexData } from '../data/selectors';
import { useHelpUrls } from '../../help-urls/hooks';
import { getFormattedSidebarMessages } from './utils';

const OutlineSideBar = ({ courseId }) => {
const intl = useIntl();
const {
learnMoreGradingUrl,
learnMoreOutlineUrl,
learnMoreVisibilityUrl,
} = useSelector(getOutlineIndexData);
visibility: learnMoreVisibilityUrl,
grading: learnMoreGradingUrl,
outline: learnMoreOutlineUrl,
} = useHelpUrls(['visibility', 'grading', 'outline']);

const sidebarMessages = getFormattedSidebarMessages(
{
learnMoreGradingUrl,
Expand Down
4 changes: 2 additions & 2 deletions src/course-outline/status-bar/StatusBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useIntl } from '@edx/frontend-platform/i18n';
import { Button, Hyperlink, Stack } from '@edx/paragon';
import { AppContext } from '@edx/frontend-platform/react';

import { getPagePath } from '../../utils';
import messages from './messages';

const StatusBar = ({
Expand Down Expand Up @@ -33,6 +32,7 @@ const StatusBar = ({

const checkListTitle = `${completedCourseLaunchChecks + completedCourseBestPracticesChecks}/${totalCourseLaunchChecks + totalCourseBestPracticesChecks}`;
const checklistDestination = new URL(`checklists/${courseId}`, config.STUDIO_BASE_URL).href;
const scheduleDestination = new URL(`course/${courseId}/settings/details#schedule`, config.BASE_URL).href;

if (isLoading) {
// eslint-disable-next-line react/jsx-no-useless-fragment
Expand All @@ -45,7 +45,7 @@ const StatusBar = ({
<h5 className="h5">{intl.formatMessage(messages.startDateTitle)}</h5>
<Hyperlink
className="small"
destination={getPagePath(courseId, process.env.ENABLE_NEW_SCHEDULE_DETAILS_PAGE, 'settings/details#schedule')}
destination={scheduleDestination}
showLaunchIcon={false}
>
{courseReleaseDate}
Expand Down
46 changes: 36 additions & 10 deletions src/course-outline/status-bar/StatusBar.test.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import React from 'react';
import { render, fireEvent } 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 StatusBar from './StatusBar';
import messages from './messages';
import initializeStore from '../../store';

const courseId = 'course123';
let store;
const mockPathname = '/foo-bar';
const courseId = '123';
const isLoading = false;
const openEnableHighlightsModalMock = jest.fn();

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useLocation: () => ({
pathname: mockPathname,
}),
}));

const statusBarData = {
courseReleaseDate: 'Feb 05, 2013 at 05:00 UTC',
isSelfPaced: true,
Expand All @@ -23,18 +35,32 @@ const statusBarData = {
};

const renderComponent = (props) => render(
<IntlProvider locale="en">
<StatusBar
courseId={courseId}
isLoading={isLoading}
openEnableHighlightsModal={openEnableHighlightsModalMock}
statusBarData={statusBarData}
{...props}
/>
</IntlProvider>,
<AppProvider store={store} messages={{}}>
<IntlProvider locale="en">
<StatusBar
courseId={courseId}
isLoading={isLoading}
openEnableHighlightsModal={openEnableHighlightsModalMock}
statusBarData={statusBarData}
{...props}
/>
</IntlProvider>
</AppProvider>,
);

describe('<StatusBar />', () => {
beforeEach(() => {
initializeMockApp({
authenticatedUser: {
userId: 3,
username: 'abc123',
administrator: true,
roles: [],
},
});
store = initializeStore();
});

it('renders StatusBar component correctly', () => {
const { getByText } = renderComponent();

Expand Down

0 comments on commit 86e5c97

Please sign in to comment.