diff --git a/tests/facility/patient/encounter/encounterFormHelpers.ts b/tests/facility/patient/encounter/encounterFormHelpers.ts new file mode 100644 index 00000000000..6b295630b5e --- /dev/null +++ b/tests/facility/patient/encounter/encounterFormHelpers.ts @@ -0,0 +1,53 @@ +import { faker } from "@faker-js/faker"; +import { expect, type Page } from "@playwright/test"; +import { ENCOUNTER_CLASSES } from "tests/facility/patient/encounter/encounterClasses"; +import { getFacilityId } from "tests/support/facilityId"; +import { getPatientId } from "tests/support/patientId"; + +export async function openCreateEncounterDialog(page: Page) { + const facilityId = getFacilityId(); + const patientId = getPatientId(); + + await page.goto(`/facility/${facilityId}/patient/${patientId}`); + await page.getByRole("link", { name: "Patient Home" }).click(); + + await expect( + page.getByRole("button", { name: "Create Encounter" }), + ).toBeVisible(); + await page.getByRole("button", { name: "Create Encounter" }).click(); +} + +export async function selectRandomEncounterClass(page: Page) { + const randomClass = faker.helpers.arrayElement(ENCOUNTER_CLASSES); + await page.getByRole("button", { name: randomClass }).click(); +} + +export async function selectStatusInCreateDialog(page: Page, status: string) { + await page.getByRole("combobox", { name: "Status" }).click(); + await page.getByRole("option", { name: status, exact: true }).click(); +} + +export async function openCalendarAndGetNextMonthButton(page: Page) { + await page + .locator('[data-slot="form-item"]') + .filter({ hasText: "Date and Time" }) + .locator('[data-slot="popover-trigger"]') + .click(); + + const nextMonthButton = page.getByRole("button", { + name: "Go to the Next Month", + }); + await expect(nextMonthButton).toBeVisible(); + return nextMonthButton; +} + +export function getFutureDateButtonFromCalendar(page: Page) { + return page + .getByRole("gridcell") + .filter({ hasText: /^15$/ }) + .getByRole("button"); +} + +export function getEncounterCreateDialog(page: Page) { + return page.getByRole("dialog", { name: "Initiate Patient Encounter" }); +} diff --git a/tests/facility/patient/encounter/encounterFutureDateRestriction.spec.ts b/tests/facility/patient/encounter/encounterFutureDateRestriction.spec.ts index b1642741535..420a85f3350 100644 --- a/tests/facility/patient/encounter/encounterFutureDateRestriction.spec.ts +++ b/tests/facility/patient/encounter/encounterFutureDateRestriction.spec.ts @@ -1,57 +1,17 @@ -import { faker } from "@faker-js/faker"; -import { expect, test, type Page } from "@playwright/test"; -import { ENCOUNTER_CLASSES } from "tests/facility/patient/encounter/encounterClasses"; -import { getFacilityId } from "tests/support/facilityId"; -import { getPatientId } from "tests/support/patientId"; +import { expect, test } from "@playwright/test"; +import { + getEncounterCreateDialog as getEncounterDialog, + getFutureDateButtonFromCalendar, + openCalendarAndGetNextMonthButton, + openCreateEncounterDialog, + selectRandomEncounterClass, +} from "tests/facility/patient/encounter/encounterFormHelpers"; test.use({ storageState: "tests/.auth/user.json" }); -async function openEncounterForm(page: Page) { - const facilityId = getFacilityId(); - const patientId = getPatientId(); - - await page.goto(`/facility/${facilityId}/patient/${patientId}`); - await page.getByRole("link", { name: "Patient Home" }).click(); - - await expect( - page.getByRole("button", { name: "Create Encounter" }), - ).toBeVisible(); - await page.getByRole("button", { name: "Create Encounter" }).click(); -} - -async function selectRandomEncounterClass(page: Page) { - const randomClass = faker.helpers.arrayElement(ENCOUNTER_CLASSES); - await page.getByRole("button", { name: randomClass }).click(); -} - -async function openCalendarAndGetNextMonthButton(page: Page) { - await page - .locator('[data-slot="form-item"]') - .filter({ hasText: "Date and Time" }) - .locator('[data-slot="popover-trigger"]') - .click(); - - const nextMonthButton = page.getByRole("button", { - name: "Go to the Next Month", - }); - await expect(nextMonthButton).toBeVisible(); - return nextMonthButton; -} - -function getFutureDateButtonFromCalendar(page: Page) { - return page - .getByRole("gridcell") - .filter({ hasText: /^15$/ }) - .getByRole("button"); -} - -function getEncounterDialog(page: Page) { - return page.getByRole("dialog", { name: "Initiate Patient Encounter" }); -} - test.describe("Encounter Future Date Restriction", () => { test.beforeEach(async ({ page }) => { - await openEncounterForm(page); + await openCreateEncounterDialog(page); }); test("should disable future dates when status is In Progress", async ({ diff --git a/tests/facility/patient/encounter/encounterPlannedStatusTransition.spec.ts b/tests/facility/patient/encounter/encounterPlannedStatusTransition.spec.ts new file mode 100644 index 00000000000..c4944d0d173 --- /dev/null +++ b/tests/facility/patient/encounter/encounterPlannedStatusTransition.spec.ts @@ -0,0 +1,189 @@ +import { expect, test, type Page } from "@playwright/test"; +import { + getEncounterCreateDialog, + getFutureDateButtonFromCalendar, + openCalendarAndGetNextMonthButton, + openCreateEncounterDialog, + selectRandomEncounterClass, + selectStatusInCreateDialog, +} from "tests/facility/patient/encounter/encounterFormHelpers"; + +test.use({ storageState: "tests/.auth/user.json" }); + +const VALIDATION_ERROR_TEXT = + "period: Value error, Start Date cannot be greater than End Date"; + +async function selectFutureDateInCalendar(page: Page) { + const nextMonthButton = await openCalendarAndGetNextMonthButton(page); + await expect(nextMonthButton).toBeEnabled(); + await nextMonthButton.click(); + + const futureDayButton = getFutureDateButtonFromCalendar(page); + await expect(futureDayButton).toBeEnabled(); + await futureDayButton.click(); +} + +async function createPlannedEncounterWithFutureDate(page: Page) { + await openCreateEncounterDialog(page); + await selectRandomEncounterClass(page); + await selectStatusInCreateDialog(page, "Planned"); + await selectFutureDateInCalendar(page); + + const dialog = getEncounterCreateDialog(page); + await dialog.getByRole("button", { name: /^Create Encounter/ }).click(); + + // Submit navigates to the encounter detail page. + await page.waitForURL(/\/encounter\/[^/]+/); + await expect( + page.getByRole("button", { name: "Encounter Actions" }), + ).toBeVisible(); +} + +// Update-encounter form uses a bare