@internetarchive/bookreader 5.0.0-94 → 5.0.0-96

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 (167) hide show
  1. package/BookReader/BookReader.js +1 -1
  2. package/BookReader/hypothesis/LICENSE +50 -0
  3. package/BookReader/hypothesis/README.md +55 -0
  4. package/BookReader/hypothesis/build/boot.js +1 -0
  5. package/BookReader/hypothesis/build/manifest.json +20 -0
  6. package/BookReader/hypothesis/build/scripts/annotator.bundle.js +184 -0
  7. package/BookReader/hypothesis/build/scripts/annotator.bundle.js.map +1 -0
  8. package/BookReader/hypothesis/build/scripts/sidebar.bundle.js +798 -0
  9. package/BookReader/hypothesis/build/scripts/sidebar.bundle.js.map +1 -0
  10. package/BookReader/hypothesis/build/scripts/ui-playground.bundle.js +711 -0
  11. package/BookReader/hypothesis/build/scripts/ui-playground.bundle.js.map +1 -0
  12. package/BookReader/hypothesis/build/styles/annotator.css +2235 -0
  13. package/BookReader/hypothesis/build/styles/annotator.css.map +1 -0
  14. package/BookReader/hypothesis/build/styles/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  15. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  16. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  17. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  18. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  19. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Bold.woff2 +0 -0
  20. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  21. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Italic.woff2 +0 -0
  22. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Regular.woff2 +0 -0
  23. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  24. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Math-Italic.woff2 +0 -0
  25. package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  26. package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  27. package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  28. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Script-Regular.woff2 +0 -0
  29. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  30. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  31. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  32. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  33. package/BookReader/hypothesis/build/styles/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  34. package/BookReader/hypothesis/build/styles/highlights.css +2 -0
  35. package/BookReader/hypothesis/build/styles/highlights.css.map +1 -0
  36. package/BookReader/hypothesis/build/styles/katex.min.css +2 -0
  37. package/BookReader/hypothesis/build/styles/katex.min.css.map +1 -0
  38. package/BookReader/hypothesis/build/styles/pdfjs-overrides.css +2 -0
  39. package/BookReader/hypothesis/build/styles/pdfjs-overrides.css.map +1 -0
  40. package/BookReader/hypothesis/build/styles/sidebar.css +2731 -0
  41. package/BookReader/hypothesis/build/styles/sidebar.css.map +1 -0
  42. package/BookReader/hypothesis/build/styles/ui-playground.css +2659 -0
  43. package/BookReader/hypothesis/build/styles/ui-playground.css.map +1 -0
  44. package/BookReader/hypothesis/package.json +126 -0
  45. package/README.md +0 -2
  46. package/package.json +6 -1
  47. package/.eslintrc.cjs +0 -51
  48. package/.gitattributes +0 -2
  49. package/.github/ISSUE_TEMPLATE/bug.md +0 -32
  50. package/.github/ISSUE_TEMPLATE/feature-request.md +0 -30
  51. package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +0 -15
  52. package/.github/workflows/node.js.yml +0 -102
  53. package/.github/workflows/npm-publish.yml +0 -33
  54. package/.testcaferc.cjs +0 -10
  55. package/BookReaderDemo/BookReaderDemo.css +0 -40
  56. package/BookReaderDemo/BookReaderJSAdvanced.js +0 -112
  57. package/BookReaderDemo/BookReaderJSSimple.js +0 -56
  58. package/BookReaderDemo/IADemoBr.js +0 -149
  59. package/BookReaderDemo/assets/v5/Bookreader-logo-cool-grad.svg +0 -1
  60. package/BookReaderDemo/assets/v5/Bookreader-logo-flat.svg +0 -1
  61. package/BookReaderDemo/assets/v5/Bookreader-logo-hex-cool-grad.png +0 -0
  62. package/BookReaderDemo/assets/v5/Bookreader-logo-hex-flat.png +0 -0
  63. package/BookReaderDemo/assets/v5/Bookreader-logo-lines.png +0 -0
  64. package/BookReaderDemo/assets/v5/Bookreader-logo-lines.svg +0 -1
  65. package/BookReaderDemo/assets/v5/Bookreader-logo-warm.svg +0 -1
  66. package/BookReaderDemo/assets/v5/bookreader-logo-renders@1x.png +0 -0
  67. package/BookReaderDemo/assets/v5/bookreader-logo-renders@2x.png +0 -0
  68. package/BookReaderDemo/assets/v5/bookreader-v5-screenshot.png +0 -0
  69. package/BookReaderDemo/demo-advanced.html +0 -33
  70. package/BookReaderDemo/demo-embed-iframe-src.html +0 -85
  71. package/BookReaderDemo/demo-embed.html +0 -26
  72. package/BookReaderDemo/demo-fullscreen-mobile.html +0 -34
  73. package/BookReaderDemo/demo-fullscreen.html +0 -31
  74. package/BookReaderDemo/demo-iiif.html +0 -121
  75. package/BookReaderDemo/demo-internetarchive.html +0 -271
  76. package/BookReaderDemo/demo-multiple.html +0 -44
  77. package/BookReaderDemo/demo-preview-pages.html +0 -1093
  78. package/BookReaderDemo/demo-simple.html +0 -35
  79. package/BookReaderDemo/demo-vendor-fullscreen.html +0 -34
  80. package/BookReaderDemo/ia-multiple-volumes-manifest.js +0 -169
  81. package/BookReaderDemo/immersion-1up.html +0 -64
  82. package/BookReaderDemo/immersion-mode.html +0 -33
  83. package/BookReaderDemo/toggle_controls.html +0 -54
  84. package/BookReaderDemo/view_mode.html +0 -40
  85. package/BookReaderDemo/viewmode-cycle.html +0 -40
  86. package/CHANGELOG.md +0 -1080
  87. package/CONTRIBUTING.md +0 -7
  88. package/babel.config.cjs +0 -20
  89. package/codecov.yml +0 -23
  90. package/index.html +0 -34
  91. package/netlify.toml +0 -9
  92. package/renovate.json +0 -52
  93. package/screenshot.png +0 -0
  94. package/scripts/postversion.js +0 -11
  95. package/scripts/preversion.js +0 -15
  96. package/scripts/version.js +0 -27
  97. package/tests/e2e/README.md +0 -112
  98. package/tests/e2e/autoplay.test.js +0 -16
  99. package/tests/e2e/base.test.js +0 -27
  100. package/tests/e2e/helpers/base.js +0 -263
  101. package/tests/e2e/helpers/debug.js +0 -13
  102. package/tests/e2e/helpers/mockSearch.js +0 -90
  103. package/tests/e2e/helpers/params.js +0 -17
  104. package/tests/e2e/helpers/rightToLeft.js +0 -23
  105. package/tests/e2e/helpers/search.js +0 -73
  106. package/tests/e2e/models/BookReader.js +0 -11
  107. package/tests/e2e/models/Navigation.js +0 -39
  108. package/tests/e2e/rightToLeft.test.js +0 -19
  109. package/tests/e2e/viewmode.test.js +0 -44
  110. package/tests/jest/BookNavigator/book-navigator.test.js +0 -653
  111. package/tests/jest/BookNavigator/bookmarks/bookmark-button.test.js +0 -43
  112. package/tests/jest/BookNavigator/bookmarks/bookmark-edit.test.js +0 -132
  113. package/tests/jest/BookNavigator/bookmarks/bookmarks-list.test.js +0 -221
  114. package/tests/jest/BookNavigator/bookmarks/ia-bookmarks.test.js +0 -45
  115. package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +0 -67
  116. package/tests/jest/BookNavigator/downloads/downloads.test.js +0 -53
  117. package/tests/jest/BookNavigator/search/search-provider.test.js +0 -179
  118. package/tests/jest/BookNavigator/search/search-results.test.js +0 -289
  119. package/tests/jest/BookNavigator/sharing/sharing-provider.test.js +0 -49
  120. package/tests/jest/BookNavigator/viewable-files/viewable-files-provider.test.js +0 -80
  121. package/tests/jest/BookNavigator/visual-adjustments.test.js +0 -200
  122. package/tests/jest/BookReader/BookModel.test.js +0 -372
  123. package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +0 -263
  124. package/tests/jest/BookReader/ImageCache.test.js +0 -150
  125. package/tests/jest/BookReader/Mode1UpLit.test.js +0 -73
  126. package/tests/jest/BookReader/Mode2Up.test.js +0 -98
  127. package/tests/jest/BookReader/Mode2UpLit.test.js +0 -190
  128. package/tests/jest/BookReader/ModeCoordinateSpace.test.js +0 -16
  129. package/tests/jest/BookReader/ModeSmoothZoom.test.js +0 -218
  130. package/tests/jest/BookReader/ModeThumb.test.js +0 -71
  131. package/tests/jest/BookReader/Navbar/Navbar.test.js +0 -182
  132. package/tests/jest/BookReader/PageContainer.test.js +0 -249
  133. package/tests/jest/BookReader/ReduceSet.test.js +0 -38
  134. package/tests/jest/BookReader/Toolbar/Toolbar.test.js +0 -26
  135. package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +0 -59
  136. package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +0 -49
  137. package/tests/jest/BookReader/utils/SelectionObserver.test.js +0 -57
  138. package/tests/jest/BookReader/utils/classes.test.js +0 -88
  139. package/tests/jest/BookReader/utils.test.js +0 -250
  140. package/tests/jest/BookReader.keyboard.test.js +0 -190
  141. package/tests/jest/BookReader.options.test.js +0 -47
  142. package/tests/jest/BookReader.test.js +0 -316
  143. package/tests/jest/plugins/plugin.archive_analytics.test.js +0 -20
  144. package/tests/jest/plugins/plugin.autoplay.test.js +0 -35
  145. package/tests/jest/plugins/plugin.chapters.test.js +0 -193
  146. package/tests/jest/plugins/plugin.iframe.test.js +0 -42
  147. package/tests/jest/plugins/plugin.resume.test.js +0 -85
  148. package/tests/jest/plugins/plugin.text_selection.test.js +0 -447
  149. package/tests/jest/plugins/plugin.vendor-fullscreen.test.js +0 -65
  150. package/tests/jest/plugins/search/plugin.search.test.js +0 -120
  151. package/tests/jest/plugins/search/plugin.search.view.test.js +0 -131
  152. package/tests/jest/plugins/search/utils.js +0 -25
  153. package/tests/jest/plugins/search/utils.test.js +0 -29
  154. package/tests/jest/plugins/tts/AbstractTTSEngine.test.js +0 -173
  155. package/tests/jest/plugins/tts/FestivalTTSEngine.test.js +0 -59
  156. package/tests/jest/plugins/tts/PageChunk.test.js +0 -57
  157. package/tests/jest/plugins/tts/PageChunkIterator.test.js +0 -179
  158. package/tests/jest/plugins/tts/WebTTSEngine.test.js +0 -178
  159. package/tests/jest/plugins/tts/utils.test.js +0 -74
  160. package/tests/jest/plugins/url/UrlPlugin.test.js +0 -198
  161. package/tests/jest/plugins/url/plugin.url.test.js +0 -168
  162. package/tests/jest/setup.js +0 -3
  163. package/tests/jest/util/browserSniffing.test.js +0 -62
  164. package/tests/jest/util/docCookies.test.js +0 -24
  165. package/tests/jest/util/strings.test.js +0 -63
  166. package/tests/jest/utils.js +0 -83
  167. package/webpack.config.js +0 -97
@@ -1,289 +0,0 @@
1
- import {
2
- html,
3
- fixture,
4
- oneEvent,
5
- } from '@open-wc/testing-helpers';
6
- import sinon from 'sinon';
7
- import { IABookSearchResults } from '@/src/BookNavigator/search/search-results.js';
8
- import { marshallSearchResults } from '@/src/plugins/search/utils.js';
9
-
10
- const container = (results = [], query = '') => (
11
- html`<ia-book-search-results .results=${results} .query=${query}></ia-book-search-results>`
12
- );
13
-
14
- const searchQuery = 'Bristol';
15
-
16
- const results = [{
17
- text: `In the drawing of caricatures and cartoons\u2014or any other com' mercial art, for that matter\u2014the artist should know something about the processes of reproduction for that particular form of art work. For pen and ink work the engraving is made on a sine printing plate. It is not necessary, however, to know all about these processes of reproduction. The artist should know that all work intended for line rqproducttons should be made on white paper or {{{${searchQuery}}}} Board with black drawing ink. The drawing to be reproduced is photographed on a chemically treated sine plate, which is then treated with acid. This acid eats away the surface of the sine, except the photographed' lines, which are left in relief, somewhat like printing type. Colored inks do not photograph well; neither does black ink on colored paper.`,
18
- cover: '//placehold.it/30x44',
19
- title: 'Book title',
20
- displayPageNumber: 'Page 24',
21
- par: [{
22
- boxes: [{
23
- r: 2672, b: 792, t: 689, page: 24, l: 2424,
24
- }],
25
- b: 1371,
26
- t: 689,
27
- page_width: 3658,
28
- r: 3192,
29
- l: 428,
30
- page_height: 5357,
31
- page: 24,
32
- }],
33
- }, {
34
- text: `Drawings intended for sale should be made on a good grade of {{{${searchQuery}}}} Board, and a margin left all the way around the drawings. They should be mailed flat, and'require first class postage. Enclose postage for the return of the drawings. Only send good drawings of a reason- able quantity. Enclose a neat and terse letter to the one you are sending the drawings to, written with pen and ink or typewriter if possible, on`,
35
- displayPageNumber: 'Page 86',
36
- par: [{
37
- boxes: [{
38
- r: 698, b: 4460, t: 4324, page: 86, l: 450,
39
- }],
40
- b: 4938,
41
- t: 4207,
42
- page_width: 3658,
43
- r: 3196,
44
- l: 432,
45
- page_height: 5357,
46
- page: 86,
47
- }],
48
- }];
49
-
50
- marshallSearchResults({ matches: results }, () => '', '{{{', '}}}');
51
-
52
- const resultWithScript = [{
53
- text: `foo bar <script>const msg = 'test' + ' failure'; document.write(msg);</script> {{{${searchQuery}}}} baz`,
54
- cover: '//placehold.it/30x44',
55
- title: 'Book title',
56
- displayPageNumber: 'Page 24',
57
- par: [{
58
- boxes: [{
59
- r: 2672, b: 792, t: 689, page: 24, l: 2424,
60
- }],
61
- b: 1371,
62
- t: 689,
63
- page_width: 3658,
64
- r: 3192,
65
- l: 428,
66
- page_height: 5357,
67
- page: 24,
68
- }],
69
- }];
70
-
71
- marshallSearchResults({ matches: resultWithScript }, () => '', '{{{', '}}}');
72
-
73
- describe('<ia-book-search-results>', () => {
74
- afterEach(() => {
75
- sinon.restore();
76
- });
77
-
78
- test('sets default properties', async () => {
79
- const query = 'bristol';
80
- const el = await fixture(container(results, query));
81
-
82
- expect(el.results).toEqual(results);
83
- expect(el.query).toEqual(query);
84
- });
85
-
86
- test('sets results when passed in via event object', async () => {
87
- const el = await fixture(container());
88
-
89
- el.setResults({ detail: { results } });
90
- expect(el.results).toEqual(results);
91
- });
92
-
93
- test('listens for a custom search callback event on the document', async () => {
94
- IABookSearchResults.prototype.setResults = sinon.fake();
95
- const el = await fixture(container());
96
- const event = new Event('BookReader:SearchCallback');
97
-
98
- event.detail = { results };
99
- document.dispatchEvent(event);
100
- expect(el.setResults.callCount).toEqual(1);
101
- expect(el.setResults.firstArg).toEqual(event);
102
- });
103
-
104
- test('renders results that contain the book title', async () => {
105
- sinon.replace(IABookSearchResults.prototype, 'createRenderRoot', function createRenderRoot() { return this; });
106
- const el = await fixture(container(results));
107
-
108
- expect(el.innerHTML).toContain(`${results[0].title}`);
109
- });
110
-
111
- test('renders results that contain a highlighted match', async () => {
112
- sinon.replace(IABookSearchResults.prototype, 'createRenderRoot', function createRenderRoot() { return this; });
113
- const el = await fixture(container(results));
114
-
115
- // Lit inserts HTML comments that inhibit searching for exact innerHTML matches.
116
- // So query the DOM for the match instead.
117
- const match = el.querySelector('mark');
118
- expect(match?.textContent).toEqual(searchQuery);
119
- });
120
-
121
- test('renders results that contain sanitized HTML tags', async () => {
122
- sinon.replace(IABookSearchResults.prototype, 'createRenderRoot', function createRenderRoot() { return this; });
123
- // A result whose text contains a <script> tag that will insert 'test failure' into the element if not sanitized
124
- const el = await fixture(container(resultWithScript));
125
-
126
- const match = el.querySelector('mark');
127
- expect(match?.textContent).toEqual(searchQuery);
128
- expect(el.innerHTML).not.toContain('test failure');
129
- });
130
-
131
- test('renders results that contain an optional cover image', async () => {
132
- sinon.replace(IABookSearchResults.prototype, 'createRenderRoot', function createRenderRoot() { return this; });
133
- const el = await fixture(container(results));
134
-
135
- expect(el.innerHTML).toContain(`<img src="${results[0].cover}">`);
136
- });
137
-
138
- test('sets a query prop when search input receives input', async () => {
139
- const el = await fixture(container(results));
140
- const searchInput = el.shadowRoot.querySelector('[name="query"]');
141
-
142
- searchInput.value = searchQuery;
143
- searchInput.dispatchEvent(new Event('keyup'));
144
-
145
- expect(el.query).toEqual(searchQuery);
146
- });
147
-
148
- test('emits a custom event when search form submitted when input is populated', async () => {
149
- const el = await fixture(container(results));
150
-
151
- setTimeout(() => {
152
- const form = el.shadowRoot.querySelector('form');
153
- form.querySelector('input').value = 'foo';
154
- form.dispatchEvent(new Event('submit'));
155
- });
156
- const response = await oneEvent(el, 'bookSearchInitiated');
157
-
158
- expect(response).toBeDefined();
159
- });
160
-
161
- test('uses a singular noun when one result given', async () => {
162
- const el = await fixture(container([results[0]]));
163
- const resultsCount = await fixture(el.resultsCount);
164
-
165
- expect(resultsCount.innerHTML).toContain('1 result');
166
- });
167
-
168
- test('can render header with active options count', async () => {
169
- const el = await fixture(container(results));
170
- el.renderHeader = true;
171
-
172
- await el.updateComplete;
173
-
174
- expect(el.shadowRoot.querySelector('header p').textContent).toContain('2');
175
- });
176
-
177
- test('renders search all files checkbox when enabled', async () => {
178
- const el = await fixture(container(results));
179
- el.renderSearchAllFiles = true;
180
-
181
- await el.updateComplete;
182
-
183
- expect(el.shadowRoot.querySelector('[name="all_files"]')).not.toBeNull();
184
- });
185
-
186
- test('emits a resultSelected event when a search result is clicked', async () => {
187
- const el = await fixture(container(results));
188
-
189
- setTimeout(() => (
190
- el.shadowRoot.querySelector('li').click()
191
- ));
192
- const response = await oneEvent(el, 'resultSelected');
193
-
194
- expect(response).toBeDefined();
195
- });
196
-
197
- test('emits a closeMenu event when a search result is clicked', async () => {
198
- const el = await fixture(container(results));
199
-
200
- setTimeout(() => (
201
- el.shadowRoot.querySelector('li').click()
202
- ));
203
- const response = await oneEvent(el, 'closeMenu');
204
-
205
- expect(response).toBeDefined();
206
- });
207
-
208
- describe('Search results placeholders', () => {
209
- test('renders a loading state when queryInProgress is true', async () => {
210
- const el = await fixture(container(results));
211
-
212
- el.queryInProgress = true;
213
- await el.updateComplete;
214
-
215
- expect(el.shadowRoot.querySelector('.loading')).not.toBeNull();
216
- });
217
- test('renders an error message when provided', async () => {
218
- const el = await fixture(container([]));
219
- const message = 'Sample error message';
220
- el.errorMessage = message;
221
- await el.updateComplete;
222
-
223
- expect(el.shadowRoot.querySelector('.error-message')).toBeDefined();
224
- expect(el.shadowRoot.querySelector('.search-cta')).toBeNull();
225
- });
226
- test('displays call to search when no results or search errors are showing', async () => {
227
- const el = await fixture(container([]));
228
-
229
- expect(el.shadowRoot.querySelector('.search-cta')).toBeDefined();
230
- expect(el.shadowRoot.querySelector('.error-message')).toBeNull();
231
- expect(el.shadowRoot.querySelector('.results')).toBeNull();
232
- });
233
- });
234
-
235
- test('displays results images when told to', async () => {
236
- const el = await fixture(container(results));
237
- el.displayResultImages = true;
238
- await el.updateComplete;
239
-
240
- expect(el.shadowRoot.querySelector('.results.show-image')).toBeDefined();
241
- });
242
-
243
- describe('search input focus', () => {
244
- test('will always try to re-focus once the component updates', async () => {
245
- const el = await fixture(container(results));
246
- el.focusOnInputIfNecessary = sinon.fake();
247
- // update any property to fire lifecycle
248
- el.results = [];
249
- await el.updateComplete;
250
-
251
- expect(el.focusOnInputIfNecessary.callCount).toEqual(1);
252
- });
253
- test('refocuses on input when results are empty', async () => {
254
- const el = await fixture(container(results));
255
- el.results = [];
256
- await el.updateComplete;
257
-
258
- const searchInputField = el.shadowRoot.querySelector('input[type=\'search\']');
259
- expect(searchInputField).toEqual(el.shadowRoot.activeElement);
260
- });
261
- });
262
-
263
- test("emits a bookSearchCanceled event when loading state's cancel action clicked", async () => {
264
- const el = await fixture(container(results));
265
-
266
- el.queryInProgress = true;
267
- await el.updateComplete;
268
-
269
- setTimeout(() => (
270
- el.shadowRoot.querySelector('button').click()
271
- ));
272
- const response = await oneEvent(el, 'bookSearchCanceled');
273
-
274
- expect(response).toBeDefined();
275
- });
276
- it('cancels search when input is cleared', async () => {
277
- const el = await fixture(container(results));
278
-
279
- el.cancelSearch = sinon.fake();
280
- await el.updateComplete;
281
-
282
- const searchInput = el.shadowRoot.querySelector('[name="query"]');
283
-
284
- searchInput.value = '';
285
- searchInput.dispatchEvent(new Event('search'));
286
-
287
- expect(el.cancelSearch.callCount).toEqual(1);
288
- });
289
- });
@@ -1,49 +0,0 @@
1
- import { fixtureSync } from '@open-wc/testing-helpers';
2
- import sinon from 'sinon';
3
- import SharingProvider from '@/src/BookNavigator/sharing.js';
4
-
5
- afterEach(() => {
6
- sinon.restore();
7
- });
8
-
9
- const item = {
10
- metadata: {
11
- identifier: 'stubby-id',
12
- creator: 'mr. big',
13
- title: 'Stubby title',
14
- },
15
- };
16
-
17
- const baseHost = 'foo.org';
18
- const subPrefix = 'beep-boop_12 4 5';
19
-
20
- describe('Sharing Provider', () => {
21
- describe('constructor', () => {
22
- const provider = new SharingProvider({
23
- item,
24
- baseHost,
25
- bookreader: {
26
- options: { subPrefix },
27
- },
28
- });
29
-
30
- expect(provider.id).toEqual('share');
31
- expect(provider.icon).toBeDefined();
32
- expect(provider.label).toEqual('Share this book');
33
- expect(fixtureSync(provider.component).tagName).toContain('IAUX-IN-SHARE-PANEL');
34
- });
35
-
36
- describe('Handles being a sub file/volume', () => {
37
- test('encodes the subprefix if it has one', async () => {
38
- const provider = new SharingProvider({
39
- item,
40
- baseHost,
41
- bookreader: {
42
- subPrefix,
43
- },
44
- });
45
-
46
- expect(fixtureSync(provider.component).fileSubPrefix).toEqual(subPrefix);
47
- });
48
- });
49
- });
@@ -1,80 +0,0 @@
1
- import { fixtureCleanup, fixtureSync } from '@open-wc/testing-helpers';
2
- import sinon from 'sinon';
3
- import ViewableFilesProvider from '@/src/BookNavigator/viewable-files';
4
-
5
- const brOptions = {
6
- "options": {
7
- "subPrefix": 'special-subprefix',
8
- "enableMultipleBooks": true,
9
- "multipleBooksList": {
10
- "by_subprefix": {
11
- "/details/SubBookTest": {
12
- "url_path": "/details/SubBookTest",
13
- "file_subprefix": "book1/GPORFP",
14
- "orig_sort": 1,
15
- "title": "book1/GPORFP.pdf",
16
- "file_source": "/book1/GPORFP_jp2.zip",
17
- },
18
- "/details/SubBookTest/subdir/book2/brewster_kahle_internet_archive": {
19
- "url_path": "/details/SubBookTest/subdir/book2/brewster_kahle_internet_archive",
20
- "file_subprefix": "subdir/book2/brewster_kahle_internet_archive",
21
- "orig_sort": 2,
22
- "title": "subdir/book2/brewster_kahle_internet_archive.pdf",
23
- "file_source": "/subdir/book2/brewster_kahle_internet_archive_jp2.zip",
24
- },
25
- "/details/SubBookTest/subdir/subsubdir/book3/Rfp008011ResponseInternetArchive-without-resume": {
26
- "url_path": "/details/SubBookTest/subdir/subsubdir/book3/Rfp008011ResponseInternetArchive-without-resume",
27
- "file_subprefix": "subdir/subsubdir/book3/Rfp008011ResponseInternetArchive-without-resume",
28
- "orig_sort": 3,
29
- "title": "subdir/subsubdir/book3/Rfp008011ResponseInternetArchive-without-resume.pdf",
30
- "file_source": "/subdir/subsubdir/book3/Rfp008011ResponseInternetArchive-without-resume_jp2.zip",
31
- },
32
- },
33
- },
34
- },
35
- };
36
-
37
- afterEach(() => {
38
- sinon.restore();
39
- fixtureCleanup();
40
- });
41
-
42
- describe('Volumes Provider', () => {
43
- test('initiating & sorting', () => {
44
- const onProviderChange = sinon.fake();
45
-
46
- const baseHost = "https://archive.org";
47
- const provider = new ViewableFilesProvider({
48
- baseHost,
49
- bookreader: brOptions,
50
- onProviderChange,
51
- });
52
-
53
- const files = brOptions.options.multipleBooksList.by_subprefix;
54
- const volumeCount = Object.keys(files).length;
55
-
56
- expect(provider.onProviderChange).toEqual(onProviderChange);
57
- expect(provider.id).toEqual('volumes');
58
- expect(provider.icon).toBeDefined();
59
- expect(fixtureSync(provider.icon).tagName).toEqual('svg');
60
- expect(provider.sortOrderBy).toEqual('default');
61
-
62
- expect(provider.label).toEqual(`Viewable files (${volumeCount})`);
63
- expect(provider.viewableFiles).toBeDefined();
64
- expect(provider.viewableFiles.length).toEqual(3);
65
- expect(provider.volumeCount).toEqual(3);
66
-
67
- expect(provider.component.baseHost).toEqual(baseHost);
68
- expect(provider.component.fileList).toEqual(provider.viewableFiles);
69
- expect(provider.component.subPrefix).toEqual(brOptions.options.subPrefix);
70
-
71
- expect(provider.actionButton).toBeDefined();
72
- expect(provider.actionButton).toEqual(provider.sortFilesComponent);
73
- expect(provider.actionButton.fileListRaw).toEqual(provider.viewableFiles);
74
-
75
- const callbackSpy = sinon.spy(provider, 'handleFileListSorted');
76
- provider.actionButton.sortVolumes('title_asc');
77
-
78
- expect(callbackSpy.callCount).toEqual(1);
79
- });
80
- });
@@ -1,200 +0,0 @@
1
- import {
2
- html,
3
- fixture,
4
- oneEvent,
5
- } from '@open-wc/testing-helpers';
6
- import sinon from 'sinon';
7
- import { IABookVisualAdjustments } from '@/src/BookNavigator/visual-adjustments/visual-adjustments.js';
8
-
9
- const options = [{
10
- id: 'contrast',
11
- name: 'Adjust contrast',
12
- active: true,
13
- min: 0,
14
- max: 150,
15
- step: 1,
16
- value: 100,
17
- }, {
18
- id: 'invert',
19
- name: 'Invert colors (dark mode)',
20
- active: false,
21
- }, {
22
- id: 'brightness',
23
- name: 'Adjust brightness',
24
- active: false,
25
- value: 100,
26
- }];
27
-
28
- const container = (renderHeader = false) => (
29
- html`<ia-book-visual-adjustments .options=${options} ?renderHeader=${renderHeader}></ia-book-visual-adjustments>`
30
- );
31
-
32
- describe('<ia-book-visual-adjustments>', () => {
33
- afterEach(() => {
34
- sinon.restore();
35
- });
36
-
37
- test('sets default properties', async () => {
38
- const el = await fixture(container());
39
-
40
- expect(el.options).toBeDefined();
41
- expect(el.options.length).toEqual(options.length);
42
- expect(el.renderHeader).toBeDefined();
43
- expect(el.renderHeader).toBeFalsy();
44
- expect(el.activeCount).toBeDefined();
45
- expect(el.showZoomControls).toBeTruthy();
46
- });
47
-
48
- test('renders all properties of a visual adjustment option', async () => {
49
- const el = await fixture(container());
50
-
51
- await el.updateComplete;
52
-
53
- const label = el.shadowRoot.querySelector('label');
54
- const name = label.querySelector('.name');
55
- const checkbox = label.querySelector('input');
56
- expect(name.textContent).toEqual(options[0].name);
57
- expect(checkbox.checked).toEqual(true);
58
- });
59
-
60
- test('can render header with active options count', async () => {
61
- const renderHeader = true;
62
- const el = await fixture(container(renderHeader));
63
- expect(el.shadowRoot.querySelector('header p').textContent).toContain('1');
64
- });
65
-
66
- test('does not render active options count element when none are selected', async () => {
67
- const el = await fixture(container());
68
-
69
- el.options = [options[1]];
70
- await el.updateComplete;
71
-
72
- expect(el.shadowRoot.querySelector('header p')).toBe(null);
73
- });
74
-
75
- test('changes option\'s active state when input changed', async () => {
76
- const el = await fixture(container());
77
-
78
- el.shadowRoot.querySelector('li input').dispatchEvent(new Event('change'));
79
- await el.updateComplete;
80
-
81
- expect(el.options[0].active).toEqual(false);
82
- });
83
-
84
- test('renders zoom in and out controls when enabled', async () => {
85
- const el = await fixture(container());
86
-
87
- expect(el.shadowRoot.querySelector('.zoom_out')).toBeDefined();
88
- expect(el.shadowRoot.querySelector('.zoom_in')).toBeDefined();
89
- });
90
-
91
- test('does not render zoom controls when disabled', async () => {
92
- const el = await fixture(container());
93
-
94
- el.showZoomControls = false;
95
- await el.updateComplete;
96
-
97
- expect(el.shadowRoot.querySelector('.zoom_out')).toBe(null);
98
- expect(el.shadowRoot.querySelector('.zoom_in')).toBe(null);
99
- });
100
-
101
- describe('Custom events', () => {
102
- test('prepareEventDetails returns proper params', async () => {
103
- const el = await fixture(container());
104
- await el.updateComplete;
105
- const params = el.prepareEventDetails();
106
-
107
- expect(params.activeCount).toBeDefined();
108
- expect(typeof (params.activeCount)).toEqual('number');
109
- expect(params.changedOptionId).toBeDefined();
110
- expect(typeof (params.changedOptionId)).toEqual('string');
111
- expect(params.options).toBeDefined();
112
- expect(params.options.length).toBeDefined();
113
- expect(params.options.length).toBeGreaterThan(0);
114
- });
115
- test('emitOptionChangedEvent calls for the params', async () => {
116
- IABookVisualAdjustments.prototype.prepareEventDetails = sinon.fake();
117
- const el = await fixture(container());
118
- await el.updateComplete;
119
-
120
- expect(el.prepareEventDetails.callCount).toEqual(1);
121
- });
122
- test('triggers an emitOptionChangedEvent event at firstUpdate', async () => {
123
- IABookVisualAdjustments.prototype.emitOptionChangedEvent = sinon.fake();
124
- const el = await fixture(container());
125
-
126
- expect(el.emitOptionChangedEvent.callCount).toEqual(1);
127
- });
128
-
129
- test('triggers an emitOptionChangedEvent event when a checkbox\'s change event fires', async () => {
130
- IABookVisualAdjustments.prototype.emitOptionChangedEvent = sinon.fake();
131
- const el = await fixture(container());
132
-
133
- expect(el.emitOptionChangedEvent.callCount).toEqual(1); // firstUpdate fire
134
-
135
- el.shadowRoot.querySelector('li input').dispatchEvent(new Event('change'));
136
- expect(el.emitOptionChangedEvent.callCount).toEqual(2);
137
- });
138
-
139
- test('triggers an emitOptionChangedEvent event when a range\'s change event fires', async () => {
140
- IABookVisualAdjustments.prototype.emitOptionChangedEvent = sinon.fake();
141
-
142
- const el = await fixture(container());
143
- expect(el.emitOptionChangedEvent.callCount).toEqual(1); // firstUpdate fire
144
-
145
- el.shadowRoot.querySelector('[name="brightness_range"]').dispatchEvent(new Event('change'));
146
- expect(el.emitOptionChangedEvent.callCount).toEqual(2);
147
- });
148
-
149
- test('emits a zoom out event when zoom out button clicked', async () => {
150
- const el = await fixture(container());
151
-
152
- setTimeout(() => (
153
- el.shadowRoot.querySelector('.zoom_out').click()
154
- ));
155
- const response = await oneEvent(el, 'visualAdjustmentZoomOut');
156
-
157
- expect(response).toBeDefined();
158
- });
159
-
160
- test('emits a zoom in event when zoom in button clicked', async () => {
161
- const el = await fixture(container());
162
-
163
- setTimeout(() => (
164
- el.shadowRoot.querySelector('.zoom_in').click()
165
- ));
166
- const response = await oneEvent(el, 'visualAdjustmentZoomIn');
167
-
168
- expect(response).toBeDefined();
169
- });
170
- });
171
-
172
- test('sets range defaults when none supplied', async () => {
173
- const el = await fixture(container());
174
- const brightnessRange = el.shadowRoot.querySelector('[name="brightness_range"]');
175
-
176
- expect(brightnessRange.getAttribute('min')).toEqual('0');
177
- expect(brightnessRange.getAttribute('max')).toEqual('100');
178
- expect(brightnessRange.getAttribute('step')).toEqual('1');
179
- });
180
-
181
- test('sets the updated range value on the options prop', async () => {
182
- const el = await fixture(container());
183
- const { id } = options[0];
184
- const newValue = 120;
185
-
186
- el.setRangeValue(id, newValue);
187
- await el.updateComplete;
188
-
189
- expect(el.options[0].value).toEqual(newValue);
190
- });
191
-
192
- test('triggers a setRangeValue event when a range\'s input event fires', async () => {
193
- IABookVisualAdjustments.prototype.setRangeValue = sinon.fake();
194
-
195
- const el = await fixture(container());
196
-
197
- el.shadowRoot.querySelector('[name="brightness_range"]').dispatchEvent(new Event('input'));
198
- expect(el.setRangeValue.callCount).toEqual(1);
199
- });
200
- });