Skip to content

Commit 38823c4

Browse files
committed
test(hx-disclosure): add component tests and sauce builds
1 parent 17c9cf8 commit 38823c4

File tree

2 files changed

+196
-27
lines changed

2 files changed

+196
-27
lines changed

karma.sauce.config.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,46 @@
22
const { createDefaultConfig } = require('@open-wc/testing-karma');
33
const merge = require('deepmerge');
44

5-
const customLaunchers = {
6-
mac_firefox: {
7-
base: 'SauceLabs',
8-
browserName: 'firefox',
5+
/**
6+
* SauceLabs supports up to 5 browsers per test run.
7+
*/
8+
const batches = {
9+
mac_firefox: {
10+
base: 'SauceLabs',
11+
browserName: 'firefox',
912
platform: 'OS X 10.13',
1013
version: 'latest-1'
11-
},
12-
mac_safari: {
13-
base: 'SauceLabs',
14-
browserName: 'safari',
14+
},
15+
mac_safari: {
16+
base: 'SauceLabs',
17+
browserName: 'safari',
1518
platform: 'OS X 10.13',
1619
version: 'latest-1'
17-
},
18-
mac_chrome: {
19-
base: 'SauceLabs',
20-
browserName: 'chrome',
20+
},
21+
mac_chrome: {
22+
base: 'SauceLabs',
23+
browserName: 'chrome',
2124
platform: 'OS X 10.13',
2225
version: 'latest-1'
23-
},
24-
win_edge_legacy: {
25-
base: 'SauceLabs',
26-
browserName: 'microsoftedge',
27-
platform: 'Windows 10',
28-
version: '18.17763'
26+
},
27+
win_edge_legacy: {
28+
base: 'SauceLabs',
29+
browserName: 'microsoftedge',
30+
platform: 'Windows 10',
31+
version: '18.17763'
2932
},
3033
win_10_ie_11: {
3134
base: 'SauceLabs',
3235
browserName: 'internet explorer',
3336
platform: 'Windows 10',
3437
version: '11.285',
3538
},
36-
// win_edge_chromium: { // Current SL config only allows 5 browsers per test run
37-
// base: 'SauceLabs',
38-
// browserName: 'microsoftedge',
39-
// platform: 'Windows 10',
40-
// version: 'latest'
41-
// },
39+
// win_edge_chromium: {
40+
// base: 'SauceLabs',
41+
// browserName: 'microsoftedge',
42+
// platform: 'Windows 10',
43+
// version: 'latest-1'
44+
// },
4245
};
4346

4447
module.exports = config => {
@@ -65,13 +68,14 @@ module.exports = config => {
6568
moduleDirs: ['node_modules', 'dist'],
6669
},
6770
sauceLabs: {
68-
testName: 'HelixUI Component Unit Tests',
71+
testName: 'HelixUI Components - Browser Tests',
6972
public: "public restricted",
7073
recordVideo: false,
7174
recordLogs: false,
75+
build: process.env.TRAVIS_BUILD_NUMBER || Date.now(),
7276
},
73-
customLaunchers: customLaunchers,
74-
browsers: Object.keys(customLaunchers),
77+
customLaunchers: batches,
78+
browsers: Object.keys(batches),
7579
reporters: ['dots', 'saucelabs'],
7680
singleRun: true,
7781
browserDisconnectTimeout : 120000, // default 2000
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
import { fixture, oneEvent, expect } from '@open-wc/testing';
2+
3+
/**
4+
* <hx-disclosure> component tests
5+
*
6+
* @type HXDisclosureElement
7+
*
8+
*/
9+
describe('<hx-disclosure> component tests', () => {
10+
const template = '<hx-disclosure>';
11+
12+
describe('instantiate element', () => {
13+
it('should be instantiated with hx-defined attribute', async () => {
14+
const component = /** @type {HXDisclosureElement} */ 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 {HXDisclosureElement} */ 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 {HXDisclosureElement} */ await fixture(template);
29+
30+
expect(component).lightDom.to.not.equal(template);
31+
});
32+
33+
it(`should NOT have a Shadow DOM`, async () => {
34+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
35+
const shadow = component.shadowRoot;
36+
37+
expect(shadow).to.be.null;
38+
});
39+
});
40+
41+
describe('test $onConnect method', () => {
42+
it('should have aria-expanded attribute', async () => {
43+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
44+
const attr = component.hasAttribute('aria-expanded');
45+
46+
expect(attr).to.be.true;
47+
});
48+
49+
it('should have aria-expanded attribute default to false', async () => {
50+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
51+
const attr = component.getAttribute('aria-expanded');
52+
53+
expect(attr).to.be.equal(String(false));
54+
});
55+
56+
it('should default to null target', async () => {
57+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
58+
const targetProp = component.target;
59+
60+
expect(targetProp).to.be.null;
61+
});
62+
63+
it('should have role attribute default to button', async () => {
64+
const roleAttr = 'button';
65+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
66+
const attr = component.hasAttribute('role');
67+
const role = component.getAttribute('role');
68+
69+
expect(attr).to.be.true;
70+
expect(role).to.equal(roleAttr);
71+
});
72+
73+
it('should have tabindex attribute', async () => {
74+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
75+
const attr = component.hasAttribute('tabindex');
76+
77+
expect(attr).to.be.true;
78+
});
79+
80+
it('should have tabindex attribute default to 0', async () => {
81+
const tabDefault = "0";
82+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
83+
const attr = component.hasAttribute('tabindex');
84+
const attrValue = component.getAttribute('tabindex');
85+
86+
expect(attr).to.be.true;
87+
expect(attrValue).to.be.equal(tabDefault);
88+
});
89+
});
90+
91+
describe('test <hx-disclosure> getter and setter methods', () => {
92+
it('should have a default null target', async () => {
93+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
94+
const target = component.target;
95+
96+
expect(target).to.be.null;
97+
});
98+
});
99+
100+
describe('test adding event listeners', () => {
101+
describe('test click event listeners', () => {
102+
it('should fire a click event', async () => {
103+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
104+
const detail = { evt: 'clicked!'};
105+
const customEvent = new CustomEvent('click', { detail });
106+
107+
setTimeout(() => component.dispatchEvent(customEvent));
108+
const evt = await oneEvent(component, 'click');
109+
110+
expect(evt).to.equal(customEvent);
111+
expect(evt.detail).to.equal(detail);
112+
});
113+
114+
it('should add a keydown event listener', async () => {
115+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
116+
const detail = { evt: 'key down!'};
117+
const customEvent = new CustomEvent('keydown', { detail });
118+
119+
setTimeout(() => component.dispatchEvent(customEvent));
120+
const evt = await oneEvent(component, 'keydown');
121+
122+
expect(evt).to.equal(customEvent);
123+
expect(evt.detail).to.equal(detail);
124+
});
125+
126+
it('should add a keyup event listener', async () => {
127+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
128+
const detail = { evt: 'key up!'};
129+
const customEvent = new CustomEvent('keyup', { detail });
130+
131+
setTimeout(() => component.dispatchEvent(customEvent));
132+
const evt = await oneEvent(component, 'keyup');
133+
134+
expect(evt).to.equal(customEvent);
135+
expect(evt.detail).to.equal(detail);
136+
});
137+
});
138+
139+
describe('test target event listeners', () => {
140+
it('should be able to open target', async () => {
141+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
142+
const detail = { evt: 'open target!'};
143+
const customEvent = new CustomEvent('open', { detail });
144+
145+
setTimeout(() => component.dispatchEvent(customEvent));
146+
const evt = await oneEvent(component, 'open');
147+
148+
expect(evt).to.equal(customEvent);
149+
expect(evt.detail).to.equal(detail);
150+
});
151+
152+
it('should be able to close target', async () => {
153+
const component = /** @type {HXDisclosureElement} */ await fixture(template);
154+
const detail = { evt: 'close target!'};
155+
const customEvent = new CustomEvent('close', { detail });
156+
157+
setTimeout(() => component.dispatchEvent(customEvent));
158+
const evt = await oneEvent(component, 'close');
159+
160+
expect(evt).to.equal(customEvent);
161+
expect(evt.detail).to.equal(detail);
162+
});
163+
});
164+
});
165+
});

0 commit comments

Comments
 (0)