@@ -15,8 +15,7 @@ limitations under the License.
15
15
*/
16
16
17
17
import React from "react" ;
18
- // eslint-disable-next-line deprecate/import
19
- import { mount } from "enzyme" ;
18
+ import { render } from "@testing-library/react" ;
20
19
21
20
import ContextMenu , { ChevronFace } from "../../../../src/components/structures/ContextMenu" ;
22
21
import UIStore from "../../../../src/stores/UIStore" ;
@@ -41,11 +40,11 @@ describe("<ContextMenu />", () => {
41
40
42
41
const targetChevronOffset = 25 ;
43
42
44
- describe ( "near top edge of window" , ( ) => {
43
+ it ( "near top edge of window" , ( ) => {
45
44
const targetY = - 50 ;
46
45
const onFinished = jest . fn ( ) ;
47
46
48
- const wrapper = mount (
47
+ render (
49
48
< ContextMenu
50
49
bottom = { windowSize - targetY - menuSize }
51
50
right = { menuSize }
@@ -54,25 +53,25 @@ describe("<ContextMenu />", () => {
54
53
chevronOffset = { targetChevronOffset }
55
54
/> ,
56
55
) ;
57
- const chevron = wrapper . find ( ".mx_ContextualMenu_chevron_left" ) ;
56
+ const chevron = document . querySelector < HTMLElement > ( ".mx_ContextualMenu_chevron_left" ) ! ;
58
57
59
- const bottomStyle = parseInt ( wrapper . getDOMNode < HTMLElement > ( ) . style . getPropertyValue ( "bottom" ) ) ;
58
+ const bottomStyle = parseInt (
59
+ document . querySelector < HTMLElement > ( ".mx_ContextualMenu_wrapper" ) ! . style . getPropertyValue ( "bottom" ) ,
60
+ ) ;
60
61
const actualY = windowSize - bottomStyle - menuSize ;
61
- const actualChevronOffset = parseInt ( chevron . getDOMNode < HTMLElement > ( ) . style . getPropertyValue ( "top" ) ) ;
62
-
63
- it ( "stays within the window" , ( ) => {
64
- expect ( actualY ) . toBeGreaterThanOrEqual ( 0 ) ;
65
- } ) ;
66
- it ( "positions the chevron correctly" , ( ) => {
67
- expect ( actualChevronOffset ) . toEqual ( targetChevronOffset + targetY - actualY ) ;
68
- } ) ;
62
+ const actualChevronOffset = parseInt ( chevron . style . getPropertyValue ( "top" ) ) ;
63
+
64
+ // stays within the window
65
+ expect ( actualY ) . toBeGreaterThanOrEqual ( 0 ) ;
66
+ // positions the chevron correctly
67
+ expect ( actualChevronOffset ) . toEqual ( targetChevronOffset + targetY - actualY ) ;
69
68
} ) ;
70
69
71
- describe ( "near right edge of window" , ( ) => {
70
+ it ( "near right edge of window" , ( ) => {
72
71
const targetX = windowSize - menuSize + 50 ;
73
72
const onFinished = jest . fn ( ) ;
74
73
75
- const wrapper = mount (
74
+ render (
76
75
< ContextMenu
77
76
bottom = { 0 }
78
77
onFinished = { onFinished }
@@ -81,24 +80,24 @@ describe("<ContextMenu />", () => {
81
80
chevronOffset = { targetChevronOffset }
82
81
/> ,
83
82
) ;
84
- const chevron = wrapper . find ( ".mx_ContextualMenu_chevron_top" ) ;
83
+ const chevron = document . querySelector < HTMLElement > ( ".mx_ContextualMenu_chevron_top" ) ! ;
85
84
86
- const actualX = parseInt ( wrapper . getDOMNode < HTMLElement > ( ) . style . getPropertyValue ( "left" ) ) ;
87
- const actualChevronOffset = parseInt ( chevron . getDOMNode < HTMLElement > ( ) . style . getPropertyValue ( "left" ) ) ;
85
+ const actualX = parseInt (
86
+ document . querySelector < HTMLElement > ( ".mx_ContextualMenu_wrapper" ) ! . style . getPropertyValue ( "left" ) ,
87
+ ) ;
88
+ const actualChevronOffset = parseInt ( chevron . style . getPropertyValue ( "left" ) ) ;
88
89
89
- it ( "stays within the window" , ( ) => {
90
- expect ( actualX + menuSize ) . toBeLessThanOrEqual ( windowSize ) ;
91
- } ) ;
92
- it ( "positions the chevron correctly" , ( ) => {
93
- expect ( actualChevronOffset ) . toEqual ( targetChevronOffset + targetX - actualX ) ;
94
- } ) ;
90
+ // stays within the window
91
+ expect ( actualX + menuSize ) . toBeLessThanOrEqual ( windowSize ) ;
92
+ // positions the chevron correctly
93
+ expect ( actualChevronOffset ) . toEqual ( targetChevronOffset + targetX - actualX ) ;
95
94
} ) ;
96
95
97
- describe ( "near bottom edge of window" , ( ) => {
96
+ it ( "near bottom edge of window" , ( ) => {
98
97
const targetY = windowSize - menuSize + 50 ;
99
98
const onFinished = jest . fn ( ) ;
100
99
101
- const wrapper = mount (
100
+ render (
102
101
< ContextMenu
103
102
top = { targetY }
104
103
left = { 0 }
@@ -107,24 +106,24 @@ describe("<ContextMenu />", () => {
107
106
chevronOffset = { targetChevronOffset }
108
107
/> ,
109
108
) ;
110
- const chevron = wrapper . find ( ".mx_ContextualMenu_chevron_right" ) ;
109
+ const chevron = document . querySelector < HTMLElement > ( ".mx_ContextualMenu_chevron_right" ) ! ;
111
110
112
- const actualY = parseInt ( wrapper . getDOMNode < HTMLElement > ( ) . style . getPropertyValue ( "top" ) ) ;
113
- const actualChevronOffset = parseInt ( chevron . getDOMNode < HTMLElement > ( ) . style . getPropertyValue ( "top" ) ) ;
111
+ const actualY = parseInt (
112
+ document . querySelector < HTMLElement > ( ".mx_ContextualMenu_wrapper" ) ! . style . getPropertyValue ( "top" ) ,
113
+ ) ;
114
+ const actualChevronOffset = parseInt ( chevron . style . getPropertyValue ( "top" ) ) ;
114
115
115
- it ( "stays within the window" , ( ) => {
116
- expect ( actualY + menuSize ) . toBeLessThanOrEqual ( windowSize ) ;
117
- } ) ;
118
- it ( "positions the chevron correctly" , ( ) => {
119
- expect ( actualChevronOffset ) . toEqual ( targetChevronOffset + targetY - actualY ) ;
120
- } ) ;
116
+ // stays within the window
117
+ expect ( actualY + menuSize ) . toBeLessThanOrEqual ( windowSize ) ;
118
+ // positions the chevron correctly
119
+ expect ( actualChevronOffset ) . toEqual ( targetChevronOffset + targetY - actualY ) ;
121
120
} ) ;
122
121
123
- describe ( "near left edge of window" , ( ) => {
122
+ it ( "near left edge of window" , ( ) => {
124
123
const targetX = - 50 ;
125
124
const onFinished = jest . fn ( ) ;
126
125
127
- const wrapper = mount (
126
+ render (
128
127
< ContextMenu
129
128
top = { 0 }
130
129
right = { windowSize - targetX - menuSize }
@@ -133,25 +132,25 @@ describe("<ContextMenu />", () => {
133
132
chevronOffset = { targetChevronOffset }
134
133
/> ,
135
134
) ;
136
- const chevron = wrapper . find ( ".mx_ContextualMenu_chevron_bottom" ) ;
135
+ const chevron = document . querySelector < HTMLElement > ( ".mx_ContextualMenu_chevron_bottom" ) ! ;
137
136
138
- const rightStyle = parseInt ( wrapper . getDOMNode < HTMLElement > ( ) . style . getPropertyValue ( "right" ) ) ;
137
+ const rightStyle = parseInt (
138
+ document . querySelector < HTMLElement > ( ".mx_ContextualMenu_wrapper" ) ! . style . getPropertyValue ( "right" ) ,
139
+ ) ;
139
140
const actualX = windowSize - rightStyle - menuSize ;
140
- const actualChevronOffset = parseInt ( chevron . getDOMNode < HTMLElement > ( ) . style . getPropertyValue ( "left" ) ) ;
141
-
142
- it ( "stays within the window" , ( ) => {
143
- expect ( actualX ) . toBeGreaterThanOrEqual ( 0 ) ;
144
- } ) ;
145
- it ( "positions the chevron correctly" , ( ) => {
146
- expect ( actualChevronOffset ) . toEqual ( targetChevronOffset + targetX - actualX ) ;
147
- } ) ;
141
+ const actualChevronOffset = parseInt ( chevron . style . getPropertyValue ( "left" ) ) ;
142
+
143
+ // stays within the window
144
+ expect ( actualX ) . toBeGreaterThanOrEqual ( 0 ) ;
145
+ // positions the chevron correctly
146
+ expect ( actualChevronOffset ) . toEqual ( targetChevronOffset + targetX - actualX ) ;
148
147
} ) ;
149
148
150
149
it ( "should automatically close when a modal is opened" , ( ) => {
151
150
const targetX = - 50 ;
152
151
const onFinished = jest . fn ( ) ;
153
152
154
- mount (
153
+ render (
155
154
< ContextMenu
156
155
top = { 0 }
157
156
right = { windowSize - targetX - menuSize }
@@ -171,7 +170,7 @@ describe("<ContextMenu />", () => {
171
170
const onFinished = jest . fn ( ) ;
172
171
173
172
Modal . createDialog ( BaseDialog ) ;
174
- mount (
173
+ render (
175
174
< ContextMenu
176
175
top = { 0 }
177
176
right = { windowSize - targetX - menuSize }
0 commit comments