mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Move Bookmark modal/component to use d-modal (#22532)
c.f. https://meta.discourse.org/t/converting-modals-from-legacy-controllers-to-new-dmodal-component-api/268057 This also converts the Bookmark component to a Glimmer component.
This commit is contained in:
@@ -2,14 +2,18 @@
|
||||
|
||||
describe "Bookmarking posts and topics", type: :system do
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:current_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") }
|
||||
fab!(:post_2) { Fabricate(:post, topic: topic, raw: "Some interesting post content") }
|
||||
|
||||
let(:timezone) { "Australia/Brisbane" }
|
||||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||
let(:bookmark_modal) { PageObjects::Modals::Bookmark.new }
|
||||
|
||||
before { sign_in user }
|
||||
before do
|
||||
current_user.user_option.update!(timezone: timezone)
|
||||
sign_in(current_user)
|
||||
end
|
||||
|
||||
def visit_topic_and_open_bookmark_modal(post)
|
||||
topic_page.visit_topic(topic)
|
||||
@@ -24,15 +28,15 @@ describe "Bookmarking posts and topics", type: :system do
|
||||
bookmark_modal.save
|
||||
|
||||
expect(topic_page).to have_post_bookmarked(post)
|
||||
bookmark = Bookmark.find_by(bookmarkable: post, user: user)
|
||||
bookmark = Bookmark.find_by(bookmarkable: post, user: current_user)
|
||||
expect(bookmark.name).to eq("something important")
|
||||
expect(bookmark.reminder_at).to eq(nil)
|
||||
|
||||
visit_topic_and_open_bookmark_modal(post2)
|
||||
visit_topic_and_open_bookmark_modal(post_2)
|
||||
|
||||
bookmark_modal.select_preset_reminder(:tomorrow)
|
||||
expect(topic_page).to have_post_bookmarked(post2)
|
||||
bookmark = Bookmark.find_by(bookmarkable: post2, user: user)
|
||||
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
|
||||
@@ -44,7 +48,7 @@ describe "Bookmarking posts and topics", type: :system do
|
||||
bookmark_modal.cancel
|
||||
|
||||
expect(topic_page).to have_no_post_bookmarked(post)
|
||||
expect(Bookmark.exists?(bookmarkable: post, user: user)).to eq(false)
|
||||
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
|
||||
@@ -56,22 +60,108 @@ describe "Bookmarking posts and topics", type: :system do
|
||||
expect(topic_page).to have_post_bookmarked(post)
|
||||
end
|
||||
|
||||
it "allows the topic to be bookmarked" do
|
||||
topic_page.visit_topic(topic)
|
||||
topic_page.click_topic_footer_button(:bookmark)
|
||||
|
||||
bookmark_modal.fill_name("something important")
|
||||
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)
|
||||
bookmark_modal.open_options_panel
|
||||
expect(bookmark_modal).to have_auto_delete_preference(
|
||||
Bookmark.auto_delete_preferences[:on_owner_reply],
|
||||
)
|
||||
bookmark_modal.select_auto_delete_preference(Bookmark.auto_delete_preferences[:clear_reminder])
|
||||
bookmark_modal.save
|
||||
expect(topic_page).to have_post_bookmarked(post_2)
|
||||
topic_page.click_post_action_button(post_2, :bookmark)
|
||||
expect(bookmark_modal).to have_open_options_panel
|
||||
expect(bookmark_modal).to have_auto_delete_preference(
|
||||
Bookmark.auto_delete_preferences[:clear_reminder],
|
||||
)
|
||||
end
|
||||
|
||||
expect(topic_page).to have_topic_bookmarked
|
||||
bookmark =
|
||||
try_until_success { expect(Bookmark.exists?(bookmarkable: topic, user: user)).to eq(true) }
|
||||
expect(bookmark).not_to eq(nil)
|
||||
describe "topic level bookmarks" do
|
||||
it "allows the topic to be bookmarked" do
|
||||
topic_page.visit_topic(topic)
|
||||
topic_page.click_topic_footer_button(:bookmark)
|
||||
|
||||
bookmark_modal.fill_name("something important")
|
||||
bookmark_modal.save
|
||||
|
||||
expect(topic_page).to have_topic_bookmarked
|
||||
expect(Bookmark.exists?(bookmarkable: topic, user: current_user)).to be_truthy
|
||||
end
|
||||
|
||||
it "opens the edit bookmark modal from the topic bookmark button if one post is bookmarked" do
|
||||
bookmark = Fabricate(:bookmark, bookmarkable: post_2, user: current_user)
|
||||
topic_page.visit_topic(topic)
|
||||
topic_page.click_topic_footer_button(:bookmark)
|
||||
expect(bookmark_modal).to be_open
|
||||
expect(bookmark_modal).to be_editing_id(bookmark.id)
|
||||
end
|
||||
|
||||
it "clears all topic bookmarks from the topic bookmark button if more than one post is bookmarked" do
|
||||
Fabricate(:bookmark, bookmarkable: post, user: current_user)
|
||||
Fabricate(:bookmark, bookmarkable: post_2, user: current_user)
|
||||
topic_page.visit_topic(topic)
|
||||
topic_page.click_topic_footer_button(:bookmark)
|
||||
dialog = PageObjects::Components::Dialog.new
|
||||
expect(dialog).to have_content(I18n.t("js.bookmarks.confirm_clear"))
|
||||
dialog.click_yes
|
||||
expect(dialog).to be_closed
|
||||
expect(Bookmark.where(user: current_user).count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe "editing existing bookmarks" do
|
||||
fab!(:bookmark) do
|
||||
Fabricate(
|
||||
:bookmark,
|
||||
bookmarkable: post_2,
|
||||
user: current_user,
|
||||
name: "test name",
|
||||
reminder_at: 10.days.from_now,
|
||||
)
|
||||
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)
|
||||
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(
|
||||
bookmark_modal.existing_reminder_alert_message(bookmark),
|
||||
)
|
||||
expect(bookmark_modal.custom_date_picker.value).to eq(
|
||||
bookmark.reminder_at_in_zone(timezone).strftime("%Y-%m-%d"),
|
||||
)
|
||||
expect(bookmark_modal.custom_time_picker.value).to eq(
|
||||
bookmark.reminder_at_in_zone(timezone).strftime("%H:%M"),
|
||||
)
|
||||
expect(bookmark_modal).to have_active_preset("custom")
|
||||
end
|
||||
|
||||
it "can delete the bookmark" do
|
||||
topic_page.visit_topic(topic)
|
||||
topic_page.click_post_action_button(post_2, :bookmark)
|
||||
bookmark_modal.delete
|
||||
bookmark_modal.confirm_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)
|
||||
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")
|
||||
expect(bookmark.reload.name).to eq("test name")
|
||||
end
|
||||
end
|
||||
|
||||
context "when the user has a bookmark auto_delete_preference" do
|
||||
before do
|
||||
user.user_option.update!(
|
||||
current_user.user_option.update!(
|
||||
bookmark_auto_delete_preference: Bookmark.auto_delete_preferences[:on_owner_reply],
|
||||
)
|
||||
end
|
||||
@@ -82,7 +172,7 @@ describe "Bookmarking posts and topics", type: :system do
|
||||
bookmark_modal.save
|
||||
expect(topic_page).to have_post_bookmarked(post)
|
||||
|
||||
bookmark = Bookmark.find_by(bookmarkable: post, user: user)
|
||||
bookmark = Bookmark.find_by(bookmarkable: post, user: current_user)
|
||||
expect(bookmark.auto_delete_preference).to eq(
|
||||
Bookmark.auto_delete_preferences[:on_owner_reply],
|
||||
)
|
||||
@@ -94,7 +184,7 @@ describe "Bookmarking posts and topics", type: :system do
|
||||
bookmark_modal.save
|
||||
expect(topic_page).to have_post_bookmarked(post)
|
||||
|
||||
bookmark = Bookmark.find_by(bookmarkable: post, user: user)
|
||||
bookmark = Bookmark.find_by(bookmarkable: post, user: current_user)
|
||||
expect(bookmark.auto_delete_preference).to eq(
|
||||
Bookmark.auto_delete_preferences[:on_owner_reply],
|
||||
)
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
module PageObjects
|
||||
module Components
|
||||
class Dialog < PageObjects::Components::Base
|
||||
def closed?
|
||||
has_no_css?(".dialog-container")
|
||||
end
|
||||
|
||||
def open?
|
||||
has_css?(".dialog-container")
|
||||
end
|
||||
|
||||
def has_content?(content)
|
||||
find(".dialog-container").has_content?(content)
|
||||
end
|
||||
|
||||
@@ -4,16 +4,90 @@ module PageObjects
|
||||
module Modals
|
||||
class Bookmark < PageObjects::Modals::Base
|
||||
def fill_name(name)
|
||||
fill_in "bookmark-name", with: name
|
||||
fill_in("bookmark-name", with: name)
|
||||
end
|
||||
|
||||
def name
|
||||
find("#bookmark-name")
|
||||
end
|
||||
|
||||
def select_preset_reminder(identifier)
|
||||
find("#tap_tile_#{identifier}").click
|
||||
end
|
||||
|
||||
def has_active_preset?(identifier)
|
||||
has_css?("#tap_tile_#{identifier}.tap-tile.active")
|
||||
end
|
||||
|
||||
def has_preset?(identifier)
|
||||
has_css?("#tap_tile_#{identifier}")
|
||||
end
|
||||
|
||||
def has_no_preset?(identifier)
|
||||
has_no_css?("#tap_tile_#{identifier}")
|
||||
end
|
||||
|
||||
def editing_id?(bookmark_id)
|
||||
has_css?(".bookmark-reminder-modal[data-bookmark-id='#{bookmark_id}']")
|
||||
end
|
||||
|
||||
def open_options_panel
|
||||
find(".bookmark-options-button").click
|
||||
end
|
||||
|
||||
def has_open_options_panel?
|
||||
has_css?(".bookmark-options-panel")
|
||||
end
|
||||
|
||||
def select_auto_delete_preference(preference)
|
||||
select_kit = PageObjects::Components::SelectKit.new("#bookmark-auto-delete-preference")
|
||||
select_kit.expand
|
||||
select_kit.select_row_by_value(preference)
|
||||
end
|
||||
|
||||
def has_auto_delete_preference?(preference)
|
||||
select_kit = PageObjects::Components::SelectKit.new("#bookmark-auto-delete-preference")
|
||||
select_kit.has_selected_value?(preference)
|
||||
end
|
||||
|
||||
def custom_date_picker
|
||||
find(".tap-tile-date-input #custom-date .date-picker")
|
||||
end
|
||||
|
||||
def custom_time_picker
|
||||
find(".tap-tile-time-input #custom-time")
|
||||
end
|
||||
|
||||
def save
|
||||
find("#save-bookmark").click
|
||||
end
|
||||
|
||||
def delete
|
||||
find("#delete-bookmark").click
|
||||
end
|
||||
|
||||
def confirm_delete
|
||||
find(".dialog-footer .btn-danger").click
|
||||
end
|
||||
|
||||
def existing_reminder_alert
|
||||
find(".existing-reminder-at-alert")
|
||||
end
|
||||
|
||||
def existing_reminder_alert_message(bookmark)
|
||||
I18n.t(
|
||||
"js.bookmarks.reminders.existing_reminder",
|
||||
at_date_time:
|
||||
I18n.t(
|
||||
"js.bookmarks.reminders.at_time",
|
||||
date_time:
|
||||
bookmark
|
||||
.reminder_at_in_zone(bookmark.user.user_option&.timezone || "UTC")
|
||||
.strftime("%b %-d, %Y %l:%M %P")
|
||||
.gsub(" ", " "), # have to do this because %l adds padding before the hour but not in JS
|
||||
),
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user