/
switch-properties.component.spec.ts
118 lines (90 loc) · 3.39 KB
/
switch-properties.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
import { CommonModule } from '@angular/common';
import { Component, Inject, Input, OnInit, ViewChild } from '@angular/core';
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { CreateIntValue, CreateValue, MockOntology, ReadResource, ResourcePropertyDefinition } from '@dasch-swiss/dsp-js';
import { IntValueComponent } from '../../../values/int-value/int-value.component';
import { SwitchPropertiesComponent } from './switch-properties.component';
/**
* test host component to simulate parent component.
*/
@Component({
template: `
<app-switch-properties
#switchProps
[property]="property"
[parentResource]="parentResource"
[parentForm]="parentForm"
[formName]="property.label + '_' + index">
</app-switch-properties>`
})
class TestSwitchPropertiesParentComponent implements OnInit {
@ViewChild('switchProps') switchPropertiesComponent: SwitchPropertiesComponent;
property: ResourcePropertyDefinition;
parentResource: ReadResource;
parentForm: FormGroup;
formName: string;
ngOnInit() {
this.property = MockOntology.mockReadOntology(
'http://0.0.0.0:3333/ontology/0001/anything/v2'
).properties[
'http://0.0.0.0:3333/ontology/0001/anything/v2#hasInteger'
] as ResourcePropertyDefinition;
}
}
/**
* mock value component to use in tests.
*/
@Component({
selector: 'app-int-value'
})
class MockCreateIntValueComponent implements OnInit {
@ViewChild('createVal') createValueComponent: IntValueComponent;
@Input() parentForm: FormGroup;
@Input() formName: string;
@Input() mode;
@Input() displayValue;
form: FormGroup;
valueFormControl: FormControl;
constructor(@Inject(FormBuilder) private _fb: FormBuilder) { }
ngOnInit(): void {
this.valueFormControl = new FormControl(null, [Validators.required]);
this.form = this._fb.group({
test: this.valueFormControl
});
}
getNewValue(): CreateValue {
const createIntVal = new CreateIntValue();
createIntVal.int = 123;
return createIntVal;
}
updateCommentVisibility(): void { }
}
describe('SwitchPropertiesComponent', () => {
let testHostComponent: TestSwitchPropertiesParentComponent;
let testHostFixture: ComponentFixture<TestSwitchPropertiesParentComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
SwitchPropertiesComponent,
MockCreateIntValueComponent,
TestSwitchPropertiesParentComponent
],
providers: [
CommonModule,
FormBuilder
]
})
.compileComponents();
}));
beforeEach(() => {
testHostFixture = TestBed.createComponent(TestSwitchPropertiesParentComponent);
testHostComponent = testHostFixture.componentInstance;
testHostFixture.detectChanges();
expect(testHostComponent).toBeTruthy();
});
it('should create an IntValue component', () => {
expect(testHostComponent.switchPropertiesComponent.createValueComponent instanceof MockCreateIntValueComponent).toBe(true);
expect(testHostComponent.switchPropertiesComponent.createValueComponent.mode).toEqual('create');
});
});