LastPageButton.test.ts 1.4 KB

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