Skip to content

Commit

Permalink
Removed sort by memberof, when the memberOf is the same of items then…
Browse files Browse the repository at this point in the history
… sort function doesn't works correctly.

Added Unit Tests
Fixed documentationjs#838
  • Loading branch information
anthony-redFox committed Aug 7, 2017
1 parent 4911ba6 commit 4edd3c7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
26 changes: 26 additions & 0 deletions __tests__/lib/__snapshots__/sort.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,29 @@ Array [
},
]
`;

exports[`sort toc with files absolute path 2`] = `
Array [
Object {
"context": Object {
"sortKey": "a",
},
"memberof": "classB",
"name": "apples",
},
Object {
"context": Object {
"sortKey": "c",
},
"memberof": "classB",
"name": "bananas",
},
Object {
"context": Object {
"sortKey": "b",
},
"memberof": "classB",
"name": "carrot",
},
]
`;
31 changes: 30 additions & 1 deletion __tests__/lib/sort.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var sort = require('../../src/sort'), path = require('path');
var sort = require('../../src/sort'),
path = require('path');

test('sort stream alphanumeric', function() {
var apples = { context: { sortKey: 'a' }, name: 'apples' };
Expand Down Expand Up @@ -204,3 +205,31 @@ test('sort toc with files absolute path', function() {
})
).toMatchSnapshot();
});

test('sort toc with files absolute path', function() {
var apples = {
context: { sortKey: 'a' },
name: 'apples',
memberof: 'classB'
};
var carrot = {
context: { sortKey: 'b' },
name: 'carrot',
memberof: 'classB'
};
var bananas = {
context: { sortKey: 'c' },
name: 'bananas',
memberof: 'classB'
};

var snowflake = {
name: 'snowflake',
file: path.join(__dirname, '../fixture/snowflake.md')
};
expect(
sort([carrot, apples, bananas], {
sortOrder: 'alpha'
})
).toMatchSnapshot();
});
4 changes: 2 additions & 2 deletions src/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ function compare(a: string, b: string) {
}

function compareCommentsByName(a, b) {
var akey = a.memberof || a.name;
var bkey = b.memberof || b.name;
var akey = a.name;
var bkey = b.name;

if (akey && bkey) {
return compare(akey, bkey);
Expand Down

0 comments on commit 4edd3c7

Please sign in to comment.