From 2e2362e2dfd6686bb6c33dd097ef2280a021c484 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 16 Jan 2024 15:18:26 -0800 Subject: [PATCH] Fix: outdated confirm dialog confirm --- .../document-detail/document-detail.component.spec.ts | 6 ++++++ .../components/document-detail/document-detail.component.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts index 51a77fb91..e2a148bb9 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts @@ -968,6 +968,8 @@ describe('DocumentDetailComponent', () => { }) it('should warn when open document does not match doc retrieved from backend on init', () => { + let openModal: NgbModalRef + modalService.activeInstances.subscribe((modals) => (openModal = modals[0])) const modalSpy = jest.spyOn(modalService, 'open') const openDoc = Object.assign({}, doc) // simulate a document being modified elsewhere and db updated @@ -986,6 +988,10 @@ describe('DocumentDetailComponent', () => { ) fixture.detectChanges() // calls ngOnInit expect(modalSpy).toHaveBeenCalledWith(ConfirmDialogComponent) + const closeSpy = jest.spyOn(openModal, 'close') + const confirmDialog = openModal.componentInstance as ConfirmDialogComponent + confirmDialog.confirmClicked.next(confirmDialog) + expect(closeSpy).toHaveBeenCalled() }) function initNormally() { diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts index 16eb9599c..0e79b3deb 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.ts @@ -309,6 +309,9 @@ export class DocumentDetailComponent modal.componentInstance.message = $localize`Saving the document here may overwrite other changes that were made. To restore the existing version, discard your changes or close the document.` modal.componentInstance.cancelBtnClass = 'visually-hidden' modal.componentInstance.btnCaption = $localize`Ok` + modal.componentInstance.confirmClicked.subscribe(() => + modal.close() + ) } if (this.documentForm.dirty) {