Add added option to _print_edited_summary (#1366)

* Add added option to _print_edited_summary

* Add tests for counts of entries added, modified, and deleted

* Add test for modifying an entry rather than replacing it

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
This commit is contained in:
Piero Lescano 2021-11-20 14:47:56 -05:00 committed by GitHub
parent ffc8bdd5f1
commit ba3fd2202f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 1 deletions

View file

@ -275,13 +275,18 @@ def _edit_search_results(config, journal, old_entries, **kwargs):
def _print_edited_summary(journal, old_stats, **kwargs): def _print_edited_summary(journal, old_stats, **kwargs):
stats = { stats = {
"added": len(journal) - old_stats["count"],
"deleted": old_stats["count"] - len(journal), "deleted": old_stats["count"] - len(journal),
"modified": len([e for e in journal.entries if e.modified]), "modified": len([e for e in journal.entries if e.modified]),
} }
prompts = [] prompts = []
if stats["deleted"]: if stats["added"] > 0:
prompts.append(f"{stats['added']} {_pluralize_entry(stats['added'])} added")
stats["modified"] -= stats["added"]
if stats["deleted"] > 0:
prompts.append( prompts.append(
f"{stats['deleted']} {_pluralize_entry(stats['deleted'])} deleted" f"{stats['deleted']} {_pluralize_entry(stats['deleted'])} deleted"
) )

View file

@ -211,3 +211,89 @@ Feature: Writing new entries.
Then we should see the message "Entry added" Then we should see the message "Entry added"
When we run "jrnl -1" When we run "jrnl -1"
Then the output should be "2013-07-23 09:00 Testing folder journal." Then the output should be "2013-07-23 09:00 Testing folder journal."
Scenario Outline: Correctly count when adding a single entry via --edit
Given we use the config "<config_file>"
And we use the password "test" if prompted
And we append to the editor if opened
[2021-11-13] worked on jrnl tests
When we run "jrnl --edit"
Then the output should contain
[1 entry added]
Examples: configs
| config_file |
| basic_onefile.yaml |
| basic_encrypted.yaml |
| basic_folder.yaml |
#| basic_dayone.yaml | @todo
Scenario Outline: Correctly count when adding multiple entries via --edit
Given we use the config "<config_file>"
And we use the password "test" if prompted
And we append to the editor if opened
[2021-11-11] worked on jrnl tests
[2021-11-12] worked on jrnl tests again
[2021-11-13] worked on jrnl tests a little bit more
When we run "jrnl --edit"
Then the output should contain
[3 entries added]
Examples: configs
| config_file |
| basic_onefile.yaml |
| basic_encrypted.yaml |
| basic_folder.yaml |
#| basic_dayone.yaml | @todo
Scenario Outline: Correctly count when removing entries via --edit
Given we use the config "<config_file>"
And we use the password "test" if prompted
And we write to the editor if opened
[2021-11-13] I am replacing my whole journal with this entry
When we run "jrnl --edit"
Then the output should contain
[2 entries deleted, 1 entry modified]
Examples: configs
| config_file |
| basic_onefile.yaml |
| basic_encrypted.yaml |
| basic_folder.yaml |
#| basic_dayone.yaml | @todo
Scenario Outline: Correctly count modification when running --edit to replace a single entry
Given we use the config "<config_file>"
And we use the password "test" if prompted
And we write to the editor if opened
[2021-11-13] I am replacing the last entry with this entry
When we run "jrnl --edit -1"
Then the output should contain
[1 entry modified]
Examples: configs
| config_file |
| basic_onefile.yaml |
| basic_encrypted.yaml |
| basic_folder.yaml |
#| basic_dayone.yaml | @todo
Scenario Outline: Correctly count modification when running --edit on whole journal and adding to last entry
Given we use the config "<config_file>"
And we use the password "test" if prompted
And we append to the editor if opened
This is a small addendum to my latest entry.
When we run "jrnl --edit"
Then the output should contain
[1 entry modified]
Examples: configs
| config_file |
| basic_onefile.yaml |
| basic_encrypted.yaml |
| basic_folder.yaml |
#| basic_dayone.yaml | @todo