Skip to content

Commit 2edad2e

Browse files
author
Andrés Soto
committed
refactor: TT-319 Change moment library with date
1 parent 26bfd68 commit 2edad2e

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/app/modules/time-entries/pages/time-entries.component.spec.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ describe('TimeEntriesComponent', () => {
561561
const dateMoment: moment.Moment = moment().month(monthIndex).year(year);
562562
jasmine.clock().mockDate(dateMoment.toDate());
563563

564-
component.currentMonth = monthIndex;
564+
component.actualDate.setMonth(monthIndex);
565565
component.dateSelected(eventData);
566566

567567
expect(component.selectedDate).toEqual(dateMoment);
@@ -601,18 +601,15 @@ describe('TimeEntriesComponent', () => {
601601
});
602602

603603
it('change component selectedDate to be the first day of the month when call dateSelected', () => {
604-
const actualMoment: moment.Moment = moment(new Date('2021-01-07'));
605-
const selectedMoment: moment.Moment = moment(new Date('2021-05-13'));
606-
const firstDayMoment: moment.Moment = selectedMoment.startOf('month');
604+
const actualDate: Date = new Date(2021, 5, 15);
605+
const selectedDate: Date = new Date(2021, 2, 1);
607606
const eventDate = {
608-
monthIndex: selectedMoment.month(),
609-
year: selectedMoment.year()
607+
monthIndex: selectedDate.getMonth(),
608+
year: selectedDate.getFullYear()
610609
};
611-
component.currentMonth = actualMoment.month();
612-
component.selectedDate = selectedMoment;
613-
spyOn(component, 'dateSelected');
610+
component.actualDate = actualDate;
614611
component.dateSelected(eventDate);
615-
expect(component.selectedDate).toBe(firstDayMoment);
612+
expect(component.selectedDate.date()).toBe(selectedDate.getDate());
616613
});
617614

618615
it('change component calendarView from Month to Day when call changeView', () => {

src/app/modules/time-entries/pages/time-entries.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
4040
selectedMonthAsText: string;
4141
isActiveEntryOverlapping = false;
4242
calendarView: CalendarView = CalendarView.Month;
43-
currentMonth = moment().month();
43+
actualDate: Date;
4444
readonly NO_DATA_MESSAGE: string = 'No data available in table';
4545
constructor(
4646
private store: Store<EntryState>,
@@ -49,6 +49,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
4949
private cookiesService: CookieService) {
5050
this.displayGridView = false;
5151
this.selectedDate = moment(new Date());
52+
this.actualDate = new Date();
5253
this.timeEntriesDataSource$ = this.store.pipe(delay(0), select(getTimeEntriesDataSource));
5354
}
5455
ngOnDestroy(): void {
@@ -183,7 +184,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
183184
this.selectedMonthAsText = moment().month(event.monthIndex).format('MMMM');
184185
this.store.dispatch(new entryActions.LoadEntries(this.selectedMonth, this.selectedYear));
185186
this.selectedDate = moment().month(event.monthIndex).year(event.year);
186-
if (this.currentMonth !== event.monthIndex){
187+
if (this.actualDate.getMonth() !== event.monthIndex){
187188
this.selectedDate = this.selectedDate.startOf('month');
188189
}
189190
}

0 commit comments

Comments
 (0)