Toasts for edit dialogs
This commit is contained in:
parent
6447d0820f
commit
117b0b44b3
@ -12,6 +12,7 @@ import {
|
|||||||
NgbDropdownModule,
|
NgbDropdownModule,
|
||||||
NgbModal,
|
NgbModal,
|
||||||
NgbModalModule,
|
NgbModalModule,
|
||||||
|
NgbModalRef,
|
||||||
} from '@ng-bootstrap/ng-bootstrap'
|
} from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { CorrespondentEditDialogComponent } from '../../common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component'
|
import { CorrespondentEditDialogComponent } from '../../common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component'
|
||||||
import { UserEditDialogComponent } from '../../common/edit-dialog/user-edit-dialog/user-edit-dialog.component'
|
import { UserEditDialogComponent } from '../../common/edit-dialog/user-edit-dialog/user-edit-dialog.component'
|
||||||
@ -32,6 +33,7 @@ import { GroupEditDialogComponent } from '../../common/edit-dialog/group-edit-di
|
|||||||
import { CustomFieldEditDialogComponent } from '../../common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component'
|
import { CustomFieldEditDialogComponent } from '../../common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component'
|
||||||
import { WorkflowEditDialogComponent } from '../../common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component'
|
import { WorkflowEditDialogComponent } from '../../common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component'
|
||||||
import { ElementRef } from '@angular/core'
|
import { ElementRef } from '@angular/core'
|
||||||
|
import { ToastService } from 'src/app/services/toast.service'
|
||||||
|
|
||||||
const searchResults = {
|
const searchResults = {
|
||||||
total: 11,
|
total: 11,
|
||||||
@ -118,6 +120,7 @@ describe('GlobalSearchComponent', () => {
|
|||||||
let modalService: NgbModal
|
let modalService: NgbModal
|
||||||
let documentService: DocumentService
|
let documentService: DocumentService
|
||||||
let documentListViewService: DocumentListViewService
|
let documentListViewService: DocumentListViewService
|
||||||
|
let toastService: ToastService
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
@ -137,6 +140,7 @@ describe('GlobalSearchComponent', () => {
|
|||||||
modalService = TestBed.inject(NgbModal)
|
modalService = TestBed.inject(NgbModal)
|
||||||
documentService = TestBed.inject(DocumentService)
|
documentService = TestBed.inject(DocumentService)
|
||||||
documentListViewService = TestBed.inject(DocumentListViewService)
|
documentListViewService = TestBed.inject(DocumentListViewService)
|
||||||
|
toastService = TestBed.inject(ToastService)
|
||||||
|
|
||||||
fixture = TestBed.createComponent(GlobalSearchComponent)
|
fixture = TestBed.createComponent(GlobalSearchComponent)
|
||||||
component = fixture.componentInstance
|
component = fixture.componentInstance
|
||||||
@ -222,6 +226,9 @@ describe('GlobalSearchComponent', () => {
|
|||||||
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
|
const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
|
||||||
const modalSpy = jest.spyOn(modalService, 'open')
|
const modalSpy = jest.spyOn(modalService, 'open')
|
||||||
|
|
||||||
|
let modal: NgbModalRef
|
||||||
|
modalService.activeInstances.subscribe((m) => (modal = m[m.length - 1]))
|
||||||
|
|
||||||
component.primaryAction('document', object)
|
component.primaryAction('document', object)
|
||||||
expect(routerSpy).toHaveBeenCalledWith(['/documents', object.id])
|
expect(routerSpy).toHaveBeenCalledWith(['/documents', object.id])
|
||||||
|
|
||||||
@ -274,6 +281,18 @@ describe('GlobalSearchComponent', () => {
|
|||||||
expect(modalSpy).toHaveBeenCalledWith(WorkflowEditDialogComponent, {
|
expect(modalSpy).toHaveBeenCalledWith(WorkflowEditDialogComponent, {
|
||||||
size: 'xl',
|
size: 'xl',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const editDialog = modal.componentInstance as CustomFieldEditDialogComponent
|
||||||
|
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
||||||
|
const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
|
||||||
|
|
||||||
|
// fail first
|
||||||
|
editDialog.failed.emit({ error: 'error creating item' })
|
||||||
|
expect(toastErrorSpy).toHaveBeenCalled()
|
||||||
|
|
||||||
|
// succeed
|
||||||
|
editDialog.succeeded.emit(true)
|
||||||
|
expect(toastInfoSpy).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support secondary action', () => {
|
it('should support secondary action', () => {
|
||||||
@ -284,6 +303,10 @@ describe('GlobalSearchComponent', () => {
|
|||||||
|
|
||||||
const correspondent = searchResults.correspondents[0]
|
const correspondent = searchResults.correspondents[0]
|
||||||
const modalSpy = jest.spyOn(modalService, 'open')
|
const modalSpy = jest.spyOn(modalService, 'open')
|
||||||
|
|
||||||
|
let modal: NgbModalRef
|
||||||
|
modalService.activeInstances.subscribe((m) => (modal = m[m.length - 1]))
|
||||||
|
|
||||||
component.secondaryAction('correspondent', correspondent)
|
component.secondaryAction('correspondent', correspondent)
|
||||||
expect(modalSpy).toHaveBeenCalledWith(CorrespondentEditDialogComponent, {
|
expect(modalSpy).toHaveBeenCalledWith(CorrespondentEditDialogComponent, {
|
||||||
size: 'md',
|
size: 'md',
|
||||||
@ -303,6 +326,18 @@ describe('GlobalSearchComponent', () => {
|
|||||||
expect(modalSpy).toHaveBeenCalledWith(CorrespondentEditDialogComponent, {
|
expect(modalSpy).toHaveBeenCalledWith(CorrespondentEditDialogComponent, {
|
||||||
size: 'md',
|
size: 'md',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const editDialog = modal.componentInstance as CustomFieldEditDialogComponent
|
||||||
|
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
||||||
|
const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
|
||||||
|
|
||||||
|
// fail first
|
||||||
|
editDialog.failed.emit({ error: 'error creating item' })
|
||||||
|
expect(toastErrorSpy).toHaveBeenCalled()
|
||||||
|
|
||||||
|
// succeed
|
||||||
|
editDialog.succeeded.emit(true)
|
||||||
|
expect(toastInfoSpy).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support reset', () => {
|
it('should support reset', () => {
|
||||||
|
@ -1,42 +1,43 @@
|
|||||||
import {
|
import {
|
||||||
Component,
|
Component,
|
||||||
ElementRef,
|
|
||||||
HostListener,
|
|
||||||
QueryList,
|
|
||||||
ViewChild,
|
ViewChild,
|
||||||
|
ElementRef,
|
||||||
ViewChildren,
|
ViewChildren,
|
||||||
|
QueryList,
|
||||||
|
HostListener,
|
||||||
} from '@angular/core'
|
} from '@angular/core'
|
||||||
import { Router } from '@angular/router'
|
import { Router } from '@angular/router'
|
||||||
import { NgbDropdown, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
|
import { NgbDropdown, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { Subject, debounceTime, distinctUntilChanged, filter, map } from 'rxjs'
|
import { Subject, debounceTime, distinctUntilChanged, filter } from 'rxjs'
|
||||||
|
import {
|
||||||
|
FILTER_HAS_CORRESPONDENT_ANY,
|
||||||
|
FILTER_HAS_DOCUMENT_TYPE_ANY,
|
||||||
|
FILTER_HAS_STORAGE_PATH_ANY,
|
||||||
|
FILTER_HAS_ANY_TAG,
|
||||||
|
} from 'src/app/data/filter-rule-type'
|
||||||
import { ObjectWithId } from 'src/app/data/object-with-id'
|
import { ObjectWithId } from 'src/app/data/object-with-id'
|
||||||
|
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
|
||||||
|
import {
|
||||||
|
PermissionsService,
|
||||||
|
PermissionAction,
|
||||||
|
} from 'src/app/services/permissions.service'
|
||||||
|
import { DocumentService } from 'src/app/services/rest/document.service'
|
||||||
import {
|
import {
|
||||||
GlobalSearchResult,
|
GlobalSearchResult,
|
||||||
SearchService,
|
SearchService,
|
||||||
} from 'src/app/services/rest/search.service'
|
} from 'src/app/services/rest/search.service'
|
||||||
|
import { ToastService } from 'src/app/services/toast.service'
|
||||||
import { CorrespondentEditDialogComponent } from '../../common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component'
|
import { CorrespondentEditDialogComponent } from '../../common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component'
|
||||||
import { EditDialogMode } from '../../common/edit-dialog/edit-dialog.component'
|
|
||||||
import { DocumentTypeEditDialogComponent } from '../../common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component'
|
|
||||||
import { StoragePathEditDialogComponent } from '../../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component'
|
|
||||||
import { TagEditDialogComponent } from '../../common/edit-dialog/tag-edit-dialog/tag-edit-dialog.component'
|
|
||||||
import { CustomFieldEditDialogComponent } from '../../common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component'
|
import { CustomFieldEditDialogComponent } from '../../common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component'
|
||||||
|
import { DocumentTypeEditDialogComponent } from '../../common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component'
|
||||||
|
import { EditDialogMode } from '../../common/edit-dialog/edit-dialog.component'
|
||||||
import { GroupEditDialogComponent } from '../../common/edit-dialog/group-edit-dialog/group-edit-dialog.component'
|
import { GroupEditDialogComponent } from '../../common/edit-dialog/group-edit-dialog/group-edit-dialog.component'
|
||||||
import { MailAccountEditDialogComponent } from '../../common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component'
|
import { MailAccountEditDialogComponent } from '../../common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component'
|
||||||
import { MailRuleEditDialogComponent } from '../../common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component'
|
import { MailRuleEditDialogComponent } from '../../common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component'
|
||||||
|
import { StoragePathEditDialogComponent } from '../../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component'
|
||||||
|
import { TagEditDialogComponent } from '../../common/edit-dialog/tag-edit-dialog/tag-edit-dialog.component'
|
||||||
import { UserEditDialogComponent } from '../../common/edit-dialog/user-edit-dialog/user-edit-dialog.component'
|
import { UserEditDialogComponent } from '../../common/edit-dialog/user-edit-dialog/user-edit-dialog.component'
|
||||||
import { WorkflowEditDialogComponent } from '../../common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component'
|
import { WorkflowEditDialogComponent } from '../../common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component'
|
||||||
import { DocumentService } from 'src/app/services/rest/document.service'
|
|
||||||
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
|
|
||||||
import {
|
|
||||||
FILTER_HAS_ANY_TAG,
|
|
||||||
FILTER_HAS_CORRESPONDENT_ANY,
|
|
||||||
FILTER_HAS_DOCUMENT_TYPE_ANY,
|
|
||||||
FILTER_HAS_STORAGE_PATH_ANY,
|
|
||||||
} from 'src/app/data/filter-rule-type'
|
|
||||||
import {
|
|
||||||
PermissionAction,
|
|
||||||
PermissionsService,
|
|
||||||
} from 'src/app/services/permissions.service'
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'pngx-global-search',
|
selector: 'pngx-global-search',
|
||||||
@ -97,7 +98,8 @@ export class GlobalSearchComponent {
|
|||||||
private modalService: NgbModal,
|
private modalService: NgbModal,
|
||||||
private documentService: DocumentService,
|
private documentService: DocumentService,
|
||||||
private documentListViewService: DocumentListViewService,
|
private documentListViewService: DocumentListViewService,
|
||||||
private permissionsService: PermissionsService
|
private permissionsService: PermissionsService,
|
||||||
|
private toastService: ToastService
|
||||||
) {
|
) {
|
||||||
this.queryDebounce = new Subject<string>()
|
this.queryDebounce = new Subject<string>()
|
||||||
|
|
||||||
@ -179,6 +181,12 @@ export class GlobalSearchComponent {
|
|||||||
)
|
)
|
||||||
modalRef.componentInstance.dialogMode = EditDialogMode.EDIT
|
modalRef.componentInstance.dialogMode = EditDialogMode.EDIT
|
||||||
modalRef.componentInstance.object = object
|
modalRef.componentInstance.object = object
|
||||||
|
modalRef.componentInstance.succeeded.subscribe(() => {
|
||||||
|
this.toastService.showInfo($localize`Successfully updated object.`)
|
||||||
|
})
|
||||||
|
modalRef.componentInstance.failed.subscribe((e) => {
|
||||||
|
this.toastService.showError($localize`Error occurred saving object.`, e)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,6 +219,12 @@ export class GlobalSearchComponent {
|
|||||||
)
|
)
|
||||||
modalRef.componentInstance.dialogMode = EditDialogMode.EDIT
|
modalRef.componentInstance.dialogMode = EditDialogMode.EDIT
|
||||||
modalRef.componentInstance.object = object
|
modalRef.componentInstance.object = object
|
||||||
|
modalRef.componentInstance.succeeded.subscribe(() => {
|
||||||
|
this.toastService.showInfo($localize`Successfully updated object.`)
|
||||||
|
})
|
||||||
|
modalRef.componentInstance.failed.subscribe((e) => {
|
||||||
|
this.toastService.showError($localize`Error occurred saving object.`, e)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user