|
1 | 1 | use super::{ |
2 | | - DedupUpdate, DetailRecord, EntryMeta, Focus, MODAL_ATTR_ENTRY_LIMIT_PER_KIND, ViewApp, create_temp_path, extract_otlp_log_message, |
| 2 | + DedupUpdate, DetailRecord, EntryMeta, ExportField, Focus, MODAL_ATTR_ENTRY_LIMIT_PER_KIND, ViewApp, create_temp_path, extract_otlp_log_message, |
3 | 3 | format_summary, open_temp_spool_pair, read_spool_record, render_modal_info_entries, render_modal_message, text_preview, write_spool_record, |
4 | 4 | }; |
5 | 5 | use crate::cli::ViewArgs; |
@@ -516,12 +516,49 @@ fn export_prompt_defaults_to_json_and_all() { |
516 | 516 | let _ = std::fs::remove_file(input); |
517 | 517 | } |
518 | 518 |
|
| 519 | +#[test] |
| 520 | +fn export_prompt_supports_cursor_navigation_and_mid_string_editing() { |
| 521 | + let input = create_temp_path().unwrap(); |
| 522 | + write_test_logjet_rows(&input, &[("alpha", &["AndroidGeoLocationListener"], "esotrace.log.utf8")]); |
| 523 | + |
| 524 | + let mut app = make_view_app(input.clone()); |
| 525 | + app.apply_filter().unwrap(); |
| 526 | + wait_for_scan(&mut app); |
| 527 | + app.open_export_prompt().unwrap(); |
| 528 | + |
| 529 | + app.export_field = ExportField::Range; |
| 530 | + app.export_range = "all".to_string(); |
| 531 | + app.export_range_cursor = 1; |
| 532 | + app.handle_export_prompt_key(KeyEvent::from(KeyCode::Delete)).unwrap(); |
| 533 | + assert_eq!(app.export_range, "al"); |
| 534 | + assert_eq!(app.export_range_cursor, 1); |
| 535 | + |
| 536 | + app.handle_export_prompt_key(KeyEvent::from(KeyCode::Left)).unwrap(); |
| 537 | + app.handle_export_prompt_key(KeyEvent::from(KeyCode::Char('c'))).unwrap(); |
| 538 | + assert_eq!(app.export_range, "cal"); |
| 539 | + assert_eq!(app.export_range_cursor, 1); |
| 540 | + |
| 541 | + app.handle_export_prompt_key(KeyEvent::from(KeyCode::End)).unwrap(); |
| 542 | + app.handle_export_prompt_key(KeyEvent::from(KeyCode::Char('l'))).unwrap(); |
| 543 | + assert_eq!(app.export_range, "call"); |
| 544 | + |
| 545 | + app.handle_export_prompt_key(KeyEvent::from(KeyCode::Home)).unwrap(); |
| 546 | + assert_eq!(app.export_range_cursor, 0); |
| 547 | + |
| 548 | + let _ = std::fs::remove_file(input); |
| 549 | +} |
| 550 | + |
519 | 551 | #[test] |
520 | 552 | fn export_selection_accepts_all_amount_and_range() { |
521 | | - assert_eq!(super::parse_export_selection("all", 50).unwrap(), (0, 50)); |
522 | | - assert_eq!(super::parse_export_selection("aLl", 50).unwrap(), (0, 50)); |
523 | | - assert_eq!(super::parse_export_selection("3", 50).unwrap(), (0, 3)); |
524 | | - assert_eq!(super::parse_export_selection("2-4", 50).unwrap(), (1, 4)); |
| 553 | + assert_eq!(super::parse_export_selection("all", 50, 0).unwrap(), (0, 50)); |
| 554 | + assert_eq!(super::parse_export_selection("aLl", 50, 0).unwrap(), (0, 50)); |
| 555 | + assert_eq!(super::parse_export_selection("a", 50, 0).unwrap(), (0, 50)); |
| 556 | + assert_eq!(super::parse_export_selection("current", 50, 7).unwrap(), (7, 8)); |
| 557 | + assert_eq!(super::parse_export_selection("CuRrEnT", 50, 7).unwrap(), (7, 8)); |
| 558 | + assert_eq!(super::parse_export_selection("c", 50, 7).unwrap(), (7, 8)); |
| 559 | + assert_eq!(super::parse_export_selection("0", 50, 7).unwrap(), (7, 8)); |
| 560 | + assert_eq!(super::parse_export_selection("3", 50, 0).unwrap(), (0, 3)); |
| 561 | + assert_eq!(super::parse_export_selection("2-4", 50, 0).unwrap(), (1, 4)); |
525 | 562 | } |
526 | 563 |
|
527 | 564 | #[test] |
@@ -554,3 +591,32 @@ fn export_current_results_writes_ndjson_from_filtered_view() { |
554 | 591 | let _ = std::fs::remove_file(input); |
555 | 592 | let _ = std::fs::remove_file(output); |
556 | 593 | } |
| 594 | + |
| 595 | +#[test] |
| 596 | +fn export_current_results_can_export_selected_row_only() { |
| 597 | + let input = create_temp_path().unwrap(); |
| 598 | + let output = input.parent().unwrap().join("export-current.json"); |
| 599 | + write_test_logjet_rows( |
| 600 | + &input, |
| 601 | + &[ |
| 602 | + ("first gps", &["AndroidGeoLocationListener"], "esotrace.log.utf8"), |
| 603 | + ("second gps", &["AndroidGeoLocationListener"], "esotrace.log.utf8"), |
| 604 | + ("third gps", &["AndroidGeoLocationListener"], "esotrace.log.utf8"), |
| 605 | + ], |
| 606 | + ); |
| 607 | + |
| 608 | + let mut app = make_view_app(input.clone()); |
| 609 | + app.apply_filter().unwrap(); |
| 610 | + wait_for_scan(&mut app); |
| 611 | + app.selected = 1; |
| 612 | + app.export_filename = "export-current.json".to_string(); |
| 613 | + app.export_range = "current".to_string(); |
| 614 | + app.export_current_results().unwrap(); |
| 615 | + |
| 616 | + let docs = read_ndjson(&output); |
| 617 | + assert_eq!(docs.len(), 1); |
| 618 | + assert_eq!(docs[0]["body"], "second gps"); |
| 619 | + |
| 620 | + let _ = std::fs::remove_file(input); |
| 621 | + let _ = std::fs::remove_file(output); |
| 622 | +} |
0 commit comments