@internetarchive/collection-browser 4.3.1-alpha-webdev8165.0 → 4.3.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 (42) hide show
  1. package/dist/index.js.map +1 -1
  2. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  3. package/dist/src/manage/manage-bar.js +77 -77
  4. package/dist/src/manage/manage-bar.js.map +1 -1
  5. package/dist/src/models.d.ts +6 -0
  6. package/dist/src/models.js +16 -7
  7. package/dist/src/models.js.map +1 -1
  8. package/dist/src/restoration-state-handler.js +3 -1
  9. package/dist/src/restoration-state-handler.js.map +1 -1
  10. package/dist/src/tiles/base-tile-component.js.map +1 -1
  11. package/dist/src/tiles/grid/item-tile.js +138 -138
  12. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  13. package/dist/src/tiles/models.js.map +1 -1
  14. package/dist/src/tiles/tile-dispatcher.js +216 -216
  15. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  16. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  17. package/dist/test/data-source/collection-browser-data-source.test.js +2 -2
  18. package/dist/test/data-source/collection-browser-data-source.test.js.map +1 -1
  19. package/dist/test/manage/manage-bar.test.js +33 -33
  20. package/dist/test/manage/manage-bar.test.js.map +1 -1
  21. package/dist/test/restoration-state-handler.test.js +0 -70
  22. package/dist/test/restoration-state-handler.test.js.map +1 -1
  23. package/dist/test/tiles/list/tile-list-compact-header.test.js +12 -12
  24. package/dist/test/tiles/list/tile-list-compact-header.test.js.map +1 -1
  25. package/dist/test/tiles/list/tile-list.test.js +134 -134
  26. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  27. package/index.ts +28 -28
  28. package/package.json +2 -2
  29. package/src/data-source/collection-browser-data-source.ts +1465 -1465
  30. package/src/manage/manage-bar.ts +276 -276
  31. package/src/models.ts +895 -879
  32. package/src/restoration-state-handler.ts +550 -546
  33. package/src/tiles/base-tile-component.ts +65 -65
  34. package/src/tiles/grid/item-tile.ts +346 -346
  35. package/src/tiles/models.ts +8 -8
  36. package/src/tiles/tile-dispatcher.ts +527 -527
  37. package/src/tiles/tile-display-value-provider.ts +134 -134
  38. package/test/data-source/collection-browser-data-source.test.ts +193 -193
  39. package/test/manage/manage-bar.test.ts +347 -347
  40. package/test/restoration-state-handler.test.ts +480 -569
  41. package/test/tiles/list/tile-list-compact-header.test.ts +43 -43
  42. package/test/tiles/list/tile-list.test.ts +576 -576
@@ -1,576 +1,576 @@
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('Weekly views: 10');
147
- });
148
-
149
- it('should render all-time views when sorting by non-week field', async () => {
150
- const el = await fixture<TileList>(html`
151
- <tile-list
152
- .model=${{ viewCount: 50, weeklyViewCount: 10 }}
153
- .sortParam=${{ field: 'downloads', direction: 'desc' }}
154
- >
155
- </tile-list>
156
- `);
157
-
158
- const viewsRow = el.shadowRoot?.getElementById('views-line');
159
- expect(viewsRow).to.exist;
160
- expect(viewsRow?.textContent?.trim()).to.equal('All-time views: 50');
161
- });
162
-
163
- it('should render all-time views with no sort param', async () => {
164
- const el = await fixture<TileList>(html`
165
- <tile-list .model=${{ viewCount: 50, weeklyViewCount: 10 }}> </tile-list>
166
- `);
167
-
168
- const viewsRow = el.shadowRoot?.getElementById('views-line');
169
- expect(viewsRow).to.exist;
170
- expect(viewsRow?.textContent?.trim()).to.equal('All-time views: 50');
171
- });
172
-
173
- it('should render published date when sorting by it', async () => {
174
- const model: Partial<TileModel> = {
175
- dateAdded: new Date(2010, 0, 2),
176
- dateArchived: new Date(2011, 0, 2),
177
- datePublished: new Date(2012, 0, 2),
178
- dateReviewed: new Date(2013, 0, 2),
179
- };
180
-
181
- const el = await fixture<TileList>(html`
182
- <tile-list
183
- .model=${model}
184
- .sortParam=${{ field: 'date', direction: 'desc' }}
185
- >
186
- </tile-list>
187
- `);
188
-
189
- const dateRow = el.shadowRoot?.getElementById('dates-line');
190
- expect(dateRow).to.exist;
191
- expect(dateRow?.textContent?.trim()).to.contain('Published: Jan 02, 2012');
192
- });
193
-
194
- it('should render added date when sorting by it', async () => {
195
- const model: Partial<TileModel> = {
196
- dateAdded: new Date(2010, 0, 2),
197
- dateArchived: new Date(2011, 0, 2),
198
- datePublished: new Date(2012, 0, 2),
199
- dateReviewed: new Date(2013, 0, 2),
200
- };
201
-
202
- const el = await fixture<TileList>(html`
203
- <tile-list
204
- .model=${model}
205
- .sortParam=${{ field: 'addeddate', direction: 'desc' }}
206
- >
207
- </tile-list>
208
- `);
209
-
210
- const dateRow = el.shadowRoot?.getElementById('dates-line');
211
- expect(dateRow).to.exist;
212
- expect(dateRow?.textContent?.trim()).to.contain('Added: Jan 02, 2010');
213
- });
214
-
215
- it('should render archived date when sorting by it', async () => {
216
- const model: Partial<TileModel> = {
217
- dateAdded: new Date(2010, 0, 2),
218
- dateArchived: new Date(2011, 0, 2),
219
- datePublished: new Date(2012, 0, 2),
220
- dateReviewed: new Date(2013, 0, 2),
221
- };
222
-
223
- const el = await fixture<TileList>(html`
224
- <tile-list
225
- .model=${model}
226
- .sortParam=${{ field: 'publicdate', direction: 'desc' }}
227
- >
228
- </tile-list>
229
- `);
230
-
231
- const dateRow = el.shadowRoot?.getElementById('dates-line');
232
- expect(dateRow).to.exist;
233
- expect(dateRow?.textContent?.trim()).to.contain('Archived: Jan 02, 2011');
234
- });
235
-
236
- it('should render reviewed date when sorting by it', async () => {
237
- const model: Partial<TileModel> = {
238
- dateAdded: new Date(2010, 0, 2),
239
- dateArchived: new Date(2011, 0, 2),
240
- datePublished: new Date(2012, 0, 2),
241
- dateReviewed: new Date(2013, 0, 2),
242
- };
243
-
244
- const el = await fixture<TileList>(html`
245
- <tile-list
246
- .model=${model}
247
- .sortParam=${{ field: 'reviewdate', direction: 'desc' }}
248
- >
249
- </tile-list>
250
- `);
251
-
252
- const dateRow = el.shadowRoot?.getElementById('dates-line');
253
- expect(dateRow).to.exist;
254
- expect(dateRow?.textContent?.trim()).to.contain('Reviewed: Jan 02, 2013');
255
- });
256
-
257
- it('should only show the year for a date published of Jan 1 at midnight UTC', async () => {
258
- const model: Partial<TileModel> = {
259
- datePublished: new Date('2012-01-01T00:00:00Z'),
260
- };
261
-
262
- const el = await fixture<TileList>(html`
263
- <tile-list
264
- .model=${model}
265
- .sortParam=${{ field: 'date', direction: 'desc' }}
266
- >
267
- </tile-list>
268
- `);
269
-
270
- const dateRow = el.shadowRoot?.getElementById('dates-line');
271
- expect(dateRow).to.exist;
272
- expect(dateRow?.textContent?.trim()).to.contain('Published: 2012');
273
- });
274
-
275
- it('should show full date added/archived/reviewed, even on Jan 1 at midnight UTC', async () => {
276
- const model: Partial<TileModel> = {
277
- dateAdded: new Date(2010, 0, 1, 0, 0, 0, 0),
278
- dateArchived: new Date(2011, 0, 1, 0, 0, 0, 0),
279
- datePublished: new Date(2012, 0, 1, 0, 0, 0, 0),
280
- dateReviewed: new Date(2013, 0, 1, 0, 0, 0, 0),
281
- };
282
-
283
- const el = await fixture<TileList>(html`
284
- <tile-list
285
- .model=${model}
286
- .sortParam=${{ field: 'addeddate', direction: 'desc' }}
287
- >
288
- </tile-list>
289
- `);
290
-
291
- let dateRow = el.shadowRoot?.getElementById('dates-line');
292
- expect(dateRow).to.exist;
293
- expect(dateRow?.textContent?.trim()).to.contain('Added: Jan 01, 2010');
294
-
295
- el.sortParam = { field: 'publicdate', direction: 'desc' };
296
- await el.updateComplete;
297
- dateRow = el.shadowRoot?.getElementById('dates-line');
298
- expect(dateRow).to.exist;
299
- expect(dateRow?.textContent?.trim()).to.contain('Archived: Jan 01, 2011');
300
-
301
- el.sortParam = { field: 'reviewdate', direction: 'desc' };
302
- await el.updateComplete;
303
- dateRow = el.shadowRoot?.getElementById('dates-line');
304
- expect(dateRow).to.exist;
305
- expect(dateRow?.textContent?.trim()).to.contain('Reviewed: Jan 01, 2013');
306
- });
307
-
308
- it('should display dates in UTC time zone by default', async () => {
309
- const model: Partial<TileModel> = {
310
- datePublished: new Date('2012-02-15T00:00:00Z'),
311
- };
312
-
313
- const el = await fixture<TileList>(html`
314
- <tile-list
315
- .model=${model}
316
- .sortParam=${{ field: 'date', direction: 'desc' }}
317
- >
318
- </tile-list>
319
- `);
320
-
321
- const dateRow = el.shadowRoot?.getElementById('dates-line');
322
- expect(dateRow).to.exist;
323
- expect(dateRow?.textContent?.trim()).to.contain('Published: Feb 15, 2012');
324
- });
325
-
326
- it('should display dates in local time when useLocalTime option is true', async () => {
327
- // Expected behavior depends on the time zone offset where the testing occurs
328
- const offset = new Date().getTimezoneOffset();
329
- let datePublished, expected;
330
- if (offset > 0) {
331
- // Positive local time zone offsets have earlier local dates than UTC
332
- datePublished = new Date('2012-02-15T00:00:00Z');
333
- expected = 'Published: Feb 14, 2012';
334
- } else if (offset < 0) {
335
- // Negative local time zone offsets have later local dates than UTC
336
- datePublished = new Date('2012-02-15T23:59:59Z');
337
- expected = 'Published: Feb 16, 2012';
338
- } else {
339
- // Local time may just be UTC itself
340
- datePublished = new Date('2012-02-15T00:00:00Z');
341
- expected = 'Published: Feb 15, 2012';
342
- }
343
-
344
- const model: Partial<TileModel> = {
345
- datePublished,
346
- };
347
-
348
- const el = await fixture<TileList>(html`
349
- <tile-list
350
- useLocalTime
351
- .model=${model}
352
- .sortParam=${{ field: 'date', direction: 'desc' }}
353
- >
354
- </tile-list>
355
- `);
356
-
357
- const dateRow = el.shadowRoot?.getElementById('dates-line');
358
- expect(dateRow).to.exist;
359
-
360
- expect(dateRow?.textContent?.trim()).to.contain(expected);
361
- });
362
-
363
- it('should render links to /search pages (not search.php) for subject, creator, and source', async () => {
364
- const model: Partial<TileModel> = {
365
- subjects: ['foo'],
366
- creators: ['bar'],
367
- source: 'baz',
368
- };
369
-
370
- const el = await fixture<TileList>(html`
371
- <tile-list .model=${model}></tile-list>
372
- `);
373
-
374
- const subjectLink = el.shadowRoot?.querySelector('#topics a[href]');
375
- expect(subjectLink).to.exist;
376
- expect(subjectLink?.getAttribute('href')).to.equal(
377
- `/search?query=${encodeURIComponent('subject:"foo"')}`,
378
- );
379
-
380
- const creatorLink = el.shadowRoot?.querySelector('#creator a[href]');
381
- expect(creatorLink).to.exist;
382
- expect(creatorLink?.getAttribute('href')).to.equal(
383
- `/search?query=${encodeURIComponent('creator:"bar"')}`,
384
- );
385
-
386
- const sourceLink = el.shadowRoot?.querySelector('#source a[href]');
387
- expect(sourceLink).to.exist;
388
- expect(sourceLink?.getAttribute('href')).to.equal(
389
- `/search?query=${encodeURIComponent('source:"baz"')}`,
390
- );
391
- });
392
-
393
- it('should render multi-line descriptions with spaces b/w lines', async () => {
394
- const el = await fixture<TileList>(html`
395
- <tile-list .model=${{ description: 'line1\nline2' }}> </tile-list>
396
- `);
397
-
398
- const descriptionBlock = el.shadowRoot?.getElementById('description');
399
- expect(descriptionBlock).to.exist;
400
- expect(descriptionBlock?.textContent?.trim()).to.equal('line1 line2'); // line break replaced by space
401
- });
402
-
403
- it('should render mediatype icon as link to corresponding mediatype collection details', async () => {
404
- const model: Partial<TileModel> = {
405
- mediatype: 'texts',
406
- };
407
-
408
- const el = await fixture<TileList>(html`
409
- <tile-list
410
- .baseNavigationUrl=${'https://archive.org'}
411
- .model=${model}
412
- ></tile-list>
413
- `);
414
-
415
- const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
416
- expect(mediatypeLink).to.exist;
417
- expect(mediatypeLink?.getAttribute('href')).to.equal(
418
- `https://archive.org/details/texts`,
419
- );
420
- expect(mediatypeLink?.getAttribute('title')).to.equal('See more: texts');
421
- });
422
-
423
- it('should render mediatype icon as link even with empty baseNavigationUrl', async () => {
424
- const model: Partial<TileModel> = {
425
- mediatype: 'texts',
426
- };
427
-
428
- const el = await fixture<TileList>(html`
429
- <tile-list .baseNavigationUrl=${''} .model=${model}></tile-list>
430
- `);
431
-
432
- const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
433
- expect(mediatypeLink).to.exist;
434
- expect(mediatypeLink?.getAttribute('href')).to.equal(`/details/texts`);
435
- });
436
-
437
- it('should render collection mediatype icon as link to search page', async () => {
438
- const model: Partial<TileModel> = {
439
- mediatype: 'collection',
440
- };
441
-
442
- const el = await fixture<TileList>(html`
443
- <tile-list
444
- .baseNavigationUrl=${'https://archive.org'}
445
- .model=${model}
446
- ></tile-list>
447
- `);
448
-
449
- const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
450
- expect(mediatypeLink).to.exist;
451
- expect(mediatypeLink?.getAttribute('href')).to.equal(
452
- `https://archive.org/search?query=mediatype:collection&sort=-downloads`,
453
- );
454
- });
455
-
456
- it('should not render account mediatype icon as link', async () => {
457
- const model: Partial<TileModel> = {
458
- mediatype: 'account',
459
- };
460
-
461
- const el = await fixture<TileList>(html`
462
- <tile-list
463
- .baseNavigationUrl=${'https://archive.org'}
464
- .model=${model}
465
- ></tile-list>
466
- `);
467
-
468
- const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
469
- expect(mediatypeLink).to.exist;
470
- expect(mediatypeLink?.getAttribute('href')).not.to.exist;
471
- });
472
-
473
- it('should render date added for accounts', async () => {
474
- const el = await fixture<TileList>(html`
475
- <tile-list
476
- .model=${{
477
- mediatype: 'account',
478
- dateAdded: new Date('2015-05-05T00:00:00'),
479
- }}
480
- >
481
- </tile-list>
482
- `);
483
-
484
- const creatorBlock = el.shadowRoot?.getElementById('creator');
485
- expect(creatorBlock).to.exist;
486
- expect(creatorBlock?.textContent?.trim()).to.equal('Archivist since 2015');
487
- });
488
-
489
- it('should render web capture date links if present', async () => {
490
- const captureDates = [
491
- new Date('2010-01-02T12:34:56Z'),
492
- new Date('2011-02-03T12:43:21Z'),
493
- ];
494
-
495
- const el = await fixture<TileList>(html`
496
- <tile-list
497
- .model=${{
498
- identifier: 'foo',
499
- title: 'https://example.com/',
500
- captureDates,
501
- }}
502
- ></tile-list>
503
- `);
504
-
505
- const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
506
- expect(captureDatesUl, 'capture dates container').to.exist;
507
- expect(captureDatesUl?.children.length).to.equal(2);
508
-
509
- const firstDateLink = captureDatesUl?.children[0]?.querySelector('a[href]');
510
- expect(firstDateLink, 'first date link').to.exist;
511
- expect(firstDateLink?.getAttribute('href')).to.equal(
512
- 'https://web.archive.org/web/20100102123456/https%3A%2F%2Fexample.com%2F',
513
- );
514
- expect(firstDateLink?.textContent?.trim()).to.equal('Jan 02, 2010');
515
-
516
- const secondDateLink =
517
- captureDatesUl?.children[1]?.querySelector('a[href]');
518
- expect(secondDateLink, 'second date link').to.exist;
519
- expect(secondDateLink?.getAttribute('href')).to.equal(
520
- 'https://web.archive.org/web/20110203124321/https%3A%2F%2Fexample.com%2F',
521
- );
522
- expect(secondDateLink?.textContent?.trim()).to.equal('Feb 03, 2011');
523
- });
524
-
525
- it('should not render web captures if no title is present', async () => {
526
- const captureDates = [
527
- new Date('2010-01-02T12:34:56Z'),
528
- new Date('2011-02-03T12:43:21Z'),
529
- ];
530
-
531
- const el = await fixture<TileList>(html`
532
- <tile-list
533
- .model=${{
534
- identifier: 'foo',
535
- captureDates,
536
- }}
537
- ></tile-list>
538
- `);
539
-
540
- const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
541
- expect(captureDatesUl).not.to.exist;
542
- });
543
-
544
- it('should render review snippet if present', async () => {
545
- const review = {
546
- title: 'Foo',
547
- body: 'foo bar baz',
548
- stars: 3,
549
- };
550
-
551
- const el = await fixture<TileList>(html`
552
- <tile-list
553
- .model=${{
554
- identifier: 'foo',
555
- review,
556
- }}
557
- ></tile-list>
558
- `);
559
-
560
- const reviewBlock = el.shadowRoot?.querySelector('review-block');
561
- expect(reviewBlock).to.exist;
562
- });
563
-
564
- it('should not render review snippet block when no review is present', async () => {
565
- const el = await fixture<TileList>(html`
566
- <tile-list
567
- .model=${{
568
- identifier: 'foo',
569
- }}
570
- ></tile-list>
571
- `);
572
-
573
- const reviewBlock = el.shadowRoot?.querySelector('review-block');
574
- expect(reviewBlock).not.to.exist;
575
- });
576
- });
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('Weekly views: 10');
147
+ });
148
+
149
+ it('should render all-time views when sorting by non-week field', async () => {
150
+ const el = await fixture<TileList>(html`
151
+ <tile-list
152
+ .model=${{ viewCount: 50, weeklyViewCount: 10 }}
153
+ .sortParam=${{ field: 'downloads', direction: 'desc' }}
154
+ >
155
+ </tile-list>
156
+ `);
157
+
158
+ const viewsRow = el.shadowRoot?.getElementById('views-line');
159
+ expect(viewsRow).to.exist;
160
+ expect(viewsRow?.textContent?.trim()).to.equal('All-time views: 50');
161
+ });
162
+
163
+ it('should render all-time views with no sort param', async () => {
164
+ const el = await fixture<TileList>(html`
165
+ <tile-list .model=${{ viewCount: 50, weeklyViewCount: 10 }}> </tile-list>
166
+ `);
167
+
168
+ const viewsRow = el.shadowRoot?.getElementById('views-line');
169
+ expect(viewsRow).to.exist;
170
+ expect(viewsRow?.textContent?.trim()).to.equal('All-time views: 50');
171
+ });
172
+
173
+ it('should render published date when sorting by it', async () => {
174
+ const model: Partial<TileModel> = {
175
+ dateAdded: new Date(2010, 0, 2),
176
+ dateArchived: new Date(2011, 0, 2),
177
+ datePublished: new Date(2012, 0, 2),
178
+ dateReviewed: new Date(2013, 0, 2),
179
+ };
180
+
181
+ const el = await fixture<TileList>(html`
182
+ <tile-list
183
+ .model=${model}
184
+ .sortParam=${{ field: 'date', direction: 'desc' }}
185
+ >
186
+ </tile-list>
187
+ `);
188
+
189
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
190
+ expect(dateRow).to.exist;
191
+ expect(dateRow?.textContent?.trim()).to.contain('Published: Jan 02, 2012');
192
+ });
193
+
194
+ it('should render added date when sorting by it', async () => {
195
+ const model: Partial<TileModel> = {
196
+ dateAdded: new Date(2010, 0, 2),
197
+ dateArchived: new Date(2011, 0, 2),
198
+ datePublished: new Date(2012, 0, 2),
199
+ dateReviewed: new Date(2013, 0, 2),
200
+ };
201
+
202
+ const el = await fixture<TileList>(html`
203
+ <tile-list
204
+ .model=${model}
205
+ .sortParam=${{ field: 'addeddate', direction: 'desc' }}
206
+ >
207
+ </tile-list>
208
+ `);
209
+
210
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
211
+ expect(dateRow).to.exist;
212
+ expect(dateRow?.textContent?.trim()).to.contain('Added: Jan 02, 2010');
213
+ });
214
+
215
+ it('should render archived date when sorting by it', async () => {
216
+ const model: Partial<TileModel> = {
217
+ dateAdded: new Date(2010, 0, 2),
218
+ dateArchived: new Date(2011, 0, 2),
219
+ datePublished: new Date(2012, 0, 2),
220
+ dateReviewed: new Date(2013, 0, 2),
221
+ };
222
+
223
+ const el = await fixture<TileList>(html`
224
+ <tile-list
225
+ .model=${model}
226
+ .sortParam=${{ field: 'publicdate', direction: 'desc' }}
227
+ >
228
+ </tile-list>
229
+ `);
230
+
231
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
232
+ expect(dateRow).to.exist;
233
+ expect(dateRow?.textContent?.trim()).to.contain('Archived: Jan 02, 2011');
234
+ });
235
+
236
+ it('should render reviewed date when sorting by it', async () => {
237
+ const model: Partial<TileModel> = {
238
+ dateAdded: new Date(2010, 0, 2),
239
+ dateArchived: new Date(2011, 0, 2),
240
+ datePublished: new Date(2012, 0, 2),
241
+ dateReviewed: new Date(2013, 0, 2),
242
+ };
243
+
244
+ const el = await fixture<TileList>(html`
245
+ <tile-list
246
+ .model=${model}
247
+ .sortParam=${{ field: 'reviewdate', direction: 'desc' }}
248
+ >
249
+ </tile-list>
250
+ `);
251
+
252
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
253
+ expect(dateRow).to.exist;
254
+ expect(dateRow?.textContent?.trim()).to.contain('Reviewed: Jan 02, 2013');
255
+ });
256
+
257
+ it('should only show the year for a date published of Jan 1 at midnight UTC', async () => {
258
+ const model: Partial<TileModel> = {
259
+ datePublished: new Date('2012-01-01T00:00:00Z'),
260
+ };
261
+
262
+ const el = await fixture<TileList>(html`
263
+ <tile-list
264
+ .model=${model}
265
+ .sortParam=${{ field: 'date', direction: 'desc' }}
266
+ >
267
+ </tile-list>
268
+ `);
269
+
270
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
271
+ expect(dateRow).to.exist;
272
+ expect(dateRow?.textContent?.trim()).to.contain('Published: 2012');
273
+ });
274
+
275
+ it('should show full date added/archived/reviewed, even on Jan 1 at midnight UTC', async () => {
276
+ const model: Partial<TileModel> = {
277
+ dateAdded: new Date(2010, 0, 1, 0, 0, 0, 0),
278
+ dateArchived: new Date(2011, 0, 1, 0, 0, 0, 0),
279
+ datePublished: new Date(2012, 0, 1, 0, 0, 0, 0),
280
+ dateReviewed: new Date(2013, 0, 1, 0, 0, 0, 0),
281
+ };
282
+
283
+ const el = await fixture<TileList>(html`
284
+ <tile-list
285
+ .model=${model}
286
+ .sortParam=${{ field: 'addeddate', direction: 'desc' }}
287
+ >
288
+ </tile-list>
289
+ `);
290
+
291
+ let dateRow = el.shadowRoot?.getElementById('dates-line');
292
+ expect(dateRow).to.exist;
293
+ expect(dateRow?.textContent?.trim()).to.contain('Added: Jan 01, 2010');
294
+
295
+ el.sortParam = { field: 'publicdate', direction: 'desc' };
296
+ await el.updateComplete;
297
+ dateRow = el.shadowRoot?.getElementById('dates-line');
298
+ expect(dateRow).to.exist;
299
+ expect(dateRow?.textContent?.trim()).to.contain('Archived: Jan 01, 2011');
300
+
301
+ el.sortParam = { field: 'reviewdate', direction: 'desc' };
302
+ await el.updateComplete;
303
+ dateRow = el.shadowRoot?.getElementById('dates-line');
304
+ expect(dateRow).to.exist;
305
+ expect(dateRow?.textContent?.trim()).to.contain('Reviewed: Jan 01, 2013');
306
+ });
307
+
308
+ it('should display dates in UTC time zone by default', async () => {
309
+ const model: Partial<TileModel> = {
310
+ datePublished: new Date('2012-02-15T00:00:00Z'),
311
+ };
312
+
313
+ const el = await fixture<TileList>(html`
314
+ <tile-list
315
+ .model=${model}
316
+ .sortParam=${{ field: 'date', direction: 'desc' }}
317
+ >
318
+ </tile-list>
319
+ `);
320
+
321
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
322
+ expect(dateRow).to.exist;
323
+ expect(dateRow?.textContent?.trim()).to.contain('Published: Feb 15, 2012');
324
+ });
325
+
326
+ it('should display dates in local time when useLocalTime option is true', async () => {
327
+ // Expected behavior depends on the time zone offset where the testing occurs
328
+ const offset = new Date().getTimezoneOffset();
329
+ let datePublished, expected;
330
+ if (offset > 0) {
331
+ // Positive local time zone offsets have earlier local dates than UTC
332
+ datePublished = new Date('2012-02-15T00:00:00Z');
333
+ expected = 'Published: Feb 14, 2012';
334
+ } else if (offset < 0) {
335
+ // Negative local time zone offsets have later local dates than UTC
336
+ datePublished = new Date('2012-02-15T23:59:59Z');
337
+ expected = 'Published: Feb 16, 2012';
338
+ } else {
339
+ // Local time may just be UTC itself
340
+ datePublished = new Date('2012-02-15T00:00:00Z');
341
+ expected = 'Published: Feb 15, 2012';
342
+ }
343
+
344
+ const model: Partial<TileModel> = {
345
+ datePublished,
346
+ };
347
+
348
+ const el = await fixture<TileList>(html`
349
+ <tile-list
350
+ useLocalTime
351
+ .model=${model}
352
+ .sortParam=${{ field: 'date', direction: 'desc' }}
353
+ >
354
+ </tile-list>
355
+ `);
356
+
357
+ const dateRow = el.shadowRoot?.getElementById('dates-line');
358
+ expect(dateRow).to.exist;
359
+
360
+ expect(dateRow?.textContent?.trim()).to.contain(expected);
361
+ });
362
+
363
+ it('should render links to /search pages (not search.php) for subject, creator, and source', async () => {
364
+ const model: Partial<TileModel> = {
365
+ subjects: ['foo'],
366
+ creators: ['bar'],
367
+ source: 'baz',
368
+ };
369
+
370
+ const el = await fixture<TileList>(html`
371
+ <tile-list .model=${model}></tile-list>
372
+ `);
373
+
374
+ const subjectLink = el.shadowRoot?.querySelector('#topics a[href]');
375
+ expect(subjectLink).to.exist;
376
+ expect(subjectLink?.getAttribute('href')).to.equal(
377
+ `/search?query=${encodeURIComponent('subject:"foo"')}`,
378
+ );
379
+
380
+ const creatorLink = el.shadowRoot?.querySelector('#creator a[href]');
381
+ expect(creatorLink).to.exist;
382
+ expect(creatorLink?.getAttribute('href')).to.equal(
383
+ `/search?query=${encodeURIComponent('creator:"bar"')}`,
384
+ );
385
+
386
+ const sourceLink = el.shadowRoot?.querySelector('#source a[href]');
387
+ expect(sourceLink).to.exist;
388
+ expect(sourceLink?.getAttribute('href')).to.equal(
389
+ `/search?query=${encodeURIComponent('source:"baz"')}`,
390
+ );
391
+ });
392
+
393
+ it('should render multi-line descriptions with spaces b/w lines', async () => {
394
+ const el = await fixture<TileList>(html`
395
+ <tile-list .model=${{ description: 'line1\nline2' }}> </tile-list>
396
+ `);
397
+
398
+ const descriptionBlock = el.shadowRoot?.getElementById('description');
399
+ expect(descriptionBlock).to.exist;
400
+ expect(descriptionBlock?.textContent?.trim()).to.equal('line1 line2'); // line break replaced by space
401
+ });
402
+
403
+ it('should render mediatype icon as link to corresponding mediatype collection details', async () => {
404
+ const model: Partial<TileModel> = {
405
+ mediatype: 'texts',
406
+ };
407
+
408
+ const el = await fixture<TileList>(html`
409
+ <tile-list
410
+ .baseNavigationUrl=${'https://archive.org'}
411
+ .model=${model}
412
+ ></tile-list>
413
+ `);
414
+
415
+ const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
416
+ expect(mediatypeLink).to.exist;
417
+ expect(mediatypeLink?.getAttribute('href')).to.equal(
418
+ `https://archive.org/details/texts`,
419
+ );
420
+ expect(mediatypeLink?.getAttribute('title')).to.equal('See more: texts');
421
+ });
422
+
423
+ it('should render mediatype icon as link even with empty baseNavigationUrl', async () => {
424
+ const model: Partial<TileModel> = {
425
+ mediatype: 'texts',
426
+ };
427
+
428
+ const el = await fixture<TileList>(html`
429
+ <tile-list .baseNavigationUrl=${''} .model=${model}></tile-list>
430
+ `);
431
+
432
+ const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
433
+ expect(mediatypeLink).to.exist;
434
+ expect(mediatypeLink?.getAttribute('href')).to.equal(`/details/texts`);
435
+ });
436
+
437
+ it('should render collection mediatype icon as link to search page', async () => {
438
+ const model: Partial<TileModel> = {
439
+ mediatype: 'collection',
440
+ };
441
+
442
+ const el = await fixture<TileList>(html`
443
+ <tile-list
444
+ .baseNavigationUrl=${'https://archive.org'}
445
+ .model=${model}
446
+ ></tile-list>
447
+ `);
448
+
449
+ const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
450
+ expect(mediatypeLink).to.exist;
451
+ expect(mediatypeLink?.getAttribute('href')).to.equal(
452
+ `https://archive.org/search?query=mediatype:collection&sort=-downloads`,
453
+ );
454
+ });
455
+
456
+ it('should not render account mediatype icon as link', async () => {
457
+ const model: Partial<TileModel> = {
458
+ mediatype: 'account',
459
+ };
460
+
461
+ const el = await fixture<TileList>(html`
462
+ <tile-list
463
+ .baseNavigationUrl=${'https://archive.org'}
464
+ .model=${model}
465
+ ></tile-list>
466
+ `);
467
+
468
+ const mediatypeLink = el.shadowRoot?.querySelector('a#icon-right');
469
+ expect(mediatypeLink).to.exist;
470
+ expect(mediatypeLink?.getAttribute('href')).not.to.exist;
471
+ });
472
+
473
+ it('should render date added for accounts', async () => {
474
+ const el = await fixture<TileList>(html`
475
+ <tile-list
476
+ .model=${{
477
+ mediatype: 'account',
478
+ dateAdded: new Date('2015-05-05T00:00:00'),
479
+ }}
480
+ >
481
+ </tile-list>
482
+ `);
483
+
484
+ const creatorBlock = el.shadowRoot?.getElementById('creator');
485
+ expect(creatorBlock).to.exist;
486
+ expect(creatorBlock?.textContent?.trim()).to.equal('Archivist since 2015');
487
+ });
488
+
489
+ it('should render web capture date links if present', async () => {
490
+ const captureDates = [
491
+ new Date('2010-01-02T12:34:56Z'),
492
+ new Date('2011-02-03T12:43:21Z'),
493
+ ];
494
+
495
+ const el = await fixture<TileList>(html`
496
+ <tile-list
497
+ .model=${{
498
+ identifier: 'foo',
499
+ title: 'https://example.com/',
500
+ captureDates,
501
+ }}
502
+ ></tile-list>
503
+ `);
504
+
505
+ const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
506
+ expect(captureDatesUl, 'capture dates container').to.exist;
507
+ expect(captureDatesUl?.children.length).to.equal(2);
508
+
509
+ const firstDateLink = captureDatesUl?.children[0]?.querySelector('a[href]');
510
+ expect(firstDateLink, 'first date link').to.exist;
511
+ expect(firstDateLink?.getAttribute('href')).to.equal(
512
+ 'https://web.archive.org/web/20100102123456/https%3A%2F%2Fexample.com%2F',
513
+ );
514
+ expect(firstDateLink?.textContent?.trim()).to.equal('Jan 02, 2010');
515
+
516
+ const secondDateLink =
517
+ captureDatesUl?.children[1]?.querySelector('a[href]');
518
+ expect(secondDateLink, 'second date link').to.exist;
519
+ expect(secondDateLink?.getAttribute('href')).to.equal(
520
+ 'https://web.archive.org/web/20110203124321/https%3A%2F%2Fexample.com%2F',
521
+ );
522
+ expect(secondDateLink?.textContent?.trim()).to.equal('Feb 03, 2011');
523
+ });
524
+
525
+ it('should not render web captures if no title is present', async () => {
526
+ const captureDates = [
527
+ new Date('2010-01-02T12:34:56Z'),
528
+ new Date('2011-02-03T12:43:21Z'),
529
+ ];
530
+
531
+ const el = await fixture<TileList>(html`
532
+ <tile-list
533
+ .model=${{
534
+ identifier: 'foo',
535
+ captureDates,
536
+ }}
537
+ ></tile-list>
538
+ `);
539
+
540
+ const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
541
+ expect(captureDatesUl).not.to.exist;
542
+ });
543
+
544
+ it('should render review snippet if present', async () => {
545
+ const review = {
546
+ title: 'Foo',
547
+ body: 'foo bar baz',
548
+ stars: 3,
549
+ };
550
+
551
+ const el = await fixture<TileList>(html`
552
+ <tile-list
553
+ .model=${{
554
+ identifier: 'foo',
555
+ review,
556
+ }}
557
+ ></tile-list>
558
+ `);
559
+
560
+ const reviewBlock = el.shadowRoot?.querySelector('review-block');
561
+ expect(reviewBlock).to.exist;
562
+ });
563
+
564
+ it('should not render review snippet block when no review is present', async () => {
565
+ const el = await fixture<TileList>(html`
566
+ <tile-list
567
+ .model=${{
568
+ identifier: 'foo',
569
+ }}
570
+ ></tile-list>
571
+ `);
572
+
573
+ const reviewBlock = el.shadowRoot?.querySelector('review-block');
574
+ expect(reviewBlock).not.to.exist;
575
+ });
576
+ });