文件
mynode/packages/app-mobile/components/screens/encryption-config.test.tsx
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

74 行
2.6 KiB
TypeScript

import * as React from 'react';
import { Store } from 'redux';
import { AppState } from '../../utils/types';
import TestProviderStack from '../testing/TestProviderStack';
import EncryptionConfig from './encryption-config';
import { loadEncryptionMasterKey, setupDatabaseAndSynchronizer, switchClient, synchronizerStart } from '@joplin/lib/testing/test-utils';
import createMockReduxStore from '../../utils/testing/createMockReduxStore';
import setupGlobalStore from '../../utils/testing/setupGlobalStore';
import { getActiveMasterKeyId, setEncryptionEnabled, setMasterKeyEnabled } from '@joplin/lib/services/synchronizer/syncInfoUtils';
import { act, render, screen } from '../../utils/testing/testingLibrary';
interface WrapperProps { }
let store: Store<AppState>;
const WrappedEncryptionConfigScreen: React.FC<WrapperProps> = _props => {
return <TestProviderStack store={store}>
<EncryptionConfig/>
</TestProviderStack>;
};
describe('encryption-config', () => {
beforeEach(async () => {
await setupDatabaseAndSynchronizer(1);
await setupDatabaseAndSynchronizer(0);
await switchClient(0);
setEncryptionEnabled(true);
await loadEncryptionMasterKey();
store = createMockReduxStore();
setupGlobalStore(store);
});
afterEach(() => {
screen.unmount();
});
test('should show an input for entering the master password after an initial sync', async () => {
// Switch to the other client and sync so that there's a master key missing
// a password
await synchronizerStart();
await switchClient(1);
await synchronizerStart();
const { unmount } = render(<WrappedEncryptionConfigScreen/>);
// Should auto-enable encryption
expect(screen.getByText('Encryption is: Enabled')).toBeVisible();
const passwordInput = screen.getByLabelText(/The master password is not set/);
expect(passwordInput).toBeVisible();
// Unmount here to prevent "An update to EncryptionConfigScreen inside a test was not wrapped in act(...)"
// errors
unmount();
});
test('should not show the "disabled keys" dropdown unless there are disabled keys', async () => {
const masterKeyId = getActiveMasterKeyId();
setMasterKeyEnabled(masterKeyId, false);
const { unmount } = render(<WrappedEncryptionConfigScreen/>);
const queryDisabledKeysButton = () => screen.queryByRole('button', { name: 'Disabled keys' });
// Should be visible when there are disabled keys
expect(queryDisabledKeysButton()).toBeVisible();
// Enabling the key should hide the button
act(() => setMasterKeyEnabled(masterKeyId, true));
expect(queryDisabledKeysButton()).toBeNull();
unmount();
});
});