<commit_before>/* global describe:true, it:true, before:true, beforeEach:true, afterEach:true */
import assert from 'assert';
import { contains } from 'lodash';
import { setupTestRekapi, setupTestActor } from './test-utils';

import Rekapi, { KeyframeProperty } from '../src/main';
import {
  Tweenable,
  interpolate,
  setBezierFunction,
  unsetBezierFunction
} from 'shifty';

describe('KeyframeProperty', () => {
  let rekapi, actor;

  beforeEach(() => {
    rekapi = setupTestRekapi();
    actor = setupTestActor(rekapi);
  });

  describe('constructor', () => {
    it('is a function', () => {
      assert.equal(typeof KeyframeProperty, 'function');
    });
  });
});<commit_msg>Port KeyframeProperty tests<commit_after>/* global describe:true, it:true, before:true, beforeEach:true, afterEach:true */
import assert from 'assert';
import { contains } from 'lodash';
import { setupTestRekapi, setupTestActor } from './test-utils';

import Rekapi, { KeyframeProperty } from '../src/main';
import {
  Tweenable,
  interpolate,
  setBezierFunction,
  unsetBezierFunction
} from 'shifty';

describe('KeyframeProperty', () => {
  let rekapi, actor;

  beforeEach(() => {
    rekapi = setupTestRekapi();
    actor = setupTestActor(rekapi);
  });

  describe('constructor', () => {
    it('is a function', () => {
      assert.equal(typeof KeyframeProperty, 'function');
    });

    it('sets key object properties', () => {
      const keyframeProperty = new Rekapi.KeyframeProperty(500, 'x', 10, 'easeInQuad');

      assert.equal(keyframeProperty.millisecond, 500);
      assert.equal(keyframeProperty.name, 'x');
      assert.equal(keyframeProperty.value, 10);
      assert.equal(keyframeProperty.easing, 'easeInQuad');
    });
  });

  describe('#modifyWith', () => {
    it('modifies properties', function () {
      const keyframeProperty = new Rekapi.KeyframeProperty(500, 'x', 10, 'easeInQuad');

      keyframeProperty.modifyWith({
        millisecond: 1500,
        easing: 'bounce',
        value: 123456
      });

      assert.equal(keyframeProperty.millisecond, 1500);
      assert.equal(keyframeProperty.value, 123456);
      assert.equal(keyframeProperty.easing, 'bounce');
    });
  });

  describe('#linkToNext', () => {
    it('links to a given KeyframeProperty instance', () => {
      const keyframeProperty = new Rekapi.KeyframeProperty(500, 'x', 10, 'easeInQuad');
      const linkedKeyprop = new Rekapi.KeyframeProperty(1000, 'x', 20, 'swingTo');

      keyframeProperty.linkToNext(linkedKeyprop);

      assert.equal(keyframeProperty.nextProperty, linkedKeyprop);
    });
  });

  describe('#getValueAt', () => {
    it('computes given midpoint between self and linked KeyframeProperty instance', () => {
      const keyframeProperty = new Rekapi.KeyframeProperty(500, 'x', 10, 'linear');
      const linkedKeyprop = new Rekapi.KeyframeProperty(1000, 'x', 20, 'linear');

      keyframeProperty.linkToNext(linkedKeyprop);
      const midpoint = keyframeProperty.getValueAt(750);

      assert.equal(midpoint, 15);
    });
  });

  describe('#detach', () => {
    it('destroys actor/keyframeProperty association', () => {
      actor.keyframe(0, { x: 10 });
      const keyframeProperty = actor.getKeyframeProperty('x', 0);

      assert.equal(actor, keyframeProperty.actor);
      keyframeProperty.detach();
      assert.equal(null, keyframeProperty.actor);
    });
  });

  describe('#exportPropertyData', () => {
    it('exports key data points', () => {
      actor.keyframe(0, { x: 1 });

      const exportedProp = actor._propertyTracks.x[0].exportPropertyData();
      assert.equal(typeof exportedProp.millisecond, 'number');
      assert.equal(typeof exportedProp.name, 'string');
      assert.equal(typeof exportedProp.value, 'number');
      assert.equal(typeof exportedProp.easing, 'string');
    });
  });

  describe('removeKeyframeProperty event', () => {
    let removeKeyframePropertyWasTriggered, keyframeProperty;

    beforeEach(() => {
      removeKeyframePropertyWasTriggered = false;
      actor.keyframe(0, { x: 10 });
      keyframeProperty = actor.getKeyframeProperty('x', 0);
      rekapi.on('removeKeyframeProperty', () => removeKeyframePropertyWasTriggered = true);
    });

    it('is fired by #detach', () => {
      keyframeProperty.detach();
      assert(removeKeyframePropertyWasTriggered);
    });

    it('is fired by Actor#removeKeyframe', () => {
      actor.removeKeyframe(0);
      assert(removeKeyframePropertyWasTriggered);
    });

    it('is fired by Actor#removeAllKeyframes', () => {
      actor.removeAllKeyframes();
      assert(removeKeyframePropertyWasTriggered);
    });

    it('is fired by Actor#removeKeyframeProperty', () => {
      actor.removeKeyframeProperty('x', 0);
      assert(removeKeyframePropertyWasTriggered);
    });
  });
});
{'fraction_non_alphanumeric': 0.15279219431181232, 'fraction_numerical': 0.015569856757317833, 'mean_word_length': 3.842211055276382, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '5869010', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1446, 'n_words': 276}