Skip to content

Commit 6f5f889

Browse files
committed
feat: rename classname to className and add related testing
1 parent 4a4c2c7 commit 6f5f889

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/Input.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { SvgBorderedClose } from 'or-icons'
55

66
interface Props {
77
/**
8-
* additional classname
8+
* additional className
99
*/
10-
classname?: string
10+
className?: string
1111

1212
/**
1313
* whether the input box can only enter numbers
@@ -45,13 +45,13 @@ interface Props {
4545
export class Input extends PureComponent<Props, {}> {
4646
render() {
4747
const {
48-
classname,
48+
className,
4949
placeholder = '',
5050
value,
5151
maxlength,
5252
canClear = true
5353
} = this.props
54-
const inputClass = clx(classname, 'or-input')
54+
const inputClass = clx(className, 'or-input')
5555

5656
return (
5757
<div className={inputClass}>
@@ -88,6 +88,7 @@ export class Input extends PureComponent<Props, {}> {
8888

8989
handleClear = () => {
9090
const { onChange } = this.props
91+
/* istanbul ignore next */
9192
if (typeof onChange === 'function') {
9293
onChange('')
9394
}

tests/Input.test.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ describe('src/index', () => {
1414
expect(wrapper.find('.or-input .or-clear-icon').length).toBe(0)
1515
})
1616

17+
it('should render basicly #className', () => {
18+
wrapper = mount(<RenderInput className="hello" />)
19+
expect(wrapper.find('.or-input').length).toBe(1)
20+
expect(wrapper.find('.or-input').hasClass('hello')).toBe(true)
21+
})
22+
1723
it('should render basicly #placeholder', () => {
1824
wrapper = mount(<RenderInput placeholder="name" />)
1925
expect(wrapper.find('.or-input').length).toBe(1)
@@ -22,7 +28,7 @@ describe('src/index', () => {
2228
})
2329
})
2430

25-
describe('simulate events', () => {
31+
describe('simulate events #default', () => {
2632
let wrapper
2733
it('onchange event', () => {
2834
wrapper = mount(<RenderInput />)
@@ -35,6 +41,19 @@ describe('src/index', () => {
3541
})
3642
})
3743

44+
describe('simulate events #numericInput', () => {
45+
let wrapper
46+
it('onchange event', () => {
47+
wrapper = mount(<RenderInput numericInput={true} />)
48+
const input = wrapper.find('.or-input input')
49+
input.simulate('change', { target: { value: '123' } })
50+
expect(wrapper.find('.or-input input').prop('value')).toBe('123')
51+
expect(wrapper.find('.or-input .or-clear-icon').hostNodes().length).toBe(
52+
1
53+
)
54+
})
55+
})
56+
3857
describe('simulate clear input events', () => {
3958
let wrapper
4059
it('onchange event', () => {
@@ -53,6 +72,7 @@ interface Props {
5372
maxlength?: number
5473
placeholder?: string
5574
value?: string
75+
className?: string
5676
}
5777

5878
class RenderInput extends React.Component<Props, {}> {
@@ -64,6 +84,7 @@ class RenderInput extends React.Component<Props, {}> {
6484
return (
6585
<div>
6686
<Input
87+
className={this.props.className}
6788
value={this.state.name}
6889
onChange={this.handleChange}
6990
{...this.props}

0 commit comments

Comments
 (0)