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. 13
      packages/fineui/src/widget/searchmultitextvaluecombo/__test__/multitextvalue.combo.search.test.js
  4. 42
      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 = {
'BI-Multi_Date_Quarter_End': '季度末',
'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;

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

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

42
packages/fineui/test/utils.js

@ -1,17 +1,35 @@
BI.Test = {};
BI.extend(BI.Test, {
createWidget: function (widgetJson) {
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事件
*/
triggerKeyDown: function (element, value, keyCode, callback) {
function triggerKeyDown (element, value, keyCode, callback) {
// keydown
var e = BI.$.Event("keydown");
e.keyCode = keyCode;
@ -31,15 +49,23 @@ BI.extend(BI.Test, {
BI.delay(function () {
callback();
}, 300);
},
};
/**
* 模拟一次鼠标hover
*/
triggerMouseover: function (element, callback) {
function triggerMouseover(element, callback) {
// keydown
var e = BI.$.Event("mouseover");
element.trigger(e);
callback && callback();
}
};
BI.Test = {};
BI.extend(BI.Test, {
registeCloser,
sleep,
createWidget,
triggerKeyDown,
triggerMouseover
})

2
packages/fineui/tsconfig.json

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

Loading…
Cancel
Save