@@ -178,32 +178,26 @@ describe('SecurityNavControlService', () => {
178
178
} ) ;
179
179
180
180
describe ( `#start` , ( ) => {
181
- it ( 'should return functions to register and retrieve user menu links' , ( ) => {
182
- const license$ = new BehaviorSubject < ILicense > ( validLicense ) ;
181
+ let navControlService : SecurityNavControlService ;
182
+ beforeEach ( ( ) => {
183
+ const license$ = new BehaviorSubject < ILicense > ( { } as ILicense ) ;
183
184
184
- const navControlService = new SecurityNavControlService ( ) ;
185
+ navControlService = new SecurityNavControlService ( ) ;
185
186
navControlService . setup ( {
186
187
securityLicense : new SecurityLicenseService ( ) . setup ( { license$ } ) . license ,
187
188
authc : securityMock . createSetup ( ) . authc ,
188
189
logoutUrl : '/some/logout/url' ,
189
190
} ) ;
191
+ } ) ;
190
192
193
+ it ( 'should return functions to register and retrieve user menu links' , ( ) => {
191
194
const coreStart = coreMock . createStart ( ) ;
192
195
const navControlServiceStart = navControlService . start ( { core : coreStart } ) ;
193
196
expect ( navControlServiceStart ) . toHaveProperty ( 'getUserMenuLinks$' ) ;
194
197
expect ( navControlServiceStart ) . toHaveProperty ( 'addUserMenuLinks' ) ;
195
198
} ) ;
196
199
197
200
it ( 'should register custom user menu links to be displayed in the nav controls' , ( done ) => {
198
- const license$ = new BehaviorSubject < ILicense > ( validLicense ) ;
199
-
200
- const navControlService = new SecurityNavControlService ( ) ;
201
- navControlService . setup ( {
202
- securityLicense : new SecurityLicenseService ( ) . setup ( { license$ } ) . license ,
203
- authc : securityMock . createSetup ( ) . authc ,
204
- logoutUrl : '/some/logout/url' ,
205
- } ) ;
206
-
207
201
const coreStart = coreMock . createStart ( ) ;
208
202
const { getUserMenuLinks$, addUserMenuLinks } = navControlService . start ( { core : coreStart } ) ;
209
203
const userMenuLinks$ = getUserMenuLinks$ ( ) ;
@@ -231,15 +225,6 @@ describe('SecurityNavControlService', () => {
231
225
} ) ;
232
226
233
227
it ( 'should retrieve user menu links sorted by order' , ( done ) => {
234
- const license$ = new BehaviorSubject < ILicense > ( validLicense ) ;
235
-
236
- const navControlService = new SecurityNavControlService ( ) ;
237
- navControlService . setup ( {
238
- securityLicense : new SecurityLicenseService ( ) . setup ( { license$ } ) . license ,
239
- authc : securityMock . createSetup ( ) . authc ,
240
- logoutUrl : '/some/logout/url' ,
241
- } ) ;
242
-
243
228
const coreStart = coreMock . createStart ( ) ;
244
229
const { getUserMenuLinks$, addUserMenuLinks } = navControlService . start ( { core : coreStart } ) ;
245
230
const userMenuLinks$ = getUserMenuLinks$ ( ) ;
@@ -305,5 +290,79 @@ describe('SecurityNavControlService', () => {
305
290
done ( ) ;
306
291
} ) ;
307
292
} ) ;
293
+
294
+ it ( 'should allow adding a custom profile link' , ( ) => {
295
+ const coreStart = coreMock . createStart ( ) ;
296
+ const { getUserMenuLinks$, addUserMenuLinks } = navControlService . start ( { core : coreStart } ) ;
297
+ const userMenuLinks$ = getUserMenuLinks$ ( ) ;
298
+
299
+ addUserMenuLinks ( [
300
+ { label : 'link3' , href : 'path-to-link3' , iconType : 'empty' , order : 3 } ,
301
+ { label : 'link1' , href : 'path-to-link1' , iconType : 'empty' , order : 1 , setAsProfile : true } ,
302
+ ] ) ;
303
+
304
+ const onUserMenuLinksHandler = jest . fn ( ) ;
305
+ userMenuLinks$ . subscribe ( onUserMenuLinksHandler ) ;
306
+
307
+ expect ( onUserMenuLinksHandler ) . toHaveBeenCalledTimes ( 1 ) ;
308
+ expect ( onUserMenuLinksHandler ) . toHaveBeenCalledWith ( [
309
+ { label : 'link1' , href : 'path-to-link1' , iconType : 'empty' , order : 1 , setAsProfile : true } ,
310
+ { label : 'link3' , href : 'path-to-link3' , iconType : 'empty' , order : 3 } ,
311
+ ] ) ;
312
+ } ) ;
313
+
314
+ it ( 'should not allow adding more than one custom profile link' , ( ) => {
315
+ const coreStart = coreMock . createStart ( ) ;
316
+ const { getUserMenuLinks$, addUserMenuLinks } = navControlService . start ( { core : coreStart } ) ;
317
+ const userMenuLinks$ = getUserMenuLinks$ ( ) ;
318
+
319
+ expect ( ( ) => {
320
+ addUserMenuLinks ( [
321
+ {
322
+ label : 'link3' ,
323
+ href : 'path-to-link3' ,
324
+ iconType : 'empty' ,
325
+ order : 3 ,
326
+ setAsProfile : true ,
327
+ } ,
328
+ {
329
+ label : 'link1' ,
330
+ href : 'path-to-link1' ,
331
+ iconType : 'empty' ,
332
+ order : 1 ,
333
+ setAsProfile : true ,
334
+ } ,
335
+ ] ) ;
336
+ } ) . toThrowErrorMatchingInlineSnapshot (
337
+ `"Only one custom profile link can be passed at a time (found 2)"`
338
+ ) ;
339
+
340
+ // Adding a single custom profile link.
341
+ addUserMenuLinks ( [
342
+ { label : 'link3' , href : 'path-to-link3' , iconType : 'empty' , order : 3 , setAsProfile : true } ,
343
+ ] ) ;
344
+
345
+ expect ( ( ) => {
346
+ addUserMenuLinks ( [
347
+ {
348
+ label : 'link1' ,
349
+ href : 'path-to-link1' ,
350
+ iconType : 'empty' ,
351
+ order : 1 ,
352
+ setAsProfile : true ,
353
+ } ,
354
+ ] ) ;
355
+ } ) . toThrowErrorMatchingInlineSnapshot (
356
+ `"Only one custom profile link can be set. A custom profile link named link3 (path-to-link3) already exists"`
357
+ ) ;
358
+
359
+ const onUserMenuLinksHandler = jest . fn ( ) ;
360
+ userMenuLinks$ . subscribe ( onUserMenuLinksHandler ) ;
361
+
362
+ expect ( onUserMenuLinksHandler ) . toHaveBeenCalledTimes ( 1 ) ;
363
+ expect ( onUserMenuLinksHandler ) . toHaveBeenCalledWith ( [
364
+ { label : 'link3' , href : 'path-to-link3' , iconType : 'empty' , order : 3 , setAsProfile : true } ,
365
+ ] ) ;
366
+ } ) ;
308
367
} ) ;
309
368
} ) ;
0 commit comments