Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {

Expand All @@ -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);
});
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -43,25 +43,25 @@ 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', () => {
const date = new Date();
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', () => {
const date = new Date();
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());
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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 = {
Expand Down