This repository was archived by the owner on Feb 8, 2020. It is now read-only.

14 files changed

+184
-57
lines changed
Whitespace-only changes.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.content-area {
2+
margin-top: 25px;
3+
height: 93%;
4+
overflow-y: auto;
5+
}
6+
7+
.input-card {
8+
margin: 16px;
9+
}
10+
11+
mat-form-field {
12+
width: 100%;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<mat-toolbar color="primary">
2+
<mat-toolbar-row>
3+
<span>TODO App</span>
4+
</mat-toolbar-row>
5+
</mat-toolbar>
6+
<div class="content-area">
7+
<div class="input-card">
8+
<app-input (submit)="addItem($event)" [placeholder]="'What do you need to do?'" [maxLength]="250" [buttonEnabled]="true"
9+
[buttonText]="'Add'"></app-input>
10+
</div>
11+
<app-todo-list [items]="todos"></app-todo-list>
12+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {ComponentFixture, getTestBed, TestBed} from '@angular/core/testing';
2+
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
3+
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
4+
5+
import {MaterialModule} from '../../modules';
6+
import {TodoService} from '../../services/todo/todo.service';
7+
import {InputComponent} from '../input/input.component';
8+
import {TodoListComponent} from '../todo-list/todo-list.component';
9+
10+
import {AppComponent} from './app.component';
11+
12+
describe('AppComponent', () => {
13+
let component: AppComponent;
14+
let fixture: ComponentFixture<AppComponent>;
15+
16+
let todoService: TodoService;
17+
18+
beforeEach(() => {
19+
TestBed.configureTestingModule({
20+
declarations: [AppComponent, InputComponent, TodoListComponent],
21+
imports: [MaterialModule, FormsModule, ReactiveFormsModule, BrowserAnimationsModule]
22+
});
23+
24+
fixture = TestBed.createComponent(AppComponent);
25+
component = fixture.componentInstance;
26+
27+
todoService = getTestBed().get(TodoService);
28+
29+
fixture.detectChanges();
30+
});
31+
32+
it('should create the app', () => {
33+
expect(component).toBeTruthy();
34+
});
35+
36+
describe('addItem', () => {
37+
it('should call addTodo of TodoService', () => {
38+
const text: string = 'SomeText';
39+
const spy = spyOn(todoService, 'addTodo');
40+
41+
component.addItem(text);
42+
43+
expect(spy).toHaveBeenCalled();
44+
expect(spy).toHaveBeenCalledWith({text});
45+
});
46+
47+
it('should call getTodos of TodoService', () => {
48+
const text: string = 'SomeText';
49+
const spy = spyOn(todoService, 'getTodos');
50+
51+
component.addItem(text);
52+
53+
expect(spy).toHaveBeenCalled();
54+
});
55+
});
56+
57+
describe('getTodos', () => {
58+
it('should call getTodos of TodoService', () => {
59+
const spy = spyOn(todoService, 'getTodos');
60+
61+
component.getTodos();
62+
63+
expect(spy).toHaveBeenCalled();
64+
});
65+
});
66+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {TodoItem} from '../../models/todo-item.model';
3+
import {TodoService} from '../../services';
4+
5+
@Component({selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css']})
6+
export class AppComponent implements OnInit {
7+
newItemText: string = '';
8+
9+
todos: TodoItem[];
10+
11+
constructor(private todoService: TodoService) {}
12+
13+
ngOnInit(): void {}
14+
15+
addItem(text: string): void {
16+
this.todoService.addTodo({text});
17+
this.getTodos();
18+
}
19+
20+
getTodos(): void {
21+
this.todos = this.todoService.getTodos();
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export {AppComponent} from './app/app.component';
2+
export {InputComponent} from './input/input.component';
3+
export {TodoListComponent} from './todo-list/todo-list.component';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {} from './todo-item.model';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class TodoItem {
2+
done?: boolean;
3+
text: string;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {TodoService} from './todo/todo.service';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {getTestBed, TestBed} from '@angular/core/testing';
2+
3+
import {TodoItem} from '../../models/todo-item.model';
4+
5+
import {TodoService} from './todo.service';
6+
7+
describe('TodoService', () => {
8+
let service: TodoService;
9+
10+
beforeEach(() => {
11+
TestBed.configureTestingModule({});
12+
13+
service = getTestBed().get(TodoService);
14+
});
15+
16+
it('should be created', () => {
17+
expect(service).toBeTruthy();
18+
expect(service['todos']).toEqual([]);
19+
});
20+
21+
describe('addTodo', () => {
22+
it('should add todo to array', () => {
23+
const todo: TodoItem = {text: 'SomeTextINeedToDo'};
24+
25+
service.addTodo(todo);
26+
27+
expect(service['todos']).toEqual([todo]);
28+
});
29+
});
30+
31+
describe('getTodos', () => {
32+
it('should return the todos', () => {
33+
const todos: TodoItem[] = [{text: 'SomeTextINeedToDo'}];
34+
35+
service['todos'] = todos;
36+
37+
const result = service.getTodos();
38+
39+
expect(result).toEqual(todos);
40+
});
41+
});
42+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Injectable} from '@angular/core';
2+
import {TodoItem} from '../../models/todo-item.model';
3+
4+
@Injectable({providedIn: 'root'})
5+
export class TodoService {
6+
private todos: TodoItem[];
7+
8+
constructor() {
9+
this.todos = [];
10+
}
11+
12+
addTodo(todo: TodoItem): void {
13+
this.todos.push(todo);
14+
}
15+
16+
getTodos(): TodoItem[] {
17+
return this.todos;
18+
}
19+
}

0 commit comments

Comments
 (0)