[ACS-5857] added unit tests for formatLabel

This commit is contained in:
SheenaMalhotra182
2023-10-04 01:15:31 +05:30
parent 9ca1394309
commit 837ec58a8d
5 changed files with 50 additions and 2 deletions
@@ -331,4 +331,20 @@ describe('DateTimeWidgetComponent', () => {
expect(adfLeftLabel).toBeNull(); expect(adfLeftLabel).toBeNull();
}); });
}); });
describe('format label', () => {
beforeEach(() => {
widget.field = new FormFieldModel(new FormModel({ taskId: '<id>' }), {
name: 'Date Time',
dateDisplayFormat: 'd-M-yyyy hh:mm a'
});
fixture.detectChanges();
});
it('should format label correctly', () => {
const result = widget.formatLabel(widget.field);
expect(result).toBe('Date Time (D-M-YYYY hh:mm A)');
});
});
}); });
@@ -25,7 +25,7 @@ import { WidgetComponent } from '../widget.component';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { DateFnsUtils } from '../../../../common'; import { DateFnsUtils } from '../../../../common';
import { TranslationService } from '../../../../../../../core/src/lib/translation/translation.service'; import { TranslationService } from '../../../../../../../core/src/lib/translation';
import { FormFieldModel } from '../core'; import { FormFieldModel } from '../core';
import { isValid } from 'date-fns'; import { isValid } from 'date-fns';
import { DateFnsAdapter } from '@angular/material-date-fns-adapter'; import { DateFnsAdapter } from '@angular/material-date-fns-adapter';
@@ -259,4 +259,20 @@ describe('DateWidgetComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
expect(dateElement.value).toContain('03-02-2020'); expect(dateElement.value).toContain('03-02-2020');
}); });
describe('format label', () => {
beforeEach(() => {
widget.field = new FormFieldModel(new FormModel({ taskId: '<id>' }), {
name: 'Date',
dateDisplayFormat: 'd-M-yyyy'
});
fixture.detectChanges();
});
it('should format label correctly', () => {
const result = widget.formatLabel(widget.field);
expect(result).toBe('Date (D-M-YYYY)');
});
});
}); });
@@ -28,7 +28,7 @@ import { DateFnsAdapter, MAT_DATE_FNS_FORMATS } from '@angular/material-date-fns
import { DateFnsUtils } from '../../../../common'; import { DateFnsUtils } from '../../../../common';
import { isValid } from 'date-fns'; import { isValid } from 'date-fns';
import { FormFieldModel } from '../core'; import { FormFieldModel } from '../core';
import { TranslationService } from '../../../../../../../core/src/lib/translation/translation.service'; import { TranslationService } from '../../../../../../../core/src/lib/translation';
@Component({ @Component({
selector: 'date-widget', selector: 'date-widget',
@@ -541,4 +541,20 @@ describe('DateWidgetComponent', () => {
expect(element.querySelector('.adf-invalid')).toBeTruthy(); expect(element.querySelector('.adf-invalid')).toBeTruthy();
}); });
}); });
describe('format label', () => {
beforeEach(() => {
widget.field = new FormFieldModel(new FormModel({ taskId: '<id>' }), {
name: 'Date Field',
dateDisplayFormat: 'd-M-yyyy'
});
fixture.detectChanges();
});
it('should format label correctly', () => {
const result = widget.formatLabel(widget.field);
expect(result).toBe('Date Field (D-M-YYYY)');
});
});
}); });