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 += ''; 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 = "
Ignore
"; - 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('020Arcyksiążę William2991.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('\n\ +\n\ +
IncreasePlaceKnightOrderLevelLootIgnore
062Arcyksiążę MichalOprych [IMP]198499.653.242
020Arcyksiążę William2991.041.479.270
'); + }); }); describe('Utils', () => {