CustomButton.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { MessageButton } from "discord.js";
  2. import CustomButton from "../../src/Classes/Buttons/CustomButton";
  3. describe("Button that has custom scripts", () => {
  4. test("should initialize with a null style, null action and null disableWhen.", () => {
  5. const button = new CustomButton();
  6. expect(button.style).toBeNull();
  7. expect(button.action).toBeNull();
  8. expect(button.disableWhen).toBeNull();
  9. });
  10. test("should initialize with a given style.", () => {
  11. const style = new MessageButton().setCustomId("testid").setLabel("button").setStyle("PRIMARY");
  12. expect(new CustomButton(style).style).toBe(style);
  13. const buttonStyle = new CustomButton().setStyle(new MessageButton().setCustomId("testid").setLabel("button").setStyle("PRIMARY")).setAction(1).setDisableWhen(1),
  14. button = new CustomButton(buttonStyle);
  15. expect(button.style).toBe(buttonStyle.style);
  16. expect(button.action).toBe(buttonStyle.action);
  17. expect(button.disableWhen).toBe(buttonStyle.disableWhen);
  18. });
  19. test("setAction should throw error if floating point number is passed.", () => {
  20. const button = new CustomButton();
  21. expect(() => button.setAction(2.5)).toThrow("Action should return natural number or minus one to stop pagination.");
  22. });
  23. test("setAction should throw error if negative number, except minus one, is passed.", () => {
  24. const button = new CustomButton();
  25. expect(() => button.setAction(-2)).toThrow("Action should return natural number or minus one to stop pagination.");
  26. expect(button.setAction(-1).action).toBe(-1);
  27. });
  28. test("setDisableWhen should throw error if floating point number is passed.", () => {
  29. const button = new CustomButton();
  30. expect(() => button.setDisableWhen(2.5)).toThrow("DisableWhen should return natural number or minus one to be always turned on.");
  31. });
  32. test("setDisableWhen should throw error if negative number, except minus one, is passed.", () => {
  33. const button = new CustomButton();
  34. expect(() => button.setDisableWhen(-2)).toThrow("DisableWhen should return natural number or minus one to be always turned on.");
  35. expect(button.setDisableWhen(-1).disableWhen).toBe(-1);
  36. });
  37. });