story-kit: merge 106_story_test_coverage_http_settings_rs_to_80
This commit is contained in:
@@ -77,12 +77,95 @@ pub fn get_editor_command_from_store(ctx: &AppContext) -> Option<String> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::http::context::AppContext;
|
use crate::http::context::AppContext;
|
||||||
|
use std::sync::Arc;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
fn test_ctx(dir: &TempDir) -> AppContext {
|
fn test_ctx(dir: &TempDir) -> AppContext {
|
||||||
AppContext::new_test(dir.path().to_path_buf())
|
AppContext::new_test(dir.path().to_path_buf())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_api(dir: &TempDir) -> SettingsApi {
|
||||||
|
SettingsApi {
|
||||||
|
ctx: Arc::new(AppContext::new_test(dir.path().to_path_buf())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn get_editor_returns_none_when_unset() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let api = make_api(&dir);
|
||||||
|
let result = api.get_editor().await.unwrap();
|
||||||
|
assert!(result.0.editor_command.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn set_editor_stores_command() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let api = make_api(&dir);
|
||||||
|
let payload = Json(EditorCommandPayload {
|
||||||
|
editor_command: Some("zed".to_string()),
|
||||||
|
});
|
||||||
|
let result = api.set_editor(payload).await.unwrap();
|
||||||
|
assert_eq!(result.0.editor_command, Some("zed".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn set_editor_clears_command_on_null() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let api = make_api(&dir);
|
||||||
|
api.set_editor(Json(EditorCommandPayload {
|
||||||
|
editor_command: Some("zed".to_string()),
|
||||||
|
}))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let result = api
|
||||||
|
.set_editor(Json(EditorCommandPayload {
|
||||||
|
editor_command: None,
|
||||||
|
}))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert!(result.0.editor_command.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn set_editor_clears_command_on_empty_string() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let api = make_api(&dir);
|
||||||
|
let result = api
|
||||||
|
.set_editor(Json(EditorCommandPayload {
|
||||||
|
editor_command: Some(String::new()),
|
||||||
|
}))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert!(result.0.editor_command.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn set_editor_trims_whitespace_only() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let api = make_api(&dir);
|
||||||
|
let result = api
|
||||||
|
.set_editor(Json(EditorCommandPayload {
|
||||||
|
editor_command: Some(" ".to_string()),
|
||||||
|
}))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert!(result.0.editor_command.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn get_editor_returns_value_after_set() {
|
||||||
|
let dir = TempDir::new().unwrap();
|
||||||
|
let api = make_api(&dir);
|
||||||
|
api.set_editor(Json(EditorCommandPayload {
|
||||||
|
editor_command: Some("cursor".to_string()),
|
||||||
|
}))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let result = api.get_editor().await.unwrap();
|
||||||
|
assert_eq!(result.0.editor_command, Some("cursor".to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn editor_command_defaults_to_null() {
|
fn editor_command_defaults_to_null() {
|
||||||
let dir = TempDir::new().unwrap();
|
let dir = TempDir::new().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user