!1 Merge back to master

Merge pull request !1 from dev branch
This commit is contained in:
hekk 2018-05-27 21:32:55 +08:00
parent 30c963a5f0
commit 61a1c93f0f
89 changed files with 15859 additions and 2 deletions

View file

@ -0,0 +1,4 @@
import { configure } from "enzyme";
import Adapter from "enzyme-adapter-react-15";
configure({ adapter: new Adapter() });

View file

@ -0,0 +1,73 @@
// function should be called after async operation is finished
export function execFuncs(instance, execs) {
// instance: enzyme mounted component
// const execs = [
// {
// func: "componentWillMount",
// args: []
// }
// ];
return execs.reduce((prePromise, nextFunc) => {
return prePromise.then(() => instance[nextFunc.func](...nextFunc.args));
}, Promise.resolve());
}
export function execsToStr(execs) {
// const execs = [
// {
// func: "componentWillMount",
// args: []
// }
// ];
const execList = execs.map(
funcInfo => `${funcInfo.func}(${funcInfo.args.join(", ")})`
);
return execList.join(", ");
}
export function getDesc(componentName, testCase) {
// const testCase = {
// execs: [
// {
// func: "onAddLocalFiles",
// args: []
// }
// ],
// state: {
// filterFileName: ""
// },
// calls: [
// {
// func: "onAddLocalFiles",
// count: 1
// }
// ]
// }
return `${componentName} should satisfy following by exec ${execsToStr(
testCase.execs
)}
state=${JSON.stringify(testCase.state)}
calls=${JSON.stringify(testCase.calls)} `;
}
export function verifyCalls(calls, stubs) {
// const calls: [
// {
// func: "funcName",
// count: 1
// }
// ];
// const stubs = {
// funcName: jest.fn(),
// };
let err = null;
calls.forEach(called => {
if (stubs[called.func].mock.calls.length != called.count) {
err = `InfoBar: ${called.func} should be called ${called.count} but ${
stubs[called.func].mock.calls.length
}`;
}
});
return err;
}