Skip to content

Commit

Permalink
test(radio-tile): increase coverage (#17741)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Datilio Ribeiro <[email protected]>
  • Loading branch information
ariellalgilmore and guidari authored Oct 17, 2024
1 parent e840ffd commit d1c7569
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion packages/react/src/components/RadioTile/RadioTile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import React from 'react';
import RadioTile from './RadioTile';
import { AILabel } from '../AILabel';
import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';
import { FeatureFlags } from '../FeatureFlags';

describe('RadioTile', () => {
describe('renders as expected - Component API', () => {
Expand Down Expand Up @@ -92,8 +94,9 @@ describe('RadioTile', () => {
);

await userEvent.click(screen.getByRole('radio'));
await userEvent.keyboard('{Enter}');

expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenCalledTimes(2);
});

it('should respect tabIndex prop', () => {
Expand Down Expand Up @@ -132,4 +135,32 @@ describe('RadioTile', () => {
expect(screen.getByRole('radio')).toHaveAttribute('required');
});
});

it('should check AILabel exists on radio tile and is xs', async () => {
render(
<RadioTile value="standard" slug={<AILabel />}>
{' '}
Option 1{' '}
</RadioTile>
);
expect(screen.getByRole('button')).toHaveClass(`cds--slug__button--xs`);
});

//Feature flag : enable-v12-tile-radio-icons
it('should have a checked attribute if the prop checked is provided', () => {
render(
<FeatureFlags enableV12TileRadioIcons>
<RadioTile id="test-1" value="test-1" checked>
Option 1
</RadioTile>
</FeatureFlags>
);

expect(screen.getByDisplayValue('test-1')).toEqual(
screen.getByRole('radio', {
checked: true,
name: 'Option 1',
})
);
});
});

0 comments on commit d1c7569

Please sign in to comment.