Refactor application structure and simplify implementation
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type {
|
||||
ApplyConfigurationResult,
|
||||
PingServerResponse,
|
||||
} from "../api/tauriCommands";
|
||||
import type { ComponentStatus } from "../domain/types";
|
||||
import {
|
||||
noticeFromConfigurationApply,
|
||||
pingSummary,
|
||||
routeChainSegments,
|
||||
} from "./viewModel";
|
||||
|
||||
const runningProxiFyre: ComponentStatus = {
|
||||
id: "proxyfier",
|
||||
name: "ProxiFyre",
|
||||
state: "running",
|
||||
installed: true,
|
||||
running: true,
|
||||
path: "C:\\Tools\\ProxiFyre\\ProxiFyre.exe",
|
||||
problems: [],
|
||||
actions: [],
|
||||
};
|
||||
|
||||
describe("App view helpers", () => {
|
||||
it("describes the external SOCKS5 route without Local sing-box", () => {
|
||||
const segments = routeChainSegments({
|
||||
routeMode: "external",
|
||||
proxyInput: "proxy.example.test:1080",
|
||||
proxyfier: runningProxiFyre,
|
||||
singbox: undefined,
|
||||
singBoxStatus: null,
|
||||
selectedServer: null,
|
||||
appCount: 2,
|
||||
isDetectingComponents: false,
|
||||
});
|
||||
|
||||
expect(segments.map((segment) => segment.id)).toEqual([
|
||||
"apps",
|
||||
"proxifyre",
|
||||
"endpoint",
|
||||
"exit",
|
||||
]);
|
||||
expect(segments[2]).toMatchObject({
|
||||
value: "proxy.example.test:1080",
|
||||
tone: "ok",
|
||||
});
|
||||
expect(segments[3].details).toContain(
|
||||
"Local sing-box не нужен для этого маршрута.",
|
||||
);
|
||||
});
|
||||
|
||||
it("summarizes the fastest successful ping", () => {
|
||||
const results = [
|
||||
{ tag: "slow", ok: true, latency: 90 },
|
||||
{ tag: "failed", ok: false },
|
||||
{ tag: "fast", ok: true, latency: 20 },
|
||||
] as PingServerResponse[];
|
||||
|
||||
expect(pingSummary(results)).toBe("Ответили 2/3; быстрее fast: 20 ms.");
|
||||
});
|
||||
|
||||
it("distinguishes rolled-back and partial apply failures", () => {
|
||||
const base: ApplyConfigurationResult = {
|
||||
success: false,
|
||||
changed: false,
|
||||
partialState: false,
|
||||
message: "Helper failed; previous files restored.",
|
||||
generatedConfigPath:
|
||||
"C:\\ProgramData\\ProxyWarden\\generated\\proxifyre-app-config.json",
|
||||
restartRequired: [],
|
||||
phases: [],
|
||||
};
|
||||
|
||||
expect(noticeFromConfigurationApply(base).title).toBe("Изменения отменены");
|
||||
expect(
|
||||
noticeFromConfigurationApply({ ...base, partialState: true }).title,
|
||||
).toBe("Проверь состояние файлов");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user