create unit tests
This commit is contained in:
3
Makefile
3
Makefile
@@ -9,6 +9,9 @@ config:
|
||||
build:
|
||||
tsc -p ./src/main --outFile ./package/contents/code/main.js
|
||||
|
||||
tests:
|
||||
./run-ts.sh ./src/tests
|
||||
|
||||
install: build config
|
||||
kpackagetool6 --type=KWin/Script -i ./package || kpackagetool6 --type=KWin/Script -u ./package
|
||||
|
||||
|
||||
27
src/lib/rules/WindowRuleEnforcer.test.ts
Normal file
27
src/lib/rules/WindowRuleEnforcer.test.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
const testCases = [
|
||||
{tiledByDefault: true, resourceClass: "ksmserver-logout-greeter", caption: "anything", shouldTile: false},
|
||||
];
|
||||
|
||||
const enforcer = new WindowRuleEnforcer(JSON.parse(defaultWindowRules));
|
||||
for (const testCase of testCases) {
|
||||
const kwinClient: any = createKwinClient(testCase.tiledByDefault, testCase.resourceClass, testCase.caption);
|
||||
assert(enforcer.shouldTile(kwinClient) === testCase.shouldTile, "failed case: " + JSON.stringify(testCase));
|
||||
}
|
||||
|
||||
function createKwinClient(normalWindow: boolean, resoureClass: string, caption: string) {
|
||||
return {
|
||||
normalWindow: normalWindow,
|
||||
transient: false,
|
||||
managed: true,
|
||||
moveable: true,
|
||||
resizeable: true,
|
||||
popupWindow: false,
|
||||
minimized: false,
|
||||
desktops: [1],
|
||||
activities: [1],
|
||||
resourceClass: resoureClass,
|
||||
caption: caption,
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/tests/tests.ts
Normal file
17
src/tests/tests.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
declare const process: {
|
||||
exit(code?: number): void,
|
||||
};
|
||||
|
||||
function assert(assertion: boolean, message?: string) {
|
||||
if (assertion) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message != undefined) {
|
||||
console.assert(assertion, message);
|
||||
} else {
|
||||
console.assert(assertion);
|
||||
}
|
||||
console.trace();
|
||||
process.exit(1);
|
||||
}
|
||||
5
src/tests/tsconfig.json
Normal file
5
src/tests/tsconfig.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"include": ["../lib/**/*", "./**/*"],
|
||||
"exclude": []
|
||||
}
|
||||
Reference in New Issue
Block a user