From 3cf12fca49aa18acb1b8db5faf1f6b79f51b00ca Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Tue, 14 Jan 2020 00:14:11 +0100 Subject: [PATCH] fix readonly attach file scenarios (#5365) --- lib/core/i18n/en.json | 1 + .../attach-file-cloud-widget.component.html | 35 +++++++------ ...attach-file-cloud-widget.component.spec.ts | 50 +++++++++++++++++++ .../attach-file/upload-cloud.widget.html | 5 ++ 4 files changed, 76 insertions(+), 15 deletions(-) diff --git a/lib/core/i18n/en.json b/lib/core/i18n/en.json index b52e26efe3..c108b9364f 100644 --- a/lib/core/i18n/en.json +++ b/lib/core/i18n/en.json @@ -26,6 +26,7 @@ "REMOVE_FILE": "Remove", "UPLOAD": "UPLOAD", "REQUIRED": "*Required", + "NO_FILE_ATTACHED" : "No file attached", "VALIDATOR": { "INVALID_NUMBER": "Use a different number format", "INVALID_DATE": "Use a different date format", diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.html b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.html index 1d127e9e09..310aa6fce4 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.html +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.html @@ -1,6 +1,6 @@
+ [class.adf-invalid]="!field.isValid" + [class.adf-readonly]="field.readOnly"> @@ -10,26 +10,27 @@ {{ 'FORM.FIELD.UPLOAD' | translate }} file_upload + [multiple]="multipleOption" + type="file" + [id]="field.id" + (change)="onAttachFileChanged($event)"/>
@@ -53,12 +54,12 @@ @@ -71,6 +72,10 @@ +
+ {{ 'FORM.FIELD.NO_FILE_ATTACHED' | translate }} +
+
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 5eedaccd00..7179d8d6d9 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 @@ -234,6 +234,56 @@ describe('AttachFileCloudWidgetComponent', () => { }); })); + describe('when is readonly', () => { + + it('should show empty list message when there are no file', async(() => { + widget.field = new FormFieldModel(new FormModel(), { + type: FormFieldTypes.UPLOAD, + readOnly: true, + value: [] + }); + widget.field.id = 'empty-test'; + widget.field.params = onlyLocalParams; + fixture.detectChanges(); + fixture.whenStable().then(() => { + expect(element.querySelector('#adf-attach-empty-list-empty-test')).not.toBeNull(); + }); + })); + + it('should not show empty list message when there are files', async(() => { + widget.field = new FormFieldModel(new FormModel(), { + type: FormFieldTypes.UPLOAD, + readOnly: true, + value: [fakePngAnswer] + }); + widget.field.id = 'fill-test'; + widget.field.params = onlyLocalParams; + fixture.detectChanges(); + fixture.whenStable().then(() => { + expect(element.querySelector('#adf-attach-empty-list-fill-test')).toBeNull(); + }); + })); + + it('should not show remove button when there are files attached', async(() => { + widget.field = new FormFieldModel(new FormModel(), { + type: FormFieldTypes.UPLOAD, + readOnly: true, + value: [fakePngAnswer] + }); + widget.field.id = 'fill-test'; + widget.field.params = onlyLocalParams; + + fixture.detectChanges(); + const menuButton: HTMLButtonElement = ( + fixture.debugElement.query(By.css('#file-1155-option-menu')) + .nativeElement + ); + menuButton.click(); + fixture.detectChanges(); + expect(fixture.debugElement.query(By.css('#file-1155-remove'))).toBeNull(); + })); + }); + describe('when a file is uploaded', () => { beforeEach(async(() => { widget.field = new FormFieldModel(new FormModel(), { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.html b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.html index dab71df2f2..df871e9720 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.html +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.html @@ -34,6 +34,11 @@ (change)="onFileChanged($event)"/> + +
+ {{ 'FORM.FIELD.NO_FILE_ATTACHED' | translate }} +
+