forked from cadence-workflow/cadence-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule-actions-menu.test.tsx
More file actions
95 lines (75 loc) · 2.7 KB
/
Copy pathschedule-actions-menu.test.tsx
File metadata and controls
95 lines (75 loc) · 2.7 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 React from 'react';
import { render, screen, userEvent, within } from '@/test-utils/rtl';
import {
getMockPausedDescribeScheduleResponse,
getMockRunningDescribeScheduleResponse,
mockDescribeScheduleResponse,
} from '@/route-handlers/describe-schedule/__fixtures__/mock-describe-schedule-response';
import { mockScheduleActionsConfig } from '../../__fixtures__/schedule-actions-config';
import ScheduleActionsMenu from '../schedule-actions-menu';
jest.mock(
'../../config/schedule-actions.config',
() => mockScheduleActionsConfig
);
describe(ScheduleActionsMenu.name, () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('renders the menu items correctly', () => {
setup({ schedule: mockDescribeScheduleResponse });
const menuButtons = screen.getAllByRole('button');
expect(menuButtons).toHaveLength(2);
expect(within(menuButtons[0]).getByText('Mock pause')).toBeInTheDocument();
expect(menuButtons[0]).not.toBeDisabled();
expect(within(menuButtons[1]).getByText('Mock resume')).toBeInTheDocument();
expect(menuButtons[1]).toBeDisabled();
});
it('disables pause and enables resume when schedule is paused', () => {
setup({ schedule: getMockPausedDescribeScheduleResponse() });
const menuButtons = screen.getAllByRole('button');
expect(menuButtons[0]).toBeDisabled();
expect(menuButtons[1]).not.toBeDisabled();
});
it('shows tooltip when pause is disabled for a paused schedule', async () => {
const { user } = setup({
schedule: getMockPausedDescribeScheduleResponse(),
});
await user.hover(screen.getAllByRole('button')[0]);
expect(
await screen.findByText('Schedule is already paused')
).toBeInTheDocument();
});
it('shows tooltip when resume is disabled for a running schedule', async () => {
const { user } = setup({
schedule: getMockRunningDescribeScheduleResponse(),
});
await user.hover(screen.getAllByRole('button')[1]);
expect(
await screen.findByText('Schedule is not paused')
).toBeInTheDocument();
});
it('calls onActionSelect when an enabled action button is clicked', async () => {
const { user, mockOnActionSelect } = setup({
schedule: mockDescribeScheduleResponse,
});
await user.click(screen.getAllByRole('button')[0]);
expect(mockOnActionSelect).toHaveBeenCalledWith(
expect.objectContaining({ id: 'pause' })
);
});
});
function setup({
schedule,
}: {
schedule: typeof mockDescribeScheduleResponse;
}) {
const user = userEvent.setup();
const mockOnActionSelect = jest.fn();
render(
<ScheduleActionsMenu
schedule={schedule}
onActionSelect={mockOnActionSelect}
/>
);
return { user, mockOnActionSelect };
}