@@ -171,7 +171,14 @@ impl Controller {
171
171
Action :: ExportCSV ( app_config_path) => {
172
172
self . handle_action ( Action :: GetTasks ) ;
173
173
let task_list = self . state . get_task_list ( ) ;
174
- let acp = app_config_path. join ( constants:: CSV_NAME ) ;
174
+ let acp = match app_config_path {
175
+ Some ( acp_option) => acp_option. join ( constants:: CSV_NAME ) ,
176
+ None => {
177
+ let temp_acp = get_app_config_path ( ) . expect ( "Could not get app config path" ) ;
178
+ temp_acp. join ( constants:: CSV_NAME )
179
+ }
180
+ } ;
181
+
175
182
let write_result = write_tasks_into_csv_file ( task_list, & acp) ;
176
183
177
184
match write_result {
@@ -192,18 +199,7 @@ impl Controller {
192
199
Screen :: Main => match key_code {
193
200
KeyCode :: Char ( 'a' ) => Action :: OpenAddScreen ,
194
201
KeyCode :: Char ( 'x' ) => Action :: RemoveTask ,
195
- // in order to test it
196
- KeyCode :: Char ( 'e' ) => {
197
- let app_config_path = get_app_config_path ( ) ;
198
- match app_config_path {
199
- Ok ( acp) => Action :: ExportCSV ( acp) ,
200
- Err ( _) => {
201
- self . state
202
- . set_error ( String :: from ( "Could not save csv file" ) ) ;
203
- Action :: Empty
204
- }
205
- }
206
- }
202
+ KeyCode :: Char ( 'e' ) => Action :: ExportCSV ( None ) ,
207
203
KeyCode :: Up => Action :: MenuUp ,
208
204
KeyCode :: Down => Action :: MenuDown ,
209
205
KeyCode :: Esc => Action :: Exit ,
@@ -356,7 +352,7 @@ mod tests {
356
352
357
353
let mut csv_path = PathBuf :: new ( ) ;
358
354
csv_path. push ( "./test/csv/" ) ;
359
- controller. handle_action ( Action :: ExportCSV ( csv_path. clone ( ) ) ) ;
355
+ controller. handle_action ( Action :: ExportCSV ( Some ( csv_path. clone ( ) ) ) ) ;
360
356
let csv_file_exist = file_exists ( & csv_path, constants:: CSV_NAME ) ;
361
357
assert_eq ! ( csv_file_exist, true ) ;
362
358
0 commit comments