2023-05-18 18:21:43 +00:00
|
|
|
#![allow(deprecated)]
|
|
|
|
|
2023-03-17 16:03:49 +00:00
|
|
|
use ratatui::{
|
2023-05-18 18:21:43 +00:00
|
|
|
backend::TestBackend, buffer::Buffer, layout::Rect, symbols, text::Line, widgets::Tabs,
|
2020-05-10 13:44:30 +00:00
|
|
|
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| {
|
2023-05-18 18:21:43 +00:00
|
|
|
let tabs = Tabs::new(["Tab1", "Tab2"].iter().cloned().map(Line::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| {
|
2023-05-18 18:21:43 +00:00
|
|
|
let tabs = Tabs::new(["Tab1", "Tab2"].iter().cloned().map(Line::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);
|
|
|
|
}
|