@@ -5,6 +5,7 @@ import { MockStore, provideMockStore } from '@ngrx/store/testing';
5
5
import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
6
6
import { formatDate } from '@angular/common' ;
7
7
import { ActionsSubject } from '@ngrx/store' ;
8
+ import { ToastrService , IndividualConfig } from 'ngx-toastr' ;
8
9
9
10
import { TechnologyState } from '../../store/technology.reducers' ;
10
11
import { allTechnologies } from '../../store/technology.selectors' ;
@@ -15,6 +16,7 @@ import { EntryState } from '../../../time-clock/store/entry.reducer';
15
16
import * as entryActions from '../../../time-clock/store/entry.actions' ;
16
17
import { getCreateError , getUpdateError } from 'src/app/modules/time-clock/store/entry.selectors' ;
17
18
import { SaveEntryEvent } from './save-entry-event' ;
19
+ import * as moment from 'moment' ;
18
20
19
21
describe ( 'DetailsFieldsComponent' , ( ) => {
20
22
type Merged = TechnologyState & ProjectState & EntryState ;
@@ -28,6 +30,9 @@ describe('DetailsFieldsComponent', () => {
28
30
let entryToEdit ;
29
31
let formValues ;
30
32
const actionSub : ActionsSubject = new ActionsSubject ( ) ;
33
+ const toastrServiceStub = {
34
+ error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { }
35
+ } ;
31
36
32
37
const state = {
33
38
projects : {
@@ -67,7 +72,11 @@ describe('DetailsFieldsComponent', () => {
67
72
beforeEach ( async ( ( ) => {
68
73
TestBed . configureTestingModule ( {
69
74
declarations : [ DetailsFieldsComponent , TechnologiesComponent ] ,
70
- providers : [ provideMockStore ( { initialState : state } ) , { provide : ActionsSubject , useValue : actionSub } ] ,
75
+ providers : [
76
+ provideMockStore ( { initialState : state } ) ,
77
+ { provide : ActionsSubject , useValue : actionSub } ,
78
+ { provide : ToastrService , useValue : toastrServiceStub }
79
+ ] ,
71
80
imports : [ FormsModule , ReactiveFormsModule ] ,
72
81
} ) . compileComponents ( ) ;
73
82
store = TestBed . inject ( MockStore ) ;
@@ -273,6 +282,17 @@ describe('DetailsFieldsComponent', () => {
273
282
274
283
expect ( component . saveEntry . emit ) . toHaveBeenCalledWith ( data ) ;
275
284
} ) ;
285
+
286
+ it ( 'displays error message when the date selected is in the future' , ( ) => {
287
+ spyOn ( toastrServiceStub , 'error' ) ;
288
+
289
+ const futureDate = moment ( ) . add ( 1 , 'days' ) . format ( 'YYYY-MM-DD' ) ;
290
+ component . entryForm . setValue ( { ...formValues , entry_date : futureDate } ) ;
291
+ component . onSubmit ( ) ;
292
+
293
+ expect ( toastrServiceStub . error ) . toHaveBeenCalled ( ) ;
294
+ } ) ;
295
+
276
296
/*
277
297
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
278
298
and now these couple of tests are failing. A solution to this error might be generate a Test Wrapper Component. More details here:
0 commit comments