Browse Source

Replace some code with mock function

pull/341/head
Hironsan 5 years ago
parent
commit
02c1215b61
2 changed files with 16 additions and 8 deletions
  1. 10
      frontend/components/organisms/ProjectCreationForm.vue
  2. 14
      frontend/test/unit/components/organisms/ProjecCreationForm.spec.js

10
frontend/components/organisms/ProjectCreationForm.vue

@ -101,14 +101,20 @@ export default {
cancel() {
this.$emit('close')
},
validate() {
return this.$refs.form.validate()
},
reset() {
this.$refs.form.reset()
},
create() {
if (this.$refs.form.validate()) {
if (this.validate()) {
this.createProject({
name: this.name,
description: this.description,
project_type: this.projectType
})
this.$refs.form.reset()
this.reset()
this.cancel()
}
}

14
frontend/test/unit/components/organisms/ProjecCreationForm.spec.js

@ -29,18 +29,20 @@ describe('ProjectCreationForm', () => {
test('emit close event when form is valid', () => {
const wrapper = factory({ createProject, projectTypes })
wrapper.vm.$refs.form = {} // Todo: need more elegant solution
wrapper.vm.$refs.form.validate = () => (true)
wrapper.vm.$refs.form.reset = () => { }
wrapper.setMethods({
validate: jest.fn(() => true),
reset: jest.fn()
})
wrapper.vm.create()
expect(wrapper.emitted('close')).toBeTruthy()
})
test('do not emit close event when form is invalid', () => {
const wrapper = factory({ createProject, projectTypes })
wrapper.vm.$refs.form = {} // Todo: need more elegant solution
wrapper.vm.$refs.form.validate = () => (false)
wrapper.vm.$refs.form.reset = () => { }
wrapper.setMethods({
validate: jest.fn(() => false),
reset: jest.fn()
})
wrapper.vm.create()
expect(wrapper.emitted('close')).toBeFalsy()
})

Loading…
Cancel
Save