diff --git a/lib/content-services/src/lib/category/categories-management/categories-management.component.spec.ts b/lib/content-services/src/lib/category/categories-management/categories-management.component.spec.ts index 027c637ae2..6a6ea4ab3d 100644 --- a/lib/content-services/src/lib/category/categories-management/categories-management.component.spec.ts +++ b/lib/content-services/src/lib/category/categories-management/categories-management.component.spec.ts @@ -466,11 +466,4 @@ describe('CategoriesManagementComponent', () => { component.removeCategory(categoryToRemove); expect(component.categories.length).toBe(0); })); - - it('should toggle categoryNameControl visibility', () => { - component.categoryNameControlVisible = true; - expect(component.categoryNameControlVisible).toBe(true); - component.categoryNameControlVisible = false; - expect(component.categoryNameControlVisible).toBe(false); - }); }); diff --git a/lib/content-services/src/lib/category/categories-management/categories-management.component.ts b/lib/content-services/src/lib/category/categories-management/categories-management.component.ts index 06cf901b8a..62414f8b1a 100644 --- a/lib/content-services/src/lib/category/categories-management/categories-management.component.ts +++ b/lib/content-services/src/lib/category/categories-management/categories-management.component.ts @@ -83,9 +83,7 @@ export class CategoriesManagementComponent implements OnInit, OnDestroy { set categoryNameControlVisible(categoryNameControlVisible: boolean) { this._categoryNameControlVisible = categoryNameControlVisible; if (categoryNameControlVisible) { - setTimeout(() => { this.categoryNameInputElement.nativeElement.scrollIntoView(); - }); this._existingCategoriesPanelVisible = true; } else { this._existingCategoriesPanelVisible = false; 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 fb500d083c..330385df38 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 @@ -33,7 +33,10 @@ 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 { AllowableOperationsEnum, CategoriesManagementComponent, CategoriesManagementMode, CategoryService, TagsCreatorComponent, TagsCreatorMode, TagService } from '@alfresco/adf-content-services'; +import { CategoriesManagementComponent, CategoriesManagementMode, CategoryService, TagsCreatorComponent, TagsCreatorMode, TagService } from '@alfresco/adf-content-services'; +import { MatIconModule } from '@angular/material/icon'; +import { MatExpansionModule, MatExpansionPanel } from '@angular/material/expansion'; +import { MatDividerModule } from '@angular/material/divider'; describe('ContentMetadataComponent', () => { let component: ContentMetadataComponent; @@ -76,25 +79,7 @@ describe('ContentMetadataComponent', () => { fixture.detectChanges(); }; - const findGenralInfoSaveButton = (): HTMLButtonElement => fixture.debugElement.query(By.css('[data-automation-id=save-generalInfo-metadata]')).nativeElement; - const findTagsSaveButton = (): HTMLButtonElement => fixture.debugElement.query(By.css('[data-automation-id=save-tags-metadata]')).nativeElement; const findSaveButton = (): HTMLButtonElement => fixture.debugElement.query(By.css('[data-automation-id=save-metadata]')).nativeElement; - const findSCategorieSaveButton = (): HTMLButtonElement => fixture.debugElement.query(By.css('[data-automation-id=save-categories-metadata]')).nativeElement; - - const clickOnGenralInfoSave = () => { - findGenralInfoSaveButton().click(); - fixture.detectChanges(); - }; - - const clickOnTagsSave = () => { - findTagsSaveButton().click(); - fixture.detectChanges(); - }; - - const clickOnCategoriesSave = () => { - findSCategorieSaveButton().click(); - fixture.detectChanges(); - }; const clickOnSave = () => { findSaveButton().click(); @@ -122,7 +107,11 @@ describe('ContentMetadataComponent', () => { TestBed.configureTestingModule({ imports: [ TranslateModule.forRoot(), - ContentTestingModule + ContentTestingModule, + MatIconModule, + MatExpansionModule, + MatExpansionPanel, + MatDividerModule ], providers: [ { @@ -190,14 +179,6 @@ describe('ContentMetadataComponent', () => { expect(component.editable).toBe(false); }); - it('should have editableTags input param as false by default', () => { - expect(component.editableTags).toBe(false); - }); - - it('should have editableCategories input param as false by default', () => { - expect(component.editableCategories).toBe(false); - }); - it('should have displayEmpty input param as false by default', () => { expect(component.displayEmpty).toBe(false); }); @@ -247,7 +228,7 @@ describe('ContentMetadataComponent', () => { })); it('should save changedProperties on save click', fakeAsync(async () => { - component.editableGeneralInfo = true; + component.editableGeneralInfo = 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)); @@ -257,14 +238,14 @@ describe('ContentMetadataComponent', () => { fixture.detectChanges(); await fixture.whenStable(); - clickOnGenralInfoSave(); - + const mockEvent = new Event('click'); + component.saveGeneralInfoChanges(mockEvent); await fixture.whenStable(); expect(component.node).toEqual(expectedNode); expect(nodesApiService.updateNode).toHaveBeenCalled(); })); - it('should call removeTag and assignTagsToNode on TagService on save click',() => { + it('should call removeTag and assignTagsToNode on TagService on save click', () => { component.editableTags = true; component.displayTags = true; const property = { key: 'properties.property-key', value: 'original-value' } as CardViewBaseItemModel; @@ -293,7 +274,7 @@ describe('ContentMetadataComponent', () => { expect(tagService.assignTagsToNode).toHaveBeenCalledWith(node.id, [tag1, tag2]); }); - it('should call getTagsByNodeId on TagService on save click', () => { + it('should call getTagsByNodeId on TagService on save click', fakeAsync( () => { component.editableTags = true; component.displayTags = true; const property = { key: 'properties.property-key', value: 'original-value' } as CardViewBaseItemModel; @@ -306,6 +287,7 @@ describe('ContentMetadataComponent', () => { spyOn(tagService, 'assignTagsToNode').and.returnValue(of({})); updateService.update(property, 'updated-value'); + tick(600); fixture.detectChanges(); findTagsCreator().tagsChange.emit([tagPaging.list.entries[0].entry.tag, 'New tag 3']); @@ -314,7 +296,7 @@ describe('ContentMetadataComponent', () => { component.saveTagsChanges(mockEvent); expect(tagService.getTagsByNodeId).toHaveBeenCalledWith(node.id); - }); + })); it('should throw error on unsuccessful save', fakeAsync(() => { const logService: LogService = TestBed.inject(LogService); @@ -333,13 +315,13 @@ describe('ContentMetadataComponent', () => { spyOn(nodesApiService, 'updateNode').and.returnValue(throwError(new Error('My bad'))); fixture.detectChanges(); - fixture.whenStable().then(() => clickOnGenralInfoSave()); + fixture.whenStable().then(() => clickOnSave()); discardPeriodicTasks(); flush(); })); it('should open the confirm dialog when content type is changed', fakeAsync(() => { - component.editableGeneralInfo = true; + component.editable = true; const property = { key: 'nodeType', value: 'ft:sbiruli' } as CardViewBaseItemModel; const expectedNode = { ...node, nodeType: 'ft:sbiruli' }; spyOn(contentMetadataService, 'openConfirmDialog').and.returnValue(of(true)); @@ -350,7 +332,7 @@ describe('ContentMetadataComponent', () => { fixture.detectChanges(); tick(100); - clickOnGenralInfoSave(); + clickOnSave(); tick(100); expect(component.node).toEqual(expectedNode); @@ -359,7 +341,7 @@ describe('ContentMetadataComponent', () => { discardPeriodicTasks(); })); - it('should call removeTag and assignTagsToNode on TagService after confirming confirmation dialog when content type is changed', () => { + it('should call removeTag and assignTagsToNode on TagService after confirming confirmation dialog when content type is changed', fakeAsync(() => { component.editableTags = true; component.displayTags = true; const property = { key: 'nodeType', value: 'ft:sbiruli' } as CardViewBaseItemModel; @@ -375,23 +357,26 @@ describe('ContentMetadataComponent', () => { const tagName2 = 'New tag 3'; updateService.update(property, 'ft:poppoli'); + tick(600); fixture.detectChanges(); findTagsCreator().tagsChange.emit([tagName1, tagName2]); + tick(100); fixture.detectChanges(); const mockEvent = new Event('click'); component.saveTagsChanges(mockEvent); + tick(100); const tag1 = new TagBody(); tag1.tag = tagName1; const tag2 = new TagBody(); tag2.tag = tagName2; expect(tagService.removeTag).toHaveBeenCalledWith(node.id, tagPaging.list.entries[1].entry.id); expect(tagService.assignTagsToNode).toHaveBeenCalledWith(node.id, [tag1, tag2]); - }); + })); it('should retrigger the load of the properties when the content type has changed', fakeAsync(() => { - component.editableGeneralInfo = true; + component.editable = true; const property = { key: 'nodeType', value: 'ft:sbiruli' } as CardViewBaseItemModel; const expectedNode = Object.assign({}, node, { nodeType: 'ft:sbiruli' }); spyOn(contentMetadataService, 'openConfirmDialog').and.returnValue(of(true)); @@ -403,7 +388,7 @@ describe('ContentMetadataComponent', () => { fixture.detectChanges(); tick(100); - clickOnGenralInfoSave(); + clickOnSave(); tick(100); expect(component.node).toEqual(expectedNode); @@ -411,95 +396,6 @@ describe('ContentMetadataComponent', () => { })); }); - describe('editing', () => { - it('should toggle editableGeneralInfo by clicking on the edit button', () => { - component.editableGeneralInfo = true; - component.node.allowableOperations = [AllowableOperationsEnum.UPDATE]; - fixture.detectChanges(); - const mockEvent = new Event('click'); - component.toggleGeneralEdit(mockEvent); - expect(component.editableGeneralInfo).toBe(false); - }); - - it('should toggle editableTags by clicking on the edit button', () => { - component.editableTags = true; - component.node.allowableOperations = [AllowableOperationsEnum.UPDATE]; - fixture.detectChanges(); - const mockEvent = new Event('click'); - component.toggleTagsEdit(mockEvent); - expect(component.editableTags).toBe(false); - }); - - it('should toggle editableCategories by clicking on the edit button', () => { - component.editableCategories = true; - component.node.allowableOperations = [AllowableOperationsEnum.UPDATE]; - fixture.detectChanges(); - const mockEvent = new Event('click'); - component.toggleCategoriesEdit(mockEvent); - expect(component.editableCategories).toBe(false); - }); - - it('should set group.editable to true and call expandePanel when toggleEdit is called with group.editable as false', () => { - const group = { editable: false }; - const mockEvent = { stopPropagation: () => {} }; - spyOn(mockEvent, 'stopPropagation'); - spyOn(component, 'expandePanel'); - component.toggleEdit(group, mockEvent as Event); - expect(group.editable).toBe(true); - expect(mockEvent.stopPropagation).toHaveBeenCalled(); - expect(component.expandePanel).toHaveBeenCalledWith(group); - }); - - it('should set group.editable to false and not call expandePanel when toggleEdit is called with group.editable as true', () => { - const group = { editable: true }; - const mockEvent = { stopPropagation: () => {} }; - spyOn(mockEvent, 'stopPropagation'); - spyOn(component, 'expandePanel'); - component.toggleEdit(group, mockEvent as Event); - expect(group.editable).toBe(false); - expect(mockEvent.stopPropagation).toHaveBeenCalled(); - expect(component.expandePanel).not.toHaveBeenCalled(); - }); - }); - - describe('cancelChanges', () => { - it('should cancel changes for group and set editable to false', () => { - const group = { editable: true }; - const mockEvent = new Event('click'); - spyOn(component, 'revertChanges'); - component.cancelChanges(mockEvent); - expect(group.editable).toBe(false); - expect(component.revertChanges).toHaveBeenCalled(); - }); - - it('should cancel general info changes and set editableGeneralInfo to false', () => { - const mockEvent = new Event('click'); - component.editableGeneralInfo = true; - spyOn(component, 'revertChanges'); - component.cancelGeneralInfoChanges(mockEvent); - expect(component.editableGeneralInfo).toBe(false); - expect(component.revertChanges).toHaveBeenCalled(); - }); - - it('should cancel tags changes and set editableTags to false', () => { - component.editableTags = true; - const mockEvent = new Event('click'); - spyOn(component, 'revertChanges'); - component.CancelTagsChanges(mockEvent); - expect(component.editableTags).toBe(false); - expect(component.revertChanges).toHaveBeenCalled(); - }); - - it('should cancel categories changes and set editableCategories to false', () => { - const mockEvent = new Event('click'); - component.editableCategories = true; - spyOn(component, 'revertChanges'); - component.cancelCategoriesChanges(mockEvent); - expect(component.editableCategories).toBe(false); - expect(component.revertChanges).toHaveBeenCalled(); - }); - }); - describe('Reseting', () => { it('should reset changedProperties on reset click', async () => { component.changedProperties = { properties: { 'property-key': 'updated-value' } }; @@ -1128,7 +1024,7 @@ describe('ContentMetadataComponent', () => { }); it('should render tags after loading tags after clicking on Cancel button', fakeAsync(() => { - component.editableTags = true; + component.editable = true; fixture.detectChanges(); TestBed.inject(CardViewContentUpdateService).itemUpdated$.next({ changed: {} @@ -1138,7 +1034,7 @@ describe('ContentMetadataComponent', () => { spyOn(tagService, 'getTagsByNodeId').and.returnValue(of(tagPaging)); clickOnCancel(); - component.editableTags = false; + component.editable = false; fixture.detectChanges(); const tagElements = findTagElements(); expect(tagElements).toHaveSize(2); @@ -1162,7 +1058,7 @@ describe('ContentMetadataComponent', () => { let tagsCreator: TagsCreatorComponent; beforeEach(() => { - component.editableTags = true; + component.editable = true; component.displayTags = true; fixture.detectChanges(); tagsCreator = findTagsCreator(); @@ -1212,7 +1108,7 @@ describe('ContentMetadataComponent', () => { tagsCreator.tagsChange.emit([]); fixture.detectChanges(); - clickOnTagsSave(); + clickOnSave(); expect(tagsCreator.disabledTagsRemoving).toBeTrue(); }); @@ -1233,7 +1129,7 @@ describe('ContentMetadataComponent', () => { fixture.detectChanges(); tagsCreator.tagsChange.emit([tagName1, tagName2]); - clickOnTagsSave(); + clickOnSave(); expect(tagsCreator.disabledTagsRemoving).toBeFalse(); })); @@ -1243,7 +1139,7 @@ describe('ContentMetadataComponent', () => { tagsCreator.tagsChange.emit([]); fixture.detectChanges(); - clickOnTagsSave(); + clickOnSave(); expect(tagsCreator.tagNameControlVisible).toBeFalse(); }); @@ -1371,7 +1267,7 @@ describe('ContentMetadataComponent', () => { let categoriesManagementComponent: CategoriesManagementComponent; beforeEach(() => { - component.editableCategories = true; + component.editable = true; component.displayCategories = true; component.node.aspectNames.push('generalclassifiable'); spyOn(categoryService, 'getCategoryLinksForNode').and.returnValue(of(categoryPagingResponse)); @@ -1428,7 +1324,7 @@ describe('ContentMetadataComponent', () => { categoriesManagementComponent.categoriesChange.emit([]); fixture.detectChanges(); - clickOnCategoriesSave(); + clickOnSave(); expect(categoriesManagementComponent.disableRemoval).toBeTrue(); }); @@ -1459,7 +1355,7 @@ describe('ContentMetadataComponent', () => { categoriesManagementComponent.categoriesChange.emit([]); fixture.detectChanges(); - clickOnCategoriesSave(); + clickOnSave(); expect(categoriesManagementComponent.categoryNameControlVisible).toBeFalse(); }); diff --git a/lib/core/src/lib/card-view/interfaces/card-view-item-properties.interface.ts b/lib/core/src/lib/card-view/interfaces/card-view-item-properties.interface.ts index d9780d9cfa..65b1e94dae 100644 --- a/lib/core/src/lib/card-view/interfaces/card-view-item-properties.interface.ts +++ b/lib/core/src/lib/card-view/interfaces/card-view-item-properties.interface.ts @@ -23,6 +23,7 @@ export interface CardViewItemProperties { key: any; default?: any; editable?: boolean; + editableGeneralInfo?: boolean; clickable?: any; icon?: string; hint?: string; diff --git a/lib/core/src/lib/card-view/models/card-view-baseitem.model.ts b/lib/core/src/lib/card-view/models/card-view-baseitem.model.ts index 015ad9c0a2..4d6b544354 100644 --- a/lib/core/src/lib/card-view/models/card-view-baseitem.model.ts +++ b/lib/core/src/lib/card-view/models/card-view-baseitem.model.ts @@ -24,6 +24,7 @@ export abstract class CardViewBaseItemModel { key: any; default: any; editable: boolean; + editableGeneralInfo: boolean; clickable: boolean; icon?: string; hint?: string; @@ -38,6 +39,7 @@ export abstract class CardViewBaseItemModel { this.key = cardViewItemProperties.key; this.default = cardViewItemProperties.default; this.editable = !!cardViewItemProperties.editable; + this.editableGeneralInfo = !!cardViewItemProperties.editableGeneralInfo; this.clickable = !!cardViewItemProperties.clickable; this.icon = cardViewItemProperties.icon || ''; this.hint = cardViewItemProperties.hint || '';