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();
});
});