Skip to content
Snippets Groups Projects
Commit dbfc602c authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Tests on login containers => DONE

parent e615e272
No related branches found
No related tags found
2 merge requests!147Develop,!135Resolve "Continue tests integration"
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
import { FormsModule } from '@angular/forms';
import { ChangePasswordComponent } from './change-password.component';
import * as fromLogin from '../store/login.reducer';
import * as loginActions from '../store/login.action';
describe('[Search] Container: ChangePasswordComponent', () => {
let component: ChangePasswordComponent;
let fixture: ComponentFixture<ChangePasswordComponent>;
let store: MockStore;
const initialState = {
login: { ...fromLogin.initialState },
};
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ChangePasswordComponent ],
providers: [
provideMockStore({ initialState })
],
imports: [ FormsModule ]
});
fixture = TestBed.createComponent(ChangePasswordComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
}));
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('#submitted() should dispatch ChangePasswordAction', () => {
component.model.password = 'toto';
component.model.newPassword = 'tutu';
const changePasswordAction = new loginActions.ChangePasswordAction({
password: 'toto',
new_password: 'tutu'
});
const spy = spyOn(store, 'dispatch');
component.submitted();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(changePasswordAction);
});
});
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
import { Component } from '@angular/core';
import { TabsModule } from 'ngx-bootstrap/tabs';
import { ForgotPasswordComponent } from './forgot-password.component';
import * as fromLogin from '../store/login.reducer';
import * as loginActions from '../store/login.action';
describe('[Search] Container: ForgotPasswordComponent', () => {
@Component({ selector: 'app-form-forgot-password', template: '' })
class FormForgotPasswordStubComponent { }
@Component({ selector: 'app-account-benefits', template: '' })
class AccountBenefitsStubComponent { }
let component: ForgotPasswordComponent;
let fixture: ComponentFixture<ForgotPasswordComponent>;
let store: MockStore;
const initialState = {
login: { ...fromLogin.initialState },
};
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ForgotPasswordComponent,
FormForgotPasswordStubComponent,
AccountBenefitsStubComponent
],
providers: [
provideMockStore({ initialState })
],
imports: [TabsModule.forRoot()]
});
fixture = TestBed.createComponent(ForgotPasswordComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
}));
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('#forgotPassword() should dispatch ForgotPasswordAction', () => {
const forgotPasswordAction = new loginActions.ForgotPasswordAction('toto');
const spy = spyOn(store, 'dispatch');
component.forgotPassword('toto');
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(forgotPasswordAction);
});
});
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { provideMockStore, MockStore } from '@ngrx/store/testing';
import { Component } from '@angular/core';
import { TabsModule } from 'ngx-bootstrap/tabs';
import { LoginComponent } from './login.component';
import * as fromLogin from '../store/login.reducer';
import * as loginActions from '../store/login.action';
import { Login } from "../store/model";
describe('[Search] Container: LoginComponent', () => {
@Component({ selector: 'app-form-login', template: '' })
class FormLoginStubComponent { }
@Component({ selector: '<app-form-register', template: '' })
class FormRegisterStubComponent { }
@Component({ selector: 'app-account-benefits', template: '' })
class AccountBenefitsStubComponent { }
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
let store: MockStore;
const initialState = {
login: { ...fromLogin.initialState },
};
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
LoginComponent,
FormLoginStubComponent,
FormRegisterStubComponent,
AccountBenefitsStubComponent
],
providers: [
provideMockStore({ initialState })
],
imports: [TabsModule.forRoot()]
});
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);
}));
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('#login() should dispatch LoginAction', () => {
const login: Login = { email: 'test@email.com', password: 'password'};
const loginAction = new loginActions.LoginAction(login);
const spy = spyOn(store, 'dispatch');
component.login(login);
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(loginAction);
});
it('#register() should dispatch RegisterAction', () => {
const login: Login = { email: 'test@email.com', password: 'password'};
const registerAction = new loginActions.RegisterAction(login);
const spy = spyOn(store, 'dispatch');
component.register(login);
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(registerAction);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment