@internetarchive/ia-book-actions 0.0.6-8 → 0.0.6-8-01
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 +1 -1
- package/src/components/collapsible-action-group.js +4 -1
- package/src/components/dialog-alert.js +12 -7
- package/src/core/services/actions-handler/actions-handler-service.js +4 -1
- package/src/core/services/actions-handler/actions-handler.js +3 -1
- package/src/ia-book-actions.js +11 -11
- package/test/components/dialog-alert.test.js +62 -0
- package/test/ia-book-actions.test.js +0 -1
package/package.json
CHANGED
|
@@ -63,7 +63,10 @@ export class CollapsibleActionGroup extends ActionsHandler {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// this is execute on demo page only
|
|
66
|
-
if (
|
|
66
|
+
if (
|
|
67
|
+
changed.has('bookHasBrowsed') &&
|
|
68
|
+
window.location.pathname === '/demo/'
|
|
69
|
+
) {
|
|
67
70
|
this.emitFetchLoanToken();
|
|
68
71
|
}
|
|
69
72
|
}
|
|
@@ -12,6 +12,7 @@ export class ShowDialog extends LitElement {
|
|
|
12
12
|
body: { type: String },
|
|
13
13
|
actions: { type: Array },
|
|
14
14
|
opened: { type: Boolean },
|
|
15
|
+
allowClose: { type: Boolean },
|
|
15
16
|
};
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -22,6 +23,7 @@ export class ShowDialog extends LitElement {
|
|
|
22
23
|
'Unexpected error: loan does not exist. Please try deleting your archive.org cookie.';
|
|
23
24
|
this.actions = [];
|
|
24
25
|
this.opened = false;
|
|
26
|
+
this.allowClose = false;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
updated(changed) {
|
|
@@ -41,19 +43,22 @@ export class ShowDialog extends LitElement {
|
|
|
41
43
|
closed: !this.opened,
|
|
42
44
|
})}"
|
|
43
45
|
>
|
|
44
|
-
<div class="dialog-head">
|
|
45
|
-
${this.title}
|
|
46
|
-
<ia-icon-close
|
|
47
|
-
@click="${() =>
|
|
48
|
-
this.dispatchEvent(new CustomEvent('dialogAlertClose'))}"
|
|
49
|
-
></ia-icon-close>
|
|
50
|
-
</div>
|
|
46
|
+
<div class="dialog-head">${this.title} ${this.closeButton}</div>
|
|
51
47
|
<div class="dialog-body">${this.body}</div>
|
|
52
48
|
<div class="dialog-foot">${this.renderActionButton}</div>
|
|
53
49
|
</div>
|
|
54
50
|
`;
|
|
55
51
|
}
|
|
56
52
|
|
|
53
|
+
get closeButton() {
|
|
54
|
+
return this.allowClose
|
|
55
|
+
? html`<ia-icon-close
|
|
56
|
+
@click="${() =>
|
|
57
|
+
this.dispatchEvent(new CustomEvent('dialogAlertClose'))}"
|
|
58
|
+
></ia-icon-close>`
|
|
59
|
+
: html``;
|
|
60
|
+
}
|
|
61
|
+
|
|
57
62
|
/* exceptional case to use dom element */
|
|
58
63
|
addOverlay() {
|
|
59
64
|
if (this.opened && !document.getElementById('ui-overlay')) {
|
|
@@ -32,7 +32,10 @@ export default function ActionsHandlerService(options) {
|
|
|
32
32
|
// test changes, (won't affect you)
|
|
33
33
|
if (baseHost == '/demo/1' || baseHost == '/demo/') {
|
|
34
34
|
if (option.action == 'create_token') {
|
|
35
|
-
|
|
35
|
+
return {
|
|
36
|
+
success: false,
|
|
37
|
+
error: 'loan token not found. please try again later.',
|
|
38
|
+
};
|
|
36
39
|
return {
|
|
37
40
|
success: true,
|
|
38
41
|
token: '1640945898-f77a0cb615190798f1faf2dafe277b2e',
|
|
@@ -15,7 +15,8 @@ export default class ActionsHandler extends LitElement {
|
|
|
15
15
|
super();
|
|
16
16
|
this.identifier = identifier;
|
|
17
17
|
this.ajaxTimeout = 6000;
|
|
18
|
-
this.loanTokenPollingDelay =
|
|
18
|
+
this.loanTokenPollingDelay =
|
|
19
|
+
window.location.pathname === '/demo/' ? 2000 : 20000; // 20000 ms = 20 sec
|
|
19
20
|
this.loanTokenInterval = null;
|
|
20
21
|
this.bindEvents();
|
|
21
22
|
}
|
|
@@ -192,6 +193,7 @@ export default class ActionsHandler extends LitElement {
|
|
|
192
193
|
action: context,
|
|
193
194
|
error: data => {
|
|
194
195
|
this.ActionError(context, data);
|
|
196
|
+
clearInterval(this.loanTokenInterval); // stop token fetch api
|
|
195
197
|
},
|
|
196
198
|
});
|
|
197
199
|
}
|
package/src/ia-book-actions.js
CHANGED
|
@@ -23,7 +23,7 @@ export default class IABookActions extends LitElement {
|
|
|
23
23
|
bwbPurchaseUrl: { type: String },
|
|
24
24
|
barType: { type: String },
|
|
25
25
|
sharedObserver: { attribute: false },
|
|
26
|
-
|
|
26
|
+
disableActionGroup: { type: Boolean },
|
|
27
27
|
dialogVisible: { type: Boolean },
|
|
28
28
|
bookHasBrowsed: { type: Boolean },
|
|
29
29
|
};
|
|
@@ -166,7 +166,8 @@ export default class IABookActions extends LitElement {
|
|
|
166
166
|
.title=${this.dialogTitle}
|
|
167
167
|
.body=${this.dialogBody}
|
|
168
168
|
.actions=${this.dialogActions}
|
|
169
|
-
?opened
|
|
169
|
+
?opened=${this.dialogVisible}
|
|
170
|
+
?allowClose=${this.allowClose}
|
|
170
171
|
@dialogAlertClose="${() => this.closeDialogAlert()}"
|
|
171
172
|
></show-dialog>
|
|
172
173
|
`;
|
|
@@ -192,9 +193,9 @@ export default class IABookActions extends LitElement {
|
|
|
192
193
|
.primaryActions=${this.primaryActions}
|
|
193
194
|
.secondaryActions=${this.secondaryActions}
|
|
194
195
|
.width=${this.width}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
?hasAdminAccess=${this.hasAdminAccess}
|
|
197
|
+
?disabled=${this.disableActionGroup}
|
|
198
|
+
?bookHasBrowsed=${this.bookHasBrowsed}
|
|
198
199
|
@lendingActionError=${this.handleLendingActionError}
|
|
199
200
|
>
|
|
200
201
|
</collapsible-action-group>
|
|
@@ -209,10 +210,8 @@ export default class IABookActions extends LitElement {
|
|
|
209
210
|
const context = e?.detail?.context;
|
|
210
211
|
const errorMsg = e?.detail?.data?.error;
|
|
211
212
|
|
|
212
|
-
//
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
this.initializeDialogAlert(context, errorMsg);
|
|
213
|
+
// initiate dialog-alert if error occured
|
|
214
|
+
if (errorMsg) this.initializeDialogAlert(context, errorMsg);
|
|
216
215
|
|
|
217
216
|
// update action bar state if book is not available to browse or borrow.
|
|
218
217
|
if (errorMsg && errorMsg.match(/not available to borrow/gm)) {
|
|
@@ -237,14 +236,15 @@ export default class IABookActions extends LitElement {
|
|
|
237
236
|
this.dialogVisible = true;
|
|
238
237
|
this.dialogTitle = 'Sorry!';
|
|
239
238
|
this.dialogBody = errorMsg;
|
|
240
|
-
this.
|
|
239
|
+
this.allowClose = true;
|
|
241
240
|
|
|
242
241
|
if (context === 'create_token') {
|
|
242
|
+
this.allowClose = false;
|
|
243
243
|
this.dialogActions = [
|
|
244
244
|
{
|
|
245
245
|
className: 'ia-button primary',
|
|
246
246
|
text: 'Back to Item Details',
|
|
247
|
-
href:
|
|
247
|
+
href: this.lendingStatus.bookUrl,
|
|
248
248
|
},
|
|
249
249
|
];
|
|
250
250
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import { html, fixture, expect } from '@open-wc/testing';
|
|
3
|
+
import '../../src/components/dialog-alert.js';
|
|
4
|
+
|
|
5
|
+
const container = ({
|
|
6
|
+
title = '',
|
|
7
|
+
body = '',
|
|
8
|
+
allowClose = false,
|
|
9
|
+
opened = false,
|
|
10
|
+
} = {}) =>
|
|
11
|
+
html`<show-dialog
|
|
12
|
+
.title=${title}
|
|
13
|
+
.body=${body}
|
|
14
|
+
?allowClose=${allowClose}
|
|
15
|
+
?opened=${opened}
|
|
16
|
+
></show-dialog>`;
|
|
17
|
+
|
|
18
|
+
describe('<show-dialog>', () => {
|
|
19
|
+
it('assign values and initiate dialog-alert', async () => {
|
|
20
|
+
const el = await fixture(
|
|
21
|
+
container({
|
|
22
|
+
title: 'internal error!',
|
|
23
|
+
body: 'there was an internal error',
|
|
24
|
+
opened: true,
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
expect(el.title).to.be.equal('internal error!');
|
|
28
|
+
expect(el.body).to.be.equal('there was an internal error');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('close button should not render', async () => {
|
|
32
|
+
const el = await fixture(
|
|
33
|
+
container({
|
|
34
|
+
title: 'internal error!',
|
|
35
|
+
body: 'there was an internal error',
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
expect(el.title).to.be.equal('internal error!');
|
|
39
|
+
expect(el.body).to.be.equal('there was an internal error');
|
|
40
|
+
|
|
41
|
+
// close icon is not exist
|
|
42
|
+
const closeButton = el.shadowRoot.querySelector('ia-icon-close');
|
|
43
|
+
expect(closeButton).to.be.null;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('close dialog-alert on X icon click', async () => {
|
|
47
|
+
const el = await fixture(
|
|
48
|
+
container({
|
|
49
|
+
title: 'internal error!',
|
|
50
|
+
body: 'there was an internal error',
|
|
51
|
+
allowClose: true,
|
|
52
|
+
opened: true,
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const closeButton = el.shadowRoot.querySelector('ia-icon-close');
|
|
57
|
+
const errorEvent = new CustomEvent('dialogAlertClose');
|
|
58
|
+
closeButton.dispatchEvent(errorEvent);
|
|
59
|
+
await el.updateComplete;
|
|
60
|
+
expect(el.opened).to.be.true;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -130,7 +130,6 @@ describe('Borrow status actions', () => {
|
|
|
130
130
|
el.dispatchEvent(errorEvent);
|
|
131
131
|
await el.updateComplete;
|
|
132
132
|
|
|
133
|
-
console.log(el.lendingStatus);
|
|
134
133
|
// removed available_to_browse from lending bar
|
|
135
134
|
expect(el.lendingStatus.available_to_browse).to.be.false;
|
|
136
135
|
expect(el.primaryActions[0].text).to.equal('Borrow for 14 days');
|