@adia-ai/web-components 0.7.6 → 0.7.8

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.
@@ -0,0 +1,54 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import { logicalChildren, logicalSlotted } from './logical-children.js';
3
+
4
+ function host(html) {
5
+ const el = document.createElement('div');
6
+ el.innerHTML = html;
7
+ return el;
8
+ }
9
+
10
+ describe('logical-children', () => {
11
+ beforeEach(() => { document.body.innerHTML = ''; });
12
+
13
+ it('returns static direct children as-is', () => {
14
+ const h = host(`<button slot="primary">A</button><p>body</p><button slot="secondary">B</button>`);
15
+ expect(logicalChildren(h).map((e) => e.tagName)).toEqual(['BUTTON', 'P', 'BUTTON']);
16
+ expect(logicalSlotted(h, 'primary').length).toBe(1);
17
+ expect(logicalSlotted(h, 'secondary')[0].textContent).toBe('B');
18
+ expect(logicalSlotted(h, 'missing').length).toBe(0);
19
+ });
20
+
21
+ it('pierces a single display:contents/role=presentation wrapper', () => {
22
+ const h = host(`
23
+ <span style="display:contents" role="presentation"><button slot="primary">A</button></span>
24
+ <p>body</p>
25
+ `);
26
+ // Without piercing, h.querySelector(':scope > [slot="primary"]') would be null:
27
+ expect(h.querySelector(':scope > [slot="primary"]')).toBeNull();
28
+ // With the helper, it's found:
29
+ expect(logicalSlotted(h, 'primary').length).toBe(1);
30
+ expect(logicalChildren(h).map((e) => e.tagName)).toEqual(['BUTTON', 'P']);
31
+ });
32
+
33
+ it('pierces NESTED wrappers (the .map() shape)', () => {
34
+ const h = host(`
35
+ <span style="display:contents" role="presentation">
36
+ <span style="display:contents" role="presentation"><button slot="act">A</button></span>
37
+ <span style="display:contents" role="presentation"><button slot="act">B</button></span>
38
+ </span>
39
+ `);
40
+ expect(logicalSlotted(h, 'act').map((e) => e.textContent)).toEqual(['A', 'B']);
41
+ });
42
+
43
+ it('does NOT pierce non-wrapper elements (logical = direct, wrappers aside)', () => {
44
+ const h = host(`<div><button slot="primary">nested-in-real-div</button></div>`);
45
+ // The button is inside a real <div>, not a transparent wrapper → not a logical child.
46
+ expect(logicalSlotted(h, 'primary').length).toBe(0);
47
+ expect(logicalChildren(h).map((e) => e.tagName)).toEqual(['DIV']);
48
+ });
49
+
50
+ it('tolerates a null host', () => {
51
+ expect(logicalChildren(null)).toEqual([]);
52
+ expect(logicalSlotted(null, 'x')).toEqual([]);
53
+ });
54
+ });