11import { EventFixture } from 'sentry-fixture/event' ;
22import { GroupFixture } from 'sentry-fixture/group' ;
3- import { LocationFixture } from 'sentry-fixture/locationFixture' ;
4- import { RouterFixture } from 'sentry-fixture/routerFixture' ;
3+ import { OrganizationFixture } from 'sentry-fixture/organization' ;
54
6- import { initializeOrg } from 'sentry-test/initializeOrg' ;
7- import { render , screen , userEvent , waitFor } from 'sentry-test/reactTestingLibrary' ;
5+ import {
6+ render ,
7+ screen ,
8+ userEvent ,
9+ waitFor ,
10+ type RouterConfig ,
11+ } from 'sentry-test/reactTestingLibrary' ;
812
913import { IssueDetailsEventNavigation } from './issueDetailsEventNavigation' ;
1014
1115describe ( 'IssueDetailsEventNavigation' , ( ) => {
12- const { organization, router } = initializeOrg ( ) ;
16+ const organization = OrganizationFixture ( ) ;
1317 const group = GroupFixture ( { id : 'group-id' } ) ;
1418 const testEvent = EventFixture ( {
1519 id : 'event-id' ,
@@ -28,6 +32,24 @@ describe('IssueDetailsEventNavigation', () => {
2832 event : testEvent ,
2933 group,
3034 } ;
35+ const routerConfigBase : Pick < RouterConfig , 'routes' > = {
36+ routes : [
37+ '/organizations/:orgId/issues/:groupId/events/' ,
38+ '/organizations/:orgId/issues/:groupId/events/:eventId/' ,
39+ ] ,
40+ } ;
41+ const latestRouterConfig : RouterConfig = {
42+ ...routerConfigBase ,
43+ location : {
44+ pathname : `/organizations/${ organization . slug } /issues/${ group . id } /events/latest/` ,
45+ } ,
46+ } ;
47+ const recommendedRouterConfig : RouterConfig = {
48+ ...routerConfigBase ,
49+ location : {
50+ pathname : `/organizations/${ organization . slug } /issues/${ group . id } /events/recommended/` ,
51+ } ,
52+ } ;
3153
3254 beforeEach ( ( ) => {
3355 jest . resetAllMocks ( ) ;
@@ -39,58 +61,63 @@ describe('IssueDetailsEventNavigation', () => {
3961
4062 describe ( 'recommended event tabs' , ( ) => {
4163 it ( 'can navigate to the oldest event' , async ( ) => {
42- render ( < IssueDetailsEventNavigation { ...defaultProps } isSmallNav /> , {
43- router,
44- deprecatedRouterMocks : true ,
45- } ) ;
64+ const { router} = render (
65+ < IssueDetailsEventNavigation { ...defaultProps } isSmallNav /> ,
66+ {
67+ initialRouterConfig : latestRouterConfig ,
68+ }
69+ ) ;
4670
4771 await userEvent . click ( await screen . findByRole ( 'tab' , { name : 'First' } ) ) ;
4872
49- expect ( router . push ) . toHaveBeenCalledWith ( {
50- pathname : '/organizations/org-slug/issues/group-id/events/oldest/' ,
51- query : { referrer : 'oldest-event' } ,
52- } ) ;
73+ await waitFor ( ( ) =>
74+ expect ( router . location . pathname ) . toBe (
75+ '/organizations/org-slug/issues/group-id/events/oldest/'
76+ )
77+ ) ;
78+ expect ( router . location . query ) . toEqual ( { referrer : 'oldest-event' } ) ;
5379 } ) ;
5480
5581 it ( 'can navigate to the latest event' , async ( ) => {
56- render ( < IssueDetailsEventNavigation { ...defaultProps } isSmallNav /> , {
57- router,
58- deprecatedRouterMocks : true ,
59- } ) ;
82+ const { router} = render (
83+ < IssueDetailsEventNavigation { ...defaultProps } isSmallNav /> ,
84+ {
85+ initialRouterConfig : recommendedRouterConfig ,
86+ }
87+ ) ;
6088
6189 await userEvent . click ( await screen . findByRole ( 'tab' , { name : 'Latest' } ) ) ;
6290
63- expect ( router . push ) . toHaveBeenCalledWith ( {
64- pathname : '/organizations/org-slug/issues/group-id/events/latest/' ,
65- query : { referrer : 'latest-event' } ,
66- } ) ;
91+ await waitFor ( ( ) =>
92+ expect ( router . location . pathname ) . toBe (
93+ '/organizations/org-slug/issues/group-id/events/latest/'
94+ )
95+ ) ;
96+ expect ( router . location . query ) . toEqual ( { referrer : 'latest-event' } ) ;
6797 } ) ;
6898
6999 it ( 'can navigate to the recommended event' , async ( ) => {
70- const recommendedEventRouter = RouterFixture ( {
71- params : { eventId : 'latest' } ,
72- location : LocationFixture ( {
73- pathname : `/organizations/org-slug/issues/group-id/events/latest/` ,
74- } ) ,
75- } ) ;
76-
77- render ( < IssueDetailsEventNavigation { ...defaultProps } isSmallNav /> , {
78- router : recommendedEventRouter ,
79- deprecatedRouterMocks : true ,
80- } ) ;
100+ const { router} = render (
101+ < IssueDetailsEventNavigation { ...defaultProps } isSmallNav /> ,
102+ {
103+ initialRouterConfig : latestRouterConfig ,
104+ }
105+ ) ;
81106
82107 await userEvent . click ( await screen . findByRole ( 'tab' , { name : 'Rec.' } ) ) ;
83108
84- expect ( recommendedEventRouter . push ) . toHaveBeenCalledWith ( {
85- pathname : '/organizations/org-slug/issues/group-id/events/recommended/' ,
86- query : { referrer : 'recommended-event' } ,
87- } ) ;
109+ await waitFor ( ( ) =>
110+ expect ( router . location . pathname ) . toBe (
111+ '/organizations/org-slug/issues/group-id/events/recommended/'
112+ )
113+ ) ;
114+ expect ( router . location . query ) . toEqual ( { referrer : 'recommended-event' } ) ;
88115 } ) ;
89116 } ) ;
90117
91118 it ( 'can navigate next/previous events' , async ( ) => {
92119 render ( < IssueDetailsEventNavigation { ...defaultProps } /> , {
93- deprecatedRouterMocks : true ,
120+ initialRouterConfig : latestRouterConfig ,
94121 } ) ;
95122
96123 expect ( await screen . findByRole ( 'button' , { name : 'Previous Event' } ) ) . toHaveAttribute (
@@ -117,7 +144,7 @@ describe('IssueDetailsEventNavigation', () => {
117144 body : EventFixture ( ) ,
118145 } ) ;
119146 render ( < IssueDetailsEventNavigation { ...defaultProps } event = { event } /> , {
120- deprecatedRouterMocks : true ,
147+ initialRouterConfig : latestRouterConfig ,
121148 } ) ;
122149
123150 expect ( mockNextEvent ) . not . toHaveBeenCalled ( ) ;
0 commit comments