from pathlib import Path


ROOT = Path(__file__).resolve().parents[2]
BASE = (ROOT / "engine" / "timesheet" / "templates" / "base.html").read_text(
    encoding="utf-8")
JS = (ROOT / "engine" / "timesheet" / "static" / "operation_busy.js").read_text(
    encoding="utf-8")
CSS = (ROOT / "engine" / "timesheet" / "static" / "app.css").read_text(
    encoding="utf-8")


def test_base_has_accessible_long_operation_overlay():
    assert 'data-operation-overlay' in BASE
    assert 'role="status"' in BASE
    assert 'aria-live="assertive"' in BASE
    assert "operation_busy.js" in BASE
    assert "Дождитесь завершения" in BASE


def test_busy_script_covers_sync_import_and_file_uploads():
    assert 'input[type="file"]' in JS
    assert 'action.indexOf("sync")' in JS
    assert 'action.indexOf("import")' in JS
    assert 'form.dataset.busySubmitted' in JS
    assert 'event.preventDefault()' in JS
    assert 'window.addEventListener("pageshow", clearBusy)' in JS


def test_busy_overlay_is_modal_and_animated():
    assert ".operation-overlay" in CSS
    assert "position: fixed" in CSS
    assert ".operation-spinner" in CSS
    assert "@keyframes operation-spin" in CSS
