Skip to content

Commit 5ec2ec2

Browse files
author
Andrés Soto
committed
refactor: TT-327 Solving code smells from sonarcloud
1 parent 87b1595 commit 5ec2ec2

File tree

8 files changed

+16
-25
lines changed

8 files changed

+16
-25
lines changed

src/app/modules/customer-management/components/projects/components/store/project.actions.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export enum ProjectActionTypes {
88
LOAD_CUSTOMER_PROJECTS = '[Projects] LOAD_CUSTOMER_PROJECTS',
99
LOAD_CUSTOMER_PROJECTS_SUCCESS = '[Projects] LOAD_CUSTOMER_PROJECTS_SUCCESS',
1010
LOAD_CUSTOMER_PROJECTS_FAIL = '[Projects] LOAD_CUSTOMER_PROJECTS_FAIL',
11-
LOAD_RECENT_PROJECTS = '[Projects] LOAD_RECENT_PROJECTS',
1211
LOAD_RECENT_PROJECTS_SUCCESS = '[Projects] LOAD_RECENT_PROJECTS_SUCCESS',
1312
LOAD_RECENT_PROJECTS_FAIL = '[Projects] LOAD_RECENT_PROJECTS_FAIL',
1413
CREATE_PROJECT = '[Projects] CREATE_PROJECT',
@@ -63,11 +62,6 @@ export class LoadCustomerProjectsFail implements Action {
6362
constructor(public error: string) {}
6463
}
6564

66-
export class LoadRecentProjects implements Action {
67-
public readonly type = ProjectActionTypes.LOAD_RECENT_PROJECTS;
68-
constructor() {}
69-
}
70-
7165
export class LoadRecentProjectsSuccess implements Action {
7266
readonly type = ProjectActionTypes.LOAD_RECENT_PROJECTS_SUCCESS;
7367
constructor(readonly payload: Project[]) {}
@@ -168,7 +162,6 @@ export type ProjectActions =
168162
| LoadCustomerProjects
169163
| LoadCustomerProjectsSuccess
170164
| LoadCustomerProjectsFail
171-
| LoadRecentProjects
172165
| LoadRecentProjectsSuccess
173166
| LoadRecentProjectsFail
174167
| CreateProject

src/app/modules/customer-management/components/projects/components/store/project.effects.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('ProjectEffects', () => {
5656
});
5757

5858
it('action type is LOAD_RECENT_PROJECTS_SUCCESS when service is executed sucessfully', async () => {
59-
actions$ = of({ type: ProjectActionTypes.LOAD_RECENT_PROJECTS });
59+
actions$ = of({ type: ProjectActionTypes.LOAD_PROJECTS });
6060
const serviceSpy = spyOn(service, 'getRecentProjects');
6161
serviceSpy.and.returnValue(of(projects));
6262

@@ -66,7 +66,7 @@ describe('ProjectEffects', () => {
6666
});
6767

6868
it('action type is LOAD_RECENT_PROJECTS_FAIL when service fail in execution', async () => {
69-
actions$ = of({ type: ProjectActionTypes.LOAD_RECENT_PROJECTS });
69+
actions$ = of({ type: ProjectActionTypes.LOAD_PROJECTS });
7070
const serviceSpy = spyOn(service, 'getRecentProjects');
7171
serviceSpy.and.returnValue(throwError({ error: { message: 'fail!' } }));
7272
spyOn(toastrService, 'error');

src/app/modules/customer-management/components/projects/components/store/project.effects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class ProjectEffects {
5151

5252
@Effect()
5353
loadRecentProjects$: Observable<Action> = this.actions$.pipe(
54-
ofType(actions.ProjectActionTypes.LOAD_RECENT_PROJECTS),
54+
ofType(actions.ProjectActionTypes.LOAD_PROJECTS),
5555
mergeMap(() =>
5656
this.projectService.getRecentProjects().pipe(
5757
map((projects) => {

src/app/modules/customer-management/components/projects/components/store/project.reducer.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ describe('projectReducer', () => {
4040
expect(state.customerProjects).toEqual([]);
4141
});
4242

43-
it('on LoadRecentProjects, isLoading is true', () => {
44-
const action = new actions.LoadRecentProjects();
45-
const state = projectReducer(initialState, action);
46-
expect(state.isLoading).toEqual(true);
47-
});
48-
4943
it('on LoadRecentProjectsSuccess, projectsFound are saved in the store', () => {
5044
const projectsFound: Project[] = [{ id: '1', name: 'abc', description: 'xxx', status: 'active' }];
5145
const newState = initialState;

src/app/modules/customer-management/components/projects/components/store/project.reducer.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ export const projectReducer = (state: ProjectState = initialState, action: Proje
6767
};
6868
}
6969

70-
case ProjectActionTypes.LOAD_RECENT_PROJECTS: {
71-
return {
72-
...state,
73-
isLoading: true,
74-
};
75-
}
7670
case ProjectActionTypes.LOAD_RECENT_PROJECTS_SUCCESS:
7771
return {
7872
...state,

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker';
2222

2323
import { DATE_FORMAT } from 'src/environments/environment';
2424
import { DATE_FORMAT_YEAR } from 'src/environments/environment';
25+
import { Project } from '../../models';
2526

2627
describe('DetailsFieldsComponent', () => {
2728
type Merged = TechnologyState & ProjectState & EntryState;
@@ -155,13 +156,22 @@ describe('DetailsFieldsComponent', () => {
155156
});
156157

157158
it('onClearedComponent project id and name are set to empty', () => {
158-
const search = {term: '', items: []};
159+
const search = {term: ''};
159160
component.onClearedComponent(search);
160161

161162
expect(component.project_id.value).toBe('');
162163
expect(component.project_name.value).toBe('');
163164
});
164165

166+
it('should change the listProjectsShowed to listProjects if search is not empty on onClearedComponent', () => {
167+
const search = {term: 'Ioet Inc.'};
168+
const listProjects: Project[] = [{ id: '1', name: 'abc', status: 'active' }];
169+
component.listProjects = listProjects;
170+
component.onClearedComponent(search);
171+
172+
expect(component.listProjectsShowed).toBe(component.listProjects);
173+
});
174+
165175
it('onSelectedProject project id and name are set using event data', () => {
166176
spyOn(component.entryForm, 'patchValue');
167177

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
158158
}
159159

160160
getRecentProjects(): void {
161-
this.store.dispatch(new projectActions.LoadRecentProjects());
161+
this.store.dispatch(new projectActions.LoadProjects());
162162
const recentProjects$ = this.store.pipe(select(getRecentProjects));
163163
recentProjects$.subscribe((projects) => {
164164
if (projects) {

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
6868
this.activities = response;
6969
});
7070

71-
this.store.dispatch(new actions.LoadRecentProjects());
71+
this.store.dispatch(new actions.LoadProjects());
7272
const recentProjects$ = this.store.pipe(select(getRecentProjects));
7373
this.recentProjectsSubscription = recentProjects$.subscribe((projects) => {
7474
if (projects) {

0 commit comments

Comments
 (0)