2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 Modification Copyright (C) 2018 IBM
7 ===================================================================
9 Unless otherwise specified, all software contained herein is licensed
10 under the Apache License, Version 2.0 (the License);
11 you may not use this software except in compliance with the License.
12 You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
22 ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 ============LICENSE_END============================================
26 /* tslint:disable:no-unused-variable */
27 import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
28 import { NO_ERRORS_SCHEMA } from '@angular/core';
29 import { ActivatedRoute } from '@angular/router';
30 import { userloginFormComponent } from './userlogin-form.component';
31 import { FormsModule } from '@angular/forms';
32 import { NotificationService } from './../../shared/services/notification.service';
33 import { ParamShareService } from './../../shared/services/paramShare.service';
34 import { MappingEditorService } from './../../shared/services/mapping-editor.service';
35 import { DialogService } from 'ng2-bootstrap-modal';
36 import { RouterTestingModule } from '@angular/router/testing';
37 import { HttpUtilService } from '.././../shared/services/httpUtil/http-util.service';
38 import { UtilityService } from '.././../shared/services/utilityService/utility.service';
39 import { Router } from '@angular/router';
40 import {NotificationsService} from 'angular2-notifications';
42 describe('userloginFormComponent', () => {
43 let component: userloginFormComponent;
44 let fixture: ComponentFixture<userloginFormComponent>;
45 let mockActiveRoute = {
52 beforeEach(async(() => {
53 TestBed.configureTestingModule({
54 declarations: [userloginFormComponent],
55 schemas: [NO_ERRORS_SCHEMA],
56 imports: [FormsModule, RouterTestingModule,],
57 providers: [UtilityService, ParamShareService, DialogService,NotificationsService, HttpUtilService, MappingEditorService,
58 {provide: ActivatedRoute, useValue: mockActiveRoute},
59 { provide: Router, useClass: MockRouter }]
64 fixture = TestBed.createComponent(userloginFormComponent);
65 component = fixture.componentInstance;
66 fixture.detectChanges();
67 // localStorage['userId'] = "testUser"
68 component.userId = 'test Usr';
72 navigateByUrl(url: string) {
76 navigate(url: string) {
85 it('should create', () => {
86 expect(component).toBeTruthy();
88 it('get the user Id', () => {
90 expect(localStorage.userId).toEqual('test Usr');
93 it('should route to myvnfform', inject([Router], (router: Router) => {
94 const spy = spyOn(router, 'navigateByUrl');
96 const url = spy.calls.first().args[0];
98 // return url is set to '/home' in mockActiveRoute.
99 expect(url.length).toBe(5);
100 expect(url[0]).toEqual('/');
101 expect(url[1]).toEqual('h');
102 expect(localStorage['userId']).toBe('test Usr');
105 it('test validateUserName function', () => {
106 component.userId = '';
107 component.validateUserName();
108 expect(component.errorMessage).toEqual('');
109 expect(component.invalid).toEqual(true);