feat(input): add test (#1177)

This commit is contained in:
XieZongChen 2021-09-14 03:57:40 -05:00 committed by GitHub
parent 94f9545056
commit 5fa436b6a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 0 deletions

View File

@ -5,6 +5,7 @@ describe('n-input', () => {
it('should work with import on demand', () => {
mount(NInput)
})
it('should call input callbacks', async () => {
const onUpdateValue = jest.fn()
const wrapper = mount(NInput, {
@ -16,6 +17,7 @@ describe('n-input', () => {
await wrapper.find('input').trigger('input')
expect(onUpdateValue).toHaveBeenCalledWith('cool')
})
it('`loading` prop', async () => {
const wrapper = mount(NInput)
expect(wrapper.find('.n-input__suffix').exists()).toBe(false)
@ -27,6 +29,67 @@ describe('n-input', () => {
expect(wrapper.find('.n-base-loading__icon').exists()).toBe(true)
wrapper.unmount()
})
it('should work with `clearable` prop', async () => {
const wrapper = mount(NInput)
expect(wrapper.find('.n-base-clear').exists()).not.toBe(true)
await wrapper.setProps({
clearable: true
})
expect(wrapper.find('.n-base-clear').exists()).toBe(true)
wrapper.unmount()
})
it('should work with `disabled` prop', async () => {
const wrapper = mount(NInput)
expect(wrapper.find('.n-input').classes()).not.toContain(
'n-input--disabled'
)
await wrapper.setProps({
disabled: true
})
expect(wrapper.find('.n-input').classes()).toContain('n-input--disabled')
wrapper.unmount()
})
it('should work with `placeholder` prop', async () => {
const wrapper = mount(NInput)
expect(wrapper.find('input').attributes('placeholder')).toBe('Please Input')
await wrapper.setProps({
placeholder: 'test-placeholder'
})
expect(wrapper.find('input').attributes('placeholder')).toBe(
'test-placeholder'
)
wrapper.unmount()
})
it('should work with `readonly` prop', async () => {
const wrapper = mount(NInput)
expect(wrapper.find('input').attributes('readonly')).not.toBe('')
await wrapper.setProps({ readonly: true })
expect(wrapper.find('input').attributes('readonly')).toBe('')
wrapper.unmount()
})
it('should work with `round` prop', async () => {
const wrapper = mount(NInput)
expect(wrapper.find('.n-input').classes()).not.toContain('n-input--round')
await wrapper.setProps({ round: true })
expect(wrapper.find('.n-input').classes()).toContain('n-input--round')
wrapper.unmount()
})
it('should work with `size` prop', async () => {
;(['small', 'medium', 'large'] as const).forEach((size) => {
const wrapper = mount(NInput, { props: { size: size } })
expect(wrapper.find('.n-input').attributes('style')).toMatchSnapshot()
wrapper.unmount()
})
})
it('should work with `type` prop', async () => {
const wrapper = mount(NInput)
await wrapper.setProps({ type: 'text' })

View File

@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`n-input should work with \`size\` prop 1`] = `"--bezier: cubic-bezier(.4, 0, .2, 1); --count-text-color: rgb(158, 164, 170); --color: rgba(255, 255, 255, 1); --font-size: 14px; --border-radius: 3px; --height: 28px; --padding-left: 10px; --padding-right: 10px; --text-color: rgb(51, 54, 57); --caret-color: #18a058; --text-decoration-color: rgb(51, 54, 57); --border: 1px solid rgb(224, 224, 230); --border-disabled: 1px solid rgb(224, 224, 230); --border-hover: 1px solid #36ad6a; --border-focus: 1px solid #36ad6a; --placeholder-color: rgba(194, 194, 194, 1); --placeholder-color-disabled: rgba(209, 209, 209, 1); --icon-size: 16px; --line-height-textarea: 1.6; --color-disabled: rgb(250, 250, 252); --color-focus: rgba(255, 255, 255, 1); --text-color-disabled: rgba(194, 194, 194, 1); --box-shadow-focus: 0 0 0 2px rgba(24, 160, 88, 0.2); --loading-color: #18a058; --caret-color-warning: #f0a020; --color-focus-warning: rgba(255, 255, 255, 1); --box-shadow-focus-warning: 0 0 0 2px rgba(240, 160, 32, 0.2); --border-warning: 1px solid #f0a020; --border-focus-warning: 1px solid #fcb040; --border-hover-warning: 1px solid #fcb040; --loading-color-warning: #f0a020; --caret-color-error: #d03050; --color-focus-error: rgba(255, 255, 255, 1); --box-shadow-focus-error: 0 0 0 2px rgba(208, 48, 80, 0.2); --border-error: 1px solid #d03050; --border-focus-error: 1px solid #de576d; --border-hover-error: 1px solid #de576d; --loading-color-error: #d03050; --clear-color: rgba(194, 194, 194, 1); --clear-size: 16px; --clear-color-hover: rgba(146, 146, 146, 1); --clear-color-pressed: rgba(175, 175, 175, 1); --icon-color: rgba(194, 194, 194, 1); --icon-color-hover: rgba(146, 146, 146, 1); --icon-color-pressed: rgba(175, 175, 175, 1); --icon-color-disabled: rgba(209, 209, 209, 1); --suffix-text-color: rgb(51, 54, 57);"`;
exports[`n-input should work with \`size\` prop 2`] = `"--bezier: cubic-bezier(.4, 0, .2, 1); --count-text-color: rgb(158, 164, 170); --color: rgba(255, 255, 255, 1); --font-size: 14px; --border-radius: 3px; --height: 34px; --padding-left: 12px; --padding-right: 12px; --text-color: rgb(51, 54, 57); --caret-color: #18a058; --text-decoration-color: rgb(51, 54, 57); --border: 1px solid rgb(224, 224, 230); --border-disabled: 1px solid rgb(224, 224, 230); --border-hover: 1px solid #36ad6a; --border-focus: 1px solid #36ad6a; --placeholder-color: rgba(194, 194, 194, 1); --placeholder-color-disabled: rgba(209, 209, 209, 1); --icon-size: 16px; --line-height-textarea: 1.6; --color-disabled: rgb(250, 250, 252); --color-focus: rgba(255, 255, 255, 1); --text-color-disabled: rgba(194, 194, 194, 1); --box-shadow-focus: 0 0 0 2px rgba(24, 160, 88, 0.2); --loading-color: #18a058; --caret-color-warning: #f0a020; --color-focus-warning: rgba(255, 255, 255, 1); --box-shadow-focus-warning: 0 0 0 2px rgba(240, 160, 32, 0.2); --border-warning: 1px solid #f0a020; --border-focus-warning: 1px solid #fcb040; --border-hover-warning: 1px solid #fcb040; --loading-color-warning: #f0a020; --caret-color-error: #d03050; --color-focus-error: rgba(255, 255, 255, 1); --box-shadow-focus-error: 0 0 0 2px rgba(208, 48, 80, 0.2); --border-error: 1px solid #d03050; --border-focus-error: 1px solid #de576d; --border-hover-error: 1px solid #de576d; --loading-color-error: #d03050; --clear-color: rgba(194, 194, 194, 1); --clear-size: 16px; --clear-color-hover: rgba(146, 146, 146, 1); --clear-color-pressed: rgba(175, 175, 175, 1); --icon-color: rgba(194, 194, 194, 1); --icon-color-hover: rgba(146, 146, 146, 1); --icon-color-pressed: rgba(175, 175, 175, 1); --icon-color-disabled: rgba(209, 209, 209, 1); --suffix-text-color: rgb(51, 54, 57);"`;
exports[`n-input should work with \`size\` prop 3`] = `"--bezier: cubic-bezier(.4, 0, .2, 1); --count-text-color: rgb(158, 164, 170); --color: rgba(255, 255, 255, 1); --font-size: 15px; --border-radius: 3px; --height: 40px; --padding-left: 14px; --padding-right: 14px; --text-color: rgb(51, 54, 57); --caret-color: #18a058; --text-decoration-color: rgb(51, 54, 57); --border: 1px solid rgb(224, 224, 230); --border-disabled: 1px solid rgb(224, 224, 230); --border-hover: 1px solid #36ad6a; --border-focus: 1px solid #36ad6a; --placeholder-color: rgba(194, 194, 194, 1); --placeholder-color-disabled: rgba(209, 209, 209, 1); --icon-size: 16px; --line-height-textarea: 1.6; --color-disabled: rgb(250, 250, 252); --color-focus: rgba(255, 255, 255, 1); --text-color-disabled: rgba(194, 194, 194, 1); --box-shadow-focus: 0 0 0 2px rgba(24, 160, 88, 0.2); --loading-color: #18a058; --caret-color-warning: #f0a020; --color-focus-warning: rgba(255, 255, 255, 1); --box-shadow-focus-warning: 0 0 0 2px rgba(240, 160, 32, 0.2); --border-warning: 1px solid #f0a020; --border-focus-warning: 1px solid #fcb040; --border-hover-warning: 1px solid #fcb040; --loading-color-warning: #f0a020; --caret-color-error: #d03050; --color-focus-error: rgba(255, 255, 255, 1); --box-shadow-focus-error: 0 0 0 2px rgba(208, 48, 80, 0.2); --border-error: 1px solid #d03050; --border-focus-error: 1px solid #de576d; --border-hover-error: 1px solid #de576d; --loading-color-error: #d03050; --clear-color: rgba(194, 194, 194, 1); --clear-size: 16px; --clear-color-hover: rgba(146, 146, 146, 1); --clear-color-pressed: rgba(175, 175, 175, 1); --icon-color: rgba(194, 194, 194, 1); --icon-color-hover: rgba(146, 146, 146, 1); --icon-color-pressed: rgba(175, 175, 175, 1); --icon-color-disabled: rgba(209, 209, 209, 1); --suffix-text-color: rgb(51, 54, 57);"`;