Skip to content

Commit fb37246

Browse files
test(hx-pill test cases): surf2015
1 parent 4863d93 commit fb37246

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

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

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { fixture, oneEvent, expect } from '@open-wc/testing';
2+
3+
/**
4+
* <hx-pill> component tests
5+
*
6+
* @type HXPillElement
7+
*
8+
*/
9+
describe('<hx-pill> component tests', () => {
10+
const template = '<hx-pill>';
11+
12+
describe('test instantiate element', () => {
13+
it('should be instantiated with hx-defined attribute', async () => {
14+
const component = /** @type {HXPillElement} */ 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 {HXPillElement} */ 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 {HXPillElement} */ 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 { HXPillElement } */ 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 { HXPillElement } */ await fixture(template);
46+
const mode = component.shadowRoot.mode;
47+
48+
expect(mode).to.equal('open');
49+
});
50+
51+
it('should have a single <slot>', async () => {
52+
const component = /** @type { HXPillElement } */ await fixture(template);
53+
const shadow = component.shadowRoot;
54+
const query = shadow.querySelectorAll('slot');
55+
const len = query.length;
56+
57+
expect(len).to.be.equal(1);
58+
});
59+
60+
it('should have an unnamed <slot>', async () => {
61+
const component = /** @type { HXPillElement } */ await fixture(template);
62+
const name = component.slot;
63+
64+
if ( name !== null ) {
65+
expect(name).to.be.equal('');
66+
} else {
67+
expect(name).to.be.null;
68+
}
69+
});
70+
});
71+
72+
describe('verify Shadow DOM markup', () => {
73+
74+
it('markup should contain a #hxDismiss button', async () => {
75+
const elSelector = 'button#hxDismiss';
76+
const id = 'hxDismiss';
77+
const component = /** @type { HXPillElement } */ await fixture(template);
78+
const shadow = component.shadowRoot;
79+
const query = shadow.querySelector(elSelector);
80+
const queryId = query.id;
81+
82+
expect(queryId).to.equal(id);
83+
});
84+
85+
it('markup should contain a #hxDismiss button with a times type <hx-icon>', async () => {
86+
const elSelector = 'button#hxDismiss > span > hx-icon';
87+
const iconType = 'times';
88+
const component = /** @type { HXPillElement } */ await fixture(template);
89+
const shadow = component.shadowRoot;
90+
const query = shadow.querySelector(elSelector);
91+
const queryType = query.type;
92+
93+
expect(queryType).to.equal(iconType);
94+
});
95+
});
96+
});
97+
98+
describe('test getters and setters', () => {
99+
it('should be able to persist', async () => {
100+
const component = /** @type {HXPillElement} */ await fixture(template);
101+
component.persist = true;
102+
const attr = component.hasAttribute('persist');
103+
104+
expect(attr).to.be.true;
105+
});
106+
});
107+
108+
describe('test for click event listener', () => {
109+
it('should fire a click event', async () => {
110+
const component = /** @type { HXPillElement } */ await fixture(template);
111+
const detail = { evt: 'clicked!'};
112+
const customEvent = new CustomEvent('click', { detail });
113+
114+
setTimeout(() => component.dispatchEvent(customEvent));
115+
const evt = await oneEvent(component, 'click');
116+
117+
expect(evt).to.equal(customEvent);
118+
expect(evt.detail).to.equal(detail);
119+
});
120+
});
121+
});

0 commit comments

Comments
 (0)