mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 14:53:39 +08:00
FIX: Correctly display /admin/emails
errors (#17321)
Also removed unused codepath in `admin-badges-show`.
This commit is contained in:
parent
c5f0aa2f32
commit
a0a7b3f9c4
|
@ -43,10 +43,10 @@ export default Controller.extend({
|
||||||
this.set("sentTestEmailMessage", response.sent_test_email_message)
|
this.set("sentTestEmailMessage", response.sent_test_email_message)
|
||||||
)
|
)
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (e.responseJSON && e.responseJSON.errors) {
|
if (e.jqXHR.responseJSON?.errors) {
|
||||||
bootbox.alert(
|
bootbox.alert(
|
||||||
I18n.t("admin.email.error", {
|
I18n.t("admin.email.error", {
|
||||||
server_error: e.responseJSON.errors[0],
|
server_error: e.jqXHR.responseJSON.errors[0],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -33,16 +33,6 @@ export default Route.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
saveError(e) {
|
|
||||||
let msg = I18n.t("generic_error");
|
|
||||||
if (e.responseJSON && e.responseJSON.errors) {
|
|
||||||
msg = I18n.t("generic_error_with_reason", {
|
|
||||||
error: e.responseJSON.errors.join(". "),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
bootbox.alert(msg);
|
|
||||||
},
|
|
||||||
|
|
||||||
editGroupings() {
|
editGroupings() {
|
||||||
const model = this.controllerFor("admin-badges").get("badgeGroupings");
|
const model = this.controllerFor("admin-badges").get("badgeGroupings");
|
||||||
showModal("admin-edit-badge-groupings", { model, admin: true });
|
showModal("admin-edit-badge-groupings", { model, admin: true });
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { click, fillIn, visit } from "@ember/test-helpers";
|
import { click, fillIn, visit } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
|
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||||
|
|
||||||
const EMAIL = `
|
const EMAIL = `
|
||||||
From: "somebody" <somebody@example.com>
|
From: "somebody" <somebody@example.com>
|
||||||
|
@ -17,25 +18,40 @@ This part should be elided.`;
|
||||||
|
|
||||||
acceptance("Admin - Emails", function (needs) {
|
acceptance("Admin - Emails", function (needs) {
|
||||||
needs.user();
|
needs.user();
|
||||||
needs.pretender((server, helper) => {
|
test("shows selected and elided text", async function (assert) {
|
||||||
server.post("/admin/email/advanced-test", () => {
|
pretender.post("/admin/email/advanced-test", () => {
|
||||||
return helper.response({
|
return response({
|
||||||
format: 1,
|
format: 1,
|
||||||
text: "Hello, this is a test!",
|
text: "Hello, this is a test!",
|
||||||
elided: "---\n\nThis part should be elided.",
|
elided: "---\n\nThis part should be elided.",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test("shows selected and elided text", async function (assert) {
|
|
||||||
await visit("/admin/email/advanced-test");
|
await visit("/admin/email/advanced-test");
|
||||||
await fillIn("textarea.email-body", EMAIL.trim());
|
await fillIn("textarea.email-body", EMAIL.trim());
|
||||||
await click(".email-advanced-test button");
|
await click(".email-advanced-test button");
|
||||||
|
|
||||||
assert.strictEqual(queryAll(".text pre").text(), "Hello, this is a test!");
|
assert.strictEqual(query(".text pre").innerText, "Hello, this is a test!");
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
queryAll(".elided pre").text(),
|
query(".elided pre").innerText,
|
||||||
"---\n\nThis part should be elided."
|
"---\n\nThis part should be elided."
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("displays received errors when testing emails", async function (assert) {
|
||||||
|
pretender.get("/admin/email.json", () => {
|
||||||
|
return response({});
|
||||||
|
});
|
||||||
|
|
||||||
|
pretender.post("/admin/email/test", () => {
|
||||||
|
return response(422, { errors: ["some error"] });
|
||||||
|
});
|
||||||
|
|
||||||
|
await visit("/admin/email");
|
||||||
|
await fillIn(".admin-controls input", "test@example.com");
|
||||||
|
await click(".btn-primary");
|
||||||
|
|
||||||
|
assert.ok(query(".bootbox.modal").innerText.includes("some error"));
|
||||||
|
await click(".bootbox .btn-primary");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user