2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * * Modification Copyright © 2020 IBM.
9 * ===================================================================
11 * Unless otherwise specified, all software contained herein is licensed
12 * under the Apache License, Version 2.0 (the "License");
13 * you may not use this software except in compliance with the License.
14 * You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 * Unless otherwise specified, all documentation contained herein is licensed
25 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
26 * you may not use this documentation except in compliance with the License.
27 * You may obtain a copy of the License at
29 * https://creativecommons.org/licenses/by/4.0/
31 * Unless required by applicable law or agreed to in writing, documentation
32 * distributed under the License is distributed on an "AS IS" BASIS,
33 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34 * See the License for the specific language governing permissions and
35 * limitations under the License.
37 * ============LICENSE_END============================================
41 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
42 import {FormsModule} from '@angular/forms';
43 import { NewMenuComponent } from './new-menu.component';
44 import { HttpClientTestingModule } from '@angular/common/http/testing';
45 import { NgbActiveModal, NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
46 import { RouterTestingModule } from '@angular/router/testing';
47 import { CookieService } from 'ngx-cookie-service';
48 import { AdminService } from '../../admin.service';
49 import 'rxjs/add/operator/toPromise';
50 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
51 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
52 import 'rxjs/add/observable/of';
53 import { Observable } from 'rxjs/Observable';
54 import 'rxjs/add/operator/catch';
55 import 'rxjs/add/observable/throw';
56 import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
59 describe('NewMenuComponent', () => {
60 let component: NewMenuComponent;
61 let fixture: ComponentFixture<NewMenuComponent>;
62 let adminService:AdminService;
64 beforeEach(async(() => {
65 TestBed.configureTestingModule({
66 declarations: [ NewMenuComponent,ConfirmationModalComponent ],
69 HttpClientTestingModule,
72 BrowserAnimationsModule
80 TestBed.overrideModule(BrowserDynamicTestingModule,{
82 entryComponents:[ConfirmationModalComponent ]
90 fixture = TestBed.createComponent(NewMenuComponent);
91 component = fixture.componentInstance;
92 fixture.detectChanges();
93 adminService=TestBed.get(AdminService);
96 it('should create', () => {
97 expect(component).toBeTruthy();
100 it('testing ngOnInit method for if condition',()=>{
101 component.selectedMenu=1;
102 component.ngOnInit();
103 expect(component.menu).toEqual(component.selectedMenu);
106 it('testing ngOnInit method for else condition',()=>{
107 component.selectedMenu=0;
108 component.ngOnInit();
109 expect(component.menu.menuSetCode).toEqual('APP');
112 it('testing sortItems method',()=>{
114 component.sortItems(prop);
118 it('testing getParentLabel method',()=>{
119 component.getParentLabel(1,"data");
123 it('should test getParentData method1 ',()=>{
124 const children="children";
125 let spy=spyOn(adminService,'getParentData').and.returnValue(Observable.of('you object'));
126 component.getParentData();
127 expect(spy).toHaveBeenCalled();
130 it('should test getParentData method2 error part ',()=>{
131 const children="children";
132 let spy=spyOn(adminService,'getParentData').and.returnValue(Observable.throw({status:404}));
133 component.getParentData();
134 expect(spy).toHaveBeenCalled();
137 describe('should test getLeftMenuItems',()=>{
138 it('testing getLeftMenuItems',()=>{
139 component.getLeftMenuItems();
143 it('testing getFunctionCDselectData method1',()=>{
144 let spy=spyOn(adminService,'getFunctionCdList').and.returnValue(Observable.of('your object'));
145 component.getFunctionCDselectData();
146 expect(spy).toHaveBeenCalled();
147 expect(component.result).toEqual('your object');
148 expect(component.functionCDselectData).toEqual('your object');
151 describe('should test getFunctionCDselectData method2',()=>{
152 it('testing getFunctionCDselectData',()=>{
153 let spy= spyOn(adminService,'getFunctionCdList').and.returnValue(Observable.throw({status:404}))
154 component.getFunctionCDselectData();
155 expect(spy).toHaveBeenCalled();
156 expect(component.showSpinner).toEqual(false);
160 it('should test updateFnMenu method',()=>{
161 component.menu.label!=null;
162 component.updateFnMenu();