]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts
import ceph 16.2.7
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / auth / login / login.component.spec.ts
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { Router } from '@angular/router';
4 import { RouterTestingModule } from '@angular/router/testing';
5
6 import { of } from 'rxjs';
7
8 import { AuthService } from '~/app/shared/api/auth.service';
9 import { configureTestBed } from '~/testing/unit-test-helper';
10 import { AuthModule } from '../auth.module';
11 import { LoginComponent } from './login.component';
12
13 describe('LoginComponent', () => {
14 let component: LoginComponent;
15 let fixture: ComponentFixture<LoginComponent>;
16 let routerNavigateSpy: jasmine.Spy;
17 let authServiceLoginSpy: jasmine.Spy;
18
19 configureTestBed({
20 imports: [RouterTestingModule, HttpClientTestingModule, AuthModule]
21 });
22
23 beforeEach(() => {
24 fixture = TestBed.createComponent(LoginComponent);
25 component = fixture.componentInstance;
26 routerNavigateSpy = spyOn(TestBed.inject(Router), 'navigate');
27 routerNavigateSpy.and.returnValue(true);
28 authServiceLoginSpy = spyOn(TestBed.inject(AuthService), 'login');
29 authServiceLoginSpy.and.returnValue(of(null));
30 fixture.detectChanges();
31 });
32
33 it('should create', () => {
34 expect(component).toBeTruthy();
35 });
36
37 it('should ensure no modal dialogs are opened', () => {
38 component['modalService']['modalsCount'] = 2;
39 component.ngOnInit();
40 expect(component['modalService'].hasOpenModals()).toBeFalsy();
41 });
42
43 it('should not show create cluster wizard if cluster creation was successful', () => {
44 component.postInstalled = true;
45 component.login();
46
47 expect(routerNavigateSpy).toHaveBeenCalledTimes(1);
48 expect(routerNavigateSpy).toHaveBeenCalledWith(['/']);
49 });
50
51 it('should show create cluster wizard if cluster creation was failed', () => {
52 component.postInstalled = false;
53 component.login();
54
55 expect(routerNavigateSpy).toHaveBeenCalledTimes(1);
56 expect(routerNavigateSpy).toHaveBeenCalledWith(['/expand-cluster']);
57 });
58 });