@internetarchive/collection-browser 1.8.0 → 1.9.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/collection-browser.js +18 -12
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/models.d.ts +48 -35
- package/dist/src/models.js +139 -78
- package/dist/src/models.js.map +1 -1
- package/dist/src/restoration-state-handler.d.ts +9 -2
- package/dist/src/restoration-state-handler.js +61 -32
- package/dist/src/restoration-state-handler.js.map +1 -1
- package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +2 -0
- package/dist/src/sort-filter-bar/sort-filter-bar.js +31 -26
- package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
- package/dist/src/tiles/tile-dispatcher.js +2 -1
- package/dist/src/tiles/tile-dispatcher.js.map +1 -1
- package/dist/test/restoration-state-handler.test.js +53 -1
- package/dist/test/restoration-state-handler.test.js.map +1 -1
- package/package.json +1 -1
- package/src/collection-browser.ts +16 -9
- package/src/models.ts +193 -109
- package/src/restoration-state-handler.ts +66 -40
- package/src/sort-filter-bar/sort-filter-bar.ts +35 -28
- package/src/tiles/tile-dispatcher.ts +2 -1
- package/test/restoration-state-handler.test.ts +68 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SearchType } from '@internetarchive/search-service';
|
|
2
2
|
import { expect } from '@open-wc/testing';
|
|
3
|
-
import { getDefaultSelectedFacets } from '../src/models';
|
|
3
|
+
import { SortField, getDefaultSelectedFacets } from '../src/models';
|
|
4
4
|
import { RestorationStateHandler } from '../src/restoration-state-handler';
|
|
5
5
|
|
|
6
6
|
describe('Restoration state handler', () => {
|
|
@@ -245,6 +245,73 @@ describe('Restoration state handler', () => {
|
|
|
245
245
|
expect(restorationState.sortDirection).to.equal('asc');
|
|
246
246
|
});
|
|
247
247
|
|
|
248
|
+
it('should restore sort from URL (space format)', async () => {
|
|
249
|
+
const handler = new RestorationStateHandler({ context: 'search' });
|
|
250
|
+
|
|
251
|
+
const url = new URL(window.location.href);
|
|
252
|
+
url.search = '?sort=foo+desc';
|
|
253
|
+
window.history.replaceState({ path: url.href }, '', url.href);
|
|
254
|
+
|
|
255
|
+
const restorationState = handler.getRestorationState();
|
|
256
|
+
expect(restorationState.selectedSort).to.equal('unrecognized');
|
|
257
|
+
expect(restorationState.sortDirection).to.equal('desc');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('should restore unrecognized sort from URL (prefix format)', async () => {
|
|
261
|
+
const handler = new RestorationStateHandler({ context: 'search' });
|
|
262
|
+
|
|
263
|
+
const url = new URL(window.location.href);
|
|
264
|
+
url.search = '?sort=-foo';
|
|
265
|
+
window.history.replaceState({ path: url.href }, '', url.href);
|
|
266
|
+
|
|
267
|
+
const restorationState = handler.getRestorationState();
|
|
268
|
+
expect(restorationState.selectedSort).to.equal('unrecognized');
|
|
269
|
+
expect(restorationState.sortDirection).to.equal('desc');
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('should save direction to URL even for unrecognized sort fields', async () => {
|
|
273
|
+
const url = new URL(window.location.href);
|
|
274
|
+
url.search = '?sort=foo';
|
|
275
|
+
window.history.replaceState({ path: url.href }, '', url.href);
|
|
276
|
+
|
|
277
|
+
const handler = new RestorationStateHandler({ context: 'search' });
|
|
278
|
+
handler.persistState({
|
|
279
|
+
selectedSort: SortField.unrecognized,
|
|
280
|
+
sortDirection: 'desc',
|
|
281
|
+
selectedFacets: getDefaultSelectedFacets(),
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
expect(window.location.search).to.equal('?sort=-foo');
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('should keep existing direction for unrecognized sort fields when unspecified in state', async () => {
|
|
288
|
+
const url = new URL(window.location.href);
|
|
289
|
+
url.search = '?sort=foo+desc';
|
|
290
|
+
window.history.replaceState({ path: url.href }, '', url.href);
|
|
291
|
+
|
|
292
|
+
const handler = new RestorationStateHandler({ context: 'search' });
|
|
293
|
+
handler.persistState({
|
|
294
|
+
selectedSort: SortField.unrecognized,
|
|
295
|
+
selectedFacets: getDefaultSelectedFacets(),
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
expect(window.location.search).to.equal('?sort=-foo');
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('should just ignore unrecognized sort fields w/ unknown formats', async () => {
|
|
302
|
+
const url = new URL(window.location.href);
|
|
303
|
+
url.search = '?sort=+foo';
|
|
304
|
+
window.history.replaceState({ path: url.href }, '', url.href);
|
|
305
|
+
|
|
306
|
+
const handler = new RestorationStateHandler({ context: 'search' });
|
|
307
|
+
handler.persistState({
|
|
308
|
+
selectedSort: SortField.unrecognized,
|
|
309
|
+
selectedFacets: getDefaultSelectedFacets(),
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
expect(window.location.search).to.equal('?sort=+foo');
|
|
313
|
+
});
|
|
314
|
+
|
|
248
315
|
it('should not save current page state to the URL for page 1', async () => {
|
|
249
316
|
const url = new URL(window.location.href);
|
|
250
317
|
url.search = '';
|