use datafusion_dft::tui::AppEvent;
use ratatui::crossterm::event;
use crate::tui_cases::TestApp;
#[tokio::test(flavor = "multi_thread")]
async fn sql_alt_enter_executes_in_edit_mode() {
let mut test_app = TestApp::new().await;
assert!(matches!(
test_app.state().tabs.selected,
datafusion_dft::tui::ui::SelectedTab::SQL
));
let edit_key = event::KeyEvent::new(event::KeyCode::Char('e'), event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(edit_key)).unwrap();
assert!(test_app.state().sql_tab.editable());
let alt_enter = event::KeyEvent::new(event::KeyCode::Enter, event::KeyModifiers::ALT);
test_app.handle_app_event(AppEvent::Key(alt_enter)).unwrap();
assert!(!test_app.state().sql_tab.editable());
}
#[tokio::test(flavor = "multi_thread")]
async fn sql_enter_in_normal_mode_executes() {
let mut test_app = TestApp::new().await;
assert!(!test_app.state().sql_tab.editable());
let enter = event::KeyEvent::new(event::KeyCode::Enter, event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(enter)).unwrap();
}
#[tokio::test(flavor = "multi_thread")]
async fn sql_plain_enter_doesnt_execute_in_edit_mode() {
let mut test_app = TestApp::new().await;
let edit_key = event::KeyEvent::new(event::KeyCode::Char('e'), event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(edit_key)).unwrap();
assert!(test_app.state().sql_tab.editable());
let enter = event::KeyEvent::new(event::KeyCode::Enter, event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(enter)).unwrap();
assert!(test_app.state().sql_tab.editable());
}
#[tokio::test(flavor = "multi_thread")]
async fn sql_ctrl_enter_doesnt_execute_in_edit_mode() {
let mut test_app = TestApp::new().await;
let edit_key = event::KeyEvent::new(event::KeyCode::Char('e'), event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(edit_key)).unwrap();
assert!(test_app.state().sql_tab.editable());
let ctrl_enter = event::KeyEvent::new(event::KeyCode::Enter, event::KeyModifiers::CONTROL);
test_app
.handle_app_event(AppEvent::Key(ctrl_enter))
.unwrap();
assert!(test_app.state().sql_tab.editable());
}
#[tokio::test(flavor = "multi_thread")]
async fn sql_esc_exits_edit_mode() {
let mut test_app = TestApp::new().await;
let edit_key = event::KeyEvent::new(event::KeyCode::Char('e'), event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(edit_key)).unwrap();
assert!(test_app.state().sql_tab.editable());
let esc = event::KeyEvent::new(event::KeyCode::Esc, event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(esc)).unwrap();
assert!(!test_app.state().sql_tab.editable());
}
#[tokio::test(flavor = "multi_thread")]
async fn sql_alt_word_navigation_in_edit_mode() {
let mut test_app = TestApp::new().await;
let edit_key = event::KeyEvent::new(event::KeyCode::Char('e'), event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(edit_key)).unwrap();
assert!(test_app.state().sql_tab.editable());
let alt_left = event::KeyEvent::new(event::KeyCode::Left, event::KeyModifiers::ALT);
test_app.handle_app_event(AppEvent::Key(alt_left)).unwrap();
let alt_right = event::KeyEvent::new(event::KeyCode::Right, event::KeyModifiers::ALT);
test_app.handle_app_event(AppEvent::Key(alt_right)).unwrap();
let alt_backspace = event::KeyEvent::new(event::KeyCode::Backspace, event::KeyModifiers::ALT);
test_app
.handle_app_event(AppEvent::Key(alt_backspace))
.unwrap();
assert!(test_app.state().sql_tab.editable());
}
#[tokio::test(flavor = "multi_thread")]
async fn sql_switch_to_ddl_mode() {
let mut test_app = TestApp::new().await;
assert_eq!(
*test_app.state().sql_tab.mode(),
datafusion_dft::tui::state::tabs::sql::SQLTabMode::Normal
);
let d_key = event::KeyEvent::new(event::KeyCode::Char('d'), event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(d_key)).unwrap();
assert_eq!(
*test_app.state().sql_tab.mode(),
datafusion_dft::tui::state::tabs::sql::SQLTabMode::DDL
);
}
#[tokio::test(flavor = "multi_thread")]
async fn sql_switch_to_normal_mode() {
let mut test_app = TestApp::new().await;
let d_key = event::KeyEvent::new(event::KeyCode::Char('d'), event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(d_key)).unwrap();
let n_key = event::KeyEvent::new(event::KeyCode::Char('n'), event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(n_key)).unwrap();
assert_eq!(
*test_app.state().sql_tab.mode(),
datafusion_dft::tui::state::tabs::sql::SQLTabMode::Normal
);
}
#[tokio::test(flavor = "multi_thread")]
async fn sql_c_clears_editor() {
let mut test_app = TestApp::new().await;
let c_key = event::KeyEvent::new(event::KeyCode::Char('c'), event::KeyModifiers::NONE);
test_app.handle_app_event(AppEvent::Key(c_key)).unwrap();
}
#[tokio::test(flavor = "multi_thread")]
async fn sql_ctrl_d_doesnt_switch_mode() {
let mut test_app = TestApp::new().await;
assert_eq!(
*test_app.state().sql_tab.mode(),
datafusion_dft::tui::state::tabs::sql::SQLTabMode::Normal
);
let ctrl_d = event::KeyEvent::new(event::KeyCode::Char('d'), event::KeyModifiers::CONTROL);
test_app.handle_app_event(AppEvent::Key(ctrl_d)).unwrap();
assert_eq!(
*test_app.state().sql_tab.mode(),
datafusion_dft::tui::state::tabs::sql::SQLTabMode::Normal
);
}