59 lines
2.2 KiB
TypeScript
59 lines
2.2 KiB
TypeScript
import { getFilename } from './handleMediaDownload';
|
|
|
|
describe('Test the getFilename', () => {
|
|
it('returns the title without changes', () => {
|
|
const { image_type, image_url, title } = {
|
|
title: 'help-image.png',
|
|
image_url: '/file-upload/oTQmb2zRCsYF4pdHv/help-image-url.png',
|
|
image_type: 'image/png'
|
|
};
|
|
|
|
const filename = getFilename({ type: 'image', mimeType: image_type, title, url: image_url });
|
|
expect(filename).toBe(title);
|
|
});
|
|
|
|
it("returns the title with correct extension based on image_type when the title's extension is wrong", () => {
|
|
const { image_type, image_url, title } = {
|
|
title: 'help-image.MOV',
|
|
image_url: '/file-upload/oTQmb2zRCsYF4pdHv/help-image-url.MOV',
|
|
image_type: 'image/png'
|
|
};
|
|
|
|
const filename = getFilename({ type: 'image', mimeType: image_type, title, url: image_url });
|
|
expect(filename).toBe('help-image.png');
|
|
});
|
|
|
|
it("returns the filename from image_url when there isn't extension at title", () => {
|
|
const { image_type, image_url, title } = {
|
|
title: 'help-image',
|
|
image_url: '/file-upload/oTQmb2zRCsYF4pdHv/help-image-url.png',
|
|
image_type: 'image/png'
|
|
};
|
|
|
|
const filename = getFilename({ type: 'image', mimeType: image_type, title, url: image_url });
|
|
expect(filename).toBe('help-image-url.png');
|
|
});
|
|
|
|
it("returns the filename from image_url with correct extension based on image_type when there isn't extension at title and the image_url's extension is wrong", () => {
|
|
const { image_type, image_url, title } = {
|
|
title: 'help-image',
|
|
image_url: '/file-upload/oTQmb2zRCsYF4pdHv/help-image-url.MOV',
|
|
image_type: 'image/png'
|
|
};
|
|
|
|
const filename = getFilename({ type: 'image', mimeType: image_type, title, url: image_url });
|
|
expect(filename).toBe('help-image-url.png');
|
|
});
|
|
|
|
it("returns the filename from image_url and based on the image_type when there isn't extension either at title and image_url", () => {
|
|
const { image_type, image_url, title } = {
|
|
title: 'help-image',
|
|
image_url: '/file-upload/oTQmb2zRCsYF4pdHv/help-image-url.png',
|
|
image_type: 'image/png'
|
|
};
|
|
|
|
const filename = getFilename({ type: 'image', mimeType: image_type, title, url: image_url });
|
|
expect(filename).toBe('help-image-url.png');
|
|
});
|
|
});
|