FIX: Correctly shows no bookmark message (#9548)

FIX: Correctly shows no bookmark message (#9548)

diff --git a/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks-with-reminders.js b/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks-with-reminders.js
index 9611ace..a24269d 100644
--- a/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks-with-reminders.js
+++ b/app/assets/javascripts/discourse/app/controllers/user-activity-bookmarks-with-reminders.js
@@ -2,6 +2,7 @@ import Controller from "@ember/controller";
 import showModal from "discourse/lib/show-modal";
 import { Promise } from "rsvp";
 import { inject } from "@ember/controller";
+import { action } from "@ember/object";
 import discourseComputed from "discourse-common/utils/decorators";
 import Bookmark from "discourse/models/bookmark";
 
@@ -22,12 +23,8 @@ export default Controller.extend({
 
     return this.model
       .loadItems()
-      .then(response => {
-        this.processLoadResponse(response);
-      })
-      .catch(() => {
-        this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
-      })
+      .then(response => this._processLoadResponse(response))
+      .catch(() => this._bookmarksListDenied())
       .finally(() =>
         this.setProperties({
           loaded: true,
@@ -38,69 +35,72 @@ export default Controller.extend({
 
   @discourseComputed("loaded", "content.length", "noResultsHelp")
   noContent(loaded, contentLength, noResultsHelp) {
-    return loaded && contentLength === 0 && noResultsHelp !== null;
+    return loaded && contentLength === 0 && noResultsHelp;
   },
 
-  processLoadResponse(response) {
-    response = response.user_bookmark_list;
+  @action
+  removeBookmark(bookmark) {
+    bootbox.confirm(I18n.t("bookmarks.confirm_delete"), result => {
+      if (result) {
+        return bookmark.destroy().then(() => this.loadItems());
+      }
+    });
+  },
 
-    if (response && response.no_results_help) {
-      this.set("noResultsHelp", response.no_results_help);
+  @action
+  editBookmark(bookmark) {
+    let controller = showModal("bookmark", {
+      model: {
+        postId: bookmark.post_id,
+        id: bookmark.id,
+        reminderAt: bookmark.reminder_at,
+        name: bookmark.name
+      },
+      title: "post.bookmarks.edit",
+      modalClass: "bookmark-with-reminder"
+    });
+    controller.setProperties({
+      afterSave: () => this.loadItems()
+    });
+  },
+
+  @action
+  loadMore() {
+    if (this.loadingMore) {
+      return Promise.resolve();
     }
 
-    this.model.more_bookmarks_url = response.more_bookmarks_url;
+    this.set("loadingMore", true);
 
-    if (response && response.bookmarks) {
-      let bookmarks = [];
-      response.bookmarks.forEach(bookmark => {
-        bookmarks.push(Bookmark.create(bookmark));
-      });
-      this.content.pushObjects(bookmarks);
-    }
+    return this.model
+      .loadMore()
+      .then(response => this._processLoadResponse(response))
+      .catch(() => this._bookmarksListDenied())
+      .finally(() => this.set("loadingMore", false));
   },
 
-  actions: {
-    removeBookmark(bookmark) {
-      bootbox.confirm(I18n.t("bookmarks.confirm_delete"), result => {
-        if (result) {
-          return bookmark.destroy().then(() => this.loadItems());
-        }
-      });
-    },
+  _bookmarksListDenied() {
+    this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
+  },
 
-    editBookmark(bookmark) {
-      let controller = showModal("bookmark", {
-        model: {
-          postId: bookmark.post_id,
-          id: bookmark.id,
-          reminderAt: bookmark.reminder_at,
-          name: bookmark.name
-        },
-        title: "post.bookmarks.edit",
-        modalClass: "bookmark-with-reminder"
-      });
-      controller.setProperties({
-        afterSave: () => this.loadItems()
-      });
-    },
+  _processLoadResponse(response) {
+    if (!response) {
+      this._bookmarksListDenied();
+      return;
+    }
 
-    loadMore() {
-      if (this.loadingMore) {
-        return Promise.resolve();
-      }
-      this.set("loadingMore", true);
+    if (response.no_results_help) {
+      this.set("noResultsHelp", response.no_results_help);
+      return;
+    }
 
-      return this.model
-        .loadMore()
-        .then(response => this.processLoadResponse(response))
-        .catch(() => {
-          this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
-        })
-        .finally(() =>
-          this.setProperties({
-            loadingMore: false
-          })
-        );
+    response = response.user_bookmark_list;
+    this.model.more_bookmarks_url = response.more_bookmarks_url;
+
+    if (response.bookmarks) {
+      this.content.pushObjects(
+        response.bookmarks.map(bookmark => Bookmark.create(bookmark))
+      );
     }
   }
 });
diff --git a/test/javascripts/acceptance/user-bookmarks-test.js b/test/javascripts/acceptance/user-bookmarks-test.js
new file mode 100644
index 0000000..e965510
--- /dev/null
+++ b/test/javascripts/acceptance/user-bookmarks-test.js
@@ -0,0 +1,50 @@
+import { acceptance } from "helpers/qunit-helpers";
+import selectKit from "helpers/select-kit-helper";
+import pretender from "helpers/create-pretender";
+
+acceptance("User's bookmarks", {
+  loggedIn: true,
+
+  beforeEach() {
+    pretender.delete("/bookmarks/576", () => [
+      200,
+      { "Content-Type": "application/json" },
+      {}
+    ]);
+  }
+});
+
+test("listing user bookmarks", async assert => {
+  await visit("/u/eviltrout/activity/bookmarks-with-reminders");
+
+  assert.ok(find(".bookmark-list-item").length);
+});
+
+test("removing a bookmark", async assert => {
+  await visit("/u/eviltrout/activity/bookmarks-with-reminders");
+
+  const dropdown = selectKit(".bookmark-actions-dropdown");
+  await dropdown.expand();
+  await dropdown.selectRowByValue("remove");
+
+  assert.ok(exists(".bootbox.modal"));
+
+  await click(".bootbox.modal .btn-primary");
+});
+
+test("listing users bookmarks - no bookmarks", async assert => {
+  pretender.get("/u/eviltrout/bookmarks.json", () => [
+    200,
+    {
+      "Content-Type": "application/json"
+    },
+    {
+      bookmarks: [],
+      no_results_help: "no bookmarks"
+    }
+  ]);
+
+  await visit("/u/eviltrout/activity/bookmarks-with-reminders");
+
+  assert.equal(find(".alert.alert-info").text(), "no bookmarks");
+});

GitHub sha: ad978b93

This commit appears in #9548 which was merged by martin.