[
{ "fn": "fieldIds", "name": "no hint and no error: nothing describes the control", "args": ["email", false, false], "expect": { "control": "email", "hint": null, "error": null, "describedBy": null } },
{ "fn": "fieldIds", "name": "a hint describes the control", "args": ["email", true, false], "expect": { "control": "email", "hint": "email-hint", "error": null, "describedBy": "email-hint" } },
{ "fn": "fieldIds", "name": "an error describes the control", "args": ["email", false, true], "expect": { "control": "email", "hint": null, "error": "email-error", "describedBy": "email-error" } },
{ "fn": "fieldIds", "name": "hint first, then error, as a screen reader should read them", "args": ["email", true, true], "expect": { "control": "email", "hint": "email-hint", "error": "email-error", "describedBy": "email-hint email-error" } },
{ "fn": "fieldIds", "name": "an id with dashes and digits is kept as it is", "args": ["address-line-2", true, false], "expect": { "control": "address-line-2", "hint": "address-line-2-hint", "error": null, "describedBy": "address-line-2-hint" } },
{ "fn": "fieldIds", "name": "a React useId id (colons and underscores) works", "args": ["_R_1_", false, true], "expect": { "control": "_R_1_", "hint": null, "error": "_R_1_-error", "describedBy": "_R_1_-error" } },
{ "fn": "fieldIds", "name": "a one-letter id", "args": ["x", true, true], "expect": { "control": "x", "hint": "x-hint", "error": "x-error", "describedBy": "x-hint x-error" } },
{ "fn": "fieldIds", "name": "an empty id is refused", "args": ["", true, false], "expectError": "a field needs an id" },
{ "fn": "fieldIds", "name": "an id with a space is refused, since aria-describedby splits on spaces", "args": ["first name", false, false], "expectError": "a field id cannot contain spaces (\"first name\")" },
{ "fn": "FormField", "name": "a label and the control, nothing else", "args": [{ "id": "name", "label": "Full name", "children": "[control]" }], "expect": "
[control]
" },
{ "fn": "FormField", "name": "a hint goes under the label, with its id", "args": [{ "id": "dob", "label": "Date of birth", "hint": "For example, 27 3 2007", "children": "[control]" }], "expect": "
For example, 27 3 2007
[control]
" },
{ "fn": "FormField", "name": "an error marks the field and says Error: to a screen reader", "args": [{ "id": "email", "label": "Email address", "error": "Enter an email address", "children": "[control]" }], "expect": "
Error: Enter an email address
[control]
" },
{ "fn": "FormField", "name": "hint and error together, hint first", "args": [{ "id": "phone", "label": "Phone", "hint": "For international numbers include the country code", "error": "Enter a phone number, like 01632 960 001", "children": "[control]" }], "expect": "
For international numbers include the country code
Error: Enter a phone number, like 01632 960 001
[control]
" },
{ "fn": "FormField", "name": "an empty hint and a null error are not shown", "args": [{ "id": "town", "label": "Town", "hint": "", "error": null, "children": "[control]" }], "expect": "
[control]
" },
{ "fn": "FormField", "name": "a class name is added to the wrapper's", "args": [{ "id": "town", "label": "Town", "className": "wide", "children": "[control]" }], "expect": "
[control]
" },
{ "fn": "FormField", "name": "with an error and a class name, the error class comes first", "args": [{ "id": "town", "label": "Town", "className": "wide", "error": "Enter a town", "children": "[control]" }], "expect": "
Error: Enter a town
[control]
" },
{ "fn": "FormField", "name": "text is escaped, never markup", "args": [{ "id": "q", "label": "Search & find", "children": "" }], "expect": "" },
{ "fn": "FormField", "name": "a number is a node too", "args": [{ "id": "n", "label": 42, "hint": 0, "children": "[control]" }], "expect": "
0
[control]
" },
{ "fn": "FormField", "name": "an id with a space is refused", "args": [{ "id": "first name", "label": "First name" }], "expectError": "a field id cannot contain spaces" }
]