|
@@ -1,31 +1,37 @@
|
|
import React from 'react';
|
|
import React from 'react';
|
|
-import { mount, shallow } from 'enzyme';
|
|
|
|
import DynamicTextButton from 'components/common/DynamicTextButton/DynamicTextButton';
|
|
import DynamicTextButton from 'components/common/DynamicTextButton/DynamicTextButton';
|
|
|
|
+import { render } from 'lib/testHelpers';
|
|
|
|
+import { fireEvent } from '@testing-library/dom';
|
|
|
|
|
|
describe('DynamicButton', () => {
|
|
describe('DynamicButton', () => {
|
|
const mockCallback = jest.fn();
|
|
const mockCallback = jest.fn();
|
|
it('exectutes callback', () => {
|
|
it('exectutes callback', () => {
|
|
- const component = shallow(
|
|
|
|
|
|
+ const component = render(
|
|
<DynamicTextButton
|
|
<DynamicTextButton
|
|
onClick={mockCallback}
|
|
onClick={mockCallback}
|
|
title="title"
|
|
title="title"
|
|
render={() => 'text'}
|
|
render={() => 'text'}
|
|
/>
|
|
/>
|
|
);
|
|
);
|
|
- component.simulate('click');
|
|
|
|
|
|
+
|
|
|
|
+ fireEvent.click(
|
|
|
|
+ component.baseElement.querySelector('button') as HTMLElement
|
|
|
|
+ );
|
|
expect(mockCallback).toBeCalled();
|
|
expect(mockCallback).toBeCalled();
|
|
});
|
|
});
|
|
|
|
|
|
it('changes the text', () => {
|
|
it('changes the text', () => {
|
|
- const component = mount(
|
|
|
|
|
|
+ const component = render(
|
|
<DynamicTextButton
|
|
<DynamicTextButton
|
|
onClick={mockCallback}
|
|
onClick={mockCallback}
|
|
title="title"
|
|
title="title"
|
|
render={(clicked) => (clicked ? 'active' : 'default')}
|
|
render={(clicked) => (clicked ? 'active' : 'default')}
|
|
/>
|
|
/>
|
|
);
|
|
);
|
|
- expect(component.text()).toEqual('default');
|
|
|
|
- component.simulate('click');
|
|
|
|
- expect(component.text()).toEqual('active');
|
|
|
|
|
|
+ expect(component.baseElement).toHaveTextContent('default');
|
|
|
|
+ fireEvent.click(
|
|
|
|
+ component.baseElement.querySelector('button') as HTMLElement
|
|
|
|
+ );
|
|
|
|
+ expect(component.baseElement).toHaveTextContent('active');
|
|
});
|
|
});
|
|
});
|
|
});
|