Tooling · Workbench: the knobs seed the settings; knobs checked

The knobs join a layout::seeded seed, so a changed starting value,
option list or range starts every setting over, and a renamed knob
no longer fails. new() refuses no knobs, twin names and a number
outside its range. Controls are keyed by knob name. The test presses
keys without a refresh, so only a notify redraws, and walks the
switch twice, the slider twice and a pick the owner takes away.
This commit is contained in:
ZacharyZhang-NY committed 2026-09-28 06:37:06 -04:00
1 parent 1dbdafd056
commit 8c038e2c24
2 files changed
+129 -42

No files matched your search

+43 -9
View File
@@ -3,6 +3,8 @@ use gpui::{
ParentElement, Render, Styled, TestAppContext, VisualTestContext, Window, div, px,
};
use std::cell::Cell;
use super::{Knob, Playground};
use crate::{
forms,
@@ -23,6 +25,10 @@ impl Render for Stage {
}
}
thread_local! {
static LARGE: Cell<bool> = const { Cell::new(true) };
}
fn playground() -> AnyElement {
Playground::new(
"playground",
@@ -30,14 +36,17 @@ fn playground() -> AnyElement {
Knob::Toggle("disabled".into(), false),
Knob::Choice(
"size".into(),
vec!["Sm".into(), "Md".into(), "Lg".into()],
["Sm", "Md", "Lg"][..2 + usize::from(LARGE.get())]
.iter()
.map(|size| (*size).into())
.collect(),
1,
),
Knob::Number("share".into(), 0.4, (0.0, 1.0), 0.1),
Knob::Number("share".into(), 0.5, (0.0, 1.0), 0.25),
],
|settings, _, _| {
let shown = format!(
"preview-{}-{}-{:.1}",
"preview-{}-{}-{:.2}",
settings.on("disabled"),
settings.picked("size"),
settings.number("share")
@@ -56,13 +65,14 @@ fn settle(cx: &mut VisualTestContext) {
cx.run_until_parked();
}
/// Presses a key with no refresh of its own, so only what notifies redraws.
fn press(key: &str, cx: &mut VisualTestContext) {
cx.simulate_keystrokes(key);
settle(cx);
cx.run_until_parked();
cx.simulate_event(KeyUpEvent {
keystroke: Keystroke::parse(key).expect("a key"),
});
settle(cx);
cx.run_until_parked();
}
/// Each knob's edit redraws the preview with the new settings.
@@ -84,16 +94,40 @@ fn knobs_redraw_the_preview(cx: &mut TestAppContext) {
settle(cx);
let shown =
|selector: &'static str, cx: &mut VisualTestContext| cx.debug_bounds(selector).is_some();
assert!(shown("preview-false-Md-0.4", cx));
assert!(shown("preview-false-Md-0.50", cx));
press("tab", cx);
press("space", cx);
assert!(shown("preview-true-Md-0.4", cx), "the switch turned");
assert!(shown("preview-true-Md-0.50", cx), "the switch turned");
press("tab", cx);
for key in ["down", "down", "enter"] {
press(key, cx);
}
assert!(shown("preview-true-Lg-0.4", cx), "the choice moved");
assert!(shown("preview-true-Lg-0.50", cx), "the choice moved");
press("tab", cx);
press("right", cx);
assert!(shown("preview-true-Lg-0.5", cx), "the number stepped");
press("right", cx);
assert!(
shown("preview-true-Lg-1.00", cx),
"the number stepped twice"
);
assert!(
shown("knob-readout-share-1.00", cx),
"its readout in the step's places"
);
press("shift-tab", cx);
press("shift-tab", cx);
press("space", cx);
assert!(
shown("preview-false-Lg-1.00", cx),
"the switch showed its own setting, so a second press turned it back"
);
LARGE.set(false);
settle(cx);
press("tab", cx);
press("tab", cx);
press("right", cx);
assert!(
shown("preview-false-Md-0.75", cx),
"the owner took away the picked size, so every setting started over"
);
}