mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Bookmark auto delete preference usage and default value (#19707)
This commit fixes an issue where the chat message bookmarks did not respect the user's `bookmark_auto_delete_preference` which they select in their user preference page. Also, it changes the default for that value to "keep bookmark and clear reminder" rather than "never", which ends up leaving a lot of expired bookmark reminders around which are a pain to clean up.
This commit is contained in:
@@ -2,30 +2,34 @@
|
||||
|
||||
describe "Bookmarking posts and topics", type: :system, js: true do
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
fab!(:user) { Fabricate(:user, username: "bookmarkguy") }
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:post) { Fabricate(:post, topic: topic, raw: "This is some post to bookmark") }
|
||||
fab!(:post2) { Fabricate(:post, topic: topic, raw: "Some interesting post content") }
|
||||
|
||||
it "allows logged in user to create bookmarks with and without reminders" do
|
||||
sign_in user
|
||||
visit "/t/#{topic.id}"
|
||||
topic_page = PageObjects::Pages::Topic.new
|
||||
expect(topic_page).to have_post_content(post)
|
||||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||
let(:bookmark_modal) { PageObjects::Modals::Bookmark.new }
|
||||
|
||||
before { sign_in user }
|
||||
|
||||
def visit_topic_and_open_bookmark_modal(post)
|
||||
topic_page.visit_topic(topic)
|
||||
topic_page.expand_post_actions(post)
|
||||
topic_page.click_post_action_button(post, :bookmark)
|
||||
end
|
||||
|
||||
it "allows the user to create bookmarks with and without reminders" do
|
||||
visit_topic_and_open_bookmark_modal(post)
|
||||
|
||||
bookmark_modal = PageObjects::Modals::Bookmark.new
|
||||
bookmark_modal.fill_name("something important")
|
||||
bookmark_modal.save
|
||||
|
||||
expect(topic_page).to have_post_bookmarked(post)
|
||||
bookmark = Bookmark.find_by(bookmarkable: post, user: user)
|
||||
expect(bookmark.name).to eq("something important")
|
||||
expect(bookmark.reminder_at).to eq(nil)
|
||||
|
||||
topic_page.expand_post_actions(post2)
|
||||
topic_page.click_post_action_button(post2, :bookmark)
|
||||
visit_topic_and_open_bookmark_modal(post2)
|
||||
|
||||
bookmark_modal = PageObjects::Modals::Bookmark.new
|
||||
bookmark_modal.select_preset_reminder(:tomorrow)
|
||||
expect(topic_page).to have_post_bookmarked(post2)
|
||||
bookmark = Bookmark.find_by(bookmarkable: post2, user: user)
|
||||
@@ -34,13 +38,8 @@ describe "Bookmarking posts and topics", type: :system, js: true do
|
||||
end
|
||||
|
||||
it "does not create a bookmark if the modal is closed with the cancel button" do
|
||||
sign_in user
|
||||
visit "/t/#{topic.id}"
|
||||
topic_page = PageObjects::Pages::Topic.new
|
||||
topic_page.expand_post_actions(post)
|
||||
topic_page.click_post_action_button(post, :bookmark)
|
||||
visit_topic_and_open_bookmark_modal(post)
|
||||
|
||||
bookmark_modal = PageObjects::Modals::Bookmark.new
|
||||
bookmark_modal.fill_name("something important")
|
||||
bookmark_modal.cancel
|
||||
|
||||
@@ -48,20 +47,57 @@ describe "Bookmarking posts and topics", type: :system, js: true do
|
||||
expect(Bookmark.exists?(bookmarkable: post, user: user)).to eq(false)
|
||||
end
|
||||
|
||||
it "creates a bookmark if the modal is closed by clicking outside the modal window" do
|
||||
visit_topic_and_open_bookmark_modal(post)
|
||||
|
||||
bookmark_modal.fill_name("something important")
|
||||
bookmark_modal.click_outside
|
||||
|
||||
expect(topic_page).to have_post_bookmarked(post)
|
||||
end
|
||||
|
||||
it "allows the topic to be bookmarked" do
|
||||
sign_in user
|
||||
visit "/t/#{topic.id}"
|
||||
topic_page = PageObjects::Pages::Topic.new
|
||||
topic_page.visit_topic(topic)
|
||||
topic_page.click_topic_footer_button(:bookmark)
|
||||
|
||||
bookmark_modal = PageObjects::Modals::Bookmark.new
|
||||
bookmark_modal.fill_name("something important")
|
||||
bookmark_modal.save
|
||||
|
||||
expect(topic_page).to have_topic_bookmarked
|
||||
bookmark = try_until_success do
|
||||
expect(Bookmark.exists?(bookmarkable: topic, user: user)).to eq(true)
|
||||
end
|
||||
bookmark =
|
||||
try_until_success { expect(Bookmark.exists?(bookmarkable: topic, user: user)).to eq(true) }
|
||||
expect(bookmark).not_to eq(nil)
|
||||
end
|
||||
|
||||
context "when the user has a bookmark auto_delete_preference" do
|
||||
before do
|
||||
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
|
||||
visit_topic_and_open_bookmark_modal(post)
|
||||
|
||||
bookmark_modal.save
|
||||
expect(topic_page).to have_post_bookmarked(post)
|
||||
|
||||
bookmark = Bookmark.find_by(bookmarkable: post, user: user)
|
||||
expect(bookmark.auto_delete_preference).to eq(
|
||||
Bookmark.auto_delete_preferences[:on_owner_reply],
|
||||
)
|
||||
end
|
||||
|
||||
it "allows the user to choose a different auto delete preference for a bookmark" do
|
||||
visit_topic_and_open_bookmark_modal(post)
|
||||
|
||||
bookmark_modal.save
|
||||
expect(topic_page).to have_post_bookmarked(post)
|
||||
|
||||
bookmark = Bookmark.find_by(bookmarkable: post, user: user)
|
||||
expect(bookmark.auto_delete_preference).to eq(
|
||||
Bookmark.auto_delete_preferences[:on_owner_reply],
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user