import { beVisible, haveAttribute, haveText, html, notBeVisible, notExist, test } from '../../../utils'
test('has accessibility attributes',
[html`
`],
({ get }) => {
get('article').should(haveAttribute('role', 'dialog'))
get('article').should(haveAttribute('aria-modal', 'true'))
},
)
test('works with x-model',
[html`
`],
({ get }) => {
get('article').should(notBeVisible())
get('button').click()
get('article').should(beVisible())
get('button').click()
get('article').should(notBeVisible())
},
)
test('works with open prop and close event',
[html`
`],
({ get }) => {
get('article').should(notBeVisible())
get('button').click()
get('article').should(beVisible())
},
)
test('works with static prop',
[html`
`],
({ get }) => {
get('article').should(notExist())
get('button').click()
get('article').should(beVisible())
},
)
test('pressing escape closes modal',
[html`
`],
({ get }) => {
get('article').should(notBeVisible())
get('button').click()
get('article').should(beVisible())
get('input').type('{esc}')
get('article').should(notBeVisible())
},
)
test('x-dialog:panel allows for click away',
[html`
Click away on me
Dialog Contents!
`],
({ get }) => {
get('article').should(beVisible())
get('h1').click()
get('article').should(notBeVisible())
},
)
test('x-dialog:overlay closes dialog when clicked on',
[html`
Click away on me
Some Overlay
Dialog Contents!
`],
({ get }) => {
get('article').should(beVisible())
get('h1').click()
get('article').should(beVisible())
get('main').click()
get('article').should(notBeVisible())
},
)
test('x-dialog:title',
[html`
Dialog Title
`],
({ get }) => {
get('article').should(haveAttribute('aria-labelledby', 'alpine-dialog-title-1'))
get('h1').should(haveAttribute('id', 'alpine-dialog-title-1'))
},
)
test('x-dialog:description',
[html`
Dialog Title
`],
({ get }) => {
get('article').should(haveAttribute('aria-describedby', 'alpine-dialog-description-1'))
get('p').should(haveAttribute('id', 'alpine-dialog-description-1'))
},
)
test('$modal.open exposes internal "open" state',
[html`
`],
({ get }) => {
get('h2').should(haveText('false'))
get('button').click()
get('h2').should(haveText('true'))
},
)
test('works with x-teleport',
[html`
`],
({ get }) => {
get('article').should(notBeVisible())
get('button').click()
get('article').should(beVisible())
get('button').click()
get('article').should(notBeVisible())
},
)
// Skipping these two tests as anything focus related seems to be flaky
// with cypress, but fine in a real browser.
// test('x-dialog traps focus'...
// test('initial-focus prop'...