import { mount } from "@vue/test-utils";
import flushPromises from "flush-promises";
import { describe, expect, it, vi } from "vitest";

import Monitor from "./Monitor.vue";

vi.mock("app");
vi.mock("onload/loadConfig", () => ({
    getAppRoot: vi.fn(() => "/"),
}));
vi.mock("../services", () => ({
    Services: class Services {
        async getInstalledRepositories() {
            return [
                {
                    name: "name_0",
                    owner: "owner_0",
                    status: "status_0_0",
                    description: "description_0_0",
                },
                {
                    name: "name_1",
                    owner: "owner_1",
                    status: "status_1",
                    description: "description_1",
                },
            ];
        }
    },
}));

describe("Monitor", () => {
    it("test monitor", async () => {
        const wrapper = mount(Monitor);

        await flushPromises();

        const headers = wrapper.findAll("th");
        expect(headers.length).toBe(0);

        const cells = wrapper.findAll("td");
        expect(cells.length).toBe(6);
        expect(cells.at(0).text()).toContain("name_0 (owner_0)");
        expect(cells.at(1).text()).toContain("status_0_0");
        expect(cells.at(3).text()).toContain("name_1 (owner_1)");
        expect(cells.at(4).text()).toContain("status_1");
    });
});
