2020-05-10 13:44:30 +00:00
|
|
|
use tui::{
|
|
|
|
backend::TestBackend, buffer::Buffer, layout::Rect, symbols, text::Spans, widgets::Tabs,
|
|
|
|
Terminal,
|
|
|
|
};
|
2020-05-21 18:17:55 +00:00
|
|
|
|
|
|
|
#[test]
|
2020-05-21 18:42:34 +00:00
|
|
|
fn widgets_tabs_should_not_panic_on_narrow_areas() {
|
2020-05-21 18:17:55 +00:00
|
|
|
let backend = TestBackend::new(1, 1);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
2020-06-15 20:57:23 +00:00
|
|
|
.draw(|f| {
|
2020-05-10 13:44:30 +00:00
|
|
|
let tabs = Tabs::new(["Tab1", "Tab2"].iter().cloned().map(Spans::from).collect());
|
2020-05-21 18:17:55 +00:00
|
|
|
f.render_widget(
|
|
|
|
tabs,
|
|
|
|
Rect {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 1,
|
|
|
|
height: 1,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
let expected = Buffer::with_lines(vec![" "]);
|
|
|
|
terminal.backend().assert_buffer(&expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-05-21 18:42:34 +00:00
|
|
|
fn widgets_tabs_should_truncate_the_last_item() {
|
2020-05-21 18:17:55 +00:00
|
|
|
let backend = TestBackend::new(10, 1);
|
|
|
|
let mut terminal = Terminal::new(backend).unwrap();
|
|
|
|
terminal
|
2020-06-15 20:57:23 +00:00
|
|
|
.draw(|f| {
|
2020-05-10 13:44:30 +00:00
|
|
|
let tabs = Tabs::new(["Tab1", "Tab2"].iter().cloned().map(Spans::from).collect());
|
2020-05-21 18:17:55 +00:00
|
|
|
f.render_widget(
|
|
|
|
tabs,
|
|
|
|
Rect {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 9,
|
|
|
|
height: 1,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.unwrap();
|
2020-05-10 13:44:30 +00:00
|
|
|
let expected = Buffer::with_lines(vec![format!(" Tab1 {} T ", symbols::line::VERTICAL)]);
|
2020-05-21 18:17:55 +00:00
|
|
|
terminal.backend().assert_buffer(&expected);
|
|
|
|
}
|