Skip to content

Commit

Permalink
Add test for creation of html table.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Oct 29, 2024
1 parent 7d10530 commit c6c0925
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
19 changes: 10 additions & 9 deletions js/ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function dataPasted(textarea) {

knightsArray.sort(compare);

createTable();
document.getElementById("wrapper").innerHTML = createTable(knightsArray);

textarea.value = "";
}
Expand All @@ -126,7 +126,7 @@ function compare(a, b) {
return 0;
}

function createTable() {
function createTable(knights) {
var theader = '<table id="rounded-corner" >';
var tbody = "<tbody>";
tbody += "<thead><tr>";
Expand All @@ -139,16 +139,16 @@ function createTable() {
tbody += '<th scope="col">Ignore</th>';
tbody += "</tr>";
tbody += "</thead>";
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 += "<tr>";
tbody += createRow(knightsArray[i], i);
tbody += createRow(knights[i], i);
tbody += "</tr>\n";
}
tbody += "</tbody>";
var tfooter = "</table>";
document.getElementById("wrapper").innerHTML = theader + tbody + tfooter;
return theader + tbody + tfooter;
}

function checkIfKnightInArrayAndUpdate(knight) {
Expand All @@ -173,19 +173,20 @@ 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);
}


module.exports = {
dataPasted,
Knight,
compare,
createRow
createRow,
createTable
};

12 changes: 12 additions & 0 deletions test/ops.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ describe('Output', () => {

expect(row).toBe('<td>0</td><td>20</td><td>Arcyksiążę William</td><td></td><td>299</td><td>1.041.479.270</td><td><center><button class=\"btnIgnore\" name=\"button\" id=\"button\" onclick=\"ignoreKnight(1);\">x</button></center></td>');
});

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('<table id=\"rounded-corner\" ><tbody><thead><tr><th scope=\"col\">Increase</th><th scope=\"col\">Place</th><th scope=\"col\">Knight</th><th scope=\"col\">Order</th><th scope=\"col\">Level</th><th scope=\"col\">Loot</th><th scope=\"col\">Ignore</th></tr></thead><tr><td>0</td><td>62</td><td>Arcyksiążę MichalOprych </td><td>[IMP]</td><td>198</td><td>499.653.242</td><td><center><button class=\"btnIgnore\" name=\"button\" id=\"button\" onclick=\"ignoreKnight(0);\">x</button></center></td></tr>\n\
<tr><td>0</td><td>20</td><td>Arcyksiążę William</td><td></td><td>299</td><td>1.041.479.270</td><td><center><button class=\"btnIgnore\" name=\"button\" id=\"button\" onclick=\"ignoreKnight(1);\">x</button></center></td></tr>\n\
</tbody></table>');
});
});

describe('Utils', () => {
Expand Down

0 comments on commit c6c0925

Please sign in to comment.