-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from redbadger/viktor/app-tester-new
Add AppTester::new
- Loading branch information
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! Test for the testing APIs | ||
|
||
use crux_core::testing::AppTester; | ||
|
||
mod app { | ||
use crux_core::macros::Effect; | ||
use crux_core::App; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub enum Event { | ||
Hello, | ||
} | ||
|
||
#[derive(Effect)] | ||
pub struct Capabilities { | ||
render: crux_core::render::Render<Event>, | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct MyApp; | ||
|
||
impl App for MyApp { | ||
type Event = Event; | ||
type Model = String; | ||
type ViewModel = String; | ||
type Capabilities = Capabilities; | ||
|
||
fn update(&self, _event: Self::Event, _model: &mut Self::Model, caps: &Self::Capabilities) { | ||
caps.render.render() | ||
} | ||
|
||
fn view(&self, model: &Self::Model) -> Self::ViewModel { | ||
model.clone() | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn app_tester_new() { | ||
let app = app::MyApp; | ||
let tester = AppTester::new(app); | ||
|
||
let mut model = "Hello".to_string(); | ||
|
||
let update = tester.update(app::Event::Hello, &mut model); | ||
|
||
let effects = update.into_effects(); | ||
|
||
assert_eq!(effects.count(), 1); | ||
} |