@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,62 @@
|
|
|
1
|
+
/** Select: filtro (tamanho, fundo) e cor por opção no Vue (DOM do jsdom). */
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { montar, clicar } from "./dom.mjs";
|
|
5
|
+
|
|
6
|
+
const montados = [];
|
|
7
|
+
const abrir = async (props) => {
|
|
8
|
+
const m = await montar("Select/Select.vue", props);
|
|
9
|
+
montados.push(m);
|
|
10
|
+
return m;
|
|
11
|
+
};
|
|
12
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
13
|
+
|
|
14
|
+
const MARCADORES = [
|
|
15
|
+
{ label: "Urgente", value: "urgente", color: "var(--umds-semantic-color-feedback-negative-pure)" },
|
|
16
|
+
{ label: "Revisão", value: "revisao", color: "var(--umds-semantic-color-primary-pure)" },
|
|
17
|
+
{ label: "Sem marcador", value: "nenhum" },
|
|
18
|
+
];
|
|
19
|
+
const raiz = (m) => m.raiz.querySelector(".umds-select");
|
|
20
|
+
|
|
21
|
+
test("as variantes de filtro nascem no tamanho sm; size explícito manda; o padrão segue md", async () => {
|
|
22
|
+
for (const variant of ["filter", "search", "combo"]) {
|
|
23
|
+
const m = await abrir({ ariaLabel: "x", options: MARCADORES, variant });
|
|
24
|
+
assert.ok(raiz(m).classList.contains("umds-select--sm"), variant);
|
|
25
|
+
}
|
|
26
|
+
const md = await abrir({ ariaLabel: "x", options: MARCADORES, variant: "filter", size: "md" });
|
|
27
|
+
assert.ok(raiz(md).classList.contains("umds-select--md"));
|
|
28
|
+
const padrao = await abrir({ ariaLabel: "x", options: MARCADORES });
|
|
29
|
+
assert.ok(raiz(padrao).classList.contains("umds-select--md") && !raiz(padrao).classList.contains("umds-select--sm"));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("--has-value só com valor escolhido numa variante de filtro", async () => {
|
|
33
|
+
const sem = await abrir({ ariaLabel: "x", options: MARCADORES, variant: "filter", placeholder: "Marcadores" });
|
|
34
|
+
assert.ok(!raiz(sem).classList.contains("umds-select--has-value"));
|
|
35
|
+
const com = await abrir({ ariaLabel: "x", options: MARCADORES, variant: "filter", placeholder: "Marcadores", value: "urgente" });
|
|
36
|
+
assert.ok(raiz(com).classList.contains("umds-select--has-value"));
|
|
37
|
+
const padrao = await abrir({ ariaLabel: "x", options: MARCADORES, placeholder: "Marcadores", value: "urgente" });
|
|
38
|
+
assert.ok(!raiz(padrao).classList.contains("umds-select--has-value"));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("a lista mostra uma amostra por opção com color", async () => {
|
|
42
|
+
const m = await abrir({ ariaLabel: "x", options: MARCADORES, variant: "filter" });
|
|
43
|
+
await clicar(m.raiz.querySelector('[role="combobox"]'));
|
|
44
|
+
const opcoes = [...m.raiz.querySelectorAll('[role="option"]')];
|
|
45
|
+
assert.equal(opcoes[0].querySelector(".umds-select__swatch").getAttribute("aria-hidden"), "true");
|
|
46
|
+
assert.match(opcoes[0].querySelector(".umds-select__swatch").getAttribute("style"), /feedback-negative-pure/);
|
|
47
|
+
assert.ok(opcoes[1].querySelector(".umds-select__swatch"));
|
|
48
|
+
assert.equal(opcoes[2].querySelector(".umds-select__swatch"), null);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("o gatilho ganha a cor da opção escolhida; triggerSwatch manda; sem valor e múltipla não pintam", async () => {
|
|
52
|
+
const escolhida = await abrir({ ariaLabel: "x", options: MARCADORES, value: "revisao", placeholder: "Marcadores" });
|
|
53
|
+
assert.match(escolhida.raiz.querySelector(".umds-select__trigger .umds-select__swatch").getAttribute("style"), /primary-pure/);
|
|
54
|
+
const explicita = await abrir({ ariaLabel: "x", options: MARCADORES, value: "urgente", triggerSwatch: "var(--umds-semantic-color-feedback-positive-pure)" });
|
|
55
|
+
const amostras = explicita.raiz.querySelectorAll(".umds-select__trigger .umds-select__swatch");
|
|
56
|
+
assert.equal(amostras.length, 1);
|
|
57
|
+
assert.match(amostras[0].getAttribute("style"), /feedback-positive-pure/);
|
|
58
|
+
const vazio = await abrir({ ariaLabel: "x", options: MARCADORES, placeholder: "Marcadores" });
|
|
59
|
+
assert.equal(vazio.raiz.querySelector(".umds-select__trigger .umds-select__swatch"), null);
|
|
60
|
+
const multipla = await abrir({ ariaLabel: "x", options: MARCADORES, multiple: true, value: ["urgente", "revisao"] });
|
|
61
|
+
assert.equal(multipla.raiz.querySelector(".umds-select__trigger .umds-select__swatch"), null);
|
|
62
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** Select: variant filter e footer, conferidos no HTML que o Vue GERADO escreve (a lista só existe aberta, então o que o SSR mostra é o gatilho). */
|
|
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 Select;
|
|
7
|
+
|
|
8
|
+
before(async () => {
|
|
9
|
+
await abrir();
|
|
10
|
+
Select = await carregar("Select/Select.vue");
|
|
11
|
+
});
|
|
12
|
+
after(fechar);
|
|
13
|
+
|
|
14
|
+
const opcoes = [
|
|
15
|
+
{ label: "Urgente", value: "urgente" },
|
|
16
|
+
{ label: "Revisão", value: "revisao" },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
test("variant filter escreve a classe; sem variant não escreve", async () => {
|
|
20
|
+
assert.match(await renderizar(Select, { ariaLabel: "x", options: opcoes, variant: "filter" }), /umds-select--filter/);
|
|
21
|
+
assert.doesNotMatch(await renderizar(Select, { ariaLabel: "x", options: opcoes }), /umds-select--filter/);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("sem placement a lista não leva a classe de abrir para cima", async () => {
|
|
25
|
+
assert.doesNotMatch(await renderizar(Select, { ariaLabel: "x", options: opcoes }), /umds-select--placement-top/);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("com emptyOptionLabel e valor vazio o gatilho mostra o placeholder (nome do filtro)", async () => {
|
|
29
|
+
const html = await renderizar(Select, {
|
|
30
|
+
ariaLabel: "Marcadores",
|
|
31
|
+
placeholder: "Marcadores",
|
|
32
|
+
options: opcoes,
|
|
33
|
+
emptyOptionLabel: "Todos os marcadores",
|
|
34
|
+
value: "",
|
|
35
|
+
});
|
|
36
|
+
assert.match(html, /umds-select__placeholder[^>]*>(?:<!--[^>]*-->)*Marcadores</);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("com emptyOptionLabel e um valor escolhido o gatilho mostra a opção", async () => {
|
|
40
|
+
const html = await renderizar(Select, {
|
|
41
|
+
ariaLabel: "Marcadores",
|
|
42
|
+
placeholder: "Marcadores",
|
|
43
|
+
options: opcoes,
|
|
44
|
+
emptyOptionLabel: "Todos os marcadores",
|
|
45
|
+
value: "urgente",
|
|
46
|
+
});
|
|
47
|
+
assert.match(html, />Urgente</);
|
|
48
|
+
assert.doesNotMatch(html, /umds-select__placeholder/);
|
|
49
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stack e Box no Vue: raiz ÚNICA e o que o consumidor passa chega ao elemento.
|
|
3
|
+
*
|
|
4
|
+
* O defeito: o gerado tinha raiz em fragmento (um `<template v-if>` por tag) e
|
|
5
|
+
* só repassava uma lista fixa de atributos. `@click`, `@keydown`, `draggable`,
|
|
6
|
+
* `tabindex` e o `ref` do componente sumiam em silêncio. Aqui o componente é
|
|
7
|
+
* montado num DOM (jsdom) e o teste dispara o evento de verdade.
|
|
8
|
+
*/
|
|
9
|
+
import { test, after } from "node:test";
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
import { montar, janela, proximoTick } from "./dom.mjs";
|
|
12
|
+
|
|
13
|
+
const montados = [];
|
|
14
|
+
const abrir = async (...args) => {
|
|
15
|
+
const m = await montar(...args);
|
|
16
|
+
montados.push(m);
|
|
17
|
+
return m;
|
|
18
|
+
};
|
|
19
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
20
|
+
|
|
21
|
+
for (const [nome, caminho, classe] of [
|
|
22
|
+
["Stack", "Stack/Stack.vue", "umds-stack"],
|
|
23
|
+
["Box", "Box/Box.vue", "umds-box"],
|
|
24
|
+
]) {
|
|
25
|
+
for (const as of [undefined, "section", "ul"]) {
|
|
26
|
+
const rotulo = `${nome}${as ? ` as="${as}"` : ""}`;
|
|
27
|
+
const props = (extra = {}) => ({ ...(as ? { as } : {}), ...extra });
|
|
28
|
+
|
|
29
|
+
test(`${rotulo}: tem UM nó raiz, o elemento (sem fragmento)`, async () => {
|
|
30
|
+
const m = await abrir(caminho, props());
|
|
31
|
+
assert.equal(m.raiz.childNodes.length, 1);
|
|
32
|
+
const el = m.raiz.firstElementChild;
|
|
33
|
+
assert.equal(el.tagName.toLowerCase(), as || "div");
|
|
34
|
+
assert.ok(el.classList.contains(classe));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test(`${rotulo}: o ouvinte de clique chega ao elemento`, async () => {
|
|
38
|
+
let cliques = 0;
|
|
39
|
+
const m = await abrir(caminho, props({ onClick: () => cliques++ }));
|
|
40
|
+
m.raiz.firstElementChild.dispatchEvent(new janela.MouseEvent("click", { bubbles: true }));
|
|
41
|
+
assert.equal(cliques, 1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test(`${rotulo}: keydown, dragstart, drop, paste e mousedown chegam ao elemento`, async () => {
|
|
45
|
+
const vistos = [];
|
|
46
|
+
const m = await abrir(
|
|
47
|
+
caminho,
|
|
48
|
+
props({
|
|
49
|
+
onKeydown: () => vistos.push("keydown"),
|
|
50
|
+
onDragstart: () => vistos.push("dragstart"),
|
|
51
|
+
onDrop: () => vistos.push("drop"),
|
|
52
|
+
onPaste: () => vistos.push("paste"),
|
|
53
|
+
onMousedown: () => vistos.push("mousedown"),
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
const el = m.raiz.firstElementChild;
|
|
57
|
+
for (const tipo of ["keydown", "dragstart", "drop", "paste", "mousedown"]) {
|
|
58
|
+
el.dispatchEvent(new janela.Event(tipo, { bubbles: true }));
|
|
59
|
+
}
|
|
60
|
+
assert.deepEqual(vistos, ["keydown", "dragstart", "drop", "paste", "mousedown"]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test(`${rotulo}: tabindex, draggable, data-*, aria-*, title e role chegam ao elemento`, async () => {
|
|
64
|
+
const m = await abrir(
|
|
65
|
+
caminho,
|
|
66
|
+
props({ tabindex: "0", draggable: "true", "data-x": "1", "aria-label": "Região", title: "dica", role: "group" }),
|
|
67
|
+
);
|
|
68
|
+
const el = m.raiz.firstElementChild;
|
|
69
|
+
assert.equal(el.getAttribute("tabindex"), "0");
|
|
70
|
+
assert.equal(el.getAttribute("draggable"), "true");
|
|
71
|
+
assert.equal(el.getAttribute("data-x"), "1");
|
|
72
|
+
assert.equal(el.getAttribute("aria-label"), "Região");
|
|
73
|
+
assert.equal(el.getAttribute("title"), "dica");
|
|
74
|
+
assert.equal(el.getAttribute("role"), "group");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test(`${rotulo}: class e style do consumidor se somam aos do componente`, async () => {
|
|
78
|
+
const m = await abrir(caminho, props({ class: "minha", style: "margin-top: 4px", className: "outra" }));
|
|
79
|
+
const el = m.raiz.firstElementChild;
|
|
80
|
+
assert.ok(el.classList.contains(classe));
|
|
81
|
+
assert.ok(el.classList.contains("minha"));
|
|
82
|
+
assert.ok(el.classList.contains("outra"));
|
|
83
|
+
assert.match(el.getAttribute("style"), /margin-top:\s*4px/);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test(`${rotulo}: o ref do componente aponta para o elemento ($el)`, async () => {
|
|
87
|
+
const m = await abrir(caminho, props());
|
|
88
|
+
assert.equal(m.instancia.$el, m.raiz.firstElementChild);
|
|
89
|
+
assert.equal(m.instancia.$el.nodeType, 1);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test(`${rotulo}: o conteúdo padrão entra dentro do elemento`, async () => {
|
|
93
|
+
const m = await abrir(caminho, props(), { default: () => "conteúdo" });
|
|
94
|
+
assert.equal(m.raiz.firstElementChild.textContent, "conteúdo");
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
test(`${nome} as="ul" e as="ol" mantêm role="list", que o consumidor pode trocar`, async () => {
|
|
99
|
+
const ul = await abrir(caminho, { as: "ul" });
|
|
100
|
+
assert.equal(ul.raiz.firstElementChild.getAttribute("role"), "list");
|
|
101
|
+
const ol = await abrir(caminho, { as: "ol" });
|
|
102
|
+
assert.equal(ol.raiz.firstElementChild.getAttribute("role"), "list");
|
|
103
|
+
const outro = await abrir(caminho, { as: "ul", role: "menu" });
|
|
104
|
+
assert.equal(outro.raiz.firstElementChild.getAttribute("role"), "menu");
|
|
105
|
+
const div = await abrir(caminho, {});
|
|
106
|
+
assert.equal(div.raiz.firstElementChild.getAttribute("role"), null);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test(`${nome} as="form" chama onSubmit e o elemento é um form`, async () => {
|
|
110
|
+
let eventos = 0;
|
|
111
|
+
const m = await abrir(caminho, { as: "form", onSubmit: () => eventos++ });
|
|
112
|
+
const form = m.raiz.firstElementChild;
|
|
113
|
+
assert.equal(form.tagName, "FORM");
|
|
114
|
+
form.dispatchEvent(new janela.Event("submit", { bubbles: true, cancelable: true }));
|
|
115
|
+
assert.equal(eventos, 1);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test(`${nome}: v-show (display none) funciona na raiz`, async () => {
|
|
119
|
+
const { createApp, h, withDirectives, vShow, ref } = await import("vue");
|
|
120
|
+
const mod = await import(`./dom.mjs`);
|
|
121
|
+
const Comp = (await import(new URL(`../components/${caminho}`, import.meta.url).href)).default;
|
|
122
|
+
const visivel = ref(true);
|
|
123
|
+
const alvo = janela.document.createElement("div");
|
|
124
|
+
janela.document.body.append(alvo);
|
|
125
|
+
const app = createApp({ render: () => withDirectives(h(Comp), [[vShow, visivel.value]]) });
|
|
126
|
+
app.mount(alvo);
|
|
127
|
+
assert.notEqual(alvo.firstElementChild.style.display, "none");
|
|
128
|
+
visivel.value = false;
|
|
129
|
+
await proximoTick();
|
|
130
|
+
assert.equal(alvo.firstElementChild.style.display, "none");
|
|
131
|
+
app.unmount();
|
|
132
|
+
void mod;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stack (as, gap="none", props de item flex, atributos),
|
|
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 { abrir, fechar, carregar, renderizar } from "./renderizar.mjs";
|
|
8
|
+
|
|
9
|
+
let Stack;
|
|
10
|
+
|
|
11
|
+
before(async () => {
|
|
12
|
+
await abrir();
|
|
13
|
+
Stack = await carregar("Stack/Stack.vue");
|
|
14
|
+
});
|
|
15
|
+
after(fechar);
|
|
16
|
+
|
|
17
|
+
test("Stack sem props continua um div vertical com gap xxxs", async () => {
|
|
18
|
+
const html = await renderizar(Stack, {}, { default: "x" });
|
|
19
|
+
assert.match(html, /<div class="umds-stack umds-stack--vertical umds-stack--gap-xxxs"/);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("Stack aceita gap none", async () => {
|
|
23
|
+
const html = await renderizar(Stack, { gap: "none" }, { default: "x" });
|
|
24
|
+
assert.match(html, /umds-stack--gap-none/);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
for (const tag of ["div", "span", "ul", "ol", "li", "section", "nav", "header", "footer", "form"]) {
|
|
28
|
+
test(`Stack as="${tag}" renderiza <${tag}> e só ele`, async () => {
|
|
29
|
+
const html = await renderizar(Stack, { as: tag }, { default: "x" });
|
|
30
|
+
assert.match(html, new RegExp(`<${tag}[ >]`));
|
|
31
|
+
const outras = ["div", "span", "ul", "ol", "li", "section", "nav", "header", "footer", "form"].filter((t) => t !== tag);
|
|
32
|
+
for (const o of outras) assert.doesNotMatch(html, new RegExp(`<${o}[ >]`));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
test("Stack ul/ol mantém a semântica de lista (role=list)", async () => {
|
|
37
|
+
assert.match(await renderizar(Stack, { as: "ul" }, { default: "x" }), /<ul[^>]*role="list"/);
|
|
38
|
+
assert.match(await renderizar(Stack, { as: "ol" }, { default: "x" }), /<ol[^>]*role="list"/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("Stack repassa id, aria-label, title e style", async () => {
|
|
42
|
+
const html = await renderizar(
|
|
43
|
+
Stack,
|
|
44
|
+
{ as: "nav", id: "menu", "aria-label": "Principal", title: "Dica", style: "margin-top: 4px" },
|
|
45
|
+
{ default: "x" },
|
|
46
|
+
);
|
|
47
|
+
assert.match(html, /<nav/);
|
|
48
|
+
assert.match(html, /id="menu"/);
|
|
49
|
+
assert.match(html, /aria-label="Principal"/);
|
|
50
|
+
assert.match(html, /title="Dica"/);
|
|
51
|
+
assert.match(html, /margin-top:\s*4px/);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("Stack escreve as classes de item flex", async () => {
|
|
55
|
+
const html = await renderizar(
|
|
56
|
+
Stack,
|
|
57
|
+
{
|
|
58
|
+
grow: true,
|
|
59
|
+
shrink: "0",
|
|
60
|
+
basis: "50",
|
|
61
|
+
minWidth: "auto",
|
|
62
|
+
overflow: "hidden",
|
|
63
|
+
overflowY: "auto",
|
|
64
|
+
fullHeight: true,
|
|
65
|
+
},
|
|
66
|
+
{ default: "x" },
|
|
67
|
+
);
|
|
68
|
+
for (const c of [
|
|
69
|
+
"umds-stack--grow",
|
|
70
|
+
"umds-stack--shrink-0",
|
|
71
|
+
"umds-stack--basis-50",
|
|
72
|
+
"umds-stack--min-w-auto",
|
|
73
|
+
"umds-stack--overflow-hidden",
|
|
74
|
+
"umds-stack--overflow-y-auto",
|
|
75
|
+
"umds-stack--full-height",
|
|
76
|
+
]) {
|
|
77
|
+
assert.ok(html.includes(c), `faltou ${c} em ${html}`);
|
|
78
|
+
}
|
|
79
|
+
assert.doesNotMatch(html, /full-width/);
|
|
80
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** StatCard: labelPosition e infoTooltip, 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 StatCard;
|
|
7
|
+
|
|
8
|
+
before(async () => {
|
|
9
|
+
await abrir();
|
|
10
|
+
StatCard = await carregar("StatCard/StatCard.vue");
|
|
11
|
+
});
|
|
12
|
+
after(fechar);
|
|
13
|
+
|
|
14
|
+
test("labelPosition top escreve a classe; sem a prop não", async () => {
|
|
15
|
+
assert.match(await renderizar(StatCard, { value: 44, label: "Não lidos", labelPosition: "top" }), /umds-stat-card--rotulo-topo/);
|
|
16
|
+
assert.doesNotMatch(await renderizar(StatCard, { value: 44, label: "Não lidos" }), /umds-stat-card--rotulo-topo/);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("o número vem antes do rótulo no HTML", async () => {
|
|
20
|
+
const html = await renderizar(StatCard, { value: 44, label: "Não lidos", labelPosition: "top" });
|
|
21
|
+
assert.ok(html.indexOf("umds-stat-card__valor") < html.indexOf("umds-stat-card__rotulo"));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("infoTooltip escreve o ⓘ como botão nomeado; infoLabel traduz", async () => {
|
|
25
|
+
const html = await renderizar(StatCard, { value: 1, label: "Não lidos", infoTooltip: "Ainda não abertos." });
|
|
26
|
+
assert.match(html, /<button[^>]*umds-stat-card__info/);
|
|
27
|
+
assert.match(html, /aria-label="Mais informações"/);
|
|
28
|
+
assert.match(html, /Ainda não abertos\./);
|
|
29
|
+
assert.match(await renderizar(StatCard, { value: 1, label: "Unread", infoTooltip: "x", infoLabel: "More info" }), /aria-label="More info"/);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("sem infoTooltip não há botão", async () => {
|
|
33
|
+
assert.doesNotMatch(await renderizar(StatCard, { value: 1, label: "x" }), /<button/);
|
|
34
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** StatCard: segunda medida e valueTone no Vue (DOM do jsdom). */
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { montar } from "./dom.mjs";
|
|
5
|
+
|
|
6
|
+
const montados = [];
|
|
7
|
+
const abrir = async (props) => {
|
|
8
|
+
const m = await montar("StatCard/StatCard.vue", props);
|
|
9
|
+
montados.push(m);
|
|
10
|
+
return m;
|
|
11
|
+
};
|
|
12
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
13
|
+
|
|
14
|
+
test("secondaryValue e secondaryLabel vêm depois do corpo, e o número principal segue antes do rótulo", async () => {
|
|
15
|
+
const m = await abrir({ value: "22,31%", label: "Eficiência", description: "Meu Setor", secondaryValue: "14,11%", secondaryLabel: "Geral", labelPosition: "top" });
|
|
16
|
+
const raiz = m.raiz.querySelector(".umds-stat-card");
|
|
17
|
+
assert.ok(raiz.classList.contains("umds-stat-card--com-secundaria"));
|
|
18
|
+
assert.equal(raiz.lastElementChild.className, "umds-stat-card__secundaria");
|
|
19
|
+
assert.equal(raiz.querySelector(".umds-stat-card__valor-secundario").textContent.trim(), "14,11%");
|
|
20
|
+
assert.equal(raiz.querySelector(".umds-stat-card__rotulo-secundario").textContent.trim(), "Geral");
|
|
21
|
+
const texto = raiz.textContent;
|
|
22
|
+
assert.ok(texto.indexOf("22,31%") < texto.indexOf("Eficiência"));
|
|
23
|
+
assert.ok(texto.indexOf("Eficiência") < texto.indexOf("14,11%"));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("secondaryValue 0 aparece; vazio e ausente não", async () => {
|
|
27
|
+
const zero = await abrir({ value: "5", label: "x", secondaryValue: 0 });
|
|
28
|
+
assert.equal(zero.raiz.querySelector(".umds-stat-card__valor-secundario").textContent.trim(), "0");
|
|
29
|
+
const vazio = await abrir({ value: "5", label: "x", secondaryValue: "" });
|
|
30
|
+
assert.equal(vazio.raiz.querySelector(".umds-stat-card__secundaria"), null);
|
|
31
|
+
const sem = await abrir({ value: "5", label: "x" });
|
|
32
|
+
assert.equal(sem.raiz.querySelector(".umds-stat-card__secundaria"), null);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("valueTone escreve a classe do tom; default e ausente não; a variant do ícone fica", async () => {
|
|
36
|
+
const n = await abrir({ value: "5", label: "x", valueTone: "negative", variant: "positive" });
|
|
37
|
+
const c = n.raiz.querySelector(".umds-stat-card").classList;
|
|
38
|
+
assert.ok(c.contains("umds-stat-card--valor-negative") && c.contains("umds-stat-card--positive"));
|
|
39
|
+
const d = await abrir({ value: "5", label: "x", valueTone: "default" });
|
|
40
|
+
assert.doesNotMatch(d.raiz.querySelector(".umds-stat-card").className, /valor-/);
|
|
41
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Tab (count, closable) e Tabs (onAdd), 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 { h } from "vue";
|
|
5
|
+
import { abrir, fechar, carregar, renderizar } from "./renderizar.mjs";
|
|
6
|
+
|
|
7
|
+
let Tabs, Tab;
|
|
8
|
+
|
|
9
|
+
before(async () => {
|
|
10
|
+
await abrir();
|
|
11
|
+
Tabs = await carregar("Tabs/Tabs.vue");
|
|
12
|
+
Tab = await carregar("Tabs/Tab.vue");
|
|
13
|
+
});
|
|
14
|
+
after(fechar);
|
|
15
|
+
|
|
16
|
+
/** Tabs com as abas dadas como filhas (cada uma é `[props]`). */
|
|
17
|
+
const comAbas = (propsDoTabs, abas) =>
|
|
18
|
+
renderizar(Tabs, propsDoTabs, { default: () => abas.map((p) => h(Tab, p)) });
|
|
19
|
+
|
|
20
|
+
test("count escreve a pílula; o 0 aparece; sem count não há pílula", async () => {
|
|
21
|
+
const html = await comAbas({ value: "0" }, [
|
|
22
|
+
{ label: "Todas", index: "0", count: 31 },
|
|
23
|
+
{ label: "Concluídas", index: "1", count: 0 },
|
|
24
|
+
{ label: "Sem", index: "2" },
|
|
25
|
+
]);
|
|
26
|
+
assert.equal((html.match(/umds-tabs__count/g) || []).length, 2);
|
|
27
|
+
assert.match(html, /umds-tabs__count[^>]*>31</);
|
|
28
|
+
assert.match(html, /umds-tabs__count[^>]*>0</);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("closable escreve o × como botão próprio com o nome 'Fechar <aba>'", async () => {
|
|
32
|
+
const html = await comAbas({ value: "0" }, [{ label: "Documento 1", index: "0", closable: true }]);
|
|
33
|
+
assert.match(html, /umds-tabs__close/);
|
|
34
|
+
assert.match(html, /aria-label="Fechar Documento 1"/);
|
|
35
|
+
// o × não está dentro do botão da aba (sem botão aninhado)
|
|
36
|
+
assert.doesNotMatch(html, /role="tab"[^>]*>(?:(?!<\/button>).)*umds-tabs__close/s);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("closeLabel traduz o nome do ×", async () => {
|
|
40
|
+
const html = await comAbas({ value: "0" }, [{ label: "Doc 1", index: "0", closable: true, closeLabel: "Close" }]);
|
|
41
|
+
assert.match(html, /aria-label="Close Doc 1"/);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("sem closable não há ×", async () => {
|
|
45
|
+
const html = await comAbas({ value: "0" }, [{ label: "Fixa", index: "0" }]);
|
|
46
|
+
assert.doesNotMatch(html, /umds-tabs__close/);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("onAdd escreve o + fora do tablist; addLabel traduz", async () => {
|
|
50
|
+
const html = await comAbas({ value: "0", onAdd: () => {}, addLabel: "New tab" }, [{ label: "A", index: "0" }]);
|
|
51
|
+
assert.match(html, /umds-tabs__add/);
|
|
52
|
+
assert.match(html, /aria-label="New tab"/);
|
|
53
|
+
const lista = html.match(/role="tablist"[\s\S]*?<\/div><button[^>]*umds-tabs__add/);
|
|
54
|
+
assert.ok(lista, "o + vem depois do fechamento do tablist");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("sem onAdd não há +", async () => {
|
|
58
|
+
const html = await comAbas({ value: "0" }, [{ label: "A", index: "0" }]);
|
|
59
|
+
assert.doesNotMatch(html, /umds-tabs__add/);
|
|
60
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Toast com ação e detalhes no Vue (DOM do jsdom; o Toast vai por Teleport para o body). */
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { montar, documento, clicar, proximoTick } from "./dom.mjs";
|
|
5
|
+
|
|
6
|
+
const montados = [];
|
|
7
|
+
const abrir = async (props) => {
|
|
8
|
+
const m = await montar("Toast/Toast.vue", props);
|
|
9
|
+
montados.push(m);
|
|
10
|
+
await proximoTick();
|
|
11
|
+
return m;
|
|
12
|
+
};
|
|
13
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
14
|
+
|
|
15
|
+
const botao = (nome) => [...documento.querySelectorAll(".umds-toast button")].find((b) => b.textContent.trim() === nome || b.getAttribute("aria-label") === nome);
|
|
16
|
+
|
|
17
|
+
test("actionLabel com onAction desenha o botão; acionar chama onAction e depois fecha", async () => {
|
|
18
|
+
const ordem = [];
|
|
19
|
+
const m = await abrir({ open: true, message: "Despacho enviado", actionLabel: "Desfazer", onAction: () => ordem.push("acao"), onClose: () => ordem.push("fechar") });
|
|
20
|
+
await clicar(botao("Desfazer"));
|
|
21
|
+
assert.deepEqual(ordem, ["acao", "fechar"]);
|
|
22
|
+
m.desmontar();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("sem onAction (ou sem actionLabel) não há botão de ação", async () => {
|
|
26
|
+
const a = await abrir({ open: true, message: "x", actionLabel: "Desfazer" });
|
|
27
|
+
assert.equal(documento.querySelector(".umds-toast__action"), null);
|
|
28
|
+
a.desmontar();
|
|
29
|
+
const b = await abrir({ open: true, message: "x", onAction: () => {} });
|
|
30
|
+
assert.equal(documento.querySelector(".umds-toast__action"), null);
|
|
31
|
+
b.desmontar();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("details vira uma lista de linhas; sem details não há lista", async () => {
|
|
35
|
+
const m = await abrir({ open: true, message: "3 anexos não enviados", details: ["Anexo 1 acima de 10 MB", "Anexo 2 sem assunto"] });
|
|
36
|
+
const itens = [...documento.querySelectorAll(".umds-toast__details li")].map((l) => l.textContent.trim());
|
|
37
|
+
assert.deepEqual(itens, ["Anexo 1 acima de 10 MB", "Anexo 2 sem assunto"]);
|
|
38
|
+
m.desmontar();
|
|
39
|
+
const sem = await abrir({ open: true, message: "Salvo" });
|
|
40
|
+
assert.equal(documento.querySelector(".umds-toast__details"), null);
|
|
41
|
+
sem.desmontar();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("o botão de fechar continua ao lado da ação", async () => {
|
|
45
|
+
const m = await abrir({ open: true, message: "x", actionLabel: "Desfazer", onAction: () => {} });
|
|
46
|
+
assert.ok(botao("Fechar notificação"));
|
|
47
|
+
m.desmontar();
|
|
48
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tooltip variant dark e maxWidth no Vue GERADO. A bolha vive num Portal e só
|
|
3
|
+
* monta no navegador, então o SSR não a mostra: o que dá para conferir aqui é
|
|
4
|
+
* que o componente declara as props novas e que renderiza com elas sem quebrar.
|
|
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 Tooltip;
|
|
11
|
+
|
|
12
|
+
before(async () => {
|
|
13
|
+
await abrir();
|
|
14
|
+
Tooltip = await carregar("Tooltip/Tooltip.vue");
|
|
15
|
+
});
|
|
16
|
+
after(fechar);
|
|
17
|
+
|
|
18
|
+
test("declara variant e maxWidth", () => {
|
|
19
|
+
const props = Object.keys(Tooltip.props || {});
|
|
20
|
+
assert.ok(props.includes("variant"), "variant");
|
|
21
|
+
assert.ok(props.includes("maxWidth"), "maxWidth");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("renderiza com variant dark e maxWidth, e a descrição acessível continua no DOM", async () => {
|
|
25
|
+
const html = await renderizar(Tooltip, { content: "Atualizar", variant: "dark", maxWidth: "140px" }, { default: "<button>Atualizar</button>" });
|
|
26
|
+
assert.match(html, /umds-tooltip__descricao/);
|
|
27
|
+
assert.match(html, /Atualizar/);
|
|
28
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Datas do `Calendar`, em ISO local (`YYYY-MM-DD`) e sem biblioteca.
|
|
3
|
+
*
|
|
4
|
+
* Tudo aqui trabalha com o DIA como texto: `"2026-05-15"`. O `Date` só aparece
|
|
5
|
+
* por dentro, sempre à meia-noite LOCAL (`new Date(ano, mes, dia)`), nunca
|
|
6
|
+
* `new Date("2026-05-15")`, que o JavaScript lê como UTC e, no fuso do Brasil,
|
|
7
|
+
* devolve o dia anterior.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const doisDigitos = (n: number): string => n < 10 ? "0" + n : String(n);
|
|
11
|
+
|
|
12
|
+
/** `Date` local → `YYYY-MM-DD`. */
|
|
13
|
+
export const toIso = (data: Date): string => data.getFullYear() + "-" + doisDigitos(data.getMonth() + 1) + "-" + doisDigitos(data.getDate());
|
|
14
|
+
|
|
15
|
+
/** `YYYY-MM-DD` → `Date` à meia-noite local. */
|
|
16
|
+
export const parseIso = (iso: string): Date => {
|
|
17
|
+
const partes = iso.slice(0, 10).split("-");
|
|
18
|
+
return new Date(Number(partes[0]), Number(partes[1]) - 1, Number(partes[2]));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Aceita `Date` ou texto (`2026-05-15` e `2026-05-15T10:00`) e devolve `YYYY-MM-DD`; "" se não der. */
|
|
22
|
+
export const normalizeIso = (valor: any): string => {
|
|
23
|
+
if (!valor) return "";
|
|
24
|
+
if (typeof valor === "string") return /^\d{4}-\d{2}-\d{2}/.test(valor) ? valor.slice(0, 10) : "";
|
|
25
|
+
if (valor instanceof Date && !isNaN(valor.getTime())) return toIso(valor);
|
|
26
|
+
return "";
|
|
27
|
+
};
|
|
28
|
+
export const addDays = (iso: string, dias: number): string => {
|
|
29
|
+
const data = parseIso(iso);
|
|
30
|
+
data.setDate(data.getDate() + dias);
|
|
31
|
+
return toIso(data);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Soma meses mantendo o dia, ou o último dia do mês de chegada (31/01 + 1 mês = 28/02). */
|
|
35
|
+
export const addMonths = (iso: string, meses: number): string => {
|
|
36
|
+
const data = parseIso(iso);
|
|
37
|
+
const dia = data.getDate();
|
|
38
|
+
data.setDate(1);
|
|
39
|
+
data.setMonth(data.getMonth() + meses);
|
|
40
|
+
const ultimo = new Date(data.getFullYear(), data.getMonth() + 1, 0).getDate();
|
|
41
|
+
data.setDate(Math.min(dia, ultimo));
|
|
42
|
+
return toIso(data);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Dia da semana: 0 = domingo. */
|
|
46
|
+
export const weekdayOf = (iso: string): number => parseIso(iso).getDay();
|
|
47
|
+
|
|
48
|
+
/** Primeiro dia da semana que contém `iso`, dado o dia em que a semana começa (0 = domingo, 1 = segunda). */
|
|
49
|
+
export const startOfWeek = (iso: string, comecaEm: number): string => {
|
|
50
|
+
const recuo = (weekdayOf(iso) - comecaEm + 7) % 7;
|
|
51
|
+
return addDays(iso, -recuo);
|
|
52
|
+
};
|
|
53
|
+
export const startOfMonth = (iso: string): string => iso.slice(0, 8) + "01";
|
|
54
|
+
export const endOfMonth = (iso: string): string => {
|
|
55
|
+
const data = parseIso(iso);
|
|
56
|
+
return toIso(new Date(data.getFullYear(), data.getMonth() + 1, 0));
|
|
57
|
+
};
|
|
58
|
+
export const isSameMonth = (a: string, b: string): boolean => a.slice(0, 7) === b.slice(0, 7);
|
|
59
|
+
|
|
60
|
+
/** Os sete dias da semana que contém `iso`. */
|
|
61
|
+
export const weekDays = (iso: string, comecaEm: number): string[] => {
|
|
62
|
+
const inicio = startOfWeek(iso, comecaEm);
|
|
63
|
+
const dias: string[] = [];
|
|
64
|
+
for (let i = 0; i < 7; i++) dias.push(addDays(inicio, i));
|
|
65
|
+
return dias;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** O mês de `iso` em semanas inteiras (de 4 a 6 linhas), com os dias dos meses vizinhos que completam as pontas. */
|
|
69
|
+
export const monthMatrix = (iso: string, comecaEm: number): string[][] => {
|
|
70
|
+
const ultimo = endOfMonth(iso);
|
|
71
|
+
let cursor = startOfWeek(startOfMonth(iso), comecaEm);
|
|
72
|
+
const semanas: string[][] = [];
|
|
73
|
+
while (cursor <= ultimo) {
|
|
74
|
+
semanas.push(weekDays(cursor, comecaEm));
|
|
75
|
+
cursor = addDays(cursor, 7);
|
|
76
|
+
}
|
|
77
|
+
return semanas;
|
|
78
|
+
}
|