A platform for community discussion. Free, open, simple.
FIX: Add bookmark quick access tests and fix username (#16934)
Martin Brennane8ca927b129e
diff --git a/app/assets/javascripts/discourse/app/widgets/quick-access-bookmarks.js b/app/assets/javascripts/discourse/app/widgets/quick-access-bookmarks.jsindex b11f5d88962..c7ec173d1e5 100644--- a/app/assets/javascripts/discourse/app/widgets/quick-access-bookmarks.js+++ b/app/assets/javascripts/discourse/app/widgets/quick-access-bookmarks.js@@ -70,7 +70,7 @@ createWidgetFrom(QuickAccessPanel, "quick-access-bookmarks", {href,title: bookmark.name,content: bookmark.title,- username: bookmark.post_user_username,+ username: bookmark.user.username,});},diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-bookmarks-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-bookmarks-test.jsindex d7eedfdd23a..4c379d80b9e 100644--- a/app/assets/javascripts/discourse/tests/acceptance/user-bookmarks-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/user-bookmarks-test.js@@ -1,4 +1,8 @@-import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";+import {+ acceptance,+ exists,+ queryAll,+} from "discourse/tests/helpers/qunit-helpers";import { click, visit } from "@ember/test-helpers";import { cloneJSON } from "discourse-common/lib/object";import selectKit from "discourse/tests/helpers/select-kit-helper";@@ -56,13 +60,13 @@ acceptance("User's bookmarks - reminder", function (needs) {test("bookmarks with reminders have a clear reminder option", async function (assert) {await visit("/u/eviltrout/activity/bookmarks");- assert.ok(exists(".bookmark-reminder"));+ assert.strictEqual(queryAll(".bookmark-reminder").length, 2);const dropdown = selectKit(".bookmark-actions-dropdown");await dropdown.expand();await dropdown.selectRowByValue("clear_reminder");- assert.not(exists(".bookmark-reminder"));+ assert.strictEqual(queryAll(".bookmark-reminder").length, 1);});});diff --git a/app/assets/javascripts/discourse/tests/fixtures/user-fixtures.js b/app/assets/javascripts/discourse/tests/fixtures/user-fixtures.jsindex cafbe1a5672..35ef0f30f5d 100644--- a/app/assets/javascripts/discourse/tests/fixtures/user-fixtures.js+++ b/app/assets/javascripts/discourse/tests/fixtures/user-fixtures.js@@ -421,18 +421,23 @@ export default {user_bookmark_list: {bookmarks: [{- excerpt: "Here this is my new topic where I yell.",- tags: [],id: 576,created_at: "2020-04-07T05:30:40.446Z",- topic_id: 119,- linked_post_number: 1,- bookmarkable_id: 281,- bookmarkable_type: "Post",- bookmarkable_url: "http://localhost:4200/t/yelling-topic-title/119",+ updated_at: "2020-04-07T05:30:40.446Z",name: "test",reminder_at: null,+ reminder_at_ics_start: null,+ reminder_at_ics_end: null,+ pinned: false,title: "Yelling topic title :/",+ fancy_title: "Yelling topic title :/",+ excerpt: "Here this is my new topic where I yell.",+ bookmarkable_id: 281,+ bookmarkable_type: "Post",+ bookmarkable_url: "http://localhost:4200/t/yelling-topic-title/119",+ tags: [],+ topic_id: 119,+ linked_post_number: 1,deleted: false,hidden: false,category_id: 1,@@ -440,12 +445,37 @@ export default {archived: false,archetype: "regular",highest_post_number: 5,+ last_read_post_number: 3,bumped_at: "2020-04-06T05:20:00.172Z",slug: "yelling-topic-title",- post_user_username: "someguy",- post_user_name: "Some Guy",- post_user_avatar_template:- "/letter_avatar/someguy/{size}/3_f9720745f5ce6dfc2b5641fca999d934.png",+ user: {+ id: 1,+ username: "someguy",+ name: "Some Guy",+ avatar_template: "/user_avatar/127.0.0.1/someguy/{size}/918_2.png",+ }+ },+ {+ id: 4857,+ created_at: "2022-05-07T05:30:40.446Z",+ updated_at: "2022-05-27T05:30:40.446Z",+ name: "test",+ reminder_at: "2022-05-29T22:00:00.000Z",+ reminder_at_ics_start: "20220529T220000Z",+ reminder_at_ics_end: "20220529T230000Z",+ pinned: false,+ title: "Channel Name",+ fancy_title: "Channel Name",+ excerpt: "some excerpt",+ bookmarkable_id: 2437,+ bookmarkable_type: "ChatMessage",+ bookmarkable_url: "http://localhost:4200/chat/message/2437",+ user: {+ id: 4343,+ username: "otherperson",+ name: "Other Person",+ avatar_template: "/user_avatar/127.0.0.1/otherperson/{size}/918_2.png",+ }},],},diff --git a/app/assets/javascripts/discourse/tests/integration/widgets/user-menu-test.js b/app/assets/javascripts/discourse/tests/integration/widgets/user-menu-test.jsindex 91dbd076f23..80b776091aa 100644--- a/app/assets/javascripts/discourse/tests/integration/widgets/user-menu-test.js+++ b/app/assets/javascripts/discourse/tests/integration/widgets/user-menu-test.js@@ -160,10 +160,13 @@ discourseModule(async test(assert) {await click(".user-bookmarks-link");- const bookmark = query(".quick-access-panel li a");- assert.ok(bookmark);+ const allBookmarks = queryAll(".quick-access-panel li a");+ const bookmark = allBookmarks[0];- assert.ok(bookmark.href.includes("/t/yelling-topic-title/119"));+ assert.ok(+ bookmark.href.includes("/t/yelling-topic-title/119"),+ "the Post bookmark should have a link to the topic"+ );assert.ok(bookmark.innerHTML.includes("someguy"),"should include the last poster's username"@@ -172,6 +175,10 @@ discourseModule(bookmark.innerHTML.match(/<img.*class="emoji".*>/),"should correctly render emoji in bookmark title");+ assert.ok(+ bookmark.innerHTML.includes("d-icon-bookmark"),+ "should use the correct icon based on no reminder_at present"+ );const routeToStub = sinon.stub(DiscourseURL, "routeTo");await click(".user-bookmarks-link");@@ -179,6 +186,18 @@ discourseModule(routeToStub.calledWith(queryAll(".user-bookmarks-link").data("url")),"a second click should redirect to the full bookmarks page");++ const nonPostBookmarkableBookmark = allBookmarks[1];+ assert.ok(+ nonPostBookmarkableBookmark.href.includes("chat/message/2437"),+ "bookmarkable_type that is not Post or Topic should use bookmarkable_url for the item link"+ );+ assert.ok(+ nonPostBookmarkableBookmark.innerHTML.includes(+ "d-icon-discourse-bookmark-clock"+ ),+ "should use the correct icon based on reminder_at present"+ );},});