-
Notifications
You must be signed in to change notification settings - Fork 842
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
[EuiSelectable] Handle more keyboard scenarios #5613
Changes from 4 commits
abb0076
7c3e380
65038dc
10b16e8
bd39639
e2e2252
cbf7074
f3e00c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { EuiSelectable, EuiSelectableProps } from './selectable'; | ||
|
||
const options: EuiSelectableProps['options'] = [ | ||
{ | ||
label: 'Titan', | ||
'data-test-subj': 'titanOption', | ||
}, | ||
{ | ||
label: 'Enceladus', | ||
}, | ||
{ | ||
label: | ||
"Pandora is one of Saturn's moons, named for a Titaness of Greek mythology", | ||
}, | ||
]; | ||
|
||
describe('EuiSelectable', () => { | ||
describe('with a `searchable` configuration', () => { | ||
it('filters the list with search', () => { | ||
cy.realMount( | ||
<EuiSelectable searchable options={options}> | ||
{(list, search) => ( | ||
<> | ||
{search} | ||
{list} | ||
</> | ||
)} | ||
</EuiSelectable> | ||
); | ||
|
||
// Focus the second option | ||
cy.get('input') | ||
.click() | ||
.type('{downarrow}') | ||
.type('{downarrow}') | ||
thompsongl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.then(() => { | ||
cy.get('li[role=option]') | ||
.eq(1) | ||
.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
|
||
// Focus remains on the second option | ||
cy.get('input') | ||
.type('{alt}') | ||
.type('{ctrl}') | ||
.type('{meta}') | ||
.type('{Shift}') | ||
thompsongl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.then(() => { | ||
cy.get('li[role=option]') | ||
.eq(1) | ||
.should('have.attr', 'aria-selected', 'true'); | ||
}); | ||
|
||
// Filter the list | ||
cy.get('input') | ||
.type('enc') | ||
thompsongl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.then(() => { | ||
cy.get('li[role=option]') | ||
.first() | ||
.should('have.attr', 'title', 'Enceladus'); | ||
}); | ||
}); | ||
|
||
it('can clear the input', () => { | ||
cy.mount( | ||
thompsongl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<EuiSelectable searchable options={options}> | ||
{(list, search) => ( | ||
<> | ||
{search} | ||
{list} | ||
</> | ||
)} | ||
</EuiSelectable> | ||
); | ||
|
||
cy.get('input') | ||
.type('enc') | ||
thompsongl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.then(() => { | ||
cy.get('li[role=option]') | ||
.first() | ||
.should('have.attr', 'title', 'Enceladus'); | ||
}); | ||
|
||
cy.get('[data-test-subj="clearSearchButton"]') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about duplicating this test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in e2e2252 |
||
.type('{enter}') | ||
thompsongl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.then(() => { | ||
cy.get('li[role=option]') | ||
.first() | ||
.should('have.attr', 'title', 'Titan'); | ||
}); | ||
}); | ||
}); | ||
}); |
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.
Great call adding a Cypress spec! I'd like to use
cypress-real-events
helpers for the click and keyboard interactions as much as possible. I'll add notes to individual lines to change, and I'm 99% sure they'll pass on first try. They worked on my machine anyhow :)I swapped
cy.type(string)
forcy.realType(string) || cy.realPress(string)
and thecy.click()
forcy.realClick()
while testing. I opted for realPress when it was a single key, and kept realType for multiple characters like "esc".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.
Updated all in e2e2252