generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
/
merch-subscription-panel.test.html.js
218 lines (192 loc) · 8.39 KB
/
merch-subscription-panel.test.html.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import { runTests } from '@web/test-runner-mocha';
import { expect } from '@esm-bundle/chai';
// Import mocks
import { mockFetch } from './mocks/fetch.js';
import { mockLana } from './mocks/lana.js';
import './spectrum.js';
import '../src/merch-quantity-select.js';
import '../src/merch-stock.js';
import '../src/merch-secure-transaction.js';
import '../src/merch-offer.js';
import '../src/merch-offer-select.js';
import '../src/merch-subscription-panel.js';
import { delay } from './utils.js';
import { mockIms } from './mocks/ims.js';
import { _$LE } from 'lit';
import { withWcs } from './mocks/wcs.js';
import { withLiterals } from './mocks/literals.js';
import mas from './mas.js';
import { getTemplateContent } from './utils.js';
const shouldSkipTests = sessionStorage.getItem('skipTests') === 'true';
const content = document.getElementById('content');
window.toggleOverlays = () => {
document.querySelectorAll('[data-overlay]').forEach((el) => {
el.style.backgroundImage = el.style.backgroundImage
? ''
: `url(/assets/${el.dataset.overlay})`;
});
};
runTests(async () => {
before(async () => {
// Activate mocks
mockLana();
await mockIms();
await mockFetch(withWcs, withLiterals);
await mas();
});
if (shouldSkipTests) {
return;
}
async function buildPanel(templates) {
const [merchSubscriptionPanel] = getTemplateContent(
'merch-subscription-panel',
);
const [merchSecureTransaction] = getTemplateContent(
'merch-secure-transaction',
);
merchSubscriptionPanel.append(merchSecureTransaction);
const promises = templates.map((template) => {
const [content] = getTemplateContent(template);
merchSubscriptionPanel.append(content);
return content.updateComplete;
});
content.appendChild(merchSubscriptionPanel);
await Promise.all([
...promises,
merchSubscriptionPanel.updateComplete,
merchSecureTransaction.updateComplete,
]);
await delay(100);
return merchSubscriptionPanel;
}
describe('component "merch-subscription-panel"', () => {
it('renders a panel with the first offer', async () => {
const panel = await buildPanel([
'merch-offer-select-cci',
'merch-stock',
]);
await delay(100);
const merchOfferSelect = panel.querySelector('merch-offer-select');
expect(
merchOfferSelect.querySelector('merch-offer').planType,
).to.eq('ABM');
});
it('renders a panel with monthly first and pre-selects ABM', async () => {
const panel = await buildPanel([
'merch-offer-select-cci-monthy-first',
]);
const merchOfferSelect = panel.querySelector('merch-offer-select');
expect(
merchOfferSelect.querySelector('merch-offer').planType,
).to.eq('M2M');
const [m2m, abm, puf] =
merchOfferSelect.querySelectorAll('merch-offer');
expect(m2m.selected).to.be.false;
expect(abm.selected).to.be.true;
puf.click();
await delay(50);
expect(m2m.selected).to.be.false;
expect(abm.selected).to.be.false;
expect(puf.selected).to.be.true;
});
it('renders with offer teaser', async () => {
const panel = await buildPanel(['merch-offer-select-cct']);
const merchOfferSelect = panel.querySelector('merch-offer-select');
expect(
merchOfferSelect
.querySelector('merch-offer[plan-type="PUF"]')
.shadowRoot.querySelector('slot[name="teaser"]')
.assignedElements()[0].innerText,
).to.eq('Save with the annual prepaid plan.');
});
it('renders team offers with tax text', async () => {
const panel = await buildPanel(['merch-offer-select-cct-tax']);
const merchOfferSelect = panel.querySelector('merch-offer-select');
expect(merchOfferSelect.textContent).to.match(/excl. tax/);
});
it('renders with quantity selector', async () => {
const [merchSubscriptionPanel] = getTemplateContent(
'merch-subscription-panel',
);
const [merchOfferSelect] = getTemplateContent(
'merch-offer-select-cct',
);
const [merchSecureTransaction] = getTemplateContent(
'merch-secure-transaction',
);
const [merchQuantitySelect] = getTemplateContent(
'merch-quantity-select',
);
merchSubscriptionPanel.append(
merchOfferSelect,
merchQuantitySelect,
merchSecureTransaction,
);
content.appendChild(merchSubscriptionPanel);
await Promise.all([
merchOfferSelect.updateComplete,
merchSubscriptionPanel.updateComplete,
merchQuantitySelect.updateComplete,
merchSecureTransaction.updateComplete,
]);
await delay(100);
expect(
merchSubscriptionPanel.shadowRoot
.querySelector('slot[name="footer"]')
.assignedElements()[0],
).to.eq(merchQuantitySelect);
merchQuantitySelect.defaultValue = 5;
await delay(50);
expect(
decodeURI(
merchSubscriptionPanel.shadowRoot.querySelector(
'[is="checkout-link"]',
).href,
),
).to.match(/items\[0\]\[q\]=5/);
});
it('renders cta with custom parameters', async () => {
const CTA_URL_SEGMENTATION =
'https://commerce.adobe.com/store/segmentation?ms=COM&ot=BASE&pa=ccsn_direct_individual&cli=adobe_com&ctx=fp&co=US&lang=en';
const CTA_PROMO_COMMITMENT =
'https://commerce.adobe.com/store/commitment?items%5B0%5D%5Bid%5D=257E1D82082387D152029F93C1030624&apc=blackfriday&cli=adobe_com&ctx=fp&co=US&lang=en';
const CTA_PROMO_COMMITMENT_Q3 =
'https://commerce.adobe.com/store/commitment?items%5B0%5D%5Bid%5D=257E1D82082387D152029F93C1030624&items%5B0%5D%5Bq%5D=3&apc=blackfriday&cli=adobe_com&ctx=fp&co=US&lang=en';
const CTA_PROMO_STOCK =
'https://commerce.adobe.com/store/commitment?items%5B0%5D%5Bid%5D=257E1D82082387D152029F93C1030624&items%5B0%5D%5Bq%5D=3&items%5B1%5D%5Bid%5D=3002E1908F4574F62C0A9ABA58196755&items%5B1%5D%5Bq%5D=1&apc=blackfriday&cli=adobe_com&ctx=fp&co=US&lang=en';
const panel = await buildPanel([
'merch-offer-select-promo',
'merch-quantity-select',
'merch-stock',
]);
const merchOfferSelect = panel.querySelector('merch-offer-select');
let cta = panel.shadowRoot.querySelector('a[is="checkout-link"]');
//renders initially a link with segmentation step
expect(cta?.href).to.eq(CTA_URL_SEGMENTATION);
merchOfferSelect.querySelector('merch-offer:nth-child(2)')?.click();
await delay(50);
cta = panel.shadowRoot.querySelector('a[is="checkout-link"]');
// after click changes link to commitment step with promo code
expect(cta?.href).to.eq(CTA_PROMO_COMMITMENT);
// changes quantity
const qs = panel.querySelector('merch-quantity-select');
qs.shadowRoot.querySelector('.picker-button').click();
await delay(100);
qs.shadowRoot
.querySelector('.popover')
?.querySelector('div:nth-child(3)')
.click();
await delay(50);
cta = panel.shadowRoot.querySelector('a[is="checkout-link"]');
expect(cta?.href).to.eq(CTA_PROMO_COMMITMENT_Q3);
//adds stock
const stock = panel
.querySelector('merch-stock')
.shadowRoot.querySelector('sp-checkbox');
stock.click();
await delay(50);
cta = panel.shadowRoot.querySelector('a[is="checkout-link"]');
expect(cta?.href).to.eq(CTA_PROMO_STOCK);
});
});
});