mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-05-26 00:55:16 -07:00
feat(config): reorganize settings window and move annotation colors to subtitleStyle
- Reorganize Configuration window into Appearance, Behavior, Anki, Input, and Integration sections - Add AnkiConnect-backed deck, note-type, and field pickers in the Anki section - Add click-to-learn keybinding controls - Move known-word and N+1 highlight colors to subtitleStyle.knownWordColor / subtitleStyle.nPlusOneColor; legacy ankiConnect.knownWords.color and ankiConnect.nPlusOne.nPlusOne keys still accepted with deprecation warnings - Add deckNames, modelNames, modelFieldNames, and fieldNamesForDeck methods to AnkiConnectClient - Mark discordPresence.presenceStyle as an enum in the config registry
This commit is contained in:
@@ -48,3 +48,78 @@ test('AnkiConnectClient includes action name in retry logs', async () => {
|
||||
console.info = originalInfo;
|
||||
}
|
||||
});
|
||||
|
||||
test('AnkiConnectClient lists decks and note type fields', async () => {
|
||||
const client = new AnkiConnectClient('http://127.0.0.1:8765') as unknown as {
|
||||
client: { post: (url: string, body: { action: string; params: unknown }) => Promise<unknown> };
|
||||
};
|
||||
const calls: Array<{ action: string; params: unknown }> = [];
|
||||
client.client = {
|
||||
post: async (_url, body) => {
|
||||
calls.push({ action: body.action, params: body.params });
|
||||
if (body.action === 'deckNames') {
|
||||
return { data: { result: ['Core', 'Mining'], error: null } };
|
||||
}
|
||||
if (body.action === 'modelNames') {
|
||||
return { data: { result: ['Japanese sentences'], error: null } };
|
||||
}
|
||||
if (body.action === 'modelFieldNames') {
|
||||
return { data: { result: ['Expression', 'Sentence'], error: null } };
|
||||
}
|
||||
return { data: { result: [], error: null } };
|
||||
},
|
||||
};
|
||||
|
||||
const typedClient = client as unknown as AnkiConnectClient;
|
||||
|
||||
assert.deepEqual(await typedClient.deckNames(), ['Core', 'Mining']);
|
||||
assert.deepEqual(await typedClient.modelNames(), ['Japanese sentences']);
|
||||
assert.deepEqual(await typedClient.modelFieldNames('Japanese sentences'), [
|
||||
'Expression',
|
||||
'Sentence',
|
||||
]);
|
||||
assert.deepEqual(
|
||||
calls.map((call) => call.action),
|
||||
['deckNames', 'modelNames', 'modelFieldNames'],
|
||||
);
|
||||
});
|
||||
|
||||
test('AnkiConnectClient derives field names from sampled notes in a deck', async () => {
|
||||
const client = new AnkiConnectClient('http://127.0.0.1:8765') as unknown as {
|
||||
client: { post: (url: string, body: { action: string; params: unknown }) => Promise<unknown> };
|
||||
};
|
||||
const calls: Array<{ action: string; params: unknown }> = [];
|
||||
client.client = {
|
||||
post: async (_url, body) => {
|
||||
calls.push({ action: body.action, params: body.params });
|
||||
if (body.action === 'findNotes') {
|
||||
return { data: { result: [3, 1, 2], error: null } };
|
||||
}
|
||||
if (body.action === 'notesInfo') {
|
||||
return {
|
||||
data: {
|
||||
result: [
|
||||
{ fields: { Sentence: { value: 'x' }, Expression: { value: 'y' } } },
|
||||
{ fields: { Reading: { value: 'z' } } },
|
||||
],
|
||||
error: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
return { data: { result: [], error: null } };
|
||||
},
|
||||
};
|
||||
|
||||
assert.deepEqual(
|
||||
await (client as unknown as AnkiConnectClient).fieldNamesForDeck('Mining "Current"'),
|
||||
['Expression', 'Reading', 'Sentence'],
|
||||
);
|
||||
assert.deepEqual(calls[0], {
|
||||
action: 'findNotes',
|
||||
params: { query: 'deck:"Mining \\"Current\\""' },
|
||||
});
|
||||
assert.deepEqual(calls[1], {
|
||||
action: 'notesInfo',
|
||||
params: { notes: [3, 1, 2] },
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user