diff --git a/.eslintignore b/.eslintignore index 1eb1fc028..e5481d2b2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -456,6 +456,7 @@ packages/app-desktop/integration-tests/models/MainScreen.js packages/app-desktop/integration-tests/models/NoteEditorScreen.js packages/app-desktop/integration-tests/models/SettingsScreen.js packages/app-desktop/integration-tests/models/Sidebar.js +packages/app-desktop/integration-tests/noteList.spec.js packages/app-desktop/integration-tests/richTextEditor.spec.js packages/app-desktop/integration-tests/sidebar.spec.js packages/app-desktop/integration-tests/simpleBackup.spec.js diff --git a/.gitignore b/.gitignore index c70fbe668..7beb46eb8 100644 --- a/.gitignore +++ b/.gitignore @@ -435,6 +435,7 @@ packages/app-desktop/integration-tests/models/MainScreen.js packages/app-desktop/integration-tests/models/NoteEditorScreen.js packages/app-desktop/integration-tests/models/SettingsScreen.js packages/app-desktop/integration-tests/models/Sidebar.js +packages/app-desktop/integration-tests/noteList.spec.js packages/app-desktop/integration-tests/richTextEditor.spec.js packages/app-desktop/integration-tests/sidebar.spec.js packages/app-desktop/integration-tests/simpleBackup.spec.js diff --git a/packages/app-desktop/integration-tests/models/MainScreen.ts b/packages/app-desktop/integration-tests/models/MainScreen.ts index dd645a2f3..30ac7b1b5 100644 --- a/packages/app-desktop/integration-tests/models/MainScreen.ts +++ b/packages/app-desktop/integration-tests/models/MainScreen.ts @@ -48,4 +48,9 @@ export default class MainScreen { throw new Error('Unable to find settings menu item in application menus.'); } } + + public async search(text: string) { + const searchBar = this.page.getByPlaceholder('Search...'); + await searchBar.fill(text); + } } diff --git a/packages/app-desktop/integration-tests/noteList.spec.ts b/packages/app-desktop/integration-tests/noteList.spec.ts new file mode 100644 index 000000000..01117ab7a --- /dev/null +++ b/packages/app-desktop/integration-tests/noteList.spec.ts @@ -0,0 +1,38 @@ +import { test, expect } from './util/test'; +import MainScreen from './models/MainScreen'; + +test.describe('noteList', () => { + test('should be possible to edit notes in a different notebook when searching', async ({ mainWindow }) => { + const mainScreen = new MainScreen(mainWindow); + const sidebar = mainScreen.sidebar; + + const folderAHeader = await sidebar.createNewFolder('Folder A'); + await expect(folderAHeader).toBeVisible(); + + const folderBHeader = await sidebar.createNewFolder('Folder B'); + await expect(folderBHeader).toBeVisible(); + await folderBHeader.click(); + + await mainScreen.createNewNote('note-1'); + + await folderAHeader.click(); + await mainScreen.createNewNote('note-2'); + + // Search for and focus a note different from the folder we were in before searching. + await mainScreen.search('/note-1'); + const note1Result = mainScreen.noteListContainer.getByText('note-1'); + await expect(note1Result).toBeAttached(); + await note1Result.click(); + + // Typing should not cause the note to disappear + const editor = mainScreen.noteEditor; + await editor.codeMirrorEditor.click(); + await mainWindow.keyboard.type('[Testing...](http://example.com/)'); + + // Wait to render + await expect(editor.getNoteViewerIframe().locator('a', { hasText: 'Testing...' })).toBeVisible(); + + // Updating the title should force the sidebar to update sooner + await expect(editor.noteTitleInput).toHaveValue('note-1'); + }); +}); diff --git a/packages/lib/reducer.ts b/packages/lib/reducer.ts index 0e9823b09..4cb0b79cc 100644 --- a/packages/lib/reducer.ts +++ b/packages/lib/reducer.ts @@ -963,13 +963,14 @@ const reducer = produce((draft: Draft = defaultState, action: any) => { for (let i = 0; i < newNotes.length; i++) { const n = newNotes[i]; if (n.id === modNote.id) { + const previousDisplayParentId = ('parent_id' in n) ? getDisplayParentId(n, draft.folders.find(f => f.id === n.parent_id)) : ''; if (n.is_conflict && !modNote.is_conflict) { // Note was a conflict but was moved outside of // the conflict folder newNotes.splice(i, 1); noteFolderHasChanged = true; movedNotePreviousIndex = i; - } else if (isViewingAllNotes || noteIsInFolder(modNote, draft.selectedFolderId)) { + } else if (isViewingAllNotes || noteIsInFolder(modNote, previousDisplayParentId)) { // Note is still in the same folder // Merge the properties that have changed (in modNote) into // the object we already have.