Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend test for deeply nested union stuff #259

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions test/auto_form_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@
|> form_for("action")
end

test "
show correct values on for_update forms" do
test "show correct values on for_update forms" do
a =
Post
|> AshPhoenix.Form.for_create(:create, domain: Domain, forms: [auto?: true])
Expand Down Expand Up @@ -395,6 +394,38 @@
assert(subform[:number].value == 1)
end

test "show correct values on for_update forms with deeply nested values" do

Check failure on line 397 in test/auto_form_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci / mix test

test list unions show correct values on for_update forms with deeply nested values (AshPhoenix.AutoFormTest)
create_form =
Post
|> AshPhoenix.Form.for_create(:create, domain: Domain, forms: [auto?: true])
|> AshPhoenix.Form.add_form(:union_array,
params: %{"_union_type" => "foo", "value" => "abc", "number" => 1}
)
|> AshPhoenix.Form.add_form(:union_array,
params: %{"_union_type" => "foo", "value" => "abc", "number" => 2}
)
|> AshPhoenix.Form.add_form([:union_array, 0, :embeds], params: %{"value" => "meow"})
|> AshPhoenix.Form.add_form([:union_array, 0, :embeds, :nested_embeds],
params: %{
"limit" => 4,
"four_chars" => "four"
}
)

post =
AshPhoenix.Form.submit!(create_form,
params: Map.put(AshPhoenix.Form.params(create_form), "text", "Test Post Text")
)

form =
post
|> AshPhoenix.Form.for_update(:update, forms: [auto?: true])
|> AshPhoenix.Form.get_form([:union_array, 0, :embeds, :nested_embeds, 0])
|> Phoenix.HTML.FormData.to_form(as: :form)

assert(form[:limit].value == 4)
end

test "a form can be removed from a union" do
form =
Post
Expand Down
2 changes: 2 additions & 0 deletions test/support/resources/foo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ defmodule AshPhoenix.Test.Foo do
end

attribute :number, :integer, public?: true

attribute :embeds, AshPhoenix.Test.EmbeddedArgument, public?: true
end
end
Loading