summaryrefslogtreecommitdiffstats
path: root/src/modules/list/tests/edit_mode.rs
blob: 4736a832de8ff40e62069eb9cde3091c9fd8f7c7 (plain)
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
use super::*;
use crate::{assert_rendered_output, assert_results, input::KeyCode, process::Artifact, test_helpers::testers};

#[test]
fn edit_with_edit_content() {
	testers::module(
		&["exec echo foo"],
		&[Event::from(StandardEvent::Edit)],
		|mut test_context| {
			let mut module = create_list(&create_config(), test_context.take_todo_file());
			assert_results!(
				test_context.handle_event(&mut module),
				Artifact::Event(Event::from(StandardEvent::Edit))
			);
			assert_eq!(module.state, ListState::Edit);
		},
	);
}

#[test]
fn edit_without_edit_content() {
	testers::module(
		&["pick aaa c1"],
		&[Event::from(StandardEvent::Edit)],
		|mut test_context| {
			let mut module = create_list(&create_config(), test_context.take_todo_file());
			assert_results!(
				test_context.handle_event(&mut module),
				Artifact::Event(Event::from(StandardEvent::Edit))
			);
			assert_eq!(module.state, ListState::Normal);
		},
	);
}

#[test]
fn edit_without_selected_line() {
	testers::module(&[], &[Event::from(StandardEvent::Edit)], |mut test_context| {
		let mut module = create_list(&create_config(), test_context.take_todo_file());
		assert_results!(
			test_context.handle_event(&mut module),
			Artifact::Event(Event::from(StandardEvent::Edit))
		);
		assert_eq!(module.state, ListState::Normal);
	});
}

#[test]
fn handle_event() {
	testers::module(
		&["exec foo"],
		&[
			Event::from(StandardEvent::Edit),
			Event::from(KeyCode::Backspace),
			Event::from(KeyCode::Enter),
		],
		|mut test_context| {
			let mut module = create_list(&create_config(), test_context.take_todo_file());
			_ = test_context.build_view_data(&mut module);
			_ = test_context.handle_all_events(&mut module);
			assert_eq!(module.todo_file.lock().get_line(0).unwrap().get_content(), "fo");
			assert_eq!(module.state, ListState::Normal);
		},
	);
}

#[test]
fn render() {
	testers::module(
		&["exec foo"],
		&[Event::from(StandardEvent::Edit)],
		|mut test_context| {
			let mut module = create_list(&create_config(), test_context.take_todo_file());
			_ = test_context.handle_all_events(&mut module);
			let view_data = test_context.build_view_data(&mut module);
			assert_rendered_output!(
				Style view_data,
				"{TITLE}",
				"{LEADING}",
				"{IndicatorColor}Modifying line: exec foo",
				"",
				"{BODY}",
				"{Normal,Dimmed}exec {Normal}foo{Normal,Underline}",
				"{TRAILING}",
				"{IndicatorColor}Enter to finish"
			);
		},
	);
}