diff --git a/src/action-sheet/test/__snapshots__/index.legacy.js.snap b/src/action-sheet/test/__snapshots__/index.legacy.js.snap deleted file mode 100644 index 932b1a226..000000000 --- a/src/action-sheet/test/__snapshots__/index.legacy.js.snap +++ /dev/null @@ -1,67 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`callback events 1`] = ` -
-
-
-
-`; - -exports[`close-icon prop 1`] = ` -
-
Title -
-
-
-`; - -exports[`closeable prop 1`] = ` -
-
Title
-
-
-`; - -exports[`color option 1`] = ` -
-
-
-`; - -exports[`description prop 1`] = ` -
-
This is a description
-
-
-`; - -exports[`description slot 1`] = ` -
-
Custom Description
-
-
-`; - -exports[`disable lazy-render 1`] = ` - -`; - -exports[`render title and default slot 1`] = ` -
-
Title -
-
Default
-
-`; - -exports[`round prop 1`] = ` -
-
-
-`; diff --git a/src/action-sheet/test/__snapshots__/index.spec.js.snap b/src/action-sheet/test/__snapshots__/index.spec.js.snap index 41636e0aa..811c4f09f 100644 --- a/src/action-sheet/test/__snapshots__/index.spec.js.snap +++ b/src/action-sheet/test/__snapshots__/index.spec.js.snap @@ -31,3 +31,8 @@ exports[`should render default slot and match snapshot 1`] = ` exports[`should render description and match snapshot 1`] = `
This is a description
`; exports[`should render description slot when match snapshot 1`] = `
Custom Description
`; + +exports[`should render subname and match snapshot 1`] = ` + +`; diff --git a/src/action-sheet/test/index.legacy.js b/src/action-sheet/test/index.legacy.js deleted file mode 100644 index fa2fe6945..000000000 --- a/src/action-sheet/test/index.legacy.js +++ /dev/null @@ -1,42 +0,0 @@ -import { mount } from '../../../test'; -import ActionSheet from '..'; - -test('callback events', () => { - const callback = jest.fn(); - const onInput = jest.fn(); - const onCancel = jest.fn(); - const onSelect = jest.fn(); - - const actions = [ - { name: 'Option', callback }, - { name: 'Option', disabled: true }, - { name: 'Option', loading: true }, - { name: 'Option', subname: 'Subname' }, - ]; - - const wrapper = mount(ActionSheet, { - propsData: { - value: true, - actions, - cancelText: 'Cancel', - }, - context: { - on: { - input: onInput, - cancel: onCancel, - select: onSelect, - }, - }, - }); - - const options = wrapper.findAll('.van-action-sheet__item'); - options.at(0).trigger('click'); - options.at(1).trigger('click'); - wrapper.find('.van-action-sheet__cancel').trigger('click'); - - expect(callback).toHaveBeenCalled(); - expect(onCancel).toHaveBeenCalled(); - expect(onInput).toHaveBeenCalledWith(false); - expect(onSelect).toHaveBeenCalledWith(actions[0], 0); - expect(wrapper.html()).toMatchSnapshot(); -}); diff --git a/src/action-sheet/test/index.spec.js b/src/action-sheet/test/index.spec.js index 5c7f539c1..de3266abd 100644 --- a/src/action-sheet/test/index.spec.js +++ b/src/action-sheet/test/index.spec.js @@ -2,6 +2,81 @@ import { mount } from '@vue/test-utils'; import { later } from '../../../test'; import ActionSheet from '..'; +test('should emit select event after clicking option', () => { + const wrapper = mount(ActionSheet, { + propsData: { + show: true, + actions: [{ name: 'Option' }], + }, + }); + + wrapper.find('.van-action-sheet__item').trigger('click'); + expect(wrapper.emitted('select').length).toEqual(1); + expect(wrapper.emitted('select')[0][0]).toEqual({ name: 'Option' }); +}); + +test('should call callback function after clicking option', () => { + const callback = jest.fn(); + const wrapper = mount(ActionSheet, { + propsData: { + show: true, + actions: [{ name: 'Option', callback }], + }, + }); + + wrapper.find('.van-action-sheet__item').trigger('click'); + expect(callback).toHaveBeenCalledTimes(1); +}); + +test('should not emit select event after clicking loading option', () => { + const wrapper = mount(ActionSheet, { + propsData: { + show: true, + actions: [{ name: 'Option', loading: true }], + }, + }); + + wrapper.find('.van-action-sheet__item').trigger('click'); + expect(wrapper.emitted('select')).toBeFalsy(); +}); + +test('should not emit select event after clicking disabled option', () => { + const wrapper = mount(ActionSheet, { + propsData: { + show: true, + actions: [{ name: 'Option', disabled: true }], + }, + }); + + wrapper.find('.van-action-sheet__item').trigger('click'); + expect(wrapper.emitted('select')).toBeFalsy(); +}); + +test('should emit cancel event after clicking cancel button', () => { + const wrapper = mount(ActionSheet, { + propsData: { + show: true, + actions: [{ name: 'Option' }], + cancelText: 'Cancel', + }, + }); + + wrapper.find('.van-action-sheet__cancel').trigger('click'); + expect(wrapper.emitted('cancel').length).toEqual(1); +}); + +test('should render subname and match snapshot', () => { + const wrapper = mount(ActionSheet, { + propsData: { + show: true, + actions: [{ name: 'Option', subname: 'Subname' }], + cancelText: 'Cancel', + }, + }); + + expect(wrapper.find('.van-action-sheet__item').html()).toMatchSnapshot(); +}); + test('should render content after disabling the lazy-render prop', async () => { const wrapper = mount(ActionSheet); expect(wrapper.find('.van-action-sheet__content').exists()).toBeFalsy();