From 7a10e2e2de23f5b64d8485435a73a9ebe7bdeb56 Mon Sep 17 00:00:00 2001 From: mukherjeesudebi <122896925+mukherjeesudebi@users.noreply.github.com> Date: Thu, 4 May 2023 15:56:25 +0300 Subject: [PATCH] test: ensure _hasInputValue is reset on clear button interaction (#623) --- test/email-field-events.html | 29 +++++++++++++++++++++++++++++ test/integer-field-events.html | 29 +++++++++++++++++++++++++++++ test/number-field-events.html | 29 +++++++++++++++++++++++++++++ test/password-field-events.html | 29 +++++++++++++++++++++++++++++ test/text-area-events.html | 29 +++++++++++++++++++++++++++++ test/text-field-events.html | 29 +++++++++++++++++++++++++++++ 6 files changed, 174 insertions(+) diff --git a/test/email-field-events.html b/test/email-field-events.html index 9cd88569..e85f9f02 100644 --- a/test/email-field-events.html +++ b/test/email-field-events.html @@ -8,6 +8,7 @@ +
@@ -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; + }); + }); + }); }); }); diff --git a/test/integer-field-events.html b/test/integer-field-events.html index 6ecd8aff..f03d071a 100644 --- a/test/integer-field-events.html +++ b/test/integer-field-events.html @@ -8,6 +8,7 @@ + @@ -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; + }); + }); + }); }); }); diff --git a/test/number-field-events.html b/test/number-field-events.html index 1f6c9959..dc08b6f4 100644 --- a/test/number-field-events.html +++ b/test/number-field-events.html @@ -8,6 +8,7 @@ + @@ -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; + }); + }); + }); }); }); diff --git a/test/password-field-events.html b/test/password-field-events.html index 5d64c5a8..8d321348 100644 --- a/test/password-field-events.html +++ b/test/password-field-events.html @@ -8,6 +8,7 @@ + @@ -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; + }); + }); + }); }); }); diff --git a/test/text-area-events.html b/test/text-area-events.html index f1f8b2c7..27fcedb4 100644 --- a/test/text-area-events.html +++ b/test/text-area-events.html @@ -8,6 +8,7 @@ + @@ -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; + }); + }); + }); }); }); diff --git a/test/text-field-events.html b/test/text-field-events.html index e0c5df37..d789eb8f 100644 --- a/test/text-field-events.html +++ b/test/text-field-events.html @@ -8,6 +8,7 @@ + @@ -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; + }); + }); + }); }); });