Skip to content

Commit

Permalink
test: fix check and required mouse move before click
Browse files Browse the repository at this point in the history
  • Loading branch information
markov00 committed Apr 7, 2021
1 parent 7242bb4 commit 7538dec
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions src/chart_types/xy_chart/state/chart_state.interactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1067,41 +1067,47 @@ function mouseOverTestSuite(scaleType: XScaleType) {
}

describe('Negative bars click and hover', () => {
const store = MockStore.default({ width: 100, height: 100, top: 0, left: 0 }, 'chartId');
const onElementClick = jest.fn<void, any[]>((): void => undefined);
const onElementClickCaller = createOnClickCaller();
store.subscribe(() => {
onElementClickCaller(store.getState());
let store: Store<GlobalChartState>;
let onElementClick: jest.Mock<void, any[]>;
beforeEach(() => {
store = MockStore.default({ width: 100, height: 100, top: 0, left: 0 }, 'chartId');
onElementClick = jest.fn<void, any[]>((): void => undefined);
const onElementClickCaller = createOnClickCaller();
store.subscribe(() => {
onElementClickCaller(store.getState());
});
MockStore.addSpecs(
[
MockGlobalSpec.settingsNoMargins({
onElementClick,
}),
MockSeriesSpec.bar({
xAccessor: 0,
yAccessors: [1],
data: [
[0, 10],
[1, -10],
[2, 10],
],
}),
],
store,
);
});
MockStore.addSpecs(
[
MockGlobalSpec.settingsNoMargins({
onElementClick,
}),
MockSeriesSpec.bar({
xAccessor: 0,
yAccessors: [1],
data: [
[0, 10],
[1, -10],
[2, 10],
],
}),
],
store,
);

test('highlight negative bars', () => {
store.dispatch(onPointerMove({ x: 50, y: 75 }, 0));
const highlightedGeoms = getHighlightedGeomsSelector(store.getState());
expect(highlightedGeoms.length).toBe(1);
expect(highlightedGeoms[0].value.datum).toEqual([1, -10]);
});
test('click negative bars', () => {
store.dispatch(onMouseDown({ x: 50, y: 75 }, 1));
store.dispatch(onPointerMove({ x: 50, y: 75 }, 0));
store.dispatch(onMouseDown({ x: 50, y: 75 }, 100));
store.dispatch(onMouseUp({ x: 50, y: 75 }, 200));

expect(onElementClick).toBeCalled();
const callArgs = onElementClick.mock.calls[0][0];
expect(callArgs[0].datum).toEqual([1, -10]);
expect(callArgs[0][0].datum).toEqual([1, -10]);
});
});

0 comments on commit 7538dec

Please sign in to comment.