From af3c7eb78384db9fb0e491f3ad7615bd3a1a33fa Mon Sep 17 00:00:00 2001 From: DominikIwanek <141320833+DominikIwanek@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:28:10 +0200 Subject: [PATCH] [ACS-5505] - Custom aspect properties are not updated when removing last existing property (#8828) * [ACS-5505] - Custom aspect properties are not updated when removing last existing property --- .../content-metadata.component.spec.ts | 69 ++++++++++++++----- .../content-metadata.component.ts | 26 +++++-- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts b/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts index b70f495557..180112d0e3 100644 --- a/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts +++ b/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.spec.ts @@ -15,25 +15,46 @@ * limitations under the License. */ -import { ComponentFixture, TestBed, tick, fakeAsync, discardPeriodicTasks, flush } from '@angular/core/testing'; +import { ComponentFixture, discardPeriodicTasks, fakeAsync, flush, TestBed, tick } from '@angular/core/testing'; import { DebugElement, SimpleChange } from '@angular/core'; import { By } from '@angular/platform-browser'; -import { Category, CategoryPaging, ClassesApi, MinimalNode, Node, Tag, TagBody, TagEntry, TagPaging, TagPagingList } from '@alfresco/js-api'; +import { + Category, + CategoryPaging, + ClassesApi, + MinimalNode, + Node, + Tag, + TagBody, + TagEntry, + TagPaging, + TagPagingList +} from '@alfresco/js-api'; import { ContentMetadataComponent } from './content-metadata.component'; import { ContentMetadataService } from '../../services/content-metadata.service'; import { - CardViewBaseItemModel, CardViewComponent, - LogService, AppConfigService, UpdateNotification + AppConfigService, + CardViewBaseItemModel, + CardViewComponent, + LogService, + UpdateNotification } from '@alfresco/adf-core'; import { NodesApiService } from '../../../common/services/nodes-api.service'; -import { throwError, of, EMPTY } from 'rxjs'; +import { EMPTY, of, throwError } from 'rxjs'; import { ContentTestingModule } from '../../../testing/content.testing.module'; import { mockGroupProperties } from './mock-data'; import { TranslateModule } from '@ngx-translate/core'; import { CardViewContentUpdateService } from '../../../common/services/card-view-content-update.service'; import { PropertyGroup } from '../../interfaces/property-group.interface'; import { PropertyDescriptorsService } from '../../services/property-descriptors.service'; -import { CategoriesManagementComponent, CategoriesManagementMode, CategoryService, TagsCreatorComponent, TagsCreatorMode, TagService } from '@alfresco/adf-content-services'; +import { + CategoriesManagementComponent, + CategoriesManagementMode, + CategoryService, + TagsCreatorComponent, + TagsCreatorMode, + TagService +} from '@alfresco/adf-content-services'; describe('ContentMetadataComponent', () => { let component: ContentMetadataComponent; @@ -100,6 +121,22 @@ describe('ContentMetadataComponent', () => { return fixture.debugElement.query(By.css('.adf-metadata-categories-title button')).nativeElement; } + async function updateAspectProperty(newValue: string): Promise { + component.editable = true; + const property = {key: 'properties.property-key', value: 'original-value'} as CardViewBaseItemModel; + const expectedNode = {...node, name: 'some-modified-value'}; + spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode)); + + updateService.update(property, newValue); + tick(600); + + fixture.detectChanges(); + await fixture.whenStable(); + clickOnSave(); + + await fixture.whenStable(); + } + beforeEach(() => { TestBed.configureTestingModule({ imports: [ @@ -221,23 +258,19 @@ describe('ContentMetadataComponent', () => { })); it('should save changedProperties on save click', fakeAsync(async () => { - component.editable = true; - const property = { key: 'properties.property-key', value: 'original-value' } as CardViewBaseItemModel; const expectedNode = { ...node, name: 'some-modified-value' }; - spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode)); - - updateService.update(property, 'updated-value'); - tick(600); - - fixture.detectChanges(); - await fixture.whenStable(); - clickOnSave(); - - await fixture.whenStable(); + await updateAspectProperty('updated-value'); expect(component.node).toEqual(expectedNode); expect(nodesApiService.updateNode).toHaveBeenCalled(); })); + it('should save changedProperties which delete property and update node on save click', fakeAsync(async () => { + const expectedNode = {...node, name: 'some-modified-value'}; + await updateAspectProperty(''); + expect(component.node).toEqual({...expectedNode, properties: {}}); + expect(nodesApiService.updateNode).toHaveBeenCalled(); + })); + it('should call removeTag and assignTagsToNode on TagService on save click', fakeAsync( () => { component.editable = true; component.displayTags = true; diff --git a/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.ts b/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.ts index 87ad4828eb..27250ef567 100644 --- a/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.ts +++ b/lib/content-services/src/lib/content-metadata/components/content-metadata/content-metadata.component.ts @@ -16,19 +16,28 @@ */ import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core'; -import { Category, CategoryEntry, CategoryLinkBody, CategoryPaging, Node, TagBody, TagEntry, TagPaging } from '@alfresco/js-api'; -import { Observable, Subject, of, zip, forkJoin } from 'rxjs'; import { + Category, + CategoryEntry, + CategoryLinkBody, + CategoryPaging, + Node, + TagBody, + TagEntry, + TagPaging +} from '@alfresco/js-api'; +import { forkJoin, Observable, of, Subject, zip } from 'rxjs'; +import { + AppConfigService, + CardViewBaseItemModel, CardViewItem, LogService, TranslationService, - AppConfigService, - CardViewBaseItemModel, UpdateNotification } from '@alfresco/adf-core'; import { ContentMetadataService } from '../../services/content-metadata.service'; import { CardViewGroup, PresetConfig } from '../../interfaces/content-metadata.interfaces'; -import { takeUntil, debounceTime, catchError, map } from 'rxjs/operators'; +import { catchError, debounceTime, map, takeUntil } from 'rxjs/operators'; import { CardViewContentUpdateService } from '../../../common/services/card-view-content-update.service'; import { NodesApiService } from '../../../common/services/nodes-api.service'; import { TagsCreatorMode } from '../../../tag/tags-creator/tags-creator-mode'; @@ -310,6 +319,7 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy { })) .subscribe((result) => { if (result) { + this.updateUndefinedNodeProperties(result.updatedNode); if (this.hasContentTypeChanged(this.changedProperties)) { this.cardViewContentUpdateService.updateNodeAspect(this.node); } @@ -333,6 +343,12 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy { return !!changedProperties?.nodeType; } + private updateUndefinedNodeProperties(node: Node): void { + if (!node.properties) { + node.properties = {}; + } + } + private loadProperties(node: Node) { if (node) { this.basicProperties$ = this.getProperties(node);