Files
odysseus/tests/test_document_stats.py
T
Léo e3eb7137b7 refactor(css): move document, gallery and image-editor styles to their own file
static/style.css is 51,425 lines and holds every panel's styles, so two
people working on unrelated panels still edit the same file. This is the
first of three steps that give each panel group its own stylesheet. It moves
the document library, image gallery and image editor rules that can move
into static/css/documents-gallery-editor.css.

The new file is loaded eagerly from index.html immediately after style.css,
so the cascade is the concatenation of the two in that order, which is the
order those rules already had. Nothing is deferred and nothing renders
differently.

Rules moved verbatim. A rule stays in style.css when its selector group
covers more than one panel, when the class is shared design language used
from modules outside the panel, or when moving it would flip which of two
equally specific rules wins on an element the markup puts both classes on.
That last rule is what keeps this change small: most panel-prefixed rules on
this branch compete with a shared component rule somewhere later in the file.

Nineteen tests read static/style.css directly and go red the moment a rule
they assert on moves, which says nothing about the page. They now go through
tests/helpers/stylesheets.app_css(), which concatenates the stylesheets in
the order index.html loads them. The helper also exposes the <link> markup
for tests that build a synthetic page through Playwright.
2026-09-23 16:12:51 +02:00

61 lines
2.0 KiB
Python

"""Behavioral and integration coverage for document editor statistics."""
import json
import subprocess
from pathlib import Path
from tests.helpers.stylesheets import app_css
ROOT = Path(__file__).resolve().parents[1]
DOC_JS = (ROOT / "static/js/document.js").read_text(encoding="utf-8")
STYLE = app_css()
def _run_stats(expression: str):
script = f"""
import {{ getDocumentStats, countDocumentWords, countDocumentCharacters }}
from './static/js/documentStats.js';
console.log(JSON.stringify({expression}));
"""
result = subprocess.run(
["node", "--input-type=module", "-e", script],
cwd=ROOT,
check=True,
capture_output=True,
text=True,
)
return json.loads(result.stdout)
def test_stats_count_words_lines_characters_and_reading_time():
assert _run_stats("getDocumentStats('Hello, world!\\nSecond line.')") == {
"words": 4,
"characters": 26,
"charactersNoSpaces": 23,
"lines": 2,
"readingMinutes": 1,
}
def test_stats_are_unicode_word_and_grapheme_aware():
result = _run_stats("({ japanese: countDocumentWords('これはテストです'), emoji: countDocumentCharacters('A 👨‍👩‍👧‍👦') })")
assert result["japanese"] > 1
assert result["emoji"] == 3
def test_stats_footer_is_selection_aware_in_both_editors():
assert "_normalizeRichStatsText(selection.toString()), selected: true" in DOC_JS
assert ".replace(/\\n{2,}/gu, '\\n')" in DOC_JS
assert "textarea.value.slice(start, end), selected: true" in DOC_JS
assert "source.selected ? 'Selection' : 'Document'" in DOC_JS
assert "ta.addEventListener(eventName, _scheduleDocumentStats);" in DOC_JS
assert "_scheduleDocumentStats();" in DOC_JS
def test_stats_popover_is_compact_on_mobile():
assert 'id="doc-stats-popover"' in DOC_JS
assert ".doc-stats-wrap" in STYLE
assert "#doc-actions-footer .doc-stats-unit { display: none; }" in STYLE
assert ".doc-stats-popover[hidden] { display: none; }" in STYLE