[AAE-2200] Fix upload dialog title (#5583)

* [AAE-2200] Fix dialog title

* [AAE-2200] Title from translation ressources and refactor

* [AAE-2200] Add unit test for title

* [AAE-2200] Fix lint in test
This commit is contained in:
Baptiste Mahé 2020-04-01 15:56:21 +02:00 committed by GitHub
parent 53bddad833
commit 1e018b9476
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 13 deletions

View File

@ -136,10 +136,8 @@ export class ContentNodeDialogService {
complete: this.close.bind(this) complete: this.close.bind(this)
}); });
const title = this.getTitleTranslation(action, contentEntry.name);
const data: ContentNodeSelectorComponentData = { const data: ContentNodeSelectorComponentData = {
title: title, title: this.getTitleTranslation(action, contentEntry.name),
actionName: action, actionName: action,
currentFolderId: contentEntry.parentId, currentFolderId: contentEntry.parentId,
imageResolver: this.imageResolver.bind(this), imageResolver: this.imageResolver.bind(this),
@ -181,7 +179,7 @@ export class ContentNodeDialogService {
}); });
const data: ContentNodeSelectorComponentData = { const data: ContentNodeSelectorComponentData = {
title: `${action} '${contentEntry.name}' to ...`, title: this.getTitleTranslation(action, contentEntry.name),
actionName: action, actionName: action,
currentFolderId: contentEntry.id, currentFolderId: contentEntry.id,
imageResolver: this.imageResolver.bind(this), imageResolver: this.imageResolver.bind(this),
@ -208,7 +206,7 @@ export class ContentNodeDialogService {
}); });
const data: ContentNodeSelectorComponentData = { const data: ContentNodeSelectorComponentData = {
title: `${action} '${contentEntry.name}' to ...`, title: this.getTitleTranslation(action, contentEntry.name),
actionName: action, actionName: action,
currentFolderId: contentEntry.id, currentFolderId: contentEntry.id,
imageResolver: this.imageResolver.bind(this), imageResolver: this.imageResolver.bind(this),

View File

@ -1,7 +1,7 @@
<header <header
mat-dialog-title mat-dialog-title
data-automation-id="content-node-selector-title"> data-automation-id="content-node-selector-title">
<h2>{{data?.title}}</h2> <h2>{{title}}</h2>
</header> </header>
<mat-dialog-content> <mat-dialog-content>

View File

@ -33,8 +33,8 @@ describe('ContentNodeSelectorDialogComponent', () => {
let component: ContentNodeSelectorComponent; let component: ContentNodeSelectorComponent;
let fixture: ComponentFixture<ContentNodeSelectorComponent>; let fixture: ComponentFixture<ContentNodeSelectorComponent>;
const data: any = { const data: any = {
title: 'Move along citizen...', title: 'Choose along citizen...',
actionName: 'move', actionName: 'choose',
select: new EventEmitter<Node>(), select: new EventEmitter<Node>(),
rowFilter: (shareDataRow: ShareDataRow) => shareDataRow.node.entry.name === 'impossible-name', rowFilter: (shareDataRow: ShareDataRow) => shareDataRow.node.entry.name === 'impossible-name',
imageResolver: () => 'piccolo', imageResolver: () => 'piccolo',
@ -71,14 +71,14 @@ describe('ContentNodeSelectorDialogComponent', () => {
it('should show the INJECTED title', () => { it('should show the INJECTED title', () => {
const titleElement = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-title"]')); const titleElement = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-title"]'));
expect(titleElement).not.toBeNull(); expect(titleElement).not.toBeNull();
expect(titleElement.nativeElement.innerText).toBe('Move along citizen...'); expect(titleElement.nativeElement.innerText).toBe('Choose along citizen...');
}); });
it('should have the INJECTED actionName on the name of the choose button', () => { it('should have the INJECTED actionName on the name of the choose button', () => {
const actionButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-choose"]')); const actionButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-choose"]'));
expect(component.buttonActionName).toBe('NODE_SELECTOR.MOVE'); expect(component.buttonActionName).toBe('NODE_SELECTOR.CHOOSE');
expect(actionButton).not.toBeNull(); expect(actionButton).not.toBeNull();
expect(actionButton.nativeElement.innerText).toBe('NODE_SELECTOR.MOVE'); expect(actionButton.nativeElement.innerText).toBe('NODE_SELECTOR.CHOOSE');
}); });
it('should pass through the injected currentFolderId to the documentList', () => { it('should pass through the injected currentFolderId to the documentList', () => {
@ -156,4 +156,16 @@ describe('ContentNodeSelectorDialogComponent', () => {
expect(actionButton.nativeElement.disabled).toBeFalsy(); expect(actionButton.nativeElement.disabled).toBeFalsy();
}); });
}); });
describe('Title', () => {
it('should be updated when a node is chosen', () => {
component.onSelect([new Node({ id: 'fake', name: 'fake-node' })]);
fixture.detectChanges();
const titleElement = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-title"]'));
expect(titleElement).not.toBeNull();
expect(titleElement.nativeElement.innerText).toBe('NODE_SELECTOR.CHOOSE_ITEM');
});
});
}); });

View File

@ -17,6 +17,7 @@
import { Component, Inject, ViewEncapsulation } from '@angular/core'; import { Component, Inject, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material'; import { MAT_DIALOG_DATA } from '@angular/material';
import { TranslationService } from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api'; import { Node } from '@alfresco/js-api';
import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface'; import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface';
@ -28,11 +29,16 @@ import { ContentNodeSelectorComponentData } from './content-node-selector.compon
}) })
export class ContentNodeSelectorComponent { export class ContentNodeSelectorComponent {
title: string;
action: string;
buttonActionName: string; buttonActionName: string;
chosenNode: Node[]; chosenNode: Node[];
constructor(@Inject(MAT_DIALOG_DATA) public data: ContentNodeSelectorComponentData) { constructor(public translation: TranslationService,
this.buttonActionName = data.actionName ? `NODE_SELECTOR.${data.actionName.toUpperCase()}` : 'NODE_SELECTOR.CHOOSE'; @Inject(MAT_DIALOG_DATA) public data: ContentNodeSelectorComponentData) {
this.action = data.actionName.toUpperCase();
this.buttonActionName = data.actionName ? `NODE_SELECTOR.${this.action}` : 'NODE_SELECTOR.CHOOSE';
this.title = data.title;
} }
close() { close() {
@ -41,10 +47,21 @@ export class ContentNodeSelectorComponent {
onSelect(nodeList: Node[]) { onSelect(nodeList: Node[]) {
this.chosenNode = nodeList; this.chosenNode = nodeList;
this.updateTitle(nodeList);
} }
onClick(): void { onClick(): void {
this.data.select.next(this.chosenNode); this.data.select.next(this.chosenNode);
this.data.select.complete(); this.data.select.complete();
} }
updateTitle(nodeList: Node[]): void {
if (this.action === 'CHOOSE' && nodeList) {
this.title = this.getTitleTranslation(this.action, nodeList[0].name);
}
}
getTitleTranslation(action: string, name: string): string {
return this.translation.instant(`NODE_SELECTOR.${action}_ITEM`, { name });
}
} }

View File

@ -71,6 +71,7 @@
"NODE_SELECTOR": { "NODE_SELECTOR": {
"CANCEL": "Cancel", "CANCEL": "Cancel",
"CHOOSE": "Choose", "CHOOSE": "Choose",
"CHOOSE_ITEM": "Choose '{{ name }}' to...",
"COPY": "Copy", "COPY": "Copy",
"COPY_ITEM": "Copy '{{ name }}' to...", "COPY_ITEM": "Copy '{{ name }}' to...",
"MOVE": "Move", "MOVE": "Move",