diff --git a/injected/integration-test/duck-ai-data-clearing.spec.js b/injected/integration-test/duck-ai-data-clearing.spec.js index b740b79e11..eff5cafff4 100644 --- a/injected/integration-test/duck-ai-data-clearing.spec.js +++ b/injected/integration-test/duck-ai-data-clearing.spec.js @@ -4,6 +4,22 @@ import { ResultsCollector } from './page-objects/results-collector.js'; const HTML = '/duck-ai-data-clearing/index.html'; const CONFIG = './integration-test/test-pages/duck-ai-data-clearing/config/enabled.json'; +test('duck-ai-data-clearing feature is ready', async ({ page }, testInfo) => { + const collector = ResultsCollector.create(page, testInfo.project.use); + collector.withUserPreferences({ + messageSecret: 'ABC', + javascriptInterface: 'javascriptInterface', + messageCallback: 'messageCallback', + }); + await collector.load(HTML, CONFIG); + + // Wait for completion message + const messages = await collector.waitForMessage('duckAiClearDataReady', 1); + + expect(messages).toHaveLength(1); + expect(messages[0].payload.method).toBe('duckAiClearDataReady'); +}); + test('duck-ai-data-clearing feature clears localStorage and IndexedDB', async ({ page }, testInfo) => { const collector = ResultsCollector.create(page, testInfo.project.use); collector.withUserPreferences({ diff --git a/injected/src/features/duck-ai-data-clearing.js b/injected/src/features/duck-ai-data-clearing.js index 7b38dab945..799ed1284b 100644 --- a/injected/src/features/duck-ai-data-clearing.js +++ b/injected/src/features/duck-ai-data-clearing.js @@ -9,17 +9,19 @@ import ContentFeature from '../content-feature.js'; export class DuckAiDataClearing extends ContentFeature { init() { this.messaging.subscribe('duckAiClearData', (_) => this.clearData()); + + this.notify('duckAiClearDataReady'); } async clearData() { - let success = true; + let lastError = null; const localStorageKeys = this.getFeatureSetting('chatsLocalStorageKeys'); for (const localStorageKey of localStorageKeys) { try { this.clearSavedAIChats(localStorageKey); } catch (error) { - success = false; + lastError = error; this.log.error('Error clearing saved chats:', error); } } @@ -29,15 +31,17 @@ export class DuckAiDataClearing extends ContentFeature { try { await this.clearChatImagesStore(indexDbName, objectStoreName); } catch (error) { - success = false; + lastError = error; this.log.error('Error clearing saved chat images:', error); } } - if (success) { + if (lastError === null) { this.notify('duckAiClearDataCompleted'); } else { - this.notify('duckAiClearDataFailed'); + this.notify('duckAiClearDataFailed', { + error: lastError?.message, + }); } }