From 82ebc706aaee2dfeee83553fe6bcf7bf1fe9177e Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Wed, 16 Jun 2021 18:42:21 +0400 Subject: [PATCH] =?UTF-8?q?FIX:=20The=20topic=20level=20bookmark=20button?= =?UTF-8?q?=20stops=20working=20if=20choose=20=E2=80=98No=E2=80=99=20on=20?= =?UTF-8?q?the=20clearing=20all=20bookmarks=20confirmation=20modal=20(#133?= =?UTF-8?q?74)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create bookmarks for several posts on a topic - Click the topic level bookmark button, it’ll open the modal that asks to confirm clearing all bookmarks from the topic - Choose No - Try to push the topic level bookmark button again - it won’t work And it's fixed with this commit --- .../discourse/app/controllers/topic.js | 10 +++- .../tests/acceptance/bookmarks-test.js | 59 ++++++++++++++++++- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.js index c3e4060c9b..f9b2b93560 100644 --- a/app/assets/javascripts/discourse/app/controllers/topic.js +++ b/app/assets/javascripts/discourse/app/controllers/topic.js @@ -1274,8 +1274,14 @@ export default Controller.extend(bufferedProperty("model"), { I18n.t("bookmarks.confirm_clear"), I18n.t("no_value"), I18n.t("yes_value"), - (confirmed) => - confirmed ? toggleBookmarkOnServer().then(resolve) : resolve() + (confirmed) => { + if (confirmed) { + toggleBookmarkOnServer().then(resolve); + } else { + this.model.set("bookmarking", false); + resolve(); + } + } ); } else { toggleBookmarkOnServer().then(resolve); diff --git a/app/assets/javascripts/discourse/tests/acceptance/bookmarks-test.js b/app/assets/javascripts/discourse/tests/acceptance/bookmarks-test.js index bab0ff7613..f2e0dfce50 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/bookmarks-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/bookmarks-test.js @@ -52,11 +52,18 @@ acceptance("Bookmarking", function (needs) { function handleRequest(request) { const data = helper.parsePostData(request.requestBody); steps.push(data.reminder_type || "none"); - return helper.response({ id: 999, success: "OK" }); + + if (data.post_id === "398") { + return helper.response({ id: 1, success: "OK" }); + } else if (data.post_id === "419") { + return helper.response({ id: 2, success: "OK" }); + } else { + throw new Error("Pretender: unknown post_id"); + } } server.post("/bookmarks", handleRequest); - server.put("/bookmarks/999", handleRequest); - server.delete("/bookmarks/999", () => + server.put("/bookmarks/1", handleRequest); + server.delete("/bookmarks/1", () => helper.response({ success: "OK", topic_bookmarked: false }) ); server.get("/t/280.json", () => helper.response(topicResponse)); @@ -262,4 +269,50 @@ acceptance("Bookmarking", function (needs) { "it does not show the local date tile" ); }); + + test("The topic level bookmark button deletes all bookmarks if several posts on the topic are bookmarked", async function (assert) { + const yesButton = "a.btn-primary"; + const noButton = "a.btn-default"; + + await visit("/t/internationalization-localization/280"); + await openBookmarkModal(1); + await click("#save-bookmark"); + await openBookmarkModal(2); + await click("#save-bookmark"); + + assert.ok( + exists(".topic-post:first-child button.bookmark.bookmarked"), + "the first bookmark is added" + ); + assert.ok( + exists(".topic-post:nth-child(3) button.bookmark.bookmarked"), + "the second bookmark is added" + ); + + // open the modal and cancel deleting + await click("#topic-footer-button-bookmark"); + await click(noButton); + + assert.ok( + exists(".topic-post:first-child button.bookmark.bookmarked"), + "the first bookmark isn't deleted" + ); + assert.ok( + exists(".topic-post:nth-child(3) button.bookmark.bookmarked"), + "the second bookmark isn't deleted" + ); + + // open the modal and accept deleting + await click("#topic-footer-button-bookmark"); + await click(yesButton); + + assert.ok( + !exists(".topic-post:first-child button.bookmark.bookmarked"), + "the first bookmark is deleted" + ); + assert.ok( + !exists(".topic-post:nth-child(3) button.bookmark.bookmarked"), + "the second bookmark is deleted" + ); + }); });