mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Test the Delete Anchor Point options bar
This commit is contained in:
1 parent
fdf1daa4b3
commit
19ed458045
3 files changed
+36
-5
No files matched your search
@@ -220,6 +220,9 @@ mod paint_tests;
|
||||
#[cfg(test)]
|
||||
mod add_anchor_options_bar_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod delete_anchor_options_bar_tests;
|
||||
|
||||
pub(crate) use pen::freeform_locked_shape;
|
||||
|
||||
/// Where a Pen draft goes, captured at its first anchor.
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::state::Tool;
|
||||
const NO_OPTIONS: &str = "No options for the Add Anchor Point Tool.";
|
||||
const WIDTH: f32 = 1280.0;
|
||||
|
||||
fn harness(tool: Tool) -> Harness<'static, PhotocraftApp> {
|
||||
pub(super) fn harness(tool: Tool) -> Harness<'static, PhotocraftApp> {
|
||||
let mut s = photocraft_engine::Session::new();
|
||||
s.execute("file.new", json!({"width": 200, "height": 100})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(WIDTH, 800.0)).build_eframe(move |cc| {
|
||||
@@ -28,12 +28,16 @@ fn harness(tool: Tool) -> Harness<'static, PhotocraftApp> {
|
||||
#[test]
|
||||
fn add_anchor_point_bar_says_it_has_no_options() {
|
||||
let h = harness(Tool::AddAnchorPoint);
|
||||
let text = h.get_by_label(NO_OPTIONS);
|
||||
assert!(h.query_by_label_contains("Click a segment to add an anchor point").is_none(), "the Alt hint is gone");
|
||||
// Centred between the preset picker and the bar's right edge; the tolerance covers the bar's padding.
|
||||
assert_centred_after_picker(&h, Tool::AddAnchorPoint, NO_OPTIONS);
|
||||
}
|
||||
|
||||
/// The text is centred between the preset picker and the bar's right edge; the tolerance covers
|
||||
/// the bar's padding.
|
||||
pub(super) fn assert_centred_after_picker(h: &Harness<'static, PhotocraftApp>, tool: Tool, label: &str) {
|
||||
let rect = h.get_by_label(label).rect();
|
||||
// The toolbox has a button of the same name; the bar's picker is the one on the text's row.
|
||||
let rect = text.rect();
|
||||
let picker = h.query_all_by_label(Tool::AddAnchorPoint.label()).map(|n| n.rect()).find(|r| r.y_range().contains(rect.center().y)).unwrap();
|
||||
let picker = h.query_all_by_label(tool.label()).map(|n| n.rect()).find(|r| r.y_range().contains(rect.center().y)).unwrap();
|
||||
let centre = (picker.max.x + WIDTH) / 2.0;
|
||||
let mid = (rect.min.x + rect.max.x) / 2.0;
|
||||
assert!((mid - centre).abs() < 20.0, "text centre {mid} vs remaining bar centre {centre}");
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
//! #12827: the Delete Anchor Point options bar holds the preset picker and "No options for the
|
||||
//! Delete Anchor Point Tool." centred in the rest of the bar, as in Photoshop.
|
||||
|
||||
use egui_kittest::kittest::Queryable;
|
||||
|
||||
use super::add_anchor_options_bar_tests::{assert_centred_after_picker, harness};
|
||||
use crate::state::Tool;
|
||||
|
||||
const NO_OPTIONS: &str = "No options for the Delete Anchor Point Tool.";
|
||||
|
||||
#[test]
|
||||
fn delete_anchor_point_bar_says_it_has_no_options() {
|
||||
let h = harness(Tool::DeleteAnchorPoint);
|
||||
assert!(h.query_by_label_contains("Click an anchor point to delete it").is_none(), "the Alt hint is gone");
|
||||
assert!(h.query_by_label("No options for the Add Anchor Point Tool.").is_none());
|
||||
assert_centred_after_picker(&h, Tool::DeleteAnchorPoint, NO_OPTIONS);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other_pen_group_bars_do_not_say_it() {
|
||||
for tool in [Tool::Pen, Tool::FreeformPen, Tool::CurvaturePen, Tool::AddAnchorPoint, Tool::ConvertPoint] {
|
||||
assert!(harness(tool).query_by_label(NO_OPTIONS).is_none(), "{tool:?}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user