mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-10803: Modified file viewer widget to handle file input (#7898)
* AAE-10803: Modified file viewer widget to handle file input * AAE-10803: Fixed linting errors
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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 { FormModel } from '../core/form.model';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { FormFieldModel } from '../core/form-field.model';
|
||||
import { FormService } from '../../../services/form.service';
|
||||
import { FileViewerWidgetComponent } from './file-viewer.widget';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
describe('FileViewerWidgetComponent', () => {
|
||||
const fakeForm = new FormModel();
|
||||
let widget: FileViewerWidgetComponent;
|
||||
let formServiceStub: Partial<FormService>;
|
||||
let fixture: ComponentFixture<FileViewerWidgetComponent>;
|
||||
|
||||
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' }
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot()
|
||||
],
|
||||
declarations: [ FileViewerWidgetComponent ],
|
||||
providers: [ { provide: FormService, useValue: formServiceStub } ]
|
||||
});
|
||||
|
||||
formServiceStub = TestBed.inject(FormService);
|
||||
fixture = TestBed.createComponent(FileViewerWidgetComponent);
|
||||
widget = fixture.componentInstance;
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(widget.field.value).toBe('1933');
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, ViewEncapsulation } from '@angular/core';
|
||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { FormService } from '../../../services/form.service';
|
||||
import { WidgetComponent } from '../widget.component';
|
||||
|
||||
@@ -38,9 +38,18 @@ import { WidgetComponent } from '../widget.component';
|
||||
},
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class FileViewerWidgetComponent extends WidgetComponent {
|
||||
|
||||
export class FileViewerWidgetComponent extends WidgetComponent implements OnInit {
|
||||
constructor(formService: 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user