behavior-runtime.test.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { describe, expect, it } from "vitest";
  2. import { actionSchema } from "../src/index.js";
  3. describe("actionSchema.play-bgm", () => {
  4. it("accepts play-bgm with soundId and fadeMs", () => {
  5. const result = actionSchema.safeParse({ action: "play-bgm", soundId: "bgm-x", fadeMs: 300 });
  6. expect(result.success).toBe(true);
  7. if (result.success) {
  8. expect(result.data).toEqual({ action: "play-bgm", soundId: "bgm-x", fadeMs: 300 });
  9. }
  10. });
  11. it("accepts play-bgm with only soundId (fadeMs optional)", () => {
  12. const result = actionSchema.safeParse({ action: "play-bgm", soundId: "bgm-y" });
  13. expect(result.success).toBe(true);
  14. if (result.success) {
  15. expect(result.data).toEqual({ action: "play-bgm", soundId: "bgm-y" });
  16. }
  17. });
  18. it("rejects play-bgm without soundId", () => {
  19. const result = actionSchema.safeParse({ action: "play-bgm", fadeMs: 300 });
  20. expect(result.success).toBe(false);
  21. });
  22. it("rejects play-bgm with empty soundId", () => {
  23. const result = actionSchema.safeParse({ action: "play-bgm", soundId: "" });
  24. expect(result.success).toBe(false);
  25. });
  26. it("rejects play-bgm with non-positive fadeMs", () => {
  27. const result1 = actionSchema.safeParse({ action: "play-bgm", soundId: "x", fadeMs: 0 });
  28. expect(result1.success).toBe(false);
  29. const result2 = actionSchema.safeParse({ action: "play-bgm", soundId: "x", fadeMs: -100 });
  30. expect(result2.success).toBe(false);
  31. });
  32. it("rejects play-bgm with non-integer fadeMs", () => {
  33. const result = actionSchema.safeParse({ action: "play-bgm", soundId: "x", fadeMs: 1.5 });
  34. expect(result.success).toBe(false);
  35. });
  36. });
  37. describe("actionSchema.stop-bgm", () => {
  38. it("accepts stop-bgm with fadeMs", () => {
  39. const result = actionSchema.safeParse({ action: "stop-bgm", fadeMs: 500 });
  40. expect(result.success).toBe(true);
  41. if (result.success) {
  42. expect(result.data).toEqual({ action: "stop-bgm", fadeMs: 500 });
  43. }
  44. });
  45. it("accepts stop-bgm without fadeMs", () => {
  46. const result = actionSchema.safeParse({ action: "stop-bgm" });
  47. expect(result.success).toBe(true);
  48. if (result.success) {
  49. expect(result.data).toEqual({ action: "stop-bgm" });
  50. }
  51. });
  52. it("rejects stop-bgm with non-positive fadeMs", () => {
  53. const result1 = actionSchema.safeParse({ action: "stop-bgm", fadeMs: 0 });
  54. expect(result1.success).toBe(false);
  55. const result2 = actionSchema.safeParse({ action: "stop-bgm", fadeMs: -50 });
  56. expect(result2.success).toBe(false);
  57. });
  58. it("rejects stop-bgm with non-integer fadeMs", () => {
  59. const result = actionSchema.safeParse({ action: "stop-bgm", fadeMs: 2.5 });
  60. expect(result.success).toBe(false);
  61. });
  62. });