import { haveAttribute, haveComputedStyle, html, notHaveAttribute, test } from '../../utils'
test('can collapse and expand element',
[html`
`],
({ get }, reload) => {
get('h1').should(haveComputedStyle('height', '0px'))
get('h1').should(haveAttribute('style', 'display: none; height: 0px; overflow: hidden;'))
get('h1').should(haveAttribute('hidden', 'hidden'))
get('button').click()
get('h1').should(haveAttribute('style', 'height: auto;'))
get('h1').should(notHaveAttribute('hidden'))
get('button').click()
get('h1').should(haveComputedStyle('height', '0px'))
get('h1').should(haveAttribute('style', 'height: 0px; overflow: hidden; display: none;'))
get('h1').should(haveAttribute('hidden', 'hidden'))
},
)
test('can collapse and expand with a minimum height instead of "display: none"',
[html`
`],
({ get }) => {
get('h1').should(haveComputedStyle('height', '25px'))
get('h1').should(haveAttribute('style', 'height: 25px; overflow: hidden;'))
get('h1').should(notHaveAttribute('hidden', 'hidden'))
get('button').click()
get('h1').should(haveAttribute('style', 'height: auto;'))
get('button').click()
get('h1').should(haveComputedStyle('height', '25px'))
get('h1').should(haveAttribute('style', 'height: 25px; overflow: hidden;'))
},
)
test('@click.away with x-collapse (prevent race condition)',
html`
h1
`,
({ get }) => {
get('h1').should(haveComputedStyle('height', '0px'))
get('button').click()
get('h1').should(haveAttribute('style', 'height: auto;'))
}
)
test('@click.away with x-collapse and borders (prevent race condition)',
html`
h1
`,
({ get }) => {
get('h1').should(haveComputedStyle('height', '0px'))
get('button').click()
get('h1').should(haveAttribute('style', 'height: auto;'))
}
)
// https://github.com/alpinejs/alpine/issues/2335
test('double-click on x-collapse does not mix styles up',
[html`
contents
`],
({ get }, reload) => {
get('h1').should(haveComputedStyle('height', '0px'))
get('h1').should(haveAttribute('style', 'display: none; height: 0px; overflow: hidden;'))
get('button').click()
get('button').click()
get('h1').should(haveAttribute('style', 'height: 0px; overflow: hidden; display: none;'))
get('button').click()
get('h1').should(haveAttribute('style', 'height: auto;'))
get('button').click()
get('button').click()
get('h1').should(haveAttribute('style', 'height: auto;'))
},
)