Skip to content

Commit

Permalink
Merge pull request #391 from koenbok/feature/defaults-fix
Browse files Browse the repository at this point in the history
Fix Framer.resetDefaults
  • Loading branch information
koenbok committed Aug 1, 2016
2 parents 9cf0155 + 7a8790a commit 5ee40e2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
5 changes: 2 additions & 3 deletions framer/Defaults.coffee
Expand Up @@ -87,8 +87,7 @@ exports.Defaults =
options = _.clone options

# Always start with the originals
defaults = _.clone Originals[className]

defaults = _.cloneDeep Originals[className]
# Copy over the user defined options
for k, v of Framer.Defaults[className]
defaults[k] = if _.isFunction(v) then v() else v
Expand All @@ -114,4 +113,4 @@ exports.Defaults =
exports.Defaults.reset()

reset: ->
window.Framer.Defaults = _.clone Originals
window.Framer.Defaults = _.cloneDeep Originals
12 changes: 9 additions & 3 deletions test/tests.coffee
@@ -1,8 +1,14 @@
window.chai = require("chai")

# We don't want to update all the tests if we change these
Framer.Defaults.Layer.width = 100
Framer.Defaults.Layer.height = 100

previousReset = Framer.resetDefaults

Framer.resetDefaults = ->
previousReset()
# We don't want to update all the tests if we change these
Framer.Defaults.Layer.width = 100
Framer.Defaults.Layer.height = 100
Framer.resetDefaults()

window.console.debug = (v) ->
window.console.warn = (v) ->
Expand Down
26 changes: 20 additions & 6 deletions test/tests/LayerTest.coffee
Expand Up @@ -11,22 +11,36 @@ describe "Layer", ->

describe "Defaults", ->

it "should set defaults", ->
it "should reset nested defaults", ->
Framer.Defaults.DeviceComponent.animationOptions.curve = "spring"
Framer.resetDefaults()
Framer.Defaults.DeviceComponent.animationOptions.curve.should.equal "ease-in-out"

it "should reset width and height to their previous values", ->
previousWidth = Framer.Defaults.Layer.width
previousHeight = Framer.Defaults.Layer.height
Framer.Defaults.Layer.width = 123
Framer.Defaults.Layer.height = 123
Framer.resetDefaults()
Framer.Defaults.Layer.width.should.equal previousWidth
Framer.Defaults.Layer.height.should.equal previousHeight

it "should set defaults", ->
width = Utils.randomNumber(0,400)
height = Utils.randomNumber(0,400)
Framer.Defaults =
Layer:
width: 200
height: 200
width: width
height: height

layer = new Layer()

layer.width.should.equal 200
layer.height.should.equal 200
layer.width.should.equal width
layer.height.should.equal height

Framer.resetDefaults()

layer = new Layer()

layer.width.should.equal 100
layer.height.should.equal 100

Expand Down

0 comments on commit 5ee40e2

Please sign in to comment.