@@ -8,15 +8,14 @@ import * as entryActions from '../../../time-clock/store/entry.actions';
88import * as moment from 'moment' ;
99import { SimpleChange } from '@angular/core' ;
1010
11-
1211describe ( 'TimeRangeCustomComponent' , ( ) => {
1312 let component : TimeRangeCustomComponent ;
1413 let fixture : ComponentFixture < TimeRangeCustomComponent > ;
1514 let store : MockStore < EntryState > ;
1615 const toastrServiceStub = {
1716 error : ( ) => {
1817 return 'test error' ;
19- }
18+ } ,
2019 } ;
2120
2221 const timeEntry = {
@@ -27,7 +26,7 @@ describe('TimeRangeCustomComponent', () => {
2726 technologies : [ 'react' , 'redux' ] ,
2827 comments : 'any comment' ,
2928 uri : 'TT-123' ,
30- project_id : '1'
29+ project_id : '1' ,
3130 } ;
3231
3332 const state = {
@@ -44,13 +43,9 @@ describe('TimeRangeCustomComponent', () => {
4443 beforeEach ( async ( ) => {
4544 await TestBed . configureTestingModule ( {
4645 imports : [ FormsModule , ReactiveFormsModule ] ,
47- declarations : [ TimeRangeCustomComponent ] ,
48- providers : [
49- provideMockStore ( { initialState : state } ) ,
50- { provide : ToastrService , useValue : toastrServiceStub }
51- ] ,
52- } )
53- . compileComponents ( ) ;
46+ declarations : [ TimeRangeCustomComponent ] ,
47+ providers : [ provideMockStore ( { initialState : state } ) , { provide : ToastrService , useValue : toastrServiceStub } ] ,
48+ } ) . compileComponents ( ) ;
5449 store = TestBed . inject ( MockStore ) ;
5550 } ) ;
5651
@@ -81,10 +76,12 @@ describe('TimeRangeCustomComponent', () => {
8176
8277 component . onSubmit ( ) ;
8378
84- expect ( store . dispatch ) . toHaveBeenCalledWith ( new entryActions . LoadEntriesByTimeRange ( {
85- start_date : end . startOf ( 'day' ) ,
86- end_date : start . endOf ( 'day' )
87- } ) ) ;
79+ expect ( store . dispatch ) . toHaveBeenCalledWith (
80+ new entryActions . LoadEntriesByTimeRange ( {
81+ start_date : end . startOf ( 'day' ) ,
82+ end_date : start . endOf ( 'day' ) ,
83+ } )
84+ ) ;
8885 } ) ;
8986
9087 it ( 'shows an error when the end date is before the start date' , ( ) => {
@@ -108,7 +105,6 @@ describe('TimeRangeCustomComponent', () => {
108105
109106 expect ( component . range . controls . start . setValue ) . toHaveBeenCalled ( ) ;
110107 expect ( component . range . controls . end . setValue ) . toHaveBeenCalled ( ) ;
111-
112108 } ) ;
113109
114110 it ( 'triggers onSubmit to set initial data' , ( ) => {
@@ -121,30 +117,41 @@ describe('TimeRangeCustomComponent', () => {
121117
122118 it ( 'When the ngOnChanges method is called, the onSubmit method is called' , ( ) => {
123119 const userIdCalled = 'test-user-1' ;
120+ const projectIdCalled = 'test-project' ;
121+ const activityIdCalled = 'test-activity' ;
124122 spyOn ( component , 'onSubmit' ) ;
125123
126- component . ngOnChanges ( { userId : new SimpleChange ( null , userIdCalled , false ) } ) ;
124+ component . ngOnChanges ( {
125+ userId : new SimpleChange ( null , userIdCalled , false ) ,
126+ projectId : new SimpleChange ( null , projectIdCalled , false ) ,
127+ activityId : new SimpleChange ( null , activityIdCalled , false ) ,
128+ } ) ;
127129
128130 expect ( component . onSubmit ) . toHaveBeenCalled ( ) ;
129131 } ) ;
130132
131133 it ( 'When the ngOnChanges method is the first change, the onSubmit method is not called' , ( ) => {
132134 const userIdNotCalled = 'test-user-2' ;
135+ const projectIdNotCalled = 'test-project' ;
136+ const activityIdNotCalled = 'test-activity' ;
133137 spyOn ( component , 'onSubmit' ) ;
134138
135- component . ngOnChanges ( { userId : new SimpleChange ( null , userIdNotCalled , true ) } ) ;
139+ component . ngOnChanges ( {
140+ userId : new SimpleChange ( null , userIdNotCalled , true ) ,
141+ projectId : new SimpleChange ( null , projectIdNotCalled , true ) ,
142+ activityId : new SimpleChange ( null , activityIdNotCalled , true ) ,
143+ } ) ;
136144
137145 expect ( component . onSubmit ) . not . toHaveBeenCalled ( ) ;
138146 } ) ;
139147
140148 it ( 'should call range form and delete variable local storage ' , ( ) => {
141149 spyOn ( localStorage , 'removeItem' ) . withArgs ( 'rangeDatePicker' ) ;
142- component . range . setValue ( { start : null , end : null } ) ;
150+ component . range . setValue ( { start : null , end : null } ) ;
143151 jasmine . clock ( ) . install ( ) ;
144152 component . dateRangeChange ( ) ;
145153 jasmine . clock ( ) . tick ( 200 ) ;
146154 expect ( localStorage . removeItem ) . toHaveBeenCalledWith ( 'rangeDatePicker' ) ;
147155 jasmine . clock ( ) . uninstall ( ) ;
148156 } ) ;
149-
150157} ) ;
0 commit comments