Skip to content

Commit

Permalink
Finish writing resize container callback tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davismcphee committed Sep 15, 2022
1 parent 5a6a0c3 commit 607ddce
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/components/resizable_container/resizable_container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe('EuiResizableContainer', () => {
expect(onResizeEnd).toHaveBeenCalledTimes(2);
});

test('onResizeStart and onResizeEnd are only called for the correct keyboard events', () => {
test('onResizeStart and onResizeEnd are called only for the correct keyboard events', () => {
const { button, onResizeStart, onResizeEnd } = mountWithCallbacks();
button.simulate('keydown', { key: keys.ARROW_DOWN });
expect(onResizeStart).toHaveBeenCalledTimes(0);
Expand All @@ -284,4 +284,44 @@ describe('EuiResizableContainer', () => {
button.simulate('keyup', { key: keys.ARROW_RIGHT });
expect(onResizeEnd).toHaveBeenCalledTimes(1);
});

test('onResizeStart and onResizeEnd are called correctly when switching resize direction with the keyboard', () => {
const { button, onResizeStart, onResizeEnd } = mountWithCallbacks();
button.simulate('keydown', { key: keys.ARROW_RIGHT });
expect(onResizeStart).toHaveBeenCalledTimes(1);
expect(onResizeStart).toHaveBeenLastCalledWith('key');
button.simulate('keydown', { key: keys.ARROW_LEFT });
expect(onResizeEnd).toHaveBeenCalledTimes(1);
expect(onResizeStart).toHaveBeenCalledTimes(2);
expect(onResizeStart).toHaveBeenLastCalledWith('key');
button.simulate('keyup', { key: keys.ARROW_RIGHT });
expect(onResizeEnd).toHaveBeenCalledTimes(1);
button.simulate('keyup', { key: keys.ARROW_LEFT });
expect(onResizeEnd).toHaveBeenCalledTimes(2);
});

test('onResizeEnd is called before starting a new resize if a keyboard resize is triggered while a pointer resize is in progress', () => {
const {
container,
button,
onResizeStart,
onResizeEnd,
} = mountWithCallbacks();
button.simulate('mousedown', {
pageX: 0,
pageY: 0,
clientX: 0,
clientY: 0,
});
expect(onResizeStart).toHaveBeenCalledTimes(1);
expect(onResizeStart).toHaveBeenLastCalledWith('pointer');
button.simulate('keydown', { key: keys.ARROW_RIGHT });
expect(onResizeEnd).toHaveBeenCalledTimes(1);
expect(onResizeStart).toHaveBeenCalledTimes(2);
expect(onResizeStart).toHaveBeenLastCalledWith('key');
container.simulate('mouseup');
expect(onResizeEnd).toHaveBeenCalledTimes(1);
button.simulate('keyup', { key: keys.ARROW_RIGHT });
expect(onResizeEnd).toHaveBeenCalledTimes(2);
});
});

0 comments on commit 607ddce

Please sign in to comment.