-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integrating react storybook and adding example unit test
- Loading branch information
Roy Yu
committed
Jul 15, 2017
1 parent
c38aba4
commit c74441a
Showing
19 changed files
with
168 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { configure } from '@storybook/react'; | ||
|
||
const req = require.context('../stories', true, /\.js$/) | ||
|
||
function loadStories() { | ||
req.keys().forEach(filename => req(filename)) | ||
} | ||
|
||
configure(loadStories, module); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// you can use this file to add your custom webpack plugins, loaders and anything you like. | ||
// This is just the basic way to add additional webpack configurations. | ||
// For more information refer the docs: https://storybook.js.org/configurations/custom-webpack-config | ||
|
||
// IMPORTANT | ||
// When you add this file, we won't add the default configurations which is similar | ||
// to "React Create App". This only has babel loader to load JavaScript. | ||
|
||
const webpack = require('webpack'); | ||
const precss = require('precss'); | ||
const postcssNested = require('postcss-nested'); | ||
const postcssImport = require('postcss-import'); | ||
const postcssCssnext = require('postcss-cssnext'); | ||
|
||
module.exports = { | ||
plugins: [ | ||
// your custom plugins | ||
], | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
{ | ||
loader: 'style-loader', | ||
}, | ||
{ | ||
loader: 'css-loader', | ||
options: { sourceMap: true, importLoaders: 1 } | ||
}, | ||
{ | ||
loader: 'postcss-loader', | ||
options: { | ||
sourceMap: true, | ||
plugins: () => [ | ||
precss(), | ||
postcssNested(), | ||
postcssImport({ addDependencyTo: webpack }), | ||
postcssCssnext({ | ||
browsers: ['last 2 versions', 'ie >= 9'], | ||
compress: true, | ||
}), | ||
], | ||
}, | ||
}, | ||
], | ||
} | ||
] | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- "6" | ||
script: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { fromJS } from 'immutable' | ||
|
||
export const exampleData = { | ||
example:{ | ||
result: fromJS({ | ||
testing: 'data' | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'test-file-stub'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import { Example } from '../src/js/common/components/Example' | ||
import { exampleData } from '../__fixtures__' | ||
|
||
describe('ExampleView', () => { | ||
it('should render a blank div without data', () => { | ||
const el = shallow(<Example />) | ||
|
||
expect(el.length).toEqual(1) | ||
expect(el.find('.row').length).toEqual(0) | ||
}) | ||
|
||
it('should render with correct data', () => { | ||
const el = shallow( | ||
<Example {...exampleData} /> | ||
) | ||
|
||
expect(el.length).toEqual(1) | ||
expect(el.find('.row').length).toEqual(1) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@font-face { | ||
font-family: "Aspira"; | ||
src: url("Aspira-Regular.eot") format("embedded-opentype"); | ||
src: url("Aspira-Regular.otf") format("opentype"); | ||
font-weight: normal; | ||
font-style: normal; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React, { PureComponent } from 'react' | ||
|
||
class Example extends PureComponent { | ||
render () { | ||
const props = this.props; | ||
const result = props.example && props.example.result ? props.example.result : null; | ||
|
||
if (result && result.size && result.size > 0) { | ||
return ( | ||
|
||
<div className="row example"> | ||
<pre className="col-md-12 example__output"> | ||
{JSON.stringify(result.toJS(), undefined, 2)} | ||
</pre> | ||
</div> | ||
|
||
|
||
); | ||
} | ||
return <div />; | ||
} | ||
} | ||
|
||
export default Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Example } from './Example' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react' | ||
|
||
import { Example } from '../src/js/common/components/Example' | ||
import { exampleData } from '../__fixtures__' | ||
|
||
storiesOf('Example View', module) | ||
.add('no data', () => <Example />) | ||
.add('with example data', () => <Example {...exampleData} />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters