1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-10 22:11:50 +02:00

Desktop: Fixes #12197: Fix inserting note links using the mouse (#12199)

This commit is contained in:
Henry Heino
2025-05-01 12:07:33 -07:00
committed by GitHub
parent e58e419c1b
commit d72224a6b9
3 changed files with 78 additions and 28 deletions

View File

@@ -65,22 +65,53 @@ test.describe('goToAnything', () => {
}
});
test('should be possible to show the set tags dialog from goToAnything', async ({ electronApp, mainWindow }) => {
const mainScreen = await new MainScreen(mainWindow).setup();
await mainScreen.createNewNote('Test note');
for (const activateWithClick of [true, false]) {
test(`should be possible to show the set tags dialog from goToAnything (activate with click: ${activateWithClick})`, async ({ electronApp, mainWindow }) => {
const mainScreen = await new MainScreen(mainWindow).setup();
await mainScreen.createNewNote('Test note');
const goToAnything = mainScreen.goToAnything;
await goToAnything.open(electronApp);
await goToAnything.inputLocator.fill(':setTags');
const goToAnything = mainScreen.goToAnything;
await goToAnything.open(electronApp);
await goToAnything.inputLocator.fill(':setTags');
// Should show a matching command
await expect(goToAnything.containerLocator.getByText('Tags (setTags)')).toBeAttached();
// Should show a matching command
const result = goToAnything.resultLocator('Tags (setTags)');
await expect(result).toBeAttached();
if (activateWithClick) {
await result.click();
} else {
await mainWindow.keyboard.press('Enter');
}
await goToAnything.expectToBeClosed();
await mainWindow.keyboard.press('Enter');
await goToAnything.expectToBeClosed();
// Should show the "set tags" dialog
const setTagsLabel = mainWindow.getByText('Add or remove tags:');
await expect(setTagsLabel).toBeVisible();
});
// Should show the "set tags" dialog
const setTagsLabel = mainWindow.getByText('Add or remove tags:');
await expect(setTagsLabel).toBeVisible();
});
// The note link dialog internally uses the same component as GotoAnything
test(`should be possible to attach note links (activate with click: ${activateWithClick})`, async ({ electronApp, mainWindow }) => {
const mainScreen = await new MainScreen(mainWindow).setup();
await mainScreen.createNewNote('Target note');
await mainScreen.createNewNote('Test note');
const goToAnything = mainScreen.goToAnything;
await goToAnything.openLinkToNote(electronApp);
const result = goToAnything.resultLocator('Target note');
await goToAnything.searchForWithRetry('Target not', result);
// Should show a matching command
await expect(result).toBeAttached();
if (activateWithClick) {
await result.click();
} else {
await mainWindow.keyboard.press('Enter');
}
await goToAnything.expectToBeClosed();
// Should have added the link
await expect(mainScreen.noteEditor.codeMirrorEditor).toContainText('[Target note]');
});
}
});

View File

@@ -12,6 +12,10 @@ export default class GoToAnything {
this.inputLocator = this.containerLocator.getByRole('textbox');
}
public async waitFor() {
await this.containerLocator.waitFor();
}
public async open(electronApp: ElectronApplication) {
await this.mainScreen.waitFor();
await activateMainMenuItem(electronApp, 'Goto Anything...');
@@ -19,8 +23,31 @@ export default class GoToAnything {
return this.waitFor();
}
public async waitFor() {
await this.containerLocator.waitFor();
public async openLinkToNote(electronApp: ElectronApplication) {
await this.mainScreen.waitFor();
await activateMainMenuItem(electronApp, 'Link to note...');
return this.waitFor();
}
public resultLocator(resultText: string|RegExp) {
return this.containerLocator.getByRole('option', { name: resultText });
}
public async searchForWithRetry(query: string, resultLocator: Locator) {
// If note indexing hasn't finished, it's sometimes necessary to search multiple times.
// This expect.poll retries the search if it initially fails.
await expect.poll(async () => {
await this.inputLocator.clear();
await this.inputLocator.fill(query);
try {
await expect(resultLocator).toBeVisible({ timeout: 1000 });
} catch (error) {
// Return, rather than throw, the error -- expect.poll doesn't retry
// if the callback throws.
return error;
}
return true;
}, { timeout: 10_000 }).toBe(true);
}
public async expectToBeClosed() {

View File

@@ -572,16 +572,8 @@ class DialogComponent extends React.PureComponent<Props, State> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
private listItem_onClick(event: any) {
const itemId = event.currentTarget.getAttribute('data-id');
const parentId = event.currentTarget.getAttribute('data-parent-id');
const itemType = Number(event.currentTarget.getAttribute('data-type'));
void this.gotoItem({
id: itemId,
parent_id: parentId,
type: itemType,
commandArgs: this.state.commandArgs,
});
const targetResultId = event.currentTarget.getAttribute('id');
void this.gotoItem(this.selectedItem(targetResultId));
}
public renderItem(item: GotoAnythingSearchResult, index: number) {
@@ -642,8 +634,8 @@ class DialogComponent extends React.PureComponent<Props, State> {
return -1;
}
public selectedItem() {
const index = this.selectedItemIndex();
public selectedItem(itemId: string = undefined) {
const index = this.selectedItemIndex(undefined, itemId);
if (index < 0) return null;
return { ...this.state.results[index], commandArgs: this.state.commandArgs };
}