From 9249922b477bef2e23c7a7fc87fd0f5b7e0851b9 Mon Sep 17 00:00:00 2001
From: Eugen Ciur <eugen@papermerge.com>
Date: Sat, 12 Mar 2022 09:56:42 +0100
Subject: [PATCH] add test function for rearange_items

---
 tests/unit/utils/array-test.js | 41 ++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/tests/unit/utils/array-test.js b/tests/unit/utils/array-test.js
index c0c50bc..d03e9d4 100644
--- a/tests/unit/utils/array-test.js
+++ b/tests/unit/utils/array-test.js
@@ -2,6 +2,20 @@ import { module, test } from 'qunit';
 import { get_id, reposition_items } from 'papermerge/utils/array';
 
 
+class Page {
+  constructor(page_id) {
+    this.id = page_id;
+
+  }
+  get() {
+    return this.id;
+  }
+
+  toString() {
+    return `Page(${this.id})`;
+  }
+}
+
 module('Unit | Utils | Array', function () {
 
   test('get_id 1', function (assert) {
@@ -23,5 +37,32 @@ module('Unit | Utils | Array', function () {
 
     assert.strictEqual(get_id(item), 13);
   });
+
+  test('reposition_items 1', function(assert) {
+    let items,
+      selected_ids = ['2'],
+      drop_pos = 0,
+      actual_result,
+      expected_result;
+
+    items = [
+      new Page('1'), new Page('2'), new Page('3'), new Page('4')
+    ];
+
+    expected_result = [
+      new Page('2'), new Page('1'), new Page('3'), new Page('4')
+    ]
+
+    actual_result = reposition_items({
+      items, selected_ids, drop_pos
+    });
+
+    assert.expect( expected_result.length );
+
+    expected_result.forEach((page, index) => {
+      assert.strictEqual(page.id, actual_result[index].id);
+    });
+
+  });
 });
 
-- 
GitLab