Alloy
v0.1
Testing pages
use smeltery::alloy::testing::{AlloyAssertions as _, AlloyRequests as _};
use smeltery::alloy::{self, Alloy, AlloyExt as _, Page};
use smeltery::testing::TestApp;
async fn dashboard() -> Page {
alloy::render("dashboard")
.with("greeting", "Hello")
.defer("activity", || async { Ok(vec!["Signed in"]) })
}
let app = TestApp::new(|app| {
app.alloy(Alloy::new().root::<Root>())
.routes(|r| { r.get("/dashboard", dashboard); })
});
app.get_alloy("/dashboard")
.assert_component("dashboard")
.assert_prop("greeting", "Hello")
.assert_missing("activity")
.assert_deferred("default", &["activity"]);
let reload = app.reload_alloy("/dashboard", "dashboard", &["activity"]);
assert_eq!(reload.prop("activity.0"), Some(smeltery::json!("Signed in")));
get_alloy(path) visits a page as Inertia's client does (with the current asset version), reload_alloy(path,
component, &[props]) is a partial reload, and post_alloy(path, &json) posts JSON as form.post does. On any
response, alloy_page() reads the page (the JSON of an Inertia visit or the <script data-page> of a first visit),
prop(path) reads a prop by dot path, and assert_component, assert_prop, assert_missing and assert_deferred
check it. assert_page_file_exists(component) checks that resources/js/pages/<component>.{tsx,jsx,vue,svelte}
exists.