-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathbulk-import.spec.ts
More file actions
376 lines (338 loc) · 12.6 KB
/
bulk-import.spec.ts
File metadata and controls
376 lines (338 loc) · 12.6 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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
import { expect, Page, test } from "@playwright/test";
import { UIhelper } from "../../utils/ui-helper";
import { Common, setupBrowser } from "../../utils/common";
import { APIHelper } from "../../utils/api-helper";
import { BulkImport } from "../../support/pages/bulk-import";
import { CatalogImport } from "../../support/pages/catalog-import";
import { DEFAULT_CATALOG_INFO_YAML } from "../../support/test-data/bulk-import";
// Pre-req : plugin-bulk-import & plugin-bulk-import-backend-dynamic
test.describe.serial("Bulk Import plugin", () => {
test.skip(
() => process.env.JOB_NAME.includes("osd-gcp"),
"skipping due to RHDHBUGS-555 on OSD Env",
);
test.describe.configure({ retries: process.env.CI ? 5 : 0 });
let page: Page;
let uiHelper: UIhelper;
let common: Common;
let bulkimport: BulkImport;
const catalogRepoName = `janus-test-1-bulk-import-test-${Date.now()}`;
const catalogRepoDetails = {
name: catalogRepoName,
url: `github.com/janus-test/${catalogRepoName}`,
org: "github.com/janus-test",
owner: "janus-test",
};
const catalogInfoYamlContent = `apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: ${catalogRepoName}
annotations:
github.com/project-slug: janus-test/${catalogRepoName}
spec:
type: other
lifecycle: unknown
owner: user:default/rhdh-qe-2`;
const newRepoName = `bulk-import-${Date.now()}`;
const newRepoDetails = {
owner: "janus-test",
repoName: newRepoName,
updatedComponentName: `${newRepoName}-updated`,
labels: `bulkimport1: test1;bulkimport2: test2`,
repoUrl: `github.com/janus-test/${newRepoName}`,
};
test.beforeAll(async ({ browser }, testInfo) => {
test.info().annotations.push({
type: "component",
description: "plugins",
});
page = (await setupBrowser(browser, testInfo)).page;
uiHelper = new UIhelper(page);
common = new Common(page);
bulkimport = new BulkImport(page);
// Create the repository with catalog-info.yaml file dynamically
await APIHelper.createGitHubRepoWithFile(
catalogRepoDetails.owner,
catalogRepoDetails.name,
"catalog-info.yaml",
catalogInfoYamlContent,
);
await bulkimport.newGitHubRepo(
newRepoDetails.owner,
newRepoDetails.repoName,
);
await common.loginAsKeycloakUser(
process.env.GH_USER2_ID,
process.env.GH_USER2_PASS,
);
});
test("Bulk import plugin page", async () => {
await uiHelper.openSidebar("Bulk import");
await uiHelper.verifyHeading("Bulk import");
await expect(
page.getByRole("button", { name: "Import to Red Hat Developer" }),
).toHaveAttribute("aria-expanded", "true");
await page
.getByRole("button", { name: "Import to Red Hat Developer" })
.click();
await expect(
page.getByRole("button", { name: "Import to Red Hat Developer" }),
).toHaveAttribute("aria-expanded", "false");
await expect(
page.getByText("Source control tool", { exact: true }),
).toBeVisible();
await page
.getByLabel("Importing requires approval.")
.getByTestId("HelpOutlineIcon")
.hover();
await expect(
page.getByRole("tooltip", { name: "Importing requires approval." }),
).toBeVisible();
await expect(page.getByRole("radio", { name: "GitHub" })).toBeChecked();
await page.getByRole("radio", { name: "GitLab" }).check();
await expect(page.getByRole("radio", { name: "GitLab" })).toBeChecked();
await page.getByRole("radio", { name: "GitHub" }).check();
await expect(page.getByRole("article")).toMatchAriaSnapshot(`
- table:
- rowgroup:
- row "select all repositories Name URL Organization Status":
- columnheader "select all repositories Name":
- checkbox "select all repositories"
- text: Name
- columnheader "URL"
- columnheader "Organization"
- columnheader "Status"
`);
});
test("Add a Repository and Confirm its Preview", async () => {
await uiHelper.openSidebar("Bulk import");
// Wait to ensure the repo will appear in the Bulk Import UI
await expect(async () => {
await page.reload();
await common.waitForLoad();
await uiHelper.searchInputPlaceholder(catalogRepoDetails.name);
await uiHelper.verifyRowInTableByUniqueText(catalogRepoDetails.name, [
"Ready to import",
]);
}).toPass({
intervals: [5_000],
timeout: 40_000,
});
await bulkimport.selectRepoInTable(catalogRepoDetails.name);
await uiHelper.verifyRowInTableByUniqueText(catalogRepoDetails.name, [
catalogRepoDetails.url,
"Ready to import",
"Preview file",
]);
await uiHelper.clickOnLinkInTableByUniqueText(
catalogRepoDetails.name,
"Preview file",
);
await expect(await uiHelper.clickButton("Save")).toBeHidden();
await expect(await uiHelper.clickButton("Import")).toBeDisabled();
});
test("Add a Repository, generate a PR, and confirm its preview", async () => {
// Wait to ensure the repo will appear in the Bulk Import UI
await expect(async () => {
await page.reload();
await common.waitForLoad();
await uiHelper.searchInputPlaceholder(newRepoDetails.repoName);
await uiHelper.verifyRowInTableByUniqueText(newRepoDetails.repoName, [
"Ready to import",
]);
}).toPass({
intervals: [5_000],
timeout: 40_000,
});
await bulkimport.selectRepoInTable(newRepoDetails.repoName);
await uiHelper.clickOnLinkInTableByUniqueText(
newRepoDetails.repoName,
"Preview file",
);
await uiHelper.clickButton("Save");
await uiHelper.verifyRowInTableByUniqueText(newRepoDetails.repoName, [
"Ready to import",
]);
await expect(await uiHelper.clickButton("Import")).toBeDisabled({
timeout: 10000,
});
});
test('Verify that the two selected repositories are listed: one with the status "Already imported" and another with the status "WAIT_PR_APPROVAL."', async () => {
await common.waitForLoad();
await bulkimport.filterAddedRepo(catalogRepoDetails.name);
await uiHelper.verifyRowInTableByUniqueText(catalogRepoDetails.name, [
catalogRepoDetails.url,
"Imported",
]);
await bulkimport.filterAddedRepo(newRepoDetails.repoName);
await uiHelper.verifyRowInTableByUniqueText(newRepoDetails.repoName, [
"Waiting for Approval",
]);
});
test("Verify the Content of catalog-info.yaml in the PR is Correct", async () => {
const prCatalogInfoYaml = await APIHelper.getfileContentFromPR(
newRepoDetails.owner,
newRepoDetails.repoName,
1,
"catalog-info.yaml",
);
const expectedCatalogInfoYaml = DEFAULT_CATALOG_INFO_YAML(
newRepoDetails.repoName,
`${newRepoDetails.owner}/${newRepoDetails.repoName}`,
process.env.GH_USER2_ID,
);
expect(prCatalogInfoYaml).toEqual(expectedCatalogInfoYaml);
});
test("Verify Selected repositories shows catalog-info.yaml status as 'Already imported' and 'WAIT_PR_APPROVAL'", async () => {
await uiHelper.openSidebar("Bulk import");
await uiHelper.searchInputPlaceholder(catalogRepoDetails.name);
await uiHelper.verifyRowInTableByUniqueText(catalogRepoDetails.name, [
"Imported",
]);
await uiHelper.searchInputPlaceholder(newRepoDetails.repoName);
await uiHelper.verifyRowInTableByUniqueText(newRepoDetails.repoName, [
"Waiting for Approval",
]);
});
test("Merge the PR on GitHub and Confirm the Status Updates to 'Already imported'", async () => {
await uiHelper.openSidebar("Bulk import");
// Merge PR is generated for the repository without the catalog.yaml file.
await APIHelper.mergeGitHubPR(
newRepoDetails.owner,
newRepoDetails.repoName,
1,
);
// Ensure that no PR is generated for the repository that already has a catalog.yaml file.
expect(
await APIHelper.getGitHubPRs(
catalogRepoDetails.owner,
catalogRepoDetails.name,
"open",
),
).toHaveLength(0);
// Wait to ensure the repo will appear in the Bulk Import UI
await expect(async () => {
await page.reload();
await common.waitForLoad();
await bulkimport.filterAddedRepo(newRepoDetails.repoName);
// verify that the status has changed to "Already imported."
await uiHelper.verifyRowInTableByUniqueText(newRepoDetails.repoName, [
"Imported",
]);
}).toPass({
intervals: [5_000],
timeout: 40_000,
});
});
test("Verify Added Repositories Appear in the Catalog as Expected", async () => {
await uiHelper.openSidebar("Catalog");
await uiHelper.selectMuiBox("Kind", "Component");
await uiHelper.searchInputPlaceholder(catalogRepoDetails.name);
await uiHelper.verifyRowInTableByUniqueText(catalogRepoDetails.name, [
"other",
"unknown",
]);
});
test.afterAll(async () => {
try {
// Delete the dynamically created GitHub repository with catalog-info.yaml
await APIHelper.deleteGitHubRepo(
catalogRepoDetails.owner,
catalogRepoDetails.name,
);
// Delete the GitHub repository
await APIHelper.deleteGitHubRepo(
newRepoDetails.owner,
newRepoDetails.repoName,
);
console.log(
`[Cleanup] Deleted GitHub repositories: ${catalogRepoDetails.name}, ${newRepoDetails.repoName}`,
);
} catch (error) {
console.error(`[Cleanup] Final cleanup failed: ${error.message}`);
}
});
});
test.describe
.serial("Bulk Import - Verify existing repo are displayed in bulk import Added repositories", () => {
test.skip(
() => process.env.JOB_NAME.includes("osd-gcp"),
"skipping due to RHDHBUGS-555 on OSD Env",
);
let page: Page;
let uiHelper: UIhelper;
let common: Common;
let bulkimport: BulkImport;
let catalogImport: CatalogImport;
const existingRepoFromAppConfig = "janus-test-3-bulk-import";
const existingComponentDetails = {
name: "janus-test-2-bulk-import-test",
repoName: "janus-test-2-bulk-import-test",
url: "https://github.com/janus-test/janus-test-2-bulk-import-test/blob/main/catalog-info.yaml",
};
test.beforeAll(async ({ browser }, testInfo) => {
page = (await setupBrowser(browser, testInfo)).page;
uiHelper = new UIhelper(page);
common = new Common(page);
bulkimport = new BulkImport(page);
catalogImport = new CatalogImport(page);
await common.loginAsKeycloakUser(
process.env.GH_USER2_ID,
process.env.GH_USER2_PASS,
);
});
test("Verify existing repo from app-config is displayed in bulk import Added repositories", async () => {
await uiHelper.openSidebar("Bulk import");
await common.waitForLoad();
await bulkimport.filterAddedRepo(existingRepoFromAppConfig);
await uiHelper.verifyRowInTableByUniqueText(existingRepoFromAppConfig, [
"Imported",
]);
});
test('Verify repo from "import an existing git repository" are displayed in bulk import Added repositories', async () => {
// Import an existing Git repository
await uiHelper.openSidebar("Catalog");
await uiHelper.clickButton("Self-service");
await uiHelper.clickButton("Import an existing Git repository");
await catalogImport.registerExistingComponent(
existingComponentDetails.url,
true,
);
// Verify in bulk import's Added Repositories
// Navigate directly to ensure a clean page state (avoids landing on the import tab)
// The backend may take time to sync the import status, so retry with page reload
await expect(async () => {
await page.goto("/bulk-import");
await common.waitForLoad();
await bulkimport.filterAddedRepo(existingComponentDetails.repoName);
await uiHelper.verifyRowInTableByUniqueText(
existingComponentDetails.repoName,
["Imported"],
);
}).toPass({
intervals: [5_000, 10_000, 15_000],
timeout: 90_000,
});
});
});
test.describe
.serial("Bulk Import - Ensure users without bulk import permissions cannot access the bulk import plugin", () => {
test.skip(
() => process.env.JOB_NAME.includes("osd-gcp"),
"skipping due to RHDHBUGS-555 on OSD Env",
);
let page: Page;
let uiHelper: UIhelper;
let common: Common;
test.beforeAll(async ({ browser }, testInfo) => {
page = (await setupBrowser(browser, testInfo)).page;
uiHelper = new UIhelper(page);
common = new Common(page);
await common.loginAsKeycloakUser();
});
test("Bulk Import - Verify users without permission cannot access", async () => {
await uiHelper.openSidebar("Bulk import");
await uiHelper.verifyText("Permission required");
expect(await uiHelper.isBtnVisible("Import")).toBeFalsy();
});
});