add test fixtures

This commit is contained in:
Jonas Kruckenberg 2022-11-03 18:52:21 +01:00
parent b3e477ed18
commit 5db7b4ada1
42 changed files with 6332 additions and 0 deletions

34
examples/test/src/app.rs Normal file
View file

@ -0,0 +1,34 @@
use anyhow::ensure;
use tauri_sys::app;
pub async fn get_name() -> anyhow::Result<()> {
let name = app::get_name().await;
ensure!(name == "tauri-sys-test");
Ok(())
}
pub async fn get_version() -> anyhow::Result<()> {
let version = app::get_version().await;
ensure!(version.major == 0);
ensure!(version.minor == 0);
ensure!(version.patch == 0);
ensure!(version.build.is_empty());
ensure!(version.pre.is_empty());
Ok(())
}
pub async fn get_tauri_version() -> anyhow::Result<()> {
let version = app::get_tauri_version().await;
ensure!(version.major == 1);
ensure!(version.minor == 1);
ensure!(version.patch == 1);
ensure!(version.build.is_empty());
ensure!(version.pre.is_empty());
Ok(())
}

View file

@ -0,0 +1,12 @@
use anyhow::ensure;
use tauri_sys::clipboard;
pub async fn test() -> anyhow::Result<()> {
clipboard::write_text("foobar").await;
let text = clipboard::read_text().await;
ensure!(text == Some("foobar".to_string()));
Ok(())
}

View file

@ -0,0 +1,10 @@
use anyhow::ensure;
use tauri_sys::{event, tauri};
pub async fn emit() -> anyhow::Result<()> {
event::emit("foo", &"bar").await;
ensure!(tauri::invoke::<_, bool>("verify_receive", &()).await.unwrap());
Ok(())
}

86
examples/test/src/main.rs Normal file
View file

@ -0,0 +1,86 @@
mod app;
mod clipboard;
mod event;
mod window;
extern crate console_error_panic_hook;
use std::future::Future;
use std::panic;
use sycamore::prelude::*;
use sycamore::suspense::Suspense;
#[cfg(feature = "ci")]
async fn exit_with_error(e: String) {
use serde::Serialize;
#[derive(Serialize)]
struct Args {
e: String,
}
tauri_sys::tauri::invoke::<_, ()>("exit_with_error", &Args { e }).await.unwrap();
}
#[derive(Props)]
pub struct TestProps<'a, F>
where
F: Future<Output = anyhow::Result<()>> + 'a,
{
name: &'a str,
test: F,
}
#[component]
pub async fn Test<'a, G: Html, F>(cx: Scope<'a>, props: TestProps<'a, F>) -> View<G>
where
F: Future<Output = anyhow::Result<()>> + 'a,
{
let res = props.test.await;
view! { cx,
tr {
td { code { (props.name.to_string()) } }
td { (if let Err(e) = &res {
#[cfg(feature = "ci")]
{
wasm_bindgen_futures::spawn_local(exit_with_error(e.to_string()));
unreachable!()
}
#[cfg(not(feature = "ci"))]
format!("{:?}", e)
} else {
format!("")
})
}
}
}
}
fn main() {
panic::set_hook(Box::new(|info| {
console_error_panic_hook::hook(info);
#[cfg(feature = "ci")]
wasm_bindgen_futures::spawn_local(exit_with_error(format!("{}", info)));
}));
sycamore::render(|cx| {
view! { cx,
table {
tbody {
Suspense(fallback=view!{ cx, "Running Tests..." }) {
Test(name="app::get_name",test=app::get_name())
Test(name="app::get_version",test=app::get_version())
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())
// Test(name="window::WebviewWindow::new",test=window::create_window())
}
}
}
}
});
#[cfg(feature = "ci")]
tauri_sys::process::exit(0);
}

View file

@ -0,0 +1,13 @@
use anyhow::ensure;
use tauri_sys::window;
pub async fn create_window() -> anyhow::Result<()> {
let win = window::WebviewWindow::new("foo", ());
ensure!(win.is_visible().await);
// ensure!(win.label() == "foo".to_string());
win.close().await;
Ok(())
}