@@ -31,6 +31,7 @@ import {
3131} from "../../../test-utils" ;
3232import DMRoomMap from "../../../../src/utils/DMRoomMap" ;
3333import { Action } from "../../../../src/dispatcher/actions" ;
34+ import { ButtonEvent } from "../../../../src/components/views/elements/AccessibleButton" ;
3435
3536describe ( "<Pill>" , ( ) => {
3637 let client : Mocked < MatrixClient > ;
@@ -43,14 +44,20 @@ describe("<Pill>", () => {
4344 const user1Id = "@user1:example.com" ;
4445 const user2Id = "@user2:example.com" ;
4546 let renderResult : RenderResult ;
47+ let pillParentClickHandler : ( e : ButtonEvent ) => void ;
4648
4749 const renderPill = ( props : PillProps ) : void => {
4850 const withDefault = {
4951 inMessage : true ,
5052 shouldShowPillAvatar : true ,
5153 ...props ,
5254 } 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+ ) ;
5461 } ;
5562
5663 filterConsole (
@@ -88,6 +95,7 @@ describe("<Pill>", () => {
8895 } ) ;
8996
9097 jest . spyOn ( dis , "dispatch" ) ;
98+ pillParentClickHandler = jest . fn ( ) ;
9199 } ) ;
92100
93101 describe ( "when rendering a pill for a room" , ( ) => {
@@ -168,11 +176,13 @@ describe("<Pill>", () => {
168176 await userEvent . click ( screen . getByText ( "User 1" ) ) ;
169177 } ) ;
170178
171- it ( "should dipsatch a view user action" , ( ) => {
179+ it ( "should dipsatch a view user action and prevent event bubbling " , ( ) => {
172180 expect ( dis . dispatch ) . toHaveBeenCalledWith ( {
173181 action : Action . ViewUser ,
174182 member : room1 . getMember ( user1Id ) ,
175183 } ) ;
184+
185+ expect ( pillParentClickHandler ) . not . toHaveBeenCalled ( ) ;
176186 } ) ;
177187 } ) ;
178188 } ) ;
@@ -195,7 +205,11 @@ describe("<Pill>", () => {
195205 renderPill ( {
196206 url : permalinkPrefix ,
197207 } ) ;
198- expect ( renderResult . asFragment ( ) ) . toMatchInlineSnapshot ( `<DocumentFragment />` ) ;
208+ expect ( renderResult . asFragment ( ) ) . toMatchInlineSnapshot ( `
209+ <DocumentFragment>
210+ <div />
211+ </DocumentFragment>
212+ ` ) ;
199213 } ) ;
200214
201215 it ( "should not render an avatar or link when called with inMessage = false and shouldShowPillAvatar = false" , ( ) => {
0 commit comments