import { haveText, test, html, haveFocus, notHaveAttribute, haveAttribute } 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('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;`))
})
},
)