diff --git a/tests/bdd/features/template.feature b/tests/bdd/features/template.feature index 799a6d3b..a6a69b9f 100644 --- a/tests/bdd/features/template.feature +++ b/tests/bdd/features/template.feature @@ -51,8 +51,7 @@ Feature: Using templates Given we use the config "" And we use the password "test" if prompted When we run "jrnl --template features/templates/basic.template" - And we run "jrnl -1" - Then the output should contain "This text is in the basic template" + Then the output should contain "No entry to save, because the template was not changed" Examples: configs | config_file | @@ -61,29 +60,13 @@ Feature: Using templates | basic_folder.yaml | | basic_dayone.yaml | - @todo - Scenario Outline: --template absolute_filepath should be used in new entry - Given we use the config "" - And we use the password "test" if prompted - When we run "jrnl --template /tmp/basic.template" - And we run "jrnl -1" - Then the output should contain "This text is in the basic template" - - Examples: configs - | config_file | - | basic_onefile.yaml | - | basic_encrypted.yaml | - | basic_folder.yaml | - | basic_dayone.yaml | - - - @todo Scenario Outline: --template file_in_XDG_templates_dir should be used in new entry Given we use the config "" And we use the password "test" if prompted + And we copy the template "basic.template" to the default templates folder When we run "jrnl --template basic.template" - And we run "jrnl -1" - Then the output should contain "This text is in the basic template" + Then the output should contain "No entry to save, because the template was not changed" + Examples: configs | config_file | diff --git a/tests/lib/fixtures.py b/tests/lib/fixtures.py index 22c11d54..b9cf0ea4 100644 --- a/tests/lib/fixtures.py +++ b/tests/lib/fixtures.py @@ -89,6 +89,7 @@ def cli_run( mock_user_input, mock_overrides, mock_default_journal_path, + mock_default_templates_path, ): # Check if we need more mocks mock_factories.update(mock_args) @@ -98,6 +99,7 @@ def cli_run( mock_factories.update(mock_config_path) mock_factories.update(mock_user_input) mock_factories.update(mock_default_journal_path) + mock_factories.update(mock_default_templates_path) return { "status": 0, @@ -179,6 +181,16 @@ def mock_default_journal_path(temp_dir): } +@fixture +def mock_default_templates_path(temp_dir): + templates_path = Path(temp_dir.name, "templates") + return { + "get_templates_path": lambda: patch( + "jrnl.controller.get_templates_path", return_value=templates_path + ), + } + + @fixture def temp_dir(): return tempfile.TemporaryDirectory() diff --git a/tests/lib/given_steps.py b/tests/lib/given_steps.py index c5fd62a1..b76f1662 100644 --- a/tests/lib/given_steps.py +++ b/tests/lib/given_steps.py @@ -125,6 +125,19 @@ def we_use_the_config(request, temp_dir, working_dir, config_file): return config_dest +@given(parse('we copy the template "{template_file}" to the default templates folder'), target_fixture="default_templates_path") +def we_copy_the_template(request, temp_dir, working_dir, template_file): + # Move into temp dir as cwd + os.chdir(temp_dir.name) # @todo move this step to a more universal place + + # Copy template over + template_source = os.path.join(working_dir, "data", "templates", template_file) + template_dest = os.path.join(temp_dir.name, "templates", template_file) + os.makedirs(os.path.dirname(template_dest), exist_ok=True) + shutil.copy2(template_source, template_dest) + return template_dest + + @given(parse('the config "{config_file}" exists'), target_fixture="config_path") def config_exists(config_file, temp_dir, working_dir): config_source = os.path.join(working_dir, "data", "configs", config_file)