Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import test, { expect } from "playwright/test";
- import { UiTester } from "@/test/fd-test-ui-tester/ui-tester";
- import {
- editPoClickSaveButton,
- editPoSetInputValue,
- editPoToggleBooleanField,
- editPoWaitForUrl,
- } from "@/test/meta/fd-meta-tester-ui/page-objects/edit-po";
- import { listPoGoTo } from "@/test/meta/fd-meta-tester-ui/page-objects/list-po";
- import { tablePoClickEditButton } from "@/test/meta/fd-meta-tester-ui/page-objects/table-po";
- import { resourceNames, personProps, routes, elementSuffixes, withIdProps } from "@fernir2/saas-kit";
- import { login } from "@/test/ui-tests/auth/login-po";
- import { getUiTestPage } from "@/test/fd-test-ui-tester/global-ui-test";
- import { selectWorkspacePoSelectWorkspace } from "@/test/meta/fd-meta-tester-ui/page-objects/select-workspace-po";
- import { getResourceById, getCurrentWorkspaceId } from "@fernir2/saas-kit/server";
- import { SeedTestData, seedTestData } from "@/test/test-data/seed-test-data";
- import { uiAssertEqual } from "@/test/fd-test-ui-tester/ui-asserts";
- test.describe("Dependent fields validation", () => {
- let testData: SeedTestData;
- test.beforeEach(async () => {
- const uiTester = new UiTester(getUiTestPage());
- const workspaceId = await getCurrentWorkspaceId();
- testData = await seedTestData(workspaceId);
- await login();
- await uiTester.expectUrl(routes.view);
- await listPoGoTo(resourceNames.person);
- await selectWorkspacePoSelectWorkspace(workspaceId);
- await tablePoClickEditButton((testData.samBrownPerson as any)[withIdProps.id]);
- await editPoWaitForUrl(resourceNames.person, (testData.samBrownPerson as any)[withIdProps.id]);
- });
- test("Dependent fields are not required when 'Has kids' is off", async () => {
- // Arrange
- await editPoToggleBooleanField(personProps.hasKids); // Turn off
- // Act
- await editPoSetInputValue(personProps.firstbornName, "");
- // Assert
- await editAssertHasNoValidationError(personProps.firstbornName);
- await editAssertHasNoValidationError(personProps.areKidsVaccinated);
- });
- test("Dependent fields become required when 'Has kids' is on", async () => {
- // Arrange
- // 'Has kids' is on by default
- // Act
- await editPoSetInputValue(personProps.firstbornName, "");
- await editPoToggleBooleanField(personProps.areKidsVaccinated); // Turn off
- // Assert
- await editAssertHasValidationError(personProps.firstbornName);
- await editAssertHasValidationError(personProps.areKidsVaccinated);
- });
- test("Validation errors disappear after filling the fields", async () => {
- // Arrange
- // 'Has kids' is on by default
- // Act
- await editPoSetInputValue(personProps.firstbornName, "John");
- await editPoToggleBooleanField(personProps.areKidsVaccinated); // Turn on
- // Assert
- await editAssertHasNoValidationError(personProps.firstbornName);
- await editAssertHasNoValidationError(personProps.areKidsVaccinated);
- });
- test("Saves and verifies the data", async () => {
- // Arrange
- // 'Has kids' is on by default
- // Act
- await editPoSetInputValue(personProps.firstbornName, "Jane");
- await editPoToggleBooleanField(personProps.areKidsVaccinated); // Turn on
- await editPoClickSaveButton(resourceNames.person);
- const person = await getResourceById<any>(
- resourceNames.person,
- (testData.samBrownPerson as any)[withIdProps.id],
- );
- // Assert
- expect(person.hasKids).toBe(true);
- expect(person.areKidsVaccinated).toBe(true);
- expect(person.firstbornName).toBe("Jane");
- });
- });
- export async function editAssertHasValidationError(propertyName: string) {
- const page = getUiTestPage();
- const uiTester = new UiTester(page);
- const elementId = propertyName + elementSuffixes.edit;
- const element = await uiTester.getById(elementId);
- await uiAssertEqual("true", await element.getAttribute("aria-invalid"));
- }
- export async function editAssertHasNoValidationError(propertyName: string) {
- const page = getUiTestPage();
- const uiTester = new UiTester(page);
- const elementId = propertyName + elementSuffixes.edit;
- const element = await uiTester.getById(elementId);
- await uiAssertEqual(null, await element.getAttribute("aria-invalid"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement