forked from surface-ui/surface
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add syntactic sugar to :keyword and :map properties
- Loading branch information
Showing
2 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
defmodule Surface.PropertiesTest do | ||
use ExUnit.Case | ||
use Phoenix.ConnTest | ||
|
||
import Surface | ||
import ComponentTestHelper | ||
|
||
defmodule Props do | ||
use Surface.Component | ||
|
||
property keyword, :keyword | ||
property map, :map | ||
|
||
def render(assigns) do | ||
~H""" | ||
<span :if={{@keyword}}>{{inspect(@keyword)}}</span> | ||
<span :if={{@map}}>{{inspect(@map)}}</span> | ||
""" | ||
end | ||
end | ||
|
||
describe "keyword" do | ||
test "passing a keyword list" do | ||
code = """ | ||
<Props keyword={{ [option1: 1, option2: 2] }}/> | ||
""" | ||
|
||
assert render_live(code) =~ "[option1: 1, option2: 2]" | ||
end | ||
|
||
test "passing a keyword list without brackets" do | ||
code = """ | ||
<Props keyword={{ option1: 1, option2: 2 }}/> | ||
""" | ||
|
||
assert render_live(code) =~ "[option1: 1, option2: 2]" | ||
end | ||
end | ||
|
||
describe "map" do | ||
test "passing a map" do | ||
code = """ | ||
<Props map={{ %{option1: 1, option2: 2} }}/> | ||
""" | ||
|
||
assert render_live(code) =~ "%{option1: 1, option2: 2}" | ||
end | ||
|
||
test "passing a keyword list" do | ||
code = """ | ||
<Props map={{ [option1: 1, option2: 2] }}/> | ||
""" | ||
|
||
assert render_live(code) =~ "%{option1: 1, option2: 2}" | ||
end | ||
|
||
test "accepts a keyword list without brackets" do | ||
code = """ | ||
<Props map={{ option1: 1, option2: 2 }}/> | ||
""" | ||
|
||
assert render_live(code) =~ "%{option1: 1, option2: 2}" | ||
end | ||
end | ||
end |