unit tests part 5
This commit is contained in:
parent
a2af5b23a3
commit
7b1295bb02
3 changed files with 11 additions and 19 deletions
|
@ -1,9 +1,11 @@
|
|||
import { html } from "./broker";
|
||||
import { test, beforeAll, afterAll } from "@jest/globals";
|
||||
|
||||
/*jest.useFakeTimers();
|
||||
|
||||
beforeAll(() => {
|
||||
jest.spyOn(console, "log").mockImplementation(() => {});
|
||||
});
|
||||
});*/
|
||||
|
||||
test("Generate HTML for hexagram", () => {
|
||||
expect(html("Hexagram No. 45 ䷬\nGathering Together [Massing]\n萃 (cuì)"))
|
||||
|
@ -20,6 +22,6 @@ test("Generate HTML for images", () => {
|
|||
.toBe("<p><h3>Images:</h3>Over the earth, the lake:<br>The image of Gathering Together.<br>Thus the superior man renews his weapons<br>In order to meet the unforseen.<br></p></div>");
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
/*afterAll(() => {
|
||||
(console.log as jest.Mock).mockRestore();
|
||||
});
|
||||
});*/
|
||||
|
|
20
broker.ts
20
broker.ts
|
@ -94,7 +94,7 @@ async function sendEmail(content: string) {
|
|||
//Calculate the time for the next execution of the main process, depending on configuration.
|
||||
//Returns the time of the next process loop.
|
||||
function calculateNextRunDate(daysInterval: number, timeOfDay: string): Date {
|
||||
/*const currentDate = new Date();
|
||||
const currentDate = new Date();
|
||||
|
||||
// Splitte die Uhrzeit in Stunden und Minuten
|
||||
const [hours, minutes] = timeOfDay.split(':').map(Number);
|
||||
|
@ -110,11 +110,6 @@ function calculateNextRunDate(daysInterval: number, timeOfDay: string): Date {
|
|||
// Berechne das Datum für den nächsten Ausführungszeitpunkt unter Berücksichtigung von X Tagen
|
||||
currentDate.setDate(currentDate.getDate() + daysInterval);
|
||||
|
||||
return currentDate;*/
|
||||
|
||||
//TODO: JUST FOR DEBUGGING!!!
|
||||
const currentDate = new Date();
|
||||
currentDate.setMinutes(currentDate.getMinutes() + 2);
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
|
@ -125,7 +120,7 @@ function scheduleNextRun(nextRunDate: Date) {
|
|||
|
||||
if (timeUntilNextRun > 0) {
|
||||
setTimeout(() => {
|
||||
console.log('Prozess wird ausgeführt!');
|
||||
console.log('Next iteration of Process was scheduled!');
|
||||
|
||||
//run the main process
|
||||
executeCommand();
|
||||
|
@ -185,7 +180,7 @@ function parse(input: string): Node {
|
|||
function render(node: Node): string {
|
||||
|
||||
if (node == undefined) {
|
||||
console.log("...finished...")
|
||||
console.log("Rendering of nodes finished!")
|
||||
|
||||
return "";
|
||||
}
|
||||
|
@ -197,19 +192,18 @@ function render(node: Node): string {
|
|||
switch (node.type) {
|
||||
case "Root":
|
||||
return render(node.child!);
|
||||
|
||||
case "Hexagram":
|
||||
node.value = node.value?.replace("<h1>", "<div style=\"border: 1px dotted gray; border-radius: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px; padding-bottom: 10px; width: auto; display: inline-block; box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);\"><h1>");
|
||||
node.value = node.value?.replace("</h1>", "</h1><div style=\"border: 1px solid gray; border-radius: 25px; padding-left: 30px; padding-right: 30px; padding-top: 20px; width: auto; display: inline-block; text-align: center; box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);\"><h2>");
|
||||
node.value = node.value?.replace("<br>", " - ");
|
||||
outputHTML = "<br><p>" + node.value + "</h2></div></p>";
|
||||
outputHTML = outputHTML + render(node.child!);
|
||||
|
||||
return outputHTML;
|
||||
|
||||
case "Images":
|
||||
outputHTML = "<p>" + node.value + "</p></div>"; //EXTRA closing div
|
||||
outputHTML = "<p>" + node.value + "</p></div>"; //EXTRA closing div (was opened at beginning of hexagram)
|
||||
outputHTML = outputHTML + render(node.child!);
|
||||
|
||||
return outputHTML;
|
||||
|
||||
case "ChangingLines" :
|
||||
|
@ -218,16 +212,12 @@ function render(node: Node): string {
|
|||
//outputHTML = "<br><p><div style=\"border: 1px dashed gray; border-radius: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px; width: auto; display: inline-block; color: gray; text-align: center; box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);\">" + node.value + "</div></p><br>";
|
||||
outputHTML = "<br><br><p><div style=\"padding-left: 20px; padding-right: 20px; padding-top: 20px; display: inline-block; color: gray; text-align: center;\">" + node.value + "</div></p><br>";
|
||||
outputHTML = outputHTML + render(node.child!);
|
||||
|
||||
return outputHTML;
|
||||
|
||||
default:
|
||||
outputHTML = "<p>" + node.value + "</p>";
|
||||
outputHTML = outputHTML + render(node.child!);
|
||||
|
||||
return outputHTML;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
"version": "1.0.0",
|
||||
"main": "broker.js",
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
"test": "jest --runInBand --detectOpenHandles --force-exit"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
|
Loading…
Reference in a new issue