blob: 277eca2348473af73a12f269f547988bd12b40fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TodoItemComponent } from './todo-item.component';
import { WorkItem } from '../todo-list-page/todo-list.service';
import { By } from '@angular/platform-browser';
import { NO_ERRORS_SCHEMA } from '@angular/core';
describe('TodoItemComponent', () => {
let component: TodoItemComponent;
let fixture: ComponentFixture<TodoItemComponent>;
let mockWorkItem: WorkItem;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TodoItemComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
mockWorkItem = {
id: 0,
title: 'Title',
isCompleted: true,
detailUrl: '/detail',
iconUrl: '/icon'
};
fixture = TestBed.createComponent(TodoItemComponent);
component = fixture.componentInstance;
component.item = mockWorkItem;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should set icon', () => {
expect(fixture.debugElement.query(By.css('img.item-icon')).properties['src']).toBe(mockWorkItem.iconUrl);
});
it('should set title', () => {
expect((fixture.debugElement.query(By.css('span.item-title')).nativeElement as HTMLSpanElement).textContent).toBe(
mockWorkItem.id + '. ' + mockWorkItem.title
);
});
it('should set detail link', () => {
expect(fixture.debugElement.query(By.css('a.item-detail-button')).properties['href']).toBe(mockWorkItem.detailUrl);
});
});
|