@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
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import { renderToString } from "react-dom/server";
|
|
4
|
+
import Select from "../components/Select/Select";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* O foco do Select cai no trigger `role="combobox"`, não num `<select>`
|
|
8
|
+
* nativo. Então nada liga a mensagem de erro ao campo de graça: se o
|
|
9
|
+
* `aria-describedby` não estiver no combobox, o leitor de tela anuncia
|
|
10
|
+
* "Setor, caixa de combinação" e a pessoa nunca ouve POR QUE o campo está
|
|
11
|
+
* vermelho.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const OPCOES = [
|
|
15
|
+
{ label: "Recursos Humanos", value: "rh" },
|
|
16
|
+
{ label: "Financeiro", value: "fin" },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
describe("Select · erro e apoio ligados ao campo", () => {
|
|
20
|
+
it("a mensagem de erro descreve o combobox e o marca inválido", () => {
|
|
21
|
+
render(
|
|
22
|
+
<Select label="Setor" options={OPCOES} errorMessage="Escolha um setor" />,
|
|
23
|
+
);
|
|
24
|
+
const campo = screen.getByRole("combobox", { name: "Setor" });
|
|
25
|
+
expect(campo).toHaveAccessibleDescription("Escolha um setor");
|
|
26
|
+
expect(campo).toHaveAttribute("aria-invalid", "true");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("erro e texto de apoio entram os dois, erro primeiro", () => {
|
|
30
|
+
render(
|
|
31
|
+
<Select
|
|
32
|
+
label="Setor"
|
|
33
|
+
options={OPCOES}
|
|
34
|
+
errorMessage="Obrigatório"
|
|
35
|
+
helperText="Onde a pessoa trabalha"
|
|
36
|
+
/>,
|
|
37
|
+
);
|
|
38
|
+
expect(screen.getByRole("combobox")).toHaveAccessibleDescription(
|
|
39
|
+
"Obrigatório Onde a pessoa trabalha",
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("o apelido antigo `description` também é ligado", () => {
|
|
44
|
+
render(<Select label="Setor" options={OPCOES} description="Opcional" />);
|
|
45
|
+
expect(screen.getByRole("combobox")).toHaveAccessibleDescription(
|
|
46
|
+
"Opcional",
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("sem erro nem apoio, nada de aria-describedby ou aria-invalid", () => {
|
|
51
|
+
render(<Select label="Setor" options={OPCOES} />);
|
|
52
|
+
const campo = screen.getByRole("combobox");
|
|
53
|
+
expect(campo).not.toHaveAttribute("aria-describedby");
|
|
54
|
+
expect(campo).not.toHaveAttribute("aria-invalid");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("`invalid` sem mensagem também marca aria-invalid", () => {
|
|
58
|
+
render(<Select label="Setor" options={OPCOES} invalid />);
|
|
59
|
+
expect(screen.getByRole("combobox")).toHaveAttribute(
|
|
60
|
+
"aria-invalid",
|
|
61
|
+
"true",
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("com `id`, os ids internos derivam dele", () => {
|
|
66
|
+
render(
|
|
67
|
+
<Select id="setor" label="Setor" options={OPCOES} errorMessage="Erro" />,
|
|
68
|
+
);
|
|
69
|
+
expect(screen.getByRole("combobox")).toHaveAttribute(
|
|
70
|
+
"aria-describedby",
|
|
71
|
+
"setor-error",
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("Select · ids na renderização do servidor", () => {
|
|
77
|
+
/**
|
|
78
|
+
* Id sorteado no render sai diferente no servidor e no cliente: a
|
|
79
|
+
* hidratação diverge e o describedby do HTML aponta para o nada. Duas
|
|
80
|
+
* renderizações de servidor têm de sair byte a byte iguais.
|
|
81
|
+
*/
|
|
82
|
+
it("o HTML do servidor é determinístico", () => {
|
|
83
|
+
const html = () =>
|
|
84
|
+
renderToString(
|
|
85
|
+
<Select label="Setor" options={OPCOES} errorMessage="Erro" />,
|
|
86
|
+
);
|
|
87
|
+
expect(html()).toBe(html());
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("com `id`, o servidor já manda o describedby", () => {
|
|
91
|
+
const html = renderToString(
|
|
92
|
+
<Select id="setor" label="Setor" options={OPCOES} errorMessage="Erro" />,
|
|
93
|
+
);
|
|
94
|
+
expect(html).toContain('aria-describedby="setor-error"');
|
|
95
|
+
expect(html).toContain('id="setor-error"');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import Select from "../components/Select/Select";
|
|
4
|
+
|
|
5
|
+
const OPCOES = [
|
|
6
|
+
{ label: "Urgente", value: "urgente" },
|
|
7
|
+
{ label: "Revisão", value: "revisao" },
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
afterEach(() => vi.restoreAllMocks());
|
|
11
|
+
|
|
12
|
+
/** jsdom não tem layout: o gatilho "mede" o que o teste mandar. */
|
|
13
|
+
function medirGatilho(topo: number, base: number, alturaDaTela: number) {
|
|
14
|
+
vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(
|
|
15
|
+
() => ({ top: topo, bottom: base, left: 0, right: 0, width: 0, height: base - topo, x: 0, y: topo, toJSON() {} }) as any,
|
|
16
|
+
);
|
|
17
|
+
Object.defineProperty(window, "innerHeight", { value: alturaDaTela, configurable: true });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("Select · placement", () => {
|
|
21
|
+
it("padrão abre para baixo", () => {
|
|
22
|
+
const { container } = render(<Select ariaLabel="x" options={OPCOES} />);
|
|
23
|
+
fireEvent.click(screen.getByRole("combobox"));
|
|
24
|
+
expect(container.querySelector(".umds-select--placement-top")).toBeNull();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("top abre para cima", () => {
|
|
28
|
+
const { container } = render(<Select ariaLabel="x" options={OPCOES} placement="top" />);
|
|
29
|
+
fireEvent.click(screen.getByRole("combobox"));
|
|
30
|
+
expect(container.querySelector(".umds-select--placement-top")).not.toBeNull();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("auto abre para cima quando falta espaço embaixo e há mais em cima", () => {
|
|
34
|
+
medirGatilho(500, 544, 600);
|
|
35
|
+
const { container } = render(<Select ariaLabel="x" options={OPCOES} placement="auto" />);
|
|
36
|
+
fireEvent.click(screen.getByRole("combobox"));
|
|
37
|
+
expect(container.querySelector(".umds-select--placement-top")).not.toBeNull();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("auto abre para baixo quando cabe", () => {
|
|
41
|
+
medirGatilho(20, 64, 900);
|
|
42
|
+
const { container } = render(<Select ariaLabel="x" options={OPCOES} placement="auto" />);
|
|
43
|
+
fireEvent.click(screen.getByRole("combobox"));
|
|
44
|
+
expect(container.querySelector(".umds-select--placement-top")).toBeNull();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("auto abre para baixo quando falta espaço dos dois lados e embaixo é maior", () => {
|
|
48
|
+
medirGatilho(60, 104, 220);
|
|
49
|
+
const { container } = render(<Select ariaLabel="x" options={OPCOES} placement="auto" />);
|
|
50
|
+
fireEvent.click(screen.getByRole("combobox"));
|
|
51
|
+
expect(container.querySelector(".umds-select--placement-top")).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("Select · variant filter", () => {
|
|
56
|
+
it("escreve a classe do filtro; sem variant não escreve", () => {
|
|
57
|
+
const { container, rerender } = render(<Select ariaLabel="x" options={OPCOES} variant="filter" />);
|
|
58
|
+
expect(container.querySelector(".umds-select--filter")).not.toBeNull();
|
|
59
|
+
rerender(<Select ariaLabel="x" options={OPCOES} />);
|
|
60
|
+
expect(container.querySelector(".umds-select--filter")).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("emptyOptionLabel vem no topo, marcada sem seleção; escolher chama onChange com vazio e volta ao placeholder", () => {
|
|
64
|
+
const aoMudar = vi.fn();
|
|
65
|
+
const { rerender } = render(
|
|
66
|
+
<Select ariaLabel="Marcadores" placeholder="Marcadores" options={OPCOES} emptyOptionLabel="Todos os marcadores" onChange={aoMudar} />,
|
|
67
|
+
);
|
|
68
|
+
fireEvent.click(screen.getByRole("combobox"));
|
|
69
|
+
const opcoes = screen.getAllByRole("option");
|
|
70
|
+
expect(opcoes[0]).toHaveTextContent("Todos os marcadores");
|
|
71
|
+
expect(opcoes[0]).toHaveAttribute("aria-selected", "true");
|
|
72
|
+
fireEvent.click(opcoes[1]);
|
|
73
|
+
expect(aoMudar).toHaveBeenLastCalledWith("urgente");
|
|
74
|
+
|
|
75
|
+
rerender(
|
|
76
|
+
<Select ariaLabel="Marcadores" placeholder="Marcadores" options={OPCOES} emptyOptionLabel="Todos os marcadores" value="urgente" onChange={aoMudar} />,
|
|
77
|
+
);
|
|
78
|
+
expect(screen.getByRole("combobox")).toHaveTextContent("Urgente");
|
|
79
|
+
fireEvent.click(screen.getByRole("combobox"));
|
|
80
|
+
fireEvent.click(screen.getAllByRole("option")[0]);
|
|
81
|
+
expect(aoMudar).toHaveBeenLastCalledWith("");
|
|
82
|
+
|
|
83
|
+
rerender(
|
|
84
|
+
<Select ariaLabel="Marcadores" placeholder="Marcadores" options={OPCOES} emptyOptionLabel="Todos os marcadores" value="" onChange={aoMudar} />,
|
|
85
|
+
);
|
|
86
|
+
expect(screen.getByRole("combobox")).toHaveTextContent("Marcadores");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("sem emptyOptionLabel não há opção extra", () => {
|
|
90
|
+
render(<Select ariaLabel="x" options={OPCOES} />);
|
|
91
|
+
fireEvent.click(screen.getByRole("combobox"));
|
|
92
|
+
expect(screen.getAllByRole("option")).toHaveLength(2);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("footer aparece dentro da lista aberta, e não fecha ao clicar nele", () => {
|
|
96
|
+
render(<Select ariaLabel="x" options={OPCOES} footer={<button>Gerenciar marcadores</button>} />);
|
|
97
|
+
expect(screen.queryByText("Gerenciar marcadores")).toBeNull();
|
|
98
|
+
fireEvent.click(screen.getByRole("combobox"));
|
|
99
|
+
const acao = screen.getByText("Gerenciar marcadores");
|
|
100
|
+
expect(acao.closest(".umds-select__footer")).not.toBeNull();
|
|
101
|
+
fireEvent.mouseDown(acao);
|
|
102
|
+
expect(screen.getByRole("combobox")).toHaveAttribute("aria-expanded", "true");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("sem footer não há rodapé", () => {
|
|
106
|
+
const { container } = render(<Select ariaLabel="x" options={OPCOES} />);
|
|
107
|
+
fireEvent.click(screen.getByRole("combobox"));
|
|
108
|
+
expect(container.querySelector(".umds-select__footer")).toBeNull();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import Stack from "../components/Stack/Stack";
|
|
4
|
+
|
|
5
|
+
const TAGS = ["div", "span", "ul", "ol", "li", "section", "nav", "header", "footer", "form"] as const;
|
|
6
|
+
|
|
7
|
+
describe("Stack", () => {
|
|
8
|
+
it("sem props continua um div vertical com gap xxxs", () => {
|
|
9
|
+
const { container } = render(<Stack>x</Stack>);
|
|
10
|
+
const el = container.firstElementChild as HTMLElement;
|
|
11
|
+
expect(el.tagName).toBe("DIV");
|
|
12
|
+
expect(el.className).toBe("umds-stack umds-stack--vertical umds-stack--gap-xxxs");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("aceita gap none", () => {
|
|
16
|
+
const { container } = render(<Stack gap="none">x</Stack>);
|
|
17
|
+
expect(container.firstElementChild).toHaveClass("umds-stack--gap-none");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it.each(TAGS)("as=%s renderiza o elemento certo", (tag) => {
|
|
21
|
+
const { container } = render(<Stack as={tag}>x</Stack>);
|
|
22
|
+
expect(container.firstElementChild?.tagName.toLowerCase()).toBe(tag);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("ul e ol mantêm a semântica de lista", () => {
|
|
26
|
+
const { container } = render(
|
|
27
|
+
<Stack as="ul" aria-label="Itens">
|
|
28
|
+
<Stack as="li">um</Stack>
|
|
29
|
+
</Stack>,
|
|
30
|
+
);
|
|
31
|
+
expect(screen.getByRole("list", { name: "Itens" })).toBeInTheDocument();
|
|
32
|
+
expect(container.querySelectorAll("li")).toHaveLength(1);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("repassa id, aria-label, title e style ao elemento raiz", () => {
|
|
36
|
+
const { container } = render(
|
|
37
|
+
<Stack as="nav" id="menu" aria-label="Principal" title="Dica" style={{ marginTop: 4 }}>
|
|
38
|
+
x
|
|
39
|
+
</Stack>,
|
|
40
|
+
);
|
|
41
|
+
const el = container.firstElementChild as HTMLElement;
|
|
42
|
+
expect(el.id).toBe("menu");
|
|
43
|
+
expect(el.getAttribute("aria-label")).toBe("Principal");
|
|
44
|
+
expect(el.getAttribute("title")).toBe("Dica");
|
|
45
|
+
expect(el.style.marginTop).toBe("4px");
|
|
46
|
+
expect(screen.getByRole("navigation", { name: "Principal" })).toBe(el);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("as=form chama onSubmit", () => {
|
|
50
|
+
const aoEnviar = vi.fn((e: Event) => e.preventDefault());
|
|
51
|
+
const { container } = render(
|
|
52
|
+
<Stack as="form" onSubmit={aoEnviar}>
|
|
53
|
+
<button type="submit">Enviar</button>
|
|
54
|
+
</Stack>,
|
|
55
|
+
);
|
|
56
|
+
fireEvent.submit(container.querySelector("form") as HTMLFormElement);
|
|
57
|
+
expect(aoEnviar).toHaveBeenCalledTimes(1);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("escreve as classes de item flex", () => {
|
|
61
|
+
const { container } = render(
|
|
62
|
+
<Stack grow shrink="0" basis="50" minWidth="auto" overflow="hidden" overflowY="auto" fullHeight>
|
|
63
|
+
x
|
|
64
|
+
</Stack>,
|
|
65
|
+
);
|
|
66
|
+
const el = container.firstElementChild as HTMLElement;
|
|
67
|
+
for (const c of [
|
|
68
|
+
"umds-stack--grow",
|
|
69
|
+
"umds-stack--shrink-0",
|
|
70
|
+
"umds-stack--basis-50",
|
|
71
|
+
"umds-stack--min-w-auto",
|
|
72
|
+
"umds-stack--overflow-hidden",
|
|
73
|
+
"umds-stack--overflow-y-auto",
|
|
74
|
+
"umds-stack--full-height",
|
|
75
|
+
]) {
|
|
76
|
+
expect(el).toHaveClass(c);
|
|
77
|
+
}
|
|
78
|
+
expect(el).not.toHaveClass("umds-stack--full-width");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import StatCard from "../components/StatCard/StatCard";
|
|
4
|
+
|
|
5
|
+
const raiz = (c: HTMLElement) => c.firstElementChild as HTMLElement;
|
|
6
|
+
|
|
7
|
+
describe("StatCard · labelPosition", () => {
|
|
8
|
+
it("top escreve a classe; sem a prop o cartão é o de antes", () => {
|
|
9
|
+
const { container } = render(
|
|
10
|
+
<>
|
|
11
|
+
<StatCard value={44} label="Não lidos" labelPosition="top" />
|
|
12
|
+
<StatCard value={44} label="Não lidos" />
|
|
13
|
+
</>,
|
|
14
|
+
);
|
|
15
|
+
expect(container.children[0]).toHaveClass("umds-stat-card--rotulo-topo");
|
|
16
|
+
expect(container.children[1]).not.toHaveClass("umds-stat-card--rotulo-topo");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("o número continua antes do rótulo no HTML (ordem do leitor de tela)", () => {
|
|
20
|
+
const { container } = render(<StatCard value={44} label="Não lidos" labelPosition="top" />);
|
|
21
|
+
const valor = container.querySelector(".umds-stat-card__valor") as HTMLElement;
|
|
22
|
+
const rotulo = container.querySelector(".umds-stat-card__rotulo") as HTMLElement;
|
|
23
|
+
expect(valor.compareDocumentPosition(rotulo) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe("StatCard · infoTooltip", () => {
|
|
28
|
+
it("mostra o ⓘ como botão nomeado, dentro do rótulo, descrito pelo texto de ajuda", () => {
|
|
29
|
+
const { container } = render(<StatCard value={44} label="Não lidos" infoTooltip="Ainda não abertos por você." />);
|
|
30
|
+
const info = screen.getByRole("button", { name: "Mais informações" });
|
|
31
|
+
expect(container.querySelector(".umds-stat-card__rotulo")?.contains(info)).toBe(true);
|
|
32
|
+
expect(info).toHaveAccessibleDescription("Ainda não abertos por você.");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("infoLabel traduz o nome do ⓘ", () => {
|
|
36
|
+
render(<StatCard value={1} label="Unread" infoTooltip="Not opened yet." infoLabel="More info" />);
|
|
37
|
+
expect(screen.getByRole("button", { name: "More info" })).toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("sem infoTooltip não há botão", () => {
|
|
41
|
+
render(<StatCard value={1} label="x" />);
|
|
42
|
+
expect(screen.queryByRole("button")).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import Tabs from "../components/Tabs/Tabs";
|
|
4
|
+
import Tab from "../components/Tabs/Tab";
|
|
5
|
+
|
|
6
|
+
describe("Tab · count", () => {
|
|
7
|
+
it("mostra o contador em pílula e ele entra no nome da aba", () => {
|
|
8
|
+
render(
|
|
9
|
+
<Tabs value="0" ariaLabel="Tarefas">
|
|
10
|
+
<Tab label="Todas" index="0" count={31} />
|
|
11
|
+
<Tab label="Atribuídas" index="1" count={9} />
|
|
12
|
+
</Tabs>,
|
|
13
|
+
);
|
|
14
|
+
expect(screen.getByRole("tab", { name: "Todas 31" })).toBeInTheDocument();
|
|
15
|
+
expect(screen.getByRole("tab", { name: "Atribuídas 9" })).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("o 0 aparece; sem count, não há pílula", () => {
|
|
19
|
+
const { container } = render(
|
|
20
|
+
<Tabs value="0">
|
|
21
|
+
<Tab label="Concluídas" index="0" count={0} />
|
|
22
|
+
<Tab label="Sem contador" index="1" />
|
|
23
|
+
</Tabs>,
|
|
24
|
+
);
|
|
25
|
+
const pilulas = container.querySelectorAll(".umds-tabs__count");
|
|
26
|
+
expect(pilulas).toHaveLength(1);
|
|
27
|
+
expect(pilulas[0].textContent).toBe("0");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("a pílula fica dentro da aba selecionada (que a pinta de azul pelo CSS)", () => {
|
|
31
|
+
const { container } = render(
|
|
32
|
+
<Tabs value="1">
|
|
33
|
+
<Tab label="A" index="0" count={1} />
|
|
34
|
+
<Tab label="B" index="1" count={2} />
|
|
35
|
+
</Tabs>,
|
|
36
|
+
);
|
|
37
|
+
const selecionada = container.querySelector(".umds-tabs__tab--selected");
|
|
38
|
+
expect(selecionada?.querySelector(".umds-tabs__count")?.textContent).toBe("2");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("Tab · closable", () => {
|
|
43
|
+
it("o × é um botão irmão da aba, com o nome 'Fechar <aba>'", () => {
|
|
44
|
+
render(
|
|
45
|
+
<Tabs value="0">
|
|
46
|
+
<Tab label="Documento 1" index="0" closable />
|
|
47
|
+
</Tabs>,
|
|
48
|
+
);
|
|
49
|
+
const fechar = screen.getByRole("button", { name: "Fechar Documento 1" });
|
|
50
|
+
const aba = screen.getByRole("tab");
|
|
51
|
+
expect(aba.contains(fechar)).toBe(false);
|
|
52
|
+
expect(fechar.parentElement).toBe(aba.parentElement);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("o rótulo do × vem por prop", () => {
|
|
56
|
+
render(
|
|
57
|
+
<Tabs value="0">
|
|
58
|
+
<Tab label="Doc 1" index="0" closable closeLabel="Close" />
|
|
59
|
+
</Tabs>,
|
|
60
|
+
);
|
|
61
|
+
expect(screen.getByRole("button", { name: "Close Doc 1" })).toBeInTheDocument();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("clicar no × chama onClose com o index e não troca de aba", () => {
|
|
65
|
+
const aoFechar = vi.fn();
|
|
66
|
+
const aoTrocar = vi.fn();
|
|
67
|
+
render(
|
|
68
|
+
<Tabs value="0" onChange={aoTrocar}>
|
|
69
|
+
<Tab label="Um" index="0" />
|
|
70
|
+
<Tab label="Dois" index="1" closable onClose={aoFechar} />
|
|
71
|
+
</Tabs>,
|
|
72
|
+
);
|
|
73
|
+
fireEvent.click(screen.getByRole("button", { name: "Fechar Dois" }));
|
|
74
|
+
expect(aoFechar).toHaveBeenCalledTimes(1);
|
|
75
|
+
expect(aoFechar.mock.calls[0][0]).toBe("1");
|
|
76
|
+
expect(aoTrocar).not.toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("Delete na aba focada fecha; sem closable, não", () => {
|
|
80
|
+
const aoFechar = vi.fn();
|
|
81
|
+
render(
|
|
82
|
+
<Tabs value="0">
|
|
83
|
+
<Tab label="Fechável" index="0" closable onClose={aoFechar} />
|
|
84
|
+
<Tab label="Fixa" index="1" onClose={aoFechar} />
|
|
85
|
+
</Tabs>,
|
|
86
|
+
);
|
|
87
|
+
fireEvent.keyDown(screen.getByRole("tab", { name: "Fechável" }), { key: "Delete" });
|
|
88
|
+
expect(aoFechar).toHaveBeenCalledTimes(1);
|
|
89
|
+
fireEvent.keyDown(screen.getByRole("tab", { name: "Fixa" }), { key: "Delete" });
|
|
90
|
+
expect(aoFechar).toHaveBeenCalledTimes(1);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("sem closable não há ×", () => {
|
|
94
|
+
render(
|
|
95
|
+
<Tabs value="0">
|
|
96
|
+
<Tab label="Fixa" index="0" />
|
|
97
|
+
</Tabs>,
|
|
98
|
+
);
|
|
99
|
+
expect(screen.queryByRole("button")).toBeNull();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("o tablist só tem abas como filhas de papel (o × não é tab)", () => {
|
|
103
|
+
render(
|
|
104
|
+
<Tabs value="0">
|
|
105
|
+
<Tab label="A" index="0" closable />
|
|
106
|
+
<Tab label="B" index="1" closable />
|
|
107
|
+
</Tabs>,
|
|
108
|
+
);
|
|
109
|
+
expect(screen.getAllByRole("tab")).toHaveLength(2);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("Tabs · onAdd", () => {
|
|
114
|
+
it("mostra o + fora do tablist e chama onAdd", () => {
|
|
115
|
+
const aoAdicionar = vi.fn();
|
|
116
|
+
render(
|
|
117
|
+
<Tabs value="0" onAdd={aoAdicionar}>
|
|
118
|
+
<Tab label="A" index="0" />
|
|
119
|
+
</Tabs>,
|
|
120
|
+
);
|
|
121
|
+
const mais = screen.getByRole("button", { name: "Adicionar aba" });
|
|
122
|
+
expect(screen.getByRole("tablist").contains(mais)).toBe(false);
|
|
123
|
+
fireEvent.click(mais);
|
|
124
|
+
expect(aoAdicionar).toHaveBeenCalledTimes(1);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("o rótulo do + vem por prop", () => {
|
|
128
|
+
render(
|
|
129
|
+
<Tabs value="0" onAdd={() => {}} addLabel="New tab">
|
|
130
|
+
<Tab label="A" index="0" />
|
|
131
|
+
</Tabs>,
|
|
132
|
+
);
|
|
133
|
+
expect(screen.getByRole("button", { name: "New tab" })).toBeInTheDocument();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("sem onAdd não há botão", () => {
|
|
137
|
+
render(
|
|
138
|
+
<Tabs value="0">
|
|
139
|
+
<Tab label="A" index="0" />
|
|
140
|
+
</Tabs>,
|
|
141
|
+
);
|
|
142
|
+
expect(screen.queryByRole("button")).toBeNull();
|
|
143
|
+
});
|
|
144
|
+
});
|