import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { configureTestBed } from '../../../../testing/unit-test-helper';
-import { AuthService } from '../../../shared/api/auth.service';
-import { AuthStorageService } from '../../../shared/services/auth-storage.service';
+import { AuthModule } from '../auth.module';
import { LoginComponent } from './login.component';
describe('LoginComponent', () => {
let fixture: ComponentFixture<LoginComponent>;
configureTestBed({
- imports: [FormsModule, RouterTestingModule, HttpClientTestingModule],
- declarations: [LoginComponent],
- providers: [AuthService, AuthStorageService]
+ imports: [RouterTestingModule, HttpClientTestingModule, AuthModule]
});
beforeEach(() => {
it('should create', () => {
expect(component).toBeTruthy();
});
+
+ it('should ensure no modal dialogs are opened', () => {
+ component.bsModalService.modalsCount = 2;
+ component.ngOnInit();
+ expect(component.bsModalService.getModalsCount()).toBe(0);
+ });
});
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
+import { BsModalService } from 'ngx-bootstrap';
+
import { AuthService } from '../../../shared/api/auth.service';
import { Credentials } from '../../../shared/models/credentials';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
constructor(
private authService: AuthService,
private authStorageService: AuthStorageService,
+ private bsModalService: BsModalService,
private router: Router
) {}
ngOnInit() {
if (this.authStorageService.isLoggedIn()) {
this.router.navigate(['']);
+ } else {
+ // Make sure all open modal dialogs are closed. This might be
+ // necessary when the logged in user is redirected to the login
+ // page after a 401.
+ const modalsCount = this.bsModalService.getModalsCount();
+ for (let i = 1; i <= modalsCount; i++) {
+ this.bsModalService.hide(i);
+ }
}
}