feat(web): object-form visibility uses ui/Select (#51)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { expect, test, vi } from "vitest";
|
import { expect, test, vi } from "vitest";
|
||||||
import { fireEvent, screen, waitFor } from "@testing-library/react";
|
import { fireEvent, screen, waitFor, within } from "@testing-library/react";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
import { renderApp } from "../test/render";
|
import { renderApp } from "../test/render";
|
||||||
import { ObjectForm } from "./object-form";
|
import { ObjectForm } from "./object-form";
|
||||||
@@ -13,10 +13,11 @@ test("create mode: shows visibility (draft/internal only) and submits assembled
|
|||||||
await userEvent.type(screen.getByLabelText(/^name/i), "Amphora");
|
await userEvent.type(screen.getByLabelText(/^name/i), "Amphora");
|
||||||
await userEvent.type(screen.getByLabelText(/inscription/i), "To the gods");
|
await userEvent.type(screen.getByLabelText(/inscription/i), "To the gods");
|
||||||
|
|
||||||
const visibility = screen.getByLabelText(/visibility/i) as HTMLSelectElement;
|
await userEvent.click(screen.getByRole("combobox", { name: /visibility/i })); // open
|
||||||
expect([...visibility.options].map((o) => o.value)).toEqual(expect.arrayContaining(["draft", "internal"]));
|
expect(await within(document.body).findByRole("option", { name: /draft/i })).toBeInTheDocument();
|
||||||
expect([...visibility.options].map((o) => o.value)).not.toContain("public");
|
expect(within(document.body).getByRole("option", { name: /internal/i })).toBeInTheDocument();
|
||||||
|
expect(within(document.body).queryByRole("option", { name: /public/i })).not.toBeInTheDocument();
|
||||||
|
await userEvent.keyboard("{Escape}"); // close, keep default draft
|
||||||
await userEvent.click(screen.getByRole("button", { name: /create object/i }));
|
await userEvent.click(screen.getByRole("button", { name: /create object/i }));
|
||||||
await waitFor(() => expect(onSubmit).toHaveBeenCalledOnce());
|
await waitFor(() => expect(onSubmit).toHaveBeenCalledOnce());
|
||||||
const values = onSubmit.mock.calls[0][0];
|
const values = onSubmit.mock.calls[0][0];
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import { useFieldDefinitions } from "../api/queries";
|
import { useFieldDefinitions } from "../api/queries";
|
||||||
@@ -11,6 +11,7 @@ import { useUnsavedChanges } from "../lib/use-unsaved-changes";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||||
|
|
||||||
export type ObjectCore = {
|
export type ObjectCore = {
|
||||||
object_number: string;
|
object_number: string;
|
||||||
@@ -176,14 +177,21 @@ export function ObjectForm({
|
|||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label htmlFor="visibility">{t("form.visibility")}</Label>
|
<Label htmlFor="visibility">{t("form.visibility")}</Label>
|
||||||
|
|
||||||
<select
|
<Controller
|
||||||
id="visibility"
|
control={form.control}
|
||||||
className="w-full rounded-md border px-2 py-1 text-sm"
|
name="visibility"
|
||||||
{...register("visibility")}
|
render={({ field }) => (
|
||||||
>
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
<option value="draft">{t("form.draft")}</option>
|
<SelectTrigger id="visibility">
|
||||||
<option value="internal">{t("form.internal")}</option>
|
<SelectValue />
|
||||||
</select>
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="draft">{t("form.draft")}</SelectItem>
|
||||||
|
<SelectItem value="internal">{t("form.internal")}</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user