Skip to content

Commit 0e8bdb9

Browse files
committed
Implement Rust testing framework
Related to CapSoftware#184 Implement a scalable testing system for Rust functions in the Cap desktop application. * **Add test cases**: Create a new file `apps/desktop/src-tauri/tests/desktop_tests.rs` with test cases for `start_recording`, `stop_recording`, `copy_file_to_path`, `copy_screenshot_to_clipboard`, and `export_video`. * **Update package.json**: Add a new command `test:desktop` in `apps/desktop/package.json` to run the Rust tests using `cargo test --manifest-path src-tauri/Cargo.toml`.
1 parent aae824c commit 0e8bdb9

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

apps/desktop/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"dev": "dotenv -e ../../.env -- tauri dev",
66
"localdev": "dotenv -e ../../.env -- vinxi dev --port 3001",
77
"build": "vinxi build",
8-
"tauri": "tauri"
8+
"tauri": "tauri",
9+
"test:desktop": "cargo test --manifest-path src-tauri/Cargo.toml"
910
},
1011
"dependencies": {
1112
"@cap/database": "workspace:*",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#[cfg(test)]
2+
mod tests {
3+
use super::*;
4+
use tauri::AppHandle;
5+
use std::path::PathBuf;
6+
7+
#[tokio::test]
8+
async fn test_start_recording() {
9+
let app = AppHandle::default();
10+
let state = MutableState::default();
11+
let result = start_recording(app, state).await;
12+
assert!(result.is_ok());
13+
}
14+
15+
#[tokio::test]
16+
async fn test_stop_recording() {
17+
let app = AppHandle::default();
18+
let state = MutableState::default();
19+
let result = stop_recording(app, state).await;
20+
assert!(result.is_ok());
21+
}
22+
23+
#[tokio::test]
24+
async fn test_copy_file_to_path() {
25+
let app = AppHandle::default();
26+
let src = "test_src.txt".to_string();
27+
let dst = "test_dst.txt".to_string();
28+
let result = copy_file_to_path(app, src, dst).await;
29+
assert!(result.is_ok());
30+
}
31+
32+
#[tokio::test]
33+
async fn test_copy_screenshot_to_clipboard() {
34+
let app = AppHandle::default();
35+
let path = PathBuf::from("test_screenshot.png");
36+
let result = copy_screenshot_to_clipboard(app, path).await;
37+
assert!(result.is_ok());
38+
}
39+
40+
#[tokio::test]
41+
async fn test_export_video() {
42+
let app = AppHandle::default();
43+
let video_id = "test_video_id".to_string();
44+
let project = ProjectConfiguration::default();
45+
let progress = tauri::ipc::Channel::new(|_| Ok(()));
46+
let result = export_video(app, video_id, project, progress, true).await;
47+
assert!(result.is_ok());
48+
}
49+
}

0 commit comments

Comments
 (0)