66'use strict' ;
77
88import * as assert from 'assert' ;
9- import { IAction } from 'vs/base/common/actions' ;
109import { MainThreadMessageService } from 'vs/workbench/api/electron-browser/mainThreadMessageService' ;
11- import { TPromise as Promise } from 'vs/base/common/winjs.base' ;
10+ import { TPromise as Promise , TPromise } from 'vs/base/common/winjs.base' ;
1211import { IChoiceService } from 'vs/platform/dialogs/common/dialogs' ;
13- import { INotificationService , INotification } from 'vs/platform/notification/common/notification' ;
12+ import { INotificationService , INotification , NoOpNotification , INotificationHandle } from 'vs/platform/notification/common/notification' ;
13+ import { ICommandService } from 'vs/platform/commands/common/commands' ;
1414
1515const emptyChoiceService = new class implements IChoiceService {
1616 _serviceBrand : 'choiceService' ;
@@ -19,6 +19,13 @@ const emptyChoiceService = new class implements IChoiceService {
1919 }
2020} ;
2121
22+ const emptyCommandService : ICommandService = {
23+ _serviceBrand : undefined ,
24+ onWillExecuteCommand : ( ) => ( { dispose : ( ) => { } } ) ,
25+ executeCommand : ( commandId : string , ...args : any [ ] ) : TPromise < any > => {
26+ return TPromise . as ( void 0 ) ;
27+ }
28+ } ;
2229
2330const emptyNotificationService = new class implements INotificationService {
2431 _serviceBrand : 'notificiationService' ;
@@ -36,74 +43,46 @@ const emptyNotificationService = new class implements INotificationService {
3643 }
3744} ;
3845
46+ class EmptyNotificationService implements INotificationService {
47+
48+ _serviceBrand : any ;
49+
50+ constructor ( private withNotify : ( notification : INotification ) => void ) {
51+ }
52+
53+ notify ( notification : INotification ) : INotificationHandle {
54+ this . withNotify ( notification ) ;
55+
56+ return new NoOpNotification ( ) ;
57+ }
58+ info ( message : any ) : void {
59+ throw new Error ( 'Method not implemented.' ) ;
60+ }
61+ warn ( message : any ) : void {
62+ throw new Error ( 'Method not implemented.' ) ;
63+ }
64+ error ( message : any ) : void {
65+ throw new Error ( 'Method not implemented.' ) ;
66+ }
67+ }
68+
3969suite ( 'ExtHostMessageService' , function ( ) {
4070
4171 test ( 'propagte handle on select' , function ( ) {
4272
43- let service = new MainThreadMessageService ( null , {
44- notify ( m : INotification ) {
45- assert . equal ( m . actions . primary . length , 1 ) ;
46- setImmediate ( ( ) => m . actions . primary [ 0 ] . run ( ) ) ;
47- return undefined ;
48- }
49- } as INotificationService , emptyChoiceService ) ;
73+ let service = new MainThreadMessageService ( null , new EmptyNotificationService ( notification => {
74+ assert . equal ( notification . actions . primary . length , 1 ) ;
75+ setImmediate ( ( ) => notification . actions . primary [ 0 ] . run ( ) ) ;
76+ } ) , emptyCommandService , emptyChoiceService ) ;
5077
5178 return service . $showMessage ( 1 , 'h' , { } , [ { handle : 42 , title : 'a thing' , isCloseAffordance : true } ] ) . then ( handle => {
5279 assert . equal ( handle , 42 ) ;
5380 } ) ;
5481 } ) ;
5582
56- test ( 'isCloseAffordance' , function ( ) {
57-
58- let actions : IAction [ ] ;
59- let service = new MainThreadMessageService ( null , {
60- notify ( m : INotification ) {
61- actions = m . actions . primary ;
62-
63- return undefined ;
64- }
65- } as INotificationService , emptyChoiceService ) ;
66-
67- // default close action
68- service . $showMessage ( 1 , '' , { } , [ { title : 'a thing' , isCloseAffordance : false , handle : 0 } ] ) ;
69- assert . equal ( actions . length , 2 ) ;
70- let [ first , second ] = actions ;
71- assert . equal ( first . label , 'a thing' ) ;
72- assert . equal ( second . label , 'Close' ) ;
73-
74- // override close action
75- service . $showMessage ( 1 , '' , { } , [ { title : 'a thing' , isCloseAffordance : true , handle : 0 } ] ) ;
76- assert . equal ( actions . length , 1 ) ;
77- first = actions [ 0 ] ;
78- assert . equal ( first . label , 'a thing' ) ;
79- } ) ;
80-
81- test ( 'hide on select' , function ( ) {
82-
83- let actions : IAction [ ] ;
84- let c : number ;
85- let service = new MainThreadMessageService ( null , {
86- notify ( m : INotification ) {
87- c = 0 ;
88- actions = m . actions . primary ;
89- return {
90- dispose : ( ) => {
91- c += 1 ;
92- }
93- } ;
94- }
95- } as INotificationService , emptyChoiceService ) ;
96-
97- service . $showMessage ( 1 , '' , { } , [ { title : 'a thing' , isCloseAffordance : true , handle : 0 } ] ) ;
98- assert . equal ( actions . length , 1 ) ;
99-
100- actions [ 0 ] . run ( ) ;
101- assert . equal ( c , 1 ) ;
102- } ) ;
103-
10483 suite ( 'modal' , ( ) => {
10584 test ( 'calls choice service' , ( ) => {
106- const service = new MainThreadMessageService ( null , emptyNotificationService , {
85+ const service = new MainThreadMessageService ( null , emptyNotificationService , emptyCommandService , {
10786 choose ( severity , message , options , modal ) {
10887 assert . equal ( severity , 1 ) ;
10988 assert . equal ( message , 'h' ) ;
@@ -119,7 +98,7 @@ suite('ExtHostMessageService', function () {
11998 } ) ;
12099
121100 test ( 'returns undefined when cancelled' , ( ) => {
122- const service = new MainThreadMessageService ( null , emptyNotificationService , {
101+ const service = new MainThreadMessageService ( null , emptyNotificationService , emptyCommandService , {
123102 choose ( severity , message , options , modal ) {
124103 return Promise . as ( 1 ) ;
125104 }
@@ -131,7 +110,7 @@ suite('ExtHostMessageService', function () {
131110 } ) ;
132111
133112 test ( 'hides Cancel button when not needed' , ( ) => {
134- const service = new MainThreadMessageService ( null , emptyNotificationService , {
113+ const service = new MainThreadMessageService ( null , emptyNotificationService , emptyCommandService , {
135114 choose ( severity , message , options , modal ) {
136115 assert . equal ( options . length , 1 ) ;
137116 return Promise . as ( 0 ) ;
0 commit comments