@internetarchive/collection-browser 4.3.1-alpha-webdev8165.0 → 4.3.1-alpha-webdev8257.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.
Files changed (70) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js.map +1 -1
  3. package/dist/src/app-root.d.ts +8 -0
  4. package/dist/src/app-root.js +698 -672
  5. package/dist/src/app-root.js.map +1 -1
  6. package/dist/src/collection-browser.d.ts +8 -0
  7. package/dist/src/collection-browser.js +779 -762
  8. package/dist/src/collection-browser.js.map +1 -1
  9. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  10. package/dist/src/manage/manage-bar.js +77 -77
  11. package/dist/src/manage/manage-bar.js.map +1 -1
  12. package/dist/src/models.d.ts +6 -0
  13. package/dist/src/models.js +16 -7
  14. package/dist/src/models.js.map +1 -1
  15. package/dist/src/restoration-state-handler.js +3 -1
  16. package/dist/src/restoration-state-handler.js.map +1 -1
  17. package/dist/src/styles/tile-action-styles.d.ts +14 -0
  18. package/dist/src/styles/tile-action-styles.js +52 -0
  19. package/dist/src/styles/tile-action-styles.js.map +1 -0
  20. package/dist/src/tiles/base-tile-component.d.ts +17 -1
  21. package/dist/src/tiles/base-tile-component.js +48 -1
  22. package/dist/src/tiles/base-tile-component.js.map +1 -1
  23. package/dist/src/tiles/grid/item-tile.js +1 -0
  24. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  25. package/dist/src/tiles/list/tile-list-compact-header.js +66 -46
  26. package/dist/src/tiles/list/tile-list-compact-header.js.map +1 -1
  27. package/dist/src/tiles/list/tile-list-compact.d.ts +1 -1
  28. package/dist/src/tiles/list/tile-list-compact.js +132 -100
  29. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  30. package/dist/src/tiles/list/tile-list.d.ts +1 -1
  31. package/dist/src/tiles/list/tile-list.js +316 -298
  32. package/dist/src/tiles/list/tile-list.js.map +1 -1
  33. package/dist/src/tiles/models.d.ts +14 -0
  34. package/dist/src/tiles/models.js.map +1 -1
  35. package/dist/src/tiles/tile-dispatcher.d.ts +14 -0
  36. package/dist/src/tiles/tile-dispatcher.js +107 -4
  37. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  38. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  39. package/dist/test/data-source/collection-browser-data-source.test.js +2 -2
  40. package/dist/test/data-source/collection-browser-data-source.test.js.map +1 -1
  41. package/dist/test/manage/manage-bar.test.js +33 -33
  42. package/dist/test/manage/manage-bar.test.js.map +1 -1
  43. package/dist/test/restoration-state-handler.test.js +0 -70
  44. package/dist/test/restoration-state-handler.test.js.map +1 -1
  45. package/dist/test/tiles/list/tile-list-compact-header.test.js +12 -12
  46. package/dist/test/tiles/list/tile-list-compact-header.test.js.map +1 -1
  47. package/dist/test/tiles/list/tile-list.test.js +134 -134
  48. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  49. package/index.ts +1 -0
  50. package/package.json +1 -1
  51. package/src/app-root.ts +1281 -1251
  52. package/src/collection-browser.ts +3063 -3049
  53. package/src/data-source/collection-browser-data-source.ts +1465 -1465
  54. package/src/manage/manage-bar.ts +276 -276
  55. package/src/models.ts +895 -879
  56. package/src/restoration-state-handler.ts +550 -546
  57. package/src/styles/tile-action-styles.ts +52 -0
  58. package/src/tiles/base-tile-component.ts +57 -1
  59. package/src/tiles/grid/item-tile.ts +1 -0
  60. package/src/tiles/list/tile-list-compact-header.ts +106 -86
  61. package/src/tiles/list/tile-list-compact.ts +273 -239
  62. package/src/tiles/list/tile-list.ts +718 -700
  63. package/src/tiles/models.ts +16 -0
  64. package/src/tiles/tile-dispatcher.ts +114 -4
  65. package/src/tiles/tile-display-value-provider.ts +134 -134
  66. package/test/data-source/collection-browser-data-source.test.ts +193 -193
  67. package/test/manage/manage-bar.test.ts +347 -347
  68. package/test/restoration-state-handler.test.ts +480 -569
  69. package/test/tiles/list/tile-list-compact-header.test.ts +43 -43
  70. package/test/tiles/list/tile-list.test.ts +576 -576
@@ -1,193 +1,193 @@
1
- import { expect, fixture } from '@open-wc/testing';
2
- import { html } from 'lit';
3
- import sinon from 'sinon';
4
- import { ItemHit, SearchType } from '@internetarchive/search-service';
5
- import { CollectionBrowserDataSource } from '../../src/data-source/collection-browser-data-source';
6
- import { TileModel } from '../../src/models';
7
- import type { CollectionBrowser } from '../../src/collection-browser';
8
- import '../../src/collection-browser';
9
- import { MockSearchService } from '../mocks/mock-search-service';
10
-
11
- const dataPage: TileModel[] = [
12
- new TileModel(
13
- new ItemHit({
14
- fields: {
15
- identifier: 'foo',
16
- },
17
- }),
18
- ),
19
- new TileModel(
20
- new ItemHit({
21
- fields: {
22
- identifier: 'bar',
23
- },
24
- }),
25
- ),
26
- ];
27
-
28
- describe('Collection Browser Data Source', () => {
29
- let host: CollectionBrowser;
30
-
31
- beforeEach(async () => {
32
- host = await fixture<CollectionBrowser>(html`
33
- <collection-browser></collection-browser>
34
- `);
35
- });
36
-
37
- it('can add and retrieve data pages', () => {
38
- const dataSource = new CollectionBrowserDataSource(host);
39
- dataSource.addPage(1, dataPage);
40
-
41
- expect(Object.keys(dataSource.getAllPages()).length).to.equal(1);
42
- expect(dataSource.getPage(1).length).to.equal(2);
43
- expect(dataSource.getPage(1)[0].identifier).to.equal('foo');
44
- expect(dataSource.getPage(1)[1].identifier).to.equal('bar');
45
- });
46
-
47
- it('can add data split across multiple pages', () => {
48
- const dataSource = new CollectionBrowserDataSource(host, 3);
49
- const doubledDataPage = [...dataPage, ...dataPage];
50
- dataSource.addMultiplePages(1, doubledDataPage);
51
-
52
- expect(Object.keys(dataSource.getAllPages()).length).to.equal(2);
53
- expect(dataSource.getPage(1).length).to.equal(3);
54
- expect(dataSource.getPage(2).length).to.equal(1);
55
- expect(dataSource.getPage(1)[0].identifier).to.equal('foo');
56
- expect(dataSource.getPage(1)[1].identifier).to.equal('bar');
57
- expect(dataSource.getPage(1)[2].identifier).to.equal('foo');
58
- expect(dataSource.getPage(2)[0].identifier).to.equal('bar');
59
- });
60
-
61
- it('resets data when changing page size', () => {
62
- const dataSource = new CollectionBrowserDataSource(host);
63
- dataSource.addPage(1, dataPage);
64
-
65
- dataSource.setPageSize(100);
66
- expect(Object.keys(dataSource.getAllPages()).length).to.equal(0);
67
- expect(dataSource.getPageSize()).to.equal(100);
68
- });
69
-
70
- it('can be installed on the host', async () => {
71
- const dataSource = new CollectionBrowserDataSource(host);
72
- dataSource.addPage(1, dataPage);
73
-
74
- host.installDataSourceAndQueryState(dataSource, {
75
- searchType: SearchType.METADATA,
76
- sortDirection: null,
77
- selectedTitleFilter: null,
78
- selectedCreatorFilter: null,
79
- baseQuery: 'foobar',
80
- });
81
-
82
- await host.updateComplete;
83
-
84
- expect(host.dataSource).to.equal(dataSource);
85
- expect(host.baseQuery).to.equal('foobar');
86
-
87
- host.removeController(dataSource);
88
- });
89
-
90
- it('can suppress further fetches', async () => {
91
- host.searchService = new MockSearchService();
92
-
93
- const pageFetchSpy = sinon.spy();
94
- const dataSource = new CollectionBrowserDataSource(host);
95
- dataSource.fetchPage = pageFetchSpy;
96
-
97
- dataSource.addPage(1, dataPage);
98
- dataSource.setFetchesSuppressed(true);
99
- dataSource.handleQueryChange();
100
-
101
- expect(pageFetchSpy.callCount).to.equal(0);
102
- });
103
-
104
- it('can set its initial page batch size', async () => {
105
- host.searchService = new MockSearchService();
106
-
107
- const pageFetchSpy = sinon.spy();
108
- const dataSource = new CollectionBrowserDataSource(host);
109
- dataSource.setNumInitialPages(10);
110
- dataSource.fetchPage = pageFetchSpy;
111
-
112
- dataSource.handleQueryChange();
113
-
114
- // Uses specified number of initial pages
115
- expect(pageFetchSpy.args[0][1]).to.equal(10);
116
- });
117
-
118
- it('refreshes prefix filter counts', () => {
119
- const dataSource = new CollectionBrowserDataSource(host);
120
- dataSource.addPage(1, dataPage);
121
-
122
- dataSource.prefixFilterCountMap = {
123
- title: {
124
- X: 10,
125
- },
126
- };
127
-
128
- dataSource.refreshLetterCounts();
129
- expect(dataSource.prefixFilterCountMap).to.deep.equal({});
130
- });
131
-
132
- describe('empty FTS query in collection falls back to metadata search', () => {
133
- it('allows search with empty query and FTS in a collection', async () => {
134
- const searchService = new MockSearchService();
135
- host.searchService = searchService;
136
- host.withinCollection = 'test-collection';
137
- host.searchType = SearchType.FULLTEXT;
138
- host.baseQuery = '';
139
- await host.updateComplete;
140
-
141
- const dataSource = new CollectionBrowserDataSource(host);
142
- host.addController(dataSource);
143
- expect(dataSource.canPerformSearch).to.be.true;
144
- host.removeController(dataSource);
145
- });
146
-
147
- it('uses metadata search type for fetch when FTS query is empty in a collection', async () => {
148
- const searchService = new MockSearchService();
149
- host.searchService = searchService;
150
- host.withinCollection = 'test-collection';
151
- host.searchType = SearchType.FULLTEXT;
152
- host.baseQuery = '';
153
- await host.updateComplete;
154
-
155
- const dataSource = new CollectionBrowserDataSource(host);
156
- host.addController(dataSource);
157
- await dataSource.fetchPage(1);
158
-
159
- expect(searchService.searchType).to.equal(SearchType.METADATA);
160
- host.removeController(dataSource);
161
- });
162
-
163
- it('uses FTS search type for fetch when FTS query is non-empty in a collection', async () => {
164
- const searchService = new MockSearchService();
165
- host.searchService = searchService;
166
- host.withinCollection = 'test-collection';
167
- host.searchType = SearchType.FULLTEXT;
168
- host.baseQuery = 'some query';
169
- await host.updateComplete;
170
-
171
- const dataSource = new CollectionBrowserDataSource(host);
172
- host.addController(dataSource);
173
- await dataSource.fetchPage(1);
174
-
175
- expect(searchService.searchType).to.equal(SearchType.FULLTEXT);
176
- host.removeController(dataSource);
177
- });
178
-
179
- it('does not allow search with empty FTS query outside a collection', async () => {
180
- const searchService = new MockSearchService();
181
- host.searchService = searchService;
182
- host.withinCollection = undefined;
183
- host.searchType = SearchType.FULLTEXT;
184
- host.baseQuery = '';
185
- await host.updateComplete;
186
-
187
- const dataSource = new CollectionBrowserDataSource(host);
188
- host.addController(dataSource);
189
- expect(dataSource.canPerformSearch).to.be.false;
190
- host.removeController(dataSource);
191
- });
192
- });
193
- });
1
+ import { expect, fixture } from '@open-wc/testing';
2
+ import { html } from 'lit';
3
+ import sinon from 'sinon';
4
+ import { ItemHit, SearchType } from '@internetarchive/search-service';
5
+ import { CollectionBrowserDataSource } from '../../src/data-source/collection-browser-data-source';
6
+ import { TileModel } from '../../src/models';
7
+ import type { CollectionBrowser } from '../../src/collection-browser';
8
+ import '../../src/collection-browser';
9
+ import { MockSearchService } from '../mocks/mock-search-service';
10
+
11
+ const dataPage: TileModel[] = [
12
+ new TileModel(
13
+ new ItemHit({
14
+ fields: {
15
+ identifier: 'foo',
16
+ },
17
+ }),
18
+ ),
19
+ new TileModel(
20
+ new ItemHit({
21
+ fields: {
22
+ identifier: 'bar',
23
+ },
24
+ }),
25
+ ),
26
+ ];
27
+
28
+ describe('Collection Browser Data Source', () => {
29
+ let host: CollectionBrowser;
30
+
31
+ beforeEach(async () => {
32
+ host = await fixture<CollectionBrowser>(html`
33
+ <collection-browser></collection-browser>
34
+ `);
35
+ });
36
+
37
+ it('can add and retrieve data pages', () => {
38
+ const dataSource = new CollectionBrowserDataSource(host);
39
+ dataSource.addPage(1, dataPage);
40
+
41
+ expect(Object.keys(dataSource.getAllPages()).length).to.equal(1);
42
+ expect(dataSource.getPage(1).length).to.equal(2);
43
+ expect(dataSource.getPage(1)[0].identifier).to.equal('foo');
44
+ expect(dataSource.getPage(1)[1].identifier).to.equal('bar');
45
+ });
46
+
47
+ it('can add data split across multiple pages', () => {
48
+ const dataSource = new CollectionBrowserDataSource(host, 3);
49
+ const doubledDataPage = [...dataPage, ...dataPage];
50
+ dataSource.addMultiplePages(1, doubledDataPage);
51
+
52
+ expect(Object.keys(dataSource.getAllPages()).length).to.equal(2);
53
+ expect(dataSource.getPage(1).length).to.equal(3);
54
+ expect(dataSource.getPage(2).length).to.equal(1);
55
+ expect(dataSource.getPage(1)[0].identifier).to.equal('foo');
56
+ expect(dataSource.getPage(1)[1].identifier).to.equal('bar');
57
+ expect(dataSource.getPage(1)[2].identifier).to.equal('foo');
58
+ expect(dataSource.getPage(2)[0].identifier).to.equal('bar');
59
+ });
60
+
61
+ it('resets data when changing page size', () => {
62
+ const dataSource = new CollectionBrowserDataSource(host);
63
+ dataSource.addPage(1, dataPage);
64
+
65
+ dataSource.setPageSize(100);
66
+ expect(Object.keys(dataSource.getAllPages()).length).to.equal(0);
67
+ expect(dataSource.getPageSize()).to.equal(100);
68
+ });
69
+
70
+ it('can be installed on the host', async () => {
71
+ const dataSource = new CollectionBrowserDataSource(host);
72
+ dataSource.addPage(1, dataPage);
73
+
74
+ host.installDataSourceAndQueryState(dataSource, {
75
+ searchType: SearchType.METADATA,
76
+ sortDirection: null,
77
+ selectedTitleFilter: null,
78
+ selectedCreatorFilter: null,
79
+ baseQuery: 'foobar',
80
+ });
81
+
82
+ await host.updateComplete;
83
+
84
+ expect(host.dataSource).to.equal(dataSource);
85
+ expect(host.baseQuery).to.equal('foobar');
86
+
87
+ host.removeController(dataSource);
88
+ });
89
+
90
+ it('can suppress further fetches', async () => {
91
+ host.searchService = new MockSearchService();
92
+
93
+ const pageFetchSpy = sinon.spy();
94
+ const dataSource = new CollectionBrowserDataSource(host);
95
+ dataSource.fetchPage = pageFetchSpy;
96
+
97
+ dataSource.addPage(1, dataPage);
98
+ dataSource.setFetchesSuppressed(true);
99
+ dataSource.handleQueryChange();
100
+
101
+ expect(pageFetchSpy.callCount).to.equal(0);
102
+ });
103
+
104
+ it('can set its initial page batch size', async () => {
105
+ host.searchService = new MockSearchService();
106
+
107
+ const pageFetchSpy = sinon.spy();
108
+ const dataSource = new CollectionBrowserDataSource(host);
109
+ dataSource.setNumInitialPages(10);
110
+ dataSource.fetchPage = pageFetchSpy;
111
+
112
+ dataSource.handleQueryChange();
113
+
114
+ // Uses specified number of initial pages
115
+ expect(pageFetchSpy.args[0][1]).to.equal(10);
116
+ });
117
+
118
+ it('refreshes prefix filter counts', () => {
119
+ const dataSource = new CollectionBrowserDataSource(host);
120
+ dataSource.addPage(1, dataPage);
121
+
122
+ dataSource.prefixFilterCountMap = {
123
+ title: {
124
+ X: 10,
125
+ },
126
+ };
127
+
128
+ dataSource.refreshLetterCounts();
129
+ expect(dataSource.prefixFilterCountMap).to.deep.equal({});
130
+ });
131
+
132
+ describe('empty FTS query in collection falls back to metadata search', () => {
133
+ it('allows search with empty query and FTS in a collection', async () => {
134
+ const searchService = new MockSearchService();
135
+ host.searchService = searchService;
136
+ host.withinCollection = 'test-collection';
137
+ host.searchType = SearchType.FULLTEXT;
138
+ host.baseQuery = '';
139
+ await host.updateComplete;
140
+
141
+ const dataSource = new CollectionBrowserDataSource(host);
142
+ host.addController(dataSource);
143
+ expect(dataSource.canPerformSearch).to.be.true;
144
+ host.removeController(dataSource);
145
+ });
146
+
147
+ it('uses metadata search type for fetch when FTS query is empty in a collection', async () => {
148
+ const searchService = new MockSearchService();
149
+ host.searchService = searchService;
150
+ host.withinCollection = 'test-collection';
151
+ host.searchType = SearchType.FULLTEXT;
152
+ host.baseQuery = '';
153
+ await host.updateComplete;
154
+
155
+ const dataSource = new CollectionBrowserDataSource(host);
156
+ host.addController(dataSource);
157
+ await dataSource.fetchPage(1);
158
+
159
+ expect(searchService.searchType).to.equal(SearchType.METADATA);
160
+ host.removeController(dataSource);
161
+ });
162
+
163
+ it('uses FTS search type for fetch when FTS query is non-empty in a collection', async () => {
164
+ const searchService = new MockSearchService();
165
+ host.searchService = searchService;
166
+ host.withinCollection = 'test-collection';
167
+ host.searchType = SearchType.FULLTEXT;
168
+ host.baseQuery = 'some query';
169
+ await host.updateComplete;
170
+
171
+ const dataSource = new CollectionBrowserDataSource(host);
172
+ host.addController(dataSource);
173
+ await dataSource.fetchPage(1);
174
+
175
+ expect(searchService.searchType).to.equal(SearchType.FULLTEXT);
176
+ host.removeController(dataSource);
177
+ });
178
+
179
+ it('does not allow search with empty FTS query outside a collection', async () => {
180
+ const searchService = new MockSearchService();
181
+ host.searchService = searchService;
182
+ host.withinCollection = undefined;
183
+ host.searchType = SearchType.FULLTEXT;
184
+ host.baseQuery = '';
185
+ await host.updateComplete;
186
+
187
+ const dataSource = new CollectionBrowserDataSource(host);
188
+ host.addController(dataSource);
189
+ expect(dataSource.canPerformSearch).to.be.false;
190
+ host.removeController(dataSource);
191
+ });
192
+ });
193
+ });