Skip to content

Commit e60d8df

Browse files
committed
ioet#64 Fix comments
1 parent 58039a6 commit e60d8df

File tree

14 files changed

+106
-103
lines changed

14 files changed

+106
-103
lines changed

src/app/app.module.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ import { environment } from '../environments/environment';
7373
StoreModule.forRoot(reducers, {
7474
metaReducers,
7575
}),
76-
!environment.production ? StoreDevtoolsModule.instrument() : [],
76+
!environment.production
77+
? StoreDevtoolsModule.instrument({
78+
maxAge: 15, // Retains last 15 states
79+
})
80+
: [],
7781
EffectsModule.forRoot([ProjectEffects, ActivityEffects]),
78-
StoreDevtoolsModule.instrument({
79-
maxAge: 15, // Retains last 15 states
80-
}),
8182
],
8283
providers: [],
8384
bootstrap: [AppComponent],

src/app/modules/project-management/components/create-project/create-project.component.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22
import { provideMockStore, MockStore } from '@ngrx/store/testing';
33
import { FormsModule, ReactiveFormsModule, FormBuilder } from '@angular/forms';
44

5-
import { AppState } from '../../store/project.reducer';
5+
import { ProjectState } from '../../store/project.reducer';
66
import { CreateProjectComponent } from './create-project.component';
77
import * as actions from '../../store/project.actions';
88

99
describe('CreateProjectComponent', () => {
1010
let component: CreateProjectComponent;
1111
let fixture: ComponentFixture<CreateProjectComponent>;
12-
let store: MockStore<AppState>;
12+
let store: MockStore<ProjectState>;
1313

1414
const state = {
1515
projectList: [{ id: 'id', name: 'name', description: 'description' }],
@@ -47,7 +47,7 @@ describe('CreateProjectComponent', () => {
4747
component.ngOnChanges();
4848
expect(component.projectForm.value.name).toEqual(newData.name);
4949
expect(component.projectForm.value.description).toEqual(newData.description);
50-
expect(component.isEdit).toEqual(true);
50+
expect(component.isUpdating).toEqual(true);
5151
});
5252

5353
it('should emit ngOnChange and reset ProjectForm', () => {
@@ -56,33 +56,33 @@ describe('CreateProjectComponent', () => {
5656

5757
expect(component.projectForm.value.name).toEqual(null);
5858
expect(component.projectForm.value.description).toEqual(null);
59-
expect(component.isEdit).toEqual(false);
59+
expect(component.isUpdating).toEqual(false);
6060
});
6161

62-
it('should dispatch PostProject action #onSubmit', () => {
62+
it('should dispatch CreateProject action #onSubmit', () => {
6363
const project = {
6464
id: '1',
6565
name: 'app 4',
6666
description: 'It is a good app',
6767
};
6868

69-
component.isEdit = false;
69+
component.isUpdating = false;
7070
spyOn(store, 'dispatch');
7171
component.onSubmit(project);
72-
expect(store.dispatch).toHaveBeenCalledWith(new actions.PostProject(project));
72+
expect(store.dispatch).toHaveBeenCalledWith(new actions.CreateProject(project));
7373
});
7474

75-
it('should dispatch PutProject action #onSubmit', () => {
75+
it('should dispatch UpdateProject action #onSubmit', () => {
7676
const project = {
7777
id: '1',
7878
name: 'app 4',
7979
description: 'It is a good app',
8080
};
8181

82-
component.isEdit = true;
82+
component.isUpdating = true;
8383
spyOn(store, 'dispatch');
8484
component.onSubmit(project);
85-
expect(store.dispatch).toHaveBeenCalledWith(new actions.PutProject(project));
85+
expect(store.dispatch).toHaveBeenCalledWith(new actions.UpdateProject(project));
8686
});
8787

8888
it('should clean the form and send a cancelForm event #reset', () => {
@@ -103,7 +103,7 @@ describe('CreateProjectComponent', () => {
103103
expect(component.projectForm.valid).toBeFalsy();
104104
});
105105

106-
it('name field validity', () => {
106+
it('checks if name field is valid', () => {
107107
const name = component.projectForm.controls.name;
108108
expect(name.valid).toBeFalsy();
109109

@@ -114,7 +114,7 @@ describe('CreateProjectComponent', () => {
114114
expect(name.hasError('required')).toBeFalsy();
115115
});
116116

117-
it('description field validity', () => {
117+
it('checks if description field is valid', () => {
118118
const details = component.projectForm.controls.description;
119119
expect(details.valid).toBeFalsy();
120120

src/app/modules/project-management/components/create-project/create-project.component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, Input, OnChanges, OnInit, Output, EventEmitter } from '@angu
22
import { FormBuilder, Validators } from '@angular/forms';
33
import { Store } from '@ngrx/store';
44
import { Project } from '../../../shared/models';
5+
import { ProjectState } from '../../store/project.reducer';
56
import * as actions from '../../store/project.actions';
67

78
@Component({
@@ -12,12 +13,12 @@ import * as actions from '../../store/project.actions';
1213
export class CreateProjectComponent implements OnChanges, OnInit {
1314
projectForm;
1415
editProjectId;
15-
isEdit = false;
16+
isUpdating = false;
1617

1718
@Input() projectToEdit: Project;
1819
@Output() cancelForm = new EventEmitter();
1920

20-
constructor(private formBuilder: FormBuilder, private store: Store<any>) {
21+
constructor(private formBuilder: FormBuilder, private store: Store<ProjectState>) {
2122
this.projectForm = this.formBuilder.group({
2223
name: ['', Validators.required],
2324
description: ['', Validators.required],
@@ -29,10 +30,10 @@ export class CreateProjectComponent implements OnChanges, OnInit {
2930
ngOnChanges(): void {
3031
if (this.projectToEdit) {
3132
this.projectForm.patchValue(this.projectToEdit);
32-
this.isEdit = true;
33+
this.isUpdating = true;
3334
} else {
3435
this.projectForm.reset();
35-
this.isEdit = false;
36+
this.isUpdating = false;
3637
}
3738
}
3839

@@ -46,10 +47,10 @@ export class CreateProjectComponent implements OnChanges, OnInit {
4647

4748
onSubmit(formData) {
4849
const projectData = { ...this.projectToEdit, ...formData };
49-
if (!this.isEdit) {
50-
this.store.dispatch(new actions.PostProject(projectData));
50+
if (this.isUpdating) {
51+
this.store.dispatch(new actions.UpdateProject(projectData));
5152
} else {
52-
this.store.dispatch(new actions.PutProject(projectData));
53+
this.store.dispatch(new actions.CreateProject(projectData));
5354
}
5455
this.reset();
5556
}

src/app/modules/project-management/components/project-list/project-list.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22
import { provideMockStore, MockStore } from '@ngrx/store/testing';
33

44
import { ProjectListComponent } from './project-list.component';
5-
import { AppState } from '../../store/project.reducer';
5+
import { ProjectState } from '../../store/project.reducer';
66
import { allProjects } from '../../store/project.selectors';
77
import { FilterProjectPipe } from '../../../shared/pipes';
88

99
describe('ProjectListComponent', () => {
1010
let component: ProjectListComponent;
1111
let fixture: ComponentFixture<ProjectListComponent>;
12-
let store: MockStore<AppState>;
12+
let store: MockStore<ProjectState>;
1313
let mockProjectsSelector;
1414

1515
const state = {

src/app/modules/project-management/store/project.actions.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,31 @@ describe('Actions for Projects', () => {
1111
expect(getProjectsFail.type).toEqual(actions.ProjectActionTypes.GET_PROJECTS_FAIL);
1212
});
1313

14-
it('PostProjectSuccess type is ProjectActionTypes.POST_PROJECT_SUCCESS', () => {
15-
const postProjectSuccess = new actions.PostProjectSuccess({
14+
it('CreateProjectSuccess type is ProjectActionTypes.CREATE_PROJECT_SUCCESS', () => {
15+
const createProjectSuccess = new actions.CreateProjectSuccess({
1616
id: '1',
1717
name: 'Training',
1818
description: 'It is good for learning',
1919
});
20-
expect(postProjectSuccess.type).toEqual(actions.ProjectActionTypes.POST_PROJECT_SUCCESS);
20+
expect(createProjectSuccess.type).toEqual(actions.ProjectActionTypes.CREATE_PROJECT_SUCCESS);
2121
});
2222

23-
it('PostProjectFail type is ProjectActionTypes.POST_PROJECT_FAIL', () => {
24-
const postProjectFail = new actions.PostProjectFail('error');
25-
expect(postProjectFail.type).toEqual(actions.ProjectActionTypes.POST_PROJECT_FAIL);
23+
it('CreateProjectFail type is ProjectActionTypes.CREATE_PROJECT_FAIL', () => {
24+
const createProjectFail = new actions.CreateProjectFail('error');
25+
expect(createProjectFail.type).toEqual(actions.ProjectActionTypes.CREATE_PROJECT_FAIL);
2626
});
2727

28-
it('PutProjectSuccess type is ProjectActionTypes.POST_PROJECT_SUCCESS', () => {
29-
const putProjectSuccess = new actions.PutProjectSuccess({
28+
it('UpdateProjectSuccess type is ProjectActionTypes.UPDATE_PROJECT_SUCCESS', () => {
29+
const updateProjectSuccess = new actions.UpdateProjectSuccess({
3030
id: '1',
3131
name: 'Training',
3232
description: 'It is good for learning',
3333
});
34-
expect(putProjectSuccess.type).toEqual(actions.ProjectActionTypes.PUT_PROJECT_SUCCESS);
34+
expect(updateProjectSuccess.type).toEqual(actions.ProjectActionTypes.UPDATE_PROJECT_SUCCESS);
3535
});
3636

37-
it('PutProjectFail type is ProjectActionTypes.POST_PROJECT_FAIL', () => {
38-
const putProjectFail = new actions.PutProjectFail('error');
39-
expect(putProjectFail.type).toEqual(actions.ProjectActionTypes.PUT_PROJECT_FAIL);
37+
it('UpdateProjectFail type is ProjectActionTypes.UPDATE_PROJECT_FAIL', () => {
38+
const updateProjectFail = new actions.UpdateProjectFail('error');
39+
expect(updateProjectFail.type).toEqual(actions.ProjectActionTypes.UPDATE_PROJECT_FAIL);
4040
});
4141
});

src/app/modules/project-management/store/project.actions.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ export enum ProjectActionTypes {
55
GET_PROJECTS = '[Projects] GET_PROJECTS',
66
GET_PROJECTS_SUCCESS = '[Projects] GET_PROJECTS_SUCCESS',
77
GET_PROJECTS_FAIL = '[Projects] GET_PROJECTS_FAIL',
8-
POST_PROJECT = '[Projects] POST_PROJECT',
9-
POST_PROJECT_SUCCESS = '[Projects] POST_PROJECT_SUCCESS',
10-
POST_PROJECT_FAIL = '[Projects] POST_PROJECT_FAIL',
11-
PUT_PROJECT = '[Projects] PUT_PROJECT',
12-
PUT_PROJECT_SUCCESS = '[Projects] PUT_PROJECT_SUCCESS',
13-
PUT_PROJECT_FAIL = '[Projects] PUT_PROJECT_FAIL',
8+
CREATE_PROJECT = '[Projects] CREATE_PROJECT',
9+
CREATE_PROJECT_SUCCESS = '[Projects] CREATE_PROJECT_SUCCESS',
10+
CREATE_PROJECT_FAIL = '[Projects] CREATE_PROJECT_FAIL',
11+
UPDATE_PROJECT = '[Projects] UPDATE_PROJECT',
12+
UPDATE_PROJECT_SUCCESS = '[Projects] UPDATE_PROJECT_SUCCESS',
13+
UPDATE_PROJECT_FAIL = '[Projects] UPDATE_PROJECT_FAIL',
1414
}
1515

1616
export class GetProjectsLoad implements Action {
@@ -28,38 +28,38 @@ export class GetProjectsFail implements Action {
2828
constructor(public error: string) {}
2929
}
3030

31-
export class PostProject implements Action {
32-
public readonly type = ProjectActionTypes.POST_PROJECT;
31+
export class CreateProject implements Action {
32+
public readonly type = ProjectActionTypes.CREATE_PROJECT;
3333

3434
constructor(public payload: Project) {}
3535
}
3636

37-
export class PostProjectSuccess implements Action {
38-
public readonly type = ProjectActionTypes.POST_PROJECT_SUCCESS;
37+
export class CreateProjectSuccess implements Action {
38+
public readonly type = ProjectActionTypes.CREATE_PROJECT_SUCCESS;
3939

4040
constructor(public payload: Project) {}
4141
}
4242

43-
export class PostProjectFail implements Action {
44-
public readonly type = ProjectActionTypes.POST_PROJECT_FAIL;
43+
export class CreateProjectFail implements Action {
44+
public readonly type = ProjectActionTypes.CREATE_PROJECT_FAIL;
4545

4646
constructor(public error: string) {}
4747
}
4848

49-
export class PutProject implements Action {
50-
public readonly type = ProjectActionTypes.PUT_PROJECT;
49+
export class UpdateProject implements Action {
50+
public readonly type = ProjectActionTypes.UPDATE_PROJECT;
5151

5252
constructor(public payload: Project) {}
5353
}
5454

55-
export class PutProjectSuccess implements Action {
56-
public readonly type = ProjectActionTypes.PUT_PROJECT_SUCCESS;
55+
export class UpdateProjectSuccess implements Action {
56+
public readonly type = ProjectActionTypes.UPDATE_PROJECT_SUCCESS;
5757

5858
constructor(public payload: Project) {}
5959
}
6060

61-
export class PutProjectFail implements Action {
62-
public readonly type = ProjectActionTypes.PUT_PROJECT_FAIL;
61+
export class UpdateProjectFail implements Action {
62+
public readonly type = ProjectActionTypes.UPDATE_PROJECT_FAIL;
6363

6464
constructor(public error: string) {}
6565
}
@@ -68,9 +68,9 @@ export type ProjectActions =
6868
| GetProjectsLoad
6969
| GetProjectsSuccess
7070
| GetProjectsFail
71-
| PostProject
72-
| PostProjectSuccess
73-
| PostProjectFail
74-
| PutProject
75-
| PutProjectSuccess
76-
| PutProjectFail;
71+
| CreateProject
72+
| CreateProjectSuccess
73+
| CreateProjectFail
74+
| UpdateProject
75+
| UpdateProjectSuccess
76+
| UpdateProjectFail;

src/app/modules/project-management/store/project.effects.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ export class ProjectEffects {
2424
);
2525

2626
@Effect()
27-
postProject$: Observable<Action> = this.actions$.pipe(
28-
ofType(actions.ProjectActionTypes.POST_PROJECT),
29-
map((action: actions.PostProject) => action.payload),
27+
createProject$: Observable<Action> = this.actions$.pipe(
28+
ofType(actions.ProjectActionTypes.CREATE_PROJECT),
29+
map((action: actions.CreateProject) => action.payload),
3030
mergeMap((project) =>
3131
this.projectService.createProject(project).pipe(
3232
map((projectData) => {
33-
return new actions.PostProjectSuccess(projectData);
33+
return new actions.CreateProjectSuccess(projectData);
3434
}),
35-
catchError((error) => of(new actions.PostProjectFail(error)))
35+
catchError((error) => of(new actions.CreateProjectFail(error)))
3636
)
3737
)
3838
);
3939

4040
@Effect()
41-
putProject$: Observable<Action> = this.actions$.pipe(
42-
ofType(actions.ProjectActionTypes.PUT_PROJECT),
43-
map((action: actions.PutProject) => action.payload),
41+
updateProject$: Observable<Action> = this.actions$.pipe(
42+
ofType(actions.ProjectActionTypes.UPDATE_PROJECT),
43+
map((action: actions.UpdateProject) => action.payload),
4444
mergeMap((project) =>
4545
this.projectService.updateProject(project).pipe(
4646
map((projectData) => {
47-
return new actions.PutProjectSuccess(projectData);
47+
return new actions.UpdateProjectSuccess(projectData);
4848
}),
49-
catchError((error) => of(new actions.PutProjectFail(error)))
49+
catchError((error) => of(new actions.UpdateProjectFail(error)))
5050
)
5151
)
5252
);

0 commit comments

Comments
 (0)