@1doc/1ds-vue 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 +1289 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1218 -32
- package/dist/index.mjs +11156 -7808
- 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/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,79 @@
|
|
|
1
|
+
/** Modal: variant primary, width/maxWidth e controles de janela escolhidos, conferidos 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 Modal;
|
|
7
|
+
|
|
8
|
+
before(async () => {
|
|
9
|
+
await abrir();
|
|
10
|
+
Modal = await carregar("Modal/Modal.vue");
|
|
11
|
+
});
|
|
12
|
+
after(fechar);
|
|
13
|
+
|
|
14
|
+
const base = { open: true, inline: true, title: "Resolver tarefa" };
|
|
15
|
+
|
|
16
|
+
test("variant primary fica no modal base, com a classe do cabeçalho cheio", async () => {
|
|
17
|
+
const html = await renderizar(Modal, { ...base, variant: "primary" });
|
|
18
|
+
assert.match(html, /umds-modal--primary/);
|
|
19
|
+
assert.match(html, /umds-modal--base/);
|
|
20
|
+
assert.doesNotMatch(html, /umds-modal--feedback/);
|
|
21
|
+
assert.match(html, /umds-modal__header/);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("variant positive continua sendo diálogo de feedback", async () => {
|
|
25
|
+
const html = await renderizar(Modal, { ...base, variant: "positive" });
|
|
26
|
+
assert.match(html, /umds-modal--feedback/);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("width escreve a largura e solta o teto do size", async () => {
|
|
30
|
+
const html = await renderizar(Modal, { ...base, width: "600px" });
|
|
31
|
+
assert.match(html, /style="[^"]*width:\s*600px/);
|
|
32
|
+
assert.match(html, /style="[^"]*max-width:\s*100%/);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("maxWidth explícito vale; sem width nem maxWidth não há style no diálogo", async () => {
|
|
36
|
+
assert.match(await renderizar(Modal, { ...base, width: "90%", maxWidth: "720px" }), /max-width:\s*720px/);
|
|
37
|
+
const html = await renderizar(Modal, base);
|
|
38
|
+
assert.doesNotMatch(html, /role="dialog"[^>]*style="[^"]+"/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("windowControls true liga os quatro controles", async () => {
|
|
42
|
+
const html = await renderizar(Modal, { ...base, windowControls: true });
|
|
43
|
+
for (const nome of ["Modo normal", "Expandir", "Tela cheia", "Minimizar"]) {
|
|
44
|
+
assert.match(html, new RegExp(`aria-label="${nome}"`));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("windowControls como lista escolhe um a um", async () => {
|
|
49
|
+
const html = await renderizar(Modal, { ...base, windowControls: ["expand", "fullscreen"] });
|
|
50
|
+
assert.match(html, /aria-label="Expandir"/);
|
|
51
|
+
assert.match(html, /aria-label="Tela cheia"/);
|
|
52
|
+
assert.doesNotMatch(html, /aria-label="Minimizar"/);
|
|
53
|
+
assert.doesNotMatch(html, /aria-label="Modo normal"/);
|
|
54
|
+
assert.match(html, /aria-label="Fechar"/);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("sem windowControls só há o ×", async () => {
|
|
58
|
+
const html = await renderizar(Modal, base);
|
|
59
|
+
assert.doesNotMatch(html, /aria-label="Expandir"/);
|
|
60
|
+
assert.match(html, /aria-label="Fechar"/);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("com lista e modo normal, o diálogo não leva a classe de janela de 780px", async () => {
|
|
64
|
+
const html = await renderizar(Modal, { ...base, windowControls: ["expand"] });
|
|
65
|
+
assert.doesNotMatch(html, /umds-modal--janela-normal/);
|
|
66
|
+
const todos = await renderizar(Modal, { ...base, windowControls: true });
|
|
67
|
+
assert.match(todos, /umds-modal--janela-normal/);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("rodapé dado só por slot aparece (footer-slot e footer-start), sem confirmLabel nem cancelLabel", async () => {
|
|
71
|
+
const html = await renderizar(Modal, base, { "footer-slot": () => "ACAO-DO-RODAPE", "footer-start": () => "APOIO-DO-RODAPE" });
|
|
72
|
+
assert.match(html, /umds-modal__footer/);
|
|
73
|
+
assert.match(html, /ACAO-DO-RODAPE/);
|
|
74
|
+
assert.match(html, /APOIO-DO-RODAPE/);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("sem rodapé nenhum, não há faixa de rodapé", async () => {
|
|
78
|
+
assert.doesNotMatch(await renderizar(Modal, base), /umds-modal__footer/);
|
|
79
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OrgChart no Vue, montado num DOM (jsdom): árvore, posições, teclado e o slot `node`.
|
|
3
|
+
*/
|
|
4
|
+
import { test, after } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
// O dom.mjs vem ANTES do vue: o Vue lê o `document` global ao carregar.
|
|
7
|
+
import { montar, documento, teclar, clicar, proximoTick } from "./dom.mjs";
|
|
8
|
+
import { h } from "vue";
|
|
9
|
+
|
|
10
|
+
const ARVORE = [
|
|
11
|
+
{
|
|
12
|
+
id: "copirn",
|
|
13
|
+
title: "COPIRN",
|
|
14
|
+
subtitle: "Companhia Potiguar de Infraestrutura",
|
|
15
|
+
children: [
|
|
16
|
+
{ id: "aj", title: "AJ", subtitle: "Assessoria Jurídica" },
|
|
17
|
+
{
|
|
18
|
+
id: "sadm",
|
|
19
|
+
title: "SADM",
|
|
20
|
+
subtitle: "Secretaria de Administração",
|
|
21
|
+
children: [
|
|
22
|
+
{ id: "al", title: "AL", subtitle: "Almoxarifado" },
|
|
23
|
+
{ id: "ssa", title: "SSA", subtitle: "Subsetor do Almoxarifado" },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
{ id: "sfin", title: "SFIN", subtitle: "Secretaria de Finanças" },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const montados = [];
|
|
32
|
+
const abrir = async (props = {}, slots = {}) => {
|
|
33
|
+
const m = await montar("OrgChart/OrgChart.vue", { nodes: ARVORE, ...props }, slots);
|
|
34
|
+
montados.push(m);
|
|
35
|
+
await proximoTick();
|
|
36
|
+
return m;
|
|
37
|
+
};
|
|
38
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
39
|
+
|
|
40
|
+
const no = (m, id) => m.raiz.querySelector(`[data-node-id="${id}"]`);
|
|
41
|
+
const itens = (m) => m.raiz.querySelectorAll('[role="treeitem"]');
|
|
42
|
+
const esquerda = (m, id) => parseFloat(no(m, id).style.left);
|
|
43
|
+
|
|
44
|
+
test("é uma tree nomeada com um treeitem por nó visível e níveis ARIA", async () => {
|
|
45
|
+
const m = await abrir({ ariaLabel: "Setores" });
|
|
46
|
+
assert.equal(m.raiz.querySelector('[role="tree"]').getAttribute("aria-label"), "Setores");
|
|
47
|
+
assert.equal(itens(m).length, 6);
|
|
48
|
+
assert.equal(no(m, "al").getAttribute("aria-level"), "3");
|
|
49
|
+
assert.equal(no(m, "sadm").getAttribute("aria-posinset"), "2");
|
|
50
|
+
assert.equal(no(m, "sadm").getAttribute("aria-setsize"), "3");
|
|
51
|
+
assert.equal(no(m, "sadm").getAttribute("aria-expanded"), "true");
|
|
52
|
+
assert.equal(no(m, "aj").getAttribute("aria-expanded"), null);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("o pai se centra sobre os filhos; um conector por pai expandido", async () => {
|
|
56
|
+
const m = await abrir({ nodeWidth: 100, gapX: 20 });
|
|
57
|
+
assert.equal(esquerda(m, "aj"), 0);
|
|
58
|
+
assert.equal(esquerda(m, "al"), 120);
|
|
59
|
+
assert.equal(esquerda(m, "sadm"), 180);
|
|
60
|
+
assert.equal(esquerda(m, "sfin"), 360);
|
|
61
|
+
assert.equal(esquerda(m, "copirn"), 180);
|
|
62
|
+
assert.equal(m.raiz.querySelectorAll(".umds-org-chart__line").length, 2);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("recolher por Espaço esconde os filhos e avisa; o botão do mouse faz o mesmo", async () => {
|
|
66
|
+
const vistos = [];
|
|
67
|
+
const m = await abrir({ onCollapsedChange: (ids) => vistos.push(ids) });
|
|
68
|
+
no(m, "sadm").focus();
|
|
69
|
+
await teclar(no(m, "sadm"), " ");
|
|
70
|
+
assert.deepEqual(vistos, [["sadm"]]);
|
|
71
|
+
assert.equal(itens(m).length, 4);
|
|
72
|
+
await clicar(m.raiz.querySelectorAll(".umds-org-chart__toggle")[1]);
|
|
73
|
+
assert.deepEqual(vistos[1], []);
|
|
74
|
+
assert.equal(itens(m).length, 6);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("defaultCollapsedIds começa recolhido; clicar e Enter acionam o nó", async () => {
|
|
78
|
+
const cliques = [];
|
|
79
|
+
const m = await abrir({ defaultCollapsedIds: ["sadm"], onNodeClick: (n) => cliques.push(n.id) });
|
|
80
|
+
assert.equal(itens(m).length, 4);
|
|
81
|
+
await clicar(no(m, "aj"));
|
|
82
|
+
no(m, "sfin").focus();
|
|
83
|
+
await teclar(no(m, "sfin"), "Enter");
|
|
84
|
+
assert.deepEqual(cliques, ["aj", "sfin"]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("setas: baixo desce, cima sobe, lados andam entre irmãos, Home e End", async () => {
|
|
88
|
+
const m = await abrir();
|
|
89
|
+
no(m, "copirn").focus();
|
|
90
|
+
await teclar(no(m, "copirn"), "ArrowDown");
|
|
91
|
+
assert.equal(documento.activeElement, no(m, "aj"));
|
|
92
|
+
await teclar(documento.activeElement, "ArrowRight");
|
|
93
|
+
assert.equal(documento.activeElement, no(m, "sadm"));
|
|
94
|
+
await teclar(documento.activeElement, "ArrowDown");
|
|
95
|
+
assert.equal(documento.activeElement, no(m, "al"));
|
|
96
|
+
await teclar(documento.activeElement, "ArrowRight");
|
|
97
|
+
assert.equal(documento.activeElement, no(m, "ssa"));
|
|
98
|
+
await teclar(documento.activeElement, "Home");
|
|
99
|
+
assert.equal(documento.activeElement, no(m, "al"));
|
|
100
|
+
await teclar(documento.activeElement, "ArrowUp");
|
|
101
|
+
assert.equal(documento.activeElement, no(m, "sadm"));
|
|
102
|
+
await teclar(documento.activeElement, "End");
|
|
103
|
+
assert.equal(documento.activeElement, no(m, "sfin"));
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("só um nó entra no Tab; a raiz é cheia e selectedId marca", async () => {
|
|
107
|
+
const m = await abrir({ selectedId: "aj" });
|
|
108
|
+
const comTab = [...itens(m)].filter((n) => n.getAttribute("tabindex") === "0");
|
|
109
|
+
assert.equal(comTab.length, 1);
|
|
110
|
+
assert.equal(comTab[0], no(m, "copirn"));
|
|
111
|
+
assert.ok(no(m, "copirn").classList.contains("umds-org-chart__node--root"));
|
|
112
|
+
assert.equal(no(m, "aj").getAttribute("aria-selected"), "true");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("o slot node troca o conteúdo e recebe nó, nível e expandido", async () => {
|
|
116
|
+
const m = await abrir(
|
|
117
|
+
{},
|
|
118
|
+
{ node: ({ node, level, expanded }) => h("b", { class: "meu" }, node.title + ":" + level + ":" + expanded) },
|
|
119
|
+
);
|
|
120
|
+
assert.equal(no(m, "ssa").querySelector(".meu").textContent, "SSA:2:false");
|
|
121
|
+
assert.equal(no(m, "sadm").querySelector(".meu").textContent, "SADM:1:true");
|
|
122
|
+
assert.equal(no(m, "ssa").querySelector(".umds-org-chart__title"), null);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("sem slot, o conteúdo padrão mostra título e subtítulo; sem nós, não desenha", async () => {
|
|
126
|
+
const m = await abrir();
|
|
127
|
+
assert.equal(no(m, "aj").querySelector(".umds-org-chart__title").textContent.trim(), "AJ");
|
|
128
|
+
assert.equal(no(m, "aj").querySelector(".umds-org-chart__subtitle").textContent.trim(), "Assessoria Jurídica");
|
|
129
|
+
const v = await abrir({ nodes: [] });
|
|
130
|
+
assert.equal(v.raiz.querySelector('[role="tree"]'), null);
|
|
131
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OtpInput no Vue, montado num DOM (jsdom): digitar, colar, apagar e o foco.
|
|
3
|
+
*/
|
|
4
|
+
import { test, after } from "node:test";
|
|
5
|
+
import assert from "node:assert/strict";
|
|
6
|
+
import { montar, documento, digitar, colar, teclar, proximoTick } from "./dom.mjs";
|
|
7
|
+
|
|
8
|
+
const montados = [];
|
|
9
|
+
const abrir = async (props = {}) => {
|
|
10
|
+
const m = await montar("OtpInput/OtpInput.vue", { ariaLabel: "Código", ...props });
|
|
11
|
+
montados.push(m);
|
|
12
|
+
return m;
|
|
13
|
+
};
|
|
14
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
15
|
+
|
|
16
|
+
const caixas = (m) => [...m.raiz.querySelectorAll("input")];
|
|
17
|
+
const codigo = (m) => caixas(m).map((c) => c.value).join("");
|
|
18
|
+
|
|
19
|
+
test("tem 6 caixas, nome por caixa e grupo nomeado; length e digitLabel valem", async () => {
|
|
20
|
+
const m = await abrir();
|
|
21
|
+
assert.equal(caixas(m).length, 6);
|
|
22
|
+
assert.equal(m.raiz.querySelector('[role="group"]').getAttribute("aria-label"), "Código");
|
|
23
|
+
assert.equal(caixas(m)[2].getAttribute("aria-label"), "Dígito 3 de 6");
|
|
24
|
+
const t = await abrir({ length: 4, digitLabel: "Digit {n} of {total}" });
|
|
25
|
+
assert.equal(caixas(t).length, 4);
|
|
26
|
+
assert.equal(caixas(t)[1].getAttribute("aria-label"), "Digit 2 of 4");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("a primeira caixa leva autocomplete one-time-code", async () => {
|
|
30
|
+
const m = await abrir();
|
|
31
|
+
assert.equal(caixas(m)[0].getAttribute("autocomplete"), "one-time-code");
|
|
32
|
+
assert.equal(caixas(m)[1].getAttribute("autocomplete"), "off");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("digitar avança o foco e entrega o código em onChange", async () => {
|
|
36
|
+
const vistos = [];
|
|
37
|
+
const m = await abrir({ onChange: (v) => vistos.push(v) });
|
|
38
|
+
caixas(m)[0].focus();
|
|
39
|
+
await digitar(caixas(m)[0], "4");
|
|
40
|
+
await digitar(caixas(m)[1], "8");
|
|
41
|
+
await digitar(caixas(m)[2], "2");
|
|
42
|
+
assert.deepEqual(vistos, ["4", "48", "482"]);
|
|
43
|
+
assert.equal(codigo(m), "482");
|
|
44
|
+
assert.equal(documento.activeElement, caixas(m)[3]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("rejeita o que não é dígito e devolve a caixa ao que tinha", async () => {
|
|
48
|
+
const vistos = [];
|
|
49
|
+
const m = await abrir({ onChange: (v) => vistos.push(v) });
|
|
50
|
+
caixas(m)[0].focus();
|
|
51
|
+
await digitar(caixas(m)[0], "x");
|
|
52
|
+
assert.deepEqual(vistos, []);
|
|
53
|
+
assert.equal(caixas(m)[0].value, "");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("alphanumeric aceita letras e sai em maiúsculas", async () => {
|
|
57
|
+
const vistos = [];
|
|
58
|
+
const m = await abrir({ type: "alphanumeric", length: 4, onChange: (v) => vistos.push(v) });
|
|
59
|
+
caixas(m)[0].focus();
|
|
60
|
+
await digitar(caixas(m)[0], "a");
|
|
61
|
+
assert.deepEqual(vistos, ["A"]);
|
|
62
|
+
assert.equal(caixas(m)[0].getAttribute("inputmode"), "text");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("colar o código inteiro distribui, foca a última e chama onComplete uma vez", async () => {
|
|
66
|
+
const completos = [];
|
|
67
|
+
const m = await abrir({ onComplete: (v) => completos.push(v) });
|
|
68
|
+
caixas(m)[2].focus();
|
|
69
|
+
await colar(caixas(m)[2], "482 913");
|
|
70
|
+
assert.equal(codigo(m), "482913");
|
|
71
|
+
assert.deepEqual(completos, ["482913"]);
|
|
72
|
+
assert.equal(documento.activeElement, caixas(m)[5]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("autopreenchimento do SMS (código inteiro na primeira caixa) distribui", async () => {
|
|
76
|
+
const m = await abrir();
|
|
77
|
+
caixas(m)[0].focus();
|
|
78
|
+
await digitar(caixas(m)[0], "123456");
|
|
79
|
+
assert.equal(codigo(m), "123456");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("Backspace em caixa vazia volta e apaga o anterior; em caixa cheia apaga", async () => {
|
|
83
|
+
const vistos = [];
|
|
84
|
+
const m = await abrir({ defaultValue: "123", onChange: (v) => vistos.push(v) });
|
|
85
|
+
caixas(m)[3].focus();
|
|
86
|
+
await teclar(caixas(m)[3], "Backspace");
|
|
87
|
+
assert.deepEqual(vistos, ["12"]);
|
|
88
|
+
assert.equal(documento.activeElement, caixas(m)[2]);
|
|
89
|
+
await digitar(caixas(m)[1], "");
|
|
90
|
+
assert.equal(codigo(m), "1");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("setas, Home e End movem o foco", async () => {
|
|
94
|
+
const m = await abrir({ defaultValue: "1234" });
|
|
95
|
+
caixas(m)[4].focus();
|
|
96
|
+
await teclar(caixas(m)[4], "ArrowLeft");
|
|
97
|
+
assert.equal(documento.activeElement, caixas(m)[3]);
|
|
98
|
+
await teclar(caixas(m)[3], "Home");
|
|
99
|
+
assert.equal(documento.activeElement, caixas(m)[0]);
|
|
100
|
+
await teclar(caixas(m)[0], "End");
|
|
101
|
+
assert.equal(documento.activeElement, caixas(m)[4]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("foco à frente da primeira vazia volta para ela", async () => {
|
|
105
|
+
const m = await abrir({ defaultValue: "12" });
|
|
106
|
+
caixas(m)[5].focus();
|
|
107
|
+
assert.equal(documento.activeElement, caixas(m)[2]);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("controlado: o value de fora manda nas caixas", async () => {
|
|
111
|
+
const { ref } = await import("vue");
|
|
112
|
+
const valor = ref("90");
|
|
113
|
+
const m = await montar("OtpInput/OtpInput.vue", () => ({ ariaLabel: "Código", value: valor.value }));
|
|
114
|
+
montados.push(m);
|
|
115
|
+
assert.equal(codigo(m), "90");
|
|
116
|
+
valor.value = "7";
|
|
117
|
+
await proximoTick();
|
|
118
|
+
assert.equal(codigo(m), "7");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("errorMessage liga aria-invalid e aria-describedby; disabled desabilita", async () => {
|
|
122
|
+
const m = await abrir({ errorMessage: "Código inválido", id: "otp" });
|
|
123
|
+
for (const c of caixas(m)) {
|
|
124
|
+
assert.equal(c.getAttribute("aria-invalid"), "true");
|
|
125
|
+
assert.equal(c.getAttribute("aria-describedby"), "otp-error");
|
|
126
|
+
}
|
|
127
|
+
assert.ok(m.raiz.textContent.includes("Código inválido"));
|
|
128
|
+
const d = await abrir({ disabled: true });
|
|
129
|
+
for (const c of caixas(d)) assert.equal(c.disabled, true);
|
|
130
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Popover maxHeight no Vue GERADO. O painel vive num Portal e só monta aberto
|
|
3
|
+
* no navegador, então o SSR não o mostra: confere-se que a prop existe e que o
|
|
4
|
+
* componente renderiza com ela.
|
|
5
|
+
*/
|
|
6
|
+
import { test, before, after } from "node:test";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { abrir, fechar, carregar, renderizar } from "./renderizar.mjs";
|
|
9
|
+
|
|
10
|
+
let Popover;
|
|
11
|
+
|
|
12
|
+
before(async () => {
|
|
13
|
+
await abrir();
|
|
14
|
+
Popover = await carregar("Popover/Popover.vue");
|
|
15
|
+
});
|
|
16
|
+
after(fechar);
|
|
17
|
+
|
|
18
|
+
test("declara maxHeight", () => {
|
|
19
|
+
assert.ok(Object.keys(Popover.props || {}).includes("maxHeight"));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("renderiza o gatilho com maxHeight, sem abrir o painel", async () => {
|
|
23
|
+
const html = await renderizar(Popover, { title: "Colunas", maxHeight: "none" }, { default: "<button>Abrir</button>" });
|
|
24
|
+
assert.match(html, /Abrir/);
|
|
25
|
+
assert.doesNotMatch(html, /umds-popover__body/);
|
|
26
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renderiza um componente Vue GERADO no servidor (SSR) e devolve o HTML.
|
|
3
|
+
*
|
|
4
|
+
* Por que SSR e não jsdom: o pacote Vue não tem runner de testes, e o que
|
|
5
|
+
* estes testes conferem é o que o componente ESCREVE no DOM (atributos,
|
|
6
|
+
* classes) — o HTML do servidor é exatamente isso, sem dependência nova.
|
|
7
|
+
* Usa só `vite` e `@vitejs/plugin-vue`, que o pacote já tem para o build.
|
|
8
|
+
*
|
|
9
|
+
* Como o `Foo.vue` gerado vive em `src/components` (gitignored, reescrito a
|
|
10
|
+
* cada build), o teste fala do que o consumidor instala, não do `.lite.tsx`.
|
|
11
|
+
*/
|
|
12
|
+
import { createServer } from "vite";
|
|
13
|
+
import vue from "@vitejs/plugin-vue";
|
|
14
|
+
import { createSSRApp, h } from "vue";
|
|
15
|
+
import { renderToString } from "vue/server-renderer";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { dirname, resolve } from "node:path";
|
|
18
|
+
|
|
19
|
+
const raiz = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
|
20
|
+
|
|
21
|
+
let servidor;
|
|
22
|
+
|
|
23
|
+
/** Sobe o Vite em modo SSR uma vez só por arquivo de teste. */
|
|
24
|
+
export async function abrir() {
|
|
25
|
+
servidor = await createServer({
|
|
26
|
+
root: raiz,
|
|
27
|
+
configFile: false,
|
|
28
|
+
plugins: [vue()],
|
|
29
|
+
logLevel: "silent",
|
|
30
|
+
appType: "custom",
|
|
31
|
+
server: { middlewareMode: true, hmr: false, watch: null },
|
|
32
|
+
optimizeDeps: { noDiscovery: true, include: [] },
|
|
33
|
+
ssr: { noExternal: [/@1doc/] },
|
|
34
|
+
});
|
|
35
|
+
return servidor;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function fechar() {
|
|
39
|
+
if (servidor) await servidor.close();
|
|
40
|
+
servidor = undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Carrega um componente pelo caminho dentro de `src/components`. */
|
|
44
|
+
export async function carregar(caminho) {
|
|
45
|
+
const modulo = await servidor.ssrLoadModule(`/src/components/${caminho}`);
|
|
46
|
+
return modulo.default;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Renderiza `Componente` com `props` (atributos soltos entram junto) e um
|
|
51
|
+
* conteúdo padrão opcional. `slots` aceita `{ nome: "texto" }` ou, para slot
|
|
52
|
+
* com escopo, `{ nome: (props) => "texto" }`.
|
|
53
|
+
*/
|
|
54
|
+
export async function renderizar(Componente, props = {}, slots = {}) {
|
|
55
|
+
const filhos = Object.fromEntries(
|
|
56
|
+
Object.entries(slots).map(([nome, valor]) => [
|
|
57
|
+
nome,
|
|
58
|
+
// função = slot com escopo: recebe as props do slot e devolve o conteúdo
|
|
59
|
+
typeof valor === "function" ? valor : () => valor,
|
|
60
|
+
]),
|
|
61
|
+
);
|
|
62
|
+
const app = createSSRApp({ render: () => h(Componente, props, filhos) });
|
|
63
|
+
return renderToString(app);
|
|
64
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RichTextEditor no Vue, montado num DOM (jsdom). O jsdom não traz `execCommand`:
|
|
3
|
+
* o teste usa um espião e confere o que o editor pede ao navegador.
|
|
4
|
+
*/
|
|
5
|
+
import { test, after, beforeEach } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { montar, documento, janela, teclar, clicar, proximoTick } from "./dom.mjs";
|
|
8
|
+
|
|
9
|
+
let chamadas;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
chamadas = [];
|
|
12
|
+
documento.execCommand = (...args) => {
|
|
13
|
+
chamadas.push(args);
|
|
14
|
+
return true;
|
|
15
|
+
};
|
|
16
|
+
documento.queryCommandState = () => false;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const montados = [];
|
|
20
|
+
const abrir = async (props = {}, slots = {}) => {
|
|
21
|
+
const m = await montar("RichTextEditor/RichTextEditor.vue", { ariaLabel: "Despacho", ...props }, slots);
|
|
22
|
+
montados.push(m);
|
|
23
|
+
await proximoTick();
|
|
24
|
+
return m;
|
|
25
|
+
};
|
|
26
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
27
|
+
|
|
28
|
+
const area = (m) => m.raiz.querySelector('[role="textbox"]');
|
|
29
|
+
const botao = (m, nome) => [...m.raiz.querySelectorAll("button")].find((b) => b.getAttribute("aria-label") === nome || b.textContent.trim() === nome);
|
|
30
|
+
const escrever = async (m, html) => {
|
|
31
|
+
area(m).innerHTML = html;
|
|
32
|
+
area(m).dispatchEvent(new janela.Event("input", { bubbles: true }));
|
|
33
|
+
await proximoTick();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
test("a barra é um toolbar nomeado com as ferramentas padrão e três separadores", async () => {
|
|
37
|
+
const m = await abrir();
|
|
38
|
+
const barra = m.raiz.querySelector('[role="toolbar"]');
|
|
39
|
+
assert.equal(barra.getAttribute("aria-label"), "Formatação");
|
|
40
|
+
for (const nome of ["Negrito", "Itálico", "Sublinhado", "Lista com marcadores", "Lista numerada", "Link", "Desfazer", "Refazer"]) {
|
|
41
|
+
assert.ok(botao(m, nome), nome);
|
|
42
|
+
}
|
|
43
|
+
assert.equal(barra.querySelectorAll('[role="separator"]').length, 3);
|
|
44
|
+
assert.equal(botao(m, "Tachado"), undefined);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("a área é um textbox multilinha editável, com placeholder", async () => {
|
|
48
|
+
const m = await abrir({ placeholder: "Escreva o despacho..." });
|
|
49
|
+
assert.equal(area(m).getAttribute("aria-label"), "Despacho");
|
|
50
|
+
assert.equal(area(m).getAttribute("aria-multiline"), "true");
|
|
51
|
+
assert.equal(area(m).getAttribute("contenteditable"), "true");
|
|
52
|
+
assert.equal(area(m).getAttribute("data-placeholder"), "Escreva o despacho...");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("toolbar escolhe as ferramentas; labels traduz", async () => {
|
|
56
|
+
const m = await abrir({ toolbar: ["bold", "|", "strike"], toolbarLabel: "Formatting", labels: { bold: "Bold" } });
|
|
57
|
+
assert.equal(m.raiz.querySelector('[role="toolbar"]').getAttribute("aria-label"), "Formatting");
|
|
58
|
+
assert.deepEqual([...m.raiz.querySelectorAll(".umds-rte__tool")].map((b) => b.getAttribute("aria-label")), ["Bold", "Tachado"]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("o HTML que entra é higienizado", async () => {
|
|
62
|
+
const m = await abrir({
|
|
63
|
+
defaultValue: '<p style="color:red" 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>',
|
|
64
|
+
});
|
|
65
|
+
const html = area(m).innerHTML;
|
|
66
|
+
assert.doesNotMatch(html, /script|onerror|onclick|style=|javascript:|<img/i);
|
|
67
|
+
assert.ok(html.includes('<a href="https://1doc.com.br" rel="noopener noreferrer">bom</a>'));
|
|
68
|
+
assert.ok(html.includes("<p>ok</p>"));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("digitar entrega o HTML em onChange; apagar tudo entrega vazio", async () => {
|
|
72
|
+
const vistos = [];
|
|
73
|
+
const m = await abrir({ onChange: (h) => vistos.push(h) });
|
|
74
|
+
await escrever(m, "<b>Oi</b>");
|
|
75
|
+
await escrever(m, "<br>");
|
|
76
|
+
assert.deepEqual(vistos, ["<b>Oi</b>", ""]);
|
|
77
|
+
assert.equal(area(m).innerHTML, "");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("colar entra como texto puro", async () => {
|
|
81
|
+
const m = await abrir();
|
|
82
|
+
const evento = new janela.Event("paste", { bubbles: true, cancelable: true });
|
|
83
|
+
Object.defineProperty(evento, "clipboardData", { value: { getData: (t) => (t === "text/plain" ? "texto puro" : "<b>html</b>") } });
|
|
84
|
+
area(m).dispatchEvent(evento);
|
|
85
|
+
assert.equal(evento.defaultPrevented, true);
|
|
86
|
+
assert.deepEqual(chamadas, [["insertText", false, "texto puro"]]);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("cada botão pede o seu comando ao navegador", async () => {
|
|
90
|
+
const m = await abrir({ toolbar: ["bold", "italic", "underline", "strike", "ul", "ol", "undo", "redo", "clear"] });
|
|
91
|
+
const esperado = {
|
|
92
|
+
Negrito: "bold",
|
|
93
|
+
Itálico: "italic",
|
|
94
|
+
Sublinhado: "underline",
|
|
95
|
+
Tachado: "strikeThrough",
|
|
96
|
+
"Lista com marcadores": "insertUnorderedList",
|
|
97
|
+
"Lista numerada": "insertOrderedList",
|
|
98
|
+
Desfazer: "undo",
|
|
99
|
+
Refazer: "redo",
|
|
100
|
+
"Limpar formatação": "removeFormat",
|
|
101
|
+
};
|
|
102
|
+
for (const [nome, comando] of Object.entries(esperado)) {
|
|
103
|
+
chamadas.length = 0;
|
|
104
|
+
await clicar(botao(m, nome));
|
|
105
|
+
assert.deepEqual(chamadas[0], [comando, false, undefined], nome);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("o mousedown na barra é impedido (a área não perde o foco nem a seleção)", async () => {
|
|
110
|
+
const m = await abrir();
|
|
111
|
+
const evento = new janela.MouseEvent("mousedown", { bubbles: true, cancelable: true });
|
|
112
|
+
botao(m, "Negrito").dispatchEvent(evento);
|
|
113
|
+
assert.equal(evento.defaultPrevented, true);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("os botões de liga/desliga seguem o cursor (aria-pressed)", async () => {
|
|
117
|
+
const m = await abrir({ defaultValue: "<p>x</p>" });
|
|
118
|
+
assert.equal(botao(m, "Negrito").getAttribute("aria-pressed"), "false");
|
|
119
|
+
documento.queryCommandState = (c) => c === "bold";
|
|
120
|
+
const selecao = janela.getSelection();
|
|
121
|
+
const faixa = documento.createRange();
|
|
122
|
+
faixa.selectNodeContents(area(m));
|
|
123
|
+
selecao.removeAllRanges();
|
|
124
|
+
selecao.addRange(faixa);
|
|
125
|
+
documento.dispatchEvent(new janela.Event("selectionchange"));
|
|
126
|
+
await proximoTick();
|
|
127
|
+
assert.equal(botao(m, "Negrito").getAttribute("aria-pressed"), "true");
|
|
128
|
+
assert.equal(botao(m, "Link").getAttribute("aria-pressed"), null);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("setas movem entre as ferramentas (Tab numa parada só)", async () => {
|
|
132
|
+
const m = await abrir({ toolbar: ["bold", "italic", "underline"] });
|
|
133
|
+
const botoes = [...m.raiz.querySelectorAll(".umds-rte__tool")];
|
|
134
|
+
assert.deepEqual(botoes.map((b) => b.getAttribute("tabindex")), ["0", "-1", "-1"]);
|
|
135
|
+
botoes[0].focus();
|
|
136
|
+
await teclar(botoes[0], "ArrowRight");
|
|
137
|
+
assert.equal(documento.activeElement, botoes[1]);
|
|
138
|
+
await teclar(documento.activeElement, "End");
|
|
139
|
+
assert.equal(documento.activeElement, botoes[2]);
|
|
140
|
+
await teclar(documento.activeElement, "ArrowRight");
|
|
141
|
+
assert.equal(documento.activeElement, botoes[0]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("readOnly: sem barra e sem edição; disabled desabilita os botões", async () => {
|
|
145
|
+
const r = await abrir({ readOnly: true, defaultValue: "<p>x</p>" });
|
|
146
|
+
assert.equal(r.raiz.querySelector('[role="toolbar"]'), null);
|
|
147
|
+
assert.equal(area(r).getAttribute("contenteditable"), "false");
|
|
148
|
+
const d = await abrir({ disabled: true });
|
|
149
|
+
for (const b of d.raiz.querySelectorAll(".umds-rte__tool")) assert.equal(b.disabled, true);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("errorMessage liga aria-invalid e aria-describedby; o slot footer entra", async () => {
|
|
153
|
+
const m = await abrir({ errorMessage: "Escreva o despacho", id: "r" }, { footer: () => "Ana Paula Souza" });
|
|
154
|
+
assert.equal(area(m).getAttribute("aria-invalid"), "true");
|
|
155
|
+
assert.equal(area(m).getAttribute("aria-describedby"), "r-error");
|
|
156
|
+
assert.ok(m.raiz.querySelector(".umds-rte__footer").textContent.includes("Ana Paula Souza"));
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("o botão Link abre o campo; aplicar com texto escolhido cria o link com https://", async () => {
|
|
160
|
+
const m = await abrir({ defaultValue: "<p>texto</p>" });
|
|
161
|
+
const selecao = janela.getSelection();
|
|
162
|
+
const faixa = documento.createRange();
|
|
163
|
+
faixa.selectNodeContents(area(m));
|
|
164
|
+
selecao.removeAllRanges();
|
|
165
|
+
selecao.addRange(faixa);
|
|
166
|
+
await clicar(botao(m, "Link"));
|
|
167
|
+
const campo = m.raiz.querySelector(".umds-rte__link input");
|
|
168
|
+
assert.ok(campo);
|
|
169
|
+
campo.value = "exemplo.com.br";
|
|
170
|
+
campo.dispatchEvent(new janela.Event("input", { bubbles: true }));
|
|
171
|
+
await proximoTick();
|
|
172
|
+
m.raiz.querySelector(".umds-rte__link").dispatchEvent(new janela.Event("submit", { bubbles: true, cancelable: true }));
|
|
173
|
+
await proximoTick();
|
|
174
|
+
assert.deepEqual(chamadas.find((c) => c[0] === "createLink"), ["createLink", false, "https://exemplo.com.br"]);
|
|
175
|
+
assert.equal(m.raiz.querySelector(".umds-rte__link"), null);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("endereço perigoso não vira link e mostra o erro", async () => {
|
|
179
|
+
const m = await abrir({ defaultValue: "<p>texto</p>" });
|
|
180
|
+
await clicar(botao(m, "Link"));
|
|
181
|
+
const campo = m.raiz.querySelector(".umds-rte__link input");
|
|
182
|
+
campo.value = "javascript:alert(1)";
|
|
183
|
+
campo.dispatchEvent(new janela.Event("input", { bubbles: true }));
|
|
184
|
+
await proximoTick();
|
|
185
|
+
m.raiz.querySelector(".umds-rte__link").dispatchEvent(new janela.Event("submit", { bubbles: true, cancelable: true }));
|
|
186
|
+
await proximoTick();
|
|
187
|
+
assert.equal(chamadas.some((c) => c[0] === "createLink" || c[0] === "insertHTML"), false);
|
|
188
|
+
assert.ok(m.raiz.textContent.includes("Use um endereço http, https, mailto ou tel."));
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("Esc no campo de link fecha; Ctrl+K na área abre", async () => {
|
|
192
|
+
const m = await abrir();
|
|
193
|
+
area(m).dispatchEvent(new janela.KeyboardEvent("keydown", { key: "k", ctrlKey: true, bubbles: true, cancelable: true }));
|
|
194
|
+
await proximoTick();
|
|
195
|
+
assert.ok(m.raiz.querySelector(".umds-rte__link"));
|
|
196
|
+
await teclar(m.raiz.querySelector(".umds-rte__link input"), "Escape");
|
|
197
|
+
assert.equal(m.raiz.querySelector(".umds-rte__link"), null);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("controlado: um value novo de fora reescreve a área", async () => {
|
|
201
|
+
const { ref } = await import("vue");
|
|
202
|
+
const html = ref("<p>um</p>");
|
|
203
|
+
const m = await montar("RichTextEditor/RichTextEditor.vue", () => ({ ariaLabel: "x", value: html.value }));
|
|
204
|
+
montados.push(m);
|
|
205
|
+
await proximoTick();
|
|
206
|
+
assert.equal(area(m).innerHTML, "<p>um</p>");
|
|
207
|
+
html.value = "<p>dois</p>";
|
|
208
|
+
await proximoTick();
|
|
209
|
+
assert.equal(area(m).innerHTML, "<p>dois</p>");
|
|
210
|
+
});
|