|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { render } from '@testing-library/svelte'; |
| 3 | +import UsePlotTest from './usePlot.test.svelte'; |
| 4 | + |
| 5 | +describe('usePlot', () => { |
| 6 | + it('returns plot state with correct height', () => { |
| 7 | + const { container } = render(UsePlotTest, { |
| 8 | + props: { width: 200, height: 150 } |
| 9 | + }); |
| 10 | + const el = container.querySelector('[data-testid="plot-state"]')!; |
| 11 | + expect(el.getAttribute('data-height')).toBe('150'); |
| 12 | + }); |
| 13 | + |
| 14 | + it('returns default dimensions when no props given', () => { |
| 15 | + const { container } = render(UsePlotTest); |
| 16 | + const el = container.querySelector('[data-testid="plot-state"]')!; |
| 17 | + expect(el.getAttribute('data-height')).toBe('100'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('exposes plotWidth and plotHeight', () => { |
| 21 | + const { container } = render(UsePlotTest, { |
| 22 | + props: { width: 100, height: 100 } |
| 23 | + }); |
| 24 | + const el = container.querySelector('[data-testid="plot-state"]')!; |
| 25 | + // plotWidth/plotHeight are width/height minus margins |
| 26 | + const plotWidth = Number(el.getAttribute('data-plot-width')); |
| 27 | + const plotHeight = Number(el.getAttribute('data-plot-height')); |
| 28 | + expect(plotWidth).toBeGreaterThan(0); |
| 29 | + expect(plotWidth).toBeLessThanOrEqual(100); |
| 30 | + expect(plotHeight).toBeGreaterThan(0); |
| 31 | + expect(plotHeight).toBeLessThanOrEqual(100); |
| 32 | + }); |
| 33 | +}); |
| 34 | + |
| 35 | +describe('setPlot', () => { |
| 36 | + it('creates PlotState used by Plot component', () => { |
| 37 | + // setPlot is called internally by Plot, so we verify |
| 38 | + // it works indirectly through usePlot |
| 39 | + const { container } = render(UsePlotTest, { |
| 40 | + props: { width: 300, height: 250 } |
| 41 | + }); |
| 42 | + const el = container.querySelector('[data-testid="plot-state"]')!; |
| 43 | + expect(el.getAttribute('data-height')).toBe('250'); |
| 44 | + }); |
| 45 | +}); |
0 commit comments