|
| 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 | +import React from 'react'; |
| 20 | +import { createStore, Store } from 'redux'; |
| 21 | +import { Provider } from 'react-redux'; |
| 22 | +import { mount } from 'enzyme'; |
| 23 | + |
| 24 | +import { chartStoreReducer, GlobalChartState } from '../../../state/chart_state'; |
| 25 | +import { SpecsParser } from '../../../specs/specs_parser'; |
| 26 | +import { LineSeries } from './line_series'; |
| 27 | +import { LineAnnotation, AnnotationDomainTypes } from '../../../specs'; |
| 28 | + |
| 29 | +function LineAnnotationChart(props: { chartStore: Store<GlobalChartState> }) { |
| 30 | + return ( |
| 31 | + <Provider store={props.chartStore}> |
| 32 | + <SpecsParser> |
| 33 | + <LineSeries |
| 34 | + id="line" |
| 35 | + data={[ |
| 36 | + [1585126720460, 0], |
| 37 | + [1585126780460, 22], |
| 38 | + [1585126840460, 100], |
| 39 | + [1585126900460, 333], |
| 40 | + [1585126960460, 444], |
| 41 | + ]} |
| 42 | + xAccessor={0} |
| 43 | + yAccessors={[1]} |
| 44 | + /> |
| 45 | + <LineAnnotation |
| 46 | + id="threshold" |
| 47 | + domainType={AnnotationDomainTypes.YDomain} |
| 48 | + dataValues={[{ dataValue: 120, details: 'threshold' }]} |
| 49 | + /> |
| 50 | + </SpecsParser> |
| 51 | + </Provider> |
| 52 | + ); |
| 53 | +} |
| 54 | + |
| 55 | +describe('Line annotation', () => { |
| 56 | + it('Should always be available on the on every render', () => { |
| 57 | + const storeReducer = chartStoreReducer('chart_id'); |
| 58 | + const chartStore = createStore(storeReducer); |
| 59 | + const wrapper = mount(<LineAnnotationChart chartStore={chartStore} />); |
| 60 | + expect(chartStore.getState().specs['threshold']).toBeDefined(); |
| 61 | + wrapper.setProps({}); |
| 62 | + expect(chartStore.getState().specs['threshold']).toBeDefined(); |
| 63 | + }); |
| 64 | +}); |
0 commit comments