Skip to content

Commit 64d718d

Browse files
fix: Use soft nav when clicking a library from studio home (#1306)
1 parent 353ef50 commit 64d718d

File tree

19 files changed

+282
-351
lines changed

19 files changed

+282
-351
lines changed

src/generic/alert-message/index.jsx

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/generic/alert-message/index.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import { Alert } from '@openedx/paragon';
3+
4+
interface Props extends React.ComponentPropsWithoutRef<typeof Alert> {
5+
title?: string | React.ReactNode;
6+
description?: string | React.ReactNode;
7+
}
8+
9+
const AlertMessage: React.FC<Props> = ({ title, description, ...props }) => (
10+
<Alert {...props}>
11+
<Alert.Heading>{title}</Alert.Heading>
12+
<span>{description}</span>
13+
</Alert>
14+
);
15+
16+
export default AlertMessage;

src/studio-home/StudioHome.jsx renamed to src/studio-home/StudioHome.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Row,
99
} from '@openedx/paragon';
1010
import { Add as AddIcon, Error } from '@openedx/paragon/icons';
11-
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
11+
import { useIntl } from '@edx/frontend-platform/i18n';
1212
import { StudioFooter } from '@edx/frontend-component-footer';
1313
import { getConfig } from '@edx/frontend-platform';
1414
import { useLocation, useNavigate } from 'react-router-dom';
@@ -28,7 +28,8 @@ import messages from './messages';
2828
import { useStudioHome } from './hooks';
2929
import AlertMessage from '../generic/alert-message';
3030

31-
const StudioHome = ({ intl }) => {
31+
const StudioHome = () => {
32+
const intl = useIntl();
3233
const location = useLocation();
3334
const navigate = useNavigate();
3435

@@ -46,7 +47,6 @@ const StudioHome = ({ intl }) => {
4647
hasAbilityToCreateNewCourse,
4748
isFiltered,
4849
setShowNewCourseContainer,
49-
dispatch,
5050
} = useStudioHome(isPaginationCoursesEnabled);
5151

5252
const libMode = getConfig().LIBRARY_MODE;
@@ -64,7 +64,7 @@ const StudioHome = ({ intl }) => {
6464
} = studioHomeData;
6565

6666
const getHeaderButtons = useCallback(() => {
67-
const headerButtons = [];
67+
const headerButtons: JSX.Element[] = [];
6868

6969
if (isFailedLoadingPage || !userIsActive) {
7070
return headerButtons;
@@ -160,11 +160,9 @@ const StudioHome = ({ intl }) => {
160160
)}
161161
{isShowOrganizationDropdown && <OrganizationSection />}
162162
<TabsSection
163-
tabsData={studioHomeData}
164163
showNewCourseContainer={showNewCourseContainer}
165164
onClickNewCourse={() => setShowNewCourseContainer(true)}
166165
isShowProcessing={isShowProcessing && !isFiltered}
167-
dispatch={dispatch}
168166
isPaginationCoursesEnabled={isPaginationCoursesEnabled}
169167
/>
170168
</section>
@@ -203,8 +201,4 @@ const StudioHome = ({ intl }) => {
203201
);
204202
};
205203

206-
StudioHome.propTypes = {
207-
intl: intlShape.isRequired,
208-
};
209-
210-
export default injectIntl(StudioHome);
204+
export default StudioHome;

src/studio-home/card-item/CardItem.test.jsx

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import * as reactRedux from 'react-redux';
2+
import { getConfig } from '@edx/frontend-platform';
3+
4+
import { studioHomeMock } from '../__mocks__';
5+
import messages from '../messages';
6+
import { trimSlashes } from './utils';
7+
import {
8+
fireEvent,
9+
initializeMocks,
10+
render,
11+
screen,
12+
} from '../../testUtils';
13+
import CardItem from '.';
14+
15+
jest.spyOn(reactRedux, 'useSelector').mockImplementation(() => studioHomeMock);
16+
17+
describe('<CardItem />', () => {
18+
beforeEach(() => {
19+
initializeMocks();
20+
});
21+
it('should render course details for non-library course', () => {
22+
const props = studioHomeMock.archivedCourses[0];
23+
render(<CardItem {...props} />);
24+
expect(screen.getByText(`${props.org} / ${props.number} / ${props.run}`)).toBeInTheDocument();
25+
});
26+
27+
it('should render correct links for non-library course', () => {
28+
const props = studioHomeMock.archivedCourses[0];
29+
render(<CardItem {...props} />);
30+
const courseTitleLink = screen.getByText(props.displayName);
31+
expect(courseTitleLink).toHaveAttribute('href', `${getConfig().STUDIO_BASE_URL}${props.url}`);
32+
const btnReRunCourse = screen.getByText(messages.btnReRunText.defaultMessage);
33+
expect(btnReRunCourse).toHaveAttribute('href', trimSlashes(props.rerunLink));
34+
const viewLiveLink = screen.getByText(messages.viewLiveBtnText.defaultMessage);
35+
expect(viewLiveLink).toHaveAttribute('href', props.lmsLink);
36+
});
37+
38+
it('should render correct links for non-library course pagination', () => {
39+
const props = studioHomeMock.archivedCourses[0];
40+
render(<CardItem {...props} isPaginated />);
41+
const courseTitleLink = screen.getByText(props.displayName);
42+
expect(courseTitleLink).toHaveAttribute('href', `${getConfig().STUDIO_BASE_URL}${props.url}`);
43+
const dropDownMenu = screen.getByTestId('toggle-dropdown');
44+
fireEvent.click(dropDownMenu);
45+
const btnReRunCourse = screen.getByText(messages.btnReRunText.defaultMessage);
46+
expect(btnReRunCourse).toHaveAttribute('href', trimSlashes(props.rerunLink));
47+
const viewLiveLink = screen.getByText(messages.viewLiveBtnText.defaultMessage);
48+
expect(viewLiveLink).toHaveAttribute('href', props.lmsLink);
49+
});
50+
it('should render course details for library course', () => {
51+
const props = { ...studioHomeMock.archivedCourses[0], isLibraries: true };
52+
render(<CardItem {...props} />);
53+
const courseTitleLink = screen.getByText(props.displayName);
54+
expect(courseTitleLink).toHaveAttribute('href', `${getConfig().STUDIO_BASE_URL}${props.url}`);
55+
expect(screen.getByText(`${props.org} / ${props.number}`)).toBeInTheDocument();
56+
});
57+
it('should hide rerun button if disallowed', () => {
58+
const props = studioHomeMock.archivedCourses[0];
59+
// Update our mocked redux data:
60+
jest.spyOn(reactRedux, 'useSelector').mockImplementation(() => (
61+
{ ...studioHomeMock, allowCourseReruns: false }
62+
));
63+
const { queryByText } = render(<CardItem {...props} />);
64+
expect(queryByText(messages.btnReRunText.defaultMessage)).not.toBeInTheDocument();
65+
});
66+
it('should be read only course if old mongo course', () => {
67+
const props = studioHomeMock.courses[1];
68+
render(<CardItem {...props} />);
69+
expect(screen.queryByText(props.displayName)).not.toHaveAttribute('href');
70+
expect(screen.queryByText(messages.btnReRunText.defaultMessage)).not.toBeInTheDocument();
71+
expect(screen.queryByText(messages.viewLiveBtnText.defaultMessage)).not.toBeInTheDocument();
72+
});
73+
74+
it('should render course key if displayname is empty', () => {
75+
const props = studioHomeMock.courses[1];
76+
const courseKeyTest = 'course-key';
77+
render(
78+
<CardItem
79+
{...props}
80+
displayName=""
81+
courseKey={courseKeyTest}
82+
lmsLink="lmsLink"
83+
rerunLink="returnLink"
84+
url="url"
85+
/>,
86+
);
87+
expect(screen.getByText(courseKeyTest)).toBeInTheDocument();
88+
});
89+
});

0 commit comments

Comments
 (0)