fixed errors found by tests; fixed tests

This commit is contained in:
Adam Piontek 2021-03-04 23:15:20 -05:00
parent 42c7a49e88
commit 6c5d6ce046
5 changed files with 93 additions and 37 deletions

View file

@ -1,4 +1,5 @@
<%= form_for @changeset, "#", [
id: "property-form",
phx_target: @myself,
phx_change: "validate",
phx_submit: "save"

View file

@ -17,18 +17,29 @@ defmodule Bones73kWeb.PropertyLive.Show do
property = Properties.get_property!(id)
if Roles.can?(current_user, property, live_action) do
{:noreply,
socket
|> assign(:property, property)
|> assign(:page_title, page_title(live_action))}
socket
|> assign(:property, property)
|> assign(:page_title, page_title(live_action))
|> assign(:modal_return_to, Routes.property_show_path(socket, :show, property))
|> live_noreply()
else
{:noreply,
socket
|> put_flash(:error, "Unauthorised")
|> redirect(to: "/")}
socket
|> put_flash(:error, "Unauthorised")
|> redirect(to: "/")
|> live_noreply()
end
end
@impl true
def handle_info({:close_modal, _}, %{assigns: %{modal_return_to: to}} = socket) do
socket |> copy_flash() |> push_patch(to: to) |> live_noreply()
end
@impl true
def handle_info({:put_flash_message, {flash_type, msg}}, socket) do
socket |> put_flash(flash_type, msg) |> live_noreply()
end
defp page_title(:show), do: "Show Property"
defp page_title(:edit), do: "Edit Property"
end

View file

@ -5,8 +5,7 @@
id: @property.id,
title: @page_title,
action: @live_action,
property: @property,
return_to: Routes.property_show_path(@socket, :show, @property) %>
property: @property %>
<% end %>
<table class="table table-nonfluid">

View file

@ -54,14 +54,23 @@ defmodule Bones73kWeb.PropertyLiveTest do
|> form("#property-form", property: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
{:ok, _, html} =
index_live
|> form("#property-form", property: @create_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.property_index_path(conn, :index))
# update form attrs
index_live
|> form("#property-form", property: @update_attrs)
|> render_change()
# submit new form attrs
index_live
|> form("#property-form", property: @update_attrs)
|> render_submit()
# send modal close event & observe results
send(index_live.pid, {:close_modal, true})
html = render(index_live)
assert_patched(index_live, Routes.property_index_path(conn, :index))
assert html =~ "Property created successfully"
assert html =~ "some description"
assert html =~ "some updated description"
end
test "updates property in listing", %{conn: conn, property: property} do
@ -76,12 +85,21 @@ defmodule Bones73kWeb.PropertyLiveTest do
|> form("#property-form", property: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
{:ok, _, html} =
index_live
|> form("#property-form", property: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.property_index_path(conn, :index))
# update form attrs
index_live
|> form("#property-form", property: @update_attrs)
|> render_change()
# submit new form attrs
index_live
|> form("#property-form", property: @update_attrs)
|> render_submit()
# send modal close event & observe results
send(index_live.pid, {:close_modal, true})
html = render(index_live)
assert_patched(index_live, Routes.property_index_path(conn, :index))
assert html =~ "Property updated successfully"
assert html =~ "some updated description"
end
@ -130,12 +148,21 @@ defmodule Bones73kWeb.PropertyLiveTest do
|> form("#property-form", property: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
{:ok, _, html} =
index_live
|> form("#property-form", property: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.property_index_path(conn, :index))
# update form attrs
index_live
|> form("#property-form", property: @update_attrs)
|> render_change()
# submit new form attrs
index_live
|> form("#property-form", property: @update_attrs)
|> render_submit()
# send modal close event & observe results
send(index_live.pid, {:close_modal, true})
html = render(index_live)
assert_patched(index_live, Routes.property_index_path(conn, :index))
assert html =~ "Property updated successfully"
assert html =~ "some updated description"
end
@ -257,12 +284,21 @@ defmodule Bones73kWeb.PropertyLiveTest do
|> form("#property-form", property: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
{:ok, _, html} =
show_live
|> form("#property-form", property: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.property_show_path(conn, :show, property))
# update form attrs
show_live
|> form("#property-form", property: @update_attrs)
|> render_change()
# submit new form attrs
show_live
|> form("#property-form", property: @update_attrs)
|> render_submit()
# send modal close event & observe results
send(show_live.pid, {:close_modal, true})
html = render(show_live)
assert_patched(show_live, Routes.property_show_path(conn, :show, property))
assert html =~ "Property updated successfully"
assert html =~ "some updated description"
end
@ -293,12 +329,21 @@ defmodule Bones73kWeb.PropertyLiveTest do
|> form("#property-form", property: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
{:ok, _, html} =
show_live
|> form("#property-form", property: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.property_show_path(conn, :show, property))
# update form attrs
show_live
|> form("#property-form", property: @update_attrs)
|> render_change()
# submit new form attrs
show_live
|> form("#property-form", property: @update_attrs)
|> render_submit()
# send modal close event & observe results
send(show_live.pid, {:close_modal, true})
html = render(show_live)
assert_patched(show_live, Routes.property_show_path(conn, :show, property))
assert html =~ "Property updated successfully"
assert html =~ "some updated description"
end

View file

@ -36,7 +36,7 @@ defmodule Bones73k.AccountsFixtures do
# {:ok, captured} = fun.(&"[TOKEN]#{&1}[TOKEN]")
# [_, token, _] = String.split(captured.body, "[TOKEN]")
# token
%Bamboo.Email{} = email = fun.(&"[TOKEN]#{&1}[TOKEN]")
{:ok, %Bamboo.Email{} = email} = fun.(&"[TOKEN]#{&1}[TOKEN]")
[_, token, _] = String.split(email.text_body, "[TOKEN]")
token
end