FIX: `u/:username/deleted-posts` route regression (#21834)

Regressed in 48987af
This commit is contained in:
Jarek Radosz 2023-05-30 23:40:44 +02:00 committed by GitHub
parent a187411611
commit 1e3a5124da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 39 deletions

View File

@ -1,37 +0,0 @@
import DiscourseRoute from "discourse/routes/discourse";
import { emojiUnescape } from "discourse/lib/text";
import { escapeExpression } from "discourse/lib/utilities";
import { action } from "@ember/object";
export default function (filter) {
return DiscourseRoute.extend({
templateName: "user/posts",
model() {
return this.modelFor("user").get("postsStream");
},
afterModel(model) {
return model.filterBy({ filter });
},
setupController(controller, model) {
// initialize "canLoadMore"
model.set("canLoadMore", model.get("itemsLoaded") === 60);
model.get("content").forEach((item) => {
if (item.get("title")) {
item.set("title", emojiUnescape(escapeExpression(item.title)));
}
});
this.controllerFor("user-posts").set("model", model);
},
@action
didTransition() {
this.controllerFor("user-posts")._showFooter();
return true;
},
});
}

View File

@ -1,3 +1,35 @@
import createAdminUserPostsRoute from "discourse/routes/build-admin-user-posts-route";
import DiscourseRoute from "discourse/routes/discourse";
import { emojiUnescape } from "discourse/lib/text";
import { escapeExpression } from "discourse/lib/utilities";
import { action } from "@ember/object";
export default createAdminUserPostsRoute("deleted");
export default class UserDeletedPosts extends DiscourseRoute {
templateName = "user/posts";
controllerName = "user-posts";
model() {
return this.modelFor("user").postsStream;
}
afterModel(model) {
return model.filterBy({ filter: "deleted" });
}
setupController(controller, model) {
super.setupController(...arguments);
model.set("canLoadMore", model.itemsLoaded === 60);
model.content.forEach((item) => {
if (item.title) {
item.set("title", emojiUnescape(escapeExpression(item.title)));
}
});
}
@action
didTransition() {
this.controller._showFooter();
return true;
}
}

View File

@ -0,0 +1,29 @@
import { acceptance } from "../helpers/qunit-helpers";
import { test } from "qunit";
import postFixtures from "discourse/tests/fixtures/post";
import { cloneJSON } from "discourse-common/lib/object";
import { visit } from "@ember/test-helpers";
acceptance("User's deleted posts page", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.get(`/posts/eviltrout/deleted`, () => {
const post1 = cloneJSON(postFixtures["/posts/398"]);
post1.excerpt = "Topic #1";
const post2 = cloneJSON(postFixtures["/posts/98737532"]);
post2.excerpt = "Another topic's text";
return helper.response([post1, post2]);
});
});
test("Displays the posts", async function (assert) {
await visit(`/u/eviltrout/deleted-posts`);
assert.dom(".user-stream-item [data-topic-id='280']").hasText("Topic #1");
assert
.dom(".user-stream-item [data-topic-id='34']")
.hasText("Another topic's text");
});
});