Skip to content

Commit

Permalink
All: Fixes laurent22#2803: Remember last selected note (laurent22#2809)
Browse files Browse the repository at this point in the history
* Fix : Remember last selected note

Fixes laurent22#2803

* Add unit test
  • Loading branch information
naviji committed Mar 21, 2020
1 parent 4249884 commit 3ecd29d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 30 additions & 0 deletions CliClient/tests/reducer.js
Expand Up @@ -462,6 +462,36 @@ describe('Reducer', function() {
expect(getIds(state.forwardHistoryNotes)).toEqual([]);
}));

it('should remember the last seen note of a notebook', asyncTest(async () => {
const folders = await createNTestFolders(2);
const notes = [];
for (let i = 0; i < folders.length; i++) {
notes.push(...await createNTestNotes(5, folders[i]));
}

let state = initTestState(folders, 0, notes.slice(0,5), [0]);

state = goToNote(notes, [1], state);
state = goToNote(notes, [2], state);
state = goToNote(notes, [3], state);
state = goToNote(notes, [4], state); // last seen note is notes[4]


// go to second folder
state = reducer(state, { type: 'FOLDER_SELECT', id: folders[1].id, historyAction: 'goto' });
state = goToNote(notes, [5], state);
state = goToNote(notes, [6], state);


// return to first folder
state = reducer(state, { type: 'FOLDER_SELECT', id: folders[0].id, historyAction: 'goto' });

expect(state.lastSelectedNotesIds.Folder[folders[0].id]).toEqual([notes[4].id]);

// return to second folder
state = reducer(state, { type: 'FOLDER_SELECT', id: folders[1].id, historyAction: 'goto' });
expect(state.lastSelectedNotesIds.Folder[folders[1].id]).toEqual([notes[6].id]);

}));

});
2 changes: 0 additions & 2 deletions ReactNativeClient/lib/reducer.js
Expand Up @@ -365,8 +365,6 @@ function changeSelectedNotes(state, action, options = null) {
newState.backwardHistoryNotes = backwardHistoryNotes;
newState.forwardHistoryNotes = forwardHistoryNotes;

return newState;

} else if (action.type === 'NOTE_SELECT_ADD') {
if (!noteIds.length) return state;
newState.selectedNoteIds = ArrayUtils.unique(newState.selectedNoteIds.concat(noteIds));
Expand Down

0 comments on commit 3ecd29d

Please sign in to comment.