From 2a7006229aa0a5f3b5f61ae64f7cfe9261c96e17 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 30 Nov 2024 16:16:01 +0000 Subject: [PATCH 1/2] Fix embed pagination buttons --- src/helpers/EffectHelper.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/helpers/EffectHelper.ts b/src/helpers/EffectHelper.ts index 275e8e6..11f6ed8 100644 --- a/src/helpers/EffectHelper.ts +++ b/src/helpers/EffectHelper.ts @@ -60,7 +60,7 @@ export default class EffectHelper { const effects = query[0]; const count = query[1]; - const isLastPage = Math.ceil(count / itemsPerPage) - 1 == page; + const totalPages = count > 0 ? Math.ceil(count / itemsPerPage) : 1; let description = "*none*"; @@ -71,7 +71,8 @@ export default class EffectHelper { const embed = new EmbedBuilder() .setTitle("Effects") .setDescription(description) - .setColor(EmbedColours.Ok); + .setColor(EmbedColours.Ok) + .setFooter({ text: `Page ${page} of ${totalPages}` }); const row = new ActionRowBuilder() .addComponents( @@ -79,12 +80,12 @@ export default class EffectHelper { .setCustomId(`effects list ${page - 1}`) .setLabel("Previous") .setStyle(ButtonStyle.Primary) - .setDisabled(page == 0), + .setDisabled(page - 1 == 0), new ButtonBuilder() .setCustomId(`effects list ${page + 1}`) .setLabel("Next") .setStyle(ButtonStyle.Primary) - .setDisabled(isLastPage), + .setDisabled(page == totalPages), ); return { From 6e6b2a0af61cf0c9ce3f274d90ecb3e47a544537 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 30 Nov 2024 16:38:02 +0000 Subject: [PATCH 2/2] Plan tests --- tests/buttonEvents/Effects.test.ts | 25 ++++++++++++++++++++++++ tests/commands/effects.test.ts | 31 ++++++++++++++++++++++++++++++ tests/helpers/EffectHelper.test.ts | 24 +++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 tests/buttonEvents/Effects.test.ts create mode 100644 tests/commands/effects.test.ts diff --git a/tests/buttonEvents/Effects.test.ts b/tests/buttonEvents/Effects.test.ts new file mode 100644 index 0000000..6c7bd97 --- /dev/null +++ b/tests/buttonEvents/Effects.test.ts @@ -0,0 +1,25 @@ +describe("execute", () => { + describe("GIVEN action in custom id is list", () => { + test.todo("EXPECT list function to be called"); + }); +}); + +describe("List", () => { + describe("GIVEN page is a valid number", () => { + test.todo("EXPECT EffectHelper.GenerateEffectEmbed to be called"); + + test.todo("EXPECT interaction to be updated"); + }); + + describe("GIVEN page in custom id is not supplied", () => { + test.todo("EXPECT interaction to be replied with error"); + + test.todo("EXPECT interaction to not be updated"); + }); + + describe("GIVEN page in custom id is not a number", () => { + test.todo("EXPECT interaction to be replied with error"); + + test.todo("EXPECT interaction to not be updated"); + }); +}); diff --git a/tests/commands/effects.test.ts b/tests/commands/effects.test.ts new file mode 100644 index 0000000..f2c14ce --- /dev/null +++ b/tests/commands/effects.test.ts @@ -0,0 +1,31 @@ +describe("constructor", () => { + test.todo("EXPECT CommandBuilder to be defined"); +}); + +describe("execute", () => { + describe("GIVEN interaction is not a chat input command", () => { + test.todo("EXPECT nothing to happen"); + }); + + describe("GIVEN subcommand is list", () => { + test.todo("EXPECT list function to be called"); + }); +}); + +describe("List", () => { + describe("GIVEN page option is supplied", () => { + describe("AND page is a valid number", () => { + test.todo("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page"); + + test.todo("EXPECT interaction to have been replied"); + }); + + describe("AND page is not a valid number", () => { + test.todo("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page of 1"); + }); + }); + + describe("GIVEN page option is not supplied", () => { + test.todo("EXPECT EffectHelper.GenerateEffectEmbed to have been called with a page of 1"); + }); +}); diff --git a/tests/helpers/EffectHelper.test.ts b/tests/helpers/EffectHelper.test.ts index 343f06c..2adcc9b 100644 --- a/tests/helpers/EffectHelper.test.ts +++ b/tests/helpers/EffectHelper.test.ts @@ -279,3 +279,27 @@ describe("HasEffect", () => { }); }); }); + +describe("GenerateEffectEmbed", () => { + test.todo("EXPECT UserEffect.FetchAllByUserIdPaginated to be called"); + + describe("GIVEN there are no effects returned", () => { + test.todo("EXPECT embed generated"); + + test.todo("EXPECT row generated"); + }); + + describe("GIVEN there are effects returned", () => { + test.todo("EXPECT embed generated"); + + test.todo("EXPECT row generated"); + + describe("AND it is the first page", () => { + test.todo("EXPECT Previous button to be disabled"); + }); + + describe("AND it is the last page", () => { + test.todo("EXPECT Next button to be disabled"); + }); + }); +});