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(
"render_collapsed",
type="string",
default="",
help="Open the report with all rows collapsed. Useful for very large reports",
default="passed",
help="row(s) to render collapsed on open.",
)
parser.addini(
"max_asset_filename_length",
@ -63,9 +63,15 @@ def pytest_addoption(parser):
parser.addini(
"environment_table_redact_list",
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",
)
parser.addini(
"initial_sort",
type="string",
default="result",
help="column to initially sort on.",
)
def pytest_configure(config):

View File

@ -33,17 +33,21 @@ class ReportData:
}
collapsed = config.getini("render_collapsed")
if collapsed:
if collapsed.lower() == "true":
warnings.warn(
"'render_collapsed = True' is deprecated and support "
"will be removed in the next major release. "
"Please use 'render_collapsed = all' instead.",
DeprecationWarning,
)
self.set_data(
"renderCollapsed", [outcome.lower() for outcome in collapsed.split(",")]
if collapsed.lower() == "true":
warnings.warn(
"'render_collapsed = True' is deprecated and support "
"will be removed in the next major release. "
"Please use 'render_collapsed = all' instead.",
DeprecationWarning,
)
collapsed = "all"
self.set_data(
"renderCollapsed", [outcome.lower() for outcome in collapsed.split(",")]
)
initial_sort = config.getini("initial_sort")
self.set_data("initialSort", initial_sort)
@property
def title(self):

View File

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

View File

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

View File

@ -48,9 +48,13 @@ const setFilter = (currentFilter) => {
history.pushState({}, null, unescape(url.href))
}
const getSort = () => {
const getSort = (initialSort) => {
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 url = new URL(window.location.href)