Files
MeshChatX/tests/frontend/AppPropagationSync.test.js
Sudo-Ivan 39b8d5fef8
Some checks failed
Build Test / Build and Test (push) Failing after 6m1s
CI / lint (push) Failing after 1m27s
CI / build-frontend (push) Failing after 1m30s
CI / test-backend (push) Successful in 1m17s
CI / test-lang (push) Failing after 1m15s
Build and Publish Docker Image / build (push) Failing after 4m28s
Build and Publish Docker Image / build-dev (push) Failing after 5m38s
Security Scans / scan (push) Successful in 2m12s
Tests / test (push) Failing after 1m17s
Cleanup
2026-02-17 17:59:46 -06:00

90 lines
3.0 KiB
JavaScript

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import App from "../../meshchatx/src/frontend/components/App.vue";
import ToastUtils from "../../meshchatx/src/frontend/js/ToastUtils";
vi.mock("../../meshchatx/src/frontend/js/ToastUtils", () => ({
default: {
success: vi.fn(),
error: vi.fn(),
},
}));
describe("App propagation sync metrics", () => {
const axiosMock = {
get: vi.fn(),
};
beforeEach(() => {
vi.clearAllMocks();
vi.useFakeTimers();
globalThis.axios = axiosMock;
});
afterEach(() => {
vi.useRealTimers();
});
it("shows detailed sync toast with stored, confirmations and hidden counts", async () => {
axiosMock.get.mockImplementation((url) => {
if (url === "/api/v1/lxmf/propagation-node/sync") {
return Promise.resolve({ data: { message: "Sync is starting" } });
}
if (url === "/api/v1/lxmf/propagation-node/status") {
return Promise.resolve({
data: {
propagation_node_status: {
state: "complete",
messages_received: 8,
messages_stored: 3,
delivery_confirmations: 2,
messages_hidden: 3,
},
},
});
}
return Promise.resolve({ data: {} });
});
const ctx = {
propagationNodeStatus: null,
get isSyncingPropagationNode() {
return [
"path_requested",
"link_establishing",
"link_established",
"request_sent",
"receiving",
"response_received",
].includes(this.propagationNodeStatus?.state);
},
async updatePropagationNodeStatus() {
return App.methods.updatePropagationNodeStatus.call(this);
},
async stopSyncingPropagationNode() {},
$t(key, params = {}) {
if (key === "app.sync_complete") {
return `Sync complete. ${params.count} messages received.`;
}
if (key === "app.sync_error") {
return `Sync error: ${params.status}`;
}
if (key === "app.sync_error_generic") {
return "Sync failed";
}
if (key === "app.stop_sync_confirm") {
return "Stop syncing?";
}
return key;
},
};
await App.methods.syncPropagationNode.call(ctx);
vi.advanceTimersByTime(600);
expect(ToastUtils.success).toHaveBeenCalledWith(
"Sync complete. 8 messages received. (3 stored, 2 confirmations, 3 hidden)"
);
expect(ToastUtils.error).not.toHaveBeenCalled();
});
});