diff --git a/main_test.go b/main_test.go index a809dc9..002d28b 100644 --- a/main_test.go +++ b/main_test.go @@ -427,6 +427,114 @@ func TestDropdownSurfaceOriginKeepsMenusWithinVisibleArea(t *testing.T) { } } +func TestBuildSyncMenuModelForUnboundVault(t *testing.T) { + t.Parallel() + + u := newUIWithModel("desktop", vault.Model{ + Entries: []vault.Entry{ + {ID: "mint-ledger", Title: "Mint Ledger"}, + }, + }) + u.state.Section = appstate.SectionEntries + + model := u.buildSyncMenuModel() + if !model.showRemoteSyncSetupShortcut() { + t.Fatal("model.showRemoteSyncSetupShortcut() = false, want true for an unbound open vault") + } + if model.showDirectRemoteSyncShortcut() { + t.Fatal("model.showDirectRemoteSyncShortcut() = true, want false without a saved binding") + } + if got := model.actionLabels(); !slices.Equal(got, []string{"Open Advanced Sync", "Set Up Remote Sync"}) { + t.Fatalf("model.actionLabels() = %v, want [Open Advanced Sync Set Up Remote Sync]", got) + } +} + +func TestBuildSyncMenuModelForBoundVault(t *testing.T) { + t.Parallel() + + u := newUIWithModel("desktop", vault.Model{ + Entries: []vault.Entry{ + { + ID: "mint-credential", + Title: "Mint Credentials", + Username: "verbal-kint", + }, + }, + RemoteProfiles: []vault.RemoteProfile{ + { + ID: "mint-profile", + Name: "Downtown Mint", + Backend: vault.RemoteBackendWebDAV, + BaseURL: "https://mint.example.invalid/remote.php/dav", + Path: "/files/kint/mint.kdbx", + }, + }, + }) + u.state.Section = appstate.SectionEntries + u.selectedVaultRemoteProfileID = "mint-profile" + u.selectedVaultRemoteCredentialEntryID = "mint-credential" + u.selectedVaultRemoteSyncMode = appstate.SyncModeAutomaticOnOpenSave + + model := u.buildSyncMenuModel() + if model.showRemoteSyncSetupShortcut() { + t.Fatal("model.showRemoteSyncSetupShortcut() = true, want false for a bound vault") + } + if !model.showDirectRemoteSyncShortcut() { + t.Fatal("model.showDirectRemoteSyncShortcut() = false, want true for a bound vault") + } + if !model.showRemoteSyncSettingsShortcut() { + t.Fatal("model.showRemoteSyncSettingsShortcut() = false, want true for a bound vault") + } + if !model.showRemoveRemoteSyncShortcut() { + t.Fatal("model.showRemoveRemoteSyncShortcut() = false, want true for a bound vault") + } + summary := model.savedBindingSummary + if !summary.ok { + t.Fatal("model.savedBindingSummary.ok = false, want true") + } + if summary.profileLabel != "Downtown Mint" { + t.Fatalf("model.savedBindingSummary.profileLabel = %q, want Downtown Mint", summary.profileLabel) + } + if summary.credentialLabel != "Mint Credentials · verbal-kint" { + t.Fatalf("model.savedBindingSummary.credentialLabel = %q, want Mint Credentials · verbal-kint", summary.credentialLabel) + } + if summary.syncLabel != "Syncs automatically on open and save." { + t.Fatalf("model.savedBindingSummary.syncLabel = %q, want automatic-sync summary", summary.syncLabel) + } +} + +func TestBuildSyncMenuModelShowsSaveCurrentBindingOnlyWithCompleteRemoteInput(t *testing.T) { + t.Parallel() + + u := newUIWithModel("desktop", vault.Model{ + Entries: []vault.Entry{ + {ID: "mint-ledger", Title: "Mint Ledger"}, + }, + }) + u.state.Section = appstate.SectionEntries + + model := u.buildSyncMenuModel() + if model.showSaveCurrentBinding { + t.Fatal("model.showSaveCurrentBinding = true, want false without remote input") + } + + u.remoteBaseURL.SetText("https://mint.example.invalid/remote.php/dav") + u.remotePath.SetText("/files/kint/mint.kdbx") + u.remoteUsername.SetText("verbal-kint") + u.remotePassword.SetText("kobayashi") + + model = u.buildSyncMenuModel() + if !model.showSaveCurrentBinding { + t.Fatal("model.showSaveCurrentBinding = false, want true with complete remote input") + } + if got := model.saveCurrentRemoteBindingHeading(); got != "Bind this local vault to the current remote target" { + t.Fatalf("model.saveCurrentRemoteBindingHeading() = %q, want vault binding guidance", got) + } + if got := model.saveCurrentRemoteBindingButtonLabel(); got != "Save Remote In Vault" { + t.Fatalf("model.saveCurrentRemoteBindingButtonLabel() = %q, want Save Remote In Vault", got) + } +} + func TestUICurrentVaultSummary(t *testing.T) { t.Parallel()