Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
package store_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"pageswiki/internal/db"
|
|
"pageswiki/internal/store"
|
|
)
|
|
|
|
func TestBrowserNavigationLifecycleAndRecursiveRename(t *testing.T) {
|
|
database, err := db.Open(t.TempDir() + "/browser-navigation.db")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer database.Close()
|
|
if err = db.Migrate(database); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
st := store.New(database)
|
|
domain, err := st.GetDefaultDomain()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err = st.CreatePageAtPathInDomain(domain.UUID, "/old/page"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
principal := "principal-test"
|
|
folder, err := st.AddBrowserNavigationLink(domain.UUID, principal, "Old folder", "/old", true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
file, err := st.AddBrowserNavigationLink(domain.UUID, principal, "Page", "/old/page", false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
duplicate, err := st.AddBrowserNavigationLink(domain.UUID, principal, "Duplicate", "/old/page", false)
|
|
if err != nil || duplicate.UUID != file.UUID {
|
|
t.Fatalf("duplicate add = %#v, %v", duplicate, err)
|
|
}
|
|
if err = st.RenameBrowserNavigationLink(domain.UUID, principal, folder.UUID, "Renamed folder"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
count, err := st.RenamePathsInDomain(domain.UUID, "/old", "/new", true)
|
|
if err != nil || count != 1 {
|
|
t.Fatalf("recursive rename = %d, %v", count, err)
|
|
}
|
|
links, err := st.ListBrowserNavigationLinks(domain.UUID, principal)
|
|
if err != nil || len(links) != 2 {
|
|
t.Fatalf("links = %#v, %v", links, err)
|
|
}
|
|
if links[0].Label != "Renamed folder" || links[0].Path != "/new" || !links[0].IsDir || links[1].Path != "/new/page" || links[1].IsDir {
|
|
t.Fatalf("renamed links = %#v", links)
|
|
}
|
|
if err = st.DeleteBrowserNavigationLink(domain.UUID, principal, file.UUID); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
links, err = st.ListBrowserNavigationLinks(domain.UUID, principal)
|
|
if err != nil || len(links) != 1 {
|
|
t.Fatalf("links after delete = %#v, %v", links, err)
|
|
}
|
|
}
|