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';
6 import { of } from 'rxjs';
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';
13 describe('LoginComponent', () => {
14 let component: LoginComponent;
15 let fixture: ComponentFixture<LoginComponent>;
16 let routerNavigateSpy: jasmine.Spy;
17 let authServiceLoginSpy: jasmine.Spy;
20 imports: [RouterTestingModule, HttpClientTestingModule, AuthModule]
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();
33 it('should create', () => {
34 expect(component).toBeTruthy();
37 it('should ensure no modal dialogs are opened', () => {
38 component['modalService']['modalsCount'] = 2;
40 expect(component['modalService'].hasOpenModals()).toBeFalsy();
43 it('should not show create cluster wizard if cluster creation was successful', () => {
44 component.postInstalled = true;
47 expect(routerNavigateSpy).toHaveBeenCalledTimes(1);
48 expect(routerNavigateSpy).toHaveBeenCalledWith(['/']);
51 it('should show create cluster wizard if cluster creation was failed', () => {
52 component.postInstalled = false;
55 expect(routerNavigateSpy).toHaveBeenCalledTimes(1);
56 expect(routerNavigateSpy).toHaveBeenCalledWith(['/expand-cluster']);