@@ -9,23 +9,19 @@ import {
9
9
} from '@testing-library/react' ;
10
10
import { expect } from 'chai' ;
11
11
import type { ConnectionOptions , connect } from 'mongodb-data-service' ;
12
- import type {
13
- ConnectionInfo ,
14
- ConnectionStorage ,
12
+ import {
13
+ type ConnectionInfo ,
14
+ type ConnectionStorage ,
15
+ ConnectionStorageBus ,
15
16
} from '@mongodb-js/connection-storage/renderer' ;
16
17
import { v4 as uuid } from 'uuid' ;
17
18
import sinon from 'sinon' ;
18
-
19
19
import Connections from './connections' ;
20
20
import { ToastArea } from '@mongodb-js/compass-components' ;
21
21
import type { PreferencesAccess } from 'compass-preferences-model' ;
22
22
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model' ;
23
23
import { PreferencesProvider } from 'compass-preferences-model/provider' ;
24
- import { ConnectionRepository } from '@mongodb-js/connection-storage/main' ;
25
- import {
26
- ConnectionRepositoryContext ,
27
- ConnectionStorageContext ,
28
- } from '@mongodb-js/connection-storage/provider' ;
24
+ import { ConnectionStorageContext } from '@mongodb-js/connection-storage/provider' ;
29
25
import { ConnectionsManager , ConnectionsManagerProvider } from '../provider' ;
30
26
import type { DataService } from 'mongodb-data-service' ;
31
27
import { createNoopLoggerAndTelemetry } from '@mongodb-js/compass-logging/provider' ;
@@ -40,6 +36,7 @@ function getConnectionsManager(mockTestConnectFn?: typeof connect) {
40
36
41
37
function getMockConnectionStorage ( mockConnections : ConnectionInfo [ ] ) {
42
38
return {
39
+ events : new ConnectionStorageBus ( ) ,
43
40
loadAll : ( ) => {
44
41
return Promise . resolve ( mockConnections ) ;
45
42
} ,
@@ -101,27 +98,23 @@ describe('Connections Component', function () {
101
98
beforeEach ( function ( ) {
102
99
const mockStorage = getMockConnectionStorage ( [ ] ) ;
103
100
loadConnectionsSpy = sinon . spy ( mockStorage , 'loadAll' ) ;
104
- const connectionRepository = new ConnectionRepository ( mockStorage ) ;
105
101
render (
106
102
< PreferencesProvider value = { preferences } >
107
103
< ConnectionStorageContext . Provider value = { mockStorage } >
108
- < ConnectionRepositoryContext . Provider value = { connectionRepository } >
109
- < ConnectionsManagerProvider value = { getConnectionsManager ( ) } >
110
- < Connections
111
- onConnected = { onConnectedSpy }
112
- onConnectionFailed = { onConnectionFailedSpy }
113
- onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
114
- appName = "Test App Name"
115
- />
116
- </ ConnectionsManagerProvider >
117
- </ ConnectionRepositoryContext . Provider >
104
+ < ConnectionsManagerProvider value = { getConnectionsManager ( ) } >
105
+ < Connections
106
+ onConnected = { onConnectedSpy }
107
+ onConnectionFailed = { onConnectionFailedSpy }
108
+ onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
109
+ />
110
+ </ ConnectionsManagerProvider >
118
111
</ ConnectionStorageContext . Provider >
119
112
</ PreferencesProvider >
120
113
) ;
121
114
} ) ;
122
115
123
116
it ( 'calls once to load the connections' , function ( ) {
124
- expect ( loadConnectionsSpy . callCount ) . to . equal ( 2 ) ; // favorite + recent
117
+ expect ( loadConnectionsSpy . callCount ) . to . equal ( 1 ) ;
125
118
} ) ;
126
119
127
120
it ( 'renders the connect button from the connect-form' , function ( ) {
@@ -193,7 +186,6 @@ describe('Connections Component', function () {
193
186
] ;
194
187
mockStorage = getMockConnectionStorage ( connections ) ;
195
188
sinon . replace ( mockStorage , 'save' , saveConnectionSpy ) ;
196
- const connectionRepository = new ConnectionRepository ( mockStorage ) ;
197
189
198
190
const connectionsManager = getConnectionsManager ( ( ) => {
199
191
return Promise . resolve ( {
@@ -206,18 +198,15 @@ describe('Connections Component', function () {
206
198
render (
207
199
< PreferencesProvider value = { preferences } >
208
200
< ConnectionStorageContext . Provider value = { mockStorage } >
209
- < ConnectionRepositoryContext . Provider value = { connectionRepository } >
210
- < ConnectionsManagerProvider value = { connectionsManager } >
211
- < ToastArea >
212
- < Connections
213
- onConnected = { onConnectedSpy }
214
- onConnectionFailed = { onConnectionFailedSpy }
215
- onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
216
- appName = "Test App Name"
217
- />
218
- </ ToastArea >
219
- </ ConnectionsManagerProvider >
220
- </ ConnectionRepositoryContext . Provider >
201
+ < ConnectionsManagerProvider value = { connectionsManager } >
202
+ < ToastArea >
203
+ < Connections
204
+ onConnected = { onConnectedSpy }
205
+ onConnectionFailed = { onConnectionFailedSpy }
206
+ onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
207
+ />
208
+ </ ToastArea >
209
+ </ ConnectionsManagerProvider >
221
210
</ ConnectionStorageContext . Provider >
222
211
</ PreferencesProvider >
223
212
) ;
@@ -269,8 +258,7 @@ describe('Connections Component', function () {
269
258
connectSpyFn . firstCall . args [ 0 ] . connectionOptions
270
259
) . to . deep . equal ( {
271
260
connectionString :
272
- 'mongodb://localhost:27018/?readPreference=primary&ssl=false&appName=Test+App+Name' ,
273
- oidc : { } ,
261
+ 'mongodb://localhost:27018/?readPreference=primary&ssl=false' ,
274
262
} ) ;
275
263
} ) ;
276
264
@@ -325,7 +313,6 @@ describe('Connections Component', function () {
325
313
) . to . deep . equal ( {
326
314
connectionString :
327
315
'mongodb://localhost:27019/?appName=Some+App+Name' ,
328
- oidc : { } ,
329
316
} ) ;
330
317
} ) ;
331
318
}
@@ -355,7 +342,7 @@ describe('Connections Component', function () {
355
342
} ) => {
356
343
if (
357
344
connectionOptions . connectionString ===
358
- 'mongodb://localhost:27099/?connectTimeoutMS=5000&serverSelectionTimeoutMS=5000&appName=Test+App+Name '
345
+ 'mongodb://localhost:27099/?connectTimeoutMS=5000&serverSelectionTimeoutMS=5000'
359
346
) {
360
347
return new Promise ( ( resolve ) => {
361
348
// On first call we want this attempt to be cancelled before
@@ -395,25 +382,19 @@ describe('Connections Component', function () {
395
382
] ;
396
383
const mockStorage = getMockConnectionStorage ( connections ) ;
397
384
sinon . replace ( mockStorage , 'save' , saveConnectionSpy ) ;
398
- const connectionRepository = new ConnectionRepository ( mockStorage ) ;
399
385
400
386
render (
401
387
< PreferencesProvider value = { preferences } >
402
388
< ConnectionStorageContext . Provider value = { mockStorage } >
403
- < ConnectionRepositoryContext . Provider
404
- value = { connectionRepository }
405
- >
406
- < ConnectionsManagerProvider value = { connectionsManager } >
407
- < ToastArea >
408
- < Connections
409
- onConnected = { onConnectedSpy }
410
- onConnectionFailed = { onConnectionFailedSpy }
411
- onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
412
- appName = "Test App Name"
413
- />
414
- </ ToastArea >
415
- </ ConnectionsManagerProvider >
416
- </ ConnectionRepositoryContext . Provider >
389
+ < ConnectionsManagerProvider value = { connectionsManager } >
390
+ < ToastArea >
391
+ < Connections
392
+ onConnected = { onConnectedSpy }
393
+ onConnectionFailed = { onConnectionFailedSpy }
394
+ onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
395
+ />
396
+ </ ToastArea >
397
+ </ ConnectionsManagerProvider >
417
398
</ ConnectionStorageContext . Provider >
418
399
</ PreferencesProvider >
419
400
) ;
@@ -480,8 +461,7 @@ describe('Connections Component', function () {
480
461
connectSpyFn . firstCall . args [ 0 ] . connectionOptions
481
462
) . to . deep . equal ( {
482
463
connectionString :
483
- 'mongodb://localhost:27099/?connectTimeoutMS=5000&serverSelectionTimeoutMS=5000&appName=Test+App+Name' ,
484
- oidc : { } ,
464
+ 'mongodb://localhost:27099/?connectTimeoutMS=5000&serverSelectionTimeoutMS=5000' ,
485
465
} ) ;
486
466
} ) ;
487
467
@@ -521,8 +501,7 @@ describe('Connections Component', function () {
521
501
connectSpyFn . secondCall . args [ 0 ] . connectionOptions
522
502
) . to . deep . equal ( {
523
503
connectionString :
524
- 'mongodb://localhost:27018/?readPreference=primary&ssl=false&appName=Test+App+Name' ,
525
- oidc : { } ,
504
+ 'mongodb://localhost:27018/?readPreference=primary&ssl=false' ,
526
505
} ) ;
527
506
} ) ;
528
507
}
@@ -538,23 +517,18 @@ describe('Connections Component', function () {
538
517
. stub ( mockStorage , 'getLegacyConnections' )
539
518
. resolves ( [ { name : 'Connection1' } ] ) ;
540
519
541
- const connectionRepository = new ConnectionRepository ( mockStorage ) ;
542
-
543
520
render (
544
521
< PreferencesProvider value = { preferences } >
545
522
< ConnectionStorageContext . Provider value = { mockStorage } >
546
- < ConnectionRepositoryContext . Provider value = { connectionRepository } >
547
- < ConnectionsManagerProvider value = { getConnectionsManager ( ) } >
548
- < ToastArea >
549
- < Connections
550
- onConnected = { onConnectedSpy }
551
- onConnectionFailed = { onConnectionFailedSpy }
552
- onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
553
- appName = "Test App Name"
554
- />
555
- </ ToastArea >
556
- </ ConnectionsManagerProvider >
557
- </ ConnectionRepositoryContext . Provider >
523
+ < ConnectionsManagerProvider value = { getConnectionsManager ( ) } >
524
+ < ToastArea >
525
+ < Connections
526
+ onConnected = { onConnectedSpy }
527
+ onConnectionFailed = { onConnectionFailedSpy }
528
+ onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
529
+ />
530
+ </ ToastArea >
531
+ </ ConnectionsManagerProvider >
558
532
</ ConnectionStorageContext . Provider >
559
533
</ PreferencesProvider >
560
534
) ;
@@ -573,23 +547,18 @@ describe('Connections Component', function () {
573
547
. stub ( mockStorage , 'getLegacyConnections' )
574
548
. resolves ( [ { name : 'Connection2' } ] ) ;
575
549
576
- const connectionRepository = new ConnectionRepository ( mockStorage ) ;
577
-
578
550
const { rerender } = render (
579
551
< PreferencesProvider value = { preferences } >
580
552
< ConnectionStorageContext . Provider value = { mockStorage } >
581
- < ConnectionRepositoryContext . Provider value = { connectionRepository } >
582
- < ConnectionsManagerProvider value = { getConnectionsManager ( ) } >
583
- < ToastArea >
584
- < Connections
585
- onConnected = { onConnectedSpy }
586
- onConnectionFailed = { onConnectionFailedSpy }
587
- onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
588
- appName = "Test App Name"
589
- />
590
- </ ToastArea >
591
- </ ConnectionsManagerProvider >
592
- </ ConnectionRepositoryContext . Provider >
553
+ < ConnectionsManagerProvider value = { getConnectionsManager ( ) } >
554
+ < ToastArea >
555
+ < Connections
556
+ onConnected = { onConnectedSpy }
557
+ onConnectionFailed = { onConnectionFailedSpy }
558
+ onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
559
+ />
560
+ </ ToastArea >
561
+ </ ConnectionsManagerProvider >
593
562
</ ConnectionStorageContext . Provider >
594
563
</ PreferencesProvider >
595
564
) ;
@@ -607,18 +576,15 @@ describe('Connections Component', function () {
607
576
rerender (
608
577
< PreferencesProvider value = { preferences } >
609
578
< ConnectionStorageContext . Provider value = { mockStorage } >
610
- < ConnectionRepositoryContext . Provider value = { connectionRepository } >
611
- < ConnectionsManagerProvider value = { getConnectionsManager ( ) } >
612
- < ToastArea >
613
- < Connections
614
- onConnected = { onConnectedSpy }
615
- onConnectionFailed = { onConnectionFailedSpy }
616
- onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
617
- appName = "Test App Name"
618
- />
619
- </ ToastArea >
620
- </ ConnectionsManagerProvider >
621
- </ ConnectionRepositoryContext . Provider >
579
+ < ConnectionsManagerProvider value = { getConnectionsManager ( ) } >
580
+ < ToastArea >
581
+ < Connections
582
+ onConnected = { onConnectedSpy }
583
+ onConnectionFailed = { onConnectionFailedSpy }
584
+ onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
585
+ />
586
+ </ ToastArea >
587
+ </ ConnectionsManagerProvider >
622
588
</ ConnectionStorageContext . Provider >
623
589
</ PreferencesProvider >
624
590
) ;
@@ -634,31 +600,4 @@ describe('Connections Component', function () {
634
600
} ) . to . throw ;
635
601
} ) ;
636
602
} ) ;
637
-
638
- context ( 'when multiple connection management is enabled' , function ( ) {
639
- beforeEach ( async function ( ) {
640
- await preferences . savePreferences ( {
641
- enableNewMultipleConnectionSystem : true ,
642
- } ) ;
643
- const mockStorage = getMockConnectionStorage ( [ ] ) ;
644
- const connectionRepository = new ConnectionRepository ( mockStorage ) ;
645
-
646
- render (
647
- < PreferencesProvider value = { preferences } >
648
- < ConnectionStorageContext . Provider value = { mockStorage } >
649
- < ConnectionRepositoryContext . Provider value = { connectionRepository } >
650
- < ConnectionsManagerProvider value = { getConnectionsManager ( ) } >
651
- < Connections
652
- onConnected = { onConnectedSpy }
653
- onConnectionFailed = { onConnectionFailedSpy }
654
- onConnectionAttemptStarted = { onConnectionAttemptStartedSpy }
655
- appName = "Test App Name"
656
- />
657
- </ ConnectionsManagerProvider >
658
- </ ConnectionRepositoryContext . Provider >
659
- </ ConnectionStorageContext . Provider >
660
- </ PreferencesProvider >
661
- ) ;
662
- } ) ;
663
- } ) ;
664
603
} ) ;
0 commit comments