Skip to content

Commit

Permalink
[Op#40437]: wait for activity tab comments to load (opf#17055)
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru authored Oct 29, 2024
1 parent 4f221f9 commit 32f9763
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%=
component_wrapper(class: "work-packages-activities-tab-journals-index-component") do
flex_layout do |journals_index_wrapper_container|
flex_layout(data: { test_selector: "op-wp-journals-#{filter}-#{journal_sorting}" }) do |journals_index_wrapper_container|
journals_index_wrapper_container.with_row(
classes: "work-packages-activities-tab-journals-index-component--journals-inner-container",
mb: inner_container_margin_bottom
Expand Down
10 changes: 4 additions & 6 deletions spec/features/activities/work_package/activities_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
version: 2)

# the comment is shown without browser reload
activity_tab.expect_journal_notes(text: "First comment by member")
wait_for { page }.to have_test_selector("op-journal-notes-body", text: "First comment by member")

# simulate comments made within the polling interval
create(:work_package_journal, user: member, notes: "Second comment by member", journable: work_package, version: 3)
Expand All @@ -387,10 +387,8 @@

first_journal.update!(notes: "First comment by member updated")

sleep 1 # avoid flaky test

# properly updates the comment when the comment is updated
activity_tab.expect_journal_notes(text: "First comment by member updated")
wait_for { page }.to have_test_selector("op-journal-notes-body", text: "First comment by member updated")
end
end

Expand Down Expand Up @@ -872,15 +870,15 @@
# auto-scrolls to the bottom when a new comment is added by the user
# add a comment
activity_tab.add_comment(text: "New comment by admin")
activity_tab.expect_journal_notes(text: "New comment by admin") # wait for the comment to be added
activity_tab.expect_journal_container_at_bottom

# auto-scrolls to the bottom when a new comment is added by another user
# add a comment
latest_journal_version = work_package.journals.last.version
create(:work_package_journal, user: member, notes: "New comment by member", journable: work_package,
version: latest_journal_version + 1)
activity_tab.expect_journal_notes(text: "New comment by member") # wait for the comment to be added
# wait for the comment to be added
wait_for { page }.to have_test_selector("op-journal-notes-body", text: "New comment by member")
sleep 1 # wait for auto scrolling to finish
activity_tab.expect_journal_container_at_bottom
end
Expand Down
18 changes: 10 additions & 8 deletions spec/support/components/work_packages/activities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Activities
include Capybara::DSL
include Capybara::RSpecMatchers
include RSpec::Matchers
include RSpec::Wait

attr_reader :work_package

Expand Down Expand Up @@ -144,7 +145,6 @@ def expect_no_input_field
end

def add_comment(text: nil, save: true)
# TODO: get rid of static sleep
sleep 1 # otherwise the stimulus component is not mounted yet and the click does not work

if page.find_test_selector("op-open-work-package-journal-form-trigger")
Expand All @@ -160,7 +160,8 @@ def add_comment(text: nil, save: true)

if save
page.within_test_selector("op-wp-journals-container") do
expect(page).to have_text(text)
# wait for the comment to be loaded
wait_for { page }.to have_test_selector("op-journal-notes-body", text:)
end
end
end
Expand All @@ -175,12 +176,12 @@ def edit_comment(journal, text: nil)
page.find_test_selector("op-submit-work-package-journal-form").click
end

expect(page).to have_text(text)
# wait for the comment to be loaded
wait_for { page }.to have_test_selector("op-journal-notes-body", text:)
end
end

def quote_comment(journal)
# TODO: get rid of static sleep
sleep 1 # otherwise the stimulus component is not mounted yet and the click does not work

within_journal_entry(journal) do
Expand All @@ -199,7 +200,7 @@ def get_all_comments_as_arrary
page.all(".work-packages-activities-tab-journals-item-component--journal-notes-body").map(&:text)
end

def filter_journals(filter)
def filter_journals(filter, default_sorting: User.current.preference&.comments_sorting || "desc")
page.find_test_selector("op-wp-journals-filter-menu").click

case filter
Expand All @@ -211,10 +212,11 @@ def filter_journals(filter)
page.find_test_selector("op-wp-journals-filter-show-only-changes").click
end

sleep 1 # wait for the journals to be reloaded, TODO: get rid of static sleep
# Ensure the journals are reloaded
wait_for { page }.to have_test_selector("op-wp-journals-#{filter}-#{default_sorting}")
end

def set_journal_sorting(sorting)
def set_journal_sorting(sorting, default_filter: :all)
page.find_test_selector("op-wp-journals-sorting-menu").click

case sorting
Expand All @@ -224,7 +226,7 @@ def set_journal_sorting(sorting)
page.find_test_selector("op-wp-journals-sorting-desc").click
end

sleep 1 # wait for the journals to be reloaded, TODO: get rid of static sleep
wait_for { page }.to have_test_selector("op-wp-journals-#{default_filter}-#{sorting}")
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions spec/support/components/work_packages/emoji_reactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
module Components
module WorkPackages
class EmojiReactions < Activities
include RSpec::Wait

def add_first_emoji_reaction_for_journal(journal, emoji)
within_journal_entry(journal) do
click_on "Add reaction"
Expand Down

0 comments on commit 32f9763

Please sign in to comment.