(t *testing.T)
| 488 | } |
| 489 | |
| 490 | func TestUpdate_DownloadRequestMsg(t *testing.T) { |
| 491 | // Setup initial model |
| 492 | ch := make(chan any, 100) |
| 493 | pool := download.NewWorkerPool(ch, 1) |
| 494 | svc := core.NewLocalDownloadServiceWithInput(pool, ch) |
| 495 | t.Cleanup(func() { _ = svc.Shutdown() }) |
| 496 | |
| 497 | m := RootModel{ |
| 498 | Settings: config.DefaultSettings(), |
| 499 | Service: svc, |
| 500 | logViewport: viewport.New(viewport.WithWidth(40), viewport.WithHeight(5)), |
| 501 | list: NewDownloadList(40, 10), |
| 502 | inputs: []textinput.Model{textinput.New(), textinput.New(), textinput.New(), textinput.New()}, |
| 503 | } |
| 504 | |
| 505 | // 1. Test Extension Prompt Enabled |
| 506 | m.Settings.Extension.ExtensionPrompt.Value = true |
| 507 | m.Settings.General.WarnOnDuplicate.Value = true |
| 508 | |
| 509 | msg := events.DownloadRequestMsg{ |
| 510 | URL: "http://example.com/test.zip", |
| 511 | Filename: "test.zip", |
| 512 | Path: "/tmp/downloads", |
| 513 | } |
| 514 | |
| 515 | newM, _ := m.Update(msg) |
| 516 | newRoot := newM.(RootModel) |
| 517 | |
| 518 | if newRoot.state != ExtensionConfirmationState { |
| 519 | t.Errorf("Expected ExtensionConfirmationState, got %v", newRoot.state) |
| 520 | } |
| 521 | if newRoot.pendingURL != msg.URL { |
| 522 | t.Errorf("Expected pendingURL=%s, got %s", msg.URL, newRoot.pendingURL) |
| 523 | } |
| 524 | if newRoot.pendingFilename != msg.Filename { |
| 525 | t.Errorf("Expected pendingFilename=%s, got %s", msg.Filename, newRoot.pendingFilename) |
| 526 | } |
| 527 | if newRoot.pendingPath != msg.Path { |
| 528 | t.Errorf("Expected pendingPath=%s, got %s", msg.Path, newRoot.pendingPath) |
| 529 | } |
| 530 | |
| 531 | // 2. Test Duplicate Warning (when prompt disabled but duplicate exists) |
| 532 | m.Settings.Extension.ExtensionPrompt.Value = false |
| 533 | m.Settings.General.WarnOnDuplicate.Value = true |
| 534 | |
| 535 | // Add existing download |
| 536 | m.downloads = append(m.downloads, &DownloadModel{ |
| 537 | URL: "http://example.com/test.zip", |
| 538 | Filename: "test.zip", |
| 539 | }) |
| 540 | |
| 541 | newM, _ = m.Update(msg) |
| 542 | newRoot = newM.(RootModel) |
| 543 | |
| 544 | if newRoot.state != DuplicateWarningState { |
| 545 | t.Errorf("Expected DuplicateWarningState, got %v", newRoot.state) |
| 546 | } |
| 547 |
nothing calls this directly
no test coverage detected