generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
/
merch-card.test.html.js
147 lines (137 loc) · 5.76 KB
/
merch-card.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
// @ts-nocheck
import { runTests } from '@web/test-runner-mocha';
import { expect } from '@esm-bundle/chai';
import { mockLana } from './mocks/lana.js';
import { mockFetch } from './mocks/fetch.js';
import { mockConfig } from './mocks/config.js';
import '../src/merch-offer.js';
import '../src/merch-offer-select.js';
import '../src/merch-quantity-select.js';
import { appendMiloStyles, delay } from './utils.js';
import { mockIms } from './mocks/ims.js';
import { withWcs } from './mocks/wcs.js';
import mas from './mas.js';
const skipTests = sessionStorage.getItem('skipTests');
runTests(async () => {
mockIms();
mockLana();
await mockFetch(withWcs);
await mas();
if (skipTests !== null) {
appendMiloStyles();
return;
}
describe('merch-card web component', () => {
it('should exist in the HTML document', async () => {
expect(document.querySelector('merch-card')).to.exist;
});
it('should exist special offers card in HTML document', async () => {
expect(
document.querySelector('merch-card[variant="special-offers"]'),
).to.exist;
});
it('should display a merch-badge', async () => {
expect(
document
.querySelector('merch-card[variant="special-offers"]')
.shadowRoot.querySelector('.special-offers-badge'),
).to.exist;
});
it('should exist segment card in HTML document', async () => {
expect(document.querySelector('merch-card[variant="segment"]')).to
.exist;
});
it('should exist a plans card in HTML document', async () => {
expect(document.querySelector('merch-card[variant="plans"]')).to
.exist;
});
it('should exist an image card in HTML document', async () => {
expect(document.querySelector('merch-card[variant="image"]')).to
.exist;
});
it('should exist an inline heading card in HTML document', async () => {
expect(
document.querySelector('merch-card[variant="inline-heading"]'),
).to.exist;
});
it('should exist an inline heading card in HTML document with CTA button', async () => {
expect(
document.querySelector(
'merch-card[variant="inline-heading"] div[slot="footer"] a.con-button.blue',
),
).to.exist;
});
it('should have stock trial checkbox', async () => {
const plansCard = document.querySelector(
'merch-card[variant="plans"]',
);
const stockCheckbox =
plansCard.shadowRoot.getElementById('stock-checkbox');
expect(stockCheckbox).to.exist;
expect(plansCard.price.dataset.wcsOsi).to.equal('m2m');
expect(plansCard.checkoutLinks[0].dataset.wcsOsi).to.equal('m2m');
stockCheckbox.querySelector('input').click();
await delay(100);
expect(plansCard.checkoutLinks[0].dataset.wcsOsi).to.equal(
'm2m,stock-m2m',
);
});
it('should display an action menu on hover for catalog variant', async () => {
const catalogCard = document.querySelector(
'merch-card[variant="catalog"]',
);
catalogCard.dispatchEvent(
new MouseEvent('mouseover', { bubbles: true }),
);
await delay(100);
const shadowRoot = catalogCard.shadowRoot;
const actionMenu = shadowRoot.querySelector('.action-menu');
const actionMenuContent = shadowRoot.querySelector(
'.action-menu-content',
);
expect(actionMenu.classList.contains('invisible')).to.be.true;
expect(actionMenuContent.classList.contains('hidden')).to.be.true;
expect(actionMenu).to.exist;
expect(actionMenuContent).to.exist;
catalogCard.toggleActionMenu();
});
it('should have and interact with quantity-selector', async () => {
const plansCard = document.querySelector('merch-card[type="q-ty"]');
const quantitySelect = plansCard.querySelector(
'merch-quantity-select',
);
expect(quantitySelect).to.exist;
const inputField =
quantitySelect.shadowRoot.querySelector('.text-field-input');
inputField.value = '3';
const event = new KeyboardEvent('keyup', {
key: '3',
bubbles: true,
});
event.composedPath = () => [quantitySelect];
inputField.dispatchEvent(event);
await delay(100);
expect(quantitySelect.selectedValue).to.equal(3);
const button = plansCard.querySelector('.con-button');
expect(button.getAttribute('data-quantity')).to.equal('3');
});
});
it('should return title for special offer card', async () => {
const title = document.querySelector(
'merch-card[variant="special-offers"]',
).title;
expect(title).to.equal('INDIVIDUALS');
});
it('should return title for segment card', async () => {
const title = document.querySelector(
'merch-card[variant="segment"]',
).title;
expect(title).to.equal('Individuals');
});
it('should have custom border color for segment card', async () => {
const segmentCard = document.querySelector('merch-card[variant="segment"].custom-border-color');
const borderColor = segmentCard.getAttribute('border-color');
expect(borderColor).to.exist;
expect(borderColor).to.not.equal('');
});
});