1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { ReactiveFormsModule } from '@angular/forms';
4 import { Router } from '@angular/router';
5 import { RouterTestingModule } from '@angular/router/testing';
7 import { ToastrModule } from 'ngx-toastr';
9 import { configureTestBed, FormHelper, i18nProviders } from '../../../../testing/unit-test-helper';
10 import { AuthService } from '../../../shared/api/auth.service';
11 import { ComponentsModule } from '../../../shared/components/components.module';
12 import { CdFormGroup } from '../../../shared/forms/cd-form-group';
13 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
14 import { SharedModule } from '../../../shared/shared.module';
15 import { LoginPasswordFormComponent } from './login-password-form.component';
17 describe('LoginPasswordFormComponent', () => {
18 let component: LoginPasswordFormComponent;
19 let fixture: ComponentFixture<LoginPasswordFormComponent>;
20 let form: CdFormGroup;
21 let formHelper: FormHelper;
22 let httpTesting: HttpTestingController;
24 let authStorageService: AuthStorageService;
25 let authService: AuthService;
30 HttpClientTestingModule,
34 ToastrModule.forRoot(),
37 declarations: [LoginPasswordFormComponent],
38 providers: i18nProviders
44 fixture = TestBed.createComponent(LoginPasswordFormComponent);
45 component = fixture.componentInstance;
46 httpTesting = TestBed.get(HttpTestingController);
47 router = TestBed.get(Router);
48 authStorageService = TestBed.get(AuthStorageService);
49 authService = TestBed.get(AuthService);
50 spyOn(router, 'navigate');
51 fixture.detectChanges();
52 form = component.userForm;
53 formHelper = new FormHelper(form);
56 it('should create', () => {
57 expect(component).toBeTruthy();
60 it('should submit', () => {
61 spyOn(component, 'onPasswordChange').and.callThrough();
62 spyOn(authService, 'logout');
63 spyOn(authStorageService, 'getUsername').and.returnValue('test1');
64 formHelper.setMultipleValues({
68 formHelper.setValue('confirmnewpassword', 'bar', true);
70 const request = httpTesting.expectOne('api/user/test1/change_password');
72 expect(component.onPasswordChange).toHaveBeenCalled();
73 expect(authService.logout).toHaveBeenCalled();
76 it('should cancel', () => {
77 spyOn(authService, 'logout');
79 expect(authService.logout).toHaveBeenCalled();