2020-02-27 20:25:42 +02:00
|
|
|
/* eslint-disable no-unused-vars */
|
2023-10-26 14:21:05 +02:00
|
|
|
|
|
|
|
// ====================== IMPORTANT ============================================
|
|
|
|
// As of 2023-10-23 we should not use these tests anymore as they are too flaky.
|
|
|
|
// To test the reducer we can use `reducer.test.js` or `app.reducer.test.ts`. If
|
|
|
|
// it becomes too much of a burden to maintain these `feature_*` tests we may to
|
|
|
|
// remove them.
|
|
|
|
// ====================== IMPORTANT ============================================
|
|
|
|
|
2021-05-21 15:17:21 +02:00
|
|
|
const { setupDatabaseAndSynchronizer, switchClient, id, ids, sortedIds, at, createNTestFolders, createNTestNotes, createNTestTags, TestApp } = require('@joplin/lib/testing/test-utils.js');
|
2020-11-07 17:59:37 +02:00
|
|
|
const Setting = require('@joplin/lib/models/Setting').default;
|
2021-01-22 19:41:11 +02:00
|
|
|
const Folder = require('@joplin/lib/models/Folder').default;
|
|
|
|
const Note = require('@joplin/lib/models/Note').default;
|
|
|
|
const Tag = require('@joplin/lib/models/Tag').default;
|
2020-11-07 17:59:37 +02:00
|
|
|
const time = require('@joplin/lib/time').default;
|
|
|
|
const { ALL_NOTES_FILTER_ID } = require('@joplin/lib/reserved-ids.js');
|
2020-02-27 20:25:42 +02:00
|
|
|
|
2023-10-26 14:21:05 +02:00
|
|
|
// The integration tests are to test the integration of the core system,
|
|
|
|
// comprising the base application with middleware, reducer and models in
|
|
|
|
// response to dispatched events.
|
2020-02-27 20:25:42 +02:00
|
|
|
//
|
|
|
|
// The general strategy for each integration test is:
|
|
|
|
// - create a starting application state,
|
|
|
|
// - inject the event to be tested
|
|
|
|
// - check the resulting application state
|
|
|
|
//
|
2023-10-26 14:21:05 +02:00
|
|
|
// Important: TestApp.wait() must be used after TestApp dispatch to allow the
|
|
|
|
// async processing to complete
|
2020-02-27 20:25:42 +02:00
|
|
|
|
|
|
|
let testApp = null;
|
|
|
|
|
2023-02-20 17:02:29 +02:00
|
|
|
describe('integration_ShowAllNotes', () => {
|
2020-02-27 20:25:42 +02:00
|
|
|
|
2023-10-26 14:21:05 +02:00
|
|
|
// The below tests can randomly fail, probably due to timing issues, so
|
|
|
|
// repeat them.
|
|
|
|
jest.retryTimes(2);
|
|
|
|
|
2022-11-15 12:23:50 +02:00
|
|
|
beforeEach(async () => {
|
2020-02-27 20:25:42 +02:00
|
|
|
testApp = new TestApp();
|
|
|
|
await testApp.start(['--no-welcome']);
|
|
|
|
});
|
|
|
|
|
2022-11-15 12:23:50 +02:00
|
|
|
afterEach(async () => {
|
2020-02-27 20:25:42 +02:00
|
|
|
if (testApp !== null) await testApp.destroy();
|
|
|
|
testApp = null;
|
|
|
|
});
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should show all notes', (async () => {
|
2020-02-27 20:25:42 +02:00
|
|
|
// setup
|
2020-03-14 01:46:14 +02:00
|
|
|
const folders = await createNTestFolders(3);
|
2020-02-27 20:25:42 +02:00
|
|
|
Folder.moveToFolder(id(folders[2]), id(folders[1])); // subfolder
|
2020-03-16 04:30:54 +02:00
|
|
|
await testApp.wait();
|
2020-03-14 01:46:14 +02:00
|
|
|
const notes0 = await createNTestNotes(3, folders[0]);
|
|
|
|
const notes1 = await createNTestNotes(3, folders[1]);
|
|
|
|
const notes2 = await createNTestNotes(3, folders[2]);
|
2020-03-16 04:30:54 +02:00
|
|
|
await testApp.wait();
|
2020-02-27 20:25:42 +02:00
|
|
|
|
|
|
|
// TEST ACTION: View all-notes
|
|
|
|
testApp.dispatch({ type: 'SMART_FILTER_SELECT', id: ALL_NOTES_FILTER_ID });
|
2020-03-16 04:30:54 +02:00
|
|
|
await testApp.wait();
|
2020-02-27 20:25:42 +02:00
|
|
|
|
|
|
|
// check: all the notes are shown
|
2020-03-14 01:46:14 +02:00
|
|
|
const state = testApp.store().getState();
|
2020-02-27 20:25:42 +02:00
|
|
|
expect(state.notesParentType).toEqual('SmartFilter');
|
|
|
|
expect(state.selectedSmartFilterId).toEqual(ALL_NOTES_FILTER_ID);
|
|
|
|
expect(sortedIds(state.notes)).toEqual(sortedIds(notes0.concat(notes1).concat(notes2)));
|
|
|
|
}));
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should show retain note selection when going from a folder to all-notes', (async () => {
|
2020-02-27 20:25:42 +02:00
|
|
|
// setup
|
2020-03-14 01:46:14 +02:00
|
|
|
const folders = await createNTestFolders(2);
|
|
|
|
const notes0 = await createNTestNotes(3, folders[0]);
|
|
|
|
const notes1 = await createNTestNotes(3, folders[1]);
|
2020-03-16 04:30:54 +02:00
|
|
|
await testApp.wait();
|
|
|
|
|
2020-02-27 20:25:42 +02:00
|
|
|
testApp.dispatch({ type: 'FOLDER_SELECT', id: id(folders[1]) });
|
2020-03-16 04:30:54 +02:00
|
|
|
await testApp.wait();
|
2020-02-27 20:25:42 +02:00
|
|
|
testApp.dispatch({ type: 'NOTE_SELECT', id: id(notes1[1]) });
|
2020-03-16 04:30:54 +02:00
|
|
|
await testApp.wait();
|
2020-02-27 20:25:42 +02:00
|
|
|
|
|
|
|
// check the state is set up as expected
|
|
|
|
let state = testApp.store().getState();
|
|
|
|
expect(state.notesParentType).toEqual('Folder');
|
|
|
|
expect(state.selectedFolderId).toEqual(id(folders[1]));
|
|
|
|
expect(sortedIds(state.notes)).toEqual(sortedIds(notes1));
|
|
|
|
expect(state.selectedNoteIds).toEqual(ids([notes1[1]]));
|
|
|
|
|
|
|
|
// TEST ACTION: View all-notes
|
|
|
|
testApp.dispatch({ type: 'SMART_FILTER_SELECT', id: ALL_NOTES_FILTER_ID });
|
2020-03-16 04:30:54 +02:00
|
|
|
await testApp.wait();
|
2020-02-27 20:25:42 +02:00
|
|
|
|
|
|
|
// check: all the notes are shown
|
|
|
|
state = testApp.store().getState();
|
|
|
|
expect(state.notesParentType).toEqual('SmartFilter');
|
|
|
|
expect(state.selectedSmartFilterId).toEqual(ALL_NOTES_FILTER_ID);
|
|
|
|
expect(sortedIds(state.notes)).toEqual(sortedIds(notes0.concat(notes1)));
|
|
|
|
expect(state.selectedNoteIds).toEqual(ids([notes1[1]]));
|
|
|
|
}));
|
2020-03-15 14:05:17 +02:00
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should support note duplication', (async () => {
|
2020-03-15 14:05:17 +02:00
|
|
|
// setup
|
2020-03-15 23:53:49 +02:00
|
|
|
const folder1 = await Folder.save({ title: 'folder1' });
|
|
|
|
const folder2 = await Folder.save({ title: 'folder2' });
|
|
|
|
const note1 = await Note.save({ title: 'note1', parent_id: folder1.id });
|
|
|
|
const note2 = await Note.save({ title: 'note2', parent_id: folder2.id });
|
2020-03-15 14:05:17 +02:00
|
|
|
testApp.dispatch({ type: 'FOLDER_SELECT', id: folder1.id }); // active folder
|
|
|
|
await time.msleep(100);
|
|
|
|
testApp.dispatch({ type: 'NOTE_SELECT', id: note1.id });
|
|
|
|
await time.msleep(100);
|
|
|
|
testApp.dispatch({ type: 'SMART_FILTER_SELECT', id: ALL_NOTES_FILTER_ID });
|
|
|
|
await time.msleep(100);
|
|
|
|
|
|
|
|
// check the state is set up as expected
|
|
|
|
let state = testApp.store().getState();
|
|
|
|
expect(state.notesParentType).toEqual('SmartFilter');
|
|
|
|
expect(sortedIds(state.notes)).toEqual(sortedIds([note1, note2]));
|
|
|
|
|
|
|
|
// TEST ACTION: duplicate a note from the active folder
|
|
|
|
const newNote1 = await Note.duplicate(note1.id);
|
|
|
|
await time.msleep(100);
|
|
|
|
|
|
|
|
// check the note is duplicated and the view updated
|
|
|
|
state = testApp.store().getState();
|
|
|
|
expect(state.notes.length).toEqual(3);
|
|
|
|
expect(sortedIds(state.notes)).toEqual(sortedIds([note1, note2, newNote1]));
|
|
|
|
|
|
|
|
// TEST ACTION: duplicate a note from a non-active folder
|
|
|
|
const newNote2 = await Note.duplicate(note2.id);
|
|
|
|
await time.msleep(100);
|
|
|
|
|
|
|
|
// check the note is duplicated and the view updated
|
|
|
|
state = testApp.store().getState();
|
|
|
|
expect(state.notes.length).toEqual(4);
|
|
|
|
expect(sortedIds(state.notes)).toEqual(sortedIds([note1, note2, newNote1, newNote2]));
|
|
|
|
}));
|
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should support changing the note parent', (async () => {
|
2020-03-15 14:05:17 +02:00
|
|
|
// setup
|
2020-03-15 23:53:49 +02:00
|
|
|
const folder1 = await Folder.save({ title: 'folder1' });
|
|
|
|
const folder2 = await Folder.save({ title: 'folder2' });
|
|
|
|
const note1 = await Note.save({ title: 'note1', parent_id: folder1.id });
|
|
|
|
const note2 = await Note.save({ title: 'note1', parent_id: folder2.id });
|
2020-03-15 14:05:17 +02:00
|
|
|
testApp.dispatch({ type: 'FOLDER_SELECT', id: folder1.id }); // active folder
|
|
|
|
await time.msleep(100);
|
|
|
|
testApp.dispatch({ type: 'NOTE_SELECT', id: note1.id });
|
|
|
|
await time.msleep(100);
|
|
|
|
testApp.dispatch({ type: 'SMART_FILTER_SELECT', id: ALL_NOTES_FILTER_ID });
|
|
|
|
await time.msleep(100);
|
|
|
|
|
|
|
|
// check the state is set up as expected
|
|
|
|
let state = testApp.store().getState();
|
|
|
|
expect(state.notesParentType).toEqual('SmartFilter');
|
|
|
|
expect(sortedIds(state.notes)).toEqual(sortedIds([note1, note2]));
|
|
|
|
expect(note1.parent_id).toEqual(folder1.id);
|
|
|
|
|
|
|
|
// TEST ACTION: change the notes parent
|
|
|
|
await Note.moveToFolder(note1.id, folder2.id);
|
|
|
|
await time.msleep(100);
|
|
|
|
|
|
|
|
// check the note is duplicated and the view updated
|
|
|
|
state = testApp.store().getState();
|
|
|
|
expect(state.notes.length).toEqual(2);
|
|
|
|
let n1 = await Note.load(note1.id);
|
|
|
|
expect(n1.parent_id).toEqual(folder2.id);
|
|
|
|
|
|
|
|
// TEST ACTION: change the notes parent
|
|
|
|
await Note.moveToFolder(note1.id, folder1.id);
|
|
|
|
await time.msleep(100);
|
|
|
|
|
|
|
|
// check the note is duplicated and the view updated
|
|
|
|
state = testApp.store().getState();
|
|
|
|
expect(state.notes.length).toEqual(2);
|
|
|
|
n1 = await Note.load(note1.id);
|
|
|
|
expect(n1.parent_id).toEqual(folder1.id);
|
|
|
|
}));
|
2020-02-27 20:25:42 +02:00
|
|
|
});
|