ButtonData.test.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { MessageButton } from "discord.js";
  2. import ButtonData from "../../../src/Classes/Buttons/Basic/ButtonData";
  3. describe("Button data", () => {
  4. test("should initialize with a null style, null action and null disableWhen.", () => {
  5. const button = new ButtonData();
  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 ButtonData(style).style).toBe(style);
  13. const buttonStyle = new ButtonData().setStyle(new MessageButton().setCustomId("testid").setLabel("button").setStyle("PRIMARY"));
  14. expect(new ButtonData(buttonStyle).style).toBe(buttonStyle.style);
  15. });
  16. test("setStyle should throw error if there are no customId.", () => {
  17. const incorrectStyle = new MessageButton().setLabel("button").setStyle("PRIMARY");
  18. expect(() => new ButtonData(incorrectStyle)).toThrow("Button should have customId, emoji or label and style.");
  19. });
  20. test("setStyle should throw error if there are no label or emoji.", () => {
  21. const incorrectStyle = new MessageButton().setCustomId("testid").setStyle("PRIMARY");
  22. expect(() => new ButtonData(incorrectStyle)).toThrow("Button should have customId, emoji or label and style.");
  23. });
  24. test("setStyle should throw error if there are no style.", () => {
  25. const incorrectStyle = new MessageButton().setCustomId("testid").setEmoji("▶");
  26. expect(() => new ButtonData(incorrectStyle)).toThrow("Button should have customId, emoji or label and style.");
  27. });
  28. test("setStyle should throw error if LINK style is passed.", () => {
  29. const incorrectStyle = new MessageButton().setCustomId("testid").setEmoji("▶").setStyle("LINK");
  30. expect(() => new ButtonData(incorrectStyle)).toThrow("Button can't have link style, because component collector can't collect it's interaction.");
  31. });
  32. });