Skip to content

Commit 43d5301

Browse files
Add utils and dashboard tests
1 parent 2e9c437 commit 43d5301

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Page, expect, test } from '@playwright/test';
2+
3+
test.describe.configure({ mode: 'serial' });
4+
5+
let page: Page;
6+
7+
test.describe('compression', () => {
8+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Page, expect, test } from '@playwright/test';
2+
import { setAPIKey, uploadMedia } from './utils';
3+
4+
test.describe.configure({ mode: 'serial' });
5+
6+
let page: Page;
7+
8+
test.describe('dashboardwidget', () => {
9+
test.beforeAll(async ({ browser }) => {
10+
page = await browser.newPage();
11+
await setAPIKey(page, 'PNG123')
12+
});
13+
test('show widget without images', async () => {
14+
await page.goto('/wp-admin/index.php');
15+
await expect(page.getByText('You do not seem to have uploaded any JPEG, PNG or WebP images yet.')).toBeVisible();
16+
});
17+
18+
test('show widget without optimized images', async () => {
19+
await page.goto('/wp-admin/options-general.php?page=tinify');
20+
await page.locator('#tinypng_compression_timing_auto').check();
21+
await page.locator('#submit').click();
22+
23+
// upload something
24+
await uploadMedia(page, 'input-example.png');
25+
26+
await page.goto('/wp-admin/index.php');
27+
await expect(
28+
page.getByText('Hi Admin, you haven’t compressed any images in your media library. If you like you can to optimize your whole library in one go with the bulk optimization page.')
29+
).toBeVisible();
30+
});
31+
32+
test('show widget with some images optimized', async () => {
33+
// set compression on auto
34+
// upload media here
35+
// set api key
36+
// upload something
37+
// validate if halve optimized
38+
39+
await page.goto('/wp-admin/index.php');
40+
await expect(page.getByText('Admin, you are doing good. With your current settings you can still optimize')).toBeVisible();
41+
});
42+
43+
test('show widget with all images optimized', async () => {
44+
// set compression on auto
45+
// set api key
46+
// upload something
47+
48+
await page.goto('/wp-admin/index.php');
49+
await expect(page.getByText('Admin, this is great! Your entire library is optimized!')).toBeVisible();
50+
});
51+
});

test/integration/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import path from 'path';
2+
import { Page } from '@playwright/test';
3+
4+
export async function uploadMedia(page: Page, file: string) {
5+
await page.goto('/wp-admin/media-new.php');
6+
const fileChooserPromise = page.waitForEvent('filechooser');
7+
await page.locator('#async-upload').click();
8+
const fileChooser = await fileChooserPromise;
9+
await fileChooser.setFiles(path.join(__dirname, `../fixtures/${file}`));
10+
}
11+
12+
export async function setAPIKey(page: Page, key = '') {
13+
await page.goto('/wp-admin/options-general.php?page=tinify');
14+
15+
// Clear API Key
16+
await page.locator('#tinypng_api_key').fill(key);
17+
18+
await page.locator('#submit').click();
19+
}

0 commit comments

Comments
 (0)