Skip to content

Commit

Permalink
Merge pull request #55 from storybooks/new-test
Browse files Browse the repository at this point in the history
add tests for decorator
  • Loading branch information
hipstersmoothie authored Mar 18, 2019
2 parents d10b668 + 0bcc8c1 commit a7c628c
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 225 deletions.
16 changes: 10 additions & 6 deletions example/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { configure } from '@storybook/react'
import { setOptions } from '@storybook/addon-options'
import { configure, setAddon } from '@storybook/react';
import { setOptions } from '@storybook/addon-options';
import JSXAddon from '../../lib/index';

setAddon(JSXAddon);

function loadStories() {
require('../stories')
require('../stories');
}

setOptions({
name: 'CUSTOM-OPTIONS',
url: 'https://github.com/kadirahq/storybook-addon-options',
Expand All @@ -12,7 +16,7 @@ setOptions({
showDownPanel: true,
showSearchBox: false,
downPanelInRight: true,
sortStoriesByKind: false,
})
sortStoriesByKind: false
});

configure(loadStories, module)
configure(loadStories, module);
77 changes: 38 additions & 39 deletions example/stories/array.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
import React from 'react'
import { storiesOf } from '@storybook/react'
import React from 'react';
import { storiesOf } from '@storybook/react';

const Component = () => <div />
const Component = () => <div />;
const Simple = props => (
<div>
<span>Hello</span>
{props.children}
</div>
)
);

export default () =>
storiesOf('Children Array', module)
.addWithJSX(
'Simple Array',
() => (
<div>
<div />
<div />
</div>
),
{ skip: 1 },
)
.addWithJSX(
'Array with function',
() => (
<div>
<div />
<div />
{Component()}
</div>
),
{ skip: 1 },
)
.addWithJSX(
'Array with nested component',
() => (
<div>
<div />
<Simple>
<span>hello</span>
</Simple>
</div>
),
{ skip: 1 },
)
storiesOf('Children Array', module)
.addWithJSX(
'Simple Array',
() => (
<div>
<div />
<div />
</div>
),
{ skip: 1 }
)
.addWithJSX(
'Array with function',
() => (
<div>
<div />
<div />
{Component()}
</div>
),
{ skip: 1 }
)
.addWithJSX(
'Array with nested component',
() => (
<div>
<div />
<Simple>
<span>hello</span>
</Simple>
</div>
),
{ skip: 1 }
);
47 changes: 47 additions & 0 deletions example/stories/decorator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { jsxDecorator } from '../../lib/index';

const Component = () => <div />;
const Simple = props => (
<div>
<span>Hello</span>
{props.children}
</div>
);

storiesOf('Decorator', module)
.addDecorator(jsxDecorator)
.addWithJSX(
'Simple Array',
() => (
<div>
<div />
<div />
</div>
),
{ skip: 1 }
)
.addWithJSX(
'Array with function',
() => (
<div>
<div />
<div />
{Component()}
</div>
),
{ skip: 1 }
)
.addWithJSX(
'Array with nested component',
() => (
<div>
<div />
<Simple>
<span>hello</span>
</Simple>
</div>
),
{ skip: 1 }
);
109 changes: 54 additions & 55 deletions example/stories/deep.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { storiesOf } from '@storybook/react'
import React from 'react';
import { storiesOf } from '@storybook/react';

const Deep = ({ children }) => (
<div>
Expand All @@ -12,87 +12,86 @@ const Deep = ({ children }) => (
</div>
</div>
</div>
)
);

export default () =>
storiesOf('Deep Test', module)
.addWithJSX('No children - No options', () => (
storiesOf('Deep Test', module)
.addWithJSX('No children - No options', () => (
<div>
<div>
<ul>
<li>Deeper</li>
</ul>
<div>
<ul>
<li>Deeper</li>
</ul>
<div>
<div>
<span>Hello</span>
<Deep />
</div>
<span>Hello</span>
<Deep />
</div>
</div>
</div>
))
.addWithJSX(
'No children - Rename',
() => (
</div>
))
.addWithJSX(
'No children - Rename',
() => (
<div>
<div>
<div>
<div>
<div>
<span>Hello</span>
<Deep />
</div>
<span>Hello</span>
<Deep />
</div>
</div>
</div>
),
{
displayName: () => 'Renamed',
},
)
.addWithJSX('With children - No options', () => (
</div>
),
{
displayName: () => 'Renamed'
}
)
.addWithJSX('With children - No options', () => (
<div>
<div>
<div>
<div>
<div>
<span>Hello</span>
<Deep />
</div>
<span>Hello</span>
<Deep />
</div>
</div>
</div>
))
.addWithJSX(
'With children - Skip',
() => (
</div>
))
.addWithJSX(
'With children - Skip',
() => (
<div>
<div>
<div>
<div>
<div>
<span>Hello</span>
<Deep />
</div>
<span>Hello</span>
<Deep />
</div>
</div>
</div>
),
{ skip: 1 },
)
.addWithJSX(
'With children - Skip and rename',
() => (
</div>
),
{ skip: 1 }
)
.addWithJSX(
'With children - Skip and rename',
() => (
<div>
<div>
<ul>
<li>Deeper</li>
</ul>
<div>
<ul>
<li>Deeper</li>
</ul>
<div>
<div>
<span>Hello</span>
<Deep />
</div>
<span>Hello</span>
<Deep />
</div>
</div>
</div>
),
{ skip: 1, displayName: () => 'Renamed' },
)
</div>
),
{ skip: 1, displayName: () => 'Renamed' }
);
51 changes: 25 additions & 26 deletions example/stories/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,35 @@ const withErrors = BaseComponent => props => {

const SimpleWithErrors = withErrors(Simple);

export default () =>
storiesOf('Function as a children', module)
.addWithJSX('No options', () => <Simple>{() => <span>World</span>}</Simple>)
.addWithJSX('Skip', () => <Simple>{() => <span>World</span>}</Simple>, {
skip: 1,
})
.addWithJSX(
'Skip and Rename',
() => <Simple>{() => <span>World</span>}</Simple>,
{ skip: 1, displayName: () => 'Renamed' },
)
.addWithJSX('Deep function - No options', () => (
storiesOf('Function as a children', module)
.addWithJSX('No options', () => <Simple>{() => <span>World</span>}</Simple>)
.addWithJSX('Skip', () => <Simple>{() => <span>World</span>}</Simple>, {
skip: 1
})
.addWithJSX(
'Skip and Rename',
() => <Simple>{() => <span>World</span>}</Simple>,
{ skip: 1, displayName: () => 'Renamed' }
)
.addWithJSX('Deep function - No options', () => (
<Simple>
{() => (
<SimpleWithErrors>
<span>World</span>
</SimpleWithErrors>
)}
</Simple>
))
.addWithJSX(
'Deep function - Skip',
() => (
<Simple>
{() => (
<SimpleWithErrors>
<span>World</span>
</SimpleWithErrors>
)}
</Simple>
))
.addWithJSX(
'Deep function - Skip',
() => (
<Simple>
{() => (
<SimpleWithErrors>
<span>World</span>
</SimpleWithErrors>
)}
</Simple>
),
{ skip: 2 },
);
),
{ skip: 2 }
);
20 changes: 6 additions & 14 deletions example/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import React from 'react';
import { setAddon } from '@storybook/react';
import JSXAddon from '../../lib/index';

import SimpleStories from './simple';
import DeepStories from './deep';
import FunctionStories from './functions';
import ArrayStories from './array';
import WithPropsStories from './withProps';

setAddon(JSXAddon);

SimpleStories();
DeepStories();
FunctionStories();
ArrayStories();
WithPropsStories();
import './simple';
import './deep';
import './decorator';
import './functions';
import './array';
import './withProps';
Loading

0 comments on commit a7c628c

Please sign in to comment.