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

feat(combobox): Allow grouping of listbox items #535

Merged
merged 26 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
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 Mar 23, 2020
1aca52f
fix flatten import
vibdev Mar 26, 2020
b003110
pretty
vibdev Mar 26, 2020
e46514f
Merge branch 'master' into combobox-add-groups
vibdev Apr 21, 2020
28fbca2
WIP add text for changing groups
vibdev Apr 22, 2020
23e7f67
fix lint
vibdev Apr 22, 2020
66c712b
hide accessibility text
vibdev May 5, 2020
a5daa31
add tests
vibdev May 5, 2020
83c4e90
update readme
vibdev May 5, 2020
6346a85
switch to hasOwnProperty from in
vibdev Jun 3, 2020
4ca010e
fix linting
vibdev Jun 3, 2020
920dbe0
switch to hasOwnProperty from in, for real this time
vibdev Jun 4, 2020
dd20f80
Fix exhaustive-deps warnings
vibdev Jun 4, 2020
494eaf5
add exhaustive-deps warnings
vibdev Jun 4, 2020
49ec26a
add hook linting errors and fix them
vibdev Jun 9, 2020
1face4a
add ToDo to fix useTheme hook
vibdev Jun 9, 2020
af0afb6
Merge branch 'master' of github.com:Workday/canvas-kit into HEAD
NicholasBoll Jun 18, 2020
0629cf9
test(combobox): Add Cypress tests
NicholasBoll Jun 22, 2020
61cad16
Merge branch 'master' of github.com:Workday/canvas-kit into autocompl…
NicholasBoll Jul 7, 2020
b4e205f
chore: Fix new lint errors
NicholasBoll Jul 7, 2020
968517d
fix: Rename uniqueId to useUniqueId and fix usage
NicholasBoll Jul 8, 2020
d984f21
Merge branch 'master' of github.com:Workday/canvas-kit into autocompl…
NicholasBoll Jul 9, 2020
c540416
test: Fix unit tests
NicholasBoll Jul 9, 2020
fd4166d
fix(popup): Fix regression of hook lint fix
NicholasBoll Jul 9, 2020
aca6373
chore(select): Refactor select menu autofocus
NicholasBoll Jul 9, 2020
79b5ddd
Merge branch 'master' into combobox-add-groups
NicholasBoll Jul 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ module.exports = {
'prefer-const': 'error',
'space-before-function-paren': 'off',
'react/jsx-no-bind': 'off', // Keep perf implications in mind, but was giving too many warnings and hurting readability
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": 'error',
curly: 'error',
radix: 'error',
},
Expand Down
3 changes: 2 additions & 1 deletion cypress.json
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
Copy link
Member

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.

}
381 changes: 381 additions & 0 deletions cypress/integration/Combobox.spec.ts
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');
});
});
});
});
Loading