Skip to content

Commit

Permalink
fix: fix bug of model and fix animation of transfer add test code
Browse files Browse the repository at this point in the history
  • Loading branch information
wuls committed Oct 1, 2020
1 parent aa14dc2 commit d435460
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 deletions.
43 changes: 43 additions & 0 deletions packages/message-box/__tests__/MessageBox.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mount } from '@vue/test-utils'
import { ref } from 'vue'
import MessageBox from '../src/main.vue'
describe('MessageBox.vue', () => {
afterEach(() => {
Expand All @@ -22,6 +23,48 @@ describe('MessageBox.vue', () => {
closeOnClickModal: false
}
})
const _messagebox = messagebox.find('.el-message-box__message')
expect(_messagebox.text()).toBe('message')
expect(messagebox.find('.el-message-box__wrapper').exists()).toBe(true)
})

test('dangerouslyUseHTMLString', async () => {
const messagebox = await mount(MessageBox, {
props: {
title: 'title',
message: '<div>message</div>',
_type: 'alert',
closeOnPressEscape: false,
closeOnClickModal: false,
dangerouslyUseHTMLString: true
}
})
const _messagebox = messagebox.find('.el-message-box__message')
expect(_messagebox.text()).toBe('message')
})

test('test dome click', async () => {
const callBackAction = ref(null)
const messagebox = await mount(MessageBox, {
props: {
title: 'title',
message: '<div>message</div>',
_type: 'alert',
cancelButtonClass: 'el-cccc',
closeOnPressEscape: false,
closeOnClickModal: false,
showCancelButton: true,
dangerouslyUseHTMLString: true,
callback: (action) => {
callBackAction.value = action
}
}
})
await messagebox.find('.el-cccc').trigger('click')
const w = messagebox.find('.el-message-box__title span')
expect(w.text()).toBe('title')
setTimeout(() => {
expect(callBackAction.value).toBe('cancel')
})
})
})
30 changes: 18 additions & 12 deletions packages/message-box/src/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default {
},
beforeClose: {
type: Function,
default: () => {}
default: null
},
distinguishCancelAndClose: {
type: Boolean,
Expand Down Expand Up @@ -292,7 +292,7 @@ export default {
inputValue
} = toRefs(props)
const state = reactive({
visible: true,
visible: false,
action: null,
editorErrorMessage: null,
uid: 0,
Expand Down Expand Up @@ -365,7 +365,6 @@ export default {
return
}
state.action = action
if (typeof unref(beforeClose) === 'function') {
const close = getSafeClose()
unref(beforeClose)(action, instance.proxy, close)
Expand All @@ -374,7 +373,13 @@ export default {
}
}
const handleWrapperClick = () => {
if (!unref(closeOnClickModal)) {
if (unref(closeOnClickModal)) {
handleAction(unref(distinguishCancelAndClose) ? 'close' : 'cancel')
}
}
const handleKeyup = (element = {}) => {
if (element.code !== 'Escape') return
if (unref(props.closeOnPressEscape)) {
handleAction(unref(distinguishCancelAndClose) ? 'close' : 'cancel')
}
}
Expand All @@ -392,10 +397,10 @@ export default {
)
})
const cancelButtonClasses = computed(() => {
return `${cancelButtonClass}`
return `el-button--primary ${unref(cancelButtonClass)}`
})
const confirmButtonClasses = computed(() => {
return `el-button--primary ${confirmButtonClass}`
return `el-button--primary ${unref(confirmButtonClass)}`
})
const getFirstFocus = () => {
const btn = instance.ctx.$el.querySelector(
Expand All @@ -411,6 +416,7 @@ export default {
return inputRefs.input || inputRefs.textarea
}
onMounted(() => {
state.visible = true
nextTick(() => {
state.uid++
rendered.value = true
Expand All @@ -427,22 +433,22 @@ export default {
focusAfterClosed,
getFirstFocus()
)
if (unref(closeOnHashChange)) {
window.addEventListener('hashchange', doClose)
}
window.addEventListener('keyup', handleKeyup)
if (unref(_type) !== 'prompt') return
setTimeout(() => {
if (instance.refs.input && instance.refs.input.$el) {
getInputElement().focus()
}
}, 500)
nextTick(() => {
if (unref(closeOnHashChange)) {
window.addEventListener('hashchange', () => {})
}
})
})
onUnmounted(() => {
if (unref(closeOnHashChange)) {
window.removeEventListener('hashchange', () => {})
window.removeEventListener('hashchange', doClose)
}
window.removeEventListener('keyup', handleKeyup)
setTimeout(() => {
messageBox.closeDialog()
})
Expand Down

0 comments on commit d435460

Please sign in to comment.