forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

menu_wire.rs304 lines, 12.5 KiBHistoryRawDownload
1//! The click -> action path of every menu, and the invariants that keep a
2//! card, a menu or a lost focus from leaving the room dead. This binary has no
3//! `TestAppContext` to mount a `Player` in, so the row-by-row walk runs the
4//! oracle over a project with media and a clip selected (the same answer the
5//! menus draw their rows by) and scans the wiring that turns a click into the
6//! action, the way the neighbouring guards do.
7
8use super::*;
9use crate::ui::menubar::{Entry, Title};
10use keymap::ActionId;
11
12/// A clip on V1, frames 30..90, the one every row is asked about.
13fn 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/// A project with media, a clip selected on `lane`, something on the
47/// clipboard and history on both sides.
48fn 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/// Every row any menu can draw: the six bar menus, the clip menu, the ruler
62/// menu, the dock's body menu and both kinds of lane head.
63fn 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/// Every row either runs or says why it cannot: an enabled row has an arm in
90/// the one action table (so the click reaches a verb, not a fall-through), a
91/// disabled one carries its reason, and a hidden one is simply not drawn.
92#[test]
93fn 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/// The rows that open a card, from every door, are the ones the dock tab
120/// follows: each is a real action with a card verb behind it.
121#[test]
122fn 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 // Every menu that offers a card is one of the doors.
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 // One invariant for all of them: a card up means the Clip tab shows.
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/// Every check mark reads the state its action flips.
160#[test]
161fn 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/// Undo and Redo dim with nothing to take back or walk forward, in the menu,
178/// the toolbar and the palette alike (they all ask `enable`).
179#[test]
180fn 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/// A docked card is not an invisible modal: a right-click on the bench
192/// opens its menu and leaves the card up, and the transport keys keep their meaning.
193#[test]
194fn 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 // The keys keep their meaning while only a docked card shows: that is a card up that does
206 // not cover the room, and not the Export tab.
207 let docked = fn_body("docked_card_only");
208 assert!(docked.contains("!self.covers_room()") && docked.contains("!self.export_open"), "{docked}");
209}
210
211/// The focus invariant: whatever closes, the room's keys keep a home. A check
212/// after every frame puts focus back on the root when the focused handle is no
213/// longer in the tree.
214#[test]
215fn 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/// The clip menu's Adjust submenu carries the Effects opener, and the row walk
224/// above reaches it through MENU_ITEMS.
225#[test]
226fn 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/// A bar dropdown taller than the window (the Clip menu) scrolls inside its
233/// plate, capped by the viewport height, instead of hanging off the bottom.
234#[test]
235fn 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/// N3: Ungroup, Regroup and a lone Group dim, with a reason, on a clip with no
242/// group mate, no cut under the playhead and no partner on another track.
243#[test]
244fn 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/// Item 17: every card opener has a chord, and no two share one.
263#[test]
264fn 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/// Item 29: the palette sets its text on the shared scale.
278#[test]
279fn 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/// Item 16: the shortcuts sheet is a dialog; the kit shell's X closes it.
286#[test]
287fn 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/// The transcript's cut is a Clip row with its own name, and it says what it needs (a picked word)
294/// when none is picked. Paste attributes, the chord with no row of its own, is a row of Edit.
295#[test]
296fn 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}