Skip to content

Commit 045656d

Browse files
authored
chore(e2e): retries for bulk import test (#3367)
* chore(e2e): retries for repo filtering * Skip if already added * Logging * Revert * Dynamically create the repository * Update bulk-import.spec.ts
1 parent 61468ca commit 045656d

File tree

3 files changed

+105
-16
lines changed

3 files changed

+105
-16
lines changed

e2e-tests/playwright/e2e/plugins/bulk-import.spec.ts

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,26 @@ test.describe.serial("Bulk Import plugin", () => {
1717
let uiHelper: UIhelper;
1818
let common: Common;
1919

20-
test.beforeAll(async () => {
21-
test.info().annotations.push({
22-
type: "component",
23-
description: "plugins",
24-
});
25-
});
26-
2720
let bulkimport: BulkImport;
2821

22+
const catalogRepoName = `janus-test-1-bulk-import-test-${Date.now()}`;
2923
const catalogRepoDetails = {
30-
name: "janus-test-1-bulk-import-test",
31-
url: "github.com/janus-test/janus-test-1-bulk-import-test",
24+
name: catalogRepoName,
25+
url: `github.com/janus-test/${catalogRepoName}`,
3226
org: "github.com/janus-test",
3327
owner: "janus-test",
3428
};
29+
30+
const catalogInfoYamlContent = `apiVersion: backstage.io/v1alpha1
31+
kind: Component
32+
metadata:
33+
name: ${catalogRepoName}
34+
annotations:
35+
github.com/project-slug: janus-test/${catalogRepoName}
36+
spec:
37+
type: other
38+
lifecycle: unknown
39+
owner: user:default/rhdh-qe-2`;
3540
const newRepoName = `bulk-import-${Date.now()}`;
3641
const newRepoDetails = {
3742
owner: "janus-test",
@@ -40,13 +45,27 @@ test.describe.serial("Bulk Import plugin", () => {
4045
labels: `bulkimport1: test1;bulkimport2: test2`,
4146
repoUrl: `github.com/janus-test/${newRepoName}`,
4247
};
48+
4349
test.beforeAll(async ({ browser }, testInfo) => {
50+
test.info().annotations.push({
51+
type: "component",
52+
description: "plugins",
53+
});
54+
4455
page = (await setupBrowser(browser, testInfo)).page;
4556

4657
uiHelper = new UIhelper(page);
4758
common = new Common(page);
4859
bulkimport = new BulkImport(page);
4960

61+
// Create the repository with catalog-info.yaml file dynamically
62+
await APIHelper.createGitHubRepoWithFile(
63+
catalogRepoDetails.owner,
64+
catalogRepoDetails.name,
65+
"catalog-info.yaml",
66+
catalogInfoYamlContent,
67+
);
68+
5069
await bulkimport.newGitHubRepo(
5170
newRepoDetails.owner,
5271
newRepoDetails.repoName,
@@ -62,6 +81,7 @@ test.describe.serial("Bulk Import plugin", () => {
6281
await uiHelper.openSidebar("Bulk import");
6382
await uiHelper.clickButton("Add");
6483
await uiHelper.searchInputPlaceholder(catalogRepoDetails.name);
84+
6585
await uiHelper.verifyRowInTableByUniqueText(catalogRepoDetails.name, [
6686
"Not Generated",
6787
]);
@@ -234,10 +254,25 @@ test.describe.serial("Bulk Import plugin", () => {
234254
});
235255

236256
test.afterAll(async () => {
237-
await APIHelper.deleteGitHubRepo(
238-
newRepoDetails.owner,
239-
newRepoDetails.repoName,
240-
);
257+
try {
258+
// Delete the dynamically created GitHub repository with catalog-info.yaml
259+
await APIHelper.deleteGitHubRepo(
260+
catalogRepoDetails.owner,
261+
catalogRepoDetails.name,
262+
);
263+
264+
// Delete the GitHub repository
265+
await APIHelper.deleteGitHubRepo(
266+
newRepoDetails.owner,
267+
newRepoDetails.repoName,
268+
);
269+
270+
console.log(
271+
`[Cleanup] Deleted GitHub repositories: ${catalogRepoDetails.name}, ${newRepoDetails.repoName}`,
272+
);
273+
} catch (error) {
274+
console.error(`[Cleanup] Final cleanup failed: ${error.message}`);
275+
}
241276
});
242277
});
243278

e2e-tests/playwright/support/pages/bulk-import.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,23 @@ export class BulkImport {
1717
}
1818

1919
async filterAddedRepo(searchText: string) {
20-
await this.page
21-
.getByPlaceholder("Filter", { exact: true })
22-
.fill(searchText);
20+
await expect(async () => {
21+
// Clear any existing filter first
22+
await this.page.getByPlaceholder("Filter", { exact: true }).clear();
23+
24+
// Fill the filter with search text
25+
await this.page
26+
.getByPlaceholder("Filter", { exact: true })
27+
.fill(searchText);
28+
29+
// Wait for the filter to be applied and verify no "no-import-jobs-found" message appears
30+
await expect(this.page.getByTestId("no-import-jobs-found")).toBeHidden({
31+
timeout: 2000,
32+
});
33+
}).toPass({
34+
intervals: [1_000, 2_000, 5_000],
35+
timeout: 15_000,
36+
});
2337
}
2438

2539
async newGitHubRepo(owner: string, repoName: string) {

e2e-tests/playwright/utils/api-helper.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,46 @@ export class APIHelper {
7676
expect(response.status() === 201 || response.ok()).toBeTruthy();
7777
}
7878

79+
static async createGitHubRepoWithFile(
80+
owner: string,
81+
repoName: string,
82+
filename: string,
83+
fileContent: string,
84+
) {
85+
// Create the repository
86+
await APIHelper.createGitHubRepo(owner, repoName);
87+
88+
// Add the specified file
89+
await APIHelper.createFileInRepo(
90+
owner,
91+
repoName,
92+
filename,
93+
fileContent,
94+
`Add ${filename} file`,
95+
);
96+
}
97+
98+
static async createFileInRepo(
99+
owner: string,
100+
repoName: string,
101+
filePath: string,
102+
content: string,
103+
commitMessage: string,
104+
branch = "main",
105+
) {
106+
const encodedContent = Buffer.from(content).toString("base64");
107+
const response = await APIHelper.githubRequest(
108+
"PUT",
109+
`${GITHUB_API_ENDPOINTS.contents(owner, repoName)}/${filePath}`,
110+
{
111+
message: commitMessage,
112+
content: encodedContent,
113+
branch: branch,
114+
},
115+
);
116+
expect(response.status() === 201 || response.ok()).toBeTruthy();
117+
}
118+
79119
static async initCommit(owner: string, repo: string, branch = "main") {
80120
const content = Buffer.from(
81121
"This is the initial commit for the repository.",

0 commit comments

Comments
 (0)