diff --git a/src/components/LogRulesPanel.test.ts b/src/components/LogRulesPanel.test.ts new file mode 100644 index 0000000..b073b57 --- /dev/null +++ b/src/components/LogRulesPanel.test.ts @@ -0,0 +1,144 @@ +import { describe, it, expect, vi, beforeEach } from "vitest"; +import { mount, flushPromises } from "@vue/test-utils"; +import { createTestingPinia } from "@pinia/testing"; +import LogRulesPanel from "./LogRulesPanel.vue"; + +vi.mock("@/services/observability", () => ({ + observabilityApi: { + logRules: vi.fn().mockResolvedValue({ data: [] }), + saveLogRules: vi.fn().mockImplementation((rules) => Promise.resolve({ data: rules })), + }, +})); + +vi.mock("@/services/api", () => ({ + notificationsApi: { + getTargets: vi.fn().mockResolvedValue({ data: { targets: [{ id: "t1", name: "Ops chat" }] } }), + }, +})); + +describe("LogRulesPanel", () => { + beforeEach(() => vi.clearAllMocks()); + + const mountPanel = () => + mount(LogRulesPanel, { + props: { deployments: ["shop", "blog"] }, + global: { + plugins: [createTestingPinia({ createSpy: vi.fn })], + stubs: { BaseModal: { template: "
+ Nothing is watched yet. A log rule turns what a deployment writes into an incident, once the same fault has + happened often enough to be worth your attention. +
+ ++ {{ rule.name }} + triage +
+{{ describe(rule) }}
+No notification targets yet. Add one in Settings to send anywhere.
++ One explanation per distinct fault, reused while the same fault keeps happening, and bounded by the agent's + daily cap. Needs the assistant configured and log triage enabled in the Observability settings. +
+ + + +{{ formError }}
+