@internetarchive/bookreader 5.0.0-22 → 5.0.0-24-sortingstate-1
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/.nvmrc +1 -0
- package/BookReader/BookReader.js +32148 -2
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/bookreader-component-bundle.js +10917 -941
- package/BookReader/bookreader-component-bundle.js.map +1 -1
- package/BookReader/icons/1up.svg +12 -1
- package/BookReader/icons/2up.svg +15 -1
- package/BookReader/icons/advance.svg +26 -3
- 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 +17 -1
- package/BookReader/icons/fullscreen_exit.svg +17 -1
- package/BookReader/icons/hamburger.svg +15 -1
- package/BookReader/icons/left-arrow.svg +12 -1
- package/BookReader/icons/magnify-minus.svg +16 -1
- package/BookReader/icons/magnify-plus.svg +17 -1
- package/BookReader/icons/magnify.svg +15 -1
- package/BookReader/icons/pause.svg +23 -1
- package/BookReader/icons/play.svg +22 -1
- package/BookReader/icons/playback-speed.svg +34 -1
- package/BookReader/icons/read-aloud.svg +22 -1
- package/BookReader/icons/review.svg +22 -3
- package/BookReader/icons/thumbnails.svg +17 -1
- package/BookReader/icons/voice.svg +1 -1
- package/BookReader/icons/volume-full.svg +22 -1
- package/BookReader/images/BRicons.svg +94 -5
- package/BookReader/images/books_graphic.svg +177 -1
- package/BookReader/images/icon_book.svg +12 -1
- package/BookReader/images/icon_bookmark.svg +12 -1
- package/BookReader/images/icon_gear.svg +14 -1
- package/BookReader/images/icon_hamburger.svg +20 -1
- package/BookReader/images/icon_home.svg +21 -1
- package/BookReader/images/icon_info.svg +11 -1
- package/BookReader/images/icon_one_page.svg +8 -1
- package/BookReader/images/icon_pause.svg +1 -1
- package/BookReader/images/icon_play.svg +1 -1
- package/BookReader/images/icon_playback-rate.svg +15 -1
- package/BookReader/images/icon_search_button.svg +8 -1
- package/BookReader/images/icon_share.svg +9 -1
- package/BookReader/images/icon_skip-ahead.svg +6 -1
- package/BookReader/images/icon_skip-back.svg +13 -2
- package/BookReader/images/icon_speaker.svg +18 -1
- package/BookReader/images/icon_speaker_open.svg +10 -1
- package/BookReader/images/icon_thumbnails.svg +12 -1
- package/BookReader/images/icon_toc.svg +5 -1
- package/BookReader/images/icon_two_pages.svg +9 -1
- package/BookReader/images/marker_chap-off.svg +11 -1
- package/BookReader/images/marker_chap-on.svg +11 -1
- package/BookReader/images/marker_srch-on.svg +11 -1
- package/BookReader/jquery-1.10.1.js +108 -2
- package/BookReader/plugins/plugin.archive_analytics.js +170 -1
- package/BookReader/plugins/plugin.archive_analytics.js.map +1 -1
- package/BookReader/plugins/plugin.autoplay.js +163 -1
- package/BookReader/plugins/plugin.autoplay.js.map +1 -1
- package/BookReader/plugins/plugin.chapters.js +333 -1
- package/BookReader/plugins/plugin.chapters.js.map +1 -1
- package/BookReader/plugins/plugin.iframe.js +72 -1
- package/BookReader/plugins/plugin.iframe.js.map +1 -1
- package/BookReader/plugins/plugin.mobile_nav.js +332 -1
- package/BookReader/plugins/plugin.mobile_nav.js.map +1 -1
- package/BookReader/plugins/plugin.resume.js +241 -1
- package/BookReader/plugins/plugin.resume.js.map +1 -1
- package/BookReader/plugins/plugin.search.js +1263 -1
- package/BookReader/plugins/plugin.search.js.map +1 -1
- package/BookReader/plugins/plugin.text_selection.js +839 -1
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.tts.js +9114 -2
- package/BookReader/plugins/plugin.tts.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +750 -1
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js +326 -1
- package/BookReader/plugins/plugin.vendor-fullscreen.js.map +1 -1
- package/BookReader/webcomponents-bundle.js +411 -2
- package/BookReader/webcomponents-bundle.js.map +1 -1
- package/CHANGELOG.md +9 -0
- package/package.json +2 -6
- package/src/BookNavigator/bookmarks/bookmarks-provider.js +1 -0
- package/src/BookNavigator/bookmarks/ia-bookmarks.js +3 -0
- package/src/BookNavigator/visual-adjustments/visual-adjustments-provider.js +1 -1
- package/src/BookNavigator/volumes/volumes-provider.js +40 -9
- package/src/BookReader/Mode1Up.js +10 -2
- package/src/BookReader/ModeThumb.js +13 -6
- package/src/BookReader/options.js +4 -0
- package/src/BookReader.js +8 -22
- package/src/ItemNavigator/ItemNavigator.js +1 -0
- package/src/plugins/plugin.url.js +209 -2
- package/tests/{BookReader → jest/BookReader}/BookModel.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/BookReaderPublicFunctions.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/DebugConsole.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/ImageCache.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/Mode1UpLit.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/Mode2Up.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/ModeSmoothZoom.test.js +0 -0
- package/tests/jest/BookReader/ModeThumb.test.js +71 -0
- package/tests/{BookReader → jest/BookReader}/Navbar/Navbar.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/PageContainer.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/ReduceSet.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/Toolbar/Toolbar.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/utils/HTMLDimensionsCacher.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/utils/classes.test.js +0 -0
- package/tests/{BookReader → jest/BookReader}/utils.test.js +0 -0
- package/tests/{BookReader.options.test.js → jest/BookReader.options.test.js} +0 -0
- package/tests/{BookReader.test.js → jest/BookReader.test.js} +0 -0
- package/tests/{plugins → jest/plugins}/plugin.archive_analytics.test.js +0 -0
- package/tests/{plugins → jest/plugins}/plugin.autoplay.test.js +0 -0
- package/tests/{plugins → jest/plugins}/plugin.chapters.test.js +0 -0
- package/tests/{plugins → jest/plugins}/plugin.iframe.test.js +0 -0
- package/tests/{plugins → jest/plugins}/plugin.mobile_nav.test.js +0 -0
- package/tests/{plugins → jest/plugins}/plugin.resume.test.js +0 -0
- package/tests/{plugins → jest/plugins}/plugin.text_selection.test.js +0 -0
- package/tests/jest/plugins/plugin.url.test.js +306 -0
- package/tests/{plugins → jest/plugins}/plugin.vendor-fullscreen.test.js +0 -0
- package/tests/{plugins → jest/plugins}/search/plugin.search.test.js +0 -0
- package/tests/{plugins → jest/plugins}/search/plugin.search.view.test.js +0 -0
- package/tests/{plugins → jest/plugins}/tts/AbstractTTSEngine.test.js +0 -0
- package/tests/{plugins → jest/plugins}/tts/FestivalTTSEngine.test.js +0 -0
- package/tests/{plugins → jest/plugins}/tts/PageChunk.test.js +0 -0
- package/tests/{plugins → jest/plugins}/tts/PageChunkIterator.test.js +0 -0
- package/tests/{plugins → jest/plugins}/tts/WebTTSEngine.test.js +0 -0
- package/tests/{plugins → jest/plugins}/tts/utils.test.js +0 -0
- package/tests/{util → jest/util}/browserSniffing.test.js +0 -0
- package/tests/{util → jest/util}/docCookies.test.js +0 -0
- package/tests/{util → jest/util}/strings.test.js +0 -0
- package/tests/{utils.js → jest/utils.js} +0 -0
- package/tests/karma/BookNavigator/volumes/volumes-provider.test.js +6 -6
- package/tests/plugins/plugin.url.test.js +0 -147
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import BookReader from '@/src/BookReader.js';
|
|
2
|
+
import '@/src/plugins/plugin.url.js';
|
|
3
|
+
import { UrlPlugin } from '@/src/plugins/plugin.url.js';
|
|
4
|
+
import sinon from 'sinon';
|
|
5
|
+
|
|
6
|
+
let br;
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
document.body.innerHTML = '<div id="BookReader">';
|
|
9
|
+
br = new BookReader();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
jest.clearAllMocks();
|
|
14
|
+
sinon.restore();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
describe.only('UrlPlugin tests', () => {
|
|
19
|
+
const urlPlugin = new UrlPlugin();
|
|
20
|
+
const urlSchema = [
|
|
21
|
+
{ name: 'page', position: 'path', default: 'n0' },
|
|
22
|
+
{ name: 'mode', position: 'path', default: '2up' },
|
|
23
|
+
{ name: 'search', position: 'path', deprecated_for: 'q' },
|
|
24
|
+
{ name: 'q', position: 'query_param' },
|
|
25
|
+
{ name: 'sort', position: 'query_param' },
|
|
26
|
+
{ name: 'view', position: 'query_param' },
|
|
27
|
+
{ name: 'admin', position: 'query_param' },
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
describe('urlStateToUrlString tests', () => {
|
|
31
|
+
test('urlStateToUrlString with known states in schema', () => {
|
|
32
|
+
const urlState = { page: 'n7', mode: '1up', search: 'foo' };
|
|
33
|
+
const urlStateWithQueries = { page: 'n7', mode: '1up', q: 'hello', view: 'theater', sort: 'title_asc' };
|
|
34
|
+
|
|
35
|
+
const expectedUrlFromState = '/page/n7/mode/1up?q=foo';
|
|
36
|
+
const expectedUrlFromStateWithQueries = '/page/n7/mode/1up?q=hello&view=theater&sort=title_asc';
|
|
37
|
+
|
|
38
|
+
expect(urlPlugin.urlStateToUrlString(urlSchema, urlState)).toBe(expectedUrlFromState);
|
|
39
|
+
expect(urlPlugin.urlStateToUrlString(urlSchema, urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('urlStateToUrlString with unknown states in schema', () => {
|
|
43
|
+
const urlState = { page: 'n7', mode: '1up' };
|
|
44
|
+
const urlStateWithQueries = { page: 'n7', mode: '1up', q: 'hello', viewer: 'theater', sortBy: 'title_asc' };
|
|
45
|
+
|
|
46
|
+
const expectedUrlFromState = '/page/n7/mode/1up';
|
|
47
|
+
const expectedUrlFromStateWithQueries = '/page/n7/mode/1up?q=hello&viewer=theater&sortBy=title_asc';
|
|
48
|
+
|
|
49
|
+
expect(urlPlugin.urlStateToUrlString(urlSchema, urlState)).toBe(expectedUrlFromState);
|
|
50
|
+
expect(urlPlugin.urlStateToUrlString(urlSchema, urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('urlStateToUrlString with boolean value', () => {
|
|
54
|
+
const urlState = { page: 'n7', mode: '1up', search: 'foo', view: 'theater', wrapper: false };
|
|
55
|
+
const expectedUrlFromState = '/page/n7/mode/1up?q=foo&view=theater&wrapper=false';
|
|
56
|
+
|
|
57
|
+
expect(urlPlugin.urlStateToUrlString(urlSchema, urlState)).toBe(expectedUrlFromState);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('urlStringToUrlState tests', () => {
|
|
62
|
+
test('urlStringToUrlState without query string', () => {
|
|
63
|
+
const url = '/page/n7/mode/2up';
|
|
64
|
+
const url1 = '/page/n7/mode/1up';
|
|
65
|
+
|
|
66
|
+
expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual({page: 'n7', mode: '2up'});
|
|
67
|
+
expect(urlPlugin.urlStringToUrlState(urlSchema, url1)).toEqual({page: 'n7', mode: '1up'});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('urlStringToUrlState with deprecated_for', () => {
|
|
71
|
+
const url = '/page/n7/mode/2up/search/hello';
|
|
72
|
+
|
|
73
|
+
expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('urlStringToUrlState with query string', () => {
|
|
77
|
+
const url = '/page/n7/mode/2up/search/hello?view=theather&foo=bar&sort=title_asc';
|
|
78
|
+
const url1 = '/mode/2up?ref=ol&ui=embed&wrapper=false&view=theater';
|
|
79
|
+
|
|
80
|
+
expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual(
|
|
81
|
+
{page: 'n7', mode: '2up', q: 'hello', view: 'theather', foo: 'bar', sort: 'title_asc'}
|
|
82
|
+
);
|
|
83
|
+
expect(urlPlugin.urlStringToUrlState(urlSchema, url1)).toEqual(
|
|
84
|
+
{page: 'n0', mode: '2up', ref: 'ol', ui: 'embed', wrapper: false, view: 'theater'}
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('urlStringToUrlState compare search and ?q', () => {
|
|
89
|
+
const url = '/page/n7/mode/2up/search/hello';
|
|
90
|
+
urlPlugin.urlState = { q: 'hello' };
|
|
91
|
+
|
|
92
|
+
expect(urlPlugin.urlStringToUrlState(urlSchema, url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('url plugin helper functions', () => {
|
|
97
|
+
test('setUrlParam', () => {
|
|
98
|
+
urlPlugin.urlState = {};
|
|
99
|
+
urlPlugin.setUrlParam('page', '20');
|
|
100
|
+
urlPlugin.setUrlParam('mode', '2up');
|
|
101
|
+
|
|
102
|
+
expect(urlPlugin.urlState).toEqual({page: '20', mode: '2up'});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('removeUrlParam', () => {
|
|
106
|
+
urlPlugin.setUrlParam('page', '20');
|
|
107
|
+
urlPlugin.setUrlParam('mode', '2up');
|
|
108
|
+
urlPlugin.removeUrlParam('mode');
|
|
109
|
+
|
|
110
|
+
expect(urlPlugin.urlState).toEqual({page: '20'});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('getUrlParam', () => {
|
|
114
|
+
urlPlugin.setUrlParam('page', '20');
|
|
115
|
+
urlPlugin.setUrlParam('mode', '2up');
|
|
116
|
+
expect(urlPlugin.getUrlParam('page')).toEqual('20');
|
|
117
|
+
expect(urlPlugin.getUrlParam('mode')).toEqual('2up');
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('pullFromAddressBar and pushToAddressBar - hash mode', () => {
|
|
122
|
+
test('url without mode state value - use default', () => {
|
|
123
|
+
urlPlugin.urlState = {};
|
|
124
|
+
urlPlugin.urlMode = 'hash';
|
|
125
|
+
|
|
126
|
+
urlPlugin.pullFromAddressBar('/page/12');
|
|
127
|
+
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up'});
|
|
128
|
+
|
|
129
|
+
urlPlugin.pushToAddressBar();
|
|
130
|
+
expect(window.location.hash).toEqual('#/page/12/mode/2up');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('url with query param', () => {
|
|
134
|
+
urlPlugin.urlState = {};
|
|
135
|
+
urlPlugin.urlMode = 'hash';
|
|
136
|
+
|
|
137
|
+
urlPlugin.pullFromAddressBar('/page/12/search/hello?view=theater');
|
|
138
|
+
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up', q: 'hello', view: 'theater'});
|
|
139
|
+
|
|
140
|
+
urlPlugin.pushToAddressBar();
|
|
141
|
+
expect(window.location.hash).toEqual('#/page/12/mode/2up?q=hello&view=theater');
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('pullFromAddressBar and pushToAddressBar - history mode', () => {
|
|
146
|
+
test('url without mode state value - use default', () => {
|
|
147
|
+
urlPlugin.urlState = {};
|
|
148
|
+
urlPlugin.urlHistoryBasePath = '/details/foo';
|
|
149
|
+
urlPlugin.urlMode = 'history';
|
|
150
|
+
|
|
151
|
+
urlPlugin.pullFromAddressBar('/details/foo/page/12');
|
|
152
|
+
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up'});
|
|
153
|
+
|
|
154
|
+
urlPlugin.pushToAddressBar();
|
|
155
|
+
expect(window.location.pathname).toEqual('/details/foo/page/12/mode/2up');
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('url with query param', () => {
|
|
159
|
+
urlPlugin.urlState = {};
|
|
160
|
+
urlPlugin.urlHistoryBasePath = '/details/foo';
|
|
161
|
+
urlPlugin.urlMode = 'history';
|
|
162
|
+
|
|
163
|
+
urlPlugin.pullFromAddressBar('/details/foo/page/12/search/hello?view=theater');
|
|
164
|
+
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up', q: 'hello', view: 'theater'});
|
|
165
|
+
|
|
166
|
+
urlPlugin.pushToAddressBar();
|
|
167
|
+
const locationUrl = `${window.location.pathname}${window.location.search}`;
|
|
168
|
+
expect(locationUrl).toEqual('/details/foo/page/12/mode/2up?q=hello&view=theater');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('Plugin: URL controller', () => {
|
|
175
|
+
test('has default option flag', () => {
|
|
176
|
+
expect(BookReader.defaultOptions.enableUrlPlugin).toEqual(true);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('adds url specific fields to BR', () => {
|
|
180
|
+
const { defaultOptions } = BookReader;
|
|
181
|
+
expect(defaultOptions).toHaveProperty('urlTrackIndex0');
|
|
182
|
+
expect(defaultOptions).toHaveProperty('urlTrackedParams');
|
|
183
|
+
expect(defaultOptions).toHaveProperty('urlHistoryBasePath');
|
|
184
|
+
expect(defaultOptions).toHaveProperty('urlMode');
|
|
185
|
+
expect(defaultOptions).toHaveProperty('updateWindowTitle');
|
|
186
|
+
expect(defaultOptions).toHaveProperty('defaults');
|
|
187
|
+
expect(defaultOptions).toHaveProperty('bookId');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('has a whitelist of params that it tracks', () => {
|
|
191
|
+
['page', 'search', 'mode', 'region', 'highlight'];
|
|
192
|
+
const { defaultOptions: { urlTrackedParams } } = BookReader;
|
|
193
|
+
expect(Array.isArray(urlTrackedParams)).toEqual(true);
|
|
194
|
+
expect(urlTrackedParams.find(param => param === 'page')).toBeTruthy();
|
|
195
|
+
expect(urlTrackedParams.find(param => param === 'search')).toBeTruthy();
|
|
196
|
+
expect(urlTrackedParams.find(param => param === 'mode')).toBeTruthy();
|
|
197
|
+
expect(urlTrackedParams.find(param => param === 'region')).toBeTruthy();
|
|
198
|
+
expect(urlTrackedParams.find(param => param === 'highlight')).toBeTruthy();
|
|
199
|
+
expect(urlTrackedParams.find(param => param === 'view')).toBeTruthy();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('initializes polling for url changes if using hash', () => {
|
|
203
|
+
BookReader.prototype.urlStartLocationPolling = jest.fn();
|
|
204
|
+
br.init();
|
|
205
|
+
|
|
206
|
+
expect(br.urlStartLocationPolling).toHaveBeenCalled();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('updates URL when index changes', () => {
|
|
210
|
+
window.history.replaceState = jest.fn();
|
|
211
|
+
BookReader.prototype.currentIndex = jest.fn(() => 1);
|
|
212
|
+
BookReader.prototype.urlReadFragment = jest.fn(() => '/page/2/mode/1up');
|
|
213
|
+
BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
|
|
214
|
+
index: 88,
|
|
215
|
+
mode: 1,
|
|
216
|
+
search: ''
|
|
217
|
+
}));
|
|
218
|
+
br.options.urlMode = 'history';
|
|
219
|
+
br.init();
|
|
220
|
+
br.urlUpdateFragment();
|
|
221
|
+
|
|
222
|
+
expect(window.history.replaceState).toHaveBeenCalled();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('updates URL when mode changes', () => {
|
|
226
|
+
window.history.replaceState = jest.fn();
|
|
227
|
+
BookReader.prototype.currentIndex = jest.fn(() => 1);
|
|
228
|
+
BookReader.prototype.urlReadFragment = jest.fn(() => '/page/2/mode/1up');
|
|
229
|
+
BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
|
|
230
|
+
index: 2,
|
|
231
|
+
mode: 2,
|
|
232
|
+
search: ''
|
|
233
|
+
}));
|
|
234
|
+
br.options.urlMode = 'history';
|
|
235
|
+
br.init();
|
|
236
|
+
br.urlUpdateFragment();
|
|
237
|
+
|
|
238
|
+
expect(window.history.replaceState).toHaveBeenCalled();
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test('updates URL when search changes', () => {
|
|
242
|
+
window.history.replaceState = jest.fn();
|
|
243
|
+
BookReader.prototype.currentIndex = jest.fn(() => 1);
|
|
244
|
+
BookReader.prototype.urlReadFragment = jest.fn(() => '');
|
|
245
|
+
BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
|
|
246
|
+
index: 1,
|
|
247
|
+
mode: 2,
|
|
248
|
+
search: 'foo'
|
|
249
|
+
}));
|
|
250
|
+
BookReader.prototype.search = jest.fn();
|
|
251
|
+
br.options.urlMode = 'history';
|
|
252
|
+
br.init();
|
|
253
|
+
br.urlUpdateFragment();
|
|
254
|
+
|
|
255
|
+
expect(window.history.replaceState).toHaveBeenCalled();
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('updates URL when view changes', () => {
|
|
259
|
+
window.history.replaceState = jest.fn();
|
|
260
|
+
BookReader.prototype.currentIndex = jest.fn(() => 1);
|
|
261
|
+
BookReader.prototype.urlReadFragment = jest.fn(() => '');
|
|
262
|
+
BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
|
|
263
|
+
index: 1,
|
|
264
|
+
mode: 2,
|
|
265
|
+
view: 'theater'
|
|
266
|
+
}));
|
|
267
|
+
BookReader.prototype.search = jest.fn();
|
|
268
|
+
br.options.urlMode = 'history';
|
|
269
|
+
br.init();
|
|
270
|
+
br.urlUpdateFragment();
|
|
271
|
+
|
|
272
|
+
expect(window.history.replaceState).toHaveBeenCalled();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test('does not update URL when search in query string', () => {
|
|
276
|
+
window.history.replaceState = jest.fn();
|
|
277
|
+
BookReader.prototype.currentIndex = jest.fn(() => 1);
|
|
278
|
+
BookReader.prototype.urlReadFragment = jest.fn(() => 'mode/2up');
|
|
279
|
+
BookReader.prototype.getLocationSearch = jest.fn(() => '?q=foo');
|
|
280
|
+
BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
|
|
281
|
+
index: 1,
|
|
282
|
+
mode: 2,
|
|
283
|
+
search: 'foo'
|
|
284
|
+
}));
|
|
285
|
+
BookReader.prototype.search = jest.fn();
|
|
286
|
+
br.options.initialSearchTerm = 'foo';
|
|
287
|
+
br.options.urlMode = 'history';
|
|
288
|
+
br.init();
|
|
289
|
+
br.urlUpdateFragment();
|
|
290
|
+
|
|
291
|
+
expect(window.history.replaceState).toHaveBeenCalledTimes(0);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test('only q= param is selected from url query params', () => {
|
|
295
|
+
const INTIAL_URL = "http://127.0.0.1:8080/BookReaderDemo/demo-internetarchive.html?ocaid=adventuresofoli00dick&q=foo";
|
|
296
|
+
const result = br.urlParamsFiltersOnlySearch(INTIAL_URL);
|
|
297
|
+
expect(result).toBe("?q=foo");
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test('only q= param is selected from url query params with special character', () => {
|
|
301
|
+
const INTIAL_URL = "http://127.0.0.1:8080/BookReaderDemo/demo-internetarchive.html?ocaid=adventuresofoli00dick&q=foo%24%24";
|
|
302
|
+
const result = br.urlParamsFiltersOnlySearch(INTIAL_URL);
|
|
303
|
+
expect(result).toBe("?q=foo%24%24");
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -64,7 +64,7 @@ describe('Volumes Provider', () => {
|
|
|
64
64
|
const baseHost = "https://archive.org";
|
|
65
65
|
const provider = new volumesProvider(baseHost, brOptions, onSortClick);
|
|
66
66
|
|
|
67
|
-
expect(provider.sortOrderBy).to.equal("
|
|
67
|
+
expect(provider.sortOrderBy).to.equal("default");
|
|
68
68
|
|
|
69
69
|
provider.sortVolumes("title_asc");
|
|
70
70
|
expect(provider.sortOrderBy).to.equal("title_asc");
|
|
@@ -74,8 +74,8 @@ describe('Volumes Provider', () => {
|
|
|
74
74
|
expect(provider.sortOrderBy).to.equal("title_desc");
|
|
75
75
|
expect(provider.sortButton.getHTML()).includes("sort-by desc-icon");
|
|
76
76
|
|
|
77
|
-
provider.sortVolumes("
|
|
78
|
-
expect(provider.sortOrderBy).to.equal("
|
|
77
|
+
provider.sortVolumes("default");
|
|
78
|
+
expect(provider.sortOrderBy).to.equal("default");
|
|
79
79
|
expect(provider.sortButton.getHTML()).includes("sort-by neutral-icon");
|
|
80
80
|
});
|
|
81
81
|
|
|
@@ -88,9 +88,9 @@ describe('Volumes Provider', () => {
|
|
|
88
88
|
const files = Object.keys(parsedFiles).map(item => parsedFiles[item]).sort((a, b) => a.orig_sort - b.orig_sort);
|
|
89
89
|
const origSortTitles = files.map(item => item.title);
|
|
90
90
|
|
|
91
|
-
provider.sortVolumes("
|
|
91
|
+
provider.sortVolumes("default");
|
|
92
92
|
|
|
93
|
-
expect(provider.sortOrderBy).to.equal("
|
|
93
|
+
expect(provider.sortOrderBy).to.equal("default");
|
|
94
94
|
expect(provider.actionButton).to.exist;
|
|
95
95
|
|
|
96
96
|
const providerFileTitles = provider.viewableFiles.map(item => item.title);
|
|
@@ -144,7 +144,7 @@ describe('Volumes Provider', () => {
|
|
|
144
144
|
const baseHost = "https://archive.org";
|
|
145
145
|
const provider = new volumesProvider(baseHost, brOptions, onSortClick);
|
|
146
146
|
|
|
147
|
-
provider.sortOrderBy = '
|
|
147
|
+
provider.sortOrderBy = 'default';
|
|
148
148
|
const origSortButton = await fixture(provider.sortButton);
|
|
149
149
|
expect(origSortButton.classList.contains('neutral-icon')).to.be.true;
|
|
150
150
|
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import BookReader from '@/src/BookReader.js';
|
|
3
|
-
import '@/src/plugins/plugin.url.js';
|
|
4
|
-
|
|
5
|
-
let br;
|
|
6
|
-
beforeAll(() => {
|
|
7
|
-
document.body.innerHTML = '<div id="BookReader">';
|
|
8
|
-
br = new BookReader();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
jest.clearAllMocks();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe('Plugin: URL controller', () => {
|
|
16
|
-
test('has default option flag', () => {
|
|
17
|
-
expect(BookReader.defaultOptions.enableUrlPlugin).toEqual(true);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('adds url specific fields to BR', () => {
|
|
21
|
-
const { defaultOptions } = BookReader;
|
|
22
|
-
expect(defaultOptions).toHaveProperty('urlTrackIndex0');
|
|
23
|
-
expect(defaultOptions).toHaveProperty('urlTrackedParams');
|
|
24
|
-
expect(defaultOptions).toHaveProperty('urlHistoryBasePath');
|
|
25
|
-
expect(defaultOptions).toHaveProperty('urlMode');
|
|
26
|
-
expect(defaultOptions).toHaveProperty('updateWindowTitle');
|
|
27
|
-
expect(defaultOptions).toHaveProperty('defaults');
|
|
28
|
-
expect(defaultOptions).toHaveProperty('bookId');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('has a whitelist of params that it tracks', () => {
|
|
32
|
-
['page', 'search', 'mode', 'region', 'highlight'];
|
|
33
|
-
const { defaultOptions: { urlTrackedParams } } = BookReader;
|
|
34
|
-
expect(Array.isArray(urlTrackedParams)).toEqual(true);
|
|
35
|
-
expect(urlTrackedParams.find(param => param === 'page')).toBeTruthy();
|
|
36
|
-
expect(urlTrackedParams.find(param => param === 'search')).toBeTruthy();
|
|
37
|
-
expect(urlTrackedParams.find(param => param === 'mode')).toBeTruthy();
|
|
38
|
-
expect(urlTrackedParams.find(param => param === 'region')).toBeTruthy();
|
|
39
|
-
expect(urlTrackedParams.find(param => param === 'highlight')).toBeTruthy();
|
|
40
|
-
expect(urlTrackedParams.find(param => param === 'view')).toBeTruthy();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('initializes polling for url changes if using hash', () => {
|
|
44
|
-
BookReader.prototype.urlStartLocationPolling = jest.fn();
|
|
45
|
-
br.init();
|
|
46
|
-
|
|
47
|
-
expect(br.urlStartLocationPolling).toHaveBeenCalled();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('updates URL when index changes', () => {
|
|
51
|
-
window.history.replaceState = jest.fn();
|
|
52
|
-
BookReader.prototype.currentIndex = jest.fn(() => 1);
|
|
53
|
-
BookReader.prototype.urlReadFragment = jest.fn(() => '/page/2/mode/1up');
|
|
54
|
-
BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
|
|
55
|
-
index: 88,
|
|
56
|
-
mode: 1,
|
|
57
|
-
search: ''
|
|
58
|
-
}));
|
|
59
|
-
br.options.urlMode = 'history';
|
|
60
|
-
br.init();
|
|
61
|
-
br.urlUpdateFragment();
|
|
62
|
-
|
|
63
|
-
expect(window.history.replaceState).toHaveBeenCalled();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('updates URL when mode changes', () => {
|
|
67
|
-
window.history.replaceState = jest.fn();
|
|
68
|
-
BookReader.prototype.currentIndex = jest.fn(() => 1);
|
|
69
|
-
BookReader.prototype.urlReadFragment = jest.fn(() => '/page/2/mode/1up');
|
|
70
|
-
BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
|
|
71
|
-
index: 2,
|
|
72
|
-
mode: 2,
|
|
73
|
-
search: ''
|
|
74
|
-
}));
|
|
75
|
-
br.options.urlMode = 'history';
|
|
76
|
-
br.init();
|
|
77
|
-
br.urlUpdateFragment();
|
|
78
|
-
|
|
79
|
-
expect(window.history.replaceState).toHaveBeenCalled();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('updates URL when search changes', () => {
|
|
83
|
-
window.history.replaceState = jest.fn();
|
|
84
|
-
BookReader.prototype.currentIndex = jest.fn(() => 1);
|
|
85
|
-
BookReader.prototype.urlReadFragment = jest.fn(() => '');
|
|
86
|
-
BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
|
|
87
|
-
index: 1,
|
|
88
|
-
mode: 2,
|
|
89
|
-
search: 'foo'
|
|
90
|
-
}));
|
|
91
|
-
BookReader.prototype.search = jest.fn();
|
|
92
|
-
br.options.urlMode = 'history';
|
|
93
|
-
br.init();
|
|
94
|
-
br.urlUpdateFragment();
|
|
95
|
-
|
|
96
|
-
expect(window.history.replaceState).toHaveBeenCalled();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('updates URL when view changes', () => {
|
|
100
|
-
window.history.replaceState = jest.fn();
|
|
101
|
-
BookReader.prototype.currentIndex = jest.fn(() => 1);
|
|
102
|
-
BookReader.prototype.urlReadFragment = jest.fn(() => '');
|
|
103
|
-
BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
|
|
104
|
-
index: 1,
|
|
105
|
-
mode: 2,
|
|
106
|
-
view: 'theater'
|
|
107
|
-
}));
|
|
108
|
-
BookReader.prototype.search = jest.fn();
|
|
109
|
-
br.options.urlMode = 'history';
|
|
110
|
-
br.init();
|
|
111
|
-
br.urlUpdateFragment();
|
|
112
|
-
|
|
113
|
-
expect(window.history.replaceState).toHaveBeenCalled();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('does not update URL when search in query string', () => {
|
|
117
|
-
window.history.replaceState = jest.fn();
|
|
118
|
-
BookReader.prototype.currentIndex = jest.fn(() => 1);
|
|
119
|
-
BookReader.prototype.urlReadFragment = jest.fn(() => 'mode/2up');
|
|
120
|
-
BookReader.prototype.getLocationSearch = jest.fn(() => '?q=foo');
|
|
121
|
-
BookReader.prototype.paramsFromCurrent = jest.fn(() => ({
|
|
122
|
-
index: 1,
|
|
123
|
-
mode: 2,
|
|
124
|
-
search: 'foo'
|
|
125
|
-
}));
|
|
126
|
-
BookReader.prototype.search = jest.fn();
|
|
127
|
-
br.options.initialSearchTerm = 'foo';
|
|
128
|
-
br.options.urlMode = 'history';
|
|
129
|
-
br.init();
|
|
130
|
-
br.urlUpdateFragment();
|
|
131
|
-
|
|
132
|
-
expect(window.history.replaceState).toHaveBeenCalledTimes(0);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('only q= param is selected from url query params', () => {
|
|
136
|
-
const INTIAL_URL = "http://127.0.0.1:8080/BookReaderDemo/demo-internetarchive.html?ocaid=adventuresofoli00dick&q=foo";
|
|
137
|
-
const result = br.urlParamsFiltersOnlySearch(INTIAL_URL);
|
|
138
|
-
expect(result).toBe("?q=foo");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test('only q= param is selected from url query params with special character', () => {
|
|
142
|
-
const INTIAL_URL = "http://127.0.0.1:8080/BookReaderDemo/demo-internetarchive.html?ocaid=adventuresofoli00dick&q=foo%24%24";
|
|
143
|
-
const result = br.urlParamsFiltersOnlySearch(INTIAL_URL);
|
|
144
|
-
expect(result).toBe("?q=foo%24%24");
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|