Merge matrix-react-sdk into element-web
Merge remote-tracking branch 'repomerge/t3chguy/repomerge' into t3chguy/repo-merge Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
commit
f0ee7f7905
3265 changed files with 484599 additions and 699 deletions
87
test/unit-tests/notifications/ContentRules-test.ts
Normal file
87
test/unit-tests/notifications/ContentRules-test.ts
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { TweakName, PushRuleActionName, TweakHighlight, TweakSound } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { ContentRules, PushRuleVectorState } from "../../../src/notifications";
|
||||
|
||||
const NORMAL_RULE = {
|
||||
actions: [PushRuleActionName.Notify, { set_tweak: TweakName.Highlight, value: false } as TweakHighlight],
|
||||
default: false,
|
||||
enabled: true,
|
||||
pattern: "vdh2",
|
||||
rule_id: "vdh2",
|
||||
};
|
||||
|
||||
const LOUD_RULE = {
|
||||
actions: [
|
||||
PushRuleActionName.Notify,
|
||||
{ set_tweak: TweakName.Highlight } as TweakHighlight,
|
||||
{ set_tweak: TweakName.Sound, value: "default" } as TweakSound,
|
||||
],
|
||||
default: false,
|
||||
enabled: true,
|
||||
pattern: "vdh2",
|
||||
rule_id: "vdh2",
|
||||
};
|
||||
|
||||
const USERNAME_RULE = {
|
||||
actions: [
|
||||
PushRuleActionName.Notify,
|
||||
{ set_tweak: TweakName.Sound, value: "default" } as TweakSound,
|
||||
{ set_tweak: TweakName.Highlight } as TweakHighlight,
|
||||
],
|
||||
default: true,
|
||||
enabled: true,
|
||||
pattern: "richvdh",
|
||||
rule_id: ".m.rule.contains_user_name",
|
||||
};
|
||||
|
||||
describe("ContentRules", function () {
|
||||
describe("parseContentRules", function () {
|
||||
it("should handle there being no keyword rules", function () {
|
||||
const rules = { global: { content: [USERNAME_RULE] } };
|
||||
const parsed = ContentRules.parseContentRules(rules);
|
||||
expect(parsed.rules).toEqual([]);
|
||||
expect(parsed.vectorState).toEqual(PushRuleVectorState.ON);
|
||||
expect(parsed.externalRules).toEqual([]);
|
||||
});
|
||||
|
||||
it("should parse regular keyword notifications", function () {
|
||||
const rules = { global: { content: [NORMAL_RULE, USERNAME_RULE] } };
|
||||
|
||||
const parsed = ContentRules.parseContentRules(rules);
|
||||
expect(parsed.rules.length).toEqual(1);
|
||||
expect(parsed.rules[0]).toEqual(NORMAL_RULE);
|
||||
expect(parsed.vectorState).toEqual(PushRuleVectorState.ON);
|
||||
expect(parsed.externalRules).toEqual([]);
|
||||
});
|
||||
|
||||
it("should parse loud keyword notifications", function () {
|
||||
const rules = { global: { content: [LOUD_RULE, USERNAME_RULE] } };
|
||||
|
||||
const parsed = ContentRules.parseContentRules(rules);
|
||||
expect(parsed.rules.length).toEqual(1);
|
||||
expect(parsed.rules[0]).toEqual(LOUD_RULE);
|
||||
expect(parsed.vectorState).toEqual(PushRuleVectorState.LOUD);
|
||||
expect(parsed.externalRules).toEqual([]);
|
||||
});
|
||||
|
||||
it("should parse mixed keyword notifications", function () {
|
||||
const rules = { global: { content: [LOUD_RULE, NORMAL_RULE, USERNAME_RULE] } };
|
||||
|
||||
const parsed = ContentRules.parseContentRules(rules);
|
||||
expect(parsed.rules.length).toEqual(1);
|
||||
expect(parsed.rules[0]).toEqual(LOUD_RULE);
|
||||
expect(parsed.vectorState).toEqual(PushRuleVectorState.LOUD);
|
||||
expect(parsed.externalRules.length).toEqual(1);
|
||||
expect(parsed.externalRules[0]).toEqual(NORMAL_RULE);
|
||||
});
|
||||
});
|
||||
});
|
57
test/unit-tests/notifications/PushRuleVectorState-test.ts
Normal file
57
test/unit-tests/notifications/PushRuleVectorState-test.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { PushRuleActionName, TweakHighlight, TweakName, TweakSound } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { PushRuleVectorState } from "../../../src/notifications";
|
||||
|
||||
describe("PushRuleVectorState", function () {
|
||||
describe("contentRuleVectorStateKind", function () {
|
||||
it("should understand normal notifications", function () {
|
||||
const rule = {
|
||||
actions: [PushRuleActionName.Notify],
|
||||
default: false,
|
||||
enabled: false,
|
||||
rule_id: "1",
|
||||
};
|
||||
|
||||
expect(PushRuleVectorState.contentRuleVectorStateKind(rule)).toEqual(PushRuleVectorState.ON);
|
||||
});
|
||||
|
||||
it("should handle loud notifications", function () {
|
||||
const rule = {
|
||||
actions: [
|
||||
PushRuleActionName.Notify,
|
||||
{ set_tweak: TweakName.Highlight, value: true } as TweakHighlight,
|
||||
{ set_tweak: TweakName.Sound, value: "default" } as TweakSound,
|
||||
],
|
||||
default: false,
|
||||
enabled: false,
|
||||
rule_id: "1",
|
||||
};
|
||||
|
||||
expect(PushRuleVectorState.contentRuleVectorStateKind(rule)).toEqual(PushRuleVectorState.LOUD);
|
||||
});
|
||||
|
||||
it("should understand missing highlight.value", function () {
|
||||
const rule = {
|
||||
actions: [
|
||||
PushRuleActionName.Notify,
|
||||
{ set_tweak: TweakName.Highlight } as TweakHighlight,
|
||||
{ set_tweak: TweakName.Sound, value: "default" } as TweakSound,
|
||||
],
|
||||
default: false,
|
||||
enabled: false,
|
||||
rule_id: "1",
|
||||
};
|
||||
|
||||
expect(PushRuleVectorState.contentRuleVectorStateKind(rule)).toEqual(PushRuleVectorState.LOUD);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue