[ACS-5645]code modification

This commit is contained in:
Yasa-Nataliya
2023-10-13 16:19:57 +05:30
committed by Anukriti Singh
parent c629c1b3a4
commit c005237498
7 changed files with 138 additions and 126 deletions
+2 -2
View File
@@ -33,7 +33,7 @@ export class MetadataViewPage {
author = $(`[data-automation-id='card-textitem-value-properties.cm:author']`); author = $(`[data-automation-id='card-textitem-value-properties.cm:author']`);
titleProperty = $(`span[data-automation-id='card-textitem-value-properties.cm:title'] span`); titleProperty = $(`span[data-automation-id='card-textitem-value-properties.cm:title'] span`);
editIcon = $(`button[data-automation-id='meta-data-card-toggle-edit']`); editIcon = $(`button[data-automation-id='meta-data-card-toggle-edit']`);
editIconGeneral = $(`button[data-automation-id='meta-data-generalInfo-edit']`); editIconGeneral = $(`button[data-automation-id='meta-data-general-info-edit']`);
informationButton = $(`button[data-automation-id='meta-data-card-toggle-expand']`); informationButton = $(`button[data-automation-id='meta-data-card-toggle-expand']`);
informationSpan = $(`span[data-automation-id='meta-data-card-toggle-expand-label']`); informationSpan = $(`span[data-automation-id='meta-data-card-toggle-expand-label']`);
informationIcon = $(`span[data-automation-id='meta-data-card-toggle-expand-label'] ~ mat-icon`); informationIcon = $(`span[data-automation-id='meta-data-card-toggle-expand-label'] ~ mat-icon`);
@@ -119,7 +119,7 @@ export class MetadataViewPage {
} }
async editIconGeneralClick(): Promise<void> { async editIconGeneralClick(): Promise<void> {
await BrowserActions.clickExecuteScript('button[data-automation-id="meta-data-generalInfo-edit"]'); await BrowserActions.click(this.editIconGeneral);
} }
async informationButtonIsDisplayed(): Promise<void> { async informationButtonIsDisplayed(): Promise<void> {
@@ -220,7 +220,7 @@ describe('CategoriesManagementComponent', () => {
component.categoryNameControlVisible = true; component.categoryNameControlVisible = true;
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should be hidden initially', () => { it('should not hide category name control when categoryNameControlVisible is false', () => {
component.categoryNameControlVisible = false; component.categoryNameControlVisible = false;
fixture.detectChanges(); fixture.detectChanges();
const categoryControl: HTMLDivElement = fixture.debugElement.query(By.css('.adf-category-name-field')).nativeElement; const categoryControl: HTMLDivElement = fixture.debugElement.query(By.css('.adf-category-name-field')).nativeElement;
@@ -21,19 +21,19 @@
(click)="toggleGeneralEdit($event)" (click)="toggleGeneralEdit($event)"
[attr.title]="'CORE.METADATA.ACTIONS.EDIT' | translate" [attr.title]="'CORE.METADATA.ACTIONS.EDIT' | translate"
[attr.aria-label]="'CORE.METADATA.ACCESSIBILITY.EDIT' | translate" [attr.aria-label]="'CORE.METADATA.ACCESSIBILITY.EDIT' | translate"
data-automation-id="meta-data-generalInfo-edit" data-automation-id="meta-data-general-info-edit"
class="adf-edit-icon-buttons"> class="adf-edit-icon-buttons">
<mat-icon>mode_edit</mat-icon> <mat-icon>mode_edit</mat-icon>
</button> </button>
<div *ngIf="editable" <div *ngIf="editable"
class="adf-metadata-action-buttons"> class="adf-metadata-action-buttons">
<button mat-icon-button <button mat-icon-button
(click)="cancelGeneralInfoChanges($event)" (click)="cancelEditChanges('generalInfo', $event)"
data-automation-id="reset-metadata"> data-automation-id="reset-metadata">
<mat-icon>clear</mat-icon> <mat-icon>clear</mat-icon>
</button> </button>
<button mat-icon-button <button mat-icon-button
(click)="saveGeneralInfoChanges($event)" (click)="saveEditChanges('generalInfo', $event)"
color="primary" color="primary"
data-automation-id="save-generalInfo-metadata" data-automation-id="save-generalInfo-metadata"
[disabled]="!hasMetadataChanged"> [disabled]="!hasMetadataChanged">
@@ -54,8 +54,8 @@
</mat-expansion-panel> </mat-expansion-panel>
<ng-container *ngIf="displayTags"> <ng-container *ngIf="displayTags">
<mat-expansion-panel <mat-expansion-panel
(opened)="handleTagPanelOpen()" (opened)="handleTagsPanelState(true)"
(closed)="handleTagPanelClose()" (closed)="handleTagsPanelState(false)"
hideToggle hideToggle
[expanded]="tagsPanelState"> [expanded]="tagsPanelState">
<mat-expansion-panel-header> <mat-expansion-panel-header>
@@ -80,12 +80,12 @@
</div> </div>
<div *ngIf="editableTags" class="adf-metadata-action-buttons"> <div *ngIf="editableTags" class="adf-metadata-action-buttons">
<button mat-icon-button <button mat-icon-button
(click)="CancelTagsChanges($event)" (click)="cancelEditChanges('tags', $event)"
data-automation-id="reset-metadata"> data-automation-id="reset-tags-metadata">
<mat-icon>clear</mat-icon> <mat-icon>clear</mat-icon>
</button> </button>
<button mat-icon-button <button mat-icon-button
(click)="saveTagsChanges($event)" (click)="saveEditChanges('tags', $event)"
color="primary" color="primary"
data-automation-id="save-tags-metadata" data-automation-id="save-tags-metadata"
[disabled]="!hasMetadataChanged"> [disabled]="!hasMetadataChanged">
@@ -115,8 +115,8 @@
</ng-container> </ng-container>
<ng-container *ngIf="displayCategories"> <ng-container *ngIf="displayCategories">
<mat-expansion-panel <mat-expansion-panel
(opened)="handleCategoryPanelOpen()" (opened)="handleCategoriesPanelState(true)"
(closed)="handleCategoryPanelClose()" (closed)="handleCategoriesPanelState(false)"
hideToggle hideToggle
[expanded]="categoriesPanelState"> [expanded]="categoriesPanelState">
<mat-expansion-panel-header> <mat-expansion-panel-header>
@@ -140,12 +140,12 @@
</div> </div>
<div *ngIf="editableCategories" class="adf-metadata-action-buttons"> <div *ngIf="editableCategories" class="adf-metadata-action-buttons">
<button mat-icon-button <button mat-icon-button
(click)="cancelCategoriesChanges($event)" (click)="cancelEditChanges('categories', $event)"
data-automation-id="reset-metadata"> data-automation-id="reset-metadata">
<mat-icon>clear</mat-icon> <mat-icon>clear</mat-icon>
</button> </button>
<button mat-icon-button <button mat-icon-button
(click)="saveCategoriesChanges($event)" (click)="saveEditChanges('categories', $event)"
color="primary" color="primary"
data-automation-id="save-categories-metadata" data-automation-id="save-categories-metadata"
[disabled]="!hasMetadataChanged"> [disabled]="!hasMetadataChanged">
@@ -204,12 +204,12 @@
</button> </button>
<div class="adf-metadata-action-buttons" *ngIf="group.editable"> <div class="adf-metadata-action-buttons" *ngIf="group.editable">
<button mat-icon-button <button mat-icon-button
(click)="cancelGroupChanges(group, $event)" (click)="cancelEditChanges('group', $event, group)"
data-automation-id="reset-metadata"> data-automation-id="reset-metadata">
<mat-icon>clear</mat-icon> <mat-icon>clear</mat-icon>
</button> </button>
<button mat-icon-button <button mat-icon-button
(click)="saveGroupChanges(group, $event)" (click)="saveEditChanges('group', $event, group)"
color="primary" color="primary"
data-automation-id="save-metadata" data-automation-id="save-metadata"
[disabled]="!hasMetadataChanged"> [disabled]="!hasMetadataChanged">
@@ -123,7 +123,6 @@
.acs-details-container { .acs-details-container {
.mat-tab-body-content { .mat-tab-body-content {
.adf-content-metadata-card {
.adf-metadata-properties { .adf-metadata-properties {
.mat-expansion-panel { .mat-expansion-panel {
width: 755px; width: 755px;
@@ -134,7 +133,6 @@
} }
} }
} }
}
.adf-content-metadata-card { .adf-content-metadata-card {
.mat-card:not([class*=mat-elevation-z]) { .mat-card:not([class*=mat-elevation-z]) {
@@ -76,6 +76,7 @@ describe('ContentMetadataComponent', () => {
const findTagElements = (): DebugElement[] => fixture.debugElement.queryAll(By.css('.adf-metadata-properties .adf-metadata-properties-tag')); const findTagElements = (): DebugElement[] => fixture.debugElement.queryAll(By.css('.adf-metadata-properties .adf-metadata-properties-tag'));
const findCancelButton = (): HTMLButtonElement => fixture.debugElement.query(By.css('[data-automation-id=reset-metadata]')).nativeElement; const findCancelButton = (): HTMLButtonElement => fixture.debugElement.query(By.css('[data-automation-id=reset-metadata]')).nativeElement;
const findCancelTagsButton = (): HTMLButtonElement => fixture.debugElement.query(By.css('[data-automation-id=reset-tags-metadata]')).nativeElement;
const clickOnCancel = () => { const clickOnCancel = () => {
findCancelButton().click(); findCancelButton().click();
@@ -302,7 +303,7 @@ describe('ContentMetadataComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
findTagsCreator().tagsChange.emit([tagName1, tagName2]); findTagsCreator().tagsChange.emit([tagName1, tagName2]);
const mockEvent = new Event('click'); const mockEvent = new Event('click');
component.saveTagsChanges(mockEvent); component.saveChanges(mockEvent);
const tag1 = new TagBody(); const tag1 = new TagBody();
tag1.tag = tagName1; tag1.tag = tagName1;
@@ -312,7 +313,7 @@ describe('ContentMetadataComponent', () => {
expect(tagService.assignTagsToNode).toHaveBeenCalledWith(node.id, [tag1, tag2]); expect(tagService.assignTagsToNode).toHaveBeenCalledWith(node.id, [tag1, tag2]);
})); }));
it('should call getTagsByNodeId on TagService on save click', async() => { it('should call getTagsByNodeId on TagService on save click', () => {
component.editableTags = true; component.editableTags = true;
component.displayTags = true; component.displayTags = true;
const property = { key: 'properties.property-key', value: 'original-value' } as CardViewBaseItemModel; const property = { key: 'properties.property-key', value: 'original-value' } as CardViewBaseItemModel;
@@ -330,7 +331,7 @@ describe('ContentMetadataComponent', () => {
findTagsCreator().tagsChange.emit([tagPaging.list.entries[0].entry.tag, 'New tag 3']); findTagsCreator().tagsChange.emit([tagPaging.list.entries[0].entry.tag, 'New tag 3']);
getTagsByNodeIdSpy.calls.reset(); getTagsByNodeIdSpy.calls.reset();
const mockEvent = new Event('click'); const mockEvent = new Event('click');
component.saveTagsChanges(mockEvent); component.saveChanges(mockEvent);
expect(tagService.getTagsByNodeId).toHaveBeenCalledWith(node.id); expect(tagService.getTagsByNodeId).toHaveBeenCalledWith(node.id);
}); });
@@ -432,81 +433,106 @@ describe('ContentMetadataComponent', () => {
})); }));
}); });
describe('saveChanges', () => { describe('saveEditChanges', () => {
it('should save general info changes and toggle editable', () => { it('should save general info changes and toggle editable flag', () => {
const event = new Event('click'); const event = new Event('click');
spyOn(component, 'saveChanges'); const buttonType = 'generalInfo';
component.editable = true; component.editable = true;
component.saveGeneralInfoChanges(event);
spyOn(component, 'saveChanges');
component.saveEditChanges(buttonType, event);
expect(component.saveChanges).toHaveBeenCalledWith(event); expect(component.saveChanges).toHaveBeenCalledWith(event);
expect(component.editable).toBe(false); expect(component.editable).toBe(false);
}); });
it('should save tags changes and toggle editableTags', () => { it('should save tags changes and toggle editableTags flag', () => {
const event = new Event('click'); const event = new Event('click');
spyOn(component, 'saveChanges'); const buttonType = 'tags';
component.editableTags = true; component.editableTags = true;
component.saveTagsChanges(event);
expect(component.saveChanges).toHaveBeenCalledWith(event);
expect(component.editableTags).toBe(false);
});
it('should save categories changes and toggle editableCategories', () => {
const event = new Event('click');
spyOn(component, 'saveChanges'); spyOn(component, 'saveChanges');
component.editableCategories = true; component.saveEditChanges(buttonType, event);
component.saveCategoriesChanges(event);
expect(component.saveChanges).toHaveBeenCalledWith(event); expect(component.saveChanges).toHaveBeenCalledWith(event);
expect(component.editableTags).toBe(false); expect(component.editableTags).toBe(false);
}); });
it('should save group changes and toggle group.editable', () => { it('should save categories changes and toggle editableCategories flag', () => {
const event = new Event('click');
const buttonType = 'categories';
component.editableCategories = true;
spyOn(component, 'saveChanges');
component.saveEditChanges(buttonType, event);
expect(component.saveChanges).toHaveBeenCalledWith(event);
expect(component.editableCategories).toBe(false);
});
it('should save group changes and toggle editable flag', () => {
const group = { editable: true }; const group = { editable: true };
const event = new Event('click'); const event = new Event('click');
const buttonType = 'group';
spyOn(component, 'saveChanges'); spyOn(component, 'saveChanges');
component.saveGroupChanges(group, event); component.saveEditChanges(buttonType, event, group);
expect(component.saveChanges).toHaveBeenCalledWith(event); expect(component.saveChanges).toHaveBeenCalledWith(event);
expect(group.editable).toBe(false); expect(group.editable).toBe(false);
}); });
}) });
describe('cancelChanges', () => { describe('cancelChanges', () => {
it('should cancel group changes and set group editable to false', () => { it('should cancel group changes and set group editable to false', () => {
const group = { editable: true }; const group = { editable: true };
const event = new Event('click'); const event = new Event('click');
const buttonType = 'group';
spyOn(component, 'cancelChanges'); spyOn(component, 'cancelChanges');
component.cancelGroupChanges(group, event); component.cancelEditChanges(buttonType, event, group);
expect(component.cancelChanges).toHaveBeenCalledWith(event); expect(component.cancelChanges).toHaveBeenCalledWith(event);
expect(group.editable).toBe(false); expect(group.editable).toBe(false);
}); });
it('should cancel general info changes and toggle editable', () => { it('should cancel general info changes and toggle editable flag', () => {
const event = new Event('click'); const event = new Event('click');
spyOn(component, 'cancelChanges'); const buttonType = 'generalInfo';
component.editable = true; component.editable = true;
component.cancelGeneralInfoChanges(event);
spyOn(component, 'cancelChanges');
component.cancelEditChanges(buttonType, event);
expect(component.cancelChanges).toHaveBeenCalledWith(event); expect(component.cancelChanges).toHaveBeenCalledWith(event);
expect(component.editable).toBe(false); expect(component.editable).toBe(false);
}); });
it('should cancel tags changes and toggle editableTags', () => { it('should cancel tags changes and toggle editableTags flag', () => {
const event = new Event('click'); const event = new Event('click');
spyOn(component, 'cancelChanges'); const buttonType = 'tags';
component.editableTags = true; component.editableTags = true;
component.CancelTagsChanges(event);
spyOn(component, 'cancelChanges');
component.cancelEditChanges(buttonType, event);
expect(component.cancelChanges).toHaveBeenCalledWith(event); expect(component.cancelChanges).toHaveBeenCalledWith(event);
expect(component.editableTags).toBe(false); expect(component.editableTags).toBe(false);
}); });
it('should cancel categories changes and toggle editableCategories', () => { it('should cancel categories changes and toggle editableCategories flag', () => {
const event = new Event('click'); const event = new Event('click');
spyOn(component, 'cancelChanges'); const buttonType = 'categories';
component.editableCategories = true; component.editableCategories = true;
component.cancelCategoriesChanges(event);
spyOn(component, 'cancelChanges');
component.cancelEditChanges(buttonType, event);
expect(component.cancelChanges).toHaveBeenCalledWith(event); expect(component.cancelChanges).toHaveBeenCalledWith(event);
expect(component.editableCategories).toBe(false); expect(component.editableCategories).toBe(false);
}); });
}) });
describe('editing', () => { describe('editing', () => {
it('should toggle categories edit and set categoriesPanelState accordingly', () => { it('should toggle categories edit and set categoriesPanelState accordingly', () => {
@@ -729,7 +755,7 @@ describe('ContentMetadataComponent', () => {
it('should display card views group when there is at least one property that is not empty', async () => { it('should display card views group when there is at least one property that is not empty', async () => {
component.expanded = true; component.expanded = true;
spyOn(contentMetadataService, 'getGroupedProperties'); spyOn(contentMetadataService, 'getGroupedProperties').and.stub();
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) }); component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
@@ -1118,7 +1144,6 @@ describe('ContentMetadataComponent', () => {
it('should render tags after loading tags in ngOnInit', () => { it('should render tags after loading tags in ngOnInit', () => {
spyOn(tagService, 'getTagsByNodeId').and.returnValue(of(tagPaging)); spyOn(tagService, 'getTagsByNodeId').and.returnValue(of(tagPaging));
component.ngOnInit(); component.ngOnInit();
fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
const tagElements = findTagElements(); const tagElements = findTagElements();
expect(tagElements).toHaveSize(2); expect(tagElements).toHaveSize(2);
@@ -1195,9 +1220,7 @@ describe('ContentMetadataComponent', () => {
tick(500); tick(500);
fixture.detectChanges(); fixture.detectChanges();
spyOn(tagService, 'getTagsByNodeId').and.returnValue(of(tagPaging)); spyOn(tagService, 'getTagsByNodeId').and.returnValue(of(tagPaging));
findCancelTagsButton().click();
const mockEvent = new Event('click');
component.CancelTagsChanges(mockEvent);
component.editableTags = false; component.editableTags = false;
fixture.detectChanges(); fixture.detectChanges();
const tagElements = findTagElements(); const tagElements = findTagElements();
@@ -1249,7 +1272,7 @@ describe('ContentMetadataComponent', () => {
it('should enable cancel button after emitting tagsChange event', () => { it('should enable cancel button after emitting tagsChange event', () => {
tagsCreator.tagsChange.emit(['New tag 1', 'New tag 2', 'New tag 3']); tagsCreator.tagsChange.emit(['New tag 1', 'New tag 2', 'New tag 3']);
fixture.detectChanges(); fixture.detectChanges();
expect(findCancelButton().disabled).toBeFalse(); expect(findCancelTagsButton().disabled).toBeFalse();
}); });
it('should enable save button after emitting tagsChange event', () => { it('should enable save button after emitting tagsChange event', () => {
@@ -1270,7 +1293,7 @@ describe('ContentMetadataComponent', () => {
expect(tagsCreator.disabledTagsRemoving).toBeTrue(); expect(tagsCreator.disabledTagsRemoving).toBeTrue();
}); });
it('should have assigned false to disabledTagsRemoving if forkJoin fails', fakeAsync(() => { it('should have assigned false to disabledTagsRemoving if forkJoin fails', () => {
const property = { key: 'properties.property-key', value: 'original-value' } as CardViewBaseItemModel; 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)); spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode));
@@ -1289,7 +1312,7 @@ describe('ContentMetadataComponent', () => {
clickOnTagsSave(); clickOnTagsSave();
expect(tagsCreator.disabledTagsRemoving).toBeFalse(); expect(tagsCreator.disabledTagsRemoving).toBeFalse();
})); });
it('should have assigned false to tagNameControlVisible after clicking on update button', () => { it('should have assigned false to tagNameControlVisible after clicking on update button', () => {
tagsCreator.tagNameControlVisibleChange.emit(true); tagsCreator.tagNameControlVisibleChange.emit(true);
@@ -273,25 +273,29 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
} }
} }
saveGeneralInfoChanges(event:Event) { saveEditChanges(buttonType: string, event: Event, group?: any) {
this.saveChanges(event); this.saveChanges(event);
switch (buttonType) {
case 'generalInfo':
this.editable = !this.editable; this.editable = !this.editable;
} break;
case 'tags':
saveTagsChanges(event: Event) {
this.saveChanges(event);
this.editableTags = !this.editableTags; this.editableTags = !this.editableTags;
} break;
case 'categories':
saveCategoriesChanges(event: Event) {
this.saveChanges(event);
this.editableCategories = !this.editableCategories; this.editableCategories = !this.editableCategories;
} break;
case 'group':
saveGroupChanges(group: any, event:Event) { if (group) {
this.saveChanges(event);
group.editable = !group.editable; group.editable = !group.editable;
} }
break;
default:
break;
}
}
/** /**
* Register all tags which should be assigned to node. Please note that they are just in "register" state and are not yet saved * Register all tags which should be assigned to node. Please note that they are just in "register" state and are not yet saved
@@ -328,24 +332,28 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
this.loadProperties(this.node); this.loadProperties(this.node);
} }
cancelGroupChanges(group: any, event: Event) { cancelEditChanges(buttonType: string, event: Event, group?: any) {
this.cancelChanges(event); this.cancelChanges(event);
switch (buttonType) {
case 'generalInfo':
this.editable = !this.editable;
break;
case 'tags':
this.editableTags = !this.editableTags;
break;
case 'categories':
this.editableCategories = !this.editableCategories;
break;
case 'group':
if (group) {
group.editable = !group.editable; group.editable = !group.editable;
} }
break;
CancelTagsChanges(event: Event) { default:
this.cancelChanges(event); break;
this.editableTags = !this.editableTags;
} }
cancelCategoriesChanges(event: Event) {
this.cancelChanges(event);
this.editableCategories = !this.editableCategories;
}
cancelGeneralInfoChanges(event: Event) {
this.cancelChanges(event);
this.editable = !this.editable;
} }
toggleGeneralEdit(event: Event): void { toggleGeneralEdit(event: Event): void {
@@ -386,28 +394,18 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
} }
} }
handleTagPanelOpen() {
this.tagsPanelState = true;
this.cdr.detectChanges();
}
handleTagPanelClose() {
this.tagsPanelState = false;
this.cdr.detectChanges();
}
generalTogglePanelState() { generalTogglePanelState() {
this.generalInfoPanelState = !this.generalInfoPanelState; this.generalInfoPanelState = !this.generalInfoPanelState;
this.cdr.detectChanges(); this.cdr.detectChanges();
} }
handleCategoryPanelOpen() { handleTagsPanelState(tagPanelState: boolean) {
this.categoriesPanelState = true; this.tagsPanelState = tagPanelState;
this.cdr.detectChanges(); this.cdr.detectChanges();
} }
handleCategoryPanelClose() { handleCategoriesPanelState(categoriesPanelState: boolean) {
this.categoriesPanelState = false; this.categoriesPanelState= categoriesPanelState;
this.cdr.detectChanges(); this.cdr.detectChanges();
} }
@@ -386,13 +386,6 @@ describe('TagsCreatorComponent', () => {
expect(getFirstError()).toBe('TAG.TAGS_CREATOR.ERRORS.ALREADY_ADDED_TAG'); expect(getFirstError()).toBe('TAG.TAGS_CREATOR.ERRORS.ALREADY_ADDED_TAG');
})); }));
it('should not show error for required if tags are changed', fakeAsync(() => {
typeTag('');
component.tags = ['new tag 1', 'new tag 2'];
fixture.detectChanges();
expect(getFirstError()).toBeUndefined();
}));
it('should show error when duplicated already existing tag', fakeAsync(() => { it('should show error when duplicated already existing tag', fakeAsync(() => {
const tag = 'Some tag'; const tag = 'Some tag';