Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit c4c3dda

Browse files
authored
Merge pull request #102 from skellock/storyshots
Storyshots support
2 parents 70d010d + 6565d08 commit c4c3dda

File tree

23 files changed

+718
-45
lines changed

23 files changed

+718
-45
lines changed

.storybook/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { configure } from '@storybook/react'
1+
const { configure } = require('@storybook/react')
22

33
const req = require.context('../src', true, /story\.tsx?$/)
44

.storybook/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = (config, env) => {
1010
exclude: /node_modules/,
1111
include: path.resolve(__dirname, '..', 'src'),
1212
})
13-
13+
1414
myConfig.resolve.extensions.unshift('.tsx')
1515
myConfig.resolve.extensions.unshift('.ts')
1616

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ You have to bring your own awesome. But here's a picture* after `npm i` and `np
3939
* lean production bundles
4040
* integrated storybook support
4141
* unit tests with mocking
42-
* 100% code coverage with examples on how to keep it there
42+
* storybook snapshot testing
4343
* code linting & formatting
4444

4545
### Documentation & Samples 🖨

docs/stack.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Start your app only when your gut says, "You'll fuck this up long before your st
8989

9090
Provides a sandbox to work on your components with whatever props you can dream of wanting set to make sure your components are in tip top shape before and during use in your application. If you are writing a component you should be writing stories about it.
9191

92+
Also the storyshots addon for working with `jest` is a great way to add snapshot testing for your React components by using your stories. (Like we needed another reason to use storybook!!)
93+
9294
## Animations
9395

9496
> **react-transition-group**

package.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
"react-transition-group": "^2.2.1"
8080
},
8181
"devDependencies": {
82+
"@storybook/addon-actions": "^3.2.15",
83+
"@storybook/addon-links": "^3.2.15",
84+
"@storybook/addon-storyshots": "^3.2.15",
8285
"@storybook/react": "^3.2.15",
8386
"@types/electron-is-dev": "^0.3.0",
8487
"@types/electron-store": "^1.2.0",
@@ -99,6 +102,7 @@
99102
"lint-staged": "^5.0.0",
100103
"npm-run-all": "^4.1.2",
101104
"prettier": "^1.8.2",
105+
"react-powerplug": "^0.1.2",
102106
"react-test-renderer": "^16.0.0",
103107
"ts-jest": "^21.2.1",
104108
"ts-loader": "^3.1.1",
@@ -113,19 +117,25 @@
113117
"transform": {
114118
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
115119
},
120+
"moduleNameMapper": {
121+
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/test/mock-file.ts",
122+
"\\.(css|less)$": "<rootDir>/test/mock-style.ts"
123+
},
116124
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
117125
"moduleFileExtensions": [
118126
"ts",
119127
"tsx",
120-
"js"
128+
"js",
129+
"json"
121130
],
122131
"coveragePathIgnorePatterns": [
123-
"/node_modules/",
124-
"/test/",
125-
"/out/",
126-
"/build/",
127-
"/dist/",
128-
"/docs/"
132+
"./node_modules",
133+
"./out",
134+
"./build",
135+
"./dist",
136+
"./test",
137+
"./docs",
138+
"\\.story.tsx$"
129139
],
130140
"coverageThreshold": {
131141
"global": {

src/renderer/features/example-using-tabs/welcome-screen/sample-tabs.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export interface SampleTabsProps {
1919
onChangeTab: (tab: SampleTabType) => void
2020
}
2121

22-
const KEY_1 = `${commandOrControlKey}+1`
23-
const KEY_2 = `${commandOrControlKey}+2`
24-
const KEY_3 = `${commandOrControlKey}+3`
22+
const KEY_1 = `${commandOrControlKey()}+1`
23+
const KEY_2 = `${commandOrControlKey()}+2`
24+
const KEY_3 = `${commandOrControlKey()}+3`
2525

2626
// an extra layer just for the drag style due to electron bug
2727
const ROOT = css(styles.windowDrag)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react'
2+
import { StorybookStory as Story, StorybookGroup as Group } from '../storybook'
3+
import { storiesOf } from '@storybook/react'
4+
import { CenteredContent } from './index'
5+
6+
storiesOf('CenteredContent', module).add('default', () => (
7+
<Story>
8+
<Group title='default'>
9+
<CenteredContent>
10+
<p>i am in the middle</p>
11+
<p>i am also a really strange component and shouldn't exist.</p>
12+
</CenteredContent>
13+
</Group>
14+
</Story>
15+
))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as React from 'react'
2+
import { StorybookStory as Story, StorybookGroup as Group } from '../storybook'
3+
4+
import { storiesOf } from '@storybook/react'
5+
import { EnterAnimation } from './index'
6+
// import { Value } from 'react-powerplug'
7+
8+
storiesOf('EnterAnimation', module).add('default', () => (
9+
<Story>
10+
<Group title='grow'>
11+
<EnterAnimation animation='grow'>
12+
<p>hi</p>
13+
</EnterAnimation>
14+
</Group>
15+
<Group title='slide'>
16+
<EnterAnimation animation='slide'>
17+
<p>hi</p>
18+
</EnterAnimation>
19+
</Group>
20+
</Story>
21+
))

src/renderer/platform/components/enter-animation/enter-animation.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const FINISH = cssProps({ transform: `translate(0, 0) scale(1, 1)` })
2828
export class EnterAnimation extends React.Component<EnterAnimationProps, EnterAnimationState> {
2929
state: EnterAnimationState = {}
3030

31+
// istanbul ignore next
3132
componentDidMount() {
3233
setTimeout(() => this.setState({ mounted: true }), 1)
3334
}
@@ -55,6 +56,7 @@ export class EnterAnimation extends React.Component<EnterAnimationProps, EnterAn
5556

5657
// style props
5758
const starting = css(cssProps({ transform, transition }))
59+
// istanbul ignore next
5860
const finishing = css(mounted && FINISH)
5961

6062
return (
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as React from 'react'
2+
import { StorybookStory as Story, StorybookGroup as Group } from '../storybook'
3+
import { storiesOf } from '@storybook/react'
4+
import { ScrollableContent } from './index'
5+
6+
storiesOf('ScrollableContent', module).add('default', () => (
7+
<Story>
8+
<Group title='default'>
9+
<ScrollableContent style={{ height: 100 }}>
10+
<p>hi</p>
11+
<p>hi</p>
12+
<p>hi</p>
13+
<p>hi</p>
14+
<p>hi</p>
15+
<p>hi</p>
16+
<p>hi</p>
17+
<p>hi</p>
18+
<p>hi</p>
19+
<p>hi</p>
20+
<p>hi</p>
21+
<p>hi</p>
22+
</ScrollableContent>
23+
</Group>
24+
</Story>
25+
))

0 commit comments

Comments
 (0)