From 57f16c23ee94b05d132574a6b5980a65e7db7f2f Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Sat, 13 Oct 2018 12:42:33 +0100 Subject: [PATCH] Finish up e2e tests for text elements --- cypress/integration/text_element_spec.js | 64 +++++++++++++++++++++++- public/test/text.html | 36 ++++++------- 2 files changed, 76 insertions(+), 24 deletions(-) diff --git a/cypress/integration/text_element_spec.js b/cypress/integration/text_element_spec.js index cb5a490..caab333 100644 --- a/cypress/integration/text_element_spec.js +++ b/cypress/integration/text_element_spec.js @@ -52,6 +52,32 @@ describe('Choices - text element', () => { }); }); + describe('editing choices', () => { + beforeEach(() => { + cy.get('[data-test-hook=basic]') + .find('.choices__input--cloned') + .type(textInput) + .type('{enter}'); + }); + + describe('pressing back space', () => { + it('allows me to change my entry', () => { + cy.get('[data-test-hook=basic]') + .find('.choices__input--cloned') + .type('{backspace}') + .type('-edited') + .type('{enter}'); + + cy.get('[data-test-hook=basic]') + .find('.choices__list--multiple .choices__item') + .last() + .should($choice => { + expect($choice.data('value')).to.equal(`${textInput}-edited`); + }); + }); + }); + }); + describe('removing choices', () => { beforeEach(() => { cy.get('[data-test-hook=basic]') @@ -162,10 +188,10 @@ describe('Choices - text element', () => { .type('{enter}'); cy.get('[data-test-hook=regex-filter]') - .find('.choices__list .choices__item') + .find('.choices__list--multiple .choices__item') .last() .should($choice => { - expect($choice).to.contain(input); + expect($choice.text().trim()).to.equal(input); }); }); }); @@ -200,6 +226,16 @@ describe('Choices - text element', () => { expect($choice.data('value')).to.equal(`before-${textInput}-after`); }); }); + + it('displays just the inputted value to the user', () => { + cy.get('[data-test-hook=prepend-append]') + .find('.choices__list--multiple .choices__item') + .last() + .should($choice => { + expect($choice.text()).to.not.contain(`before-${textInput}-after`); + expect($choice.text()).to.contain(textInput); + }); + }); }); describe('disabled', () => { @@ -209,5 +245,29 @@ describe('Choices - text element', () => { .should('be.disabled'); }); }); + + describe('pre-populated choices', () => { + it('pre-populates choices', () => { + cy.get('[data-test-hook=prepopulated]') + .find('.choices__list--multiple .choices__item') + .should($choices => { + expect($choices.length).to.equal(2); + }); + + cy.get('[data-test-hook=prepopulated]') + .find('.choices__list--multiple .choices__item') + .first() + .should($choice => { + expect($choice.text().trim()).to.equal('Josh Johnson'); + }); + + cy.get('[data-test-hook=prepopulated]') + .find('.choices__list--multiple .choices__item') + .last() + .should($choice => { + expect($choice.text().trim()).to.equal('Joe Bloggs'); + }); + }); + }); }); }); diff --git a/public/test/text.html b/public/test/text.html index 1b4c189..ec613e5 100644 --- a/public/test/text.html +++ b/public/test/text.html @@ -39,10 +39,6 @@
-

Text inputs

@@ -74,14 +70,10 @@
-
- -

Multiple select input

- -
- -

Single select input

- +
+ + +
- - - - - -