Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcfaul committed Nov 15, 2023
1 parent 5085ba6 commit 3623984
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ test('Renders default classes', () => {

test('Renders id when id is passed', () => {
render(<HelperText id="helper-id">text </HelperText>);
expect(screen.getByText('text')).toHaveAttribute('id');
expect(screen.getByText('text')).toHaveAttribute('id', 'helper-id');
});

test('Renders aria-live when isLiveRegion is passed', () => {
render(<HelperText isLiveRegion>text </HelperText>);
expect(screen.getByText('text')).toHaveAttribute('aria-live');
expect(screen.getByText('text')).toHaveAttribute('aria-live', 'polite');
});

test('Spreads additional props when passed', () => {
test('Does not render aria-live by default', () => {
render(<HelperText>text </HelperText>);
expect(screen.getByText('text')).toBeInTheDocument();
expect(screen.getByText('text')).not.toHaveAttribute('aria-live');
});

test('Spreads additional props when passed', () => {
render(<HelperText dir="rtl">text </HelperText>);
expect(screen.getByText('text')).toHaveAttribute('dir', 'rtl');
});

test('Renders custom className', () => {
Expand All @@ -49,6 +54,11 @@ test('Renders with element passed to component prop', () => {
expect(screen.getByText('text').tagName).toBe('UL');
});

test('Renders with div by default when no component prop is passed', () => {
render(<HelperText>text</HelperText>);
expect(screen.getByText('text').tagName).toBe('DIV');
});

test('Renders aria-label and role when component = ul', () => {
render(
<HelperText component="ul" aria-label="helper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,12 @@ test('Renders dynamic helper text', () => {
expect(screen.getByText('help test text').parentElement).toHaveClass(styles.modifiers.dynamic);
expect(screen.getByText('help test text').querySelector('span')).toHaveClass('pf-v5-screen-reader');
});

test('Renders custom screenreader text when isDynamic = true and screenReaderText is passed', () => {
render(
<HelperTextItem isDynamic screenReaderText="sr test">
help test text
</HelperTextItem>
);
expect(screen.getByText('help test text').querySelector('span')).toHaveTextContent('sr test');
});

0 comments on commit 3623984

Please sign in to comment.