| 1 | |
| 2 | |
| 3 | |
| 4 | use crate::keymap::ActionId; |
| 5 | use crate::player::project_dialogs::project_file_name; |
| 6 | use crate::viewer_view::{Zoom, picture_rect}; |
| 7 | use gpui::{Pixels, Point, point, px}; |
| 8 | |
| 9 | |
| 10 | #[test] |
| 11 | fn the_export_tab_lets_the_range_marks_through() { |
| 12 | let km = crate::keymap::Keymap::defaults(); |
| 13 | for key in ["i", "o"] { |
| 14 | let action = km.lookup(key, false, false, false).expect("a mark key"); |
| 15 | assert!(crate::ui::stance::export_tab_action(action), "{key} is swallowed by the Export tab"); |
| 16 | } |
| 17 | assert!(crate::ui::stance::export_tab_action(ActionId::ClearRange)); |
| 18 | |
| 19 | assert!(!crate::ui::stance::export_tab_action(ActionId::Delete)); |
| 20 | } |
| 21 | |
| 22 | |
| 23 | #[test] |
| 24 | fn a_seam_click_without_travel_is_not_a_drag() { |
| 25 | use crate::player::timeline_edit::split_travelled; |
| 26 | let at = |x: f32, y: f32| -> Point<Pixels> { point(px(x), px(y)) }; |
| 27 | assert!(!split_travelled(at(500., 400.), at(500., 400.))); |
| 28 | assert!(!split_travelled(at(500., 400.), at(501., 402.))); |
| 29 | assert!(split_travelled(at(500., 400.), at(500., 410.))); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | |
| 34 | #[test] |
| 35 | fn leaving_the_window_commits_the_scrubs() { |
| 36 | let src = include_str!("../player/timeline_edit.rs"); |
| 37 | let at = src.find("pub(crate) fn drag_left_window").expect("the leave handler"); |
| 38 | let body = &src[at..at + src[at..].find("\n }\n").unwrap()]; |
| 39 | assert!(body.contains("pan_scrub_end"), "a pan scrub dropped on leave"); |
| 40 | assert!(body.contains("title_scrub_end"), "a title scrub dropped on leave"); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | #[test] |
| 45 | fn the_zoomed_picture_has_its_own_rectangle() { |
| 46 | let native = (1920., 1080.); |
| 47 | let bx = (800., 450.); |
| 48 | |
| 49 | assert_eq!(picture_rect(Zoom::Fit, native, bx, (0., 0.), (0., 0.), 1.), (0., 0., 800., 450.)); |
| 50 | |
| 51 | assert_eq!(picture_rect(Zoom::P50, native, bx, (0., 0.), (0., 0.), 1.), (-80., -45., 960., 540.)); |
| 52 | |
| 53 | assert_eq!(picture_rect(Zoom::P50, native, bx, (0., 0.), (30., 0.), 1.), (-50., -45., 960., 540.)); |
| 54 | assert_eq!(picture_rect(Zoom::P50, native, bx, (0., 0.), (500., 0.), 1.).0, 0.); |
| 55 | |
| 56 | assert_eq!(picture_rect(Zoom::P25, native, bx, (0., 0.), (0., 0.), 1.), (160., 90., 480., 270.)); |
| 57 | |
| 58 | let render = include_str!("../render.rs"); |
| 59 | assert!(!render.contains("== crate::viewer_view::Zoom::Fit))"), "an overlay is hidden while zoomed"); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | #[test] |
| 64 | fn the_clip_menu_words_are_plain_and_trim_out_has_an_icon() { |
| 65 | assert_eq!(ActionId::Detach.label(), "Unlink audio and video"); |
| 66 | assert_eq!(ActionId::Regroup.label(), "Join clips back"); |
| 67 | assert!(crate::menus::note(ActionId::Detach).is_some(), "Unlink says what it does on hover"); |
| 68 | assert!(crate::menus::icon(ActionId::TrimOut).is_some()); |
| 69 | assert!(crate::menus::icon(ActionId::TrimIn).is_some()); |
| 70 | for action in crate::menus::MENU_ITEMS { |
| 71 | let label = action.label(); |
| 72 | assert!(!label.contains("group") && !label.contains("Group") || action == ActionId::Group, "{label}"); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | #[test] |
| 77 | fn a_typed_project_name_makes_a_safe_file_name() { |
| 78 | assert_eq!(project_file_name("Trip"), Some("Trip.edith".into())); |
| 79 | assert_eq!(project_file_name(" Trip.edith "), Some("Trip.edith".into())); |
| 80 | assert_eq!(project_file_name("a/b"), Some("a-b.edith".into())); |
| 81 | assert_eq!(project_file_name(" "), None); |
| 82 | assert_eq!(project_file_name(".."), None); |
| 83 | } |