Skip to content

Commit 7ffb4ab

Browse files
committed
Test next and previous navigation helpers
1 parent 31982bc commit 7ffb4ab

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/renderer/html_handlebars/helpers/navigation.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,42 @@ pub fn next(_h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> Result<(), R
135135

136136
Ok(())
137137
}
138+
139+
#[cfg(test)]
140+
mod tests {
141+
use super::*;
142+
143+
#[test]
144+
fn test_next_previous() {
145+
let template = "
146+
{{#previous}}{{title}}: {{link}}{{/previous}}
147+
{{#next}}{{title}}: {{link}}{{/next}}";
148+
149+
let data = json!({
150+
"name": "two",
151+
"path": "two.path",
152+
"chapters": [
153+
{
154+
"name": "one",
155+
"path": "one.path"
156+
},
157+
{
158+
"name": "two",
159+
"path": "two.path",
160+
},
161+
{
162+
"name": "three",
163+
"path": "three.path"
164+
}
165+
]
166+
});
167+
168+
let mut h = Handlebars::new();
169+
h.register_helper("previous", Box::new(previous));
170+
h.register_helper("next", Box::new(next));
171+
172+
assert_eq!(h.template_render(template, &data).unwrap(), "
173+
one: one.html
174+
three: three.html");
175+
}
176+
}

0 commit comments

Comments
 (0)