mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-09 15:35:25 +02:00
testing put above method
This commit is contained in:
parent
022deaf74b
commit
8e5148f7cf
3 changed files with 15 additions and 2 deletions
|
@ -87,7 +87,7 @@ class PagesOrder {
|
||||||
static async update(currentPageId, parentPageId, putAbovePageId) {
|
static async update(currentPageId, parentPageId, putAbovePageId) {
|
||||||
const pageOrder = await Model.get(parentPageId);
|
const pageOrder = await Model.get(parentPageId);
|
||||||
|
|
||||||
pageOrder.shift(currentPageId, putAbovePageId);
|
pageOrder.putAbove(currentPageId, putAbovePageId);
|
||||||
await pageOrder.save();
|
await pageOrder.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,9 +103,14 @@ class PageOrder {
|
||||||
*
|
*
|
||||||
* @returns void
|
* @returns void
|
||||||
*/
|
*/
|
||||||
shift(currentPageId, putAbovePageId) {
|
putAbove(currentPageId, putAbovePageId) {
|
||||||
const found1 = this.order.indexOf(putAbovePageId);
|
const found1 = this.order.indexOf(putAbovePageId);
|
||||||
const found2 = this.order.indexOf(currentPageId);
|
const found2 = this.order.indexOf(currentPageId);
|
||||||
|
|
||||||
|
if (found1 === -1 || found2 === -1) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const margin = found1 < found2 ? 1 : 0;
|
const margin = found1 < found2 ? 1 : 0;
|
||||||
|
|
||||||
this.order.splice(found1, 0, currentPageId);
|
this.order.splice(found1, 0, currentPageId);
|
||||||
|
|
|
@ -110,7 +110,15 @@ describe('PageOrder model', () => {
|
||||||
pageOrder.push(3);
|
pageOrder.push(3);
|
||||||
}).to.throw('given id is not string');
|
}).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();
|
await pageOrder.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue