| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | use super::*; |
| 9 | use crate::ui::menubar::{Entry, Title}; |
| 10 | use keymap::ActionId; |
| 11 | |
| 12 | |
| 13 | fn clip() -> Clip { |
| 14 | Clip { |
| 15 | speed_keys: Vec::new(), |
| 16 | effects: Vec::new(), |
| 17 | stabilise: None, deinterlace: Default::default(), mark: Default::default(), |
| 18 | angle: Default::default(), |
| 19 | reversed: false, |
| 20 | fade_in: 0, |
| 21 | fade_out: 0, |
| 22 | transition_out: 0, |
| 23 | transition_kind: Default::default(), |
| 24 | visualizer: 0, |
| 25 | viz_paint: 0, |
| 26 | gain_db: 0.0, |
| 27 | gain_keys: Vec::new(), |
| 28 | pan: 0, |
| 29 | pitch: 0.0, |
| 30 | transform_keys: Vec::new(), |
| 31 | opacity_keys: Vec::new(), |
| 32 | color_keys: Vec::new(), |
| 33 | start: 30, |
| 34 | in_frame: 0, |
| 35 | out_frame: 60, |
| 36 | source: 0, |
| 37 | link: None, |
| 38 | eq: None, |
| 39 | color: None, |
| 40 | transform: None, |
| 41 | fit: FitPolicy::default(), |
| 42 | speed: Speed::NORMAL, |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | |
| 47 | |
| 48 | fn ctx(lane: Lane) -> Ctx { |
| 49 | Ctx { |
| 50 | clip: Some((clip(), lane)), |
| 51 | playhead: 45, |
| 52 | timeline: true, |
| 53 | playable: true, |
| 54 | clipboard: true, |
| 55 | picks: 1, |
| 56 | pick_lanes: 1, |
| 57 | ..Ctx::default() |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | |
| 62 | |
| 63 | fn every_menu_row() -> Vec<(String, ActionId)> { |
| 64 | let mut rows = Vec::new(); |
| 65 | for title in Title::ALL { |
| 66 | for entry in title.entries() { |
| 67 | if let Entry::Act(a) | Entry::Switch(a) = entry { |
| 68 | rows.push((format!("{} menu", title.label()), a)); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | for a in MENU_ITEMS { |
| 73 | rows.push(("clip menu".into(), a)); |
| 74 | } |
| 75 | for a in BENCH_ITEMS { |
| 76 | rows.push(("ruler menu".into(), a)); |
| 77 | } |
| 78 | for a in crate::menus::DOCK_ITEMS { |
| 79 | rows.push(("dock menu".into(), a)); |
| 80 | } |
| 81 | for lane in [Lane::V1, Lane::A1] { |
| 82 | for a in crate::oracle::lane_items(lane) { |
| 83 | rows.push((format!("{lane:?} head menu"), a)); |
| 84 | } |
| 85 | } |
| 86 | rows |
| 87 | } |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | #[test] |
| 93 | fn every_menu_row_runs_or_says_why_it_cannot() { |
| 94 | let act = src_text("player/actions.rs"); |
| 95 | let table = &act[act.find("pub(crate) fn act(").expect("the action table")..]; |
| 96 | let mut ran = 0; |
| 97 | for (menu, action) in every_menu_row() { |
| 98 | for lane in [Lane::V1, Lane::A1] { |
| 99 | match enable(action, ctx(lane)) { |
| 100 | Enable::Yes => { |
| 101 | ran += 1; |
| 102 | let named = format!("ActionId::{action:?}"); |
| 103 | let by_kind = action.transition_kind().is_some(); |
| 104 | assert!( |
| 105 | by_kind || table.contains(&named), |
| 106 | "{menu}: {action:?} is enabled but act() has no arm for it" |
| 107 | ); |
| 108 | } |
| 109 | Enable::No(why) => { |
| 110 | assert!(!why.trim().is_empty(), "{menu}: {action:?} is dim with no reason") |
| 111 | } |
| 112 | Enable::Hidden(_) => {} |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | assert!(ran > 80, "the walk reached only {ran} live rows"); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | |
| 121 | #[test] |
| 122 | fn card_rows_open_their_card_and_the_dock_follows() { |
| 123 | let act = src_text("player/actions.rs"); |
| 124 | for (action, opener) in [ |
| 125 | (ActionId::Silence, "self.open_silence("), |
| 126 | (ActionId::Speed, "self.open_speed("), |
| 127 | (ActionId::Color, "self.open_color("), |
| 128 | (ActionId::Transform, "self.open_transform("), |
| 129 | (ActionId::Equalizer, "self.open_eq("), |
| 130 | (ActionId::Effects, "self.open_effects("), |
| 131 | (ActionId::Mix, "self.open_mix("), |
| 132 | (ActionId::Markers, "self.open_markers("), |
| 133 | (ActionId::SubtitleStyle, "self.open_subtitle_style("), |
| 134 | ] { |
| 135 | let arm = format!("ActionId::{action:?}"); |
| 136 | let at = act.find(&arm).unwrap_or_else(|| panic!("no arm for {action:?}")); |
| 137 | assert!( |
| 138 | act[at..at + 400].contains(opener), |
| 139 | "{action:?} does not open its card through {opener}" |
| 140 | ); |
| 141 | |
| 142 | assert!( |
| 143 | Title::Clip.entries().contains(&Entry::Act(action)) |
| 144 | || Title::Timeline.entries().contains(&Entry::Act(action)), |
| 145 | "{action:?} has no bar-menu row" |
| 146 | ); |
| 147 | } |
| 148 | |
| 149 | let render = src_text("render.rs"); |
| 150 | assert!(render.contains("self.sync_dock_tab();"), "the frame must sync the dock tab"); |
| 151 | let sync = fn_body("sync_dock_tab"); |
| 152 | assert!( |
| 153 | sync.contains("self.dock_src_active && (self.clip_card_open() || self.export_open || self.transcript_open)") |
| 154 | && sync.contains("self.dock_src_active = false;"), |
| 155 | "a docked card must switch the dock to the Clip tab" |
| 156 | ); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | #[test] |
| 161 | fn switch_rows_have_a_check_mark_that_reads_their_state() { |
| 162 | let checked = src_text("ui/menubar.rs"); |
| 163 | let checked = &checked[checked.find("fn checked(").expect("checked()")..]; |
| 164 | let checked = &checked[..checked.find("\n}\n").unwrap()]; |
| 165 | for title in Title::ALL { |
| 166 | for entry in title.entries() { |
| 167 | if let Entry::Switch(a) = entry { |
| 168 | assert!( |
| 169 | checked.contains(&format!("ActionId::{a:?} =>")), |
| 170 | "{a:?} is a switch row whose check mark reads nothing" |
| 171 | ); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | |
| 178 | |
| 179 | #[test] |
| 180 | fn undo_and_redo_dim_with_an_empty_history() { |
| 181 | let live = ctx(Lane::V1); |
| 182 | assert!(enable(ActionId::Undo, live.clone()).yes()); |
| 183 | assert!(enable(ActionId::Redo, live.clone()).yes()); |
| 184 | let empty = Ctx { nothing_to_undo: true, nothing_to_redo: true, ..live }; |
| 185 | assert!(matches!(enable(ActionId::Undo, empty.clone()), Enable::No("nothing to undo"))); |
| 186 | assert!(matches!(enable(ActionId::Redo, empty), Enable::No("nothing to redo"))); |
| 187 | let ctx_fn = fn_body("ctx"); |
| 188 | assert!(ctx_fn.contains("session.undo_depth() == 0") && ctx_fn.contains("session.redo_depth() == 0")); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | |
| 193 | #[test] |
| 194 | fn a_docked_card_does_not_swallow_right_clicks_or_transport_keys() { |
| 195 | for open in ["open_menu", "open_gap_menu", "open_bench_menu", "open_head_menu"] { |
| 196 | assert!( |
| 197 | fn_body(open).contains("self.menu_allowed()"), |
| 198 | "{open} must go through menu_allowed, not a bare modal() refusal" |
| 199 | ); |
| 200 | } |
| 201 | assert!(!fn_body("menu_allowed").contains("close_card"), "a docked card stays up under a menu"); |
| 202 | for safe in [ActionId::Play, ActionId::GoStart, ActionId::GoEnd, ActionId::Export, ActionId::Settings] { |
| 203 | assert!(crate::ui::stance::docked_card_safe_action(safe), "{safe:?}"); |
| 204 | } |
| 205 | |
| 206 | |
| 207 | let docked = fn_body("docked_card_only"); |
| 208 | assert!(docked.contains("!self.covers_room()") && docked.contains("!self.export_open"), "{docked}"); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | #[test] |
| 215 | fn focus_returns_to_the_room_when_the_focused_surface_unmounts() { |
| 216 | let render = src_text("render.rs"); |
| 217 | assert!(render.contains("self.guard_focus(window, cx);")); |
| 218 | let guard = fn_body("guard_focus"); |
| 219 | assert!(guard.contains("!p.focus.contains_focused(window, cx)")); |
| 220 | assert!(guard.contains("window.focus(&p.focus)")); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | |
| 225 | #[test] |
| 226 | fn the_adjust_submenu_opens_the_effects_card() { |
| 227 | assert!(MENU_ITEMS.contains(&ActionId::Effects)); |
| 228 | assert!(crate::menus::adjust_item(ActionId::Effects)); |
| 229 | assert!(every_menu_row().iter().any(|(m, a)| m == "clip menu" && *a == ActionId::Effects)); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | |
| 234 | #[test] |
| 235 | fn a_bar_dropdown_scrolls_inside_the_window() { |
| 236 | let bar = src_text("ui/menubar.rs"); |
| 237 | let drop = &bar[bar.find("fn dropdown(").expect("dropdown()")..]; |
| 238 | assert!(drop.contains("view_h") && drop.contains("max_h(px(room))") && drop.contains("overflow_y_scroll()")); |
| 239 | } |
| 240 | |
| 241 | |
| 242 | |
| 243 | #[test] |
| 244 | fn group_rows_dim_with_a_reason_on_a_plain_clip() { |
| 245 | let plain = Ctx { alone: true, no_join: true, no_partner: true, playhead: 30, ..ctx(Lane::V1) }; |
| 246 | for a in [ActionId::Detach, ActionId::Regroup, ActionId::Group] { |
| 247 | let e = enable(a, plain.clone()); |
| 248 | assert!(!e.yes(), "{a:?} must be dim on a plain clip"); |
| 249 | assert!(e.why().is_some(), "{a:?} dims with a reason"); |
| 250 | } |
| 251 | let mut c = clip(); |
| 252 | c.link = Some(7); |
| 253 | let grouped = Ctx { clip: Some((c, Lane::V1)), no_join: false, ..plain.clone() }; |
| 254 | assert!(!enable(ActionId::Detach, grouped.clone()).yes(), "alone still dims"); |
| 255 | let grouped = Ctx { alone: false, ..grouped }; |
| 256 | assert!(enable(ActionId::Detach, grouped).yes()); |
| 257 | let cut = Ctx { alone: false, no_join: false, no_partner: false, playhead: 30, ..ctx(Lane::V1) }; |
| 258 | assert!(enable(ActionId::Regroup, cut.clone()).yes()); |
| 259 | assert!(enable(ActionId::Group, cut).yes()); |
| 260 | } |
| 261 | |
| 262 | |
| 263 | #[test] |
| 264 | fn every_card_opener_has_a_shortcut() { |
| 265 | let k = keymap::Keymap::defaults(); |
| 266 | for a in [ |
| 267 | ActionId::Speed, ActionId::Color, ActionId::Transform, ActionId::Equalizer, |
| 268 | ActionId::Silence, ActionId::Visualizer, ActionId::Fit, ActionId::Markers, |
| 269 | ActionId::Mix, ActionId::Effects, ActionId::Normalize, ActionId::Captions, |
| 270 | ActionId::Fillers, ActionId::Voiceover, |
| 271 | ] { |
| 272 | assert_ne!(k.display(a), "unbound", "{a:?}"); |
| 273 | assert_ne!(k.display(a), "--", "{a:?}"); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | |
| 278 | #[test] |
| 279 | fn the_palette_uses_the_shared_type_scale() { |
| 280 | let body = fn_body("palette_row"); |
| 281 | assert!(body.contains("type_scale::body_strong()") && body.contains("type_scale::caption()")); |
| 282 | assert!(!body.contains("label(14.") && !body.contains("mono(13.")); |
| 283 | } |
| 284 | |
| 285 | |
| 286 | #[test] |
| 287 | fn the_shortcuts_sheet_has_a_highlighted_tab_and_a_close() { |
| 288 | let src = std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/src/ui/dock_stance.rs")).unwrap(); |
| 289 | assert!(!src.contains(r#"dock_tab("dock-tab-keys""#), "the sheet is a dialog, not a dock tab"); |
| 290 | assert!(!src.contains("dock-keys-close"), "the shell's X is the only close"); |
| 291 | } |
| 292 | |
| 293 | |
| 294 | |
| 295 | #[test] |
| 296 | fn cut_selected_words_and_paste_attributes_have_menu_rows() { |
| 297 | assert_eq!(ActionId::CutSelectedWords.label(), "Cut selected words"); |
| 298 | assert!(Title::Clip.entries().contains(&Entry::Act(ActionId::CutSelectedWords)), "the Clip menu lists the cut"); |
| 299 | let none = enable(ActionId::CutSelectedWords, ctx(Lane::V1)); |
| 300 | assert!(!none.yes(), "no words picked: the cut is dim"); |
| 301 | assert_eq!(none.why(), Some("no transcript words picked")); |
| 302 | assert!(enable(ActionId::CutSelectedWords, Ctx { words: true, ..ctx(Lane::V1) }).yes()); |
| 303 | assert!(Title::Edit.entries().contains(&Entry::Act(ActionId::PasteAttributes)), "Edit lists Paste attributes"); |
| 304 | } |