minor test refactoring
This commit is contained in:
parent
d63b566873
commit
0bc40b492f
2 changed files with 50 additions and 60 deletions
|
@ -74,14 +74,15 @@ pub fn BlockElement(block: Block) -> Element {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use meta::{PageContext, SiteContext};
|
||||
use meta::PageContext;
|
||||
|
||||
use crate::{
|
||||
domain::entities::{
|
||||
self,
|
||||
cursor::Paginated,
|
||||
site::{CollectionKind, Image, SiteInfo},
|
||||
site::{CollectionKind, Image},
|
||||
},
|
||||
inbound::renderer::testing,
|
||||
outbound::services::site::{MockSiteService, SiteServiceProvider},
|
||||
};
|
||||
|
||||
|
@ -90,11 +91,12 @@ mod tests {
|
|||
#[test]
|
||||
fn block_renders_text() {
|
||||
let text = "Hello, world!";
|
||||
let block = Block::Text {
|
||||
text: text.to_string(),
|
||||
};
|
||||
let element = rsx! {
|
||||
BlockElement { block }
|
||||
BlockElement {
|
||||
block: Block::Text {
|
||||
text: text.to_string(),
|
||||
},
|
||||
}
|
||||
};
|
||||
let elem_str = dioxus::ssr::render_element(element);
|
||||
assert!(elem_str.contains(text));
|
||||
|
@ -102,7 +104,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn block_gallery_renders_images() {
|
||||
let images = vec![
|
||||
let element = rsx! {
|
||||
BlockElement {
|
||||
block: Block::Gallery {
|
||||
images: vec![
|
||||
Image {
|
||||
src: "https://example.com/image1.jpg".to_string(),
|
||||
caption: "Image 1".to_string(),
|
||||
|
@ -111,10 +116,9 @@ mod tests {
|
|||
src: "https://example.com/image2.jpg".to_string(),
|
||||
caption: "Image 2".to_string(),
|
||||
},
|
||||
];
|
||||
let block = Block::Gallery { images };
|
||||
let element = rsx! {
|
||||
BlockElement { block }
|
||||
],
|
||||
},
|
||||
}
|
||||
};
|
||||
let elem_str = dioxus::ssr::render_element(element);
|
||||
assert!(elem_str.contains("<img"));
|
||||
|
@ -124,17 +128,19 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn post_renders_blocks() {
|
||||
let blocks = vec![
|
||||
let element = rsx! {
|
||||
PostElement {
|
||||
post: Post {
|
||||
blocks: vec![
|
||||
Block::Text {
|
||||
text: "Hello, world!".to_string(),
|
||||
},
|
||||
Block::Text {
|
||||
text: "Something else!".to_string(),
|
||||
},
|
||||
];
|
||||
let post = Post { blocks };
|
||||
let element = rsx! {
|
||||
PostElement { post }
|
||||
],
|
||||
},
|
||||
}
|
||||
};
|
||||
let elem_str = dioxus::ssr::render_element(element);
|
||||
assert!(elem_str.contains("Hello, world!"));
|
||||
|
@ -149,13 +155,7 @@ mod tests {
|
|||
}
|
||||
});
|
||||
|
||||
app.provide_root_context(SiteContext {
|
||||
info: SiteInfo {
|
||||
title: "test".to_string(),
|
||||
domain: "test".to_string(),
|
||||
pages: vec![],
|
||||
},
|
||||
});
|
||||
testing::add_test_site_context(&mut app);
|
||||
|
||||
let mut mock_service = MockSiteService::new();
|
||||
mock_service
|
||||
|
@ -196,13 +196,7 @@ mod tests {
|
|||
}
|
||||
});
|
||||
|
||||
app.provide_root_context(SiteContext {
|
||||
info: SiteInfo {
|
||||
title: "test".to_string(),
|
||||
domain: "test".to_string(),
|
||||
pages: vec![],
|
||||
},
|
||||
});
|
||||
testing::add_test_site_context(&mut app);
|
||||
|
||||
app.provide_root_context(PageContext {
|
||||
data: entities::site::Page {
|
||||
|
@ -250,13 +244,7 @@ mod tests {
|
|||
}
|
||||
});
|
||||
|
||||
app.provide_root_context(SiteContext {
|
||||
info: SiteInfo {
|
||||
title: "test".to_string(),
|
||||
domain: "test".to_string(),
|
||||
pages: vec![],
|
||||
},
|
||||
});
|
||||
testing::add_test_site_context(&mut app);
|
||||
|
||||
app.provide_root_context(PageContext {
|
||||
data: entities::site::Page {
|
||||
|
@ -288,13 +276,7 @@ mod tests {
|
|||
}
|
||||
});
|
||||
|
||||
app.provide_root_context(SiteContext {
|
||||
info: SiteInfo {
|
||||
title: "test".to_string(),
|
||||
domain: "test".to_string(),
|
||||
pages: vec![],
|
||||
},
|
||||
});
|
||||
testing::add_test_site_context(&mut app);
|
||||
|
||||
app.provide_root_context(PageContext {
|
||||
data: entities::site::Page {
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub fn UseSiteContext() -> Element {
|
||||
use_context_provider(|| Signal::new(0));
|
||||
rsx! {}
|
||||
use crate::domain::entities::site::SiteInfo;
|
||||
|
||||
use super::meta::SiteContext;
|
||||
|
||||
pub fn add_test_site_context(app: &mut VirtualDom) {
|
||||
app.provide_root_context(SiteContext {
|
||||
info: SiteInfo {
|
||||
title: "test".to_string(),
|
||||
domain: "test".to_string(),
|
||||
pages: vec![],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue