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
145 lines
3.9 KiB
Python
145 lines
3.9 KiB
Python
import pandas as pd
|
|
import pytest
|
|
from fasthtml.components import *
|
|
from fasthtml.xtend import Script
|
|
|
|
from components.datagrid_new.components.ColumnsSettings import ColumnsSettings
|
|
from components.datagrid_new.components.DataGrid import DataGrid
|
|
from components.datagrid_new.constants import ColumnType
|
|
from core.settings_management import SettingsManager, MemoryDbEngine
|
|
from helpers import matches, search_elements_by_path
|
|
|
|
COLUMNS_SETTINGS_ID = "columns_settings_id"
|
|
TEST_GRID_ID = "test_grid_id"
|
|
TEST_GRID_KEY = ("RepositoryName", "test_grid_key")
|
|
|
|
|
|
@pytest.fixture()
|
|
def empty_dg(session):
|
|
return DataGrid(session,
|
|
_id=TEST_GRID_ID,
|
|
settings_manager=SettingsManager(MemoryDbEngine()),
|
|
key=TEST_GRID_KEY)
|
|
|
|
|
|
@pytest.fixture()
|
|
def dg(empty_dg):
|
|
df = pd.DataFrame({
|
|
'Name': ['Alice', 'Bob'],
|
|
'Age': [20, 25],
|
|
'Male': [False, True],
|
|
})
|
|
|
|
# hack for the test because multiple dg are created with the same id
|
|
empty_dg._columns_settings._owner = empty_dg
|
|
|
|
empty_dg.init_from_dataframe(df)
|
|
return empty_dg
|
|
|
|
|
|
@pytest.fixture
|
|
def cs(session, dg):
|
|
return ColumnsSettings(session, COLUMNS_SETTINGS_ID, owner=dg)
|
|
|
|
|
|
def test_i_can_render(cs):
|
|
actual = cs.__ft__()
|
|
expected = Div(
|
|
Div(
|
|
H1("Columns Settings"),
|
|
Div(
|
|
Div(), # header
|
|
Div(), # body
|
|
Div(), # buttons
|
|
cls="dt2-cs-container"
|
|
),
|
|
),
|
|
Script(f"bindColumnsSettings('{cs.get_id()}')"),
|
|
id=cs.get_id(),
|
|
)
|
|
|
|
assert matches(actual, expected)
|
|
|
|
|
|
def test_i_can_render_when_no_dataframe(empty_dg):
|
|
columns_settings = empty_dg._columns_settings
|
|
actual = columns_settings.__ft__()
|
|
|
|
expected = Div(
|
|
Div(
|
|
H1("Columns Settings"),
|
|
Div(
|
|
Div(), # header
|
|
Div(), # body
|
|
Div(), # buttons
|
|
cls="dt2-cs-container"
|
|
),
|
|
),
|
|
Script(f"bindColumnsSettings('{columns_settings.get_id()}')"),
|
|
id=columns_settings.get_id(),
|
|
)
|
|
|
|
assert matches(actual, expected)
|
|
|
|
|
|
def test_i_can_render_columns_settings(cs):
|
|
def _mk_options(selected_value):
|
|
return [Option(value.value, selected=True if selected_value == value else None) for value in ColumnType]
|
|
|
|
actual = cs.__ft__()
|
|
to_compare = search_elements_by_path(actual, "div", attrs={"class": "dt2-cs-container"})[0]
|
|
|
|
expected = Div(
|
|
Div(
|
|
Div(cls="place-self-center"),
|
|
Div("Title"),
|
|
Div("Type"),
|
|
Div("Visible"),
|
|
Div("Usable"),
|
|
Div("Width"),
|
|
cls="dt2-cs-header dt2-cs-columns"
|
|
),
|
|
Div(
|
|
Div(
|
|
A(cls="dt2-item-handle"),
|
|
Input(name="title_name", type="input", value="Name"),
|
|
Select(
|
|
*_mk_options(ColumnType.Text),
|
|
name="type_name",
|
|
),
|
|
Input(name=f"visible_name", type="checkbox", checked=True),
|
|
Input(name=f"usable_name", type="checkbox", checked=True),
|
|
Input(name=f"width_name", type="input", value=100),
|
|
data_col="name",
|
|
),
|
|
Div(
|
|
A(cls="dt2-item-handle"),
|
|
Input(name="title_age", type="input", value="Age"),
|
|
Select(
|
|
*_mk_options(ColumnType.Number),
|
|
name="type_age",
|
|
),
|
|
Input(name=f"visible_age", type="checkbox", checked=True),
|
|
Input(name=f"usable_age", type="checkbox", checked=True),
|
|
Input(name=f"width_age", type="input", value=100),
|
|
data_col="age",
|
|
),
|
|
Div(
|
|
A(cls="dt2-item-handle"),
|
|
Input(name="title_male", type="input", value="Male"),
|
|
Select(
|
|
*_mk_options(ColumnType.Bool),
|
|
name="type_male",
|
|
),
|
|
Input(name=f"visible_male", type="checkbox", checked=True),
|
|
Input(name=f"usable_male", type="checkbox", checked=True),
|
|
Input(name=f"width_male", type="input", value=100),
|
|
data_col="male",
|
|
),
|
|
),
|
|
Div(), # buttons
|
|
cls="dt2-cs-container",
|
|
)
|
|
|
|
assert matches(to_compare, expected)
|