]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Test incorrect mnemonic shows error
authorIan Coleman <coleman.ian@gmail.com>
Thu, 29 Sep 2016 08:52:51 +0000 (18:52 +1000)
committerIan Coleman <coleman.ian@gmail.com>
Thu, 29 Sep 2016 08:52:51 +0000 (18:52 +1000)
tests.js

index e5a40ae1447b138d7043ee5a462ea3e1a59fd674..f76baf85adec70f5fdaf4f2a045aab96a81f7934 100644 (file)
--- a/tests.js
+++ b/tests.js
@@ -44,6 +44,37 @@ function waitForGenerate(fn, maxTime) {
     wait();
 }
 
+function waitForFeedback(fn, maxTime) {
+    if (!maxTime) {
+        maxTime = testMaxTime;
+    }
+    var start = new Date().getTime();
+    var wait = function keepWaiting() {
+        var now = new Date().getTime();
+        var hasTimedOut = now - start > maxTime;
+        if (hasTimedOut) {
+            console.log("Test timed out");
+            fn();
+            return;
+        }
+        var feedback = page.evaluate(function() {
+            var feedback = $(".feedback");
+            if (feedback.css("display") == "none") {
+                return "";
+            }
+            return feedback.text();
+        });
+        var hasFinished = feedback.length > 0 && feedback != "Calculating...";
+        if (hasFinished) {
+            fn();
+        }
+        else {
+            setTimeout(keepWaiting, 100);
+        }
+    }
+    wait();
+}
+
 function next() {
     if (tests.length > 0) {
         var testsStr = tests.length == 1 ? "test" : "tests";
@@ -1404,6 +1435,26 @@ page.open(url, function(status) {
 },
 
 // Incorrect mnemonic shows error
+function() {
+page.open(url, function(status) {
+    // set the root key
+    page.evaluate(function() {
+        $(".phrase").val("abandon abandon abandon").trigger("input");
+    });
+    waitForFeedback(function() {
+        // check there is an error shown
+        var feedback = page.evaluate(function() {
+            return $(".feedback").text();
+        });
+        if (feedback.length <= 0) {
+            console.log("Invalid mnemonic does not show error");
+            fail();
+        }
+        next();
+    });
+});
+},
+
 // Incorrect word shows suggested replacement
 // Incorrect BIP32 root key shows error
 // Derivation path not starting with m shows error