-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
147 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import {unifyParents} from '../../src/model/internal'; | ||
import {IGroupParent, IOrderedGroup} from '../../src/model'; | ||
|
||
function groupGen(name: string, parent?: IGroupParent): IOrderedGroup { | ||
return { | ||
color: 'gray', | ||
name, | ||
order: [], | ||
parent | ||
}; | ||
} | ||
|
||
function parentGen(name: string, parent?: IGroupParent): IGroupParent { | ||
return { | ||
name, | ||
color: 'gray', | ||
parent, | ||
subGroups: [] | ||
}; | ||
} | ||
|
||
describe('unifyParents', () => { | ||
it('[]', () => { | ||
expect(unifyParents([])).toEqual([]); | ||
}); | ||
it('single', () => { | ||
const a = groupGen('a'); | ||
expect(unifyParents([a])).toEqual([a]); | ||
}); | ||
it('different', () => { | ||
const a = groupGen('a'); | ||
const b = groupGen('b'); | ||
expect(unifyParents([a, b])).toEqual([a, b]); | ||
}); | ||
it('common parent', () => { | ||
const p = parentGen('p'); | ||
const pClone = parentGen('p'); | ||
const a = groupGen('a', p); | ||
const b = groupGen('b', pClone); | ||
unifyParents([a, b]); | ||
expect(a.parent).toBe(p); | ||
expect(a.parent).toBe(b.parent); | ||
}); | ||
it('different parent', () => { | ||
const p = parentGen('p'); | ||
const p2 = parentGen('p2'); | ||
const a = groupGen('a', p); | ||
const b = groupGen('b', p2); | ||
unifyParents([a, b]); | ||
expect(a.parent).toBe(p); | ||
expect(a.parent).not.toBe(b.parent); | ||
}); | ||
it('different in the middle', () => { | ||
const p = parentGen('p'); | ||
const pClone = parentGen('p'); | ||
const p2 = parentGen('p2'); | ||
const a = groupGen('a', p); | ||
const b = groupGen('b', p2); | ||
const c = groupGen('c', pClone); // same as p | ||
unifyParents([a, b, c]); | ||
expect(a.parent).toBe(p); | ||
expect(b.parent).toBe(p2); | ||
expect(c.parent).toBe(pClone); | ||
expect(a.parent).not.toBe(c.parent); | ||
}); | ||
|
||
it('same - different - separate', () => { | ||
const r = parentGen('r'); | ||
const rClone = parentGen('r'); | ||
const rClone2 = parentGen('r'); | ||
|
||
const p = parentGen('p', r); | ||
const pClone = parentGen('p', rClone); | ||
const p2 = parentGen('p2', rClone2); | ||
const a = groupGen('a', p); | ||
const b = groupGen('b', p2); | ||
const c = groupGen('c', pClone); | ||
unifyParents([a, b, c]); | ||
expect(a.parent).toBe(p); | ||
expect(b.parent).toBe(p2); | ||
expect(c.parent).toBe(pClone); | ||
expect(p.parent).toBe(r); | ||
expect(pClone.parent).toBe(r); | ||
expect(p2.parent).toBe(r); | ||
}); | ||
}); |