|
| 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 | +}); |
0 commit comments