From bb342bafe9a9d41f912c49e2eeda3edb66c60b11 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Tue, 10 Oct 2023 11:49:48 +1100 Subject: [PATCH] FIX: display error when moving post fails (#23860) This fix ensures that an error modal is displayed when a post is moved to a new topic that has an invalid title. --- .../app/components/modal/move-to-topic.hbs | 2 ++ .../app/components/modal/move-to-topic.js | 1 + .../tests/acceptance/topic-move-posts-test.js | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/app/assets/javascripts/discourse/app/components/modal/move-to-topic.hbs b/app/assets/javascripts/discourse/app/components/modal/move-to-topic.hbs index b08bc15fb22..1c37295002d 100644 --- a/app/assets/javascripts/discourse/app/components/modal/move-to-topic.hbs +++ b/app/assets/javascripts/discourse/app/components/modal/move-to-topic.hbs @@ -3,6 +3,8 @@ @title={{i18n "topic.move_to.title"}} @closeModal={{@closeModal}} class="choose-topic-modal" + @flash={{this.flash}} + @flashType="error" > <:body> {{#if @model.topic.isPrivateMessage}} diff --git a/app/assets/javascripts/discourse/app/components/modal/move-to-topic.js b/app/assets/javascripts/discourse/app/components/modal/move-to-topic.js index 84c17e03d01..955b064b708 100644 --- a/app/assets/javascripts/discourse/app/components/modal/move-to-topic.js +++ b/app/assets/javascripts/discourse/app/components/modal/move-to-topic.js @@ -19,6 +19,7 @@ export default class MoveToTopic extends Component { @tracked chronologicalOrder = false; @tracked selection = "new_topic"; @tracked selectedTopicId; + @tracked flash; constructor() { super(...arguments); diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-move-posts-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-move-posts-test.js index 5ee88179af7..eac343763ab 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/topic-move-posts-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/topic-move-posts-test.js @@ -9,6 +9,13 @@ import { test } from "qunit"; acceptance("Topic move posts", function (needs) { needs.user(); + needs.pretender((server, helper) => { + server.post("/t/280/move-posts", () => { + return helper.response(404, { + errors: ["Invalid title"], + }); + }); + }); test("default", async function (assert) { await visit("/t/internationalization-localization"); @@ -53,6 +60,20 @@ acceptance("Topic move posts", function (needs) { ); }); + test("display error when new topic has invalid title", async function (assert) { + await visit("/t/internationalization-localization"); + await click(".toggle-admin-menu"); + await click(".topic-admin-multi-select .btn"); + await click("#post_11 .select-below"); + await click(".selected-posts .move-to-topic"); + await fillIn(".choose-topic-modal #split-topic-name", "Existing topic"); + await click(".choose-topic-modal .modal-footer .btn-primary"); + assert.strictEqual( + query("#modal-alert").innerText.trim(), + I18n.t("topic.move_to.error") + ); + }); + test("moving all posts", async function (assert) { await visit("/t/internationalization-localization"); await click(".toggle-admin-menu");