Skip to content

Customize collapsed rows with a query param #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ HTML report for the test results.
:alt: PyPI
.. image:: https://img.shields.io/conda/vn/conda-forge/pytest-html.svg
:target: https://anaconda.org/conda-forge/pytest-html
:alt: Conda Forge
:alt: Conda Forge
.. image:: https://img.shields.io/travis/pytest-dev/pytest-html.svg
:target: https://travis-ci.org/pytest-dev/pytest-html/
:alt: Travis
Expand Down Expand Up @@ -240,6 +240,14 @@ additional HTML and log output with a notice that the log is empty:
del data[:]
data.append(html.div('No log output captured.', class_='empty log'))

Display options
---------------

By default, all rows in the **Results** table will be expanded except those that have :code:`Passed`.

This behavior can be customized with a query parameter: :code:`?collapsed=Passed,XFailed,Skipped`.


Screenshots
-----------

Expand Down
8 changes: 7 additions & 1 deletion pytest_html/resources/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ function add_collapse() {

// Add show/hide link to each result
find_all('.col-result').forEach(function(elem) {
var collapsed = get_query_parameter('collapsed') || 'Passed';
var extras = elem.parentNode.nextElementSibling;
var expandcollapse = document.createElement("span");
if (elem.innerHTML === 'Passed') {
if (collapsed.includes(elem.innerHTML)) {
extras.classList.add("collapsed");
expandcollapse.classList.add("expander");
} else {
Expand All @@ -98,6 +99,11 @@ function add_collapse() {
})
}

function get_query_parameter(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

function init () {
reset_sort_headers();

Expand Down
6 changes: 6 additions & 0 deletions testing/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

if (!String.prototype.includes) {
String.prototype.includes = function() {'use strict';
return String.prototype.indexOf.apply(this, arguments) !== -1;
};
}

QUnit.module( 'module', {
beforeEach: function( assert ) {
init();
Expand Down