expand test to check html after post

master
rasul 5 years ago
parent e64de60953
commit 3e08364cd5

@ -23,7 +23,14 @@ fn get_index() {
} }
#[test] #[test]
fn submit_html() { fn submit_html_and_check_html() {
use askama::Template;
use syntect::html::ClassedHTMLGenerator;
use crate::routes::view::View;
use crate::paste::Paste;
use crate::syntax::SYNTAX_SET;
let res = TEST_SERVER let res = TEST_SERVER
.client() .client()
.post( .post(
@ -34,6 +41,44 @@ fn submit_html() {
.perform() .perform()
.unwrap(); .unwrap();
assert_eq!(res.status(), StatusCode::SEE_OTHER); assert_eq!(res.status(), StatusCode::SEE_OTHER);
let location: String = res.headers().get("Location").unwrap().to_str().unwrap().into();
let id: String = location.clone().split('/').last().unwrap().into();
let mut new_url = CONFIG.url.clone();
new_url.push_str(&location);
let res = TEST_SERVER.client().get(new_url).perform().unwrap();
assert_eq!(res.status(), StatusCode::OK);
let body = res.read_utf8_body().unwrap();
let mut path = CONFIG.data_directory.clone();
path.push(&id);
let paste = Paste::from_file(path).unwrap();
let text_lines: Vec<String> = paste.text.lines().map(|s| s.into()).collect();
let index_len = format!("{}", text_lines.len()).len();
let syntax = SYNTAX_SET
.find_syntax_by_name(&paste.lang)
.unwrap_or_else(|| SYNTAX_SET.find_syntax_plain_text());
let mut high_lines: Vec<String> = Vec::new();
for line in text_lines {
let mut html_generator = ClassedHTMLGenerator::new(&syntax, &SYNTAX_SET);
html_generator.parse_html_for_line(&line);
high_lines.push(html_generator.finalize());
}
let template: View = View {
id,
dt: paste.dt.format("%Y-%m-%dT%H:%MZ").to_string(),
text_lines: high_lines,
index_len,
site_url: CONFIG.url.clone(),
syntax: paste.lang,
};
let content = template.render().unwrap();
assert_eq!(body, content);
} }
#[test] #[test]

Loading…
Cancel
Save