discourse/plugins/chat/spec/system/bookmark_message_spec.rb
Roman Rizzi 5c699e4384
DEV: Pass messageId as a dynamic segment instead of a query param (#20013)
* DEV: Rnemae channel path to just c

Also swap the channel id and channel slug params to be consistent with core.

* linting

* channel_path

* Drop slugify helper and channel route without slug

* Request slug and route models through the channel model if possible

* DEV: Pass messageId as a dynamic segment instead of a query param

* Ensure change is backwards-compatible

* drop query param from oneboxes

* Correctly extract channelId from routes

* Better route organization using siblings for regular and near-message

* Ensures sessions are unique even when using parallelism

* prevents didReceiveAttrs to clear input mid test

* we disable animations in capybara so sometimes the message was barely showing

* adds wait

* ensures finished loading

* is it causing more harm than good?

* this check is slowing things for no reason

* actually target the button

* more resilient select chat message

* apply similar fix to bookmark

* fix

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-02-01 12:39:23 -03:00

72 lines
2.1 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Bookmark message", type: :system, js: true do
fab!(:current_user) { Fabricate(:user) }
let(:chat) { PageObjects::Pages::Chat.new }
let(:channel) { PageObjects::Pages::ChatChannel.new }
let(:bookmark_modal) { PageObjects::Modals::Bookmark.new }
fab!(:category_channel_1) { Fabricate(:category_channel) }
fab!(:message_1) { Fabricate(:chat_message, chat_channel: category_channel_1) }
before do
chat_system_bootstrap
category_channel_1.add(current_user)
sign_in(current_user)
end
context "when desktop" do
it "allows to bookmark a message" do
chat.visit_channel(category_channel_1)
channel.bookmark_message(message_1)
bookmark_modal.fill_name("Check this out later")
bookmark_modal.select_preset_reminder(:next_month)
expect(channel).to have_bookmarked_message(message_1)
end
context "when the user has a bookmark auto_delete_preference" do
before do
current_user.user_option.update!(
bookmark_auto_delete_preference: Bookmark.auto_delete_preferences[:on_owner_reply],
)
end
it "is respected when the user creates a new bookmark" do
chat.visit_channel(category_channel_1)
channel.bookmark_message(message_1)
bookmark_modal.save
expect(channel).to have_bookmarked_message(message_1)
bookmark = Bookmark.find_by(bookmarkable: message_1, user: current_user)
expect(bookmark.auto_delete_preference).to eq(
Bookmark.auto_delete_preferences[:on_owner_reply],
)
end
end
end
context "when mobile", mobile: true do
it "allows to bookmark a message" do
chat.visit_channel(category_channel_1)
expect(channel).to have_no_loading_skeleton
i = 0.5
try_until_success(timeout: 20) do
channel.message_by_id(message_1.id).click(delay: i)
first(".bookmark-btn")
i += 0.1
end
find(".bookmark-btn").click
bookmark_modal.fill_name("Check this out later")
bookmark_modal.select_preset_reminder(:next_month)
expect(channel).to have_bookmarked_message(message_1)
end
end
end