@kubex/zinc 1.1.39 → 1.1.41

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.
@@ -7,4 +7,75 @@ describe('<zn-style>', () => {
7
7
 
8
8
  expect(el).to.exist;
9
9
  });
10
+
11
+ describe('border', () => {
12
+ it('border="t" applies only zn-bt', async () => {
13
+ const el = await fixture<HTMLElement>(html`<zn-style border="t"></zn-style>`);
14
+ expect(el.classList.contains('zn-bt')).to.be.true;
15
+ expect(el.classList.contains('zn-bb')).to.be.false;
16
+ expect(el.classList.contains('zn-bl')).to.be.false;
17
+ expect(el.classList.contains('zn-br')).to.be.false;
18
+ expect(el.classList.contains('zn-border')).to.be.false;
19
+ });
20
+
21
+ it('border="tb" applies zn-bt and zn-bb', async () => {
22
+ const el = await fixture<HTMLElement>(html`<zn-style border="tb"></zn-style>`);
23
+ expect(el.classList.contains('zn-bt')).to.be.true;
24
+ expect(el.classList.contains('zn-bb')).to.be.true;
25
+ expect(el.classList.contains('zn-bl')).to.be.false;
26
+ expect(el.classList.contains('zn-br')).to.be.false;
27
+ });
28
+
29
+ it('border (attribute present but empty) applies zn-border (all four sides)', async () => {
30
+ const el = await fixture<HTMLElement>(html`<zn-style border></zn-style>`);
31
+ expect(el.classList.contains('zn-border')).to.be.true;
32
+ });
33
+
34
+ it('no border attribute applies no border classes', async () => {
35
+ const el = await fixture<HTMLElement>(html`<zn-style></zn-style>`);
36
+ expect(el.classList.contains('zn-border')).to.be.false;
37
+ expect(el.classList.contains('zn-bt')).to.be.false;
38
+ expect(el.classList.contains('zn-bb')).to.be.false;
39
+ expect(el.classList.contains('zn-bl')).to.be.false;
40
+ expect(el.classList.contains('zn-br')).to.be.false;
41
+ });
42
+ });
43
+
44
+ describe('size', () => {
45
+ it('size="s" applies zn-size-s', async () => {
46
+ const el = await fixture<HTMLElement>(html`<zn-style size="s"></zn-style>`);
47
+ expect(el.classList.contains('zn-size-s')).to.be.true;
48
+ });
49
+
50
+ it('size="xs" applies zn-size-xs', async () => {
51
+ const el = await fixture<HTMLElement>(html`<zn-style size="xs"></zn-style>`);
52
+ expect(el.classList.contains('zn-size-xs')).to.be.true;
53
+ });
54
+
55
+ it('size="xl" applies zn-size-xl', async () => {
56
+ const el = await fixture<HTMLElement>(html`<zn-style size="xl"></zn-style>`);
57
+ expect(el.classList.contains('zn-size-xl')).to.be.true;
58
+ });
59
+
60
+ it('size="m" applies no size class', async () => {
61
+ const el = await fixture<HTMLElement>(html`<zn-style size="m"></zn-style>`);
62
+ expect(el.classList.contains('zn-size-m')).to.be.false;
63
+ expect(el.classList.contains('zn-size-xs')).to.be.false;
64
+ expect(el.classList.contains('zn-size-s')).to.be.false;
65
+ expect(el.classList.contains('zn-size-l')).to.be.false;
66
+ expect(el.classList.contains('zn-size-xl')).to.be.false;
67
+ });
68
+ });
69
+
70
+ describe('muted', () => {
71
+ it('applies zn-muted class when present', async () => {
72
+ const el = await fixture<HTMLElement>(html`<zn-style muted></zn-style>`);
73
+ expect(el.classList.contains('zn-muted')).to.be.true;
74
+ });
75
+
76
+ it('does not apply zn-muted when absent', async () => {
77
+ const el = await fixture<HTMLElement>(html`<zn-style></zn-style>`);
78
+ expect(el.classList.contains('zn-muted')).to.be.false;
79
+ });
80
+ });
10
81
  });
@@ -0,0 +1,63 @@
1
+ import {expect, fixture, html} from '@open-wc/testing';
2
+ import {deepQuery} from './query';
3
+
4
+ describe('deepQuery', () => {
5
+ it('returns null when no element matches', async () => {
6
+ await fixture(html`<div></div>`);
7
+ expect(deepQuery('.does-not-exist')).to.be.null;
8
+ });
9
+
10
+ it('finds an element in the light DOM of document', async () => {
11
+ const el = await fixture<HTMLElement>(html`<div class="needle"></div>`);
12
+ expect(deepQuery('.needle')).to.equal(el);
13
+ });
14
+
15
+ it('finds an element nested inside a shadow root', async () => {
16
+ const host = await fixture<HTMLElement>(html`<div></div>`);
17
+ const shadow = host.attachShadow({mode: 'open'});
18
+ const needle = document.createElement('span');
19
+ needle.className = 'needle';
20
+ shadow.appendChild(needle);
21
+
22
+ expect(deepQuery('.needle')).to.equal(needle);
23
+ });
24
+
25
+ it('finds an element across two nested shadow roots', async () => {
26
+ const outer = await fixture<HTMLElement>(html`<div></div>`);
27
+ const outerShadow = outer.attachShadow({mode: 'open'});
28
+
29
+ const inner = document.createElement('div');
30
+ outerShadow.appendChild(inner);
31
+ const innerShadow = inner.attachShadow({mode: 'open'});
32
+
33
+ const needle = document.createElement('span');
34
+ needle.className = 'needle';
35
+ innerShadow.appendChild(needle);
36
+
37
+ expect(deepQuery('.needle')).to.equal(needle);
38
+ });
39
+
40
+ it('returns the first match in document order', async () => {
41
+ const root = await fixture<HTMLElement>(html`
42
+ <div>
43
+ <span class="needle" data-which="light"></span>
44
+ </div>
45
+ `);
46
+ const shadow = root.attachShadow({mode: 'open'});
47
+ const inShadow = document.createElement('span');
48
+ inShadow.className = 'needle';
49
+ inShadow.setAttribute('data-which', 'shadow');
50
+ shadow.appendChild(inShadow);
51
+
52
+ const hit = deepQuery<HTMLElement>('.needle');
53
+ expect(hit?.getAttribute('data-which')).to.equal('light');
54
+ });
55
+
56
+ it('accepts a custom root', async () => {
57
+ const a = await fixture<HTMLElement>(html`<div><span class="needle"></span></div>`);
58
+ const b = await fixture<HTMLElement>(html`<div></div>`);
59
+
60
+ expect(deepQuery('.needle', a)).to.exist;
61
+ expect(deepQuery('.needle', b)).to.be.null;
62
+ });
63
+ });
@@ -1,3 +1,30 @@
1
+ export function deepQuery<T extends Element = Element>(
2
+ selector: string,
3
+ root: Document | ShadowRoot | Element = document,
4
+ ): T | null {
5
+ const direct = root.querySelector<T>(selector);
6
+ if (direct) return direct;
7
+ for (const el of root.querySelectorAll<Element>('*')) {
8
+ if (el.shadowRoot) {
9
+ const hit = deepQuery<T>(selector, el.shadowRoot);
10
+ if (hit) return hit;
11
+ }
12
+ }
13
+ return null;
14
+ }
15
+
16
+ export function deepQueryAll<T extends Element = Element>(
17
+ selector: string,
18
+ root: Document | ShadowRoot | Element = document,
19
+ out: T[] = [],
20
+ ): T[] {
21
+ out.push(...root.querySelectorAll<T>(selector));
22
+ for (const el of root.querySelectorAll<Element>('*')) {
23
+ if (el.shadowRoot) deepQueryAll<T>(selector, el.shadowRoot, out);
24
+ }
25
+ return out;
26
+ }
27
+
1
28
  export function deepQuerySelectorAll(selector: string, element: Element, stopSelector: string): Element[] {
2
29
  const arr: Element[] = [];
3
30