@internetarchive/ia-book-actions 0.0.13 → 0.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetarchive/ia-book-actions",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
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 && web-test-runner --coverage",
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.5",
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",
@@ -144,6 +144,7 @@ export default class GetLendingActions {
144
144
  primaryTitle: 'Book available to patrons with print disabilities.',
145
145
  primaryActions: [unavailable],
146
146
  primaryColor: 'primary',
147
+ secondaryActions: [],
147
148
  };
148
149
  }
149
150
 
@@ -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 {
@@ -147,11 +151,11 @@ export default class IABookActions extends LitElement {
147
151
  if (!actions) return;
148
152
 
149
153
  this.primaryTitle = actions.primaryTitle;
150
- this.primaryActions = actions.primaryActions.filter(action => {
154
+ this.primaryActions = actions.primaryActions?.filter(action => {
151
155
  return action != null;
152
156
  });
153
157
  this.primaryColor = actions.primaryColor;
154
- this.secondaryActions = actions.secondaryActions.filter(action => {
158
+ this.secondaryActions = actions.secondaryActions?.filter(action => {
155
159
  return action != null;
156
160
  });
157
161
 
@@ -162,6 +166,14 @@ export default class IABookActions extends LitElement {
162
166
  this.lendingStatus?.browsingExpired;
163
167
  if (hasExpired) {
164
168
  this.tokenPoller?.disconnectedInterval();
169
+ /** Global event - always fire */
170
+ this.dispatchEvent(
171
+ new Event(events.browseExpired, {
172
+ bubbles: true,
173
+ cancelable: false,
174
+ composed: true,
175
+ })
176
+ );
165
177
  return;
166
178
  }
167
179
 
@@ -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);