Skip to content

Commit 8ebc8e9

Browse files
committed
presentation component testing complete
1 parent 6a60524 commit 8ebc8e9

File tree

2 files changed

+66
-40
lines changed

2 files changed

+66
-40
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
2+
import {CoursesCardListComponent} from './courses-card-list.component';
3+
import {CoursesModule} from '../courses.module';
4+
import {COURSES} from '../../../../server/db-data';
5+
import {DebugElement} from '@angular/core';
6+
import {By} from '@angular/platform-browser';
7+
import {sortCoursesBySeqNo} from '../home/sort-course-by-seq';
8+
import {Course} from '../model/course';
9+
import {setupCourses} from '../common/setup-test-data';
10+
11+
12+
13+
14+
describe('CoursesCardListComponent', () => {
15+
let component: CoursesCardListComponent;
16+
let fixture: ComponentFixture<CoursesCardListComponent>;
17+
let el: DebugElement;
18+
19+
beforeEach(waitForAsync( () => {
20+
TestBed.configureTestingModule({
21+
imports: [
22+
CoursesModule
23+
]
24+
})
25+
.compileComponents()
26+
.then(() => {
27+
fixture = TestBed.createComponent(CoursesCardListComponent);
28+
component = fixture.componentInstance;
29+
el = fixture.debugElement;
30+
});
31+
}));
32+
33+
it('should create the component', () => {
34+
expect(component).toBeTruthy();
35+
});
36+
37+
38+
it('should display the course list', () => {
39+
component.courses = setupCourses();
40+
fixture.detectChanges();
41+
const cards = el.queryAll(By.css('.course-card'));
42+
expect(cards).toBeTruthy('Could not find cards');
43+
expect(cards.length).toBe(12, 'Unexpected number of courses');
44+
});
45+
46+
47+
it('should display the first course', () => {
48+
component.courses = setupCourses();
49+
fixture.detectChanges();
50+
const course = component.courses[0];
51+
const card = el.query(By.css('.course-card:first-child'));
52+
const title = card.query(By.css('mat-card-title'));
53+
const image = card.query(By.css('img'));
54+
expect(card).toBeTruthy('Could not find course card');
55+
expect(title.nativeElement.textContent).toBe(course.titles.description);
56+
expect(image.nativeElement.src).toBe(course.iconUrl);
57+
58+
59+
60+
61+
});
62+
63+
64+
});
65+
66+

src/app/courses/courses-card-list/courses-card-list.component.ts.TODO

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)