Skip to content

Commit

Permalink
Updating tests to cover components
Browse files Browse the repository at this point in the history
  • Loading branch information
akoutmos committed Apr 15, 2022
1 parent 189272b commit dd41614
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion test/mjml_eex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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
Expand All @@ -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
52 changes: 52 additions & 0 deletions test/test_templates/invalid_component_template.mjml.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<mjml>
<% render_component(MjmlEEx.TestComponents.HeadBlock, [title: "Hello!"]) %>
<mj-body background-color="#F2F2F2">
<mj-section padding="10px 0 20px 0">
<mj-column>
<mj-text align="center" color="#9B9B9B" font-size="11px">Writing A Good Headline For Your Advertisement</mj-text>
</mj-column>
</mj-section>
<mj-section padding="20px 20px 0 20px" background-color="#FFFFFF">
<mj-column width="35%">
<mj-text align="left" font-size="20px" font-weight="500">// BR&amp;AND</mj-text>
</mj-column>
<mj-column width="65%">
<mj-text align="right" font-size="11px"><a href="#" style="color: #000000; text-decoration: none;">HOME</a>&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;<a href="#" style="color: #000000; text-decoration: none;">SERVICE</a>&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;<a href="#" style="color: #000000; text-decoration: none;">THIRD</a></mj-text>
</mj-column>
</mj-section>
<mj-section padding="20px 20px 0 20px" background-color="#FFFFFF">
<mj-column>
<mj-text align="center" font-weight="300" padding="30px 40px 10px 40px" font-size="32px" line-height="40px" color="#5FA91D">Free Advertising For Your Online Business.</mj-text>
</mj-column>
</mj-section>
<mj-section padding="10px 20px" background-color="#FFFFFF">
<mj-column>
<mj-divider width="30px" border-width="3px" border-color="#9B9B9B"></mj-divider>
</mj-column>
</mj-section>
<mj-section padding="0 20px 20px 20px" background-color="#FFFFFF">
<mj-column width="80%">
<mj-text align="center" padding-top="10px" font-weight="500" padding="0px">A Right Media Mix Can Make The Difference.</mj-text>
</mj-column>
</mj-section>
<mj-section background-url="http://nimus.de/share/tpl-card/bg.jpg" vertical-align="middle" background-size="cover" background-repeat="no-repeat">
<mj-column width="100%">
<mj-image src="http://nimus.de/share/tpl-card/lineshadow.png" alt="" align="center" border="none" padding="0px"></mj-image>
<mj-text align="center" padding="50px 40px 0 40px" font-weight="300">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.</mj-text>
<mj-button align="center" background-color="#5FA91D" color="#FFFFFF" border-radius="2px" href="#" inner-padding="15px 30px" padding-bottom="100px" padding-top="20px">
<%= @call_to_action_text %>
</mj-button>
</mj-column>
</mj-section>
<mj-section padding="50px 0 0 0" background-color="#FFFFFF">
<mj-column>
<mj-image src="http://nimus.de/share/tpl-card/bottom.png" alt="bottom border" align="center" border="none" padding="0px"></mj-image>
</mj-column>
</mj-section>
<mj-section padding="10px 0 20px 0">
<mj-column>
<mj-text align="center" color="#9B9B9B" font-size="11px"><a href="#" style="color: #9B9B9B;">Unsubscribe</a> from this newsletter<br />52 Edison Court Suite 259 / East Aidabury / Cambodi<br /> <a href="#" style="color: #9B9B9B; text-decoration:none;">Made by svenhaustein.de</a></mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>

0 comments on commit dd41614

Please sign in to comment.