From d27fdfac6cc8cc14a7723e2c2e479ed39e8a71b3 Mon Sep 17 00:00:00 2001 From: Sufiyan Shaikh Date: Tue, 8 Mar 2022 19:37:49 +0530 Subject: [PATCH] [DSC-472] Automated Test cases --- .../context-menu.component.spec.ts | 36 +++++++++++++++++++ .../context-menu/context-menu.component.ts | 14 ++++---- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/app/shared/context-menu/context-menu.component.spec.ts b/src/app/shared/context-menu/context-menu.component.spec.ts index 1257c870d1c..4a6679ba35f 100644 --- a/src/app/shared/context-menu/context-menu.component.spec.ts +++ b/src/app/shared/context-menu/context-menu.component.spec.ts @@ -146,6 +146,18 @@ describe('ContextMenuComponent', () => { done(); }); + it('should display d-none', (done) => { + const menu = fixture.debugElement.query(By.css('div.d-none')); + expect(menu).not.toBeNull(); + done(); + }); + + it('should not display d-inline-block', (done) => { + const menu = fixture.debugElement.query(By.css('div.d-inline-block')); + expect(menu).toBeNull(); + done(); + }); + it('should display stand alone buttons', (done) => { const menu = fixture.debugElement.query(By.css('button.btn-primary')); expect(menu).not.toBeNull(); @@ -203,6 +215,18 @@ describe('ContextMenuComponent', () => { done(); }); + it('should display d-none', (done) => { + const menu = fixture.debugElement.query(By.css('div.d-none')); + expect(menu).not.toBeNull(); + done(); + }); + + it('should not display d-inline-block', (done) => { + const menu = fixture.debugElement.query(By.css('div.d-inline-block')); + expect(menu).toBeNull(); + done(); + }); + it('should not display stand alone buttons', (done) => { const menu = fixture.debugElement.query(By.css('button.btn-primary')); expect(menu).not.toBeNull(); @@ -232,6 +256,18 @@ describe('ContextMenuComponent', () => { done(); }); + it('should display d-inline-block', (done) => { + const menu = fixture.debugElement.query(By.css('div.d-inline-block')); + expect(menu).toBeNull(); + done(); + }); + + it('should not display d-none', (done) => { + const menu = fixture.debugElement.query(By.css('div.d-none')); + expect(menu).toBeNull(); + done(); + }); + it('should check the authorization of the current user', (done) => { expect(component.isAuthenticated).toBeObservable(cold('a', { a: false })); done(); diff --git a/src/app/shared/context-menu/context-menu.component.ts b/src/app/shared/context-menu/context-menu.component.ts index 0de17f9d00b..3403d7363cc 100644 --- a/src/app/shared/context-menu/context-menu.component.ts +++ b/src/app/shared/context-menu/context-menu.component.ts @@ -133,12 +133,14 @@ export class ContextMenuComponent implements OnInit { ngAfterViewChecked() { // To check that Context-menu contains options or not - const el = Array.from(document.getElementById('itemOptionsDropdownMenu')?.getElementsByClassName('ng-star-inserted')); - this.optionCount = 0; - if (el) { - el.forEach(element => { - this.optionCount += element.childElementCount; - }); + if (document.getElementById('itemOptionsDropdownMenu')) { + const el = Array.from(document.getElementById('itemOptionsDropdownMenu')?.getElementsByClassName('ng-star-inserted')); + this.optionCount = 0; + if (el) { + el.forEach(element => { + this.optionCount += element.childElementCount; + }); + } } } }