@internetarchive/collection-browser 3.3.3 → 3.3.4-alpha-webdev7761.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.
Files changed (55) hide show
  1. package/dist/src/collection-browser.d.ts +10 -2
  2. package/dist/src/collection-browser.js +112 -10
  3. package/dist/src/collection-browser.js.map +1 -1
  4. package/dist/src/collection-facets/facet-row.js +141 -140
  5. package/dist/src/collection-facets/facet-row.js.map +1 -1
  6. package/dist/src/collection-facets/models.js.map +1 -1
  7. package/dist/src/collection-facets.js +12 -0
  8. package/dist/src/collection-facets.js.map +1 -1
  9. package/dist/src/data-source/collection-browser-data-source-interface.d.ts +10 -1
  10. package/dist/src/data-source/collection-browser-data-source-interface.js.map +1 -1
  11. package/dist/src/data-source/collection-browser-data-source.d.ts +19 -1
  12. package/dist/src/data-source/collection-browser-data-source.js +36 -18
  13. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  14. package/dist/src/data-source/collection-browser-query-state.d.ts +1 -2
  15. package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
  16. package/dist/src/data-source/models.d.ts +11 -0
  17. package/dist/src/data-source/models.js.map +1 -1
  18. package/dist/src/manage/manage-bar.js +77 -77
  19. package/dist/src/manage/manage-bar.js.map +1 -1
  20. package/dist/src/models.d.ts +2 -6
  21. package/dist/src/models.js +8 -12
  22. package/dist/src/models.js.map +1 -1
  23. package/dist/src/restoration-state-handler.d.ts +1 -2
  24. package/dist/src/restoration-state-handler.js +3 -9
  25. package/dist/src/restoration-state-handler.js.map +1 -1
  26. package/dist/src/tiles/grid/search-tile.js +42 -42
  27. package/dist/src/tiles/grid/search-tile.js.map +1 -1
  28. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +119 -119
  29. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js.map +1 -1
  30. package/dist/test/collection-browser.test.js +19 -9
  31. package/dist/test/collection-browser.test.js.map +1 -1
  32. package/dist/test/collection-facets/facet-row.test.js +23 -23
  33. package/dist/test/collection-facets/facet-row.test.js.map +1 -1
  34. package/dist/test/collection-facets.test.js +20 -20
  35. package/dist/test/collection-facets.test.js.map +1 -1
  36. package/dist/test/restoration-state-handler.test.js +5 -37
  37. package/dist/test/restoration-state-handler.test.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/collection-browser.ts +132 -7
  40. package/src/collection-facets/facet-row.ts +299 -296
  41. package/src/collection-facets/models.ts +10 -10
  42. package/src/collection-facets.ts +11 -0
  43. package/src/data-source/collection-browser-data-source-interface.ts +345 -333
  44. package/src/data-source/collection-browser-data-source.ts +59 -19
  45. package/src/data-source/collection-browser-query-state.ts +1 -7
  46. package/src/data-source/models.ts +13 -0
  47. package/src/manage/manage-bar.ts +247 -247
  48. package/src/models.ts +866 -870
  49. package/src/restoration-state-handler.ts +542 -544
  50. package/src/tiles/grid/search-tile.ts +90 -90
  51. package/src/tiles/grid/styles/tile-grid-shared-styles.ts +130 -130
  52. package/test/collection-browser.test.ts +21 -11
  53. package/test/collection-facets/facet-row.test.ts +375 -375
  54. package/test/collection-facets.test.ts +928 -928
  55. package/test/restoration-state-handler.test.ts +480 -510
@@ -1,928 +1,928 @@
1
- import { expect, fixture } from '@open-wc/testing';
2
- import sinon from 'sinon';
3
- import { html } from 'lit';
4
- import { Aggregation } from '@internetarchive/search-service';
5
- import {
6
- ModalManager,
7
- ModalManagerInterface,
8
- } from '@internetarchive/modal-manager';
9
- import type { CollectionFacets } from '../src/collection-facets';
10
- import '@internetarchive/modal-manager';
11
- import '../src/collection-facets';
12
- import {
13
- FacetOption,
14
- // SelectedFacets, Used in lending tests (disabled)
15
- getDefaultSelectedFacets,
16
- } from '../src/models';
17
- import { MockAnalyticsHandler } from './mocks/mock-analytics-handler';
18
- import type { FacetRow } from '../src/collection-facets/facet-row';
19
- // import type { FacetsTemplate } from '../src/collection-facets/facets-template'; Used in lending tests (disabled)
20
-
21
- describe('Collection Facets', () => {
22
- it('has loader', async () => {
23
- const el = await fixture<CollectionFacets>(
24
- html`<collection-facets ?facetsLoading=${true}></collection-facets>`,
25
- );
26
-
27
- expect(
28
- el.shadowRoot?.querySelector('#container')?.classList.contains('loading'),
29
- ).to.be.true;
30
-
31
- el.facetsLoading = false;
32
- await el.updateComplete;
33
-
34
- expect(
35
- el.shadowRoot?.querySelector('#container')?.classList.contains('loading'),
36
- ).to.be.false;
37
- });
38
-
39
- it('renders a date picker loading placeholder when date picker enabled', async () => {
40
- const el = await fixture<CollectionFacets>(
41
- html`<collection-facets></collection-facets>`,
42
- );
43
-
44
- el.histogramAggregationLoading = true;
45
- el.showHistogramDatePicker = true;
46
- el.histogramAggregation = new Aggregation({
47
- buckets: [1, 2, 3],
48
- first_bucket_key: 0,
49
- last_bucket_key: 2,
50
- });
51
- await el.updateComplete;
52
-
53
- const histogramLoader = el.shadowRoot?.querySelector(
54
- '.histogram-loading-indicator',
55
- );
56
- expect(histogramLoader).to.exist;
57
- });
58
-
59
- it('does not render a date picker loading placeholder when date picker disabled', async () => {
60
- const el = await fixture<CollectionFacets>(
61
- html`<collection-facets></collection-facets>`,
62
- );
63
-
64
- el.histogramAggregationLoading = true;
65
- el.showHistogramDatePicker = false;
66
- el.histogramAggregation = new Aggregation({
67
- buckets: [1, 2, 3],
68
- first_bucket_key: 0,
69
- last_bucket_key: 2,
70
- });
71
- await el.updateComplete;
72
-
73
- const histogramLoader = el.shadowRoot?.querySelector(
74
- '.histogram-loading-indicator',
75
- );
76
- expect(histogramLoader).to.be.null;
77
- });
78
-
79
- it('renders the date picker when enabled with data present', async () => {
80
- const el = await fixture<CollectionFacets>(
81
- html`<collection-facets></collection-facets>`,
82
- );
83
-
84
- el.histogramAggregationLoading = false;
85
- el.showHistogramDatePicker = true;
86
- el.histogramAggregation = new Aggregation({
87
- buckets: [1, 2, 3],
88
- first_bucket_key: 0,
89
- last_bucket_key: 2,
90
- });
91
- await el.updateComplete;
92
-
93
- const histogram = el.shadowRoot?.querySelector('histogram-date-range');
94
- expect(histogram).to.exist;
95
- });
96
-
97
- it('does not render the date picker when disabled', async () => {
98
- const el = await fixture<CollectionFacets>(
99
- html`<collection-facets></collection-facets>`,
100
- );
101
-
102
- el.histogramAggregationLoading = false;
103
- el.showHistogramDatePicker = false;
104
- el.histogramAggregation = new Aggregation({
105
- buckets: [1, 2, 3],
106
- first_bucket_key: 0,
107
- last_bucket_key: 2,
108
- });
109
- await el.updateComplete;
110
-
111
- const histogram = el.shadowRoot?.querySelector('histogram-date-range');
112
- expect(histogram).to.be.null;
113
- });
114
-
115
- it('renders button to expand the date picker when allowed', async () => {
116
- const el = await fixture<CollectionFacets>(
117
- html`<collection-facets></collection-facets>`,
118
- );
119
-
120
- el.histogramAggregationLoading = false;
121
- el.showHistogramDatePicker = true;
122
- el.allowExpandingDatePicker = true;
123
- el.histogramAggregation = new Aggregation({
124
- buckets: [1, 2, 3],
125
- first_bucket_key: 0,
126
- last_bucket_key: 2,
127
- });
128
- await el.updateComplete;
129
-
130
- const expandBtn = el.shadowRoot?.querySelector('.expand-date-picker-btn');
131
- expect(expandBtn).to.exist;
132
- });
133
-
134
- it('does not render button to expand the date picker when disallowed', async () => {
135
- const el = await fixture<CollectionFacets>(
136
- html`<collection-facets></collection-facets>`,
137
- );
138
-
139
- el.histogramAggregationLoading = false;
140
- el.showHistogramDatePicker = true;
141
- el.allowExpandingDatePicker = false;
142
- el.histogramAggregation = new Aggregation({
143
- buckets: [1, 2, 3],
144
- first_bucket_key: 0,
145
- last_bucket_key: 2,
146
- });
147
- await el.updateComplete;
148
-
149
- const expandBtn = el.shadowRoot?.querySelector('.expand-date-picker-btn');
150
- expect(expandBtn).to.be.null;
151
- });
152
-
153
- it('opens modal when date picker expand button clicked', async () => {
154
- const modalManager = await fixture<ModalManager>(
155
- html`<modal-manager></modal-manager>`,
156
- );
157
-
158
- const el = await fixture<CollectionFacets>(
159
- html`<collection-facets
160
- .modalManager=${modalManager}
161
- ></collection-facets>`,
162
- );
163
-
164
- el.histogramAggregationLoading = false;
165
- el.showHistogramDatePicker = true;
166
- el.allowExpandingDatePicker = true;
167
- el.histogramAggregation = new Aggregation({
168
- buckets: [1, 2, 3],
169
- first_bucket_key: 0,
170
- last_bucket_key: 2,
171
- });
172
- await el.updateComplete;
173
-
174
- const expandBtn = el.shadowRoot?.querySelector(
175
- '.expand-date-picker-btn',
176
- ) as HTMLButtonElement;
177
- expect(expandBtn).to.exist;
178
-
179
- const showModalSpy = sinon.spy(
180
- el.modalManager as ModalManagerInterface,
181
- 'showModal',
182
- );
183
-
184
- // Click the expand button to open the modal
185
- expandBtn?.click();
186
- await el.updateComplete;
187
-
188
- expect(showModalSpy.callCount).to.equal(1);
189
- expect(el.modalManager?.classList.contains('expanded-date-picker')).to.be
190
- .true;
191
- });
192
-
193
- it('renders aggregations as facets', async () => {
194
- const el = await fixture<CollectionFacets>(
195
- html`<collection-facets></collection-facets>`,
196
- );
197
-
198
- const aggs: Record<string, Aggregation> = {
199
- subject: new Aggregation({
200
- buckets: [
201
- {
202
- key: 'foo',
203
- doc_count: 5,
204
- },
205
- ],
206
- }),
207
- };
208
-
209
- el.aggregations = aggs;
210
- await el.updateComplete;
211
- const facetGroups = el.shadowRoot?.querySelectorAll('.facet-group');
212
- expect(facetGroups?.length).to.equal(1);
213
-
214
- const titleFacetGroup = facetGroups?.[0];
215
- const facetGroupHeader = titleFacetGroup?.querySelector('h3');
216
- // Every facet group header has an invisible " filters" suffix for screen-readers
217
- expect(
218
- facetGroupHeader?.querySelector('span.sr-only')?.textContent?.trim(),
219
- ).to.equal('filters');
220
- // Ignoring the screen-reader suffix, we should be left with only the readable, capitalized title
221
- expect(
222
- facetGroupHeader?.textContent?.trim().replace(/\s*filters$/, ''),
223
- ).to.equal('Subject');
224
-
225
- const titleFacetRow = titleFacetGroup
226
- ?.querySelector('facets-template')
227
- ?.shadowRoot?.querySelector('facet-row') as FacetRow;
228
- await titleFacetRow.updateComplete;
229
- });
230
-
231
- it('renders multiple aggregation types', async () => {
232
- const el = await fixture<CollectionFacets>(
233
- html`<collection-facets></collection-facets>`,
234
- );
235
-
236
- const aggs: Record<string, Aggregation> = {
237
- subject: new Aggregation({
238
- buckets: [
239
- {
240
- key: 'foo',
241
- doc_count: 5,
242
- },
243
- ],
244
- }),
245
- mediatype: new Aggregation({
246
- buckets: [
247
- {
248
- key: 'bar',
249
- doc_count: 10,
250
- },
251
- ],
252
- }),
253
- };
254
-
255
- el.aggregations = aggs;
256
- await el.updateComplete;
257
-
258
- const facetGroups = el.shadowRoot?.querySelectorAll('.facet-group');
259
- expect(facetGroups?.length).to.equal(2);
260
- });
261
-
262
- it('does not render suppressed collection facets', async () => {
263
- const el = await fixture<CollectionFacets>(
264
- html`<collection-facets></collection-facets>`,
265
- );
266
-
267
- const aggs: Record<string, Aggregation> = {
268
- collection: new Aggregation({
269
- buckets: [
270
- {
271
- key: 'deemphasize',
272
- doc_count: 5,
273
- },
274
- {
275
- key: 'community',
276
- doc_count: 5,
277
- },
278
- {
279
- key: 'foo',
280
- doc_count: 5,
281
- },
282
- ],
283
- }),
284
- };
285
-
286
- el.aggregations = aggs;
287
- await el.updateComplete;
288
-
289
- const collectionFacets = el.shadowRoot
290
- ?.querySelector('facets-template')
291
- ?.shadowRoot?.querySelectorAll('facet-row') as ArrayLike<FacetRow>;
292
- expect(collectionFacets?.length).to.equal(1);
293
-
294
- // The first (and only) collection link should be for 'foo'
295
- expect(collectionFacets[0].bucket?.key).to.equal('foo');
296
- });
297
-
298
- // Lending tests disabled because lending facet disabled
299
- // it('renders lending facets with human-readable names', async () => {
300
- // const el = await fixture<CollectionFacets>(
301
- // html`<collection-facets></collection-facets>`
302
- // );
303
-
304
- // const aggs: Record<string, Aggregation> = {
305
- // lending: new Aggregation({
306
- // buckets: [
307
- // {
308
- // key: 'is_lendable',
309
- // doc_count: 3,
310
- // },
311
- // {
312
- // key: 'available_to_borrow',
313
- // doc_count: 2,
314
- // },
315
- // {
316
- // key: 'is_readable',
317
- // doc_count: 1,
318
- // },
319
- // ],
320
- // }),
321
- // };
322
-
323
- // el.aggregations = aggs;
324
- // await el.updateComplete;
325
-
326
- // const facetsTemplate = el.shadowRoot?.querySelector(
327
- // 'facets-template'
328
- // ) as FacetsTemplate;
329
- // await facetsTemplate?.updateComplete;
330
-
331
- // const lendingFacets = facetsTemplate?.shadowRoot?.querySelectorAll(
332
- // 'facet-row'
333
- // ) as ArrayLike<FacetRow>;
334
- // expect(lendingFacets?.length).to.equal(3);
335
-
336
- // expect(lendingFacets[0].shadowRoot?.textContent?.trim()).to.match(
337
- // /^Lending Library\s*3$/
338
- // );
339
- // expect(lendingFacets[1].shadowRoot?.textContent?.trim()).to.match(
340
- // /^Borrow 14 Days\s*2$/
341
- // );
342
- // expect(lendingFacets[2].shadowRoot?.textContent?.trim()).to.match(
343
- // /^Always Available\s*1$/
344
- // );
345
- // });
346
-
347
- // it('renders selected/negative lending facets with human-readable names', async () => {
348
- // const el = await fixture<CollectionFacets>(
349
- // html`<collection-facets></collection-facets>`
350
- // );
351
-
352
- // const selectedFacets: SelectedFacets = {
353
- // subject: {},
354
- // lending: {
355
- // is_lendable: {
356
- // key: 'is_lendable',
357
- // count: 5,
358
- // state: 'selected',
359
- // },
360
- // available_to_borrow: {
361
- // key: 'available_to_borrow',
362
- // count: 4,
363
- // state: 'selected',
364
- // },
365
- // is_readable: {
366
- // key: 'is_readable',
367
- // count: 3,
368
- // state: 'hidden',
369
- // },
370
- // },
371
- // mediatype: {},
372
- // language: {},
373
- // creator: {},
374
- // collection: {},
375
- // year: {},
376
- // };
377
-
378
- // el.selectedFacets = selectedFacets;
379
- // await el.updateComplete;
380
-
381
- // const facetsTemplate = el.shadowRoot?.querySelector(
382
- // 'facets-template'
383
- // ) as FacetsTemplate;
384
- // await facetsTemplate?.updateComplete;
385
-
386
- // const lendingFacets = facetsTemplate?.shadowRoot?.querySelectorAll(
387
- // 'facet-row'
388
- // ) as ArrayLike<FacetRow>;
389
- // expect(lendingFacets?.length).to.equal(3);
390
-
391
- // expect(lendingFacets[0].shadowRoot?.textContent?.trim()).to.match(
392
- // /^Lending Library\s*5$/
393
- // );
394
- // expect(lendingFacets[1].shadowRoot?.textContent?.trim()).to.match(
395
- // /^Borrow 14 Days\s*4$/
396
- // );
397
- // expect(lendingFacets[2].shadowRoot?.textContent?.trim()).to.match(
398
- // /^Always Available\s*3$/
399
- // );
400
- // });
401
-
402
- // it('only renders lending facets for is_lendable, available_to_borrow, and is_readable', async () => {
403
- // const el = await fixture<CollectionFacets>(
404
- // html`<collection-facets></collection-facets>`
405
- // );
406
-
407
- // const aggs: Record<string, Aggregation> = {
408
- // lending: new Aggregation({
409
- // buckets: [
410
- // {
411
- // key: 'is_lendable',
412
- // doc_count: 5,
413
- // },
414
- // {
415
- // key: 'is_borrowable',
416
- // doc_count: 4,
417
- // },
418
- // {
419
- // key: 'available_to_borrow',
420
- // doc_count: 5,
421
- // },
422
- // {
423
- // key: 'is_browsable',
424
- // doc_count: 4,
425
- // },
426
- // {
427
- // key: 'available_to_browse',
428
- // doc_count: 5,
429
- // },
430
- // {
431
- // key: 'is_readable',
432
- // doc_count: 4,
433
- // },
434
- // {
435
- // key: 'available_to_waitlist',
436
- // doc_count: 5,
437
- // },
438
- // ],
439
- // }),
440
- // };
441
-
442
- // el.aggregations = aggs;
443
- // await el.updateComplete;
444
-
445
- // const facetsTemplate = el.shadowRoot?.querySelector(
446
- // 'facets-template'
447
- // ) as FacetsTemplate;
448
- // await facetsTemplate?.updateComplete;
449
- // await new Promise(res => {
450
- // setTimeout(res, 100);
451
- // });
452
-
453
- // const lendingFacets = facetsTemplate?.shadowRoot?.querySelectorAll(
454
- // 'facet-row'
455
- // ) as ArrayLike<FacetRow>;
456
- // expect(lendingFacets?.length).to.equal(3);
457
-
458
- // expect(lendingFacets[0].shadowRoot?.textContent?.trim()).to.match(
459
- // /^Lending Library\s*5$/
460
- // );
461
- // expect(lendingFacets[1].shadowRoot?.textContent?.trim()).to.match(
462
- // /^Borrow 14 Days\s*5$/
463
- // );
464
- // expect(lendingFacets[2].shadowRoot?.textContent?.trim()).to.match(
465
- // /^Always Available\s*4$/
466
- // );
467
- // });
468
-
469
- // it('does not render a More... link for lending facets', async () => {
470
- // const el = await fixture<CollectionFacets>(
471
- // html`<collection-facets></collection-facets>`
472
- // );
473
-
474
- // const aggs: Record<string, Aggregation> = {
475
- // lending: new Aggregation({
476
- // buckets: [
477
- // {
478
- // key: 'is_lendable',
479
- // doc_count: 5,
480
- // },
481
- // {
482
- // key: 'is_borrowable',
483
- // doc_count: 4,
484
- // },
485
- // {
486
- // key: 'available_to_borrow',
487
- // doc_count: 5,
488
- // },
489
- // {
490
- // key: 'is_browsable',
491
- // doc_count: 4,
492
- // },
493
- // {
494
- // key: 'available_to_browse',
495
- // doc_count: 5,
496
- // },
497
- // {
498
- // key: 'is_readable',
499
- // doc_count: 4,
500
- // },
501
- // {
502
- // key: 'available_to_waitlist',
503
- // doc_count: 5,
504
- // },
505
- // ],
506
- // }),
507
- // };
508
-
509
- // el.aggregations = aggs;
510
- // await el.updateComplete;
511
-
512
- // const moreLink = el.shadowRoot?.querySelector('.more-link');
513
- // expect(moreLink).not.to.exist;
514
- // });
515
-
516
- it('always renders the mediatype:collection facet when present', async () => {
517
- const el = await fixture<CollectionFacets>(
518
- html`<collection-facets></collection-facets>`,
519
- );
520
-
521
- const aggs: Record<string, Aggregation> = {
522
- mediatype: new Aggregation({
523
- buckets: [
524
- {
525
- key: 'texts',
526
- doc_count: 10000,
527
- },
528
- {
529
- key: 'image',
530
- doc_count: 9000,
531
- },
532
- {
533
- key: 'audio',
534
- doc_count: 8000,
535
- },
536
- {
537
- key: 'movies',
538
- doc_count: 7000,
539
- },
540
- {
541
- key: 'software',
542
- doc_count: 6000,
543
- },
544
- {
545
- key: 'data',
546
- doc_count: 5000,
547
- },
548
- {
549
- key: 'etree',
550
- doc_count: 4000,
551
- },
552
- {
553
- key: 'collection',
554
- doc_count: 1,
555
- },
556
- ],
557
- }),
558
- };
559
-
560
- el.aggregations = aggs;
561
- await el.updateComplete;
562
-
563
- const facetsTemplate = el.shadowRoot?.querySelector('facets-template');
564
- const facetRows = facetsTemplate?.shadowRoot?.querySelectorAll(
565
- 'facet-row',
566
- ) as ArrayLike<FacetRow>;
567
- expect(facetRows?.length).to.equal(6);
568
- expect(facetRows?.[5]?.bucket?.key).to.equal('collection');
569
- });
570
-
571
- it('renders the mediatype:collection facet even when >=6 other mediatypes are selected', async () => {
572
- const el = await fixture<CollectionFacets>(
573
- html`<collection-facets></collection-facets>`,
574
- );
575
-
576
- const aggs: Record<string, Aggregation> = {
577
- mediatype: new Aggregation({
578
- buckets: [
579
- {
580
- key: 'texts',
581
- doc_count: 10000,
582
- },
583
- {
584
- key: 'image',
585
- doc_count: 9000,
586
- },
587
- {
588
- key: 'audio',
589
- doc_count: 8000,
590
- },
591
- {
592
- key: 'movies',
593
- doc_count: 7000,
594
- },
595
- {
596
- key: 'software',
597
- doc_count: 6000,
598
- },
599
- {
600
- key: 'data',
601
- doc_count: 5000,
602
- },
603
- {
604
- key: 'etree',
605
- doc_count: 4000,
606
- },
607
- {
608
- key: 'collection',
609
- doc_count: 1,
610
- },
611
- ],
612
- }),
613
- };
614
-
615
- const selectedFacets = getDefaultSelectedFacets();
616
- selectedFacets.mediatype = {
617
- texts: { key: 'texts', count: 10000, state: 'selected' },
618
- image: { key: 'image', count: 9000, state: 'selected' },
619
- audio: { key: 'audio', count: 8000, state: 'selected' },
620
- movies: { key: 'movies', count: 7000, state: 'selected' },
621
- software: { key: 'software', count: 6000, state: 'selected' },
622
- data: { key: 'data', count: 5000, state: 'selected' },
623
- etree: { key: 'etree', count: 4000, state: 'selected' },
624
- };
625
-
626
- el.aggregations = aggs;
627
- el.selectedFacets = selectedFacets;
628
- await el.updateComplete;
629
-
630
- const facetsTemplate = el.shadowRoot?.querySelector('facets-template');
631
- const facetRows = facetsTemplate?.shadowRoot?.querySelectorAll(
632
- 'facet-row',
633
- ) as ArrayLike<FacetRow>;
634
- expect(facetRows?.length).to.equal(8);
635
- expect(facetRows?.[7]?.bucket?.key).to.equal('collection');
636
- });
637
-
638
- it('uses specified facet display order', async () => {
639
- const el = await fixture<CollectionFacets>(
640
- html`<collection-facets
641
- .facetDisplayOrder=${['language', 'creator'] as FacetOption[]}
642
- ></collection-facets>`,
643
- );
644
-
645
- const aggs: Record<string, Aggregation> = {
646
- mediatype: new Aggregation({
647
- buckets: [{ key: 'texts', doc_count: 5 }],
648
- }),
649
- collection: new Aggregation({
650
- buckets: [{ key: 'foo', doc_count: 10 }],
651
- }),
652
- creator: new Aggregation({
653
- buckets: [{ key: 'bar', doc_count: 15 }],
654
- }),
655
- language: new Aggregation({
656
- buckets: [{ key: 'baz', doc_count: 20 }],
657
- }),
658
- };
659
-
660
- el.aggregations = aggs;
661
- await el.updateComplete;
662
-
663
- const facetHeaders = el.shadowRoot?.querySelectorAll('.facet-group-header');
664
-
665
- // The only two facet groups should be Language and Creator (in that order)
666
- expect(facetHeaders?.length).to.equal(2);
667
- expect(facetHeaders?.[0].textContent).to.contain('Language');
668
- expect(facetHeaders?.[1].textContent).to.contain('Creator');
669
- });
670
-
671
- describe('More Facets', () => {
672
- it('Does not render < allowedFacetCount', async () => {
673
- const el = await fixture<CollectionFacets>(
674
- html`<collection-facets></collection-facets>`,
675
- );
676
-
677
- const aggs: Record<string, Aggregation> = {
678
- subject: new Aggregation({
679
- buckets: [
680
- {
681
- key: 'foo',
682
- doc_count: 5,
683
- },
684
- ],
685
- }),
686
- };
687
-
688
- el.aggregations = aggs;
689
- await el.updateComplete;
690
-
691
- const moreLink = el.shadowRoot?.querySelector('.more-link');
692
- expect(moreLink).to.be.null;
693
- });
694
-
695
- it('Render More Facets', async () => {
696
- const modalManager = await fixture<ModalManager>(
697
- html`<modal-manager></modal-manager>`,
698
- );
699
-
700
- const el = await fixture<CollectionFacets>(
701
- html`<collection-facets
702
- .modalManager=${modalManager}
703
- ></collection-facets>`,
704
- );
705
-
706
- const aggs: Record<string, Aggregation> = {
707
- subject: new Aggregation({
708
- buckets: [
709
- {
710
- key: 'foo',
711
- doc_count: 5,
712
- },
713
- {
714
- key: 'fi',
715
- doc_count: 5,
716
- },
717
- {
718
- key: 'fum',
719
- doc_count: 5,
720
- },
721
- {
722
- key: 'flee',
723
- doc_count: 5,
724
- },
725
- {
726
- key: 'wheee',
727
- doc_count: 5,
728
- },
729
- {
730
- key: 'whooo',
731
- doc_count: 5,
732
- },
733
- {
734
- key: 'boop',
735
- doc_count: 5,
736
- },
737
- ],
738
- }),
739
- };
740
-
741
- el.aggregations = aggs;
742
- await el.updateComplete;
743
-
744
- let eventCaught = false;
745
- let eventFacet = '';
746
- el.addEventListener('showMoreFacets', e => {
747
- eventFacet = (e as CustomEvent).detail;
748
- eventCaught = true;
749
- });
750
-
751
- const moreLink = el.shadowRoot?.querySelector(
752
- '.more-link',
753
- ) as HTMLButtonElement;
754
- expect(moreLink).to.exist; // has link
755
-
756
- const showModalSpy = sinon.spy(
757
- el.modalManager as ModalManagerInterface,
758
- 'showModal',
759
- );
760
- // let's pop up modal
761
- moreLink?.click();
762
- await el.updateComplete;
763
-
764
- expect(showModalSpy.callCount).to.equal(1);
765
- expect(el.modalManager?.classList.contains('more-search-facets')).to.be
766
- .true;
767
- expect(eventCaught).to.be.true;
768
- expect(eventFacet).to.equal('subject' as FacetOption);
769
- });
770
- });
771
-
772
- it('fire analytics on more link', async () => {
773
- const mockAnalyticsHandler = new MockAnalyticsHandler();
774
-
775
- const el = await fixture<CollectionFacets>(
776
- html`<collection-facets
777
- .analyticsHandler=${mockAnalyticsHandler}
778
- ></collection-facets>`,
779
- );
780
- const aggs: Record<string, Aggregation> = {
781
- subject: new Aggregation({
782
- buckets: [
783
- {
784
- key: 'foo',
785
- doc_count: 5,
786
- },
787
- {
788
- key: 'fi',
789
- doc_count: 5,
790
- },
791
- {
792
- key: 'fum',
793
- doc_count: 5,
794
- },
795
- {
796
- key: 'flee',
797
- doc_count: 5,
798
- },
799
- {
800
- key: 'wheee',
801
- doc_count: 5,
802
- },
803
- {
804
- key: 'whooo',
805
- doc_count: 5,
806
- },
807
- {
808
- key: 'boop',
809
- doc_count: 5,
810
- },
811
- ],
812
- }),
813
- };
814
-
815
- el.aggregations = aggs;
816
- await el.updateComplete;
817
-
818
- const moreLink = el.shadowRoot?.querySelector(
819
- '.more-link',
820
- ) as HTMLButtonElement;
821
-
822
- expect(moreLink).to.exist; // has link
823
-
824
- moreLink?.click();
825
- await el.updateComplete;
826
-
827
- expect(mockAnalyticsHandler.callCategory).to.equal('collection-browser');
828
- expect(mockAnalyticsHandler.callAction).to.equal('showMoreFacetsModal');
829
- expect(mockAnalyticsHandler.callLabel).to.equal('subject');
830
- });
831
-
832
- it('includes Part Of section for collections', async () => {
833
- const el = await fixture<CollectionFacets>(
834
- html`<collection-facets
835
- .baseNavigationUrl=${''}
836
- .withinCollection=${'foo'}
837
- .parentCollections=${['bar', 'baz']}
838
- .collectionTitles=${new Map([
839
- ['foo', 'foo-name'],
840
- ['bar', 'bar-name'],
841
- ['baz', 'baz-name'],
842
- ])}
843
- ></collection-facets>`,
844
- );
845
-
846
- const partOfSection = el.shadowRoot?.querySelector('.partof-collections');
847
- expect(partOfSection).to.exist;
848
-
849
- const partOfLinks = partOfSection?.querySelectorAll('a[href]');
850
- expect(partOfLinks?.length).to.equal(2);
851
-
852
- expect(partOfLinks?.[0]?.textContent?.trim()).to.equal('bar-name');
853
- expect(partOfLinks?.[0]?.getAttribute('href')).to.equal('/details/bar');
854
- expect(partOfLinks?.[1]?.textContent?.trim()).to.equal('baz-name');
855
- expect(partOfLinks?.[1]?.getAttribute('href')).to.equal('/details/baz');
856
- });
857
-
858
- it('does not include Part Of section without parent collections', async () => {
859
- // No parentCollections prop
860
- const el = await fixture<CollectionFacets>(
861
- html`<collection-facets .withinCollection=${'foo'}></collection-facets>`,
862
- );
863
-
864
- const partOfSection = el.shadowRoot?.querySelector('.partof-collections');
865
- expect(partOfSection).not.to.exist;
866
- });
867
-
868
- it('fires analytics on expanding date picker', async () => {
869
- const mockAnalyticsHandler = new MockAnalyticsHandler();
870
-
871
- const el = await fixture<CollectionFacets>(
872
- html`<collection-facets
873
- .analyticsHandler=${mockAnalyticsHandler}
874
- ></collection-facets>`,
875
- );
876
-
877
- el.histogramAggregationLoading = false;
878
- el.showHistogramDatePicker = true;
879
- el.allowExpandingDatePicker = true;
880
- el.histogramAggregation = new Aggregation({
881
- buckets: [1, 2, 3],
882
- first_bucket_key: 0,
883
- last_bucket_key: 2,
884
- });
885
- await el.updateComplete;
886
-
887
- const expandBtn = el.shadowRoot?.querySelector(
888
- '.expand-date-picker-btn',
889
- ) as HTMLButtonElement;
890
- expect(expandBtn).to.exist;
891
-
892
- // Click the expand button to open the modal
893
- expandBtn?.click();
894
- await el.updateComplete;
895
-
896
- expect(mockAnalyticsHandler.callCategory).to.equal('collection-browser');
897
- expect(mockAnalyticsHandler.callAction).to.equal('histogramExpanded');
898
- expect(mockAnalyticsHandler.callLabel).to.equal(window.location.href);
899
- });
900
-
901
- it('fires analytics on clicking Part Of collection link', async () => {
902
- const mockAnalyticsHandler = new MockAnalyticsHandler();
903
-
904
- const el = await fixture<CollectionFacets>(
905
- html`<collection-facets
906
- .baseNavigationUrl=${''}
907
- .withinCollection=${'foo'}
908
- .parentCollections=${['bar']}
909
- .analyticsHandler=${mockAnalyticsHandler}
910
- ></collection-facets>`,
911
- );
912
-
913
- const partOfLinks = el.shadowRoot?.querySelectorAll(
914
- '.partof-collections a[href]',
915
- );
916
- expect(partOfLinks?.length).to.equal(1);
917
-
918
- // Click the expand button to open the modal
919
- const link = partOfLinks?.[0] as HTMLAnchorElement;
920
- link?.addEventListener('click', e => e.preventDefault());
921
- link?.click();
922
- await el.updateComplete;
923
-
924
- expect(mockAnalyticsHandler.callCategory).to.equal('collection-browser');
925
- expect(mockAnalyticsHandler.callAction).to.equal('partOfCollectionClicked');
926
- expect(mockAnalyticsHandler.callLabel).to.equal('bar');
927
- });
928
- });
1
+ import { expect, fixture } from '@open-wc/testing';
2
+ import sinon from 'sinon';
3
+ import { html } from 'lit';
4
+ import { Aggregation } from '@internetarchive/search-service';
5
+ import {
6
+ ModalManager,
7
+ ModalManagerInterface,
8
+ } from '@internetarchive/modal-manager';
9
+ import type { CollectionFacets } from '../src/collection-facets';
10
+ import '@internetarchive/modal-manager';
11
+ import '../src/collection-facets';
12
+ import {
13
+ FacetOption,
14
+ // SelectedFacets, Used in lending tests (disabled)
15
+ getDefaultSelectedFacets,
16
+ } from '../src/models';
17
+ import { MockAnalyticsHandler } from './mocks/mock-analytics-handler';
18
+ import type { FacetRow } from '../src/collection-facets/facet-row';
19
+ // import type { FacetsTemplate } from '../src/collection-facets/facets-template'; Used in lending tests (disabled)
20
+
21
+ describe('Collection Facets', () => {
22
+ it('has loader', async () => {
23
+ const el = await fixture<CollectionFacets>(
24
+ html`<collection-facets ?facetsLoading=${true}></collection-facets>`,
25
+ );
26
+
27
+ expect(
28
+ el.shadowRoot?.querySelector('#container')?.classList.contains('loading'),
29
+ ).to.be.true;
30
+
31
+ el.facetsLoading = false;
32
+ await el.updateComplete;
33
+
34
+ expect(
35
+ el.shadowRoot?.querySelector('#container')?.classList.contains('loading'),
36
+ ).to.be.false;
37
+ });
38
+
39
+ it('renders a date picker loading placeholder when date picker enabled', async () => {
40
+ const el = await fixture<CollectionFacets>(
41
+ html`<collection-facets></collection-facets>`,
42
+ );
43
+
44
+ el.histogramAggregationLoading = true;
45
+ el.showHistogramDatePicker = true;
46
+ el.histogramAggregation = new Aggregation({
47
+ buckets: [1, 2, 3],
48
+ first_bucket_key: 0,
49
+ last_bucket_key: 2,
50
+ });
51
+ await el.updateComplete;
52
+
53
+ const histogramLoader = el.shadowRoot?.querySelector(
54
+ '.histogram-loading-indicator',
55
+ );
56
+ expect(histogramLoader).to.exist;
57
+ });
58
+
59
+ it('does not render a date picker loading placeholder when date picker disabled', async () => {
60
+ const el = await fixture<CollectionFacets>(
61
+ html`<collection-facets></collection-facets>`,
62
+ );
63
+
64
+ el.histogramAggregationLoading = true;
65
+ el.showHistogramDatePicker = false;
66
+ el.histogramAggregation = new Aggregation({
67
+ buckets: [1, 2, 3],
68
+ first_bucket_key: 0,
69
+ last_bucket_key: 2,
70
+ });
71
+ await el.updateComplete;
72
+
73
+ const histogramLoader = el.shadowRoot?.querySelector(
74
+ '.histogram-loading-indicator',
75
+ );
76
+ expect(histogramLoader).to.be.null;
77
+ });
78
+
79
+ it('renders the date picker when enabled with data present', async () => {
80
+ const el = await fixture<CollectionFacets>(
81
+ html`<collection-facets></collection-facets>`,
82
+ );
83
+
84
+ el.histogramAggregationLoading = false;
85
+ el.showHistogramDatePicker = true;
86
+ el.histogramAggregation = new Aggregation({
87
+ buckets: [1, 2, 3],
88
+ first_bucket_key: 0,
89
+ last_bucket_key: 2,
90
+ });
91
+ await el.updateComplete;
92
+
93
+ const histogram = el.shadowRoot?.querySelector('histogram-date-range');
94
+ expect(histogram).to.exist;
95
+ });
96
+
97
+ it('does not render the date picker when disabled', async () => {
98
+ const el = await fixture<CollectionFacets>(
99
+ html`<collection-facets></collection-facets>`,
100
+ );
101
+
102
+ el.histogramAggregationLoading = false;
103
+ el.showHistogramDatePicker = false;
104
+ el.histogramAggregation = new Aggregation({
105
+ buckets: [1, 2, 3],
106
+ first_bucket_key: 0,
107
+ last_bucket_key: 2,
108
+ });
109
+ await el.updateComplete;
110
+
111
+ const histogram = el.shadowRoot?.querySelector('histogram-date-range');
112
+ expect(histogram).to.be.null;
113
+ });
114
+
115
+ it('renders button to expand the date picker when allowed', async () => {
116
+ const el = await fixture<CollectionFacets>(
117
+ html`<collection-facets></collection-facets>`,
118
+ );
119
+
120
+ el.histogramAggregationLoading = false;
121
+ el.showHistogramDatePicker = true;
122
+ el.allowExpandingDatePicker = true;
123
+ el.histogramAggregation = new Aggregation({
124
+ buckets: [1, 2, 3],
125
+ first_bucket_key: 0,
126
+ last_bucket_key: 2,
127
+ });
128
+ await el.updateComplete;
129
+
130
+ const expandBtn = el.shadowRoot?.querySelector('.expand-date-picker-btn');
131
+ expect(expandBtn).to.exist;
132
+ });
133
+
134
+ it('does not render button to expand the date picker when disallowed', async () => {
135
+ const el = await fixture<CollectionFacets>(
136
+ html`<collection-facets></collection-facets>`,
137
+ );
138
+
139
+ el.histogramAggregationLoading = false;
140
+ el.showHistogramDatePicker = true;
141
+ el.allowExpandingDatePicker = false;
142
+ el.histogramAggregation = new Aggregation({
143
+ buckets: [1, 2, 3],
144
+ first_bucket_key: 0,
145
+ last_bucket_key: 2,
146
+ });
147
+ await el.updateComplete;
148
+
149
+ const expandBtn = el.shadowRoot?.querySelector('.expand-date-picker-btn');
150
+ expect(expandBtn).to.be.null;
151
+ });
152
+
153
+ it('opens modal when date picker expand button clicked', async () => {
154
+ const modalManager = await fixture<ModalManager>(
155
+ html`<modal-manager></modal-manager>`,
156
+ );
157
+
158
+ const el = await fixture<CollectionFacets>(
159
+ html`<collection-facets
160
+ .modalManager=${modalManager}
161
+ ></collection-facets>`,
162
+ );
163
+
164
+ el.histogramAggregationLoading = false;
165
+ el.showHistogramDatePicker = true;
166
+ el.allowExpandingDatePicker = true;
167
+ el.histogramAggregation = new Aggregation({
168
+ buckets: [1, 2, 3],
169
+ first_bucket_key: 0,
170
+ last_bucket_key: 2,
171
+ });
172
+ await el.updateComplete;
173
+
174
+ const expandBtn = el.shadowRoot?.querySelector(
175
+ '.expand-date-picker-btn',
176
+ ) as HTMLButtonElement;
177
+ expect(expandBtn).to.exist;
178
+
179
+ const showModalSpy = sinon.spy(
180
+ el.modalManager as ModalManagerInterface,
181
+ 'showModal',
182
+ );
183
+
184
+ // Click the expand button to open the modal
185
+ expandBtn?.click();
186
+ await el.updateComplete;
187
+
188
+ expect(showModalSpy.callCount).to.equal(1);
189
+ expect(el.modalManager?.classList.contains('expanded-date-picker')).to.be
190
+ .true;
191
+ });
192
+
193
+ it('renders aggregations as facets', async () => {
194
+ const el = await fixture<CollectionFacets>(
195
+ html`<collection-facets></collection-facets>`,
196
+ );
197
+
198
+ const aggs: Record<string, Aggregation> = {
199
+ subject: new Aggregation({
200
+ buckets: [
201
+ {
202
+ key: 'foo',
203
+ doc_count: 5,
204
+ },
205
+ ],
206
+ }),
207
+ };
208
+
209
+ el.aggregations = aggs;
210
+ await el.updateComplete;
211
+ const facetGroups = el.shadowRoot?.querySelectorAll('.facet-group');
212
+ expect(facetGroups?.length).to.equal(1);
213
+
214
+ const titleFacetGroup = facetGroups?.[0];
215
+ const facetGroupHeader = titleFacetGroup?.querySelector('h3');
216
+ // Every facet group header has an invisible " filters" suffix for screen-readers
217
+ expect(
218
+ facetGroupHeader?.querySelector('span.sr-only')?.textContent?.trim(),
219
+ ).to.equal('filters');
220
+ // Ignoring the screen-reader suffix, we should be left with only the readable, capitalized title
221
+ expect(
222
+ facetGroupHeader?.textContent?.trim().replace(/\s*filters$/, ''),
223
+ ).to.equal('Subject');
224
+
225
+ const titleFacetRow = titleFacetGroup
226
+ ?.querySelector('facets-template')
227
+ ?.shadowRoot?.querySelector('facet-row') as FacetRow;
228
+ await titleFacetRow.updateComplete;
229
+ });
230
+
231
+ it('renders multiple aggregation types', async () => {
232
+ const el = await fixture<CollectionFacets>(
233
+ html`<collection-facets></collection-facets>`,
234
+ );
235
+
236
+ const aggs: Record<string, Aggregation> = {
237
+ subject: new Aggregation({
238
+ buckets: [
239
+ {
240
+ key: 'foo',
241
+ doc_count: 5,
242
+ },
243
+ ],
244
+ }),
245
+ mediatype: new Aggregation({
246
+ buckets: [
247
+ {
248
+ key: 'bar',
249
+ doc_count: 10,
250
+ },
251
+ ],
252
+ }),
253
+ };
254
+
255
+ el.aggregations = aggs;
256
+ await el.updateComplete;
257
+
258
+ const facetGroups = el.shadowRoot?.querySelectorAll('.facet-group');
259
+ expect(facetGroups?.length).to.equal(2);
260
+ });
261
+
262
+ it('does not render suppressed collection facets', async () => {
263
+ const el = await fixture<CollectionFacets>(
264
+ html`<collection-facets></collection-facets>`,
265
+ );
266
+
267
+ const aggs: Record<string, Aggregation> = {
268
+ collection: new Aggregation({
269
+ buckets: [
270
+ {
271
+ key: 'deemphasize',
272
+ doc_count: 5,
273
+ },
274
+ {
275
+ key: 'community',
276
+ doc_count: 5,
277
+ },
278
+ {
279
+ key: 'foo',
280
+ doc_count: 5,
281
+ },
282
+ ],
283
+ }),
284
+ };
285
+
286
+ el.aggregations = aggs;
287
+ await el.updateComplete;
288
+
289
+ const collectionFacets = el.shadowRoot
290
+ ?.querySelector('facets-template')
291
+ ?.shadowRoot?.querySelectorAll('facet-row') as ArrayLike<FacetRow>;
292
+ expect(collectionFacets?.length).to.equal(1);
293
+
294
+ // The first (and only) collection link should be for 'foo'
295
+ expect(collectionFacets[0].bucket?.key).to.equal('foo');
296
+ });
297
+
298
+ // Lending tests disabled because lending facet disabled
299
+ // it('renders lending facets with human-readable names', async () => {
300
+ // const el = await fixture<CollectionFacets>(
301
+ // html`<collection-facets></collection-facets>`
302
+ // );
303
+
304
+ // const aggs: Record<string, Aggregation> = {
305
+ // lending: new Aggregation({
306
+ // buckets: [
307
+ // {
308
+ // key: 'is_lendable',
309
+ // doc_count: 3,
310
+ // },
311
+ // {
312
+ // key: 'available_to_borrow',
313
+ // doc_count: 2,
314
+ // },
315
+ // {
316
+ // key: 'is_readable',
317
+ // doc_count: 1,
318
+ // },
319
+ // ],
320
+ // }),
321
+ // };
322
+
323
+ // el.aggregations = aggs;
324
+ // await el.updateComplete;
325
+
326
+ // const facetsTemplate = el.shadowRoot?.querySelector(
327
+ // 'facets-template'
328
+ // ) as FacetsTemplate;
329
+ // await facetsTemplate?.updateComplete;
330
+
331
+ // const lendingFacets = facetsTemplate?.shadowRoot?.querySelectorAll(
332
+ // 'facet-row'
333
+ // ) as ArrayLike<FacetRow>;
334
+ // expect(lendingFacets?.length).to.equal(3);
335
+
336
+ // expect(lendingFacets[0].shadowRoot?.textContent?.trim()).to.match(
337
+ // /^Lending Library\s*3$/
338
+ // );
339
+ // expect(lendingFacets[1].shadowRoot?.textContent?.trim()).to.match(
340
+ // /^Borrow 14 Days\s*2$/
341
+ // );
342
+ // expect(lendingFacets[2].shadowRoot?.textContent?.trim()).to.match(
343
+ // /^Always Available\s*1$/
344
+ // );
345
+ // });
346
+
347
+ // it('renders selected/negative lending facets with human-readable names', async () => {
348
+ // const el = await fixture<CollectionFacets>(
349
+ // html`<collection-facets></collection-facets>`
350
+ // );
351
+
352
+ // const selectedFacets: SelectedFacets = {
353
+ // subject: {},
354
+ // lending: {
355
+ // is_lendable: {
356
+ // key: 'is_lendable',
357
+ // count: 5,
358
+ // state: 'selected',
359
+ // },
360
+ // available_to_borrow: {
361
+ // key: 'available_to_borrow',
362
+ // count: 4,
363
+ // state: 'selected',
364
+ // },
365
+ // is_readable: {
366
+ // key: 'is_readable',
367
+ // count: 3,
368
+ // state: 'hidden',
369
+ // },
370
+ // },
371
+ // mediatype: {},
372
+ // language: {},
373
+ // creator: {},
374
+ // collection: {},
375
+ // year: {},
376
+ // };
377
+
378
+ // el.selectedFacets = selectedFacets;
379
+ // await el.updateComplete;
380
+
381
+ // const facetsTemplate = el.shadowRoot?.querySelector(
382
+ // 'facets-template'
383
+ // ) as FacetsTemplate;
384
+ // await facetsTemplate?.updateComplete;
385
+
386
+ // const lendingFacets = facetsTemplate?.shadowRoot?.querySelectorAll(
387
+ // 'facet-row'
388
+ // ) as ArrayLike<FacetRow>;
389
+ // expect(lendingFacets?.length).to.equal(3);
390
+
391
+ // expect(lendingFacets[0].shadowRoot?.textContent?.trim()).to.match(
392
+ // /^Lending Library\s*5$/
393
+ // );
394
+ // expect(lendingFacets[1].shadowRoot?.textContent?.trim()).to.match(
395
+ // /^Borrow 14 Days\s*4$/
396
+ // );
397
+ // expect(lendingFacets[2].shadowRoot?.textContent?.trim()).to.match(
398
+ // /^Always Available\s*3$/
399
+ // );
400
+ // });
401
+
402
+ // it('only renders lending facets for is_lendable, available_to_borrow, and is_readable', async () => {
403
+ // const el = await fixture<CollectionFacets>(
404
+ // html`<collection-facets></collection-facets>`
405
+ // );
406
+
407
+ // const aggs: Record<string, Aggregation> = {
408
+ // lending: new Aggregation({
409
+ // buckets: [
410
+ // {
411
+ // key: 'is_lendable',
412
+ // doc_count: 5,
413
+ // },
414
+ // {
415
+ // key: 'is_borrowable',
416
+ // doc_count: 4,
417
+ // },
418
+ // {
419
+ // key: 'available_to_borrow',
420
+ // doc_count: 5,
421
+ // },
422
+ // {
423
+ // key: 'is_browsable',
424
+ // doc_count: 4,
425
+ // },
426
+ // {
427
+ // key: 'available_to_browse',
428
+ // doc_count: 5,
429
+ // },
430
+ // {
431
+ // key: 'is_readable',
432
+ // doc_count: 4,
433
+ // },
434
+ // {
435
+ // key: 'available_to_waitlist',
436
+ // doc_count: 5,
437
+ // },
438
+ // ],
439
+ // }),
440
+ // };
441
+
442
+ // el.aggregations = aggs;
443
+ // await el.updateComplete;
444
+
445
+ // const facetsTemplate = el.shadowRoot?.querySelector(
446
+ // 'facets-template'
447
+ // ) as FacetsTemplate;
448
+ // await facetsTemplate?.updateComplete;
449
+ // await new Promise(res => {
450
+ // setTimeout(res, 100);
451
+ // });
452
+
453
+ // const lendingFacets = facetsTemplate?.shadowRoot?.querySelectorAll(
454
+ // 'facet-row'
455
+ // ) as ArrayLike<FacetRow>;
456
+ // expect(lendingFacets?.length).to.equal(3);
457
+
458
+ // expect(lendingFacets[0].shadowRoot?.textContent?.trim()).to.match(
459
+ // /^Lending Library\s*5$/
460
+ // );
461
+ // expect(lendingFacets[1].shadowRoot?.textContent?.trim()).to.match(
462
+ // /^Borrow 14 Days\s*5$/
463
+ // );
464
+ // expect(lendingFacets[2].shadowRoot?.textContent?.trim()).to.match(
465
+ // /^Always Available\s*4$/
466
+ // );
467
+ // });
468
+
469
+ // it('does not render a More... link for lending facets', async () => {
470
+ // const el = await fixture<CollectionFacets>(
471
+ // html`<collection-facets></collection-facets>`
472
+ // );
473
+
474
+ // const aggs: Record<string, Aggregation> = {
475
+ // lending: new Aggregation({
476
+ // buckets: [
477
+ // {
478
+ // key: 'is_lendable',
479
+ // doc_count: 5,
480
+ // },
481
+ // {
482
+ // key: 'is_borrowable',
483
+ // doc_count: 4,
484
+ // },
485
+ // {
486
+ // key: 'available_to_borrow',
487
+ // doc_count: 5,
488
+ // },
489
+ // {
490
+ // key: 'is_browsable',
491
+ // doc_count: 4,
492
+ // },
493
+ // {
494
+ // key: 'available_to_browse',
495
+ // doc_count: 5,
496
+ // },
497
+ // {
498
+ // key: 'is_readable',
499
+ // doc_count: 4,
500
+ // },
501
+ // {
502
+ // key: 'available_to_waitlist',
503
+ // doc_count: 5,
504
+ // },
505
+ // ],
506
+ // }),
507
+ // };
508
+
509
+ // el.aggregations = aggs;
510
+ // await el.updateComplete;
511
+
512
+ // const moreLink = el.shadowRoot?.querySelector('.more-link');
513
+ // expect(moreLink).not.to.exist;
514
+ // });
515
+
516
+ it('always renders the mediatype:collection facet when present', async () => {
517
+ const el = await fixture<CollectionFacets>(
518
+ html`<collection-facets></collection-facets>`,
519
+ );
520
+
521
+ const aggs: Record<string, Aggregation> = {
522
+ mediatype: new Aggregation({
523
+ buckets: [
524
+ {
525
+ key: 'texts',
526
+ doc_count: 10000,
527
+ },
528
+ {
529
+ key: 'image',
530
+ doc_count: 9000,
531
+ },
532
+ {
533
+ key: 'audio',
534
+ doc_count: 8000,
535
+ },
536
+ {
537
+ key: 'movies',
538
+ doc_count: 7000,
539
+ },
540
+ {
541
+ key: 'software',
542
+ doc_count: 6000,
543
+ },
544
+ {
545
+ key: 'data',
546
+ doc_count: 5000,
547
+ },
548
+ {
549
+ key: 'etree',
550
+ doc_count: 4000,
551
+ },
552
+ {
553
+ key: 'collection',
554
+ doc_count: 1,
555
+ },
556
+ ],
557
+ }),
558
+ };
559
+
560
+ el.aggregations = aggs;
561
+ await el.updateComplete;
562
+
563
+ const facetsTemplate = el.shadowRoot?.querySelector('facets-template');
564
+ const facetRows = facetsTemplate?.shadowRoot?.querySelectorAll(
565
+ 'facet-row',
566
+ ) as ArrayLike<FacetRow>;
567
+ expect(facetRows?.length).to.equal(6);
568
+ expect(facetRows?.[5]?.bucket?.key).to.equal('collection');
569
+ });
570
+
571
+ it('renders the mediatype:collection facet even when >=6 other mediatypes are selected', async () => {
572
+ const el = await fixture<CollectionFacets>(
573
+ html`<collection-facets></collection-facets>`,
574
+ );
575
+
576
+ const aggs: Record<string, Aggregation> = {
577
+ mediatype: new Aggregation({
578
+ buckets: [
579
+ {
580
+ key: 'texts',
581
+ doc_count: 10000,
582
+ },
583
+ {
584
+ key: 'image',
585
+ doc_count: 9000,
586
+ },
587
+ {
588
+ key: 'audio',
589
+ doc_count: 8000,
590
+ },
591
+ {
592
+ key: 'movies',
593
+ doc_count: 7000,
594
+ },
595
+ {
596
+ key: 'software',
597
+ doc_count: 6000,
598
+ },
599
+ {
600
+ key: 'data',
601
+ doc_count: 5000,
602
+ },
603
+ {
604
+ key: 'etree',
605
+ doc_count: 4000,
606
+ },
607
+ {
608
+ key: 'collection',
609
+ doc_count: 1,
610
+ },
611
+ ],
612
+ }),
613
+ };
614
+
615
+ const selectedFacets = getDefaultSelectedFacets();
616
+ selectedFacets.mediatype = {
617
+ texts: { key: 'texts', count: 10000, state: 'selected' },
618
+ image: { key: 'image', count: 9000, state: 'selected' },
619
+ audio: { key: 'audio', count: 8000, state: 'selected' },
620
+ movies: { key: 'movies', count: 7000, state: 'selected' },
621
+ software: { key: 'software', count: 6000, state: 'selected' },
622
+ data: { key: 'data', count: 5000, state: 'selected' },
623
+ etree: { key: 'etree', count: 4000, state: 'selected' },
624
+ };
625
+
626
+ el.aggregations = aggs;
627
+ el.selectedFacets = selectedFacets;
628
+ await el.updateComplete;
629
+
630
+ const facetsTemplate = el.shadowRoot?.querySelector('facets-template');
631
+ const facetRows = facetsTemplate?.shadowRoot?.querySelectorAll(
632
+ 'facet-row',
633
+ ) as ArrayLike<FacetRow>;
634
+ expect(facetRows?.length).to.equal(8);
635
+ expect(facetRows?.[7]?.bucket?.key).to.equal('collection');
636
+ });
637
+
638
+ it('uses specified facet display order', async () => {
639
+ const el = await fixture<CollectionFacets>(
640
+ html`<collection-facets
641
+ .facetDisplayOrder=${['language', 'creator'] as FacetOption[]}
642
+ ></collection-facets>`,
643
+ );
644
+
645
+ const aggs: Record<string, Aggregation> = {
646
+ mediatype: new Aggregation({
647
+ buckets: [{ key: 'texts', doc_count: 5 }],
648
+ }),
649
+ collection: new Aggregation({
650
+ buckets: [{ key: 'foo', doc_count: 10 }],
651
+ }),
652
+ creator: new Aggregation({
653
+ buckets: [{ key: 'bar', doc_count: 15 }],
654
+ }),
655
+ language: new Aggregation({
656
+ buckets: [{ key: 'baz', doc_count: 20 }],
657
+ }),
658
+ };
659
+
660
+ el.aggregations = aggs;
661
+ await el.updateComplete;
662
+
663
+ const facetHeaders = el.shadowRoot?.querySelectorAll('.facet-group-header');
664
+
665
+ // The only two facet groups should be Language and Creator (in that order)
666
+ expect(facetHeaders?.length).to.equal(2);
667
+ expect(facetHeaders?.[0].textContent).to.contain('Language');
668
+ expect(facetHeaders?.[1].textContent).to.contain('Creator');
669
+ });
670
+
671
+ describe('More Facets', () => {
672
+ it('Does not render < allowedFacetCount', async () => {
673
+ const el = await fixture<CollectionFacets>(
674
+ html`<collection-facets></collection-facets>`,
675
+ );
676
+
677
+ const aggs: Record<string, Aggregation> = {
678
+ subject: new Aggregation({
679
+ buckets: [
680
+ {
681
+ key: 'foo',
682
+ doc_count: 5,
683
+ },
684
+ ],
685
+ }),
686
+ };
687
+
688
+ el.aggregations = aggs;
689
+ await el.updateComplete;
690
+
691
+ const moreLink = el.shadowRoot?.querySelector('.more-link');
692
+ expect(moreLink).to.be.null;
693
+ });
694
+
695
+ it('Render More Facets', async () => {
696
+ const modalManager = await fixture<ModalManager>(
697
+ html`<modal-manager></modal-manager>`,
698
+ );
699
+
700
+ const el = await fixture<CollectionFacets>(
701
+ html`<collection-facets
702
+ .modalManager=${modalManager}
703
+ ></collection-facets>`,
704
+ );
705
+
706
+ const aggs: Record<string, Aggregation> = {
707
+ subject: new Aggregation({
708
+ buckets: [
709
+ {
710
+ key: 'foo',
711
+ doc_count: 5,
712
+ },
713
+ {
714
+ key: 'fi',
715
+ doc_count: 5,
716
+ },
717
+ {
718
+ key: 'fum',
719
+ doc_count: 5,
720
+ },
721
+ {
722
+ key: 'flee',
723
+ doc_count: 5,
724
+ },
725
+ {
726
+ key: 'wheee',
727
+ doc_count: 5,
728
+ },
729
+ {
730
+ key: 'whooo',
731
+ doc_count: 5,
732
+ },
733
+ {
734
+ key: 'boop',
735
+ doc_count: 5,
736
+ },
737
+ ],
738
+ }),
739
+ };
740
+
741
+ el.aggregations = aggs;
742
+ await el.updateComplete;
743
+
744
+ let eventCaught = false;
745
+ let eventFacet = '';
746
+ el.addEventListener('showMoreFacets', e => {
747
+ eventFacet = (e as CustomEvent).detail;
748
+ eventCaught = true;
749
+ });
750
+
751
+ const moreLink = el.shadowRoot?.querySelector(
752
+ '.more-link',
753
+ ) as HTMLButtonElement;
754
+ expect(moreLink).to.exist; // has link
755
+
756
+ const showModalSpy = sinon.spy(
757
+ el.modalManager as ModalManagerInterface,
758
+ 'showModal',
759
+ );
760
+ // let's pop up modal
761
+ moreLink?.click();
762
+ await el.updateComplete;
763
+
764
+ expect(showModalSpy.callCount).to.equal(1);
765
+ expect(el.modalManager?.classList.contains('more-search-facets')).to.be
766
+ .true;
767
+ expect(eventCaught).to.be.true;
768
+ expect(eventFacet).to.equal('subject' as FacetOption);
769
+ });
770
+ });
771
+
772
+ it('fire analytics on more link', async () => {
773
+ const mockAnalyticsHandler = new MockAnalyticsHandler();
774
+
775
+ const el = await fixture<CollectionFacets>(
776
+ html`<collection-facets
777
+ .analyticsHandler=${mockAnalyticsHandler}
778
+ ></collection-facets>`,
779
+ );
780
+ const aggs: Record<string, Aggregation> = {
781
+ subject: new Aggregation({
782
+ buckets: [
783
+ {
784
+ key: 'foo',
785
+ doc_count: 5,
786
+ },
787
+ {
788
+ key: 'fi',
789
+ doc_count: 5,
790
+ },
791
+ {
792
+ key: 'fum',
793
+ doc_count: 5,
794
+ },
795
+ {
796
+ key: 'flee',
797
+ doc_count: 5,
798
+ },
799
+ {
800
+ key: 'wheee',
801
+ doc_count: 5,
802
+ },
803
+ {
804
+ key: 'whooo',
805
+ doc_count: 5,
806
+ },
807
+ {
808
+ key: 'boop',
809
+ doc_count: 5,
810
+ },
811
+ ],
812
+ }),
813
+ };
814
+
815
+ el.aggregations = aggs;
816
+ await el.updateComplete;
817
+
818
+ const moreLink = el.shadowRoot?.querySelector(
819
+ '.more-link',
820
+ ) as HTMLButtonElement;
821
+
822
+ expect(moreLink).to.exist; // has link
823
+
824
+ moreLink?.click();
825
+ await el.updateComplete;
826
+
827
+ expect(mockAnalyticsHandler.callCategory).to.equal('collection-browser');
828
+ expect(mockAnalyticsHandler.callAction).to.equal('showMoreFacetsModal');
829
+ expect(mockAnalyticsHandler.callLabel).to.equal('subject');
830
+ });
831
+
832
+ it('includes Part Of section for collections', async () => {
833
+ const el = await fixture<CollectionFacets>(
834
+ html`<collection-facets
835
+ .baseNavigationUrl=${''}
836
+ .withinCollection=${'foo'}
837
+ .parentCollections=${['bar', 'baz']}
838
+ .collectionTitles=${new Map([
839
+ ['foo', 'foo-name'],
840
+ ['bar', 'bar-name'],
841
+ ['baz', 'baz-name'],
842
+ ])}
843
+ ></collection-facets>`,
844
+ );
845
+
846
+ const partOfSection = el.shadowRoot?.querySelector('.partof-collections');
847
+ expect(partOfSection).to.exist;
848
+
849
+ const partOfLinks = partOfSection?.querySelectorAll('a[href]');
850
+ expect(partOfLinks?.length).to.equal(2);
851
+
852
+ expect(partOfLinks?.[0]?.textContent?.trim()).to.equal('bar-name');
853
+ expect(partOfLinks?.[0]?.getAttribute('href')).to.equal('/details/bar');
854
+ expect(partOfLinks?.[1]?.textContent?.trim()).to.equal('baz-name');
855
+ expect(partOfLinks?.[1]?.getAttribute('href')).to.equal('/details/baz');
856
+ });
857
+
858
+ it('does not include Part Of section without parent collections', async () => {
859
+ // No parentCollections prop
860
+ const el = await fixture<CollectionFacets>(
861
+ html`<collection-facets .withinCollection=${'foo'}></collection-facets>`,
862
+ );
863
+
864
+ const partOfSection = el.shadowRoot?.querySelector('.partof-collections');
865
+ expect(partOfSection).not.to.exist;
866
+ });
867
+
868
+ it('fires analytics on expanding date picker', async () => {
869
+ const mockAnalyticsHandler = new MockAnalyticsHandler();
870
+
871
+ const el = await fixture<CollectionFacets>(
872
+ html`<collection-facets
873
+ .analyticsHandler=${mockAnalyticsHandler}
874
+ ></collection-facets>`,
875
+ );
876
+
877
+ el.histogramAggregationLoading = false;
878
+ el.showHistogramDatePicker = true;
879
+ el.allowExpandingDatePicker = true;
880
+ el.histogramAggregation = new Aggregation({
881
+ buckets: [1, 2, 3],
882
+ first_bucket_key: 0,
883
+ last_bucket_key: 2,
884
+ });
885
+ await el.updateComplete;
886
+
887
+ const expandBtn = el.shadowRoot?.querySelector(
888
+ '.expand-date-picker-btn',
889
+ ) as HTMLButtonElement;
890
+ expect(expandBtn).to.exist;
891
+
892
+ // Click the expand button to open the modal
893
+ expandBtn?.click();
894
+ await el.updateComplete;
895
+
896
+ expect(mockAnalyticsHandler.callCategory).to.equal('collection-browser');
897
+ expect(mockAnalyticsHandler.callAction).to.equal('histogramExpanded');
898
+ expect(mockAnalyticsHandler.callLabel).to.equal(window.location.href);
899
+ });
900
+
901
+ it('fires analytics on clicking Part Of collection link', async () => {
902
+ const mockAnalyticsHandler = new MockAnalyticsHandler();
903
+
904
+ const el = await fixture<CollectionFacets>(
905
+ html`<collection-facets
906
+ .baseNavigationUrl=${''}
907
+ .withinCollection=${'foo'}
908
+ .parentCollections=${['bar']}
909
+ .analyticsHandler=${mockAnalyticsHandler}
910
+ ></collection-facets>`,
911
+ );
912
+
913
+ const partOfLinks = el.shadowRoot?.querySelectorAll(
914
+ '.partof-collections a[href]',
915
+ );
916
+ expect(partOfLinks?.length).to.equal(1);
917
+
918
+ // Click the expand button to open the modal
919
+ const link = partOfLinks?.[0] as HTMLAnchorElement;
920
+ link?.addEventListener('click', e => e.preventDefault());
921
+ link?.click();
922
+ await el.updateComplete;
923
+
924
+ expect(mockAnalyticsHandler.callCategory).to.equal('collection-browser');
925
+ expect(mockAnalyticsHandler.callAction).to.equal('partOfCollectionClicked');
926
+ expect(mockAnalyticsHandler.callLabel).to.equal('bar');
927
+ });
928
+ });