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
This commit is contained in:
parent
9556b20ade
commit
50e3fb0021
1 changed files with 66 additions and 0 deletions
|
|
@ -280,3 +280,69 @@ func TestTextarea_ExplicitRows(t *testing.T) {
|
||||||
t.Errorf("expected rows=\"6\"; got: %s", out)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue