@@ -3,7 +3,6 @@ import {ProjectFixture} from 'sentry-fixture/project';
33import { TagsFixture } from 'sentry-fixture/tags' ;
44import { TagValuesFixture } from 'sentry-fixture/tagvalues' ;
55
6- import { initializeOrg } from 'sentry-test/initializeOrg' ;
76import { render , screen , userEvent , waitFor } from 'sentry-test/reactTestingLibrary' ;
87
98import ProjectsStore from 'sentry/stores/projectsStore' ;
@@ -14,19 +13,15 @@ describe('GroupTagValues', () => {
1413 const tags = TagsFixture ( ) ;
1514 const project = ProjectFixture ( ) ;
1615
17- function init ( tagKey : string , environment ?: string [ ] | string ) {
18- return initializeOrg ( {
19- router : {
20- location : {
21- query : {
22- environment,
23- } ,
24- pathname : '/organizations/:orgId/issues/:groupId/tags/:tagKey/' ,
25- } ,
26- params : { orgId : 'org-slug' , groupId : group . id , tagKey} ,
16+ const makeInitialRouterConfig = ( tagKey : string , environment ?: string [ ] | string ) => ( {
17+ location : {
18+ pathname : `/organizations/org-slug/issues/${ group . id } /tags/${ tagKey } /` ,
19+ query : {
20+ ...( environment && { environment} ) ,
2721 } ,
28- } ) ;
29- }
22+ } ,
23+ route : '/organizations/:orgId/issues/:groupId/tags/:tagKey/' ,
24+ } ) ;
3025
3126 beforeEach ( ( ) => {
3227 ProjectsStore . init ( ) ;
@@ -46,15 +41,12 @@ describe('GroupTagValues', () => {
4641 } ) ;
4742
4843 it ( 'renders a list of tag values' , async ( ) => {
49- const { router} = init ( 'user' ) ;
50-
5144 MockApiClient . addMockResponse ( {
5245 url : '/organizations/org-slug/issues/1/tags/user/values/' ,
5346 body : TagValuesFixture ( ) ,
5447 } ) ;
5548 render ( < GroupTagValues /> , {
56- router,
57- deprecatedRouterMocks : true ,
49+ initialRouterConfig : makeInitialRouterConfig ( 'user' ) ,
5850 } ) ;
5951
6052 // Special case for user tag - column title changes to Affected Users
@@ -69,8 +61,6 @@ describe('GroupTagValues', () => {
6961 } ) ;
7062
7163 it ( 'can page through tag values' , async ( ) => {
72- const { router} = init ( 'user' ) ;
73-
7464 MockApiClient . addMockResponse ( {
7565 url : '/organizations/org-slug/issues/1/tags/user/values/' ,
7666 body : TagValuesFixture ( ) ,
@@ -80,9 +70,8 @@ describe('GroupTagValues', () => {
8070 '<https://sentry.io/api/0/organizations/sentry/user-feedback/?statsPeriod=14d&cursor=0:100:0>; rel="next"; results="true"; cursor="0:100:0"' ,
8171 } ,
8272 } ) ;
83- render ( < GroupTagValues /> , {
84- router,
85- deprecatedRouterMocks : true ,
73+ const { router} = render ( < GroupTagValues /> , {
74+ initialRouterConfig : makeInitialRouterConfig ( 'user' ) ,
8675 } ) ;
8776
8877 expect ( await screen . findByRole ( 'button' , { name : 'Previous' } ) ) . toBeDisabled ( ) ;
@@ -91,46 +80,38 @@ describe('GroupTagValues', () => {
9180 // Clicking next button loads page with query param ?cursor=0:100:0
9281 await userEvent . click ( screen . getByRole ( 'button' , { name : 'Next' } ) ) ;
9382 await waitFor ( ( ) => {
94- expect ( router . push ) . toHaveBeenCalledWith (
95- expect . objectContaining ( { query : expect . objectContaining ( { cursor : '0:100:0' } ) } )
96- ) ;
83+ expect ( router . location . query . cursor ) . toBe ( '0:100:0' ) ;
9784 } ) ;
9885 } ) ;
9986
10087 it ( 'navigates to issue details events tab with correct query params' , async ( ) => {
101- const { router} = init ( 'user' ) ;
102-
10388 MockApiClient . addMockResponse ( {
10489 url : '/organizations/org-slug/issues/1/tags/user/values/' ,
10590 body : TagValuesFixture ( ) ,
10691 } ) ;
107- render ( < GroupTagValues /> , {
108- router,
109- deprecatedRouterMocks : true ,
92+ const { router} = render ( < GroupTagValues /> , {
93+ initialRouterConfig : makeInitialRouterConfig ( 'user' ) ,
11094 } ) ;
11195
11296 await userEvent . click ( await screen . findByRole ( 'button' , { name : 'More' } ) ) ;
11397 await userEvent . click (
11498 screen . getByRole ( 'menuitemradio' , { name : 'Search All Issues with Tag Value' } )
11599 ) ;
116100
117- expect ( router . push ) . toHaveBeenCalledWith ( {
118- pathname : '/organizations/org-slug/issues/' ,
119- query : { query : 'user.username:david' } ,
101+ await waitFor ( ( ) => {
102+ expect ( router . location . pathname ) . toBe ( '/organizations/org-slug/issues/' ) ;
120103 } ) ;
104+ expect ( router . location . query . query ) . toBe ( 'user.username:david' ) ;
121105 } ) ;
122106
123107 it ( 'renders an error message if tag values request fails' , async ( ) => {
124- const { router} = init ( 'user' , 'staging' ) ;
125-
126108 MockApiClient . addMockResponse ( {
127109 url : '/organizations/org-slug/issues/1/tags/user/values/' ,
128110 statusCode : 500 ,
129111 } ) ;
130112
131113 render ( < GroupTagValues /> , {
132- router,
133- deprecatedRouterMocks : true ,
114+ initialRouterConfig : makeInitialRouterConfig ( 'user' , 'staging' ) ,
134115 } ) ;
135116
136117 expect (
@@ -139,16 +120,13 @@ describe('GroupTagValues', () => {
139120 } ) ;
140121
141122 it ( 'renders an error message if no tag values are returned because of environment selection' , async ( ) => {
142- const { router} = init ( 'user' , 'staging' ) ;
143-
144123 MockApiClient . addMockResponse ( {
145124 url : '/organizations/org-slug/issues/1/tags/user/values/' ,
146125 body : [ ] ,
147126 } ) ;
148127
149128 render ( < GroupTagValues /> , {
150- router,
151- deprecatedRouterMocks : true ,
129+ initialRouterConfig : makeInitialRouterConfig ( 'user' , 'staging' ) ,
152130 } ) ;
153131
154132 expect (
0 commit comments