Fix collapsable bug

This commit is contained in:
Jim Brännlund 2020-02-20 12:12:12 -05:00
parent 0f6c16a157
commit 301d52f150
3 changed files with 23 additions and 14 deletions

View File

@ -143,12 +143,13 @@ class HTMLReport:
)
if len(cells) > 0:
td_class = "extra"
tr_class = None
if self.config.getini("render_collapsed"):
td_class += " collapsed"
tr_class = "collapsed"
self.row_table = html.tr(cells)
self.row_extra = html.tr(
html.td(self.additional_html, class_=td_class, colspan=len(cells))
html.td(self.additional_html, class_="extra", colspan=len(cells)),
class_=tr_class,
)
def __lt__(self, other):

View File

@ -81,7 +81,9 @@ function add_collapse() {
var collapsed = get_query_parameter('collapsed') || 'Passed';
var extras = elem.parentNode.nextElementSibling;
var expandcollapse = document.createElement("span");
if (collapsed.includes(elem.innerHTML)) {
if (extras.classList.contains("collapsed")) {
expandcollapse.classList.add("expander")
} else if (collapsed.includes(elem.innerHTML)) {
extras.classList.add("collapsed");
expandcollapse.classList.add("expander");
} else {

View File

@ -881,20 +881,26 @@ class TestHTML:
assert result.ret == 0
assert r"\u6d4b\u8bd5\u7528\u4f8b\u540d\u79f0" not in html
@pytest.mark.parametrize("collapsed", [True, False])
def test_collapsed_ini(self, testdir, collapsed):
td_class = "extra"
if collapsed:
td_class += " collapsed"
expected_html = f'<td class="{td_class}" colspan="4">'
@pytest.mark.parametrize("is_collapsed", [True, False])
def test_collapsed(self, testdir, is_collapsed):
collapsed_html = '<tr class="collapsed">'
expected_count = 2 if is_collapsed else 0
testdir.makeini(
f"""
[pytest]
render_collapsed = {collapsed}
render_collapsed = {is_collapsed}
"""
)
testdir.makepyfile(
"""
def test_fail():
assert False
def test_pass():
assert True
"""
)
testdir.makepyfile("def test_fail(): assert False")
result, html = run(testdir)
assert result.ret == 1
assert expected_html in html
assert_results(html, tests=1, passed=0, failed=1)
assert len(re.findall(collapsed_html, html)) == expected_count
assert_results(html, tests=2, passed=1, failed=1)