diff --git a/src-ui/src/app/components/manage/mail/mail.component.spec.ts b/src-ui/src/app/components/manage/mail/mail.component.spec.ts
index 4a134b880..14cd10944 100644
--- a/src-ui/src/app/components/manage/mail/mail.component.spec.ts
+++ b/src-ui/src/app/components/manage/mail/mail.component.spec.ts
@@ -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()
+ })
})
diff --git a/src-ui/src/app/components/manage/mail/mail.component.ts b/src-ui/src/app/components/manage/mail/mail.component.ts
index 5d00b6c13..288e8e121 100644
--- a/src-ui/src/app/components/manage/mail/mail.component.ts
+++ b/src-ui/src/app/components/manage/mail/mail.component.ts
@@ -170,6 +170,21 @@ export class MailComponent
this.editMailRule(clone, true)
}
+ onMailRuleEnableToggled(rule: MailRule) {
+ this.mailRuleService.patch(rule).subscribe({
+ next: () => {
+ this.toastService.showInfo(
+ rule.enabled
+ ? $localize`Rule "${rule.name}" enabled.`
+ : $localize`Rule "${rule.name}" disabled.`
+ )
+ },
+ error: (e) => {
+ this.toastService.showError($localize`Error toggling rule.`, e)
+ },
+ })
+ }
+
deleteMailRule(rule: MailRule) {
const modal = this.modalService.open(ConfirmDialogComponent, {
backdrop: 'static',
diff --git a/src-ui/src/styles.scss b/src-ui/src/styles.scss
index c83ebd493..ef856fbc7 100644
--- a/src-ui/src/styles.scss
+++ b/src-ui/src/styles.scss
@@ -369,6 +369,10 @@ textarea,
cursor: not-allowed;
}
+.cursor-pointer {
+ cursor: pointer;
+}
+
ul.pagination {
margin-bottom: 0;
}