|
| 1 | +<html> |
| 2 | +<head> |
| 3 | + <meta charset="utf-8"> |
| 4 | + <title>Mocha Tests</title> |
| 5 | + <link rel="stylesheet" href="lib/mocha.css" /> |
| 6 | + <script src="../../dist/html2canvas.js"></script> |
| 7 | + <script src="../../src/log.js"></script> |
| 8 | + <script src="../../src/renderer.js"></script> |
| 9 | + <script src="../../src/renderers/canvas.js"></script> |
| 10 | + <script src="../assets/jquery-1.6.2.js"></script> |
| 11 | + <script src="lib/expect.js"></script> |
| 12 | + <script src="lib/mocha.js"></script> |
| 13 | + <style> |
| 14 | + .block { |
| 15 | + width: 200px; |
| 16 | + height: 200px; |
| 17 | + } |
| 18 | + </style> |
| 19 | +</head> |
| 20 | +<body> |
| 21 | +<div id="mocha"></div> |
| 22 | +<script>mocha.setup('bdd')</script> |
| 23 | +<div id="block1" class="block"> |
| 24 | + <input type="text" value="text" /> |
| 25 | +</div> |
| 26 | +<div id="block2" class="block"> |
| 27 | + <input type="password" value="password" /> |
| 28 | +</div> |
| 29 | +<div id="block3" class="block"> |
| 30 | + <input type="text" value="text" /> |
| 31 | +</div> |
| 32 | + |
| 33 | +<div id="block4" class="block"> |
| 34 | + <textarea>text</textarea> |
| 35 | +</div> |
| 36 | + |
| 37 | +<div id="block5" class="block"> |
| 38 | + <select> |
| 39 | + <option value="1">1</option> |
| 40 | + <option value="2" selected>2</option> |
| 41 | + <option value="3">3</option> |
| 42 | + </select> |
| 43 | +</div> |
| 44 | + |
| 45 | +<div id="green-block"></div> |
| 46 | +<script> |
| 47 | + describe("Rendering input values", function() { |
| 48 | + it("uses default value for input[type='text']", function(done) { |
| 49 | + CanvasRenderer.prototype.text = function(text) { |
| 50 | + expect(text).to.equal('text'); |
| 51 | + }; |
| 52 | + html2canvas(document.querySelector("#block1"), {renderer: CanvasRenderer, strict: true}).then(function(canvas) { |
| 53 | + expect(canvas.width).to.equal(200); |
| 54 | + expect(canvas.height).to.equal(200); |
| 55 | + done(); |
| 56 | + }).catch(function(error) { |
| 57 | + done(error); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + it("uses transformed value for input[type='password']", function(done) { |
| 62 | + var count = 0; |
| 63 | + CanvasRenderer.prototype.text = function(text) { |
| 64 | + expect(text).to.equal('•'); |
| 65 | + count++; |
| 66 | + }; |
| 67 | + html2canvas(document.querySelector("#block2"), {renderer: CanvasRenderer, strict: true}).then(function(canvas) { |
| 68 | + expect(canvas.width).to.equal(200); |
| 69 | + expect(canvas.height).to.equal(200); |
| 70 | + expect(count).to.equal("password".length); |
| 71 | + done(); |
| 72 | + }).catch(function(error) { |
| 73 | + done(error); |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + it("used property and not attribute for rendering", function(done) { |
| 78 | + document.querySelector("#block3 input").value = 'updated'; |
| 79 | + |
| 80 | + CanvasRenderer.prototype.text = function(text) { |
| 81 | + expect(text).to.equal('updated'); |
| 82 | + }; |
| 83 | + html2canvas(document.querySelector("#block3"), {renderer: CanvasRenderer, strict: true}).then(function(canvas) { |
| 84 | + expect(canvas.width).to.equal(200); |
| 85 | + expect(canvas.height).to.equal(200); |
| 86 | + done(); |
| 87 | + }).catch(function(error) { |
| 88 | + done(error); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + describe("Rendering textarea values", function() { |
| 93 | + it("uses default value correctly", function(done) { |
| 94 | + CanvasRenderer.prototype.text = function(text) { |
| 95 | + expect(text).to.equal('text'); |
| 96 | + }; |
| 97 | + html2canvas(document.querySelector("#block4"), {renderer: CanvasRenderer, strict: true}).then(function(canvas) { |
| 98 | + expect(canvas.width).to.equal(200); |
| 99 | + expect(canvas.height).to.equal(200); |
| 100 | + done(); |
| 101 | + }).catch(function(error) { |
| 102 | + done(error); |
| 103 | + }); |
| 104 | + }); |
| 105 | + |
| 106 | + it("used property and not attribute for rendering", function(done) { |
| 107 | + document.querySelector("#block4 textarea").value = 'updated'; |
| 108 | + |
| 109 | + CanvasRenderer.prototype.text = function(text) { |
| 110 | + expect(text).to.equal('updated'); |
| 111 | + }; |
| 112 | + html2canvas(document.querySelector("#block4"), {renderer: CanvasRenderer, strict: true, logging: true, removeContainer: false}).then(function(canvas) { |
| 113 | + expect(canvas.width).to.equal(200); |
| 114 | + expect(canvas.height).to.equal(200); |
| 115 | + done(); |
| 116 | + }).catch(function(error) { |
| 117 | + done(error); |
| 118 | + }); |
| 119 | + }); |
| 120 | + }); |
| 121 | + |
| 122 | + describe("Select values", function() { |
| 123 | + it("uses default value correctly", function(done) { |
| 124 | + CanvasRenderer.prototype.text = function(text) { |
| 125 | + expect(text).to.equal('2'); |
| 126 | + }; |
| 127 | + html2canvas(document.querySelector("#block5"), {renderer: CanvasRenderer, strict: true}).then(function(canvas) { |
| 128 | + expect(canvas.width).to.equal(200); |
| 129 | + expect(canvas.height).to.equal(200); |
| 130 | + done(); |
| 131 | + }).catch(function(error) { |
| 132 | + done(error); |
| 133 | + }); |
| 134 | + }); |
| 135 | + |
| 136 | + it("used property and not attribute for rendering", function(done) { |
| 137 | + document.querySelector("#block5 select").value = '3'; |
| 138 | + |
| 139 | + CanvasRenderer.prototype.text = function(text) { |
| 140 | + expect(text).to.equal('3'); |
| 141 | + }; |
| 142 | + html2canvas(document.querySelector("#block5"), {renderer: CanvasRenderer, strict: true, logging: true, removeContainer: false}).then(function(canvas) { |
| 143 | + expect(canvas.width).to.equal(200); |
| 144 | + expect(canvas.height).to.equal(200); |
| 145 | + done(); |
| 146 | + }).catch(function(error) { |
| 147 | + done(error); |
| 148 | + }); |
| 149 | + }); |
| 150 | + }); |
| 151 | + }); |
| 152 | + |
| 153 | + mocha.checkLeaks(); |
| 154 | + mocha.globals(['jQuery']); |
| 155 | + if (window.mochaPhantomJS) { |
| 156 | + mochaPhantomJS.run(); |
| 157 | + } |
| 158 | + else { |
| 159 | + mocha.run(); |
| 160 | + } |
| 161 | +</script> |
| 162 | +</body> |
| 163 | +</html> |
0 commit comments