Files
react/components/auto-complete/__tests__/index.test.tsx
witt d4a1e02430 feat(scaleable): add scaleable props to each component (#531)
* feat(scaleable): add scaleable props to each component

* chore(scaleable): update the exported type

* feat: apply scaleable to components

chore: remove with-default

test: improve testcase for scaleable

chore: resolve test warning

ci: upgrade nodejs to latest lts

docs: fix type error in document site

* docs: update documents to be compatible with scaleable

chore: fix build errors

* chore: remove all size-related attributes

docs: improve guide document

* docs: add scaleable documentation

test: update snapshots

chore: remove unused

* feat: add scaleable to grid components

* docs: improve docs

* test: update snapshots

* fix(grid): fix basic component props
2021-06-23 10:53:30 +08:00

67 lines
2.1 KiB
TypeScript

import React from 'react'
import { mount } from 'enzyme'
import { AutoComplete } from 'components'
import { nativeEvent } from 'tests/utils'
import { act } from 'react-dom/test-utils'
describe('AutoComplete', () => {
it('should render correctly', () => {
const wrapper = mount(<AutoComplete />)
expect(() => wrapper.unmount()).not.toThrow()
expect(<AutoComplete />).toMatchSnapshot()
})
it('should support sizes and status', () => {
const wrapper = mount(
<div>
<AutoComplete type="secondary" />
<AutoComplete type="success" />
<AutoComplete />
<AutoComplete />
</div>,
)
expect(() => wrapper.unmount()).not.toThrow()
})
it('should set input value from initial value', () => {
let wrapper = mount(<AutoComplete initialValue="value" />)
let input = wrapper.find('input').at(0).getDOMNode()
expect((input as HTMLInputElement).value).toEqual('value')
wrapper = mount(<AutoComplete value="value2" />)
input = wrapper.find('input').at(0).getDOMNode()
expect((input as HTMLInputElement).value).toEqual('value2')
})
it('should render clear icon', async () => {
const wrapper = mount(<AutoComplete initialValue="value" />)
expect(wrapper.find('svg').length).toBe(0)
await act(async () => {
wrapper.setProps({ clearable: true })
})
expect(wrapper.find('svg').length).toBe(1)
wrapper.find('svg').simulate('click', nativeEvent)
const input = wrapper.find('input').at(0).getDOMNode()
expect((input as HTMLInputElement).value).toEqual('')
})
it('should reponse width change', async () => {
const wrapper = mount(<AutoComplete initialValue="value" width="100px" />)
expect(wrapper.prop('width')).toEqual('100px')
await act(async () => {
wrapper.setProps({ width: '200px' })
})
expect(wrapper.prop('width')).toEqual('200px')
})
it('should forward ref by default', () => {
const ref = React.createRef<HTMLInputElement>()
const wrapper = mount(<AutoComplete ref={ref} />)
expect(ref.current).not.toBeNull()
expect(() => wrapper.unmount()).not.toThrow()
})
})