From 3a85341dbf32158dcc205d33f5d83e84e5bb75f9 Mon Sep 17 00:00:00 2001 From: regexowl Date: Thu, 13 Mar 2025 17:26:31 +0100 Subject: [PATCH] playwright: Add `playwright` to ESLint and fix errors This add the `playwright` folder to the lint script and fixes errors. --- package.json | 4 ++-- playwright/lib/lib.ts | 38 ++++++++++++++++---------------------- playwright/test.spec.ts | 36 ++++++++++++++++++++++-------------- 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index f4034441..5dca9889 100644 --- a/package.json +++ b/package.json @@ -96,8 +96,8 @@ }, "scripts": { "lint": "npm-run-all lint:*", - "lint:js": "eslint src", - "lint:js:fix": "eslint src --fix", + "lint:js": "eslint src playwright", + "lint:js:fix": "eslint src playwright --fix", "start": "fec dev", "start:stage": "fec dev --clouddotEnv=stage", "start:prod": "fec dev --clouddotEnv=prod", diff --git a/playwright/lib/lib.ts b/playwright/lib/lib.ts index bdbcf5ed..c7a75199 100644 --- a/playwright/lib/lib.ts +++ b/playwright/lib/lib.ts @@ -1,15 +1,15 @@ -import { expect, type Page, type FrameLocator } from '@playwright/test'; +import { type Page, type FrameLocator } from '@playwright/test'; export const ibFrame = (page: Page): FrameLocator | Page => { if (isHosted()) { - return page + return page; } - return page.locator('iframe[name="cockpit1\\:localhost\\/cockpit-image-builder"]').contentFrame(); -} + return page + .locator('iframe[name="cockpit1\\:localhost\\/cockpit-image-builder"]') + .contentFrame(); +}; -export const login = async ( - page: Page -) => { +export const login = async (page: Page) => { if (!process.env.USER || !process.env.PASSWORD) { throw new Error('user or password not set in environment'); } @@ -21,17 +21,13 @@ export const login = async ( return loginConsole(page, user, password); } return loginCockpit(page, user, password); -} +}; -export const isHosted = (): Boolean => { +export const isHosted = (): boolean => { return process.env.BASE_URL?.includes('redhat.com') || false; -} +}; -const loginCockpit = async ( - page: Page, - user: string, - password: string -) => { +const loginCockpit = async (page: Page, user: string, password: string) => { await page.goto('/cockpit-image-builder'); await page.getByRole('textbox', { name: 'User name' }).fill(user); @@ -44,20 +40,18 @@ const loginCockpit = async ( await page.getByRole('button', { name: 'Administrative access' }); }; -const loginConsole = async ( - page: Page, - user: string, - password: string -) => { +const loginConsole = async (page: Page, user: string, password: string) => { await page.goto('/insights/image-builder/landing'); - await page.getByRole('textbox', { name: 'Red Hat login or email' }).fill(user); + await page + .getByRole('textbox', { name: 'Red Hat login or email' }) + .fill(user); await page.getByRole('button', { name: 'Next' }).click(); await page.getByRole('textbox', { name: 'Password' }).fill(password); await page.getByRole('button', { name: 'Log in' }).click(); await closePopupsIfExist(page); await page.locator('#preview-toggle').check(); await page.getByRole('heading', { name: 'All images' }); -} +}; const closePopupsIfExist = async (page: Page) => { const locatorsToCheck = [ diff --git a/playwright/test.spec.ts b/playwright/test.spec.ts index 78ebba55..f4fd2e4c 100644 --- a/playwright/test.spec.ts +++ b/playwright/test.spec.ts @@ -1,17 +1,12 @@ import { expect, test } from '@playwright/test'; - import { v4 as uuidv4 } from 'uuid'; -import { - login, - ibFrame, - isHosted, -} from './lib/lib'; +import { login, ibFrame, isHosted } from './lib/lib'; test.describe.serial('test', () => { - let blueprintName = uuidv4(); + const blueprintName = uuidv4(); test('create blueprint', async ({ page }) => { - await login(page) + await login(page); const frame = await ibFrame(page); await frame.getByRole('heading', { name: 'Images About image builder' }); @@ -23,7 +18,9 @@ test.describe.serial('test', () => { await frame.getByRole('button', { name: 'Next', exact: true }).click(); if (isHosted()) { - await frame.getByRole('heading', { name: 'Register systems using this image' }); + await frame.getByRole('heading', { + name: 'Register systems using this image', + }); await page.getByTestId('automatically-register-checkbox').uncheck(); await frame.getByRole('button', { name: 'Next', exact: true }).click(); await frame.getByRole('heading', { name: 'Compliance' }); @@ -89,7 +86,9 @@ test.describe.serial('test', () => { await login(page); const frame = await ibFrame(page); - await frame.getByRole('textbox', { name: 'Search input' }).fill(blueprintName); + await frame + .getByRole('textbox', { name: 'Search input' }) + .fill(blueprintName); await frame.getByText(blueprintName, { exact: true }).first().click(); await frame.getByRole('button', { name: 'Edit blueprint' }).click(); @@ -101,7 +100,9 @@ test.describe.serial('test', () => { await frame.getByRole('button', { name: 'Review and finish' }).click(); await frame.getByRole('button', { name: 'About packages' }).click(); await frame.getByRole('gridcell', { name: 'osbuild-composer' }); - await frame.getByRole('button', { name: 'Save changes to blueprint' }).click(); + await frame + .getByRole('button', { name: 'Save changes to blueprint' }) + .click(); await frame.getByRole('button', { name: 'Edit blueprint' }).click(); await frame.getByRole('button', { name: 'About packages' }).click(); @@ -113,19 +114,26 @@ test.describe.serial('test', () => { test('build blueprint', async ({ page }) => { await login(page); const frame = await ibFrame(page); - await frame.getByRole('textbox', { name: 'Search input' }).fill(blueprintName); + await frame + .getByRole('textbox', { name: 'Search input' }) + .fill(blueprintName); await frame.getByText(blueprintName, { exact: true }).first().click(); await frame.getByTestId('blueprint-build-image-menu-option').click(); // make sure the image is present - await frame.getByTestId('images-table').getByRole('button', { name: 'Details' }).click(); + await frame + .getByTestId('images-table') + .getByRole('button', { name: 'Details' }) + .click(); await frame.getByText('Build Information'); }); test('delete blueprint', async ({ page }) => { await login(page); const frame = await ibFrame(page); - await frame.getByRole('textbox', { name: 'Search input' }).fill(blueprintName); + await frame + .getByRole('textbox', { name: 'Search input' }) + .fill(blueprintName); await frame.getByText(blueprintName, { exact: true }).first().click(); await frame.getByTestId('blueprint-action-menu-toggle').click(); await frame.getByRole('menuitem', { name: 'Delete blueprint' }).click();