Skip to content

A platform for community discussion. Free, open, simple.

FIX: hide solved answer prompt when marking answer as solution (#37262)

David Battersby574028bff8e1
diff --git a/plugins/discourse-solved/assets/javascripts/discourse/connectors/topic-navigation/no-answer.gjs b/plugins/discourse-solved/assets/javascripts/discourse/connectors/topic-navigation/no-answer.gjs
index 0c316ca8906..bd8dffcddf7 100644
--- a/plugins/discourse-solved/assets/javascripts/discourse/connectors/topic-navigation/no-answer.gjs
+++ b/plugins/discourse-solved/assets/javascripts/discourse/connectors/topic-navigation/no-answer.gjs
@@ -24,6 +24,13 @@ export default class NoAnswer extends Component {
oneWeek: ONE_WEEK,
show: false,
});
+
+ this.appEvents.on(
+ "discourse-solved:solution-toggled",
+ this,
+ this.hidePopup
+ );
+
later(() => {
if (!this.element || this.isDestroying || this.isDestroyed) {
return;
@@ -50,6 +57,20 @@ export default class NoAnswer extends Component {
}, DISPLAY_DELAY);
}
+ willDestroyElement() {
+ super.willDestroyElement(...arguments);
+
+ this.appEvents.off(
+ "discourse-solved:solution-toggled",
+ this,
+ this.hidePopup
+ );
+ }
+
+ hidePopup() {
+ this.set("show", false);
+ }
+
<template>
{{#if this.show}}
<TopicNavigationPopup
diff --git a/plugins/discourse-solved/test/javascripts/acceptance/no-answer-prompt-test.js b/plugins/discourse-solved/test/javascripts/acceptance/no-answer-prompt-test.js
new file mode 100644
index 00000000000..9c8ce573028
--- /dev/null
+++ b/plugins/discourse-solved/test/javascripts/acceptance/no-answer-prompt-test.js
@@ -0,0 +1,38 @@
+import { click, visit } from "@ember/test-helpers";
+import { test } from "qunit";
+import pretender, { response } from "discourse/tests/helpers/create-pretender";
+import { acceptance } from "discourse/tests/helpers/qunit-helpers";
+import { topicWithNoAnswer } from "../helpers/discourse-solved-helpers";
+
+acceptance("Discourse Solved - No Answer Prompt", function (needs) {
+ needs.user({ id: 1 });
+ needs.settings({
+ solved_enabled: true,
+ allow_solved_on_all_topics: true,
+ });
+
+ test("hides the no answer prompt when clicking the solution button", async function (assert) {
+ pretender.get("/t/100.json", () => response(topicWithNoAnswer(1)));
+
+ pretender.post("/solution/accept", () =>
+ response({
+ success: "OK",
+ post_number: 2,
+ username: "helper",
+ excerpt: "<p>Here is a potential answer</p>",
+ })
+ );
+
+ await visit("/t/test-topic-no-answer/100");
+
+ assert
+ .dom(".topic-navigation-popup")
+ .exists("no answer prompt is displayed");
+
+ await click(".post-action-menu__solved-unaccepted");
+
+ assert
+ .dom(".topic-navigation-popup")
+ .doesNotExist("no answer prompt is hidden after accepting solution");
+ });
+});
diff --git a/plugins/discourse-solved/test/javascripts/helpers/discourse-solved-helpers.js b/plugins/discourse-solved/test/javascripts/helpers/discourse-solved-helpers.js
index f1bce61c085..739ec4f032f 100644
--- a/plugins/discourse-solved/test/javascripts/helpers/discourse-solved-helpers.js
+++ b/plugins/discourse-solved/test/javascripts/helpers/discourse-solved-helpers.js
@@ -205,3 +205,65 @@ export const postStreamWithAcceptedAnswerExcerpt = (excerpt) => ({
accepter_name: "Tomtom",
},
});
+
+export function topicWithNoAnswer(currentUserId) {
+ const twoWeeksAgo = new Date(Date.now() - 14 * 24 * 60 * 60 * 1000);
+
+ return {
+ post_stream: {
+ posts: [
+ {
+ id: 1,
+ username: "topic_creator",
+ cooked: "<p>This is my question</p>",
+ post_number: 1,
+ post_type: 1,
+ topic_id: 100,
+ user_id: currentUserId,
+ can_accept_answer: false,
+ accepted_answer: false,
+ },
+ {
+ id: 2,
+ username: "helper",
+ cooked: "<p>Here is a potential answer</p>",
+ post_number: 2,
+ post_type: 1,
+ topic_id: 100,
+ user_id: 999,
+ can_accept_answer: true,
+ accepted_answer: false,
+ },
+ ],
+ stream: [1, 2],
+ },
+ id: 100,
+ title: "Test topic with no answer",
+ fancy_title: "Test topic with no answer",
+ slug: "test-topic-no-answer",
+ posts_count: 2,
+ created_at: twoWeeksAgo.toISOString(),
+ views: 10,
+ reply_count: 1,
+ like_count: 0,
+ visible: true,
+ closed: false,
+ archived: false,
+ archetype: "regular",
+ category_id: 1,
+ user_id: currentUserId,
+ draft: null,
+ draft_key: "topic_100",
+ draft_sequence: 0,
+ accepted_answer: null,
+ details: {
+ created_by: {
+ id: currentUserId,
+ username: "topic_creator",
+ },
+ can_create_post: true,
+ },
+ highest_post_number: 2,
+ chunk_size: 20,
+ };
+}