Skip to content

Commit

Permalink
Merge pull request #2724 from glific/bug/resizer
Browse files Browse the repository at this point in the history
Fixed issue with resizer
  • Loading branch information
mdshamoon authored Feb 5, 2024
2 parents 1264c6d + b9731e9 commit e137e75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/components/UI/Form/WhatsAppEditor/WhatsAppEditor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { render, fireEvent } from '@testing-library/react';
import { render, fireEvent, waitFor } from '@testing-library/react';
import draftJs, { EditorState, ContentState } from 'draft-js';
import { vi } from 'vitest';

import WhatsAppEditor from './WhatsAppEditor';

const mockHandleKeyCommand = vi.fn();

const mockObserve = vi.fn();
global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: mockObserve,
unobserve: vi.fn(),
disconnect: vi.fn(),
}));

vi.spyOn(draftJs, 'Editor').mockImplementation((props: any, _context: any) => {
const input: any = (
<input
Expand Down Expand Up @@ -51,10 +58,11 @@ describe('<WhatsAppEditor/>', () => {
expect(mockHandleKeyCommand).toHaveBeenCalled();
});

test('testing change size callback', () => {
const { getByTestId } = render(<WhatsAppEditor {...defaultProps(editorContent)} />);
fireEvent.click(getByTestId('resizer'));
expect(handleHeightChange).toHaveBeenCalled();
test('resize observer event is called', async () => {
render(<WhatsAppEditor {...defaultProps(editorContent)} />);
await waitFor(() => {
expect(mockObserve).toHaveBeenCalled();
});
});

// since we are mocking emoji mart picker we need to implement the following functionalities
Expand Down
6 changes: 4 additions & 2 deletions src/components/UI/Form/WhatsAppEditor/WhatsAppEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ export const WhatsAppEditor = ({
return getDefaultKeyBinding(e);
};

const onResize = useCallback((height: any) => {
handleHeightChange(height - 40);
const onResize = useCallback((width: number | undefined, height: number | undefined) => {
if (height) {
handleHeightChange(height - 40);
}
}, []);

const { ref } = useResizeDetector({
Expand Down

0 comments on commit e137e75

Please sign in to comment.