Fix autocomlete alignment
This commit is contained in:
1 parent
f92d08810a
commit
aa282439fc
7 files changed
+326
-6
No files matched your search
@@ -2,6 +2,6 @@ window.__ENV = {
|
||||
GLOBAL_REFRESH: "60000",
|
||||
APP_HOST: "http://localhost:5173",
|
||||
APP_API_BASE_URL: "http://localhost:52345/api/v1",
|
||||
APP_DEPLOYMENT_MODE: "self_hosted",
|
||||
// APP_DEPLOYMENT_MODE: "saas",
|
||||
// APP_DEPLOYMENT_MODE: "self_hosted",
|
||||
APP_DEPLOYMENT_MODE: "saas",
|
||||
};
|
||||
@@ -52,7 +52,7 @@ export const AutoCompleteInput = ({
|
||||
const { key, ...optionProps } = props;
|
||||
return (
|
||||
<ListItem key={key} {...optionProps}>
|
||||
<Stack direction={"row"} gap={theme.spacing(2)}>
|
||||
<Stack direction={"row"} alignItems={"center"} gap={theme.spacing(2)}>
|
||||
{multiple && <Checkbox checked={selected} />}
|
||||
{option.name}
|
||||
</Stack>
|
||||
|
||||
@@ -77,7 +77,7 @@ export const HeaderFilter = ({
|
||||
>
|
||||
{UptimeMonitorTypes.map((type) => (
|
||||
<MenuItem key={type} value={type}>
|
||||
<Stack direction={"row"} gap={theme.spacing(2)}>
|
||||
<Stack direction={"row"} alignItems={"center"} gap={theme.spacing(2)}>
|
||||
<Checkbox checked={selectedTypes.includes(type)} />
|
||||
<Typography textTransform={"capitalize"}>{type}</Typography>
|
||||
</Stack>
|
||||
@@ -92,7 +92,7 @@ export const HeaderFilter = ({
|
||||
>
|
||||
{MonitorStatuses.map((status) => (
|
||||
<MenuItem key={status} value={status}>
|
||||
<Stack direction={"row"} gap={theme.spacing(2)}>
|
||||
<Stack direction={"row"} alignItems={"center"} gap={theme.spacing(2)}>
|
||||
<Checkbox checked={selectedStatuses.includes(status)} />
|
||||
<Typography textTransform={"capitalize"}>{status}</Typography>
|
||||
</Stack>
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
"common": {
|
||||
"appName": "Checkmate",
|
||||
"breadcrumbs": {
|
||||
"billing": "Bililng",
|
||||
"checks": "Checks",
|
||||
"configure": "Configure",
|
||||
"create": "Create",
|
||||
|
||||
@@ -87,7 +87,7 @@ const BillingPage = () => {
|
||||
onClick={handleCancel}
|
||||
loading={isPosting}
|
||||
>
|
||||
{t("buttons.cancelSubscription")}
|
||||
{t("common.buttons.cancelSubscription")}
|
||||
</Button>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
import JobGenerator from "@/services/infrastructure/JobGenerator.js";
|
||||
|
||||
// Minimal monitor/check shapes
|
||||
const monitor = { _id: "m1", type: "http" };
|
||||
const infraMonitor = { _id: "m2", type: "infrastructure" };
|
||||
|
||||
const buildDeps = () => {
|
||||
const networkService = { requestStatus: jest.fn() };
|
||||
const checkService = { buildCheck: jest.fn(), cleanupOrphanedChecks: jest.fn() };
|
||||
const monitorStatsService = { cleanupOrphanedMonitorStats: jest.fn() };
|
||||
const statusService = {
|
||||
updateMonitorStatus: jest.fn(),
|
||||
updateMonitorStats: jest.fn(),
|
||||
evaluateThresholds: jest.fn(),
|
||||
};
|
||||
const notificationService = { handleNotifications: jest.fn().mockResolvedValue(true) };
|
||||
const maintenanceService = { isInMaintenance: jest.fn().mockResolvedValue(false) };
|
||||
const incidentService = {
|
||||
handleStatusChange: jest.fn(),
|
||||
handleThresholdBreach: jest.fn(),
|
||||
cleanupOrphanedIncidents: jest.fn(),
|
||||
};
|
||||
|
||||
return {
|
||||
networkService,
|
||||
checkService,
|
||||
monitorStatsService,
|
||||
statusService,
|
||||
notificationService,
|
||||
incidentService,
|
||||
maintenanceService,
|
||||
};
|
||||
};
|
||||
|
||||
describe("JobGenerator", () => {
|
||||
it("skips job when in maintenance window", async () => {
|
||||
const d = buildDeps();
|
||||
d.maintenanceService.isInMaintenance.mockResolvedValue(true);
|
||||
const gen = new JobGenerator(
|
||||
d.networkService,
|
||||
d.checkService,
|
||||
d.monitorStatsService,
|
||||
d.statusService,
|
||||
d.notificationService,
|
||||
d.incidentService,
|
||||
d.maintenanceService
|
||||
);
|
||||
const job = gen.generateJob();
|
||||
await expect(job(monitor)).resolves.toBeUndefined();
|
||||
expect(d.networkService.requestStatus).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("runs full flow for http monitor, triggers notifications only on status change", async () => {
|
||||
const d = buildDeps();
|
||||
d.networkService.requestStatus.mockResolvedValue({ status: "up" });
|
||||
const fakeCheck = { save: jest.fn().mockResolvedValue(true) };
|
||||
d.checkService.buildCheck.mockResolvedValue(fakeCheck);
|
||||
d.statusService.updateMonitorStatus.mockResolvedValue([{ _id: "m1", type: "http" }, true]);
|
||||
d.statusService.updateMonitorStats.mockResolvedValue({});
|
||||
d.incidentService.handleStatusChange.mockResolvedValue({ id: "incident1" });
|
||||
|
||||
const gen = new JobGenerator(
|
||||
d.networkService,
|
||||
d.checkService,
|
||||
d.monitorStatsService,
|
||||
d.statusService,
|
||||
d.notificationService,
|
||||
d.incidentService,
|
||||
d.maintenanceService
|
||||
);
|
||||
const job = gen.generateJob();
|
||||
await job(monitor);
|
||||
expect(d.networkService.requestStatus).toHaveBeenCalledWith(monitor);
|
||||
expect(d.checkService.buildCheck).toHaveBeenCalled();
|
||||
expect(fakeCheck.save).toHaveBeenCalled();
|
||||
expect(d.statusService.updateMonitorStatus).toHaveBeenCalled();
|
||||
expect(d.incidentService.handleStatusChange).toHaveBeenCalled();
|
||||
expect(d.notificationService.handleNotifications).toHaveBeenCalled();
|
||||
expect(d.statusService.updateMonitorStats).toHaveBeenCalled();
|
||||
// Not an infra monitor, so evaluateThresholds not called
|
||||
expect(d.statusService.evaluateThresholds).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("evaluates thresholds and may notify for infrastructure monitors", async () => {
|
||||
const d = buildDeps();
|
||||
d.networkService.requestStatus.mockResolvedValue({ status: "up" });
|
||||
const fakeCheck = { save: jest.fn().mockResolvedValue(true) };
|
||||
d.checkService.buildCheck.mockResolvedValue(fakeCheck);
|
||||
d.statusService.updateMonitorStatus.mockResolvedValue([{ _id: "m2", type: "infrastructure" }, false]);
|
||||
d.statusService.updateMonitorStats.mockResolvedValue({});
|
||||
d.statusService.evaluateThresholds.mockResolvedValue({ hasBreach: true, notes: [], metrics: {} });
|
||||
d.incidentService.handleThresholdBreach.mockResolvedValue({ id: "incident2" });
|
||||
|
||||
const gen = new JobGenerator(
|
||||
d.networkService,
|
||||
d.checkService,
|
||||
d.monitorStatsService,
|
||||
d.statusService,
|
||||
d.notificationService,
|
||||
d.incidentService,
|
||||
d.maintenanceService
|
||||
);
|
||||
const job = gen.generateJob();
|
||||
await job(infraMonitor);
|
||||
expect(d.statusService.evaluateThresholds).toHaveBeenCalled();
|
||||
expect(d.incidentService.handleThresholdBreach).toHaveBeenCalled();
|
||||
expect(d.notificationService.handleNotifications).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("propagates errors thrown during job execution", async () => {
|
||||
const d = buildDeps();
|
||||
d.networkService.requestStatus.mockRejectedValue(new Error("net"));
|
||||
const gen = new JobGenerator(
|
||||
d.networkService,
|
||||
d.checkService,
|
||||
d.monitorStatsService,
|
||||
d.statusService,
|
||||
d.notificationService,
|
||||
d.incidentService,
|
||||
d.maintenanceService
|
||||
);
|
||||
const job = gen.generateJob();
|
||||
await expect(job(monitor)).rejects.toThrow("net");
|
||||
});
|
||||
|
||||
it("cleanup job runs all cleanup steps and propagates errors", async () => {
|
||||
const d = buildDeps();
|
||||
const gen = new JobGenerator(
|
||||
d.networkService,
|
||||
d.checkService,
|
||||
d.monitorStatsService,
|
||||
d.statusService,
|
||||
d.notificationService,
|
||||
d.incidentService,
|
||||
d.maintenanceService
|
||||
);
|
||||
const cleanup = gen.generateCleanupJob();
|
||||
await cleanup();
|
||||
expect(d.checkService.cleanupOrphanedChecks).toHaveBeenCalled();
|
||||
expect(d.monitorStatsService.cleanupOrphanedMonitorStats).toHaveBeenCalled();
|
||||
expect(d.incidentService.cleanupOrphanedIncidents).toHaveBeenCalled();
|
||||
|
||||
// error propagation
|
||||
d.checkService.cleanupOrphanedChecks.mockRejectedValueOnce(new Error("oops"));
|
||||
await expect(cleanup()).rejects.toThrow("oops");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
import JobQueue from "@/services/infrastructure/JobQueue.js";
|
||||
|
||||
// Mocks
|
||||
jest.mock("super-simple-scheduler", () => {
|
||||
return function Scheduler() {
|
||||
return {
|
||||
start: jest.fn(),
|
||||
stop: jest.fn().mockResolvedValue(true),
|
||||
addTemplate: jest.fn(),
|
||||
addJob: jest.fn().mockResolvedValue(true),
|
||||
pauseJob: jest.fn().mockResolvedValue(true),
|
||||
resumeJob: jest.fn().mockResolvedValue(true),
|
||||
updateJob: jest.fn().mockResolvedValue(true),
|
||||
removeJob: jest.fn(),
|
||||
getJobs: jest.fn().mockResolvedValue([]),
|
||||
flushJobs: jest.fn().mockResolvedValue(true),
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock("@/db/models/index.js", () => ({
|
||||
Monitor: {
|
||||
find: jest.fn().mockResolvedValue([]),
|
||||
exists: jest.fn().mockResolvedValue(true),
|
||||
},
|
||||
}));
|
||||
import Scheduler from "super-simple-scheduler";
|
||||
import { Monitor } from "@/db/models/index.js";
|
||||
|
||||
const mockJobGenerator = () => ({
|
||||
generateJob: jest.fn(() => ({
|
||||
handler: jest.fn(),
|
||||
})),
|
||||
generateCleanupJob: jest.fn(() => ({ handler: jest.fn() })),
|
||||
});
|
||||
|
||||
describe("JobQueue", () => {
|
||||
beforeEach(() => {
|
||||
// Reset singleton between tests
|
||||
// @ts-ignore
|
||||
JobQueue["instance"] = null;
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("creates singleton and initializes templates and cleanup job", async () => {
|
||||
const jq = await JobQueue.create(mockJobGenerator());
|
||||
expect(jq).toBeInstanceOf(JobQueue);
|
||||
expect(Scheduler().addTemplate).toBeDefined();
|
||||
});
|
||||
|
||||
it("add/pause/resume/update/delete/flush/shutdown return true on scheduler success", async () => {
|
||||
const jq = await JobQueue.create(mockJobGenerator());
|
||||
const monitor = { _id: "m1", interval: 1000, status: "up", url: "http://x" };
|
||||
await expect(jq.addJob(monitor)).resolves.toBe(true);
|
||||
await expect(jq.pauseJob(monitor)).resolves.toBe(true);
|
||||
await expect(jq.resumeJob(monitor)).resolves.toBe(true);
|
||||
await expect(jq.updateJob(monitor)).resolves.toBe(true);
|
||||
await expect(jq.deleteJob(monitor)).resolves.toBe(true);
|
||||
await expect(jq.flush()).resolves.toBe(true);
|
||||
await expect(jq.shutdown()).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it("getJobs maps lastRunTook only when run finished and not locked", async () => {
|
||||
const fakeJobs = [
|
||||
{ id: "a", lockedAt: null, lastRunAt: 100, lastFinishedAt: 160 }, // took 60
|
||||
{ id: "b", lockedAt: 1, lastRunAt: 100, lastFinishedAt: 120 }, // locked => null
|
||||
{ id: "c", lockedAt: null, lastRunAt: null, lastFinishedAt: 120 }, // missing => null
|
||||
];
|
||||
const jq = await JobQueue.create(mockJobGenerator());
|
||||
// Patch scheduler's getJobs to return our fake jobs
|
||||
// @ts-ignore
|
||||
jq["scheduler"].getJobs = jest.fn().mockResolvedValue(fakeJobs);
|
||||
const jobs = await jq.getJobs();
|
||||
expect(jobs?.find((j) => j.id === "a")?.lastRunTook).toBe(60);
|
||||
expect(jobs?.find((j) => j.id === "b")?.lastRunTook).toBeNull();
|
||||
expect(jobs?.find((j) => j.id === "c")?.lastRunTook).toBeNull();
|
||||
});
|
||||
|
||||
it("getMetrics aggregates counters and flags failing/active jobs", async () => {
|
||||
const jobs = [
|
||||
{ id: "1", data: { url: "u1", type: "http" }, runCount: 2, failCount: 1, lastFailedAt: 200, lastRunAt: 100, lastFailReason: "e1", lockedAt: null },
|
||||
{ id: "2", data: { url: "u2", type: "ping" }, runCount: 0, failCount: 0, lastFailedAt: null, lastRunAt: null, lastFailReason: null, lockedAt: 1 },
|
||||
];
|
||||
const jq = await JobQueue.create(mockJobGenerator());
|
||||
// @ts-ignore
|
||||
jq["scheduler"].getJobs = jest.fn().mockResolvedValue(jobs);
|
||||
const metrics = await jq.getMetrics();
|
||||
expect(metrics).toMatchObject({ jobs: 2, totalRuns: 2, totalFailures: 1, activeJobs: 1, failingJobs: 1 });
|
||||
expect(metrics?.jobsWithFailures[0]).toMatchObject({ monitorId: "1", failReason: "e1" });
|
||||
});
|
||||
|
||||
it("init schedules addJob for existing monitors and skips missing ones", async () => {
|
||||
jest.useFakeTimers();
|
||||
const originalRandom = Math.random;
|
||||
// Force deterministic offsets of 1000ms
|
||||
Math.random = jest.fn().mockReturnValue(0);
|
||||
const monitors = [
|
||||
{ _id: "a", interval: 1000, status: "up" },
|
||||
{ _id: "b", interval: 1000, status: "up" },
|
||||
];
|
||||
Monitor.find.mockResolvedValueOnce(monitors);
|
||||
// exists: only 'a' exists
|
||||
Monitor.exists.mockImplementation(async ({ _id }) => _id === "a");
|
||||
const gen = mockJobGenerator();
|
||||
const jq = await JobQueue.create(gen);
|
||||
const addSpy = jest.spyOn(jq, "addJob").mockResolvedValue(true);
|
||||
// Advance timers to trigger setTimeouts (1000ms)
|
||||
jest.advanceTimersByTime(1100);
|
||||
// Allow async callback to resolve
|
||||
// @ts-ignore
|
||||
if (jest.runOnlyPendingTimersAsync) {
|
||||
// modern timers
|
||||
// @ts-ignore
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
}
|
||||
await Promise.resolve();
|
||||
expect(addSpy).toHaveBeenCalledTimes(1);
|
||||
expect(addSpy).toHaveBeenCalledWith(expect.objectContaining({ _id: "a" }));
|
||||
// restore
|
||||
Math.random = originalRandom;
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it("returns false/null on scheduler errors across methods", async () => {
|
||||
const jq = await JobQueue.create(mockJobGenerator());
|
||||
// addJob failure
|
||||
// @ts-ignore
|
||||
jq["scheduler"].addJob = jest.fn(() => { throw new Error("boom"); });
|
||||
await expect(jq.addJob({ _id: "m1", interval: 1, status: "up" })).resolves.toBe(false);
|
||||
// pause/resume/update failures
|
||||
// @ts-ignore
|
||||
jq["scheduler"].pauseJob = jest.fn(() => { throw new Error("boom"); });
|
||||
await expect(jq.pauseJob({ _id: "m1" })).resolves.toBe(false);
|
||||
// @ts-ignore
|
||||
jq["scheduler"].resumeJob = jest.fn(() => { throw new Error("boom"); });
|
||||
await expect(jq.resumeJob({ _id: "m1" })).resolves.toBe(false);
|
||||
// @ts-ignore
|
||||
jq["scheduler"].updateJob = jest.fn(() => { throw new Error("boom"); });
|
||||
await expect(jq.updateJob({ _id: "m1", interval: 1 })).resolves.toBe(false);
|
||||
// delete failure
|
||||
// @ts-ignore
|
||||
jq["scheduler"].removeJob = jest.fn(() => { throw new Error("boom"); });
|
||||
await expect(jq.deleteJob({ _id: "m1" })).resolves.toBe(false);
|
||||
// getJobs failure
|
||||
// @ts-ignore
|
||||
jq["scheduler"].getJobs = jest.fn(() => { throw new Error("boom"); });
|
||||
await expect(jq.getJobs()).resolves.toBeNull();
|
||||
// getMetrics failure
|
||||
// @ts-ignore
|
||||
jq["scheduler"].getJobs = jest.fn(() => { throw new Error("boom"); });
|
||||
await expect(jq.getMetrics()).resolves.toBeNull();
|
||||
// flush/shutdown failure
|
||||
// @ts-ignore
|
||||
jq["scheduler"].flushJobs = jest.fn(() => { throw new Error("boom"); });
|
||||
await expect(jq.flush()).resolves.toBe(false);
|
||||
// @ts-ignore
|
||||
jq["scheduler"].stop = jest.fn(() => { throw new Error("boom"); });
|
||||
await expect(jq.shutdown()).resolves.toBe(false);
|
||||
});
|
||||
|
||||
it("init returns false when scheduler throws during setup", async () => {
|
||||
const jq = new JobQueue();
|
||||
// Force addTemplate to throw
|
||||
// @ts-ignore
|
||||
jq["scheduler"].addTemplate = jest.fn(() => { throw new Error("setup fail"); });
|
||||
// attach generator to avoid undefined access
|
||||
// @ts-ignore
|
||||
jq["jobGenerator"] = mockJobGenerator();
|
||||
await expect(jq.init()).resolves.toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user