DEV: Better control what prompts can appear in post/composer
This PR updates the logic for the location map so it permits only the desired prompts through to the composer/post menu. Anything else won't be shown by default. This PR also adds relevant tests to prevent regression.
This commit is contained in:
parent
dabef02919
commit
d67dacc3ae
|
@ -233,10 +233,8 @@ module DiscourseAi
|
||||||
%w[post]
|
%w[post]
|
||||||
when "illustrate_post"
|
when "illustrate_post"
|
||||||
%w[composer]
|
%w[composer]
|
||||||
when "detect_text_locale"
|
|
||||||
%w[]
|
|
||||||
else
|
else
|
||||||
%w[composer post]
|
%w[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,31 @@ RSpec.describe DiscourseAi::AiHelper::Assistant do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns all prompts to be shown in the composer" do
|
||||||
|
prompts = subject.available_prompts(user)
|
||||||
|
filtered_prompts = prompts.select { |prompt| prompt[:location].include?("composer") }
|
||||||
|
expect(filtered_prompts.length).to eq(5)
|
||||||
|
expect(filtered_prompts.map { |p| p[:name] }).to contain_exactly(
|
||||||
|
"translate",
|
||||||
|
"generate_titles",
|
||||||
|
"proofread",
|
||||||
|
"markdown_table",
|
||||||
|
"custom_prompt",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns all prompts to be shown in the post menu" do
|
||||||
|
prompts = subject.available_prompts(user)
|
||||||
|
filtered_prompts = prompts.select { |prompt| prompt[:location].include?("post") }
|
||||||
|
expect(filtered_prompts.length).to eq(4)
|
||||||
|
expect(filtered_prompts.map { |p| p[:name] }).to contain_exactly(
|
||||||
|
"translate",
|
||||||
|
"explain",
|
||||||
|
"proofread",
|
||||||
|
"custom_prompt",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
it "does not raise an error when effective_locale does not exactly match keys in LocaleSiteSetting" do
|
it "does not raise an error when effective_locale does not exactly match keys in LocaleSiteSetting" do
|
||||||
SiteSetting.default_locale = "zh_CN"
|
SiteSetting.default_locale = "zh_CN"
|
||||||
expect { subject.available_prompts(user) }.not_to raise_error
|
expect { subject.available_prompts(user) }.not_to raise_error
|
||||||
|
|
Loading…
Reference in New Issue