3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { workbenchCalculateActions } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookEditorToolbar' ;
6
+ import { workbenchCalculateActions , workbenchDynamicCalculateActions } from 'vs/workbench/contrib/notebook/browser/viewParts/notebookEditorToolbar' ;
7
7
import { Action , IAction , Separator } from 'vs/base/common/actions' ;
8
8
import * as assert from 'assert' ;
9
9
@@ -24,7 +24,7 @@ interface IActionModel {
24
24
*
25
25
* ex: action with size 50 requires 58px of space
26
26
*/
27
- suite ( 'workbenchCalculateActions ' , ( ) => {
27
+ suite ( 'Workbench Toolbar calculateActions (strategy always + never) ' , ( ) => {
28
28
29
29
const defaultSecondaryActionModels : IActionModel [ ] = [
30
30
{ action : new Action ( 'secondaryAction0' , 'Secondary Action 0' ) , size : 50 , visible : true , renderLabel : true } ,
@@ -48,7 +48,7 @@ suite('workbenchCalculateActions', () => {
48
48
{ action : new Action ( 'action2' , 'Action 2' ) , size : 50 , visible : true , renderLabel : true } ,
49
49
] ;
50
50
const result = workbenchCalculateActions ( actions , defaultSecondaryActions , 200 ) ;
51
- assert . deepEqual ( result . primaryActions , actions . map ( action => action . action ) ) ;
51
+ assert . deepEqual ( result . primaryActions , actions ) ;
52
52
assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
53
53
} ) ;
54
54
@@ -59,7 +59,7 @@ suite('workbenchCalculateActions', () => {
59
59
{ action : new Action ( 'action2' , 'Action 2' ) , size : 50 , visible : true , renderLabel : true } ,
60
60
] ;
61
61
const result = workbenchCalculateActions ( actions , defaultSecondaryActions , 100 ) ;
62
- assert . deepEqual ( result . primaryActions , [ actions [ 0 ] ] . map ( action => action . action ) ) ;
62
+ assert . deepEqual ( result . primaryActions , [ actions [ 0 ] ] ) ;
63
63
assert . deepEqual ( result . secondaryActions , [ actions [ 1 ] , actions [ 2 ] , separator , ...defaultSecondaryActionModels ] . map ( action => action . action ) ) ;
64
64
} ) ;
65
65
@@ -71,7 +71,7 @@ suite('workbenchCalculateActions', () => {
71
71
{ action : new Action ( 'action1' , 'Action 1' ) , size : 50 , visible : true , renderLabel : true } ,
72
72
] ;
73
73
const result = workbenchCalculateActions ( actions , defaultSecondaryActions , 125 ) ;
74
- assert . deepEqual ( result . primaryActions , [ actions [ 0 ] , actions [ 1 ] , actions [ 3 ] ] . map ( action => action . action ) ) ;
74
+ assert . deepEqual ( result . primaryActions , [ actions [ 0 ] , actions [ 1 ] , actions [ 3 ] ] ) ;
75
75
assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
76
76
} ) ;
77
77
@@ -83,7 +83,7 @@ suite('workbenchCalculateActions', () => {
83
83
{ action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
84
84
] ;
85
85
const result = workbenchCalculateActions ( actions , defaultSecondaryActions , 200 ) ;
86
- assert . deepEqual ( result . primaryActions , [ actions [ 0 ] , actions [ 1 ] , actions [ 2 ] ] . map ( action => action . action ) ) ;
86
+ assert . deepEqual ( result . primaryActions , [ actions [ 0 ] , actions [ 1 ] , actions [ 2 ] ] ) ;
87
87
assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
88
88
} ) ;
89
89
@@ -95,7 +95,7 @@ suite('workbenchCalculateActions', () => {
95
95
{ action : new Action ( 'action3' , 'Action 3' ) , size : 0 , visible : true , renderLabel : true } ,
96
96
] ;
97
97
const result = workbenchCalculateActions ( actions , defaultSecondaryActions , 116 ) ;
98
- assert . deepEqual ( result . primaryActions , [ actions [ 0 ] , actions [ 1 ] , actions [ 3 ] ] . map ( action => action . action ) ) ;
98
+ assert . deepEqual ( result . primaryActions , [ actions [ 0 ] , actions [ 1 ] , actions [ 3 ] ] ) ;
99
99
assert . deepEqual ( result . secondaryActions , [ actions [ 2 ] , separator , ...defaultSecondaryActionModels ] . map ( action => action . action ) ) ;
100
100
} ) ;
101
101
@@ -106,7 +106,7 @@ suite('workbenchCalculateActions', () => {
106
106
{ action : new Action ( 'action1' , 'Action 1' ) , size : 50 , visible : true , renderLabel : true } ,
107
107
] ;
108
108
const result = workbenchCalculateActions ( actions , defaultSecondaryActions , 116 ) ;
109
- assert . deepEqual ( result . primaryActions , [ actions [ 0 ] , actions [ 2 ] ] . map ( action => action . action ) ) ;
109
+ assert . deepEqual ( result . primaryActions , [ actions [ 0 ] , actions [ 2 ] ] ) ;
110
110
assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
111
111
} ) ;
112
112
@@ -120,7 +120,184 @@ suite('workbenchCalculateActions', () => {
120
120
{ action : new Action ( 'action3' , 'Action 3' ) , size : 50 , visible : true , renderLabel : true } ,
121
121
] ;
122
122
const result = workbenchCalculateActions ( actions , defaultSecondaryActions , 300 ) ;
123
- assert . deepEqual ( result . primaryActions , [ actions [ 0 ] , actions [ 1 ] , actions [ 2 ] , actions [ 3 ] , actions [ 5 ] ] . map ( action => action . action ) ) ;
123
+ assert . deepEqual ( result . primaryActions , [ actions [ 0 ] , actions [ 1 ] , actions [ 2 ] , actions [ 3 ] , actions [ 5 ] ] ) ;
124
+ assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
125
+ } ) ;
126
+ } ) ;
127
+
128
+ suite ( 'Workbench Toolbar Dynamic calculateActions (strategy dynamic)' , ( ) => {
129
+
130
+ const actionTemplate = [
131
+ new Action ( 'action0' , 'Action 0' ) ,
132
+ new Action ( 'action1' , 'Action 1' ) ,
133
+ new Action ( 'action2' , 'Action 2' ) ,
134
+ new Action ( 'action3' , 'Action 3' )
135
+ ] ;
136
+
137
+ const defaultSecondaryActionModels : IActionModel [ ] = [
138
+ { action : new Action ( 'secondaryAction0' , 'Secondary Action 0' ) , size : 50 , visible : true , renderLabel : true } ,
139
+ { action : new Action ( 'secondaryAction1' , 'Secondary Action 1' ) , size : 50 , visible : true , renderLabel : true } ,
140
+ { action : new Action ( 'secondaryAction2' , 'Secondary Action 2' ) , size : 50 , visible : true , renderLabel : true } ,
141
+ ] ;
142
+ const defaultSecondaryActions : IAction [ ] = defaultSecondaryActionModels . map ( action => action . action ) ;
143
+
144
+
145
+ test ( 'should return empty primary and secondary actions when given empty initial actions' , ( ) => {
146
+ const result = workbenchDynamicCalculateActions ( [ ] , [ ] , 100 ) ;
147
+ assert . deepEqual ( result . primaryActions , [ ] ) ;
148
+ assert . deepEqual ( result . secondaryActions , [ ] ) ;
149
+ } ) ;
150
+
151
+ test ( 'should return all primary actions as visiblewhen they fit within the container width' , ( ) => {
152
+ const constainerSize = 200 ;
153
+ const input : IActionModel [ ] = [
154
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
155
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } ,
156
+ { action : actionTemplate [ 2 ] , size : 50 , visible : true , renderLabel : true } ,
157
+ ] ;
158
+ const expected : IActionModel [ ] = [
159
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
160
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } ,
161
+ { action : actionTemplate [ 2 ] , size : 50 , visible : true , renderLabel : true } ,
162
+ ] ;
163
+ const result = workbenchDynamicCalculateActions ( input , defaultSecondaryActions , constainerSize ) ;
164
+ assert . deepEqual ( result . primaryActions , expected ) ;
165
+ assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
166
+ } ) ;
167
+
168
+ test ( 'actions all within a group that cannot all fit, will all be icon only' , ( ) => {
169
+ const containerSize = 150 ;
170
+ const input : IActionModel [ ] = [
171
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
172
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } ,
173
+ { action : actionTemplate [ 2 ] , size : 50 , visible : true , renderLabel : true } ,
174
+ ] ;
175
+ const expected : IActionModel [ ] = [
176
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : false } ,
177
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : false } ,
178
+ { action : actionTemplate [ 2 ] , size : 50 , visible : true , renderLabel : false } ,
179
+ ] ;
180
+
181
+
182
+ const result = workbenchDynamicCalculateActions ( input , defaultSecondaryActions , containerSize ) ;
183
+ assert . deepEqual ( result . primaryActions , expected ) ;
184
+ assert . deepEqual ( result . secondaryActions , [ ...defaultSecondaryActionModels ] . map ( action => action . action ) ) ;
185
+ } ) ;
186
+
187
+ test ( 'should ignore second separator when two separators are in a row' , ( ) => {
188
+ const containerSize = 200 ;
189
+ const input : IActionModel [ ] = [
190
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
191
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
192
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
193
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } ,
194
+ ] ;
195
+ const expected : IActionModel [ ] = [
196
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
197
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
198
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } ,
199
+ ] ;
200
+ const result = workbenchDynamicCalculateActions ( input , defaultSecondaryActions , containerSize ) ;
201
+ assert . deepEqual ( result . primaryActions , expected ) ;
202
+ assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
203
+ } ) ;
204
+
205
+ test ( 'check label visibility in different groupings' , ( ) => {
206
+ const containerSize = 150 ;
207
+ const actions : IActionModel [ ] = [
208
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
209
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
210
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } ,
211
+ { action : actionTemplate [ 2 ] , size : 50 , visible : true , renderLabel : true } ,
212
+ ] ;
213
+ const expectedOutputActions : IActionModel [ ] = [
214
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
215
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
216
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : false } ,
217
+ { action : actionTemplate [ 2 ] , size : 50 , visible : true , renderLabel : false } ,
218
+ ] ;
219
+
220
+
221
+ const result = workbenchDynamicCalculateActions ( actions , defaultSecondaryActions , containerSize ) ;
222
+ assert . deepEqual ( result . primaryActions , expectedOutputActions ) ;
223
+ assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
224
+ } ) ;
225
+
226
+ test ( 'should ignore separators when they are at the end of the resulting primary actions' , ( ) => {
227
+ const containerSize = 200 ;
228
+ const input : IActionModel [ ] = [
229
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
230
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
231
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } ,
232
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
233
+ ] ;
234
+ const expected : IActionModel [ ] = [
235
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
236
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
237
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } ,
238
+ ] ;
239
+ const result = workbenchDynamicCalculateActions ( input , defaultSecondaryActions , containerSize ) ;
240
+ assert . deepEqual ( result . primaryActions , expected ) ;
241
+ assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
242
+ } ) ;
243
+
244
+ test ( 'should keep actions with size 0 in primary actions' , ( ) => {
245
+ const containerSize = 170 ;
246
+ const input : IActionModel [ ] = [
247
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
248
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } ,
249
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
250
+ { action : actionTemplate [ 2 ] , size : 50 , visible : true , renderLabel : true } ,
251
+ { action : actionTemplate [ 3 ] , size : 0 , visible : true , renderLabel : true } ,
252
+ ] ;
253
+ const expected : IActionModel [ ] = [
254
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
255
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } ,
256
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
257
+ { action : actionTemplate [ 2 ] , size : 50 , visible : true , renderLabel : false } ,
258
+ { action : actionTemplate [ 3 ] , size : 0 , visible : true , renderLabel : false } ,
259
+ ] ;
260
+ const result = workbenchDynamicCalculateActions ( input , defaultSecondaryActions , containerSize ) ;
261
+ assert . deepEqual ( result . primaryActions , expected ) ;
262
+ assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
263
+ } ) ;
264
+
265
+ test ( 'should not render separator if preceeded by size 0 action(s), but keep size 0 action in primary.' , ( ) => {
266
+ const containerSize = 116 ;
267
+ const input : IActionModel [ ] = [
268
+ { action : actionTemplate [ 0 ] , size : 0 , visible : true , renderLabel : true } , // hidden
269
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } , // sep
270
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } , // visible
271
+ ] ;
272
+ const expected : IActionModel [ ] = [
273
+ { action : actionTemplate [ 0 ] , size : 0 , visible : true , renderLabel : true } , // hidden
274
+ { action : actionTemplate [ 1 ] , size : 50 , visible : true , renderLabel : true } // visible
275
+ ] ;
276
+ const result = workbenchDynamicCalculateActions ( input , defaultSecondaryActions , containerSize ) ;
277
+ assert . deepEqual ( result . primaryActions , expected ) ;
278
+ assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
279
+ } ) ;
280
+
281
+ test ( 'should not render second separator if space between is hidden (size 0) actions.' , ( ) => {
282
+ const containerSize = 300 ;
283
+ const input : IActionModel [ ] = [
284
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
285
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
286
+ { action : actionTemplate [ 1 ] , size : 0 , visible : true , renderLabel : true } ,
287
+ { action : actionTemplate [ 2 ] , size : 0 , visible : true , renderLabel : true } ,
288
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
289
+ { action : actionTemplate [ 3 ] , size : 50 , visible : true , renderLabel : true } ,
290
+ ] ;
291
+ const expected : IActionModel [ ] = [
292
+ { action : actionTemplate [ 0 ] , size : 50 , visible : true , renderLabel : true } ,
293
+ { action : new Separator ( ) , size : 1 , visible : true , renderLabel : true } ,
294
+ { action : actionTemplate [ 1 ] , size : 0 , visible : true , renderLabel : true } ,
295
+ { action : actionTemplate [ 2 ] , size : 0 , visible : true , renderLabel : true } ,
296
+ // remove separator here
297
+ { action : actionTemplate [ 3 ] , size : 50 , visible : true , renderLabel : true } ,
298
+ ] ;
299
+ const result = workbenchDynamicCalculateActions ( input , defaultSecondaryActions , containerSize ) ;
300
+ assert . deepEqual ( result . primaryActions , expected ) ;
124
301
assert . deepEqual ( result . secondaryActions , defaultSecondaryActions ) ;
125
302
} ) ;
126
303
} ) ;
0 commit comments