-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathselect-form.spec.ts
104 lines (87 loc) · 2.94 KB
/
select-form.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
import {
FormControl,
FormGroup,
FormsModule,
ReactiveFormsModule,
} from '@angular/forms';
import {
ApplicationInitStatus,
Component,
CUSTOM_ELEMENTS_SCHEMA,
} from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { IxModule } from '@siemens/ix-angular';
import { By } from '@angular/platform-browser';
import { waitForHydration } from '../utils/wait-for-hydration';
import { checkForError } from '../utils/check-for-error';
@Component({
selector: 'ix-example-select-form',
template: `
<form [formGroup]="form">
<ix-select formControlName="select">
<ix-select-item label="Item 1" value="1"></ix-select-item>
<ix-select-item label="Item 2" value="2"></ix-select-item>
<ix-select-item label="Item 3" value="3"></ix-select-item>
<ix-select-item label="Item 4" value="4"></ix-select-item>
</ix-select>
</form>
<h1>TypeError-Example</h1>
<ix-select [value]="value">
<ix-select-item
*ngFor="let item of selection"
[label]="item"
[value]="item"
></ix-select-item>
</ix-select>
`,
})
class SelectFormComponent {
public form = new FormGroup({ select: new FormControl('1') });
value = '3';
selection = ['3', '4', '5'];
public updateSelection() {
this.value = '6';
this.selection = ['6', '7', '8'];
}
}
describe('SelectFormComponent', () => {
let component: SelectFormComponent;
let fixture: ComponentFixture<SelectFormComponent>;
let consoleSpy: jasmine.Spy;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [SelectFormComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [FormsModule, ReactiveFormsModule, IxModule.forRoot()],
}).compileComponents();
fixture = TestBed.createComponent(SelectFormComponent);
component = fixture.componentInstance;
consoleSpy = spyOn(console, 'error').and.callThrough();
fixture.detectChanges();
});
beforeEach(async () => {
// until https://github.com/angular/angular/issues/24218 is fixed
await TestBed.inject(ApplicationInitStatus).donePromise;
});
it('should change the form control value', async () => {
const select = fixture.debugElement.query(
By.css('ix-select[formControlName="select"]')
);
await waitForHydration(select.nativeElement);
component.form.get('select')!.setValue('2');
fixture.detectChanges();
expect(select.nativeElement.value).toBe('2');
expect(component).toBeDefined();
});
it('should change the input value and check for errors', async () => {
const select = fixture.debugElement.query(
By.css('ix-select:not([formControlName="select"])')
);
await waitForHydration(select.nativeElement);
component.updateSelection();
fixture.detectChanges();
expect(checkForError(consoleSpy, 'TypeError')).toBe(false);
expect(select.nativeElement.value).toBe('6');
expect(component).toBeDefined();
});
});