122 lines
4.1 KiB
Python
122 lines
4.1 KiB
Python
from zotero_kb.api import create_app
|
|
from zotero_kb.config import AppConfig
|
|
|
|
|
|
def _get_index_html(tmp_path) -> str:
|
|
app = create_app(
|
|
AppConfig(
|
|
workspace_dir=tmp_path / "workspace",
|
|
zotero_data_dir=tmp_path / "zotero",
|
|
bridge_file=tmp_path / "bridge.json",
|
|
)
|
|
)
|
|
|
|
for route in app.routes:
|
|
if getattr(route, "path", None) == "/" and "GET" in getattr(route, "methods", set()):
|
|
return route.endpoint()
|
|
|
|
raise AssertionError("GET / route not found")
|
|
|
|
|
|
def test_index_contains_base_page_forms(tmp_path) -> None:
|
|
html = _get_index_html(tmp_path)
|
|
|
|
assert 'id="create-project-form"' in html
|
|
assert 'id="recommend-form"' in html
|
|
assert 'id="plan-form"' in html
|
|
|
|
|
|
def test_index_contains_import_window_controls(tmp_path) -> None:
|
|
html = _get_index_html(tmp_path)
|
|
|
|
assert 'id="open-import-modal-button"' in html
|
|
assert 'id="import-window-shell"' in html
|
|
assert 'id="window-minimize-button"' in html
|
|
assert 'id="window-maximize-button"' in html
|
|
assert 'id="window-close-button"' in html
|
|
assert 'id="window-restore-button"' in html
|
|
assert 'id="import-window-minimized-bar"' in html
|
|
assert 'id="import-window-project-label"' in html
|
|
# New two-column import layout
|
|
assert 'id="import-items-list"' in html
|
|
assert 'id="item-preview"' in html
|
|
assert 'id="pending-count"' in html
|
|
assert 'id="done-count"' in html
|
|
assert 'id="select-all-pending"' in html
|
|
assert 'id="generate-cards-btn"' in html
|
|
assert 'isImportWindowOpen: false' in html
|
|
assert "function openImportWindow()" in html
|
|
assert "function closeImportWindow()" in html
|
|
assert "function updateImportActionState()" in html
|
|
assert 'document.body.classList.toggle("modal-open"' in html
|
|
|
|
|
|
def test_index_window_frame_css(tmp_path) -> None:
|
|
html = _get_index_html(tmp_path)
|
|
|
|
assert ".window-frame" in html
|
|
assert ".window-shell" in html
|
|
assert ".window-toolbar" in html
|
|
assert ".window-body" in html
|
|
assert ".window-minimized-bar" in html
|
|
assert '"zotero-kb.import-window"' in html
|
|
assert "startWindowDrag" in html
|
|
assert "minimizeWindow" in html
|
|
assert "maximizeWindow" in html
|
|
assert "restoreWindow" in html
|
|
assert "initWindowFromSession" in html
|
|
assert "persistWindowSessionState" in html
|
|
|
|
|
|
def test_index_import_window_has_two_column_layout(tmp_path) -> None:
|
|
html = _get_index_html(tmp_path)
|
|
|
|
# Two-column split layout structure
|
|
assert 'class="import-split"' in html
|
|
assert 'class="import-left"' in html
|
|
assert 'class="import-right"' in html
|
|
|
|
# Left column: list header, list, footer
|
|
assert 'class="import-list-header"' in html
|
|
assert 'id="import-items-list"' in html
|
|
assert 'class="import-list-footer"' in html
|
|
assert 'id="pending-count"' in html
|
|
assert 'id="done-count"' in html
|
|
assert 'id="select-all-pending"' in html
|
|
|
|
# Right column: preview
|
|
assert 'id="item-preview"' in html
|
|
|
|
# Action bar
|
|
assert 'class="import-actions"' in html
|
|
assert 'id="generate-cards-btn"' in html
|
|
|
|
# CSS: import-split grid layout
|
|
assert ".import-split" in html
|
|
# CSS: import-item classes
|
|
assert ".import-item" in html
|
|
assert ".import-item.pending" in html
|
|
assert ".import-item.done" in html
|
|
|
|
|
|
def test_index_has_import_state_and_cards_generate_api_calls(tmp_path) -> None:
|
|
html = _get_index_html(tmp_path)
|
|
|
|
# loadImportState function fetches import-state
|
|
assert "function loadImportState()" in html
|
|
assert "/api/projects/" in html
|
|
assert "import-state" in html
|
|
|
|
# generateSelectedCards function calls cards/generate
|
|
assert "function generateSelectedCards()" in html
|
|
assert "/cards/generate" in html
|
|
|
|
# openImportWindow calls loadImportState
|
|
assert "openImportWindow()" in html
|
|
# Check loadImportState is called inside openImportWindow (await statement appears)
|
|
assert "await loadImportState()" in html
|
|
|
|
# generate-cards-btn has click listener for generateSelectedCards
|
|
assert 'generate-cards-btn' in html
|
|
assert 'generateSelectedCards' in html
|