|
1 | 1 | import { MenuDisplayItemModel } from '../models/menu-display-item.model';
|
| 2 | +import { ReducedGroup } from '../models/reduced-group'; |
2 | 3 |
|
3 | 4 | import { ArrayUtility } from './array.utility';
|
4 | 5 |
|
@@ -61,26 +62,16 @@ const flat: MenuDisplayItemModel[] = [
|
61 | 62 | ];
|
62 | 63 |
|
63 | 64 | it('should group flat set', () => {
|
64 |
| - const grouped = ArrayUtility.groupBy(flat, i => i.groupId as string); |
65 |
| - expect(grouped).not.toBeNull(); |
66 |
| - console.log({grouped}); |
| 65 | + const groups: ReducedGroup[] = ArrayUtility.groupBy(flat, (i: MenuDisplayItemModel) => i.groupId); |
| 66 | + expect(groups).not.toBeNull(); |
| 67 | + console.log({groups}); |
67 | 68 |
|
68 |
| - const key = 'group-three'; |
69 |
| - expect(grouped).toHaveProperty(key); |
70 |
| - expect(grouped[key]).toHaveLength(1); |
| 69 | + const groupId = 'group-three'; |
| 70 | + const group = groups.find(i => i.key === groupId); |
| 71 | + expect(group.values).toHaveLength(1); |
71 | 72 |
|
72 |
| - const nested = Object.keys(grouped).map(i => { |
73 |
| - const first = grouped[i][0]; |
74 |
| - const menu: MenuDisplayItemModel = { |
75 |
| - id: first.groupId, |
76 |
| - displayText: first.groupDisplayText, |
77 |
| - childItems: grouped[i] |
78 |
| - }; |
79 |
| - return menu; |
80 |
| - }); |
81 |
| - expect(nested).not.toBeNull(); |
82 |
| - console.log({nested}); |
83 |
| - |
84 |
| - expect(nested.find(i => i.id === key)).toBeTruthy(); |
85 |
| - expect(nested.find(i => i.id === key).childItems).toHaveLength(1); |
| 73 | + const first = group.values[0] as MenuDisplayItemModel; |
| 74 | + expect(first).not.toBeNull(); |
| 75 | + console.log({first}); |
| 76 | + expect(first.groupId).toEqual(groupId); |
86 | 77 | });
|
0 commit comments