forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeaderActions.test.tsx
More file actions
58 lines (47 loc) · 1.83 KB
/
HeaderActions.test.tsx
File metadata and controls
58 lines (47 loc) · 1.83 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
import {
fireEvent, initializeMocks, render, screen,
} from '@src/testUtils';
import messages from './messages';
import HeaderActions, { HeaderActionsProps } from './HeaderActions';
const handleNewSectionMock = jest.fn();
const headerNavigationsActions = {
handleNewSection: handleNewSectionMock,
lmsLink: '',
};
const courseActions = {
draggable: true,
childAddable: true,
deletable: true,
duplicable: true,
};
const renderComponent = (props?: Partial<HeaderActionsProps>) => render(
<HeaderActions
actions={headerNavigationsActions}
courseActions={courseActions}
{...props}
/>,
);
describe('<HeaderActions />', () => {
beforeEach(() => {
initializeMocks();
});
it('render HeaderActions component correctly', async () => {
renderComponent();
expect(await screen.findByRole('button', { name: messages.addButton.defaultMessage })).toBeInTheDocument();
expect(await screen.findByRole('button', { name: messages.viewLiveButton.defaultMessage })).toBeInTheDocument();
expect(await screen.findByRole('button', { name: messages.moreActionsButtonAriaLabel.defaultMessage })).toBeInTheDocument();
});
it('calls the correct handlers when clicking buttons', async () => {
renderComponent();
const addButton = await screen.findByRole('button', { name: messages.addButton.defaultMessage });
fireEvent.click(addButton);
expect(handleNewSectionMock).toHaveBeenCalledTimes(1);
});
it('disables new section button if course outline fetch fails', async () => {
renderComponent({
errors: { outlineIndexApi: { data: 'some error', type: 'serverError' } },
});
expect(await screen.findByRole('button', { name: messages.addButton.defaultMessage })).toBeInTheDocument();
expect(await screen.findByRole('button', { name: messages.addButton.defaultMessage })).toBeDisabled();
});
});