forked from didi/mand-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
226 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import {DatePicker} from 'mand-mobile' | ||
import sinon from 'sinon' | ||
import {mount} from '@vue/test-utils' | ||
|
||
describe('DatePicker - Operation', () => { | ||
let wrapper | ||
|
||
afterEach(() => { | ||
wrapper && wrapper.destroy() | ||
}) | ||
|
||
it('create a date picker', done => { | ||
const date = new Date() | ||
wrapper = mount(DatePicker, { | ||
propsData: { | ||
isView: true, | ||
minDate: new Date('2013/9/9'), | ||
maxDate: new Date('2020/9/9'), | ||
defaultDate: date, | ||
todayText: '今天', | ||
}, | ||
}) | ||
const eventSpy = sinon.spy(wrapper.vm, '$emit') | ||
|
||
wrapper.vm.$nextTick(() => { | ||
expect(wrapper.findAll('.md-picker-column-item').length).toEqual(3) | ||
setTimeout(() => { | ||
expect(eventSpy.calledWith('initialed')).toBe(true) | ||
expect(wrapper.vm.getFormatDate('yyyy-MM-dd')).toEqual( | ||
`${date.getFullYear()}-${date.getMonth() + 1 < 10 | ||
? '0' + (date.getMonth() + 1) | ||
: date.getMonth() + 1}-${date.getDate() < 10 ? '0' + date.getDate() : date.getDate()}`, | ||
) | ||
done() | ||
}, 50) | ||
}) | ||
}) | ||
|
||
it('create a time picker', done => { | ||
const date = new Date() | ||
wrapper = mount(DatePicker, { | ||
propsData: { | ||
type: 'time', | ||
unitText: ['', '', '', 'h', 'm'], | ||
halfDayText: ['AM', 'PM'], | ||
isView: true, | ||
defaultDate: date, | ||
maxDate: new Date('2018/9/9'), | ||
}, | ||
}) | ||
|
||
wrapper.vm.$nextTick(() => { | ||
expect(wrapper.findAll('.md-picker-column-item').length).toEqual(2) | ||
done() | ||
}) | ||
}) | ||
|
||
it('create a datetime picker', done => { | ||
const date = new Date() | ||
wrapper = mount(DatePicker, { | ||
propsData: { | ||
type: 'datetime', | ||
isView: true, | ||
defaultDate: date, | ||
minDate: new Date('2020/9/9'), | ||
}, | ||
}) | ||
|
||
wrapper.vm.$nextTick(() => { | ||
expect(wrapper.findAll('.md-picker-column-item').length).toEqual(5) | ||
done() | ||
}) | ||
}) | ||
|
||
it('create a custom picker', done => { | ||
const date = new Date() | ||
wrapper = mount(DatePicker, { | ||
propsData: { | ||
type: 'custom', | ||
value: true, | ||
customTypes: ['dd', 'hh', 'mm'], | ||
isTwelveHours: true, | ||
}, | ||
}) | ||
|
||
wrapper.vm.$nextTick(() => { | ||
expect(wrapper.findAll('.md-picker-column-item').length).toEqual(3) | ||
wrapper.vm.isPickerShow = false | ||
done() | ||
}) | ||
}) | ||
|
||
it('create a popup picker', done => { | ||
const date = new Date() | ||
const minDate = new Date(date.getTime() - 60 * 60 * 24) | ||
const maxDate = new Date(date.getTime() - 60 * 60 * 24) | ||
wrapper = mount(DatePicker, { | ||
propsData: { | ||
value: false, | ||
}, | ||
}) | ||
wrapper.setProps({value: true}) | ||
wrapper.vm.$nextTick(() => { | ||
expect(wrapper.findAll('.md-picker-column-item').length).toEqual(3) | ||
wrapper.setProps({ | ||
defaultDate: date, | ||
minDate, | ||
maxDate, | ||
}) | ||
const cancel = wrapper.find('.md-popup-cancel') | ||
cancel.trigger('click') | ||
setTimeout(() => { | ||
wrapper.setProps({value: true}) | ||
const confirm = wrapper.find('.md-popup-confirm') | ||
confirm.trigger('click') | ||
setTimeout(() => { | ||
done() | ||
}, 300) | ||
}, 300) | ||
}) | ||
}) | ||
|
||
it('defaultDate = maxDate', done => { | ||
const date = new Date() | ||
wrapper = mount(DatePicker, { | ||
propsData: { | ||
isView: true, | ||
type: 'datetime', | ||
defaultDate: date, | ||
maxDate: date, | ||
}, | ||
}) | ||
|
||
wrapper.vm.$nextTick(() => { | ||
expect(wrapper.findAll('.md-picker-column-item').length).toEqual(5) | ||
done() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {FieldItem} from 'mand-mobile' | ||
import sinon from 'sinon' | ||
import {shallowMount} from '@vue/test-utils' | ||
|
||
describe('Field - Operation', () => { | ||
let wrapper | ||
|
||
afterEach(() => { | ||
wrapper && wrapper.destroy() | ||
}) | ||
|
||
it('field item click event', () => { | ||
let clicked = false | ||
wrapper = shallowMount(FieldItem, { | ||
listeners: { | ||
click() { | ||
clicked = true | ||
}, | ||
}, | ||
}) | ||
const eventSpy = sinon.spy(wrapper.vm, '$emit') | ||
|
||
wrapper.find('.md-field-item').trigger('click') | ||
expect(eventSpy.calledWith('click')).toBe(true) | ||
expect(clicked).toBe(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {Icon} from 'mand-mobile' | ||
import sinon from 'sinon' | ||
import {shallowMount} from '@vue/test-utils' | ||
|
||
describe('Icon - Operation', () => { | ||
let wrapper | ||
|
||
afterEach(() => { | ||
wrapper && wrapper.destroy() | ||
}) | ||
|
||
it('icon click event', () => { | ||
let clicked = false | ||
wrapper = shallowMount(Icon, { | ||
propsData: { | ||
name: 'success-color', | ||
}, | ||
listeners: { | ||
click() { | ||
clicked = true | ||
}, | ||
}, | ||
}) | ||
const eventSpy = sinon.spy(wrapper.vm, '$emit') | ||
|
||
wrapper.find('.md-icon').trigger('click') | ||
expect(eventSpy.calledWith('click')).toBe(true) | ||
expect(clicked).toBe(true) | ||
}) | ||
}) |