Skip to content

Commit 33b3b66

Browse files
authored
Fix: visible query param (#695)
1 parent cb09706 commit 33b3b66

File tree

4 files changed

+200
-36
lines changed

4 files changed

+200
-36
lines changed

.github/workflows/tests.yml

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
verbose: true
8484

8585
test_unit:
86-
name: ${{ matrix.os }} - ${{ matrix.python-version }}
86+
name: ${{ matrix.os }} - ${{ matrix.python-version }} - unit
8787
runs-on: ${{ matrix.os }}
8888
strategy:
8989
fail-fast: false
@@ -145,17 +145,13 @@ jobs:
145145
restore-keys: |
146146
${{ matrix.os }}-tox-${{ matrix.python-version }}-
147147
148-
- name: Run unit tests
149-
if: ${{ ! matrix.tox-env && matrix.with-coverage }}
150-
run: tox -e py${{ matrix.python-version }}-cov -- testing/test_unit.py
148+
- name: Run unit tests with coverage
149+
if: ${{ matrix.with-coverage }}
150+
run: tox -e ${{ matrix.python-version }}-cov -- testing/test_unit.py
151151

152-
- name: Run unit tests
153-
if: ${{ ! matrix.tox-env && ! matrix.with-coverage }}
154-
run: tox -e py${{ matrix.python-version }} -- testing/test_unit.py
155-
156-
- name: Run unit tests
157-
if: ${{ matrix.tox-env }}
158-
run: tox -e ${{ matrix.tox-env }} -- testing/test_unit.py
152+
- name: Run unit tests without coverage
153+
if: ${{ ! matrix.with-coverage }}
154+
run: tox -e ${{ matrix.tox-env || matrix.python-version }} -- testing/test_unit.py
159155

160156
- name: Upload coverage to codecov
161157
if: >-
@@ -174,10 +170,7 @@ jobs:
174170
verbose: true
175171

176172
test_integration:
177-
name: ubuntu - ${{ matrix.python-version }}
178-
needs:
179-
- test_javascript
180-
- test_unit
173+
name: ubuntu - ${{ matrix.python-version }} - integration
181174
runs-on: ubuntu-latest
182175
strategy:
183176
fail-fast: false
@@ -224,17 +217,13 @@ jobs:
224217
restore-keys: |
225218
ubuntu-latest-tox-${{ matrix.python-version }}-
226219
227-
- name: Run integration tests
228-
if: ${{ ! matrix.tox-env && matrix.with-coverage }}
220+
- name: Run integration tests with coverage
221+
if: ${{ matrix.with-coverage }}
229222
run: tox -e ${{ matrix.python-version }}-cov -- testing/test_integration.py
230223

231-
- name: Run integration tests
232-
if: ${{ ! matrix.tox-env && ! matrix.with-coverage }}
233-
run: tox -e ${{ matrix.python-version }} -- testing/test_integration.py
234-
235-
- name: Run integration tests
236-
if: ${{ matrix.tox-env }}
237-
run: tox -e ${{ matrix.tox-env }} -- testing/test_integration.py
224+
- name: Run integration tests without coverage
225+
if: ${{ ! matrix.with-coverage }}
226+
run: tox -e ${{ matrix.tox-env || matrix.python-version }} -- testing/test_integration.py
238227

239228
- name: Upload coverage to codecov
240229
if: >-
@@ -251,3 +240,52 @@ jobs:
251240
flags: py_integration_tests
252241
name: ubuntu-latest-${{ matrix.python-version }}
253242
verbose: true
243+
244+
test_e2e:
245+
name: ubuntu - ${{ matrix.python-version }} - e2e
246+
runs-on: ubuntu-latest
247+
strategy:
248+
fail-fast: false
249+
matrix:
250+
python-version: ["3.7", "3.8", "3.9", "3.10"]
251+
include:
252+
- python-version: pypy3.9
253+
tox-env: py3.9
254+
- python-version: 3.11-dev
255+
tox-env: devel
256+
257+
steps:
258+
- name: Set newline behavior
259+
run: git config --global core.autocrlf false
260+
261+
- uses: actions/checkout@v3
262+
263+
- name: Start chrome
264+
run: ./start
265+
266+
- name: Use Node.js
267+
uses: actions/setup-node@v3
268+
with:
269+
node-version: '16.x'
270+
271+
- name: Set up python
272+
uses: actions/setup-python@v4
273+
with:
274+
python-version: ${{ matrix.python-version }}
275+
276+
- name: Ensure latest pip
277+
run: python -m pip install --upgrade pip
278+
279+
- name: Install tox
280+
run: python -m pip install --upgrade tox
281+
282+
- name: Cache tox virtual environment
283+
uses: actions/cache@v3
284+
with:
285+
path: .tox
286+
key: ubuntu-latest-tox-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml', 'tox.ini') }}
287+
restore-keys: |
288+
ubuntu-latest-tox-${{ matrix.python-version }}-
289+
290+
- name: Run e2e tests
291+
run: tox -e ${{ matrix.tox-env || matrix.python-version }} -- testing/test_e2e.py

src/pytest_html/scripts/storage.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@ const possibleFilters = possibleResults.map((item) => item.result)
1111

1212
const getVisible = () => {
1313
const url = new URL(window.location.href)
14-
const settings = new URLSearchParams(url.search).get('visible') || ''
15-
return settings ?
16-
[...new Set(settings.split(',').filter((filter) => possibleFilters.includes(filter)))] : possibleFilters
14+
const settings = new URLSearchParams(url.search).get('visible')
15+
const lower = (item) => {
16+
const lowerItem = item.toLowerCase()
17+
if (possibleFilters.includes(lowerItem)) {
18+
return lowerItem
19+
}
20+
return null
21+
}
22+
return settings === null ?
23+
possibleFilters :
24+
[...new Set(settings?.split(',').map(lower).filter((item) => item))]
1725
}
26+
1827
const hideCategory = (categoryToHide) => {
1928
const url = new URL(window.location.href)
2029
const visibleParams = new URLSearchParams(url.search).get('visible')

testing/test_e2e.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# write a test that sorts the table and asserts the order.
2+
# sort default columns and custom sortable column
3+
import os
4+
import urllib.parse
5+
6+
import pytest
7+
import selenium.webdriver.support.expected_conditions as ec
8+
from assertpy import assert_that
9+
from selenium import webdriver
10+
from selenium.webdriver.common.by import By
11+
from selenium.webdriver.support.wait import WebDriverWait
12+
13+
pytest_plugins = ("pytester",)
14+
15+
16+
@pytest.fixture
17+
def driver(pytester):
18+
chrome_options = webdriver.ChromeOptions()
19+
if os.environ.get("CI", False):
20+
chrome_options.add_argument("--headless")
21+
chrome_options.add_argument("--window-size=1920x1080")
22+
driver = webdriver.Remote(
23+
command_executor="http://127.0.0.1:4444", options=chrome_options
24+
)
25+
26+
yield driver
27+
driver.quit()
28+
29+
30+
@pytest.fixture
31+
def path(pytester):
32+
def func(path="report.html", cmd_flags=None):
33+
cmd_flags = cmd_flags or []
34+
35+
path = pytester.path.joinpath(path)
36+
pytester.runpytest("--html", path, *cmd_flags)
37+
38+
# Begin workaround
39+
# See: https://github.com/pytest-dev/pytest/issues/10738
40+
path.chmod(0o755)
41+
for parent in path.parents:
42+
try:
43+
os.chmod(parent, 0o755)
44+
except PermissionError:
45+
continue
46+
# End workaround
47+
48+
return path
49+
50+
return func
51+
52+
53+
def _encode_query_params(params):
54+
return urllib.parse.urlencode(params)
55+
56+
57+
def test_visible(pytester, path, driver):
58+
pytester.makepyfile(
59+
"""
60+
def test_pass_one(): pass
61+
def test_pass_two(): pass
62+
"""
63+
)
64+
65+
driver.get(f"file:///reports{path()}")
66+
WebDriverWait(driver, 5).until(
67+
ec.visibility_of_all_elements_located((By.CSS_SELECTOR, "#results-table"))
68+
)
69+
result = driver.find_elements(By.CSS_SELECTOR, "tr.collapsible")
70+
assert_that(result).is_length(2)
71+
72+
query_params = _encode_query_params({"visible": ""})
73+
driver.get(f"file:///reports{path()}?{query_params}")
74+
WebDriverWait(driver, 5).until(
75+
ec.visibility_of_all_elements_located((By.CSS_SELECTOR, "#results-table"))
76+
)
77+
result = driver.find_elements(By.CSS_SELECTOR, "tr.collapsible")
78+
assert_that(result).is_length(0)

testing/unittest.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,43 @@ describe('Filter tests', () => {
8080
])
8181
})
8282
})
83+
describe('getVisible', () => {
84+
let originalWindow
85+
86+
after(() => global.window = originalWindow)
87+
88+
it('returns all filters by default', () => {
89+
mockWindow()
90+
const visibleItems = storageModule.getVisible()
91+
expect(visibleItems).to.eql(storageModule.possibleFilters)
92+
})
93+
94+
it('returns specified filters', () => {
95+
mockWindow('visible=failed,error')
96+
const visibleItems = storageModule.getVisible()
97+
expect(visibleItems).to.eql(['failed', 'error'])
98+
})
99+
100+
it('handles case insensitive params', () => {
101+
mockWindow('visible=fAiLeD,ERROR,passed')
102+
const visibleItems = storageModule.getVisible()
103+
expect(visibleItems).to.eql(['failed', 'error', 'passed'])
104+
})
105+
106+
const falsy = [
107+
{ param: 'visible' },
108+
{ param: 'visible=' },
109+
{ param: 'visible=""' },
110+
{ param: 'visible=\'\'' },
111+
]
112+
falsy.forEach(({ param }) => {
113+
it(`returns no filters with ${param}`, () => {
114+
mockWindow(param)
115+
const visibleItems = storageModule.getVisible()
116+
expect(visibleItems).to.be.empty
117+
})
118+
})
119+
})
83120
})
84121

85122

@@ -153,18 +190,20 @@ describe('Sort tests', () => {
153190
})
154191
})
155192

193+
const mockWindow = (queryParam) => {
194+
const mock = {
195+
location: {
196+
href: `https://example.com/page?${queryParam}`,
197+
},
198+
}
199+
originalWindow = global.window
200+
global.window = mock
201+
}
202+
156203
describe('Storage tests', () => {
157204
describe('getCollapsedCategory', () => {
158205
let originalWindow
159-
const mockWindow = (queryParam) => {
160-
const mock = {
161-
location: {
162-
href: `https://example.com/page?${queryParam}`,
163-
},
164-
}
165-
originalWindow = global.window
166-
global.window = mock
167-
}
206+
168207
after(() => global.window = originalWindow)
169208

170209
it('collapses passed by default', () => {

0 commit comments

Comments
 (0)