Skip to content
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

Feature: Only one collapsed state #701

Merged
merged 1 commit into from
Jul 27, 2023
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
11 changes: 4 additions & 7 deletions src/layout/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ div.media {
flex: 0 0 25px;
align-items: center;
}
.collapsed {
display: none;
}

@mixin rowToggle {
color: #bbb;
Expand All @@ -199,25 +196,25 @@ div.media {
}
}

.col-result.collapser {
.col-result {
&:hover::after {
content: ' (hide details)';
}
}
.col-result.expander {
.col-result.collapsed {
&:hover::after {
content: ' (show details)';
}
}

#environment-header.collapser h2 {
#environment-header h2 {
&:hover::after {
content: ' (hide details)';
@include rowToggle;
font-size: $font-size-text;
}
}
#environment-header.expander h2 {
#environment-header.collapsed h2 {
&:hover::after {
content: ' (show details)';
@include rowToggle;
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_html/resources/index.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<h1 id="title">{{ title }}</h1>
<p>Report generated on {{ date }} at {{ time }} by <a href="https://pypi.python.org/pypi/pytest-html">pytest-html</a>
v{{ version }}</p>
<div id="environment-header" class="collapser">
<div id="environment-header">
<h2>Environment</h2>
</div>
<table id="environment"></table>
Expand Down
12 changes: 4 additions & 8 deletions src/pytest_html/resources/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/pytest_html/scripts/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const dom = {
t.innerHTML = html
resultBody.querySelector('.collapsible').appendChild(t.content)
})
resultBody.querySelector('.collapsible > td')?.classList.add(`${collapsed ? 'expander' : 'collapser'}`)

if (log) {
// Wrap lines starting with "E" with span.error to color those lines red
Expand All @@ -61,7 +60,10 @@ const dom = {
}

if (collapsed) {
resultBody.querySelector('.collapsible > td')?.classList.add('collapsed')
resultBody.querySelector('.extras-row').classList.add('hidden')
} else {
resultBody.querySelector('.collapsible > td')?.classList.remove('collapsed')
}

const media = []
Expand Down
3 changes: 1 addition & 2 deletions src/pytest_html/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ const bindEvents = () => {
header.addEventListener('click', () => {
const table = document.getElementById('environment')
table.classList.toggle('hidden')
header.classList.toggle('collapser')
header.classList.toggle('expander')
header.classList.toggle('collapsed')
})

findAll('input[name="filter_checkbox"]').forEach((elem) => {
Expand Down
15 changes: 2 additions & 13 deletions src/pytest_html/scripts/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,15 @@ const showCategory = (categoryToShow) => {
return
}
const url = new URL(window.location.href)
const currentVisible = new URLSearchParams(url.search).get('visible')?.split(',') || [...possibleFilters]
const currentVisible = new URLSearchParams(url.search).get('visible')?.split(',').filter(Boolean) ||
[...possibleFilters]
const settings = [...new Set([categoryToShow, ...currentVisible])]
const noFilter = possibleFilters.length === settings.length || !settings.length

noFilter ? url.searchParams.delete('visible') : url.searchParams.set('visible', settings.join(','))
history.pushState({}, null, unescape(url.href))
}

const setFilter = (currentFilter) => {
if (!possibleFilters.includes(currentFilter)) {
return
}
const url = new URL(window.location.href)
const settings = [currentFilter, ...new Set(new URLSearchParams(url.search).get('filter').split(','))]

url.searchParams.set('filter', settings)
history.pushState({}, null, unescape(url.href))
}

const getSort = (initialSort) => {
const url = new URL(window.location.href)
let sort = new URLSearchParams(url.search).get('sort')
Expand Down Expand Up @@ -103,7 +93,6 @@ const setSortDirection = (ascending) => sessionStorage.setItem('sortAsc', ascend

module.exports = {
getVisible,
setFilter,
hideCategory,
showCategory,
getSort,
Expand Down
2 changes: 1 addition & 1 deletion testing/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_text(page, selector):


def is_collapsed(page, test_name):
return get_element(page, f".summary tbody[id$='{test_name}'] .expander")
return get_element(page, f".summary tbody[id$='{test_name}'] .collapsed")


def get_log(page, test_id=None):
Expand Down
3 changes: 0 additions & 3 deletions testing/unittest.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ describe('Filter tests', () => {
})
})
describe('doFilter', () => {
let setFilterMock
afterEach(() => setFilterMock.restore())
it('removes all but passed', () => {
getFilterMock = sinon.stub(storageModule, 'getVisible').returns(['passed'])
setFilterMock = sinon.stub(storageModule, 'setFilter')
managerSpy = sinon.spy(dataModule.manager, 'setRender')

doFilter('passed', true)
Expand Down