-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathactionSimulation.test.tsx
More file actions
96 lines (80 loc) · 3.18 KB
/
Copy pathactionSimulation.test.tsx
File metadata and controls
96 lines (80 loc) · 3.18 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
import { render, screen } from '@testing-library/react';
import { DateTime } from 'luxon';
import { GukCoreProvider } from '../../../../core';
import type { IActionSimulationProps } from './actionSimulation';
import { ActionSimulation } from './actionSimulation';
describe('<ActionSimulation /> component', () => {
const createTestComponent = (props?: Partial<IActionSimulationProps>) => {
const completeProps: IActionSimulationProps = {
totalActions: 3,
...props,
};
return (
<GukCoreProvider>
<ActionSimulation {...completeProps} />
</GukCoreProvider>
);
};
it('renders all definition list items', () => {
render(createTestComponent());
expect(screen.getByText('Total actions')).toBeInTheDocument();
expect(screen.getByText('Last simulation')).toBeInTheDocument();
expect(screen.getByText('Executable')).toBeInTheDocument();
});
it('renders the total actions count', () => {
render(createTestComponent({ totalActions: 5 }));
expect(screen.getByText('5 actions')).toBeInTheDocument();
});
it('renders singular action text for one action', () => {
render(createTestComponent({ totalActions: 1 }));
expect(screen.getByText('1 action')).toBeInTheDocument();
});
it('renders "Never" when no last simulation is provided', () => {
render(createTestComponent());
expect(screen.getByText('Never')).toBeInTheDocument();
});
it('renders the execution status label', () => {
render(
createTestComponent({
lastSimulation: {
timestamp: DateTime.now().toMillis(),
url: 'https://dashboard.tenderly.co/simulation/12345',
status: 'success',
},
}),
);
expect(screen.getByText('Likely to succeed')).toBeInTheDocument();
});
it('renders failure status label', () => {
render(
createTestComponent({
lastSimulation: {
timestamp: DateTime.now().toMillis(),
url: 'https://dashboard.tenderly.co/simulation/12345',
status: 'failure',
},
}),
);
expect(screen.getByText('Likely to fail')).toBeInTheDocument();
});
it('renders unknown status when no lastSimulation is provided', () => {
render(createTestComponent());
expect(screen.getByText('Unknown')).toBeInTheDocument();
});
it('renders loading state when execution status is loading', () => {
render(
createTestComponent({
isLoading: true,
}),
);
expect(screen.getAllByText('Simulating')).toHaveLength(3);
});
it('shows simulate button by default when isSimulatable is not specified', () => {
render(createTestComponent());
expect(screen.getByText(/simulate/i)).toBeInTheDocument();
});
it('hides simulate button when isSimulatable is false', () => {
render(createTestComponent({ isEnabled: false }));
expect(screen.queryByText(/simulate/i)).toBeNull();
});
});