Add behavior tests for extracted menu model
This commit is contained in:
+108
@@ -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) {
|
func TestUICurrentVaultSummary(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user