Newer
Older
smart-home-server / webclient-vue / src / features / scripts / pages / __tests__ / ScriptsActionsPage.spec.js
import { describe, it, expect, beforeEach } from "vitest";
import { mount } from "@vue/test-utils";
import { setActivePinia, createPinia } from "pinia";
import { useScriptsStore } from "../../../../stores/scripts.js";
import ScriptsActionsPage from "../ScriptsActionsPage.vue";

describe("ScriptsActionsPage", () => {
  beforeEach(() => {
    setActivePinia(createPinia());
  });

  it("renders loading state", () => {
    const store = useScriptsStore();
    store.isLoadingActions = true;
    const wrapper = mount(ScriptsActionsPage);
    expect(wrapper.text()).toContain("Loading actions");
  });

  it("renders action cards after loading", async () => {
    const wrapper = mount(ScriptsActionsPage);
    await new Promise((resolve) => setTimeout(resolve, 50));
    expect(wrapper.text()).toContain("Kitchen Light");
    expect(wrapper.text()).toContain("Hall Light");
    expect(wrapper.text()).toContain("enabled");
  });

  it("renders area badge for assigned script", async () => {
    const wrapper = mount(ScriptsActionsPage);
    await new Promise((resolve) => setTimeout(resolve, 50));
    expect(wrapper.text()).toContain("Kitchen"); // area badge for kitchen_light
  });
});