@@ -15,68 +15,102 @@ limitations under the License.
1515*/
1616
1717import React from 'react' ;
18- // eslint-disable-next-line deprecate/import
19- import { shallow , mount } from "enzyme " ;
18+ import { render , screen , fireEvent } from "@testing-library/react" ;
19+ import { mocked } from "jest-mock " ;
2020import 'focus-visible' ; // to fix context menus
2121
22- import {
23- ThreadFilterType ,
24- ThreadPanelHeader ,
25- ThreadPanelHeaderFilterOptionItem ,
26- } from '../../../src/components/structures/ThreadPanel' ;
27- import { ContextMenuButton } from '../../../src/accessibility/context_menu/ContextMenuButton' ;
28- import ContextMenu from '../../../src/components/structures/ContextMenu' ;
22+ import ThreadPanel , { ThreadFilterType , ThreadPanelHeader } from '../../../src/components/structures/ThreadPanel' ;
2923import { _t } from '../../../src/languageHandler' ;
24+ import ResizeNotifier from '../../../src/utils/ResizeNotifier' ;
25+ import { RoomPermalinkCreator } from '../../../src/utils/permalinks/Permalinks' ;
26+ import { createTestClient , mkStubRoom } from '../../test-utils' ;
27+ import { shouldShowFeedback } from "../../../src/utils/Feedback" ;
28+ import MatrixClientContext from "../../../src/contexts/MatrixClientContext" ;
29+
30+ jest . mock ( "../../../src/utils/Feedback" ) ;
3031
3132describe ( 'ThreadPanel' , ( ) => {
33+ describe ( "Feedback prompt" , ( ) => {
34+ const cli = createTestClient ( ) ;
35+ const room = mkStubRoom ( "!room:server" , "room" , cli ) ;
36+ mocked ( cli . getRoom ) . mockReturnValue ( room ) ;
37+
38+ it ( "should show feedback prompt if feedback is enabled" , ( ) => {
39+ mocked ( shouldShowFeedback ) . mockReturnValue ( true ) ;
40+
41+ render ( < MatrixClientContext . Provider value = { cli } >
42+ < ThreadPanel
43+ roomId = "!room:server"
44+ onClose = { jest . fn ( ) }
45+ resizeNotifier = { new ResizeNotifier ( ) }
46+ permalinkCreator = { new RoomPermalinkCreator ( room ) }
47+ />
48+ </ MatrixClientContext . Provider > ) ;
49+ expect ( screen . queryByText ( "Give feedback" ) ) . toBeTruthy ( ) ;
50+ } ) ;
51+
52+ it ( "should hide feedback prompt if feedback is disabled" , ( ) => {
53+ mocked ( shouldShowFeedback ) . mockReturnValue ( false ) ;
54+
55+ render ( < MatrixClientContext . Provider value = { cli } >
56+ < ThreadPanel
57+ roomId = "!room:server"
58+ onClose = { jest . fn ( ) }
59+ resizeNotifier = { new ResizeNotifier ( ) }
60+ permalinkCreator = { new RoomPermalinkCreator ( room ) }
61+ />
62+ </ MatrixClientContext . Provider > ) ;
63+ expect ( screen . queryByText ( "Give feedback" ) ) . toBeFalsy ( ) ;
64+ } ) ;
65+ } ) ;
66+
3267 describe ( 'Header' , ( ) => {
3368 it ( 'expect that All filter for ThreadPanelHeader properly renders Show: All threads' , ( ) => {
34- const wrapper = shallow (
69+ const { asFragment } = render (
3570 < ThreadPanelHeader
3671 empty = { false }
3772 filterOption = { ThreadFilterType . All }
3873 setFilterOption = { ( ) => undefined } /> ,
3974 ) ;
40- expect ( wrapper ) . toMatchSnapshot ( ) ;
75+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
4176 } ) ;
4277
4378 it ( 'expect that My filter for ThreadPanelHeader properly renders Show: My threads' , ( ) => {
44- const wrapper = shallow (
79+ const { asFragment } = render (
4580 < ThreadPanelHeader
4681 empty = { false }
4782 filterOption = { ThreadFilterType . My }
4883 setFilterOption = { ( ) => undefined } /> ,
4984 ) ;
50- expect ( wrapper ) . toMatchSnapshot ( ) ;
85+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
5186 } ) ;
5287
5388 it ( 'expect that ThreadPanelHeader properly opens a context menu when clicked on the button' , ( ) => {
54- const wrapper = mount (
89+ const { container } = render (
5590 < ThreadPanelHeader
5691 empty = { false }
5792 filterOption = { ThreadFilterType . All }
5893 setFilterOption = { ( ) => undefined } /> ,
5994 ) ;
60- const found = wrapper . find ( ContextMenuButton ) ;
61- expect ( found ) . not . toBe ( undefined ) ;
62- expect ( found ) . not . toBe ( null ) ;
63- expect ( wrapper . exists ( ContextMenu ) ) . toEqual ( false ) ;
64- found . simulate ( 'click' ) ;
65- expect ( wrapper . exists ( ContextMenu ) ) . toEqual ( true ) ;
95+ const found = container . querySelector ( ".mx_ThreadPanel_dropdown" ) ;
96+ expect ( found ) . toBeTruthy ( ) ;
97+ expect ( screen . queryByRole ( "menu" ) ) . toBeFalsy ( ) ;
98+ fireEvent . click ( found ) ;
99+ expect ( screen . queryByRole ( "menu" ) ) . toBeTruthy ( ) ;
66100 } ) ;
67101
68102 it ( 'expect that ThreadPanelHeader has the correct option selected in the context menu' , ( ) => {
69- const wrapper = mount (
103+ const { container } = render (
70104 < ThreadPanelHeader
71105 empty = { false }
72106 filterOption = { ThreadFilterType . All }
73107 setFilterOption = { ( ) => undefined } /> ,
74108 ) ;
75- wrapper . find ( ContextMenuButton ) . simulate ( 'click' ) ;
76- const found = wrapper . find ( ThreadPanelHeaderFilterOptionItem ) ;
77- expect ( found . length ) . toEqual ( 2 ) ;
78- const foundButton = found . find ( '[aria- checked= true]' ) . first ( ) ;
79- expect ( foundButton . text ( ) ) . toEqual ( `${ _t ( "All threads" ) } ${ _t ( 'Shows all threads from current room' ) } ` ) ;
109+ fireEvent . click ( container . querySelector ( ".mx_ThreadPanel_dropdown" ) ) ;
110+ const found = screen . queryAllByRole ( "menuitemradio" ) ;
111+ expect ( found ) . toHaveLength ( 2 ) ;
112+ const foundButton = screen . queryByRole ( "menuitemradio" , { checked : true } ) ;
113+ expect ( foundButton . textContent ) . toEqual ( `${ _t ( "All threads" ) } ${ _t ( 'Shows all threads from current room' ) } ` ) ;
80114 expect ( foundButton ) . toMatchSnapshot ( ) ;
81115 } ) ;
82116 } ) ;
0 commit comments