From ecb2132be3778e2302d272298fef638221871c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E6=B0=B8=E8=B6=85?= <827048737@qq.com> Date: Tue, 15 Dec 2020 12:10:38 +0800 Subject: [PATCH 1/2] feat(Switch): test --- .../packages/switch/__tests__/Switch.spec.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/element3/packages/switch/__tests__/Switch.spec.js b/packages/element3/packages/switch/__tests__/Switch.spec.js index 17b3656a5..231b28e42 100644 --- a/packages/element3/packages/switch/__tests__/Switch.spec.js +++ b/packages/element3/packages/switch/__tests__/Switch.spec.js @@ -162,4 +162,17 @@ describe('Switch', () => { expect(wrapper.emitted('update:modelValue')).toEqual([['3']]) }) + it('handleClick', async () => { + const wrapper = mount(Switch, { + props: { + isChecked: true, + disabled: false, + activeValue: '2', + inactiveValue: '3' + } + }) + await wrapper.find('.el-switch').trigger('click') + expect(wrapper.emitted('update:modelValue')).toEqual([['3'], ['2']]) + expect(wrapper.emitted('update:change')).toEqual([['2']]) + }) }) From a5319dd22607acaf892d98156f20be0fe2ffa817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E6=B0=B8=E8=B6=85?= <827048737@qq.com> Date: Wed, 16 Dec 2020 11:14:21 +0800 Subject: [PATCH 2/2] fix(slider): test --- packages/element3/packages/slider/Slider.vue | 83 ++++++++++++------- .../packages/slider/__tests__/Slider.spec.js | 82 +++++++++++++++--- .../element3/packages/slider/src/button.vue | 48 ++++++----- 3 files changed, 149 insertions(+), 64 deletions(-) diff --git a/packages/element3/packages/slider/Slider.vue b/packages/element3/packages/slider/Slider.vue index 7a40e80ce..6253e36a6 100644 --- a/packages/element3/packages/slider/Slider.vue +++ b/packages/element3/packages/slider/Slider.vue @@ -1,7 +1,7 @@ @@ -126,7 +123,7 @@ export default { displayTooltip, hideTooltip ) - + const buttonClass = useButtonClasses(hovering, dragging) return { // data hovering, @@ -161,17 +158,19 @@ export default { onLeftKeyDown, onRightKeyDown, // ref - tooltip + tooltip, + // classs + buttonClass } } } -function useToolTip(ctx) { - function displayTooltip() { +const useToolTip = (ctx) => { + const displayTooltip = () => { ctx.tooltip && (ctx.tooltip.showPopper = true) } - function hideTooltip() { + const hideTooltip = () => { ctx.tooltip && (ctx.tooltip.showPopper = false) } return { @@ -180,21 +179,21 @@ function useToolTip(ctx) { } } -function useMouseHover(displayTooltip, hideTooltip) { +const useMouseHover = (displayTooltip, hideTooltip) => { const hovering = ref(false) - function handleMouseEnter() { + const handleMouseEnter = () => { hovering.value = true displayTooltip() } - function handleMouseLeave() { + const handleMouseLeave = () => { hovering.value = false hideTooltip() } return { hovering, handleMouseEnter, handleMouseLeave } } -function useDragAndKeyDown( +const useDragAndKeyDown = ( parent, ctx, emit, @@ -208,7 +207,7 @@ function useDragAndKeyDown( currentPosition, displayTooltip, hideTooltip -) { +) => { const { resetSize, emitChange } = parent.ctx const dragging = ref(false) @@ -237,7 +236,7 @@ function useDragAndKeyDown( window.addEventListener('contextmenu', onDragEnd) } - function onDragStart(event) { + const onDragStart = (event) => { dragging.value = true isClick.value = true if (event.type === 'touchstart') { @@ -253,7 +252,7 @@ function useDragAndKeyDown( newPosition.value = unref(startPosition) } - function onDragging(event) { + const onDragging = (event) => { if (unref(dragging)) { isClick.value = false displayTooltip() @@ -275,7 +274,7 @@ function useDragAndKeyDown( } } - function onDragEnd() { + const onDragEnd = () => { if (unref(dragging)) { /* * 防止在 mouseup 后立即触发 click,导致滑块有几率产生一小段位移 @@ -302,7 +301,7 @@ function useDragAndKeyDown( // eslint-disable-next-line //#region KeyDown methods: onLeftKeyDown, onRightKeyDown - function onLeftKeyDown() { + const onLeftKeyDown = () => { if (unref(disabled)) return newPosition.value = parseFloat(unref(currentPosition)) - @@ -310,7 +309,7 @@ function useDragAndKeyDown( setPosition(unref(newPosition)) emitChange() } - function onRightKeyDown() { + const onRightKeyDown = () => { if (unref(disabled)) return newPosition.value = parseFloat(unref(currentPosition)) + @@ -322,7 +321,7 @@ function useDragAndKeyDown( // eslint-disable-next-line //#endregion - function setPosition(newPosition) { + const setPosition = (newPosition) => { if (newPosition === null || isNaN(newPosition)) return if (newPosition < 0) { newPosition = 0 @@ -365,7 +364,7 @@ function useDragAndKeyDown( } } -function useComputed(modelValue, vertical) { +const useComputed = (modelValue, vertical) => { const { parent } = getCurrentInstance() const disabled = computed(() => parent.ctx.sliderDisabled) @@ -404,4 +403,9 @@ function useComputed(modelValue, vertical) { wrapperStyle } } +const useButtonClasses = (hovering, dragging) => { + return computed(() => { + return [hovering.value ? 'hover' : '', dragging.value ? 'dragging' : ''] + }) +}