1 | import {shallow, mount, render} from 'enzyme';
|
2 | import {expect} from 'chai';
|
3 | import Button from 'bee-button';
|
4 | import React, { Component } from 'react';
|
5 | import Upload from '../src';
|
6 | import ReactDOM from 'react-dom';
|
7 | import Icon from 'bee-icon';
|
8 |
|
9 | describe('Upload test', function () {
|
10 | let state;
|
11 | const props = {
|
12 | name: 'file',
|
13 | action: '/upload.do',
|
14 | headers: {
|
15 | authorization: 'authorization-text',
|
16 | },
|
17 | listType: 'picture',
|
18 | defaultFileList: [{
|
19 | uid: -1,
|
20 | name: 'xxx.png',
|
21 | status: 'done',
|
22 | url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
23 | thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
24 | }, {
|
25 | uid: -2,
|
26 | name: 'yyy.png',
|
27 | status: 'done',
|
28 | url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
29 | thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
30 | }],
|
31 | onChange(info) {
|
32 | if (info.file.status !== 'uploading') {
|
33 | state = 'uploading';
|
34 | console.log(info.file, info.fileList);
|
35 | }
|
36 | if (info.file.status === 'done') {
|
37 | state = 'done';
|
38 | console.log(`${info.file.name} file uploaded successfully`);
|
39 | } else if (info.file.status === 'error') {
|
40 | state = 'error';
|
41 | console.log(`${info.file.name} file upload failed.`);
|
42 | }
|
43 | },
|
44 | };
|
45 |
|
46 | class Demo1 extends Component {
|
47 | render(){
|
48 | return(
|
49 | <Upload {...props}>
|
50 | <Button type="primary" shape="border">
|
51 | <Icon type="upload" /> Click to Upload
|
52 | </Button>
|
53 | </Upload>
|
54 | )
|
55 | }
|
56 | }
|
57 | it('upload render successfully', function () {
|
58 | let upload = mount(<Demo1 />);
|
59 | expect(upload.find('.u-upload-select').length).to.equal(1);
|
60 | });
|
61 | it('upload default list', function () {
|
62 | let upload = mount(<Demo1 />);
|
63 | let uploadList = upload.find('.u-upload-list-item-done');
|
64 | expect(uploadList.length).to.equal(2);
|
65 | });
|
66 | it('upload list type should be picture', function () {
|
67 | let upload = mount(<Demo1 />);
|
68 | let uploadList = upload.find('.u-upload-list-item-thumbnail');
|
69 | expect(uploadList.length).to.equal(2);
|
70 | });
|
71 |
|
72 | }); |
\ | No newline at end of file |