/
intermediate.component.spec.ts
203 lines (160 loc) · 7.08 KB
/
intermediate.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { Component, DebugElement, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatTooltipModule } from '@angular/material/tooltip';
import { By } from '@angular/platform-browser';
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
import { AppInitService, DspActionModule, DspApiConfigToken, DspApiConnectionToken, FilteredResources } from '@dasch-swiss/dsp-ui';
import { TestConfig } from 'test.config';
import { IntermediateComponent } from './intermediate.component';
/**
* test host component to simulate parent component
*/
@Component({
template: '<app-intermediate #intermediateView [resources]="resources"></app-intermediate>'
})
class OneSelectedResourcesComponent {
@ViewChild('intermediateView') intermediateComponent: IntermediateComponent;
resources: FilteredResources = {
'count': 1,
'resListIndex': [1],
'resInfo': [{
'id': 'http://rdfh.ch/0803/83616f8d8501',
'label': '65r'
}],
'selectionType': 'multiple'
};
constructor() { }
}
/**
* test host component to simulate parent component
*/
@Component({
template: '<app-intermediate #intermediateView [resources]="resources"></app-intermediate>'
})
class ThreeSelectedResourcesComponent {
@ViewChild('intermediateView') intermediateComponent: IntermediateComponent;
resources: FilteredResources = {
'count': 3,
'resListIndex': [3, 2, 1],
'resInfo': [
{
'id': 'http://rdfh.ch/0803/83616f8d8501',
'label': '65r'
},
{
'id': 'http://rdfh.ch/0803/71e0b9958a01',
'label': '76r'
},
{
'id': 'http://rdfh.ch/0803/683d5cd26f01',
'label': '17v'
},
],
'selectionType': 'multiple'
};
constructor() { }
}
describe('IntermediateComponent', () => {
let host1Component: OneSelectedResourcesComponent;
let host1Fixture: ComponentFixture<OneSelectedResourcesComponent>;
let host3Component: ThreeSelectedResourcesComponent;
let host3Fixture: ComponentFixture<ThreeSelectedResourcesComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [
IntermediateComponent,
OneSelectedResourcesComponent,
ThreeSelectedResourcesComponent
],
imports: [
DspActionModule,
MatButtonModule,
MatDialogModule,
MatIconModule,
MatTooltipModule
],
providers: [
AppInitService,
{
provide: DspApiConfigToken,
useValue: TestConfig.ApiConfig
},
{
provide: DspApiConnectionToken,
useValue: new KnoraApiConnection(TestConfig.ApiConfig)
}
]
}).compileComponents();
});
beforeEach(() => {
host1Fixture = TestBed.createComponent(OneSelectedResourcesComponent);
host1Component = host1Fixture.componentInstance;
host1Fixture.detectChanges();
expect(host1Component).toBeTruthy();
host3Fixture = TestBed.createComponent(ThreeSelectedResourcesComponent);
host3Component = host3Fixture.componentInstance;
host3Fixture.detectChanges();
expect(host3Component).toBeTruthy();
});
describe('One selected resource', () => {
it('expect count to be "1" and text to be "Resource Selected', () => {
expect(host1Component.intermediateComponent).toBeTruthy();
expect(host1Component.intermediateComponent.resources).toBeDefined();
const hostCompDe = host1Fixture.debugElement;
const count: DebugElement = hostCompDe.query(By.css('.count'));
expect(count.nativeElement.innerText).toEqual('1');
const text: DebugElement = hostCompDe.query(By.css('.text'));
expect(text.nativeElement.innerText).toEqual('Resource Selected');
});
it('expect compare button to be disabled', () => {
expect(host1Component.intermediateComponent).toBeTruthy();
expect(host1Component.intermediateComponent.resources).toBeDefined();
const hostCompDe = host1Fixture.debugElement;
const button: DebugElement = hostCompDe.query(By.css('.compare'));
expect(button.nativeElement.disabled).toBeTruthy();
});
it('expect no card stack', () => {
expect(host1Component.intermediateComponent).toBeTruthy();
expect(host1Component.intermediateComponent.resources).toBeDefined();
const hostCompDe = host1Fixture.debugElement;
const twoCards: DebugElement = hostCompDe.query(By.css('.two'));
expect(twoCards).toBeFalsy();
const threeCards: DebugElement = hostCompDe.query(By.css('.three'));
expect(threeCards).toBeFalsy();
const moreCards: DebugElement = hostCompDe.query(By.css('.more'));
expect(moreCards).toBeFalsy();
});
});
describe('Three selected resources', () => {
it('expect count to be "3" and text to be "Resources Selected', () => {
expect(host3Component.intermediateComponent).toBeTruthy();
expect(host3Component.intermediateComponent.resources).toBeDefined();
const hostCompDe = host3Fixture.debugElement;
const count: DebugElement = hostCompDe.query(By.css('.count'));
expect(count.nativeElement.innerText).toEqual('3');
const text: DebugElement = hostCompDe.query(By.css('.text'));
expect(text.nativeElement.innerText).toEqual('Resources Selected');
});
it('expect compare button to be enabled', () => {
expect(host3Component.intermediateComponent).toBeTruthy();
expect(host3Component.intermediateComponent.resources).toBeDefined();
const hostCompDe = host3Fixture.debugElement;
const button: DebugElement = hostCompDe.query(By.css('.compare'));
expect(button.nativeElement.disabled).toBeFalsy();
});
it('expect card stack of more than 2', () => {
expect(host3Component.intermediateComponent).toBeTruthy();
expect(host3Component.intermediateComponent.resources).toBeDefined();
const hostCompDe = host3Fixture.debugElement;
const twoCards: DebugElement = hostCompDe.query(By.css('.two'));
expect(twoCards.nativeElement).toBeDefined();
const threeCards: DebugElement = hostCompDe.query(By.css('.three'));
expect(threeCards.nativeElement).toBeDefined();
const moreCards: DebugElement = hostCompDe.query(By.css('.more'));
expect(moreCards).toBeFalsy();
});
});
});