From 3ecd8e6d6460f5a1802da42bc4c6f3b4628261b7 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 8 Jan 2024 11:26:25 -0800 Subject: [PATCH] Confirm search form with Playwright, refs #19 --- tests/conftest.py | 14 ++++++++++++-- tests/test_playwright.py | 5 ++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5aee914..e08ec30 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,7 +21,17 @@ def db_path(tmpdir): @pytest.fixture -def ds_server(db_path): +def db_path_searchable(db_path): + sqlite_utils.Database(db_path)["creatures"].enable_fts(["name", "description"]) + # Copy to /tmp + import shutil + + shutil.copyfile(str(db_path), "/tmp/data.db") + return db_path + + +@pytest.fixture +def ds_server(db_path_searchable): process = Popen( [ sys.executable, @@ -29,7 +39,7 @@ def ds_server(db_path): "datasette", "--port", "8126", - str(db_path), + str(db_path_searchable), ], stdout=PIPE, ) diff --git a/tests/test_playwright.py b/tests/test_playwright.py index f86c5f9..5bf974e 100644 --- a/tests/test_playwright.py +++ b/tests/test_playwright.py @@ -4,10 +4,13 @@ sync_api = None import pytest + @pytest.mark.skipif(sync_api is None, reason="playwright not installed") -def test_search(ds_server): +def test_ds_server(ds_server): with sync_api.sync_playwright() as playwright: browser = playwright.chromium.launch() page = browser.new_page() page.goto(ds_server + "/") assert page.title() == "Datasette: data" + # It should have a search form + assert page.query_selector('form[action="/-/search"]')