]> git.proxmox.com Git - ceph.git/blobdiff - 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
index 15a7275739f36d08c088bd0ba1238bbf6182b8f2..fc02e9bdeeefbad495ddd56826f61b5b30f99f29 100644 (file)
@@ -1,7 +1,11 @@
 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';
@@ -9,6 +13,8 @@ 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]
@@ -17,6 +23,10 @@ describe('LoginComponent', () => {
   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();
   });
 
@@ -29,4 +39,20 @@ describe('LoginComponent', () => {
     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']);
+  });
 });