Skip to content

Commit 5db4d7d

Browse files
test(hx-icon test case): surf2011
1 parent cc7132d commit 5db4d7d

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

src/elements/hx-icon/index.spec.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { fixture, expect } from '@open-wc/testing';
2+
3+
/**
4+
* <hx-icon> component tests
5+
*
6+
* @type HXIconElement
7+
*
8+
*/
9+
describe('<hx-icon> component tests', () => {
10+
const template = '<hx-icon>';
11+
12+
describe('instantiate element', () => {
13+
it('should be instantiated with hx-defined attribute', async () => {
14+
const component = /** @type {HXIconElement} */ await fixture(template);
15+
const attr = component.hasAttribute('hx-defined');
16+
17+
expect(attr).to.be.true;
18+
});
19+
20+
it('should not be hidden', async () => {
21+
const component = /** @type {HXIconElement} */ await fixture(template);
22+
const prop = component.hidden;
23+
24+
expect(prop).to.be.false;
25+
});
26+
27+
it(`the rendered light DOM should NOT equal simple template ${template}`, async () => {
28+
const component = /** @type {HXIconElement} */ await fixture(template);
29+
30+
expect(component).lightDom.to.not.equal(template);
31+
});
32+
33+
});
34+
35+
describe('test Shadow DOM', () => {
36+
describe('verify render', () => {
37+
it('should have a static Shadow DOM', async function () {
38+
const component = /** @type { HXIconElement } */ await fixture(template);
39+
const shadow = component.shadowRoot.innerHTML;
40+
41+
expect(component).shadowDom.to.equal(shadow);
42+
});
43+
44+
it('should render the Shadow Root mode open', async () => {
45+
const component = /** @type { HXIconElement } */ await fixture(template);
46+
const mode = component.shadowRoot.mode;
47+
48+
expect(mode).to.equal('open');
49+
});
50+
});
51+
52+
describe('verify Shadow DOM markup', () => {
53+
it('markup should contain a #hxIcon <span>', async () => {
54+
const elSelector = 'span#hxIcon';
55+
const id = 'hxIcon';
56+
const component = /** @type { HXIconElement } */ await fixture(template);
57+
const shadow = component.shadowRoot;
58+
const query = shadow.querySelector(elSelector);
59+
const queryId = query.id;
60+
61+
expect(queryId).to.equal(id);
62+
});
63+
64+
it('markup should contain a #hxPath <path>', async () => {
65+
const elSelector = 'path#hxPath';
66+
const id = 'hxPath';
67+
const component = /** @type { HXIconElement } */ await fixture(template);
68+
const shadow = component.shadowRoot;
69+
const query = shadow.querySelector(elSelector);
70+
const queryId = query.id;
71+
72+
expect(queryId).to.equal(id);
73+
});
74+
});
75+
});
76+
77+
describe('test getters and setters', () => {
78+
it('should be able to set bell [type="bell"]', async () => {
79+
const component = /** @type {HXIconElement} */ await fixture(template);
80+
const attrType = 'bell';
81+
82+
component.type = attrType;
83+
const attr = component.hasAttribute('type');
84+
const fileType = component.getAttribute('type');
85+
86+
expect(attr).to.be.true;
87+
expect(fileType).to.equal(attrType);
88+
});
89+
});
90+
91+
});

0 commit comments

Comments
 (0)