@internetarchive/collection-browser 3.3.1 → 3.3.3
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/.editorconfig +29 -29
- package/.github/workflows/ci.yml +27 -27
- package/.github/workflows/gh-pages-main.yml +39 -39
- package/.github/workflows/npm-publish.yml +39 -39
- package/.github/workflows/pr-preview.yml +38 -38
- package/.husky/pre-commit +4 -4
- package/.prettierignore +1 -1
- package/LICENSE +661 -661
- package/README.md +83 -83
- package/dist/src/collection-browser.js +683 -683
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/collection-facets/more-facets-content.js +118 -118
- package/dist/src/collection-facets/more-facets-content.js.map +1 -1
- package/dist/src/collection-facets.js +265 -266
- package/dist/src/collection-facets.js.map +1 -1
- package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
- package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
- package/dist/src/data-source/models.js.map +1 -1
- package/dist/src/tiles/base-tile-component.js.map +1 -1
- package/dist/src/tiles/grid/account-tile.js +36 -36
- package/dist/src/tiles/grid/account-tile.js.map +1 -1
- package/dist/src/tiles/grid/collection-tile.js +77 -77
- package/dist/src/tiles/grid/collection-tile.js.map +1 -1
- package/dist/src/tiles/grid/item-tile.js +137 -137
- package/dist/src/tiles/grid/item-tile.js.map +1 -1
- package/dist/src/tiles/hover/hover-pane-controller.d.ts +9 -1
- package/dist/src/tiles/hover/hover-pane-controller.js +105 -37
- package/dist/src/tiles/hover/hover-pane-controller.js.map +1 -1
- package/dist/src/tiles/hover/tile-hover-pane.d.ts +1 -0
- package/dist/src/tiles/hover/tile-hover-pane.js +115 -112
- package/dist/src/tiles/hover/tile-hover-pane.js.map +1 -1
- package/dist/src/tiles/list/tile-list-compact.js +99 -99
- package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
- package/dist/src/tiles/list/tile-list.js +297 -297
- package/dist/src/tiles/list/tile-list.js.map +1 -1
- package/dist/src/tiles/tile-dispatcher.d.ts +4 -1
- package/dist/src/tiles/tile-dispatcher.js +231 -204
- package/dist/src/tiles/tile-dispatcher.js.map +1 -1
- package/dist/src/utils/format-date.js.map +1 -1
- package/dist/test/collection-browser.test.js +189 -189
- package/dist/test/collection-browser.test.js.map +1 -1
- package/dist/test/tiles/grid/item-tile.test.js +77 -77
- package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
- package/dist/test/tiles/hover/hover-pane-controller.test.js +68 -21
- package/dist/test/tiles/hover/hover-pane-controller.test.js.map +1 -1
- package/dist/test/tiles/list/tile-list-compact.test.js +70 -70
- package/dist/test/tiles/list/tile-list-compact.test.js.map +1 -1
- package/dist/test/tiles/list/tile-list.test.js +126 -126
- package/dist/test/tiles/list/tile-list.test.js.map +1 -1
- package/dist/test/tiles/tile-dispatcher.test.js +130 -52
- package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
- package/dist/test/utils/format-date.test.js.map +1 -1
- package/eslint.config.mjs +53 -53
- package/index.html +24 -24
- package/local.archive.org.cert +86 -86
- package/local.archive.org.key +27 -27
- package/package.json +118 -117
- package/renovate.json +6 -6
- package/src/collection-browser.ts +2829 -2829
- package/src/collection-facets/more-facets-content.ts +639 -639
- package/src/collection-facets.ts +994 -995
- package/src/data-source/collection-browser-data-source.ts +1401 -1401
- package/src/data-source/collection-browser-query-state.ts +65 -65
- package/src/data-source/models.ts +43 -43
- package/src/tiles/base-tile-component.ts +65 -65
- package/src/tiles/grid/account-tile.ts +113 -113
- package/src/tiles/grid/collection-tile.ts +163 -163
- package/src/tiles/grid/item-tile.ts +340 -340
- package/src/tiles/hover/hover-pane-controller.ts +613 -517
- package/src/tiles/hover/tile-hover-pane.ts +184 -180
- package/src/tiles/list/tile-list-compact.ts +239 -239
- package/src/tiles/list/tile-list.ts +700 -700
- package/src/tiles/tile-dispatcher.ts +517 -490
- package/src/utils/format-date.ts +62 -62
- package/test/collection-browser.test.ts +2403 -2403
- package/test/tiles/grid/item-tile.test.ts +520 -520
- package/test/tiles/hover/hover-pane-controller.test.ts +418 -353
- package/test/tiles/list/tile-list-compact.test.ts +282 -282
- package/test/tiles/list/tile-list.test.ts +552 -552
- package/test/tiles/tile-dispatcher.test.ts +283 -187
- package/test/utils/format-date.test.ts +89 -89
- package/tsconfig.json +20 -20
- package/web-dev-server.config.mjs +30 -30
- package/web-test-runner.config.mjs +41 -41
|
@@ -1,353 +1,418 @@
|
|
|
1
|
-
import { expect, fixture } from '@open-wc/testing';
|
|
2
|
-
import { html, LitElement, nothing, TemplateResult } from 'lit';
|
|
3
|
-
import { customElement, property, query } from 'lit/decorators.js';
|
|
4
|
-
import {
|
|
5
|
-
HoverPaneController,
|
|
6
|
-
HoverPaneControllerInterface,
|
|
7
|
-
HoverPaneControllerOptions,
|
|
8
|
-
HoverPaneProperties,
|
|
9
|
-
HoverPaneProviderInterface,
|
|
10
|
-
} from '../../../src/tiles/hover/hover-pane-controller';
|
|
11
|
-
import type { TileHoverPane } from '../../../src/tiles/hover/tile-hover-pane';
|
|
12
|
-
import { TileModel } from '../../../src/models';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
tileModel
|
|
43
|
-
tileModel.
|
|
44
|
-
tileModel.
|
|
45
|
-
tileModel.
|
|
46
|
-
tileModel.
|
|
47
|
-
tileModel.
|
|
48
|
-
tileModel.
|
|
49
|
-
tileModel.
|
|
50
|
-
tileModel.
|
|
51
|
-
tileModel.
|
|
52
|
-
tileModel.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
window.matchMedia =
|
|
76
|
-
window.ontouchstart =
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
host.dispatchEvent(new MouseEvent('
|
|
202
|
-
await new Promise(resolve => {
|
|
203
|
-
setTimeout(resolve,
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
host.dispatchEvent(new MouseEvent('
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
host.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
});
|
|
1
|
+
import { expect, fixture } from '@open-wc/testing';
|
|
2
|
+
import { html, LitElement, nothing, TemplateResult } from 'lit';
|
|
3
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
4
|
+
import {
|
|
5
|
+
HoverPaneController,
|
|
6
|
+
HoverPaneControllerInterface,
|
|
7
|
+
HoverPaneControllerOptions,
|
|
8
|
+
HoverPaneProperties,
|
|
9
|
+
HoverPaneProviderInterface,
|
|
10
|
+
} from '../../../src/tiles/hover/hover-pane-controller';
|
|
11
|
+
import type { TileHoverPane } from '../../../src/tiles/hover/tile-hover-pane';
|
|
12
|
+
import { TileModel } from '../../../src/models';
|
|
13
|
+
import sinon from 'sinon';
|
|
14
|
+
|
|
15
|
+
@customElement('host-element')
|
|
16
|
+
class HostElement extends LitElement implements HoverPaneProviderInterface {
|
|
17
|
+
@property({ type: Object }) controllerOptions?: HoverPaneControllerOptions;
|
|
18
|
+
|
|
19
|
+
@property({ type: Boolean }) suppressHoverPane: boolean = false;
|
|
20
|
+
|
|
21
|
+
@query('tile-hover-pane') hoverPane?: TileHoverPane;
|
|
22
|
+
|
|
23
|
+
controller?: HoverPaneControllerInterface;
|
|
24
|
+
|
|
25
|
+
render(): TemplateResult {
|
|
26
|
+
return html` ${this.controller?.getTemplate()} `;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected firstUpdated(): void {
|
|
30
|
+
this.controller = new HoverPaneController(this, this.controllerOptions);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
acquireFocus(): void {}
|
|
34
|
+
|
|
35
|
+
releaseFocus(): void {}
|
|
36
|
+
|
|
37
|
+
getHoverPane(): HTMLElement | undefined {
|
|
38
|
+
return this.suppressHoverPane ? undefined : this.hoverPane;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getHoverPaneProps(): HoverPaneProperties {
|
|
42
|
+
const tileModel = new TileModel({});
|
|
43
|
+
tileModel.checked = false;
|
|
44
|
+
tileModel.collectionFilesCount = 1;
|
|
45
|
+
tileModel.collections = ['foo', 'bar'];
|
|
46
|
+
tileModel.collectionSize = 1;
|
|
47
|
+
tileModel.commentCount = 1;
|
|
48
|
+
tileModel.contentWarning = false;
|
|
49
|
+
tileModel.creators = ['foo', 'bar'];
|
|
50
|
+
tileModel.favCount = 1;
|
|
51
|
+
tileModel.identifier = 'foo';
|
|
52
|
+
tileModel.itemCount = 1;
|
|
53
|
+
tileModel.loginRequired = false;
|
|
54
|
+
tileModel.mediatype = 'data';
|
|
55
|
+
tileModel.subjects = ['foo', 'bar'];
|
|
56
|
+
tileModel.title = 'foo';
|
|
57
|
+
tileModel.viewCount = 1;
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
model: tileModel,
|
|
61
|
+
loggedIn: false,
|
|
62
|
+
suppressBlurring: false,
|
|
63
|
+
sortParam: null,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe('Hover Pane Controller', () => {
|
|
69
|
+
let oldMatchMedia: typeof window.matchMedia;
|
|
70
|
+
let oldOnTouchStart: typeof window.ontouchstart;
|
|
71
|
+
|
|
72
|
+
before(() => {
|
|
73
|
+
oldMatchMedia = window.matchMedia;
|
|
74
|
+
oldOnTouchStart = window.ontouchstart;
|
|
75
|
+
window.matchMedia = () => ({ matches: true }) as MediaQueryList;
|
|
76
|
+
window.ontouchstart = () => {};
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
after(() => {
|
|
80
|
+
window.matchMedia = oldMatchMedia;
|
|
81
|
+
window.ontouchstart = oldOnTouchStart;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should initially provide empty template', async () => {
|
|
85
|
+
const host = await fixture<HostElement>(
|
|
86
|
+
html`<host-element></host-element>`,
|
|
87
|
+
);
|
|
88
|
+
expect(host.controller?.getTemplate()).to.equal(nothing);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should produce a hover pane template after mousemove, and hide it after mouseleave', async () => {
|
|
92
|
+
const host = await fixture<HostElement>(
|
|
93
|
+
html`<host-element
|
|
94
|
+
.controllerOptions=${{ showDelay: 0, hideDelay: 0 }}
|
|
95
|
+
></host-element>`,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
host.dispatchEvent(new MouseEvent('mousemove'));
|
|
99
|
+
// Need to wait a tick for the event handlers to run
|
|
100
|
+
await new Promise(resolve => {
|
|
101
|
+
setTimeout(resolve, 0);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(host.controller?.getTemplate()).not.to.equal(nothing); // Is a TemplateResult
|
|
105
|
+
|
|
106
|
+
host.dispatchEvent(new MouseEvent('mouseleave'));
|
|
107
|
+
// Need to wait for the fade out transition
|
|
108
|
+
await new Promise(resolve => {
|
|
109
|
+
setTimeout(resolve, 150);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(host.controller?.getTemplate()).to.equal(nothing);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should produce a hover pane template after mouseenter, even without mousemove', async () => {
|
|
116
|
+
const host = await fixture<HostElement>(
|
|
117
|
+
html`<host-element
|
|
118
|
+
.controllerOptions=${{ showDelay: 0, hideDelay: 0 }}
|
|
119
|
+
></host-element>`,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
host.dispatchEvent(new MouseEvent('mouseenter'));
|
|
123
|
+
// Need to wait a tick for the event handlers to run
|
|
124
|
+
await new Promise(resolve => {
|
|
125
|
+
setTimeout(resolve, 0);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
expect(host.controller?.getTemplate()).not.to.equal(nothing); // Is a TemplateResult
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should immediately fade back in if mouse enters while fading out', async () => {
|
|
132
|
+
const host = await fixture<HostElement>(
|
|
133
|
+
html`<host-element
|
|
134
|
+
.controllerOptions=${{ showDelay: 0, hideDelay: 0 }}
|
|
135
|
+
></host-element>`,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
// Enter the host element and wait for the show handlers to run
|
|
139
|
+
host.dispatchEvent(new MouseEvent('mousemove'));
|
|
140
|
+
await new Promise(resolve => {
|
|
141
|
+
setTimeout(resolve, 0);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Leave the host element so it begins fading out, but not all the way
|
|
145
|
+
host.dispatchEvent(new MouseEvent('mouseleave'));
|
|
146
|
+
await new Promise(resolve => {
|
|
147
|
+
setTimeout(resolve, 20);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Re-enter the host element and wait long enough that it would disappear
|
|
151
|
+
// if the hide were not cancelled
|
|
152
|
+
host.dispatchEvent(new MouseEvent('mousemove'));
|
|
153
|
+
await new Promise(resolve => {
|
|
154
|
+
setTimeout(resolve, 150);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
expect(host.controller?.getTemplate()).not.to.equal(nothing);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should flip hover pane if it would overflow the viewport', async () => {
|
|
161
|
+
const host = await fixture<HostElement>(
|
|
162
|
+
html`<host-element
|
|
163
|
+
.controllerOptions=${{ showDelay: 0, hideDelay: 0 }}
|
|
164
|
+
></host-element>`,
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
host.dispatchEvent(
|
|
168
|
+
new MouseEvent('mousemove', { clientX: 800, clientY: 600 }),
|
|
169
|
+
);
|
|
170
|
+
// Need to wait a tick for the event handlers to run
|
|
171
|
+
await new Promise(resolve => {
|
|
172
|
+
setTimeout(resolve, 0);
|
|
173
|
+
});
|
|
174
|
+
await host.updateComplete;
|
|
175
|
+
|
|
176
|
+
expect(host.controller?.getTemplate()).not.to.equal(nothing);
|
|
177
|
+
expect(host.getHoverPane()?.getBoundingClientRect()?.right).to.be.lessThan(
|
|
178
|
+
window.innerWidth,
|
|
179
|
+
);
|
|
180
|
+
expect(host.getHoverPane()?.getBoundingClientRect()?.bottom).to.be.lessThan(
|
|
181
|
+
window.innerHeight,
|
|
182
|
+
);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should gracefully handle undefined hover pane from host element', async () => {
|
|
186
|
+
const host = await fixture<HostElement>(
|
|
187
|
+
html`<host-element
|
|
188
|
+
.controllerOptions=${{ showDelay: 0, hideDelay: 0 }}
|
|
189
|
+
?suppressHoverPane=${true}
|
|
190
|
+
></host-element>`,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
host.dispatchEvent(new MouseEvent('mousemove'));
|
|
194
|
+
// Need to wait a tick for the event handlers to run
|
|
195
|
+
await new Promise(resolve => {
|
|
196
|
+
setTimeout(resolve, 0);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
expect(host.controller?.getTemplate()).not.to.equal(nothing);
|
|
200
|
+
|
|
201
|
+
host.dispatchEvent(new MouseEvent('mouseleave'));
|
|
202
|
+
await new Promise(resolve => {
|
|
203
|
+
setTimeout(resolve, 20);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
host.dispatchEvent(new MouseEvent('mousemove'));
|
|
207
|
+
await new Promise(resolve => {
|
|
208
|
+
setTimeout(resolve, 0);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
host.dispatchEvent(new MouseEvent('mouseleave'));
|
|
212
|
+
// Need to wait for the fade out transition
|
|
213
|
+
await new Promise(resolve => {
|
|
214
|
+
setTimeout(resolve, 150);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
expect(host.controller?.getTemplate()).to.equal(nothing);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe('Touch & long-press', () => {
|
|
221
|
+
const getTouchStartEvent = (host: EventTarget) =>
|
|
222
|
+
new TouchEvent('touchstart', {
|
|
223
|
+
touches: [new Touch({ identifier: 0, target: host })],
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('should produce a hover pane after long press', async () => {
|
|
227
|
+
const host = await fixture<HostElement>(
|
|
228
|
+
html`<host-element
|
|
229
|
+
.controllerOptions=${{
|
|
230
|
+
showDelay: 0,
|
|
231
|
+
longPressDelay: 0,
|
|
232
|
+
enableLongPress: true,
|
|
233
|
+
}}
|
|
234
|
+
></host-element>`,
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
// Touch the host element and wait for the long press handlers to run
|
|
238
|
+
host.dispatchEvent(getTouchStartEvent(host));
|
|
239
|
+
await new Promise(resolve => {
|
|
240
|
+
setTimeout(resolve, 0);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
expect(host.controller?.getTemplate()).not.to.equal(nothing); // Is a TemplateResult
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('should cancel a long press by moving', async () => {
|
|
247
|
+
const host = await fixture<HostElement>(
|
|
248
|
+
html`<host-element
|
|
249
|
+
.controllerOptions=${{
|
|
250
|
+
showDelay: 0,
|
|
251
|
+
longPressDelay: 100,
|
|
252
|
+
enableLongPress: true,
|
|
253
|
+
}}
|
|
254
|
+
></host-element>`,
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
// Touch the host element
|
|
258
|
+
host.dispatchEvent(getTouchStartEvent(host));
|
|
259
|
+
await new Promise(resolve => {
|
|
260
|
+
setTimeout(resolve, 0);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// Move the touch point, cancelling the long press
|
|
264
|
+
host.dispatchEvent(new TouchEvent('touchmove'));
|
|
265
|
+
await new Promise(resolve => {
|
|
266
|
+
setTimeout(resolve, 150);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
expect(host.controller?.getTemplate()).to.equal(nothing);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('should cancel a long press by ending touch', async () => {
|
|
273
|
+
const host = await fixture<HostElement>(
|
|
274
|
+
html`<host-element
|
|
275
|
+
.controllerOptions=${{
|
|
276
|
+
showDelay: 0,
|
|
277
|
+
longPressDelay: 100,
|
|
278
|
+
enableLongPress: true,
|
|
279
|
+
}}
|
|
280
|
+
></host-element>`,
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
// Touch the host element
|
|
284
|
+
host.dispatchEvent(getTouchStartEvent(host));
|
|
285
|
+
await new Promise(resolve => {
|
|
286
|
+
setTimeout(resolve, 0);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// Lift the touch point, cancelling the long press
|
|
290
|
+
host.dispatchEvent(new TouchEvent('touchend'));
|
|
291
|
+
await new Promise(resolve => {
|
|
292
|
+
setTimeout(resolve, 150);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
expect(host.controller?.getTemplate()).to.equal(nothing);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('should cancel a long press by cancelling touch (e.g., too many touch points)', async () => {
|
|
299
|
+
const host = await fixture<HostElement>(
|
|
300
|
+
html`<host-element
|
|
301
|
+
.controllerOptions=${{
|
|
302
|
+
showDelay: 0,
|
|
303
|
+
longPressDelay: 100,
|
|
304
|
+
enableLongPress: true,
|
|
305
|
+
}}
|
|
306
|
+
></host-element>`,
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
// Touch the host element
|
|
310
|
+
host.dispatchEvent(getTouchStartEvent(host));
|
|
311
|
+
await new Promise(resolve => {
|
|
312
|
+
setTimeout(resolve, 0);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// Cancel the touch point, also cancelling the long press
|
|
316
|
+
host.dispatchEvent(new TouchEvent('touchcancel'));
|
|
317
|
+
await new Promise(resolve => {
|
|
318
|
+
setTimeout(resolve, 150);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
expect(host.controller?.getTemplate()).to.equal(nothing);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('should close the hover pane on mobile when touching the backdrop', async () => {
|
|
325
|
+
const host = await fixture<HostElement>(
|
|
326
|
+
html`<host-element
|
|
327
|
+
.controllerOptions=${{
|
|
328
|
+
showDelay: 0,
|
|
329
|
+
hideDelay: 0,
|
|
330
|
+
longPressDelay: 0,
|
|
331
|
+
enableLongPress: true,
|
|
332
|
+
mobileBreakpoint: 9999, // Ensure we get the mobile view
|
|
333
|
+
}}
|
|
334
|
+
></host-element>`,
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
// Touch the host element
|
|
338
|
+
host.dispatchEvent(getTouchStartEvent(host));
|
|
339
|
+
await new Promise(resolve => {
|
|
340
|
+
setTimeout(resolve, 0);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
expect(host.controller?.getTemplate()).not.to.equal(nothing);
|
|
344
|
+
|
|
345
|
+
await host.updateComplete;
|
|
346
|
+
|
|
347
|
+
// Touch the backdrop
|
|
348
|
+
host.shadowRoot
|
|
349
|
+
?.querySelector('#touch-backdrop')
|
|
350
|
+
?.dispatchEvent(new TouchEvent('touchstart'));
|
|
351
|
+
await new Promise(resolve => {
|
|
352
|
+
setTimeout(resolve, 150);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
expect(host.controller?.getTemplate()).to.equal(nothing);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
describe('keyboard accessibility', () => {
|
|
360
|
+
it('should call host getBoundingClientRect if anchor is host', async () => {
|
|
361
|
+
const host = await fixture<HostElement>(
|
|
362
|
+
html`<host-element
|
|
363
|
+
.controllerOptions=${{ showDelay: 0, hideDelay: 0 }}
|
|
364
|
+
></host-element>`,
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
const getBoundingClientRectSpy = sinon.spy(host, 'getBoundingClientRect');
|
|
368
|
+
|
|
369
|
+
host.dispatchEvent(new FocusEvent('focus'));
|
|
370
|
+
// Need to wait a tick for the event handlers to run
|
|
371
|
+
await new Promise(resolve => {
|
|
372
|
+
setTimeout(resolve, 0);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
expect(getBoundingClientRectSpy.called).to.be.true;
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it('should show hover pane on focus', async () => {
|
|
379
|
+
const host = await fixture<HostElement>(
|
|
380
|
+
html`<host-element
|
|
381
|
+
.controllerOptions=${{ showDelay: 0, hideDelay: 0 }}
|
|
382
|
+
></host-element>`,
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
host.dispatchEvent(new FocusEvent('focus'));
|
|
386
|
+
// Need to wait a tick for the event handlers to run
|
|
387
|
+
await new Promise(resolve => {
|
|
388
|
+
setTimeout(resolve, 0);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
expect(host.controller?.getTemplate()).not.to.equal(nothing); // Is a TemplateResult
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('should hide hover pane on blur', async () => {
|
|
395
|
+
const host = await fixture<HostElement>(
|
|
396
|
+
html`<host-element
|
|
397
|
+
.controllerOptions=${{ showDelay: 0, hideDelay: 0 }}
|
|
398
|
+
></host-element>`,
|
|
399
|
+
);
|
|
400
|
+
|
|
401
|
+
host.dispatchEvent(new FocusEvent('focus'));
|
|
402
|
+
// Need to wait a tick for the event handlers to run
|
|
403
|
+
await new Promise(resolve => {
|
|
404
|
+
setTimeout(resolve, 0);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
expect(host.controller?.getTemplate()).not.to.equal(nothing); // Is a TemplateResult
|
|
408
|
+
|
|
409
|
+
host.dispatchEvent(new FocusEvent('blur'));
|
|
410
|
+
// Need to wait for the fade out transition
|
|
411
|
+
await new Promise(resolve => {
|
|
412
|
+
setTimeout(resolve, 150);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
expect(host.controller?.getTemplate()).to.equal(nothing);
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
});
|