From 837ec58a8d8f1b4af73d39ed3346fd7e9f73acec Mon Sep 17 00:00:00 2001 From: SheenaMalhotra182 Date: Fri, 29 Sep 2023 21:31:28 +0530 Subject: [PATCH] [ACS-5857] added unit tests for formatLabel --- .../widgets/date-time/date-time.widget.spec.ts | 16 ++++++++++++++++ .../widgets/date-time/date-time.widget.ts | 2 +- .../components/widgets/date/date.widget.spec.ts | 16 ++++++++++++++++ .../form/components/widgets/date/date.widget.ts | 2 +- .../widgets/date/date-cloud.widget.spec.ts | 16 ++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts b/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts index 57bab55a1d..856cab47e3 100644 --- a/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.spec.ts @@ -331,4 +331,20 @@ describe('DateTimeWidgetComponent', () => { expect(adfLeftLabel).toBeNull(); }); }); + + describe('format label', () => { + beforeEach(() => { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { + 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)'); + }); + }); }); diff --git a/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.ts b/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.ts index 89c7ad894a..27d0ffa9ba 100644 --- a/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.ts +++ b/lib/core/src/lib/form/components/widgets/date-time/date-time.widget.ts @@ -25,7 +25,7 @@ import { WidgetComponent } from '../widget.component'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; 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 { isValid } from 'date-fns'; import { DateFnsAdapter } from '@angular/material-date-fns-adapter'; diff --git a/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts b/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts index ed7d837655..e3e8ea2aa4 100644 --- a/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/date/date.widget.spec.ts @@ -259,4 +259,20 @@ describe('DateWidgetComponent', () => { fixture.detectChanges(); expect(dateElement.value).toContain('03-02-2020'); }); + + describe('format label', () => { + beforeEach(() => { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { + 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)'); + }); + }); }); diff --git a/lib/core/src/lib/form/components/widgets/date/date.widget.ts b/lib/core/src/lib/form/components/widgets/date/date.widget.ts index 40da0e3be6..fe9fa667f0 100644 --- a/lib/core/src/lib/form/components/widgets/date/date.widget.ts +++ b/lib/core/src/lib/form/components/widgets/date/date.widget.ts @@ -28,7 +28,7 @@ import { DateFnsAdapter, MAT_DATE_FNS_FORMATS } from '@angular/material-date-fns import { DateFnsUtils } from '../../../../common'; import { isValid } from 'date-fns'; import { FormFieldModel } from '../core'; -import { TranslationService } from '../../../../../../../core/src/lib/translation/translation.service'; +import { TranslationService } from '../../../../../../../core/src/lib/translation'; @Component({ selector: 'date-widget', diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts index 4f1688e8a8..2a88f094c1 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/date/date-cloud.widget.spec.ts @@ -541,4 +541,20 @@ describe('DateWidgetComponent', () => { expect(element.querySelector('.adf-invalid')).toBeTruthy(); }); }); + + describe('format label', () => { + beforeEach(() => { + widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { + 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)'); + }); + }); });