2021-06-14 06:36:55 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
require "rails_helper"
|
|
|
|
require "composer_messages_finder"
|
2021-06-14 06:36:55 -04:00
|
|
|
|
|
|
|
describe ComposerMessagesFinder do
|
2022-12-23 15:36:08 -05:00
|
|
|
describe ".check_topic_is_solved" do
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
2021-06-14 06:36:55 -04:00
|
|
|
fab!(:topic) { Fabricate(:topic) }
|
|
|
|
fab!(:post) { Fabricate(:post, topic: topic, user: Fabricate(:user)) }
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
before { SiteSetting.disable_solved_education_message = false }
|
2021-06-14 06:36:55 -04:00
|
|
|
|
|
|
|
it "does not show message without a topic id" do
|
2022-12-23 15:36:08 -05:00
|
|
|
expect(
|
|
|
|
described_class.new(user, composer_action: "createTopic").check_topic_is_solved,
|
|
|
|
).to be_blank
|
|
|
|
expect(described_class.new(user, composer_action: "reply").check_topic_is_solved).to be_blank
|
2021-06-14 06:36:55 -04:00
|
|
|
end
|
|
|
|
|
2022-10-03 16:21:31 -04:00
|
|
|
describe "a reply" do
|
2021-06-14 06:36:55 -04:00
|
|
|
it "does not show message if topic is not solved" do
|
2022-12-23 15:36:08 -05:00
|
|
|
expect(
|
|
|
|
described_class.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
).check_topic_is_solved,
|
|
|
|
).to be_blank
|
2021-06-14 06:36:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not show message if disable_solved_education_message is true" do
|
|
|
|
SiteSetting.disable_solved_education_message = true
|
|
|
|
DiscourseSolved.accept_answer!(post, Discourse.system_user)
|
2022-12-23 15:36:08 -05:00
|
|
|
expect(
|
|
|
|
described_class.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
).check_topic_is_solved,
|
|
|
|
).to be_blank
|
2021-06-14 06:36:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "shows message if the topic is solved" do
|
|
|
|
DiscourseSolved.accept_answer!(post, Discourse.system_user)
|
2022-12-23 15:36:08 -05:00
|
|
|
message =
|
|
|
|
described_class.new(
|
|
|
|
user,
|
|
|
|
composer_action: "reply",
|
|
|
|
topic_id: topic.id,
|
|
|
|
).check_topic_is_solved
|
2021-06-14 06:36:55 -04:00
|
|
|
expect(message).not_to be_blank
|
|
|
|
expect(message[:body]).to include("This topic has been solved")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|