Skip to content

Commit

Permalink
test: adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
2nikhiltom committed Jan 23, 2025
1 parent 44fa46c commit b58e020
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions packages/react/src/components/AILabel/__tests__/AILabel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,25 @@ describe('AILabelActions', () => {

expect(screen.getByText('View details')).toBeInTheDocument();
});
describe('Labels and kind prop', () => {
it('should use empty label for inline kind', () => {
render(<AILabel kind="inline" aiText="AI" textLabel="Text goes here" />);
expect(screen.getByRole('button')).toHaveAttribute('aria-label', '');
});

it('should set aria-label when kind is default', () => {
render(<AILabel aiText="AI" />);
expect(screen.getByRole('button')).toHaveAttribute(
'aria-label',
'AI Show information'
);
});

it('should let visible text serve as accessible name in inline mode', () => {
render(<AILabel kind="inline" aiText="AI" textLabel="Text goes here" />);
expect(
screen.getByRole('button', { name: 'AI Text goes here' })
).toBeInTheDocument();
});
});
});
2 changes: 1 addition & 1 deletion packages/react/src/components/AILabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export const AILabel = React.forwardRef<HTMLDivElement, AILabelProps>(
{...rest}>
<ToggletipButton
className={aiLabelButtonClasses}
label={kind === 'inline' ? null : ariaLabelText}>
label={kind === 'inline' ? '' : ariaLabelText}>
<span className={`${prefix}--ai-label__text`}>{aiText}</span>
{kind === 'inline' && (aiTextLabel || textLabel) && (
<span className={`${prefix}--ai-label__additional-text`}>
Expand Down

0 comments on commit b58e020

Please sign in to comment.