Improve testing of window edit state
This commit is contained in:
parent
a21dbdd0d6
commit
90102f22fd
1 changed files with 42 additions and 1 deletions
|
@ -442,7 +442,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_closing_window_via_mouse(executor: Arc<Deterministic>, cx: &mut TestAppContext) {
|
async fn test_window_edit_state(executor: Arc<Deterministic>, cx: &mut TestAppContext) {
|
||||||
let app_state = init(cx);
|
let app_state = init(cx);
|
||||||
app_state
|
app_state
|
||||||
.fs
|
.fs
|
||||||
|
@ -454,6 +454,7 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(cx.window_ids().len(), 1);
|
assert_eq!(cx.window_ids().len(), 1);
|
||||||
|
|
||||||
|
// When opening the workspace, the window is not in a edited state.
|
||||||
let workspace = cx.root_view::<Workspace>(cx.window_ids()[0]).unwrap();
|
let workspace = cx.root_view::<Workspace>(cx.window_ids()[0]).unwrap();
|
||||||
let editor = workspace.read_with(cx, |workspace, cx| {
|
let editor = workspace.read_with(cx, |workspace, cx| {
|
||||||
workspace
|
workspace
|
||||||
|
@ -464,11 +465,51 @@ mod tests {
|
||||||
});
|
});
|
||||||
assert!(!cx.is_window_edited(workspace.window_id()));
|
assert!(!cx.is_window_edited(workspace.window_id()));
|
||||||
|
|
||||||
|
// Editing a buffer marks the window as edited.
|
||||||
editor.update(cx, |editor, cx| editor.insert("EDIT", cx));
|
editor.update(cx, |editor, cx| editor.insert("EDIT", cx));
|
||||||
assert!(cx.is_window_edited(workspace.window_id()));
|
assert!(cx.is_window_edited(workspace.window_id()));
|
||||||
|
|
||||||
|
// Undoing the edit restores the window's edited state.
|
||||||
|
editor.update(cx, |editor, cx| editor.undo(&Default::default(), cx));
|
||||||
|
assert!(!cx.is_window_edited(workspace.window_id()));
|
||||||
|
|
||||||
|
// Redoing the edit marks the window as edited again.
|
||||||
|
editor.update(cx, |editor, cx| editor.redo(&Default::default(), cx));
|
||||||
|
assert!(cx.is_window_edited(workspace.window_id()));
|
||||||
|
|
||||||
|
// Closing the item restores the window's edited state.
|
||||||
|
let close = workspace.update(cx, |workspace, cx| {
|
||||||
|
drop(editor);
|
||||||
|
Pane::close_active_item(workspace, &Default::default(), cx).unwrap()
|
||||||
|
});
|
||||||
|
executor.run_until_parked();
|
||||||
|
cx.simulate_prompt_answer(workspace.window_id(), 1);
|
||||||
|
close.await.unwrap();
|
||||||
|
assert!(!cx.is_window_edited(workspace.window_id()));
|
||||||
|
|
||||||
|
// Opening the buffer again doesn't impact the window's edited state.
|
||||||
|
cx.update(|cx| open_paths(&[PathBuf::from("/root/a")], &app_state, cx))
|
||||||
|
.await;
|
||||||
|
let editor = workspace.read_with(cx, |workspace, cx| {
|
||||||
|
workspace
|
||||||
|
.active_item(cx)
|
||||||
|
.unwrap()
|
||||||
|
.downcast::<Editor>()
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
assert!(!cx.is_window_edited(workspace.window_id()));
|
||||||
|
|
||||||
|
// Editing the buffer marks the window as edited.
|
||||||
|
editor.update(cx, |editor, cx| editor.insert("EDIT", cx));
|
||||||
|
assert!(cx.is_window_edited(workspace.window_id()));
|
||||||
|
|
||||||
|
// Ensure closing the window via the mouse gets preempted due to the
|
||||||
|
// buffer having unsaved changes.
|
||||||
assert!(!cx.simulate_window_close(workspace.window_id()));
|
assert!(!cx.simulate_window_close(workspace.window_id()));
|
||||||
executor.run_until_parked();
|
executor.run_until_parked();
|
||||||
|
assert_eq!(cx.window_ids().len(), 1);
|
||||||
|
|
||||||
|
// The window is successfully closed after the user dismisses the prompt.
|
||||||
cx.simulate_prompt_answer(workspace.window_id(), 1);
|
cx.simulate_prompt_answer(workspace.window_id(), 1);
|
||||||
executor.run_until_parked();
|
executor.run_until_parked();
|
||||||
assert_eq!(cx.window_ids().len(), 0);
|
assert_eq!(cx.window_ids().len(), 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue