FIX: shows errors when converting to public is impossible (#27103)
Follow up to e04ac5e2d8
which missed showing the error messages in the "convert to public" modal 🤦♂️
This commit is contained in:
parent
40d65dddf8
commit
fe12cfeab2
|
@ -2,7 +2,7 @@ import Component from "@glimmer/component";
|
|||
import { tracked } from "@glimmer/tracking";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import I18n from "discourse-i18n";
|
||||
import { extractError } from "discourse/lib/ajax-error";
|
||||
|
||||
export default class ConvertToPublicTopic extends Component {
|
||||
@service appEvents;
|
||||
|
@ -13,18 +13,18 @@ export default class ConvertToPublicTopic extends Component {
|
|||
|
||||
@action
|
||||
async makePublic() {
|
||||
const { topic } = this.args.model;
|
||||
|
||||
try {
|
||||
this.saving = true;
|
||||
await this.args.model.topic.convertTopic("public", {
|
||||
categoryId: this.publicCategoryId,
|
||||
});
|
||||
this.args.model.topic.set("archetype", "regular");
|
||||
this.args.model.topic.set("category_id", this.publicCategoryId);
|
||||
this.appEvents.trigger("header:show-topic", this.args.model.topic);
|
||||
this.saving = false;
|
||||
await topic.convertTopic("public", { categoryId: this.publicCategoryId });
|
||||
topic.set("archetype", "regular");
|
||||
topic.set("category_id", this.publicCategoryId);
|
||||
this.appEvents.trigger("header:show-topic", topic);
|
||||
this.args.closeModal();
|
||||
} catch (e) {
|
||||
this.flash = I18n.t("generic_error");
|
||||
this.flash = extractError(e);
|
||||
} finally {
|
||||
this.saving = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,6 +228,18 @@ module PageObjects
|
|||
post_by_number(post).has_css?(".read-state.read", visible: :all, wait: 3)
|
||||
end
|
||||
|
||||
def move_to_public_category(category)
|
||||
click_admin_menu_button
|
||||
find(".topic-admin-menu-content li.topic-admin-convert").click
|
||||
move_to_public_modal.find(".category-chooser").click
|
||||
find(".category-row[data-value=\"#{category.id}\"]").click
|
||||
move_to_public_modal.find(".btn-primary").click
|
||||
end
|
||||
|
||||
def move_to_public_modal
|
||||
find(".modal.convert-to-public-topic")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def within_post(post)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe "Topic Admin Menu", type: :system do
|
||||
fab!(:admin)
|
||||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||
|
||||
before { sign_in(admin) }
|
||||
|
||||
context "for a PM" do
|
||||
fab!(:pm) { Fabricate(:private_message_topic, title: "Can you help me with this?") }
|
||||
fab!(:op) { Fabricate(:post, topic: pm, user: admin, created_at: 1.day.ago) }
|
||||
fab!(:category)
|
||||
|
||||
it "shows the errors when converting to a public topic is not possible" do
|
||||
# create a topic with the same title to force a "duplicate title" error
|
||||
Fabricate(:topic, title: pm.title, category: category)
|
||||
|
||||
topic_page.visit_topic(pm)
|
||||
topic_page.move_to_public_category(category)
|
||||
expect(topic_page.move_to_public_modal).to have_css("#modal-alert")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue