Skip to content

Commit

Permalink
Merge pull request #1107 from rainlanguage/migrate-metric-chart-compo…
Browse files Browse the repository at this point in the history
…nent-to-components-ui

Add test for MetricChart component
  • Loading branch information
hardyjosh authored Jan 5, 2025
2 parents d7aa9f5 + 0e37a47 commit 795b287
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tauri-app/src/lib/components/MetricChart.test.ts
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();
});
});

0 comments on commit 795b287

Please sign in to comment.