1
0
Fork 0

add tests for rendering the index pages

This commit is contained in:
Adrian Hedqvist 2023-03-26 13:05:39 +02:00
parent ff8f38c563
commit d585ba3f92
4 changed files with 48 additions and 2 deletions

View file

@ -51,3 +51,13 @@ impl IntoResponse for WebsiteError {
}
}
}
#[cfg(test)]
mod tests {
#[test]
fn render_index() {
let tera = tera::Tera::new("templates/**/*").unwrap();
let ctx = tera::Context::new();
let _res = tera.render("index.html", &ctx).unwrap();
}
}

View file

@ -74,3 +74,39 @@ pub async fn view(
.inc();
Ok(Html(res))
}
#[cfg(test)]
mod tests {
use chrono::DateTime;
use crate::post::Post;
use super::IndexContext;
#[test]
fn render_index() {
let posts = vec![Post {
title: "test".into(),
slug: "test".into(),
date: Some(DateTime::parse_from_rfc3339("2023-03-26T13:04:01+02:00").unwrap()),
..Default::default()
},
Post {
title: "test2".into(),
slug: "test2".into(),
date: None,
..Default::default()
}];
let ctx = IndexContext {
title: "Posts",
posts: posts.iter().collect(),
};
let tera = tera::Tera::new("templates/**/*").unwrap();
let _res = tera
.render(
"posts_index.html",
&tera::Context::from_serialize(ctx).unwrap(),
)
.unwrap();
}
}

View file

@ -1,7 +1,7 @@
use std::{collections::HashMap, sync::Arc};
use axum::{body, response::Response, routing::get, Extension, Router};
use color_eyre::eyre::{Result, Error};
use color_eyre::eyre::{Error, Result};
use hyper::header::CONTENT_TYPE;
use post::Post;
use prometheus::{Encoder, TextEncoder};

View file

@ -22,7 +22,7 @@ pub struct TomlFrontMatter {
pub tags: Option<Vec<String>>,
}
#[derive(Serialize, Clone, Debug)]
#[derive(Serialize, Clone, Debug, Default)]
pub struct Post {
pub title: String,
pub date: Option<DateTime<FixedOffset>>,