forked from FlowwStar/FlowStar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunlock-chart.test.ts
More file actions
63 lines (49 loc) · 1.78 KB
/
Copy pathunlock-chart.test.ts
File metadata and controls
63 lines (49 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { describe, it, expect } from 'vitest'
import { toX, toY } from '@/components/streams/unlock-chart'
// Chart layout constants (must match unlock-chart.tsx)
const PADDING_LEFT = 64
const PADDING_TOP = 20
const CHART_W = 520 // 600 - 64 - 16
const CHART_H = 208 // 260 - 20 - 32
describe('toX', () => {
const start = 1000n
const end = 2000n
it('returns PADDING.left at start boundary', () => {
expect(toX(start, start, end)).toBe(PADDING_LEFT)
})
it('returns PADDING.left + CHART_W at end boundary', () => {
expect(toX(end, start, end)).toBe(PADDING_LEFT + CHART_W)
})
it('returns midpoint pixel for midpoint time', () => {
const mid = 1500n
expect(toX(mid, start, end)).toBe(PADDING_LEFT + CHART_W / 2)
})
it('returns PADDING.left when duration is zero', () => {
expect(toX(start, start, start)).toBe(PADDING_LEFT)
})
it('returns PADDING.left when duration is negative', () => {
expect(toX(start, end, start)).toBe(PADDING_LEFT)
})
it('maps a quarter-way time correctly', () => {
const quarterTime = 1250n
expect(toX(quarterTime, start, end)).toBe(PADDING_LEFT + CHART_W * 0.25)
})
})
describe('toY', () => {
const total = 1000n
it('returns bottom of chart (PADDING.top + CHART_H) at zero amount', () => {
expect(toY(0n, total)).toBe(PADDING_TOP + CHART_H)
})
it('returns top of chart (PADDING.top) at full amount', () => {
expect(toY(total, total)).toBe(PADDING_TOP)
})
it('returns midpoint pixel for half amount', () => {
expect(toY(500n, total)).toBe(PADDING_TOP + CHART_H / 2)
})
it('returns bottom of chart when total is zero', () => {
expect(toY(0n, 0n)).toBe(PADDING_TOP + CHART_H)
})
it('maps a quarter amount correctly', () => {
expect(toY(250n, total)).toBe(PADDING_TOP + CHART_H * 0.75)
})
})