feat(webui): add developer settings tools
Expose onboarding replay and page crash testing from a dedicated settings page.\n\nKeep replay actions isolated from persisted consent and password state.
This commit is contained in:
11 files changed
+365
-29
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
DEVELOPER_CRASH_MESSAGE,
|
||||
DeveloperCrashProbe,
|
||||
developerCrashReducer,
|
||||
} from '../src/components/settings/developer-tools';
|
||||
import { ErrorPage } from '../src/components/pages/status-screens';
|
||||
import { SETTINGS_TABS } from '../src/router';
|
||||
|
||||
describe('developer settings tools', () => {
|
||||
it('keeps the developer page in the public settings route contract', () => {
|
||||
expect(SETTINGS_TABS).toContain('developer');
|
||||
});
|
||||
|
||||
it('promotes a confirmed crash into the route error screen', () => {
|
||||
const requested = developerCrashReducer(false, 'confirm');
|
||||
expect(() => renderToStaticMarkup(
|
||||
<DeveloperCrashProbe requested={requested} />,
|
||||
)).toThrowError(DEVELOPER_CRASH_MESSAGE);
|
||||
|
||||
const html = renderToStaticMarkup(
|
||||
<ErrorPage error={new Error(DEVELOPER_CRASH_MESSAGE)} reset={() => undefined} />,
|
||||
);
|
||||
expect(html).toContain('页面出错了');
|
||||
expect(html).toContain('重试');
|
||||
expect(html).toContain(DEVELOPER_CRASH_MESSAGE);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { onboardingExecution } from '../src/lib/onboarding-actions';
|
||||
|
||||
describe('developer onboarding rehearsal', () => {
|
||||
it('completes consent and password steps without writing persistent state', async () => {
|
||||
const acceptAgreements = vi.fn(async () => ({ success: true }));
|
||||
const changePassword = vi.fn(async () => ({ success: true }));
|
||||
const execution = onboardingExecution(true, {
|
||||
acceptAgreements,
|
||||
changePassword,
|
||||
});
|
||||
|
||||
expect(execution.passwordMode).toBe('rehearsal');
|
||||
await expect(execution.actions.acceptAgreements()).resolves.toEqual({ success: true });
|
||||
await expect(execution.actions.changePassword('old', 'new')).resolves.toEqual({ success: true });
|
||||
expect(acceptAgreements).not.toHaveBeenCalled();
|
||||
expect(changePassword).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('keeps real onboarding wired to persistent actions', async () => {
|
||||
const acceptAgreements = vi.fn(async () => ({ success: true }));
|
||||
const changePassword = vi.fn(async () => ({ success: true }));
|
||||
const execution = onboardingExecution(false, {
|
||||
acceptAgreements,
|
||||
changePassword,
|
||||
});
|
||||
|
||||
expect(execution.passwordMode).toBe('change');
|
||||
await execution.actions.acceptAgreements();
|
||||
await execution.actions.changePassword('old', 'new');
|
||||
expect(acceptAgreements).toHaveBeenCalledOnce();
|
||||
expect(changePassword).toHaveBeenCalledWith('old', 'new');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
browserPath,
|
||||
DEVELOPER_ONBOARDING_RETURN_KEY,
|
||||
developerOnboardingReturnPath,
|
||||
isDeveloperOnboardingLocation,
|
||||
} from '../src/lib/onboarding-navigation';
|
||||
|
||||
describe('developer onboarding navigation', () => {
|
||||
it('recognizes only the dedicated developer replay URL', () => {
|
||||
expect(isDeveloperOnboardingLocation({
|
||||
pathname: '/onboarding',
|
||||
search: '?mode=developer',
|
||||
})).toBe(true);
|
||||
expect(isDeveloperOnboardingLocation({ pathname: '/onboarding', search: '' })).toBe(false);
|
||||
expect(isDeveloperOnboardingLocation({
|
||||
pathname: '/settings',
|
||||
search: '?mode=developer',
|
||||
})).toBe(false);
|
||||
});
|
||||
|
||||
it('preserves the complete local return path', () => {
|
||||
expect(browserPath({
|
||||
pathname: '/settings',
|
||||
search: '?tab=developer',
|
||||
hash: '#tools',
|
||||
})).toBe('/settings?tab=developer#tools');
|
||||
});
|
||||
|
||||
it('accepts only local non-onboarding return paths from history state', () => {
|
||||
expect(developerOnboardingReturnPath({
|
||||
[DEVELOPER_ONBOARDING_RETURN_KEY]: '/settings?tab=developer',
|
||||
})).toBe('/settings?tab=developer');
|
||||
expect(developerOnboardingReturnPath({
|
||||
[DEVELOPER_ONBOARDING_RETURN_KEY]: 'https://example.com',
|
||||
})).toBeNull();
|
||||
expect(developerOnboardingReturnPath({
|
||||
[DEVELOPER_ONBOARDING_RETURN_KEY]: '//example.com',
|
||||
})).toBeNull();
|
||||
expect(developerOnboardingReturnPath({
|
||||
[DEVELOPER_ONBOARDING_RETURN_KEY]: '/onboarding?mode=developer',
|
||||
})).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user