|
1 | 1 | import AwesomePlugin from "@allurereport/plugin-awesome"; |
2 | 2 | import { expect, test } from "@playwright/test"; |
3 | 3 | import { Stage, Status } from "allure-js-commons"; |
| 4 | +import { CommonPage, SummaryPage } from "../pageObjects/index.js"; |
4 | 5 | import { AwesomePluginWithoutSummary, type ReportBootstrap, bootstrapReport } from "../utils/index.js"; |
5 | 6 |
|
6 | 7 | let bootstrap: ReportBootstrap; |
| 8 | +let summaryPage: SummaryPage; |
| 9 | +let commonPage: CommonPage; |
7 | 10 |
|
8 | 11 | test.afterAll(async () => { |
9 | 12 | await bootstrap?.shutdown?.(); |
10 | 13 | }); |
11 | 14 |
|
| 15 | +test.beforeEach(async ({ page }) => { |
| 16 | + commonPage = new CommonPage(page); |
| 17 | + summaryPage = new SummaryPage(page); |
| 18 | +}); |
| 19 | + |
12 | 20 | test.describe("summary", () => { |
| 21 | + test("should not generate summary for a single report", async ({ page }) => { |
| 22 | + bootstrap = await bootstrapReport({ |
| 23 | + reportConfig: { |
| 24 | + name: "Sample allure report", |
| 25 | + appendHistory: false, |
| 26 | + history: undefined, |
| 27 | + historyPath: undefined, |
| 28 | + knownIssuesPath: undefined, |
| 29 | + plugins: [ |
| 30 | + { |
| 31 | + id: "awesome1", |
| 32 | + enabled: true, |
| 33 | + plugin: new AwesomePlugin({}), |
| 34 | + options: {}, |
| 35 | + }, |
| 36 | + ], |
| 37 | + }, |
| 38 | + testResults: [ |
| 39 | + { |
| 40 | + name: "0 sample passed test", |
| 41 | + fullName: "sample.js#0 sample passed test", |
| 42 | + status: Status.PASSED, |
| 43 | + stage: Stage.FINISHED, |
| 44 | + start: 1000, |
| 45 | + }, |
| 46 | + ], |
| 47 | + }); |
| 48 | + |
| 49 | + await page.goto(bootstrap.url); |
| 50 | + |
| 51 | + await expect(summaryPage.reportCardLocator).not.toBeVisible(); |
| 52 | + await expect(commonPage.baseLayoutLocator).toBeVisible(); |
| 53 | + }); |
| 54 | + |
| 55 | + test("should not generate summary on the single report re-generation", async ({ page }) => { |
| 56 | + bootstrap = await bootstrapReport({ |
| 57 | + reportConfig: { |
| 58 | + name: "Sample allure report", |
| 59 | + appendHistory: false, |
| 60 | + history: undefined, |
| 61 | + historyPath: undefined, |
| 62 | + knownIssuesPath: undefined, |
| 63 | + plugins: [ |
| 64 | + { |
| 65 | + id: "awesome1", |
| 66 | + enabled: true, |
| 67 | + plugin: new AwesomePlugin({}), |
| 68 | + options: {}, |
| 69 | + }, |
| 70 | + ], |
| 71 | + }, |
| 72 | + testResults: [ |
| 73 | + { |
| 74 | + name: "0 sample passed test", |
| 75 | + fullName: "sample.js#0 sample passed test", |
| 76 | + status: Status.PASSED, |
| 77 | + stage: Stage.FINISHED, |
| 78 | + start: 1000, |
| 79 | + }, |
| 80 | + ], |
| 81 | + }); |
| 82 | + |
| 83 | + await page.goto(bootstrap.url); |
| 84 | + |
| 85 | + await expect(summaryPage.reportCardLocator).not.toBeVisible(); |
| 86 | + await expect(commonPage.baseLayoutLocator).toBeVisible(); |
| 87 | + |
| 88 | + await bootstrap.regenerate(); |
| 89 | + await page.reload(); |
| 90 | + |
| 91 | + await expect(summaryPage.reportCardLocator).not.toBeVisible(); |
| 92 | + await expect(commonPage.baseLayoutLocator).toBeVisible(); |
| 93 | + }); |
| 94 | + |
13 | 95 | test("should render cards for each generated report with summary", async ({ page, context }) => { |
14 | 96 | bootstrap = await bootstrapReport({ |
15 | 97 | reportConfig: { |
@@ -43,18 +125,17 @@ test.describe("summary", () => { |
43 | 125 | }, |
44 | 126 | ], |
45 | 127 | }); |
46 | | - const summaryCardsLocator = page.getByTestId("summary-report-card"); |
47 | 128 |
|
48 | 129 | await page.goto(bootstrap.url); |
49 | 130 |
|
50 | | - await expect(summaryCardsLocator).toHaveCount(2); |
| 131 | + await expect(summaryPage.reportCardLocator).toHaveCount(2); |
51 | 132 |
|
52 | 133 | const pageUrl = page.url(); |
53 | 134 |
|
54 | 135 | expect(context.pages()).toHaveLength(1); |
55 | 136 | expect(context.pages()[0].url()).toBe(pageUrl); |
56 | 137 |
|
57 | | - const [newTab] = await Promise.all([context.waitForEvent("page"), await summaryCardsLocator.nth(0).click()]); |
| 138 | + const [newTab] = await Promise.all([context.waitForEvent("page"), await summaryPage.clickReportCard(0)]); |
58 | 139 |
|
59 | 140 | expect(context.pages()[0].url()).toBe(pageUrl); |
60 | 141 | expect(newTab.url()).not.toBe(`${pageUrl}awesome1/index.html`); |
@@ -99,10 +180,9 @@ test.describe("summary", () => { |
99 | 180 | }, |
100 | 181 | ], |
101 | 182 | }); |
102 | | - const summaryCardsLocator = page.getByTestId("summary-report-card"); |
103 | 183 |
|
104 | 184 | await page.goto(bootstrap.url); |
105 | 185 |
|
106 | | - await expect(summaryCardsLocator).toHaveCount(2); |
| 186 | + await expect(summaryPage.reportCardLocator).toHaveCount(2); |
107 | 187 | }); |
108 | 188 | }); |
0 commit comments