FIX: `expandAllPinned` was not resetting after visiting a category

FIX: expandAllPinned was not resetting after visiting a category

This resulted in a bug where if you saw a pinned topic in a category, then went back to latest, the same topic would show an excerpt even though it shouldn’t on the latest view.

See: Pinned post excerpt no longer appears after refreshing the page - ux - Discourse Meta

diff --git a/.eslintrc b/.eslintrc
index 148fa3b..0f2d2c8 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -62,6 +62,7 @@
     "triggerEvent": true,
     "visible": true,
     "visit": true,
+    "pauseTest": true
   },
   "rules": {
     "block-scoped-var": 2,
diff --git a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6
index 4bfb0ff..72db374 100644
--- a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6
+++ b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6
@@ -113,6 +113,7 @@ export default function(filter, extras) {
             model.get("for_period") ||
             (filter.indexOf("top/") >= 0 ? filter.split("/")[1] : ""),
           selected: [],
+          expandAllPinned: false,
           expandGloballyPinned: true
         };
 
diff --git a/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs b/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs
index 095518f..5b45e1b 100644
--- a/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs
+++ b/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs
@@ -68,4 +68,4 @@
 
 <td class="num views {{topic.viewsHeat}}">{{number topic.views numberKey="views_long"}}</td>
 
-{{raw "list/activity-column" topic=topic class="num" tagName="td"}}
\ No newline at end of file
+{{raw "list/activity-column" topic=topic class="num" tagName="td"}}
diff --git a/test/javascripts/acceptance/topic-discovery-test.js.es6 b/test/javascripts/acceptance/topic-discovery-test.js.es6
index 54e578b..e060c94 100644
--- a/test/javascripts/acceptance/topic-discovery-test.js.es6
+++ b/test/javascripts/acceptance/topic-discovery-test.js.es6
@@ -1,5 +1,9 @@
 import { acceptance } from "helpers/qunit-helpers";
-acceptance("Topic Discovery");
+acceptance("Topic Discovery", {
+  settings: {
+    show_pinned_excerpt_desktop: true
+  }
+});
 
 QUnit.test("Visit Discovery Pages", async assert => {
   await visit("/");
@@ -59,3 +63,16 @@ QUnit.test("Visit Discovery Pages", async assert => {
     "The featured topics are there too"
   );
 });
+
+QUnit.test("Clearing state after leaving a category", async assert => {
+  await visit("/c/dev");
+  assert.ok(
+    exists(".topic-list-item[data-topic-id=11994] .topic-excerpt"),
+    "it expands pinned topics in a subcategory"
+  );
+  await visit("/");
+  assert.ok(
+    !exists(".topic-list-item[data-topic-id=11557] .topic-excerpt"),
+    "it doesn't expand all pinned in the latest category"
+  );
+});
diff --git a/test/javascripts/fixtures/discovery_fixtures.js.es6 b/test/javascripts/fixtures/discovery_fixtures.js.es6
index 378a8b7..1de2598 100644
--- a/test/javascripts/fixtures/discovery_fixtures.js.es6
+++ b/test/javascripts/fixtures/discovery_fixtures.js.es6
@@ -4962,7 +4962,8 @@ export default {
           bumped: true,
           bumped_at: "2014-01-16T11:04:32.000-05:00",
           unseen: false,
-          pinned: false,
+          pinned: true,
+          excerpt: "Hello world",
           visible: true,
           closed: false,
           archived: false,

GitHub sha: f75915ef

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: