@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,329 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
import RichTextEditor from "../components/RichTextEditor/RichTextEditor";
|
|
6
|
+
import { enderecoSeguro, normalizarEndereco, sanitizarHtml } from "../utils/html-seguro";
|
|
7
|
+
|
|
8
|
+
/** jsdom não traz `execCommand`: o teste fala com um espião e confere o que o editor pede ao navegador. */
|
|
9
|
+
let execCommand: ReturnType<typeof vi.fn>;
|
|
10
|
+
let estados: Record<string, boolean>;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
estados = {};
|
|
14
|
+
execCommand = vi.fn(() => true);
|
|
15
|
+
(document as any).execCommand = execCommand;
|
|
16
|
+
(document as any).queryCommandState = (comando: string) => !!estados[comando];
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const area = () => screen.getByRole("textbox") as HTMLElement;
|
|
20
|
+
|
|
21
|
+
/** Escreve na área como o navegador faz: muda o conteúdo e dispara `input`. */
|
|
22
|
+
const escrever = (html: string) => {
|
|
23
|
+
area().innerHTML = html;
|
|
24
|
+
fireEvent.input(area());
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const selecionarTudoNaArea = () => {
|
|
28
|
+
const selecao = window.getSelection() as Selection;
|
|
29
|
+
const faixa = document.createRange();
|
|
30
|
+
faixa.selectNodeContents(area());
|
|
31
|
+
selecao.removeAllRanges();
|
|
32
|
+
selecao.addRange(faixa);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
describe("RichTextEditor: estrutura e nomes", () => {
|
|
36
|
+
it("a barra é um toolbar nomeado com as ferramentas padrão", () => {
|
|
37
|
+
render(<RichTextEditor ariaLabel="Despacho" />);
|
|
38
|
+
const barra = screen.getByRole("toolbar", { name: "Formatação" });
|
|
39
|
+
for (const nome of ["Negrito", "Itálico", "Sublinhado", "Lista com marcadores", "Lista numerada", "Link", "Desfazer", "Refazer"]) {
|
|
40
|
+
expect(screen.getByRole("button", { name: nome })).toBeInTheDocument();
|
|
41
|
+
}
|
|
42
|
+
expect(barra.querySelectorAll('[role="separator"]')).toHaveLength(3);
|
|
43
|
+
expect(screen.queryByRole("button", { name: "Tachado" })).toBeNull();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("a área de escrita é um textbox multilinha com nome e placeholder", () => {
|
|
47
|
+
render(<RichTextEditor ariaLabel="Despacho" placeholder="Escreva o despacho..." />);
|
|
48
|
+
const caixa = screen.getByRole("textbox", { name: "Despacho" });
|
|
49
|
+
expect(caixa).toHaveAttribute("aria-multiline", "true");
|
|
50
|
+
expect(caixa).toHaveAttribute("contenteditable", "true");
|
|
51
|
+
expect(caixa).toHaveAttribute("data-placeholder", "Escreva o despacho...");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("label visível nomeia a área", () => {
|
|
55
|
+
render(<RichTextEditor label="Descrição" id="rte" />);
|
|
56
|
+
expect(screen.getByRole("textbox", { name: "Descrição" })).toBeInTheDocument();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("toolbar escolhe as ferramentas e os separadores", () => {
|
|
60
|
+
render(<RichTextEditor ariaLabel="x" toolbar={["bold", "|", "strike", "clear"]} />);
|
|
61
|
+
expect(screen.getAllByRole("button").map((b) => b.getAttribute("aria-label"))).toEqual(["Negrito", "Tachado", "Limpar formatação"]);
|
|
62
|
+
expect(screen.getByRole("toolbar").querySelectorAll('[role="separator"]')).toHaveLength(1);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("labels e toolbarLabel traduzem a barra", () => {
|
|
66
|
+
render(<RichTextEditor ariaLabel="x" toolbarLabel="Formatting" toolbar={["bold", "link"]} labels={{ bold: "Bold", link: "Link (Ctrl+K)" }} />);
|
|
67
|
+
expect(screen.getByRole("toolbar", { name: "Formatting" })).toBeInTheDocument();
|
|
68
|
+
expect(screen.getByRole("button", { name: "Bold" })).toBeInTheDocument();
|
|
69
|
+
expect(screen.getByRole("button", { name: "Link (Ctrl+K)" })).toBeInTheDocument();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("errorMessage e helperText ligam a área por aria-describedby", () => {
|
|
73
|
+
render(<RichTextEditor ariaLabel="x" id="r" errorMessage="Escreva o despacho" helperText="Obrigatório" />);
|
|
74
|
+
expect(area()).toHaveAttribute("aria-invalid", "true");
|
|
75
|
+
expect(area().getAttribute("aria-describedby")).toBe("r-error r-helper");
|
|
76
|
+
expect(screen.getByText("Escreva o despacho")).toBeInTheDocument();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("minHeight e resizable", () => {
|
|
80
|
+
const { container } = render(<RichTextEditor ariaLabel="x" minHeight={200} resizable />);
|
|
81
|
+
expect(area().style.minHeight).toBe("200px");
|
|
82
|
+
expect(container.querySelector(".umds-rte--resizable")).not.toBeNull();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("o slot footer aparece dentro da moldura", () => {
|
|
86
|
+
render(<RichTextEditor ariaLabel="x" footer={<span data-testid="assinatura">Ana Paula Souza</span>} />);
|
|
87
|
+
expect(screen.getByTestId("assinatura").closest(".umds-rte__footer")).not.toBeNull();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe("RichTextEditor: valor e higienização", () => {
|
|
92
|
+
it("defaultValue entra na área", () => {
|
|
93
|
+
render(<RichTextEditor ariaLabel="x" defaultValue="<p>Olá <b>mundo</b></p>" />);
|
|
94
|
+
expect(area().innerHTML).toBe("<p>Olá <b>mundo</b></p>");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("o HTML que entra é higienizado: sem script, onerror, style nem javascript:", () => {
|
|
98
|
+
render(
|
|
99
|
+
<RichTextEditor
|
|
100
|
+
ariaLabel="x"
|
|
101
|
+
defaultValue={'<p style="color:red" class="x" onclick="a()">ok</p><script>alert(1)</script><img src=x onerror="alert(1)"><a href="javascript:alert(1)">mau</a><a href="https://1doc.com.br">bom</a>'}
|
|
102
|
+
/>,
|
|
103
|
+
);
|
|
104
|
+
const html = area().innerHTML;
|
|
105
|
+
expect(html).not.toMatch(/script|onerror|onclick|style=|class=|javascript:|<img/i);
|
|
106
|
+
expect(html).toContain('<a href="https://1doc.com.br" rel="noopener noreferrer">bom</a>');
|
|
107
|
+
expect(html).toContain("<p>ok</p>");
|
|
108
|
+
expect(html).toContain("mau");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("digitar entrega o HTML em onChange; apagar tudo entrega vazio", () => {
|
|
112
|
+
const aoMudar = vi.fn();
|
|
113
|
+
render(<RichTextEditor ariaLabel="x" onChange={aoMudar} />);
|
|
114
|
+
escrever("<b>Oi</b>");
|
|
115
|
+
expect(aoMudar).toHaveBeenLastCalledWith("<b>Oi</b>");
|
|
116
|
+
escrever("<br>");
|
|
117
|
+
expect(aoMudar).toHaveBeenLastCalledWith("");
|
|
118
|
+
expect(area().innerHTML).toBe("");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("colar entra como texto puro (insertText) e não deixa o HTML colado passar", () => {
|
|
122
|
+
render(<RichTextEditor ariaLabel="x" />);
|
|
123
|
+
const evento = new Event("paste", { bubbles: true, cancelable: true });
|
|
124
|
+
Object.defineProperty(evento, "clipboardData", { value: { getData: (tipo: string) => (tipo === "text/plain" ? "texto puro" : "<b>html</b>") } });
|
|
125
|
+
area().dispatchEvent(evento);
|
|
126
|
+
expect(evento.defaultPrevented).toBe(true);
|
|
127
|
+
expect(execCommand).toHaveBeenCalledWith("insertText", false, "texto puro");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("controlado: um value novo de fora reescreve; o mesmo que o editor emitiu não", () => {
|
|
131
|
+
function Pai() {
|
|
132
|
+
const [html, setHtml] = useState("<p>um</p>");
|
|
133
|
+
return (
|
|
134
|
+
<>
|
|
135
|
+
<RichTextEditor ariaLabel="x" value={html} onChange={setHtml} />
|
|
136
|
+
<button onClick={() => setHtml("<p>dois</p>")}>trocar</button>
|
|
137
|
+
</>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
render(<Pai />);
|
|
141
|
+
expect(area().innerHTML).toBe("<p>um</p>");
|
|
142
|
+
escrever("<p>um mais</p>");
|
|
143
|
+
expect(area().innerHTML).toBe("<p>um mais</p>");
|
|
144
|
+
fireEvent.click(screen.getByText("trocar"));
|
|
145
|
+
expect(area().innerHTML).toBe("<p>dois</p>");
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("RichTextEditor: ferramentas", () => {
|
|
150
|
+
it("clicar em Negrito pede o comando ao navegador e avisa onChange", async () => {
|
|
151
|
+
const usuario = userEvent.setup();
|
|
152
|
+
const aoMudar = vi.fn();
|
|
153
|
+
render(<RichTextEditor ariaLabel="x" onChange={aoMudar} defaultValue="<p>x</p>" />);
|
|
154
|
+
await usuario.click(screen.getByRole("button", { name: "Negrito" }));
|
|
155
|
+
expect(execCommand).toHaveBeenCalledWith("bold", false, undefined);
|
|
156
|
+
expect(aoMudar).toHaveBeenCalled();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("cada ferramenta pede o seu comando", async () => {
|
|
160
|
+
const usuario = userEvent.setup();
|
|
161
|
+
render(<RichTextEditor ariaLabel="x" toolbar={["bold", "italic", "underline", "strike", "ul", "ol", "undo", "redo", "clear"]} />);
|
|
162
|
+
const esperado: Record<string, string> = {
|
|
163
|
+
Negrito: "bold",
|
|
164
|
+
Itálico: "italic",
|
|
165
|
+
Sublinhado: "underline",
|
|
166
|
+
Tachado: "strikeThrough",
|
|
167
|
+
"Lista com marcadores": "insertUnorderedList",
|
|
168
|
+
"Lista numerada": "insertOrderedList",
|
|
169
|
+
Desfazer: "undo",
|
|
170
|
+
Refazer: "redo",
|
|
171
|
+
"Limpar formatação": "removeFormat",
|
|
172
|
+
};
|
|
173
|
+
for (const [nome, comando] of Object.entries(esperado)) {
|
|
174
|
+
execCommand.mockClear();
|
|
175
|
+
await usuario.click(screen.getByRole("button", { name: nome }));
|
|
176
|
+
expect(execCommand).toHaveBeenCalledWith(comando, false, undefined);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("o clique na barra não rouba o foco da área (mousedown é impedido)", () => {
|
|
181
|
+
render(<RichTextEditor ariaLabel="x" />);
|
|
182
|
+
const evento = new MouseEvent("mousedown", { bubbles: true, cancelable: true });
|
|
183
|
+
screen.getByRole("button", { name: "Negrito" }).dispatchEvent(evento);
|
|
184
|
+
expect(evento.defaultPrevented).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("os botões de liga/desliga seguem o cursor (aria-pressed)", () => {
|
|
188
|
+
render(<RichTextEditor ariaLabel="x" defaultValue="<p>x</p>" />);
|
|
189
|
+
const negrito = screen.getByRole("button", { name: "Negrito" });
|
|
190
|
+
expect(negrito).toHaveAttribute("aria-pressed", "false");
|
|
191
|
+
estados.bold = true;
|
|
192
|
+
selecionarTudoNaArea();
|
|
193
|
+
fireEvent(document, new Event("selectionchange"));
|
|
194
|
+
expect(negrito).toHaveAttribute("aria-pressed", "true");
|
|
195
|
+
expect(negrito).toHaveClass("umds-rte__tool--active");
|
|
196
|
+
expect(screen.getByRole("button", { name: "Itálico" })).toHaveAttribute("aria-pressed", "false");
|
|
197
|
+
expect(screen.getByRole("button", { name: "Link" })).not.toHaveAttribute("aria-pressed");
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("Tab entra numa parada só; setas, Home e End movem entre as ferramentas", async () => {
|
|
201
|
+
const usuario = userEvent.setup();
|
|
202
|
+
render(<RichTextEditor ariaLabel="x" toolbar={["bold", "italic", "underline"]} />);
|
|
203
|
+
const botoes = screen.getAllByRole("button");
|
|
204
|
+
expect(botoes.map((b) => b.getAttribute("tabindex"))).toEqual(["0", "-1", "-1"]);
|
|
205
|
+
botoes[0].focus();
|
|
206
|
+
await usuario.keyboard("{ArrowRight}");
|
|
207
|
+
expect(botoes[1]).toHaveFocus();
|
|
208
|
+
await usuario.keyboard("{End}");
|
|
209
|
+
expect(botoes[2]).toHaveFocus();
|
|
210
|
+
await usuario.keyboard("{ArrowRight}");
|
|
211
|
+
expect(botoes[0]).toHaveFocus();
|
|
212
|
+
await usuario.keyboard("{ArrowLeft}");
|
|
213
|
+
expect(botoes[2]).toHaveFocus();
|
|
214
|
+
await usuario.keyboard("{Home}");
|
|
215
|
+
expect(botoes[0]).toHaveFocus();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("readOnly: sem barra e a área não edita; disabled: botões desabilitados", () => {
|
|
219
|
+
const { rerender } = render(<RichTextEditor ariaLabel="x" readOnly defaultValue="<p>x</p>" />);
|
|
220
|
+
expect(screen.queryByRole("toolbar")).toBeNull();
|
|
221
|
+
expect(area()).toHaveAttribute("contenteditable", "false");
|
|
222
|
+
rerender(<RichTextEditor ariaLabel="x" disabled />);
|
|
223
|
+
for (const b of screen.getAllByRole("button")) expect(b).toBeDisabled();
|
|
224
|
+
expect(area()).toHaveAttribute("tabindex", "-1");
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe("RichTextEditor: link", () => {
|
|
229
|
+
it("o botão Link abre o campo, com foco nele; Esc fecha", async () => {
|
|
230
|
+
const usuario = userEvent.setup();
|
|
231
|
+
render(<RichTextEditor ariaLabel="x" defaultValue="<p>texto</p>" />);
|
|
232
|
+
await usuario.click(screen.getByRole("button", { name: "Link" }));
|
|
233
|
+
const campo = screen.getByLabelText("Endereço do link");
|
|
234
|
+
expect(campo).toHaveFocus();
|
|
235
|
+
await usuario.keyboard("{Escape}");
|
|
236
|
+
expect(screen.queryByLabelText("Endereço do link")).toBeNull();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("Ctrl+K abre o campo de link", () => {
|
|
240
|
+
render(<RichTextEditor ariaLabel="x" />);
|
|
241
|
+
fireEvent.keyDown(area(), { key: "k", ctrlKey: true });
|
|
242
|
+
expect(screen.getByLabelText("Endereço do link")).toBeInTheDocument();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("com texto escolhido, aplicar cria o link; endereço sem esquema ganha https://", async () => {
|
|
246
|
+
const usuario = userEvent.setup();
|
|
247
|
+
render(<RichTextEditor ariaLabel="x" defaultValue="<p>texto</p>" />);
|
|
248
|
+
selecionarTudoNaArea();
|
|
249
|
+
await usuario.click(screen.getByRole("button", { name: "Link" }));
|
|
250
|
+
await usuario.type(screen.getByLabelText("Endereço do link"), "exemplo.com.br");
|
|
251
|
+
await usuario.click(screen.getByRole("button", { name: "Aplicar" }));
|
|
252
|
+
expect(execCommand).toHaveBeenCalledWith("createLink", false, "https://exemplo.com.br");
|
|
253
|
+
expect(screen.queryByLabelText("Endereço do link")).toBeNull();
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("sem texto escolhido, o endereço vira o texto do link", async () => {
|
|
257
|
+
const usuario = userEvent.setup();
|
|
258
|
+
render(<RichTextEditor ariaLabel="x" defaultValue="<p>texto</p>" />);
|
|
259
|
+
const selecao = window.getSelection() as Selection;
|
|
260
|
+
const faixa = document.createRange();
|
|
261
|
+
faixa.setStart(area().querySelector("p")!.firstChild!, 2);
|
|
262
|
+
faixa.collapse(true);
|
|
263
|
+
selecao.removeAllRanges();
|
|
264
|
+
selecao.addRange(faixa);
|
|
265
|
+
await usuario.click(screen.getByRole("button", { name: "Link" }));
|
|
266
|
+
await usuario.type(screen.getByLabelText("Endereço do link"), "https://1doc.com.br{Enter}");
|
|
267
|
+
expect(execCommand).toHaveBeenCalledWith("insertHTML", false, '<a href="https://1doc.com.br">https://1doc.com.br</a>');
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("endereço perigoso não vira link: mostra o erro e continua aberto", async () => {
|
|
271
|
+
const usuario = userEvent.setup();
|
|
272
|
+
render(<RichTextEditor ariaLabel="x" defaultValue="<p>texto</p>" />);
|
|
273
|
+
selecionarTudoNaArea();
|
|
274
|
+
await usuario.click(screen.getByRole("button", { name: "Link" }));
|
|
275
|
+
await usuario.type(screen.getByLabelText("Endereço do link"), "javascript:alert(1)");
|
|
276
|
+
await usuario.click(screen.getByRole("button", { name: "Aplicar" }));
|
|
277
|
+
expect(execCommand).not.toHaveBeenCalledWith("createLink", expect.anything(), expect.anything());
|
|
278
|
+
expect(screen.getByText("Use um endereço http, https, mailto ou tel.")).toBeInTheDocument();
|
|
279
|
+
expect(screen.getByLabelText("Endereço do link")).toBeInTheDocument();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("em cima de um link existente, o campo vem preenchido e Remover link aparece", async () => {
|
|
283
|
+
const usuario = userEvent.setup();
|
|
284
|
+
render(<RichTextEditor ariaLabel="x" defaultValue='<p><a href="https://1doc.com.br">site</a></p>' />);
|
|
285
|
+
const selecao = window.getSelection() as Selection;
|
|
286
|
+
const faixa = document.createRange();
|
|
287
|
+
faixa.setStart(area().querySelector("a")!.firstChild!, 1);
|
|
288
|
+
faixa.collapse(true);
|
|
289
|
+
selecao.removeAllRanges();
|
|
290
|
+
selecao.addRange(faixa);
|
|
291
|
+
await usuario.click(screen.getByRole("button", { name: "Link" }));
|
|
292
|
+
expect(screen.getByLabelText("Endereço do link")).toHaveValue("https://1doc.com.br");
|
|
293
|
+
await usuario.click(screen.getByRole("button", { name: "Remover link" }));
|
|
294
|
+
expect(execCommand).toHaveBeenCalledWith("unlink", false, undefined);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("os textos do campo de link vêm por labels", async () => {
|
|
298
|
+
const usuario = userEvent.setup();
|
|
299
|
+
render(<RichTextEditor ariaLabel="x" labels={{ linkAddress: "Link address", linkApply: "Apply", linkCancel: "Cancel" }} />);
|
|
300
|
+
await usuario.click(screen.getByRole("button", { name: "Link" }));
|
|
301
|
+
expect(screen.getByLabelText("Link address")).toBeInTheDocument();
|
|
302
|
+
expect(screen.getByRole("button", { name: "Apply" })).toBeInTheDocument();
|
|
303
|
+
expect(screen.getByRole("button", { name: "Cancel" })).toBeInTheDocument();
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
describe("html-seguro", () => {
|
|
308
|
+
it("enderecoSeguro aceita http, https, mailto, tel, caminho e âncora; recusa o resto", () => {
|
|
309
|
+
for (const ok of ["https://a.com", "http://a.com", "mailto:a@b.com", "tel:+5584999999999", "/x", "./x", "../x", "#topo"]) {
|
|
310
|
+
expect(enderecoSeguro(ok)).toBe(ok);
|
|
311
|
+
}
|
|
312
|
+
for (const mau of ["javascript:alert(1)", "JaVaScRiPt:alert(1)", "java\nscript:alert(1)", "data:text/html,x", "vbscript:x", "exemplo.com"]) {
|
|
313
|
+
expect(enderecoSeguro(mau)).toBe("");
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("normalizarEndereco põe https:// no que não tem esquema e recusa o perigoso", () => {
|
|
318
|
+
expect(normalizarEndereco("exemplo.com.br")).toBe("https://exemplo.com.br");
|
|
319
|
+
expect(normalizarEndereco(" https://a.com ")).toBe("https://a.com");
|
|
320
|
+
expect(normalizarEndereco("javascript:alert(1)")).toBe("");
|
|
321
|
+
expect(normalizarEndereco("java\tscript:alert(1)")).toBe("");
|
|
322
|
+
expect(normalizarEndereco("")).toBe("");
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("sanitizarHtml tira tags desconhecidas mantendo o conteúdo e descarta as perigosas inteiras", () => {
|
|
326
|
+
expect(sanitizarHtml("<font color=red>a</font><iframe src=x>b</iframe><style>p{}</style>c")).toBe("ac");
|
|
327
|
+
expect(sanitizarHtml("<ul><li>um</li><li><b>dois</b></li></ul>")).toBe("<ul><li>um</li><li><b>dois</b></li></ul>");
|
|
328
|
+
});
|
|
329
|
+
});
|