From be4db2315403aa4da2b57f078475aee0a6b92a2b Mon Sep 17 00:00:00 2001 From: ishikawa999 Date: Thu, 17 Apr 2025 13:43:57 +0900 Subject: [PATCH 2/2] Fix system test not to fail --- .../copy_pre_content_to_clipboard_test.rb | 76 +++++++------------ 1 file changed, 28 insertions(+), 48 deletions(-) diff --git a/test/system/copy_pre_content_to_clipboard_test.rb b/test/system/copy_pre_content_to_clipboard_test.rb index 072f9e49c..d6db85206 100644 --- a/test/system/copy_pre_content_to_clipboard_test.rb +++ b/test/system/copy_pre_content_to_clipboard_test.rb @@ -18,72 +18,52 @@ require_relative '../application_system_test_case' class CopyPreContentToClipboardSystemTest < ApplicationSystemTestCase def test_copy_issue_pre_content_to_clipboard_if_common_mark - log_user('jsmith', 'jsmith') issue = Issue.find(1) - issue.journals.first.update(notes: "```\ntest\n```") - visit "/issues/#{issue.id}" - # A button appears when hovering over the
 tag
-    find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type").hover
-    find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type .copy-pre-content-link")
-    # Copy pre content to Clipboard
-    find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type .copy-pre-content-link").click
-    # Paste the value copied to the clipboard into the textarea to get and test
-    first('.icon-edit').click
-    find('textarea#issue_notes').send_keys([modifier_key, 'v'])
-    assert_equal find('textarea#issue_notes').value, 'test'
+    issue.update(description: "```\ntest\ncommon mark\n```")
+    assert_copied_pre_content_matches(issue_id: issue.id, expected_value: "test\ncommon mark")
   end
+
   def test_copy_issue_code_content_to_clipboard_if_common_mark
-    log_user('jsmith', 'jsmith')
     issue = Issue.find(1)
-    issue.journals.first.update(notes: "```ruby\nputs \"Hello, World.\"\n```")
-    visit "/issues/#{issue.id}"
-    # A button appears when hovering over the 
 tag
-    find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type").hover
-    find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type .copy-pre-content-link")
-    # Copy pre content to Clipboard
-    find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type .copy-pre-content-link").click
-    # Paste the value copied to the clipboard into the textarea to get and test
-    first('.icon-edit').click
-    find('textarea#issue_notes').send_keys([modifier_key, 'v'])
-    assert_equal find('textarea#issue_notes').value, 'puts "Hello, World."'
+    issue.update(description: "```ruby\nputs 'Hello, World.'\ncommon mark\n```")
+    assert_copied_pre_content_matches(issue_id: issue.id, expected_value: "puts 'Hello, World.'\ncommon mark")
   end
+
   def test_copy_issue_pre_content_to_clipboard_if_textile
-    log_user('jsmith', 'jsmith')
     issue = Issue.find(1)
-    issue.journals.first.update(notes: "
\ntest\n
") + issue.update(description: "
\ntest\ntextile\n
") with_settings text_formatting: :textile do - visit "/issues/#{issue.id}" - # A button appears when hovering over the
 tag
-      find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type").hover
-      find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type .copy-pre-content-link")
-      # Copy pre content to Clipboard
-      find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type .copy-pre-content-link").click
-      # Paste the value copied to the clipboard into the textarea to get and test
-      first('.icon-edit').click
-      find('textarea#issue_notes').send_keys([modifier_key, 'v'])
-      assert_equal find('textarea#issue_notes').value, 'test'
+      assert_copied_pre_content_matches(issue_id: issue.id, expected_value: "test\ntextile")
     end
   end
+
   def test_copy_issue_code_content_to_clipboard_if_textile
-    log_user('jsmith', 'jsmith')
     issue = Issue.find(1)
-    issue.journals.first.update(notes: "
\nputs \"Hello, World.\"\n
") + issue.update(description: "
\nputs 'Hello, World.'\ntextile\n
") with_settings text_formatting: :textile do - visit "/issues/#{issue.id}" - # A button appears when hovering over the
 tag
-      find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type").hover
-      find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type .copy-pre-content-link")
-      # Copy pre content to Clipboard
-      find("#journal-#{issue.journals.first.id}-notes div.pre-wrapper:first-of-type .copy-pre-content-link").click
-      # Paste the value copied to the clipboard into the textarea to get and test
-      first('.icon-edit').click
-      find('textarea#issue_notes').send_keys([modifier_key, 'v'])
-      assert_equal find('textarea#issue_notes').value, 'puts "Hello, World."'
+      assert_copied_pre_content_matches(issue_id: issue.id, expected_value: "puts 'Hello, World.'\ntextile")
     end
   end
+
   private
   def modifier_key
     modifier = osx? ? 'command' : 'control'
     modifier.to_sym
   end
+
+  def assert_copied_pre_content_matches(issue_id:, expected_value:)
+    visit "/issues/#{issue_id}"
+    # A button appears when hovering over the 
 tag
+    find("#issue_description_wiki div.pre-wrapper:first-of-type").hover
+    assert_selector('#issue_description_wiki div.pre-wrapper:first-of-type .copy-pre-content-link')
+
+    # Copy pre content to Clipboard
+    find("#issue_description_wiki div.pre-wrapper:first-of-type .copy-pre-content-link").click
+
+    # Paste the value copied to the clipboard into the textarea to get and test
+    first('.icon-edit').click
+    find('textarea#issue_notes').set('')
+    find('textarea#issue_notes').send_keys([modifier_key, 'v'])
+    assert_equal find('textarea#issue_notes').value, expected_value
+  end
 end
-- 
2.49.0