| 1 | // use helix_tui::{ |
| 2 | // backend::TestBackend, |
| 3 | // buffer::Buffer, |
| 4 | // layout::Rect, |
| 5 | // style::{Color, Style}, |
| 6 | // symbols, |
| 7 | // widgets::{Block, Borders, List, ListItem, ListState}, |
| 8 | // Terminal, |
| 9 | // }; |
| 10 | |
| 11 | // #[test] |
| 12 | // fn widgets_list_should_highlight_the_selected_item() { |
| 13 | // let backend = TestBackend::new(10, 3); |
| 14 | // let mut terminal = Terminal::new(backend).unwrap(); |
| 15 | // let mut state = ListState::default(); |
| 16 | // state.select(Some(1)); |
| 17 | // terminal |
| 18 | // .draw(|f| { |
| 19 | // let size = f.size(); |
| 20 | // let items = vec![ |
| 21 | // ListItem::new("Item 1"), |
| 22 | // ListItem::new("Item 2"), |
| 23 | // ListItem::new("Item 3"), |
| 24 | // ]; |
| 25 | // let list = List::new(items) |
| 26 | // .highlight_style(Style::default().bg(Color::Yellow)) |
| 27 | // .highlight_symbol(">> "); |
| 28 | // f.render_stateful_widget(list, size, &mut state); |
| 29 | // }) |
| 30 | // .unwrap(); |
| 31 | // let mut expected = Buffer::with_lines(vec![" Item 1 ", ">> Item 2 ", " Item 3 "]); |
| 32 | // for x in 0..10 { |
| 33 | // expected.get_mut(x, 1).set_bg(Color::Yellow); |
| 34 | // } |
| 35 | // terminal.backend().assert_buffer(&expected); |
| 36 | // } |
| 37 | |
| 38 | // #[test] |
| 39 | // fn widgets_list_should_truncate_items() { |
| 40 | // let backend = TestBackend::new(10, 2); |
| 41 | // let mut terminal = Terminal::new(backend).unwrap(); |
| 42 | |
| 43 | // struct TruncateTestCase<'a> { |
| 44 | // selected: Option<usize>, |
| 45 | // items: Vec<ListItem<'a>>, |
| 46 | // expected: Buffer, |
| 47 | // } |
| 48 | |
| 49 | // let cases = vec![ |
| 50 | // // An item is selected |
| 51 | // TruncateTestCase { |
| 52 | // selected: Some(0), |
| 53 | // items: vec![ |
| 54 | // ListItem::new("A very long line"), |
| 55 | // ListItem::new("A very long line"), |
| 56 | // ], |
| 57 | // expected: Buffer::with_lines(vec![ |
| 58 | // format!(">> A ve{} ", symbols::line::VERTICAL), |
| 59 | // format!(" A ve{} ", symbols::line::VERTICAL), |
| 60 | // ]), |
| 61 | // }, |
| 62 | // // No item is selected |
| 63 | // TruncateTestCase { |
| 64 | // selected: None, |
| 65 | // items: vec![ |
| 66 | // ListItem::new("A very long line"), |
| 67 | // ListItem::new("A very long line"), |
| 68 | // ], |
| 69 | // expected: Buffer::with_lines(vec![ |
| 70 | // format!("A very {} ", symbols::line::VERTICAL), |
| 71 | // format!("A very {} ", symbols::line::VERTICAL), |
| 72 | // ]), |
| 73 | // }, |
| 74 | // ]; |
| 75 | // for case in cases { |
| 76 | // let mut state = ListState::default(); |
| 77 | // state.select(case.selected); |
| 78 | // terminal |
| 79 | // .draw(|f| { |
| 80 | // let list = List::new(case.items.clone()) |
| 81 | // .block(Block::default().borders(Borders::RIGHT)) |
| 82 | // .highlight_symbol(">> "); |
| 83 | // f.render_stateful_widget(list, Rect::new(0, 0, 8, 2), &mut state); |
| 84 | // }) |
| 85 | // .unwrap(); |
| 86 | // terminal.backend().assert_buffer(&case.expected); |
| 87 | // } |
| 88 | // } |