Skip to content

Commit 31b8e51

Browse files
author
Juan Gabriel Guzmán
authored
Merge pull request #512 from ioet/492-fixing-flaky-test
test: #402 Fixing flaky test
2 parents 0df6106 + 2e60be7 commit 31b8e51

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { AutocompleteLibModule } from 'angular-ng-autocomplete';
21
import { formatDate } from '@angular/common';
32
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
43
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
54
import { ActionsSubject } from '@ngrx/store';
65
import { MockStore, provideMockStore } from '@ngrx/store/testing';
6+
import { AutocompleteLibModule } from 'angular-ng-autocomplete';
7+
import * as moment from 'moment';
78
import { IndividualConfig, ToastrService } from 'ngx-toastr';
89
import { getCreateError, getUpdateError } from 'src/app/modules/time-clock/store/entry.selectors';
910
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
@@ -17,6 +18,7 @@ import { TechnologiesComponent } from './../technologies/technologies.component'
1718
import { DetailsFieldsComponent } from './details-fields.component';
1819
import { SaveEntryEvent } from './save-entry-event';
1920

21+
2022
describe('DetailsFieldsComponent', () => {
2123
type Merged = TechnologyState & ProjectState & EntryState;
2224
let component: DetailsFieldsComponent;
@@ -304,16 +306,15 @@ describe('DetailsFieldsComponent', () => {
304306
expect(component.saveEntry.emit).toHaveBeenCalledWith(data);
305307
});
306308

307-
// TODO Fix this test since it is failing.
308-
// it('displays error message when the date selected is in the future', () => {
309-
// spyOn(toastrServiceStub, 'error');
309+
it('displays error message when the date selected is in the future', () => {
310+
spyOn(toastrServiceStub, 'error');
310311

311-
// const futureDate = moment().add(1, 'days').format('YYYY-MM-DD');
312-
// component.entryForm.setValue({ ...formValues, entry_date: futureDate });
313-
// component.onSubmit();
312+
const futureDate = moment().add(1, 'days').format('YYYY-MM-DD');
313+
component.entryForm.setValue({ ...formValues, entry_date: futureDate });
314+
component.onSubmit();
314315

315-
// expect(toastrServiceStub.error).toHaveBeenCalled();
316-
// });
316+
expect(toastrServiceStub.error).toHaveBeenCalled();
317+
});
317318

318319
/*
319320
TODO As part of https://github.com/ioet/time-tracker-ui/issues/424 a new parameter was added to the details-field-component,

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { formatDate } from '@angular/common';
22
import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild } from '@angular/core';
33
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
44
import { ActionsSubject, select, Store } from '@ngrx/store';
5+
import * as moment from 'moment';
56
import { ToastrService } from 'ngx-toastr';
67
import { filter } from 'rxjs/operators';
78
import { getCreateError, getUpdateError } from 'src/app/modules/time-clock/store/entry.selectors';
@@ -16,6 +17,7 @@ import { TechnologyState } from '../../store/technology.reducers';
1617
import { EntryActionTypes } from './../../../time-clock/store/entry.actions';
1718
import { SaveEntryEvent } from './save-entry-event';
1819

20+
1921
type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
2022
@Component({
2123
selector: 'app-details-fields',
@@ -203,8 +205,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
203205
if (this.goingToWorkOnThis) {
204206
delete entry.end_date;
205207
}
206-
207-
const isEntryDateInTheFuture = new Date(entryDate) > new Date();
208+
const isEntryDateInTheFuture = moment(entryDate).isAfter(moment());
208209
if (isEntryDateInTheFuture) {
209210
this.toastrService.error('You cannot start a time-entry in the future');
210211
return;

0 commit comments

Comments
 (0)