Skip to content

Commit

Permalink
#20
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Wilhite committed Jan 8, 2020
1 parent a099c01 commit 07ef358
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export { SyndicationFeed } from './models/syndication-feed';
/* utilities */
export { ArrayUtility } from './utilities/array.utility';
export { CssUtility } from './utilities/css.utility';
export { DisplayItemUtility } from './utilities/display-item.utility';
export { DomUtility } from './utilities/dom.utility';
export { MapObjectUtility } from './utilities/map-object.utility';
export { MathUtility } from './utilities/math.utility';
export { ObjectUtility } from './utilities/object.utility';
export { ReducedGroupUtility } from './utilities/reduced-group-utility';
31 changes: 11 additions & 20 deletions src/utilities/array.utility.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MenuDisplayItemModel } from '../models/menu-display-item.model';
import { ReducedGroup } from '../models/reduced-group';

import { ArrayUtility } from './array.utility';

Expand Down Expand Up @@ -61,26 +62,16 @@ const flat: MenuDisplayItemModel[] = [
];

it('should group flat set', () => {
const grouped = ArrayUtility.groupBy(flat, i => i.groupId as string);
expect(grouped).not.toBeNull();
console.log({grouped});
const groups: ReducedGroup[] = ArrayUtility.groupBy(flat, (i: MenuDisplayItemModel) => i.groupId);
expect(groups).not.toBeNull();
console.log({groups});

const key = 'group-three';
expect(grouped).toHaveProperty(key);
expect(grouped[key]).toHaveLength(1);
const groupId = 'group-three';
const group = groups.find(i => i.key === groupId);
expect(group.values).toHaveLength(1);

const nested = Object.keys(grouped).map(i => {
const first = grouped[i][0];
const menu: MenuDisplayItemModel = {
id: first.groupId,
displayText: first.groupDisplayText,
childItems: grouped[i]
};
return menu;
});
expect(nested).not.toBeNull();
console.log({nested});

expect(nested.find(i => i.id === key)).toBeTruthy();
expect(nested.find(i => i.id === key).childItems).toHaveLength(1);
const first = group.values[0] as MenuDisplayItemModel;
expect(first).not.toBeNull();
console.log({first});
expect(first.groupId).toEqual(groupId);
});
2 changes: 1 addition & 1 deletion src/utilities/array.utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ArrayUtility {
}

/**
* reduces the specified reducible in @type {ReducedGroup} groups
* reduces the specified reducible to @type {ReducedGroup} groups
*
* @description https://github.com/BryanWilhite/songhay-core/issues/20
*/
Expand Down

0 comments on commit 07ef358

Please sign in to comment.