Skip to content

Commit 2f233d8

Browse files
author
name
committed
test(test_cz_search_filter.py): add test cases for search filter configuration
1 parent 3226654 commit 2f233d8

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

tests/test_cz_search_filter.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import pytest
2+
from unittest.mock import patch
3+
from commitizen.config import TomlConfig
4+
from commitizen.cz.customize import CustomizeCommitsCz
5+
import questionary
6+
7+
TOML_WITH_SEARCH_FILTER = r"""
8+
[tool.commitizen]
9+
name = "cz_customize"
10+
11+
[tool.commitizen.customize]
12+
message_template = "{{change_type}}:{% if scope %} ({{scope}}){% endif %}{% if breaking %}!{% endif %} {{message}}"
13+
14+
[[tool.commitizen.customize.questions]]
15+
type = "select"
16+
name = "change_type"
17+
message = "Select the type of change you are committing"
18+
use_search_filter = true
19+
use_jk_keys = false
20+
choices = [
21+
{value = "fix", name = "fix: A bug fix. Correlates with PATCH in SemVer"},
22+
{value = "feat", name = "feat: A new feature. Correlates with MINOR in SemVer"},
23+
{value = "docs", name = "docs: Documentation only changes"},
24+
{value = "style", name = "style: Changes that do not affect the meaning of the code"},
25+
{value = "refactor", name = "refactor: A code change that neither fixes a bug nor adds a feature"},
26+
{value = "perf", name = "perf: A code change that improves performance"},
27+
{value = "test", name = "test: Adding missing or correcting existing tests"},
28+
{value = "build", name = "build: Changes that affect the build system or external dependencies"},
29+
{value = "ci", name = "ci: Changes to CI configuration files and scripts"}
30+
]
31+
32+
[[tool.commitizen.customize.questions]]
33+
type = "input"
34+
name = "scope"
35+
message = "What is the scope of this change? (class or file name): (press [enter] to skip)"
36+
37+
[[tool.commitizen.customize.questions]]
38+
type = "input"
39+
name = "message"
40+
message = "Write a short and imperative summary of the code changes: (lower case and no period)"
41+
"""
42+
43+
@pytest.fixture
44+
def config():
45+
return TomlConfig(data=TOML_WITH_SEARCH_FILTER, path="not_exist.toml")
46+
47+
def test_questions_with_search_filter(config):
48+
"""Test that questions are properly configured with search filter"""
49+
cz = CustomizeCommitsCz(config)
50+
questions = cz.questions()
51+
52+
# Test that the first question (change_type) has search filter enabled
53+
assert questions[0]["type"] == "select"
54+
assert questions[0]["name"] == "change_type"
55+
assert questions[0]["use_search_filter"] is True
56+
assert questions[0]["use_jk_keys"] is False
57+
58+
# Test that the choices are properly configured
59+
choices = questions[0]["choices"]
60+
assert len(choices) == 9 # We have 9 commit types
61+
assert choices[0]["value"] == "fix"
62+
assert choices[1]["value"] == "feat"
63+
64+
def test_message_template(config):
65+
"""Test that the message template is properly configured"""
66+
cz = CustomizeCommitsCz(config)
67+
template = cz.message({
68+
"change_type": "feat",
69+
"scope": "search",
70+
"message": "add search filter support"
71+
})
72+
assert template == "feat: (search) add search filter support"
73+

0 commit comments

Comments
 (0)