[APPS-2127] migrated dependency in date-range-filter component from moment to date-fns (#8833)

* migrated dependency in date-range-filter component from moment to date-fns

* test cases migrated to date-fns impacted due to migration of dependency in date-range-filter.component.ts

* migrate date-range-filter.service.ts from moment to date-fns dependency
This commit is contained in:
Jatin Chugh 2023-08-23 00:15:52 +05:30 committed by GitHub
parent a8be9d64e1
commit c9fdf24553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 52 deletions

View File

@ -22,8 +22,8 @@ import { ProcessServiceCloudTestingModule } from '../../testing/process-service-
import { MatSelectChange } from '@angular/material/select';
import { DateCloudFilterType } from '../../models/date-cloud-filter.model';
import { DateRangeFilterService } from './date-range-filter.service';
import moment from 'moment';
import { mockFilterProperty } from '../mock/date-range-filter.mock';
import { add, endOfDay } from 'date-fns';
describe('DateRangeFilterComponent', () => {
let component: DateRangeFilterComponent;
@ -92,8 +92,8 @@ describe('DateRangeFilterComponent', () => {
it('should return correct date when any type is selected', () => {
const expectedDate = {
startDate: moment().endOf('day').toISOString(true),
endDate: moment().add(1, 'days').endOf('day').toISOString(true)
startDate: endOfDay(new Date()).toISOString(),
endDate: add(endOfDay(new Date()), { days: 1 }).toISOString()
};
expect(service.getDateRange(DateCloudFilterType.TOMORROW)).toEqual(expectedDate);
});
@ -126,9 +126,9 @@ describe('DateRangeFilterComponent', () => {
fixture.detectChanges();
// eslint-disable-next-line no-underscore-dangle
expect(component.dateRangeForm.get('from').value).toEqual(moment(mockFilterProperty.value._startFrom));
expect(component.dateRangeForm.get('from').value).toEqual(mockFilterProperty.value._startFrom);
// eslint-disable-next-line no-underscore-dangle
expect(component.dateRangeForm.get('to').value).toEqual(moment(mockFilterProperty.value._startTo));
expect(component.dateRangeForm.get('to').value).toEqual(mockFilterProperty.value._startTo);
});
it('should have floating labels when values are present', () => {

View File

@ -20,7 +20,7 @@ import { MatSelectChange } from '@angular/material/select';
import { ProcessFilterProperties, ProcessFilterOptions } from '../../process/process-filters/models/process-filter-cloud.model';
import { UntypedFormGroup, UntypedFormControl } from '@angular/forms';
import { DateRangeFilter, DateCloudFilterType } from '../../models/date-cloud-filter.model';
import moment from 'moment';
import { endOfDay, startOfDay } from 'date-fns';
@Component({
selector: 'adf-cloud-date-range-filter',
@ -70,8 +70,8 @@ import moment from 'moment';
onDateRangeClosed() {
const dateRange = {
startDate: moment(this.dateRangeForm.controls.from.value).startOf('day').toISOString(true),
endDate: moment(this.dateRangeForm.controls.to.value).endOf('day').toISOString(true)
startDate: startOfDay(new Date(this.dateRangeForm.controls.from.value)).toISOString(),
endDate: endOfDay(new Date(this.dateRangeForm.controls.to.value)).toISOString()
};
this.dateChanged.emit(dateRange);
}
@ -85,8 +85,8 @@ import moment from 'moment';
const to = this.getFilterAttribute('to');
const type = this.getFilterAttribute('dateType');
this.dateRangeForm.get('from').setValue(moment(this.getFilterValue(from)));
this.dateRangeForm.get('to').setValue(moment(this.getFilterValue(to)));
this.dateRangeForm.get('from').setValue(this.getFilterValue(from));
this.dateRangeForm.get('to').setValue(this.getFilterValue(to));
this.type = this.getFilterValue(type);
}

View File

@ -18,7 +18,7 @@
import { TestBed } from '@angular/core/testing';
import { DateRangeFilterService } from './date-range-filter.service';
import { DateCloudFilterType } from '../../models/date-cloud-filter.model';
import moment from 'moment';
import { add, endOfDay, endOfMonth, endOfQuarter, endOfYear, startOfDay, startOfMonth, startOfQuarter, startOfYear } from 'date-fns';
describe('Date Range Filter service', () => {
@ -30,32 +30,32 @@ describe('Date Range Filter service', () => {
it('should return today range', () => {
const expectedDate = {
startDate: moment().startOf('day').toISOString(true),
endDate: moment().endOf('day').toISOString(true)
startDate: startOfDay(new Date()).toISOString(),
endDate: endOfDay(new Date()).toISOString()
};
expect(service.getDateRange(DateCloudFilterType.TODAY)).toEqual(expectedDate);
});
it('should return month range', () => {
const expectedDate = {
startDate: moment().startOf('month').toISOString(true),
endDate: moment().endOf('month').toISOString(true)
startDate: startOfMonth(new Date()).toISOString(),
endDate: endOfMonth(new Date()).toISOString()
};
expect(service.getDateRange(DateCloudFilterType.MONTH)).toEqual(expectedDate);
});
it('should return year range', () => {
const expectedDate = {
startDate: moment().startOf('year').toISOString(true),
endDate: moment().endOf('year').toISOString(true)
startDate: startOfYear(new Date()).toISOString(),
endDate: endOfYear(new Date()).toISOString()
};
expect(service.getDateRange(DateCloudFilterType.YEAR)).toEqual(expectedDate);
});
it('should return quarter range', () => {
const expectedDate = {
startDate: moment().startOf('quarter').toISOString(true),
endDate: moment().endOf('quarter').toISOString(true)
startDate: startOfQuarter(new Date()).toISOString(),
endDate: endOfQuarter(new Date()).toISOString()
};
expect(service.getDateRange(DateCloudFilterType.QUARTER)).toEqual(expectedDate);
});
@ -70,16 +70,16 @@ describe('Date Range Filter service', () => {
it('should return tomorow range', () => {
const expectedDate = {
startDate: moment().endOf('day').toISOString(true),
endDate: moment().add(1, 'days').endOf('day').toISOString(true)
startDate: endOfDay(new Date()).toISOString(),
endDate: add(endOfDay(new Date()), { days: 1 }).toISOString()
};
expect(service.getDateRange(DateCloudFilterType.TOMORROW)).toEqual(expectedDate);
});
it('should return next 7 days range', () => {
const expectedDate = {
startDate: moment().startOf('day').toISOString(true),
endDate: moment().add(7, 'days').endOf('day').toISOString(true)
startDate: startOfDay(new Date()).toISOString(),
endDate: add(endOfDay(new Date()), { days: 7 }).toISOString()
};
expect(service.getDateRange(DateCloudFilterType.NEXT_7_DAYS)).toEqual(expectedDate);
});

View File

@ -16,8 +16,8 @@
*/
import { Injectable } from '@angular/core';
import moment from 'moment';
import { DateRangeFilter, DateCloudFilterType } from '../../models/date-cloud-filter.model';
import { add, endOfDay, endOfMonth, endOfQuarter, endOfWeek, endOfYear, startOfDay, startOfMonth, startOfQuarter, startOfWeek, startOfYear } from 'date-fns';
@Injectable({
providedIn: 'root'
@ -52,50 +52,50 @@ export class DateRangeFilterService {
private getNext7DaysDateRange(): DateRangeFilter {
return {
startDate: moment().startOf('day').toISOString(true),
endDate: moment().add(7, 'days').endOf('day').toISOString(true)
startDate: startOfDay(new Date()).toISOString(),
endDate: add(endOfDay(new Date()), { days: 7 }).toISOString()
};
}
private getTomorrowDateRange(): DateRangeFilter {
return {
startDate: moment().endOf('day').toISOString(true),
endDate: moment().add(1, 'days').endOf('day').toISOString(true)
startDate: endOfDay(new Date()).toISOString(),
endDate: add(endOfDay(new Date()), { days: 1 }).toISOString()
};
}
private getCurrentYearDateRange(): DateRangeFilter {
return {
startDate: moment().startOf('year').toISOString(true),
endDate: moment().endOf('year').toISOString(true)
startDate: startOfYear(new Date()).toISOString(),
endDate: endOfYear(new Date()).toISOString()
};
}
private getTodayDateRange(): DateRangeFilter {
return {
startDate: moment().startOf('day').toISOString(true),
endDate: moment().endOf('day').toISOString(true)
startDate: startOfDay(new Date()).toISOString(),
endDate: endOfDay(new Date()).toISOString()
};
}
private getCurrentWeekRange(): DateRangeFilter {
return {
startDate: moment().startOf('week').toISOString(true),
endDate: moment().endOf('week').toISOString(true)
startDate: startOfWeek(new Date()).toISOString(),
endDate: endOfWeek(new Date()).toISOString()
};
}
private getCurrentMonthDateRange(): DateRangeFilter {
return {
startDate: moment().startOf('month').toISOString(true),
endDate: moment().endOf('month').toISOString(true)
startDate: startOfMonth(new Date()).toISOString(),
endDate: endOfMonth(new Date()).toISOString()
};
}
private getQuarterDateRange(): DateRangeFilter {
return {
startDate: moment().startOf('quarter').toISOString(true),
endDate: moment().endOf('quarter').toISOString(true)
startDate: startOfQuarter(new Date()).toISOString(),
endDate: endOfQuarter(new Date()).toISOString()
};
}
}

View File

@ -41,6 +41,7 @@ import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud
import { mockAppVersions } from '../mock/process-filters-cloud.mock';
import { DATE_FORMAT_CLOUD } from '../../../models/date-format-cloud.model';
import { fakeEnvironmentList } from '../../../common/mock/environment.mock';
import { endOfDay, startOfDay } from 'date-fns';
describe('EditProcessFilterCloudComponent', () => {
let component: EditProcessFilterCloudComponent;
@ -1048,8 +1049,8 @@ describe('EditProcessFilterCloudComponent', () => {
component.filterChange.subscribe(() => {
const dateFilter = {
startFrom: moment().startOf('day').toISOString(true),
startTo: moment().endOf('day').toISOString(true)
startFrom: startOfDay(new Date()).toISOString(),
startTo: endOfDay(new Date()).toISOString()
};
expect(component.processFilter.completedFrom).toEqual(dateFilter.startFrom);
expect(component.processFilter.completedTo).toEqual(dateFilter.startTo);

View File

@ -15,9 +15,9 @@
* limitations under the License.
*/
import moment from 'moment';
import { DateCloudFilterType } from '../../../models/date-cloud-filter.model';
import { ProcessFilterCloudModel } from './process-filter-cloud.model';
import { endOfDay, startOfDay } from 'date-fns';
describe('ProcessFilterCloudModel', () => {
it('should use appVersion from the provided object', () => {
@ -43,8 +43,8 @@ describe('ProcessFilterCloudModel', () => {
const model = new ProcessFilterCloudModel({
suspendedDateType: DateCloudFilterType.TODAY
});
expect(model.suspendedFrom).toEqual(moment(date).startOf('day').toISOString(true));
expect(model.suspendedTo).toEqual(moment(date).endOf('day').toISOString(true));
expect(model.suspendedFrom).toEqual(startOfDay(date).toISOString());
expect(model.suspendedTo).toEqual(endOfDay(date).toISOString());
});
it('should get completed date start and end date if date type is today', () => {
@ -52,8 +52,8 @@ describe('ProcessFilterCloudModel', () => {
const model = new ProcessFilterCloudModel({
completedDateType: DateCloudFilterType.TODAY
});
expect(model.completedFrom).toEqual(moment(date).startOf('day').toISOString(true));
expect(model.completedTo).toEqual(moment(date).endOf('day').toISOString(true));
expect(model.completedFrom).toEqual(startOfDay(date).toISOString());
expect(model.completedTo).toEqual(endOfDay(date).toISOString());
});
it('should get started date start and end date if date type is today', () => {
@ -61,7 +61,7 @@ describe('ProcessFilterCloudModel', () => {
const model = new ProcessFilterCloudModel({
startedDateType: DateCloudFilterType.TODAY
});
expect(model.startFrom).toEqual(moment(date).startOf('day').toISOString(true));
expect(model.startTo).toEqual(moment(date).endOf('day').toISOString(true));
expect(model.startFrom).toEqual(startOfDay(date).toISOString());
expect(model.startTo).toEqual(endOfDay(date).toISOString());
});
});

View File

@ -16,8 +16,8 @@
*/
import { SimpleChange } from '@angular/core';
import moment from 'moment';
import { fakeApplicationInstance } from '../../../app/mock/app-model.mock';
import { endOfDay, startOfDay } from 'date-fns';
export const mockAlfrescoApi: any = {
oauth2Auth: {
@ -64,13 +64,13 @@ export const mockDefaultTaskFilter = {
};
export const mockDateFilterFromTo = {
startFrom: moment().startOf('day').toISOString(true),
startTo: moment().endOf('day').toISOString(true)
startFrom: startOfDay(new Date()).toISOString(),
startTo: endOfDay(new Date()).toISOString()
};
export const mockDateFilterStartEnd = {
startDate: moment().startOf('day').toISOString(true),
endDate: moment().endOf('day').toISOString(true)
startDate: startOfDay(new Date()).toISOString(),
endDate: endOfDay(new Date()).toISOString()
};
export const mockDueDateFilter = {