| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import { describe, expect, it } from "vitest";
- import { actionSchema } from "../src/index.js";
- describe("actionSchema.play-bgm", () => {
- it("accepts play-bgm with soundId and fadeMs", () => {
- const result = actionSchema.safeParse({ action: "play-bgm", soundId: "bgm-x", fadeMs: 300 });
- expect(result.success).toBe(true);
- if (result.success) {
- expect(result.data).toEqual({ action: "play-bgm", soundId: "bgm-x", fadeMs: 300 });
- }
- });
- it("accepts play-bgm with only soundId (fadeMs optional)", () => {
- const result = actionSchema.safeParse({ action: "play-bgm", soundId: "bgm-y" });
- expect(result.success).toBe(true);
- if (result.success) {
- expect(result.data).toEqual({ action: "play-bgm", soundId: "bgm-y" });
- }
- });
- it("rejects play-bgm without soundId", () => {
- const result = actionSchema.safeParse({ action: "play-bgm", fadeMs: 300 });
- expect(result.success).toBe(false);
- });
- it("rejects play-bgm with empty soundId", () => {
- const result = actionSchema.safeParse({ action: "play-bgm", soundId: "" });
- expect(result.success).toBe(false);
- });
- it("rejects play-bgm with non-positive fadeMs", () => {
- const result1 = actionSchema.safeParse({ action: "play-bgm", soundId: "x", fadeMs: 0 });
- expect(result1.success).toBe(false);
- const result2 = actionSchema.safeParse({ action: "play-bgm", soundId: "x", fadeMs: -100 });
- expect(result2.success).toBe(false);
- });
- it("rejects play-bgm with non-integer fadeMs", () => {
- const result = actionSchema.safeParse({ action: "play-bgm", soundId: "x", fadeMs: 1.5 });
- expect(result.success).toBe(false);
- });
- });
- describe("actionSchema.stop-bgm", () => {
- it("accepts stop-bgm with fadeMs", () => {
- const result = actionSchema.safeParse({ action: "stop-bgm", fadeMs: 500 });
- expect(result.success).toBe(true);
- if (result.success) {
- expect(result.data).toEqual({ action: "stop-bgm", fadeMs: 500 });
- }
- });
- it("accepts stop-bgm without fadeMs", () => {
- const result = actionSchema.safeParse({ action: "stop-bgm" });
- expect(result.success).toBe(true);
- if (result.success) {
- expect(result.data).toEqual({ action: "stop-bgm" });
- }
- });
- it("rejects stop-bgm with non-positive fadeMs", () => {
- const result1 = actionSchema.safeParse({ action: "stop-bgm", fadeMs: 0 });
- expect(result1.success).toBe(false);
- const result2 = actionSchema.safeParse({ action: "stop-bgm", fadeMs: -50 });
- expect(result2.success).toBe(false);
- });
- it("rejects stop-bgm with non-integer fadeMs", () => {
- const result = actionSchema.safeParse({ action: "stop-bgm", fadeMs: 2.5 });
- expect(result.success).toBe(false);
- });
- });
|