})
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
)
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() {
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) {