import { haveText, test, html, haveFocus, notHaveAttribute, haveAttribute, notHaveFocus, notHaveText } from '../../utils'
test('can trap focus',
[html`
`],
({ get }, reload) => {
get('#1').click()
get('#1').should(haveFocus())
get('#2').click()
get('#3').should(haveFocus())
cy.focused().tab()
get('#4').should(haveFocus())
cy.focused().tab()
get('#3').should(haveFocus())
cy.focused().tab({shift: true})
get('#4').should(haveFocus())
cy.focused().click()
get('#2').should(haveFocus())
},
)
test('works with clone',
[html`
`],
({ get, wait }, reload) => {
get('#one').click()
get('#two').click()
get('p').should(haveText('bar'))
}
)
test('releases focus when x-if is destroyed',
[html`
`],
({ get }, reload) => {
get('#1').click()
get('#2').should(haveFocus())
get('#2').click()
get('#1').should(haveFocus())
},
)
test('can trap focus with inert',
[html`
I should have aria-hidden when outside trap
`],
({ get }, reload) => {
get('#open').should(notHaveAttribute('aria-hidden', 'true'))
get('#open').click()
get('#open').should(haveAttribute('aria-hidden', 'true'))
get('#close').click()
get('#open').should(notHaveAttribute('aria-hidden', 'true'))
},
)
test('can trap focus with noscroll',
[html`
`],
({ get, window }, reload) => {
window().then((win) => {
let scrollbarWidth = win.innerWidth - win.document.documentElement.clientWidth
get('#open').click()
get('html').should(haveAttribute('style', `overflow: hidden; padding-right: ${scrollbarWidth}px;`))
get('#close').click()
get('html').should(notHaveAttribute('style', `overflow: hidden; padding-right: ${scrollbarWidth}px;`))
})
},
)
test('can trap focus with noreturn',
[html`
`],
({ get }) => {
get('#input').focus()
get('#close')
get('#close').click()
get('#input').should(notHaveFocus())
},
)
test('$focus.focus',
[html`
`],
({ get }) => {
get('#focus-me').should(notHaveFocus())
get('#press-me').click()
get('#focus-me').should(haveFocus())
},
)
test('$focus.focusable',
[html`
`],
({ get }) => {
get('#1').should(haveText('false'))
get('#2').should(haveText('true'))
},
)
test('$focus.focusables',
[html`
`],
({ get }) => {
get('h1').should(haveText('2'))
},
)
test('$focus.focused',
[html`
`],
({ get }) => {
get('button').click()
get('button').should(haveText('true'))
},
)
test('$focus.lastFocused',
[html`
`],
({ get }) => {
get('#1').click()
get('#2').click()
get('#2').should(haveText('true'))
},
)
test('$focus.within',
[html`
`],
({ get }) => {
get('#1').should(haveText('2'))
},
)
test('$focus.next',
[html`
`],
({ get }) => {
get('#1').click()
get('#1').should(haveText('2'))
},
)
test('$focus.prev',
[html`
`],
({ get }) => {
get('#1').click()
get('#1').should(haveText('2'))
},
)
test('$focus.wrap',
[html`
`],
({ get }) => {
get('#1').click()
get('#1').should(haveText('2'))
},
)
test('$focus.first',
[html`
`],
({ get }) => {
get('#1').click()
get('#1').should(haveText('2'))
},
)
test('$focus.last',
[html`
`],
({ get }) => {
get('#1').click()
get('#1').should(haveText('3'))
},
)