Skip to content

Commit e1716c0

Browse files
test(hx-modal): surf2014
1 parent 54f5256 commit e1716c0

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import { fixture, oneEvent, expect } from '@open-wc/testing';
2+
3+
/**
4+
* <hx-modal> component tests
5+
*
6+
* @type HXModalElement
7+
*
8+
*/
9+
describe('<hx-modal> component tests', () => {
10+
const template = '<hx-modal>';
11+
12+
describe('test instantiate element', () => {
13+
it('should be instantiated with hx-defined attribute', async () => {
14+
const component = /** @type {HXModalElement} */ 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 {HXModalElement} */ 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 {HXModalElement} */ 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 { HXModalElement } */ 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 { HXModalElement } */ 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 { HXModalElement } */ 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 { HXModalElement } */ 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 #hxBackdrop <div>', async () => {
75+
const elSelector = 'div#hxBackdrop';
76+
const id = 'hxBackdrop';
77+
const component = /** @type { HXModalElement } */ 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 #hxModal <div>', async () => {
86+
const elSelector = 'div#hxModal';
87+
const id = 'hxModal';
88+
const component = /** @type { HXModalElement } */ await fixture(template);
89+
const shadow = component.shadowRoot;
90+
const query = shadow.querySelector(elSelector);
91+
const queryId = query.id;
92+
93+
expect(queryId).to.equal(id);
94+
});
95+
96+
it('markup should contain a #hxClose button', async () => {
97+
const elSelector = 'button#hxClose';
98+
const id = 'hxClose';
99+
const component = /** @type { HXModalElement } */ await fixture(template);
100+
const shadow = component.shadowRoot;
101+
const query = shadow.querySelector(elSelector);
102+
const queryId = query.id;
103+
104+
expect(queryId).to.equal(id);
105+
});
106+
107+
it('markup should contain a #hxClose button with a times type <hx-icon>', async () => {
108+
const elSelector = 'button#hxClose > hx-icon';
109+
const iconType = 'times';
110+
const component = /** @type { HXModalElement } */ await fixture(template);
111+
const shadow = component.shadowRoot;
112+
const query = shadow.querySelector(elSelector);
113+
const queryType = query.type;
114+
115+
expect(queryType).to.equal(iconType);
116+
});
117+
118+
it('markup should contain a #hxContent <div>', async () => {
119+
const elSelector = 'div#hxContent';
120+
const id = 'hxContent';
121+
const component = /** @type { HXModalElement } */ await fixture(template);
122+
const shadow = component.shadowRoot;
123+
const query = shadow.querySelector(elSelector);
124+
const queryId = query.id;
125+
126+
expect(queryId).to.equal(id);
127+
});
128+
});
129+
});
130+
131+
describe('test getters and setters', () => {
132+
it('should be able to open', async () => {
133+
const component = /** @type {HXModalElement} */ await fixture(template);
134+
component.open = true;
135+
const attr = component.hasAttribute('open');
136+
137+
expect(attr).to.be.true;
138+
});
139+
});
140+
141+
describe('test for click event listener', () => {
142+
it('should fire a click event', async () => {
143+
const component = /** @type { HXModalElement } */ await fixture(template);
144+
const detail = { evt: 'clicked!'};
145+
const customEvent = new CustomEvent('click', { detail });
146+
147+
setTimeout(() => component.dispatchEvent(customEvent));
148+
const evt = await oneEvent(component, 'click');
149+
150+
expect(evt).to.equal(customEvent);
151+
expect(evt.detail).to.equal(detail);
152+
});
153+
});
154+
});

0 commit comments

Comments
 (0)