|
1 | 1 | use super::*;
|
2 | 2 | use crate::{config::Theme, display::Size, test_helpers::mocks};
|
3 | 3 |
|
4 |
| -fn assert_render(width: usize, height: usize, view_data: &ViewData, expected: &[&str]) { |
| 4 | +fn assert_render_slice(width: usize, height: usize, render_slice: &RenderSlice, expected: &[&str]) { |
5 | 5 | let theme = Theme::new_with_config(None).unwrap();
|
6 | 6 | let mut crossterm = mocks::CrossTerm::new();
|
7 | 7 | let readonly_tui = crossterm.clone();
|
8 | 8 | crossterm.set_size(Size::new(width, height));
|
9 | 9 | let display = Display::new(crossterm, &theme);
|
10 | 10 | let mut view = View::new(display, "~", "?");
|
11 | 11 |
|
| 12 | + view.render(render_slice).unwrap(); |
| 13 | + assert_eq!(readonly_tui.get_output().join(""), format!("{}\n", expected.join("\n"))); |
| 14 | +} |
| 15 | + |
| 16 | +fn assert_render(width: usize, height: usize, view_data: &ViewData, expected: &[&str]) { |
12 | 17 | let mut render_slice = RenderSlice::new();
|
13 | 18 | render_slice.record_resize(width, height);
|
14 | 19 | render_slice.sync_view_data(view_data);
|
15 |
| - view.render(&render_slice).unwrap(); |
16 |
| - assert_eq!(readonly_tui.get_output().join(""), format!("{}\n", expected.join("\n"))); |
| 20 | + assert_render_slice(width, height, &render_slice, expected); |
17 | 21 | }
|
18 | 22 |
|
19 | 23 | #[test]
|
@@ -235,3 +239,66 @@ fn render_ensure_visible_multiple_rows_decreasing_order() {
|
235 | 239 | &["This is line 3 ", "This is line 4 ", "This is line 5█"],
|
236 | 240 | );
|
237 | 241 | }
|
| 242 | + |
| 243 | +#[test] |
| 244 | +fn render_after_leading_lines_change() { |
| 245 | + let width = 30; |
| 246 | + let height = 2; |
| 247 | + let mut render_slice = RenderSlice::new(); |
| 248 | + render_slice.record_resize(width, height); |
| 249 | + let mut view_data = ViewData::new(|updater| { |
| 250 | + updater.push_line(ViewLine::from("This is line 1")); |
| 251 | + updater.push_line(ViewLine::from("This is line 2")); |
| 252 | + updater.push_line(ViewLine::from("This is line 3")); |
| 253 | + updater.ensure_line_visible(2); |
| 254 | + }); |
| 255 | + render_slice.sync_view_data(&view_data); |
| 256 | + view_data.update_view_data(|updater| { |
| 257 | + updater.push_leading_line(ViewLine::from("This is line 0")); |
| 258 | + }); |
| 259 | + render_slice.sync_view_data(&view_data); |
| 260 | + assert_render_slice(width, height, &render_slice, &["This is line 0", "This is line 3█"]); |
| 261 | +} |
| 262 | + |
| 263 | +#[test] |
| 264 | +fn render_after_title_show() { |
| 265 | + let width = 30; |
| 266 | + let height = 2; |
| 267 | + let mut render_slice = RenderSlice::new(); |
| 268 | + render_slice.record_resize(width, height); |
| 269 | + let mut view_data = ViewData::new(|updater| { |
| 270 | + updater.push_line(ViewLine::from("This is line 1")); |
| 271 | + updater.push_line(ViewLine::from("This is line 2")); |
| 272 | + updater.push_line(ViewLine::from("This is line 3")); |
| 273 | + updater.ensure_line_visible(2); |
| 274 | + }); |
| 275 | + render_slice.sync_view_data(&view_data); |
| 276 | + view_data.update_view_data(|updater| { |
| 277 | + updater.set_show_title(true); |
| 278 | + }); |
| 279 | + render_slice.sync_view_data(&view_data); |
| 280 | + assert_render_slice(width, height, &render_slice, &[ |
| 281 | + "Git Interactive Rebase Tool ", |
| 282 | + "This is line 3█", |
| 283 | + ]); |
| 284 | +} |
| 285 | + |
| 286 | +#[test] |
| 287 | +fn render_after_trailing_lines_change() { |
| 288 | + let width = 30; |
| 289 | + let height = 2; |
| 290 | + let mut render_slice = RenderSlice::new(); |
| 291 | + render_slice.record_resize(width, height); |
| 292 | + let mut view_data = ViewData::new(|updater| { |
| 293 | + updater.push_line(ViewLine::from("This is line 1")); |
| 294 | + updater.push_line(ViewLine::from("This is line 2")); |
| 295 | + updater.push_line(ViewLine::from("This is line 3")); |
| 296 | + updater.ensure_line_visible(2); |
| 297 | + }); |
| 298 | + render_slice.sync_view_data(&view_data); |
| 299 | + view_data.update_view_data(|updater| { |
| 300 | + updater.push_trailing_line(ViewLine::from("This is line 4")); |
| 301 | + }); |
| 302 | + render_slice.sync_view_data(&view_data); |
| 303 | + assert_render_slice(width, height, &render_slice, &["This is line 3█", "This is line 4"]); |
| 304 | +} |
0 commit comments