From d0d4dc572d13e381d0a372bbc77323f7a8bd9735 Mon Sep 17 00:00:00 2001 From: Kyle Zhao Date: Tue, 4 Jun 2019 09:42:29 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20FEATURE:=20AMP=20form=20dirtiness?= =?UTF-8?q?=20indicator=20class=20(#22640)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * FEATURE: AMP form dirtiness indicator class This currently supports detecting the dirtiness of text-typed `` and `'; + form.insertAdjacentHTML('afterbegin', html); + textarea = form.querySelector('textarea'); + }); + + it('removes dirtiness class when textarea is in default state', () => { + changeInput(textarea, textarea.defaultValue); + expect(form).to.not.have.class(DIRTINESS_INDICATOR_CLASS); + }); + + it('removes dirtiness class when textarea is empty', () => { + changeInput(textarea, ''); + expect(form).to.not.have.class(DIRTINESS_INDICATOR_CLASS); + }); + + it('adds dirtiness class when textarea is changed', () => { + changeInput(textarea, 'changed'); + expect(form).to.have.class(DIRTINESS_INDICATOR_CLASS); + }); + }); + + describe('#onSubmitting', () => { + it('clears the dirtiness class', () => { + const input = doc.createElement('input'); + input.type = 'text'; + input.name = 'text'; + form.appendChild(input); + + changeInput(input, 'changed'); + dirtinessHandler.onSubmitting(); + + expect(form).to.not.have.class(DIRTINESS_INDICATOR_CLASS); + }); + }); + + describe('#onSubmitError', () => { + let input; + + beforeEach(() => { + input = doc.createElement('input'); + input.type = 'text'; + input.name = 'text'; + form.appendChild(input); + }); + + it('adds the dirtiness class if the form was dirty before submitting', () => { + changeInput(input, 'changed'); + dirtinessHandler.onSubmitting(); + dirtinessHandler.onSubmitError(); + + expect(form).to.have.class(DIRTINESS_INDICATOR_CLASS); + }); + + it('does not add the dirtiness class if the form was clean before submitting', () => { + changeInput(input, ''); + dirtinessHandler.onSubmitting(); + dirtinessHandler.onSubmitError(); + + expect(form).to.have.not.class(DIRTINESS_INDICATOR_CLASS); + }); + }); + + describe('#onSubmitSuccess', () => { + it('clears the dirtiness class', () => { + const input = doc.createElement('input'); + input.type = 'text'; + input.name = 'text'; + form.appendChild(input); + + changeInput(input, 'changed'); + dirtinessHandler.onSubmitting(); + dirtinessHandler.onSubmitSuccess(); + + expect(form).to.not.have.class(DIRTINESS_INDICATOR_CLASS); + }); + }); +});