mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
AAE-39612 Registering click event on form widget twice (#11323)
* AAE-39612 Remove click from base and add it directly to the implementations * AAE-39612 Add unit tests for the Text Widgets * AAE-39612 Add unit tests for the Date Widgets * AAE-39612 Add unit tests for the UI Widgets * AAE-39612 Add unit tests for the People Widgets * AAE-39612 Add unit tests for the Display Text Widgets * AAE-39612 Add unit tests for the Base Viewer Widget * AAE-39612 Add unit tests for the Object View Widgets * AAE-39612 Add unit tests for the File Upload Widgets * AAE-39612 Add unit tests for the Data Table Widget
This commit is contained in:
+21
@@ -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);
|
||||
|
||||
-11
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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('');
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user