OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
fixed and cleaned up activity_comments_spec markdown specs
Jonas Jabari8f5d375e8eef
diff --git a/spec/features/work_packages/details/markdown/activity_comments_spec.rb b/spec/features/work_packages/details/markdown/activity_comments_spec.rbindex e8b7bf81937..f5319ae1f41 100644--- a/spec/features/work_packages/details/markdown/activity_comments_spec.rb+++ b/spec/features/work_packages/details/markdown/activity_comments_spec.rb@@ -11,14 +11,68 @@ RSpec.describe "activity comments", :js, :selenium dojournal_notes: initial_comment)endlet(:wp_page) { Pages::SplitWorkPackage.new(work_package, project) }- let(:selector) { ".work-packages--activity--add-comment" }- let(:comment_field) do- TextEditorField.new wp_page,- "comment",- selector:- end+ let(:activity_tab) { Components::WorkPackages::Activities.new(work_package) }let(:initial_comment) { "the first comment in this WP" }+ RSpec.shared_examples "a field which supports principal autocomplete" do+ let(:role) { create(:project_role, permissions: %i[view_work_packages edit_work_packages]) }+ let!(:user) do+ create(:user,+ member_with_roles: { project => role },+ firstname: "John")+ end+ let!(:mentioned_user) do+ create(:user,+ member_with_roles: { project => role },+ firstname: "Laura",+ lastname: "Foobar")+ end+ let!(:mentioned_group) do+ create(:group, lastname: "Laudators", member_with_roles: { project => role })+ end+ let(:activity_tab) { Components::WorkPackages::Activities.new(work_package) }++ shared_examples "principal autocomplete on field" do+ before do+ wp_page.visit!+ wp_page.ensure_page_loaded+ wp_page.switch_to_tab tab: :activity+ wp_page.wait_for_activity_tab+ end++ it "autocompletes links to user profiles" do+ activity_tab.open_new_comment_editor+ activity_tab.get_editor_form_field_element.input_element.send_keys(" @lau")+ expect(page).to have_css(".mention-list-item", text: mentioned_user.name)+ expect(page).to have_css(".mention-list-item", text: mentioned_group.name)+ expect(page).to have_no_css(".mention-list-item", text: user.name)++ # Close the autocompleter+ activity_tab.get_editor_form_field_element.input_element.send_keys :escape+ activity_tab.ckeditor.clear++ sleep 1++ activity_tab.ckeditor.type_slowly "@Laura"+ expect(page).to have_css(".mention-list-item", text: mentioned_user.name)+ expect(page).to have_no_css(".mention-list-item", text: mentioned_group.name)+ expect(page).to have_no_css(".mention-list-item", text: user.name)+ end+ end++ context "with the project page" do+ let(:wp_page) { Pages::SplitWorkPackage.new(work_package, project) }++ it_behaves_like "principal autocomplete on field"+ end++ context "without the project page" do+ let(:wp_page) { Pages::SplitWorkPackage.new(work_package) }++ it_behaves_like "principal autocomplete on field"+ end+ end+before dologin_as(current_user)allow(current_user.pref).to receive(:warn_on_leaving_unsaved?).and_return(false)@@ -30,91 +84,23 @@ RSpec.describe "activity comments", :js, :selenium dobefore dowp_page.visit!wp_page.ensure_page_loaded+ wp_page.switch_to_tab tab: :activity+ wp_page.wait_for_activity_tabendcontext "in edit state" do- before do- comment_field.activate!- end-describe "submitting comment" doit "does not submit with enter" do- comment_field.click_and_type_slowly "this is a comment"- comment_field.submit_by_enter-- expect(page).to have_no_css(".user-comment .message", text: "this is a comment")+ activity_tab.type_comment("this is a comment")+ activity_tab.get_editor_form_field_element.input_element.send_keys :enter+ # Enter key is ignored, so comment should not be submitted+ activity_tab.expect_no_journal_notes(text: "this is a comment")endit "submits with click" do- comment_field.click_and_type_slowly "this is a comment!1"- comment_field.submit_by_click-- wp_page.expect_comment text: "this is a comment!1"- end-- it "submits comments repeatedly" do- comment_field.click_and_type_slowly "this is my first comment!1"- comment_field.submit_by_click-- expect(page).to have_css(".user-comment > .message", count: 2)- wp_page.expect_comment text: "this is my first comment!1"-- expect(comment_field.editing?).to be false- comment_field.activate!- expect(comment_field.editing?).to be true-- comment_field.click_and_type_slowly "this is my second comment!1"- comment_field.submit_by_click-- expect(page).to have_css(".user-comment > .message", count: 3)- wp_page.expect_comment text: "this is my second comment!1"-- expect(comment_field.editing?).to be false- comment_field.activate!- expect(comment_field.editing?).to be true-- comment_field.click_and_type_slowly "this is my third comment!1"- comment_field.submit_by_click-- # Only shows three most recent- expect(page).to have_css(".user-comment > .message", count: 3)- wp_page.expect_comment text: "this is my third comment!1"-- wp_page.switch_to_tab tab: "Activity"- # Now showing all comments- expect(page).to have_css(".user-comment > .message", count: 4, wait: 10)-- expect(comment_field.editing?).to be false- comment_field.activate!- expect(comment_field.editing?).to be true-- comment_field.click_and_type_slowly "this is my fifth comment!1"- comment_field.submit_by_click-- expect(page).to have_css(".user-comment > .message", count: 4)- wp_page.expect_comment text: "this is my fifth comment!1"-- # Expect no activity details- expect(page).to have_no_css(".work-package-details-activities-messages li")- end- end-- describe "cancel comment" do- it do- expect(comment_field.editing?).to be true- comment_field.input_element.set "this is a comment"-- # Escape should NOT cancel the editing- comment_field.cancel_by_escape- expect(comment_field.editing?).to be true-- expect(page).to have_no_css(".user-comment .message", text: "this is a comment")-- # Click should cancel the editing- comment_field.cancel_by_click- expect(comment_field.editing?).to be false-- expect(page).to have_no_css(".user-comment .message", text: "this is a comment")+ activity_tab.type_comment("this is a comment!1")+ page.find_test_selector("op-submit-work-package-journal-form").click+ activity_tab.expect_journal_notes(text: "this is a comment!1")endend@@ -123,11 +109,13 @@ RSpec.describe "activity comments", :js, :selenium dolet!(:wp2) { create(:work_package, project:, subject: "AutoFoo") }it "can move to the work package by click (Regression #30928)" do- comment_field.input_element.send_keys("##{wp2.id}")+ activity_tab.type_comment("foo ##{wp2.id}")expect(page).to have_css(".mention-list-item", text: wp2.to_s.strip)- comment_field.submit_by_click- page.find("#activity-2 a.issue", text: wp2.id).click+ activity_tab.submit_comment+ activity_tab.expect_journal_notes(text: "foo") # check if the comment is saved++ page.find("a.issue", text: wp2.id).clickother_wp_page = Pages::FullWorkPackage.new wp2other_wp_page.ensure_page_loaded@@ -136,96 +124,33 @@ RSpec.describe "activity comments", :js, :selenium doenddescribe "users" do- it_behaves_like "a principal autocomplete field" do- let(:field) { comment_field }- end+ it_behaves_like "a field which supports principal autocomplete"endend- describe "with an existing comment" do- it "allows to edit an existing comment" do+ describe "with markdown" do+ it "allows to add e.g. bold text" do+ activity_tab.open_new_comment_editor# Insert new text, need to do this separately.''["Comment with", " ", "*", "*", "bold text", "*", "*", " ", "in it"].each do |key|- comment_field.input_element.send_keys key+ activity_tab.get_editor_form_field_element.input_element.send_keys keyend- comment_field.submit_by_click-- wp_page.expect_comment text: "Comment with bold text in it"- wp_page.expect_comment text: "bold text", subselector: "strong"-- # Hover the new activity- activity = page.find_by_id("activity-2")- page.driver.browser.action.move_to(activity.native).perform+ activity_tab.submit_comment- # Check the edit textarea- edit_button = activity.find(".icon-edit")- scroll_to_element(edit_button)- edit_button.click- edit = TextEditorField.new wp_page,- "comment",- selector: ".user-comment--form"-- # Insert new text, need to do this separately.- edit.input_element.click-- [:enter, "Comment with", " ", "_", "italic text", "_", " ", "in it"].each do |key|- edit.input_element.send_keys key- end-- edit.submit_by_click- wp_page.expect_comment text: "Comment with italic text in it"- wp_page.expect_comment text: "italic text", subselector: "em"+ activity_tab.expect_journal_notes(text: "Comment with bold text in it")+ activity_tab.expect_journal_notes(text: "bold text", subselector: "strong")endendend- describe "quoting" do- it "can quote a previous comment" do- expect(page).to have_css(".user-comment .message",- text: initial_comment)-- # Hover comment- quoted = page.find(".user-comment > .message")- scroll_to_element(quoted)- quoted.hover-- # Quote this comment- page.find(".comments-icons .icon-quote").click- expect(comment_field.editing?).to be true-- # Add our comment- expect(comment_field.input_element).to have_css("blockquote")- quote = comment_field.input_element[:innerHTML]- expect(quote).to eq '<p class="op-uc-p">Anonymous wrote:</p><blockquote class="op-uc-blockquote"><p class="op-uc-p">the first comment in this WP</p></blockquote>'-- # Extend the comment- comment_field.input_element.click-- comment_field.ckeditor.click_and_type_slowly :enter-- # Insert new text, need to do this separately.- comment_field.ckeditor.click_and_type_slowly :return, "this is ", "*", "*", "a bold", "*", "*", " remark"-- comment_field.submit_by_click-- # Scroll to the activity- scroll_to_element(page.find_by_id("activity-2"))-- wp_page.expect_comment text: "this is a bold remark"- wp_page.expect_comment count: 2- wp_page.expect_comment subselector: "blockquote"- wp_page.expect_comment subselector: "strong", text: "a bold"- end- end-describe "referencing another work package" dolet!(:work_package2) { create(:work_package, project:, type: create(:type)) }it "can reference another work package with all methods" do- comment_field.activate!+ activity_tab.open_new_comment_editor# Insert a new reference using the autocompleter- comment_field.input_element.send_keys "Single ##{work_package2.id}"+ activity_tab.get_editor_form_field_element.input_element.send_keys "Single ##{work_package2.id}"expect(page).to have_css(".mention-list-item", text: "#{work_package2.type.name} ##{work_package2.id}:")@@ -240,60 +165,39 @@ RSpec.describe "activity comments", :js, :selenium do"Triple ####{work_package2.id}",:return].each do |key|- comment_field.input_element.send_keys key+ activity_tab.get_editor_form_field_element.input_element.send_keys keyend- comment_field.submit_by_click+ activity_tab.submit_comment- wp_page.expect_comment text: "Single ##{work_package2.id}"- expect(page).to have_css(".user-comment opce-macro-wp-quickinfo", count: 2)- expect(page).to have_css(".user-comment opce-macro-wp-quickinfo .op-hover-card--preview-trigger", count: 2)+ activity_tab.expect_journal_notes(text: "Single ##{work_package2.id}")+ expect(page).to have_css(".work-packages-activities-tab-journals-item-component opce-macro-wp-quickinfo", count: 2)+ expect(page).to have_css(+ ".work-packages-activities-tab-journals-item-component opce-macro-wp-quickinfo .op-hover-card--preview-trigger", count: 2+ )endendit "can move away to another tab, keeping the draft comment" do- comment_field.activate!- comment_field.input_element.send_keys "I'm typing an important message here ..."+ activity_tab.open_new_comment_editor+ activity_tab.get_editor_form_field_element.input_element.send_keys "I'm typing an important message here ..."wp_page.switch_to_tab tab: :filesexpect(page).to have_test_selector("op-tab-content--tab-section")wp_page.switch_to_tab tab: :activity- comment_field.expect_active!- comment_field.ckeditor.expect_value "I'm typing an important message here ..."-- wp_page.switch_to_tab tab: :overview-- comment_field.expect_active!- comment_field.ckeditor.expect_value "I'm typing an important message here ..."-- comment_field.cancel_by_click+ activity_tab.expect_input_field+ activity_tab.ckeditor.expect_value "I'm typing an important message here ..."+ activity_tab.clear_comment# Has removed the draft nowwp_page.switch_to_tab tab: :filesexpect(page).to have_test_selector("op-tab-content--tab-section")wp_page.switch_to_tab tab: :activity- comment_field.expect_inactive!-- wp_page.switch_to_tab tab: :overview- comment_field.expect_inactive!- end- end-- context "with no permission" do- let(:role) { create(:project_role, permissions: %i(view_work_packages)) }- let(:current_user) { create(:user, member_with_roles: { project => role }) }-- before do- wp_page.visit!- wp_page.ensure_page_loaded- end-- it "does not show the field" do- expect(page).to have_no_selector(selector, visible: true)+ activity_tab.expect_no_input_fieldendendenddiff --git a/spec/support/components/work_packages/activities.rb b/spec/support/components/work_packages/activities.rbindex 323ae305de0..719c66092f4 100644--- a/spec/support/components/work_packages/activities.rb+++ b/spec/support/components/work_packages/activities.rb@@ -65,6 +65,14 @@ module Components# helpers for new primerized activities+ def ckeditor+ Components::WysiwygEditor.new("#work-package-journal-form-element")+ end++ def get_editor_form_field_element+ FormFields::Primerized::EditorFormField.new("notes", selector: "#work-package-journal-form-element")+ end+def within_journal_entry(journal, &)wait_for { page }.to have_test_selector("op-wp-journal-entry-#{journal.id}") # avoid flakynesspage.within_test_selector("op-wp-journal-entry-#{journal.id}", &)@@ -98,8 +106,14 @@ module Componentsexpect(page).not_to have_test_selector("op-journal-notes-header", text:, wait: 10)end- def expect_journal_notes(text: nil)- expect(page).to have_test_selector("op-journal-notes-body", text:, wait: 10)+ def expect_journal_notes(text: nil, subselector: nil, count: nil)+ if text && subselector+ expect(page).to have_css("#{page.test_selector('op-journal-notes-body')} #{subselector}", text:, wait: 10)+ elsif text+ expect(page).to have_test_selector("op-journal-notes-body", text:, wait: 10)+ elsif count+ expect(page).to have_test_selector("op-journal-notes-body", count:, wait: 10)+ endenddef expect_journal_mention(text: nil)@@ -164,7 +178,7 @@ module Componentsdef expect_unsaved_content(text)page.within_test_selector("op-work-package-journal-form-element") do- editor = FormFields::Primerized::EditorFormField.new("notes", selector: "#work-package-journal-form-element")+ editor = get_editor_form_field_elementexpect(editor.input_element.value).to eq(text)endend@@ -176,7 +190,7 @@ module Componentswait_for { page }.to have_test_selector("op-work-package-journal-form-element")page.within_test_selector("op-work-package-journal-form-element") do- editor = FormFields::Primerized::EditorFormField.new("notes", selector: "#work-package-journal-form-element")+ editor = get_editor_form_field_element# Wait for the editor to be initializedwait_for { editor.input_element }.to be_presenteditor.input_element.send_keys(text)@@ -188,7 +202,7 @@ module Componentsdef clear_comment(blur: false)page.within_test_selector("op-work-package-journal-form-element") do- editor = FormFields::Primerized::EditorFormField.new("notes", selector: "#work-package-journal-form-element")+ editor = get_editor_form_field_elementeditor.set_value("")if blur@@ -209,7 +223,7 @@ module Componentsendpage.within_test_selector("op-work-package-journal-form-element") do- FormFields::Primerized::EditorFormField.new("notes", selector: "#work-package-journal-form-element").set_value(text)+ get_editor_form_field_element.set_value(text)page.find_test_selector("op-submit-work-package-journal-form").click if saveend@@ -229,7 +243,7 @@ module Componentspage.find_test_selector("op-wp-journal-#{journal.id}-edit").clickpage.within_test_selector("op-work-package-journal-form-element") do- FormFields::Primerized::EditorFormField.new("notes", selector: "#work-package-journal-form-element").set_value(text)+ get_editor_form_field_element.set_value(text)page.find_test_selector("op-submit-work-package-journal-form").click if saveend@@ -246,7 +260,7 @@ module Componentspage.find_test_selector("op-wp-journal-#{journal.id}-edit").clickpage.within_test_selector("op-work-package-journal-form-element") do- editor = FormFields::Primerized::EditorFormField.new("notes", selector: "#work-package-journal-form-element")+ editor = get_editor_form_field_element# Wait for the editor to be initializedwait_for { editor.input_element }.to be_presenteditor.input_element.send_keys(text)