Skip to content

Commit

Permalink
[EuiDragDropContext] Convert from Enzyme to RTL
Browse files Browse the repository at this point in the history
- remove unnecessary/unused jest mock
  • Loading branch information
cee-chen committed Sep 15, 2023
1 parent dd887ab commit 0c85e13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiDragDropContext is rendered 1`] = `<div />`;
exports[`EuiDragDropContext renders 1`] = `<div />`;
67 changes: 24 additions & 43 deletions src/components/drag_and_drop/drag_drop_context.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,40 @@
*/

import React from 'react';
import { mount, ReactWrapper } from 'enzyme';

import { findTestSubject } from '../../test';
import { render } from '../../test/rtl';
import { requiredProps } from '../../test/required_props';

import { EuiDragDropContext } from './';
import { EuiDragDropContextContext } from './drag_drop_context';

function snapshotDragDropContext(component: ReactWrapper) {
// Get the Portal's sibling and return its html
const renderedHtml = component.html();
const container = document.createElement('div');
container.innerHTML = renderedHtml;
return container.firstChild;
}
import {
EuiDragDropContext,
EuiDragDropContextContext,
} from './drag_drop_context';

describe('EuiDragDropContext', () => {
test('is rendered', () => {
const handler = jest.fn();
const component = mount(
<EuiDragDropContext onDragEnd={handler} {...requiredProps}>
it('renders', () => {
const { container } = render(
<EuiDragDropContext onDragEnd={() => {}} {...requiredProps}>
<div />
</EuiDragDropContext>
);

expect(snapshotDragDropContext(component)).toMatchSnapshot();
expect(container.firstChild).toMatchSnapshot();
});

describe('custom behavior', () => {
describe('isDraggingType', () => {
test('is set on proprietary context', () => {
jest.mock('react', () => {
const react = jest.requireActual('react');
return {
...react,
useLayoutEffect: react.useEffect,
};
});
const handler = jest.fn();
const component = mount(
<EuiDragDropContext onDragEnd={handler} {...requiredProps}>
<EuiDragDropContextContext.Consumer>
{(value) => (
<div data-test-subj="child">
{value.hasOwnProperty('isDraggingType') ? 'true' : 'false'}
</div>
)}
</EuiDragDropContextContext.Consumer>
</EuiDragDropContext>
);

expect(findTestSubject(component, 'child').text()).toBe('true');
});
describe('isDraggingType', () => {
test('is set on proprietary context', () => {
const { getByTestSubject } = render(
<EuiDragDropContext onDragEnd={() => {}}>
<EuiDragDropContextContext.Consumer>
{(value) => (
<div data-test-subj="child">
{value.hasOwnProperty('isDraggingType') ? 'true' : 'false'}
</div>
)}
</EuiDragDropContextContext.Consumer>
</EuiDragDropContext>
);

expect(getByTestSubject('child')).toHaveTextContent('true');
});
});
});

0 comments on commit 0c85e13

Please sign in to comment.