Skip to content

Commit 64aa3af

Browse files
author
Andrei Neagu
committed
made tests more redable
1 parent 74874ef commit 64aa3af

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

services/dynamic-scheduler/tests/unit/api_frontend/_common/test_updatable_component.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pylint:disable=redefined-outer-name
22
# pylint:disable=unused-argument
33

4-
from collections.abc import Callable
4+
from collections.abc import Awaitable, Callable
55
from functools import cached_property
66
from unittest.mock import Mock
77

@@ -67,6 +67,23 @@ async def index():
6767
return router
6868

6969

70+
@pytest.fixture
71+
def ensure_page_loaded(
72+
async_page: Page,
73+
server_host_port: str,
74+
mount_path: str,
75+
layout_manager: LayoutManager,
76+
) -> Callable[[Callable[[], None]], Awaitable[None]]:
77+
async def _(draw_ui: Callable[[], None]) -> None:
78+
layout_manager.set(draw_ui)
79+
await async_page.goto(f"{server_host_port}{mount_path}")
80+
await _ensure_before_corpus(async_page)
81+
await _ensure_after_corpus(async_page)
82+
print("✅ index page loaded")
83+
84+
return _
85+
86+
7087
@pytest.fixture
7188
def not_initialized_app(
7289
reset_nicegui_app: None,
@@ -270,10 +287,8 @@ def _get_updatable_display_model_ids(obj: BaseUpdatableDisplayModel) -> dict[int
270287
)
271288
async def test_updatable_component(
272289
app_runner: None,
290+
ensure_page_loaded: Callable[[Callable[[], None]], Awaitable[None]],
273291
async_page: Page,
274-
layout_manager: LayoutManager,
275-
mount_path: str,
276-
server_host_port: str,
277292
person: Person,
278293
person_update: Person,
279294
expect_same_companion_object: bool,
@@ -282,12 +297,7 @@ async def test_updatable_component(
282297
def _index_corpus() -> None:
283298
PersonComponent(person).display()
284299

285-
layout_manager.set(_index_corpus)
286-
287-
await async_page.goto(f"{server_host_port}{mount_path}")
288-
await _ensure_before_corpus(async_page)
289-
await _ensure_after_corpus(async_page)
290-
print("✅ index page loaded")
300+
await ensure_page_loaded(_index_corpus)
291301

292302
# check initial page layout
293303
await _ensure_index_page(async_page, person)
@@ -314,17 +324,9 @@ def _index_corpus() -> None:
314324
await _ensure_after_corpus(async_page)
315325

316326

317-
# TODO: add a test where I have 10 Persons Rendered on the page
318-
# Add add a way to remove and add them to the page based on a model to which we add or remove stuff
319-
# might require some special facilities in the BaseUpdatableComponent
320-
321-
322327
async def test_multiple_componenets_management(
323328
app_runner: None,
324-
async_page: Page,
325-
layout_manager: LayoutManager,
326-
mount_path: str,
327-
server_host_port: str,
329+
ensure_page_loaded: Callable[[Callable[[], None]], Awaitable[None]],
328330
):
329331
def _index_corpus() -> None:
330332
# TODO: crate something that updates a dict[str, BaseUpdatableDisplayModel]
@@ -334,9 +336,9 @@ def _index_corpus() -> None:
334336
# PersonComponent(person).display()
335337
pass
336338

337-
layout_manager.set(_index_corpus)
339+
await ensure_page_loaded(_index_corpus)
338340

339-
await async_page.goto(f"{server_host_port}{mount_path}")
340-
await _ensure_before_corpus(async_page)
341-
await _ensure_after_corpus(async_page)
342-
print("✅ index page loaded")
341+
342+
# TODO: add a test where I have 10 Persons Rendered on the page
343+
# Add add a way to remove and add them to the page based on a model to which we add or remove stuff
344+
# might require some special facilities in the BaseUpdatableComponent

0 commit comments

Comments
 (0)