feat: add reusable proxy configuration

This commit is contained in:
QiuSW
2026-07-25 17:04:26 +08:00
parent f13e06500c
commit 3a3c92c875
13 changed files with 772 additions and 48 deletions
+38
View File
@@ -3,6 +3,7 @@ package ui
import (
"context"
"path/filepath"
"strings"
"sync/atomic"
"testing"
"time"
@@ -443,3 +444,40 @@ func TestShellRequestsDiscardConfirmationForDirtyEdit(t *testing.T) {
t.Fatalf("dirty edit cancellation state = discard %v editing %q", shell.pendingEditDiscard, shell.editingID)
}
}
func TestShellCreatesAndEditsInstanceProxySelection(t *testing.T) {
shell := NewShell(material.NewTheme())
shell.SetProxies([]ProxyOption{{ID: "proxy-sg", Name: "新加坡", Server: "http://127.0.0.1:8080"}})
shell.instanceName.SetText("新实例")
shell.instanceDir.SetText(t.TempDir())
shell.createProxyID = "proxy-sg"
shell.createInstanceFromForm()
created := shell.rows[len(shell.rows)-1]
if created.ProxyID != "proxy-sg" {
t.Fatalf("created proxy id = %q", created.ProxyID)
}
shell.beginEdit(created.ID)
shell.editProxyID = ""
shell.saveEdit()
row, ok := shell.instanceRow(created.ID)
if !ok || row.ProxyID != "" {
t.Fatalf("edited proxy row = %#v", row)
}
}
func TestShellPreventsDeletingReferencedProxy(t *testing.T) {
shell := NewShell(material.NewTheme())
shell.SetProxies([]ProxyOption{{ID: "proxy-sg", Name: "新加坡", Server: "http://127.0.0.1:8080"}})
shell.rows[0].ProxyID = "proxy-sg"
changes := 0
shell.OnProxiesChanged(func([]ProxyOption) { changes++ })
shell.deleteProxy("proxy-sg")
if len(shell.proxies) != 1 || changes != 0 || !strings.Contains(shell.proxyFeedback, "不能删除") {
t.Fatalf("referenced delete state = proxies %#v, changes %d, feedback %q", shell.proxies, changes, shell.proxyFeedback)
}
shell.rows[0].ProxyID = ""
shell.deleteProxy("proxy-sg")
if len(shell.proxies) != 0 || changes != 1 {
t.Fatalf("unreferenced delete state = proxies %#v, changes %d", shell.proxies, changes)
}
}