test(v0): use component-scoped generated APIs

Drop the v0 example's global export opt-in and update tests to use component-scoped slots and forms, matching the checked public API path.

req: component/003

req: build/001
This commit is contained in:
slhx agent
2026-05-26 01:38:01 +02:00
parent e20d356c1d
commit 162c117a5a
2 changed files with 21 additions and 21 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
fn main() { fn main() {
slhx_build::app().global_exports(true).run().unwrap(); slhx_build::app().run().unwrap();
} }
+20 -20
View File
@@ -49,12 +49,12 @@ mod tests {
#[test] #[test]
fn counter_updates_a_generated_slot() { fn counter_updates_a_generated_slot() {
fn increment(count: u64) -> impl IntoEffect { fn increment(count: u64) -> impl IntoEffect {
ui::slots::counter_value.text(count + 1) ui::counter::slots::counter_value.text(count + 1)
} }
let effect = inspect(increment(1)); let effect = inspect(increment(1));
assert!(effect.has_slot(ui::slots::counter_value)); assert!(effect.has_slot(ui::counter::slots::counter_value));
assert!(matches!(effect.ops(), [Effect::Put { .. }])); assert!(matches!(effect.ops(), [Effect::Put { .. }]));
} }
@@ -63,12 +63,12 @@ mod tests {
fn form_handler_is_checked_against_hemplate_form() { fn form_handler_is_checked_against_hemplate_form() {
#[slhx::handler] #[slhx::handler]
fn add_todo(_form: slhx::Form<TodoInput>) -> impl IntoEffect { fn add_todo(_form: slhx::Form<TodoInput>) -> impl IntoEffect {
ui::slots::todo_list.text("queued") ui::todos::slots::todo_list.text("queued")
} }
let effect = inspect(add_todo(TodoInput::FORM)); let effect = inspect(add_todo(TodoInput::FORM));
assert!(effect.has_slot(ui::slots::todo_list)); assert!(effect.has_slot(ui::todos::slots::todo_list));
assert!(matches!(effect.ops(), [Effect::Put { payload: Payload::Text(_), .. }])); assert!(matches!(effect.ops(), [Effect::Put { payload: Payload::Text(_), .. }]));
} }
@@ -77,7 +77,7 @@ mod tests {
fn todos_append_keyed_rows_from_form_input() { fn todos_append_keyed_rows_from_form_input() {
fn add_todo(input: TodoInput) -> impl IntoEffect { fn add_todo(input: TodoInput) -> impl IntoEffect {
let todo = Todo { id: 7, title: input.title }; let todo = Todo { id: 7, title: input.title };
ui::slots::todo_row.append( ui::todos::slots::todo_row.append(
todo.id.to_string(), todo.id.to_string(),
&TodoRow { title: todo.title }, &TodoRow { title: todo.title },
) )
@@ -85,7 +85,7 @@ mod tests {
let effect = inspect(add_todo(TodoInput { title: "Ship v0".into() })); let effect = inspect(add_todo(TodoInput { title: "Ship v0".into() }));
assert!(effect.has_resource(ui::slots::todo_row.id())); assert!(effect.has_resource(ui::todos::slots::todo_row.id()));
assert!(matches!(effect.ops(), [Effect::Insert { key, payload, .. }] if key == "7" && matches!(payload, Payload::Html(_)))); assert!(matches!(effect.ops(), [Effect::Insert { key, payload, .. }] if key == "7" && matches!(payload, Payload::Html(_))));
} }
@@ -94,12 +94,12 @@ mod tests {
fn wizard_form_handler_is_checked_against_hemplate_form() { fn wizard_form_handler_is_checked_against_hemplate_form() {
#[slhx::handler] #[slhx::handler]
fn next_step(_form: slhx::Form<WizardInput>) -> impl IntoEffect { fn next_step(_form: slhx::Form<WizardInput>) -> impl IntoEffect {
ui::slots::wizard_step.text("queued") ui::wizard::slots::wizard_step.text("queued")
} }
let effect = inspect(next_step(WizardInput::FORM)); let effect = inspect(next_step(WizardInput::FORM));
assert!(effect.has_slot(ui::slots::wizard_step)); assert!(effect.has_slot(ui::wizard::slots::wizard_step));
assert!(matches!(effect.ops(), [Effect::Put { payload: Payload::Text(_), .. }])); assert!(matches!(effect.ops(), [Effect::Put { payload: Payload::Text(_), .. }]));
} }
@@ -107,12 +107,12 @@ mod tests {
#[test] #[test]
fn wizard_form_swaps_the_current_step() { fn wizard_form_swaps_the_current_step() {
fn next_step(input: WizardInput) -> impl IntoEffect { fn next_step(input: WizardInput) -> impl IntoEffect {
ui::slots::wizard_step.text(format!("Step {}", input.step + 1)) ui::wizard::slots::wizard_step.text(format!("Step {}", input.step + 1))
} }
let effect = inspect(next_step(WizardInput { step: 1 })); let effect = inspect(next_step(WizardInput { step: 1 }));
assert!(effect.has_slot(ui::slots::wizard_step)); assert!(effect.has_slot(ui::wizard::slots::wizard_step));
assert!(matches!(effect.ops(), [Effect::Put { .. }])); assert!(matches!(effect.ops(), [Effect::Put { .. }]));
} }
@@ -121,18 +121,18 @@ mod tests {
fn page_swap_updates_content_and_history() { fn page_swap_updates_content_and_history() {
fn load_docs() -> impl IntoEffect { fn load_docs() -> impl IntoEffect {
( (
ui::slots::content.render(&DocsContent { ui::page_swap::slots::content.render(&DocsContent {
message: "This page was swapped.", message: "This page was swapped.",
}), }),
ui::slots::title.text("Docs"), ui::page_swap::slots::title.text("Docs"),
push("/docs"), push("/docs"),
) )
} }
let effect = inspect(load_docs()); let effect = inspect(load_docs());
assert!(effect.has_slot(ui::slots::content)); assert!(effect.has_slot(ui::page_swap::slots::content));
assert!(effect.has_slot(ui::slots::title)); assert!(effect.has_slot(ui::page_swap::slots::title));
assert!(matches!(effect.ops().first(), Some(Effect::Put { payload: Payload::Html(_), .. }))); assert!(matches!(effect.ops().first(), Some(Effect::Put { payload: Payload::Html(_), .. })));
assert!(matches!(effect.ops().last(), Some(Effect::Navigate { url, mode: NavigateMode::Push, .. }) if url == "/docs")); assert!(matches!(effect.ops().last(), Some(Effect::Navigate { url, mode: NavigateMode::Push, .. }) if url == "/docs"));
} }
@@ -142,12 +142,12 @@ mod tests {
fn auth_form_handler_is_checked_against_hemplate_form() { fn auth_form_handler_is_checked_against_hemplate_form() {
#[slhx::handler] #[slhx::handler]
fn login(_form: slhx::Form<Credentials>) -> impl IntoEffect { fn login(_form: slhx::Form<Credentials>) -> impl IntoEffect {
ui::slots::login_status.text("queued") ui::auth::slots::login_status.text("queued")
} }
let effect = inspect(login(Credentials::FORM)); let effect = inspect(login(Credentials::FORM));
assert!(effect.has_slot(ui::slots::login_status)); assert!(effect.has_slot(ui::auth::slots::login_status));
assert!(matches!(effect.ops(), [Effect::Put { payload: Payload::Text(_), .. }])); assert!(matches!(effect.ops(), [Effect::Put { payload: Payload::Text(_), .. }]));
} }
@@ -161,12 +161,12 @@ mod tests {
"Try again" "Try again"
}; };
ui::slots::login_status.text(status) ui::auth::slots::login_status.text(status)
} }
let effect = inspect(login(Credentials { email: "demo@example.com".into(), password: "secret".into() })); let effect = inspect(login(Credentials { email: "demo@example.com".into(), password: "secret".into() }));
assert!(effect.has_slot(ui::slots::login_status)); assert!(effect.has_slot(ui::auth::slots::login_status));
assert!(matches!(effect.ops(), [Effect::Put { .. }])); assert!(matches!(effect.ops(), [Effect::Put { .. }]));
} }
@@ -174,12 +174,12 @@ mod tests {
#[test] #[test]
fn sse_notifications_update_a_generated_slot() { fn sse_notifications_update_a_generated_slot() {
fn notification(message: &str) -> impl IntoEffect { fn notification(message: &str) -> impl IntoEffect {
ui::slots::notifications.text(message) ui::notifications::slots::notifications.text(message)
} }
let effect = inspect(notification("Build finished")); let effect = inspect(notification("Build finished"));
assert!(effect.has_slot(ui::slots::notifications)); assert!(effect.has_slot(ui::notifications::slots::notifications));
assert!(matches!(effect.ops(), [Effect::Put { .. }])); assert!(matches!(effect.ops(), [Effect::Put { .. }]));
} }
} }