Skip to content

Commit

Permalink
make sure moveAfter marks nodes as needing update
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed May 8, 2020
1 parent 7df0d9f commit 1ba343c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Database.elm
Expand Up @@ -308,6 +308,10 @@ appendSibling sibling target ((Database db) as database) =
db.nodes
|> Dict.update parent (Maybe.map (\node -> { node | children = insertAfter sibling target node.children }))
|> Dict.update target (Maybe.map (\node -> { node | parent = Just parent }))
, toPersist =
db.toPersist
|> Set.insert parent
|> Set.insert target
}


Expand Down
18 changes: 18 additions & 0 deletions tests/DatabaseTest.elm
Expand Up @@ -209,6 +209,24 @@ databaseTest =
|> get parent.id
|> Maybe.map .children
|> Expect.equal (Just [ second.id, first.id, third.id ])
, test "will mark both the moved node and parent as needing update" <|
\_ ->
let
( parent, ( first, ( second, database ) ) ) =
insert (Node.note (plainContent "parent")) emptyFixture
|> Tuple.mapSecond (insert (Node.note (plainContent "first")))
|> Tuple.mapSecond (Tuple.mapSecond (insert (Node.note (plainContent "second"))))
in
database
|> moveInto parent.id first.id
|> toPersist
|> Tuple.second
-----
|> moveAfter first.id second.id
|> toPersist
|> Tuple.first
|> List.map .id
|> Expect.equal [ second.id, parent.id ]
]
, describe "finding a sibling"
[ test "won't work for the only note in the database" <|
Expand Down

0 comments on commit 1ba343c

Please sign in to comment.