@internetarchive/bookreader 5.0.0-23 → 5.0.0-24-sortingstate-2
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 +32145 -2
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/bookreader-component-bundle.js +10911 -941
- package/BookReader/bookreader-component-bundle.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +763 -1
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- 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 +4 -22
- package/src/plugins/plugin.url.js +215 -2
- package/tests/jest/BookReader/ModeThumb.test.js +71 -0
- package/tests/jest/plugins/plugin.url.test.js +160 -1
@@ -1,6 +1,7 @@
|
|
1
|
-
|
2
1
|
import BookReader from '@/src/BookReader.js';
|
3
2
|
import '@/src/plugins/plugin.url.js';
|
3
|
+
import { UrlPlugin } from '@/src/plugins/plugin.url.js';
|
4
|
+
import sinon from 'sinon';
|
4
5
|
|
5
6
|
let br;
|
6
7
|
beforeAll(() => {
|
@@ -10,6 +11,164 @@ beforeAll(() => {
|
|
10
11
|
|
11
12
|
afterEach(() => {
|
12
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({ pathname: '/page/12', search: '', hash: '' });
|
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({ pathname: '/page/12', search: '?q=hello&view=theater', hash: '' });
|
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({ pathname: '/details/foo/page/12', search: '', hash: '' });
|
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({ pathname: '/details/foo/page/12', search: '?q=hello&view=theater', hash: '' });
|
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
|
+
|
13
172
|
});
|
14
173
|
|
15
174
|
describe('Plugin: URL controller', () => {
|