Skip to content

Commit 3edb079

Browse files
authored
Merge pull request #697 from BY00565233/SURF-2009
test(hx-file-input): surf-2009
2 parents f87b6a3 + ac930ad commit 3edb079

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
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-file-input> component tests
5+
*
6+
* @type HXFileInputElement
7+
*
8+
*/
9+
describe('<hx-file-input> component tests', () => {
10+
const template = '<hx-file-input>';
11+
12+
describe('test instantiate element', () => {
13+
it('should be instantiated with hx-defined attribute', async () => {
14+
const component = /** @type {HXFileInputElement} */ 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 {HXFileInputElement} */ 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 {HXFileInputElement} */ 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 { HXFileInputElement } */ 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 { HXFileInputElement } */ 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 { HXFileInputElement } */ 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 { HXFileInputElement } */ 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; // IE11, Legacy Edge, and older browsers
68+
}
69+
});
70+
});
71+
72+
describe('verify Shadow DOM markup', () => {
73+
it('markup should contain a #hxFileInput <div>', async () => {
74+
const elSelector = 'div#hxFileInput';
75+
const id = 'hxFileInput';
76+
const component = /** @type { HXFileInputElement } */ await fixture(template);
77+
const shadow = component.shadowRoot;
78+
const query = shadow.querySelector(elSelector);
79+
const queryId = query.id;
80+
81+
expect(queryId).to.equal(id);
82+
});
83+
84+
it('markup should contain a #hxIcon', async () => {
85+
const elSelector = 'div#hxFileInput > #hxIcon';
86+
const id = 'hxIcon';
87+
const component = /** @type { HXFileInputElement } */ await fixture(template);
88+
const shadow = component.shadowRoot;
89+
const query = shadow.querySelector(elSelector);
90+
const queryId = query.id;
91+
92+
expect(queryId).to.equal(id);
93+
});
94+
95+
it('markup should contain a #hxLabel <span>', async () => {
96+
const elSelector = 'span#hxLabel';
97+
const id = 'hxLabel';
98+
const component = /** @type { HXFileInputElement } */ await fixture(template);
99+
const shadow = component.shadowRoot;
100+
const query = shadow.querySelector(elSelector);
101+
const queryId = query.id;
102+
103+
expect(queryId).to.equal(id);
104+
});
105+
});
106+
});
107+
108+
describe('test getters and setters', () => {
109+
it('should be able to set icon [icon="upload"]', async () => {
110+
const component = /** @type {HXFileInputElement} */ await fixture(template);
111+
const attrType = 'upload';
112+
113+
component.icon = attrType;
114+
const attr = component.hasAttribute('icon');
115+
const iconType = component.getAttribute('icon');
116+
117+
expect(attr).to.be.true;
118+
expect(iconType).to.equal(attrType);
119+
});
120+
});
121+
});

0 commit comments

Comments
 (0)