summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts
blob: fc02e9bdeeefbad495ddd56826f61b5b30f99f29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';

import { of } from 'rxjs';

import { AuthService } from '~/app/shared/api/auth.service';
import { configureTestBed } from '~/testing/unit-test-helper';
import { AuthModule } from '../auth.module';
import { LoginComponent } from './login.component';

describe('LoginComponent', () => {
  let component: LoginComponent;
  let fixture: ComponentFixture<LoginComponent>;
  let routerNavigateSpy: jasmine.Spy;
  let authServiceLoginSpy: jasmine.Spy;

  configureTestBed({
    imports: [RouterTestingModule, HttpClientTestingModule, AuthModule]
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(LoginComponent);
    component = fixture.componentInstance;
    routerNavigateSpy = spyOn(TestBed.inject(Router), 'navigate');
    routerNavigateSpy.and.returnValue(true);
    authServiceLoginSpy = spyOn(TestBed.inject(AuthService), 'login');
    authServiceLoginSpy.and.returnValue(of(null));
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should ensure no modal dialogs are opened', () => {
    component['modalService']['modalsCount'] = 2;
    component.ngOnInit();
    expect(component['modalService'].hasOpenModals()).toBeFalsy();
  });

  it('should not show create cluster wizard if cluster creation was successful', () => {
    component.postInstalled = true;
    component.login();

    expect(routerNavigateSpy).toHaveBeenCalledTimes(1);
    expect(routerNavigateSpy).toHaveBeenCalledWith(['/']);
  });

  it('should show create cluster wizard if cluster creation was failed', () => {
    component.postInstalled = false;
    component.login();

    expect(routerNavigateSpy).toHaveBeenCalledTimes(1);
    expect(routerNavigateSpy).toHaveBeenCalledWith(['/expand-cluster']);
  });
});