Skip to content

Commit 035c100

Browse files
committed
Capture the viewport, the picker, the Assets panel and the orb under each starter environment
An ignored snapshot test reads the starter folder named in TEXTURECRAFT_STARTER_ASSETS and writes the viewport under every installed environment (the sample material, then a smooth white metal), the Environment Map picker with a tile hovered, the Assets panel's Environments type and the Properties orb; TC_UI_THEMES adds the dark and light themes.
1 parent bd296e9 commit 035c100

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

‎crates/ui-egui/tests/ui_snapshots.rs‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,3 +3697,105 @@ fn export_window_snapshots() {
36973697
harness.state_mut().ui.export.tab = 2;
36983698
save(&mut harness, &output_dir, &format!("ep-list-{theme}"));
36993699
}
3700+
3701+
/// The Assets panel's Environments type, as an index into its type row
3702+
const ENVIRONMENTS_TYPE: usize = 7;
3703+
3704+
/// How long a picked environment gets to be read, filtered on its worker and uploaded before the viewport is captured
3705+
const ENVIRONMENT_SETTLE: std::time::Duration = std::time::Duration::from_secs(6);
3706+
3707+
/// Frames until the viewport shows `environment`: each frame is rendered, since the renderer takes a filtered environment in the frame that hands it over
3708+
fn show_environment(harness: &mut Harness<'_, TextureCraftApp>, environment: &str) {
3709+
harness.state_mut().run("display.set", serde_json::json!({"environment": environment})).unwrap();
3710+
let start = std::time::Instant::now();
3711+
while start.elapsed() < ENVIRONMENT_SETTLE {
3712+
harness.run_steps(1);
3713+
harness.render().unwrap();
3714+
std::thread::sleep(std::time::Duration::from_millis(20));
3715+
}
3716+
}
3717+
3718+
/// Built-in environments read from the starter folder in `TEXTURECRAFT_STARTER_ASSETS`: the viewport under each (the sample material, then a smooth white metal), the Environment Map picker (a tile hovered), the Assets panel's Environments type and the Properties material orb; `TC_UI_THEMES` adds dark and light
3719+
#[test]
3720+
#[ignore]
3721+
fn starter_environment_snapshots() {
3722+
use serde_json::json;
3723+
use texturecraft_engine::core::starter_environment::STARTER_ENVIRONMENTS;
3724+
use texturecraft_engine::execute;
3725+
3726+
let Some(output_dir) = std::env::var_os("TC_UI_SNAPSHOTS").map(PathBuf::from) else { return };
3727+
let Some(starter_dir) = std::env::var_os(texturecraft_engine::starter_environment_loader::STARTER_ASSETS_VARIABLE).map(PathBuf::from) else { return };
3728+
std::fs::create_dir_all(&output_dir).unwrap();
3729+
let mut session = texturecraft_engine::sample_session(256, 64).unwrap();
3730+
session.starter_dir = Some(starter_dir.clone());
3731+
let installed: Vec<_> =
3732+
STARTER_ENVIRONMENTS.iter().filter(|entry| texturecraft_engine::starter_environment_loader::environment_path(&starter_dir, entry).is_file()).collect();
3733+
assert!(!installed.is_empty(), "no starter environment in {}", starter_dir.display());
3734+
let mut harness = Harness::builder()
3735+
.with_size(egui::vec2(1600.0, 960.0))
3736+
.with_pixels_per_point(1.0)
3737+
.with_render_cursor(false)
3738+
.wgpu()
3739+
.with_context_setup(texturecraft_ui_egui::framework::install_headless)
3740+
.build_eframe(|context| TextureCraftApp::new(context, session));
3741+
harness.state_mut().ui.prefs.language = "en".into();
3742+
harness.run_steps(4);
3743+
let viewport = harness.state().viewport_rect;
3744+
std::fs::write(output_dir.join("viewport-rect.txt"), format!("{} {} {} {}", viewport.min.x, viewport.min.y, viewport.max.x, viewport.max.y)).unwrap();
3745+
3746+
for (index, entry) in installed.iter().enumerate() {
3747+
show_environment(&mut harness, entry.name);
3748+
save(&mut harness, &output_dir, &format!("env-sample-{index:02}"));
3749+
}
3750+
3751+
// A smooth white metal on top shows how sharp and how bright each environment's reflections are
3752+
let layer = harness.state_mut().run("layer.add.fill", json!({"color": [0.9, 0.9, 0.9]})).unwrap()["layer"].as_u64().unwrap();
3753+
for (channel, value) in [("metallic", 1.0), ("roughness", 0.2)] {
3754+
let session = &mut harness.state_mut().session;
3755+
execute(session, "layer.fill.set", &json!({"layer": layer, "channel": channel, "enabled": true})).unwrap();
3756+
execute(session, "layer.fill.set", &json!({"layer": layer, "channel": channel, "value": value})).unwrap();
3757+
}
3758+
for (index, entry) in installed.iter().enumerate() {
3759+
show_environment(&mut harness, entry.name);
3760+
save(&mut harness, &output_dir, &format!("env-metal-{index:02}"));
3761+
}
3762+
std::fs::write(output_dir.join("environments.txt"), installed.iter().map(|entry| entry.name).collect::<Vec<_>>().join("\n")).unwrap();
3763+
3764+
// Every installed environment's thumbnail, for the picker and the Assets panel
3765+
let context = harness.ctx.clone();
3766+
let start = std::time::Instant::now();
3767+
while !installed.iter().all(|entry| harness.state_mut().thumbs.starter_environment(&context, entry, &starter_dir).is_some()) {
3768+
assert!(start.elapsed() < std::time::Duration::from_secs(120), "starter environment thumbnails did not arrive");
3769+
harness.run_steps(1);
3770+
std::thread::sleep(std::time::Duration::from_millis(20));
3771+
}
3772+
3773+
let mut themes = vec![(Brightness::MediumDark, "medium")];
3774+
if std::env::var_os("TC_UI_THEMES").is_some() {
3775+
themes.extend([(Brightness::Dark, "dark"), (Brightness::Light, "light")]);
3776+
}
3777+
// The first one: the picker's own tile (the slot shows the last one, and the Assets panel is switched away from environments)
3778+
let hovered = installed[0].name;
3779+
for (brightness, theme) in themes {
3780+
harness.state_mut().ui.prefs.brightness = brightness;
3781+
harness.state_mut().ui.shelf_tab = ENVIRONMENTS_TYPE;
3782+
harness.hover_at(AWAY_FROM_TILES);
3783+
save(&mut harness, &output_dir, &format!("env-shelf-{theme}"));
3784+
3785+
if let Some(tab) = harness.query_by_role_and_label(egui::Role::Tab, "Material") {
3786+
tab.click();
3787+
}
3788+
save(&mut harness, &output_dir, &format!("env-properties-orb-{theme}"));
3789+
3790+
harness.state_mut().ui.shelf_tab = 0;
3791+
harness.state_mut().ui.dock.focus(Panel::Display);
3792+
harness.run_steps(3);
3793+
let current = harness.state().session.doc.project.display.environment.clone();
3794+
harness.get_by_role_and_label(egui::Role::Button, &current).click();
3795+
harness.run_steps(3);
3796+
harness.get_by_role_and_label(egui::Role::Button, hovered).hover();
3797+
save_with_pointer(&mut harness, &output_dir, &format!("env-picker-{theme}"));
3798+
harness.key_press(egui::Key::Escape);
3799+
harness.run_steps(3);
3800+
}
3801+
}

0 commit comments

Comments
 (0)