[new feature] IndexBar: add sticky prop (#3402)

This commit is contained in:
neverland
2019-05-30 11:50:09 +08:00
committed by GitHub
parent 74124246f6
commit 82134fe402
14 changed files with 263 additions and 60 deletions
+16 -8
View File
@@ -1,17 +1,17 @@
import Slider from '..';
import { mount, trigger, triggerDrag } from '../../../test/utils';
import { mount, trigger, triggerDrag, mockGetBoundingClientRect } from '../../../test/utils';
function mockGetBoundingClientRect(vertical) {
Element.prototype.getBoundingClientRect = jest.fn(() => ({
function mockRect(vertical) {
return mockGetBoundingClientRect({
width: vertical ? 0 : 100,
height: vertical ? 100 : 0,
top: vertical ? 0 : 100,
left: vertical ? 100 : 0
}));
});
}
test('drag button', () => {
mockGetBoundingClientRect();
const restoreMock = mockRect();
const wrapper = mount(Slider, {
propsData: {
@@ -37,10 +37,12 @@ test('drag button', () => {
expect(wrapper).toMatchSnapshot();
expect(wrapper.emitted('drag-start')).toBeTruthy();
expect(wrapper.emitted('drag-end')).toBeTruthy();
restoreMock();
});
it('click bar', () => {
mockGetBoundingClientRect();
const restoreMock = mockRect();
const wrapper = mount(Slider, {
propsData: {
@@ -59,10 +61,12 @@ it('click bar', () => {
wrapper.setData({ disabled: false });
trigger(wrapper, 'click', 100, 0);
expect(wrapper).toMatchSnapshot();
restoreMock();
});
test('drag button vertical', () => {
mockGetBoundingClientRect(true);
const restoreMock = mockRect(true);
const wrapper = mount(Slider, {
propsData: {
@@ -78,10 +82,12 @@ test('drag button vertical', () => {
const button = wrapper.find('.van-slider__button');
triggerDrag(button, 0, 50);
expect(wrapper).toMatchSnapshot();
restoreMock();
});
it('click vertical', () => {
mockGetBoundingClientRect(true);
const restoreMock = mockRect(true);
const wrapper = mount(Slider, {
propsData: {
@@ -96,4 +102,6 @@ it('click vertical', () => {
trigger(wrapper, 'click', 0, 100);
expect(wrapper).toMatchSnapshot();
restoreMock();
});