diff --git a/n-link-core/components/ProgressBar.spec.ts b/n-link-core/components/ProgressBar.spec.ts new file mode 100644 index 0000000..b582615 --- /dev/null +++ b/n-link-core/components/ProgressBar.spec.ts @@ -0,0 +1,29 @@ +import { describe, it, expect } from 'vitest'; +import { mount } from '@vue/test-utils'; +import ProgressBar from './ProgressBar.vue'; + +const fill = (w: ReturnType) => w.get('[data-testid="fill"]'); + +describe('ProgressBar', () => { + it('renders fraction as a width percentage', () => { + const wrapper = mount(ProgressBar, { props: { fraction: 0.5 } }); + expect(fill(wrapper).attributes('style')).toContain('width: 50%'); + }); + + it('clamps fractions below 0 and above 1', () => { + expect(fill(mount(ProgressBar, { props: { fraction: -0.3 } })) + .attributes('style')).toContain('width: 0%'); + expect(fill(mount(ProgressBar, { props: { fraction: 1.8 } })) + .attributes('style')).toContain('width: 100%'); + }); + + it('applies the accent color class by default', () => { + const wrapper = mount(ProgressBar, { props: { fraction: 0.5 } }); + expect(fill(wrapper).classes()).toContain('bg-accent'); + }); + + it('applies a chosen color class', () => { + const wrapper = mount(ProgressBar, { props: { fraction: 0.5, color: 'ok' } }); + expect(fill(wrapper).classes()).toContain('bg-ok'); + }); +}); diff --git a/n-link-core/components/ProgressBar.vue b/n-link-core/components/ProgressBar.vue new file mode 100644 index 0000000..4d3c137 --- /dev/null +++ b/n-link-core/components/ProgressBar.vue @@ -0,0 +1,19 @@ + + +