@@ -87,6 +87,10 @@ describe('OrganizationContext', function() {
87
87
88
88
it ( 'fetches new org when router params change' , function ( ) {
89
89
wrapper = createWrapper ( ) ;
90
+ MockApiClient . addMockResponse ( {
91
+ url : '/organizations/new-slug/environments/' ,
92
+ body : TestStubs . Environments ( ) ,
93
+ } ) ;
90
94
const mock = MockApiClient . addMockResponse ( {
91
95
url : '/organizations/new-slug/' ,
92
96
body : org ,
@@ -140,8 +144,13 @@ describe('OrganizationContext', function() {
140
144
} ) ;
141
145
142
146
it ( 'uses last organization from ConfigStore' , function ( ) {
147
+ MockApiClient . addMockResponse ( {
148
+ url : '/organizations/lastOrganization/environments/' ,
149
+ body : TestStubs . Environments ( ) ,
150
+ } ) ;
143
151
getOrgMock = MockApiClient . addMockResponse ( {
144
152
url : '/organizations/lastOrganization/' ,
153
+ body : org ,
145
154
} ) ;
146
155
// mocking `.get('lastOrganization')`
147
156
ConfigStore . get . mockImplementation ( ( ) => 'lastOrganization' ) ;
@@ -153,8 +162,13 @@ describe('OrganizationContext', function() {
153
162
} ) ;
154
163
155
164
it ( 'uses last organization from `organizations` prop' , async function ( ) {
165
+ MockApiClient . addMockResponse ( {
166
+ url : '/organizations/foo/environments/' ,
167
+ body : TestStubs . Environments ( ) ,
168
+ } ) ;
156
169
getOrgMock = MockApiClient . addMockResponse ( {
157
170
url : '/organizations/foo/' ,
171
+ body : org ,
158
172
} ) ;
159
173
ConfigStore . get . mockImplementation ( ( ) => '' ) ;
160
174
@@ -182,4 +196,28 @@ describe('OrganizationContext', function() {
182
196
183
197
expect ( getOrgMock ) . toHaveBeenLastCalledWith ( '/organizations/foo/' , expect . anything ( ) ) ;
184
198
} ) ;
199
+
200
+ it ( 'fetches org details only once if organizations loading store changes' , async function ( ) {
201
+ wrapper = createWrapper ( {
202
+ params : { orgId : 'org-slug' } ,
203
+ organizationsLoading : true ,
204
+ organizations : [ ] ,
205
+ } ) ;
206
+ await tick ( ) ;
207
+ wrapper . update ( ) ;
208
+ expect ( wrapper . find ( 'LoadingIndicator' ) ) . toHaveLength ( 0 ) ;
209
+ expect ( getOrgMock ) . toHaveBeenCalledTimes ( 1 ) ;
210
+
211
+ // Simulate OrganizationsStore being loaded *after* `OrganizationContext` finishes
212
+ // org details fetch
213
+ wrapper . setProps ( {
214
+ organizationsLoading : false ,
215
+ organizations : [
216
+ TestStubs . Organization ( { slug : 'foo' } ) ,
217
+ TestStubs . Organization ( { slug : 'bar' } ) ,
218
+ ] ,
219
+ } ) ;
220
+
221
+ expect ( getOrgMock ) . toHaveBeenCalledTimes ( 1 ) ;
222
+ } ) ;
185
223
} ) ;
0 commit comments