2022-07-25 20:12:11 -04:00
|
|
|
defmodule MemexWeb.PipelineLiveTest do
|
|
|
|
use MemexWeb.ConnCase
|
|
|
|
import Phoenix.LiveViewTest
|
2023-03-22 22:08:37 -04:00
|
|
|
import Memex.Fixtures
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
@create_attrs %{
|
2023-03-22 22:08:37 -04:00
|
|
|
description: "some description",
|
|
|
|
tags_string: "tag1",
|
|
|
|
slug: "some-slug",
|
|
|
|
visibility: :public
|
2022-11-24 14:31:16 -05:00
|
|
|
}
|
2022-07-25 22:05:54 -04:00
|
|
|
@update_attrs %{
|
2023-03-22 22:08:37 -04:00
|
|
|
description: "some updated description",
|
|
|
|
tags_string: "tag1,tag2",
|
|
|
|
slug: "some-updated-slug",
|
|
|
|
visibility: :private
|
2022-11-24 14:31:16 -05:00
|
|
|
}
|
|
|
|
@invalid_attrs %{
|
2023-03-22 22:08:37 -04:00
|
|
|
description: nil,
|
2023-04-13 23:29:29 -04:00
|
|
|
tags_string: "invalid tags",
|
2023-03-22 22:08:37 -04:00
|
|
|
slug: nil,
|
|
|
|
visibility: nil
|
2022-07-25 22:05:54 -04:00
|
|
|
}
|
2022-11-26 21:26:21 -05:00
|
|
|
@step_create_attrs %{
|
2023-03-22 22:08:37 -04:00
|
|
|
content: "some content",
|
|
|
|
title: "some title"
|
2022-11-26 21:26:21 -05:00
|
|
|
}
|
|
|
|
@step_update_attrs %{
|
2023-03-22 22:08:37 -04:00
|
|
|
content: "some updated content",
|
|
|
|
title: "some updated title"
|
2022-11-26 21:26:21 -05:00
|
|
|
}
|
|
|
|
@step_invalid_attrs %{
|
2023-03-22 22:08:37 -04:00
|
|
|
content: nil,
|
|
|
|
title: nil
|
2022-11-26 21:26:21 -05:00
|
|
|
}
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2023-02-04 17:22:06 -05:00
|
|
|
defp create_pipeline(%{current_user: current_user}) do
|
|
|
|
[pipeline: pipeline_fixture(current_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
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, _index_live, html} = live(conn, ~p"/pipelines")
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
assert html =~ "pipelines"
|
2022-07-25 20:12:11 -04:00
|
|
|
assert html =~ pipeline.description
|
|
|
|
end
|
|
|
|
|
2023-03-22 22:08:37 -04:00
|
|
|
test "searches by tag", %{conn: conn, pipeline: %{tags: [tag]}} do
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, index_live, html} = live(conn, ~p"/pipelines")
|
2022-12-15 22:33:10 -05:00
|
|
|
|
2023-03-22 22:08:37 -04:00
|
|
|
assert html =~ tag
|
|
|
|
assert index_live |> element("a", tag) |> render_click()
|
2023-04-13 23:29:29 -04:00
|
|
|
assert_patch(index_live, ~p"/pipelines/#{tag}")
|
2022-12-15 22:33:10 -05:00
|
|
|
end
|
|
|
|
|
2022-07-25 20:12:11 -04:00
|
|
|
test "saves new pipeline", %{conn: conn} do
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, index_live, _html} = live(conn, ~p"/pipelines")
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2023-03-22 22:08:37 -04:00
|
|
|
assert index_live |> element("a", "new pipeline") |> render_click() =~ "new pipeline"
|
2023-04-13 23:29:29 -04:00
|
|
|
assert_patch(index_live, ~p"/pipelines/new")
|
2022-07-25 20:12:11 -04:00
|
|
|
|
|
|
|
assert index_live
|
2023-03-22 22:08:37 -04:00
|
|
|
|> form("#pipeline-form")
|
|
|
|
|> render_change(pipeline: @invalid_attrs) =~ "can't be blank"
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2023-02-04 17:36:27 -05:00
|
|
|
{:ok, _live, html} =
|
2022-07-25 20:12:11 -04:00
|
|
|
index_live
|
2023-03-22 22:08:37 -04:00
|
|
|
|> form("#pipeline-form")
|
|
|
|
|> render_submit(pipeline: @create_attrs)
|
2023-04-13 23:29:29 -04:00
|
|
|
|> follow_redirect(conn, ~p"/pipelines")
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2023-03-22 22:08:37 -04:00
|
|
|
assert html =~ "#{@create_attrs.slug} created"
|
|
|
|
assert html =~ @create_attrs.description
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "updates pipeline in listing", %{conn: conn, pipeline: pipeline} do
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, index_live, _html} = live(conn, ~p"/pipelines")
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2023-03-14 23:51:50 -04:00
|
|
|
assert index_live |> element(~s/a[aria-label="edit #{pipeline.slug}"]/) |> render_click() =~
|
2022-11-24 14:31:16 -05:00
|
|
|
"edit"
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2023-04-13 23:29:29 -04:00
|
|
|
assert_patch(index_live, ~p"/pipelines/#{pipeline}/edit")
|
2022-07-25 20:12:11 -04:00
|
|
|
|
|
|
|
assert index_live
|
2023-03-22 22:08:37 -04:00
|
|
|
|> form("#pipeline-form")
|
|
|
|
|> render_change(pipeline: @invalid_attrs) =~ "can't be blank"
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2023-02-04 17:36:27 -05:00
|
|
|
{:ok, _live, html} =
|
2022-07-25 20:12:11 -04:00
|
|
|
index_live
|
2023-03-22 22:08:37 -04:00
|
|
|
|> form("#pipeline-form")
|
|
|
|
|> render_submit(pipeline: @update_attrs)
|
2023-04-13 23:29:29 -04:00
|
|
|
|> follow_redirect(conn, ~p"/pipelines")
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2023-03-22 22:08:37 -04:00
|
|
|
assert html =~ "#{@update_attrs.slug} saved"
|
|
|
|
assert html =~ @update_attrs.description
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "deletes pipeline in listing", %{conn: conn, pipeline: pipeline} do
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, index_live, _html} = live(conn, ~p"/pipelines")
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2022-11-24 14:31:16 -05:00
|
|
|
assert index_live
|
2023-03-14 23:51:50 -04:00
|
|
|
|> element(~s/a[aria-label="delete #{pipeline.slug}"]/)
|
2022-11-24 14:31:16 -05:00
|
|
|
|> 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
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, _show_live, html} = live(conn, ~p"/pipeline/#{pipeline}")
|
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
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
|
2022-11-24 14:31:16 -05:00
|
|
|
assert show_live |> element("a", "edit") |> render_click() =~ "edit"
|
2023-04-13 23:29:29 -04:00
|
|
|
assert_patch(show_live, ~p"/pipeline/#{pipeline}/edit")
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2022-12-19 22:29:26 -05:00
|
|
|
html =
|
|
|
|
show_live
|
2023-03-22 22:08:37 -04:00
|
|
|
|> form("#pipeline-form")
|
|
|
|
|> render_change(pipeline: @invalid_attrs)
|
2022-12-19 22:29:26 -05:00
|
|
|
|
|
|
|
assert html =~ "can't be blank"
|
|
|
|
assert html =~ "tags must be comma-delimited"
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2023-02-04 17:36:27 -05:00
|
|
|
{:ok, _live, html} =
|
2022-07-25 20:12:11 -04:00
|
|
|
show_live
|
2023-03-22 22:08:37 -04:00
|
|
|
|> form("#pipeline-form")
|
|
|
|
|> render_submit(pipeline: @update_attrs |> Map.put(:slug, pipeline.slug))
|
2023-04-13 23:29:29 -04:00
|
|
|
|> follow_redirect(conn, ~p"/pipeline/#{pipeline}")
|
2022-07-25 20:12:11 -04:00
|
|
|
|
2022-11-26 14:51:18 -05:00
|
|
|
assert html =~ "#{pipeline.slug} saved"
|
2023-03-22 22:08:37 -04:00
|
|
|
assert html =~ @update_attrs.description
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
2022-11-24 14:31:16 -05:00
|
|
|
|
|
|
|
test "deletes pipeline", %{conn: conn, pipeline: pipeline} do
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
|
2022-11-24 14:31:16 -05:00
|
|
|
|
|
|
|
{:ok, index_live, _html} =
|
|
|
|
show_live
|
2023-03-14 23:51:50 -04:00
|
|
|
|> element(~s/button[aria-label="delete #{pipeline.slug}"]/)
|
2022-11-24 14:31:16 -05:00
|
|
|
|> render_click()
|
2023-04-13 23:29:29 -04:00
|
|
|
|> follow_redirect(conn, ~p"/pipelines")
|
2022-11-24 14:31:16 -05:00
|
|
|
|
|
|
|
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
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
|
2023-03-14 23:51:50 -04:00
|
|
|
show_live |> element("a", "add step") |> render_click()
|
2023-04-13 23:29:29 -04:00
|
|
|
assert_patch(show_live, ~p"/pipeline/#{pipeline}/add_step")
|
2022-11-26 21:26:21 -05:00
|
|
|
|
|
|
|
{:ok, _show_live, html} =
|
|
|
|
show_live
|
2023-03-22 22:08:37 -04:00
|
|
|
|> form("#step-form")
|
|
|
|
|> render_submit(step: @step_create_attrs)
|
2023-04-13 23:29:29 -04:00
|
|
|
|> follow_redirect(conn, ~p"/pipeline/#{pipeline}")
|
2022-11-26 21:26:21 -05:00
|
|
|
|
2023-03-22 22:08:37 -04:00
|
|
|
assert html =~ @step_create_attrs.title
|
|
|
|
assert html =~ @step_create_attrs.content
|
2022-11-26 21:26:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "show with a step" do
|
|
|
|
setup [:register_and_log_in_user, :create_pipeline]
|
|
|
|
|
2023-02-04 17:22:06 -05:00
|
|
|
setup %{pipeline: pipeline, current_user: current_user} do
|
2022-11-26 21:26:21 -05:00
|
|
|
[
|
2023-02-04 17:22:06 -05:00
|
|
|
step: step_fixture(0, pipeline, current_user)
|
2022-11-26 21:26:21 -05:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2023-03-22 22:08:37 -04:00
|
|
|
test "searches by tag", %{conn: conn, pipeline: %{tags: [tag]} = pipeline} do
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, show_live, html} = live(conn, ~p"/pipeline/#{pipeline}")
|
2022-12-15 22:33:10 -05:00
|
|
|
|
2023-03-22 22:08:37 -04:00
|
|
|
assert html =~ tag
|
|
|
|
assert show_live |> element("a", tag) |> render_click()
|
2023-04-13 23:29:29 -04:00
|
|
|
assert_redirect(show_live, ~p"/pipelines/#{tag}")
|
2022-12-15 22:33:10 -05:00
|
|
|
end
|
|
|
|
|
2022-11-26 21:26:21 -05:00
|
|
|
test "updates a step", %{conn: conn, pipeline: pipeline, step: step} do
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
|
2022-11-26 21:26:21 -05:00
|
|
|
|
|
|
|
show_live
|
2023-03-14 23:51:50 -04:00
|
|
|
|> element(~s/a[aria-label="edit #{step.title}"]/)
|
2022-11-26 21:26:21 -05:00
|
|
|
|> render_click()
|
|
|
|
|
2023-04-13 23:29:29 -04:00
|
|
|
assert_patch(show_live, ~p"/pipeline/#{pipeline}/#{step.id}")
|
2022-11-26 21:26:21 -05:00
|
|
|
|
|
|
|
assert show_live
|
2023-03-22 22:08:37 -04:00
|
|
|
|> form("#step-form")
|
|
|
|
|> render_change(step: @step_invalid_attrs) =~ "can't be blank"
|
2022-11-26 21:26:21 -05:00
|
|
|
|
|
|
|
{:ok, _show_live, html} =
|
|
|
|
show_live
|
2023-03-22 22:08:37 -04:00
|
|
|
|> form("#step-form")
|
|
|
|
|> render_submit(step: @step_update_attrs)
|
2023-04-13 23:29:29 -04:00
|
|
|
|> follow_redirect(conn, ~p"/pipeline/#{pipeline}")
|
2022-11-26 21:26:21 -05:00
|
|
|
|
2023-03-22 22:08:37 -04:00
|
|
|
assert html =~ @step_update_attrs.title
|
|
|
|
assert html =~ @step_update_attrs.content
|
2022-11-26 21:26:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "deletes a step", %{conn: conn, pipeline: pipeline, step: step} do
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
|
2022-11-26 21:26:21 -05:00
|
|
|
|
|
|
|
html =
|
|
|
|
show_live
|
2023-03-14 23:51:50 -04:00
|
|
|
|> element(~s/button[aria-label="delete #{step.title}"]/)
|
2022-11-26 21:26:21 -05:00
|
|
|
|> render_click()
|
|
|
|
|
2023-04-13 23:29:29 -04:00
|
|
|
assert_patch(show_live, ~p"/pipeline/#{pipeline}")
|
2022-11-26 21:26:21 -05:00
|
|
|
|
2023-03-22 22:08:37 -04:00
|
|
|
assert html =~ "#{step.title} deleted"
|
|
|
|
refute html =~ step.content
|
2022-11-26 21:26:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "show with multiple steps" do
|
|
|
|
setup [:register_and_log_in_user, :create_pipeline]
|
|
|
|
|
2023-02-04 17:22:06 -05:00
|
|
|
setup %{pipeline: pipeline, current_user: current_user} do
|
2022-11-26 21:26:21 -05:00
|
|
|
[
|
2023-02-04 17:22:06 -05:00
|
|
|
first_step: step_fixture(%{title: "first step"}, 0, pipeline, current_user),
|
|
|
|
second_step: step_fixture(%{title: "second step"}, 1, pipeline, current_user),
|
|
|
|
third_step: step_fixture(%{title: "third step"}, 2, pipeline, current_user)
|
2022-11-26 21:26:21 -05:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "reorders a step",
|
|
|
|
%{conn: conn, pipeline: pipeline, first_step: first_step, second_step: second_step} do
|
2023-04-13 23:29:29 -04:00
|
|
|
{:ok, show_live, _html} = live(conn, ~p"/pipeline/#{pipeline}")
|
2022-11-26 21:26:21 -05:00
|
|
|
|
|
|
|
html =
|
|
|
|
show_live
|
2023-03-14 23:51:50 -04:00
|
|
|
|> element(~s/button[aria-label="move #{second_step.title} up"]/)
|
2022-11-26 21:26:21 -05:00
|
|
|
|> render_click()
|
|
|
|
|
|
|
|
assert html =~ "1. second step"
|
|
|
|
assert html =~ "2. first step"
|
|
|
|
assert html =~ "3. third step"
|
|
|
|
|
2023-03-14 23:51:50 -04:00
|
|
|
refute has_element?(show_live, ~s/button[aria-label="move #{second_step.title} up"]/)
|
2022-11-26 21:26:21 -05:00
|
|
|
|
|
|
|
html =
|
|
|
|
show_live
|
2023-03-14 23:51:50 -04:00
|
|
|
|> element(~s/button[aria-label="move #{first_step.title} down"]/)
|
2022-11-26 21:26:21 -05:00
|
|
|
|> render_click()
|
|
|
|
|
|
|
|
assert html =~ "1. second step"
|
|
|
|
assert html =~ "2. third step"
|
|
|
|
assert html =~ "3. first step"
|
|
|
|
|
2023-03-14 23:51:50 -04:00
|
|
|
refute has_element?(show_live, ~s/button[aria-label="move #{first_step.title} down"]/)
|
2022-11-26 21:26:21 -05:00
|
|
|
end
|
2022-07-25 20:12:11 -04:00
|
|
|
end
|
|
|
|
end
|