@internetarchive/bookreader 5.0.0-24-sortingstate-1 → 5.0.0-24-sortingstate-5
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.js +1 -4
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/bookreader-component-bundle.js +16 -22
- package/BookReader/bookreader-component-bundle.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +61 -46
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/package.json +1 -1
- package/src/BookNavigator/volumes/volumes-provider.js +1 -1
- package/src/BookReader.js +0 -4
- package/src/plugins/plugin.url.js +29 -23
- package/tests/jest/plugins/plugin.url.test.js +15 -24
- package/tests/karma/BookNavigator/volumes/volumes-provider.test.js +6 -6
@@ -17,15 +17,6 @@ afterEach(() => {
|
|
17
17
|
|
18
18
|
describe.only('UrlPlugin tests', () => {
|
19
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
20
|
|
30
21
|
describe('urlStateToUrlString tests', () => {
|
31
22
|
test('urlStateToUrlString with known states in schema', () => {
|
@@ -35,8 +26,8 @@ describe.only('UrlPlugin tests', () => {
|
|
35
26
|
const expectedUrlFromState = '/page/n7/mode/1up?q=foo';
|
36
27
|
const expectedUrlFromStateWithQueries = '/page/n7/mode/1up?q=hello&view=theater&sort=title_asc';
|
37
28
|
|
38
|
-
expect(urlPlugin.urlStateToUrlString(
|
39
|
-
expect(urlPlugin.urlStateToUrlString(
|
29
|
+
expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
|
30
|
+
expect(urlPlugin.urlStateToUrlString(urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
|
40
31
|
});
|
41
32
|
|
42
33
|
test('urlStateToUrlString with unknown states in schema', () => {
|
@@ -46,15 +37,15 @@ describe.only('UrlPlugin tests', () => {
|
|
46
37
|
const expectedUrlFromState = '/page/n7/mode/1up';
|
47
38
|
const expectedUrlFromStateWithQueries = '/page/n7/mode/1up?q=hello&viewer=theater&sortBy=title_asc';
|
48
39
|
|
49
|
-
expect(urlPlugin.urlStateToUrlString(
|
50
|
-
expect(urlPlugin.urlStateToUrlString(
|
40
|
+
expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
|
41
|
+
expect(urlPlugin.urlStateToUrlString(urlStateWithQueries)).toBe(expectedUrlFromStateWithQueries);
|
51
42
|
});
|
52
43
|
|
53
44
|
test('urlStateToUrlString with boolean value', () => {
|
54
45
|
const urlState = { page: 'n7', mode: '1up', search: 'foo', view: 'theater', wrapper: false };
|
55
46
|
const expectedUrlFromState = '/page/n7/mode/1up?q=foo&view=theater&wrapper=false';
|
56
47
|
|
57
|
-
expect(urlPlugin.urlStateToUrlString(
|
48
|
+
expect(urlPlugin.urlStateToUrlString(urlState)).toBe(expectedUrlFromState);
|
58
49
|
});
|
59
50
|
});
|
60
51
|
|
@@ -63,24 +54,24 @@ describe.only('UrlPlugin tests', () => {
|
|
63
54
|
const url = '/page/n7/mode/2up';
|
64
55
|
const url1 = '/page/n7/mode/1up';
|
65
56
|
|
66
|
-
expect(urlPlugin.urlStringToUrlState(
|
67
|
-
expect(urlPlugin.urlStringToUrlState(
|
57
|
+
expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up'});
|
58
|
+
expect(urlPlugin.urlStringToUrlState(url1)).toEqual({page: 'n7', mode: '1up'});
|
68
59
|
});
|
69
60
|
|
70
61
|
test('urlStringToUrlState with deprecated_for', () => {
|
71
62
|
const url = '/page/n7/mode/2up/search/hello';
|
72
63
|
|
73
|
-
expect(urlPlugin.urlStringToUrlState(
|
64
|
+
expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
|
74
65
|
});
|
75
66
|
|
76
67
|
test('urlStringToUrlState with query string', () => {
|
77
68
|
const url = '/page/n7/mode/2up/search/hello?view=theather&foo=bar&sort=title_asc';
|
78
69
|
const url1 = '/mode/2up?ref=ol&ui=embed&wrapper=false&view=theater';
|
79
70
|
|
80
|
-
expect(urlPlugin.urlStringToUrlState(
|
71
|
+
expect(urlPlugin.urlStringToUrlState(url)).toEqual(
|
81
72
|
{page: 'n7', mode: '2up', q: 'hello', view: 'theather', foo: 'bar', sort: 'title_asc'}
|
82
73
|
);
|
83
|
-
expect(urlPlugin.urlStringToUrlState(
|
74
|
+
expect(urlPlugin.urlStringToUrlState(url1)).toEqual(
|
84
75
|
{page: 'n0', mode: '2up', ref: 'ol', ui: 'embed', wrapper: false, view: 'theater'}
|
85
76
|
);
|
86
77
|
});
|
@@ -89,7 +80,7 @@ describe.only('UrlPlugin tests', () => {
|
|
89
80
|
const url = '/page/n7/mode/2up/search/hello';
|
90
81
|
urlPlugin.urlState = { q: 'hello' };
|
91
82
|
|
92
|
-
expect(urlPlugin.urlStringToUrlState(
|
83
|
+
expect(urlPlugin.urlStringToUrlState(url)).toEqual({page: 'n7', mode: '2up', q: 'hello'});
|
93
84
|
});
|
94
85
|
});
|
95
86
|
|
@@ -123,7 +114,7 @@ describe.only('UrlPlugin tests', () => {
|
|
123
114
|
urlPlugin.urlState = {};
|
124
115
|
urlPlugin.urlMode = 'hash';
|
125
116
|
|
126
|
-
urlPlugin.pullFromAddressBar('/page/12');
|
117
|
+
urlPlugin.pullFromAddressBar({ pathname: '/page/12', search: '', hash: '' });
|
127
118
|
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up'});
|
128
119
|
|
129
120
|
urlPlugin.pushToAddressBar();
|
@@ -134,7 +125,7 @@ describe.only('UrlPlugin tests', () => {
|
|
134
125
|
urlPlugin.urlState = {};
|
135
126
|
urlPlugin.urlMode = 'hash';
|
136
127
|
|
137
|
-
urlPlugin.pullFromAddressBar('/page/12
|
128
|
+
urlPlugin.pullFromAddressBar({ pathname: '/page/12', search: '?q=hello&view=theater', hash: '' });
|
138
129
|
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up', q: 'hello', view: 'theater'});
|
139
130
|
|
140
131
|
urlPlugin.pushToAddressBar();
|
@@ -148,7 +139,7 @@ describe.only('UrlPlugin tests', () => {
|
|
148
139
|
urlPlugin.urlHistoryBasePath = '/details/foo';
|
149
140
|
urlPlugin.urlMode = 'history';
|
150
141
|
|
151
|
-
urlPlugin.pullFromAddressBar('/details/foo/page/12');
|
142
|
+
urlPlugin.pullFromAddressBar({ pathname: '/details/foo/page/12', search: '', hash: '' });
|
152
143
|
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up'});
|
153
144
|
|
154
145
|
urlPlugin.pushToAddressBar();
|
@@ -160,7 +151,7 @@ describe.only('UrlPlugin tests', () => {
|
|
160
151
|
urlPlugin.urlHistoryBasePath = '/details/foo';
|
161
152
|
urlPlugin.urlMode = 'history';
|
162
153
|
|
163
|
-
urlPlugin.pullFromAddressBar('/details/foo/page/12
|
154
|
+
urlPlugin.pullFromAddressBar({ pathname: '/details/foo/page/12', search: '?q=hello&view=theater', hash: '' });
|
164
155
|
expect(urlPlugin.urlState).toEqual({page: '12', mode: '2up', q: 'hello', view: 'theater'});
|
165
156
|
|
166
157
|
urlPlugin.pushToAddressBar();
|
@@ -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("orig_sort");
|
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("orig_sort");
|
78
|
+
expect(provider.sortOrderBy).to.equal("orig_sort");
|
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("orig_sort");
|
92
92
|
|
93
|
-
expect(provider.sortOrderBy).to.equal("
|
93
|
+
expect(provider.sortOrderBy).to.equal("orig_sort");
|
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 = 'orig_sort';
|
148
148
|
const origSortButton = await fixture(provider.sortButton);
|
149
149
|
expect(origSortButton.classList.contains('neutral-icon')).to.be.true;
|
150
150
|
|