Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACS-5600] AlfrescoViewerComponent shows the original mimetype #9095

Merged
merged 9 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/core/components/viewer.component.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ See the [Custom layout](#custom-layout) section for full details of all availabl
| canNavigateNext | `boolean` | true | Toggles the next (">") button. Requires `allowNavigate` to be enabled. |
| fileName | `string` | | Override Content filename. |
| mimeType | `string` | | Overload mimeType |
| originalMimeType | `string` | | Overload originalMimeType |
| overlayMode | `boolean` | false | If `true` then show the Viewer as a full page over the current content. Otherwise fit inside the parent div. |
| readOnly | `boolean` | true | Enable when where is possible the editing functionalities |
| showLeftSidebar | `boolean` | false | Toggles left sidebar visibility. Requires `allowLeftSidebar` to be set to `true`. |
Expand Down Expand Up @@ -113,6 +114,7 @@ You can provide custom file parameters, for example a value for the `mimeType` o
[fileName]="fileName"
[allowGoBack]="false"
[mimeType]="mimeType"
[originalMimeType]="originalMimeType"
[urlFile]="fileUrl">
</adf-viewer>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
[sidebarLeftTemplateContext]="sidebarLeftTemplateContext"
[fileName]="fileName"
[mimeType]="mimeType"
[originalMimeType]="originalMimeType"
[urlFile]="urlFileContent"
[tracks]="tracks"
[readOnly]="readOnly"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,42 @@ describe('AlfrescoViewerComponent', () => {
//
});

describe('originalMimeType', () => {
it('should set originalMimeType based on nodeData content', async () => {
const defaultNode: Node = {
id: 'mock-id',
name: 'Mock Node',
nodeType: 'cm:content',
isFolder: false,
isFile: true,
modifiedAt: new Date(),
modifiedByUser: { id: 'user123', displayName: 'John Doe' },
createdAt: new Date(),
createdByUser: { id: 'user456', displayName: 'Jane Doe' },
properties: { 'cm:versionLabel': 'mock-version-label' }
};
component.nodeEntry = { entry: defaultNode };
component.nodeId = '123';
spyOn(renditionService, 'getNodeRendition').and.returnValue(
Promise.resolve({
url: '',
mimeType: ''
})
);

fixture.detectChanges();
nodesApiService.nodeUpdated.next({
id: '123',
name: 'file2',
content: {
mimeType: 'application/msWord'
}
} as any);
await fixture.whenStable();
expect(component.originalMimeType).toEqual('application/msWord');
});
});

describe('Toolbar', () => {
it('should show only next file button', async () => {
component.allowNavigate = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
urlFileContent: string;
fileName: string;
mimeType: string;
originalMimeType: string;
nodeEntry: NodeEntry;
tracks: Track[] = [];
readOnly: boolean = true;
Expand Down Expand Up @@ -328,6 +329,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
if (nodeRendition) {
urlFileContent = nodeRendition.url;
mimeType = nodeRendition.mimeType;
this.originalMimeType = nodeData?.content?.mimeType;
}
} else if (viewerType === 'media') {
this.tracks = await this.renditionService.generateMediaTracksRendition(this.nodeId);
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/lib/viewer/components/viewer.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<mat-icon>navigate_before</mat-icon>
</button>
<img class="adf-viewer__mimeicon"
[alt]="mimeType"
[src]="mimeType | adfMimeTypeIcon"
[alt]="originalMimeType || mimeType"
[src]="(originalMimeType || mimeType) | adfMimeTypeIcon"
data-automation-id="adf-file-thumbnail">
<span class="adf-viewer__display-name"
id="adf-viewer-display-name">{{ fileName }}</span>
Expand Down
32 changes: 32 additions & 0 deletions lib/core/src/lib/viewer/components/viewer.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,38 @@ describe('ViewerComponent', () => {

});

describe('originalMimeType', () => {
const getMimeTypeIconElement = () => fixture.nativeElement.querySelector('.adf-viewer__mimeicon');

it('should set alt attribute to originalMimeType when originalMimeType is provided', () => {
AleksanderSklorz marked this conversation as resolved.
Show resolved Hide resolved
component.originalMimeType = 'image/png';
fixture.detectChanges();
const altAttribute: string = getMimeTypeIconElement().getAttribute('alt');
expect(altAttribute).toBe('image/png');
});

it('should set src attribute based on originalMimeType when originalMimeType is provided', () => {
AleksanderSklorz marked this conversation as resolved.
Show resolved Hide resolved
component.originalMimeType = 'image';
fixture.detectChanges();
const srcAttribute: string = getMimeTypeIconElement().getAttribute('src');
expect(srcAttribute).toContain('image');
});

it('should set alt attribute to mimeType when originalMimeType is not provided', () => {
component.mimeType = 'application/pdf';
fixture.detectChanges();
const altAttribute: string = getMimeTypeIconElement().getAttribute('alt');
expect(altAttribute).toBe('application/pdf');
});

it('should set src attribute based on mimeType when originalMimeType is not provided', () => {
component.mimeType = 'image';
fixture.detectChanges();
const srcAttribute: string = getMimeTypeIconElement().getAttribute('src');
expect(srcAttribute).toContain('image');
});
});

describe('File Name Test', () => {

it('should fileName be set by urlFile input if the fileName is not provided as Input', () => {
Expand Down
4 changes: 4 additions & 0 deletions lib/core/src/lib/viewer/components/viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
@Input()
mimeType: string;

/** Overload originalMimeType*/
@Input()
originalMimeType: string;
AleksanderSklorz marked this conversation as resolved.
Show resolved Hide resolved

/**
* Context object available for binding by the local sidebarRightTemplate with let declarations.
*/
Expand Down
Loading