]> git.openstreetmap.org Git - rails.git/blob - test/system/context_menu_test.rb
Merge remote-tracking branch 'upstream/pull/7650'
[rails.git] / test / system / context_menu_test.rb
1 # frozen_string_literal: true
2
3 require "application_system_test_case"
4
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)
9
10     visit "/#map=15/51.76320/-0.00760"
11
12     find_by_id("map").right_click
13
14     within "#map-context-menu" do
15       assert_link "Centre map here"
16     end
17
18     menu = evaluate_script("document.querySelector('#map-context-menu .dropdown-menu').getBoundingClientRect().toJSON()")
19     map = evaluate_script("document.getElementById('map').getBoundingClientRect().toJSON()")
20
21     assert_operator menu["top"], :>=, map["top"]
22     assert_operator menu["bottom"], :<=, map["bottom"]
23   ensure
24     page.current_window.resize_to(*original_size) if original_size
25   end
26 end