@1doc/1ds-vue 2.9.0 → 2.11.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 +653 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +164 -10
- package/dist/index.mjs +9734 -8309
- package/dist/index.umd.js +4 -4
- package/package.json +3 -3
- package/src/teste/accordion-controlado.test.mjs +75 -0
- package/src/teste/accordion-titulo-neutro.test.mjs +32 -0
- package/src/teste/appsubheader-regiao.test.mjs +18 -0
- package/src/teste/attachmentcard-lista.test.mjs +39 -0
- package/src/teste/attachmentcard-sm.test.mjs +28 -0
- package/src/teste/badge-attached-tom-padding.test.mjs +49 -0
- package/src/teste/badge-neutro-colado.test.mjs +30 -0
- package/src/teste/badge-tag.test.mjs +8 -0
- package/src/teste/button-densidade.test.mjs +33 -0
- package/src/teste/calendar-compacto.test.mjs +37 -0
- package/src/teste/calendar-slots-cabecalho.test.mjs +46 -0
- package/src/teste/coachmark-sem-veu.test.mjs +70 -0
- package/src/teste/coachmark-um-passo.test.mjs +47 -0
- package/src/teste/color-picker-xs.test.mjs +28 -0
- package/src/teste/datatable-arvore-variantes.test.mjs +194 -0
- package/src/teste/datatable-compacta-tom.test.mjs +70 -0
- package/src/teste/descriptionlist-compacta.test.mjs +32 -0
- package/src/teste/dom.mjs +2 -0
- package/src/teste/empty-state-titulo-rico.test.mjs +39 -0
- package/src/teste/input-agrupado.test.mjs +44 -0
- package/src/teste/input-ghost.test.mjs +37 -0
- package/src/teste/list-item-standalone.test.mjs +75 -0
- package/src/teste/list.test.mjs +2 -1
- package/src/teste/modal-proporcoes-1doc.test.mjs +38 -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/segmented-contador.test.mjs +39 -0
- package/src/teste/segmented-superficie.test.mjs +40 -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-item-com-escopo.test.mjs +68 -0
- package/src/teste/select-lista-filtro.test.mjs +112 -0
- package/src/teste/statcard-secundaria-tom.test.mjs +41 -0
- package/src/teste/statcard-tamanho-sm.test.mjs +34 -0
- package/src/teste/tabs-compacta-css.test.mjs +23 -0
- package/src/teste/tabs-compacta.test.mjs +27 -0
- package/src/teste/tag-positivo-tingido.test.mjs +56 -0
- package/src/teste/toast-acao-detalhes.test.mjs +48 -0
- package/src/teste/token-primary-lighter.test.mjs +48 -0
- package/src/utils/html-seguro.ts +105 -2
- package/src/utils/toast.ts +12 -2
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RichTextEditor no Vue: alinhamento, imagem e tabela (DOM do jsdom). O jsdom não
|
|
3
|
+
* traz `execCommand`: o teste usa um espião e confere o que o editor pede.
|
|
4
|
+
*/
|
|
5
|
+
import { test, after, beforeEach } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { montar, documento, janela, clicar, digitar, proximoTick } from "./dom.mjs";
|
|
8
|
+
|
|
9
|
+
let chamadas;
|
|
10
|
+
let estados;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
chamadas = [];
|
|
13
|
+
estados = {};
|
|
14
|
+
documento.execCommand = (...args) => {
|
|
15
|
+
chamadas.push(args);
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
documento.queryCommandState = (c) => !!estados[c];
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const montados = [];
|
|
22
|
+
const abrir = async (props = {}) => {
|
|
23
|
+
const m = await montar("RichTextEditor/RichTextEditor.vue", { ariaLabel: "Despacho", ...props });
|
|
24
|
+
montados.push(m);
|
|
25
|
+
await proximoTick();
|
|
26
|
+
return m;
|
|
27
|
+
};
|
|
28
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
29
|
+
|
|
30
|
+
const area = (m) => m.raiz.querySelector('[role="textbox"]');
|
|
31
|
+
const botao = (m, nome) => [...m.raiz.querySelectorAll("button")].find((b) => b.getAttribute("aria-label") === nome || b.textContent.trim() === nome);
|
|
32
|
+
const campo = (m, rotulo) => {
|
|
33
|
+
const label = [...m.raiz.querySelectorAll("label")].find((l) => l.textContent.trim().startsWith(rotulo));
|
|
34
|
+
return label ? m.raiz.querySelector(`#${label.getAttribute("for")}`) : null;
|
|
35
|
+
};
|
|
36
|
+
const PNG = "data:image/png;base64,iVBORw0KGgo=";
|
|
37
|
+
|
|
38
|
+
test("as quatro ferramentas de alinhamento pedem o comando e seguem o cursor", async () => {
|
|
39
|
+
const m = await abrir({ toolbar: ["alignLeft", "alignCenter", "alignRight", "alignJustify"], defaultValue: "<p>x</p>" });
|
|
40
|
+
const esperado = {
|
|
41
|
+
"Alinhar à esquerda": "justifyLeft",
|
|
42
|
+
Centralizar: "justifyCenter",
|
|
43
|
+
"Alinhar à direita": "justifyRight",
|
|
44
|
+
Justificar: "justifyFull",
|
|
45
|
+
};
|
|
46
|
+
for (const [nome, comando] of Object.entries(esperado)) {
|
|
47
|
+
chamadas.length = 0;
|
|
48
|
+
await clicar(botao(m, nome));
|
|
49
|
+
assert.deepEqual(chamadas[0], [comando, false, undefined], nome);
|
|
50
|
+
}
|
|
51
|
+
estados.justifyCenter = true;
|
|
52
|
+
const faixa = documento.createRange();
|
|
53
|
+
faixa.selectNodeContents(area(m));
|
|
54
|
+
janela.getSelection().removeAllRanges();
|
|
55
|
+
janela.getSelection().addRange(faixa);
|
|
56
|
+
documento.dispatchEvent(new janela.Event("selectionchange"));
|
|
57
|
+
await proximoTick();
|
|
58
|
+
assert.equal(botao(m, "Centralizar").getAttribute("aria-pressed"), "true");
|
|
59
|
+
assert.equal(botao(m, "Justificar").getAttribute("aria-pressed"), "false");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("a barra padrão não ganha as ferramentas novas", async () => {
|
|
63
|
+
const m = await abrir();
|
|
64
|
+
for (const nome of ["Centralizar", "Imagem", "Tabela"]) assert.equal(botao(m, nome), undefined, nome);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("o valor com text-align, imagem e tabela passa pela higienização", async () => {
|
|
68
|
+
const m = await abrir({
|
|
69
|
+
defaultValue: `<p style="text-align: center; color: red">a</p><img src="${PNG}" alt="x" onerror="y()"><img src="javascript:alert(1)"><table><tbody><tr><td colspan="2">c</td></tr></tbody></table>`,
|
|
70
|
+
});
|
|
71
|
+
const html = area(m).innerHTML;
|
|
72
|
+
assert.ok(html.includes('<p style="text-align: center;">a</p>'));
|
|
73
|
+
assert.ok(html.includes(`<img src="${PNG}" alt="x">`));
|
|
74
|
+
assert.doesNotMatch(html, /javascript|onerror|color/);
|
|
75
|
+
assert.ok(html.includes('<td colspan="2">c</td>'));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("imagem: o painel abre, o endereço vira img com alt, o perigoso dá erro", async () => {
|
|
79
|
+
const vistos = [];
|
|
80
|
+
const m = await abrir({ toolbar: ["image"], defaultValue: "<p>t</p>", onChange: (h) => vistos.push(h) });
|
|
81
|
+
await clicar(botao(m, "Imagem"));
|
|
82
|
+
const url = campo(m, "Endereço da imagem");
|
|
83
|
+
assert.ok(url, "campo do endereço");
|
|
84
|
+
await digitar(url, "javascript:alert(1)");
|
|
85
|
+
await clicar(botao(m, "Inserir imagem"));
|
|
86
|
+
assert.match(m.raiz.textContent, /Use um endereço http ou https/);
|
|
87
|
+
assert.equal(chamadas.length, 0);
|
|
88
|
+
|
|
89
|
+
await digitar(campo(m, "Endereço da imagem"), "exemplo.com.br/brasao.png");
|
|
90
|
+
await digitar(campo(m, "Texto alternativo"), "Brasão");
|
|
91
|
+
await clicar(botao(m, "Inserir imagem"));
|
|
92
|
+
assert.deepEqual(chamadas.at(-1), ["insertHTML", false, '<img src="https://exemplo.com.br/brasao.png" alt="Brasão">']);
|
|
93
|
+
assert.equal(campo(m, "Endereço da imagem"), null, "o painel fecha");
|
|
94
|
+
assert.ok(vistos.length > 0);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("imagem: arquivo vira data URL; tipo e tamanho inválidos são recusados", async () => {
|
|
98
|
+
const m = await abrir({ toolbar: ["image"] });
|
|
99
|
+
await clicar(botao(m, "Imagem"));
|
|
100
|
+
const entrada = m.raiz.querySelector('input[type="file"]');
|
|
101
|
+
const mandar = async (arquivo) => {
|
|
102
|
+
Object.defineProperty(entrada, "files", { value: [arquivo], configurable: true });
|
|
103
|
+
entrada.dispatchEvent(new janela.Event("change", { bubbles: true }));
|
|
104
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
105
|
+
await proximoTick();
|
|
106
|
+
};
|
|
107
|
+
await mandar(new janela.File(["x"], "a.svg", { type: "image/svg+xml" }));
|
|
108
|
+
assert.match(m.raiz.textContent, /Use uma imagem PNG, JPEG, GIF ou WebP/);
|
|
109
|
+
const grande = new janela.File(["x"], "g.png", { type: "image/png" });
|
|
110
|
+
Object.defineProperty(grande, "size", { value: 3 * 1024 * 1024 });
|
|
111
|
+
await mandar(grande);
|
|
112
|
+
assert.match(m.raiz.textContent, /A imagem passa de 2 MB/);
|
|
113
|
+
await mandar(new janela.File([new Uint8Array([137, 80, 78, 71])], "brasao.png", { type: "image/png" }));
|
|
114
|
+
assert.match(m.raiz.textContent, /brasao\.png/);
|
|
115
|
+
await clicar(botao(m, "Inserir imagem"));
|
|
116
|
+
assert.match(chamadas.at(-1)[2], /^<img src="data:image\/png;base64,[A-Za-z0-9+/=]+" alt="">$/);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("tabela: o painel insere linhas × colunas; fora do limite dá erro", async () => {
|
|
120
|
+
const m = await abrir({ toolbar: ["table"] });
|
|
121
|
+
await clicar(botao(m, "Tabela"));
|
|
122
|
+
await digitar(campo(m, "Colunas"), "11");
|
|
123
|
+
await clicar(botao(m, "Inserir tabela"));
|
|
124
|
+
assert.match(m.raiz.textContent, /Use de 1 a 20 linhas e de 1 a 10 colunas/);
|
|
125
|
+
assert.equal(chamadas.length, 0);
|
|
126
|
+
await digitar(campo(m, "Colunas"), "2");
|
|
127
|
+
await digitar(campo(m, "Linhas"), "4");
|
|
128
|
+
await clicar(botao(m, "Inserir tabela"));
|
|
129
|
+
const html = chamadas.at(-1)[2];
|
|
130
|
+
assert.equal((html.match(/<tr>/g) || []).length, 4);
|
|
131
|
+
assert.equal((html.match(/<td><br><\/td>/g) || []).length, 8);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("tabela: com o cursor numa célula a barra adiciona e remove linha e coluna", async () => {
|
|
135
|
+
const m = await abrir({
|
|
136
|
+
toolbar: ["table"],
|
|
137
|
+
defaultValue: "<table><tbody><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>d</td></tr></tbody></table>",
|
|
138
|
+
});
|
|
139
|
+
const cursor = async (i) => {
|
|
140
|
+
const faixa = documento.createRange();
|
|
141
|
+
faixa.selectNodeContents(area(m).querySelectorAll("td")[i]);
|
|
142
|
+
janela.getSelection().removeAllRanges();
|
|
143
|
+
janela.getSelection().addRange(faixa);
|
|
144
|
+
documento.dispatchEvent(new janela.Event("selectionchange"));
|
|
145
|
+
await proximoTick();
|
|
146
|
+
};
|
|
147
|
+
assert.equal(m.raiz.querySelector('[role="group"]'), null);
|
|
148
|
+
await cursor(0);
|
|
149
|
+
assert.ok(m.raiz.querySelector('[role="group"]'), "a barra aparece");
|
|
150
|
+
await clicar(botao(m, "Adicionar coluna"));
|
|
151
|
+
assert.equal(area(m).querySelectorAll("tr")[0].cells.length, 3);
|
|
152
|
+
await cursor(0);
|
|
153
|
+
await clicar(botao(m, "Adicionar linha"));
|
|
154
|
+
assert.equal(area(m).querySelectorAll("tr").length, 3);
|
|
155
|
+
await cursor(0);
|
|
156
|
+
await clicar(botao(m, "Remover linha"));
|
|
157
|
+
assert.equal(area(m).querySelectorAll("tr").length, 2);
|
|
158
|
+
await cursor(0);
|
|
159
|
+
await clicar(botao(m, "Remover coluna"));
|
|
160
|
+
assert.equal(area(m).querySelectorAll("tr")[0].cells.length, 2);
|
|
161
|
+
await cursor(0);
|
|
162
|
+
await clicar(botao(m, "Remover tabela"));
|
|
163
|
+
assert.equal(area(m).querySelector("table"), null);
|
|
164
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** RichTextEditor: fonte, tamanho e cor do texto por token, no Vue (DOM do jsdom). */
|
|
2
|
+
import { test, after, beforeEach } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { montar, documento, janela, clicar, proximoTick } from "./dom.mjs";
|
|
5
|
+
|
|
6
|
+
let chamadas;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
chamadas = [];
|
|
9
|
+
documento.execCommand = (...args) => {
|
|
10
|
+
chamadas.push(args);
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
13
|
+
documento.queryCommandState = () => false;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const montados = [];
|
|
17
|
+
const abrir = async (props = {}) => {
|
|
18
|
+
const m = await montar("RichTextEditor/RichTextEditor.vue", { ariaLabel: "Despacho", defaultValue: "<p>Parecer</p>", ...props });
|
|
19
|
+
montados.push(m);
|
|
20
|
+
await proximoTick();
|
|
21
|
+
return m;
|
|
22
|
+
};
|
|
23
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
24
|
+
|
|
25
|
+
const area = (m) => m.raiz.querySelector('[role="textbox"]');
|
|
26
|
+
const botao = (m, nome) => [...m.raiz.querySelectorAll("button")].find((b) => b.getAttribute("aria-label") === nome || b.textContent.trim() === nome);
|
|
27
|
+
const selecionar = (m) => {
|
|
28
|
+
const texto = area(m).querySelector("p").firstChild;
|
|
29
|
+
const faixa = documento.createRange();
|
|
30
|
+
faixa.setStart(texto, 0);
|
|
31
|
+
faixa.setEnd(texto, texto.length);
|
|
32
|
+
janela.getSelection().removeAllRanges();
|
|
33
|
+
janela.getSelection().addRange(faixa);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
test("a barra padrão não ganha as ferramentas novas", async () => {
|
|
37
|
+
const m = await abrir();
|
|
38
|
+
for (const nome of ["Fonte", "Tamanho da fonte", "Cor do texto"]) assert.equal(botao(m, nome), undefined, nome);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("o valor volta higienizado: só token do DS passa no style do span", async () => {
|
|
42
|
+
const m = await abrir({ defaultValue: '<p><span style="color: var(--umds-primitive-blue-pure); background: red; font-size: 40px">a</span><b style="color: var(--umds-primitive-red-pure)">b</b></p>' });
|
|
43
|
+
assert.equal(area(m).innerHTML, '<p><span style="color: var(--umds-primitive-blue-pure);">a</span><b>b</b></p>');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("cada ferramenta abre um painel nomeado; Fechar fecha", async () => {
|
|
47
|
+
const m = await abrir({ toolbar: ["fontFamily", "fontSize", "textColor"] });
|
|
48
|
+
await clicar(botao(m, "Tamanho da fonte"));
|
|
49
|
+
assert.equal(m.raiz.querySelector('[role="group"]').getAttribute("aria-label"), "Tamanho da fonte");
|
|
50
|
+
await clicar(botao(m, "Fechar"));
|
|
51
|
+
assert.equal(m.raiz.querySelector('[role="group"]'), null);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("a fonte monoespaçada embrulha o texto selecionado num span com o token", async () => {
|
|
55
|
+
const m = await abrir({ toolbar: ["fontFamily"] });
|
|
56
|
+
selecionar(m);
|
|
57
|
+
await clicar(botao(m, "Fonte"));
|
|
58
|
+
await clicar(m.raiz.querySelector('[role="combobox"]'));
|
|
59
|
+
const mono = [...m.raiz.querySelectorAll('[role="option"]')].find((o) => o.textContent.includes("Monoespaçada"));
|
|
60
|
+
await clicar(mono);
|
|
61
|
+
assert.deepEqual(chamadas.at(-1), ["insertHTML", false, '<span style="font-family: var(--umds-semantic-font-family-mono);">Parecer</span>']);
|
|
62
|
+
assert.equal(m.raiz.querySelector('[role="group"]'), null, "o painel fecha");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("o tamanho usa os degraus 12, 14, 16, 20 e 24", async () => {
|
|
66
|
+
const m = await abrir({ toolbar: ["fontSize"] });
|
|
67
|
+
selecionar(m);
|
|
68
|
+
await clicar(botao(m, "Tamanho da fonte"));
|
|
69
|
+
await clicar(m.raiz.querySelector('[role="combobox"]'));
|
|
70
|
+
const opcoes = [...m.raiz.querySelectorAll('[role="option"]')];
|
|
71
|
+
assert.deepEqual(opcoes.map((o) => o.textContent.trim()), ["12", "14", "16", "20", "24"]);
|
|
72
|
+
await clicar(opcoes[3]);
|
|
73
|
+
assert.deepEqual(chamadas.at(-1), ["insertHTML", false, '<span style="font-size: var(--umds-primitive-font-size-sm);">Parecer</span>']);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("a cor vem da paleta do DS e vira var() do token; sem seleção pede a seleção", async () => {
|
|
77
|
+
const m = await abrir({ toolbar: ["textColor"] });
|
|
78
|
+
janela.getSelection().removeAllRanges();
|
|
79
|
+
await clicar(botao(m, "Cor do texto"));
|
|
80
|
+
const vermelho = () => m.raiz.querySelector('[role="radio"][aria-label="Vermelho"]');
|
|
81
|
+
await clicar(vermelho());
|
|
82
|
+
assert.match(m.raiz.textContent, /Selecione o texto antes de aplicar/);
|
|
83
|
+
assert.equal(chamadas.length, 0);
|
|
84
|
+
selecionar(m);
|
|
85
|
+
await clicar(vermelho());
|
|
86
|
+
assert.deepEqual(chamadas.at(-1), ["insertHTML", false, '<span style="color: var(--umds-primitive-red-pure);">Parecer</span>']);
|
|
87
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** SegmentedControl com contador (count) 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("SegmentedControl/SegmentedControl.vue", props);
|
|
9
|
+
montados.push(m);
|
|
10
|
+
return m;
|
|
11
|
+
};
|
|
12
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
13
|
+
|
|
14
|
+
const FILA = [
|
|
15
|
+
{ label: "Todas", value: "todas", count: 31 },
|
|
16
|
+
{ label: "Minhas", value: "minhas", count: 0 },
|
|
17
|
+
{ label: "Arquivadas", value: "arquivadas" },
|
|
18
|
+
{ label: "Vazias", value: "vazias", count: "" },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
test("a pílula do contador vem depois do texto; 0 aparece, vazio e ausente não", async () => {
|
|
22
|
+
const m = await abrir({ label: "Fila", options: FILA });
|
|
23
|
+
const itens = [...m.raiz.querySelectorAll(".umds-segmented__item")];
|
|
24
|
+
assert.equal(itens[0].querySelector(".umds-segmented__count").textContent.trim(), "31");
|
|
25
|
+
assert.equal(itens[1].querySelector(".umds-segmented__count").textContent.trim(), "0");
|
|
26
|
+
assert.equal(itens[2].querySelector(".umds-segmented__count"), null);
|
|
27
|
+
assert.equal(itens[3].querySelector(".umds-segmented__count"), null);
|
|
28
|
+
assert.ok(itens[0].querySelector(".umds-segmented__conteudo").lastElementChild.classList.contains("umds-segmented__count"));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("a escolha segue funcionando com contador", async () => {
|
|
32
|
+
const vistos = [];
|
|
33
|
+
const m = await abrir({ label: "Fila", options: FILA, defaultValue: "todas", onChange: (v) => vistos.push(v) });
|
|
34
|
+
const radios = [...m.raiz.querySelectorAll('input[type="radio"]')];
|
|
35
|
+
assert.equal(radios[0].checked, true);
|
|
36
|
+
await clicar(m.raiz.querySelectorAll(".umds-segmented__item")[1]);
|
|
37
|
+
assert.deepEqual(vistos, ["minhas"]);
|
|
38
|
+
assert.equal(m.raiz.querySelectorAll(".umds-segmented__count").length, 2);
|
|
39
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** SegmentedControl variant surface no Vue (classes no DOM e regras de CSS na fonte). */
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
import { montar } from "./dom.mjs";
|
|
7
|
+
|
|
8
|
+
const montados = [];
|
|
9
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
10
|
+
const raiz = async (caminho, props, seletor) => {
|
|
11
|
+
const m = await montar(caminho, props);
|
|
12
|
+
montados.push(m);
|
|
13
|
+
return m.raiz.querySelector(seletor);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const css = (componente) =>
|
|
17
|
+
readFileSync(resolve(process.cwd(), `../core/src/components/${componente}/${componente}.css`), "utf8").replace(/\r\n/g, "\n");
|
|
18
|
+
const bloco = (texto, seletor) => {
|
|
19
|
+
const inicio = texto.indexOf(seletor + " {");
|
|
20
|
+
assert.ok(inicio >= 0, seletor);
|
|
21
|
+
return texto.slice(inicio, texto.indexOf("}", inicio));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
test("SegmentedControl variant surface escreve a classe; sem a prop e com default, não", async () => {
|
|
25
|
+
const opcoes = [{ label: "Individual", value: "individual", count: 12 }, { label: "Em lote", value: "lote" }];
|
|
26
|
+
assert.ok((await raiz("SegmentedControl/SegmentedControl.vue", { options: opcoes, variant: "surface", defaultValue: "individual" }, ".umds-segmented")).classList.contains("umds-segmented--surface"));
|
|
27
|
+
assert.ok(!(await raiz("SegmentedControl/SegmentedControl.vue", { options: opcoes, defaultValue: "individual" }, ".umds-segmented")).classList.contains("umds-segmented--surface"));
|
|
28
|
+
assert.ok(!(await raiz("SegmentedControl/SegmentedControl.vue", { options: opcoes, variant: "default", defaultValue: "individual" }, ".umds-segmented")).classList.contains("umds-segmented--surface"));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("SegmentedControl CSS: o escolhido é branco, em negrito e com sombra; o trilho é cinza claro; o azul do padrão segue", () => {
|
|
32
|
+
const t = css("SegmentedControl");
|
|
33
|
+
const escolhido = bloco(t, ".umds-segmented--surface .umds-segmented__input:checked + .umds-segmented__item,\n.umds-segmented--surface .umds-segmented__input:checked + .umds-segmented__item:hover");
|
|
34
|
+
assert.match(escolhido, /background-color:\s*var\(--umds-semantic-color-background-white\)/);
|
|
35
|
+
assert.match(escolhido, /font-weight:\s*var\(--umds-primitive-font-weight-bold\)/);
|
|
36
|
+
assert.match(escolhido, /box-shadow:\s*var\(--umds-semantic-shadow-md\)/);
|
|
37
|
+
assert.match(bloco(t, ".umds-segmented--surface .umds-segmented__track"), /background-color:\s*var\(--umds-semantic-color-neutral-light-medium\)/);
|
|
38
|
+
assert.match(t, /\.umds-segmented__input:checked \+ \.umds-segmented__item,\n\.umds-segmented__input:checked \+ \.umds-segmented__item:hover \{\n\s*background-color:\s*var\(--umds-semantic-color-primary-pure\)/);
|
|
39
|
+
assert.match(bloco(t, ".umds-segmented--surface .umds-segmented__count"), /background-color:\s*var\(--umds-semantic-color-background-white\)/);
|
|
40
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Select no Vue: open/onOpenChange, gatilho com ícone e amostra, variantes de filtro
|
|
3
|
+
* e a lista por cima de diálogo (DOM do jsdom).
|
|
4
|
+
*/
|
|
5
|
+
import { test, after } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import { montar, proximoTick, clicar, teclar, documento, janela } from "./dom.mjs";
|
|
8
|
+
|
|
9
|
+
const montados = [];
|
|
10
|
+
const abrir = async (props, slots) => {
|
|
11
|
+
const m = await montar("Select/Select.vue", props, slots);
|
|
12
|
+
montados.push(m);
|
|
13
|
+
return m;
|
|
14
|
+
};
|
|
15
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
16
|
+
|
|
17
|
+
const OPCOES = [
|
|
18
|
+
{ label: "Urgente", value: "urgente" },
|
|
19
|
+
{ label: "Revisão", value: "revisao" },
|
|
20
|
+
];
|
|
21
|
+
const combo = (m) => m.raiz.querySelector('[role="combobox"]');
|
|
22
|
+
const lista = (m) => m.raiz.querySelector('[role="listbox"]');
|
|
23
|
+
|
|
24
|
+
test("open controlado mostra a lista sem clique; false não mostra", async () => {
|
|
25
|
+
const aberto = await abrir({ ariaLabel: "x", options: OPCOES, open: true });
|
|
26
|
+
assert.ok(lista(aberto));
|
|
27
|
+
assert.equal(combo(aberto).getAttribute("aria-expanded"), "true");
|
|
28
|
+
const fechado = await abrir({ ariaLabel: "x", options: OPCOES, open: false });
|
|
29
|
+
assert.equal(lista(fechado), null);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("sem a prop open o Select é não controlado (Vue não vira false)", async () => {
|
|
33
|
+
const m = await abrir({ ariaLabel: "x", options: OPCOES });
|
|
34
|
+
assert.equal(lista(m), null);
|
|
35
|
+
await clicar(combo(m));
|
|
36
|
+
assert.ok(lista(m), "abriu sozinho");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("controlado: o clique só avisa; quem abre é o pai", async () => {
|
|
40
|
+
const chamadas = [];
|
|
41
|
+
const m = await abrir({ ariaLabel: "x", options: OPCOES, open: false, onOpenChange: (v) => chamadas.push(v) });
|
|
42
|
+
await clicar(combo(m));
|
|
43
|
+
assert.deepEqual(chamadas, [true]);
|
|
44
|
+
assert.equal(lista(m), null);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("controlado aberto: opção, Esc e clique fora pedem para fechar", async () => {
|
|
48
|
+
const chamadas = [];
|
|
49
|
+
const m = await abrir({ ariaLabel: "x", options: OPCOES, open: true, onOpenChange: (v) => chamadas.push(v) });
|
|
50
|
+
await clicar(m.raiz.querySelectorAll('[role="option"]')[0]);
|
|
51
|
+
assert.equal(chamadas.at(-1), false);
|
|
52
|
+
chamadas.length = 0;
|
|
53
|
+
await teclar(combo(m), "Escape");
|
|
54
|
+
assert.equal(chamadas.at(-1), false);
|
|
55
|
+
chamadas.length = 0;
|
|
56
|
+
documento.body.dispatchEvent(new janela.MouseEvent("mousedown", { bubbles: true }));
|
|
57
|
+
await proximoTick();
|
|
58
|
+
assert.deepEqual(chamadas, [false]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("o clique fora não avisa quando a lista está fechada", async () => {
|
|
62
|
+
const chamadas = [];
|
|
63
|
+
await abrir({ ariaLabel: "x", options: OPCOES, open: false, onOpenChange: (v) => chamadas.push(v) });
|
|
64
|
+
documento.body.dispatchEvent(new janela.MouseEvent("mousedown", { bubbles: true }));
|
|
65
|
+
await proximoTick();
|
|
66
|
+
assert.deepEqual(chamadas, []);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("triggerIcon, triggerSwatch e aria-required", async () => {
|
|
70
|
+
const { faFilter } = await import("@fortawesome/free-solid-svg-icons");
|
|
71
|
+
const m = await abrir({
|
|
72
|
+
ariaLabel: "x",
|
|
73
|
+
options: OPCOES,
|
|
74
|
+
required: true,
|
|
75
|
+
triggerIcon: faFilter,
|
|
76
|
+
triggerSwatch: "var(--umds-semantic-color-primary-pure)",
|
|
77
|
+
});
|
|
78
|
+
const icone = m.raiz.querySelector(".umds-select__trigger-icon");
|
|
79
|
+
assert.equal(icone.getAttribute("aria-hidden"), "true");
|
|
80
|
+
assert.equal(icone.querySelector("svg").getAttribute("data-icon"), "filter");
|
|
81
|
+
const amostra = m.raiz.querySelector(".umds-select__swatch");
|
|
82
|
+
assert.equal(amostra.getAttribute("aria-hidden"), "true");
|
|
83
|
+
assert.match(amostra.getAttribute("style"), /--umds-semantic-color-primary-pure/);
|
|
84
|
+
assert.equal(combo(m).getAttribute("aria-required"), "true");
|
|
85
|
+
const sem = await abrir({ ariaLabel: "x", options: OPCOES });
|
|
86
|
+
assert.equal(sem.raiz.querySelector(".umds-select__swatch"), null);
|
|
87
|
+
assert.equal(combo(sem).getAttribute("aria-required"), null);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("search e combo escrevem a classe do filtro e a própria", async () => {
|
|
91
|
+
const s = await abrir({ ariaLabel: "x", options: OPCOES, variant: "search" });
|
|
92
|
+
assert.ok(s.raiz.querySelector(".umds-select--filter.umds-select--filter-search"));
|
|
93
|
+
const c = await abrir({ ariaLabel: "x", options: OPCOES, variant: "combo" });
|
|
94
|
+
assert.ok(c.raiz.querySelector(".umds-select--filter.umds-select--filter-combo"));
|
|
95
|
+
assert.equal(c.raiz.querySelector(".umds-select--filter-search"), null);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("dentro de role=dialog a lista vira fixed; fora, não", async () => {
|
|
99
|
+
const alvo = documento.createElement("div");
|
|
100
|
+
alvo.setAttribute("role", "dialog");
|
|
101
|
+
alvo.setAttribute("aria-label", "Filtros");
|
|
102
|
+
documento.body.append(alvo);
|
|
103
|
+
const { createApp, h } = await import("vue");
|
|
104
|
+
const { pathToFileURL } = await import("node:url");
|
|
105
|
+
const { resolve } = await import("node:path");
|
|
106
|
+
const modulo = await import(pathToFileURL(resolve(process.cwd(), "src/components/Select/Select.vue")).href);
|
|
107
|
+
const app = createApp({ render: () => h(modulo.default, { ariaLabel: "x", options: OPCOES }) });
|
|
108
|
+
app.mount(alvo);
|
|
109
|
+
await clicar(alvo.querySelector('[role="combobox"]'));
|
|
110
|
+
const dentro = alvo.querySelector(".umds-select__dropdown");
|
|
111
|
+
assert.ok(alvo.querySelector(".umds-select--floating"));
|
|
112
|
+
assert.equal(dentro.style.position, "fixed");
|
|
113
|
+
app.unmount();
|
|
114
|
+
alvo.remove();
|
|
115
|
+
|
|
116
|
+
const m = await abrir({ ariaLabel: "x", options: OPCOES });
|
|
117
|
+
await clicar(combo(m));
|
|
118
|
+
assert.equal(m.raiz.querySelector(".umds-select--floating"), null);
|
|
119
|
+
assert.equal(m.raiz.querySelector(".umds-select__dropdown").style.position, "");
|
|
120
|
+
});
|
|
@@ -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,68 @@
|
|
|
1
|
+
/** Select: o slot #item com escopo da opção, na lista e no gatilho, no Vue (DOM do jsdom). */
|
|
2
|
+
import { test, after } from "node:test";
|
|
3
|
+
import assert from "node:assert/strict";
|
|
4
|
+
import { montar, clicar, proximoTick } from "./dom.mjs";
|
|
5
|
+
import { h } from "vue";
|
|
6
|
+
|
|
7
|
+
const montados = [];
|
|
8
|
+
after(() => montados.forEach((m) => m.desmontar()));
|
|
9
|
+
|
|
10
|
+
const OPCOES = [
|
|
11
|
+
{ label: "Urgente", value: "urgente", etiqueta: "Prazo hoje" },
|
|
12
|
+
{ label: "Rotina", value: "rotina", etiqueta: "Sem prazo" },
|
|
13
|
+
];
|
|
14
|
+
const abrir = async (props, slots = {}) => {
|
|
15
|
+
const m = await montar("Select/Select.vue", { ariaLabel: "Prioridade", options: OPCOES, ...props }, slots);
|
|
16
|
+
montados.push(m);
|
|
17
|
+
return m;
|
|
18
|
+
};
|
|
19
|
+
const gatilho = (m) => m.raiz.querySelector(".umds-select__trigger");
|
|
20
|
+
const slotItem = (escopos) => ({
|
|
21
|
+
item: (escopo) => {
|
|
22
|
+
escopos.push(escopo);
|
|
23
|
+
return h("span", { "data-testid": "item" }, escopo.optionData.label + " " + escopo.optionData.etiqueta);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("a lista passa a opção ao slot (optionData e o apelido option)", async () => {
|
|
28
|
+
const escopos = [];
|
|
29
|
+
const m = await abrir({}, slotItem(escopos));
|
|
30
|
+
await clicar(gatilho(m));
|
|
31
|
+
const itens = [...m.raiz.querySelectorAll('[data-testid="item"]')].map((n) => n.textContent);
|
|
32
|
+
assert.deepEqual(itens, ["Urgente Prazo hoje", "Rotina Sem prazo"]);
|
|
33
|
+
const daLista = escopos.find((e) => e.optionData.value === "rotina");
|
|
34
|
+
assert.equal(daLista.optionData, OPCOES[1]);
|
|
35
|
+
assert.equal(daLista.option, OPCOES[1]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("o gatilho com a opção escolhida mostra o conteúdo do slot, não o texto", async () => {
|
|
39
|
+
const m = await abrir({ value: "urgente" }, slotItem([]));
|
|
40
|
+
await proximoTick();
|
|
41
|
+
const dentro = gatilho(m).querySelector(".umds-select__trigger-item");
|
|
42
|
+
assert.ok(dentro);
|
|
43
|
+
assert.match(dentro.textContent, /Urgente Prazo hoje/);
|
|
44
|
+
assert.equal(gatilho(m).querySelector(".umds-select__placeholder"), null);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("sem valor o gatilho mostra o placeholder, e escolher na lista passa o item ao gatilho", async () => {
|
|
48
|
+
const m = await abrir({ placeholder: "Escolha" }, slotItem([]));
|
|
49
|
+
assert.match(gatilho(m).textContent, /Escolha/);
|
|
50
|
+
assert.equal(gatilho(m).querySelector(".umds-select__trigger-item"), null);
|
|
51
|
+
await clicar(gatilho(m));
|
|
52
|
+
await clicar(m.raiz.querySelectorAll('[role="option"]')[1]);
|
|
53
|
+
await proximoTick();
|
|
54
|
+
assert.match(gatilho(m).querySelector(".umds-select__trigger-item").textContent, /Rotina Sem prazo/);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("seleção múltipla segue com o texto no gatilho", async () => {
|
|
58
|
+
const m = await abrir({ multiple: true, value: ["urgente"] }, slotItem([]));
|
|
59
|
+
assert.equal(gatilho(m).querySelector(".umds-select__trigger-item"), null);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("sem o slot nada muda: o gatilho mostra o rótulo e a lista o texto da opção", async () => {
|
|
63
|
+
const m = await abrir({ value: "urgente" });
|
|
64
|
+
assert.equal(gatilho(m).querySelector(".umds-select__trigger-item"), null);
|
|
65
|
+
assert.match(gatilho(m).textContent, /Urgente/);
|
|
66
|
+
await clicar(gatilho(m));
|
|
67
|
+
assert.match(m.raiz.querySelector('[role="option"]').textContent, /Urgente/);
|
|
68
|
+
});
|