From dd416140216856439f3c9268ba8d978b6fc48f78 Mon Sep 17 00:00:00 2001 From: Alex Koutmos Date: Fri, 15 Apr 2022 14:06:49 -0400 Subject: [PATCH] Updating tests to cover components --- mix.exs | 2 +- test/mjml_eex_test.exs | 25 ++++++++- .../invalid_component_template.mjml.eex | 52 +++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 test/test_templates/invalid_component_template.mjml.eex diff --git a/mix.exs b/mix.exs index 6ba924d..9e626a9 100644 --- a/mix.exs +++ b/mix.exs @@ -25,7 +25,7 @@ defmodule MjmlEEx.MixProject do end # Specifies which paths to compile per environment. - defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(:test), do: ["lib", "test/test_components"] defp elixirc_paths(_), do: ["lib"] defp package do diff --git a/test/mjml_eex_test.exs b/test/mjml_eex_test.exs index 3b2e89c..5e7a6b2 100644 --- a/test/mjml_eex_test.exs +++ b/test/mjml_eex_test.exs @@ -9,6 +9,10 @@ defmodule MjmlEExTest do use MjmlEEx, mjml_template: "test_templates/conditional_template.mjml.eex" end + defmodule ComponentTemplate do + use MjmlEEx, mjml_template: "test_templates/component_template.mjml.eex" + end + describe "BasicTemplate.render/1" do test "should raise an error if no assigns are provided" do assert_raise ArgumentError, ~r/assign @call_to_action_text not available in template/, fn -> @@ -28,7 +32,7 @@ defmodule MjmlEExTest do end end - describe "ErrorTemplate.render/1" do + describe "ErrorTemplate" do test "should raise an error if the MJML template fails to compile" do assert_raise RuntimeError, ~r/Failed to compile MJML template: \"unexpected element at position 448\"/, fn -> defmodule InvalidTemplateOption do @@ -55,4 +59,23 @@ defmodule MjmlEExTest do end end end + + describe "ComponentTemplate.render/1" do + test "should render the document with the head and attribute block" do + assert ComponentTemplate.render(all_caps: true) =~ "SIGN UP TODAY!!" + assert ComponentTemplate.render(all_caps: true) =~ "mj-head" + assert ComponentTemplate.render(all_caps: true) =~ "mj-font name=\"Roboto\"" + assert ComponentTemplate.render(all_caps: true) =~ "mj-attributes" + end + end + + describe "InvalidComponentTemplate" do + test "should fail to compile since the render_component call is not in an = expression" do + assert_raise RuntimeError, ~r/render_component can only be invoked inside of an <%= ... %> expression/, fn -> + defmodule InvalidTemplateOption do + use MjmlEEx, mjml_template: "test_templates/invalid_component_template.mjml.eex" + end + end + end + end end diff --git a/test/test_templates/invalid_component_template.mjml.eex b/test/test_templates/invalid_component_template.mjml.eex new file mode 100644 index 0000000..6d4046f --- /dev/null +++ b/test/test_templates/invalid_component_template.mjml.eex @@ -0,0 +1,52 @@ + + <% render_component(MjmlEEx.TestComponents.HeadBlock, [title: "Hello!"]) %> + + + + Writing A Good Headline For Your Advertisement + + + + + // BR&AND + + + HOME   /   SERVICE   /   THIRD + + + + + Free Advertising For Your Online Business. + + + + + + + + + + A Right Media Mix Can Make The Difference. + + + + + + Marketers/advertisers usually focus their efforts on the people responsible for making the purchase. In many cases, this is an effective approach but in other cases it can make for a totally useless marketing campaign. + + <%= @call_to_action_text %> + + + + + + + + + + + Unsubscribe from this newsletter
52 Edison Court Suite 259 / East Aidabury / Cambodi
Made by svenhaustein.de
+
+
+
+