@1doc/1ds-react 2.7.2 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1280 -0
- package/dist/components/AIContent/AIContent.d.ts +10 -0
- package/dist/components/AIContent/AIContent.js +1 -1
- package/dist/components/AILabel/AILabel.d.ts +4 -0
- package/dist/components/AILabel/AILabel.js +2 -2
- package/dist/components/Accordion/Accordion.d.ts +6 -2
- package/dist/components/Alert/Alert.css +2 -0
- package/dist/components/Alert/Alert.d.ts +3 -1
- package/dist/components/Alert/Alert.js +7 -1
- package/dist/components/AppHeader/AppHeader.css +82 -8
- package/dist/components/AppHeader/AppHeader.d.ts +12 -1
- package/dist/components/AppHeader/AppHeader.js +186 -1
- package/dist/components/AppNavItem/AppNavItem.css +11 -3
- package/dist/components/AppShell/AppShell.css +9 -0
- package/dist/components/AppShell/AppShell.d.ts +8 -0
- package/dist/components/AppShell/AppShell.js +4 -1
- package/dist/components/AppSidebar/AppSidebar.css +1 -1
- package/dist/components/AppSidebar/AppSidebar.d.ts +4 -0
- package/dist/components/AppSidebar/AppSidebar.js +3 -1
- package/dist/components/AttachmentCard/AttachmentCard.css +17 -1
- package/dist/components/AttachmentCard/AttachmentCard.d.ts +29 -2
- package/dist/components/AttachmentCard/AttachmentCard.js +88 -20
- package/dist/components/Avatar/Avatar.css +7 -2
- package/dist/components/Avatar/AvatarGroup.d.ts +27 -0
- package/dist/components/Avatar/AvatarGroup.js +28 -4
- package/dist/components/Badge/Badge.css +61 -3
- package/dist/components/Badge/Badge.d.ts +14 -4
- package/dist/components/Badge/Badge.js +1 -0
- package/dist/components/BottomSheet/BottomSheet.css +1 -0
- package/dist/components/BottomSheet/BottomSheet.d.ts +8 -0
- package/dist/components/BottomSheet/BottomSheet.js +14 -2
- package/dist/components/Box/Box.css +83 -0
- package/dist/components/Box/Box.d.ts +82 -2
- package/dist/components/Box/Box.js +42 -2
- package/dist/components/Button/Button.css +29 -0
- package/dist/components/Button/Button.d.ts +4 -4
- package/dist/components/Button/Button.js +4 -1
- package/dist/components/Calendar/Calendar.css +245 -0
- package/dist/components/Calendar/Calendar.d.ts +125 -0
- package/dist/components/Calendar/Calendar.js +320 -0
- package/dist/components/Chart/BarChart.d.ts +6 -0
- package/dist/components/Chart/BarChart.js +3 -1
- package/dist/components/Chart/LineChart.d.ts +6 -0
- package/dist/components/Chart/LineChart.js +3 -1
- package/dist/components/Checkbox/Checkbox.css +4 -1
- package/dist/components/Chips/Chips.css +39 -0
- package/dist/components/Chips/Chips.d.ts +7 -2
- package/dist/components/Chips/Chips.js +6 -2
- package/dist/components/Coachmark/Coachmark.css +118 -0
- package/dist/components/Coachmark/Coachmark.d.ts +75 -0
- package/dist/components/Coachmark/Coachmark.js +321 -0
- package/dist/components/CodeBlock/CodeBlock.css +96 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +47 -0
- package/dist/components/CodeBlock/CodeBlock.js +103 -0
- package/dist/components/ColorPicker/ColorPicker.css +133 -0
- package/dist/components/ColorPicker/ColorPicker.d.ts +73 -0
- package/dist/components/ColorPicker/ColorPicker.js +219 -0
- package/dist/components/Combobox/Combobox.css +11 -3
- package/dist/components/ConfirmAIAction/ConfirmAIAction.d.ts +11 -1
- package/dist/components/ConfirmAIAction/ConfirmAIAction.js +6 -1
- package/dist/components/ConfirmDialog/ConfirmDialog.css +3 -0
- package/dist/components/ConfirmDialog/ConfirmDialog.d.ts +14 -0
- package/dist/components/ConfirmDialog/ConfirmDialog.js +2 -2
- package/dist/components/DataTable/DataTable.css +80 -0
- package/dist/components/DataTable/DataTable.d.ts +23 -4
- package/dist/components/DataTable/DataTable.js +61 -15
- package/dist/components/DatePicker/DatePicker.css +8 -0
- package/dist/components/DatePicker/DatePicker.d.ts +4 -0
- package/dist/components/DatePicker/DatePicker.js +14 -1
- package/dist/components/DescriptionList/DescriptionList.css +113 -0
- package/dist/components/DescriptionList/DescriptionList.d.ts +59 -0
- package/dist/components/DescriptionList/DescriptionList.js +51 -0
- package/dist/components/Drawer/Drawer.css +1 -0
- package/dist/components/Dropdown/Dropdown.js +47 -29
- package/dist/components/FileInput/FileInput.css +24 -4
- package/dist/components/FileInput/FileInput.d.ts +22 -2
- package/dist/components/FileInput/FileInput.js +23 -2
- package/dist/components/Grid/Grid.js +5 -5
- package/dist/components/IconPicker/IconPicker.css +107 -0
- package/dist/components/IconPicker/IconPicker.d.ts +74 -0
- package/dist/components/IconPicker/IconPicker.js +194 -0
- package/dist/components/Input/Input.css +41 -3
- package/dist/components/Input/Input.d.ts +14 -1
- package/dist/components/Input/Input.js +72 -6
- package/dist/components/Kanban/Kanban.css +5 -0
- package/dist/components/Kanban/Kanban.d.ts +41 -0
- package/dist/components/Kanban/Kanban.js +59 -27
- package/dist/components/Kanban/KanbanCard.d.ts +2 -0
- package/dist/components/Kanban/KanbanCard.js +1 -1
- package/dist/components/Kanban/KanbanColumn.d.ts +2 -0
- package/dist/components/Kanban/KanbanColumn.js +3 -0
- package/dist/components/Kbd/Kbd.css +66 -0
- package/dist/components/Kbd/Kbd.d.ts +32 -0
- package/dist/components/Kbd/Kbd.js +40 -0
- package/dist/components/Link/Link.css +1 -1
- package/dist/components/List/List.css +136 -0
- package/dist/components/List/List.d.ts +82 -0
- package/dist/components/List/List.js +53 -0
- package/dist/components/List/ListItem.d.ts +85 -0
- package/dist/components/List/ListItem.js +81 -0
- package/dist/components/Modal/Modal.css +93 -8
- package/dist/components/Modal/Modal.d.ts +45 -7
- package/dist/components/Modal/Modal.js +106 -6
- package/dist/components/MultiSelect/MultiSelect.css +9 -1
- package/dist/components/MultiSelect/MultiSelect.js +45 -8
- package/dist/components/OrgChart/OrgChart.css +149 -0
- package/dist/components/OrgChart/OrgChart.d.ts +83 -0
- package/dist/components/OrgChart/OrgChart.js +297 -0
- package/dist/components/OtpInput/OtpInput.css +93 -0
- package/dist/components/OtpInput/OtpInput.d.ts +60 -0
- package/dist/components/OtpInput/OtpInput.js +215 -0
- package/dist/components/Pagination/Pagination.d.ts +6 -0
- package/dist/components/Pagination/Pagination.js +9 -1
- package/dist/components/PhoneInput/PhoneInput.css +9 -1
- package/dist/components/PhoneInput/PhoneInput.d.ts +10 -0
- package/dist/components/PhoneInput/PhoneInput.js +20 -3
- package/dist/components/Popover/Popover.d.ts +7 -0
- package/dist/components/Popover/Popover.js +11 -1
- package/dist/components/RichTextEditor/RichTextEditor.css +203 -0
- package/dist/components/RichTextEditor/RichTextEditor.d.ts +83 -0
- package/dist/components/RichTextEditor/RichTextEditor.js +494 -0
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +2 -0
- package/dist/components/SegmentedControl/SegmentedControl.js +21 -8
- package/dist/components/Select/Select.css +71 -1
- package/dist/components/Select/Select.d.ts +12 -0
- package/dist/components/Select/Select.js +93 -10
- package/dist/components/SidePanel/SidePanel.css +4 -4
- package/dist/components/SidePanelItem/SidePanelItem.css +7 -5
- package/dist/components/SidePanelSearch/SidePanelSearch.css +2 -2
- package/dist/components/SidePanelSection/SidePanelSection.css +7 -5
- package/dist/components/Stack/Stack.css +49 -0
- package/dist/components/Stack/Stack.d.ts +65 -7
- package/dist/components/Stack/Stack.js +30 -2
- package/dist/components/StatCard/StatCard.css +73 -0
- package/dist/components/StatCard/StatCard.d.ts +17 -0
- package/dist/components/StatCard/StatCard.js +4 -1
- package/dist/components/Stepper/Stepper.css +4 -1
- package/dist/components/Stepper/Stepper.d.ts +8 -0
- package/dist/components/Stepper/Stepper.js +4 -4
- package/dist/components/Switch/Switch.css +1 -0
- package/dist/components/Tabs/Tab.d.ts +15 -0
- package/dist/components/Tabs/Tab.js +30 -1
- package/dist/components/Tabs/Tabs.css +132 -0
- package/dist/components/Tabs/Tabs.d.ts +7 -0
- package/dist/components/Tabs/Tabs.js +13 -2
- package/dist/components/Tag/Tag.css +85 -2
- package/dist/components/Tag/Tag.d.ts +13 -6
- package/dist/components/Tag/Tag.js +1 -0
- package/dist/components/Text/Text.d.ts +9 -1
- package/dist/components/Text/Text.js +2 -2
- package/dist/components/Textarea/Textarea.css +11 -3
- package/dist/components/TimePicker/TimePicker.css +8 -0
- package/dist/components/TimePicker/TimePicker.d.ts +6 -0
- package/dist/components/TimePicker/TimePicker.js +1 -1
- package/dist/components/Tooltip/Tooltip.css +40 -0
- package/dist/components/Tooltip/Tooltip.d.ts +11 -0
- package/dist/components/Tooltip/Tooltip.js +114 -11
- package/dist/index.d.ts +25 -0
- package/dist/index.js +14 -0
- package/dist/teste/AILabel.test.d.ts +1 -0
- package/dist/teste/AILabel.test.js +33 -0
- package/dist/teste/AccordionConteudoLivre.test.d.ts +1 -0
- package/dist/teste/AccordionConteudoLivre.test.js +29 -0
- package/dist/teste/Alert.test.d.ts +1 -0
- package/dist/teste/Alert.test.js +27 -0
- package/dist/teste/AtributosRepassados.test.d.ts +1 -0
- package/dist/teste/AtributosRepassados.test.js +52 -0
- package/dist/teste/AttachmentCardIA.test.d.ts +1 -0
- package/dist/teste/AttachmentCardIA.test.js +89 -0
- package/dist/teste/AvatarGroupOverlap.test.d.ts +1 -0
- package/dist/teste/AvatarGroupOverlap.test.js +56 -0
- package/dist/teste/BadgeTag.test.d.ts +1 -0
- package/dist/teste/BadgeTag.test.js +42 -0
- package/dist/teste/BottomSheet.test.d.ts +1 -0
- package/dist/teste/BottomSheet.test.js +23 -0
- package/dist/teste/BoxItemFlex.test.d.ts +1 -0
- package/dist/teste/BoxItemFlex.test.js +54 -0
- package/dist/teste/BoxLayout.test.d.ts +1 -0
- package/dist/teste/BoxLayout.test.js +35 -0
- package/dist/teste/Button.test.d.ts +1 -0
- package/dist/teste/Button.test.js +27 -0
- package/dist/teste/Calendar.test.d.ts +1 -0
- package/dist/teste/Calendar.test.js +221 -0
- package/dist/teste/ChipsXs.test.d.ts +1 -0
- package/dist/teste/ChipsXs.test.js +31 -0
- package/dist/teste/Coachmark.test.d.ts +1 -0
- package/dist/teste/Coachmark.test.js +149 -0
- package/dist/teste/ColorPicker.test.d.ts +1 -0
- package/dist/teste/ColorPicker.test.js +132 -0
- package/dist/teste/ConfirmAIAction.test.d.ts +1 -0
- package/dist/teste/ConfirmAIAction.test.js +33 -0
- package/dist/teste/DataTableCelulaLivre.test.d.ts +1 -0
- package/dist/teste/DataTableCelulaLivre.test.js +76 -0
- package/dist/teste/DataTableDocumento.test.d.ts +1 -0
- package/dist/teste/DataTableDocumento.test.js +92 -0
- package/dist/teste/DatePicker.test.js +23 -0
- package/dist/teste/Dropdown.test.js +111 -0
- package/dist/teste/FileInputTrigger.test.d.ts +1 -0
- package/dist/teste/FileInputTrigger.test.js +53 -0
- package/dist/teste/IconPicker.test.d.ts +1 -0
- package/dist/teste/IconPicker.test.js +130 -0
- package/dist/teste/InputMascaraEAfins.test.d.ts +1 -0
- package/dist/teste/InputMascaraEAfins.test.js +99 -0
- package/dist/teste/KbdCodeBlock.test.d.ts +1 -0
- package/dist/teste/KbdCodeBlock.test.js +95 -0
- package/dist/teste/List.test.d.ts +1 -0
- package/dist/teste/List.test.js +153 -0
- package/dist/teste/Modal.test.d.ts +1 -0
- package/dist/teste/Modal.test.js +26 -0
- package/dist/teste/ModalVariantes.test.d.ts +1 -0
- package/dist/teste/ModalVariantes.test.js +151 -0
- package/dist/teste/MultiSelectErro.test.d.ts +1 -0
- package/dist/teste/MultiSelectErro.test.js +62 -0
- package/dist/teste/NomeAcessivelSsr.test.d.ts +1 -0
- package/dist/teste/NomeAcessivelSsr.test.js +88 -0
- package/dist/teste/OrgChart.test.d.ts +1 -0
- package/dist/teste/OrgChart.test.js +162 -0
- package/dist/teste/OtpInput.test.d.ts +1 -0
- package/dist/teste/OtpInput.test.js +143 -0
- package/dist/teste/PopoverMaxHeight.test.d.ts +1 -0
- package/dist/teste/PopoverMaxHeight.test.js +38 -0
- package/dist/teste/RichTextEditor.test.d.ts +1 -0
- package/dist/teste/RichTextEditor.test.js +287 -0
- package/dist/teste/RotulosTraduziveis.test.d.ts +1 -0
- package/dist/teste/RotulosTraduziveis.test.js +405 -0
- package/dist/teste/SegmentedControl.test.js +33 -0
- package/dist/teste/Select.test.d.ts +1 -0
- package/dist/teste/Select.test.js +62 -0
- package/dist/teste/SelectPlacementFiltro.test.d.ts +1 -0
- package/dist/teste/SelectPlacementFiltro.test.js +88 -0
- package/dist/teste/Stack.test.d.ts +1 -0
- package/dist/teste/Stack.test.js +57 -0
- package/dist/teste/StatCardRotuloTopo.test.d.ts +1 -0
- package/dist/teste/StatCardRotuloTopo.test.js +34 -0
- package/dist/teste/TabsContadorFechavel.test.d.ts +1 -0
- package/dist/teste/TabsContadorFechavel.test.js +79 -0
- package/dist/teste/Tooltip.test.d.ts +1 -0
- package/dist/teste/Tooltip.test.js +109 -0
- package/dist/teste/TooltipDark.test.d.ts +1 -0
- package/dist/teste/TooltipDark.test.js +31 -0
- package/dist/utils/calendario.d.ts +28 -0
- package/dist/utils/calendario.js +73 -0
- package/dist/utils/chart.d.ts +4 -0
- package/dist/utils/chart.js +3 -2
- package/dist/utils/html-seguro.d.ts +27 -0
- package/dist/utils/html-seguro.js +97 -0
- package/dist/utils/id.d.ts +2 -0
- package/dist/utils/id.js +23 -0
- package/dist/utils/paleta-de-cores.d.ts +26 -0
- package/dist/utils/paleta-de-cores.js +10 -0
- package/dist/utils/texto.d.ts +5 -0
- package/dist/utils/texto.js +5 -0
- package/package.json +3 -3
- package/src/index.ts +26 -0
- package/src/teste/AILabel.test.tsx +41 -0
- package/src/teste/AccordionConteudoLivre.test.tsx +39 -0
- package/src/teste/Alert.test.tsx +32 -0
- package/src/teste/AtributosRepassados.test.tsx +73 -0
- package/src/teste/AttachmentCardIA.test.tsx +126 -0
- package/src/teste/AvatarGroupOverlap.test.tsx +74 -0
- package/src/teste/BadgeTag.test.tsx +64 -0
- package/src/teste/BottomSheet.test.tsx +25 -0
- package/src/teste/BoxItemFlex.test.tsx +81 -0
- package/src/teste/BoxLayout.test.tsx +50 -0
- package/src/teste/Button.test.tsx +39 -0
- package/src/teste/Calendar.test.tsx +282 -0
- package/src/teste/ChipsXs.test.tsx +41 -0
- package/src/teste/Coachmark.test.tsx +198 -0
- package/src/teste/ColorPicker.test.tsx +153 -0
- package/src/teste/ConfirmAIAction.test.tsx +41 -0
- package/src/teste/DataTableCelulaLivre.test.tsx +103 -0
- package/src/teste/DataTableDocumento.test.tsx +102 -0
- package/src/teste/DatePicker.test.tsx +38 -0
- package/src/teste/Dropdown.test.tsx +146 -0
- package/src/teste/FileInputTrigger.test.tsx +89 -0
- package/src/teste/IconPicker.test.tsx +145 -0
- package/src/teste/InputMascaraEAfins.test.tsx +124 -0
- package/src/teste/KbdCodeBlock.test.tsx +106 -0
- package/src/teste/List.test.tsx +269 -0
- package/src/teste/Modal.test.tsx +28 -0
- package/src/teste/ModalVariantes.test.tsx +173 -0
- package/src/teste/MultiSelectErro.test.tsx +97 -0
- package/src/teste/NomeAcessivelSsr.test.tsx +110 -0
- package/src/teste/OrgChart.test.tsx +183 -0
- package/src/teste/OtpInput.test.tsx +163 -0
- package/src/teste/PopoverMaxHeight.test.tsx +47 -0
- package/src/teste/RichTextEditor.test.tsx +329 -0
- package/src/teste/RotulosTraduziveis.test.tsx +545 -0
- package/src/teste/SegmentedControl.test.tsx +57 -0
- package/src/teste/Select.test.tsx +97 -0
- package/src/teste/SelectPlacementFiltro.test.tsx +110 -0
- package/src/teste/Stack.test.tsx +80 -0
- package/src/teste/StatCardRotuloTopo.test.tsx +44 -0
- package/src/teste/TabsContadorFechavel.test.tsx +144 -0
- package/src/teste/Tooltip.test.tsx +219 -0
- package/src/teste/TooltipDark.test.tsx +51 -0
- package/src/utils/calendario.ts +78 -0
- package/src/utils/chart.ts +7 -2
- package/src/utils/html-seguro.ts +94 -0
- package/src/utils/id.ts +24 -0
- package/src/utils/paleta-de-cores.ts +34 -0
- package/src/utils/texto.ts +5 -0
|
@@ -215,3 +215,149 @@ describe("Dropdown · modo controlado", () => {
|
|
|
215
215
|
await waitFor(() => expect(screen.getByRole("menu")).toBeInTheDocument());
|
|
216
216
|
});
|
|
217
217
|
});
|
|
218
|
+
|
|
219
|
+
describe("Dropdown · teclado", () => {
|
|
220
|
+
/**
|
|
221
|
+
* No React gerado, `moveActive` lia `activeIndex` do closure do render — o
|
|
222
|
+
* valor ANTERIOR ao `setActiveIndex` que acabara de ser chamado. Assim o End
|
|
223
|
+
* partia do índice velho e marcava o penúltimo, e o foco ia para o item que
|
|
224
|
+
* estava ativo antes da tecla, um passo atrás. O Vue não sofria disso porque
|
|
225
|
+
* lá o `ref` muda na hora. Estes testes prendem o comportamento dos dois.
|
|
226
|
+
*/
|
|
227
|
+
const ITENS_COM_DESABILITADO = [
|
|
228
|
+
{ key: "editar", label: "Editar" },
|
|
229
|
+
{ key: "arquivar", label: "Arquivar", disabled: true },
|
|
230
|
+
{ key: "duplicar", label: "Duplicar" },
|
|
231
|
+
{ key: "excluir", label: "Excluir", danger: true },
|
|
232
|
+
];
|
|
233
|
+
|
|
234
|
+
const item = (nome: string) => screen.getByRole("menuitem", { name: nome });
|
|
235
|
+
|
|
236
|
+
it("ArrowDown no gatilho abre e leva o foco ao primeiro item", async () => {
|
|
237
|
+
const usuario = userEvent.setup();
|
|
238
|
+
render(menu());
|
|
239
|
+
|
|
240
|
+
gatilho().focus();
|
|
241
|
+
await usuario.keyboard("{ArrowDown}");
|
|
242
|
+
await waitFor(() => expect(item("Editar")).toHaveFocus());
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("ArrowUp no gatilho abre e leva o foco ao último item", async () => {
|
|
246
|
+
const usuario = userEvent.setup();
|
|
247
|
+
render(menu());
|
|
248
|
+
|
|
249
|
+
gatilho().focus();
|
|
250
|
+
await usuario.keyboard("{ArrowUp}");
|
|
251
|
+
await waitFor(() => expect(item("Excluir")).toHaveFocus());
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("as setas movem o foco item a item, com volta nas pontas", async () => {
|
|
255
|
+
const usuario = userEvent.setup();
|
|
256
|
+
render(menu());
|
|
257
|
+
|
|
258
|
+
gatilho().focus();
|
|
259
|
+
await usuario.keyboard("{ArrowDown}");
|
|
260
|
+
await waitFor(() => expect(item("Editar")).toHaveFocus());
|
|
261
|
+
|
|
262
|
+
await usuario.keyboard("{ArrowDown}");
|
|
263
|
+
expect(item("Duplicar")).toHaveFocus();
|
|
264
|
+
await usuario.keyboard("{ArrowDown}");
|
|
265
|
+
expect(item("Excluir")).toHaveFocus();
|
|
266
|
+
await usuario.keyboard("{ArrowDown}");
|
|
267
|
+
expect(item("Editar")).toHaveFocus();
|
|
268
|
+
await usuario.keyboard("{ArrowUp}");
|
|
269
|
+
expect(item("Excluir")).toHaveFocus();
|
|
270
|
+
await usuario.keyboard("{ArrowUp}");
|
|
271
|
+
expect(item("Duplicar")).toHaveFocus();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("Home e End vão ao primeiro e ao último item", async () => {
|
|
275
|
+
const usuario = userEvent.setup();
|
|
276
|
+
render(menu());
|
|
277
|
+
|
|
278
|
+
gatilho().focus();
|
|
279
|
+
await usuario.keyboard("{ArrowDown}");
|
|
280
|
+
await waitFor(() => expect(item("Editar")).toHaveFocus());
|
|
281
|
+
|
|
282
|
+
await usuario.keyboard("{End}");
|
|
283
|
+
expect(item("Excluir")).toHaveFocus();
|
|
284
|
+
// End de novo, já no último: continua no último (era aqui que o React
|
|
285
|
+
// marcava o penúltimo).
|
|
286
|
+
await usuario.keyboard("{End}");
|
|
287
|
+
expect(item("Excluir")).toHaveFocus();
|
|
288
|
+
await usuario.keyboard("{Home}");
|
|
289
|
+
expect(item("Editar")).toHaveFocus();
|
|
290
|
+
await usuario.keyboard("{Home}");
|
|
291
|
+
expect(item("Editar")).toHaveFocus();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("item desabilitado é pulado pelas setas", async () => {
|
|
295
|
+
const usuario = userEvent.setup();
|
|
296
|
+
render(
|
|
297
|
+
<Dropdown items={ITENS_COM_DESABILITADO} ariaLabel="Ações">
|
|
298
|
+
<Button variant="secondary">Abrir</Button>
|
|
299
|
+
</Dropdown>,
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
gatilho().focus();
|
|
303
|
+
await usuario.keyboard("{ArrowDown}");
|
|
304
|
+
await waitFor(() => expect(item("Editar")).toHaveFocus());
|
|
305
|
+
await usuario.keyboard("{ArrowDown}");
|
|
306
|
+
expect(item("Duplicar")).toHaveFocus();
|
|
307
|
+
await usuario.keyboard("{ArrowUp}");
|
|
308
|
+
expect(item("Editar")).toHaveFocus();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("Enter ativa o item com foco", async () => {
|
|
312
|
+
const usuario = userEvent.setup();
|
|
313
|
+
const aoSelecionar = vi.fn();
|
|
314
|
+
render(menu({ onSelect: aoSelecionar }));
|
|
315
|
+
|
|
316
|
+
gatilho().focus();
|
|
317
|
+
await usuario.keyboard("{ArrowDown}");
|
|
318
|
+
await waitFor(() => expect(item("Editar")).toHaveFocus());
|
|
319
|
+
await usuario.keyboard("{ArrowDown}");
|
|
320
|
+
await usuario.keyboard("{Enter}");
|
|
321
|
+
|
|
322
|
+
expect(aoSelecionar).toHaveBeenCalledTimes(1);
|
|
323
|
+
expect(aoSelecionar).toHaveBeenCalledWith(
|
|
324
|
+
expect.objectContaining({ key: "duplicar" }),
|
|
325
|
+
);
|
|
326
|
+
await waitFor(() =>
|
|
327
|
+
expect(screen.queryByRole("menu")).not.toBeInTheDocument(),
|
|
328
|
+
);
|
|
329
|
+
expect(gatilho()).toHaveFocus();
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("Espaço ativa o item com foco", async () => {
|
|
333
|
+
const usuario = userEvent.setup();
|
|
334
|
+
const aoSelecionar = vi.fn();
|
|
335
|
+
render(menu({ onSelect: aoSelecionar }));
|
|
336
|
+
|
|
337
|
+
gatilho().focus();
|
|
338
|
+
await usuario.keyboard("{ArrowUp}");
|
|
339
|
+
await waitFor(() => expect(item("Excluir")).toHaveFocus());
|
|
340
|
+
await usuario.keyboard(" ");
|
|
341
|
+
|
|
342
|
+
expect(aoSelecionar).toHaveBeenCalledTimes(1);
|
|
343
|
+
expect(aoSelecionar).toHaveBeenCalledWith(
|
|
344
|
+
expect.objectContaining({ key: "excluir" }),
|
|
345
|
+
);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("Esc fecha depois de navegar e devolve o foco ao gatilho", async () => {
|
|
349
|
+
const usuario = userEvent.setup();
|
|
350
|
+
render(menu());
|
|
351
|
+
|
|
352
|
+
gatilho().focus();
|
|
353
|
+
await usuario.keyboard("{ArrowDown}");
|
|
354
|
+
await waitFor(() => expect(item("Editar")).toHaveFocus());
|
|
355
|
+
await usuario.keyboard("{ArrowDown}");
|
|
356
|
+
await usuario.keyboard("{Escape}");
|
|
357
|
+
|
|
358
|
+
await waitFor(() =>
|
|
359
|
+
expect(screen.queryByRole("menu")).not.toBeInTheDocument(),
|
|
360
|
+
);
|
|
361
|
+
expect(gatilho()).toHaveFocus();
|
|
362
|
+
});
|
|
363
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import FileInput from "../components/FileInput/FileInput";
|
|
4
|
+
|
|
5
|
+
const arquivo = (nome: string) => new File(["conteudo"], nome, { type: "application/pdf" });
|
|
6
|
+
|
|
7
|
+
describe("FileInput · variant trigger", () => {
|
|
8
|
+
it("renderiza o conteúdo como gatilho, sem a caixa de arrastar", () => {
|
|
9
|
+
const { container } = render(
|
|
10
|
+
<FileInput variant="trigger">
|
|
11
|
+
<button type="button">Anexar arquivo</button>
|
|
12
|
+
</FileInput>,
|
|
13
|
+
);
|
|
14
|
+
expect(screen.getByRole("button", { name: "Anexar arquivo" })).toBeInTheDocument();
|
|
15
|
+
expect(container.querySelector(".umds-file-input__drop-zone")).toBeNull();
|
|
16
|
+
expect(container.querySelector(".umds-file-input--trigger")).not.toBeNull();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("clicar no conteúdo abre o seletor (clique no input nativo)", () => {
|
|
20
|
+
const { container } = render(
|
|
21
|
+
<FileInput variant="trigger">
|
|
22
|
+
<button type="button">Anexar arquivo</button>
|
|
23
|
+
</FileInput>,
|
|
24
|
+
);
|
|
25
|
+
const nativo = container.querySelector('input[type="file"]') as HTMLInputElement;
|
|
26
|
+
const clique = vi.spyOn(nativo, "click");
|
|
27
|
+
fireEvent.click(screen.getByRole("button", { name: "Anexar arquivo" }));
|
|
28
|
+
expect(clique).toHaveBeenCalledTimes(1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("disabled não abre o seletor", () => {
|
|
32
|
+
const { container } = render(
|
|
33
|
+
<FileInput variant="trigger" disabled>
|
|
34
|
+
<span>Alterar foto</span>
|
|
35
|
+
</FileInput>,
|
|
36
|
+
);
|
|
37
|
+
const nativo = container.querySelector('input[type="file"]') as HTMLInputElement;
|
|
38
|
+
const clique = vi.spyOn(nativo, "click");
|
|
39
|
+
fireEvent.click(screen.getByText("Alterar foto"));
|
|
40
|
+
expect(clique).not.toHaveBeenCalled();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("escolher arquivos chama onChange, e accept e multiple chegam ao input", () => {
|
|
44
|
+
const aoMudar = vi.fn();
|
|
45
|
+
const { container } = render(
|
|
46
|
+
<FileInput variant="trigger" accept=".pdf" multiple onChange={aoMudar}>
|
|
47
|
+
<button type="button">Anexar</button>
|
|
48
|
+
</FileInput>,
|
|
49
|
+
);
|
|
50
|
+
const nativo = container.querySelector('input[type="file"]') as HTMLInputElement;
|
|
51
|
+
expect(nativo).toHaveAttribute("accept", ".pdf");
|
|
52
|
+
expect(nativo).toHaveAttribute("multiple");
|
|
53
|
+
fireEvent.change(nativo, { target: { files: [arquivo("a.pdf"), arquivo("b.pdf")] } });
|
|
54
|
+
expect(aoMudar).toHaveBeenCalledTimes(1);
|
|
55
|
+
expect(aoMudar.mock.calls[0][0].map((f: File) => f.name)).toEqual(["a.pdf", "b.pdf"]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("o input nativo não entra no Tab e tem nome acessível", () => {
|
|
59
|
+
const { container } = render(
|
|
60
|
+
<FileInput variant="trigger" label="Anexar arquivo">
|
|
61
|
+
<button type="button">Anexar</button>
|
|
62
|
+
</FileInput>,
|
|
63
|
+
);
|
|
64
|
+
const nativo = container.querySelector('input[type="file"]') as HTMLInputElement;
|
|
65
|
+
expect(nativo).toHaveAttribute("tabindex", "-1");
|
|
66
|
+
expect(nativo).toHaveAttribute("aria-label", "Anexar arquivo");
|
|
67
|
+
// o rótulo visível não aparece: o gatilho é o conteúdo
|
|
68
|
+
expect(container.querySelector(".umds-file-input__label")).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("a lista de arquivos continua aparecendo no modo trigger", () => {
|
|
72
|
+
render(
|
|
73
|
+
<FileInput variant="trigger" files={[{ name: "oficio.pdf", size: 2048 }]}>
|
|
74
|
+
<button type="button">Anexar</button>
|
|
75
|
+
</FileInput>,
|
|
76
|
+
);
|
|
77
|
+
expect(screen.getByText("oficio.pdf")).toBeInTheDocument();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("as variantes base e card seguem com a caixa", () => {
|
|
81
|
+
const { container } = render(
|
|
82
|
+
<>
|
|
83
|
+
<FileInput variant="base" />
|
|
84
|
+
<FileInput variant="card" />
|
|
85
|
+
</>,
|
|
86
|
+
);
|
|
87
|
+
expect(container.querySelectorAll(".umds-file-input__drop-zone")).toHaveLength(2);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import { faBuilding, faFileLines, faFolder, faGavel, faUser } from "@fortawesome/free-solid-svg-icons";
|
|
6
|
+
import IconPicker from "../components/IconPicker/IconPicker";
|
|
7
|
+
|
|
8
|
+
const ICONES = [
|
|
9
|
+
faUser,
|
|
10
|
+
faFolder,
|
|
11
|
+
faFileLines,
|
|
12
|
+
{ icon: faBuilding, label: "Prédio", keywords: ["prefeitura", "órgão"] },
|
|
13
|
+
{ icon: faGavel, label: "Martelo", keywords: ["jurídico", "decisão"] },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const radios = () => screen.getAllByRole("radio");
|
|
17
|
+
|
|
18
|
+
describe("IconPicker", () => {
|
|
19
|
+
it("é um radiogroup com um radio por ícone, nomeado pelo iconName sem hífen", () => {
|
|
20
|
+
render(<IconPicker ariaLabel="Ícone da categoria" icons={ICONES} />);
|
|
21
|
+
expect(screen.getByRole("radiogroup", { name: "Ícone da categoria" })).toBeInTheDocument();
|
|
22
|
+
expect(radios()).toHaveLength(5);
|
|
23
|
+
expect(screen.getByRole("radio", { name: "user" })).toBeInTheDocument();
|
|
24
|
+
expect(screen.getByRole("radio", { name: "file lines" })).toBeInTheDocument();
|
|
25
|
+
expect(screen.getByRole("radio", { name: "Prédio" })).toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("iconLabel traduz os nomes que não vêm com label", () => {
|
|
29
|
+
render(<IconPicker ariaLabel="x" icons={[faUser, faFolder]} iconLabel={(n) => ({ user: "Pessoa", folder: "Pasta" } as any)[n]} />);
|
|
30
|
+
expect(screen.getByRole("radio", { name: "Pessoa" })).toBeInTheDocument();
|
|
31
|
+
expect(screen.getByRole("radio", { name: "Pasta" })).toBeInTheDocument();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("clicar escolhe e entrega o NOME do ícone e o item em onChange", async () => {
|
|
35
|
+
const usuario = userEvent.setup();
|
|
36
|
+
const aoMudar = vi.fn();
|
|
37
|
+
render(<IconPicker ariaLabel="x" icons={ICONES} onChange={aoMudar} />);
|
|
38
|
+
await usuario.click(screen.getByRole("radio", { name: "folder" }));
|
|
39
|
+
expect(aoMudar).toHaveBeenCalledWith("folder", faFolder);
|
|
40
|
+
expect(screen.getByRole("radio", { name: "folder" })).toHaveAttribute("aria-checked", "true");
|
|
41
|
+
await usuario.click(screen.getByRole("radio", { name: "Prédio" }));
|
|
42
|
+
expect(aoMudar).toHaveBeenLastCalledWith("building", ICONES[3]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("defaultValue marca o escolhido; só ele entra na ordem de Tab", () => {
|
|
46
|
+
render(<IconPicker ariaLabel="x" icons={ICONES} defaultValue="file-lines" />);
|
|
47
|
+
expect(screen.getByRole("radio", { name: "file lines" })).toHaveAttribute("aria-checked", "true");
|
|
48
|
+
const comTab = radios().filter((r) => r.getAttribute("tabindex") === "0");
|
|
49
|
+
expect(comTab).toHaveLength(1);
|
|
50
|
+
expect(comTab[0]).toHaveAccessibleName("file lines");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("sem valor, Tab entra no primeiro", () => {
|
|
54
|
+
render(<IconPicker ariaLabel="x" icons={ICONES} />);
|
|
55
|
+
expect(radios()[0]).toHaveAttribute("tabindex", "0");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("a busca filtra por nome, rótulo e palavras-chave, sem acento nem caixa", async () => {
|
|
59
|
+
const usuario = userEvent.setup();
|
|
60
|
+
render(<IconPicker ariaLabel="x" icons={ICONES} />);
|
|
61
|
+
const campo = screen.getByRole("searchbox", { name: "Buscar ícone" });
|
|
62
|
+
await usuario.type(campo, "PREFEITURA");
|
|
63
|
+
expect(radios()).toHaveLength(1);
|
|
64
|
+
expect(radios()[0]).toHaveAccessibleName("Prédio");
|
|
65
|
+
await usuario.clear(campo);
|
|
66
|
+
await usuario.type(campo, "juridico");
|
|
67
|
+
expect(radios().map((r) => r.getAttribute("aria-label"))).toEqual(["Martelo"]);
|
|
68
|
+
await usuario.clear(campo);
|
|
69
|
+
await usuario.type(campo, "fol");
|
|
70
|
+
expect(radios().map((r) => r.getAttribute("aria-label"))).toEqual(["folder"]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("a quantidade de resultados é anunciada e resultsLabel traduz", async () => {
|
|
74
|
+
const usuario = userEvent.setup();
|
|
75
|
+
render(<IconPicker ariaLabel="x" icons={ICONES} resultsLabel="{count} icons" />);
|
|
76
|
+
expect(screen.getByRole("status")).toHaveTextContent("5 icons");
|
|
77
|
+
await usuario.type(screen.getByRole("searchbox"), "user");
|
|
78
|
+
expect(screen.getByRole("status")).toHaveTextContent("1 icons");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("sem resultado mostra o texto e some a grade", async () => {
|
|
82
|
+
const usuario = userEvent.setup();
|
|
83
|
+
render(<IconPicker ariaLabel="x" icons={ICONES} emptyText="Nada por aqui" />);
|
|
84
|
+
await usuario.type(screen.getByRole("searchbox"), "zzz");
|
|
85
|
+
expect(screen.getByText("Nada por aqui")).toBeInTheDocument();
|
|
86
|
+
expect(screen.queryByRole("radiogroup")).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("setas movem a escolha e o foco; cima e baixo andam uma linha (columns)", async () => {
|
|
90
|
+
const usuario = userEvent.setup();
|
|
91
|
+
const aoMudar = vi.fn();
|
|
92
|
+
render(<IconPicker ariaLabel="x" icons={ICONES} columns={2} defaultValue="user" onChange={aoMudar} />);
|
|
93
|
+
radios()[0].focus();
|
|
94
|
+
await usuario.keyboard("{ArrowRight}");
|
|
95
|
+
expect(aoMudar).toHaveBeenLastCalledWith("folder", faFolder);
|
|
96
|
+
expect(radios()[1]).toHaveFocus();
|
|
97
|
+
await usuario.keyboard("{ArrowDown}");
|
|
98
|
+
expect(radios()[3]).toHaveFocus();
|
|
99
|
+
await usuario.keyboard("{ArrowUp}");
|
|
100
|
+
expect(radios()[1]).toHaveFocus();
|
|
101
|
+
await usuario.keyboard("{End}");
|
|
102
|
+
expect(radios()[4]).toHaveFocus();
|
|
103
|
+
await usuario.keyboard("{ArrowRight}");
|
|
104
|
+
expect(radios()[0]).toHaveFocus();
|
|
105
|
+
await usuario.keyboard("{ArrowLeft}");
|
|
106
|
+
expect(radios()[4]).toHaveFocus();
|
|
107
|
+
await usuario.keyboard("{Home}");
|
|
108
|
+
expect(radios()[0]).toHaveFocus();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("seta para baixo no campo de busca leva à grade", async () => {
|
|
112
|
+
const usuario = userEvent.setup();
|
|
113
|
+
render(<IconPicker ariaLabel="x" icons={ICONES} defaultValue="folder" />);
|
|
114
|
+
await usuario.click(screen.getByRole("searchbox"));
|
|
115
|
+
await usuario.keyboard("{ArrowDown}");
|
|
116
|
+
expect(screen.getByRole("radio", { name: "folder" })).toHaveFocus();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("hideSearch tira o campo; disabled desabilita tudo", () => {
|
|
120
|
+
const { rerender } = render(<IconPicker ariaLabel="x" icons={ICONES} hideSearch />);
|
|
121
|
+
expect(screen.queryByRole("searchbox")).toBeNull();
|
|
122
|
+
rerender(<IconPicker ariaLabel="x" icons={ICONES} disabled />);
|
|
123
|
+
for (const r of radios()) expect(r).toBeDisabled();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("textos da busca por prop; label visível nomeia o grupo; columns vira o grid", () => {
|
|
127
|
+
const { container } = render(
|
|
128
|
+
<IconPicker label="Ícone" id="ip" icons={ICONES} searchLabel="Search icon" searchPlaceholder="Search..." columns={4} maxHeight={120} />,
|
|
129
|
+
);
|
|
130
|
+
expect(screen.getByRole("radiogroup", { name: "Ícone" })).toBeInTheDocument();
|
|
131
|
+
expect(screen.getByRole("searchbox", { name: "Search icon" })).toHaveAttribute("placeholder", "Search...");
|
|
132
|
+
const grade = container.querySelector(".umds-icon-picker__grid") as HTMLElement;
|
|
133
|
+
expect(grade.style.gridTemplateColumns).toBe("repeat(4, var(--umds-icon-picker-tile))");
|
|
134
|
+
expect(grade.style.maxHeight).toBe("120px");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("controlado: reflete o value", () => {
|
|
138
|
+
function Pai() {
|
|
139
|
+
const [valor, setValor] = useState("gavel");
|
|
140
|
+
return <IconPicker ariaLabel="x" icons={ICONES} value={valor} onChange={setValor} />;
|
|
141
|
+
}
|
|
142
|
+
render(<Pai />);
|
|
143
|
+
expect(screen.getByRole("radio", { name: "Martelo" })).toHaveAttribute("aria-checked", "true");
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { faMagnifyingGlass } from "@fortawesome/free-solid-svg-icons";
|
|
5
|
+
import Input from "../components/Input/Input";
|
|
6
|
+
|
|
7
|
+
describe("Input · onChange a cada tecla, uma vez só", () => {
|
|
8
|
+
it("digitar chama onChange uma vez por tecla, com o valor novo", async () => {
|
|
9
|
+
const aoMudar = vi.fn();
|
|
10
|
+
render(<Input label="Nome" onChange={aoMudar} />);
|
|
11
|
+
await userEvent.type(screen.getByLabelText("Nome"), "ab");
|
|
12
|
+
expect(aoMudar.mock.calls.map((c) => c[0])).toEqual(["a", "ab"]);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("change disparado à mão também chega (testes de quem consome)", () => {
|
|
16
|
+
const aoMudar = vi.fn();
|
|
17
|
+
render(<Input label="Nome" onChange={aoMudar} />);
|
|
18
|
+
fireEvent.change(screen.getByLabelText("Nome"), { target: { value: "xyz" } });
|
|
19
|
+
expect(aoMudar).toHaveBeenCalledTimes(1);
|
|
20
|
+
expect(aoMudar).toHaveBeenCalledWith("xyz");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("onBlur continua sendo o evento de saída do campo", async () => {
|
|
24
|
+
const aoSair = vi.fn();
|
|
25
|
+
const aoMudar = vi.fn();
|
|
26
|
+
render(<Input label="Nome" onBlur={aoSair} onChange={aoMudar} />);
|
|
27
|
+
const campo = screen.getByLabelText("Nome");
|
|
28
|
+
await userEvent.type(campo, "a");
|
|
29
|
+
expect(aoSair).not.toHaveBeenCalled();
|
|
30
|
+
await userEvent.tab();
|
|
31
|
+
expect(aoSair).toHaveBeenCalledTimes(1);
|
|
32
|
+
expect(aoMudar).toHaveBeenCalledTimes(1);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("Input · mask", () => {
|
|
37
|
+
async function digitar(mask: any, texto: string) {
|
|
38
|
+
const aoMudar = vi.fn();
|
|
39
|
+
render(<Input label="Campo" mask={mask} onChange={aoMudar} />);
|
|
40
|
+
const campo = screen.getByLabelText("Campo") as HTMLInputElement;
|
|
41
|
+
await userEvent.type(campo, texto);
|
|
42
|
+
return { campo, aoMudar };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
it("cpf", async () => {
|
|
46
|
+
const { campo, aoMudar } = await digitar("cpf", "12345678901");
|
|
47
|
+
expect(campo.value).toBe("123.456.789-01");
|
|
48
|
+
expect(aoMudar).toHaveBeenLastCalledWith("123.456.789-01");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("cnpj", async () => {
|
|
52
|
+
const { campo } = await digitar("cnpj", "12345678000190");
|
|
53
|
+
expect(campo.value).toBe("12.345.678/0001-90");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("cep", async () => {
|
|
57
|
+
const { campo } = await digitar("cep", "80010000");
|
|
58
|
+
expect(campo.value).toBe("80010-000");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("phone troca de formato com 10 ou 11 dígitos", async () => {
|
|
62
|
+
expect((await digitar("phone", "4133334444")).campo.value).toBe("(41) 3333-4444");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("phone de 11 dígitos", async () => {
|
|
66
|
+
expect((await digitar("phone", "41999998888")).campo.value).toBe("(41) 99999-8888");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("ignora letras e passa do tamanho, sem estourar", async () => {
|
|
70
|
+
const { campo } = await digitar("cpf", "12a3.4b5-678901999");
|
|
71
|
+
expect(campo.value).toBe("123.456.789-01");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("valor controlado com dígitos aparece formatado", () => {
|
|
75
|
+
render(<Input label="CPF" mask="cpf" value="12345678901" onChange={() => {}} />);
|
|
76
|
+
expect((screen.getByLabelText("CPF") as HTMLInputElement).value).toBe("123.456.789-01");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("abre o teclado numérico e limita o tamanho; sem máscara, nenhum dos dois", () => {
|
|
80
|
+
render(
|
|
81
|
+
<>
|
|
82
|
+
<Input label="Com" mask="cep" />
|
|
83
|
+
<Input label="Sem" />
|
|
84
|
+
</>,
|
|
85
|
+
);
|
|
86
|
+
expect(screen.getByLabelText("Com")).toHaveAttribute("inputmode", "numeric");
|
|
87
|
+
expect(screen.getByLabelText("Com")).toHaveAttribute("maxlength", "9");
|
|
88
|
+
expect(screen.getByLabelText("Sem")).not.toHaveAttribute("inputmode");
|
|
89
|
+
expect(screen.getByLabelText("Sem")).not.toHaveAttribute("maxlength");
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("Input · iconRight e borderless", () => {
|
|
94
|
+
it("iconRight é decorativo: aparece, não é botão e fica fora da árvore de acessibilidade", () => {
|
|
95
|
+
const { container } = render(<Input ariaLabel="Número" iconRight={faMagnifyingGlass} />);
|
|
96
|
+
const icone = container.querySelector(".umds-input__icon-right") as HTMLElement;
|
|
97
|
+
expect(icone).not.toBeNull();
|
|
98
|
+
expect(icone).toHaveAttribute("aria-hidden", "true");
|
|
99
|
+
expect(icone.querySelector("svg")).not.toBeNull();
|
|
100
|
+
expect(screen.queryByRole("button")).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("sem iconRight não há ícone à direita", () => {
|
|
104
|
+
const { container } = render(<Input ariaLabel="x" />);
|
|
105
|
+
expect(container.querySelector(".umds-input__icon-right")).toBeNull();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("borderless escreve a classe; sem a prop não", () => {
|
|
109
|
+
const { container } = render(
|
|
110
|
+
<>
|
|
111
|
+
<Input ariaLabel="a" borderless />
|
|
112
|
+
<Input ariaLabel="b" />
|
|
113
|
+
</>,
|
|
114
|
+
);
|
|
115
|
+
expect(container.children[0]).toHaveClass("umds-input--borderless");
|
|
116
|
+
expect(container.children[1]).not.toHaveClass("umds-input--borderless");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("borderless com erro continua marcando o erro", () => {
|
|
120
|
+
const { container } = render(<Input ariaLabel="a" borderless errorMessage="Obrigatório" />);
|
|
121
|
+
expect(container.firstElementChild).toHaveClass("umds-input--borderless", "umds-input--error");
|
|
122
|
+
expect(screen.getByLabelText("a")).toHaveAttribute("aria-invalid", "true");
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { act, render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import Kbd from "../components/Kbd/Kbd";
|
|
5
|
+
import CodeBlock from "../components/CodeBlock/CodeBlock";
|
|
6
|
+
|
|
7
|
+
describe("Kbd", () => {
|
|
8
|
+
it("uma tecla é um kbd com o texto", () => {
|
|
9
|
+
const { container } = render(<Kbd>Esc</Kbd>);
|
|
10
|
+
const tecla = container.querySelector("kbd") as HTMLElement;
|
|
11
|
+
expect(tecla).toHaveTextContent("Esc");
|
|
12
|
+
expect(tecla).toHaveClass("umds-kbd", "umds-kbd--md");
|
|
13
|
+
expect(container.querySelectorAll("kbd")).toHaveLength(1);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("keys desenha uma tecla por item, com o separador entre elas", () => {
|
|
17
|
+
const { container } = render(<Kbd keys={["Ctrl", "Shift", "P"]} />);
|
|
18
|
+
const conjunto = container.querySelector("kbd.umds-kbd-combo") as HTMLElement;
|
|
19
|
+
expect(conjunto).not.toBeNull();
|
|
20
|
+
expect(conjunto.querySelectorAll("kbd.umds-kbd")).toHaveLength(3);
|
|
21
|
+
expect(conjunto.textContent).toBe("Ctrl+Shift+P");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("separator troca o texto entre as teclas; size vira classe", () => {
|
|
25
|
+
const { container } = render(<Kbd keys={["Ctrl", "K"]} separator=" + " size="sm" />);
|
|
26
|
+
expect(container.querySelector("kbd")).toHaveClass("umds-kbd--sm");
|
|
27
|
+
expect(container.textContent).toBe("Ctrl + K");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("atributos HTML vão para o kbd", () => {
|
|
31
|
+
const { container } = render(<Kbd title="Atalho" data-x="1">Tab</Kbd>);
|
|
32
|
+
const tecla = container.querySelector("kbd") as HTMLElement;
|
|
33
|
+
expect(tecla).toHaveAttribute("title", "Atalho");
|
|
34
|
+
expect(tecla).toHaveAttribute("data-x", "1");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("CodeBlock", () => {
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
vi.useRealTimers();
|
|
41
|
+
vi.restoreAllMocks();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("mostra o código em pre/code, mantendo as quebras, numa região focável e nomeada", () => {
|
|
45
|
+
const { container } = render(<CodeBlock code={'{\n "ok": true\n}'} ariaLabel="Resposta" />);
|
|
46
|
+
const regiao = screen.getByRole("region", { name: "Resposta" });
|
|
47
|
+
expect(regiao.tagName).toBe("PRE");
|
|
48
|
+
expect(regiao).toHaveAttribute("tabindex", "0");
|
|
49
|
+
expect(container.querySelector("code")?.textContent).toBe('{\n "ok": true\n}');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("o texto também vem como conteúdo; o nome padrão é a linguagem, ou Código", () => {
|
|
53
|
+
const { rerender } = render(<CodeBlock language="JSON">{"{}"}</CodeBlock>);
|
|
54
|
+
expect(screen.getByRole("region", { name: "JSON" })).toHaveTextContent("{}");
|
|
55
|
+
expect(screen.getByText("JSON", { selector: ".umds-code-block__language" })).toBeInTheDocument();
|
|
56
|
+
rerender(<CodeBlock code="x" />);
|
|
57
|
+
expect(screen.getByRole("region", { name: "Código" })).toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("wrap e maxHeight", () => {
|
|
61
|
+
const { container } = render(<CodeBlock code="linha longa" wrap maxHeight={120} />);
|
|
62
|
+
expect(container.querySelector(".umds-code-block--wrap")).not.toBeNull();
|
|
63
|
+
expect((container.querySelector("pre") as HTMLElement).style.maxHeight).toBe("120px");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("sem copyable e sem linguagem, não há cabeçalho nem botão", () => {
|
|
67
|
+
render(<CodeBlock code="x" />);
|
|
68
|
+
expect(screen.queryByRole("button")).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("copiar manda o texto inteiro à área de transferência, confirma e volta depois de 2 s", async () => {
|
|
72
|
+
vi.useFakeTimers({ shouldAdvanceTime: true });
|
|
73
|
+
const escrever = vi.fn(() => Promise.resolve());
|
|
74
|
+
const aoCopiar = vi.fn();
|
|
75
|
+
const usuario = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
|
|
76
|
+
// O userEvent.setup instala a própria área de transferência: o espião entra depois.
|
|
77
|
+
Object.defineProperty(navigator, "clipboard", { value: { writeText: escrever }, configurable: true });
|
|
78
|
+
render(<CodeBlock code={'{"a":1}'} copyable onCopy={aoCopiar} />);
|
|
79
|
+
await usuario.click(screen.getByRole("button", { name: "Copiar" }));
|
|
80
|
+
expect(escrever).toHaveBeenCalledWith('{"a":1}');
|
|
81
|
+
expect(await screen.findByRole("button", { name: "Copiado" })).toBeInTheDocument();
|
|
82
|
+
expect(aoCopiar).toHaveBeenCalledWith('{"a":1}');
|
|
83
|
+
expect(screen.getByRole("status")).toHaveTextContent("Copiado");
|
|
84
|
+
await act(async () => {
|
|
85
|
+
vi.advanceTimersByTime(2100);
|
|
86
|
+
});
|
|
87
|
+
expect(screen.getByRole("button", { name: "Copiar" })).toBeInTheDocument();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("copiar com o texto vindo como conteúdo lê o texto do bloco", async () => {
|
|
91
|
+
const escrever = vi.fn(() => Promise.resolve());
|
|
92
|
+
const usuario = userEvent.setup();
|
|
93
|
+
Object.defineProperty(navigator, "clipboard", { value: { writeText: escrever }, configurable: true });
|
|
94
|
+
render(<CodeBlock copyable>{"npm run build"}</CodeBlock>);
|
|
95
|
+
await usuario.click(screen.getByRole("button", { name: "Copiar" }));
|
|
96
|
+
expect(escrever).toHaveBeenCalledWith("npm run build");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("copyLabel e copiedLabel por prop", async () => {
|
|
100
|
+
const usuario = userEvent.setup();
|
|
101
|
+
Object.defineProperty(navigator, "clipboard", { value: { writeText: () => Promise.resolve() }, configurable: true });
|
|
102
|
+
render(<CodeBlock code="x" copyable copyLabel="Copy" copiedLabel="Copied" />);
|
|
103
|
+
await usuario.click(screen.getByRole("button", { name: "Copy" }));
|
|
104
|
+
expect(await screen.findByRole("button", { name: "Copied" })).toBeInTheDocument();
|
|
105
|
+
});
|
|
106
|
+
});
|