mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
✅ upload utils test
This commit is contained in:
parent
d97218fb28
commit
44812cf5e8
@ -2,7 +2,13 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import Upload from '..';
|
||||
import { fileToObject } from '../utils';
|
||||
import {
|
||||
T,
|
||||
fileToObject,
|
||||
genPercentAdd,
|
||||
getFileItem,
|
||||
removeFileItem,
|
||||
} from '../utils';
|
||||
import { setup, teardown } from './mock';
|
||||
|
||||
describe('Upload', () => {
|
||||
@ -177,6 +183,12 @@ describe('Upload', () => {
|
||||
});
|
||||
|
||||
describe('util', () => {
|
||||
// https://github.com/react-component/upload/issues/36
|
||||
it('should T() return true', () => {
|
||||
const res = T();
|
||||
expect(res).toBe(true);
|
||||
});
|
||||
|
||||
it('should be able to copy file instance', () => {
|
||||
const file = new File([], 'aaa.zip');
|
||||
const copiedFile = fileToObject(file);
|
||||
@ -184,6 +196,60 @@ describe('Upload', () => {
|
||||
expect(key in copiedFile).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to progress from 0.1 ', () => {
|
||||
// 0.1 -> 0.98
|
||||
const getPercent = genPercentAdd();
|
||||
let curPercent = 0;
|
||||
curPercent = getPercent(curPercent);
|
||||
expect(curPercent).toBe(0.1);
|
||||
});
|
||||
|
||||
it('should be able to progress to 0.98 ', () => {
|
||||
// 0.1 -> 0.98
|
||||
const getPercent = genPercentAdd();
|
||||
let curPercent = 0;
|
||||
for (let i = 0; i < 500; i += 1) {
|
||||
curPercent = getPercent(curPercent);
|
||||
}
|
||||
expect(parseFloat(curPercent.toFixed(2))).toBe(0.98);
|
||||
});
|
||||
|
||||
it('should be able to get fileItem', () => {
|
||||
const file = { uid: '-1', name: 'item.jpg' };
|
||||
const fileList = [{
|
||||
uid: '-1',
|
||||
name: 'item.jpg',
|
||||
}];
|
||||
const targetItem = getFileItem(file, fileList);
|
||||
expect(targetItem).toBe(fileList[0]);
|
||||
});
|
||||
|
||||
it('should be able to remove fileItem', () => {
|
||||
const file = { uid: '-1', name: 'item.jpg' };
|
||||
const fileList = [{
|
||||
uid: '-1',
|
||||
name: 'item.jpg',
|
||||
}, {
|
||||
uid: '-2',
|
||||
name: 'item2.jpg',
|
||||
}];
|
||||
const targetItem = removeFileItem(file, fileList);
|
||||
expect(targetItem).toEqual(fileList.slice(1));
|
||||
});
|
||||
|
||||
it('should not be able to remove fileItem', () => {
|
||||
const file = { uid: '-3', name: 'item.jpg' };
|
||||
const fileList = [{
|
||||
uid: '-1',
|
||||
name: 'item.jpg',
|
||||
}, {
|
||||
uid: '-2',
|
||||
name: 'item2.jpg',
|
||||
}];
|
||||
const targetItem = removeFileItem(file, fileList);
|
||||
expect(targetItem).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
it('should support linkProps as object', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user