discourse/plugins/chat/spec/system/dates_separators_spec.rb
Joffrey JAFFEUX f20be4b092
FIX: prevents subscribing with an old id (#21509)
This issue was for example possibly causing the last visit indicator to be reset by `sent` messages events.

The following was happening:
- a user (bob) had a last message bus ID of 1 on a channel (id:1) subscription
- bob then go to another channel (id:2), unsubscribing from updates of channel (id:1)
- another user (laura) then send messages to channel (id:1)
- bob goes back to channel (id:1)

At this point we we doing in the same sequence:
- loading channel with messages, getting a new last message bus id
- subscribing to updates using the last known message bus id

Most of the times we were lucky enough for this to work (no events while away, or just got the new id in time...) but it was also very likely to do a double fetch of messages as MessageBus would think we were late.
2023-05-11 22:27:48 +02:00

67 lines
1.9 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Dates separators", type: :system, js: true do
fab!(:current_user) { Fabricate(:user) }
fab!(:channel_1) { Fabricate(:chat_channel) }
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
before do
chat_system_bootstrap
channel_1.add(current_user)
sign_in(current_user)
end
context "when today separator is out of screen" do
before do
20.times { Fabricate(:chat_message, chat_channel: channel_1, created_at: 1.day.ago) }
25.times { Fabricate(:chat_message, chat_channel: channel_1) }
end
it "shows it as a sticky date" do
chat_page.visit_channel(channel_1)
expect(page.find(".chat-message-separator__text-container.is-pinned")).to have_content(
I18n.t("js.chat.chat_message_separator.today"),
)
expect(page).to have_css(
".chat-message-separator__text-container:not(.is-pinned)",
visible: :hidden,
text:
"#{I18n.t("js.chat.chat_message_separator.yesterday")} - #{I18n.t("js.chat.last_visit")}",
)
end
end
context "when receiving messages on a different channel" do
fab!(:channel_2) { Fabricate(:chat_channel) }
fab!(:user_1) { Fabricate(:user) }
before do
channel_2.add(current_user)
channel_1.add(user_1)
end
it "doesn't impact the last visit separator" do
chat_page.visit_channel(channel_1)
channel_page.send_message("message1")
chat_page.visit_channel(channel_2)
using_session(:user_1) do |session|
sign_in(user_1)
chat_page.visit_channel(channel_1)
channel_page.send_message("message2")
session.quit
end
chat_page.visit_channel(channel_1)
expect(page).to have_css(
".chat-message-separator__text-container",
text: I18n.t("js.chat.last_visit"),
)
end
end
end