GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — lankir/app_test.go at master · Matbe34/lankir Expand file tree/ Copy pathapp_test.goMore file actions 206 lines (176 loc) · 5.27 KB / Copy pathapp_test.goFile metadata and controls206 lines (176 loc) · 5.27 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 package main import ( "os" "path/filepath" "reflect" "strings" "testing" "github.com/wailsapp/wails/v3/pkg/application" "github.com/Matbe34/lankir/internal/version" ) func TestVersionReportsBuildVersion(t *testing.T) { old := version.Version version.Version = "1.2.3-test" t.Cleanup(func() { version.Version = old }) if got := NewApp(nil).Version(); got != "1.2.3-test" { t.Errorf("Version() = %q, want %q", got, "1.2.3-test") } } type emitted struct { name string data []any } func newTestApp(initial []string) (*App, *[]emitted) { var events []emitted app := NewApp(initial) app.emit = func(name string, data ...any) bool { events = append(events, emitted{name, data}) return false } return app, &events } func TestTakeStartupFiles_ReturnsInitialFilesOnce(t *testing.T) { app, events := newTestApp([]string{"a.pdf", "b.pdf"}) if got := app.TakeStartupFiles(); !reflect.DeepEqual(got, []string{"a.pdf", "b.pdf"}) { t.Errorf("first take: got %v", got) } if got := app.TakeStartupFiles(); len(got) != 0 { t.Errorf("second take should be empty, got %v", got) } if len(*events) != 0 { t.Errorf("startup files must not be emitted, got %v", *events) } } func TestInterceptClose(t *testing.T) { app, events := newTestApp(nil) if app.interceptClose() { t.Error("nothing unsaved: close must go ahead") } app.SetUnsavedChanges(1, true) if !app.interceptClose() { t.Error("unsaved changes: close must be held") } want := []emitted{{"close-requested", nil}} if !reflect.DeepEqual(*events, want) { t.Errorf("got %v want %v", *events, want) } app.closeConfirmed.Store(true) if app.interceptClose() { t.Error("confirmed close must go ahead") } } func TestSetUnsavedChanges_IgnoresStaleCalls(t *testing.T) { app, _ := newTestApp(nil) // Each binding call runs on its own goroutine, so they can land out of order. app.SetUnsavedChanges(2, false) app.SetUnsavedChanges(1, true) if app.unsaved.Load() { t.Error("an older report overrode a newer one") } app.SetUnsavedChanges(3, true) if !app.unsaved.Load() { t.Error("a newer report was ignored") } } func TestOpenFiles_QueuedUntilFrontendTakesThem(t *testing.T) { app, events := newTestApp([]string{"start.pdf"}) app.openFiles([]string{"/early.pdf"}) if len(*events) != 0 { t.Fatalf("emitted before frontend was ready: %v", *events) } if got := app.TakeStartupFiles(); !reflect.DeepEqual(got, []string{"start.pdf", "/early.pdf"}) { t.Errorf("take: got %v", got) } app.openFiles([]string{"/late.pdf"}) want := []emitted{{"open-files", []any{[]string{"/late.pdf"}}}} if !reflect.DeepEqual(*events, want) { t.Errorf("got %v want %v", *events, want) } } func TestOnFilesDropped(t *testing.T) { app, events := newTestApp(nil) app.TakeStartupFiles() app.onFilesDropped(nil) if len(*events) != 0 { t.Fatalf("empty drop must not emit, got %v", *events) } app.onFilesDropped([]string{"/x/a.txt"}) app.onFilesDropped([]string{"/x/a.PDF", "/x/b.png", "/x/c.pdf"}) want := []emitted{ {"open-files", []any{[]string{}}}, {"open-files", []any{[]string{"/x/a.PDF", "/x/c.pdf"}}}, } if !reflect.DeepEqual(*events, want) { t.Errorf("got %v want %v", *events, want) } } func TestOnSecondInstance(t *testing.T) { app, events := newTestApp(nil) app.TakeStartupFiles() cwd := t.TempDir() app.onSecondInstance(application.SecondInstanceData{Args: []string{"/usr/bin/lankir"}, WorkingDir: cwd}) if len(*events) != 0 { t.Fatalf("bare relaunch must not emit, got %v", *events) } app.onSecondInstance(application.SecondInstanceData{ Args: []string{"/opt/lankir.pdf", "rel.pdf", "/abs/x.pdf", "notes.txt"}, WorkingDir: cwd, }) want := []emitted{{"open-files", []any{[]string{filepath.Join(cwd, "rel.pdf"), "/abs/x.pdf"}}}} if !reflect.DeepEqual(*events, want) { t.Errorf("got %v want %v", *events, want) } } func TestFilterPDFPaths(t *testing.T) { got := filterPDFPaths([]string{"a.pdf", "b.txt", "C.PDF", "/x/y/z.png", "doc.pdf"}) want := []string{"a.pdf", "C.PDF", "doc.pdf"} if !reflect.DeepEqual(got, want) { t.Errorf("got %v want %v", got, want) } } func TestResolveSecondInstancePaths(t *testing.T) { cwd, err := os.MkdirTemp("", "lankir-test-cwd-*") if err != nil { t.Fatal(err) } defer os.RemoveAll(cwd) abs := filepath.Join(cwd, "abs.pdf") got := resolveSecondInstancePaths([]string{"rel.pdf", abs, "other.txt"}, cwd) want := []string{ filepath.Join(cwd, "rel.pdf"), abs, } if !reflect.DeepEqual(got, want) { t.Errorf("got %v want %v", got, want) } } func TestNewWindowEnv(t *testing.T) { in := []string{"PATH=/bin", "LANKIR_NEW_WINDOW=1", "HOME=/root", "LANKIR_NEW_WINDOW=stale"} got := newWindowEnv(in) // Must contain exactly one LANKIR_NEW_WINDOW=1 (we strip any prior and re-add). count := 0 for _, e := range got { if e == "LANKIR_NEW_WINDOW=1" { count++ } if strings.HasPrefix(e, "LANKIR_NEW_WINDOW=") && e != "LANKIR_NEW_WINDOW=1" { t.Errorf("non-canonical LANKIR_NEW_WINDOW entry: %q", e) } } if count != 1 { t.Errorf("expected exactly one LANKIR_NEW_WINDOW=1; got %d in %v", count, got) } // Other env entries preserved. hasPath, hasHome := false, false for _, e := range got { if e == "PATH=/bin" { hasPath = true } if e == "HOME=/root" { hasHome = true } } if !hasPath || !hasHome { t.Errorf("non-LANKIR env not preserved: %v", got) } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |