| 1 |
from typing import Awaitable, Callable, List |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from harlequin import Harlequin |
| 6 |
|
| 7 |
|
| 8 |
@pytest.mark.asyncio |
| 9 |
async def test_toggle_sidebar( |
| 10 |
app: Harlequin, |
| 11 |
app_snapshot: Callable[..., Awaitable[bool]], |
| 12 |
wait_for_workers: Callable[[Harlequin], Awaitable[None]], |
| 13 |
) -> None: |
| 14 |
snap_results: List[bool] = [] |
| 15 |
async with app.run_test() as pilot: |
| 16 |
await wait_for_workers(app) |
| 17 |
while app.editor is None or app.data_catalog.database_tree.loading: |
| 18 |
await pilot.pause() |
| 19 |
# initialization |
| 20 |
sidebar = app.data_catalog |
| 21 |
assert not sidebar.disabled |
| 22 |
assert sidebar.styles.width |
| 23 |
assert sidebar.styles.width.value > 0 |
| 24 |
snap_results.append(await app_snapshot(app, "Initialization")) |
| 25 |
|
| 26 |
await pilot.press("ctrl+b") |
| 27 |
assert sidebar.disabled |
| 28 |
assert sidebar.styles.width |
| 29 |
assert sidebar.styles.width.value == 0 |
| 30 |
snap_results.append(await app_snapshot(app, "Hidden")) |
| 31 |
|
| 32 |
await pilot.press("ctrl+b") |
| 33 |
assert not sidebar.disabled |
| 34 |
assert sidebar.styles.width |
| 35 |
assert sidebar.styles.width.value > 0 |
| 36 |
snap_results.append(await app_snapshot(app, "Unhidden")) |
| 37 |
|
| 38 |
await pilot.press("f9") |
| 39 |
assert sidebar.disabled |
| 40 |
assert sidebar.styles.width |
| 41 |
assert sidebar.styles.width.value == 0 |
| 42 |
snap_results.append(await app_snapshot(app, "Hidden Again")) |
| 43 |
|
| 44 |
assert all(snap_results) |
| 45 |
|
| 46 |
|
| 47 |
@pytest.mark.asyncio |
| 48 |
async def test_toggle_full_screen( |
| 49 |
app: Harlequin, |
| 50 |
app_snapshot: Callable[..., Awaitable[bool]], |
| 51 |
wait_for_workers: Callable[[Harlequin], Awaitable[None]], |
| 52 |
) -> None: |
| 53 |
snap_results: List[bool] = [] |
| 54 |
async with app.run_test() as pilot: |
| 55 |
await wait_for_workers(app) |
| 56 |
while app.editor is None: |
| 57 |
await pilot.pause() |
| 58 |
# initialization; all visible |
| 59 |
app.editor.focus() |
| 60 |
assert app.full_screen is False |
| 61 |
assert app.sidebar_hidden is False |
| 62 |
widgets = [app.data_catalog, app.editor_collection, app.results_viewer] |
| 63 |
for w in widgets: |
| 64 |
assert not w.disabled |
| 65 |
assert w.styles.width |
| 66 |
assert w.styles.width.value > 0 |
| 67 |
snap_results.append(await app_snapshot(app, "Initialization")) |
| 68 |
|
| 69 |
await pilot.press("f10") |
| 70 |
# only editor visible |
| 71 |
assert not app.editor_collection.disabled |
| 72 |
assert not app.editor.disabled |
| 73 |
assert not app.run_query_bar.disabled |
| 74 |
assert app.editor_collection.styles.width |
| 75 |
assert app.editor_collection.styles.width.value > 0 |
| 76 |
for w in [w for w in widgets if w != app.editor_collection]: |
| 77 |
assert w.disabled |
| 78 |
assert w.styles.width |
| 79 |
assert w.styles.width.value == 0 |
| 80 |
snap_results.append(await app_snapshot(app, "Editor Full Screen")) |
| 81 |
|
| 82 |
await pilot.press("ctrl+b") |
| 83 |
# editor and data catalog should be visible |
| 84 |
assert not app.sidebar_hidden |
| 85 |
assert not app.data_catalog.disabled |
| 86 |
assert app.full_screen |
| 87 |
assert not app.editor_collection.disabled |
| 88 |
assert not app.editor.disabled |
| 89 |
snap_results.append(await app_snapshot(app, "Editor Full Screen with Sidebar")) |
| 90 |
|
| 91 |
await pilot.press("f10") |
| 92 |
# all visible |
| 93 |
for w in widgets: |
| 94 |
assert not w.disabled |
| 95 |
assert w.styles.width |
| 96 |
assert w.styles.width.value > 0 |
| 97 |
snap_results.append( |
| 98 |
await app_snapshot(app, "Exit Full Screen (sidebar already visible)") |
| 99 |
) |
| 100 |
|
| 101 |
await pilot.press("ctrl+b") |
| 102 |
# data catalog hidden |
| 103 |
assert app.sidebar_hidden |
| 104 |
assert app.data_catalog.disabled |
| 105 |
assert not app.editor_collection.disabled |
| 106 |
assert not app.editor.disabled |
| 107 |
snap_results.append(await app_snapshot(app, "Sidebar hidden")) |
| 108 |
|
| 109 |
await pilot.press("f10") |
| 110 |
# only editor visible |
| 111 |
assert not app.editor_collection.disabled |
| 112 |
assert not app.editor.disabled |
| 113 |
assert app.data_catalog.disabled |
| 114 |
assert app.results_viewer.disabled |
| 115 |
snap_results.append( |
| 116 |
await app_snapshot(app, "Editor Full Screen (sidebar already hidden)") |
| 117 |
) |
| 118 |
|
| 119 |
await pilot.press("f10") |
| 120 |
# data catalog should still be hidden |
| 121 |
assert not app.editor_collection.disabled |
| 122 |
assert not app.editor.disabled |
| 123 |
assert not app.run_query_bar.disabled |
| 124 |
assert app.data_catalog.disabled |
| 125 |
assert not app.results_viewer.disabled |
| 126 |
snap_results.append( |
| 127 |
await app_snapshot(app, "Exit Full Screen (sidebar remains hidden)") |
| 128 |
) |
| 129 |
app.editor.text = "select 1" |
| 130 |
await pilot.press("ctrl+j") |
| 131 |
|
| 132 |
app.results_viewer.focus() |
| 133 |
await pilot.press("f10") |
| 134 |
# only results viewer should be visible |
| 135 |
assert app.editor_collection.disabled |
| 136 |
assert app.run_query_bar.disabled |
| 137 |
assert app.data_catalog.disabled |
| 138 |
assert not app.results_viewer.disabled |
| 139 |
snap_results.append(await app_snapshot(app, "Results Viewer Full Screen")) |
| 140 |
|
| 141 |
await pilot.press("f9") |
| 142 |
# results viewer and data catalog should be visible |
| 143 |
assert not app.sidebar_hidden |
| 144 |
assert not app.data_catalog.disabled |
| 145 |
assert app.full_screen |
| 146 |
assert app.editor_collection.disabled |
| 147 |
assert app.run_query_bar.disabled |
| 148 |
assert not app.results_viewer.disabled |
| 149 |
snap_results.append( |
| 150 |
await app_snapshot(app, "Results Viewer Full Screen with Sidebar") |
| 151 |
) |
| 152 |
|
| 153 |
await pilot.press("f10") |
| 154 |
# all visible |
| 155 |
assert not app.sidebar_hidden |
| 156 |
assert not app.full_screen |
| 157 |
for w in widgets: |
| 158 |
assert not w.disabled |
| 159 |
assert w.styles.width |
| 160 |
assert w.styles.width.value > 0 |
| 161 |
snap_results.append( |
| 162 |
await app_snapshot(app, "Exit RV Full Screen (sidebar visible)") |
| 163 |
) |
| 164 |
|
| 165 |
assert all(snap_results) |