| 658 | }); |
| 659 | |
| 660 | function prepareObjectsForTreeTesting() { |
| 661 | class TestObject extends fabric.Object { |
| 662 | toJSON() { |
| 663 | return { |
| 664 | id: this.id, |
| 665 | objects: this._objects?.map(o => o.id), |
| 666 | parent: this.parent?.id, |
| 667 | canvas: this.canvas?.id |
| 668 | } |
| 669 | } |
| 670 | toString() { |
| 671 | return JSON.stringify(this.toJSON(), null, '\t'); |
| 672 | } |
| 673 | } |
| 674 | class TestCollection extends fabric.createCollectionMixin(TestObject) { |
| 675 | constructor({ id }) { |
| 676 | super(); |
| 677 | this.id = id; |
| 678 | this._objects = []; |
| 679 | } |
| 680 | _onObjectAdded(object) { |
| 681 | object.group = this; |
| 682 | object.parent = this; |
| 683 | } |
| 684 | _onObjectRemoved(object) { |
| 685 | delete object.group; |
| 686 | delete object.parent; |
| 687 | } |
| 688 | removeAll() { |
| 689 | this.remove(...this._objects); |
| 690 | } |
| 691 | } |
| 692 | class TestCanvas extends TestCollection { |
| 693 | _onObjectAdded (object) { |
| 694 | object.canvas = this; |
| 695 | } |
| 696 | _onObjectRemoved (object) { |
| 697 | delete object.canvas; |
| 698 | } |
| 699 | } |
| 700 | return { |
| 701 | object: new TestObject({ id: 'object' }), |
| 702 | other: new TestObject({ id: 'other' }), |
| 703 | a: new TestCollection({ id: 'a' }), |
| 704 | b: new TestCollection({ id: 'b' }), |
| 705 | c: new TestCollection({ id: 'c' }), |
| 706 | canvas: new TestCanvas({ id: 'canvas' }) |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | QUnit.test('findCommonAncestors', function (assert) { |
| 711 | function findCommonAncestors(object, other, expected, message) { |