@@ -40,14 +40,83 @@ describe("Button", () => {
4040 expect ( button ) . toHaveAttribute ( "aria-disabled" , "true" ) ;
4141 } ) ;
4242
43- it ( "should have aria-disabled when loading" , ( ) => {
44- const { getByRole } = renderButton ( {
45- label : "Button" ,
46- loading : true ,
43+ describe ( "Loading state" , ( ) => {
44+ it ( "should have aria-disabled when loading" , ( ) => {
45+ const { getByRole } = renderButton ( {
46+ label : "Button" ,
47+ loading : true ,
48+ } ) ;
49+ const button = getByRole ( "button" ) ;
50+
51+ expect ( button ) . toBeDisabled ( ) ;
52+ expect ( button ) . toHaveAttribute ( "aria-disabled" , "true" ) ;
4753 } ) ;
48- const button = getByRole ( "button" ) ;
4954
50- expect ( button ) . toBeDisabled ( ) ;
51- expect ( button ) . toHaveAttribute ( "aria-disabled" , "true" ) ;
55+ it ( "should not execute onClick when loading" , ( ) => {
56+ let counter = 0 ;
57+ const handleClick = ( ) => ( counter = 1 ) ;
58+ const { getByRole } = renderButton ( {
59+ onClick : handleClick ,
60+ label : "Button" ,
61+ loading : true ,
62+ } ) ;
63+ const button = getByRole ( "button" ) ;
64+ fireEvent . click ( button ) ;
65+
66+ expect ( counter ) . toEqual ( 0 ) ;
67+ } ) ;
68+
69+ it ( "should still render the label when loading" , ( ) => {
70+ const { getByText } = renderButton ( {
71+ label : "Loading Button" ,
72+ loading : true ,
73+ } ) ;
74+
75+ expect ( getByText ( "Loading Button" ) ) . toBeInTheDocument ( ) ;
76+ } ) ;
77+
78+ it ( "should render loading state for primary button type" , ( ) => {
79+ const { getByRole } = renderButton ( {
80+ label : "Button" ,
81+ type : "primary" ,
82+ loading : true ,
83+ } ) ;
84+ const button = getByRole ( "button" ) ;
85+
86+ expect ( button ) . toBeDisabled ( ) ;
87+ } ) ;
88+
89+ it ( "should render loading state for secondary button type" , ( ) => {
90+ const { getByRole } = renderButton ( {
91+ label : "Button" ,
92+ type : "secondary" ,
93+ loading : true ,
94+ } ) ;
95+ const button = getByRole ( "button" ) ;
96+
97+ expect ( button ) . toBeDisabled ( ) ;
98+ } ) ;
99+
100+ it ( "should render loading state for danger button type" , ( ) => {
101+ const { getByRole } = renderButton ( {
102+ label : "Button" ,
103+ type : "danger" ,
104+ loading : true ,
105+ } ) ;
106+ const button = getByRole ( "button" ) ;
107+
108+ expect ( button ) . toBeDisabled ( ) ;
109+ } ) ;
110+
111+ it ( "should render loading state for empty button type" , ( ) => {
112+ const { getByRole } = renderButton ( {
113+ label : "Button" ,
114+ type : "empty" ,
115+ loading : true ,
116+ } ) ;
117+ const button = getByRole ( "button" ) ;
118+
119+ expect ( button ) . toBeDisabled ( ) ;
120+ } ) ;
52121 } ) ;
53122} ) ;
0 commit comments