|
2 | 2 | import dash_ag_grid as dag |
3 | 3 | import plotly.express as px |
4 | 4 | import json |
| 5 | +import pytest |
5 | 6 |
|
6 | 7 | from . import utils |
7 | 8 | from dash.testing.wait import until |
@@ -61,3 +62,58 @@ def test_us001_user_style(dash_duo): |
61 | 62 | in dash_duo.find_element("div.ag-theme-alpine").get_attribute("style"), |
62 | 63 | timeout=3, |
63 | 64 | ) |
| 65 | + |
| 66 | + |
| 67 | +@pytest.mark.parametrize("theme", ["alpine", "balham", "material", "quartz"]) |
| 68 | +def test_us002_legacy_themes(dash_duo, theme): |
| 69 | + app = Dash( |
| 70 | + __name__, |
| 71 | + external_stylesheets=[ |
| 72 | + dag.themes.BASE, |
| 73 | + dag.themes.ALPINE, |
| 74 | + dag.themes.BALHAM, |
| 75 | + dag.themes.MATERIAL, |
| 76 | + dag.themes.QUARTZ, |
| 77 | + ], |
| 78 | + ) |
| 79 | + |
| 80 | + columnDefs = [ |
| 81 | + {"field": "name", "width": "500"}, |
| 82 | + ] |
| 83 | + |
| 84 | + rowData = [ |
| 85 | + {"name": "a"}, |
| 86 | + {"name": "b"}, |
| 87 | + {"name": "c"}, |
| 88 | + ] |
| 89 | + |
| 90 | + app.layout = html.Div( |
| 91 | + [ |
| 92 | + dag.AgGrid( |
| 93 | + id="grid", |
| 94 | + columnDefs=columnDefs, |
| 95 | + rowData=rowData, |
| 96 | + dashGridOptions={"theme": "legacy"}, |
| 97 | + className=f"ag-theme-{theme}", |
| 98 | + ), |
| 99 | + ] |
| 100 | + ) |
| 101 | + |
| 102 | + dash_duo.start_server(app) |
| 103 | + |
| 104 | + grid = utils.Grid(dash_duo, "grid") |
| 105 | + |
| 106 | + grid.wait_for_cell_text(0, 0, "a") |
| 107 | + |
| 108 | + # Test that the CSS files are actually loaded and applied |
| 109 | + |
| 110 | + # Base styles: assert that the grid height is <= 400px because an unstyled |
| 111 | + # grid is very "tall" |
| 112 | + root_wrapper = dash_duo.find_element(".ag-root-wrapper") |
| 113 | + wrapper_height = root_wrapper.size["height"] |
| 114 | + assert wrapper_height <= 400, f"Grid appears to be unstyled: height is too tall ({wrapper_height}px)" |
| 115 | + |
| 116 | + # Specific themes: Assert that cell headers are bold |
| 117 | + header_cell_text = dash_duo.find_element(".ag-header-cell-text") |
| 118 | + font_weight = header_cell_text.value_of_css_property("font-weight") |
| 119 | + assert font_weight in ["bold", "700", "600", "500",], "Grid appears to be unstyled: cell headers are not bold" |
0 commit comments