@internetarchive/bookreader 5.0.0-32-shadydom3 → 5.0.0-32-1
Sign up to get free protection for your applications and to get access to all the features.
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +26 -26
- package/BookReader/ia-bookreader-bundle.js.map +1 -1
- package/package.json +1 -1
- package/src/BookNavigator/bookmarks/bookmarks-provider.js +1 -1
- package/src/BookNavigator/bookmarks/ia-bookmarks.js +5 -2
- package/tests/karma/BookNavigator/bookmarks/ia-bookmarks.test.js +57 -0
package/package.json
CHANGED
@@ -142,8 +142,8 @@ class IABookmarks extends LitElement {
|
|
142
142
|
if (this.displayMode === 'login') {
|
143
143
|
return;
|
144
144
|
}
|
145
|
+
this.fetchUserBookmarks();
|
145
146
|
this.setBREventListeners();
|
146
|
-
this.initializeBookmarks();
|
147
147
|
}
|
148
148
|
|
149
149
|
updateDisplay() {
|
@@ -153,6 +153,9 @@ class IABookmarks extends LitElement {
|
|
153
153
|
}
|
154
154
|
|
155
155
|
fetchUserBookmarks() {
|
156
|
+
if (!this.api.identifier) {
|
157
|
+
return;
|
158
|
+
}
|
156
159
|
this.fetchBookmarks()
|
157
160
|
.then(() => {
|
158
161
|
this.initializeBookmarks();
|
@@ -227,7 +230,7 @@ class IABookmarks extends LitElement {
|
|
227
230
|
}
|
228
231
|
|
229
232
|
fetchBookmarks() {
|
230
|
-
return this.api.getAll().then((res) => {
|
233
|
+
return this.api.getAll().then(res => res.text()).then((res) => {
|
231
234
|
let response;
|
232
235
|
try {
|
233
236
|
response = JSON.parse(res);
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import {
|
2
|
+
html,
|
3
|
+
fixtureSync,
|
4
|
+
expect,
|
5
|
+
fixtureCleanup,
|
6
|
+
} from '@open-wc/testing';
|
7
|
+
import '../../../../src/BookNavigator/bookmarks/ia-bookmarks.js';
|
8
|
+
import sinon from 'sinon';
|
9
|
+
|
10
|
+
afterEach(() => {
|
11
|
+
sinon.restore();
|
12
|
+
fixtureCleanup();
|
13
|
+
});
|
14
|
+
|
15
|
+
describe('<ia-bookmarks>', () => {
|
16
|
+
it('uses `setup` to start component', async () => {
|
17
|
+
const el = fixtureSync(html`<ia-bookmarks></ia-bookmarks>`);
|
18
|
+
await el.updateComplete;
|
19
|
+
|
20
|
+
let fetchHappened = false;
|
21
|
+
el.bookreader.bookId = 'foo';
|
22
|
+
el.displayMode = 'bookmarks';
|
23
|
+
|
24
|
+
el.fetchBookmarks = async () => {
|
25
|
+
fetchHappened = true;
|
26
|
+
return await Promise.resolve();
|
27
|
+
};
|
28
|
+
|
29
|
+
const fetchSpy = sinon.spy(el, 'fetchUserBookmarks');
|
30
|
+
|
31
|
+
el.setup();
|
32
|
+
await el.updateComplete;
|
33
|
+
|
34
|
+
expect(fetchSpy.callCount).to.equal(1);
|
35
|
+
expect(fetchHappened).to.equal(true);
|
36
|
+
});
|
37
|
+
it('does not fetch user bookmarks if displayMode = login', async () => {
|
38
|
+
const el = fixtureSync(html`<ia-bookmarks></ia-bookmarks>`);
|
39
|
+
await el.updateComplete;
|
40
|
+
|
41
|
+
let fetchHappened = false;
|
42
|
+
el.displayMode = 'login';
|
43
|
+
|
44
|
+
el.fetchBookmarks = async () => {
|
45
|
+
fetchHappened = true;
|
46
|
+
return await Promise.resolve();
|
47
|
+
};
|
48
|
+
|
49
|
+
const fetchSpy = sinon.spy(el, 'fetchUserBookmarks');
|
50
|
+
|
51
|
+
el.setup();
|
52
|
+
await el.updateComplete;
|
53
|
+
|
54
|
+
expect(fetchSpy.callCount).to.equal(0);
|
55
|
+
expect(fetchHappened).to.equal(false);
|
56
|
+
});
|
57
|
+
});
|