-
Notifications
You must be signed in to change notification settings - Fork 215
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
feat(combobox): Allow grouping of listbox items #535
Merged
Merged
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c5c3bab
feat(combobox): Allow grouping of listbox items
vibdev 1aca52f
fix flatten import
vibdev b003110
pretty
vibdev e46514f
Merge branch 'master' into combobox-add-groups
vibdev 28fbca2
WIP add text for changing groups
vibdev 23e7f67
fix lint
vibdev 66c712b
hide accessibility text
vibdev a5daa31
add tests
vibdev 83c4e90
update readme
vibdev 6346a85
switch to hasOwnProperty from in
vibdev 4ca010e
fix linting
vibdev 920dbe0
switch to hasOwnProperty from in, for real this time
vibdev dd20f80
Fix exhaustive-deps warnings
vibdev 494eaf5
add exhaustive-deps warnings
vibdev 49ec26a
add hook linting errors and fix them
vibdev 1face4a
add ToDo to fix useTheme hook
vibdev af0afb6
Merge branch 'master' of github.com:Workday/canvas-kit into HEAD
NicholasBoll 0629cf9
test(combobox): Add Cypress tests
NicholasBoll 61cad16
Merge branch 'master' of github.com:Workday/canvas-kit into autocompl…
NicholasBoll b4e205f
chore: Fix new lint errors
NicholasBoll 968517d
fix: Rename uniqueId to useUniqueId and fix usage
NicholasBoll d984f21
Merge branch 'master' of github.com:Workday/canvas-kit into autocompl…
NicholasBoll c540416
test: Fix unit tests
NicholasBoll fd4166d
fix(popup): Fix regression of hook lint fix
NicholasBoll aca6373
chore(select): Refactor select menu autofocus
NicholasBoll 79b5ddd
Merge branch 'master' into combobox-add-groups
NicholasBoll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"projectId": "odida5", | ||
"baseUrl": "http://localhost:9001", | ||
"supportFile": "cypress/support/index.ts" | ||
"supportFile": "cypress/support/index.ts", | ||
"watchForFileChanges": false | ||
} |
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 |
---|---|---|
@@ -0,0 +1,381 @@ | ||
import * as h from '../helpers'; | ||
|
||
const haveAttrMatchingIdOf = (name: string, selector: string) => ($el: JQuery) => { | ||
const $matchingEl = Cypress.$(selector); | ||
|
||
expect($el).to.have.attr(name, $matchingEl.attr('id')!); | ||
}; | ||
|
||
describe('Combobox', () => { | ||
before(() => { | ||
h.stories.visit(); | ||
}); | ||
|
||
context(`given the 'Group of results' story is rendered`, () => { | ||
beforeEach(() => { | ||
h.stories.load('Labs|Combobox/React', 'Group of results'); | ||
}); | ||
|
||
it('should have aria-haspopup set to true', () => { | ||
cy.findByRole('combobox').should('have.attr', 'aria-haspopup', 'true'); | ||
}); | ||
|
||
it('should have aria-expanded set to false', () => { | ||
cy.findByRole('combobox').should('have.attr', 'aria-expanded', 'false'); | ||
}); | ||
|
||
it('should not have an aria-activedescendant attribute', () => { | ||
cy.findByRole('combobox').should('not.have.attr', 'aria-activedescendant'); | ||
}); | ||
|
||
it('should have an aria-autocomplete attribute set to "list"', () => { | ||
cy.findByRole('combobox').should('have.attr', 'aria-autocomplete', 'list'); | ||
}); | ||
|
||
it('should not set aria-owns', () => { | ||
cy.findByRole('combobox').should('not.have.attr', 'aria-owns'); | ||
}); | ||
|
||
it('should not show menu', () => { | ||
cy.findByRole('listbox').should('not.be.visible'); | ||
}); | ||
|
||
it('should show the clear button', () => { | ||
cy.findByLabelText('Reset Search Input').should('be.visible'); | ||
}); | ||
|
||
context('when the combobox is focused', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').focus(); | ||
}); | ||
|
||
it('should set the aria-owns to reference the listbox element', () => { | ||
cy.findByRole('combobox').should(haveAttrMatchingIdOf('aria-owns', '[role=listbox]')); | ||
}); | ||
|
||
it('should show menu', () => { | ||
cy.findByRole('listbox').should('be.visible'); | ||
}); | ||
|
||
it('should not have activedescendant set', () => { | ||
cy.findByRole('combobox').should('not.have.attr', 'aria-activedescendant'); | ||
}); | ||
|
||
it('should not have aria-selected=true on any elements', () => { | ||
cy.get('[aria-selected=true]').should('not.exist'); | ||
}); | ||
|
||
context('when escape key is pressed', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('{esc}'); | ||
}); | ||
|
||
it('should clear the combobox', () => { | ||
cy.findByRole('combobox').should('have.value', ''); | ||
}); | ||
|
||
it('should close the listbox', () => { | ||
cy.findByRole('listbox').should('not.exist'); | ||
}); | ||
|
||
it('should keep focus on the combobox', () => { | ||
cy.findByRole('combobox').should('have.focus'); | ||
}); | ||
|
||
it('should not show the clear button', () => { | ||
cy.findByLabelText('Reset Search Input').should('not.be.visible'); | ||
}); | ||
}); | ||
|
||
context('when the clear button is clicked', () => { | ||
beforeEach(() => { | ||
cy.findByLabelText('Reset Search Input').click(); | ||
}); | ||
|
||
it('should clear the combobox', () => { | ||
cy.findByRole('combobox').should('have.value', ''); | ||
}); | ||
|
||
it('should close the listbox', () => { | ||
cy.findByRole('listbox').should('not.exist'); | ||
}); | ||
|
||
it('should keep focus on the combobox', () => { | ||
cy.findByRole('combobox').should('have.focus'); | ||
}); | ||
}); | ||
|
||
context('when down arrow key is pressed', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('{downarrow}'); | ||
}); | ||
|
||
it('should have activedecendant set to the first option', () => { | ||
cy.findByRole('combobox').should( | ||
haveAttrMatchingIdOf('aria-activedescendant', '[role=option]:eq(0)') | ||
); | ||
}); | ||
|
||
it('should set aria-selected to the first option', () => { | ||
cy.findAllByRole('option') | ||
.eq(0) | ||
.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
|
||
it('should announce a group was entered', () => { | ||
cy.findAllByRole('option') | ||
.eq(0) | ||
.should('contain', 'Entering group Animals, with 2 options'); | ||
}); | ||
|
||
context('when the user types a printable character "b"', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('b'); | ||
}); | ||
|
||
it('should clear activedescendant', () => { | ||
cy.findAllByRole('combobox').should('not.have.attr', 'aria-activedescendant'); | ||
}); | ||
|
||
it('should set aria-selected to the first option', () => { | ||
cy.findAllByRole('option') | ||
.eq(0) | ||
.should('have.not.attr', 'aria-selected'); | ||
}); | ||
}); | ||
|
||
context('when the user presses the enter key', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('{enter}'); | ||
}); | ||
|
||
it('should set the combobox value to the option text value', () => { | ||
cy.findByRole('combobox').should('have.value', 'Result number 0'); | ||
}); | ||
|
||
it('should close the listbox', () => { | ||
cy.findByRole('listbox').should('not.be.visible'); | ||
}); | ||
|
||
context('when the use hits the "a" key', () => { | ||
beforeEach(() => { | ||
cy.findAllByRole('combobox').type('a'); | ||
}); | ||
|
||
it('should open the listbox', () => { | ||
cy.findByRole('listbox').should('be.visible'); | ||
}); | ||
|
||
it('should change the combobox value to reflect the key entered', () => { | ||
cy.findByRole('combobox').should('have.value', 'Result number 0a'); | ||
}); | ||
}); | ||
}); | ||
|
||
context('when the user presses metaKey + enter key', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('{meta}{enter}'); | ||
}); | ||
|
||
it('should not set the combobox value to the option text value', () => { | ||
cy.findByRole('combobox').should('have.value', 'Test'); | ||
}); | ||
|
||
it('should not close the listbox', () => { | ||
cy.findByRole('listbox').should('be.visible'); | ||
}); | ||
}); | ||
}); | ||
|
||
context('when the user clicks on the "Animals" group', () => { | ||
beforeEach(() => { | ||
cy.findByText('Animals').click({force: true}); | ||
}); | ||
|
||
it('should not close the listbox', () => { | ||
cy.findByRole('listbox').should('be.visible'); | ||
}); | ||
|
||
it('should not change the combobox value', () => { | ||
cy.findByRole('combobox').should('have.value', 'Test'); | ||
}); | ||
}); | ||
|
||
context('when the user clicks on the first option', () => { | ||
beforeEach(() => { | ||
cy.findAllByRole('option') | ||
.eq(0) | ||
.click(); | ||
}); | ||
|
||
it('should set the combobox value to the option text value', () => { | ||
cy.findByRole('combobox').should('have.value', 'Result number 0'); | ||
}); | ||
|
||
it('should close the listbox', () => { | ||
cy.findByRole('listbox').should('not.be.visible'); | ||
}); | ||
|
||
it('should keep focus on combobox', () => { | ||
cy.findByRole('combobox').should('be.focused'); | ||
}); | ||
|
||
context('when the user clicks on the combobox', () => { | ||
beforeEach(() => { | ||
cy.findAllByRole('combobox').click(); | ||
}); | ||
|
||
it('should open the listbox again', () => { | ||
cy.findByRole('listbox').should('be.visible'); | ||
}); | ||
}); | ||
}); | ||
|
||
context('when down arrow key is pressed two times', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('{downarrow}{downarrow}'); | ||
}); | ||
|
||
it('should have activedecendant set to the second option', () => { | ||
cy.findByRole('combobox').should( | ||
haveAttrMatchingIdOf('aria-activedescendant', '[role=option]:eq(1)') | ||
); | ||
}); | ||
|
||
it('should set aria-selected to the second option', () => { | ||
cy.findAllByRole('option') | ||
.eq(1) | ||
.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
}); | ||
|
||
context('when down arrow key is pressed four times', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('{downarrow}{downarrow}{downarrow}{downarrow}'); | ||
}); | ||
it('should have activedecendant set to the first option', () => { | ||
cy.findByRole('combobox').should( | ||
haveAttrMatchingIdOf('aria-activedescendant', '[role=option]:eq(0)') | ||
); | ||
}); | ||
|
||
it('should set aria-selected to the first option', () => { | ||
cy.findAllByRole('option') | ||
.eq(0) | ||
.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
}); | ||
|
||
context('when up arrow key is pressed', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('{uparrow}'); | ||
}); | ||
|
||
it('should have activedecendant set to the last option', () => { | ||
cy.findByRole('combobox').should( | ||
haveAttrMatchingIdOf('aria-activedescendant', '[role=option]:eq(2)') | ||
); | ||
}); | ||
|
||
it('should set aria-selected to the last option', () => { | ||
cy.findAllByRole('option') | ||
.eq(2) | ||
.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
|
||
it('should announce a group was entered', () => { | ||
cy.findAllByRole('option') | ||
.eq(2) | ||
.should('contain', 'Entering group Cars, with 1 option'); | ||
}); | ||
}); | ||
|
||
context('when up arrow key is pressed two times', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('{uparrow}{uparrow}'); | ||
}); | ||
|
||
it('should have activedecendant set to the second option', () => { | ||
cy.findByRole('combobox').should( | ||
haveAttrMatchingIdOf('aria-activedescendant', '[role=option]:eq(1)') | ||
); | ||
}); | ||
|
||
it('should set aria-selected to the second option', () => { | ||
cy.findAllByRole('option') | ||
.eq(1) | ||
.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
}); | ||
|
||
context('when up arrow key is pressed four times', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('{uparrow}{uparrow}{uparrow}{uparrow}'); | ||
}); | ||
it('should have activedecendant set to the first option', () => { | ||
cy.findByRole('combobox').should( | ||
haveAttrMatchingIdOf('aria-activedescendant', '[role=option]:eq(-1)') | ||
); | ||
}); | ||
|
||
it('should set aria-selected to the first option', () => { | ||
cy.findAllByRole('option') | ||
.eq(-1) | ||
.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
context(`given the 'Disabled item' story is rendered`, () => { | ||
beforeEach(() => { | ||
h.stories.load('Labs|Combobox/React', 'Disabled item'); | ||
}); | ||
|
||
context('when the combobox is focused', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').focus(); | ||
}); | ||
|
||
context('when down arrow key is pressed', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('{downarrow}'); | ||
}); | ||
|
||
it('should have activedecendant set to the first option', () => { | ||
cy.findByRole('combobox').should( | ||
haveAttrMatchingIdOf('aria-activedescendant', '[role=option]:eq(0)') | ||
); | ||
}); | ||
|
||
it('should set aria-selected to the first option', () => { | ||
cy.findAllByRole('option') | ||
.eq(0) | ||
.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
|
||
context('when the user presses the enter key', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox').type('{enter}'); | ||
}); | ||
|
||
it('should not set the combobox value to the option text value', () => { | ||
cy.findByRole('combobox').should('have.value', 'Test'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
context('when "foo" is entered', () => { | ||
beforeEach(() => { | ||
cy.findByRole('combobox') | ||
.clear() | ||
.type('foo'); | ||
}); | ||
|
||
it('should update the aria-live status to "There are 3 suggestions"', () => { | ||
cy.findByRole('log').should('contain', 'There are 3 suggestions'); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this. I think it's annoying to write a bit of test code, then go back to Cypress to find out what I'm querying the DOM for and the Cypress test starts over again increasing time to write tests rather than decreasing it.