@@ -595,4 +595,45 @@ describe('AlertRulesList', () => {
595
595
expect ( await screen . findByText ( 'Auto Detected' ) ) . toBeInTheDocument ( ) ;
596
596
expect ( await screen . findByText ( 'Up' ) ) . toBeInTheDocument ( ) ;
597
597
} ) ;
598
+
599
+ it ( 'deletes an uptime rule' , async ( ) => {
600
+ const deletedRuleName = 'Uptime Rule' ;
601
+ const uptimeRule = UptimeRuleFixture ( { owner : undefined } ) ;
602
+
603
+ MockApiClient . addMockResponse ( {
604
+ url : '/organizations/org-slug/combined-rules/' ,
605
+ headers : { Link : pageLinks } ,
606
+ body : [ { ...uptimeRule , type : CombinedAlertType . UPTIME } ] ,
607
+ } ) ;
608
+
609
+ const { router, project, organization} = initializeOrg ( { organization : defaultOrg } ) ;
610
+ render ( < AlertRulesList /> , { router, organization} ) ;
611
+ renderGlobalModal ( ) ;
612
+
613
+ const deleteMock = MockApiClient . addMockResponse ( {
614
+ url : `/projects/${ organization . slug } /${ project . slug } /uptime/${ uptimeRule . id } /` ,
615
+ method : 'DELETE' ,
616
+ body : { } ,
617
+ } ) ;
618
+
619
+ const actions = ( await screen . findAllByRole ( 'button' , { name : 'Actions' } ) ) [ 0 ] ;
620
+
621
+ // Add a new response to the mock with no rules
622
+ const emptyListMock = MockApiClient . addMockResponse ( {
623
+ url : '/organizations/org-slug/combined-rules/' ,
624
+ headers : { Link : pageLinks } ,
625
+ body : [ ] ,
626
+ } ) ;
627
+
628
+ expect (
629
+ screen . queryByRole ( 'link' , { name : 'Uptime Rule Auto Detected' } )
630
+ ) . toBeInTheDocument ( ) ;
631
+ await userEvent . click ( actions ) ;
632
+ await userEvent . click ( screen . getByRole ( 'menuitemradio' , { name : 'Delete' } ) ) ;
633
+ await userEvent . click ( screen . getByRole ( 'button' , { name : 'Delete Rule' } ) ) ;
634
+
635
+ expect ( deleteMock ) . toHaveBeenCalledTimes ( 1 ) ;
636
+ expect ( emptyListMock ) . toHaveBeenCalledTimes ( 1 ) ;
637
+ expect ( screen . queryByText ( deletedRuleName ) ) . not . toBeInTheDocument ( ) ;
638
+ } ) ;
598
639
} ) ;
0 commit comments