Skip to content

Commit

Permalink
Move axe test down
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Jan 5, 2024
1 parent 1e3d7a9 commit 726fa5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function NumberComponent(props: Props) {
handleChange,
} = useDataValue(preparedProps)

const ariaParams = {
const ariaParams = showStepControls && {
role: 'spinbutton',
'aria-valuemin': props.minimum,
'aria-valuemax': props.maximum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,6 @@ describe('Field.Number', () => {
})
})

it('should validate with ARIA rules', async () => {
const element = render(
<Field.Number label="Label" required validateInitially />
)

expect(await axeComponent(element)).toHaveNoViolations()
})

describe('with step controls', () => {
it('renders with control buttons', () => {
render(<Field.Number showStepControls />)
Expand All @@ -254,6 +246,7 @@ describe('Field.Number', () => {

it('controls input value correctly using arrow keys', async () => {
render(<Field.Number showStepControls value={0} step={10} />)

const input = document.querySelector('input')

act(() => {
Expand All @@ -279,16 +272,21 @@ describe('Field.Number', () => {
step={3}
/>
)

const input = document.querySelector('input')
const buttons = document.getElementsByClassName('dnb-button')
const decreaseButton = buttons[0]
const increaseButton = buttons[1]

fireEvent.click(increaseButton)
expect(input.value).toBe('2')

fireEvent.click(increaseButton)
expect(input.value).toBe('2')

fireEvent.click(decreaseButton)
expect(input.value).toBe('0')

fireEvent.click(decreaseButton)
expect(input.value).toBe('0')
})
Expand All @@ -302,6 +300,7 @@ describe('Field.Number', () => {
step: 5,
}
render(<Field.Number {...settings} />)

const ariaElements = document.querySelectorAll(
'.dnb-input__input, .dnb-button'
)
Expand All @@ -320,4 +319,12 @@ describe('Field.Number', () => {
})
})
})

it('should validate with ARIA rules', async () => {
const element = render(
<Field.Number label="Label" required validateInitially />
)

expect(await axeComponent(element)).toHaveNoViolations()
})
})

0 comments on commit 726fa5c

Please sign in to comment.