1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
use crate::input::input_handler::InputMode;
use crate::input::Input;
use crate::process::exit_status::ExitStatus;
use crate::process::process_module::ProcessModule;
use crate::process::process_result::ProcessResult;
use crate::process::state::State;
use crate::todo_file::TodoFile;
use crate::view::view_data::ViewData;
use crate::view::View;
pub struct ConfirmRebase {
view_data: ViewData,
}
impl ProcessModule for ConfirmRebase {
fn build_view_data(&mut self, view: &View<'_>, _: &TodoFile) -> &ViewData {
let view_width = view.get_view_size().width();
let view_height = view.get_view_size().height();
self.view_data.set_view_size(view_width, view_height);
self.view_data.rebuild();
&self.view_data
}
fn handle_input(&mut self, view: &mut View<'_>, _: &mut TodoFile) -> ProcessResult {
let input = view.get_input(InputMode::Confirm);
let mut result = ProcessResult::new().input(input);
match input {
Input::Yes => {
result = result.exit_status(ExitStatus::Good);
},
Input::No => {
result = result.state(State::List);
},
_ => {},
}
result
}
}
impl ConfirmRebase {
pub(crate) fn new() -> Self {
Self {
view_data: ViewData::new_confirm("Are you sure you want to rebase"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::assert_process_result;
use crate::assert_rendered_output;
use crate::process::testutil::{process_module_test, TestContext, ViewState};
#[test]
#[serial_test::serial]
fn build_view_data() {
process_module_test(
&["pick aaa comment"],
ViewState::default(),
&[],
|test_context: TestContext<'_>| {
let mut module = ConfirmRebase::new();
let view_data = test_context.build_view_data(&mut module);
assert_rendered_output!(view_data, "{TITLE}", "{PROMPT}", "Are you sure you want to rebase");
},
);
}
#[test]
#[serial_test::serial]
fn handle_input_yes() {
process_module_test(
&["pick aaa comment"],
ViewState::default(),
&[Input::Yes],
|mut test_context: TestContext<'_>| {
let mut module = ConfirmRebase::new();
assert_process_result!(
test_context.handle_input(&mut module),
input = Input::Yes,
exit_status = ExitStatus::Good
);
assert_eq!(test_context.rebase_todo_file.get_lines().len(), 1);
},
);
}
#[test]
#[serial_test::serial]
fn handle_input_no() {
process_module_test(
&["pick aaa comment"],
ViewState::default(),
&[Input::No],
|mut test_context: TestContext<'_>| {
let mut module = ConfirmRebase::new();
assert_process_result!(
test_context.handle_input(&mut module),
input = Input::No,
state = State::List
);
},
);
}
#[test]
#[serial_test::serial]
fn handle_input_any_key() {
process_module_test(
&["pick aaa comment"],
ViewState::default(),
&[Input::Character('x')],
|mut test_context: TestContext<'_>| {
let mut module = ConfirmRebase::new();
assert_process_result!(
test_context.handle_input(&mut module),
input = Input::No,
state = State::List
);
},
);
}
#[test]
#[serial_test::serial]
fn handle_input_resize() {
process_module_test(
&["pick aaa comment"],
ViewState::default(),
&[Input::Resize],
|mut test_context: TestContext<'_>| {
let mut module = ConfirmRebase::new();
assert_process_result!(test_context.handle_input(&mut module), input = Input::Resize);
},
);
}
}
|