@@ -97,7 +97,7 @@ describe('SubscriptionDetails', () => {
9797 ] ,
9898 } ) ;
9999
100- const { getByRole, getByText, queryByText, getAllByText, userEvent } = render (
100+ const { getByRole, getByText, queryByText, getAllByText } = render (
101101 < Drawer . Root
102102 open
103103 onOpenChange = { ( ) => { } }
@@ -130,12 +130,8 @@ describe('SubscriptionDetails', () => {
130130 expect ( queryByText ( 'Ends on' ) ) . toBeNull ( ) ;
131131 } ) ;
132132
133- const menuButton = getByRole ( 'button' , { name : / O p e n m e n u / i } ) ;
134- expect ( menuButton ) . toBeVisible ( ) ;
135- await userEvent . click ( menuButton ) ;
136-
137133 await waitFor ( ( ) => {
138- expect ( getByText ( 'Switch to annual $100 / year ' ) ) . toBeVisible ( ) ;
134+ expect ( getByText ( 'Switch to annual' ) ) . toBeVisible ( ) ;
139135 expect ( getByText ( 'Cancel subscription' ) ) . toBeVisible ( ) ;
140136 } ) ;
141137 } ) ;
@@ -204,7 +200,7 @@ describe('SubscriptionDetails', () => {
204200 ] ,
205201 } ) ;
206202
207- const { getByRole, getByText, queryByText, getAllByText, userEvent } = render (
203+ const { getByRole, getByText, queryByText, getAllByText } = render (
208204 < Drawer . Root
209205 open
210206 onOpenChange = { ( ) => { } }
@@ -237,12 +233,8 @@ describe('SubscriptionDetails', () => {
237233 expect ( queryByText ( 'Ends on' ) ) . toBeNull ( ) ;
238234 } ) ;
239235
240- const menuButton = getByRole ( 'button' , { name : / O p e n m e n u / i } ) ;
241- expect ( menuButton ) . toBeVisible ( ) ;
242- await userEvent . click ( menuButton ) ;
243-
244236 await waitFor ( ( ) => {
245- expect ( getByText ( 'Switch to monthly $10 / month ' ) ) . toBeVisible ( ) ;
237+ expect ( getByText ( 'Switch to monthly' ) ) . toBeVisible ( ) ;
246238 expect ( getByText ( 'Cancel subscription' ) ) . toBeVisible ( ) ;
247239 } ) ;
248240 } ) ;
@@ -293,7 +285,7 @@ describe('SubscriptionDetails', () => {
293285 ] ,
294286 } ) ;
295287
296- const { getByRole, getByText, queryByText, queryByRole } = render (
288+ const { getByRole, getByText, queryByText } = render (
297289 < Drawer . Root
298290 open
299291 onOpenChange = { ( ) => { } }
@@ -319,7 +311,9 @@ describe('SubscriptionDetails', () => {
319311 expect ( queryByText ( 'Monthly' ) ) . toBeNull ( ) ;
320312 expect ( queryByText ( 'Next payment on' ) ) . toBeNull ( ) ;
321313 expect ( queryByText ( 'Next payment amount' ) ) . toBeNull ( ) ;
322- expect ( queryByRole ( 'button' , { name : / O p e n m e n u / i } ) ) . toBeNull ( ) ;
314+
315+ expect ( queryByText ( 'Cancel subscription' ) ) . toBeNull ( ) ;
316+ expect ( queryByText ( / S w i t c h t o / i) ) . toBeNull ( ) ;
323317 } ) ;
324318 } ) ;
325319
@@ -436,7 +430,7 @@ describe('SubscriptionDetails', () => {
436430 ] ,
437431 } ) ;
438432
439- const { getByRole, getByText, getAllByText, queryByText, getAllByRole , userEvent } = render (
433+ const { getByRole, getByText, getAllByText, queryByText } = render (
440434 < Drawer . Root
441435 open
442436 onOpenChange = { ( ) => { } }
@@ -469,20 +463,10 @@ describe('SubscriptionDetails', () => {
469463 expect ( getByText ( 'Begins on' ) ) . toBeVisible ( ) ;
470464 } ) ;
471465
472- const [ menuButton , upcomingMenuButton ] = getAllByRole ( 'button' , { name : / O p e n m e n u / i } ) ;
473- await userEvent . click ( menuButton ) ;
474-
475466 await waitFor ( ( ) => {
476- expect ( getByText ( 'Switch to monthly $13 / month ' ) ) . toBeVisible ( ) ;
467+ expect ( getByText ( 'Switch to monthly' ) ) . toBeVisible ( ) ;
477468 expect ( getByText ( 'Resubscribe' ) ) . toBeVisible ( ) ;
478- expect ( queryByText ( 'Cancel subscription' ) ) . toBeNull ( ) ;
479- } ) ;
480-
481- await userEvent . click ( upcomingMenuButton ) ;
482-
483- await waitFor ( ( ) => {
484- expect ( getByText ( 'Switch to annual $90.99 / year' ) ) . toBeVisible ( ) ;
485- expect ( getByText ( 'Cancel subscription' ) ) . toBeVisible ( ) ;
469+ expect ( getAllByText ( 'Cancel subscription' ) . length ) . toBe ( 1 ) ;
486470 } ) ;
487471 } ) ;
488472
@@ -694,7 +678,7 @@ describe('SubscriptionDetails', () => {
694678 ] ,
695679 } ) ;
696680
697- const { getByRole , getByText , userEvent } = render (
681+ const { getByText , getAllByText , userEvent } = render (
698682 < Drawer . Root
699683 open
700684 onOpenChange = { ( ) => { } }
@@ -710,12 +694,9 @@ describe('SubscriptionDetails', () => {
710694 expect ( getByText ( 'Active' ) ) . toBeVisible ( ) ;
711695 } ) ;
712696
713- // Open the menu
714- const menuButton = getByRole ( 'button' , { name : / O p e n m e n u / i } ) ;
715- await userEvent . click ( menuButton ) ;
716-
717- // Wait for the cancel option to appear and click it
718- await userEvent . click ( getByText ( 'Cancel subscription' ) ) ;
697+ // Get the inline Cancel subscription button (first one, before confirmation dialog opens)
698+ const cancelButtons = getAllByText ( 'Cancel subscription' ) ;
699+ await userEvent . click ( cancelButtons [ 0 ] ) ;
719700
720701 await waitFor ( ( ) => {
721702 expect ( getByText ( 'Cancel Monthly Plan Subscription?' ) ) . toBeVisible ( ) ;
@@ -727,7 +708,10 @@ describe('SubscriptionDetails', () => {
727708 expect ( getByText ( 'Keep subscription' ) ) . toBeVisible ( ) ;
728709 } ) ;
729710
730- await userEvent . click ( getByText ( 'Cancel subscription' ) ) ;
711+ // Click the Cancel subscription button in the confirmation dialog
712+ // Use getAllByText and select the last one (confirmation dialog button)
713+ const allCancelButtons = getAllByText ( 'Cancel subscription' ) ;
714+ await userEvent . click ( allCancelButtons [ allCancelButtons . length - 1 ] ) ;
731715
732716 // Assert that the cancelSubscription method was called
733717 await waitFor ( ( ) => {
@@ -815,7 +799,7 @@ describe('SubscriptionDetails', () => {
815799 subscriptionItems : [ subscription ] ,
816800 } ) ;
817801
818- const { getByRole , getByText, userEvent } = render (
802+ const { getByText, userEvent } = render (
819803 < Drawer . Root
820804 open
821805 onOpenChange = { ( ) => { } }
@@ -829,11 +813,6 @@ describe('SubscriptionDetails', () => {
829813 expect ( getByText ( 'Annual Plan' ) ) . toBeVisible ( ) ;
830814 } ) ;
831815
832- // Open the menu
833- const menuButton = getByRole ( 'button' , { name : / O p e n m e n u / i } ) ;
834- await userEvent . click ( menuButton ) ;
835-
836- // Wait for the Resubscribe option and click it
837816 await userEvent . click ( getByText ( 'Resubscribe' ) ) ;
838817
839818 // Assert resubscribe was called
@@ -920,7 +899,7 @@ describe('SubscriptionDetails', () => {
920899 subscriptionItems : [ subscription ] ,
921900 } ) ;
922901
923- const { getByRole , getByText, userEvent } = render (
902+ const { getByText, userEvent } = render (
924903 < Drawer . Root
925904 open
926905 onOpenChange = { ( ) => { } }
@@ -934,11 +913,6 @@ describe('SubscriptionDetails', () => {
934913 expect ( getByText ( 'Annual Plan' ) ) . toBeVisible ( ) ;
935914 } ) ;
936915
937- // Open the menu
938- const menuButton = getByRole ( 'button' , { name : / O p e n m e n u / i } ) ;
939- await userEvent . click ( menuButton ) ;
940-
941- // Wait for the Switch to monthly option and click it
942916 await userEvent . click ( getByText ( / S w i t c h t o m o n t h l y / i) ) ;
943917
944918 // Assert switchToMonthly was called
@@ -1112,7 +1086,7 @@ describe('SubscriptionDetails', () => {
11121086 ] ,
11131087 } ) ;
11141088
1115- const { getByRole, getByText, getAllByText, queryByText, userEvent } = render (
1089+ const { getByRole, getByText, getAllByText, queryByText } = render (
11161090 < Drawer . Root
11171091 open
11181092 onOpenChange = { ( ) => { } }
@@ -1149,11 +1123,7 @@ describe('SubscriptionDetails', () => {
11491123 expect ( queryByText ( 'Next payment amount' ) ) . toBeNull ( ) ;
11501124 } ) ;
11511125
1152- // Test the menu shows free trial specific options
1153- const menuButton = getByRole ( 'button' , { name : / O p e n m e n u / i } ) ;
1154- expect ( menuButton ) . toBeVisible ( ) ;
1155- await userEvent . click ( menuButton ) ;
1156-
1126+ // Test the inline button shows free trial specific option
11571127 await waitFor ( ( ) => {
11581128 expect ( getByText ( 'Cancel free trial' ) ) . toBeVisible ( ) ;
11591129 } ) ;
@@ -1228,7 +1198,7 @@ describe('SubscriptionDetails', () => {
12281198 ] ,
12291199 } ) ;
12301200
1231- const { getByRole , getByText , userEvent } = render (
1201+ const { getByText , getAllByText , userEvent } = render (
12321202 < Drawer . Root
12331203 open
12341204 onOpenChange = { ( ) => { } }
@@ -1244,12 +1214,9 @@ describe('SubscriptionDetails', () => {
12441214 expect ( getByText ( 'Free trial' ) ) . toBeVisible ( ) ;
12451215 } ) ;
12461216
1247- // Open the menu
1248- const menuButton = getByRole ( 'button' , { name : / O p e n m e n u / i } ) ;
1249- await userEvent . click ( menuButton ) ;
1250-
1251- // Wait for the cancel option to appear and click it
1252- await userEvent . click ( getByText ( 'Cancel free trial' ) ) ;
1217+ // Get the inline Cancel free trial button (first one, before confirmation dialog opens)
1218+ const cancelTrialButtons = getAllByText ( 'Cancel free trial' ) ;
1219+ await userEvent . click ( cancelTrialButtons [ 0 ] ) ;
12531220
12541221 await waitFor ( ( ) => {
12551222 // Should show free trial specific cancellation dialog
@@ -1262,8 +1229,10 @@ describe('SubscriptionDetails', () => {
12621229 expect ( getByText ( 'Keep free trial' ) ) . toBeVisible ( ) ;
12631230 } ) ;
12641231
1265- // Click the cancel button in the dialog
1266- await userEvent . click ( getByText ( 'Cancel free trial' ) ) ;
1232+ // Click the Cancel free trial button in the confirmation dialog
1233+ // Use getAllByText and select the last one (confirmation dialog button)
1234+ const allCancelTrialButtons = getAllByText ( 'Cancel free trial' ) ;
1235+ await userEvent . click ( allCancelTrialButtons [ allCancelTrialButtons . length - 1 ] ) ;
12671236
12681237 // Assert that the cancelSubscription method was called
12691238 await waitFor ( ( ) => {
0 commit comments