-
Notifications
You must be signed in to change notification settings - Fork 205
/
InstructorToolbar.test.jsx
76 lines (63 loc) · 2.74 KB
/
InstructorToolbar.test.jsx
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
import React from 'react';
import { getConfig } from '@edx/frontend-platform';
import MockAdapter from 'axios-mock-adapter';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import {
initializeTestStore, render, screen, waitFor, getByText, logUnhandledRequests,
} from '../setupTest';
import InstructorToolbar from './index';
const originalConfig = jest.requireActual('@edx/frontend-platform').getConfig();
jest.mock('@edx/frontend-platform', () => ({
...jest.requireActual('@edx/frontend-platform'),
getConfig: jest.fn(),
}));
getConfig.mockImplementation(() => originalConfig);
describe('Instructor Toolbar', () => {
let mockData;
let axiosMock;
let masqueradeUrl;
beforeAll(async () => {
const store = await initializeTestStore({ excludeFetchSequence: true });
const { courseware, models } = store.getState();
mockData = {
courseId: courseware.courseId,
unitId: Object.values(models.units)[0].id,
};
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
masqueradeUrl = `${getConfig().LMS_BASE_URL}/courses/${courseware.courseId}/masquerade`;
});
beforeEach(() => {
axiosMock.reset();
axiosMock.onGet(masqueradeUrl).reply(200, { success: true });
logUnhandledRequests(axiosMock);
});
it('sends query to masquerade and does not display alerts by default', async () => {
render(<InstructorToolbar {...mockData} />);
await waitFor(() => expect(axiosMock.history.get).toHaveLength(1));
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
});
it('displays masquerade error', async () => {
axiosMock.reset();
axiosMock.onGet(masqueradeUrl).reply(200, { success: false });
render(<InstructorToolbar {...mockData} />);
await waitFor(() => expect(axiosMock.history.get).toHaveLength(1));
expect(screen.getByRole('alert')).toHaveTextContent('Unable to get masquerade options');
});
it('displays links to view course in different services', () => {
const config = { ...originalConfig };
config.INSIGHTS_BASE_URL = 'http://localhost:18100';
getConfig.mockImplementation(() => config);
render(<InstructorToolbar {...mockData} />);
const linksContainer = screen.getByText('View course in:').parentElement;
['Legacy experience', 'Studio', 'Insights'].forEach(service => {
expect(getByText(linksContainer, service).getAttribute('href')).toMatch(/http.*/);
});
});
it('does not display links if there are no services available', () => {
const config = { ...originalConfig };
config.STUDIO_BASE_URL = undefined;
getConfig.mockImplementation(() => config);
render(<InstructorToolbar {...mockData} unitId={null} />);
expect(screen.queryByText('View course in:')).not.toBeInTheDocument();
});
});