This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #471 from juan-cortes/LL-2136
LL-2136 Account ordering prioritize starred accounts + tests
- Loading branch information
Showing
2 changed files
with
190 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
// @flow | ||
import { fromAccountRaw, sortAccountsComparatorFromOrder } from "../../account"; | ||
|
||
const accounts = [ | ||
{ | ||
id: "ethereumjs:2:ethereum:0x01:", | ||
seedIdentifier: "0x01", | ||
name: "A", | ||
derivationMode: "", | ||
index: 0, | ||
freshAddress: "0x01", | ||
freshAddressPath: "44'/60'/0'/0/0", | ||
freshAddresses: [], | ||
blockHeight: 8168983, | ||
operations: [], | ||
pendingOperations: [], | ||
currencyId: "ethereum", | ||
unitMagnitude: 18, | ||
lastSyncDate: "2019-07-17T15:13:30.318Z", | ||
balance: "1000000000000000000" | ||
}, | ||
{ | ||
id: "ethereumjs:2:ethereum:0x02:", | ||
seedIdentifier: "0x02", | ||
name: "B", | ||
derivationMode: "", | ||
index: 1, | ||
freshAddress: "0x02", | ||
freshAddressPath: "44'/60'/1'/0/0", | ||
freshAddresses: [], | ||
blockHeight: 8168983, | ||
operations: [], | ||
pendingOperations: [], | ||
currencyId: "ethereum", | ||
unitMagnitude: 18, | ||
lastSyncDate: "2019-07-17T15:13:29.306Z", | ||
balance: "2000000000000000000" | ||
}, | ||
{ | ||
id: "libcore:1:ethereum:xpub3:", | ||
seedIdentifier: "seed", | ||
name: "C", | ||
derivationMode: "", | ||
index: 2, | ||
freshAddress: "0x03", | ||
freshAddressPath: "44'/60'/2'/0/0", | ||
freshAddresses: [], | ||
blockHeight: 8168983, | ||
operations: [], | ||
pendingOperations: [], | ||
currencyId: "ethereum", | ||
unitMagnitude: 18, | ||
lastSyncDate: "2019-07-17T15:13:29.306Z", | ||
balance: "3000000000000000000" | ||
}, | ||
{ | ||
id: "libcore:1:ethereum:xpub3B:", | ||
seedIdentifier: "seed", | ||
name: "CA", | ||
derivationMode: "", | ||
index: 2, | ||
freshAddress: "0x03", | ||
freshAddressPath: "44'/60'/2'/0/0", | ||
freshAddresses: [], | ||
blockHeight: 8168983, | ||
operations: [], | ||
pendingOperations: [], | ||
currencyId: "ethereum", | ||
unitMagnitude: 18, | ||
lastSyncDate: "2019-07-17T15:13:29.306Z", | ||
balance: "3000000000000000000" | ||
}, | ||
{ | ||
id: "libcore:1:ethereum:xpub1B:", | ||
seedIdentifier: "seed", | ||
name: "AA", | ||
derivationMode: "", | ||
index: 2, | ||
freshAddress: "0x03", | ||
freshAddressPath: "44'/60'/2'/0/0", | ||
freshAddresses: [], | ||
blockHeight: 8168983, | ||
operations: [], | ||
pendingOperations: [], | ||
currencyId: "ethereum", | ||
unitMagnitude: 18, | ||
lastSyncDate: "2019-07-17T15:13:29.306Z", | ||
balance: "4000000000000000000" | ||
} | ||
].map(fromAccountRaw); | ||
|
||
const mockedCalculateCountervalue = (_, balance) => balance; | ||
|
||
test("Accounts ordering | name asc", () => { | ||
const compareFn = sortAccountsComparatorFromOrder( | ||
"name|asc", | ||
mockedCalculateCountervalue, | ||
[] | ||
); | ||
const sortedAccounts = accounts.sort(compareFn); | ||
expect(sortedAccounts.map(a => a.name)).toEqual(["A", "AA", "B", "C", "CA"]); | ||
}); | ||
|
||
test("Accounts ordering | name desc", () => { | ||
const compareFn = sortAccountsComparatorFromOrder( | ||
"name|desc", | ||
mockedCalculateCountervalue, | ||
[] | ||
); | ||
const sortedAccounts = accounts.sort(compareFn); | ||
expect(sortedAccounts.map(a => a.name)).toEqual(["CA", "C", "B", "AA", "A"]); | ||
}); | ||
|
||
test("Accounts ordering | balance asc", () => { | ||
const compareFn = sortAccountsComparatorFromOrder( | ||
"balance|asc", | ||
mockedCalculateCountervalue, | ||
[] | ||
); | ||
const sortedAccounts = accounts.sort(compareFn); | ||
expect(sortedAccounts.map(a => a.name)).toEqual(["A", "B", "C", "CA", "AA"]); | ||
}); | ||
|
||
test("Accounts ordering | balance desc", () => { | ||
const compareFn = sortAccountsComparatorFromOrder( | ||
"balance|desc", | ||
mockedCalculateCountervalue, | ||
[] | ||
); | ||
const sortedAccounts = accounts.sort(compareFn); | ||
expect(sortedAccounts.map(a => a.name)).toEqual(["AA", "C", "CA", "B", "A"]); | ||
}); | ||
|
||
test("Accounts ordering | starred + name", () => { | ||
const compareFn = sortAccountsComparatorFromOrder( | ||
"name|desc", | ||
mockedCalculateCountervalue, | ||
["ethereumjs:2:ethereum:0x01:"] | ||
); | ||
const sortedAccounts = accounts.sort(compareFn); | ||
expect(sortedAccounts.map(a => a.name)).toEqual(["A", "CA", "C", "B", "AA"]); | ||
}); | ||
|
||
test("Accounts ordering | all accounts starred, then balance, then name", () => { | ||
const compareFn = sortAccountsComparatorFromOrder( | ||
"balance|desc", | ||
mockedCalculateCountervalue, | ||
[ | ||
"ethereumjs:2:ethereum:0x01:", | ||
"ethereumjs:2:ethereum:0x02:", | ||
"libcore:1:ethereum:xpub3:", | ||
"libcore:1:ethereum:xpub3B:", | ||
"libcore:1:ethereum:xpub1B:" | ||
] | ||
); | ||
const sortedAccounts = accounts.sort(compareFn); | ||
expect(sortedAccounts.map(a => a.name)).toEqual(["AA", "C", "CA", "B", "A"]); | ||
}); | ||
|
||
test("Accounts ordering | backwards compatible when no starred accounts are passed", () => { | ||
const compareFn = sortAccountsComparatorFromOrder( | ||
"balance|desc", | ||
mockedCalculateCountervalue | ||
); | ||
const sortedAccounts = accounts.sort(compareFn); | ||
expect(sortedAccounts.map(a => a.name)).toEqual(["AA", "C", "CA", "B", "A"]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters