Browse Source

修复单测问题 && 优化tsconfig.json配置

research/test^2
Zoupers 6 months ago
parent
commit
cfe8ce1d6c
  1. 2
      packages/demo/i18n/i18n.cn.js
  2. 51
      packages/fineui/jest.config.ts
  3. 39
      packages/fineui/src/widget/searchmultitextvaluecombo/__test__/multitextvalue.combo.search.test.js
  4. 110
      packages/fineui/test/utils.js
  5. 2
      packages/fineui/tsconfig.json

2
packages/demo/i18n/i18n.cn.js

@ -1,4 +1,4 @@
window.BI = {}; window.BI = window.BI || {};
window.BI.i18n = { window.BI.i18n = {
'BI-Multi_Date_Quarter_End': '季度末', 'BI-Multi_Date_Quarter_End': '季度末',
'BI-Multi_Date_Month_Begin': '月初', 'BI-Multi_Date_Month_Begin': '月初',

51
packages/fineui/jest.config.ts

@ -0,0 +1,51 @@
import type { Config } from "jest";
// import webpackConfig from "./webpack/webpack.dev";
export default {
// testEnvironment: "<rootDir>/test/testEnvironmentJsdom.ts",
testEnvironment: "jsdom",
testEnvironmentOptions: {
// html: fs.readFileSync(path.join(__dirname, "test/index.html")),
},
testMatch: ["<rootDir>/src/**/*.test.js"],
collectCoverage: false,
collectCoverageFrom: ["src/**/*.js", "!src/**/*.test.js"],
coverageDirectory: "coverage",
coverageReporters: ["html", "json-summary", "cobertura"],
reporters: [
"default",
[
"jest-html-reporters",
{
publicPath: "./html-report",
openReport: true,
},
],
],
transform: {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tsx?$": "babel-jest",
},
preset: "jest-puppeteer",
verbose: true,
watchman: true,
injectGlobals: true,
globals: {
"ts-jest": {
tsconfig: "tsconfig.json",
},
},
setupFilesAfterEnv: [
"<rootDir>/src/bundle.js",
"<rootDir>/src/core/platform/web/config.js",
"<rootDir>/../demo/i18n/i18n.cn.js",
"<rootDir>/test/utils.js",
"<rootDir>/test/prepare.js",
],
moduleNameMapper: {
"@/(.*)$": "<rootDir>/src/$1",
},
} as Config;

39
packages/fineui/src/widget/searchmultitextvaluecombo/__test__/multitextvalue.combo.search.test.js

@ -69,33 +69,32 @@ describe("multitextvaluecombo", () => {
/** /**
* test_author_windy * test_author_windy
**/ **/
it("点选选值", done => { it("点选选值", async () => {
var widget = BI.Test.createWidget({ var widget = BI.Test.createWidget({
type: "bi.search_multi_text_value_combo", type: "bi.search_multi_text_value_combo",
width: 220, width: 220,
items: items items: items
}); });
// 组件创建需要时间...
await BI.Test.sleep(300);
widget.element.find(".bi-multi-select-trigger").click(); widget.element.find(".bi-multi-select-trigger").click();
await BI.Test.sleep(300);
// 为什么要delay 300呢,因为按钮有debounce // 为什么要delay 300呢,因为按钮有debounce
BI.delay(function () { // 点选1、2、3
// 点选1、2、3 BI.each(itemSelectorGetter([1,2,3]), function (idx, selector) {
BI.each(itemSelectorGetter([1,2,3]), function (idx, selector) { widget.element.find(selector).click();
widget.element.find(selector).click(); });
}); // 点全选
// 点全选 widget.element.find(".bi-multi-select-popup-view .bi-label:contains(全选)").click();
widget.element.find(".bi-multi-select-popup-view .bi-label:contains(全选)").click(); await BI.Test.sleep(300);
// 取消勾选1、2、3 // 取消勾选1、2、3
BI.delay(function () { BI.each(itemSelectorGetter([1,2,3]), function (idx, selector) {
BI.each(itemSelectorGetter([1,2,3]), function (idx, selector) { widget.element.find(selector).click();
widget.element.find(selector).click(); });
}); await BI.Test.sleep(300);
var value = widget.getValue(); var value = widget.getValue();
expect(value.type).toBe(2); expect(value.type).toBe(2);
expect(value.value).toEqual([0, 1, 2]); expect(value.value).toEqual([0, 1, 2]);
widget.destroy();
done();
}, 300);
}, 300);
}); });
/** /**

110
packages/fineui/test/utils.js

@ -1,45 +1,71 @@
const onetimeAfterEach = []
afterEach(() => {
while(onetimeAfterEach.length > 0) {
onetimeAfterEach.shift()()
}
});
function registeCloser(...f) {
onetimeAfterEach.unshift(...f)
};
function sleep(t) {
return new Promise(resolve => setTimeout(() => {
resolve()
}, t))
};
function createWidget(widgetJson) {
var widget = BI.createWidget(BI.extend(widgetJson, {
root: true
}));
widget.element.appendTo("body");
registeCloser(() => {
widget.destroy()
});
return widget;
};
/**
* 模拟一次输入框的keydown事件
*/
function triggerKeyDown (element, value, keyCode, callback) {
// keydown
var e = BI.$.Event("keydown");
e.keyCode = keyCode;
element.trigger(e);
// input
BI.isNotNull(value) && element.val(value);
var e1 = BI.$.Event("input");
e1.originalEvent = {};
e1.keyCode = keyCode;
element.trigger(e1);
// keyup 至少等300ms后触发
var e2 = BI.$.Event("keyup");
e2.keyCode = keyCode;
element.trigger(e2);
BI.delay(function () {
callback();
}, 300);
};
/**
* 模拟一次鼠标hover
*/
function triggerMouseover(element, callback) {
// keydown
var e = BI.$.Event("mouseover");
element.trigger(e);
callback && callback();
};
BI.Test = {}; BI.Test = {};
BI.extend(BI.Test, { BI.extend(BI.Test, {
createWidget: function (widgetJson) { registeCloser,
var widget = BI.createWidget(BI.extend(widgetJson, { sleep,
root: true createWidget,
})); triggerKeyDown,
widget.element.appendTo("body"); triggerMouseover
return widget;
},
/**
* 模拟一次输入框的keydown事件
*/
triggerKeyDown: function (element, value, keyCode, callback) {
// keydown
var e = BI.$.Event("keydown");
e.keyCode = keyCode;
element.trigger(e);
// input
BI.isNotNull(value) && element.val(value);
var e1 = BI.$.Event("input");
e1.originalEvent = {};
e1.keyCode = keyCode;
element.trigger(e1);
// keyup 至少等300ms后触发
var e2 = BI.$.Event("keyup");
e2.keyCode = keyCode;
element.trigger(e2);
BI.delay(function () {
callback();
}, 300);
},
/**
* 模拟一次鼠标hover
*/
triggerMouseover: function (element, callback) {
// keydown
var e = BI.$.Event("mouseover");
element.trigger(e);
callback && callback();
}
}) })

2
packages/fineui/tsconfig.json

@ -22,7 +22,7 @@
"noFallthroughCasesInSwitch": true, "noFallthroughCasesInSwitch": true,
"emitDeclarationOnly": true, "emitDeclarationOnly": true,
"paths": { "paths": {
"@": ["src"] "@/*": ["src/*"]
} }
}, },
"include": ["typescript/*.ts", "typescript/**/*.ts", "types/*.d.ts", "src/*.js", "src/**/*.js"], "include": ["typescript/*.ts", "typescript/**/*.ts", "types/*.d.ts", "src/*.js", "src/**/*.js"],

Loading…
Cancel
Save