From 92cfd989ff5456e89e8a0f7931d1b1bc71bce57d Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Wed, 17 Oct 2018 22:36:37 +0100 Subject: [PATCH] Add search tests + refactor tests --- cypress/integration/select-multiple.spec.js | 121 ++++++++++++++---- cypress/integration/select-one.spec.js | 103 ++++++++++++--- cypress/integration/text.spec.js | 132 ++++++++++---------- public/test/select-multiple.html | 43 +++++-- public/test/select-one.html | 27 +++- public/test/text.html | 17 ++- 6 files changed, 318 insertions(+), 125 deletions(-) diff --git a/cypress/integration/select-multiple.spec.js b/cypress/integration/select-multiple.spec.js index 942a725..7876889 100644 --- a/cypress/integration/select-multiple.spec.js +++ b/cypress/integration/select-multiple.spec.js @@ -5,13 +5,13 @@ describe('Choices - select multiple', () => { describe('configs', () => { describe('basic', () => { - describe('selecting choices', () => { - beforeEach(() => { - cy.get('[data-test-hook=basic]') - .find('.choices__input--cloned') - .focus(); - }); + beforeEach(() => { + cy.get('[data-test-hook=basic]') + .find('.choices__input--cloned') + .focus(); + }); + describe('selecting choices', () => { describe('focusing on text input', () => { const selectedChoiceText = 'Dropdown item 1'; @@ -61,7 +61,7 @@ describe('Choices - select multiple', () => { } }); - it('displays dropdown prompt', () => { + it('displays "no choices to choose" prompt', () => { cy.get('[data-test-hook=basic]') .find('.choices__list--dropdown') .should('be.visible') @@ -117,10 +117,6 @@ describe('Choices - select multiple', () => { describe('removing choices', () => { beforeEach(() => { - cy.get('[data-test-hook=basic]') - .find('.choices__input--cloned') - .focus(); - cy.get('[data-test-hook=basic]') .find('.choices__list--dropdown .choices__list') .children() @@ -128,7 +124,7 @@ describe('Choices - select multiple', () => { .click(); }); - describe('pressing backspace', () => { + describe('on backspace', () => { it('removes last choice', () => { cy.get('[data-test-hook=basic]') .find('.choices__input--cloned') @@ -140,21 +136,87 @@ describe('Choices - select multiple', () => { .should('have.length', 0); }); }); + }); - describe('remove button', () => { - it('removes last choice', () => { - cy.get('[data-test-hook=basic]') - .find('.choices__list--multiple .choices__item') - .last() - .find('.choices__button') - .focus() - .click(); + describe('searching choices', () => { + describe('on input', () => { + describe('searching by label', () => { + it('displays choices filtered on inputted value', () => { + cy.get('[data-test-hook=basic]') + .find('.choices__input--cloned') + .type('item 2'); - cy.get('[data-test-hook=basic]') - .find('.choices__list--multiple') - .children() - .should('have.length', 0); + cy.get('[data-test-hook=basic]') + .find('.choices__list--dropdown .choices__list') + .children() + .first() + .should($choice => { + expect($choice.text().trim()).to.equal('Dropdown item 2'); + }); + }); }); + + describe('searching by value', () => { + it('displays choices filtered on inputted value', () => { + cy.get('[data-test-hook=basic]') + .find('.choices__input--cloned') + .type('find me'); + + cy.get('[data-test-hook=basic]') + .find('.choices__list--dropdown .choices__list') + .children() + .first() + .should($choice => { + expect($choice.text().trim()).to.equal('Dropdown item 3'); + }); + }); + }); + + describe('no results found', () => { + it('displays "no results found" prompt', () => { + cy.get('[data-test-hook=basic]') + .find('.choices__input--cloned') + .type('faergge'); + + cy.get('[data-test-hook=basic]') + .find('.choices__list--dropdown') + .should('be.visible') + .should($dropdown => { + const dropdownText = $dropdown.text().trim(); + expect(dropdownText).to.equal('No results found'); + }); + }); + }); + }); + }); + }); + + describe('remove button', () => { + beforeEach(() => { + cy.get('[data-test-hook=remove-button]') + .find('.choices__input--cloned') + .focus(); + + cy.get('[data-test-hook=remove-button]') + .find('.choices__list--dropdown .choices__list') + .children() + .last() + .click(); + }); + + describe('on click', () => { + it('removes respective choice', () => { + cy.get('[data-test-hook=remove-button]') + .find('.choices__list--multiple .choices__item') + .last() + .find('.choices__button') + .focus() + .click(); + + cy.get('[data-test-hook=remove-button]') + .find('.choices__list--multiple') + .children() + .should('have.length', 0); }); }); }); @@ -202,7 +264,7 @@ describe('Choices - select multiple', () => { } }); - it('shows dropdown prompt once limit has been reached', () => { + it('displays "limit reached" prompt', () => { cy.get('[data-test-hook=selection-limit]') .find('.choices__list--dropdown') .should('be.visible') @@ -261,4 +323,13 @@ describe('Choices - select multiple', () => { }); }); }); + + describe('render choice limit', () => { + it('only displays given number of choices in the dropdown', () => { + cy.get('[data-test-hook=render-choice-limit]') + .find('.choices__list--dropdown .choices__list') + .children() + .should('have.length', 1); + }); + }); }); diff --git a/cypress/integration/select-one.spec.js b/cypress/integration/select-one.spec.js index 921dc4e..effc97f 100644 --- a/cypress/integration/select-one.spec.js +++ b/cypress/integration/select-one.spec.js @@ -5,13 +5,13 @@ describe('Choices - select one', () => { describe('configs', () => { describe('basic', () => { - describe('selecting choices', () => { - beforeEach(() => { - cy.get('[data-test-hook=basic]') - .find('.choices__input--cloned') - .focus(); - }); + beforeEach(() => { + cy.get('[data-test-hook=basic]') + .find('.choices__input--cloned') + .focus(); + }); + describe('selecting choice', () => { describe('focusing on text input', () => { const selectedChoiceText = 'Dropdown item 1'; @@ -78,29 +78,83 @@ describe('Choices - select one', () => { }); }); - describe('removing choices', () => { - beforeEach(() => { - cy.get('[data-test-hook=basic]') - .find('.choices__input--cloned') - .focus(); + describe('searching choices', () => { + describe('on input', () => { + describe('searching by label', () => { + it('displays choices filtered on inputted value', () => { + cy.get('[data-test-hook=basic]') + .find('.choices__input--cloned') + .type('item 2'); - cy.get('[data-test-hook=basic]') - .find('.choices__list--dropdown .choices__list') - .children() - .last() - .click(); + cy.get('[data-test-hook=basic]') + .find('.choices__list--dropdown .choices__list') + .children() + .first() + .should($choice => { + expect($choice.text().trim()).to.equal('Dropdown item 2'); + }); + }); + }); + + describe('searching by value', () => { + it('displays choices filtered on inputted value', () => { + cy.get('[data-test-hook=basic]') + .find('.choices__input--cloned') + .type('find me'); + + cy.get('[data-test-hook=basic]') + .find('.choices__list--dropdown .choices__list') + .children() + .first() + .should($choice => { + expect($choice.text().trim()).to.equal('Dropdown item 3'); + }); + }); + }); + + describe('no results found', () => { + it('displays "no results found" prompt', () => { + cy.get('[data-test-hook=basic]') + .find('.choices__input--cloned') + .type('faergge'); + + cy.get('[data-test-hook=basic]') + .find('.choices__list--dropdown') + .should('be.visible') + .should($dropdown => { + const dropdownText = $dropdown.text().trim(); + expect(dropdownText).to.equal('No results found'); + }); + }); + }); }); + }); + }); - describe('remove button', () => { - it('removes last choice', () => { - cy.get('[data-test-hook=basic]') + describe('remove button', () => { + beforeEach(() => { + cy.get('[data-test-hook=remove-button]') + .find('.choices__input--cloned') + .focus(); + + cy.get('[data-test-hook=remove-button]') + .find('.choices__list--dropdown .choices__list') + .children() + .last() + .click(); + }); + + describe('remove button', () => { + describe('on click', () => { + it('removes selected choice', () => { + cy.get('[data-test-hook=remove-button]') .find('.choices__list--single .choices__item') .last() .find('.choices__button') .focus() .click(); - cy.get('[data-test-hook=basic]') + cy.get('[data-test-hook=remove-button]') .find('.choices__list--single') .children() .should('have.length', 0); @@ -182,5 +236,14 @@ describe('Choices - select one', () => { }); }); }); + + describe('render choice limit', () => { + it('only displays given number of choices in the dropdown', () => { + cy.get('[data-test-hook=render-choice-limit]') + .find('.choices__list--dropdown .choices__list') + .children() + .should('have.length', 1); + }); + }); }); }); diff --git a/cypress/integration/text.spec.js b/cypress/integration/text.spec.js index 398d727..181cca3 100644 --- a/cypress/integration/text.spec.js +++ b/cypress/integration/text.spec.js @@ -7,8 +7,8 @@ describe('Choices - text element', () => { const textInput = 'testing'; describe('basic', () => { - describe('adding choices', () => { - it('allows me to input choices', () => { + describe('adding items', () => { + it('allows me to input items', () => { cy.get('[data-test-hook=basic]') .find('.choices__input--cloned') .type(textInput) @@ -51,78 +51,78 @@ 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('editing items', () => { + beforeEach(() => { + cy.get('[data-test-hook=edit-items]') + .find('.choices__input--cloned') + .type(textInput) + .type('{enter}'); }); - describe('removing choices', () => { - beforeEach(() => { - cy.get('[data-test-hook=basic]') + describe('on back space', () => { + it('allows me to change my entry', () => { + cy.get('[data-test-hook=edit-items]') .find('.choices__input--cloned') - .type(`${textInput}`) + .type('{backspace}') + .type('-edited') .type('{enter}'); + + cy.get('[data-test-hook=edit-items]') + .find('.choices__list--multiple .choices__item') + .last() + .should($choice => { + expect($choice.data('value')).to.equal(`${textInput}-edited`); + }); + }); + }); + }); + + describe('remove button', () => { + beforeEach(() => { + cy.get('[data-test-hook=remove-button]') + .find('.choices__input--cloned') + .type(`${textInput}`) + .type('{enter}'); + }); + + describe('on click', () => { + it('removes respective choice', () => { + cy.get('[data-test-hook=remove-button]') + .find('.choices__list--multiple') + .children() + .should($items => { + expect($items.length).to.equal(1); + }); + + cy.get('[data-test-hook=remove-button]') + .find('.choices__list--multiple .choices__item') + .last() + .find('.choices__button') + .focus() + .click(); + + cy.get('[data-test-hook=remove-button]') + .find('.choices__list--multiple .choices__item') + .should($items => { + expect($items.length).to.equal(0); + }); }); - describe('remove button', () => { - it('allows me to remove inputted choices', () => { - cy.get('[data-test-hook=basic]') - .find('.choices__list--multiple') - .children() - .should($items => { - expect($items.length).to.equal(1); - }); + it('updates the value of the original input', () => { + cy.get('[data-test-hook=remove-button]') + .find('.choices__list--multiple .choices__item') + .last() + .find('.choices__button') + .focus() + .click(); - cy.get('[data-test-hook=basic]') - .find('.choices__list--multiple .choices__item') - .last() - .find('.choices__button') - .focus() - .click(); - - cy.get('[data-test-hook=basic]') - .find('.choices__list--multiple .choices__item') - .should($items => { - expect($items.length).to.equal(0); - }); - }); - - it('updates the value of the original input', () => { - cy.get('[data-test-hook=basic]') - .find('.choices__list--multiple .choices__item') - .last() - .find('.choices__button') - .focus() - .click(); - - cy.get('[data-test-hook=basic]') - .find('.choices__input.is-hidden') - .then($input => { - expect($input.val()).to.not.contain(textInput); - }); - }); + cy.get('[data-test-hook=remove-button]') + .find('.choices__input.is-hidden') + .then($input => { + expect($input.val()).to.not.contain(textInput); + }); }); }); }); diff --git a/public/test/select-multiple.html b/public/test/select-multiple.html index e7fe3c1..2fbc280 100644 --- a/public/test/select-multiple.html +++ b/public/test/select-multiple.html @@ -31,8 +31,17 @@

Select multiple inputs

- + + + + + +
+ +
+ + + + + +
+ +
+ + + + + + + +
+ +
+ +
+ +
+ + +
diff --git a/public/test/text.html b/public/test/text.html index 1ab696b..38567e1 100644 --- a/public/test/text.html +++ b/public/test/text.html @@ -34,6 +34,16 @@ +
+ + +
+ +
+ + +
+
@@ -67,8 +77,13 @@