FIX: Correctly set categoryId on Composer model (#23934)

This commit is contained in:
Jarek Radosz 2023-10-19 19:19:40 +02:00 committed by GitHub
parent f42f54d58f
commit e31859a33a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 89 additions and 5 deletions

View File

@ -824,7 +824,10 @@ const Composer = RestModel.extend({
});
// We set the category id separately for topic templates on opening of composer
this.set("categoryId", opts.categoryId || this.get("topic.category.id"));
this.set(
"categoryId",
opts.topicCategoryId || opts.categoryId || this.get("topic.category.id")
);
if (!this.categoryId && this.creatingTopic) {
const categories = this.site.categories;

View File

@ -1455,10 +1455,6 @@ export default class ComposerService extends Service {
this.model.set("title", opts.topicTitle);
}
if (opts.topicCategoryId) {
this.model.set("categoryId", opts.topicCategoryId);
}
if (opts.topicTags && this.site.can_tag_topics) {
let tags = escapeExpression(opts.topicTags)
.split(",")

View File

@ -160,6 +160,77 @@ describe "Composer Form Templates", type: :system do
sign_in user
end
describe "discard draft modal" do
it "does not show the modal if there is no draft on a topic without a template" do
category_page.visit(category_no_template)
category_page.new_topic_button.click
composer.close
expect(composer).to be_closed
end
it "shows the modal if there is a draft on a topic without a template" do
category_page.visit(category_no_template)
category_page.new_topic_button.click
composer.fill_content("abc")
composer.close
expect(composer).to be_opened
expect(composer).to have_discard_draft_modal
end
it "does not show the modal if there is no draft on a topic with a topic template" do
category_page.visit(category_topic_template)
category_page.new_topic_button.click
composer.close
expect(composer).to be_closed
end
it "shows the modal if there is a draft on a topic with a topic template" do
category_page.visit(category_topic_template)
category_page.new_topic_button.click
composer.append_content(" some more content")
composer.close
expect(composer).to be_opened
expect(composer).to have_discard_draft_modal
end
it "does not show the modal if on a topic with a form template" do
category_page.visit(category_with_template_1)
category_page.new_topic_button.click
composer.close
expect(composer).to be_closed
end
context "when the default template has a topic template" do
SiteSetting.default_composer_category =
(
if SiteSetting.general_category_id != -1
SiteSetting.general_category_id
else
SiteSetting.uncategorized_category_id
end
)
let(:default_category) { Category.find(SiteSetting.default_composer_category) }
before { default_category.update!(topic_template: "Testing") }
it "does not show the modal if there is no draft" do
category_page.visit(default_category)
category_page.new_topic_button.click
composer.close
expect(composer).to be_closed
end
it "shows the modal if there is a draft" do
category_page.visit(default_category)
category_page.new_topic_button.click
composer.append_content(" some more content")
composer.close
expect(composer).to be_opened
expect(composer).to have_discard_draft_modal
end
end
end
it "shows a textarea when no form template is assigned to the category" do
category_page.visit(category_no_template)
category_page.new_topic_button.click

View File

@ -10,6 +10,10 @@ module PageObjects
page.has_css?("#{COMPOSER_ID}.open")
end
def closed?
page.has_css?("#{COMPOSER_ID}.closed", visible: :all)
end
def open_composer_actions
find(".composer-action-title .btn").click
self
@ -30,6 +34,12 @@ module PageObjects
self
end
def append_content(content)
current_content = composer_input.value
composer_input.set(current_content + content)
self
end
def fill_form_template_field(field, content)
form_template_field(field).fill_in(with: content)
self
@ -90,6 +100,10 @@ module PageObjects
find("#{COMPOSER_ID} .d-editor-preview-wrapper")
end
def has_discard_draft_modal?
page.has_css?(".discard-draft-modal")
end
def has_emoji_autocomplete?
has_css?(AUTOCOMPLETE_MENU)
end