Skip to content

Commit

Permalink
Revert "fixup! Feat: Add alert role for ValidationText #DS-1175"
Browse files Browse the repository at this point in the history
This reverts commit 3d24876.
  • Loading branch information
curdaj committed May 9, 2024
1 parent b71c35e commit acff7f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
12 changes: 5 additions & 7 deletions packages/web-react/src/components/Field/ValidationText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ export const ValidationText = <T extends ElementType = 'div'>(props: ValidationT

if (validationText) {
return Array.isArray(validationText) ? (
<div role="alert">
<ul className={className} id={id}>
{validationText.map((item) => (
<li key={`validationText_${item}`}>{item}</li>
))}
</ul>
</div>
<ul className={className} id={id} role="alert">
{validationText.map((item) => (
<li key={`validationText_${item}`}>{item}</li>
))}
</ul>
) : (
<ElementTag className={className} id={id} role="alert">
{validationText}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom';
import ValidationText from '../ValidationText';

describe('ValidationText', () => {
it('should render single validation text', () => {
const { container } = render(
<ValidationText className="ValidationText__validationText" validationText="validation text" />,
);
const dom = render(<ValidationText className="ValidationText__validationText" validationText="validation text" />);

expect(container.textContent).toBe('validation text');
expect(container.firstElementChild).toHaveAttribute('role', 'alert');
const element = dom.container.querySelector('div') as HTMLElement;
expect(element.textContent).toBe('validation text');
});

it('should render multiple validation texts', () => {
render(
const dom = render(
<ValidationText
className="ValidationText__validationText"
validationText={['validation text', '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');
const elements = dom.container.querySelectorAll('li') as NodeListOf<HTMLLIElement>;
expect(elements[0].textContent).toBe('validation text');
expect(elements[1].textContent).toBe('another validation text');
});
});

0 comments on commit acff7f8

Please sign in to comment.