@internetarchive/bookreader 5.0.0-95 → 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.
- package/BookReader/BookReader.css +2251 -0
- package/BookReader/BookReader.js +3 -0
- package/BookReader/BookReader.js.LICENSE.txt +72 -0
- package/BookReader/BookReader.js.map +1 -0
- package/BookReader/hypothesis/LICENSE +50 -0
- package/BookReader/hypothesis/README.md +55 -0
- package/BookReader/hypothesis/build/boot.js +1 -0
- package/BookReader/hypothesis/build/manifest.json +20 -0
- package/BookReader/hypothesis/build/scripts/annotator.bundle.js +184 -0
- package/BookReader/hypothesis/build/scripts/annotator.bundle.js.map +1 -0
- package/BookReader/hypothesis/build/scripts/sidebar.bundle.js +798 -0
- package/BookReader/hypothesis/build/scripts/sidebar.bundle.js.map +1 -0
- package/BookReader/hypothesis/build/scripts/ui-playground.bundle.js +711 -0
- package/BookReader/hypothesis/build/scripts/ui-playground.bundle.js.map +1 -0
- package/BookReader/hypothesis/build/styles/annotator.css +2235 -0
- package/BookReader/hypothesis/build/styles/annotator.css.map +1 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Bold.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Italic.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Main-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Math-Italic.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Script-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/BookReader/hypothesis/build/styles/highlights.css +2 -0
- package/BookReader/hypothesis/build/styles/highlights.css.map +1 -0
- package/BookReader/hypothesis/build/styles/katex.min.css +2 -0
- package/BookReader/hypothesis/build/styles/katex.min.css.map +1 -0
- package/BookReader/hypothesis/build/styles/pdfjs-overrides.css +2 -0
- package/BookReader/hypothesis/build/styles/pdfjs-overrides.css.map +1 -0
- package/BookReader/hypothesis/build/styles/sidebar.css +2731 -0
- package/BookReader/hypothesis/build/styles/sidebar.css.map +1 -0
- package/BookReader/hypothesis/build/styles/ui-playground.css +2659 -0
- package/BookReader/hypothesis/build/styles/ui-playground.css.map +1 -0
- package/BookReader/hypothesis/package.json +126 -0
- 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 -0
- package/BookReader/icons/2up.svg +1 -0
- package/BookReader/icons/advance.svg +3 -0
- package/BookReader/icons/chevron-right.svg +1 -0
- package/BookReader/icons/close-circle-dark.svg +1 -0
- package/BookReader/icons/close-circle.svg +1 -0
- package/BookReader/icons/fullscreen.svg +1 -0
- package/BookReader/icons/fullscreen_exit.svg +1 -0
- package/BookReader/icons/hamburger.svg +1 -0
- package/BookReader/icons/left-arrow.svg +1 -0
- package/BookReader/icons/magnify-minus.svg +1 -0
- package/BookReader/icons/magnify-plus.svg +1 -0
- package/BookReader/icons/magnify.svg +1 -0
- package/BookReader/icons/pause.svg +1 -0
- package/BookReader/icons/play.svg +1 -0
- package/BookReader/icons/playback-speed.svg +1 -0
- package/BookReader/icons/read-aloud.svg +1 -0
- package/BookReader/icons/review.svg +3 -0
- package/BookReader/icons/thumbnails.svg +1 -0
- package/BookReader/icons/voice.svg +1 -0
- package/BookReader/icons/volume-full.svg +1 -0
- package/BookReader/images/BRicons.png +0 -0
- package/BookReader/images/BRicons.svg +5 -0
- package/BookReader/images/BRicons_ia.png +0 -0
- package/BookReader/images/back_pages.png +0 -0
- package/BookReader/images/book_bottom_icon.png +0 -0
- package/BookReader/images/book_down_icon.png +0 -0
- package/BookReader/images/book_left_icon.png +0 -0
- package/BookReader/images/book_leftmost_icon.png +0 -0
- package/BookReader/images/book_right_icon.png +0 -0
- package/BookReader/images/book_rightmost_icon.png +0 -0
- package/BookReader/images/book_top_icon.png +0 -0
- package/BookReader/images/book_up_icon.png +0 -0
- package/BookReader/images/books_graphic.svg +1 -0
- package/BookReader/images/booksplit.png +0 -0
- package/BookReader/images/control_pause_icon.png +0 -0
- package/BookReader/images/control_play_icon.png +0 -0
- package/BookReader/images/embed_icon.png +0 -0
- package/BookReader/images/hypothesis.ico +0 -0
- package/BookReader/images/icon-home-ia.png +0 -0
- package/BookReader/images/icon_OL-logo-xs.png +0 -0
- package/BookReader/images/icon_alert-xs.png +0 -0
- package/BookReader/images/icon_book.svg +1 -0
- package/BookReader/images/icon_bookmark.svg +1 -0
- package/BookReader/images/icon_close-pop.png +0 -0
- package/BookReader/images/icon_download.png +0 -0
- package/BookReader/images/icon_gear.svg +1 -0
- package/BookReader/images/icon_hamburger.svg +1 -0
- package/BookReader/images/icon_home.png +0 -0
- package/BookReader/images/icon_home.svg +1 -0
- package/BookReader/images/icon_home_ia.png +0 -0
- package/BookReader/images/icon_indicator.png +0 -0
- package/BookReader/images/icon_info.svg +1 -0
- package/BookReader/images/icon_one_page.svg +1 -0
- package/BookReader/images/icon_pause.svg +1 -0
- package/BookReader/images/icon_play.svg +1 -0
- package/BookReader/images/icon_playback-rate.svg +1 -0
- package/BookReader/images/icon_return.png +0 -0
- package/BookReader/images/icon_search_button.svg +1 -0
- package/BookReader/images/icon_share.svg +1 -0
- package/BookReader/images/icon_skip-ahead.svg +1 -0
- package/BookReader/images/icon_skip-back.svg +2 -0
- package/BookReader/images/icon_speaker.svg +1 -0
- package/BookReader/images/icon_speaker_open.svg +1 -0
- package/BookReader/images/icon_thumbnails.svg +1 -0
- package/BookReader/images/icon_toc.svg +1 -0
- package/BookReader/images/icon_two_pages.svg +1 -0
- package/BookReader/images/icon_zoomer.png +0 -0
- package/BookReader/images/loading.gif +0 -0
- package/BookReader/images/logo_icon.png +0 -0
- package/BookReader/images/marker_chap-off.png +0 -0
- package/BookReader/images/marker_chap-off.svg +1 -0
- package/BookReader/images/marker_chap-off_ia.png +0 -0
- package/BookReader/images/marker_chap-on.png +0 -0
- package/BookReader/images/marker_chap-on.svg +1 -0
- package/BookReader/images/marker_srch-on.svg +1 -0
- package/BookReader/images/marker_srchchap-off.png +0 -0
- package/BookReader/images/marker_srchchap-on.png +0 -0
- package/BookReader/images/nav_control-dn.png +0 -0
- package/BookReader/images/nav_control-dn_ia.png +0 -0
- package/BookReader/images/nav_control-up.png +0 -0
- package/BookReader/images/nav_control-up_ia.png +0 -0
- package/BookReader/images/nav_control.png +0 -0
- package/BookReader/images/one_page_mode_icon.png +0 -0
- package/BookReader/images/paper-badge.png +0 -0
- package/BookReader/images/print_icon.png +0 -0
- package/BookReader/images/progressbar.gif +0 -0
- package/BookReader/images/right_edges.png +0 -0
- package/BookReader/images/slider.png +0 -0
- package/BookReader/images/slider_ia.png +0 -0
- package/BookReader/images/thumbnail_mode_icon.png +0 -0
- package/BookReader/images/transparent.png +0 -0
- package/BookReader/images/two_page_mode_icon.png +0 -0
- package/BookReader/images/unviewable_page.png +0 -0
- package/BookReader/images/zoom_in_icon.png +0 -0
- package/BookReader/images/zoom_out_icon.png +0 -0
- package/BookReader/jquery-3.js +2 -0
- package/BookReader/jquery-3.js.LICENSE.txt +24 -0
- package/BookReader/plugins/plugin.archive_analytics.js +2 -0
- package/BookReader/plugins/plugin.archive_analytics.js.map +1 -0
- package/BookReader/plugins/plugin.autoplay.js +2 -0
- package/BookReader/plugins/plugin.autoplay.js.map +1 -0
- package/BookReader/plugins/plugin.chapters.js +26 -0
- package/BookReader/plugins/plugin.chapters.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.chapters.js.map +1 -0
- package/BookReader/plugins/plugin.experiments.js +3 -0
- package/BookReader/plugins/plugin.experiments.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.experiments.js.map +1 -0
- package/BookReader/plugins/plugin.iframe.js +2 -0
- package/BookReader/plugins/plugin.iframe.js.map +1 -0
- package/BookReader/plugins/plugin.iiif.js +2 -0
- package/BookReader/plugins/plugin.iiif.js.map +1 -0
- package/BookReader/plugins/plugin.resume.js +2 -0
- package/BookReader/plugins/plugin.resume.js.map +1 -0
- package/BookReader/plugins/plugin.search.js +3 -0
- package/BookReader/plugins/plugin.search.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.search.js.map +1 -0
- package/BookReader/plugins/plugin.text_selection.js +3 -0
- package/BookReader/plugins/plugin.text_selection.js.LICENSE.txt +1 -0
- package/BookReader/plugins/plugin.text_selection.js.map +1 -0
- package/BookReader/plugins/plugin.tts.js +3 -0
- package/BookReader/plugins/plugin.tts.js.LICENSE.txt +29 -0
- package/BookReader/plugins/plugin.tts.js.map +1 -0
- package/BookReader/plugins/plugin.url.js +2 -0
- package/BookReader/plugins/plugin.url.js.map +1 -0
- package/BookReader/plugins/plugin.vendor-fullscreen.js +2 -0
- package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -0
- 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/package.json +6 -1
- package/src/BookReader/BookModel.js +564 -0
- package/src/BookReader/DragScrollable.js +233 -0
- package/src/BookReader/ImageCache.js +149 -0
- package/src/BookReader/Mode1Up.js +110 -0
- package/src/BookReader/Mode1UpLit.js +388 -0
- package/src/BookReader/Mode2Up.js +107 -0
- package/src/BookReader/Mode2UpLit.js +777 -0
- package/src/BookReader/ModeCoordinateSpace.js +29 -0
- package/src/BookReader/ModeSmoothZoom.js +312 -0
- package/src/BookReader/ModeThumb.js +344 -0
- package/src/BookReader/Navbar/Navbar.js +355 -0
- package/src/BookReader/PageContainer.js +172 -0
- package/src/BookReader/ReduceSet.js +26 -0
- package/src/BookReader/Toolbar/Toolbar.js +362 -0
- package/src/BookReader/events.js +19 -0
- package/src/BookReader/options.js +387 -0
- 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/classes.js +36 -0
- package/src/BookReader/utils.js +313 -0
- package/.eslintrc.cjs +0 -51
- package/.gitattributes +0 -2
- package/.github/ISSUE_TEMPLATE/bug.md +0 -32
- package/.github/ISSUE_TEMPLATE/feature-request.md +0 -30
- package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +0 -15
- package/.github/workflows/node.js.yml +0 -102
- package/.github/workflows/npm-publish.yml +0 -23
- package/.testcaferc.cjs +0 -10
- package/BookReaderDemo/BookReaderDemo.css +0 -40
- package/BookReaderDemo/BookReaderJSAdvanced.js +0 -112
- package/BookReaderDemo/BookReaderJSSimple.js +0 -56
- package/BookReaderDemo/IADemoBr.js +0 -149
- package/BookReaderDemo/assets/v5/Bookreader-logo-cool-grad.svg +0 -1
- package/BookReaderDemo/assets/v5/Bookreader-logo-flat.svg +0 -1
- package/BookReaderDemo/assets/v5/Bookreader-logo-hex-cool-grad.png +0 -0
- package/BookReaderDemo/assets/v5/Bookreader-logo-hex-flat.png +0 -0
- package/BookReaderDemo/assets/v5/Bookreader-logo-lines.png +0 -0
- package/BookReaderDemo/assets/v5/Bookreader-logo-lines.svg +0 -1
- package/BookReaderDemo/assets/v5/Bookreader-logo-warm.svg +0 -1
- package/BookReaderDemo/assets/v5/bookreader-logo-renders@1x.png +0 -0
- package/BookReaderDemo/assets/v5/bookreader-logo-renders@2x.png +0 -0
- package/BookReaderDemo/assets/v5/bookreader-v5-screenshot.png +0 -0
- package/BookReaderDemo/demo-advanced.html +0 -33
- package/BookReaderDemo/demo-embed-iframe-src.html +0 -85
- package/BookReaderDemo/demo-embed.html +0 -26
- package/BookReaderDemo/demo-fullscreen-mobile.html +0 -34
- package/BookReaderDemo/demo-fullscreen.html +0 -31
- package/BookReaderDemo/demo-iiif.html +0 -121
- package/BookReaderDemo/demo-internetarchive.html +0 -271
- package/BookReaderDemo/demo-multiple.html +0 -44
- package/BookReaderDemo/demo-preview-pages.html +0 -1093
- package/BookReaderDemo/demo-simple.html +0 -35
- package/BookReaderDemo/demo-vendor-fullscreen.html +0 -34
- package/BookReaderDemo/ia-multiple-volumes-manifest.js +0 -169
- package/BookReaderDemo/immersion-1up.html +0 -64
- package/BookReaderDemo/immersion-mode.html +0 -33
- package/BookReaderDemo/toggle_controls.html +0 -54
- package/BookReaderDemo/view_mode.html +0 -40
- package/BookReaderDemo/viewmode-cycle.html +0 -40
- package/CHANGELOG.md +0 -1087
- package/CONTRIBUTING.md +0 -7
- package/babel.config.cjs +0 -20
- package/codecov.yml +0 -23
- package/index.html +0 -34
- package/netlify.toml +0 -9
- package/renovate.json +0 -52
- package/screenshot.png +0 -0
- package/scripts/postversion.js +0 -11
- package/scripts/preversion.js +0 -15
- package/scripts/version.js +0 -24
- package/tests/e2e/README.md +0 -112
- package/tests/e2e/autoplay.test.js +0 -16
- package/tests/e2e/base.test.js +0 -27
- package/tests/e2e/helpers/base.js +0 -263
- package/tests/e2e/helpers/debug.js +0 -13
- package/tests/e2e/helpers/mockSearch.js +0 -90
- package/tests/e2e/helpers/params.js +0 -17
- package/tests/e2e/helpers/rightToLeft.js +0 -23
- package/tests/e2e/helpers/search.js +0 -73
- package/tests/e2e/models/BookReader.js +0 -11
- package/tests/e2e/models/Navigation.js +0 -39
- package/tests/e2e/rightToLeft.test.js +0 -19
- package/tests/e2e/viewmode.test.js +0 -44
- package/tests/jest/BookNavigator/book-navigator.test.js +0 -653
- package/tests/jest/BookNavigator/bookmarks/bookmark-button.test.js +0 -43
- package/tests/jest/BookNavigator/bookmarks/bookmark-edit.test.js +0 -132
- package/tests/jest/BookNavigator/bookmarks/bookmarks-list.test.js +0 -221
- package/tests/jest/BookNavigator/bookmarks/ia-bookmarks.test.js +0 -45
- package/tests/jest/BookNavigator/downloads/downloads-provider.test.js +0 -67
- package/tests/jest/BookNavigator/downloads/downloads.test.js +0 -53
- package/tests/jest/BookNavigator/search/search-provider.test.js +0 -179
- package/tests/jest/BookNavigator/search/search-results.test.js +0 -289
- package/tests/jest/BookNavigator/sharing/sharing-provider.test.js +0 -49
- package/tests/jest/BookNavigator/viewable-files/viewable-files-provider.test.js +0 -80
- package/tests/jest/BookNavigator/visual-adjustments.test.js +0 -200
- package/tests/jest/BookReader.keyboard.test.js +0 -190
- package/tests/jest/BookReader.options.test.js +0 -47
- package/tests/jest/BookReader.test.js +0 -316
- package/tests/jest/plugins/plugin.archive_analytics.test.js +0 -20
- package/tests/jest/plugins/plugin.autoplay.test.js +0 -35
- package/tests/jest/plugins/plugin.chapters.test.js +0 -193
- package/tests/jest/plugins/plugin.iframe.test.js +0 -42
- package/tests/jest/plugins/plugin.resume.test.js +0 -85
- package/tests/jest/plugins/plugin.text_selection.test.js +0 -447
- package/tests/jest/plugins/plugin.vendor-fullscreen.test.js +0 -65
- package/tests/jest/plugins/search/plugin.search.test.js +0 -120
- package/tests/jest/plugins/search/plugin.search.view.test.js +0 -131
- package/tests/jest/plugins/search/utils.js +0 -25
- package/tests/jest/plugins/search/utils.test.js +0 -29
- package/tests/jest/plugins/tts/AbstractTTSEngine.test.js +0 -173
- package/tests/jest/plugins/tts/FestivalTTSEngine.test.js +0 -59
- package/tests/jest/plugins/tts/PageChunk.test.js +0 -57
- package/tests/jest/plugins/tts/PageChunkIterator.test.js +0 -179
- package/tests/jest/plugins/tts/WebTTSEngine.test.js +0 -178
- package/tests/jest/plugins/tts/utils.test.js +0 -74
- package/tests/jest/plugins/url/UrlPlugin.test.js +0 -198
- package/tests/jest/plugins/url/plugin.url.test.js +0 -168
- package/tests/jest/setup.js +0 -3
- package/tests/jest/util/browserSniffing.test.js +0 -62
- package/tests/jest/util/docCookies.test.js +0 -24
- package/tests/jest/util/strings.test.js +0 -63
- package/tests/jest/utils.js +0 -83
- package/webpack.config.js +0 -97
@@ -1,653 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
html,
|
3
|
-
elementUpdated,
|
4
|
-
fixtureCleanup,
|
5
|
-
fixtureSync,
|
6
|
-
} from '@open-wc/testing-helpers';
|
7
|
-
import sinon from 'sinon';
|
8
|
-
import DownloadsProvider from '@/src/BookNavigator/downloads/downloads-provider.js';
|
9
|
-
import SearchProvider from '@/src/BookNavigator/search/search-provider.js';
|
10
|
-
import SharingProvider from '@/src/BookNavigator/sharing.js';
|
11
|
-
import VisualAdjustmentsProvider from '@/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js';
|
12
|
-
import ViewableFilesProvider from '@/src/BookNavigator/viewable-files.js';
|
13
|
-
import { ModalManager } from '@internetarchive/modal-manager';
|
14
|
-
import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
|
15
|
-
import '@/src/BookNavigator/book-navigator.js';
|
16
|
-
|
17
|
-
const promise0 = () => new Promise(res => setTimeout(res, 0));
|
18
|
-
|
19
|
-
const container = (sharedObserver = null) => {
|
20
|
-
const itemStub = {
|
21
|
-
metadata: {
|
22
|
-
identifier: 'foo',
|
23
|
-
creator: 'bar',
|
24
|
-
title: 'baz',
|
25
|
-
},
|
26
|
-
};
|
27
|
-
const modalMgr = new ModalManager();
|
28
|
-
return html`
|
29
|
-
<book-navigator
|
30
|
-
.itemMD=${itemStub}
|
31
|
-
.baseHost=${`https://foo.archive.org`}
|
32
|
-
.sharedObserver=${sharedObserver || new SharedResizeObserver()}
|
33
|
-
.modal=${modalMgr}
|
34
|
-
>
|
35
|
-
<div slot="main">
|
36
|
-
<div id="BookReader"></div>
|
37
|
-
<p class="visible-in-reader">now showing</p>
|
38
|
-
<\div>
|
39
|
-
</book-navigator>
|
40
|
-
`;
|
41
|
-
};
|
42
|
-
|
43
|
-
window.ResizeObserver = class ResizeObserver {
|
44
|
-
observe = sinon.fake()
|
45
|
-
unobserve = sinon.fake()
|
46
|
-
disconnect = sinon.fake()
|
47
|
-
};
|
48
|
-
|
49
|
-
beforeEach(() => {
|
50
|
-
window.archive_analytics = {
|
51
|
-
send_event_no_sampling: sinon.fake(),
|
52
|
-
send_event: sinon.fake(),
|
53
|
-
};
|
54
|
-
});
|
55
|
-
|
56
|
-
afterEach(() => {
|
57
|
-
window.br = null;
|
58
|
-
fixtureCleanup();
|
59
|
-
const body = document.querySelector('body');
|
60
|
-
body.innerHTML = '';
|
61
|
-
sinon.restore();
|
62
|
-
});
|
63
|
-
|
64
|
-
|
65
|
-
describe('<book-navigator>', () => {
|
66
|
-
describe("How it loads", () => {
|
67
|
-
describe('Attaches BookReader listeners before `br.init` is called', () => {
|
68
|
-
test('binds global event listeners', async () => {
|
69
|
-
const el = fixtureSync(container());
|
70
|
-
const spy = sinon.spy(el, 'bindEventListeners');
|
71
|
-
await elementUpdated(el);
|
72
|
-
expect(spy.callCount).toEqual(1);
|
73
|
-
});
|
74
|
-
test('Listens for Global Event @BookReader:PostInit', async () => {
|
75
|
-
const brStub = {
|
76
|
-
resize: sinon.fake(),
|
77
|
-
currentIndex: sinon.fake(),
|
78
|
-
jumpToIndex: sinon.fake(),
|
79
|
-
options: { enableMultipleBooks: false }, // for multipleBooks
|
80
|
-
el: '#BookReader',
|
81
|
-
refs: {},
|
82
|
-
};
|
83
|
-
|
84
|
-
const sharedObserver = new SharedResizeObserver();
|
85
|
-
sinon.spy(sharedObserver, 'addObserver');
|
86
|
-
const el = fixtureSync(container(sharedObserver));
|
87
|
-
|
88
|
-
el.initializeBookSubmenus = sinon.fake();
|
89
|
-
el.emitLoadingStatusUpdate = sinon.fake();
|
90
|
-
el.handleResize = sinon.fake();
|
91
|
-
await elementUpdated(el);
|
92
|
-
|
93
|
-
expect(brStub.resize.callCount).toEqual(0);
|
94
|
-
|
95
|
-
window.dispatchEvent(new CustomEvent('BookReader:PostInit', {
|
96
|
-
detail: { props: brStub },
|
97
|
-
}));
|
98
|
-
await elementUpdated(el);
|
99
|
-
|
100
|
-
expect(el.emitLoadingStatusUpdate.callCount).toEqual(1);
|
101
|
-
expect(el.bookreader).toEqual(brStub); // sets bookreader
|
102
|
-
expect(el.bookReaderLoaded).toBeTruthy(); // notes bookreader is loaded
|
103
|
-
expect(el.bookReaderCannotLoad).toBeFalsy();
|
104
|
-
expect(sharedObserver.addObserver.callCount).toEqual(1);
|
105
|
-
|
106
|
-
await promise0();
|
107
|
-
|
108
|
-
expect(brStub.resize.callCount > 0).toBeTruthy();
|
109
|
-
});
|
110
|
-
});
|
111
|
-
test('Emits a BrBookNav:PostInit event at completion', async () => {
|
112
|
-
let initEventFired = false;
|
113
|
-
window.addEventListener('BrBookNav:PostInit', (e) => {
|
114
|
-
initEventFired = true;
|
115
|
-
});
|
116
|
-
const el = fixtureSync(container());
|
117
|
-
const spy = sinon.spy(el, 'emitPostInit');
|
118
|
-
|
119
|
-
await elementUpdated(el);
|
120
|
-
|
121
|
-
expect(initEventFired).toBeTruthy();
|
122
|
-
expect(spy.callCount).toEqual(1);
|
123
|
-
});
|
124
|
-
|
125
|
-
test('creates an item image from metadata', async () => {
|
126
|
-
const el = fixtureSync(container());
|
127
|
-
const itemImage = fixtureSync(el.itemImage);
|
128
|
-
expect(itemImage).toBeInstanceOf(HTMLImageElement);
|
129
|
-
expect(itemImage.getAttribute('class')).toEqual('cover-img');
|
130
|
-
expect(itemImage.getAttribute('src')).toEqual('https://https://foo.archive.org/services/img/foo');
|
131
|
-
});
|
132
|
-
});
|
133
|
-
describe('Menu/Layer Provider', () => {
|
134
|
-
describe('Connecting with a provider:', () => {
|
135
|
-
// loads Providers with base shared resources
|
136
|
-
test('We load 3 Sub Menus by default', async() => {
|
137
|
-
const el = fixtureSync(container());
|
138
|
-
const $brContainer = document.createElement('div');
|
139
|
-
const brStub = {
|
140
|
-
resize: sinon.fake(),
|
141
|
-
currentIndex: sinon.fake(),
|
142
|
-
jumpToIndex: sinon.fake(),
|
143
|
-
options: {},
|
144
|
-
refs: {
|
145
|
-
$brContainer,
|
146
|
-
},
|
147
|
-
};
|
148
|
-
el.bookreader = brStub;
|
149
|
-
await el.elementUpdated;
|
150
|
-
|
151
|
-
el.downloadableTypes = ['foo/bar'];
|
152
|
-
await el.elementUpdated;
|
153
|
-
|
154
|
-
el.initializeBookSubmenus();
|
155
|
-
await el.elementUpdated;
|
156
|
-
const defaultMenus = Object.keys(el.menuProviders);
|
157
|
-
expect(defaultMenus).toContain('downloads');
|
158
|
-
expect(el.menuProviders.downloads).toBeInstanceOf(DownloadsProvider);
|
159
|
-
|
160
|
-
expect(defaultMenus).toContain('share');
|
161
|
-
expect(el.menuProviders.share).toBeInstanceOf(SharingProvider);
|
162
|
-
|
163
|
-
expect(defaultMenus).toContain('visualAdjustments');
|
164
|
-
expect(el.menuProviders.visualAdjustments).toBeInstanceOf(VisualAdjustmentsProvider);
|
165
|
-
});
|
166
|
-
describe('Loading Sub Menus By Plugin Flags', () => {
|
167
|
-
test('Search: uses `enabled` flag', async() => {
|
168
|
-
const el = fixtureSync(container());
|
169
|
-
const $brContainer = document.createElement('div');
|
170
|
-
const brStub = {
|
171
|
-
resize: sinon.fake(),
|
172
|
-
currentIndex: sinon.fake(),
|
173
|
-
jumpToIndex: sinon.fake(),
|
174
|
-
options: {
|
175
|
-
plugins: {
|
176
|
-
search: {
|
177
|
-
enabled: true,
|
178
|
-
},
|
179
|
-
},
|
180
|
-
},
|
181
|
-
refs: {
|
182
|
-
$brContainer,
|
183
|
-
},
|
184
|
-
};
|
185
|
-
el.bookreader = brStub;
|
186
|
-
await el.elementUpdated;
|
187
|
-
|
188
|
-
el.initializeBookSubmenus();
|
189
|
-
await el.elementUpdated;
|
190
|
-
|
191
|
-
expect(el.menuProviders.search).toBeDefined();
|
192
|
-
expect(el.menuProviders.search).toBeInstanceOf(SearchProvider);
|
193
|
-
|
194
|
-
// also adds a menu shortcut
|
195
|
-
expect(el.menuShortcuts.find(m => m.id === 'search')).toBeDefined();
|
196
|
-
});
|
197
|
-
test('Volumes/Multiple Books: uses `enableMultipleBooks` flag', async() => {
|
198
|
-
const el = fixtureSync(container());
|
199
|
-
const $brContainer = document.createElement('div');
|
200
|
-
const brStub = {
|
201
|
-
resize: sinon.fake(),
|
202
|
-
currentIndex: sinon.fake(),
|
203
|
-
jumpToIndex: sinon.fake(),
|
204
|
-
options: {
|
205
|
-
enableMultipleBooks: true,
|
206
|
-
multipleBooksList: {
|
207
|
-
by_subprefix: {
|
208
|
-
fooSubprefix: 'beep',
|
209
|
-
},
|
210
|
-
},
|
211
|
-
},
|
212
|
-
refs: {
|
213
|
-
$brContainer,
|
214
|
-
},
|
215
|
-
};
|
216
|
-
el.bookreader = brStub;
|
217
|
-
await el.elementUpdated;
|
218
|
-
|
219
|
-
el.initializeBookSubmenus();
|
220
|
-
await el.elementUpdated;
|
221
|
-
|
222
|
-
expect(el.menuProviders.volumes).toBeDefined();
|
223
|
-
expect(el.menuProviders.volumes).toBeInstanceOf(ViewableFilesProvider);
|
224
|
-
|
225
|
-
// also adds a menu shortcut
|
226
|
-
expect(el.menuShortcuts.find(m => m.id === 'volumes')).toBeDefined();
|
227
|
-
});
|
228
|
-
});
|
229
|
-
test('keeps track of base shared resources for providers in: `baseProviderConfig`', () => {
|
230
|
-
const el = fixtureSync(container());
|
231
|
-
const baseConfigKeys = Object.keys(el.baseProviderConfig);
|
232
|
-
expect(baseConfigKeys).toContain('baseHost');
|
233
|
-
expect(baseConfigKeys).toContain('modal');
|
234
|
-
expect(baseConfigKeys).toContain('sharedObserver');
|
235
|
-
expect(baseConfigKeys).toContain('bookreader');
|
236
|
-
expect(baseConfigKeys).toContain('item');
|
237
|
-
expect(baseConfigKeys).toContain('signedIn');
|
238
|
-
expect(baseConfigKeys).toContain('isAdmin');
|
239
|
-
expect(baseConfigKeys).toContain('onProviderChange');
|
240
|
-
});
|
241
|
-
|
242
|
-
test('Downloads panel - does not show if no available `downloadableTypes`', async () => {
|
243
|
-
const el = fixtureSync(container());
|
244
|
-
const $brContainer = document.createElement('div');
|
245
|
-
const brStub = {
|
246
|
-
resize: sinon.fake(),
|
247
|
-
currentIndex: sinon.fake(),
|
248
|
-
jumpToIndex: sinon.fake(),
|
249
|
-
options: {},
|
250
|
-
refs: {
|
251
|
-
$brContainer,
|
252
|
-
},
|
253
|
-
};
|
254
|
-
el.bookreader = brStub;
|
255
|
-
await el.elementUpdated;
|
256
|
-
|
257
|
-
el.initializeBookSubmenus();
|
258
|
-
await el.elementUpdated;
|
259
|
-
const defaultMenus = Object.keys(el.menuProviders);
|
260
|
-
expect(defaultMenus.find(menu => menu === 'downloads')).toBeUndefined;
|
261
|
-
});
|
262
|
-
});
|
263
|
-
|
264
|
-
describe('Controlling Menu Side Panel & Shortcuts', () => {
|
265
|
-
describe('Side Menu Panels', () => {
|
266
|
-
test('`isWideEnoughToOpenMenu` checks if menu should be open', async () => {
|
267
|
-
const el = fixtureSync(container());
|
268
|
-
el.brWidth = 300;
|
269
|
-
await el.elementUpdated;
|
270
|
-
|
271
|
-
expect(el.isWideEnoughToOpenMenu).toEqual(false);
|
272
|
-
|
273
|
-
el.brWidth = 641;
|
274
|
-
await el.elementUpdated;
|
275
|
-
|
276
|
-
expect(el.isWideEnoughToOpenMenu).toEqual(true);
|
277
|
-
});
|
278
|
-
describe('Control which side menu to toggle open by using: `this.updateSideMenu`', () => {
|
279
|
-
test('Emits `@updateSideMenu` to signal which menu gets the update', async () => {
|
280
|
-
const el = fixtureSync(container());
|
281
|
-
const brStub = {
|
282
|
-
resize: sinon.fake(),
|
283
|
-
currentIndex: sinon.fake(),
|
284
|
-
jumpToIndex: sinon.fake(),
|
285
|
-
options: { enableMultipleBooks: true },
|
286
|
-
refs: {},
|
287
|
-
};
|
288
|
-
el.bookreader = brStub;
|
289
|
-
await elementUpdated(el);
|
290
|
-
|
291
|
-
let initEventFired = false;
|
292
|
-
let eventDetails = {};
|
293
|
-
el.addEventListener('updateSideMenu', (e) => {
|
294
|
-
eventDetails = e.detail;
|
295
|
-
initEventFired = true;
|
296
|
-
});
|
297
|
-
|
298
|
-
el.updateSideMenu('foo', 'open');
|
299
|
-
expect(initEventFired).toEqual(true);
|
300
|
-
expect(eventDetails.menuId).toEqual('foo');
|
301
|
-
expect(eventDetails.action).toEqual('open');
|
302
|
-
});
|
303
|
-
test('Will Not Emit `@updateSideMenu` if menu ID is missing', async() => {
|
304
|
-
const el = fixtureSync(container());
|
305
|
-
const brStub = {
|
306
|
-
resize: sinon.fake(),
|
307
|
-
currentIndex: sinon.fake(),
|
308
|
-
jumpToIndex: sinon.fake(),
|
309
|
-
options: { enableMultipleBooks: true },
|
310
|
-
refs: {},
|
311
|
-
};
|
312
|
-
el.bookreader = brStub;
|
313
|
-
await elementUpdated(el);
|
314
|
-
|
315
|
-
let initEventFired = false;
|
316
|
-
el.addEventListener('updateSideMenu', (e) => {
|
317
|
-
initEventFired = true;
|
318
|
-
});
|
319
|
-
|
320
|
-
el.updateSideMenu('', 'open');
|
321
|
-
expect(initEventFired).toEqual(false);
|
322
|
-
});
|
323
|
-
});
|
324
|
-
});
|
325
|
-
|
326
|
-
describe('Behaviors for specific menus', () => {
|
327
|
-
describe('Search menu - ref: plugin.search.js', () => {
|
328
|
-
test('Event: listens for `BookReader:ToggleSearchMenu to open search side panel', async () => {
|
329
|
-
const el = fixtureSync(container());
|
330
|
-
const brStub = {
|
331
|
-
resize: sinon.fake(),
|
332
|
-
currentIndex: sinon.fake(),
|
333
|
-
jumpToIndex: sinon.fake(),
|
334
|
-
options: { enableMultipleBooks: true },
|
335
|
-
refs: {},
|
336
|
-
};
|
337
|
-
el.bookreader = brStub;
|
338
|
-
await elementUpdated(el);
|
339
|
-
|
340
|
-
let sidePanelConfig = {};
|
341
|
-
el.addEventListener('updateSideMenu', (e) => {
|
342
|
-
sidePanelConfig = e.detail;
|
343
|
-
});
|
344
|
-
const toggleSearchMenuEvent = new Event('BookReader:ToggleSearchMenu');
|
345
|
-
window.dispatchEvent(toggleSearchMenuEvent);
|
346
|
-
|
347
|
-
await elementUpdated(el);
|
348
|
-
expect(sidePanelConfig.menuId).toEqual('search');
|
349
|
-
expect(sidePanelConfig.action).toEqual('toggle');
|
350
|
-
});
|
351
|
-
});
|
352
|
-
});
|
353
|
-
});
|
354
|
-
});
|
355
|
-
|
356
|
-
describe('Resizing',() => {
|
357
|
-
test('keeps track of `brWidth` and `brHeight`', async () => {
|
358
|
-
const el = fixtureSync(container());
|
359
|
-
const brStub = {
|
360
|
-
resize: sinon.fake(),
|
361
|
-
options: {},
|
362
|
-
refs: {
|
363
|
-
$brContainer: document.createElement('div'),
|
364
|
-
},
|
365
|
-
};
|
366
|
-
el.bookreader = brStub;
|
367
|
-
await elementUpdated(el);
|
368
|
-
expect(el.brWidth).toEqual(0);
|
369
|
-
expect(el.brHeight).toEqual(0);
|
370
|
-
|
371
|
-
const mockResizeEvent = {
|
372
|
-
contentRect: {
|
373
|
-
height: 500,
|
374
|
-
width: 900,
|
375
|
-
},
|
376
|
-
target: el.mainBRContainer,
|
377
|
-
};
|
378
|
-
el.handleResize(mockResizeEvent);
|
379
|
-
|
380
|
-
await elementUpdated(el);
|
381
|
-
await promise0();
|
382
|
-
|
383
|
-
expect(el.brHeight).toEqual(500);
|
384
|
-
expect(el.brWidth).toEqual(900);
|
385
|
-
});
|
386
|
-
test('resizes if height/width changes && is not animating', async () => {
|
387
|
-
const el = fixtureSync(container());
|
388
|
-
const brStub = {
|
389
|
-
animating: false,
|
390
|
-
resize: sinon.fake(),
|
391
|
-
options: {},
|
392
|
-
refs: {
|
393
|
-
$brContainer: document.createElement('div'),
|
394
|
-
},
|
395
|
-
};
|
396
|
-
|
397
|
-
el.bookreader = brStub;
|
398
|
-
await elementUpdated(el);
|
399
|
-
expect(el.brWidth).toEqual(0);
|
400
|
-
expect(el.brHeight).toEqual(0);
|
401
|
-
|
402
|
-
const mockResizeEvent = {
|
403
|
-
contentRect: {
|
404
|
-
height: 500,
|
405
|
-
width: 900,
|
406
|
-
},
|
407
|
-
target: el.mainBRContainer,
|
408
|
-
};
|
409
|
-
el.handleResize(mockResizeEvent);
|
410
|
-
|
411
|
-
await elementUpdated(el);
|
412
|
-
await promise0();
|
413
|
-
|
414
|
-
expect(brStub.resize.callCount).toEqual(1);
|
415
|
-
});
|
416
|
-
test('does not resize bookreader if animating', async () => {
|
417
|
-
const el = fixtureSync(container());
|
418
|
-
const brStub = {
|
419
|
-
animating: true, // <-- testing for this
|
420
|
-
resize: sinon.fake(),
|
421
|
-
currentIndex: sinon.fake(),
|
422
|
-
jumpToIndex: sinon.fake(),
|
423
|
-
options: { enableMultipleBooks: true },
|
424
|
-
refs: {},
|
425
|
-
};
|
426
|
-
|
427
|
-
el.bookreader = brStub;
|
428
|
-
await elementUpdated(el);
|
429
|
-
|
430
|
-
expect(el.bookreader.resize.callCount).toEqual(0);
|
431
|
-
expect(el.bookreader.currentIndex.callCount).toEqual(0);
|
432
|
-
expect(el.bookreader.jumpToIndex.callCount).toEqual(0);
|
433
|
-
});
|
434
|
-
});
|
435
|
-
|
436
|
-
describe('Fullscreen Management', () => {
|
437
|
-
test('needs option: `enableFSLogoShortcut` to use FS logo', async () => {
|
438
|
-
const el = fixtureSync(container());
|
439
|
-
const brStub = {
|
440
|
-
isFullscreen: () => true,
|
441
|
-
options: {
|
442
|
-
enableFSLogoShortcut: false,
|
443
|
-
},
|
444
|
-
refs: {},
|
445
|
-
};
|
446
|
-
|
447
|
-
el.bookreader = brStub;
|
448
|
-
el.emitMenuShortcutsUpdated = sinon.fake();
|
449
|
-
await elementUpdated(el);
|
450
|
-
|
451
|
-
el.manageFullScreenBehavior();
|
452
|
-
await elementUpdated(el);
|
453
|
-
expect(el.menuShortcuts.length).toEqual(0);
|
454
|
-
});
|
455
|
-
test('sets fullscreen shortcut when entering Fullscreen', async () => {
|
456
|
-
const el = fixtureSync(container());
|
457
|
-
const brStub = {
|
458
|
-
isFullscreen: () => true,
|
459
|
-
options: {
|
460
|
-
enableFSLogoShortcut: true,
|
461
|
-
},
|
462
|
-
refs: {},
|
463
|
-
};
|
464
|
-
|
465
|
-
el.bookreader = brStub;
|
466
|
-
el.emitMenuShortcutsUpdated = sinon.fake();
|
467
|
-
await elementUpdated(el);
|
468
|
-
|
469
|
-
el.manageFullScreenBehavior();
|
470
|
-
await elementUpdated(el);
|
471
|
-
expect(el.menuShortcuts.length).toEqual(1);
|
472
|
-
expect(el.menuShortcuts[0].id).toEqual('fullscreen');
|
473
|
-
expect(el.menuShortcuts[0].icon).toBeDefined();
|
474
|
-
expect(el.emitMenuShortcutsUpdated.callCount).toEqual(1);
|
475
|
-
});
|
476
|
-
test('clicking Fullscreen shortcut closes fullscreen', async () => {
|
477
|
-
const el = fixtureSync(container());
|
478
|
-
const brStub = {
|
479
|
-
isFullscreen: () => true,
|
480
|
-
options: {
|
481
|
-
enableFSLogoShortcut: true,
|
482
|
-
},
|
483
|
-
refs: {},
|
484
|
-
};
|
485
|
-
|
486
|
-
el.bookreader = brStub;
|
487
|
-
el.emitMenuShortcutsUpdated = sinon.fake();
|
488
|
-
el.closeFullscreen = sinon.fake();
|
489
|
-
await elementUpdated(el);
|
490
|
-
|
491
|
-
el.manageFullScreenBehavior();
|
492
|
-
await elementUpdated(el);
|
493
|
-
|
494
|
-
fixtureSync(el.menuShortcuts[0].icon).click();
|
495
|
-
await elementUpdated(el);
|
496
|
-
|
497
|
-
expect(el.closeFullscreen.callCount).toEqual(1);
|
498
|
-
});
|
499
|
-
test('removes Fullscreen shortcut when leaving fullscreen', async() => {
|
500
|
-
const el = fixtureSync(container());
|
501
|
-
const brStub = {
|
502
|
-
isFullscreen: () => false,
|
503
|
-
options: {
|
504
|
-
enableFSLogoShortcut: true,
|
505
|
-
},
|
506
|
-
refs: {},
|
507
|
-
};
|
508
|
-
|
509
|
-
el.bookreader = brStub;
|
510
|
-
el.emitMenuShortcutsUpdated = sinon.fake();
|
511
|
-
await elementUpdated(el);
|
512
|
-
|
513
|
-
el.manageFullScreenBehavior();
|
514
|
-
await elementUpdated(el);
|
515
|
-
expect(el.menuShortcuts.length).toEqual(0);
|
516
|
-
expect(el.emitMenuShortcutsUpdated.callCount).toEqual(1);
|
517
|
-
});
|
518
|
-
test('Event: Listens for `BookReader:FullscreenToggled', async() => {
|
519
|
-
const el = fixtureSync(container());
|
520
|
-
const brStub = {
|
521
|
-
isFullscreen: () => true,
|
522
|
-
resize: sinon.fake(),
|
523
|
-
currentIndex: sinon.fake(),
|
524
|
-
jumpToIndex: sinon.fake(),
|
525
|
-
options: {
|
526
|
-
enableFSLogoShortcut: true,
|
527
|
-
},
|
528
|
-
refs: {},
|
529
|
-
};
|
530
|
-
el.bookreader = brStub;
|
531
|
-
el.manageFullScreenBehavior = sinon.fake();
|
532
|
-
await elementUpdated(el);
|
533
|
-
|
534
|
-
window.dispatchEvent(new CustomEvent('BookReader:fullscreenToggled', {
|
535
|
-
detail: { props: brStub },
|
536
|
-
}));
|
537
|
-
await elementUpdated(el);
|
538
|
-
|
539
|
-
expect(el.manageFullScreenBehavior.callCount).toEqual(1);
|
540
|
-
});
|
541
|
-
});
|
542
|
-
describe('Handles Restricted Books', () => {
|
543
|
-
describe('contextMenu is prevented when book is restricted', () => {
|
544
|
-
it('watches on `div.BRscreen`', async () => {
|
545
|
-
const el = fixtureSync(container());
|
546
|
-
const brStub = {
|
547
|
-
options: { restricted: true },
|
548
|
-
};
|
549
|
-
|
550
|
-
el.bookreader = brStub;
|
551
|
-
el.bookIsRestricted = true;
|
552
|
-
|
553
|
-
const elSpy = sinon.spy(el.manageContextMenuVisibility);
|
554
|
-
await el.elementUpdated;
|
555
|
-
|
556
|
-
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(false);
|
557
|
-
expect(window.archive_analytics.send_event.called).toEqual(false);
|
558
|
-
expect(elSpy.called).toEqual(false);
|
559
|
-
|
560
|
-
const body = document.querySelector('body');
|
561
|
-
|
562
|
-
const divBRscreen = document.createElement('div');
|
563
|
-
divBRscreen.classList.add('BRscreen');
|
564
|
-
body.appendChild(divBRscreen);
|
565
|
-
|
566
|
-
const contextMenuEvent = new Event('contextmenu', { bubbles: true });
|
567
|
-
|
568
|
-
// Set spy on contextMenuEvent to check if `preventDefault` is called
|
569
|
-
const preventDefaultSpy = sinon.spy(contextMenuEvent, 'preventDefault');
|
570
|
-
expect(preventDefaultSpy.called).toEqual(false);
|
571
|
-
|
572
|
-
divBRscreen.dispatchEvent(contextMenuEvent);
|
573
|
-
|
574
|
-
// analytics fires
|
575
|
-
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(
|
576
|
-
false,
|
577
|
-
);
|
578
|
-
expect(window.archive_analytics.send_event.called).toEqual(true);
|
579
|
-
// we prevent default
|
580
|
-
expect(preventDefaultSpy.called).toEqual(true);
|
581
|
-
});
|
582
|
-
it('watches on `img.BRpageimage`', async () => {
|
583
|
-
const el = fixtureSync(container());
|
584
|
-
const brStub = {
|
585
|
-
options: { restricted: true },
|
586
|
-
};
|
587
|
-
|
588
|
-
el.bookreader = brStub;
|
589
|
-
el.bookIsRestricted = true;
|
590
|
-
|
591
|
-
await el.elementUpdated;
|
592
|
-
|
593
|
-
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(false);
|
594
|
-
expect(window.archive_analytics.send_event.called).toEqual(false);
|
595
|
-
|
596
|
-
const body = document.querySelector('body');
|
597
|
-
// const element stub for img.BRpageimage
|
598
|
-
const imgBRpageimage = document.createElement('img');
|
599
|
-
imgBRpageimage.classList.add('BRpageimage');
|
600
|
-
body.appendChild(imgBRpageimage);
|
601
|
-
const contextMenuEvent = new Event('contextmenu', { bubbles: true });
|
602
|
-
|
603
|
-
// Set spy on contextMenuEvent to check if `preventDefault` is called
|
604
|
-
const preventDefaultSpy = sinon.spy(contextMenuEvent, 'preventDefault');
|
605
|
-
expect(preventDefaultSpy.called).toEqual(false);
|
606
|
-
|
607
|
-
imgBRpageimage.dispatchEvent(contextMenuEvent);
|
608
|
-
|
609
|
-
// analytics fires
|
610
|
-
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(false);
|
611
|
-
expect(window.archive_analytics.send_event.called).toEqual(true);
|
612
|
-
// we prevent default
|
613
|
-
expect(preventDefaultSpy.called).toEqual(true);
|
614
|
-
});
|
615
|
-
});
|
616
|
-
it('Allows unrestricted books access to context menu', async () => {
|
617
|
-
const el = fixtureSync(container());
|
618
|
-
const brStub = {
|
619
|
-
options: { restricted: false },
|
620
|
-
};
|
621
|
-
|
622
|
-
el.bookreader = brStub;
|
623
|
-
el.bookIsRestricted = false;
|
624
|
-
|
625
|
-
await el.elementUpdated;
|
626
|
-
|
627
|
-
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(
|
628
|
-
false,
|
629
|
-
);
|
630
|
-
expect(window.archive_analytics.send_event.called).toEqual(false);
|
631
|
-
|
632
|
-
|
633
|
-
const body = document.querySelector('body');
|
634
|
-
// const element stub for img.BRpageimage
|
635
|
-
const imgBRpageimage = document.createElement('img');
|
636
|
-
imgBRpageimage.classList.add('not-targeted-element');
|
637
|
-
body.appendChild(imgBRpageimage);
|
638
|
-
const contextMenuEvent = new Event('contextmenu', { bubbles: true });
|
639
|
-
|
640
|
-
// Set spy on contextMenuEvent to check if `preventDefault` is called
|
641
|
-
const preventDefaultSpy = sinon.spy(contextMenuEvent, 'preventDefault');
|
642
|
-
expect(preventDefaultSpy.called).toEqual(false);
|
643
|
-
|
644
|
-
imgBRpageimage.dispatchEvent(contextMenuEvent);
|
645
|
-
|
646
|
-
// analytics fires
|
647
|
-
expect(window.archive_analytics.send_event_no_sampling.called).toEqual(false);
|
648
|
-
expect(window.archive_analytics.send_event.called).toEqual(true);
|
649
|
-
// we do not prevent default
|
650
|
-
expect(preventDefaultSpy.called).toEqual(false);
|
651
|
-
});
|
652
|
-
});
|
653
|
-
});
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
html,
|
3
|
-
fixtureSync,
|
4
|
-
fixtureCleanup,
|
5
|
-
} from '@open-wc/testing-helpers';
|
6
|
-
import '@/src/BookNavigator/bookmarks/bookmark-button.js';
|
7
|
-
import sinon from 'sinon';
|
8
|
-
|
9
|
-
afterEach(() => {
|
10
|
-
sinon.restore();
|
11
|
-
fixtureCleanup();
|
12
|
-
});
|
13
|
-
|
14
|
-
describe('<bookmark-button>', () => {
|
15
|
-
test('sets default properties', async () => {
|
16
|
-
const el = fixtureSync(html`<bookmark-button></bookmark-button>`);
|
17
|
-
|
18
|
-
expect(el.side).toBeUndefined();
|
19
|
-
expect(el.state).toEqual('hollow');
|
20
|
-
});
|
21
|
-
test('Event: fires `@bookmarkButtonClicked on click', async () => {
|
22
|
-
const el = fixtureSync(html`<bookmark-button></bookmark-button>`);
|
23
|
-
let buttonClicked = false;
|
24
|
-
el.addEventListener('bookmarkButtonClicked', () => { buttonClicked = true; });
|
25
|
-
const eventStub = { preventDefault: sinon.fake()};
|
26
|
-
el.handleClick(eventStub);
|
27
|
-
await el.updateComplete;
|
28
|
-
|
29
|
-
expect(buttonClicked).toBeTruthy();
|
30
|
-
expect(eventStub.preventDefault.callCount).toEqual(1);
|
31
|
-
});
|
32
|
-
test('Title: Toggles title between `Add/Remove bookmark`', async () => {
|
33
|
-
const el = fixtureSync(html`<bookmark-button></bookmark-button>`);
|
34
|
-
expect(el.title).toEqual('Add bookmark');
|
35
|
-
expect(el.state).toEqual('hollow');
|
36
|
-
|
37
|
-
el.state = 'filled';
|
38
|
-
await el.updateComplete;
|
39
|
-
|
40
|
-
expect(el.title).toEqual('Remove bookmark');
|
41
|
-
expect(el.state).not.toEqual('hollow');
|
42
|
-
});
|
43
|
-
});
|