Skip to content

Commit 4edd3c7

Browse files
Removed sort by memberof, when the memberOf is the same of items then sort function doesn't works correctly.
Added Unit Tests Fixed documentationjs#838
1 parent 4911ba6 commit 4edd3c7

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

__tests__/lib/__snapshots__/sort.js.snap

+26
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,29 @@ Array [
107107
},
108108
]
109109
`;
110+
111+
exports[`sort toc with files absolute path 2`] = `
112+
Array [
113+
Object {
114+
"context": Object {
115+
"sortKey": "a",
116+
},
117+
"memberof": "classB",
118+
"name": "apples",
119+
},
120+
Object {
121+
"context": Object {
122+
"sortKey": "c",
123+
},
124+
"memberof": "classB",
125+
"name": "bananas",
126+
},
127+
Object {
128+
"context": Object {
129+
"sortKey": "b",
130+
},
131+
"memberof": "classB",
132+
"name": "carrot",
133+
},
134+
]
135+
`;

__tests__/lib/sort.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
var sort = require('../../src/sort'), path = require('path');
1+
var sort = require('../../src/sort'),
2+
path = require('path');
23

34
test('sort stream alphanumeric', function() {
45
var apples = { context: { sortKey: 'a' }, name: 'apples' };
@@ -204,3 +205,31 @@ test('sort toc with files absolute path', function() {
204205
})
205206
).toMatchSnapshot();
206207
});
208+
209+
test('sort toc with files absolute path', function() {
210+
var apples = {
211+
context: { sortKey: 'a' },
212+
name: 'apples',
213+
memberof: 'classB'
214+
};
215+
var carrot = {
216+
context: { sortKey: 'b' },
217+
name: 'carrot',
218+
memberof: 'classB'
219+
};
220+
var bananas = {
221+
context: { sortKey: 'c' },
222+
name: 'bananas',
223+
memberof: 'classB'
224+
};
225+
226+
var snowflake = {
227+
name: 'snowflake',
228+
file: path.join(__dirname, '../fixture/snowflake.md')
229+
};
230+
expect(
231+
sort([carrot, apples, bananas], {
232+
sortOrder: 'alpha'
233+
})
234+
).toMatchSnapshot();
235+
});

src/sort.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ function compare(a: string, b: string) {
9999
}
100100

101101
function compareCommentsByName(a, b) {
102-
var akey = a.memberof || a.name;
103-
var bkey = b.memberof || b.name;
102+
var akey = a.name;
103+
var bkey = b.name;
104104

105105
if (akey && bkey) {
106106
return compare(akey, bkey);

0 commit comments

Comments
 (0)