You've already forked joplin
							
							
				mirror of
				https://github.com/laurent22/joplin.git
				synced 2025-10-31 00:07:48 +02:00 
			
		
		
		
	This commit is contained in:
		| @@ -23,6 +23,7 @@ import ItemChange from '@joplin/lib/models/ItemChange'; | ||||
| import { getDisplayParentId } from '@joplin/lib/services/trash'; | ||||
| import { itemIsReadOnlySync, ItemSlice } from '@joplin/lib/models/utils/readOnly'; | ||||
| import { LayoutChangeEvent } from 'react-native'; | ||||
| import shim from '@joplin/lib/shim'; | ||||
|  | ||||
| interface WrapperProps { | ||||
| } | ||||
| @@ -140,6 +141,24 @@ describe('Note', () => { | ||||
| 		}); | ||||
| 	}); | ||||
|  | ||||
| 	it('pressing "delete permanently" should permanently delete a note', async () => { | ||||
| 		const noteId = await openNewNote({ title: 'To be deleted', body: '...', deleted_time: Date.now() }); | ||||
| 		render(<WrappedNoteScreen />); | ||||
|  | ||||
| 		// Permanently delete note shows a confirmation dialog -- mock it. | ||||
| 		const deleteId = 0; | ||||
| 		shim.showMessageBox = jest.fn(async () => deleteId); | ||||
|  | ||||
| 		await openNoteActionsMenu(); | ||||
| 		const deleteButton = await screen.findByText('Permanently delete note'); | ||||
| 		fireEvent.press(deleteButton); | ||||
|  | ||||
| 		await waitFor(async () => { | ||||
| 			expect(await Note.load(noteId)).toBeUndefined(); | ||||
| 		}); | ||||
| 		expect(shim.showMessageBox).toHaveBeenCalled(); | ||||
| 	}); | ||||
|  | ||||
| 	it('delete should be disabled in a read-only note', async () => { | ||||
| 		const shareId = 'testShare'; | ||||
| 		const noteId = await openNewNote({ | ||||
|   | ||||
| @@ -627,21 +627,6 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B | ||||
| 		await shared.saveOneProperty(this, name, value); | ||||
| 	} | ||||
|  | ||||
| 	private async deleteNote_onPress() { | ||||
| 		const note = this.state.note; | ||||
| 		if (!note.id) return; | ||||
|  | ||||
| 		const folderId = note.parent_id; | ||||
|  | ||||
| 		await Note.delete(note.id, { toTrash: true, sourceDescription: 'Delete note button' }); | ||||
|  | ||||
| 		this.props.dispatch({ | ||||
| 			type: 'NAV_GO', | ||||
| 			routeName: 'Notes', | ||||
| 			folderId: folderId, | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	private async pickDocuments() { | ||||
| 		const result = await pickDocument({ multiple: true }); | ||||
| 		return result; | ||||
| @@ -1283,30 +1268,33 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		output.push({ | ||||
| 			title: _('Delete'), | ||||
| 			onPress: () => { | ||||
| 				void this.deleteNote_onPress(); | ||||
| 			}, | ||||
| 			disabled: readOnly, | ||||
| 		}); | ||||
| 		const commandService = CommandService.instance(); | ||||
| 		const whenContext = commandService.currentWhenClauseContext(); | ||||
| 		const addButtonFromCommand = (commandName: string, title?: string) => { | ||||
| 			if (commandName === '-') { | ||||
| 				output.push({ isDivider: true }); | ||||
| 			} else { | ||||
| 				output.push({ | ||||
| 					title: title ?? commandService.description(commandName), | ||||
| 					onPress: async () => { | ||||
| 						void commandService.execute(commandName); | ||||
| 					}, | ||||
| 					disabled: !commandService.isEnabled(commandName, whenContext), | ||||
| 				}); | ||||
| 			} | ||||
| 		}; | ||||
|  | ||||
| 		if (whenContext.inTrash) { | ||||
| 			addButtonFromCommand('permanentlyDeleteNote'); | ||||
| 		} else { | ||||
| 			addButtonFromCommand('deleteNote', _('Delete')); | ||||
| 		} | ||||
|  | ||||
| 		if (pluginCommands.length) { | ||||
| 			output.push({ isDivider: true }); | ||||
|  | ||||
| 			const commandService = CommandService.instance(); | ||||
| 			for (const commandName of pluginCommands) { | ||||
| 				if (commandName === '-') { | ||||
| 					output.push({ isDivider: true }); | ||||
| 				} else { | ||||
| 					output.push({ | ||||
| 						title: commandService.description(commandName), | ||||
| 						onPress: async () => { | ||||
| 							void commandService.execute(commandName); | ||||
| 						}, | ||||
| 						disabled: !commandService.isEnabled(commandName), | ||||
| 					}); | ||||
| 				} | ||||
| 				addButtonFromCommand(commandName); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user