mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-09-16 21:55:37 -05:00
Enhancement: disable-able mail rules, add toggle to overview (#7810)
This commit is contained in:
@@ -43,14 +43,15 @@ import { EditDialogMode } from '../../common/edit-dialog/edit-dialog.component'
|
||||
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
||||
import { SwitchComponent } from '../../common/input/switch/switch.component'
|
||||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
|
||||
import { By } from '@angular/platform-browser'
|
||||
|
||||
const mailAccounts = [
|
||||
{ id: 1, name: 'account1' },
|
||||
{ id: 2, name: 'account2' },
|
||||
]
|
||||
const mailRules = [
|
||||
{ id: 1, name: 'rule1', owner: 1, account: 1 },
|
||||
{ id: 2, name: 'rule2', owner: 2, account: 2 },
|
||||
{ id: 1, name: 'rule1', owner: 1, account: 1, enabled: true },
|
||||
{ id: 2, name: 'rule2', owner: 2, account: 2, enabled: true },
|
||||
]
|
||||
|
||||
describe('MailComponent', () => {
|
||||
@@ -321,4 +322,30 @@ describe('MailComponent', () => {
|
||||
dialog.confirmClicked.emit({ permissions: perms, merge: true })
|
||||
expect(accountPatchSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should update mail rule when enable is toggled', () => {
|
||||
completeSetup()
|
||||
const patchSpy = jest.spyOn(mailRuleService, 'patch')
|
||||
const toggleInput = fixture.debugElement.query(
|
||||
By.css('input[type="checkbox"]')
|
||||
)
|
||||
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
||||
const toastInfoSpy = jest.spyOn(toastService, 'showInfo')
|
||||
// fail first
|
||||
patchSpy.mockReturnValueOnce(
|
||||
throwError(() => new Error('Error getting config'))
|
||||
)
|
||||
toggleInput.nativeElement.click()
|
||||
expect(patchSpy).toHaveBeenCalled()
|
||||
expect(toastErrorSpy).toHaveBeenCalled()
|
||||
// succeed second
|
||||
patchSpy.mockReturnValueOnce(of(mailRules[0] as MailRule))
|
||||
toggleInput.nativeElement.click()
|
||||
patchSpy.mockReturnValueOnce(
|
||||
of({ ...mailRules[0], enabled: false } as MailRule)
|
||||
)
|
||||
toggleInput.nativeElement.click()
|
||||
expect(patchSpy).toHaveBeenCalled()
|
||||
expect(toastInfoSpy).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user