@@ -31,6 +31,7 @@ import {
31
31
} from "../../../test-utils" ;
32
32
import DMRoomMap from "../../../../src/utils/DMRoomMap" ;
33
33
import { Action } from "../../../../src/dispatcher/actions" ;
34
+ import { ButtonEvent } from "../../../../src/components/views/elements/AccessibleButton" ;
34
35
35
36
describe ( "<Pill>" , ( ) => {
36
37
let client : Mocked < MatrixClient > ;
@@ -43,14 +44,20 @@ describe("<Pill>", () => {
43
44
const user1Id = "@user1:example.com" ;
44
45
const user2Id = "@user2:example.com" ;
45
46
let renderResult : RenderResult ;
47
+ let pillParentClickHandler : ( e : ButtonEvent ) => void ;
46
48
47
49
const renderPill = ( props : PillProps ) : void => {
48
50
const withDefault = {
49
51
inMessage : true ,
50
52
shouldShowPillAvatar : true ,
51
53
...props ,
52
54
} as PillProps ;
53
- renderResult = render ( < Pill { ...withDefault } /> ) ;
55
+ // wrap Pill with a div to allow testing of event bubbling
56
+ renderResult = render (
57
+ < div onClick = { pillParentClickHandler } >
58
+ < Pill { ...withDefault } />
59
+ </ div > ,
60
+ ) ;
54
61
} ;
55
62
56
63
filterConsole (
@@ -88,6 +95,7 @@ describe("<Pill>", () => {
88
95
} ) ;
89
96
90
97
jest . spyOn ( dis , "dispatch" ) ;
98
+ pillParentClickHandler = jest . fn ( ) ;
91
99
} ) ;
92
100
93
101
describe ( "when rendering a pill for a room" , ( ) => {
@@ -168,11 +176,13 @@ describe("<Pill>", () => {
168
176
await userEvent . click ( screen . getByText ( "User 1" ) ) ;
169
177
} ) ;
170
178
171
- it ( "should dipsatch a view user action" , ( ) => {
179
+ it ( "should dipsatch a view user action and prevent event bubbling " , ( ) => {
172
180
expect ( dis . dispatch ) . toHaveBeenCalledWith ( {
173
181
action : Action . ViewUser ,
174
182
member : room1 . getMember ( user1Id ) ,
175
183
} ) ;
184
+
185
+ expect ( pillParentClickHandler ) . not . toHaveBeenCalled ( ) ;
176
186
} ) ;
177
187
} ) ;
178
188
} ) ;
@@ -195,7 +205,11 @@ describe("<Pill>", () => {
195
205
renderPill ( {
196
206
url : permalinkPrefix ,
197
207
} ) ;
198
- expect ( renderResult . asFragment ( ) ) . toMatchInlineSnapshot ( `<DocumentFragment />` ) ;
208
+ expect ( renderResult . asFragment ( ) ) . toMatchInlineSnapshot ( `
209
+ <DocumentFragment>
210
+ <div />
211
+ </DocumentFragment>
212
+ ` ) ;
199
213
} ) ;
200
214
201
215
it ( "should not render an avatar or link when called with inMessage = false and shouldShowPillAvatar = false" , ( ) => {
0 commit comments