Newer
Older
smart-home-server / webclient-vue / src / test / integration / device-discovery.spec.js
@Eugene Sukhodolskiy Eugene Sukhodolskiy 1 day ago 1 KB Add script detail pages with scope grouping
import { describe, it, expect, beforeEach } from "vitest";
import { mount } from "@vue/test-utils";
import { setActivePinia, createPinia } from "pinia";
import { useScanningStore } from "../../stores/scanning.js";
import { useDevicesStore } from "../../stores/devices.js";
import DevicesScanningPage from "../../features/devices/pages/DevicesScanningPage.vue";

describe("Device discovery integration", () => {
  beforeEach(() => {
    setActivePinia(createPinia());
  });

  it("discovers devices via scan", async () => {
    const wrapper = mount(DevicesScanningPage);
    const store = useScanningStore();

    await store.scan();

    expect(store.devices.length).toBeGreaterThan(0);
    expect(store.devices[0].status).toBe("setup");
  });

  it("sets up a new device and it appears in device list", async () => {
    const scanningStore = useScanningStore();
    const devicesStore = useDevicesStore();

    await scanningStore.scan();
    const foundDevice = scanningStore.devices[0];

    const result = await scanningStore.setupDevice({
      device_ip: foundDevice.ip_address,
      alias: "new_relay",
      name: "New Relay",
      description: "",
    });

    expect(result.ok).toBe(true);
  });
});