Skip to content

Commit 4dfec1c

Browse files
authored
Make the links column in the results table sortable (#324)
* Make the links column sortable
1 parent 4aaa875 commit 4dfec1c

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Release Notes
33

44
**2.1.2 (unreleased)**
55

6+
* Make the ``Results`` table ``Links`` column sortable (`#242 <https://github.com/pytest-dev/pytest-html/issues/242>`_)
7+
8+
* Thanks to `@vashirov <https://github.com/vashirov>`_ for reporting and `@gnikonorov <https://github.com/gnikonorov>`_ for the fix
9+
610
* Fix issue with missing image or video in extras. (`#265 <https://github.com/pytest-dev/pytest-html/issues/265>`_ and `pytest-selenium#237 <https://github.com/pytest-dev/pytest-selenium/issues/237>`_)
711

812
* Thanks to `@p00j4 <https://github.com/p00j4>`_ and `@anothermattbrown <https://github.com/anothermattbrown>`_ for reporting and `@christiansandberg <https://github.com/christiansandberg>`_ and `@superdodd <https://github.com/superdodd>`_ and `@dhalperi <https://github.com/dhalperi>`_ for the fix

pytest_html/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def generate_summary_item(self):
498498
html.th("Result", class_="sortable result initial-sort", col="result"),
499499
html.th("Test", class_="sortable", col="name"),
500500
html.th("Duration", class_="sortable numeric", col="duration"),
501-
html.th("Links"),
501+
html.th("Links", class_="sortable links", col="links"),
502502
]
503503
session.config.hook.pytest_html_results_table_header(cells=cells)
504504

pytest_html/resources/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function sort_column(elem) {
3232
key = key_num;
3333
} else if (elem.classList.contains('result')) {
3434
key = key_result;
35+
} else if (elem.classList.contains('links')) {
36+
key = key_link;
3537
} else {
3638
key = key_alpha;
3739
}
@@ -178,6 +180,13 @@ function key_num(col_index) {
178180
};
179181
}
180182

183+
function key_link(col_index) {
184+
return function(elem) {
185+
dataCell = elem.childNodes[1].childNodes[col_index].firstChild
186+
return dataCell == null ? "" : dataCell.innerText.toLowerCase();
187+
};
188+
}
189+
181190
function key_result(col_index) {
182191
return function(elem) {
183192
var strings = ['Error', 'Failed', 'Rerun', 'XFailed', 'XPassed',

testing/js_test_report.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<th class="sortable result initial-sort" col="result">Result</th>
2121
<th class="sortable" col="name">Test</th>
2222
<th class="sortable numeric" col="duration">Duration</th>
23-
<th>Links</th></tr>
23+
<th class="sortable links" col="links">Links</th></tr>
2424
<tr hidden="true" id="not-found-message">
2525
<th colspan="5">No results found. Try to check the filters</th>
2626
</tr>
@@ -30,7 +30,7 @@
3030
<td class="col-result">Rerun</td>
3131
<td class="test-1 col-name">rerun.py::test_rexample_1</td>
3232
<td class="col-duration">1.00</td>
33-
<td class="col-links"></td></tr>
33+
<td class="col-links"><a class="url" href="http://www.google.com/" target="_blank">URL</a> </td></tr>
3434
<tr>
3535
<td class="extra" colspan="5">
3636
<div class="log">@pytest.mark.flaky(reruns=5)<br/> def test_example():<br/> import random<br/>&gt; assert random.choice([True, False])<br/><span class="error">E assert False</span><br/><span class="error">E + where False = &lt;bound method Random.choice of &lt;random.Random object at 0x7fe80b85f420&gt;&gt;([True, False])</span><br/><span class="error">E + where &lt;bound method Random.choice of &lt;random.Random object at 0x7fe80b85f420&gt;&gt; = &lt;module 'random' from '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.pyc'&gt;.choice</span><br/><br/>rerun.py:6: AssertionError<br/></div></td></tr></tbody>

testing/test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
'rerun results-table-row', 'passed results-table-row');
4949
sort_column_test('[col=duration]',
5050
'passed results-table-row', 'rerun results-table-row');
51+
52+
//links
53+
sort_column_test('[col=links]',
54+
'rerun results-table-row', 'passed results-table-row');
55+
sort_column_test('[col=links]',
56+
'passed results-table-row', 'rerun results-table-row');
5157
});
5258

5359
QUnit.test('filter_table', function(assert){
@@ -123,6 +129,6 @@ QUnit.test('find', function (assert) {
123129
});
124130

125131
QUnit.test('find_all', function(assert) {
126-
assert.equal(find_all('.sortable').length, 3);
132+
assert.equal(find_all('.sortable').length, 4);
127133
assert.equal(find_all('.not-in-table').length, 0);
128134
});

0 commit comments

Comments
 (0)