| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from pathlib import Path |
| 4 |
from textwrap import dedent |
| 5 |
from typing import Awaitable, Callable |
| 6 |
|
| 7 |
import pytest |
| 8 |
|
| 9 |
from harlequin import Harlequin, HarlequinAdapter |
| 10 |
from harlequin.config import load_profile_and_keymaps |
| 11 |
|
| 12 |
QUERY = dedent( |
| 13 |
""" |
| 14 |
select * |
| 15 |
from |
| 16 |
( |
| 17 |
values |
| 18 |
(1, 2, 3), |
| 19 |
(4, 5, 6), |
| 20 |
(7, 8, 9), |
| 21 |
(10, 11, 12), |
| 22 |
(13, 14, 15), |
| 23 |
(16, 17, 18), |
| 24 |
(19, 20, 21) |
| 25 |
) foo(a, b, c) |
| 26 |
""" |
| 27 |
).strip() |
| 28 |
|
| 29 |
|
| 30 |
@pytest.mark.asyncio |
| 31 |
async def test_results_viewer_bindings( |
| 32 |
duckdb_adapter: type[HarlequinAdapter], |
| 33 |
data_dir: Path, |
| 34 |
wait_for_workers: Callable[[Harlequin], Awaitable[None]], |
| 35 |
) -> None: |
| 36 |
config_path = ( |
| 37 |
data_dir / "functional_tests" / "test_keymap_from_config" / "config.toml" |
| 38 |
) |
| 39 |
profile, my_keymaps = load_profile_and_keymaps( |
| 40 |
config_path=config_path, profile_name=None |
| 41 |
) |
| 42 |
app = Harlequin( |
| 43 |
duckdb_adapter([":memory:"], no_init=True), |
| 44 |
keymap_names=profile["keymap_name"], |
| 45 |
user_defined_keymaps=my_keymaps, |
| 46 |
) |
| 47 |
async with app.run_test() as pilot: |
| 48 |
await wait_for_workers(app) |
| 49 |
while app.editor is None: |
| 50 |
await pilot.pause() |
| 51 |
|
| 52 |
q = QUERY |
| 53 |
app.editor.text = q |
| 54 |
await pilot.press("ctrl+j") |
| 55 |
|
| 56 |
while (table := app.results_viewer.get_visible_table()) is None: |
| 57 |
await pilot.pause() |
| 58 |
|
| 59 |
assert table is not None |
| 60 |
assert table.cursor_coordinate == (0, 0) |
| 61 |
assert table.selection_anchor_coordinate is None |
| 62 |
|
| 63 |
# simple navigation |
| 64 |
await pilot.press("s") |
| 65 |
assert table.cursor_coordinate == (1, 0) |
| 66 |
assert table.selection_anchor_coordinate is None |
| 67 |
await pilot.press("d") |
| 68 |
assert table.cursor_coordinate == (1, 1) |
| 69 |
assert table.selection_anchor_coordinate is None |
| 70 |
await pilot.press("d") |
| 71 |
assert table.cursor_coordinate == (1, 2) |
| 72 |
assert table.selection_anchor_coordinate is None |
| 73 |
await pilot.press("a") |
| 74 |
assert table.cursor_coordinate == (1, 1) |
| 75 |
assert table.selection_anchor_coordinate is None |
| 76 |
await pilot.press("w") |
| 77 |
assert table.cursor_coordinate == (0, 1) |
| 78 |
assert table.selection_anchor_coordinate is None |