mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-15839] Fix file object input in viewers (#8804)
* [AAE-15839] Fix file object input in viewers * [AAE-15839] Attend review comments * [AAE-15839] Remove duplication * [AAE-15839] Fix package-lock.json * [AAE-15839] Fix package.json * [AAE-15839] Remove duplication * [AAE-15839] Remove duplication
This commit is contained in:
committed by
GitHub
parent
1f96c3452c
commit
04803c1815
@@ -60,26 +60,27 @@ describe('BaseViewerWidgetComponent', () => {
|
||||
});
|
||||
|
||||
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;
|
||||
assertFileId([fakePngAnswer], '1933', fakeForm, widget, fixture, done);
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(widget.field.value).toBe('1933');
|
||||
done();
|
||||
});
|
||||
it('should set the file id corretly when the field value is an object', (done) => {
|
||||
assertFileId(fakePngAnswer, '1933', fakeForm, widget, fixture, done);
|
||||
});
|
||||
|
||||
it('should set the file id corretly when the field value is a string', (done) => {
|
||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' });
|
||||
widget.field = fakeField;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(widget.field.value).toBe('fakeValue');
|
||||
done();
|
||||
});
|
||||
assertFileId('fakeValue', 'fakeValue', fakeForm, widget, fixture, done);
|
||||
});
|
||||
});
|
||||
|
||||
function assertFileId(value: any, expectedFileId: string, fakeForm: FormModel, widget: BaseViewerWidgetComponent, fixture: ComponentFixture<BaseViewerWidgetComponent>, done: DoneFn) {
|
||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value });
|
||||
widget.field = fakeField;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(widget.field.value).toBe(expectedFileId);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { FormService } from '../../../services/form.service';
|
||||
import { WidgetComponent } from '../widget.component';
|
||||
|
||||
/* eslint-disable @angular-eslint/component-selector */
|
||||
/* eslint-disable @angular-eslint/component-selector */
|
||||
|
||||
@Component({
|
||||
selector: 'base-viewer-widget',
|
||||
@@ -44,12 +44,13 @@ export class BaseViewerWidgetComponent extends WidgetComponent implements OnInit
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.field &&
|
||||
this.field.value &&
|
||||
Array.isArray(this.field.value) &&
|
||||
this.field.value.length) {
|
||||
const file = this.field.value[0];
|
||||
this.field.value = file.id;
|
||||
if (this.field?.value) {
|
||||
if (Array.isArray(this.field.value) && this.field.value.length > 0) {
|
||||
const file = this.field.value[0];
|
||||
this.field.value = file.id;
|
||||
} else if (typeof this.field.value === 'object' && this.field.value.id) {
|
||||
this.field.value = this.field.value.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user