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