|
|
@@ -1,14 +1,29 @@
|
|
|
-import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
|
|
+import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
|
|
+import { By } from '@angular/platform-browser';
|
|
|
+import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
|
+import { Router } from '@angular/router';
|
|
|
|
|
|
import { LoginComponent } from './login.component';
|
|
|
+import { AuthService } from 'src/app/services/auth.service';
|
|
|
+
|
|
|
+
|
|
|
+class AuthServiceMock { }
|
|
|
+class RouterMock { }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
describe('LoginComponent', () => {
|
|
|
let component: LoginComponent;
|
|
|
let fixture: ComponentFixture<LoginComponent>;
|
|
|
|
|
|
- beforeEach(waitForAsync(() => {
|
|
|
+ beforeEach(async(() => {
|
|
|
TestBed.configureTestingModule({
|
|
|
- declarations: [ LoginComponent ]
|
|
|
+ imports: [ FormsModule, ReactiveFormsModule ],
|
|
|
+ declarations: [ LoginComponent ],
|
|
|
+ providers: [
|
|
|
+ { provide: Router, useClass: RouterMock },
|
|
|
+ { provide: AuthService, useClass: AuthServiceMock }
|
|
|
+ ]
|
|
|
})
|
|
|
.compileComponents();
|
|
|
}));
|
|
|
@@ -22,4 +37,25 @@ describe('LoginComponent', () => {
|
|
|
it('should create', () => {
|
|
|
expect(component).toBeTruthy();
|
|
|
});
|
|
|
+
|
|
|
+ it('should display the page header text', () => {
|
|
|
+ const el = fixture.debugElement.query(By.css('h1')).nativeElement;
|
|
|
+ expect(el.textContent).toContain('Connexion');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should display the username and password inputs', () => {
|
|
|
+ const [inputUsername, inputPassword] = fixture.debugElement.queryAll(By.css('input'));
|
|
|
+ expect(inputUsername.nativeElement).toBeTruthy();
|
|
|
+ expect(inputPassword.nativeElement).toBeTruthy();
|
|
|
+ expect(inputUsername.nativeElement.value).toBeFalsy();
|
|
|
+ expect(inputPassword.nativeElement.value).toBeFalsy();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should display the login button', () => {
|
|
|
+ const el = fixture.debugElement.query(By.css('button')).nativeElement;
|
|
|
+ expect(el).toBeTruthy();
|
|
|
+ expect(el.textContent).toContain('Connexion');
|
|
|
+ expect(el.disabled).toBeTruthy();
|
|
|
+ });
|
|
|
+
|
|
|
});
|