fix(character-dictionary): normalize fallback titles and wire close button

- Trim blank fallback titles in toAniListMediaCandidate; fall back to
  \"AniList <id>\" when all title fields and the fallback string are empty
- Add fetch unit test covering the trimmed-fallback path
- Extract wireDomEvents from createCharacterDictionaryModal so event
  listeners are bound explicitly after construction
- Call wireDomEvents in renderer init alongside other modal wiring
- Extend modal test to cover close-button click dismissing the modal
This commit is contained in:
2026-04-25 20:03:51 -07:00
parent 992856ac5e
commit ba48db6255
5 changed files with 49 additions and 4 deletions

View File

@@ -0,0 +1,29 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { searchAniListMediaCandidates } from './fetch';
test('searchAniListMediaCandidates trims fallback candidate titles', async () => {
const previousFetch = globalThis.fetch;
Object.defineProperty(globalThis, 'fetch', {
configurable: true,
value: async () =>
new Response(
JSON.stringify({
data: {
Page: {
media: [{ id: 21355, episodes: 25, title: {} }],
},
},
}),
),
});
try {
const candidates = await searchAniListMediaCandidates(' Re:ZERO ');
assert.equal(candidates[0]?.title, 'Re:ZERO');
} finally {
Object.defineProperty(globalThis, 'fetch', { configurable: true, value: previousFetch });
}
});