Files
genoffice/apps/sheets/tests/chart-legend-swatch.test.ts
T
merrick-2002andGenOffice 0a2c25d483 Sync snapshot (2026-08-26) (#159)
- Sheets: CSV export and save support, Excel-matching data validation
- Docs: image, shape, WordArt, and chart rendering fixes
- Slides: downloadable font catalog with a missing-font banner
- Slides: better AI text layout and a speaker-notes tool

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-08-26 17:34:55 +08:00

52 lines
2.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
legendSwatchColor,
legendUsesLineSwatches,
lineStroke,
} from '../src/renderer/WorkbookVisuals'
describe('lineStroke', () => {
it('prefers the explicit series line color over the fill/accent default', () => {
expect(lineStroke({ color: '#9BBB59', lineColor: '#10253F' }, 0)).toBe('#10253F')
expect(lineStroke({ color: '#9BBB59' }, 0)).toBe('#9BBB59')
})
it('returns null for an explicit noFill line and falls back to the palette', () => {
expect(lineStroke({ color: '#9BBB59', lineColor: 'none' }, 0)).toBeNull()
expect(lineStroke({}, 0)).toBe('#4472c4')
})
})
describe('legendSwatchColor', () => {
const series = { color: '#9BBB59', lineColor: '#10253F' }
it('mirrors the drawn stroke on line-family charts', () => {
expect(legendSwatchColor(series, 0, true)).toBe('#10253F')
// noFill line: the swatch keeps the series color instead of vanishing.
expect(legendSwatchColor({ color: '#9BBB59', lineColor: 'none' }, 0, true)).toBe('#9BBB59')
expect(legendSwatchColor({}, 1, true)).toBe('#ed7d31')
})
it('keeps the fill resolution for non-line charts', () => {
expect(legendSwatchColor(series, 0, false)).toBe('#9BBB59')
expect(legendSwatchColor({}, 1, false)).toBe('#ed7d31')
})
})
describe('legendUsesLineSwatches', () => {
it('follows the render dispatch: only a winning line/radar plot strokes', () => {
expect(legendUsesLineSwatches(['lineChart'])).toBe(true)
expect(legendUsesLineSwatches(['radarChart'])).toBe(true)
// Area wins the cascade over line: the drawn series are fills, so the
// swatches must keep the fill resolution.
expect(legendUsesLineSwatches(['lineChart', 'areaChart'])).toBe(false)
expect(legendUsesLineSwatches(['lineChart', 'scatterChart'])).toBe(false)
// Bar combos render BarChart; pie keeps its own legend.
expect(legendUsesLineSwatches(['barChart', 'lineChart'])).toBe(false)
expect(legendUsesLineSwatches(['radarChart', 'barChart'])).toBe(false)
expect(legendUsesLineSwatches(['pieChart', 'lineChart'])).toBe(false)
expect(legendUsesLineSwatches(['barChart'])).toBe(false)
})
})