Skip to content

Commit bf565d2

Browse files
committed
test: client: e2e: all jpg files are opened with text viewer (#477)
1 parent 043344e commit bf565d2

8 files changed

Lines changed: 84 additions & 0 deletions

File tree

‎.github/workflows/nodejs.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ jobs:
4242
message: "chore: ${{ env.NAME }}: actions: lint ☘️"
4343
- name: Build
4444
run: redrun build
45+
- name: Install Playwright browsers
46+
run: npx playwright install chromium --with-deps
47+
- name: Test E2E Client
48+
run: redrun test:e2e:client
4549
- name: Test
4650
run: redrun test
4751
- name: Coverage

‎.madrun.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default {
3030
'lint:stream': () => run('lint', '-f stream'),
3131
'test': () => [testEnv, `tape '{test}/**/*.js' '{bin,client,static,common,server}/**/*.spec.js' -f fail`],
3232
'test:e2e': () => `tape 'test-e2e/**/*.js'`,
33+
'test:e2e:client': () => 'playwright test',
3334
'test:client': () => `tape 'test/client/**/*.js'`,
3435
'test:server': () => `tape 'test/**/*.js' 'server/**/*.spec.js' 'common/**/*.spec.js'`,
3536
'wisdom': async () => await run(['lint:all', 'build', 'test'], null, {

‎.npmignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ coverage
2727
css
2828
html
2929
client
30+
playwright.config.*

‎client/modules/view/index.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ export async function show(data, options = {}) {
147147
return await viewFile();
148148
}
149149

150+
export {show as _show};
151+
150152
export const _createIframe = createIframe;
151153

152154
function createIframe(src, overrides = {}) {

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
"@cloudcmd/stub": "^5.0.0",
163163
"@iocmd/wait": "^2.1.0",
164164
"@putout/eslint-flat": "^4.0.0",
165+
"@playwright/test": "^1.63.0",
165166
"@rspack/cli": "^2.1.4",
166167
"@rspack/core": "^2.1.4",
167168
"@supertape/loader-css": "^1.0.0",

‎playwright.config.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {defineConfig} from '@playwright/test';
2+
3+
export default defineConfig({
4+
testDir: './test-e2e',
5+
testMatch: '**/*.spec.js',
6+
timeout: 30_000,
7+
use: {
8+
baseURL: 'http://localhost:3002',
9+
headless: true,
10+
},
11+
webServer: {
12+
command: 'node bin/cloudcmd.js --port 3002 --root test/fixture',
13+
url: 'http://localhost:3002',
14+
reuseExistingServer: false,
15+
timeout: 15_000,
16+
},
17+
});

‎test-e2e/view-image.spec.js‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import {test, expect} from '@playwright/test';
2+
3+
const getModal = (page) => page.locator('[data-name="modal-main"]');
4+
5+
test('F3 on a .jpg file opens the image viewer', async ({page}) => {
6+
await page.goto('/');
7+
await page.getByText('photo.jpg').first().click();
8+
await page.keyboard.press('F3');
9+
10+
const modal = getModal(page);
11+
await expect(modal).toBeVisible();
12+
});
13+
14+
test('F3 on a .jpg file does not open the text viewer', async ({page}) => {
15+
await page.goto('/');
16+
await page.getByText('photo.jpg').first().click();
17+
await page.keyboard.press('F3');
18+
19+
const modal = getModal(page);
20+
const modalText = await modal.textContent();
21+
await expect(modalText).not.toContain('JFIF');
22+
});
23+
24+
test('double-click on a .jpg file opens the image viewer', async ({page}) => {
25+
await page.goto('/');
26+
await page.getByText('photo.jpg').first().dblclick();
27+
28+
const modal = getModal(page);
29+
await expect(modal).toBeVisible();
30+
});
31+
32+
test('double-click on a .jpg file does not open the text viewer', async ({page}) => {
33+
await page.goto('/');
34+
await page.getByText('photo.jpg').first().dblclick();
35+
36+
const modal = getModal(page);
37+
const modalText = await modal.textContent();
38+
await expect(modalText).not.toContain('JFIF');
39+
});
40+
41+
test('F3 on a .txt file opens the text viewer', async ({page}) => {
42+
await page.goto('/');
43+
await page.getByText('copy.txt').first().click();
44+
await page.keyboard.press('F3');
45+
46+
const modal = getModal(page);
47+
await expect(modal).toBeVisible();
48+
});
49+
50+
test('F3 on a .txt file shows file content', async ({page}) => {
51+
await page.goto('/');
52+
await page.getByText('copy.txt').first().click();
53+
await page.keyboard.press('F3');
54+
55+
const modal = getModal(page);
56+
const modalText = await modal.textContent();
57+
await expect(modalText.length).toBeGreaterThan(0);
58+
});

‎test/fixture/photo.jpg‎

143 Bytes
Loading

0 commit comments

Comments
 (0)