|
| 1 | +import {Numeric} from '../components/fields'; |
| 2 | +import NumericInput from '../components/widgets/NumericInputStatefulWrapper'; |
| 3 | +import React from 'react'; |
| 4 | +import {EDITOR_ACTIONS} from '../constants'; |
| 5 | +import {TestEditor, fixtures} from '../lib/test-utils'; |
| 6 | +import { |
| 7 | + connectAxesToLayout, |
| 8 | + connectLayoutToPlot, |
| 9 | + connectToContainer, |
| 10 | + connectTraceToPlot, |
| 11 | +} from '../lib'; |
| 12 | +import {mount} from 'enzyme'; |
| 13 | + |
| 14 | +describe('Plot Connection', () => { |
| 15 | + it('can connect Field directly with full connection pipeline', () => { |
| 16 | + const onUpdate = jest.fn(); |
| 17 | + const fixtureProps = fixtures.scatter({layout: {xaxis: {range: [0, 10]}}}); |
| 18 | + const LayoutAxesNumeric = connectLayoutToPlot( |
| 19 | + connectAxesToLayout(connectToContainer(Numeric)) |
| 20 | + ); |
| 21 | + mount( |
| 22 | + <TestEditor {...{...fixtureProps, onUpdate}}> |
| 23 | + <LayoutAxesNumeric label="Min" attr="range[0]" /> |
| 24 | + </TestEditor> |
| 25 | + ) |
| 26 | + .find('[attr="range[0]"]') |
| 27 | + .find(NumericInput) |
| 28 | + .find('.js-numeric-increase') |
| 29 | + .simulate('click'); |
| 30 | + |
| 31 | + expect(onUpdate).toBeCalled(); |
| 32 | + const update = onUpdate.mock.calls[0][0]; |
| 33 | + const {type, payload} = update; |
| 34 | + expect(type).toBe(EDITOR_ACTIONS.UPDATE_LAYOUT); |
| 35 | + expect(payload).toEqual({update: {'xaxis.range[0]': 1}}); |
| 36 | + }); |
| 37 | + |
| 38 | + it('can connect to layout when connected within trace context', () => { |
| 39 | + const onUpdate = jest.fn(); |
| 40 | + const fixtureProps = fixtures.scatter({layout: {width: 10}}); |
| 41 | + const TraceLayoutNumeric = connectTraceToPlot( |
| 42 | + connectLayoutToPlot(connectToContainer(Numeric)) |
| 43 | + ); |
| 44 | + mount( |
| 45 | + <TestEditor {...{...fixtureProps, onUpdate}}> |
| 46 | + <TraceLayoutNumeric traceIndex={0} label="Width" attr="width" /> |
| 47 | + </TestEditor> |
| 48 | + ) |
| 49 | + .find('[attr="width"]') |
| 50 | + .find(NumericInput) |
| 51 | + .find('.js-numeric-increase') |
| 52 | + .simulate('click'); |
| 53 | + |
| 54 | + expect(onUpdate).toBeCalled(); |
| 55 | + const update = onUpdate.mock.calls[0][0]; |
| 56 | + const {type, payload} = update; |
| 57 | + expect(type).toBe(EDITOR_ACTIONS.UPDATE_LAYOUT); |
| 58 | + expect(payload).toEqual({update: {width: 11}}); |
| 59 | + }); |
| 60 | +}); |
0 commit comments