|
1 | 1 | import { ChartOptions } from '../Chart.types';
|
2 | 2 |
|
3 |
| -import { addSeries, removeSeries, updateOptions } from './updateUtils'; |
| 3 | +import { |
| 4 | + getOptionsToUpdateWithAddedSeries, |
| 5 | + getOptionsToUpdateWithRemovedSeries, |
| 6 | +} from './updateUtils'; |
4 | 7 |
|
5 | 8 | describe('@lg-charts/core/Chart/hooks/updateUtils', () => {
|
6 |
| - test('addSeries should add a series to the chart options', () => { |
| 9 | + test('getOptionsToUpdateWithAddedSeries should return options with an added series', () => { |
7 | 10 | const currentOptions: Partial<ChartOptions> = {
|
8 |
| - series: [{ name: 'series1' }], |
| 11 | + series: [{ id: 'series-1' }], |
9 | 12 | };
|
10 |
| - const newSeriesName = 'series2'; |
11 |
| - const data = { name: newSeriesName }; |
12 |
| - const updatedOptions = addSeries(currentOptions, data); |
| 13 | + const newSeriesId = 'series-2'; |
| 14 | + const data = { id: newSeriesId }; |
| 15 | + const updatedOptions = getOptionsToUpdateWithAddedSeries( |
| 16 | + currentOptions, |
| 17 | + data, |
| 18 | + ); |
13 | 19 | expect(updatedOptions.series).toHaveLength(2);
|
14 |
| - expect(updatedOptions.series?.[1].name).toBe(newSeriesName); |
| 20 | + expect(updatedOptions.series?.[1].id).toBe(newSeriesId); |
15 | 21 | });
|
16 | 22 |
|
17 |
| - test('addSeries should not add a series if a chart with the same name exists', () => { |
| 23 | + test('getOptionsToUpdateWithAddedSeries should return options without an added series if a series with the same id exists', () => { |
18 | 24 | const currentOptions: Partial<ChartOptions> = {
|
19 |
| - series: [{ name: 'series1' }], |
| 25 | + series: [{ id: 'series-1' }], |
20 | 26 | };
|
21 |
| - const newSeriesName = 'series1'; |
22 |
| - const data = { name: newSeriesName }; |
23 |
| - const updatedOptions = addSeries(currentOptions, data); |
| 27 | + const existingSeriesId = 'series-1'; |
| 28 | + const data = { id: existingSeriesId }; |
| 29 | + const updatedOptions = getOptionsToUpdateWithAddedSeries( |
| 30 | + currentOptions, |
| 31 | + data, |
| 32 | + ); |
24 | 33 | expect(updatedOptions.series).toHaveLength(1);
|
25 |
| - expect(updatedOptions.series?.[0].name).toBe(newSeriesName); |
| 34 | + expect(updatedOptions.series?.[0].id).toBe(existingSeriesId); |
26 | 35 | });
|
27 | 36 |
|
28 |
| - test('removeSeries should remove a series from the chart options', () => { |
| 37 | + test('getOptionsToUpdateWithRemovedSeries should return options with a removed series', () => { |
29 | 38 | const currentOptions: Partial<ChartOptions> = {
|
30 |
| - series: [{ name: 'series1' }, { name: 'series2' }], |
| 39 | + series: [{ id: 'series-1' }, { id: 'series-2' }], |
31 | 40 | };
|
32 |
| - const seriesName1 = 'series1'; |
33 |
| - const seriesName2 = 'series2'; |
34 |
| - const updatedOptions = removeSeries(currentOptions, seriesName1); |
| 41 | + const seriesId1 = 'series-1'; |
| 42 | + const seriesId2 = 'series-2'; |
| 43 | + const updatedOptions = getOptionsToUpdateWithRemovedSeries( |
| 44 | + currentOptions, |
| 45 | + seriesId1, |
| 46 | + ); |
35 | 47 | expect(updatedOptions.series).toHaveLength(1);
|
36 |
| - expect(updatedOptions.series?.[0].name).toBe(seriesName2); |
37 |
| - }); |
38 |
| - |
39 |
| - /** |
40 |
| - * Tests that option updates don't overwrite the entire chart options object. |
41 |
| - */ |
42 |
| - test('updateOptions should merge chart options non-destructively', () => { |
43 |
| - const currentOptions: Partial<ChartOptions> = { |
44 |
| - xAxis: { |
45 |
| - show: true, |
46 |
| - splitLine: { |
47 |
| - show: true, |
48 |
| - }, |
49 |
| - }, |
50 |
| - }; |
51 |
| - const updatedOptions = updateOptions(currentOptions, { |
52 |
| - xAxis: { |
53 |
| - show: false, // This should only update the show property and not other properties |
54 |
| - }, |
55 |
| - grid: { |
56 |
| - show: true, |
57 |
| - }, |
58 |
| - }); |
59 |
| - // @ts-ignore: Property 'show' does not exist on type 'Arrayable<AriaOption>'. |
60 |
| - expect(updatedOptions?.xAxis?.show).toBe(false); |
61 |
| - // @ts-ignore: Property 'show' does not exist on type 'Arrayable<AriaOption>'. |
62 |
| - expect(updatedOptions?.xAxis?.splitLine?.show).toBe(true); |
63 |
| - // @ts-ignore: Property 'show' does not exist on type 'Arrayable<GridOption>'. |
64 |
| - expect(updatedOptions?.grid?.show).toBe(true); |
| 48 | + expect(updatedOptions.series?.[0].id).toBe(seriesId2); |
65 | 49 | });
|
66 | 50 | });
|
0 commit comments