fix some tests
fix merge issues
This commit is contained in:
8
src/elements/GPElements/Button.module.css
Normal file
8
src/elements/GPElements/Button.module.css
Normal file
@@ -0,0 +1,8 @@
|
||||
.button {
|
||||
background-color: green;
|
||||
border-radius: 5px;
|
||||
border-width: 0;
|
||||
color: white;
|
||||
margin-right: 15px;
|
||||
padding: 6px;
|
||||
}
|
32
src/elements/GPElements/Button.test.js
Normal file
32
src/elements/GPElements/Button.test.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
import {Button} from './Button';
|
||||
|
||||
function prepareFetchApi(response) {
|
||||
const mockJsonPromise = Promise.resolve(response);
|
||||
const mockFetchPromise = Promise.resolve({
|
||||
json: () => mockJsonPromise
|
||||
});
|
||||
return (jest.fn().mockImplementation(() => mockFetchPromise));
|
||||
}
|
||||
|
||||
describe('<Button/>', function () {
|
||||
it('renders without crashing ', function () {
|
||||
const wrapper = shallow(<Button onClick={() => {}} title='test'/>);
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
it('renders title', function () {
|
||||
const wrapper = shallow(<Button onClick={() => {}} title='test1'/>);
|
||||
expect(wrapper.text()).toBe('test1');
|
||||
});
|
||||
|
||||
it('test onclick handling', () => {
|
||||
const func = jest.fn();
|
||||
const wrapper = shallow(<Button onClick={func} title='test1'/>);
|
||||
|
||||
wrapper.find('button').simulate('click');
|
||||
|
||||
expect(func).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
16
src/elements/GPElements/Button.tsx
Normal file
16
src/elements/GPElements/Button.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import React from 'react';
|
||||
import style from './Button.module.css';
|
||||
|
||||
interface ButtonProps {
|
||||
title: string;
|
||||
onClick?: () => void;
|
||||
color?: React.CSSProperties;
|
||||
}
|
||||
|
||||
export function Button(props: ButtonProps): JSX.Element {
|
||||
return (
|
||||
<button className={style.button} style={props.color} onClick={props.onClick}>
|
||||
{props.title}
|
||||
</button>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user