mirror of
https://git.quad4.io/RNS-Things/MeshChatX.git
synced 2026-03-31 10:25:42 +00:00
- Introduced new test suite for `parse_lxmf_display_name`, `parse_nomadnetwork_node_display_name`, and related functions using Hypothesis for property-based testing. - Added various strategies to generate diverse input data, including edge cases for invalid and long names. - Implemented tests to ensure robustness against invalid base64 inputs and to verify expected behavior with valid and corrupted data. - Created smoke tests for frontend components including BotsPage, ForwarderPage, and others to ensure proper rendering and functionality.
99 lines
3.3 KiB
JavaScript
99 lines
3.3 KiB
JavaScript
import { mount } from "@vue/test-utils";
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
import RNPathTracePage from "@/components/tools/RNPathTracePage.vue";
|
|
|
|
describe("RNPathTracePage.vue", () => {
|
|
let axiosMock;
|
|
|
|
beforeEach(() => {
|
|
axiosMock = {
|
|
get: vi.fn(),
|
|
};
|
|
window.axios = axiosMock;
|
|
});
|
|
|
|
afterEach(() => {
|
|
delete window.axios;
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
const mountRNPathTracePage = (query = {}) => {
|
|
return mount(RNPathTracePage, {
|
|
global: {
|
|
mocks: {
|
|
$t: (key) => key,
|
|
$route: { query },
|
|
$router: { push: vi.fn() },
|
|
},
|
|
stubs: {
|
|
MaterialDesignIcon: {
|
|
template: '<div class="mdi-stub" :data-icon-name="iconName"></div>',
|
|
props: ["iconName"],
|
|
},
|
|
},
|
|
},
|
|
});
|
|
};
|
|
|
|
it("renders the path trace page", () => {
|
|
const wrapper = mountRNPathTracePage();
|
|
expect(wrapper.text()).toContain("tools.rnpath_trace.title");
|
|
});
|
|
|
|
it("validates destination hash", async () => {
|
|
const wrapper = mountRNPathTracePage();
|
|
const input = wrapper.find("input");
|
|
const button = wrapper.find("button[title='Trace Path']");
|
|
|
|
await input.setValue("invalid");
|
|
expect(button.element.disabled).toBe(true);
|
|
|
|
await input.setValue("a".repeat(32));
|
|
expect(button.element.disabled).toBe(false);
|
|
});
|
|
|
|
it("calls trace API and displays results", async () => {
|
|
axiosMock.get.mockResolvedValue({
|
|
data: {
|
|
hops: 2,
|
|
interface: "UDP",
|
|
next_hop: "next_hop_hash",
|
|
path: [
|
|
{ type: "local", name: "Local", hash: "local_hash" },
|
|
{ type: "node", name: "Intermediate", hash: "node_hash", interface: "UDP" },
|
|
{ type: "destination", name: "Destination", hash: "dest_hash" },
|
|
],
|
|
},
|
|
});
|
|
|
|
const wrapper = mountRNPathTracePage();
|
|
await wrapper.find("input").setValue("a".repeat(32));
|
|
await wrapper.find("button[title='Trace Path']").trigger("click");
|
|
|
|
await vi.waitFor(() => expect(wrapper.vm.isLoading).toBe(false));
|
|
|
|
expect(axiosMock.get).toHaveBeenCalledWith(`/api/v1/rnpath/trace/${"a".repeat(32)}`);
|
|
expect(wrapper.text()).toContain("2");
|
|
expect(wrapper.text()).toContain("UDP");
|
|
expect(wrapper.text()).toContain("Local");
|
|
expect(wrapper.text()).toContain("Intermediate");
|
|
expect(wrapper.text()).toContain("Destination");
|
|
});
|
|
|
|
it("handles trace error", async () => {
|
|
axiosMock.get.mockRejectedValue({
|
|
response: { data: { error: "Trace failed" } },
|
|
});
|
|
|
|
const wrapper = mountRNPathTracePage();
|
|
await wrapper.find("input").setValue("a".repeat(32));
|
|
await wrapper.find("button[title='Trace Path']").trigger("click");
|
|
|
|
await vi.waitFor(() => expect(wrapper.vm.error).toBe("Trace failed"));
|
|
await wrapper.vm.$nextTick();
|
|
|
|
expect(wrapper.text()).toContain("Trace Error");
|
|
expect(wrapper.text()).toContain("Trace failed");
|
|
});
|
|
});
|