mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
[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
This commit is contained in:
parent
885c5a52fe
commit
af3c7eb783
@ -15,25 +15,46 @@
|
|||||||
* limitations under the License.
|
* 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 { DebugElement, SimpleChange } from '@angular/core';
|
||||||
import { By } from '@angular/platform-browser';
|
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 { ContentMetadataComponent } from './content-metadata.component';
|
||||||
import { ContentMetadataService } from '../../services/content-metadata.service';
|
import { ContentMetadataService } from '../../services/content-metadata.service';
|
||||||
import {
|
import {
|
||||||
CardViewBaseItemModel, CardViewComponent,
|
AppConfigService,
|
||||||
LogService, AppConfigService, UpdateNotification
|
CardViewBaseItemModel,
|
||||||
|
CardViewComponent,
|
||||||
|
LogService,
|
||||||
|
UpdateNotification
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { NodesApiService } from '../../../common/services/nodes-api.service';
|
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 { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||||
import { mockGroupProperties } from './mock-data';
|
import { mockGroupProperties } from './mock-data';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { CardViewContentUpdateService } from '../../../common/services/card-view-content-update.service';
|
import { CardViewContentUpdateService } from '../../../common/services/card-view-content-update.service';
|
||||||
import { PropertyGroup } from '../../interfaces/property-group.interface';
|
import { PropertyGroup } from '../../interfaces/property-group.interface';
|
||||||
import { PropertyDescriptorsService } from '../../services/property-descriptors.service';
|
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', () => {
|
describe('ContentMetadataComponent', () => {
|
||||||
let component: ContentMetadataComponent;
|
let component: ContentMetadataComponent;
|
||||||
@ -100,6 +121,22 @@ describe('ContentMetadataComponent', () => {
|
|||||||
return fixture.debugElement.query(By.css('.adf-metadata-categories-title button')).nativeElement;
|
return fixture.debugElement.query(By.css('.adf-metadata-categories-title button')).nativeElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateAspectProperty(newValue: string): Promise<void> {
|
||||||
|
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(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@ -221,23 +258,19 @@ describe('ContentMetadataComponent', () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it('should save changedProperties on save click', fakeAsync(async () => {
|
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' };
|
const expectedNode = { ...node, name: 'some-modified-value' };
|
||||||
spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode));
|
await updateAspectProperty('updated-value');
|
||||||
|
|
||||||
updateService.update(property, 'updated-value');
|
|
||||||
tick(600);
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
await fixture.whenStable();
|
|
||||||
clickOnSave();
|
|
||||||
|
|
||||||
await fixture.whenStable();
|
|
||||||
expect(component.node).toEqual(expectedNode);
|
expect(component.node).toEqual(expectedNode);
|
||||||
expect(nodesApiService.updateNode).toHaveBeenCalled();
|
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( () => {
|
it('should call removeTag and assignTagsToNode on TagService on save click', fakeAsync( () => {
|
||||||
component.editable = true;
|
component.editable = true;
|
||||||
component.displayTags = true;
|
component.displayTags = true;
|
||||||
|
@ -16,19 +16,28 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core';
|
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 {
|
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,
|
CardViewItem,
|
||||||
LogService,
|
LogService,
|
||||||
TranslationService,
|
TranslationService,
|
||||||
AppConfigService,
|
|
||||||
CardViewBaseItemModel,
|
|
||||||
UpdateNotification
|
UpdateNotification
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { ContentMetadataService } from '../../services/content-metadata.service';
|
import { ContentMetadataService } from '../../services/content-metadata.service';
|
||||||
import { CardViewGroup, PresetConfig } from '../../interfaces/content-metadata.interfaces';
|
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 { CardViewContentUpdateService } from '../../../common/services/card-view-content-update.service';
|
||||||
import { NodesApiService } from '../../../common/services/nodes-api.service';
|
import { NodesApiService } from '../../../common/services/nodes-api.service';
|
||||||
import { TagsCreatorMode } from '../../../tag/tags-creator/tags-creator-mode';
|
import { TagsCreatorMode } from '../../../tag/tags-creator/tags-creator-mode';
|
||||||
@ -310,6 +319,7 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
}))
|
}))
|
||||||
.subscribe((result) => {
|
.subscribe((result) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
|
this.updateUndefinedNodeProperties(result.updatedNode);
|
||||||
if (this.hasContentTypeChanged(this.changedProperties)) {
|
if (this.hasContentTypeChanged(this.changedProperties)) {
|
||||||
this.cardViewContentUpdateService.updateNodeAspect(this.node);
|
this.cardViewContentUpdateService.updateNodeAspect(this.node);
|
||||||
}
|
}
|
||||||
@ -333,6 +343,12 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
return !!changedProperties?.nodeType;
|
return !!changedProperties?.nodeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateUndefinedNodeProperties(node: Node): void {
|
||||||
|
if (!node.properties) {
|
||||||
|
node.properties = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private loadProperties(node: Node) {
|
private loadProperties(node: Node) {
|
||||||
if (node) {
|
if (node) {
|
||||||
this.basicProperties$ = this.getProperties(node);
|
this.basicProperties$ = this.getProperties(node);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user