Tests for Adding a tag in all notes leads to select first note

I am working on this issue Adding a tag in all notes leads to select first note · Issue #4911 · laurent22/joplin · GitHub.
I have already set up working repository in local and changes suggested here Desktop: Resolves #4911: Adding a tag in all notes leads to select first note by Aksh-Konda · Pull Request #4990 · laurent22/joplin · GitHub.

This PR was closed because there were not enough unit test to test the reducer. I would make all test. Can someone list what test exactly to be included ?

Ideally you should have some tests that check the issue itself, e.g. they should fail without the fix but pass with it. Also ensure all code paths affected by your change are tested.

No one could give you the exact list of tests to add, this is like 80% of the work here. Especially since the fix itself was already implemented.

okay


I did log out state and parentItem and all the changes made in the PR i linked above.
I see this error.
lastSelectedNotesIds only has three keys Folder, Tag and search. So There is no smartFilter used in lastSelectedNotesIds.

Can you tell me what all is included in smart filter except All Notes ?

I tried adding SmartFilter as type in lastSelectedNotesId and the bug was again encountered, so this was wrong fix suggestion.

This is the PR fix: Adding tag when smart filter is selected by Udit-takkar · Pull Request #5911 · laurent22/joplin · GitHub I raised. I ran all tests and posted demo video.

The test in the PR is not right. What i want to test is

  1. SELECT any note
  2. Select All Notes smart filter
  3. Adding a Tag
    Now after this notes refreshed and the selected note id should not change to first in the list.

Here are all actions after log
VISIBLE_DIALOGS_ADD -> TAG_UPDATE_ONE -> VISIBLE_DIALOGS_REMOVE ->SET_NOTE_TAGS->TAG_UPDATE_ALL-> Refreshing Notes

How can I do this?

it('should record last selected notes when all notes filter is on and new tag is added', async () => {
		const folders = await createNTestFolders(2);
		const notes = [];
		for (let i = 0; i < folders.length; i++) {
			notes.push(...await createNTestNotes(2, folders[i]));
		}

		// Initialize state with selected note at 1 index
		let state = initTestState(folders, [0], notes.slice(), [1]);
		// Turn on 'All Notes' filter
		state = reducer(state, { type: 'SMART_FILTER_SELECT', id: ALL_NOTES_FILTER_ID });
		// Add a Tag
		const tag = await createNTestTags(1);

		state = reducer(state, { type: 'TAG_UPDATE_ONE' ,item: tag[0] });

		// Refresh Notes ??


		expect(state.selectedNoteIds[0]).toEqual(notes[1].id);
	});

refreshing of notes is called in generalMiddleware function in /lib/BaseApplication.ts. I am guessing i would have to use TestApp class from /lib/testing/test-utils.ts. But I can't figure out how exactly to properly go forward?

testApp = new TestApp();
		await testApp.start(['--no-welcome']);
		done();

Should I dispatch actions like testApp.dispatch({ type: 'FOLDER_SELECT', id: id(folders[0]) }); . So that the refreshNotes would also be triggered?
@roman_r_m