/* * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== * 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. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Unless otherwise specified, all documentation contained herein is licensed * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at * * https://creativecommons.org/licenses/by/4.0/ * * Unless required by applicable law or agreed to in writing, documentation * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ============LICENSE_END============================================ * * */ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { TranslateModule } from '@ngx-translate/core'; import { HttpClientModule } from '@angular/common/http'; import { SidebarComponent } from './sidebar.component'; import { LayoutModule } from '../../layout.module'; import { CookieService } from 'ngx-cookie-service'; import { SidebarService } from 'src/app/shared/services'; import 'rxjs/add/observable/of'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { Observable } from 'rxjs'; describe('SidebarComponent', () => { let component: SidebarComponent; let fixture: ComponentFixture; let sidebarService: SidebarService; var stubData1={ "data":'"d"', "data2":'"data2"' }; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ LayoutModule, RouterTestingModule, TranslateModule.forRoot(), HttpClientModule, HttpClientTestingModule ], providers:[CookieService, SidebarService], }) .compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(SidebarComponent); component = fixture.componentInstance; fixture.detectChanges(); sidebarService = TestBed.get(SidebarService); }); it('should create', () => { expect(component).toBeTruthy(); }); describe('should test ngOnInit',()=>{ it('should validate on ngOnInit',()=>{ let spy=spyOn(sidebarService,'getLeftMenu').and.returnValue(Observable.of(stubData1)); component.ngOnInit(); expect(component.isActive).toEqual(false); expect(component.collapsed).toEqual(false); expect(component.showMenu).toEqual(''); expect(component.pushRightClass).toEqual('push-right'); expect(component.leftParentData).toEqual(JSON.parse(component.result.data)); expect(component.leftChildData).toEqual(JSON.parse(component.result.data2)); expect(spy).toHaveBeenCalled(); }) }); it('should test addExpandClass if element and showMenu variable value are same', () => { component.showMenu= '1'; component.addExpandClass('1'); expect(component.showMenu).toBe('0'); }); it('should test addExpandClass if element and showMenu variable value are not same', () => { component.showMenu= '0'; component.addExpandClass('1'); expect(component.showMenu).toBe('1'); }); it('should test toggleCollapsed function', () => { component.collapsed= true; component.toggleCollapsed(); expect(component.collapsed).toBe(false); }); it('should test eventCalled function', () => { component.isActive= true; component.eventCalled(); expect(component.isActive).toBe(false); }); it('should test isToggled method',()=>{ expect(component.isToggled()).toBe(false); }); it('should test toggleSidebar method',()=>{ component.pushRightClass="kumar"; expect(component.toggleSidebar()).toBeUndefined; }); it('should test on onLoggedout method',()=>{ expect(localStorage.getItem('isLoggedin')).toBeFalsy }); });