1
- import { TestBed , ComponentFixture , async , inject } from '@angular/core/testing' ;
1
+ import { async , ComponentFixture , inject , TestBed } from '@angular/core/testing' ;
2
2
import { createGenericTestComponent } from '../test/common' ;
3
3
4
- import { Component , Injectable } from '@angular/core' ;
4
+ import { ChangeDetectionStrategy , Component , Injectable } from '@angular/core' ;
5
5
import { By } from '@angular/platform-browser' ;
6
- import { Validators , FormControl , FormGroup , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
6
+ import { FormControl , FormGroup , FormsModule , ReactiveFormsModule , Validators } from '@angular/forms' ;
7
7
8
8
import { NgbTimepickerModule } from './timepicker.module' ;
9
9
import { NgbTimepickerConfig } from './timepicker-config' ;
@@ -14,6 +14,9 @@ import {NgbTimeStruct} from './ngb-time-struct';
14
14
const createTestComponent = ( html : string ) =>
15
15
createGenericTestComponent ( html , TestComponent ) as ComponentFixture < TestComponent > ;
16
16
17
+ const createOnPushTestComponent = ( html : string ) =>
18
+ createGenericTestComponent ( html , TestComponentOnPush ) as ComponentFixture < TestComponentOnPush > ;
19
+
17
20
function getTimepicker ( el : HTMLElement ) {
18
21
return el . querySelector ( 'ngb-timepicker' ) ;
19
22
}
@@ -78,14 +81,16 @@ function customizeConfig(config: NgbTimepickerConfig) {
78
81
describe ( 'ngb-timepicker' , ( ) => {
79
82
80
83
beforeEach ( ( ) => {
81
- TestBed . configureTestingModule (
82
- { declarations : [ TestComponent ] , imports : [ NgbTimepickerModule , FormsModule , ReactiveFormsModule ] } ) ;
84
+ TestBed . configureTestingModule ( {
85
+ declarations : [ TestComponent , TestComponentOnPush ] ,
86
+ imports : [ NgbTimepickerModule , FormsModule , ReactiveFormsModule ]
87
+ } ) ;
83
88
} ) ;
84
89
85
90
describe ( 'initialization' , ( ) => {
86
91
it ( 'should initialize inputs with provided config' , ( ) => {
87
92
const defaultConfig = new NgbTimepickerConfig ( ) ;
88
- const timepicker = new NgbTimepicker ( new NgbTimepickerConfig ( ) , new NgbTimeStructAdapter ( ) ) ;
93
+ const timepicker = new NgbTimepicker ( new NgbTimepickerConfig ( ) , new NgbTimeStructAdapter ( ) , null ) ;
89
94
expectSameValues ( timepicker , defaultConfig ) ;
90
95
} ) ;
91
96
} ) ;
@@ -1532,6 +1537,18 @@ describe('ngb-timepicker', () => {
1532
1537
} ) ;
1533
1538
} ) ;
1534
1539
} ) ;
1540
+
1541
+ describe ( 'on push' , ( ) => {
1542
+
1543
+ it ( 'should render initial model value' , async ( async ( ) => {
1544
+ const fixture =
1545
+ createOnPushTestComponent ( `<ngb-timepicker [ngModel]="{hour: 13, minute: 30}"></ngb-timepicker>` ) ;
1546
+ fixture . detectChanges ( ) ;
1547
+ await fixture . whenStable ( ) ;
1548
+ fixture . detectChanges ( ) ;
1549
+ expectToDisplayTime ( fixture . nativeElement , '13:30' ) ;
1550
+ } ) ) ;
1551
+ } ) ;
1535
1552
} ) ;
1536
1553
1537
1554
@@ -1549,6 +1566,10 @@ class TestComponent {
1549
1566
onSubmit ( ) { this . submitted = true ; }
1550
1567
}
1551
1568
1569
+ @Component ( { selector : 'test-cmp-on-push' , template : '' , changeDetection : ChangeDetectionStrategy . OnPush } )
1570
+ class TestComponentOnPush {
1571
+ }
1572
+
1552
1573
@Injectable ( )
1553
1574
class StringTimeAdapter extends NgbTimeAdapter < string > {
1554
1575
fromModel ( value : string ) : NgbTimeStruct {
0 commit comments