@internetarchive/collection-browser 3.1.1-alpha-webdev6778.6 → 3.1.1-alpha-webdev6778.8

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 (73) hide show
  1. package/dist/src/app-root.js +606 -606
  2. package/dist/src/app-root.js.map +1 -1
  3. package/dist/src/collection-browser.js.map +1 -1
  4. package/dist/src/collection-facets/facet-row.js +140 -140
  5. package/dist/src/collection-facets/facet-row.js.map +1 -1
  6. package/dist/src/collection-facets/models.js.map +1 -1
  7. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js +75 -75
  8. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js.map +1 -1
  9. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js +54 -54
  10. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js.map +1 -1
  11. package/dist/src/data-source/collection-browser-data-source-interface.js.map +1 -1
  12. package/dist/src/data-source/collection-browser-data-source.js +1 -3
  13. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  14. package/dist/src/data-source/models.js.map +1 -1
  15. package/dist/src/expanded-date-picker.js +52 -52
  16. package/dist/src/expanded-date-picker.js.map +1 -1
  17. package/dist/src/manage/manage-bar.js +77 -77
  18. package/dist/src/manage/manage-bar.js.map +1 -1
  19. package/dist/src/models.js.map +1 -1
  20. package/dist/src/sort-filter-bar/sort-filter-bar.js +376 -376
  21. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  22. package/dist/src/tiles/base-tile-component.js.map +1 -1
  23. package/dist/src/tiles/grid/account-tile.js +36 -36
  24. package/dist/src/tiles/grid/account-tile.js.map +1 -1
  25. package/dist/src/tiles/grid/search-tile.js +42 -42
  26. package/dist/src/tiles/grid/search-tile.js.map +1 -1
  27. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +119 -119
  28. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js.map +1 -1
  29. package/dist/src/tiles/list/tile-list-compact.js +97 -97
  30. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  31. package/dist/src/utils/analytics-events.js.map +1 -1
  32. package/dist/src/utils/format-date.js.map +1 -1
  33. package/dist/test/collection-browser.test.js +187 -187
  34. package/dist/test/collection-browser.test.js.map +1 -1
  35. package/dist/test/collection-facets/facet-row.test.js +23 -23
  36. package/dist/test/collection-facets/facet-row.test.js.map +1 -1
  37. package/dist/test/collection-facets.test.js +20 -20
  38. package/dist/test/collection-facets.test.js.map +1 -1
  39. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +37 -37
  40. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
  41. package/dist/test/tiles/grid/item-tile.test.js +64 -64
  42. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  43. package/dist/test/tiles/list/tile-list-compact.test.js +57 -57
  44. package/dist/test/tiles/list/tile-list-compact.test.js.map +1 -1
  45. package/dist/test/utils/format-date.test.js.map +1 -1
  46. package/package.json +2 -2
  47. package/src/app-root.ts +1140 -1140
  48. package/src/collection-browser.ts +1 -1
  49. package/src/collection-facets/facet-row.ts +296 -296
  50. package/src/collection-facets/models.ts +10 -10
  51. package/src/collection-facets/smart-facets/smart-facet-bar.ts +437 -437
  52. package/src/collection-facets/smart-facets/smart-facet-dropdown.ts +185 -185
  53. package/src/data-source/collection-browser-data-source-interface.ts +333 -333
  54. package/src/data-source/collection-browser-data-source.ts +2 -4
  55. package/src/data-source/models.ts +43 -43
  56. package/src/expanded-date-picker.ts +191 -191
  57. package/src/manage/manage-bar.ts +247 -247
  58. package/src/models.ts +870 -870
  59. package/src/sort-filter-bar/sort-filter-bar.ts +1283 -1283
  60. package/src/tiles/base-tile-component.ts +53 -53
  61. package/src/tiles/grid/account-tile.ts +112 -112
  62. package/src/tiles/grid/search-tile.ts +90 -90
  63. package/src/tiles/grid/styles/tile-grid-shared-styles.ts +130 -130
  64. package/src/tiles/list/tile-list-compact.ts +236 -236
  65. package/src/utils/analytics-events.ts +29 -29
  66. package/src/utils/format-date.ts +42 -42
  67. package/test/collection-browser.test.ts +2359 -2359
  68. package/test/collection-facets/facet-row.test.ts +375 -375
  69. package/test/collection-facets.test.ts +928 -928
  70. package/test/sort-filter-bar/sort-filter-bar.test.ts +885 -885
  71. package/test/tiles/grid/item-tile.test.ts +464 -464
  72. package/test/tiles/list/tile-list-compact.test.ts +228 -228
  73. package/test/utils/format-date.test.ts +39 -39
@@ -1,228 +1,228 @@
1
- import { expect, fixture } from '@open-wc/testing';
2
- import { html } from 'lit';
3
- import type { TileListCompact } from '../../../src/tiles/list/tile-list-compact';
4
-
5
- import '../../../src/tiles/list/tile-list-compact';
6
- import type { TileModel } from '../../../src/models';
7
-
8
- describe('List Tile Compact', () => {
9
- it('should render initial component', async () => {
10
- const el = await fixture<TileListCompact>(
11
- html`<tile-list-compact></tile-list-compact>`,
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
- const itemIcon = el.shadowRoot?.querySelector('#icon');
18
- const itemViews = el.shadowRoot?.querySelector('#views');
19
-
20
- expect(listContainer).to.exist;
21
- expect(itemTitle).to.exist;
22
- expect(imageBlock).to.exist;
23
- expect(itemIcon).to.exist;
24
- expect(itemViews).to.exist;
25
- });
26
-
27
- it('should render with creator element with title', async () => {
28
- const el = await fixture<TileListCompact>(html`
29
- <tile-list-compact
30
- .model=${{ creators: ['someone'] }}
31
- ></tile-list-compact>
32
- `);
33
-
34
- const creator = el.shadowRoot?.querySelector('#creator');
35
-
36
- expect(creator).to.exist;
37
- });
38
-
39
- it('should render title link with model href if provided', async () => {
40
- const el = await fixture<TileListCompact>(html`
41
- <tile-list-compact
42
- .baseNavigationUrl=${''}
43
- .model=${{ identifier: 'id', title: 'foo', href: '/foo/bar' }}
44
- ></tile-list-compact>
45
- `);
46
-
47
- const title = el.shadowRoot?.querySelector('#title');
48
-
49
- expect(title).to.exist;
50
- expect(title?.getAttribute('href')).to.equal('/foo/bar');
51
- });
52
-
53
- it('should render weekly views when sorting by week', async () => {
54
- const el = await fixture<TileListCompact>(html`
55
- <tile-list-compact
56
- .model=${{ viewCount: 50, weeklyViewCount: 10 }}
57
- .sortParam=${{ field: 'week', direction: 'desc' }}
58
- >
59
- </tile-list-compact>
60
- `);
61
-
62
- const viewsColumn = el.shadowRoot?.getElementById('views');
63
- expect(viewsColumn).to.exist;
64
- expect(viewsColumn?.textContent?.trim()).to.equal('10');
65
- });
66
-
67
- it('should render 0 for views if missing model', async () => {
68
- const el = await fixture<TileListCompact>(html`
69
- <tile-list-compact .sortParam=${{ field: 'week', direction: 'desc' }}>
70
- </tile-list-compact>
71
- `);
72
-
73
- const viewsColumn = el.shadowRoot?.getElementById('views');
74
- expect(viewsColumn).to.exist;
75
- expect(viewsColumn?.textContent?.trim()).to.equal('0');
76
- });
77
-
78
- it('should render published date when sorting by it', async () => {
79
- const model: Partial<TileModel> = {
80
- dateAdded: new Date(2010, 0, 2),
81
- dateArchived: new Date(2011, 0, 2),
82
- datePublished: new Date(2012, 0, 2),
83
- dateReviewed: new Date(2013, 0, 2),
84
- };
85
-
86
- const el = await fixture<TileListCompact>(html`
87
- <tile-list-compact
88
- .model=${model}
89
- .sortParam=${{ field: 'date', direction: 'desc' }}
90
- >
91
- </tile-list-compact>
92
- `);
93
-
94
- const dateColumn = el.shadowRoot?.getElementById('date');
95
- expect(dateColumn).to.exist;
96
- expect(dateColumn?.textContent?.trim()).to.equal('Jan 02, 2012');
97
- });
98
-
99
- it('should render added date when sorting by it', async () => {
100
- const model: Partial<TileModel> = {
101
- dateAdded: new Date(2010, 0, 2),
102
- dateArchived: new Date(2011, 0, 2),
103
- datePublished: new Date(2012, 0, 2),
104
- dateReviewed: new Date(2013, 0, 2),
105
- };
106
-
107
- const el = await fixture<TileListCompact>(html`
108
- <tile-list-compact
109
- .model=${model}
110
- .sortParam=${{ field: 'addeddate', direction: 'desc' }}
111
- >
112
- </tile-list-compact>
113
- `);
114
-
115
- const dateColumn = el.shadowRoot?.getElementById('date');
116
- expect(dateColumn).to.exist;
117
- expect(dateColumn?.textContent?.trim()).to.equal('Jan 02, 2010');
118
- });
119
-
120
- it('should render archived date when sorting by it', async () => {
121
- const model: Partial<TileModel> = {
122
- dateAdded: new Date(2010, 0, 2),
123
- dateArchived: new Date(2011, 0, 2),
124
- datePublished: new Date(2012, 0, 2),
125
- dateReviewed: new Date(2013, 0, 2),
126
- };
127
-
128
- const el = await fixture<TileListCompact>(html`
129
- <tile-list-compact
130
- .model=${model}
131
- .sortParam=${{ field: 'publicdate', direction: 'desc' }}
132
- >
133
- </tile-list-compact>
134
- `);
135
-
136
- const dateColumn = el.shadowRoot?.getElementById('date');
137
- expect(dateColumn).to.exist;
138
- expect(dateColumn?.textContent?.trim()).to.equal('Jan 02, 2011');
139
- });
140
-
141
- it('should render reviewed date when sorting by it', async () => {
142
- const model: Partial<TileModel> = {
143
- dateAdded: new Date(2010, 0, 2),
144
- dateArchived: new Date(2011, 0, 2),
145
- datePublished: new Date(2012, 0, 2),
146
- dateReviewed: new Date(2013, 0, 2),
147
- };
148
-
149
- const el = await fixture<TileListCompact>(html`
150
- <tile-list-compact
151
- .model=${model}
152
- .sortParam=${{ field: 'reviewdate', direction: 'desc' }}
153
- >
154
- </tile-list-compact>
155
- `);
156
-
157
- const dateColumn = el.shadowRoot?.getElementById('date');
158
- expect(dateColumn).to.exist;
159
- expect(dateColumn?.textContent?.trim()).to.equal('Jan 02, 2013');
160
- });
161
-
162
- it('should only show the year for a date published of Jan 1 at midnight UTC', async () => {
163
- const model: Partial<TileModel> = {
164
- datePublished: new Date('2012-01-01T00:00:00Z'),
165
- };
166
-
167
- const el = await fixture<TileListCompact>(html`
168
- <tile-list-compact
169
- .model=${model}
170
- .sortParam=${{ field: 'date', direction: 'desc' }}
171
- >
172
- </tile-list-compact>
173
- `);
174
-
175
- const dateColumn = el.shadowRoot?.getElementById('date');
176
- expect(dateColumn).to.exist;
177
- expect(dateColumn?.textContent?.trim()).to.equal('2012');
178
- });
179
-
180
- it('should show full date added/archived/reviewed, even on Jan 1 at midnight UTC', async () => {
181
- const model: Partial<TileModel> = {
182
- dateAdded: new Date(2010, 0, 1, 0, 0, 0, 0),
183
- dateArchived: new Date(2011, 0, 1, 0, 0, 0, 0),
184
- datePublished: new Date(2012, 0, 1, 0, 0, 0, 0),
185
- dateReviewed: new Date(2013, 0, 1, 0, 0, 0, 0),
186
- };
187
-
188
- const el = await fixture<TileListCompact>(html`
189
- <tile-list-compact
190
- .model=${model}
191
- .sortParam=${{ field: 'addeddate', direction: 'desc' }}
192
- >
193
- </tile-list-compact>
194
- `);
195
-
196
- let dateColumn = el.shadowRoot?.getElementById('date');
197
- expect(dateColumn).to.exist;
198
- expect(dateColumn?.textContent?.trim()).to.equal('Jan 01, 2010');
199
-
200
- el.sortParam = { field: 'publicdate', direction: 'desc' };
201
- await el.updateComplete;
202
- dateColumn = el.shadowRoot?.getElementById('date');
203
- expect(dateColumn).to.exist;
204
- expect(dateColumn?.textContent?.trim()).to.equal('Jan 01, 2011');
205
-
206
- el.sortParam = { field: 'reviewdate', direction: 'desc' };
207
- await el.updateComplete;
208
- dateColumn = el.shadowRoot?.getElementById('date');
209
- expect(dateColumn).to.exist;
210
- expect(dateColumn?.textContent?.trim()).to.equal('Jan 01, 2013');
211
- });
212
-
213
- it('should show the first creator matching the letter filter, if defined', async () => {
214
- const model: Partial<TileModel> = {
215
- creator: 'foo',
216
- creators: ['foo', 'bar', 'baz'],
217
- };
218
-
219
- const el = await fixture<TileListCompact>(html`
220
- <tile-list-compact .model=${model} .creatorFilter=${'B'}>
221
- </tile-list-compact>
222
- `);
223
-
224
- const creator = el.shadowRoot?.getElementById('creator');
225
- expect(creator).to.exist;
226
- expect(creator?.textContent?.trim()).to.equal('bar');
227
- });
228
- });
1
+ import { expect, fixture } from '@open-wc/testing';
2
+ import { html } from 'lit';
3
+ import type { TileListCompact } from '../../../src/tiles/list/tile-list-compact';
4
+
5
+ import '../../../src/tiles/list/tile-list-compact';
6
+ import type { TileModel } from '../../../src/models';
7
+
8
+ describe('List Tile Compact', () => {
9
+ it('should render initial component', async () => {
10
+ const el = await fixture<TileListCompact>(
11
+ html`<tile-list-compact></tile-list-compact>`,
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
+ const itemIcon = el.shadowRoot?.querySelector('#icon');
18
+ const itemViews = el.shadowRoot?.querySelector('#views');
19
+
20
+ expect(listContainer).to.exist;
21
+ expect(itemTitle).to.exist;
22
+ expect(imageBlock).to.exist;
23
+ expect(itemIcon).to.exist;
24
+ expect(itemViews).to.exist;
25
+ });
26
+
27
+ it('should render with creator element with title', async () => {
28
+ const el = await fixture<TileListCompact>(html`
29
+ <tile-list-compact
30
+ .model=${{ creators: ['someone'] }}
31
+ ></tile-list-compact>
32
+ `);
33
+
34
+ const creator = el.shadowRoot?.querySelector('#creator');
35
+
36
+ expect(creator).to.exist;
37
+ });
38
+
39
+ it('should render title link with model href if provided', async () => {
40
+ const el = await fixture<TileListCompact>(html`
41
+ <tile-list-compact
42
+ .baseNavigationUrl=${''}
43
+ .model=${{ identifier: 'id', title: 'foo', href: '/foo/bar' }}
44
+ ></tile-list-compact>
45
+ `);
46
+
47
+ const title = el.shadowRoot?.querySelector('#title');
48
+
49
+ expect(title).to.exist;
50
+ expect(title?.getAttribute('href')).to.equal('/foo/bar');
51
+ });
52
+
53
+ it('should render weekly views when sorting by week', async () => {
54
+ const el = await fixture<TileListCompact>(html`
55
+ <tile-list-compact
56
+ .model=${{ viewCount: 50, weeklyViewCount: 10 }}
57
+ .sortParam=${{ field: 'week', direction: 'desc' }}
58
+ >
59
+ </tile-list-compact>
60
+ `);
61
+
62
+ const viewsColumn = el.shadowRoot?.getElementById('views');
63
+ expect(viewsColumn).to.exist;
64
+ expect(viewsColumn?.textContent?.trim()).to.equal('10');
65
+ });
66
+
67
+ it('should render 0 for views if missing model', async () => {
68
+ const el = await fixture<TileListCompact>(html`
69
+ <tile-list-compact .sortParam=${{ field: 'week', direction: 'desc' }}>
70
+ </tile-list-compact>
71
+ `);
72
+
73
+ const viewsColumn = el.shadowRoot?.getElementById('views');
74
+ expect(viewsColumn).to.exist;
75
+ expect(viewsColumn?.textContent?.trim()).to.equal('0');
76
+ });
77
+
78
+ it('should render published date when sorting by it', async () => {
79
+ const model: Partial<TileModel> = {
80
+ dateAdded: new Date(2010, 0, 2),
81
+ dateArchived: new Date(2011, 0, 2),
82
+ datePublished: new Date(2012, 0, 2),
83
+ dateReviewed: new Date(2013, 0, 2),
84
+ };
85
+
86
+ const el = await fixture<TileListCompact>(html`
87
+ <tile-list-compact
88
+ .model=${model}
89
+ .sortParam=${{ field: 'date', direction: 'desc' }}
90
+ >
91
+ </tile-list-compact>
92
+ `);
93
+
94
+ const dateColumn = el.shadowRoot?.getElementById('date');
95
+ expect(dateColumn).to.exist;
96
+ expect(dateColumn?.textContent?.trim()).to.equal('Jan 02, 2012');
97
+ });
98
+
99
+ it('should render added date when sorting by it', async () => {
100
+ const model: Partial<TileModel> = {
101
+ dateAdded: new Date(2010, 0, 2),
102
+ dateArchived: new Date(2011, 0, 2),
103
+ datePublished: new Date(2012, 0, 2),
104
+ dateReviewed: new Date(2013, 0, 2),
105
+ };
106
+
107
+ const el = await fixture<TileListCompact>(html`
108
+ <tile-list-compact
109
+ .model=${model}
110
+ .sortParam=${{ field: 'addeddate', direction: 'desc' }}
111
+ >
112
+ </tile-list-compact>
113
+ `);
114
+
115
+ const dateColumn = el.shadowRoot?.getElementById('date');
116
+ expect(dateColumn).to.exist;
117
+ expect(dateColumn?.textContent?.trim()).to.equal('Jan 02, 2010');
118
+ });
119
+
120
+ it('should render archived date when sorting by it', async () => {
121
+ const model: Partial<TileModel> = {
122
+ dateAdded: new Date(2010, 0, 2),
123
+ dateArchived: new Date(2011, 0, 2),
124
+ datePublished: new Date(2012, 0, 2),
125
+ dateReviewed: new Date(2013, 0, 2),
126
+ };
127
+
128
+ const el = await fixture<TileListCompact>(html`
129
+ <tile-list-compact
130
+ .model=${model}
131
+ .sortParam=${{ field: 'publicdate', direction: 'desc' }}
132
+ >
133
+ </tile-list-compact>
134
+ `);
135
+
136
+ const dateColumn = el.shadowRoot?.getElementById('date');
137
+ expect(dateColumn).to.exist;
138
+ expect(dateColumn?.textContent?.trim()).to.equal('Jan 02, 2011');
139
+ });
140
+
141
+ it('should render reviewed date when sorting by it', async () => {
142
+ const model: Partial<TileModel> = {
143
+ dateAdded: new Date(2010, 0, 2),
144
+ dateArchived: new Date(2011, 0, 2),
145
+ datePublished: new Date(2012, 0, 2),
146
+ dateReviewed: new Date(2013, 0, 2),
147
+ };
148
+
149
+ const el = await fixture<TileListCompact>(html`
150
+ <tile-list-compact
151
+ .model=${model}
152
+ .sortParam=${{ field: 'reviewdate', direction: 'desc' }}
153
+ >
154
+ </tile-list-compact>
155
+ `);
156
+
157
+ const dateColumn = el.shadowRoot?.getElementById('date');
158
+ expect(dateColumn).to.exist;
159
+ expect(dateColumn?.textContent?.trim()).to.equal('Jan 02, 2013');
160
+ });
161
+
162
+ it('should only show the year for a date published of Jan 1 at midnight UTC', async () => {
163
+ const model: Partial<TileModel> = {
164
+ datePublished: new Date('2012-01-01T00:00:00Z'),
165
+ };
166
+
167
+ const el = await fixture<TileListCompact>(html`
168
+ <tile-list-compact
169
+ .model=${model}
170
+ .sortParam=${{ field: 'date', direction: 'desc' }}
171
+ >
172
+ </tile-list-compact>
173
+ `);
174
+
175
+ const dateColumn = el.shadowRoot?.getElementById('date');
176
+ expect(dateColumn).to.exist;
177
+ expect(dateColumn?.textContent?.trim()).to.equal('2012');
178
+ });
179
+
180
+ it('should show full date added/archived/reviewed, even on Jan 1 at midnight UTC', async () => {
181
+ const model: Partial<TileModel> = {
182
+ dateAdded: new Date(2010, 0, 1, 0, 0, 0, 0),
183
+ dateArchived: new Date(2011, 0, 1, 0, 0, 0, 0),
184
+ datePublished: new Date(2012, 0, 1, 0, 0, 0, 0),
185
+ dateReviewed: new Date(2013, 0, 1, 0, 0, 0, 0),
186
+ };
187
+
188
+ const el = await fixture<TileListCompact>(html`
189
+ <tile-list-compact
190
+ .model=${model}
191
+ .sortParam=${{ field: 'addeddate', direction: 'desc' }}
192
+ >
193
+ </tile-list-compact>
194
+ `);
195
+
196
+ let dateColumn = el.shadowRoot?.getElementById('date');
197
+ expect(dateColumn).to.exist;
198
+ expect(dateColumn?.textContent?.trim()).to.equal('Jan 01, 2010');
199
+
200
+ el.sortParam = { field: 'publicdate', direction: 'desc' };
201
+ await el.updateComplete;
202
+ dateColumn = el.shadowRoot?.getElementById('date');
203
+ expect(dateColumn).to.exist;
204
+ expect(dateColumn?.textContent?.trim()).to.equal('Jan 01, 2011');
205
+
206
+ el.sortParam = { field: 'reviewdate', direction: 'desc' };
207
+ await el.updateComplete;
208
+ dateColumn = el.shadowRoot?.getElementById('date');
209
+ expect(dateColumn).to.exist;
210
+ expect(dateColumn?.textContent?.trim()).to.equal('Jan 01, 2013');
211
+ });
212
+
213
+ it('should show the first creator matching the letter filter, if defined', async () => {
214
+ const model: Partial<TileModel> = {
215
+ creator: 'foo',
216
+ creators: ['foo', 'bar', 'baz'],
217
+ };
218
+
219
+ const el = await fixture<TileListCompact>(html`
220
+ <tile-list-compact .model=${model} .creatorFilter=${'B'}>
221
+ </tile-list-compact>
222
+ `);
223
+
224
+ const creator = el.shadowRoot?.getElementById('creator');
225
+ expect(creator).to.exist;
226
+ expect(creator?.textContent?.trim()).to.equal('bar');
227
+ });
228
+ });
@@ -1,39 +1,39 @@
1
- import { expect } from '@open-wc/testing';
2
- import { formatDate } from '../../src/utils/format-date';
3
-
4
- const testDate = new Date(2020, 11, 9);
5
-
6
- describe('formatDate', () => {
7
- it('returns blank when undefined date', () => {
8
- expect(formatDate(undefined)).to.equal('');
9
- });
10
-
11
- it('returns short date when no DateFormat', () => {
12
- expect(formatDate(testDate)).to.equal('Dec 2020');
13
- });
14
-
15
- it('returns long date when long DateFormat', () => {
16
- expect(formatDate(testDate, 'long')).to.equal('Dec 09, 2020');
17
- });
18
-
19
- it('returns year-only date when year-only DateFormat', () => {
20
- expect(formatDate(testDate, 'year-only')).to.equal('2020');
21
- });
22
-
23
- it('returns correct year for old "Jan 1 at midnight" dates and year-only DateFormat', () => {
24
- // Many standard timezones have a discontinuity in date parsing at some point during
25
- // the 19th or 20th century, corresponding to the creation of the timezone.
26
- // Dates prior to the discontinuity generally have a non-hour-aligned timezone offset
27
- // which can throw off the calculated year for dates which are close to a year boundary.
28
- // This is particularly problematic for "Jan 1 at midnight" dates, which are what we
29
- // receive from the search engine for date metadata that only specifies the year.
30
- // So we must ensure these older dates still output the correct year, not the prior one.
31
- expect(formatDate(new Date('1234-01-01T00:00:00Z'), 'year-only')).to.equal(
32
- '1234',
33
- );
34
- });
35
-
36
- it('returns locale formatted date', () => {
37
- expect(formatDate(testDate, 'long', 'de-DE')).to.equal('09. Dez. 2020');
38
- });
39
- });
1
+ import { expect } from '@open-wc/testing';
2
+ import { formatDate } from '../../src/utils/format-date';
3
+
4
+ const testDate = new Date(2020, 11, 9);
5
+
6
+ describe('formatDate', () => {
7
+ it('returns blank when undefined date', () => {
8
+ expect(formatDate(undefined)).to.equal('');
9
+ });
10
+
11
+ it('returns short date when no DateFormat', () => {
12
+ expect(formatDate(testDate)).to.equal('Dec 2020');
13
+ });
14
+
15
+ it('returns long date when long DateFormat', () => {
16
+ expect(formatDate(testDate, 'long')).to.equal('Dec 09, 2020');
17
+ });
18
+
19
+ it('returns year-only date when year-only DateFormat', () => {
20
+ expect(formatDate(testDate, 'year-only')).to.equal('2020');
21
+ });
22
+
23
+ it('returns correct year for old "Jan 1 at midnight" dates and year-only DateFormat', () => {
24
+ // Many standard timezones have a discontinuity in date parsing at some point during
25
+ // the 19th or 20th century, corresponding to the creation of the timezone.
26
+ // Dates prior to the discontinuity generally have a non-hour-aligned timezone offset
27
+ // which can throw off the calculated year for dates which are close to a year boundary.
28
+ // This is particularly problematic for "Jan 1 at midnight" dates, which are what we
29
+ // receive from the search engine for date metadata that only specifies the year.
30
+ // So we must ensure these older dates still output the correct year, not the prior one.
31
+ expect(formatDate(new Date('1234-01-01T00:00:00Z'), 'year-only')).to.equal(
32
+ '1234',
33
+ );
34
+ });
35
+
36
+ it('returns locale formatted date', () => {
37
+ expect(formatDate(testDate, 'long', 'de-DE')).to.equal('09. Dez. 2020');
38
+ });
39
+ });