Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for adding user created items to select boxes #856

Closed
wants to merge 8 commits into from
Closed
85 changes: 75 additions & 10 deletions cypress/e2e/select-multiple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,41 @@ describe('Choices - select multiple', () => {
});
});

describe('unique values only', () => {
describe('unique values', () => {
beforeEach(() => {
cy.get('[data-test-hook=unique-values]')
.find('.choices__input--cloned')
.type('Choice 1')
.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(
'Only unique values can be added',
);
});
});
});
});
});

describe('disabled choice', () => {
describe('selecting a disabled choice', () => {
beforeEach(() => {
Expand All @@ -308,26 +343,56 @@ describe('Choices - select multiple', () => {
});
});

describe('adding user-created choices', () => {
it('allows the user to add choices', () => {
const newChoice = 'New Choice';

cy.get('[data-test-hook=add-items]')
.find('.choices__input--cloned')
.type(newChoice)
.type('{enter}');

cy.get('[data-test-hook=add-items]')
.find('.choices__list--multiple')
.last()
.should($el => {
expect($el).to.contain(newChoice);
});
});
});

describe('adding items disabled', () => {
/*
{
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);
});
});
});

Expand Down
62 changes: 50 additions & 12 deletions cypress/e2e/select-one.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,28 +271,66 @@ describe('Choices - select one', () => {
});
});

describe('adding user-created choices', () => {
beforeEach(() => {
cy.get('[data-test-hook=add-items]')
.find('.choices')
.click();
});

it('allows the user to add choices', () => {
const newChoice = 'New Choice';

cy.get('[data-test-hook=add-items]')
.find('.choices__input--cloned')
.type(newChoice)
.type('{enter}');

cy.get('[data-test-hook=add-items]')
.find('.choices__list--single .choices__item')
.should($el => {
expect($el).to.contain(newChoice);
});
});
});

describe('adding items disabled', () => {
/*
{
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);
});
});
});

Expand Down
24 changes: 21 additions & 3 deletions cypress/e2e/text.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,28 @@ describe('Choices - text element', () => {
});

describe('adding items disabled', () => {
it('does not allow me to input data', () => {
cy.get('[data-test-hook=adding-items-disabled]')
/*
{
addItems: false,
}
*/
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--multiple')
.last()
.should($el => {
expect($el).to.not.contain(newChoice);
});
});
});

Expand Down
Loading