mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-10-08 02:06:16 -05:00
Fix: correct save hotkey action when no next document exists (#11027)
This commit is contained in:
@@ -1212,7 +1212,7 @@ describe('DocumentDetailComponent', () => {
|
||||
it('should support keyboard shortcuts', () => {
|
||||
initNormally()
|
||||
|
||||
jest.spyOn(component, 'hasNext').mockReturnValue(true)
|
||||
const hasNextSpy = jest.spyOn(component, 'hasNext').mockReturnValue(true)
|
||||
const nextSpy = jest.spyOn(component, 'nextDoc')
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent('keydown', { key: 'arrowright', ctrlKey: true })
|
||||
@@ -1226,21 +1226,32 @@ describe('DocumentDetailComponent', () => {
|
||||
)
|
||||
expect(prevSpy).toHaveBeenCalled()
|
||||
|
||||
jest.spyOn(openDocumentsService, 'isDirty').mockReturnValue(true)
|
||||
const isDirtySpy = jest
|
||||
.spyOn(openDocumentsService, 'isDirty')
|
||||
.mockReturnValue(true)
|
||||
const saveSpy = jest.spyOn(component, 'save')
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent('keydown', { key: 's', ctrlKey: true })
|
||||
)
|
||||
expect(saveSpy).toHaveBeenCalled()
|
||||
|
||||
jest.spyOn(openDocumentsService, 'isDirty').mockReturnValue(true)
|
||||
jest.spyOn(component, 'hasNext').mockReturnValue(true)
|
||||
hasNextSpy.mockReturnValue(true)
|
||||
const saveNextSpy = jest.spyOn(component, 'saveEditNext')
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent('keydown', { key: 's', ctrlKey: true, shiftKey: true })
|
||||
)
|
||||
expect(saveNextSpy).toHaveBeenCalled()
|
||||
|
||||
saveSpy.mockClear()
|
||||
saveNextSpy.mockClear()
|
||||
isDirtySpy.mockReturnValue(true)
|
||||
hasNextSpy.mockReturnValue(false)
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent('keydown', { key: 's', ctrlKey: true, shiftKey: true })
|
||||
)
|
||||
expect(saveNextSpy).not.toHaveBeenCalled()
|
||||
expect(saveSpy).toHaveBeenCalledWith(true)
|
||||
|
||||
const closeSpy = jest.spyOn(component, 'close')
|
||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'escape' }))
|
||||
expect(closeSpy).toHaveBeenCalled()
|
||||
|
@@ -615,7 +615,10 @@ export class DocumentDetailComponent
|
||||
})
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe(() => {
|
||||
if (this.openDocumentService.isDirty(this.document)) this.saveEditNext()
|
||||
if (this.openDocumentService.isDirty(this.document)) {
|
||||
if (this.hasNext()) this.saveEditNext()
|
||||
else this.save(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user