so many tests...
This commit is contained in:
parent
2332d6bc80
commit
71388da342
2 changed files with 129 additions and 3 deletions
|
@ -74,12 +74,13 @@ pub fn BlockElement(block: Block) -> Element {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use meta::SiteContext;
|
use meta::{PageContext, SiteContext};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
domain::entities::{
|
domain::entities::{
|
||||||
|
self,
|
||||||
cursor::Paginated,
|
cursor::Paginated,
|
||||||
site::{Image, SiteInfo},
|
site::{CollectionKind, Image, SiteInfo},
|
||||||
},
|
},
|
||||||
outbound::services::site::{MockSiteService, SiteServiceProvider},
|
outbound::services::site::{MockSiteService, SiteServiceProvider},
|
||||||
};
|
};
|
||||||
|
@ -186,4 +187,130 @@ mod tests {
|
||||||
assert!(elem_str.contains("Hello, world!"));
|
assert!(elem_str.contains("Hello, world!"));
|
||||||
assert!(elem_str.contains("Something else!"));
|
assert!(elem_str.contains("Something else!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn page_renders_collection() {
|
||||||
|
let mut app = VirtualDom::new(|| {
|
||||||
|
rsx! {
|
||||||
|
Page {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.provide_root_context(SiteContext {
|
||||||
|
info: SiteInfo {
|
||||||
|
title: "test".to_string(),
|
||||||
|
domain: "test".to_string(),
|
||||||
|
pages: vec![],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
app.provide_root_context(PageContext {
|
||||||
|
data: entities::site::Page {
|
||||||
|
info: entities::site::PageInfo {
|
||||||
|
title: "test".to_string(),
|
||||||
|
name: "test".to_string(),
|
||||||
|
order: 0,
|
||||||
|
},
|
||||||
|
content: PageContent::Collection {
|
||||||
|
kind: CollectionKind::Blog,
|
||||||
|
collection_id: "".to_string(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut mock_service = MockSiteService::new();
|
||||||
|
mock_service
|
||||||
|
.expect_get_posts()
|
||||||
|
.times(1)
|
||||||
|
.returning(move |_, _, _| {
|
||||||
|
Box::pin(async {
|
||||||
|
Ok(Paginated {
|
||||||
|
data: vec![Post {
|
||||||
|
blocks: vec![Block::Text {
|
||||||
|
text: "some post here!".to_string(),
|
||||||
|
}],
|
||||||
|
}],
|
||||||
|
next: None,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
server_context().insert(SiteServiceProvider::with(mock_service));
|
||||||
|
|
||||||
|
app.rebuild_in_place();
|
||||||
|
let elem_str = dioxus::ssr::render(&app);
|
||||||
|
assert!(elem_str.contains("some post here!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn page_renders_flat_post() {
|
||||||
|
let mut app = VirtualDom::new(|| {
|
||||||
|
rsx! {
|
||||||
|
Page {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.provide_root_context(SiteContext {
|
||||||
|
info: SiteInfo {
|
||||||
|
title: "test".to_string(),
|
||||||
|
domain: "test".to_string(),
|
||||||
|
pages: vec![],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
app.provide_root_context(PageContext {
|
||||||
|
data: entities::site::Page {
|
||||||
|
info: entities::site::PageInfo {
|
||||||
|
title: "test".to_string(),
|
||||||
|
name: "test".to_string(),
|
||||||
|
order: 0,
|
||||||
|
},
|
||||||
|
content: PageContent::Single {
|
||||||
|
content: Post {
|
||||||
|
blocks: vec![Block::Text {
|
||||||
|
text: "single post!".to_string(),
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
app.rebuild_in_place();
|
||||||
|
let elem_str = dioxus::ssr::render(&app);
|
||||||
|
assert!(elem_str.contains("single post!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn page_renders_title() {
|
||||||
|
let mut app = VirtualDom::new(|| {
|
||||||
|
rsx! {
|
||||||
|
Page {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.provide_root_context(SiteContext {
|
||||||
|
info: SiteInfo {
|
||||||
|
title: "test".to_string(),
|
||||||
|
domain: "test".to_string(),
|
||||||
|
pages: vec![],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
app.provide_root_context(PageContext {
|
||||||
|
data: entities::site::Page {
|
||||||
|
info: entities::site::PageInfo {
|
||||||
|
title: "Page name here".to_string(),
|
||||||
|
name: "test".to_string(),
|
||||||
|
order: 0,
|
||||||
|
},
|
||||||
|
content: PageContent::Single {
|
||||||
|
content: Post { blocks: vec![] },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
app.rebuild_in_place();
|
||||||
|
let elem_str = dioxus::ssr::render(&app);
|
||||||
|
assert!(elem_str.contains("Page name here"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ pub async fn get_posts(
|
||||||
domain: String,
|
domain: String,
|
||||||
collection_id: String,
|
collection_id: String,
|
||||||
) -> Result<Paginated<Post, String>, ServerFnError> {
|
) -> Result<Paginated<Post, String>, ServerFnError> {
|
||||||
println!("server_context: {:#?}", server_context().request_parts());
|
|
||||||
use crate::outbound::services::site::SiteServiceProvider;
|
use crate::outbound::services::site::SiteServiceProvider;
|
||||||
let FromContext(SiteServiceProvider { service }) = extract().await?;
|
let FromContext(SiteServiceProvider { service }) = extract().await?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue