This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
/
dataservices.component.spec.ts
127 lines (109 loc) · 4.94 KB
/
dataservices.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
123
124
125
126
127
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 { AppSettingsService } from "@core/app-settings.service";
import { CoreModule } from "@core/core.module";
import { DataservicesCardsComponent } from "@dataservices/dataservices-cards/dataservices-cards.component";
import { DataservicesListComponent } from "@dataservices/dataservices-list/dataservices-list.component";
import { DataservicesComponent } from "@dataservices/dataservices.component";
import { DataserviceService } from "@dataservices/shared/dataservice.service";
import { MockDataserviceService } from "@dataservices/shared/mock-dataservice.service";
import { MockVdbService } from "@dataservices/shared/mock-vdb.service";
import { VdbService } from "@dataservices/shared/vdb.service";
import { SqlControlComponent } from "@dataservices/sql-control/sql-control.component";
import { SharedModule } from "@shared/shared.module";
import { NgxDatatableModule } from "@swimlane/ngx-datatable";
import { CodemirrorModule } from "ng2-codemirror";
import { ModalModule } from "ngx-bootstrap";
import { PatternFlyNgModule } from "patternfly-ng";
describe("DataservicesComponent", () => {
let component: DataservicesComponent;
let fixture: ComponentFixture<DataservicesComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ CoreModule, FormsModule, HttpModule, ModalModule.forRoot(), PatternFlyNgModule,
RouterTestingModule, SharedModule, CodemirrorModule, NgxDatatableModule ],
declarations: [ DataservicesComponent, DataservicesListComponent, DataservicesCardsComponent, SqlControlComponent ],
providers: [
AppSettingsService,
{ provide: VdbService, useClass: MockVdbService }
]
});
// use mock service
TestBed.overrideComponent( DataservicesComponent, {
set: {
providers: [
{ provide: DataserviceService, useClass: MockDataserviceService },
]
}
});
fixture = TestBed.createComponent(DataservicesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it("should be created", () => {
expect(component).toBeTruthy();
});
it("should have Dataservices 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("Dataservices");
});
it("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 Dataservices", () => {
// Check component object
const dataservices = component.allDataservices;
expect(dataservices.length).toEqual(3);
// Check html has the same number of dataservice cards
const cardDebugElems = fixture.debugElement.queryAll(By.css(".dataservice-card-title"));
expect(cardDebugElems).toBeDefined();
expect(cardDebugElems.length).toEqual(3);
});
it("should have initial card layout", () => {
// app-dataservices-cards should be present
let debugEl = fixture.debugElement.query(By.css("app-dataservices-cards"));
const element = debugEl.nativeElement;
expect(element).toBeDefined();
// app-dataservices-list should not be present
debugEl = fixture.debugElement.query(By.css("app-dataservices-list"));
expect(debugEl).toBeNull();
});
it("should toggle layout", () => {
// Initial layout should be Card Layout
let cardDebugElem = fixture.debugElement.query(By.css("app-dataservices-cards"));
let listDebugElem = fixture.debugElement.query(By.css("app-dataservices-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-dataservices-cards"));
listDebugElem = fixture.debugElement.query(By.css("app-dataservices-list"));
expect(cardDebugElem).toBeNull();
expect(listDebugElem).toBeDefined();
const listElem = listDebugElem.nativeElement;
expect(listElem).toBeDefined();
});
it("should filter dataservices", () => {
// Expect 3 dataservices initially.
let dataservices = component.filteredDataservices;
expect(dataservices.length).toEqual(3);
// Set a name filter which satisfies none of the dataservices
component.nameFilter = "g";
component.filterDataservices();
fixture.detectChanges();
// Now expect 0 services match
dataservices = component.filteredDataservices;
expect(dataservices.length).toEqual(0);
});
});