@1doc/1ds-vue 2.8.0 → 2.10.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +1549 -0
  2. package/dist/index.css +1 -1
  3. package/dist/index.d.ts +1128 -29
  4. package/dist/index.mjs +12299 -7939
  5. package/dist/index.umd.js +4 -4
  6. package/package.json +5 -4
  7. package/src/index.ts +26 -0
  8. package/src/teste/accordion-conteudo-livre.test.mjs +44 -0
  9. package/src/teste/accordion-titulo-neutro.test.mjs +32 -0
  10. package/src/teste/appsubheader-regiao.test.mjs +18 -0
  11. package/src/teste/atributos.test.mjs +91 -0
  12. package/src/teste/attachmentcard-ia.test.mjs +48 -0
  13. package/src/teste/attachmentcard-lista.test.mjs +39 -0
  14. package/src/teste/attachmentcard-sm.test.mjs +28 -0
  15. package/src/teste/avatargroup-overlap.test.mjs +45 -0
  16. package/src/teste/badge-neutro-colado.test.mjs +30 -0
  17. package/src/teste/badge-tag.test.mjs +53 -0
  18. package/src/teste/box-item-flex.test.mjs +84 -0
  19. package/src/teste/box-layout.test.mjs +57 -0
  20. package/src/teste/button.test.mjs +34 -0
  21. package/src/teste/calendar-slots-cabecalho.test.mjs +46 -0
  22. package/src/teste/calendar.test.mjs +179 -0
  23. package/src/teste/chips-xs.test.mjs +33 -0
  24. package/src/teste/coachmark-sem-veu.test.mjs +70 -0
  25. package/src/teste/coachmark.test.mjs +119 -0
  26. package/src/teste/color-picker-xs.test.mjs +28 -0
  27. package/src/teste/color-picker.test.mjs +79 -0
  28. package/src/teste/datatable-arvore-variantes.test.mjs +194 -0
  29. package/src/teste/datatable-documento.test.mjs +106 -0
  30. package/src/teste/datatable-slots.test.mjs +105 -0
  31. package/src/teste/descriptionlist-compacta.test.mjs +32 -0
  32. package/src/teste/dom.mjs +170 -0
  33. package/src/teste/empty-state-titulo-rico.test.mjs +39 -0
  34. package/src/teste/fileinput-trigger.test.mjs +36 -0
  35. package/src/teste/icon-picker.test.mjs +98 -0
  36. package/src/teste/input-agrupado.test.mjs +44 -0
  37. package/src/teste/input-mascara-afins.test.mjs +64 -0
  38. package/src/teste/kbd-code-block.test.mjs +76 -0
  39. package/src/teste/list-item-standalone.test.mjs +75 -0
  40. package/src/teste/list.test.mjs +163 -0
  41. package/src/teste/modal-variantes.test.mjs +79 -0
  42. package/src/teste/org-chart.test.mjs +131 -0
  43. package/src/teste/otp-input.test.mjs +130 -0
  44. package/src/teste/popover-maxheight.test.mjs +26 -0
  45. package/src/teste/renderizar.mjs +64 -0
  46. package/src/teste/rich-text-editor-alinha-imagem-tabela.test.mjs +164 -0
  47. package/src/teste/rich-text-editor-estilo-de-texto.test.mjs +87 -0
  48. package/src/teste/rich-text-editor.test.mjs +210 -0
  49. package/src/teste/segmented-contador.test.mjs +39 -0
  50. package/src/teste/select-aberto-controlado-flutuante.test.mjs +120 -0
  51. package/src/teste/select-filtro-cor-tamanho.test.mjs +62 -0
  52. package/src/teste/select-placement-filtro.test.mjs +49 -0
  53. package/src/teste/stack-box-raiz-unica.test.mjs +134 -0
  54. package/src/teste/stack.test.mjs +80 -0
  55. package/src/teste/statcard-rotulo-topo.test.mjs +34 -0
  56. package/src/teste/statcard-secundaria-tom.test.mjs +41 -0
  57. package/src/teste/tabs-contador-fechavel.test.mjs +60 -0
  58. package/src/teste/toast-acao-detalhes.test.mjs +48 -0
  59. package/src/teste/tooltip-dark.test.mjs +28 -0
  60. package/src/utils/calendario.ts +78 -0
  61. package/src/utils/html-seguro.ts +197 -0
  62. package/src/utils/paleta-de-cores.ts +34 -0
  63. package/src/utils/texto.ts +5 -0
  64. package/src/utils/toast.ts +12 -2
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Monta um componente Vue GERADO num DOM de verdade (jsdom), para o que o
3
+ * `renderizar.mjs` (SSR) não alcança: ouvinte, foco, teclado, `ref`.
4
+ *
5
+ * Por que existe: o HTML do servidor não leva ouvinte nenhum (`@click` some) e
6
+ * não tem `ref`. Um componente que descarta `@click` em silêncio passa em todo
7
+ * teste de SSR. Aqui o componente roda no cliente, e o teste dispara o evento.
8
+ *
9
+ * Como, sem dependência nova: o Node 25 já corta tipos de `.ts`; um gancho de
10
+ * módulo compila `.vue` com o `vue/compiler-sfc` (que o `vue` já traz) e o
11
+ * `typescript` do pacote, deixa vazio o `import "./X.css"` e completa a extensão
12
+ * dos imports sem ela. O jsdom vem do pacote `react`, que já o usa nos
13
+ * próprios testes.
14
+ *
15
+ * Importe este módulo ANTES de qualquer `import "vue"`: o Vue lê o `document`
16
+ * global na hora em que carrega. Por isso o teste que o usa não importa o
17
+ * `renderizar.mjs` (que traz o Vue do servidor).
18
+ */
19
+ import { registerHooks, createRequire } from "node:module";
20
+ import { existsSync, readFileSync } from "node:fs";
21
+ import { dirname, resolve } from "node:path";
22
+ import { fileURLToPath, pathToFileURL } from "node:url";
23
+ import { parse, compileScript } from "vue/compiler-sfc";
24
+
25
+ const aqui = dirname(fileURLToPath(import.meta.url));
26
+ const raiz = resolve(aqui, "../..");
27
+
28
+ const requerDoReact = createRequire(resolve(raiz, "../react/package.json"));
29
+ const ts = createRequire(resolve(raiz, "package.json"))("typescript");
30
+ const { JSDOM } = requerDoReact("jsdom");
31
+
32
+ const dom = new JSDOM("<!doctype html><html><body></body></html>", {
33
+ pretendToBeVisual: true,
34
+ url: "http://localhost/",
35
+ });
36
+ const janela = dom.window;
37
+ for (const nome of [
38
+ "window",
39
+ "document",
40
+ "HTMLElement",
41
+ "HTMLInputElement",
42
+ "SVGElement",
43
+ "DocumentFragment",
44
+ "ShadowRoot",
45
+ "Text",
46
+ "Comment",
47
+ "Element",
48
+ "Node",
49
+ "Event",
50
+ "KeyboardEvent",
51
+ "MouseEvent",
52
+ "ClipboardEvent",
53
+ "DataTransfer",
54
+ "FileReader",
55
+ "File",
56
+ "InputEvent",
57
+ "FocusEvent",
58
+ "CustomEvent",
59
+ "MutationObserver",
60
+ "getComputedStyle",
61
+ "requestAnimationFrame",
62
+ "cancelAnimationFrame",
63
+ ]) {
64
+ if (nome in janela) {
65
+ Object.defineProperty(globalThis, nome, { value: janela[nome], configurable: true, writable: true });
66
+ }
67
+ }
68
+ // jsdom não traz ResizeObserver nem IntersectionObserver; os componentes só os usam se existirem.
69
+
70
+ registerHooks({
71
+ resolve(especificador, contexto, proximo) {
72
+ const relativo = /^\.{1,2}\//.test(especificador);
73
+ const ultimo = especificador.split("/").pop() || "";
74
+ if (relativo && !/\.[a-z0-9]+$/i.test(ultimo) && contexto.parentURL) {
75
+ const base = resolve(dirname(fileURLToPath(contexto.parentURL)), especificador);
76
+ for (const ext of [".ts", ".vue"]) {
77
+ if (existsSync(base + ext)) {
78
+ return { url: pathToFileURL(base + ext).href, shortCircuit: true };
79
+ }
80
+ }
81
+ }
82
+ return proximo(especificador, contexto);
83
+ },
84
+ load(url, contexto, proximo) {
85
+ if (url.endsWith(".css")) {
86
+ return { format: "module", source: "", shortCircuit: true };
87
+ }
88
+ if (url.endsWith(".vue")) {
89
+ const arquivo = fileURLToPath(url);
90
+ const { descriptor } = parse(readFileSync(arquivo, "utf8"), { filename: arquivo });
91
+ const script = compileScript(descriptor, { id: url, inlineTemplate: true });
92
+ // transpileModule (e não só apagar tipos): ele descarta os `import { Tipo }`
93
+ // que só servem a tipos, como o esbuild do Vite faz no build.
94
+ const js = ts.transpileModule(script.content, {
95
+ compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext },
96
+ }).outputText;
97
+ return { format: "module", source: js, shortCircuit: true };
98
+ }
99
+ return proximo(url, contexto);
100
+ },
101
+ });
102
+
103
+ export const documento = janela.document;
104
+ export { janela };
105
+
106
+ /**
107
+ * Monta `caminho` (dentro de `src/components`, ex. `Stack/Stack.vue`) num nó
108
+ * novo do `body`. `props` pode ser uma função (lida a cada render, para o teste
109
+ * mudar um `ref` e ver o componente reagir). Devolve `{ raiz, app, instancia, desmontar }`.
110
+ * `raiz` é o nó onde o app foi montado (o componente é o primeiro filho).
111
+ */
112
+ export async function montar(caminho, props = {}, slots = {}) {
113
+ const { createApp, h } = await import("vue");
114
+ const modulo = await import(pathToFileURL(resolve(raiz, "src/components", caminho)).href);
115
+ const Componente = modulo.default;
116
+ const alvo = documento.createElement("div");
117
+ documento.body.append(alvo);
118
+ let instancia;
119
+ const app = createApp({
120
+ render: () =>
121
+ h(Componente, { ...(typeof props === "function" ? props() : props), ref: (valor) => (instancia = valor) }, slots),
122
+ });
123
+ app.mount(alvo);
124
+ return {
125
+ raiz: alvo,
126
+ app,
127
+ get instancia() {
128
+ return instancia;
129
+ },
130
+ desmontar() {
131
+ app.unmount();
132
+ alvo.remove();
133
+ },
134
+ };
135
+ }
136
+
137
+ /** Espera o Vue aplicar as mudanças pendentes. */
138
+ export async function proximoTick() {
139
+ const { nextTick } = await import("vue");
140
+ await nextTick();
141
+ }
142
+
143
+ /** Dispara um evento de teclado e espera o Vue. */
144
+ export async function teclar(el, key, extra = {}) {
145
+ const evento = new janela.KeyboardEvent("keydown", { key, bubbles: true, cancelable: true, ...extra });
146
+ el.dispatchEvent(evento);
147
+ await proximoTick();
148
+ return evento;
149
+ }
150
+
151
+ /** Escreve `texto` num input e dispara `input`, como o navegador faz ao digitar. */
152
+ export async function digitar(el, texto) {
153
+ el.value = texto;
154
+ el.dispatchEvent(new janela.Event("input", { bubbles: true }));
155
+ await proximoTick();
156
+ }
157
+
158
+ /** Cola `texto` no elemento (evento `paste` com `clipboardData`). */
159
+ export async function colar(el, texto) {
160
+ const evento = new janela.Event("paste", { bubbles: true, cancelable: true });
161
+ Object.defineProperty(evento, "clipboardData", { value: { getData: () => texto } });
162
+ el.dispatchEvent(evento);
163
+ await proximoTick();
164
+ }
165
+
166
+ /** Clica no elemento e espera o Vue. */
167
+ export async function clicar(el) {
168
+ el.dispatchEvent(new janela.MouseEvent("click", { bubbles: true, cancelable: true }));
169
+ await proximoTick();
170
+ }
@@ -0,0 +1,39 @@
1
+ /** EmptyState com título rico (slot title) no Vue (DOM do jsdom). */
2
+ import { test, after } from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { montar } from "./dom.mjs";
5
+ import { h } from "vue";
6
+
7
+ const montados = [];
8
+ const abrir = async (props, slots) => {
9
+ const m = await montar("EmptyState/EmptyState.vue", props, slots);
10
+ montados.push(m);
11
+ return m;
12
+ };
13
+ after(() => montados.forEach((m) => m.desmontar()));
14
+
15
+ test("título em texto continua igual", async () => {
16
+ const m = await abrir({ title: "Nenhuma mensagem", description: "Tudo em dia." });
17
+ assert.equal(m.raiz.querySelector(".umds-empty-state__title").textContent.trim(), "Nenhuma mensagem");
18
+ });
19
+
20
+ test("o slot title traz conteúdo rico e vale sobre a prop", async () => {
21
+ const m = await abrir(
22
+ { title: "texto de reserva" },
23
+ { title: () => [h("span", { "data-termo": "1" }, "Nenhum processo para "), h("a", { href: "#limpar" }, "Limpar filtro")] },
24
+ );
25
+ const titulo = m.raiz.querySelector(".umds-empty-state__title");
26
+ assert.ok(titulo.querySelector("[data-termo]"));
27
+ assert.equal(titulo.querySelector("a").getAttribute("href"), "#limpar");
28
+ assert.doesNotMatch(titulo.textContent, /texto de reserva/);
29
+ });
30
+
31
+ test("só o slot, sem a prop title, também funciona", async () => {
32
+ const m = await abrir({}, { title: () => h("b", "Só o slot") });
33
+ assert.equal(m.raiz.querySelector(".umds-empty-state__title b").textContent, "Só o slot");
34
+ });
35
+
36
+ test("o título é um div", async () => {
37
+ const m = await abrir({ title: "x" });
38
+ assert.equal(m.raiz.querySelector(".umds-empty-state__title").tagName, "DIV");
39
+ });
@@ -0,0 +1,36 @@
1
+ /** FileInput variant trigger, conferido no HTML que o Vue GERADO escreve. */
2
+ import { test, before, after } from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { abrir, fechar, carregar, renderizar } from "./renderizar.mjs";
5
+
6
+ let FileInput;
7
+
8
+ before(async () => {
9
+ await abrir();
10
+ FileInput = await carregar("FileInput/FileInput.vue");
11
+ });
12
+ after(fechar);
13
+
14
+ test("trigger renderiza o conteúdo como gatilho e não escreve a caixa de arrastar", async () => {
15
+ const html = await renderizar(FileInput, { variant: "trigger" }, { default: "Anexar arquivo" });
16
+ assert.match(html, /umds-file-input--trigger/);
17
+ assert.match(html, /umds-file-input__trigger-wrap[^>]*>(?:<!--[^>]*-->)*Anexar arquivo/);
18
+ assert.doesNotMatch(html, /umds-file-input__drop-zone/);
19
+ });
20
+
21
+ test("o input nativo fica oculto ao lado, fora do Tab, com accept e multiple", async () => {
22
+ const html = await renderizar(FileInput, { variant: "trigger", accept: ".pdf", multiple: true, label: "Anexar" }, { default: "x" });
23
+ assert.match(html, /<input[^>]*type="file"/);
24
+ assert.match(html, /<input[^>]*tabIndex="-1"/);
25
+ assert.match(html, /<input[^>]*accept="\.pdf"/);
26
+ assert.match(html, /<input[^>]*multiple/);
27
+ assert.doesNotMatch(html, /umds-file-input__label/);
28
+ });
29
+
30
+ test("base e card seguem com a caixa e sem o gatilho", async () => {
31
+ for (const variant of ["base", "card"]) {
32
+ const html = await renderizar(FileInput, { variant });
33
+ assert.match(html, /umds-file-input__drop-zone/);
34
+ assert.doesNotMatch(html, /umds-file-input__trigger-wrap/);
35
+ }
36
+ });
@@ -0,0 +1,98 @@
1
+ /**
2
+ * IconPicker no Vue, montado num DOM (jsdom): radiogroup, busca, teclado.
3
+ */
4
+ import { test, after } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { faBuilding, faFileLines, faFolder, faGavel, faUser } from "@fortawesome/free-solid-svg-icons";
7
+ import { montar, documento, digitar, teclar, clicar, proximoTick } from "./dom.mjs";
8
+
9
+ const ICONES = [
10
+ faUser,
11
+ faFolder,
12
+ faFileLines,
13
+ { icon: faBuilding, label: "Prédio", keywords: ["prefeitura", "órgão"] },
14
+ { icon: faGavel, label: "Martelo", keywords: ["jurídico", "decisão"] },
15
+ ];
16
+
17
+ const montados = [];
18
+ const abrir = async (props = {}) => {
19
+ const m = await montar("IconPicker/IconPicker.vue", { ariaLabel: "Ícone", icons: ICONES, ...props });
20
+ montados.push(m);
21
+ await proximoTick();
22
+ return m;
23
+ };
24
+ after(() => montados.forEach((m) => m.desmontar()));
25
+
26
+ const radios = (m) => [...m.raiz.querySelectorAll('[role="radio"]')];
27
+ const nomes = (m) => radios(m).map((r) => r.getAttribute("aria-label"));
28
+
29
+ test("é um radiogroup com um radio por ícone, nomeado pelo iconName sem hífen", async () => {
30
+ const m = await abrir();
31
+ assert.equal(m.raiz.querySelector('[role="radiogroup"]').getAttribute("aria-label"), "Ícone");
32
+ assert.deepEqual(nomes(m), ["user", "folder", "file lines", "Prédio", "Martelo"]);
33
+ });
34
+
35
+ test("clicar escolhe e entrega o nome e o item em onChange", async () => {
36
+ const vistos = [];
37
+ const m = await abrir({ onChange: (nome, item) => vistos.push([nome, item]) });
38
+ await clicar(radios(m)[1]);
39
+ await clicar(radios(m)[3]);
40
+ assert.deepEqual(vistos[0], ["folder", faFolder]);
41
+ assert.deepEqual(vistos[1], ["building", ICONES[3]]);
42
+ assert.equal(radios(m)[3].getAttribute("aria-checked"), "true");
43
+ });
44
+
45
+ test("defaultValue marca o escolhido e só ele entra no Tab", async () => {
46
+ const m = await abrir({ defaultValue: "file-lines" });
47
+ assert.equal(radios(m)[2].getAttribute("aria-checked"), "true");
48
+ const comTab = radios(m).filter((r) => r.getAttribute("tabindex") === "0");
49
+ assert.equal(comTab.length, 1);
50
+ assert.equal(comTab[0], radios(m)[2]);
51
+ });
52
+
53
+ test("a busca filtra sem acento nem caixa, e anuncia a quantidade", async () => {
54
+ const m = await abrir({ resultsLabel: "{count} icons" });
55
+ const campo = m.raiz.querySelector('input[type="search"]');
56
+ assert.equal(m.raiz.querySelector('[role="status"]').textContent.trim(), "5 icons");
57
+ await digitar(campo, "JURIDICO");
58
+ assert.deepEqual(nomes(m), ["Martelo"]);
59
+ assert.equal(m.raiz.querySelector('[role="status"]').textContent.trim(), "1 icons");
60
+ await digitar(campo, "zzz");
61
+ assert.equal(m.raiz.querySelector('[role="radiogroup"]'), null);
62
+ assert.ok(m.raiz.textContent.includes("Nenhum ícone encontrado"));
63
+ });
64
+
65
+ test("setas movem a escolha e o foco; cima e baixo andam uma linha", async () => {
66
+ const vistos = [];
67
+ const m = await abrir({ columns: 2, defaultValue: "user", onChange: (n) => vistos.push(n) });
68
+ radios(m)[0].focus();
69
+ await teclar(radios(m)[0], "ArrowRight");
70
+ assert.deepEqual(vistos, ["folder"]);
71
+ assert.equal(documento.activeElement, radios(m)[1]);
72
+ await teclar(documento.activeElement, "ArrowDown");
73
+ assert.equal(documento.activeElement, radios(m)[3]);
74
+ await teclar(documento.activeElement, "ArrowUp");
75
+ assert.equal(documento.activeElement, radios(m)[1]);
76
+ await teclar(documento.activeElement, "End");
77
+ assert.equal(documento.activeElement, radios(m)[4]);
78
+ await teclar(documento.activeElement, "Home");
79
+ assert.equal(documento.activeElement, radios(m)[0]);
80
+ });
81
+
82
+ test("seta para baixo no campo de busca leva à grade", async () => {
83
+ const m = await abrir({ defaultValue: "folder" });
84
+ const campo = m.raiz.querySelector('input[type="search"]');
85
+ campo.focus();
86
+ await teclar(campo, "ArrowDown");
87
+ assert.equal(documento.activeElement, radios(m)[1]);
88
+ });
89
+
90
+ test("hideSearch, disabled, columns e maxHeight", async () => {
91
+ const sem = await abrir({ hideSearch: true });
92
+ assert.equal(sem.raiz.querySelector('input[type="search"]'), null);
93
+ const d = await abrir({ disabled: true, columns: 4, maxHeight: 120 });
94
+ for (const r of radios(d)) assert.equal(r.disabled, true);
95
+ const grade = d.raiz.querySelector(".umds-icon-picker__grid");
96
+ assert.match(grade.getAttribute("style"), /grid-template-columns:\s*repeat\(4,\s*var\(--umds-icon-picker-tile\)\)/);
97
+ assert.match(grade.getAttribute("style"), /max-height:\s*120px/);
98
+ });
@@ -0,0 +1,44 @@
1
+ /** Input grouped no Vue (DOM do jsdom). */
2
+ import { test, after } from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { readFileSync } from "node:fs";
5
+ import { resolve } from "node:path";
6
+ import { montar } from "./dom.mjs";
7
+
8
+ const montados = [];
9
+ const abrir = async (props) => {
10
+ const m = await montar("Input/Input.vue", props);
11
+ montados.push(m);
12
+ return m;
13
+ };
14
+ after(() => montados.forEach((m) => m.desmontar()));
15
+
16
+ test("grouped liga a classe própria e a do borderless; sem a prop, nenhuma", async () => {
17
+ const g = await abrir({ ariaLabel: "Adicionar setor", grouped: true });
18
+ const raiz = g.raiz.querySelector(".umds-input");
19
+ assert.ok(raiz.classList.contains("umds-input--grouped"));
20
+ assert.ok(raiz.classList.contains("umds-input--borderless"));
21
+ const n = await abrir({ ariaLabel: "Adicionar setor" });
22
+ const normal = n.raiz.querySelector(".umds-input");
23
+ assert.ok(!normal.classList.contains("umds-input--grouped"));
24
+ assert.ok(!normal.classList.contains("umds-input--borderless"));
25
+ });
26
+
27
+ test("borderless sozinho não ganha a classe do grupo", async () => {
28
+ const m = await abrir({ ariaLabel: "x", borderless: true });
29
+ const raiz = m.raiz.querySelector(".umds-input");
30
+ assert.ok(raiz.classList.contains("umds-input--borderless"));
31
+ assert.ok(!raiz.classList.contains("umds-input--grouped"));
32
+ });
33
+
34
+ test("CSS: o campo agrupado não impõe altura nem padding nem anel de foco próprio", () => {
35
+ const css = readFileSync(resolve(process.cwd(), "../core/src/components/Input/Input.css"), "utf8");
36
+ const bloco = (seletor) => {
37
+ const inicio = css.indexOf(seletor + " {");
38
+ return css.slice(inicio, css.indexOf("}", inicio));
39
+ };
40
+ assert.match(bloco(".umds-input--grouped .umds-input__container"), /height:\s*auto/);
41
+ const foco = bloco(".umds-input--grouped .umds-input__container:focus-within:not(.umds-input__container--disabled):not(.umds-input__container--readonly)");
42
+ assert.match(foco, /outline:\s*none/);
43
+ assert.match(foco, /box-shadow:\s*none/);
44
+ });
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Input no Vue GERADO: o campo escuta `input` (a cada tecla) e não só `change`
3
+ * (que no Vue só dispara no blur), e a máscara, o ícone à direita e o borderless
4
+ * chegam ao HTML.
5
+ */
6
+ import { test, before, after } from "node:test";
7
+ import assert from "node:assert/strict";
8
+ import { readFileSync } from "node:fs";
9
+ import { fileURLToPath } from "node:url";
10
+ import { resolve, dirname } from "node:path";
11
+ import { faMagnifyingGlass } from "@fortawesome/free-solid-svg-icons";
12
+ import { abrir, fechar, carregar, renderizar } from "./renderizar.mjs";
13
+
14
+ let Input;
15
+
16
+ before(async () => {
17
+ await abrir();
18
+ Input = await carregar("Input/Input.vue");
19
+ });
20
+ after(fechar);
21
+
22
+ test("o template gerado liga @input no campo (onChange a cada tecla, como no React)", () => {
23
+ const aqui = dirname(fileURLToPath(import.meta.url));
24
+ const fonte = readFileSync(resolve(aqui, "../components/Input/Input.vue"), "utf8");
25
+ const campo = fonte.match(/<input[\s\S]*?\/>/)?.[0] || fonte.match(/<input[\s\S]*?>/)?.[0] || "";
26
+ assert.match(campo, /@input=/);
27
+ assert.match(campo, /@blur=/, "o blur segue em onBlur");
28
+ });
29
+
30
+ test("mask formata o valor controlado e limita o tamanho", async () => {
31
+ const html = await renderizar(Input, { ariaLabel: "CPF", mask: "cpf", value: "12345678901" });
32
+ assert.match(html, /value="123\.456\.789-01"/);
33
+ assert.match(html, /maxlength="14"/i);
34
+ assert.match(html, /inputmode="numeric"/i);
35
+ });
36
+
37
+ test("mask phone escolhe o formato pelo tamanho", async () => {
38
+ assert.match(await renderizar(Input, { ariaLabel: "t", mask: "phone", value: "4133334444" }), /value="\(41\) 3333-4444"/);
39
+ assert.match(await renderizar(Input, { ariaLabel: "t", mask: "phone", value: "41999998888" }), /value="\(41\) 99999-8888"/);
40
+ });
41
+
42
+ test("mask cnpj e cep", async () => {
43
+ assert.match(await renderizar(Input, { ariaLabel: "t", mask: "cnpj", value: "12345678000190" }), /value="12\.345\.678\/0001-90"/);
44
+ assert.match(await renderizar(Input, { ariaLabel: "t", mask: "cep", value: "80010000" }), /value="80010-000"/);
45
+ });
46
+
47
+ test("sem mask não há inputmode nem maxlength, e o valor passa como veio", async () => {
48
+ const html = await renderizar(Input, { ariaLabel: "t", value: "12345678901" });
49
+ assert.match(html, /value="12345678901"/);
50
+ assert.doesNotMatch(html, /inputmode/i);
51
+ assert.doesNotMatch(html, /maxlength/i);
52
+ });
53
+
54
+ test("iconRight escreve o ícone decorativo; sem a prop não há", async () => {
55
+ const html = await renderizar(Input, { ariaLabel: "n", iconRight: faMagnifyingGlass });
56
+ assert.match(html, /<div[^>]*aria-hidden="true"[^>]*umds-input__icon-right/);
57
+ assert.match(html, /umds-input__icon-right[^>]*><span[^>]*><span><svg/);
58
+ assert.doesNotMatch(await renderizar(Input, { ariaLabel: "n" }), /umds-input__icon-right/);
59
+ });
60
+
61
+ test("borderless escreve a classe; sem a prop não", async () => {
62
+ assert.match(await renderizar(Input, { ariaLabel: "n", borderless: true }), /umds-input--borderless/);
63
+ assert.doesNotMatch(await renderizar(Input, { ariaLabel: "n" }), /umds-input--borderless/);
64
+ });
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Kbd e CodeBlock no Vue, montados num DOM (jsdom).
3
+ */
4
+ import { test, after } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { montar, janela, clicar, proximoTick } from "./dom.mjs";
7
+
8
+ const montados = [];
9
+ const abrir = async (caminho, props = {}, slots = {}) => {
10
+ const m = await montar(caminho, props, slots);
11
+ montados.push(m);
12
+ await proximoTick();
13
+ return m;
14
+ };
15
+ after(() => montados.forEach((m) => m.desmontar()));
16
+
17
+ test("Kbd: uma tecla é um kbd com o texto; raiz única repassa ouvinte e atributos", async () => {
18
+ let cliques = 0;
19
+ const m = await abrir("Kbd/Kbd.vue", { title: "Atalho", "data-x": "1", onClick: () => cliques++ }, { default: () => "Esc" });
20
+ const tecla = m.raiz.firstElementChild;
21
+ assert.equal(m.raiz.childNodes.length, 1);
22
+ assert.equal(tecla.tagName, "KBD");
23
+ assert.equal(tecla.textContent, "Esc");
24
+ assert.ok(tecla.classList.contains("umds-kbd") && tecla.classList.contains("umds-kbd--md"));
25
+ assert.equal(tecla.getAttribute("title"), "Atalho");
26
+ assert.equal(tecla.getAttribute("data-x"), "1");
27
+ tecla.dispatchEvent(new janela.MouseEvent("click", { bubbles: true }));
28
+ assert.equal(cliques, 1);
29
+ });
30
+
31
+ test("Kbd: keys desenha uma tecla por item com o separador; size e separator por prop", async () => {
32
+ const m = await abrir("Kbd/Kbd.vue", { keys: ["Ctrl", "Shift", "P"] });
33
+ const conjunto = m.raiz.firstElementChild;
34
+ assert.ok(conjunto.classList.contains("umds-kbd-combo"));
35
+ assert.equal(conjunto.querySelectorAll("kbd.umds-kbd").length, 3);
36
+ assert.equal(conjunto.textContent, "Ctrl+Shift+P");
37
+ const s = await abrir("Kbd/Kbd.vue", { keys: ["Ctrl", "K"], separator: " + ", size: "sm" });
38
+ assert.equal(s.raiz.firstElementChild.textContent, "Ctrl + K");
39
+ assert.ok(s.raiz.firstElementChild.classList.contains("umds-kbd--sm"));
40
+ });
41
+
42
+ test("CodeBlock: pre/code numa região focável e nomeada; texto por code ou por conteúdo", async () => {
43
+ const m = await abrir("CodeBlock/CodeBlock.vue", { code: '{\n "ok": true\n}', ariaLabel: "Resposta" });
44
+ const regiao = m.raiz.querySelector('[role="region"]');
45
+ assert.equal(regiao.tagName, "PRE");
46
+ assert.equal(regiao.getAttribute("aria-label"), "Resposta");
47
+ assert.equal(regiao.getAttribute("tabindex"), "0");
48
+ assert.equal(m.raiz.querySelector("code").textContent, '{\n "ok": true\n}');
49
+ const c = await abrir("CodeBlock/CodeBlock.vue", { language: "JSON" }, { default: () => "{}" });
50
+ assert.equal(c.raiz.querySelector("code").textContent, "{}");
51
+ assert.equal(c.raiz.querySelector('[role="region"]').getAttribute("aria-label"), "JSON");
52
+ });
53
+
54
+ test("CodeBlock: wrap e maxHeight; sem copyable não há botão", async () => {
55
+ const m = await abrir("CodeBlock/CodeBlock.vue", { code: "x", wrap: true, maxHeight: 120 });
56
+ assert.ok(m.raiz.querySelector(".umds-code-block--wrap"));
57
+ assert.match(m.raiz.querySelector("pre").getAttribute("style"), /max-height:\s*120px/);
58
+ assert.equal(m.raiz.querySelector("button"), null);
59
+ });
60
+
61
+ test("CodeBlock: copiar manda o texto, confirma e avisa onCopy", async () => {
62
+ const escritos = [];
63
+ Object.defineProperty(janela.navigator, "clipboard", { value: { writeText: (t) => (escritos.push(t), Promise.resolve()) }, configurable: true });
64
+ Object.defineProperty(globalThis, "navigator", { value: janela.navigator, configurable: true });
65
+ const copiados = [];
66
+ const m = await abrir("CodeBlock/CodeBlock.vue", { code: '{"a":1}', copyable: true, onCopy: (t) => copiados.push(t) });
67
+ const botao = m.raiz.querySelector(".umds-code-block__copy");
68
+ assert.equal(botao.getAttribute("aria-label"), "Copiar");
69
+ await clicar(botao);
70
+ await new Promise((r) => setTimeout(r, 10));
71
+ await proximoTick();
72
+ assert.deepEqual(escritos, ['{"a":1}']);
73
+ assert.deepEqual(copiados, ['{"a":1}']);
74
+ assert.equal(m.raiz.querySelector(".umds-code-block__copy").getAttribute("aria-label"), "Copiado");
75
+ assert.equal(m.raiz.querySelector('[role="status"]').textContent.trim(), "Copiado");
76
+ });
@@ -0,0 +1,75 @@
1
+ /**
2
+ * ListItem no Vue: tooltip, standalone e atributos só no elemento interativo (DOM do jsdom).
3
+ */
4
+ import { test, after } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { montar, clicar } from "./dom.mjs";
7
+
8
+ const montados = [];
9
+ const abrir = async (props, slots) => {
10
+ const m = await montar("List/ListItem.vue", props, slots);
11
+ montados.push(m);
12
+ return m;
13
+ };
14
+ after(() => montados.forEach((m) => m.desmontar()));
15
+
16
+ test("aria-*, role, data-* e style vão só ao elemento interativo; o li fica limpo", async () => {
17
+ const m = await abrir({
18
+ title: "Memorando 114/2025",
19
+ tooltip: "Abrir o memorando",
20
+ "aria-label": "Memorando",
21
+ role: "menuitem",
22
+ "data-origem": "home",
23
+ style: "margin-top: 4px",
24
+ });
25
+ const li = m.raiz.querySelector("li");
26
+ const botao = li.querySelector("button");
27
+ assert.equal(botao.getAttribute("title"), "Abrir o memorando");
28
+ assert.equal(botao.getAttribute("aria-label"), "Memorando");
29
+ assert.equal(botao.getAttribute("role"), "menuitem");
30
+ assert.equal(botao.getAttribute("data-origem"), "home");
31
+ assert.match(botao.getAttribute("style"), /margin-top:\s*4px/);
32
+ for (const a of ["title", "aria-label", "role", "data-origem", "style"]) {
33
+ assert.equal(li.getAttribute(a), null, `li não deve ter ${a}`);
34
+ }
35
+ });
36
+
37
+ test("o class do Vue segue no li, como sempre", async () => {
38
+ const m = await abrir({ title: "Com classe", class: "minha-linha" });
39
+ assert.ok(m.raiz.querySelector("li").classList.contains("minha-linha"));
40
+ assert.ok(!m.raiz.querySelector("button").classList.contains("minha-linha"));
41
+ });
42
+
43
+ test("tooltip no link e na linha div; sem tooltip não há title", async () => {
44
+ const link = await abrir({ title: "Link", href: "/x", tooltip: "Dica do link" });
45
+ assert.equal(link.raiz.querySelector("a").getAttribute("title"), "Dica do link");
46
+ const div = await abrir({ title: "Div", as: "div", tooltip: "Dica da div" });
47
+ assert.equal(div.raiz.querySelector(".umds-list-item").getAttribute("title"), "Dica da div");
48
+ const sem = await abrir({ title: "Sem dica" });
49
+ assert.equal(sem.raiz.querySelector("[title]"), null);
50
+ });
51
+
52
+ test("standalone: sem li, só o elemento interativo, com class, aria e clique", async () => {
53
+ let cliques = 0;
54
+ const m = await abrir({
55
+ standalone: true,
56
+ title: "12",
57
+ tooltip: "Página 12",
58
+ class: "numero",
59
+ "aria-label": "Página 12",
60
+ onClick: () => cliques++,
61
+ });
62
+ assert.equal(m.raiz.querySelector("li"), null);
63
+ const botao = m.raiz.querySelector("button");
64
+ assert.ok(botao);
65
+ assert.ok(botao.classList.contains("numero"));
66
+ assert.equal(botao.getAttribute("aria-label"), "Página 12");
67
+ assert.equal(botao.getAttribute("title"), "Página 12");
68
+ await clicar(botao);
69
+ assert.equal(cliques, 1);
70
+ });
71
+
72
+ test("sem standalone o li continua lá", async () => {
73
+ const m = await abrir({ title: "Normal" });
74
+ assert.equal(m.raiz.querySelectorAll("li").length, 1);
75
+ });