@internetarchive/collection-browser 4.3.1-alpha-webdev8165.0 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/index.js.map +1 -1
  2. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  3. package/dist/src/manage/manage-bar.js +77 -77
  4. package/dist/src/manage/manage-bar.js.map +1 -1
  5. package/dist/src/models.d.ts +6 -0
  6. package/dist/src/models.js +16 -7
  7. package/dist/src/models.js.map +1 -1
  8. package/dist/src/restoration-state-handler.js +3 -1
  9. package/dist/src/restoration-state-handler.js.map +1 -1
  10. package/dist/src/tiles/base-tile-component.js.map +1 -1
  11. package/dist/src/tiles/grid/item-tile.js +138 -138
  12. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  13. package/dist/src/tiles/models.js.map +1 -1
  14. package/dist/src/tiles/tile-dispatcher.js +216 -216
  15. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  16. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  17. package/dist/test/data-source/collection-browser-data-source.test.js +2 -2
  18. package/dist/test/data-source/collection-browser-data-source.test.js.map +1 -1
  19. package/dist/test/manage/manage-bar.test.js +33 -33
  20. package/dist/test/manage/manage-bar.test.js.map +1 -1
  21. package/dist/test/restoration-state-handler.test.js +0 -70
  22. package/dist/test/restoration-state-handler.test.js.map +1 -1
  23. package/dist/test/tiles/list/tile-list-compact-header.test.js +12 -12
  24. package/dist/test/tiles/list/tile-list-compact-header.test.js.map +1 -1
  25. package/dist/test/tiles/list/tile-list.test.js +134 -134
  26. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  27. package/index.ts +28 -28
  28. package/package.json +2 -2
  29. package/src/data-source/collection-browser-data-source.ts +1465 -1465
  30. package/src/manage/manage-bar.ts +276 -276
  31. package/src/models.ts +895 -879
  32. package/src/restoration-state-handler.ts +550 -546
  33. package/src/tiles/base-tile-component.ts +65 -65
  34. package/src/tiles/grid/item-tile.ts +346 -346
  35. package/src/tiles/models.ts +8 -8
  36. package/src/tiles/tile-dispatcher.ts +527 -527
  37. package/src/tiles/tile-display-value-provider.ts +134 -134
  38. package/test/data-source/collection-browser-data-source.test.ts +193 -193
  39. package/test/manage/manage-bar.test.ts +347 -347
  40. package/test/restoration-state-handler.test.ts +480 -569
  41. package/test/tiles/list/tile-list-compact-header.test.ts +43 -43
  42. package/test/tiles/list/tile-list.test.ts +576 -576
@@ -1,347 +1,347 @@
1
- import { expect, fixture } from '@open-wc/testing';
2
- import { html } from 'lit';
3
- import Sinon from 'sinon';
4
- import '../../src/manage/manage-bar';
5
- import '../../src/manage/remove-items-modal-content';
6
- import {
7
- ModalManager,
8
- ModalManagerInterface,
9
- } from '@internetarchive/modal-manager';
10
- import '@internetarchive/modal-manager';
11
- import { msg } from '@lit/localize';
12
- import type { ManageBar } from '../../src/manage/manage-bar';
13
- import type { PageElementName } from '@internetarchive/search-service';
14
- import type { RemoveItemsModalContent } from '../../src/manage/remove-items-modal-content';
15
-
16
- describe('Manage bar', () => {
17
- it('renders basic component', async () => {
18
- const el = await fixture<ManageBar>(html`<manage-bar></manage-bar>`);
19
-
20
- expect(el.shadowRoot?.querySelector('.manage-label')).to.exist;
21
- expect(el.shadowRoot?.querySelector('.manage-buttons')).to.exist;
22
- expect(el.shadowRoot?.querySelector('.ia-button.dark')).to.exist;
23
- expect(el.shadowRoot?.querySelector('.ia-button.danger')).to.exist;
24
- });
25
-
26
- it('can set the label', async () => {
27
- const el = await fixture<ManageBar>(
28
- html`<manage-bar label="foo bar"></manage-bar>`,
29
- );
30
- expect(el.shadowRoot?.querySelector('.manage-label')?.textContent).to.equal(
31
- 'foo bar',
32
- );
33
- });
34
-
35
- it('does not include Select All/Unselect All buttons by default', async () => {
36
- const el = await fixture<ManageBar>(html`<manage-bar></manage-bar>`);
37
- expect(el.shadowRoot?.querySelector('.select-all-btn')).not.to.exist;
38
- expect(el.shadowRoot?.querySelector('.unselect-all-btn')).not.to.exist;
39
- });
40
-
41
- it('does not render item manager button except /search/ page', async () => {
42
- const el = await fixture<ManageBar>(html`<manage-bar></manage-bar>`);
43
- expect(el.shadowRoot?.querySelector('.ia-button.warning')).not.to.exist;
44
- });
45
-
46
- it('render item manager button for /search/ page', async () => {
47
- const el = await fixture<ManageBar>(
48
- html`<manage-bar showItemManageButton></manage-bar>`,
49
- );
50
- expect(el.shadowRoot?.querySelector('.ia-button.warning')).to.exist;
51
- });
52
-
53
- it('includes Select All button when requested', async () => {
54
- const el = await fixture<ManageBar>(
55
- html`<manage-bar showSelectAll></manage-bar>`,
56
- );
57
- expect(el.shadowRoot?.querySelector('.select-all-btn')).to.exist;
58
- });
59
-
60
- it('includes Unselect All button when requested', async () => {
61
- const el = await fixture<ManageBar>(
62
- html`<manage-bar showUnselectAll></manage-bar>`,
63
- );
64
- expect(el.shadowRoot?.querySelector('.unselect-all-btn')).to.exist;
65
- });
66
-
67
- it('default and toggle state of remove button', async () => {
68
- const el = await fixture<ManageBar>(html`<manage-bar></manage-bar>`);
69
-
70
- expect(el.shadowRoot?.querySelector('.ia-button.danger:disabled')).to.exist;
71
-
72
- el.removeAllowed = true;
73
- await el.updateComplete;
74
-
75
- expect(el.shadowRoot?.querySelector('.ia-button.danger:disabled')).to.not
76
- .exist;
77
- });
78
-
79
- it('emits event when Cancel button clicked', async () => {
80
- const spy = Sinon.spy();
81
- const el = await fixture<ManageBar>(
82
- html`<manage-bar @cancel=${spy}></manage-bar>`,
83
- );
84
-
85
- const cancelBtn = el.shadowRoot?.querySelector(
86
- '.ia-button.dark',
87
- ) as HTMLButtonElement;
88
- expect(cancelBtn).to.exist;
89
-
90
- cancelBtn.click();
91
- expect(spy.callCount).to.equal(1);
92
- });
93
-
94
- it('emits event when Select All button clicked', async () => {
95
- const spy = Sinon.spy();
96
- const el = await fixture<ManageBar>(
97
- html`<manage-bar showSelectAll @selectAll=${spy}></manage-bar>`,
98
- );
99
-
100
- const selectAllBtn = el.shadowRoot?.querySelector(
101
- '.select-all-btn',
102
- ) as HTMLButtonElement;
103
- expect(selectAllBtn).to.exist;
104
-
105
- selectAllBtn.click();
106
- expect(spy.callCount).to.equal(1);
107
- });
108
-
109
- it('emits event when Unselect All button clicked', async () => {
110
- const spy = Sinon.spy();
111
- const el = await fixture<ManageBar>(
112
- html`<manage-bar showUnselectAll @unselectAll=${spy}></manage-bar>`,
113
- );
114
-
115
- const unselectAllBtn = el.shadowRoot?.querySelector(
116
- '.unselect-all-btn',
117
- ) as HTMLButtonElement;
118
- expect(unselectAllBtn).to.exist;
119
-
120
- unselectAllBtn.click();
121
- expect(spy.callCount).to.equal(1);
122
- });
123
-
124
- it('opens the remove items modal when showRemoveItemsModal is clicked', async () => {
125
- const modalManager = await fixture<ModalManager>(
126
- html`<modal-manager></modal-manager>`,
127
- );
128
-
129
- const el = await fixture<ManageBar>(html`
130
- <manage-bar
131
- .modalManager=${modalManager}
132
- .selectedItems=${[{ identifier: '1', title: 'Item 1' }]}
133
- removeAllowed
134
- ></manage-bar>
135
- `);
136
- await el.updateComplete;
137
-
138
- const removeButton = el.shadowRoot?.querySelector(
139
- '.ia-button.danger',
140
- ) as HTMLButtonElement;
141
- expect(removeButton).to.exist;
142
-
143
- const showModalSpy = Sinon.spy(
144
- el.modalManager as ModalManagerInterface,
145
- 'showModal',
146
- );
147
-
148
- await el.updateComplete;
149
- removeButton?.click();
150
-
151
- expect(showModalSpy.callCount).to.equal(1);
152
- expect(el.modalManager?.classList.contains('remove-items')).to.be;
153
- expect(showModalSpy.args[0][0].config.title?.values[0]).to.equal(
154
- msg('Are you sure you want to remove these items?'),
155
- );
156
- expect(showModalSpy.args[0][0].customModalContent).to.exist;
157
- });
158
-
159
- it('shows selected items count in remove button', async () => {
160
- const el = await fixture<ManageBar>(html`
161
- <manage-bar
162
- .selectedItems=${[
163
- { identifier: '1', title: 'Item 1' },
164
- { identifier: '2', title: 'Item 2' },
165
- { identifier: '3', title: 'Item 3' },
166
- ]}
167
- ></manage-bar>
168
- `);
169
- const removeBtn = el.shadowRoot?.querySelector('.ia-button.danger');
170
- expect(removeBtn?.textContent?.trim()).to.include('(3)');
171
- });
172
-
173
- it('Item Manager button is disabled when removeAllowed is false', async () => {
174
- const el = await fixture<ManageBar>(
175
- html`<manage-bar showItemManageButton></manage-bar>`,
176
- );
177
- expect(el.shadowRoot?.querySelector('.ia-button.warning:disabled')).to
178
- .exist;
179
-
180
- el.removeAllowed = true;
181
- await el.updateComplete;
182
-
183
- expect(el.shadowRoot?.querySelector('.ia-button.warning:disabled')).not.to
184
- .exist;
185
- });
186
-
187
- it('emits manageItems event when Item Manager button clicked', async () => {
188
- const spy = Sinon.spy();
189
- const el = await fixture<ManageBar>(html`
190
- <manage-bar
191
- showItemManageButton
192
- removeAllowed
193
- @manageItems=${spy}
194
- ></manage-bar>
195
- `);
196
- const manageBtn = el.shadowRoot?.querySelector(
197
- '.ia-button.warning',
198
- ) as HTMLButtonElement;
199
- expect(manageBtn).to.exist;
200
- manageBtn.click();
201
- expect(spy.callCount).to.equal(1);
202
- });
203
-
204
- it('emits removeItems event when modal confirm is clicked', async () => {
205
- const modalManager = await fixture<ModalManager>(
206
- html`<modal-manager></modal-manager>`,
207
- );
208
- const removeItemsSpy = Sinon.spy();
209
- const el = await fixture<ManageBar>(html`
210
- <manage-bar
211
- .modalManager=${modalManager}
212
- .selectedItems=${[{ identifier: '1', title: 'Item 1' }]}
213
- removeAllowed
214
- @removeItems=${removeItemsSpy}
215
- ></manage-bar>
216
- `);
217
- await el.updateComplete;
218
-
219
- const showModalSpy = Sinon.spy(
220
- el.modalManager as ModalManagerInterface,
221
- 'showModal',
222
- );
223
- (
224
- el.shadowRoot?.querySelector('.ia-button.danger') as HTMLButtonElement
225
- ).click();
226
-
227
- const contentEl = (await fixture(
228
- showModalSpy.args[0][0].customModalContent!,
229
- )) as RemoveItemsModalContent;
230
- (
231
- contentEl.shadowRoot?.querySelector(
232
- '.remove-items-btn',
233
- ) as HTMLButtonElement
234
- ).click();
235
-
236
- expect(removeItemsSpy.callCount).to.equal(1);
237
- });
238
-
239
- describe('profileElement modal messages', () => {
240
- async function openModalContent(
241
- profileElement: string,
242
- itemCount = 1,
243
- ): Promise<RemoveItemsModalContent> {
244
- const modalManager = await fixture<ModalManager>(
245
- html`<modal-manager></modal-manager>`,
246
- );
247
- const items = Array.from({ length: itemCount }, (_, i) => ({
248
- identifier: String(i + 1),
249
- title: `Item ${i + 1}`,
250
- }));
251
- const el = await fixture<ManageBar>(html`
252
- <manage-bar
253
- .selectedItems=${items}
254
- .profileElement=${profileElement as PageElementName}
255
- removeAllowed
256
- ></manage-bar>
257
- `);
258
- el.modalManager = modalManager as ModalManagerInterface;
259
- await el.updateComplete;
260
-
261
- const showModalSpy = Sinon.spy(
262
- el.modalManager as ModalManagerInterface,
263
- 'showModal',
264
- );
265
- (
266
- el.shadowRoot?.querySelector('.ia-button.danger') as HTMLButtonElement
267
- ).click();
268
-
269
- return (await fixture(
270
- showModalSpy.args[0][0].customModalContent!,
271
- )) as RemoveItemsModalContent;
272
- }
273
-
274
- it('shows uploads-specific message for profileElement=uploads', async () => {
275
- const contentEl = await openModalContent('uploads');
276
- expect(contentEl.message).to.include('uploads list');
277
- });
278
-
279
- it('shows web archives message for profileElement=web_archives', async () => {
280
- const contentEl = await openModalContent('web_archives');
281
- expect(contentEl.message).to.include('web archives list');
282
- });
283
-
284
- it('shows favorites message for profileElement=favorites', async () => {
285
- const contentEl = await openModalContent('favorites');
286
- expect(contentEl.message).to.include('favorites list');
287
- });
288
-
289
- it('shows no message for unmapped profileElement (e.g. reviews)', async () => {
290
- const contentEl = await openModalContent('reviews');
291
- expect(contentEl.message).to.equal('');
292
- expect(contentEl.shadowRoot?.querySelector('.message')).not.to.exist;
293
- });
294
-
295
- it('uses "this item" for a single selected item', async () => {
296
- const contentEl = await openModalContent('uploads', 1);
297
- expect(contentEl.message).to.include('this item');
298
- });
299
-
300
- it('uses "these items" for multiple selected items', async () => {
301
- const contentEl = await openModalContent('uploads', 2);
302
- expect(contentEl.message).to.include('these items');
303
- });
304
- });
305
-
306
- it('showRemoveItemsProcessingModal shows processing modal', async () => {
307
- const modalManager = await fixture<ModalManager>(
308
- html`<modal-manager></modal-manager>`,
309
- );
310
- const el = await fixture<ManageBar>(html`
311
- <manage-bar .modalManager=${modalManager}></manage-bar>
312
- `);
313
- const showModalSpy = Sinon.spy(
314
- el.modalManager as ModalManagerInterface,
315
- 'showModal',
316
- );
317
-
318
- el.showRemoveItemsProcessingModal();
319
-
320
- expect(showModalSpy.callCount).to.equal(1);
321
- expect(showModalSpy.args[0][0].config.showProcessingIndicator).to.be.true;
322
- expect(showModalSpy.args[0][0].config.title?.values[0]).to.equal(
323
- msg('Removing selected items...'),
324
- );
325
- });
326
-
327
- it('showRemoveItemsErrorModal shows error modal', async () => {
328
- const modalManager = await fixture<ModalManager>(
329
- html`<modal-manager></modal-manager>`,
330
- );
331
- const el = await fixture<ManageBar>(html`
332
- <manage-bar .modalManager=${modalManager}></manage-bar>
333
- `);
334
- const showModalSpy = Sinon.spy(
335
- el.modalManager as ModalManagerInterface,
336
- 'showModal',
337
- );
338
-
339
- el.showRemoveItemsErrorModal();
340
-
341
- expect(showModalSpy.callCount).to.equal(1);
342
- expect(showModalSpy.args[0][0].config.showProcessingIndicator).to.be.false;
343
- expect(showModalSpy.args[0][0].config.title?.values[0]).to.equal(
344
- msg('Error: unable to remove items'),
345
- );
346
- });
347
- });
1
+ import { expect, fixture } from '@open-wc/testing';
2
+ import { html } from 'lit';
3
+ import Sinon from 'sinon';
4
+ import '../../src/manage/manage-bar';
5
+ import '../../src/manage/remove-items-modal-content';
6
+ import {
7
+ ModalManager,
8
+ ModalManagerInterface,
9
+ } from '@internetarchive/modal-manager';
10
+ import '@internetarchive/modal-manager';
11
+ import { msg } from '@lit/localize';
12
+ import type { ManageBar } from '../../src/manage/manage-bar';
13
+ import type { PageElementName } from '@internetarchive/search-service';
14
+ import type { RemoveItemsModalContent } from '../../src/manage/remove-items-modal-content';
15
+
16
+ describe('Manage bar', () => {
17
+ it('renders basic component', async () => {
18
+ const el = await fixture<ManageBar>(html`<manage-bar></manage-bar>`);
19
+
20
+ expect(el.shadowRoot?.querySelector('.manage-label')).to.exist;
21
+ expect(el.shadowRoot?.querySelector('.manage-buttons')).to.exist;
22
+ expect(el.shadowRoot?.querySelector('.ia-button.dark')).to.exist;
23
+ expect(el.shadowRoot?.querySelector('.ia-button.danger')).to.exist;
24
+ });
25
+
26
+ it('can set the label', async () => {
27
+ const el = await fixture<ManageBar>(
28
+ html`<manage-bar label="foo bar"></manage-bar>`,
29
+ );
30
+ expect(el.shadowRoot?.querySelector('.manage-label')?.textContent).to.equal(
31
+ 'foo bar',
32
+ );
33
+ });
34
+
35
+ it('does not include Select All/Unselect All buttons by default', async () => {
36
+ const el = await fixture<ManageBar>(html`<manage-bar></manage-bar>`);
37
+ expect(el.shadowRoot?.querySelector('.select-all-btn')).not.to.exist;
38
+ expect(el.shadowRoot?.querySelector('.unselect-all-btn')).not.to.exist;
39
+ });
40
+
41
+ it('does not render item manager button except /search/ page', async () => {
42
+ const el = await fixture<ManageBar>(html`<manage-bar></manage-bar>`);
43
+ expect(el.shadowRoot?.querySelector('.ia-button.warning')).not.to.exist;
44
+ });
45
+
46
+ it('render item manager button for /search/ page', async () => {
47
+ const el = await fixture<ManageBar>(
48
+ html`<manage-bar showItemManageButton></manage-bar>`,
49
+ );
50
+ expect(el.shadowRoot?.querySelector('.ia-button.warning')).to.exist;
51
+ });
52
+
53
+ it('includes Select All button when requested', async () => {
54
+ const el = await fixture<ManageBar>(
55
+ html`<manage-bar showSelectAll></manage-bar>`,
56
+ );
57
+ expect(el.shadowRoot?.querySelector('.select-all-btn')).to.exist;
58
+ });
59
+
60
+ it('includes Unselect All button when requested', async () => {
61
+ const el = await fixture<ManageBar>(
62
+ html`<manage-bar showUnselectAll></manage-bar>`,
63
+ );
64
+ expect(el.shadowRoot?.querySelector('.unselect-all-btn')).to.exist;
65
+ });
66
+
67
+ it('default and toggle state of remove button', async () => {
68
+ const el = await fixture<ManageBar>(html`<manage-bar></manage-bar>`);
69
+
70
+ expect(el.shadowRoot?.querySelector('.ia-button.danger:disabled')).to.exist;
71
+
72
+ el.removeAllowed = true;
73
+ await el.updateComplete;
74
+
75
+ expect(el.shadowRoot?.querySelector('.ia-button.danger:disabled')).to.not
76
+ .exist;
77
+ });
78
+
79
+ it('emits event when Cancel button clicked', async () => {
80
+ const spy = Sinon.spy();
81
+ const el = await fixture<ManageBar>(
82
+ html`<manage-bar @cancel=${spy}></manage-bar>`,
83
+ );
84
+
85
+ const cancelBtn = el.shadowRoot?.querySelector(
86
+ '.ia-button.dark',
87
+ ) as HTMLButtonElement;
88
+ expect(cancelBtn).to.exist;
89
+
90
+ cancelBtn.click();
91
+ expect(spy.callCount).to.equal(1);
92
+ });
93
+
94
+ it('emits event when Select All button clicked', async () => {
95
+ const spy = Sinon.spy();
96
+ const el = await fixture<ManageBar>(
97
+ html`<manage-bar showSelectAll @selectAll=${spy}></manage-bar>`,
98
+ );
99
+
100
+ const selectAllBtn = el.shadowRoot?.querySelector(
101
+ '.select-all-btn',
102
+ ) as HTMLButtonElement;
103
+ expect(selectAllBtn).to.exist;
104
+
105
+ selectAllBtn.click();
106
+ expect(spy.callCount).to.equal(1);
107
+ });
108
+
109
+ it('emits event when Unselect All button clicked', async () => {
110
+ const spy = Sinon.spy();
111
+ const el = await fixture<ManageBar>(
112
+ html`<manage-bar showUnselectAll @unselectAll=${spy}></manage-bar>`,
113
+ );
114
+
115
+ const unselectAllBtn = el.shadowRoot?.querySelector(
116
+ '.unselect-all-btn',
117
+ ) as HTMLButtonElement;
118
+ expect(unselectAllBtn).to.exist;
119
+
120
+ unselectAllBtn.click();
121
+ expect(spy.callCount).to.equal(1);
122
+ });
123
+
124
+ it('opens the remove items modal when showRemoveItemsModal is clicked', async () => {
125
+ const modalManager = await fixture<ModalManager>(
126
+ html`<modal-manager></modal-manager>`,
127
+ );
128
+
129
+ const el = await fixture<ManageBar>(html`
130
+ <manage-bar
131
+ .modalManager=${modalManager}
132
+ .selectedItems=${[{ identifier: '1', title: 'Item 1' }]}
133
+ removeAllowed
134
+ ></manage-bar>
135
+ `);
136
+ await el.updateComplete;
137
+
138
+ const removeButton = el.shadowRoot?.querySelector(
139
+ '.ia-button.danger',
140
+ ) as HTMLButtonElement;
141
+ expect(removeButton).to.exist;
142
+
143
+ const showModalSpy = Sinon.spy(
144
+ el.modalManager as ModalManagerInterface,
145
+ 'showModal',
146
+ );
147
+
148
+ await el.updateComplete;
149
+ removeButton?.click();
150
+
151
+ expect(showModalSpy.callCount).to.equal(1);
152
+ expect(el.modalManager?.classList.contains('remove-items')).to.be;
153
+ expect(showModalSpy.args[0][0].config.title?.values[0]).to.equal(
154
+ msg('Are you sure you want to remove these items?'),
155
+ );
156
+ expect(showModalSpy.args[0][0].customModalContent).to.exist;
157
+ });
158
+
159
+ it('shows selected items count in remove button', async () => {
160
+ const el = await fixture<ManageBar>(html`
161
+ <manage-bar
162
+ .selectedItems=${[
163
+ { identifier: '1', title: 'Item 1' },
164
+ { identifier: '2', title: 'Item 2' },
165
+ { identifier: '3', title: 'Item 3' },
166
+ ]}
167
+ ></manage-bar>
168
+ `);
169
+ const removeBtn = el.shadowRoot?.querySelector('.ia-button.danger');
170
+ expect(removeBtn?.textContent?.trim()).to.include('(3)');
171
+ });
172
+
173
+ it('Item Manager button is disabled when removeAllowed is false', async () => {
174
+ const el = await fixture<ManageBar>(
175
+ html`<manage-bar showItemManageButton></manage-bar>`,
176
+ );
177
+ expect(el.shadowRoot?.querySelector('.ia-button.warning:disabled')).to
178
+ .exist;
179
+
180
+ el.removeAllowed = true;
181
+ await el.updateComplete;
182
+
183
+ expect(el.shadowRoot?.querySelector('.ia-button.warning:disabled')).not.to
184
+ .exist;
185
+ });
186
+
187
+ it('emits manageItems event when Item Manager button clicked', async () => {
188
+ const spy = Sinon.spy();
189
+ const el = await fixture<ManageBar>(html`
190
+ <manage-bar
191
+ showItemManageButton
192
+ removeAllowed
193
+ @manageItems=${spy}
194
+ ></manage-bar>
195
+ `);
196
+ const manageBtn = el.shadowRoot?.querySelector(
197
+ '.ia-button.warning',
198
+ ) as HTMLButtonElement;
199
+ expect(manageBtn).to.exist;
200
+ manageBtn.click();
201
+ expect(spy.callCount).to.equal(1);
202
+ });
203
+
204
+ it('emits removeItems event when modal confirm is clicked', async () => {
205
+ const modalManager = await fixture<ModalManager>(
206
+ html`<modal-manager></modal-manager>`,
207
+ );
208
+ const removeItemsSpy = Sinon.spy();
209
+ const el = await fixture<ManageBar>(html`
210
+ <manage-bar
211
+ .modalManager=${modalManager}
212
+ .selectedItems=${[{ identifier: '1', title: 'Item 1' }]}
213
+ removeAllowed
214
+ @removeItems=${removeItemsSpy}
215
+ ></manage-bar>
216
+ `);
217
+ await el.updateComplete;
218
+
219
+ const showModalSpy = Sinon.spy(
220
+ el.modalManager as ModalManagerInterface,
221
+ 'showModal',
222
+ );
223
+ (
224
+ el.shadowRoot?.querySelector('.ia-button.danger') as HTMLButtonElement
225
+ ).click();
226
+
227
+ const contentEl = (await fixture(
228
+ showModalSpy.args[0][0].customModalContent!,
229
+ )) as RemoveItemsModalContent;
230
+ (
231
+ contentEl.shadowRoot?.querySelector(
232
+ '.remove-items-btn',
233
+ ) as HTMLButtonElement
234
+ ).click();
235
+
236
+ expect(removeItemsSpy.callCount).to.equal(1);
237
+ });
238
+
239
+ describe('profileElement modal messages', () => {
240
+ async function openModalContent(
241
+ profileElement: string,
242
+ itemCount = 1,
243
+ ): Promise<RemoveItemsModalContent> {
244
+ const modalManager = await fixture<ModalManager>(
245
+ html`<modal-manager></modal-manager>`,
246
+ );
247
+ const items = Array.from({ length: itemCount }, (_, i) => ({
248
+ identifier: String(i + 1),
249
+ title: `Item ${i + 1}`,
250
+ }));
251
+ const el = await fixture<ManageBar>(html`
252
+ <manage-bar
253
+ .selectedItems=${items}
254
+ .profileElement=${profileElement as PageElementName}
255
+ removeAllowed
256
+ ></manage-bar>
257
+ `);
258
+ el.modalManager = modalManager as ModalManagerInterface;
259
+ await el.updateComplete;
260
+
261
+ const showModalSpy = Sinon.spy(
262
+ el.modalManager as ModalManagerInterface,
263
+ 'showModal',
264
+ );
265
+ (
266
+ el.shadowRoot?.querySelector('.ia-button.danger') as HTMLButtonElement
267
+ ).click();
268
+
269
+ return (await fixture(
270
+ showModalSpy.args[0][0].customModalContent!,
271
+ )) as RemoveItemsModalContent;
272
+ }
273
+
274
+ it('shows uploads-specific message for profileElement=uploads', async () => {
275
+ const contentEl = await openModalContent('uploads');
276
+ expect(contentEl.message).to.include('uploads list');
277
+ });
278
+
279
+ it('shows web archives message for profileElement=web_archives', async () => {
280
+ const contentEl = await openModalContent('web_archives');
281
+ expect(contentEl.message).to.include('web archives list');
282
+ });
283
+
284
+ it('shows favorites message for profileElement=favorites', async () => {
285
+ const contentEl = await openModalContent('favorites');
286
+ expect(contentEl.message).to.include('favorites list');
287
+ });
288
+
289
+ it('shows no message for unmapped profileElement (e.g. reviews)', async () => {
290
+ const contentEl = await openModalContent('reviews');
291
+ expect(contentEl.message).to.equal('');
292
+ expect(contentEl.shadowRoot?.querySelector('.message')).not.to.exist;
293
+ });
294
+
295
+ it('uses "this item" for a single selected item', async () => {
296
+ const contentEl = await openModalContent('uploads', 1);
297
+ expect(contentEl.message).to.include('this item');
298
+ });
299
+
300
+ it('uses "these items" for multiple selected items', async () => {
301
+ const contentEl = await openModalContent('uploads', 2);
302
+ expect(contentEl.message).to.include('these items');
303
+ });
304
+ });
305
+
306
+ it('showRemoveItemsProcessingModal shows processing modal', async () => {
307
+ const modalManager = await fixture<ModalManager>(
308
+ html`<modal-manager></modal-manager>`,
309
+ );
310
+ const el = await fixture<ManageBar>(html`
311
+ <manage-bar .modalManager=${modalManager}></manage-bar>
312
+ `);
313
+ const showModalSpy = Sinon.spy(
314
+ el.modalManager as ModalManagerInterface,
315
+ 'showModal',
316
+ );
317
+
318
+ el.showRemoveItemsProcessingModal();
319
+
320
+ expect(showModalSpy.callCount).to.equal(1);
321
+ expect(showModalSpy.args[0][0].config.showProcessingIndicator).to.be.true;
322
+ expect(showModalSpy.args[0][0].config.title?.values[0]).to.equal(
323
+ msg('Removing selected items...'),
324
+ );
325
+ });
326
+
327
+ it('showRemoveItemsErrorModal shows error modal', async () => {
328
+ const modalManager = await fixture<ModalManager>(
329
+ html`<modal-manager></modal-manager>`,
330
+ );
331
+ const el = await fixture<ManageBar>(html`
332
+ <manage-bar .modalManager=${modalManager}></manage-bar>
333
+ `);
334
+ const showModalSpy = Sinon.spy(
335
+ el.modalManager as ModalManagerInterface,
336
+ 'showModal',
337
+ );
338
+
339
+ el.showRemoveItemsErrorModal();
340
+
341
+ expect(showModalSpy.callCount).to.equal(1);
342
+ expect(showModalSpy.args[0][0].config.showProcessingIndicator).to.be.false;
343
+ expect(showModalSpy.args[0][0].config.title?.values[0]).to.equal(
344
+ msg('Error: unable to remove items'),
345
+ );
346
+ });
347
+ });