0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/plugins/poll/spec/system/large_poll_scroll_spec.rb
Régis Hanol 6fa7aa7b05
FIX: Preserve scroll position when toggling a poll's results (#41002)
Previously, clicking the button that toggles a large poll between its
results and the ballot scroll-jumped the page far down — often to the
bottom — leaving the poll off-screen and the vote seemingly impossible
to amend (the browser's native scroll anchoring loses its anchor node
when the toggle removes the results table the user is scrolled into).

This change pins the poll's button row and restores its viewport
position with `window.scrollBy` after the swap, so the poll stays
exactly where the user was looking when switching between results and
voting.

Meta:
https://meta.discourse.org/t/large-poll-bug-users-cannot-amend-votes-on-open-polls/405511
2026-06-29 11:41:35 +02:00

43 lines
1.3 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Returning to the ballot on a large open poll" do
fab!(:user)
fab!(:topic)
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:poll_page) { PageObjects::Pages::Poll.new(topic_page:) }
before do
SiteSetting.poll_enabled = true
SiteSetting.poll_maximum_options = 100
sign_in(user)
end
it "keeps the poll on screen when the user clicks back to the ballot" do
options = (1..80).map { |i| "* Option #{format("%02d", i)}" }.join("\n")
post = Fabricate(:post, topic:, raw: <<~RAW)
[poll type=multiple results=always min=1 max=80]
#{options}
[/poll]
RAW
20.times do |i|
Fabricate(:post, topic:, raw: "Reply #{i} that keeps the topic tall enough to scroll.")
end
page.current_window.resize_to(1100, 700)
topic_page.visit_topic(topic)
expect(poll_page).to have_poll_for_post(post)
poll_page.vote_for_option(post, "Option 01")
poll_page.vote_for_option(post, "Option 02")
poll_page.click_cast_votes(post)
expect(poll_page).to have_results_toggle(post)
poll_page.scroll_results_toggle_into_view
poll_page.click_results_toggle
expect(poll_page).to have_voting_options(post)
expect(poll_page).to have_poll_within_viewport
end
end