From 9183f9f658222dc3a24c8b4794887b6ecd80ba1e Mon Sep 17 00:00:00 2001 From: Ian Coleman Date: Tue, 21 Nov 2017 12:06:56 +1100 Subject: Allow more rows to be generated at a custom index --- src/index.html | 7 +++++-- src/js/index.js | 18 +++++++++++++++++- tests/spec/tests.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/index.html b/src/index.html index cdd2ab2..63533a9 100644 --- a/src/index.html +++ b/src/index.html @@ -622,9 +622,12 @@ - Show more rows: + Show - + + starting from index + + (leave blank to generate from next index)
diff --git a/src/js/index.js b/src/js/index.js index 739dc01..38a7efd 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -80,6 +80,7 @@ DOM.addresses = $(".addresses"); DOM.rowsToAdd = $(".rows-to-add"); DOM.more = $(".more"); + DOM.moreRowsStartIndex = $(".more-rows-start-index"); DOM.feedback = $(".feedback"); DOM.tab = $(".derivation-type a"); DOM.indexToggle = $(".index-toggle"); @@ -750,12 +751,19 @@ } function showMore() { - var start = DOM.addresses.children().length; var rowsToAdd = parseInt(DOM.rowsToAdd.val()); if (isNaN(rowsToAdd)) { rowsToAdd = 20; DOM.rowsToAdd.val("20"); } + var start = parseInt(DOM.moreRowsStartIndex.val()) + if (isNaN(start)) { + start = lastIndexInTable() + 1; + } + else { + var newStart = start + rowsToAdd; + DOM.moreRowsStartIndex.val(newStart); + } if (rowsToAdd > 200) { var msg = "Generating " + rowsToAdd + " rows could take a while. "; msg += "Do you want to continue?"; @@ -1291,6 +1299,14 @@ } } + function lastIndexInTable() { + var pathText = DOM.addresses.find(".index").last().text(); + var pathBits = pathText.split("/"); + var lastBit = pathBits[pathBits.length-1]; + var lastBitClean = lastBit.replace("'", ""); + return parseInt(lastBitClean); + } + var networks = [ { name: "BCH - Bitcoin Cash", diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 998809a..f10f7a4 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -2577,4 +2577,48 @@ it('Can use bitpay format for bitcoin cash addresses', function(done) { }); }); +// End of tests ported from old suit, so no more comments above each test now + +it('Can generate more addresses from a custom index', function(done) { + var expectedIndexes = [ + 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, + 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59 + ]; + driver.findElement(By.css('.phrase')) + .sendKeys("abandon abandon ability"); + driver.sleep(generateDelay).then(function() { + // Set start of next lot of rows to be from index 40 + // which means indexes 20-39 will not be in the table. + driver.findElement(By.css('.more-rows-start-index')) + .sendKeys("40"); + driver.findElement(By.css('.more')) + .click(); + driver.sleep(generateDelay).then(function() { + // Check actual indexes in the table match the expected pattern + driver.findElements(By.css(".index")) + .then(function(els) { + expect(els.length).toBe(expectedIndexes.length); + var testRowAtIndex = function(i) { + if (i >= expectedIndexes.length) { + done(); + } + else { + els[i].getText() + .then(function(actualPath) { + var noHardened = actualPath.replace(/'/g, ""); + var pathBits = noHardened.split("/") + var lastBit = pathBits[pathBits.length-1]; + var actualIndex = parseInt(lastBit); + var expectedIndex = expectedIndexes[i]; + expect(actualIndex).toBe(expectedIndex); + testRowAtIndex(i+1); + }); + } + } + testRowAtIndex(0); + }); + }); + }); +}); + }); -- cgit v1.2.3