Packages
corex
0.1.1
0.1.2
0.1.1
0.1.0
0.1.0-rc.1
0.1.0-rc.0
0.1.0-beta.5
0.1.0-beta.4
0.1.0-beta.3
0.1.0-beta.2
0.1.0-beta.1
0.1.0-alpha.33
0.1.0-alpha.32
0.1.0-alpha.31
0.1.0-alpha.30
0.1.0-alpha.29
0.1.0-alpha.28
0.1.0-alpha.27
0.1.0-alpha.26
0.1.0-alpha.25
0.1.0-alpha.24
0.1.0-alpha.23
0.1.0-alpha.22
0.1.0-alpha.21
0.1.0-alpha.20
0.1.0-alpha.19
0.1.0-alpha.18
0.1.0-alpha.17
0.1.0-alpha.16
0.1.0-alpha.15
0.1.0-alpha.14
0.1.0-alpha.13
0.1.0-alpha.12
0.1.0-alpha.11
0.1.0-alpha.10
0.1.0-alpha.9
0.1.0-alpha.8
0.1.0-alpha.7
0.1.0-alpha.6
0.1.0-alpha.5
0.1.0-alpha.4
0.1.0-alpha.3
0.1.0-alpha.2
0.1.0-alpha.1
Accessible and unstyled UI components library written in Elixir and TypeScript that integrates Zag.js state machines into the Phoenix Framework.
Current section
Files
Jump to
Current section
Files
priv/templates/corex.gen.html/controller_test.exs
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ControllerTest do
use <%= inspect context.web_module %>.ConnCase
import <%= inspect context.module %>Fixtures
@create_attrs %{
<% params_create = schema.params.create %><%= for {{key, value}, idx} <- Enum.with_index(params_create) do %> <%= key %>: <%= Mix.Phoenix.Schema.value(schema, key, value) %><%= if idx < Enum.count(params_create) - 1 do %>,<% end %>
<% end %> }
@update_attrs %{
<% params_update = schema.params.update %><%= for {{key, value}, idx} <- Enum.with_index(params_update) do %> <%= key %>: <%= Mix.Phoenix.Schema.value(schema, key, value) %><%= if idx < Enum.count(params_update) - 1 do %>,<% end %>
<% end %> }
@invalid_attrs %{
<% params_create_inv = schema.params.create %><%= for {{key, _}, idx} <- Enum.with_index(params_create_inv) do %> <%= key %>: nil<%= if idx < Enum.count(params_create_inv) - 1 do %>,<% end %>
<% end %> }<%= if layout_locale do %>
@locale Application.compile_env(:<%= context.context_app %>, :locales, ["en"]) |> List.first()<% end %><%= if scope do %>
setup :<%= scope.test_setup_helper %><% end %>
describe "index" do
test "lists all <%= schema.plural %>", %{conn: conn<%= test_context_scope %>} do
conn = get(conn, ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>")
assert html_response(conn, 200) =~ "Listing <%= schema.human_plural %>"
end
end
describe "new <%= schema.singular %>" do
test "renders form", %{conn: conn<%= test_context_scope %>} do
conn = get(conn, ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>/new")
assert html_response(conn, 200) =~ "New <%= schema.human_singular %>"
end
end
describe "create <%= schema.singular %>" do
test "redirects to show when data is valid", %{conn: conn<%= test_context_scope %>} do
conn = post(conn, ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>", <%= schema.singular %>: @create_attrs)
assert %{<%= primary_key %>: <%= primary_key %>} = redirected_params(conn)
assert redirected_to(conn) == ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>/#{<%= primary_key %>}"
conn = get(conn, ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>/#{<%= primary_key %>}")
assert html_response(conn, 200) =~ "<%= schema.human_singular %> #{<%= primary_key %>}"
end
test "renders errors when data is invalid", %{conn: conn<%= test_context_scope %>} do
conn = post(conn, ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>", <%= schema.singular %>: @invalid_attrs)
assert html_response(conn, 200) =~ "New <%= schema.human_singular %>"
end
end
describe "edit <%= schema.singular %>" do
setup [:create_<%= schema.singular %>]
test "renders form for editing chosen <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %><%= test_context_scope %>} do
conn = get(conn, ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>/#{<%= schema.singular %>}/edit")
assert html_response(conn, 200) =~ "Edit <%= schema.human_singular %>"
end
end
describe "update <%= schema.singular %>" do
setup [:create_<%= schema.singular %>]
test "redirects when data is valid", %{conn: conn, <%= schema.singular %>: <%= schema.singular %><%= test_context_scope %>} do
conn = put(conn, ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>/#{<%= schema.singular %>}", <%= schema.singular %>: @update_attrs)
assert redirected_to(conn) == ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>/#{<%= schema.singular %>}"
conn = get(conn, ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>/#{<%= schema.singular %>}")<%= if schema.string_attr do %>
assert html_response(conn, 200) =~ <%= inspect Mix.Phoenix.Schema.default_param(schema, :update) %><% else %>
assert html_response(conn, 200)<% end %>
end
test "renders errors when data is invalid", %{conn: conn, <%= schema.singular %>: <%= schema.singular %><%= test_context_scope %>} do
conn = put(conn, ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>/#{<%= schema.singular %>}", <%= schema.singular %>: @invalid_attrs)
assert html_response(conn, 200) =~ "Edit <%= schema.human_singular %>"
end
end
describe "delete <%= schema.singular %>" do
setup [:create_<%= schema.singular %>]
test "deletes chosen <%= schema.singular %>", %{conn: conn, <%= schema.singular %>: <%= schema.singular %><%= test_context_scope %>} do
conn = delete(conn, ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>/#{<%= schema.singular %>}")
assert redirected_to(conn) == ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>"
assert_error_sent 404, fn ->
get(conn, ~p"<%= if layout_locale do %>/#{@locale}<% end %><%= scope_param_route_prefix %><%= schema.route_prefix %>/#{<%= schema.singular %>}")
end
end
end
<%= if scope do %> defp create_<%= schema.singular %>(%{scope: scope}) do
<%= schema.singular %> = <%= schema.singular %>_fixture(scope)
<% else %> defp create_<%= schema.singular %>(_) do
<%= schema.singular %> = <%= schema.singular %>_fixture()
<% end %>
%{<%= schema.singular %>: <%= schema.singular %>}
end
end