@kubex/zinc 1.1.73 → 1.1.75
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/dist/custom-elements.json +575 -91
- package/dist/vscode.html-custom-data.json +20 -15
- package/dist/web-types.json +37 -27
- package/dist/zn.d.ts +71 -5
- package/dist/zn.min.js +229 -229
- package/docs/data/preview-frame-payload-tall.json +7 -0
- package/docs/pages/components/preview-frame-demo.njk +45 -2
- package/docs/pages/components/preview-frame.md +79 -0
- package/docs/pages/components/tabs.md +9 -2
- package/package.json +1 -2
- package/scripts/build.js +5 -5
- package/src/components/defined-label/defined-label.component.ts +10 -17
- package/src/components/defined-label/defined-label.test.ts +107 -1
- package/src/components/expanding-action/expanding-action.component.ts +4 -2
- package/src/components/expanding-action/expanding-action.scss +14 -2
- package/src/components/expanding-action/expanding-action.test.ts +44 -1
- package/src/components/page/page.component.ts +71 -6
- package/src/components/page/page.test.ts +247 -0
- package/src/components/preview-frame/preview-frame.component.ts +84 -8
- package/src/components/preview-frame/preview-frame.scss +7 -1
- package/src/components/preview-frame/preview-frame.test.ts +184 -0
- package/src/components/tabs/tabs-navigation.ts +197 -0
- package/src/components/tabs/tabs.component.ts +188 -56
- package/src/components/tabs/tabs.test.ts +128 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import '../../../dist/zn.min.js';
|
|
2
2
|
import { aTimeout, expect, fixture, html } from '@open-wc/testing';
|
|
3
|
+
import { locationScopedKey } from './tabs-navigation';
|
|
3
4
|
import type ZnTabs from './tabs.component';
|
|
4
5
|
|
|
5
6
|
describe('<zn-tabs>', () => {
|
|
@@ -48,4 +49,131 @@ describe('<zn-tabs>', () => {
|
|
|
48
49
|
const selectedPagePanel = page.shadowRoot!.querySelector<HTMLElement>('#content > div[selected]')!;
|
|
49
50
|
expect(selectedPagePanel.id).to.equal('');
|
|
50
51
|
});
|
|
52
|
+
|
|
53
|
+
describe('selection persistence', () => {
|
|
54
|
+
const storeKey = 'tabs-navigation-test';
|
|
55
|
+
const originalHref = window.location.href;
|
|
56
|
+
let locationCount = 0;
|
|
57
|
+
|
|
58
|
+
const renderTabs = () => fixture<ZnTabs>(html`
|
|
59
|
+
<zn-tabs store-key=${storeKey} active="first">
|
|
60
|
+
<zn-navbar slot="top">
|
|
61
|
+
<li tab="first">First</li>
|
|
62
|
+
<li tab="second">Second</li>
|
|
63
|
+
</zn-navbar>
|
|
64
|
+
<div id="first">First panel</div>
|
|
65
|
+
<div id="second">Second panel</div>
|
|
66
|
+
</zn-tabs>
|
|
67
|
+
`);
|
|
68
|
+
|
|
69
|
+
// Each test runs on its own location so a stored selection, and whether that
|
|
70
|
+
// location may restore one, cannot leak between them.
|
|
71
|
+
const navigateTo = (name: string) => window.history.pushState({}, '', `?tabs-test=${name}`);
|
|
72
|
+
const returnWithHistory = () => window.dispatchEvent(new PopStateEvent('popstate'));
|
|
73
|
+
|
|
74
|
+
beforeEach(() => {
|
|
75
|
+
locationCount += 1;
|
|
76
|
+
navigateTo(`case-${locationCount}`);
|
|
77
|
+
sessionStorage.removeItem(`zntab:${storeKey}`);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterEach(() => window.history.replaceState({}, '', originalHref));
|
|
81
|
+
|
|
82
|
+
it('restores the tab a location was left on when returning to it', async () => {
|
|
83
|
+
const el = await renderTabs();
|
|
84
|
+
await aTimeout(40);
|
|
85
|
+
el.querySelector('zn-navbar')!.querySelectorAll<HTMLElement>('li')[1].click();
|
|
86
|
+
await aTimeout(40);
|
|
87
|
+
expect(el.getAttribute('active')).to.equal('second');
|
|
88
|
+
el.remove();
|
|
89
|
+
|
|
90
|
+
returnWithHistory();
|
|
91
|
+
const restored = await renderTabs();
|
|
92
|
+
await aTimeout(40);
|
|
93
|
+
|
|
94
|
+
expect(restored.getAttribute('active')).to.equal('second');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('starts from the default tab when navigating to the location', async () => {
|
|
98
|
+
const first = await renderTabs();
|
|
99
|
+
await aTimeout(40);
|
|
100
|
+
first.querySelector('zn-navbar')!.querySelectorAll<HTMLElement>('li')[1].click();
|
|
101
|
+
await aTimeout(40);
|
|
102
|
+
first.remove();
|
|
103
|
+
|
|
104
|
+
// Leave and navigate back, rather than returning through history.
|
|
105
|
+
const stored = window.location.search;
|
|
106
|
+
navigateTo('elsewhere');
|
|
107
|
+
window.history.pushState({}, '', stored);
|
|
108
|
+
|
|
109
|
+
const el = await renderTabs();
|
|
110
|
+
await aTimeout(40);
|
|
111
|
+
|
|
112
|
+
expect(el.getAttribute('active')).to.equal('first');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('stores tab changes made outside the navigation', async () => {
|
|
116
|
+
const el = await renderTabs();
|
|
117
|
+
await aTimeout(40);
|
|
118
|
+
|
|
119
|
+
el.nextTab();
|
|
120
|
+
await aTimeout(40);
|
|
121
|
+
expect(el.getAttribute('active')).to.equal('second');
|
|
122
|
+
el.remove();
|
|
123
|
+
|
|
124
|
+
returnWithHistory();
|
|
125
|
+
const restored = await renderTabs();
|
|
126
|
+
await aTimeout(40);
|
|
127
|
+
|
|
128
|
+
expect(restored.getAttribute('active')).to.equal('second');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('steps back through each tab that was opened', async () => {
|
|
132
|
+
const el = await renderTabs();
|
|
133
|
+
await aTimeout(40);
|
|
134
|
+
const items = el.querySelector('zn-navbar')!.querySelectorAll<HTMLElement>('li');
|
|
135
|
+
|
|
136
|
+
items[1].click();
|
|
137
|
+
await aTimeout(40);
|
|
138
|
+
expect(el.getAttribute('active')).to.equal('second');
|
|
139
|
+
|
|
140
|
+
await new Promise<void>(resolve => {
|
|
141
|
+
window.addEventListener('popstate', () => resolve(), {once: true});
|
|
142
|
+
window.history.back();
|
|
143
|
+
});
|
|
144
|
+
await aTimeout(40);
|
|
145
|
+
|
|
146
|
+
expect(el.getAttribute('active')).to.equal('first');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('forgets the selection once the location is navigated away from', async () => {
|
|
150
|
+
const el = await renderTabs();
|
|
151
|
+
await aTimeout(40);
|
|
152
|
+
el.querySelector('zn-navbar')!.querySelectorAll<HTMLElement>('li')[1].click();
|
|
153
|
+
await aTimeout(40);
|
|
154
|
+
const stored = window.location.search;
|
|
155
|
+
el.remove();
|
|
156
|
+
|
|
157
|
+
navigateTo('departed');
|
|
158
|
+
await aTimeout(40);
|
|
159
|
+
expect(sessionStorage.getItem(`zntab:${storeKey}@${window.location.pathname}${stored}`)).to.equal(null);
|
|
160
|
+
|
|
161
|
+
window.history.replaceState({}, '', stored);
|
|
162
|
+
returnWithHistory();
|
|
163
|
+
const returned = await renderTabs();
|
|
164
|
+
await aTimeout(40);
|
|
165
|
+
|
|
166
|
+
expect(returned.getAttribute('active')).to.equal('first');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('keeps a session selection out of local storage', async () => {
|
|
170
|
+
const el = await renderTabs();
|
|
171
|
+
await aTimeout(40);
|
|
172
|
+
el.querySelector('zn-navbar')!.querySelectorAll<HTMLElement>('li')[1].click();
|
|
173
|
+
await aTimeout(40);
|
|
174
|
+
|
|
175
|
+
expect(localStorage.getItem(`zntab:${storeKey}`)).to.equal(null);
|
|
176
|
+
expect(sessionStorage.getItem(`zntab:${locationScopedKey(storeKey)}`)).to.contain('second');
|
|
177
|
+
});
|
|
178
|
+
});
|
|
51
179
|
});
|