@1doc/1ds-react 2.8.0 → 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 +1106 -0
- package/dist/components/AILabel/AILabel.js +1 -1
- package/dist/components/Accordion/Accordion.d.ts +6 -2
- package/dist/components/AttachmentCard/AttachmentCard.css +16 -0
- package/dist/components/AttachmentCard/AttachmentCard.d.ts +19 -2
- package/dist/components/AttachmentCard/AttachmentCard.js +40 -3
- package/dist/components/Avatar/Avatar.css +7 -2
- package/dist/components/Avatar/AvatarGroup.d.ts +17 -0
- package/dist/components/Avatar/AvatarGroup.js +22 -8
- package/dist/components/Badge/Badge.css +54 -2
- package/dist/components/Badge/Badge.d.ts +14 -4
- package/dist/components/Badge/Badge.js +1 -0
- 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/Chips/Chips.css +38 -0
- package/dist/components/Chips/Chips.d.ts +5 -2
- package/dist/components/Chips/Chips.js +2 -1
- 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 +8 -0
- package/dist/components/DataTable/DataTable.css +80 -0
- package/dist/components/DataTable/DataTable.d.ts +19 -4
- package/dist/components/DataTable/DataTable.js +59 -15
- package/dist/components/DatePicker/DatePicker.css +8 -0
- package/dist/components/DatePicker/DatePicker.js +10 -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/FileInput/FileInput.css +16 -0
- package/dist/components/FileInput/FileInput.d.ts +4 -2
- package/dist/components/FileInput/FileInput.js +8 -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 +38 -0
- package/dist/components/Input/Input.d.ts +10 -1
- package/dist/components/Input/Input.js +66 -5
- package/dist/components/Kanban/Kanban.css +4 -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/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 +80 -0
- package/dist/components/Modal/Modal.d.ts +33 -6
- package/dist/components/Modal/Modal.js +101 -6
- package/dist/components/MultiSelect/MultiSelect.css +8 -0
- package/dist/components/MultiSelect/MultiSelect.js +10 -1
- 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/PhoneInput/PhoneInput.css +8 -0
- 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.js +7 -2
- package/dist/components/Select/Select.css +70 -0
- package/dist/components/Select/Select.d.ts +12 -0
- package/dist/components/Select/Select.js +59 -4
- 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/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.js +2 -2
- package/dist/components/Textarea/Textarea.css +8 -0
- package/dist/components/TimePicker/TimePicker.css +8 -0
- package/dist/components/Tooltip/Tooltip.css +25 -0
- package/dist/components/Tooltip/Tooltip.d.ts +11 -0
- package/dist/components/Tooltip/Tooltip.js +18 -3
- 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/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/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/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/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/ModalVariantes.test.d.ts +1 -0
- package/dist/teste/ModalVariantes.test.js +151 -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/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/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/html-seguro.d.ts +27 -0
- package/dist/utils/html-seguro.js +97 -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/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/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/DataTableCelulaLivre.test.tsx +103 -0
- package/src/teste/DataTableDocumento.test.tsx +102 -0
- package/src/teste/DatePicker.test.tsx +38 -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/ModalVariantes.test.tsx +173 -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/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/TooltipDark.test.tsx +51 -0
- package/src/utils/calendario.ts +78 -0
- package/src/utils/html-seguro.ts +94 -0
- package/src/utils/paleta-de-cores.ts +34 -0
- package/src/utils/texto.ts +5 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import DataTable from "../components/DataTable/DataTable";
|
|
6
|
+
import DescriptionList from "../components/DescriptionList/DescriptionList";
|
|
7
|
+
const COLUNAS = [
|
|
8
|
+
{ key: "descricao", label: "Descrição", sortable: true },
|
|
9
|
+
{ key: "quantidade", label: "Quantidade", align: "right" },
|
|
10
|
+
];
|
|
11
|
+
const DADOS = [
|
|
12
|
+
{ descricao: "Diesel S10", quantidade: "5.760" },
|
|
13
|
+
{ descricao: "Gasolina comum", quantidade: "1.200" },
|
|
14
|
+
];
|
|
15
|
+
describe("DataTable variant=document", () => {
|
|
16
|
+
it("é a tabela de documento: classe própria, cabeçalho e linhas", () => {
|
|
17
|
+
const { container } = render(_jsx(DataTable, { variant: "document", columns: COLUNAS, data: DADOS }));
|
|
18
|
+
expect(container.querySelector(".umds-datatable--document")).not.toBeNull();
|
|
19
|
+
expect(screen.getAllByRole("columnheader")).toHaveLength(2);
|
|
20
|
+
expect(screen.getByText("Diesel S10")).toBeInTheDocument();
|
|
21
|
+
});
|
|
22
|
+
it("não ordena: sem botão de ordenar, sem aria-sort", () => {
|
|
23
|
+
render(_jsx(DataTable, { variant: "document", columns: COLUNAS, data: DADOS, sortKey: "descricao", sortDirection: "asc" }));
|
|
24
|
+
expect(screen.queryByRole("button")).toBeNull();
|
|
25
|
+
for (const th of screen.getAllByRole("columnheader"))
|
|
26
|
+
expect(th).not.toHaveAttribute("aria-sort");
|
|
27
|
+
});
|
|
28
|
+
it("não seleciona: selectable é ignorado", () => {
|
|
29
|
+
render(_jsx(DataTable, { variant: "document", selectable: true, columns: COLUNAS, data: DADOS }));
|
|
30
|
+
expect(screen.queryByRole("checkbox")).toBeNull();
|
|
31
|
+
expect(screen.getAllByRole("columnheader")).toHaveLength(2);
|
|
32
|
+
});
|
|
33
|
+
it("linha não é clicável nem entra na ordem de Tab", async () => {
|
|
34
|
+
const usuario = userEvent.setup();
|
|
35
|
+
const aoClicar = vi.fn();
|
|
36
|
+
const { container } = render(_jsx(DataTable, { variant: "document", columns: COLUNAS, data: DADOS, onRowClick: aoClicar }));
|
|
37
|
+
const linha = container.querySelector("tbody tr");
|
|
38
|
+
expect(linha).not.toHaveAttribute("tabindex");
|
|
39
|
+
expect(linha).not.toHaveClass("umds-datatable__row--clickable");
|
|
40
|
+
await usuario.click(linha);
|
|
41
|
+
expect(aoClicar).not.toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
it("a tabela de interface continua igual (ordena, seleciona, clica)", async () => {
|
|
44
|
+
const usuario = userEvent.setup();
|
|
45
|
+
const aoOrdenar = vi.fn();
|
|
46
|
+
render(_jsx(DataTable, { columns: COLUNAS, data: DADOS, selectable: true, onSort: aoOrdenar }));
|
|
47
|
+
expect(screen.getAllByRole("checkbox").length).toBeGreaterThan(0);
|
|
48
|
+
await usuario.click(screen.getByRole("button", { name: /Descrição/ }));
|
|
49
|
+
expect(aoOrdenar).toHaveBeenCalledWith("descricao", "asc");
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe("DescriptionList", () => {
|
|
53
|
+
const ITENS = [
|
|
54
|
+
{ label: "Dotação", value: "02.031.0001" },
|
|
55
|
+
{ label: "Empenho", value: "2026NE000184" },
|
|
56
|
+
{ label: "Fonte", value: "" },
|
|
57
|
+
];
|
|
58
|
+
it("é um dl com um dt e um dd por par", () => {
|
|
59
|
+
const { container } = render(_jsx(DescriptionList, { items: ITENS, ariaLabel: "Dados de empenho" }));
|
|
60
|
+
const dl = container.querySelector("dl");
|
|
61
|
+
expect(dl).toHaveAttribute("aria-label", "Dados de empenho");
|
|
62
|
+
expect(dl.querySelectorAll("dt")).toHaveLength(3);
|
|
63
|
+
expect(dl.querySelectorAll("dd")).toHaveLength(3);
|
|
64
|
+
expect(dl.querySelector("dt")).toHaveTextContent("Dotação");
|
|
65
|
+
expect(dl.querySelector("dd")).toHaveTextContent("02.031.0001");
|
|
66
|
+
});
|
|
67
|
+
it("valor vazio mostra o traço, ou o texto de emptyValue", () => {
|
|
68
|
+
const { container, rerender } = render(_jsx(DescriptionList, { items: ITENS }));
|
|
69
|
+
expect(container.querySelectorAll("dd")[2]).toHaveTextContent("—");
|
|
70
|
+
rerender(_jsx(DescriptionList, { items: ITENS, emptyValue: "N\u00E3o informado" }));
|
|
71
|
+
expect(container.querySelectorAll("dd")[2]).toHaveTextContent("Não informado");
|
|
72
|
+
});
|
|
73
|
+
it("inline é o padrão; fit encolhe", () => {
|
|
74
|
+
const { container, rerender } = render(_jsx(DescriptionList, { items: ITENS }));
|
|
75
|
+
const dl = container.querySelector("dl");
|
|
76
|
+
expect(dl).toHaveClass("umds-description-list--inline");
|
|
77
|
+
expect(dl).not.toHaveClass("umds-description-list--fit");
|
|
78
|
+
rerender(_jsx(DescriptionList, { items: ITENS, fit: true }));
|
|
79
|
+
expect(container.querySelector("dl")).toHaveClass("umds-description-list--fit");
|
|
80
|
+
});
|
|
81
|
+
it("stacked ganha as colunas e a caixa do valor", () => {
|
|
82
|
+
const { container } = render(_jsx(DescriptionList, { items: ITENS, layout: "stacked", columns: 3, bordered: true }));
|
|
83
|
+
const dl = container.querySelector("dl");
|
|
84
|
+
expect(dl).toHaveClass("umds-description-list--stacked");
|
|
85
|
+
expect(dl).toHaveClass("umds-description-list--cols-3");
|
|
86
|
+
expect(dl).toHaveClass("umds-description-list--bordered");
|
|
87
|
+
});
|
|
88
|
+
it("sem itens, não desenha par nenhum", () => {
|
|
89
|
+
const { container } = render(_jsx(DescriptionList, {}));
|
|
90
|
+
expect(container.querySelectorAll("dt")).toHaveLength(0);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -69,3 +69,26 @@ describe("DatePicker · teclado", () => {
|
|
|
69
69
|
expect(screen.getByRole("combobox")).toHaveTextContent(/15\/\d{2}\/\d{4}/);
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
|
+
/**
|
|
73
|
+
* A story "Com valor" mostrava "Selecione o período" com `value="2025-12-31"`.
|
|
74
|
+
* Não era a story: no modo single o componente só lia `range`, e `value` e
|
|
75
|
+
* `defaultValue` eram declarados e nunca chegavam ao campo.
|
|
76
|
+
*/
|
|
77
|
+
describe("DatePicker · valor no modo single", () => {
|
|
78
|
+
it("`value` aparece no campo, no formato pedido", () => {
|
|
79
|
+
render(_jsx(DatePicker, { label: "Vencimento", value: "2025-12-31", format: "DD/MM/YYYY" }));
|
|
80
|
+
expect(screen.getByRole("combobox")).toHaveTextContent("31/12/2025");
|
|
81
|
+
});
|
|
82
|
+
it("`defaultValue` semeia o campo no modo não-controlado", () => {
|
|
83
|
+
render(_jsx(DatePicker, { label: "Vencimento", defaultValue: "2025-06-15" }));
|
|
84
|
+
expect(screen.getByRole("combobox")).toHaveTextContent("15/06/2025");
|
|
85
|
+
});
|
|
86
|
+
it("`value` vazio no modo controlado mostra o placeholder", () => {
|
|
87
|
+
render(_jsx(DatePicker, { label: "Vencimento", value: "", placeholder: "DD/MM/AAAA" }));
|
|
88
|
+
expect(screen.getByRole("combobox")).toHaveTextContent("DD/MM/AAAA");
|
|
89
|
+
});
|
|
90
|
+
it("o modo range continua lendo `range`, não `value`", () => {
|
|
91
|
+
render(_jsx(DatePicker, { mode: "range", label: "Per\u00EDodo", value: "2025-01-01", range: { from: "2025-03-01", to: "2025-03-10" } }));
|
|
92
|
+
expect(screen.getByRole("combobox")).toHaveTextContent("01/03/2025 – 10/03/2025");
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
+
import FileInput from "../components/FileInput/FileInput";
|
|
5
|
+
const arquivo = (nome) => new File(["conteudo"], nome, { type: "application/pdf" });
|
|
6
|
+
describe("FileInput · variant trigger", () => {
|
|
7
|
+
it("renderiza o conteúdo como gatilho, sem a caixa de arrastar", () => {
|
|
8
|
+
const { container } = render(_jsx(FileInput, { variant: "trigger", children: _jsx("button", { type: "button", children: "Anexar arquivo" }) }));
|
|
9
|
+
expect(screen.getByRole("button", { name: "Anexar arquivo" })).toBeInTheDocument();
|
|
10
|
+
expect(container.querySelector(".umds-file-input__drop-zone")).toBeNull();
|
|
11
|
+
expect(container.querySelector(".umds-file-input--trigger")).not.toBeNull();
|
|
12
|
+
});
|
|
13
|
+
it("clicar no conteúdo abre o seletor (clique no input nativo)", () => {
|
|
14
|
+
const { container } = render(_jsx(FileInput, { variant: "trigger", children: _jsx("button", { type: "button", children: "Anexar arquivo" }) }));
|
|
15
|
+
const nativo = container.querySelector('input[type="file"]');
|
|
16
|
+
const clique = vi.spyOn(nativo, "click");
|
|
17
|
+
fireEvent.click(screen.getByRole("button", { name: "Anexar arquivo" }));
|
|
18
|
+
expect(clique).toHaveBeenCalledTimes(1);
|
|
19
|
+
});
|
|
20
|
+
it("disabled não abre o seletor", () => {
|
|
21
|
+
const { container } = render(_jsx(FileInput, { variant: "trigger", disabled: true, children: _jsx("span", { children: "Alterar foto" }) }));
|
|
22
|
+
const nativo = container.querySelector('input[type="file"]');
|
|
23
|
+
const clique = vi.spyOn(nativo, "click");
|
|
24
|
+
fireEvent.click(screen.getByText("Alterar foto"));
|
|
25
|
+
expect(clique).not.toHaveBeenCalled();
|
|
26
|
+
});
|
|
27
|
+
it("escolher arquivos chama onChange, e accept e multiple chegam ao input", () => {
|
|
28
|
+
const aoMudar = vi.fn();
|
|
29
|
+
const { container } = render(_jsx(FileInput, { variant: "trigger", accept: ".pdf", multiple: true, onChange: aoMudar, children: _jsx("button", { type: "button", children: "Anexar" }) }));
|
|
30
|
+
const nativo = container.querySelector('input[type="file"]');
|
|
31
|
+
expect(nativo).toHaveAttribute("accept", ".pdf");
|
|
32
|
+
expect(nativo).toHaveAttribute("multiple");
|
|
33
|
+
fireEvent.change(nativo, { target: { files: [arquivo("a.pdf"), arquivo("b.pdf")] } });
|
|
34
|
+
expect(aoMudar).toHaveBeenCalledTimes(1);
|
|
35
|
+
expect(aoMudar.mock.calls[0][0].map((f) => f.name)).toEqual(["a.pdf", "b.pdf"]);
|
|
36
|
+
});
|
|
37
|
+
it("o input nativo não entra no Tab e tem nome acessível", () => {
|
|
38
|
+
const { container } = render(_jsx(FileInput, { variant: "trigger", label: "Anexar arquivo", children: _jsx("button", { type: "button", children: "Anexar" }) }));
|
|
39
|
+
const nativo = container.querySelector('input[type="file"]');
|
|
40
|
+
expect(nativo).toHaveAttribute("tabindex", "-1");
|
|
41
|
+
expect(nativo).toHaveAttribute("aria-label", "Anexar arquivo");
|
|
42
|
+
// o rótulo visível não aparece: o gatilho é o conteúdo
|
|
43
|
+
expect(container.querySelector(".umds-file-input__label")).toBeNull();
|
|
44
|
+
});
|
|
45
|
+
it("a lista de arquivos continua aparecendo no modo trigger", () => {
|
|
46
|
+
render(_jsx(FileInput, { variant: "trigger", files: [{ name: "oficio.pdf", size: 2048 }], children: _jsx("button", { type: "button", children: "Anexar" }) }));
|
|
47
|
+
expect(screen.getByText("oficio.pdf")).toBeInTheDocument();
|
|
48
|
+
});
|
|
49
|
+
it("as variantes base e card seguem com a caixa", () => {
|
|
50
|
+
const { container } = render(_jsxs(_Fragment, { children: [_jsx(FileInput, { variant: "base" }), _jsx(FileInput, { variant: "card" })] }));
|
|
51
|
+
expect(container.querySelectorAll(".umds-file-input__drop-zone")).toHaveLength(2);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { render, screen } from "@testing-library/react";
|
|
5
|
+
import userEvent from "@testing-library/user-event";
|
|
6
|
+
import { faBuilding, faFileLines, faFolder, faGavel, faUser } from "@fortawesome/free-solid-svg-icons";
|
|
7
|
+
import IconPicker from "../components/IconPicker/IconPicker";
|
|
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
|
+
const radios = () => screen.getAllByRole("radio");
|
|
16
|
+
describe("IconPicker", () => {
|
|
17
|
+
it("é um radiogroup com um radio por ícone, nomeado pelo iconName sem hífen", () => {
|
|
18
|
+
render(_jsx(IconPicker, { ariaLabel: "\u00CDcone da categoria", icons: ICONES }));
|
|
19
|
+
expect(screen.getByRole("radiogroup", { name: "Ícone da categoria" })).toBeInTheDocument();
|
|
20
|
+
expect(radios()).toHaveLength(5);
|
|
21
|
+
expect(screen.getByRole("radio", { name: "user" })).toBeInTheDocument();
|
|
22
|
+
expect(screen.getByRole("radio", { name: "file lines" })).toBeInTheDocument();
|
|
23
|
+
expect(screen.getByRole("radio", { name: "Prédio" })).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
it("iconLabel traduz os nomes que não vêm com label", () => {
|
|
26
|
+
render(_jsx(IconPicker, { ariaLabel: "x", icons: [faUser, faFolder], iconLabel: (n) => ({ user: "Pessoa", folder: "Pasta" }[n]) }));
|
|
27
|
+
expect(screen.getByRole("radio", { name: "Pessoa" })).toBeInTheDocument();
|
|
28
|
+
expect(screen.getByRole("radio", { name: "Pasta" })).toBeInTheDocument();
|
|
29
|
+
});
|
|
30
|
+
it("clicar escolhe e entrega o NOME do ícone e o item em onChange", async () => {
|
|
31
|
+
const usuario = userEvent.setup();
|
|
32
|
+
const aoMudar = vi.fn();
|
|
33
|
+
render(_jsx(IconPicker, { ariaLabel: "x", icons: ICONES, onChange: aoMudar }));
|
|
34
|
+
await usuario.click(screen.getByRole("radio", { name: "folder" }));
|
|
35
|
+
expect(aoMudar).toHaveBeenCalledWith("folder", faFolder);
|
|
36
|
+
expect(screen.getByRole("radio", { name: "folder" })).toHaveAttribute("aria-checked", "true");
|
|
37
|
+
await usuario.click(screen.getByRole("radio", { name: "Prédio" }));
|
|
38
|
+
expect(aoMudar).toHaveBeenLastCalledWith("building", ICONES[3]);
|
|
39
|
+
});
|
|
40
|
+
it("defaultValue marca o escolhido; só ele entra na ordem de Tab", () => {
|
|
41
|
+
render(_jsx(IconPicker, { ariaLabel: "x", icons: ICONES, defaultValue: "file-lines" }));
|
|
42
|
+
expect(screen.getByRole("radio", { name: "file lines" })).toHaveAttribute("aria-checked", "true");
|
|
43
|
+
const comTab = radios().filter((r) => r.getAttribute("tabindex") === "0");
|
|
44
|
+
expect(comTab).toHaveLength(1);
|
|
45
|
+
expect(comTab[0]).toHaveAccessibleName("file lines");
|
|
46
|
+
});
|
|
47
|
+
it("sem valor, Tab entra no primeiro", () => {
|
|
48
|
+
render(_jsx(IconPicker, { ariaLabel: "x", icons: ICONES }));
|
|
49
|
+
expect(radios()[0]).toHaveAttribute("tabindex", "0");
|
|
50
|
+
});
|
|
51
|
+
it("a busca filtra por nome, rótulo e palavras-chave, sem acento nem caixa", async () => {
|
|
52
|
+
const usuario = userEvent.setup();
|
|
53
|
+
render(_jsx(IconPicker, { ariaLabel: "x", icons: ICONES }));
|
|
54
|
+
const campo = screen.getByRole("searchbox", { name: "Buscar ícone" });
|
|
55
|
+
await usuario.type(campo, "PREFEITURA");
|
|
56
|
+
expect(radios()).toHaveLength(1);
|
|
57
|
+
expect(radios()[0]).toHaveAccessibleName("Prédio");
|
|
58
|
+
await usuario.clear(campo);
|
|
59
|
+
await usuario.type(campo, "juridico");
|
|
60
|
+
expect(radios().map((r) => r.getAttribute("aria-label"))).toEqual(["Martelo"]);
|
|
61
|
+
await usuario.clear(campo);
|
|
62
|
+
await usuario.type(campo, "fol");
|
|
63
|
+
expect(radios().map((r) => r.getAttribute("aria-label"))).toEqual(["folder"]);
|
|
64
|
+
});
|
|
65
|
+
it("a quantidade de resultados é anunciada e resultsLabel traduz", async () => {
|
|
66
|
+
const usuario = userEvent.setup();
|
|
67
|
+
render(_jsx(IconPicker, { ariaLabel: "x", icons: ICONES, resultsLabel: "{count} icons" }));
|
|
68
|
+
expect(screen.getByRole("status")).toHaveTextContent("5 icons");
|
|
69
|
+
await usuario.type(screen.getByRole("searchbox"), "user");
|
|
70
|
+
expect(screen.getByRole("status")).toHaveTextContent("1 icons");
|
|
71
|
+
});
|
|
72
|
+
it("sem resultado mostra o texto e some a grade", async () => {
|
|
73
|
+
const usuario = userEvent.setup();
|
|
74
|
+
render(_jsx(IconPicker, { ariaLabel: "x", icons: ICONES, emptyText: "Nada por aqui" }));
|
|
75
|
+
await usuario.type(screen.getByRole("searchbox"), "zzz");
|
|
76
|
+
expect(screen.getByText("Nada por aqui")).toBeInTheDocument();
|
|
77
|
+
expect(screen.queryByRole("radiogroup")).toBeNull();
|
|
78
|
+
});
|
|
79
|
+
it("setas movem a escolha e o foco; cima e baixo andam uma linha (columns)", async () => {
|
|
80
|
+
const usuario = userEvent.setup();
|
|
81
|
+
const aoMudar = vi.fn();
|
|
82
|
+
render(_jsx(IconPicker, { ariaLabel: "x", icons: ICONES, columns: 2, defaultValue: "user", onChange: aoMudar }));
|
|
83
|
+
radios()[0].focus();
|
|
84
|
+
await usuario.keyboard("{ArrowRight}");
|
|
85
|
+
expect(aoMudar).toHaveBeenLastCalledWith("folder", faFolder);
|
|
86
|
+
expect(radios()[1]).toHaveFocus();
|
|
87
|
+
await usuario.keyboard("{ArrowDown}");
|
|
88
|
+
expect(radios()[3]).toHaveFocus();
|
|
89
|
+
await usuario.keyboard("{ArrowUp}");
|
|
90
|
+
expect(radios()[1]).toHaveFocus();
|
|
91
|
+
await usuario.keyboard("{End}");
|
|
92
|
+
expect(radios()[4]).toHaveFocus();
|
|
93
|
+
await usuario.keyboard("{ArrowRight}");
|
|
94
|
+
expect(radios()[0]).toHaveFocus();
|
|
95
|
+
await usuario.keyboard("{ArrowLeft}");
|
|
96
|
+
expect(radios()[4]).toHaveFocus();
|
|
97
|
+
await usuario.keyboard("{Home}");
|
|
98
|
+
expect(radios()[0]).toHaveFocus();
|
|
99
|
+
});
|
|
100
|
+
it("seta para baixo no campo de busca leva à grade", async () => {
|
|
101
|
+
const usuario = userEvent.setup();
|
|
102
|
+
render(_jsx(IconPicker, { ariaLabel: "x", icons: ICONES, defaultValue: "folder" }));
|
|
103
|
+
await usuario.click(screen.getByRole("searchbox"));
|
|
104
|
+
await usuario.keyboard("{ArrowDown}");
|
|
105
|
+
expect(screen.getByRole("radio", { name: "folder" })).toHaveFocus();
|
|
106
|
+
});
|
|
107
|
+
it("hideSearch tira o campo; disabled desabilita tudo", () => {
|
|
108
|
+
const { rerender } = render(_jsx(IconPicker, { ariaLabel: "x", icons: ICONES, hideSearch: true }));
|
|
109
|
+
expect(screen.queryByRole("searchbox")).toBeNull();
|
|
110
|
+
rerender(_jsx(IconPicker, { ariaLabel: "x", icons: ICONES, disabled: true }));
|
|
111
|
+
for (const r of radios())
|
|
112
|
+
expect(r).toBeDisabled();
|
|
113
|
+
});
|
|
114
|
+
it("textos da busca por prop; label visível nomeia o grupo; columns vira o grid", () => {
|
|
115
|
+
const { container } = render(_jsx(IconPicker, { label: "\u00CDcone", id: "ip", icons: ICONES, searchLabel: "Search icon", searchPlaceholder: "Search...", columns: 4, maxHeight: 120 }));
|
|
116
|
+
expect(screen.getByRole("radiogroup", { name: "Ícone" })).toBeInTheDocument();
|
|
117
|
+
expect(screen.getByRole("searchbox", { name: "Search icon" })).toHaveAttribute("placeholder", "Search...");
|
|
118
|
+
const grade = container.querySelector(".umds-icon-picker__grid");
|
|
119
|
+
expect(grade.style.gridTemplateColumns).toBe("repeat(4, var(--umds-icon-picker-tile))");
|
|
120
|
+
expect(grade.style.maxHeight).toBe("120px");
|
|
121
|
+
});
|
|
122
|
+
it("controlado: reflete o value", () => {
|
|
123
|
+
function Pai() {
|
|
124
|
+
const [valor, setValor] = useState("gavel");
|
|
125
|
+
return _jsx(IconPicker, { ariaLabel: "x", icons: ICONES, value: valor, onChange: setValor });
|
|
126
|
+
}
|
|
127
|
+
render(_jsx(Pai, {}));
|
|
128
|
+
expect(screen.getByRole("radio", { name: "Martelo" })).toHaveAttribute("aria-checked", "true");
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import { faMagnifyingGlass } from "@fortawesome/free-solid-svg-icons";
|
|
6
|
+
import Input from "../components/Input/Input";
|
|
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(_jsx(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
|
+
it("change disparado à mão também chega (testes de quem consome)", () => {
|
|
15
|
+
const aoMudar = vi.fn();
|
|
16
|
+
render(_jsx(Input, { label: "Nome", onChange: aoMudar }));
|
|
17
|
+
fireEvent.change(screen.getByLabelText("Nome"), { target: { value: "xyz" } });
|
|
18
|
+
expect(aoMudar).toHaveBeenCalledTimes(1);
|
|
19
|
+
expect(aoMudar).toHaveBeenCalledWith("xyz");
|
|
20
|
+
});
|
|
21
|
+
it("onBlur continua sendo o evento de saída do campo", async () => {
|
|
22
|
+
const aoSair = vi.fn();
|
|
23
|
+
const aoMudar = vi.fn();
|
|
24
|
+
render(_jsx(Input, { label: "Nome", onBlur: aoSair, onChange: aoMudar }));
|
|
25
|
+
const campo = screen.getByLabelText("Nome");
|
|
26
|
+
await userEvent.type(campo, "a");
|
|
27
|
+
expect(aoSair).not.toHaveBeenCalled();
|
|
28
|
+
await userEvent.tab();
|
|
29
|
+
expect(aoSair).toHaveBeenCalledTimes(1);
|
|
30
|
+
expect(aoMudar).toHaveBeenCalledTimes(1);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe("Input · mask", () => {
|
|
34
|
+
async function digitar(mask, texto) {
|
|
35
|
+
const aoMudar = vi.fn();
|
|
36
|
+
render(_jsx(Input, { label: "Campo", mask: mask, onChange: aoMudar }));
|
|
37
|
+
const campo = screen.getByLabelText("Campo");
|
|
38
|
+
await userEvent.type(campo, texto);
|
|
39
|
+
return { campo, aoMudar };
|
|
40
|
+
}
|
|
41
|
+
it("cpf", async () => {
|
|
42
|
+
const { campo, aoMudar } = await digitar("cpf", "12345678901");
|
|
43
|
+
expect(campo.value).toBe("123.456.789-01");
|
|
44
|
+
expect(aoMudar).toHaveBeenLastCalledWith("123.456.789-01");
|
|
45
|
+
});
|
|
46
|
+
it("cnpj", async () => {
|
|
47
|
+
const { campo } = await digitar("cnpj", "12345678000190");
|
|
48
|
+
expect(campo.value).toBe("12.345.678/0001-90");
|
|
49
|
+
});
|
|
50
|
+
it("cep", async () => {
|
|
51
|
+
const { campo } = await digitar("cep", "80010000");
|
|
52
|
+
expect(campo.value).toBe("80010-000");
|
|
53
|
+
});
|
|
54
|
+
it("phone troca de formato com 10 ou 11 dígitos", async () => {
|
|
55
|
+
expect((await digitar("phone", "4133334444")).campo.value).toBe("(41) 3333-4444");
|
|
56
|
+
});
|
|
57
|
+
it("phone de 11 dígitos", async () => {
|
|
58
|
+
expect((await digitar("phone", "41999998888")).campo.value).toBe("(41) 99999-8888");
|
|
59
|
+
});
|
|
60
|
+
it("ignora letras e passa do tamanho, sem estourar", async () => {
|
|
61
|
+
const { campo } = await digitar("cpf", "12a3.4b5-678901999");
|
|
62
|
+
expect(campo.value).toBe("123.456.789-01");
|
|
63
|
+
});
|
|
64
|
+
it("valor controlado com dígitos aparece formatado", () => {
|
|
65
|
+
render(_jsx(Input, { label: "CPF", mask: "cpf", value: "12345678901", onChange: () => { } }));
|
|
66
|
+
expect(screen.getByLabelText("CPF").value).toBe("123.456.789-01");
|
|
67
|
+
});
|
|
68
|
+
it("abre o teclado numérico e limita o tamanho; sem máscara, nenhum dos dois", () => {
|
|
69
|
+
render(_jsxs(_Fragment, { children: [_jsx(Input, { label: "Com", mask: "cep" }), _jsx(Input, { label: "Sem" })] }));
|
|
70
|
+
expect(screen.getByLabelText("Com")).toHaveAttribute("inputmode", "numeric");
|
|
71
|
+
expect(screen.getByLabelText("Com")).toHaveAttribute("maxlength", "9");
|
|
72
|
+
expect(screen.getByLabelText("Sem")).not.toHaveAttribute("inputmode");
|
|
73
|
+
expect(screen.getByLabelText("Sem")).not.toHaveAttribute("maxlength");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe("Input · iconRight e borderless", () => {
|
|
77
|
+
it("iconRight é decorativo: aparece, não é botão e fica fora da árvore de acessibilidade", () => {
|
|
78
|
+
const { container } = render(_jsx(Input, { ariaLabel: "N\u00FAmero", iconRight: faMagnifyingGlass }));
|
|
79
|
+
const icone = container.querySelector(".umds-input__icon-right");
|
|
80
|
+
expect(icone).not.toBeNull();
|
|
81
|
+
expect(icone).toHaveAttribute("aria-hidden", "true");
|
|
82
|
+
expect(icone.querySelector("svg")).not.toBeNull();
|
|
83
|
+
expect(screen.queryByRole("button")).toBeNull();
|
|
84
|
+
});
|
|
85
|
+
it("sem iconRight não há ícone à direita", () => {
|
|
86
|
+
const { container } = render(_jsx(Input, { ariaLabel: "x" }));
|
|
87
|
+
expect(container.querySelector(".umds-input__icon-right")).toBeNull();
|
|
88
|
+
});
|
|
89
|
+
it("borderless escreve a classe; sem a prop não", () => {
|
|
90
|
+
const { container } = render(_jsxs(_Fragment, { children: [_jsx(Input, { ariaLabel: "a", borderless: true }), _jsx(Input, { ariaLabel: "b" })] }));
|
|
91
|
+
expect(container.children[0]).toHaveClass("umds-input--borderless");
|
|
92
|
+
expect(container.children[1]).not.toHaveClass("umds-input--borderless");
|
|
93
|
+
});
|
|
94
|
+
it("borderless com erro continua marcando o erro", () => {
|
|
95
|
+
const { container } = render(_jsx(Input, { ariaLabel: "a", borderless: true, errorMessage: "Obrigat\u00F3rio" }));
|
|
96
|
+
expect(container.firstElementChild).toHaveClass("umds-input--borderless", "umds-input--error");
|
|
97
|
+
expect(screen.getByLabelText("a")).toHaveAttribute("aria-invalid", "true");
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { act, render, screen } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import Kbd from "../components/Kbd/Kbd";
|
|
6
|
+
import CodeBlock from "../components/CodeBlock/CodeBlock";
|
|
7
|
+
describe("Kbd", () => {
|
|
8
|
+
it("uma tecla é um kbd com o texto", () => {
|
|
9
|
+
const { container } = render(_jsx(Kbd, { children: "Esc" }));
|
|
10
|
+
const tecla = container.querySelector("kbd");
|
|
11
|
+
expect(tecla).toHaveTextContent("Esc");
|
|
12
|
+
expect(tecla).toHaveClass("umds-kbd", "umds-kbd--md");
|
|
13
|
+
expect(container.querySelectorAll("kbd")).toHaveLength(1);
|
|
14
|
+
});
|
|
15
|
+
it("keys desenha uma tecla por item, com o separador entre elas", () => {
|
|
16
|
+
const { container } = render(_jsx(Kbd, { keys: ["Ctrl", "Shift", "P"] }));
|
|
17
|
+
const conjunto = container.querySelector("kbd.umds-kbd-combo");
|
|
18
|
+
expect(conjunto).not.toBeNull();
|
|
19
|
+
expect(conjunto.querySelectorAll("kbd.umds-kbd")).toHaveLength(3);
|
|
20
|
+
expect(conjunto.textContent).toBe("Ctrl+Shift+P");
|
|
21
|
+
});
|
|
22
|
+
it("separator troca o texto entre as teclas; size vira classe", () => {
|
|
23
|
+
const { container } = render(_jsx(Kbd, { keys: ["Ctrl", "K"], separator: " + ", size: "sm" }));
|
|
24
|
+
expect(container.querySelector("kbd")).toHaveClass("umds-kbd--sm");
|
|
25
|
+
expect(container.textContent).toBe("Ctrl + K");
|
|
26
|
+
});
|
|
27
|
+
it("atributos HTML vão para o kbd", () => {
|
|
28
|
+
const { container } = render(_jsx(Kbd, { title: "Atalho", "data-x": "1", children: "Tab" }));
|
|
29
|
+
const tecla = container.querySelector("kbd");
|
|
30
|
+
expect(tecla).toHaveAttribute("title", "Atalho");
|
|
31
|
+
expect(tecla).toHaveAttribute("data-x", "1");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe("CodeBlock", () => {
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
vi.useRealTimers();
|
|
37
|
+
vi.restoreAllMocks();
|
|
38
|
+
});
|
|
39
|
+
it("mostra o código em pre/code, mantendo as quebras, numa região focável e nomeada", () => {
|
|
40
|
+
const { container } = render(_jsx(CodeBlock, { code: '{\n "ok": true\n}', ariaLabel: "Resposta" }));
|
|
41
|
+
const regiao = screen.getByRole("region", { name: "Resposta" });
|
|
42
|
+
expect(regiao.tagName).toBe("PRE");
|
|
43
|
+
expect(regiao).toHaveAttribute("tabindex", "0");
|
|
44
|
+
expect(container.querySelector("code")?.textContent).toBe('{\n "ok": true\n}');
|
|
45
|
+
});
|
|
46
|
+
it("o texto também vem como conteúdo; o nome padrão é a linguagem, ou Código", () => {
|
|
47
|
+
const { rerender } = render(_jsx(CodeBlock, { language: "JSON", children: "{}" }));
|
|
48
|
+
expect(screen.getByRole("region", { name: "JSON" })).toHaveTextContent("{}");
|
|
49
|
+
expect(screen.getByText("JSON", { selector: ".umds-code-block__language" })).toBeInTheDocument();
|
|
50
|
+
rerender(_jsx(CodeBlock, { code: "x" }));
|
|
51
|
+
expect(screen.getByRole("region", { name: "Código" })).toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
it("wrap e maxHeight", () => {
|
|
54
|
+
const { container } = render(_jsx(CodeBlock, { code: "linha longa", wrap: true, maxHeight: 120 }));
|
|
55
|
+
expect(container.querySelector(".umds-code-block--wrap")).not.toBeNull();
|
|
56
|
+
expect(container.querySelector("pre").style.maxHeight).toBe("120px");
|
|
57
|
+
});
|
|
58
|
+
it("sem copyable e sem linguagem, não há cabeçalho nem botão", () => {
|
|
59
|
+
render(_jsx(CodeBlock, { code: "x" }));
|
|
60
|
+
expect(screen.queryByRole("button")).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
it("copiar manda o texto inteiro à área de transferência, confirma e volta depois de 2 s", async () => {
|
|
63
|
+
vi.useFakeTimers({ shouldAdvanceTime: true });
|
|
64
|
+
const escrever = vi.fn(() => Promise.resolve());
|
|
65
|
+
const aoCopiar = vi.fn();
|
|
66
|
+
const usuario = userEvent.setup({ advanceTimers: vi.advanceTimersByTime });
|
|
67
|
+
// O userEvent.setup instala a própria área de transferência: o espião entra depois.
|
|
68
|
+
Object.defineProperty(navigator, "clipboard", { value: { writeText: escrever }, configurable: true });
|
|
69
|
+
render(_jsx(CodeBlock, { code: '{"a":1}', copyable: true, onCopy: aoCopiar }));
|
|
70
|
+
await usuario.click(screen.getByRole("button", { name: "Copiar" }));
|
|
71
|
+
expect(escrever).toHaveBeenCalledWith('{"a":1}');
|
|
72
|
+
expect(await screen.findByRole("button", { name: "Copiado" })).toBeInTheDocument();
|
|
73
|
+
expect(aoCopiar).toHaveBeenCalledWith('{"a":1}');
|
|
74
|
+
expect(screen.getByRole("status")).toHaveTextContent("Copiado");
|
|
75
|
+
await act(async () => {
|
|
76
|
+
vi.advanceTimersByTime(2100);
|
|
77
|
+
});
|
|
78
|
+
expect(screen.getByRole("button", { name: "Copiar" })).toBeInTheDocument();
|
|
79
|
+
});
|
|
80
|
+
it("copiar com o texto vindo como conteúdo lê o texto do bloco", async () => {
|
|
81
|
+
const escrever = vi.fn(() => Promise.resolve());
|
|
82
|
+
const usuario = userEvent.setup();
|
|
83
|
+
Object.defineProperty(navigator, "clipboard", { value: { writeText: escrever }, configurable: true });
|
|
84
|
+
render(_jsx(CodeBlock, { copyable: true, children: "npm run build" }));
|
|
85
|
+
await usuario.click(screen.getByRole("button", { name: "Copiar" }));
|
|
86
|
+
expect(escrever).toHaveBeenCalledWith("npm run build");
|
|
87
|
+
});
|
|
88
|
+
it("copyLabel e copiedLabel por prop", async () => {
|
|
89
|
+
const usuario = userEvent.setup();
|
|
90
|
+
Object.defineProperty(navigator, "clipboard", { value: { writeText: () => Promise.resolve() }, configurable: true });
|
|
91
|
+
render(_jsx(CodeBlock, { code: "x", copyable: true, copyLabel: "Copy", copiedLabel: "Copied" }));
|
|
92
|
+
await usuario.click(screen.getByRole("button", { name: "Copy" }));
|
|
93
|
+
expect(await screen.findByRole("button", { name: "Copied" })).toBeInTheDocument();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|