|
@@ -64,17 +64,17 @@ describe('<Select />', function () {
|
|
|
it('renders default text', function () {
|
|
it('renders default text', function () {
|
|
|
render({ defaultText: 'Choose an item' })
|
|
render({ defaultText: 'Choose an item' })
|
|
|
cy.findByTestId('spinner').should('not.exist')
|
|
cy.findByTestId('spinner').should('not.exist')
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' })
|
|
|
|
|
|
|
+ cy.findByRole('combobox').should('have.value', 'Choose an item')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('renders default item', function () {
|
|
it('renders default item', function () {
|
|
|
render({ defaultItem: testData[2] })
|
|
render({ defaultItem: testData[2] })
|
|
|
- cy.findByRole('textbox', { name: 'Demo item 3' })
|
|
|
|
|
|
|
+ cy.findByRole('combobox').should('have.value', 'Demo item 3')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('default item takes precedence over default text', function () {
|
|
it('default item takes precedence over default text', function () {
|
|
|
render({ defaultText: 'Choose an item', defaultItem: testData[2] })
|
|
render({ defaultText: 'Choose an item', defaultItem: testData[2] })
|
|
|
- cy.findByRole('textbox', { name: 'Demo item 3' })
|
|
|
|
|
|
|
+ cy.findByRole('combobox').should('have.value', 'Demo item 3')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('renders label', function () {
|
|
it('renders label', function () {
|
|
@@ -83,8 +83,8 @@ describe('<Select />', function () {
|
|
|
label: 'test label',
|
|
label: 'test label',
|
|
|
optionalLabel: false,
|
|
optionalLabel: false,
|
|
|
})
|
|
})
|
|
|
- cy.findByRole('textbox', { name: 'test label' })
|
|
|
|
|
- cy.findByRole('textbox', { name: '(Optional)' }).should('not.exist')
|
|
|
|
|
|
|
+ cy.findByRole('combobox', { name: 'test label' })
|
|
|
|
|
+ cy.findByRole('combobox', { name: '(Optional)' }).should('not.exist')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('renders optional label', function () {
|
|
it('renders optional label', function () {
|
|
@@ -93,7 +93,7 @@ describe('<Select />', function () {
|
|
|
label: 'test label',
|
|
label: 'test label',
|
|
|
optionalLabel: true,
|
|
optionalLabel: true,
|
|
|
})
|
|
})
|
|
|
- cy.findByRole('textbox', { name: 'test label (Optional)' })
|
|
|
|
|
|
|
+ cy.findByRole('combobox', { name: 'test label (Optional)' })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('renders a spinner while loading when there is a label', function () {
|
|
it('renders a spinner while loading when there is a label', function () {
|
|
@@ -117,7 +117,7 @@ describe('<Select />', function () {
|
|
|
describe('items rendering', function () {
|
|
describe('items rendering', function () {
|
|
|
it('renders all items', function () {
|
|
it('renders all items', function () {
|
|
|
render({ defaultText: 'Choose an item' })
|
|
render({ defaultText: 'Choose an item' })
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' }).click()
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
|
|
|
|
|
cy.findByRole('option', { name: 'Demo item 1' })
|
|
cy.findByRole('option', { name: 'Demo item 1' })
|
|
|
cy.findByRole('option', { name: 'Demo item 2' })
|
|
cy.findByRole('option', { name: 'Demo item 2' })
|
|
@@ -129,7 +129,7 @@ describe('<Select />', function () {
|
|
|
defaultText: 'Choose an item',
|
|
defaultText: 'Choose an item',
|
|
|
itemToSubtitle: x => String(x?.sub),
|
|
itemToSubtitle: x => String(x?.sub),
|
|
|
})
|
|
})
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' }).click()
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
|
|
|
|
|
cy.findByRole('option', { name: 'Demo item 1 Subtitle 1' })
|
|
cy.findByRole('option', { name: 'Demo item 1 Subtitle 1' })
|
|
|
cy.findByRole('option', { name: 'Demo item 2 Subtitle 2' })
|
|
cy.findByRole('option', { name: 'Demo item 2 Subtitle 2' })
|
|
@@ -140,27 +140,27 @@ describe('<Select />', function () {
|
|
|
describe('item selection', function () {
|
|
describe('item selection', function () {
|
|
|
it('cannot select an item when disabled', function () {
|
|
it('cannot select an item when disabled', function () {
|
|
|
render({ defaultText: 'Choose an item', disabled: true })
|
|
render({ defaultText: 'Choose an item', disabled: true })
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' }).click({
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click({
|
|
|
force: true,
|
|
force: true,
|
|
|
})
|
|
})
|
|
|
cy.findByRole('option', { name: 'Demo item 1' }).should('not.exist')
|
|
cy.findByRole('option', { name: 'Demo item 1' }).should('not.exist')
|
|
|
cy.findByRole('option', { name: 'Demo item 2' }).should('not.exist')
|
|
cy.findByRole('option', { name: 'Demo item 2' }).should('not.exist')
|
|
|
cy.findByRole('option', { name: 'Demo item 3' }).should('not.exist')
|
|
cy.findByRole('option', { name: 'Demo item 3' }).should('not.exist')
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' })
|
|
|
|
|
|
|
+ cy.findByRole('combobox').should('have.value', 'Choose an item')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('renders only the selected item after selection', function () {
|
|
it('renders only the selected item after selection', function () {
|
|
|
render({ defaultText: 'Choose an item' })
|
|
render({ defaultText: 'Choose an item' })
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' }).click()
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
|
|
|
|
|
cy.findByRole('option', { name: 'Demo item 1' })
|
|
cy.findByRole('option', { name: 'Demo item 1' })
|
|
|
cy.findByRole('option', { name: 'Demo item 2' })
|
|
cy.findByRole('option', { name: 'Demo item 2' })
|
|
|
cy.findByRole('option', { name: 'Demo item 3' }).click()
|
|
cy.findByRole('option', { name: 'Demo item 3' }).click()
|
|
|
|
|
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' }).should('not.exist')
|
|
|
|
|
|
|
+ cy.findByRole('combobox').should('not.have.value', 'Choose an item')
|
|
|
cy.findByRole('option', { name: 'Demo item 1' }).should('not.exist')
|
|
cy.findByRole('option', { name: 'Demo item 1' }).should('not.exist')
|
|
|
cy.findByRole('option', { name: 'Demo item 2' }).should('not.exist')
|
|
cy.findByRole('option', { name: 'Demo item 2' }).should('not.exist')
|
|
|
- cy.findByRole('textbox', { name: 'Demo item 3' })
|
|
|
|
|
|
|
+ cy.findByRole('combobox').should('have.value', 'Demo item 3')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('invokes callback after selection', function () {
|
|
it('invokes callback after selection', function () {
|
|
@@ -170,7 +170,7 @@ describe('<Select />', function () {
|
|
|
defaultText: 'Choose an item',
|
|
defaultText: 'Choose an item',
|
|
|
onSelectedItemChanged: selectionHandler,
|
|
onSelectedItemChanged: selectionHandler,
|
|
|
})
|
|
})
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' }).click()
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
cy.findByRole('option', { name: 'Demo item 2' }).click()
|
|
cy.findByRole('option', { name: 'Demo item 2' }).click()
|
|
|
|
|
|
|
|
cy.get('@selectionHandler').should(
|
|
cy.get('@selectionHandler').should(
|
|
@@ -195,7 +195,7 @@ describe('<Select />', function () {
|
|
|
const submitHandler = cy.stub().as('submitHandler')
|
|
const submitHandler = cy.stub().as('submitHandler')
|
|
|
render({ defaultItem: testData[1], onSubmit: submitHandler })
|
|
render({ defaultItem: testData[1], onSubmit: submitHandler })
|
|
|
|
|
|
|
|
- cy.findByRole('textbox', { name: 'Demo item 2' }).click() // open dropdown
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click() // open dropdown
|
|
|
cy.findByText('Demo item 3').click() // choose a different item
|
|
cy.findByText('Demo item 3').click() // choose a different item
|
|
|
|
|
|
|
|
cy.findByText('submit').click()
|
|
cy.findByText('submit').click()
|
|
@@ -262,7 +262,7 @@ describe('<Select />', function () {
|
|
|
</div>
|
|
</div>
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- cy.findByRole('textbox', { name: 'Demo item 1' }).click() // open dropdown
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click() // open dropdown
|
|
|
cy.findByRole('option', { name: 'Demo item 3' }).click() // choose a different item
|
|
cy.findByRole('option', { name: 'Demo item 3' }).click() // choose a different item
|
|
|
|
|
|
|
|
cy.findByText('submit').click()
|
|
cy.findByText('submit').click()
|
|
@@ -275,11 +275,10 @@ describe('<Select />', function () {
|
|
|
describe('keyboard navigation', function () {
|
|
describe('keyboard navigation', function () {
|
|
|
it('can select an item using the keyboard', function () {
|
|
it('can select an item using the keyboard', function () {
|
|
|
render({ defaultText: 'Choose an item' })
|
|
render({ defaultText: 'Choose an item' })
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' }).type(
|
|
|
|
|
- '{Enter}{downArrow}{Enter}',
|
|
|
|
|
- { force: true }
|
|
|
|
|
- )
|
|
|
|
|
- cy.findByRole('textbox', { name: 'Demo item 1' }).should('exist')
|
|
|
|
|
|
|
+ cy.findByRole('combobox').type('{Enter}{downArrow}{Enter}', {
|
|
|
|
|
+ force: true,
|
|
|
|
|
+ })
|
|
|
|
|
+ cy.findByRole('combobox').should('exist')
|
|
|
cy.findByRole('option', { name: 'Demo item 2' }).should('not.exist')
|
|
cy.findByRole('option', { name: 'Demo item 2' }).should('not.exist')
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
@@ -290,9 +289,9 @@ describe('<Select />', function () {
|
|
|
defaultText: 'Choose an item',
|
|
defaultText: 'Choose an item',
|
|
|
selectedIcon: true,
|
|
selectedIcon: true,
|
|
|
})
|
|
})
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' }).click()
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
cy.findByRole('option', { name: 'Demo item 1' }).click()
|
|
cy.findByRole('option', { name: 'Demo item 1' }).click()
|
|
|
- cy.findByRole('textbox', { name: 'Demo item 1' }).click()
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
|
|
|
|
|
cy.findByText('check').should('exist')
|
|
cy.findByText('check').should('exist')
|
|
|
})
|
|
})
|
|
@@ -301,9 +300,9 @@ describe('<Select />', function () {
|
|
|
defaultText: 'Choose an item',
|
|
defaultText: 'Choose an item',
|
|
|
selectedIcon: false,
|
|
selectedIcon: false,
|
|
|
})
|
|
})
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' }).click()
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
cy.findByRole('option', { name: 'Demo item 1' }).click()
|
|
cy.findByRole('option', { name: 'Demo item 1' }).click()
|
|
|
- cy.findByRole('textbox', { name: 'Demo item 1' }).click()
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
|
|
|
|
|
cy.findByText('check').should('not.exist')
|
|
cy.findByText('check').should('not.exist')
|
|
|
})
|
|
})
|
|
@@ -315,7 +314,7 @@ describe('<Select />', function () {
|
|
|
defaultText: 'Choose an item',
|
|
defaultText: 'Choose an item',
|
|
|
itemToDisabled: x => x?.key === 2,
|
|
itemToDisabled: x => x?.key === 2,
|
|
|
})
|
|
})
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' }).click()
|
|
|
|
|
|
|
+ cy.findByRole('combobox').click()
|
|
|
cy.findByRole('option', { name: 'Demo item 2' }).click({ force: true })
|
|
cy.findByRole('option', { name: 'Demo item 2' }).click({ force: true })
|
|
|
// still showing other list items
|
|
// still showing other list items
|
|
|
cy.findByRole('option', { name: 'Demo item 3' }).should('exist')
|
|
cy.findByRole('option', { name: 'Demo item 3' }).should('exist')
|
|
@@ -331,7 +330,7 @@ describe('<Select />', function () {
|
|
|
defaultText: 'Choose an item',
|
|
defaultText: 'Choose an item',
|
|
|
selected: testData[1],
|
|
selected: testData[1],
|
|
|
})
|
|
})
|
|
|
- cy.findByRole('textbox', { name: 'Demo item 2' }).should('exist')
|
|
|
|
|
|
|
+ cy.findByRole('combobox').should('have.value', 'Demo item 2')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should show default text when selected is null', function () {
|
|
it('should show default text when selected is null', function () {
|
|
@@ -339,7 +338,7 @@ describe('<Select />', function () {
|
|
|
selected: null,
|
|
selected: null,
|
|
|
defaultText: 'Choose an item',
|
|
defaultText: 'Choose an item',
|
|
|
})
|
|
})
|
|
|
- cy.findByRole('textbox', { name: 'Choose an item' }).should('exist')
|
|
|
|
|
|
|
+ cy.findByRole('combobox').should('have.value', 'Choose an item')
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|