Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/sql pagination 2 #157

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update test structure for tui
  • Loading branch information
matthewmturner committed Sep 20, 2024
commit e2623533d71a8cf7e21d1c772f617bc25cac0616
19 changes: 19 additions & 0 deletions tests/app_cases/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

mod quit;
121 changes: 121 additions & 0 deletions tests/app_cases/quit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//! Tests for the TUI (e.g. user application with keyboard commands)

use dft::app::state::initialize;
use dft::app::{App, AppEvent};
use dft::execution::ExecutionContext;
use ratatui::crossterm::event;
use tempfile::{tempdir, TempDir};

#[tokio::test]
async fn construct_with_no_args() {
let _test_app = TestApp::new();
}

#[tokio::test]
async fn quit_app_from_sql_tab() {
let mut test_app = TestApp::new();
// SQL Tab
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
// Ideally, we figure out a way to check that the app actually quits
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_flightsql_tab() {
let mut test_app = TestApp::new();
let flightsql_key = event::KeyEvent::new(event::KeyCode::Char('2'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(flightsql_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_history_tab() {
let mut test_app = TestApp::new();
let history_key = event::KeyEvent::new(event::KeyCode::Char('3'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(history_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_logs_tab() {
let mut test_app = TestApp::new();
let logs_key = event::KeyEvent::new(event::KeyCode::Char('4'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(logs_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_context_tab() {
let mut test_app = TestApp::new();
let context_key = event::KeyEvent::new(event::KeyCode::Char('5'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(context_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}

/// Fixture with an [`App`] instance and other temporary state
struct TestApp<'app> {
/// Temporary directory for configuration files
///
/// The directory is removed when the object is dropped so this
/// field must remain alive while the app is running
#[allow(dead_code)]
config_path: TempDir,
/// The [`App`] instance
app: App<'app>,
}

impl<'app> TestApp<'app> {
/// Create a new [`TestApp`] instance configured with a temporary directory
fn new() -> Self {
let config_path = tempdir().unwrap();
let state = initialize(config_path.path().to_path_buf());
let execution = ExecutionContext::try_new(&state.config.execution).unwrap();
let app = App::new(state, execution);
Self { config_path, app }
}

/// Call app.event_handler with the given event
pub fn handle_app_event(&mut self, event: AppEvent) -> color_eyre::Result<()> {
self.app.handle_app_event(event)
}

/// Return the app state
pub fn state(&self) -> &dft::app::state::AppState {
self.app.state()
}
}
88 changes: 88 additions & 0 deletions tests/app_cases/tui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//! Tests for the TUI (e.g. user application with keyboard commands)

use dft::app::state::initialize;
use dft::app::{App, AppEvent};
use dft::execution::ExecutionContext;
use ratatui::crossterm::event;
use tempfile::{tempdir, TempDir};

#[tokio::test]
async fn construct_with_no_args() {
let _test_app = TestApp::new();
}

#[tokio::test]
async fn quit_app_from_sql_tab() {
let mut test_app = TestApp::new();
// SQL Tab
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
// Ideally, we figure out a way to check that the app actually quits
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_flightsql_tab() {
let mut test_app = TestApp::new();
let flightsql_key = event::KeyEvent::new(event::KeyCode::Char('2'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(flightsql_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_history_tab() {
let mut test_app = TestApp::new();
let history_key = event::KeyEvent::new(event::KeyCode::Char('3'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(history_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_logs_tab() {
let mut test_app = TestApp::new();
let logs_key = event::KeyEvent::new(event::KeyCode::Char('4'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(logs_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_context_tab() {
let mut test_app = TestApp::new();
let context_key = event::KeyEvent::new(event::KeyCode::Char('5'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(context_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}
75 changes: 6 additions & 69 deletions tests/tui.rs
Original file line number Diff line number Diff line change
@@ -14,78 +14,15 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//


//! Tests for the TUI (e.g. user application with keyboard commands)

use dft::app::state::initialize;
use dft::app::{App, AppEvent};
use dft::execution::ExecutionContext;
use ratatui::crossterm::event;
use dft::{
app::{state::initialize, App, AppEvent},
execution::ExecutionContext,
};
use tempfile::{tempdir, TempDir};

#[tokio::test]
async fn construct_with_no_args() {
let _test_app = TestApp::new();
}

#[tokio::test]
async fn quit_app_from_sql_tab() {
let mut test_app = TestApp::new();
// SQL Tab
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
// Ideally, we figure out a way to check that the app actually quits
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_flightsql_tab() {
let mut test_app = TestApp::new();
let flightsql_key = event::KeyEvent::new(event::KeyCode::Char('2'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(flightsql_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_history_tab() {
let mut test_app = TestApp::new();
let history_key = event::KeyEvent::new(event::KeyCode::Char('3'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(history_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_logs_tab() {
let mut test_app = TestApp::new();
let logs_key = event::KeyEvent::new(event::KeyCode::Char('4'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(logs_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}

#[tokio::test]
async fn quit_app_from_context_tab() {
let mut test_app = TestApp::new();
let context_key = event::KeyEvent::new(event::KeyCode::Char('5'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(context_key);
test_app.handle_app_event(app_event).unwrap();
let key = event::KeyEvent::new(event::KeyCode::Char('q'), event::KeyModifiers::NONE);
let app_event = AppEvent::Key(key);
test_app.handle_app_event(app_event).unwrap();
assert!(test_app.state().should_quit);
}
mod app_cases;

/// Fixture with an [`App`] instance and other temporary state
struct TestApp<'app> {