Radish alpha
r
rad:z39mP9rQAaGmERfUMPULfPUi473tY
Radicle terminal user interface
Radicle
Git
bin(patch): Extend review tests
Erik Kundt committed 1 year ago
commit b399bc46261d90300750349a389bf1b8fd45cd9b
parent baf0335
2 files changed +70 -4
modified bin/commands/patch/review.rs
@@ -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(())
+
    }
}
modified bin/test.rs
@@ -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,