Skip to content

Commit 31d7378

Browse files
committed
fix: update after review
1 parent 03fd60f commit 31d7378

5 files changed

Lines changed: 63 additions & 12 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { expect as baseExpect } from "@playwright/test";
2+
import type { DetailsPage } from "../helpers/DetailsPage";
3+
import type { MatcherResult } from "./types";
4+
5+
export interface DetailsPageMatchers {
6+
toHaveVisibleAction(actionName: string): Promise<MatcherResult>;
7+
}
8+
9+
type DetailsPageMatcherDefinitions = {
10+
readonly [K in keyof DetailsPageMatchers]: (
11+
receiver: DetailsPage,
12+
...args: Parameters<DetailsPageMatchers[K]>
13+
) => Promise<MatcherResult>;
14+
};
15+
16+
export const detailsPageAssertions =
17+
baseExpect.extend<DetailsPageMatcherDefinitions>({
18+
toHaveVisibleAction: async (
19+
detailsPage: DetailsPage,
20+
actionName: string,
21+
): Promise<MatcherResult> => {
22+
try {
23+
await baseExpect(
24+
detailsPage.page.getByRole("menuitem", { name: actionName }),
25+
).toBeVisible();
26+
return {
27+
pass: true,
28+
message: () =>
29+
`Action "${actionName}" is visible in the actions menu`,
30+
};
31+
} catch (error) {
32+
return {
33+
pass: false,
34+
message: () =>
35+
error instanceof Error ? error.message : String(error),
36+
};
37+
}
38+
},
39+
});

e2e/tests/ui/assertions/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ import {
2222
type FileUploadMatchers,
2323
} from "./FileUploadMatchers";
2424

25+
import type { DetailsPage } from "../helpers/DetailsPage";
26+
import {
27+
detailsPageAssertions,
28+
type DetailsPageMatchers,
29+
} from "./DetailsPageMatchers";
30+
2531
const merged = mergeExpects(
2632
tableAssertions,
2733
paginationAssertions,
2834
toolbarAssertions,
2935
dialogAssertions,
3036
fileUploadAssertions,
37+
detailsPageAssertions,
3138
// Add more custom assertions here
3239
);
3340

@@ -89,6 +96,14 @@ function typedExpect(
8996
): Omit<ReturnType<typeof merged<FileUpload>>, keyof FileUploadMatchers> &
9097
FileUploadMatchers;
9198

99+
/**
100+
* Overload from DetailsPageMatchers.ts
101+
*/
102+
function typedExpect(
103+
value: DetailsPage,
104+
): Omit<ReturnType<typeof merged<DetailsPage>>, keyof DetailsPageMatchers> &
105+
DetailsPageMatchers;
106+
92107
// Default overload
93108
function typedExpect<T>(value: T): ReturnType<typeof merged<T>>;
94109
function typedExpect<T>(value: T): unknown {

e2e/tests/ui/features/@license-export_cdx/license-export_cdx.step.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ When('User Clicks "Action" button', async ({ page }) => {
7373

7474
Then('"Download License Report" Option should be visible', async ({ page }) => {
7575
const detailsPage = new DetailsPage(page);
76-
await detailsPage.verifyActionIsVisibleInMenu("Download License Report");
76+
await expect(detailsPage).toHaveVisibleAction("Download License Report");
7777
});
7878

7979
When('Selects "Download License Report" option', async ({ page }) => {

e2e/tests/ui/helpers/DetailsPage.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,7 @@ export class DetailsPage {
3737
}
3838

3939
async verifyActionIsAvailable(actionName: string) {
40-
await this.page.getByRole("button", { name: "Actions" }).click();
41-
await expect(
42-
this.page.getByRole("menuitem", { name: actionName }),
43-
).toBeVisible();
44-
}
45-
46-
async verifyActionIsVisibleInMenu(actionName: string) {
40+
await this.openActionsMenu();
4741
await expect(
4842
this.page.getByRole("menuitem", { name: actionName }),
4943
).toBeVisible();

e2e/tests/ui/pages/LicenseExportHelpers.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Page } from "@playwright/test";
22
import * as fs from "node:fs";
33
import * as os from "node:os";
44
import * as path from "node:path";
5-
import { exec } from "node:child_process";
5+
import { execFile } from "node:child_process";
66
import { promisify } from "node:util";
77
import { DetailsPage } from "../helpers/DetailsPage";
88
import { clickAndDownload } from "./Helpers";
@@ -19,9 +19,12 @@ export const downloadLicenseReport = async (page: Page): Promise<string> => {
1919
.click(),
2020
);
2121

22+
const sanitizedFilename = download
23+
.suggestedFilename()
24+
.replace(/[\/\\.]/g, "_");
2225
const savePath = path.join(
2326
os.tmpdir(),
24-
`license-report-${Date.now()}-${download.suggestedFilename()}`,
27+
`license-report-${Date.now()}-${sanitizedFilename}`,
2528
);
2629
await download.saveAs(savePath);
2730
return savePath;
@@ -30,7 +33,7 @@ export const downloadLicenseReport = async (page: Page): Promise<string> => {
3033
export const extractLicenseReport = async (
3134
downloadedFilePath: string,
3235
): Promise<string> => {
33-
const execAsync = promisify(exec);
36+
const execFileAsync = promisify(execFile);
3437
const extractionPath = path.join(
3538
path.dirname(downloadedFilePath),
3639
"extracted",
@@ -39,7 +42,7 @@ export const extractLicenseReport = async (
3942
fs.mkdirSync(extractionPath);
4043
}
4144

42-
await execAsync(`tar -xzf ${downloadedFilePath} -C ${extractionPath}`);
45+
await execFileAsync("tar", ["-xzf", downloadedFilePath, "-C", extractionPath]);
4346
return extractionPath;
4447
};
4548

0 commit comments

Comments
 (0)