Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
#62 renaming tests and removing not needed service injection
  • Loading branch information
enriquezrene committed Apr 7, 2020
commit 306aa9ee357c0259d2c9a6ad9647b70fac6aeeca
Original file line number Diff line number Diff line change
Expand Up @@ -42,58 +42,63 @@ describe('CreateProjectComponent', () => {
name: 'Project Test 13',
description: 'description',
};

component.projectToEdit = newData;

component.ngOnChanges();

expect(component.projectForm.value.name).toEqual(newData.name);
expect(component.projectForm.value.description).toEqual(newData.description);
expect(component.isUpdating).toEqual(true);
});

it('should emit ngOnChange and reset ProjectForm', () => {
it('on ngOnChange with projectToEdit=null should reset projectForm', () => {
component.projectToEdit = null;

component.ngOnChanges();

expect(component.projectForm.value.name).toEqual(null);
expect(component.projectForm.value.description).toEqual(null);
expect(component.isUpdating).toEqual(false);
});

it('should dispatch CreateProject action #onSubmit', () => {
it('should dispatch CreateProject action #onSubmit if isUpdating=false', () => {
const project = {
id: '1',
name: 'app 4',
description: 'It is a good app',
};

component.isUpdating = false;
spyOn(store, 'dispatch');

component.onSubmit(project);

expect(store.dispatch).toHaveBeenCalledWith(new actions.CreateProject(project));
});

it('should dispatch UpdateProject action #onSubmit', () => {
it('should dispatch UpdateProject action #onSubmit if isUpdating=true', () => {
const project = {
id: '1',
name: 'app 4',
description: 'It is a good app',
};

component.isUpdating = true;
spyOn(store, 'dispatch');

component.onSubmit(project);

expect(store.dispatch).toHaveBeenCalledWith(new actions.UpdateProject(project));
});

it('should clean the form and send a cancelForm event #reset', () => {
it('should clean the form and emmit a cancelForm event on #reset', () => {
const project = {
name: 'app 4',
description: 'It is a good app',
};

component.projectForm.setValue(project);
spyOn(component.cancelForm, 'emit');

component.reset();

expect(component.projectForm.value.name).toEqual(null);
expect(component.projectForm.value.description).toEqual(null);
expect(component.cancelForm.emit).toHaveBeenCalled();
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/project-management/store/project.effects.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Injectable } from '@angular/core';
import { ofType, Actions, Effect } from '@ngrx/effects';
import { Action, Store } from '@ngrx/store';
import { Action } from '@ngrx/store';
import { of, Observable } from 'rxjs';
import { catchError, map, mergeMap } from 'rxjs/operators';
import { ProjectService } from '../services/project.service';
import * as actions from './project.actions';

@Injectable()
export class ProjectEffects {
constructor(private actions$: Actions, private projectService: ProjectService, private store: Store<any>) {}
constructor(private actions$: Actions, private projectService: ProjectService) {}

@Effect()
loadProjects$: Observable<Action> = this.actions$.pipe(
Expand Down