-
-
Notifications
You must be signed in to change notification settings - Fork 654
/
FeatureArchiveDialog.test.tsx
119 lines (106 loc) · 3.53 KB
/
FeatureArchiveDialog.test.tsx
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
import { vi } from 'vitest';
import React from 'react';
import { screen, waitFor } from '@testing-library/react';
import { render } from 'utils/testRenderer';
import { testServerRoute, testServerSetup } from 'utils/testServer';
import { FeatureArchiveDialog } from './FeatureArchiveDialog';
import { UIProviderContainer } from 'component/providers/UIProvider/UIProviderContainer';
const server = testServerSetup();
const setupHappyPathForChangeRequest = () => {
testServerRoute(
server,
'/api/admin/projects/projectId/environments/development/change-requests',
{},
'post'
);
testServerRoute(
server,
'/api/admin/projects/projectId/change-requests/config',
[
{
environment: 'development',
type: 'development',
requiredApprovals: 1,
changeRequestEnabled: true,
},
]
);
testServerRoute(server, '/api/admin/ui-config', {
versionInfo: {
current: { oss: 'version', enterprise: 'version' },
},
});
};
test('Add single archive feature change to change request', async () => {
const onClose = vi.fn();
const onConfirm = vi.fn();
setupHappyPathForChangeRequest();
render(
<UIProviderContainer>
<FeatureArchiveDialog
featureIds={['featureA']}
projectId={'projectId'}
isOpen={true}
onClose={onClose}
onConfirm={onConfirm}
featuresWithUsage={[]}
/>
</UIProviderContainer>
);
expect(screen.getByText('Archive feature toggle')).toBeInTheDocument();
const button = await screen.findByText('Add change to draft');
button.click();
await waitFor(() => {
expect(onConfirm).toBeCalledTimes(1);
});
expect(onClose).toBeCalledTimes(1);
});
test('Add multiple archive feature changes to change request', async () => {
const onClose = vi.fn();
const onConfirm = vi.fn();
setupHappyPathForChangeRequest();
render(
<UIProviderContainer>
<FeatureArchiveDialog
featureIds={['featureA', 'featureB']}
projectId={'projectId'}
isOpen={true}
onClose={onClose}
onConfirm={onConfirm}
featuresWithUsage={[]}
/>
</UIProviderContainer>
);
await screen.findByText('Archive feature toggles');
const button = await screen.findByText('Add to change request');
button.click();
await waitFor(() => {
expect(onConfirm).toBeCalledTimes(1);
});
expect(onClose).toBeCalledTimes(1);
});
test('Skip change request', async () => {
const onClose = vi.fn();
const onConfirm = vi.fn();
setupHappyPathForChangeRequest();
render(
<UIProviderContainer>
<FeatureArchiveDialog
featureIds={['featureA', 'featureB']}
projectId={'projectId'}
isOpen={true}
onClose={onClose}
onConfirm={onConfirm}
featuresWithUsage={[]}
/>
</UIProviderContainer>,
{ permissions: [{ permission: 'SKIP_CHANGE_REQUEST' }] }
);
await screen.findByText('Archive feature toggles');
const button = await screen.findByText('Archive toggles');
button.click();
await waitFor(() => {
expect(onClose).toBeCalledTimes(1);
});
expect(onConfirm).toBeCalledTimes(0); // we didn't setup non Change Request flow so failure
});