From ace9f5bdc4a287772ba0e8e5ed408b55b96243eb Mon Sep 17 00:00:00 2001 From: Arthur Belleville Date: Sat, 16 May 2026 13:58:19 +0200 Subject: [PATCH] test(13-03): add failing tests for Input and Textarea components (RED) - TestInput_DefaultType: expects type="text" for empty Type - TestInput_EmailType: expects type="email" for explicit Type - TestInput_IDFallback: expects id from Name when no ID set - TestInput_ExplicitID: expects explicit ID to take precedence - TestTextarea_RendersClass: expects class="ui-textarea" - TestTextarea_DefaultRows: expects rows="4" for zero Rows - TestTextarea_ExplicitRows: expects rows="6" for explicit Rows --- backend/internal/web/ui/ui_test.go | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/backend/internal/web/ui/ui_test.go b/backend/internal/web/ui/ui_test.go index 4125007..468a90d 100644 --- a/backend/internal/web/ui/ui_test.go +++ b/backend/internal/web/ui/ui_test.go @@ -226,3 +226,57 @@ func TestBadge_PrimaryVariant(t *testing.T) { t.Errorf("expected ui-badge-primary in output; got: %s", out) } } + +// Phase 13 Plan 03 — Input and Textarea component tests (TDD RED) + +func TestInput_DefaultType(t *testing.T) { + out := render(t, context.Background(), Input(InputProps{Name: "x"})) + if !strings.Contains(out, `type="text"`) { + t.Errorf("expected type=\"text\" for empty Type; got: %s", out) + } + if !strings.Contains(out, `class="ui-input"`) { + t.Errorf("expected class=\"ui-input\"; got: %s", out) + } +} + +func TestInput_EmailType(t *testing.T) { + out := render(t, context.Background(), Input(InputProps{Name: "email", Type: "email"})) + if !strings.Contains(out, `type="email"`) { + t.Errorf("expected type=\"email\"; got: %s", out) + } +} + +func TestInput_IDFallback(t *testing.T) { + out := render(t, context.Background(), Input(InputProps{Name: "email"})) + if !strings.Contains(out, `id="email"`) { + t.Errorf("expected id=\"email\" (fallback from name); got: %s", out) + } +} + +func TestInput_ExplicitID(t *testing.T) { + out := render(t, context.Background(), Input(InputProps{ID: "my-id", Name: "x"})) + if !strings.Contains(out, `id="my-id"`) { + t.Errorf("expected id=\"my-id\"; got: %s", out) + } +} + +func TestTextarea_RendersClass(t *testing.T) { + out := render(t, context.Background(), Textarea(TextareaProps{Name: "body"})) + if !strings.Contains(out, `class="ui-textarea"`) { + t.Errorf("expected class=\"ui-textarea\"; got: %s", out) + } +} + +func TestTextarea_DefaultRows(t *testing.T) { + out := render(t, context.Background(), Textarea(TextareaProps{Name: "x", Rows: 0})) + if !strings.Contains(out, `rows="4"`) { + t.Errorf("expected rows=\"4\" for zero Rows; got: %s", out) + } +} + +func TestTextarea_ExplicitRows(t *testing.T) { + out := render(t, context.Background(), Textarea(TextareaProps{Name: "x", Rows: 6})) + if !strings.Contains(out, `rows="6"`) { + t.Errorf("expected rows=\"6\"; got: %s", out) + } +}