This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
connections.component.spec.ts
122 lines (104 loc) · 4.78 KB
/
connections.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
import { FormsModule } from "@angular/forms";
import { HttpModule } from "@angular/http";
import { By } from "@angular/platform-browser";
import { RouterTestingModule } from "@angular/router/testing";
import { ConnectionsCardsComponent } from "@connections/connections-cards/connections-cards.component";
import { ConnectionsListComponent } from "@connections/connections-list/connections-list.component";
import { ConnectionsComponent } from "@connections/connections.component";
import { ConnectionService } from "@connections/shared/connection.service";
import { MockConnectionService } from "@connections/shared/mock-connection.service";
import { CoreModule } from "@core/core.module";
import { SharedModule } from "@shared/shared.module";
import { ModalModule } from "ngx-bootstrap";
describe("ConnectionsComponent", () => {
let component: ConnectionsComponent;
let fixture: ComponentFixture<ConnectionsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ CoreModule, FormsModule, HttpModule, ModalModule.forRoot(), RouterTestingModule, SharedModule ],
declarations: [ ConnectionsComponent, ConnectionsListComponent, ConnectionsCardsComponent ]
});
// use mock service
TestBed.overrideComponent( ConnectionsComponent, {
set: {
providers: [
{ provide: ConnectionService, useClass: MockConnectionService },
]
}
});
fixture = TestBed.createComponent(ConnectionsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it("should be created", () => {
console.log("========== [ConnectionsComponent] should be created");
expect(component).toBeTruthy();
});
it("should have Connections Title", () => {
console.log("========== [ConnectionsComponent] should have Connections Title");
// query for the title <h2> by CSS element selector
const de = fixture.debugElement.query(By.css("h2"));
const el = de.nativeElement;
expect(el.textContent).toEqual("Connections");
});
it("should have Toolbar", () => {
console.log("========== [ConnectionsComponent] should have Toolbar");
// query for the toolbar by css classname
const de = fixture.debugElement.query(By.css(".toolbar-pf"));
expect(de).toBeDefined();
});
it("should have Connections", () => {
console.log("========== [ConnectionsComponent] should have Connections");
// Check component object
const connections = component.allConnections;
expect(connections.length).toEqual(3);
// Check html has the same number of connection cards
const cardDebugElems = fixture.debugElement.queryAll(By.css(".connection-card-title"));
expect(cardDebugElems).toBeDefined();
expect(cardDebugElems.length).toEqual(3);
});
it("should have initial card layout", () => {
console.log("========== [ConnectionsComponent] should have initial card layout");
// app-connections-cards should be present
let debugEl = fixture.debugElement.query(By.css("app-connections-cards"));
const element = debugEl.nativeElement;
expect(element).toBeDefined();
// app-connections-list should not be present
debugEl = fixture.debugElement.query(By.css("app-connections-list"));
expect(debugEl).toBeNull();
});
it("should toggle layout", () => {
console.log("========== [ConnectionsComponent] should toggle layout");
// Initial layout should be Card Layout
let cardDebugElem = fixture.debugElement.query(By.css("app-connections-cards"));
let listDebugElem = fixture.debugElement.query(By.css("app-connections-list"));
expect(cardDebugElem).toBeDefined();
expect(listDebugElem).toBeNull();
const cardElem = cardDebugElem.nativeElement;
expect(cardElem).toBeDefined();
// Change the layout to ListLayout
component.setListLayout();
fixture.detectChanges();
// Verify that the layout has changed
cardDebugElem = fixture.debugElement.query(By.css("app-connections-cards"));
listDebugElem = fixture.debugElement.query(By.css("app-connections-list"));
expect(cardDebugElem).toBeNull();
expect(listDebugElem).toBeDefined();
const listElem = listDebugElem.nativeElement;
expect(listElem).toBeDefined();
});
it("should filter connections", () => {
console.log("========== [ConnectionsComponent] should filter connections");
// Expect 3 connections initially.
let connections = component.filteredConnections;
expect(connections.length).toEqual(3);
// Set a name filter which satisfies none of the connections
component.nameFilter = "g";
component.filterConnections();
fixture.detectChanges();
// Now expect 0 connections match
connections = component.filteredConnections;
expect(connections.length).toEqual(0);
});
});