|
1 |
| -import { isLine, isColumn, getGeometryOption, getDefaultYAxis } from '../../../../../src/plots/dual-axes/util/option'; |
2 |
| - |
| 1 | +import { |
| 2 | + isLine, |
| 3 | + isColumn, |
| 4 | + getGeometryOption, |
| 5 | + getCompatibleYAxis, |
| 6 | + getYAxisWithDefault, |
| 7 | +} from '../../../../../src/plots/dual-axes/util/option'; |
3 | 8 | import { AxisType } from '../../../../../src/plots/dual-axes/types';
|
4 | 9 |
|
5 | 10 | const DEFAULT_LEFT_YAXIS_CONFIG = {
|
@@ -32,42 +37,56 @@ describe('DualAxes option', () => {
|
32 | 37 | expect(isColumn({ geometry: 'column' })).toBe(true);
|
33 | 38 | });
|
34 | 39 |
|
35 |
| - it('getDefaultYAxis', () => { |
36 |
| - expect(getDefaultYAxis(['yField1', 'yField2'], undefined)).toEqual({ |
37 |
| - yField1: DEFAULT_LEFT_YAXIS_CONFIG, |
38 |
| - yField2: DEFAULT_RIGHT_YAXIS_CONFIG, |
| 40 | + it('getCompatibleYAxis', () => { |
| 41 | + expect(getCompatibleYAxis(['yField1', 'yField2'], undefined)).toEqual({ |
| 42 | + yField1: undefined, |
| 43 | + yField2: undefined, |
39 | 44 | });
|
40 |
| - }); |
41 |
| - it('yAxis option', () => { |
42 |
| - expect(getDefaultYAxis(['yField1', 'yField2'], {})).toEqual({ |
43 |
| - yField1: DEFAULT_LEFT_YAXIS_CONFIG, |
44 |
| - yField2: DEFAULT_RIGHT_YAXIS_CONFIG, |
| 45 | + |
| 46 | + expect(getCompatibleYAxis(['yField1', 'yField2'], [{ nice: false }])).toEqual({ |
| 47 | + yField1: { nice: false }, |
| 48 | + yField2: undefined, |
45 | 49 | });
|
46 | 50 |
|
47 |
| - // @ts-ignore |
48 |
| - expect(getDefaultYAxis(['yField1', 'yField2'], { yField1: { a: 1 }, yField2: false })).toEqual({ |
49 |
| - yField1: { |
50 |
| - ...DEFAULT_LEFT_YAXIS_CONFIG, |
51 |
| - a: 1, |
52 |
| - }, |
53 |
| - yField2: false, |
| 51 | + expect(getCompatibleYAxis(['yField1', 'yField2'], [false])).toEqual({ |
| 52 | + yField1: false, |
| 53 | + yField2: undefined, |
54 | 54 | });
|
55 | 55 |
|
56 |
| - expect(getDefaultYAxis(['yField1', 'yField2'], [])).toEqual({ |
57 |
| - yField1: DEFAULT_LEFT_YAXIS_CONFIG, |
58 |
| - yField2: DEFAULT_RIGHT_YAXIS_CONFIG, |
| 56 | + expect(getCompatibleYAxis(['yField1', 'yField2'], { yField1: { nice: true } })).toEqual({ |
| 57 | + yField1: { nice: true }, |
| 58 | + yField2: undefined, |
59 | 59 | });
|
60 | 60 |
|
61 |
| - // @ts-ignore |
62 |
| - expect(getDefaultYAxis(['yField1', 'yField2'], [{ a: 1 }, false])).toEqual({ |
63 |
| - yField1: { |
64 |
| - ...DEFAULT_LEFT_YAXIS_CONFIG, |
65 |
| - a: 1, |
66 |
| - }, |
| 61 | + expect(getCompatibleYAxis(['yField1', 'yField2'], { yField1: { nice: true }, yField2: false })).toEqual({ |
| 62 | + yField1: { nice: true }, |
67 | 63 | yField2: false,
|
68 | 64 | });
|
69 | 65 | });
|
70 | 66 |
|
| 67 | + it('getDefaultYAxis', () => { |
| 68 | + expect(getYAxisWithDefault(undefined, AxisType.Left)).toEqual(DEFAULT_LEFT_YAXIS_CONFIG); |
| 69 | + expect(getYAxisWithDefault({}, AxisType.Left)).toEqual(DEFAULT_LEFT_YAXIS_CONFIG); |
| 70 | + expect(getYAxisWithDefault(false, AxisType.Left)).toBe(false); |
| 71 | + expect(getYAxisWithDefault({ type: 'cat' }, AxisType.Left)).toEqual({ ...DEFAULT_LEFT_YAXIS_CONFIG, type: 'cat' }); |
| 72 | + expect(getYAxisWithDefault({ nice: false }, AxisType.Left)).toEqual({ ...DEFAULT_LEFT_YAXIS_CONFIG, nice: false }); |
| 73 | + |
| 74 | + expect(getYAxisWithDefault(undefined, AxisType.Right)).toEqual(DEFAULT_RIGHT_YAXIS_CONFIG); |
| 75 | + expect(getYAxisWithDefault({}, AxisType.Right)).toEqual(DEFAULT_RIGHT_YAXIS_CONFIG); |
| 76 | + expect(getYAxisWithDefault(false, AxisType.Right)).toBe(false); |
| 77 | + expect(getYAxisWithDefault({ type: 'cat' }, AxisType.Right)).toEqual({ |
| 78 | + ...DEFAULT_RIGHT_YAXIS_CONFIG, |
| 79 | + type: 'cat', |
| 80 | + }); |
| 81 | + expect(getYAxisWithDefault({ nice: false }, AxisType.Right)).toEqual({ |
| 82 | + ...DEFAULT_RIGHT_YAXIS_CONFIG, |
| 83 | + nice: false, |
| 84 | + }); |
| 85 | + |
| 86 | + // @ts-ignore |
| 87 | + expect(getYAxisWithDefault({ type: 'log' }, 'xxx')).toEqual({ type: 'log' }); |
| 88 | + }); |
| 89 | + |
71 | 90 | it('getGeometryOption', () => {
|
72 | 91 | expect(getGeometryOption('test', 'yField1', undefined, AxisType.Left)).toEqual({
|
73 | 92 | geometry: 'line',
|
|
0 commit comments