1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-08 23:15:28 +02:00

testing put above method

This commit is contained in:
Murod Khaydarov 2019-01-19 17:07:48 +03:00
parent 022deaf74b
commit 8e5148f7cf
No known key found for this signature in database
GPG key ID: C480BA53A8D274C5
3 changed files with 15 additions and 2 deletions

View file

@ -87,7 +87,7 @@ class PagesOrder {
static async update(currentPageId, parentPageId, putAbovePageId) {
const pageOrder = await Model.get(parentPageId);
pageOrder.shift(currentPageId, putAbovePageId);
pageOrder.putAbove(currentPageId, putAbovePageId);
await pageOrder.save();
}
}

View file

@ -103,9 +103,14 @@ class PageOrder {
*
* @returns void
*/
shift(currentPageId, putAbovePageId) {
putAbove(currentPageId, putAbovePageId) {
const found1 = this.order.indexOf(putAbovePageId);
const found2 = this.order.indexOf(currentPageId);
if (found1 === -1 || found2 === -1) {
return
}
const margin = found1 < found2 ? 1 : 0;
this.order.splice(found1, 0, currentPageId);

View file

@ -110,7 +110,15 @@ describe('PageOrder model', () => {
pageOrder.push(3);
}).to.throw('given id is not string');
pageOrder.push('4');
pageOrder.push('5');
pageOrder.push('2');
pageOrder.putAbove('2', '3');
expect(pageOrder.data.order).to.deep.equals(['1', '2', '3', '4', '5']);
pageOrder.putAbove('2', '10');
expect(pageOrder.data.order).to.deep.equals(['1', '2', '3', '4', '5']);
await pageOrder.destroy();
});