1
+ // NG
2
+ import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
3
+ // App
4
+ import { NovoSelectElement } from './Select' ;
5
+ import { NovoSelectModule } from './Select.module' ;
6
+ import { NovoLabelService } from 'novo-elements/services' ;
7
+ import { NovoOptionModule } from 'novo-elements/elements/common' ;
8
+ import { Component , ViewChild } from '@angular/core' ;
9
+ import { FormControl , FormGroup , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
10
+
11
+ @Component ( {
12
+ template : `
13
+ <form [formGroup]="form">
14
+ <novo-select #select extupdatefix formControlName="value" multiple>
15
+ <novo-option value="1">One</novo-option>
16
+ <novo-option value="2">Two</novo-option>
17
+ <novo-option value="3">Three</novo-option>
18
+ </novo-select>
19
+ </form>`
20
+ } )
21
+ class FixedSelectComponent {
22
+ @ViewChild ( 'select' )
23
+ select : NovoSelectElement ;
24
+
25
+ form = new FormGroup ( {
26
+ value : new FormControl ( [ '2' ] )
27
+ } ) ;
28
+ }
29
+
30
+ describe ( 'Directive: NovoSelectExtUpdateFix' , ( ) => {
31
+ let fixture : ComponentFixture < FixedSelectComponent > ;
32
+ let comp : FixedSelectComponent ;
33
+
34
+ beforeEach ( waitForAsync ( ( ) => {
35
+ TestBed . configureTestingModule ( {
36
+ imports : [ NovoSelectModule , NovoOptionModule , FormsModule , ReactiveFormsModule ] ,
37
+ providers : [ NovoLabelService ] ,
38
+ declarations : [ FixedSelectComponent ] ,
39
+ } ) . compileComponents ( ) ;
40
+ fixture = TestBed . createComponent ( FixedSelectComponent ) ;
41
+ comp = fixture . debugElement . componentInstance ;
42
+ fixture . detectChanges ( ) ;
43
+ } ) ) ;
44
+
45
+ it ( 'should update checkboxes when the ngmodel value is updated externally' , ( ) => {
46
+ expect ( comp . select . contentOptions . map ( opt => opt . selected ) ) . toEqual ( [ false , true , false ] ) ;
47
+ comp . form . controls . value . setValue ( [ '1' ] ) ;
48
+ expect ( comp . select . contentOptions . map ( opt => opt . selected ) ) . toEqual ( [ true , false , false ] ) ;
49
+ } ) ;
50
+
51
+ // This case may arise if, for instance, a dynamic form is about to transform this
52
+ // control from a novo-select to something else.
53
+ it ( 'should not trigger errors from negative use-case variables' , ( ) => {
54
+ ( comp . form . controls . value as FormControl ) . setValue ( 'candy' ) ;
55
+ } )
56
+ } ) ;
0 commit comments