fix and extend existing tests for new functionality

This commit is contained in:
alex 2020-04-16 05:01:21 +02:00
parent 2c57d3a690
commit cf34edd0ad
4 changed files with 55 additions and 28 deletions

View file

@ -332,20 +332,32 @@ describe('Choices - select multiple', () => {
addItems: false,
}
*/
it('disables the search input', () => {
it('disables adding new items', () => {
const newChoice = 'New Choice';
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__input--cloned')
.should('be.disabled');
.type(newChoice)
.type('{enter}');
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__list--multiple')
.last()
.should($el => {
expect($el).to.not.contain(newChoice);
});
});
describe('on click', () => {
it('does not open choice dropdown', () => {
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices')
.click()
.find('.choices__list--dropdown')
.should('not.have.class', 'is-active');
});
it('allows selecting items', () => {
const choice = 'Choice 2';
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__input--cloned')
.type(choice)
.type('{enter}');
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__list--multiple')
.last()
.should($el => {
expect($el).to.contain(choice);
});
});
});

View file

@ -300,22 +300,37 @@ describe('Choices - select one', () => {
addItems: false,
}
*/
it('disables the search input', () => {
beforeEach(() => {
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices')
.click();
});
it('disables adding new items', () => {
const newChoice = 'New Choice';
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__input--cloned')
.should('be.disabled');
.type(newChoice)
.type('{enter}');
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__list--single .choices__item')
.last()
.should($el => {
expect($el).to.not.contain(newChoice);
});
});
describe('on click', () => {
it('does not open choice dropdown', () => {
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices')
.click();
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__list--dropdown')
.should('not.have.class', 'is-active');
});
it('allows selecting items', () => {
const choice = 'Choice 2';
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__input--cloned')
.type(choice)
.type('{enter}');
cy.get('[data-test-hook=add-items-disabled]')
.find('.choices__list--single .choices__item')
.last()
.should($el => {
expect($el).to.contain(choice);
});
});
});

View file

@ -415,9 +415,7 @@
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const choicesBasic = new Choices('#choices-basic', {
allowHTML: true,
});
const choicesBasic = new Choices('#choices-basic', { addItems: false, allowHTML: true, });
document
.querySelector('button.disable')
@ -573,7 +571,8 @@
new Choices('#choices-search-by-label', {
allowHTML: true,
searchFields: ['label']
searchFields: ['label'],
addItems: false,
});
new Choices('#choices-allowhtml-undefined', {

View file

@ -435,7 +435,7 @@
<script>
document.addEventListener('DOMContentLoaded', function() {
const choicesBasic = new Choices('#choices-basic', {
allowHTML: true,
allowHTML: true, addItems: false
});
document
@ -632,7 +632,8 @@
new Choices('#choices-search-by-label', {
allowHTML: true,
searchFields: ['label']
searchFields: ['label'],
addItems: false,
});
new Choices('#choices-allowhtml-undefined', {