@internetarchive/bookreader 5.0.0-8 → 5.0.0-80
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.js +17 -15
- package/.github/workflows/node.js.yml +73 -10
- package/.github/workflows/npm-publish.yml +6 -20
- package/.testcaferc.js +10 -0
- package/BookReader/BookReader.css +398 -1133
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.LICENSE.txt +20 -20
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +1782 -0
- package/BookReader/ia-bookreader-bundle.js.LICENSE.txt +7 -0
- package/BookReader/ia-bookreader-bundle.js.map +1 -0
- package/BookReader/icons/1up.svg +1 -1
- package/BookReader/icons/2up.svg +1 -1
- package/BookReader/icons/advance.svg +1 -1
- package/BookReader/icons/chevron-right.svg +1 -1
- package/BookReader/icons/close-circle-dark.svg +1 -1
- package/BookReader/icons/close-circle.svg +1 -1
- package/BookReader/icons/fullscreen.svg +1 -1
- package/BookReader/icons/fullscreen_exit.svg +1 -1
- package/BookReader/icons/hamburger.svg +1 -1
- package/BookReader/icons/left-arrow.svg +1 -1
- package/BookReader/icons/magnify-minus.svg +1 -1
- package/BookReader/icons/magnify-plus.svg +1 -1
- package/BookReader/icons/magnify.svg +1 -1
- package/BookReader/icons/pause.svg +1 -1
- package/BookReader/icons/play.svg +1 -1
- package/BookReader/icons/playback-speed.svg +1 -1
- package/BookReader/icons/read-aloud.svg +1 -1
- package/BookReader/icons/review.svg +1 -1
- package/BookReader/icons/thumbnails.svg +1 -1
- package/BookReader/icons/voice.svg +1 -0
- package/BookReader/icons/volume-full.svg +1 -1
- package/BookReader/images/BRicons.svg +3 -3
- package/BookReader/images/books_graphic.svg +1 -1
- package/BookReader/images/icon_book.svg +1 -1
- package/BookReader/images/icon_bookmark.svg +1 -1
- package/BookReader/images/icon_gear.svg +1 -1
- package/BookReader/images/icon_hamburger.svg +1 -1
- package/BookReader/images/icon_home.svg +1 -1
- package/BookReader/images/icon_info.svg +1 -1
- package/BookReader/images/icon_one_page.svg +1 -1
- package/BookReader/images/icon_pause.svg +1 -1
- package/BookReader/images/icon_play.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_skip-ahead.svg +1 -1
- package/BookReader/images/icon_skip-back.svg +1 -1
- package/BookReader/images/icon_speaker.svg +1 -1
- package/BookReader/images/icon_speaker_open.svg +1 -1
- package/BookReader/images/icon_thumbnails.svg +1 -1
- package/BookReader/images/icon_toc.svg +1 -1
- package/BookReader/images/icon_two_pages.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 +25 -1
- package/BookReader/plugins/plugin.chapters.js.LICENSE.txt +1 -0
- 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.iiif.js +2 -0
- package/BookReader/plugins/plugin.iiif.js.map +1 -0
- package/BookReader/plugins/plugin.resume.js +1 -1
- package/BookReader/plugins/plugin.resume.js.map +1 -1
- package/BookReader/plugins/plugin.search.js +2 -1
- package/BookReader/plugins/plugin.search.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.search.js.map +1 -1
- package/BookReader/plugins/plugin.text_selection.js +2 -1
- package/BookReader/plugins/plugin.text_selection.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.tts.js +1 -1
- package/BookReader/plugins/plugin.tts.js.LICENSE.txt +2 -0
- 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 +18 -19
- package/BookReaderDemo/BookReaderJSAdvanced.js +0 -3
- package/BookReaderDemo/BookReaderJSAutoplay.js +4 -1
- package/BookReaderDemo/BookReaderJSSimple.js +1 -0
- package/BookReaderDemo/IADemoBr.js +147 -0
- package/BookReaderDemo/demo-advanced.html +2 -2
- package/BookReaderDemo/demo-autoplay.html +2 -3
- package/BookReaderDemo/demo-embed-iframe-src.html +2 -1
- package/BookReaderDemo/demo-fullscreen-mobile.html +3 -5
- package/BookReaderDemo/demo-fullscreen.html +2 -4
- package/BookReaderDemo/demo-iiif.html +99 -12
- package/BookReaderDemo/demo-internetarchive.html +214 -18
- 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 -4
- package/BookReaderDemo/ia-multiple-volumes-manifest.js +170 -0
- package/BookReaderDemo/immersion-1up.html +2 -2
- package/BookReaderDemo/immersion-mode.html +2 -4
- package/BookReaderDemo/toggle_controls.html +3 -2
- package/BookReaderDemo/view_mode.html +2 -1
- package/BookReaderDemo/viewmode-cycle.html +2 -3
- package/CHANGELOG.md +536 -33
- package/README.md +14 -1
- package/babel.config.js +20 -0
- package/codecov.yml +6 -0
- package/index.html +4 -1
- package/jsconfig.json +19 -0
- package/netlify.toml +9 -0
- package/package.json +70 -60
- package/renovate.json +52 -0
- package/scripts/preversion.js +0 -1
- package/src/BookNavigator/assets/bookmark-colors.js +1 -1
- package/src/BookNavigator/assets/button-base.js +4 -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/book-navigator.js +590 -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 +27 -17
- package/src/BookNavigator/bookmarks/ia-bookmarks.js +116 -67
- 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/search-provider.js +49 -27
- package/src/BookNavigator/search/search-results.js +23 -9
- package/src/BookNavigator/sharing.js +27 -0
- package/src/BookNavigator/viewable-files.js +95 -0
- package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +11 -10
- package/src/BookNavigator/visual-adjustments/visual-adjustments.js +3 -3
- package/src/BookReader/BookModel.js +64 -34
- package/src/BookReader/DragScrollable.js +233 -0
- package/src/BookReader/Mode1Up.js +56 -351
- package/src/BookReader/Mode1UpLit.js +388 -0
- package/src/BookReader/Mode2Up.js +73 -1318
- package/src/BookReader/Mode2UpLit.js +776 -0
- package/src/BookReader/ModeCoordinateSpace.js +29 -0
- package/src/BookReader/ModeSmoothZoom.js +312 -0
- package/src/BookReader/ModeThumb.js +18 -12
- package/src/BookReader/Navbar/Navbar.js +14 -40
- package/src/BookReader/PageContainer.js +81 -6
- package/src/BookReader/ReduceSet.js +1 -1
- package/src/BookReader/Toolbar/Toolbar.js +10 -37
- package/src/BookReader/events.js +2 -3
- package/src/BookReader/options.js +27 -2
- package/src/BookReader/utils/HTMLDimensionsCacher.js +44 -0
- package/src/BookReader/utils/ScrollClassAdder.js +31 -0
- package/src/BookReader/utils/SelectionObserver.js +45 -0
- package/src/BookReader/utils.js +118 -13
- package/src/BookReader.js +427 -1061
- 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 +1 -5
- package/src/css/_BRBookmarks.scss +1 -1
- package/src/css/_BRComponent.scss +1 -1
- package/src/css/_BRmain.scss +16 -3
- package/src/css/_BRnav.scss +12 -39
- package/src/css/_BRpages.scss +149 -40
- package/src/css/_BRsearch.scss +68 -25
- package/src/css/_BRtoolbar.scss +5 -5
- package/src/css/_TextSelection.scss +87 -27
- package/src/css/_colorbox.scss +2 -2
- package/src/css/_controls.scss +20 -7
- package/src/css/_icons.scss +1 -1
- package/src/ia-bookreader/ia-bookreader.js +224 -0
- package/src/plugins/plugin.archive_analytics.js +3 -3
- package/src/plugins/plugin.autoplay.js +5 -11
- package/src/plugins/plugin.chapters.js +237 -191
- package/src/plugins/plugin.iiif.js +151 -0
- package/src/plugins/plugin.resume.js +3 -3
- package/src/plugins/plugin.text_selection.js +464 -134
- package/src/plugins/plugin.vendor-fullscreen.js +4 -4
- package/src/plugins/search/plugin.search.js +142 -125
- package/src/plugins/search/utils.js +43 -0
- package/src/plugins/search/view.js +33 -58
- package/src/plugins/tts/AbstractTTSEngine.js +71 -40
- 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 +87 -71
- package/src/plugins/tts/plugin.tts.js +96 -127
- package/src/plugins/tts/utils.js +15 -25
- package/src/plugins/url/UrlPlugin.js +191 -0
- package/src/plugins/{plugin.url.js → url/plugin.url.js} +45 -16
- package/src/util/browserSniffing.js +22 -0
- package/src/util/docCookies.js +21 -2
- package/tests/e2e/README.md +37 -0
- package/tests/e2e/autoplay.test.js +2 -2
- package/tests/e2e/base.test.js +8 -16
- package/tests/e2e/helpers/base.js +53 -48
- package/tests/e2e/helpers/debug.js +1 -1
- package/tests/e2e/helpers/params.js +17 -0
- package/tests/e2e/helpers/rightToLeft.js +8 -14
- package/tests/e2e/helpers/search.js +73 -0
- package/tests/e2e/models/Navigation.js +20 -37
- package/tests/e2e/rightToLeft.test.js +4 -5
- package/tests/e2e/viewmode.test.js +40 -33
- package/tests/jest/BookNavigator/book-navigator.test.js +661 -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 → jest}/BookNavigator/search/search-results.test.js +109 -60
- package/tests/jest/BookNavigator/sharing/sharing-provider.test.js +49 -0
- package/tests/jest/BookNavigator/viewable-files/viewable-files-provider.test.js +80 -0
- package/tests/jest/BookNavigator/visual-adjustments.test.js +200 -0
- package/tests/{BookReader → jest/BookReader}/BookModel.test.js +74 -14
- package/tests/jest/BookReader/BookReaderPublicFunctions.test.js +193 -0
- package/tests/{BookReader → jest/BookReader}/ImageCache.test.js +4 -4
- package/tests/jest/BookReader/Mode1UpLit.test.js +73 -0
- package/tests/jest/BookReader/Mode2Up.test.js +98 -0
- package/tests/jest/BookReader/Mode2UpLit.test.js +190 -0
- package/tests/jest/BookReader/ModeCoordinateSpace.test.js +16 -0
- package/tests/jest/BookReader/ModeSmoothZoom.test.js +218 -0
- package/tests/jest/BookReader/ModeThumb.test.js +71 -0
- package/tests/{BookReader → jest/BookReader}/Navbar/Navbar.test.js +10 -10
- 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/jest/BookReader/utils/SelectionObserver.test.js +57 -0
- package/tests/{BookReader → jest/BookReader}/utils/classes.test.js +1 -1
- package/tests/jest/BookReader/utils.test.js +229 -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} +26 -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/jest/plugins/plugin.chapters.test.js +195 -0
- package/tests/{plugins → jest/plugins}/plugin.iframe.test.js +2 -2
- package/tests/{plugins → jest/plugins}/plugin.resume.test.js +3 -3
- package/tests/jest/plugins/plugin.text_selection.test.js +317 -0
- package/tests/{plugins → jest/plugins}/plugin.vendor-fullscreen.test.js +2 -2
- package/tests/{plugins → jest/plugins}/search/plugin.search.test.js +25 -47
- package/tests/{plugins → jest/plugins}/search/plugin.search.view.test.js +39 -6
- package/tests/jest/plugins/search/utils.js +25 -0
- package/tests/jest/plugins/search/utils.test.js +29 -0
- package/tests/{plugins → jest/plugins}/tts/AbstractTTSEngine.test.js +29 -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 +47 -1
- package/tests/{plugins → jest/plugins}/tts/utils.test.js +1 -60
- package/tests/jest/plugins/url/UrlPlugin.test.js +198 -0
- package/tests/{plugins → jest/plugins/url}/plugin.url.test.js +53 -14
- package/tests/jest/setup.js +3 -0
- package/tests/{util → jest/util}/browserSniffing.test.js +1 -1
- package/tests/jest/util/docCookies.test.js +24 -0
- package/tests/{util → jest/util}/strings.test.js +1 -1
- package/tests/{utils.js → jest/utils.js} +38 -0
- package/webpack.config.js +12 -6
- 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/BookReader/plugins/plugin.mobile_nav.js +0 -2
- package/BookReader/plugins/plugin.mobile_nav.js.map +0 -1
- package/BookReaderDemo/IIIFBookReader.js +0 -207
- package/BookReaderDemo/bookreader-template-bundle.js +0 -7178
- package/BookReaderDemo/demo-iiif.js +0 -26
- 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 -446
- package/src/BookNavigator/assets/book-loader.js +0 -27
- package/src/BookNavigator/br-fullscreen-mgr.js +0 -83
- package/src/BookNavigator/search/a-search-result.js +0 -55
- package/src/BookReader/DebugConsole.js +0 -54
- package/src/BookReaderComponent/BookReaderComponent.js +0 -112
- package/src/ItemNavigator/ItemNavigator.js +0 -376
- package/src/ItemNavigator/providers/sharing.js +0 -29
- package/src/css/_MobileNav.scss +0 -194
- package/src/dragscrollable-br.js +0 -261
- package/src/lit-wrapper.js +0 -2
- package/src/plugins/menu_toggle/plugin.menu_toggle.js +0 -324
- package/src/plugins/plugin.mobile_nav.js +0 -287
- package/tests/BookReader/BookReaderPublicFunctions.test.js +0 -171
- package/tests/BookReader/DebugConsole.test.js +0 -25
- package/tests/BookReader/Mode1Up.test.js +0 -164
- package/tests/BookReader/Mode2Up.test.js +0 -247
- package/tests/BookReader/utils.test.js +0 -109
- package/tests/e2e/helpers/desktopSearch.js +0 -72
- package/tests/e2e/helpers/mobileSearch.js +0 -85
- 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/search/search-provider.test.js +0 -23
- package/tests/karma/BookNavigator/visual-adjustments.test.js +0 -201
- package/tests/plugins/menu_toggle/plugin.menu_toggle.test.js +0 -68
- package/tests/plugins/plugin.chapters.test.js +0 -130
- package/tests/plugins/plugin.mobile_nav.test.js +0 -66
- package/tests/plugins/plugin.text_selection.test.js +0 -203
- package/tests/util/docCookies.test.js +0 -15
@@ -0,0 +1,200 @@
|
|
1
|
+
import {
|
2
|
+
html,
|
3
|
+
fixture,
|
4
|
+
oneEvent,
|
5
|
+
} from '@open-wc/testing-helpers';
|
6
|
+
import sinon from 'sinon';
|
7
|
+
import { IABookVisualAdjustments } from '@/src/BookNavigator/visual-adjustments/visual-adjustments.js';
|
8
|
+
|
9
|
+
const options = [{
|
10
|
+
id: 'contrast',
|
11
|
+
name: 'Adjust contrast',
|
12
|
+
active: true,
|
13
|
+
min: 0,
|
14
|
+
max: 150,
|
15
|
+
step: 1,
|
16
|
+
value: 100,
|
17
|
+
}, {
|
18
|
+
id: 'invert',
|
19
|
+
name: 'Invert colors',
|
20
|
+
active: false,
|
21
|
+
}, {
|
22
|
+
id: 'brightness',
|
23
|
+
name: 'Adjust brightness',
|
24
|
+
active: false,
|
25
|
+
value: 100,
|
26
|
+
}];
|
27
|
+
|
28
|
+
const container = (renderHeader = false) => (
|
29
|
+
html`<ia-book-visual-adjustments .options=${options} ?renderHeader=${renderHeader}></ia-book-visual-adjustments>`
|
30
|
+
);
|
31
|
+
|
32
|
+
describe('<ia-book-visual-adjustments>', () => {
|
33
|
+
afterEach(() => {
|
34
|
+
sinon.restore();
|
35
|
+
});
|
36
|
+
|
37
|
+
test('sets default properties', async () => {
|
38
|
+
const el = await fixture(container());
|
39
|
+
|
40
|
+
expect(el.options).toBeDefined();
|
41
|
+
expect(el.options.length).toEqual(options.length);
|
42
|
+
expect(el.renderHeader).toBeDefined();
|
43
|
+
expect(el.renderHeader).toBeFalsy();
|
44
|
+
expect(el.activeCount).toBeDefined();
|
45
|
+
expect(el.showZoomControls).toBeTruthy();
|
46
|
+
});
|
47
|
+
|
48
|
+
test('renders all properties of a visual adjustment option', async () => {
|
49
|
+
const el = await fixture(container());
|
50
|
+
|
51
|
+
await el.updateComplete;
|
52
|
+
|
53
|
+
const label = el.shadowRoot.querySelector('label');
|
54
|
+
const name = label.querySelector('.name');
|
55
|
+
const checkbox = label.querySelector('input');
|
56
|
+
expect(name.textContent).toEqual(options[0].name);
|
57
|
+
expect(checkbox.checked).toEqual(true);
|
58
|
+
});
|
59
|
+
|
60
|
+
test('can render header with active options count', async () => {
|
61
|
+
const renderHeader = true;
|
62
|
+
const el = await fixture(container(renderHeader));
|
63
|
+
expect(el.shadowRoot.querySelector('header p').textContent).toContain('1');
|
64
|
+
});
|
65
|
+
|
66
|
+
test('does not render active options count element when none are selected', async () => {
|
67
|
+
const el = await fixture(container());
|
68
|
+
|
69
|
+
el.options = [options[1]];
|
70
|
+
await el.updateComplete;
|
71
|
+
|
72
|
+
expect(el.shadowRoot.querySelector('header p')).toBe(null);
|
73
|
+
});
|
74
|
+
|
75
|
+
test('changes option\'s active state when input changed', async () => {
|
76
|
+
const el = await fixture(container());
|
77
|
+
|
78
|
+
el.shadowRoot.querySelector('li input').dispatchEvent(new Event('change'));
|
79
|
+
await el.updateComplete;
|
80
|
+
|
81
|
+
expect(el.options[0].active).toEqual(false);
|
82
|
+
});
|
83
|
+
|
84
|
+
test('renders zoom in and out controls when enabled', async () => {
|
85
|
+
const el = await fixture(container());
|
86
|
+
|
87
|
+
expect(el.shadowRoot.querySelector('.zoom_out')).toBeDefined();
|
88
|
+
expect(el.shadowRoot.querySelector('.zoom_in')).toBeDefined();
|
89
|
+
});
|
90
|
+
|
91
|
+
test('does not render zoom controls when disabled', async () => {
|
92
|
+
const el = await fixture(container());
|
93
|
+
|
94
|
+
el.showZoomControls = false;
|
95
|
+
await el.updateComplete;
|
96
|
+
|
97
|
+
expect(el.shadowRoot.querySelector('.zoom_out')).toBe(null);
|
98
|
+
expect(el.shadowRoot.querySelector('.zoom_in')).toBe(null);
|
99
|
+
});
|
100
|
+
|
101
|
+
describe('Custom events', () => {
|
102
|
+
test('prepareEventDetails returns proper params', async () => {
|
103
|
+
const el = await fixture(container());
|
104
|
+
await el.updateComplete;
|
105
|
+
const params = el.prepareEventDetails();
|
106
|
+
|
107
|
+
expect(params.activeCount).toBeDefined();
|
108
|
+
expect(typeof (params.activeCount)).toEqual('number');
|
109
|
+
expect(params.changedOptionId).toBeDefined();
|
110
|
+
expect(typeof (params.changedOptionId)).toEqual('string');
|
111
|
+
expect(params.options).toBeDefined();
|
112
|
+
expect(params.options.length).toBeDefined();
|
113
|
+
expect(params.options.length).toBeGreaterThan(0);
|
114
|
+
});
|
115
|
+
test('emitOptionChangedEvent calls for the params', async () => {
|
116
|
+
IABookVisualAdjustments.prototype.prepareEventDetails = sinon.fake();
|
117
|
+
const el = await fixture(container());
|
118
|
+
await el.updateComplete;
|
119
|
+
|
120
|
+
expect(el.prepareEventDetails.callCount).toEqual(1);
|
121
|
+
});
|
122
|
+
test('triggers an emitOptionChangedEvent event at firstUpdate', async () => {
|
123
|
+
IABookVisualAdjustments.prototype.emitOptionChangedEvent = sinon.fake();
|
124
|
+
const el = await fixture(container());
|
125
|
+
|
126
|
+
expect(el.emitOptionChangedEvent.callCount).toEqual(1);
|
127
|
+
});
|
128
|
+
|
129
|
+
test('triggers an emitOptionChangedEvent event when a checkbox\'s change event fires', async () => {
|
130
|
+
IABookVisualAdjustments.prototype.emitOptionChangedEvent = sinon.fake();
|
131
|
+
const el = await fixture(container());
|
132
|
+
|
133
|
+
expect(el.emitOptionChangedEvent.callCount).toEqual(1); // firstUpdate fire
|
134
|
+
|
135
|
+
el.shadowRoot.querySelector('li input').dispatchEvent(new Event('change'));
|
136
|
+
expect(el.emitOptionChangedEvent.callCount).toEqual(2);
|
137
|
+
});
|
138
|
+
|
139
|
+
test('triggers an emitOptionChangedEvent event when a range\'s change event fires', async () => {
|
140
|
+
IABookVisualAdjustments.prototype.emitOptionChangedEvent = sinon.fake();
|
141
|
+
|
142
|
+
const el = await fixture(container());
|
143
|
+
expect(el.emitOptionChangedEvent.callCount).toEqual(1); // firstUpdate fire
|
144
|
+
|
145
|
+
el.shadowRoot.querySelector('[name="brightness_range"]').dispatchEvent(new Event('change'));
|
146
|
+
expect(el.emitOptionChangedEvent.callCount).toEqual(2);
|
147
|
+
});
|
148
|
+
|
149
|
+
test('emits a zoom out event when zoom out button clicked', async () => {
|
150
|
+
const el = await fixture(container());
|
151
|
+
|
152
|
+
setTimeout(() => (
|
153
|
+
el.shadowRoot.querySelector('.zoom_out').click()
|
154
|
+
));
|
155
|
+
const response = await oneEvent(el, 'visualAdjustmentZoomOut');
|
156
|
+
|
157
|
+
expect(response).toBeDefined();
|
158
|
+
});
|
159
|
+
|
160
|
+
test('emits a zoom in event when zoom in button clicked', async () => {
|
161
|
+
const el = await fixture(container());
|
162
|
+
|
163
|
+
setTimeout(() => (
|
164
|
+
el.shadowRoot.querySelector('.zoom_in').click()
|
165
|
+
));
|
166
|
+
const response = await oneEvent(el, 'visualAdjustmentZoomIn');
|
167
|
+
|
168
|
+
expect(response).toBeDefined();
|
169
|
+
});
|
170
|
+
});
|
171
|
+
|
172
|
+
test('sets range defaults when none supplied', async () => {
|
173
|
+
const el = await fixture(container());
|
174
|
+
const brightnessRange = el.shadowRoot.querySelector('[name="brightness_range"]');
|
175
|
+
|
176
|
+
expect(brightnessRange.getAttribute('min')).toEqual('0');
|
177
|
+
expect(brightnessRange.getAttribute('max')).toEqual('100');
|
178
|
+
expect(brightnessRange.getAttribute('step')).toEqual('1');
|
179
|
+
});
|
180
|
+
|
181
|
+
test('sets the updated range value on the options prop', async () => {
|
182
|
+
const el = await fixture(container());
|
183
|
+
const { id } = options[0];
|
184
|
+
const newValue = 120;
|
185
|
+
|
186
|
+
el.setRangeValue(id, newValue);
|
187
|
+
await el.updateComplete;
|
188
|
+
|
189
|
+
expect(el.options[0].value).toEqual(newValue);
|
190
|
+
});
|
191
|
+
|
192
|
+
test('triggers a setRangeValue event when a range\'s input event fires', async () => {
|
193
|
+
IABookVisualAdjustments.prototype.setRangeValue = sinon.fake();
|
194
|
+
|
195
|
+
const el = await fixture(container());
|
196
|
+
|
197
|
+
el.shadowRoot.querySelector('[name="brightness_range"]').dispatchEvent(new Event('input'));
|
198
|
+
expect(el.setRangeValue.callCount).toEqual(1);
|
199
|
+
});
|
200
|
+
});
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import sinon from 'sinon';
|
2
2
|
import { deepCopy } from '../utils.js';
|
3
|
-
import { BookModel } from '
|
4
|
-
|
3
|
+
import { BookModel } from '@/src/BookReader/BookModel.js';
|
4
|
+
import { NAMED_REDUCE_SETS } from '@/src/BookReader/ReduceSet.js';
|
5
|
+
/** @typedef {import('@/src/BookReader/options.js').BookReaderOptions} BookReaderOptions */
|
5
6
|
|
6
7
|
afterEach(() => {
|
7
8
|
sinon.restore();
|
@@ -21,10 +22,10 @@ const SAMPLE_DATA = [
|
|
21
22
|
],
|
22
23
|
];
|
23
24
|
|
24
|
-
describe('
|
25
|
+
describe('getMedianPageSizeInches', () => {
|
25
26
|
test('handles single page data', () => {
|
26
|
-
const bm = new BookModel({ data: SAMPLE_DATA.slice(0, 1) });
|
27
|
-
expect(bm.
|
27
|
+
const bm = new BookModel({ data: SAMPLE_DATA.slice(0, 1), options: {ppi: 10} });
|
28
|
+
expect(bm.getMedianPageSizeInches()).toEqual({ width: 12.3, height: 12.3 });
|
28
29
|
});
|
29
30
|
|
30
31
|
test('handles odd pages data', () => {
|
@@ -38,8 +39,8 @@ describe('getMedianPageSize', () => {
|
|
38
39
|
Object.assign(data[0][0], sizes[0]);
|
39
40
|
Object.assign(data[1][0], sizes[1]);
|
40
41
|
Object.assign(data[1][1], sizes[2]);
|
41
|
-
const bm = new BookModel({ data });
|
42
|
-
expect(bm.
|
42
|
+
const bm = new BookModel({ data, options: {ppi: 10} });
|
43
|
+
expect(bm.getMedianPageSizeInches()).toEqual({ width: 20, height: 220 });
|
43
44
|
});
|
44
45
|
|
45
46
|
|
@@ -55,16 +56,31 @@ describe('getMedianPageSize', () => {
|
|
55
56
|
Object.assign(data[1][0], sizes[1]);
|
56
57
|
Object.assign(data[1][1], sizes[2]);
|
57
58
|
Object.assign(data[2][0], sizes[3]);
|
58
|
-
const bm = new BookModel({ data });
|
59
|
-
expect(bm.
|
59
|
+
const bm = new BookModel({ data, options: {ppi: 10} });
|
60
|
+
expect(bm.getMedianPageSizeInches()).toEqual({ width: 30, height: 230 });
|
61
|
+
});
|
62
|
+
|
63
|
+
test('does not lexicographic sort for median', () => {
|
64
|
+
const sizes = [
|
65
|
+
{width: 100, height: 100},
|
66
|
+
{width: 20, height: 20},
|
67
|
+
{width: 30, height: 30},
|
68
|
+
];
|
69
|
+
const data = deepCopy(SAMPLE_DATA);
|
70
|
+
delete data[2];
|
71
|
+
Object.assign(data[0][0], sizes[0]);
|
72
|
+
Object.assign(data[1][0], sizes[1]);
|
73
|
+
Object.assign(data[1][1], sizes[2]);
|
74
|
+
const bm = new BookModel({ data, options: {ppi: 10} });
|
75
|
+
expect(bm.getMedianPageSizeInches()).toEqual({ width: 3, height: 3 });
|
60
76
|
});
|
61
77
|
|
62
78
|
test('caches result', () => {
|
63
79
|
const bm = new BookModel({ data: SAMPLE_DATA });
|
64
|
-
const firstResult = bm.
|
65
|
-
expect(bm.
|
66
|
-
expect(bm.
|
67
|
-
expect(bm.
|
80
|
+
const firstResult = bm.getMedianPageSizeInches();
|
81
|
+
expect(bm.getMedianPageSizeInches()).toBe(firstResult);
|
82
|
+
expect(bm.getMedianPageSizeInches()).toBe(firstResult);
|
83
|
+
expect(bm.getMedianPageSizeInches()).toBe(firstResult);
|
68
84
|
});
|
69
85
|
});
|
70
86
|
|
@@ -190,7 +206,7 @@ describe('pagesIterator', () => {
|
|
190
206
|
describe('_getDataFlattened', () => {
|
191
207
|
test('Assigns correct page sides', () => {
|
192
208
|
const bm = new BookModel({ data: SAMPLE_DATA });
|
193
|
-
expect(bm._getDataFlattened().map(page => page.pageSide)).toEqual(['R', 'L', 'R', 'L'])
|
209
|
+
expect(bm._getDataFlattened().map(page => page.pageSide)).toEqual(['R', 'L', 'R', 'L']);
|
194
210
|
});
|
195
211
|
|
196
212
|
test('Memoized based on data length', () => {
|
@@ -309,4 +325,48 @@ describe('PageModel', () => {
|
|
309
325
|
expect(bm.getPage(0).findPrev({ combineConsecutiveUnviewables: true })).toBeUndefined();
|
310
326
|
});
|
311
327
|
});
|
328
|
+
|
329
|
+
describe('findLeft/findRight', () => {
|
330
|
+
const data = deepCopy(SAMPLE_DATA);
|
331
|
+
|
332
|
+
test('Calls findNext/findPrev based on progression', () => {
|
333
|
+
const bm = new BookModel({ data });
|
334
|
+
const page = bm.getPage(0);
|
335
|
+
const findNextStub = sinon.stub(page, 'findNext');
|
336
|
+
const findPrevStub = sinon.stub(page, 'findPrev');
|
337
|
+
bm.pageProgression = 'lr';
|
338
|
+
page.findLeft();
|
339
|
+
expect(findPrevStub.callCount).toBe(1);
|
340
|
+
expect(findNextStub.callCount).toBe(0);
|
341
|
+
page.findRight();
|
342
|
+
expect(findPrevStub.callCount).toBe(1);
|
343
|
+
expect(findNextStub.callCount).toBe(1);
|
344
|
+
bm.pageProgression = 'rl';
|
345
|
+
page.findLeft();
|
346
|
+
expect(findPrevStub.callCount).toBe(1);
|
347
|
+
expect(findNextStub.callCount).toBe(2);
|
348
|
+
page.findRight();
|
349
|
+
expect(findPrevStub.callCount).toBe(2);
|
350
|
+
expect(findNextStub.callCount).toBe(2);
|
351
|
+
});
|
352
|
+
});
|
353
|
+
|
354
|
+
describe('getURISrcSet', () => {
|
355
|
+
const data = deepCopy(SAMPLE_DATA);
|
356
|
+
const bm = new BookModel({ data, reduceSet: NAMED_REDUCE_SETS.pow2 });
|
357
|
+
bm.getPageURI = (index, scale, rotate) => `correctURL.png?scale=${scale}`;
|
358
|
+
const page = bm.getPage(0);
|
359
|
+
|
360
|
+
test('with 0 elements in srcset', () => {
|
361
|
+
expect(page.getURISrcSet(1)).toBe("");
|
362
|
+
});
|
363
|
+
|
364
|
+
test('with 2 elements in srcset', () => {
|
365
|
+
expect(page.getURISrcSet(5)).toBe("correctURL.png?scale=2 2x, correctURL.png?scale=1 4x");
|
366
|
+
});
|
367
|
+
|
368
|
+
test('with the most elements in srcset', () => {
|
369
|
+
expect(page.getURISrcSet(35)).toBe("correctURL.png?scale=16 2x, correctURL.png?scale=8 4x, correctURL.png?scale=4 8x, correctURL.png?scale=2 16x, correctURL.png?scale=1 32x");
|
370
|
+
});
|
371
|
+
});
|
312
372
|
});
|
@@ -0,0 +1,193 @@
|
|
1
|
+
import BookReader from '@/src/BookReader';
|
2
|
+
import { sleep } from '@/src/BookReader/utils.js';
|
3
|
+
import sinon from 'sinon';
|
4
|
+
|
5
|
+
beforeAll(() => {
|
6
|
+
global.alert = sinon.fake();
|
7
|
+
});
|
8
|
+
afterEach(() => {
|
9
|
+
sinon.restore();
|
10
|
+
});
|
11
|
+
|
12
|
+
describe('BookReader.prototype.toggleFullscreen', () => {
|
13
|
+
test('uses `isFullscreen` to check fullscreen state', () => {
|
14
|
+
const isFSmock = sinon.fake();
|
15
|
+
// isFSmock.mockReturnValueOnce(false);
|
16
|
+
const br = new BookReader();
|
17
|
+
br.mode = br.constMode1up;
|
18
|
+
br.enterFullscreen = sinon.fake();
|
19
|
+
br.isFullscreen = isFSmock;
|
20
|
+
|
21
|
+
br.toggleFullscreen();
|
22
|
+
expect(br.isFullscreen.callCount).toEqual(1);
|
23
|
+
});
|
24
|
+
|
25
|
+
test('will always emit an event', async () => {
|
26
|
+
const br = new BookReader();
|
27
|
+
br.mode = br.constMode2up;
|
28
|
+
br.trigger = sinon.fake();
|
29
|
+
br.switchMode = sinon.fake();
|
30
|
+
br.updateBrClasses = sinon.fake();
|
31
|
+
br.jumpToIndex = sinon.fake();
|
32
|
+
br.refs.$brContainer = {
|
33
|
+
css: sinon.fake(),
|
34
|
+
animate: (options, speed, style, callback) => callback()
|
35
|
+
};
|
36
|
+
br.refs.$br = {
|
37
|
+
updateBrClasses: sinon.fake(),
|
38
|
+
removeClass: sinon.fake(),
|
39
|
+
addClass: sinon.fake(),
|
40
|
+
css: sinon.fake(),
|
41
|
+
animate: (options, speed, style, callback) => callback()
|
42
|
+
};
|
43
|
+
|
44
|
+
await br.toggleFullscreen();
|
45
|
+
expect(br.trigger.callCount).toBeGreaterThan(0);
|
46
|
+
});
|
47
|
+
|
48
|
+
test('will start with opening fullscreen', () => {
|
49
|
+
const br = new BookReader();
|
50
|
+
br.mode = br.constMode2up;
|
51
|
+
br.enterFullscreen = sinon.fake();
|
52
|
+
|
53
|
+
br.toggleFullscreen();
|
54
|
+
expect(br.enterFullscreen.callCount).toEqual(1);
|
55
|
+
});
|
56
|
+
|
57
|
+
test('will close fullscreen if BookReader is in fullscreen', () => {
|
58
|
+
const br = new BookReader();
|
59
|
+
br.mode = br.constMode1up;
|
60
|
+
br.exitFullScreen = sinon.fake();
|
61
|
+
br.isFullscreenActive = true;
|
62
|
+
|
63
|
+
br.toggleFullscreen();
|
64
|
+
expect(br.exitFullScreen.callCount).toEqual(1);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
|
68
|
+
describe('BookReader.prototype.enterFullscreen', () => {
|
69
|
+
test('will bind `_fullscreenCloseHandler` by default', () => {
|
70
|
+
const br = new BookReader();
|
71
|
+
br.mode = br.constMode1up;
|
72
|
+
br.switchMode = sinon.fake();
|
73
|
+
br.updateBrClasses = sinon.fake();
|
74
|
+
br.refs.$br = {
|
75
|
+
css: sinon.fake(),
|
76
|
+
animate: sinon.fake(),
|
77
|
+
addClass: sinon.fake(),
|
78
|
+
};
|
79
|
+
expect(br._fullscreenCloseHandler).toBeUndefined();
|
80
|
+
|
81
|
+
br.enterFullscreen();
|
82
|
+
expect(br._fullscreenCloseHandler).toBeDefined();
|
83
|
+
});
|
84
|
+
|
85
|
+
test('fires certain events when called', async () => {
|
86
|
+
const br = new BookReader();
|
87
|
+
br.mode = br.constMode2up;
|
88
|
+
br.switchMode = sinon.fake();
|
89
|
+
br.updateBrClasses = sinon.fake();
|
90
|
+
br.trigger = sinon.fake();
|
91
|
+
br.resize = sinon.fake();
|
92
|
+
br.jumpToIndex = sinon.fake();
|
93
|
+
br.refs.$br = {
|
94
|
+
addClass: sinon.fake(),
|
95
|
+
removeClass: sinon.fake(),
|
96
|
+
};
|
97
|
+
br.refs.$brContainer = {
|
98
|
+
css: sinon.fake(),
|
99
|
+
animate: (options, speed, style, callback) => callback(),
|
100
|
+
};
|
101
|
+
|
102
|
+
await br.enterFullscreen();
|
103
|
+
expect(br.switchMode.callCount).toEqual(1);
|
104
|
+
expect(br.updateBrClasses.callCount).toEqual(1);
|
105
|
+
expect(br.trigger.callCount).toEqual(2); // fragmentChange, fullscreenToggled
|
106
|
+
expect(br.jumpToIndex.callCount).toEqual(1);
|
107
|
+
|
108
|
+
await sleep(0);
|
109
|
+
expect(br.resize.callCount).toEqual(1);
|
110
|
+
});
|
111
|
+
});
|
112
|
+
|
113
|
+
describe('BookReader.prototype.exitFullScreen', () => {
|
114
|
+
test('fires certain events when called', async () => {
|
115
|
+
const br = new BookReader();
|
116
|
+
br.mode = br.constMode2up;
|
117
|
+
br.switchMode = sinon.fake();
|
118
|
+
br.updateBrClasses = sinon.fake();
|
119
|
+
br.trigger = sinon.fake();
|
120
|
+
br.resize = sinon.fake();
|
121
|
+
br.refs.$br = {
|
122
|
+
addClass: sinon.fake(),
|
123
|
+
removeClass: sinon.fake(),
|
124
|
+
};
|
125
|
+
br.refs.$brContainer = {
|
126
|
+
css: sinon.fake(),
|
127
|
+
animate: (options, speed, style, callback) => callback()
|
128
|
+
};
|
129
|
+
await br.exitFullScreen();
|
130
|
+
expect(br.switchMode.callCount).toEqual(1);
|
131
|
+
expect(br.updateBrClasses.callCount).toEqual(1);
|
132
|
+
expect(br.trigger.callCount).toEqual(2); // fragmentChange, fullscreenToggled
|
133
|
+
expect(br.resize.callCount).toEqual(1);
|
134
|
+
});
|
135
|
+
});
|
136
|
+
|
137
|
+
describe('BookReader.prototype.trigger', () => {
|
138
|
+
test('fires custom event', () => {
|
139
|
+
const br = new BookReader();
|
140
|
+
global.br = br;
|
141
|
+
global.dispatchEvent = sinon.fake();
|
142
|
+
|
143
|
+
const props = {bar: 1};
|
144
|
+
br.trigger('foo', props);
|
145
|
+
expect(global.dispatchEvent.callCount).toBe(1);
|
146
|
+
});
|
147
|
+
});
|
148
|
+
|
149
|
+
describe('`BookReader.prototype.prev`', () => {
|
150
|
+
let br;
|
151
|
+
let flipAnimationStub;
|
152
|
+
beforeEach(() => {
|
153
|
+
br = new BookReader();
|
154
|
+
global.br = br;
|
155
|
+
br.trigger = sinon.fake();
|
156
|
+
br.jumpToIndex = sinon.fake();
|
157
|
+
flipAnimationStub = sinon.stub(br._modes.mode2Up.mode2UpLit, 'flipAnimation');
|
158
|
+
});
|
159
|
+
|
160
|
+
afterEach(() => {
|
161
|
+
sinon.restore();
|
162
|
+
});
|
163
|
+
|
164
|
+
test('does not take action if user is on front page', () => {
|
165
|
+
br.firstIndex = 0;
|
166
|
+
br.prev();
|
167
|
+
expect(br.trigger.callCount).toBe(0);
|
168
|
+
expect(flipAnimationStub.callCount).toBe(0);
|
169
|
+
expect(br.jumpToIndex.callCount).toBe(0);
|
170
|
+
});
|
171
|
+
|
172
|
+
describe('2up mode', () => {
|
173
|
+
test('fires event and turns the page', () => {
|
174
|
+
br.firstIndex = 10;
|
175
|
+
br.mode = br.constMode2up;
|
176
|
+
br.prev();
|
177
|
+
expect(br.jumpToIndex.callCount).toBe(0); // <-- does not get called
|
178
|
+
expect(br.trigger.callCount).toBe(1);
|
179
|
+
expect(flipAnimationStub.callCount).toBe(1);
|
180
|
+
});
|
181
|
+
});
|
182
|
+
|
183
|
+
describe('non 2up mode', () => {
|
184
|
+
test('jumps to provided index', () => {
|
185
|
+
br.firstIndex = 100;
|
186
|
+
br.mode = br.constMode1up;
|
187
|
+
br.prev();
|
188
|
+
expect(br.jumpToIndex.callCount).toBe(1); // <-- gets called
|
189
|
+
expect(flipAnimationStub.callCount).toBe(0); // <-- gets called by `jumpToIndex` internally
|
190
|
+
});
|
191
|
+
});
|
192
|
+
});
|
193
|
+
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import sinon from 'sinon';
|
2
|
-
import { BookModel } from '
|
3
|
-
import { ImageCache } from '
|
4
|
-
import { Pow2ReduceSet } from '
|
5
|
-
/** @typedef {import('
|
2
|
+
import { BookModel } from '@/src/BookReader/BookModel.js';
|
3
|
+
import { ImageCache } from '@/src/BookReader/ImageCache.js';
|
4
|
+
import { Pow2ReduceSet } from '@/src/BookReader/ReduceSet.js';
|
5
|
+
/** @typedef {import('@/src/BookReader/options.js').BookReaderOptions} BookReaderOptions */
|
6
6
|
|
7
7
|
afterEach(() => {
|
8
8
|
jest.restoreAllMocks();
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { BookModel } from '@/src/BookReader/BookModel.js';
|
2
|
+
import { Mode1UpLit } from '@/src/BookReader/Mode1UpLit.js';
|
3
|
+
|
4
|
+
/** @type {import('@/src/BookReader/options.js').BookReaderOptions['data']} */
|
5
|
+
const SAMPLE_DATA = [
|
6
|
+
[
|
7
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image0.jpg', pageNum: '1' },
|
8
|
+
],
|
9
|
+
[
|
10
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image1.jpg', pageNum: '2' },
|
11
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image2.jpg', pageNum: '3' },
|
12
|
+
],
|
13
|
+
[
|
14
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image3.jpg', pageNum: '4' },
|
15
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image4.jpg', pageNum: '5' },
|
16
|
+
],
|
17
|
+
[
|
18
|
+
{ width: 123, height: 123, uri: 'https://archive.org/image5.jpg', pageNum: '6' },
|
19
|
+
],
|
20
|
+
];
|
21
|
+
|
22
|
+
function make_dummy_br(overrides = {}) {
|
23
|
+
return Object.assign({
|
24
|
+
updateFirstIndex() {},
|
25
|
+
_components: {
|
26
|
+
navbar: {
|
27
|
+
updateNavIndexThrottled() {},
|
28
|
+
}
|
29
|
+
},
|
30
|
+
data: []
|
31
|
+
}, overrides);
|
32
|
+
}
|
33
|
+
|
34
|
+
describe('pageTops', () => {
|
35
|
+
afterEach(() => document.body.innerHTML = '');
|
36
|
+
|
37
|
+
test('Works with empty book', async () => {
|
38
|
+
const br = make_dummy_br({ data: [] });
|
39
|
+
const book = new BookModel(br);
|
40
|
+
const mode = new Mode1UpLit(book, br);
|
41
|
+
document.body.appendChild(mode);
|
42
|
+
mode.requestUpdate();
|
43
|
+
await mode.updateComplete;
|
44
|
+
expect(mode.pageTops).toEqual({});
|
45
|
+
});
|
46
|
+
|
47
|
+
test('Iterates all pages', async () => {
|
48
|
+
const br = make_dummy_br({ data: SAMPLE_DATA });
|
49
|
+
const book = new BookModel(br);
|
50
|
+
const mode = new Mode1UpLit(book, br);
|
51
|
+
document.body.appendChild(mode);
|
52
|
+
await mode.requestUpdate();
|
53
|
+
expect(Object.values(mode.pageTops)).toHaveLength(6);
|
54
|
+
});
|
55
|
+
|
56
|
+
test('Computes tops', async () => {
|
57
|
+
const br = make_dummy_br({ data: SAMPLE_DATA });
|
58
|
+
const book = new BookModel(br);
|
59
|
+
const mode = new Mode1UpLit(book, br);
|
60
|
+
document.body.appendChild(mode);
|
61
|
+
await mode.requestUpdate();
|
62
|
+
const tops = Object.entries(mode.pageTops);
|
63
|
+
expect(tops.map(([index, top]) => [index, top.toFixed(1)])).toEqual([
|
64
|
+
// Recall these are in inches
|
65
|
+
['0', '0.2'],
|
66
|
+
['1', '0.6'],
|
67
|
+
['2', '1.1'],
|
68
|
+
['3', '1.5'],
|
69
|
+
['4', '2.0'],
|
70
|
+
['5', '2.4'],
|
71
|
+
]);
|
72
|
+
});
|
73
|
+
});
|