11import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
22
33import { ProjectManagementComponent } from './project-management.component' ;
4+ import { Project } from '../../../interfaces/project' ;
45
56describe ( 'ProjectManagementComponent' , ( ) => {
67 let component : ProjectManagementComponent ;
78 let fixture : ComponentFixture < ProjectManagementComponent > ;
9+ const projects : Project [ ] = [ {
10+ id : 1 ,
11+ name : 'app 1' ,
12+ details : 'It is a good app' ,
13+ status : 'inactive' ,
14+ completed : true
15+ } ,
16+ {
17+ id : 2 ,
18+ name : 'app 2' ,
19+ details : 'It is a good app' ,
20+ status : 'inactive' ,
21+ completed : false
22+ } ,
23+ {
24+ id : 3 ,
25+ name : 'app 3' ,
26+ details : 'It is a good app' ,
27+ status : 'active' ,
28+ completed : true
29+ }
30+ ] ;
831
932 beforeEach ( async ( ( ) => {
1033 TestBed . configureTestingModule ( {
@@ -17,9 +40,61 @@ describe('ProjectManagementComponent', () => {
1740 fixture = TestBed . createComponent ( ProjectManagementComponent ) ;
1841 component = fixture . componentInstance ;
1942 fixture . detectChanges ( ) ;
43+ component . projects = projects ;
2044 } ) ;
2145
2246 it ( 'should create' , ( ) => {
2347 expect ( component ) . toBeTruthy ( ) ;
2448 } ) ;
49+
50+ it ( 'should add a project #updateProject' , ( ) => {
51+ const project = {
52+ name : 'app 4' ,
53+ details : 'It is a good app' ,
54+ status : 'inactive' ,
55+ completed : true
56+ } ;
57+
58+ component . editedProjectId = null ;
59+ component . updateProject ( project ) ;
60+ expect ( component . projects . length ) . toEqual ( 4 ) ;
61+ } ) ;
62+
63+ it ( 'should edit a project #updateProject' , ( ) => {
64+ const project = {
65+ id : 1 ,
66+ name : 'app test' ,
67+ details : 'It is a excelent app' ,
68+ status : 'inactive' ,
69+ completed : true
70+ } ;
71+
72+ component . editedProjectId = 1 ;
73+ component . updateProject ( project ) ;
74+ expect ( component . projects . length ) . toEqual ( 3 ) ;
75+ expect ( component . projects [ 0 ] . name ) . toBe ( 'app test' ) ;
76+ expect ( component . projects [ 0 ] . details ) . toBe ( 'It is a excelent app' ) ;
77+ expect ( component . projects [ 0 ] . status ) . toBe ( 'inactive' ) ;
78+ expect ( component . projects [ 0 ] . completed ) . toBe ( true ) ;
79+ } ) ;
80+
81+ it ( 'should filter the project to edit #editProject' , ( ) => {
82+ const editProjectId = 2 ;
83+ component . editProject ( editProjectId ) ;
84+ expect ( component . project . name ) . toBe ( 'app 2' ) ;
85+ } ) ;
86+
87+ it ( 'should clean the project #cancelForm' , ( ) => {
88+ const project = {
89+ id : 1 ,
90+ name : 'app 1' ,
91+ details : 'It is a good app' ,
92+ status : 'inactive' ,
93+ completed : true
94+ } ;
95+
96+ component . project = project ;
97+ component . cancelForm ( ) ;
98+ expect ( component . project ) . toBe ( null ) ;
99+ } ) ;
25100} ) ;
0 commit comments