generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
/
merch-datasource.test.html.js
76 lines (64 loc) · 2.78 KB
/
merch-datasource.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
import { runTests } from '@web/test-runner-mocha';
import chai from '@esm-bundle/chai';
import chaiAsPromised from '@esm-bundle/chai-as-promised';
import { mockFetch } from './mocks/fetch.js';
import { withWcs } from './mocks/wcs.js';
import { withAem } from './mocks/aem.js';
import mas from './mas.js';
import { getTemplateContent } from './utils.js';
chai.use(chaiAsPromised);
const expect = chai.expect;
runTests(async () => {
const [cc, photoshop] = await fetch(
'mocks/sites/cf/fragments/search/default.json',
)
.then((res) => res.json())
.then(({ items }) => items);
await mas();
await customElements.whenDefined('merch-datasource');
const { cache } = document.createElement('merch-datasource');
describe('merch-datasource web component', () => {
let aemMock;
beforeEach(async () => {
[, aemMock] = await mockFetch(withWcs, withAem);
cache.clear();
});
it('has fragment cache', async () => {
expect(cache).to.exist;
expect(cache.has('/test')).to.false;
cache.add({ path: '/test', test: 1 });
expect(cache.has('/test')).to.true;
cache.clear();
expect(cache.has('/test')).to.false;
});
it('renders a merch card from cache', async () => {
cache.add(cc, photoshop);
const [ccCard, photoshopCard] = getTemplateContent('cards');
document.querySelector('main').append(ccCard, photoshopCard);
expect(aemMock.count).to.equal(0);
});
it('re-renders a card after clearing the cache', async () => {
const [, , ccCard] = getTemplateContent('cards'); //special offers students-and-teachers.
const dataSource = ccCard.querySelector('merch-datasource');
document.querySelector('main').append(ccCard);
await dataSource.updateComplete;
const before = ccCard.innerHTML;
ccCard.footerSlot.test = true;
await dataSource.refresh(true);
await dataSource.refresh(true); // for extra coverage
await dataSource.updateComplete;
const after = ccCard.innerHTML;
expect(before).to.equal(after);
expect(ccCard.footerSlot.test).to.undefined;
expect(aemMock.count).to.equal(2);
});
it('ignores incomplete markup', async () => {
const [, , , cardWithMissingPath] = getTemplateContent('cards');
const dataSource =
cardWithMissingPath.querySelector('merch-datasource');
document.querySelector('main').append(cardWithMissingPath);
await expect(dataSource.updateComplete).to.be.rejectedWith('datasource is not correctly configured',
);
});
});
});