memEx/test/memex_web/live/pipeline_live_test.exs

275 lines
8.9 KiB
Elixir
Raw Normal View History

2022-07-25 20:12:11 -04:00
defmodule MemexWeb.PipelineLiveTest do
use MemexWeb.ConnCase
import Phoenix.LiveViewTest
2022-11-26 21:26:21 -05:00
import Memex.{PipelinesFixtures, StepsFixtures}
2022-07-25 20:12:11 -04:00
2022-11-24 14:31:16 -05:00
@create_attrs %{
"description" => "some description",
"tags_string" => "tag1",
2022-11-26 14:51:18 -05:00
"slug" => "some-slug",
2022-11-24 14:31:16 -05:00
"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",
2022-11-26 14:51:18 -05:00
"slug" => "some-updated-slug",
2022-11-24 14:31:16 -05:00
"visibility" => :private
}
@invalid_attrs %{
"description" => nil,
2022-12-19 22:29:26 -05:00
"tags_string" => " ",
2022-11-26 14:51:18 -05:00
"slug" => nil,
2022-11-24 14:31:16 -05:00
"visibility" => nil
2022-07-25 22:05:54 -04:00
}
2022-11-26 21:26:21 -05:00
@step_create_attrs %{
"content" => "some content",
"title" => "some title"
}
@step_update_attrs %{
"content" => "some updated content",
"title" => "some updated title"
}
@step_invalid_attrs %{
"content" => nil,
"title" => nil
}
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
2022-12-15 22:33:10 -05:00
test "searches by tag", %{conn: conn} do
{:ok, index_live, html} = live(conn, Routes.pipeline_index_path(conn, :index))
assert html =~ "example-tag"
assert index_live |> element("a", "example-tag") |> render_click()
assert_patch(index_live, Routes.pipeline_index_path(conn, :search, "example-tag"))
end
2022-07-25 20:12:11 -04:00
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-26 14:51:18 -05:00
assert html =~ "#{@create_attrs |> Map.get("slug")} 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
2022-11-26 14:51:18 -05:00
assert_patch(index_live, Routes.pipeline_index_path(conn, :edit, pipeline.slug))
2022-07-25 20:12:11 -04:00
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-26 14:51:18 -05:00
assert html =~ "#{@update_attrs |> Map.get("slug")} 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
2022-11-26 14:51:18 -05:00
{:ok, _show_live, html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
2022-07-25 20:12:11 -04:00
2022-11-24 17:44:01 -05:00
assert html =~ "pipeline"
2022-07-25 20:12:11 -04:00
assert html =~ pipeline.description
end
test "updates pipeline within modal", %{conn: conn, pipeline: pipeline} do
2022-11-26 14:51:18 -05:00
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
2022-07-25 20:12:11 -04:00
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
2022-11-26 14:51:18 -05:00
assert_patch(show_live, Routes.pipeline_show_path(conn, :edit, pipeline.slug))
2022-07-25 20:12:11 -04:00
2022-12-19 22:29:26 -05:00
html =
show_live
|> form("#pipeline-form", pipeline: @invalid_attrs)
|> render_change()
assert html =~ "can't be blank"
assert html =~ "tags must be comma-delimited"
2022-07-25 20:12:11 -04:00
{:ok, _, html} =
show_live
2022-11-26 14:51:18 -05:00
|> form("#pipeline-form", pipeline: Map.put(@update_attrs, "slug", pipeline.slug))
2022-07-25 20:12:11 -04:00
|> render_submit()
2022-11-26 14:51:18 -05:00
|> follow_redirect(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
2022-07-25 20:12:11 -04:00
2022-11-26 14:51:18 -05:00
assert html =~ "#{pipeline.slug} 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
2022-11-26 14:51:18 -05:00
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
2022-11-24 14:31:16 -05:00
{: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-11-26 21:26:21 -05:00
test "creates a step", %{conn: conn, pipeline: pipeline} do
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
show_live
|> element("[data-qa=\"add-step-#{pipeline.id}\"]")
|> render_click()
assert_patch(show_live, Routes.pipeline_show_path(conn, :add_step, pipeline.slug))
{:ok, _show_live, html} =
show_live
|> form("#step-form", step: @step_create_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
assert html =~ "some title created"
assert html =~ "some description"
end
end
describe "show with a step" do
setup [:register_and_log_in_user, :create_pipeline]
setup %{pipeline: pipeline, user: user} do
[
step: step_fixture(0, pipeline, user)
]
end
2022-12-15 22:33:10 -05:00
test "searches by tag", %{conn: conn, pipeline: pipeline} do
{:ok, show_live, html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
assert html =~ "example-tag"
assert show_live |> element("a", "example-tag") |> render_click()
assert_redirect(show_live, Routes.pipeline_index_path(conn, :search, "example-tag"))
end
2022-11-26 21:26:21 -05:00
test "updates a step", %{conn: conn, pipeline: pipeline, step: step} do
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
show_live
|> element("[data-qa=\"edit-step-#{step.id}\"]")
|> render_click()
assert_patch(show_live, Routes.pipeline_show_path(conn, :edit_step, pipeline.slug, step.id))
assert show_live
|> form("#step-form", step: @step_invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _show_live, html} =
show_live
|> form("#step-form", step: @step_update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
assert html =~ "some updated title saved"
assert html =~ "some updated content"
end
test "deletes a step", %{conn: conn, pipeline: pipeline, step: step} do
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
html =
show_live
|> element("[data-qa=\"delete-step-#{step.id}\"]")
|> render_click()
assert_patch(show_live, Routes.pipeline_show_path(conn, :show, pipeline.slug))
assert html =~ "some title deleted"
refute html =~ "some updated content"
end
end
describe "show with multiple steps" do
setup [:register_and_log_in_user, :create_pipeline]
setup %{pipeline: pipeline, user: user} do
[
first_step: step_fixture(%{title: "first step"}, 0, pipeline, user),
second_step: step_fixture(%{title: "second step"}, 1, pipeline, user),
third_step: step_fixture(%{title: "third step"}, 2, pipeline, user)
]
end
test "reorders a step",
%{conn: conn, pipeline: pipeline, first_step: first_step, second_step: second_step} do
{:ok, show_live, _html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline.slug))
html =
show_live
|> element("[data-qa=\"move-step-up-#{second_step.id}\"]")
|> render_click()
assert html =~ "1. second step"
assert html =~ "2. first step"
assert html =~ "3. third step"
refute has_element?(show_live, "[data-qa=\"move-step-up-#{second_step.id}\"]")
html =
show_live
|> element("[data-qa=\"move-step-down-#{first_step.id}\"]")
|> render_click()
assert html =~ "1. second step"
assert html =~ "2. third step"
assert html =~ "3. first step"
refute has_element?(show_live, "[data-qa=\"move-step-down-#{first_step.id}\"]")
end
2022-07-25 20:12:11 -04:00
end
end