mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 05:53:38 +08:00
e323628d8a
What is the problem? We are relying on RSpec custom matchers in system tests by defining predicates in page objects. The problem is that this can result in a system test unnecessarily waiting up till the full duration of Capybara's default wait time when the RSpec custom matcher is used with `not_to`. Considering this topic page object where we have a `has_post?` predicate defined. ``` class Topic < PageObject def has_post? has_css?('something') end end ``` The assertion `expect(Topic.new).not_to have_post` will end up waiting the full Capybara's default wait time since the RSpec custom matcher is calling Capybara's `has_css?` method which will wait until the selector appear. If the selector has already disappeared by the time the assertion is called, we end up waiting for something that will never exists. This commit fixes such cases by introducing new predicates that uses the `has_no_*` versions of Capybara's node matchers. For future reference, `to have_css` and `not_to have_css` is safe to sue because the RSpec matcher defined by Capbyara is smart enough to call `has_css?` or `has_no_css?` based on the expectation of the assertion.
104 lines
3.4 KiB
Ruby
104 lines
3.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe "Bookmarking posts and topics", type: :system, js: true do
|
|
fab!(:topic) { Fabricate(:topic) }
|
|
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") }
|
|
|
|
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.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)
|
|
|
|
visit_topic_and_open_bookmark_modal(post2)
|
|
|
|
bookmark_modal.select_preset_reminder(:tomorrow)
|
|
expect(topic_page).to have_post_bookmarked(post2)
|
|
bookmark = Bookmark.find_by(bookmarkable: post2, user: 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: 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
|
|
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
|
|
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
|