mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-9619] Issues with trimming file's name in viewer (#10858)
This commit is contained in:
committed by
GitHub
parent
467a19f3ec
commit
1971980216
@@ -49,8 +49,7 @@
|
||||
<div class="adf-viewer__display-name"
|
||||
id="adf-viewer-display-name"
|
||||
[title]="fileName">
|
||||
<span class="adf-viewer__display-name-without-extension">{{ fileNameWithoutExtension }}</span>
|
||||
<span class="adf-viewer__display-name-extension">{{ fileExtension }}</span>
|
||||
<span>{{ displayName }}</span>
|
||||
</div>
|
||||
<button *ngIf="allowNavigate && canNavigateNext"
|
||||
data-automation-id="adf-toolbar-next-file"
|
||||
|
@@ -55,23 +55,10 @@
|
||||
|
||||
&__display-name {
|
||||
font-size: var(--theme-subheading-2-font-size);
|
||||
opacity: 0.87;
|
||||
line-height: 1.5;
|
||||
letter-spacing: -0.4px;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
font-stretch: normal;
|
||||
vertical-align: middle;
|
||||
color: var(--adf-theme-foreground-text-color);
|
||||
|
||||
&-without-extension {
|
||||
display: inline-block;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
max-width: 400px;
|
||||
white-space: nowrap;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&-container {
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, SimpleChanges } from '@angular/core';
|
||||
import { ComponentFixture, discardPeriodicTasks, fakeAsync, flush, TestBed, tick } from '@angular/core/testing';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
@@ -143,36 +143,61 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('File Name Test', () => {
|
||||
const getFileNameWithoutExtension = (): string =>
|
||||
testingUtils.getByCSS('.adf-viewer__display-name-without-extension').nativeElement.textContent;
|
||||
const getExtension = (): string => testingUtils.getByCSS('.adf-viewer__display-name-extension').nativeElement.textContent;
|
||||
describe('File Name Display Tests', () => {
|
||||
describe('displayFileName method', () => {
|
||||
it('should return full filename when total length is 80 characters or less', () => {
|
||||
const fileShortName = 'shortname.txt';
|
||||
component.fileName = fileShortName;
|
||||
fixture.detectChanges();
|
||||
|
||||
it('should fileName be set by urlFile input if the fileName is not provided as Input', () => {
|
||||
component.fileName = '';
|
||||
spyOn(viewUtilService, 'getFilenameFromUrl').and.returnValue('fakeFileName.jpeg');
|
||||
const mockSimpleChanges: any = { urlFile: { currentValue: 'https://fakefile.url/fakeFileName.jpeg' } };
|
||||
expect(component.getDisplayFileName()).toBe(fileShortName);
|
||||
expect(getFileName()).toBe(fileShortName);
|
||||
});
|
||||
|
||||
component.ngOnChanges(mockSimpleChanges);
|
||||
fixture.detectChanges();
|
||||
it('should truncate filename when total length exceeds 80 characters', () => {
|
||||
const longName =
|
||||
'verylongfilenamethatexceedsmaximumlengthallowedverylongfilenamethatexceedsmaximumlengthallowed.verylongextensionnamethatistoolongverylongextensionnamethatistoolong';
|
||||
|
||||
expect(getFileName()).toEqual('fakeFileName.jpeg');
|
||||
expect(getFileNameWithoutExtension()).toBe('fakeFileName.');
|
||||
expect(getExtension()).toBe('jpeg');
|
||||
component.fileName = longName;
|
||||
fixture.detectChanges();
|
||||
|
||||
const result = component.getDisplayFileName();
|
||||
|
||||
expect(result).toContain('.....');
|
||||
expect(result.length).toBe(50);
|
||||
});
|
||||
|
||||
it('should handle empty filename', () => {
|
||||
component.fileName = '';
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.getDisplayFileName()).toBe('');
|
||||
expect(getFileName()).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
it('should set fileName providing fileName input', () => {
|
||||
component.fileName = 'testFileName.jpg';
|
||||
spyOn(viewUtilService, 'getFilenameFromUrl').and.returnValue('fakeFileName.jpeg');
|
||||
const mockSimpleChanges: any = { urlFile: { currentValue: 'https://fakefile.url/fakeFileName.jpeg' } };
|
||||
describe('fileName setter integration', () => {
|
||||
it('should fileName be set by urlFile input if the fileName is not provided as Input', () => {
|
||||
component.fileName = '';
|
||||
spyOn(viewUtilService, 'getFilenameFromUrl').and.returnValue('fakeFileName.jpeg');
|
||||
const mockSimpleChanges = { urlFile: { currentValue: 'https://fakefile.url/fakeFileName.jpeg' } } as unknown as SimpleChanges;
|
||||
|
||||
component.ngOnChanges(mockSimpleChanges);
|
||||
fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
component.ngOnChanges(mockSimpleChanges);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(getFileName()).toEqual('testFileName.jpg');
|
||||
expect(getFileNameWithoutExtension()).toBe('testFileName.');
|
||||
expect(getExtension()).toBe('jpg');
|
||||
expect(getFileName()).toEqual('fakeFileName.jpeg');
|
||||
});
|
||||
|
||||
it('should set fileName providing fileName input', () => {
|
||||
component.fileName = 'testFileName.jpg';
|
||||
spyOn(viewUtilService, 'getFilenameFromUrl').and.returnValue('fakeFileName.jpeg');
|
||||
const mockSimpleChanges = { urlFile: { currentValue: 'https://fakefile.url/fakeFileName.jpeg' } } as unknown as SimpleChanges;
|
||||
|
||||
component.ngOnChanges(mockSimpleChanges);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(getFileName()).toEqual('testFileName.jpg');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -297,6 +297,7 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
|
||||
private _fileNameWithoutExtension: string;
|
||||
private _fileExtension: string;
|
||||
|
||||
public displayName: string;
|
||||
public downloadPromptTimer: number;
|
||||
public downloadPromptReminderTimer: number;
|
||||
public mimeTypeIconUrl: string;
|
||||
@@ -309,6 +310,7 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
|
||||
this._fileName = fileName;
|
||||
this._fileExtension = this.viewUtilsService.getFileExtension(this.fileName);
|
||||
this._fileNameWithoutExtension = this.fileName?.replace(new RegExp(`${this.fileExtension}$`), '') || '';
|
||||
this.displayName = this.getDisplayFileName();
|
||||
}
|
||||
|
||||
get fileName(): string {
|
||||
@@ -462,6 +464,24 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
|
||||
this.clearDownloadPromptTimeouts();
|
||||
}
|
||||
|
||||
getDisplayFileName(): string {
|
||||
const fullName = (this.fileNameWithoutExtension || '') + (this.fileExtension || '');
|
||||
const maxLength = 50;
|
||||
|
||||
if (fullName.length <= maxLength) {
|
||||
return fullName;
|
||||
}
|
||||
|
||||
const amountOfTruncateDots = 5;
|
||||
const availableSpace = maxLength - amountOfTruncateDots;
|
||||
const endLength = 8;
|
||||
const startLength = availableSpace - endLength;
|
||||
|
||||
const start = fullName.substring(0, startLength);
|
||||
const end = fullName.substring(fullName.length - endLength);
|
||||
return start + '.....' + end;
|
||||
}
|
||||
|
||||
private configureAndInitDownloadPrompt() {
|
||||
this.configureDownloadPromptProperties();
|
||||
if (this.enableDownloadPrompt) {
|
||||
|
Reference in New Issue
Block a user