test cases written for new-menu component 54/103154/1
authorIndrijeet kumar <indriku1@in.ibm.com>
Thu, 5 Mar 2020 16:39:10 +0000 (22:09 +0530)
committerIndrijeet kumar <indriku1@in.ibm.com>
Thu, 5 Mar 2020 16:39:18 +0000 (22:09 +0530)
test cases written for new-menu component

Issue-ID: PORTAL-813
Change-Id: I94f38de37e3011ff6d93e3b47b8085e6adf93925
Signed-off-by: Indrijeet Kumar <indriku1@in.ibm.com>
ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/admin/menus/new-menu/new-menu.component.spec.ts

index 97ddeaa..dc0301a 100644 (file)
@@ -4,7 +4,10 @@
  * ===================================================================
  * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
  * ===================================================================
- *
+ * 
+ *  * Modification Copyright © 2020 IBM.
+ * ===================================================================
+
  * Unless otherwise specified, all software contained herein is licensed
  * under the Apache License, Version 2.0 (the "License");
  * you may not use this software except in compliance with the License.
@@ -40,33 +43,101 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
 import {FormsModule} from '@angular/forms';
 import { NewMenuComponent } from './new-menu.component';
 import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
-import { RouterModule } from '@angular/router';
+import { NgbActiveModal, NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
 import { RouterTestingModule } from '@angular/router/testing';
 import { CookieService } from 'ngx-cookie-service';
-
+import { MockBackend } from '@angular/http/testing';
+import { BaseRequestOptions, Http } from '@angular/http';
+import { AdminService } from '../../admin.service';
+import 'rxjs/add/operator/toPromise';
+import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { MaterialModule } from 'portalsdk-tag-lib/material-module';
+import 'rxjs/add/observable/of';
+import { Observable } from 'rxjs/Observable';
 
 
 describe('NewMenuComponent', () => {
   let component: NewMenuComponent;
   let fixture: ComponentFixture<NewMenuComponent>;
+  let adminService:AdminService;
+ // let entryComponents:any;
 
   beforeEach(async(() => {
     TestBed.configureTestingModule({
       declarations: [ NewMenuComponent ],
-      imports:[FormsModule, HttpClientTestingModule,RouterTestingModule],
-      providers:[NgbActiveModal,CookieService]
+      imports:[FormsModule, HttpClientTestingModule,RouterTestingModule,NgbModalModule,BrowserAnimationsModule],
+      providers:[AdminService,NgbActiveModal,CookieService,MockBackend,BaseRequestOptions,{
+        provide:Http,
+        useFactory:(backend:MockBackend,defaultOptions:BaseRequestOptions)=>{
+          return new Http(backend,defaultOptions);
+        },
+        deps:[MockBackend,BaseRequestOptions],
+        entryComponents:[ConfirmationModalComponent]
+      }],   
     })
     .compileComponents();
+    
   }));
 
   beforeEach(() => {
     fixture = TestBed.createComponent(NewMenuComponent);
     component = fixture.componentInstance;
     fixture.detectChanges();
+    adminService=TestBed.get(AdminService);
   });
 
   it('should create', () => {
     expect(component).toBeTruthy();
   });
+
+  it('testing ngOnInit method for if condition',()=>{
+    component.selectedMenu=1;
+    component.ngOnInit();
+    expect(component.menu).toEqual(component.selectedMenu);
+  })
+
+  it('testing ngOnInit method for else condition',()=>{
+    component.selectedMenu=0;
+    component.ngOnInit();
+    expect(component.menu.menuSetCode).toEqual('APP');
+  })
+
+  it('testing sortItems method',()=>{
+    let prop: any;
+      component.sortItems(prop);
+
+  })
+
+  it('testing getParentLabel method',()=>{
+    component.getParentLabel(1,"data");
+  })
+
+  describe('should test getParentData',()=>{
+  it('testing getParentData',()=>{
+    let spy=spyOn(adminService,'getParentData').and.returnValue(Observable.of('you object'));
+    component.getParentData();
+    expect(spy).toHaveBeenCalled();
+
+  })
+  })
+
+  describe('should test getLeftMenuItems',()=>{
+  it('testing getLeftMenuItems',()=>{
+    component.getLeftMenuItems();
+  })
+  })
+
+  describe('should test getFunctionCDselectData',()=>{
+    it('testing getFunctionCDselectData',()=>{
+      let spy=spyOn(adminService,'getFunctionCdList').and.returnValue(Observable.of(1,1));
+      component.getFunctionCDselectData();
+      expect(spy).toHaveBeenCalled();
+    })
+  })
+
+  it('should test updateFnMenu method',()=>{
+    //component.updateFnMenu();
+  })
+
 });