add misc tests
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 12s

This commit is contained in:
Mylloon 2024-09-27 12:39:42 +02:00
parent 54e86e4722
commit d03aa48ff3
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

152
tests/misc.test.ts Normal file
View file

@ -0,0 +1,152 @@
const {
cleanCodeBlock,
emojiPng,
isImage,
removeExtension,
splitFilenameExtensions,
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require("../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("test name", () => {
{
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",
);
});
}
});