]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login-password-form/login-password-form.component.spec.ts
import 15.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / auth / login-password-form / login-password-form.component.spec.ts
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';
6
7 import { ToastrModule } from 'ngx-toastr';
8
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';
16
17 describe('LoginPasswordFormComponent', () => {
18 let component: LoginPasswordFormComponent;
19 let fixture: ComponentFixture<LoginPasswordFormComponent>;
20 let form: CdFormGroup;
21 let formHelper: FormHelper;
22 let httpTesting: HttpTestingController;
23 let router: Router;
24 let authStorageService: AuthStorageService;
25 let authService: AuthService;
26
27 configureTestBed({
28 imports: [
29 HttpClientTestingModule,
30 RouterTestingModule,
31 ReactiveFormsModule,
32 ComponentsModule,
33 ToastrModule.forRoot(),
34 SharedModule
35 ],
36 declarations: [LoginPasswordFormComponent],
37 providers: i18nProviders
38 });
39
40 beforeEach(() => {
41 fixture = TestBed.createComponent(LoginPasswordFormComponent);
42 component = fixture.componentInstance;
43 httpTesting = TestBed.get(HttpTestingController);
44 router = TestBed.get(Router);
45 authStorageService = TestBed.get(AuthStorageService);
46 authService = TestBed.get(AuthService);
47 spyOn(router, 'navigate');
48 fixture.detectChanges();
49 form = component.userForm;
50 formHelper = new FormHelper(form);
51 });
52
53 it('should create', () => {
54 expect(component).toBeTruthy();
55 });
56
57 it('should submit', () => {
58 spyOn(component, 'onPasswordChange').and.callThrough();
59 spyOn(authService, 'logout');
60 spyOn(authStorageService, 'getUsername').and.returnValue('test1');
61 formHelper.setMultipleValues({
62 oldpassword: 'foo',
63 newpassword: 'bar'
64 });
65 formHelper.setValue('confirmnewpassword', 'bar', true);
66 component.onSubmit();
67 const request = httpTesting.expectOne('api/user/test1/change_password');
68 request.flush({});
69 expect(component.onPasswordChange).toHaveBeenCalled();
70 expect(authService.logout).toHaveBeenCalled();
71 });
72
73 it('should cancel', () => {
74 spyOn(authService, 'logout');
75 component.onCancel();
76 expect(authService.logout).toHaveBeenCalled();
77 });
78 });