Files
MyManagingTools/tests/test_repositories.py
Kodjo Sossouvi 66ea45f501 I can add tables
Refactoring DbEngine

Fixing unit tests

Fixing unit tests

Fixing unit tests

Refactored DbManager for datagrid

Improving front end performance

I can add new table

Fixed sidebar closing when clicking on it

Fix drag event rebinding, improve listener options, and add debug

Prevent duplicate drag event bindings with a dataset flag and ensure consistent scrollbar functionality. Change wheel event listener to passive mode for better performance. Refactor function naming for consistency, and add debug logs for event handling.

Refactor Datagrid bindings and default state handling.

Updated Javascript to conditionally rebind Datagrid on specific events. Improved Python components by handling empty DataFrame cases and removing redundant code. Revised default state initialization in settings for better handling of mutable fields.

Added Rowindex visualisation support

Working on Debugger with own implementation of JsonViewer

Working on JsonViewer.py

Fixed unit tests

Adding unit tests

I can fold and unfold

fixed unit tests

Adding css for debugger

Added tooltip management

Adding debugger functionalities

Refactor serializers and improve error handling in DB engine

Fixed error where tables were overwritten

I can display footer menu

Working on footer. Refactoring how heights are managed

Refactored scrollbars management

Working on footer menu

I can display footer menu + fixed unit tests

Fixed unit tests

Updated click management

I can display aggregations in footers

Added docker management

Refactor input handling and improve config defaults

Fixed scrollbars colors

Refactored tooltip management

Improved tooltip management

Improving FilterAll
2025-05-30 20:27:43 +02:00

145 lines
4.4 KiB
Python

import pytest
from fasthtml.components import *
from components.repositories.components.Repositories import Repositories
from components.repositories.constants import ROUTE_ROOT, Routes
from core.settings_management import SettingsManager, MemoryDbEngine
from helpers import matches, StartsWith, div_icon, find_first_match, search_elements_by_path
USER_EMAIL = "test@mail.com"
USER_ID = "test_user"
TEST_REPOSITORIES_ID = "testing_repositories_id"
@pytest.fixture
def session():
return {"user_id": USER_ID, "user_email": USER_EMAIL}
@pytest.fixture
def tabs_manager():
class MockTabsManager:
def __init__(self):
self.tabs = []
self.mock_content = Div("No tabs yet")
self._called_methods: list[tuple] = []
def add_tab(self, *args, **kwargs):
self._called_methods.append(("set_tab_content", args, kwargs))
table_name, content, key = args
self.tabs.append({"table_name": table_name, "content": content, "key": key})
def get_id(self):
return "tabs_id"
def set_tab_content(self, *args, **kwargs):
self._called_methods.append(("set_tab_content", args, kwargs))
title = kwargs.get("title", None)
key = kwargs.get("key", None)
self.mock_content = Div(f"{title=}, {key=}")
def refresh(self):
return self.mock_content
return MockTabsManager()
@pytest.fixture
def repositories(session, tabs_manager):
return Repositories(session=session, _id=TEST_REPOSITORIES_ID,
settings_manager=SettingsManager(engine=MemoryDbEngine()),
tabs_manager=tabs_manager)
def test_render_no_repository(repositories):
actual = repositories.__ft__()
expected = (
Div(
Div(cls="divider"),
Div("Repositories"),
Div(id=repositories.get_id()),
)
)
assert matches(actual, expected)
def test_render_when_repo_and_tables(repositories):
repositories.db.add_repository("repo 1", ["table 1", "table 2"])
repositories.db.add_repository("repo 2", ["table 3"])
actual = repositories.__ft__()
to_compare = search_elements_by_path(actual, "div", {"id": repositories.get_id()})[0]
expected = Div(
Div(
Input(type="radio"),
Div(div_icon("database"), Div("repo 1"), cls=StartsWith("collapse-title")),
Div(
Div(div_icon("table"), Div("table 1")),
Div(div_icon("table"), Div("table 2")),
cls=StartsWith("collapse-content")
),
),
Div(
Input(type="radio"),
Div(div_icon("database"), Div("repo 2"), cls=StartsWith("collapse-title")),
Div(
Div(div_icon("table"), Div("table 3")),
cls=StartsWith("collapse-content")
),
),
id=repositories.get_id())
assert matches(to_compare, expected)
def test_i_can_add_new_repository(repositories):
tab_id = "tab_id"
form_id = "form_id"
repository_name = "repository_name"
table_name = "table_name"
boundaries = {"height": 600, "width": 800}
res = repositories.add_new_repository(tab_id, form_id, repository_name, table_name, boundaries)
expected = (
Div(
Input(type="radio"),
Div(div_icon("database"), Div(repository_name)),
Div(
Div(div_icon("table"), Div(table_name)),
cls=StartsWith("collapse-content")
),
),
Div(f"title='{table_name}', key={(repository_name, table_name)}")
)
assert matches(res, expected)
def test_i_can_click_on_repo(repositories):
repositories.db.add_repository("repo 1", [])
actual = repositories.__ft__()
expected = Input(
hx_put=f"{ROUTE_ROOT}{Routes.SelectRepository}",
hx_vals=f'{{"_id": "{repositories.get_id()}", "repository": "repo 1"}}',
)
to_compare = find_first_match(actual, "div.div.div.input")
assert matches(to_compare, expected)
def test_render_i_can_click_on_table(repositories, tabs_manager):
repositories.db.add_repository("repo 1", ["table 1"])
actual = repositories.__ft__()
expected = Div(name="repo-table",
hx_get=f"{ROUTE_ROOT}{Routes.ShowTable}",
hx_target=f"#{repositories.tabs_manager.get_id()}",
hx_swap="outerHTML",
hx_vals=f'js:{{"_id": "{repositories.get_id()}", "repository": "repo 1", "table": "table 1", "tab_boundaries": getTabContentBoundaries("tabs_id")}}',
cls="flex")
to_compare = find_first_match(actual, "div.div.div.div.div[name='repo-table']")
assert matches(to_compare, expected)