-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathImageOutput.test.tsx
More file actions
199 lines (169 loc) · 5.93 KB
/
ImageOutput.test.tsx
File metadata and controls
199 lines (169 loc) · 5.93 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// NOTE: Ready for migration
// These edit mode tests verify the round-trip: API Response → mapRequestToState() →
// Redux State → mapRequestFromState() → API Request. They could be replaced by unit
// tests for the request mapper functions (mapRequestToState/mapRequestFromState) which
// would be faster and more focused than full integration tests.
import { screen, within } from '@testing-library/react';
import { CreateBlueprintRequest } from '@/store/api/backend';
import { clickWithWait, createUser } from '@/test/testUtils';
import {
CREATE_BLUEPRINT,
EDIT_BLUEPRINT,
RHEL_10,
} from '../../../../../constants';
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
import {
aarch64CreateBlueprintRequest,
centos9CreateBlueprintRequest,
rhel8CreateBlueprintRequest,
rhel9CreateBlueprintRequest,
x86_64CreateBlueprintRequest,
} from '../../../../fixtures/editMode';
import {
blueprintRequest,
enterBlueprintName,
goToReview,
interceptBlueprintRequest,
interceptEditBlueprintRequest,
renderCreateMode,
renderEditMode,
selectGuestImageTarget,
} from '../../wizardTestUtils';
describe('Image output edit mode', () => {
beforeEach(() => {
vi.clearAllMocks();
});
test('edit mode works - rhel9', async () => {
const id = mockBlueprintIds['rhel9'];
await renderEditMode(id);
// starts on review step
const receivedRequest = await interceptEditBlueprintRequest(
`${EDIT_BLUEPRINT}/${id}`,
);
const expectedRequest = rhel9CreateBlueprintRequest;
expect(receivedRequest).toEqual(expectedRequest);
});
test('edit mode works - rhel8', async () => {
const id = mockBlueprintIds['rhel8'];
await renderEditMode(id);
// starts on review step
const receivedRequest = await interceptEditBlueprintRequest(
`${EDIT_BLUEPRINT}/${id}`,
);
const expectedRequest = rhel8CreateBlueprintRequest;
expect(receivedRequest).toEqual(expectedRequest);
});
test('edit mode works - centos9', async () => {
const id = mockBlueprintIds['centos9'];
await renderEditMode(id);
// starts on review step
const receivedRequest = await interceptEditBlueprintRequest(
`${EDIT_BLUEPRINT}/${id}`,
);
const expectedRequest = centos9CreateBlueprintRequest;
expect(receivedRequest).toEqual(expectedRequest);
});
test('edit mode works - x86_64', async () => {
const id = mockBlueprintIds['x86_64'];
await renderEditMode(id);
// starts on review step
const receivedRequest = await interceptEditBlueprintRequest(
`${EDIT_BLUEPRINT}/${id}`,
);
const expectedRequest = x86_64CreateBlueprintRequest;
expect(receivedRequest).toEqual(expectedRequest);
});
test('edit mode works - aarch64', async () => {
const id = mockBlueprintIds['aarch64'];
await renderEditMode(id);
// starts on review step
const receivedRequest = await interceptEditBlueprintRequest(
`${EDIT_BLUEPRINT}/${id}`,
);
const expectedRequest = aarch64CreateBlueprintRequest;
expect(receivedRequest).toEqual(expectedRequest);
});
});
const selectNetworkInstaller = async () => {
const user = createUser();
const checkbox = await screen.findByRole('checkbox', {
name: /Network installer checkbox/i,
});
await clickWithWait(user, checkbox);
return checkbox;
};
describe('Network installer target', () => {
beforeEach(() => {
vi.clearAllMocks();
});
test('selecting network-installer shows alert and disables other checkboxes', async () => {
await renderCreateMode();
const networkInstallerCheckbox = await selectNetworkInstaller();
await screen.findByText(
/This image type requires specific, minimal configuration for remote installation/i,
);
const guestImageCheckbox = await screen.findByRole('checkbox', {
name: /Virtualization guest image/i,
});
expect(guestImageCheckbox).toBeDisabled();
const bareMetalCheckbox = await screen.findByRole('checkbox', {
name: /Bare metal installer/i,
});
expect(bareMetalCheckbox).toBeDisabled();
expect(networkInstallerCheckbox).toBeChecked();
expect(networkInstallerCheckbox).toBeEnabled();
});
test('selecting another target first disables network-installer', async () => {
await renderCreateMode();
await selectGuestImageTarget();
const networkInstallerCheckbox = await screen.findByRole('checkbox', {
name: /Network installer checkbox/i,
});
expect(networkInstallerCheckbox).toBeDisabled();
});
test('selecting network-installer only shows base settings, advanced settings, and review steps', async () => {
await renderCreateMode();
await selectNetworkInstaller();
const navigation = await screen.findByRole('navigation', {
name: /wizard steps/i,
});
const stepButtons = within(navigation).getAllByRole('button');
expect(stepButtons).toHaveLength(3);
expect(
within(navigation).getByRole('button', { name: /base settings/i }),
).toBeInTheDocument();
expect(
within(navigation).getByRole('button', { name: /advanced settings/i }),
).toBeInTheDocument();
expect(
within(navigation).getByRole('button', { name: /review/i }),
).toBeInTheDocument();
});
test('can create a blueprint with network-installer', async () => {
await renderCreateMode();
await selectNetworkInstaller();
await enterBlueprintName('Red Velvet');
await goToReview();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
const expectedRequest: CreateBlueprintRequest = {
...blueprintRequest,
distribution: RHEL_10,
customizations: {
locale: {
languages: ['C.UTF-8'],
},
},
image_requests: [
{
architecture: 'x86_64',
image_type: 'network-installer',
upload_request: {
options: {},
type: 'aws.s3',
},
},
],
};
expect(receivedRequest).toEqual(expectedRequest);
});
});