Skip to content

Commit

Permalink
test(mrml-core): test that columns render Fragment children correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Ellis <[email protected]>
  • Loading branch information
JadedBlueEyes committed Jul 1, 2024
1 parent c0aecd4 commit 908d1db
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/mrml-core/resources/compare/success/fragment-column.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title></title><!--[if !mso]><!--><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
#outlook a { padding: 0; }
body { margin: 0; padding: 0; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
table, td { border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; }
img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; }
p { display: block; margin: 13px 0; }
</style>
<!--[if mso]>
<noscript>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
</noscript>
<![endif]-->
<!--[if lte mso 11]>
<style type="text/css">
.mj-outlook-group-fix { width:100% !important; }
</style>
<![endif]-->
<!--[if !mso]><!--><link href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700" rel="stylesheet" type="text/css"><style type="text/css">@import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);</style><!--<![endif]--><style type="text/css">@media only screen and (min-width:480px) { .mj-column-per-100 { width:100% !important; max-width:100%; } }</style><style media="screen and (min-width:480px)">.moz-text-html .mj-column-per-100 { width:100% !important; max-width:100%; } </style><style type="text/css"></style></head><body style="word-spacing:normal;"><div><div class="mj-outlook-group-fix mj-column-per-100" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;"><table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%" style="vertical-align:top;"><tbody><tr><td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;"><div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;">Hello World!Same child</div></td></tr><tr><td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;"><div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;">Second child!</div></td></tr></tbody></table></div></div></body></html>
37 changes: 36 additions & 1 deletion packages/mrml-core/src/fragment/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod tests {
use crate::text::Text;

#[test]
fn empty_script_should_have_closing_element() {
fn fragment_children_should_render() {
use crate::mjml::Mjml;
use crate::prelude::render::RenderOptions;

Expand All @@ -88,4 +88,39 @@ mod tests {
assert!(result.contains("Hello World!"));
assert!(result.contains("Second child!"));
}

#[test]
fn fragment_should_render_col_correctly() {
use crate::mj_column::MjColumn;
use crate::mj_text::MjText;
use crate::mjml::Mjml;
use crate::prelude::render::RenderOptions;

let opts = RenderOptions::default();
let mut root = Mjml::default();
let body = crate::mj_body::MjBody {
children: vec![MjColumn {
children: vec![Fragment::from(vec![
MjText {
children: vec![Text::from("Hello World!").into(), Text::from("Same child").into()],
..Default::default()
}
.into(),
MjText {
children: vec![Text::from("Second child!").into()],
..Default::default()
}
.into(),
])
.into()],
..Default::default()
}
.into()],
..Default::default()
};
root.children.body = Some(body);
let result = root.render(&opts).unwrap();
let expected = include_str!(concat!("../../resources/compare/success/", "fragment-column", ".html"));
assert_eq!(result.as_str(), expected)
}
}

0 comments on commit 908d1db

Please sign in to comment.