@internetarchive/collection-browser 3.1.0 → 3.1.1-alpha-webdev6778.1

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 (81) hide show
  1. package/dist/src/app-root.js +606 -606
  2. package/dist/src/app-root.js.map +1 -1
  3. package/dist/src/collection-browser.d.ts +9 -0
  4. package/dist/src/collection-browser.js +7 -0
  5. package/dist/src/collection-browser.js.map +1 -1
  6. package/dist/src/collection-facets/facet-row.js +140 -140
  7. package/dist/src/collection-facets/facet-row.js.map +1 -1
  8. package/dist/src/collection-facets/models.js.map +1 -1
  9. package/dist/src/collection-facets/more-facets-content.d.ts +1 -0
  10. package/dist/src/collection-facets/more-facets-content.js +122 -118
  11. package/dist/src/collection-facets/more-facets-content.js.map +1 -1
  12. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js +75 -75
  13. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js.map +1 -1
  14. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js +54 -54
  15. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js.map +1 -1
  16. package/dist/src/collection-facets.d.ts +1 -0
  17. package/dist/src/collection-facets.js +269 -265
  18. package/dist/src/collection-facets.js.map +1 -1
  19. package/dist/src/data-source/collection-browser-data-source-interface.js.map +1 -1
  20. package/dist/src/data-source/collection-browser-data-source.js +27 -13
  21. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  22. package/dist/src/data-source/collection-browser-query-state.d.ts +1 -0
  23. package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
  24. package/dist/src/data-source/models.d.ts +1 -1
  25. package/dist/src/data-source/models.js.map +1 -1
  26. package/dist/src/expanded-date-picker.js +52 -52
  27. package/dist/src/expanded-date-picker.js.map +1 -1
  28. package/dist/src/manage/manage-bar.js +77 -77
  29. package/dist/src/manage/manage-bar.js.map +1 -1
  30. package/dist/src/models.js.map +1 -1
  31. package/dist/src/sort-filter-bar/sort-filter-bar.js +376 -376
  32. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  33. package/dist/src/tiles/grid/collection-tile.js +77 -77
  34. package/dist/src/tiles/grid/collection-tile.js.map +1 -1
  35. package/dist/src/tiles/grid/item-tile.js +139 -139
  36. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  37. package/dist/src/tiles/grid/search-tile.js +42 -42
  38. package/dist/src/tiles/grid/search-tile.js.map +1 -1
  39. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +119 -119
  40. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js.map +1 -1
  41. package/dist/src/tiles/list/tile-list.js +297 -297
  42. package/dist/src/tiles/list/tile-list.js.map +1 -1
  43. package/dist/src/tiles/tile-dispatcher.js +200 -200
  44. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  45. package/dist/src/utils/analytics-events.js.map +1 -1
  46. package/dist/test/collection-facets/facet-row.test.js +23 -23
  47. package/dist/test/collection-facets/facet-row.test.js.map +1 -1
  48. package/dist/test/collection-facets.test.js +20 -20
  49. package/dist/test/collection-facets.test.js.map +1 -1
  50. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +37 -37
  51. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
  52. package/dist/test/tiles/list/tile-list.test.js +113 -113
  53. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/app-root.ts +1140 -1140
  56. package/src/collection-browser.ts +14 -0
  57. package/src/collection-facets/facet-row.ts +296 -296
  58. package/src/collection-facets/models.ts +10 -10
  59. package/src/collection-facets/more-facets-content.ts +639 -636
  60. package/src/collection-facets/smart-facets/smart-facet-bar.ts +437 -437
  61. package/src/collection-facets/smart-facets/smart-facet-dropdown.ts +185 -185
  62. package/src/collection-facets.ts +995 -992
  63. package/src/data-source/collection-browser-data-source-interface.ts +333 -333
  64. package/src/data-source/collection-browser-data-source.ts +21 -11
  65. package/src/data-source/collection-browser-query-state.ts +1 -0
  66. package/src/data-source/models.ts +1 -1
  67. package/src/expanded-date-picker.ts +191 -191
  68. package/src/manage/manage-bar.ts +247 -247
  69. package/src/models.ts +870 -870
  70. package/src/sort-filter-bar/sort-filter-bar.ts +1283 -1283
  71. package/src/tiles/grid/collection-tile.ts +162 -162
  72. package/src/tiles/grid/item-tile.ts +339 -339
  73. package/src/tiles/grid/search-tile.ts +90 -90
  74. package/src/tiles/grid/styles/tile-grid-shared-styles.ts +130 -130
  75. package/src/tiles/list/tile-list.ts +696 -696
  76. package/src/tiles/tile-dispatcher.ts +486 -486
  77. package/src/utils/analytics-events.ts +29 -29
  78. package/test/collection-facets/facet-row.test.ts +375 -375
  79. package/test/collection-facets.test.ts +928 -928
  80. package/test/sort-filter-bar/sort-filter-bar.test.ts +885 -885
  81. package/test/tiles/list/tile-list.test.ts +497 -497
@@ -1,497 +1,497 @@
1
- import { expect, fixture } from '@open-wc/testing';
2
- import { html } from 'lit';
3
- import type { TileList } from '../../../src/tiles/list/tile-list';
4
-
5
- import '../../../src/tiles/list/tile-list';
6
- import type { TileModel } from '../../../src/models';
7
-
8
- describe('List Tile', () => {
9
- it('should render initial component', async () => {
10
- const el = await fixture<TileList>(
11
- html`<tile-list .model=${{}}></tile-list>`,
12
- );
13
-
14
- const listContainer = el.shadowRoot?.querySelector('#list-line');
15
- const itemTitle = el.shadowRoot?.querySelector('#title');
16
- const imageBlock = el.shadowRoot?.querySelector('image-block');
17
-
18
- expect(listContainer).to.exist;
19
- expect(itemTitle).to.exist;
20
- expect(imageBlock).to.exist;
21
- });
22
-
23
- it('should render the mobile template if below mobile breakpoint', async () => {
24
- const el = await fixture<TileList>(html`
25
- <tile-list .mobileBreakpoint=${500} .currentWidth=${400}> </tile-list>
26
- `);
27
-
28
- const listContainer = el.shadowRoot?.getElementById('list-line');
29
- const topLine = el.shadowRoot?.getElementById('list-line-top');
30
- const bottomLine = el.shadowRoot?.getElementById('list-line-bottom');
31
-
32
- expect(listContainer).to.exist;
33
- expect(listContainer?.classList.contains('mobile')).to.be.true;
34
- expect(topLine).to.exist;
35
- expect(bottomLine).to.exist;
36
- });
37
-
38
- it('should render title link with model href if provided', async () => {
39
- const el = await fixture<TileList>(html`
40
- <tile-list
41
- .baseNavigationUrl=${''}
42
- .model=${{ title: 'foo', href: '/foo/bar' }}
43
- ></tile-list>
44
- `);
45
-
46
- const title = el.shadowRoot?.querySelector('#title > a');
47
-
48
- expect(title).to.exist;
49
- expect(title?.getAttribute('href')).to.equal('/foo/bar');
50
- });
51
-
52
- it('should add title to image link if provided', async () => {
53
- const el = await fixture<TileList>(html`
54
- <tile-list
55
- .baseNavigationUrl=${''}
56
- .model=${{ title: 'foo', href: '/foo/bar' }}
57
- ></tile-list>
58
- `);
59
-
60
- const imageLink = el.shadowRoot?.querySelector('#image-link');
61
-
62
- expect(imageLink).to.exist;
63
- expect(imageLink?.getAttribute('title')).to.equal('View foo');
64
- });
65
-
66
- it('should render with creator element but not dates', async () => {
67
- const el = await fixture<TileList>(html`
68
- <tile-list .model=${{ creators: ['someone'] }}></tile-list>
69
- `);
70
-
71
- const creator = el.shadowRoot?.querySelector('#creator');
72
- const datesLine = el.shadowRoot?.querySelector('#dates-line');
73
-
74
- expect(creator).to.exist;
75
- expect(datesLine?.children.length).to.equal(0);
76
- });
77
-
78
- it('should render with snippet block when it has snippets', async () => {
79
- const el = await fixture<TileList>(html`
80
- <tile-list .model=${{ snippets: ['some {{{snippet}}} text'] }}>
81
- </tile-list>
82
- `);
83
-
84
- const snippetBlock = el.shadowRoot?.querySelector('text-snippet-block');
85
-
86
- expect(snippetBlock).to.exist;
87
- });
88
-
89
- it('should not render snippet block when no snippets are present', async () => {
90
- const el = await fixture<TileList>(html`<tile-list></tile-list>`);
91
-
92
- const snippetBlock = el.shadowRoot?.querySelector('text-snippet-block');
93
-
94
- expect(snippetBlock).to.not.exist;
95
- });
96
-
97
- it('should not render suppressed collections', async () => {
98
- const el = await fixture<TileList>(html`
99
- <tile-list
100
- .model=${{ collections: ['deemphasize', 'community', 'foo'] }}
101
- .baseNavigationUrl=${'base'}
102
- >
103
- </tile-list>
104
- `);
105
-
106
- const collectionsRow = el.shadowRoot?.getElementById('collections');
107
- expect(collectionsRow).to.exist;
108
-
109
- const collectionLinks = collectionsRow?.querySelectorAll('a[href]');
110
- expect(collectionLinks?.length).to.equal(1);
111
- expect(collectionLinks?.item(0).getAttribute('href')).to.equal(
112
- 'base/details/foo',
113
- );
114
- });
115
-
116
- it('should not render fav- collections', async () => {
117
- const el = await fixture<TileList>(html`
118
- <tile-list
119
- .model=${{ collections: ['fav-foo', 'bar'] }}
120
- .baseNavigationUrl=${'base'}
121
- >
122
- </tile-list>
123
- `);
124
-
125
- const collectionsRow = el.shadowRoot?.getElementById('collections');
126
- expect(collectionsRow).to.exist;
127
-
128
- const collectionLinks = collectionsRow?.querySelectorAll('a[href]');
129
- expect(collectionLinks?.length).to.equal(1);
130
- expect(collectionLinks?.item(0).getAttribute('href')).to.equal(
131
- 'base/details/bar',
132
- );
133
- });
134
-
135
- it('should render weekly views when sorting by week', async () => {
136
- const el = await fixture<TileList>(html`
137
- <tile-list
138
- .model=${{ viewCount: 50, weeklyViewCount: 10 }}
139
- .sortParam=${{ field: 'week', direction: 'desc' }}
140
- >
141
- </tile-list>
142
- `);
143
-
144
- const viewsRow = el.shadowRoot?.getElementById('views-line');
145
- expect(viewsRow).to.exist;
146
- expect(viewsRow?.textContent?.trim()).to.equal('Views: 10');
147
- });
148
-
149
- it('should render published date when sorting by it', async () => {
150
- const model: Partial<TileModel> = {
151
- dateAdded: new Date(2010, 0, 2),
152
- dateArchived: new Date(2011, 0, 2),
153
- datePublished: new Date(2012, 0, 2),
154
- dateReviewed: new Date(2013, 0, 2),
155
- };
156
-
157
- const el = await fixture<TileList>(html`
158
- <tile-list
159
- .model=${model}
160
- .sortParam=${{ field: 'date', direction: 'desc' }}
161
- >
162
- </tile-list>
163
- `);
164
-
165
- const dateRow = el.shadowRoot?.getElementById('dates-line');
166
- expect(dateRow).to.exist;
167
- expect(dateRow?.textContent?.trim()).to.contain('Published: Jan 02, 2012');
168
- });
169
-
170
- it('should render added date when sorting by it', async () => {
171
- const model: Partial<TileModel> = {
172
- dateAdded: new Date(2010, 0, 2),
173
- dateArchived: new Date(2011, 0, 2),
174
- datePublished: new Date(2012, 0, 2),
175
- dateReviewed: new Date(2013, 0, 2),
176
- };
177
-
178
- const el = await fixture<TileList>(html`
179
- <tile-list
180
- .model=${model}
181
- .sortParam=${{ field: 'addeddate', direction: 'desc' }}
182
- >
183
- </tile-list>
184
- `);
185
-
186
- const dateRow = el.shadowRoot?.getElementById('dates-line');
187
- expect(dateRow).to.exist;
188
- expect(dateRow?.textContent?.trim()).to.contain('Added: Jan 02, 2010');
189
- });
190
-
191
- it('should render archived date when sorting by it', async () => {
192
- const model: Partial<TileModel> = {
193
- dateAdded: new Date(2010, 0, 2),
194
- dateArchived: new Date(2011, 0, 2),
195
- datePublished: new Date(2012, 0, 2),
196
- dateReviewed: new Date(2013, 0, 2),
197
- };
198
-
199
- const el = await fixture<TileList>(html`
200
- <tile-list
201
- .model=${model}
202
- .sortParam=${{ field: 'publicdate', direction: 'desc' }}
203
- >
204
- </tile-list>
205
- `);
206
-
207
- const dateRow = el.shadowRoot?.getElementById('dates-line');
208
- expect(dateRow).to.exist;
209
- expect(dateRow?.textContent?.trim()).to.contain('Archived: Jan 02, 2011');
210
- });
211
-
212
- it('should render reviewed date when sorting by it', async () => {
213
- const model: Partial<TileModel> = {
214
- dateAdded: new Date(2010, 0, 2),
215
- dateArchived: new Date(2011, 0, 2),
216
- datePublished: new Date(2012, 0, 2),
217
- dateReviewed: new Date(2013, 0, 2),
218
- };
219
-
220
- const el = await fixture<TileList>(html`
221
- <tile-list
222
- .model=${model}
223
- .sortParam=${{ field: 'reviewdate', direction: 'desc' }}
224
- >
225
- </tile-list>
226
- `);
227
-
228
- const dateRow = el.shadowRoot?.getElementById('dates-line');
229
- expect(dateRow).to.exist;
230
- expect(dateRow?.textContent?.trim()).to.contain('Reviewed: Jan 02, 2013');
231
- });
232
-
233
- it('should only show the year for a date published of Jan 1 at midnight UTC', async () => {
234
- const model: Partial<TileModel> = {
235
- datePublished: new Date('2012-01-01T00:00:00Z'),
236
- };
237
-
238
- const el = await fixture<TileList>(html`
239
- <tile-list
240
- .model=${model}
241
- .sortParam=${{ field: 'date', direction: 'desc' }}
242
- >
243
- </tile-list>
244
- `);
245
-
246
- const dateRow = el.shadowRoot?.getElementById('dates-line');
247
- expect(dateRow).to.exist;
248
- expect(dateRow?.textContent?.trim()).to.contain('Published: 2012');
249
- });
250
-
251
- it('should show full date added/archived/reviewed, even on Jan 1 at midnight UTC', async () => {
252
- const model: Partial<TileModel> = {
253
- dateAdded: new Date(2010, 0, 1, 0, 0, 0, 0),
254
- dateArchived: new Date(2011, 0, 1, 0, 0, 0, 0),
255
- datePublished: new Date(2012, 0, 1, 0, 0, 0, 0),
256
- dateReviewed: new Date(2013, 0, 1, 0, 0, 0, 0),
257
- };
258
-
259
- const el = await fixture<TileList>(html`
260
- <tile-list
261
- .model=${model}
262
- .sortParam=${{ field: 'addeddate', direction: 'desc' }}
263
- >
264
- </tile-list>
265
- `);
266
-
267
- let dateRow = el.shadowRoot?.getElementById('dates-line');
268
- expect(dateRow).to.exist;
269
- expect(dateRow?.textContent?.trim()).to.contain('Added: Jan 01, 2010');
270
-
271
- el.sortParam = { field: 'publicdate', direction: 'desc' };
272
- await el.updateComplete;
273
- dateRow = el.shadowRoot?.getElementById('dates-line');
274
- expect(dateRow).to.exist;
275
- expect(dateRow?.textContent?.trim()).to.contain('Archived: Jan 01, 2011');
276
-
277
- el.sortParam = { field: 'reviewdate', direction: 'desc' };
278
- await el.updateComplete;
279
- dateRow = el.shadowRoot?.getElementById('dates-line');
280
- expect(dateRow).to.exist;
281
- expect(dateRow?.textContent?.trim()).to.contain('Reviewed: Jan 01, 2013');
282
- });
283
-
284
- it('should render links to /search pages (not search.php) for subject, creator, and source', async () => {
285
- const model: Partial<TileModel> = {
286
- subjects: ['foo'],
287
- creators: ['bar'],
288
- source: 'baz',
289
- };
290
-
291
- const el = await fixture<TileList>(html`
292
- <tile-list .model=${model}></tile-list>
293
- `);
294
-
295
- const subjectLink = el.shadowRoot?.querySelector('#topics a[href]');
296
- expect(subjectLink).to.exist;
297
- expect(subjectLink?.getAttribute('href')).to.equal(
298
- `/search?query=${encodeURIComponent('subject:"foo"')}`,
299
- );
300
-
301
- const creatorLink = el.shadowRoot?.querySelector('#creator a[href]');
302
- expect(creatorLink).to.exist;
303
- expect(creatorLink?.getAttribute('href')).to.equal(
304
- `/search?query=${encodeURIComponent('creator:"bar"')}`,
305
- );
306
-
307
- const sourceLink = el.shadowRoot?.querySelector('#source a[href]');
308
- expect(sourceLink).to.exist;
309
- expect(sourceLink?.getAttribute('href')).to.equal(
310
- `/search?query=${encodeURIComponent('source:"baz"')}`,
311
- );
312
- });
313
-
314
- it('should render multi-line descriptions with spaces b/w lines', async () => {
315
- const el = await fixture<TileList>(html`
316
- <tile-list .model=${{ description: 'line1\nline2' }}> </tile-list>
317
- `);
318
-
319
- const descriptionBlock = el.shadowRoot?.getElementById('description');
320
- expect(descriptionBlock).to.exist;
321
- expect(descriptionBlock?.textContent?.trim()).to.equal('line1 line2'); // line break replaced by space
322
- });
323
-
324
- it('should render mediatype icon as link to corresponding mediatype collection details', async () => {
325
- const model: Partial<TileModel> = {
326
- mediatype: 'texts',
327
- };
328
-
329
- const el = await fixture<TileList>(html`
330
- <tile-list
331
- .baseNavigationUrl=${'https://archive.org'}
332
- .model=${model}
333
- ></tile-list>
334
- `);
335
-
336
- const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
337
- expect(mediatypeLink).to.exist;
338
- expect(mediatypeLink?.getAttribute('href')).to.equal(
339
- `https://archive.org/details/texts`,
340
- );
341
- expect(mediatypeLink?.getAttribute('title')).to.equal('See more: texts');
342
- });
343
-
344
- it('should render mediatype icon as link even with empty baseNavigationUrl', async () => {
345
- const model: Partial<TileModel> = {
346
- mediatype: 'texts',
347
- };
348
-
349
- const el = await fixture<TileList>(html`
350
- <tile-list .baseNavigationUrl=${''} .model=${model}></tile-list>
351
- `);
352
-
353
- const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
354
- expect(mediatypeLink).to.exist;
355
- expect(mediatypeLink?.getAttribute('href')).to.equal(`/details/texts`);
356
- });
357
-
358
- it('should render collection mediatype icon as link to search page', async () => {
359
- const model: Partial<TileModel> = {
360
- mediatype: 'collection',
361
- };
362
-
363
- const el = await fixture<TileList>(html`
364
- <tile-list
365
- .baseNavigationUrl=${'https://archive.org'}
366
- .model=${model}
367
- ></tile-list>
368
- `);
369
-
370
- const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
371
- expect(mediatypeLink).to.exist;
372
- expect(mediatypeLink?.getAttribute('href')).to.equal(
373
- `https://archive.org/search?query=mediatype:collection&sort=-downloads`,
374
- );
375
- });
376
-
377
- it('should not render account mediatype icon as link', async () => {
378
- const model: Partial<TileModel> = {
379
- mediatype: 'account',
380
- };
381
-
382
- const el = await fixture<TileList>(html`
383
- <tile-list
384
- .baseNavigationUrl=${'https://archive.org'}
385
- .model=${model}
386
- ></tile-list>
387
- `);
388
-
389
- const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
390
- expect(mediatypeLink).to.exist;
391
- expect(mediatypeLink?.getAttribute('href')).not.to.exist;
392
- });
393
-
394
- it('should render date added for accounts', async () => {
395
- const el = await fixture<TileList>(html`
396
- <tile-list
397
- .model=${{
398
- mediatype: 'account',
399
- dateAdded: new Date('2015-05-05T00:00:00'),
400
- }}
401
- >
402
- </tile-list>
403
- `);
404
-
405
- const creatorBlock = el.shadowRoot?.getElementById('creator');
406
- expect(creatorBlock).to.exist;
407
- expect(creatorBlock?.textContent?.trim()).to.equal('Archivist since 2015');
408
- });
409
-
410
- it('should render web capture date links if present', async () => {
411
- const captureDates = [
412
- new Date('2010-01-02T12:34:56Z'),
413
- new Date('2011-02-03T12:43:21Z'),
414
- ];
415
-
416
- const el = await fixture<TileList>(html`
417
- <tile-list
418
- .model=${{
419
- identifier: 'foo',
420
- title: 'https://example.com/',
421
- captureDates,
422
- }}
423
- ></tile-list>
424
- `);
425
-
426
- const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
427
- expect(captureDatesUl, 'capture dates container').to.exist;
428
- expect(captureDatesUl?.children.length).to.equal(2);
429
-
430
- const firstDateLink = captureDatesUl?.children[0]?.querySelector('a[href]');
431
- expect(firstDateLink, 'first date link').to.exist;
432
- expect(firstDateLink?.getAttribute('href')).to.equal(
433
- 'https://web.archive.org/web/20100102123456/https%3A%2F%2Fexample.com%2F',
434
- );
435
- expect(firstDateLink?.textContent?.trim()).to.equal('Jan 02, 2010');
436
-
437
- const secondDateLink =
438
- captureDatesUl?.children[1]?.querySelector('a[href]');
439
- expect(secondDateLink, 'second date link').to.exist;
440
- expect(secondDateLink?.getAttribute('href')).to.equal(
441
- 'https://web.archive.org/web/20110203124321/https%3A%2F%2Fexample.com%2F',
442
- );
443
- expect(secondDateLink?.textContent?.trim()).to.equal('Feb 03, 2011');
444
- });
445
-
446
- it('should not render web captures if no title is present', async () => {
447
- const captureDates = [
448
- new Date('2010-01-02T12:34:56Z'),
449
- new Date('2011-02-03T12:43:21Z'),
450
- ];
451
-
452
- const el = await fixture<TileList>(html`
453
- <tile-list
454
- .model=${{
455
- identifier: 'foo',
456
- captureDates,
457
- }}
458
- ></tile-list>
459
- `);
460
-
461
- const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
462
- expect(captureDatesUl).not.to.exist;
463
- });
464
-
465
- it('should render review snippet if present', async () => {
466
- const review = {
467
- title: 'Foo',
468
- body: 'foo bar baz',
469
- stars: 3,
470
- };
471
-
472
- const el = await fixture<TileList>(html`
473
- <tile-list
474
- .model=${{
475
- identifier: 'foo',
476
- review,
477
- }}
478
- ></tile-list>
479
- `);
480
-
481
- const reviewBlock = el.shadowRoot?.querySelector('review-block');
482
- expect(reviewBlock).to.exist;
483
- });
484
-
485
- it('should not render review snippet block when no review is present', async () => {
486
- const el = await fixture<TileList>(html`
487
- <tile-list
488
- .model=${{
489
- identifier: 'foo',
490
- }}
491
- ></tile-list>
492
- `);
493
-
494
- const reviewBlock = el.shadowRoot?.querySelector('review-block');
495
- expect(reviewBlock).not.to.exist;
496
- });
497
- });
1
+ import { expect, fixture } from '@open-wc/testing';
2
+ import { html } from 'lit';
3
+ import type { TileList } from '../../../src/tiles/list/tile-list';
4
+
5
+ import '../../../src/tiles/list/tile-list';
6
+ import type { TileModel } from '../../../src/models';
7
+
8
+ describe('List Tile', () => {
9
+ it('should render initial component', async () => {
10
+ const el = await fixture<TileList>(
11
+ html`<tile-list .model=${{}}></tile-list>`,
12
+ );
13
+
14
+ const listContainer = el.shadowRoot?.querySelector('#list-line');
15
+ const itemTitle = el.shadowRoot?.querySelector('#title');
16
+ const imageBlock = el.shadowRoot?.querySelector('image-block');
17
+
18
+ expect(listContainer).to.exist;
19
+ expect(itemTitle).to.exist;
20
+ expect(imageBlock).to.exist;
21
+ });
22
+
23
+ it('should render the mobile template if below mobile breakpoint', async () => {
24
+ const el = await fixture<TileList>(html`
25
+ <tile-list .mobileBreakpoint=${500} .currentWidth=${400}> </tile-list>
26
+ `);
27
+
28
+ const listContainer = el.shadowRoot?.getElementById('list-line');
29
+ const topLine = el.shadowRoot?.getElementById('list-line-top');
30
+ const bottomLine = el.shadowRoot?.getElementById('list-line-bottom');
31
+
32
+ expect(listContainer).to.exist;
33
+ expect(listContainer?.classList.contains('mobile')).to.be.true;
34
+ expect(topLine).to.exist;
35
+ expect(bottomLine).to.exist;
36
+ });
37
+
38
+ it('should render title link with model href if provided', async () => {
39
+ const el = await fixture<TileList>(html`
40
+ <tile-list
41
+ .baseNavigationUrl=${''}
42
+ .model=${{ title: 'foo', href: '/foo/bar' }}
43
+ ></tile-list>
44
+ `);
45
+
46
+ const title = el.shadowRoot?.querySelector('#title > a');
47
+
48
+ expect(title).to.exist;
49
+ expect(title?.getAttribute('href')).to.equal('/foo/bar');
50
+ });
51
+
52
+ it('should add title to image link if provided', async () => {
53
+ const el = await fixture<TileList>(html`
54
+ <tile-list
55
+ .baseNavigationUrl=${''}
56
+ .model=${{ title: 'foo', href: '/foo/bar' }}
57
+ ></tile-list>
58
+ `);
59
+
60
+ const imageLink = el.shadowRoot?.querySelector('#image-link');
61
+
62
+ expect(imageLink).to.exist;
63
+ expect(imageLink?.getAttribute('title')).to.equal('View foo');
64
+ });
65
+
66
+ it('should render with creator element but not dates', async () => {
67
+ const el = await fixture<TileList>(html`
68
+ <tile-list .model=${{ creators: ['someone'] }}></tile-list>
69
+ `);
70
+
71
+ const creator = el.shadowRoot?.querySelector('#creator');
72
+ const datesLine = el.shadowRoot?.querySelector('#dates-line');
73
+
74
+ expect(creator).to.exist;
75
+ expect(datesLine?.children.length).to.equal(0);
76
+ });
77
+
78
+ it('should render with snippet block when it has snippets', async () => {
79
+ const el = await fixture<TileList>(html`
80
+ <tile-list .model=${{ snippets: ['some {{{snippet}}} text'] }}>
81
+ </tile-list>
82
+ `);
83
+
84
+ const snippetBlock = el.shadowRoot?.querySelector('text-snippet-block');
85
+
86
+ expect(snippetBlock).to.exist;
87
+ });
88
+
89
+ it('should not render snippet block when no snippets are present', async () => {
90
+ const el = await fixture<TileList>(html`<tile-list></tile-list>`);
91
+
92
+ const snippetBlock = el.shadowRoot?.querySelector('text-snippet-block');
93
+
94
+ expect(snippetBlock).to.not.exist;
95
+ });
96
+
97
+ it('should not render suppressed collections', async () => {
98
+ const el = await fixture<TileList>(html`
99
+ <tile-list
100
+ .model=${{ collections: ['deemphasize', 'community', 'foo'] }}
101
+ .baseNavigationUrl=${'base'}
102
+ >
103
+ </tile-list>
104
+ `);
105
+
106
+ const collectionsRow = el.shadowRoot?.getElementById('collections');
107
+ expect(collectionsRow).to.exist;
108
+
109
+ const collectionLinks = collectionsRow?.querySelectorAll('a[href]');
110
+ expect(collectionLinks?.length).to.equal(1);
111
+ expect(collectionLinks?.item(0).getAttribute('href')).to.equal(
112
+ 'base/details/foo',
113
+ );
114
+ });
115
+
116
+ it('should not render fav- collections', async () => {
117
+ const el = await fixture<TileList>(html`
118
+ <tile-list
119
+ .model=${{ collections: ['fav-foo', 'bar'] }}
120
+ .baseNavigationUrl=${'base'}
121
+ >
122
+ </tile-list>
123
+ `);
124
+
125
+ const collectionsRow = el.shadowRoot?.getElementById('collections');
126
+ expect(collectionsRow).to.exist;
127
+
128
+ const collectionLinks = collectionsRow?.querySelectorAll('a[href]');
129
+ expect(collectionLinks?.length).to.equal(1);
130
+ expect(collectionLinks?.item(0).getAttribute('href')).to.equal(
131
+ 'base/details/bar',
132
+ );
133
+ });
134
+
135
+ it('should render weekly views when sorting by week', async () => {
136
+ const el = await fixture<TileList>(html`
137
+ <tile-list
138
+ .model=${{ viewCount: 50, weeklyViewCount: 10 }}
139
+ .sortParam=${{ field: 'week', direction: 'desc' }}
140
+ >
141
+ </tile-list>
142
+ `);
143
+
144
+ const viewsRow = el.shadowRoot?.getElementById('views-line');
145
+ expect(viewsRow).to.exist;
146
+ expect(viewsRow?.textContent?.trim()).to.equal('Views: 10');
147
+ });
148
+
149
+ it('should render published date when sorting by it', async () => {
150
+ const model: Partial<TileModel> = {
151
+ dateAdded: new Date(2010, 0, 2),
152
+ dateArchived: new Date(2011, 0, 2),
153
+ datePublished: new Date(2012, 0, 2),
154
+ dateReviewed: new Date(2013, 0, 2),
155
+ };
156
+
157
+ const el = await fixture<TileList>(html`
158
+ <tile-list
159
+ .model=${model}
160
+ .sortParam=${{ field: 'date', direction: 'desc' }}
161
+ >
162
+ </tile-list>
163
+ `);
164
+
165
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
166
+ expect(dateRow).to.exist;
167
+ expect(dateRow?.textContent?.trim()).to.contain('Published: Jan 02, 2012');
168
+ });
169
+
170
+ it('should render added date when sorting by it', async () => {
171
+ const model: Partial<TileModel> = {
172
+ dateAdded: new Date(2010, 0, 2),
173
+ dateArchived: new Date(2011, 0, 2),
174
+ datePublished: new Date(2012, 0, 2),
175
+ dateReviewed: new Date(2013, 0, 2),
176
+ };
177
+
178
+ const el = await fixture<TileList>(html`
179
+ <tile-list
180
+ .model=${model}
181
+ .sortParam=${{ field: 'addeddate', direction: 'desc' }}
182
+ >
183
+ </tile-list>
184
+ `);
185
+
186
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
187
+ expect(dateRow).to.exist;
188
+ expect(dateRow?.textContent?.trim()).to.contain('Added: Jan 02, 2010');
189
+ });
190
+
191
+ it('should render archived date when sorting by it', async () => {
192
+ const model: Partial<TileModel> = {
193
+ dateAdded: new Date(2010, 0, 2),
194
+ dateArchived: new Date(2011, 0, 2),
195
+ datePublished: new Date(2012, 0, 2),
196
+ dateReviewed: new Date(2013, 0, 2),
197
+ };
198
+
199
+ const el = await fixture<TileList>(html`
200
+ <tile-list
201
+ .model=${model}
202
+ .sortParam=${{ field: 'publicdate', direction: 'desc' }}
203
+ >
204
+ </tile-list>
205
+ `);
206
+
207
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
208
+ expect(dateRow).to.exist;
209
+ expect(dateRow?.textContent?.trim()).to.contain('Archived: Jan 02, 2011');
210
+ });
211
+
212
+ it('should render reviewed date when sorting by it', async () => {
213
+ const model: Partial<TileModel> = {
214
+ dateAdded: new Date(2010, 0, 2),
215
+ dateArchived: new Date(2011, 0, 2),
216
+ datePublished: new Date(2012, 0, 2),
217
+ dateReviewed: new Date(2013, 0, 2),
218
+ };
219
+
220
+ const el = await fixture<TileList>(html`
221
+ <tile-list
222
+ .model=${model}
223
+ .sortParam=${{ field: 'reviewdate', direction: 'desc' }}
224
+ >
225
+ </tile-list>
226
+ `);
227
+
228
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
229
+ expect(dateRow).to.exist;
230
+ expect(dateRow?.textContent?.trim()).to.contain('Reviewed: Jan 02, 2013');
231
+ });
232
+
233
+ it('should only show the year for a date published of Jan 1 at midnight UTC', async () => {
234
+ const model: Partial<TileModel> = {
235
+ datePublished: new Date('2012-01-01T00:00:00Z'),
236
+ };
237
+
238
+ const el = await fixture<TileList>(html`
239
+ <tile-list
240
+ .model=${model}
241
+ .sortParam=${{ field: 'date', direction: 'desc' }}
242
+ >
243
+ </tile-list>
244
+ `);
245
+
246
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
247
+ expect(dateRow).to.exist;
248
+ expect(dateRow?.textContent?.trim()).to.contain('Published: 2012');
249
+ });
250
+
251
+ it('should show full date added/archived/reviewed, even on Jan 1 at midnight UTC', async () => {
252
+ const model: Partial<TileModel> = {
253
+ dateAdded: new Date(2010, 0, 1, 0, 0, 0, 0),
254
+ dateArchived: new Date(2011, 0, 1, 0, 0, 0, 0),
255
+ datePublished: new Date(2012, 0, 1, 0, 0, 0, 0),
256
+ dateReviewed: new Date(2013, 0, 1, 0, 0, 0, 0),
257
+ };
258
+
259
+ const el = await fixture<TileList>(html`
260
+ <tile-list
261
+ .model=${model}
262
+ .sortParam=${{ field: 'addeddate', direction: 'desc' }}
263
+ >
264
+ </tile-list>
265
+ `);
266
+
267
+ let dateRow = el.shadowRoot?.getElementById('dates-line');
268
+ expect(dateRow).to.exist;
269
+ expect(dateRow?.textContent?.trim()).to.contain('Added: Jan 01, 2010');
270
+
271
+ el.sortParam = { field: 'publicdate', direction: 'desc' };
272
+ await el.updateComplete;
273
+ dateRow = el.shadowRoot?.getElementById('dates-line');
274
+ expect(dateRow).to.exist;
275
+ expect(dateRow?.textContent?.trim()).to.contain('Archived: Jan 01, 2011');
276
+
277
+ el.sortParam = { field: 'reviewdate', direction: 'desc' };
278
+ await el.updateComplete;
279
+ dateRow = el.shadowRoot?.getElementById('dates-line');
280
+ expect(dateRow).to.exist;
281
+ expect(dateRow?.textContent?.trim()).to.contain('Reviewed: Jan 01, 2013');
282
+ });
283
+
284
+ it('should render links to /search pages (not search.php) for subject, creator, and source', async () => {
285
+ const model: Partial<TileModel> = {
286
+ subjects: ['foo'],
287
+ creators: ['bar'],
288
+ source: 'baz',
289
+ };
290
+
291
+ const el = await fixture<TileList>(html`
292
+ <tile-list .model=${model}></tile-list>
293
+ `);
294
+
295
+ const subjectLink = el.shadowRoot?.querySelector('#topics a[href]');
296
+ expect(subjectLink).to.exist;
297
+ expect(subjectLink?.getAttribute('href')).to.equal(
298
+ `/search?query=${encodeURIComponent('subject:"foo"')}`,
299
+ );
300
+
301
+ const creatorLink = el.shadowRoot?.querySelector('#creator a[href]');
302
+ expect(creatorLink).to.exist;
303
+ expect(creatorLink?.getAttribute('href')).to.equal(
304
+ `/search?query=${encodeURIComponent('creator:"bar"')}`,
305
+ );
306
+
307
+ const sourceLink = el.shadowRoot?.querySelector('#source a[href]');
308
+ expect(sourceLink).to.exist;
309
+ expect(sourceLink?.getAttribute('href')).to.equal(
310
+ `/search?query=${encodeURIComponent('source:"baz"')}`,
311
+ );
312
+ });
313
+
314
+ it('should render multi-line descriptions with spaces b/w lines', async () => {
315
+ const el = await fixture<TileList>(html`
316
+ <tile-list .model=${{ description: 'line1\nline2' }}> </tile-list>
317
+ `);
318
+
319
+ const descriptionBlock = el.shadowRoot?.getElementById('description');
320
+ expect(descriptionBlock).to.exist;
321
+ expect(descriptionBlock?.textContent?.trim()).to.equal('line1 line2'); // line break replaced by space
322
+ });
323
+
324
+ it('should render mediatype icon as link to corresponding mediatype collection details', async () => {
325
+ const model: Partial<TileModel> = {
326
+ mediatype: 'texts',
327
+ };
328
+
329
+ const el = await fixture<TileList>(html`
330
+ <tile-list
331
+ .baseNavigationUrl=${'https://archive.org'}
332
+ .model=${model}
333
+ ></tile-list>
334
+ `);
335
+
336
+ const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
337
+ expect(mediatypeLink).to.exist;
338
+ expect(mediatypeLink?.getAttribute('href')).to.equal(
339
+ `https://archive.org/details/texts`,
340
+ );
341
+ expect(mediatypeLink?.getAttribute('title')).to.equal('See more: texts');
342
+ });
343
+
344
+ it('should render mediatype icon as link even with empty baseNavigationUrl', async () => {
345
+ const model: Partial<TileModel> = {
346
+ mediatype: 'texts',
347
+ };
348
+
349
+ const el = await fixture<TileList>(html`
350
+ <tile-list .baseNavigationUrl=${''} .model=${model}></tile-list>
351
+ `);
352
+
353
+ const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
354
+ expect(mediatypeLink).to.exist;
355
+ expect(mediatypeLink?.getAttribute('href')).to.equal(`/details/texts`);
356
+ });
357
+
358
+ it('should render collection mediatype icon as link to search page', async () => {
359
+ const model: Partial<TileModel> = {
360
+ mediatype: 'collection',
361
+ };
362
+
363
+ const el = await fixture<TileList>(html`
364
+ <tile-list
365
+ .baseNavigationUrl=${'https://archive.org'}
366
+ .model=${model}
367
+ ></tile-list>
368
+ `);
369
+
370
+ const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
371
+ expect(mediatypeLink).to.exist;
372
+ expect(mediatypeLink?.getAttribute('href')).to.equal(
373
+ `https://archive.org/search?query=mediatype:collection&sort=-downloads`,
374
+ );
375
+ });
376
+
377
+ it('should not render account mediatype icon as link', async () => {
378
+ const model: Partial<TileModel> = {
379
+ mediatype: 'account',
380
+ };
381
+
382
+ const el = await fixture<TileList>(html`
383
+ <tile-list
384
+ .baseNavigationUrl=${'https://archive.org'}
385
+ .model=${model}
386
+ ></tile-list>
387
+ `);
388
+
389
+ const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
390
+ expect(mediatypeLink).to.exist;
391
+ expect(mediatypeLink?.getAttribute('href')).not.to.exist;
392
+ });
393
+
394
+ it('should render date added for accounts', async () => {
395
+ const el = await fixture<TileList>(html`
396
+ <tile-list
397
+ .model=${{
398
+ mediatype: 'account',
399
+ dateAdded: new Date('2015-05-05T00:00:00'),
400
+ }}
401
+ >
402
+ </tile-list>
403
+ `);
404
+
405
+ const creatorBlock = el.shadowRoot?.getElementById('creator');
406
+ expect(creatorBlock).to.exist;
407
+ expect(creatorBlock?.textContent?.trim()).to.equal('Archivist since 2015');
408
+ });
409
+
410
+ it('should render web capture date links if present', async () => {
411
+ const captureDates = [
412
+ new Date('2010-01-02T12:34:56Z'),
413
+ new Date('2011-02-03T12:43:21Z'),
414
+ ];
415
+
416
+ const el = await fixture<TileList>(html`
417
+ <tile-list
418
+ .model=${{
419
+ identifier: 'foo',
420
+ title: 'https://example.com/',
421
+ captureDates,
422
+ }}
423
+ ></tile-list>
424
+ `);
425
+
426
+ const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
427
+ expect(captureDatesUl, 'capture dates container').to.exist;
428
+ expect(captureDatesUl?.children.length).to.equal(2);
429
+
430
+ const firstDateLink = captureDatesUl?.children[0]?.querySelector('a[href]');
431
+ expect(firstDateLink, 'first date link').to.exist;
432
+ expect(firstDateLink?.getAttribute('href')).to.equal(
433
+ 'https://web.archive.org/web/20100102123456/https%3A%2F%2Fexample.com%2F',
434
+ );
435
+ expect(firstDateLink?.textContent?.trim()).to.equal('Jan 02, 2010');
436
+
437
+ const secondDateLink =
438
+ captureDatesUl?.children[1]?.querySelector('a[href]');
439
+ expect(secondDateLink, 'second date link').to.exist;
440
+ expect(secondDateLink?.getAttribute('href')).to.equal(
441
+ 'https://web.archive.org/web/20110203124321/https%3A%2F%2Fexample.com%2F',
442
+ );
443
+ expect(secondDateLink?.textContent?.trim()).to.equal('Feb 03, 2011');
444
+ });
445
+
446
+ it('should not render web captures if no title is present', async () => {
447
+ const captureDates = [
448
+ new Date('2010-01-02T12:34:56Z'),
449
+ new Date('2011-02-03T12:43:21Z'),
450
+ ];
451
+
452
+ const el = await fixture<TileList>(html`
453
+ <tile-list
454
+ .model=${{
455
+ identifier: 'foo',
456
+ captureDates,
457
+ }}
458
+ ></tile-list>
459
+ `);
460
+
461
+ const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
462
+ expect(captureDatesUl).not.to.exist;
463
+ });
464
+
465
+ it('should render review snippet if present', async () => {
466
+ const review = {
467
+ title: 'Foo',
468
+ body: 'foo bar baz',
469
+ stars: 3,
470
+ };
471
+
472
+ const el = await fixture<TileList>(html`
473
+ <tile-list
474
+ .model=${{
475
+ identifier: 'foo',
476
+ review,
477
+ }}
478
+ ></tile-list>
479
+ `);
480
+
481
+ const reviewBlock = el.shadowRoot?.querySelector('review-block');
482
+ expect(reviewBlock).to.exist;
483
+ });
484
+
485
+ it('should not render review snippet block when no review is present', async () => {
486
+ const el = await fixture<TileList>(html`
487
+ <tile-list
488
+ .model=${{
489
+ identifier: 'foo',
490
+ }}
491
+ ></tile-list>
492
+ `);
493
+
494
+ const reviewBlock = el.shadowRoot?.querySelector('review-block');
495
+ expect(reviewBlock).not.to.exist;
496
+ });
497
+ });