-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Combine regexFilter and addItemFilter + minor tweaks * Update tests to accomodate fixed dropdown notice * Remove broken `toggleDropdown` method * Unskip dropdown interaction tests * Remove reference to removed method
- Loading branch information
1 parent
55b356e
commit 8540d5a
Showing
15 changed files
with
130 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,8 +197,9 @@ describe('Choices - text element', () => { | |
}); | ||
|
||
describe('input limit', () => { | ||
const inputLimit = 5; | ||
beforeEach(() => { | ||
for (let index = 0; index < 6; index++) { | ||
for (let index = 0; index < inputLimit + 1; index++) { | ||
cy.get('[data-test-hook=input-limit]') | ||
.find('.choices__input--cloned') | ||
.type(`${textInput} + ${index}`) | ||
|
@@ -212,29 +213,36 @@ describe('Choices - text element', () => { | |
.first() | ||
.children() | ||
.should($items => { | ||
expect($items.length).to.equal(5); | ||
expect($items.length).to.equal(inputLimit); | ||
}); | ||
}); | ||
|
||
it('hides dropdown prompt once limit has been reached', () => { | ||
cy.wait(500); // allow for animation frame | ||
cy.get('[data-test-hook=input-limit]') | ||
.find('.choices__list--dropdown') | ||
.should('not.be.visible'); | ||
describe('reaching input limit', () => { | ||
it('displays dropdown prompt', () => { | ||
cy.get('[data-test-hook=input-limit]') | ||
.find('.choices__list--dropdown') | ||
.should('be.visible') | ||
.should($dropdown => { | ||
const dropdownText = $dropdown.text().trim(); | ||
expect(dropdownText).to.equal( | ||
`Only ${inputLimit} values can be added`, | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('regex filter', () => { | ||
describe('inputting a value that satisfies the regex', () => { | ||
describe('add item filter', () => { | ||
describe('inputting a value that satisfies the filter', () => { | ||
const input = '[email protected]'; | ||
|
||
it('allows me to add choice', () => { | ||
cy.get('[data-test-hook=regex-filter]') | ||
cy.get('[data-test-hook=add-item-filter]') | ||
.find('.choices__input--cloned') | ||
.type(input) | ||
.type('{enter}'); | ||
|
||
cy.get('[data-test-hook=regex-filter]') | ||
cy.get('[data-test-hook=add-item-filter]') | ||
.find('.choices__list--multiple .choices__item') | ||
.last() | ||
.should($choice => { | ||
|
@@ -245,14 +253,20 @@ describe('Choices - text element', () => { | |
|
||
describe('inputting a value that does not satisfy the regex', () => { | ||
it('displays dropdown prompt', () => { | ||
cy.get('[data-test-hook=regex-filter]') | ||
cy.get('[data-test-hook=add-item-filter]') | ||
.find('.choices__input--cloned') | ||
.type(`this is not an email address`) | ||
.type('{enter}'); | ||
|
||
cy.get('[data-test-hook=regex-filter]') | ||
cy.get('[data-test-hook=add-item-filter]') | ||
.find('.choices__list--dropdown') | ||
.should('not.be.visible'); | ||
.should('be.visible') | ||
.should($dropdown => { | ||
const dropdownText = $dropdown.text().trim(); | ||
expect(dropdownText).to.equal( | ||
'Only values matching specific conditions can be added', | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
@@ -293,39 +307,6 @@ describe('Choices - text element', () => { | |
}); | ||
}); | ||
|
||
describe('custom add item callback', () => { | ||
describe('inputting a value that satisfies the addItemFilter', () => { | ||
const input = 'test'; | ||
|
||
it('allows me to add choice', () => { | ||
cy.get('[data-test-hook=add-item-callback]') | ||
.find('.choices__input--cloned') | ||
.type(input) | ||
.type('{enter}'); | ||
|
||
cy.get('[data-test-hook=add-item-callback]') | ||
.find('.choices__list--multiple .choices__item') | ||
.last() | ||
.should($choice => { | ||
expect($choice.text().trim()).to.equal(input); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('inputting a value that does not satisfy the callback', () => { | ||
it('displays dropdown prompt', () => { | ||
cy.get('[data-test-hook=add-item-callback]') | ||
.find('.choices__input--cloned') | ||
.type(`this is not the allowed text`) | ||
.type('{enter}'); | ||
|
||
cy.get('[data-test-hook=add-item-callback]') | ||
.find('.choices__list--dropdown') | ||
.should('not.be.visible'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('disabled via attribute', () => { | ||
it('does not allow me to input data', () => { | ||
cy.get('[data-test-hook=disabled-via-attr]') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,7 +344,15 @@ <h2>Form interaction</h2> | |
|
||
var textEmailFilter = new Choices('#choices-text-email-filter', { | ||
editItems: true, | ||
regexFilter: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, | ||
addItemFilterFn: (value) => { | ||
if (!value) { | ||
return false; | ||
} | ||
|
||
const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ | ||
const expression = new RegExp(regex.source, 'i'); | ||
return expression.test(value); | ||
}, | ||
}).setValue(['[email protected]']); | ||
|
||
var textDisabled = new Choices('#choices-text-disabled', { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.