feat(config): add file property for notes (#614) · documentationjs/documentation@d96aa47

11

'use strict';

2233

var test = require('tap').test,

4-

sort = require('../../lib/sort');

4+

sort = require('../../lib/sort'),

5+

path = require('path');

5667

test('sort stream alphanumeric', function (t) {

78

var apples = { context: { sortKey: 'a' }, name: 'apples' };

@@ -177,3 +178,103 @@ test('sort an already-sorted stream containing a section/description', function

177178

t.deepEqual(sortTwice, [carrot, sectionMarkdown, bananas, apples]);

178179

t.end();

179180

});

181+182+

test('sort toc with files', function (t) {

183+

var apples = { context: { sortKey: 'a' }, name: 'apples' };

184+

var carrot = { context: { sortKey: 'b' }, name: 'carrot' };

185+

var bananas = { context: { sortKey: 'c' }, name: 'bananas' };

186+187+

var snowflake = {

188+

name: 'snowflake',

189+

file: 'test/fixture/snowflake.md'

190+

};

191+192+

var processedSnowflake = {

193+

name: 'snowflake',

194+

kind: 'note',

195+

description: {

196+

children: [{

197+

children: [{

198+

position: {

199+

end: {column: 16, line: 1, offset: 15},

200+

indent: [],

201+

start: {column: 3, line: 1, offset: 2}

202+

},

203+

type: 'text',

204+

value: 'The Snowflake'

205+

}],

206+

depth: 1,

207+

position: {

208+

end: {column: 16, line: 1, offset: 15},

209+

indent: [],

210+

start: {column: 1, line: 1, offset: 0}

211+

},

212+

type: 'heading'

213+

}],

214+

position: {

215+

end: {column: 1, line: 2, offset: 16},

216+

start: {column: 1, line: 1, offset: 0}

217+

},

218+

type: 'root'

219+

}

220+

};

221+

t.deepEqual(sort([

222+

apples, carrot, bananas

223+

], {

224+

toc: [snowflake]

225+

}), [

226+

processedSnowflake, apples, carrot, bananas

227+

], 'with configuration');

228+229+

t.end();

230+

});

231+232+

test('sort toc with files absolute path', function (t) {

233+

var apples = { context: { sortKey: 'a' }, name: 'apples' };

234+

var carrot = { context: { sortKey: 'b' }, name: 'carrot' };

235+

var bananas = { context: { sortKey: 'c' }, name: 'bananas' };

236+237+

var snowflake = {

238+

name: 'snowflake',

239+

file: path.join(__dirname, '../fixture/snowflake.md')

240+

};

241+242+

var processedSnowflake = {

243+

name: 'snowflake',

244+

kind: 'note',

245+

description: {

246+

children: [{

247+

children: [{

248+

position: {

249+

end: {column: 16, line: 1, offset: 15},

250+

indent: [],

251+

start: {column: 3, line: 1, offset: 2}

252+

},

253+

type: 'text',

254+

value: 'The Snowflake'

255+

}],

256+

depth: 1,

257+

position: {

258+

end: {column: 16, line: 1, offset: 15},

259+

indent: [],

260+

start: {column: 1, line: 1, offset: 0}

261+

},

262+

type: 'heading'

263+

}],

264+

position: {

265+

end: {column: 1, line: 2, offset: 16},

266+

start: {column: 1, line: 1, offset: 0}

267+

},

268+

type: 'root'

269+

}

270+

};

271+

t.deepEqual(sort([

272+

apples, carrot, bananas

273+

], {

274+

toc: [snowflake]

275+

}), [

276+

processedSnowflake, apples, carrot, bananas

277+

], 'with configuration');

278+279+

t.end();

280+

});