<repo_name>ArtemGovorov/wallaby-402<file_sep>/test/polyfill.js
if (!Function.prototype.bind) {
  Function.prototype.bind = function(oThis) {
    if (typeof this !== 'function') {
      // closest thing possible to the ECMAScript 5
      // internal IsCallable function
      throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
    }

    var aArgs   = Array.prototype.slice.call(arguments, 1),
      fToBind = this,
      fNOP    = function() {},
      fBound  = function() {
        return fToBind.apply(this instanceof fNOP && oThis
            ? this
            : oThis,
          aArgs.concat(Array.prototype.slice.call(arguments)));
      };

    // test this.prototype in case of native functions binding:
    if (this.prototype)
      fNOP.prototype = this.prototype;
    fBound.prototype = new fNOP();

    return fBound;
  };
}

if (!Object.assign) {
  Object.defineProperty(Object, 'assign', {
    enumerable: false,
    configurable: true,
    writable: true,
    value: function(target) {
      'use strict';
      if (target === undefined || target === null) {
        throw new TypeError('Cannot convert first argument to object');
      }

      var to = Object(target);
      for (var i = 1; i < arguments.length; i++) {
        var nextSource = arguments[i];
        if (nextSource === undefined || nextSource === null) {
          continue;
        }
        nextSource = Object(nextSource);

        var keysArray = Object.keys(Object(nextSource));
        for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
          var nextKey = keysArray[nextIndex];
          var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
          if (desc !== undefined && desc.enumerable) {
            to[nextKey] = nextSource[nextKey];
          }
        }
      }
      return to;
    }
  });
}<file_sep>/app/constants/build_constants.js
var imageRoot = "/app/images/";
var fontRoot = "/app/fonts/";
var styleRoot = "/app/style/";
var mobileDir = "Mobile_Assets/";
var webDir = "Client_Assets/";
var webPath = imageRoot + webDir;
var mobilePath = imageRoot + mobileDir;
var demoPath = "http://url1.com/";
var devPath = "https://url2.net";
// these variables are injected into both Javascript and SCSS.
module.exports = {
  templateDir: JSON.stringify("jsx-templates/foxwoods/"),
  styleDir: JSON.stringify("style/foxwoods/"),
  webPath: JSON.stringify(imageRoot + webDir),
  mobilePath: JSON.stringify(imageRoot + mobileDir),
  _facebookEnabled: false,
  WebpackAPIRoot: JSON.stringify(devPath)
};<file_sep>/app/game-wrappers/gamesInterface.js
var keyMirror = require('keymirror');
import * as _ from 'lodash';

var events = keyMirror({
  ERROR_DESCRIPTION: null,
  TEST: null
});

var Actions = keyMirror({
  NOT_IMPLEMENTED: null,
  ERROR_DESCRIPTION: null
});

console.log(WebpackAPIRoot);

/**
 * @name buildAction
 * @param suppliedType string
 * @param suppliedJson {json | string}
 */
export function buildAction(suppliedType, suppliedJson) {
  return {type: suppliedType, json: suppliedJson, errors: []};
}

/**
 * @name notifyViewEventDispatcher
 * @param actionObject Action
 */
export function notifyViewEventDispatcher(actionObject) {
  // stub
}
/**
 * @name notifyViewEventDispatcher
 * @param key
 * @param value
 * @param actionObject
 *
 **/
export function notifyServerEventDispatcher(key, value, actionObject) {
 // stub
}

export function stubbedListener(event) {
  if (event === undefined || event === null) {
    console.log("Undefined or null event. Returning.");
    return;
  }

  if (event.target == document.getElementById("iframeCanvas")) {
    var data = event.data;
    var separator = data.indexOf(":");
    var key = data.substr(0, separator);
    var value = data.substr(separator + 1);
    notifyPropertyChanged(key, value);
  }
}

/**
 * @name sendEventToIFrame
 * @param key
 * @param value
 * @method
 */
export function sendEventToIFrame(key, value = null){
  let dataString = "";
  if(value === null){
    dataString = key;
  }else{
    dataString = key.toString().toUpperCase()+":"+value.toString().toUpperCase();
  }
  document.getElementById("iframeCanvas").contentWindow.postMessage(dataString, "*");
}

export function addFrameEventListener(eventRef, suppliedListener = stubbedListener) {
  eventRef.addEventListener('message', suppliedListener, false);
}

export function removeFrameEventListener(eventRef, suppliedListener = stubbedListener) {
  eventRef.removeEventListener("message", suppliedListener);
  console.log("Event listener removed.");
}

export function notImplemented(suppliedKey, suppliedValue) {
  notifyViewEventDispatcher(buildAction(
    Actions.NOT_IMPLEMENTED,
    JSON.stringify({[suppliedKey]: suppliedValue}),
    "{}"
   // JSON.stringify({key: suppliedValue})
    //JSON.stringify({[suppliedKey]: suppliedValue})
  ));
}

export function notifyPropertyChanged(key, value) {
  var eventReactions = {
    [events.ERROR_DESCRIPTION]: function logError(message) {
      console.warn("error: " + message);
    }
  };
  if (_.includes(Object.keys(events), key)) {
    eventReactions[key](value);
  }
}
var publicObj = {
  notifyPropertyChanged: notifyPropertyChanged,
  addGameEventListener: addFrameEventListener,
  removeGameEventListener: removeFrameEventListener,
  sendEventToGame: sendEventToIFrame
};
export default publicObj;
<file_sep>/app/game-wrappers/gamesInterface-Test.js
import GamesInterface from './gamesInterface';
var domino = require('domino');
describe('gamesInterface', function () {
  it('should receive events from supplied element', function (done) {
    var window = domino.createWindow('<iframe id="iframeCanvas" src="about:blank"  sandbox="allow-same-origin allow-scripts"></iframe>');
    var document = window.document;

    function spyOnListener (event) {
      var testData = event.data;
      assert.equal(testData, "TEST:SUCCESS");
      done();
    }

    var elementRef = document.getElementById("iframeCanvas");
    should.exist(elementRef);
    GamesInterface.addGameEventListener(elementRef,spyOnListener);
    var event = document.createEvent('Event');
    event.initEvent('message', true, true);
    event.origin = "https://expectedUrl.com";
    event.data = "TEST:SUCCESS";
    elementRef.dispatchEvent(event);
  });
});
