|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * 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, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import { MockGlobalSpec, MockSeriesSpec } from '../../../../mocks/specs/specs'; |
| 21 | +import { MockStore } from '../../../../mocks/store/store'; |
| 22 | +import { DEFAULT_GLOBAL_ID } from '../../utils/specs'; |
| 23 | +import { computeSeriesGeometriesSelector } from './compute_series_geometries'; |
| 24 | +import { getScaleConfigsFromSpecsSelector } from './get_api_scale_configs'; |
| 25 | + |
| 26 | +describe('GroupIds and useDefaultGroupId', () => { |
| 27 | + it('use the specified useDefaultGroupId to compute scale configs', () => { |
| 28 | + const store = MockStore.default(); |
| 29 | + MockStore.addSpecs( |
| 30 | + [ |
| 31 | + MockSeriesSpec.bar({ |
| 32 | + groupId: 'other', |
| 33 | + useDefaultGroupDomain: 'a different one', |
| 34 | + }), |
| 35 | + ], |
| 36 | + store, |
| 37 | + ); |
| 38 | + const scaleConfigs = getScaleConfigsFromSpecsSelector(store.getState()); |
| 39 | + expect(scaleConfigs.y['a different one']).toBeDefined(); |
| 40 | + }); |
| 41 | + |
| 42 | + it('have 2 different y domains with 2 groups', () => { |
| 43 | + const store = MockStore.default(); |
| 44 | + MockStore.addSpecs( |
| 45 | + [ |
| 46 | + MockSeriesSpec.bar({ id: 'one' }), |
| 47 | + MockSeriesSpec.bar({ |
| 48 | + id: 'two', |
| 49 | + groupId: 'other', |
| 50 | + useDefaultGroupDomain: 'a different one', |
| 51 | + }), |
| 52 | + ], |
| 53 | + store, |
| 54 | + ); |
| 55 | + const scaleConfigs = getScaleConfigsFromSpecsSelector(store.getState()); |
| 56 | + expect(Object.keys(scaleConfigs.y)).toHaveLength(2); |
| 57 | + expect(scaleConfigs.y['a different one']).toBeDefined(); |
| 58 | + expect(scaleConfigs.y[DEFAULT_GLOBAL_ID]).toBeDefined(); |
| 59 | + }); |
| 60 | + |
| 61 | + it('have 2 different y domains with 3 groups', () => { |
| 62 | + const store = MockStore.default({ width: 120, height: 100, left: 0, top: 0 }); |
| 63 | + MockStore.addSpecs( |
| 64 | + [ |
| 65 | + MockGlobalSpec.settingsNoMargins(), |
| 66 | + MockSeriesSpec.bar({ id: 'one', data: [{ x: 1, y: 10 }] }), |
| 67 | + MockSeriesSpec.bar({ |
| 68 | + id: 'two', |
| 69 | + groupId: 'other', |
| 70 | + useDefaultGroupDomain: 'a different one', |
| 71 | + data: [{ x: 1, y: 10 }], |
| 72 | + }), |
| 73 | + MockSeriesSpec.bar({ |
| 74 | + id: 'three', |
| 75 | + groupId: 'another again', |
| 76 | + useDefaultGroupDomain: 'a different one', |
| 77 | + data: [{ x: 1, y: 10 }], |
| 78 | + }), |
| 79 | + ], |
| 80 | + store, |
| 81 | + ); |
| 82 | + const scaleConfigs = getScaleConfigsFromSpecsSelector(store.getState()); |
| 83 | + expect(Object.keys(scaleConfigs.y)).toHaveLength(2); |
| 84 | + expect(scaleConfigs.y['a different one']).toBeDefined(); |
| 85 | + expect(scaleConfigs.y[DEFAULT_GLOBAL_ID]).toBeDefined(); |
| 86 | + |
| 87 | + const geoms = computeSeriesGeometriesSelector(store.getState()); |
| 88 | + const { bars } = geoms.geometries; |
| 89 | + expect(bars).toHaveLength(3); |
| 90 | + expect(bars[0].value[0].width).toBe(40); |
| 91 | + expect(bars[1].value[0].width).toBe(40); |
| 92 | + expect(bars[2].value[0].width).toBe(40); |
| 93 | + }); |
| 94 | +}); |
0 commit comments