2022-07-25 20:12:11 -04:00
|
|
|
defmodule MemexWeb.PipelineLiveTest do
|
|
|
|
use MemexWeb.ConnCase
|
|
|
|
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
import Memex.PipelinesFixtures
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
@create_attrs %{
|
|
|
|
"description" => "some description",
|
|
|
|
"tags_string" => "tag1",
|
|
|
|
"title" => "some title",
|
|
|
|
"visibility" => :public
|
|
|
|
}
|
2022-07-25 22:05:54 -04:00
|
|
|
@update_attrs %{
|
2022-11-24 14:31:16 -05:00
|
|
|
"description" => "some updated description",
|
|
|
|
"tags_string" => "tag1,tag2",
|
|
|
|
"title" => "some updated title",
|
|
|
|
"visibility" => :private
|
|
|
|
}
|
|
|
|
@invalid_attrs %{
|
|
|
|
"description" => nil,
|
|
|
|
"tags_string" => "",
|
|
|
|
"title" => nil,
|
|
|
|
"visibility" => nil
|
2022-07-25 22:05:54 -04:00
|
|
|
}
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
defp create_pipeline(%{user: user}) do
|
|
|
|
[pipeline: pipeline_fixture(user)]
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "Index" do
|
2022-11-24 14:31:16 -05:00
|
|
|
setup [:register_and_log_in_user, :create_pipeline]
|
2022-07-25 20:12:11 -04:00
|
|
|
|
|
|
|
test "lists all pipelines", %{conn: conn, pipeline: pipeline} do
|
|
|
|
{:ok, _index_live, html} = live(conn, Routes.pipeline_index_path(conn, :index))
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
assert html =~ "pipelines"
|
2022-07-25 20:12:11 -04:00
|
|
|
assert html =~ pipeline.description
|
|
|
|
end
|
|
|
|
|
|
|
|
test "saves new pipeline", %{conn: conn} do
|
|
|
|
{:ok, index_live, _html} = live(conn, Routes.pipeline_index_path(conn, :index))
|
|
|
|
|
2022-11-17 22:30:01 -05:00
|
|
|
assert index_live |> element("a", "new pipeline") |> render_click() =~
|
|
|
|
"new pipeline"
|
2022-07-25 20:12:11 -04:00
|
|
|
|
|
|
|
assert_patch(index_live, Routes.pipeline_index_path(conn, :new))
|
|
|
|
|
|
|
|
assert index_live
|
|
|
|
|> form("#pipeline-form", pipeline: @invalid_attrs)
|
|
|
|
|> render_change() =~ "can't be blank"
|
|
|
|
|
|
|
|
{:ok, _, html} =
|
|
|
|
index_live
|
|
|
|
|> form("#pipeline-form", pipeline: @create_attrs)
|
|
|
|
|> render_submit()
|
|
|
|
|> follow_redirect(conn, Routes.pipeline_index_path(conn, :index))
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
assert html =~ "#{@create_attrs |> Map.get("title")} created"
|
2022-07-25 20:12:11 -04:00
|
|
|
assert html =~ "some description"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "updates pipeline in listing", %{conn: conn, pipeline: pipeline} do
|
|
|
|
{:ok, index_live, _html} = live(conn, Routes.pipeline_index_path(conn, :index))
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
assert index_live |> element("[data-qa=\"pipeline-edit-#{pipeline.id}\"]") |> render_click() =~
|
|
|
|
"edit"
|
2022-07-25 20:12:11 -04:00
|
|
|
|
|
|
|
assert_patch(index_live, Routes.pipeline_index_path(conn, :edit, pipeline))
|
|
|
|
|
|
|
|
assert index_live
|
|
|
|
|> form("#pipeline-form", pipeline: @invalid_attrs)
|
|
|
|
|> render_change() =~ "can't be blank"
|
|
|
|
|
|
|
|
{:ok, _, html} =
|
|
|
|
index_live
|
|
|
|
|> form("#pipeline-form", pipeline: @update_attrs)
|
|
|
|
|> render_submit()
|
|
|
|
|> follow_redirect(conn, Routes.pipeline_index_path(conn, :index))
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
assert html =~ "#{@update_attrs |> Map.get("title")} saved"
|
2022-07-25 20:12:11 -04:00
|
|
|
assert html =~ "some updated description"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "deletes pipeline in listing", %{conn: conn, pipeline: pipeline} do
|
|
|
|
{:ok, index_live, _html} = live(conn, Routes.pipeline_index_path(conn, :index))
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
assert index_live
|
|
|
|
|> element("[data-qa=\"delete-pipeline-#{pipeline.id}\"]")
|
|
|
|
|> render_click()
|
|
|
|
|
2022-07-25 20:12:11 -04:00
|
|
|
refute has_element?(index_live, "#pipeline-#{pipeline.id}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-17 22:30:01 -05:00
|
|
|
describe "show" do
|
2022-11-24 14:31:16 -05:00
|
|
|
setup [:register_and_log_in_user, :create_pipeline]
|
2022-07-25 20:12:11 -04:00
|
|
|
|
|
|
|
test "displays pipeline", %{conn: conn, pipeline: pipeline} do
|
|
|
|
{:ok, _show_live, html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline))
|
|
|
|
|
2022-11-17 22:30:01 -05:00
|
|
|
assert html =~ "show pipeline"
|
2022-07-25 20:12:11 -04:00
|
|
|
assert html =~ pipeline.description
|
|
|
|
end
|
|
|
|
|
|
|
|
test "updates pipeline within modal", %{conn: conn, pipeline: pipeline} do
|
|
|
|
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline))
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
assert show_live |> element("a", "edit") |> render_click() =~ "edit"
|
2022-07-25 20:12:11 -04:00
|
|
|
|
|
|
|
assert_patch(show_live, Routes.pipeline_show_path(conn, :edit, pipeline))
|
|
|
|
|
|
|
|
assert show_live
|
|
|
|
|> form("#pipeline-form", pipeline: @invalid_attrs)
|
|
|
|
|> render_change() =~ "can't be blank"
|
|
|
|
|
|
|
|
{:ok, _, html} =
|
|
|
|
show_live
|
|
|
|
|> form("#pipeline-form", pipeline: @update_attrs)
|
|
|
|
|> render_submit()
|
|
|
|
|> follow_redirect(conn, Routes.pipeline_show_path(conn, :show, pipeline))
|
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
assert html =~ "#{@update_attrs |> Map.get("title")} saved"
|
2022-07-25 20:12:11 -04:00
|
|
|
assert html =~ "some updated description"
|
|
|
|
end
|
2022-11-24 14:31:16 -05:00
|
|
|
|
|
|
|
test "deletes pipeline", %{conn: conn, pipeline: pipeline} do
|
|
|
|
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline))
|
|
|
|
|
|
|
|
{:ok, index_live, _html} =
|
|
|
|
show_live
|
|
|
|
|> element("[data-qa=\"delete-pipeline-#{pipeline.id}\"]")
|
|
|
|
|> render_click()
|
|
|
|
|> follow_redirect(conn, Routes.pipeline_index_path(conn, :index))
|
|
|
|
|
|
|
|
refute has_element?(index_live, "#pipeline-#{pipeline.id}")
|
|
|
|
end
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
|
|
|
end
|