Skip to content

Commit

Permalink
add tests for config-management sessionevents
Browse files Browse the repository at this point in the history
  • Loading branch information
gulbanana committed Jun 15, 2024
1 parent c7f18d1 commit 4a84ca1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src-tauri/src/worker/tests/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,6 @@ fn move_source() -> Result<()> {
Ok(())
}

// XXX need tests for branch/ref mutations
// XXX missing tests for:
// - branch/ref mutations
// - git interop
62 changes: 62 additions & 0 deletions src-tauri/src/worker/tests/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
worker::{Session, SessionEvent, WorkerSession},
};
use anyhow::Result;
use jj_cli::config::ConfigSource;
use std::{path::PathBuf, sync::mpsc::channel};

#[test]
Expand Down Expand Up @@ -329,3 +330,64 @@ fn query_rev_not_found() -> Result<()> {

Ok(())
}

#[test]
fn config_read() -> Result<()> {
let repo = mkrepo();

let (tx, rx) = channel::<SessionEvent>();
let (tx_load, rx_load) = channel::<Result<RepoConfig>>();
let (tx_read, rx_read) = channel::<Result<Vec<String>>>();

tx.send(SessionEvent::OpenWorkspace {
tx: tx_load,
wd: Some(repo.path().to_owned()),
})?;
tx.send(SessionEvent::ReadConfigArray {
tx: tx_read,
key: vec!["gg".into(), "ui".into(), "recent-workspaces".into()],
})?;
tx.send(SessionEvent::EndSession)?;

WorkerSession::default().handle_events(&rx)?;

_ = rx_load.recv()??;
let result = rx_read.recv()??;

assert!(!result.is_empty()); // it will contain the test-repo, at least

Ok(())
}

#[test]
fn config_write() -> Result<()> {
let repo = mkrepo();

let (tx, rx) = channel::<SessionEvent>();
let (tx_load, rx_load) = channel::<Result<RepoConfig>>();
let (tx_read, rx_read) = channel::<Result<Vec<String>>>();

tx.send(SessionEvent::OpenWorkspace {
tx: tx_load,
wd: Some(repo.path().to_owned()),
})?;
tx.send(SessionEvent::WriteConfigArray {
scope: ConfigSource::Repo,
key: vec!["gg".into(), "test".into()],
values: vec!["a".into(), "b".into()]
})?;
tx.send(SessionEvent::ReadConfigArray {
tx: tx_read,
key: vec!["gg".into(), "test".into()],
})?;
tx.send(SessionEvent::EndSession)?;

WorkerSession::default().handle_events(&rx)?;

_ = rx_load.recv()??;
let result = rx_read.recv()??;

assert_eq!(vec!["a".to_string(), "b".to_string()], result);

Ok(())
}

0 comments on commit 4a84ca1

Please sign in to comment.