Add a test, speed up large tests
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 18s

This commit is contained in:
Mylloon 2024-10-14 23:36:30 +02:00
parent c7fff7520b
commit 23f8d5d4d1
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -12,6 +12,9 @@ describe("Attachements Handler", () => {
["e_attachements", "yes_s"], ["e_attachements", "yes_s"],
["e_attachement", "no_s"], ["e_attachement", "no_s"],
]); ]);
// 102 is the maximum for [f](url) before rupture in a field
const max = 102;
const max_field = Array.from({ length: max }, () => "[f](url)").join(", ");
{ {
const name = "One image"; const name = "One image";
test(name, () => { test(name, () => {
@ -28,6 +31,28 @@ describe("Attachements Handler", () => {
expect(embedTest).toStrictEqual(embedExpected); expect(embedTest).toStrictEqual(embedExpected);
}); });
} }
{
const name = "Two images";
test(name, () => {
const embedExpected = new EmbedBuilder();
embedExpected.addFields({
name: "yes_s",
value: "[image.png](http://url), [image.png](http://url)",
});
const embedTest = new EmbedBuilder();
handleAttachments(
map,
embedTest,
new Collection([
[newKey(), { name: "image.png", url: "http://url" } as Attachment],
[newKey(), { name: "image.png", url: "http://url" } as Attachment],
]),
);
expect(embedTest).toStrictEqual(embedExpected);
});
}
{ {
const name = "One link"; const name = "One link";
test(name, () => { test(name, () => {
@ -66,15 +91,13 @@ describe("Attachements Handler", () => {
{ {
const name = "Two fields with multiples files each"; const name = "Two fields with multiples files each";
test(name, () => { test(name, () => {
// 102 is the maximum for [f](url) before rupture
const max = 102;
const total = 150; const total = 150;
const embedExpected = new EmbedBuilder(); const embedExpected = new EmbedBuilder();
embedExpected.addFields( embedExpected.addFields(
{ {
name: "yes_s (1)", name: "yes_s (1)",
value: Array.from({ length: max }, () => "[f](url)").join(", "), value: max_field,
}, },
{ {
name: "yes_s (2)", name: "yes_s (2)",
@ -97,15 +120,13 @@ describe("Attachements Handler", () => {
{ {
const name = "Two fields with one field with one element"; const name = "Two fields with one field with one element";
test(name, () => { test(name, () => {
// 102 is the maximum for [f](url) before rupture
const max = 102;
const total = 103; const total = 103;
const embedExpected = new EmbedBuilder(); const embedExpected = new EmbedBuilder();
embedExpected.addFields( embedExpected.addFields(
{ {
name: "yes_s (1)", name: "yes_s (1)",
value: Array.from({ length: max }, () => "[f](url)").join(", "), value: max_field,
}, },
{ {
name: "no_s (2)", name: "no_s (2)",