-
Notifications
You must be signed in to change notification settings - Fork 238
/
card.component.spec.ts
94 lines (82 loc) 路 2.77 KB
/
card.component.spec.ts
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Component } from '@angular/core';
import { By } from '@angular/platform-browser';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { CardModule } from './card.module';
describe('CardComponent', () => {
let component;
let fixture: ComponentFixture<TestCardComponent>;
let cardEle;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [TestCardComponent],
imports: [CardModule]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TestCardComponent);
component = fixture.componentInstance;
cardEle = fixture.debugElement.query(By.css('Card'));
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('full work', () => {
expect(cardEle.nativeElement.classList).toContain('am-card');
component.full = true;
fixture.detectChanges();
expect(cardEle.nativeElement.classList).toContain('am-card-full');
});
it('header title work', () => {
expect(cardEle.nativeElement.querySelector('.am-card-header-content').innerText).toEqual(component.title);
});
it('header thumb work', () => {
expect(cardEle.nativeElement.querySelector('img').src).toEqual(component.thumb);
});
it('header thumbStyle work', () => {
expect(cardEle.nativeElement.querySelector('img').style.width).toContain(component.thumbStyle.width);
});
it('header extra work', () => {
expect(cardEle.nativeElement.querySelector('.am-card-header-extra').firstElementChild.innerText).toContain(
'this is extra'
);
});
it('footer content work', () => {
expect(cardEle.nativeElement.querySelector('.am-card-footer-content').innerText).toEqual(component.content);
});
it('footer extra work', () => {
expect(cardEle.nativeElement.querySelector('.am-card-footer-extra').firstElementChild.innerText).toContain(
'extra footer content'
);
});
});
@Component({
selector: 'test-card',
template: `
<Card [full]="full">
<CardHeader [title]="title" [thumb]="thumb" [thumbStyle]="thumbStyle" [extra]="extra">
<ng-template #extra>
<span>this is extra</span>
</ng-template>
</CardHeader>
<CardBody>
<div>This is content of Card</div>
</CardBody>
<CardFooter [content]="content" [extra]="footerExtra">
<ng-template #footerExtra>
<div>extra footer content</div>
</ng-template>
</CardFooter>
</Card>
`
})
export class TestCardComponent {
full: boolean = false;
title: string = 'This is title';
thumb: string = 'https://gw.alipayobjects.com/zos/rmsportal/MRhHctKOineMbKAZslML.jpg';
thumbStyle: object = {
width: '32px',
height: '32px'
};
content: string = 'footer content';
}