@internetarchive/bookreader 5.0.0-42-a2 → 5.0.0-44-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/.github/workflows/node.js.yml +14 -14
- package/.github/workflows/npm-publish.yml +4 -4
- package/BookReader/BookReader.css +14 -15
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +87 -87
- package/BookReader/ia-bookreader-bundle.js.map +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/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-1.10.1.js +1 -1
- package/BookReader/jquery-1.10.1.js.LICENSE.txt +6 -6
- package/BookReader/plugins/plugin.archive_analytics.js +1 -1
- package/BookReader/plugins/plugin.archive_analytics.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/BookReaderDemo/IADemoBr.js +30 -0
- package/BookReaderDemo/demo-internetarchive.html +3 -0
- package/CHANGELOG.md +9 -0
- package/babel.config.js +1 -1
- package/package.json +22 -27
- package/renovate.json +13 -4
- package/scripts/preversion.js +4 -1
- package/src/BookNavigator/book-navigator.js +4 -0
- package/src/BookNavigator/downloads/downloads-provider.js +14 -5
- package/src/BookNavigator/downloads/downloads.js +23 -1
- package/src/BookNavigator/search/a-search-result.js +4 -6
- package/src/css/_controls.scss +1 -2
- package/src/plugins/search/plugin.search.js +17 -4
- package/src/plugins/search/view.js +1 -3
- package/src/plugins/tts/plugin.tts.js +15 -3
- package/tests/{karma → jest}/BookNavigator/book-navigator.test.js +119 -104
- package/tests/{karma → jest}/BookNavigator/bookmarks/bookmark-button.test.js +13 -14
- 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/{karma → jest}/BookNavigator/downloads/downloads-provider.test.js +18 -18
- package/tests/{karma → jest}/BookNavigator/downloads/downloads.test.js +7 -8
- package/tests/{karma → jest}/BookNavigator/search/search-provider.test.js +29 -29
- package/tests/{karma → jest}/BookNavigator/search/search-results.test.js +57 -56
- package/tests/{karma → jest}/BookNavigator/sharing/sharing-provider.test.js +8 -8
- package/tests/jest/BookNavigator/visual-adjustments.test.js +200 -0
- package/tests/{karma → jest}/BookNavigator/volumes/volumes-provider.test.js +38 -38
- package/tests/{karma → jest}/BookNavigator/volumes/volumes.test.js +15 -16
- package/tests/jest/plugins/search/plugin.search.test.js +40 -23
- package/tests/jest/plugins/tts/AbstractTTSEngine.test.js +3 -3
- package/karma.conf.js +0 -23
- package/tests/karma/BookNavigator/bookmarks/ia-bookmarks.test.js +0 -57
- package/tests/karma/BookNavigator/visual-adjustments.test.js +0 -201
@@ -3,17 +3,16 @@ import {
|
|
3
3
|
elementUpdated,
|
4
4
|
fixtureCleanup,
|
5
5
|
fixtureSync,
|
6
|
-
|
7
|
-
} from '@open-wc/testing';
|
6
|
+
} from '@open-wc/testing-helpers';
|
8
7
|
import sinon from 'sinon';
|
9
|
-
import DownloadsProvider from '
|
10
|
-
import SearchProvider from '
|
11
|
-
import SharingProvider from '
|
12
|
-
import VisualAdjustmentsProvider from '
|
13
|
-
import VolumesProvider from '
|
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 VolumesProvider from '@/src/BookNavigator/volumes/volumes-provider.js';
|
14
13
|
import { ModalManager } from '@internetarchive/modal-manager';
|
15
14
|
import { SharedResizeObserver } from '@internetarchive/shared-resize-observer';
|
16
|
-
import '
|
15
|
+
import '@/src/BookNavigator/book-navigator.js';
|
17
16
|
|
18
17
|
const promise0 = () => new Promise(res => setTimeout(res, 0));
|
19
18
|
|
@@ -41,6 +40,12 @@ const container = (sharedObserver = null) => {
|
|
41
40
|
`;
|
42
41
|
};
|
43
42
|
|
43
|
+
window.ResizeObserver = class ResizeObserver {
|
44
|
+
observe = sinon.fake()
|
45
|
+
unobserve = sinon.fake()
|
46
|
+
disconnect = sinon.fake()
|
47
|
+
};
|
48
|
+
|
44
49
|
afterEach(() => {
|
45
50
|
window.br = null;
|
46
51
|
fixtureCleanup();
|
@@ -53,19 +58,20 @@ afterEach(() => {
|
|
53
58
|
describe('<book-navigator>', () => {
|
54
59
|
describe("How it loads", () => {
|
55
60
|
describe('Attaches BookReader listeners before `br.init` is called', () => {
|
56
|
-
|
61
|
+
test('binds global event listeners', async () => {
|
57
62
|
const el = fixtureSync(container());
|
58
63
|
const spy = sinon.spy(el, 'bindEventListeners');
|
59
64
|
await elementUpdated(el);
|
60
|
-
expect(spy.callCount).
|
65
|
+
expect(spy.callCount).toEqual(1);
|
61
66
|
});
|
62
|
-
|
67
|
+
test('Listens for Global Event @BookReader:PostInit', async () => {
|
63
68
|
const brStub = {
|
64
69
|
resize: sinon.fake(),
|
65
70
|
currentIndex: sinon.fake(),
|
66
71
|
jumpToIndex: sinon.fake(),
|
67
72
|
options: { enableMultipleBooks: false }, // for multipleBooks
|
68
|
-
el: '#BookReader'
|
73
|
+
el: '#BookReader',
|
74
|
+
refs: {}
|
69
75
|
};
|
70
76
|
|
71
77
|
const sharedObserver = new SharedResizeObserver();
|
@@ -77,25 +83,25 @@ describe('<book-navigator>', () => {
|
|
77
83
|
el.handleResize = sinon.fake();
|
78
84
|
await elementUpdated(el);
|
79
85
|
|
80
|
-
expect(brStub.resize.callCount).
|
86
|
+
expect(brStub.resize.callCount).toEqual(0);
|
81
87
|
|
82
88
|
window.dispatchEvent(new CustomEvent('BookReader:PostInit', {
|
83
89
|
detail: { props: brStub }
|
84
90
|
}));
|
85
91
|
await elementUpdated(el);
|
86
92
|
|
87
|
-
expect(el.emitLoadingStatusUpdate.callCount).
|
88
|
-
expect(el.bookreader).
|
89
|
-
expect(el.bookReaderLoaded).
|
90
|
-
expect(el.bookReaderCannotLoad).
|
91
|
-
expect(sharedObserver.addObserver.callCount).
|
93
|
+
expect(el.emitLoadingStatusUpdate.callCount).toEqual(1);
|
94
|
+
expect(el.bookreader).toEqual(brStub); // sets bookreader
|
95
|
+
expect(el.bookReaderLoaded).toBeTruthy(); // notes bookreader is loaded
|
96
|
+
expect(el.bookReaderCannotLoad).toBeFalsy();
|
97
|
+
expect(sharedObserver.addObserver.callCount).toEqual(1);
|
92
98
|
|
93
99
|
await promise0();
|
94
100
|
|
95
|
-
expect(brStub.resize.callCount > 0).
|
101
|
+
expect(brStub.resize.callCount > 0).toBeTruthy();
|
96
102
|
});
|
97
103
|
});
|
98
|
-
|
104
|
+
test('Emits a BrBookNav:PostInit event at completion', async () => {
|
99
105
|
let initEventFired = false;
|
100
106
|
window.addEventListener('BrBookNav:PostInit', (e) => {
|
101
107
|
initEventFired = true;
|
@@ -105,22 +111,22 @@ describe('<book-navigator>', () => {
|
|
105
111
|
|
106
112
|
await elementUpdated(el);
|
107
113
|
|
108
|
-
expect(initEventFired).
|
109
|
-
expect(spy.callCount).
|
114
|
+
expect(initEventFired).toBeTruthy();
|
115
|
+
expect(spy.callCount).toEqual(1);
|
110
116
|
});
|
111
117
|
|
112
|
-
|
118
|
+
test('creates an item image from metadata', async () => {
|
113
119
|
const el = fixtureSync(container());
|
114
120
|
const itemImage = fixtureSync(el.itemImage);
|
115
|
-
expect(itemImage).
|
116
|
-
expect(itemImage.getAttribute('class')).
|
117
|
-
expect(itemImage.getAttribute('src')).
|
121
|
+
expect(itemImage).toBeInstanceOf(HTMLImageElement);
|
122
|
+
expect(itemImage.getAttribute('class')).toEqual('cover-img');
|
123
|
+
expect(itemImage.getAttribute('src')).toEqual('https://https://foo.archive.org/services/img/foo');
|
118
124
|
});
|
119
125
|
});
|
120
126
|
describe('Menu/Layer Provider', () => {
|
121
127
|
describe('Connecting with a provider:', () => {
|
122
128
|
// loads Providers with base shared resources
|
123
|
-
|
129
|
+
test('We load 3 Sub Menus by default', async() => {
|
124
130
|
const el = fixtureSync(container());
|
125
131
|
const $brContainer = document.createElement('div');
|
126
132
|
const brStub = {
|
@@ -138,17 +144,17 @@ describe('<book-navigator>', () => {
|
|
138
144
|
el.initializeBookSubmenus();
|
139
145
|
await el.elementUpdated;
|
140
146
|
const defaultMenus = Object.keys(el.menuProviders);
|
141
|
-
expect(defaultMenus).
|
142
|
-
expect(el.menuProviders.downloads).
|
147
|
+
expect(defaultMenus).toContain('downloads');
|
148
|
+
expect(el.menuProviders.downloads).toBeInstanceOf(DownloadsProvider);
|
143
149
|
|
144
|
-
expect(defaultMenus).
|
145
|
-
expect(el.menuProviders.share).
|
150
|
+
expect(defaultMenus).toContain('share');
|
151
|
+
expect(el.menuProviders.share).toBeInstanceOf(SharingProvider);
|
146
152
|
|
147
|
-
expect(defaultMenus).
|
148
|
-
expect(el.menuProviders.visualAdjustments).
|
153
|
+
expect(defaultMenus).toContain('visualAdjustments');
|
154
|
+
expect(el.menuProviders.visualAdjustments).toBeInstanceOf(VisualAdjustmentsProvider);
|
149
155
|
});
|
150
|
-
describe('Loading Sub Menus By Plugin Flags',
|
151
|
-
|
156
|
+
describe('Loading Sub Menus By Plugin Flags', () => {
|
157
|
+
test('Search: uses `enableSearch` flag', async() => {
|
152
158
|
const el = fixtureSync(container());
|
153
159
|
const $brContainer = document.createElement('div');
|
154
160
|
const brStub = {
|
@@ -166,13 +172,13 @@ describe('<book-navigator>', () => {
|
|
166
172
|
el.initializeBookSubmenus();
|
167
173
|
await el.elementUpdated;
|
168
174
|
|
169
|
-
expect(el.menuProviders.search).
|
170
|
-
expect(el.menuProviders.search).
|
175
|
+
expect(el.menuProviders.search).toBeDefined();
|
176
|
+
expect(el.menuProviders.search).toBeInstanceOf(SearchProvider);
|
171
177
|
|
172
178
|
// also adds a menu shortcut
|
173
|
-
expect(el.menuShortcuts.find(m => m.id === 'search')).
|
179
|
+
expect(el.menuShortcuts.find(m => m.id === 'search')).toBeDefined();
|
174
180
|
});
|
175
|
-
|
181
|
+
test('Volumes/Multiple Books: uses `enableMultipleBooks` flag', async() => {
|
176
182
|
const el = fixtureSync(container());
|
177
183
|
const $brContainer = document.createElement('div');
|
178
184
|
const brStub = {
|
@@ -197,49 +203,50 @@ describe('<book-navigator>', () => {
|
|
197
203
|
el.initializeBookSubmenus();
|
198
204
|
await el.elementUpdated;
|
199
205
|
|
200
|
-
expect(el.menuProviders.volumes).
|
201
|
-
expect(el.menuProviders.volumes).
|
206
|
+
expect(el.menuProviders.volumes).toBeDefined();
|
207
|
+
expect(el.menuProviders.volumes).toBeInstanceOf(VolumesProvider);
|
202
208
|
|
203
209
|
// also adds a menu shortcut
|
204
|
-
expect(el.menuShortcuts.find(m => m.id === 'volumes')).
|
210
|
+
expect(el.menuShortcuts.find(m => m.id === 'volumes')).toBeDefined();
|
205
211
|
});
|
206
212
|
});
|
207
|
-
|
213
|
+
test('keeps track of base shared resources for providers in: `baseProviderConfig`', () => {
|
208
214
|
const el = fixtureSync(container());
|
209
215
|
const baseConfigKeys = Object.keys(el.baseProviderConfig);
|
210
|
-
expect(baseConfigKeys).
|
211
|
-
expect(baseConfigKeys).
|
212
|
-
expect(baseConfigKeys).
|
213
|
-
expect(baseConfigKeys).
|
214
|
-
expect(baseConfigKeys).
|
215
|
-
expect(baseConfigKeys).
|
216
|
-
expect(baseConfigKeys).
|
217
|
-
expect(baseConfigKeys).
|
216
|
+
expect(baseConfigKeys).toContain('baseHost');
|
217
|
+
expect(baseConfigKeys).toContain('modal');
|
218
|
+
expect(baseConfigKeys).toContain('sharedObserver');
|
219
|
+
expect(baseConfigKeys).toContain('bookreader');
|
220
|
+
expect(baseConfigKeys).toContain('item');
|
221
|
+
expect(baseConfigKeys).toContain('signedIn');
|
222
|
+
expect(baseConfigKeys).toContain('isAdmin');
|
223
|
+
expect(baseConfigKeys).toContain('onProviderChange');
|
218
224
|
});
|
219
225
|
});
|
220
226
|
|
221
227
|
describe('Controlling Menu Side Panel & Shortcuts', () => {
|
222
228
|
describe('Side Menu Panels', () => {
|
223
|
-
|
229
|
+
test('`isWideEnoughToOpenMenu` checks if menu should be open', async () => {
|
224
230
|
const el = fixtureSync(container());
|
225
231
|
el.brWidth = 300;
|
226
232
|
await el.elementUpdated;
|
227
233
|
|
228
|
-
expect(el.isWideEnoughToOpenMenu).
|
234
|
+
expect(el.isWideEnoughToOpenMenu).toEqual(false);
|
229
235
|
|
230
236
|
el.brWidth = 641;
|
231
237
|
await el.elementUpdated;
|
232
238
|
|
233
|
-
expect(el.isWideEnoughToOpenMenu).
|
239
|
+
expect(el.isWideEnoughToOpenMenu).toEqual(true);
|
234
240
|
});
|
235
241
|
describe('Control which side menu to toggle open by using: `this.updateSideMenu`', () => {
|
236
|
-
|
242
|
+
test('Emits `@updateSideMenu` to signal which menu gets the update', async () => {
|
237
243
|
const el = fixtureSync(container());
|
238
244
|
const brStub = {
|
239
245
|
resize: sinon.fake(),
|
240
246
|
currentIndex: sinon.fake(),
|
241
247
|
jumpToIndex: sinon.fake(),
|
242
|
-
options: { enableMultipleBooks: true }
|
248
|
+
options: { enableMultipleBooks: true },
|
249
|
+
refs: {},
|
243
250
|
};
|
244
251
|
el.bookreader = brStub;
|
245
252
|
await elementUpdated(el);
|
@@ -252,17 +259,18 @@ describe('<book-navigator>', () => {
|
|
252
259
|
});
|
253
260
|
|
254
261
|
el.updateSideMenu('foo', 'open');
|
255
|
-
expect(initEventFired).
|
256
|
-
expect(eventDetails.menuId).
|
257
|
-
expect(eventDetails.action).
|
262
|
+
expect(initEventFired).toEqual(true);
|
263
|
+
expect(eventDetails.menuId).toEqual('foo');
|
264
|
+
expect(eventDetails.action).toEqual('open');
|
258
265
|
});
|
259
|
-
|
266
|
+
test('Will Not Emit `@updateSideMenu` if menu ID is missing', async() => {
|
260
267
|
const el = fixtureSync(container());
|
261
268
|
const brStub = {
|
262
269
|
resize: sinon.fake(),
|
263
270
|
currentIndex: sinon.fake(),
|
264
271
|
jumpToIndex: sinon.fake(),
|
265
|
-
options: { enableMultipleBooks: true }
|
272
|
+
options: { enableMultipleBooks: true },
|
273
|
+
refs: {},
|
266
274
|
};
|
267
275
|
el.bookreader = brStub;
|
268
276
|
await elementUpdated(el);
|
@@ -273,30 +281,31 @@ describe('<book-navigator>', () => {
|
|
273
281
|
});
|
274
282
|
|
275
283
|
el.updateSideMenu('', 'open');
|
276
|
-
expect(initEventFired).
|
284
|
+
expect(initEventFired).toEqual(false);
|
277
285
|
});
|
278
286
|
});
|
279
287
|
});
|
280
288
|
|
281
289
|
describe('Shortcuts', () => {
|
282
|
-
|
290
|
+
test('has specific order of menu shortcuts to show', () => {
|
283
291
|
const el = fixtureSync(container());
|
284
|
-
expect(el.shortcutOrder[0]).
|
285
|
-
expect(el.shortcutOrder[1]).
|
286
|
-
expect(el.shortcutOrder[2]).
|
287
|
-
expect(el.shortcutOrder[3]).
|
292
|
+
expect(el.shortcutOrder[0]).toEqual('fullscreen');
|
293
|
+
expect(el.shortcutOrder[1]).toEqual('volumes');
|
294
|
+
expect(el.shortcutOrder[2]).toEqual('search');
|
295
|
+
expect(el.shortcutOrder[3]).toEqual('bookmarks');
|
288
296
|
});
|
289
297
|
});
|
290
298
|
|
291
299
|
describe('Behaviors for specific menus', () => {
|
292
300
|
describe('Search menu - ref: plugin.search.js', () => {
|
293
|
-
|
301
|
+
test('Event: listens for `BookReader:ToggleSearchMenu to open search side panel', async () => {
|
294
302
|
const el = fixtureSync(container());
|
295
303
|
const brStub = {
|
296
304
|
resize: sinon.fake(),
|
297
305
|
currentIndex: sinon.fake(),
|
298
306
|
jumpToIndex: sinon.fake(),
|
299
|
-
options: { enableMultipleBooks: true }
|
307
|
+
options: { enableMultipleBooks: true },
|
308
|
+
refs: {},
|
300
309
|
};
|
301
310
|
el.bookreader = brStub;
|
302
311
|
await elementUpdated(el);
|
@@ -310,8 +319,8 @@ describe('<book-navigator>', () => {
|
|
310
319
|
window.dispatchEvent(toggleSearchMenuEvent);
|
311
320
|
|
312
321
|
await elementUpdated(el);
|
313
|
-
expect(sidePanelConfig.menuId).
|
314
|
-
expect(sidePanelConfig.action).
|
322
|
+
expect(sidePanelConfig.menuId).toEqual('search');
|
323
|
+
expect(sidePanelConfig.action).toEqual('toggle');
|
315
324
|
});
|
316
325
|
});
|
317
326
|
});
|
@@ -319,7 +328,7 @@ describe('<book-navigator>', () => {
|
|
319
328
|
});
|
320
329
|
|
321
330
|
describe('Resizing',() => {
|
322
|
-
|
331
|
+
test('keeps track of `brWidth` and `brHeight`', async () => {
|
323
332
|
const el = fixtureSync(container());
|
324
333
|
const brStub = {
|
325
334
|
resize: sinon.fake(),
|
@@ -330,8 +339,8 @@ describe('<book-navigator>', () => {
|
|
330
339
|
};
|
331
340
|
el.bookreader = brStub;
|
332
341
|
await elementUpdated(el);
|
333
|
-
expect(el.brWidth).
|
334
|
-
expect(el.brHeight).
|
342
|
+
expect(el.brWidth).toEqual(0);
|
343
|
+
expect(el.brHeight).toEqual(0);
|
335
344
|
|
336
345
|
const mockResizeEvent = {
|
337
346
|
contentRect: {
|
@@ -345,10 +354,10 @@ describe('<book-navigator>', () => {
|
|
345
354
|
await elementUpdated(el);
|
346
355
|
await promise0();
|
347
356
|
|
348
|
-
expect(el.brHeight).
|
349
|
-
expect(el.brWidth).
|
357
|
+
expect(el.brHeight).toEqual(500);
|
358
|
+
expect(el.brWidth).toEqual(900);
|
350
359
|
});
|
351
|
-
|
360
|
+
test('resizes if height/width changes && is not animating', async () => {
|
352
361
|
const el = fixtureSync(container());
|
353
362
|
const brStub = {
|
354
363
|
animating: false,
|
@@ -361,8 +370,8 @@ describe('<book-navigator>', () => {
|
|
361
370
|
|
362
371
|
el.bookreader = brStub;
|
363
372
|
await elementUpdated(el);
|
364
|
-
expect(el.brWidth).
|
365
|
-
expect(el.brHeight).
|
373
|
+
expect(el.brWidth).toEqual(0);
|
374
|
+
expect(el.brHeight).toEqual(0);
|
366
375
|
|
367
376
|
const mockResizeEvent = {
|
368
377
|
contentRect: {
|
@@ -376,35 +385,37 @@ describe('<book-navigator>', () => {
|
|
376
385
|
await elementUpdated(el);
|
377
386
|
await promise0();
|
378
387
|
|
379
|
-
expect(brStub.resize.callCount).
|
388
|
+
expect(brStub.resize.callCount).toEqual(1);
|
380
389
|
});
|
381
|
-
|
390
|
+
test('does not resize bookreader if animating', async () => {
|
382
391
|
const el = fixtureSync(container());
|
383
392
|
const brStub = {
|
384
393
|
animating: true, // <-- testing for this
|
385
394
|
resize: sinon.fake(),
|
386
395
|
currentIndex: sinon.fake(),
|
387
396
|
jumpToIndex: sinon.fake(),
|
388
|
-
options: { enableMultipleBooks: true }
|
397
|
+
options: { enableMultipleBooks: true },
|
398
|
+
refs: {},
|
389
399
|
};
|
390
400
|
|
391
401
|
el.bookreader = brStub;
|
392
402
|
await elementUpdated(el);
|
393
403
|
|
394
|
-
expect(el.bookreader.resize.callCount).
|
395
|
-
expect(el.bookreader.currentIndex.callCount).
|
396
|
-
expect(el.bookreader.jumpToIndex.callCount).
|
404
|
+
expect(el.bookreader.resize.callCount).toEqual(0);
|
405
|
+
expect(el.bookreader.currentIndex.callCount).toEqual(0);
|
406
|
+
expect(el.bookreader.jumpToIndex.callCount).toEqual(0);
|
397
407
|
});
|
398
408
|
});
|
399
409
|
|
400
410
|
describe('Fullscreen Management', () => {
|
401
|
-
|
411
|
+
test('needs option: `enableFSLogoShortcut` to use FS logo', async () => {
|
402
412
|
const el = fixtureSync(container());
|
403
413
|
const brStub = {
|
404
414
|
isFullscreen: () => true,
|
405
415
|
options: {
|
406
416
|
enableFSLogoShortcut: false,
|
407
|
-
}
|
417
|
+
},
|
418
|
+
refs: {},
|
408
419
|
};
|
409
420
|
|
410
421
|
el.bookreader = brStub;
|
@@ -413,15 +424,16 @@ describe('<book-navigator>', () => {
|
|
413
424
|
|
414
425
|
el.manageFullScreenBehavior();
|
415
426
|
await elementUpdated(el);
|
416
|
-
expect(el.menuShortcuts.length).
|
427
|
+
expect(el.menuShortcuts.length).toEqual(0);
|
417
428
|
});
|
418
|
-
|
429
|
+
test('sets fullscreen shortcut when entering Fullscreen', async () => {
|
419
430
|
const el = fixtureSync(container());
|
420
431
|
const brStub = {
|
421
432
|
isFullscreen: () => true,
|
422
433
|
options: {
|
423
434
|
enableFSLogoShortcut: true,
|
424
|
-
}
|
435
|
+
},
|
436
|
+
refs: {},
|
425
437
|
};
|
426
438
|
|
427
439
|
el.bookreader = brStub;
|
@@ -430,18 +442,19 @@ describe('<book-navigator>', () => {
|
|
430
442
|
|
431
443
|
el.manageFullScreenBehavior();
|
432
444
|
await elementUpdated(el);
|
433
|
-
expect(el.menuShortcuts.length).
|
434
|
-
expect(el.menuShortcuts[0].id).
|
435
|
-
expect(el.menuShortcuts[0].icon).
|
436
|
-
expect(el.emitMenuShortcutsUpdated.callCount).
|
445
|
+
expect(el.menuShortcuts.length).toEqual(1);
|
446
|
+
expect(el.menuShortcuts[0].id).toEqual('fullscreen');
|
447
|
+
expect(el.menuShortcuts[0].icon).toBeDefined();
|
448
|
+
expect(el.emitMenuShortcutsUpdated.callCount).toEqual(1);
|
437
449
|
});
|
438
|
-
|
450
|
+
test('clicking Fullscreen shortcut closes fullscreen', async () => {
|
439
451
|
const el = fixtureSync(container());
|
440
452
|
const brStub = {
|
441
453
|
isFullscreen: () => true,
|
442
454
|
options: {
|
443
455
|
enableFSLogoShortcut: true,
|
444
|
-
}
|
456
|
+
},
|
457
|
+
refs: {},
|
445
458
|
};
|
446
459
|
|
447
460
|
el.bookreader = brStub;
|
@@ -455,15 +468,16 @@ describe('<book-navigator>', () => {
|
|
455
468
|
fixtureSync(el.menuShortcuts[0].icon).click();
|
456
469
|
await elementUpdated(el);
|
457
470
|
|
458
|
-
expect(el.closeFullscreen.callCount).
|
471
|
+
expect(el.closeFullscreen.callCount).toEqual(1);
|
459
472
|
});
|
460
|
-
|
473
|
+
test('removes Fullscreen shortcut when leaving fullscreen', async() => {
|
461
474
|
const el = fixtureSync(container());
|
462
475
|
const brStub = {
|
463
476
|
isFullscreen: () => false,
|
464
477
|
options: {
|
465
478
|
enableFSLogoShortcut: true,
|
466
|
-
}
|
479
|
+
},
|
480
|
+
refs: {},
|
467
481
|
};
|
468
482
|
|
469
483
|
el.bookreader = brStub;
|
@@ -472,10 +486,10 @@ describe('<book-navigator>', () => {
|
|
472
486
|
|
473
487
|
el.manageFullScreenBehavior();
|
474
488
|
await elementUpdated(el);
|
475
|
-
expect(el.menuShortcuts.length).
|
476
|
-
expect(el.emitMenuShortcutsUpdated.callCount).
|
489
|
+
expect(el.menuShortcuts.length).toEqual(0);
|
490
|
+
expect(el.emitMenuShortcutsUpdated.callCount).toEqual(1);
|
477
491
|
});
|
478
|
-
|
492
|
+
test('Event: Listens for `BookReader:FullscreenToggled', async() => {
|
479
493
|
const el = fixtureSync(container());
|
480
494
|
const brStub = {
|
481
495
|
isFullscreen: () => true,
|
@@ -484,7 +498,8 @@ describe('<book-navigator>', () => {
|
|
484
498
|
jumpToIndex: sinon.fake(),
|
485
499
|
options: {
|
486
500
|
enableFSLogoShortcut: true,
|
487
|
-
}
|
501
|
+
},
|
502
|
+
refs: {},
|
488
503
|
};
|
489
504
|
el.bookreader = brStub;
|
490
505
|
el.manageFullScreenBehavior = sinon.fake();
|
@@ -495,7 +510,7 @@ describe('<book-navigator>', () => {
|
|
495
510
|
}));
|
496
511
|
await elementUpdated(el);
|
497
512
|
|
498
|
-
expect(el.manageFullScreenBehavior.callCount).
|
513
|
+
expect(el.manageFullScreenBehavior.callCount).toEqual(1);
|
499
514
|
});
|
500
515
|
});
|
501
516
|
});
|
@@ -1,10 +1,9 @@
|
|
1
1
|
import {
|
2
2
|
html,
|
3
3
|
fixtureSync,
|
4
|
-
expect,
|
5
4
|
fixtureCleanup,
|
6
|
-
} from '@open-wc/testing';
|
7
|
-
import '
|
5
|
+
} from '@open-wc/testing-helpers';
|
6
|
+
import '@/src/BookNavigator/bookmarks/bookmark-button.js';
|
8
7
|
import sinon from 'sinon';
|
9
8
|
|
10
9
|
afterEach(() => {
|
@@ -13,13 +12,13 @@ afterEach(() => {
|
|
13
12
|
});
|
14
13
|
|
15
14
|
describe('<bookmark-button>', () => {
|
16
|
-
|
15
|
+
test('sets default properties', async () => {
|
17
16
|
const el = fixtureSync(html`<bookmark-button></bookmark-button>`);
|
18
17
|
|
19
|
-
expect(el.side).
|
20
|
-
expect(el.state).
|
18
|
+
expect(el.side).toBeUndefined();
|
19
|
+
expect(el.state).toEqual('hollow');
|
21
20
|
});
|
22
|
-
|
21
|
+
test('Event: fires `@bookmarkButtonClicked on click', async () => {
|
23
22
|
const el = fixtureSync(html`<bookmark-button></bookmark-button>`);
|
24
23
|
let buttonClicked = false;
|
25
24
|
el.addEventListener('bookmarkButtonClicked', () => { buttonClicked = true; });
|
@@ -27,18 +26,18 @@ describe('<bookmark-button>', () => {
|
|
27
26
|
el.handleClick(eventStub);
|
28
27
|
await el.updateComplete;
|
29
28
|
|
30
|
-
expect(buttonClicked).
|
31
|
-
expect(eventStub.preventDefault.callCount).
|
29
|
+
expect(buttonClicked).toBeTruthy();
|
30
|
+
expect(eventStub.preventDefault.callCount).toEqual(1);
|
32
31
|
});
|
33
|
-
|
32
|
+
test('Title: Toggles title between `Add/Remove bookmark`', async () => {
|
34
33
|
const el = fixtureSync(html`<bookmark-button></bookmark-button>`);
|
35
|
-
expect(el.title).
|
36
|
-
expect(el.state).
|
34
|
+
expect(el.title).toEqual('Add bookmark');
|
35
|
+
expect(el.state).toEqual('hollow');
|
37
36
|
|
38
37
|
el.state = 'filled';
|
39
38
|
await el.updateComplete;
|
40
39
|
|
41
|
-
expect(el.title).
|
42
|
-
expect(el.state).
|
40
|
+
expect(el.title).toEqual('Remove bookmark');
|
41
|
+
expect(el.state).not.toEqual('hollow');
|
43
42
|
});
|
44
43
|
});
|