allowthem_server/
shell_context.rs1use serde::Serialize;
2
3use crate::nav::{NavItem, nav_items_for};
4
5#[derive(Debug, Clone, Serialize)]
6pub struct ShellContext {
7 pub is_admin: bool,
8 pub current_path: String,
9 pub application_name: String,
10 pub nav_items: Vec<NavItem>,
11}
12
13impl ShellContext {
14 pub fn new(is_admin: bool, current_path: &str, application_name: &str) -> Self {
15 let nav_items = nav_items_for(is_admin, current_path);
16 Self {
17 is_admin,
18 current_path: current_path.to_string(),
19 application_name: application_name.to_string(),
20 nav_items,
21 }
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn builds_admin_shell_with_five_items() {
31 let s = ShellContext::new(true, "/admin/sessions", "allowthem");
32 assert!(s.is_admin);
33 assert_eq!(s.application_name, "allowthem");
34 assert_eq!(s.nav_items.len(), 5);
35 }
36
37 #[test]
38 fn builds_user_shell_with_two_items() {
39 let s = ShellContext::new(false, "/settings", "allowthem");
40 assert!(!s.is_admin);
41 assert_eq!(s.nav_items.len(), 2);
42 }
43}