[improvement] rename packages dir to src (#3659)

This commit is contained in:
neverland
2019-06-27 11:25:57 +08:00
committed by GitHub
parent 8489918dca
commit 75c79b7044
619 changed files with 21 additions and 21 deletions
+110
View File
@@ -0,0 +1,110 @@
import Rate from '..';
import { mount, triggerDrag } from '../../../test/utils';
test('change event', () => {
const onInput = jest.fn();
const onChange = jest.fn();
const wrapper = mount(Rate, {
context: {
on: {
input: onInput,
change: onChange
}
}
});
const item4 = wrapper.findAll('.van-rate__icon').at(3);
item4.trigger('click');
expect(onInput).toHaveBeenCalledWith(4);
expect(onChange).toHaveBeenCalledWith(4);
});
test('allow half', () => {
const onInput = jest.fn();
const onChange = jest.fn();
const wrapper = mount(Rate, {
propsData: {
allowHalf: true
},
context: {
on: {
input: onInput,
change: onChange
}
}
});
const item4 = wrapper.findAll('.van-rate__icon--half').at(3);
item4.trigger('click');
expect(onInput).toHaveBeenCalledWith(3.5);
expect(onChange).toHaveBeenCalledWith(3.5);
});
test('disabled', () => {
const onInput = jest.fn();
const onChange = jest.fn();
const wrapper = mount(Rate, {
propsData: {
disabled: true
},
context: {
on: {
input: onInput,
change: onChange
}
}
});
const item4 = wrapper.findAll('.van-rate__item').at(3);
item4.trigger('click');
expect(onInput).toHaveBeenCalledTimes(0);
expect(onChange).toHaveBeenCalledTimes(0);
});
test('touchmove', () => {
const onChange = jest.fn();
const wrapper = mount(Rate, {
context: {
on: {
change: onChange
}
}
});
triggerDrag(wrapper, 100, 0);
const icons = wrapper.findAll('.van-icon');
document.elementFromPoint = function (x) {
const index = Math.round(x / 20);
if (index < icons.length) {
return icons.at(index).element;
}
};
triggerDrag(wrapper, 100, 0);
expect(onChange).toHaveBeenNthCalledWith(1, 2);
expect(onChange).toHaveBeenNthCalledWith(2, 3);
expect(onChange).toHaveBeenNthCalledWith(3, 4);
});
test('gutter prop', () => {
const wrapper = mount(Rate, {
propsData: {
gutter: 10
}
});
expect(wrapper).toMatchSnapshot();
});
test('size prop', () => {
const wrapper = mount(Rate, {
propsData: {
size: '2rem'
}
});
expect(wrapper).toMatchSnapshot();
});