]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login-password-form/login-password-form.component.spec.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / auth / login-password-form / login-password-form.component.spec.ts
CommitLineData
9f95a23c
TL
1import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
3import { ReactiveFormsModule } from '@angular/forms';
4import { Router } from '@angular/router';
5import { RouterTestingModule } from '@angular/router/testing';
6
7import { ToastrModule } from 'ngx-toastr';
8
f67539c2
TL
9import { AuthService } from '~/app/shared/api/auth.service';
10import { ComponentsModule } from '~/app/shared/components/components.module';
11import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
12import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
13import { SharedModule } from '~/app/shared/shared.module';
14import { configureTestBed, FormHelper } from '~/testing/unit-test-helper';
9f95a23c
TL
15import { LoginPasswordFormComponent } from './login-password-form.component';
16
17describe('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
f6b5b4d7
TL
27 configureTestBed({
28 imports: [
29 HttpClientTestingModule,
30 RouterTestingModule,
31 ReactiveFormsModule,
32 ComponentsModule,
33 ToastrModule.forRoot(),
34 SharedModule
35 ],
f67539c2 36 declarations: [LoginPasswordFormComponent]
f6b5b4d7 37 });
9f95a23c
TL
38
39 beforeEach(() => {
40 fixture = TestBed.createComponent(LoginPasswordFormComponent);
41 component = fixture.componentInstance;
f67539c2
TL
42 httpTesting = TestBed.inject(HttpTestingController);
43 router = TestBed.inject(Router);
44 authStorageService = TestBed.inject(AuthStorageService);
45 authService = TestBed.inject(AuthService);
9f95a23c
TL
46 spyOn(router, 'navigate');
47 fixture.detectChanges();
48 form = component.userForm;
49 formHelper = new FormHelper(form);
50 });
51
52 it('should create', () => {
53 expect(component).toBeTruthy();
54 });
55
56 it('should submit', () => {
57 spyOn(component, 'onPasswordChange').and.callThrough();
58 spyOn(authService, 'logout');
59 spyOn(authStorageService, 'getUsername').and.returnValue('test1');
60 formHelper.setMultipleValues({
61 oldpassword: 'foo',
62 newpassword: 'bar'
63 });
64 formHelper.setValue('confirmnewpassword', 'bar', true);
65 component.onSubmit();
66 const request = httpTesting.expectOne('api/user/test1/change_password');
67 request.flush({});
68 expect(component.onPasswordChange).toHaveBeenCalled();
69 expect(authService.logout).toHaveBeenCalled();
70 });
71
72 it('should cancel', () => {
73 spyOn(authService, 'logout');
74 component.onCancel();
75 expect(authService.logout).toHaveBeenCalled();
76 });
77});