2018-10-13 13:18:02 +02:00
|
|
|
describe('Choices - text element', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.visit('/text.html');
|
|
|
|
});
|
|
|
|
|
2018-10-27 17:25:46 +02:00
|
|
|
describe('scenarios', () => {
|
2018-10-13 13:18:02 +02:00
|
|
|
const textInput = 'testing';
|
|
|
|
|
|
|
|
describe('basic', () => {
|
2018-10-17 23:36:37 +02:00
|
|
|
describe('adding items', () => {
|
|
|
|
it('allows me to input items', () => {
|
2018-10-13 13:18:02 +02:00
|
|
|
cy.get('[data-test-hook=basic]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.type(textInput)
|
|
|
|
.type('{enter}');
|
|
|
|
|
|
|
|
cy.get('[data-test-hook=basic]')
|
|
|
|
.find('.choices__list--multiple .choices__item')
|
|
|
|
.last()
|
|
|
|
.should($el => {
|
|
|
|
expect($el).to.contain(textInput);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates the value of the original input', () => {
|
|
|
|
cy.get('[data-test-hook=basic]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.type(textInput)
|
|
|
|
.type('{enter}');
|
|
|
|
|
|
|
|
cy.get('[data-test-hook=basic]')
|
|
|
|
.find('.choices__input.is-hidden')
|
|
|
|
.should('have.value', textInput);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('inputting data', () => {
|
|
|
|
it('shows a dropdown prompt', () => {
|
|
|
|
cy.get('[data-test-hook=basic]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.type(textInput);
|
|
|
|
|
|
|
|
cy.get('[data-test-hook=basic]')
|
|
|
|
.find('.choices__list--dropdown')
|
|
|
|
.should('be.visible')
|
|
|
|
.should($dropdown => {
|
|
|
|
const dropdownText = $dropdown.text().trim();
|
|
|
|
expect(dropdownText).to.equal(
|
|
|
|
`Press Enter to add "${textInput}"`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-17 23:36:37 +02:00
|
|
|
});
|
2018-10-13 13:18:02 +02:00
|
|
|
|
2018-10-17 23:36:37 +02:00
|
|
|
describe('editing items', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.get('[data-test-hook=edit-items]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.type(textInput)
|
|
|
|
.type('{enter}');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('on back space', () => {
|
|
|
|
it('allows me to change my entry', () => {
|
|
|
|
cy.get('[data-test-hook=edit-items]')
|
2018-10-13 13:42:33 +02:00
|
|
|
.find('.choices__input--cloned')
|
2018-10-17 23:36:37 +02:00
|
|
|
.type('{backspace}')
|
|
|
|
.type('-edited')
|
2018-10-13 13:42:33 +02:00
|
|
|
.type('{enter}');
|
|
|
|
|
2018-10-17 23:36:37 +02:00
|
|
|
cy.get('[data-test-hook=edit-items]')
|
|
|
|
.find('.choices__list--multiple .choices__item')
|
|
|
|
.last()
|
|
|
|
.should($choice => {
|
|
|
|
expect($choice.data('value')).to.equal(`${textInput}-edited`);
|
|
|
|
});
|
2018-10-13 13:42:33 +02:00
|
|
|
});
|
|
|
|
});
|
2018-10-17 23:36:37 +02:00
|
|
|
});
|
2018-10-13 13:42:33 +02:00
|
|
|
|
2018-10-17 23:36:37 +02:00
|
|
|
describe('remove button', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.get('[data-test-hook=remove-button]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.type(`${textInput}`)
|
|
|
|
.type('{enter}');
|
|
|
|
});
|
2018-10-13 13:18:02 +02:00
|
|
|
|
2018-10-17 23:36:37 +02:00
|
|
|
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);
|
|
|
|
});
|
2018-10-13 13:18:02 +02:00
|
|
|
|
2018-10-17 23:36:37 +02:00
|
|
|
cy.get('[data-test-hook=remove-button]')
|
|
|
|
.find('.choices__list--multiple .choices__item')
|
|
|
|
.last()
|
|
|
|
.find('.choices__button')
|
|
|
|
.focus()
|
|
|
|
.click();
|
2018-10-13 13:18:02 +02:00
|
|
|
|
2018-10-17 23:36:37 +02:00
|
|
|
cy.get('[data-test-hook=remove-button]')
|
|
|
|
.find('.choices__list--multiple .choices__item')
|
|
|
|
.should($items => {
|
|
|
|
expect($items.length).to.equal(0);
|
|
|
|
});
|
|
|
|
});
|
2018-10-13 16:49:44 +02:00
|
|
|
|
2018-10-17 23:36:37 +02:00
|
|
|
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();
|
2018-10-13 16:49:44 +02:00
|
|
|
|
2018-10-17 23:36:37 +02:00
|
|
|
cy.get('[data-test-hook=remove-button]')
|
|
|
|
.find('.choices__input.is-hidden')
|
|
|
|
.then($input => {
|
|
|
|
expect($input.val()).to.not.contain(textInput);
|
|
|
|
});
|
2018-10-13 13:18:02 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unique values only', () => {
|
|
|
|
describe('unique values', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.get('[data-test-hook=unique-values]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.type(`${textInput}`)
|
|
|
|
.type('{enter}')
|
|
|
|
.type(`${textInput}`)
|
|
|
|
.type('{enter}');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('only allows me to input unique values', () => {
|
|
|
|
cy.get('[data-test-hook=unique-values]')
|
|
|
|
.find('.choices__list--multiple')
|
|
|
|
.first()
|
|
|
|
.children()
|
|
|
|
.should($items => {
|
|
|
|
expect($items.length).to.equal(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('inputting a non-unique value', () => {
|
|
|
|
it('displays dropdown prompt', () => {
|
|
|
|
cy.get('[data-test-hook=unique-values]')
|
|
|
|
.find('.choices__list--dropdown')
|
|
|
|
.should('be.visible')
|
|
|
|
.should($dropdown => {
|
|
|
|
const dropdownText = $dropdown.text().trim();
|
|
|
|
expect(dropdownText).to.equal(
|
2018-10-13 17:38:51 +02:00
|
|
|
'Only unique values can be added',
|
2018-10-13 13:18:02 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('input limit', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
for (let index = 0; index < 6; index++) {
|
|
|
|
cy.get('[data-test-hook=input-limit]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.type(`${textInput} + ${index}`)
|
|
|
|
.type('{enter}');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not let me input more than 5 choices', () => {
|
|
|
|
cy.get('[data-test-hook=input-limit]')
|
|
|
|
.find('.choices__list--multiple')
|
|
|
|
.first()
|
|
|
|
.children()
|
|
|
|
.should($items => {
|
|
|
|
expect($items.length).to.equal(5);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('hides dropdown prompt once limit has been reached', () => {
|
|
|
|
cy.get('[data-test-hook=input-limit]')
|
|
|
|
.find('.choices__list--dropdown')
|
|
|
|
.should('not.be.visible');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('regex filter', () => {
|
|
|
|
describe('a valid that satisfies regex', () => {
|
|
|
|
const input = 'joe@bloggs.com';
|
|
|
|
|
|
|
|
it('allows me to add choice', () => {
|
|
|
|
cy.get('[data-test-hook=regex-filter]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.type(input)
|
|
|
|
.type('{enter}');
|
|
|
|
|
|
|
|
cy.get('[data-test-hook=regex-filter]')
|
2018-10-13 13:42:33 +02:00
|
|
|
.find('.choices__list--multiple .choices__item')
|
2018-10-13 13:18:02 +02:00
|
|
|
.last()
|
|
|
|
.should($choice => {
|
2018-10-13 13:42:33 +02:00
|
|
|
expect($choice.text().trim()).to.equal(input);
|
2018-10-13 13:18:02 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('inputting a value that does not satisfy the regex', () => {
|
|
|
|
it('displays dropdown prompt', () => {
|
|
|
|
cy.get('[data-test-hook=regex-filter]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.type(`this is not an email address`)
|
|
|
|
.type('{enter}');
|
|
|
|
|
|
|
|
cy.get('[data-test-hook=regex-filter]')
|
|
|
|
.find('.choices__list--dropdown')
|
|
|
|
.should('not.be.visible');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('prepend/append', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.get('[data-test-hook=prepend-append]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.type(textInput)
|
|
|
|
.type('{enter}');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('prepends and appends value to inputted value', () => {
|
|
|
|
cy.get('[data-test-hook=prepend-append]')
|
|
|
|
.find('.choices__list--multiple .choices__item')
|
|
|
|
.last()
|
|
|
|
.should($choice => {
|
|
|
|
expect($choice.data('value')).to.equal(`before-${textInput}-after`);
|
|
|
|
});
|
|
|
|
});
|
2018-10-13 13:42:33 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2018-10-13 13:18:02 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('disabled', () => {
|
|
|
|
it('does not allow me to input data', () => {
|
|
|
|
cy.get('[data-test-hook=disabled]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.should('be.disabled');
|
|
|
|
});
|
|
|
|
});
|
2018-10-13 13:42:33 +02:00
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-18 23:18:17 +02:00
|
|
|
|
|
|
|
describe('placeholder', () => {
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
placeholder: true,
|
|
|
|
placeholderValue: 'I am a placeholder',
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
describe('when no value has been inputted', () => {
|
|
|
|
it('displays a placeholder', () => {
|
|
|
|
cy.get('[data-test-hook=placeholder]')
|
|
|
|
.find('.choices__input--cloned')
|
|
|
|
.should('have.attr', 'placeholder', 'I am a placeholder');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-13 13:18:02 +02:00
|
|
|
});
|
|
|
|
});
|