11import { TestBed , waitForAsync } from '@angular/core/testing' ;
22import { MenuServiceStub } from '../testing/menu-service.stub' ;
3- import { of as observableOf } from 'rxjs' ;
3+ import { combineLatest , map , of as observableOf } from 'rxjs' ;
44import { TranslateModule , TranslateService } from '@ngx-translate/core' ;
55import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
66import { RouterTestingModule } from '@angular/router/testing' ;
@@ -16,10 +16,13 @@ import { Item } from '../../core/shared/item.model';
1616import { createFailedRemoteDataObject$ , createSuccessfulRemoteDataObject$ } from '../remote-data.utils' ;
1717import { MenuID } from '../menu/menu-id.model' ;
1818import { MenuItemType } from '../menu/menu-item-type.model' ;
19- import { TextMenuItemModel } from '../menu/menu-item/models/text.model' ;
2019import { LinkMenuItemModel } from '../menu/menu-item/models/link.model' ;
2120import { ResearcherProfileDataService } from '../../core/profile/researcher-profile-data.service' ;
2221import { NotificationsService } from '../notifications/notifications.service' ;
22+ import { DSpaceObject } from '../../core/shared/dspace-object.model' ;
23+ import { Community } from '../../core/shared/community.model' ;
24+ import { Collection } from '../../core/shared/collection.model' ;
25+ import flatten from 'lodash/flatten' ;
2326
2427describe ( 'DSOEditMenuResolver' , ( ) => {
2528
@@ -37,25 +40,44 @@ describe('DSOEditMenuResolver', () => {
3740 let notificationsService ;
3841 let translate ;
3942
40- const route = {
41- data : {
42- menu : {
43- 'statistics' : [ {
44- id : 'statistics-dummy-1' ,
45- active : false ,
46- visible : true ,
47- model : null
48- } ]
49- }
50- } ,
51- params : { id : 'test-uuid' } ,
43+ const dsoRoute = ( dso : DSpaceObject ) => {
44+ return {
45+ data : {
46+ menu : {
47+ 'statistics' : [ {
48+ id : 'statistics-dummy-1' ,
49+ active : false ,
50+ visible : true ,
51+ model : null
52+ } ]
53+ }
54+ } ,
55+ params : { id : dso . uuid } ,
56+ } ;
5257 } ;
5358
5459 const state = {
5560 url : 'test-url'
5661 } ;
5762
58- const testObject = Object . assign ( new Item ( ) , { uuid : 'test-uuid' , type : 'item' , _links : { self : { href : 'self-link' } } } ) ;
63+ const testCommunity : Community = Object . assign ( new Community ( ) , {
64+ uuid : 'test-community-uuid' ,
65+ type : 'community' ,
66+ _links : { self : { href : 'self-link' } } ,
67+ } ) ;
68+ const testCollection : Collection = Object . assign ( new Collection ( ) , {
69+ uuid : 'test-collection-uuid' ,
70+ type : 'collection' ,
71+ _links : { self : { href : 'self-link' } } ,
72+ } ) ;
73+ const testItem : Item = Object . assign ( new Item ( ) , {
74+ uuid : 'test-item-uuid' ,
75+ type : 'item' ,
76+ _links : { self : { href : 'self-link' } } ,
77+ } ) ;
78+
79+ let testObject : DSpaceObject ;
80+ let route ;
5981
6082 const dummySections1 = [ {
6183 id : 'dummy-1' ,
@@ -90,6 +112,10 @@ describe('DSOEditMenuResolver', () => {
90112 } ] ;
91113
92114 beforeEach ( waitForAsync ( ( ) => {
115+ // test with Items unless specified otherwise
116+ testObject = testItem ;
117+ route = dsoRoute ( testItem ) ;
118+
93119 menuService = new MenuServiceStub ( ) ;
94120 spyOn ( menuService , 'getMenu' ) . and . returnValue ( observableOf ( MENU_STATE ) ) ;
95121
@@ -154,16 +180,17 @@ describe('DSOEditMenuResolver', () => {
154180 {
155181 ...route . data . menu ,
156182 [ MenuID . DSO_EDIT ] : [
157- ...dummySections1 . map ( ( menu ) => Object . assign ( menu , { id : menu . id + '-test-uuid' } ) ) ,
158- ...dummySections2 . map ( ( menu ) => Object . assign ( menu , { id : menu . id + '-test-uuid' } ) )
183+ ...dummySections1 . map ( ( menu ) => Object . assign ( menu , { id : menu . id + '-test-item- uuid' } ) ) ,
184+ ...dummySections2 . map ( ( menu ) => Object . assign ( menu , { id : menu . id + '-test-item- uuid' } ) )
159185 ]
160186 }
161187 ) ;
162- expect ( dSpaceObjectDataService . findById ) . toHaveBeenCalledWith ( 'test-uuid' , true , false ) ;
188+ expect ( dSpaceObjectDataService . findById ) . toHaveBeenCalledWith ( 'test-item- uuid' , true , false ) ;
163189 expect ( resolver . getDsoMenus ) . toHaveBeenCalled ( ) ;
164190 done ( ) ;
165191 } ) ;
166192 } ) ;
193+
167194 it ( 'should create all menus when a dso is found based on the route scope query param when no id param is present' , ( done ) => {
168195 spyOn ( resolver , 'getDsoMenus' ) . and . returnValue (
169196 [ observableOf ( dummySections1 ) , observableOf ( dummySections2 ) ]
@@ -198,6 +225,7 @@ describe('DSOEditMenuResolver', () => {
198225 done ( ) ;
199226 } ) ;
200227 } ) ;
228+
201229 it ( 'should return the statistics menu when no dso is found' , ( done ) => {
202230 ( dSpaceObjectDataService . findById as jasmine . Spy ) . and . returnValue ( createFailedRemoteDataObject$ ( ) ) ;
203231
@@ -211,49 +239,165 @@ describe('DSOEditMenuResolver', () => {
211239 } ) ;
212240 } ) ;
213241 } ) ;
242+
214243 describe ( 'getDsoMenus' , ( ) => {
215- it ( 'should return as first part the item version, orcid and claim list ' , ( done ) => {
216- const result = resolver . getDsoMenus ( testObject , route , state ) ;
217- result [ 0 ] . subscribe ( ( menuList ) => {
218- expect ( menuList . length ) . toEqual ( 3 ) ;
219- expect ( menuList [ 0 ] . id ) . toEqual ( 'orcid-dso' ) ;
220- expect ( menuList [ 0 ] . active ) . toEqual ( false ) ;
221- // Visible should be false due to the item not being of type person
222- expect ( menuList [ 0 ] . visible ) . toEqual ( false ) ;
223- expect ( menuList [ 0 ] . model . type ) . toEqual ( MenuItemType . LINK ) ;
224-
225- expect ( menuList [ 1 ] . id ) . toEqual ( 'version-dso' ) ;
226- expect ( menuList [ 1 ] . active ) . toEqual ( false ) ;
227- expect ( menuList [ 1 ] . visible ) . toEqual ( true ) ;
228- expect ( menuList [ 1 ] . model . type ) . toEqual ( MenuItemType . ONCLICK ) ;
229- expect ( ( menuList [ 1 ] . model as TextMenuItemModel ) . text ) . toEqual ( 'message' ) ;
230- expect ( menuList [ 1 ] . model . disabled ) . toEqual ( false ) ;
231- expect ( menuList [ 1 ] . icon ) . toEqual ( 'code-branch' ) ;
232-
233- expect ( menuList [ 2 ] . id ) . toEqual ( 'claim-dso' ) ;
234- expect ( menuList [ 2 ] . active ) . toEqual ( false ) ;
235- // Visible should be false due to the item not being of type person
236- expect ( menuList [ 2 ] . visible ) . toEqual ( false ) ;
237- expect ( menuList [ 2 ] . model . type ) . toEqual ( MenuItemType . ONCLICK ) ;
238- expect ( ( menuList [ 2 ] . model as TextMenuItemModel ) . text ) . toEqual ( 'item.page.claim.button' ) ;
239- done ( ) ;
244+ describe ( 'for Communities' , ( ) => {
245+ beforeEach ( ( ) => {
246+ testObject = testCommunity ;
247+ dSpaceObjectDataService . findById . and . returnValue ( createSuccessfulRemoteDataObject$ ( testCommunity ) ) ;
248+ route = dsoRoute ( testCommunity ) ;
249+ } ) ;
250+
251+ it ( 'should not return Item-specific entries' , ( done ) => {
252+ const result = resolver . getDsoMenus ( testObject , route , state ) ;
253+ combineLatest ( result ) . pipe ( map ( flatten ) ) . subscribe ( ( menu ) => {
254+ const orcidEntry = menu . find ( entry => entry . id === 'orcid-dso' ) ;
255+ expect ( orcidEntry ) . toBeFalsy ( ) ;
256+
257+ const versionEntry = menu . find ( entry => entry . id === 'version-dso' ) ;
258+ expect ( versionEntry ) . toBeFalsy ( ) ;
259+
260+ const claimEntry = menu . find ( entry => entry . id === 'claim-dso' ) ;
261+ expect ( claimEntry ) . toBeFalsy ( ) ;
262+
263+ done ( ) ;
264+ } ) ;
265+ } ) ;
266+
267+ it ( 'should return Community/Collection-specific entries' , ( done ) => {
268+ const result = resolver . getDsoMenus ( testObject , route , state ) ;
269+ combineLatest ( result ) . pipe ( map ( flatten ) ) . subscribe ( ( menu ) => {
270+ const subscribeEntry = menu . find ( entry => entry . id === 'subscribe' ) ;
271+ expect ( subscribeEntry ) . toBeTruthy ( ) ;
272+ expect ( subscribeEntry . active ) . toBeFalse ( ) ;
273+ expect ( subscribeEntry . visible ) . toBeTrue ( ) ;
274+ expect ( subscribeEntry . model . type ) . toEqual ( MenuItemType . ONCLICK ) ;
275+ done ( ) ;
276+ } ) ;
240277 } ) ;
241278
279+ it ( 'should return as third part the common list ' , ( done ) => {
280+ const result = resolver . getDsoMenus ( testObject , route , state ) ;
281+ combineLatest ( result ) . pipe ( map ( flatten ) ) . subscribe ( ( menu ) => {
282+ const editEntry = menu . find ( entry => entry . id === 'edit-dso' ) ;
283+ expect ( editEntry ) . toBeTruthy ( ) ;
284+ expect ( editEntry . active ) . toBeFalse ( ) ;
285+ expect ( editEntry . visible ) . toBeTrue ( ) ;
286+ expect ( editEntry . model . type ) . toEqual ( MenuItemType . LINK ) ;
287+ expect ( ( editEntry . model as LinkMenuItemModel ) . link ) . toEqual (
288+ '/communities/test-community-uuid/edit/metadata'
289+ ) ;
290+ done ( ) ;
291+ } ) ;
292+ } ) ;
242293 } ) ;
243- it ( 'should return as second part the common list ' , ( done ) => {
244- const result = resolver . getDsoMenus ( testObject , route , state ) ;
245- result [ 1 ] . subscribe ( ( menuList ) => {
246- expect ( menuList . length ) . toEqual ( 1 ) ;
247- expect ( menuList [ 0 ] . id ) . toEqual ( 'edit-dso' ) ;
248- expect ( menuList [ 0 ] . active ) . toEqual ( false ) ;
249- expect ( menuList [ 0 ] . visible ) . toEqual ( true ) ;
250- expect ( menuList [ 0 ] . model . type ) . toEqual ( MenuItemType . LINK ) ;
251- expect ( ( menuList [ 0 ] . model as LinkMenuItemModel ) . text ) . toEqual ( 'item.page.edit' ) ;
252- expect ( ( menuList [ 0 ] . model as LinkMenuItemModel ) . link ) . toEqual ( '/items/test-uuid/edit/metadata' ) ;
253- expect ( menuList [ 0 ] . icon ) . toEqual ( 'pencil-alt' ) ;
254- done ( ) ;
294+
295+ describe ( 'for Collections' , ( ) => {
296+ beforeEach ( ( ) => {
297+ testObject = testCollection ;
298+ dSpaceObjectDataService . findById . and . returnValue ( createSuccessfulRemoteDataObject$ ( testCollection ) ) ;
299+ route = dsoRoute ( testCollection ) ;
300+ } ) ;
301+
302+ it ( 'should not return Item-specific entries' , ( done ) => {
303+ const result = resolver . getDsoMenus ( testObject , route , state ) ;
304+ combineLatest ( result ) . pipe ( map ( flatten ) ) . subscribe ( ( menu ) => {
305+ const orcidEntry = menu . find ( entry => entry . id === 'orcid-dso' ) ;
306+ expect ( orcidEntry ) . toBeFalsy ( ) ;
307+
308+ const versionEntry = menu . find ( entry => entry . id === 'version-dso' ) ;
309+ expect ( versionEntry ) . toBeFalsy ( ) ;
310+
311+ const claimEntry = menu . find ( entry => entry . id === 'claim-dso' ) ;
312+ expect ( claimEntry ) . toBeFalsy ( ) ;
313+
314+ done ( ) ;
315+ } ) ;
316+ } ) ;
317+
318+ it ( 'should return Community/Collection-specific entries' , ( done ) => {
319+ const result = resolver . getDsoMenus ( testObject , route , state ) ;
320+ combineLatest ( result ) . pipe ( map ( flatten ) ) . subscribe ( ( menu ) => {
321+ const subscribeEntry = menu . find ( entry => entry . id === 'subscribe' ) ;
322+ expect ( subscribeEntry ) . toBeTruthy ( ) ;
323+ expect ( subscribeEntry . active ) . toBeFalse ( ) ;
324+ expect ( subscribeEntry . visible ) . toBeTrue ( ) ;
325+ expect ( subscribeEntry . model . type ) . toEqual ( MenuItemType . ONCLICK ) ;
326+ done ( ) ;
327+ } ) ;
328+ } ) ;
329+
330+ it ( 'should return as third part the common list ' , ( done ) => {
331+ const result = resolver . getDsoMenus ( testObject , route , state ) ;
332+ combineLatest ( result ) . pipe ( map ( flatten ) ) . subscribe ( ( menu ) => {
333+ const editEntry = menu . find ( entry => entry . id === 'edit-dso' ) ;
334+ expect ( editEntry ) . toBeTruthy ( ) ;
335+ expect ( editEntry . active ) . toBeFalse ( ) ;
336+ expect ( editEntry . visible ) . toBeTrue ( ) ;
337+ expect ( editEntry . model . type ) . toEqual ( MenuItemType . LINK ) ;
338+ expect ( ( editEntry . model as LinkMenuItemModel ) . link ) . toEqual (
339+ '/collections/test-collection-uuid/edit/metadata'
340+ ) ;
341+ done ( ) ;
342+ } ) ;
255343 } ) ;
344+ } ) ;
345+
346+ describe ( 'for Items' , ( ) => {
347+ beforeEach ( ( ) => {
348+ testObject = testItem ;
349+ dSpaceObjectDataService . findById . and . returnValue ( createSuccessfulRemoteDataObject$ ( testItem ) ) ;
350+ route = dsoRoute ( testItem ) ;
351+ } ) ;
352+
353+ it ( 'should return Item-specific entries' , ( done ) => {
354+ const result = resolver . getDsoMenus ( testObject , route , state ) ;
355+ combineLatest ( result ) . pipe ( map ( flatten ) ) . subscribe ( ( menu ) => {
356+ const orcidEntry = menu . find ( entry => entry . id === 'orcid-dso' ) ;
357+ expect ( orcidEntry ) . toBeTruthy ( ) ;
358+ expect ( orcidEntry . active ) . toBeFalse ( ) ;
359+ expect ( orcidEntry . visible ) . toBeFalse ( ) ;
360+ expect ( orcidEntry . model . type ) . toEqual ( MenuItemType . LINK ) ;
361+
362+ const versionEntry = menu . find ( entry => entry . id === 'version-dso' ) ;
363+ expect ( versionEntry ) . toBeTruthy ( ) ;
364+ expect ( versionEntry . active ) . toBeFalse ( ) ;
365+ expect ( versionEntry . visible ) . toBeTrue ( ) ;
366+ expect ( versionEntry . model . type ) . toEqual ( MenuItemType . ONCLICK ) ;
367+ expect ( versionEntry . model . disabled ) . toBeFalse ( ) ;
256368
369+ const claimEntry = menu . find ( entry => entry . id === 'claim-dso' ) ;
370+ expect ( claimEntry ) . toBeTruthy ( ) ;
371+ expect ( claimEntry . active ) . toBeFalse ( ) ;
372+ expect ( claimEntry . visible ) . toBeFalse ( ) ;
373+ expect ( claimEntry . model . type ) . toEqual ( MenuItemType . ONCLICK ) ;
374+ done ( ) ;
375+ } ) ;
376+ } ) ;
377+
378+ it ( 'should not return Community/Collection-specific entries' , ( done ) => {
379+ const result = resolver . getDsoMenus ( testObject , route , state ) ;
380+ combineLatest ( result ) . pipe ( map ( flatten ) ) . subscribe ( ( menu ) => {
381+ const subscribeEntry = menu . find ( entry => entry . id === 'subscribe' ) ;
382+ expect ( subscribeEntry ) . toBeFalsy ( ) ;
383+ done ( ) ;
384+ } ) ;
385+ } ) ;
386+
387+ it ( 'should return as third part the common list ' , ( done ) => {
388+ const result = resolver . getDsoMenus ( testObject , route , state ) ;
389+ combineLatest ( result ) . pipe ( map ( flatten ) ) . subscribe ( ( menu ) => {
390+ const editEntry = menu . find ( entry => entry . id === 'edit-dso' ) ;
391+ expect ( editEntry ) . toBeTruthy ( ) ;
392+ expect ( editEntry . active ) . toBeFalse ( ) ;
393+ expect ( editEntry . visible ) . toBeTrue ( ) ;
394+ expect ( editEntry . model . type ) . toEqual ( MenuItemType . LINK ) ;
395+ expect ( ( editEntry . model as LinkMenuItemModel ) . link ) . toEqual (
396+ '/items/test-item-uuid/edit/metadata'
397+ ) ;
398+ done ( ) ;
399+ } ) ;
400+ } ) ;
257401 } ) ;
258402 } ) ;
259403} ) ;
0 commit comments