@@ -10,6 +10,20 @@ async function getViewportWidth(): Promise<number> {
10
10
} ) ;
11
11
}
12
12
13
+ async function setDirection (
14
+ element : ChainablePromiseElement ,
15
+ direction : string ,
16
+ ) {
17
+ await browser . execute (
18
+ ( element , direction ) => {
19
+ const el = element as unknown as HTMLElement ;
20
+ el . dir = direction ;
21
+ } ,
22
+ element ,
23
+ direction ,
24
+ ) ;
25
+ }
26
+
13
27
describe ( "Context Menu" , ( ) => {
14
28
it ( "load the test" , async ( ) => {
15
29
await openTest ( browser , "integration_tests/context_menu_position" ) ;
@@ -67,7 +81,6 @@ describe("Context Menu", () => {
67
81
68
82
const menu = await player . $ ( "#context-menu" ) ;
69
83
const menuLocation = await menu . getLocation ( ) ;
70
-
71
84
expect ( menuLocation . x ) . to . equal ( viewportWidth - 500 ) ;
72
85
expect ( menuLocation . y ) . to . equal ( 500 ) ;
73
86
@@ -89,4 +102,52 @@ describe("Context Menu", () => {
89
102
// Dismiss the menu
90
103
await player . click ( { x : - 10 , y : - 10 } ) ;
91
104
} ) ;
105
+
106
+ it ( "switch context menu LTR -> RTL" , async ( ) => {
107
+ // Note: normally we should change the preferred user language
108
+ // (navigator.language), but that's not easy without creating
109
+ // a new browser instance.
110
+
111
+ const player = await browser . $ ( "#objectElement" ) ;
112
+ const menu = await player . $ ( "#context-menu" ) ;
113
+ await setDirection ( menu , "rtl" ) ;
114
+ } ) ;
115
+
116
+ it ( "open RTL context menu in the middle RTL" , async ( ) => {
117
+ const player = await browser . $ ( "#objectElement" ) ;
118
+ const viewportWidth = await getViewportWidth ( ) ;
119
+
120
+ await player . click ( { x : 0 , y : 0 , button : "right" } ) ;
121
+
122
+ const menu = await player . $ ( "#context-menu" ) ;
123
+ const menuLocation = await menu . getLocation ( ) ;
124
+ const menuSize = await menu . getSize ( ) ;
125
+ expect ( menuLocation . x ) . to . approximately (
126
+ viewportWidth - 500 - menuSize . width ,
127
+ 0.6 ,
128
+ ) ;
129
+ expect ( menuLocation . y ) . to . equal ( 500 ) ;
130
+
131
+ // Dismiss the menu
132
+ await player . click ( { x : - 10 , y : - 10 } ) ;
133
+ } ) ;
134
+
135
+ it ( "open RTL context menu in the corner RTL" , async ( ) => {
136
+ const player = await browser . $ ( "#objectElement" ) ;
137
+ const viewportWidth = await getViewportWidth ( ) ;
138
+
139
+ await player . click ( { x : - 150 , y : 150 , button : "right" } ) ;
140
+
141
+ const menu = await player . $ ( "#context-menu" ) ;
142
+ const menuLocation = await menu . getLocation ( ) ;
143
+ const menuSize = await menu . getSize ( ) ;
144
+ expect ( menuLocation . x ) . to . approximately (
145
+ viewportWidth - 650 - menuSize . width ,
146
+ 0.6 ,
147
+ ) ;
148
+ expect ( menuLocation . y ) . to . equal ( 650 ) ;
149
+
150
+ // Dismiss the menu
151
+ await player . click ( { x : - 10 , y : - 10 } ) ;
152
+ } ) ;
92
153
} ) ;
0 commit comments