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

BC-5159 - gif display error add "coalesce" options #4561

Merged
merged 14 commits into from
Nov 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ import { PreviewGeneratorService } from './preview-generator.service';

const streamMock = jest.fn();
const resizeMock = jest.fn();
const coalesceMock = jest.fn();
const selectFrameMock = jest.fn();
const imageMagickMock = () => {
return { stream: streamMock, resize: resizeMock, selectFrame: selectFrameMock, data: Readable.from('text') };
return {
stream: streamMock,
resize: resizeMock,
selectFrame: selectFrameMock,
coalesce: coalesceMock,
data: Readable.from('text'),
};
};
jest.mock('gm', () => {
return {
Expand Down Expand Up @@ -165,7 +172,7 @@ describe('PreviewGeneratorService', () => {
return { params, originFile, expectedFileData };
};

it('should call imagemagicks resize method', async () => {
it('should call imagemagicks selectFrameMock method', async () => {
const { params } = setup();

await service.generatePreview(params);
Expand All @@ -174,6 +181,40 @@ describe('PreviewGeneratorService', () => {
expect(resizeMock).toHaveBeenCalledTimes(1);
});
});

describe('WHEN mime type is gif', () => {
const setup = (width = 500) => {
const params = {
originFilePath: 'file/test.gif',
previewFilePath: 'preview/text.webp',
previewOptions: {
format: 'webp',
width,
},
};
const originFile = createFile(undefined, 'image/gif');
s3ClientAdapter.get.mockResolvedValueOnce(originFile);

const data = Readable.from('text');
streamMock.mockReturnValueOnce(data);

const expectedFileData = {
data,
mimeType: params.previewOptions.format,
};

return { params, originFile, expectedFileData };
};

it('should call imagemagicks coalesce method', async () => {
const { params } = setup();

await service.generatePreview(params);

expect(coalesceMock).toHaveBeenCalledTimes(1);
expect(resizeMock).toHaveBeenCalledTimes(1);
});
});
});

describe('WHEN preview is not possible', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export class PreviewGeneratorService {
preview.selectFrame(0);
}

if (original.contentType === PreviewInputMimeTypes.IMAGE_GIF) {
preview.coalesce();
}

if (width) {
preview.resize(width, undefined, '>');
}
Expand Down
Loading