diff --git a/packages/frontend/test/e2e/integration/designs.test.spec.ts b/packages/frontend/test/e2e/integration/designs.test.spec.ts index 77ef2144..bd0a2bc4 100644 --- a/packages/frontend/test/e2e/integration/designs.test.spec.ts +++ b/packages/frontend/test/e2e/integration/designs.test.spec.ts @@ -1,5 +1,6 @@ import { expect, test } from '@playwright/test'; import { DemoDataState, DemoDataType } from '../util/demo_data'; +import { createProject } from '../util/helpers'; const designName = 'My Test Design'; test('A User can create an Design with a Name', async ({ page }) => { @@ -45,16 +46,8 @@ test('A User can create an Design with a Name', async ({ page }) => { test('Design Settings are reflected in a Project', async ({ page }) => { const testState = new DemoDataState(); - await page.goto('/projects'); - await page.waitForSelector('text=Projects'); - await page.getByTestId('create-button').click(); - await page.getByLabel('Name').fill('My Design Test Project'); - await page.getByTestId('project-type').getByRole('textbox').fill(designName); - await page.getByTestId('page-loader').waitFor({ state: 'hidden' }); - await page.getByText('No data found').waitFor({ state: 'hidden' }); - const designId = testState.designs.at(testState.designs.length - 1); - await page.getByTestId(`design-${designId}`).click(); - await page.getByTestId('submit-project').click(); + await createProject(page, { projectName: 'My Design Test Project', designId: testState.designs.at(testState.designs.length - 1)!, designName: designName }); + await page.getByRole('link', { name: 'Executive Summary' }).click(); await page.getByLabel('Assignee', { exact: true }).waitFor(); expect(await page.getByRole('textbox').getByText('This is a test executive summary').isVisible()).toBeTruthy(); diff --git a/packages/frontend/test/e2e/integration/projects.spec.ts b/packages/frontend/test/e2e/integration/projects.spec.ts index 9c591069..b03a4864 100644 --- a/packages/frontend/test/e2e/integration/projects.spec.ts +++ b/packages/frontend/test/e2e/integration/projects.spec.ts @@ -1,29 +1,17 @@ import { expect, test } from '@playwright/test'; import { DemoDataState } from '../util/demo_data'; -const projectName = 'My Test Project'; +import { createProject } from '../util/helpers'; +const projectName = 'Updated Project Name'; test('A User can create an Project with a Name', async ({ page }) => { - await page.goto('/projects'); - await page.waitForSelector('text=Projects'); - - expect(await page.title()).toBe('Projects | SysReptor'); - // Create New Design Modal - await page.getByTestId('create-button').click(); - // Create New Design Modal - await page.getByLabel('Name').fill(projectName); - const designId = new DemoDataState().designs[0]; - - await page.getByTestId('project-type').getByRole('textbox').fill('Demo Matrix'); - await page.getByTestId('page-loader').waitFor({ state: 'hidden' }); - await page.getByText('No data found').waitFor({ state: 'hidden' }); - await page.getByTestId('design-' + designId).locator('nth=0').click(); - await page.getByTestId('submit-project').click(); + const oldProjectName = 'My Test Project' + await createProject(page, { projectName: oldProjectName, designId: new DemoDataState().designs[0]!, designName: 'Demo Matrix' }); // Verify Project Name - await expect(page.getByText(projectName)).toBeVisible(); + await expect(page.getByText(oldProjectName)).toBeVisible(); await page.getByTestId('project-settings-tab').click(); await page.getByLabel('Name').waitFor(); - await page.getByLabel('Name').fill('Updated Project Name'); + await page.getByLabel('Name').fill(projectName); await page.getByLabel('Tags').fill('Updated Tags'); await page.keyboard.press('Enter'); await page.getByRole('button', { name: 'Badge' }).click(); @@ -33,11 +21,11 @@ test('A User can create an Project with a Name', async ({ page }) => { test('A User can delete a Project', async ({ page }) => { await page.goto('/projects'); await page.waitForSelector('text=Projects'); - await page.getByRole('link', { name: 'Updated Project Name' }).click(); + await page.getByRole('link', { name: projectName }).click(); await page.getByTestId('project-settings-tab').click(); await page.getByTestId('options-dots').click(); await page.getByText('Delete').click(); - await page.getByTestId('confirm-input').getByRole('textbox').fill('Updated Project Name'); + await page.getByTestId('confirm-input').getByRole('textbox').fill(projectName); await page.getByRole('button', { name: 'Delete' }).click(); await page.waitForSelector('text=Projects'); diff --git a/packages/frontend/test/e2e/util/helpers.ts b/packages/frontend/test/e2e/util/helpers.ts new file mode 100644 index 00000000..20437564 --- /dev/null +++ b/packages/frontend/test/e2e/util/helpers.ts @@ -0,0 +1,22 @@ +import type { Page } from "@playwright/test"; + +export async function createProject(page: Page, options: { projectName: string, designId: string, designName: string }) { + // Click create project button + await page.goto('/projects'); + await page.waitForSelector('text=Projects'); + await page.getByTestId('create-button').click(); + + // Fill project name + await page.getByLabel('Name').fill(options.projectName); + + // Select design + const textbox = await page.getByTestId('project-type').getByRole('textbox'); + textbox.clear(); + textbox.fill(options.designName); + await page.getByTestId('page-loader').waitFor({ state: 'hidden' }); + await page.getByText('No data found').waitFor({ state: 'hidden' }); + await page.getByTestId(`design-${options.designId}`).click(); + + // Create + await page.getByTestId('submit-project').click(); +}