ts-prime
Version:
A utility library for JavaScript and Typescript.
64 lines (63 loc) • 2.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var sortBy_1 = require("./sortBy");
var pipe_1 = require("./pipe");
var items = [{ a: 1 }, { a: 3 }, { a: 7 }, { a: 2 }];
var sorted = [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 7 }];
var multiPropSortItems = [
{ favorite: false, category: 'A' },
{ favorite: true, category: 'C' },
{ favorite: true, category: 'B' },
{ favorite: false, category: 'B' },
];
// Expect favorites sorted alphabetically
var multiPropSortItemsSorted = [
{ favorite: true, category: 'B' },
{ favorite: true, category: 'C' },
{ favorite: false, category: 'A' },
{ favorite: false, category: 'B' },
];
var withLocaleComparison = [
{ category: 'Garden' },
{ category: 'cleaning' },
{ category: 'books' },
{ category: 'books' },
{ category: 'Tech' },
{ category: 'Cooking' },
];
var sortedWithLocaleComparison = [
{ category: 'books' },
{ category: 'books' },
{ category: 'cleaning' },
{ category: 'Cooking' },
{ category: 'Garden' },
{ category: 'Tech' },
];
describe('data first', function () {
test('sort correctly', function () {
expect(sortBy_1.sortBy(items, function (x) { return x.a; })).toEqual(sorted);
});
test('sort with multi keys', function () {
expect(sortBy_1.sortBy(multiPropSortItems, function (x) { return [
{ value: x.favorite, order: 'desc' },
x.category,
]; })).toEqual(multiPropSortItemsSorted);
});
test('sort with multi keys', function () {
expect(sortBy_1.sortBy(withLocaleComparison, function (x) { return [
{
value: x.category,
compare: function (a, b) { return a.toString().localeCompare(b.toString()); },
},
x.category,
]; })).toEqual(sortedWithLocaleComparison);
});
});
xdescribe('data last', function () {
test('sort correctly', function () {
expect(pipe_1.pipe(items, sortBy_1.sortBy(function (x) { return x.a; }))).toEqual(sorted);
});
test('sort multi objects correctly', function () {
expect(pipe_1.pipe(items, sortBy_1.sortBy(function (x) { return x.a; }))).toEqual(sorted);
});
});