feat(ui): file browser and connection string builder dialogs (#44)
Enter on File Path inputs opens a file browser (load/save, extension filter, hidden toggle, overwrite confirm). Enter on Connection String inputs opens a builder for PostgreSQL, MSSQL and SQLite with masked password/preview, parsing and optional connection test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
b38f53c603
commit
0235a28add
@@ -0,0 +1,63 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
func newDialogTestEditor() *SchemaEditor {
|
||||
se := &SchemaEditor{app: tview.NewApplication(), pages: tview.NewPages()}
|
||||
se.pages.AddPage("origin", tview.NewBox(), true, true)
|
||||
return se
|
||||
}
|
||||
|
||||
func TestFileBrowserOpensOnEachMode(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
touch(t, filepath.Join(dir, "a.dbml"))
|
||||
|
||||
for _, mode := range []FileBrowserMode{FileBrowserLoad, FileBrowserSave} {
|
||||
se := newDialogTestEditor()
|
||||
se.showFileBrowser(FileBrowserConfig{
|
||||
Mode: mode,
|
||||
StartPath: filepath.Join(dir, "a.dbml"),
|
||||
Extensions: FormatExtensions("dbml"),
|
||||
ReturnPage: "origin",
|
||||
OnSelect: func(string) { t.Error("OnSelect must not fire without a selection") },
|
||||
})
|
||||
if !se.pages.HasPage("file-browser") {
|
||||
t.Errorf("mode %d: file-browser page missing", mode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConnStringBuilderOpensForEachKind(t *testing.T) {
|
||||
for _, in := range []string{
|
||||
"",
|
||||
"postgres://u:pw@db:5432/app?sslmode=disable",
|
||||
"sqlserver://sa:pw@sql:1433?database=shop&encrypt=disable",
|
||||
"/tmp/app.db",
|
||||
"postgres://u:p@host:badport/db", // parse error falls back to defaults
|
||||
} {
|
||||
se := newDialogTestEditor()
|
||||
se.showConnStringBuilder(in, ConnPostgres, "origin", func(string) {
|
||||
t.Error("onDone must not fire without Save")
|
||||
})
|
||||
if !se.pages.HasPage(connBuilderPage) {
|
||||
t.Errorf("%q: builder page missing", in)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateConnFields(t *testing.T) {
|
||||
if validateConnFields(ConnFields{Kind: ConnSQLite}) == "" {
|
||||
t.Error("sqlite without path should be invalid")
|
||||
}
|
||||
if validateConnFields(ConnFields{Kind: ConnPostgres}) == "" {
|
||||
t.Error("postgres without host should be invalid")
|
||||
}
|
||||
if msg := validateConnFields(DefaultConnFields(ConnMSSQL)); msg != "" {
|
||||
t.Errorf("defaults should be valid, got %q", msg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user