penpot/frontend/test/frontend_tests/ui/context_menu_submenu_test.cljs
Thomas Ramé e6f3d21dce
🐛 Keep context menu submenus inside the window (#13302)
* 🐛 Keep context menu submenus inside the window

A submenu opens at the height of its entry, so one opened from an entry
near the bottom of the window ran past it and its last entries could
not be reached. It now moves up to end 8px above the window's bottom.

Signed-off-by: Florian Schroedl <flo.schroedl@gmail.com>
Signed-off-by: Thomas Ramé <thomas@rame.fr>

* 🐛 Keep nested context submenus inside the window

* ♻️ Compute the context submenu position in a testable function

---------

Signed-off-by: Florian Schroedl <flo.schroedl@gmail.com>
Signed-off-by: Thomas Ramé <thomas@rame.fr>
Co-authored-by: Florian Schroedl <flo.schroedl@gmail.com>
2026-11-25 18:29:18 +01:00

51 lines
2.1 KiB
Clojure

;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS SUBSIDIARY SL
(ns frontend-tests.ui.context-menu-submenu-test
(:require
[app.main.ui.workspace.context-menu :as ctx-menu]
[cljs.test :as t :include-macros true]))
;; A 240px wide menu, its submenus 240 x 300, in a 1200 x 800 window.
;; Submenus keep 10px from their menu and 8px from the window edges.
(defn- position
[& {:keys [menu-left entry-top submenu-height window-width window-height]
:or {menu-left 100 entry-top 200 submenu-height 300
window-width 1200 window-height 800}}]
(ctx-menu/submenu-position
{:menu {:left menu-left :right (+ menu-left 240)}
:entry {:top entry-top}
:submenu {:width 240 :height submenu-height}
:window {:width window-width :height window-height}}))
(t/deftest submenu-on-the-right-of-its-menu
(t/is (= {:left 350 :top 200} (position))
"beside the menu, at the height of its entry"))
(t/deftest submenu-touching-the-right-edge-stays-on-the-right
;; 700 + 240 + 10 + 240 = 1190 <= 1200
(t/is (= {:left 950 :top 200} (position :menu-left 700))))
(t/deftest submenu-on-the-left-when-it-would-overflow-the-window
(t/is (= {:left 650 :top 200} (position :menu-left 900))
"beside the left side of the menu")
(t/is (= {:left 1150 :top 200} (position :menu-left 900 :window-width 1700))
"back on the right in a wider window"))
(t/deftest submenu-never-past-the-left-edge-of-the-window
(t/is (= 0 (:left (position :menu-left 100 :window-width 500)))
"no room on either side"))
(t/deftest submenu-moved-up-to-stay-inside-the-window
(t/is (= 492 (:top (position :entry-top 700)))
"8px above the bottom: 800 - 300 - 8")
(t/is (= 700 (:top (position :entry-top 700 :window-height 1200)))
"at the entry in a taller window"))
(t/deftest submenu-taller-than-the-window-starts-at-its-top
(t/is (= 8 (:top (position :entry-top 700 :submenu-height 900)))))