Skip to content

Commit

Permalink
BC-5159 - fix the gif display error by adding the "coalesce" option (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenWaysDP authored Nov 22, 2023
1 parent f48b9a0 commit 391aab8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
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

0 comments on commit 391aab8

Please sign in to comment.