LastPageButton.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { ButtonInteraction, MessageEmbed } from "discord.js";
  2. import { PaginationSent } from "djs-button-pages";
  3. import { LastPageButton } from "../src/Presets";
  4. describe("LastPageButton: button that switches pagination to the last 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. data:
  12. {
  13. embeds:
  14. [
  15. new MessageEmbed(),
  16. new MessageEmbed()
  17. ]
  18. }} as unknown) as PaginationSent,
  19. interactionMock = ({} as unknown) as ButtonInteraction;
  20. const button = new LastPageButton();
  21. await button.action(pagesMock, interactionMock);
  22. expect(switchPageMock).toHaveBeenCalledWith(1);
  23. expect(updateMock).toHaveBeenCalled();
  24. });
  25. test("switch should be disabled only when pagination is set to the last page.", async () => {
  26. const pagesMock1 = ({
  27. page: 2,
  28. data:
  29. {
  30. embeds:
  31. [
  32. new MessageEmbed(),
  33. new MessageEmbed(),
  34. new MessageEmbed(),
  35. new MessageEmbed()
  36. ]
  37. }} as unknown) as PaginationSent;
  38. const button = new LastPageButton();
  39. expect(await button.switch(pagesMock1)).toBeFalsy();
  40. const pagesMock2 = ({
  41. page: 1,
  42. data:
  43. {
  44. embeds:
  45. [
  46. new MessageEmbed(),
  47. new MessageEmbed()
  48. ]
  49. }} as unknown) as PaginationSent;
  50. expect(await button.switch(pagesMock2)).toBeTruthy();
  51. });
  52. });