-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathselect.component.spec.ts
More file actions
91 lines (81 loc) · 2.51 KB
/
Copy pathselect.component.spec.ts
File metadata and controls
91 lines (81 loc) · 2.51 KB
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
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SelectDisplayComponent } from './select.component';
describe('SelectDisplayComponent', () => {
let component: SelectDisplayComponent;
let fixture: ComponentFixture<SelectDisplayComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SelectDisplayComponent],
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(SelectDisplayComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should display option label from widget params', () => {
fixture.componentRef.setInput('value', 'opt1');
fixture.componentRef.setInput('widgetStructure', {
widget_params: {
options: [
{ value: 'opt1', label: 'Option One' },
{ value: 'opt2', label: 'Option Two' },
],
},
});
component.ngOnInit();
fixture.detectChanges();
expect(component.displayValue).toBe('Option One');
});
it('should display raw value when no options match', () => {
fixture.componentRef.setInput('value', 'unknown');
fixture.componentRef.setInput('widgetStructure', {
widget_params: {
options: [{ value: 'opt1', label: 'Option One' }],
},
});
component.ngOnInit();
fixture.detectChanges();
expect(component.displayValue).toBe('unknown');
});
it('should display option label when value is 0', () => {
fixture.componentRef.setInput('value', 0);
fixture.componentRef.setInput('widgetStructure', {
widget_params: {
options: [
{ value: 0, label: 'Zero' },
{ value: 1, label: 'One' },
],
},
});
component.ngOnInit();
fixture.detectChanges();
expect(component.displayValue).toBe('Zero');
});
it('should display em dash when value is null', () => {
fixture.componentRef.setInput('value', null);
component.ngOnInit();
fixture.detectChanges();
expect(component.displayValue).toBe('—');
});
it('should display em dash when value is undefined', () => {
fixture.componentRef.setInput('value', undefined);
component.ngOnInit();
fixture.detectChanges();
expect(component.displayValue).toBe('—');
});
it('should display empty string value as raw, not dash', () => {
fixture.componentRef.setInput('value', '');
fixture.componentRef.setInput('widgetStructure', {
widget_params: {
options: [{ value: 'opt1', label: 'Option One' }],
},
});
component.ngOnInit();
fixture.detectChanges();
expect(component.displayValue).toBe('');
});
});