import { beHidden, beVisible, haveText, beChecked, haveAttribute, haveClasses, haveProperty, haveValue, notBeChecked, notHaveAttribute, notHaveClasses, test, html } from '../../utils';
test('sets attribute bindings on initialize',
html`
[Subject]
`,
({ get }) => get('span').should(haveAttribute('foo', 'bar'))
)
test('sets undefined nested keys to empty string',
html`
`,
({ get }) => get('span').should(haveAttribute('foo', ''))
)
test('style attribute bindings are added by string syntax',
html`
`,
({ get }) => get('span').should(haveClasses(['foo']))
)
test('aria-pressed/checked/expanded/selected attribute boolean values are cast to a true/false string',
html`
`,
({ get }) => {
get('span:nth-of-type(1)').should(haveAttribute('aria-pressed', 'true'))
get('span:nth-of-type(2)').should(haveAttribute('aria-checked', 'true'))
get('span:nth-of-type(3)').should(haveAttribute('aria-expanded', 'true'))
get('span:nth-of-type(4)').should(haveAttribute('aria-selected', 'true'))
get('span:nth-of-type(5)').should(haveAttribute('aria-pressed', 'false'))
get('span:nth-of-type(6)').should(haveAttribute('aria-checked', 'false'))
get('span:nth-of-type(7)').should(haveAttribute('aria-expanded', 'false'))
get('span:nth-of-type(8)').should(haveAttribute('aria-selected', 'false'))
}
)
test('non-boolean attributes set to null/undefined/false are removed from the element',
html`
`,
({ get }) => {
get('a:nth-of-type(1)').should(notHaveAttribute('href'))
get('a:nth-of-type(2)').should(notHaveAttribute('href'))
get('a:nth-of-type(3)').should(notHaveAttribute('href'))
get('span:nth-of-type(1)').should(notHaveAttribute('visible'))
get('span:nth-of-type(2)').should(notHaveAttribute('visible'))
get('span:nth-of-type(3)').should(notHaveAttribute('visible'))
get('span:nth-of-type(4)').should(notHaveAttribute('hidden'))
get('span:nth-of-type(5)').should(notHaveAttribute('hidden'))
get('span:nth-of-type(6)').should(notHaveAttribute('hidden'))
}
)
test('non-boolean empty string attributes are not removed',
html`
`,
({ get }) => get('a').should(haveAttribute('href', ''))
)
test('boolean attribute values are set to their attribute name if true and removed if false',
html`
`,
({ get }) => {
get('span').should(beVisible())
get('button').click()
get('span').should(beVisible())
get('span').should(beHidden())
}
)
test('x-bind object syntax event handlers defined as functions receive the event object as their first argument',
html`
foo
`,
({ get }) => {
get('span').should(haveText('foo'))
get('button').click()
get('span').should(haveText('bar'))
}
)
test('x-bind object syntax event handlers defined as functions receive element bound magics',
html`
foo
`,
({ get }) => {
get('span').should(haveText('foo'))
get('button').click()
get('span').should(haveText('bar'))
}
)
test('Can retrieve Alpine bound data with global bound method',
html`
`,
({ get }) => {
get('#1').should(haveText('bar'))
get('#2').should(haveText('bar'))
get('#3').should(haveText('true'))
get('#4').should(haveText('true'))
get('#5').should(haveText(''))
get('#6').should(haveText('bar'))
}
)
test('Can extract Alpine bound data as a data prop',
html`
`,
({ get }) => {
get('#1').should(haveText('bar'))
get('#1').should(notHaveAttribute('foo'))
get('#2').should(haveText('bar'))
get('#2').should(haveAttribute('foo', 'bar'))
}
)
test('x-bind updates checked attribute and property after user interaction',
html`