Skip to content

Commit 527b3f8

Browse files
committed
test: increase coverage
Signed-off-by: Andres Correa Casablanca <castarco@coderspirit.xyz>
1 parent 4c102eb commit 527b3f8

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

src/layouts.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,9 @@ const _inPlaceEvenSpacingUpdate = (
119119
): void => {
120120
if (numChildren === 0) {
121121
tree.meta.pos.x += shift
122-
tree.meta.m = 0
123122
} else if (numChildren === 1) {
124123
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125124
tree.meta.pos.x = tree.children![0]!.node.meta.pos.x
126-
tree.meta.m = 0
127125
} else {
128126
const c = // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
129127
(tree.children![0]!.node.meta.pos.x +
@@ -132,6 +130,7 @@ const _inPlaceEvenSpacingUpdate = (
132130
0.5
133131
tree.meta.pos.x = Math.max(offsets[depth] ?? 0, c)
134132
}
133+
delete tree.meta.m
135134
tracer.maxX = Math.max(tracer.maxX, tree.meta.pos.x)
136135
offsets[depth] = 1 + tree.meta.pos.x
137136
}

src/tests/layouts.test.ts

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { computeCenter3Layout, computeLeftShiftLayout } from '../layouts'
12
import { describe, expect, it } from 'vitest'
2-
import { computeLeftShiftLayout } from '../layouts'
33

44
describe('computeLeftShiftLayout', () => {
55
it('sets x=0,y=0 for a single-node tree, and data is preserved', () => {
@@ -349,3 +349,79 @@ describe('computeLeftShiftLayout', () => {
349349
})
350350
})
351351
})
352+
353+
describe('computeCenter3Layout', () => {
354+
it('sets x=0,y=0 for a single-node tree, and data is preserved', () => {
355+
const resultWithoutChildren = computeCenter3Layout({
356+
data: { v: 42 },
357+
})
358+
expect(resultWithoutChildren).toEqual({
359+
maxX: 0,
360+
maxY: 0,
361+
tree: {
362+
data: { v: 42 },
363+
meta: {
364+
isRoot: true,
365+
isLeaf: true,
366+
pos: { x: 0, y: 0 },
367+
},
368+
},
369+
})
370+
371+
const resultWithEmptyChildren = computeCenter3Layout({
372+
data: { v: 42 },
373+
children: [],
374+
})
375+
expect(resultWithEmptyChildren).toEqual({
376+
maxX: 0,
377+
maxY: 0,
378+
tree: {
379+
data: { v: 42 },
380+
children: [],
381+
meta: {
382+
isRoot: true,
383+
isLeaf: true,
384+
pos: { x: 0, y: 0 },
385+
},
386+
},
387+
})
388+
})
389+
390+
it('sets x=0,y=0 & x=0,y=1 for tree with single child', () => {
391+
const result = computeCenter3Layout({
392+
data: { v: 42 },
393+
children: [
394+
{
395+
edgeData: {},
396+
node: { data: { v: 43 } },
397+
},
398+
],
399+
})
400+
401+
expect(result).toEqual({
402+
maxX: 0,
403+
maxY: 1,
404+
tree: {
405+
data: { v: 42 },
406+
children: [
407+
{
408+
edgeData: {},
409+
node: {
410+
data: { v: 43 },
411+
meta: {
412+
isRoot: false,
413+
isLeaf: true,
414+
pos: { x: 0, y: 1 },
415+
},
416+
},
417+
},
418+
],
419+
meta: {
420+
isRoot: true,
421+
isLeaf: false,
422+
pos: { x: 0, y: 0 },
423+
},
424+
},
425+
})
426+
})
427+
})

0 commit comments

Comments
 (0)