mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-06-12 15:13:32 -07:00
feat: use cached annotations on subtitle change and skip pre-warmed cues (#97)
This commit is contained in:
@@ -19,6 +19,7 @@ interface IntegrationTestContext {
|
||||
function createIntegrationTestContext(
|
||||
options: {
|
||||
highlightEnabled?: boolean;
|
||||
nPlusOneEnabled?: boolean;
|
||||
onFindNotes?: () => Promise<number[]>;
|
||||
onNotesInfo?: () => Promise<unknown[]>;
|
||||
stateDirPrefix?: string;
|
||||
@@ -59,6 +60,12 @@ function createIntegrationTestContext(
|
||||
knownWords: {
|
||||
highlightEnabled: options.highlightEnabled ?? true,
|
||||
},
|
||||
nPlusOne:
|
||||
options.nPlusOneEnabled === undefined
|
||||
? undefined
|
||||
: {
|
||||
enabled: options.nPlusOneEnabled,
|
||||
},
|
||||
},
|
||||
{} as never,
|
||||
{} as never,
|
||||
@@ -161,6 +168,47 @@ test('AnkiIntegration.refreshKnownWordCache bypasses stale checks', async () =>
|
||||
}
|
||||
});
|
||||
|
||||
test('AnkiIntegration.refreshKnownWordCache notifies annotation cache listeners', async () => {
|
||||
const ctx = createIntegrationTestContext({
|
||||
stateDirPrefix: 'subminer-anki-integration-refresh-notify-',
|
||||
});
|
||||
let notifications = 0;
|
||||
|
||||
try {
|
||||
ctx.integration.setKnownWordCacheUpdatedCallback(() => {
|
||||
notifications += 1;
|
||||
});
|
||||
|
||||
await ctx.integration.refreshKnownWordCache();
|
||||
|
||||
assert.equal(notifications, 1);
|
||||
} finally {
|
||||
cleanupIntegrationTestContext(ctx);
|
||||
}
|
||||
});
|
||||
|
||||
test('AnkiIntegration.refreshKnownWordCache notifies when n+1 is enabled without highlights', async () => {
|
||||
const ctx = createIntegrationTestContext({
|
||||
highlightEnabled: false,
|
||||
nPlusOneEnabled: true,
|
||||
stateDirPrefix: 'subminer-anki-integration-nplusone-notify-',
|
||||
});
|
||||
let notifications = 0;
|
||||
|
||||
try {
|
||||
ctx.integration.setKnownWordCacheUpdatedCallback(() => {
|
||||
notifications += 1;
|
||||
});
|
||||
|
||||
await ctx.integration.refreshKnownWordCache();
|
||||
|
||||
assert.equal(ctx.calls.findNotes, 1);
|
||||
assert.equal(notifications, 1);
|
||||
} finally {
|
||||
cleanupIntegrationTestContext(ctx);
|
||||
}
|
||||
});
|
||||
|
||||
test('AnkiIntegration.refreshKnownWordCache skips work when highlight mode is disabled', async () => {
|
||||
const ctx = createIntegrationTestContext({
|
||||
highlightEnabled: false,
|
||||
|
||||
Reference in New Issue
Block a user