]> git.openstreetmap.org Git - rails.git/commitdiff
Merge pull request #5417 from tomhughes/social-share-helper
authorAndy Allan <git@gravitystorm.co.uk>
Thu, 19 Dec 2024 10:28:13 +0000 (10:28 +0000)
committerGitHub <noreply@github.com>
Thu, 19 Dec 2024 10:28:13 +0000 (10:28 +0000)
Refactor social sharing helper

app/assets/javascripts/index/note.js
app/assets/javascripts/social_share_button.js
test/system/create_note_test.rb
test/system/note_comments_test.rb
test/system/resolve_note_test.rb [new file with mode: 0644]

index 8687321c92d3bce115d02c6b8973ffd01ebd9124..e9c51f9bf1df571f6814be4999a10517975fd28b 100644 (file)
@@ -61,7 +61,7 @@ OSM.Note = function (map) {
       };
 
       if (name !== "subscribe" && name !== "unsubscribe" && name !== "reopen") {
-        ajaxSettings.data = { text: $("textarea").val() };
+        ajaxSettings.data = { text: content.find("textarea").val() };
       }
 
       content.find("button[name]").prop("disabled", true);
index 409b2c58a7a3e2ef469a52749b22b229938232b0..34db84758a641121b52e8d2bdeabd6f34453151c 100644 (file)
@@ -2,8 +2,8 @@ function openShareUrl(url, initialWidth = 640, initialHeight = 480) {
   const width = Math.max(100, Math.min(screen.width, initialWidth));
   const height = Math.max(100, Math.min(screen.height, initialHeight));
 
-  const left = (screen.width / 2) - (width / 2);
-  const top = (screen.height * 0.3) - (height / 2);
+  const left = screenLeft + ((outerWidth - width) / 2);
+  const top = screenTop + ((outerHeight - height) / 2);
   const opts = `width=${width},height=${height},left=${left},top=${top},menubar=no,status=no,location=no`;
 
   window.open(url, "popup", opts);
index ccb2ed32fae1fd4ca8c825d995e81968bacc436e..435233cbe1f80ea15b824912f92d8bd00a69ef3b 100644 (file)
@@ -4,20 +4,24 @@ class CreateNoteTest < ApplicationSystemTestCase
   test "can create note" do
     visit new_note_path(:anchor => "map=18/0/0")
 
-    assert_button "Add Note", :disabled => true
+    within_sidebar do
+      assert_button "Add Note", :disabled => true
 
-    fill_in "text", :with => "Some newly added note description"
-    click_on "Add Note"
+      fill_in "text", :with => "Some newly added note description"
+      click_on "Add Note"
 
-    assert_content "Unresolved note ##{Note.last.id}"
-    assert_content "Some newly added note description"
+      assert_content "Unresolved note ##{Note.last.id}"
+      assert_content "Some newly added note description"
+    end
   end
 
   test "cannot create note when api is readonly" do
     with_settings(:status => "api_readonly") do
       visit new_note_path(:anchor => "map=18/0/0")
 
-      assert_no_button "Add Note", :disabled => true
+      within_sidebar do
+        assert_no_button "Add Note", :disabled => true
+      end
     end
   end
 end
index 0577992f277432f631f36e13358f8fc78daaf5ee..e8bc83b03a936a41e37f824daaefa73678eac302 100644 (file)
@@ -80,52 +80,6 @@ class NoteCommentsTest < ApplicationSystemTestCase
     end
   end
 
-  test "can't resolve a note when blocked" do
-    note = create(:note_with_comments)
-    user = create(:user)
-    sign_in_as(user)
-    visit note_path(note)
-    create(:user_block, :user => user)
-
-    within_sidebar do
-      assert_text "Unresolved note"
-      assert_no_text "Resolved note"
-      assert_no_text "Your access to the API has been blocked"
-      assert_button "Resolve", :disabled => false
-      assert_button "Comment", :disabled => true
-
-      click_on "Resolve"
-
-      assert_text "Unresolved note"
-      assert_no_text "Resolved note"
-      assert_text "Your access to the API has been blocked"
-      assert_button "Resolve", :disabled => false
-      assert_button "Comment", :disabled => true
-    end
-  end
-
-  test "can't reactivate a note when blocked" do
-    note = create(:note_with_comments, :closed)
-    user = create(:user)
-    sign_in_as(user)
-    visit note_path(note)
-    create(:user_block, :user => user)
-
-    within_sidebar do
-      assert_no_text "Unresolved note"
-      assert_text "Resolved note"
-      assert_no_text "Your access to the API has been blocked"
-      assert_button "Reactivate", :disabled => false
-
-      click_on "Reactivate"
-
-      assert_no_text "Unresolved note"
-      assert_text "Resolved note"
-      assert_text "Your access to the API has been blocked"
-      assert_button "Reactivate", :disabled => false
-    end
-  end
-
   test "no subscribe button when not logged in" do
     note = create(:note_with_comments)
     visit note_path(note)
diff --git a/test/system/resolve_note_test.rb b/test/system/resolve_note_test.rb
new file mode 100644 (file)
index 0000000..7f47e45
--- /dev/null
@@ -0,0 +1,106 @@
+require "application_system_test_case"
+
+class ResolveNoteTest < ApplicationSystemTestCase
+  test "can resolve an open note" do
+    note = create(:note_with_comments)
+    user = create(:user)
+    sign_in_as(user)
+    visit note_path(note)
+
+    within_sidebar do
+      assert_button "Resolve"
+      assert_no_button "Comment & Resolve"
+      assert_no_button "Reactivate"
+
+      click_on "Resolve"
+
+      assert_content "Resolved note ##{note.id}"
+    end
+  end
+
+  test "can resolve an open note with a comment" do
+    note = create(:note_with_comments)
+    user = create(:user)
+    sign_in_as(user)
+    visit note_path(note)
+
+    within_sidebar do
+      assert_button "Resolve"
+      assert_no_button "Comment & Resolve"
+      assert_no_button "Reactivate"
+
+      fill_in "text", :with => "Note resolve text"
+
+      assert_button "Comment & Resolve"
+
+      click_on "Comment & Resolve"
+
+      assert_content "Resolved note ##{note.id}"
+      assert_content "Note resolve text"
+    end
+  end
+
+  test "can reactivate a closed note" do
+    note = create(:note_with_comments, :closed)
+    user = create(:user)
+    sign_in_as(user)
+    visit note_path(note)
+
+    within_sidebar do
+      assert_no_button "Resolve"
+      assert_no_button "Comment & Resolve"
+      assert_button "Reactivate"
+
+      click_on "Reactivate"
+
+      assert_content "Unresolved note ##{note.id}"
+      assert_no_content "<iframe" # leak from share textarea
+    end
+  end
+
+  test "can't resolve a note when blocked" do
+    note = create(:note_with_comments)
+    user = create(:user)
+    sign_in_as(user)
+    visit note_path(note)
+    create(:user_block, :user => user)
+
+    within_sidebar do
+      assert_text "Unresolved note"
+      assert_no_text "Resolved note"
+      assert_no_text "Your access to the API has been blocked"
+      assert_button "Resolve", :disabled => false
+      assert_button "Comment", :disabled => true
+
+      click_on "Resolve"
+
+      assert_text "Unresolved note"
+      assert_no_text "Resolved note"
+      assert_text "Your access to the API has been blocked"
+      assert_button "Resolve", :disabled => false
+      assert_button "Comment", :disabled => true
+    end
+  end
+
+  test "can't reactivate a note when blocked" do
+    note = create(:note_with_comments, :closed)
+    user = create(:user)
+    sign_in_as(user)
+    visit note_path(note)
+    create(:user_block, :user => user)
+
+    within_sidebar do
+      assert_no_text "Unresolved note"
+      assert_text "Resolved note"
+      assert_no_text "Your access to the API has been blocked"
+      assert_button "Reactivate", :disabled => false
+
+      click_on "Reactivate"
+
+      assert_no_text "Unresolved note"
+      assert_text "Resolved note"
+      assert_text "Your access to the API has been blocked"
+      assert_button "Reactivate", :disabled => false
+    end
+  end
+end