mirror of
https://github.com/tobi/disktree.git
synced 2026-11-29 08:00:52 +00:00
Four window tests built a local fixture, set app.remote, then looked up the fixture's own paths. On Windows those are C:\ paths, which a Unix host never sends and POSIX rules do not resolve. remote_view_over roots the scanned fixture at the temporary directory on Unix, keeping the nothing-deleted checks real, and at /srv/fixture on Windows.
2451 lines
84 KiB
Rust
2451 lines
84 KiB
Rust
//! End-to-end tests through the real window harness.
|
|
//!
|
|
//! These drive the application the way a person does — draw a frame, press
|
|
//! keys, type — so they catch what unit tests on the state cannot: a screen
|
|
//! that panics while painting, a binding that never fires, a removal that
|
|
//! reports success without removing anything.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use disktree_core::path_style::PathStyle;
|
|
use disktree_core::removal::RemovalMode;
|
|
use disktree_core::scan::{ScanOptions, scan};
|
|
use disktree_core::space::{SpaceInfo, Volume};
|
|
use disktree_core::treemap::Tile;
|
|
use gpui_kit::{
|
|
Bounds, Context, Entity, Pixels, Point, TestAppContext, VisualTestContext,
|
|
px,
|
|
};
|
|
use gpui_omarchy::Theme;
|
|
|
|
use crate::state::{Disktree, Screen};
|
|
|
|
/// A small tree on disk: two directories, a nested file, and a hidden one.
|
|
///
|
|
/// The hidden directory holds the largest file, which is both the common case
|
|
/// in a home directory and the one the ranking has to get right.
|
|
fn fixture() -> tempfile::TempDir {
|
|
let temp = tempfile::TempDir::new().expect("tempdir");
|
|
let root = temp.path();
|
|
for (path, bytes) in [
|
|
("keep/notes.txt", 1_000_usize),
|
|
("junk/blob.bin", 200_000),
|
|
("junk/deeper/more.bin", 100_000),
|
|
(".cache/blob.bin", 300_000),
|
|
] {
|
|
let file = root.join(path);
|
|
std::fs::create_dir_all(file.parent().expect("parent")).expect("mkdir");
|
|
std::fs::write(&file, vec![b'x'; bytes]).expect("write");
|
|
}
|
|
temp
|
|
}
|
|
|
|
/// Apparent sizes, so the assertions are about the tree and not about how the
|
|
/// filesystem rounds a small file up to a block.
|
|
fn options() -> ScanOptions {
|
|
ScanOptions {
|
|
apparent_size: true,
|
|
..ScanOptions::default()
|
|
}
|
|
}
|
|
|
|
type Window = VisualTestContext;
|
|
|
|
/// Open a window over a real scan of `root`, without the background walk.
|
|
fn view_over<'a>(
|
|
root: &Path,
|
|
cx: &'a mut TestAppContext,
|
|
) -> (Entity<Disktree>, &'a mut Window) {
|
|
let tree = scan(root, options()).expect("scan the fixture");
|
|
let root_path = root.to_path_buf();
|
|
let (view, cx) = cx.add_window_view(move |_, cx| {
|
|
Disktree::with_tree(root_path.clone(), tree, options(), 3, cx)
|
|
});
|
|
let focus = view.read_with(cx, |app, _| app.focus.clone());
|
|
cx.update(|window, cx| window.focus(&focus, cx));
|
|
(view, cx)
|
|
}
|
|
|
|
/// The fixture as an SSH session holds it. Remote paths are POSIX on every
|
|
/// client, so the root must be `/`-rooted: the temporary directory itself on
|
|
/// Unix, which keeps "nothing on disk changed" checks meaningful, and a Unix
|
|
/// path on Windows, whose temporary directory is `C:\…`.
|
|
fn remote_view_over<'a>(
|
|
temp: &Path,
|
|
cx: &'a mut TestAppContext,
|
|
) -> (Entity<Disktree>, &'a mut Window, PathBuf) {
|
|
let root = if cfg!(unix) {
|
|
temp.to_path_buf()
|
|
} else {
|
|
PathBuf::from("/srv/fixture")
|
|
};
|
|
let tree = scan(temp, options()).expect("scan the fixture");
|
|
let root_path = root.clone();
|
|
let (view, cx) = cx.add_window_view(move |_, cx| {
|
|
Disktree::with_tree(root_path.clone(), tree, options(), 3, cx)
|
|
});
|
|
let focus = view.read_with(cx, |app, _| app.focus.clone());
|
|
cx.update(|window, cx| window.focus(&focus, cx));
|
|
(view, cx, root)
|
|
}
|
|
|
|
fn draw(cx: &mut Window) {
|
|
cx.update(|window, cx| {
|
|
window.draw(cx).clear(cx);
|
|
});
|
|
}
|
|
|
|
fn press(cx: &mut Window, keys: &str) {
|
|
cx.simulate_keystrokes(keys);
|
|
draw(cx);
|
|
}
|
|
|
|
fn update<R>(
|
|
view: &Entity<Disktree>,
|
|
cx: &mut Window,
|
|
f: impl FnOnce(&mut Disktree, &mut Context<'_, Disktree>) -> R,
|
|
) -> R {
|
|
view.update(cx, f)
|
|
}
|
|
|
|
fn read<R>(
|
|
view: &Entity<Disktree>,
|
|
cx: &Window,
|
|
f: impl FnOnce(&Disktree) -> R,
|
|
) -> R {
|
|
view.read_with(cx, |app, _| f(app))
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn remote_indexing_draws_live_activity_and_the_sampled_directory(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
update(&view, cx, |app, _| {
|
|
app.tree = None;
|
|
app.remote = Some("fixture-only".into());
|
|
app.scan = Some(disktree_core::scan::ScanHandle::spawn(
|
|
temp.path().into(),
|
|
options(),
|
|
));
|
|
app.scan_started = Some(std::time::Instant::now());
|
|
app.progress.files = 1234;
|
|
app.progress.bytes = 123_456;
|
|
app.remote_progress.stage =
|
|
disktree_core::remote_progress::Stage::Indexing;
|
|
app.remote_progress.directory = Some(temp.path().join("junk/deeper"));
|
|
});
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("indexing-progress").is_some());
|
|
assert!(cx.debug_bounds("scan-directory").is_some());
|
|
update(&view, cx, |app, _| {
|
|
app.scan_error = Some("fixture scan failed".into());
|
|
});
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("scan-error").is_some());
|
|
assert!(cx.debug_bounds("scan-reading").is_none());
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn loading_values_and_paths_do_not_move_the_sidebar(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
update(&view, cx, |app, _| {
|
|
app.tree = None;
|
|
app.scan = Some(disktree_core::scan::ScanHandle::spawn(
|
|
temp.path().into(),
|
|
options(),
|
|
));
|
|
app.scan_preview =
|
|
Some(std::sync::Arc::new(disktree_core::scan_preview::Preview {
|
|
entries: vec![disktree_core::scan_preview::Entry {
|
|
name: "junk".into(),
|
|
bytes: 100,
|
|
files: 1,
|
|
}],
|
|
directory: Some(temp.path().join("short")),
|
|
}));
|
|
});
|
|
draw(cx);
|
|
draw(cx);
|
|
let panel = cx.debug_bounds("indexing-progress").unwrap();
|
|
let files = cx.debug_bounds("indexing-files").unwrap();
|
|
let path = cx.debug_bounds("scan-directory").unwrap();
|
|
assert!(cx.debug_bounds("scan-preview").is_some());
|
|
assert!(cx.debug_bounds("scan-reading").is_none());
|
|
update(&view, cx, |app, _| {
|
|
app.progress.files = 99_999_999;
|
|
app.progress.bytes = u64::MAX / 2;
|
|
app.remote = Some("fixture-only".into());
|
|
app.remote_progress.directory = Some(PathBuf::from(
|
|
"/a/very/long/directory/whose/text/must/not/move/the/layout",
|
|
));
|
|
});
|
|
draw(cx);
|
|
assert_eq!(panel, cx.debug_bounds("indexing-progress").unwrap());
|
|
assert_eq!(files, cx.debug_bounds("indexing-files").unwrap());
|
|
assert_eq!(path, cx.debug_bounds("scan-directory").unwrap());
|
|
let preview = cx.debug_bounds("scan-preview").unwrap();
|
|
cx.simulate_click(preview.center(), gpui_kit::Modifiers::none());
|
|
press(cx, "space");
|
|
read(&view, cx, |app| {
|
|
assert!(app.marks.is_empty());
|
|
assert!(app.tree.is_none());
|
|
});
|
|
update(&view, cx, Disktree::cancel_scan);
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("scan-preview").is_none());
|
|
assert!(read(&view, cx, |app| app.scan_preview.is_none()));
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn narrow_indexing_keeps_a_preview_and_compact_progress_in_bounds(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
update(&view, cx, |app, _| {
|
|
app.tree = None;
|
|
app.scan = Some(disktree_core::scan::ScanHandle::spawn(
|
|
temp.path().into(),
|
|
options(),
|
|
));
|
|
app.scan_preview =
|
|
Some(std::sync::Arc::new(disktree_core::scan_preview::Preview {
|
|
entries: vec![disktree_core::scan_preview::Entry {
|
|
name: "junk".into(),
|
|
bytes: 100,
|
|
files: 1,
|
|
}],
|
|
directory: None,
|
|
}));
|
|
});
|
|
cx.simulate_resize(gpui_kit::size(px(900.), px(600.)));
|
|
cx.update(|window, _| window.set_rem_size(px(28.)));
|
|
draw(cx);
|
|
draw(cx);
|
|
let compact = cx.debug_bounds("indexing-compact").unwrap();
|
|
assert!(compact.origin.x >= px(0.) && compact.right() <= px(900.));
|
|
assert!(compact.origin.y >= px(0.) && compact.bottom() <= px(600.));
|
|
let preview = cx.debug_bounds("scan-preview").unwrap();
|
|
assert!(preview.size.height > px(50.), "{preview:?}");
|
|
assert!(preview.bottom() <= compact.origin.y, "{preview:?}");
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn startup_chooser_never_scans_before_explicit_acceptance(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let (view, cx) =
|
|
cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));
|
|
cx.run_until_parked();
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("choose-root-idle").is_some());
|
|
assert!(cx.debug_bounds("source-host").is_some());
|
|
read(&view, cx, |app| {
|
|
assert!(app.awaiting_root);
|
|
assert_eq!(app.scan_epoch, 0);
|
|
assert!(app.scan.is_none() && app.remote_scan.is_none());
|
|
});
|
|
press(cx, "escape");
|
|
assert!(!read(&view, cx, |app| app.volumes_open));
|
|
press(cx, "r");
|
|
assert!(read(&view, cx, |app| app.volumes_open
|
|
&& app.awaiting_root
|
|
&& app.scan.is_none()));
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn entering_a_directory_scans_only_that_explicit_root(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let selected = fixture();
|
|
let other = fixture();
|
|
let (view, cx) =
|
|
cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));
|
|
cx.run_until_parked();
|
|
update(&view, cx, |app, _| {
|
|
app.volumes = vec![Volume {
|
|
point: other.path().into(),
|
|
device: None,
|
|
space: None,
|
|
}];
|
|
app.volumes_loading = false;
|
|
});
|
|
draw(cx);
|
|
let input = cx.debug_bounds("source-path").expect("path editor");
|
|
cx.simulate_click(input.center(), gpui_kit::Modifiers::none());
|
|
cx.simulate_input(selected.path().to_str().unwrap());
|
|
assert_eq!(
|
|
update(&view, cx, |app, cx| app
|
|
.picker_path
|
|
.as_ref()
|
|
.unwrap()
|
|
.read(cx)
|
|
.value()
|
|
.to_string()),
|
|
selected.path().to_str().unwrap()
|
|
);
|
|
press(cx, "enter");
|
|
assert_eq!(
|
|
read(&view, cx, |app| app.root_path.clone()),
|
|
dunce::canonicalize(selected.path()).unwrap()
|
|
);
|
|
assert!(!read(&view, cx, |app| app.awaiting_root || app.volumes_open));
|
|
finish_scan(&view, cx);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn invalid_ssh_input_does_not_start_a_scan_or_change_the_source(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let (view, cx) =
|
|
cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));
|
|
cx.run_until_parked();
|
|
draw(cx);
|
|
let input = cx.debug_bounds("source-host").expect("host editor");
|
|
cx.simulate_click(input.center(), gpui_kit::Modifiers::none());
|
|
cx.simulate_input("invalid host");
|
|
press(cx, "enter");
|
|
read(&view, cx, |app| {
|
|
assert!(app.volumes_error.is_some());
|
|
assert!(app.remote.is_none());
|
|
assert!(app.scan.is_none() && app.remote_scan.is_none());
|
|
assert_eq!(app.scan_epoch, 0);
|
|
});
|
|
press(cx, "escape");
|
|
assert!(!read(&view, cx, |app| app.volumes_open));
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn switching_from_remote_to_local_clears_machine_specific_marks(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let target = fixture();
|
|
let (view, cx, root) = remote_view_over(temp.path(), cx);
|
|
let junk = PathStyle::Posix.join(&root, "junk");
|
|
update(&view, cx, |app, cx| {
|
|
app.remote = Some("old-source".into());
|
|
app.remote_identity = Some(disktree_core::identity::HostIdentity {
|
|
hostname: "old-source".into(),
|
|
machine_id: None,
|
|
});
|
|
let crumbs = app.crumbs_for_path(&junk).unwrap();
|
|
app.select(Some(crumbs), cx);
|
|
app.toggle_mark_selected(cx);
|
|
assert!(!app.marks.is_empty());
|
|
app.volumes_open = true;
|
|
app.volumes_source = None;
|
|
app.choose_source_root(target.path().to_path_buf(), cx);
|
|
assert!(app.remote.is_none() && app.remote_identity.is_none());
|
|
assert!(app.marks.is_empty());
|
|
assert!(app.tree.is_none());
|
|
});
|
|
finish_scan(&view, cx);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn chooser_fits_a_small_window_at_large_interface_zoom(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let (_, cx) =
|
|
cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));
|
|
cx.run_until_parked();
|
|
cx.simulate_resize(gpui_kit::size(px(900.), px(600.)));
|
|
for rem in [16., 28.] {
|
|
cx.update(|window, _| window.set_rem_size(px(rem)));
|
|
draw(cx);
|
|
let bounds = cx
|
|
.debug_bounds("source-picker")
|
|
.expect("scrollable chooser");
|
|
assert!(bounds.size.width > px(200.), "{bounds:?}");
|
|
assert!(
|
|
bounds.origin.x >= px(0.) && bounds.right() <= px(900.),
|
|
"{bounds:?}"
|
|
);
|
|
assert!(
|
|
bounds.origin.y >= px(0.) && bounds.bottom() <= px(600.),
|
|
"{bounds:?}"
|
|
);
|
|
}
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn editing_a_host_never_retargets_an_existing_scan(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
update(&view, cx, Disktree::open_volumes);
|
|
cx.run_until_parked();
|
|
draw(cx);
|
|
let before = read(&view, cx, |app| app.scan_epoch);
|
|
let input = cx.debug_bounds("source-host").unwrap();
|
|
cx.simulate_click(input.center(), gpui_kit::Modifiers::none());
|
|
cx.simulate_input("new-host-not-connected");
|
|
update(&view, cx, |app, cx| {
|
|
app.choose_source_root(temp.path().into(), cx);
|
|
assert!(app.picker_error.is_some());
|
|
assert!(app.remote.is_none());
|
|
assert_eq!(app.scan_epoch, before);
|
|
assert!(app.tree.is_some());
|
|
});
|
|
press(cx, "escape");
|
|
assert!(!read(&view, cx, |app| app.volumes_open));
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn a_directory_error_can_be_corrected_without_reconnecting(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) =
|
|
cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));
|
|
cx.run_until_parked();
|
|
update(&view, cx, |app, cx| {
|
|
app.choose_source_root(PathBuf::from("relative"), cx);
|
|
assert!(app.picker_error.is_some());
|
|
assert!(app.awaiting_root);
|
|
app.choose_source_root(temp.path().into(), cx);
|
|
assert!(app.picker_error.is_none());
|
|
assert!(!app.awaiting_root);
|
|
});
|
|
finish_scan(&view, cx);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn stale_local_discovery_cannot_overwrite_a_new_source_error(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let (view, cx) =
|
|
cx.add_window_view(|_, cx| Disktree::choose(options(), 3, None, cx));
|
|
// The old discovery is still queued. The new host fails validation
|
|
// without any network connection; only its error may remain.
|
|
update(&view, cx, |app, cx| {
|
|
app.load_volume_source(Some("-invalid".into()), cx);
|
|
});
|
|
cx.run_until_parked();
|
|
draw(cx);
|
|
read(&view, cx, |app| {
|
|
assert_eq!(app.volumes_source.as_deref(), Some("-invalid"));
|
|
assert!(app.volumes_error.is_some());
|
|
assert!(app.volumes.is_empty());
|
|
assert!(app.remote.is_none());
|
|
});
|
|
update(&view, cx, |app, cx| {
|
|
app.close_volumes(cx);
|
|
assert!(!app.poll_roots_once(1, cx));
|
|
});
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn remote_root_acceptance_never_stats_the_path_locally(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
update(&view, cx, |app, cx| {
|
|
let crumbs = app.crumbs_for_path(&temp.path().join("junk")).unwrap();
|
|
app.select(Some(crumbs), cx);
|
|
app.toggle_mark_selected(cx);
|
|
app.volumes_open = true;
|
|
// An intentionally invalid SSH destination ensures acceptance cannot
|
|
// contact any machine. The listing is a decoded fixture, not a walk.
|
|
app.volumes_source = Some("-test-fixture".into());
|
|
app.finish_volume_listing(
|
|
Ok((
|
|
vec![Volume {
|
|
point: PathBuf::from("/only-on-the-remote-host"),
|
|
device: Some("/dev/remote-disk".into()),
|
|
space: None,
|
|
}],
|
|
None,
|
|
)),
|
|
cx,
|
|
);
|
|
});
|
|
draw(cx);
|
|
update(&view, cx, |app, cx| {
|
|
app.choose_volume(cx);
|
|
assert_eq!(app.remote.as_deref(), Some("-test-fixture"));
|
|
assert_eq!(app.root_path, PathBuf::from("/only-on-the-remote-host"));
|
|
assert!(app.marks.is_empty() && app.remote_identity.is_none());
|
|
assert!(
|
|
app.tree.is_none()
|
|
&& app.scan.is_none()
|
|
&& app.remote_scan.is_none()
|
|
);
|
|
assert!(
|
|
app.scan_error
|
|
.as_ref()
|
|
.is_some_and(|error| error.contains("invalid SSH"))
|
|
);
|
|
});
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn repointing_an_ssh_alias_never_reuses_old_machine_marks(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx, root) = remote_view_over(temp.path(), cx);
|
|
let junk = PathStyle::Posix.join(&root, "junk");
|
|
update(&view, cx, |app, cx| {
|
|
let old = disktree_core::identity::HostIdentity {
|
|
hostname: "same-name".into(),
|
|
machine_id: Some("machine-a".into()),
|
|
};
|
|
app.remote = Some("stable-alias".into());
|
|
app.update_remote_identity(Some(old.clone()));
|
|
let crumbs = app.crumbs_for_path(&junk).unwrap();
|
|
app.select(Some(crumbs), cx);
|
|
app.toggle_mark_selected(cx);
|
|
app.update_remote_identity(Some(old.clone()));
|
|
assert!(!app.marks.is_empty(), "same machine keeps its marks");
|
|
app.update_remote_identity(Some(
|
|
disktree_core::identity::HostIdentity {
|
|
hostname: old.hostname,
|
|
machine_id: Some("machine-b".into()),
|
|
},
|
|
));
|
|
assert!(app.marks.is_empty(), "same alias is not proof of identity");
|
|
app.toggle_mark_selected(cx);
|
|
assert!(!app.marks.is_empty());
|
|
app.update_remote_identity(None);
|
|
assert!(app.marks.is_empty(), "lost identity also fails closed");
|
|
});
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn remote_review_never_deletes_even_through_direct_actions(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx, root) = remote_view_over(temp.path(), cx);
|
|
let junk = PathStyle::Posix.join(&root, "junk");
|
|
update(&view, cx, |app, cx| {
|
|
app.remote = Some("dev".into());
|
|
let crumbs = app.crumbs_for_path(&junk).unwrap();
|
|
app.select(Some(crumbs), cx);
|
|
app.toggle_mark_selected(cx);
|
|
app.screen = Screen::Review;
|
|
});
|
|
draw(cx);
|
|
press(cx, "enter");
|
|
press(cx, "p");
|
|
press(cx, "m");
|
|
update(&view, cx, |app, cx| {
|
|
app.commit(cx);
|
|
app.confirm_delete(cx);
|
|
app.begin_removal(cx);
|
|
assert!(!app.confirm_open);
|
|
assert!(app.run.is_none());
|
|
assert_eq!(app.screen, Screen::Review);
|
|
let selection = app.plan();
|
|
assert_eq!(selection.targets.len(), 1);
|
|
assert!(selection.bytes() > 0);
|
|
assert_eq!(selection.reclaim(), 0);
|
|
assert_eq!(selection.foreign(), 0);
|
|
assert_eq!(selection.unattributed(), selection.bytes());
|
|
app.open_volumes(cx);
|
|
app.restart_as_administrator(cx);
|
|
assert!(!app.volumes_open);
|
|
assert!(!app.restarting);
|
|
});
|
|
draw(cx);
|
|
assert!(temp.path().join("junk/blob.bin").exists());
|
|
assert!(temp.path().join("keep/notes.txt").exists());
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn a_failed_remote_scan_stops_showing_the_reading_screen(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
update(&view, cx, |app, _| {
|
|
app.tree = None;
|
|
app.scan = None;
|
|
app.remote = Some("dev".into());
|
|
app.scan_error =
|
|
Some("SSH dev: Permission denied (publickey,password).".into());
|
|
});
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("scan-error").is_some());
|
|
assert!(cx.debug_bounds("scan-reading").is_none());
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn the_window_draws_a_treemap_with_tiles(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
let bounds: Bounds<Pixels> =
|
|
cx.debug_bounds("disktree-root").expect("root element");
|
|
assert!(bounds.size.width > px(0.) && bounds.size.height > px(0.));
|
|
|
|
let (size, tiles) = update(&view, cx, |app, _| {
|
|
(
|
|
app.treemap_size.get(),
|
|
app.layout().map(<[Tile]>::len).unwrap_or_default(),
|
|
)
|
|
});
|
|
assert!(size.width > px(0.), "treemap width {size:?}");
|
|
assert!(size.height > px(0.), "treemap height {size:?}");
|
|
assert!(tiles >= 3, "tiles laid out: {tiles}");
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn the_first_scan_shows_what_it_is_doing_then_the_treemap(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let root = temp.path().to_path_buf();
|
|
// Through the real constructor, so this is the path every first run takes.
|
|
let (view, cx) =
|
|
cx.add_window_view(move |_, cx| Disktree::new(root, options(), 3, cx));
|
|
draw(cx);
|
|
|
|
// Nothing is known yet, so the viewport counts the walk instead of showing
|
|
// an empty mosaic.
|
|
assert!(read(&view, cx, |app| app.tree().is_none()));
|
|
assert!(cx.debug_bounds("disktree-root").is_some());
|
|
|
|
finish_scan(&view, cx);
|
|
draw(cx);
|
|
|
|
let (tiles, selected, hidden_present) = update(&view, cx, |app, _| {
|
|
(
|
|
app.layout().map(<[Tile]>::len).unwrap_or_default(),
|
|
app.selected.is_some(),
|
|
app.tree().is_some_and(|tree| {
|
|
tree.children.iter().any(|c| c.name.starts_with('.'))
|
|
}),
|
|
)
|
|
});
|
|
assert!(tiles >= 3, "tiles after the scan: {tiles}");
|
|
assert!(
|
|
selected,
|
|
"the largest entry is selected for the selection line"
|
|
);
|
|
assert!(hidden_present, "hidden directories are part of the tree");
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn keys_walk_the_tree_and_mark_what_is_selected(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
// Largest first: .cache holds the biggest file.
|
|
let (selected, name) = read(&view, cx, |app| {
|
|
(
|
|
app.selected.clone(),
|
|
app.node_at(&[0]).map(|node| node.name.to_string()),
|
|
)
|
|
});
|
|
assert_eq!(selected, Some(vec![0]));
|
|
assert_eq!(name.as_deref(), Some(".cache"));
|
|
|
|
press(cx, "space");
|
|
let (marks, bytes) =
|
|
read(&view, cx, |app| (app.marks.len(), app.plan().bytes()));
|
|
assert_eq!(marks, 1);
|
|
assert_eq!(bytes, 300_000, "the whole hidden directory");
|
|
|
|
// Enter descends, Escape comes back out.
|
|
press(cx, "enter");
|
|
assert!(!read(&view, cx, |app| app.crumbs.is_empty()));
|
|
press(cx, "escape");
|
|
press(cx, "escape");
|
|
assert!(read(&view, cx, |app| app.crumbs.is_empty()));
|
|
|
|
// Space twice more leaves the mark as it was.
|
|
press(cx, "space");
|
|
press(cx, "space");
|
|
let marks = read(&view, cx, |app| app.marks.items().to_vec());
|
|
assert_eq!(marks.len(), 1);
|
|
assert_eq!(marks[0].bytes, 300_000);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn a_permanent_deletion_asks_in_an_alert_dialog_then_removes(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
// Mark "junk" directly, which is what clicking its tile would do, and
|
|
// choose the permanent path: the trash path would reach the real trash.
|
|
update(&view, cx, |app, cx| {
|
|
app.removal_mode = RemovalMode::Permanent;
|
|
let junk = app
|
|
.tree()
|
|
.and_then(|tree| {
|
|
tree.children
|
|
.iter()
|
|
.position(|child| &*child.name == "junk")
|
|
.map(|index| vec![index])
|
|
})
|
|
.expect("the junk directory");
|
|
app.select(Some(junk.clone()), cx);
|
|
app.toggle_mark(&junk, cx);
|
|
assert_eq!(app.plan().bytes(), 300_000);
|
|
});
|
|
|
|
press(cx, "c");
|
|
assert_eq!(read(&view, cx, |app| app.screen), Screen::Review);
|
|
|
|
// Enter on the review screen opens the alert dialog; nothing is deleted.
|
|
press(cx, "enter");
|
|
assert!(read(&view, cx, |app| app.confirm_open));
|
|
assert_eq!(read(&view, cx, |app| app.screen), Screen::Review);
|
|
assert!(
|
|
temp.path().join("junk").exists(),
|
|
"nothing has happened yet"
|
|
);
|
|
|
|
// Enter in the dialog is its confirm action.
|
|
press(cx, "enter");
|
|
assert!(!read(&view, cx, |app| app.confirm_open));
|
|
assert_eq!(read(&view, cx, |app| app.screen), Screen::Running);
|
|
|
|
// The removal runs on a real worker thread, so the test drives the same
|
|
// poll the UI's ticker drives rather than waiting on the test clock.
|
|
let epoch = read(&view, cx, |app| app.run_epoch);
|
|
let mut finished = false;
|
|
for _ in 0..400 {
|
|
std::thread::sleep(std::time::Duration::from_millis(5));
|
|
finished = update(&view, cx, |app, cx| {
|
|
app.poll_removal_once(epoch, cx);
|
|
app.screen == Screen::Done
|
|
});
|
|
if finished {
|
|
break;
|
|
}
|
|
}
|
|
assert!(finished, "the removal finished");
|
|
draw(cx);
|
|
|
|
let summary = read(&view, cx, |app| app.run_summary.clone());
|
|
assert_eq!(summary.removed, 1, "{summary:?}");
|
|
assert_eq!(summary.failed, 0, "{summary:?}");
|
|
assert!(
|
|
read(&view, cx, |app| app.marks.is_empty()),
|
|
"the list clears after the run"
|
|
);
|
|
assert!(!temp.path().join("junk").exists(), "junk is gone");
|
|
assert!(
|
|
temp.path().join("keep/notes.txt").exists(),
|
|
"an unmarked directory is untouched"
|
|
);
|
|
assert!(
|
|
temp.path().join(".cache/blob.bin").exists(),
|
|
"an unmarked hidden directory is untouched"
|
|
);
|
|
}
|
|
|
|
/// A subdivided directory keeps a band at the top for its own name, and its
|
|
/// children start below it. That is what makes the inner tiles selectable: the
|
|
/// parent's name never covers them.
|
|
#[gpui_kit::test]
|
|
fn a_parents_name_gets_its_own_band_above_its_children(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
let (band, lowest_child_top, bands_in_mosaic) =
|
|
update(&view, cx, |app, _| {
|
|
let tiles = app.layout().map(<[Tile]>::to_vec).unwrap_or_default();
|
|
let parent = tiles
|
|
.iter()
|
|
.find(|tile| tile.crumbs() == [1])
|
|
.expect("the junk directory");
|
|
let band = parent
|
|
.header
|
|
.expect("junk is subdivided, so it keeps a band");
|
|
let children_top = tiles
|
|
.iter()
|
|
.filter(|tile| {
|
|
tile.crumbs().starts_with(&[1]) && tile.crumbs().len() > 1
|
|
})
|
|
.map(|tile| tile.rect.y)
|
|
.fold(f32::INFINITY, f32::min);
|
|
let mosaic = app.prepare();
|
|
let bands_in_mosaic = mosaic
|
|
.labels
|
|
.iter()
|
|
.filter(|label| label.header.is_some())
|
|
.count();
|
|
(band, children_top, bands_in_mosaic)
|
|
});
|
|
|
|
assert!(
|
|
lowest_child_top >= band.bottom() - f32::EPSILON,
|
|
"children start at {} but the band ends at {}",
|
|
lowest_child_top,
|
|
band.bottom()
|
|
);
|
|
assert!(
|
|
band.h >= 8.0,
|
|
"a band has to be tall enough to read: {}",
|
|
band.h
|
|
);
|
|
assert!(
|
|
bands_in_mosaic >= 1,
|
|
"the parent's own label is placed in a band"
|
|
);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn hovering_reports_the_tile_under_the_pointer(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
let (origin, biggest, centre) = update(&view, cx, |app, _| {
|
|
// A leaf tile, so "the deepest tile under the pointer" is unambiguous.
|
|
let biggest = app
|
|
.layout()
|
|
.and_then(|tiles| {
|
|
tiles
|
|
.iter()
|
|
.filter(|tile| {
|
|
let crumbs = tile.crumbs();
|
|
!tiles.iter().any(|other| {
|
|
other.crumbs().len() > crumbs.len()
|
|
&& other.crumbs().starts_with(crumbs)
|
|
})
|
|
})
|
|
.max_by(|left, right| {
|
|
left.rect.area().total_cmp(&right.rect.area())
|
|
})
|
|
.map(|tile| tile.crumbs().to_vec())
|
|
})
|
|
.expect("a tile to hover");
|
|
let rect = app.tile_rect(&biggest).expect("a rectangle");
|
|
let screen = app.view.project(rect);
|
|
(
|
|
app.treemap_origin.get(),
|
|
biggest,
|
|
(screen.x + screen.w / 2.0, screen.y + screen.h / 2.0),
|
|
)
|
|
});
|
|
|
|
let (x, y) = centre;
|
|
cx.simulate_mouse_move(
|
|
Point::new(origin.x + px(x), origin.y + px(y)),
|
|
None,
|
|
gpui_kit::Modifiers::default(),
|
|
);
|
|
draw(cx);
|
|
|
|
let hovered = read(&view, cx, |app| app.hovered.clone());
|
|
assert_eq!(hovered.as_deref(), Some(biggest.as_slice()));
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn right_click_selects_the_tile_and_reveals_it(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
let (at, target, path) = update(&view, cx, |app, _| {
|
|
let biggest = app
|
|
.layout()
|
|
.and_then(|tiles| {
|
|
tiles
|
|
.iter()
|
|
.max_by(|left, right| {
|
|
left.rect.area().total_cmp(&right.rect.area())
|
|
})
|
|
.map(|tile| tile.crumbs().to_vec())
|
|
})
|
|
.expect("a tile");
|
|
let rect = app.tile_rect(&biggest).expect("a rectangle");
|
|
let screen = app.view.project(rect);
|
|
let (x, y) = (screen.x + screen.w / 2.0, screen.y + screen.h / 2.0);
|
|
// The deepest tile there, which is what a click resolves to.
|
|
let target = app.tile_at(x, y).expect("a tile under the pointer");
|
|
let path = app.path_at(&target).expect("a path");
|
|
let origin = app.treemap_origin.get();
|
|
(Point::new(origin.x + px(x), origin.y + px(y)), target, path)
|
|
});
|
|
|
|
// The test platform cannot open a file manager, so take the path away
|
|
// first: the reveal then reports it instead of reaching the platform.
|
|
if path.is_dir() {
|
|
std::fs::remove_dir_all(&path).expect("remove");
|
|
} else {
|
|
std::fs::remove_file(&path).expect("remove");
|
|
}
|
|
|
|
cx.simulate_mouse_down(
|
|
at,
|
|
gpui_kit::MouseButton::Right,
|
|
gpui_kit::Modifiers::none(),
|
|
);
|
|
cx.simulate_mouse_up(
|
|
at,
|
|
gpui_kit::MouseButton::Right,
|
|
gpui_kit::Modifiers::none(),
|
|
);
|
|
draw(cx);
|
|
|
|
let (selected, notice) = read(&view, cx, |app| {
|
|
(
|
|
app.selected.clone(),
|
|
app.notice.as_ref().map(|(text, _)| text.clone()),
|
|
)
|
|
});
|
|
assert_eq!(selected, Some(target), "the clicked tile is selected");
|
|
assert!(
|
|
notice.is_some_and(|text| text.contains("no longer on disk")),
|
|
"the reveal ran for it"
|
|
);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn typing_filters_live_and_enter_shows_only_the_matches(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
let names_drawn = |view: &Entity<Disktree>, cx: &mut Window| {
|
|
update(view, cx, |app, _| {
|
|
let tiles = app.layout().map(<[Tile]>::to_vec).unwrap_or_default();
|
|
tiles
|
|
.iter()
|
|
.filter_map(|tile| app.node_at(tile.crumbs()))
|
|
.map(|node| node.name.to_string())
|
|
.collect::<Vec<_>>()
|
|
})
|
|
};
|
|
|
|
press(cx, "/");
|
|
cx.simulate_input("BLOB");
|
|
// The search runs off the UI thread; let it land.
|
|
cx.run_until_parked();
|
|
draw(cx);
|
|
// Live: two matches, nothing hidden yet, the rest only dimmed.
|
|
let (count, applied, keep_filtered) = read(&view, cx, |app| {
|
|
let matches = app.matches.as_deref().expect("matching as it is typed");
|
|
let keep = app.tree().and_then(|tree| {
|
|
tree.children
|
|
.iter()
|
|
.position(|child| &*child.name == "keep")
|
|
});
|
|
(
|
|
matches.count,
|
|
app.filter_applied,
|
|
keep.is_some_and(|index| matches.keep(&[index]).is_none()),
|
|
)
|
|
});
|
|
assert_eq!(count, 2, "junk/blob.bin and .cache/blob.bin");
|
|
assert!(!applied);
|
|
assert!(keep_filtered, "keep holds no blob");
|
|
// Dimmed, not hidden: a non-match is still drawn while typing.
|
|
assert!(names_drawn(&view, cx).contains(&"deeper".to_string()));
|
|
|
|
// Enter: only the matches, and the largest selected for marking.
|
|
press(cx, "enter");
|
|
let drawn = names_drawn(&view, cx);
|
|
assert!(read(&view, cx, |app| app.filter_applied));
|
|
assert!(
|
|
!drawn.iter().any(|name| name == "keep" || name == "deeper"),
|
|
"{drawn:?}"
|
|
);
|
|
assert_eq!(
|
|
drawn.iter().filter(|name| *name == "blob.bin").count(),
|
|
2,
|
|
"{drawn:?}"
|
|
);
|
|
let selected = read(&view, cx, |app| {
|
|
app.selected
|
|
.as_deref()
|
|
.and_then(|crumbs| app.path_at(crumbs))
|
|
});
|
|
assert_eq!(selected, Some(temp.path().join(".cache/blob.bin")));
|
|
|
|
// Escape gives everything back.
|
|
press(cx, "escape");
|
|
assert!(read(&view, cx, |app| app.matches.is_none()
|
|
&& !app.filter_applied));
|
|
assert!(names_drawn(&view, cx).contains(&"deeper".to_string()));
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn the_help_overlay_opens_and_closes(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
press(cx, "?");
|
|
assert!(read(&view, cx, |app| app.show_help));
|
|
press(cx, "escape");
|
|
assert!(!read(&view, cx, |app| app.show_help));
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn the_volume_picker_opens_moves_and_closes(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
// The picker lists volumes and draws them without panicking; Escape
|
|
// leaves the scan where it was.
|
|
press(cx, "v");
|
|
assert!(read(&view, cx, |app| app.volumes_open));
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("disktree-root").is_some());
|
|
let before = read(&view, cx, |app| app.root_path.clone());
|
|
press(cx, "down");
|
|
press(cx, "up");
|
|
press(cx, "escape");
|
|
assert!(!read(&view, cx, |app| app.volumes_open));
|
|
assert_eq!(read(&view, cx, |app| app.root_path.clone()), before);
|
|
}
|
|
|
|
/// Enter must reach the picker even when its dialog owns keyboard focus.
|
|
#[gpui_kit::test]
|
|
fn enter_in_the_focused_volume_picker_scans_the_selected_root(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
// Accepting a local root canonicalizes it, and the temporary directory
|
|
// is behind a link on macOS (/var -> /private/var) and a short 8.3 name
|
|
// on Windows runners, so compare against the resolved path.
|
|
let target = dunce::canonicalize(temp.path().join("junk")).unwrap();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
update(&view, cx, |app, _| {
|
|
app.volumes = vec![disktree_core::space::Volume {
|
|
point: target.clone(),
|
|
device: None,
|
|
space: None,
|
|
}];
|
|
app.volume_highlight = 0;
|
|
app.volumes_open = true;
|
|
});
|
|
let focus = read(&view, cx, |app| app.confirm_focus.clone());
|
|
cx.update(|window, cx| window.focus(&focus, cx));
|
|
draw(cx);
|
|
assert!(!read(&view, cx, Disktree::can_start_over));
|
|
press(cx, "enter");
|
|
assert!(!read(&view, cx, |app| app.volumes_open));
|
|
assert_eq!(read(&view, cx, |app| app.root_path.clone()), target);
|
|
finish_scan(&view, cx);
|
|
assert!(read(&view, cx, |app| app.tree().is_some()));
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn the_volume_picker_is_centred_and_still_dismisses_from_outside(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
// Fixed rows, so this is about where the popup lands and not about which
|
|
// disks the machine running the test happens to have.
|
|
update(&view, cx, |app, cx| {
|
|
app.volumes = vec![
|
|
Volume {
|
|
point: PathBuf::from("/one"),
|
|
device: Some("/dev/one".into()),
|
|
space: Some(SpaceInfo {
|
|
total: 1_000,
|
|
free: 500,
|
|
available: 400,
|
|
}),
|
|
},
|
|
Volume {
|
|
point: PathBuf::from("/two"),
|
|
device: None,
|
|
space: None,
|
|
},
|
|
];
|
|
app.volumes_open = true;
|
|
cx.notify();
|
|
});
|
|
draw(cx);
|
|
|
|
let viewport = cx.update(|window, _| window.viewport_size());
|
|
let rows = cx.debug_bounds("volume-rows").expect("the rows are drawn");
|
|
let centre = rows.center();
|
|
assert!(
|
|
(centre.x - viewport.width / 2.0).abs() < px(4.),
|
|
"the popup is not centred across: {centre:?} in {viewport:?}"
|
|
);
|
|
assert!(
|
|
(centre.y - viewport.height / 2.0).abs() < px(150.),
|
|
"the popup is not centred down: {centre:?} in {viewport:?}"
|
|
);
|
|
|
|
// The wrapper that centres the popup must not swallow the backdrop's
|
|
// clicks: a click in the corner, outside the popup, still closes it.
|
|
cx.simulate_click(
|
|
gpui_kit::point(px(4.), px(4.)),
|
|
gpui_kit::Modifiers::none(),
|
|
);
|
|
draw(cx);
|
|
assert!(
|
|
!read(&view, cx, |app| app.volumes_open),
|
|
"clicking outside the picker closes it"
|
|
);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn showing_a_tile_that_is_gone_says_so_instead(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
// The selection is .cache, the largest; take it away behind the tree.
|
|
std::fs::remove_dir_all(temp.path().join(".cache")).expect("remove");
|
|
press(cx, "o");
|
|
let notice = read(&view, cx, |app| app.notice.clone());
|
|
let (message, _) = notice.expect("a notice");
|
|
assert!(message.contains("no longer on disk"), "{message}");
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn command_chords_are_not_read_as_plain_letters(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
// ⌘P and ⌘D are the menu bar's or nobody's; read as `p` and `d` they
|
|
// would hide the selection and re-scan.
|
|
let shown = read(&view, cx, |app| app.show_selection);
|
|
press(cx, "cmd-p cmd-d");
|
|
assert_eq!(read(&view, cx, |app| app.show_selection), shown);
|
|
assert!(read(&view, cx, |app| app.options.apparent_size));
|
|
press(cx, "p");
|
|
assert_eq!(read(&view, cx, |app| app.show_selection), !shown);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn the_treemap_zooms_with_the_wheel_and_resets(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
let middle = read(&view, cx, |app| {
|
|
let size = app.treemap_size.get();
|
|
Point::new(size.width / 2.0, size.height / 2.0)
|
|
});
|
|
update(&view, cx, |app, cx| {
|
|
app.zoom_at(middle.x.as_f32(), middle.y.as_f32(), 1.5, false, cx);
|
|
});
|
|
let zoomed = read(&view, cx, |app| app.view.scale);
|
|
assert!(zoomed > 1.0, "scale after zooming: {zoomed}");
|
|
|
|
press(cx, "0");
|
|
assert!((read(&view, cx, |app| app.view.scale) - 1.0).abs() < f32::EPSILON);
|
|
}
|
|
|
|
/// Both appearances Omarchy ships must draw: the palette is derived from the
|
|
/// theme, so a light theme is a real second configuration.
|
|
#[gpui_kit::test]
|
|
fn both_appearances_draw(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
for theme in [Theme::tokyo_night(), Theme::flexoki_light()] {
|
|
view.update(cx, |_, cx| {
|
|
theme.clone().apply(cx);
|
|
cx.notify();
|
|
});
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("disktree-root").is_some());
|
|
}
|
|
}
|
|
|
|
/// A view built without a scan keeps working: the screens must not assume a
|
|
/// walk is in flight.
|
|
#[gpui_kit::test]
|
|
fn a_view_without_flags_or_marks_still_draws(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
update(&view, cx, |app, cx| {
|
|
app.screen = Screen::Review;
|
|
cx.notify();
|
|
});
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("disktree-root").is_some());
|
|
|
|
update(&view, cx, |app, cx| {
|
|
app.screen = Screen::Running;
|
|
cx.notify();
|
|
});
|
|
draw(cx);
|
|
|
|
update(&view, cx, |app, cx| {
|
|
app.screen = Screen::Done;
|
|
cx.notify();
|
|
});
|
|
draw(cx);
|
|
assert!(cx.debug_bounds("disktree-root").is_some());
|
|
}
|
|
|
|
/// The removal mode is a choice with two independent channels: the key and the
|
|
/// button both have to reach the same state.
|
|
#[gpui_kit::test]
|
|
fn the_review_screen_switches_removal_mode(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
update(&view, cx, |app, cx| {
|
|
app.marks.toggle(disktree_core::removal::Target {
|
|
path: temp.path().join("junk"),
|
|
bytes: 300_000,
|
|
is_dir: true,
|
|
hidden: false,
|
|
});
|
|
app.screen = Screen::Review;
|
|
cx.notify();
|
|
});
|
|
draw(cx);
|
|
|
|
press(cx, "m");
|
|
assert_eq!(read(&view, cx, |app| app.removal_mode), RemovalMode::Trash);
|
|
press(cx, "p");
|
|
assert_eq!(
|
|
read(&view, cx, |app| app.removal_mode),
|
|
RemovalMode::Permanent
|
|
);
|
|
press(cx, "!");
|
|
assert!(read(&view, cx, |app| app.marks.is_empty()));
|
|
}
|
|
|
|
/// `a` on the review screen copies a prompt for an agent naming the marked
|
|
/// path, and removes nothing.
|
|
#[gpui_kit::test]
|
|
fn the_review_screen_copies_the_list_as_an_agent_prompt(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let junk = temp.path().join("junk");
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
update(&view, cx, |app, cx| {
|
|
app.marks.toggle(disktree_core::removal::Target {
|
|
path: junk.clone(),
|
|
bytes: 300_000,
|
|
is_dir: true,
|
|
hidden: false,
|
|
});
|
|
app.screen = Screen::Review;
|
|
cx.notify();
|
|
});
|
|
draw(cx);
|
|
|
|
press(cx, "a");
|
|
let copied = cx
|
|
.read_from_clipboard()
|
|
.and_then(|item| item.text())
|
|
.expect("a prompt on the clipboard");
|
|
assert!(copied.contains("free up disk space"), "{copied}");
|
|
assert!(
|
|
copied.contains(&format!("- {}", junk.display())),
|
|
"{copied}"
|
|
);
|
|
assert!(junk.exists(), "nothing was removed");
|
|
let notice = read(&view, cx, |app| app.notice.clone());
|
|
assert!(
|
|
notice.is_some_and(|(message, _)| message.contains("copied")),
|
|
"the copy is confirmed"
|
|
);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn remote_review_copies_host_guarded_script_and_prompt(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx, root) = remote_view_over(temp.path(), cx);
|
|
let junk = PathStyle::Posix.join(&root, "junk");
|
|
update(&view, cx, |app, cx| {
|
|
app.remote = Some("dev-alias".into());
|
|
app.remote_identity = Some(disktree_core::identity::HostIdentity {
|
|
hostname: "actual-server".into(),
|
|
machine_id: Some("abcdefabcdefabcdefabcdefabcdefab".into()),
|
|
});
|
|
app.marks.toggle(disktree_core::removal::Target {
|
|
path: junk.clone(),
|
|
bytes: 300_000,
|
|
is_dir: true,
|
|
hidden: false,
|
|
});
|
|
app.screen = Screen::Review;
|
|
cx.notify();
|
|
});
|
|
draw(cx);
|
|
press(cx, "y");
|
|
let script = cx
|
|
.read_from_clipboard()
|
|
.and_then(|item| item.text())
|
|
.expect("script on clipboard");
|
|
assert!(script.contains("actual-server"));
|
|
assert!(script.contains("/etc/machine-id"));
|
|
assert!(script.contains("Wrong hostname"));
|
|
assert!(script.contains("ssh -T"));
|
|
assert!(script.contains("PREVIEW ONLY"));
|
|
press(cx, "a");
|
|
let prompt = cx
|
|
.read_from_clipboard()
|
|
.and_then(|item| item.text())
|
|
.expect("prompt on clipboard");
|
|
assert!(prompt.contains("actual-server"));
|
|
assert!(prompt.contains("abcdefabcdefabcdefabcdefabcdefab"));
|
|
assert!(prompt.contains("MANDATORY HOST CHECK"));
|
|
assert!(temp.path().join("junk/blob.bin").exists());
|
|
}
|
|
|
|
/// A Unix host's paths are POSIX on every client. A Windows client must not
|
|
/// join them with `\`, split a name such as `logs\old` or `a:b`, or export a
|
|
/// delete script that names a different file on the host.
|
|
#[gpui_kit::test]
|
|
fn remote_paths_keep_the_hosts_separators_on_every_client(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
use disktree_core::tree::{Metric, Node, NodeKind, aggregate};
|
|
|
|
cx.update(gpui_omarchy::init);
|
|
let mut root = Node::directory("data");
|
|
let mut logs = Node::directory(r"logs\old");
|
|
logs.children
|
|
.push(Node::entry("a:b", NodeKind::File, 4_000));
|
|
root.children.push(logs);
|
|
root.children
|
|
.push(Node::entry("notes", NodeKind::File, 1_000));
|
|
aggregate(&mut root, Metric::Bytes);
|
|
let root_path = PathBuf::from("/srv/data");
|
|
let (view, cx) = cx.add_window_view(move |_, cx| {
|
|
let mut app =
|
|
Disktree::with_tree(root_path.clone(), root, options(), 3, cx);
|
|
app.remote = Some("dev".into());
|
|
app
|
|
});
|
|
let focus = read(&view, cx, |app| app.focus.clone());
|
|
cx.update(|window, cx| window.focus(&focus, cx));
|
|
draw(cx);
|
|
update(&view, cx, |app, cx| {
|
|
let file = Path::new(r"/srv/data/logs\old/a:b");
|
|
let crumbs = app.crumbs_for_path(file).expect("one name, not two");
|
|
assert_eq!(app.path_at(&crumbs).as_deref(), Some(file));
|
|
assert!(
|
|
app.crumbs_for_path(Path::new("/srv/data/logs/old"))
|
|
.is_none()
|
|
);
|
|
app.select(Some(crumbs), cx);
|
|
app.toggle_mark_selected(cx);
|
|
assert!(app.marks.contains(file));
|
|
let labels: Vec<_> = app
|
|
.breadcrumbs()
|
|
.into_iter()
|
|
.map(|(label, _)| label)
|
|
.collect();
|
|
assert_eq!(labels, ["/", "srv", "data"]);
|
|
app.home = Some(PathBuf::from("/srv"));
|
|
assert_eq!(app.display_path(file), r"~/data/logs\old/a:b");
|
|
app.screen = Screen::Review;
|
|
cx.notify();
|
|
});
|
|
draw(cx);
|
|
press(cx, "y");
|
|
let script = cx
|
|
.read_from_clipboard()
|
|
.and_then(|item| item.text())
|
|
.expect("script on clipboard");
|
|
assert!(script.contains(r"'/srv/data/logs\old/a:b'"), "{script}");
|
|
assert!(!script.contains(r"data\logs"), "{script}");
|
|
}
|
|
|
|
/// Escape in the alert dialog cancels: the dialog closes, the review screen
|
|
/// stays, and nothing on disk changes.
|
|
#[gpui_kit::test]
|
|
fn escape_in_the_delete_dialog_cancels(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
update(&view, cx, |app, cx| {
|
|
app.removal_mode = RemovalMode::Permanent;
|
|
app.marks.toggle(disktree_core::removal::Target {
|
|
path: temp.path().join("junk"),
|
|
bytes: 300_000,
|
|
is_dir: true,
|
|
hidden: false,
|
|
});
|
|
app.screen = Screen::Review;
|
|
cx.notify();
|
|
});
|
|
draw(cx);
|
|
|
|
press(cx, "enter");
|
|
assert!(read(&view, cx, |app| app.confirm_open));
|
|
press(cx, "escape");
|
|
assert!(!read(&view, cx, |app| app.confirm_open), "Escape cancels");
|
|
assert_eq!(read(&view, cx, |app| app.screen), Screen::Review);
|
|
assert!(temp.path().join("junk").exists());
|
|
assert_eq!(
|
|
read(&view, cx, |app| app.marks.len()),
|
|
1,
|
|
"the list is kept"
|
|
);
|
|
}
|
|
|
|
/// With a trash on the machine, the reversible path is the default and
|
|
/// commits without a dialog; the permanent one is a deliberate choice.
|
|
#[gpui_kit::test]
|
|
fn the_trash_is_the_default_when_there_is_one(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
let (mode, available) = read(&view, cx, |app| {
|
|
(app.removal_mode, app.trash_backend.is_available())
|
|
});
|
|
if available {
|
|
assert_eq!(mode, RemovalMode::Trash);
|
|
} else {
|
|
assert_eq!(mode, RemovalMode::Permanent);
|
|
}
|
|
}
|
|
|
|
/// `ctrl =` / `ctrl -` / `ctrl 0` change the window's rem, which every size
|
|
/// in the app is expressed in, and the mosaic's header band follows it.
|
|
#[gpui_kit::test]
|
|
fn interface_zoom_scales_the_rem_and_the_header_band(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
let rem =
|
|
|cx: &mut Window| cx.update(|window, _| window.rem_size().as_f32());
|
|
let base = rem(cx);
|
|
let band = |view: &Entity<Disktree>, cx: &mut Window| {
|
|
update(view, cx, |app, _| {
|
|
app.layout();
|
|
app.layout_options.header
|
|
})
|
|
};
|
|
let base_band = band(&view, cx);
|
|
|
|
press(cx, "ctrl-=");
|
|
let zoomed = rem(cx);
|
|
assert!(zoomed > base, "{zoomed} after zooming in from {base}");
|
|
let zoomed_band = band(&view, cx);
|
|
assert!(
|
|
(zoomed_band / base_band - zoomed / base).abs() < 0.01,
|
|
"the band scales with the rem: {base_band} -> {zoomed_band}"
|
|
);
|
|
|
|
press(cx, "ctrl--");
|
|
press(cx, "ctrl--");
|
|
assert!(rem(cx) < base, "zooming out goes below the default");
|
|
press(cx, "ctrl-0");
|
|
assert!((rem(cx) - base).abs() < 0.01, "ctrl 0 resets");
|
|
}
|
|
|
|
/// The crumbs of the directory named `name` directly inside `parent`.
|
|
fn child_crumbs(app: &Disktree, parent: &[usize], name: &str) -> Vec<usize> {
|
|
let node = app.node_at(parent).expect("the parent");
|
|
let index = node
|
|
.children
|
|
.iter()
|
|
.position(|child| &*child.name == name)
|
|
.unwrap_or_else(|| panic!("no {name}"));
|
|
let mut crumbs = parent.to_vec();
|
|
crumbs.push(index);
|
|
crumbs
|
|
}
|
|
|
|
/// Regression: the wheel magnified toward the deepest directory under the
|
|
/// pointer, then went into the *top-level* one containing it, so the screen
|
|
/// after the descent was never the area that was zoomed into.
|
|
#[gpui_kit::test]
|
|
fn the_wheel_goes_into_the_directory_it_zoomed_into(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
// Point at the middle of junk/deeper's contents: a directory one level
|
|
// below a top-level one.
|
|
let (deeper, point) = update(&view, cx, |app, _| {
|
|
let junk = child_crumbs(app, &[], "junk");
|
|
let deeper = child_crumbs(app, &junk, "deeper");
|
|
let body = app.tile_body(&deeper).expect("deeper is drawn");
|
|
(deeper, (body.x + body.w / 2.0, body.y + body.h / 2.0))
|
|
});
|
|
|
|
let mut entered = None;
|
|
for _ in 0..40 {
|
|
let crumbs = update(&view, cx, |app, cx| {
|
|
let (x, y) = app.view.unproject(point.0, point.1);
|
|
let screen = app
|
|
.view
|
|
.project(disktree_core::treemap::Rect::new(x, y, 0.0, 0.0));
|
|
app.zoom_at(screen.x, screen.y, 1.15, true, cx);
|
|
app.crumbs.clone()
|
|
});
|
|
draw(cx);
|
|
if !crumbs.is_empty() {
|
|
entered = Some(crumbs);
|
|
break;
|
|
}
|
|
}
|
|
assert_eq!(
|
|
entered.as_deref(),
|
|
Some(deeper.as_slice()),
|
|
"descended into the pointed-at directory, not its top-level ancestor"
|
|
);
|
|
}
|
|
|
|
/// Regression, keyboard side: Enter on a deep selection enters that
|
|
/// directory, and on a file enters the directory holding it.
|
|
#[gpui_kit::test]
|
|
fn enter_opens_the_selected_directory_at_any_depth(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
let deeper = update(&view, cx, |app, cx| {
|
|
let junk = child_crumbs(app, &[], "junk");
|
|
let deeper = child_crumbs(app, &junk, "deeper");
|
|
app.select(Some(deeper.clone()), cx);
|
|
app.descend(cx);
|
|
deeper
|
|
});
|
|
assert_eq!(read(&view, cx, |app| app.crumbs.clone()), deeper);
|
|
|
|
press(cx, "escape");
|
|
press(cx, "escape");
|
|
press(cx, "escape");
|
|
let junk = update(&view, cx, |app, cx| {
|
|
app.go_to(Vec::new(), cx);
|
|
let junk = child_crumbs(app, &[], "junk");
|
|
let blob = child_crumbs(app, &junk, "blob.bin");
|
|
app.select(Some(blob), cx);
|
|
app.descend(cx);
|
|
junk
|
|
});
|
|
assert_eq!(
|
|
read(&view, cx, |app| app.crumbs.clone()),
|
|
junk,
|
|
"a file opens its directory"
|
|
);
|
|
}
|
|
|
|
/// The mark key acts on what the pointer is over when the pointer moved
|
|
/// last, and on the keyboard selection after an arrow.
|
|
#[gpui_kit::test]
|
|
fn the_mark_key_follows_the_pointer_until_the_keyboard_moves(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
// Point at junk's name band, which belongs to junk itself (its body
|
|
// belongs to its children). junk is not the default selection, .cache.
|
|
let (keep, origin, centre) = update(&view, cx, |app, _| {
|
|
let keep = child_crumbs(app, &[], "junk");
|
|
let body = app
|
|
.layout()
|
|
.and_then(|tiles| {
|
|
tiles.iter().find(|tile| tile.crumbs() == keep.as_slice())
|
|
})
|
|
.and_then(|tile| tile.header)
|
|
.expect("junk is drawn with a band");
|
|
(
|
|
keep,
|
|
app.treemap_origin.get(),
|
|
(body.x + body.w / 2.0, body.y + body.h / 2.0),
|
|
)
|
|
});
|
|
assert_ne!(
|
|
read(&view, cx, |app| app.selected.clone()),
|
|
Some(keep.clone())
|
|
);
|
|
cx.simulate_mouse_move(
|
|
Point::new(origin.x + px(centre.0), origin.y + px(centre.1)),
|
|
None,
|
|
gpui_kit::Modifiers::default(),
|
|
);
|
|
draw(cx);
|
|
|
|
press(cx, "space");
|
|
let marked = read(&view, cx, |app| app.marks.items().to_vec());
|
|
assert_eq!(marked.len(), 1);
|
|
assert!(
|
|
marked[0].path.ends_with("junk"),
|
|
"marked what the pointer is on: {:?}",
|
|
marked[0].path
|
|
);
|
|
assert_eq!(read(&view, cx, |app| app.selected.clone()), Some(keep));
|
|
|
|
// An arrow hands control back to the keyboard selection.
|
|
press(cx, "right");
|
|
assert!(!read(&view, cx, |app| app.pointer_active));
|
|
}
|
|
|
|
/// Regression: after descending, tiles resolved against the scanned root
|
|
/// instead of the directory drawn, so labels, hover and marks named strangers.
|
|
#[gpui_kit::test]
|
|
fn after_descending_every_tile_is_inside_the_directory_drawn(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
let junk = update(&view, cx, |app, cx| {
|
|
let junk = child_crumbs(app, &[], "junk");
|
|
app.select(Some(junk.clone()), cx);
|
|
app.descend(cx);
|
|
junk
|
|
});
|
|
assert_eq!(read(&view, cx, |app| app.crumbs.clone()), junk);
|
|
draw(cx);
|
|
|
|
let (paths, labels) = update(&view, cx, |app, _| {
|
|
let tiles = app.layout().map(<[Tile]>::to_vec).unwrap_or_default();
|
|
let paths: Vec<_> = tiles
|
|
.iter()
|
|
.filter_map(|tile| app.path_at(tile.crumbs()))
|
|
.collect();
|
|
let labels: Vec<String> = app
|
|
.prepare()
|
|
.labels
|
|
.into_iter()
|
|
.map(|label| label.text)
|
|
.collect();
|
|
(paths, labels)
|
|
});
|
|
assert!(!paths.is_empty());
|
|
let junk_path = temp.path().join("junk");
|
|
for path in &paths {
|
|
assert!(path.starts_with(&junk_path), "{path:?} is outside junk");
|
|
}
|
|
for label in &labels {
|
|
assert!(
|
|
["blob.bin", "deeper", "more.bin"].contains(&label.as_str())
|
|
|| label.starts_with('+'),
|
|
"label {label} does not belong to junk"
|
|
);
|
|
}
|
|
|
|
// Space on the selection marks something inside junk, never elsewhere.
|
|
update(&view, cx, |app, cx| {
|
|
let blob = child_crumbs(app, &junk, "blob.bin");
|
|
app.select(Some(blob), cx);
|
|
});
|
|
press(cx, "space");
|
|
let marked = read(&view, cx, |app| app.marks.items().to_vec());
|
|
assert_eq!(marked.len(), 1);
|
|
assert_eq!(marked[0].path, junk_path.join("blob.bin"));
|
|
assert_eq!(marked[0].bytes, 200_000);
|
|
|
|
// And the mark is drawn on the right tile: its crumbs resolve here.
|
|
let hatched = update(&view, cx, |app, _| {
|
|
app.prepare()
|
|
.tiles
|
|
.iter()
|
|
.filter(|tile| tile.marked)
|
|
.count()
|
|
});
|
|
assert_eq!(hatched, 1, "exactly the marked tile is hatched");
|
|
}
|
|
|
|
/// Drive the scan the view started until its outcome has been applied.
|
|
///
|
|
/// The scan is what is waited on, not the tree: widening keeps the old tree
|
|
/// on screen while the wider root is read, so a tree being there does not
|
|
/// mean the requested scan has completed.
|
|
fn finish_scan(view: &Entity<Disktree>, cx: &mut Window) {
|
|
// Without a scan in flight the poller reports "stopped" at once, and the
|
|
// wait would pass without having waited for anything.
|
|
assert!(
|
|
read(view, cx, |app| app.scan.is_some()),
|
|
"no scan to finish"
|
|
);
|
|
let epoch = read(view, cx, |app| app.scan_epoch);
|
|
for _ in 0..600 {
|
|
std::thread::sleep(std::time::Duration::from_millis(5));
|
|
let running = update(view, cx, |app, cx| app.poll_scan_once(epoch, cx));
|
|
if !running {
|
|
let (error, tree) = read(view, cx, |app| {
|
|
(app.scan_error.clone(), app.tree().is_some())
|
|
});
|
|
assert_eq!(error, None, "the scan failed");
|
|
assert!(tree, "the scan landed without a tree");
|
|
return;
|
|
}
|
|
}
|
|
panic!("the scan never landed");
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn dragging_the_panel_edge_resizes_it_within_its_limits(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
use crate::state::{PANEL_MAX_REMS, PANEL_MIN_REMS, panel_width};
|
|
use gpui_kit::{Modifiers, MouseButton};
|
|
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
cx.simulate_resize(gpui_kit::size(px(1400.), px(900.)));
|
|
draw(cx);
|
|
let handle = cx.debug_bounds("panel-handle").expect("the panel is shown");
|
|
let start = handle.center();
|
|
let before = read(&view, cx, |app| app.panel_rems);
|
|
|
|
// A drag starts on the first move and reports moves after it, as a real
|
|
// pointer does in many small steps.
|
|
let drag = |cx: &mut Window, from: Point<Pixels>, to: Point<Pixels>| {
|
|
cx.simulate_mouse_down(from, MouseButton::Left, Modifiers::none());
|
|
for step in 1..=4 {
|
|
let t = step as f32 / 4.0;
|
|
let at = Point::new(from.x + (to.x - from.x) * t, to.y);
|
|
cx.simulate_mouse_move(
|
|
at,
|
|
Some(MouseButton::Left),
|
|
Modifiers::none(),
|
|
);
|
|
}
|
|
cx.simulate_mouse_up(to, MouseButton::Left, Modifiers::none());
|
|
draw(cx);
|
|
};
|
|
|
|
// Wider: drag the edge 160 px to the left.
|
|
let wider = Point::new(start.x - px(160.), start.y);
|
|
drag(cx, start, wider);
|
|
let after = read(&view, cx, |app| app.panel_rems);
|
|
assert!(
|
|
(after - before - 10.0).abs() < 0.5,
|
|
"160 px is 10 rem: {before} -> {after}"
|
|
);
|
|
|
|
// The limits, for any edge position: a minimum, a maximum, and never
|
|
// so wide that the mosaic gets less room than the panel's own minimum.
|
|
assert!((panel_width(1390., 1400., 16.) - PANEL_MIN_REMS).abs() < 1e-3);
|
|
assert!((panel_width(0., 3000., 16.) - PANEL_MAX_REMS).abs() < 1e-3);
|
|
let squeezed = panel_width(0., 800., 16.);
|
|
assert!((squeezed - (800. / 16. - PANEL_MIN_REMS)).abs() < 1e-3);
|
|
assert!((panel_width(0., 300., 16.) - PANEL_MIN_REMS).abs() < 1e-3);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn widening_reuses_the_tree_it_has_and_reads_only_the_rest(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
use crate::state::Crumb;
|
|
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let inner = temp.path().join("junk");
|
|
let (view, cx) = view_over(&inner, cx);
|
|
update(&view, cx, |app, _| {
|
|
app.disk_root = Some(temp.path().to_path_buf());
|
|
// Stale on purpose: the wider root, a folder, must reset it.
|
|
app.file_table = true;
|
|
});
|
|
let before = read(&view, cx, |app| app.tree().map(|tree| tree.files));
|
|
|
|
// The trail runs from the top of the filesystem — "/", or a drive such
|
|
// as "C:\" — and the scanned root sits under its parents.
|
|
let trail = read(&view, cx, Disktree::breadcrumbs);
|
|
let top = temp.path().ancestors().last().expect("a top");
|
|
assert_eq!(trail[0].0, top.display().to_string());
|
|
assert!(
|
|
trail.contains(&(
|
|
temp.path()
|
|
.file_name()
|
|
.unwrap()
|
|
.to_string_lossy()
|
|
.into_owned(),
|
|
Crumb::Above(temp.path().to_path_buf())
|
|
))
|
|
);
|
|
|
|
// Written after the first scan: a memoized subtree cannot see it.
|
|
std::fs::write(inner.join("late.bin"), vec![0_u8; 4096]).expect("write");
|
|
|
|
press(cx, "g");
|
|
// The old tree stays on screen while the wider one is read.
|
|
assert!(read(&view, cx, |app| app.tree().is_some()));
|
|
finish_scan(&view, cx);
|
|
assert_eq!(read(&view, cx, |app| app.root_path.clone()), temp.path());
|
|
assert!(
|
|
!read(&view, cx, |app| app.file_table),
|
|
"the offer follows the root it widened to"
|
|
);
|
|
let (reused, rest, selected) = read(&view, cx, |app| {
|
|
let tree = app.tree().expect("the wider tree");
|
|
let junk = tree.child_named("junk").map(|node| node.files);
|
|
let selected = app
|
|
.selected
|
|
.as_deref()
|
|
.and_then(|crumbs| app.node_at(crumbs))
|
|
.map(|node| node.name.to_string());
|
|
(junk, tree.child_named("keep").is_some(), selected)
|
|
});
|
|
assert_eq!(reused, before, "junk was reused, not walked again");
|
|
assert!(rest, "what is outside it was walked");
|
|
assert_eq!(selected.as_deref(), Some("junk"), "where you came from");
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn enter_before_the_search_lands_applies_it_when_it_does(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
|
|
press(cx, "/");
|
|
cx.simulate_input("blob");
|
|
cx.simulate_keystrokes("enter");
|
|
cx.run_until_parked();
|
|
draw(cx);
|
|
let (applied, count, open) = read(&view, cx, |app| {
|
|
(
|
|
app.filter_applied,
|
|
app.matches.as_deref().map(|matches| matches.count),
|
|
app.find_open,
|
|
)
|
|
});
|
|
assert!(applied, "Enter was not lost to a search in flight");
|
|
assert_eq!(count, Some(2));
|
|
assert!(!open);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn a_crumb_lists_its_siblings_and_jumps_sideways(cx: &mut TestAppContext) {
|
|
use gpui_kit::{Modifiers, MouseButton};
|
|
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
cx.simulate_resize(gpui_kit::size(px(1400.), px(900.)));
|
|
draw(cx);
|
|
// Into junk, so the trail ends in a crumb that has siblings.
|
|
let junk = read(&view, cx, |app| {
|
|
app.tree()
|
|
.and_then(|tree| {
|
|
tree.children.iter().position(|c| &*c.name == "junk")
|
|
})
|
|
.expect("junk")
|
|
});
|
|
update(&view, cx, |app, cx| app.go_to(vec![junk], cx));
|
|
draw(cx);
|
|
|
|
let last = read(&view, cx, |app| app.breadcrumbs().len() - 1);
|
|
let chevron = cx
|
|
.debug_bounds(Box::leak(format!("crumb-{last}-menu").into_boxed_str()))
|
|
.expect("the current crumb has a menu");
|
|
cx.simulate_click(chevron.center(), Modifiers::none());
|
|
draw(cx);
|
|
assert!(
|
|
cx.debug_bounds("sibling-menu").is_some(),
|
|
"the menu is drawn"
|
|
);
|
|
let (names, highlighted) = read(&view, cx, |app| {
|
|
let menu = app.crumb_menu.clone().expect("open");
|
|
let (rows, _) = app.siblings(&menu.parent);
|
|
let names: Vec<String> =
|
|
rows.iter().map(|row| row.name.clone()).collect();
|
|
let highlighted = names_at(&names, menu.highlighted);
|
|
(names, highlighted)
|
|
});
|
|
assert!(
|
|
names.contains(&".cache".to_string())
|
|
&& names.contains(&"keep".to_string())
|
|
);
|
|
assert_eq!(highlighted, "junk", "it opens on where you are");
|
|
|
|
// Walk to .cache by name, not by rank: it and junk are close in size.
|
|
let target = names
|
|
.iter()
|
|
.position(|name| name == ".cache")
|
|
.expect("listed");
|
|
let here = names
|
|
.iter()
|
|
.position(|name| name == "junk")
|
|
.expect("listed");
|
|
let key = if target < here { "up" } else { "down" };
|
|
for _ in 0..target.abs_diff(here) {
|
|
press(cx, key);
|
|
}
|
|
press(cx, "enter");
|
|
let (crumbs, open) = read(&view, cx, |app| {
|
|
(app.crumbs.clone(), app.crumb_menu.is_some())
|
|
});
|
|
let cache = read(&view, cx, |app| {
|
|
app.tree()
|
|
.and_then(|tree| {
|
|
tree.children.iter().position(|c| &*c.name == ".cache")
|
|
})
|
|
.expect(".cache")
|
|
});
|
|
assert_eq!(crumbs, vec![cache], "went sideways into .cache");
|
|
assert!(!open);
|
|
|
|
// A click outside closes it.
|
|
let chevron = cx
|
|
.debug_bounds(Box::leak(format!("crumb-{last}-menu").into_boxed_str()))
|
|
.expect("menu chevron");
|
|
cx.simulate_click(chevron.center(), Modifiers::none());
|
|
draw(cx);
|
|
assert!(read(&view, cx, |app| app.crumb_menu.is_some()));
|
|
cx.simulate_mouse_down(
|
|
gpui_kit::point(px(700.), px(600.)),
|
|
MouseButton::Left,
|
|
Modifiers::none(),
|
|
);
|
|
cx.simulate_mouse_up(
|
|
gpui_kit::point(px(700.), px(600.)),
|
|
MouseButton::Left,
|
|
Modifiers::none(),
|
|
);
|
|
draw(cx);
|
|
assert!(read(&view, cx, |app| app.crumb_menu.is_none()));
|
|
}
|
|
|
|
fn names_at(names: &[String], index: usize) -> String {
|
|
names.get(index).cloned().unwrap_or_default()
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn marking_a_directory_marks_everything_inside_it(cx: &mut TestAppContext) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
draw(cx);
|
|
let crumbs = |view: &Entity<Disktree>, cx: &mut Window, rel: &str| {
|
|
let path = temp.path().join(rel);
|
|
read(view, cx, |app| app.crumbs_for_path(&path)).expect(rel)
|
|
};
|
|
let junk = crumbs(&view, cx, "junk");
|
|
let deeper = crumbs(&view, cx, "junk/deeper");
|
|
|
|
// Marked inside first, then the directory around it: one mark remains,
|
|
// and it covers the inner one.
|
|
update(&view, cx, |app, cx| app.toggle_mark(&deeper, cx));
|
|
update(&view, cx, |app, cx| app.toggle_mark(&junk, cx));
|
|
let marks = read(&view, cx, |app| {
|
|
app.marks
|
|
.items()
|
|
.iter()
|
|
.map(|item| item.path.clone())
|
|
.collect::<Vec<_>>()
|
|
});
|
|
assert_eq!(
|
|
marks,
|
|
vec![temp.path().join("junk")],
|
|
"the inner mark is absorbed"
|
|
);
|
|
|
|
// Every tile inside it is drawn marked: the ones below the mark are
|
|
// "covered", which paints the same fill and label.
|
|
let mosaic = update(&view, cx, |app, _| app.prepare());
|
|
let (inside, covered) = update(&view, cx, |app, _| {
|
|
let tiles = app.layout().map(<[Tile]>::to_vec).unwrap_or_default();
|
|
let inside: Vec<bool> = tiles
|
|
.iter()
|
|
.zip(&mosaic.tiles)
|
|
.filter(|(tile, _)| {
|
|
tile.crumbs().starts_with(&junk) && tile.crumbs() != junk
|
|
})
|
|
.map(|(_, deco)| deco.covered)
|
|
.collect();
|
|
(inside.len(), inside.iter().all(|covered| *covered))
|
|
});
|
|
assert!(inside >= 2, "blob.bin and deeper are drawn inside junk");
|
|
assert!(covered, "every tile inside junk goes with it");
|
|
|
|
// Marking something inside it is refused, and says why.
|
|
update(&view, cx, |app, cx| app.toggle_mark(&deeper, cx));
|
|
let (count, notice) = read(&view, cx, |app| {
|
|
(
|
|
app.marks.len(),
|
|
app.notice.as_ref().map(|(text, _)| text.clone()),
|
|
)
|
|
});
|
|
assert_eq!(count, 1);
|
|
assert!(notice.is_some_and(|text| text.contains("goes with the marked")));
|
|
|
|
// Unmarking the directory unmarks everything.
|
|
update(&view, cx, |app, cx| app.toggle_mark(&junk, cx));
|
|
assert!(read(&view, cx, |app| app.marks.is_empty()));
|
|
}
|
|
|
|
/// `<` and `>` retrace the directories visited, are disabled when there is
|
|
/// nowhere to go, and a fresh move ends what was ahead.
|
|
#[gpui_kit::test]
|
|
fn back_and_forward_retrace_where_you_have_been(cx: &mut TestAppContext) {
|
|
use gpui_kit::Modifiers;
|
|
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
cx.simulate_resize(gpui_kit::size(px(1400.), px(900.)));
|
|
draw(cx);
|
|
let can = |view: &Entity<Disktree>, cx: &Window| {
|
|
read(view, cx, |app| (app.can_go_back(), app.can_go_forward()))
|
|
};
|
|
assert_eq!(can(&view, cx), (false, false), "nowhere to go yet");
|
|
|
|
let (junk, deeper, keep) = update(&view, cx, |app, cx| {
|
|
let junk = child_crumbs(app, &[], "junk");
|
|
let deeper = child_crumbs(app, &junk, "deeper");
|
|
let keep = child_crumbs(app, &[], "keep");
|
|
app.select(Some(deeper.clone()), cx);
|
|
app.descend(cx);
|
|
(junk, deeper, keep)
|
|
});
|
|
draw(cx);
|
|
assert_eq!(can(&view, cx), (true, false));
|
|
|
|
// Hovering `<` shows the card for where it goes, as hovering a tile
|
|
// does: here, the scanned root. It hangs below the button, never on it.
|
|
let back = cx
|
|
.debug_bounds("history-back")
|
|
.expect("the button is drawn");
|
|
cx.simulate_mouse_move(back.center(), None, Modifiers::none());
|
|
draw(cx);
|
|
let card = cx.debug_bounds("history-tip").expect("the card is shown");
|
|
assert!(card.top() >= back.bottom(), "{card:?} covers {back:?}");
|
|
assert_eq!(
|
|
read(&view, cx, |app| app.history_target(true)),
|
|
Some((0, Vec::new()))
|
|
);
|
|
|
|
let click = |cx: &mut Window, selector: &'static str| {
|
|
let bounds = cx.debug_bounds(selector).expect("the button is drawn");
|
|
cx.simulate_click(bounds.center(), Modifiers::none());
|
|
draw(cx);
|
|
};
|
|
click(cx, "history-back");
|
|
assert_eq!(
|
|
read(&view, cx, |app| app.crumbs.clone()),
|
|
Vec::<usize>::new()
|
|
);
|
|
assert_eq!(can(&view, cx), (false, true), "back at the start");
|
|
|
|
click(cx, "history-forward");
|
|
assert_eq!(read(&view, cx, |app| app.crumbs.clone()), deeper);
|
|
assert_eq!(can(&view, cx), (true, false));
|
|
|
|
// Up a level is a move of its own, and the keys retrace it too.
|
|
press(cx, "backspace");
|
|
assert_eq!(read(&view, cx, |app| app.crumbs.clone()), junk);
|
|
press(cx, "alt-left");
|
|
assert_eq!(read(&view, cx, |app| app.crumbs.clone()), deeper);
|
|
press(cx, "alt-left");
|
|
assert_eq!(
|
|
read(&view, cx, |app| app.crumbs.clone()),
|
|
Vec::<usize>::new()
|
|
);
|
|
press(cx, "alt-right");
|
|
assert_eq!(read(&view, cx, |app| app.crumbs.clone()), deeper);
|
|
|
|
// Going somewhere new from the middle of the history drops what was
|
|
// ahead of it, as in a browser.
|
|
press(cx, "alt-left");
|
|
update(&view, cx, |app, cx| app.go_to(keep, cx));
|
|
draw(cx);
|
|
assert_eq!(can(&view, cx), (true, false), "the forward trail is gone");
|
|
press(cx, "alt-left");
|
|
assert_eq!(
|
|
read(&view, cx, |app| app.crumbs.clone()),
|
|
Vec::<usize>::new()
|
|
);
|
|
}
|
|
|
|
/// Regression: children are ordered by the metric, so switching between
|
|
/// Size and Files reorders them. The directory on screen and the selection
|
|
/// are found again by path, rather than following their old positions into
|
|
/// a sibling.
|
|
#[gpui_kit::test]
|
|
fn switching_the_metric_keeps_the_directory_and_the_selection(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = tempfile::TempDir::new().expect("tempdir");
|
|
let root = temp.path();
|
|
// Largest by size, but fewest files: the two swap places.
|
|
std::fs::create_dir_all(root.join("big")).expect("mkdir");
|
|
std::fs::write(root.join("big/one.bin"), vec![b'x'; 500_000])
|
|
.expect("write");
|
|
std::fs::write(root.join("big/two.bin"), vec![b'x'; 1_000]).expect("write");
|
|
for index in 0..5 {
|
|
let file = root.join(format!("many/{index}.txt"));
|
|
std::fs::create_dir_all(file.parent().expect("parent")).expect("mkdir");
|
|
std::fs::write(&file, b"x").expect("write");
|
|
}
|
|
let (view, cx) = view_over(root, cx);
|
|
draw(cx);
|
|
|
|
update(&view, cx, |app, cx| {
|
|
let big = child_crumbs(app, &[], "big");
|
|
assert_eq!(big, vec![0], "largest first by size");
|
|
app.go_to(big.clone(), cx);
|
|
let one = child_crumbs(app, &big, "one.bin");
|
|
app.select(Some(one), cx);
|
|
});
|
|
draw(cx);
|
|
|
|
update(&view, cx, |app, cx| app.set_mode(1, cx));
|
|
draw(cx);
|
|
let (here, selected) = read(&view, cx, |app| {
|
|
(
|
|
app.current_path(),
|
|
app.selected
|
|
.as_deref()
|
|
.and_then(|crumbs| app.path_at(crumbs)),
|
|
)
|
|
});
|
|
assert_eq!(here, root.join("big"));
|
|
assert_eq!(selected, Some(root.join("big/one.bin")));
|
|
|
|
update(&view, cx, |app, cx| app.set_mode(0, cx));
|
|
draw(cx);
|
|
assert_eq!(read(&view, cx, Disktree::current_path), root.join("big"));
|
|
}
|
|
|
|
/// Escape stops a first scan. What the walk found so far is not shown as a
|
|
/// tree, a late result is ignored, and `r` starts over.
|
|
#[gpui_kit::test]
|
|
fn escape_cancels_the_first_scan_and_r_starts_it_again(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let root = temp.path().to_path_buf();
|
|
let (view, cx) =
|
|
cx.add_window_view(move |_, cx| Disktree::new(root, options(), 3, cx));
|
|
let focus = view.read_with(cx, |app, _| app.focus.clone());
|
|
cx.update(|window, cx| window.focus(&focus, cx));
|
|
draw(cx);
|
|
let epoch = read(&view, cx, |app| app.scan_epoch);
|
|
|
|
press(cx, "escape");
|
|
let (scanning, cancelled) = read(&view, cx, |app| {
|
|
(app.scan.is_some(), app.progress.cancelled)
|
|
});
|
|
assert!(!scanning, "the walk was dropped");
|
|
assert!(cancelled, "the panel can say it stopped");
|
|
std::thread::sleep(std::time::Duration::from_millis(50));
|
|
let polling = update(&view, cx, |app, cx| app.poll_scan_once(epoch, cx));
|
|
assert!(!polling, "the old poller stops");
|
|
assert!(read(&view, cx, |app| app.tree().is_none()));
|
|
draw(cx);
|
|
|
|
press(cx, "r");
|
|
finish_scan(&view, cx);
|
|
assert!(read(&view, cx, |app| app.tree().is_some()));
|
|
}
|
|
|
|
/// Escape stops a widening scan and keeps the tree it started from.
|
|
#[gpui_kit::test]
|
|
fn escape_cancels_widening_and_keeps_the_tree_on_screen(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let inner = temp.path().join("junk");
|
|
let (view, cx) = view_over(&inner, cx);
|
|
update(&view, cx, |app, _| {
|
|
app.disk_root = Some(temp.path().to_path_buf());
|
|
});
|
|
let before = read(&view, cx, |app| app.tree().map(|tree| tree.files));
|
|
|
|
press(cx, "g");
|
|
assert!(read(&view, cx, |app| app.scan.is_some()));
|
|
press(cx, "escape");
|
|
let (scanning, root, scan_root, files) = read(&view, cx, |app| {
|
|
(
|
|
app.scan.is_some(),
|
|
app.root_path.clone(),
|
|
app.scan_root.clone(),
|
|
app.tree().map(|tree| tree.files),
|
|
)
|
|
});
|
|
assert!(!scanning);
|
|
assert_eq!(root, inner);
|
|
assert_eq!(scan_root, inner, "the trail stops showing a widening");
|
|
assert_eq!(files, before, "the tree on screen is unchanged");
|
|
}
|
|
|
|
/// The mouse's back and forward buttons retrace the same history as
|
|
/// alt-arrows and the header buttons, and only on the explore screen.
|
|
#[gpui_kit::test]
|
|
fn mouse_side_buttons_go_back_and_forward(cx: &mut TestAppContext) {
|
|
use gpui_kit::{Modifiers, MouseButton, NavigationDirection};
|
|
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
cx.simulate_resize(gpui_kit::size(px(1400.), px(900.)));
|
|
draw(cx);
|
|
|
|
let (junk, deeper) = update(&view, cx, |app, cx| {
|
|
let junk = child_crumbs(app, &[], "junk");
|
|
let deeper = child_crumbs(app, &junk, "deeper");
|
|
app.select(Some(junk.clone()), cx);
|
|
app.descend(cx);
|
|
app.select(Some(deeper.clone()), cx);
|
|
app.descend(cx);
|
|
(junk, deeper)
|
|
});
|
|
draw(cx);
|
|
assert_eq!(read(&view, cx, |app| app.crumbs.clone()), deeper);
|
|
|
|
// Over the mosaic, buttons 8 and 9 step the history, as alt-arrows do.
|
|
let mosaic = cx.debug_bounds("treemap").expect("the mosaic is drawn");
|
|
let at = mosaic.center();
|
|
let press_button = |cx: &mut Window, button: MouseButton| {
|
|
cx.simulate_mouse_move(at, None, Modifiers::none());
|
|
cx.simulate_mouse_down(at, button, Modifiers::none());
|
|
cx.simulate_mouse_up(at, button, Modifiers::none());
|
|
draw(cx);
|
|
};
|
|
press_button(cx, MouseButton::Navigate(NavigationDirection::Back));
|
|
assert_eq!(read(&view, cx, |app| app.crumbs.clone()), junk);
|
|
press_button(cx, MouseButton::Navigate(NavigationDirection::Forward));
|
|
assert_eq!(read(&view, cx, |app| app.crumbs.clone()), deeper);
|
|
|
|
// On the review screen the same press changes nothing: the marked list
|
|
// is not somewhere the history can take you back to.
|
|
update(&view, cx, |app, cx| app.toggle_mark(&junk, cx));
|
|
press(cx, "c");
|
|
assert_eq!(read(&view, cx, |app| app.screen), Screen::Review);
|
|
press_button(cx, MouseButton::Navigate(NavigationDirection::Back));
|
|
assert_eq!(read(&view, cx, |app| app.crumbs.clone()), deeper);
|
|
assert_eq!(read(&view, cx, |app| app.screen), Screen::Review);
|
|
}
|
|
|
|
/// The restart as administrator reopens the same root and options: every
|
|
/// flag it writes is one the command line reads back.
|
|
#[test]
|
|
fn restart_arguments_parse_back_to_the_same_scan() {
|
|
use disktree_core::tree::Metric;
|
|
let temp = tempfile::TempDir::new().expect("tempdir");
|
|
let root = temp.path().join("a folder");
|
|
std::fs::create_dir(&root).expect("mkdir");
|
|
let root = dunce::canonicalize(&root).expect("canonical root");
|
|
let changed = ScanOptions {
|
|
apparent_size: true,
|
|
follow_links: true,
|
|
include_hidden: false,
|
|
one_filesystem: false,
|
|
metric: Metric::Files,
|
|
threads: disktree_core::scan_threads::ScanThreads {
|
|
max_threads: 8,
|
|
adaptive: true,
|
|
retained_throughput: 0.85,
|
|
system_cpu_limit: Some(0.70),
|
|
},
|
|
..ScanOptions::default()
|
|
};
|
|
for (options, depth) in [(changed, 5), (ScanOptions::default(), 1)] {
|
|
let args = crate::state::restart_args(&options, depth, &root);
|
|
let parsed = crate::parse_args(args.into_iter()).expect("parses");
|
|
assert_eq!(parsed.root, root);
|
|
assert_eq!(parsed.depth, depth);
|
|
let got = &parsed.options;
|
|
assert_eq!(got.threads.max_threads, options.threads.max_threads);
|
|
assert_eq!(got.threads.adaptive, options.threads.adaptive);
|
|
assert!(
|
|
(got.threads.retained_throughput
|
|
- options.threads.retained_throughput)
|
|
.abs()
|
|
< f64::EPSILON
|
|
);
|
|
assert_eq!(
|
|
got.threads.system_cpu_limit,
|
|
options.threads.system_cpu_limit
|
|
);
|
|
assert_eq!(
|
|
(
|
|
got.apparent_size,
|
|
got.follow_links,
|
|
got.include_hidden,
|
|
got.one_filesystem,
|
|
got.metric,
|
|
),
|
|
(
|
|
options.apparent_size,
|
|
options.follow_links,
|
|
options.include_hidden,
|
|
options.one_filesystem,
|
|
options.metric,
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn power_efficiency_menu_saves_without_discarding_the_tree(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
use crate::power::{self, PowerEfficiency as Power};
|
|
use gpui_kit::Modifiers;
|
|
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let config = tempfile::tempdir().expect("config");
|
|
let path = config.path().join("power-efficiency");
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
cx.simulate_resize(gpui_kit::size(px(900.), px(600.)));
|
|
update(&view, cx, |app, _| {
|
|
app.power_settings_path = Some(path.clone());
|
|
// Enough CPUs that every preset is offered, whatever runs the test.
|
|
app.cpu_threads = 18;
|
|
});
|
|
let epoch = read(&view, cx, |app| app.scan_epoch);
|
|
for preset in Power::ALL {
|
|
draw(cx);
|
|
let button = cx.debug_bounds("power-efficiency").expect("control");
|
|
cx.simulate_click(button.center(), Modifiers::none());
|
|
draw(cx);
|
|
let choice = cx.debug_bounds(preset.key()).expect("preset");
|
|
cx.simulate_click(choice.center(), Modifiers::none());
|
|
draw(cx);
|
|
assert_eq!(power::load(&path).expect("saved"), preset);
|
|
read(&view, cx, |app| {
|
|
assert_eq!(app.power_choice, Some(preset));
|
|
assert_eq!(
|
|
app.options.threads.max_threads,
|
|
preset.threads(app.cpu_threads)
|
|
);
|
|
assert!(!app.options.threads.adaptive);
|
|
assert!(app.power_menu.is_none());
|
|
assert_eq!(app.scan_epoch, epoch);
|
|
assert!(app.tree.is_some());
|
|
});
|
|
}
|
|
// Persistence failure must not masquerade as a saved preference.
|
|
update(&view, cx, |app, cx| {
|
|
app.power_settings_path = Some(config.path().to_owned());
|
|
app.set_power_efficiency(Power::Miser, cx);
|
|
});
|
|
assert!(read(&view, cx, |app| app.notice.as_ref().is_some_and(
|
|
|(message, _)| message.contains("could not be saved")
|
|
)));
|
|
update(&view, cx, Disktree::start_scan);
|
|
assert_eq!(read(&view, cx, |app| app.scan_epoch), epoch + 1);
|
|
}
|
|
|
|
#[gpui_kit::test]
|
|
fn the_power_menu_offers_only_what_the_cpus_can_tell_apart(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
use crate::power::PowerEfficiency as Power;
|
|
use gpui_kit::Modifiers;
|
|
|
|
cx.update(gpui_omarchy::init);
|
|
let temp = fixture();
|
|
let config = tempfile::tempdir().expect("config");
|
|
let (view, cx) = view_over(temp.path(), cx);
|
|
cx.simulate_resize(gpui_kit::size(px(900.), px(600.)));
|
|
update(&view, cx, |app, _| {
|
|
app.power_settings_path = Some(config.path().join("power"));
|
|
// Aggressive and Drain My Battery would both run four workers.
|
|
app.cpu_threads = 4;
|
|
app.power_choice = Some(Power::Balanced);
|
|
});
|
|
draw(cx);
|
|
let toggle = cx.debug_bounds("power-efficiency").expect("control");
|
|
cx.simulate_mouse_move(toggle.center(), None, Modifiers::none());
|
|
cx.simulate_click(toggle.center(), Modifiers::none());
|
|
draw(cx);
|
|
assert_eq!(read(&view, cx, |app| app.power_menu), Some(1));
|
|
|
|
// The pointer takes the highlight, and the check stays on what is saved.
|
|
let miser = cx.debug_bounds(Power::Miser.key()).expect("row");
|
|
cx.simulate_mouse_move(miser.center(), None, Modifiers::none());
|
|
draw(cx);
|
|
assert_eq!(read(&view, cx, |app| app.power_menu), Some(0));
|
|
let balanced = cx.debug_bounds(Power::Balanced.key()).expect("row");
|
|
let check = cx.debug_bounds("power-check").expect("check");
|
|
assert!(balanced.contains(&check.center()), "check on {check:?}");
|
|
|
|
// A disabled row ignores the click and leaves the menu to be dismissed.
|
|
let drain = cx.debug_bounds(Power::DrainMyBattery.key()).expect("row");
|
|
cx.simulate_click(drain.center(), Modifiers::none());
|
|
draw(cx);
|
|
read(&view, cx, |app| {
|
|
assert_eq!(app.power_choice, Some(Power::Balanced));
|
|
assert!(app.notice.is_none());
|
|
});
|
|
|
|
// The arrows step over what is not offered, and Enter chooses.
|
|
update(&view, cx, |app, cx| {
|
|
app.power_menu = None;
|
|
app.toggle_power_menu(cx);
|
|
});
|
|
press(cx, "down");
|
|
assert_eq!(read(&view, cx, |app| app.power_menu), Some(1));
|
|
press(cx, "up");
|
|
assert_eq!(read(&view, cx, |app| app.power_menu), Some(0));
|
|
press(cx, "enter");
|
|
read(&view, cx, |app| {
|
|
assert_eq!(app.power_choice, Some(Power::Miser));
|
|
assert_eq!(app.options.threads.max_threads, 2);
|
|
assert!(app.power_menu.is_none());
|
|
});
|
|
|
|
// The button closes what it opened, rather than the press outside the
|
|
// menu closing it only for the click to open it again.
|
|
draw(cx);
|
|
let toggle = cx.debug_bounds("power-efficiency").expect("control");
|
|
cx.simulate_mouse_move(toggle.center(), None, Modifiers::none());
|
|
cx.simulate_click(toggle.center(), Modifiers::none());
|
|
draw(cx);
|
|
assert!(read(&view, cx, |app| app.power_menu.is_some()));
|
|
cx.simulate_click(toggle.center(), Modifiers::none());
|
|
draw(cx);
|
|
assert!(read(&view, cx, |app| app.power_menu.is_none()));
|
|
}
|