Files
noteflow/client/e2e-native/settings.spec.ts
2026-01-14 23:23:01 -05:00

304 lines
9.5 KiB
TypeScript

/**
* Settings & Preferences E2E Tests
*
* Tests for preferences, triggers, and cloud consent.
*/
/// <reference path="./globals.d.ts" />
import { waitForAppReady } from './fixtures';
describe('User Preferences', () => {
before(async () => {
await waitForAppReady();
});
describe('getPreferences', () => {
it('should retrieve user preferences', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
const prefs = await api?.getPreferences();
return { success: true, prefs };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result.success).toBe(true);
expect(result.prefs).toBeDefined();
expect(result.prefs).toHaveProperty('default_export_format');
});
it('should have expected preference structure', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
const prefs = await api?.getPreferences();
return {
hasAiConfig: prefs && 'ai_config' in prefs,
hasAiTemplate: prefs && 'ai_template' in prefs,
hasAudioDevices: prefs && 'audio_devices' in prefs,
hasExportFormat: prefs && 'default_export_format' in prefs,
hasIntegrations: prefs && 'integrations' in prefs,
};
});
expect(result.hasAiConfig).toBe(true);
expect(result.hasAiTemplate).toBe(true);
expect(result.hasAudioDevices).toBe(true);
expect(result.hasExportFormat).toBe(true);
expect(result.hasIntegrations).toBe(true);
});
});
describe('savePreferences', () => {
it('should save and persist preferences', async () => {
// Get current prefs
const original = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
return await api?.getPreferences();
});
// Modify and save
const result = await browser.execute(async (prefs) => {
const api = window.__NOTEFLOW_API__;
try {
const modified = {
...prefs,
default_export_format:
prefs?.default_export_format === 'markdown' ? 'html' : 'markdown',
};
await api?.savePreferences(modified);
return { success: true };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
}, original);
expect(result.success).toBe(true);
// Verify change
const updated = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
return await api?.getPreferences();
});
expect(updated?.default_export_format).not.toBe(original?.default_export_format);
// Restore original
await browser.execute(async (prefs) => {
const api = window.__NOTEFLOW_API__;
await api?.savePreferences(prefs);
}, original);
});
it('should save AI template settings', async () => {
const original = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
return await api?.getPreferences();
});
const result = await browser.execute(async (prefs) => {
const api = window.__NOTEFLOW_API__;
try {
const modified = {
...prefs,
ai_template: {
tone: 'professional',
format: 'bullet_points',
verbosity: 'balanced',
},
};
await api?.savePreferences(modified);
const saved = await api?.getPreferences();
return { success: true, saved };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
}, original);
expect(result.success).toBe(true);
if (result.saved?.ai_template) {
expect(result.saved.ai_template.tone).toBe('professional');
}
// Restore original
await browser.execute(async (prefs) => {
const api = window.__NOTEFLOW_API__;
await api?.savePreferences(prefs);
}, original);
});
});
});
describe('Cloud Consent', () => {
before(async () => {
await waitForAppReady();
});
describe('getCloudConsentStatus', () => {
it('should return consent status', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
const status = await api?.getCloudConsentStatus();
return { success: true, status };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result.success).toBe(true);
expect(result.status).toHaveProperty('consentGranted');
expect(typeof result.status?.consentGranted).toBe('boolean');
});
});
describe('grantCloudConsent', () => {
it('should grant cloud consent', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
await api?.grantCloudConsent();
const status = await api?.getCloudConsentStatus();
return { success: true, granted: status?.consentGranted };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result.success).toBe(true);
expect(result.granted).toBe(true);
});
});
describe('revokeCloudConsent', () => {
it('should revoke cloud consent', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
await api?.revokeCloudConsent();
const status = await api?.getCloudConsentStatus();
return { success: true, granted: status?.consentGranted };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result.success).toBe(true);
expect(result.granted).toBe(false);
});
});
});
describe('Trigger Settings', () => {
before(async () => {
await waitForAppReady();
});
describe('getTriggerStatus', () => {
it('should return trigger status', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
const status = await api?.getTriggerStatus();
return { success: true, status };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result.success).toBe(true);
expect(result.status).toHaveProperty('enabled');
expect(result.status).toHaveProperty('is_snoozed');
});
});
describe('setTriggerEnabled', () => {
it('should enable triggers', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
await api?.setTriggerEnabled(true);
const status = await api?.getTriggerStatus();
return { success: true, enabled: status?.enabled };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result.success).toBe(true);
expect(result.enabled).toBe(true);
});
it('should disable triggers', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
await api?.setTriggerEnabled(false);
const status = await api?.getTriggerStatus();
return { success: true, enabled: status?.enabled };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result.success).toBe(true);
expect(result.enabled).toBe(false);
});
});
describe('snoozeTriggers', () => {
it('should snooze triggers for specified minutes', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
await api?.snoozeTriggers(15);
const status = await api?.getTriggerStatus();
return { success: true, snoozed: status?.is_snoozed };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result.success).toBe(true);
expect(result.snoozed).toBe(true);
});
});
describe('resetSnooze', () => {
it('should reset snooze', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
await api?.resetSnooze();
const status = await api?.getTriggerStatus();
return { success: true, snoozed: status?.is_snoozed };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
expect(result.success).toBe(true);
expect(result.snoozed).toBe(false);
});
});
describe('dismissTrigger', () => {
it('should dismiss active trigger', async () => {
const result = await browser.execute(async () => {
const api = window.__NOTEFLOW_API__;
try {
await api?.dismissTrigger();
return { success: true };
} catch (e) {
return { success: false, error: e instanceof Error ? e.message : String(e) };
}
});
// Should not throw even if no active trigger
expect(result).toBeDefined();
});
});
});