forked from cadence-workflow/cadence-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule-actions.test.tsx
More file actions
120 lines (95 loc) · 3.07 KB
/
Copy pathschedule-actions.test.tsx
File metadata and controls
120 lines (95 loc) · 3.07 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import React from 'react';
import { HttpResponse } from 'msw';
import { render, screen, userEvent, waitFor } from '@/test-utils/rtl';
import { mockDescribeScheduleResponse } from '@/route-handlers/describe-schedule/__fixtures__/mock-describe-schedule-response';
import { mockScheduleActionsConfig } from '../__fixtures__/schedule-actions-config';
import ScheduleActions from '../schedule-actions';
const mockScheduleParams = {
domain: 'mock-domain',
cluster: 'mock-cluster',
scheduleId: 'mock-schedule-id',
};
jest.mock('next/navigation', () => ({
...jest.requireActual('next/navigation'),
useParams: () => mockScheduleParams,
}));
jest.mock('../schedule-actions-modal/schedule-actions-modal', () =>
jest.fn((props) => {
return props.action ? (
<div data-testid="actions-modal">Actions Modal</div>
) : null;
})
);
jest.mock('../schedule-actions-menu/schedule-actions-menu', () =>
jest.fn((props) => {
return (
<div
onClick={() => props.onActionSelect(mockScheduleActionsConfig[0])}
data-testid="actions-menu"
>
Actions Menu
</div>
);
})
);
describe(ScheduleActions.name, () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('renders the button with the correct text', async () => {
setup({});
const actionsButton = await screen.findByRole('button');
expect(actionsButton).toHaveAttribute(
'aria-label',
expect.stringContaining('loading')
);
await waitFor(() => {
expect(actionsButton).not.toHaveAttribute(
'aria-label',
expect.stringContaining('loading')
);
});
expect(actionsButton).toHaveTextContent('Schedule Actions');
});
it('renders the menu when the button is clicked', async () => {
const { user } = setup({});
const actionsButton = await screen.findByRole('button');
await user.click(actionsButton);
expect(await screen.findByTestId('actions-menu')).toBeInTheDocument();
});
it('shows the modal when a menu option is clicked', async () => {
const { user } = setup({});
const actionsButton = await screen.findByRole('button');
await user.click(actionsButton);
await user.click(await screen.findByTestId('actions-menu'));
expect(await screen.findByTestId('actions-modal')).toBeInTheDocument();
});
it('renders nothing if describeSchedule fails', async () => {
setup({ isError: true });
await waitFor(() => {
expect(screen.queryByRole('button')).not.toBeInTheDocument();
});
});
});
function setup({ isError = false }: { isError?: boolean }) {
const user = userEvent.setup();
render(<ScheduleActions />, {
endpointsMocks: [
{
path: '/api/domains/:domain/:cluster/schedules/:scheduleId',
httpMethod: 'GET',
mockOnce: false,
httpResolver: () => {
if (isError) {
return HttpResponse.json(
{ message: 'Schedule not found' },
{ status: 404 }
);
}
return HttpResponse.json(mockDescribeScheduleResponse);
},
},
],
});
return { user };
}