test case

This commit is contained in:
tsxuehu 2017-04-13 16:59:13 +08:00
parent 37634739c9
commit 1ad808ab72
4 changed files with 135 additions and 21 deletions

View File

@ -49,20 +49,7 @@ export default {
#### 基础用法
:::demo 基础用法
```html
<div class="uploader-container">
<zan-uploader
:before-read="logContent"
:after-read="logContent">
</zan-uploader>
</div>
```
:::
#### 自定义上传图标
:::demo 自定义上传图标
:::demo
```html
<div class="uploader-container">
<zan-uploader :after-read="logContent">
@ -80,7 +67,7 @@ export default {
| result-type | 读取文件的方式以base64的方式读取以文本的方式读取 | `string` | `dataUrl` | `dataUrl`, `text` |
| disable | 是否禁用上传,在图片上传期间设置为true禁止用户点击此组件上传图片 | `boolean` | `false` | |
| before-read | 读文件之前的钩子,参数为选择的文件,若返回 false 则停止读取文件。 | `Function` | | |
| after-read | 文件读完之后回调此函数,参数为{name:'文件名',type:'文件类型',size:'文件大小',content:'读的内容'} | `Function` | | |
| after-read | 文件读完之后回调此函数,参数为{file:'选择的文件',content:'读的内容'} | `Function` | | |
### Slot

View File

@ -1,12 +1,10 @@
<template>
<div class="zan-uploader">
<slot>
<div>
<zan-button block>上传文件</zan-button>
</div>
</slot>
<template v-if="disabled">
<input type="file" @change="onValueChange" disabled="disabled" class="zan-uploader__input" ref="input" />
<input type="file" @change="onValueChange" disabled="disabled" class="zan-uploader__input" />
</template>
<template v-else>
<input type="file" @change="onValueChange" class="zan-uploader__input" ref="input" />
@ -48,7 +46,7 @@
file: file,
content: e.target.result
});
this.$refs.input.value = '';
this.$refs.input && (this.$refs.input.value = '');
};
if (this.resultType === 'dataUrl') {
reader.readAsDataURL(file);

View File

@ -0,0 +1,117 @@
import Uploader from 'packages/uploader';
import { mount } from 'avoriaz';
describe('Uploader', () => {
let wrapper;
afterEach(() => {
wrapper && wrapper.destroy();
});
it('enabled', () => {
wrapper = mount(Uploader, {
propsData: {
disabled: false
}
});
expect(wrapper.contains('input')).to.equal(true);
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [] }})).to.equal(undefined);
});
});
describe('Uploader', () => {
let wrapper;
afterEach(() => {
wrapper && wrapper.destroy();
});
it('disabled', () => {
wrapper = mount(Uploader, {
propsData: {
disabled: true
}
});
expect(wrapper.contains('input')).to.equal(true);
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [] }})).to.equal(undefined);
});
});
describe('Uploader', () => {
let wrapper;
afterEach(() => {
wrapper && wrapper.destroy();
});
it('before read', () => {
wrapper = mount(Uploader, {
propsData: {
disabled: false,
beforeRead: () => {
return false;
}
}
});
expect(wrapper.contains('input')).to.equal(true);
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [new File([], '')] }})).to.equal(undefined);
});
});
describe('Uploader', () => {
let wrapper;
afterEach(() => {
wrapper && wrapper.destroy();
});
it('read text', () => {
wrapper = mount(Uploader, {
propsData: {
disabled: false,
resultType: 'text',
afterRead: (file) => {
console.log(file);
}
}
});
expect(wrapper.contains('input')).to.equal(true);
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [new File([], '/Users')] }})).to.equal(undefined);
});
});
describe('Uploader', () => {
let wrapper;
afterEach(() => {
wrapper && wrapper.destroy();
});
it('read text no after hook', () => {
wrapper = mount(Uploader, {
propsData: {
disabled: false,
resultType: 'text'
}
});
expect(wrapper.contains('input')).to.equal(true);
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [new File([], '/Users')] }})).to.equal(undefined);
});
});
describe('Uploader', () => {
let wrapper;
afterEach(() => {
wrapper && wrapper.destroy();
});
it('read dataUrl', () => {
wrapper = mount(Uploader, {
propsData: {
disabled: false,
resultType: 'dataUrl',
afterRead: (file) => {
console.log(file);
}
}
});
expect(wrapper.contains('input')).to.equal(true);
expect(wrapper.methods().onValueChange.call(wrapper.vm, { target: { files: [new File([], '/Users')] }})).to.equal(undefined);
});
});

View File

@ -1589,7 +1589,7 @@ cssesc@^0.1.0:
version "0.1.0"
resolved "http://registry.npm.qima-inc.com/cssesc/download/cssesc-0.1.0.tgz#c814903e45623371a0477b40109aaafbeeaddbb4"
"cssnano@>=2.6.1 <4":
"cssnano@>=2.6.1 <4", cssnano@^3.4.0:
version "3.10.0"
resolved "http://registry.npm.qima-inc.com/cssnano/download/cssnano-3.10.0.tgz#4f38f6cea2b9b17fa01490f23f1dc68ea65c1c38"
dependencies:
@ -4666,6 +4666,14 @@ optimist@^0.6.1, optimist@~0.6.1:
minimist "~0.0.1"
wordwrap "~0.0.2"
optimize-css-assets-webpack-plugin@^1.3.0:
version "1.3.0"
resolved "http://registry.npm.qima-inc.com/optimize-css-assets-webpack-plugin/download/optimize-css-assets-webpack-plugin-1.3.0.tgz#331b3dc7ac0b2b3597f68d18fd555f5a0c81b15c"
dependencies:
cssnano "^3.4.0"
underscore "^1.8.3"
webpack-sources "^0.1.0"
optionator@^0.8.1, optionator@^0.8.2:
version "0.8.2"
resolved "http://registry.npm.qima-inc.com/optionator/download/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64"
@ -6531,6 +6539,10 @@ unc-path-regex@^0.1.0:
version "0.1.2"
resolved "http://registry.npm.qima-inc.com/unc-path-regex/download/unc-path-regex-0.1.2.tgz#e73dd3d7b0d7c5ed86fbac6b0ae7d8c6a69d50fa"
underscore@^1.8.3:
version "1.8.3"
resolved "http://registry.npm.qima-inc.com/underscore/download/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022"
underscore@~1.6.0:
version "1.6.0"
resolved "http://registry.npm.qima-inc.com/underscore/download/underscore-1.6.0.tgz#8b38b10cacdef63337b8b24e4ff86d45aea529a8"