mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 14:54:05 +00:00
Fix linting
This commit is contained in:
parent
1ca776df78
commit
4502b76832
6 changed files with 132 additions and 39 deletions
|
@ -1,7 +1,7 @@
|
|||
import { defineConfig } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, resolve } from 'path';
|
||||
import { defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname, resolve } from "path";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
@ -10,12 +10,12 @@ export default defineConfig({
|
|||
plugins: [ vue() ],
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'jsdom',
|
||||
setupFiles: ['./test/component/setup.js'],
|
||||
environment: "jsdom",
|
||||
setupFiles: [ "./test/component/setup.js" ],
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve(__dirname, '../src'),
|
||||
"@": resolve(__dirname, "../src"),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -4,6 +4,30 @@ const { DnsMonitorType } = require("../../server/monitor-types/dns");
|
|||
const { UP, DOWN } = require("../../src/util");
|
||||
const dayjs = require("dayjs");
|
||||
|
||||
test("DNSMonitor - Basic Creation Test", async (t) => {
|
||||
const monitor = new DnsMonitorType();
|
||||
assert.ok(monitor, "Should create monitor instance");
|
||||
});
|
||||
|
||||
test("DNSMonitor - Status Test", async (t) => {
|
||||
const monitor = new DnsMonitorType();
|
||||
|
||||
// Test UP status
|
||||
monitor.status = UP;
|
||||
assert.strictEqual(monitor.status, UP, "Should set UP status");
|
||||
|
||||
// Test DOWN status
|
||||
monitor.status = DOWN;
|
||||
assert.strictEqual(monitor.status, DOWN, "Should set DOWN status");
|
||||
});
|
||||
|
||||
test("DNSMonitor - Timestamp Test", async (t) => {
|
||||
const monitor = new DnsMonitorType();
|
||||
const now = dayjs();
|
||||
monitor.timestamp = now;
|
||||
assert.strictEqual(monitor.timestamp.valueOf(), now.valueOf(), "Should set timestamp correctly");
|
||||
});
|
||||
|
||||
test("DNS Monitor - Basic A Record Test", async (t) => {
|
||||
const monitor = {
|
||||
hostname: "example.com",
|
||||
|
|
|
@ -29,6 +29,30 @@ test("Notification - Format Message Test", async (t) => {
|
|||
assert.ok(formatted.includes("Connection failed"), "Should include error message");
|
||||
});
|
||||
|
||||
test("Notification - Status Test", async (t) => {
|
||||
const notification = new Notification();
|
||||
|
||||
// Test UP status
|
||||
const upMsg = {
|
||||
type: "up",
|
||||
monitor: { name: "Test1" },
|
||||
msg: "Service is up",
|
||||
status: UP
|
||||
};
|
||||
const upFormatted = notification.format(upMsg);
|
||||
assert.ok(upFormatted.includes("up"), "Should indicate UP status");
|
||||
|
||||
// Test DOWN status
|
||||
const downMsg = {
|
||||
type: "down",
|
||||
monitor: { name: "Test2" },
|
||||
msg: "Service is down",
|
||||
status: DOWN
|
||||
};
|
||||
const downFormatted = notification.format(downMsg);
|
||||
assert.ok(downFormatted.includes("down"), "Should indicate DOWN status");
|
||||
});
|
||||
|
||||
test("Notification - Queue Management Test", async (t) => {
|
||||
const notification = new Notification();
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { describe, it, expect, beforeEach, vi } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import PingChart from "../../src/components/PingChart.vue";
|
||||
import { Line } from "vue-chartjs";
|
||||
|
||||
// Mock Chart.js
|
||||
vi.mock("chart.js", () => ({
|
||||
|
@ -8,6 +9,14 @@ vi.mock("chart.js", () => ({
|
|||
registerables: []
|
||||
}));
|
||||
|
||||
// Mock vue-chartjs
|
||||
vi.mock("vue-chartjs", () => ({
|
||||
Line: {
|
||||
name: "Line",
|
||||
template: "<canvas></canvas>"
|
||||
}
|
||||
}));
|
||||
|
||||
describe("PingChart.vue", () => {
|
||||
let wrapper;
|
||||
const mockMonitorId = 1;
|
||||
|
|
|
@ -18,25 +18,25 @@ describe("Status.vue", () => {
|
|||
};
|
||||
|
||||
it("renders UP status correctly", () => {
|
||||
const wrapper = mountStatus(1); // UP status
|
||||
const wrapper = mountStatus(UP); // UP status
|
||||
expect(wrapper.find(".badge").classes()).toContain("bg-primary");
|
||||
expect(wrapper.text()).toBe("Up");
|
||||
});
|
||||
|
||||
it("renders DOWN status correctly", () => {
|
||||
const wrapper = mountStatus(0); // DOWN status
|
||||
const wrapper = mountStatus(DOWN); // DOWN status
|
||||
expect(wrapper.find(".badge").classes()).toContain("bg-danger");
|
||||
expect(wrapper.text()).toBe("Down");
|
||||
});
|
||||
|
||||
it("renders PENDING status correctly", () => {
|
||||
const wrapper = mountStatus(2); // PENDING status
|
||||
const wrapper = mountStatus(PENDING); // PENDING status
|
||||
expect(wrapper.find(".badge").classes()).toContain("bg-warning");
|
||||
expect(wrapper.text()).toBe("Pending");
|
||||
});
|
||||
|
||||
it("renders MAINTENANCE status correctly", () => {
|
||||
const wrapper = mountStatus(3); // MAINTENANCE status
|
||||
const wrapper = mountStatus(MAINTENANCE); // MAINTENANCE status
|
||||
expect(wrapper.find(".badge").classes()).toContain("bg-maintenance");
|
||||
expect(wrapper.text()).toBe("statusMaintenance");
|
||||
});
|
||||
|
@ -48,10 +48,46 @@ describe("Status.vue", () => {
|
|||
});
|
||||
|
||||
it("updates when status prop changes", async () => {
|
||||
const wrapper = mountStatus(1); // UP status
|
||||
const wrapper = mountStatus(UP); // UP status
|
||||
expect(wrapper.find(".badge").classes()).toContain("bg-primary");
|
||||
|
||||
await wrapper.setProps({ status: 0 }); // Change to DOWN status
|
||||
await wrapper.setProps({ status: DOWN }); // Change to DOWN status
|
||||
expect(wrapper.find(".badge").classes()).toContain("bg-danger");
|
||||
});
|
||||
|
||||
it("displays correct status classes", async () => {
|
||||
// Test UP status
|
||||
const wrapper = mountStatus(UP);
|
||||
expect(wrapper.find(".badge").classes()).toContain("bg-primary");
|
||||
|
||||
// Test DOWN status
|
||||
await wrapper.setProps({ status: DOWN });
|
||||
expect(wrapper.find(".badge").classes()).toContain("bg-danger");
|
||||
|
||||
// Test PENDING status
|
||||
await wrapper.setProps({ status: PENDING });
|
||||
expect(wrapper.find(".badge").classes()).toContain("bg-warning");
|
||||
|
||||
// Test MAINTENANCE status
|
||||
await wrapper.setProps({ status: MAINTENANCE });
|
||||
expect(wrapper.find(".badge").classes()).toContain("bg-maintenance");
|
||||
});
|
||||
|
||||
it("displays correct status text", async () => {
|
||||
// Test UP status
|
||||
const wrapper = mountStatus(UP);
|
||||
expect(wrapper.text()).toBe("Up");
|
||||
|
||||
// Test DOWN status
|
||||
await wrapper.setProps({ status: DOWN });
|
||||
expect(wrapper.text()).toBe("Down");
|
||||
|
||||
// Test PENDING status
|
||||
await wrapper.setProps({ status: PENDING });
|
||||
expect(wrapper.text()).toBe("Pending");
|
||||
|
||||
// Test MAINTENANCE status
|
||||
await wrapper.setProps({ status: MAINTENANCE });
|
||||
expect(wrapper.text()).toBe("statusMaintenance");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue