-
Notifications
You must be signed in to change notification settings - Fork 44
/
ProposalPage.test.jsx
278 lines (233 loc) · 7.75 KB
/
ProposalPage.test.jsx
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
* Copyright (c) [2022-2024] SUSE LLC
*
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, contact SUSE LLC.
*
* To contact SUSE LLC about this file by physical or electronic mail, you may
* find current contact information at www.suse.com.
*/
// @ts-check
import React from "react";
import { act, screen, waitFor } from "@testing-library/react";
import { createCallbackMock, installerRender } from "~/test-utils";
import { createClient } from "~/client";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { StorageClient } from "~/client/storage";
import { IDLE } from "~/client/status";
import { ProposalPage } from "~/components/storage";
/**
* @typedef {import ("~/client/storage").ProposalResult} ProposalResult
* @typedef {import ("~/client/storage").StorageDevice} StorageDevice
* @typedef {import ("~/client/storage").Volume} Volume
*/
jest.mock("~/client");
jest.mock("@patternfly/react-core", () => {
const original = jest.requireActual("@patternfly/react-core");
return {
...original,
Skeleton: () => <div>PFSkeleton</div>
};
});
jest.mock("~/components/core/Sidebar", () => () => <div>Agama sidebar</div>);
jest.mock("~/components/storage/ProposalPageMenu", () => () => <div>ProposalPage Options</div>);
jest.mock("~/context/product", () => ({
...jest.requireActual("~/context/product"),
useProduct: () => ({
selectedProduct : { name: "Test" }
})
}));
const createClientMock = /** @type {jest.Mock} */(createClient);
/** @type {StorageDevice} */
const vda = {
sid: 59,
type: "disk",
isDrive: true,
description: "",
vendor: "Micron",
model: "Micron 1100 SATA",
driver: ["ahci", "mmcblk"],
bus: "IDE",
transport: "usb",
dellBOSS: false,
sdCard: true,
active: true,
name: "/dev/vda",
size: 1e+12,
systems : ["Windows 11", "openSUSE Leap 15.2"],
udevIds: ["ata-Micron_1100_SATA_512GB_12563", "scsi-0ATA_Micron_1100_SATA_512GB"],
udevPaths: ["pci-0000:00-12", "pci-0000:00-12-ata"],
};
/** @type {StorageDevice} */
const vdb = {
sid: 60,
type: "disk",
isDrive: true,
description: "",
vendor: "Seagate",
model: "Unknown",
driver: ["ahci", "mmcblk"],
bus: "IDE",
name: "/dev/vdb",
size: 1e+6
};
/**
* @param {string} mountPath
* @returns {Volume}
*/
const volume = (mountPath) => {
return (
{
mountPath,
target: "DEFAULT",
fsType: "Btrfs",
minSize: 1024,
maxSize: 1024,
autoSize: false,
snapshots: false,
transactional: false,
outline: {
required: false,
fsTypes: ["Btrfs"],
supportAutoSize: false,
snapshotsConfigurable: false,
snapshotsAffectSizes: false,
sizeRelevantVolumes: [],
adjustByRam: false,
productDefined: false
}
}
);
};
/** @type {StorageClient} */
let storage;
/** @type {ProposalResult} */
let proposalResult;
beforeEach(() => {
proposalResult = {
settings: {
target: "DISK",
targetPVDevices: [],
configureBoot: false,
bootDevice: "",
defaultBootDevice: "",
encryptionPassword: "",
encryptionMethod: "",
spacePolicy: "",
spaceActions: [],
volumes: [],
installationDevices: []
},
actions: []
};
storage = {
probe: jest.fn().mockResolvedValue(0),
// @ts-expect-error Some methods have to be private to avoid type complaint.
proposal: {
getAvailableDevices: jest.fn().mockResolvedValue([vda, vdb]),
getEncryptionMethods: jest.fn().mockResolvedValue([]),
getProductMountPoints: jest.fn().mockResolvedValue([]),
getResult: jest.fn().mockResolvedValue(proposalResult),
defaultVolume: jest.fn(mountPath => Promise.resolve(volume(mountPath))),
calculate: jest.fn().mockResolvedValue(0),
},
// @ts-expect-error Some methods have to be private to avoid type complaint.
system: {
getDevices: jest.fn().mockResolvedValue([vda, vdb])
},
// @ts-expect-error Some methods have to be private to avoid type complaint.
staging: {
getDevices: jest.fn().mockResolvedValue([vda])
},
getErrors: jest.fn().mockResolvedValue([]),
isDeprecated: jest.fn().mockResolvedValue(false),
onDeprecate: jest.fn(),
onStatusChange: jest.fn()
};
createClientMock.mockImplementation(() => ({ storage }));
});
it("probes storage if the storage devices are deprecated", async () => {
storage.isDeprecated = jest.fn().mockResolvedValue(true);
installerRender(<ProposalPage />);
await waitFor(() => expect(storage.probe).toHaveBeenCalled());
});
it("does not probe storage if the storage devices are not deprecated", async () => {
installerRender(<ProposalPage />);
await waitFor(() => expect(storage.probe).not.toHaveBeenCalled());
});
it("loads the proposal data", async () => {
proposalResult.settings.target = "DISK";
proposalResult.settings.targetDevice = vda.name;
installerRender(<ProposalPage />);
await screen.findByText(/\/dev\/vda/);
});
it("renders the device, settings and result sections", async () => {
installerRender(<ProposalPage />);
await screen.findByText(/Device/);
await screen.findByText(/Settings/);
await screen.findByText(/Result/);
});
describe("when the storage devices become deprecated", () => {
it("probes storage", async () => {
const [mockFunction, callbacks] = createCallbackMock();
storage.onDeprecate = mockFunction;
installerRender(<ProposalPage />);
storage.isDeprecated = jest.fn().mockResolvedValue(true);
const [onDeprecateCb] = callbacks;
await act(() => onDeprecateCb());
await waitFor(() => expect(storage.probe).toHaveBeenCalled());
});
it("loads the proposal data", async () => {
proposalResult.settings.target = "DISK";
proposalResult.settings.targetDevice = vda.name;
const [mockFunction, callbacks] = createCallbackMock();
storage.onDeprecate = mockFunction;
installerRender(<ProposalPage />);
await screen.findByText(/\/dev\/vda/);
proposalResult.settings.targetDevice = vdb.name;
const [onDeprecateCb] = callbacks;
await act(() => onDeprecateCb());
await screen.findByText(/\/dev\/vdb/);
});
});
describe("when there is no proposal yet", () => {
it("loads the proposal when the service finishes to calculate", async () => {
const defaultResult = proposalResult;
proposalResult = undefined;
const [mockFunction, callbacks] = createCallbackMock();
storage.onStatusChange = mockFunction;
installerRender(<ProposalPage />);
screen.getAllByText(/PFSkeleton/);
proposalResult = defaultResult;
proposalResult.settings.target = "DISK";
proposalResult.settings.targetDevice = vda.name;
const [onStatusChangeCb] = callbacks;
await act(() => onStatusChangeCb(IDLE));
await screen.findByText(/\/dev\/vda/);
});
});
describe("when there is a proposal", () => {
beforeEach(() => {
proposalResult.settings.target = "DISK";
proposalResult.settings.targetDevice = vda.name;
});
it("does not load the proposal when the service finishes to calculate", async () => {
const [mockFunction, callbacks] = createCallbackMock();
storage.onStatusChange = mockFunction;
installerRender(<ProposalPage />);
await screen.findByText(/\/dev\/vda/);
const [onStatusChangeCb] = callbacks;
expect(onStatusChangeCb).toBeUndefined();
});
});