@@ -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,10 +130,6 @@ 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 ( ( ) => {
138134 expect ( getByText ( 'Switch to annual $100 / year' ) ) . toBeVisible ( ) ;
139135 expect ( getByText ( 'Cancel subscription' ) ) . toBeVisible ( ) ;
@@ -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,10 +233,6 @@ 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 ( ( ) => {
245237 expect ( getByText ( 'Switch to monthly $10 / month' ) ) . toBeVisible ( ) ;
246238 expect ( getByText ( 'Cancel subscription' ) ) . toBeVisible ( ) ;
@@ -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,13 @@ 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 ( ( ) => {
467+ // Active (canceled) annual subscription buttons
476468 expect ( getByText ( 'Switch to monthly $13 / month' ) ) . toBeVisible ( ) ;
477469 expect ( getByText ( 'Resubscribe' ) ) . toBeVisible ( ) ;
478- expect ( queryByText ( 'Cancel subscription' ) ) . toBeNull ( ) ;
479- } ) ;
480-
481- await userEvent . click ( upcomingMenuButton ) ;
482-
483- await waitFor ( ( ) => {
470+ // Upcoming monthly subscription buttons
484471 expect ( getByText ( 'Switch to annual $90.99 / year' ) ) . toBeVisible ( ) ;
485- expect ( getByText ( 'Cancel subscription' ) ) . toBeVisible ( ) ;
472+ expect ( getAllByText ( 'Cancel subscription' ) . length ) . toBe ( 1 ) ;
486473 } ) ;
487474 } ) ;
488475
@@ -694,7 +681,7 @@ describe('SubscriptionDetails', () => {
694681 ] ,
695682 } ) ;
696683
697- const { getByRole , getByText , userEvent } = render (
684+ const { getByText , getAllByText , userEvent } = render (
698685 < Drawer . Root
699686 open
700687 onOpenChange = { ( ) => { } }
@@ -710,12 +697,9 @@ describe('SubscriptionDetails', () => {
710697 expect ( getByText ( 'Active' ) ) . toBeVisible ( ) ;
711698 } ) ;
712699
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' ) ) ;
700+ // Get the inline Cancel subscription button (first one, before confirmation dialog opens)
701+ const cancelButtons = getAllByText ( 'Cancel subscription' ) ;
702+ await userEvent . click ( cancelButtons [ 0 ] ) ;
719703
720704 await waitFor ( ( ) => {
721705 expect ( getByText ( 'Cancel Monthly Plan Subscription?' ) ) . toBeVisible ( ) ;
@@ -727,7 +711,10 @@ describe('SubscriptionDetails', () => {
727711 expect ( getByText ( 'Keep subscription' ) ) . toBeVisible ( ) ;
728712 } ) ;
729713
730- await userEvent . click ( getByText ( 'Cancel subscription' ) ) ;
714+ // Click the Cancel subscription button in the confirmation dialog
715+ // Use getAllByText and select the last one (confirmation dialog button)
716+ const allCancelButtons = getAllByText ( 'Cancel subscription' ) ;
717+ await userEvent . click ( allCancelButtons [ allCancelButtons . length - 1 ] ) ;
731718
732719 // Assert that the cancelSubscription method was called
733720 await waitFor ( ( ) => {
@@ -815,7 +802,7 @@ describe('SubscriptionDetails', () => {
815802 subscriptionItems : [ subscription ] ,
816803 } ) ;
817804
818- const { getByRole , getByText, userEvent } = render (
805+ const { getByText, userEvent } = render (
819806 < Drawer . Root
820807 open
821808 onOpenChange = { ( ) => { } }
@@ -829,11 +816,6 @@ describe('SubscriptionDetails', () => {
829816 expect ( getByText ( 'Annual Plan' ) ) . toBeVisible ( ) ;
830817 } ) ;
831818
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
837819 await userEvent . click ( getByText ( 'Resubscribe' ) ) ;
838820
839821 // Assert resubscribe was called
@@ -920,7 +902,7 @@ describe('SubscriptionDetails', () => {
920902 subscriptionItems : [ subscription ] ,
921903 } ) ;
922904
923- const { getByRole , getByText, userEvent } = render (
905+ const { getByText, userEvent } = render (
924906 < Drawer . Root
925907 open
926908 onOpenChange = { ( ) => { } }
@@ -934,11 +916,6 @@ describe('SubscriptionDetails', () => {
934916 expect ( getByText ( 'Annual Plan' ) ) . toBeVisible ( ) ;
935917 } ) ;
936918
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
942919 await userEvent . click ( getByText ( / S w i t c h t o m o n t h l y / i) ) ;
943920
944921 // Assert switchToMonthly was called
@@ -1112,7 +1089,7 @@ describe('SubscriptionDetails', () => {
11121089 ] ,
11131090 } ) ;
11141091
1115- const { getByRole, getByText, getAllByText, queryByText, userEvent } = render (
1092+ const { getByRole, getByText, getAllByText, queryByText } = render (
11161093 < Drawer . Root
11171094 open
11181095 onOpenChange = { ( ) => { } }
@@ -1149,11 +1126,7 @@ describe('SubscriptionDetails', () => {
11491126 expect ( queryByText ( 'Next payment amount' ) ) . toBeNull ( ) ;
11501127 } ) ;
11511128
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-
1129+ // Test the inline button shows free trial specific option
11571130 await waitFor ( ( ) => {
11581131 expect ( getByText ( 'Cancel free trial' ) ) . toBeVisible ( ) ;
11591132 } ) ;
@@ -1228,7 +1201,7 @@ describe('SubscriptionDetails', () => {
12281201 ] ,
12291202 } ) ;
12301203
1231- const { getByRole , getByText , userEvent } = render (
1204+ const { getByText , getAllByText , userEvent } = render (
12321205 < Drawer . Root
12331206 open
12341207 onOpenChange = { ( ) => { } }
@@ -1244,12 +1217,9 @@ describe('SubscriptionDetails', () => {
12441217 expect ( getByText ( 'Free trial' ) ) . toBeVisible ( ) ;
12451218 } ) ;
12461219
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' ) ) ;
1220+ // Get the inline Cancel free trial button (first one, before confirmation dialog opens)
1221+ const cancelTrialButtons = getAllByText ( 'Cancel free trial' ) ;
1222+ await userEvent . click ( cancelTrialButtons [ 0 ] ) ;
12531223
12541224 await waitFor ( ( ) => {
12551225 // Should show free trial specific cancellation dialog
@@ -1262,8 +1232,10 @@ describe('SubscriptionDetails', () => {
12621232 expect ( getByText ( 'Keep free trial' ) ) . toBeVisible ( ) ;
12631233 } ) ;
12641234
1265- // Click the cancel button in the dialog
1266- await userEvent . click ( getByText ( 'Cancel free trial' ) ) ;
1235+ // Click the Cancel free trial button in the confirmation dialog
1236+ // Use getAllByText and select the last one (confirmation dialog button)
1237+ const allCancelTrialButtons = getAllByText ( 'Cancel free trial' ) ;
1238+ await userEvent . click ( allCancelTrialButtons [ allCancelTrialButtons . length - 1 ] ) ;
12671239
12681240 // Assert that the cancelSubscription method was called
12691241 await waitFor ( ( ) => {
0 commit comments