@internetarchive/ia-book-actions 0.0.14 → 0.0.16-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/demo/index.html +1 -0
- package/package.json +6 -5
- package/src/components/collapsible-action-group.js +2 -0
- package/src/core/services/actions-handler/actions-handler.js +8 -1
- package/src/ia-book-actions.js +15 -0
- package/test/components/collapsible-action-group.test.js +5 -0
- package/test/ia-book-actions.test.js +9 -3
package/demo/index.html
CHANGED
|
@@ -119,6 +119,7 @@
|
|
|
119
119
|
iaBookActions.modalConfig = modalConfig;
|
|
120
120
|
iaBookActions.lendingBarPostInit = lendingBarPostInit;
|
|
121
121
|
iaBookActions.tokenDelay = 2000; // 2 seconds
|
|
122
|
+
iaBookActions.loansUrl = 'https://openlibrary.org';
|
|
122
123
|
|
|
123
124
|
let lendingStatus1 = iaBookActions.lendingStatus;
|
|
124
125
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@internetarchive/ia-book-actions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16-1",
|
|
4
4
|
"description": "Bookreader actions for borrowable book",
|
|
5
5
|
"author": "Internet Archive",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"start": "web-dev-server",
|
|
14
14
|
"lint": "eslint --ext .js,.html . --ignore-path .gitignore && prettier \"**/*.js\" --check --ignore-path .gitignore",
|
|
15
15
|
"format": "eslint --ext .js,.html . --fix --ignore-path .gitignore && prettier \"**/*.js\" --write --ignore-path .gitignore",
|
|
16
|
-
"test": "yarn run lint &&
|
|
17
|
-
"test:fast": "web-test-runner --coverage",
|
|
18
|
-
"test:watch": "web-test-runner --watch"
|
|
16
|
+
"test": "yarn run lint && yarn test:fast",
|
|
17
|
+
"test:fast": "web-test-runner --coverage --playwright --browsers chromium firefox webkit",
|
|
18
|
+
"test:watch": "web-test-runner --watch --playwright --browsers chromium firefox webkit"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@internetarchive/ia-icons": "^1.2.2",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"@open-wc/testing": "^2.0.0",
|
|
34
34
|
"@web/dev-server": "^0.1.1",
|
|
35
35
|
"@web/dev-server-esbuild": "^0.2.16",
|
|
36
|
-
"@web/test-runner": "^0.11.
|
|
36
|
+
"@web/test-runner": "^0.11.7",
|
|
37
|
+
"@web/test-runner-playwright": "^0.8.8",
|
|
37
38
|
"eslint": "^7.32.0",
|
|
38
39
|
"eslint-config-prettier": "^6.11.0",
|
|
39
40
|
"eslint-plugin-import": "^2.22.1",
|
|
@@ -27,6 +27,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
27
27
|
hasAdminAccess: { type: Boolean },
|
|
28
28
|
dropdownArrow: { type: String },
|
|
29
29
|
disabled: { type: Boolean },
|
|
30
|
+
loansUrl: { type: String },
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -45,6 +46,7 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
45
46
|
this.title = '';
|
|
46
47
|
this.loaderIcon = 'https://archive.org/upload/images/tree/loading.gif';
|
|
47
48
|
this.disabled = false;
|
|
49
|
+
this.loansUrl = '';
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
updated(changed) {
|
|
@@ -13,11 +13,18 @@ import * as Cookies from '../doc-cookies.js';
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
export default class ActionsHandler extends LitElement {
|
|
16
|
+
static properties() {
|
|
17
|
+
return {
|
|
18
|
+
loansUrl: { type: String },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
constructor(identifier) {
|
|
17
23
|
super();
|
|
18
24
|
this.identifier = identifier;
|
|
19
25
|
this.ajaxTimeout = 6000;
|
|
20
26
|
this.bindEvents();
|
|
27
|
+
this.loansUrl = '';
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
sendEvent(eventCategory, eventAction) {
|
|
@@ -121,7 +128,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
121
128
|
identifier: this.identifier,
|
|
122
129
|
success: () => {
|
|
123
130
|
this.deleteLoanCookies();
|
|
124
|
-
URLHelper.goToUrl(
|
|
131
|
+
URLHelper.goToUrl(this.loansUrl, true);
|
|
125
132
|
},
|
|
126
133
|
error: data => {
|
|
127
134
|
this.dispatchActionError(action, data);
|
package/src/ia-book-actions.js
CHANGED
|
@@ -13,6 +13,10 @@ import GetLendingActions from './core/services/get-lending-actions.js';
|
|
|
13
13
|
import { mobileContainerWidth } from './core/config/constants.js';
|
|
14
14
|
import { LoanTokenPoller } from './core/services/loan-token-poller.js';
|
|
15
15
|
|
|
16
|
+
export const events = {
|
|
17
|
+
browseExpired: 'IABookReader:BrowsingHasExpired',
|
|
18
|
+
};
|
|
19
|
+
|
|
16
20
|
export default class IABookActions extends LitElement {
|
|
17
21
|
static get properties() {
|
|
18
22
|
return {
|
|
@@ -20,6 +24,7 @@ export default class IABookActions extends LitElement {
|
|
|
20
24
|
identifier: { type: String },
|
|
21
25
|
bookTitle: { type: String },
|
|
22
26
|
lendingStatus: { type: Object },
|
|
27
|
+
loansUrl: { type: String },
|
|
23
28
|
width: { type: Number },
|
|
24
29
|
bwbPurchaseUrl: { type: String },
|
|
25
30
|
lendingBarPostInit: {
|
|
@@ -39,6 +44,7 @@ export default class IABookActions extends LitElement {
|
|
|
39
44
|
this.userid = '';
|
|
40
45
|
this.identifier = '';
|
|
41
46
|
this.bookTitle = '';
|
|
47
|
+
this.loansUrl = '';
|
|
42
48
|
this.lendingStatus = {};
|
|
43
49
|
this.width = 0;
|
|
44
50
|
this.bwbPurchaseUrl = '';
|
|
@@ -162,6 +168,14 @@ export default class IABookActions extends LitElement {
|
|
|
162
168
|
this.lendingStatus?.browsingExpired;
|
|
163
169
|
if (hasExpired) {
|
|
164
170
|
this.tokenPoller?.disconnectedInterval();
|
|
171
|
+
/** Global event - always fire */
|
|
172
|
+
this.dispatchEvent(
|
|
173
|
+
new Event(events.browseExpired, {
|
|
174
|
+
bubbles: true,
|
|
175
|
+
cancelable: false,
|
|
176
|
+
composed: true,
|
|
177
|
+
})
|
|
178
|
+
);
|
|
165
179
|
return;
|
|
166
180
|
}
|
|
167
181
|
|
|
@@ -209,6 +223,7 @@ export default class IABookActions extends LitElement {
|
|
|
209
223
|
.secondaryActions=${this.secondaryActions}
|
|
210
224
|
.width=${this.width}
|
|
211
225
|
.borrowType=${this.borrowType}
|
|
226
|
+
.loansUrl=${this.loansUrl}
|
|
212
227
|
?hasAdminAccess=${this.hasAdminAccess}
|
|
213
228
|
?disabled=${this.disableActionGroup}
|
|
214
229
|
@lendingActionError=${this.handleLendingActionError}
|
|
@@ -29,6 +29,7 @@ const container = ({
|
|
|
29
29
|
.primaryActions=${primaryActions}
|
|
30
30
|
.secondaryActions=${secondaryActions}
|
|
31
31
|
.borrowType=${borrowType}
|
|
32
|
+
.loansUrl=${'https://openlibrary.org'}
|
|
32
33
|
></collapsible-action-group>`;
|
|
33
34
|
|
|
34
35
|
describe('<collapsible-action-group>', () => {
|
|
@@ -83,4 +84,8 @@ describe('<collapsible-action-group>', () => {
|
|
|
83
84
|
expect(eAnalytics.category).to.equal('Lending');
|
|
84
85
|
expect(eAnalytics.action).to.equal('Browse');
|
|
85
86
|
});
|
|
87
|
+
it('receives `loanUrl`', async () => {
|
|
88
|
+
const el = await fixture(container());
|
|
89
|
+
expect(el.loansUrl).to.equal('https://openlibrary.org');
|
|
90
|
+
});
|
|
86
91
|
});
|
|
@@ -257,12 +257,10 @@ describe('Browsing expired status', () => {
|
|
|
257
257
|
expect(el.primaryActions[0].text).to.equal('Borrow again');
|
|
258
258
|
});
|
|
259
259
|
|
|
260
|
-
it('Expiring book cancels interval', async () => {
|
|
260
|
+
it('Expiring book cancels interval & emits event', async () => {
|
|
261
261
|
const baseStatus = {
|
|
262
262
|
is_lendable: true,
|
|
263
263
|
user_has_browsed: false,
|
|
264
|
-
browseHasExpired: false,
|
|
265
|
-
secondsLeftOnLoan: 1,
|
|
266
264
|
};
|
|
267
265
|
const el = await fixture(
|
|
268
266
|
container({
|
|
@@ -270,6 +268,13 @@ describe('Browsing expired status', () => {
|
|
|
270
268
|
lendingStatus: baseStatus,
|
|
271
269
|
})
|
|
272
270
|
);
|
|
271
|
+
|
|
272
|
+
let eventReceived = false;
|
|
273
|
+
const listener = () => {
|
|
274
|
+
eventReceived = true;
|
|
275
|
+
};
|
|
276
|
+
el.addEventListener('IABookReader:BrowsingHasExpired', listener);
|
|
277
|
+
|
|
273
278
|
const browsingStatus = { ...baseStatus, user_has_browsed: true };
|
|
274
279
|
el.lendingStatus = browsingStatus;
|
|
275
280
|
await el.updateComplete;
|
|
@@ -283,6 +288,7 @@ describe('Browsing expired status', () => {
|
|
|
283
288
|
await el.updateComplete;
|
|
284
289
|
await aTimeout(1500); // wait for 1.5 sec
|
|
285
290
|
|
|
291
|
+
expect(eventReceived).to.equal(true);
|
|
286
292
|
expect(el.primaryTitle).contains('Your loan has expired.');
|
|
287
293
|
expect(el.primaryActions[0].text).to.equal('Borrow again');
|
|
288
294
|
expect(el.tokenPoller.loanTokenInterval).to.equal(undefined);
|