文件
mynode/packages/app-mobile/commands/newNote.test.ts
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

50 行
2.0 KiB
TypeScript

import NavService from '@joplin/lib/services/NavService';
import { runtime } from './newNote';
import { setupDatabaseAndSynchronizer, switchClient } from '@joplin/lib/testing/test-utils';
import Note from '@joplin/lib/models/Note';
import Folder from '@joplin/lib/models/Folder';
import Setting from '@joplin/lib/models/Setting';
describe('newNote', () => {
beforeEach(async () => {
await setupDatabaseAndSynchronizer(1);
await switchClient(1);
});
test.each([
[null, null],
['order', true],
['order', false],
])('should create and navigate to a new note', async (sortOrderField: string, sortOrderReverse: boolean) => {
const dispatchMock = jest.fn();
NavService.dispatch = dispatchMock;
// The command needs an active folder ID.
const activeFolder = await Folder.save({ title: 'folder' });
const initialNote = await Note.save({ title: 'test', parent_id: activeFolder.id });
Setting.setValue('activeFolderId', activeFolder.id);
Setting.setValue('notes.sortOrder.field', sortOrderField);
Setting.setValue('notes.sortOrder.reverse', sortOrderReverse);
await runtime().execute(null, 'test note', true);
expect(dispatchMock).toHaveBeenCalledTimes(1);
// Correct note should have been created
const noteId = dispatchMock.mock.lastCall[0].noteId;
const newNote = await Note.load(noteId);
expect(newNote.body).toEqual('test note');
expect(newNote.parent_id).toEqual(activeFolder.id);
if (sortOrderField === 'order' && !!sortOrderReverse) {
expect(newNote.order).toBeGreaterThanOrEqual(initialNote.order + Note.defaultIntevalBetweenNotes);
} else if (sortOrderField === 'order' && !sortOrderReverse) {
expect(newNote.order).toBeLessThanOrEqual(initialNote.order - Note.defaultIntevalBetweenNotes);
} else {
expect(newNote.order).toBeLessThan(initialNote.order + Note.defaultIntevalBetweenNotes);
}
// Should have tried to navigate to the note.
expect(dispatchMock.mock.lastCall).toMatchObject([
{ noteId: noteId, noteHash: '' },
]);
});
});