From 86e5c97c62cbc46051045aa4e016c7319ad2fddd Mon Sep 17 00:00:00 2001 From: vladislavkeblysh <138868841+vladislavkeblysh@users.noreply.github.com> Date: Tue, 15 Aug 2023 19:12:12 +0300 Subject: [PATCH] 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 --- .../EnableHighlightsModal.test.jsx | 2 +- .../outline-sidebar/OutlineSidebar.jsx | 12 ++--- src/course-outline/status-bar/StatusBar.jsx | 4 +- .../status-bar/StatusBar.test.jsx | 46 +++++++++++++++---- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/course-outline/enable-highlights-modal/EnableHighlightsModal.test.jsx b/src/course-outline/enable-highlights-modal/EnableHighlightsModal.test.jsx index ac68295d34..833631d034 100644 --- a/src/course-outline/enable-highlights-modal/EnableHighlightsModal.test.jsx +++ b/src/course-outline/enable-highlights-modal/EnableHighlightsModal.test.jsx @@ -50,6 +50,6 @@ describe('', () => { const cancelButton = getByRole('button', { name: messages.cancelButton.defaultMessage }); fireEvent.click(cancelButton); - expect(closeMock).toHaveBeenCalledTimes(1); + expect(closeMock).toHaveBeenCalled(); }); }); diff --git a/src/course-outline/outline-sidebar/OutlineSidebar.jsx b/src/course-outline/outline-sidebar/OutlineSidebar.jsx index c542daf2bf..7756ce006b 100644 --- a/src/course-outline/outline-sidebar/OutlineSidebar.jsx +++ b/src/course-outline/outline-sidebar/OutlineSidebar.jsx @@ -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, diff --git a/src/course-outline/status-bar/StatusBar.jsx b/src/course-outline/status-bar/StatusBar.jsx index 80b86f325e..d32edabaf1 100644 --- a/src/course-outline/status-bar/StatusBar.jsx +++ b/src/course-outline/status-bar/StatusBar.jsx @@ -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 = ({ @@ -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 @@ -45,7 +45,7 @@ const StatusBar = ({
{intl.formatMessage(messages.startDateTitle)}
{courseReleaseDate} diff --git a/src/course-outline/status-bar/StatusBar.test.jsx b/src/course-outline/status-bar/StatusBar.test.jsx index 038f546d55..ae7ce4e585 100644 --- a/src/course-outline/status-bar/StatusBar.test.jsx +++ b/src/course-outline/status-bar/StatusBar.test.jsx @@ -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, @@ -23,18 +35,32 @@ const statusBarData = { }; const renderComponent = (props) => render( - - - , + + + + + , ); describe('', () => { + beforeEach(() => { + initializeMockApp({ + authenticatedUser: { + userId: 3, + username: 'abc123', + administrator: true, + roles: [], + }, + }); + store = initializeStore(); + }); + it('renders StatusBar component correctly', () => { const { getByText } = renderComponent();