REFACTOR: Improve the readability of code (#7076)

REFACTOR: Improve the readability of code (#7076)

diff --git a/app/assets/javascripts/discourse/controllers/preferences/account.js.es6 b/app/assets/javascripts/discourse/controllers/preferences/account.js.es6
index bab680c..b3c09ef 100644
--- a/app/assets/javascripts/discourse/controllers/preferences/account.js.es6
+++ b/app/assets/javascripts/discourse/controllers/preferences/account.js.es6
@@ -106,9 +106,15 @@ export default Ember.Controller.extend(
 
     @computed("showAllAuthTokens", "model.user_auth_tokens")
     authTokens(showAllAuthTokens, tokens) {
-      tokens.sort((a, b) =>
-        a.is_active ? -1 : b.is_active ? 1 : b.seen_at.localeCompare(a.seen_at)
-      );
+      tokens.sort((a, b) => {
+        if (a.is_active) {
+          return -1;
+        } else if (b.is_active) {
+          return 1;
+        } else {
+          return b.seen_at.localeCompare(a.seen_at);
+        }
+      });
 
       return showAllAuthTokens
         ? tokens
diff --git a/test/javascripts/acceptance/preferences-test.js.es6 b/test/javascripts/acceptance/preferences-test.js.es6
index ab16190..d5ab2f6 100644
--- a/test/javascripts/acceptance/preferences-test.js.es6
+++ b/test/javascripts/acceptance/preferences-test.js.es6
@@ -300,6 +300,14 @@ QUnit.test("recently connected devices", async assert => {
   await visit("/u/eviltrout/preferences");
 
   assert.equal(
+    find(".auth-tokens > .auth-token:first .auth-token-device")
+      .text()
+      .trim(),
+    "Linux Computer",
+    "it should display active token first"
+  );
+
+  assert.equal(
     find(".pref-auth-tokens > a:first")
       .text()
       .trim(),

GitHub sha: 59c66fd2

1 Like