@clevertask/react-sortable-tree 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -369,6 +369,11 @@ await expectItemNotToBeChildOf(expect, taskA, taskC);
369
369
  ### expectItemBefore
370
370
 
371
371
  This helper tells you if an item is before the "x" item. You don't need a function for after because it's a matter of targeting the items in their proper places.
372
+ ⚠️ You must add a `data-tree-item-label` to your HTML element that contains the tree label
373
+
374
+ ```tsx
375
+ <p data-tree-item-label>{props.treeItem.label}</p>
376
+ ```
372
377
 
373
378
  ```ts
374
379
  await expectItemBefore(page, expect, 'C', 'A');
package/dist/e2e/index.js CHANGED
@@ -1,51 +1,63 @@
1
- async function f({ page: t, expect: e, from: o, to: a }) {
2
- const n = t.getByLabel(`Drag ${o.name}`, { exact: !0 }), m = t.getByRole("treeitem", { name: a.name });
3
- await e(n).toBeVisible(), await e(m).toBeVisible();
4
- const r = await n.boundingBox(), i = await m.boundingBox();
5
- if (!r || !i)
1
+ function u(t, e, o) {
2
+ return t.getByRole("treeitem", {
3
+ name: e,
4
+ exact: (o == null ? void 0 : o.exact) ?? !0
5
+ });
6
+ }
7
+ async function g({ page: t, expect: e, from: o, to: s }) {
8
+ const i = t.getByLabel(`Drag ${o.name}`, { exact: !0 }), n = u(t, s.name).locator("[data-tree-draggable]");
9
+ await e(i).toBeVisible(), await e(n).toBeVisible();
10
+ const a = await i.boundingBox(), r = await n.boundingBox();
11
+ if (!a || !r)
6
12
  throw new Error("Could not determine bounding boxes for drag operation");
7
- const c = r.x + r.width / 2, w = r.y + r.height / 2;
8
- let u = i.x + 8, d = i.y;
9
- const b = 4;
10
- switch (a.position) {
11
- case "before":
12
- d = i.y + b;
13
+ const w = a.x + a.width / 2, m = a.y + a.height / 2;
14
+ let f = r.x + 8, d = r.y;
15
+ const h = 4, l = a.y > r.y;
16
+ switch (s.position) {
17
+ case "before": {
18
+ d = r.y + h, l && (d += a.height);
13
19
  break;
14
- case "after":
15
- d = i.y + i.height - b;
20
+ }
21
+ case "after": {
22
+ d = r.y + r.height - h, l && (d += a.height);
16
23
  break;
24
+ }
17
25
  case "inside": {
18
- const s = await m.locator("[data-tree-draggable]").boundingBox();
19
- if (!s)
26
+ const c = await n.boundingBox();
27
+ if (!c)
20
28
  throw new Error("Could not determine draggable item bounds");
21
- u = s.x + s.width * 0.05, d = s.y + s.height * 0.75;
29
+ f = c.x + c.width * 0.25, l ? d = c.y + c.height * 2 : d = c.y + c.height * 0.75;
22
30
  break;
23
31
  }
24
32
  }
25
- await t.mouse.move(c, w), await t.mouse.down(), await t.mouse.move(c + 1, w + 1), await t.mouse.move(u, d, { steps: 10 }), await t.evaluate(() => new Promise(requestAnimationFrame)), await t.mouse.up();
33
+ await t.mouse.move(w, m), await t.mouse.down(), await t.mouse.move(w + 1, m + 1), await t.mouse.move(f, d, { steps: 10 }), await t.evaluate(() => new Promise(requestAnimationFrame)), await t.waitForTimeout(120), await t.mouse.up(), await t.waitForTimeout(120), await e(i).toHaveCount(1);
26
34
  }
27
- async function l(t) {
35
+ async function b(t) {
28
36
  const e = await t.getAttribute("data-tree-item-id");
29
37
  if (!e)
30
38
  throw new Error("Tree item does not have data-tree-item-id");
31
39
  return e;
32
40
  }
33
- async function x(t, e, o, a) {
34
- const n = await t.getByRole("treeitem").allTextContents();
35
- e(n.indexOf(o)).toBeLessThan(n.indexOf(a));
41
+ async function y(t, e, o, s) {
42
+ const i = await t.locator('[role="treeitem"] [data-tree-item-label]').evaluateAll((r) => r.map((w) => {
43
+ var m;
44
+ return (m = w.textContent) == null ? void 0 : m.trim();
45
+ })), n = i.indexOf(o), a = i.indexOf(s);
46
+ e(n).toBeLessThan(a);
36
47
  }
37
- async function h(t, e, o) {
38
- const a = await l(o);
39
- await t(e).toHaveAttribute("data-tree-item-parent-id", a);
48
+ async function B(t, e, o, s) {
49
+ const i = u(t, o), n = u(t, s), a = await b(n);
50
+ await e(i).toHaveAttribute("data-tree-item-parent-id", a);
40
51
  }
41
- async function B(t, e, o) {
42
- const a = await l(o);
43
- await t(e).not.toHaveAttribute("data-tree-item-parent-id", a);
52
+ async function I(t, e, o, s) {
53
+ const i = u(t, o), n = u(t, s), a = await b(n);
54
+ await e(i).not.toHaveAttribute("data-tree-item-parent-id", a);
44
55
  }
45
56
  export {
46
- f as dragItem,
47
- x as expectItemBefore,
48
- B as expectItemNotToBeChildOf,
49
- h as expectItemToBeChildOf,
50
- l as getTreeItemId
57
+ g as dragItem,
58
+ y as expectItemBefore,
59
+ I as expectItemNotToBeChildOf,
60
+ B as expectItemToBeChildOf,
61
+ u as getTreeItem,
62
+ b as getTreeItemId
51
63
  };
@@ -1,2 +1,2 @@
1
- import { Expect, Page } from '@playwright/test';
2
- export declare function expectItemBefore(page: Page, expect: Expect, first: string, second: string): Promise<void>;
1
+ import { Page, Expect } from '@playwright/test';
2
+ export declare function expectItemBefore(page: Page, expect: Expect, beforeLabel: string, afterLabel: string): Promise<void>;
@@ -1,3 +1,3 @@
1
- import { Locator, Expect } from '@playwright/test';
2
- export declare function expectItemToBeChildOf(expect: Expect, child: Locator, parent: Locator): Promise<void>;
3
- export declare function expectItemNotToBeChildOf(expect: Expect, child: Locator, parent: Locator): Promise<void>;
1
+ import { Page, Expect } from '@playwright/test';
2
+ export declare function expectItemToBeChildOf(page: Page, expect: Expect, child: string, parent: string): Promise<void>;
3
+ export declare function expectItemNotToBeChildOf(page: Page, expect: Expect, child: string, parent: string): Promise<void>;
@@ -0,0 +1,4 @@
1
+ import { Page, Locator } from '@playwright/test';
2
+ export declare function getTreeItem(page: Page, name: string, options?: {
3
+ exact?: boolean;
4
+ }): Locator;
@@ -1,4 +1,5 @@
1
1
  export * from './drag-item';
2
+ export * from './get-tree-item';
2
3
  export * from './get-tree-item-id';
3
4
  export * from './expect-item-before';
4
5
  export * from './expect-item-child-of';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clevertask/react-sortable-tree",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "CleverTask",