55 */
66
77import { assert , describe , test } from "@rezi-ui/testkit" ;
8+ import { createTestRenderer } from "../../testing/renderer.js" ;
9+ import { darkTheme } from "../../theme/presets.js" ;
810import {
911 CHECKBOX_CHECKED ,
1012 CHECKBOX_DISABLED_CHECKED ,
@@ -14,7 +16,15 @@ import {
1416 getCheckboxIndicator ,
1517 toggleCheckbox ,
1618} from "../checkbox.js" ;
17- import { REQUIRED_INDICATOR , buildFieldLabel , shouldShowError } from "../field.js" ;
19+ import {
20+ FIELD_ERROR_STYLE ,
21+ FIELD_HINT_STYLE ,
22+ FIELD_LABEL_STYLE ,
23+ REQUIRED_INDICATOR ,
24+ buildFieldLabel ,
25+ getFieldFooterText ,
26+ shouldShowError ,
27+ } from "../field.js" ;
1828import {
1929 RADIO_SELECTED ,
2030 RADIO_UNSELECTED ,
@@ -57,6 +67,52 @@ describe("field widget utilities", () => {
5767 test ( "shouldShowError returns true for non-empty string" , ( ) => {
5868 assert . equal ( shouldShowError ( "Required" ) , true ) ;
5969 } ) ;
70+
71+ test ( "getFieldFooterText prefers non-empty error over hint" , ( ) => {
72+ assert . equal ( getFieldFooterText ( "Required" , "Helpful hint" ) , "Required" ) ;
73+ } ) ;
74+
75+ test ( "getFieldFooterText falls back to hint when error is empty" , ( ) => {
76+ assert . equal ( getFieldFooterText ( "" , "Helpful hint" ) , "Helpful hint" ) ;
77+ } ) ;
78+
79+ test ( "field helper styles stay theme-agnostic" , ( ) => {
80+ assert . deepEqual ( FIELD_LABEL_STYLE , { bold : true } ) ;
81+ assert . deepEqual ( FIELD_ERROR_STYLE , { bold : true } ) ;
82+ assert . deepEqual ( FIELD_HINT_STYLE , { dim : true } ) ;
83+ } ) ;
84+
85+ test ( "field renderer shows error footer before hint and falls back from empty error to hint" , ( ) => {
86+ const renderer = createTestRenderer ( {
87+ viewport : { cols : 40 , rows : 6 } ,
88+ theme : darkTheme ,
89+ } ) ;
90+
91+ const withError = renderer . render (
92+ ui . field ( {
93+ label : "Name" ,
94+ error : "Required" ,
95+ hint : "Enter your name" ,
96+ children : ui . text ( "abcdefghijklmnopqrst" ) ,
97+ } ) ,
98+ ) ;
99+ const withEmptyError = renderer . render (
100+ ui . field ( {
101+ label : "Name" ,
102+ error : "" ,
103+ hint : "Enter your name" ,
104+ children : ui . text ( "abcdefghijklmnopqrst" ) ,
105+ } ) ,
106+ ) ;
107+
108+ const withErrorText = withError . toText ( ) ;
109+ const withEmptyErrorText = withEmptyError . toText ( ) ;
110+
111+ assert . ok ( withErrorText . includes ( "Required" ) ) ;
112+ assert . ok ( ! withErrorText . includes ( "Enter your name" ) ) ;
113+ assert . ok ( withEmptyErrorText . includes ( "Enter your name" ) ) ;
114+ assert . ok ( ! withEmptyErrorText . includes ( "Required" ) ) ;
115+ } ) ;
60116} ) ;
61117
62118describe ( "select widget utilities" , ( ) => {
0 commit comments