Skip to content

Commit

Permalink
Suppress "Entry added" message if using default journal (jrnl-org#1561)
Browse files Browse the repository at this point in the history
* Suppress "Entry added to default journal" message if using default journal
* Replace "Entry added" BDD test steps with "we should get no error" now that the message is suppressed
* Add positive and negative tests for "Entry added" message behavior
micahellison authored Aug 27, 2022
1 parent bb6491b commit f65f07d
Showing 7 changed files with 57 additions and 35 deletions.
14 changes: 8 additions & 6 deletions jrnl/jrnl.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
from jrnl import install
from jrnl import plugins
from jrnl import time
from jrnl.config import DEFAULT_JOURNAL_KEY
from jrnl.config import get_config_path
from jrnl.config import get_journal_name
from jrnl.config import scope_config
@@ -146,13 +147,14 @@ def write_mode(args, config, journal, **kwargs):
'Write mode: appending raw text to journal "%s": %s', args.journal_name, raw
)
journal.new_entry(raw)
print_msg(
Message(
MsgText.JournalEntryAdded,
MsgStyle.NORMAL,
{"journal_name": args.journal_name},
if args.journal_name != DEFAULT_JOURNAL_KEY:
print_msg(
Message(
MsgText.JournalEntryAdded,
MsgStyle.NORMAL,
{"journal_name": args.journal_name},
)
)
)
journal.write()
logging.debug("Write mode: completed journal.write()")

16 changes: 8 additions & 8 deletions tests/bdd/features/datetime.feature
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ Feature: Reading and writing to journal with custom date formats
# https://github.com/jrnl-org/jrnl/issues/117
Given we use the config "simple.yaml"
When we run "jrnl 2013-11-30 15:42: Project Started."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -999"
Then the output should contain "2013-11-30 15:42 Project Started."

@@ -16,7 +16,7 @@ Feature: Reading and writing to journal with custom date formats
# https://github.com/jrnl-org/jrnl/issues/185
Given we use the config "simple.yaml"
When we run "jrnl 26/06/2099: Planet? Earth. Year? 2099."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -999"
Then the output should contain "2099-06-26 09:00 Planet?"

@@ -37,7 +37,7 @@ Feature: Reading and writing to journal with custom date formats
Scenario Outline: Writing an entry from command line with custom date
Given we use the config "<config_file>"
When we run "jrnl <command>"
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -n 1"
Then the output should contain "<expected_output>"
@@ -91,7 +91,7 @@ Feature: Reading and writing to journal with custom date formats
Given we use the config "simple.yaml"
And now is "2019-03-12 01:30:32 PM"
When we run "jrnl <command>"
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -1"
Then the output should contain "<expected_output>"
Then the output should contain the date "<date>"
@@ -113,7 +113,7 @@ Feature: Reading and writing to journal with custom date formats
Given we use the config "simple.yaml"
And now is "2019-03-12 01:30:32 PM"
When we run "jrnl <command>"
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -1"
Then the output should contain "<expected_output>"
Then the output should contain the date "<date>"
@@ -183,11 +183,11 @@ Feature: Reading and writing to journal with custom date formats
Given we use the config "dayone.yaml"
And now is "<date>"
When we run "jrnl yesterday: This thing happened yesterday"
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl today at 11:59pm: Adding an entry right now."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl tomorrow: A future entry."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -from yesterday -to today"
Then the output should contain "This thing happened yesterday"
And the output should contain "Adding an entry right now."
4 changes: 2 additions & 2 deletions tests/bdd/features/file_storage.feature
Original file line number Diff line number Diff line change
@@ -6,15 +6,15 @@ Feature: Journals iteracting with the file system in a way that users can see
Scenario: Adding entries to a Folder journal should generate date files
Given we use the config "empty_folder.yaml"
When we run "jrnl 23 July 2013: Testing folder journal."
Then the output should contain "Entry added"
Then we should get no error
And the journal directory should contain
2013/07/23.txt

Scenario: Adding multiple entries to a Folder journal should generate multiple date files
Given we use the config "empty_folder.yaml"
When we run "jrnl 23 July 2013: Testing folder journal."
And we run "jrnl 3/7/2014: Second entry of journal."
Then the output should contain "Entry added"
Then we should get no error
And the journal directory should contain
2013/07/23.txt

1 change: 0 additions & 1 deletion tests/bdd/features/override.feature
Original file line number Diff line number Diff line change
@@ -72,7 +72,6 @@ Feature: Implementing Runtime Overrides for Select Configuration Keys
And we use the password "test" if prompted
When we run "jrnl --config-override journals.default features/journals/simple.journal 20 Mar 2000: The rain in Spain comes from clouds"
Then we should get no error
And the output should contain "Entry added"
When we run "jrnl -3 --config-override journals.default features/journals/simple.journal"
Then the output should be
2000-03-20 09:00 The rain in Spain comes from clouds
18 changes: 9 additions & 9 deletions tests/bdd/features/search.feature
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ Feature: Searching in a journal
Scenario Outline: Displaying entries using -on today should display entries created today
Given we use the config "<config_file>"
When we run "jrnl today: Adding an entry right now."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -on today"
Then the output should contain "Adding an entry right now."
But the output should not contain "Everything is alright"
@@ -21,11 +21,11 @@ Feature: Searching in a journal
Scenario Outline: Displaying entries using -from day should display correct entries
Given we use the config "<config_file>"
When we run "jrnl yesterday: This thing happened yesterday"
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl today at 11:59pm: Adding an entry right now."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl tomorrow: A future entry."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -from today"
Then the output should contain "2 entries found"
And the output should contain "Adding an entry right now."
@@ -42,11 +42,11 @@ Feature: Searching in a journal
Given we use the config "<config_file>"
And now is "2022-03-10 02:32:00 PM"
When we run "jrnl yesterday: This thing happened yesterday"
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl today at 11:59pm: Adding an entry right now."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl tomorrow: A future entry."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -from yesterday -to today"
Then the output should contain "2 entries found"
And the output should contain "This thing happened yesterday"
@@ -140,9 +140,9 @@ Feature: Searching in a journal
Scenario: Out of order entries to a Folder journal should be listed in date order
Given we use the config "empty_folder.yaml"
When we run "jrnl 3/7/2014 4:37pm: Second entry of journal."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl 23 July 2013: Testing folder journal."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -2"
Then the output should be
2013-07-23 09:00 Testing folder journal.
4 changes: 2 additions & 2 deletions tests/bdd/features/star.feature
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ Feature: Starring entries
Scenario Outline: Starring an entry will mark it in the journal file
Given we use the config "<config_file>"
When we run "jrnl 20 july 2013 *: Best day of my life!"
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -on 2013-07-20 -starred"
Then the output should contain "2013-07-20 09:00 Best day of my life!"

@@ -34,6 +34,6 @@ Feature: Starring entries
Given we use the config "encrypted.yaml"
And we use the password "bad doggie no biscuit" if prompted
When we run "jrnl 20 july 2013 *: Best day of my life!"
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -on 2013-07-20 -starred" and enter "bad doggie no biscuit"
Then the output should contain "2013-07-20 09:00 Best day of my life!"
35 changes: 28 additions & 7 deletions tests/bdd/features/write.feature
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ Feature: Writing new entries.
Given we use the config "<config_file>"
And we use the password "bad doggie no biscuit" if prompted
When we run "jrnl 23 july 2013: A cold and stormy day. I ate crisps on the sofa."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -n 1"
Then the output should contain "2013-07-23 09:00 A cold and stormy day."

@@ -64,7 +64,7 @@ Feature: Writing new entries.
Given we use the config "<config_file>"
And we use the password "test" if prompted
When we run "jrnl this is a partial --edit"
Then the output should contain "Entry added"
Then we should get no error
Then the editor should have been called
And the editor file content should be
this is a partial
@@ -128,7 +128,7 @@ Feature: Writing new entries.
Given we use the config "<config_file>"
And we use the password "bad doggie no biscuit" if prompted
When we run "jrnl 23 july 2013: A cold and stormy day. I ate crisps on the sofa."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -n 1"
Then the output should not contain "Life is good"

@@ -143,7 +143,7 @@ Feature: Writing new entries.
Given we use the config "<config_file>"
And we use the password "bad doggie no biscuit" if prompted
When we run "jrnl 04-24-2014: Created a new website - empty.com. Hope to get a lot of traffic."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -1"
Then the output should be
2014-04-24 09:00 Created a new website - empty.com.
@@ -160,7 +160,7 @@ Feature: Writing new entries.
Given we use the config "<config_file>"
And we use the password "bad doggie no biscuit" if prompted
When we run "jrnl 23 july 2013: 🌞 sunny day. Saw an 🐘"
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -n 1"
Then the output should contain "🌞"
And the output should contain "🐘"
@@ -217,7 +217,7 @@ Feature: Writing new entries.
Scenario: Title with an embedded period on DayOne journal
Given we use the config "dayone.yaml"
When we run "jrnl 04-24-2014: Ran 6.2 miles today in 1:02:03. I am feeling sore because I forgot to stretch."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -1"
Then the output should be
2014-04-24 09:00 Ran 6.2 miles today in 1:02:03.
@@ -226,7 +226,7 @@ Feature: Writing new entries.
Scenario: Opening an folder that's not a DayOne folder should treat as folder journal
Given we use the config "empty_folder.yaml"
When we run "jrnl 23 july 2013: Testing folder journal."
Then the output should contain "Entry added"
Then we should get no error
When we run "jrnl -1"
Then the output should be "2013-07-23 09:00 Testing folder journal."
@@ -313,3 +313,24 @@ Feature: Writing new entries.
| basic_encrypted.yaml |
| basic_folder.yaml |
| basic_dayone.yaml |

Scenario Outline: No "Entry added" message should appear when writing to the default journal
Given we use the config "<config_file>"
And we use the password "test" if prompted
When we run "jrnl This is a new entry"
Then the output should not contain "Entry added"
And we should get no error

Examples: configs
| config_file |
| basic_onefile.yaml |
| basic_encrypted.yaml |
| basic_folder.yaml |
| basic_dayone.yaml |

Scenario: An "Entry added" message should appear when writing to a non-default journal
Given we use the config "multiple.yaml"
And we use the password "test" if prompted
When we run "jrnl work This is a new entry"
Then the output should contain "Entry added to work journal"
And we should get no error

0 comments on commit f65f07d

Please sign in to comment.