Permalink
Browse files

Add gradient tests and fix warnings

  • Loading branch information...
jonastreub committed Jun 12, 2017
1 parent cc7d5b1 commit 7cea5338b47f0b0c130cbdf7b7e045c074a0d71e
Showing with 56 additions and 3 deletions.
  1. +3 −3 framer/LinearGradient.coffee
  2. +1 −0 test/tests.coffee
  3. +52 −0 test/tests/LinearGradientTest.coffee
@@ -24,7 +24,7 @@ class exports.LinearGradient extends BaseClass
set: (value) ->
@_angle = value if _.isNumber(value)
toCSS: () =>
toCSS: =>
return "linear-gradient(#{this.angle}deg, #{this.start}, #{this.end})"
mix: (gradientB, fraction) =>
@@ -56,7 +56,7 @@ class exports.LinearGradient extends BaseClass
end: end
angle: angle
@random: () ->
@random: ->
hue = Math.random() * 360
colorA = new Color h: hue
colorB = new Color h: hue + 40
@@ -73,4 +73,4 @@ class exports.LinearGradient extends BaseClass
equalAngle = Math.abs(gradientA.angle - gradientB.angle) % 360 is 0
equalStart = Color.equal(gradientA.start, gradientB.start)
equalEnd = Color.equal(gradientA.end, gradientB.end)
return equalAngle and equalStart and equalEnd
return equalAngle and equalStart and equalEnd
View
@@ -46,6 +46,7 @@ require "./tests/TextLayerTest"
require "./tests/PageComponentTest"
require "./tests/VersionTest"
require "./tests/ColorTest"
require "./tests/LinearGradientTest"
require "./tests/DeviceComponentTest"
require "./tests/SliderComponentTest"
require "./tests/RangeSliderComponentTest"
@@ -0,0 +1,52 @@
describe "Linear Gradient", ->
it "should allow input as object", ->
start = "red"
end = "orange"
angle = 20
gradient = new LinearGradient
start: start
end: end
angle: angle
gradient.start.isEqual(start).should.be.true
gradient.end.isEqual(end).should.be.true
gradient.angle.should.equal angle
it "should compare for equality", ->
gradient = new LinearGradient
angle: 360
start: "red"
equalGradient = new LinearGradient
angle: 0
start: "red"
LinearGradient.equal(gradient, equalGradient).should.be.true
unequalGradient = new LinearGradient
angle: 90
unequalGradient.isEqual(gradient).should.be.false
it "should mix gradients", ->
colorA = "red"
colorB = "yellow"
gradientA = new LinearGradient
start: colorA
gradientB = new LinearGradient
start: colorB
angle: 90
mixed = gradientA.mix(gradientB)
mixed.angle.should.equal 45
mixed.start.isEqual(Color.mix(colorA, colorB)).should.be.true
it "should take the shortest route when animating to a new angle", ->
gradientA = new LinearGradient
angle: 0
gradientB = new LinearGradient
angle: 405
mixed = LinearGradient.mix(gradientA, gradientB, 1)
mixed.angle.should.equal 45

0 comments on commit 7cea533

Please sign in to comment.