Skip to content

Commit

Permalink
test: model change
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jun 24, 2024
1 parent fc042ef commit c35f9e1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/packages/form/__tests__/Form.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest'
import { mount } from '@vue/test-utils'
import { last } from 'lodash-es'
import { BaseForm, DrawerForm, Field, Form, ModalForm, QueryFilter, Submitter } from '../index'
import mountTest from '../../../../tests/shared/mountTest'

Expand All @@ -25,4 +26,36 @@ describe('Form', () => {
expect(wrapper.emitted()).toHaveProperty('reset')
expect(wrapper.emitted()).toHaveProperty('submit')
})

it(`test BaseForm model change`, async () => {
const wrapper = mount(BaseForm, {
slots: {
default: () => (
<Field
valueType={'text'}
formItemProps={{
name: 'text'
}}
/>
)
}
})
// update:value
await wrapper.find('input').setValue('new value')
expect(wrapper.find('input').element.value).toBe('new value')
expect(last(wrapper.emitted('valuesChange'))).toEqual([{ text: 'new value' }])
// getModelValue
expect(wrapper.vm.getModelValue(['text'])).toEqual('new value')
// setModelValue
expect(wrapper.vm.setModelValue(['text'], 'new text')).toEqual({ text: 'new text' })
expect(last(wrapper.emitted('valuesChange'))).toEqual([{ text: 'new text' }])
// updateModelValue
expect(wrapper.vm.updateModelValue(['text'], (value) => {
return value + ' update'
})).toEqual({ text: 'new text update' })
expect(last(wrapper.emitted('valuesChange'))).toEqual([{ text: 'new text update' }])
// deleteModelValue
expect(wrapper.vm.deleteModelValue(['text'])).toEqual(true)
expect(last(wrapper.emitted('valuesChange'))).toEqual([{}])
})
})

0 comments on commit c35f9e1

Please sign in to comment.