Skip to content

Commit

Permalink
fixup: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicbites committed Sep 5, 2024
1 parent 1100910 commit 29fa4fe
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions test/radiator/outline_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,27 @@ defmodule Radiator.OutlineTest do
assert node_5.prev_id == node_3.uuid
end

# before 1 2 3 4 5
# after 1 2 4 3 5
test "move node 4 within list to node 2, but ommitting the parent_id", %{
node_2: node_2,
node_3: node_3,
node_4: node_4,
node_5: node_5
} do
{:ok, _} = Outline.move_node(node_4.uuid, prev_id: node_2.uuid)

# reload nodes
node_5 = Repo.reload!(node_5)
node_4 = Repo.reload!(node_4)
node_3 = Repo.reload!(node_3)
node_2 = Repo.reload!(node_2)

assert node_4.prev_id == node_2.uuid
assert node_3.prev_id == node_4.uuid
assert node_5.prev_id == node_3.uuid
end

# before 1 2 3 4 5
# after 4 1 2 3 5
test "move node 4 to the top of the list", %{
Expand Down Expand Up @@ -503,6 +524,30 @@ defmodule Radiator.OutlineTest do
assert node_2.prev_id == node_5.uuid
end

# before 1 2 3 4 5
# after 1 3 4 5 2
test "move node 2 to the end of the list but ommitting the parent_id", %{
node_1: node_1,
node_2: node_2,
node_3: node_3,
node_4: node_4,
node_5: node_5
} do
{:ok, _} = Outline.move_node(node_2.uuid, prev_id: node_5.uuid)

# reload nodes
node_5 = Repo.reload!(node_5)
node_4 = Repo.reload!(node_4)
node_3 = Repo.reload!(node_3)
node_2 = Repo.reload!(node_2)
node_1 = Repo.reload!(node_1)

assert node_3.prev_id == node_1.uuid
assert node_4.prev_id == node_3.uuid
assert node_5.prev_id == node_4.uuid
assert node_2.prev_id == node_5.uuid
end

# before 1 2 3 4 5
# after 2 3 4 5 1
test "move first node to the end of the list", %{
Expand All @@ -527,6 +572,30 @@ defmodule Radiator.OutlineTest do
assert node_2.prev_id == nil
end

# before 1 2 3 4 5
# after 2 3 4 5 1
test "move first node to the end of the list and ommitting the parent_id", %{
node_1: node_1,
node_2: node_2,
node_3: node_3,
node_4: node_4,
node_5: node_5
} do
{:ok, _} = Outline.move_node(node_1.uuid, prev_id: node_5.uuid)

# reload nodes
node_5 = Repo.reload!(node_5)
node_4 = Repo.reload!(node_4)
node_3 = Repo.reload!(node_3)
node_2 = Repo.reload!(node_2)
node_1 = Repo.reload!(node_1)

assert node_1.prev_id == node_5.uuid
assert node_5.prev_id == node_4.uuid
assert node_3.prev_id == node_2.uuid
assert node_2.prev_id == nil
end

# before 1 2 3 4 5
# after 5 1 2 3 4
test "move last node to the top of the list", %{
Expand Down Expand Up @@ -593,6 +662,29 @@ defmodule Radiator.OutlineTest do
assert nested_node_2.prev_id == nested_node_1.uuid
end

test "move node with child elements to top also works without parent_id", %{
parent_node: parent_node,
node_3: node_3,
nested_node_1: nested_node_1,
nested_node_2: nested_node_2
} do
{:ok, _} = Outline.move_node(node_3.uuid, prev_id: nil)

# reload nodes
parent_node = Repo.reload!(parent_node)
node_3 = Repo.reload!(node_3)
nested_node_1 = Repo.reload!(nested_node_1)
nested_node_2 = Repo.reload!(nested_node_2)

assert node_3.prev_id == nil
assert node_3.parent_id == nil
assert parent_node.prev_id == node_3.uuid
assert nested_node_1.parent_id == node_3.uuid
assert nested_node_2.parent_id == node_3.uuid
assert nested_node_1.prev_id == nil
assert nested_node_2.prev_id == nested_node_1.uuid
end

# before 1 2 3 4 5
# after 2 3 4 5 1
test "move first node to the end of the list returns all needed infos", %{
Expand Down

0 comments on commit 29fa4fe

Please sign in to comment.