Skip to content

Commit

Permalink
add tests for utils.sort and utils.filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ortexx committed Jul 30, 2017
1 parent a0267f7 commit 09da119
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
12 changes: 10 additions & 2 deletions dist/akili.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/akili.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "akili",
"version": "0.3.2",
"version": "0.3.3",
"description": "Akili - javascript framework",
"main": "./src/akili.js",
"author": {
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ utils.style = function(obj) {
* @example
* // returns [{x:1}, {x:11}]
* utils.filter([{x:1}, {x:2}, {x:3}, {x:11}], '1', ['x']);
*
* * @example
* // returns [{x:{y:1}}]
* utils.filter([{x:{y:1}}, {x:{y:2}}], '1', ['x', 'y']);
*
* @param {Array} arr
* @param {string|RegExp|function} handler - type of filtering
Expand Down Expand Up @@ -136,6 +140,10 @@ utils.filter = function (arr, handler, keys = []) {
* @example
* // returns [{x: 1, y: 3}, {x: 2, y: 1}, {x:2, y: 2}]
* utils.sort([{x: 2, y: 2}, {x: 2, y: 1}, {x: 2, y: 3}], [['x'], ['y']], [true, true]);
*
* @example
* // returns [{x: {y: 1}}, {x: {y: 2}}]
* utils.sort([{x: {y: 2}}, {x: {y: 1}}], [['x', 'y']], [true]);
*
* @param {Array} arr
* @param {boolean|Array[]|string[]|string} [keys]
Expand Down
19 changes: 19 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,18 @@ describe('utils.js', () => {

assert.equal(JSON.stringify([{value: 3}]), JSON.stringify(res));
});

it('should filter array with the nested property key', () => {
let arr = [
{ x: { value: 1 } },
{ x: { value: 2 } },
{ x: { value: 3 } }
];

let res = utils.filter(arr, '1', ['x', 'value']);

assert.equal(JSON.stringify([{ x: { value: 1 } }]), JSON.stringify(res));
});
});

describe('.sort()', () => {
Expand Down Expand Up @@ -372,6 +384,13 @@ describe('utils.js', () => {

assert.equal(JSON.stringify(sorted), JSON.stringify(utils.sort(arr, ['x', 'y'], [true, true])));
});

it('should order nested keys', () => {
let arr = [{x: {y: 2}}, {x: {y: 1}}];
let sorted = [{x: {y: 1}}, {x: {y: 2}}];

assert.equal(JSON.stringify(sorted), JSON.stringify(utils.sort(arr, [['x', 'y']], [true])));
});
});
});
});
Expand Down

0 comments on commit 09da119

Please sign in to comment.