@internetarchive/collection-browser 0.4.3-alpha.9 → 0.4.4-alpha

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 (250) hide show
  1. package/.editorconfig +29 -29
  2. package/.github/workflows/ci.yml +26 -26
  3. package/.github/workflows/gh-pages-main.yml +39 -39
  4. package/.github/workflows/npm-publish.yml +39 -39
  5. package/.github/workflows/pr-preview.yml +38 -38
  6. package/.husky/pre-commit +4 -4
  7. package/LICENSE +661 -661
  8. package/README.md +83 -83
  9. package/dist/index.d.ts +9 -9
  10. package/dist/index.js +9 -9
  11. package/dist/src/app-root.d.ts +50 -48
  12. package/dist/src/app-root.js +449 -412
  13. package/dist/src/app-root.js.map +1 -1
  14. package/dist/src/assets/img/icons/arrow-left.d.ts +2 -2
  15. package/dist/src/assets/img/icons/arrow-left.js +2 -2
  16. package/dist/src/assets/img/icons/arrow-right.d.ts +2 -2
  17. package/dist/src/assets/img/icons/arrow-right.js +2 -2
  18. package/dist/src/assets/img/icons/chevron.d.ts +2 -2
  19. package/dist/src/assets/img/icons/chevron.js +2 -2
  20. package/dist/src/assets/img/icons/empty-query.d.ts +2 -2
  21. package/dist/src/assets/img/icons/empty-query.js +2 -2
  22. package/dist/src/assets/img/icons/eye-closed.d.ts +2 -2
  23. package/dist/src/assets/img/icons/eye-closed.js +2 -2
  24. package/dist/src/assets/img/icons/eye.d.ts +2 -2
  25. package/dist/src/assets/img/icons/eye.js +2 -2
  26. package/dist/src/assets/img/icons/favorite-filled.d.ts +1 -1
  27. package/dist/src/assets/img/icons/favorite-filled.js +2 -2
  28. package/dist/src/assets/img/icons/login-required.d.ts +1 -1
  29. package/dist/src/assets/img/icons/login-required.js +2 -2
  30. package/dist/src/assets/img/icons/mediatype/account.d.ts +1 -1
  31. package/dist/src/assets/img/icons/mediatype/account.js +2 -2
  32. package/dist/src/assets/img/icons/mediatype/audio.d.ts +1 -1
  33. package/dist/src/assets/img/icons/mediatype/audio.js +2 -2
  34. package/dist/src/assets/img/icons/mediatype/collection.d.ts +1 -1
  35. package/dist/src/assets/img/icons/mediatype/collection.js +2 -2
  36. package/dist/src/assets/img/icons/mediatype/data.d.ts +1 -1
  37. package/dist/src/assets/img/icons/mediatype/data.js +2 -2
  38. package/dist/src/assets/img/icons/mediatype/etree.d.ts +1 -1
  39. package/dist/src/assets/img/icons/mediatype/etree.js +2 -2
  40. package/dist/src/assets/img/icons/mediatype/film.d.ts +1 -1
  41. package/dist/src/assets/img/icons/mediatype/film.js +2 -2
  42. package/dist/src/assets/img/icons/mediatype/images.d.ts +1 -1
  43. package/dist/src/assets/img/icons/mediatype/images.js +2 -2
  44. package/dist/src/assets/img/icons/mediatype/radio.d.ts +1 -1
  45. package/dist/src/assets/img/icons/mediatype/radio.js +2 -2
  46. package/dist/src/assets/img/icons/mediatype/software.d.ts +1 -1
  47. package/dist/src/assets/img/icons/mediatype/software.js +2 -2
  48. package/dist/src/assets/img/icons/mediatype/texts.d.ts +1 -1
  49. package/dist/src/assets/img/icons/mediatype/texts.js +2 -2
  50. package/dist/src/assets/img/icons/mediatype/tv.d.ts +1 -1
  51. package/dist/src/assets/img/icons/mediatype/tv.js +2 -2
  52. package/dist/src/assets/img/icons/mediatype/video.d.ts +1 -1
  53. package/dist/src/assets/img/icons/mediatype/video.js +2 -2
  54. package/dist/src/assets/img/icons/mediatype/web.d.ts +1 -1
  55. package/dist/src/assets/img/icons/mediatype/web.js +2 -2
  56. package/dist/src/assets/img/icons/null-result.d.ts +2 -2
  57. package/dist/src/assets/img/icons/null-result.js +2 -2
  58. package/dist/src/assets/img/icons/restricted.d.ts +1 -1
  59. package/dist/src/assets/img/icons/restricted.js +2 -2
  60. package/dist/src/assets/img/icons/reviews.d.ts +1 -1
  61. package/dist/src/assets/img/icons/reviews.js +2 -2
  62. package/dist/src/assets/img/icons/upload.d.ts +1 -1
  63. package/dist/src/assets/img/icons/upload.js +2 -2
  64. package/dist/src/assets/img/icons/views.d.ts +1 -1
  65. package/dist/src/assets/img/icons/views.js +2 -2
  66. package/dist/src/circular-activity-indicator.d.ts +5 -5
  67. package/dist/src/circular-activity-indicator.js +17 -17
  68. package/dist/src/collection-browser.d.ts +315 -276
  69. package/dist/src/collection-browser.js +1276 -1179
  70. package/dist/src/collection-browser.js.map +1 -1
  71. package/dist/src/collection-facets/facet-tombstone-row.d.ts +5 -5
  72. package/dist/src/collection-facets/facet-tombstone-row.js +15 -15
  73. package/dist/src/collection-facets/facets-template.d.ts +16 -16
  74. package/dist/src/collection-facets/facets-template.js +125 -125
  75. package/dist/src/collection-facets/more-facets-content.d.ts +77 -77
  76. package/dist/src/collection-facets/more-facets-content.js +357 -357
  77. package/dist/src/collection-facets/more-facets-pagination.d.ts +36 -36
  78. package/dist/src/collection-facets/more-facets-pagination.js +192 -192
  79. package/dist/src/collection-facets.d.ts +78 -78
  80. package/dist/src/collection-facets.js +391 -391
  81. package/dist/src/empty-placeholder.d.ts +11 -11
  82. package/dist/src/empty-placeholder.js +42 -42
  83. package/dist/src/language-code-handler/language-code-handler.d.ts +37 -37
  84. package/dist/src/language-code-handler/language-code-handler.js +26 -26
  85. package/dist/src/language-code-handler/language-code-mapping.d.ts +1 -1
  86. package/dist/src/language-code-handler/language-code-mapping.js +562 -562
  87. package/dist/src/mediatype/mediatype-config.d.ts +3 -3
  88. package/dist/src/mediatype/mediatype-config.js +85 -85
  89. package/dist/src/models.d.ts +114 -112
  90. package/dist/src/models.js +125 -125
  91. package/dist/src/models.js.map +1 -1
  92. package/dist/src/restoration-state-handler.d.ts +45 -45
  93. package/dist/src/restoration-state-handler.js +230 -230
  94. package/dist/src/sort-filter-bar/alpha-bar.d.ts +12 -12
  95. package/dist/src/sort-filter-bar/alpha-bar.js +52 -52
  96. package/dist/src/sort-filter-bar/img/compact.d.ts +1 -1
  97. package/dist/src/sort-filter-bar/img/compact.js +2 -2
  98. package/dist/src/sort-filter-bar/img/list.d.ts +1 -1
  99. package/dist/src/sort-filter-bar/img/list.js +2 -2
  100. package/dist/src/sort-filter-bar/img/sort-triangle.d.ts +1 -1
  101. package/dist/src/sort-filter-bar/img/sort-triangle.js +2 -2
  102. package/dist/src/sort-filter-bar/img/tile.d.ts +1 -1
  103. package/dist/src/sort-filter-bar/img/tile.js +2 -2
  104. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +108 -108
  105. package/dist/src/sort-filter-bar/sort-filter-bar.js +428 -428
  106. package/dist/src/styles/item-image-styles.d.ts +8 -8
  107. package/dist/src/styles/item-image-styles.js +22 -12
  108. package/dist/src/styles/item-image-styles.js.map +1 -1
  109. package/dist/src/tiles/collection-browser-loading-tile.d.ts +5 -5
  110. package/dist/src/tiles/collection-browser-loading-tile.js +16 -16
  111. package/dist/src/tiles/collection-browser-loading-tile.js.map +1 -1
  112. package/dist/src/tiles/grid/account-tile.d.ts +17 -17
  113. package/dist/src/tiles/grid/account-tile.js +48 -47
  114. package/dist/src/tiles/grid/account-tile.js.map +1 -1
  115. package/dist/src/tiles/grid/collection-tile.d.ts +14 -7
  116. package/dist/src/tiles/grid/collection-tile.js +112 -146
  117. package/dist/src/tiles/grid/collection-tile.js.map +1 -1
  118. package/dist/src/tiles/grid/item-tile.d.ts +29 -29
  119. package/dist/src/tiles/grid/item-tile.js +110 -105
  120. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  121. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.d.ts +1 -1
  122. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +12 -8
  123. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js.map +1 -1
  124. package/dist/src/tiles/grid/tile-stats.d.ts +10 -10
  125. package/dist/src/tiles/grid/tile-stats.js +41 -40
  126. package/dist/src/tiles/grid/tile-stats.js.map +1 -1
  127. package/dist/src/tiles/image-block.d.ts +17 -17
  128. package/dist/src/tiles/image-block.js +76 -72
  129. package/dist/src/tiles/image-block.js.map +1 -1
  130. package/dist/src/tiles/item-image.d.ts +35 -35
  131. package/dist/src/tiles/item-image.js +117 -116
  132. package/dist/src/tiles/item-image.js.map +1 -1
  133. package/dist/src/tiles/list/account-label.d.ts +1 -1
  134. package/dist/src/tiles/list/account-label.js +6 -6
  135. package/dist/src/tiles/list/date-label.d.ts +1 -1
  136. package/dist/src/tiles/list/date-label.js +12 -12
  137. package/dist/src/tiles/list/tile-list-compact-header.d.ts +12 -12
  138. package/dist/src/tiles/list/tile-list-compact-header.js +41 -41
  139. package/dist/src/tiles/list/tile-list-compact.d.ts +21 -21
  140. package/dist/src/tiles/list/tile-list-compact.js +93 -93
  141. package/dist/src/tiles/list/tile-list.d.ts +53 -53
  142. package/dist/src/tiles/list/tile-list.js +279 -279
  143. package/dist/src/tiles/mediatype-icon.d.ts +9 -9
  144. package/dist/src/tiles/mediatype-icon.js +47 -47
  145. package/dist/src/tiles/overlay/icon-overlay.d.ts +10 -10
  146. package/dist/src/tiles/overlay/icon-overlay.js +40 -40
  147. package/dist/src/tiles/overlay/icon-text-overlay.d.ts +9 -9
  148. package/dist/src/tiles/overlay/icon-text-overlay.js +38 -38
  149. package/dist/src/tiles/overlay/text-overlay.d.ts +10 -10
  150. package/dist/src/tiles/overlay/text-overlay.js +42 -42
  151. package/dist/src/tiles/text-snippet-block.d.ts +27 -27
  152. package/dist/src/tiles/text-snippet-block.js +73 -73
  153. package/dist/src/tiles/tile-dispatcher.d.ts +36 -36
  154. package/dist/src/tiles/tile-dispatcher.js +145 -128
  155. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  156. package/dist/src/utils/analytics-events.d.ts +22 -22
  157. package/dist/src/utils/analytics-events.js +24 -24
  158. package/dist/src/utils/format-count.d.ts +7 -7
  159. package/dist/src/utils/format-count.js +76 -76
  160. package/dist/src/utils/format-date.d.ts +2 -2
  161. package/dist/src/utils/format-date.js +23 -23
  162. package/dist/src/utils/format-unit-size.d.ts +2 -0
  163. package/dist/src/utils/format-unit-size.js +34 -0
  164. package/dist/src/utils/format-unit-size.js.map +1 -0
  165. package/dist/test/collection-browser.test.d.ts +1 -1
  166. package/dist/test/collection-browser.test.js +646 -646
  167. package/dist/test/collection-facets/facets-template.test.d.ts +1 -1
  168. package/dist/test/collection-facets/facets-template.test.js +62 -62
  169. package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -1
  170. package/dist/test/collection-facets/more-facets-content.test.js +114 -114
  171. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -1
  172. package/dist/test/collection-facets/more-facets-pagination.test.js +117 -117
  173. package/dist/test/collection-facets.test.d.ts +2 -2
  174. package/dist/test/collection-facets.test.js +544 -544
  175. package/dist/test/empty-placeholder.test.d.ts +1 -1
  176. package/dist/test/empty-placeholder.test.js +33 -33
  177. package/dist/test/icon-overlay.test.d.ts +1 -1
  178. package/dist/test/icon-overlay.test.js +24 -24
  179. package/dist/test/image-block.test.d.ts +1 -1
  180. package/dist/test/image-block.test.js +48 -48
  181. package/dist/test/item-image.test.d.ts +1 -1
  182. package/dist/test/item-image.test.js +84 -80
  183. package/dist/test/item-image.test.js.map +1 -1
  184. package/dist/test/mediatype-config.test.d.ts +1 -1
  185. package/dist/test/mediatype-config.test.js +16 -16
  186. package/dist/test/mocks/mock-analytics-handler.d.ts +10 -10
  187. package/dist/test/mocks/mock-analytics-handler.js +15 -15
  188. package/dist/test/mocks/mock-collection-name-cache.d.ts +7 -7
  189. package/dist/test/mocks/mock-collection-name-cache.js +13 -13
  190. package/dist/test/mocks/mock-search-responses.d.ts +12 -12
  191. package/dist/test/mocks/mock-search-responses.js +341 -341
  192. package/dist/test/mocks/mock-search-service.d.ts +13 -13
  193. package/dist/test/mocks/mock-search-service.js +40 -40
  194. package/dist/test/restoration-state-handler.test.d.ts +1 -1
  195. package/dist/test/restoration-state-handler.test.js +125 -125
  196. package/dist/test/sort-filter-bar/alpha-bar.test.d.ts +1 -1
  197. package/dist/test/sort-filter-bar/alpha-bar.test.js +43 -43
  198. package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +1 -1
  199. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +141 -141
  200. package/dist/test/text-overlay.test.d.ts +1 -1
  201. package/dist/test/text-overlay.test.js +48 -48
  202. package/dist/test/text-snippet-block.test.d.ts +1 -1
  203. package/dist/test/text-snippet-block.test.js +57 -57
  204. package/dist/test/tile-stats.test.d.ts +1 -1
  205. package/dist/test/tile-stats.test.js +33 -33
  206. package/dist/test/tiles/grid/account-tile.test.d.ts +1 -1
  207. package/dist/test/tiles/grid/account-tile.test.js +60 -60
  208. package/dist/test/tiles/grid/collection-tile.test.d.ts +1 -0
  209. package/dist/test/tiles/grid/collection-tile.test.js +73 -0
  210. package/dist/test/tiles/grid/collection-tile.test.js.map +1 -0
  211. package/dist/test/tiles/grid/item-tile.test.d.ts +1 -1
  212. package/dist/test/tiles/grid/item-tile.test.js +142 -129
  213. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  214. package/dist/test/tiles/list/tile-list-compact.test.d.ts +1 -1
  215. package/dist/test/tiles/list/tile-list-compact.test.js +92 -92
  216. package/dist/test/tiles/list/tile-list.test.d.ts +1 -1
  217. package/dist/test/tiles/list/tile-list.test.js +123 -123
  218. package/dist/test/utils/format-count.test.d.ts +1 -1
  219. package/dist/test/utils/format-count.test.js +23 -23
  220. package/dist/test/utils/format-date.test.d.ts +1 -1
  221. package/dist/test/utils/format-date.test.js +17 -17
  222. package/dist/test/utils/format-unit-size.test.d.ts +1 -0
  223. package/dist/test/utils/format-unit-size.test.js +18 -0
  224. package/dist/test/utils/format-unit-size.test.js.map +1 -0
  225. package/index.html +24 -24
  226. package/local.archive.org.cert +86 -86
  227. package/local.archive.org.key +27 -27
  228. package/package.json +2 -2
  229. package/renovate.json +6 -6
  230. package/src/app-root.ts +214 -169
  231. package/src/collection-browser.ts +122 -3
  232. package/src/models.ts +2 -0
  233. package/src/styles/item-image-styles.ts +13 -3
  234. package/src/tiles/collection-browser-loading-tile.ts +1 -1
  235. package/src/tiles/grid/account-tile.ts +4 -2
  236. package/src/tiles/grid/collection-tile.ts +106 -136
  237. package/src/tiles/grid/item-tile.ts +8 -2
  238. package/src/tiles/grid/styles/tile-grid-shared-styles.ts +6 -2
  239. package/src/tiles/grid/tile-stats.ts +1 -0
  240. package/src/tiles/image-block.ts +5 -2
  241. package/src/tiles/item-image.ts +4 -3
  242. package/src/tiles/tile-dispatcher.ts +17 -0
  243. package/src/utils/format-unit-size.ts +43 -0
  244. package/test/item-image.test.ts +4 -0
  245. package/test/tiles/grid/collection-tile.test.ts +85 -0
  246. package/test/tiles/grid/item-tile.test.ts +30 -4
  247. package/test/utils/format-unit-size.test.ts +21 -0
  248. package/tsconfig.json +21 -21
  249. package/web-dev-server.config.mjs +30 -30
  250. package/web-test-runner.config.mjs +41 -41
@@ -1,693 +1,693 @@
1
- /* eslint-disable import/no-duplicates */
2
- import { expect, fixture } from '@open-wc/testing';
3
- import { html } from 'lit';
4
- import sinon from 'sinon';
5
- import { SearchType } from '@internetarchive/search-service';
6
- import '../src/collection-browser';
7
- import { defaultSelectedFacets, SortField, } from '../src/models';
8
- import { MockSearchService } from './mocks/mock-search-service';
9
- import { MockCollectionNameCache } from './mocks/mock-collection-name-cache';
10
- import { MockAnalyticsHandler } from './mocks/mock-analytics-handler';
11
- import { analyticsCategories } from '../src/utils/analytics-events';
12
- /**
13
- * Wait for the next tick of the event loop.
14
- *
15
- * This is necessary in some of the tests because certain collection browser
16
- * updates take more than one tick to render (e.g., date picker & query changes).
17
- * These delays are non-ideal and should eventually be investigated and fixed,
18
- * but they are minor enough that waiting for the next tick is a reasonable
19
- * testing solution for now.
20
- */
21
- const nextTick = () => new Promise(resolve => {
22
- setTimeout(resolve, 0);
23
- });
24
- describe('Collection Browser', () => {
25
- beforeEach(async () => {
26
- // Apparently query params set by one test can bleed into other tests.
27
- // Since collection browser restores its state from certain query params, we need
28
- // to clear these before each test to ensure they run in isolation from one another.
29
- const url = new URL(window.location.href);
30
- const { searchParams } = url;
31
- searchParams.delete('sin');
32
- searchParams.delete('sort');
33
- searchParams.delete('query');
34
- searchParams.delete('page');
35
- searchParams.delete('and[]');
36
- searchParams.delete('not[]');
37
- window.history.replaceState({}, '', url);
38
- });
39
- it('clear existing filter for facets & sort-bar', async () => {
40
- const el = await fixture(html `<collection-browser></collection-browser>`);
41
- el.selectedSort = 'title';
42
- await el.updateComplete;
43
- el.clearFilters();
44
- expect(el.selectedFacets).to.equal(defaultSelectedFacets);
45
- expect(el.selectedSort).to.equal('relevance');
46
- expect(el.sortDirection).to.null;
47
- expect(el.sortParam).to.null;
48
- expect(el.selectedCreatorFilter).to.null;
49
- expect(el.selectedTitleFilter).to.null;
50
- });
51
- it('filterBy creator with analytics', async () => {
52
- const mockAnalyticsHandler = new MockAnalyticsHandler();
1
+ /* eslint-disable import/no-duplicates */
2
+ import { expect, fixture } from '@open-wc/testing';
3
+ import { html } from 'lit';
4
+ import sinon from 'sinon';
5
+ import { SearchType } from '@internetarchive/search-service';
6
+ import '../src/collection-browser';
7
+ import { defaultSelectedFacets, SortField, } from '../src/models';
8
+ import { MockSearchService } from './mocks/mock-search-service';
9
+ import { MockCollectionNameCache } from './mocks/mock-collection-name-cache';
10
+ import { MockAnalyticsHandler } from './mocks/mock-analytics-handler';
11
+ import { analyticsCategories } from '../src/utils/analytics-events';
12
+ /**
13
+ * Wait for the next tick of the event loop.
14
+ *
15
+ * This is necessary in some of the tests because certain collection browser
16
+ * updates take more than one tick to render (e.g., date picker & query changes).
17
+ * These delays are non-ideal and should eventually be investigated and fixed,
18
+ * but they are minor enough that waiting for the next tick is a reasonable
19
+ * testing solution for now.
20
+ */
21
+ const nextTick = () => new Promise(resolve => {
22
+ setTimeout(resolve, 0);
23
+ });
24
+ describe('Collection Browser', () => {
25
+ beforeEach(async () => {
26
+ // Apparently query params set by one test can bleed into other tests.
27
+ // Since collection browser restores its state from certain query params, we need
28
+ // to clear these before each test to ensure they run in isolation from one another.
29
+ const url = new URL(window.location.href);
30
+ const { searchParams } = url;
31
+ searchParams.delete('sin');
32
+ searchParams.delete('sort');
33
+ searchParams.delete('query');
34
+ searchParams.delete('page');
35
+ searchParams.delete('and[]');
36
+ searchParams.delete('not[]');
37
+ window.history.replaceState({}, '', url);
38
+ });
39
+ it('clear existing filter for facets & sort-bar', async () => {
40
+ const el = await fixture(html `<collection-browser></collection-browser>`);
41
+ el.selectedSort = 'title';
42
+ await el.updateComplete;
43
+ el.clearFilters();
44
+ expect(el.selectedFacets).to.equal(defaultSelectedFacets);
45
+ expect(el.selectedSort).to.equal('relevance');
46
+ expect(el.sortDirection).to.null;
47
+ expect(el.sortParam).to.null;
48
+ expect(el.selectedCreatorFilter).to.null;
49
+ expect(el.selectedTitleFilter).to.null;
50
+ });
51
+ it('filterBy creator with analytics', async () => {
52
+ const mockAnalyticsHandler = new MockAnalyticsHandler();
53
53
  const el = await fixture(html `<collection-browser .analyticsHandler=${mockAnalyticsHandler}>
54
- </collection-browser>`);
55
- el.searchContext = 'betaSearchService';
56
- el.selectedSort = 'creator';
57
- el.sortDirection = 'asc';
58
- el.selectedCreatorFilter = 'A';
59
- await el.updateComplete;
60
- expect(mockAnalyticsHandler.callCategory).to.equal('betaSearchService');
61
- expect(mockAnalyticsHandler.callAction).to.equal('filterByCreator');
62
- expect(mockAnalyticsHandler.callLabel).to.equal('start-A');
63
- el.clearFilters();
64
- await el.updateComplete;
65
- expect(el.selectedTitleFilter).to.null;
66
- expect(mockAnalyticsHandler.callCategory).to.equal('betaSearchService');
67
- expect(mockAnalyticsHandler.callAction).to.equal('filterByCreator');
68
- expect(mockAnalyticsHandler.callLabel).to.equal('clear-A');
69
- });
70
- it('filterBy title with analytics', async () => {
71
- const mockAnalyticsHandler = new MockAnalyticsHandler();
54
+ </collection-browser>`);
55
+ el.searchContext = 'betaSearchService';
56
+ el.selectedSort = 'creator';
57
+ el.sortDirection = 'asc';
58
+ el.selectedCreatorFilter = 'A';
59
+ await el.updateComplete;
60
+ expect(mockAnalyticsHandler.callCategory).to.equal('betaSearchService');
61
+ expect(mockAnalyticsHandler.callAction).to.equal('filterByCreator');
62
+ expect(mockAnalyticsHandler.callLabel).to.equal('start-A');
63
+ el.clearFilters();
64
+ await el.updateComplete;
65
+ expect(el.selectedTitleFilter).to.null;
66
+ expect(mockAnalyticsHandler.callCategory).to.equal('betaSearchService');
67
+ expect(mockAnalyticsHandler.callAction).to.equal('filterByCreator');
68
+ expect(mockAnalyticsHandler.callLabel).to.equal('clear-A');
69
+ });
70
+ it('filterBy title with analytics', async () => {
71
+ const mockAnalyticsHandler = new MockAnalyticsHandler();
72
72
  const el = await fixture(html `<collection-browser .analyticsHandler=${mockAnalyticsHandler}>
73
- </collection-browser>`);
74
- el.searchContext = 'beta-search-service';
75
- el.selectedSort = 'title';
76
- el.sortDirection = 'asc';
77
- el.selectedTitleFilter = 'A';
78
- await el.updateComplete;
79
- expect(mockAnalyticsHandler.callCategory).to.equal('beta-search-service');
80
- expect(mockAnalyticsHandler.callAction).to.equal('filterByTitle');
81
- expect(mockAnalyticsHandler.callLabel).to.equal('start-A');
82
- el.clearFilters();
83
- await el.updateComplete;
84
- expect(el.selectedTitleFilter).to.null;
85
- expect(mockAnalyticsHandler.callCategory).to.equal('beta-search-service');
86
- expect(mockAnalyticsHandler.callAction).to.equal('filterByTitle');
87
- expect(mockAnalyticsHandler.callLabel).to.equal('clear-A');
88
- });
89
- it('selected facets with analytics - not negative facets', async () => {
90
- const mockAnalyticsHandler = new MockAnalyticsHandler();
91
- const mediaTypeBucket = { count: 123, state: 'selected' };
92
- const mockedSelectedFacets = {
93
- subject: {},
94
- lending: {},
95
- mediatype: { data: mediaTypeBucket },
96
- language: {},
97
- creator: {},
98
- collection: {},
99
- year: {},
100
- };
73
+ </collection-browser>`);
74
+ el.searchContext = 'beta-search-service';
75
+ el.selectedSort = 'title';
76
+ el.sortDirection = 'asc';
77
+ el.selectedTitleFilter = 'A';
78
+ await el.updateComplete;
79
+ expect(mockAnalyticsHandler.callCategory).to.equal('beta-search-service');
80
+ expect(mockAnalyticsHandler.callAction).to.equal('filterByTitle');
81
+ expect(mockAnalyticsHandler.callLabel).to.equal('start-A');
82
+ el.clearFilters();
83
+ await el.updateComplete;
84
+ expect(el.selectedTitleFilter).to.null;
85
+ expect(mockAnalyticsHandler.callCategory).to.equal('beta-search-service');
86
+ expect(mockAnalyticsHandler.callAction).to.equal('filterByTitle');
87
+ expect(mockAnalyticsHandler.callLabel).to.equal('clear-A');
88
+ });
89
+ it('selected facets with analytics - not negative facets', async () => {
90
+ const mockAnalyticsHandler = new MockAnalyticsHandler();
91
+ const mediaTypeBucket = { count: 123, state: 'selected' };
92
+ const mockedSelectedFacets = {
93
+ subject: {},
94
+ lending: {},
95
+ mediatype: { data: mediaTypeBucket },
96
+ language: {},
97
+ creator: {},
98
+ collection: {},
99
+ year: {},
100
+ };
101
101
  const el = await fixture(html `<collection-browser .analyticsHandler=${mockAnalyticsHandler}>
102
- </collection-browser>`);
103
- el.searchContext = 'search-service';
104
- el.selectedFacets = mockedSelectedFacets;
105
- await el.updateComplete;
106
- el.facetClickHandler('mediatype', true, false);
107
- expect(mockAnalyticsHandler.callCategory).to.equal('search-service');
108
- expect(mockAnalyticsHandler.callAction).to.equal('facetSelected');
109
- expect(mockAnalyticsHandler.callLabel).to.equal('mediatype');
110
- el.facetClickHandler('mediatype', false, false);
111
- expect(el.selectedFacets).to.equal(mockedSelectedFacets);
112
- expect(mockAnalyticsHandler.callCategory).to.equal('search-service');
113
- expect(mockAnalyticsHandler.callAction).to.equal('facetDeselected');
114
- expect(mockAnalyticsHandler.callLabel).to.equal('mediatype');
115
- });
116
- it('selected facets with analytics - negative facets', async () => {
117
- const mockAnalyticsHandler = new MockAnalyticsHandler();
118
- const mediaTypeBucket = { count: 123, state: 'selected' };
119
- const mockedSelectedFacets = {
120
- subject: {},
121
- lending: {},
122
- mediatype: { data: mediaTypeBucket },
123
- language: {},
124
- creator: {},
125
- collection: {},
126
- year: {},
127
- };
102
+ </collection-browser>`);
103
+ el.searchContext = 'search-service';
104
+ el.selectedFacets = mockedSelectedFacets;
105
+ await el.updateComplete;
106
+ el.facetClickHandler('mediatype', true, false);
107
+ expect(mockAnalyticsHandler.callCategory).to.equal('search-service');
108
+ expect(mockAnalyticsHandler.callAction).to.equal('facetSelected');
109
+ expect(mockAnalyticsHandler.callLabel).to.equal('mediatype');
110
+ el.facetClickHandler('mediatype', false, false);
111
+ expect(el.selectedFacets).to.equal(mockedSelectedFacets);
112
+ expect(mockAnalyticsHandler.callCategory).to.equal('search-service');
113
+ expect(mockAnalyticsHandler.callAction).to.equal('facetDeselected');
114
+ expect(mockAnalyticsHandler.callLabel).to.equal('mediatype');
115
+ });
116
+ it('selected facets with analytics - negative facets', async () => {
117
+ const mockAnalyticsHandler = new MockAnalyticsHandler();
118
+ const mediaTypeBucket = { count: 123, state: 'selected' };
119
+ const mockedSelectedFacets = {
120
+ subject: {},
121
+ lending: {},
122
+ mediatype: { data: mediaTypeBucket },
123
+ language: {},
124
+ creator: {},
125
+ collection: {},
126
+ year: {},
127
+ };
128
128
  const el = await fixture(html `<collection-browser .analyticsHandler=${mockAnalyticsHandler}>
129
- </collection-browser>`);
130
- el.searchContext = 'beta-search-service';
131
- el.selectedFacets = mockedSelectedFacets;
132
- await el.updateComplete;
133
- el.facetClickHandler('mediatype', true, true);
134
- expect(mockAnalyticsHandler.callCategory).to.equal('beta-search-service');
135
- expect(mockAnalyticsHandler.callAction).to.equal('facetNegativeSelected');
136
- expect(mockAnalyticsHandler.callLabel).to.equal('mediatype');
137
- el.facetClickHandler('mediatype', false, true);
138
- expect(el.selectedFacets).to.equal(mockedSelectedFacets);
139
- expect(mockAnalyticsHandler.callCategory).to.equal('beta-search-service');
140
- expect(mockAnalyticsHandler.callAction).to.equal('facetNegativeDeselected');
141
- expect(mockAnalyticsHandler.callLabel).to.equal('mediatype');
142
- });
143
- it('should render with a sort bar, facets, and infinite scroller', async () => {
144
- var _a, _b, _c;
145
- const searchService = new MockSearchService();
129
+ </collection-browser>`);
130
+ el.searchContext = 'beta-search-service';
131
+ el.selectedFacets = mockedSelectedFacets;
132
+ await el.updateComplete;
133
+ el.facetClickHandler('mediatype', true, true);
134
+ expect(mockAnalyticsHandler.callCategory).to.equal('beta-search-service');
135
+ expect(mockAnalyticsHandler.callAction).to.equal('facetNegativeSelected');
136
+ expect(mockAnalyticsHandler.callLabel).to.equal('mediatype');
137
+ el.facetClickHandler('mediatype', false, true);
138
+ expect(el.selectedFacets).to.equal(mockedSelectedFacets);
139
+ expect(mockAnalyticsHandler.callCategory).to.equal('beta-search-service');
140
+ expect(mockAnalyticsHandler.callAction).to.equal('facetNegativeDeselected');
141
+ expect(mockAnalyticsHandler.callLabel).to.equal('mediatype');
142
+ });
143
+ it('should render with a sort bar, facets, and infinite scroller', async () => {
144
+ var _a, _b, _c;
145
+ const searchService = new MockSearchService();
146
146
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
147
- </collection-browser>`);
148
- el.baseQuery = 'hello';
149
- await el.updateComplete;
150
- const facets = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('collection-facets');
151
- const sortBar = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('sort-filter-bar');
152
- const infiniteScroller = (_c = el.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('infinite-scroller');
153
- expect(facets).to.exist;
154
- expect(sortBar).to.exist;
155
- expect(infiniteScroller).to.exist;
156
- });
157
- it('queries the search service when given a base query', async () => {
158
- var _a, _b, _c;
159
- const searchService = new MockSearchService();
147
+ </collection-browser>`);
148
+ el.baseQuery = 'hello';
149
+ await el.updateComplete;
150
+ const facets = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('collection-facets');
151
+ const sortBar = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('sort-filter-bar');
152
+ const infiniteScroller = (_c = el.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('infinite-scroller');
153
+ expect(facets).to.exist;
154
+ expect(sortBar).to.exist;
155
+ expect(infiniteScroller).to.exist;
156
+ });
157
+ it('queries the search service when given a base query', async () => {
158
+ var _a, _b, _c;
159
+ const searchService = new MockSearchService();
160
160
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
161
- </collection-browser>`);
162
- el.baseQuery = 'collection:foo';
163
- await el.updateComplete;
164
- await nextTick();
165
- expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('collection:foo');
166
- expect((_c = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#big-results-label')) === null || _c === void 0 ? void 0 : _c.textContent).to.contains('Results');
167
- });
168
- it('queries the search service with a metadata search', async () => {
169
- var _a, _b, _c;
170
- const searchService = new MockSearchService();
161
+ </collection-browser>`);
162
+ el.baseQuery = 'collection:foo';
163
+ await el.updateComplete;
164
+ await nextTick();
165
+ expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('collection:foo');
166
+ expect((_c = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#big-results-label')) === null || _c === void 0 ? void 0 : _c.textContent).to.contains('Results');
167
+ });
168
+ it('queries the search service with a metadata search', async () => {
169
+ var _a, _b, _c;
170
+ const searchService = new MockSearchService();
171
171
  const el = await fixture(html ` <collection-browser
172
172
  .searchService=${searchService}
173
173
  .searchType=${SearchType.METADATA}
174
174
  >
175
- </collection-browser>`);
176
- el.baseQuery = 'collection:foo';
177
- await el.updateComplete;
178
- await nextTick();
179
- expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('collection:foo');
180
- expect(searchService.searchType).to.equal(SearchType.METADATA);
181
- expect((_c = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#big-results-label')) === null || _c === void 0 ? void 0 : _c.textContent).to.contains('Results');
182
- });
183
- it('queries the search service with a fulltext search', async () => {
184
- var _a, _b, _c;
185
- const searchService = new MockSearchService();
175
+ </collection-browser>`);
176
+ el.baseQuery = 'collection:foo';
177
+ await el.updateComplete;
178
+ await nextTick();
179
+ expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('collection:foo');
180
+ expect(searchService.searchType).to.equal(SearchType.METADATA);
181
+ expect((_c = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#big-results-label')) === null || _c === void 0 ? void 0 : _c.textContent).to.contains('Results');
182
+ });
183
+ it('queries the search service with a fulltext search', async () => {
184
+ var _a, _b, _c;
185
+ const searchService = new MockSearchService();
186
186
  const el = await fixture(html ` <collection-browser
187
187
  .searchService=${searchService}
188
188
  .searchType=${SearchType.FULLTEXT}
189
189
  >
190
- </collection-browser>`);
191
- el.baseQuery = 'collection:foo';
192
- await el.updateComplete;
193
- await nextTick();
194
- expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('collection:foo');
195
- expect(searchService.searchType).to.equal(SearchType.FULLTEXT);
196
- expect((_c = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#big-results-label')) === null || _c === void 0 ? void 0 : _c.textContent).to.contains('Results');
197
- });
198
- it('queries the search service with facets selected/negated', async () => {
199
- var _a, _b;
200
- const searchService = new MockSearchService();
201
- const selectedFacets = {
202
- subject: {
203
- foo: {
204
- key: 'foo',
205
- count: 1,
206
- state: 'selected',
207
- },
208
- bar: {
209
- key: 'bar',
210
- count: 2,
211
- state: 'hidden',
212
- },
213
- },
214
- lending: {},
215
- mediatype: {},
216
- language: {
217
- en: {
218
- key: 'en',
219
- count: 1,
220
- state: 'selected',
221
- },
222
- },
223
- creator: {},
224
- collection: {},
225
- year: {},
226
- };
190
+ </collection-browser>`);
191
+ el.baseQuery = 'collection:foo';
192
+ await el.updateComplete;
193
+ await nextTick();
194
+ expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('collection:foo');
195
+ expect(searchService.searchType).to.equal(SearchType.FULLTEXT);
196
+ expect((_c = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#big-results-label')) === null || _c === void 0 ? void 0 : _c.textContent).to.contains('Results');
197
+ });
198
+ it('queries the search service with facets selected/negated', async () => {
199
+ var _a, _b;
200
+ const searchService = new MockSearchService();
201
+ const selectedFacets = {
202
+ subject: {
203
+ foo: {
204
+ key: 'foo',
205
+ count: 1,
206
+ state: 'selected',
207
+ },
208
+ bar: {
209
+ key: 'bar',
210
+ count: 2,
211
+ state: 'hidden',
212
+ },
213
+ },
214
+ lending: {},
215
+ mediatype: {},
216
+ language: {
217
+ en: {
218
+ key: 'en',
219
+ count: 1,
220
+ state: 'selected',
221
+ },
222
+ },
223
+ creator: {},
224
+ collection: {},
225
+ year: {},
226
+ };
227
227
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
228
- </collection-browser>`);
229
- el.baseQuery = 'collection:foo';
230
- el.selectedFacets = selectedFacets;
231
- await el.updateComplete;
232
- expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('collection:foo');
233
- expect((_b = searchService.searchParams) === null || _b === void 0 ? void 0 : _b.filters).to.deep.equal({
234
- subject: {
235
- foo: 'inc',
236
- bar: 'exc',
237
- },
238
- language: {
239
- en: 'inc',
240
- },
241
- });
242
- });
243
- it('fires a separate date histogram query when year facets are applied', async () => {
244
- var _a, _b, _c;
245
- const searchService = new MockSearchService();
246
- const selectedFacets = {
247
- subject: {},
248
- lending: {},
249
- mediatype: {},
250
- language: {},
251
- creator: {},
252
- collection: {},
253
- year: {
254
- '2000': {
255
- key: '2000',
256
- state: 'selected',
257
- count: 123,
258
- },
259
- },
260
- };
228
+ </collection-browser>`);
229
+ el.baseQuery = 'collection:foo';
230
+ el.selectedFacets = selectedFacets;
231
+ await el.updateComplete;
232
+ expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('collection:foo');
233
+ expect((_b = searchService.searchParams) === null || _b === void 0 ? void 0 : _b.filters).to.deep.equal({
234
+ subject: {
235
+ foo: 'inc',
236
+ bar: 'exc',
237
+ },
238
+ language: {
239
+ en: 'inc',
240
+ },
241
+ });
242
+ });
243
+ it('fires a separate date histogram query when year facets are applied', async () => {
244
+ var _a, _b, _c;
245
+ const searchService = new MockSearchService();
246
+ const selectedFacets = {
247
+ subject: {},
248
+ lending: {},
249
+ mediatype: {},
250
+ language: {},
251
+ creator: {},
252
+ collection: {},
253
+ year: {
254
+ '2000': {
255
+ key: '2000',
256
+ state: 'selected',
257
+ count: 123,
258
+ },
259
+ },
260
+ };
261
261
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
262
- </collection-browser>`);
263
- el.baseQuery = 'collection:foo';
264
- el.showHistogramDatePicker = true;
265
- el.selectedFacets = selectedFacets;
266
- await el.updateComplete;
267
- expect((_b = (_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.aggregations) === null || _b === void 0 ? void 0 : _b.simpleParams).to.deep.equal(['year']); // Explicitly requests year aggregations
268
- expect((_c = searchService.searchParams) === null || _c === void 0 ? void 0 : _c.query).to.equal('collection:foo' // No date clause on query
269
- );
270
- });
271
- it('fires a separate date histogram query when a date range is applied', async () => {
272
- var _a, _b, _c;
273
- const searchService = new MockSearchService();
262
+ </collection-browser>`);
263
+ el.baseQuery = 'collection:foo';
264
+ el.showHistogramDatePicker = true;
265
+ el.selectedFacets = selectedFacets;
266
+ await el.updateComplete;
267
+ expect((_b = (_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.aggregations) === null || _b === void 0 ? void 0 : _b.simpleParams).to.deep.equal(['year']); // Explicitly requests year aggregations
268
+ expect((_c = searchService.searchParams) === null || _c === void 0 ? void 0 : _c.query).to.equal('collection:foo' // No date clause on query
269
+ );
270
+ });
271
+ it('fires a separate date histogram query when a date range is applied', async () => {
272
+ var _a, _b, _c;
273
+ const searchService = new MockSearchService();
274
274
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
275
- </collection-browser>`);
276
- el.baseQuery = 'collection:foo';
277
- el.showHistogramDatePicker = true;
278
- el.minSelectedDate = '1995';
279
- el.maxSelectedDate = '2005';
280
- await el.updateComplete;
281
- expect((_b = (_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.aggregations) === null || _b === void 0 ? void 0 : _b.simpleParams).to.deep.equal(['year']); // Explicitly requests year aggregations
282
- expect((_c = searchService.searchParams) === null || _c === void 0 ? void 0 : _c.query).to.equal('collection:foo' // No date clause on query
283
- );
284
- });
285
- it('does not fire a separate date histogram query when no date filters are applied', async () => {
286
- var _a, _b;
287
- const searchService = new MockSearchService();
275
+ </collection-browser>`);
276
+ el.baseQuery = 'collection:foo';
277
+ el.showHistogramDatePicker = true;
278
+ el.minSelectedDate = '1995';
279
+ el.maxSelectedDate = '2005';
280
+ await el.updateComplete;
281
+ expect((_b = (_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.aggregations) === null || _b === void 0 ? void 0 : _b.simpleParams).to.deep.equal(['year']); // Explicitly requests year aggregations
282
+ expect((_c = searchService.searchParams) === null || _c === void 0 ? void 0 : _c.query).to.equal('collection:foo' // No date clause on query
283
+ );
284
+ });
285
+ it('does not fire a separate date histogram query when no date filters are applied', async () => {
286
+ var _a, _b;
287
+ const searchService = new MockSearchService();
288
288
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
289
- </collection-browser>`);
290
- el.baseQuery = 'collection:foo';
291
- el.showHistogramDatePicker = true;
292
- await el.updateComplete;
293
- expect((_b = (_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.aggregations) === null || _b === void 0 ? void 0 : _b.simpleParams).to.satisfy((aggTypes) => !aggTypes || !aggTypes.includes('year') // Not requesting year aggregations explicitly
294
- );
295
- });
296
- it('does not fire a separate date histogram query when date picker is disabled', async () => {
297
- var _a, _b;
298
- const searchService = new MockSearchService();
289
+ </collection-browser>`);
290
+ el.baseQuery = 'collection:foo';
291
+ el.showHistogramDatePicker = true;
292
+ await el.updateComplete;
293
+ expect((_b = (_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.aggregations) === null || _b === void 0 ? void 0 : _b.simpleParams).to.satisfy((aggTypes) => !aggTypes || !aggTypes.includes('year') // Not requesting year aggregations explicitly
294
+ );
295
+ });
296
+ it('does not fire a separate date histogram query when date picker is disabled', async () => {
297
+ var _a, _b;
298
+ const searchService = new MockSearchService();
299
299
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
300
- </collection-browser>`);
301
- el.baseQuery = 'collection:foo';
302
- el.showHistogramDatePicker = false;
303
- el.minSelectedDate = '1995';
304
- el.maxSelectedDate = '2005';
305
- await el.updateComplete;
306
- expect((_b = (_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.aggregations) === null || _b === void 0 ? void 0 : _b.simpleParams).to.satisfy((aggTypes) => !aggTypes || !aggTypes.includes('year') // Not requesting year aggregations explicitly
307
- );
308
- });
309
- it('fails gracefully if no search service provided', async () => {
310
- var _a;
311
- const el = await fixture(html `<collection-browser></collection-browser>`);
312
- el.baseQuery = 'collection:foo';
313
- await el.updateComplete;
314
- // This shouldn't throw an error
315
- expect(el.fetchPage(2)).to.exist;
316
- // Should continue showing the empty placeholder
317
- expect((_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('empty-placeholder')).to.exist;
318
- });
319
- it('restores search type from URL param', async () => {
320
- // Add a sin=TXT param to the URL
321
- const url = new URL(window.location.href);
322
- url.searchParams.append('sin', 'TXT');
323
- window.history.replaceState({}, '', url);
324
- const searchService = new MockSearchService();
300
+ </collection-browser>`);
301
+ el.baseQuery = 'collection:foo';
302
+ el.showHistogramDatePicker = false;
303
+ el.minSelectedDate = '1995';
304
+ el.maxSelectedDate = '2005';
305
+ await el.updateComplete;
306
+ expect((_b = (_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.aggregations) === null || _b === void 0 ? void 0 : _b.simpleParams).to.satisfy((aggTypes) => !aggTypes || !aggTypes.includes('year') // Not requesting year aggregations explicitly
307
+ );
308
+ });
309
+ it('fails gracefully if no search service provided', async () => {
310
+ var _a;
311
+ const el = await fixture(html `<collection-browser></collection-browser>`);
312
+ el.baseQuery = 'collection:foo';
313
+ await el.updateComplete;
314
+ // This shouldn't throw an error
315
+ expect(el.fetchPage(2)).to.exist;
316
+ // Should continue showing the empty placeholder
317
+ expect((_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('empty-placeholder')).to.exist;
318
+ });
319
+ it('restores search type from URL param', async () => {
320
+ // Add a sin=TXT param to the URL
321
+ const url = new URL(window.location.href);
322
+ url.searchParams.append('sin', 'TXT');
323
+ window.history.replaceState({}, '', url);
324
+ const searchService = new MockSearchService();
325
325
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
326
- </collection-browser>`);
327
- expect(el.searchType).to.equal(SearchType.FULLTEXT);
328
- });
329
- it('applies loggedin flag to tile models if needed', async () => {
330
- var _a;
331
- const searchService = new MockSearchService();
326
+ </collection-browser>`);
327
+ expect(el.searchType).to.equal(SearchType.FULLTEXT);
328
+ });
329
+ it('applies loggedin flag to tile models if needed', async () => {
330
+ var _a;
331
+ const searchService = new MockSearchService();
332
332
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
333
- </collection-browser>`);
334
- el.baseQuery = 'loggedin';
335
- await el.updateComplete;
336
- const cellTemplate = el.cellForIndex(0);
337
- expect(cellTemplate).to.exist;
338
- const cell = await fixture(cellTemplate);
339
- expect(cell).to.exist;
340
- expect((_a = cell.model) === null || _a === void 0 ? void 0 : _a.loginRequired).to.be.true;
341
- });
342
- it('applies no-preview flag to tile models if needed', async () => {
343
- var _a;
344
- const searchService = new MockSearchService();
333
+ </collection-browser>`);
334
+ el.baseQuery = 'loggedin';
335
+ await el.updateComplete;
336
+ const cellTemplate = el.cellForIndex(0);
337
+ expect(cellTemplate).to.exist;
338
+ const cell = await fixture(cellTemplate);
339
+ expect(cell).to.exist;
340
+ expect((_a = cell.model) === null || _a === void 0 ? void 0 : _a.loginRequired).to.be.true;
341
+ });
342
+ it('applies no-preview flag to tile models if needed', async () => {
343
+ var _a;
344
+ const searchService = new MockSearchService();
345
345
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
346
- </collection-browser>`);
347
- el.baseQuery = 'no-preview';
348
- await el.updateComplete;
349
- const cellTemplate = el.cellForIndex(0);
350
- expect(cellTemplate).to.exist;
351
- const cell = await fixture(cellTemplate);
352
- expect(cell).to.exist;
353
- expect((_a = cell.model) === null || _a === void 0 ? void 0 : _a.contentWarning).to.be.true;
354
- });
355
- it('both loggedin and no-preview flags can be set simultaneously', async () => {
356
- var _a, _b;
357
- const searchService = new MockSearchService();
346
+ </collection-browser>`);
347
+ el.baseQuery = 'no-preview';
348
+ await el.updateComplete;
349
+ const cellTemplate = el.cellForIndex(0);
350
+ expect(cellTemplate).to.exist;
351
+ const cell = await fixture(cellTemplate);
352
+ expect(cell).to.exist;
353
+ expect((_a = cell.model) === null || _a === void 0 ? void 0 : _a.contentWarning).to.be.true;
354
+ });
355
+ it('both loggedin and no-preview flags can be set simultaneously', async () => {
356
+ var _a, _b;
357
+ const searchService = new MockSearchService();
358
358
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
359
- </collection-browser>`);
360
- el.baseQuery = 'loggedin-no-preview';
361
- await el.updateComplete;
362
- const cellTemplate = el.cellForIndex(0);
363
- expect(cellTemplate).to.exist;
364
- const cell = await fixture(cellTemplate);
365
- expect(cell).to.exist;
366
- expect((_a = cell.model) === null || _a === void 0 ? void 0 : _a.loginRequired).to.be.true;
367
- expect((_b = cell.model) === null || _b === void 0 ? void 0 : _b.contentWarning).to.be.true;
368
- });
369
- it('joins full description array into a single string with line breaks', async () => {
370
- var _a;
371
- const searchService = new MockSearchService();
359
+ </collection-browser>`);
360
+ el.baseQuery = 'loggedin-no-preview';
361
+ await el.updateComplete;
362
+ const cellTemplate = el.cellForIndex(0);
363
+ expect(cellTemplate).to.exist;
364
+ const cell = await fixture(cellTemplate);
365
+ expect(cell).to.exist;
366
+ expect((_a = cell.model) === null || _a === void 0 ? void 0 : _a.loginRequired).to.be.true;
367
+ expect((_b = cell.model) === null || _b === void 0 ? void 0 : _b.contentWarning).to.be.true;
368
+ });
369
+ it('joins full description array into a single string with line breaks', async () => {
370
+ var _a;
371
+ const searchService = new MockSearchService();
372
372
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
373
- </collection-browser>`);
374
- // This query receives an array description like ['line1', 'line2']
375
- el.baseQuery = 'multi-line-description';
376
- await el.updateComplete;
377
- const cellTemplate = el.cellForIndex(0);
378
- expect(cellTemplate).to.exist;
379
- const cell = await fixture(cellTemplate);
380
- expect(cell).to.exist;
381
- // Actual model description should be joined
382
- expect((_a = cell.model) === null || _a === void 0 ? void 0 : _a.description).to.equal('line1\nline2');
383
- });
384
- it('can search on demand if only search type has changed', async () => {
385
- const searchService = new MockSearchService();
373
+ </collection-browser>`);
374
+ // This query receives an array description like ['line1', 'line2']
375
+ el.baseQuery = 'multi-line-description';
376
+ await el.updateComplete;
377
+ const cellTemplate = el.cellForIndex(0);
378
+ expect(cellTemplate).to.exist;
379
+ const cell = await fixture(cellTemplate);
380
+ expect(cell).to.exist;
381
+ // Actual model description should be joined
382
+ expect((_a = cell.model) === null || _a === void 0 ? void 0 : _a.description).to.equal('line1\nline2');
383
+ });
384
+ it('can search on demand if only search type has changed', async () => {
385
+ const searchService = new MockSearchService();
386
386
  const el = await fixture(html `<collection-browser
387
387
  .searchService=${searchService}
388
388
  .searchType=${SearchType.METADATA}
389
- ></collection-browser>`);
390
- el.baseQuery = 'collection:foo';
391
- await el.updateComplete;
392
- el.searchType = SearchType.FULLTEXT;
393
- await el.updateComplete;
394
- // Haven't performed the search yet
395
- expect(searchService.searchType).to.equal(SearchType.METADATA);
396
- el.requestSearch();
397
- expect(searchService.searchType).to.equal(SearchType.FULLTEXT);
398
- });
399
- it('queries for collection names after a fetch', async () => {
400
- const searchService = new MockSearchService();
401
- const collectionNameCache = new MockCollectionNameCache();
389
+ ></collection-browser>`);
390
+ el.baseQuery = 'collection:foo';
391
+ await el.updateComplete;
392
+ el.searchType = SearchType.FULLTEXT;
393
+ await el.updateComplete;
394
+ // Haven't performed the search yet
395
+ expect(searchService.searchType).to.equal(SearchType.METADATA);
396
+ el.requestSearch();
397
+ expect(searchService.searchType).to.equal(SearchType.FULLTEXT);
398
+ });
399
+ it('queries for collection names after a fetch', async () => {
400
+ const searchService = new MockSearchService();
401
+ const collectionNameCache = new MockCollectionNameCache();
402
402
  const el = await fixture(html `<collection-browser
403
403
  .searchService=${searchService}
404
404
  .collectionNameCache=${collectionNameCache}
405
405
  >
406
- </collection-browser>`);
407
- el.baseQuery = 'collection:foo';
408
- await el.updateComplete;
409
- expect(collectionNameCache.preloadIdentifiersRequested).to.deep.equal([
410
- 'foo',
411
- 'bar',
412
- 'baz',
413
- 'boop',
414
- ]);
415
- });
416
- it('keeps search results from fetch if no change to query or sort param', async () => {
417
- const resultsSpy = sinon.spy();
418
- const searchService = new MockSearchService({
419
- asyncResponse: true,
420
- resultsSpy,
421
- });
406
+ </collection-browser>`);
407
+ el.baseQuery = 'collection:foo';
408
+ await el.updateComplete;
409
+ expect(collectionNameCache.preloadIdentifiersRequested).to.deep.equal([
410
+ 'foo',
411
+ 'bar',
412
+ 'baz',
413
+ 'boop',
414
+ ]);
415
+ });
416
+ it('keeps search results from fetch if no change to query or sort param', async () => {
417
+ const resultsSpy = sinon.spy();
418
+ const searchService = new MockSearchService({
419
+ asyncResponse: true,
420
+ resultsSpy,
421
+ });
422
422
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
423
- </collection-browser>`);
424
- el.baseQuery = 'with-sort';
425
- el.sortParam = { field: 'foo', direction: 'asc' };
426
- await el.updateComplete;
427
- await el.fetchPage(2);
428
- // If there is no change to the query or sort param during the fetch, the results
429
- // should be read.
430
- expect(resultsSpy.callCount).to.be.greaterThanOrEqual(1);
431
- });
432
- it('discards obsolete search results if sort params changed before arrival', async () => {
433
- const resultsSpy = sinon.spy();
434
- const searchService = new MockSearchService({
435
- asyncResponse: true,
436
- resultsSpy,
437
- });
423
+ </collection-browser>`);
424
+ el.baseQuery = 'with-sort';
425
+ el.sortParam = { field: 'foo', direction: 'asc' };
426
+ await el.updateComplete;
427
+ await el.fetchPage(2);
428
+ // If there is no change to the query or sort param during the fetch, the results
429
+ // should be read.
430
+ expect(resultsSpy.callCount).to.be.greaterThanOrEqual(1);
431
+ });
432
+ it('discards obsolete search results if sort params changed before arrival', async () => {
433
+ const resultsSpy = sinon.spy();
434
+ const searchService = new MockSearchService({
435
+ asyncResponse: true,
436
+ resultsSpy,
437
+ });
438
438
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
439
- </collection-browser>`);
440
- el.baseQuery = 'with-sort';
441
- el.sortParam = { field: 'foo', direction: 'asc' };
442
- await el.updateComplete;
443
- const fetchPromise = el.fetchPage(2);
444
- el.sortParam = { field: 'foo', direction: 'desc' };
445
- await fetchPromise;
446
- // If the different sort param causes the results to be discarded,
447
- // the results array should never be read.
448
- expect(resultsSpy.callCount).to.equal(0);
449
- });
450
- it('discards obsolete search results if sort param added before arrival', async () => {
451
- const resultsSpy = sinon.spy();
452
- const searchService = new MockSearchService({
453
- asyncResponse: true,
454
- resultsSpy,
455
- });
439
+ </collection-browser>`);
440
+ el.baseQuery = 'with-sort';
441
+ el.sortParam = { field: 'foo', direction: 'asc' };
442
+ await el.updateComplete;
443
+ const fetchPromise = el.fetchPage(2);
444
+ el.sortParam = { field: 'foo', direction: 'desc' };
445
+ await fetchPromise;
446
+ // If the different sort param causes the results to be discarded,
447
+ // the results array should never be read.
448
+ expect(resultsSpy.callCount).to.equal(0);
449
+ });
450
+ it('discards obsolete search results if sort param added before arrival', async () => {
451
+ const resultsSpy = sinon.spy();
452
+ const searchService = new MockSearchService({
453
+ asyncResponse: true,
454
+ resultsSpy,
455
+ });
456
456
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
457
- </collection-browser>`);
458
- el.baseQuery = 'single-result';
459
- await el.updateComplete;
460
- const fetchPromise = el.fetchPage(2);
461
- el.sortParam = { field: 'foo', direction: 'asc' };
462
- await fetchPromise;
463
- // If the different sort param causes the results to be discarded,
464
- // the results array should never be read.
465
- expect(resultsSpy.callCount).to.equal(0);
466
- });
467
- it('discards obsolete search results if sort param cleared before arrival', async () => {
468
- const resultsSpy = sinon.spy();
469
- const searchService = new MockSearchService({
470
- asyncResponse: true,
471
- resultsSpy,
472
- });
457
+ </collection-browser>`);
458
+ el.baseQuery = 'single-result';
459
+ await el.updateComplete;
460
+ const fetchPromise = el.fetchPage(2);
461
+ el.sortParam = { field: 'foo', direction: 'asc' };
462
+ await fetchPromise;
463
+ // If the different sort param causes the results to be discarded,
464
+ // the results array should never be read.
465
+ expect(resultsSpy.callCount).to.equal(0);
466
+ });
467
+ it('discards obsolete search results if sort param cleared before arrival', async () => {
468
+ const resultsSpy = sinon.spy();
469
+ const searchService = new MockSearchService({
470
+ asyncResponse: true,
471
+ resultsSpy,
472
+ });
473
473
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
474
- </collection-browser>`);
475
- el.baseQuery = 'with-sort';
476
- await el.updateComplete;
477
- const fetchPromise = el.fetchPage(2);
478
- el.sortParam = null;
479
- await fetchPromise;
480
- // If the different sort param causes the results to be discarded,
481
- // the results array should never be read.
482
- expect(resultsSpy.callCount).to.equal(0);
483
- });
484
- it('sets sort properties when user changes sort', async () => {
485
- var _a, _b, _c, _d;
486
- const searchService = new MockSearchService();
474
+ </collection-browser>`);
475
+ el.baseQuery = 'with-sort';
476
+ await el.updateComplete;
477
+ const fetchPromise = el.fetchPage(2);
478
+ el.sortParam = null;
479
+ await fetchPromise;
480
+ // If the different sort param causes the results to be discarded,
481
+ // the results array should never be read.
482
+ expect(resultsSpy.callCount).to.equal(0);
483
+ });
484
+ it('sets sort properties when user changes sort', async () => {
485
+ var _a, _b, _c, _d;
486
+ const searchService = new MockSearchService();
487
487
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
488
- </collection-browser>`);
489
- expect(el.selectedSort).to.equal(SortField.relevance);
490
- el.baseQuery = 'foo';
491
- await el.updateComplete;
492
- const sortBar = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('sort-filter-bar');
493
- const sortSelector = (_b = sortBar === null || sortBar === void 0 ? void 0 : sortBar.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#desktop-sort-selector');
494
- expect(sortSelector).to.exist;
495
- // Click the title sorter
496
- (_d = (_c = [...sortSelector === null || sortSelector === void 0 ? void 0 : sortSelector.children] // tsc doesn't know children is iterable
497
- .find(child => { var _a; return ((_a = child.textContent) === null || _a === void 0 ? void 0 : _a.trim()) === 'Title'; })) === null || _c === void 0 ? void 0 : _c.querySelector('a[href]')) === null || _d === void 0 ? void 0 : _d.click();
498
- await el.updateComplete;
499
- expect(el.selectedSort).to.equal(SortField.title);
500
- });
501
- it('sets sort filter properties when user selects title filter', async () => {
502
- var _a;
503
- const searchService = new MockSearchService();
488
+ </collection-browser>`);
489
+ expect(el.selectedSort).to.equal(SortField.relevance);
490
+ el.baseQuery = 'foo';
491
+ await el.updateComplete;
492
+ const sortBar = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('sort-filter-bar');
493
+ const sortSelector = (_b = sortBar === null || sortBar === void 0 ? void 0 : sortBar.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#desktop-sort-selector');
494
+ expect(sortSelector).to.exist;
495
+ // Click the title sorter
496
+ (_d = (_c = [...sortSelector === null || sortSelector === void 0 ? void 0 : sortSelector.children] // tsc doesn't know children is iterable
497
+ .find(child => { var _a; return ((_a = child.textContent) === null || _a === void 0 ? void 0 : _a.trim()) === 'Title'; })) === null || _c === void 0 ? void 0 : _c.querySelector('a[href]')) === null || _d === void 0 ? void 0 : _d.click();
498
+ await el.updateComplete;
499
+ expect(el.selectedSort).to.equal(SortField.title);
500
+ });
501
+ it('sets sort filter properties when user selects title filter', async () => {
502
+ var _a;
503
+ const searchService = new MockSearchService();
504
504
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
505
- </collection-browser>`);
506
- el.baseQuery = 'first-title';
507
- el.selectedSort = 'title';
508
- el.sortDirection = 'asc';
509
- el.selectedTitleFilter = 'X';
510
- await el.updateComplete;
511
- // Wait an extra tick
512
- await new Promise(res => {
513
- setTimeout(res, 0);
514
- });
515
- expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('first-title AND firstTitle:X');
516
- });
517
- it('sets sort filter properties when user selects creator filter', async () => {
518
- var _a;
519
- const searchService = new MockSearchService();
505
+ </collection-browser>`);
506
+ el.baseQuery = 'first-title';
507
+ el.selectedSort = 'title';
508
+ el.sortDirection = 'asc';
509
+ el.selectedTitleFilter = 'X';
510
+ await el.updateComplete;
511
+ // Wait an extra tick
512
+ await new Promise(res => {
513
+ setTimeout(res, 0);
514
+ });
515
+ expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('first-title AND firstTitle:X');
516
+ });
517
+ it('sets sort filter properties when user selects creator filter', async () => {
518
+ var _a;
519
+ const searchService = new MockSearchService();
520
520
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
521
- </collection-browser>`);
522
- el.baseQuery = 'first-creator';
523
- el.selectedSort = 'creator';
524
- el.sortDirection = 'asc';
525
- el.selectedCreatorFilter = 'X';
526
- await el.updateComplete;
527
- // Wait an extra tick
528
- await new Promise(res => {
529
- setTimeout(res, 0);
530
- });
531
- expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('first-creator AND firstCreator:X');
532
- });
533
- it('sets sort filter properties simultaneous with facets and date range', async () => {
534
- var _a, _b;
535
- const searchService = new MockSearchService();
536
- const selectedFacets = {
537
- collection: { foo: { key: 'foo', state: 'selected', count: 1 } },
538
- creator: {},
539
- language: {},
540
- lending: {},
541
- mediatype: {},
542
- subject: {},
543
- year: {},
544
- };
521
+ </collection-browser>`);
522
+ el.baseQuery = 'first-creator';
523
+ el.selectedSort = 'creator';
524
+ el.sortDirection = 'asc';
525
+ el.selectedCreatorFilter = 'X';
526
+ await el.updateComplete;
527
+ // Wait an extra tick
528
+ await new Promise(res => {
529
+ setTimeout(res, 0);
530
+ });
531
+ expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('first-creator AND firstCreator:X');
532
+ });
533
+ it('sets sort filter properties simultaneous with facets and date range', async () => {
534
+ var _a, _b;
535
+ const searchService = new MockSearchService();
536
+ const selectedFacets = {
537
+ collection: { foo: { key: 'foo', state: 'selected', count: 1 } },
538
+ creator: {},
539
+ language: {},
540
+ lending: {},
541
+ mediatype: {},
542
+ subject: {},
543
+ year: {},
544
+ };
545
545
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
546
- </collection-browser>`);
547
- el.baseQuery = 'first-creator';
548
- el.selectedSort = 'creator';
549
- el.selectedFacets = selectedFacets;
550
- el.minSelectedDate = '1950';
551
- el.maxSelectedDate = '1970';
552
- el.sortDirection = 'asc';
553
- el.selectedCreatorFilter = 'X';
554
- await el.updateComplete;
555
- // Wait an extra tick
556
- await new Promise(res => {
557
- setTimeout(res, 0);
558
- });
559
- expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('first-creator AND firstCreator:X');
560
- expect((_b = searchService.searchParams) === null || _b === void 0 ? void 0 : _b.filters).to.deep.equal({
561
- collection: {
562
- foo: 'inc',
563
- },
564
- year: {
565
- '1950': 'gte',
566
- '1970': 'lte',
567
- },
568
- });
569
- });
570
- it('sets date range query when date picker selection changed', async () => {
571
- var _a, _b, _c;
572
- const searchService = new MockSearchService();
546
+ </collection-browser>`);
547
+ el.baseQuery = 'first-creator';
548
+ el.selectedSort = 'creator';
549
+ el.selectedFacets = selectedFacets;
550
+ el.minSelectedDate = '1950';
551
+ el.maxSelectedDate = '1970';
552
+ el.sortDirection = 'asc';
553
+ el.selectedCreatorFilter = 'X';
554
+ await el.updateComplete;
555
+ // Wait an extra tick
556
+ await new Promise(res => {
557
+ setTimeout(res, 0);
558
+ });
559
+ expect((_a = searchService.searchParams) === null || _a === void 0 ? void 0 : _a.query).to.equal('first-creator AND firstCreator:X');
560
+ expect((_b = searchService.searchParams) === null || _b === void 0 ? void 0 : _b.filters).to.deep.equal({
561
+ collection: {
562
+ foo: 'inc',
563
+ },
564
+ year: {
565
+ '1950': 'gte',
566
+ '1970': 'lte',
567
+ },
568
+ });
569
+ });
570
+ it('sets date range query when date picker selection changed', async () => {
571
+ var _a, _b, _c;
572
+ const searchService = new MockSearchService();
573
573
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
574
- </collection-browser>`);
575
- el.baseQuery = 'years'; // Includes year_histogram aggregation in response
576
- el.showHistogramDatePicker = true;
577
- await el.updateComplete;
578
- const facets = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('collection-facets');
579
- await (facets === null || facets === void 0 ? void 0 : facets.updateComplete);
580
- // Wait for the date picker to be rendered (which may take until the next tick)
581
- await new Promise(res => {
582
- setTimeout(res, 0);
583
- });
584
- const histogram = (_b = facets === null || facets === void 0 ? void 0 : facets.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('histogram-date-range');
585
- expect(histogram).to.exist;
586
- // Enter a new min date into the date picker
587
- const minDateInput = (_c = histogram.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('#date-min');
588
- const pressEnterEvent = new KeyboardEvent('keyup', {
589
- key: 'Enter',
590
- });
591
- minDateInput.value = '1960';
592
- minDateInput.dispatchEvent(pressEnterEvent);
593
- // Wait for the histogram's update delay
594
- await new Promise(res => {
595
- setTimeout(res, histogram.updateDelay + 50);
596
- });
597
- // Ensure that the histogram change propagated to the collection browser's
598
- // date query correctly.
599
- await el.updateComplete;
600
- expect(el.minSelectedDate).to.equal('1960');
601
- expect(el.maxSelectedDate).to.equal('2000');
602
- });
603
- it('scrolls to page', async () => {
604
- var _a;
605
- const searchService = new MockSearchService();
574
+ </collection-browser>`);
575
+ el.baseQuery = 'years'; // Includes year_histogram aggregation in response
576
+ el.showHistogramDatePicker = true;
577
+ await el.updateComplete;
578
+ const facets = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('collection-facets');
579
+ await (facets === null || facets === void 0 ? void 0 : facets.updateComplete);
580
+ // Wait for the date picker to be rendered (which may take until the next tick)
581
+ await new Promise(res => {
582
+ setTimeout(res, 0);
583
+ });
584
+ const histogram = (_b = facets === null || facets === void 0 ? void 0 : facets.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('histogram-date-range');
585
+ expect(histogram).to.exist;
586
+ // Enter a new min date into the date picker
587
+ const minDateInput = (_c = histogram.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('#date-min');
588
+ const pressEnterEvent = new KeyboardEvent('keyup', {
589
+ key: 'Enter',
590
+ });
591
+ minDateInput.value = '1960';
592
+ minDateInput.dispatchEvent(pressEnterEvent);
593
+ // Wait for the histogram's update delay
594
+ await new Promise(res => {
595
+ setTimeout(res, histogram.updateDelay + 50);
596
+ });
597
+ // Ensure that the histogram change propagated to the collection browser's
598
+ // date query correctly.
599
+ await el.updateComplete;
600
+ expect(el.minSelectedDate).to.equal('1960');
601
+ expect(el.maxSelectedDate).to.equal('2000');
602
+ });
603
+ it('scrolls to page', async () => {
604
+ var _a;
605
+ const searchService = new MockSearchService();
606
606
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
607
- </collection-browser>`);
608
- // Infinite scroller won't exist unless there's a base query
609
- el.baseQuery = 'collection:foo';
610
- await el.updateComplete;
611
- const infiniteScroller = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('infinite-scroller');
612
- expect(infiniteScroller).to.exist;
613
- const oldScrollToCell = infiniteScroller.scrollToCell;
614
- const spy = sinon.spy();
615
- infiniteScroller.scrollToCell = spy;
616
- el.goToPage(1);
617
- // Give it a second to scroll
618
- await new Promise(res => {
619
- setTimeout(res, 1000);
620
- });
621
- expect(spy.callCount).to.equal(1);
622
- infiniteScroller.scrollToCell = oldScrollToCell;
623
- });
624
- it('refreshes when certain properties change - with some analytics event sampling', async () => {
625
- var _a;
626
- const mockAnalyticsHandler = new MockAnalyticsHandler();
627
- const searchService = new MockSearchService();
628
- const collectionNameCache = new MockCollectionNameCache();
607
+ </collection-browser>`);
608
+ // Infinite scroller won't exist unless there's a base query
609
+ el.baseQuery = 'collection:foo';
610
+ await el.updateComplete;
611
+ const infiniteScroller = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('infinite-scroller');
612
+ expect(infiniteScroller).to.exist;
613
+ const oldScrollToCell = infiniteScroller.scrollToCell;
614
+ const spy = sinon.spy();
615
+ infiniteScroller.scrollToCell = spy;
616
+ el.goToPage(1);
617
+ // Give it a second to scroll
618
+ await new Promise(res => {
619
+ setTimeout(res, 1000);
620
+ });
621
+ expect(spy.callCount).to.equal(1);
622
+ infiniteScroller.scrollToCell = oldScrollToCell;
623
+ });
624
+ it('refreshes when certain properties change - with some analytics event sampling', async () => {
625
+ var _a;
626
+ const mockAnalyticsHandler = new MockAnalyticsHandler();
627
+ const searchService = new MockSearchService();
628
+ const collectionNameCache = new MockCollectionNameCache();
629
629
  const el = await fixture(html `<collection-browser
630
630
  .analyticsHandler=${mockAnalyticsHandler}
631
631
  .searchService=${searchService}
632
632
  .collectionNameCache=${collectionNameCache}
633
- ></collection-browser>`);
634
- const infiniteScrollerRefreshSpy = sinon.spy();
635
- // Infinite scroller won't exist unless there's a base query
636
- el.baseQuery = 'collection:foo';
637
- await el.updateComplete;
638
- const infiniteScroller = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('infinite-scroller');
639
- infiniteScroller.reload = infiniteScrollerRefreshSpy;
640
- expect(infiniteScrollerRefreshSpy.called).to.be.false;
641
- expect(infiniteScrollerRefreshSpy.callCount).to.equal(0);
642
- // testing: `loggedIn`
643
- el.loggedIn = true;
644
- await el.updateComplete;
645
- expect(infiniteScrollerRefreshSpy.called).to.be.true;
646
- expect(infiniteScrollerRefreshSpy.callCount).to.equal(1);
647
- el.loggedIn = false;
648
- await el.updateComplete;
649
- expect(infiniteScrollerRefreshSpy.callCount).to.equal(2);
650
- // testing: `displayMode`
651
- el.displayMode = 'list-compact';
652
- el.searchContext = 'beta-search';
653
- await el.updateComplete;
654
- expect(infiniteScrollerRefreshSpy.callCount).to.equal(3);
655
- expect(mockAnalyticsHandler.callCategory).to.equal('beta-search');
656
- expect(mockAnalyticsHandler.callAction).to.equal('displayMode');
657
- expect(mockAnalyticsHandler.callLabel).to.equal('list-compact');
658
- el.displayMode = 'list-detail';
659
- await el.updateComplete;
660
- expect(infiniteScrollerRefreshSpy.callCount).to.equal(4);
661
- expect(mockAnalyticsHandler.callCategory).to.equal('beta-search');
662
- expect(mockAnalyticsHandler.callAction).to.equal('displayMode');
663
- expect(mockAnalyticsHandler.callLabel).to.equal('list-detail');
664
- // testing: `baseNavigationUrl`
665
- el.baseNavigationUrl = 'https://funtestsite.com';
666
- await el.updateComplete;
667
- expect(infiniteScrollerRefreshSpy.callCount).to.equal(5);
668
- // testing: `baseImageUrl`
669
- el.baseImageUrl = 'https://funtestsiteforimages.com';
670
- await el.updateComplete;
671
- expect(infiniteScrollerRefreshSpy.callCount).to.equal(6);
672
- });
673
- it('query the search service for single result', async () => {
674
- var _a, _b;
675
- const searchService = new MockSearchService();
633
+ ></collection-browser>`);
634
+ const infiniteScrollerRefreshSpy = sinon.spy();
635
+ // Infinite scroller won't exist unless there's a base query
636
+ el.baseQuery = 'collection:foo';
637
+ await el.updateComplete;
638
+ const infiniteScroller = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('infinite-scroller');
639
+ infiniteScroller.reload = infiniteScrollerRefreshSpy;
640
+ expect(infiniteScrollerRefreshSpy.called).to.be.false;
641
+ expect(infiniteScrollerRefreshSpy.callCount).to.equal(0);
642
+ // testing: `loggedIn`
643
+ el.loggedIn = true;
644
+ await el.updateComplete;
645
+ expect(infiniteScrollerRefreshSpy.called).to.be.true;
646
+ expect(infiniteScrollerRefreshSpy.callCount).to.equal(1);
647
+ el.loggedIn = false;
648
+ await el.updateComplete;
649
+ expect(infiniteScrollerRefreshSpy.callCount).to.equal(2);
650
+ // testing: `displayMode`
651
+ el.displayMode = 'list-compact';
652
+ el.searchContext = 'beta-search';
653
+ await el.updateComplete;
654
+ expect(infiniteScrollerRefreshSpy.callCount).to.equal(3);
655
+ expect(mockAnalyticsHandler.callCategory).to.equal('beta-search');
656
+ expect(mockAnalyticsHandler.callAction).to.equal('displayMode');
657
+ expect(mockAnalyticsHandler.callLabel).to.equal('list-compact');
658
+ el.displayMode = 'list-detail';
659
+ await el.updateComplete;
660
+ expect(infiniteScrollerRefreshSpy.callCount).to.equal(4);
661
+ expect(mockAnalyticsHandler.callCategory).to.equal('beta-search');
662
+ expect(mockAnalyticsHandler.callAction).to.equal('displayMode');
663
+ expect(mockAnalyticsHandler.callLabel).to.equal('list-detail');
664
+ // testing: `baseNavigationUrl`
665
+ el.baseNavigationUrl = 'https://funtestsite.com';
666
+ await el.updateComplete;
667
+ expect(infiniteScrollerRefreshSpy.callCount).to.equal(5);
668
+ // testing: `baseImageUrl`
669
+ el.baseImageUrl = 'https://funtestsiteforimages.com';
670
+ await el.updateComplete;
671
+ expect(infiniteScrollerRefreshSpy.callCount).to.equal(6);
672
+ });
673
+ it('query the search service for single result', async () => {
674
+ var _a, _b;
675
+ const searchService = new MockSearchService();
676
676
  const el = await fixture(html `<collection-browser .searchService=${searchService}>
677
- </collection-browser>`);
678
- el.baseQuery = 'single-result';
679
- await el.updateComplete;
680
- await nextTick();
681
- expect((_b = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#big-results-label')) === null || _b === void 0 ? void 0 : _b.textContent).to.contains('Result');
682
- });
683
- it('`searchContext` prop helps describe where component is being used', async () => {
684
- const el = await fixture(html `<collection-browser></collection-browser>`);
685
- expect(el.searchContext).to.equal(analyticsCategories.default);
686
- el.searchContext = 'unicorn-search';
687
- await el.updateComplete;
688
- expect(el.searchContext).to.equal('unicorn-search');
689
- // property is reflected as attribute
690
- expect(el.getAttribute('searchcontext')).to.equal('unicorn-search');
691
- });
692
- });
677
+ </collection-browser>`);
678
+ el.baseQuery = 'single-result';
679
+ await el.updateComplete;
680
+ await nextTick();
681
+ expect((_b = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#big-results-label')) === null || _b === void 0 ? void 0 : _b.textContent).to.contains('Result');
682
+ });
683
+ it('`searchContext` prop helps describe where component is being used', async () => {
684
+ const el = await fixture(html `<collection-browser></collection-browser>`);
685
+ expect(el.searchContext).to.equal(analyticsCategories.default);
686
+ el.searchContext = 'unicorn-search';
687
+ await el.updateComplete;
688
+ expect(el.searchContext).to.equal('unicorn-search');
689
+ // property is reflected as attribute
690
+ expect(el.getAttribute('searchcontext')).to.equal('unicorn-search');
691
+ });
692
+ });
693
693
  //# sourceMappingURL=collection-browser.test.js.map