<commit_before>assert = require "assert"

AnimationTime = Framer.Defaults.Animation.time
AnimationProperties = ["x", "y", "midY", "rotation"]

describe "LayerAnimation", ->

	it "should use defaults", ->

		Framer.Defaults.Animation =
			curve: "ease-in"

		animation = new Animation new Layer(),
			x: 50

		animation.options.curve.should.equal Bezier.easeIn

		Framer.resetDefaults()

	it "should handle default spring curves correctly", ->

		Framer.Defaults.Animation =
			curve: Spring(0.5)

		layer = new Layer
		animation = layer.animate
			x: 50

		animation._animator.constructor.name.should.equal "SpringRK4Animator"

		Framer.resetDefaults()


	it "should use linear", ->

		# We shouldn't change the linear default, people rely on it

		animation = new Animation new Layer(),
			x: 50

		animation.options.curve.should.equal Bezier.ease
		animation.options.time.should.equal Framer.Defaults.Animation.time

	describe "Properties", ->

		AnimationProperties.map (p) ->

			it "should still support the deprecated API for property #{p}", (done) ->

				layer = new Layer()

				properties = {}
				properties[p] = 100

				layer.animate
					properties: properties
					curve: "linear"

				layer.on "end", ->
					layer[p].should.equal 100
					done()

			it "should animate property #{p}", (done) ->

				layer = new Layer()

				properties = {}
				properties[p] = 100
				options =
					curve: Bezier.easeInOut

				animation = layer.animate properties, options
				animation.options.curve.should.equal Bezier.easeInOut
				layer.on "end", ->
					layer[p].should.equal 100
					done()

			it "should support options key for property #{p}", (done) ->
				layer = new Layer()

				properties = {}
				properties[p] = 100
				properties.options =
					curve: Bezier.linear

				animation = layer.animate properties
				animation.options.curve.should.equal Bezier.linear

				layer.on "end", ->
					layer[p].should.equal 100
					done()

			it "should animate property #{p} with positive offset from current value", (done) ->

				layer = new Layer()
				layer[p] = 50

				properties = {}
				properties[p] = "+=50"

				layer.animate properties,
					curve: "linear"


				layer.on "end", ->
					layer[p].should.equal 100
					done()

			it "should animate property #{p} with negative offset from current value", (done) ->

				layer = new Layer()
				layer[p] = 50

				properties = {}
				properties[p] = "+=50"

				layer.animate properties,
					curve: "linear"


				layer.on "end", ->
					layer[p].should.equal 100
					done()


		it "should animate dynamic properties", (done) ->

			layer = new Layer()

			layer.animate
				scale: -> layer.scale + 1
				options:
					curve: "linear"

			layer.on "end", ->
				layer.scale.should.equal 2
				done()

		it "should animate colors", (done) ->

			color = "red"
			layer = new Layer()

			layer.animate
				backgroundColor: color
				options:
					curve: "linear"

			layer.on "end", ->
				layer.backgroundColor.toName().should.eql color
				done()

		it "should not animate non-animatable properties that are set to null", ->

			layerA = new Layer
			layerB = new Layer parent: layerA

			layerB.animate
				parent: null
				options:
					instant: true

			assert.equal(layerB.parent, layerA)


	describe "Basic", ->

		it "should stop", (done) ->

			layer = new Layer()

			animation = new Animation layer,
				x: 50
				options:
					curve: "linear"

			animation.start()

			Utils.delay animation.options.time / 2.0, ->
				animation.stop()
				layer.x.should.be.within(10, 45)
				done()

		it "should cancel previous animation for the same property", ->

			layer = new Layer()

			animationA = new Animation layer,
				x: 50
				options:
					curve: "linear"
<commit_msg>Giving animation a little bit more time, because it fails on CI<commit_after>assert = require "assert"

AnimationTime = Framer.Defaults.Animation.time
AnimationProperties = ["x", "y", "midY", "rotation"]

describe "LayerAnimation", ->

	it "should use defaults", ->

		Framer.Defaults.Animation =
			curve: "ease-in"

		animation = new Animation new Layer(),
			x: 50

		animation.options.curve.should.equal Bezier.easeIn

		Framer.resetDefaults()

	it "should handle default spring curves correctly", ->

		Framer.Defaults.Animation =
			curve: Spring(0.5)

		layer = new Layer
		animation = layer.animate
			x: 50

		animation._animator.constructor.name.should.equal "SpringRK4Animator"

		Framer.resetDefaults()


	it "should use linear", ->

		# We shouldn't change the linear default, people rely on it

		animation = new Animation new Layer(),
			x: 50

		animation.options.curve.should.equal Bezier.ease
		animation.options.time.should.equal Framer.Defaults.Animation.time

	describe "Properties", ->

		AnimationProperties.map (p) ->

			it "should still support the deprecated API for property #{p}", (done) ->

				layer = new Layer()

				properties = {}
				properties[p] = 100

				layer.animate
					properties: properties
					curve: "linear"

				layer.on "end", ->
					layer[p].should.equal 100
					done()

			it "should animate property #{p}", (done) ->

				layer = new Layer()

				properties = {}
				properties[p] = 100
				options =
					curve: Bezier.easeInOut

				animation = layer.animate properties, options
				animation.options.curve.should.equal Bezier.easeInOut
				layer.on "end", ->
					layer[p].should.equal 100
					done()

			it "should support options key for property #{p}", (done) ->
				layer = new Layer()

				properties = {}
				properties[p] = 100
				properties.options =
					curve: Bezier.linear

				animation = layer.animate properties
				animation.options.curve.should.equal Bezier.linear

				layer.on "end", ->
					layer[p].should.equal 100
					done()

			it "should animate property #{p} with positive offset from current value", (done) ->

				layer = new Layer()
				layer[p] = 50

				properties = {}
				properties[p] = "+=50"

				layer.animate properties,
					curve: "linear"


				layer.on "end", ->
					layer[p].should.equal 100
					done()

			it "should animate property #{p} with negative offset from current value", (done) ->

				layer = new Layer()
				layer[p] = 50

				properties = {}
				properties[p] = "+=50"

				layer.animate properties,
					curve: "linear"


				layer.on "end", ->
					layer[p].should.equal 100
					done()


		it "should animate dynamic properties", (done) ->

			layer = new Layer()

			layer.animate
				scale: -> layer.scale + 1
				options:
					curve: "linear"

			layer.on "end", ->
				layer.scale.should.equal 2
				done()

		it "should animate colors", (done) ->

			color = "red"
			layer = new Layer()

			layer.animate
				backgroundColor: color
				options:
					curve: "linear"

			layer.on "end", ->
				layer.backgroundColor.toName().should.eql color
				done()

		it "should not animate non-animatable properties that are set to null", ->

			layerA = new Layer
			layerB = new Layer parent: layerA

			layerB.animate
				parent: null
				options:
					instant: true

			assert.equal(layerB.parent, layerA)


	describe "Basic", ->

		it "should stop", (done) ->

			layer = new Layer()

			animation = new Animation layer,
				x: 50
				options:
					time: AnimationTime * 2
					curve: "linear"

			animation.start()

			Utils.delay animation.options.time / 2.0, ->
				animation.stop()
				layer.x.should.be.within(10, 45)
				done()

		it "should cancel previous animation for the same property", ->

			layer = new Layer()

			animationA = new Animation layer,
				x: 50
				options:
					curve: "linear"

{'fraction_non_alphanumeric': 0.12251087959910326, 'fraction_numerical': 0.01411051035210339, 'mean_word_length': 2.6977084349098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4806983', 'n_tokens_mistral': 3179, 'n_tokens_neox': 2229, 'n_words': 680}