Skip to content

Commit

Permalink
test: update cases & snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyan0205 committed Jan 26, 2019
1 parent 88ff9d6 commit d30defb
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 38 deletions.
2 changes: 1 addition & 1 deletion components/picker/test/__snapshots__/demo.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ exports[`Picker - Demo Display in Popup 1`] = `
<div class="md-picker-column-list">
<div class="md-picker-column-item">
<ul class="column-list" style="padding-top: 100px;">
<li class="column-item" style="height: 45px; line-height: 45px;">2015</li>
<li class="column-item active" style="height: 45px; line-height: 45px;">2015</li>
<li class="column-item" style="height: 45px; line-height: 45px;">2016</li>
<li class="column-item" style="height: 45px; line-height: 45px;">2017</li>
<li class="column-item" style="height: 45px; line-height: 45px;">2018</li>
Expand Down
28 changes: 25 additions & 3 deletions components/popup/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
import {Popup} from 'mand-mobile'
import {mount} from '@vue/test-utils'
import sinon from 'sinon'
import {shallowMount} from '@vue/test-utils'
import triggerTouch from './touch-trigger'

describe('Popup', () => {
describe('Popup - Operation', () => {
let wrapper

afterEach(() => {
wrapper && wrapper.destroy()
})

it('popup show/hide', done => {
wrapper = shallowMount(Popup, {
propsData: {
value: false,
},
})
const eventSpy = sinon.spy(wrapper.vm, '$emit')
wrapper.setProps({value: true})
setTimeout(() => {
expect(eventSpy.calledWith('beforeShow')).toBe(true)

const mask = wrapper.find('.md-popup-mask')
mask.trigger('click')
expect(eventSpy.calledWith('maskClick')).toBe(true)
expect(eventSpy.calledWith('input')).toBe(true)
expect(eventSpy.calledWith('beforeHide')).toBe(true)
done()
}, 50)
// expect(eventSpy.calledWith('before-show')).toBe(true)
})

it('popup prevent scroll', done => {
wrapper = mount(Popup, {
wrapper = shallowMount(Popup, {
propsData: {
preventScroll: true,
value: true,
Expand Down
4 changes: 2 additions & 2 deletions components/progress/test/__snapshots__/demo.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ exports[`Progress Basic 1`] = `
exports[`Progress Other configurations 1`] = `
<div class="md-example-child md-example-child-progress">
<div class="md-activity-indicator-rolling md-progress">
<div class="rolling-container"><svg viewBox="0 0 120 120" preserveAspectRatio="xMidYMid" class="md-activity-indicator-svg rolling" style="width:100px;height:100px;transform:rotateZ(0deg);">
<div class="rolling-container"><svg viewBox="0 0 120 120" preserveAspectRatio="xMidYMid" class="md-activity-indicator-svg rolling" style="width: 100px; height: 100px; transform: rotateZ(0deg);">
<circle fill="none" stroke="#FFF" stroke-width="10" cx="60" cy="60" r="50"></circle>
<g class="circle">
<circle cx="60" cy="60" fill="transparent" stroke="url(#linear)" stroke-width="10" stroke-dasharray="251.32000000000005 62.82999999999999" stroke-linecap="butt" r="50" class="stroke">
Expand All @@ -66,7 +66,7 @@ exports[`Progress Other configurations 1`] = `
</div>
</div>
<div class="md-activity-indicator-rolling md-progress">
<div class="rolling-container"><svg viewBox="0 0 120 120" preserveAspectRatio="xMidYMid" class="md-activity-indicator-svg rolling" style="width:100px;height:100px;transform:rotateZ(-90deg);">
<div class="rolling-container"><svg viewBox="0 0 120 120" preserveAspectRatio="xMidYMid" class="md-activity-indicator-svg rolling" style="width: 100px; height: 100px; transform: rotateZ(-90deg);">
<circle fill="none" stroke="rgba(0, 0, 0, .1)" stroke-width="10" cx="60" cy="60" r="50"></circle>
<g class="circle">
<circle cx="60" cy="60" fill="transparent" stroke="#FF5257" stroke-width="10" stroke-dasharray="0 314.15000000000003" stroke-linecap="round" r="50" class="stroke">
Expand Down
4 changes: 3 additions & 1 deletion components/progress/test/demo.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Demo0 from './cases/demo0'
import Demo1 from './cases/demo1'
import {renderToString} from '@vue/server-test-utils'
import {mount} from '@vue/test-utils'

describe('Progress', () => {
test(`Basic`, () => {
expect(renderToString(Demo0)).toMatchSnapshot()
})
test(`Other configurations`, () => {
expect(renderToString(Demo1)).toMatchSnapshot()
const wrapper = mount(Demo1)
expect(wrapper.html()).toMatchSnapshot()
})
})
93 changes: 93 additions & 0 deletions components/radio/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {Radio, RadioList} from 'mand-mobile'
import {mount} from '@vue/test-utils'
import triggerTouch from '../../popup/test/touch-trigger'

describe('Radio', () => {
let wrapper

afterEach(() => {
wrapper && wrapper.destroy()
})

it('create a radio', () => {
let name = ''
wrapper = mount(Radio, {
propsData: {
name: '123',
},
listeners: {
input(val) {
name = val
},
},
})
wrapper.find('.md-radio').trigger('click')
expect(name).toEqual('123')
})

it('create a radio list', done => {
let value = 0
wrapper = mount(RadioList, {
propsData: {
value,
options: [{value: 0, text: '选项1'}, {value: 1, text: '选项2', disabled: true}, {value: 2, text: '选项3'}],
defaultIndex: 1,
},
listeners: {
input(val) {
value = val
},
},
})

expect(wrapper.findAll('.md-radio-item').length).toEqual(3)
wrapper
.findAll('.md-radio-item')
.at(1)
.trigger('click')
expect(
wrapper
.findAll('.md-radio-item')
.at(0)
.classes('is-selected'),
).toBe(true)
wrapper
.findAll('.md-radio-item')
.at(2)
.trigger('click')
expect(value).toEqual(2)
wrapper.vm.select(1)
expect(value).toEqual(1)
wrapper.vm.selectByIndex(2)
expect(value).toEqual(2)

wrapper.setProps({value: 1})

wrapper.vm.options = [{text: '选项1'}, {text: '选项2'}]
wrapper.vm.$nextTick(() => {
expect(wrapper.findAll('.md-radio-item').length).toEqual(2)
done()
})
})

it('create a radio list with input', () => {
let value = 0
wrapper = mount(RadioList, {
propsData: {
value,
options: [{value: 0, text: '选项1'}, {value: 1, text: '选项2'}, {value: 2, text: '选项3'}],
hasInput: true,
},
listeners: {
input(val) {
value = val
},
},
})

const input = wrapper.find('.md-input-item-input')
input.trigger('focus')
triggerTouch(input.element, 'input', 0, 0, '123')
expect(value).toEqual('123')
})
})
20 changes: 19 additions & 1 deletion components/scroll-view/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ScrollViewMore from 'mand-mobile/components/scroll-view/more'
import ScrollViewContent from './scroll-view-content'
import sinon from 'sinon'
import {mount} from '@vue/test-utils'
import triggerTouch from '../../popup/test/touch-trigger'

describe('ScrollView', () => {
let wrapper
Expand All @@ -14,12 +15,27 @@ describe('ScrollView', () => {

it('create scroll-view', () => {
wrapper = mount(ScrollView, {
propsData: {
autoReflow: true,
},
slots: {
default: ScrollViewContent,
},
})
// const eventStub = sinon.stub(wrapper.vm, '$emit')
wrapper.vm.scrollTo(0, 50, true)

wrapper.vm.init()

const scrollView = wrapper.find('.md-scroll-view')
triggerTouch(scrollView.element, 'touchstart', 0, 0)
triggerTouch(scrollView.element, 'touchmove', 0, -50)
triggerTouch(scrollView.element, 'touchend', 0, -50)

wrapper.vm.scrollTo(0, 0, true)

triggerTouch(scrollView.element, 'mousedown', 0, 0)
triggerTouch(scrollView.element, 'mousemove', 0, -50)
triggerTouch(scrollView.element, 'mouseup', 0, -50)
})

it('scroll-view pull refresh', done => {
Expand All @@ -36,6 +52,7 @@ describe('ScrollView', () => {
wrapper.vm.triggerRefresh()
setTimeout(() => {
expect(eventStub.calledWith('refreshing')).toBe(true)
wrapper.vm.finishRefresh()
done()
}, 500)
})
Expand All @@ -50,5 +67,6 @@ describe('ScrollView', () => {

const eventStub = sinon.stub(wrapper.vm, '$emit')
expect(wrapper.findAll('.scroll-view-more').length > 0).toBe(true)
wrapper.vm.finishLoadMore()
})
})
4 changes: 2 additions & 2 deletions components/selector/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Selector - Operation', () => {
test('selector events choose', done => {
wrapper = mount(Selector, {
propsData: {
value: true,
value: false,
data: [
{
value: '1',
Expand All @@ -47,7 +47,7 @@ describe('Selector - Operation', () => {
})

const eventStub = sinon.stub(wrapper.vm, '$emit')

wrapper.setProps({value: true})
wrapper.vm.$nextTick(() => {
wrapper.find('.md-radio-item').trigger('click')
expect(wrapper.vm.tmpActiveIndex).toBe(0)
Expand Down
29 changes: 25 additions & 4 deletions components/stepper/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Stepper} from 'mand-mobile'
import {mount} from '@vue/test-utils'
import triggerTouch from '../../popup/test/touch-trigger'

describe('Stepper Operation', () => {
let wrapper
Expand All @@ -9,11 +10,19 @@ describe('Stepper Operation', () => {
})

test('stepper method reduce', () => {
wrapper = mount(Stepper)
wrapper.vm.currentNum = 1
wrapper.vm.step = 2
wrapper = mount(Stepper, {
propsData: {
value: 1,
step: 2,
},
})
wrapper.setProps({value: 2})
wrapper.find('.md-stepper-button-reduce').trigger('click')
expect(Number(wrapper.vm.currentNum)).toBe(-1)
expect(Number(wrapper.vm.currentNum)).toBe(0)

wrapper.setProps({disabled: true})
wrapper.find('.md-stepper-button-reduce').trigger('click')
expect(Number(wrapper.vm.currentNum)).toBe(0)
})

test('stepper method add', () => {
Expand All @@ -22,6 +31,10 @@ describe('Stepper Operation', () => {
wrapper.vm.step = 2
wrapper.find('.md-stepper-button-add').trigger('click')
expect(wrapper.vm.currentNum).toBe(3)

wrapper.setProps({disabled: true})
wrapper.find('.md-stepper-button-add').trigger('click')
expect(wrapper.vm.currentNum).toBe(3)
})

test('stepper method getCurrentNum', () => {
Expand Down Expand Up @@ -55,6 +68,14 @@ describe('Stepper Operation', () => {
expect(wrapper.vm.isMin).toBe(true)
})

test('stepper input', () => {
wrapper = mount(Stepper)
const input = wrapper.find('input')
triggerTouch(input.element, 'focus')
triggerTouch(input.element, 'input', 0, 0, 5)
expect(wrapper.vm.currentNum).toBe(5)
})

test('stepper method onChange', () => {
wrapper = mount(Stepper)
wrapper.vm.currentNum = 2
Expand Down
Loading

0 comments on commit d30defb

Please sign in to comment.