REFACTOR: Improve the readability of code (#7076)

This commit is contained in:
Vinoth Kannan 2019-02-26 23:03:49 +05:30 committed by GitHub
parent fbedaea5ed
commit 59c66fd226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -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

View File

@ -299,6 +299,14 @@ QUnit.test("visit my preferences", async assert => {
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()