Skip to content

Commit

Permalink
Show File System and Deployment Group form errors (#2396)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleDsz authored Dec 11, 2023
1 parent 74d98e5 commit c8fbad1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/livebook_web/live/hub/file_system_form_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,14 @@ defmodule LivebookWeb.Hub.FileSystemFormComponent do
|> put_flash(:success, message)
|> push_patch(to: socket.assigns.return_to)}
else
{:error, %Ecto.Changeset{} = changeset} -> {:noreply, assign(socket, changeset: changeset)}
{:transport_error, message} -> {:noreply, assign(socket, error_message: message)}
{:error, message} -> {:noreply, assign(socket, error_message: message)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: Map.replace!(changeset, :action, :validate))}

{:transport_error, message} ->
{:noreply, assign(socket, error_message: message)}

{:error, message} ->
{:noreply, assign(socket, error_message: message)}
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ defmodule LivebookWeb.Hub.Teams.DeploymentGroupFormComponent do
|> push_patch(to: ~p"/hub/#{socket.assigns.hub.id}/deployment-groups/edit/#{id}")}
else
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, changeset: changeset)}
{:noreply, assign(socket, changeset: Map.replace!(changeset, :action, :validate))}

{:transport_error, message} ->
{:noreply, assign(socket, error_message: message)}
Expand Down
20 changes: 20 additions & 0 deletions test/livebook_teams/web/hub/edit_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do
assert render(view) =~ "Secret TEAM_ADD_SECRET added successfully"
assert render(element(view, "#hub-secrets-list")) =~ secret.name
assert secret in Livebook.Hubs.get_secrets(hub)

# Guarantee it shows the error from API

{:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}/secrets/new")

view
|> element("#secrets-form")
|> render_submit(attrs)

assert render(view) =~ "has already been taken"
end

test "updates existing secret", %{conn: conn, hub: hub} do
Expand Down Expand Up @@ -332,6 +342,16 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do
assert_patch(view, "/hub/#{hub.id}/deployment-groups/edit/#{id}")
assert render(view) =~ "Deployment group TEAM_ADD_DEPLOYMENT_GROUP added successfully"
assert deployment_group in Livebook.Teams.get_deployment_groups(hub)

# Guarantee it shows the error from API

{:ok, view, _html} = live(conn, ~p"/hub/#{hub.id}/deployment-groups/new")

view
|> element("#deployment-groups-form")
|> render_submit(attrs)

assert render(view) =~ "has already been taken"
end

test "updates existing deployment group", %{conn: conn, hub: hub} do
Expand Down

0 comments on commit c8fbad1

Please sign in to comment.