Skip to content

Commit

Permalink
Add test covering --to-title renaming with duplicated, renamed todo.
Browse files Browse the repository at this point in the history
refs gh-292
  • Loading branch information
xwmx committed Nov 27, 2023
1 parent e2db0a2 commit 4a5086f
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/move-rename.bats
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,62 @@ Moved\ to:\ .*[.*Example\ Folder/1.*].*\ .*Example\ Folder/Example\ File\.js.*

# --to title / --to-title #####################################################

@test "'move --to title' with duplicated, renamed todo renames title." {
# NOTE: https://github.com/xwmx/nb/issues/292
{
"${_NB}" init

"${_NB}" todo add "Example One"

"${_NB}" rename 1 --to-title <<< "y${_NEWLINE}"

[[ -f "${NB_DIR}/home/example_one.todo.md" ]]
[[ ! -e "${NB_DIR}/home/example_one-1.todo.md" ]]
[[ ! -e "${NB_DIR}/home/example_two.todo.md" ]]

"${_NB}" duplicate 1

[[ -f "${NB_DIR}/home/example_one.todo.md" ]]
[[ -f "${NB_DIR}/home/example_one-1.todo.md" ]]
[[ ! -e "${NB_DIR}/home/example_two.todo.md" ]]

printf "# [ ] Example Two\\n" > "$("${_NB}" show 2 --path)"
}

run "${_NB}" rename 2 --to title <<< "y${_NEWLINE}"

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

# Returns status 0:

[[ ${status} -eq 0 ]]

# Moves file:

[[ -f "${NB_DIR}/home/example_one.todo.md" ]]
[[ ! -e "${NB_DIR}/home/example_one-1.todo.md" ]]
[[ -f "${NB_DIR}/home/example_two.todo.md" ]]

# Creates git commit:

cd "${NB_DIR}/home" || return 1
while [[ -n "$(git status --porcelain)" ]]
do
sleep 1
done
git log | grep -q '\[nb\] Move'

# Prints output:

[[ "${lines[0]}" =~ \
Moving:\ \ \ .*[.*2.*].*\ ✔️\ \ .*example_one-1.todo.md.*\ \".*[.*\ .*].*\ Example\ Two\" ]]
[[ "${lines[1]}" =~ \
To:\ \ \ \ \ \ \ .*example_two.todo.md.* ]]
[[ "${lines[2]}" =~ \
Moved\ to:\ .*[.*2.*].*\ .*example_two.todo.md.*\ \".*[.*\ .*].*\ Example\ Two\" ]]
}

@test "'move --to title' with title and root-level bookmark renames to title." {
{
"${_NB}" init
Expand Down

0 comments on commit 4a5086f

Please sign in to comment.