From 392e672ab7325c733f1587b95aa5ad5b743529a8 Mon Sep 17 00:00:00 2001 From: Nethmi Rodrigo Date: Tue, 10 Sep 2024 12:02:09 +0300 Subject: [PATCH] (chore): Update the filter form e2e test --- e2e/pages/form-builder-page.ts | 34 ------------------------------- e2e/specs/forms-dashboard.spec.ts | 20 ++++++++---------- 2 files changed, 8 insertions(+), 46 deletions(-) diff --git a/e2e/pages/form-builder-page.ts b/e2e/pages/form-builder-page.ts index e5c9064..4f6107b 100644 --- a/e2e/pages/form-builder-page.ts +++ b/e2e/pages/form-builder-page.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ import type { Page } from '@playwright/test'; -import { expect } from '@playwright/test'; export class FormBuilderPage { constructor(readonly page: Page) {} @@ -60,39 +59,6 @@ export class FormBuilderPage { await this.page.goto('form-builder'); } - async buildFormInteractively() { - await this.interactiveBuilderTab().click(); - await this.startBuildingButton().click(); - await this.interactiveFormNameInput().fill('Covid-19 Screening'); - await this.interactiveFormDescriptionInput().fill('A test form for recording COVID-19 screening information'); - await this.createFormButton().click(); - await expect(this.page.getByText(/form created/i)).toBeVisible(); - - await this.addPageButton().click(); - await this.pageNameInput().fill('Screening'); - await this.savePageButton().click(); - await expect(this.page.getByText(/new page created/i)).toBeVisible(); - - await this.addSectionButton().click(); - await this.sectionNameInput().fill('Testing history'); - await this.saveSectionButton().click(); - await expect(this.page.getByText(/new section created/i)).toBeVisible(); - - await this.page.getByRole('button', { name: /^testing history$/i }).click(); - await this.addQuestionButton().click(); - await this.questionLabelInput().fill('Have you been ever been tested for COVID-19?'); - await this.questionIdInput().fill('everTestedForCovid19'); - await this.questionTypeDropdown().selectOption('obs'); - await this.renderingTypeDropdown().selectOption('radio'); - await this.conceptSearchInput().fill('Tested for COVID 19'); - await this.conceptSearchInput().press('Enter'); - await this.answer().click(); - await this.selectAnswersDropdown().click(); - await this.page.getByRole('option', { name: 'No' }).click(); - await this.page.getByRole('option', { name: 'Yes' }).click(); - await this.saveQuestionButton().click(); - } - async saveForm() { const formName = `A sample test form ${Math.floor(Math.random() * 10000)}`; diff --git a/e2e/specs/forms-dashboard.spec.ts b/e2e/specs/forms-dashboard.spec.ts index 2ec7a18..ade7088 100644 --- a/e2e/specs/forms-dashboard.spec.ts +++ b/e2e/specs/forms-dashboard.spec.ts @@ -20,20 +20,16 @@ test('Filter forms based on publish status', async ({ page }) => { // Test the filter functionality await test.step('Then I click the filter dropdown', async () => { - await page.getByText('Filter by:').click(); + await formBuilderPage.page.getByRole('combobox', { name: /Filter by:/i }).click(); }); - await test.step('And I click the Unpublished option', async () => await page.getByText('Unpublished').click()); + await test.step('And I click the Unpublished option', async () => + await formBuilderPage.page.getByText(/Unpublished/i).click()); - // Expect the publish status to be "No" - const tagElements = await page.$$('div[data-testid="no-tag"]'); - const firstTagElement = tagElements[0]; - - // Get the inner text of the tag element - const innerText = await firstTagElement.innerText(); - await test.step('Then the forms list should only show unpublished forms', () => { - expect(innerText).toBe('No'); - }); + // Expect the list of forms to not have any published forms + await expect( + formBuilderPage.page.getByRole('table').filter({ has: formBuilderPage.page.getByTestId(/yes-tag/i) }), + ).toHaveCount(0); }); test('Search forms by name', async ({ page }) => { @@ -65,7 +61,7 @@ test('Clicking on a form should navigate me to the editor', async ({ page }) => }); await test.step('And I click the `A sample test form` form', async () => { - await page.getByText('A sample test form').click(); + await formBuilderPage.page.getByText('A sample test form').click(); }); await test.step('Then I should be navigated to the editor page', async () => {