Skip to content

Commit

Permalink
test: Update the e2e test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
harshthakkr committed Jan 25, 2025
1 parent db6dc01 commit b593bee
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 4 deletions.
15 changes: 13 additions & 2 deletions e2e/pages/form-builder-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export class FormBuilderPage {
readonly renderChangesButton = () => this.page.getByRole('button', { name: /render changes/i });
readonly inputDummySchemaButton = () => this.page.getByRole('button', { name: /input dummy schema/i });
readonly saveFormButton = () => this.page.getByRole('button', { name: /save form/i });
readonly editFormButton = () => this.page.getByRole('button', { name: /edit schema/i });
readonly deleteFormConfirmationButton = () => this.page.getByRole('button', { name: /danger delete/i });
readonly publishFormButton = () => this.page.getByRole('button', { name: /^publish form$/i });
readonly unpublishFormButton = () => this.page.getByRole('button', { name: /unpublish form/i });
readonly unpublishFormConfirmationButton = () =>
Expand All @@ -27,18 +29,28 @@ export class FormBuilderPage {
readonly interactiveFormNameInput = () => this.page.getByRole('textbox', { name: /form name/i });
readonly interactiveFormDescriptionInput = () => this.page.getByRole('textbox', { name: /form description/i });
readonly createFormButton = () => this.page.getByRole('button', { name: /create form/i });
readonly editFormNameInput = () => this.page.locator('#formNameInput');
readonly addPageButton = () => this.page.getByRole('button', { name: /add page/i });
readonly pageNameInput = () =>
this.page.getByRole('textbox', {
name: /enter a title for your new page/i,
});
readonly savePageButton = () => this.page.getByRole('button', { name: /^save$/i, exact: true });
readonly editPageButton = () => this.page.getByRole('button', { name: /edit page/i });
readonly editPageNameInput = () => this.page.locator('#pageNameInput');
readonly deletePageButton = () => this.page.getByRole('button', { name: /delete page/i });
readonly saveButton = () => this.page.getByRole('button', { name: /^save$/i, exact: true });
readonly pageCreatedMessage = () => this.page.getByText(/new page created/i);
readonly addSectionButton = () => this.page.getByRole('button', { name: /add section/i });
readonly sectionNameInput = () => this.page.getByRole('textbox', { name: /enter a section title/i });
readonly saveSectionButton = () => this.page.getByRole('button', { name: /^save$/i, exact: true });
readonly editSectionButton = () => this.page.getByRole('button', { name: /edit section/i });
readonly editSectionNameInput = () => this.page.locator('#sectionNameInput');
readonly deleteSectionButton = () => this.page.getByRole('button', { name: /delete section/i });
readonly sectionCreatedMessage = () => this.page.getByText(/new section created/i);
readonly addQuestionButton = () => this.page.getByRole('button', { name: /add question/i });
readonly editQuestionButton = () => this.page.getByRole('button', { name: /edit question/i });
readonly duplicateQuestionButton = () => this.page.getByRole('button', { name: /duplicate question/i });
readonly deleteQuestionButton = () => this.page.getByRole('button', { name: /delete question/i }).nth(0);
readonly questionLabelInput = () => this.page.getByRole('textbox', { name: /label/i });
readonly questionTypeDropdown = () =>
this.page.getByRole('combobox', {
Expand All @@ -53,7 +65,6 @@ export class FormBuilderPage {
readonly answer = () => this.page.getByRole('menuitem', { name: /tested for covid 19/i });
readonly questionIdInput = () => this.page.getByRole('textbox', { name: /question id/i });
readonly questionCreatedMessage = () => this.page.getByText(/new question created/i);
readonly saveQuestionButton = () => this.page.getByRole('button', { name: /^save$/i, exact: true });

async gotoFormBuilder() {
await this.page.goto('form-builder');
Expand Down
46 changes: 46 additions & 0 deletions e2e/specs/delete-existing-form.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { test } from '../core';
import { createForm, createValueReference, addFormResources, deleteForm } from '../commands/form-operations';
import type { Form } from '../../src/types';
import { FormBuilderPage } from '../pages';
import { expect } from '@playwright/test';

let form: Form = null;
test.beforeEach(async ({ api }) => {
form = await createForm(api, false);
const valueReference = await createValueReference(api);
await addFormResources(api, valueReference, form.uuid);
});

test('Delete an existing form', async ({ page }) => {
const formBuilderPage = new FormBuilderPage(page);

await test.step('When I visit the form builder', async () => {
await formBuilderPage.gotoFormBuilder();
});

await test.step('And I search for the form I need to delete', async () => {
await formBuilderPage.searchForForm(form.name);
});

await test.step('And I click the `Delete` button on the form I need to delete', async () => {
await formBuilderPage.page
.getByRole('row', { name: form.name })
.getByLabel(/delete schema/i)
.click();
});

await test.step('Then I click the `Delete` button on the modal', async () => {
await formBuilderPage.deleteFormConfirmationButton().click();
});

await test.step('Then I should get a success message and the row with the form name should be removed', async () => {
await expect(formBuilderPage.page.getByText(/form deleted/i)).toBeVisible();
await expect(formBuilderPage.page.getByRole('row', { name: form.name })).toHaveCount(0);
});
});

test.afterEach(async ({ api }) => {
if (form) {
await deleteForm(api, form.uuid);
}
});
41 changes: 41 additions & 0 deletions e2e/specs/download-existing-form.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { test } from '../core';
import { createForm, createValueReference, addFormResources, deleteForm } from '../commands/form-operations';
import type { Form } from '../../src/types';
import { FormBuilderPage } from '../pages';
import { expect } from '@playwright/test';

let form: Form = null;

test.beforeEach(async ({ api }) => {
form = await createForm(api, false);
const valueReference = await createValueReference(api);
await addFormResources(api, valueReference, form.uuid);
});

test('Download an existing form', async ({ page }) => {
const formBuilderPage = new FormBuilderPage(page);

await test.step('When I visit the form builder', async () => {
await formBuilderPage.gotoFormBuilder();
});

await test.step('And I search for the form I need to download', async () => {
await formBuilderPage.searchForForm(form.name);
});

await test.step('And I click the `Download` button on the form I need to download', async () => {
const downloadPromise = page.waitForEvent('download');
await formBuilderPage.page
.getByRole('row', { name: form.name })
.getByLabel(/download schema/i)
.click();
const download = await downloadPromise;
expect(download).toBeDefined();
});
});

test.afterEach(async ({ api }) => {
if (form) {
await deleteForm(api, form.uuid);
}
});
121 changes: 119 additions & 2 deletions e2e/specs/interactive-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test('Create a form using the interactive builder', async ({ page, context }) =>
});

await test.step('And then I click on `Save`', async () => {
await formBuilderPage.savePageButton().click();
await formBuilderPage.saveButton().click();
await expect(formBuilderPage.page.getByText(/new page created/i)).toBeVisible();
expect(JSON.parse(await formBuilderPage.schemaEditorContent().textContent())).toEqual({
...formDetails,
Expand Down Expand Up @@ -178,7 +178,7 @@ test('Create a form using the interactive builder', async ({ page, context }) =>
});

await test.step('And then I click on `Save`', async () => {
await formBuilderPage.saveQuestionButton().click();
await formBuilderPage.saveButton().click();
await expect(formBuilderPage.page.getByText(/new question created/i)).toBeVisible();
});

Expand Down Expand Up @@ -224,6 +224,123 @@ test('Create a form using the interactive builder', async ({ page, context }) =>
const editFormPageURL = page.url();
formUuid = editFormPageURL.split('/').slice(-1)[0];
});

await test.step('Then I click the `Edit` button on the form name I need to edit', async () => {
await formBuilderPage.editFormButton().click();
});

await test.step('And then I fill in the updated form name', async () => {
await formBuilderPage.editFormNameInput().click();
await formBuilderPage.editFormNameInput().fill('An edited form');
});

await test.step('And then I click the `save` button', async () => {
await formBuilderPage.saveButton().click();
});

await test.step('Then I should get a success message and the form name should be renamed', async () => {
await expect(formBuilderPage.page.getByText(/form renamed/i)).toBeVisible();
await expect(formBuilderPage.page.getByRole('heading', { level: 1, name: /an edited form/i })).toBeVisible();
});

await test.step('Then I click the `Edit` button on the page I need to edit', async () => {
await formBuilderPage.editPageButton().click();
});

await test.step('And then I fill in the updated page name', async () => {
await formBuilderPage.editPageNameInput().fill('An edited page');
});

await test.step('Then I click the `Save` button', async () => {
await formBuilderPage.saveButton().click();
});

await test.step('Then I should get a success message and the page name should be renamed', async () => {
await expect(formBuilderPage.page.getByText(/page renamed/i)).toBeVisible();
await expect(formBuilderPage.page.getByRole('heading', { level: 1, name: /an edited page/i })).toBeVisible();
});

await test.step('Then I click the `Edit` button on the section I need to edit', async () => {
await formBuilderPage.editSectionButton().click();
});

await test.step('And then I fill in the updated section name', async () => {
await formBuilderPage.editSectionNameInput().fill('An edited section');
});

await test.step('Then I click the `Save` button', async () => {
await formBuilderPage.saveButton().click();
});

await test.step('Then I should get a success message and the section name should be renamed', async () => {
await expect(formBuilderPage.page.getByText(/section renamed/i)).toBeVisible();
await expect(formBuilderPage.page.getByRole('heading', { level: 1, name: /an edited section/i })).toBeVisible();
});

await test.step('Then I click the `Edit` button on the question I need to edit', async () => {
await formBuilderPage.editQuestionButton().click();
});

await test.step('And then I type in the updated question label', async () => {
await formBuilderPage.questionLabelInput().fill('An edited question label');
});

await test.step('Then I click the `Save` button', async () => {
await formBuilderPage.saveButton().click();
});

await test.step('Then I should get a success message and the question name should be renamed', async () => {
await expect(formBuilderPage.page.getByText(/question edited/i)).toBeVisible();
await expect(formBuilderPage.page.locator('p').getByText(/an edited question label/i)).toBeVisible();
});

await test.step('Then I click the `Duplicate` button on the question I need to duplicate', async () => {
await formBuilderPage.duplicateQuestionButton().click();
});

await test.step('Then I should get a success message and a duplicate quesion should be added', async () => {
await expect(formBuilderPage.page.getByText(/question duplicated/i)).toBeVisible();
await expect(formBuilderPage.page.locator('p').getByText(/an edited question label/i)).toHaveCount(2);
});

await test.step('Then I click the `Delete` button on the question I need to delete', async () => {
await formBuilderPage.deleteQuestionButton().click();
});

await test.step('And then I click the `Delete` button on the modal', async () => {
await formBuilderPage.page.getByRole('button', { name: /danger delete question/i }).click();
});

await test.step('Then I should get a success message and a question should be deleted', async () => {
await expect(formBuilderPage.page.getByText(/question deleted/i)).toBeVisible();
await expect(formBuilderPage.page.locator('p').getByText(/an edited question label/i)).toHaveCount(1);
});

await test.step('Then I click the `Delete` button on the section I need to delete', async () => {
await formBuilderPage.deleteSectionButton().click();
});

await test.step('And then I click the `Delete` button on the modal', async () => {
await formBuilderPage.page.getByRole('button', { name: /danger delete section/i }).click();
});

await test.step('Then I should get a success message and the section should be deleted', async () => {
await expect(formBuilderPage.page.getByText(/section deleted/i)).toBeVisible();
await expect(formBuilderPage.page.getByRole('heading', { level: 1, name: /an edited section/i })).toHaveCount(0);
});

await test.step('Then I click the `Delete` button on the page I need to delete', async () => {
await formBuilderPage.deletePageButton().click();
});

await test.step('And then I click the `Delete` button on the modal', async () => {
await formBuilderPage.page.getByRole('button', { name: /danger delete page/i }).click();
});

await test.step('Then I should get a success message and the page should be deleted', async () => {
await expect(formBuilderPage.page.getByText(/page deleted/i)).toBeVisible();
await expect(formBuilderPage.page.getByRole('heading', { level: 1, name: /an edited page/i })).toHaveCount(0);
});
});

test.afterEach(async ({ api }) => {
Expand Down

0 comments on commit b593bee

Please sign in to comment.