Skip to content

Commit 4ee12c4

Browse files
authored
fix: original sort order (#768)
1 parent e48a649 commit 4ee12c4

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Versions follow `Semantic Versioning`_ (``<major>.<minor>.<patch>``).
66
Version History
77
---------------
88

9+
Unreleased
10+
~~~~~~~~~~
11+
12+
* Fix original initial sort INI-setting.
13+
14+
* Thanks to `@sturmf <https://github.com/sturmf>`_ for reporting.
15+
916
4.1.0 (2023-11-04)
1017
~~~~~~~~~~~~~~~~~~
1118

src/pytest_html/scripts/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const renderContent = (tests) => {
5757

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

6363
if (!rows.length) {

testing/test_integration.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,52 @@ def test_log_escaping(self, pytester, outcome, occurrence):
823823
count = log.count(each)
824824
assert_that(count).is_equal_to(occurrence)
825825

826+
@pytest.mark.parametrize(
827+
"sort, order",
828+
[
829+
(None, ["BBB", "AAA", "CCC"]),
830+
("result", ["BBB", "AAA", "CCC"]),
831+
("testId", ["AAA", "BBB", "CCC"]),
832+
("duration", ["CCC", "BBB", "AAA"]),
833+
("original", ["AAA", "BBB", "CCC"]),
834+
],
835+
)
836+
def test_initial_sort(self, pytester, sort, order):
837+
if sort is not None:
838+
pytester.makeini(
839+
f"""
840+
[pytest]
841+
initial_sort = {sort}
842+
"""
843+
)
844+
845+
pytester.makepyfile(
846+
"""
847+
import pytest
848+
from time import sleep
849+
850+
def test_AAA():
851+
sleep(0.3)
852+
assert True
853+
854+
def test_BBB():
855+
sleep(0.2)
856+
assert False
857+
858+
def test_CCC():
859+
sleep(0.1)
860+
assert True
861+
"""
862+
)
863+
864+
page = run(pytester)
865+
assert_results(page, passed=2, failed=1)
866+
867+
result = page.select("td.col-testId")
868+
assert_that(result).is_length(3)
869+
for row, expected in zip(result, order):
870+
assert_that(row.string).contains(expected)
871+
826872

827873
class TestLogCapturing:
828874
LOG_LINE_REGEX = r"\s+this is {}"

0 commit comments

Comments
 (0)