Skip to content

Commit

Permalink
test: update tests for resizable button
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <tygao@amazon.com>
  • Loading branch information
raintygao committed Mar 4, 2024
1 parent 8cf8206 commit ffed335
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test('it should be vertical when docked mode is takeover', () => {
expect(component).toMatchSnapshot();
});

test('it should emit onResize with new flyout size when drag and horizontal', () => {
test('it should emit onResize with new flyout size when docked right and drag and horizontal', () => {
const windowEvents = storeWindowEvents();

const onResize = jest.fn();
Expand All @@ -60,6 +60,22 @@ test('it should emit onResize with new flyout size when drag and horizontal', ()
expect(component).toMatchSnapshot();
});

test('it should emit onResize with new flyout size when docked left and drag and horizontal', () => {
const windowEvents = storeWindowEvents();

const onResize = jest.fn();
const newProps = { ...props, onResize, dockedMode: SIDECAR_DOCKED_MODE.LEFT };
const component = shallow(<ResizableButton {...newProps} />);
const resizer = component.find(`[data-test-subj~="resizableButton"]`).first();
expect(onResize).not.toHaveBeenCalled();
resizer.simulate('mousedown', { clientX: 0, pageX: 0, pageY: 0 });
windowEvents?.mousemove({ clientX: 1000, pageX: 0, pageY: 0 });
windowEvents?.mouseup();
const newSize = 1000 + DEFAULT_FLYOUT_SIZE;
expect(onResize).toHaveBeenCalledWith(newSize);
expect(component).toMatchSnapshot();
});

test('it should emit onResize with new flyout size when drag and vertical', () => {
const windowEvents = storeWindowEvents();

Expand Down
10 changes: 10 additions & 0 deletions src/core/public/overlays/sidecar/sidecar_service.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ describe('SidecarService', () => {
const content = mount(mockReactDomRender.mock.calls[0][0]);
expect(content.html()).toMatchSnapshot();
});

it('does not unmount if targetDom is null', async () => {
const sidecarRef = new SidecarService().start({ i18n: i18nMock, targetDomElement: null });
const ref = sidecarRef.open(mountText('Sidecar content'), options);
const content = mount(mockReactDomRender.mock.calls[0][0]);
expect(content.html()).toMatchSnapshot();
await ref.close();
expect(mockReactDomUnmount).not.toHaveBeenCalled();
});

describe('with a currently active sidecar', () => {
let ref1: OverlayRef;
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/overlays/sidecar/sidecar_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export interface OverlaySidecarOpenOptions {

interface StartDeps {
i18n: I18nStart;
targetDomElement: Element;
targetDomElement: Element | null;
}

export enum SIDECAR_DOCKED_MODE {
Expand Down

0 comments on commit ffed335

Please sign in to comment.