RuleModeSwitcher rebuilt a rule's actions from scratch, so changing the mode of e.g. .m.rule.is_user_mention silently dropped its highlight tweak account-wide. Derive the existing highlight/custom-sound tweaks from the rule's current actions and pass them through as NotificationModeOptions. Adds getNotificationModeOptionsFromActions + unit tests. Fixes #19 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { PushRuleActionName, TweakName } from 'matrix-js-sdk';
|
|
import { getNotificationModeOptionsFromActions } from './useNotificationMode';
|
|
|
|
test('getNotificationModeOptionsFromActions: no tweaks -> no highlight, no sound value', () => {
|
|
const options = getNotificationModeOptionsFromActions([PushRuleActionName.Notify]);
|
|
assert.deepEqual(options, { soundValue: undefined, highlight: false });
|
|
});
|
|
|
|
test('getNotificationModeOptionsFromActions: picks up highlight: true', () => {
|
|
const options = getNotificationModeOptionsFromActions([
|
|
PushRuleActionName.Notify,
|
|
{ set_tweak: TweakName.Highlight, value: true },
|
|
]);
|
|
assert.equal(options.highlight, true);
|
|
});
|
|
|
|
test('getNotificationModeOptionsFromActions: highlight: false is not treated as set', () => {
|
|
const options = getNotificationModeOptionsFromActions([
|
|
PushRuleActionName.Notify,
|
|
{ set_tweak: TweakName.Highlight, value: false },
|
|
]);
|
|
assert.equal(options.highlight, false);
|
|
});
|
|
|
|
test('getNotificationModeOptionsFromActions: picks up a custom sound value', () => {
|
|
const options = getNotificationModeOptionsFromActions([
|
|
PushRuleActionName.Notify,
|
|
{ set_tweak: TweakName.Sound, value: 'ping.ogg' },
|
|
]);
|
|
assert.equal(options.soundValue, 'ping.ogg');
|
|
});
|
|
|
|
test('getNotificationModeOptionsFromActions: picks up both tweaks together', () => {
|
|
const options = getNotificationModeOptionsFromActions([
|
|
PushRuleActionName.Notify,
|
|
{ set_tweak: TweakName.Sound, value: 'ping.ogg' },
|
|
{ set_tweak: TweakName.Highlight, value: true },
|
|
]);
|
|
assert.deepEqual(options, { soundValue: 'ping.ogg', highlight: true });
|
|
});
|