Skip to content

Commit

Permalink
chore(Lint): lint test/**/* with prettier & add commit linter for test
Browse files Browse the repository at this point in the history
  • Loading branch information
YSMJ1994 committed Nov 1, 2023
1 parent d29fe62 commit adde9ed
Show file tree
Hide file tree
Showing 116 changed files with 3,459 additions and 6,087 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
"prepub": "npm run eslint && npm run stylelint && npm run changelog && npm run build && npm run check && npm run docs && npm run clear-dist && npm run pack && npm run pack -- minimize && npm run pack-adaptor"
},
"lint-staged": {
"test/**/*": [
"prettier --write",
"git add"
],
"types/**/*.d.ts": [
"prettier --write",
"git add"
Expand Down
11 changes: 2 additions & 9 deletions test/affix/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import Affix from '../../src/affix/index';

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



/* eslint-disable react/jsx-filename-extension, react/no-multi-comp, react/prop-types, react/prefer-stateless-function */
/* global describe, it, beforeEach, afterEach */

Expand Down Expand Up @@ -39,10 +37,7 @@ class AffixDemo extends React.Component {
}}
style={{ height: 100, overflowY: 'scroll' }}
>
<div
className="affix-wrapper"
style={{ padding: 60, height: 300, background: '#eee' }}
>
<div className="affix-wrapper" style={{ padding: 60, height: 300, background: '#eee' }}>
<Affix
id="affix"
offsetTop={offsetTop}
Expand All @@ -51,9 +46,7 @@ class AffixDemo extends React.Component {
this.affix = ref;
}}
>
<Button onClick={this.changeOffset.bind(this)}>
hello world
</Button>
<Button onClick={this.changeOffset.bind(this)}>hello world</Button>
</Affix>
</div>
</div>
Expand Down
19 changes: 4 additions & 15 deletions test/animate/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class Demo extends React.Component {
<div>
<button onClick={this.handleToggle}>Toggle visible</button>
<A animation="my-zoom" {...others}>
{this.state.visible ? (
<div className="basic-demo">Next Animate</div>
) : null}
{this.state.visible ? <div className="basic-demo">Next Animate</div> : null}
</A>
</div>
);
Expand Down Expand Up @@ -98,10 +96,7 @@ describe('Animate', () => {

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

it('should play leave animation', () => {
return co(function*() {
ReactDOM.render(
<Demo visible animationAppear={false} />,
mountNode
);
ReactDOM.render(<Demo visible animationAppear={false} />, mountNode);
const btn = document.querySelector('button');
btn.click();
const demo = document.querySelector('.basic-demo');
Expand Down Expand Up @@ -173,10 +165,7 @@ describe('Animate', () => {

it('should play expand animation', () => {
return co(function*() {
ReactDOM.render(
<Demo visible={false} expand animation="expand" />,
mountNode
);
ReactDOM.render(<Demo visible={false} expand animation="expand" />, mountNode);
const btn = document.querySelector('button');
btn.click();
const demo = document.querySelector('.basic-demo');
Expand Down
2 changes: 1 addition & 1 deletion test/avatar/a11y-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Avatar A11y', () => {
});

it('should render', async () => {
wrapper = await testReact(<Avatar />);
wrapper = await testReact(<Avatar />);
return wrapper;
});
});
21 changes: 12 additions & 9 deletions test/avatar/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ describe('Avatar', () => {
wrapper = null;
});

it("should render", () => {
it('should render', () => {
const avatar = wrapper.find('.next-avatar');
assert(avatar.hasClass('next-avatar'));
});

it("should render src", (done) => {
it('should render src', done => {
const link = 'https://img.alicdn.com/tfs/TB1EHhicAH0gK0jSZPiXXavapXa-904-826.png';
let avatar = wrapper.find('.next-avatar');
assert(avatar.hasClass('next-avatar'));
Expand All @@ -35,25 +35,28 @@ describe('Avatar', () => {
assert(avatar.find('img').props().src === link);

let error = 0;
avatar = wrapper.setProps({ src: 'unexist', onError: () => {
error += 1;
} });
setTimeout(()=> {
avatar = wrapper.setProps({
src: 'unexist',
onError: () => {
error += 1;
},
});
setTimeout(() => {
assert(error === 1);
done();
}, 200);
});

it("should render icon", () => {
it('should render icon', () => {
let avatar = wrapper.find('.next-avatar');
avatar = wrapper.setProps({ icon: 'account' });
assert(avatar.find('.next-icon-account'));

avatar = wrapper.setProps({ icon: <Icon type="atm"/> });
avatar = wrapper.setProps({ icon: <Icon type="atm" /> });
assert(avatar.find('.next-icon-atm'));
});

it("should render letters", () => {
it('should render letters', () => {
let avatar = wrapper.find('.next-avatar');
avatar = wrapper.setProps({ children: 'U' });

Expand Down
92 changes: 10 additions & 82 deletions test/badge/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,47 +121,15 @@ describe('Badge', () => {
assert(document.querySelector('.next-badge sup') === null);

enterNumber(1);
assert(
expectStyle(
document.querySelector(
'.next-badge .next-badge-scroll-number-only'
),
true,
11
)
);
assert(expectStyle(document.querySelector('.next-badge .next-badge-scroll-number-only'), true, 11));

enterNumber(2);
assert(
expectStyle(
document.querySelector(
'.next-badge .next-badge-scroll-number-only'
),
false,
12
)
);
assert(expectStyle(document.querySelector('.next-badge .next-badge-scroll-number-only'), false, 12));
yield delay(350);
assert(
expectStyle(
document.querySelector(
'.next-badge .next-badge-scroll-number-only'
),
true,
12
)
);
assert(expectStyle(document.querySelector('.next-badge .next-badge-scroll-number-only'), true, 12));

enterNumber(1);
assert(
expectStyle(
document.querySelector(
'.next-badge .next-badge-scroll-number-only'
),
true,
11
)
);
assert(expectStyle(document.querySelector('.next-badge .next-badge-scroll-number-only'), true, 11));
yield delay(350);

enterNumber(0);
Expand Down Expand Up @@ -192,35 +160,11 @@ describe('Badge', () => {
enterNumber(9);
yield delay(350);
enterNumber(10);
assert(
expectStyle(
document.querySelectorAll(
'.next-badge .next-badge-scroll-number-only'
)[0],
false,
11
)
);
assert(
expectStyle(
document.querySelectorAll(
'.next-badge .next-badge-scroll-number-only'
)[1],
true,
20
)
);
assert(expectStyle(document.querySelectorAll('.next-badge .next-badge-scroll-number-only')[0], false, 11));
assert(expectStyle(document.querySelectorAll('.next-badge .next-badge-scroll-number-only')[1], true, 20));

enterNumber(9);
assert(
expectStyle(
document.querySelectorAll(
'.next-badge .next-badge-scroll-number-only'
)[0],
false,
9
)
);
assert(expectStyle(document.querySelectorAll('.next-badge .next-badge-scroll-number-only')[0], false, 9));
yield delay(350);

ReactDOM.unmountComponentAtNode(div);
Expand All @@ -247,24 +191,8 @@ describe('Badge', () => {
assert(document.querySelector('.next-badge sup').innerHTML === '99+');

enterNumber(99);
assert(
expectStyle(
document.querySelectorAll(
'.next-badge .next-badge-scroll-number-only'
)[0],
false,
9
)
);
assert(
expectStyle(
document.querySelectorAll(
'.next-badge .next-badge-scroll-number-only'
)[1],
false,
9
)
);
assert(expectStyle(document.querySelectorAll('.next-badge .next-badge-scroll-number-only')[0], false, 9));
assert(expectStyle(document.querySelectorAll('.next-badge .next-badge-scroll-number-only')[1], false, 9));

ReactDOM.unmountComponentAtNode(div);
document.body.removeChild(div);
Expand All @@ -274,5 +202,5 @@ describe('Badge', () => {
const wrapper = render(<Badge count={0} showZero />);
assert.notStrictEqual(wrapper.find('.next-badge-count'), null);
assert(wrapper.find('.next-badge-count').hasClass('next-badge-scroll-number'));
})
});
});
20 changes: 3 additions & 17 deletions test/balloon/a11y-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import Balloon from '../../src/balloon/index';
import '../../src/balloon/style';
import {
unmount,
test,
testReact,
createContainer,
} from '../util/a11y/validate';
import { unmount, test, testReact, createContainer } from '../util/a11y/validate';

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

Expand Down Expand Up @@ -44,12 +39,7 @@ describe('Balloon A11y', () => {
it('should not have any violations when not closable', async () => {
portalContainer = createContainer(portalContainerId);
wrapper = await testReact(
<Balloon
id="balloon-2"
visible
closable={false}
popupContainer={portalContainerId}
>
<Balloon id="balloon-2" visible closable={false} popupContainer={portalContainerId}>
I am balloon content
</Balloon>
);
Expand All @@ -61,11 +51,7 @@ describe('Balloon A11y', () => {
portalContainer = createContainer(portalContainerId);

wrapper = await testReact(
<Balloon.Tooltip
id="tooltip-1"
visible
popupContainer={portalContainerId}
>
<Balloon.Tooltip id="tooltip-1" visible popupContainer={portalContainerId}>
I am balloon content
</Balloon.Tooltip>
);
Expand Down
Loading

0 comments on commit adde9ed

Please sign in to comment.