|
7 | 7 | from textual.widgets import OptionList |
8 | 8 |
|
9 | 9 | from sqlit.domains.query.store.history import QueryHistoryEntry |
| 10 | +from sqlit.domains.query.store.memory import InMemoryHistoryStore |
10 | 11 | from sqlit.domains.query.ui.screens.query_history import QueryHistoryScreen |
11 | 12 | from sqlit.domains.shell.app.main import SSMSTUI |
12 | 13 |
|
@@ -195,6 +196,34 @@ async def test_show_history_for_unsaved_connection_uses_session_history(self) -> |
195 | 196 | option_list = screen.query_one("#history-list", OptionList) |
196 | 197 | assert option_list.option_count == 1 |
197 | 198 |
|
| 199 | + @pytest.mark.asyncio |
| 200 | + async def test_show_history_for_unsaved_connection_with_duplicates(self) -> None: |
| 201 | + unsaved_conn = create_test_connection("temp-db", "sqlite") |
| 202 | + history_store = MockHistoryStore() |
| 203 | + services = build_test_services( |
| 204 | + connection_store=MockConnectionStore([]), |
| 205 | + settings_store=MockSettingsStore({"theme": "tokyo-night"}), |
| 206 | + history_store=history_store, |
| 207 | + ) |
| 208 | + app = SSMSTUI(services=services) |
| 209 | + |
| 210 | + async with app.run_test(size=(100, 35)) as pilot: |
| 211 | + app.current_config = unsaved_conn |
| 212 | + app._save_query_history(unsaved_conn, "SELECT 1") |
| 213 | + app._save_query_history(unsaved_conn, "SELECT 1") |
| 214 | + |
| 215 | + app.action_show_history() |
| 216 | + await pilot.pause(0.2) |
| 217 | + |
| 218 | + screen = next( |
| 219 | + (s for s in app.screen_stack if isinstance(s, QueryHistoryScreen)), |
| 220 | + None, |
| 221 | + ) |
| 222 | + assert screen is not None, "History screen should be present" |
| 223 | + |
| 224 | + option_list = screen.query_one("#history-list", OptionList) |
| 225 | + assert option_list.option_count == 1 |
| 226 | + |
198 | 227 | def test_saved_connection_queries_saved(self) -> None: |
199 | 228 | saved_conn = create_test_connection("saved-db", "sqlite") |
200 | 229 | history_store = MockHistoryStore() |
|
0 commit comments