add steps
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
defmodule Memex.StepsTest do
|
||||
use Memex.DataCase
|
||||
import Memex.{PipelinesFixtures, StepsFixtures}
|
||||
alias Memex.Pipelines.{Step, Steps}
|
||||
alias Memex.Pipelines.{Steps, Steps.Step}
|
||||
@moduletag :steps_test
|
||||
@invalid_attrs %{content: nil, title: nil}
|
||||
|
||||
@ -13,19 +13,19 @@ defmodule Memex.StepsTest do
|
||||
[user: user, pipeline: pipeline]
|
||||
end
|
||||
|
||||
test "list_steps/1 returns all steps for a user", %{pipeline: pipeline, user: user} do
|
||||
test "list_steps/2 returns all steps for a user", %{pipeline: pipeline, user: user} do
|
||||
step_a = step_fixture(0, pipeline, user)
|
||||
step_b = step_fixture(1, pipeline, user)
|
||||
step_c = step_fixture(2, pipeline, user)
|
||||
assert Steps.list_steps(pipeline, user) == [step_a, step_b, step_c]
|
||||
end
|
||||
|
||||
test "get_step!/1 returns the step with given id", %{pipeline: pipeline, user: user} do
|
||||
test "get_step!/2 returns the step with given id", %{pipeline: pipeline, user: user} do
|
||||
step = step_fixture(0, pipeline, user)
|
||||
assert Steps.get_step!(step.id, user) == step
|
||||
end
|
||||
|
||||
test "get_step!/1 only returns unlisted or public steps for other users", %{user: user} do
|
||||
test "get_step!/2 only returns unlisted or public steps for other users", %{user: user} do
|
||||
another_user = user_fixture()
|
||||
another_pipeline = pipeline_fixture(another_user)
|
||||
step = step_fixture(0, another_pipeline, another_user)
|
||||
@ -35,7 +35,7 @@ defmodule Memex.StepsTest do
|
||||
end
|
||||
end
|
||||
|
||||
test "create_step/1 with valid data creates a step", %{pipeline: pipeline, user: user} do
|
||||
test "create_step/4 with valid data creates a step", %{pipeline: pipeline, user: user} do
|
||||
valid_attrs = %{
|
||||
"content" => "some content",
|
||||
"title" => "some title"
|
||||
@ -46,12 +46,12 @@ defmodule Memex.StepsTest do
|
||||
assert step.title == "some title"
|
||||
end
|
||||
|
||||
test "create_step/1 with invalid data returns error changeset",
|
||||
test "create_step/4 with invalid data returns error changeset",
|
||||
%{pipeline: pipeline, user: user} do
|
||||
assert {:error, %Ecto.Changeset{}} = Steps.create_step(@invalid_attrs, 0, pipeline, user)
|
||||
end
|
||||
|
||||
test "update_step/2 with valid data updates the step", %{pipeline: pipeline, user: user} do
|
||||
test "update_step/3 with valid data updates the step", %{pipeline: pipeline, user: user} do
|
||||
step = step_fixture(0, pipeline, user)
|
||||
|
||||
update_attrs = %{
|
||||
@ -59,36 +59,90 @@ defmodule Memex.StepsTest do
|
||||
"title" => "some updated title"
|
||||
}
|
||||
|
||||
assert {:ok, %Step{} = step} = Steps.update_step(step, update_attrs, 0, user)
|
||||
assert {:ok, %Step{} = step} = Steps.update_step(step, update_attrs, user)
|
||||
assert step.content == "some updated content"
|
||||
assert step.title == "some updated title"
|
||||
end
|
||||
|
||||
test "update_step/2 with invalid data returns error changeset", %{
|
||||
test "update_step/3 with invalid data returns error changeset", %{
|
||||
pipeline: pipeline,
|
||||
user: user
|
||||
} do
|
||||
step = step_fixture(0, pipeline, user)
|
||||
assert {:error, %Ecto.Changeset{}} = Steps.update_step(step, @invalid_attrs, 0, user)
|
||||
assert {:error, %Ecto.Changeset{}} = Steps.update_step(step, @invalid_attrs, user)
|
||||
assert step == Steps.get_step!(step.id, user)
|
||||
end
|
||||
|
||||
test "delete_step/1 deletes the step", %{pipeline: pipeline, user: user} do
|
||||
test "delete_step/2 deletes the step", %{pipeline: pipeline, user: user} do
|
||||
step = step_fixture(0, pipeline, user)
|
||||
assert {:ok, %Step{}} = Steps.delete_step(step, user)
|
||||
assert_raise Ecto.NoResultsError, fn -> Steps.get_step!(step.id, user) end
|
||||
end
|
||||
|
||||
test "delete_step/1 deletes the step for an admin user", %{pipeline: pipeline, user: user} do
|
||||
test "delete_step/2 moves past steps up", %{pipeline: pipeline, user: user} do
|
||||
first_step = step_fixture(0, pipeline, user)
|
||||
second_step = step_fixture(1, pipeline, user)
|
||||
assert {:ok, %Step{}} = Steps.delete_step(first_step, user)
|
||||
assert %{position: 0} = second_step |> Repo.reload!()
|
||||
end
|
||||
|
||||
test "delete_step/2 deletes the step for an admin user", %{pipeline: pipeline, user: user} do
|
||||
admin_user = admin_fixture()
|
||||
step = step_fixture(0, pipeline, user)
|
||||
assert {:ok, %Step{}} = Steps.delete_step(step, admin_user)
|
||||
assert_raise Ecto.NoResultsError, fn -> Steps.get_step!(step.id, user) end
|
||||
end
|
||||
|
||||
test "change_step/2 returns a step changeset", %{pipeline: pipeline, user: user} do
|
||||
step = step_fixture(0, pipeline, user)
|
||||
assert %Ecto.Changeset{} = Steps.change_step(step, user)
|
||||
end
|
||||
|
||||
test "change_step/1 returns a step changeset", %{pipeline: pipeline, user: user} do
|
||||
step = step_fixture(0, pipeline, user)
|
||||
assert %Ecto.Changeset{} = Steps.change_step(step, 0, user)
|
||||
assert %Ecto.Changeset{} = Steps.change_step(step, user)
|
||||
end
|
||||
|
||||
test "reorder_step/1 reorders steps properly", %{pipeline: pipeline, user: user} do
|
||||
[
|
||||
%{id: first_step_id} = first_step,
|
||||
%{id: second_step_id} = second_step,
|
||||
%{id: third_step_id} = third_step
|
||||
] = Enum.map(0..2, fn index -> step_fixture(index, pipeline, user) end)
|
||||
|
||||
Steps.reorder_step(third_step, :up, user)
|
||||
|
||||
assert [
|
||||
%{id: ^first_step_id, position: 0},
|
||||
%{id: ^third_step_id, position: 1},
|
||||
%{id: ^second_step_id, position: 2}
|
||||
] = Steps.list_steps(pipeline, user)
|
||||
|
||||
Steps.reorder_step(first_step, :up, user)
|
||||
|
||||
assert [
|
||||
%{id: ^first_step_id, position: 0},
|
||||
%{id: ^third_step_id, position: 1},
|
||||
%{id: ^second_step_id, position: 2}
|
||||
] = Steps.list_steps(pipeline, user)
|
||||
|
||||
second_step
|
||||
|> Repo.reload!()
|
||||
|> Steps.reorder_step(:down, user)
|
||||
|
||||
assert [
|
||||
%{id: ^first_step_id, position: 0},
|
||||
%{id: ^third_step_id, position: 1},
|
||||
%{id: ^second_step_id, position: 2}
|
||||
] = Steps.list_steps(pipeline, user)
|
||||
|
||||
Steps.reorder_step(first_step, :down, user)
|
||||
|
||||
assert [
|
||||
%{id: ^third_step_id, position: 0},
|
||||
%{id: ^first_step_id, position: 1},
|
||||
%{id: ^second_step_id, position: 2}
|
||||
] = Steps.list_steps(pipeline, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,7 @@
|
||||
defmodule MemexWeb.PipelineLiveTest do
|
||||
use MemexWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import Memex.PipelinesFixtures
|
||||
import Memex.{PipelinesFixtures, StepsFixtures}
|
||||
|
||||
@create_attrs %{
|
||||
"description" => "some description",
|
||||
@ -22,6 +21,18 @@ defmodule MemexWeb.PipelineLiveTest do
|
||||
"slug" => nil,
|
||||
"visibility" => nil
|
||||
}
|
||||
@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
|
||||
}
|
||||
|
||||
defp create_pipeline(%{user: user}) do
|
||||
[pipeline: pipeline_fixture(user)]
|
||||
@ -134,5 +145,110 @@ defmodule MemexWeb.PipelineLiveTest do
|
||||
|
||||
refute has_element?(index_live, "#pipeline-#{pipeline.id}")
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user