diff --git a/app/assets/javascripts/discourse/app/routes/build-admin-user-posts-route.js b/app/assets/javascripts/discourse/app/routes/build-admin-user-posts-route.js deleted file mode 100644 index fbbc3fd6f48..00000000000 --- a/app/assets/javascripts/discourse/app/routes/build-admin-user-posts-route.js +++ /dev/null @@ -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; - }, - }); -} diff --git a/app/assets/javascripts/discourse/app/routes/user-deleted-posts.js b/app/assets/javascripts/discourse/app/routes/user-deleted-posts.js index 75b35d804ff..e5a9e658997 100644 --- a/app/assets/javascripts/discourse/app/routes/user-deleted-posts.js +++ b/app/assets/javascripts/discourse/app/routes/user-deleted-posts.js @@ -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; + } +} diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-deleted-posts-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-deleted-posts-test.js new file mode 100644 index 00000000000..2b589360ff3 --- /dev/null +++ b/app/assets/javascripts/discourse/tests/acceptance/user-deleted-posts-test.js @@ -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"); + }); +});