Skip to content

Commit

Permalink
Merge pull request #2401 from steemit/im/2182/more-storybooks
Browse files Browse the repository at this point in the history
More Component Stories and init component file-structure.
  • Loading branch information
gl2748 authored Feb 2, 2018
2 parents 9511839 + c92a006 commit 1e5bc0c
Show file tree
Hide file tree
Showing 19 changed files with 344 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/components/all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@import "./elements/Reblog";
@import "./elements/YoutubePreview";
@import "./elements/ShareMenu";
@import "./elements/Author";
@import "./elements/Author/styles";
@import "./elements/AuthorDropdown";
@import "./elements/UserNames";
@import "./elements/UserKeys";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { withKnobs } from '@storybook/addon-knobs';
import rootReducer from 'app/redux/RootReducer';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import Author from './Author';
import { Center } from './Tooltip.story';
import Author from './index';
import { Center } from '../Tooltip.story';
import { IntlProvider } from 'react-intl';

const store = createStore(rootReducer);
Expand Down
55 changes: 55 additions & 0 deletions src/app/components/elements/Author/__snapshots__/spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Author /> renders without crashing 1`] = `
ShallowWrapper {
"length": 1,
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <Provider
store={
Object {
"dispatch": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
Symbol(observable): [Function],
}
}
>
<Connect(Author) />
</Provider>,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
"getNode": [Function],
"render": [Function],
"simulateEvent": [Function],
"unmount": [Function],
},
Symbol(enzyme.__node__): Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {},
"ref": null,
"rendered": null,
"type": [Function],
},
Symbol(enzyme.__nodes__): Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {},
"ref": null,
"rendered": null,
"type": [Function],
},
],
Symbol(enzyme.__options__): Object {
"adapter": ReactFifteenAdapter {
"options": Object {
"supportPrevContextArgumentOfComponentDidUpdate": true,
},
},
},
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import shouldComponentUpdate from 'app/utils/shouldComponentUpdate';
import Icon from 'app/components/elements/Icon';
import { Link } from 'react-router';
import { authorNameAndRep } from 'app/utils/ComponentFormatters';
import AuthorDropdown from './AuthorDropdown';
import AuthorDropdown from '../AuthorDropdown';
import Reputation from 'app/components/elements/Reputation';
import normalizeProfile from 'app/utils/NormalizeProfile';
import Overlay from 'react-overlays/lib/Overlay';
Expand Down
27 changes: 27 additions & 0 deletions src/app/components/elements/Author/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import Author from './index';
import rootReducer from 'app/redux/RootReducer';
import { configure, shallow } from 'enzyme';

import Adapter from 'enzyme-adapter-react-15';

configure({ adapter: new Adapter() });

const store = createStore(rootReducer);

describe('<Author />', () => {
const wrapper = shallow(
<Provider store={store}>
<Author />
</Provider>
);
const container = wrapper.instance();

it('renders without crashing', () => {
expect(wrapper).toBeTruthy();
expect(container).toBeTruthy();
expect(wrapper).toMatchSnapshot();
});
});
File renamed without changes.
24 changes: 24 additions & 0 deletions src/app/components/elements/ChangePassword.story.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs';
import rootReducer from 'app/redux/RootReducer';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import ChangePassword from './ChangePassword';
import { Center } from './Tooltip.story';

const store = createStore(rootReducer);

storiesOf('Elements', module)
.addDecorator(withKnobs)
.addDecorator(getStory => <Provider store={store}>{getStory()}</Provider>)
.add('ChangePassword', () => (
<Center>
<ChangePassword
username={'maitland'}
defaultPassword={'password1'}
authType={null}
priorAuthKey={'posting'} // Required pubkey if authType is given
/>
</Center>
));
26 changes: 26 additions & 0 deletions src/app/components/elements/Follow/Follow.story.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs, boolean } from '@storybook/addon-knobs';
import rootReducer from 'app/redux/RootReducer';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import Follow from './index';
import { Center } from '../Tooltip.story';

const store = createStore(rootReducer);

storiesOf('Elements', module)
.addDecorator(withKnobs)
.addDecorator(getStory => <Provider store={store}>{getStory()}</Provider>)
.add('Follow', () => (
<Center>
<Follow
className="float-right"
follower={'maitland'}
following={'Carol'}
what="blog"
showFollow={boolean('Show Follow?', true)}
showMute={boolean('Show Mute?', true)}
/>
</Center>
));
55 changes: 55 additions & 0 deletions src/app/components/elements/Follow/__snapshots__/spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Follow /> renders without crashing 1`] = `
ShallowWrapper {
"length": 1,
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <Provider
store={
Object {
"dispatch": [Function],
"getState": [Function],
"replaceReducer": [Function],
"subscribe": [Function],
Symbol(observable): [Function],
}
}
>
<Connect(Follow) />
</Provider>,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
"getNode": [Function],
"render": [Function],
"simulateEvent": [Function],
"unmount": [Function],
},
Symbol(enzyme.__node__): Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {},
"ref": null,
"rendered": null,
"type": [Function],
},
Symbol(enzyme.__nodes__): Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {},
"ref": null,
"rendered": null,
"type": [Function],
},
],
Symbol(enzyme.__options__): Object {
"adapter": ReactFifteenAdapter {
"options": Object {
"supportPrevContextArgumentOfComponentDidUpdate": true,
},
},
},
}
`;
File renamed without changes.
26 changes: 26 additions & 0 deletions src/app/components/elements/Follow/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { mount, configure, shallow } from 'enzyme';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import Follow from './index';
import rootReducer from 'app/redux/RootReducer';
import Adapter from 'enzyme-adapter-react-15';

const store = createStore(rootReducer);

configure({ adapter: new Adapter() });

describe('<Follow />', () => {
const wrapper = shallow(
<Provider store={store}>
<Follow />
</Provider>
);
const container = wrapper.instance();

it('renders without crashing', () => {
expect(wrapper).toBeTruthy();
expect(container).toBeTruthy();
expect(wrapper).toMatchSnapshot();
});
});
30 changes: 30 additions & 0 deletions src/app/components/elements/Keys.story.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs';
import rootReducer from 'app/redux/RootReducer';
import { Map, List } from 'immutable';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import Keys from './Keys';
import { Center } from './Tooltip.story';

const store = createStore(rootReducer);

const mockAccount = Map({
name: 'maitland',
posting: Map({
key_auths: [
List(['SOMETHING', 'HERE']),
List(['ANOTHER THING', 'OVER THERE']),
],
}),
});

storiesOf('Elements', module)
.addDecorator(withKnobs)
.addDecorator(getStory => <Provider store={store}>{getStory()}</Provider>)
.add('Keys', () => (
<Center>
<Keys account={mockAccount} authType="posting" onKey={() => {}} />
</Center>
));
23 changes: 23 additions & 0 deletions src/app/components/elements/Reblog.story.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs';
import rootReducer from 'app/redux/RootReducer';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import Reblog from './Reblog';
import { Center } from './Tooltip.story';

const store = createStore(rootReducer);

storiesOf('Elements', module)
.addDecorator(withKnobs)
.addDecorator(getStory => <Provider store={store}>{getStory()}</Provider>)
.add('Reblog', () => (
<Center>
<Reblog
permlink={'foo/bar'}
author={'maitland'}
reblog={() => alert('STEEM WAZ HERE')}
/>
</Center>
));
10 changes: 10 additions & 0 deletions src/app/components/elements/Reputation.story.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import Reputation from './Reputation';
import { Center } from './Tooltip.story';

storiesOf('Elements', module).add('Reputation', () => (
<Center>
<Reputation value={1200} />
</Center>
));
21 changes: 21 additions & 0 deletions src/app/components/elements/TransactionError.story.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs, text } from '@storybook/addon-knobs';
import TransactionError from './TransactionError';
import { Center } from './Tooltip.story';
import rootReducer from 'app/redux/RootReducer';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
const store = createStore(rootReducer);

storiesOf('Elements', module)
.addDecorator(withKnobs)
.addDecorator(getStory => <Provider store={store}>{getStory()}</Provider>)
.add('TransactionError', () => (
<Center>
<TransactionError
opType="This is a test"
error="There was an error ey"
/>
</Center>
));
17 changes: 14 additions & 3 deletions src/app/components/elements/UserList.story.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs';
import { withKnobs, number } from '@storybook/addon-knobs';
import { Map, List } from 'immutable';
import rootReducer from 'app/redux/RootReducer';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
Expand All @@ -9,9 +10,19 @@ import UserList from './UserList';

const store = createStore(rootReducer);

const mockUsers = Array(70).fill('test');
const options = {
range: true,
min: 0,
max: 150,
step: 1,
};

storiesOf('Elements', module)
.addDecorator(withKnobs)
.addDecorator(getStory => <Provider store={store}>{getStory()}</Provider>)
.add('UserList', () => <UserList users={mockUsers} title="User List" />);
.add('UserList', () => {
let mockUsers = List(
Array(number('number of users', 10, options)).fill('test')
);
return <UserList users={mockUsers} title="User List" />;
});
18 changes: 18 additions & 0 deletions src/app/components/elements/WalletSubMenu.story.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withKnobs, text } from '@storybook/addon-knobs';
import WalletSubMenu from './WalletSubMenu';
import { Center } from './Tooltip.story';
import rootReducer from 'app/redux/RootReducer';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
const store = createStore(rootReducer);

storiesOf('Elements', module)
.addDecorator(withKnobs)
.addDecorator(getStory => <Provider store={store}>{getStory()}</Provider>)
.add('WalletSubMenu', () => (
<Center>
<WalletSubMenu />
</Center>
));
5 changes: 5 additions & 0 deletions src/app/redux/TransactionSaga.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import {
} from './TransactionSaga';
import { DEBT_TICKER } from 'app/client_config';

import { configure, shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';

configure({ adapter: new Adapter() });

const operation = {
type: 'comment',
author: 'Alice',
Expand Down
Loading

0 comments on commit 1e5bc0c

Please sign in to comment.