diff --git a/lib/core/src/lib/form/components/widgets/amount/amount.widget.spec.ts b/lib/core/src/lib/form/components/widgets/amount/amount.widget.spec.ts index 61f733f2e9..bc416e9e63 100644 --- a/lib/core/src/lib/form/components/widgets/amount/amount.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/amount/amount.widget.spec.ts @@ -40,6 +40,24 @@ describe('AmountWidgetComponent', () => { testingUtils = new UnitTestingUtils(fixture.debugElement, loader); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should setup currency from field', () => { const currency = 'UAH'; widget.field = new FormFieldModel(null, { diff --git a/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.spec.ts b/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.spec.ts index 216628438c..8a5ac7dad2 100644 --- a/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.spec.ts @@ -52,6 +52,24 @@ describe('BaseViewerWidgetComponent', () => { widget = fixture.componentInstance; }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event'); + widget.field = new FormFieldModel(new FormModel(), { value: { urlFile: '' } }); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should set the file id corretly when the field value is an array', (done) => { assertFileId([fakePngAnswer], '1933', fakeForm, widget, fixture, done); }); diff --git a/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.ts b/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.ts index 0fdf0aefb4..26999a4864 100644 --- a/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.ts +++ b/lib/core/src/lib/form/components/widgets/base-viewer/base-viewer.widget.ts @@ -29,15 +29,7 @@ import { WidgetComponent } from '../widget.component'; templateUrl: './base-viewer.widget.html', styleUrls: ['./base-viewer.widget.scss'], host: { - '(click)': 'event($event)', - '(blur)': 'event($event)', - '(change)': 'event($event)', - '(focus)': 'event($event)', - '(focusin)': 'event($event)', - '(focusout)': 'event($event)', - '(input)': 'event($event)', - '(invalid)': 'event($event)', - '(select)': 'event($event)' + '(click)': 'event($event)' }, imports: [TranslatePipe, ViewerComponent, ErrorWidgetComponent], encapsulation: ViewEncapsulation.None diff --git a/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts b/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts index da9c6852d0..76589d148e 100644 --- a/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/checkbox/checkbox.widget.spec.ts @@ -18,7 +18,6 @@ import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { MatCheckboxModule } from '@angular/material/checkbox'; import { UnitTestingUtils } from '../../../../testing'; import { FormFieldModel, FormFieldTypes, FormModel } from '../core'; import { CheckboxWidgetComponent } from './checkbox.widget'; @@ -31,7 +30,7 @@ describe('CheckboxWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [MatCheckboxModule] + imports: [CheckboxWidgetComponent] }); fixture = TestBed.createComponent(CheckboxWidgetComponent); widget = fixture.componentInstance; @@ -39,7 +38,23 @@ describe('CheckboxWidgetComponent', () => { testingUtils = new UnitTestingUtils(fixture.debugElement, loader); }); - afterEach(() => fixture.destroy()); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); describe('when template is ready', () => { beforeEach(() => { 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 eff9df2d5d..e04eadece1 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 @@ -23,9 +23,6 @@ import { FormFieldTypes } from '../core/form-field-types'; import { HarnessLoader, TestKey } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { addMinutes } from 'date-fns'; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatDatetimepickerModule, MatNativeDatetimeModule } from '@mat-datetimepicker/core'; -import { MatDatepickerModule } from '@angular/material/datepicker'; import { UnitTestingUtils } from '../../../../testing/unit-testing-utils'; describe('DateTimeWidgetComponent', () => { @@ -37,7 +34,7 @@ describe('DateTimeWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [MatDialogModule, MatNativeDatetimeModule, MatDatepickerModule, MatDatetimepickerModule, DateTimeWidgetComponent] + imports: [DateTimeWidgetComponent] }); fixture = TestBed.createComponent(DateTimeWidgetComponent); widget = fixture.componentInstance; @@ -51,6 +48,24 @@ describe('DateTimeWidgetComponent', () => { TestBed.resetTestingModule(); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should not call onFieldChanged on init', () => { spyOn(widget, 'onFieldChanged').and.callThrough(); expect(widget.onFieldChanged).not.toHaveBeenCalled(); 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 f74486d9d8..82d8a5d013 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 @@ -43,6 +43,9 @@ import { ReactiveFormWidget } from '../reactive-widget.interface'; ], templateUrl: './date-time.widget.html', styleUrls: ['./date-time.widget.scss'], + host: { + '(click)': 'event($event)' + }, imports: [NgIf, TranslatePipe, MatFormFieldModule, MatInputModule, MatDatetimepickerModule, ReactiveFormsModule, ErrorWidgetComponent], encapsulation: ViewEncapsulation.None }) 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 f3f6fedf68..1b2632230c 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 @@ -42,6 +42,24 @@ describe('DateWidgetComponent', () => { testingUtils = new UnitTestingUtils(fixture.debugElement); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should not call onFieldChanged on init', () => { spyOn(widget, 'onFieldChanged').and.callThrough(); expect(widget.onFieldChanged).not.toHaveBeenCalled(); diff --git a/lib/core/src/lib/form/components/widgets/decimal/decimal.component.spec.ts b/lib/core/src/lib/form/components/widgets/decimal/decimal.component.spec.ts index 3fdd71b3e5..e91062c385 100644 --- a/lib/core/src/lib/form/components/widgets/decimal/decimal.component.spec.ts +++ b/lib/core/src/lib/form/components/widgets/decimal/decimal.component.spec.ts @@ -18,7 +18,6 @@ import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { MatInputModule } from '@angular/material/input'; import { UnitTestingUtils } from '../../../../testing'; import { FormService } from '../../../services/form.service'; import { FormFieldModel, FormFieldTypes, FormModel } from '../core'; @@ -32,7 +31,7 @@ describe('DecimalComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [MatInputModule, DecimalWidgetComponent], + imports: [DecimalWidgetComponent], providers: [FormService] }); @@ -42,6 +41,24 @@ describe('DecimalComponent', () => { testingUtils = new UnitTestingUtils(fixture.debugElement, loader); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + describe('when tooltip is set', () => { beforeEach(() => { widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { diff --git a/lib/core/src/lib/form/components/widgets/display-text/display-text.widget.spec.ts b/lib/core/src/lib/form/components/widgets/display-text/display-text.widget.spec.ts new file mode 100644 index 0000000000..981bb4258d --- /dev/null +++ b/lib/core/src/lib/form/components/widgets/display-text/display-text.widget.spec.ts @@ -0,0 +1,52 @@ +/*! + * @license + * Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved. + * + * 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. + */ + +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { FormFieldModel, FormModel } from '../core'; +import { DisplayTextWidgetComponent } from './display-text.widget'; + +describe('DisplayTextWidgetComponent', () => { + let fixture: ComponentFixture; + let widget: DisplayTextWidgetComponent; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [DisplayTextWidgetComponent] + }); + + fixture = TestBed.createComponent(DisplayTextWidgetComponent); + widget = fixture.componentInstance; + }); + + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); +}); diff --git a/lib/core/src/lib/form/components/widgets/hyperlink/hyperlink.widget.spec.ts b/lib/core/src/lib/form/components/widgets/hyperlink/hyperlink.widget.spec.ts index 3a7e06a23a..04eb200bff 100644 --- a/lib/core/src/lib/form/components/widgets/hyperlink/hyperlink.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/hyperlink/hyperlink.widget.spec.ts @@ -34,6 +34,24 @@ describe('HyperlinkWidgetComponent', () => { testingUtils = new UnitTestingUtils(fixture.debugElement); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should get link text from field display text', () => { const text = 'hello world'; diff --git a/lib/core/src/lib/form/components/widgets/multiline-text/multiline-text.widget.spec.ts b/lib/core/src/lib/form/components/widgets/multiline-text/multiline-text.widget.spec.ts index ee5cbdc58d..e0b9a66e7c 100644 --- a/lib/core/src/lib/form/components/widgets/multiline-text/multiline-text.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/multiline-text/multiline-text.widget.spec.ts @@ -40,6 +40,24 @@ describe('MultilineTextWidgetComponentComponent', () => { testingUtils = new UnitTestingUtils(fixture.debugElement, loader); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + describe('when tooltip is set', () => { beforeEach(() => { widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { diff --git a/lib/core/src/lib/form/components/widgets/number/number.widget.spec.ts b/lib/core/src/lib/form/components/widgets/number/number.widget.spec.ts index 80c12b8031..843e3141fa 100644 --- a/lib/core/src/lib/form/components/widgets/number/number.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/number/number.widget.spec.ts @@ -18,8 +18,6 @@ import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { MatIconModule } from '@angular/material/icon'; -import { MatInputModule } from '@angular/material/input'; import { UnitTestingUtils } from '../../../../testing'; import { FormFieldModel, FormFieldTypes, FormModel } from '../core'; import { NumberWidgetComponent } from './number.widget'; @@ -36,7 +34,7 @@ describe('NumberWidgetComponent', () => { mockDecimalNumberPipe = jasmine.createSpyObj('DecimalNumberPipe', ['transform']); await TestBed.configureTestingModule({ - imports: [MatInputModule, MatIconModule] + imports: [NumberWidgetComponent] }) .overrideComponent(NumberWidgetComponent, { set: { @@ -51,8 +49,22 @@ describe('NumberWidgetComponent', () => { testingUtils = new UnitTestingUtils(fixture.debugElement, loader); }); - it('should create', () => { - expect(widget).toBeTruthy(); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); }); describe('with readonly true', () => { diff --git a/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts b/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts index a98f1694ab..45ce5a5fa6 100644 --- a/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts +++ b/lib/core/src/lib/form/components/widgets/text/text.widget.spec.ts @@ -43,6 +43,24 @@ describe('TextWidgetComponent', () => { testingUtils = new UnitTestingUtils(fixture.debugElement, loader); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + describe('when template is ready', () => { describe('and no mask is configured on text element', () => { it('should raise ngModelChange event', async () => { diff --git a/lib/core/src/lib/form/components/widgets/widget.component.ts b/lib/core/src/lib/form/components/widgets/widget.component.ts index 5bfe4ed911..9f5ba71278 100644 --- a/lib/core/src/lib/form/components/widgets/widget.component.ts +++ b/lib/core/src/lib/form/components/widgets/widget.component.ts @@ -29,7 +29,6 @@ import { FormFieldModel } from './core'; selector: 'base-widget', template: '', host: { - '(click)': 'event($event)', '(blur)': 'event($event)', '(change)': 'event($event)', '(focus)': 'event($event)', diff --git a/lib/insights/src/lib/analytics-process/components/widgets/checkbox/checkbox.widget.ts b/lib/insights/src/lib/analytics-process/components/widgets/checkbox/checkbox.widget.ts index 3e3912c65d..7a37781850 100644 --- a/lib/insights/src/lib/analytics-process/components/widgets/checkbox/checkbox.widget.ts +++ b/lib/insights/src/lib/analytics-process/components/widgets/checkbox/checkbox.widget.ts @@ -28,6 +28,9 @@ import { MatCheckboxModule } from '@angular/material/checkbox'; selector: 'analytics-checkbox-widget', imports: [CommonModule, TranslatePipe, ReactiveFormsModule, MatCheckboxModule], templateUrl: './checkbox.widget.html', + host: { + '(click)': 'event($event)' + }, encapsulation: ViewEncapsulation.None }) export class CheckboxWidgetAnalyticsComponent extends WidgetComponent { diff --git a/lib/insights/src/lib/analytics-process/components/widgets/dropdown/dropdown.widget.ts b/lib/insights/src/lib/analytics-process/components/widgets/dropdown/dropdown.widget.ts index 92dfa8c0f6..c2f6cf917e 100644 --- a/lib/insights/src/lib/analytics-process/components/widgets/dropdown/dropdown.widget.ts +++ b/lib/insights/src/lib/analytics-process/components/widgets/dropdown/dropdown.widget.ts @@ -28,6 +28,9 @@ import { TranslatePipe } from '@ngx-translate/core'; imports: [CommonModule, TranslatePipe, ReactiveFormsModule], templateUrl: './dropdown.widget.html', styleUrls: ['./dropdown.widget.scss'], + host: { + '(click)': 'event($event)' + }, encapsulation: ViewEncapsulation.None }) export class DropdownWidgetAnalyticsComponent extends WidgetComponent implements OnInit { diff --git a/lib/insights/src/lib/analytics-process/components/widgets/number/number.widget.ts b/lib/insights/src/lib/analytics-process/components/widgets/number/number.widget.ts index 96becfb556..7a388614b4 100644 --- a/lib/insights/src/lib/analytics-process/components/widgets/number/number.widget.ts +++ b/lib/insights/src/lib/analytics-process/components/widgets/number/number.widget.ts @@ -30,6 +30,9 @@ import { MatInputModule } from '@angular/material/input'; imports: [CommonModule, TranslatePipe, ReactiveFormsModule, MatFormFieldModule, MatInputModule], templateUrl: './number.widget.html', styleUrls: ['./number.widget.scss'], + host: { + '(click)': 'event($event)' + }, encapsulation: ViewEncapsulation.None }) export class NumberWidgetAnalyticsComponent extends WidgetComponent implements OnInit { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts index 49a9f8f58b..59d53a9cb7 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts @@ -170,8 +170,22 @@ describe('AttachFileCloudWidgetComponent', () => { }); }); - afterEach(() => { - fixture.destroy(); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); }); it('should show up as simple upload when is configured for only local files', async () => { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts index 6ca23b6ca1..0f2edc3778 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts @@ -56,17 +56,6 @@ const VALID_ALIAS = [ALIAS_ROOT_FOLDER, ALIAS_USER_FOLDER, '-shared-']; imports: [CommonModule, ErrorWidgetComponent, TranslatePipe, MatIconModule, FilePropertiesTableCloudComponent, MatButtonModule], templateUrl: './attach-file-cloud-widget.component.html', styleUrls: ['./attach-file-cloud-widget.component.scss'], - host: { - '(click)': 'event($event)', - '(blur)': 'event($event)', - '(change)': 'event($event)', - '(focus)': 'event($event)', - '(focusin)': 'event($event)', - '(focusout)': 'event($event)', - '(input)': 'event($event)', - '(invalid)': 'event($event)', - '(select)': 'event($event)' - }, encapsulation: ViewEncapsulation.None }) export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent implements OnInit, OnDestroy { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.spec.ts index e3d472e77c..13361c1ee0 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/data-table/data-table.widget.spec.ts @@ -96,6 +96,24 @@ describe('DataTableWidgetComponent', () => { }); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should display label', () => { fixture.detectChanges(); 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 e580266dd3..b175b69549 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 @@ -48,6 +48,24 @@ describe('DateCloudWidgetComponent', () => { testingUtils = new UnitTestingUtils(fixture.debugElement, loader); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should not call onFieldChanged on init', () => { spyOn(widget, 'onFieldChanged').and.callThrough(); expect(widget.onFieldChanged).not.toHaveBeenCalled(); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.spec.ts index 62a44de2f7..8a838753c1 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/display-external-property/display-external-property.widget.spec.ts @@ -46,6 +46,24 @@ describe('DisplayExternalPropertyWidgetComponent', () => { testingUtils = new UnitTestingUtils(fixture.debugElement, loader); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should display initial value', async () => { widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { type: FormFieldTypes.DISPLAY_EXTERNAL_PROPERTY, diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/display-rich-text/display-rich-text.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/display-rich-text/display-rich-text.widget.spec.ts index 64785f5a30..c1e3f6acf3 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/display-rich-text/display-rich-text.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/display-rich-text/display-rich-text.widget.spec.ts @@ -20,6 +20,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DisplayRichTextWidgetComponent, RICH_TEXT_PARSER_TOKEN } from './display-rich-text.widget'; import { RichTextParserService } from '../../../services/rich-text-parser.service'; +import { FormFieldModel, FormModel } from '@alfresco/adf-core'; describe('DisplayRichTextWidgetComponent', () => { let widget: DisplayRichTextWidgetComponent; @@ -96,6 +97,24 @@ describe('DisplayRichTextWidgetComponent', () => { widget.field = fakeFormField; }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should call RichTextParserService.parse() method', () => { fixture.detectChanges(); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts index a816f8c356..b030a4a81c 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts @@ -74,6 +74,24 @@ describe('DropdownCloudWidgetComponent', () => { afterEach(() => fixture.destroy()); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + describe('Simple Dropdown', () => { beforeEach(() => { widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', readOnly: false, id: 'form-id' }), { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts index 81eaf37204..3eb04db352 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts @@ -29,7 +29,7 @@ import { SelectFilterInputComponent, WidgetComponent } from '@alfresco/adf-core'; -import { AsyncPipe, NgClass, NgFor, NgIf } from '@angular/common'; +import { AsyncPipe, NgClass, NgIf } from '@angular/common'; import { Component, DestroyRef, inject, OnInit, ViewEncapsulation } from '@angular/core'; import { FormControl, ReactiveFormsModule, Validators } from '@angular/forms'; import { MatFormFieldModule } from '@angular/material/form-field'; @@ -56,10 +56,12 @@ export const DROPDOWN_CLOUD_WIDGET_SET_VALUE_DEBOUNCE = 100; selector: 'dropdown-cloud-widget', templateUrl: './dropdown-cloud.widget.html', styleUrls: ['./dropdown-cloud.widget.scss'], + host: { + '(click)': 'event($event)' + }, encapsulation: ViewEncapsulation.None, imports: [ NgIf, - NgFor, NgClass, AsyncPipe, ReactiveFormsModule, diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.spec.ts index ee9c665e97..0cf5163781 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.spec.ts @@ -51,6 +51,24 @@ describe('FileViewerWidgetComponent', () => { widget = fixture.componentInstance; }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should set the file id corretly when the field value is an array', async () => { widget.field = new FormFieldModel(fakeForm, { id: 'fakeField', value: [fakePngAnswer] }); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.ts index 3473f87b69..99570f21f6 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/file-viewer/file-viewer.widget.ts @@ -27,17 +27,6 @@ import { TranslatePipe } from '@ngx-translate/core'; imports: [ErrorWidgetComponent, AlfrescoViewerComponent, TranslatePipe], templateUrl: './file-viewer.widget.html', styleUrls: ['./file-viewer.widget.scss'], - host: { - '(click)': 'event($event)', - '(blur)': 'event($event)', - '(change)': 'event($event)', - '(focus)': 'event($event)', - '(focusin)': 'event($event)', - '(focusout)': 'event($event)', - '(input)': 'event($event)', - '(invalid)': 'event($event)', - '(select)': 'event($event)' - }, encapsulation: ViewEncapsulation.None }) export class FileViewerWidgetComponent extends BaseViewerWidgetComponent { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts index d9b87e94a9..b712a0501d 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/group/group-cloud.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { FormFieldModel, FormFieldTypes, FormModel, IdentityGroupModel, NoopAuthModule, CoreModule } from '@alfresco/adf-core'; +import { FormFieldModel, FormFieldTypes, FormModel, IdentityGroupModel, NoopAuthModule } from '@alfresco/adf-core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { GroupCloudWidgetComponent } from './group-cloud.widget'; import { HarnessLoader } from '@angular/cdk/testing'; @@ -30,7 +30,7 @@ describe('GroupCloudWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [CoreModule.forRoot(), NoopAuthModule, GroupCloudWidgetComponent] + imports: [NoopAuthModule, GroupCloudWidgetComponent] }); fixture = TestBed.createComponent(GroupCloudWidgetComponent); widget = fixture.componentInstance; @@ -38,8 +38,22 @@ describe('GroupCloudWidgetComponent', () => { loader = TestbedHarnessEnvironment.loader(fixture); }); - afterEach(() => { - fixture.destroy(); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); }); it('should have enabled validation if field is NOT readOnly', () => { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts index c583bc7dae..7b2aa0a181 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/people/people-cloud.widget.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { FormFieldModel, FormFieldTypes, FormModel, IdentityUserModel, NoopAuthModule, CoreModule } from '@alfresco/adf-core'; +import { FormFieldModel, FormFieldTypes, FormModel, IdentityUserModel, NoopAuthModule } from '@alfresco/adf-core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { PeopleCloudWidgetComponent } from './people-cloud.widget'; import { IdentityUserService } from '../../../../people/services/identity-user.service'; @@ -33,7 +33,7 @@ describe('PeopleCloudWidgetComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [CoreModule.forRoot(), NoopAuthModule, PeopleCloudWidgetComponent] + imports: [NoopAuthModule, PeopleCloudWidgetComponent] }); identityUserService = TestBed.inject(IdentityUserService); fixture = TestBed.createComponent(PeopleCloudWidgetComponent); @@ -43,8 +43,22 @@ describe('PeopleCloudWidgetComponent', () => { loader = TestbedHarnessEnvironment.loader(fixture); }); - afterEach(() => { - fixture.destroy(); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); }); it('should preselect the current user', () => { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.spec.ts index eef6be50a9..ffdd126c2f 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.spec.ts @@ -57,7 +57,23 @@ describe('PropertiesViewerWidgetComponent', () => { spyOn(nodesApiService, 'getNode').and.returnValue(of(fakeNodeWithProperties)); }); - afterEach(() => fixture.destroy()); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); it('should not display properties viewer when value is not set', async () => { widget.field.value = undefined; diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.ts index e305de3a1f..fed3102342 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/properties-viewer/properties-viewer.widget.ts @@ -29,17 +29,6 @@ import { CommonModule } from '@angular/common'; imports: [CommonModule, ErrorWidgetComponent, PropertiesViewerWrapperComponent, TranslatePipe], templateUrl: './properties-viewer.widget.html', styleUrls: ['./properties-viewer.widget.scss'], - host: { - '(click)': 'event($event)', - '(blur)': 'event($event)', - '(change)': 'event($event)', - '(focus)': 'event($event)', - '(focusin)': 'event($event)', - '(focusout)': 'event($event)', - '(input)': 'event($event)', - '(invalid)': 'event($event)', - '(select)': 'event($event)' - }, encapsulation: ViewEncapsulation.None }) export class PropertiesViewerWidgetComponent extends BaseViewerWidgetComponent { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.spec.ts index 7053d13621..2754f53eb7 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/radio-buttons/radio-buttons-cloud.widget.spec.ts @@ -56,6 +56,24 @@ describe('RadioButtonsCloudWidgetComponent', () => { widget.field = new FormFieldModel(new FormModel(), { restUrl: '' }); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should update form on values fetched', () => { spyOn(formCloudService, 'getRestWidgetData').and.returnValue(of(restOption)); const taskId = ''; diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/upload/upload-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/upload/upload-cloud.widget.spec.ts new file mode 100644 index 0000000000..c7502ae659 --- /dev/null +++ b/lib/process-services-cloud/src/lib/form/components/widgets/upload/upload-cloud.widget.spec.ts @@ -0,0 +1,58 @@ +/*! + * @license + * Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved. + * + * 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. + */ + +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { UploadCloudWidgetComponent } from './upload-cloud.widget'; +import { FormFieldModel, FormModel, ThumbnailService, NotificationService } from '@alfresco/adf-core'; +import { ProcessCloudContentService } from '../../../services/process-cloud-content.service'; + +describe('UploadCloudWidgetComponent', () => { + let fixture: ComponentFixture; + let widget: UploadCloudWidgetComponent; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [UploadCloudWidgetComponent], + providers: [ + { provide: ThumbnailService, useValue: {} }, + { provide: ProcessCloudContentService, useValue: {} }, + { provide: NotificationService, useValue: {} } + ] + }); + + fixture = TestBed.createComponent(UploadCloudWidgetComponent); + widget = fixture.componentInstance; + }); + + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); +}); diff --git a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.spec.ts b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.spec.ts index cf0c77e647..a41078764f 100644 --- a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.spec.ts +++ b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.spec.ts @@ -207,6 +207,27 @@ describe('AttachFileWidgetComponent', () => { return showFileButton.isDisabled(); }; + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of([])); + spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(of({})); + eventSpy = spyOn(widget, 'event').and.callThrough(); + + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should add file to tempFilesList when form has value and file source is configured', () => { spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer)); spyOn(widget, 'isFileSourceConfigured').and.returnValue(true); diff --git a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.ts b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.ts index 78c72b5eae..1a688074ed 100644 --- a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.ts +++ b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget.component.ts @@ -41,17 +41,6 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; imports: [CommonModule, TranslatePipe, MatIconModule, MatButtonModule, MatMenuModule, MatListModule, ErrorWidgetComponent, AlfrescoIconComponent], templateUrl: './attach-file-widget.component.html', styleUrls: ['./attach-file-widget.component.scss'], - host: { - '(click)': 'event($event)', - '(blur)': 'event($event)', - '(change)': 'event($event)', - '(focus)': 'event($event)', - '(focusin)': 'event($event)', - '(focusout)': 'event($event)', - '(input)': 'event($event)', - '(invalid)': 'event($event)', - '(select)': 'event($event)' - }, encapsulation: ViewEncapsulation.None }) export class AttachFileWidgetComponent extends UploadWidgetComponent implements OnInit { diff --git a/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.spec.ts b/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.spec.ts index 011502504a..57d191c937 100644 --- a/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/dropdown/dropdown.widget.spec.ts @@ -54,6 +54,24 @@ describe('DropdownWidgetComponent', () => { loader = TestbedHarnessEnvironment.loader(fixture); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should require field with restUrl', () => { spyOn(taskFormService, 'getRestFieldValues').and.stub(); diff --git a/lib/process-services/src/lib/form/widgets/file-viewer/file-viewer.widget.spec.ts b/lib/process-services/src/lib/form/widgets/file-viewer/file-viewer.widget.spec.ts index eede774fbf..12c1e26a33 100644 --- a/lib/process-services/src/lib/form/widgets/file-viewer/file-viewer.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/file-viewer/file-viewer.widget.spec.ts @@ -57,6 +57,24 @@ describe('FileViewerWidgetComponent', () => { widget = fixture.componentInstance; }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + it('should set the file id corretly when the field value is an array', (done) => { const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: [fakePngAnswer] }); widget.field = fakeField; diff --git a/lib/process-services/src/lib/form/widgets/file-viewer/file-viewer.widget.ts b/lib/process-services/src/lib/form/widgets/file-viewer/file-viewer.widget.ts index 08420d1cab..6c1acfdc43 100644 --- a/lib/process-services/src/lib/form/widgets/file-viewer/file-viewer.widget.ts +++ b/lib/process-services/src/lib/form/widgets/file-viewer/file-viewer.widget.ts @@ -28,17 +28,6 @@ import { AlfrescoViewerComponent } from '@alfresco/adf-content-services'; imports: [CommonModule, TranslatePipe, AlfrescoViewerComponent, ErrorWidgetComponent], templateUrl: './file-viewer.widget.html', styleUrls: ['./file-viewer.widget.scss'], - host: { - '(click)': 'event($event)', - '(blur)': 'event($event)', - '(change)': 'event($event)', - '(focus)': 'event($event)', - '(focusin)': 'event($event)', - '(focusout)': 'event($event)', - '(input)': 'event($event)', - '(invalid)': 'event($event)', - '(select)': 'event($event)' - }, encapsulation: ViewEncapsulation.None }) export class FileViewerWidgetComponent extends BaseViewerWidgetComponent { diff --git a/lib/process-services/src/lib/form/widgets/people/people.widget.spec.ts b/lib/process-services/src/lib/form/widgets/people/people.widget.spec.ts index 486b9ab076..cc5c7bf7ba 100644 --- a/lib/process-services/src/lib/form/widgets/people/people.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/people/people.widget.spec.ts @@ -56,6 +56,24 @@ describe('PeopleWidgetComponent', () => { fixture.detectChanges(); }); + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(widget, 'event').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); + describe('display name', () => { it('should return empty display name for missing model', () => { expect(widget.getDisplayName(null)).toBe(''); diff --git a/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts b/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts index d8f322b151..1585a17d70 100644 --- a/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts +++ b/lib/process-services/src/lib/form/widgets/upload/upload.widget.spec.ts @@ -383,5 +383,23 @@ describe('UploadWidgetComponent', () => { fileJpegIcon.nativeElement.dispatchEvent(new MouseEvent('click')); }); }); + + describe('event tracking', () => { + let eventSpy: jasmine.Spy; + + beforeEach(() => { + eventSpy = spyOn(uploadWidgetComponent, 'event').and.callThrough(); + uploadWidgetComponent.field = new FormFieldModel(new FormModel(), {}); + fixture.detectChanges(); + }); + + it('should call event method only once when widget is clicked', () => { + const clickEvent = new MouseEvent('click', { bubbles: true }); + fixture.debugElement.nativeElement.dispatchEvent(clickEvent); + + expect(eventSpy).toHaveBeenCalledTimes(1); + expect(eventSpy).toHaveBeenCalledWith(clickEvent); + }); + }); }); });