-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1107 from rainlanguage/migrate-metric-chart-compo…
…nent-to-components-ui Add test for MetricChart component
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { describe, test, expect } from 'vitest'; | ||
import { render } from '@testing-library/svelte'; | ||
import MetricChart from './MetricChart.svelte'; | ||
|
||
describe('MetricChart Component', () => { | ||
test('renders metric label', () => { | ||
const metric = { | ||
label: 'Test Metric', | ||
'unit-prefix': '$', | ||
'unit-suffix': ' USD', | ||
value: 'testValue', | ||
precision: 4, | ||
}; | ||
const data = [{ testValue: 22 }]; | ||
|
||
const { getByText } = render(MetricChart, { props: { metric, data } }); | ||
|
||
expect(getByText('Test Metric')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders formatted data with precision', () => { | ||
const metric = { | ||
label: 'Test Metric', | ||
'unit-prefix': '$', | ||
'unit-suffix': ' USD', | ||
value: 'testValue', | ||
precision: 4, | ||
}; | ||
const data = [{ testValue: 123.456 }]; | ||
|
||
const { getByText } = render(MetricChart, { props: { metric, data } }); | ||
|
||
expect(getByText('$123.5 USD')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders data without precision when not provided', () => { | ||
const metric = { | ||
label: 'Test Metric', | ||
'unit-prefix': '$', | ||
'unit-suffix': ' USD', | ||
value: 'testValue', | ||
}; | ||
const data = [{ testValue: 123.456 }]; | ||
|
||
const { getByText } = render(MetricChart, { props: { metric, data } }); | ||
|
||
expect(getByText('$123.456 USD')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders description if provided', () => { | ||
const metric = { | ||
label: 'Test Metric', | ||
description: 'This is a test metric.', | ||
'unit-prefix': '$', | ||
'unit-suffix': ' USD', | ||
value: 'testValue', | ||
precision: 2, | ||
}; | ||
const data = [{ testValue: 123.456 }]; | ||
|
||
const { getByText } = render(MetricChart, { props: { metric, data } }); | ||
|
||
expect(getByText('This is a test metric.')).toBeInTheDocument(); | ||
}); | ||
}); |