From 50e3fb00215a8b57f84074527adcda6e069923a6 Mon Sep 17 00:00:00 2001 From: Arthur Belleville Date: Sat, 16 May 2026 13:59:21 +0200 Subject: [PATCH] test(13-03): add failing tests for Select and FormField components (RED) - TestSelect_RendersControl: expects ui-select-control in output - TestSelect_HasInlineScript: expects __uiSelectInitAll in script block - TestSelect_HasHtmxListener: expects htmx:afterSwap re-init listener - TestFormField_RendersLabel: expects ui-form-field and ui-form-label - TestFormField_RendersError: expects ui-form-error when Error is set - TestFormField_NoErrorWhenEmpty: expects no ui-form-error when Error is empty --- backend/internal/web/ui/ui_test.go | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/backend/internal/web/ui/ui_test.go b/backend/internal/web/ui/ui_test.go index 468a90d..4000ad1 100644 --- a/backend/internal/web/ui/ui_test.go +++ b/backend/internal/web/ui/ui_test.go @@ -280,3 +280,69 @@ func TestTextarea_ExplicitRows(t *testing.T) { t.Errorf("expected rows=\"6\"; got: %s", out) } } + +// Phase 13 Plan 03 — Select and FormField component tests (TDD RED) + +func TestSelect_RendersControl(t *testing.T) { + out := render(t, context.Background(), Select(SelectProps{ + Name: "status", + Options: []SelectOption{{Value: "a", Label: "Alpha"}}, + })) + if !strings.Contains(out, "ui-select-control") { + t.Errorf("expected ui-select-control in output; got: %s", out) + } +} + +func TestSelect_HasInlineScript(t *testing.T) { + out := render(t, context.Background(), Select(SelectProps{ + Name: "status", + Options: []SelectOption{{Value: "a", Label: "Alpha"}}, + })) + if !strings.Contains(out, "__uiSelectInitAll") { + t.Errorf("expected __uiSelectInitAll in output (inline JS); got: %s", out) + } +} + +func TestSelect_HasHtmxListener(t *testing.T) { + out := render(t, context.Background(), Select(SelectProps{ + Name: "status", + Options: []SelectOption{{Value: "a", Label: "Alpha"}}, + })) + if !strings.Contains(out, "htmx:afterSwap") { + t.Errorf("expected htmx:afterSwap in output (re-init listener); got: %s", out) + } +} + +func TestFormField_RendersLabel(t *testing.T) { + out := render(t, context.Background(), FormField(FormFieldProps{ + Label: "Name", + For: "name-input", + })) + for _, want := range []string{"ui-form-field", "ui-form-label"} { + if !strings.Contains(out, want) { + t.Errorf("expected %q in output; got: %s", want, out) + } + } +} + +func TestFormField_RendersError(t *testing.T) { + out := render(t, context.Background(), FormField(FormFieldProps{ + Label: "Name", + For: "name-input", + Error: "This field is required", + })) + if !strings.Contains(out, "ui-form-error") { + t.Errorf("expected ui-form-error in output when Error is set; got: %s", out) + } +} + +func TestFormField_NoErrorWhenEmpty(t *testing.T) { + out := render(t, context.Background(), FormField(FormFieldProps{ + Label: "Name", + For: "name-input", + Error: "", + })) + if strings.Contains(out, "ui-form-error") { + t.Errorf("expected NO ui-form-error in output when Error is empty; got: %s", out) + } +}