@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,178 +0,0 @@
1
- import sinon from 'sinon';
2
- import WebTTSEngine, { WebTTSSound } from '@/src/plugins/tts/WebTTSEngine.js';
3
- import { afterEventLoop, eventTargetMixin } from '../../utils.js';
4
-
5
- beforeEach(() => {
6
- window.speechSynthesis = {
7
- cancel: sinon.stub(),
8
- speak: sinon.stub(),
9
- pause: sinon.stub(),
10
- resume: sinon.stub(),
11
-
12
- ...eventTargetMixin(),
13
- };
14
- window.SpeechSynthesisUtterance = function (text) {
15
- this.text = text;
16
- Object.assign(this, eventTargetMixin());
17
- };
18
- });
19
-
20
- afterEach(() => {
21
- delete window.speechSynthesis;
22
- delete window.SpeechSynthesisUtterance;
23
- });
24
-
25
- describe('WebTTSEngine', () => {
26
- test('getVoices should include default voice when no actual default', () => {
27
- // iOS devices set all the voices to default -_-
28
- speechSynthesis.getVoices = () => [
29
- {
30
- default: true,
31
- lang: "ar-001",
32
- localService: true,
33
- name: "Majed",
34
- voiceURI: "com.apple.voice.compact.ar-001.Maged",
35
- },
36
- {
37
- default: true,
38
- lang: "bg-BG",
39
- localService: true,
40
- name: "Daria",
41
- voiceURI: "com.apple.voice.compact.bg-BG.Daria",
42
- },
43
- ];
44
- const voices = WebTTSEngine.prototype.getVoices();
45
- expect(voices.length).toBe(3);
46
- expect(voices[0].voiceURI).toBe('bookreader.SystemDefault');
47
- });
48
-
49
- test('getVoices should not include default voice when there is a default', () => {
50
- speechSynthesis.getVoices = () => [
51
- {
52
- default: true,
53
- lang: "ar-001",
54
- localService: true,
55
- name: "Majed",
56
- voiceURI: "com.apple.voice.compact.ar-001.Maged",
57
- },
58
- {
59
- default: false,
60
- lang: "bg-BG",
61
- localService: true,
62
- name: "Daria",
63
- voiceURI: "com.apple.voice.compact.bg-BG.Daria",
64
- },
65
- ];
66
- const voices = WebTTSEngine.prototype.getVoices();
67
- expect(voices.length).toBe(2);
68
- });
69
- });
70
-
71
- describe('WebTTSSound', () => {
72
- describe('setPlaybackRate', () => {
73
- test('works if not playing', () => {
74
- const sound = new WebTTSSound('hello world');
75
- sound.load();
76
- expect(sound.rate).toBe(1);
77
- sound.setPlaybackRate(2);
78
- expect(sound.rate).toBe(2);
79
- });
80
-
81
- test('reloading does not resolve the original promise', async () => {
82
- const sound = new WebTTSSound('hello world');
83
- sound.load();
84
- const finishSpy = sinon.spy();
85
- sound.play().then(finishSpy);
86
- sound.reload();
87
- sound.utterance.dispatchEvent('pause', {});
88
- await afterEventLoop();
89
- sound.utterance.dispatchEvent('end', {});
90
- await afterEventLoop();
91
- expect(finishSpy.callCount).toBe(0);
92
- });
93
- });
94
-
95
- describe('_chromePausingBugFix', () => {
96
- /** @type {sinon.SinonFakeTimers} */
97
- let clock = null;
98
-
99
- beforeEach(() => {
100
- clock = sinon.useFakeTimers();
101
- });
102
-
103
- afterEach(() => {
104
- clock.restore();
105
- });
106
-
107
- test('if speech less than 15s, nothing special', async () => {
108
- const sound = new WebTTSSound('hello world foo bar');
109
- sound.load();
110
- sound.play();
111
- sound._chromePausingBugFix();
112
- clock.tick(10000);
113
- sound.utterance.dispatchEvent('end', {});
114
- await afterEventLoop();
115
- expect(speechSynthesis.pause.callCount).toBe(0);
116
- });
117
-
118
- test('if speech greater than 15s, pause called', async () => {
119
- const sound = new WebTTSSound('foo bah');
120
- sound.load();
121
- sound.play();
122
- sound._chromePausingBugFix();
123
- clock.tick(20000);
124
-
125
- await afterEventLoop();
126
- expect(speechSynthesis.pause.callCount).toBe(1);
127
- });
128
-
129
- test('on pause, stops sound if timed out', async () => {
130
- const sound = new WebTTSSound('foo bah');
131
- sound.load();
132
- sound.play();
133
- sound.stop = sinon.stub();
134
- sound._chromePausingBugFix();
135
- clock.tick(5000);
136
- sound.utterance.dispatchEvent('pause', {});
137
- await afterEventLoop();
138
- clock.tick(15000);
139
-
140
- await afterEventLoop();
141
- expect(sound.stop.callCount).toBe(1);
142
- });
143
- });
144
-
145
- test('fire pause if browser does not do it', async () => {
146
- const clock = sinon.useFakeTimers();
147
- const sound = new WebTTSSound('foo bah');
148
- sound.load();
149
- sound.play();
150
- const dispatchSpy = sinon.spy(sound.utterance, 'dispatchEvent');
151
- sound.pause();
152
- clock.tick(1000);
153
- clock.restore();
154
-
155
- await afterEventLoop();
156
- expect(dispatchSpy.callCount).toBe(1);
157
- expect(dispatchSpy.args[0][0].type).toBe('pause');
158
- });
159
-
160
- test('fire resume if browser does not do it', async () => {
161
- const clock = sinon.useFakeTimers();
162
- const languageGetter = jest.spyOn(window.navigator, 'userAgent', 'get');
163
- languageGetter.mockReturnValue('firefox android');
164
- const sound = new WebTTSSound('foo bah');
165
- sound.load();
166
- sound.play();
167
- sound.started = true;
168
- sound.paused = true;
169
- const dispatchSpy = sinon.spy(sound.utterance, 'dispatchEvent');
170
- sound.resume();
171
- clock.tick(1000);
172
- clock.restore();
173
-
174
- await afterEventLoop();
175
- expect(dispatchSpy.callCount).toBe(1);
176
- expect(dispatchSpy.args[0][0].type).toBe('resume');
177
- });
178
- });
@@ -1,74 +0,0 @@
1
- import * as utils from '@/src/plugins/tts/utils.js';
2
-
3
- describe('approximateWordCount', () => {
4
- const { approximateWordCount } = utils;
5
-
6
- test('Empties', () => {
7
- expect(approximateWordCount('')).toBe(0);
8
- expect(approximateWordCount(' ')).toBe(0);
9
- });
10
-
11
- test('Spaceless', () => {
12
- expect(approximateWordCount('supercalifragilisticexpialidocious')).toBe(1);
13
- });
14
-
15
- test('Basic', () => {
16
- expect(approximateWordCount('the quick brown fox jumped over the lazy dog')).toBe(9);
17
- expect(approximateWordCount('to be or not to be that is the question')).toBe(10);
18
- });
19
-
20
- test('Spacing', () => {
21
- expect(approximateWordCount(' the quick brown fox jumped over the lazy dog ')).toBe(9);
22
- });
23
-
24
- test('Punctuation not separate word (unless separate)', () => {
25
- expect(approximateWordCount('the. quick brown. fox. jumped. over the. lazy dog.')).toBe(9);
26
- expect(approximateWordCount(' . . . . . ')).toBe(5);
27
- });
28
-
29
- test('Realword examples', () => {
30
- expect(approximateWordCount("Albert\u2019s cats had a .large blue dish of milk for breakfast.")).toBe(11);
31
- expect(approximateWordCount("FARM FOLK O nce upon a time there was a sturdy little boy who lived in Belgium. Every morning after he milked the cows, he gave his cats a large blue dish of milk for breakfast.")).toBe(36);
32
- });
33
- });
34
-
35
- describe('toISO6391', () => {
36
- const { toISO6391 } = utils;
37
-
38
- test('ISO 639-1', () => {
39
- expect(toISO6391('en')).toBe('en');
40
- expect(toISO6391('fr')).toBe('fr');
41
- expect(toISO6391('SQ')).toBe('sq');
42
- expect(toISO6391('aa')).toBe('aa');
43
- });
44
-
45
- test('ISO 639-2/T', () => {
46
- expect(toISO6391('amh')).toBe('am');
47
- expect(toISO6391('BIH')).toBe('bh');
48
- });
49
-
50
- test('ISO 639-2/B', () => {
51
- expect(toISO6391('BAQ')).toBe('eu');
52
- expect(toISO6391('chi')).toBe('zh');
53
- });
54
-
55
- test('Name', () => {
56
- expect(toISO6391('english')).toBe('en');
57
- expect(toISO6391('German')).toBe('de');
58
- });
59
-
60
- test('Endonym', () => {
61
- expect(toISO6391('français')).toBe('fr');
62
- expect(toISO6391('汉语')).toBe('zh');
63
- });
64
-
65
- test('Mismatch', () => {
66
- expect(toISO6391('Parseltongue')).toBe(null);
67
- expect(toISO6391('Pig Latin')).toBe(null);
68
- });
69
-
70
- test('Falsey inputs', () => {
71
- expect(toISO6391(null)).toBe(null);
72
- expect(toISO6391('')).toBe(null);
73
- });
74
- });
@@ -1,198 +0,0 @@
1
- import { UrlPlugin } from '@/src/plugins/url/UrlPlugin.js';
2
-
3
- afterEach(() => {
4
- jest.clearAllMocks();
5
- });
6
-
7
- describe('UrlPlugin tests', () => {
8
- const urlPlugin = new UrlPlugin();
9
-
10
- describe('urlStateToUrlString tests', () => {
11
- test('urlStateToUrlString with known states in schema', () => {
12
- const urlState = { page: 'n7', mode: '1up', search: 'foo' };
13
- const urlStateWithQueries = { page: 'n7', mode: '1up', q: 'hello', view: 'theater', sort: 'title_asc' };
14
-
15
- const expectedUrlFromState = 'page/n7/mode/1up?q=foo';
16
- const expectedUrlFromStateWithQueries = 'page/n7/mode/1up?q=hello&view=theater&sort=title_asc';
17
-
18
- expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
19
- expect(urlPlugin.urlStateToUrlString(urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
20
- });
21
-
22
- test('encodes page number', () => {
23
- expect(urlPlugin.urlStateToUrlString({ page: '12/46' })).toBe(`page/12%2F46`);
24
- });
25
-
26
- test('urlStateToUrlString with unknown states in schema', () => {
27
- const urlState = { page: 'n7', mode: '1up' };
28
- const urlStateWithQueries = { page: 'n7', mode: '1up', q: 'hello', viewer: 'theater', sortBy: 'title_asc' };
29
-
30
- const expectedUrlFromState = 'page/n7/mode/1up';
31
- const expectedUrlFromStateWithQueries = 'page/n7/mode/1up?q=hello&viewer=theater&sortBy=title_asc';
32
-
33
- expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
34
- expect(urlPlugin.urlStateToUrlString(urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
35
- });
36
-
37
- test('urlStateToUrlString with boolean value', () => {
38
- const urlState = { page: 'n7', mode: '1up', search: 'foo', view: 'theater', wrapper: 'false' };
39
- const expectedUrlFromState = 'page/n7/mode/1up?q=foo&view=theater&wrapper=false';
40
-
41
- expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
42
- });
43
- });
44
-
45
- describe('urlStringToUrlState tests', () => {
46
- test('urlStringToUrlState without query string', () => {
47
- const url = '/page/n7/mode/2up';
48
- const url1 = '/page/n7/mode/1up';
49
-
50
- expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up'});
51
- expect(urlPlugin.urlStringToUrlState(url1)).toEqual({page: 'n7', mode: '1up'});
52
- });
53
-
54
- test('decodes page number', () => {
55
- expect(urlPlugin.urlStringToUrlState('/page/12%2F46')).toStrictEqual({ page: '12/46' });
56
- });
57
-
58
- test('urlStringToUrlState with deprecated_for', () => {
59
- const url = '/page/n7/mode/2up/search/hello';
60
-
61
- expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
62
- });
63
-
64
- test('urlStringToUrlState with query string', () => {
65
- const url = '/page/n7/mode/2up/search/hello?view=theather&foo=bar&sort=title_asc';
66
- const url1 = '/mode/2up?ref=ol&ui=embed&wrapper=false&view=theater';
67
-
68
- expect(urlPlugin.urlStringToUrlState(url)).toEqual(
69
- {page: 'n7', mode: '2up', q: 'hello', view: 'theather', foo: 'bar', sort: 'title_asc'},
70
- );
71
- expect(urlPlugin.urlStringToUrlState(url1)).toEqual(
72
- {mode: '2up', ref: 'ol', ui: 'embed', wrapper: 'false', view: 'theater'},
73
- );
74
- });
75
-
76
- test('urlStringToUrlState compare search and ?q', () => {
77
- const url = '/page/n7/mode/2up/search/hello';
78
- urlPlugin.urlState = { q: 'hello' };
79
-
80
- expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
81
- });
82
- });
83
-
84
- describe('url plugin helper functions', () => {
85
- test('setUrlParam', () => {
86
- urlPlugin.urlState = {};
87
- urlPlugin.setUrlParam('page', '20');
88
- urlPlugin.setUrlParam('mode', '2up');
89
-
90
- expect(urlPlugin.urlState).toEqual({page: '20', mode: '2up'});
91
- });
92
-
93
- test('removeUrlParam', () => {
94
- urlPlugin.setUrlParam('page', '20');
95
- urlPlugin.setUrlParam('mode', '2up');
96
- urlPlugin.removeUrlParam('mode');
97
-
98
- expect(urlPlugin.urlState).toEqual({page: '20'});
99
- });
100
-
101
- test('getUrlParam', () => {
102
- urlPlugin.setUrlParam('page', '20');
103
- urlPlugin.setUrlParam('mode', '2up');
104
- expect(urlPlugin.getUrlParam('page')).toEqual('20');
105
- expect(urlPlugin.getUrlParam('mode')).toEqual('2up');
106
- });
107
- });
108
-
109
- describe('pullFromAddressBar and pushToAddressBar - hash mode', () => {
110
- test('url first load - empty state', () => {
111
- urlPlugin.urlState = {};
112
- urlPlugin.urlMode = 'hash';
113
-
114
- urlPlugin.pullFromAddressBar({ pathname: '', search: '', hash: '#' });
115
- expect(urlPlugin.urlState).toEqual({});
116
-
117
- urlPlugin.pushToAddressBar();
118
- expect(window.location.hash).toEqual('');
119
- });
120
-
121
- test('url without mode state value - use default', () => {
122
- urlPlugin.urlState = {};
123
- urlPlugin.urlMode = 'hash';
124
-
125
- urlPlugin.pullFromAddressBar({ pathname: '', search: '', hash: '#page/12' });
126
- expect(urlPlugin.urlState).toEqual({page: '12'});
127
-
128
- urlPlugin.pushToAddressBar();
129
- expect(window.location.hash).toEqual('#page/12');
130
- });
131
-
132
- test('url with query param', () => {
133
- urlPlugin.urlState = {};
134
- urlPlugin.urlMode = 'hash';
135
-
136
- urlPlugin.pullFromAddressBar({ pathname: '', search: '', hash: '#page/12?q=hello&view=theater' });
137
- expect(urlPlugin.urlState).toEqual({page: '12', q: 'hello', view: 'theater'});
138
-
139
- urlPlugin.pushToAddressBar();
140
- expect(window.location.hash).toEqual('#page/12?q=hello&view=theater');
141
- });
142
- });
143
-
144
- describe('pullFromAddressBar and pushToAddressBar - history mode', () => {
145
- test('url first load - empty state', () => {
146
- urlPlugin.urlState = {};
147
- urlPlugin.urlHistoryBasePath = '/details/foo';
148
- urlPlugin.urlMode = 'history';
149
-
150
- urlPlugin.pullFromAddressBar({ pathname: '', search: '', hash: '' });
151
- expect(urlPlugin.urlState).toEqual({});
152
-
153
- urlPlugin.pushToAddressBar();
154
- expect(window.location.pathname).toEqual('/details/foo');
155
- });
156
-
157
- test('url without mode state value', () => {
158
- urlPlugin.urlState = {};
159
- urlPlugin.urlHistoryBasePath = '/details/foo/';
160
- urlPlugin.urlMode = 'history';
161
-
162
- urlPlugin.pullFromAddressBar({ pathname: '/details/foo/page/12', search: '', hash: '' });
163
- expect(urlPlugin.urlState).toEqual({page: '12'});
164
-
165
- urlPlugin.pushToAddressBar();
166
- expect(window.location.pathname).toEqual('/details/foo/page/12');
167
- });
168
-
169
- test('url with query param', () => {
170
- urlPlugin.urlState = {};
171
- urlPlugin.urlHistoryBasePath = '/details/foo/';
172
- urlPlugin.urlMode = 'history';
173
-
174
- urlPlugin.pullFromAddressBar({ pathname: '/details/foo/page/12', search: '?q=hello&view=theater', hash: '' });
175
- expect(urlPlugin.urlState).toEqual({page: '12', q: 'hello', view: 'theater'});
176
-
177
- urlPlugin.pushToAddressBar();
178
- const locationUrl = `${window.location.pathname}${window.location.search}`;
179
- expect(locationUrl).toEqual('/details/foo/page/12?q=hello&view=theater');
180
- });
181
-
182
- test('strips leading slash of incoming path name for no double slash', () => {
183
- const urlPlugin = new UrlPlugin();
184
- urlPlugin.urlMode = 'history';
185
-
186
- urlPlugin.urlHistoryBasePath = '/details/SubBookTest/book1/GPORFP/';
187
- urlPlugin.urlState = {
188
- "mode": "1up",
189
- };
190
-
191
- urlPlugin.setUrlParam('sort', 'title_asc');
192
- urlPlugin.setUrlParam('mode', 'thumb');
193
-
194
- expect(window.location.href).toEqual('http://localhost/details/SubBookTest/book1/GPORFP/mode/thumb?sort=title_asc');
195
- });
196
- });
197
-
198
- });
@@ -1,168 +0,0 @@
1
- import BookReader from '@/src/BookReader.js';
2
- import '@/src/plugins/url/plugin.url.js';
3
- import sinon from 'sinon';
4
-
5
- let br;
6
- beforeAll(() => {
7
- document.body.innerHTML = '<div id="BookReader">';
8
- br = new BookReader();
9
- });
10
-
11
- afterEach(() => {
12
- jest.clearAllMocks();
13
- sinon.restore();
14
- });
15
-
16
- describe('Plugin: URL controller', () => {
17
- test('has default option flag', () => {
18
- expect(BookReader.defaultOptions.enableUrlPlugin).toEqual(true);
19
- });
20
-
21
- test('adds url specific fields to BR', () => {
22
- const { defaultOptions } = BookReader;
23
- expect(defaultOptions).toHaveProperty('urlTrackIndex0');
24
- expect(defaultOptions).toHaveProperty('urlTrackedParams');
25
- expect(defaultOptions).toHaveProperty('urlHistoryBasePath');
26
- expect(defaultOptions).toHaveProperty('urlMode');
27
- expect(defaultOptions).toHaveProperty('updateWindowTitle');
28
- expect(defaultOptions).toHaveProperty('defaults');
29
- expect(defaultOptions).toHaveProperty('bookId');
30
- });
31
-
32
- test('has a whitelist of params that it tracks', () => {
33
- ['page', 'search', 'mode', 'region', 'highlight'];
34
- const { defaultOptions: { urlTrackedParams } } = BookReader;
35
- expect(Array.isArray(urlTrackedParams)).toEqual(true);
36
- expect(urlTrackedParams.find(param => param === 'page')).toBeTruthy();
37
- expect(urlTrackedParams.find(param => param === 'search')).toBeTruthy();
38
- expect(urlTrackedParams.find(param => param === 'mode')).toBeTruthy();
39
- expect(urlTrackedParams.find(param => param === 'region')).toBeTruthy();
40
- expect(urlTrackedParams.find(param => param === 'highlight')).toBeTruthy();
41
- expect(urlTrackedParams.find(param => param === 'view')).toBeTruthy();
42
- });
43
-
44
- test('initializes polling for url changes if using hash', () => {
45
- BookReader.prototype.urlStartLocationPolling = jest.fn();
46
- br.init();
47
-
48
- expect(br.urlStartLocationPolling).toHaveBeenCalled();
49
- });
50
-
51
- test('updates URL when index changes', () => {
52
- window.history.replaceState = jest.fn();
53
- BookReader.prototype.currentIndex = jest.fn(() => 1);
54
- BookReader.prototype.urlReadFragment = jest.fn(() => '/page/2/mode/1up');
55
- BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
56
- index: 88,
57
- mode: 1,
58
- search: '',
59
- }));
60
- br.options.urlMode = 'history';
61
- br.init();
62
- br.urlUpdateFragment();
63
-
64
- expect(window.history.replaceState).toHaveBeenCalled();
65
- });
66
-
67
- test('updates URL when mode changes', () => {
68
- window.history.replaceState = jest.fn();
69
- BookReader.prototype.currentIndex = jest.fn(() => 1);
70
- BookReader.prototype.urlReadFragment = jest.fn(() => '/page/2/mode/1up');
71
- BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
72
- index: 2,
73
- mode: 2,
74
- search: '',
75
- }));
76
- br.options.urlMode = 'history';
77
- br.init();
78
- br.urlUpdateFragment();
79
-
80
- expect(window.history.replaceState).toHaveBeenCalled();
81
- });
82
-
83
- test('updates URL when search changes', () => {
84
- window.history.replaceState = jest.fn();
85
- BookReader.prototype.currentIndex = jest.fn(() => 1);
86
- BookReader.prototype.urlReadFragment = jest.fn(() => '');
87
- BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
88
- index: 1,
89
- mode: 2,
90
- search: 'foo',
91
- }));
92
- BookReader.prototype.search = jest.fn();
93
- br.options.urlMode = 'history';
94
- br.init();
95
- br.urlUpdateFragment();
96
-
97
- expect(window.history.replaceState).toHaveBeenCalled();
98
- });
99
-
100
- test('updates URL when view changes', () => {
101
- window.history.replaceState = jest.fn();
102
- BookReader.prototype.currentIndex = jest.fn(() => 1);
103
- BookReader.prototype.urlReadFragment = jest.fn(() => '');
104
- BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
105
- index: 1,
106
- mode: 2,
107
- view: 'theater',
108
- }));
109
- BookReader.prototype.search = jest.fn();
110
- br.options.urlMode = 'history';
111
- br.init();
112
- br.urlUpdateFragment();
113
-
114
- expect(window.history.replaceState).toHaveBeenCalled();
115
- });
116
-
117
- test('switches to hashMode if replaceState errors', () => {
118
- window.history.replaceState = jest.fn(() => {
119
- throw new Error('foo');
120
- });
121
- BookReader.prototype.currentIndex = jest.fn(() => 1);
122
- BookReader.prototype.urlReadFragment = jest.fn(() => '');
123
- BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
124
- index: 1,
125
- mode: 2,
126
- view: 'theater',
127
- }));
128
- BookReader.prototype.search = jest.fn();
129
- br.options.urlMode = 'history';
130
- br.init();
131
- br.urlUpdateFragment();
132
-
133
- expect(window.history.replaceState).toHaveBeenCalled();
134
- expect(br.options.urlMode).toEqual('hash');
135
- });
136
-
137
- test('does not update URL when search in query string', () => {
138
- window.history.replaceState = jest.fn();
139
- BookReader.prototype.currentIndex = jest.fn(() => 1);
140
- BookReader.prototype.urlReadFragment = jest.fn(() => 'mode/2up');
141
- BookReader.prototype.getLocationSearch = jest.fn(() => '?q=foo');
142
- BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
143
- index: 1,
144
- mode: 2,
145
- search: 'foo',
146
- }));
147
- BookReader.prototype.search = jest.fn();
148
- br.options.plugins.search = { initialSearchTerm: 'foo' };
149
- br.options.urlMode = 'history';
150
- br.init();
151
- br.urlUpdateFragment();
152
-
153
- expect(window.history.replaceState).toHaveBeenCalledTimes(0);
154
- });
155
-
156
- test('only q= param is selected from url query params', () => {
157
- const INTIAL_URL = "http://127.0.0.1:8080/BookReaderDemo/demo-internetarchive.html?ocaid=adventuresofoli00dick&q=foo";
158
- const result = br.urlParamsFiltersOnlySearch(INTIAL_URL);
159
- expect(result).toBe("?q=foo");
160
- });
161
-
162
- test('only q= param is selected from url query params with special character', () => {
163
- const INTIAL_URL = "http://127.0.0.1:8080/BookReaderDemo/demo-internetarchive.html?ocaid=adventuresofoli00dick&q=foo%24%24";
164
- const result = br.urlParamsFiltersOnlySearch(INTIAL_URL);
165
- expect(result).toBe("?q=foo%24%24");
166
- });
167
- });
168
-
@@ -1,3 +0,0 @@
1
- process.on("unhandledRejection", (error) => {
2
- throw error;
3
- });
@@ -1,62 +0,0 @@
1
- import {
2
- isChrome, isEdge, isFirefox, isSafari,
3
- } from '@/src/util/browserSniffing.js';
4
-
5
- const TESTS = [
6
- {
7
- name: 'Firefox on Windows 10',
8
- userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0',
9
- vendor: '',
10
- machingFn: isFirefox,
11
- },
12
- {
13
- name: 'Chrome on Windows 10',
14
- userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
15
- vendor: 'Google Inc.',
16
- machingFn: isChrome,
17
- },
18
- {
19
- name: 'Edge on Windows 10',
20
- userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; ServiceUI 14) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362',
21
- vendor: '',
22
- machingFn: isEdge,
23
- },
24
- {
25
- name: 'Edge on Windows 11',
26
- userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0',
27
- vendor: 'Google Inc.',
28
- machingFn: isEdge,
29
- },
30
- {
31
- name: 'IE11 on Windows 10',
32
- userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; Touch; .NET4.0C; .NET4.0E; Tablet PC 2.0; Zoom 3.6.0; rv:11.0) like Gecko',
33
- vendor: '',
34
- machingFn: null,
35
- },
36
- {
37
- name: 'Chromium on Windows 10',
38
- userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3923.0 Safari/537.36',
39
- vendor: 'Google Inc.',
40
- machingFn: isChrome,
41
- },
42
- {
43
- name: 'Safari 12 on Mojave',
44
- userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Safari/605.1.15',
45
- vendor: 'Apple Computer, Inc.',
46
- machingFn: isSafari,
47
- },
48
- {
49
- name: 'Safari 10 on iPhone 7',
50
- userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
51
- vendor: 'Apple Computer, Inc.',
52
- machingFn: isSafari,
53
- },
54
- ];
55
-
56
- for (const fn of [isChrome, isEdge, isFirefox, isSafari]) {
57
- describe(fn.name, () => {
58
- for (const { name, userAgent, vendor, machingFn } of TESTS) {
59
- test(name, () => expect(fn(userAgent, vendor)).toBe(machingFn == fn));
60
- }
61
- });
62
- }