FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Regression tests for #130, #703, #1084 and #1309 (#2861)
skylar taylor-barrickb366ff320555
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex 1d760d0c0..d4742ff59 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -904,7 +904,8 @@ pub fn menu_bar(app: &mut FilmcraftApp, ui: &mut egui::Ui) {let labels = app.session.prefs.labels.clone();let ctx = ui.ctx().clone();let mut clicked: Option<String> = None;- egui::MenuBar::new().config(egui::containers::menu::MenuConfig::new().style(crate::theme::menu_style)).ui(ui, |ui| {+ // The bar's titles and their menus share one size and colour, as in a native menu bar.+ egui::MenuBar::new().style(crate::theme::menu_style).config(egui::containers::menu::MenuConfig::new().style(crate::theme::menu_style)).ui(ui, |ui| {let mut titles = Vec::with_capacity(MENUS.len());for top in MENUS {let mine: Vec<&MenuItem> = items.iter().filter(|i| i.path.first().map(String::as_str) == Some(top)).collect();diff --git a/crates/ui-egui/tests/captions_font_ui.rs b/crates/ui-egui/tests/captions_font_ui.rsindex bd6822d55..877976c74 100644--- a/crates/ui-egui/tests/captions_font_ui.rs+++ b/crates/ui-egui/tests/captions_font_ui.rs@@ -93,3 +93,52 @@ fn caption_font_picker_sets_the_track_font() {d.frames(3);assert_eq!(d.font(track), "Noto Serif");}++/// Every text shape on screen, with the colour of its first run.+fn painted_text(d: &Driver) -> Vec<(String, egui::Color32)> {+ fn walk(s: &egui::Shape, out: &mut Vec<(String, egui::Color32)>) {+ match s {+ egui::Shape::Text(t) => {+ if let Some(sec) = t.galley.job.sections.first() {+ out.push((t.galley.text().to_string(), sec.format.color));+ }+ }+ egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),+ _ => {}+ }+ }+ let mut out = Vec::new();+ d.harness.output().shapes.iter().for_each(|c| walk(&c.shape, &mut out));+ out+}++/// Relative luminance (WCAG) of an opaque colour.+fn luminance(c: egui::Color32) -> f32 {+ let f = |v: u8| {+ let v = v as f32 / 255.0;+ if v <= 0.03928 { v / 12.92 } else { ((v + 0.055) / 1.055).powf(2.4) }+ };+ 0.2126 * f(c.r()) + 0.7152 * f(c.g()) + 0.0722 * f(c.b())+}++// Regression test for #1072: the Captions tab's "Import captions file…" button label was always+// white, so it vanished against the light grey button in light mode.+#[test]+fn import_captions_button_label_is_legible_in_both_themes() {+ let mut d = Driver::demo();+ d.ok("ui.set", json!({"workspace": "Captions and Graphics"}));+ d.ok("ui.click", json!({"id": "text.tab.Captions"}));+ for theme in ["dark", "light"] {+ d.ok("ui.set", json!({"theme": theme}));+ d.frames(3);+ assert!(d.ids("text.captions.import").iter().any(|i| i == "text.captions.import"), "{theme}: the empty Captions tab offers the import button");+ let field_bg = d.harness.state().tokens.field_bg;+ let (_, color) = painted_text(&d)+ .into_iter()+ .find(|(text, _)| text.starts_with("Import captions file"))+ .unwrap_or_else(|| panic!("{theme}: the button label is not drawn"));+ let (hi, lo) = (luminance(color).max(luminance(field_bg)), luminance(color).min(luminance(field_bg)));+ let contrast = (hi + 0.05) / (lo + 0.05);+ assert!(contrast >= 4.5, "{theme}: label {color:?} on {field_bg:?} has contrast {contrast:.2}:1");+ }+}diff --git a/crates/ui-egui/tests/panels_ui.rs b/crates/ui-egui/tests/panels_ui.rsindex 483bee1c9..150f4d0bf 100644--- a/crates/ui-egui/tests/panels_ui.rs+++ b/crates/ui-egui/tests/panels_ui.rs@@ -781,3 +781,74 @@ fn effects_are_indented_under_their_folders() {assert!(b >= a + 12.0, "`{inner}` ({b}) is not indented under `{outer}` ({a})");}}++/// The font of the first run of every text shape drawn this frame, with the text, position and colour.+fn painted_text(d: &Driver) -> Vec<(String, egui::Pos2, egui::FontId, egui::Color32)> {+ fn walk(s: &egui::Shape, out: &mut Vec<(String, egui::Pos2, egui::FontId, egui::Color32)>) {+ match s {+ egui::Shape::Text(t) => {+ if let Some(sec) = t.galley.job.sections.first() {+ out.push((t.galley.text().to_string(), t.pos, sec.format.font_id.clone(), sec.format.color));+ }+ }+ egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),+ _ => {}+ }+ }+ let mut out = Vec::new();+ d.harness.output().shapes.iter().for_each(|c| walk(&c.shape, &mut out));+ out+}++// Regression test for #130: the big blue timecodes over the timeline and under the monitors were+// drawn in 15 pt semibold; Premiere's are regular weight, 16 pt, in the timecode colour.+#[test]+fn big_timecodes_are_regular_weight_16pt_in_the_timecode_colour() {+ let mut d = Driver::demo();+ d.ok("ui.panel.show", json!({"panel": "Program"}));+ d.ok("ui.panel.show", json!({"panel": "ReferenceMonitor"}));+ d.frames(3);+ let timecode = d.app().tokens.timecode;+ for id in ["timeline.timecode", "program.timecode", "reference.timecode"] {+ let rect = {+ let v = d.ok("ui.elements", json!({"prefix": id}));+ let e = v.as_array().unwrap().iter().find(|e| e["id"] == json!(id)).unwrap_or_else(|| panic!("no element {id}")).clone();+ let r = &e["rect"];+ egui::Rect::from_min_size(+ egui::pos2(r[0].as_f64().unwrap() as f32, r[1].as_f64().unwrap() as f32),+ egui::vec2(r[2].as_f64().unwrap() as f32, r[3].as_f64().unwrap() as f32),+ )+ };+ let shown = d.label(id);+ let (_, _, font, color) = painted_text(&d)+ .into_iter()+ .find(|(text, pos, ..)| *text == shown && rect.expand(2.0).contains(*pos))+ .unwrap_or_else(|| panic!("{id}: `{shown}` is not drawn in {rect:?}"));+ assert_eq!(font, egui::FontId::new(16.0, egui::FontFamily::Proportional), "{id}: font");+ assert_eq!(color, timecode, "{id}: colour");+ }+}++// Regression test for #130: the menu bar's menus were drawn in egui's default body size; Premiere's+// are the system's, larger (13 pt) and brighter than panel text.+#[test]+fn menu_bar_menus_use_the_13pt_menu_text() {+ let mut d = Driver::demo();+ d.click("menu.File");+ d.frames(3);+ for id in ["menu.File", "menu.file.open", "menu.file.save", "menu.file.saveAs"] {+ let v = d.ok("ui.elements", json!({"prefix": id}));+ let e = v.as_array().unwrap().iter().find(|e| e["id"] == json!(id)).unwrap_or_else(|| panic!("no menu item {id}")).clone();+ let label = e["label"].as_str().unwrap().to_string();+ let r = &e["rect"];+ let rect = egui::Rect::from_min_size(+ egui::pos2(r[0].as_f64().unwrap() as f32, r[1].as_f64().unwrap() as f32),+ egui::vec2(r[2].as_f64().unwrap() as f32, r[3].as_f64().unwrap() as f32),+ );+ let (_, _, font, _) = painted_text(&d)+ .into_iter()+ .find(|(text, pos, ..)| *text == label && rect.contains(*pos))+ .unwrap_or_else(|| panic!("`{label}` is not drawn in {rect:?}"));+ assert_eq!(font.size, 13.0, "`{label}` in the File menu");+ }+}diff --git a/crates/ui-egui/tests/project_panel_ui.rs b/crates/ui-egui/tests/project_panel_ui.rsindex 87874210f..8fdbb9f0c 100644--- a/crates/ui-egui/tests/project_panel_ui.rs+++ b/crates/ui-egui/tests/project_panel_ui.rs@@ -235,6 +235,59 @@ fn list_view_columns_sort_resize_and_rename() {assert_ne!(d.app().session.project.item(ItemId(items[0])).unwrap().name, "Hero shot");}+// Regression test for #1295: in a narrow List-view column the sort arrow was painted over the end of+// the (clipped) column name; the name must be clipped to the left of the arrow.+#[test]+fn sorted_column_header_name_is_clipped_clear_of_the_sort_arrow() {+ fn collect<'a>(shapes: &'a [egui::Shape], clip: egui::Rect, out: &mut Vec<(&'a egui::Shape, egui::Rect)>) {+ for s in shapes {+ match s {+ egui::Shape::Vec(v) => collect(v, clip, out),+ other => out.push((other, clip)),+ }+ }+ }+ let mut d = project_driver();+ d.exec("project.view.set", json!({"view": "list"}));+ d.frames(2);+ // the default sort is by Name; make that column narrow enough that its name is clipped+ for c in &mut d.app().session.prefs.project_panel.view.columns {+ if c.name == "Name" {+ c.width = 40.0;+ }+ }+ d.frames(3);+ assert_eq!(d.app().session.prefs.project_panel.view.sort.column, "Name");+ let [hx, hy, hw, hh] = d.rect("project.list.header.Name");+ let header = egui::Rect::from_min_size(egui::pos2(hx, hy), egui::vec2(hw, hh));+ let mut all = Vec::new();+ let clipped: Vec<_> = d.harness.output().shapes.iter().map(|c| (c.shape.clone(), c.clip_rect)).collect();+ for (shape, clip) in &clipped {+ collect(std::slice::from_ref(shape), *clip, &mut all);+ }+ // the visible part of the name: the clip rect of the header's "Name" text+ let name_clip = all+ .iter()+ .find_map(|(s, clip)| match s {+ egui::Shape::Text(t) if t.galley.text() == "Name" && header.contains(t.pos) => Some(*clip),+ _ => None,+ })+ .expect("the Name header text is drawn");+ // the arrow: the 1.3 px strokes drawn inside the header+ let arrow_x: Vec<f32> = all+ .iter()+ .filter_map(|(s, _)| match s {+ egui::Shape::LineSegment { points, stroke } if (stroke.width - 1.3).abs() < 1e-3 && header.contains(points[0]) && header.contains(points[1]) => {+ Some(points[0].x.min(points[1].x))+ }+ _ => None,+ })+ .collect();+ assert!(!arrow_x.is_empty(), "the sort arrow is drawn in the sorted column's header");+ let arrow_left = arrow_x.into_iter().fold(f32::MAX, f32::min);+ assert!(name_clip.max.x <= arrow_left, "the name is visible up to x={} but the sort arrow starts at x={arrow_left}", name_clip.max.x);+}+#[test]fn icon_view_hover_scrub_sets_in_and_out() {let mut d = project_driver();diff --git a/crates/ui-egui/tests/timeline_track_height_ui.rs b/crates/ui-egui/tests/timeline_track_height_ui.rsindex eb272be4b..53e54c6c9 100644--- a/crates/ui-egui/tests/timeline_track_height_ui.rs+++ b/crates/ui-egui/tests/timeline_track_height_ui.rs@@ -112,3 +112,83 @@ fn the_bottom_edge_of_the_last_audio_track_resizes_the_audio_tracks_from_either_d.drag(&id, 0.1, -15.0);assert!(d.heights().1 < a1 - 5.0);}++/// Every shape drawn this frame, flattened.+fn flat_shapes(d: &Driver) -> Vec<egui::Shape> {+ fn walk(s: &egui::Shape, out: &mut Vec<egui::Shape>) {+ match s {+ egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),+ other => out.push(other.clone()),+ }+ }+ let mut out = Vec::new();+ d.harness.output().shapes.iter().for_each(|c| walk(&c.shape, &mut out));+ out+}++fn rect_of(d: &mut Driver, id: &str) -> egui::Rect {+ let v = d.ok("ui.elements", json!({"prefix": id}));+ let e = v.as_array().unwrap().iter().find(|e| e["id"] == json!(id)).unwrap_or_else(|| panic!("no element {id}")).clone();+ let r: Vec<f32> = e["rect"].as_array().unwrap().iter().map(|n| n.as_f64().unwrap() as f32).collect();+ egui::Rect::from_min_size(egui::pos2(r[0], r[1]), egui::vec2(r[2], r[3]))+}++// Regression test for #703: the lines between the timeline's tracks were drawn in the timeline's own+// background colour, so they were invisible, and nothing marked the top of the highest video track.+#[test]+fn timeline_draws_visible_lines_between_tracks_and_above_the_top_video_track() {+ let mut d = Driver::demo();+ let (top, _) = d.labels();+ let separator = d.app().tokens.separator;+ let ruler = rect_of(&mut d, "timeline.ruler");+ let top_edge = rect_of(&mut d, &format!("timeline.track.{top}.resizeTop"));+ let seq = d.app().session.active_sequence().unwrap();+ let tracks = seq.video_tracks.len() + seq.audio_tracks.len();+ // horizontal separator lines across the track area (the headers' own lines start left of the ruler)+ let mut ys: Vec<f32> = flat_shapes(&d)+ .into_iter()+ .filter_map(|s| match s {+ egui::Shape::LineSegment { points, stroke }+ if stroke.color == separator+ && points[0].y == points[1].y+ && points[0].x >= ruler.min.x - 1.0+ && points[1].x - points[0].x > 200.0+ && points[0].y > ruler.max.y =>+ {+ Some(points[0].y)+ }+ _ => None,+ })+ .collect();+ ys.sort_by(f32::total_cmp);+ ys.dedup_by(|a, b| (*a - *b).abs() < 0.1);+ assert!(ys.len() > tracks, "a line under each of the {tracks} tracks and one above the top video track, found {ys:?}");+ let first = ys[0];+ assert!((first - top_edge.center().y).abs() < 1.5, "the first line ({first}) is at the top edge of the highest video track ({})", top_edge.center().y);+}++// Regression test for #703: the playhead's head spanned the whole ruler and covered the markers and+// the timecode labels; it must be a short head on the tick row at the bottom of the ruler.+#[test]+fn playhead_head_is_short_and_sits_on_the_ruler_tick_row() {+ let mut d = Driver::demo();+ let playhead = d.app().tokens.playhead;+ let ruler = rect_of(&mut d, "timeline.ruler");+ let heads: Vec<egui::Rect> = flat_shapes(&d)+ .into_iter()+ .filter_map(|s| match s {+ egui::Shape::Path(p) if p.fill == playhead && p.points.len() == 5 => Some(egui::Rect::from_points(&p.points)),+ _ => None,+ })+ .filter(|r| r.max.y <= ruler.max.y + 1.0 && r.min.y >= ruler.min.y)+ .collect();+ assert_eq!(heads.len(), 1, "one playhead head over the ruler: {heads:?}");+ let head = heads[0];+ assert!(head.height() <= 14.0, "the head is {} tall, ruler is {}", head.height(), ruler.height());+ assert!(+ head.min.y >= ruler.max.y - 14.0,+ "the head starts at y={}, leaving the ruler's marker and label rows (above y={}) clear",+ head.min.y,+ ruler.max.y - 14.0+ );+}