Add enabled/disabled tests

This commit is contained in:
Josh Johnson 2018-10-11 19:58:06 +01:00
parent 447f53a078
commit e53ebdda42

View file

@ -6,77 +6,117 @@ describe('Choices', () => {
describe('text element', () => { describe('text element', () => {
const textInput = 'testing'; const textInput = 'testing';
describe('adding choices', () => { describe('choices enabled', () => {
it('allows me to input choices', () => { describe('adding choices', () => {
cy.get('.choices') it('allows me to input choices', () => {
.first()
.find('.choices__input--cloned')
.type(textInput)
.type('{enter}');
cy.get('.choices')
.first()
.find('.choices__list .choices__item')
.last()
.should($el => {
expect($el).to.contain(textInput);
});
});
describe('inputting data', () => {
it('shows a dropdown prompt', () => {
cy.get('.choices') cy.get('.choices')
.first() .first()
.find('.choices__input--cloned') .find('.choices__input--cloned')
.type(textInput); .type(textInput)
.type('{enter}');
cy.get('.choices') cy.get('.choices')
.first() .first()
.find('.choices__list--dropdown') .find('.choices__list .choices__item')
.should('be.visible') .last()
.should($dropdown => { .should($el => {
const dropdownText = $dropdown.text().trim(); expect($el).to.contain(textInput);
expect(dropdownText).to.equal(
`Press Enter to add "${textInput}"`,
);
}); });
}); });
});
describe('input limit', () => { describe('inputting data', () => {
beforeEach(() => { it('shows a dropdown prompt', () => {
for (let index = 0; index < 6; index++) {
cy.get('.choices') cy.get('.choices')
.first() .first()
.find('.choices__input--cloned') .find('.choices__input--cloned')
.type(`${textInput} + ${index}`) .type(textInput);
cy.get('.choices')
.first()
.find('.choices__list--dropdown')
.should('be.visible')
.should($dropdown => {
const dropdownText = $dropdown.text().trim();
expect(dropdownText).to.equal(
`Press Enter to add "${textInput}"`,
);
});
});
});
describe('input limit', () => {
beforeEach(() => {
for (let index = 0; index < 6; index++) {
cy.get('.choices')
.first()
.find('.choices__input--cloned')
.type(`${textInput} + ${index}`)
.type('{enter}');
}
});
it('does not let me input more than 5 choices', () => {
cy.get('.choices')
.first()
.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('.choices')
.first()
.find('.choices__list--dropdown')
.should('not.be.visible');
});
});
describe('unique values', () => {
beforeEach(() => {
cy.get('.choices')
.eq(1) // second choices instance
.find('.choices__input--cloned')
.type(`${textInput}`)
.type('{enter}')
.type(`${textInput}`)
.type('{enter}'); .type('{enter}');
} });
});
it('does not let me input more than 5 choices', () => { it('only allows me to input unique values', () => {
cy.get('.choices') cy.get('.choices')
.first() .eq(1)
.find('.choices__list--multiple') .find('.choices__list--multiple')
.first() .first()
.children() .children()
.should($items => { .should($items => {
expect($items.length).to.equal(5); expect($items.length).to.equal(1);
});
});
describe('inputting a non-unique value', () => {
it('displays dropdown prompt', () => {
cy.get('.choices')
.eq(1)
.find('.choices__list--dropdown')
.should('be.visible')
.should($dropdown => {
const dropdownText = $dropdown.text().trim();
expect(dropdownText).to.equal(
'Only unique values can be added.',
);
});
}); });
}); });
it('hides dropdown prompt once limit has been reached', () => {
cy.get('.choices')
.first()
.find('.choices__list--dropdown')
.should('not.be.visible');
}); });
}); });
describe('unique values', () => { describe('removing choices', () => {
beforeEach(() => { beforeEach(() => {
cy.get('.choices') cy.get('.choices')
.eq(1) // second choices instance .first() // second choices instance
.find('.choices__input--cloned') .find('.choices__input--cloned')
.type(`${textInput}`) .type(`${textInput}`)
.type('{enter}') .type('{enter}')
@ -84,70 +124,41 @@ describe('Choices', () => {
.type('{enter}'); .type('{enter}');
}); });
it('only allows me to input unique values', () => { it('allows me to remove inputted choices', () => {
cy.get('.choices') cy.get('.choices')
.eq(1) .first()
.find('.choices__list--multiple') .find('.choices__list--multiple')
.first() .first()
.children() .children()
.should($items => {
expect($items.length).to.equal(2);
});
cy.get('.choices')
.first()
.find('.choices__list--multiple .choices__item')
.last()
.find('.choices__button')
.focus()
.click();
cy.get('.choices')
.first()
.find('.choices__list--multiple')
.first()
.should($items => { .should($items => {
expect($items.length).to.equal(1); expect($items.length).to.equal(1);
}); });
}); });
describe('inputting a non-unique value', () => {
it('displays dropdown prompt', () => {
cy.get('.choices')
.eq(1)
.find('.choices__list--dropdown')
.should('be.visible')
.should($dropdown => {
const dropdownText = $dropdown.text().trim();
expect(dropdownText).to.equal(
'Only unique values can be added.',
);
});
});
});
}); });
}); });
describe('removing choices', () => { describe('choices disabled', () => {
beforeEach(() => { it('does not allow me to input data', () => {
cy.get('.choices') cy.get('.choices')
.first() // second choices instance .eq(3)
.find('.choices__input--cloned') .find('.choices__input--cloned')
.type(`${textInput}`) .should('be.disabled');
.type('{enter}')
.type(`${textInput}`)
.type('{enter}');
});
it('allows me to remove inputted choices', () => {
cy.get('.choices')
.first()
.find('.choices__list--multiple')
.first()
.children()
.should($items => {
expect($items.length).to.equal(2);
});
cy.get('.choices')
.first()
.find('.choices__list--multiple .choices__item')
.last()
.find('.choices__button')
.focus()
.click();
cy.get('.choices')
.first()
.find('.choices__list--multiple')
.first()
.should($items => {
expect($items.length).to.equal(1);
});
}); });
}); });
}); });