mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Redesigned bookmark modal and menu (#23071)
Adds the new quick menu for bookmarking. When you bookmark a post (chat message behaviour will come later) we show this new quick menu and bookmark the item straight away. You can then choose a reminder quick option, or choose Custom... to open the old modal. If you click on an existing bookmark, we show the same quick menu but with Edit and Delete options. A later PR will introduce a new bookmark modal, but for now we are using the old modal for Edit and Custom... options.
This commit is contained in:
@@ -9,63 +9,61 @@ describe "Bookmarking posts and topics", type: :system do
|
||||
let(:timezone) { "Australia/Brisbane" }
|
||||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||
let(:bookmark_modal) { PageObjects::Modals::Bookmark.new }
|
||||
let(:bookmark_menu) { PageObjects::Components::BookmarkMenu.new }
|
||||
|
||||
before do
|
||||
current_user.user_option.update!(timezone: timezone)
|
||||
sign_in(current_user)
|
||||
end
|
||||
|
||||
def visit_topic_and_open_bookmark_modal(post)
|
||||
def visit_topic_and_open_bookmark_menu(post, expand_actions: true)
|
||||
topic_page.visit_topic(topic)
|
||||
topic_page.expand_post_actions(post)
|
||||
|
||||
topic_page.expand_post_actions(post) if expand_actions
|
||||
|
||||
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.fill_name("something important")
|
||||
bookmark_modal.save
|
||||
it "creates a bookmark on the post as soon as the bookmark button is clicked" do
|
||||
visit_topic_and_open_bookmark_menu(post)
|
||||
|
||||
expect(bookmark_menu).to be_open
|
||||
expect(page).to have_content(I18n.t("js.bookmarks.bookmarked_success"))
|
||||
expect(topic_page).to have_post_bookmarked(post)
|
||||
bookmark = Bookmark.find_by(bookmarkable: post, user: current_user)
|
||||
expect(bookmark.name).to eq("something important")
|
||||
expect(bookmark.reminder_at).to eq(nil)
|
||||
expect(Bookmark.find_by(bookmarkable: post, user: current_user)).to be_truthy
|
||||
end
|
||||
|
||||
visit_topic_and_open_bookmark_modal(post_2)
|
||||
it "updates the created bookmark with a selected reminder option from the bookmark menu" do
|
||||
visit_topic_and_open_bookmark_menu(post)
|
||||
|
||||
expect(bookmark_menu).to be_open
|
||||
expect(page).to have_content(I18n.t("js.bookmarks.bookmarked_success"))
|
||||
|
||||
bookmark_menu.click_menu_option("tomorrow")
|
||||
expect(page).to have_content(I18n.t("js.bookmarks.reminder_set_success"))
|
||||
expect(Bookmark.find_by(bookmarkable: post, user: current_user).reminder_at).not_to be_blank
|
||||
end
|
||||
|
||||
it "can set a reminder from the bookmark modal using the custom bookmark menu option" do
|
||||
visit_topic_and_open_bookmark_menu(post)
|
||||
bookmark_menu.click_menu_option("custom")
|
||||
bookmark_modal.select_preset_reminder(:tomorrow)
|
||||
expect(topic_page).to have_post_bookmarked(post_2)
|
||||
bookmark = Bookmark.find_by(bookmarkable: post_2, user: current_user)
|
||||
expect(bookmark.reminder_at).not_to eq(nil)
|
||||
expect(bookmark.reminder_set_at).not_to eq(nil)
|
||||
end
|
||||
|
||||
it "does not create a bookmark if the modal is closed with the cancel button" do
|
||||
visit_topic_and_open_bookmark_modal(post)
|
||||
|
||||
bookmark_modal.fill_name("something important")
|
||||
bookmark_modal.cancel
|
||||
|
||||
expect(topic_page).to have_no_post_bookmarked(post)
|
||||
expect(Bookmark.exists?(bookmarkable: post, user: current_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)
|
||||
expect(Bookmark.find_by(bookmarkable: post, user: current_user).reminder_at).not_to be_blank
|
||||
end
|
||||
|
||||
it "allows choosing a different auto_delete_preference to the user preference and remembers it when reopening the modal" do
|
||||
current_user.user_option.update!(
|
||||
bookmark_auto_delete_preference: Bookmark.auto_delete_preferences[:on_owner_reply],
|
||||
)
|
||||
visit_topic_and_open_bookmark_modal(post_2)
|
||||
visit_topic_and_open_bookmark_menu(post_2)
|
||||
bookmark_menu.click_menu_option("custom")
|
||||
expect(bookmark_modal).to be_open
|
||||
|
||||
# TODO (martin) Not sure why, but I need to click this twice for the panel to open :/
|
||||
bookmark_modal.open_options_panel
|
||||
bookmark_modal.open_options_panel
|
||||
|
||||
expect(bookmark_modal).to have_auto_delete_preference(
|
||||
Bookmark.auto_delete_preferences[:on_owner_reply],
|
||||
)
|
||||
@@ -73,6 +71,7 @@ describe "Bookmarking posts and topics", type: :system do
|
||||
bookmark_modal.save
|
||||
expect(topic_page).to have_post_bookmarked(post_2)
|
||||
topic_page.click_post_action_button(post_2, :bookmark)
|
||||
bookmark_menu.click_menu_option("edit")
|
||||
expect(bookmark_modal).to have_open_options_panel
|
||||
expect(bookmark_modal).to have_auto_delete_preference(
|
||||
Bookmark.auto_delete_preferences[:clear_reminder],
|
||||
@@ -125,8 +124,8 @@ describe "Bookmarking posts and topics", type: :system do
|
||||
end
|
||||
|
||||
it "prefills the name of the bookmark and the custom reminder date and time" do
|
||||
topic_page.visit_topic(topic)
|
||||
topic_page.click_post_action_button(post_2, :bookmark)
|
||||
visit_topic_and_open_bookmark_menu(post_2, expand_actions: false)
|
||||
bookmark_menu.click_menu_option("edit")
|
||||
expect(bookmark_modal).to have_open_options_panel
|
||||
expect(bookmark_modal.name.value).to eq("test name")
|
||||
expect(bookmark_modal.existing_reminder_alert).to have_content(
|
||||
@@ -142,20 +141,27 @@ describe "Bookmarking posts and topics", type: :system do
|
||||
end
|
||||
|
||||
it "can delete the bookmark" do
|
||||
topic_page.visit_topic(topic)
|
||||
topic_page.click_post_action_button(post_2, :bookmark)
|
||||
visit_topic_and_open_bookmark_menu(post_2, expand_actions: false)
|
||||
bookmark_menu.click_menu_option("edit")
|
||||
bookmark_modal.delete
|
||||
bookmark_modal.confirm_delete
|
||||
expect(topic_page).to have_no_post_bookmarked(post_2)
|
||||
end
|
||||
|
||||
it "can delete the bookmark from within the menu" do
|
||||
visit_topic_and_open_bookmark_menu(post_2, expand_actions: false)
|
||||
bookmark_menu.click_menu_option("delete")
|
||||
expect(topic_page).to have_no_post_bookmarked(post_2)
|
||||
end
|
||||
|
||||
it "does not save edits when pressing cancel" do
|
||||
topic_page.visit_topic(topic)
|
||||
topic_page.click_post_action_button(post_2, :bookmark)
|
||||
visit_topic_and_open_bookmark_menu(post_2, expand_actions: false)
|
||||
bookmark_menu.click_menu_option("edit")
|
||||
bookmark_modal.fill_name("something important")
|
||||
bookmark_modal.cancel
|
||||
topic_page.click_post_action_button(post_2, :bookmark)
|
||||
expect(bookmark_modal.name.value).to eq("test name")
|
||||
bookmark_menu.click_menu_option("edit")
|
||||
expect(bookmark_modal.name.value).to eq("something important")
|
||||
expect(bookmark.reload.name).to eq("test name")
|
||||
end
|
||||
end
|
||||
|
||||
15
spec/system/page_objects/components/bookmark_menu.rb
Normal file
15
spec/system/page_objects/components/bookmark_menu.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PageObjects
|
||||
module Components
|
||||
class BookmarkMenu < PageObjects::Components::Base
|
||||
def click_menu_option(option_id)
|
||||
find(".bookmark-menu__row[data-menu-option-id='#{option_id}']").click
|
||||
end
|
||||
|
||||
def open?
|
||||
has_css?(".bookmark-menu__body")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -83,7 +83,7 @@ module PageObjects
|
||||
def click_post_action_button(post, button)
|
||||
case button
|
||||
when :bookmark
|
||||
post_by_number(post).find(".bookmark.with-reminder").click
|
||||
post_by_number(post).find(".bookmark").click
|
||||
when :reply
|
||||
post_by_number(post).find(".post-controls .reply").click
|
||||
when :flag
|
||||
@@ -240,10 +240,7 @@ module PageObjects
|
||||
|
||||
def is_post_bookmarked(post, bookmarked:)
|
||||
within post_by_number(post) do
|
||||
page.public_send(
|
||||
bookmarked ? :has_css? : :has_no_css?,
|
||||
".bookmark.with-reminder.bookmarked",
|
||||
)
|
||||
page.public_send(bookmarked ? :has_css? : :has_no_css?, ".bookmark.bookmarked")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user