From 69e55a0e1ce93808a30c68cc034cff0be1158a9c Mon Sep 17 00:00:00 2001 From: Kris Date: Tue, 22 Nov 2022 08:36:43 -0500 Subject: [PATCH] A11Y: Improve "my posts" sidebar link title (#19132) --- .../my-posts-section-link.js | 6 +++++- .../sidebar-user-community-section-test.js | 20 +++++++++++++++++++ config/locales/client.en.yml | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js b/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js index 01544b54d9d..82fceb4bd0e 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/user/community-section/my-posts-section-link.js @@ -47,7 +47,11 @@ export default class MyPostsSectionLink extends BaseSectionLink { } get title() { - return I18n.t("sidebar.sections.community.links.my_posts.title"); + if (this._hasDraft) { + return I18n.t("sidebar.sections.community.links.my_posts.title_drafts"); + } else { + return I18n.t("sidebar.sections.community.links.my_posts.title"); + } } get text() { diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js index 0b2ca1c1da3..47c505d2f37 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-user-community-section-test.js @@ -564,6 +564,26 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) { ); }); + test("my posts title changes when drafts are present", async function (assert) { + await visit("/"); + + assert.strictEqual( + query(".sidebar-section-link-my-posts").title, + I18n.t("sidebar.sections.community.links.my_posts.title"), + "displays the default title when no drafts are present" + ); + + await publishToMessageBus(`/user-drafts/${loggedInUser().id}`, { + draft_count: 1, + }); + + assert.strictEqual( + query(".sidebar-section-link-my-posts").title, + I18n.t("sidebar.sections.community.links.my_posts.title_drafts"), + "displays the draft title when drafts are present" + ); + }); + test("visiting top route", async function (assert) { await visit("/top"); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index a04315378a9..d23ec802ea3 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -4248,7 +4248,8 @@ en: title: "All users" my_posts: content: "My Posts" - title: "My posts" + title: "My recent topic activity" + title_drafts: "My unposted drafts" draft_count: one: "%{count} draft" other: "%{count} drafts"