mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: correctly filter user bookmarks (#28612)
We were not updating `searchTerm` when changing the input which was making us always send an empty q parameter. This commit is also adding tests for: - initial url with q param - filtering the bookmarks through the input
This commit is contained in:
parent
5df3aa66c8
commit
6f91014d64
@ -30,11 +30,11 @@ export default class UserActivityBookmarksController extends Controller {
|
|||||||
|
|
||||||
@computed("q")
|
@computed("q")
|
||||||
get searchTerm() {
|
get searchTerm() {
|
||||||
return this.q;
|
return this._searchTerm || this.q;
|
||||||
}
|
}
|
||||||
|
|
||||||
set searchTerm(value) {
|
set searchTerm(value) {
|
||||||
/* noop */
|
this._searchTerm = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@discourseComputed()
|
@discourseComputed()
|
||||||
@ -59,7 +59,7 @@ export default class UserActivityBookmarksController extends Controller {
|
|||||||
@action
|
@action
|
||||||
search() {
|
search() {
|
||||||
this.router.transitionTo({
|
this.router.transitionTo({
|
||||||
queryParams: { q: this.searchTerm },
|
queryParams: { q: this._searchTerm },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
@type="text"
|
@type="text"
|
||||||
@value={{this.searchTerm}}
|
@value={{this.searchTerm}}
|
||||||
placeholder={{i18n "bookmarks.search_placeholder"}}
|
placeholder={{i18n "bookmarks.search_placeholder"}}
|
||||||
@enter={{action "search"}}
|
@enter={{this.search}}
|
||||||
id="bookmark-search"
|
id="bookmark-search"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
/>
|
/>
|
||||||
|
41
spec/system/page_objects/pages/user_activity_bookmarks.rb
Normal file
41
spec/system/page_objects/pages/user_activity_bookmarks.rb
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module PageObjects
|
||||||
|
module Pages
|
||||||
|
class UserActivityBookmarks < PageObjects::Pages::Base
|
||||||
|
def visit(user, q: nil)
|
||||||
|
url = "/u/#{user.username_lower}/activity/bookmarks"
|
||||||
|
url += "?q=#{q}" if q
|
||||||
|
page.visit(url)
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def search_for(query)
|
||||||
|
fill_in_search(query).submit_button.click
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_query
|
||||||
|
fill_in_search("").submit_button.click
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def fill_in_search(query)
|
||||||
|
fill_in("bookmark-search", with: query)
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_topic?(topic)
|
||||||
|
has_content?(topic.title)
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_no_topic?(topic)
|
||||||
|
has_no_content?(topic.title)
|
||||||
|
end
|
||||||
|
|
||||||
|
def submit_button
|
||||||
|
@submit_button ||= page.find(".bookmark-search-form button")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
61
spec/system/user_activity_bookmarks_spec.rb
Normal file
61
spec/system/user_activity_bookmarks_spec.rb
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe "User activity bookmarks", type: :system do
|
||||||
|
fab!(:current_user) { Fabricate(:user) }
|
||||||
|
fab!(:bookmark_1) do
|
||||||
|
Fabricate(
|
||||||
|
:bookmark,
|
||||||
|
user: current_user,
|
||||||
|
name: "Bookmark 1",
|
||||||
|
bookmarkable: Fabricate(:post, raw: "a nice event"),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
fab!(:bookmark_2) do
|
||||||
|
Fabricate(
|
||||||
|
:bookmark,
|
||||||
|
user: current_user,
|
||||||
|
name: "Bookmark 2",
|
||||||
|
bookmarkable: Fabricate(:post, raw: "a pretty cat"),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:user_activity_bookmarks) { PageObjects::Pages::UserActivityBookmarks.new }
|
||||||
|
|
||||||
|
before do
|
||||||
|
SearchIndexer.enable
|
||||||
|
SearchIndexer.index(bookmark_1.bookmarkable, force: true)
|
||||||
|
SearchIndexer.index(bookmark_2.bookmarkable, force: true)
|
||||||
|
Fabricate(:topic_user, user: current_user, topic: bookmark_1.bookmarkable.topic)
|
||||||
|
Fabricate(:topic_user, user: current_user, topic: bookmark_2.bookmarkable.topic)
|
||||||
|
|
||||||
|
sign_in(current_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
after { SearchIndexer.disable }
|
||||||
|
|
||||||
|
it "can filter the list of bookmarks from the URL" do
|
||||||
|
user_activity_bookmarks.visit(current_user, q: bookmark_1.bookmarkable.raw)
|
||||||
|
|
||||||
|
expect(user_activity_bookmarks).to have_no_topic(bookmark_2.bookmarkable.topic)
|
||||||
|
expect(user_activity_bookmarks).to have_topic(bookmark_1.bookmarkable.topic)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can filter the list of bookmarks" do
|
||||||
|
user_activity_bookmarks.visit(current_user).search_for(bookmark_2.bookmarkable.raw)
|
||||||
|
|
||||||
|
expect(user_activity_bookmarks).to have_no_topic(bookmark_1.bookmarkable.topic)
|
||||||
|
expect(user_activity_bookmarks).to have_topic(bookmark_2.bookmarkable.topic)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can clear the query" do
|
||||||
|
user_activity_bookmarks.visit(current_user).search_for(bookmark_2.bookmarkable.raw)
|
||||||
|
|
||||||
|
expect(user_activity_bookmarks).to have_no_topic(bookmark_1.bookmarkable.topic)
|
||||||
|
expect(user_activity_bookmarks).to have_topic(bookmark_2.bookmarkable.topic)
|
||||||
|
|
||||||
|
user_activity_bookmarks.clear_query
|
||||||
|
|
||||||
|
expect(user_activity_bookmarks).to have_topic(bookmark_1.bookmarkable.topic)
|
||||||
|
expect(user_activity_bookmarks).to have_topic(bookmark_2.bookmarkable.topic)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user