import { cleanCodeBlock, emojiPng, isImage, removeExtension, splitFilenameExtensions, } from "../../src/utils/misc"; describe("Filename splitter", () => { { const name = "test.js"; test(name, () => { expect(splitFilenameExtensions(name)).toStrictEqual({ file: "test", ext: "js" }); }); } { const name = ".env"; test(name, () => { expect(splitFilenameExtensions(name)).toStrictEqual({ file: ".env", ext: undefined }); }); } { const name = ".env.test"; test(name, () => { expect(splitFilenameExtensions(name)).toStrictEqual({ file: ".env", ext: "test", }); }); } { const name = "file.test.js"; test(name, () => { expect(splitFilenameExtensions(name)).toStrictEqual({ file: "file.test", ext: "js" }); }); } }); describe("Extension remover", () => { { const name = "test.js"; test(name, () => { expect(removeExtension(name)).toBe("test"); }); } { const name = ".env"; test(name, () => { expect(removeExtension(name)).toBe(".env"); }); } { const name = ".env.test"; test(name, () => { expect(removeExtension(name)).toBe(".env"); }); } { const name = "file.test.js"; test(name, () => { expect(removeExtension(name)).toBe("file.test"); }); } }); describe("Image checker", () => { { const name = "image.Png"; test(name, () => { expect(isImage(name)).toBe(true); }); } { const name = "image.jpeg"; test(name, () => { expect(isImage(name)).toBe(true); }); } { const name = "image.wav"; test(name, () => { expect(isImage(name)).toBe(false); }); } { const name = "image.jpg"; test(name, () => { expect(isImage(name)).toBe(true); }); } { const name = "image.webP"; test(name, () => { expect(isImage(name)).toBe(true); }); } { const name = "image.GIF"; test(name, () => { expect(isImage(name)).toBe(true); }); } }); describe("Code block cleaner", () => { { const name = "salut"; test(name, () => { expect(cleanCodeBlock(name)).toBe("`salut`"); }); } { const name = "<@158260864623968257> ça va ?"; test(name, () => { expect(cleanCodeBlock(name)).toBe("<@158260864623968257>` ça va ?`"); }); } { const name = "t'as vu la vidéo ? https://youtu.be/dQw4w9WgXcQ"; test(name, () => { expect(cleanCodeBlock(name)).toBe("`t'as vu la vidéo ? `https://youtu.be/dQw4w9WgXcQ"); }); } { const name = "t'as vu la vidéo ? https://youtu.be/dQw4w9WgXcQ elle est cool en vrai tqt"; test(name, () => { expect(cleanCodeBlock(name)).toBe( "`t'as vu la vidéo ? `https://youtu.be/dQw4w9WgXcQ` elle est cool en vrai tqt`", ); }); } }); describe("Emoji to link", () => { { const name = "☺️"; test(name, () => { expect(emojiPng(name)).toBe( "https://cdn.jsdelivr.net/gh/twitter/twemoji/assets/72x72/263a.png", ); }); } { const name = "🍕"; test(name, () => { expect(emojiPng(name)).toBe( "https://cdn.jsdelivr.net/gh/twitter/twemoji/assets/72x72/1f355.png", ); }); } });