@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,132 +0,0 @@
1
- import {
2
- html,
3
- fixture,
4
- oneEvent,
5
- } from '@open-wc/testing-helpers';
6
- import '@/src/BookNavigator/bookmarks/bookmark-edit.js';
7
-
8
- const bookmarkColors = [{
9
- id: 0,
10
- className: '',
11
- }, {
12
- id: 1,
13
- className: 'blue',
14
- }, {
15
- id: 2,
16
- className: 'red',
17
- }, {
18
- id: 3,
19
- className: 'green',
20
- }, {
21
- id: 4,
22
- className: 'yellow',
23
- }];
24
-
25
- const container = (bookmark = {}) => (
26
- html`<ia-bookmark-edit .bookmark=${bookmark} .bookmarkColors=${bookmarkColors}></ia-bookmark-edit>`
27
- );
28
-
29
- const bookmark = {
30
- id: 2,
31
- thumbnail: '//placehold.it/37x46/06c/fff',
32
- page: 9,
33
- note: 'This is a long comment I left about this bookmark in order to test out the display in the panel on the side of the bookreader.',
34
- color: 0,
35
- };
36
-
37
- describe('<ia-bookmark-edit>', () => {
38
- test('sets default properties', async () => {
39
- const el = await fixture(container(bookmark));
40
-
41
- expect(el.bookmark).toEqual(bookmark);
42
- expect(el.renderHeader).toBeFalsy();
43
- });
44
-
45
- test('renders bookmark thumb and page number', async () => {
46
- const el = await fixture(container(bookmark));
47
-
48
- expect(el.shadowRoot.querySelector('img').getAttribute('src')).toEqual(bookmark.thumbnail);
49
- expect(el.shadowRoot.querySelector('h4').textContent).toEqual(`Page ${bookmark.page}`);
50
- });
51
-
52
- test('renders an optional header section', async () => {
53
- const el = await fixture(container(bookmark));
54
- el.renderHeader = true;
55
-
56
- await el.updateComplete;
57
-
58
- expect(el.shadowRoot.querySelector('header')).toBeDefined();
59
- });
60
-
61
- test('toggles rendering of the bookmark thumbnail and page number', async () => {
62
- const el = await fixture(container(bookmark));
63
- expect(el.shadowRoot.querySelector('img')).toBeDefined();
64
- expect(el.shadowRoot.querySelector('h4')).toBeDefined();
65
-
66
- el.showBookmark = false;
67
- await el.updateComplete;
68
-
69
- expect(el.shadowRoot.querySelector('img')).toBe(null);
70
- expect(el.shadowRoot.querySelector('h4')).toBe(null);
71
- });
72
-
73
- test('emits a custom event when the bookmark color is changed', async () => {
74
- const el = await fixture(container(bookmark));
75
-
76
- setTimeout(() => (
77
- el.shadowRoot.querySelector('li input').dispatchEvent(new Event('change'))
78
- ));
79
- const response = await oneEvent(el, 'bookmarkColorChanged');
80
-
81
- expect(response).toBeDefined();
82
- });
83
-
84
- test('emits a custom event when the edit form is submitted', async () => {
85
- const el = await fixture(container(bookmark));
86
-
87
- setTimeout(() => (
88
- el.shadowRoot.querySelector('form').dispatchEvent(new Event('submit'))
89
- ));
90
- const response = await oneEvent(el, 'saveBookmark');
91
-
92
- expect(response).toBeDefined();
93
- });
94
-
95
- test('emits a custom event when the delete button is clicked', async () => {
96
- const el = await fixture(container(bookmark));
97
-
98
- setTimeout(() => (
99
- el.shadowRoot.querySelector('button').click()
100
- ));
101
- const response = await oneEvent(el, 'deleteBookmark');
102
-
103
- expect(response).toBeDefined();
104
- });
105
-
106
- test('updates bookmark color when a color input changed', async () => {
107
- const el = await fixture(container(bookmark));
108
-
109
- setTimeout(() => (
110
- el.shadowRoot.querySelector('input#color_2').dispatchEvent(new Event('change'))
111
- ));
112
- await oneEvent(el, 'bookmarkColorChanged');
113
-
114
- expect(el.bookmark.color).toEqual(2);
115
- });
116
-
117
- test('updates bookmark note when the note textarea changed', async () => {
118
- const el = await fixture(container(bookmark));
119
- const textarea = el.shadowRoot.querySelector('textarea');
120
- const updatedNote = 'New note';
121
-
122
- textarea.value = updatedNote;
123
-
124
- setTimeout(() => (
125
- textarea.dispatchEvent(new Event('change'))
126
- ));
127
-
128
- await oneEvent(textarea, 'change');
129
-
130
- expect(el.bookmark.note).toContain(updatedNote);
131
- });
132
- });
@@ -1,221 +0,0 @@
1
- import {
2
- html,
3
- fixture,
4
- oneEvent,
5
- } from '@open-wc/testing-helpers';
6
- import '@/src/BookNavigator/bookmarks/bookmarks-list.js';
7
-
8
- const bookmarks = [{
9
- id: 1,
10
- thumbnail: '//placehold.it/37x46',
11
- page: 'xii',
12
- }, {
13
- id: 2,
14
- thumbnail: '//placehold.it/37x46/06c/fff',
15
- page: 9,
16
- note: 'This is a long comment I left about this bookmark in order to test out the display in the panel on the side of the bookreader.',
17
- }, {
18
- id: 3,
19
- thumbnail: '//placehold.it/37x46/e5e5e5/06c',
20
- page: 9,
21
- note: 'Interesting quote here regarding the division of labor',
22
- }];
23
-
24
- const bookmarkColors = [{
25
- id: 0,
26
- className: 'blue',
27
- }, {
28
- id: 1,
29
- className: 'red',
30
- }, {
31
- id: 2,
32
- className: 'green',
33
- }];
34
-
35
- const container = (bookmarksSet = []) => (
36
- html`<ia-bookmarks-list .bookmarks=${bookmarksSet} .bookmarkColors=${bookmarkColors}></ia-bookmarks-list>`
37
- );
38
-
39
- describe('<ia-bookmarks-list>', () => {
40
- it('sets default properties', async () => {
41
- const el = await fixture(container(bookmarks));
42
-
43
- expect(el.bookmarks).toEqual(bookmarks);
44
- expect(el.activeBookmarkID).toBeUndefined();
45
- expect(el.renderHeader).toBeFalsy();
46
- });
47
-
48
- test('renders bookmarks that contain page numbers', async () => {
49
- const el = await fixture(container(bookmarks));
50
-
51
- expect(el.shadowRoot.textContent).toContain(`Page ${bookmarks[0].page}`);
52
- });
53
-
54
- test('renders bookmarks that contain an optional note', async () => {
55
- const el = await fixture(container(bookmarks));
56
-
57
- expect(el.shadowRoot.innerHTML).toContain(bookmarks[1].note);
58
- });
59
-
60
- test('emits a custom event when a bookmark is clicked', async () => {
61
- const el = await fixture(container(bookmarks));
62
-
63
- setTimeout(() => (
64
- el.shadowRoot.querySelector('li').click()
65
- ));
66
- const response = await oneEvent(el, 'bookmarkSelected');
67
-
68
- expect(response).toBeDefined();
69
- });
70
-
71
- test('emits a custom event when an edit button is clicked', async () => {
72
- const el = await fixture(container(bookmarks));
73
-
74
- setTimeout(() => (
75
- el.shadowRoot.querySelector('li button').click()
76
- ));
77
- const response = await oneEvent(el, 'bookmarkEdited');
78
-
79
- expect(response).toBeDefined();
80
- });
81
-
82
- test('emits a saveBookmark event', async () => {
83
- const el = await fixture(container(bookmarks));
84
-
85
- setTimeout(() => (
86
- el.emitSaveBookmark(bookmarks[0])
87
- ));
88
- const response = await oneEvent(el, 'saveBookmark');
89
-
90
- expect(response).toBeDefined();
91
- });
92
-
93
- test('emits a deleteBookmark event', async () => {
94
- const el = await fixture(container(bookmarks));
95
-
96
- setTimeout(() => (
97
- el.emitDeleteBookmark(bookmarks[0].id)
98
- ));
99
- const response = await oneEvent(el, 'deleteBookmark');
100
-
101
- expect(response).toBeDefined();
102
- });
103
-
104
- test('emits a bookmarkColorChanged event', async () => {
105
- const el = await fixture(container(bookmarks));
106
-
107
- setTimeout(() => (
108
- el.emitBookmarkColorChanged({ detail: { bookmarkId: 0, colorId: 0 } })
109
- ));
110
- const response = await oneEvent(el, 'bookmarkColorChanged');
111
-
112
- expect(response).toBeDefined();
113
- });
114
-
115
- test('sets editedBookmark when an edit button is clicked', async () => {
116
- const el = await fixture(container(bookmarks));
117
- let prevState = el.editedBookmark;
118
-
119
- el.shadowRoot.querySelector('li button').click();
120
- await el.updateComplete;
121
-
122
- expect(el.editedBookmark).not.toEqual(prevState);
123
- expect(el.editedBookmark.page).toEqual(bookmarks[0].page);
124
-
125
- // When clicking the same edit button while in edit mode, should toggle
126
- // edit mode off and remove editedBookmark pointer
127
- prevState = el.editedBookmark;
128
- el.shadowRoot.querySelector('li button').click();
129
- await el.updateComplete;
130
-
131
- expect(el.editedBookmark).not.toEqual(prevState);
132
- expect(el.editedBookmark.page).not.toEqual(bookmarks[0].page);
133
- });
134
-
135
- test('resets editedBookmark when saveBookmark callback called', async () => {
136
- const el = await fixture(container(bookmarks));
137
-
138
- [el.editedBookmark] = bookmarks;
139
- await el.updateComplete;
140
- el.saveBookmark({ detail: { bookmark: bookmarks[0] } });
141
- await el.updateComplete;
142
-
143
- expect(el.editedBookmark).not.toEqual(bookmarks[0]);
144
- expect(el.editedBookmark).not.toHaveProperty('page', 'thumbnail', 'id');
145
- });
146
-
147
- test('resets editedBookmark when deleteBookmark callback called', async () => {
148
- const el = await fixture(container(bookmarks));
149
-
150
- [el.editedBookmark] = bookmarks;
151
- await el.updateComplete;
152
- el.deleteBookmark({ detail: { id: bookmarks[0].id } });
153
- await el.updateComplete;
154
-
155
- expect(el.editedBookmark).not.toEqual(bookmarks[0]);
156
- expect(el.editedBookmark).not.toHaveProperty('page', 'thumbnail', 'id');
157
- });
158
-
159
- test('renders the bookmarks count', async () => {
160
- const el = await fixture(container([bookmarks[0]]));
161
- const bookmarksCount = await fixture(el.bookmarksCount);
162
-
163
- expect(bookmarksCount.textContent).toContain('(1)');
164
- });
165
-
166
- test('does not render the bookmarks count when no bookmarks present', async () => {
167
- const el = await fixture(container());
168
- el.renderHeader = true;
169
-
170
- await el.updateComplete;
171
-
172
- expect(el.shadowRoot.querySelector('header small')).toBe(null);
173
- });
174
-
175
- test('renders an optional header section', async () => {
176
- const el = await fixture(container(bookmarks));
177
- el.renderHeader = true;
178
-
179
- await el.updateComplete;
180
-
181
- expect(el.shadowRoot.querySelector('header')).toBeDefined();
182
- });
183
-
184
- // skipped:
185
- // Uncaught TypeError: Cannot read property 'click' of null
186
- xit('emits a custom event when the add bookmark button is clicked', async () => {
187
- const el = await fixture(container(bookmarks));
188
-
189
- setTimeout(() => (
190
- el.shadowRoot.querySelector('.add-bookmark').click()
191
- ));
192
- const response = await oneEvent(el, 'addBookmark');
193
-
194
- expect(response).toBeDefined();
195
- });
196
-
197
- // skipped:
198
- // AssertionError: expected null to exist
199
- xit('renders an optional add bookmark button', async () => {
200
- const el = await fixture(container(bookmarks));
201
-
202
- expect(el.shadowRoot.querySelector('.add-bookmark')).toBeDefined();
203
-
204
- el.renderAddBookmarkButton = false;
205
- await el.updateComplete;
206
-
207
- expect(el.shadowRoot.querySelector('.add-bookmark')).not.toBeDefined();
208
- });
209
-
210
- // skipped:
211
- // TypeError: Cannot read property 'getAttribute' of null
212
- xit('can toggle disable behavior of add bookmark button', async () => {
213
- const el = await fixture(container(bookmarks));
214
- expect(el.shadowRoot.querySelector('.add-bookmark').getAttribute('disabled')).toBeNull();
215
-
216
- el.disableAddBookmarkButton = true;
217
- await el.updateComplete;
218
-
219
- expect(el.shadowRoot.querySelector('.add-bookmark').getAttribute('disabled')).toEqual('disabled');
220
- });
221
- });
@@ -1,45 +0,0 @@
1
- import {
2
- html,
3
- fixtureSync,
4
- fixtureCleanup,
5
- } from '@open-wc/testing-helpers';
6
- import '@/src/BookNavigator/bookmarks/ia-bookmarks.js';
7
- import sinon from 'sinon';
8
-
9
- afterEach(() => {
10
- sinon.restore();
11
- fixtureCleanup();
12
- });
13
-
14
- describe('<ia-bookmarks>', () => {
15
- test('uses `setup` to start component', async () => {
16
- const el = fixtureSync(html`<ia-bookmarks displayMode="bookmarks"></ia-bookmarks>`);
17
- el.bookreader = {
18
- bookId: 'foo',
19
- $,
20
- currentIndex: () => 0,
21
- };
22
- await el.updateComplete;
23
- const fetchUserBookmarks = sinon.spy(el, 'fetchUserBookmarks');
24
- const fetchBookmarks = sinon.stub(el, 'fetchBookmarks');
25
-
26
- el.setup();
27
- await el.updateComplete;
28
-
29
- expect(fetchUserBookmarks.callCount).toEqual(1);
30
- expect(fetchBookmarks.callCount).toEqual(1);
31
- });
32
-
33
- test('does not fetch user bookmarks if displayMode = login', async () => {
34
- const el = fixtureSync(html`<ia-bookmarks displayMode="login"></ia-bookmarks>`);
35
- await el.updateComplete;
36
- const fetchSpy = sinon.spy(el, 'fetchUserBookmarks');
37
- const fetchBookmarks = sinon.stub(el, 'fetchBookmarks');
38
-
39
- el.setup();
40
- await el.updateComplete;
41
-
42
- expect(fetchSpy.callCount).toEqual(0);
43
- expect(fetchBookmarks.callCount).toEqual(0);
44
- });
45
- });
@@ -1,67 +0,0 @@
1
- import { fixtureCleanup, fixtureSync } from '@open-wc/testing-helpers';
2
- import sinon from 'sinon';
3
- import DownloadsProvider from '@/src/BookNavigator/downloads/downloads-provider.js';
4
-
5
- const downloadableTypes = [
6
- ["PDF", "//archive.org/download/theworksofplato01platiala/theworksofplato01platiala.pdf"],
7
- ["ePub", "//archive.org/download/theworksofplato01platiala/theworksofplato01platiala.epub"],
8
- ["Plain Text", "//archive.org/download/theworksofplato01platiala/theworksofplato01platiala_djvu.txt"],
9
- ["DAISY", "//archive.org/download/theworksofplato01platiala/theworksofplato01platiala_daisy.zip"],
10
- ["Kindle", "//archive.org/download/theworksofplato01platiala/theworksofplato01platiala.mobi"],
11
- ];
12
-
13
- const downloads = [
14
- {
15
- type: "PDF",
16
- url: "//archive.org/download/theworksofplato01platiala/theworksofplato01platiala.pdf",
17
- note: "PDF files contain high quality images of pages.",
18
- },
19
- {
20
- type: "ePub",
21
- url: "//archive.org/download/theworksofplato01platiala/theworksofplato01platiala.epub",
22
- note: "ePub files are smaller in size, but may contain errors.",
23
- },
24
- ];
25
-
26
- afterEach(() => {
27
- sinon.restore();
28
- fixtureCleanup();
29
- });
30
-
31
- describe('Downloads Provider', () => {
32
- test('constructor - initial setup', () => {
33
- const isBookProtected = false;
34
- const provider = new DownloadsProvider(isBookProtected);
35
-
36
- expect(provider.id).toEqual('downloads');
37
- expect(provider.icon).toBeDefined();
38
- expect(fixtureSync(provider.icon).tagName).toEqual('IA-ICON-DL');
39
- expect(provider.label).toEqual('Downloadable files');
40
- expect(provider.menuDetails).toBeDefined();
41
- expect(provider.component).toBeDefined();
42
-
43
- provider.update(downloadableTypes);
44
-
45
- expect(provider.isBookProtected).toEqual(false);
46
-
47
- expect(provider.downloads[0].type).toEqual("PDF");
48
- expect(provider.downloads[1].type).toEqual("ePub");
49
-
50
- expect(provider.menuDetails).toEqual(`(${downloads.length} formats)`);
51
- });
52
-
53
- test('render view if book is protected', () => {
54
- const provider = new DownloadsProvider({
55
- bookreader: { options: { isProtected: true } },
56
- });
57
-
58
- expect(provider.isBookProtected).toEqual(true);
59
-
60
- provider.update(downloadableTypes);
61
-
62
- expect(provider.downloads[0].type).toEqual("Encrypted Adobe PDF");
63
- expect(provider.downloads[1].type).toEqual("Encrypted Adobe ePub");
64
-
65
- expect(provider.downloads.length).toEqual(downloads.length);
66
- });
67
- });
@@ -1,53 +0,0 @@
1
- import {
2
- html,
3
- fixture,
4
- fixtureCleanup,
5
- } from '@open-wc/testing-helpers';
6
- import sinon from 'sinon';
7
- import '@/src/BookNavigator/downloads/downloads.js';
8
-
9
-
10
- const downloads = [
11
- {
12
- type: "PDF",
13
- url: "//archive.org/download/theworksofplato01platiala/theworksofplato01platiala.pdf",
14
- note: "PDF files contain high quality images of pages.",
15
- },
16
- {
17
- type: "ePub",
18
- url: "//archive.org/download/theworksofplato01platiala/theworksofplato01platiala.epub",
19
- note: "ePub files are smaller in size, but may contain errors.",
20
- },
21
- ];
22
-
23
-
24
- const container = (downloads) => (
25
- html`
26
- <ia-book-downloads .downloads=${downloads}></ia-book-downloads>
27
- `
28
- );
29
-
30
- beforeEach(() => {
31
- const body = document.querySelector('body');
32
- const brHook = document.createElement('div');
33
- brHook.setAttribute('id', 'BookReader');
34
- body.appendChild(brHook);
35
- });
36
-
37
- afterEach(() => {
38
- sinon.restore();
39
- fixtureCleanup();
40
- });
41
-
42
- describe('<ia-book-downloads>', () => {
43
- test('sets default properties', async () => {
44
- const el = await fixture(container(downloads));
45
- await el.updateComplete;
46
-
47
- expect(el.downloads.length).toEqual(2);
48
- expect(el.shadowRoot.querySelector("ul").childElementCount).toEqual(2);
49
- expect(el.isBookProtected).toEqual(false);
50
-
51
- expect(el.shadowRoot.querySelector("ul li a").textContent).toContain("Get PDF");
52
- });
53
- });
@@ -1,179 +0,0 @@
1
- import { fixtureCleanup, fixtureSync } from '@open-wc/testing-helpers';
2
- import sinon from 'sinon';
3
- import searchProvider from '@/src/BookNavigator/search/search-provider.js';
4
-
5
- afterEach(() => {
6
- sinon.restore();
7
- fixtureCleanup();
8
- });
9
-
10
- describe('Search Provider', () => {
11
- describe('constructor', () => {
12
- const provider = new searchProvider({
13
- onProviderChange: sinon.fake(),
14
- bookreader: {},
15
- });
16
-
17
- expect(provider.bookreader).toBeDefined();
18
- expect(provider.onProviderChange).toBeDefined();
19
- expect(provider.id).toEqual('search');
20
- expect(provider.icon).toBeDefined();
21
- expect(fixtureSync(provider.icon).tagName).toEqual('IA-ICON-SEARCH');
22
- expect(provider.label).toEqual('Search inside');
23
- expect(provider.menuDetails).toBeDefined();
24
- expect(provider.component).toBeDefined();
25
- });
26
- describe('Search request life cycles', () => {
27
- test('Event: catches `BookReader:SearchStarted`', async() => {
28
- const provider = new searchProvider({
29
- onProviderChange: sinon.fake(),
30
- bookreader: {},
31
- });
32
- sinon.spy(provider, 'updateMenu');
33
- window.dispatchEvent(new CustomEvent('BookReader:SearchStarted', { detail: { props: { term: 'foo' }}}));
34
- expect(provider.updateMenu.callCount).toEqual(1);
35
- });
36
- test('Event: catches `BookReader:SearchCallback`', async() => {
37
- const provider = new searchProvider({
38
- onProviderChange: sinon.fake(),
39
- bookreader: {},
40
- });
41
- sinon.spy(provider, 'updateMenu');
42
- const brStub = {};
43
- window.dispatchEvent(new CustomEvent('BookReader:SearchCallback', { detail: { props: { instance: brStub, results: { matches: []} }}}));
44
- expect(provider.updateMenu.callCount).toEqual(1);
45
- expect(provider.bookreader).toEqual(brStub);
46
- });
47
- test('Event: catches `BookReader:SearchCallbackEmpty`', async() => {
48
- const provider = new searchProvider({
49
- onProviderChange: sinon.fake(),
50
- bookreader: {},
51
- });
52
- sinon.spy(provider, 'onSearchRequestError');
53
- sinon.spy(provider, 'updateMenu');
54
- const brStub = {};
55
- window.dispatchEvent(new CustomEvent('BookReader:SearchCallbackEmpty', { detail: { props: { instance: brStub }}}));
56
- expect(provider.onSearchRequestError.getCall(0).args[1]).toEqual('noResults');
57
- expect(provider.updateMenu.callCount).toEqual(1);
58
- expect(provider.bookreader).toEqual(brStub);
59
- });
60
- test('Event: catches `BookReader:SearchCallbackNotIndexed`', async() => {
61
- const provider = new searchProvider({
62
- onProviderChange: sinon.fake(),
63
- bookreader: {},
64
- });
65
- const brStub = {};
66
- sinon.spy(provider, 'onSearchRequestError');
67
- sinon.spy(provider, 'updateMenu');
68
- window.dispatchEvent(new CustomEvent('BookReader:SearchCallbackNotIndexed', { detail: { props: { instance: brStub }}}));
69
- expect(provider.onSearchRequestError.getCall(0).args[1]).toEqual('notIndexed');
70
- expect(provider.updateMenu.callCount).toEqual(1);
71
- expect(provider.bookreader).toEqual(brStub);
72
- });
73
- test('Event: catches `BookReader:SearchCallbackError`', async() => {
74
- const provider = new searchProvider({
75
- onProviderChange: sinon.fake(),
76
- bookreader: {},
77
- });
78
- sinon.spy(provider, 'onSearchRequestError');
79
- sinon.spy(provider, 'updateMenu');
80
- const brStub = {};
81
- window.dispatchEvent(new CustomEvent('BookReader:SearchCallbackError', { detail: { props: { instance: brStub }}}));
82
- expect(provider.onSearchRequestError.getCall(0).args[1]).toEqual(undefined);
83
- expect(provider.updateMenu.callCount).toEqual(1);
84
- expect(provider.bookreader).toEqual(brStub);
85
- });
86
- test('Event: catches `component@resultSelected` - user clicks result in side panel - & turns page', async() => {
87
- const provider = new searchProvider({
88
- onProviderChange: sinon.fake(),
89
- bookreader: {
90
- leafNumToIndex: sinon.fake(),
91
- plugins: {
92
- search: {
93
- jumpToMatch: sinon.fake(),
94
- },
95
- },
96
- },
97
- });
98
-
99
- const searchResultStub = {
100
- match: { par: [{ text: 'foo', page: 3 }] },
101
- };
102
- fixtureSync(provider.component).dispatchEvent(
103
- new CustomEvent('resultSelected',
104
- { detail: searchResultStub }),
105
- );
106
-
107
- expect(provider.bookreader.plugins.search.jumpToMatch.callCount).toEqual(1);
108
- });
109
- test('update url when search is cancelled or input cleared', async() => {
110
- const urlPluginMock = {
111
- pullFromAddressBar: sinon.fake(),
112
- removeUrlParam: sinon.fake(),
113
- };
114
- const provider = new searchProvider({
115
- onProviderChange: sinon.fake(),
116
- bookreader: {
117
- leafNumToIndex: sinon.fake(),
118
- plugins: {
119
- search: {
120
- jumpToMatch: sinon.fake(),
121
- },
122
- },
123
- urlPlugin: urlPluginMock,
124
- },
125
- });
126
-
127
- provider.onSearchCanceled();
128
- await provider.updateComplete;
129
-
130
- expect(urlPluginMock.pullFromAddressBar.callCount).toEqual(1);
131
- expect(urlPluginMock.removeUrlParam.callCount).toEqual(1);
132
-
133
- provider.onSearchCanceled();
134
- await provider.updateComplete;
135
-
136
- expect(urlPluginMock.pullFromAddressBar.callCount).toEqual(2);
137
- expect(urlPluginMock.removeUrlParam.callCount).toEqual(2);
138
- });
139
- it('updateSearchInUrl', async () => {
140
- let fieldToSet;
141
- let valueOfFieldToSet;
142
- let setUrlParamCalled = false;
143
- const urlPluginMock = {
144
- pullFromAddressBar: sinon.fake(),
145
- removeUrlParam: sinon.fake(),
146
- setUrlParam: (field, val) => {
147
- fieldToSet = field;
148
- valueOfFieldToSet = val;
149
- setUrlParamCalled = true;
150
- },
151
- };
152
- const provider = new searchProvider({
153
- onProviderChange: sinon.fake(),
154
- bookreader: {
155
- leafNumToIndex: sinon.fake(),
156
- plugins: {
157
- search: {
158
- jumpToMatch: sinon.fake(),
159
- },
160
- },
161
- urlPlugin: urlPluginMock,
162
- search: sinon.fake(),
163
- },
164
- });
165
-
166
- const searchInitiatedEvent = new CustomEvent('bookSearchInitiated', { detail: { query: 'foobar' } });
167
- // set initial seachState with a query
168
- provider.onBookSearchInitiated(searchInitiatedEvent);
169
- await provider.updateComplete;
170
- // checking this fn:
171
- provider.updateSearchInUrl();
172
- await provider.updateComplete;
173
-
174
- expect(fieldToSet).toEqual('q');
175
- expect(valueOfFieldToSet).toEqual('foobar');
176
- expect(setUrlParamCalled).toBe(true);
177
- });
178
- });
179
- });