Skip to content

Commit 8b38cef

Browse files
committed
test: use vaadin testing helpers
1 parent 6b0cfe4 commit 8b38cef

File tree

5 files changed

+26
-80
lines changed

5 files changed

+26
-80
lines changed

packages/vaadin-radio-button/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@
6565
"devDependencies": {
6666
"@esm-bundle/chai": "^4.1.5",
6767
"@open-wc/rollup-plugin-html": "^1.2.5",
68-
"@open-wc/testing-helpers": "^1.8.12",
6968
"@polymer/iron-component-page": "^4.0.0",
70-
"@polymer/iron-test-helpers": "^3.0.0",
69+
"@vaadin/testing-helpers": "^0.1.0",
7170
"@web/dev-server": "^0.1.3",
7271
"@web/test-runner": "^0.11.7",
7372
"@web/test-runner-saucelabs": "^0.3.3",

packages/vaadin-radio-button/test/helpers.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
import { keyDownOn, keyUpOn } from '@polymer/iron-test-helpers/mock-interactions.js';
2-
3-
/**
4-
* Helper which mimics the way how Polymer <test-fixture> works.
5-
* Use `document.importNode` to ensure proper upgrade timings.
6-
*/
7-
export const fixtureSync = (html) => {
8-
const tpl = document.createElement('template');
9-
tpl.innerHTML = html;
10-
const div = document.createElement('div');
11-
div.appendChild(document.importNode(tpl.content, true));
12-
const el = div.firstElementChild;
13-
document.body.appendChild(el);
14-
return el;
15-
};
16-
171
export const down = (node) => {
182
node.dispatchEvent(new CustomEvent('down'));
193
};
@@ -22,36 +6,6 @@ export const up = (node) => {
226
node.dispatchEvent(new CustomEvent('up'));
237
};
248

25-
export const focusout = (node, composed = true) => {
26-
const event = new CustomEvent('focusout', { bubbles: true, composed });
27-
node.dispatchEvent(event);
28-
};
29-
30-
export const focusin = (node) => {
31-
const event = new CustomEvent('focusin', { bubbles: true, composed: true });
32-
node.dispatchEvent(event);
33-
};
34-
35-
export const arrowDown = (target) => {
36-
keyDownOn(target, 40);
37-
keyUpOn(target, 40);
38-
};
39-
40-
export const arrowRight = (target) => {
41-
keyDownOn(target, 39);
42-
keyUpOn(target, 39);
43-
};
44-
45-
export const arrowLeft = (target) => {
46-
keyDownOn(target, 37);
47-
keyUpOn(target, 37);
48-
};
49-
50-
export const arrowUp = (target) => {
51-
keyDownOn(target, 38);
52-
keyUpOn(target, 38);
53-
};
54-
559
export const visible = (e) => {
5610
const rect = e.getBoundingClientRect();
5711
return !!(rect.width && rect.height);

packages/vaadin-radio-button/test/radio-button.test.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync, nextFrame } from '@open-wc/testing-helpers';
32
import sinon from 'sinon';
4-
import { keyDownOn, keyUpOn, touchstart, touchend } from '@polymer/iron-test-helpers/mock-interactions.js';
3+
import { fixtureSync, nextFrame, space, spaceKeyDown, spaceKeyUp, touchstart, touchend } from '@vaadin/testing-helpers';
54
import { down, up } from './helpers.js';
65
import '../vaadin-radio-button.js';
76

@@ -103,8 +102,7 @@ describe('radio-button', () => {
103102
});
104103

105104
it('should set checked on space keyup', () => {
106-
keyDownOn(radio, 32);
107-
keyUpOn(radio, 32);
105+
space(radio);
108106
expect(radio.checked).to.be.true;
109107
});
110108
});
@@ -132,21 +130,19 @@ describe('radio-button', () => {
132130
});
133131

134132
it('should not set checked on space keyup when disabled', () => {
135-
keyDownOn(radio, 32);
136-
keyUpOn(radio, 32);
133+
space(radio);
137134
expect(radio.checked).to.be.false;
138135
});
139136
});
140137

141138
describe('active attribute', () => {
142139
it('should have active attribute on space keydown', () => {
143-
keyDownOn(radio, 32);
140+
spaceKeyDown(radio);
144141
expect(radio.hasAttribute('active')).to.be.true;
145142
});
146143

147144
it('should not have active attribute on space keyup', () => {
148-
keyDownOn(radio, 32);
149-
keyUpOn(radio, 32);
145+
space(radio);
150146
expect(radio.hasAttribute('active')).to.be.false;
151147
});
152148
});
@@ -179,15 +175,13 @@ describe('radio-button', () => {
179175
});
180176

181177
it('should be called on space keyup', () => {
182-
keyDownOn(radio, 32);
183-
keyUpOn(radio, 32);
178+
space(radio);
184179
expect(spy.calledOnce).to.be.true;
185180
});
186181

187182
it('should not be called on space keyup when disabled', () => {
188183
radio.disabled = true;
189-
keyDownOn(radio, 32);
190-
keyUpOn(radio, 32);
184+
space(radio);
191185
expect(spy.called).to.be.false;
192186
});
193187
});
@@ -218,9 +212,10 @@ describe('radio-button', () => {
218212
});
219213

220214
it('should fire on space keyup', () => {
221-
keyDownOn(radio, 32);
215+
spaceKeyDown(radio);
222216
expect(spy.called).to.be.false;
223-
keyUpOn(radio, 32);
217+
218+
spaceKeyUp(radio);
224219
expect(spy.calledOnce).to.be.true;
225220
});
226221

packages/vaadin-radio-button/test/radio-group.test.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { aTimeout, nextFrame } from '@open-wc/testing-helpers';
32
import sinon from 'sinon';
4-
import { arrowDown, arrowLeft, arrowRight, arrowUp, fixtureSync, focusin, focusout, visible } from './helpers.js';
3+
import {
4+
arrowDown,
5+
arrowLeft,
6+
arrowRight,
7+
arrowUp,
8+
aTimeout,
9+
fixtureSync,
10+
focusin,
11+
focusout,
12+
nextFrame
13+
} from '@vaadin/testing-helpers';
14+
import { visible } from './helpers.js';
515
import '../vaadin-radio-group.js';
616

717
describe('radio-group', () => {
@@ -20,10 +30,6 @@ describe('radio-group', () => {
2030
buttons = group._radioButtons;
2131
});
2232

23-
afterEach(() => {
24-
group.remove();
25-
});
26-
2733
describe('custom element definition', () => {
2834
let tagName;
2935

@@ -503,7 +509,7 @@ describe('radio-group', () => {
503509
const spy = sinon.spy();
504510
group.addEventListener('invalid-changed', spy);
505511
group.required = true;
506-
focusout(group, true);
512+
focusout(group);
507513
expect(spy.calledOnce).to.be.true;
508514
});
509515

@@ -614,10 +620,6 @@ describe('radio-group initial value', () => {
614620
buttons = group._radioButtons;
615621
});
616622

617-
afterEach(() => {
618-
group.remove();
619-
});
620-
621623
it('should set the value based on the initially checked radio button', () => {
622624
expect(group.value).to.be.equal('2');
623625
});
@@ -676,10 +678,6 @@ describe('radio-group helper slot', () => {
676678
group._observer.flush();
677679
});
678680

679-
afterEach(() => {
680-
group.remove();
681-
});
682-
683681
it('should have has-helper attribute when slotted helper is present', () => {
684682
expect(group.hasAttribute('has-helper')).to.be.true;
685683
});

packages/vaadin-radio-button/test/visual/default.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
</div>
4646

4747
<script type="module">
48-
import { keyDownOn } from '@polymer/iron-test-helpers/mock-interactions.js';
48+
import { focusin, keyDownOn } from '@vaadin/testing-helpers';
4949

5050
(async () => {
5151
const theme = window.location.search.replace(/.*theme=(\w+).*/, '$1') || 'lumo';
5252

5353
await import('../../theme/' + theme + '/vaadin-radio-group.js');
5454

5555
keyDownOn(document.body, 9);
56-
document.getElementById('radio').dispatchEvent(new CustomEvent('focusin', { composed: true, bubbles: true }));
56+
focusin(document.getElementById('radio'));
5757

5858
window.requestAnimationFrame(() => {
5959
document.getElementById('tests').dataset.ready = true;

0 commit comments

Comments
 (0)