Skip to content

Commit 3ae81ed

Browse files
committed
Add e2e test
1 parent 3e7d05d commit 3ae81ed

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

tests/app.d/ui_table.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,11 @@ def toggle_table_component():
173173
_stocks,
174174
aggregations=ui.TableAgg("sum"),
175175
)
176+
177+
t_selection = ui.table(
178+
_stocks,
179+
on_selection_change=lambda d: print(
180+
"Selection:", [[row["Sym"]["text"], row["Exchange"]["text"]] for row in d]
181+
),
182+
always_fetch_columns=["Sym", "Exchange"],
183+
)

tests/ui_table.spec.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from '@playwright/test';
2-
import { openPanel, gotoPage } from './utils';
2+
import { openPanel, gotoPage, clickGridRow } from './utils';
33

44
const REACT_PANEL_VISIBLE = '.dh-react-panel:visible';
55

@@ -40,3 +40,21 @@ test('UI table responds to prop changes', async ({ page }) => {
4040
await locator.getByRole('button', { name: 'case' }).click();
4141
await expect(locator).toHaveScreenshot();
4242
});
43+
44+
test('UI table on_selection_change', async ({ page }) => {
45+
await gotoPage(page, '');
46+
await openPanel(page, 't_selection', REACT_PANEL_VISIBLE);
47+
48+
const locator = page.locator(REACT_PANEL_VISIBLE);
49+
50+
await clickGridRow(locator, 3);
51+
await expect(page.getByText("Selection: [['CAT', 'NYPE']]")).toBeVisible();
52+
53+
await clickGridRow(locator, 0, { modifiers: ['ControlOrMeta'] });
54+
await expect(
55+
page.getByText("Selection: [['FISH', 'TPET'], ['CAT', 'NYPE']]")
56+
).toBeVisible();
57+
58+
await page.keyboard.press('Escape');
59+
await expect(page.getByText('Selection: []')).toBeVisible();
60+
});

tests/utils.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const SELECTORS = {
77
REACT_PANEL_OVERLAY: '.dh-react-panel-overlay',
88
};
99

10+
const ROW_HEIGHT = 19;
11+
const COLUMN_HEADER_HEIGHT = 30;
12+
1013
/**
1114
* Goes to a page and waits for the progress bar to disappear
1215
* @param page The page
@@ -168,3 +171,24 @@ export async function pasteInMonaco(
168171
await expect(locator.locator('textarea')).not.toBeEmpty();
169172
}
170173
}
174+
175+
/**
176+
* Clicks the specified row for the grid.
177+
* Clicks in the first column of the row as column width is variable.
178+
* Assumes there is only one level of column headers (i.e., no column groups).
179+
* @param gridContainer The Playwright Locator of the grid container
180+
* @param row The row index to click
181+
* @param clickOptions The Locator click options such as modifies to use
182+
*/
183+
export async function clickGridRow(
184+
gridContainer: Locator,
185+
row: number,
186+
clickOptions?: Parameters<Locator['click']>[0]
187+
): Promise<void> {
188+
const x = 1;
189+
const y = COLUMN_HEADER_HEIGHT + (row + 0.5) * ROW_HEIGHT;
190+
await gridContainer.click({
191+
...clickOptions,
192+
position: { x, y },
193+
});
194+
}

0 commit comments

Comments
 (0)