This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sortBy): compare whole prefix instead of first character (#702)
* fix(sortBy): compare whole prefix instead of first character This was noticed in #690 (comment) by @samouss, so I took the time to rewrite this function a little bit to be more clear (IMO) * test(formatSort): add UT * refactor: change conditions to lower nesting * clearer flow (slightly slower, but clearer)
- Loading branch information
Showing
2 changed files
with
62 additions
and
11 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
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,41 @@ | ||
'use strict'; | ||
|
||
var formatSort = require('../../../src/functions/formatSort'); | ||
|
||
it('splits into attribute & direction', function() { | ||
expect(formatSort(['isRefined:desc', 'isNotRefined:desc'])).toEqual([ | ||
['isRefined', 'isNotRefined'], | ||
['desc', 'desc'] | ||
]); | ||
}); | ||
|
||
it('leaves direction empty if no direction was given', function() { | ||
expect(formatSort(['isRefined:desc', 'isNotRefined'])).toEqual([ | ||
['isRefined', 'isNotRefined'], | ||
['desc', undefined] | ||
]); | ||
}); | ||
|
||
it('takes from defaults if no direction was given', function() { | ||
expect( | ||
formatSort( | ||
['isRefined:desc', 'isNotRefined'], | ||
['books:asc', 'isRefined:desc', 'isNotRefined:asc'] | ||
) | ||
).toEqual([ | ||
['isRefined', 'isNotRefined'], | ||
['desc', 'asc'] | ||
]); | ||
}); | ||
|
||
it('leaves direction empty if no direction was given & no default matches', function() { | ||
expect( | ||
formatSort( | ||
['isRefined:desc', 'isNotRefined'], | ||
['books:asc', 'isRefined:desc'] | ||
) | ||
).toEqual([ | ||
['isRefined', 'isNotRefined'], | ||
['desc', undefined] | ||
]); | ||
}); |