[AAE-3886] Cleanup the customModels when the attach file widget component gets destroyed (#6275)

This commit is contained in:
arditdomi
2020-10-22 15:36:37 +01:00
committed by GitHub
parent 37fef5a1b6
commit 278c28c684
2 changed files with 16 additions and 3 deletions

View File

@@ -34,7 +34,7 @@ import {
} from '@alfresco/adf-core'; } from '@alfresco/adf-core';
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 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 { By } from '@angular/platform-browser';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { Node } from '@alfresco/js-api'; import { Node } from '@alfresco/js-api';
@@ -51,6 +51,7 @@ describe('AttachFileCloudWidgetComponent', () => {
let formService: FormService; let formService: FormService;
let downloadService: DownloadService; let downloadService: DownloadService;
let alfrescoApiService: AlfrescoApiService; let alfrescoApiService: AlfrescoApiService;
let contentNodeSelectorPanelService: ContentNodeSelectorPanelService;
let apiServiceSpy: jasmine.Spy; let apiServiceSpy: jasmine.Spy;
let contentModelFormFileHandlerSpy: jasmine.Spy; let contentModelFormFileHandlerSpy: jasmine.Spy;
let updateFormSpy: jasmine.Spy; let updateFormSpy: jasmine.Spy;
@@ -208,6 +209,7 @@ describe('AttachFileCloudWidgetComponent', () => {
); );
formService = TestBed.inject(FormService); formService = TestBed.inject(FormService);
alfrescoApiService = TestBed.inject(AlfrescoApiService); alfrescoApiService = TestBed.inject(AlfrescoApiService);
contentNodeSelectorPanelService = TestBed.inject(ContentNodeSelectorPanelService);
})); }));
afterEach(() => { 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', () => { describe('destinationFolderPath', () => {
let openUploadFileDialogSpy: jasmine.Spy; let openUploadFileDialogSpy: jasmine.Spy;

View File

@@ -17,7 +17,7 @@
/* tslint:disable:component-selector */ /* tslint:disable:component-selector */
import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { import {
FormService, FormService,
LogService, LogService,
@@ -53,7 +53,7 @@ import { ContentNodeSelectorPanelService } from '@alfresco/adf-content-services'
}, },
encapsulation: ViewEncapsulation.None 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_ROOT_FOLDER = '-root-';
static ALIAS_USER_FOLDER = '-my-'; static ALIAS_USER_FOLDER = '-my-';
@@ -217,4 +217,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
isValidAlias(alias: string): boolean { isValidAlias(alias: string): boolean {
return alias && AttachFileCloudWidgetComponent.VALID_ALIAS.includes(alias); return alias && AttachFileCloudWidgetComponent.VALID_ALIAS.includes(alias);
} }
ngOnDestroy() {
this.contentNodeSelectorPanelService.customModels = [];
}
} }