一些检查失败了
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
52 行
1.8 KiB
TypeScript
52 行
1.8 KiB
TypeScript
import * as React from 'react';
|
|
import { Store } from 'redux';
|
|
import { AppState } from '../../../utils/types';
|
|
import TestProviderStack from '../../testing/TestProviderStack';
|
|
import NoteLockConfig from './NoteLockConfig';
|
|
import { setupDatabaseAndSynchronizer, switchClient } from '@joplin/lib/testing/test-utils';
|
|
import createMockReduxStore from '../../../utils/testing/createMockReduxStore';
|
|
import setupGlobalStore from '../../../utils/testing/setupGlobalStore';
|
|
import NoteLockKey from '@joplin/lib/services/noteLock/NoteLockKey';
|
|
import { MasterKeyEntity } from '@joplin/lib/services/e2ee/types';
|
|
import { act, render, screen } from '../../../utils/testing/testingLibrary';
|
|
|
|
let store: Store<AppState>;
|
|
const WrappedNoteLockConfig: React.FC = () => {
|
|
return <TestProviderStack store={store}>
|
|
<NoteLockConfig/>
|
|
</TestProviderStack>;
|
|
};
|
|
|
|
describe('NoteLockConfig', () => {
|
|
beforeEach(async () => {
|
|
await setupDatabaseAndSynchronizer(0);
|
|
await switchClient(0);
|
|
NoteLockKey.destroyInstance();
|
|
|
|
store = createMockReduxStore();
|
|
setupGlobalStore(store);
|
|
});
|
|
afterEach(() => {
|
|
screen.unmount();
|
|
});
|
|
|
|
test('should show the password setup form only while no note lock key is set', async () => {
|
|
const { unmount } = render(<WrappedNoteLockConfig/>);
|
|
|
|
expect(screen.getByText('Password setup')).toBeVisible();
|
|
expect(screen.getByLabelText('Password')).toBeVisible();
|
|
|
|
// Seed the key via save() rather than create(): the mobile test crypto shim can't
|
|
// run real key generation.
|
|
act(() => {
|
|
NoteLockKey.instance().save({ id: 'test-note-lock-key' } as MasterKeyEntity);
|
|
});
|
|
|
|
expect(screen.queryByText('Password setup')).toBeNull();
|
|
expect(screen.queryByLabelText('Password')).toBeNull();
|
|
expect(screen.getByText(/Note lock password:.*Set/)).toBeVisible();
|
|
|
|
unmount();
|
|
});
|
|
});
|