1
0
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:
Henry Heino
2024-07-26 04:35:50 -07:00
committed by GitHub
parent d2028588e8
commit 8c0769fdb3
16 changed files with 300 additions and 35 deletions

View File

@ -67,6 +67,7 @@ import OcrDriverTesseract from '../services/ocr/drivers/OcrDriverTesseract';
import OcrService from '../services/ocr/OcrService';
import { createWorker } from 'tesseract.js';
import { reg } from '../registry';
import { Store } from 'redux';
// 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
@ -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.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 () => {
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 };