@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.
- package/CHANGELOG.md +1549 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1128 -29
- package/dist/index.mjs +12299 -7939
- 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/accordion-titulo-neutro.test.mjs +32 -0
- package/src/teste/appsubheader-regiao.test.mjs +18 -0
- package/src/teste/atributos.test.mjs +91 -0
- package/src/teste/attachmentcard-ia.test.mjs +48 -0
- package/src/teste/attachmentcard-lista.test.mjs +39 -0
- package/src/teste/attachmentcard-sm.test.mjs +28 -0
- package/src/teste/avatargroup-overlap.test.mjs +45 -0
- package/src/teste/badge-neutro-colado.test.mjs +30 -0
- package/src/teste/badge-tag.test.mjs +53 -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-slots-cabecalho.test.mjs +46 -0
- package/src/teste/calendar.test.mjs +179 -0
- package/src/teste/chips-xs.test.mjs +33 -0
- package/src/teste/coachmark-sem-veu.test.mjs +70 -0
- package/src/teste/coachmark.test.mjs +119 -0
- package/src/teste/color-picker-xs.test.mjs +28 -0
- package/src/teste/color-picker.test.mjs +79 -0
- package/src/teste/datatable-arvore-variantes.test.mjs +194 -0
- package/src/teste/datatable-documento.test.mjs +106 -0
- package/src/teste/datatable-slots.test.mjs +105 -0
- package/src/teste/descriptionlist-compacta.test.mjs +32 -0
- package/src/teste/dom.mjs +170 -0
- package/src/teste/empty-state-titulo-rico.test.mjs +39 -0
- package/src/teste/fileinput-trigger.test.mjs +36 -0
- package/src/teste/icon-picker.test.mjs +98 -0
- package/src/teste/input-agrupado.test.mjs +44 -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-item-standalone.test.mjs +75 -0
- package/src/teste/list.test.mjs +163 -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-alinha-imagem-tabela.test.mjs +164 -0
- package/src/teste/rich-text-editor-estilo-de-texto.test.mjs +87 -0
- package/src/teste/rich-text-editor.test.mjs +210 -0
- package/src/teste/segmented-contador.test.mjs +39 -0
- package/src/teste/select-aberto-controlado-flutuante.test.mjs +120 -0
- package/src/teste/select-filtro-cor-tamanho.test.mjs +62 -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/statcard-secundaria-tom.test.mjs +41 -0
- package/src/teste/tabs-contador-fechavel.test.mjs +60 -0
- package/src/teste/toast-acao-detalhes.test.mjs +48 -0
- package/src/teste/tooltip-dark.test.mjs +28 -0
- package/src/utils/calendario.ts +78 -0
- package/src/utils/html-seguro.ts +197 -0
- package/src/utils/paleta-de-cores.ts +34 -0
- package/src/utils/texto.ts +5 -0
- package/src/utils/toast.ts +12 -2
|
@@ -0,0 +1,163 @@
|
|
|
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
|
+
// o ListItem tem duas raízes (com li e standalone): o HTML abre com marcador de fragmento
|
|
26
|
+
assert.match(html, new RegExp(`${ABRE}<li class="umds-list__item"><button type="button"`));
|
|
27
|
+
assert.match(html, /Memorando 114\/2025/);
|
|
28
|
+
assert.doesNotMatch(html, /<a[ >]/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("ListItem com href vira link; target _blank ganha rel seguro", async () => {
|
|
32
|
+
const html = await renderizar(ListItem, { title: "Ofício", href: "/oficios/31", target: "_blank" });
|
|
33
|
+
assert.match(html, /<a[^>]*href="\/oficios\/31"/);
|
|
34
|
+
assert.match(html, /rel="noopener noreferrer"/);
|
|
35
|
+
assert.doesNotMatch(html, /<button/);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("ListItem as=div sem onClick é só leitura", async () => {
|
|
39
|
+
const html = await renderizar(ListItem, { as: "div", title: "Leitura" });
|
|
40
|
+
assert.match(html, /<div[^>]*class="umds-list-item/);
|
|
41
|
+
assert.doesNotMatch(html, /role=/);
|
|
42
|
+
assert.doesNotMatch(html, /tabindex=/i);
|
|
43
|
+
assert.doesNotMatch(html, /umds-list-item--interactive/);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("ListItem as=div com onClick ganha role=button e tabindex 0", async () => {
|
|
47
|
+
const html = await renderizar(ListItem, { as: "div", title: "Acionável", onClick: () => {} });
|
|
48
|
+
assert.match(html, /role="button"/);
|
|
49
|
+
assert.match(html, /tabindex="0"/i);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("ListItem monta os slots start, title, subtitle, meta, end e o padrão", async () => {
|
|
53
|
+
const html = await renderizar(
|
|
54
|
+
ListItem,
|
|
55
|
+
{},
|
|
56
|
+
{
|
|
57
|
+
start: () => h("i", { class: "ini" }, "AV"),
|
|
58
|
+
title: () => h("b", { class: "tit" }, "Título rico"),
|
|
59
|
+
subtitle: () => "Subtítulo",
|
|
60
|
+
meta: () => "Meta",
|
|
61
|
+
end: () => h("i", { class: "fim" }, "novo"),
|
|
62
|
+
default: () => h("p", { class: "livre" }, "livre"),
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
assert.match(html, /umds-list-item__start">(?:<!--.*?-->)*<i class="ini">AV/);
|
|
66
|
+
assert.match(html, /umds-list-item__title"[\s\S]*<b class="tit">Título rico<\/b>/);
|
|
67
|
+
assert.match(html, /umds-list-item__subtitle"[\s\S]*Subtítulo/);
|
|
68
|
+
assert.match(html, /umds-list-item__meta"[\s\S]*Meta/);
|
|
69
|
+
assert.match(html, /umds-list-item__end">(?:<!--.*?-->)*<i class="fim">novo/);
|
|
70
|
+
assert.match(html, /umds-list-item__body"[\s\S]*<p class="livre">livre<\/p>/);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("ListItem aceita title, subtitle e meta como texto por prop", async () => {
|
|
74
|
+
const html = await renderizar(ListItem, { title: "T", subtitle: "S", meta: "M" });
|
|
75
|
+
for (const parte of ["__title", "__subtitle", "__meta"]) assert.match(html, new RegExp(`umds-list-item${parte}`));
|
|
76
|
+
assert.doesNotMatch(html, / title="/);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("ListItem sem conteúdo não desenha as regiões vazias", async () => {
|
|
80
|
+
const html = await renderizar(ListItem, { title: "Só título" });
|
|
81
|
+
assert.doesNotMatch(html, /umds-list-item__(start|end|subtitle|meta)/);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("ListItem selected marca aria-current e a classe", async () => {
|
|
85
|
+
const html = await renderizar(ListItem, { title: "Atual", selected: true });
|
|
86
|
+
assert.match(html, /aria-current="true"/);
|
|
87
|
+
assert.match(html, /umds-list-item--selected/);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("ListItem disabled: button desabilitado; link sem href com aria-disabled", async () => {
|
|
91
|
+
const botao = await renderizar(ListItem, { title: "B", disabled: true });
|
|
92
|
+
assert.match(botao, /<button[^>]*disabled/);
|
|
93
|
+
assert.match(botao, /umds-list-item--disabled/);
|
|
94
|
+
const link = await renderizar(ListItem, { title: "L", href: "/x", disabled: true });
|
|
95
|
+
assert.doesNotMatch(link, /href=/);
|
|
96
|
+
assert.match(link, /aria-disabled="true"/);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("ListItem repassa aria-label, id, data-* e style ao elemento interativo", async () => {
|
|
100
|
+
const html = await renderizar(ListItem, {
|
|
101
|
+
"aria-label": "Abrir memorando",
|
|
102
|
+
id: "item-1",
|
|
103
|
+
"data-origem": "home",
|
|
104
|
+
style: "margin-top: 4px",
|
|
105
|
+
});
|
|
106
|
+
assert.match(html, /<button[^>]*aria-label="Abrir memorando"/);
|
|
107
|
+
assert.match(html, /<button[^>]*id="item-1"/);
|
|
108
|
+
assert.match(html, /<button[^>]*data-origem="home"/);
|
|
109
|
+
assert.match(html, /margin-top:\s*4px/);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("List é uma ul com role list, nome acessível e gap padrão", async () => {
|
|
113
|
+
const html = await renderizar(List, { ariaLabel: "Documentos não lidos" }, { default: () => h("li", "a") });
|
|
114
|
+
assert.match(html, new RegExp(`${ABRE}<ul[^>]*role="list"`));
|
|
115
|
+
assert.match(html, /aria-label="Documentos não lidos"/);
|
|
116
|
+
assert.match(html, /umds-list--gap-quarck/);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("List as=ol e gap trocam elemento e classe; ariaLabelledby é repassado", async () => {
|
|
120
|
+
const html = await renderizar(List, { as: "ol", gap: "nano", ariaLabelledby: "t" }, { default: () => h("li", "a") });
|
|
121
|
+
assert.match(html, new RegExp(`${ABRE}<ol`));
|
|
122
|
+
assert.match(html, /umds-list--gap-nano/);
|
|
123
|
+
assert.match(html, /aria-labelledby="t"/);
|
|
124
|
+
assert.doesNotMatch(html, /<ul/);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("List sem isEmpty nunca mostra o estado vazio", async () => {
|
|
128
|
+
const html = await renderizar(List, { emptyTitle: "Nada aqui" }, { default: () => h("li", "a") });
|
|
129
|
+
assert.doesNotMatch(html, /Nada aqui/);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("List isEmpty troca os itens pelo EmptyState, com role=status", async () => {
|
|
133
|
+
const html = await renderizar(
|
|
134
|
+
List,
|
|
135
|
+
{ isEmpty: true, emptyTitle: "Nenhum documento", emptyDescription: "Tudo em dia.", ariaLabel: "Lista" },
|
|
136
|
+
{ default: () => h("li", { class: "nao-aparece" }, "x") },
|
|
137
|
+
);
|
|
138
|
+
assert.match(html, new RegExp(`${ABRE}<div[^>]*role="status"`));
|
|
139
|
+
assert.match(html, /umds-list--empty/);
|
|
140
|
+
assert.match(html, /umds-empty-state--sm/);
|
|
141
|
+
assert.match(html, /Nenhum documento/);
|
|
142
|
+
assert.match(html, /Tudo em dia\./);
|
|
143
|
+
assert.doesNotMatch(html, /nao-aparece/);
|
|
144
|
+
assert.doesNotMatch(html, /<ul/);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("List isEmpty sem título usa o texto padrão", async () => {
|
|
148
|
+
const html = await renderizar(List, { isEmpty: true });
|
|
149
|
+
assert.match(html, /Nenhum item encontrado/);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("List isEmpty: o botão do estado vazio só existe com rótulo E callback", async () => {
|
|
153
|
+
const sem = await renderizar(List, { isEmpty: true, emptyActionLabel: "Atualizar" });
|
|
154
|
+
assert.doesNotMatch(sem, /Atualizar/);
|
|
155
|
+
const com = await renderizar(List, { isEmpty: true, emptyActionLabel: "Atualizar", onEmptyAction: () => {} });
|
|
156
|
+
assert.match(com, /Atualizar/);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("List isEmpty: o slot empty substitui o EmptyState", async () => {
|
|
160
|
+
const html = await renderizar(List, { isEmpty: true }, { empty: () => h("p", { class: "vazio" }, "Nada por aqui") });
|
|
161
|
+
assert.match(html, /<p class="vazio">Nada por aqui<\/p>/);
|
|
162
|
+
assert.doesNotMatch(html, /umds-empty-state/);
|
|
163
|
+
});
|
|
@@ -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
|
+
}
|