Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: TT-319 Change moment library with date
  • Loading branch information
Andrés Soto committed Aug 25, 2021
commit 2edad2e696e06796593c11e573be30c96e2f5c08
17 changes: 7 additions & 10 deletions src/app/modules/time-entries/pages/time-entries.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ describe('TimeEntriesComponent', () => {
const dateMoment: moment.Moment = moment().month(monthIndex).year(year);
jasmine.clock().mockDate(dateMoment.toDate());

component.currentMonth = monthIndex;
component.actualDate.setMonth(monthIndex);
component.dateSelected(eventData);

expect(component.selectedDate).toEqual(dateMoment);
Expand Down Expand Up @@ -601,18 +601,15 @@ describe('TimeEntriesComponent', () => {
});

it('change component selectedDate to be the first day of the month when call dateSelected', () => {
const actualMoment: moment.Moment = moment(new Date('2021-01-07'));
const selectedMoment: moment.Moment = moment(new Date('2021-05-13'));
const firstDayMoment: moment.Moment = selectedMoment.startOf('month');
const actualDate: Date = new Date(2021, 5, 15);
const selectedDate: Date = new Date(2021, 2, 1);
const eventDate = {
monthIndex: selectedMoment.month(),
year: selectedMoment.year()
monthIndex: selectedDate.getMonth(),
year: selectedDate.getFullYear()
};
component.currentMonth = actualMoment.month();
component.selectedDate = selectedMoment;
spyOn(component, 'dateSelected');
component.actualDate = actualDate;
component.dateSelected(eventDate);
expect(component.selectedDate).toBe(firstDayMoment);
expect(component.selectedDate.date()).toBe(selectedDate.getDate());
});

it('change component calendarView from Month to Day when call changeView', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
selectedMonthAsText: string;
isActiveEntryOverlapping = false;
calendarView: CalendarView = CalendarView.Month;
currentMonth = moment().month();
actualDate: Date;
readonly NO_DATA_MESSAGE: string = 'No data available in table';
constructor(
private store: Store<EntryState>,
Expand All @@ -49,6 +49,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
private cookiesService: CookieService) {
this.displayGridView = false;
this.selectedDate = moment(new Date());
this.actualDate = new Date();
this.timeEntriesDataSource$ = this.store.pipe(delay(0), select(getTimeEntriesDataSource));
}
ngOnDestroy(): void {
Expand Down Expand Up @@ -183,7 +184,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
this.selectedMonthAsText = moment().month(event.monthIndex).format('MMMM');
this.store.dispatch(new entryActions.LoadEntries(this.selectedMonth, this.selectedYear));
this.selectedDate = moment().month(event.monthIndex).year(event.year);
if (this.currentMonth !== event.monthIndex){
if (this.actualDate.getMonth() !== event.monthIndex){
this.selectedDate = this.selectedDate.startOf('month');
}
}
Expand Down