-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathproposalActionSimulationStructure.test.tsx
More file actions
88 lines (72 loc) · 3.13 KB
/
Copy pathproposalActionSimulationStructure.test.tsx
File metadata and controls
88 lines (72 loc) · 3.13 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
import { render, screen } from '@testing-library/react';
import { DateTime } from 'luxon';
import { GukCoreProvider } from '../../../../core';
import type { IProposalActionSimulationStructureProps } from './proposalActionSimulationStructure';
import { ProposalActionSimulationStructure } from './proposalActionSimulationStructure';
describe('<ProposalActionSimulationStructure /> component', () => {
const createTestComponent = (props?: Partial<IProposalActionSimulationStructureProps>) => {
const completeProps: IProposalActionSimulationStructureProps = {
totalActions: 3,
status: 'success',
...props,
};
return (
<GukCoreProvider>
<ProposalActionSimulationStructure {...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 relative time for recent simulation', () => {
const recentTime = DateTime.now().minus({ days: 2 });
render(createTestComponent({ lastSimulation: recentTime }));
expect(screen.getByText('2 days ago')).toBeInTheDocument();
});
it('renders "Now" for very recent simulation', () => {
const veryRecentTime = DateTime.now().minus({ seconds: 30 });
render(createTestComponent({ lastSimulation: veryRecentTime }));
expect(screen.getByText('Now')).toBeInTheDocument();
});
it('renders the execution status label', () => {
render(
createTestComponent({
status: 'success',
}),
);
expect(screen.getByText('Likely to succeed')).toBeInTheDocument();
});
it('renders loading state when execution status is loading', () => {
render(
createTestComponent({
status: 'unknown',
isSimulating: 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({ isSimulatable: false }));
expect(screen.queryByText(/simulate/i)).toBeNull();
});
});