mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
test(ActionSheet): add more test cases
This commit is contained in:
parent
27b761f534
commit
9240cd128f
@ -1,4 +1,4 @@
|
||||
import { mount, later } from '../../../test';
|
||||
import { mount } from '../../../test';
|
||||
import ActionSheet from '..';
|
||||
|
||||
test('callback events', () => {
|
||||
@ -40,61 +40,3 @@ test('callback events', () => {
|
||||
expect(onSelect).toHaveBeenCalledWith(actions[0], 0);
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('click overlay and close', async () => {
|
||||
const onInput = jest.fn();
|
||||
const onClickOverlay = jest.fn();
|
||||
const div = document.createElement('div');
|
||||
|
||||
mount({
|
||||
template: `
|
||||
<div>
|
||||
<action-sheet
|
||||
:value="true"
|
||||
:teleport="teleport"
|
||||
@input="onInput"
|
||||
@click-overlay="onClickOverlay"
|
||||
/>
|
||||
</div>
|
||||
`,
|
||||
components: {
|
||||
ActionSheet,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
teleport: () => div,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
onInput,
|
||||
onClickOverlay,
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
|
||||
div.querySelector('.van-overlay').click();
|
||||
expect(onInput).toHaveBeenCalledWith(false);
|
||||
expect(onClickOverlay).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('close-on-click-action prop', () => {
|
||||
const onInput = jest.fn();
|
||||
const wrapper = mount(ActionSheet, {
|
||||
propsData: {
|
||||
value: true,
|
||||
actions: [{ name: 'Option' }],
|
||||
closeOnClickAction: true,
|
||||
},
|
||||
context: {
|
||||
on: {
|
||||
input: onInput,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const option = wrapper.find('.van-action-sheet__item');
|
||||
option.trigger('click');
|
||||
|
||||
expect(onInput).toHaveBeenCalledWith(false);
|
||||
});
|
||||
|
@ -115,3 +115,35 @@ test('should render description slot when match snapshot', () => {
|
||||
wrapper.find('.van-action-sheet__description').html()
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should close after clicking option if close-on-click-action prop is true', () => {
|
||||
const wrapper = mount(ActionSheet, {
|
||||
propsData: {
|
||||
show: true,
|
||||
actions: [{ name: 'Option' }],
|
||||
closeOnClickAction: true,
|
||||
},
|
||||
});
|
||||
|
||||
const option = wrapper.find('.van-action-sheet__item');
|
||||
option.trigger('click');
|
||||
|
||||
expect(wrapper.emitted('update:show').length).toEqual(1);
|
||||
expect(wrapper.emitted('update:show')[0][0]).toEqual(false);
|
||||
});
|
||||
|
||||
test('should emit click-overlay event and closed after clicking the overlay', async () => {
|
||||
const onClickOverlay = jest.fn();
|
||||
const wrapper = mount(ActionSheet, {
|
||||
props: {
|
||||
show: true,
|
||||
onClickOverlay,
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
|
||||
wrapper.find('.van-overlay').trigger('click');
|
||||
expect(wrapper.emitted('update:show')[0][0]).toEqual(false);
|
||||
expect(onClickOverlay).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user