mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 20:43:18 -05:00
Use regional decimals in remaining UI fixtures
This commit is contained in:
1 parent
2a66d0fe6b
commit
d689f09e46
10 files changed
+18
-10
No files matched your search
@@ -134,7 +134,7 @@ mod tests {
|
||||
let undo = panel.app().session.active().unwrap().history.undo.len();
|
||||
panel.click_role(label, Role::SPIN_BUTTON);
|
||||
panel.key(Key::A, Modifiers::COMMAND);
|
||||
panel.type_text(typed);
|
||||
panel.type_text(&crate::tests::regional_text(typed));
|
||||
panel.frame();
|
||||
let proposed = panel.app().session.tool_options_of(tool);
|
||||
assert_ne!(proposed[key], before[key], "{label} changes while typing");
|
||||
|
||||
@@ -659,7 +659,7 @@ mod cancel_tests {
|
||||
panel.frame();
|
||||
panel.click_role("TL", Role::SPIN_BUTTON);
|
||||
panel.key(Key::A, Modifiers::COMMAND);
|
||||
panel.type_text("4.125");
|
||||
panel.type_text(&crate::tests::regional_text("4.125"));
|
||||
panel.frame();
|
||||
let proposed = panel.app().session.tool_options();
|
||||
assert_ne!(proposed["cornerRadii"], before["cornerRadii"]);
|
||||
|
||||
@@ -257,6 +257,6 @@ fn ruler_labels_carry_the_sign_and_the_steps_decimals() {
|
||||
(1.0, 0.0625, "1"),
|
||||
(1.1875, 0.0625, "1.1875"),
|
||||
] {
|
||||
assert_eq!(x.tick_label(&units, value, step), want, "the tick at {value} of a {step} step");
|
||||
assert_eq!(x.tick_label(&units, value, step), crate::tests::regional_text(want), "the tick at {value} of a {step} step");
|
||||
}
|
||||
}
|
||||
@@ -825,7 +825,7 @@ mod tests {
|
||||
assert_eq!(pending.size_choice, Some(ArtboardSizeChoice::Orientation(true)));
|
||||
panel.click_role(label, Role::SPIN_BUTTON);
|
||||
panel.key(Key::A, Modifiers::COMMAND);
|
||||
panel.type_text(typed);
|
||||
panel.type_text(&crate::tests::regional_text(typed));
|
||||
assert_eq!(actual_value(&panel), pending, "typing must not discard the pending orientation or reference-point policy");
|
||||
panel.key(Key::Escape, Modifiers::NONE);
|
||||
assert!(!is_open(&panel.app()), "Escape discards the modal for {label}");
|
||||
@@ -875,7 +875,7 @@ mod tests {
|
||||
panel.frame();
|
||||
panel.click_role(label, Role::SPIN_BUTTON);
|
||||
panel.key(Key::A, Modifiers::COMMAND);
|
||||
panel.type_text(typed);
|
||||
panel.type_text(&crate::tests::regional_text(typed));
|
||||
if blur {
|
||||
panel.key(Key::Tab, Modifiers::NONE);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ mod tests {
|
||||
for (label, text) in [("Value", typed), ("Variation:", variation)] {
|
||||
panel.click_role(label, Role::SPIN_BUTTON);
|
||||
panel.key(Key::A, Modifiers::COMMAND);
|
||||
panel.type_text(text);
|
||||
panel.type_text(&crate::tests::regional_text(text));
|
||||
panel.key(Key::Escape, Modifiers::NONE);
|
||||
assert!(!panel.app().dialogs().unwrap().with(|host| host.is_open::<HostedParamDialog>()));
|
||||
assert_eq!(panel.app().session.tool_options_of(tool), original, "the canceled {label} leaves the tool unchanged");
|
||||
@@ -143,7 +143,7 @@ mod tests {
|
||||
for (label, text) in [("Value", typed), ("Variation:", variation)] {
|
||||
panel.click_role(label, Role::SPIN_BUTTON);
|
||||
panel.key(Key::A, Modifiers::COMMAND);
|
||||
panel.type_text(text);
|
||||
panel.type_text(&crate::tests::regional_text(text));
|
||||
panel.key(Key::Tab, Modifiers::NONE);
|
||||
}
|
||||
panel.click_role("Mode", Role::COMBO_BOX);
|
||||
|
||||
@@ -203,7 +203,7 @@ fn a_plug_in_effect_s_editor_follows_its_manifest() {
|
||||
}
|
||||
assert!(!panel.shows("spacing") && !panel.shows("width"), "the labels replace the names");
|
||||
let spacing = panel.value_role("Spacing", craft::ui::contract::Role::SPIN_BUTTON);
|
||||
assert!(spacing.as_deref().is_some_and(|v| v.contains("1.5") && v.contains("mm")), "{spacing:?}");
|
||||
assert!(spacing.as_deref().is_some_and(|v| v.contains(&crate::tests::regional_text("1.5")) && v.contains("mm")), "{spacing:?}");
|
||||
assert!(panel.value("Angles").is_some_and(|v| v.contains("45, 135")), "{:?}", panel.value("Angles"));
|
||||
// Without the outline, its width isn't shown.
|
||||
panel.app().run("effect.setParams", json!({"item": null, "index": 0, "params": {"outline": false}})).unwrap();
|
||||
|
||||
@@ -58,6 +58,7 @@ fn bar(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
pub(crate) fn reads(value: Option<String>, unit: Unit, pt: f64) -> bool {
|
||||
value.is_some_and(|v| {
|
||||
let Some(number) = v.strip_suffix(unit.suffix()).map(str::trim_end) else { return false };
|
||||
let number = vectorcraft_doc::decimal_point(number);
|
||||
let decimals = number.split_once('.').map_or(0, |(_, d)| d.len());
|
||||
number.parse::<f64>().is_ok_and(|shown| (shown - unit.from_pt(pt)).abs() <= 0.5 * 10f64.powi(-(decimals as i32)) + 1e-9)
|
||||
})
|
||||
|
||||
@@ -20,7 +20,7 @@ fn pt(v: f64) -> String {
|
||||
|
||||
/// A shown angle, in degrees.
|
||||
fn degrees(p: &Panel, name: &str) -> Option<f64> {
|
||||
p.value(name)?.trim_end_matches('°').trim_end().parse().ok()
|
||||
vectorcraft_doc::parse_number(&vectorcraft_doc::decimal_point(p.value(name)?.trim_end_matches('°').trim_end()))
|
||||
}
|
||||
|
||||
/// The state of panel-menu row `id`, as the panel menus' states give it.
|
||||
|
||||
@@ -67,3 +67,10 @@ mod trace_runs;
|
||||
/// test also installs, or that check how plug-ins sharing a name are told apart, hold this lock
|
||||
/// while their plug-ins are installed, so each sees only its own plug-ins under that name.
|
||||
pub(super) static SHARED_PLUGIN_NAMES: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||
|
||||
/// Formats a decimal fixture with the system region used by the UI.
|
||||
pub(crate) fn regional_text(text: &str) -> String {
|
||||
let decimal = craft::i18n::Format::new(&craft::i18n::Region::system(), craft::i18n::Digits::Latin).number_ungrouped(0.1, 1);
|
||||
let mark = decimal.strip_prefix('0').unwrap().strip_suffix('1').unwrap();
|
||||
text.replace('.', mark)
|
||||
}
|
||||
@@ -1624,7 +1624,7 @@ fn the_smooth_tools_fidelity_label_is_one_line_beside_its_field() {
|
||||
let labels = tree.with_role(craft::ui::contract::Role::LABEL);
|
||||
assert!(labels.iter().any(|key| tree.name_of(*key) == Some("Fidelity:")), "the label is in the access tree");
|
||||
let run = |text: &str| fx.texts().iter().find(|t| t.text == text).cloned().unwrap_or_else(|| panic!("no `{text}` painted"));
|
||||
let (label, value) = (run("Fidelity:"), run("2.50 px"));
|
||||
let (label, value) = (run("Fidelity:"), run(&crate::tests::regional_text("2.50 px")));
|
||||
assert!(label.rect.height() < 2.0 * value.rect.height(), "the label is one line: {:?}", label.rect);
|
||||
assert!((label.baseline - value.baseline).abs() <= 1.0, "the label sits on the field's baseline: {label:?} {value:?}");
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user