Files
odysseus/tests/test_notes_search_reset_on_reopen_js.py
T
Alexandre TeixeiraandLéo f1a47f3812 refactor(notes): decompose Notes into feature-owned modules (#6713)
* refactor(notes): decompose Notes into feature-owned modules

* fix(notes): avoid HTML interpolation in reminder picker

* docs(notes): drop checkpoint archives, session logs and publication drafts

The N0-N6 tarballs and raw pytest/node logs are not read by any script or
test, and the logs carry absolute home-directory paths. Once squashed into
dev they would stay in history for good. notes-pr.md and notes-issue.md
were the drafts used to open #6712 and #6713, not documentation.

notes-validation.md keeps the counts, the checkpoint hashes and
implementation.sha256 as the record; local interpreter paths and the local
Docker image name are replaced with portable placeholders.

* fix(notes): keep the state store raw and stop masonry re-observing after close

- state: writes built from views (filter, spread, splice) stored nested
  read-only views in the store, so structuredClone on a stored note threw
  DataCloneError. Store writes now unwrap nested views.
- layout: a save that resolves after closePanel re-renders the leaving pane
  and re-created the masonry ResizeObserver that teardown had disposed.
  Skip creating it once Notes is closed.
- index.js: drop 30 imported or declared names that were never used and
  group the imports at the top. Import order is unchanged.
- Revert unrelated punctuation edits in .gitattributes and keep the header
  comment and docstring first in compare/vote.js and
  test_notes_dom_xss_helpers.py.

Both fixes have a node test that fails on the previous head.

* test(notes): make script rejection assertion case-insensitive

Address CodeQL js/bad-tag-filter alert #1150 in test-only assertion and refresh Notes evidence manifest checksum.

---------

Co-authored-by: Léo <leograndcontact@gmail.com>
2026-10-15 09:29:41 +01:00

66 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Issue #2919 — openPanel must reset _searchQuery so a reopened Notes panel
doesn't keep filtering by a stale query (the rebuilt search box renders empty).
notes.js is a browser ES module with a heavy import chain (can't node-import in
isolation), so — per the repo's DOM-coupled-guard convention — this asserts the
reset is present in openPanel, beside the existing _editingId reset.
"""
import re
from pathlib import Path
from tests.helpers.notes_source import notes_source
SRC = notes_source("ui/panel", "ui/filters", "ui/cardRendering", "ui/cardInteractions", "ui/drawing", "infrastructure/storage", "application/state", "ui/toolbar")
def _open_panel_body():
start = SRC.index("function openPanel()")
rest = SRC[start + len("function openPanel()"):]
m = re.search(r"\n\s*(?:export\s+)?(?:async\s+)?function ", rest)
return rest[: m.start()] if m else rest
def test_open_panel_resets_search_query():
body = _open_panel_body()
assert "app.setSearchQuery('')" in body, body[:400]
# reset must sit with the other open-time state resets, before render
assert body.index("app.setSearchQuery('')") < body.index("_renderNotes") if "_renderNotes" in body else True
def test_module_still_declares_search_query():
assert "searchQuery: ''" in SRC
def test_notes_label_chips_can_be_collapsed_like_calendar_tags():
assert "NOTES_LABELS_COLLAPSED_KEY = 'odysseus-notes-labels-collapsed'" in SRC
assert "app.setLabelsCollapsed(!state.labelsCollapsed)" in SRC
assert "persistence.setItem(NOTES_LABELS_COLLAPSED_KEY" in SRC
assert "toggle.textContent = state.labelsCollapsed ? '+ Tags' : '− Tags';" in SRC
assert "bar.style.display = 'none';" in SRC
def test_notes_tag_toggle_sits_in_search_toolbar_before_select():
assert "const toggleHost = pane?.querySelector('.notes-search-bar') || _body;" in SRC
assert "const selectButton = toggleHost.querySelector('#notes-select-btn');" in SRC
assert "toggleHost.insertBefore(toggle, selectButton || null);" in SRC
def test_expanded_tags_strip_hides_when_no_useful_filters_exist():
assert "const hasUsefulFilters = sortedLabels.length > 0 || reminderCount > 0 || goalCount > 0;" in SRC
assert "if (!hasUsefulFilters && !hasActiveFilter)" in SRC
assert "bar.style.display = 'none';" in SRC
def test_drawing_preview_opens_its_note_editor():
assert "note.note_type === 'draw' ? ' note-card-drawing' : ''" in SRC
assert "body.querySelectorAll('.note-card-drawing .note-card-image')" in SRC
assert "tapToEditOrSelect(el.closest('.note-card'))" in SRC
def test_drawing_defaults_follow_theme_surface_and_highlight():
assert "const surfaceColor = resolveThemeColor('var(--panel, var(--bg))'" in SRC
assert "resolveThemeColor('var(--accent, var(--red))'" in SRC
assert "if (colorInput) colorInput.value = highlightColor;" in SRC
assert "ctx.strokeStyle = erasing ? surfaceColor" in SRC
assert "destination-out" not in SRC