test: add e2e coverage for editor add context switching#5078
Open
fernandolins wants to merge 8 commits into
Open
test: add e2e coverage for editor add context switching#5078fernandolins wants to merge 8 commits into
fernandolins wants to merge 8 commits into
Conversation
Documentation build overview
18 files changed ·
|
Member
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.
…o test/e2e-context-switching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
addNotewith the selecteddeckIdContext persistence (issue #4948)
Mode B: notetype drives deck selection (
addToCur = false)lastDeckfalls back to the collection's current decklastDeckis ignored and the current deck is used insteadMode A: current deck drives notetype selection (
addToCur = true)lastNotetypefalls back to the global current notetypeTest environment fix
A fresh Anki collection defaults to Mode A (
addToCur = trueper schema11). The previous tests ran under Mode A without realising it, which causeddefaultsForAddingto use the wrong logic for Mode B assertions. ThebeforeEachnow explicitly setsaddToCur = false(Mode B) so all tests share a known baseline; Mode A tests re-enable it in their body and restore it infinally.Config manipulation uses
setConfigJson, the only config-write RPC exposed by the editor's mediasrv (setConfigBool/setCurrentDeck/removeConfigare not in theexposed_backend_list).How to test
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.rsreachable from the editor are covered, and the test environment correctly isolates each mode.