@internetarchive/collection-browser 3.3.1 → 3.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/.editorconfig +29 -29
  2. package/.github/workflows/ci.yml +27 -27
  3. package/.github/workflows/gh-pages-main.yml +39 -39
  4. package/.github/workflows/npm-publish.yml +39 -39
  5. package/.github/workflows/pr-preview.yml +38 -38
  6. package/.husky/pre-commit +4 -4
  7. package/.prettierignore +1 -1
  8. package/LICENSE +661 -661
  9. package/README.md +83 -83
  10. package/dist/src/collection-browser.js +683 -683
  11. package/dist/src/collection-browser.js.map +1 -1
  12. package/dist/src/collection-facets/more-facets-content.js +118 -118
  13. package/dist/src/collection-facets/more-facets-content.js.map +1 -1
  14. package/dist/src/collection-facets.js +265 -266
  15. package/dist/src/collection-facets.js.map +1 -1
  16. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  17. package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
  18. package/dist/src/data-source/models.js.map +1 -1
  19. package/dist/src/tiles/base-tile-component.js.map +1 -1
  20. package/dist/src/tiles/grid/account-tile.js +36 -36
  21. package/dist/src/tiles/grid/account-tile.js.map +1 -1
  22. package/dist/src/tiles/grid/collection-tile.js +77 -77
  23. package/dist/src/tiles/grid/collection-tile.js.map +1 -1
  24. package/dist/src/tiles/grid/item-tile.js +137 -137
  25. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  26. package/dist/src/tiles/hover/hover-pane-controller.d.ts +9 -1
  27. package/dist/src/tiles/hover/hover-pane-controller.js +105 -37
  28. package/dist/src/tiles/hover/hover-pane-controller.js.map +1 -1
  29. package/dist/src/tiles/hover/tile-hover-pane.d.ts +1 -0
  30. package/dist/src/tiles/hover/tile-hover-pane.js +115 -112
  31. package/dist/src/tiles/hover/tile-hover-pane.js.map +1 -1
  32. package/dist/src/tiles/list/tile-list-compact.js +99 -99
  33. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  34. package/dist/src/tiles/list/tile-list.js +297 -297
  35. package/dist/src/tiles/list/tile-list.js.map +1 -1
  36. package/dist/src/tiles/tile-dispatcher.d.ts +4 -1
  37. package/dist/src/tiles/tile-dispatcher.js +231 -204
  38. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  39. package/dist/src/utils/format-date.js.map +1 -1
  40. package/dist/test/collection-browser.test.js +189 -189
  41. package/dist/test/collection-browser.test.js.map +1 -1
  42. package/dist/test/tiles/grid/item-tile.test.js +77 -77
  43. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  44. package/dist/test/tiles/hover/hover-pane-controller.test.js +68 -21
  45. package/dist/test/tiles/hover/hover-pane-controller.test.js.map +1 -1
  46. package/dist/test/tiles/list/tile-list-compact.test.js +70 -70
  47. package/dist/test/tiles/list/tile-list-compact.test.js.map +1 -1
  48. package/dist/test/tiles/list/tile-list.test.js +126 -126
  49. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  50. package/dist/test/tiles/tile-dispatcher.test.js +130 -52
  51. package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
  52. package/dist/test/utils/format-date.test.js.map +1 -1
  53. package/eslint.config.mjs +53 -53
  54. package/index.html +24 -24
  55. package/local.archive.org.cert +86 -86
  56. package/local.archive.org.key +27 -27
  57. package/package.json +118 -117
  58. package/renovate.json +6 -6
  59. package/src/collection-browser.ts +2829 -2829
  60. package/src/collection-facets/more-facets-content.ts +639 -639
  61. package/src/collection-facets.ts +994 -995
  62. package/src/data-source/collection-browser-data-source.ts +1401 -1401
  63. package/src/data-source/collection-browser-query-state.ts +65 -65
  64. package/src/data-source/models.ts +43 -43
  65. package/src/tiles/base-tile-component.ts +65 -65
  66. package/src/tiles/grid/account-tile.ts +113 -113
  67. package/src/tiles/grid/collection-tile.ts +163 -163
  68. package/src/tiles/grid/item-tile.ts +340 -340
  69. package/src/tiles/hover/hover-pane-controller.ts +613 -517
  70. package/src/tiles/hover/tile-hover-pane.ts +184 -180
  71. package/src/tiles/list/tile-list-compact.ts +239 -239
  72. package/src/tiles/list/tile-list.ts +700 -700
  73. package/src/tiles/tile-dispatcher.ts +517 -490
  74. package/src/utils/format-date.ts +62 -62
  75. package/test/collection-browser.test.ts +2403 -2403
  76. package/test/tiles/grid/item-tile.test.ts +520 -520
  77. package/test/tiles/hover/hover-pane-controller.test.ts +418 -353
  78. package/test/tiles/list/tile-list-compact.test.ts +282 -282
  79. package/test/tiles/list/tile-list.test.ts +552 -552
  80. package/test/tiles/tile-dispatcher.test.ts +283 -187
  81. package/test/utils/format-date.test.ts +89 -89
  82. package/tsconfig.json +20 -20
  83. package/web-dev-server.config.mjs +30 -30
  84. package/web-test-runner.config.mjs +41 -41
@@ -1,520 +1,520 @@
1
- import { expect, fixture } from '@open-wc/testing';
2
- import sinon from 'sinon';
3
- import { html } from 'lit';
4
- import type { ItemTile } from '../../../src/tiles/grid/item-tile';
5
-
6
- import '../../../src/tiles/grid/item-tile';
7
- import type { TileModel } from '../../../src/models';
8
-
9
- describe('Item Tile', () => {
10
- it('should render initial component', async () => {
11
- const el = await fixture<ItemTile>(html`<item-tile></item-tile>`);
12
-
13
- const container = el.shadowRoot?.querySelector('.container');
14
- const tileDetails = el.shadowRoot?.querySelector('.tile-details');
15
- const itemInfo = el.shadowRoot?.querySelector('.item-info');
16
- const itemTitle = el.shadowRoot?.querySelector('#title');
17
- const imageBlock = el.shadowRoot?.querySelector('image-block');
18
-
19
- expect(container).to.exist;
20
- expect(tileDetails).to.exist;
21
- expect(itemInfo).to.exist;
22
- expect(imageBlock).to.exist;
23
- expect(itemTitle).to.exist;
24
- });
25
-
26
- it('should render with created-by element', async () => {
27
- const el = await fixture<ItemTile>(
28
- html`<item-tile .model=${{ creator: 'someone' }}></item-tile>`,
29
- );
30
-
31
- const container = el.shadowRoot?.querySelector('.container');
32
- const tileDetails = el.shadowRoot?.querySelector('.tile-details');
33
- const itemInfo = el.shadowRoot?.querySelector('.item-info');
34
- const createdBy = el.shadowRoot?.querySelector('.created-by');
35
- const truncatedCreatorText = createdBy?.querySelector('.truncated');
36
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
37
-
38
- expect(container).to.exist;
39
- expect(tileDetails).to.exist;
40
- expect(itemInfo).to.exist;
41
- expect(createdBy).to.exist;
42
- expect(truncatedCreatorText).to.exist;
43
- expect(dateSortedBy).to.not.exist;
44
- });
45
-
46
- it('should not render with created-by but date element', async () => {
47
- const el = await fixture<ItemTile>(
48
- html`<item-tile .model=${{ datePublished: new Date() }}></item-tile>`,
49
- );
50
-
51
- el.sortParam = {
52
- field: 'date',
53
- direction: 'desc',
54
- };
55
- await el.updateComplete;
56
-
57
- const createdBy = el.shadowRoot?.querySelector('.created-by');
58
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
59
-
60
- expect(createdBy).to.not.exist;
61
- expect(dateSortedBy).to.exist;
62
- });
63
-
64
- it('should not render with created-by but reviewdate element', async () => {
65
- const el = await fixture<ItemTile>(
66
- html`<item-tile .model=${{ dateReviewed: new Date() }}></item-tile>`,
67
- );
68
-
69
- el.sortParam = {
70
- field: 'reviewdate',
71
- direction: 'desc',
72
- };
73
- await el.updateComplete;
74
-
75
- const createdBy = el.shadowRoot?.querySelector('.created-by');
76
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
77
-
78
- expect(createdBy).to.not.exist;
79
- expect(dateSortedBy).to.exist;
80
- });
81
-
82
- it('should not render with created-by but publicdate element', async () => {
83
- const el = await fixture<ItemTile>(
84
- html`<item-tile .model=${{ dateArchived: new Date() }}></item-tile>`,
85
- );
86
-
87
- el.sortParam = {
88
- field: 'publicdate',
89
- direction: 'desc',
90
- };
91
- await el.updateComplete;
92
-
93
- const createdBy = el.shadowRoot?.querySelector('.created-by');
94
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
95
-
96
- expect(createdBy).to.not.exist;
97
- expect(dateSortedBy).to.exist;
98
- });
99
-
100
- it('should not render date-sorted-by element if date is not provided', async () => {
101
- const el = await fixture<ItemTile>(
102
- html`<item-tile .model=${{ dateArchived: undefined }}></item-tile>`,
103
- );
104
-
105
- el.sortParam = {
106
- field: 'publicdate',
107
- direction: 'desc',
108
- };
109
- await el.updateComplete;
110
-
111
- const createdBy = el.shadowRoot?.querySelector('.created-by');
112
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
113
-
114
- expect(createdBy).to.not.exist;
115
- expect(dateSortedBy).to.not.exist;
116
- });
117
-
118
- it('should render without created-by when sorting by a date field', async () => {
119
- const el = await fixture<ItemTile>(
120
- html`<item-tile .model=${{ dateAdded: new Date() }}></item-tile>`,
121
- );
122
-
123
- el.sortParam = {
124
- field: 'addeddate',
125
- direction: 'asc',
126
- };
127
- await el.updateComplete;
128
-
129
- const itemInfo = el.shadowRoot?.querySelector('.item-info');
130
- const createdBy = el.shadowRoot?.querySelector('.created-by');
131
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
132
-
133
- expect(itemInfo).to.exist;
134
- expect(createdBy).to.not.exist;
135
- expect(dateSortedBy).to.exist;
136
- });
137
-
138
- it('should render with created-by when sort field is not a date', async () => {
139
- const el = await fixture<ItemTile>(
140
- html`<item-tile .model=${{ creator: 'someone' }}></item-tile>`,
141
- );
142
-
143
- el.sortParam = {
144
- field: 'week',
145
- direction: 'asc',
146
- };
147
- await el.updateComplete;
148
-
149
- const itemInfo = el.shadowRoot?.querySelector('.item-info');
150
- const createdBy = el.shadowRoot?.querySelector('.created-by');
151
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
152
-
153
- expect(itemInfo).to.exist;
154
- expect(dateSortedBy).to.not.exist; // it should not exist because this is not a date sort
155
- expect(createdBy).to.exist;
156
- });
157
-
158
- it('should render published date when sorting by it', async () => {
159
- const model: Partial<TileModel> = {
160
- dateAdded: new Date(2010, 0, 2),
161
- dateArchived: new Date(2011, 0, 2),
162
- datePublished: new Date(2012, 0, 2),
163
- dateReviewed: new Date(2013, 0, 2),
164
- };
165
-
166
- const el = await fixture<ItemTile>(html`
167
- <item-tile
168
- .model=${model}
169
- .sortParam=${{ field: 'date', direction: 'desc' }}
170
- >
171
- </item-tile>
172
- `);
173
-
174
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
175
- expect(dateSortedBy).to.exist;
176
- expect(dateSortedBy?.textContent?.trim()).to.contain(
177
- 'published Jan 02, 2012',
178
- );
179
- });
180
-
181
- it('should render added date when sorting by it', async () => {
182
- const model: Partial<TileModel> = {
183
- dateAdded: new Date(2010, 0, 2),
184
- dateArchived: new Date(2011, 0, 2),
185
- datePublished: new Date(2012, 0, 2),
186
- dateReviewed: new Date(2013, 0, 2),
187
- };
188
-
189
- const el = await fixture<ItemTile>(html`
190
- <item-tile
191
- .model=${model}
192
- .sortParam=${{ field: 'addeddate', direction: 'desc' }}
193
- >
194
- </item-tile>
195
- `);
196
-
197
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
198
- expect(dateSortedBy).to.exist;
199
- expect(dateSortedBy?.textContent?.trim()).to.contain('added Jan 02, 2010');
200
- });
201
-
202
- it('should render archived date when sorting by it', async () => {
203
- const model: Partial<TileModel> = {
204
- dateAdded: new Date(2010, 0, 2),
205
- dateArchived: new Date(2011, 0, 2),
206
- datePublished: new Date(2012, 0, 2),
207
- dateReviewed: new Date(2013, 0, 2),
208
- };
209
-
210
- const el = await fixture<ItemTile>(html`
211
- <item-tile
212
- .model=${model}
213
- .sortParam=${{ field: 'publicdate', direction: 'desc' }}
214
- >
215
- </item-tile>
216
- `);
217
-
218
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
219
- expect(dateSortedBy).to.exist;
220
- expect(dateSortedBy?.textContent?.trim()).to.contain(
221
- 'archived Jan 02, 2011',
222
- );
223
- });
224
-
225
- it('should render reviewed date when sorting by it', async () => {
226
- const model: Partial<TileModel> = {
227
- dateAdded: new Date(2010, 0, 2),
228
- dateArchived: new Date(2011, 0, 2),
229
- datePublished: new Date(2012, 0, 2),
230
- dateReviewed: new Date(2013, 0, 2),
231
- };
232
-
233
- const el = await fixture<ItemTile>(html`
234
- <item-tile
235
- .model=${model}
236
- .sortParam=${{ field: 'reviewdate', direction: 'desc' }}
237
- >
238
- </item-tile>
239
- `);
240
-
241
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
242
- expect(dateSortedBy).to.exist;
243
- expect(dateSortedBy?.textContent?.trim()).to.contain(
244
- 'reviewed Jan 02, 2013',
245
- );
246
- });
247
-
248
- it('should only show the year for a date published of Jan 1 at midnight UTC', async () => {
249
- const model: Partial<TileModel> = {
250
- datePublished: new Date('2012-01-01T00:00:00Z'),
251
- };
252
-
253
- const el = await fixture<ItemTile>(html`
254
- <item-tile
255
- .model=${model}
256
- .sortParam=${{ field: 'date', direction: 'desc' }}
257
- >
258
- </item-tile>
259
- `);
260
-
261
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
262
- expect(dateSortedBy).to.exist;
263
- expect(dateSortedBy?.textContent?.trim()).to.equal('published 2012');
264
- });
265
-
266
- it('should show full date added/archived/reviewed, even on Jan 1 at midnight UTC', async () => {
267
- const model: Partial<TileModel> = {
268
- dateAdded: new Date(2010, 0, 1, 0, 0, 0, 0),
269
- dateArchived: new Date(2011, 0, 1, 0, 0, 0, 0),
270
- datePublished: new Date(2012, 0, 1, 0, 0, 0, 0),
271
- dateReviewed: new Date(2013, 0, 1, 0, 0, 0, 0),
272
- };
273
-
274
- const el = await fixture<ItemTile>(html`
275
- <item-tile
276
- .model=${model}
277
- .sortParam=${{ field: 'addeddate', direction: 'desc' }}
278
- >
279
- </item-tile>
280
- `);
281
-
282
- let dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
283
- expect(dateSortedBy).to.exist;
284
- expect(dateSortedBy?.textContent?.trim()).to.equal('added Jan 01, 2010');
285
-
286
- el.sortParam = { field: 'publicdate', direction: 'desc' };
287
- await el.updateComplete;
288
- dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
289
- expect(dateSortedBy).to.exist;
290
- expect(dateSortedBy?.textContent?.trim()).to.equal('archived Jan 01, 2011');
291
-
292
- el.sortParam = { field: 'reviewdate', direction: 'desc' };
293
- await el.updateComplete;
294
- dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
295
- expect(dateSortedBy).to.exist;
296
- expect(dateSortedBy?.textContent?.trim()).to.equal('reviewed Jan 01, 2013');
297
- });
298
-
299
- it('should display dates in UTC time zone by default', async () => {
300
- const model: Partial<TileModel> = {
301
- datePublished: new Date('2012-02-15T00:00:00Z'),
302
- };
303
-
304
- const el = await fixture<ItemTile>(html`
305
- <item-tile
306
- .model=${model}
307
- .sortParam=${{ field: 'date', direction: 'desc' }}
308
- >
309
- </item-tile>
310
- `);
311
-
312
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
313
- expect(dateSortedBy).to.exist;
314
- expect(dateSortedBy?.textContent?.trim()).to.equal(
315
- 'published Feb 15, 2012',
316
- );
317
- });
318
-
319
- it('should display dates in local time when useLocalTime option is true', async () => {
320
- // Expected behavior depends on the time zone offset where the testing occurs
321
- const offset = new Date().getTimezoneOffset();
322
- let datePublished, expected;
323
- if (offset > 0) {
324
- // Positive local time zone offsets have earlier local dates than UTC
325
- datePublished = new Date('2012-02-15T00:00:00Z');
326
- expected = 'published Feb 14, 2012';
327
- } else if (offset < 0) {
328
- // Negative local time zone offsets have later local dates than UTC
329
- datePublished = new Date('2012-02-15T23:59:59Z');
330
- expected = 'published Feb 16, 2012';
331
- } else {
332
- // Local time may just be UTC itself
333
- datePublished = new Date('2012-02-15T00:00:00Z');
334
- expected = 'published Feb 15, 2012';
335
- }
336
-
337
- const model: Partial<TileModel> = {
338
- datePublished,
339
- };
340
-
341
- const el = await fixture<ItemTile>(html`
342
- <item-tile
343
- useLocalTime
344
- .model=${model}
345
- .sortParam=${{ field: 'date', direction: 'desc' }}
346
- >
347
- </item-tile>
348
- `);
349
-
350
- const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
351
- expect(dateSortedBy).to.exist;
352
- expect(dateSortedBy?.textContent?.trim()).to.equal(expected);
353
- });
354
-
355
- it('should show the first creator matching the letter filter, if defined', async () => {
356
- const model: Partial<TileModel> = {
357
- creator: 'foo',
358
- creators: ['foo', 'bar', 'baz'],
359
- };
360
-
361
- const el = await fixture<ItemTile>(html`
362
- <item-tile .model=${model} .creatorFilter=${'B'}> </item-tile>
363
- `);
364
-
365
- const creator = el.shadowRoot?.querySelector('.created-by');
366
- expect(creator).to.exist;
367
- expect(creator?.textContent?.trim()).to.match(/by\s+bar/);
368
- });
369
-
370
- it('should render with snippet block when it has snippets', async () => {
371
- const el = await fixture<ItemTile>(html`
372
- <item-tile .model=${{ snippets: ['some {{{snippet}}} text'] }}>
373
- </item-tile>
374
- `);
375
-
376
- const snippetBlock = el.shadowRoot?.querySelector('text-snippet-block');
377
-
378
- expect(snippetBlock).to.exist;
379
- });
380
-
381
- it('should not render snippet block when no snippets are present', async () => {
382
- const el = await fixture<ItemTile>(html`<item-tile></item-tile>`);
383
-
384
- const snippetBlock = el.shadowRoot?.querySelector('text-snippet-block');
385
-
386
- expect(snippetBlock).to.not.exist;
387
- });
388
-
389
- it('should render info button when showInfoButton flag is set', async () => {
390
- const el = await fixture<ItemTile>(html`
391
- <item-tile ?showInfoButton=${true}> </item-tile>
392
- `);
393
-
394
- const infoButton = el.shadowRoot?.querySelector('.info-button');
395
-
396
- expect(infoButton).to.exist;
397
- });
398
-
399
- it('should dispatch event when info button tapped', async () => {
400
- const infoButtonSpy = sinon.spy();
401
- const el = await fixture<ItemTile>(html`
402
- <item-tile ?showInfoButton=${true} @infoButtonPressed=${infoButtonSpy}>
403
- </item-tile>
404
- `);
405
-
406
- const infoButton = el.shadowRoot?.querySelector(
407
- '.info-button',
408
- ) as HTMLButtonElement;
409
- infoButton.click();
410
- await el.updateComplete;
411
-
412
- expect(infoButtonSpy.callCount).to.equal(1);
413
- });
414
-
415
- it('should render with volume/issue view', async () => {
416
- const el = await fixture<ItemTile>(html`
417
- <item-tile .model=${{ volume: '1', issue: 'Index' }}></item-tile>
418
- `);
419
-
420
- const volumeIssueBlock = el.shadowRoot?.querySelector('.volume-issue');
421
-
422
- expect(volumeIssueBlock).to.exist;
423
- });
424
-
425
- it('should render with volume/issue view to not render', async () => {
426
- const el = await fixture<ItemTile>(html`<item-tile></item-tile>`);
427
-
428
- const volumeIssueBlock = el.shadowRoot?.querySelector('.volume-issue');
429
-
430
- expect(volumeIssueBlock).to.not.exist;
431
- });
432
-
433
- it('should render web capture date links if present', async () => {
434
- const captureDates = [
435
- new Date('2010-01-02T12:34:56Z'),
436
- new Date('2011-02-03T12:43:21Z'),
437
- ];
438
-
439
- const el = await fixture<ItemTile>(html`
440
- <item-tile
441
- .model=${{
442
- identifier: 'foo',
443
- title: 'https://example.com/',
444
- captureDates,
445
- }}
446
- ></item-tile>
447
- `);
448
-
449
- const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
450
- expect(captureDatesUl, 'capture dates container').to.exist;
451
- expect(captureDatesUl?.children.length).to.equal(2);
452
-
453
- const firstDateLink = captureDatesUl?.children[0]?.querySelector('a[href]');
454
- expect(firstDateLink, 'first date link').to.exist;
455
- expect(firstDateLink?.getAttribute('href')).to.equal(
456
- 'https://web.archive.org/web/20100102123456/https%3A%2F%2Fexample.com%2F',
457
- );
458
- expect(firstDateLink?.textContent?.trim()).to.equal('Jan 02, 2010');
459
-
460
- const secondDateLink =
461
- captureDatesUl?.children[1]?.querySelector('a[href]');
462
- expect(secondDateLink, 'second date link').to.exist;
463
- expect(secondDateLink?.getAttribute('href')).to.equal(
464
- 'https://web.archive.org/web/20110203124321/https%3A%2F%2Fexample.com%2F',
465
- );
466
- expect(secondDateLink?.textContent?.trim()).to.equal('Feb 03, 2011');
467
- });
468
-
469
- it('should not render web captures if no title is present', async () => {
470
- const captureDates = [
471
- new Date('2010-01-02T12:34:56Z'),
472
- new Date('2011-02-03T12:43:21Z'),
473
- ];
474
-
475
- const el = await fixture<ItemTile>(html`
476
- <item-tile
477
- .model=${{
478
- identifier: 'foo',
479
- captureDates,
480
- }}
481
- ></item-tile>
482
- `);
483
-
484
- const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
485
- expect(captureDatesUl).not.to.exist;
486
- });
487
-
488
- it('should render review snippet if present', async () => {
489
- const review = {
490
- title: 'Foo',
491
- body: 'foo bar baz',
492
- stars: 3,
493
- };
494
-
495
- const el = await fixture<ItemTile>(html`
496
- <item-tile
497
- .model=${{
498
- identifier: 'foo',
499
- review,
500
- }}
501
- ></item-tile>
502
- `);
503
-
504
- const reviewBlock = el.shadowRoot?.querySelector('review-block');
505
- expect(reviewBlock).to.exist;
506
- });
507
-
508
- it('should not render review snippet block when no review is present', async () => {
509
- const el = await fixture<ItemTile>(html`
510
- <item-tile
511
- .model=${{
512
- identifier: 'foo',
513
- }}
514
- ></item-tile>
515
- `);
516
-
517
- const reviewBlock = el.shadowRoot?.querySelector('review-block');
518
- expect(reviewBlock).not.to.exist;
519
- });
520
- });
1
+ import { expect, fixture } from '@open-wc/testing';
2
+ import sinon from 'sinon';
3
+ import { html } from 'lit';
4
+ import type { ItemTile } from '../../../src/tiles/grid/item-tile';
5
+
6
+ import '../../../src/tiles/grid/item-tile';
7
+ import type { TileModel } from '../../../src/models';
8
+
9
+ describe('Item Tile', () => {
10
+ it('should render initial component', async () => {
11
+ const el = await fixture<ItemTile>(html`<item-tile></item-tile>`);
12
+
13
+ const container = el.shadowRoot?.querySelector('.container');
14
+ const tileDetails = el.shadowRoot?.querySelector('.tile-details');
15
+ const itemInfo = el.shadowRoot?.querySelector('.item-info');
16
+ const itemTitle = el.shadowRoot?.querySelector('#title');
17
+ const imageBlock = el.shadowRoot?.querySelector('image-block');
18
+
19
+ expect(container).to.exist;
20
+ expect(tileDetails).to.exist;
21
+ expect(itemInfo).to.exist;
22
+ expect(imageBlock).to.exist;
23
+ expect(itemTitle).to.exist;
24
+ });
25
+
26
+ it('should render with created-by element', async () => {
27
+ const el = await fixture<ItemTile>(
28
+ html`<item-tile .model=${{ creator: 'someone' }}></item-tile>`,
29
+ );
30
+
31
+ const container = el.shadowRoot?.querySelector('.container');
32
+ const tileDetails = el.shadowRoot?.querySelector('.tile-details');
33
+ const itemInfo = el.shadowRoot?.querySelector('.item-info');
34
+ const createdBy = el.shadowRoot?.querySelector('.created-by');
35
+ const truncatedCreatorText = createdBy?.querySelector('.truncated');
36
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
37
+
38
+ expect(container).to.exist;
39
+ expect(tileDetails).to.exist;
40
+ expect(itemInfo).to.exist;
41
+ expect(createdBy).to.exist;
42
+ expect(truncatedCreatorText).to.exist;
43
+ expect(dateSortedBy).to.not.exist;
44
+ });
45
+
46
+ it('should not render with created-by but date element', async () => {
47
+ const el = await fixture<ItemTile>(
48
+ html`<item-tile .model=${{ datePublished: new Date() }}></item-tile>`,
49
+ );
50
+
51
+ el.sortParam = {
52
+ field: 'date',
53
+ direction: 'desc',
54
+ };
55
+ await el.updateComplete;
56
+
57
+ const createdBy = el.shadowRoot?.querySelector('.created-by');
58
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
59
+
60
+ expect(createdBy).to.not.exist;
61
+ expect(dateSortedBy).to.exist;
62
+ });
63
+
64
+ it('should not render with created-by but reviewdate element', async () => {
65
+ const el = await fixture<ItemTile>(
66
+ html`<item-tile .model=${{ dateReviewed: new Date() }}></item-tile>`,
67
+ );
68
+
69
+ el.sortParam = {
70
+ field: 'reviewdate',
71
+ direction: 'desc',
72
+ };
73
+ await el.updateComplete;
74
+
75
+ const createdBy = el.shadowRoot?.querySelector('.created-by');
76
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
77
+
78
+ expect(createdBy).to.not.exist;
79
+ expect(dateSortedBy).to.exist;
80
+ });
81
+
82
+ it('should not render with created-by but publicdate element', async () => {
83
+ const el = await fixture<ItemTile>(
84
+ html`<item-tile .model=${{ dateArchived: new Date() }}></item-tile>`,
85
+ );
86
+
87
+ el.sortParam = {
88
+ field: 'publicdate',
89
+ direction: 'desc',
90
+ };
91
+ await el.updateComplete;
92
+
93
+ const createdBy = el.shadowRoot?.querySelector('.created-by');
94
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
95
+
96
+ expect(createdBy).to.not.exist;
97
+ expect(dateSortedBy).to.exist;
98
+ });
99
+
100
+ it('should not render date-sorted-by element if date is not provided', async () => {
101
+ const el = await fixture<ItemTile>(
102
+ html`<item-tile .model=${{ dateArchived: undefined }}></item-tile>`,
103
+ );
104
+
105
+ el.sortParam = {
106
+ field: 'publicdate',
107
+ direction: 'desc',
108
+ };
109
+ await el.updateComplete;
110
+
111
+ const createdBy = el.shadowRoot?.querySelector('.created-by');
112
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
113
+
114
+ expect(createdBy).to.not.exist;
115
+ expect(dateSortedBy).to.not.exist;
116
+ });
117
+
118
+ it('should render without created-by when sorting by a date field', async () => {
119
+ const el = await fixture<ItemTile>(
120
+ html`<item-tile .model=${{ dateAdded: new Date() }}></item-tile>`,
121
+ );
122
+
123
+ el.sortParam = {
124
+ field: 'addeddate',
125
+ direction: 'asc',
126
+ };
127
+ await el.updateComplete;
128
+
129
+ const itemInfo = el.shadowRoot?.querySelector('.item-info');
130
+ const createdBy = el.shadowRoot?.querySelector('.created-by');
131
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
132
+
133
+ expect(itemInfo).to.exist;
134
+ expect(createdBy).to.not.exist;
135
+ expect(dateSortedBy).to.exist;
136
+ });
137
+
138
+ it('should render with created-by when sort field is not a date', async () => {
139
+ const el = await fixture<ItemTile>(
140
+ html`<item-tile .model=${{ creator: 'someone' }}></item-tile>`,
141
+ );
142
+
143
+ el.sortParam = {
144
+ field: 'week',
145
+ direction: 'asc',
146
+ };
147
+ await el.updateComplete;
148
+
149
+ const itemInfo = el.shadowRoot?.querySelector('.item-info');
150
+ const createdBy = el.shadowRoot?.querySelector('.created-by');
151
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
152
+
153
+ expect(itemInfo).to.exist;
154
+ expect(dateSortedBy).to.not.exist; // it should not exist because this is not a date sort
155
+ expect(createdBy).to.exist;
156
+ });
157
+
158
+ it('should render published date when sorting by it', async () => {
159
+ const model: Partial<TileModel> = {
160
+ dateAdded: new Date(2010, 0, 2),
161
+ dateArchived: new Date(2011, 0, 2),
162
+ datePublished: new Date(2012, 0, 2),
163
+ dateReviewed: new Date(2013, 0, 2),
164
+ };
165
+
166
+ const el = await fixture<ItemTile>(html`
167
+ <item-tile
168
+ .model=${model}
169
+ .sortParam=${{ field: 'date', direction: 'desc' }}
170
+ >
171
+ </item-tile>
172
+ `);
173
+
174
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
175
+ expect(dateSortedBy).to.exist;
176
+ expect(dateSortedBy?.textContent?.trim()).to.contain(
177
+ 'published Jan 02, 2012',
178
+ );
179
+ });
180
+
181
+ it('should render added date when sorting by it', async () => {
182
+ const model: Partial<TileModel> = {
183
+ dateAdded: new Date(2010, 0, 2),
184
+ dateArchived: new Date(2011, 0, 2),
185
+ datePublished: new Date(2012, 0, 2),
186
+ dateReviewed: new Date(2013, 0, 2),
187
+ };
188
+
189
+ const el = await fixture<ItemTile>(html`
190
+ <item-tile
191
+ .model=${model}
192
+ .sortParam=${{ field: 'addeddate', direction: 'desc' }}
193
+ >
194
+ </item-tile>
195
+ `);
196
+
197
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
198
+ expect(dateSortedBy).to.exist;
199
+ expect(dateSortedBy?.textContent?.trim()).to.contain('added Jan 02, 2010');
200
+ });
201
+
202
+ it('should render archived date when sorting by it', async () => {
203
+ const model: Partial<TileModel> = {
204
+ dateAdded: new Date(2010, 0, 2),
205
+ dateArchived: new Date(2011, 0, 2),
206
+ datePublished: new Date(2012, 0, 2),
207
+ dateReviewed: new Date(2013, 0, 2),
208
+ };
209
+
210
+ const el = await fixture<ItemTile>(html`
211
+ <item-tile
212
+ .model=${model}
213
+ .sortParam=${{ field: 'publicdate', direction: 'desc' }}
214
+ >
215
+ </item-tile>
216
+ `);
217
+
218
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
219
+ expect(dateSortedBy).to.exist;
220
+ expect(dateSortedBy?.textContent?.trim()).to.contain(
221
+ 'archived Jan 02, 2011',
222
+ );
223
+ });
224
+
225
+ it('should render reviewed date when sorting by it', async () => {
226
+ const model: Partial<TileModel> = {
227
+ dateAdded: new Date(2010, 0, 2),
228
+ dateArchived: new Date(2011, 0, 2),
229
+ datePublished: new Date(2012, 0, 2),
230
+ dateReviewed: new Date(2013, 0, 2),
231
+ };
232
+
233
+ const el = await fixture<ItemTile>(html`
234
+ <item-tile
235
+ .model=${model}
236
+ .sortParam=${{ field: 'reviewdate', direction: 'desc' }}
237
+ >
238
+ </item-tile>
239
+ `);
240
+
241
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
242
+ expect(dateSortedBy).to.exist;
243
+ expect(dateSortedBy?.textContent?.trim()).to.contain(
244
+ 'reviewed Jan 02, 2013',
245
+ );
246
+ });
247
+
248
+ it('should only show the year for a date published of Jan 1 at midnight UTC', async () => {
249
+ const model: Partial<TileModel> = {
250
+ datePublished: new Date('2012-01-01T00:00:00Z'),
251
+ };
252
+
253
+ const el = await fixture<ItemTile>(html`
254
+ <item-tile
255
+ .model=${model}
256
+ .sortParam=${{ field: 'date', direction: 'desc' }}
257
+ >
258
+ </item-tile>
259
+ `);
260
+
261
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
262
+ expect(dateSortedBy).to.exist;
263
+ expect(dateSortedBy?.textContent?.trim()).to.equal('published 2012');
264
+ });
265
+
266
+ it('should show full date added/archived/reviewed, even on Jan 1 at midnight UTC', async () => {
267
+ const model: Partial<TileModel> = {
268
+ dateAdded: new Date(2010, 0, 1, 0, 0, 0, 0),
269
+ dateArchived: new Date(2011, 0, 1, 0, 0, 0, 0),
270
+ datePublished: new Date(2012, 0, 1, 0, 0, 0, 0),
271
+ dateReviewed: new Date(2013, 0, 1, 0, 0, 0, 0),
272
+ };
273
+
274
+ const el = await fixture<ItemTile>(html`
275
+ <item-tile
276
+ .model=${model}
277
+ .sortParam=${{ field: 'addeddate', direction: 'desc' }}
278
+ >
279
+ </item-tile>
280
+ `);
281
+
282
+ let dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
283
+ expect(dateSortedBy).to.exist;
284
+ expect(dateSortedBy?.textContent?.trim()).to.equal('added Jan 01, 2010');
285
+
286
+ el.sortParam = { field: 'publicdate', direction: 'desc' };
287
+ await el.updateComplete;
288
+ dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
289
+ expect(dateSortedBy).to.exist;
290
+ expect(dateSortedBy?.textContent?.trim()).to.equal('archived Jan 01, 2011');
291
+
292
+ el.sortParam = { field: 'reviewdate', direction: 'desc' };
293
+ await el.updateComplete;
294
+ dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
295
+ expect(dateSortedBy).to.exist;
296
+ expect(dateSortedBy?.textContent?.trim()).to.equal('reviewed Jan 01, 2013');
297
+ });
298
+
299
+ it('should display dates in UTC time zone by default', async () => {
300
+ const model: Partial<TileModel> = {
301
+ datePublished: new Date('2012-02-15T00:00:00Z'),
302
+ };
303
+
304
+ const el = await fixture<ItemTile>(html`
305
+ <item-tile
306
+ .model=${model}
307
+ .sortParam=${{ field: 'date', direction: 'desc' }}
308
+ >
309
+ </item-tile>
310
+ `);
311
+
312
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
313
+ expect(dateSortedBy).to.exist;
314
+ expect(dateSortedBy?.textContent?.trim()).to.equal(
315
+ 'published Feb 15, 2012',
316
+ );
317
+ });
318
+
319
+ it('should display dates in local time when useLocalTime option is true', async () => {
320
+ // Expected behavior depends on the time zone offset where the testing occurs
321
+ const offset = new Date().getTimezoneOffset();
322
+ let datePublished, expected;
323
+ if (offset > 0) {
324
+ // Positive local time zone offsets have earlier local dates than UTC
325
+ datePublished = new Date('2012-02-15T00:00:00Z');
326
+ expected = 'published Feb 14, 2012';
327
+ } else if (offset < 0) {
328
+ // Negative local time zone offsets have later local dates than UTC
329
+ datePublished = new Date('2012-02-15T23:59:59Z');
330
+ expected = 'published Feb 16, 2012';
331
+ } else {
332
+ // Local time may just be UTC itself
333
+ datePublished = new Date('2012-02-15T00:00:00Z');
334
+ expected = 'published Feb 15, 2012';
335
+ }
336
+
337
+ const model: Partial<TileModel> = {
338
+ datePublished,
339
+ };
340
+
341
+ const el = await fixture<ItemTile>(html`
342
+ <item-tile
343
+ useLocalTime
344
+ .model=${model}
345
+ .sortParam=${{ field: 'date', direction: 'desc' }}
346
+ >
347
+ </item-tile>
348
+ `);
349
+
350
+ const dateSortedBy = el.shadowRoot?.querySelector('.date-sorted-by');
351
+ expect(dateSortedBy).to.exist;
352
+ expect(dateSortedBy?.textContent?.trim()).to.equal(expected);
353
+ });
354
+
355
+ it('should show the first creator matching the letter filter, if defined', async () => {
356
+ const model: Partial<TileModel> = {
357
+ creator: 'foo',
358
+ creators: ['foo', 'bar', 'baz'],
359
+ };
360
+
361
+ const el = await fixture<ItemTile>(html`
362
+ <item-tile .model=${model} .creatorFilter=${'B'}> </item-tile>
363
+ `);
364
+
365
+ const creator = el.shadowRoot?.querySelector('.created-by');
366
+ expect(creator).to.exist;
367
+ expect(creator?.textContent?.trim()).to.match(/by\s+bar/);
368
+ });
369
+
370
+ it('should render with snippet block when it has snippets', async () => {
371
+ const el = await fixture<ItemTile>(html`
372
+ <item-tile .model=${{ snippets: ['some {{{snippet}}} text'] }}>
373
+ </item-tile>
374
+ `);
375
+
376
+ const snippetBlock = el.shadowRoot?.querySelector('text-snippet-block');
377
+
378
+ expect(snippetBlock).to.exist;
379
+ });
380
+
381
+ it('should not render snippet block when no snippets are present', async () => {
382
+ const el = await fixture<ItemTile>(html`<item-tile></item-tile>`);
383
+
384
+ const snippetBlock = el.shadowRoot?.querySelector('text-snippet-block');
385
+
386
+ expect(snippetBlock).to.not.exist;
387
+ });
388
+
389
+ it('should render info button when showInfoButton flag is set', async () => {
390
+ const el = await fixture<ItemTile>(html`
391
+ <item-tile ?showInfoButton=${true}> </item-tile>
392
+ `);
393
+
394
+ const infoButton = el.shadowRoot?.querySelector('.info-button');
395
+
396
+ expect(infoButton).to.exist;
397
+ });
398
+
399
+ it('should dispatch event when info button tapped', async () => {
400
+ const infoButtonSpy = sinon.spy();
401
+ const el = await fixture<ItemTile>(html`
402
+ <item-tile ?showInfoButton=${true} @infoButtonPressed=${infoButtonSpy}>
403
+ </item-tile>
404
+ `);
405
+
406
+ const infoButton = el.shadowRoot?.querySelector(
407
+ '.info-button',
408
+ ) as HTMLButtonElement;
409
+ infoButton.click();
410
+ await el.updateComplete;
411
+
412
+ expect(infoButtonSpy.callCount).to.equal(1);
413
+ });
414
+
415
+ it('should render with volume/issue view', async () => {
416
+ const el = await fixture<ItemTile>(html`
417
+ <item-tile .model=${{ volume: '1', issue: 'Index' }}></item-tile>
418
+ `);
419
+
420
+ const volumeIssueBlock = el.shadowRoot?.querySelector('.volume-issue');
421
+
422
+ expect(volumeIssueBlock).to.exist;
423
+ });
424
+
425
+ it('should render with volume/issue view to not render', async () => {
426
+ const el = await fixture<ItemTile>(html`<item-tile></item-tile>`);
427
+
428
+ const volumeIssueBlock = el.shadowRoot?.querySelector('.volume-issue');
429
+
430
+ expect(volumeIssueBlock).to.not.exist;
431
+ });
432
+
433
+ it('should render web capture date links if present', async () => {
434
+ const captureDates = [
435
+ new Date('2010-01-02T12:34:56Z'),
436
+ new Date('2011-02-03T12:43:21Z'),
437
+ ];
438
+
439
+ const el = await fixture<ItemTile>(html`
440
+ <item-tile
441
+ .model=${{
442
+ identifier: 'foo',
443
+ title: 'https://example.com/',
444
+ captureDates,
445
+ }}
446
+ ></item-tile>
447
+ `);
448
+
449
+ const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
450
+ expect(captureDatesUl, 'capture dates container').to.exist;
451
+ expect(captureDatesUl?.children.length).to.equal(2);
452
+
453
+ const firstDateLink = captureDatesUl?.children[0]?.querySelector('a[href]');
454
+ expect(firstDateLink, 'first date link').to.exist;
455
+ expect(firstDateLink?.getAttribute('href')).to.equal(
456
+ 'https://web.archive.org/web/20100102123456/https%3A%2F%2Fexample.com%2F',
457
+ );
458
+ expect(firstDateLink?.textContent?.trim()).to.equal('Jan 02, 2010');
459
+
460
+ const secondDateLink =
461
+ captureDatesUl?.children[1]?.querySelector('a[href]');
462
+ expect(secondDateLink, 'second date link').to.exist;
463
+ expect(secondDateLink?.getAttribute('href')).to.equal(
464
+ 'https://web.archive.org/web/20110203124321/https%3A%2F%2Fexample.com%2F',
465
+ );
466
+ expect(secondDateLink?.textContent?.trim()).to.equal('Feb 03, 2011');
467
+ });
468
+
469
+ it('should not render web captures if no title is present', async () => {
470
+ const captureDates = [
471
+ new Date('2010-01-02T12:34:56Z'),
472
+ new Date('2011-02-03T12:43:21Z'),
473
+ ];
474
+
475
+ const el = await fixture<ItemTile>(html`
476
+ <item-tile
477
+ .model=${{
478
+ identifier: 'foo',
479
+ captureDates,
480
+ }}
481
+ ></item-tile>
482
+ `);
483
+
484
+ const captureDatesUl = el.shadowRoot?.querySelector('.capture-dates');
485
+ expect(captureDatesUl).not.to.exist;
486
+ });
487
+
488
+ it('should render review snippet if present', async () => {
489
+ const review = {
490
+ title: 'Foo',
491
+ body: 'foo bar baz',
492
+ stars: 3,
493
+ };
494
+
495
+ const el = await fixture<ItemTile>(html`
496
+ <item-tile
497
+ .model=${{
498
+ identifier: 'foo',
499
+ review,
500
+ }}
501
+ ></item-tile>
502
+ `);
503
+
504
+ const reviewBlock = el.shadowRoot?.querySelector('review-block');
505
+ expect(reviewBlock).to.exist;
506
+ });
507
+
508
+ it('should not render review snippet block when no review is present', async () => {
509
+ const el = await fixture<ItemTile>(html`
510
+ <item-tile
511
+ .model=${{
512
+ identifier: 'foo',
513
+ }}
514
+ ></item-tile>
515
+ `);
516
+
517
+ const reviewBlock = el.shadowRoot?.querySelector('review-block');
518
+ expect(reviewBlock).not.to.exist;
519
+ });
520
+ });