Skip to content

Commit

Permalink
test: ensure _hasInputValue is reset on clear button interaction (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
mukherjeesudebi authored May 4, 2023
1 parent 202917d commit 7a10e2e
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/email-field-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../vaadin-email-field.html">
<link rel="import" href="../../test-fixture/test-fixture.html">
<script src="../../iron-test-helpers/mock-interactions.js"></script>
</head>

<body>
Expand Down Expand Up @@ -71,6 +72,34 @@
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});

describe('with clear button', () => {
beforeEach(async() => {
emailField.clearButtonVisible = true;
});

describe('with user input', () => {
beforeEach(async() => {
input.value = 'foo';
input.dispatchEvent(new CustomEvent('input'));
hasInputValueChangedSpy.reset();
valueChangedSpy.reset();
});

it('should fire the event on clear button click', async() => {
emailField.$.clearButton.click();
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});

it('should fire the event on Esc', async() => {
input.focus();
MockInteractions.keyDownOn(input, 27, null, 'Escape');
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});
});
});
});
</script>
Expand Down
29 changes: 29 additions & 0 deletions test/integer-field-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../vaadin-integer-field.html">
<link rel="import" href="../../test-fixture/test-fixture.html">
<script src="../../iron-test-helpers/mock-interactions.js"></script>
</head>

<body>
Expand Down Expand Up @@ -71,6 +72,34 @@
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});

describe('with clear button', () => {
beforeEach(async() => {
integerField.clearButtonVisible = true;
});

describe('with user input', () => {
beforeEach(async() => {
input.value = '5';
input.dispatchEvent(new CustomEvent('input'));
hasInputValueChangedSpy.reset();
valueChangedSpy.reset();
});

it('should fire the event on clear button click', async() => {
integerField.$.clearButton.click();
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});

it('should fire the event on Esc', async() => {
input.focus();
MockInteractions.keyDownOn(input, 27, null, 'Escape');
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});
});
});
});
</script>
Expand Down
29 changes: 29 additions & 0 deletions test/number-field-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../vaadin-number-field.html">
<link rel="import" href="../../test-fixture/test-fixture.html">
<script src="../../iron-test-helpers/mock-interactions.js"></script>
</head>

<body>
Expand Down Expand Up @@ -71,6 +72,34 @@
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});

describe('with clear button', () => {
beforeEach(async() => {
numberField.clearButtonVisible = true;
});

describe('with user input', () => {
beforeEach(async() => {
input.value = '5';
input.dispatchEvent(new CustomEvent('input'));
hasInputValueChangedSpy.reset();
valueChangedSpy.reset();
});

it('should fire the event on clear button click', async() => {
numberField.$.clearButton.click();
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});

it('should fire the event on Esc', async() => {
input.focus();
MockInteractions.keyDownOn(input, 27, null, 'Escape');
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});
});
});
});
</script>
Expand Down
29 changes: 29 additions & 0 deletions test/password-field-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../vaadin-password-field.html">
<link rel="import" href="../../test-fixture/test-fixture.html">
<script src="../../iron-test-helpers/mock-interactions.js"></script>
</head>

<body>
Expand Down Expand Up @@ -71,6 +72,34 @@
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});

describe('with clear button', () => {
beforeEach(async() => {
passwordField.clearButtonVisible = true;
});

describe('with user input', () => {
beforeEach(async() => {
input.value = 'foo';
input.dispatchEvent(new CustomEvent('input'));
hasInputValueChangedSpy.reset();
valueChangedSpy.reset();
});

it('should fire the event on clear button click', async() => {
passwordField.$.clearButton.click();
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});

it('should fire the event on Esc', async() => {
input.focus();
MockInteractions.keyDownOn(input, 27, null, 'Escape');
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});
});
});
});
</script>
Expand Down
29 changes: 29 additions & 0 deletions test/text-area-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../vaadin-text-area.html">
<link rel="import" href="../../test-fixture/test-fixture.html">
<script src="../../iron-test-helpers/mock-interactions.js"></script>
</head>

<body>
Expand Down Expand Up @@ -71,6 +72,34 @@
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});

describe('with clear button', () => {
beforeEach(async() => {
textArea.clearButtonVisible = true;
});

describe('with user input', () => {
beforeEach(async() => {
input.value = 'foo';
input.dispatchEvent(new CustomEvent('input'));
hasInputValueChangedSpy.reset();
valueChangedSpy.reset();
});

it('should fire the event on clear button click', async() => {
textArea.$.clearButton.click();
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});

it('should fire the event on Esc', async() => {
input.focus();
MockInteractions.keyDownOn(input, 27, null, 'Escape');
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});
});
});
});
</script>
Expand Down
29 changes: 29 additions & 0 deletions test/text-field-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../vaadin-text-field.html">
<link rel="import" href="../../test-fixture/test-fixture.html">
<script src="../../iron-test-helpers/mock-interactions.js"></script>
</head>

<body>
Expand Down Expand Up @@ -71,6 +72,34 @@
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});

describe('with clear button', () => {
beforeEach(async() => {
textField.clearButtonVisible = true;
});

describe('with user input', () => {
beforeEach(async() => {
input.value = 'foo';
input.dispatchEvent(new CustomEvent('input'));
hasInputValueChangedSpy.reset();
valueChangedSpy.reset();
});

it('should fire the event on clear button click', async() => {
textField.$.clearButton.click();
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});

it('should fire the event on Esc', async() => {
input.focus();
MockInteractions.keyDownOn(input, 27, null, 'Escape');
expect(hasInputValueChangedSpy.calledOnce).to.be.true;
expect(hasInputValueChangedSpy.calledBefore(valueChangedSpy)).to.be.true;
});
});
});
});
});
</script>
Expand Down

0 comments on commit 7a10e2e

Please sign in to comment.