Skip to content

Commit 7a10e2e

Browse files
test: ensure _hasInputValue is reset on clear button interaction (#623)
1 parent 202917d commit 7a10e2e

File tree

6 files changed

+174
-0
lines changed

6 files changed

+174
-0
lines changed

test/email-field-events.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
99
<link rel="import" href="../vaadin-email-field.html">
1010
<link rel="import" href="../../test-fixture/test-fixture.html">
11+
<script src="../../iron-test-helpers/mock-interactions.js"></script>
1112
</head>
1213

1314
<body>
@@ -71,6 +72,34 @@
7172
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
7273
});
7374
});
75+
76+
describe('with clear button', () => {
77+
beforeEach(async() => {
78+
emailField.clearButtonVisible = true;
79+
});
80+
81+
describe('with user input', () => {
82+
beforeEach(async() => {
83+
input.value = 'foo';
84+
input.dispatchEvent(new CustomEvent('input'));
85+
hasInputValueChangedSpy.reset();
86+
valueChangedSpy.reset();
87+
});
88+
89+
it('should fire the event on clear button click', async() => {
90+
emailField.$.clearButton.click();
91+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
92+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
93+
});
94+
95+
it('should fire the event on Esc', async() => {
96+
input.focus();
97+
MockInteractions.keyDownOn(input, 27, null, 'Escape');
98+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
99+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
100+
});
101+
});
102+
});
74103
});
75104
});
76105
</script>

test/integer-field-events.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
99
<link rel="import" href="../vaadin-integer-field.html">
1010
<link rel="import" href="../../test-fixture/test-fixture.html">
11+
<script src="../../iron-test-helpers/mock-interactions.js"></script>
1112
</head>
1213

1314
<body>
@@ -71,6 +72,34 @@
7172
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
7273
});
7374
});
75+
76+
describe('with clear button', () => {
77+
beforeEach(async() => {
78+
integerField.clearButtonVisible = true;
79+
});
80+
81+
describe('with user input', () => {
82+
beforeEach(async() => {
83+
input.value = '5';
84+
input.dispatchEvent(new CustomEvent('input'));
85+
hasInputValueChangedSpy.reset();
86+
valueChangedSpy.reset();
87+
});
88+
89+
it('should fire the event on clear button click', async() => {
90+
integerField.$.clearButton.click();
91+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
92+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
93+
});
94+
95+
it('should fire the event on Esc', async() => {
96+
input.focus();
97+
MockInteractions.keyDownOn(input, 27, null, 'Escape');
98+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
99+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
100+
});
101+
});
102+
});
74103
});
75104
});
76105
</script>

test/number-field-events.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
99
<link rel="import" href="../vaadin-number-field.html">
1010
<link rel="import" href="../../test-fixture/test-fixture.html">
11+
<script src="../../iron-test-helpers/mock-interactions.js"></script>
1112
</head>
1213

1314
<body>
@@ -71,6 +72,34 @@
7172
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
7273
});
7374
});
75+
76+
describe('with clear button', () => {
77+
beforeEach(async() => {
78+
numberField.clearButtonVisible = true;
79+
});
80+
81+
describe('with user input', () => {
82+
beforeEach(async() => {
83+
input.value = '5';
84+
input.dispatchEvent(new CustomEvent('input'));
85+
hasInputValueChangedSpy.reset();
86+
valueChangedSpy.reset();
87+
});
88+
89+
it('should fire the event on clear button click', async() => {
90+
numberField.$.clearButton.click();
91+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
92+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
93+
});
94+
95+
it('should fire the event on Esc', async() => {
96+
input.focus();
97+
MockInteractions.keyDownOn(input, 27, null, 'Escape');
98+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
99+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
100+
});
101+
});
102+
});
74103
});
75104
});
76105
</script>

test/password-field-events.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
99
<link rel="import" href="../vaadin-password-field.html">
1010
<link rel="import" href="../../test-fixture/test-fixture.html">
11+
<script src="../../iron-test-helpers/mock-interactions.js"></script>
1112
</head>
1213

1314
<body>
@@ -71,6 +72,34 @@
7172
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
7273
});
7374
});
75+
76+
describe('with clear button', () => {
77+
beforeEach(async() => {
78+
passwordField.clearButtonVisible = true;
79+
});
80+
81+
describe('with user input', () => {
82+
beforeEach(async() => {
83+
input.value = 'foo';
84+
input.dispatchEvent(new CustomEvent('input'));
85+
hasInputValueChangedSpy.reset();
86+
valueChangedSpy.reset();
87+
});
88+
89+
it('should fire the event on clear button click', async() => {
90+
passwordField.$.clearButton.click();
91+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
92+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
93+
});
94+
95+
it('should fire the event on Esc', async() => {
96+
input.focus();
97+
MockInteractions.keyDownOn(input, 27, null, 'Escape');
98+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
99+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
100+
});
101+
});
102+
});
74103
});
75104
});
76105
</script>

test/text-area-events.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
99
<link rel="import" href="../vaadin-text-area.html">
1010
<link rel="import" href="../../test-fixture/test-fixture.html">
11+
<script src="../../iron-test-helpers/mock-interactions.js"></script>
1112
</head>
1213

1314
<body>
@@ -71,6 +72,34 @@
7172
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
7273
});
7374
});
75+
76+
describe('with clear button', () => {
77+
beforeEach(async() => {
78+
textArea.clearButtonVisible = true;
79+
});
80+
81+
describe('with user input', () => {
82+
beforeEach(async() => {
83+
input.value = 'foo';
84+
input.dispatchEvent(new CustomEvent('input'));
85+
hasInputValueChangedSpy.reset();
86+
valueChangedSpy.reset();
87+
});
88+
89+
it('should fire the event on clear button click', async() => {
90+
textArea.$.clearButton.click();
91+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
92+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
93+
});
94+
95+
it('should fire the event on Esc', async() => {
96+
input.focus();
97+
MockInteractions.keyDownOn(input, 27, null, 'Escape');
98+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
99+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
100+
});
101+
});
102+
});
74103
});
75104
});
76105
</script>

test/text-field-events.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
99
<link rel="import" href="../vaadin-text-field.html">
1010
<link rel="import" href="../../test-fixture/test-fixture.html">
11+
<script src="../../iron-test-helpers/mock-interactions.js"></script>
1112
</head>
1213

1314
<body>
@@ -71,6 +72,34 @@
7172
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
7273
});
7374
});
75+
76+
describe('with clear button', () => {
77+
beforeEach(async() => {
78+
textField.clearButtonVisible = true;
79+
});
80+
81+
describe('with user input', () => {
82+
beforeEach(async() => {
83+
input.value = 'foo';
84+
input.dispatchEvent(new CustomEvent('input'));
85+
hasInputValueChangedSpy.reset();
86+
valueChangedSpy.reset();
87+
});
88+
89+
it('should fire the event on clear button click', async() => {
90+
textField.$.clearButton.click();
91+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
92+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
93+
});
94+
95+
it('should fire the event on Esc', async() => {
96+
input.focus();
97+
MockInteractions.keyDownOn(input, 27, null, 'Escape');
98+
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
99+
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
100+
});
101+
});
102+
});
74103
});
75104
});
76105
</script>

0 commit comments

Comments
 (0)