FIX: Incorrect title and chevron when filtering by post number. (#14985)

The widget's state did not reflect the state of the controller.
This commit is contained in:
Alan Guo Xiang Tan
2021-11-18 09:19:00 +08:00
committed by GitHub
parent eb82849ccb
commit db24c9b94e
2 changed files with 39 additions and 2 deletions

View File

@@ -388,8 +388,20 @@ createWidget("post-group-request", {
createWidget("post-contents", {
buildKey: (attrs) => `post-contents-${attrs.id}`,
defaultState() {
return { expandedFirstPost: false, repliesBelow: [] };
defaultState(attrs) {
const defaultState = {
expandedFirstPost: false,
repliesBelow: [],
};
if (this.siteSettings.enable_filtered_replies_view) {
const topicController = this.register.lookup("controller:topic");
defaultState.filteredRepliesShown =
topicController.replies_to_post_number === attrs.post_number.toString();
}
return defaultState;
},
buildClasses(attrs) {

View File

@@ -546,3 +546,28 @@ acceptance("Topic last visit line", function (needs) {
);
});
});
acceptance("Topic filter replies to post number", function (needs) {
needs.settings({
enable_filtered_replies_view: true,
});
test("visit topic", async function (assert) {
await visit("/t/-/280");
assert.equal(
query("#post_3 .show-replies").title,
I18n.t("post.filtered_replies_hint", { count: 3 }),
"it displays the right title for filtering by replies"
);
await visit("/");
await visit("/t/-/280?replies_to_post_number=3");
assert.equal(
query("#post_3 .show-replies").title,
I18n.t("post.view_all_posts"),
"it displays the right title when filtered by replies"
);
});
});