@@ -6,10 +6,8 @@ import { setupRtl } from 'component-test-setup';
66import { IconButton } from '../IconButton' ;
77import { IconButtonFloatingMock } from './mocks' ;
88
9- const label = 'Click ' ;
9+ const label = 'Aria gonna click this button? ' ;
1010const tip = 'Click this button' ;
11- const tipText = 'this button' ;
12- const uniqueTip = 'I am not repetitive text' ;
1311
1412const onClick = jest . fn ( ) ;
1513const buttonProps = {
@@ -39,55 +37,37 @@ describe('IconButton', () => {
3937 view . getByRole ( 'img' , { hidden : true } ) ;
4038 } ) ;
4139
42- // TO-DO: When we upgrade jest, we can use `description` in the tests below to make sure they are semantically connected to buttons.
43- it ( 'renders a tip with repetition removed' , async ( ) => {
40+ it ( 'renders the tip text from the tip prop' , async ( ) => {
4441 const { view } = renderView ( { } ) ;
4542
46- const button = view . getByRole ( 'button' , { name : label } ) ;
43+ view . getByRole ( 'button' , { name : label } ) ;
4744
48- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
49- // @ts -ignore: We need to update the rest of the testing suite to use the correct types (which are reliant on upgrading Node)
50- expect ( button ) . toHaveAccessibleDescription ( tipText ) ;
51- expect ( view . getByRole ( 'tooltip' , { hidden : true } ) ) . toHaveTextContent (
52- tipText
53- ) ;
45+ expect ( view . getByRole ( 'tooltip' , { hidden : true } ) ) . toHaveTextContent ( tip ) ;
5446 } ) ;
5547
56- it ( 'renders a tip with both labels when they are not repetitive ' , async ( ) => {
57- const { view } = renderView ( { tip : uniqueTip } ) ;
48+ it ( 'sets the aria-label as the tip when only the tip prop is provided ' , async ( ) => {
49+ const { view } = renderView ( { 'aria-label' : '' } ) ;
5850
59- view . getByRole ( 'button' , { name : label } ) ;
60- expect ( view . getByRole ( 'tooltip' , { hidden : true } ) ) . toHaveTextContent (
61- uniqueTip
62- ) ;
51+ view . getByRole ( 'button' , { name : tip } ) ;
52+ expect ( view . getByRole ( 'tooltip' , { hidden : true } ) ) . toHaveTextContent ( tip ) ;
6353 } ) ;
6454
65- it ( 'renders a true aria-label based on tip when aria-label is not defined ' , async ( ) => {
66- const { view } = renderView ( { 'aria-label' : undefined } ) ;
55+ it ( 'sets the aria-label text from the aria-label prop when both the tip and aria-label is provided ' , async ( ) => {
56+ const { view } = renderView ( { 'aria-label' : '' } ) ;
6757
68- view . getByRole ( 'button' , { name : label } ) ;
69- expect ( view . getByRole ( 'tooltip' , { hidden : true } ) ) . toHaveTextContent (
70- tipText
71- ) ;
58+ view . getByRole ( 'button' , { name : tip } ) ;
59+ expect ( view . getByRole ( 'tooltip' , { hidden : true } ) ) . toHaveTextContent ( tip ) ;
7260 } ) ;
7361
7462 it ( 'renders a floating tip' , async ( ) => {
7563 const { view } = renderFloatingView ( { } ) ;
7664
77- expect ( view . getByRole ( 'tooltip' , { hidden : true } ) ) . toHaveTextContent (
78- tipText
79- ) ;
80-
81- expect ( view . queryByText ( tip ) ) . toBeNull ( ) ;
65+ expect ( view . queryAllByText ( tip ) . length ) . toBe ( 1 ) ;
8266
8367 const cta = view . getByRole ( 'button' , { name : label } ) ;
8468
85- expect ( view . queryByText ( 'tooltip' ) ) . toBeNull ( ) ;
86-
8769 await userEvent . hover ( cta ) ;
8870
89- await waitFor ( ( ) => {
90- view . getByText ( tip ) ;
91- } ) ;
71+ await waitFor ( ( ) => expect ( view . queryAllByText ( tip ) . length ) . toBe ( 2 ) ) ;
9272 } ) ;
9373} ) ;
0 commit comments