NextPageButton.test.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { ButtonInteraction, MessageEmbed } from "discord.js";
  2. import { PaginationSent } from "djs-button-pages";
  3. import { NextPageButton } from "../src/Presets";
  4. describe("NextPageButton: button that switches pagination to the next page.", () => {
  5. test("action should switch pagination's page and call an update method.", async () => {
  6. const switchPageMock = jest.fn(),
  7. updateMock = jest.fn(),
  8. pagesMock = ({
  9. update: updateMock,
  10. setPage:switchPageMock,
  11. page: 1,
  12. } as unknown) as PaginationSent,
  13. interactionMock = ({} as unknown) as ButtonInteraction;
  14. const button = new NextPageButton();
  15. await button.action(pagesMock, interactionMock);
  16. expect(switchPageMock).toHaveBeenCalledWith(2);
  17. expect(updateMock).toHaveBeenCalled();
  18. });
  19. test("switch should be disabled only when pagination is set to the last page.", async () => {
  20. const pagesMock1 = ({
  21. page: 2,
  22. data:
  23. {
  24. embeds:
  25. [
  26. new MessageEmbed(),
  27. new MessageEmbed(),
  28. new MessageEmbed(),
  29. new MessageEmbed()
  30. ]
  31. }} as unknown) as PaginationSent;
  32. const button = new NextPageButton();
  33. expect(await button.switch(pagesMock1)).toBeFalsy();
  34. const pagesMock2 = ({
  35. page: 1,
  36. data:
  37. {
  38. embeds:
  39. [
  40. new MessageEmbed(),
  41. new MessageEmbed()
  42. ]
  43. }} as unknown) as PaginationSent;
  44. expect(await button.switch(pagesMock2)).toBeTruthy();
  45. });
  46. });