Skip to content

Commit 22230cb

Browse files
committed
Remove default styled option in render tests
This makes the addition of rendering styles in render based tests optional. By default styles are now omitted and must be explicitly enabled in the render options. To achieve this, existing tests have been updated to either remove unneeded styling assertions, or to enable style rendering.
1 parent c2b679b commit 22230cb

File tree

22 files changed

+334
-324
lines changed

22 files changed

+334
-324
lines changed

src/core/src/components/choice/tests.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use input::StandardEvent;
22
use rstest::rstest;
3-
use view::{assert_rendered_output, testutil::with_view_state};
3+
use view::{
4+
assert_rendered_output,
5+
testutil::{with_view_state, AssertRenderOptions},
6+
};
47

58
use super::*;
69

@@ -23,7 +26,7 @@ fn create_choices() -> Vec<(TestAction, char, String)> {
2326
fn render_options_no_prompt() {
2427
let mut module = Choice::new(create_choices());
2528
assert_rendered_output!(
26-
module.get_view_data(),
29+
Style module.get_view_data(),
2730
"{TITLE}",
2831
"{BODY}",
2932
"{Normal}a) Description A",
@@ -39,7 +42,7 @@ fn render_options_prompt() {
3942
let mut module = Choice::new(create_choices());
4043
module.set_prompt(vec![ViewLine::from("Prompt")]);
4144
assert_rendered_output!(
42-
module.get_view_data(),
45+
Style module.get_view_data(),
4346
"{TITLE}",
4447
"{LEADING}",
4548
"{Normal}Prompt",
@@ -60,14 +63,12 @@ fn valid_selection() {
6063
let choice = module.handle_event(Event::from('b'), &context.state);
6164
assert_eq!(choice.unwrap(), &TestAction::B);
6265
assert_rendered_output!(
63-
module.get_view_data(),
64-
"{TITLE}",
65-
"{BODY}",
66-
"{Normal}a) Description A",
67-
"{Normal}b) Description B",
68-
"{Normal}c) Description C",
66+
Body module.get_view_data(),
67+
"a) Description A",
68+
"b) Description B",
69+
"c) Description C",
6970
"",
70-
"{IndicatorColor}Please choose an option."
71+
"Please choose an option."
7172
);
7273
});
7374
}
@@ -79,14 +80,12 @@ fn invalid_selection_character() {
7980
let choice = module.handle_event(Event::from('z'), &context.state);
8081
assert!(choice.is_none());
8182
assert_rendered_output!(
82-
module.get_view_data(),
83-
"{TITLE}",
84-
"{BODY}",
85-
"{Normal}a) Description A",
86-
"{Normal}b) Description B",
87-
"{Normal}c) Description C",
83+
Body module.get_view_data(),
84+
"a) Description A",
85+
"b) Description B",
86+
"c) Description C",
8887
"",
89-
"{IndicatorColor}Invalid option selected. Please choose an option."
88+
"Invalid option selected. Please choose an option."
9089
);
9190
});
9291
}

src/core/src/components/confirm/tests.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use input::StandardEvent;
22
use rstest::rstest;
3-
use view::assert_rendered_output;
3+
use view::{assert_rendered_output, testutil::AssertRenderOptions};
44

55
use super::*;
66
use crate::testutil::create_test_keybindings;
@@ -12,11 +12,9 @@ fn render() {
1212
String::from("X"),
1313
]);
1414
assert_rendered_output!(
15-
Options AssertRenderOptions::INCLUDE_TRAILING_WHITESPACE,
15+
Options AssertRenderOptions::INCLUDE_TRAILING_WHITESPACE | AssertRenderOptions::BODY_ONLY,
1616
module.get_view_data(),
17-
"{TITLE}",
18-
"{BODY}",
19-
"{Normal}Prompt message (y,Z/n,X)? "
17+
"Prompt message (y,Z/n,X)? "
2018
);
2119
}
2220

src/core/src/components/edit/tests.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use view::assert_rendered_output;
1+
use view::{assert_rendered_output, testutil::AssertRenderOptions};
22

33
use super::*;
44

@@ -15,7 +15,7 @@ fn with_before_and_after_build() {
1515
},
1616
);
1717
assert_rendered_output!(
18-
Options AssertRenderOptions::INCLUDE_TRAILING_WHITESPACE,
18+
Options AssertRenderOptions::INCLUDE_TRAILING_WHITESPACE | AssertRenderOptions::INCLUDE_STYLE,
1919
view_data,
2020
"{TITLE}",
2121
"{BODY}",
@@ -35,8 +35,7 @@ fn edit_event() {
3535
let view_data = module.get_view_data();
3636

3737
assert_rendered_output!(
38-
Options AssertRenderOptions::INCLUDE_TRAILING_WHITESPACE,
39-
view_data,
38+
Style view_data,
4039
"{TITLE}",
4140
"{BODY}",
4241
"{Normal}fooba{Normal,Underline}r",

src/core/src/components/help/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn handle_event(help: &mut Help, event: Event) {
1313
fn empty() {
1414
let mut module = Help::new_from_keybindings(&[]);
1515
assert_rendered_output!(
16-
module.get_view_data(),
16+
Style module.get_view_data(),
1717
"{TITLE}",
1818
"{LEADING}",
1919
"{Normal,Underline} Key Action{Pad( )}",
@@ -29,7 +29,7 @@ fn from_key_bindings() {
2929
(vec![String::from("b")], String::from("Description B")),
3030
]);
3131
assert_rendered_output!(
32-
module.get_view_data(),
32+
Style module.get_view_data(),
3333
"{TITLE}",
3434
"{LEADING}",
3535
"{Normal,Underline} Key Action{Pad( )}",

src/core/src/components/search_bar/tests.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ fn create_view_data(search_bar: &SearchBar) -> ViewData {
1212
fn new() {
1313
let search_bar = SearchBar::new();
1414
assert_eq!(search_bar.state, State::Deactivated);
15-
assert_rendered_output!(&create_view_data(&search_bar), "{BODY}", "{Normal}/{Normal,Underline}");
15+
let view_data = &create_view_data(&search_bar);
16+
assert_rendered_output!(Body view_data, "/");
1617
}
1718

1819
#[test]
@@ -21,30 +22,25 @@ fn start_search_without_initial_value() {
2122
search_bar.editable_line.set_read_only(true);
2223
search_bar.start_search(None);
2324
assert_eq!(search_bar.state, State::Editing);
24-
assert_rendered_output!(&create_view_data(&search_bar), "{BODY}", "{Normal}/{Normal,Underline}");
25+
let view_data = &create_view_data(&search_bar);
26+
assert_rendered_output!(Body view_data, "/");
2527
}
2628

2729
#[test]
2830
fn start_search_with_initial_value() {
2931
let mut search_bar = SearchBar::new();
3032
search_bar.start_search(Some("foo"));
31-
assert_rendered_output!(
32-
&create_view_data(&search_bar),
33-
"{BODY}",
34-
"{Normal}/foo{Normal,Underline}"
35-
);
33+
let view_data = &create_view_data(&search_bar);
34+
assert_rendered_output!(Body view_data, "/foo");
3635
}
3736

3837
#[test]
3938
fn start_search_with_previous_value_and_without_initial_value() {
4039
let mut search_bar = SearchBar::new();
4140
search_bar.start_search(Some("foo"));
4241
search_bar.start_search(None);
43-
assert_rendered_output!(
44-
&create_view_data(&search_bar),
45-
"{BODY}",
46-
"{Normal}/foo{Normal,Underline}"
47-
);
42+
let view_data = &create_view_data(&search_bar);
43+
assert_rendered_output!(Body view_data, "/foo");
4844
}
4945

5046
#[test]
@@ -136,7 +132,8 @@ fn handle_event_search_finish() {
136132
SearchBarAction::Start(String::from("foo"))
137133
);
138134
assert_eq!(search_bar.state, State::Searching);
139-
assert_rendered_output!(&create_view_data(&search_bar), "{BODY}", "{Normal}foo");
135+
let view_data = &create_view_data(&search_bar);
136+
assert_rendered_output!(Body view_data, "foo");
140137
}
141138

142139
#[test]
@@ -173,11 +170,8 @@ fn handle_event_other_active_without_change() {
173170
search_bar.start_search(Some("foo"));
174171
let event = Event::from(KeyCode::Null);
175172
assert_eq!(search_bar.handle_event(event), SearchBarAction::None);
176-
assert_rendered_output!(
177-
&create_view_data(&search_bar),
178-
"{BODY}",
179-
"{Normal}/foo{Normal,Underline}"
180-
);
173+
let view_data = &create_view_data(&search_bar);
174+
assert_rendered_output!(Body view_data, "/foo");
181175
}
182176

183177
#[test]
@@ -189,11 +183,8 @@ fn handle_event_other_active_with_change() {
189183
search_bar.handle_event(event),
190184
SearchBarAction::Update(String::from("fooa"))
191185
);
192-
assert_rendered_output!(
193-
&create_view_data(&search_bar),
194-
"{BODY}",
195-
"{Normal}/fooa{Normal,Underline}"
196-
);
186+
let view_data = &create_view_data(&search_bar);
187+
assert_rendered_output!(Body view_data, "/fooa");
197188
}
198189

199190
#[test]
@@ -203,11 +194,8 @@ fn handle_event_other_inactive() {
203194
search_bar.state = State::Deactivated;
204195
let event = Event::from('a');
205196
assert_eq!(search_bar.handle_event(event), SearchBarAction::None);
206-
assert_rendered_output!(
207-
&create_view_data(&search_bar),
208-
"{BODY}",
209-
"{Normal}/foo{Normal,Underline}"
210-
);
197+
let view_data = &create_view_data(&search_bar);
198+
assert_rendered_output!(Body view_data, "/foo");
211199
}
212200

213201
#[test]
@@ -270,8 +258,8 @@ fn is_searching() {
270258
#[test]
271259
fn build_view_line() {
272260
assert_rendered_output!(
261+
Options AssertRenderOptions::INCLUDE_STYLE | AssertRenderOptions::BODY_ONLY,
273262
&create_view_data(&SearchBar::new()),
274-
"{BODY}",
275263
"{Normal}/{Normal,Underline}"
276264
);
277265
}

0 commit comments

Comments
 (0)