1 # frozen_string_literal: true
3 require "application_system_test_case"
5 class ContextMenuTest < ApplicationSystemTestCase
6 test "context menu stays inside the map when there isn't room above or below the click" do
7 original_size = page.current_window.size
8 page.current_window.resize_to(640, 360)
10 visit "/#map=15/51.76320/-0.00760"
12 find_by_id("map").right_click
14 within "#map-context-menu" do
15 assert_link "Centre map here"
18 menu = evaluate_script("document.querySelector('#map-context-menu .dropdown-menu').getBoundingClientRect().toJSON()")
19 map = evaluate_script("document.getElementById('map').getBoundingClientRect().toJSON()")
21 assert_operator menu["top"], :>=, map["top"]
22 assert_operator menu["bottom"], :<=, map["bottom"]
24 page.current_window.resize_to(*original_size) if original_size