numerous improvements
This commit is contained in:
@@ -7,6 +7,7 @@ import GlobalState from "../../meshchatx/src/frontend/js/GlobalState";
|
||||
const mockAxios = {
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
patch: vi.fn(),
|
||||
};
|
||||
window.axios = mockAxios;
|
||||
|
||||
@@ -110,4 +111,85 @@ describe("InterfacesPage.vue", () => {
|
||||
expect(wrapper.vm.modifiedInterfaceNames.size).toBe(0);
|
||||
expect(mockAxios.post).toHaveBeenCalledWith("/api/v1/reticulum/reload");
|
||||
});
|
||||
|
||||
it("loads and saves discovery config", async () => {
|
||||
mockAxios.get.mockImplementation((url) => {
|
||||
if (url === "/api/v1/reticulum/interfaces") {
|
||||
return Promise.resolve({ data: { interfaces: [] } });
|
||||
}
|
||||
if (url === "/api/v1/app/info") {
|
||||
return Promise.resolve({ data: { app_info: { is_reticulum_running: true } } });
|
||||
}
|
||||
if (url === "/api/v1/reticulum/discovery") {
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
discovery: {
|
||||
discover_interfaces: "true",
|
||||
interface_discovery_sources: "abc",
|
||||
required_discovery_value: "16",
|
||||
autoconnect_discovered_interfaces: "3",
|
||||
network_identity: "/tmp/netid",
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
return Promise.reject();
|
||||
});
|
||||
|
||||
mockAxios.patch.mockResolvedValue({
|
||||
data: {
|
||||
discovery: {
|
||||
discover_interfaces: false,
|
||||
interface_discovery_sources: null,
|
||||
required_discovery_value: 18,
|
||||
autoconnect_discovered_interfaces: 5,
|
||||
network_identity: "/tmp/new",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const wrapper = mount(InterfacesPage, {
|
||||
global: {
|
||||
mocks: {
|
||||
$route: mockRoute,
|
||||
$router: mockRouter,
|
||||
$t: (msg) => msg,
|
||||
},
|
||||
stubs: [
|
||||
"RouterLink",
|
||||
"MaterialDesignIcon",
|
||||
"IconButton",
|
||||
"Interface",
|
||||
"ImportInterfacesModal",
|
||||
"Toggle",
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
await wrapper.vm.$nextTick();
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
expect(wrapper.vm.discoveryConfig.discover_interfaces).toBe(true);
|
||||
expect(wrapper.vm.discoveryConfig.interface_discovery_sources).toBe("abc");
|
||||
expect(wrapper.vm.discoveryConfig.required_discovery_value).toBe(16);
|
||||
expect(wrapper.vm.discoveryConfig.autoconnect_discovered_interfaces).toBe(3);
|
||||
expect(wrapper.vm.discoveryConfig.network_identity).toBe("/tmp/netid");
|
||||
|
||||
wrapper.vm.discoveryConfig.discover_interfaces = false;
|
||||
wrapper.vm.discoveryConfig.interface_discovery_sources = "";
|
||||
wrapper.vm.discoveryConfig.required_discovery_value = 18;
|
||||
wrapper.vm.discoveryConfig.autoconnect_discovered_interfaces = 5;
|
||||
wrapper.vm.discoveryConfig.network_identity = "/tmp/new";
|
||||
|
||||
await wrapper.vm.saveDiscoveryConfig();
|
||||
|
||||
expect(mockAxios.patch).toHaveBeenCalledWith("/api/v1/reticulum/discovery", {
|
||||
discover_interfaces: false,
|
||||
interface_discovery_sources: null,
|
||||
required_discovery_value: 18,
|
||||
autoconnect_discovered_interfaces: 5,
|
||||
network_identity: "/tmp/new",
|
||||
});
|
||||
expect(wrapper.vm.savingDiscovery).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user