discourse/plugins/chat/spec/system/channel_info_pages_spec.rb
Joffrey JAFFEUX 0764dc3452
FIX: cancel fetching messages after channel change (#21689)
This issue was especially visible in tests. the `@debounce(100)` was not cancelled when changing channel which was causing 404s as we were trying to load messages on a channel which was deleted as the channel has been destroyed at the end of the test.

This is still not a perfect solution, as we can only cancel the start of `fetchMessages`, but we can't cancel the actual `chatApi.channel` request which result can potentially happens after channel changed, which we try to mitigate with various checks on to ensure visible channel == loaded messages channel.

This commit also tries to make handler naming and cancelling more consistent.

<!-- NOTE: All pull requests should have tests (rspec in Ruby, qunit in JavaScript). If your code does not include test coverage, please include an explanation of why it was omitted. -->
2023-05-23 16:01:47 +02:00

39 lines
1.1 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Info pages", type: :system, js: true do
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:channel) { PageObjects::Pages::ChatChannel.new }
fab!(:current_user) { Fabricate(:user) }
fab!(:channel_1) { Fabricate(:chat_channel) }
before do
chat_system_bootstrap
channel_1.add(current_user)
sign_in(current_user)
end
context "when visiting from browse page" do
context "when clicking back button" do
it "redirects to browse page" do
chat_page.visit_browse
find(".chat-channel-card__setting").click
find(".chat-full-page-header__back-btn").click
expect(page).to have_current_path("/chat/browse/open")
end
end
end
context "when visiting from channel page" do
context "when clicking back button" do
it "redirects to channel page" do
chat_page.visit_channel(channel_1)
find(".chat-channel-title-wrapper").click
find(".chat-full-page-header__back-btn").click
expect(page).to have_current_path(chat.channel_path(channel_1.slug, channel_1.id))
end
end
end
end