//! Code for whole frames: nested HTML with a stylesheet (flexbox for auto layout, absolute //! positions elsewhere), unique class names, escaped text. use serde_json::{Value, json}; use crate::Session; use crate::codegen::{CodeLang, code_for}; use crate::params::id_of; fn id(v: Value) -> figcraft_doc::NodeId { id_of(&v["id"]).unwrap() } #[test] fn frames_become_nested_html_with_flexbox_and_absolute_children() { let mut s = Session::new(); let card = id(s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 200, "height": 120})).unwrap()); s.execute("node.set", &json!({"id": card, "props": {"name": "Card"}})).unwrap(); let a = id(s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 50, "height": 20, "parent": card})).unwrap()); let b = id(s.execute("shape.rectangle", &json!({"x": 0, "y": 30, "width": 50, "height": 20, "parent": card})).unwrap()); for r in [a, b] { s.execute("node.set", &json!({"id": r, "props": {"name": "Row", "fill": "#0D99FF"}})).unwrap(); } let t = id(s.execute("text.create", &json!({"text": "Hi & ", "x": 0, "y": 60})).unwrap()); s.execute("node.reparent", &json!({"ids": [t], "parent": card})).unwrap(); s.execute("layout.add", &json!({"ids": [card]})).unwrap(); s.execute("node.set", &json!({"id": card, "props": {"layoutMode": "vertical", "gap": 8}})).unwrap(); let code = code_for(s.doc().unwrap(), card, CodeLang::Html); assert!(code.starts_with("
"), "{code}"); assert!(code.contains("
") && code.contains("
"), "unique classes: {code}"); assert!(code.contains("& <bye>

"), "escaped text: {code}"); assert!(code.contains(".card {\n position: relative;\n") && code.contains("display: flex;") && code.contains("flex-direction: column;")); assert!(!code.contains(".row {\n position: absolute"), "flex items flow"); assert!(code.trim_end().ends_with("")); // Without auto layout, children sit at their positions. s.execute("layout.remove", &json!({"ids": [card]})).unwrap(); let code = code_for(s.doc().unwrap(), card, CodeLang::Html); assert!(code.contains(".row-2 {\n position: absolute;\n left: "), "{code}"); // The command takes the language by id. let out = s.execute("inspect.code", &json!({"id": card, "language": "html"})).unwrap(); assert!(out["code"].as_str().unwrap().contains("