Skip to content

test: add e2e coverage for editor add context switching#5078

Open
fernandolins wants to merge 8 commits into
test/e2e-editor-suitefrom
test/e2e-context-switching
Open

test: add e2e coverage for editor add context switching#5078
fernandolins wants to merge 8 commits into
test/e2e-editor-suitefrom
test/e2e-context-switching

Conversation

@fernandolins

@fernandolins fernandolins commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Linked issue

Closes #4948

Summary / motivation

Adds Playwright e2e coverage for Add-mode context switching in the Svelte editor, as requested in #4948.

The goal is to verify parity with the Qt editor: when a user changes the notetype and/or deck while adding cards, that context should be used for the note being added and should remain selected when Add mode is opened again.

What is tested

Chooser UI and payload correctness

  • Switching notetype reloads the editor fields via the Svelte path
  • Switching deck sends addNote with the selected deckId
  • Switching both sends both selected IDs in the payload

Context persistence (issue #4948)

  • Selected notetype + deck persist as context for the next note after add
  • Reopening Add mode restores the last used notetype + deck

Mode B: notetype drives deck selection (addToCur = false)

  • Switching notetype auto-selects the last deck used with that notetype
  • Notetype with no lastDeck falls back to the collection's current deck
  • Deleted lastDeck is ignored and the current deck is used instead

Mode A: current deck drives notetype selection (addToCur = true)

  • Switching notetype does NOT auto-update the deck chooser
  • Last notetype used for the current deck is restored on reopen
  • Deck with no lastNotetype falls back to the global current notetype

Test environment fix

A fresh Anki collection defaults to Mode A (addToCur = true per schema11). The previous tests ran under Mode A without realising it, which caused defaultsForAdding to use the wrong logic for Mode B assertions. The beforeEach now explicitly sets addToCur = false (Mode B) so all tests share a known baseline; Mode A tests re-enable it in their body and restore it in finally.

Config manipulation uses setConfigJson, the only config-write RPC exposed by the editor's mediasrv (setConfigBool/setCurrentDeck/removeConfig are not in the exposed_backend_list).

How to test

just test-e2e

All context-switching tests pass. The only known failure is a pre-existing gap in paste-filter.spec.ts (pasted <script> contents are discarded instead of becoming visible text), which is unrelated to this PR.

Before / after behavior

Before: no e2e coverage for Add-mode deck/notetype context switching; test environment was silently running under Mode A, masking Mode B assertions.

After: all branches of rslib/src/adding.rs reachable from the editor are covered, and the test environment correctly isolates each mode.

@fernandolins fernandolins requested a review from abdnh June 30, 2026 14:10
@read-the-docs-community

read-the-docs-community Bot commented Jun 30, 2026

Copy link
Copy Markdown

@abdnh

abdnh commented Jul 1, 2026

Copy link
Copy Markdown
Member

That failure confirms the Svelte editor does not currently preserve the Add-mode context after reopen.

The behavior here depends on the selected deck (which is the "Default" deck by default), so the test should make a request to change the deck to confirm the correct behavior. We should have more tests here to cover all cases (See rslib/src/adding.rs).

…back

- Rename "notetype persists" test to "notetype and deck persist" and
  switch the add to use TEST_DECK instead of Default so the assertion
  exercises the real _nt_{ntid}_lastDeck persistence path rather than
  the trivially-satisfied Default fallback.

- Add setConfigJson helper and force Mode B (addToCur=false) in
  beforeEach: fresh Anki collections default to Mode A (addToCur=true
  per schema11), which caused all Mode B assertions to silently pass
  or fail against the wrong code path.

- Add test: mode B session — switching notetype auto-selects the last
  deck used with that notetype (onNotetypeChange → defaultDeckForNotetype
  → deckChooser.select, no user interaction required).

- Add test: mode A reopen — last notetype used for the current deck is
  restored via _deck_{did}_lastNotetype.

- Add test: mode B fallback (no history) — when _nt_{ntid}_lastDeck is
  absent or points to a deleted deck, defaults_for_adding falls back to
  the collection's curDeck, not Default.

- Add test: mode A fallback — when _deck_{did}_lastNotetype is absent,
  default_notetype_for_deck falls back to get_current_notetype_for_adding.

All branches of rslib/src/adding.rs are now covered.
Add set_config_bool, set_config_json_no_undo, remove_config and
set_current_deck to the exposed_backend_list so they are reachable
via /_anki/{method} from the web layer.

These RPCs are already defined in the proto and have _raw variants in
the backend; exposing them is consistent with the existing set_config_json
and get_config_bool entries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants