@@ -9,11 +9,12 @@ import * as moment from 'moment';
99import { ToastrModule , ToastrService } from 'ngx-toastr' ;
1010import { Observable , of , throwError } from 'rxjs' ;
1111import { TimeEntriesTimeRange } from '../models/time-entries-time-range' ;
12- import { EntryService } from '../services/entry.service' ;
12+ import { EntryService , MAX_NUMBER_OF_ENTRIES_FOR_REPORTS } from '../services/entry.service' ;
1313import { INFO_SAVED_SUCCESSFULLY } from './../../shared/messages' ;
1414import { EntryActionTypes , SwitchTimeEntry , DeleteEntry , CreateEntry } from './entry.actions' ;
1515import { EntryEffects } from './entry.effects' ;
1616
17+
1718describe ( 'TimeEntryActionEffects' , ( ) => {
1819
1920 let actions$ : Observable < Action > ;
@@ -385,7 +386,7 @@ describe('TimeEntryActionEffects', () => {
385386 spyOn ( toastrService , 'success' ) ;
386387
387388 effects . updateCurrentOrLastEntry$ . subscribe ( action => {
388- expect ( toastrService . success ) . toHaveBeenCalledWith ( 'You change the time-in successfully' ) ;
389+ expect ( toastrService . success ) . toHaveBeenCalledWith ( 'You changed the time-in successfully' ) ;
389390 expect ( action . type ) . toEqual ( EntryActionTypes . UPDATE_ENTRY_RUNNING ) ;
390391 } ) ;
391392 } ) ;
@@ -399,4 +400,26 @@ describe('TimeEntryActionEffects', () => {
399400 } ) ;
400401 } ) ;
401402
403+ it ( 'should show a warning when maximum number of entries is received' , async ( ) => {
404+ const timeRange : TimeEntriesTimeRange = { start_date : moment ( new Date ( ) ) , end_date : moment ( new Date ( ) ) } ;
405+ const userId = '*' ;
406+ const entries = [ ] ;
407+ for ( let i = 0 ; i < MAX_NUMBER_OF_ENTRIES_FOR_REPORTS ; i ++ ) {
408+ entries . push ( { ...entry , id : i . toString ( ) } ) ;
409+ }
410+
411+ const serviceSpy = spyOn ( service , 'loadEntriesByTimeRange' ) ;
412+ serviceSpy . and . returnValue ( of ( entries ) ) ;
413+ spyOn ( toastrService , 'warning' ) ;
414+
415+ actions$ = of ( { type : EntryActionTypes . LOAD_ENTRIES_BY_TIME_RANGE , timeRange, userId } ) ;
416+
417+ effects . loadEntriesByTimeRange$ . subscribe ( action => {
418+ expect ( toastrService . warning ) . toHaveBeenCalledWith (
419+ 'Still loading. Limit of ' + MAX_NUMBER_OF_ENTRIES_FOR_REPORTS +
420+ ' entries reached, try filtering the request by users or date.' +
421+ ' Some information may be missing.'
422+ ) ;
423+ } ) ;
424+ } ) ;
402425} ) ;
0 commit comments