@1doc/1ds-vue 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 +1115 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1016 -28
- package/dist/index.mjs +10524 -7523
- package/dist/index.umd.js +4 -4
- package/package.json +5 -4
- package/src/index.ts +26 -0
- package/src/teste/accordion-conteudo-livre.test.mjs +44 -0
- package/src/teste/atributos.test.mjs +91 -0
- package/src/teste/attachmentcard-ia.test.mjs +48 -0
- package/src/teste/avatargroup-overlap.test.mjs +45 -0
- package/src/teste/badge-tag.test.mjs +45 -0
- package/src/teste/box-item-flex.test.mjs +84 -0
- package/src/teste/box-layout.test.mjs +57 -0
- package/src/teste/button.test.mjs +34 -0
- package/src/teste/calendar.test.mjs +179 -0
- package/src/teste/chips-xs.test.mjs +33 -0
- package/src/teste/coachmark.test.mjs +119 -0
- package/src/teste/color-picker.test.mjs +79 -0
- package/src/teste/datatable-documento.test.mjs +106 -0
- package/src/teste/datatable-slots.test.mjs +105 -0
- package/src/teste/dom.mjs +168 -0
- package/src/teste/fileinput-trigger.test.mjs +36 -0
- package/src/teste/icon-picker.test.mjs +98 -0
- package/src/teste/input-mascara-afins.test.mjs +64 -0
- package/src/teste/kbd-code-block.test.mjs +76 -0
- package/src/teste/list.test.mjs +162 -0
- package/src/teste/modal-variantes.test.mjs +79 -0
- package/src/teste/org-chart.test.mjs +131 -0
- package/src/teste/otp-input.test.mjs +130 -0
- package/src/teste/popover-maxheight.test.mjs +26 -0
- package/src/teste/renderizar.mjs +64 -0
- package/src/teste/rich-text-editor.test.mjs +210 -0
- package/src/teste/select-placement-filtro.test.mjs +49 -0
- package/src/teste/stack-box-raiz-unica.test.mjs +134 -0
- package/src/teste/stack.test.mjs +80 -0
- package/src/teste/statcard-rotulo-topo.test.mjs +34 -0
- package/src/teste/tabs-contador-fechavel.test.mjs +60 -0
- package/src/teste/tooltip-dark.test.mjs +28 -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,168 @@
|
|
|
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
|
+
"InputEvent",
|
|
55
|
+
"FocusEvent",
|
|
56
|
+
"CustomEvent",
|
|
57
|
+
"MutationObserver",
|
|
58
|
+
"getComputedStyle",
|
|
59
|
+
"requestAnimationFrame",
|
|
60
|
+
"cancelAnimationFrame",
|
|
61
|
+
]) {
|
|
62
|
+
if (nome in janela) {
|
|
63
|
+
Object.defineProperty(globalThis, nome, { value: janela[nome], configurable: true, writable: true });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// jsdom não traz ResizeObserver nem IntersectionObserver; os componentes só os usam se existirem.
|
|
67
|
+
|
|
68
|
+
registerHooks({
|
|
69
|
+
resolve(especificador, contexto, proximo) {
|
|
70
|
+
const relativo = /^\.{1,2}\//.test(especificador);
|
|
71
|
+
const ultimo = especificador.split("/").pop() || "";
|
|
72
|
+
if (relativo && !/\.[a-z0-9]+$/i.test(ultimo) && contexto.parentURL) {
|
|
73
|
+
const base = resolve(dirname(fileURLToPath(contexto.parentURL)), especificador);
|
|
74
|
+
for (const ext of [".ts", ".vue"]) {
|
|
75
|
+
if (existsSync(base + ext)) {
|
|
76
|
+
return { url: pathToFileURL(base + ext).href, shortCircuit: true };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return proximo(especificador, contexto);
|
|
81
|
+
},
|
|
82
|
+
load(url, contexto, proximo) {
|
|
83
|
+
if (url.endsWith(".css")) {
|
|
84
|
+
return { format: "module", source: "", shortCircuit: true };
|
|
85
|
+
}
|
|
86
|
+
if (url.endsWith(".vue")) {
|
|
87
|
+
const arquivo = fileURLToPath(url);
|
|
88
|
+
const { descriptor } = parse(readFileSync(arquivo, "utf8"), { filename: arquivo });
|
|
89
|
+
const script = compileScript(descriptor, { id: url, inlineTemplate: true });
|
|
90
|
+
// transpileModule (e não só apagar tipos): ele descarta os `import { Tipo }`
|
|
91
|
+
// que só servem a tipos, como o esbuild do Vite faz no build.
|
|
92
|
+
const js = ts.transpileModule(script.content, {
|
|
93
|
+
compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext },
|
|
94
|
+
}).outputText;
|
|
95
|
+
return { format: "module", source: js, shortCircuit: true };
|
|
96
|
+
}
|
|
97
|
+
return proximo(url, contexto);
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export const documento = janela.document;
|
|
102
|
+
export { janela };
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Monta `caminho` (dentro de `src/components`, ex. `Stack/Stack.vue`) num nó
|
|
106
|
+
* novo do `body`. `props` pode ser uma função (lida a cada render, para o teste
|
|
107
|
+
* mudar um `ref` e ver o componente reagir). Devolve `{ raiz, app, instancia, desmontar }`.
|
|
108
|
+
* `raiz` é o nó onde o app foi montado (o componente é o primeiro filho).
|
|
109
|
+
*/
|
|
110
|
+
export async function montar(caminho, props = {}, slots = {}) {
|
|
111
|
+
const { createApp, h } = await import("vue");
|
|
112
|
+
const modulo = await import(pathToFileURL(resolve(raiz, "src/components", caminho)).href);
|
|
113
|
+
const Componente = modulo.default;
|
|
114
|
+
const alvo = documento.createElement("div");
|
|
115
|
+
documento.body.append(alvo);
|
|
116
|
+
let instancia;
|
|
117
|
+
const app = createApp({
|
|
118
|
+
render: () =>
|
|
119
|
+
h(Componente, { ...(typeof props === "function" ? props() : props), ref: (valor) => (instancia = valor) }, slots),
|
|
120
|
+
});
|
|
121
|
+
app.mount(alvo);
|
|
122
|
+
return {
|
|
123
|
+
raiz: alvo,
|
|
124
|
+
app,
|
|
125
|
+
get instancia() {
|
|
126
|
+
return instancia;
|
|
127
|
+
},
|
|
128
|
+
desmontar() {
|
|
129
|
+
app.unmount();
|
|
130
|
+
alvo.remove();
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Espera o Vue aplicar as mudanças pendentes. */
|
|
136
|
+
export async function proximoTick() {
|
|
137
|
+
const { nextTick } = await import("vue");
|
|
138
|
+
await nextTick();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Dispara um evento de teclado e espera o Vue. */
|
|
142
|
+
export async function teclar(el, key, extra = {}) {
|
|
143
|
+
const evento = new janela.KeyboardEvent("keydown", { key, bubbles: true, cancelable: true, ...extra });
|
|
144
|
+
el.dispatchEvent(evento);
|
|
145
|
+
await proximoTick();
|
|
146
|
+
return evento;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Escreve `texto` num input e dispara `input`, como o navegador faz ao digitar. */
|
|
150
|
+
export async function digitar(el, texto) {
|
|
151
|
+
el.value = texto;
|
|
152
|
+
el.dispatchEvent(new janela.Event("input", { bubbles: true }));
|
|
153
|
+
await proximoTick();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Cola `texto` no elemento (evento `paste` com `clipboardData`). */
|
|
157
|
+
export async function colar(el, texto) {
|
|
158
|
+
const evento = new janela.Event("paste", { bubbles: true, cancelable: true });
|
|
159
|
+
Object.defineProperty(evento, "clipboardData", { value: { getData: () => texto } });
|
|
160
|
+
el.dispatchEvent(evento);
|
|
161
|
+
await proximoTick();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Clica no elemento e espera o Vue. */
|
|
165
|
+
export async function clicar(el) {
|
|
166
|
+
el.dispatchEvent(new janela.MouseEvent("click", { bubbles: true, cancelable: true }));
|
|
167
|
+
await proximoTick();
|
|
168
|
+
}
|
|
@@ -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,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,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ListItem e List no Vue (slots, elemento, estados, estado vazio),
|
|
3
|
+
* conferidos no HTML que o Vue GERADO escreve.
|
|
4
|
+
*/
|
|
5
|
+
import { test, before, after } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { h } from "vue";
|
|
8
|
+
import { abrir, fechar, carregar, renderizar } from "./renderizar.mjs";
|
|
9
|
+
|
|
10
|
+
/** Componente de raiz múltipla: o HTML abre com marcadores de fragmento do Vue. */
|
|
11
|
+
const ABRE = "^(?:<!--\\[-->|<!---->)*";
|
|
12
|
+
|
|
13
|
+
let List;
|
|
14
|
+
let ListItem;
|
|
15
|
+
|
|
16
|
+
before(async () => {
|
|
17
|
+
await abrir();
|
|
18
|
+
List = await carregar("List/List.vue");
|
|
19
|
+
ListItem = await carregar("List/ListItem.vue");
|
|
20
|
+
});
|
|
21
|
+
after(fechar);
|
|
22
|
+
|
|
23
|
+
test("ListItem sem as nem href é um button dentro de um li", async () => {
|
|
24
|
+
const html = await renderizar(ListItem, { title: "Memorando 114/2025" });
|
|
25
|
+
assert.match(html, /^<li class="umds-list__item"><button type="button"/);
|
|
26
|
+
assert.match(html, /Memorando 114\/2025/);
|
|
27
|
+
assert.doesNotMatch(html, /<a[ >]/);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("ListItem com href vira link; target _blank ganha rel seguro", async () => {
|
|
31
|
+
const html = await renderizar(ListItem, { title: "Ofício", href: "/oficios/31", target: "_blank" });
|
|
32
|
+
assert.match(html, /<a[^>]*href="\/oficios\/31"/);
|
|
33
|
+
assert.match(html, /rel="noopener noreferrer"/);
|
|
34
|
+
assert.doesNotMatch(html, /<button/);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("ListItem as=div sem onClick é só leitura", async () => {
|
|
38
|
+
const html = await renderizar(ListItem, { as: "div", title: "Leitura" });
|
|
39
|
+
assert.match(html, /<div[^>]*class="umds-list-item/);
|
|
40
|
+
assert.doesNotMatch(html, /role=/);
|
|
41
|
+
assert.doesNotMatch(html, /tabindex=/i);
|
|
42
|
+
assert.doesNotMatch(html, /umds-list-item--interactive/);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("ListItem as=div com onClick ganha role=button e tabindex 0", async () => {
|
|
46
|
+
const html = await renderizar(ListItem, { as: "div", title: "Acionável", onClick: () => {} });
|
|
47
|
+
assert.match(html, /role="button"/);
|
|
48
|
+
assert.match(html, /tabindex="0"/i);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("ListItem monta os slots start, title, subtitle, meta, end e o padrão", async () => {
|
|
52
|
+
const html = await renderizar(
|
|
53
|
+
ListItem,
|
|
54
|
+
{},
|
|
55
|
+
{
|
|
56
|
+
start: () => h("i", { class: "ini" }, "AV"),
|
|
57
|
+
title: () => h("b", { class: "tit" }, "Título rico"),
|
|
58
|
+
subtitle: () => "Subtítulo",
|
|
59
|
+
meta: () => "Meta",
|
|
60
|
+
end: () => h("i", { class: "fim" }, "novo"),
|
|
61
|
+
default: () => h("p", { class: "livre" }, "livre"),
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
assert.match(html, /umds-list-item__start">(?:<!--.*?-->)*<i class="ini">AV/);
|
|
65
|
+
assert.match(html, /umds-list-item__title"[\s\S]*<b class="tit">Título rico<\/b>/);
|
|
66
|
+
assert.match(html, /umds-list-item__subtitle"[\s\S]*Subtítulo/);
|
|
67
|
+
assert.match(html, /umds-list-item__meta"[\s\S]*Meta/);
|
|
68
|
+
assert.match(html, /umds-list-item__end">(?:<!--.*?-->)*<i class="fim">novo/);
|
|
69
|
+
assert.match(html, /umds-list-item__body"[\s\S]*<p class="livre">livre<\/p>/);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("ListItem aceita title, subtitle e meta como texto por prop", async () => {
|
|
73
|
+
const html = await renderizar(ListItem, { title: "T", subtitle: "S", meta: "M" });
|
|
74
|
+
for (const parte of ["__title", "__subtitle", "__meta"]) assert.match(html, new RegExp(`umds-list-item${parte}`));
|
|
75
|
+
assert.doesNotMatch(html, / title="/);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("ListItem sem conteúdo não desenha as regiões vazias", async () => {
|
|
79
|
+
const html = await renderizar(ListItem, { title: "Só título" });
|
|
80
|
+
assert.doesNotMatch(html, /umds-list-item__(start|end|subtitle|meta)/);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("ListItem selected marca aria-current e a classe", async () => {
|
|
84
|
+
const html = await renderizar(ListItem, { title: "Atual", selected: true });
|
|
85
|
+
assert.match(html, /aria-current="true"/);
|
|
86
|
+
assert.match(html, /umds-list-item--selected/);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("ListItem disabled: button desabilitado; link sem href com aria-disabled", async () => {
|
|
90
|
+
const botao = await renderizar(ListItem, { title: "B", disabled: true });
|
|
91
|
+
assert.match(botao, /<button[^>]*disabled/);
|
|
92
|
+
assert.match(botao, /umds-list-item--disabled/);
|
|
93
|
+
const link = await renderizar(ListItem, { title: "L", href: "/x", disabled: true });
|
|
94
|
+
assert.doesNotMatch(link, /href=/);
|
|
95
|
+
assert.match(link, /aria-disabled="true"/);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("ListItem repassa aria-label, id, data-* e style ao elemento interativo", async () => {
|
|
99
|
+
const html = await renderizar(ListItem, {
|
|
100
|
+
"aria-label": "Abrir memorando",
|
|
101
|
+
id: "item-1",
|
|
102
|
+
"data-origem": "home",
|
|
103
|
+
style: "margin-top: 4px",
|
|
104
|
+
});
|
|
105
|
+
assert.match(html, /<button[^>]*aria-label="Abrir memorando"/);
|
|
106
|
+
assert.match(html, /<button[^>]*id="item-1"/);
|
|
107
|
+
assert.match(html, /<button[^>]*data-origem="home"/);
|
|
108
|
+
assert.match(html, /margin-top:\s*4px/);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("List é uma ul com role list, nome acessível e gap padrão", async () => {
|
|
112
|
+
const html = await renderizar(List, { ariaLabel: "Documentos não lidos" }, { default: () => h("li", "a") });
|
|
113
|
+
assert.match(html, new RegExp(`${ABRE}<ul[^>]*role="list"`));
|
|
114
|
+
assert.match(html, /aria-label="Documentos não lidos"/);
|
|
115
|
+
assert.match(html, /umds-list--gap-quarck/);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("List as=ol e gap trocam elemento e classe; ariaLabelledby é repassado", async () => {
|
|
119
|
+
const html = await renderizar(List, { as: "ol", gap: "nano", ariaLabelledby: "t" }, { default: () => h("li", "a") });
|
|
120
|
+
assert.match(html, new RegExp(`${ABRE}<ol`));
|
|
121
|
+
assert.match(html, /umds-list--gap-nano/);
|
|
122
|
+
assert.match(html, /aria-labelledby="t"/);
|
|
123
|
+
assert.doesNotMatch(html, /<ul/);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("List sem isEmpty nunca mostra o estado vazio", async () => {
|
|
127
|
+
const html = await renderizar(List, { emptyTitle: "Nada aqui" }, { default: () => h("li", "a") });
|
|
128
|
+
assert.doesNotMatch(html, /Nada aqui/);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("List isEmpty troca os itens pelo EmptyState, com role=status", async () => {
|
|
132
|
+
const html = await renderizar(
|
|
133
|
+
List,
|
|
134
|
+
{ isEmpty: true, emptyTitle: "Nenhum documento", emptyDescription: "Tudo em dia.", ariaLabel: "Lista" },
|
|
135
|
+
{ default: () => h("li", { class: "nao-aparece" }, "x") },
|
|
136
|
+
);
|
|
137
|
+
assert.match(html, new RegExp(`${ABRE}<div[^>]*role="status"`));
|
|
138
|
+
assert.match(html, /umds-list--empty/);
|
|
139
|
+
assert.match(html, /umds-empty-state--sm/);
|
|
140
|
+
assert.match(html, /Nenhum documento/);
|
|
141
|
+
assert.match(html, /Tudo em dia\./);
|
|
142
|
+
assert.doesNotMatch(html, /nao-aparece/);
|
|
143
|
+
assert.doesNotMatch(html, /<ul/);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("List isEmpty sem título usa o texto padrão", async () => {
|
|
147
|
+
const html = await renderizar(List, { isEmpty: true });
|
|
148
|
+
assert.match(html, /Nenhum item encontrado/);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("List isEmpty: o botão do estado vazio só existe com rótulo E callback", async () => {
|
|
152
|
+
const sem = await renderizar(List, { isEmpty: true, emptyActionLabel: "Atualizar" });
|
|
153
|
+
assert.doesNotMatch(sem, /Atualizar/);
|
|
154
|
+
const com = await renderizar(List, { isEmpty: true, emptyActionLabel: "Atualizar", onEmptyAction: () => {} });
|
|
155
|
+
assert.match(com, /Atualizar/);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("List isEmpty: o slot empty substitui o EmptyState", async () => {
|
|
159
|
+
const html = await renderizar(List, { isEmpty: true }, { empty: () => h("p", { class: "vazio" }, "Nada por aqui") });
|
|
160
|
+
assert.match(html, /<p class="vazio">Nada por aqui<\/p>/);
|
|
161
|
+
assert.doesNotMatch(html, /umds-empty-state/);
|
|
162
|
+
});
|