notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 4bd01682da59ce6e2e632f7d6ed8b8872ec326ae
parent 242053c6e0b7bc00fae198b04b7a42c1182be0b3
Author: kernelkind <kernelkind@gmail.com>
Date:   Mon,  1 Apr 2024 11:04:51 -0400

Add ui_test_harness binary implementation

Adds ability to run UI components isolated from main app.

`cargo run --bin ui_test_harness -- AccountLoginView`

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
MCargo.toml | 9+++++++++
Msrc/lib.rs | 6+++---
Asrc/tests_ui/account_login_view_test.rs | 21+++++++++++++++++++++
Asrc/tests_ui/egui_test_setup.rs | 15+++++++++++++++
Asrc/tests_ui/main.rs | 34++++++++++++++++++++++++++++++++++
5 files changed, 82 insertions(+), 3 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -3,6 +3,7 @@ name = "notedeck" version = "0.1.0" authors = ["William Casarin <jb55@jb55.com>"] edition = "2021" +default-run = "notedeck" #rust-version = "1.60" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -93,3 +94,11 @@ name = "android.permission.INTERNET" [package.metadata.android.application] label = "Damus" + +[[bin]] +name = "notedeck" +path = "src/bin/notedeck.rs" + +[[bin]] +name = "ui_test_harness" +path = "src/tests_ui/main.rs" diff --git a/src/lib.rs b/src/lib.rs @@ -19,9 +19,9 @@ mod timeline; mod colors; mod profile; mod key_parsing; -mod login_manager; -mod account_login_view; -mod app_creation; +pub mod login_manager; +pub mod account_login_view; +pub mod app_creation; #[cfg(test)] #[macro_use] diff --git a/src/tests_ui/account_login_view_test.rs b/src/tests_ui/account_login_view_test.rs @@ -0,0 +1,21 @@ +use crate::egui_test_setup::{EguiTestCase, EguiTestSetup}; +use notedeck::account_login_view::AccountLoginView; +use notedeck::login_manager::LoginManager; + +pub struct AccountLoginTest { + manager: LoginManager, +} + +impl EguiTestCase for AccountLoginTest { + fn new(supr: EguiTestSetup) -> Self { + AccountLoginTest { + manager: LoginManager::new(), + } + } +} + +impl eframe::App for AccountLoginTest { + fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) { + AccountLoginView::new(ctx, &mut self.manager).panel() + } +} diff --git a/src/tests_ui/egui_test_setup.rs b/src/tests_ui/egui_test_setup.rs @@ -0,0 +1,15 @@ +use notedeck::app_creation::setup_cc; + +pub struct EguiTestSetup {} + +pub trait EguiTestCase: eframe::App { + fn new(supr: EguiTestSetup) -> Self; +} + +impl EguiTestSetup { + pub fn new(cc: &eframe::CreationContext<'_>) -> Self { + setup_cc(cc); + + EguiTestSetup {} + } +} diff --git a/src/tests_ui/main.rs b/src/tests_ui/main.rs @@ -0,0 +1,34 @@ +mod account_login_view_test; +mod egui_test_setup; +use account_login_view_test::AccountLoginTest; +use egui_test_setup::{EguiTestCase, EguiTestSetup}; +use notedeck::app_creation::generate_native_options; +use std::env; + +fn run_test_app<F, T, O>(create_supr: F, create_child: O) +where + F: 'static + FnOnce(&eframe::CreationContext<'_>) -> EguiTestSetup, + T: 'static + EguiTestCase, + O: 'static + FnOnce(EguiTestSetup) -> T, +{ + tracing_subscriber::fmt::init(); + + let _ = eframe::run_native( + "UI Test Harness", + generate_native_options(), + Box::new(|cc| Box::new(create_child(create_supr(cc)))), + ); +} + +fn main() { + let args: Vec<String> = env::args().collect(); + + if args.len() > 1 { + match args[1].as_str() { + "AccountLoginView" => run_test_app(EguiTestSetup::new, AccountLoginTest::new), + _ => println!("Component not found."), + } + } else { + println!("Please specify a component to test."); + } +}