blob: bde9a9a00b239f890fe1674f9e7430aec765e917 (
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
54
55
56
57
58
59
60
61
62
63
64
65
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { configureTestBed } from '~/testing/unit-test-helper';
import { InfoCardComponent } from './info-card.component';
describe('InfoCardComponent', () => {
let component: InfoCardComponent;
let fixture: ComponentFixture<InfoCardComponent>;
configureTestBed({
imports: [RouterTestingModule],
declarations: [InfoCardComponent]
});
beforeEach(() => {
fixture = TestBed.createComponent(InfoCardComponent);
component = fixture.componentInstance;
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('Setting cardTitle makes title visible', () => {
const cardTitle = 'Card Title';
component.cardTitle = cardTitle;
fixture.detectChanges();
const titleDiv = fixture.debugElement.nativeElement.querySelector('.card-title');
expect(titleDiv.textContent).toContain(cardTitle);
});
it('Setting link makes anchor visible', () => {
const cardTitle = 'Card Title';
const link = '/dashboard';
component.cardTitle = cardTitle;
component.link = link;
fixture.detectChanges();
const anchor = fixture.debugElement.nativeElement
.querySelector('.card-title')
.querySelector('a');
expect(anchor.textContent).toContain(cardTitle);
expect(anchor.href).toBe(`http://localhost${link}`);
});
it('Setting cardClass makes class set', () => {
const cardClass = 'my-css-card-class';
component.cardClass = cardClass;
fixture.detectChanges();
const card = fixture.debugElement.nativeElement.querySelector(`.card.${cardClass}`);
expect(card).toBeTruthy();
});
it('Setting contentClass makes class set', () => {
const contentClass = 'my-css-content-class';
component.contentClass = contentClass;
fixture.detectChanges();
const card = fixture.debugElement.nativeElement.querySelector(`.card-body .${contentClass}`);
expect(card).toBeTruthy();
});
});
|