77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestCaptureTextCreatesInboxArtifact(t *testing.T) {
|
|
app, _ := setupTestApp(t)
|
|
|
|
dto, err := app.CaptureText("Нужно разобрать этот текст")
|
|
if err != nil {
|
|
t.Fatalf("CaptureText: %v", err)
|
|
}
|
|
if dto.ID == "" {
|
|
t.Fatal("empty captured node id")
|
|
}
|
|
if dto.CaptureKind != "text" {
|
|
t.Fatalf("CaptureKind = %q, want text", dto.CaptureKind)
|
|
}
|
|
if dto.CaptureSource != "clipboard" {
|
|
t.Fatalf("CaptureSource = %q, want clipboard", dto.CaptureSource)
|
|
}
|
|
|
|
content, err := app.ReadNote(dto.ID)
|
|
if err != nil {
|
|
t.Fatalf("ReadNote: %v", err)
|
|
}
|
|
if !strings.Contains(content, "Нужно разобрать этот текст") {
|
|
t.Fatalf("captured content missing: %q", content)
|
|
}
|
|
var path string
|
|
if err := app.db.QueryRow(`SELECT f.path FROM notes n JOIN files f ON f.id = n.file_id WHERE n.node_id = ?`, dto.ID).Scan(&path); err != nil {
|
|
t.Fatalf("query note file path: %v", err)
|
|
}
|
|
if !strings.HasPrefix(path, ".verstak/inbox/") {
|
|
t.Fatalf("path = %q, want .verstak/inbox prefix", path)
|
|
}
|
|
|
|
inbox, err := app.ListInboxNodes()
|
|
if err != nil {
|
|
t.Fatalf("ListInboxNodes: %v", err)
|
|
}
|
|
var found bool
|
|
for _, item := range inbox {
|
|
if item.ID == dto.ID {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatal("captured text missing from inbox")
|
|
}
|
|
}
|
|
|
|
func TestCaptureURLCreatesInboxArtifact(t *testing.T) {
|
|
app, _ := setupTestApp(t)
|
|
|
|
dto, err := app.CaptureURL("https://example.test/page", "Example Page")
|
|
if err != nil {
|
|
t.Fatalf("CaptureURL: %v", err)
|
|
}
|
|
if dto.CaptureKind != "url" {
|
|
t.Fatalf("CaptureKind = %q, want url", dto.CaptureKind)
|
|
}
|
|
if dto.Title != "Example Page" {
|
|
t.Fatalf("Title = %q, want Example Page", dto.Title)
|
|
}
|
|
|
|
content, err := app.ReadNote(dto.ID)
|
|
if err != nil {
|
|
t.Fatalf("ReadNote: %v", err)
|
|
}
|
|
if !strings.Contains(content, "https://example.test/page") {
|
|
t.Fatalf("captured URL missing: %q", content)
|
|
}
|
|
}
|