Skip to content

Commit

Permalink
Add custom color and shadow assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed Dec 17, 2017
1 parent 0821535 commit 2aa68af
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
24 changes: 24 additions & 0 deletions test/tests.coffee
Expand Up @@ -22,6 +22,30 @@ chai.should()
chai.config.truncateThreshold = 2 chai.config.truncateThreshold = 2
chai.config.showDiff = true 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.setup({ui: "bdd", bail: true, reporter: "dot"})
mocha.globals(["__import__"]) mocha.globals(["__import__"])


Expand Down
37 changes: 14 additions & 23 deletions test/tests/LayerAnimationTest.coffee
Expand Up @@ -4,15 +4,6 @@ assert = require "assert"
AnimationTime = Framer.Defaults.Animation.time AnimationTime = Framer.Defaults.Animation.time
AnimationProperties = ["x", "y", "midY", "rotation"] 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", -> describe "LayerAnimation", ->


it "should use defaults", -> it "should use defaults", ->
Expand Down Expand Up @@ -199,7 +190,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd -> a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) -> layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true shadow.should.equalShadow template.shadows[index]
done() done()


it "should work when using the same kind of shadows", (done) -> it "should work when using the same kind of shadows", (done) ->
Expand All @@ -225,7 +216,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd -> a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) -> layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true shadow.should.equalShadow template.shadows[index]
done() done()


it "should work when using different shadows", (done) -> it "should work when using different shadows", (done) ->
Expand All @@ -248,7 +239,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd -> a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) -> layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true shadow.should.equalShadow template.shadows[index]
done() done()


it "should keep other shadows intact when animating one shadow", (done) -> it "should keep other shadows intact when animating one shadow", (done) ->
Expand All @@ -264,10 +255,10 @@ describe "LayerAnimation", ->
shadow.x.should.equal template.shadows[index].x shadow.x.should.equal template.shadows[index].x
shadow.y.should.equal template.shadows[index].y shadow.y.should.equal template.shadows[index].y
shadow.type.should.equal template.shadows[index].type 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 shadow.blur.should.equal 200
else else
equalShadows(shadow, template.shadows[index]).should.be.true shadow.should.equalShadow template.shadows[index]
done() done()


it "should animate to null shadow nicely", (done) -> it "should animate to null shadow nicely", (done) ->
Expand Down Expand Up @@ -296,13 +287,13 @@ describe "LayerAnimation", ->
shadow1 = layerA.shadows[0] shadow1 = layerA.shadows[0]
shadow1.type.should.equal "inset" shadow1.type.should.equal "inset"
opaqueShadowColor = shadow1.color.alpha(1) opaqueShadowColor = shadow1.color.alpha(1)
Color.equal(new Color("blue"), opaqueShadowColor).should.be.true opaqueShadowColor.shoul.equalColor "blue"
a.onAnimationEnd -> a.onAnimationEnd ->
layerA.shadow1.x.should.equal 100 layerA.shadow1.x.should.equal 100
layerA.shadow1.y.should.equal 0 layerA.shadow1.y.should.equal 0
layerA.shadow1.blur.should.equal 10 layerA.shadow1.blur.should.equal 10
layerA.shadow1.type.should.equal "inset" layerA.shadow1.type.should.equal "inset"
Color.equal(new Color("blue"), layerA.shadow1.color).should.be.true layerA.shadow1.color.should.equalColor "blue"
done() done()


it "should animate from no shadows nicely", (done) -> it "should animate from no shadows nicely", (done) ->
Expand All @@ -318,13 +309,13 @@ describe "LayerAnimation", ->
shadow1 = layerA.shadows[0] shadow1 = layerA.shadows[0]
shadow1.type.should.equal "inset" shadow1.type.should.equal "inset"
opaqueShadowColor = shadow1.color.alpha(1) opaqueShadowColor = shadow1.color.alpha(1)
Color.equal(new Color("blue"), opaqueShadowColor).should.be.true opaqueShadowColor.should.equalColor "blue"
a.onAnimationEnd -> a.onAnimationEnd ->
layerA.shadow1.x.should.equal 100 layerA.shadow1.x.should.equal 100
layerA.shadow1.y.should.equal 0 layerA.shadow1.y.should.equal 0
layerA.shadow1.blur.should.equal 10 layerA.shadow1.blur.should.equal 10
layerA.shadow1.type.should.equal "inset" layerA.shadow1.type.should.equal "inset"
Color.equal(new Color("blue"), layerA.shadow1.color).should.be.true layerA.shadow1.color.should.equalColor "blue"
done() done()


describe "by setting shadow array", -> describe "by setting shadow array", ->
Expand All @@ -335,7 +326,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd -> a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) -> layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true shadow.should.equalShadow template.shadows[index]
done() done()


it "should work when using the same kind of shadows", (done) -> it "should work when using the same kind of shadows", (done) ->
Expand All @@ -353,7 +344,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd -> a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) -> layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true shadow.should.equalShadow template.shadows[index]
done() done()


it "should work when using different shadows", (done) -> it "should work when using different shadows", (done) ->
Expand All @@ -368,7 +359,7 @@ describe "LayerAnimation", ->
a.onAnimationEnd -> a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) -> layer.shadows.map (shadow, index) ->
equalShadows(shadow, template.shadows[index]).should.be.true shadow.should.equalShadow template.shadows[index]
done() done()


describe "Basic", -> describe "Basic", ->
Expand Down Expand Up @@ -1258,14 +1249,14 @@ describe "LayerAnimation", ->


it "should animate the fill property", (done) -> it "should animate the fill property", (done) ->
layer.onAnimationEnd -> layer.onAnimationEnd ->
Color.equal(layer.fill, "yellow").should.be.true layer.fill.should.equalColor "yellow"
done() done()
layer.animate layer.animate
fill: "yellow" fill: "yellow"
x: 100 x: 100
it "should animate the stroke property", (done) -> it "should animate the stroke property", (done) ->
layer.onAnimationEnd -> layer.onAnimationEnd ->
Color.equal(layer.stroke, "yellow").should.be.true layer.stroke.should.equalColor "yellow"
done() done()
layer.animate layer.animate
stroke: "yellow" stroke: "yellow"
Expand Down
10 changes: 5 additions & 5 deletions test/tests/LayerTest.coffee
Expand Up @@ -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 # if the default background color is not set the content layer of scrollcomponent is not hidden when layers are added
layer = new Layer() layer = new Layer()


Color.equal(layer.backgroundColor, Framer.Defaults.Layer.backgroundColor).should.be.true layer.backgroundColor.should.equalColor Framer.Defaults.Layer.backgroundColor


Framer.Defaults = Framer.Defaults =
Layer: Layer:
Expand Down Expand Up @@ -371,12 +371,12 @@ describe "Layer", ->


layer = new Layer backgroundColor: "red" layer = new Layer backgroundColor: "red"
layer.image = imagePath layer.image = imagePath
Color.equal(layer.backgroundColor, new Color("red")).should.be.true layer.backgroundColor.should.equalColor "red"


layer = new Layer layer = new Layer
layer.backgroundColor = "red" layer.backgroundColor = "red"
layer.image = imagePath layer.image = imagePath
Color.equal(layer.backgroundColor, new Color("red")).should.be.true layer.backgroundColor.should.equalColor "red"


it "should set visible", -> it "should set visible", ->


Expand Down Expand Up @@ -911,7 +911,7 @@ describe "Layer", ->
l.shadows = [] l.shadows = []
l.shadowColor = "yellow" l.shadowColor = "yellow"
l.shadows.length.should.equal 1 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", -> it "should copy shadows if you copy a layer", ->
l = new Layer l = new Layer
Expand Down Expand Up @@ -1010,7 +1010,7 @@ describe "Layer", ->


layer.shadowX.should.equal 5 layer.shadowX.should.equal 5
layer.shadowY.should.equal 20 layer.shadowY.should.equal 20
Color.equal(layer.shadowColor, "blue").should.be.true layer.shadowColor.should.equalColor "blue"
layer.shadowBlur.should.equal 10 layer.shadowBlur.should.equal 10
layer.shadowType.should.equal "box" layer.shadowType.should.equal "box"


Expand Down

0 comments on commit 2aa68af

Please sign in to comment.