| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import NumberKeyboard from '..';
- import { mount } from '../../../test/utils';
- function mockTouch(wrapper, event, keyIndex) {
- const key = wrapper.element.querySelectorAll('.van-key')[keyIndex];
- const touchStart = document.createEvent('CustomEvent');
- touchStart.initCustomEvent(event, true, true, {});
- key.dispatchEvent(touchStart);
- }
- test('click number key', () => {
- const wrapper = mount(NumberKeyboard, {
- propsData: {
- theme: 'custom',
- closeButtonText: 'close'
- }
- });
- mockTouch(wrapper, 'touchstart', 10);
- mockTouch(wrapper, 'touchstart', 0);
- mockTouch(wrapper, 'touchend', 0);
- wrapper.destroy();
- expect(wrapper.emitted('input')[0][0]).toEqual(1);
- });
- it('click delete key', () => {
- const wrapper = mount(NumberKeyboard);
- mockTouch(wrapper, 'touchstart', 11);
- expect(wrapper.emitted('delete')).toBeTruthy();
- });
- test('click close button', () => {
- const wrapper = mount(NumberKeyboard, {
- propsData: {
- theme: 'custom',
- closeButtonText: 'close'
- }
- });
- mockTouch(wrapper, 'touchstart', 12);
- expect(wrapper.emitted('close')).toBeTruthy();
- });
- test('keey-alive live cycle', () => {
- const wrapper = mount({
- template: `
- <keep-alive>
- <number-keyboard v-if="show" />
- </keep-alive>
- `,
- props: ['show'],
- components: { NumberKeyboard }
- }, {
- attachToDocument: true,
- propsData: {
- show: true
- }
- });
- expect(wrapper.vm.$el).toBeTruthy();
- wrapper.vm.show = false;
- expect(wrapper.vm.el).toBeFalsy();
- });
- test('listen to show/hide event when has transtion', () => {
- const wrapper = mount(NumberKeyboard);
- wrapper.vm.show = true;
- wrapper.trigger('animationend');
- wrapper.vm.show = false;
- wrapper.trigger('animationend');
- expect(wrapper.emitted('show')).toBeTruthy();
- expect(wrapper.emitted('hide')).toBeTruthy();
- });
- test('listen to show event when no transtion', () => {
- const wrapper = mount(NumberKeyboard, {
- propsData: {
- transition: false
- }
- });
- wrapper.vm.show = true;
- wrapper.vm.show = false;
- expect(wrapper.emitted('show')).toBeTruthy();
- expect(wrapper.emitted('hide')).toBeTruthy();
- });
- test('title-left slot', () => {
- const wrapper = mount({
- template: `
- <number-keyboard show>
- <template v-slot:title-left>Custom Title Left</template>
- </number-keyboard>
- `
- }, {
- components: {
- NumberKeyboard
- }
- });
- expect(wrapper).toMatchSnapshot();
- });
|