-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Feat: Add alert role for ValidationText #DS-1175
- Loading branch information
Showing
2 changed files
with
21 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
packages/web-react/src/components/Field/__tests__/ValidationText.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,32 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import ValidationText from '../ValidationText'; | ||
|
||
describe('ValidationText', () => { | ||
it('should render single validation text', () => { | ||
const dom = render(<ValidationText className="ValidationText__validationText" validationText="validation text" />); | ||
const { container } = render( | ||
<ValidationText className="ValidationText__validationText" validationText="validation text" />, | ||
); | ||
|
||
const element = dom.container.querySelector('div') as HTMLElement; | ||
expect(element.textContent).toBe('validation text'); | ||
expect(container.textContent).toBe('validation text'); | ||
expect(container.firstElementChild).toHaveAttribute('role', 'alert'); | ||
}); | ||
|
||
it('should render multiple validation texts', () => { | ||
const dom = render( | ||
render( | ||
<ValidationText | ||
className="ValidationText__validationText" | ||
validationText={['validation text', 'another validation text']} | ||
/>, | ||
); | ||
|
||
const elements = dom.container.querySelectorAll('li') as NodeListOf<HTMLLIElement>; | ||
expect(elements[0].textContent).toBe('validation text'); | ||
expect(elements[1].textContent).toBe('another validation text'); | ||
const list = screen.getByRole('list'); | ||
const listItems = screen.getAllByRole('listitem'); | ||
|
||
expect(listItems[0].textContent).toBe('validation text'); | ||
expect(listItems[1].textContent).toBe('another validation text'); | ||
|
||
expect(list.parentElement).toHaveAttribute('role', 'alert'); | ||
}); | ||
}); |