aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2016-10-20 16:22:49 +1100
committerIan Coleman <coleman.ian@gmail.com>2016-10-20 16:22:49 +1100
commite1bae8436ab35aa99f8e7e378db0c8a8d1f316e0 (patch)
treef5328a00dd80bcdac01d6dc23db768429359cc41
parent7c31e3cd23202ae93fb4736ae96b4acae6dafacb (diff)
downloadBIP39-e1bae8436ab35aa99f8e7e378db0c8a8d1f316e0.tar.gz
BIP39-e1bae8436ab35aa99f8e7e378db0c8a8d1f316e0.tar.zst
BIP39-e1bae8436ab35aa99f8e7e378db0c8a8d1f316e0.zip
Non-English language tests added
-rw-r--r--tests.js148
1 files changed, 148 insertions, 0 deletions
diff --git a/tests.js b/tests.js
index 4fd2ca5..ebdf9ec 100644
--- a/tests.js
+++ b/tests.js
@@ -1762,6 +1762,154 @@ page.open(url, function(status) {
1762}); 1762});
1763}, 1763},
1764 1764
1765// Selecting a language with no existing phrase should generate a phrase in
1766// that language.
1767function() {
1768page.open(url, function(status) {
1769 // Select a language
1770 // Need to manually simulate hash being set due to quirk between
1771 // 'click' event triggered by javascript vs triggered by mouse.
1772 // Perhaps look into page.sendEvent
1773 // http://phantomjs.org/api/webpage/method/send-event.html
1774 page.evaluate(function() {
1775 window.location.hash = "#japanese";
1776 $("a[href='#japanese']").trigger("click");
1777 });
1778 waitForGenerate(function() {
1779 // Check the mnemonic is in Japanese
1780 var phrase = page.evaluate(function() {
1781 return $(".phrase").val();
1782 });
1783 if (phrase.length <= 0) {
1784 console.log("No Japanese phrase generated");
1785 fail();
1786 }
1787 if (phrase.charCodeAt(0) < 128) {
1788 console.log("First character of Japanese phrase is ascii");
1789 console.log("Phrase: " + phrase);
1790 fail();
1791 }
1792 next();
1793 });
1794});
1795},
1796
1797// Selecting a language with existing phrase should update the phrase to use
1798// that language.
1799function() {
1800page.open(url, function(status) {
1801 // Set the phrase to an English phrase.
1802 page.evaluate(function() {
1803 $(".phrase").val("abandon abandon ability").trigger("input");
1804 });
1805 waitForGenerate(function() {
1806 // Change to Italian
1807 // Need to manually simulate hash being set due to quirk between
1808 // 'click' event triggered by javascript vs triggered by mouse.
1809 // Perhaps look into page.sendEvent
1810 // http://phantomjs.org/api/webpage/method/send-event.html
1811 page.evaluate(function() {
1812 window.location.hash = "#italian";
1813 $("a[href='#italian']").trigger("click");
1814 });
1815 waitForGenerate(function() {
1816 // Check only the language changes, not the phrase
1817 var expected = "abaco abaco abbaglio";
1818 var actual = page.evaluate(function() {
1819 return $(".phrase").val();
1820 });
1821 if (actual != expected) {
1822 console.log("Changing language with existing phrase");
1823 console.log("Expected: " + expected);
1824 console.log("Actual: " + actual);
1825 fail();
1826 }
1827 // Check the address is correct
1828 var expected = "1Dz5TgDhdki9spa6xbPFbBqv5sjMrx3xgV";
1829 var actual = page.evaluate(function() {
1830 return $(".address:first").text();
1831 });
1832 if (actual != expected) {
1833 console.log("Changing language generates incorrect address");
1834 console.log("Expected: " + expected);
1835 console.log("Actual: " + actual);
1836 fail();
1837 }
1838 next();
1839 });
1840 });
1841});
1842},
1843
1844// Suggested replacement for erroneous word in non-English language
1845function() {
1846page.open(url, function(status) {
1847 // Set an incorrect phrase in Italian
1848 page.evaluate(function() {
1849 $(".phrase").val("abaco abaco zbbaglio").trigger("input");
1850 });
1851 waitForFeedback(function() {
1852 // Check the suggestion is correct
1853 var feedback = page.evaluate(function() {
1854 return $(".feedback").text();
1855 });
1856 if (feedback.indexOf("did you mean abbaglio?") < 0) {
1857 console.log("Incorrect Italian word does not show suggested replacement");
1858 console.log("Error: " + error);
1859 fail();
1860 }
1861 next();
1862 });
1863});
1864},
1865
1866
1867// Japanese word does not break across lines.
1868// Point 2 from
1869// https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md#japanese
1870function() {
1871page.open(url, function(status) {
1872 hasWordBreakCss = page.content.indexOf("word-break: keep-all;") > -1;
1873 if (!hasWordBreakCss) {
1874 console.log("Japanese words can break across lines mid-word");
1875 console.log("Check CSS for '.phrase { word-break: keep-all; }'");
1876 fail();
1877 }
1878 // Run the next test
1879 next();
1880});
1881},
1882
1883// Language can be specified at page load using hash value in url
1884function() {
1885page.open(url, function(status) {
1886 // Set the page hash as if it were on a fresh page load
1887 page.evaluate(function() {
1888 window.location.hash = "#japanese";
1889 });
1890 // Generate a random phrase
1891 page.evaluate(function() {
1892 $(".generate").trigger("click");
1893 });
1894 waitForGenerate(function() {
1895 // Check the phrase is in Japanese
1896 var phrase = page.evaluate(function() {
1897 return $(".phrase").val();
1898 });
1899 if (phrase.length <= 0) {
1900 console.log("No phrase generated using url hash");
1901 fail();
1902 }
1903 if (phrase.charCodeAt(0) < 128) {
1904 console.log("Language not detected from url hash on page load.");
1905 console.log("Phrase: " + phrase);
1906 fail();
1907 }
1908 next();
1909 });
1910});
1911},
1912
1765// If you wish to add more tests, do so here... 1913// If you wish to add more tests, do so here...
1766 1914
1767// Here is a blank test template 1915// Here is a blank test template