|
| 1 | +import { identifyAndAddParentRows } from '../useStructuredProperties'; |
| 2 | + |
| 3 | +describe('identifyAndAddParentRows', () => { |
| 4 | + it('should not return parent rows when there are none', () => { |
| 5 | + const propertyRows = [ |
| 6 | + { displayName: 'test1', qualifiedName: 'test1' }, |
| 7 | + { displayName: 'test2', qualifiedName: 'test2' }, |
| 8 | + ]; |
| 9 | + expect(identifyAndAddParentRows(propertyRows)).toMatchObject([]); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should not return parent rows when another row starts with the same letters but is a different token', () => { |
| 13 | + const propertyRows = [ |
| 14 | + { displayName: 'test1', qualifiedName: 'testing.one' }, |
| 15 | + { displayName: 'test2', qualifiedName: 'testingAgain.two' }, |
| 16 | + ]; |
| 17 | + expect(identifyAndAddParentRows(propertyRows)).toMatchObject([]); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should return parent rows properly', () => { |
| 21 | + const propertyRows = [ |
| 22 | + { displayName: 'test1', qualifiedName: 'testing.one' }, |
| 23 | + { displayName: 'test2', qualifiedName: 'testing.two' }, |
| 24 | + { displayName: 'test3', qualifiedName: 'testing.three' }, |
| 25 | + ]; |
| 26 | + expect(identifyAndAddParentRows(propertyRows)).toMatchObject([ |
| 27 | + { displayName: 'testing', qualifiedName: 'testing', childrenCount: 3 }, |
| 28 | + ]); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should return parent rows properly with multiple layers of nesting', () => { |
| 32 | + const propertyRows = [ |
| 33 | + { displayName: 'test1', qualifiedName: 'testing.one.two.a.1' }, |
| 34 | + { displayName: 'test1', qualifiedName: 'testing.one.two.a.2' }, |
| 35 | + { displayName: 'test1', qualifiedName: 'testing.one.two.b' }, |
| 36 | + { displayName: 'test1', qualifiedName: 'testing.one.three' }, |
| 37 | + { displayName: 'test2', qualifiedName: 'testing.two.c.d' }, |
| 38 | + { displayName: 'test3', qualifiedName: 'testing.three' }, |
| 39 | + { displayName: 'test3', qualifiedName: 'testParent' }, |
| 40 | + ]; |
| 41 | + expect(identifyAndAddParentRows(propertyRows)).toMatchObject([ |
| 42 | + { displayName: 'testing', qualifiedName: 'testing', isParentRow: true, childrenCount: 6 }, |
| 43 | + { displayName: 'testing.one', qualifiedName: 'testing.one', isParentRow: true, childrenCount: 4 }, |
| 44 | + { displayName: 'testing.one.two', qualifiedName: 'testing.one.two', isParentRow: true, childrenCount: 3 }, |
| 45 | + { |
| 46 | + displayName: 'testing.one.two.a', |
| 47 | + qualifiedName: 'testing.one.two.a', |
| 48 | + isParentRow: true, |
| 49 | + childrenCount: 2, |
| 50 | + }, |
| 51 | + ]); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should return parent rows properly with multiple layers of nesting regardless of order', () => { |
| 55 | + const propertyRows = [ |
| 56 | + { displayName: 'test1', qualifiedName: 'testing.one.two.a.1' }, |
| 57 | + { displayName: 'test3', qualifiedName: 'testParent' }, |
| 58 | + { displayName: 'test1', qualifiedName: 'testing.one.three' }, |
| 59 | + { displayName: 'test2', qualifiedName: 'testing.two.c.d' }, |
| 60 | + { displayName: 'test1', qualifiedName: 'testing.one.two.b' }, |
| 61 | + { displayName: 'test3', qualifiedName: 'testing.three' }, |
| 62 | + { displayName: 'test1', qualifiedName: 'testing.one.two.a.2' }, |
| 63 | + ]; |
| 64 | + expect(identifyAndAddParentRows(propertyRows)).toMatchObject([ |
| 65 | + { displayName: 'testing', qualifiedName: 'testing', isParentRow: true, childrenCount: 6 }, |
| 66 | + { displayName: 'testing.one', qualifiedName: 'testing.one', isParentRow: true, childrenCount: 4 }, |
| 67 | + { displayName: 'testing.one.two', qualifiedName: 'testing.one.two', isParentRow: true, childrenCount: 3 }, |
| 68 | + { |
| 69 | + displayName: 'testing.one.two.a', |
| 70 | + qualifiedName: 'testing.one.two.a', |
| 71 | + isParentRow: true, |
| 72 | + childrenCount: 2, |
| 73 | + }, |
| 74 | + ]); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should return parent rows properly with simpler layers of nesting', () => { |
| 78 | + const propertyRows = [ |
| 79 | + { displayName: 'test2', qualifiedName: 'testing.two.c.d' }, |
| 80 | + { displayName: 'test3', qualifiedName: 'testing.three' }, |
| 81 | + { displayName: 'test3', qualifiedName: 'testParent' }, |
| 82 | + ]; |
| 83 | + expect(identifyAndAddParentRows(propertyRows)).toMatchObject([ |
| 84 | + { displayName: 'testing', qualifiedName: 'testing', isParentRow: true, childrenCount: 2 }, |
| 85 | + ]); |
| 86 | + }); |
| 87 | +}); |
0 commit comments