@internetarchive/bookreader 5.0.0-5 → 5.0.0-50-a1
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.
- package/.eslintrc.js +17 -15
- package/.github/workflows/node.js.yml +77 -6
- package/.github/workflows/npm-publish.yml +6 -20
- package/.testcaferc.js +10 -0
- package/BookReader/BookReader.css +131 -339
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.LICENSE.txt +24 -0
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +1493 -0
- package/BookReader/ia-bookreader-bundle.js.LICENSE.txt +17 -0
- package/BookReader/ia-bookreader-bundle.js.map +1 -0
- package/BookReader/icons/close-circle-dark.svg +1 -0
- package/BookReader/icons/magnify-minus.svg +1 -1
- package/BookReader/icons/magnify-plus.svg +1 -1
- package/BookReader/icons/pause.svg +1 -1
- package/BookReader/icons/playback-speed.svg +1 -1
- package/BookReader/icons/read-aloud.svg +1 -1
- package/BookReader/icons/voice.svg +1 -0
- package/BookReader/images/BRicons.svg +2 -2
- package/BookReader/images/books_graphic.svg +1 -1
- package/BookReader/images/icon_book.svg +1 -1
- package/BookReader/images/icon_gear.svg +1 -1
- package/BookReader/images/icon_info.svg +1 -1
- package/BookReader/images/icon_playback-rate.svg +1 -1
- package/BookReader/images/icon_search_button.svg +1 -1
- package/BookReader/images/icon_share.svg +1 -1
- package/BookReader/images/icon_speaker.svg +1 -1
- package/BookReader/images/icon_speaker_open.svg +1 -1
- package/BookReader/images/marker_chap-off.svg +1 -1
- package/BookReader/images/marker_chap-on.svg +1 -1
- package/BookReader/images/marker_srch-on.svg +1 -1
- package/BookReader/jquery-3.js +2 -0
- package/BookReader/jquery-3.js.LICENSE.txt +24 -0
- package/BookReader/plugins/plugin.archive_analytics.js +1 -1
- package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
- package/BookReader/plugins/plugin.autoplay.js +1 -1
- package/BookReader/plugins/plugin.autoplay.js.map +1 -1
- package/BookReader/plugins/plugin.chapters.js +1 -1
- package/BookReader/plugins/plugin.chapters.js.map +1 -1
- package/BookReader/plugins/plugin.iframe.js +1 -1
- package/BookReader/plugins/plugin.iframe.js.map +1 -1
- package/BookReader/plugins/plugin.mobile_nav.js +1 -1
- package/BookReader/plugins/plugin.mobile_nav.js.map +1 -1
- package/BookReader/plugins/plugin.resume.js +1 -1
- package/BookReader/plugins/plugin.resume.js.map +1 -1
- package/BookReader/plugins/plugin.search.js +1 -1
- package/BookReader/plugins/plugin.search.js.map +1 -1
- package/BookReader/plugins/plugin.text_selection.js +1 -1
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.tts.js +1 -1
- package/BookReader/plugins/plugin.tts.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +1 -1
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
- package/BookReader/webcomponents-bundle.js +3 -0
- package/BookReader/webcomponents-bundle.js.LICENSE.txt +9 -0
- package/BookReader/webcomponents-bundle.js.map +1 -0
- package/BookReaderDemo/BookReaderDemo.css +14 -1
- package/BookReaderDemo/IADemoBr.js +148 -0
- package/BookReaderDemo/demo-advanced.html +2 -2
- package/BookReaderDemo/demo-autoplay.html +2 -1
- package/BookReaderDemo/demo-embed-iframe-src.html +2 -1
- package/BookReaderDemo/demo-fullscreen-mobile.html +2 -1
- package/BookReaderDemo/demo-fullscreen.html +2 -1
- package/BookReaderDemo/demo-iiif.html +2 -1
- package/BookReaderDemo/demo-internetarchive.html +84 -17
- package/BookReaderDemo/demo-multiple.html +2 -1
- package/BookReaderDemo/demo-preview-pages.html +2 -1
- package/BookReaderDemo/demo-simple.html +2 -1
- package/BookReaderDemo/demo-vendor-fullscreen.html +2 -1
- package/BookReaderDemo/ia-multiple-volumes-manifest.js +170 -0
- package/BookReaderDemo/immersion-1up.html +2 -1
- package/BookReaderDemo/immersion-mode.html +2 -1
- package/BookReaderDemo/toggle_controls.html +2 -1
- package/BookReaderDemo/view_mode.html +2 -1
- package/BookReaderDemo/viewmode-cycle.html +2 -3
- package/CHANGELOG.md +202 -0
- package/README.md +14 -1
- package/babel.config.js +18 -0
- package/codecov.yml +6 -0
- package/index.html +3 -0
- package/jsconfig.json +19 -0
- package/package.json +66 -56
- package/renovate.json +52 -0
- package/scripts/preversion.js +4 -1
- package/src/BookNavigator/assets/bookmark-colors.js +1 -1
- package/src/BookNavigator/assets/button-base.js +9 -2
- package/src/BookNavigator/assets/ia-logo.js +17 -0
- package/src/BookNavigator/assets/icon_checkmark.js +1 -1
- package/src/BookNavigator/assets/icon_close.js +1 -1
- package/src/BookNavigator/assets/icon_sort_asc.js +5 -0
- package/src/BookNavigator/assets/icon_sort_desc.js +5 -0
- package/src/BookNavigator/assets/icon_sort_neutral.js +5 -0
- package/src/BookNavigator/assets/icon_volumes.js +11 -0
- package/src/BookNavigator/book-navigator.js +583 -0
- package/src/BookNavigator/bookmarks/bookmark-button.js +3 -2
- package/src/BookNavigator/bookmarks/bookmark-edit.js +3 -4
- package/src/BookNavigator/bookmarks/bookmarks-list.js +2 -3
- package/src/BookNavigator/bookmarks/bookmarks-loginCTA.js +3 -8
- package/src/BookNavigator/bookmarks/bookmarks-provider.js +21 -8
- package/src/BookNavigator/bookmarks/ia-bookmarks.js +102 -66
- package/src/BookNavigator/delete-modal-actions.js +1 -1
- package/src/BookNavigator/downloads/downloads-provider.js +36 -21
- package/src/BookNavigator/downloads/downloads.js +41 -25
- package/src/BookNavigator/search/a-search-result.js +18 -13
- package/src/BookNavigator/search/search-provider.js +80 -28
- package/src/BookNavigator/search/search-results.js +10 -18
- package/src/BookNavigator/sharing.js +27 -0
- package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +11 -10
- package/src/BookNavigator/visual-adjustments/visual-adjustments.js +3 -3
- package/src/BookNavigator/volumes/volumes-provider.js +114 -0
- package/src/BookNavigator/volumes/volumes.js +188 -0
- package/src/BookReader/BookModel.js +0 -29
- package/src/BookReader/DebugConsole.js +3 -3
- package/src/BookReader/DragScrollable.js +233 -0
- package/src/BookReader/Mode1Up.js +51 -351
- package/src/BookReader/Mode1UpLit.js +441 -0
- package/src/BookReader/Mode2Up.js +120 -105
- package/src/BookReader/ModeSmoothZoom.js +179 -0
- package/src/BookReader/ModeThumb.js +17 -11
- package/src/BookReader/Navbar/Navbar.js +10 -36
- package/src/BookReader/PageContainer.js +69 -6
- package/src/BookReader/ReduceSet.js +1 -1
- package/src/BookReader/Toolbar/Toolbar.js +10 -37
- package/src/BookReader/options.js +10 -0
- package/src/BookReader/utils/HTMLDimensionsCacher.js +44 -0
- package/src/BookReader/utils/ScrollClassAdder.js +31 -0
- package/src/BookReader/utils.js +92 -13
- package/src/BookReader.js +431 -620
- package/src/assets/icons/close-circle-dark.svg +1 -0
- package/src/assets/icons/magnify-minus.svg +3 -7
- package/src/assets/icons/magnify-plus.svg +3 -7
- package/src/assets/icons/voice.svg +1 -0
- package/src/css/BookReader.scss +0 -12
- package/src/css/_BRComponent.scss +1 -1
- package/src/css/_BRmain.scss +19 -24
- package/src/css/_BRnav.scss +4 -26
- package/src/css/_BRpages.scss +35 -0
- package/src/css/_BRsearch.scss +25 -216
- package/src/css/_TextSelection.scss +14 -17
- package/src/css/_colorbox.scss +2 -2
- package/src/css/_controls.scss +17 -5
- package/src/css/_icons.scss +6 -0
- package/src/ia-bookreader/ia-bookreader.js +224 -0
- package/src/plugins/plugin.autoplay.js +4 -4
- package/src/plugins/plugin.chapters.js +28 -35
- package/src/plugins/plugin.mobile_nav.js +11 -10
- package/src/plugins/plugin.resume.js +3 -3
- package/src/plugins/plugin.text_selection.js +26 -39
- package/src/plugins/plugin.vendor-fullscreen.js +4 -4
- package/src/plugins/search/plugin.search.js +174 -116
- package/src/plugins/search/view.js +63 -179
- package/src/plugins/tts/AbstractTTSEngine.js +46 -37
- package/src/plugins/tts/FestivalTTSEngine.js +13 -14
- package/src/plugins/tts/PageChunk.js +15 -21
- package/src/plugins/tts/PageChunkIterator.js +8 -12
- package/src/plugins/tts/WebTTSEngine.js +66 -69
- package/src/plugins/tts/plugin.tts.js +92 -109
- package/src/plugins/tts/utils.js +0 -9
- package/src/plugins/url/UrlPlugin.js +184 -0
- package/src/plugins/{plugin.url.js → url/plugin.url.js} +28 -6
- package/src/util/manifestGenerator.js +0 -0
- package/tests/e2e/README.md +37 -0
- package/tests/e2e/autoplay.test.js +2 -2
- package/tests/e2e/base.test.js +7 -7
- package/tests/e2e/helpers/base.js +9 -3
- package/tests/e2e/helpers/debug.js +1 -1
- package/tests/e2e/helpers/desktopSearch.js +14 -13
- package/tests/e2e/helpers/mobileSearch.js +3 -3
- package/tests/e2e/helpers/params.js +17 -0
- package/tests/e2e/models/Navigation.js +13 -4
- package/tests/e2e/rightToLeft.test.js +4 -5
- package/tests/e2e/viewmode.test.js +38 -33
- package/tests/jest/BookNavigator/book-navigator.test.js +634 -0
- package/tests/jest/BookNavigator/bookmarks/bookmark-button.test.js +43 -0
- package/tests/{karma → jest}/BookNavigator/bookmarks/bookmark-edit.test.js +25 -26
- package/tests/{karma → jest}/BookNavigator/bookmarks/bookmarks-list.test.js +41 -42
- package/tests/jest/BookNavigator/bookmarks/ia-bookmarks.test.js +45 -0
- package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +67 -0
- package/tests/jest/BookNavigator/downloads/downloads.test.js +53 -0
- package/tests/jest/BookNavigator/search/search-provider.test.js +167 -0
- package/tests/{karma/BookNavigator → jest/BookNavigator/search}/search-results.test.js +102 -58
- package/tests/jest/BookNavigator/sharing/sharing-provider.test.js +49 -0
- package/tests/jest/BookNavigator/visual-adjustments.test.js +200 -0
- package/tests/jest/BookNavigator/volumes/volumes-provider.test.js +184 -0
- package/tests/jest/BookNavigator/volumes/volumes.test.js +97 -0
- package/tests/{BookReader → jest/BookReader}/BookModel.test.js +34 -14
- package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +176 -0
- package/tests/{BookReader → jest/BookReader}/DebugConsole.test.js +1 -1
- package/tests/{BookReader → jest/BookReader}/ImageCache.test.js +4 -4
- package/tests/jest/BookReader/Mode1UpLit.test.js +92 -0
- package/tests/{BookReader → jest/BookReader}/Mode2Up.test.js +36 -15
- package/tests/jest/BookReader/ModeSmoothZoom.test.js +149 -0
- package/tests/jest/BookReader/ModeThumb.test.js +71 -0
- package/tests/{BookReader → jest/BookReader}/Navbar/Navbar.test.js +7 -7
- package/tests/{BookReader → jest/BookReader}/PageContainer.test.js +88 -6
- package/tests/{BookReader → jest/BookReader}/ReduceSet.test.js +1 -1
- package/tests/{BookReader → jest/BookReader}/Toolbar/Toolbar.test.js +2 -2
- package/tests/jest/BookReader/utils/HTMLDimensionsCacher.test.js +59 -0
- package/tests/jest/BookReader/utils/ScrollClassAdder.test.js +49 -0
- package/tests/{BookReader → jest/BookReader}/utils/classes.test.js +1 -1
- package/tests/jest/BookReader/utils.test.js +186 -0
- package/tests/jest/BookReader.keyboard.test.js +190 -0
- package/tests/{BookReader.options.test.js → jest/BookReader.options.test.js} +9 -1
- package/tests/{BookReader.test.js → jest/BookReader.test.js} +18 -37
- package/tests/{plugins → jest/plugins}/plugin.archive_analytics.test.js +2 -2
- package/tests/{plugins → jest/plugins}/plugin.autoplay.test.js +4 -4
- package/tests/{plugins → jest/plugins}/plugin.chapters.test.js +10 -11
- package/tests/{plugins → jest/plugins}/plugin.iframe.test.js +2 -2
- package/tests/{plugins → jest/plugins}/plugin.mobile_nav.test.js +5 -5
- package/tests/{plugins → jest/plugins}/plugin.resume.test.js +3 -3
- package/tests/{plugins → jest/plugins}/plugin.text_selection.test.js +39 -47
- package/tests/{plugins → jest/plugins}/plugin.vendor-fullscreen.test.js +2 -2
- package/tests/{plugins → jest/plugins}/search/plugin.search.test.js +63 -47
- package/tests/{plugins → jest/plugins}/search/plugin.search.view.test.js +35 -6
- package/tests/{plugins → jest/plugins}/tts/AbstractTTSEngine.test.js +9 -9
- package/tests/{plugins → jest/plugins}/tts/FestivalTTSEngine.test.js +4 -4
- package/tests/{plugins → jest/plugins}/tts/PageChunk.test.js +1 -1
- package/tests/{plugins → jest/plugins}/tts/PageChunkIterator.test.js +3 -3
- package/tests/{plugins → jest/plugins}/tts/WebTTSEngine.test.js +1 -1
- package/tests/{plugins → jest/plugins}/tts/utils.test.js +3 -28
- package/tests/jest/plugins/url/UrlPlugin.test.js +190 -0
- package/tests/{plugins → jest/plugins/url}/plugin.url.test.js +33 -14
- package/tests/{util → jest/util}/browserSniffing.test.js +1 -1
- package/tests/{util → jest/util}/docCookies.test.js +1 -1
- package/tests/{util → jest/util}/strings.test.js +1 -1
- package/tests/{utils.js → jest/utils.js} +38 -0
- package/webpack.config.js +11 -5
- package/.babelrc +0 -12
- package/.dependabot/config.yml +0 -6
- package/.testcaferc.json +0 -5
- package/BookReader/bookreader-component-bundle.js +0 -1450
- package/BookReader/bookreader-component-bundle.js.LICENSE.txt +0 -38
- package/BookReader/bookreader-component-bundle.js.map +0 -1
- package/BookReader/jquery-1.10.1.js +0 -2
- package/BookReader/jquery-1.10.1.js.LICENSE.txt +0 -24
- package/BookReader/plugins/plugin.menu_toggle.js +0 -2
- package/BookReader/plugins/plugin.menu_toggle.js.map +0 -1
- package/BookReaderDemo/bookreader-template-bundle.js +0 -7178
- package/BookReaderDemo/demo-plugin-menu-toggle.html +0 -34
- package/karma.conf.js +0 -23
- package/src/BookNavigator/BookModel.js +0 -14
- package/src/BookNavigator/BookNavigator.js +0 -438
- package/src/BookNavigator/assets/book-loader.js +0 -27
- package/src/BookNavigator/br-fullscreen-mgr.js +0 -83
- package/src/BookReaderComponent/BookReaderComponent.js +0 -112
- package/src/ItemNavigator/ItemNavigator.js +0 -372
- package/src/ItemNavigator/providers/sharing.js +0 -29
- package/src/Layers/sharing/sharing-provider.js +0 -22
- package/src/dragscrollable-br.js +0 -261
- package/src/plugins/menu_toggle/plugin.menu_toggle.js +0 -324
- package/src/plugins/plugin.bookmarks.js +0 -50
- package/tests/BookReader/BookReaderPublicFunctions.test.js +0 -171
- package/tests/BookReader/Mode1Up.test.js +0 -164
- package/tests/BookReader/utils.test.js +0 -109
- package/tests/e2e/ia-production/ia-prod-base.js +0 -17
- package/tests/karma/BookNavigator/book-navigator.test.js +0 -132
- package/tests/karma/BookNavigator/visual-adjustments.test.js +0 -201
- package/tests/plugins/menu_toggle/plugin.menu_toggle.test.js +0 -68
@@ -1,4 +1,4 @@
|
|
1
|
-
import {PageContainer} from '
|
1
|
+
import {PageContainer, boxToSVGRect, createSVGPageLayer, renderBoxesInPageContainerLayer} from '@/src/BookReader/PageContainer.js';
|
2
2
|
|
3
3
|
describe('constructor', () => {
|
4
4
|
test('protected books', () => {
|
@@ -31,7 +31,7 @@ describe('constructor', () => {
|
|
31
31
|
});
|
32
32
|
});
|
33
33
|
|
34
|
-
describe('update',
|
34
|
+
describe('update', () => {
|
35
35
|
test('dimensions sets CSS', () => {
|
36
36
|
const pc = new PageContainer(null, {});
|
37
37
|
pc.update({ dimensions: { left: 20 } });
|
@@ -62,17 +62,18 @@ describe('update', async () => {
|
|
62
62
|
expect(pc.$img[0].style.background).toBe('');
|
63
63
|
});
|
64
64
|
|
65
|
-
test('removes image between updates', () => {
|
65
|
+
test('removes image between updates only if changed', () => {
|
66
66
|
const fakeImageCache = {
|
67
67
|
imageLoaded: () => true,
|
68
|
-
image: () => $(
|
68
|
+
image: (index, reduce) => $(`<img src="page${index}-${reduce}.jpg" />`),
|
69
69
|
};
|
70
70
|
const pc = new PageContainer({index: 12}, {imageCache: fakeImageCache});
|
71
71
|
pc.update({ reduce: 7 });
|
72
72
|
const $im1 = pc.$img;
|
73
73
|
pc.update({ reduce: 7 });
|
74
|
-
|
75
|
-
|
74
|
+
expect(pc.$img).toBe($im1);
|
75
|
+
pc.update({ reduce: 16 });
|
76
|
+
expect(pc.$img).not.toBe($im1);
|
76
77
|
expect($im1.parent().length).toBe(0);
|
77
78
|
});
|
78
79
|
|
@@ -113,3 +114,84 @@ describe('update', async () => {
|
|
113
114
|
expect(pc.$img.css('background')).toBeFalsy();
|
114
115
|
});
|
115
116
|
});
|
117
|
+
|
118
|
+
describe('createSVGPageLayer', () => {
|
119
|
+
test('Does what it says', () => {
|
120
|
+
const svg = createSVGPageLayer({ width: 100, height: 200}, 'myClass');
|
121
|
+
expect(svg.getAttribute('viewBox')).toBe('0 0 100 200');
|
122
|
+
expect(svg.getAttribute('class')).toContain('myClass');
|
123
|
+
});
|
124
|
+
});
|
125
|
+
|
126
|
+
describe('boxToSVGRect', () => {
|
127
|
+
test('Does what it says', () => {
|
128
|
+
const rect = boxToSVGRect({ l: 100, r: 200, t: 300, b: 500 });
|
129
|
+
expect(rect.getAttribute('x')).toBe('100');
|
130
|
+
expect(rect.getAttribute('y')).toBe('300');
|
131
|
+
expect(rect.getAttribute('width')).toBe('100');
|
132
|
+
expect(rect.getAttribute('height')).toBe('200');
|
133
|
+
});
|
134
|
+
});
|
135
|
+
|
136
|
+
describe('renderBoxesInPageContainerLayer', () => {
|
137
|
+
test('Handles missing layer', () => {
|
138
|
+
const container = document.createElement('div');
|
139
|
+
const page = { width: 100, height: 200 };
|
140
|
+
const boxes = [{l: 1, r: 2, t: 3, b: 4}];
|
141
|
+
renderBoxesInPageContainerLayer('foo', boxes, page, container);
|
142
|
+
expect(container.querySelector('.foo')).toBeTruthy();
|
143
|
+
expect(container.querySelectorAll('.foo rect').length).toBe(1);
|
144
|
+
});
|
145
|
+
|
146
|
+
test('Handles existing layer', () => {
|
147
|
+
const container = document.createElement('div');
|
148
|
+
const layer = document.createElement('svg');
|
149
|
+
layer.classList.add('foo');
|
150
|
+
container.append(layer);
|
151
|
+
|
152
|
+
const page = { width: 100, height: 200 };
|
153
|
+
const boxes = [{l: 1, r: 2, t: 3, b: 4}];
|
154
|
+
renderBoxesInPageContainerLayer('foo', boxes, page, container);
|
155
|
+
expect(container.querySelector('.foo')).toBe(layer);
|
156
|
+
expect(container.querySelectorAll('.foo rect').length).toBe(1);
|
157
|
+
});
|
158
|
+
|
159
|
+
test('Adds layer after image if it exists', () => {
|
160
|
+
const container = document.createElement('div');
|
161
|
+
const img = document.createElement('img');
|
162
|
+
img.classList.add('BRpageimage');
|
163
|
+
container.append(img);
|
164
|
+
|
165
|
+
const page = { width: 100, height: 200 };
|
166
|
+
const boxes = [{l: 1, r: 2, t: 3, b: 4}];
|
167
|
+
renderBoxesInPageContainerLayer('foo', boxes, page, container);
|
168
|
+
expect(container.querySelector('.foo')).toBeTruthy();
|
169
|
+
expect(container.children[0].getAttribute('class')).toBe('BRpageimage');
|
170
|
+
expect(container.children[1].getAttribute('class')).toBe('BRPageLayer foo');
|
171
|
+
});
|
172
|
+
|
173
|
+
test('Renders all boxes', () => {
|
174
|
+
const container = document.createElement('div');
|
175
|
+
const page = { width: 100, height: 200 };
|
176
|
+
const boxes = [{l: 1, r: 2, t: 3, b: 4}, {l: 1, r: 2, t: 3, b: 4}, {l: 1, r: 2, t: 3, b: 4}];
|
177
|
+
renderBoxesInPageContainerLayer('foo', boxes, page, container);
|
178
|
+
expect(container.querySelectorAll('.foo rect').length).toBe(3);
|
179
|
+
});
|
180
|
+
|
181
|
+
test('Adds optional classes', () => {
|
182
|
+
const container = document.createElement('div');
|
183
|
+
const page = { width: 100, height: 200 };
|
184
|
+
const boxes = [{l: 1, r: 2, t: 3, b: 4}, {l: 1, r: 2, t: 3, b: 4}, {l: 1, r: 2, t: 3, b: 4}];
|
185
|
+
renderBoxesInPageContainerLayer('foo', boxes, page, container, ['match-1', 'match-2', 'match-3']);
|
186
|
+
const rects = Array.from(container.querySelectorAll('.foo rect'));
|
187
|
+
expect(rects.map(r => r.getAttribute('class'))).toEqual(['match-1', 'match-2', 'match-3']);
|
188
|
+
});
|
189
|
+
|
190
|
+
test('Handles no boxes', () => {
|
191
|
+
const container = document.createElement('div');
|
192
|
+
const page = { width: 100, height: 200 };
|
193
|
+
const boxes = [];
|
194
|
+
renderBoxesInPageContainerLayer('foo', boxes, page, container);
|
195
|
+
expect(container.querySelectorAll('.foo rect').length).toBe(0);
|
196
|
+
});
|
197
|
+
});
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import sinon from 'sinon';
|
2
2
|
|
3
|
-
import { createPopup } from '
|
3
|
+
import { createPopup } from '@/src/BookReader/Toolbar/Toolbar.js';
|
4
4
|
|
5
5
|
afterEach(() => {
|
6
6
|
sinon.restore();
|
7
|
-
})
|
7
|
+
});
|
8
8
|
|
9
9
|
describe('createPopup', () => {
|
10
10
|
test('calls window.open', () => {
|
@@ -0,0 +1,59 @@
|
|
1
|
+
// @ts-check
|
2
|
+
import sinon from 'sinon';
|
3
|
+
import { HTMLDimensionsCacher } from '@/src/BookReader/utils/HTMLDimensionsCacher';
|
4
|
+
|
5
|
+
describe('HTMLDimensionsCacher', () => {
|
6
|
+
test('Does not read from element directly', () => {
|
7
|
+
const element = document.createElement('div');
|
8
|
+
const getBoundingClientRectStub = element.getBoundingClientRect = sinon.stub().returns({ top: 10, left: 20 });
|
9
|
+
const clientWidthStub = sinon.stub().returns(300);
|
10
|
+
const clientHeightStub = sinon.stub().returns(500);
|
11
|
+
Object.defineProperty(element, 'clientWidth', { get: clientWidthStub });
|
12
|
+
Object.defineProperty(element, 'clientHeight', { get: clientHeightStub });
|
13
|
+
|
14
|
+
const hdc = new HTMLDimensionsCacher(element);
|
15
|
+
hdc.clientHeight;
|
16
|
+
expect(getBoundingClientRectStub.callCount).toBe(0);
|
17
|
+
expect(clientWidthStub.callCount).toBe(0);
|
18
|
+
expect(clientHeightStub.callCount).toBe(0);
|
19
|
+
});
|
20
|
+
|
21
|
+
test('Read from element when calling update', () => {
|
22
|
+
const element = document.createElement('div');
|
23
|
+
const getBoundingClientRectStub = element.getBoundingClientRect = sinon.stub().returns({ top: 10, left: 20 });
|
24
|
+
const clientWidthStub = sinon.stub().returns(300);
|
25
|
+
const clientHeightStub = sinon.stub().returns(500);
|
26
|
+
Object.defineProperty(element, 'clientWidth', { get: clientWidthStub });
|
27
|
+
Object.defineProperty(element, 'clientHeight', { get: clientHeightStub });
|
28
|
+
|
29
|
+
const hdc = new HTMLDimensionsCacher(element);
|
30
|
+
hdc.updateClientSizes();
|
31
|
+
expect(getBoundingClientRectStub.callCount).toBe(1);
|
32
|
+
expect(clientWidthStub.callCount).toBe(1);
|
33
|
+
expect(clientHeightStub.callCount).toBe(1);
|
34
|
+
|
35
|
+
expect(hdc.boundingClientRect).toEqual({ top: 10, left: 20 });
|
36
|
+
expect(hdc.clientWidth).toBe(300);
|
37
|
+
expect(hdc.clientHeight).toBe(500);
|
38
|
+
});
|
39
|
+
|
40
|
+
test('Does not listen for window resizes when not attached', () => {
|
41
|
+
const element = document.createElement('div');
|
42
|
+
const hdc = new HTMLDimensionsCacher(element);
|
43
|
+
const dummyWindow = new EventTarget();
|
44
|
+
const debouncedUpdateSpy = sinon.spy(hdc, 'debouncedUpdateClientSizes');
|
45
|
+
|
46
|
+
dummyWindow.dispatchEvent(new Event('resize', {}));
|
47
|
+
expect(debouncedUpdateSpy.callCount).toBe(0);
|
48
|
+
|
49
|
+
hdc.attachResizeListener(dummyWindow);
|
50
|
+
|
51
|
+
dummyWindow.dispatchEvent(new Event('resize', {}));
|
52
|
+
expect(debouncedUpdateSpy.callCount).toBe(1);
|
53
|
+
|
54
|
+
hdc.detachResizeListener(dummyWindow);
|
55
|
+
|
56
|
+
dummyWindow.dispatchEvent(new Event('resize', {}));
|
57
|
+
expect(debouncedUpdateSpy.callCount).toBe(1);
|
58
|
+
});
|
59
|
+
});
|
@@ -0,0 +1,49 @@
|
|
1
|
+
// @ts-check
|
2
|
+
import sinon from 'sinon';
|
3
|
+
import { ScrollClassAdder } from '@/src/BookReader/utils/ScrollClassAdder';
|
4
|
+
|
5
|
+
describe('ScrollClassAdder', () => {
|
6
|
+
test('Does not attach during construction', () => {
|
7
|
+
const element = document.createElement('div');
|
8
|
+
const attachSpy = sinon.spy(ScrollClassAdder.prototype, 'attach');
|
9
|
+
new ScrollClassAdder(element, 'foo');
|
10
|
+
expect(attachSpy.callCount).toBe(0);
|
11
|
+
});
|
12
|
+
|
13
|
+
test('Attach/detach call correct methods', () => {
|
14
|
+
const el = document.createElement('div');
|
15
|
+
const addEventListenerSpy = sinon.spy(el, 'addEventListener');
|
16
|
+
const removeEventListenerSpy = sinon.spy(el, 'removeEventListener');
|
17
|
+
const sca = new ScrollClassAdder(el, 'foo');
|
18
|
+
expect(addEventListenerSpy.callCount).toBe(0);
|
19
|
+
sca.attach();
|
20
|
+
expect(addEventListenerSpy.callCount).toBe(1);
|
21
|
+
sca.detach();
|
22
|
+
expect(removeEventListenerSpy.callCount).toBe(1);
|
23
|
+
});
|
24
|
+
|
25
|
+
test('onScroll adds class at right time', () => {
|
26
|
+
const clock = sinon.useFakeTimers();
|
27
|
+
const el = document.createElement('div');
|
28
|
+
const sca = new ScrollClassAdder(el, 'foo');
|
29
|
+
expect(el.getAttribute('class')).toBeFalsy();
|
30
|
+
sca.onScroll();
|
31
|
+
expect(el.getAttribute('class')).toBe('foo');
|
32
|
+
clock.tick(600);
|
33
|
+
expect(el.getAttribute('class')).toBeFalsy();
|
34
|
+
|
35
|
+
sca.onScroll();
|
36
|
+
expect(el.getAttribute('class')).toBe('foo');
|
37
|
+
clock.tick(500);
|
38
|
+
expect(el.getAttribute('class')).toBe('foo');
|
39
|
+
sca.onScroll();
|
40
|
+
expect(el.getAttribute('class')).toBe('foo');
|
41
|
+
clock.tick(100);
|
42
|
+
expect(el.getAttribute('class')).toBe('foo');
|
43
|
+
clock.tick(499);
|
44
|
+
expect(el.getAttribute('class')).toBe('foo');
|
45
|
+
clock.tick(1);
|
46
|
+
expect(el.getAttribute('class')).toBeFalsy();
|
47
|
+
clock.restore();
|
48
|
+
});
|
49
|
+
});
|
@@ -0,0 +1,186 @@
|
|
1
|
+
import sinon from 'sinon';
|
2
|
+
import { afterEventLoop } from '../utils.js';
|
3
|
+
import {
|
4
|
+
clamp,
|
5
|
+
cssPercentage,
|
6
|
+
debounce,
|
7
|
+
decodeURIComponentPlus,
|
8
|
+
encodeURIComponentPlus,
|
9
|
+
escapeHTML,
|
10
|
+
getActiveElement,
|
11
|
+
isInputActive,
|
12
|
+
poll,
|
13
|
+
polyfillCustomEvent,
|
14
|
+
PolyfilledCustomEvent,
|
15
|
+
sleep,
|
16
|
+
} from '@/src/BookReader/utils.js';
|
17
|
+
|
18
|
+
test('clamp function returns Math.min(Math.max(value, min), max)', () => {
|
19
|
+
expect(clamp(2,1,3)).toEqual(2);
|
20
|
+
});
|
21
|
+
|
22
|
+
test('calculate a percentage suitable for CSS', () => {
|
23
|
+
expect(cssPercentage(2,1)).toEqual('200%');
|
24
|
+
});
|
25
|
+
|
26
|
+
test('escapeHTML function which replaces the string', () => {
|
27
|
+
expect(escapeHTML('Me & You')).toEqual('Me & You');
|
28
|
+
expect(escapeHTML('Me > You')).toEqual('Me > You');
|
29
|
+
expect(escapeHTML('Me < You')).toEqual('Me < You');
|
30
|
+
expect(escapeHTML('Me " You')).toEqual('Me " You');
|
31
|
+
});
|
32
|
+
|
33
|
+
test('Decodes a URI component and converts + to emptyStr', () => {
|
34
|
+
expect(decodeURIComponentPlus("https%3A%2F%2Farchive.org%2Fskr+")).toEqual("https://archive.org/skr ");
|
35
|
+
expect(decodeURIComponentPlus("%3Fx%3D+test")).toEqual("?x= test");
|
36
|
+
});
|
37
|
+
|
38
|
+
test('Encodes a URI component and converts emptyStr to +', () => {
|
39
|
+
expect(encodeURIComponentPlus("?x=test ")).toEqual("%3Fx%3Dtest+");
|
40
|
+
expect(encodeURIComponentPlus("ABC abc 123")).toEqual("ABC+abc+123");
|
41
|
+
});
|
42
|
+
|
43
|
+
describe('getActiveElement', () => {
|
44
|
+
test('Can ignore shadow DOM', () => {
|
45
|
+
const doc = {activeElement: { shadowRoot: {activeElement: {}}}};
|
46
|
+
expect(getActiveElement(doc, false)).toBe(doc.activeElement);
|
47
|
+
});
|
48
|
+
|
49
|
+
test('Can traverse shadow DOM', () => {
|
50
|
+
const doc = {activeElement: { shadowRoot: {activeElement: {}}}};
|
51
|
+
expect(getActiveElement(doc, true)).toBe(doc.activeElement.shadowRoot.activeElement);
|
52
|
+
});
|
53
|
+
|
54
|
+
test('Handles non-shadow elements', () => {
|
55
|
+
const doc = {activeElement: {}};
|
56
|
+
expect(getActiveElement(doc, true)).toBe(doc.activeElement);
|
57
|
+
});
|
58
|
+
|
59
|
+
test('Handles no active element', () => {
|
60
|
+
const doc = {activeElement: null};
|
61
|
+
expect(getActiveElement(doc, true)).toBe(null);
|
62
|
+
});
|
63
|
+
});
|
64
|
+
|
65
|
+
describe('isInputActive', () => {
|
66
|
+
test('Handles no activeElement', () => {
|
67
|
+
expect(isInputActive({activeElement: null})).toBe(false);
|
68
|
+
});
|
69
|
+
|
70
|
+
test('Handles deep input activeElement', () => {
|
71
|
+
const doc = {activeElement: { shadowRoot: {activeElement: { tagName: 'INPUT' }}}};
|
72
|
+
expect(isInputActive(doc)).toBe(true);
|
73
|
+
});
|
74
|
+
|
75
|
+
test('Handles deep non-input activeElement', () => {
|
76
|
+
const doc = {activeElement: { shadowRoot: {activeElement: { tagName: 'A' }}}};
|
77
|
+
expect(isInputActive(doc)).toBe(false);
|
78
|
+
});
|
79
|
+
|
80
|
+
test('Handles textarea activeElement', () => {
|
81
|
+
const doc = {activeElement: { tagName: 'TEXTAREA' }};
|
82
|
+
expect(isInputActive(doc)).toBe(true);
|
83
|
+
});
|
84
|
+
});
|
85
|
+
|
86
|
+
describe('debounce', () => {
|
87
|
+
/** @type {sinon.SinonFakeTimers} */
|
88
|
+
let clock;
|
89
|
+
beforeEach(() => clock = sinon.useFakeTimers());
|
90
|
+
afterEach(() => clock.restore());
|
91
|
+
|
92
|
+
test('testing debounce', () => {
|
93
|
+
const func = jest.fn();
|
94
|
+
const debouncedFunc = debounce(func, 1000);
|
95
|
+
// Call it immediately
|
96
|
+
debouncedFunc();
|
97
|
+
expect(func).toHaveBeenCalledTimes(0); // func not called
|
98
|
+
|
99
|
+
// Call it several times with 500ms between each call
|
100
|
+
for (let i = 0; i < 10; i++) {
|
101
|
+
clock.tick(500);
|
102
|
+
debouncedFunc();
|
103
|
+
}
|
104
|
+
expect(func).toHaveBeenCalledTimes(0); // func not called
|
105
|
+
|
106
|
+
// wait 1000ms
|
107
|
+
clock.tick(1000);
|
108
|
+
expect(func).toHaveBeenCalledTimes(1); // func called
|
109
|
+
});
|
110
|
+
});
|
111
|
+
|
112
|
+
|
113
|
+
describe('polyfillCustomEvent', () => {
|
114
|
+
test('Overrides when missing', () => {
|
115
|
+
const win = {};
|
116
|
+
polyfillCustomEvent(win);
|
117
|
+
expect(win).toHaveProperty('CustomEvent');
|
118
|
+
});
|
119
|
+
|
120
|
+
test('Overrides when not a function', () => {
|
121
|
+
const win = { CustomEvent: {} };
|
122
|
+
polyfillCustomEvent(win);
|
123
|
+
expect(typeof win.CustomEvent).toBe('function');
|
124
|
+
});
|
125
|
+
});
|
126
|
+
|
127
|
+
describe('PolyfilledCustomEvent', () => {
|
128
|
+
test('Can be called as a constructor', () => {
|
129
|
+
new PolyfilledCustomEvent('foo');
|
130
|
+
});
|
131
|
+
|
132
|
+
test('Calls deprecated browser methods', () => {
|
133
|
+
const createEventSpy = sinon.spy(document, 'createEvent');
|
134
|
+
const initCustomEventSpy = sinon.spy(CustomEvent.prototype, 'initCustomEvent');
|
135
|
+
new PolyfilledCustomEvent('foo');
|
136
|
+
expect(createEventSpy.callCount).toBe(1);
|
137
|
+
expect(initCustomEventSpy.callCount).toBe(1);
|
138
|
+
});
|
139
|
+
});
|
140
|
+
|
141
|
+
describe('poll', () => {
|
142
|
+
beforeEach(() => jest.useFakeTimers());
|
143
|
+
afterEach(() => jest.useRealTimers());
|
144
|
+
test('polls until condition is true', async () => {
|
145
|
+
const fakeSleep = sinon.spy((ms) => jest.advanceTimersByTime(ms));
|
146
|
+
|
147
|
+
const returns = [null, null, 'foo'];
|
148
|
+
const check = sinon.spy(() => returns.shift());
|
149
|
+
const result = await poll(check, {_sleep: fakeSleep});
|
150
|
+
expect(fakeSleep.callCount).toBe(2);
|
151
|
+
expect(result).toBe('foo');
|
152
|
+
expect(check.callCount).toBe(3);
|
153
|
+
});
|
154
|
+
|
155
|
+
test('times out eventually', async () => {
|
156
|
+
const fakeSleep = sinon.spy((ms) => jest.advanceTimersByTime(ms));
|
157
|
+
|
158
|
+
const check = sinon.stub().returns(null);
|
159
|
+
const result = await poll(check, {_sleep: fakeSleep});
|
160
|
+
expect(result).toBeUndefined();
|
161
|
+
expect(check.callCount).toBe(10);
|
162
|
+
});
|
163
|
+
});
|
164
|
+
|
165
|
+
describe('sleep', () => {
|
166
|
+
test('Sleep 0 doest not called immediately', async () => {
|
167
|
+
const spy = sinon.spy();
|
168
|
+
sleep(0).then(spy);
|
169
|
+
expect(spy.callCount).toBe(0);
|
170
|
+
await afterEventLoop();
|
171
|
+
expect(spy.callCount).toBe(1);
|
172
|
+
});
|
173
|
+
|
174
|
+
test('Waits the appropriate ms', async () => {
|
175
|
+
const clock = sinon.useFakeTimers();
|
176
|
+
const spy = sinon.spy();
|
177
|
+
sleep(10).then(spy);
|
178
|
+
expect(spy.callCount).toBe(0);
|
179
|
+
clock.tick(10);
|
180
|
+
expect(spy.callCount).toBe(0);
|
181
|
+
clock.restore();
|
182
|
+
|
183
|
+
await afterEventLoop();
|
184
|
+
expect(spy.callCount).toBe(1);
|
185
|
+
});
|
186
|
+
});
|
@@ -0,0 +1,190 @@
|
|
1
|
+
import BookReader from '@/src/BookReader.js';
|
2
|
+
import * as utils from '@/src/BookReader/utils.js';
|
3
|
+
|
4
|
+
let br;
|
5
|
+
beforeAll(() => {
|
6
|
+
document.body.innerHTML = '<div id="BookReader">';
|
7
|
+
br = new BookReader();
|
8
|
+
});
|
9
|
+
|
10
|
+
afterEach(() => {
|
11
|
+
jest.clearAllMocks();
|
12
|
+
});
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Only run init() once. Otherwise multiple EventListeners will be added.
|
16
|
+
*/
|
17
|
+
test('Initialzation enables IntersectionObserver and defaults', () => {
|
18
|
+
const observe = jest.fn();
|
19
|
+
window.IntersectionObserver = jest.fn(() => ({
|
20
|
+
observe
|
21
|
+
}));
|
22
|
+
br.init();
|
23
|
+
expect(br.hasKeyFocus).toBe(true);
|
24
|
+
expect(observe).toHaveBeenCalledTimes(1);
|
25
|
+
});
|
26
|
+
|
27
|
+
describe('Keyboard shortcuts turned off', () => {
|
28
|
+
|
29
|
+
test('Focus flag disables', () => {
|
30
|
+
br.next = jest.fn();
|
31
|
+
br.hasKeyFocus = false;
|
32
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'ArrowDown'});
|
33
|
+
keyEvent.preventDefault = jest.fn();
|
34
|
+
document.dispatchEvent(keyEvent);
|
35
|
+
expect(br.next).toHaveBeenCalledTimes(0);
|
36
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(0);
|
37
|
+
// Must reset for following tests
|
38
|
+
br.hasKeyFocus = true;
|
39
|
+
});
|
40
|
+
|
41
|
+
test('Input active disables', () => {
|
42
|
+
// eslint-disable-next-line no-import-assign
|
43
|
+
utils.isInputActive = jest.fn(() => true);
|
44
|
+
br.next = jest.fn();
|
45
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'ArrowDown'});
|
46
|
+
keyEvent.preventDefault = jest.fn();
|
47
|
+
document.dispatchEvent(keyEvent);
|
48
|
+
expect(br.next).toHaveBeenCalledTimes(0);
|
49
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(0);
|
50
|
+
// Must reset for following tests
|
51
|
+
utils.isInputActive.mockReset();
|
52
|
+
});
|
53
|
+
|
54
|
+
});
|
55
|
+
|
56
|
+
describe('Keyboard shortcuts', () => {
|
57
|
+
|
58
|
+
test('Home key', () => {
|
59
|
+
br.first = jest.fn();
|
60
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'Home'});
|
61
|
+
keyEvent.preventDefault = jest.fn();
|
62
|
+
document.dispatchEvent(keyEvent);
|
63
|
+
expect(br.first).toHaveBeenCalledTimes(1);
|
64
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
65
|
+
});
|
66
|
+
|
67
|
+
test('End key', () => {
|
68
|
+
br.last = jest.fn();
|
69
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'End'});
|
70
|
+
keyEvent.preventDefault = jest.fn();
|
71
|
+
document.dispatchEvent(keyEvent);
|
72
|
+
expect(br.last).toHaveBeenCalledTimes(1);
|
73
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
74
|
+
});
|
75
|
+
|
76
|
+
test('ArrowDown key', () => {
|
77
|
+
br.mode = br.constMode2up;
|
78
|
+
br.next = jest.fn();
|
79
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'ArrowDown'});
|
80
|
+
keyEvent.preventDefault = jest.fn();
|
81
|
+
document.dispatchEvent(keyEvent);
|
82
|
+
expect(br.next).toHaveBeenCalledTimes(1);
|
83
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
84
|
+
});
|
85
|
+
|
86
|
+
test('PageDown key', () => {
|
87
|
+
br.mode = br.constMode2up;
|
88
|
+
br.next = jest.fn();
|
89
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'PageDown'});
|
90
|
+
keyEvent.preventDefault = jest.fn();
|
91
|
+
document.dispatchEvent(keyEvent);
|
92
|
+
expect(br.next).toHaveBeenCalledTimes(1);
|
93
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
94
|
+
});
|
95
|
+
|
96
|
+
test('ArrowUp key', () => {
|
97
|
+
br.mode = br.constMode2up;
|
98
|
+
br.prev = jest.fn();
|
99
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'ArrowUp'});
|
100
|
+
keyEvent.preventDefault = jest.fn();
|
101
|
+
document.dispatchEvent(keyEvent);
|
102
|
+
expect(br.prev).toHaveBeenCalledTimes(1);
|
103
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
104
|
+
});
|
105
|
+
|
106
|
+
test('PageUp key', () => {
|
107
|
+
br.mode = br.constMode2up;
|
108
|
+
br.prev = jest.fn();
|
109
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'PageUp'});
|
110
|
+
keyEvent.preventDefault = jest.fn();
|
111
|
+
document.dispatchEvent(keyEvent);
|
112
|
+
expect(br.prev).toHaveBeenCalledTimes(1);
|
113
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
114
|
+
});
|
115
|
+
|
116
|
+
test('ArrowLeft key', () => {
|
117
|
+
br.mode = br.constMode2up;
|
118
|
+
br.left = jest.fn();
|
119
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'ArrowLeft'});
|
120
|
+
keyEvent.preventDefault = jest.fn();
|
121
|
+
document.dispatchEvent(keyEvent);
|
122
|
+
expect(br.left).toHaveBeenCalledTimes(1);
|
123
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
124
|
+
});
|
125
|
+
|
126
|
+
test('ArrowRight key', () => {
|
127
|
+
br.mode = br.constMode2up;
|
128
|
+
br.right = jest.fn();
|
129
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'ArrowRight'});
|
130
|
+
keyEvent.preventDefault = jest.fn();
|
131
|
+
document.dispatchEvent(keyEvent);
|
132
|
+
expect(br.right).toHaveBeenCalledTimes(1);
|
133
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
134
|
+
});
|
135
|
+
|
136
|
+
test('Subtract key', () => {
|
137
|
+
br.zoom = jest.fn();
|
138
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'Subtract'});
|
139
|
+
keyEvent.preventDefault = jest.fn();
|
140
|
+
document.dispatchEvent(keyEvent);
|
141
|
+
expect(br.zoom).toHaveBeenCalledTimes(1);
|
142
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
143
|
+
});
|
144
|
+
|
145
|
+
test('- key', () => {
|
146
|
+
br.zoom = jest.fn();
|
147
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': '-'});
|
148
|
+
keyEvent.preventDefault = jest.fn();
|
149
|
+
document.dispatchEvent(keyEvent);
|
150
|
+
expect(br.zoom).toHaveBeenCalledTimes(1);
|
151
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
152
|
+
});
|
153
|
+
|
154
|
+
test('Add key', () => {
|
155
|
+
br.zoom = jest.fn();
|
156
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'Add'});
|
157
|
+
keyEvent.preventDefault = jest.fn();
|
158
|
+
document.dispatchEvent(keyEvent);
|
159
|
+
expect(br.zoom).toHaveBeenCalledTimes(1);
|
160
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
161
|
+
});
|
162
|
+
|
163
|
+
test('+ key', () => {
|
164
|
+
br.zoom = jest.fn();
|
165
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': '+'});
|
166
|
+
keyEvent.preventDefault = jest.fn();
|
167
|
+
document.dispatchEvent(keyEvent);
|
168
|
+
expect(br.zoom).toHaveBeenCalledTimes(1);
|
169
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
170
|
+
});
|
171
|
+
|
172
|
+
test('= key', () => {
|
173
|
+
br.zoom = jest.fn();
|
174
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': '='});
|
175
|
+
keyEvent.preventDefault = jest.fn();
|
176
|
+
document.dispatchEvent(keyEvent);
|
177
|
+
expect(br.zoom).toHaveBeenCalledTimes(1);
|
178
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
179
|
+
});
|
180
|
+
|
181
|
+
test('F key', () => {
|
182
|
+
br.toggleFullscreen = jest.fn();
|
183
|
+
const keyEvent = new KeyboardEvent('keydown', {'key': 'F'});
|
184
|
+
keyEvent.preventDefault = jest.fn();
|
185
|
+
document.dispatchEvent(keyEvent);
|
186
|
+
expect(br.toggleFullscreen).toHaveBeenCalledTimes(1);
|
187
|
+
expect(keyEvent.preventDefault).toHaveBeenCalledTimes(1);
|
188
|
+
});
|
189
|
+
|
190
|
+
});
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
import BookReader from '
|
2
|
+
import BookReader from '@/src/BookReader.js';
|
3
3
|
|
4
4
|
beforeAll(() => {
|
5
5
|
document.body.innerHTML = '<div id="BookReader">';
|
@@ -36,4 +36,12 @@ describe('BookReader options', () => {
|
|
36
36
|
expect(br.options.autoResize).toBe(true);
|
37
37
|
});
|
38
38
|
});
|
39
|
+
|
40
|
+
describe('`showNavbar`', () => {
|
41
|
+
it('is on by default', () => {
|
42
|
+
const br = new BookReader();
|
43
|
+
br.init();
|
44
|
+
expect(br.options.showNavbar).toBe(true);
|
45
|
+
});
|
46
|
+
});
|
39
47
|
});
|