Skip to content

Commit c6b0fb5

Browse files
committed
web: Update context_menu_position test
Add cases where the direction of the context menu is different.
1 parent 211676f commit c6b0fb5

File tree

1 file changed

+62
-1
lines changed
  • web/packages/selfhosted/test/integration_tests/context_menu_position

1 file changed

+62
-1
lines changed

web/packages/selfhosted/test/integration_tests/context_menu_position/test.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ async function getViewportWidth(): Promise<number> {
1010
});
1111
}
1212

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+
1327
describe("Context Menu", () => {
1428
it("load the test", async () => {
1529
await openTest(browser, "integration_tests/context_menu_position");
@@ -67,7 +81,6 @@ describe("Context Menu", () => {
6781

6882
const menu = await player.$("#context-menu");
6983
const menuLocation = await menu.getLocation();
70-
7184
expect(menuLocation.x).to.equal(viewportWidth - 500);
7285
expect(menuLocation.y).to.equal(500);
7386

@@ -89,4 +102,52 @@ describe("Context Menu", () => {
89102
// Dismiss the menu
90103
await player.click({ x: -10, y: -10 });
91104
});
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+
});
92153
});

0 commit comments

Comments
 (0)