From d1c7569dfe4122896072a12b13e8e36f6cd94488 Mon Sep 17 00:00:00 2001 From: Ariella Gilmore Date: Thu, 17 Oct 2024 11:04:47 -0700 Subject: [PATCH] test(radio-tile): increase coverage (#17741) Co-authored-by: Guilherme Datilio Ribeiro --- .../components/RadioTile/RadioTile-test.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/react/src/components/RadioTile/RadioTile-test.js b/packages/react/src/components/RadioTile/RadioTile-test.js index 7b91f4e66a47..7f123a53e21e 100644 --- a/packages/react/src/components/RadioTile/RadioTile-test.js +++ b/packages/react/src/components/RadioTile/RadioTile-test.js @@ -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', () => { @@ -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', () => { @@ -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( + }> + {' '} + Option 1{' '} + + ); + 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( + + + Option 1 + + + ); + + expect(screen.getByDisplayValue('test-1')).toEqual( + screen.getByRole('radio', { + checked: true, + name: 'Option 1', + }) + ); + }); });