@@ -12,28 +12,101 @@ import { SectionDataService } from '@dspace/core/data/section-data.service';
1212import { createPaginatedList } from '@dspace/core/testing/utils.test' ;
1313import { createSuccessfulRemoteDataObject$ } from '@dspace/core/utilities/remote-data.utils' ;
1414
15- import { environment } from '../../../../environments/environment' ;
15+ import { MenuItemType } from '../menu-item-type.model' ;
16+ import { PartialMenuSection } from '../menu-provider.model' ;
1617import { ExploreMenuProvider } from './explore.menu' ;
1718
1819describe ( 'ExploreMenuProvider' , ( ) => {
1920
2021 let provider : ExploreMenuProvider ;
21- let sectionDataServiceStub = {
22- findVisibleSections : ( ) => createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ ] ) ) ,
23- } ;
22+ let sectionDataServiceStub : any ;
23+
24+ const mockSections = [
25+ { id : 'publications' , componentRows : [ ] , nestedSections : [ ] } ,
26+ { id : 'researchers' , componentRows : [ ] , nestedSections : [ ] } ,
27+ ] ;
28+
29+ function configureTestingModule ( enableExplorePages : boolean ) {
30+ sectionDataServiceStub = {
31+ findVisibleSections : jasmine . createSpy ( 'findVisibleSections' ) . and . returnValue (
32+ createSuccessfulRemoteDataObject$ ( createPaginatedList ( mockSections ) ) ,
33+ ) ,
34+ } ;
2435
25- beforeEach ( ( ) => {
2636 TestBed . configureTestingModule ( {
2737 providers : [
2838 ExploreMenuProvider ,
29- { provide : APP_CONFIG , useValue : environment } ,
39+ { provide : APP_CONFIG , useValue : { layout : { enableExplorePages } } } ,
3040 { provide : SectionDataService , useValue : sectionDataServiceStub } ,
3141 ] ,
3242 } ) ;
3343 provider = TestBed . inject ( ExploreMenuProvider ) ;
44+ }
45+
46+ describe ( 'when enableExplorePages is true' , ( ) => {
47+ beforeEach ( ( ) => {
48+ configureTestingModule ( true ) ;
49+ } ) ;
50+
51+ it ( 'should be created' , ( ) => {
52+ expect ( provider ) . toBeTruthy ( ) ;
53+ } ) ;
54+
55+ it ( 'should call findVisibleSections on the SectionDataService' , ( done ) => {
56+ provider . getSections ( ) . subscribe ( ( ) => {
57+ expect ( sectionDataServiceStub . findVisibleSections ) . toHaveBeenCalled ( ) ;
58+ done ( ) ;
59+ } ) ;
60+ } ) ;
61+
62+ it ( 'should return menu sections for each visible section' , ( done ) => {
63+ const expectedSections : PartialMenuSection [ ] = [
64+ {
65+ visible : true ,
66+ model : {
67+ type : MenuItemType . LINK ,
68+ text : 'menu.section.explore_publications' ,
69+ link : '/explore/publications' ,
70+ } ,
71+ } ,
72+ {
73+ visible : true ,
74+ model : {
75+ type : MenuItemType . LINK ,
76+ text : 'menu.section.explore_researchers' ,
77+ link : '/explore/researchers' ,
78+ } ,
79+ } ,
80+ ] ;
81+
82+ provider . getSections ( ) . subscribe ( ( sections ) => {
83+ expect ( sections ) . toEqual ( expectedSections ) ;
84+ done ( ) ;
85+ } ) ;
86+ } ) ;
3487 } ) ;
3588
36- it ( 'should be created' , ( ) => {
37- expect ( provider ) . toBeTruthy ( ) ;
89+ describe ( 'when enableExplorePages is false' , ( ) => {
90+ beforeEach ( ( ) => {
91+ configureTestingModule ( false ) ;
92+ } ) ;
93+
94+ it ( 'should be created' , ( ) => {
95+ expect ( provider ) . toBeTruthy ( ) ;
96+ } ) ;
97+
98+ it ( 'should return an empty array' , ( done ) => {
99+ provider . getSections ( ) . subscribe ( ( sections ) => {
100+ expect ( sections ) . toEqual ( [ ] ) ;
101+ done ( ) ;
102+ } ) ;
103+ } ) ;
104+
105+ it ( 'should not call findVisibleSections on the SectionDataService' , ( done ) => {
106+ provider . getSections ( ) . subscribe ( ( ) => {
107+ expect ( sectionDataServiceStub . findVisibleSections ) . not . toHaveBeenCalled ( ) ;
108+ done ( ) ;
109+ } ) ;
110+ } ) ;
38111 } ) ;
39112} ) ;
0 commit comments