mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 12:55:06 +03:00
* Add all missing libraries in the packages/apps. * Add all missing Vitest imports to the tests. * Add some missing exports to ui. * Fix the admonition export. * Fix various minor bugs. * Migrate the ui package to use vitest.
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { renderHook } from '@testing-library/react'
|
|
import {
|
|
isFloat,
|
|
numberFormatter,
|
|
precisionFormatter,
|
|
useStacked,
|
|
} from 'components/ui/Charts/Charts.utils'
|
|
import { test, expect } from 'vitest'
|
|
|
|
test('isFloat', () => {
|
|
expect(isFloat(123)).toBe(false)
|
|
expect(isFloat(123.123)).toBe(true)
|
|
})
|
|
test('numberFormatter', () => {
|
|
expect(numberFormatter(123)).toBe('123')
|
|
expect(numberFormatter(123.123)).toBe('123.12')
|
|
expect(numberFormatter(123456.78)).toBe('123,456.78')
|
|
})
|
|
|
|
test('precisionFormatter', () => {
|
|
expect(precisionFormatter(123, 1)).toBe('123.0')
|
|
expect(precisionFormatter(123.12345, 4)).toBe('123.1234')
|
|
expect(precisionFormatter(123456, 2)).toBe('123,456.00')
|
|
expect(precisionFormatter(123456.78, 2)).toBe('123,456.78')
|
|
})
|
|
|
|
test('useStacked', () => {
|
|
const { result } = renderHook(() =>
|
|
useStacked({
|
|
data: [
|
|
{ label: 'a', x: 1, y: 2 },
|
|
{ label: 'b', x: 1, y: 3 },
|
|
] as any,
|
|
xAxisKey: 'x',
|
|
yAxisKey: 'y',
|
|
stackKey: 'label',
|
|
variant: 'percentages',
|
|
})
|
|
)
|
|
expect(result.current).toMatchObject({
|
|
stackedData: [
|
|
{
|
|
a: 2,
|
|
b: 3,
|
|
x: 1,
|
|
},
|
|
],
|
|
percentagesStackedData: [
|
|
{
|
|
a: 2 / 5,
|
|
b: 3 / 5,
|
|
x: 1,
|
|
},
|
|
],
|
|
})
|
|
})
|