Skip to content

Commit 0fbf8eb

Browse files
committed
add helpers for marketing screenshots
1 parent d144690 commit 0fbf8eb

4 files changed

Lines changed: 49 additions & 30 deletions

File tree

frontend/viewer/Taskfile.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,11 @@ tasks:
4747
env:
4848
AUTO_START_SERVER: true
4949
cmd: pnpm run test:playwright {{.CLI_ARGS}}
50+
generate-marketing-screenshots:
51+
desc: 'they should be in the screenshots folder'
52+
env:
53+
AUTO_START_SERVER: true
54+
MARKETING_SCREENSHOTS: true
55+
cmd: pnpm run test:playwright {{.CLI_ARGS}}
5056
playwright-test-report:
5157
cmd: pnpm run test:playwright-report

frontend/viewer/playwright.config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ const vitePort = '5173';
44
const dotnetPort = '5137';
55
const autoStartServer = process.env.AUTO_START_SERVER ? Boolean(process.env.AUTO_START_SERVER) : false;
66
const serverPort = process.env.SERVER_PORT ?? (autoStartServer ? vitePort : dotnetPort);
7-
const allReporters: ReporterDescription[] = [['list'], [
7+
const allReporters: ReporterDescription[] = [
8+
['list'],
9+
];
10+
const localReporters: ReporterDescription[] = [['html', { outputFolder: 'html-test-results', open: 'never' }]];
11+
const ciReporters: ReporterDescription[] = [['github'], ['junit', {outputFile: 'test-results/results.xml'}], [
812
'@argos-ci/playwright/reporter',
913
{
14+
//by only using the argos reporter in CI, screenshots will be placed in the screenshots folder when run locally
1015
// Upload to Argos on CI only.
1116
uploadToArgos: !!process.env.CI
1217
// Argos token not required when using GitHub Actions.
1318
}
1419
]];
15-
const localReporters: ReporterDescription[] = [['html', { outputFolder: 'html-test-results', open: 'never' }]];
16-
const ciReporters: ReporterDescription[] = [['github'], ['junit', {outputFile: 'test-results/results.xml'}]];
1720
export default defineConfig({
1821
testDir: './tests',
1922
fullyParallel: true,

frontend/viewer/tests/project-view-snapshots.test.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
import {type Page, expect, test} from '@playwright/test';
22
import { assertScreenshot } from './snapshot';
33

4-
const viewports = [
5-
{height: 720, width: 1280, name: 'medium'},
6-
{height: 812, width: 375, name: 'iphone-11'},
7-
];
4+
for (const colorScheme of ['light', 'dark'] as const) {
5+
test(`ui snapshot selected entry (color: ${colorScheme})`, async ({page}) => {
6+
await page.emulateMedia({colorScheme});
7+
await page.goto('/testing/project-view');
8+
await waitForProjectViewReady(page);
9+
await page.getByRole('row', {name: 'ambuka to cross a body of'}).click();
10+
await expect(page.getByRole('heading', {name: 'ambuka'})).toBeVisible();
11+
await expect(page.locator('.i-mdi-dots-vertical')).toBeVisible();
12+
await expect(page.locator('.i-mdi-loading')).toHaveCount(0);
13+
await assertScreenshot(page, 'project-view-entry-selected-' + colorScheme);
14+
});
815

9-
for (const colorScheme of ['light', 'dark'] as const) {
10-
test(`ui snapshot selected entry (color: ${colorScheme})`, async ({page}) => {
11-
await page.emulateMedia({colorScheme});
12-
await page.goto('/testing/project-view');
13-
await waitForProjectViewReady(page);
14-
await page.getByRole('row', {name: 'ambuka to cross a body of'}).click();
15-
await expect(page.getByRole('heading', {name: 'ambuka'})).toBeVisible();
16-
await expect(page.locator('.i-mdi-dots-vertical')).toBeVisible();
17-
await expect(page.locator('.i-mdi-loading')).toHaveCount(0);
18-
await assertScreenshot(page, 'project-view-entry-selected-' + colorScheme);
19-
});
20-
21-
test(`ui snapshot default (color: ${colorScheme})`, async ({page}) => {
22-
await page.emulateMedia({colorScheme});
23-
await page.goto('/testing/project-view');
24-
await waitForProjectViewReady(page);
25-
await expect(page.getByRole('textbox', {name: 'Filter'})).toBeVisible();
26-
await page.getByRole('row', { name: 'ambuka to cross a body of' }).scrollIntoViewIfNeeded();
27-
await assertScreenshot(page, 'project-view-default-' + colorScheme);
28-
});
29-
}
16+
test(`ui snapshot default (color: ${colorScheme})`, async ({page}) => {
17+
await page.emulateMedia({colorScheme});
18+
await page.goto('/testing/project-view');
19+
await waitForProjectViewReady(page);
20+
await expect(page.getByRole('textbox', {name: 'Filter'})).toBeVisible();
21+
await page.getByRole('row', { name: 'ambuka to cross a body of' }).scrollIntoViewIfNeeded();
22+
await assertScreenshot(page, 'project-view-default-' + colorScheme);
23+
});
24+
}
3025

3126

3227
async function waitForProjectViewReady(page: Page) {

frontend/viewer/tests/snapshot.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,26 @@ import type {Page} from '@playwright/test';
33

44
const defaultOptions: ArgosScreenshotOptions = {
55
viewports: [
6-
{height: 720, width: 1280},
6+
{ height: 720, width: 1280 },
77
'iphone-x'
8-
]
8+
],
99
};
1010

11+
const marketingScreenshotSizes: Exclude<ArgosScreenshotOptions['viewports'], undefined> = [
12+
{ width: 1024, height: 500 },//android feature graphic
13+
{ width: 720, height: 1280 },
14+
{ preset: 'macbook-16', orientation: 'landscape' },
15+
{ preset: 'macbook-16', orientation: 'portrait' },
16+
{ width: 1620, height: 2160 },//ipad
17+
{ width: 2160, height: 1620 }
18+
];
19+
1120
export async function assertScreenshot(page: Page, name: string, options?: ArgosScreenshotOptions): Promise<void> {
21+
if (process.env.MARKETING_SCREENSHOTS === 'true') {
22+
options = {
23+
...options,
24+
viewports: [...defaultOptions.viewports ?? [], ...marketingScreenshotSizes]
25+
};
26+
}
1227
await argosScreenshot(page, name, {...defaultOptions, ...options});
1328
}

0 commit comments

Comments
 (0)