@internetarchive/ia-book-actions 0.0.12 → 0.0.13-3

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.12",
3
+ "version": "0.0.13-3",
4
4
  "description": "Bookreader actions for borrowable book",
5
5
  "author": "Internet Archive",
6
6
  "license": "AGPL-3.0-only",
@@ -15,7 +15,7 @@
15
15
  "format": "eslint --ext .js,.html . --fix --ignore-path .gitignore && prettier \"**/*.js\" --write --ignore-path .gitignore",
16
16
  "test": "yarn run lint && web-test-runner --coverage",
17
17
  "test:fast": "web-test-runner --coverage",
18
- "test:watch": "web-test-runner --watch"
18
+ "test:watch": "web-test-runner --watch --puppeteer"
19
19
  },
20
20
  "dependencies": {
21
21
  "@internetarchive/ia-icons": "^1.2.2",
@@ -156,6 +156,15 @@ export default class IABookActions extends LitElement {
156
156
  });
157
157
 
158
158
  this.borrowType = actions.borrowType;
159
+
160
+ const hasExpired =
161
+ 'browsingExpired' in this.lendingStatus &&
162
+ this.lendingStatus?.browsingExpired;
163
+ if (hasExpired) {
164
+ this.tokenPoller?.disconnectedInterval();
165
+ return;
166
+ }
167
+
159
168
  if (this.borrowType === 'browsed') {
160
169
  // start timer for browsed.
161
170
  // when browse is completed, we shows browse-again button
@@ -308,6 +317,7 @@ export default class IABookActions extends LitElement {
308
317
  title: 'Lending error',
309
318
  message: errorMsg,
310
319
  headerColor: '#d9534f',
320
+ showCloseButton: true,
311
321
  });
312
322
 
313
323
  if (action === 'create_token') {
@@ -318,8 +328,6 @@ export default class IABookActions extends LitElement {
318
328
  refresh
319
329
  </button>`;
320
330
 
321
- modalConfig.closeOnBackdropClick = false;
322
- modalConfig.showCloseButton = false;
323
331
  modalConfig.message = html` Uh oh, something went wrong trying to access
324
332
  this book.<br />
325
333
  Please ${refreshButton} to try again or send us an email to
@@ -251,10 +251,41 @@ describe('Browsing expired status', () => {
251
251
  );
252
252
 
253
253
  await aTimeout(1500); // wait for 1.5 second
254
- el.updateComplete;
254
+ await el.updateComplete;
255
+
256
+ expect(el.primaryTitle).contains('Your loan has expired.');
257
+ expect(el.primaryActions[0].text).to.equal('Borrow again');
258
+ });
259
+
260
+ it('Expiring book cancels interval', async () => {
261
+ const baseStatus = {
262
+ is_lendable: true,
263
+ user_has_browsed: false,
264
+ browseHasExpired: false,
265
+ secondsLeftOnLoan: 1,
266
+ };
267
+ const el = await fixture(
268
+ container({
269
+ userid: '@userid',
270
+ lendingStatus: baseStatus,
271
+ })
272
+ );
273
+ const browsingStatus = { ...baseStatus, user_has_browsed: true };
274
+ el.lendingStatus = browsingStatus;
275
+ await el.updateComplete;
276
+
277
+ expect(el.primaryTitle).contains('Borrow ends at ');
278
+ expect(el.primaryActions[0].text).to.equal('Return now');
279
+ expect(el.tokenPoller.loanTokenInterval).to.not.equal(undefined);
280
+
281
+ const expiredStatus = { ...browsingStatus, browsingExpired: true };
282
+ el.lendingStatus = expiredStatus;
283
+ await el.updateComplete;
284
+ await aTimeout(1500); // wait for 1.5 sec
255
285
 
256
286
  expect(el.primaryTitle).contains('Your loan has expired.');
257
287
  expect(el.primaryActions[0].text).to.equal('Borrow again');
288
+ expect(el.tokenPoller.loanTokenInterval).to.equal(undefined);
258
289
  });
259
290
  });
260
291