mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 05:33:38 +08:00
4fdb275683
Some of the changes in this commit are extracted from https://github.com/discourse/discourse/pull/17379. The bookmarks tab in the new user menu is different from the other tabs in that it can display a mixture of notifications and bookmarks. When there are unread bookmark reminder notifications, the tab displays all of these notifications at the top and fills the remaining space in the menu with the rest of the bookmarks. The bubble/badge count on the bookmarks tab indicates how many unread bookmark reminder notifications there are. On the technical aspect, since this commit introduces a new `bookmark-item` component, we've done some refactoring so that all 3 "item" components (`notification-item`, `reviewable-item` and the new `bookmark-item`) inherit from a base component and get identical HTML structure so they all look consistent. Internal tickets: t70584 and t65045.
61 lines
3.2 KiB
Ruby
61 lines
3.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe UserTopicBookmarkSerializer do
|
|
fab!(:user) { Fabricate(:user) }
|
|
let!(:topic) { Fabricate(:topic, user: user) }
|
|
let!(:post) { Fabricate(:post, topic: topic) }
|
|
let!(:bookmark) { Fabricate(:bookmark, name: 'Test', user: user, bookmarkable: topic) }
|
|
|
|
describe "#excerpt" do
|
|
it "uses the last_read_post_number + 1 for the bookmarks excerpt" do
|
|
next_unread_post = Fabricate(:post_with_long_raw_content, topic: bookmark.bookmarkable)
|
|
Fabricate(:post_with_external_links, topic: bookmark.bookmarkable)
|
|
bookmark.reload
|
|
TopicUser.change(user.id, bookmark.bookmarkable.id, { last_read_post_number: post.post_number })
|
|
serializer = UserTopicBookmarkSerializer.new(bookmark, scope: Guardian.new(user))
|
|
expect(serializer.excerpt).to eq(PrettyText.excerpt(next_unread_post.cooked, 300, keep_emoji_images: true))
|
|
end
|
|
|
|
it "does not use a small post for the last unread cooked post" do
|
|
small_action_post = Fabricate(:small_action, topic: bookmark.bookmarkable)
|
|
next_unread_post = Fabricate(:post_with_long_raw_content, topic: bookmark.bookmarkable)
|
|
Fabricate(:post_with_external_links, topic: bookmark.bookmarkable)
|
|
bookmark.reload
|
|
TopicUser.change(user.id, bookmark.bookmarkable.id, { last_read_post_number: post.post_number })
|
|
serializer = UserTopicBookmarkSerializer.new(bookmark, scope: Guardian.new(user))
|
|
expect(serializer.excerpt).to eq(PrettyText.excerpt(next_unread_post.cooked, 300, keep_emoji_images: true))
|
|
end
|
|
|
|
it "handles the last read post in the topic being a small post by getting the last read regular post" do
|
|
last_regular_post = Fabricate(:post_with_long_raw_content, topic: bookmark.bookmarkable)
|
|
small_action_post = Fabricate(:small_action, topic: bookmark.bookmarkable)
|
|
bookmark.reload
|
|
topic.reload
|
|
TopicUser.change(user.id, bookmark.bookmarkable.id, { last_read_post_number: small_action_post.post_number })
|
|
serializer = UserTopicBookmarkSerializer.new(bookmark, scope: Guardian.new(user))
|
|
expect(serializer.cooked).to eq(last_regular_post.cooked)
|
|
expect(serializer.excerpt).to eq(PrettyText.excerpt(last_regular_post.cooked, 300, keep_emoji_images: true))
|
|
end
|
|
end
|
|
|
|
describe "#bookmarkable_url" do
|
|
context "with the link_to_first_unread_post option" do
|
|
it "is a full topic URL to the first unread post in the topic when the option is set" do
|
|
TopicUser.change(user.id, bookmark.bookmarkable.id, { last_read_post_number: post.post_number })
|
|
serializer = UserTopicBookmarkSerializer.new(
|
|
bookmark,
|
|
scope: Guardian.new(user),
|
|
link_to_first_unread_post: true
|
|
)
|
|
expect(serializer.bookmarkable_url).to end_with("/t/#{topic.slug}/#{topic.id}/#{post.post_number + 1}")
|
|
end
|
|
|
|
it "is a full topic URL to the first post in the topic when the option isn't set" do
|
|
TopicUser.change(user.id, bookmark.bookmarkable.id, { last_read_post_number: post.post_number })
|
|
serializer = UserTopicBookmarkSerializer.new(bookmark, scope: Guardian.new(user))
|
|
expect(serializer.bookmarkable_url).to end_with("/t/#{topic.slug}/#{topic.id}")
|
|
end
|
|
end
|
|
end
|
|
end
|