import { haveAttribute, haveText, html, test } from '../../utils'
test('$id generates a unique id',
html`
`,
({ get }) => {
get('#1 h1').should(haveAttribute('id', 'foo-1'))
get('#1 span').should(haveAttribute('aria-labelledby', 'foo-1'))
get('#2 h1').should(haveAttribute('id', 'foo-2'))
get('#2 span').should(haveAttribute('aria-labelledby', 'foo-2'))
}
)
test('$id works with keys and nested data scopes',
html`
`,
({ get }) => {
get('#1 span').should(haveAttribute('aria-activedescendant', 'foo-1-3'))
get('#1 li:nth-child(1)').should(haveAttribute('id', 'foo-1-1'))
get('#1 li:nth-child(2)').should(haveAttribute('id', 'foo-1-2'))
get('#1 li:nth-child(3)').should(haveAttribute('id', 'foo-1-3'))
get('#2 span').should(haveAttribute('aria-activedescendant', 'foo-2-3'))
get('#2 li:nth-child(1)').should(haveAttribute('id', 'foo-2-1'))
get('#2 li:nth-child(2)').should(haveAttribute('id', 'foo-2-2'))
get('#2 li:nth-child(3)').should(haveAttribute('id', 'foo-2-3'))
}
)
test('$id scopes are grouped by name',
html`
`,
({ get }) => {
get('span').should(haveAttribute('aria-activedescendant', 'foo-1'))
get('li:nth-child(1)').should(haveAttribute('id', 'bar-1'))
get('li:nth-child(2)').should(haveAttribute('id', 'bar-2'))
}
)
test('$ids are globally unique when outside x-id',
html`
`,
({ get }) => {
get('h1').should(haveAttribute('id', 'foo-1'))
get('h2').should(haveAttribute('id', 'foo-2'))
}
)
test('$id scopes can be reset',
html`
`,
({ get }) => {
get('span').should(haveAttribute('aria-labelledby', 'foo-1'))
get('h1').should(haveAttribute('id', 'foo-1'))
get('h2').should(haveAttribute('aria-labelledby', 'foo-2'))
get('h3').should(haveAttribute('id', 'foo-2'))
get('h4').should(haveAttribute('id', 'foo-1'))
get('h5').should(haveAttribute('id', 'bar-1'))
get('h6').should(haveAttribute('aria-labelledby', 'bar-1'))
}
)