@@ -45,12 +45,25 @@ describe('DsoEditMenuComponent', () => {
4545 index : 1 ,
4646 } ;
4747
48+ const subSection = {
49+ id : 'edit-dso-sub' ,
50+ active : false ,
51+ visible : true ,
52+ model : {
53+ text : 'sub-section-text' ,
54+ type : null ,
55+ disabled : false ,
56+ } as TextMenuItemModel ,
57+ icon : 'pencil' ,
58+ index : 0 ,
59+ } ;
4860
4961 beforeEach ( waitForAsync ( ( ) => {
5062 authorizationService = jasmine . createSpyObj ( 'authorizationService' , {
5163 isAuthorized : of ( true ) ,
5264 } ) ;
5365 spyOn ( menuService , 'getMenuTopSections' ) . and . returnValue ( of ( [ section ] ) ) ;
66+ spyOn ( menuService , 'getSubSectionsByParentID' ) . and . returnValue ( of ( [ subSection ] ) ) ;
5467 TestBed . configureTestingModule ( {
5568 imports : [ TranslateModule . forRoot ( ) , RouterTestingModule , DsoEditMenuComponent ] ,
5669 providers : [
@@ -65,17 +78,42 @@ describe('DsoEditMenuComponent', () => {
6578 } ) . compileComponents ( ) ;
6679 } ) ) ;
6780
68- beforeEach ( ( ) => {
69- fixture = TestBed . createComponent ( DsoEditMenuComponent ) ;
70- comp = fixture . componentInstance ;
71- comp . sections = of ( [ ] ) ;
72- fixture . detectChanges ( ) ;
73- } ) ;
74-
7581 describe ( 'onInit' , ( ) => {
7682 it ( 'should create' , ( ) => {
83+ fixture = TestBed . createComponent ( DsoEditMenuComponent ) ;
84+ comp = fixture . componentInstance ;
85+ fixture . detectChanges ( ) ;
7786 expect ( comp ) . toBeTruthy ( ) ;
7887 } ) ;
88+
89+ it ( 'should have role menubar when subsections exist' , ( ) => {
90+ ( menuService . getSubSectionsByParentID as jasmine . Spy ) . and . returnValue ( of ( [ subSection ] ) ) ;
91+ fixture = TestBed . createComponent ( DsoEditMenuComponent ) ;
92+ comp = fixture . componentInstance ;
93+ fixture . detectChanges ( ) ;
94+
95+ const menu = fixture . nativeElement . querySelector ( '.dso-edit-menu' ) ;
96+ expect ( menu . getAttribute ( 'role' ) ) . toBe ( 'menubar' ) ;
97+ } ) ;
98+
99+ it ( 'should NOT have role menubar when no subsections exist' , ( ) => {
100+ ( menuService . getSubSectionsByParentID as jasmine . Spy ) . and . returnValue ( of ( [ ] ) ) ;
101+ fixture = TestBed . createComponent ( DsoEditMenuComponent ) ;
102+ comp = fixture . componentInstance ;
103+ fixture . detectChanges ( ) ;
104+
105+ const menu = fixture . nativeElement . querySelector ( '.dso-edit-menu' ) ;
106+ expect ( menu . getAttribute ( 'role' ) ) . toBeNull ( ) ;
107+ } ) ;
108+
109+ it ( 'should have aria-hidden when no subsections exist' , ( ) => {
110+ ( menuService . getSubSectionsByParentID as jasmine . Spy ) . and . returnValue ( of ( [ ] ) ) ;
111+ fixture = TestBed . createComponent ( DsoEditMenuComponent ) ;
112+ comp = fixture . componentInstance ;
113+ fixture . detectChanges ( ) ;
114+
115+ const menu = fixture . nativeElement . querySelector ( '.dso-edit-menu' ) ;
116+ expect ( menu . getAttribute ( 'aria-hidden' ) ) . toBe ( 'true' ) ;
117+ } ) ;
79118 } ) ;
80119} ) ;
81-
0 commit comments