Skip to content

Commit 78bf315

Browse files
committed
create reproduction for issue #5085
1 parent c8c3dd7 commit 78bf315

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

tests/test_sub_pages.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ def test_async_nested_sub_pages(screen: Screen):
254254
'index': 0,
255255
'sleep': 0,
256256
'sleep_main': 0,
257+
'sleep_sub': 0,
257258
'background': 0,
258259
'background_main': 0,
259260
}
@@ -272,7 +273,10 @@ def index():
272273
async def sleep():
273274
calls['sleep'] += 1
274275
await asyncio.sleep(0.1)
275-
ui.sub_pages({'/': sleep_main})
276+
ui.sub_pages({
277+
'/': sleep_main,
278+
'/sub': sleep_sub,
279+
})
276280

277281
def background():
278282
async def add():
@@ -288,25 +292,34 @@ def sleep_main():
288292
calls['sleep_main'] += 1
289293
ui.label('sleep main page')
290294

295+
def sleep_sub():
296+
calls['sleep_sub'] += 1
297+
ui.label('sleep sub page')
298+
291299
def background_main():
292300
calls['background_main'] += 1
293301
ui.label('background main page')
294302

295303
screen.open('/sleep')
296304
screen.should_contain('sleep main page')
297-
assert calls == {'index': 1, 'sleep': 1, 'sleep_main': 1, 'background': 0, 'background_main': 0}
305+
assert calls == {'index': 1, 'sleep': 1, 'sleep_main': 1, 'sleep_sub': 0, 'background': 0, 'background_main': 0}
298306

299307
screen.open('/background')
300308
screen.should_contain('background main page')
301-
assert calls == {'index': 2, 'sleep': 1, 'sleep_main': 1, 'background': 1, 'background_main': 1}
309+
assert calls == {'index': 2, 'sleep': 1, 'sleep_main': 1, 'sleep_sub': 0, 'background': 1, 'background_main': 1}
302310

303311
screen.click('Go to sleep')
304312
screen.should_contain('sleep main page')
305-
assert calls == {'index': 2, 'sleep': 2, 'sleep_main': 2, 'background': 1, 'background_main': 1}
313+
assert calls == {'index': 2, 'sleep': 2, 'sleep_main': 2, 'sleep_sub': 0, 'background': 1, 'background_main': 1}
306314

307315
screen.click('Go to background')
308316
screen.should_contain('background main page')
309-
assert calls == {'index': 2, 'sleep': 2, 'sleep_main': 2, 'background': 2, 'background_main': 2}
317+
assert calls == {'index': 2, 'sleep': 2, 'sleep_main': 2, 'sleep_sub': 0, 'background': 2, 'background_main': 2}
318+
319+
# directly opening a nested sub page on an async sub page (see https://github.com/zauberzeug/nicegui/issues/5085)
320+
screen.open('/sleep/sub')
321+
screen.should_contain('sleep sub page')
322+
assert calls == {'index': 3, 'sleep': 3, 'sleep_main': 2, 'sleep_sub': 1, 'background': 2, 'background_main': 2}
310323

311324

312325
def test_parameterized_sub_pages(screen: Screen):

0 commit comments

Comments
 (0)