@internetarchive/collection-browser 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/collection-browser.d.ts +4 -0
- package/dist/src/collection-browser.js +21 -1
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/tiles/base-tile-component.d.ts +7 -0
- package/dist/src/tiles/base-tile-component.js +13 -0
- package/dist/src/tiles/base-tile-component.js.map +1 -1
- package/dist/src/tiles/grid/account-tile.js +1 -0
- package/dist/src/tiles/grid/account-tile.js.map +1 -1
- package/dist/src/tiles/grid/collection-tile.js +1 -0
- package/dist/src/tiles/grid/collection-tile.js.map +1 -1
- package/dist/src/tiles/grid/item-tile.d.ts +1 -1
- package/dist/src/tiles/grid/item-tile.js +3 -4
- package/dist/src/tiles/grid/item-tile.js.map +1 -1
- package/dist/src/tiles/list/tile-list-compact.js +4 -2
- package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
- package/dist/src/tiles/list/tile-list.js +3 -3
- package/dist/src/tiles/list/tile-list.js.map +1 -1
- package/dist/src/tiles/tile-dispatcher.js +4 -0
- package/dist/src/tiles/tile-dispatcher.js.map +1 -1
- package/dist/src/utils/format-date.d.ts +15 -1
- package/dist/src/utils/format-date.js +8 -3
- package/dist/src/utils/format-date.js.map +1 -1
- package/dist/test/tiles/grid/item-tile.test.js +51 -0
- package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
- package/dist/test/tiles/list/tile-list-compact.test.js +51 -0
- package/dist/test/tiles/list/tile-list-compact.test.js.map +1 -1
- package/dist/test/tiles/list/tile-list.test.js +51 -0
- package/dist/test/tiles/list/tile-list.test.js.map +1 -1
- package/dist/test/utils/format-date.test.js +31 -1
- package/dist/test/utils/format-date.test.js.map +1 -1
- package/package.json +1 -1
- package/src/collection-browser.ts +26 -1
- package/src/tiles/base-tile-component.ts +12 -0
- package/src/tiles/grid/account-tile.ts +1 -0
- package/src/tiles/grid/collection-tile.ts +1 -0
- package/src/tiles/grid/item-tile.ts +6 -5
- package/src/tiles/list/tile-list-compact.ts +5 -2
- package/src/tiles/list/tile-list.ts +7 -3
- package/src/tiles/tile-dispatcher.ts +4 -0
- package/src/utils/format-date.ts +23 -3
- package/test/tiles/grid/item-tile.test.ts +56 -0
- package/test/tiles/list/tile-list-compact.test.ts +54 -0
- package/test/tiles/list/tile-list.test.ts +55 -0
- package/test/utils/format-date.test.ts +51 -1
|
@@ -296,6 +296,62 @@ describe('Item Tile', () => {
|
|
|
296
296
|
expect(dateSortedBy?.textContent?.trim()).to.equal('reviewed Jan 01, 2013');
|
|
297
297
|
});
|
|
298
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
|
+
|
|
299
355
|
it('should show the first creator matching the letter filter, if defined', async () => {
|
|
300
356
|
const model: Partial<TileModel> = {
|
|
301
357
|
creator: 'foo',
|
|
@@ -210,6 +210,60 @@ describe('List Tile Compact', () => {
|
|
|
210
210
|
expect(dateColumn?.textContent?.trim()).to.equal('Jan 01, 2013');
|
|
211
211
|
});
|
|
212
212
|
|
|
213
|
+
it('should display dates in UTC time zone by default', async () => {
|
|
214
|
+
const model: Partial<TileModel> = {
|
|
215
|
+
datePublished: new Date('2012-02-15T00:00:00Z'),
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const el = await fixture<TileListCompact>(html`
|
|
219
|
+
<tile-list-compact
|
|
220
|
+
.model=${model}
|
|
221
|
+
.sortParam=${{ field: 'date', direction: 'desc' }}
|
|
222
|
+
>
|
|
223
|
+
</tile-list-compact>
|
|
224
|
+
`);
|
|
225
|
+
|
|
226
|
+
const dateColumn = el.shadowRoot?.getElementById('date');
|
|
227
|
+
expect(dateColumn).to.exist;
|
|
228
|
+
expect(dateColumn?.textContent?.trim()).to.equal('Feb 15, 2012');
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should display dates in local time when useLocalTime option is true', async () => {
|
|
232
|
+
// Expected behavior depends on the time zone offset where the testing occurs
|
|
233
|
+
const offset = new Date().getTimezoneOffset();
|
|
234
|
+
let datePublished, expected;
|
|
235
|
+
if (offset > 0) {
|
|
236
|
+
// Positive local time zone offsets have earlier local dates than UTC
|
|
237
|
+
datePublished = new Date('2012-02-15T00:00:00Z');
|
|
238
|
+
expected = 'Feb 14, 2012';
|
|
239
|
+
} else if (offset < 0) {
|
|
240
|
+
// Negative local time zone offsets have later local dates than UTC
|
|
241
|
+
datePublished = new Date('2012-02-15T23:59:59Z');
|
|
242
|
+
expected = 'Feb 16, 2012';
|
|
243
|
+
} else {
|
|
244
|
+
// Local time may just be UTC itself
|
|
245
|
+
datePublished = new Date('2012-02-15T00:00:00Z');
|
|
246
|
+
expected = 'Feb 15, 2012';
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const model: Partial<TileModel> = {
|
|
250
|
+
datePublished,
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const el = await fixture<TileListCompact>(html`
|
|
254
|
+
<tile-list-compact
|
|
255
|
+
useLocalTime
|
|
256
|
+
.model=${model}
|
|
257
|
+
.sortParam=${{ field: 'date', direction: 'desc' }}
|
|
258
|
+
>
|
|
259
|
+
</tile-list-compact>
|
|
260
|
+
`);
|
|
261
|
+
|
|
262
|
+
const dateColumn = el.shadowRoot?.getElementById('date');
|
|
263
|
+
expect(dateColumn).to.exist;
|
|
264
|
+
expect(dateColumn?.textContent?.trim()).to.equal(expected);
|
|
265
|
+
});
|
|
266
|
+
|
|
213
267
|
it('should show the first creator matching the letter filter, if defined', async () => {
|
|
214
268
|
const model: Partial<TileModel> = {
|
|
215
269
|
creator: 'foo',
|
|
@@ -281,6 +281,61 @@ describe('List Tile', () => {
|
|
|
281
281
|
expect(dateRow?.textContent?.trim()).to.contain('Reviewed: Jan 01, 2013');
|
|
282
282
|
});
|
|
283
283
|
|
|
284
|
+
it('should display dates in UTC time zone by default', async () => {
|
|
285
|
+
const model: Partial<TileModel> = {
|
|
286
|
+
datePublished: new Date('2012-02-15T00:00:00Z'),
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const el = await fixture<TileList>(html`
|
|
290
|
+
<tile-list
|
|
291
|
+
.model=${model}
|
|
292
|
+
.sortParam=${{ field: 'date', direction: 'desc' }}
|
|
293
|
+
>
|
|
294
|
+
</tile-list>
|
|
295
|
+
`);
|
|
296
|
+
|
|
297
|
+
const dateRow = el.shadowRoot?.getElementById('dates-line');
|
|
298
|
+
expect(dateRow).to.exist;
|
|
299
|
+
expect(dateRow?.textContent?.trim()).to.contain('Published: Feb 15, 2012');
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('should display dates in local time when useLocalTime option is true', async () => {
|
|
303
|
+
// Expected behavior depends on the time zone offset where the testing occurs
|
|
304
|
+
const offset = new Date().getTimezoneOffset();
|
|
305
|
+
let datePublished, expected;
|
|
306
|
+
if (offset > 0) {
|
|
307
|
+
// Positive local time zone offsets have earlier local dates than UTC
|
|
308
|
+
datePublished = new Date('2012-02-15T00:00:00Z');
|
|
309
|
+
expected = 'Published: Feb 14, 2012';
|
|
310
|
+
} else if (offset < 0) {
|
|
311
|
+
// Negative local time zone offsets have later local dates than UTC
|
|
312
|
+
datePublished = new Date('2012-02-15T23:59:59Z');
|
|
313
|
+
expected = 'Published: Feb 16, 2012';
|
|
314
|
+
} else {
|
|
315
|
+
// Local time may just be UTC itself
|
|
316
|
+
datePublished = new Date('2012-02-15T00:00:00Z');
|
|
317
|
+
expected = 'Published: Feb 15, 2012';
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const model: Partial<TileModel> = {
|
|
321
|
+
datePublished,
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const el = await fixture<TileList>(html`
|
|
325
|
+
<tile-list
|
|
326
|
+
useLocalTime
|
|
327
|
+
.model=${model}
|
|
328
|
+
.sortParam=${{ field: 'date', direction: 'desc' }}
|
|
329
|
+
>
|
|
330
|
+
</tile-list>
|
|
331
|
+
`);
|
|
332
|
+
|
|
333
|
+
const dateRow = el.shadowRoot?.getElementById('dates-line');
|
|
334
|
+
expect(dateRow).to.exist;
|
|
335
|
+
|
|
336
|
+
expect(dateRow?.textContent?.trim()).to.contain(expected);
|
|
337
|
+
});
|
|
338
|
+
|
|
284
339
|
it('should render links to /search pages (not search.php) for subject, creator, and source', async () => {
|
|
285
340
|
const model: Partial<TileModel> = {
|
|
286
341
|
subjects: ['foo'],
|
|
@@ -33,7 +33,57 @@ describe('formatDate', () => {
|
|
|
33
33
|
);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
+
it('uses UTC time zone by default or when useLocalTime is explicitly false', () => {
|
|
37
|
+
// Default options
|
|
38
|
+
expect(formatDate(new Date('2025-02-15T00:00:00Z'), 'long')).to.equal(
|
|
39
|
+
'Feb 15, 2025',
|
|
40
|
+
);
|
|
41
|
+
expect(formatDate(new Date('2025-02-15T23:59:59Z'), 'long')).to.equal(
|
|
42
|
+
'Feb 15, 2025',
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// Explicit `useLocalTime: false` option
|
|
46
|
+
const options = { useLocalTime: false };
|
|
47
|
+
expect(
|
|
48
|
+
formatDate(new Date('2025-02-15T00:00:00Z'), 'long', options),
|
|
49
|
+
).to.equal('Feb 15, 2025');
|
|
50
|
+
expect(
|
|
51
|
+
formatDate(new Date('2025-02-15T23:59:59Z'), 'long', options),
|
|
52
|
+
).to.equal('Feb 15, 2025');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('uses local time zone when specified', () => {
|
|
56
|
+
// N.B.:
|
|
57
|
+
// - Positive offset corresponds to UTC-x zones
|
|
58
|
+
// - Negative offset corresponds to UTC+x zones
|
|
59
|
+
const offset = new Date().getTimezoneOffset();
|
|
60
|
+
const options = { useLocalTime: true };
|
|
61
|
+
|
|
62
|
+
// The expected behavior depends on the local time where the tests are run:
|
|
63
|
+
if (offset > 0) {
|
|
64
|
+
// If we're testing under a positive offset, the first second of the UTC day should locally fall on the previous day
|
|
65
|
+
expect(
|
|
66
|
+
formatDate(new Date('2025-02-15T00:00:00Z'), 'long', options),
|
|
67
|
+
).to.equal('Feb 14, 2025');
|
|
68
|
+
} else if (offset < 0) {
|
|
69
|
+
// If we're testing under a negative offset, the last second of the UTC day should locally fall on the next day
|
|
70
|
+
expect(
|
|
71
|
+
formatDate(new Date('2025-02-15T23:59:59Z'), 'long', options),
|
|
72
|
+
).to.equal('Feb 16, 2025');
|
|
73
|
+
} else {
|
|
74
|
+
// If we're testing *in* UTC, then both seconds should locally fall on the same day
|
|
75
|
+
expect(
|
|
76
|
+
formatDate(new Date('2025-02-15T00:00:00Z'), 'long', options),
|
|
77
|
+
).to.equal('Feb 15, 2025');
|
|
78
|
+
expect(
|
|
79
|
+
formatDate(new Date('2025-02-15T23:59:59Z'), 'long', options),
|
|
80
|
+
).to.equal('Feb 15, 2025');
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
36
84
|
it('returns locale formatted date', () => {
|
|
37
|
-
expect(formatDate(testDate, 'long', 'de-DE')).to.equal(
|
|
85
|
+
expect(formatDate(testDate, 'long', { locale: 'de-DE' })).to.equal(
|
|
86
|
+
'09. Dez. 2020',
|
|
87
|
+
);
|
|
38
88
|
});
|
|
39
89
|
});
|