Skip to content

Commit

Permalink
style(*): prettier test files
Browse files Browse the repository at this point in the history
  • Loading branch information
youluna committed Mar 4, 2019
1 parent 77892a1 commit d34a187
Show file tree
Hide file tree
Showing 94 changed files with 10,682 additions and 5,354 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"test": "node --max_old_space_size=8192 ./scripts/test/index.js",
"order-var": "node ./scripts/order-var.js",
"eslint": "eslint '@(src|scripts)/**/*.@(js|jsx)' && eslint --fix 'docs/**/@(demo|theme)/*.@(md)'",
"prettierjs": "prettier --write '@(src|scripts)/**/*.@(js|jsx)'",
"prettierjs": "prettier --write '@(src|test|scripts)/**/*.@(js|jsx)'",
"stylelint": "stylelint --fix 'src/**/*.@(css|scss)'",
"commitmsg": "commitlint -E GIT_PARAMS",
"precommit": "lint-staged",
Expand Down
91 changes: 56 additions & 35 deletions test/affix/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Enzyme.configure({ adapter: new Adapter() });
/* global describe, it, beforeEach, afterEach */

class AffixDemo extends React.Component {

constructor(props) {
super(props);
this.state = {
Expand All @@ -28,23 +27,35 @@ class AffixDemo extends React.Component {
});
}


render() {
const { offsetTop } = this.state;
return (<div className="affix-demo" ref={ref => {
this.container = ref;
}} style={{ height: 100, overflowY: 'scroll' }}>
<div className="affix-wrapper" style={{ padding: 60, height: 300, background: '#eee' }}>
<Affix id="affix" offsetTop={offsetTop} container={() => this.container} ref={
ref => {
this.affix = ref;
}
}>
<Button
onClick={this.changeOffset.bind(this)}>hello world</Button>
</Affix>
return (
<div
className="affix-demo"
ref={ref => {
this.container = ref;
}}
style={{ height: 100, overflowY: 'scroll' }}
>
<div
className="affix-wrapper"
style={{ padding: 60, height: 300, background: '#eee' }}
>
<Affix
id="affix"
offsetTop={offsetTop}
container={() => this.container}
ref={ref => {
this.affix = ref;
}}
>
<Button onClick={this.changeOffset.bind(this)}>
hello world
</Button>
</Affix>
</div>
</div>
</div>);
);
}
}

Expand All @@ -68,36 +79,44 @@ describe('Affix', () => {

it('should render', () => {
const style = { padding: '40px 0' };
wrapper = mount(<div style={style}>
<Affix>
<Button type="secondary"> Hello World </Button>
</Affix>
</div>);
wrapper = mount(
<div style={style}>
<Affix>
<Button type="secondary"> Hello World </Button>
</Affix>
</div>
);
assert(wrapper.find('div.next-affix').length === 0);
});

it('shoud render with affixTop', () => {
const style = { padding: '40px 0' };
wrapper = mount(<div style={style}>
<Affix offsetTop={0}>
<Button type="secondary"> Hello World </Button>
</Affix>
</div>);
wrapper = mount(
<div style={style}>
<Affix offsetTop={0}>
<Button type="secondary"> Hello World </Button>
</Affix>
</div>
);
assert(wrapper.find('.next-affix').length === 0);
});

it('shoud render with affixBottom', () => {
const style = { padding: '40px 0' };
wrapper = mount(<div style={style}>
<Affix offsetBottom={0}>
<Button type="secondary"> Hello World </Button>
</Affix>
</div>);
wrapper = mount(
<div style={style}>
<Affix offsetBottom={0}>
<Button type="secondary"> Hello World </Button>
</Affix>
</div>
);
assert(wrapper.find('.next-affix').length === 0);
});

it('should render with specified target', () => {
wrapper = mount(<AffixDemo />, { attachTo: document.getElementById('react-app')});
wrapper = mount(<AffixDemo />, {
attachTo: document.getElementById('react-app'),
});
const affix = wrapper.find('div.next-affix');
assert(affix.length === 0);

Expand All @@ -109,21 +128,23 @@ describe('Affix', () => {
});

it('should receive offset change', () => {
wrapper = mount(<AffixDemo />, { attachTo: document.getElementById('react-app')});
wrapper = mount(<AffixDemo />, {
attachTo: document.getElementById('react-app'),
});
const affix = wrapper.find('div.next-affix');
assert(affix.length === 0);
const rect = document.querySelectorAll('.next-affix-top');
ReactTestUtils.Simulate.click(rect[0].firstChild, {
pageX: rect.left,
pageY: rect.top
pageY: rect.top,
});
ReactTestUtils.Simulate.click(rect[0].firstChild, {
pageX: rect.left,
pageY: rect.top
pageY: rect.top,
});
ReactTestUtils.Simulate.click(rect[0].firstChild, {
pageX: rect.left,
pageY: rect.top
pageY: rect.top,
});
const affixDemo = wrapper.find('div.affix-demo');

Expand Down
62 changes: 37 additions & 25 deletions test/animate/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import './index-spec.scss';
/* eslint-disable react/jsx-filename-extension, react/no-multi-comp, react/prop-types, react/prefer-stateless-function */
/* global describe, it, beforeEach, afterEach */


const { hasClass, getStyle } = dom;
const { ieVersion } = env;

Expand All @@ -22,7 +21,7 @@ class Demo extends React.Component {

static defaultProps = {
visible: false,
expand: false
expand: false,
};

constructor(props) {
Expand All @@ -33,7 +32,7 @@ class Demo extends React.Component {

handleToggle() {
this.setState({
visible: !this.state.visible
visible: !this.state.visible,
});
}

Expand All @@ -43,22 +42,21 @@ class Demo extends React.Component {
const A = expand ? Animate.Expand : Animate;

return (
<div>
<button onClick={this.handleToggle}>Toggle visible</button>
<A animation="my-zoom" {...others}>
{this.state.visible ?
<div className="basic-demo">Next Animate</div> :
null}
</A>
</div>
<div>
<button onClick={this.handleToggle}>Toggle visible</button>
<A animation="my-zoom" {...others}>
{this.state.visible ? (
<div className="basic-demo">Next Animate</div>
) : null}
</A>
</div>
);
}
}

const delay = time => new Promise(resolve => setTimeout(resolve, time));

describe('Animate', () => {

let mountNode;

beforeEach(() => {
Expand Down Expand Up @@ -86,7 +84,7 @@ describe('Animate', () => {
}

it('should play appear animation', () => {
return co(function* () {
return co(function*() {
ReactDOM.render(<Demo visible />, mountNode);
const demo = document.querySelector('.basic-demo');
assert(hasClass(demo, 'my-zoom-appear'));
Expand All @@ -99,8 +97,11 @@ describe('Animate', () => {
});

it('should not play appear animation if set animationAppear to false', () => {
return co(function* () {
ReactDOM.render(<Demo visible animationAppear={false} />, mountNode);
return co(function*() {
ReactDOM.render(
<Demo visible animationAppear={false} />,
mountNode
);
const demo = document.querySelector('.basic-demo');
assert(!hasClass(demo, 'my-zoom-appear'));
yield delay(15);
Expand All @@ -109,7 +110,7 @@ describe('Animate', () => {
});

it('should play enter animation', () => {
return co(function* () {
return co(function*() {
ReactDOM.render(<Demo />, mountNode);
const btn = document.querySelector('button');
btn.click();
Expand All @@ -124,8 +125,11 @@ describe('Animate', () => {
});

it('should play leave animation', () => {
return co(function* () {
ReactDOM.render(<Demo visible animationAppear={false} />, mountNode);
return co(function*() {
ReactDOM.render(
<Demo visible animationAppear={false} />,
mountNode
);
const btn = document.querySelector('button');
btn.click();
const demo = document.querySelector('.basic-demo');
Expand All @@ -138,11 +142,16 @@ describe('Animate', () => {
});

it('should support passing object to animation property', () => {
return co(function* () {
ReactDOM.render(<Demo animation={{
enter: 'my-zoom-in',
leave: 'my-zoom-out'
}} />, mountNode);
return co(function*() {
ReactDOM.render(
<Demo
animation={{
enter: 'my-zoom-in',
leave: 'my-zoom-out',
}}
/>,
mountNode
);
const btn = document.querySelector('button');
btn.click();
const demo = document.querySelector('.basic-demo');
Expand All @@ -163,8 +172,11 @@ describe('Animate', () => {
});

it('should play expand animation', () => {
return co(function* () {
ReactDOM.render(<Demo visible={false} expand animation="expand" />, mountNode);
return co(function*() {
ReactDOM.render(
<Demo visible={false} expand animation="expand" />,
mountNode
);
const btn = document.querySelector('button');
btn.click();
const demo = document.querySelector('.basic-demo');
Expand Down
Loading

0 comments on commit d34a187

Please sign in to comment.