@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
+ /* eslint-disable @typescript-eslint/no-var-requires */
16
17
17
18
import React from 'react' ;
18
19
import { mount } from 'enzyme' ;
@@ -22,11 +23,18 @@ import { PendingEventOrdering } from 'matrix-js-sdk/src/matrix';
22
23
import { ExtensibleEvent , MessageEvent , M_POLL_KIND_DISCLOSED , PollStartEvent } from 'matrix-events-sdk' ;
23
24
24
25
import * as TestUtils from '../../../test-utils' ;
25
- import MessageContextMenu from '../../../../src/components/views/context_menus/MessageContextMenu' ;
26
26
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg' ;
27
- import { copyPlaintext , getSelectedText } from "../../../../src/utils/strings" ;
27
+
28
+ const PATH_TO_STRING_UTILS = "../../../../src/utils/strings" ;
29
+
30
+ jest . mock ( PATH_TO_STRING_UTILS ) ;
31
+ const { copyPlaintext, getSelectedText } = require ( PATH_TO_STRING_UTILS ) ;
28
32
29
33
describe ( 'MessageContextMenu' , ( ) => {
34
+ beforeAll ( ( ) => {
35
+ jest . resetAllMocks ( ) ;
36
+ } ) ;
37
+
30
38
it ( 'allows forwarding a room message' , ( ) => {
31
39
const eventContent = MessageEvent . from ( "hello" ) ;
32
40
const menu = createMessageContextMenu ( eventContent ) ;
@@ -41,7 +49,7 @@ describe('MessageContextMenu', () => {
41
49
42
50
it ( 'does show copy link button when supplied a link' , ( ) => {
43
51
const eventContent = MessageEvent . from ( "hello" ) ;
44
- const props : Partial < React . ComponentProps < typeof MessageContextMenu > > = {
52
+ const props = {
45
53
link : "https://google.com/" ,
46
54
} ;
47
55
const menu = createMessageContextMenu ( eventContent , props ) ;
@@ -52,24 +60,25 @@ describe('MessageContextMenu', () => {
52
60
53
61
it ( 'does show copy button when we have selected text and we are requesting a right-click menu' , ( ) => {
54
62
const eventContent = MessageEvent . from ( "hello" ) ;
55
- const props : Partial < React . ComponentProps < typeof MessageContextMenu > > = {
63
+ const props = {
56
64
rightClick : true ,
57
65
} ;
58
- getSelectedText = jest . fn ( ) . mockReturnValue ( "hello" ) ;
66
+ getSelectedText . mockReturnValue ( "hello" ) ;
67
+
59
68
const menu = createMessageContextMenu ( eventContent , props ) ;
60
- const copyLinkButton = menu . find ( 'a[aria-label="Copy"]' ) . first ( ) ;
61
- expect ( copyLinkButton ) . toBeDefined ( ) ;
62
- ( copyLinkButton ?. getDOMNode ( ) as HTMLDivElement ) ?. click ( ) ;
69
+ const copyButton = menu . find ( 'div[aria-label="Copy"]' ) ;
70
+ copyButton . first ( ) . first ( ) . simulate ( "click" ) ;
63
71
expect ( copyPlaintext ) . toHaveBeenCalled ( ) ;
64
72
} ) ;
65
73
} ) ;
66
74
67
75
function createMessageContextMenu (
68
76
eventContent : ExtensibleEvent ,
69
- props ?: Partial < React . ComponentProps < typeof MessageContextMenu > > ,
77
+ props ?,
70
78
) {
71
79
TestUtils . stubClient ( ) ;
72
80
const client = MatrixClientPeg . get ( ) ;
81
+ const MessageContextMenu = require ( "../../../../src/components/views/context_menus/MessageContextMenu" ) [ "default" ] ;
73
82
74
83
const room = new Room (
75
84
"roomid" ,
0 commit comments