|
9 | 9 | * OF ANY KIND, either express or implied. See the License for the specific language |
10 | 10 | * governing permissions and limitations under the License. |
11 | 11 | */ |
12 | | -import { FILTERED_TABLE } from '@spectrum-charts/constants'; |
| 12 | +import { DEFAULT_LEGEND_COLUMN_PADDING, DEFAULT_LEGEND_SYMBOL_WIDTH, FILTERED_TABLE } from '@spectrum-charts/constants'; |
13 | 13 | import { spectrumColors } from '@spectrum-charts/themes'; |
14 | 14 |
|
15 | 15 | import { defaultLegendOptions } from './legendTestUtils'; |
16 | 16 | import { |
17 | 17 | getClickEncodings, |
| 18 | + getColumns, |
18 | 19 | getHiddenSeriesColorRule, |
19 | 20 | getSymbolEncodings, |
20 | 21 | getSymbolType, |
@@ -128,3 +129,55 @@ describe('getHiddenSeriesColorRule()', () => { |
128 | 129 | expect(colorRules[0].test).toContain('hiddenSeries'); |
129 | 130 | }); |
130 | 131 | }); |
| 132 | + |
| 133 | +describe('getColumns()', () => { |
| 134 | + test('should return undefined for left position', () => { |
| 135 | + expect(getColumns('left')).toBeUndefined(); |
| 136 | + }); |
| 137 | + |
| 138 | + test('should return undefined for right position', () => { |
| 139 | + expect(getColumns('right')).toBeUndefined(); |
| 140 | + }); |
| 141 | + |
| 142 | + test('should return default signal for top position without labelLimit', () => { |
| 143 | + expect(getColumns('top')).toEqual({ signal: 'floor(width / 220)' }); |
| 144 | + }); |
| 145 | + |
| 146 | + test('should return default signal for bottom position without labelLimit', () => { |
| 147 | + expect(getColumns('bottom')).toEqual({ signal: 'floor(width / 220)' }); |
| 148 | + }); |
| 149 | + |
| 150 | + test('should return default signal when labelLimit is undefined', () => { |
| 151 | + expect(getColumns('top', undefined)).toEqual({ signal: 'floor(width / 220)' }); |
| 152 | + }); |
| 153 | + |
| 154 | + test('should return default signal when labelLimit is 0', () => { |
| 155 | + expect(getColumns('bottom', 0)).toEqual({ signal: 'floor(width / 220)' }); |
| 156 | + }); |
| 157 | + |
| 158 | + test('should return default signal when labelLimit is negative', () => { |
| 159 | + expect(getColumns('top', -10)).toEqual({ signal: 'floor(width / 220)' }); |
| 160 | + }); |
| 161 | + |
| 162 | + test('should calculate columns based on labelLimit when provided', () => { |
| 163 | + const labelLimit = 100; |
| 164 | + const expectedItemWidth = labelLimit + DEFAULT_LEGEND_SYMBOL_WIDTH + DEFAULT_LEGEND_COLUMN_PADDING; |
| 165 | + const expectedSignal = `max(1, floor(width / ${expectedItemWidth}))`; |
| 166 | + |
| 167 | + expect(getColumns('top', labelLimit)).toEqual({ signal: expectedSignal }); |
| 168 | + }); |
| 169 | + |
| 170 | + test('should calculate columns with different labelLimit values', () => { |
| 171 | + const labelLimit50 = 50; |
| 172 | + const expectedItemWidth50 = 50 + DEFAULT_LEGEND_SYMBOL_WIDTH + DEFAULT_LEGEND_COLUMN_PADDING; |
| 173 | + expect(getColumns('bottom', labelLimit50)).toEqual({ |
| 174 | + signal: `max(1, floor(width / ${expectedItemWidth50}))` |
| 175 | + }); |
| 176 | + |
| 177 | + const labelLimit200 = 200; |
| 178 | + const expectedItemWidth200 = 200 + DEFAULT_LEGEND_SYMBOL_WIDTH + DEFAULT_LEGEND_COLUMN_PADDING; // 200 + 16 + 20 = 236 |
| 179 | + expect(getColumns('top', labelLimit200)).toEqual({ |
| 180 | + signal: `max(1, floor(width / ${expectedItemWidth200}))` |
| 181 | + }); |
| 182 | + }); |
| 183 | +}); |
0 commit comments