Skip to content

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

Allow tests to call poll trigger manually

Oliver Güntherf03d2a48b9f7
diff --git a/frontend/src/stimulus/controllers/poll-for-changes.controller.ts b/frontend/src/stimulus/controllers/poll-for-changes.controller.ts
index b323c17501a..f2886bec534 100644
--- a/frontend/src/stimulus/controllers/poll-for-changes.controller.ts
+++ b/frontend/src/stimulus/controllers/poll-for-changes.controller.ts
@@ -44,17 +44,25 @@ export default class PollForChangesController extends ApplicationController {
private interval:number;
+ private pollListener:() => unknown = () => this.triggerTurboStream();
+
connect() {
super.connect();
- this.interval = setInterval(() => {
- void this.triggerTurboStream();
- }, this.intervalValue || 10_000);
+
+ if (this.intervalValue !== 0) {
+ this.interval = setInterval(() => {
+ void this.triggerTurboStream();
+ }, this.intervalValue || 10_000);
+ }
+
+ this.element.addEventListener('op:poll-for-changes:trigger', this.pollListener);
}
disconnect() {
super.disconnect();
clearInterval(this.interval);
+ this.element.removeEventListener('op:poll-for-changes:trigger', this.pollListener);
}
async triggerTurboStream():Promise<void> {
diff --git a/modules/meeting/app/components/meetings/header_component.html.erb b/modules/meeting/app/components/meetings/header_component.html.erb
index 1e219313de4..4f4d617e7a5 100644
--- a/modules/meeting/app/components/meetings/header_component.html.erb
+++ b/modules/meeting/app/components/meetings/header_component.html.erb
@@ -1,6 +1,7 @@
<%=
component_wrapper do
render(Primer::OpenProject::PageHeader.new(
+ test_selector: "meeting-page-header",
state: @state,
data: {
controller: "poll-for-changes",
diff --git a/modules/meeting/spec/features/structured_meetings/history_spec.rb b/modules/meeting/spec/features/structured_meetings/history_spec.rb
index 64c7e1047f9..34140bd9f95 100644
--- a/modules/meeting/spec/features/structured_meetings/history_spec.rb
+++ b/modules/meeting/spec/features/structured_meetings/history_spec.rb
@@ -91,6 +91,7 @@ RSpec.describe "history",
# Create meeting
show_page.visit!
+ show_page.trigger_dropdown_menu_item "History"
history_page.open_history_modal
diff --git a/modules/meeting/spec/features/structured_meetings/structured_meeting_update_flash_spec.rb b/modules/meeting/spec/features/structured_meetings/structured_meeting_update_flash_spec.rb
index 24c33349fcc..7215454d39d 100644
--- a/modules/meeting/spec/features/structured_meetings/structured_meeting_update_flash_spec.rb
+++ b/modules/meeting/spec/features/structured_meetings/structured_meeting_update_flash_spec.rb
@@ -46,9 +46,10 @@ RSpec.describe "Structured meetings CRUD",
context "it shows an info toast when updated from a different page" do
before do
+ # Disable the polling so we can trigger it manually
allow_any_instance_of(Meetings::HeaderComponent)
.to receive(:check_for_updates_interval)
- .and_return(5000)
+ .and_return(0)
end
it do
@@ -59,7 +60,9 @@ RSpec.describe "Structured meetings CRUD",
show_page.visit!
# Visit meeting on window2 and do something
+ first_window = current_window
second_window = open_new_window
+
within_window(second_window) do
show_page.visit!
@@ -69,45 +72,45 @@ RSpec.describe "Structured meetings CRUD",
end
# Expect change in window1
- expect(page).to have_css(flash_component, wait: 5)
- expect(page).to have_text I18n.t(:notice_meeting_updated)
-
- click_on "Reload"
+ within_window(first_window) do
+ show_page.trigger_change_poll
+ expect(page).to have_css(flash_component, wait: 5)
+ expect(page).to have_text I18n.t(:notice_meeting_updated)
+ click_on "Reload"
+ end
# Expect no notification in window2
within_window(second_window) do
- sleep 2
+ show_page.trigger_change_poll
# expect(page).to have_no_css(flash_component)
expect(page).to have_no_text I18n.t(:notice_meeting_updated)
end
## Edit agenda item
# In window1
- sleep 2
- item = MeetingAgendaItem.find_by(title: "Update toast test item")
+ within_window(first_window) do
+ item = MeetingAgendaItem.find_by(title: "Update toast test item")
- show_page.edit_agenda_item(item) do
- fill_in "Title", with: "Updated title"
- click_on "Save"
- end
+ show_page.edit_agenda_item(item) do
+ fill_in "Title", with: "Updated title"
+ click_on "Save"
+ end
- # Expect no notification in window1
- sleep 2
- # expect(page).to have_no_css(flash_component)
- expect(page).to have_no_text I18n.t(:notice_meeting_updated)
+ # Expect no notification in window1 because we're editing in the same
+ # expect(page).to have_no_css(flash_component)
+ show_page.trigger_change_poll
+ expect(page).to have_no_text I18n.t(:notice_meeting_updated)
+ end
# Expect notification in window2
within_window(second_window) do
+ show_page.trigger_change_poll
expect(page).to have_css(flash_component, wait: 5)
expect(page).to have_text I18n.t(:notice_meeting_updated)
click_on "Reload"
- end
- ## Add section
- # In window2
- within_window(second_window) do
- sleep 2
+ ## Add section while we're in window2
show_page.add_section do
fill_in "Title", with: "First section"
click_on "Save"
@@ -117,40 +120,40 @@ RSpec.describe "Structured meetings CRUD",
end
# Expect change in window1
- expect(page).to have_css(flash_component, wait: 5)
- expect(page).to have_text I18n.t(:notice_meeting_updated)
-
- click_on "Reload"
+ within_window(first_window) do
+ show_page.trigger_change_poll
+ expect(page).to have_css(flash_component, wait: 5)
+ expect(page).to have_text I18n.t(:notice_meeting_updated)
+ click_on "Reload"
+ end
# Expect no notification in window2
within_window(second_window) do
- sleep 2
- # expect(page).to have_no_css(flash_component)
+ show_page.trigger_change_poll
expect(page).to have_no_text I18n.t(:notice_meeting_updated)
end
- # ## Edit meeting details
- # ## In window1
- # item = MeetingAgendaItem.find_by(title: "Update toast test item")
-
- # show_page.edit_agenda_it em(item) do
- # fill_in "Title", with: "Updated title"
- # click_on "Save"
- # end
+ ## Edit meeting details
+ ## In window1
+ within_window(first_window) do
+ find_test_selector("edit-meeting-details-button").click
+ fill_in "structured_meeting_duration", with: "2.5"
+ click_link_or_button "Save"
- # # Expect no notification in window1
- # expect(page).to have_no_css(flash_component)
- # expect(page).to have_no_text I18n.t(:notice_meeting_updated)
+ # Expect updated duration
+ expect(page).to have_text "2 hrs, 30 mins"
- # # Expect notification in window2
- # within_window(second_window) do
- # expect(page).to have_css(flash_component, wait: 5)
- # expect(page).to have_text I18n.t(:notice_meeting_updated)
+ # Expect no notification in window1
+ show_page.trigger_change_poll
+ expect(page).to have_no_text I18n.t(:notice_meeting_updated)
+ end
- # within flash_component do
- # click "Reload"
- # end
- # end
+ # Expect notification in window2
+ within_window(second_window) do
+ show_page.trigger_change_poll
+ expect(page).to have_text I18n.t(:notice_meeting_updated)
+ click_on "Reload"
+ end
second_window.close
end
diff --git a/modules/meeting/spec/support/pages/structured_meeting/history.rb b/modules/meeting/spec/support/pages/structured_meeting/history.rb
index 385e1fb2b25..2713c8ebe83 100644
--- a/modules/meeting/spec/support/pages/structured_meeting/history.rb
+++ b/modules/meeting/spec/support/pages/structured_meeting/history.rb
@@ -33,14 +33,10 @@ module Pages::StructuredMeeting
@meeting = meeting
end
- def open_history_modal
- retry_block do
- click_link_or_button "op-meetings-header-action-trigger"
- click_link_or_button "History"
- # dynamically wait for the modal to be loaded
- # otherwise running into timing issues with `item = history_page.first_item`
- expect(page).to have_css(".op-activity-list--item")
- end
+ def expect_modal_open
+ # dynamically wait for the modal to be loaded
+ # otherwise running into timing issues with `item = history_page.first_item`
+ expect(page).to have_css(".op-activity-list--item")
end
def close_history_modal
diff --git a/modules/meeting/spec/support/pages/structured_meeting/show.rb b/modules/meeting/spec/support/pages/structured_meeting/show.rb
index 9f6455be622..b5105b51956 100644
--- a/modules/meeting/spec/support/pages/structured_meeting/show.rb
+++ b/modules/meeting/spec/support/pages/structured_meeting/show.rb
@@ -36,6 +36,23 @@ module Pages::StructuredMeeting
expect(page).to have_no_css('[id^="meeting-agenda-items-item-component"]')
end
+ def trigger_dropdown_menu_item(name)
+ click_link_or_button "op-meetings-header-action-trigger"
+ click_link_or_button name
+ end
+
+ def trigger_change_poll
+ script = <<~JS
+ var event = new CustomEvent(
+ 'op:poll-for-changes:trigger',
+ );
+
+ document.querySelector('[data-test-selector="meeting-page-header"]').dispatchEvent(event);
+ JS
+
+ page.execute_script(script)
+ end
+
def add_agenda_item(type: MeetingAgendaItem, save: true, &)
page.within("#meeting-agenda-items-new-button-component") do
click_on I18n.t(:button_add)