1
- import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
2
- import { MockStore , provideMockStore } from '@ngrx/store/testing' ;
3
- import { TimeRangeFormComponent } from './time-range-form.component' ;
4
- import { EntryState } from '../../../time-clock/store/entry.reducer' ;
5
- import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
6
- import { InputDateComponent } from '../../../shared/components/input-date/input-date.component' ;
1
+ import { ToastrService , IndividualConfig } from 'ngx-toastr' ;
2
+ import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
3
+ import { MockStore , provideMockStore } from '@ngrx/store/testing' ;
4
+ import { TimeRangeFormComponent } from './time-range-form.component' ;
5
+ import { EntryState } from '../../../time-clock/store/entry.reducer' ;
6
+ import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
7
+ import { InputDateComponent } from '../../../shared/components/input-date/input-date.component' ;
7
8
import * as entryActions from '../../../time-clock/store/entry.actions' ;
8
9
import * as moment from 'moment' ;
9
10
@@ -12,6 +13,10 @@ describe('Reports Page', () => {
12
13
let component : TimeRangeFormComponent ;
13
14
let fixture : ComponentFixture < TimeRangeFormComponent > ;
14
15
let store : MockStore < EntryState > ;
16
+ const toastrServiceStub = {
17
+ error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { }
18
+ } ;
19
+
15
20
const timeEntry = {
16
21
id : '123' ,
17
22
start_date : new Date ( ) ,
@@ -38,7 +43,10 @@ describe('Reports Page', () => {
38
43
TestBed . configureTestingModule ( {
39
44
imports : [ FormsModule , ReactiveFormsModule ] ,
40
45
declarations : [ TimeRangeFormComponent , InputDateComponent ] ,
41
- providers : [ provideMockStore ( { initialState : state } ) ] ,
46
+ providers : [
47
+ provideMockStore ( { initialState : state } ) ,
48
+ { provide : ToastrService , useValue : toastrServiceStub }
49
+ ] ,
42
50
} ) . compileComponents ( ) ;
43
51
store = TestBed . inject ( MockStore ) ;
44
52
@@ -54,7 +62,7 @@ describe('Reports Page', () => {
54
62
expect ( component ) . toBeTruthy ( ) ;
55
63
} ) ;
56
64
57
- it ( 'when submitting form a new LoadEntriesByTimeRange action is triggered ' , ( ) => {
65
+ it ( 'LoadEntriesByTimeRange action is triggered when start date is before end date ' , ( ) => {
58
66
const yesterday = moment ( new Date ( ) ) . subtract ( 1 , 'days' ) ;
59
67
const today = moment ( new Date ( ) ) ;
60
68
spyOn ( store , 'dispatch' ) ;
@@ -77,6 +85,19 @@ describe('Reports Page', () => {
77
85
expect ( component . setInitialDataOnScreen ) . toHaveBeenCalled ( ) ;
78
86
} ) ;
79
87
88
+ it ( 'shows an error when the end date is before the start date' , ( ) => {
89
+ spyOn ( toastrServiceStub , 'error' ) ;
90
+ const yesterday = moment ( new Date ( ) ) . subtract ( 1 , 'days' ) ;
91
+ const today = moment ( new Date ( ) ) ;
92
+ spyOn ( store , 'dispatch' ) ;
93
+ component . reportForm . controls . startDate . setValue ( today ) ;
94
+ component . reportForm . controls . endDate . setValue ( yesterday ) ;
95
+
96
+ component . onSubmit ( ) ;
97
+
98
+ expect ( toastrServiceStub . error ) . toHaveBeenCalled ( ) ;
99
+ } ) ;
100
+
80
101
it ( 'setInitialDataOnScreen sets dates in form' , ( ) => {
81
102
spyOn ( component . reportForm , 'setValue' ) ;
82
103
0 commit comments