[AAE-10311] - Fix deprecation warning about dates in cloud unit tests (#7787)

* [AAE-10311] - Fix deprecation warning about dates in cloud unit tests

* Fix comments
This commit is contained in:
Ardit Domi
2022-09-13 08:33:17 +01:00
committed by GitHub
parent 79b5cd49b8
commit c845843591
5 changed files with 43 additions and 24 deletions

View File

@@ -16,11 +16,12 @@
*/
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DateCloudWidgetComponent, DATE_FORMAT_CLOUD } from './date-cloud.widget';
import { DateCloudWidgetComponent } from './date-cloud.widget';
import { setupTestBed, FormFieldModel, FormModel, FormFieldTypes } from '@alfresco/adf-core';
import moment from 'moment';
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { DATE_FORMAT_CLOUD } from '../../../../models/date-format-cloud.model';
describe('DateWidgetComponent', () => {
@@ -90,8 +91,9 @@ describe('DateWidgetComponent', () => {
});
widget.field = field;
const todayDate = moment().format(DATE_FORMAT_CLOUD);
widget.onDateChanged({ value: todayDate });
widget.onDateChanged({ value: moment('12/12/2012') });
expect(widget.onFieldChanged).toHaveBeenCalledWith(field);
});
@@ -200,7 +202,7 @@ describe('DateWidgetComponent', () => {
});
});
it('should display always the json value', () => {
it('should display always the json value', async () => {
const field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
@@ -213,21 +215,19 @@ describe('DateWidgetComponent', () => {
widget.field = field;
widget.ngOnInit();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toContain('12-30-9999');
await fixture.whenStable();
widget.field.value = '03-02-2020';
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toContain('12-30-9999');
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(dateElement.value).toContain('03-02-2020');
});
});
widget.field.value = '03-02-2020';
fixture.detectChanges();
await fixture.whenStable();
expect(dateElement.value).toContain('03-02-2020');
});
describe('when form model has left labels', () => {
@@ -491,8 +491,6 @@ describe('DateWidgetComponent', () => {
});
});
});

View File

@@ -26,8 +26,7 @@ import {
MOMENT_DATE_FORMATS, MomentDateAdapter, WidgetComponent,
UserPreferencesService, UserPreferenceValues, FormService
} from '@alfresco/adf-core';
export const DATE_FORMAT_CLOUD = 'YYYY-MM-DD';
import { DATE_FORMAT_CLOUD } from '../../../../models/date-format-cloud.model';
@Component({
selector: 'date-widget',

View File

@@ -0,0 +1,18 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const DATE_FORMAT_CLOUD = 'YYYY-MM-DD';

View File

@@ -40,6 +40,7 @@ import { DateCloudFilterType } from '../../../models/date-cloud-filter.model';
import { MatIconTestingModule } from '@angular/material/icon/testing';
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
import { mockAppVersions } from '../mock/process-filters-cloud.mock';
import { DATE_FORMAT_CLOUD } from '../../../models/date-format-cloud.model';
describe('EditProcessFilterCloudComponent', () => {
let component: EditProcessFilterCloudComponent;
@@ -500,8 +501,10 @@ describe('EditProcessFilterCloudComponent', () => {
priority: '12',
suspendedDateType: DateCloudFilterType.RANGE
});
filter.suspendedFrom = new Date(2021, 1, 1).toString();
filter.suspendedTo = new Date(2021, 1, 2).toString();
const oneYearAgoDate = moment().add(-1, 'years').format(DATE_FORMAT_CLOUD);
const todayDate = moment().format(DATE_FORMAT_CLOUD);
filter.suspendedFrom = oneYearAgoDate.toString();
filter.suspendedTo = todayDate.toString();
getProcessFilterByIdSpy.and.returnValue(of(filter));
fixture.detectChanges();
@@ -518,8 +521,8 @@ describe('EditProcessFilterCloudComponent', () => {
fixture.detectChanges();
await fixture.whenStable();
expect(component.editProcessFilterForm.get('_suspendedFrom').value).toEqual(new Date(2021, 1, 1).toString());
expect(component.editProcessFilterForm.get('_suspendedTo').value).toEqual(new Date(2021, 1, 2).toString());
expect(component.editProcessFilterForm.get('_suspendedFrom').value).toEqual(oneYearAgoDate.toString());
expect(component.editProcessFilterForm.get('_suspendedTo').value).toEqual(todayDate.toString());
expect(component.editProcessFilterForm.get('suspendedDateType').value).toEqual(DateCloudFilterType.RANGE);
});

View File

@@ -35,3 +35,4 @@ export * from './lib/models/filter-cloud-model';
export * from './lib/models/task-list-sorting.model';
export * from './lib/models/process-instance-variable.model';
export * from './lib/models/variable-definition';
export * from './lib/models/date-format-cloud.model';