Skip to content

Commit

Permalink
Add a few core component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed Nov 1, 2024
1 parent a39d0f8 commit 112f1be
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions test/live_view_native/swiftui/core_components_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ defmodule LiveViewNative.SwiftUI.CoreComponentsTest do
end

describe "simple_form/1" do
test "can render empty form" do
params = %{}
form = to_form(params, as: "user")

assigns = %{form: form}

template = ~LVN"""
<.simple_form for={@form}>
</.simple_form>
"""

assert t2h(template) ==
~X"""
<LiveForm>
<Form>
<Section/>
</Form>
</LiveForm>
"""
end

test "can render form with an input" do
params = %{"email" => "test@example.com"}
form = to_form(params, as: "user")
Expand Down Expand Up @@ -92,15 +113,68 @@ defmodule LiveViewNative.SwiftUI.CoreComponentsTest do
end

describe "button/1" do
test "will render a button" do
assigns = %{}

template = ~LVN"""
<.button>Send!</.button>
"""

assert t2h(template) ==
~X"""
<Button>
Send!
</Button>
"""

end
end

describe "table" do

end

describe "list/1" do
test "will render a list" do
assigns = %{}

template = ~LVN"""
<.list>
<:item :for={item <- [%{title: "Foo"}, %{title: "Bar"}]} title={item.title}>
<Text><%= item.title %></Text>
</:item>
</.list>
"""

assert t2h(template) ==
~X"""
<List>
<LabeledContent>
<Text template="label">Foo</Text>
<Text>Foo</Text>
</LabeledContent>
<LabeledContent>
<Text template="label">Bar</Text>
<Text>Bar</Text>
</LabeledContent>
</List>
"""
end
end

describe "icon/1" do
test "renders an image tag as a system icon" do
assigns = %{}

template = ~LVN"""
<.icon name="star"/>
"""

assert t2h(template) ==
~X"""
<Image systemName="star"/>
"""
end
end

describe "image/1" do
Expand Down

0 comments on commit 112f1be

Please sign in to comment.