uptime-kuma/test/component/Status.spec.js

94 lines
3.3 KiB
JavaScript
Raw Normal View History

2024-11-20 13:48:13 +00:00
import { describe, it, expect } from "vitest";
import { mount } from "@vue/test-utils";
import Status from "../../src/components/Status.vue";
import { UP, DOWN, PENDING, MAINTENANCE } from "../../src/util";
describe("Status.vue", () => {
const mountStatus = (status) => {
return mount(Status, {
props: {
status
2024-11-20 13:58:15 +00:00
},
global: {
mocks: {
$t: (key) => key // Mock translation function
}
2024-11-20 13:48:13 +00:00
}
});
};
it("renders UP status correctly", () => {
2024-11-20 14:12:46 +00:00
const wrapper = mountStatus(UP); // UP status
2024-11-20 13:58:15 +00:00
expect(wrapper.find(".badge").classes()).toContain("bg-primary");
expect(wrapper.text()).toBe("Up");
2024-11-20 13:48:13 +00:00
});
it("renders DOWN status correctly", () => {
2024-11-20 14:12:46 +00:00
const wrapper = mountStatus(DOWN); // DOWN status
2024-11-20 13:48:13 +00:00
expect(wrapper.find(".badge").classes()).toContain("bg-danger");
2024-11-20 13:58:15 +00:00
expect(wrapper.text()).toBe("Down");
2024-11-20 13:48:13 +00:00
});
it("renders PENDING status correctly", () => {
2024-11-20 14:12:46 +00:00
const wrapper = mountStatus(PENDING); // PENDING status
2024-11-20 13:48:13 +00:00
expect(wrapper.find(".badge").classes()).toContain("bg-warning");
2024-11-20 13:58:15 +00:00
expect(wrapper.text()).toBe("Pending");
2024-11-20 13:48:13 +00:00
});
it("renders MAINTENANCE status correctly", () => {
2024-11-20 14:12:46 +00:00
const wrapper = mountStatus(MAINTENANCE); // MAINTENANCE status
2024-11-20 13:58:15 +00:00
expect(wrapper.find(".badge").classes()).toContain("bg-maintenance");
expect(wrapper.text()).toBe("statusMaintenance");
2024-11-20 13:48:13 +00:00
});
it("handles unknown status gracefully", () => {
2024-11-20 13:58:15 +00:00
const wrapper = mountStatus(999); // Unknown status
2024-11-20 13:48:13 +00:00
expect(wrapper.find(".badge").classes()).toContain("bg-secondary");
2024-11-20 13:58:15 +00:00
expect(wrapper.text()).toBe("Unknown");
2024-11-20 13:48:13 +00:00
});
it("updates when status prop changes", async () => {
2024-11-20 14:12:46 +00:00
const wrapper = mountStatus(UP); // UP status
2024-11-20 13:58:15 +00:00
expect(wrapper.find(".badge").classes()).toContain("bg-primary");
2024-11-20 13:48:13 +00:00
2024-11-20 14:12:46 +00:00
await wrapper.setProps({ status: DOWN }); // Change to DOWN status
2024-11-20 13:48:13 +00:00
expect(wrapper.find(".badge").classes()).toContain("bg-danger");
});
2024-11-20 14:12:46 +00:00
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");
});
2024-11-20 13:48:13 +00:00
});