Skip to content

Commit 3f7145f

Browse files
committed
test(anywidget): Add tests for dark mode
1 parent 62897ec commit 3f7145f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

tests/js/table_widget.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,49 @@ describe("TableWidget", () => {
241241
});
242242
});
243243

244+
describe("Theme detection", () => {
245+
beforeEach(() => {
246+
jest.useFakeTimers();
247+
// Mock the initial state for theme detection tests
248+
model.get.mockImplementation((property) => {
249+
if (property === "table_html") {
250+
return "";
251+
}
252+
if (property === "row_count") {
253+
return 100;
254+
}
255+
if (property === "error_message") {
256+
return null;
257+
}
258+
if (property === "page_size") {
259+
return 10;
260+
}
261+
if (property === "page") {
262+
return 0;
263+
}
264+
return null;
265+
});
266+
});
267+
268+
afterEach(() => {
269+
jest.useRealTimers();
270+
document.body.classList.remove("vscode-dark");
271+
});
272+
273+
it("should add bigframes-dark-mode class in dark mode", () => {
274+
document.body.classList.add("vscode-dark");
275+
render({ model, el });
276+
jest.runAllTimers();
277+
expect(el.classList.contains("bigframes-dark-mode")).toBe(true);
278+
});
279+
280+
it("should not add bigframes-dark-mode class in light mode", () => {
281+
render({ model, el });
282+
jest.runAllTimers();
283+
expect(el.classList.contains("bigframes-dark-mode")).toBe(false);
284+
});
285+
});
286+
244287
it("should render the series as a table with an index and one value column", () => {
245288
// Mock the initial state
246289
model.get.mockImplementation((property) => {

tests/unit/display/test_anywidget.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ def handler(signum, frame):
8080
signal.alarm(0)
8181

8282

83+
def test_css_contains_dark_mode_media_query():
84+
from bigframes.display.anywidget import TableWidget
85+
86+
mock_df = mock.create_autospec(bigframes.dataframe.DataFrame, instance=True)
87+
# mock_df.columns and mock_df.dtypes are needed for __init__
88+
mock_df.columns = ["col1"]
89+
mock_df.dtypes = {"col1": "object"}
90+
91+
# Mock _block to avoid AttributeError during _set_table_html
92+
mock_block = mock.Mock()
93+
mock_block.has_index = False
94+
mock_df._block = mock_block
95+
96+
with mock.patch.object(TableWidget, "_initial_load"):
97+
widget = TableWidget(mock_df)
98+
assert "@media (prefers-color-scheme: dark)" in widget._css
99+
100+
83101
@pytest.fixture
84102
def mock_df():
85103
df = mock.create_autospec(bigframes.dataframe.DataFrame, instance=True)

0 commit comments

Comments
 (0)