Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
} from 'src/app/modules/customer-management/store';
import { DataTablesModule } from 'angular-datatables';
import { ActionsSubject } from '@ngrx/store';
import { ResetProjectToEdit } from '../../../projects/components/store/project.actions';
import { ResetProjectTypeToEdit } from '../../../projects-type/store';
import { ResetProjectToEdit, SetProjectToEdit } from '../../../projects/components/store/project.actions';
import { ResetProjectTypeToEdit, SetProjectTypeToEdit } from '../../../projects-type/store';

describe('CustomerTableListComponent', () => {
let component: CustomerListComponent;
Expand Down Expand Up @@ -58,7 +58,6 @@ describe('CustomerTableListComponent', () => {
expect(store.dispatch).toHaveBeenCalledWith(new LoadCustomers());
});


it('Onclick Edit, if there are changes, the modal must be presented ', () => {
component.hasChange = true;
const expectMessage = 'Do you have changes in a client, do you want to discard them?';
Expand Down Expand Up @@ -86,6 +85,8 @@ describe('CustomerTableListComponent', () => {

component.editCustomer('1');

expect(store.dispatch).toHaveBeenCalledWith(new SetProjectToEdit(null));
expect(store.dispatch).toHaveBeenCalledWith(new SetProjectTypeToEdit(null));
expect(store.dispatch).toHaveBeenCalledWith(new ResetProjectToEdit());
expect(store.dispatch).toHaveBeenCalledWith(new ResetProjectTypeToEdit());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
LoadCustomers,
SetCustomerToEdit,
} from './../../../../store/customer-management.actions';
import { ResetProjectToEdit } from '../../../projects/components/store/project.actions';
import { ResetProjectTypeToEdit } from '../../../projects-type/store';
import { ResetProjectToEdit, SetProjectToEdit } from '../../../projects/components/store/project.actions';
import { ResetProjectTypeToEdit, SetProjectTypeToEdit } from '../../../projects-type/store';

@Component({
selector: 'app-customer-list',
templateUrl: './customer-list.component.html',
Expand Down Expand Up @@ -101,6 +102,8 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
}

private resetProjectFieldsToEdit() {
this.store.dispatch(new SetProjectTypeToEdit(null));
this.store.dispatch(new SetProjectToEdit(null));
this.store.dispatch(new ResetProjectToEdit());
this.store.dispatch(new ResetProjectTypeToEdit());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormBuilder } from '@angular/forms';
import { provideMockStore, MockStore } from '@ngrx/store/testing';

import { ReactiveFormsModule } from '@angular/forms';
import { CreateProjectTypeComponent } from './create-project-type.component';
import {
ProjectTypeState,
Expand Down Expand Up @@ -40,6 +40,7 @@ describe('InputProjectTypeComponent', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule],
declarations: [CreateProjectTypeComponent],
providers: [FormBuilder, provideMockStore({ initialState: state })],
}).compileComponents();
Expand Down Expand Up @@ -121,6 +122,15 @@ describe('InputProjectTypeComponent', () => {
expect(store.dispatch).toHaveBeenCalledWith(new CreateProjectType(projectTypeData));
});

it('should reset projectTypeForm if projectTypeIdToEdit is null', () => {

spyOn(component.projectTypeForm, 'reset');

store.overrideSelector(projectTypeIdToEdit, null);
store.refreshState();
expect(component.projectTypeForm.reset).toHaveBeenCalled();
});

it('should get name using projectTypeForm', () => {
spyOn(component.projectTypeForm, 'get');
// tslint:disable-next-line:no-unused-expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormBuilder, Validators, FormGroup } from '@angular/forms';
import { Store, select } from '@ngrx/store';

import { ProjectType } from '../../../../../shared/models';
import { ProjectTypeState } from '../../store';
import { projectTypeIdToEdit, ProjectTypeState } from '../../store';
import { CreateProjectType, ResetProjectTypeToEdit, UpdateProjectType, getProjectTypeById } from '../../store';
import { getCustomerId } from 'src/app/modules/customer-management/store/customer-management.selectors';
import { Subscription } from 'rxjs';
Expand All @@ -20,6 +20,7 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {
projectTypeToEdit: ProjectType;
customerId: string;
getCustomerIdSubscription: Subscription;
projectTypeIdToEditSubscription: Subscription;

constructor(private formBuilder: FormBuilder, private store: Store<ProjectTypeState>) {
this.projectTypeForm = this.formBuilder.group({
Expand All @@ -29,6 +30,13 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {
}

ngOnInit(): void {
const projectTypeIdToEdit$ = this.store.pipe(select(projectTypeIdToEdit));
this.projectTypeIdToEditSubscription = projectTypeIdToEdit$.subscribe((projectTypeId: string) => {
if (projectTypeId === null) {
this.projectTypeForm.reset();
}
});

const projectType$ = this.store.pipe(select(getProjectTypeById));
projectType$.subscribe((projectType) => {
this.projectTypeToEdit = projectType;
Expand Down Expand Up @@ -79,6 +87,7 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {

ngOnDestroy(): void {
this.getCustomerIdSubscription.unsubscribe();
this.projectTypeIdToEditSubscription.unsubscribe();
}

onInputChangeProjectType(searchValue: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { ProjectTypeState } from './project-type.reducers';
const getProjectTypeState = createFeatureSelector<ProjectTypeState>('projectType');

export const allProjectTypes = createSelector(getProjectTypeState, (state: ProjectTypeState) => {
return state.data;
return state?.data;
});

export const projectTypeIdToEdit = createSelector(getProjectTypeState, (state: ProjectTypeState) => {
return state.projectTypeIdToEdit;
return state?.projectTypeIdToEdit;
});

export const getProjectTypeById = createSelector(
Expand Down