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,6 +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';

describe('CustomerTableListComponent', () => {
let component: CustomerListComponent;
Expand Down Expand Up @@ -65,6 +67,15 @@ describe('CustomerTableListComponent', () => {
expect(component.showCustomerForm).toBeTruthy();
});

it('onClick edit, dispatch clean Forms in project and project type', () => {
spyOn(store, 'dispatch');

component.editCustomer('1');

expect(store.dispatch).toHaveBeenCalledWith(new ResetProjectToEdit());
expect(store.dispatch).toHaveBeenCalledWith(new ResetProjectTypeToEdit());
});

it('onClick delete, dispatch DeleteCustomer', () => {
spyOn(store, 'dispatch');
component.idToDelete = '1';
Expand Down Expand Up @@ -121,7 +132,7 @@ describe('CustomerTableListComponent', () => {
const actionSubject = TestBed.inject(ActionsSubject);
const action = {
type: CustomerManagementActionTypes.LOAD_CUSTOMERS_SUCCESS,
payload: state.data
payload: state.data,
};
spyOn(component.dtElement.dtInstance, 'then');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ import {
CustomerManagementActionTypes,
DeleteCustomer,
LoadCustomers,
SetCustomerToEdit
SetCustomerToEdit,
} from './../../../../store/customer-management.actions';
import { ResetProjectToEdit } from '../../../projects/components/store/project.actions';
import { ResetProjectTypeToEdit } from '../../../projects-type/store';
@Component({
selector: 'app-customer-list',
templateUrl: './customer-list.component.html',
styleUrls: ['./customer-list.component.scss'],
})
export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {

@Input() showCustomerForm: boolean;
@Output() changeValueShowCustomerForm = new EventEmitter<boolean>();
@Input()
customers: Customer[] = [];
dtOptions: any = {};
dtTrigger: Subject<any> = new Subject();
@ViewChild(DataTableDirective, {static: false})
@ViewChild(DataTableDirective, { static: false })
dtElement: DataTableDirective;
loadCustomersSubscription: Subscription;
changeCustomerSubscription: Subscription;
Expand All @@ -40,33 +41,32 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
ngOnInit(): void {
this.dtOptions = {
scrollY: '290px',
paging: false
paging: false,
};
this.loadCustomersSubscription = this.actionsSubject$.pipe(
filter((action: any) => (
action.type === CustomerManagementActionTypes.LOAD_CUSTOMERS_SUCCESS
)
)
).subscribe((action) => {
this.customers = action.payload;
this.rerenderDataTable();
});
this.loadCustomersSubscription = this.actionsSubject$
.pipe(filter((action: any) => action.type === CustomerManagementActionTypes.LOAD_CUSTOMERS_SUCCESS))
.subscribe((action) => {
this.customers = action.payload;
this.rerenderDataTable();
});

this.changeCustomerSubscription = this.actionsSubject$.pipe(
filter((action: any) => (
action.type === CustomerManagementActionTypes.DELETE_CUSTOMER_SUCCESS ||
action.type === CustomerManagementActionTypes.UPDATE_CUSTOMER_SUCCESS ||
action.type === CustomerManagementActionTypes.CREATE_CUSTOMER_SUCCESS
this.changeCustomerSubscription = this.actionsSubject$
.pipe(
filter(
(action: any) =>
action.type === CustomerManagementActionTypes.DELETE_CUSTOMER_SUCCESS ||
action.type === CustomerManagementActionTypes.UPDATE_CUSTOMER_SUCCESS ||
action.type === CustomerManagementActionTypes.CREATE_CUSTOMER_SUCCESS
)
)
).subscribe((action) => {
this.store.dispatch(new LoadCustomers());
this.showCustomerForm = false;
});
.subscribe((action) => {
this.store.dispatch(new LoadCustomers());
this.showCustomerForm = false;
});
this.store.dispatch(new LoadCustomers());
}

ngAfterViewInit(): void {
ngAfterViewInit(): void {
this.rerenderDataTable();
}

Expand All @@ -80,6 +80,12 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
this.showCustomerForm = true;
this.changeValueShowCustomerForm.emit(this.showCustomerForm);
this.store.dispatch(new SetCustomerToEdit(customerId));
this.resetProjectFieldsToEdit();
}

private resetProjectFieldsToEdit() {
this.store.dispatch(new ResetProjectToEdit());
this.store.dispatch(new ResetProjectTypeToEdit());
}

deleteCustomer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ describe('InputProjectTypeComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CreateProjectTypeComponent],
providers: [
FormBuilder,
provideMockStore({ initialState: state })
],
providers: [FormBuilder, provideMockStore({ initialState: state })],
}).compileComponents();
}));

Expand Down Expand Up @@ -153,6 +150,14 @@ describe('InputProjectTypeComponent', () => {
expect(component.projectTypeForm.setValue).toHaveBeenCalledWith(projectTypeDataForm);
});

it('shoud reset Project Type Form before set the data to Edit', () => {
spyOn(component.projectTypeForm, 'reset');

component.setDataToUpdate(projectType);

expect(component.projectTypeForm.reset).toHaveBeenCalled();
});

it('should dispatch a ResetProjectTypeToEdit action', () => {
spyOn(store, 'dispatch');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {
customerId: string;
getCustomerIdSubscription: Subscription;

constructor(private formBuilder: FormBuilder,
private store: Store<ProjectTypeState>) {
constructor(private formBuilder: FormBuilder, private store: Store<ProjectTypeState>) {
this.projectTypeForm = this.formBuilder.group({
name: ['', Validators.required],
description: [''],
Expand All @@ -47,6 +46,7 @@ export class CreateProjectTypeComponent implements OnInit, OnDestroy {
}

setDataToUpdate(projectTypeData: ProjectType) {
this.projectTypeForm.reset();
if (projectTypeData) {
this.projectTypeForm.setValue({
name: projectTypeData.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ describe('InputProjectComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CreateProjectComponent],
providers: [
FormBuilder,
provideMockStore({ initialState: state })
],
providers: [FormBuilder, provideMockStore({ initialState: state })],
}).compileComponents();
}));

Expand Down Expand Up @@ -233,6 +230,14 @@ describe('InputProjectComponent', () => {
expect(component.projectForm.setValue).toHaveBeenCalledWith(projectForm);
});

it('shoud reset Project Form before set the data to Edit', () => {
spyOn(component.projectForm, 'reset');

component.setDataToUpdate(project);

expect(component.projectForm.reset).toHaveBeenCalled();
});

it('should dispatch a ResetActivityToEdit action', () => {
spyOn(store, 'dispatch');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class CreateProjectComponent implements OnInit, OnDestroy {
}

setDataToUpdate(projectData: Project) {
this.projectForm.reset();
if (projectData) {
this.projectForm.setValue({
name: projectData.name,
Expand Down