PrintToVeraeTimeStamp/cmd/verae-print/saveas_test.go
Grok Bot (for George) 13ebc351f5 0.3.2: Save As filename prompt per print (Windows + macOS)
- promptForFilename setting (default true; env VERAE_PROMPT_FOR_FILENAME),
  'verae-print config --prompt-for-filename', last Save As folder in
  ~/.verae/state.json
- Windows helper: common file dialog (PDF filter, overwrite prompt, topmost
  owner) before stamping; macOS printer path: choose file name (NSSavePanel)
  via 'stamp -prompt-name -title'; cancel discards the job (no stamp/credit)
- job.Options.OutPath: original saved at the chosen path, certificate and
  .verae.json next to it with the chosen base name (never overwritten)
- held jobs keep the chosen path (pendingMeta.OutPath)
- installer: 'Ask for a file name for each print' checkbox; removed the
  'Open the user guide' finish-page checkbox; mac-key-setup asks too
- auth test no longer touches the real macOS keychain (VERAE_SKIP_KEYCHAIN)
- version 0.3.2
2026-10-03 20:00:56 -04:00

39 lines
1.1 KiB
Go

package main
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestSaveNameFromTitle(t *testing.T) {
now := time.Date(2026, 10, 3, 19, 5, 7, 0, time.Local)
cases := map[string]string{
"Microsoft Word - Contract v2.docx": "Contract v2.pdf",
`C:\Users\x\Désirée notes.txt`: "Désirée notes.pdf",
"": "Printed 2026-10-03 190507.pdf",
" ": "Printed 2026-10-03 190507.pdf",
"a:b?c": "a-b-c.pdf",
"Report 1.5 final": "Report 1.5 final.pdf",
}
for in, want := range cases {
if got := saveNameFromTitle(in, now); got != want {
t.Errorf("%q -> %q want %q", in, got, want)
}
}
}
func TestEnsurePDFExt(t *testing.T) {
d := t.TempDir()
if got := ensurePDFExt(filepath.Join(d, "a.PDF")); got != filepath.Join(d, "a.PDF") {
t.Fatal(got)
}
if got := ensurePDFExt(filepath.Join(d, "b")); got != filepath.Join(d, "b.pdf") {
t.Fatal(got)
}
_ = os.WriteFile(filepath.Join(d, "b.pdf"), nil, 0o600)
if got := ensurePDFExt(filepath.Join(d, "b")); got != filepath.Join(d, "b-2.pdf") {
t.Fatal(got)
}
}