@@ -147,49 +147,65 @@ describe("PinningUtils", () => {
147
147
} ) ;
148
148
} ) ;
149
149
150
- describe ( "canPinOrUnpin" , ( ) => {
151
- test ( "should return false if pinning is disabled" , ( ) => {
152
- // Disable feature pinning
153
- jest . spyOn ( SettingsStore , "getValue" ) . mockReturnValue ( false ) ;
154
- const event = makePinEvent ( ) ;
150
+ describe ( "canPin & canUnpin" , ( ) => {
151
+ describe ( "canPin" , ( ) => {
152
+ test ( "should return false if pinning is disabled" , ( ) => {
153
+ // Disable feature pinning
154
+ jest . spyOn ( SettingsStore , "getValue" ) . mockReturnValue ( false ) ;
155
+ const event = makePinEvent ( ) ;
156
+
157
+ expect ( PinningUtils . canPin ( matrixClient , event ) ) . toBe ( false ) ;
158
+ } ) ;
155
159
156
- expect ( PinningUtils . canPinOrUnpin ( matrixClient , event ) ) . toBe ( false ) ;
157
- } ) ;
160
+ test ( "should return false if event is not actionable" , ( ) => {
161
+ mockedIsContentActionable . mockImplementation ( ( ) => false ) ;
162
+ const event = makePinEvent ( ) ;
158
163
159
- test ( "should return false if event is not actionable" , ( ) => {
160
- mockedIsContentActionable . mockImplementation ( ( ) => false ) ;
161
- const event = makePinEvent ( ) ;
164
+ expect ( PinningUtils . canPin ( matrixClient , event ) ) . toBe ( false ) ;
165
+ } ) ;
162
166
163
- expect ( PinningUtils . canPinOrUnpin ( matrixClient , event ) ) . toBe ( false ) ;
164
- } ) ;
167
+ test ( "should return false if no room" , ( ) => {
168
+ matrixClient . getRoom = jest . fn ( ) . mockReturnValue ( undefined ) ;
169
+ const event = makePinEvent ( ) ;
165
170
166
- test ( "should return false if no room" , ( ) => {
167
- matrixClient . getRoom = jest . fn ( ) . mockReturnValue ( undefined ) ;
168
- const event = makePinEvent ( ) ;
171
+ expect ( PinningUtils . canPin ( matrixClient , event ) ) . toBe ( false ) ;
172
+ } ) ;
169
173
170
- expect ( PinningUtils . canPinOrUnpin ( matrixClient , event ) ) . toBe ( false ) ;
171
- } ) ;
174
+ test ( "should return false if client cannot send state event" , ( ) => {
175
+ jest . spyOn (
176
+ matrixClient . getRoom ( roomId ) ! . getLiveTimeline ( ) . getState ( EventTimeline . FORWARDS ) ! ,
177
+ "mayClientSendStateEvent" ,
178
+ ) . mockReturnValue ( false ) ;
179
+ const event = makePinEvent ( ) ;
172
180
173
- test ( "should return false if client cannot send state event" , ( ) => {
174
- jest . spyOn (
175
- matrixClient . getRoom ( roomId ) ! . getLiveTimeline ( ) . getState ( EventTimeline . FORWARDS ) ! ,
176
- "mayClientSendStateEvent" ,
177
- ) . mockReturnValue ( false ) ;
178
- const event = makePinEvent ( ) ;
181
+ expect ( PinningUtils . canPin ( matrixClient , event ) ) . toBe ( false ) ;
182
+ } ) ;
179
183
180
- expect ( PinningUtils . canPinOrUnpin ( matrixClient , event ) ) . toBe ( false ) ;
181
- } ) ;
184
+ test ( "should return false if event is not pinnable" , ( ) => {
185
+ const event = makePinEvent ( { type : EventType . RoomCreate } ) ;
182
186
183
- test ( "should return false if event is not pinnable" , ( ) => {
184
- const event = makePinEvent ( { type : EventType . RoomCreate } ) ;
187
+ expect ( PinningUtils . canPin ( matrixClient , event ) ) . toBe ( false ) ;
188
+ } ) ;
185
189
186
- expect ( PinningUtils . canPinOrUnpin ( matrixClient , event ) ) . toBe ( false ) ;
190
+ test ( "should return true if all conditions are met" , ( ) => {
191
+ const event = makePinEvent ( ) ;
192
+
193
+ expect ( PinningUtils . canPin ( matrixClient , event ) ) . toBe ( true ) ;
194
+ } ) ;
187
195
} ) ;
188
196
189
- test ( "should return true if all conditions are met" , ( ) => {
190
- const event = makePinEvent ( ) ;
197
+ describe ( "canUnpin" , ( ) => {
198
+ test ( "should return false if event is not unpinnable" , ( ) => {
199
+ const event = makePinEvent ( { type : EventType . RoomCreate } ) ;
191
200
192
- expect ( PinningUtils . canPinOrUnpin ( matrixClient , event ) ) . toBe ( true ) ;
201
+ expect ( PinningUtils . canUnpin ( matrixClient , event ) ) . toBe ( false ) ;
202
+ } ) ;
203
+
204
+ test ( "should return true if all conditions are met" , ( ) => {
205
+ const event = makePinEvent ( ) ;
206
+
207
+ expect ( PinningUtils . canUnpin ( matrixClient , event ) ) . toBe ( true ) ;
208
+ } ) ;
193
209
} ) ;
194
210
} ) ;
195
211
@@ -258,4 +274,32 @@ describe("PinningUtils", () => {
258
274
) ;
259
275
} ) ;
260
276
} ) ;
277
+
278
+ describe ( "userHasPinOrUnpinPermission" , ( ) => {
279
+ test ( "should return true if user can pin or unpin" , ( ) => {
280
+ expect ( PinningUtils . userHasPinOrUnpinPermission ( matrixClient , room ) ) . toBe ( true ) ;
281
+ } ) ;
282
+
283
+ test ( "should return false if client cannot send state event" , ( ) => {
284
+ jest . spyOn (
285
+ matrixClient . getRoom ( roomId ) ! . getLiveTimeline ( ) . getState ( EventTimeline . FORWARDS ) ! ,
286
+ "mayClientSendStateEvent" ,
287
+ ) . mockReturnValue ( false ) ;
288
+
289
+ expect ( PinningUtils . userHasPinOrUnpinPermission ( matrixClient , room ) ) . toBe ( false ) ;
290
+ } ) ;
291
+ } ) ;
292
+
293
+ describe ( "unpinAllEvents" , ( ) => {
294
+ it ( "should unpin all events in the given room" , async ( ) => {
295
+ await PinningUtils . unpinAllEvents ( matrixClient , roomId ) ;
296
+
297
+ expect ( matrixClient . sendStateEvent ) . toHaveBeenCalledWith (
298
+ roomId ,
299
+ EventType . RoomPinnedEvents ,
300
+ { pinned : [ ] } ,
301
+ "" ,
302
+ ) ;
303
+ } ) ;
304
+ } ) ;
261
305
} ) ;
0 commit comments