test: aria-label check (#1133)

* Install jest-each

* Add accessibility.spec.tsx

It render App and click button to render context menu.
Then it check if aria-label exists.

* restore lock

* Delete package-lock.json

* Update accessibility.spec.tsx

---------

Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
This commit is contained in:
Jang Min 2023-03-10 04:59:31 +09:00 committed by GitHub
parent d00c06144d
commit 967efd6b7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,51 @@
import { fireEvent, render } from '@testing-library/react'
import { Tldraw } from '../Tldraw'
const toolIds = [
'TD-PrimaryTools-CursorArrow',
'TD-PrimaryTools-Pencil',
'TD-PrimaryTools-Eraser',
'TD-PrimaryTools-Shapes',
'TD-PrimaryTools-Shapes-rectangle',
'TD-PrimaryTools-Shapes-ellipse',
'TD-PrimaryTools-Shapes-triangle',
'TD-PrimaryTools-Shapes-line',
'TD-PrimaryTools-ArrowTopRight',
'TD-PrimaryTools-Text',
'TD-PrimaryTools-Pencil2',
'TD-PrimaryTools-Image',
]
const dashAndSizeIds = [
'TD-Styles-Dash-draw',
'TD-Styles-Dash-solid',
'TD-Styles-Dash-dashed',
'TD-Styles-Dash-dotted',
'TD-Styles-Dash-small',
'TD-Styles-Dash-medium',
'TD-Styles-Dash-large',
]
describe('tool buttons accessibility', () => {
const { container } = render(<Tldraw />)
const testButtons = (buttonId: string, ids: Array<string>) => {
const button = container.querySelector(`#${buttonId}`)
if (!button) return
fireEvent.click(button)
describe(`accessibility`, () => {
for (const id of ids) {
it(`component ${id} has aria-label`, async () => {
const element = container.querySelector(`#${id}`)
const ariaLabel = element?.getAttribute('aria-label')
// eslint-disable-next-line jest/no-standalone-expect
expect(ariaLabel).not.toBeNull()
})
}
})
}
testButtons('TD-PrimaryTools-Shapes', toolIds)
testButtons('TD-Styles', dashAndSizeIds)
})