From d70b13eedda83bc6bb7da3f6d604979d4eda0f10 Mon Sep 17 00:00:00 2001
From: fuzhen <fuzhen@maptalks.org>
Date: Sat, 16 Jan 2016 17:22:47 +0800
Subject: [PATCH] add tests for globalAlpha

---
 test/unit.spec.js | 38 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/test/unit.spec.js b/test/unit.spec.js
index e8f05a7..bcafbd1 100644
--- a/test/unit.spec.js
+++ b/test/unit.spec.js
@@ -296,4 +296,40 @@ describe('canvas2svg', function() {
         });
 
     });
-});
\ No newline at end of file
+
+    describe("supports globalOpacity", function() {
+        it("set stroke-opacity when stroking and set fill-opacity when filling",function() {
+            var ctx = new C2S();
+            ctx.globalAlpha = 0.5;
+            ctx.moveTo(5,5);
+            ctx.lineTo(15,15);
+            ctx.stroke();
+            var svg = ctx.getSvg();
+            expect(svg.querySelector("path").getAttribute("stroke-opacity")).to.equal('0.5');
+            ctx.globalAlpha = 0.1;
+            ctx.fillStyle = "#000000";
+            ctx.fill();
+            expect(svg.querySelector("path").getAttribute("fill-opacity")).to.equal('0.1');
+            //stroke-opacity stays o.5
+            expect(svg.querySelector("path").getAttribute("stroke-opacity")).to.equal('0.5');
+        });
+
+        it("added into color opacity when stroking or filling with rgba style color. ",function() {
+            var ctx = new C2S();
+            ctx.strokeStyle="rgba(0,0,0,0.8)";
+            ctx.globalAlpha = 0.5;
+            ctx.moveTo(5,5);
+            ctx.lineTo(15,15);
+            ctx.stroke();
+            var svg = ctx.getSvg();
+            expect(svg.querySelector("path").getAttribute("stroke")).to.equal('rgb(0,0,0)');
+            //stroke-opacity should be globalAlpha*(alpha in rgba)
+            expect(svg.querySelector("path").getAttribute("stroke-opacity")).to.equal(''+0.8*0.5);
+            ctx.globalAlpha = 0.6;
+            ctx.fillStyle = "rgba(0,0,0,0.6)";
+            ctx.fill();
+            expect(svg.querySelector("path").getAttribute("fill-opacity")).to.equal(''+0.6*0.6);
+            expect(svg.querySelector("path").getAttribute("stroke-opacity")).to.equal(''+0.8*0.5);
+        });
+    });
+});