forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicSection.test.jsx
More file actions
80 lines (72 loc) · 3.09 KB
/
BasicSection.test.jsx
File metadata and controls
80 lines (72 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react';
import { render } from '@testing-library/react';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import { INVITE_STUDENTS_LINK_ID } from './constants';
import messages from './messages';
import BasicSection from '.';
describe('<BasicSection />', () => {
const RootWrapper = (props) => (
<IntlProvider locale="en">
<BasicSection {...props} />
</IntlProvider>
);
const props = {
intl: {},
org: 'foo org',
courseNumber: 'bar number',
run: 'foo run',
lmsLinkForAboutPage: 'link://to',
marketingEnabled: true,
courseDisplayName: 'foo course',
platformName: 'Your platform name here',
};
it('renders basic section successfully', () => {
const { getByText } = render(<RootWrapper {...props} />);
expect(getByText(messages.basicTitle.defaultMessage)).toBeInTheDocument();
expect(
getByText(messages.basicDescription.defaultMessage),
).toBeInTheDocument();
expect(
getByText(messages.courseOrganization.defaultMessage),
).toBeInTheDocument();
expect(getByText(props.org)).toBeInTheDocument();
expect(getByText(messages.courseNumber.defaultMessage)).toBeInTheDocument();
expect(getByText(props.courseNumber)).toBeInTheDocument();
expect(getByText(messages.courseRun.defaultMessage)).toBeInTheDocument();
expect(getByText(props.run)).toBeInTheDocument();
});
it('shows the page banner if the marketingEnabled is true', () => {
const { getByText, queryAllByText } = render(<RootWrapper {...props} />);
expect(
getByText(`Promoting your course with ${props.platformName}`),
).toBeInTheDocument();
expect(
getByText(messages.basicBannerText.defaultMessage),
).toBeInTheDocument();
expect(queryAllByText('Course summary page').length).toBe(0);
});
it('shows the course promotion if the marketingEnabled is false', () => {
const initialProps = { ...props, marketingEnabled: false };
const { getByText, getByRole, queryAllByText } = render(
<RootWrapper {...initialProps} />,
);
const inviteButton = getByRole('button', {
name: messages.basicPromotionButton.defaultMessage,
});
expect(getByText(/Course Summary Page/i)).toBeInTheDocument();
expect(
getByText(/(for student enrollment and access)/i),
).toBeInTheDocument();
expect(getByText(props.lmsLinkForAboutPage)).toBeInTheDocument();
expect(inviteButton).toBeInTheDocument();
expect(queryAllByText(`Promoting your course with ${props.platformName}`).length).toBe(0);
});
it('checks link link to invite', () => {
const initialProps = { ...props, marketingEnabled: false };
const { getByTestId } = render(<RootWrapper {...initialProps} />);
const inviteLink = getByTestId(INVITE_STUDENTS_LINK_ID);
expect(decodeURIComponent(inviteLink.href)).toEqual(
`mailto:${process.env.INVITE_STUDENTS_EMAIL_TO}?body=The course ${props.courseDisplayName}, provided by ${props.platformName}, is open for enrollment. Please navigate to this course at ${props.lmsLinkForAboutPage} to enroll.&subject=Enroll in ${props.courseDisplayName}.`,
);
});
});