Skip to content

Commit fd6a4ef

Browse files
committed
refactor(tests): follow other tests conventions
1 parent 31636c7 commit fd6a4ef

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

tests/cli/cli_external_actions.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,29 @@
55
66
use super::common::*;
77
use std::{fs, thread::sleep, time::Duration};
8-
use tempfile::TempDir;
98

109
// ANSI escape sequences for function keys
1110
const F8_KEY: &str = "\x1b[19~";
1211
const F9_KEY: &str = "\x1b[20~";
1312

13+
/// Helper to create a custom cable directory with external actions.
14+
fn write_toml_config(
15+
cable_dir: &std::path::Path,
16+
filename: &str,
17+
content: &str,
18+
) {
19+
let toml_path = cable_dir.join(filename);
20+
fs::write(&toml_path, content).unwrap();
21+
}
22+
1423
/// Tests that external actions execute properly when triggered by keybindings.
1524
#[test]
1625
fn test_external_action_lsman_with_f9() {
1726
let mut tester = PtyTester::new();
1827

19-
// Create a temporary directory for the custom cable
20-
let temp_dir = TempDir::new().unwrap();
21-
let cable_dir = temp_dir.path();
28+
// Use TARGET_DIR for consistency with other tests
29+
let cable_dir = std::path::Path::new(TARGET_DIR).join("custom_cable");
30+
fs::create_dir_all(&cable_dir).unwrap();
2231

2332
// Create a custom files.toml with external actions
2433
let files_toml_content = r#"
@@ -40,17 +49,15 @@ f8 = "thebatman"
4049
f9 = "lsman"
4150
4251
[actions.thebatman]
43-
description = "cats the file"
44-
command = "bat '{}'"
45-
env = { BAT_THEME = "ansi" }
52+
description = "show file content"
53+
command = "cat '{}'"
4654
4755
[actions.lsman]
4856
description = "show stats"
4957
command = "ls '{}'"
5058
"#;
5159

52-
let files_toml_path = cable_dir.join("files.toml");
53-
fs::write(&files_toml_path, files_toml_content).unwrap();
60+
write_toml_config(&cable_dir, "files.toml", files_toml_content);
5461

5562
// Use the LICENSE file as input since it exists in the repo
5663
let mut cmd = tv();
@@ -82,9 +89,8 @@ command = "ls '{}'"
8289
fn test_external_action_thebatman_with_f8() {
8390
let mut tester = PtyTester::new();
8491

85-
// Create a temporary directory for the custom cable
86-
let temp_dir = TempDir::new().unwrap();
87-
let cable_dir = temp_dir.path();
92+
let cable_dir = std::path::Path::new(TARGET_DIR).join("custom_cable_f8");
93+
fs::create_dir_all(&cable_dir).unwrap();
8894

8995
// Create a custom files.toml with external actions
9096
let files_toml_content = r#"
@@ -106,17 +112,15 @@ f8 = "thebatman"
106112
f9 = "lsman"
107113
108114
[actions.thebatman]
109-
description = "cats the file"
110-
command = "bat '{}'"
111-
env = { BAT_THEME = "ansi" }
115+
description = "show file content"
116+
command = "cat '{}'"
112117
113118
[actions.lsman]
114119
description = "show stats"
115120
command = "ls '{}'"
116121
"#;
117122

118-
let files_toml_path = cable_dir.join("files.toml");
119-
fs::write(&files_toml_path, files_toml_content).unwrap();
123+
write_toml_config(&cable_dir, "files.toml", files_toml_content);
120124

121125
// Use the LICENSE file as input since it exists in the repo
122126
let mut cmd = tv();
@@ -129,7 +133,7 @@ command = "ls '{}'"
129133
// Wait for the UI to load
130134
sleep(DEFAULT_DELAY);
131135

132-
// Send F8 to trigger the "thebatman" action (mapped to bat command)
136+
// Send F8 to trigger the "thebatman" action (mapped to cat command)
133137
tester.send(F8_KEY);
134138

135139
// Give time for the action to execute

0 commit comments

Comments
 (0)