Skip to content

Commit

Permalink
fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
mdshamoon committed Feb 1, 2024
1 parent e7bc69f commit b9731e9
Showing 1 changed file with 13 additions and 5 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

0 comments on commit b9731e9

Please sign in to comment.