Newer
Older
import { Component, Input } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CriteriaByFamilyComponent } from './criteria-by-family.component';
import { Option } from '../../../../metamodel/models';
import { Criterion, FieldCriterion, SvomKeyword } from '../../../store/models';
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
describe('[Instance][Search][Component][Criteria] CriteriaByFamilyComponent', () => {
@Component({ selector: 'app-field', template: '' })
class FieldStubComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input() placeholder: string;
@Input() attributeType: string;
@Input() criterion: Criterion;
@Input() advancedForm: boolean;
}
@Component({ selector: 'app-between', template: '' })
class BetweenStubComponent {
@Input() id: number;
@Input() label: string;
@Input() placeholderMin: string;
@Input() placeholderMax: string;
@Input() criterion: Criterion;
}
@Component({ selector: 'app-select', template: '' })
class SelectStubComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input() options: Option[];
@Input() criterion: Criterion;
@Input() advancedForm: boolean;
}
@Component({ selector: 'app-select-multiple', template: '' })
class SelectMultipleStubComponent {
@Input() id: number;
@Input() label: string;
@Input() options: Option[];
@Input() criterion: Criterion;
}
@Component({ selector: 'app-datalist', template: '' })
class DatalistStubComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input() placeholder: string;
@Input() options: Option[];
@Input() criterion: Criterion;
@Input() advancedForm: boolean;
}
@Component({ selector: 'app-list', template: '' })
class ListStubComponent {
@Input() id: number;
@Input() label: string;
@Input() placeholder: string;
@Input() criterion: Criterion;
}
@Component({ selector: 'app-radio', template: '' })
class RadioStubComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input() options: Option[];
@Input() criterion: Criterion;
}
@Component({ selector: 'app-checkbox', template: '' })
class CheckboxStubComponent {
@Input() id: number;
@Input() label: string;
@Input() options: Option[];
@Input() criterion: Criterion;
}
@Component({ selector: 'app-date', template: '' })
class DateStubComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input() placeholder: string;
@Input() criterion: Criterion;
@Input() advancedForm: boolean;
}
@Component({ selector: 'app-between-date', template: '' })
class BetweenDateStubComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input() criterion: Criterion;
}
@Component({ selector: 'app-time', template: '' })
class TimeStubComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input() criterion: Criterion;
@Input() advancedForm: boolean;
}
@Component({ selector: 'app-datetime', template: '' })
class DatetimeStubComponent {
@Input() id: number;
@Input() operator: string;
@Input() label: string;
@Input() criterion: Criterion;
@Input() advancedForm: boolean;
}
@Component({ selector: 'app-json-criteria', template: '' })
class JsonStubComponent {
@Input() id: number;
@Input() label: string;
@Input() criterion: Criterion;
}
@Component({ selector: 'app-svom-json-kw-criteria', template: '' })
class SvomJsonStubKwComponent {
@Input() id: number;
@Input() label: string;
@Input() criterion: Criterion;
@Input() criteriaList: Criterion[];
@Input() svomKeywords: SvomKeyword[];
}
let component: CriteriaByFamilyComponent;
let fixture: ComponentFixture<CriteriaByFamilyComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
CriteriaByFamilyComponent,
FieldStubComponent,
BetweenStubComponent,
SelectStubComponent,
SelectMultipleStubComponent,
DatalistStubComponent,
ListStubComponent,
RadioStubComponent,
CheckboxStubComponent,
DateStubComponent,
BetweenDateStubComponent,
TimeStubComponent,
DatetimeStubComponent,
JsonStubComponent,
SvomJsonStubKwComponent
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
204
205
206
207
208
209
210
211
212
213
214
]
});
fixture = TestBed.createComponent(CriteriaByFamilyComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('#getOptions(attribute) should return options of attribute', () => {
component.attributeList = [
{
id: 1,
name: 'name_one',
label: 'label_one',
form_label: 'form_label_one',
description: 'description_one',
output_display: 2,
criteria_display: 2,
search_flag: 'ID',
search_type: 'field',
operator: '=',
type: 'integer',
display_detail: 2,
options: [
{ label: 'Three', value: 'three', display: 3 },
{ label: 'One', value: 'one', display: 1 },
{ label: 'Two', value: 'two', display: 2 }
]
}
];
const attributeId = 1;
const options: Option[] = component.getOptions(attributeId);
expect(options.length).toBe(3)
});
it('#getCriterion(criterionId) should return correct criterion', () => {
component.criteriaList = [
{ 'id': 1, 'type': 'field', 'operator': 'eq', 'value': 'one' } as FieldCriterion,
{ 'id': 2, 'type': 'field', 'operator': 'eq', 'value': 'two' } as FieldCriterion
];
const criterionId = 1;
const criterion = component.getCriterion(criterionId) as FieldCriterion;
expect(criterion.value).toBe('one');
});
it('raises the add criterion event when clicked', () => {
const criterion = { id: 1, type: 'field', operator: 'eq', value: 'test' } as FieldCriterion;
component.addCriterion.subscribe((event: FieldCriterion) => expect(event).toEqual(criterion));
component.emitAdd(criterion);
});
it('raises the delete criterion event when clicked', () => {
const criterionId = 1;
component.deleteCriterion.subscribe((event: number) => expect(event).toEqual(1));
component.emitDelete(criterionId);
});
});