Skip to content

Commit ca4edbe

Browse files
committed
Added tests
1 parent 78f4c0a commit ca4edbe

9 files changed

+606
-154
lines changed

cypress/integration/home.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
3+
describe('Home Page', () => {
4+
5+
beforeEach(() => {
6+
7+
cy.fixture('courses.json').as("coursesJSON");
8+
9+
cy.server();
10+
11+
cy.route('/api/courses', "@coursesJSON").as("courses");
12+
13+
cy.visit('/');
14+
15+
});
16+
17+
it('should display a list of courses', () => {
18+
19+
cy.contains("All Courses");
20+
21+
cy.wait('@courses');
22+
23+
cy.get("mat-card").should("have.length", 9);
24+
25+
});
26+
27+
it('should display the advanced courses', () => {
28+
29+
cy.get('.mat-tab-label').should("have.length", 2);
30+
31+
cy.get('.mat-tab-label').last().click();
32+
33+
cy.get('.mat-tab-body-active .mat-card-title').its('length').should("be.gt", 1);
34+
35+
cy.get('.mat-tab-body-active .mat-card-title').first()
36+
.should('contain', "Angular Security Course");
37+
38+
});
39+
40+
});

package-lock.json

Lines changed: 50 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"build:prod": "ng build --prod",
1515
"start:prod": "http-server ./dist -a localhost -p 4200",
1616
"build-and-start:prod": "run-s build:prod start:prod",
17+
"build_and-deploy:prod": "run-s build:prod start:prod",
1718
"e2e": "start-server-and-test build-and-start:prod http://localhost:4200 cypress:run"
1819
},
1920
"private": true,
@@ -31,7 +32,7 @@
3132
"@angular/router": "10.0.2",
3233
"body-parser": "^1.18.3",
3334
"core-js": "^2.4.1",
34-
"cypress": "^3.2.0",
35+
"cypress": "^3.8.3",
3536
"express": "^4.16.2",
3637
"http-server": "^0.12.1",
3738
"moment": "^2.22.2",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import {async, ComponentFixture, TestBed} 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+
16+
let component: CoursesCardListComponent;
17+
let fixture: ComponentFixture<CoursesCardListComponent>;
18+
let el: DebugElement;
19+
20+
beforeEach(async( () => {
21+
22+
TestBed.configureTestingModule({
23+
imports: [CoursesModule]
24+
})
25+
.compileComponents()
26+
.then(() => {
27+
28+
fixture = TestBed.createComponent(CoursesCardListComponent);
29+
component = fixture.componentInstance;
30+
el = fixture.debugElement;
31+
32+
});
33+
34+
}) );
35+
36+
37+
it("should create the component", () => {
38+
39+
expect(component).toBeTruthy();
40+
41+
});
42+
43+
44+
it("should display the course list", () => {
45+
46+
component.courses = setupCourses();
47+
48+
fixture.detectChanges();
49+
50+
const cards = el.queryAll(By.css(".course-card"));
51+
52+
expect(cards).toBeTruthy("Could not find cards");
53+
expect(cards.length).toBe(12, "Unexpected number of courses");
54+
55+
});
56+
57+
58+
it("should display the first course", () => {
59+
60+
component.courses = setupCourses();
61+
62+
fixture.detectChanges();
63+
64+
const course = component.courses[0];
65+
66+
const card = el.query(By.css(".course-card:first-child")),
67+
title = card.query(By.css("mat-card-title")),
68+
image = card.query(By.css("img"));
69+
70+
expect(card).toBeTruthy("Could not find course card");
71+
72+
expect(title.nativeElement.textContent).toBe(course.titles.description);
73+
74+
expect(image.nativeElement.src).toBe(course.iconUrl);
75+
76+
});
77+
78+
79+
});
80+
81+

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)