generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
/
merch-card.mini-compare.test.html.js
111 lines (104 loc) · 4.09 KB
/
merch-card.mini-compare.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
// @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 } from './utils.js';
import { mockIms } from './mocks/ims.js';
import { withLiterals } from './mocks/literals.js';
import { withWcs } from './mocks/wcs.js';
import mas from './mas.js';
const skipTests = sessionStorage.getItem('skipTests');
runTests(async () => {
mockIms();
mockLana();
await mockFetch(withWcs, withLiterals);
await mas();
if (skipTests !== null) {
appendMiloStyles();
return;
}
describe('merch-card web component with mini-compare variant', () => {
it('mini-compare-chart should have same body slot heights', async () => {
const miniCompareCharts = document.querySelectorAll(
'merch-card[variant="mini-compare-chart"]',
);
await Promise.all(
[...miniCompareCharts].flatMap((card) => {
return [
card.updateComplete,
...[...card.querySelectorAll('[data-wcs-osi]')].map(
(osi) => osi.onceSettled(),
),
];
}),
);
const [card1Slots, card2Slots, card3Slots] = [
...miniCompareCharts,
].map((miniCompareChart) => {
const heights = [
'slot[name="heading-m"]',
'slot[name="body-m"]',
'slot[name="heading-m-price"]',
'slot[name="price-commitment"]',
'slot[name="offers"]',
'slot[name="promo-text"]',
'slot[name="callout-content"]',
'footer',
]
.map((selector) =>
Math.round(
window.getComputedStyle(
miniCompareChart.shadowRoot.querySelector(
selector,
),
).height,
),
)
.join(',');
return heights;
});
expect(card1Slots).to.not.contain('auto');
expect(card1Slots).to.equal(card2Slots);
expect(card2Slots).to.equal(card3Slots);
});
it('mini-compare-chart should have same height footer rows', async () => {
const miniCompareCharts = document.querySelectorAll(
'merch-card[variant="mini-compare-chart"]',
);
await Promise.all(
[...miniCompareCharts].map((card) => card.updateComplete),
);
const [card1Rows, card2Rows, card3Rows] = [
...miniCompareCharts,
].map((miniCompareChart) => {
const heights = new Array(5)
.fill()
.map((_, i) =>
Math.round(
window.getComputedStyle(
miniCompareChart.querySelector(
`.footer-row-cell:nth-child(${i + 1})`,
),
).height,
),
)
.join(',');
return heights;
});
expect(card1Rows).to.equal(card2Rows);
expect(card2Rows).to.equal(card3Rows);
});
it('mini-compare-chart should ', async () => {
const miniCompareChart = document.querySelector(
'merch-card[variant="mini-compare-chart"]',
);
miniCompareChart.removeEmptyRows();
expect(true, 'removing empty lines do not fail').to.be.true; // TODO improve the assertion
});
});
});