Skip to content

Commit 6ad18f5

Browse files
committed
fix: #177 fix projects creation test
1 parent 0acb6cb commit 6ad18f5

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

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

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,77 @@ describe('InputProjectComponent', () => {
109109
expect(store.dispatch).toHaveBeenCalledWith(new UpdateProject(projectUpdated));
110110
});
111111

112+
it('should reset form #onSubmit and dispatch UpdateProject action with null project_type_id', () => {
113+
const currentState = {
114+
data: [project],
115+
isLoading: false,
116+
message: '',
117+
projectToEdit: project,
118+
};
119+
120+
const dataForm = {
121+
name: 'Test',
122+
description: 'xxx',
123+
project_type_id: '',
124+
};
125+
126+
getProjectToEditMock = store.overrideSelector(getProjectToEdit, currentState.projectToEdit);
127+
component.projectToEdit = getProjectToEditMock;
128+
129+
const projectUpdated = {
130+
id: component.projectToEdit.id,
131+
name: 'Test',
132+
description: 'xxx',
133+
project_type_id: null,
134+
};
135+
136+
component.projectToEditSubscription = new Subscription();
137+
component.projectTypesSubscription = new Subscription();
138+
spyOn(component.projectForm, 'reset');
139+
spyOn(store, 'dispatch');
140+
const subscription = spyOn(component.projectToEditSubscription, 'unsubscribe');
141+
const projectTypeSubscription = spyOn(component.projectTypesSubscription, 'unsubscribe');
142+
143+
component.onSubmit(dataForm);
144+
component.ngOnDestroy();
145+
146+
expect(subscription).toHaveBeenCalledTimes(1);
147+
expect(projectTypeSubscription).toHaveBeenCalledTimes(1);
148+
expect(dataForm.project_type_id).toBe(null);
149+
expect(component.projectForm.reset).toHaveBeenCalled();
150+
expect(store.dispatch).toHaveBeenCalledTimes(1);
151+
expect(store.dispatch).toHaveBeenCalledWith(new UpdateProject(projectUpdated));
152+
});
153+
112154
it('should reset form onSubmit and dispatch CreateProject action', () => {
113155
component.projectToEdit = undefined;
114156

115157
spyOn(component.projectForm, 'reset');
116158
spyOn(store, 'dispatch');
117159

118-
component.onSubmit(project);
160+
component.onSubmit(projectForm);
161+
162+
expect(component.projectForm.reset).toHaveBeenCalled();
163+
expect(store.dispatch).toHaveBeenCalledTimes(1);
164+
expect(store.dispatch).toHaveBeenCalledWith(new CreateProject(projectForm));
165+
});
166+
167+
it('should reset form onSubmit and dispatch CreateProject action with null project_type_id', () => {
168+
const dataForm = {
169+
name: 'Test',
170+
description: 'xxx',
171+
project_type_id: '',
172+
};
173+
component.projectToEdit = undefined;
174+
175+
spyOn(component.projectForm, 'reset');
176+
spyOn(store, 'dispatch');
119177

178+
component.onSubmit(dataForm);
179+
expect(dataForm.project_type_id).toBe(null);
120180
expect(component.projectForm.reset).toHaveBeenCalled();
121181
expect(store.dispatch).toHaveBeenCalledTimes(1);
122-
expect(store.dispatch).toHaveBeenCalledWith(new CreateProject(project));
182+
expect(store.dispatch).toHaveBeenCalledWith(new CreateProject(dataForm));
123183
});
124184

125185
it('should set data in projectForm', () => {

src/app/modules/shared/models/project.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface Project {
2-
id: string;
2+
id?: string;
33
customer_id?: string;
44
name: string;
55
description?: string;

0 commit comments

Comments
 (0)