AAE-10842: Modified properties viewer widget to handle file input (#7900)

* AAE-10842: Modified properties viewer widget to handle file input

* AAE-10842: Fixed linting issue

* trigger Codacy
This commit is contained in:
Ehsan Rezaei 2022-11-02 11:48:00 +01:00 committed by GitHub
parent 68d6d15142
commit b48784a04e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 2 deletions

View File

@ -36,6 +36,21 @@ describe('PropertiesViewerWidgetComponent', () => {
let element: HTMLElement; let element: HTMLElement;
let nodesApiService: NodesApiService; let nodesApiService: NodesApiService;
const fakePngAnswer: any = {
id: '1933',
link: false,
isExternal: false,
relatedContent: false,
contentAvailable: true,
name: 'a_png_file.png',
simpleType: 'image',
mimeType: 'image/png',
previewStatus: 'queued',
thumbnailStatus: 'queued',
created: '2022-10-14T17:17:37.099Z',
createdBy: { id: 1001, firstName: 'Admin', lastName: 'admin', email: 'admin@example.com' }
};
setupTestBed({ setupTestBed({
imports: [ imports: [
TranslateModule.forRoot(), TranslateModule.forRoot(),
@ -92,4 +107,15 @@ describe('PropertiesViewerWidgetComponent', () => {
expect(nodeContentLoadedSpy).toHaveBeenCalledWith(fakeNodeWithProperties); expect(nodeContentLoadedSpy).toHaveBeenCalledWith(fakeNodeWithProperties);
}); });
it('should set NodeId crrectly when field value is array of file instead of string', async () => {
const fakeField = new FormFieldModel(new FormModel(), { id: 'fakeField', value: [fakePngAnswer] });
widget.field = fakeField;
fixture.detectChanges();
await fixture.whenStable();
expect(widget.field.value).toBe('1933');
});
}); });

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, EventEmitter, Output, ViewEncapsulation } from '@angular/core'; import { Component, EventEmitter, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { FormService, WidgetComponent } from '@alfresco/adf-core'; import { FormService, WidgetComponent } from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api'; import { Node } from '@alfresco/js-api';
@ -38,7 +38,7 @@ import { Node } from '@alfresco/js-api';
}, },
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })
export class PropertiesViewerWidgetComponent extends WidgetComponent { export class PropertiesViewerWidgetComponent extends WidgetComponent implements OnInit {
@Output() @Output()
nodeContentLoaded: EventEmitter<Node> = new EventEmitter(); nodeContentLoaded: EventEmitter<Node> = new EventEmitter();
@ -47,6 +47,16 @@ export class PropertiesViewerWidgetComponent extends WidgetComponent {
super(formService); super(formService);
} }
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;
}
}
onNodeContentLoaded(node: Node) { onNodeContentLoaded(node: Node) {
this.nodeContentLoaded.emit(node); this.nodeContentLoaded.emit(node);
} }