PreviousPageButton.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { ButtonInteraction } from "discord.js";
  2. import { PaginationSent } from "djs-button-pages";
  3. import { PreviousPageButton } from "../src/Presets";
  4. describe("PreviousPageButton: button that switches pagination to the previous 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 PreviousPageButton();
  15. await button.action(pagesMock, interactionMock);
  16. expect(switchPageMock).toHaveBeenCalledWith(0);
  17. expect(updateMock).toHaveBeenCalled();
  18. });
  19. test("switch should be disabled only when pagination is set to the first page.", async () => {
  20. const pagesMock1 = ({
  21. page: 1
  22. } as unknown) as PaginationSent;
  23. const button = new PreviousPageButton();
  24. expect(await button.switch(pagesMock1)).toBeFalsy();
  25. const pagesMock2 = ({
  26. page: 0
  27. } as unknown) as PaginationSent;
  28. expect(await button.switch(pagesMock2)).toBeTruthy();
  29. });
  30. });