Skip to content

Commit 8e0fa69

Browse files
committed
add tests for editor launch and dialog improvements
Add comprehensive test coverage for the wait_for_completion functionality and InfoDialogKind enum variants. Tests verify proper handling of successful editor launches, exit status reporting, and missing command detection in both background and blocking modes.
1 parent dde7af8 commit 8e0fa69

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

src/commands/interactive/dialog.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,47 @@ pub(crate) enum Dialog {
542542
Create(CreateDialog),
543543
Merge(MergeDialog),
544544
}
545+
546+
#[cfg(test)]
547+
mod tests {
548+
use super::*;
549+
550+
#[test]
551+
fn dialog_info_with_info_kind() {
552+
let dialog = Dialog::Info {
553+
message: "Test message".to_string(),
554+
kind: InfoDialogKind::Info,
555+
};
556+
557+
match dialog {
558+
Dialog::Info { message, kind } => {
559+
assert_eq!(message, "Test message");
560+
assert!(matches!(kind, InfoDialogKind::Info));
561+
}
562+
_ => panic!("Expected Info dialog"),
563+
}
564+
}
565+
566+
#[test]
567+
fn dialog_info_with_error_kind() {
568+
let dialog = Dialog::Info {
569+
message: "Error message".to_string(),
570+
kind: InfoDialogKind::Error,
571+
};
572+
573+
match dialog {
574+
Dialog::Info { message, kind } => {
575+
assert_eq!(message, "Error message");
576+
assert!(matches!(kind, InfoDialogKind::Error));
577+
}
578+
_ => panic!("Expected Info dialog"),
579+
}
580+
}
581+
582+
#[test]
583+
fn info_dialog_kind_is_copy() {
584+
let kind = InfoDialogKind::Info;
585+
let _copy = kind;
586+
let _another_copy = kind; // Should compile due to Copy trait
587+
}
588+
}

src/editor/launch.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,69 @@ mod tests {
160160
let outcome = launch_editor(request);
161161
assert_eq!(outcome.status, EditorLaunchStatus::EditorMissing);
162162
}
163+
164+
#[test]
165+
fn wait_for_completion_succeeds_with_valid_command() {
166+
let dir = TempDir::new().expect("tempdir");
167+
let worktree_path = dir.path();
168+
let request = LaunchRequest {
169+
preference: &EditorPreference {
170+
command: OsString::from("true"),
171+
args: Vec::new(),
172+
source: crate::editor::EditorPreferenceSource::Environment {
173+
variable: crate::editor::EditorEnvVar::Editor,
174+
},
175+
},
176+
worktree_name: "feature",
177+
worktree_path,
178+
wait_for_completion: true,
179+
};
180+
181+
let outcome = launch_editor(request);
182+
assert_eq!(outcome.status, EditorLaunchStatus::Success);
183+
}
184+
185+
#[test]
186+
fn wait_for_completion_reports_exit_status() {
187+
let dir = TempDir::new().expect("tempdir");
188+
let worktree_path = dir.path();
189+
let request = LaunchRequest {
190+
preference: &EditorPreference {
191+
command: OsString::from("false"),
192+
args: Vec::new(),
193+
source: crate::editor::EditorPreferenceSource::Environment {
194+
variable: crate::editor::EditorEnvVar::Editor,
195+
},
196+
},
197+
worktree_name: "feature",
198+
worktree_path,
199+
wait_for_completion: true,
200+
};
201+
202+
let outcome = launch_editor(request);
203+
assert_eq!(outcome.status, EditorLaunchStatus::SpawnError);
204+
assert!(outcome.message.contains("exited with status"));
205+
}
206+
207+
#[test]
208+
fn wait_for_completion_reports_missing_command() {
209+
let dir = TempDir::new().expect("tempdir");
210+
let worktree_path = dir.path();
211+
let request = LaunchRequest {
212+
preference: &EditorPreference {
213+
command: OsString::from("unlikely-editor-command"),
214+
args: Vec::new(),
215+
source: crate::editor::EditorPreferenceSource::Environment {
216+
variable: crate::editor::EditorEnvVar::Editor,
217+
},
218+
},
219+
worktree_name: "feature",
220+
worktree_path,
221+
wait_for_completion: true,
222+
};
223+
224+
let outcome = launch_editor(request);
225+
assert_eq!(outcome.status, EditorLaunchStatus::EditorMissing);
226+
assert!(outcome.message.contains("was not found on PATH"));
227+
}
163228
}

0 commit comments

Comments
 (0)