Merge pull request #130 from unix/test

test: add test cases
This commit is contained in:
witt
2020-04-25 00:06:56 +08:00
committed by GitHub
5 changed files with 5043 additions and 5 deletions

View File

@@ -0,0 +1,97 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Spacer should render correctly 1`] = `
"<span class=\\"\\"><style>
span {
display: block;
height: 1px;
width: 1px;
margin-left: calc(15.25pt + 1px * 0);
margin-top: calc(15.25pt + 1px * 0);
}
</style></span>"
`;
exports[`Spacer should support x and y 1`] = `
"<div><span class=\\"\\"><style>
span {
display: block;
height: 1px;
width: 1px;
margin-left: calc(76.25pt + 1px * 4);
margin-top: calc(15.25pt + 1px * 0);
}
</style></span><span class=\\"\\"><style>
span {
display: block;
height: 1px;
width: 1px;
margin-left: calc(228.75pt + 1px * 14);
margin-top: calc(15.25pt + 1px * 0);
}
</style></span><span class=\\"\\"><style>
span {
display: block;
height: 1px;
width: 1px;
margin-left: calc(15.25pt + 1px * 0);
margin-top: calc(228.75pt + 1px * 14);
}
</style></span><span class=\\"\\"><style>
span {
display: block;
height: 1px;
width: 1px;
margin-left: calc(15.25pt + 1px * 0);
margin-top: calc(30.5pt + 1px * 1);
}
</style></span></div>"
`;
exports[`Spacer should work with float 1`] = `
"<div><span class=\\"\\"><style>
span {
display: block;
height: 1px;
width: 1px;
margin-left: calc(33.550000000000004pt + 1px * 1.2000000000000002);
margin-top: calc(15.25pt + 1px * 0);
}
</style></span><span class=\\"\\"><style>
span {
display: block;
height: 1px;
width: 1px;
margin-left: calc(22.875pt + 1px * 0.5);
margin-top: calc(15.25pt + 1px * 0);
}
</style></span><span class=\\"\\"><style>
span {
display: block;
height: 1px;
width: 1px;
margin-left: calc(15.25pt + 1px * 0);
margin-top: calc(1.5250000000000001pt + 1px * -0.9);
}
</style></span><span class=\\"\\"><style>
span {
display: block;
height: 1px;
width: 1px;
margin-left: calc(15.25pt + 1px * 0);
margin-top: calc(27.45pt + 1px * 0.8);
}
</style></span></div>"
`;
exports[`Spacer should work with inline mode 1`] = `
"<span class=\\"\\"><style>
span {
display: inline-block;
height: 1px;
width: 1px;
margin-left: calc(15.25pt + 1px * 0);
margin-top: calc(15.25pt + 1px * 0);
}
</style></span>"
`;

View File

@@ -0,0 +1,43 @@
import React from 'react'
import { mount } from 'enzyme'
import { Spacer } from 'components'
describe('Spacer', () => {
it('should render correctly', () => {
const wrapper = mount(<Spacer />)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should support x and y', () => {
const wrapper = mount(
<div>
<Spacer x={5} />
<Spacer x={15} />
<Spacer y={15} />
<Spacer y={2} />
</div>
)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should work with float', () => {
const wrapper = mount(
<div>
<Spacer x={2.2} />
<Spacer x={1.5} />
<Spacer y={0.1} />
<Spacer y={1.8} />
</div>
)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should work with inline mode', () => {
const wrapper = mount(<Spacer inline />)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
})

View File

@@ -1,6 +1,5 @@
import React from 'react'
import withDefaults from '../utils/with-defaults'
import useWarning from '../utils/use-warning'
interface Props {
x?: number
@@ -20,10 +19,6 @@ type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
export type SpacerProps = Props & typeof defaultProps & NativeAttrs
export const getMargin = (num: number): string => {
if (num < 0) {
useWarning('Props "x"/"y" must be greater than or equal to 0', 'Spacer')
return '0'
}
return `calc(${num * 15.25}pt + 1px * ${num - 1})`
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,24 @@
import React from 'react'
import { mount } from 'enzyme'
import { Spinner } from 'components'
describe('Spacer', () => {
it('should render correctly', () => {
const wrapper = mount(<Spinner />)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
it('should work with different sizes', () => {
const wrapper = mount(
<div>
<Spinner size="mini" />
<Spinner size="small" />
<Spinner size="medium" />
<Spinner size="large" />
</div>
)
expect(wrapper.html()).toMatchSnapshot()
expect(() => wrapper.unmount()).not.toThrow()
})
})