1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Tests: Fix random failures (#2777)

* Update new feature tests following test harness fixes.

* Fix lint errors.
This commit is contained in:
mic704b 2020-04-20 20:32:42 +10:00 committed by GitHub
parent d2acf314f5
commit d1cab4b7f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 143 additions and 12 deletions

View File

@ -0,0 +1,129 @@
require('app-module-path').addPath(__dirname);
const { asyncTest, id, ids, createNTestFolders, createNTestNotes, TestApp } = require('test-utils.js');
let testApp = null;
const goBackWard = (state) => {
const lastItem = state.backwardHistoryNotes[state.backwardHistoryNotes.length - 1];
testApp.dispatch({ type: 'FOLDER_AND_NOTE_SELECT', noteId: lastItem.id, folderId: lastItem.parent_id, historyAction: 'pop' });
};
const goForward = (state) => {
const lastItem = state.forwardHistoryNotes[state.forwardHistoryNotes.length - 1];
testApp.dispatch({ type: 'FOLDER_AND_NOTE_SELECT', noteId: lastItem.id, folderId: lastItem.parent_id, historyAction: 'push' });
};
describe('integration_ForwardBackwardNoteHistory', function() {
beforeEach(async (done) => {
testApp = new TestApp();
await testApp.start(['--no-welcome']);
done();
});
afterEach(async (done) => {
if (testApp !== null) await testApp.destroy();
testApp = null;
done();
});
it('should save history when navigating through notes', asyncTest(async () => {
// setup
const folders = await createNTestFolders(2);
await testApp.wait();
const notes0 = await createNTestNotes(5, folders[0]);
await testApp.wait();
testApp.dispatch({ type: 'FOLDER_SELECT', id: id(folders[0]) });
await testApp.wait();
let state = testApp.store().getState();
expect(state.backwardHistoryNotes).toEqual([]);
expect(state.forwardHistoryNotes).toEqual([]);
testApp.dispatch({ type: 'NOTE_SELECT', id: notes0[3].id, historyAction: 'goto' });
await testApp.wait();
testApp.dispatch({ type: 'NOTE_SELECT', id: notes0[2].id, historyAction: 'goto' });
await testApp.wait();
testApp.dispatch({ type: 'NOTE_SELECT', id: notes0[1].id, historyAction: 'goto' });
await testApp.wait();
testApp.dispatch({ type: 'NOTE_SELECT', id: notes0[0].id, historyAction: 'goto' });
await testApp.wait();
state = testApp.store().getState();
expect(ids(state.backwardHistoryNotes)).toEqual(ids([notes0[4], notes0[3], notes0[2], notes0[1]]));
expect(ids(state.forwardHistoryNotes)).toEqual([]);
goBackWard(state);
await testApp.wait();
state = testApp.store().getState();
expect(ids(state.backwardHistoryNotes)).toEqual(ids([notes0[4], notes0[3], notes0[2]]));
expect(ids(state.forwardHistoryNotes)).toEqual(ids([notes0[0]]));
goBackWard(state);
await testApp.wait();
state = testApp.store().getState();
expect(ids(state.backwardHistoryNotes)).toEqual(ids([notes0[4], notes0[3]]));
expect(ids(state.forwardHistoryNotes)).toEqual(ids([notes0[0], notes0[1]]));
goForward(state);
await testApp.wait();
state = testApp.store().getState();
expect(ids(state.backwardHistoryNotes)).toEqual(ids([notes0[4], notes0[3], notes0[2]]));
expect(ids(state.forwardHistoryNotes)).toEqual(ids([notes0[0]]));
testApp.dispatch({ type: 'NOTE_SELECT', id: notes0[4].id, historyAction: 'goto' });
await testApp.wait();
state = testApp.store().getState();
expect(ids(state.backwardHistoryNotes)).toEqual(ids([notes0[4], notes0[3], notes0[2], notes0[1]]));
expect(ids(state.forwardHistoryNotes)).toEqual([]);
}));
it('should save history when navigating through notebooks', asyncTest(async () => {
const folders = await createNTestFolders(2);
await testApp.wait();
const notes0 = await createNTestNotes(5, folders[0]);
const notes1 = await createNTestNotes(5, folders[1]);
await testApp.wait();
testApp.dispatch({ type: 'FOLDER_SELECT', id: id(folders[0]) });
await testApp.wait();
let state = testApp.store().getState();
expect(state.backwardHistoryNotes).toEqual([]);
expect(state.forwardHistoryNotes).toEqual([]);
testApp.dispatch({ type: 'FOLDER_SELECT', id: id(folders[1]), historyAction: 'goto' });
await testApp.wait();
state = testApp.store().getState();
expect(ids(state.backwardHistoryNotes)).toEqual(ids([notes0[4]])); // notes0[4] was last created
expect(ids(state.forwardHistoryNotes)).toEqual([]);
testApp.dispatch({ type: 'FOLDER_SELECT', id: id(folders[0]), historyAction: 'goto' });
await testApp.wait();
state = testApp.store().getState();
expect(ids(state.backwardHistoryNotes)).toEqual(ids([notes0[4], notes1[4]]));
expect(state.forwardHistoryNotes).toEqual([]);
goBackWard(state);
await testApp.wait();
state = testApp.store().getState();
expect(ids(state.backwardHistoryNotes)).toEqual(ids([notes0[4]]));
expect(ids(state.forwardHistoryNotes)).toEqual(ids([notes0[4]]));
goForward(state);
await testApp.wait();
state = testApp.store().getState();
expect(ids(state.backwardHistoryNotes)).toEqual(ids([notes0[4], notes1[4]]));
expect(state.forwardHistoryNotes).toEqual([]);
}));
});

View File

@ -95,12 +95,13 @@ describe('integration_ShowAllNotes', function() {
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 });
await testApp.wait();
testApp.dispatch({ type: 'FOLDER_SELECT', id: folder1.id }); // active folder
await time.msleep(100);
await testApp.wait();
testApp.dispatch({ type: 'NOTE_SELECT', id: note1.id });
await time.msleep(100);
await testApp.wait();
testApp.dispatch({ type: 'SMART_FILTER_SELECT', id: ALL_NOTES_FILTER_ID });
await time.msleep(100);
await testApp.wait();
// check the state is set up as expected
let state = testApp.store().getState();
@ -109,7 +110,7 @@ describe('integration_ShowAllNotes', function() {
// TEST ACTION: duplicate a note from the active folder
const newNote1 = await Note.duplicate(note1.id);
await time.msleep(100);
await testApp.wait();
// check the note is duplicated and the view updated
state = testApp.store().getState();
@ -118,7 +119,7 @@ describe('integration_ShowAllNotes', function() {
// TEST ACTION: duplicate a note from a non-active folder
const newNote2 = await Note.duplicate(note2.id);
await time.msleep(100);
await testApp.wait();
// check the note is duplicated and the view updated
state = testApp.store().getState();
@ -132,12 +133,13 @@ describe('integration_ShowAllNotes', function() {
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 });
await testApp.wait();
testApp.dispatch({ type: 'FOLDER_SELECT', id: folder1.id }); // active folder
await time.msleep(100);
await testApp.wait();
testApp.dispatch({ type: 'NOTE_SELECT', id: note1.id });
await time.msleep(100);
await testApp.wait();
testApp.dispatch({ type: 'SMART_FILTER_SELECT', id: ALL_NOTES_FILTER_ID });
await time.msleep(100);
await testApp.wait();
// check the state is set up as expected
let state = testApp.store().getState();
@ -147,9 +149,9 @@ describe('integration_ShowAllNotes', function() {
// TEST ACTION: change the notes parent
await Note.moveToFolder(note1.id, folder2.id);
await time.msleep(100);
await testApp.wait();
// check the note is duplicated and the view updated
// check the note is updated and remains in view
state = testApp.store().getState();
expect(state.notes.length).toEqual(2);
let n1 = await Note.load(note1.id);
@ -157,9 +159,9 @@ describe('integration_ShowAllNotes', function() {
// TEST ACTION: change the notes parent
await Note.moveToFolder(note1.id, folder1.id);
await time.msleep(100);
await testApp.wait();
// check the note is duplicated and the view updated
// check the note is updated and remains in view
state = testApp.store().getState();
expect(state.notes.length).toEqual(2);
n1 = await Note.load(note1.id);