diff --git a/src/composables/plotTemplates.ts b/src/composables/plotTemplates.ts index cd2b6e82..9fecdb49 100644 --- a/src/composables/plotTemplates.ts +++ b/src/composables/plotTemplates.ts @@ -52,7 +52,9 @@ function replaceTemplateColumns(template: Partial, nameMap: Record = {}; @@ -64,7 +66,9 @@ function replaceTemplateColumns(template: Partial, nameMap: Record Object.keys(plotTemplates.value)), }; } diff --git a/tests/unit/plotTemplates.spec.ts b/tests/unit/plotTemplates.spec.ts new file mode 100644 index 00000000..29a60900 --- /dev/null +++ b/tests/unit/plotTemplates.spec.ts @@ -0,0 +1,98 @@ +import { describe, it, expect } from 'vitest'; + +import { usePlotTemplates } from '@/composables/plotTemplates'; +import { PlotConfig } from '@/types'; + +describe('plotTemplates.ts', () => { + it('Updates main plot values', () => { + const { replaceTemplateColumns } = usePlotTemplates(); + const reMapping = { ema: 'ema_14' }; + const template: Partial = { + main_plot: { + ema: { + color: '#ff8000', + type: 'line', + }, + }, + }; + const expected: Partial = { + main_plot: { + ema_14: { + color: '#ff8000', + type: 'line', + }, + }, + }; + expect(replaceTemplateColumns(template, reMapping)).toEqual(expected); + }); + it('Updates subplot plot values', () => { + const { replaceTemplateColumns } = usePlotTemplates(); + const reMapping = { rsi: 'rsi_14' }; + const template: Partial = { + subplots: { + RSI: { + rsi: { + color: '#ff8000', + type: 'line', + }, + }, + }, + }; + const expected: Partial = { + subplots: { + RSI: { + rsi_14: { + color: '#ff8000', + type: 'line', + }, + }, + }, + }; + expect(replaceTemplateColumns(template, reMapping)).toEqual(expected); + }); + it('Updates both main and subplot values', () => { + const { replaceTemplateColumns } = usePlotTemplates(); + const reMapping = { ema: 'ema_200', macd: 'macd_5m', macdsignal: 'macdsignal_5m' }; + const template: Partial = { + main_plot: { + ema: { + color: '#ff8000', + type: 'line', + }, + }, + subplots: { + MACD: { + macdsignal: { + color: '#ff8000', + type: 'line', + }, + macd: { + color: '#1370f4', + type: 'line', + }, + }, + }, + }; + const expected: Partial = { + main_plot: { + ema_200: { + color: '#ff8000', + type: 'line', + }, + }, + subplots: { + MACD: { + macdsignal_5m: { + color: '#ff8000', + type: 'line', + }, + macd_5m: { + color: '#1370f4', + type: 'line', + }, + }, + }, + }; + expect(replaceTemplateColumns(template, reMapping)).toEqual(expected); + }); +});