@@ -17,6 +17,7 @@ limitations under the License.
17
17
import React from "react" ;
18
18
import { render } from "@testing-library/react" ;
19
19
import { MatrixEvent , ConditionKind , EventType , PushRuleActionName , Room , TweakName } from "matrix-js-sdk/src/matrix" ;
20
+ import { mocked } from "jest-mock" ;
20
21
21
22
import { pillifyLinks } from "../../src/utils/pillify" ;
22
23
import { stubClient } from "../test-utils" ;
@@ -36,7 +37,9 @@ describe("pillify", () => {
36
37
beforeEach ( ( ) => {
37
38
stubClient ( ) ;
38
39
const cli = MatrixClientPeg . safeGet ( ) ;
39
- ( cli . getRoom as jest . Mock ) . mockReturnValue ( new Room ( roomId , cli , cli . getUserId ( ) ! ) ) ;
40
+ const room = new Room ( roomId , cli , cli . getUserId ( ) ! ) ;
41
+ room . currentState . mayTriggerNotifOfType = jest . fn ( ) . mockReturnValue ( true ) ;
42
+ ( cli . getRoom as jest . Mock ) . mockReturnValue ( room ) ;
40
43
cli . pushRules ! . global = {
41
44
override : [
42
45
{
@@ -58,6 +61,28 @@ describe("pillify", () => {
58
61
} ,
59
62
] ,
60
63
} ,
64
+ {
65
+ rule_id : ".m.rule.is_room_mention" ,
66
+ default : true ,
67
+ enabled : true ,
68
+ conditions : [
69
+ {
70
+ kind : ConditionKind . EventPropertyIs ,
71
+ key : "content.m\\.mentions.room" ,
72
+ value : true ,
73
+ } ,
74
+ {
75
+ kind : ConditionKind . SenderNotificationPermission ,
76
+ key : "room" ,
77
+ } ,
78
+ ] ,
79
+ actions : [
80
+ PushRuleActionName . Notify ,
81
+ {
82
+ set_tweak : TweakName . Highlight ,
83
+ } ,
84
+ ] ,
85
+ } ,
61
86
] ,
62
87
} ;
63
88
@@ -81,6 +106,29 @@ describe("pillify", () => {
81
106
expect ( container . querySelector ( ".mx_Pill.mx_AtRoomPill" ) ?. textContent ) . toBe ( "!@room" ) ;
82
107
} ) ;
83
108
109
+ it ( "should pillify @room in an intentional mentions world" , ( ) => {
110
+ mocked ( MatrixClientPeg . safeGet ( ) . supportsIntentionalMentions ) . mockReturnValue ( true ) ;
111
+ const { container } = render ( < div > @room</ div > ) ;
112
+ const containers : Element [ ] = [ ] ;
113
+ pillifyLinks (
114
+ MatrixClientPeg . safeGet ( ) ,
115
+ [ container ] ,
116
+ new MatrixEvent ( {
117
+ room_id : roomId ,
118
+ type : EventType . RoomMessage ,
119
+ content : {
120
+ "body" : "@room" ,
121
+ "m.mentions" : {
122
+ room : true ,
123
+ } ,
124
+ } ,
125
+ } ) ,
126
+ containers ,
127
+ ) ;
128
+ expect ( containers ) . toHaveLength ( 1 ) ;
129
+ expect ( container . querySelector ( ".mx_Pill.mx_AtRoomPill" ) ?. textContent ) . toBe ( "!@room" ) ;
130
+ } ) ;
131
+
84
132
it ( "should not double up pillification on repeated calls" , ( ) => {
85
133
const { container } = render ( < div > @room</ div > ) ;
86
134
const containers : Element [ ] = [ ] ;
0 commit comments