Permalink
Browse files

Add custom color and shadow assertions

  • Loading branch information...
nvh committed Dec 17, 2017
1 parent 0821535 commit 2aa68af43497debf23a6c2ccb797bce263cfec09
Showing with 43 additions and 28 deletions.
  1. +24 −0 test/tests.coffee
  2. +14 −23 test/tests/LayerAnimationTest.coffee
  3. +5 −5 test/tests/LayerTest.coffee
View
@@ -22,6 +22,30 @@ chai.should()
chai.config.truncateThreshold = 2
chai.config.showDiff = true
chai.Assertion.addChainableMethod 'equalColor', (color) ->
expected = color
actual = @_obj
return @assert Color.equal(expected, actual),
"expected #{this._obj} to equal #{color}",
"expected #{this._obj} to not equal #{color}"
chai.Assertion.addChainableMethod 'equalShadow', (shadow) ->
expected = shadow
actual = @_obj
equal = true
for key, value of expected
if Color.isColor(value)
equal = equal and Color.equal(value, actual[key])
else
equal = equal and _.eq(value, actual[key])
return @assert equal,
"expected #{Utils.inspect(this._obj)} to equal #{Utils.inspect(shadow)}",
"expected #{Utils.inspect(this._obj)} to not equal #{Utils.inspect(shadow)}"
mocha.setup({ui: "bdd", bail: true, reporter: "dot"})
mocha.globals(["__import__"])
@@ -4,15 +4,6 @@ assert = require "assert"
AnimationTime = Framer.Defaults.Animation.time
AnimationProperties = ["x", "y", "midY", "rotation"]
equalShadows = (shadow1, shadow2) ->
equal = true
for key, value of shadow1
if Color.isColor(value)
equal = equal and Color.equal(value, shadow2[key])
else
equal = equal and _.eq(value, shadow2[key])
return equal
describe "LayerAnimation", ->
it "should use defaults", ->
@@ -199,7 +190,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true
shadow.should.equalShadow template.shadows[index]
done()
it "should work when using the same kind of shadows", (done) ->
@@ -225,7 +216,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true
shadow.should.equalShadow template.shadows[index]
done()
it "should work when using different shadows", (done) ->
@@ -248,7 +239,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true
shadow.should.equalShadow template.shadows[index]
done()
it "should keep other shadows intact when animating one shadow", (done) ->
@@ -264,10 +255,10 @@ describe "LayerAnimation", ->
shadow.x.should.equal template.shadows[index].x
shadow.y.should.equal template.shadows[index].y
shadow.type.should.equal template.shadows[index].type
Color.equal(shadow.color, template.shadows[index].color).should.be.true
shadow.color.should.equalColor template.shadows[index].color
shadow.blur.should.equal 200
else
equalShadows(shadow, template.shadows[index]).should.be.true
shadow.should.equalShadow template.shadows[index]
done()
it "should animate to null shadow nicely", (done) ->
@@ -296,13 +287,13 @@ describe "LayerAnimation", ->
shadow1 = layerA.shadows[0]
shadow1.type.should.equal "inset"
opaqueShadowColor = shadow1.color.alpha(1)
Color.equal(new Color("blue"), opaqueShadowColor).should.be.true
opaqueShadowColor.shoul.equalColor "blue"
a.onAnimationEnd ->
layerA.shadow1.x.should.equal 100
layerA.shadow1.y.should.equal 0
layerA.shadow1.blur.should.equal 10
layerA.shadow1.type.should.equal "inset"
Color.equal(new Color("blue"), layerA.shadow1.color).should.be.true
layerA.shadow1.color.should.equalColor "blue"
done()
it "should animate from no shadows nicely", (done) ->
@@ -318,13 +309,13 @@ describe "LayerAnimation", ->
shadow1 = layerA.shadows[0]
shadow1.type.should.equal "inset"
opaqueShadowColor = shadow1.color.alpha(1)
Color.equal(new Color("blue"), opaqueShadowColor).should.be.true
opaqueShadowColor.should.equalColor "blue"
a.onAnimationEnd ->
layerA.shadow1.x.should.equal 100
layerA.shadow1.y.should.equal 0
layerA.shadow1.blur.should.equal 10
layerA.shadow1.type.should.equal "inset"
Color.equal(new Color("blue"), layerA.shadow1.color).should.be.true
layerA.shadow1.color.should.equalColor "blue"
done()
describe "by setting shadow array", ->
@@ -335,7 +326,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true
shadow.should.equalShadow template.shadows[index]
done()
it "should work when using the same kind of shadows", (done) ->
@@ -353,7 +344,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true
shadow.should.equalShadow template.shadows[index]
done()
it "should work when using different shadows", (done) ->
@@ -368,7 +359,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true
shadow.should.equalShadow template.shadows[index]
done()
describe "Basic", ->
@@ -1258,14 +1249,14 @@ describe "LayerAnimation", ->
it "should animate the fill property", (done) ->
layer.onAnimationEnd ->
Color.equal(layer.fill, "yellow").should.be.true
layer.fill.should.equalColor "yellow"
done()
layer.animate
fill: "yellow"
x: 100
it "should animate the stroke property", (done) ->
layer.onAnimationEnd ->
Color.equal(layer.stroke, "yellow").should.be.true
layer.stroke.should.equalColor "yellow"
done()
layer.animate
stroke: "yellow"
@@ -50,7 +50,7 @@ describe "Layer", ->
# if the default background color is not set the content layer of scrollcomponent is not hidden when layers are added
layer = new Layer()
Color.equal(layer.backgroundColor, Framer.Defaults.Layer.backgroundColor).should.be.true
layer.backgroundColor.should.equalColor Framer.Defaults.Layer.backgroundColor
Framer.Defaults =
Layer:
@@ -371,12 +371,12 @@ describe "Layer", ->
layer = new Layer backgroundColor: "red"
layer.image = imagePath
Color.equal(layer.backgroundColor, new Color("red")).should.be.true
layer.backgroundColor.should.equalColor "red"
layer = new Layer
layer.backgroundColor = "red"
layer.image = imagePath
Color.equal(layer.backgroundColor, new Color("red")).should.be.true
layer.backgroundColor.should.equalColor "red"
it "should set visible", ->
@@ -911,7 +911,7 @@ describe "Layer", ->
l.shadows = []
l.shadowColor = "yellow"
l.shadows.length.should.equal 1
Color.equal(l.shadows[0].color, "yellow").should.be.true
l.shadows[0].color.should.equalColor "yellow"
it "should copy shadows if you copy a layer", ->
l = new Layer
@@ -1010,7 +1010,7 @@ describe "Layer", ->
layer.shadowX.should.equal 5
layer.shadowY.should.equal 20
Color.equal(layer.shadowColor, "blue").should.be.true
layer.shadowColor.should.equalColor "blue"
layer.shadowBlur.should.equal 10
layer.shadowType.should.equal "box"

0 comments on commit 2aa68af

Please sign in to comment.