Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ function ActivityDefinitionFormContent({
const { t } = useTranslation();

const formSchema = z.object({
title: z.string().min(1, t("field_required")),
title: z.string().trim().min(1, t("field_required")),
Comment thread
Valyrian-Code marked this conversation as resolved.
slug_value: z
.string()
.min(5, t("character_count_validation", { min: 5, max: 25 }))
.max(25, t("character_count_validation", { min: 5, max: 25 })),
description: z.string().min(1, t("field_required")),
usage: z.string().min(1, t("field_required")),
description: z.string().trim().min(1, t("field_required")),
usage: z.string().trim().min(1, t("field_required")),
Comment thread
Valyrian-Code marked this conversation as resolved.
Comment thread
Valyrian-Code marked this conversation as resolved.
derived_from_uri: z.string().nullable(),
status: z.nativeEnum(Status),
classification: z.nativeEnum(Classification),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ function ObservationDefinitionFormContent({

const formSchema = z
.object({
title: z.string().min(1, t("field_required")),
title: z.string().trim().min(1, t("field_required")),
Comment thread
Valyrian-Code marked this conversation as resolved.
slug_value: z
.string()
.min(5, t("character_count_validation", { min: 5, max: 25 }))
.max(25, t("character_count_validation", { min: 5, max: 25 })),
description: z.string().min(1, t("field_required")),
description: z.string().trim().min(1, t("field_required")),
Comment thread
Valyrian-Code marked this conversation as resolved.
Comment thread
Valyrian-Code marked this conversation as resolved.
status: z.nativeEnum(ObservationDefinitionStatus),
category: z.enum(
OBSERVATION_DEFINITION_CATEGORY as [string, ...string[]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ function SpecimenDefinitionFormContent({
const isEditMode = Boolean(specimenSlug);

const formSchema = z.object({
title: z.string().min(1, t("field_required")),
title: z.string().trim().min(1, t("field_required")),
Comment thread
Valyrian-Code marked this conversation as resolved.
slug_value: z
.string()
.min(5, t("character_count_validation", { min: 5, max: 25 }))
.max(25, t("character_count_validation", { min: 5, max: 25 })),
status: z.nativeEnum(SpecimenDefinitionStatus),
description: z.string().min(1, t("field_required")),
description: z.string().trim().min(1, t("field_required")),
Comment thread
Valyrian-Code marked this conversation as resolved.
derived_from_uri: z
.string()
.url({ message: t("field_required") })
Comment thread
Valyrian-Code marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ test.describe("activity definition form", () => {
);
});

test("should reject a whitespace-only title", async ({ page }) => {
await page.goto(
`/facility/${facilityId}/settings/activity_definitions/categories/f-${facilityId}-${RESOURCE_CATEGORY_SLUG}/new`,
);

const titleInput = page.getByRole("textbox", { name: "Title *" });
await titleInput.fill(" ");
await page.getByRole("button", { name: "Create" }).click();

// Whitespace-only title must be treated as empty.
await expect(getFieldErrorMessage(titleInput)).toBeVisible();
});
Comment thread
Valyrian-Code marked this conversation as resolved.
Outdated
Comment thread
Valyrian-Code marked this conversation as resolved.
Outdated

test("should create activity definition with required fields", async ({
page,
}) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { faker } from "@faker-js/faker";

import { expect, test } from "@playwright/test";
import { getFieldErrorMessage } from "tests/helper/error";
import { getFacilityId } from "tests/support/facilityId";

const UNITS = [
Expand Down Expand Up @@ -201,6 +202,15 @@ test.describe("Observation Definition Form with Interpretation", () => {
await page.goto(targetUrl);
});

test("should reject a whitespace-only title", async ({ page }) => {
const titleInput = page.getByRole("textbox", { name: "Title" });
await titleInput.fill(" ");
await page.getByRole("button", { name: "Create" }).click();

// Whitespace-only title must be treated as empty.
await expect(getFieldErrorMessage(titleInput)).toBeVisible();
});

test("should create observation definition with root-level interpretation", async ({
page,
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ test.describe("Specimen Definitions Create", () => {
await page.goto(targetUrl);
});

test("should reject a whitespace-only title", async ({ page }) => {
await page.getByRole("button", { name: "Add Definition" }).click();

const titleInput = page.getByRole("textbox", { name: "Title *" });
await titleInput.fill(" ");
await page.getByRole("button", { name: /save/i }).click();

// Whitespace-only title must be treated as empty.
await expect(getFieldErrorMessage(titleInput)).toBeVisible();
});

test("should create specimen definition with all fields", async ({
page,
}) => {
Expand Down
Loading