-
+
Tab 1
Tab 2
Tab 3
diff --git a/components/upload/__tests__/requests.js b/components/upload/__tests__/requests.js
new file mode 100644
index 000000000..13ad54f86
--- /dev/null
+++ b/components/upload/__tests__/requests.js
@@ -0,0 +1,11 @@
+export const successRequest = ({ onSuccess, file }) => {
+ setTimeout(() => {
+ onSuccess(null, file)
+ })
+}
+
+export const errorRequest = ({ onError }) => {
+ setTimeout(() => {
+ onError()
+ })
+}
diff --git a/components/upload/__tests__/upload.test.js b/components/upload/__tests__/upload.test.js
new file mode 100644
index 000000000..2b697f68e
--- /dev/null
+++ b/components/upload/__tests__/upload.test.js
@@ -0,0 +1,175 @@
+import { mount } from '@vue/test-utils'
+import Upload from '..'
+import { fileToObject } from '../utils'
+
+describe('Upload', () => {
+ it('should get refs inside Upload in componentDidMount', () => {
+ let ref
+ const APP = {
+ mounted () {
+ ref = this.$refs.input
+ },
+ render () {
+ return (
+
+
+
+ )
+ },
+ }
+ mount(APP)
+ expect(ref).toBeDefined()
+ })
+
+ it('return promise in beforeUpload', (done) => {
+ const data = jest.fn()
+ const props = {
+ propsData: {
+ action: 'http://upload.com',
+ beforeUpload: () => new Promise(resolve =>
+ setTimeout(() => resolve('success'), 100)
+ ),
+ data,
+ },
+ listeners: {
+ change: ({ file }) => {
+ if (file.status !== 'uploading') {
+ expect(data).toBeCalled()
+ done()
+ }
+ },
+ },
+ slots: {
+ default: '
',
+ },
+ sync: false,
+ }
+ const wrapper = mount(Upload, props)
+ setTimeout(() => {
+ const mockFile = new File(['foo'], 'foo.png', {
+ type: 'image/png',
+ })
+ wrapper.find({ name: 'ajaxUploader' }).vm.onChange({
+ target: {
+ files: [mockFile],
+ },
+ })
+ }, 0)
+ })
+
+ it('should not stop upload when return value of beforeUpload is false', (done) => {
+ const data = jest.fn()
+ const props = {
+ propsData: {
+ action: 'http://upload.com',
+ beforeUpload: () => false,
+ data,
+ },
+ listeners: {
+ change: ({ file }) => {
+ expect(file instanceof File).toBe(true)
+ expect(data).not.toBeCalled()
+ done()
+ },
+ },
+ slots: {
+ default: '
',
+ },
+ sync: false,
+ }
+ const wrapper = mount(Upload, props)
+ setTimeout(() => {
+ const mockFile = new File(['foo'], 'foo.png', {
+ type: 'image/png',
+ })
+ wrapper.find({ name: 'ajaxUploader' }).vm.onChange({
+ target: {
+ files: [mockFile],
+ },
+ })
+ }, 0)
+ })
+
+ it('should increase percent automaticly when call autoUpdateProgress in IE', (done) => {
+ let uploadInstance
+ let lastPercent = -1
+ const props = {
+ propsData: {
+ action: 'http://jsonplaceholder.typicode.com/posts/',
+ },
+ listeners: {
+ change: ({ file }) => {
+ if (file.percent === 0 && file.status === 'uploading') {
+ // manually call it
+ uploadInstance.autoUpdateProgress(0, file)
+ }
+ if (file.status === 'uploading') {
+ expect(file.percent).toBeGreaterThan(lastPercent)
+ lastPercent = file.percent
+ }
+ if (file.status === 'done' || file.status === 'error') {
+ done()
+ }
+ },
+ },
+ slots: {
+ default: '
',
+ },
+ sync: false,
+ }
+ const wrapper = mount(Upload, props)
+ setTimeout(() => {
+ const mockFile = new File(['foo'], 'foo.png', {
+ type: 'image/png',
+ })
+ wrapper.find({ name: 'ajaxUploader' }).vm.onChange({
+ target: {
+ files: [mockFile],
+ },
+ })
+ uploadInstance = wrapper.vm
+ }, 0)
+ })
+ it('should not stop upload when return value of beforeUpload is not false', (done) => {
+ const data = jest.fn()
+ const props = {
+ propsData: {
+ action: 'http://upload.com',
+ beforeUpload () {},
+ data,
+ },
+ listeners: {
+ change: () => {
+ expect(data).toBeCalled()
+ done()
+ },
+ },
+ slots: {
+ default: '
',
+ },
+ sync: false,
+ }
+
+ const wrapper = mount(Upload, props)
+ setTimeout(() => {
+ const mockFile = new File(['foo'], 'foo.png', {
+ type: 'image/png',
+ })
+ wrapper.find({ name: 'ajaxUploader' }).vm.onChange({
+ target: {
+ files: [mockFile],
+ },
+ })
+ }, 0)
+ })
+
+ describe('util', () => {
+ it('should be able to copy file instance', () => {
+ const file = new File([], 'aaa.zip')
+ const copiedFile = fileToObject(file);
+ ['uid', 'lastModified', 'lastModifiedDate', 'name', 'size', 'type'].forEach((key) => {
+ expect(key in copiedFile).toBe(true)
+ })
+ })
+ })
+})
diff --git a/components/upload/utils.jsx b/components/upload/utils.jsx
index 44093e471..efc82cc0f 100644
--- a/components/upload/utils.jsx
+++ b/components/upload/utils.jsx
@@ -38,7 +38,7 @@ export function genPercentAdd () {
if (k < 0.001) {
k = 0.001
}
- return start * 100
+ return start
}
}
diff --git a/components/vc-input-number/src/index.js b/components/vc-input-number/src/index.js
index 0f14a71c1..f5e8947bf 100755
--- a/components/vc-input-number/src/index.js
+++ b/components/vc-input-number/src/index.js
@@ -47,6 +47,7 @@ const inputNumberProps = {
// onKeyUp: PropTypes.func,
prefixCls: PropTypes.string,
tabIndex: PropTypes.string,
+ placeholder: PropTypes.string,
disabled: PropTypes.bool,
// onFocus: PropTypes.func,
// onBlur: PropTypes.func,
diff --git a/components/vc-upload/src/AjaxUploader.jsx b/components/vc-upload/src/AjaxUploader.jsx
index f6e5dd957..51b78ae5b 100644
--- a/components/vc-upload/src/AjaxUploader.jsx
+++ b/components/vc-upload/src/AjaxUploader.jsx
@@ -29,6 +29,7 @@ const upLoadPropTypes = {
}
const AjaxUploader = {
+ name: 'ajaxUploader',
mixins: [BaseMixin],
props: upLoadPropTypes,
data () {
diff --git a/site/routes.js b/site/routes.js
index 3f19c9bd4..b66e530cd 100644
--- a/site/routes.js
+++ b/site/routes.js
@@ -4,7 +4,7 @@ import Iframe from './components/iframe.vue'
const AsyncTestComp = () => {
const d = window.location.hash.replace('#', '')
return {
- component: import(`../components/upload/demo/${d}`),
+ component: import(`../components/input-number/demo/${d}`),
}
}