NextPageButton.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { MessageEmbed } from "discord.js";
  2. import NextPageButton from "../../src/Classes/Buttons/NextPageButton";
  3. import PaginationData from "../../src/Classes/Paginations/Basic/PaginationData";
  4. describe("Button that switches pagination to the next page", () => {
  5. test("should initialize with action and disableWhen.", async () => {
  6. const button = new NextPageButton();
  7. expect(button.action).toBeInstanceOf(Function);
  8. expect(button.disableWhen).toBeInstanceOf(Function);
  9. const dataMock: PaginationData = ({
  10. embeds: [new MessageEmbed().setDescription("1"), new MessageEmbed().setDescription("2")],
  11. currentPage: 0,
  12. } as unknown) as PaginationData;
  13. if(!dataMock.embeds)
  14. throw new Error("No embeds!");
  15. if (!(button.action instanceof Function))
  16. throw new Error("Action should be a function!");
  17. const result = await button.action(dataMock);
  18. expect(result).toBe(dataMock.currentPage + 1);
  19. if (!(button.disableWhen instanceof Function))
  20. throw new Error("DisableWhen should be a function!");
  21. const anotherResult = await button.disableWhen(dataMock, 1);
  22. expect(anotherResult).toBe(dataMock.embeds.length - 1);
  23. });
  24. test("should throw error if no embeds supplied.", async () => {
  25. const button = new NextPageButton();
  26. const dataMock: PaginationData = ({} as unknown) as PaginationData;
  27. await expect(async () => {
  28. if (!(button.disableWhen instanceof Function))
  29. throw new Error("Action should be a function!");
  30. await button.disableWhen(dataMock, -1);
  31. }).rejects.toThrow("Next page button can't be used before embeds are supplied to the pagination.");
  32. });
  33. });