@internetarchive/bookreader 5.0.0-27 → 5.0.0-28
Sign up to get free protection for your applications and to get access to all the features.
- package/.nvmrc +1 -0
- package/BookReader/BookReader.js +1 -1
- package/BookReader/bookreader-component-bundle.js +1 -1
- package/BookReader/bookreader-component-bundle.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +1 -1
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/CHANGELOG.md +3 -0
- package/package.json +1 -1
- package/src/BookNavigator/volumes/volumes-provider.js +41 -9
- package/src/BookNavigator/volumes/volumes.js +14 -3
- package/src/plugins/url/UrlPlugin.js +185 -0
- package/src/plugins/{plugin.url.js → url/plugin.url.js} +24 -2
- package/tests/jest/BookReader.test.js +1 -1
- package/tests/jest/plugins/url/UrlPlugin.test.js +152 -0
- package/tests/jest/plugins/{plugin.url.test.js → url/plugin.url.test.js} +3 -2
- package/tests/karma/BookNavigator/volumes/volumes-provider.test.js +6 -6
- package/webpack.config.js +1 -1
@@ -0,0 +1,152 @@
|
|
1
|
+
import { UrlPlugin } from '@/src/plugins/url/UrlPlugin';
|
2
|
+
|
3
|
+
afterEach(() => {
|
4
|
+
jest.clearAllMocks();
|
5
|
+
});
|
6
|
+
|
7
|
+
describe('UrlPlugin tests', () => {
|
8
|
+
const urlPlugin = new UrlPlugin();
|
9
|
+
|
10
|
+
describe('urlStateToUrlString tests', () => {
|
11
|
+
test('urlStateToUrlString with known states in schema', () => {
|
12
|
+
const urlState = { page: 'n7', mode: '1up', search: 'foo' };
|
13
|
+
const urlStateWithQueries = { page: 'n7', mode: '1up', q: 'hello', view: 'theater', sort: 'title_asc' };
|
14
|
+
|
15
|
+
const expectedUrlFromState = 'page/n7/mode/1up?q=foo';
|
16
|
+
const expectedUrlFromStateWithQueries = 'page/n7/mode/1up?q=hello&view=theater&sort=title_asc';
|
17
|
+
|
18
|
+
expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
|
19
|
+
expect(urlPlugin.urlStateToUrlString(urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
|
20
|
+
});
|
21
|
+
|
22
|
+
test('urlStateToUrlString with unknown states in schema', () => {
|
23
|
+
const urlState = { page: 'n7', mode: '1up' };
|
24
|
+
const urlStateWithQueries = { page: 'n7', mode: '1up', q: 'hello', viewer: 'theater', sortBy: 'title_asc' };
|
25
|
+
|
26
|
+
const expectedUrlFromState = 'page/n7/mode/1up';
|
27
|
+
const expectedUrlFromStateWithQueries = 'page/n7/mode/1up?q=hello&viewer=theater&sortBy=title_asc';
|
28
|
+
|
29
|
+
expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
|
30
|
+
expect(urlPlugin.urlStateToUrlString(urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
|
31
|
+
});
|
32
|
+
|
33
|
+
test('urlStateToUrlString with boolean value', () => {
|
34
|
+
const urlState = { page: 'n7', mode: '1up', search: 'foo', view: 'theater', wrapper: 'false' };
|
35
|
+
const expectedUrlFromState = 'page/n7/mode/1up?q=foo&view=theater&wrapper=false';
|
36
|
+
|
37
|
+
expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
|
38
|
+
});
|
39
|
+
});
|
40
|
+
|
41
|
+
describe('urlStringToUrlState tests', () => {
|
42
|
+
test('urlStringToUrlState without query string', () => {
|
43
|
+
const url = '/page/n7/mode/2up';
|
44
|
+
const url1 = '/page/n7/mode/1up';
|
45
|
+
|
46
|
+
expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up'});
|
47
|
+
expect(urlPlugin.urlStringToUrlState(url1)).toEqual({page: 'n7', mode: '1up'});
|
48
|
+
});
|
49
|
+
|
50
|
+
test('urlStringToUrlState with deprecated_for', () => {
|
51
|
+
const url = '/page/n7/mode/2up/search/hello';
|
52
|
+
|
53
|
+
expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
|
54
|
+
});
|
55
|
+
|
56
|
+
test('urlStringToUrlState with query string', () => {
|
57
|
+
const url = '/page/n7/mode/2up/search/hello?view=theather&foo=bar&sort=title_asc';
|
58
|
+
const url1 = '/mode/2up?ref=ol&ui=embed&wrapper=false&view=theater';
|
59
|
+
|
60
|
+
expect(urlPlugin.urlStringToUrlState(url)).toEqual(
|
61
|
+
{page: 'n7', mode: '2up', q: 'hello', view: 'theather', foo: 'bar', sort: 'title_asc'}
|
62
|
+
);
|
63
|
+
expect(urlPlugin.urlStringToUrlState(url1)).toEqual(
|
64
|
+
{page: 'n0', mode: '2up', ref: 'ol', ui: 'embed', wrapper: 'false', view: 'theater'}
|
65
|
+
);
|
66
|
+
});
|
67
|
+
|
68
|
+
test('urlStringToUrlState compare search and ?q', () => {
|
69
|
+
const url = '/page/n7/mode/2up/search/hello';
|
70
|
+
urlPlugin.urlState = { q: 'hello' };
|
71
|
+
|
72
|
+
expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
|
73
|
+
});
|
74
|
+
});
|
75
|
+
|
76
|
+
describe('url plugin helper functions', () => {
|
77
|
+
test('setUrlParam', () => {
|
78
|
+
urlPlugin.urlState = {};
|
79
|
+
urlPlugin.setUrlParam('page', '20');
|
80
|
+
urlPlugin.setUrlParam('mode', '2up');
|
81
|
+
|
82
|
+
expect(urlPlugin.urlState).toEqual({page: '20', mode: '2up'});
|
83
|
+
});
|
84
|
+
|
85
|
+
test('removeUrlParam', () => {
|
86
|
+
urlPlugin.setUrlParam('page', '20');
|
87
|
+
urlPlugin.setUrlParam('mode', '2up');
|
88
|
+
urlPlugin.removeUrlParam('mode');
|
89
|
+
|
90
|
+
expect(urlPlugin.urlState).toEqual({page: '20'});
|
91
|
+
});
|
92
|
+
|
93
|
+
test('getUrlParam', () => {
|
94
|
+
urlPlugin.setUrlParam('page', '20');
|
95
|
+
urlPlugin.setUrlParam('mode', '2up');
|
96
|
+
expect(urlPlugin.getUrlParam('page')).toEqual('20');
|
97
|
+
expect(urlPlugin.getUrlParam('mode')).toEqual('2up');
|
98
|
+
});
|
99
|
+
});
|
100
|
+
|
101
|
+
describe('pullFromAddressBar and pushToAddressBar - hash mode', () => {
|
102
|
+
test('url without mode state value - use default', () => {
|
103
|
+
urlPlugin.urlState = {};
|
104
|
+
urlPlugin.urlMode = 'hash';
|
105
|
+
|
106
|
+
urlPlugin.pullFromAddressBar({ pathname: '', search: '', hash: '#page/12' });
|
107
|
+
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up'});
|
108
|
+
|
109
|
+
urlPlugin.pushToAddressBar();
|
110
|
+
expect(window.location.hash).toEqual('#page/12/mode/2up');
|
111
|
+
});
|
112
|
+
|
113
|
+
test('url with query param', () => {
|
114
|
+
urlPlugin.urlState = {};
|
115
|
+
urlPlugin.urlMode = 'hash';
|
116
|
+
|
117
|
+
urlPlugin.pullFromAddressBar({ pathname: '', search: '', hash: '#page/12?q=hello&view=theater' });
|
118
|
+
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up', q: 'hello', view: 'theater'});
|
119
|
+
|
120
|
+
urlPlugin.pushToAddressBar();
|
121
|
+
expect(window.location.hash).toEqual('#page/12/mode/2up?q=hello&view=theater');
|
122
|
+
});
|
123
|
+
});
|
124
|
+
|
125
|
+
describe('pullFromAddressBar and pushToAddressBar - history mode', () => {
|
126
|
+
test('url without mode state value - use default', () => {
|
127
|
+
urlPlugin.urlState = {};
|
128
|
+
urlPlugin.urlHistoryBasePath = '/details/foo/';
|
129
|
+
urlPlugin.urlMode = 'history';
|
130
|
+
|
131
|
+
urlPlugin.pullFromAddressBar({ pathname: '/details/foo/page/12', search: '', hash: '' });
|
132
|
+
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up'});
|
133
|
+
|
134
|
+
urlPlugin.pushToAddressBar();
|
135
|
+
expect(window.location.pathname).toEqual('/details/foo/page/12/mode/2up');
|
136
|
+
});
|
137
|
+
|
138
|
+
test('url with query param', () => {
|
139
|
+
urlPlugin.urlState = {};
|
140
|
+
urlPlugin.urlHistoryBasePath = '/details/foo/';
|
141
|
+
urlPlugin.urlMode = 'history';
|
142
|
+
|
143
|
+
urlPlugin.pullFromAddressBar({ pathname: '/details/foo/page/12', search: '?q=hello&view=theater', hash: '' });
|
144
|
+
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up', q: 'hello', view: 'theater'});
|
145
|
+
|
146
|
+
urlPlugin.pushToAddressBar();
|
147
|
+
const locationUrl = `${window.location.pathname}${window.location.search}`;
|
148
|
+
expect(locationUrl).toEqual('/details/foo/page/12/mode/2up?q=hello&view=theater');
|
149
|
+
});
|
150
|
+
});
|
151
|
+
|
152
|
+
});
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
1
|
import BookReader from '@/src/BookReader.js';
|
3
|
-
import '@/src/plugins/plugin.url.js';
|
2
|
+
import '@/src/plugins/url/plugin.url.js';
|
3
|
+
import sinon from 'sinon';
|
4
4
|
|
5
5
|
let br;
|
6
6
|
beforeAll(() => {
|
@@ -10,6 +10,7 @@ beforeAll(() => {
|
|
10
10
|
|
11
11
|
afterEach(() => {
|
12
12
|
jest.clearAllMocks();
|
13
|
+
sinon.restore();
|
13
14
|
});
|
14
15
|
|
15
16
|
describe('Plugin: URL controller', () => {
|
@@ -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
|
|
package/webpack.config.js
CHANGED
@@ -51,7 +51,7 @@ module.exports = [
|
|
51
51
|
'plugins/plugin.search.js': { import: './src/plugins/search/plugin.search.js', dependOn: 'BookReader.js' },
|
52
52
|
'plugins/plugin.text_selection.js': { import: './src/plugins/plugin.text_selection.js', dependOn: 'BookReader.js' },
|
53
53
|
'plugins/plugin.tts.js': { import: './src/plugins/tts/plugin.tts.js', dependOn: 'BookReader.js' },
|
54
|
-
'plugins/plugin.url.js': { import: './src/plugins/plugin.url.js', dependOn: 'BookReader.js' },
|
54
|
+
'plugins/plugin.url.js': { import: './src/plugins/url/plugin.url.js', dependOn: 'BookReader.js' },
|
55
55
|
'plugins/plugin.vendor-fullscreen.js': { import: './src/plugins/plugin.vendor-fullscreen.js', dependOn: 'BookReader.js' },
|
56
56
|
'bookreader-component-bundle.js': { import: './src/BookReaderComponent/BookReaderComponent.js', dependOn: 'BookReader.js' }
|
57
57
|
},
|