From c6c092571216d280f88effedfda1b2d2387543e6 Mon Sep 17 00:00:00 2001
From: przemek83 <4788832+przemek83@users.noreply.github.com>
Date: Tue, 29 Oct 2024 19:54:17 +0100
Subject: [PATCH] Add test for creation of html table.
---
js/ops.js | 19 ++++++++++---------
test/ops.test.js | 12 ++++++++++++
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/js/ops.js b/js/ops.js
index 4137ac3..1210bc3 100644
--- a/js/ops.js
+++ b/js/ops.js
@@ -111,7 +111,7 @@ function dataPasted(textarea) {
knightsArray.sort(compare);
- createTable();
+ document.getElementById("wrapper").innerHTML = createTable(knightsArray);
textarea.value = "";
}
@@ -126,7 +126,7 @@ function compare(a, b) {
return 0;
}
-function createTable() {
+function createTable(knights) {
var theader = '
';
var tbody = "";
tbody += "";
@@ -139,16 +139,16 @@ function createTable() {
tbody += 'Ignore | ';
tbody += "
";
tbody += "";
- for (var i = 0; i < knightsArray.length; i++) {
- if (knightsArray[i].ignore === true) continue;
+ for (var i = 0; i < knights.length; i++) {
+ if (knights[i].ignore === true) continue;
tbody += "";
- tbody += createRow(knightsArray[i], i);
+ tbody += createRow(knights[i], i);
tbody += "
\n";
}
tbody += "";
var tfooter = "
";
- document.getElementById("wrapper").innerHTML = theader + tbody + tfooter;
+ return theader + tbody + tfooter;
}
function checkIfKnightInArrayAndUpdate(knight) {
@@ -173,12 +173,12 @@ function saveCheckpoint() {
knightsArray[i].lootDiff = 0;
}
- createTable();
+ document.getElementById("wrapper").innerHTML = createTable(knightsArray);
}
function ignoreKnight(number) {
knightsArray[number].ignore = true;
- createTable();
+ document.getElementById("wrapper").innerHTML = createTable(knightsArray);
}
@@ -186,6 +186,7 @@ module.exports = {
dataPasted,
Knight,
compare,
- createRow
+ createRow,
+ createTable
};
diff --git a/test/ops.test.js b/test/ops.test.js
index 125fa52..0283ec9 100644
--- a/test/ops.test.js
+++ b/test/ops.test.js
@@ -78,6 +78,18 @@ describe('Output', () => {
expect(row).toBe('0 | 20 | Arcyksiążę William | | 299 | 1.041.479.270 | | ');
});
+
+ const knights = new Array();
+ knights[0] = new toTest.Knight(knightWithOrderText);
+ knights[1] = new toTest.Knight(knightWithoutOrderText);
+
+ test('should create table with 2 knights', () => {
+ const table = toTest.createTable(knights)
+
+ expect(table).toBe('Increase | Place | Knight | Order | Level | Loot | Ignore |
---|
0 | 62 | Arcyksiążę MichalOprych | [IMP] | 198 | 499.653.242 | |
\n\
+0 | 20 | Arcyksiążę William | | 299 | 1.041.479.270 | |
\n\
+
');
+ });
});
describe('Utils', () => {