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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use meta::{PageContext, SiteContext};
|
use meta::PageContext;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
domain::entities::{
|
domain::entities::{
|
||||||
self,
|
self,
|
||||||
cursor::Paginated,
|
cursor::Paginated,
|
||||||
site::{CollectionKind, Image, SiteInfo},
|
site::{CollectionKind, Image},
|
||||||
},
|
},
|
||||||
|
inbound::renderer::testing,
|
||||||
outbound::services::site::{MockSiteService, SiteServiceProvider},
|
outbound::services::site::{MockSiteService, SiteServiceProvider},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -90,11 +91,12 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn block_renders_text() {
|
fn block_renders_text() {
|
||||||
let text = "Hello, world!";
|
let text = "Hello, world!";
|
||||||
let block = Block::Text {
|
|
||||||
text: text.to_string(),
|
|
||||||
};
|
|
||||||
let element = rsx! {
|
let element = rsx! {
|
||||||
BlockElement { block }
|
BlockElement {
|
||||||
|
block: Block::Text {
|
||||||
|
text: text.to_string(),
|
||||||
|
},
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let elem_str = dioxus::ssr::render_element(element);
|
let elem_str = dioxus::ssr::render_element(element);
|
||||||
assert!(elem_str.contains(text));
|
assert!(elem_str.contains(text));
|
||||||
|
@ -102,19 +104,21 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn block_gallery_renders_images() {
|
fn block_gallery_renders_images() {
|
||||||
let images = vec![
|
|
||||||
Image {
|
|
||||||
src: "https://example.com/image1.jpg".to_string(),
|
|
||||||
caption: "Image 1".to_string(),
|
|
||||||
},
|
|
||||||
Image {
|
|
||||||
src: "https://example.com/image2.jpg".to_string(),
|
|
||||||
caption: "Image 2".to_string(),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
let block = Block::Gallery { images };
|
|
||||||
let element = rsx! {
|
let element = rsx! {
|
||||||
BlockElement { block }
|
BlockElement {
|
||||||
|
block: Block::Gallery {
|
||||||
|
images: vec![
|
||||||
|
Image {
|
||||||
|
src: "https://example.com/image1.jpg".to_string(),
|
||||||
|
caption: "Image 1".to_string(),
|
||||||
|
},
|
||||||
|
Image {
|
||||||
|
src: "https://example.com/image2.jpg".to_string(),
|
||||||
|
caption: "Image 2".to_string(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let elem_str = dioxus::ssr::render_element(element);
|
let elem_str = dioxus::ssr::render_element(element);
|
||||||
assert!(elem_str.contains("<img"));
|
assert!(elem_str.contains("<img"));
|
||||||
|
@ -124,17 +128,19 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn post_renders_blocks() {
|
fn post_renders_blocks() {
|
||||||
let blocks = vec![
|
|
||||||
Block::Text {
|
|
||||||
text: "Hello, world!".to_string(),
|
|
||||||
},
|
|
||||||
Block::Text {
|
|
||||||
text: "Something else!".to_string(),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
let post = Post { blocks };
|
|
||||||
let element = rsx! {
|
let element = rsx! {
|
||||||
PostElement { post }
|
PostElement {
|
||||||
|
post: Post {
|
||||||
|
blocks: vec![
|
||||||
|
Block::Text {
|
||||||
|
text: "Hello, world!".to_string(),
|
||||||
|
},
|
||||||
|
Block::Text {
|
||||||
|
text: "Something else!".to_string(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let elem_str = dioxus::ssr::render_element(element);
|
let elem_str = dioxus::ssr::render_element(element);
|
||||||
assert!(elem_str.contains("Hello, world!"));
|
assert!(elem_str.contains("Hello, world!"));
|
||||||
|
@ -149,13 +155,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.provide_root_context(SiteContext {
|
testing::add_test_site_context(&mut app);
|
||||||
info: SiteInfo {
|
|
||||||
title: "test".to_string(),
|
|
||||||
domain: "test".to_string(),
|
|
||||||
pages: vec![],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut mock_service = MockSiteService::new();
|
let mut mock_service = MockSiteService::new();
|
||||||
mock_service
|
mock_service
|
||||||
|
@ -196,13 +196,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.provide_root_context(SiteContext {
|
testing::add_test_site_context(&mut app);
|
||||||
info: SiteInfo {
|
|
||||||
title: "test".to_string(),
|
|
||||||
domain: "test".to_string(),
|
|
||||||
pages: vec![],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
app.provide_root_context(PageContext {
|
app.provide_root_context(PageContext {
|
||||||
data: entities::site::Page {
|
data: entities::site::Page {
|
||||||
|
@ -250,13 +244,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.provide_root_context(SiteContext {
|
testing::add_test_site_context(&mut app);
|
||||||
info: SiteInfo {
|
|
||||||
title: "test".to_string(),
|
|
||||||
domain: "test".to_string(),
|
|
||||||
pages: vec![],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
app.provide_root_context(PageContext {
|
app.provide_root_context(PageContext {
|
||||||
data: entities::site::Page {
|
data: entities::site::Page {
|
||||||
|
@ -288,13 +276,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.provide_root_context(SiteContext {
|
testing::add_test_site_context(&mut app);
|
||||||
info: SiteInfo {
|
|
||||||
title: "test".to_string(),
|
|
||||||
domain: "test".to_string(),
|
|
||||||
pages: vec![],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
app.provide_root_context(PageContext {
|
app.provide_root_context(PageContext {
|
||||||
data: entities::site::Page {
|
data: entities::site::Page {
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
#[component]
|
use crate::domain::entities::site::SiteInfo;
|
||||||
pub fn UseSiteContext() -> Element {
|
|
||||||
use_context_provider(|| Signal::new(0));
|
use super::meta::SiteContext;
|
||||||
rsx! {}
|
|
||||||
|
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