Skip to content

Commit

Permalink
fix: original sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil committed Nov 7, 2023
1 parent 1348430 commit bb7be37
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pytest_html/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const renderContent = (tests) => {

// remove all sorting classes and set the relevant
findAll('.sortable', tableHeader).forEach((elem) => elem.classList.remove('asc', 'desc'))
tableHeader.querySelector(`.sortable[data-column-type="${sortAttr}"]`).classList.add(sortAsc ? 'desc' : 'asc')
tableHeader.querySelector(`.sortable[data-column-type="${sortAttr}"]`)?.classList.add(sortAsc ? 'desc' : 'asc')
newTable.appendChild(tableHeader)

if (!rows.length) {
Expand Down
46 changes: 46 additions & 0 deletions testing/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,52 @@ def test_log_escaping(self, pytester, outcome, occurrence):
count = log.count(each)
assert_that(count).is_equal_to(occurrence)

@pytest.mark.parametrize(
"sort, order",
[
(None, ["BBB", "AAA", "CCC"]),
("result", ["BBB", "AAA", "CCC"]),
("testId", ["AAA", "BBB", "CCC"]),
("duration", ["CCC", "BBB", "AAA"]),
("original", ["AAA", "BBB", "CCC"]),
],
)
def test_initial_sort(self, pytester, sort, order):
if sort is not None:
pytester.makeini(
f"""
[pytest]
initial_sort = {sort}
"""
)

pytester.makepyfile(
"""
import pytest
from time import sleep
def test_AAA():
sleep(0.3)
assert True
def test_BBB():
sleep(0.2)
assert False
def test_CCC():
sleep(0.1)
assert True
"""
)

page = run(pytester)
assert_results(page, passed=2, failed=1)

result = page.select("td.col-testId")
assert_that(result).is_length(3)
for row, expected in zip(result, order):
assert_that(row.string).contains(expected)


class TestLogCapturing:
LOG_LINE_REGEX = r"\s+this is {}"
Expand Down

0 comments on commit bb7be37

Please sign in to comment.