Feature: Add initial sort column as ini (#692)

This commit is contained in:
Jim Brännlund 2023-07-23 02:37:45 +02:00 committed by GitHub
parent ae54ee6277
commit 27208bba3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 19 deletions

View File

@ -51,8 +51,8 @@ def pytest_addoption(parser):
parser.addini( parser.addini(
"render_collapsed", "render_collapsed",
type="string", type="string",
default="", default="passed",
help="Open the report with all rows collapsed. Useful for very large reports", help="row(s) to render collapsed on open.",
) )
parser.addini( parser.addini(
"max_asset_filename_length", "max_asset_filename_length",
@ -63,9 +63,15 @@ def pytest_addoption(parser):
parser.addini( parser.addini(
"environment_table_redact_list", "environment_table_redact_list",
type="linelist", type="linelist",
help="A list of regexes corresponding to environment " help="a list of regexes corresponding to environment "
"table variables whose values should be redacted from the report", "table variables whose values should be redacted from the report",
) )
parser.addini(
"initial_sort",
type="string",
default="result",
help="column to initially sort on.",
)
def pytest_configure(config): def pytest_configure(config):

View File

@ -33,7 +33,6 @@ class ReportData:
} }
collapsed = config.getini("render_collapsed") collapsed = config.getini("render_collapsed")
if collapsed:
if collapsed.lower() == "true": if collapsed.lower() == "true":
warnings.warn( warnings.warn(
"'render_collapsed = True' is deprecated and support " "'render_collapsed = True' is deprecated and support "
@ -41,10 +40,15 @@ class ReportData:
"Please use 'render_collapsed = all' instead.", "Please use 'render_collapsed = all' instead.",
DeprecationWarning, DeprecationWarning,
) )
collapsed = "all"
self.set_data( self.set_data(
"renderCollapsed", [outcome.lower() for outcome in collapsed.split(",")] "renderCollapsed", [outcome.lower() for outcome in collapsed.split(",")]
) )
initial_sort = config.getini("initial_sort")
self.set_data("initialSort", initial_sort)
@property @property
def title(self): def title(self):
return self._data["title"] return self._data["title"]

View File

@ -40,9 +40,9 @@ const dom = {
return envRow return envRow
}, },
getListHeader: ({ resultsTableHeader }) => { getListHeader: ({ initialSort, resultsTableHeader }) => {
const header = listHeader.content.cloneNode(true) const header = listHeader.content.cloneNode(true)
const sortAttr = storageModule.getSort() const sortAttr = storageModule.getSort(initialSort)
const sortAsc = JSON.parse(storageModule.getSortDirection()) const sortAsc = JSON.parse(storageModule.getSortDirection())
resultsTableHeader.forEach((html) => { resultsTableHeader.forEach((html) => {

View File

@ -43,7 +43,7 @@ const durationSort = (list, ascending) => {
} }
const doInitSort = () => { const doInitSort = () => {
const type = storageModule.getSort() const type = storageModule.getSort(manager.allData.initialSort)
const ascending = storageModule.getSortDirection() const ascending = storageModule.getSortDirection()
const list = manager.testSubset const list = manager.testSubset
const initialOrder = ['Error', 'Failed', 'Rerun', 'XFailed', 'XPassed', 'Skipped', 'Passed'] const initialOrder = ['Error', 'Failed', 'Rerun', 'XFailed', 'XPassed', 'Skipped', 'Passed']
@ -67,7 +67,7 @@ const doInitSort = () => {
} }
const doSort = (type) => { const doSort = (type) => {
const newSortType = storageModule.getSort() !== type const newSortType = storageModule.getSort(manager.allData.initialSort) !== type
const currentAsc = storageModule.getSortDirection() const currentAsc = storageModule.getSortDirection()
const ascending = newSortType ? true : !currentAsc const ascending = newSortType ? true : !currentAsc
storageModule.setSort(type) storageModule.setSort(type)

View File

@ -48,9 +48,13 @@ const setFilter = (currentFilter) => {
history.pushState({}, null, unescape(url.href)) history.pushState({}, null, unescape(url.href))
} }
const getSort = () => { const getSort = (initialSort) => {
const url = new URL(window.location.href) const url = new URL(window.location.href)
return new URLSearchParams(url.search).get('sort') || 'result' let sort = new URLSearchParams(url.search).get('sort')
if (!sort) {
sort = initialSort || 'result'
}
return sort
} }
const setSort = (type) => { const setSort = (type) => {
const url = new URL(window.location.href) const url = new URL(window.location.href)