Skip to content

Commit 6915493

Browse files
committed
create test
1 parent c5a1f45 commit 6915493

File tree

3 files changed

+80
-8
lines changed

3 files changed

+80
-8
lines changed

src/app/app.component.spec.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,4 @@ describe('AppComponent', () => {
2525
const app = fixture.componentInstance;
2626
expect(app.title).toEqual('time-tracker');
2727
});
28-
29-
it('should render title', () => {
30-
const fixture = TestBed.createComponent(AppComponent);
31-
fixture.detectChanges();
32-
const compiled = fixture.nativeElement;
33-
expect(compiled.querySelector('.content span').textContent).toContain('time-tracker app is running!');
34-
});
3528
});

src/app/components/options-sidebar/project-management/project-management.component.spec.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { ProjectManagementComponent } from './project-management.component';
4+
import { Project } from '../../../interfaces/project';
45

56
describe('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
});

src/app/components/shared/create-project/create-project.component.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { CreateProjectComponent } from './create-project.component';
4+
import { Validators, FormBuilder } from '@angular/forms';
45

56
describe('CreateProjectComponent', () => {
67
let component: CreateProjectComponent;
78
let fixture: ComponentFixture<CreateProjectComponent>;
89

910
beforeEach(async(() => {
1011
TestBed.configureTestingModule({
11-
declarations: [ CreateProjectComponent ]
12+
declarations: [ CreateProjectComponent ],
13+
providers: [
14+
FormBuilder
15+
],
1216
})
1317
.compileComponents();
1418
}));

0 commit comments

Comments
 (0)