import { describe, it, expect, beforeEach } from "vitest";
import { get } from "svelte/store";
import { messageMode, getCurrentMode } from "./messageMode";

describe("messageMode store", () => {
  beforeEach(() => {
    messageMode.reset();
  });

  describe("initial state", () => {
    it("defaults to chat mode", () => {
      expect(get(messageMode)).toBe("chat");
    });
  });

  describe("set", () => {
    it("sets the mode to the given value", () => {
      messageMode.set("plan");
      expect(get(messageMode)).toBe("plan");
    });

    it("can set any arbitrary mode string", () => {
      messageMode.set("auto");
      expect(get(messageMode)).toBe("auto");
    });
  });

  describe("reset", () => {
    it("resets mode back to chat", () => {
      messageMode.set("plan");
      messageMode.reset();
      expect(get(messageMode)).toBe("chat");
    });
  });
});

describe("getCurrentMode", () => {
  beforeEach(() => {
    messageMode.reset();
  });

  it("returns chat when in default state", () => {
    expect(getCurrentMode()).toBe("chat");
  });

  it("returns the currently set mode", () => {
    messageMode.set("plan");
    expect(getCurrentMode()).toBe("plan");
  });

  it("returns chat after a reset", () => {
    messageMode.set("auto");
    messageMode.reset();
    expect(getCurrentMode()).toBe("chat");
  });
});
