generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathutilities.js
55 lines (47 loc) · 1.54 KB
/
utilities.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import chaiAsPromised from '@esm-bundle/chai-as-promised';
import { expect, use } from '@esm-bundle/chai';
import sinon from 'sinon';
import { equalsCaseInsensitive } from '../src/external.js';
import { TAG_NAME_SERVICE } from '../src/mas-commerce-service.js';
use(chaiAsPromised);
use((chai) => {
function normalise(val) {
return String(val)
.trim()
.replace(/>\s*</g, '><')
.replace(/>\s*/g, '>')
.replace(/\s*</g, '<')
.replace(/"\s*>/g, '">')
.replace(/"\s*\/>/g, '/>')
.replace(/\s+/g, ' ');
}
chai.Assertion.addMethod('html', function assertHtml(snapshot) {
const normAct = normalise(this._obj);
const normExp = normalise(snapshot);
this.assert(
equalsCaseInsensitive(normAct, normExp),
'expected to match html snapshot',
'expected not to match html snapshot',
normAct,
normExp,
);
});
});
const initMasCommerceService = async (attributes, checkoutAction) => {
const el = document.createElement(TAG_NAME_SERVICE);
if (attributes) {
Object.keys(attributes).forEach((key) => {
el.setAttribute(key, attributes[key]);
})
}
if (checkoutAction) {
el.registerCheckoutAction(checkoutAction);
}
document.head.appendChild(el);
await el.readyPromise;
return el;
}
const disableMasCommerceService = () => {
document.querySelector(TAG_NAME_SERVICE)?.remove();
}
export { expect, sinon, initMasCommerceService, disableMasCommerceService };