Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/export #8

Merged
merged 21 commits into from
Jul 14, 2023
Prev Previous commit
Next Next commit
added generate_html helper test
  • Loading branch information
yplog committed Jul 13, 2023
commit 95bcfc2bdca5b2913f01015ab8e775852ab70f4d
42 changes: 30 additions & 12 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,22 @@ pub fn print_result<T, E>(result: Result<T, E>) -> Result<(), io::Error> {
pub fn generate_html(groups: HashMap<NaiveDate, Vec<models::Todo>>) -> String {
let header: &str = r#"<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

"#;

let footer: &str = r#"
</body>
</body>
</html>
"#;

let mut content = header.to_owned();

for (date, todos) in groups.iter() {
let h1 = format!(
r#"
<h1>{}</h1>
"#,
date
);
let h1 = format!(r#"<h1>{}</h1>"#, date);

content.push_str(&h1);

Expand All @@ -122,7 +114,7 @@ pub fn generate_html(groups: HashMap<NaiveDate, Vec<models::Todo>>) -> String {
#[cfg(test)]
mod tests {
use super::*;
use chrono::Duration;
use chrono::{Duration, Utc};

#[test]
fn test_get_date() {
Expand Down Expand Up @@ -215,6 +207,32 @@ mod tests {

#[test]
fn test_generate_html() {
!unimplemented!()
use chrono::NaiveDate;
use models::Todo;
use std::collections::HashMap;

// Create some sample data
let mut groups: HashMap<NaiveDate, Vec<Todo>> = HashMap::new();
let todos = vec![
Todo {
id: 1,
content: "Buy groceries".to_owned(),
completed: false,
when_will_it_be_done: Utc::now().naive_utc().into(),
},
Todo {
id: 2,
content: "Clean the house".to_owned(),
completed: true,
when_will_it_be_done: Utc::now().naive_utc().into(),
},
];
groups.insert(NaiveDate::from_ymd_opt(2023, 7, 1).unwrap(), todos);

// Call the generate_html function
let html = generate_html(groups);
let slice = &html[0..15];

assert_eq!(slice, "<!DOCTYPE html>");
}
}