-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathCompareChangesWidget.test.tsx
More file actions
95 lines (79 loc) · 3.43 KB
/
CompareChangesWidget.test.tsx
File metadata and controls
95 lines (79 loc) · 3.43 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import {
fireEvent,
render,
screen,
initializeMocks,
within,
} from '../../testUtils';
import CompareChangesWidget from './CompareChangesWidget';
const usageKey = 'lb:org:lib:type:id';
describe('<CompareChangesWidget />', () => {
beforeEach(() => {
initializeMocks();
});
it('can compare published (old) and draft (new) versions by default', async () => {
render(<CompareChangesWidget usageKey={usageKey} />);
// By default we see the new version:
const newTab = await screen.findByRole('tab', { name: 'New version' });
expect(newTab).toBeInTheDocument();
expect(newTab).toHaveClass('active');
const newTabPanel = await screen.findByRole('tabpanel', { name: 'New version' });
const newIframe = within(newTabPanel).getByTitle('Preview');
expect(newIframe).toBeVisible();
expect(newIframe).toHaveAttribute(
'src',
`http://localhost:18010/xblocks/v2/${usageKey}/embed/student_view/?version=draft`,
);
// Now switch to the "old version" tab:
const oldTab = await screen.findByRole('tab', { name: 'Old version' });
fireEvent.click(oldTab);
const oldTabPanel = await screen.findByRole('tabpanel', { name: 'Old version' });
expect(oldTabPanel).toBeVisible();
const oldIframe = within(oldTabPanel).getByTitle('Preview');
expect(oldIframe).toBeVisible();
expect(oldIframe).toHaveAttribute(
'src',
`http://localhost:18010/xblocks/v2/${usageKey}/embed/student_view/?version=published`,
);
});
it('can compare a specific old and published (new) version', async () => {
render(<CompareChangesWidget usageKey={usageKey} oldVersion={7} newVersion="published" />);
// By default we see the new version:
const newTab = await screen.findByRole('tab', { name: 'New version' });
expect(newTab).toBeInTheDocument();
expect(newTab).toHaveClass('active');
const newTabPanel = await screen.findByRole('tabpanel', { name: 'New version' });
const newIframe = within(newTabPanel).getByTitle('Preview');
expect(newIframe).toBeVisible();
expect(newIframe).toHaveAttribute(
'src',
`http://localhost:18010/xblocks/v2/${usageKey}/embed/student_view/?version=published`,
);
// Now switch to the "old version" tab:
const oldTab = await screen.findByRole('tab', { name: 'Old version' });
fireEvent.click(oldTab);
const oldTabPanel = await screen.findByRole('tabpanel', { name: 'Old version' });
expect(oldTabPanel).toBeVisible();
const oldIframe = within(oldTabPanel).getByTitle('Preview');
expect(oldIframe).toBeVisible();
expect(oldIframe).toHaveAttribute(
'src',
`http://localhost:18010/xblocks/v2/${usageKey}/embed/student_view/?version=7`,
);
});
it('renders side-by-side compare mode with both iframes and expected sources', async () => {
render(<CompareChangesWidget usageKey={usageKey} oldVersion={7} newVersion="published" sideBySide />);
expect(await screen.findByText('Old version')).toBeInTheDocument();
expect(await screen.findByText('New version')).toBeInTheDocument();
const iframes = await screen.findAllByTitle('Preview');
expect(iframes).toHaveLength(2);
expect(iframes[0]).toHaveAttribute(
'src',
`http://localhost:18010/xblocks/v2/${usageKey}/embed/student_view/?version=7`,
);
expect(iframes[1]).toHaveAttribute(
'src',
`http://localhost:18010/xblocks/v2/${usageKey}/embed/student_view/?version=published`,
);
});
});