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 edc2e47d64..43d967532f 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 @@ -34,7 +34,7 @@ import { } from '@alfresco/adf-core'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; -import { ContentModule } from '@alfresco/adf-content-services'; +import { ContentModule, ContentNodeSelectorPanelService } from '@alfresco/adf-content-services'; import { By } from '@angular/platform-browser'; import { of } from 'rxjs'; import { Node } from '@alfresco/js-api'; @@ -51,6 +51,7 @@ describe('AttachFileCloudWidgetComponent', () => { let formService: FormService; let downloadService: DownloadService; let alfrescoApiService: AlfrescoApiService; + let contentNodeSelectorPanelService: ContentNodeSelectorPanelService; let apiServiceSpy: jasmine.Spy; let contentModelFormFileHandlerSpy: jasmine.Spy; let updateFormSpy: jasmine.Spy; @@ -208,6 +209,7 @@ describe('AttachFileCloudWidgetComponent', () => { ); formService = TestBed.inject(FormService); alfrescoApiService = TestBed.inject(AlfrescoApiService); + contentNodeSelectorPanelService = TestBed.inject(ContentNodeSelectorPanelService); })); afterEach(() => { @@ -326,6 +328,13 @@ describe('AttachFileCloudWidgetComponent', () => { }); }); + it('should reset the custom models when the component gets destroyed', () => { + contentNodeSelectorPanelService.customModels = ['mock-value']; + widget.ngOnDestroy(); + + expect(contentNodeSelectorPanelService.customModels).toEqual([]); + }); + describe('destinationFolderPath', () => { let openUploadFileDialogSpy: jasmine.Spy; diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts index 7b5f124d92..55cc013502 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts @@ -17,7 +17,7 @@ /* tslint:disable:component-selector */ -import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; import { FormService, LogService, @@ -53,7 +53,7 @@ import { ContentNodeSelectorPanelService } from '@alfresco/adf-content-services' }, encapsulation: ViewEncapsulation.None }) -export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent implements OnInit { +export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent implements OnInit, OnDestroy { static ALIAS_ROOT_FOLDER = '-root-'; static ALIAS_USER_FOLDER = '-my-'; @@ -217,4 +217,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i isValidAlias(alias: string): boolean { return alias && AttachFileCloudWidgetComponent.VALID_ALIAS.includes(alias); } + + ngOnDestroy() { + this.contentNodeSelectorPanelService.customModels = []; + } }