@@ -11,6 +11,7 @@ import { TranslateModule } from '@ngx-translate/core';
1111import { of as observableOf } from 'rxjs' ;
1212
1313import { MenuService } from '../../../shared/menu/menu.service' ;
14+ import { MenuItemModels } from '../../../shared/menu/menu-section.model' ;
1415import { CSSVariableService } from '../../../shared/sass-helper/css-variable.service' ;
1516import { CSSVariableServiceStub } from '../../../shared/testing/css-variable-service.stub' ;
1617import { MenuServiceStub } from '../../../shared/testing/menu-service.stub' ;
@@ -22,47 +23,89 @@ describe('ExpandableAdminSidebarSectionComponent', () => {
2223 let fixture : ComponentFixture < ExpandableAdminSidebarSectionComponent > ;
2324 const menuService = new MenuServiceStub ( ) ;
2425 const iconString = 'test' ;
25- beforeEach ( waitForAsync ( ( ) => {
26- TestBed . configureTestingModule ( {
27- imports : [ NoopAnimationsModule , TranslateModule . forRoot ( ) , ExpandableAdminSidebarSectionComponent , TestComponent ] ,
28- providers : [
29- { provide : 'sectionDataProvider' , useValue : { icon : iconString , model : { } } } ,
30- { provide : MenuService , useValue : menuService } ,
31- { provide : CSSVariableService , useClass : CSSVariableServiceStub } ,
32- { provide : Router , useValue : new RouterStub ( ) } ,
33- ] ,
34- } ) . compileComponents ( ) ;
35- } ) ) ;
3626
37- beforeEach ( ( ) => {
38- spyOn ( menuService , 'getSubSectionsByParentID' ) . and . returnValue ( observableOf ( [ ] ) ) ;
39- fixture = TestBed . createComponent ( ExpandableAdminSidebarSectionComponent ) ;
40- component = fixture . componentInstance ;
41- spyOn ( component as any , 'getMenuItemComponent' ) . and . returnValue ( TestComponent ) ;
42- fixture . detectChanges ( ) ;
43- } ) ;
4427
45- it ( 'should create' , ( ) => {
46- expect ( component ) . toBeTruthy ( ) ;
47- } ) ;
28+ describe ( 'when there are subsections' , ( ) => {
29+ beforeEach ( waitForAsync ( ( ) => {
30+ TestBed . configureTestingModule ( {
31+ imports : [ NoopAnimationsModule , TranslateModule . forRoot ( ) , ExpandableAdminSidebarSectionComponent , TestComponent ] ,
32+ providers : [
33+ { provide : 'sectionDataProvider' , useValue : { icon : iconString , model : { } } } ,
34+ { provide : MenuService , useValue : menuService } ,
35+ { provide : CSSVariableService , useClass : CSSVariableServiceStub } ,
36+ { provide : Router , useValue : new RouterStub ( ) } ,
37+ ] ,
38+ } ) . compileComponents ( ) ;
39+ } ) ) ;
40+
41+ beforeEach ( ( ) => {
42+ spyOn ( menuService , 'getSubSectionsByParentID' ) . and . returnValue ( observableOf ( [ {
43+ id : 'test' ,
44+ visible : true ,
45+ model : { } as MenuItemModels ,
46+ } ] ) ) ;
47+ fixture = TestBed . createComponent ( ExpandableAdminSidebarSectionComponent ) ;
48+ component = fixture . componentInstance ;
49+ spyOn ( component as any , 'getMenuItemComponent' ) . and . returnValue ( TestComponent ) ;
50+ fixture . detectChanges ( ) ;
51+ } ) ;
52+
53+ it ( 'should create' , ( ) => {
54+ expect ( component ) . toBeTruthy ( ) ;
55+ } ) ;
56+
57+ it ( 'should set the right icon' , ( ) => {
58+ const icon = fixture . debugElement . query ( By . css ( '[data-test="sidebar-section-icon"] > i.fas' ) ) ;
59+ expect ( icon . nativeElement . getAttribute ( 'class' ) ) . toContain ( 'fa-' + iconString ) ;
60+ } ) ;
4861
49- it ( 'should set the right icon' , ( ) => {
50- const icon = fixture . debugElement . query ( By . css ( '[data-test="sidebar-section-icon"] > i.fas' ) ) ;
51- expect ( icon . nativeElement . getAttribute ( 'class' ) ) . toContain ( 'fa-' + iconString ) ;
62+ describe ( 'when the header text is clicked' , ( ) => {
63+ beforeEach ( ( ) => {
64+ spyOn ( menuService , 'toggleActiveSection' ) ;
65+ const sidebarToggler = fixture . debugElement . query ( By . css ( 'a.sidebar-section-wrapper' ) ) ;
66+ sidebarToggler . triggerEventHandler ( 'click' , {
67+ preventDefault : ( ) => { /**/
68+ } ,
69+ } ) ;
70+ } ) ;
71+
72+ it ( 'should call toggleActiveSection on the menuService' , ( ) => {
73+ expect ( menuService . toggleActiveSection ) . toHaveBeenCalled ( ) ;
74+ } ) ;
75+ } ) ;
5276 } ) ;
5377
54- describe ( 'when the header text is clicked' , ( ) => {
78+
79+ describe ( 'when there are no subsections' , ( ) => {
80+ beforeEach ( waitForAsync ( ( ) => {
81+ TestBed . configureTestingModule ( {
82+ imports : [ NoopAnimationsModule , TranslateModule . forRoot ( ) , ExpandableAdminSidebarSectionComponent , TestComponent ] ,
83+ providers : [
84+ { provide : 'sectionDataProvider' , useValue : { icon : iconString , model : { } } } ,
85+ { provide : MenuService , useValue : menuService } ,
86+ { provide : CSSVariableService , useClass : CSSVariableServiceStub } ,
87+ { provide : Router , useValue : new RouterStub ( ) } ,
88+ ] ,
89+ } ) . compileComponents ( ) ;
90+ } ) ) ;
91+
5592 beforeEach ( ( ) => {
56- spyOn ( menuService , 'toggleActiveSection' ) ;
57- const sidebarToggler = fixture . debugElement . query ( By . css ( 'a.sidebar-section-wrapper' ) ) ;
58- sidebarToggler . triggerEventHandler ( 'click' , {
59- preventDefault : ( ) => { /**/
60- } ,
61- } ) ;
93+ spyOn ( menuService , 'getSubSectionsByParentID' ) . and . returnValue ( observableOf ( [ ] ) ) ;
94+ fixture = TestBed . createComponent ( ExpandableAdminSidebarSectionComponent ) ;
95+ component = fixture . componentInstance ;
96+ spyOn ( component as any , 'getMenuItemComponent' ) . and . returnValue ( TestComponent ) ;
97+ fixture . detectChanges ( ) ;
98+ } ) ;
99+
100+ it ( 'should create' , ( ) => {
101+ expect ( component ) . toBeTruthy ( ) ;
62102 } ) ;
63103
64- it ( 'should call toggleActiveSection on the menuService' , ( ) => {
65- expect ( menuService . toggleActiveSection ) . toHaveBeenCalled ( ) ;
104+ it ( 'should not contain a section' , ( ) => {
105+ const icon = fixture . debugElement . query ( By . css ( '.shortcut-icon' ) ) ;
106+ expect ( icon ) . toBeNull ( ) ;
107+ const sidebarToggler = fixture . debugElement . query ( By . css ( '.sidebar-section' ) ) ;
108+ expect ( sidebarToggler ) . toBeNull ( ) ;
66109 } ) ;
67110 } ) ;
68111} ) ;
0 commit comments