Newer
Older
smart-home-server / webclient-vue / src / components / feedback / __tests__ / AppErrorState.spec.js
@Eugene Sukhodolskiy Eugene Sukhodolskiy 23 hours ago 1 KB Add script detail pages with scope grouping
import { describe, it, expect, vi } from "vitest";
import { mount } from "@vue/test-utils";
import AppErrorState from "../AppErrorState.vue";

describe("AppErrorState", () => {
  it("renders title and message", () => {
    const wrapper = mount(AppErrorState, {
      props: {
        title: "Load failed",
        message: "Server error",
      },
    });

    expect(wrapper.text()).toContain("Load failed");
    expect(wrapper.text()).toContain("Server error");
  });

  it("renders retry button when retry prop provided", () => {
    const retry = vi.fn();
    const wrapper = mount(AppErrorState, {
      props: {
        title: "Error",
        retry,
      },
    });

    const btn = wrapper.find("button");
    expect(btn.exists()).toBe(true);
    expect(btn.text()).toContain("Retry");
  });

  it("does not render retry button when retry is null", () => {
    const wrapper = mount(AppErrorState, {
      props: {
        title: "Error",
        retry: null,
      },
    });

    expect(wrapper.find("button").exists()).toBe(false);
  });

  it("calls retry callback on button click", () => {
    const retry = vi.fn();
    const wrapper = mount(AppErrorState, {
      props: {
        title: "Error",
        retry,
      },
    });

    wrapper.find("button").trigger("click");

    expect(retry).toHaveBeenCalled();
  });
});