Skip to content

Commit

Permalink
update e2e tests with screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanrajpac committed Sep 21, 2024
1 parent 817b94f commit d3e9a20
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"prepare": "husky",
"start": "wp-scripts start",
"test:e2e": "wp-scripts test-playwright",
"test:e2e:debug": "wp-scripts test-playwright --ui",
"test:js": "wp-scripts test-unit-js",
"test:js:update": "wp-scripts test-unit-js --updateSnapshot",
"test:performance": "wp-scripts test-playwright --config tests/performance/playwright.config.ts",
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default defineConfig({
use: {
baseURL: process.env.WP_BASE_URL,
trace: 'on-first-retry',
permissions: ['clipboard-read'],
permissions: ['clipboard-write', 'clipboard-read'],
},

projects: [
Expand Down
6 changes: 4 additions & 2 deletions tests/e2e/feature-flags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,16 @@ test.describe('Feature flags', () => {
).toBeVisible();

// Check PHP Snippet clipboard details
await page.getByLabel('Copy to clipboard').first().click();
await page.getByRole('button').nth(1).click();

// await page.getByLabel('Copy to clipboard').first().click();
const phpClipboardText = await page.evaluate(
'navigator.clipboard.readText()'
);
expect(phpClipboardText).toContain(`Flag::is_enabled( '${flagName}' )`);

// Check JS Snippet clipboard details
await page.getByLabel('Copy to clipboard').nth(1).click();
await page.getByRole('button').nth(2).click();
const jsClipboardText: string = await page.evaluate(
'navigator.clipboard.readText()'
);
Expand Down
Binary file added tests/e2e/screenshots/delete-flag-modal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/e2e/screenshots/flag-disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/e2e/screenshots/no-flags.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/e2e/screenshots/sdk-modal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/e2e/screenshots/some-flags.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 19 additions & 6 deletions tests/e2e/visual-comparison.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
import { test } from '@wordpress/e2e-test-utils-playwright';
import {
AddNewFlagAndFill,
CloseSdkModal,
Expand All @@ -23,7 +23,9 @@ test.describe('Visual tests', () => {
});

test('Feature flags screen without flags', async ({ page }) => {
await expect(page).toHaveScreenshot('no-flags.png');
await page
.locator('#codeb_feature_flags_settings_screen')
.screenshot({ path: 'tests/e2e/screenshots/no-flags.png' });
});

test('Feature flags screen with some flags', async ({ page }) => {
Expand All @@ -33,13 +35,18 @@ test.describe('Visual tests', () => {
await AddNewFlagAndFill(page, 'healthCheck');

await SaveFlags(page);
await expect(page).toHaveScreenshot('some-flags.png');

await page
.locator('#codeb_feature_flags_settings_screen')
.screenshot({ path: 'tests/e2e/screenshots/some-flags.png' });
});

test('Toggle feature flag', async ({ page }) => {
await AddNewFlagAndFill(page, 'auth0');
await DisableFlag(page, true);
await expect(page).toHaveScreenshot('flag-disabled.png');
await page
.locator('#codeb_feature_flags_settings_screen')
.screenshot({ path: 'tests/e2e/screenshots/flag-disabled.png' });
});

test('Delete flag modal', async ({ page }) => {
Expand All @@ -51,7 +58,11 @@ test.describe('Visual tests', () => {
.getByLabel('Delete Flag')
.click();

await expect(page).toHaveScreenshot('delete-flag-modal.png');
await page

Check warning on line 61 in tests/e2e/visual-comparison.spec.ts

View workflow job for this annotation

GitHub Actions / js-lint-test

Replace `⏎↹↹↹.locator('#codeb_feature_flags_settings_screen')⏎↹↹↹` with `.locator('#codeb_feature_flags_settings_screen')`
.locator('#codeb_feature_flags_settings_screen')
.screenshot({
path: 'tests/e2e/screenshots/delete-flag-modal.png',

Check warning on line 64 in tests/e2e/visual-comparison.spec.ts

View workflow job for this annotation

GitHub Actions / js-lint-test

Delete `↹`
});

Check warning on line 65 in tests/e2e/visual-comparison.spec.ts

View workflow job for this annotation

GitHub Actions / js-lint-test

Delete `↹`

await page.getByRole('button', { name: 'Yes' }).click();
});
Expand All @@ -60,7 +71,9 @@ test.describe('Visual tests', () => {
await AddNewFlagAndFill(page, 'drag-drop');
await OpenSdkModal(page);

await expect(page).toHaveScreenshot('sdk-modal.png');
await page
.locator('#codeb_feature_flags_settings_screen')
.screenshot({ path: 'tests/e2e/screenshots/sdk-modal.png' });

await CloseSdkModal(page);
});
Expand Down

0 comments on commit d3e9a20

Please sign in to comment.