From c2a656819588f98c5a62eed380b9806d8ed919a2 Mon Sep 17 00:00:00 2001 From: yatbfm Date: Mon, 2 Jun 2025 15:15:33 +0800 Subject: [PATCH 1/2] test: add test case of getChartSpecWithContext when chartType is liquid --- .../getChartSpecWithContext_liquid.test.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/vmind/__tests__/unit/getChartSpecWithContext_liquid.test.ts diff --git a/packages/vmind/__tests__/unit/getChartSpecWithContext_liquid.test.ts b/packages/vmind/__tests__/unit/getChartSpecWithContext_liquid.test.ts new file mode 100644 index 00000000..9402b4fa --- /dev/null +++ b/packages/vmind/__tests__/unit/getChartSpecWithContext_liquid.test.ts @@ -0,0 +1,42 @@ +import { ChartType } from '../../src'; +import { getChartSpecWithContext } from '../../src/atom/chartGenerator/spec'; + +describe('getChartSpecWithContext', () => { + it('should generate correct basic liquid spec', () => { + const data = [{ value: 0.76 }]; + const context = { + chartTypeList: Object.values(ChartType), + dataTable: data, + command: 'Genarate a basic liquid chart', + cell: { + value: 'value' + }, + chartType: ChartType.LiquidChart.toUpperCase() + }; + const { chartType, spec } = getChartSpecWithContext(context); + expect(chartType).toBe(ChartType.LiquidChart); + expect(spec.type).toBe('liquid'); + expect(spec.valueField).not.toBeNull(); + expect(spec.data.values).toEqual(data); + }); + + it('should generate correct basic liquid spec with custom title', () => { + const data = [{ title: '当前进度', value: 0.76 }]; + const context = { + chartTypeList: Object.values(ChartType), + dataTable: data, + command: 'Genarate a basic liquid chart', + cell: { + x: 'title', + value: 'value' + }, + chartType: ChartType.LiquidChart.toUpperCase() + }; + const { chartType, spec } = getChartSpecWithContext(context); + expect(chartType).toBe(ChartType.LiquidChart); + expect(spec.type).toBe('liquid'); + expect(spec.data.values).toEqual(data); + expect(spec.valueField).not.toBeNull(); + expect(spec.indicator.title.style.text).toBe('当前进度'); + }); +}); From 39f02c3606b9b9ee68cdacb108d744d6f626a995 Mon Sep 17 00:00:00 2001 From: yatbfm Date: Sat, 7 Jun 2025 17:04:59 +0800 Subject: [PATCH 2/2] feat: add indicatorSmartInvert configuration check --- .../__tests__/unit/getChartSpecWithContext_liquid.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/vmind/__tests__/unit/getChartSpecWithContext_liquid.test.ts b/packages/vmind/__tests__/unit/getChartSpecWithContext_liquid.test.ts index 9402b4fa..460ad831 100644 --- a/packages/vmind/__tests__/unit/getChartSpecWithContext_liquid.test.ts +++ b/packages/vmind/__tests__/unit/getChartSpecWithContext_liquid.test.ts @@ -16,8 +16,9 @@ describe('getChartSpecWithContext', () => { const { chartType, spec } = getChartSpecWithContext(context); expect(chartType).toBe(ChartType.LiquidChart); expect(spec.type).toBe('liquid'); - expect(spec.valueField).not.toBeNull(); + expect(spec.valueField).toBe(context.cell.value); expect(spec.data.values).toEqual(data); + expect(spec.indicatorSmartInvert).toBe(true); }); it('should generate correct basic liquid spec with custom title', () => { @@ -36,7 +37,8 @@ describe('getChartSpecWithContext', () => { expect(chartType).toBe(ChartType.LiquidChart); expect(spec.type).toBe('liquid'); expect(spec.data.values).toEqual(data); - expect(spec.valueField).not.toBeNull(); + expect(spec.valueField).toBe(context.cell.value); expect(spec.indicator.title.style.text).toBe('当前进度'); + expect(spec.indicatorSmartInvert).toBe(true); }); });