2023-03-17 16:03:49 +00:00
|
|
|
use ratatui::{
|
2023-12-04 09:39:46 +00:00
|
|
|
backend::TestBackend,
|
|
|
|
buffer::Buffer,
|
|
|
|
layout::Rect,
|
|
|
|
style::{Style, Stylize},
|
|
|
|
symbols,
|
|
|
|
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| {
|
2024-01-11 01:16:44 +00:00
|
|
|
let tabs = Tabs::new(["Tab1", "Tab2"]);
|
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| {
|
2024-01-11 01:16:44 +00:00
|
|
|
let tabs = Tabs::new(["Tab1", "Tab2"]);
|
2020-05-21 18:17:55 +00:00
|
|
|
f.render_widget(
|
|
|
|
tabs,
|
|
|
|
Rect {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 9,
|
|
|
|
height: 1,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.unwrap();
|
2023-12-04 09:39:46 +00:00
|
|
|
let mut expected = Buffer::with_lines(vec![format!(" Tab1 {} T ", symbols::line::VERTICAL)]);
|
|
|
|
expected.set_style(Rect::new(1, 0, 4, 1), Style::new().reversed());
|
2020-05-21 18:17:55 +00:00
|
|
|
terminal.backend().assert_buffer(&expected);
|
|
|
|
}
|