1- import { initializeOrg } from 'sentry-test/initializeOrg' ;
1+ import { OrganizationFixture } from 'sentry-fixture/organization' ;
2+ import { ProjectFixture } from 'sentry-fixture/project' ;
3+ import { RouterFixture } from 'sentry-fixture/routerFixture' ;
4+
25import { act , fireEvent , render , screen , userEvent } from 'sentry-test/reactTestingLibrary' ;
36
47import { initializeUrlState , updateEnvironments } from 'sentry/actionCreators/pageFilters' ;
@@ -7,20 +10,11 @@ import OrganizationStore from 'sentry/stores/organizationStore';
710import PageFiltersStore from 'sentry/stores/pageFiltersStore' ;
811import ProjectsStore from 'sentry/stores/projectsStore' ;
912
10- const { organization, projects, router} = initializeOrg ( {
11- organization : { features : [ 'open-membership' ] } ,
12- projects : [
13- { id : '1' , slug : 'project-1' , environments : [ 'prod' , 'staging' ] } ,
14- { id : '2' , slug : 'project-2' , environments : [ 'prod' , 'stage' ] } ,
15- ] ,
16- router : {
17- location : {
18- pathname : '/organizations/org-slug/issues/' ,
19- query : { } ,
20- } ,
21- params : { } ,
22- } ,
23- } ) ;
13+ const organization = OrganizationFixture ( { features : [ 'open-membership' ] } ) ;
14+ const projects = [
15+ ProjectFixture ( { id : '1' , slug : 'project-1' , environments : [ 'prod' , 'staging' ] } ) ,
16+ ProjectFixture ( { id : '2' , slug : 'project-2' , environments : [ 'prod' , 'stage' ] } ) ,
17+ ] ;
2418
2519describe ( 'EnvironmentPageFilter' , ( ) => {
2620 beforeEach ( ( ) => {
@@ -40,10 +34,11 @@ describe('EnvironmentPageFilter', () => {
4034 afterEach ( ( ) => PageFiltersStore . reset ( ) ) ;
4135
4236 it ( 'renders & handles single selection' , async ( ) => {
43- render ( < EnvironmentPageFilter /> , {
44- router,
37+ const { router} = render ( < EnvironmentPageFilter /> , {
4538 organization,
46- deprecatedRouterMocks : true ,
39+ initialRouterConfig : {
40+ location : { pathname : '/organizations/org-slug/issues/' , query : { } } ,
41+ } ,
4742 } ) ;
4843
4944 // Open menu
@@ -59,16 +54,15 @@ describe('EnvironmentPageFilter', () => {
5954
6055 // Trigger label & router is updated
6156 expect ( screen . getByRole ( 'button' , { name : 'prod' } ) ) . toBeInTheDocument ( ) ;
62- expect ( router . push ) . toHaveBeenCalledWith (
63- expect . objectContaining ( { query : { environment : [ 'prod' ] } } )
64- ) ;
57+ expect ( router . location . query ) . toEqual ( expect . objectContaining ( { environment : 'prod' } ) ) ;
6558 } ) ;
6659
6760 it ( 'handles multiple selection' , async ( ) => {
68- render ( < EnvironmentPageFilter /> , {
69- router,
61+ const { router} = render ( < EnvironmentPageFilter /> , {
7062 organization,
71- deprecatedRouterMocks : true ,
63+ initialRouterConfig : {
64+ location : { pathname : '/organizations/org-slug/issues/' , query : { } } ,
65+ } ,
7266 } ) ;
7367
7468 // Open menu
@@ -83,27 +77,24 @@ describe('EnvironmentPageFilter', () => {
8377
8478 // Trigger button & router are updated
8579 expect ( screen . getByRole ( 'button' , { name : 'prod, stage' } ) ) . toBeInTheDocument ( ) ;
86- expect ( router . push ) . toHaveBeenCalledWith (
87- expect . objectContaining ( { query : { environment : [ 'prod' , 'stage' ] } } )
80+ expect ( router . location . query ) . toEqual (
81+ expect . objectContaining ( { environment : [ 'prod' , 'stage' ] } )
8882 ) ;
8983 } ) ;
9084
9185 it ( 'handles reset' , async ( ) => {
9286 const onReset = jest . fn ( ) ;
93- render ( < EnvironmentPageFilter onReset = { onReset } /> , {
94- router,
87+ const { router} = render ( < EnvironmentPageFilter onReset = { onReset } /> , {
9588 organization,
96- deprecatedRouterMocks : true ,
89+ initialRouterConfig : {
90+ location : { pathname : '/organizations/org-slug/issues/' , query : { } } ,
91+ } ,
9792 } ) ;
9893
9994 // Open the menu, select project-1
10095 await userEvent . click ( screen . getByRole ( 'button' , { name : 'All Envs' } ) ) ;
10196 await userEvent . click ( screen . getByRole ( 'row' , { name : 'prod' } ) ) ;
102- expect ( router . push ) . toHaveBeenCalledWith (
103- expect . objectContaining ( {
104- query : { environment : [ 'prod' ] } ,
105- } )
106- ) ;
97+ expect ( router . location . query ) . toEqual ( expect . objectContaining ( { environment : 'prod' } ) ) ;
10798
10899 // Open menu again & click "Reset"
109100 await userEvent . click ( screen . getByRole ( 'button' , { name : 'prod' } ) ) ;
@@ -115,52 +106,47 @@ describe('EnvironmentPageFilter', () => {
115106 } ) ;
116107
117108 it ( 'responds to page filter changes, async e.g. from back button nav' , async ( ) => {
109+ const mockRouter = RouterFixture ( {
110+ location : { pathname : '/organizations/org-slug/issues/' , query : { } } ,
111+ } ) ;
112+
118113 render ( < EnvironmentPageFilter /> , {
119- router,
120114 organization,
121- deprecatedRouterMocks : true ,
115+ initialRouterConfig : {
116+ location : { pathname : '/organizations/org-slug/issues/' , query : { } } ,
117+ } ,
122118 } ) ;
123119
124120 // Confirm initial selection
125121 expect ( await screen . findByRole ( 'button' , { name : 'All Envs' } ) ) . toBeInTheDocument ( ) ;
126122
127123 // Edit store value
128- act ( ( ) => updateEnvironments ( [ 'prod' ] , router ) ) ;
124+ act ( ( ) => updateEnvironments ( [ 'prod' ] , mockRouter ) ) ;
129125
130126 // <EnvironmentPageFilter /> is updated
131127 expect ( screen . getByRole ( 'button' , { name : 'prod' } ) ) . toBeInTheDocument ( ) ;
132128 } ) ;
133129
134130 it ( 'displays a desynced state message' , async ( ) => {
135- const { organization : desyncOrganization , router : desyncRouter } = initializeOrg ( {
136- organization : { features : [ 'open-membership' ] } ,
137- projects : [
138- { id : '1' , slug : 'project-1' , environments : [ 'prod' , 'staging' ] } ,
139- { id : '2' , slug : 'project-2' , environments : [ 'prod' , 'stage' ] } ,
140- ] ,
141- router : {
142- location : {
143- pathname : '/organizations/org-slug/issues/' ,
144- // the environment parameter needs to be non-null for desync detection to work
145- query : { environment : 'prod' } ,
146- } ,
147- params : { } ,
148- } ,
149- } ) ;
131+ const desyncOrganization = OrganizationFixture ( { features : [ 'open-membership' ] } ) ;
132+ // the environment parameter needs to be non-null for desync detection to work
133+ const desyncLocation = {
134+ pathname : '/organizations/org-slug/issues/' ,
135+ query : { environment : 'prod' } ,
136+ } ;
150137
151138 PageFiltersStore . reset ( ) ;
152139 initializeUrlState ( {
153140 memberProjects : projects ,
154141 nonMemberProjects : [ ] ,
155142 organization : desyncOrganization ,
156143 queryParams : { project : [ '1' ] , environment : 'staging' } ,
157- router : desyncRouter ,
144+ router : RouterFixture ( { location : desyncLocation } ) ,
158145 } ) ;
159146
160147 render ( < EnvironmentPageFilter /> , {
161- router : desyncRouter ,
162148 organization : desyncOrganization ,
163- deprecatedRouterMocks : true ,
149+ initialRouterConfig : { location : desyncLocation } ,
164150 } ) ;
165151
166152 // Open menu
0 commit comments