(t *testing.T)
| 67 | } |
| 68 | |
| 69 | func TestTUI_Startup_LoadsCompletedTiming(t *testing.T) { |
| 70 | tmpDir, err := os.MkdirTemp("", "surge-tui-completed-test") |
| 71 | if err != nil { |
| 72 | t.Fatal(err) |
| 73 | } |
| 74 | defer func() { _ = os.RemoveAll(tmpDir) }() |
| 75 | |
| 76 | setupTestEnv(t, tmpDir) |
| 77 | |
| 78 | testID := "tui-completed-id" |
| 79 | testURL := "http://example.com/completed.zip" |
| 80 | testDest := filepath.Join(tmpDir, "completed.zip") |
| 81 | const totalSize = int64(5 * 1024 * 1024) |
| 82 | const timeTakenMs = int64(2500) |
| 83 | const avgSpeed = float64(2 * 1024 * 1024) // 2 MB/s |
| 84 | |
| 85 | if err := state.AddToMasterList(types.DownloadEntry{ |
| 86 | ID: testID, |
| 87 | URL: testURL, |
| 88 | URLHash: state.URLHash(testURL), |
| 89 | DestPath: testDest, |
| 90 | Filename: filepath.Base(testDest), |
| 91 | Status: "completed", |
| 92 | TotalSize: totalSize, |
| 93 | Downloaded: totalSize, |
| 94 | TimeTaken: timeTakenMs, |
| 95 | AvgSpeed: avgSpeed, |
| 96 | }); err != nil { |
| 97 | t.Fatal(err) |
| 98 | } |
| 99 | |
| 100 | progressChan := make(chan any, 10) |
| 101 | pool := download.NewWorkerPool(progressChan, 3) |
| 102 | m := InitialRootModel(1700, "test-version", core.NewLocalDownloadServiceWithInput(pool, progressChan), processing.NewLifecycleManager(nil, nil), false) |
| 103 | |
| 104 | var found *DownloadModel |
| 105 | for _, d := range m.downloads { |
| 106 | if d.ID == testID { |
| 107 | found = d |
| 108 | break |
| 109 | } |
| 110 | } |
| 111 | if found == nil { |
| 112 | t.Fatal("TUI Model failed to load completed download") |
| 113 | return |
| 114 | } |
| 115 | if !found.done { |
| 116 | t.Error("Expected completed download to be marked done") |
| 117 | } |
| 118 | if found.Elapsed != time.Duration(timeTakenMs)*time.Millisecond { |
| 119 | t.Errorf("Elapsed = %v, want %v", found.Elapsed, time.Duration(timeTakenMs)*time.Millisecond) |
| 120 | } |
| 121 | if found.Speed != avgSpeed { |
| 122 | t.Errorf("Speed = %f, want %f", found.Speed, avgSpeed) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | func TestTUI_Startup_LoadsErroredDownloadsIntoDoneTab(t *testing.T) { |
nothing calls this directly
no test coverage detected