mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-28 22:10:27 +08:00
bin(patch): Extend review tests
This commit is contained in:
@@ -684,9 +684,24 @@ mod test {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_can_be_constructed() -> Result<()> {
|
||||
fn app_with_single_hunk_can_be_constructed() -> Result<()> {
|
||||
let alice = test::fixtures::node_with_repo();
|
||||
let branch = test::fixtures::branch(&alice);
|
||||
let branch = test::fixtures::branch_with_line_added(&alice);
|
||||
|
||||
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
|
||||
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
|
||||
|
||||
let app = fixtures::app(&alice, patch)?;
|
||||
|
||||
assert_eq!(app.hunks().len(), 1);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_with_single_file_multiple_hunks_can_be_constructed() -> Result<()> {
|
||||
let alice = test::fixtures::node_with_repo();
|
||||
let branch = test::fixtures::branch_with_eof_removed(&alice);
|
||||
|
||||
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
|
||||
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
|
||||
@@ -701,7 +716,7 @@ mod test {
|
||||
#[test]
|
||||
fn first_hunk_is_selected_by_default() -> Result<()> {
|
||||
let alice = test::fixtures::node_with_repo();
|
||||
let branch = test::fixtures::branch(&alice);
|
||||
let branch = test::fixtures::branch_with_line_added(&alice);
|
||||
|
||||
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
|
||||
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
|
||||
@@ -716,7 +731,7 @@ mod test {
|
||||
#[test]
|
||||
fn hunk_can_be_selected() -> Result<()> {
|
||||
let alice = test::fixtures::node_with_repo();
|
||||
let branch = test::fixtures::branch(&alice);
|
||||
let branch = test::fixtures::branch_with_eof_removed(&alice);
|
||||
|
||||
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
|
||||
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
|
||||
@@ -730,4 +745,50 @@ mod test {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_file_single_hunk_can_be_accepted() -> Result<()> {
|
||||
let alice = test::fixtures::node_with_repo();
|
||||
let branch = test::fixtures::branch_with_line_added(&alice);
|
||||
|
||||
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
|
||||
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
|
||||
|
||||
let mut app = fixtures::app(&alice, patch)?;
|
||||
app.update(Message::Accept);
|
||||
|
||||
let hunks = app.hunks();
|
||||
let state = &hunks.get(0).unwrap().inner.state();
|
||||
|
||||
assert_eq!(**state, HunkState::Accepted);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_files_single_hunk_can_be_accepted() -> Result<()> {
|
||||
let alice = test::fixtures::node_with_repo();
|
||||
let branch = test::fixtures::branch_with_files_added(&alice);
|
||||
|
||||
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
|
||||
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
|
||||
|
||||
let mut app = fixtures::app(&alice, patch)?;
|
||||
app.update(Message::Accept);
|
||||
|
||||
app.update(Message::HunkChanged {
|
||||
state: TableState::new(Some(1)),
|
||||
});
|
||||
app.update(Message::Accept);
|
||||
|
||||
let hunks = app.hunks();
|
||||
let states = [
|
||||
hunks.get(0).unwrap().inner.state(),
|
||||
hunks.get(1).unwrap().inner.state(),
|
||||
];
|
||||
|
||||
assert_eq!(states, [&HunkState::Accepted, &HunkState::Accepted]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,11 @@ pub mod fixtures {
|
||||
checkout.branch_with([("README", b"Hello World!\nHello World!\n")])
|
||||
}
|
||||
|
||||
pub fn branch_with_files_added(node: &NodeWithRepo) -> BranchWith {
|
||||
let checkout = node.repo.checkout();
|
||||
checkout.branch_with([("CONTRIBUTE", b"TBD\n"), ("LICENSE", b"TBD\n")])
|
||||
}
|
||||
|
||||
pub fn patch<'a, 'g>(
|
||||
node: &'a NodeWithRepo,
|
||||
branch: &BranchWith,
|
||||
|
||||
Reference in New Issue
Block a user