From f18e749e93efa492e1a4d0b541f58de490d32f14 Mon Sep 17 00:00:00 2001 From: Priscila Date: Wed, 31 Oct 2018 06:00:59 +0100 Subject: [PATCH] refactor: added flow and css in js (#1100) fix: fixed tests --- src/webui/components/NoItems/index.js | 26 +++++++++---------- src/webui/components/NoItems/noItems.scss | 3 --- src/webui/components/NoItems/styles.js | 12 +++++++++ src/webui/components/NoItems/types.js | 8 ++++++ .../__snapshots__/noitems.spec.js.snap | 4 ++- test/unit/webui/components/noitems.spec.js | 8 +++--- 6 files changed, 39 insertions(+), 22 deletions(-) delete mode 100644 src/webui/components/NoItems/noItems.scss create mode 100644 src/webui/components/NoItems/styles.js create mode 100644 src/webui/components/NoItems/types.js diff --git a/src/webui/components/NoItems/index.js b/src/webui/components/NoItems/index.js index 67430f2eb..1e48a9139 100644 --- a/src/webui/components/NoItems/index.js +++ b/src/webui/components/NoItems/index.js @@ -1,18 +1,16 @@ +/** + * @prettier + * @flow + */ + import React from 'react'; -import PropTypes from 'prop-types'; +import { IProps } from './types'; +import { Wrapper } from './styles'; -import classes from './noItems.scss'; - -const NoItems = (props) => { - return ( -
-

{props.text}

-
- ); -}; - -NoItems.propTypes = { - text: PropTypes.string.isRequired -}; +const NoItems = ({ text }: IProps) => ( + +

{text}

+
+); export default NoItems; diff --git a/src/webui/components/NoItems/noItems.scss b/src/webui/components/NoItems/noItems.scss deleted file mode 100644 index 81a2a9ec9..000000000 --- a/src/webui/components/NoItems/noItems.scss +++ /dev/null @@ -1,3 +0,0 @@ -.noItems { - margin: 5em 0; -} diff --git a/src/webui/components/NoItems/styles.js b/src/webui/components/NoItems/styles.js new file mode 100644 index 000000000..1a0085de8 --- /dev/null +++ b/src/webui/components/NoItems/styles.js @@ -0,0 +1,12 @@ +/** + * @prettier + * @flow + */ + +import styled from 'react-emotion'; + +export const Wrapper = styled.div` + && { + margin: 5em 0; + } +`; diff --git a/src/webui/components/NoItems/types.js b/src/webui/components/NoItems/types.js new file mode 100644 index 000000000..50115e670 --- /dev/null +++ b/src/webui/components/NoItems/types.js @@ -0,0 +1,8 @@ +/** + * @prettier + * @flow + */ + +export interface IProps { + text: string; +} diff --git a/test/unit/webui/components/__snapshots__/noitems.spec.js.snap b/test/unit/webui/components/__snapshots__/noitems.spec.js.snap index cfb8d0a5b..56f50160c 100644 --- a/test/unit/webui/components/__snapshots__/noitems.spec.js.snap +++ b/test/unit/webui/components/__snapshots__/noitems.spec.js.snap @@ -1,3 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should set html from props 1`] = `"

This is a test string

"`; +exports[` component should load the component in default state 1`] = `"

"`; + +exports[` component should set html from props 1`] = `"

This is a test string

"`; diff --git a/test/unit/webui/components/noitems.spec.js b/test/unit/webui/components/noitems.spec.js index 30938a9c0..b3c964bae 100644 --- a/test/unit/webui/components/noitems.spec.js +++ b/test/unit/webui/components/noitems.spec.js @@ -3,15 +3,15 @@ */ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow, mount } from 'enzyme'; import NoItems from '../../../../src/webui/components/NoItems/index'; console.error = jest.fn(); describe(' component', () => { - it('should give error for the required fields', () => { - shallow(); - expect(console.error).toBeCalled(); + it('should load the component in default state', () => { + const wrapper = mount(); + expect(wrapper.html()).toMatchSnapshot(); }); it('should set html from props', () => {