|
| 1 | +/** |
| 2 | + * Datart |
| 3 | + * |
| 4 | + * Copyright 2021 |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +import { |
| 20 | + getAutoFunnelTopPosition, |
| 21 | + getIntervalShow, |
| 22 | + hadAxisLabelOverflowConfig, |
| 23 | +} from '../chartHelper'; |
| 24 | + |
| 25 | +describe('test getIntervalShow return boolean', () => { |
| 26 | + it('getIntervalShow return true when arg is number', () => { |
| 27 | + expect(getIntervalShow(0)).toBeTruthy(); |
| 28 | + }); |
| 29 | + |
| 30 | + it('1. getIntervalShow return true when arg is string', () => { |
| 31 | + expect(getIntervalShow('0')).toBeTruthy(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('getIntervalShow return false when arg is "auto"', () => { |
| 35 | + expect(getIntervalShow('auto')).toBeFalsy(); |
| 36 | + }); |
| 37 | + |
| 38 | + // Interval 已经经过处理,不可能为 undefined |
| 39 | + it('getIntervalShow return false when arg is null', () => { |
| 40 | + expect(getIntervalShow(null)).toBeFalsy(); |
| 41 | + }); |
| 42 | +}); |
| 43 | + |
| 44 | +describe('test hadAxisLabelOverflowConfig return boolean', () => { |
| 45 | + const axisLabel = { |
| 46 | + overflow: 'break', |
| 47 | + interval: 0, |
| 48 | + show: true, |
| 49 | + }; |
| 50 | + |
| 51 | + const getOptions = (label: any = null, horizon = false) => ({ |
| 52 | + [horizon ? 'yAxis' : 'xAxis']: label ? [label] : null, |
| 53 | + }); |
| 54 | + |
| 55 | + it('hadAxisLabelOverflowConfig return false when options is null', () => { |
| 56 | + expect(hadAxisLabelOverflowConfig(getOptions())).toBeFalsy(); |
| 57 | + }); |
| 58 | + |
| 59 | + it('hadAxisLabelOverflowConfig return false when options.xAxis[0].axisLabel is null', () => { |
| 60 | + expect(hadAxisLabelOverflowConfig(getOptions({}))).toBeFalsy(); |
| 61 | + }); |
| 62 | + |
| 63 | + it('hadAxisLabelOverflowConfig return false when get options.yAxis opts', () => { |
| 64 | + expect(hadAxisLabelOverflowConfig(getOptions({}, true))).toBeFalsy(); |
| 65 | + }); |
| 66 | + |
| 67 | + it('hadAxisLabelOverflowConfig return true when get options.xAxis', () => { |
| 68 | + expect(hadAxisLabelOverflowConfig(getOptions({ axisLabel }))).toBeTruthy(); |
| 69 | + }); |
| 70 | + |
| 71 | + it('hadAxisLabelOverflowConfig return false when get options.yAxis opts', () => { |
| 72 | + expect(hadAxisLabelOverflowConfig(getOptions({}, true))).toBeFalsy(); |
| 73 | + }); |
| 74 | + |
| 75 | + it('hadAxisLabelOverflowConfig return true when get options.yAxis', () => { |
| 76 | + expect( |
| 77 | + hadAxisLabelOverflowConfig(getOptions({ axisLabel }, true), true), |
| 78 | + ).toBeTruthy(); |
| 79 | + }); |
| 80 | + |
| 81 | + it('hadAxisLabelOverflowConfig return false when show false', () => { |
| 82 | + expect( |
| 83 | + hadAxisLabelOverflowConfig( |
| 84 | + getOptions({ |
| 85 | + axisLabel: { |
| 86 | + axisLabel, |
| 87 | + show: false, |
| 88 | + }, |
| 89 | + }), |
| 90 | + ), |
| 91 | + ).toBeFalsy(); |
| 92 | + }); |
| 93 | + |
| 94 | + it('hadAxisLabelOverflowConfig return false when interval "auto"', () => { |
| 95 | + expect( |
| 96 | + hadAxisLabelOverflowConfig( |
| 97 | + getOptions({ |
| 98 | + axisLabel: { |
| 99 | + axisLabel, |
| 100 | + interval: 'auto', |
| 101 | + }, |
| 102 | + }), |
| 103 | + ), |
| 104 | + ).toBeFalsy(); |
| 105 | + }); |
| 106 | + |
| 107 | + it('hadAxisLabelOverflowConfig return false when overflow null"', () => { |
| 108 | + expect( |
| 109 | + hadAxisLabelOverflowConfig( |
| 110 | + getOptions({ |
| 111 | + axisLabel: { |
| 112 | + axisLabel, |
| 113 | + overflow: null, |
| 114 | + }, |
| 115 | + }), |
| 116 | + ), |
| 117 | + ).toBeFalsy(); |
| 118 | + }); |
| 119 | +}); |
| 120 | + |
| 121 | +describe('test getAutoFunnelTopPosition return number', () => { |
| 122 | + it('getAutoFunnelTopPosition return 8 when legendPos is not left or right', () => { |
| 123 | + expect( |
| 124 | + getAutoFunnelTopPosition({ |
| 125 | + legendPos: 'top', |
| 126 | + } as any), |
| 127 | + ).toEqual(8); |
| 128 | + }); |
| 129 | + it('getAutoFunnelTopPosition return 16 when legendPos is left or right and height is 0 or null', () => { |
| 130 | + expect( |
| 131 | + getAutoFunnelTopPosition({ |
| 132 | + legendPos: 'left', |
| 133 | + } as any), |
| 134 | + ).toEqual(16); |
| 135 | + |
| 136 | + expect( |
| 137 | + getAutoFunnelTopPosition({ |
| 138 | + legendPos: 'left', |
| 139 | + height: 0, |
| 140 | + } as any), |
| 141 | + ).toEqual(16); |
| 142 | + }); |
| 143 | + |
| 144 | + it('getAutoFunnelTopPosition return 16 when sort is ascending', () => { |
| 145 | + expect( |
| 146 | + getAutoFunnelTopPosition({ |
| 147 | + legendPos: 'left', |
| 148 | + height: 32, |
| 149 | + sort: 'ascending', |
| 150 | + } as any), |
| 151 | + ).toEqual(16); |
| 152 | + }); |
| 153 | + |
| 154 | + it('getAutoFunnelTopPosition return 16 when chart.getHeight return null/0', () => { |
| 155 | + expect( |
| 156 | + getAutoFunnelTopPosition({ |
| 157 | + legendPos: 'left', |
| 158 | + height: 32, |
| 159 | + sort: 'none', |
| 160 | + chart: { |
| 161 | + getHeight: () => 0, |
| 162 | + }, |
| 163 | + } as any), |
| 164 | + ).toEqual(16); |
| 165 | + }); |
| 166 | + |
| 167 | + it('getAutoFunnelTopPosition return chart.getHeight - height - marginBottom', () => { |
| 168 | + expect( |
| 169 | + getAutoFunnelTopPosition({ |
| 170 | + legendPos: 'left', |
| 171 | + height: 100, |
| 172 | + sort: 'none', |
| 173 | + chart: { |
| 174 | + getHeight: () => 800, |
| 175 | + }, |
| 176 | + } as any), |
| 177 | + ).toEqual(800 - 100 - 24); |
| 178 | + }); |
| 179 | +}); |
0 commit comments