add interactive tests

This commit is contained in:
Jonas Kruckenberg 2022-11-14 14:01:39 +01:00
parent 373bdcd860
commit d1459f8ae3
3 changed files with 178 additions and 5 deletions

View file

@ -0,0 +1,3 @@
/src
/public
/Cargo.toml

View file

@ -0,0 +1,97 @@
use anyhow::ensure;
use tauri_sys::dialog::{FileDialogBuilder, MessageDialogBuilder, MessageDialogType};
pub async fn ask() -> anyhow::Result<()> {
let mut builder = MessageDialogBuilder::new();
builder.set_title("Tauri");
builder.set_type(MessageDialogType::Warning);
let works = builder
.ask("Does this work? \n Click Yes to mark this test as passing")
.await?;
ensure!(works);
Ok(())
}
pub async fn confirm() -> anyhow::Result<()> {
let mut builder = MessageDialogBuilder::new();
builder.set_title("Tauri");
builder.set_type(MessageDialogType::Warning);
let works = builder
.confirm("Does this work? \n Click Ok to mark this test as passing")
.await?;
ensure!(works);
Ok(())
}
pub async fn message() -> anyhow::Result<()> {
let mut builder = MessageDialogBuilder::new();
builder.set_title("Tauri");
builder.set_type(MessageDialogType::Warning);
builder.message("This is a message just for you!").await?;
Ok(())
}
pub async fn pick_file() -> anyhow::Result<()> {
let mut builder = FileDialogBuilder::new();
builder.set_title("Select a file to mark this test as passing");
let file = builder.pick_file().await?;
ensure!(file.is_some());
Ok(())
}
pub async fn pick_files() -> anyhow::Result<()> {
let mut builder = FileDialogBuilder::new();
builder.set_title("Select a multiple files to mark this test as passing");
let file = builder.pick_files().await?;
ensure!(file.is_some());
ensure!(file.unwrap().len() > 1);
Ok(())
}
pub async fn pick_folder() -> anyhow::Result<()> {
let mut builder = FileDialogBuilder::new();
builder.set_title("Select a folder to mark this test as passing");
let file = builder.pick_folder().await?;
ensure!(file.is_some());
Ok(())
}
pub async fn pick_folders() -> anyhow::Result<()> {
let mut builder = FileDialogBuilder::new();
builder.set_title("Select a multiple folders to mark this test as passing");
let file = builder.pick_folders().await?;
ensure!(file.is_some());
ensure!(file.unwrap().len() > 1);
Ok(())
}
pub async fn save() -> anyhow::Result<()> {
let mut builder = FileDialogBuilder::new();
builder.set_title("Select a file to mark this test as passing");
let file = builder.save().await?;
ensure!(file.is_some());
Ok(())
}

View file

@ -2,6 +2,7 @@ mod app;
mod clipboard;
mod event;
mod window;
mod dialog;
extern crate console_error_panic_hook;
use std::future::Future;
@ -58,6 +59,72 @@ where
}
}
#[cfg(not(feature = "ci"))]
#[component]
pub async fn InteractiveTest<'a, G: Html, F>(cx: Scope<'a>, props: TestProps<'a, F>) -> View<G>
where
F: Future<Output = anyhow::Result<()>> + 'a,
{
let mut test = Some(props.test);
let render_test = create_signal(cx, false);
let run_test = |_| {
render_test.set(true);
};
view! { cx,
(if *render_test.get() {
let test = test.take().unwrap();
let fallback = view! { cx,
tr {
td { code { (props.name.to_string()) } }
td {
"Running Test..."
}
}
};
view! { cx,
Suspense(fallback=fallback) {
Test(name=props.name, test=test)
}
}
} else {
view! { cx,
tr {
td { code { (props.name.to_string()) } }
td {
button(on:click=run_test) { "Run Interactive Test"}
}
}
}
})
}
}
#[cfg(feature = "ci")]
#[component]
pub async fn InteractiveTest<'a, G: Html, F>(cx: Scope<'a>, _props: TestProps<'a, F>) -> View<G>
where
F: Future<Output = anyhow::Result<()>> + 'a,
{
view! { cx, "Interactive tests are not run in CI mode" }
}
#[component]
pub async fn Terminate<'a, G: Html>(cx: Scope<'a>) -> View<G> {
#[cfg(feature = "ci")]
sycamore::suspense::await_suspense(cx, async {
tauri_sys::process::exit(0).await;
})
.await;
view! {
cx,
}
}
fn main() {
wasm_logger::init(wasm_logger::Config::default());
@ -69,11 +136,6 @@ fn main() {
}));
sycamore::render(|cx| {
#[cfg(feature = "ci")]
sycamore::suspense::await_suspense(cx, async {
tauri_sys::process::exit(0).await;
});
view! { cx,
table {
tbody {
@ -83,7 +145,18 @@ fn main() {
Test(name="app::get_tauri_version",test=app::get_tauri_version())
Test(name="clipboard::read_text | clipboard::write_text",test=clipboard::test())
Test(name="event::emit",test=event::emit())
InteractiveTest(name="dialog::message",test=dialog::message())
InteractiveTest(name="dialog::ask",test=dialog::ask())
InteractiveTest(name="dialog::confirm",test=dialog::confirm())
InteractiveTest(name="dialog::pick_file",test=dialog::pick_file())
InteractiveTest(name="dialog::pick_files",test=dialog::pick_files())
InteractiveTest(name="dialog::pick_folder",test=dialog::pick_folder())
InteractiveTest(name="dialog::pick_folders",test=dialog::pick_folders())
InteractiveTest(name="dialog::save",test=dialog::save())
// Test(name="window::WebviewWindow::new",test=window::create_window())
Terminate
}
}
}