You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Chore: Mobile: Add note screen tests (#10766)
This commit is contained in:
@ -674,6 +674,7 @@ packages/app-mobile/components/screens/ConfigScreen/plugins/utils/useUpdateState
|
|||||||
packages/app-mobile/components/screens/ConfigScreen/types.js
|
packages/app-mobile/components/screens/ConfigScreen/types.js
|
||||||
packages/app-mobile/components/screens/JoplinCloudLoginScreen.js
|
packages/app-mobile/components/screens/JoplinCloudLoginScreen.js
|
||||||
packages/app-mobile/components/screens/LogScreen.js
|
packages/app-mobile/components/screens/LogScreen.js
|
||||||
|
packages/app-mobile/components/screens/Note.test.js
|
||||||
packages/app-mobile/components/screens/Note.js
|
packages/app-mobile/components/screens/Note.js
|
||||||
packages/app-mobile/components/screens/NoteTagsDialog.js
|
packages/app-mobile/components/screens/NoteTagsDialog.js
|
||||||
packages/app-mobile/components/screens/Notes.js
|
packages/app-mobile/components/screens/Notes.js
|
||||||
@ -695,7 +696,7 @@ packages/app-mobile/services/e2ee/RSA.react-native.js
|
|||||||
packages/app-mobile/services/plugins/PlatformImplementation.js
|
packages/app-mobile/services/plugins/PlatformImplementation.js
|
||||||
packages/app-mobile/services/profiles/index.js
|
packages/app-mobile/services/profiles/index.js
|
||||||
packages/app-mobile/services/voiceTyping/vosk.android.js
|
packages/app-mobile/services/voiceTyping/vosk.android.js
|
||||||
packages/app-mobile/services/voiceTyping/vosk.ios.js
|
packages/app-mobile/services/voiceTyping/vosk.js
|
||||||
packages/app-mobile/setupQuickActions.js
|
packages/app-mobile/setupQuickActions.js
|
||||||
packages/app-mobile/tools/buildInjectedJs/BundledFile.js
|
packages/app-mobile/tools/buildInjectedJs/BundledFile.js
|
||||||
packages/app-mobile/tools/buildInjectedJs/constants.js
|
packages/app-mobile/tools/buildInjectedJs/constants.js
|
||||||
@ -734,6 +735,7 @@ packages/app-mobile/utils/shareHandler.js
|
|||||||
packages/app-mobile/utils/shim-init-react.js
|
packages/app-mobile/utils/shim-init-react.js
|
||||||
packages/app-mobile/utils/showMessageBox.js
|
packages/app-mobile/utils/showMessageBox.js
|
||||||
packages/app-mobile/utils/testing/createMockReduxStore.js
|
packages/app-mobile/utils/testing/createMockReduxStore.js
|
||||||
|
packages/app-mobile/utils/testing/getWebViewDomById.js
|
||||||
packages/app-mobile/utils/types.js
|
packages/app-mobile/utils/types.js
|
||||||
packages/default-plugins/build.js
|
packages/default-plugins/build.js
|
||||||
packages/default-plugins/buildDefaultPlugins.js
|
packages/default-plugins/buildDefaultPlugins.js
|
||||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -653,6 +653,7 @@ packages/app-mobile/components/screens/ConfigScreen/plugins/utils/useUpdateState
|
|||||||
packages/app-mobile/components/screens/ConfigScreen/types.js
|
packages/app-mobile/components/screens/ConfigScreen/types.js
|
||||||
packages/app-mobile/components/screens/JoplinCloudLoginScreen.js
|
packages/app-mobile/components/screens/JoplinCloudLoginScreen.js
|
||||||
packages/app-mobile/components/screens/LogScreen.js
|
packages/app-mobile/components/screens/LogScreen.js
|
||||||
|
packages/app-mobile/components/screens/Note.test.js
|
||||||
packages/app-mobile/components/screens/Note.js
|
packages/app-mobile/components/screens/Note.js
|
||||||
packages/app-mobile/components/screens/NoteTagsDialog.js
|
packages/app-mobile/components/screens/NoteTagsDialog.js
|
||||||
packages/app-mobile/components/screens/Notes.js
|
packages/app-mobile/components/screens/Notes.js
|
||||||
@ -674,7 +675,7 @@ packages/app-mobile/services/e2ee/RSA.react-native.js
|
|||||||
packages/app-mobile/services/plugins/PlatformImplementation.js
|
packages/app-mobile/services/plugins/PlatformImplementation.js
|
||||||
packages/app-mobile/services/profiles/index.js
|
packages/app-mobile/services/profiles/index.js
|
||||||
packages/app-mobile/services/voiceTyping/vosk.android.js
|
packages/app-mobile/services/voiceTyping/vosk.android.js
|
||||||
packages/app-mobile/services/voiceTyping/vosk.ios.js
|
packages/app-mobile/services/voiceTyping/vosk.js
|
||||||
packages/app-mobile/setupQuickActions.js
|
packages/app-mobile/setupQuickActions.js
|
||||||
packages/app-mobile/tools/buildInjectedJs/BundledFile.js
|
packages/app-mobile/tools/buildInjectedJs/BundledFile.js
|
||||||
packages/app-mobile/tools/buildInjectedJs/constants.js
|
packages/app-mobile/tools/buildInjectedJs/constants.js
|
||||||
@ -713,6 +714,7 @@ packages/app-mobile/utils/shareHandler.js
|
|||||||
packages/app-mobile/utils/shim-init-react.js
|
packages/app-mobile/utils/shim-init-react.js
|
||||||
packages/app-mobile/utils/showMessageBox.js
|
packages/app-mobile/utils/showMessageBox.js
|
||||||
packages/app-mobile/utils/testing/createMockReduxStore.js
|
packages/app-mobile/utils/testing/createMockReduxStore.js
|
||||||
|
packages/app-mobile/utils/testing/getWebViewDomById.js
|
||||||
packages/app-mobile/utils/types.js
|
packages/app-mobile/utils/types.js
|
||||||
packages/default-plugins/build.js
|
packages/default-plugins/build.js
|
||||||
packages/default-plugins/buildDefaultPlugins.js
|
packages/default-plugins/buildDefaultPlugins.js
|
||||||
|
@ -14,6 +14,7 @@ import { HandleMessageCallback, OnMarkForDownloadCallback } from './hooks/useOnM
|
|||||||
import Resource from '@joplin/lib/models/Resource';
|
import Resource from '@joplin/lib/models/Resource';
|
||||||
import shim from '@joplin/lib/shim';
|
import shim from '@joplin/lib/shim';
|
||||||
import Note from '@joplin/lib/models/Note';
|
import Note from '@joplin/lib/models/Note';
|
||||||
|
import getWebViewDomById from '../../utils/testing/getWebViewDomById';
|
||||||
|
|
||||||
interface WrapperProps {
|
interface WrapperProps {
|
||||||
noteBody: string;
|
noteBody: string;
|
||||||
@ -56,17 +57,8 @@ const WrappedNoteViewer: React.FC<WrapperProps> = (
|
|||||||
</MenuProvider>;
|
</MenuProvider>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getNoteViewerDom = async (): Promise<Document> => {
|
const getNoteViewerDom = async () => {
|
||||||
const webviewContent = await screen.findByTestId('NoteBodyViewer');
|
return await getWebViewDomById('NoteBodyViewer');
|
||||||
expect(webviewContent).toBeVisible();
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(!!webviewContent.props.document).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Return the composite ExtendedWebView component
|
|
||||||
// See https://callstack.github.io/react-native-testing-library/docs/advanced/testing-env#tree-navigation
|
|
||||||
return webviewContent.props.document;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('NoteBodyViewer', () => {
|
describe('NoteBodyViewer', () => {
|
||||||
|
@ -66,8 +66,8 @@ export const WarningBannerComponent: React.FC<Props> = props => {
|
|||||||
warningComps.push(renderWarningBox(
|
warningComps.push(renderWarningBox(
|
||||||
'ShareManager',
|
'ShareManager',
|
||||||
_('%s (%s) would like to share a notebook with you.',
|
_('%s (%s) would like to share a notebook with you.',
|
||||||
substrWithEllipsis(sharer.full_name, 0, 48),
|
substrWithEllipsis(sharer?.full_name ?? 'Unknown', 0, 48),
|
||||||
substrWithEllipsis(sharer.email, 0, 52)),
|
substrWithEllipsis(sharer?.email ?? 'Unknown', 0, 52)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,7 +540,10 @@ class ScreenHeaderComponent extends PureComponent<ScreenHeaderProps, ScreenHeade
|
|||||||
} else {
|
} else {
|
||||||
menuOptionComponents.push(
|
menuOptionComponents.push(
|
||||||
<MenuOption value={o.onPress} key={`menuOption_${key++}`} style={this.styles().contextMenuItem} disabled={!!o.disabled}>
|
<MenuOption value={o.onPress} key={`menuOption_${key++}`} style={this.styles().contextMenuItem} disabled={!!o.disabled}>
|
||||||
<Text style={o.disabled ? this.styles().contextMenuItemTextDisabled : this.styles().contextMenuItemText}>{o.title}</Text>
|
<Text
|
||||||
|
style={o.disabled ? this.styles().contextMenuItemTextDisabled : this.styles().contextMenuItemText}
|
||||||
|
disabled={!!o.disabled}
|
||||||
|
>{o.title}</Text>
|
||||||
</MenuOption>,
|
</MenuOption>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -655,7 +658,7 @@ class ScreenHeaderComponent extends PureComponent<ScreenHeaderProps, ScreenHeade
|
|||||||
const menuComp =
|
const menuComp =
|
||||||
!menuOptionComponents.length || !showContextMenuButton ? null : (
|
!menuOptionComponents.length || !showContextMenuButton ? null : (
|
||||||
<Menu onSelect={value => this.menu_select(value)} style={this.styles().contextMenu}>
|
<Menu onSelect={value => this.menu_select(value)} style={this.styles().contextMenu}>
|
||||||
<MenuTrigger style={contextMenuStyle}>
|
<MenuTrigger style={contextMenuStyle} testID='screen-header-menu-trigger'>
|
||||||
<View accessibilityLabel={_('Actions')}>
|
<View accessibilityLabel={_('Actions')}>
|
||||||
<Icon name="ellipsis-vertical" style={this.styles().contextMenuTrigger} />
|
<Icon name="ellipsis-vertical" style={this.styles().contextMenuTrigger} />
|
||||||
</View>
|
</View>
|
||||||
|
173
packages/app-mobile/components/screens/Note.test.tsx
Normal file
173
packages/app-mobile/components/screens/Note.test.tsx
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { describe, it, beforeEach } from '@jest/globals';
|
||||||
|
import { fireEvent, render, screen, userEvent, waitFor } from '@testing-library/react-native';
|
||||||
|
import '@testing-library/jest-native/extend-expect';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
|
||||||
|
import NoteScreen from './Note';
|
||||||
|
import { MenuProvider } from 'react-native-popup-menu';
|
||||||
|
import { runWithFakeTimers, setupDatabaseAndSynchronizer, switchClient, simulateReadOnlyShareEnv } from '@joplin/lib/testing/test-utils';
|
||||||
|
import Note from '@joplin/lib/models/Note';
|
||||||
|
import { AppState } from '../../utils/types';
|
||||||
|
import { Store } from 'redux';
|
||||||
|
import createMockReduxStore from '../../utils/testing/createMockReduxStore';
|
||||||
|
import initializeCommandService from '../../utils/initializeCommandService';
|
||||||
|
import { PaperProvider } from 'react-native-paper';
|
||||||
|
import getWebViewDomById from '../../utils/testing/getWebViewDomById';
|
||||||
|
import { NoteEntity } from '@joplin/lib/services/database/types';
|
||||||
|
import Folder from '@joplin/lib/models/Folder';
|
||||||
|
import BaseItem from '@joplin/lib/models/BaseItem';
|
||||||
|
import { ModelType } from '@joplin/lib/BaseModel';
|
||||||
|
import ItemChange from '@joplin/lib/models/ItemChange';
|
||||||
|
import { getDisplayParentId } from '@joplin/lib/services/trash';
|
||||||
|
import { itemIsReadOnlySync, ItemSlice } from '@joplin/lib/models/utils/readOnly';
|
||||||
|
import { LayoutChangeEvent } from 'react-native';
|
||||||
|
|
||||||
|
interface WrapperProps {
|
||||||
|
}
|
||||||
|
|
||||||
|
let store: Store<AppState>;
|
||||||
|
|
||||||
|
const WrappedNoteScreen: React.FC<WrapperProps> = _props => {
|
||||||
|
return <MenuProvider>
|
||||||
|
<PaperProvider>
|
||||||
|
<Provider store={store}>
|
||||||
|
<NoteScreen />
|
||||||
|
</Provider>
|
||||||
|
</PaperProvider>
|
||||||
|
</MenuProvider>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getNoteViewerDom = async () => {
|
||||||
|
return await getWebViewDomById('NoteBodyViewer');
|
||||||
|
};
|
||||||
|
|
||||||
|
const openNewNote = async (noteProperties: NoteEntity) => {
|
||||||
|
const note = await Note.save({
|
||||||
|
parent_id: (await Folder.defaultFolder()).id,
|
||||||
|
...noteProperties,
|
||||||
|
});
|
||||||
|
|
||||||
|
const displayParentId = getDisplayParentId(note, await Folder.load(note.parent_id));
|
||||||
|
|
||||||
|
store.dispatch({
|
||||||
|
type: 'NOTE_UPDATE_ALL',
|
||||||
|
notes: await Note.previews(displayParentId),
|
||||||
|
});
|
||||||
|
|
||||||
|
store.dispatch({
|
||||||
|
type: 'FOLDER_AND_NOTE_SELECT',
|
||||||
|
id: note.id,
|
||||||
|
folderId: displayParentId,
|
||||||
|
});
|
||||||
|
return note.id;
|
||||||
|
};
|
||||||
|
|
||||||
|
const openNoteActionsMenu = async () => {
|
||||||
|
// It doesn't seem possible to find the menu trigger with role/label.
|
||||||
|
const actionMenuButton = await screen.findByTestId('screen-header-menu-trigger');
|
||||||
|
|
||||||
|
// react-native-action-menu only shows the menu content after receiving onLayout
|
||||||
|
// events from various components (including a View that wraps the screen).
|
||||||
|
let cursor = actionMenuButton;
|
||||||
|
while (cursor.parent) {
|
||||||
|
if (cursor.props.onLayout) {
|
||||||
|
const mockedEvent = { nativeEvent: { layout: { x: 0, y: 0, width: 120, height: 100 } } };
|
||||||
|
cursor.props.onLayout(mockedEvent as LayoutChangeEvent);
|
||||||
|
}
|
||||||
|
cursor = cursor.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
await runWithFakeTimers(() => userEvent.press(actionMenuButton));
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Note', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await setupDatabaseAndSynchronizer(0);
|
||||||
|
await switchClient(0);
|
||||||
|
|
||||||
|
store = createMockReduxStore();
|
||||||
|
initializeCommandService(store);
|
||||||
|
|
||||||
|
// In order for note changes to be saved, note-screen-shared requires
|
||||||
|
// that at least one folder exist.
|
||||||
|
await Folder.save({ title: 'test', parent_id: '' });
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
screen.unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show the currently selected note', async () => {
|
||||||
|
await openNewNote({ title: 'Test note (title)', body: '# Testing...' });
|
||||||
|
render(<WrappedNoteScreen />);
|
||||||
|
|
||||||
|
const titleInput = await screen.findByDisplayValue('Test note (title)');
|
||||||
|
expect(titleInput).toBeVisible();
|
||||||
|
|
||||||
|
const renderedNote = await getNoteViewerDom();
|
||||||
|
expect(renderedNote.querySelector('h1')).toMatchObject({ textContent: 'Testing...' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('changing the note title input should update the note\'s title', async () => {
|
||||||
|
const noteId = await openNewNote({ title: 'Change me!', body: 'Unchanged body' });
|
||||||
|
render(<WrappedNoteScreen />);
|
||||||
|
|
||||||
|
const titleInput = await screen.findByDisplayValue('Change me!');
|
||||||
|
// We need to use fake timers while using userEvent to avoid warnings:
|
||||||
|
await runWithFakeTimers(async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
await user.clear(titleInput);
|
||||||
|
await user.type(titleInput, 'New title');
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(async () => {
|
||||||
|
expect(await Note.load(noteId)).toMatchObject({ title: 'New title', body: 'Unchanged body' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('pressing "delete" should move the note to the trash', async () => {
|
||||||
|
const noteId = await openNewNote({ title: 'To be deleted', body: '...' });
|
||||||
|
render(<WrappedNoteScreen />);
|
||||||
|
|
||||||
|
await openNoteActionsMenu();
|
||||||
|
const deleteButton = await screen.findByText('Delete');
|
||||||
|
fireEvent.press(deleteButton);
|
||||||
|
|
||||||
|
await waitFor(async () => {
|
||||||
|
expect((await Note.load(noteId)).deleted_time).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('delete should be disabled in a read-only note', async () => {
|
||||||
|
const shareId = 'testShare';
|
||||||
|
const noteId = await openNewNote({
|
||||||
|
title: 'Title: Read-only note',
|
||||||
|
body: 'A **read-only** note.',
|
||||||
|
share_id: shareId,
|
||||||
|
});
|
||||||
|
const cleanup = simulateReadOnlyShareEnv(shareId, store);
|
||||||
|
expect(
|
||||||
|
itemIsReadOnlySync(
|
||||||
|
ModelType.Note,
|
||||||
|
ItemChange.SOURCE_UNSPECIFIED,
|
||||||
|
await Note.load(noteId) as ItemSlice,
|
||||||
|
'',
|
||||||
|
BaseItem.syncShareCache,
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
|
||||||
|
render(<WrappedNoteScreen />);
|
||||||
|
|
||||||
|
const titleInput = await screen.findByDisplayValue('Title: Read-only note');
|
||||||
|
expect(titleInput).toBeVisible();
|
||||||
|
expect(titleInput).toBeDisabled();
|
||||||
|
|
||||||
|
await openNoteActionsMenu();
|
||||||
|
const deleteButton = await screen.findByText('Delete');
|
||||||
|
expect(deleteButton).toBeDisabled();
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
});
|
||||||
|
});
|
@ -10,7 +10,7 @@ const FileViewer = require('react-native-file-viewer').default;
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
import { Keyboard, View, TextInput, StyleSheet, Linking, Share, NativeSyntheticEvent } from 'react-native';
|
import { Keyboard, View, TextInput, StyleSheet, Linking, Share, NativeSyntheticEvent } from 'react-native';
|
||||||
import { Platform, PermissionsAndroid } from 'react-native';
|
import { Platform, PermissionsAndroid } from 'react-native';
|
||||||
const { connect } = require('react-redux');
|
import { connect } from 'react-redux';
|
||||||
// const { MarkdownEditor } = require('@joplin/lib/../MarkdownEditor/index.js');
|
// const { MarkdownEditor } = require('@joplin/lib/../MarkdownEditor/index.js');
|
||||||
import Note from '@joplin/lib/models/Note';
|
import Note from '@joplin/lib/models/Note';
|
||||||
import BaseItem from '@joplin/lib/models/BaseItem';
|
import BaseItem from '@joplin/lib/models/BaseItem';
|
||||||
@ -35,7 +35,7 @@ import { BaseScreenComponent } from '../base-screen';
|
|||||||
import { themeStyle, editorFont } from '../global-style';
|
import { themeStyle, editorFont } from '../global-style';
|
||||||
const { dialogs } = require('../../utils/dialogs.js');
|
const { dialogs } = require('../../utils/dialogs.js');
|
||||||
const DialogBox = require('react-native-dialogbox').default;
|
const DialogBox = require('react-native-dialogbox').default;
|
||||||
import shared, { BaseNoteScreenComponent } from '@joplin/lib/components/shared/note-screen-shared';
|
import shared, { BaseNoteScreenComponent, Props as BaseProps } from '@joplin/lib/components/shared/note-screen-shared';
|
||||||
import { Asset, ImagePickerResponse, launchImageLibrary } from 'react-native-image-picker';
|
import { Asset, ImagePickerResponse, launchImageLibrary } from 'react-native-image-picker';
|
||||||
import SelectDateTimeDialog from '../SelectDateTimeDialog';
|
import SelectDateTimeDialog from '../SelectDateTimeDialog';
|
||||||
import ShareExtension from '../../utils/ShareExtension.js';
|
import ShareExtension from '../../utils/ShareExtension.js';
|
||||||
@ -47,7 +47,7 @@ import promptRestoreAutosave from '../NoteEditor/ImageEditor/promptRestoreAutosa
|
|||||||
import isEditableResource from '../NoteEditor/ImageEditor/isEditableResource';
|
import isEditableResource from '../NoteEditor/ImageEditor/isEditableResource';
|
||||||
import VoiceTypingDialog from '../voiceTyping/VoiceTypingDialog';
|
import VoiceTypingDialog from '../voiceTyping/VoiceTypingDialog';
|
||||||
import { voskEnabled } from '../../services/voiceTyping/vosk';
|
import { voskEnabled } from '../../services/voiceTyping/vosk';
|
||||||
import { isSupportedLanguage } from '../../services/voiceTyping/vosk.android';
|
import { isSupportedLanguage } from '../../services/voiceTyping/vosk';
|
||||||
import { ChangeEvent as EditorChangeEvent, SelectionRangeChangeEvent, UndoRedoDepthChangeEvent } from '@joplin/editor/events';
|
import { ChangeEvent as EditorChangeEvent, SelectionRangeChangeEvent, UndoRedoDepthChangeEvent } from '@joplin/editor/events';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { Dispatch } from 'redux';
|
import { Dispatch } from 'redux';
|
||||||
@ -71,7 +71,7 @@ const emptyArray: any[] = [];
|
|||||||
|
|
||||||
const logger = Logger.create('screens/Note');
|
const logger = Logger.create('screens/Note');
|
||||||
|
|
||||||
interface Props {
|
interface Props extends BaseProps {
|
||||||
provisionalNoteIds: string[];
|
provisionalNoteIds: string[];
|
||||||
dispatch: Dispatch;
|
dispatch: Dispatch;
|
||||||
noteId: string;
|
noteId: string;
|
||||||
@ -81,8 +81,8 @@ interface Props {
|
|||||||
editorFontSize: number;
|
editorFontSize: number;
|
||||||
editorFont: number; // e.g. Setting.FONT_MENLO
|
editorFont: number; // e.g. Setting.FONT_MENLO
|
||||||
showSideMenu: boolean;
|
showSideMenu: boolean;
|
||||||
searchQuery: string[];
|
searchQuery: string;
|
||||||
ftsEnabled: boolean;
|
ftsEnabled: number;
|
||||||
highlightedWords: string[];
|
highlightedWords: string[];
|
||||||
noteHash: string;
|
noteHash: string;
|
||||||
toolbarEnabled: boolean;
|
toolbarEnabled: boolean;
|
||||||
@ -1186,7 +1186,7 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B
|
|||||||
|
|
||||||
const pluginCommands = pluginUtils.commandNamesFromViews(this.props.plugins, 'noteToolbar');
|
const pluginCommands = pluginUtils.commandNamesFromViews(this.props.plugins, 'noteToolbar');
|
||||||
|
|
||||||
const cacheKey = md5([isTodo, isSaved, pluginCommands.join(',')].join('_'));
|
const cacheKey = md5([isTodo, isSaved, pluginCommands.join(','), readOnly].join('_'));
|
||||||
if (!this.menuOptionsCache_) this.menuOptionsCache_ = {};
|
if (!this.menuOptionsCache_) this.menuOptionsCache_ = {};
|
||||||
|
|
||||||
if (this.menuOptionsCache_[cacheKey]) return this.menuOptionsCache_[cacheKey];
|
if (this.menuOptionsCache_[cacheKey]) return this.menuOptionsCache_[cacheKey];
|
||||||
@ -1675,7 +1675,7 @@ const NoteScreen = connect((state: AppState) => {
|
|||||||
folders: state.folders,
|
folders: state.folders,
|
||||||
searchQuery: state.searchQuery,
|
searchQuery: state.searchQuery,
|
||||||
themeId: state.settings.theme,
|
themeId: state.settings.theme,
|
||||||
editorFont: [state.settings['style.editor.fontFamily']],
|
editorFont: state.settings['style.editor.fontFamily'] as number,
|
||||||
editorFontSize: state.settings['style.editor.fontSize'],
|
editorFontSize: state.settings['style.editor.fontSize'],
|
||||||
toolbarEnabled: state.settings['editor.mobile.toolbarEnabled'],
|
toolbarEnabled: state.settings['editor.mobile.toolbarEnabled'],
|
||||||
ftsEnabled: state.settings['db.ftsEnabled'],
|
ftsEnabled: state.settings['db.ftsEnabled'],
|
||||||
|
@ -5,7 +5,7 @@ import { _, languageName } from '@joplin/lib/locale';
|
|||||||
import useAsyncEffect, { AsyncEffectEvent } from '@joplin/lib/hooks/useAsyncEffect';
|
import useAsyncEffect, { AsyncEffectEvent } from '@joplin/lib/hooks/useAsyncEffect';
|
||||||
import { getVosk, Recorder, startRecording, Vosk } from '../../services/voiceTyping/vosk';
|
import { getVosk, Recorder, startRecording, Vosk } from '../../services/voiceTyping/vosk';
|
||||||
import { IconSource } from 'react-native-paper/lib/typescript/components/Icon';
|
import { IconSource } from 'react-native-paper/lib/typescript/components/Icon';
|
||||||
import { modelIsDownloaded } from '../../services/voiceTyping/vosk.android';
|
import { modelIsDownloaded } from '../../services/voiceTyping/vosk';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
locale: string;
|
locale: string;
|
||||||
|
@ -58,10 +58,29 @@ jest.mock('@react-native-clipboard/clipboard', () => {
|
|||||||
return { default: { getString: jest.fn(), setString: jest.fn() } };
|
return { default: { getString: jest.fn(), setString: jest.fn() } };
|
||||||
});
|
});
|
||||||
|
|
||||||
jest.mock('react-native-share', () => {
|
const emptyMockPackages = [
|
||||||
|
'react-native-share',
|
||||||
|
'react-native-file-viewer',
|
||||||
|
'react-native-image-picker',
|
||||||
|
'react-native-document-picker',
|
||||||
|
'@joplin/react-native-saf-x',
|
||||||
|
];
|
||||||
|
for (const packageName of emptyMockPackages) {
|
||||||
|
jest.doMock(packageName, () => {
|
||||||
|
return { default: { } };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
jest.mock('react-native-file-viewer', () => {
|
||||||
return { default: { } };
|
return { default: { } };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jest.mock('react-native-image-picker', () => {
|
||||||
|
return { default: { } };
|
||||||
|
});
|
||||||
|
|
||||||
|
jest.mock('react-native-document-picker', () => ({ default: { } }));
|
||||||
|
|
||||||
// Used by the renderer
|
// Used by the renderer
|
||||||
jest.doMock('react-native-vector-icons/Ionicons', () => {
|
jest.doMock('react-native-vector-icons/Ionicons', () => {
|
||||||
return {
|
return {
|
||||||
|
@ -131,6 +131,8 @@ import PlatformImplementation from './services/plugins/PlatformImplementation';
|
|||||||
import ShareManager from './components/screens/ShareManager';
|
import ShareManager from './components/screens/ShareManager';
|
||||||
import appDefaultState, { DEFAULT_ROUTE } from './utils/appDefaultState';
|
import appDefaultState, { DEFAULT_ROUTE } from './utils/appDefaultState';
|
||||||
import { setDateFormat, setTimeFormat, setTimeLocale } from '@joplin/utils/time';
|
import { setDateFormat, setTimeFormat, setTimeLocale } from '@joplin/utils/time';
|
||||||
|
import { AppState } from './utils/types';
|
||||||
|
import { getDisplayParentId } from '@joplin/lib/services/trash';
|
||||||
|
|
||||||
type SideMenuPosition = 'left' | 'right';
|
type SideMenuPosition = 'left' | 'right';
|
||||||
|
|
||||||
@ -159,7 +161,7 @@ const generalMiddleware = (store: any) => (next: any) => async (action: any) =>
|
|||||||
PoorManIntervals.update(); // This function needs to be called regularly so put it here
|
PoorManIntervals.update(); // This function needs to be called regularly so put it here
|
||||||
|
|
||||||
const result = next(action);
|
const result = next(action);
|
||||||
const newState = store.getState();
|
const newState: AppState = store.getState();
|
||||||
let doRefreshFolders = false;
|
let doRefreshFolders = false;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||||
@ -180,6 +182,12 @@ const generalMiddleware = (store: any) => (next: any) => async (action: any) =>
|
|||||||
await AlarmService.updateNoteNotification(action.id, action.type === 'NOTE_DELETE');
|
await AlarmService.updateNoteNotification(action.id, action.type === 'NOTE_DELETE');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action.type === 'NOTE_DELETE' && newState.route?.routeName === 'Note' && newState.route.noteId === action.id) {
|
||||||
|
const parentItem = action.originalItem?.parent_id ? await Folder.load(action.originalItem?.parent_id) : null;
|
||||||
|
const parentId = getDisplayParentId(action.originalItem, parentItem);
|
||||||
|
await NavService.go('Notes', { folderId: parentId });
|
||||||
|
}
|
||||||
|
|
||||||
if (action.type === 'SETTING_UPDATE_ONE' && action.key === 'sync.interval' || action.type === 'SETTING_UPDATE_ALL') {
|
if (action.type === 'SETTING_UPDATE_ONE' && action.key === 'sync.interval' || action.type === 'SETTING_UPDATE_ALL') {
|
||||||
reg.setupRecurrentSync();
|
reg.setupRecurrentSync();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Currently disabled on iOS
|
// Currently disabled on non-Android platforms
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||||
type Vosk = any;
|
type Vosk = any;
|
15
packages/app-mobile/utils/testing/getWebViewDomById.ts
Normal file
15
packages/app-mobile/utils/testing/getWebViewDomById.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { screen, waitFor } from '@testing-library/react-native';
|
||||||
|
const getWebViewDomById = async (id: string): Promise<Document> => {
|
||||||
|
const webviewContent = await screen.findByTestId(id);
|
||||||
|
expect(webviewContent).toBeVisible();
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(!!webviewContent.props.document).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Return the composite ExtendedWebView component
|
||||||
|
// See https://callstack.github.io/react-native-testing-library/docs/advanced/testing-env#tree-navigation
|
||||||
|
return webviewContent.props.document;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getWebViewDomById;
|
@ -1,4 +1,4 @@
|
|||||||
import { NoteEntity } from '../../services/database/types';
|
import { FolderEntity, NoteEntity } from '../../services/database/types';
|
||||||
import { reg } from '../../registry';
|
import { reg } from '../../registry';
|
||||||
import Folder from '../../models/Folder';
|
import Folder from '../../models/Folder';
|
||||||
import BaseModel, { ModelType } from '../../BaseModel';
|
import BaseModel, { ModelType } from '../../BaseModel';
|
||||||
@ -12,9 +12,27 @@ import { itemIsReadOnlySync, ItemSlice } from '../../models/utils/readOnly';
|
|||||||
import ItemChange from '../../models/ItemChange';
|
import ItemChange from '../../models/ItemChange';
|
||||||
import BaseItem from '../../models/BaseItem';
|
import BaseItem from '../../models/BaseItem';
|
||||||
|
|
||||||
|
interface SharedResource {
|
||||||
|
uri: string;
|
||||||
|
mimeType: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SharedData {
|
||||||
|
title: string;
|
||||||
|
text: string;
|
||||||
|
resources: SharedResource[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Props {
|
||||||
|
provisionalNoteIds: string[];
|
||||||
|
noteId: string;
|
||||||
|
folders: FolderEntity[];
|
||||||
|
sharedData: SharedData|undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export interface BaseNoteScreenComponent {
|
export interface BaseNoteScreenComponent {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
props: Props;
|
||||||
props: any;
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||||
state: any;
|
state: any;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||||
|
@ -916,6 +916,7 @@ export default class Note extends BaseItem {
|
|||||||
this.dispatch({
|
this.dispatch({
|
||||||
type: 'NOTE_DELETE',
|
type: 'NOTE_DELETE',
|
||||||
id: id,
|
id: id,
|
||||||
|
originalItem: notes[i],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import eventManager, { EventListenerCallback, EventName } from '../eventManager'
|
|||||||
import BaseService from './BaseService';
|
import BaseService from './BaseService';
|
||||||
import shim from '../shim';
|
import shim from '../shim';
|
||||||
import WhenClause from './WhenClause';
|
import WhenClause from './WhenClause';
|
||||||
|
import type { WhenClauseContext } from './commands/stateToWhenClauseContext';
|
||||||
|
|
||||||
type LabelFunction = ()=> string;
|
type LabelFunction = ()=> string;
|
||||||
type EnabledCondition = string;
|
type EnabledCondition = string;
|
||||||
@ -271,7 +272,7 @@ export default class CommandService extends BaseService {
|
|||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public currentWhenClauseContext() {
|
public currentWhenClauseContext(): WhenClauseContext {
|
||||||
return this.stateToWhenClauseContext_(this.store_.getState());
|
return this.stateToWhenClauseContext_(this.store_.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ import OcrDriverTesseract from '../services/ocr/drivers/OcrDriverTesseract';
|
|||||||
import OcrService from '../services/ocr/OcrService';
|
import OcrService from '../services/ocr/OcrService';
|
||||||
import { createWorker } from 'tesseract.js';
|
import { createWorker } from 'tesseract.js';
|
||||||
import { reg } from '../registry';
|
import { reg } from '../registry';
|
||||||
|
import { Store } from 'redux';
|
||||||
|
|
||||||
// Each suite has its own separate data and temp directory so that multiple
|
// Each suite has its own separate data and temp directory so that multiple
|
||||||
// suites can be run at the same time. suiteName is what is used to
|
// suites can be run at the same time. suiteName is what is used to
|
||||||
@ -1043,10 +1044,26 @@ const createTestShareData = (shareId: string): ShareState => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const simulateReadOnlyShareEnv = (shareId: string) => {
|
const simulateReadOnlyShareEnv = (shareId: string, store?: Store) => {
|
||||||
Setting.setValue('sync.target', 10);
|
Setting.setValue('sync.target', 10);
|
||||||
Setting.setValue('sync.userId', 'abcd');
|
Setting.setValue('sync.userId', 'abcd');
|
||||||
BaseItem.syncShareCache = createTestShareData(shareId);
|
const shareData = createTestShareData(shareId);
|
||||||
|
BaseItem.syncShareCache = shareData;
|
||||||
|
|
||||||
|
if (store) {
|
||||||
|
store.dispatch({
|
||||||
|
type: 'SHARE_SET',
|
||||||
|
shares: shareData.shares,
|
||||||
|
});
|
||||||
|
store.dispatch({
|
||||||
|
type: 'SHARE_INVITATION_SET',
|
||||||
|
shareInvitations: shareData.shareInvitations,
|
||||||
|
});
|
||||||
|
store.dispatch({
|
||||||
|
type: 'SHARE_USER_SET',
|
||||||
|
shareUsers: shareData.shareUsers,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
BaseItem.syncShareCache = null;
|
BaseItem.syncShareCache = null;
|
||||||
@ -1074,4 +1091,18 @@ export const mockMobilePlatform = (platform: string) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const runWithFakeTimers = (callback: ()=> Promise<void>) => {
|
||||||
|
if (typeof jest === 'undefined') {
|
||||||
|
throw new Error('Fake timers are only supported in jest.');
|
||||||
|
}
|
||||||
|
|
||||||
|
jest.useFakeTimers();
|
||||||
|
try {
|
||||||
|
return callback();
|
||||||
|
} finally {
|
||||||
|
jest.runOnlyPendingTimers();
|
||||||
|
jest.useRealTimers();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export { supportDir, createNoteAndResource, createTempFile, createTestShareData, simulateReadOnlyShareEnv, waitForFolderCount, afterAllCleanUp, exportDir, synchronizerStart, afterEachCleanUp, syncTargetName, setSyncTargetName, syncDir, createTempDir, isNetworkSyncTarget, kvStore, expectThrow, logger, expectNotThrow, resourceService, resourceFetcher, tempFilePath, allSyncTargetItemsEncrypted, msleep, setupDatabase, revisionService, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, objectsEqual, checkThrowAsync, checkThrow, encryptionService, loadEncryptionMasterKey, fileContentEqual, decryptionWorker, currentClientId, id, ids, sortedIds, at, createNTestNotes, createNTestFolders, createNTestTags, TestApp };
|
export { supportDir, createNoteAndResource, createTempFile, createTestShareData, simulateReadOnlyShareEnv, waitForFolderCount, afterAllCleanUp, exportDir, synchronizerStart, afterEachCleanUp, syncTargetName, setSyncTargetName, syncDir, createTempDir, isNetworkSyncTarget, kvStore, expectThrow, logger, expectNotThrow, resourceService, resourceFetcher, tempFilePath, allSyncTargetItemsEncrypted, msleep, setupDatabase, revisionService, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient, syncTargetId, objectsEqual, checkThrowAsync, checkThrow, encryptionService, loadEncryptionMasterKey, fileContentEqual, decryptionWorker, currentClientId, id, ids, sortedIds, at, createNTestNotes, createNTestFolders, createNTestTags, TestApp };
|
||||||
|
Reference in New Issue
Block a user