fix: serialize persistent profile mutations
This commit is contained in:
@@ -141,11 +141,9 @@ func (m Model) updateForm(key tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
case "ctrl+t":
|
||||
if m.form.profile.Mode == profile.SingleMode {
|
||||
m.form.profile.Mode = profile.AdvancedMode
|
||||
if m.form.profile.HTTPURL == "" && m.form.profile.HTTPSURL == "" && m.form.profile.AllURL == "" {
|
||||
m.form.profile.HTTPURL = m.form.profile.SingleURL
|
||||
m.form.profile.HTTPSURL = m.form.profile.SingleURL
|
||||
m.form.profile.AllURL = m.form.profile.SingleURL
|
||||
}
|
||||
m.form.profile.HTTPURL = m.form.profile.SingleURL
|
||||
m.form.profile.HTTPSURL = m.form.profile.SingleURL
|
||||
m.form.profile.AllURL = m.form.profile.SingleURL
|
||||
} else {
|
||||
m.form.profile.Mode = profile.SingleMode
|
||||
}
|
||||
|
||||
@@ -81,6 +81,33 @@ func TestProfileFormMapsKeyboardInputToCreateIntent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEditingSingleURLExpandsCurrentValueWhenSwitchingToAdvanced(t *testing.T) {
|
||||
const oldURL = "http://old.example:8080"
|
||||
const newURL = "socks5h://new.example:1080"
|
||||
module := &recordingModule{snapshot: app.Snapshot{Profiles: []profile.Profile{{
|
||||
Name: "office", Mode: profile.SingleMode, SingleURL: oldURL,
|
||||
HTTPURL: oldURL, HTTPSURL: oldURL, AllURL: oldURL,
|
||||
}}}}
|
||||
model := NewModel(module)
|
||||
model = updateKey(model, "p")
|
||||
model = updateKey(model, "e")
|
||||
model = updateKey(model, "tab")
|
||||
for range oldURL {
|
||||
model = updateKey(model, "backspace")
|
||||
}
|
||||
model = updateRunes(model, newURL)
|
||||
model = updateKey(model, "ctrl+t")
|
||||
model = updateKey(model, "ctrl+s")
|
||||
|
||||
if len(module.intents) != 1 {
|
||||
t.Fatalf("edit form dispatched %d intents", len(module.intents))
|
||||
}
|
||||
got := module.intents[0].Profile
|
||||
if got.HTTPURL != newURL || got.HTTPSURL != newURL || got.AllURL != newURL {
|
||||
t.Fatalf("advanced URLs = %q, %q, %q; want current Single URL %q", got.HTTPURL, got.HTTPSURL, got.AllURL, newURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderedMalformedProxyURLStillObscuresPassword(t *testing.T) {
|
||||
module := &recordingModule{snapshot: app.Snapshot{Profiles: []profile.Profile{{
|
||||
Name: "manual", Mode: profile.SingleMode, SingleURL: "http://alice:do-not-show@proxy.example:bad",
|
||||
@@ -107,6 +134,10 @@ func updateKey(model Model, key string) Model {
|
||||
msg = tea.KeyMsg{Type: tea.KeyTab}
|
||||
case "ctrl+s":
|
||||
msg = tea.KeyMsg{Type: tea.KeyCtrlS}
|
||||
case "ctrl+t":
|
||||
msg = tea.KeyMsg{Type: tea.KeyCtrlT}
|
||||
case "backspace":
|
||||
msg = tea.KeyMsg{Type: tea.KeyBackspace}
|
||||
}
|
||||
updated, _ := model.Update(msg)
|
||||
return updated.(Model)
|
||||
|
||||
Reference in New Issue
Block a user