FirstPageButton.test.ts 1.3 KB

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