@@ -5,6 +5,7 @@ import { MockStore, provideMockStore } from '@ngrx/store/testing';
55import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
66import { formatDate } from '@angular/common' ;
77import { ActionsSubject } from '@ngrx/store' ;
8+ import { ToastrService , IndividualConfig } from 'ngx-toastr' ;
89
910import { TechnologyState } from '../../store/technology.reducers' ;
1011import { allTechnologies } from '../../store/technology.selectors' ;
@@ -15,6 +16,7 @@ import { EntryState } from '../../../time-clock/store/entry.reducer';
1516import * as entryActions from '../../../time-clock/store/entry.actions' ;
1617import { getCreateError , getUpdateError } from 'src/app/modules/time-clock/store/entry.selectors' ;
1718import { SaveEntryEvent } from './save-entry-event' ;
19+ import * as moment from 'moment' ;
1820
1921describe ( 'DetailsFieldsComponent' , ( ) => {
2022 type Merged = TechnologyState & ProjectState & EntryState ;
@@ -28,6 +30,9 @@ describe('DetailsFieldsComponent', () => {
2830 let entryToEdit ;
2931 let formValues ;
3032 const actionSub : ActionsSubject = new ActionsSubject ( ) ;
33+ const toastrServiceStub = {
34+ error : ( message ?: string , title ?: string , override ?: Partial < IndividualConfig > ) => { }
35+ } ;
3136
3237 const state = {
3338 projects : {
@@ -67,7 +72,11 @@ describe('DetailsFieldsComponent', () => {
6772 beforeEach ( async ( ( ) => {
6873 TestBed . configureTestingModule ( {
6974 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+ ] ,
7180 imports : [ FormsModule , ReactiveFormsModule ] ,
7281 } ) . compileComponents ( ) ;
7382 store = TestBed . inject ( MockStore ) ;
@@ -273,6 +282,17 @@ describe('DetailsFieldsComponent', () => {
273282
274283 expect ( component . saveEntry . emit ) . toHaveBeenCalledWith ( data ) ;
275284 } ) ;
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+
276296 /*
277297 TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,
278298 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