@@ -270,6 +270,60 @@ suite('Playground Controller Test Suite', function () {
270
270
expectedMessage
271
271
) ;
272
272
} ) ;
273
+
274
+ suite ( 'running code from the participant' , function ( ) {
275
+ beforeEach ( function ( ) {
276
+ sinon
277
+ . stub ( testPlaygroundController , '_evaluateWithCancelModal' )
278
+ . resolves ( { result : '123' } as any ) ;
279
+ sinon . stub ( testPlaygroundController , '_openInResultPane' ) . resolves ( ) ;
280
+
281
+ showInformationMessageStub . resolves ( 'Yes' ) ;
282
+ } ) ;
283
+
284
+ afterEach ( ( ) => sinon . restore ( ) ) ;
285
+
286
+ test ( 'prompts to connect to a database and succeeds with selection' , async ( ) => {
287
+ const changeActiveConnectionStub = sinon . stub (
288
+ testPlaygroundController . _connectionController ,
289
+ 'changeActiveConnection'
290
+ ) ;
291
+ // Mocks the user selecting a connection.
292
+ changeActiveConnectionStub . resolves ( true ) ;
293
+
294
+ const result = await testPlaygroundController . evaluateParticipantCode (
295
+ 'console.log("test");'
296
+ ) ;
297
+
298
+ expect ( showErrorMessageStub . notCalled ) . is . true ;
299
+
300
+ expect ( changeActiveConnectionStub . calledOnce ) . is . true ;
301
+
302
+ expect ( result ) . is . true ;
303
+ } ) ;
304
+
305
+ test ( 'prompts to connect to a database and errors if not selected' , async ( ) => {
306
+ const changeActiveConnectionStub = sinon . stub (
307
+ testPlaygroundController . _connectionController ,
308
+ 'changeActiveConnection'
309
+ ) ;
310
+ // Mocks the user selecting a connection.
311
+ changeActiveConnectionStub . resolves ( false ) ;
312
+
313
+ const result = await testPlaygroundController . evaluateParticipantCode (
314
+ 'console.log("test");'
315
+ ) ;
316
+
317
+ const expectedMessage =
318
+ 'Please connect to a database before running a playground.' ;
319
+ await testPlaygroundController . runAllOrSelectedPlaygroundBlocks ( ) ;
320
+ expect ( showErrorMessageStub . firstCall . args [ 0 ] ) . to . be . equal (
321
+ expectedMessage
322
+ ) ;
323
+
324
+ expect ( result ) . is . false ;
325
+ } ) ;
326
+ } ) ;
273
327
} ) ;
274
328
275
329
suite ( 'user is connected' , ( ) => {
@@ -431,6 +485,35 @@ suite('Playground Controller Test Suite', function () {
431
485
expect ( result ) . to . be . false ;
432
486
} ) ;
433
487
} ) ;
488
+
489
+ suite ( 'running code from the participant' , function ( ) {
490
+ beforeEach ( function ( ) {
491
+ sinon
492
+ . stub ( testPlaygroundController , '_evaluateWithCancelModal' )
493
+ . resolves ( { result : '123' } as any ) ;
494
+ sinon . stub ( testPlaygroundController , '_openInResultPane' ) . resolves ( ) ;
495
+
496
+ showInformationMessageStub . resolves ( 'Yes' ) ;
497
+ } ) ;
498
+
499
+ afterEach ( ( ) => sinon . restore ( ) ) ;
500
+
501
+ test ( 'does not prompt to connect to the database' , async ( ) => {
502
+ const changeActiveConnectionStub = sinon . stub (
503
+ testPlaygroundController . _connectionController ,
504
+ 'changeActiveConnection'
505
+ ) ;
506
+ const result = await testPlaygroundController . evaluateParticipantCode (
507
+ 'console.log("test");'
508
+ ) ;
509
+
510
+ expect ( showErrorMessageStub . notCalled ) . is . true ;
511
+
512
+ expect ( changeActiveConnectionStub . notCalled ) . is . true ;
513
+
514
+ expect ( result ) . is . true ;
515
+ } ) ;
516
+ } ) ;
434
517
} ) ;
435
518
} ) ;
436
519
} ) ;
0 commit comments