;(function() { /*! * @overview Ember - JavaScript Application Framework * @copyright Copyright 2011-2016 Tilde Inc. and contributors * Portions Copyright 2006-2011 Strobe Inc. * Portions Copyright 2008-2011 Apple Inc. All rights reserved. * @license Licensed under MIT license * See https://raw.github.com/emberjs/ember.js/master/LICENSE * @version 2.6.0-beta.1 */ var enifed, requireModule, require, Ember; var mainContext = this; (function() { var isNode = typeof window === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; if (!isNode) { Ember = this.Ember = this.Ember || {}; } if (typeof Ember === 'undefined') { Ember = {}; } if (typeof Ember.__loader === 'undefined') { var registry = {}; var seen = {}; enifed = function(name, deps, callback) { var value = { }; if (!callback) { value.deps = []; value.callback = deps; } else { value.deps = deps; value.callback = callback; } registry[name] = value; }; require = requireModule = function(name) { return internalRequire(name, null); }; // setup `require` module require['default'] = require; require.has = function registryHas(moduleName) { return !!registry[moduleName] || !!registry[moduleName + '/index']; }; function missingModule(name, referrerName) { if (referrerName) { throw new Error('Could not find module ' + name + ' required by: ' + referrerName); } else { throw new Error('Could not find module ' + name); } } function internalRequire(_name, referrerName) { var name = _name; var mod = registry[name]; if (!mod) { name = name + '/index'; mod = registry[name]; } var exports = seen[name]; if (exports !== undefined) { return exports; } exports = seen[name] = {}; if (!mod) { missingModule(_name, referrerName); } var deps = mod.deps; var callback = mod.callback; var length = deps.length; var reified = new Array(length); for (var i = 0; i < length; i++) { if (deps[i] === 'exports') { reified[i] = exports; } else if (deps[i] === 'require') { reified[i] = require; } else { reified[i] = internalRequire(deps[i], name); } } callback.apply(this, reified); return exports; } requireModule._eak_seen = registry; Ember.__loader = { define: enifed, require: require, registry: registry }; } else { enifed = Ember.__loader.define; require = requireModule = Ember.__loader.require; } })(); enifed('ember-debug/deprecate', ['exports', 'ember-metal/core', 'ember-metal/error', 'ember-metal/logger', 'ember-debug/handlers'], function (exports, _emberMetalCore, _emberMetalError, _emberMetalLogger, _emberDebugHandlers) { /*global __fail__*/ 'use strict'; var _slice = Array.prototype.slice; exports.registerHandler = registerHandler; exports.default = deprecate; function registerHandler(handler) { _emberDebugHandlers.registerHandler('deprecate', handler); } function formatMessage(_message, options) { var message = _message; if (options && options.id) { message = message + (' [deprecation id: ' + options.id + ']'); } if (options && options.url) { message += ' See ' + options.url + ' for more details.'; } return message; } registerHandler(function logDeprecationToConsole(message, options) { var updatedMessage = formatMessage(message, options); _emberMetalLogger.default.warn('DEPRECATION: ' + updatedMessage); }); var captureErrorForStack = undefined; if (new Error().stack) { captureErrorForStack = function () { return new Error(); }; } else { captureErrorForStack = function () { try { __fail__.fail(); } catch (e) { return e; } }; } registerHandler(function logDeprecationStackTrace(message, options, next) { if (_emberMetalCore.default.LOG_STACKTRACE_ON_DEPRECATION) { var stackStr = ''; var error = captureErrorForStack(); var stack = undefined; if (error.stack) { if (error['arguments']) { // Chrome stack = error.stack.replace(/^\s+at\s+/gm, '').replace(/^([^\(]+?)([\n$])/gm, '{anonymous}($1)$2').replace(/^Object.\s*\(([^\)]+)\)/gm, '{anonymous}($1)').split('\n'); stack.shift(); } else { // Firefox stack = error.stack.replace(/(?:\n@:0)?\s+$/m, '').replace(/^\(/gm, '{anonymous}(').split('\n'); } stackStr = '\n ' + stack.slice(2).join('\n '); } var updatedMessage = formatMessage(message, options); _emberMetalLogger.default.warn('DEPRECATION: ' + updatedMessage + stackStr); } else { next.apply(undefined, arguments); } }); registerHandler(function raiseOnDeprecation(message, options, next) { if (_emberMetalCore.default.ENV.RAISE_ON_DEPRECATION) { var updatedMessage = formatMessage(message); throw new _emberMetalError.default(updatedMessage); } else { next.apply(undefined, arguments); } }); var missingOptionsDeprecation = 'When calling `Ember.deprecate` you ' + 'must provide an `options` hash as the third parameter. ' + '`options` should include `id` and `until` properties.'; exports.missingOptionsDeprecation = missingOptionsDeprecation; var missingOptionsIdDeprecation = 'When calling `Ember.deprecate` you must provide `id` in options.'; exports.missingOptionsIdDeprecation = missingOptionsIdDeprecation; var missingOptionsUntilDeprecation = 'When calling `Ember.deprecate` you must provide `until` in options.'; exports.missingOptionsUntilDeprecation = missingOptionsUntilDeprecation; /** @module ember @submodule ember-debug */ /** Display a deprecation warning with the provided message and a stack trace (Chrome and Firefox only). * In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build. @method deprecate @param {String} message A description of the deprecation. @param {Boolean} test A boolean. If falsy, the deprecation will be displayed. @param {Object} options An object that can be used to pass in a `url` to the transition guide on the emberjs.com website, and a unique `id` for this deprecation. The `id` can be used by Ember debugging tools to change the behavior (raise, log or silence) for that specific deprecation. The `id` should be namespaced by dots, e.g. "view.helper.select". @for Ember @public */ function deprecate(message, test, options) { if (!options || !options.id && !options.until) { deprecate(missingOptionsDeprecation, false, { id: 'ember-debug.deprecate-options-missing', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options' }); } if (options && !options.id) { deprecate(missingOptionsIdDeprecation, false, { id: 'ember-debug.deprecate-id-missing', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options' }); } if (options && !options.until) { deprecate(missingOptionsUntilDeprecation, options && options.until, { id: 'ember-debug.deprecate-until-missing', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options' }); } _emberDebugHandlers.invoke.apply(undefined, ['deprecate'].concat(_slice.call(arguments))); } }); enifed('ember-debug/handlers', ['exports', 'ember-debug/is-plain-function', 'ember-debug/deprecate'], function (exports, _emberDebugIsPlainFunction, _emberDebugDeprecate) { 'use strict'; exports.generateTestAsFunctionDeprecation = generateTestAsFunctionDeprecation; exports.registerHandler = registerHandler; exports.invoke = invoke; var HANDLERS = {}; exports.HANDLERS = HANDLERS; function generateTestAsFunctionDeprecation(source) { return 'Calling `' + source + '` with a function argument is deprecated. Please ' + 'use `!!Constructor` for constructors, or an `IIFE` to compute the test for deprecation. ' + 'In a future version, functions will be treated as truthy values instead of being executed.'; } function normalizeTest(test, source) { if (_emberDebugIsPlainFunction.default(test)) { _emberDebugDeprecate.default(generateTestAsFunctionDeprecation(source), false, { id: 'ember-debug.deprecate-test-as-function', until: '2.5.0' }); return test(); } return test; } function registerHandler(type, callback) { var nextHandler = HANDLERS[type] || function () {}; HANDLERS[type] = function (message, options) { callback(message, options, nextHandler); }; } function invoke(type, message, test, options) { if (normalizeTest(test, 'Ember.' + type)) { return; } var handlerForType = HANDLERS[type]; if (!handlerForType) { return; } if (handlerForType) { handlerForType(message, options); } } }); enifed('ember-debug/index', ['exports', 'ember-metal/core', 'ember-metal/debug', 'ember-metal/features', 'ember-metal/error', 'ember-metal/logger', 'ember-metal/environment', 'ember-debug/deprecate', 'ember-debug/warn', 'ember-debug/is-plain-function', 'ember-debug/handlers'], function (exports, _emberMetalCore, _emberMetalDebug, _emberMetalFeatures, _emberMetalError, _emberMetalLogger, _emberMetalEnvironment, _emberDebugDeprecate, _emberDebugWarn, _emberDebugIsPlainFunction, _emberDebugHandlers) { 'use strict'; exports._warnIfUsingStrippedFeatureFlags = _warnIfUsingStrippedFeatureFlags; /** @module ember @submodule ember-debug */ /** @class Ember @public */ /** Define an assertion that will throw an exception if the condition is not met. * In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build. ```javascript // Test for truthiness Ember.assert('Must pass a valid object', obj); // Fail unconditionally Ember.assert('This code path should never be run'); ``` @method assert @param {String} desc A description of the assertion. This will become the text of the Error thrown if the assertion fails. @param {Boolean} test Must be truthy for the assertion to pass. If falsy, an exception will be thrown. @public */ _emberMetalDebug.setDebugFunction('assert', function assert(desc, test) { var throwAssertion = undefined; if (_emberDebugIsPlainFunction.default(test)) { _emberMetalDebug.deprecate(_emberDebugHandlers.generateTestAsFunctionDeprecation('Ember.assert'), false, { id: 'ember-debug.deprecate-test-as-function', until: '2.5.0' }); throwAssertion = !test(); } else { throwAssertion = !test; } if (throwAssertion) { throw new _emberMetalError.default('Assertion Failed: ' + desc); } }); /** Display a debug notice. * In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build. ```javascript Ember.debug('I\'m a debug notice!'); ``` @method debug @param {String} message A debug message to display. @public */ _emberMetalDebug.setDebugFunction('debug', function debug(message) { _emberMetalLogger.default.debug('DEBUG: ' + message); }); /** Display an info notice. * In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build. @method info @private */ _emberMetalDebug.setDebugFunction('info', function info() { _emberMetalLogger.default.info.apply(undefined, arguments); }); /** Alias an old, deprecated method with its new counterpart. Display a deprecation warning with the provided message and a stack trace (Chrome and Firefox only) when the assigned method is called. * In a production build, this method is defined as an empty function (NOP). ```javascript Ember.oldMethod = Ember.deprecateFunc('Please use the new, updated method', Ember.newMethod); ``` @method deprecateFunc @param {String} message A description of the deprecation. @param {Object} [options] The options object for Ember.deprecate. @param {Function} func The new function called to replace its deprecated counterpart. @return {Function} A new function that wraps the original function with a deprecation warning @private */ _emberMetalDebug.setDebugFunction('deprecateFunc', function deprecateFunc() { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } if (args.length === 3) { var _ret = (function () { var message = args[0]; var options = args[1]; var func = args[2]; return { v: function () { _emberMetalDebug.deprecate(message, false, options); return func.apply(this, arguments); } }; })(); if (typeof _ret === 'object') return _ret.v; } else { var _ret2 = (function () { var message = args[0]; var func = args[1]; return { v: function () { _emberMetalDebug.deprecate(message); return func.apply(this, arguments); } }; })(); if (typeof _ret2 === 'object') return _ret2.v; } }); /** Run a function meant for debugging. * In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build. ```javascript Ember.runInDebug(() => { Ember.Component.reopen({ didInsertElement() { console.log("I'm happy"); } }); }); ``` @method runInDebug @param {Function} func The function to be executed. @since 1.5.0 @public */ _emberMetalDebug.setDebugFunction('runInDebug', function runInDebug(func) { func(); }); _emberMetalDebug.setDebugFunction('debugSeal', function debugSeal(obj) { Object.seal(obj); }); _emberMetalDebug.setDebugFunction('deprecate', _emberDebugDeprecate.default); _emberMetalDebug.setDebugFunction('warn', _emberDebugWarn.default); /** Will call `Ember.warn()` if ENABLE_OPTIONAL_FEATURES or any specific FEATURES flag is truthy. This method is called automatically in debug canary builds. @private @method _warnIfUsingStrippedFeatureFlags @return {void} */ function _warnIfUsingStrippedFeatureFlags(FEATURES, knownFeatures, featuresWereStripped) { if (featuresWereStripped) { _emberMetalDebug.warn('Ember.ENV.ENABLE_OPTIONAL_FEATURES is only available in canary builds.', !_emberMetalCore.default.ENV.ENABLE_OPTIONAL_FEATURES, { id: 'ember-debug.feature-flag-with-features-stripped' }); var keys = Object.keys(FEATURES || {}); for (var i = 0; i < keys.length; i++) { var key = keys[i]; if (key === 'isEnabled' || !(key in knownFeatures)) { continue; } _emberMetalDebug.warn('FEATURE["' + key + '"] is set as enabled, but FEATURE flags are only available in canary builds.', !FEATURES[key], { id: 'ember-debug.feature-flag-with-features-stripped' }); } } } if (!_emberMetalCore.default.testing) { // Complain if they're using FEATURE flags in builds other than canary _emberMetalFeatures.FEATURES['features-stripped-test'] = true; var featuresWereStripped = true; delete _emberMetalFeatures.FEATURES['features-stripped-test']; _warnIfUsingStrippedFeatureFlags(_emberMetalCore.default.ENV.FEATURES, _emberMetalFeatures.KNOWN_FEATURES, featuresWereStripped); // Inform the developer about the Ember Inspector if not installed. var isFirefox = _emberMetalEnvironment.default.isFirefox; var isChrome = _emberMetalEnvironment.default.isChrome; if (typeof window !== 'undefined' && (isFirefox || isChrome) && window.addEventListener) { window.addEventListener('load', function () { if (document.documentElement && document.documentElement.dataset && !document.documentElement.dataset.emberExtension) { var downloadURL; if (isChrome) { downloadURL = 'https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi'; } else if (isFirefox) { downloadURL = 'https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/'; } _emberMetalDebug.debug('For more advanced debugging, install the Ember Inspector from ' + downloadURL); } }, false); } } /** @public @class Ember.Debug */ _emberMetalCore.default.Debug = {}; /** Allows for runtime registration of handler functions that override the default deprecation behavior. Deprecations are invoked by calls to [Ember.deprecate](http://emberjs.com/api/classes/Ember.html#method_deprecate). The following example demonstrates its usage by registering a handler that throws an error if the message contains the word "should", otherwise defers to the default handler. ```javascript Ember.Debug.registerDeprecationHandler((message, options, next) => { if (message.indexOf('should') !== -1) { throw new Error(`Deprecation message with should: ${message}`); } else { // defer to whatever handler was registered before this one next(message, options); } } ``` The handler function takes the following arguments: @public @static @method registerDeprecationHandler @param handler {Function} A function to handle deprecation calls. @since 2.1.0 */ _emberMetalCore.default.Debug.registerDeprecationHandler = _emberDebugDeprecate.registerHandler; /** Allows for runtime registration of handler functions that override the default warning behavior. Warnings are invoked by calls made to [Ember.warn](http://emberjs.com/api/classes/Ember.html#method_warn). The following example demonstrates its usage by registering a handler that does nothing overriding Ember's default warning behavior. ```javascript // next is not called, so no warnings get the default behavior Ember.Debug.registerWarnHandler(() => {}); ``` The handler function takes the following arguments: @public @static @method registerWarnHandler @param handler {Function} A function to handle warnings. @since 2.1.0 */ _emberMetalCore.default.Debug.registerWarnHandler = _emberDebugWarn.registerHandler; /* We are transitioning away from `ember.js` to `ember.debug.js` to make it much clearer that it is only for local development purposes. This flag value is changed by the tooling (by a simple string replacement) so that if `ember.js` (which must be output for backwards compat reasons) is used a nice helpful warning message will be printed out. */ var runningNonEmberDebugJS = false; exports.runningNonEmberDebugJS = runningNonEmberDebugJS; if (runningNonEmberDebugJS) { _emberMetalDebug.warn('Please use `ember.debug.js` instead of `ember.js` for development and debugging.'); } }); enifed('ember-debug/is-plain-function', ['exports'], function (exports) { 'use strict'; exports.default = isPlainFunction; function isPlainFunction(test) { return typeof test === 'function' && test.PrototypeMixin === undefined; } }); enifed('ember-debug/warn', ['exports', 'ember-metal/logger', 'ember-metal/debug', 'ember-debug/handlers'], function (exports, _emberMetalLogger, _emberMetalDebug, _emberDebugHandlers) { 'use strict'; var _slice = Array.prototype.slice; exports.registerHandler = registerHandler; exports.default = warn; function registerHandler(handler) { _emberDebugHandlers.registerHandler('warn', handler); } registerHandler(function logWarning(message, options) { _emberMetalLogger.default.warn('WARNING: ' + message); if ('trace' in _emberMetalLogger.default) { _emberMetalLogger.default.trace(); } }); var missingOptionsDeprecation = 'When calling `Ember.warn` you ' + 'must provide an `options` hash as the third parameter. ' + '`options` should include an `id` property.'; exports.missingOptionsDeprecation = missingOptionsDeprecation; var missingOptionsIdDeprecation = 'When calling `Ember.warn` you must provide `id` in options.'; exports.missingOptionsIdDeprecation = missingOptionsIdDeprecation; /** @module ember @submodule ember-debug */ /** Display a warning with the provided message. * In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build. @method warn @param {String} message A warning to display. @param {Boolean} test An optional boolean. If falsy, the warning will be displayed. @param {Object} options An object that can be used to pass a unique `id` for this warning. The `id` can be used by Ember debugging tools to change the behavior (raise, log, or silence) for that specific warning. The `id` should be namespaced by dots, e.g. "ember-debug.feature-flag-with-features-stripped" @for Ember @public */ function warn(message, test, options) { if (!options) { _emberMetalDebug.deprecate(missingOptionsDeprecation, false, { id: 'ember-debug.warn-options-missing', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options' }); } if (options && !options.id) { _emberMetalDebug.deprecate(missingOptionsIdDeprecation, false, { id: 'ember-debug.warn-id-missing', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options' }); } _emberDebugHandlers.invoke.apply(undefined, ['warn'].concat(_slice.call(arguments))); } }); enifed('ember-testing/adapters/adapter', ['exports', 'ember-runtime/system/object'], function (exports, _emberRuntimeSystemObject) { 'use strict'; function K() { return this; } /** @module ember @submodule ember-testing */ /** The primary purpose of this class is to create hooks that can be implemented by an adapter for various test frameworks. @class Adapter @namespace Ember.Test @public */ var Adapter = _emberRuntimeSystemObject.default.extend({ /** This callback will be called whenever an async operation is about to start. Override this to call your framework's methods that handle async operations. @public @method asyncStart */ asyncStart: K, /** This callback will be called whenever an async operation has completed. @public @method asyncEnd */ asyncEnd: K, /** Override this method with your testing framework's false assertion. This function is called whenever an exception occurs causing the testing promise to fail. QUnit example: ```javascript exception: function(error) { ok(false, error); }; ``` @public @method exception @param {String} error The exception to be raised. */ exception: function (error) { throw error; } }); exports.default = Adapter; }); enifed('ember-testing/adapters/qunit', ['exports', 'ember-testing/adapters/adapter', 'ember-metal/utils'], function (exports, _emberTestingAdaptersAdapter, _emberMetalUtils) { 'use strict'; /** This class implements the methods defined by Ember.Test.Adapter for the QUnit testing framework. @class QUnitAdapter @namespace Ember.Test @extends Ember.Test.Adapter @public */ exports.default = _emberTestingAdaptersAdapter.default.extend({ asyncStart: function () { QUnit.stop(); }, asyncEnd: function () { QUnit.start(); }, exception: function (error) { ok(false, _emberMetalUtils.inspect(error)); } }); }); enifed('ember-testing/helpers', ['exports', 'ember-metal/property_get', 'ember-metal/error', 'ember-metal/run_loop', 'ember-views/system/jquery', 'ember-testing/test', 'ember-runtime/ext/rsvp', 'ember-metal/features'], function (exports, _emberMetalProperty_get, _emberMetalError, _emberMetalRun_loop, _emberViewsSystemJquery, _emberTestingTest, _emberRuntimeExtRsvp, _emberMetalFeatures) { 'use strict'; /** @module ember @submodule ember-testing */ var helper = _emberTestingTest.default.registerHelper; var asyncHelper = _emberTestingTest.default.registerAsyncHelper; var keyboardEventTypes, mouseEventTypes, buildKeyboardEvent, buildMouseEvent, buildBasicEvent, fireEvent, focus; var defaultEventOptions = { canBubble: true, cancelable: true }; keyboardEventTypes = ['keydown', 'keypress', 'keyup']; mouseEventTypes = ['click', 'mousedown', 'mouseup', 'dblclick', 'mousenter', 'mouseleave', 'mousemove', 'mouseout', 'mouseover']; buildKeyboardEvent = function buildKeyboardEvent(type) { var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; var event = undefined; try { event = document.createEvent('KeyEvents'); var eventOpts = _emberViewsSystemJquery.default.extend({}, defaultEventOptions, options); event.initKeyEvent(type, eventOpts.canBubble, eventOpts.cancelable, window, eventOpts.ctrlKey, eventOpts.altKey, eventOpts.shiftKey, eventOpts.metaKey, eventOpts.keyCode, eventOpts.charCode); } catch (e) { event = buildBasicEvent(type, options); } return event; }; buildMouseEvent = function buildMouseEvent(type) { var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; var event = undefined; try { event = document.createEvent('MouseEvents'); var eventOpts = _emberViewsSystemJquery.default.extend({}, defaultEventOptions, options); event.initMouseEvent(type, eventOpts.canBubble, eventOpts.cancelable, window, eventOpts.detail, eventOpts.screenX, eventOpts.screenY, eventOpts.clientX, eventOpts.clientY, eventOpts.ctrlKey, eventOpts.altKey, eventOpts.shiftKey, eventOpts.metaKey, eventOpts.button, eventOpts.relatedTarget); } catch (e) { event = buildBasicEvent(type, options); } return event; }; buildBasicEvent = function buildBasicEvent(type) { var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; var event = document.createEvent('Events'); event.initEvent(type, true, true); _emberViewsSystemJquery.default.extend(event, options); return event; }; fireEvent = function fireEvent(element, type) { var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; if (!element) { return; } var event = undefined; if (keyboardEventTypes.indexOf(type) > -1) { event = buildKeyboardEvent(type, options); } else if (mouseEventTypes.indexOf(type) > -1) { var rect = element.getBoundingClientRect(); var x = rect.left + 1; var y = rect.top + 1; var simulatedCoordinates = { screenX: x + 5, screenY: y + 95, clientX: x, clientY: y }; event = buildMouseEvent(type, _emberViewsSystemJquery.default.extend(simulatedCoordinates, options)); } else { event = buildBasicEvent(type, options); } element.dispatchEvent(event); }; focus = function focus(el) { if (!el) { return; } var $el = _emberViewsSystemJquery.default(el); if ($el.is(':input, [contenteditable=true]')) { var type = $el.prop('type'); if (type !== 'checkbox' && type !== 'radio' && type !== 'hidden') { _emberMetalRun_loop.default(null, function () { // Firefox does not trigger the `focusin` event if the window // does not have focus. If the document doesn't have focus just // use trigger('focusin') instead. if (!document.hasFocus || document.hasFocus()) { el.focus(); } else { $el.trigger('focusin'); } }); } } }; function currentRouteName(app) { var routingService = app.__container__.lookup('service:-routing'); return _emberMetalProperty_get.get(routingService, 'currentRouteName'); } function currentPath(app) { var routingService = app.__container__.lookup('service:-routing'); return _emberMetalProperty_get.get(routingService, 'currentPath'); } function currentURL(app) { var router = app.__container__.lookup('router:main'); return _emberMetalProperty_get.get(router, 'location').getURL(); } function pauseTest() { _emberTestingTest.default.adapter.asyncStart(); return new _emberRuntimeExtRsvp.default.Promise(function () {}, 'TestAdapter paused promise'); } function visit(app, url) { var router = app.__container__.lookup('router:main'); var shouldHandleURL = false; app.boot().then(function () { router.location.setURL(url); if (shouldHandleURL) { _emberMetalRun_loop.default(app.__deprecatedInstance__, 'handleURL', url); } }); if (app._readinessDeferrals > 0) { router['initialURL'] = url; _emberMetalRun_loop.default(app, 'advanceReadiness'); delete router['initialURL']; } else { shouldHandleURL = true; } return app.testHelpers.wait(); } function click(app, selector, context) { var $el = app.testHelpers.findWithAssert(selector, context); var el = $el[0]; _emberMetalRun_loop.default(null, fireEvent, el, 'mousedown'); focus(el); _emberMetalRun_loop.default(null, fireEvent, el, 'mouseup'); _emberMetalRun_loop.default(null, fireEvent, el, 'click'); return app.testHelpers.wait(); } function triggerEvent(app, selector, contextOrType, typeOrOptions, possibleOptions) { var arity = arguments.length; var context, type, options; if (arity === 3) { // context and options are optional, so this is // app, selector, type context = null; type = contextOrType; options = {}; } else if (arity === 4) { // context and options are optional, so this is if (typeof typeOrOptions === 'object') { // either // app, selector, type, options context = null; type = contextOrType; options = typeOrOptions; } else { // or // app, selector, context, type context = contextOrType; type = typeOrOptions; options = {}; } } else { context = contextOrType; type = typeOrOptions; options = possibleOptions; } var $el = app.testHelpers.findWithAssert(selector, context); var el = $el[0]; _emberMetalRun_loop.default(null, fireEvent, el, type, options); return app.testHelpers.wait(); } function keyEvent(app, selector, contextOrType, typeOrKeyCode, keyCode) { var context, type; if (typeof keyCode === 'undefined') { context = null; keyCode = typeOrKeyCode; type = contextOrType; } else { context = contextOrType; type = typeOrKeyCode; } return app.testHelpers.triggerEvent(selector, context, type, { keyCode: keyCode, which: keyCode }); } function fillIn(app, selector, contextOrText, text) { var $el, el, context; if (typeof text === 'undefined') { text = contextOrText; } else { context = contextOrText; } $el = app.testHelpers.findWithAssert(selector, context); el = $el[0]; focus(el); _emberMetalRun_loop.default(function () { $el.val(text); fireEvent(el, 'input'); fireEvent(el, 'change'); }); return app.testHelpers.wait(); } function findWithAssert(app, selector, context) { var $el = app.testHelpers.find(selector, context); if ($el.length === 0) { throw new _emberMetalError.default('Element ' + selector + ' not found.'); } return $el; } function find(app, selector, context) { var $el; context = context || _emberMetalProperty_get.get(app, 'rootElement'); $el = app.$(selector, context); return $el; } function andThen(app, callback) { return app.testHelpers.wait(callback(app)); } function wait(app, value) { return new _emberRuntimeExtRsvp.default.Promise(function (resolve) { var router = app.__container__.lookup('router:main'); // Every 10ms, poll for the async thing to have finished var watcher = setInterval(function () { // 1. If the router is loading, keep polling var routerIsLoading = router.router && !!router.router.activeTransition; if (routerIsLoading) { return; } // 2. If there are pending Ajax requests, keep polling if (_emberTestingTest.default.pendingAjaxRequests) { return; } // 3. If there are scheduled timers or we are inside of a run loop, keep polling if (_emberMetalRun_loop.default.hasScheduledTimers() || _emberMetalRun_loop.default.currentRunLoop) { return; } if (_emberTestingTest.default.waiters && _emberTestingTest.default.waiters.any(function (waiter) { var context = waiter[0]; var callback = waiter[1]; return !callback.call(context); })) { return; } // Stop polling clearInterval(watcher); // Synchronously resolve the promise _emberMetalRun_loop.default(null, resolve, value); }, 10); }); } /** Loads a route, sets up any controllers, and renders any templates associated with the route as though a real user had triggered the route change while using your app. Example: ```javascript visit('posts/index').then(function() { // assert something }); ``` @method visit @param {String} url the name of the route @return {RSVP.Promise} @public */ asyncHelper('visit', visit); /** Clicks an element and triggers any actions triggered by the element's `click` event. Example: ```javascript click('.some-jQuery-selector').then(function() { // assert something }); ``` @method click @param {String} selector jQuery selector for finding element on the DOM @return {RSVP.Promise} @public */ asyncHelper('click', click); /** Simulates a key event, e.g. `keypress`, `keydown`, `keyup` with the desired keyCode Example: ```javascript keyEvent('.some-jQuery-selector', 'keypress', 13).then(function() { // assert something }); ``` @method keyEvent @param {String} selector jQuery selector for finding element on the DOM @param {String} type the type of key event, e.g. `keypress`, `keydown`, `keyup` @param {Number} keyCode the keyCode of the simulated key event @return {RSVP.Promise} @since 1.5.0 @public */ asyncHelper('keyEvent', keyEvent); /** Fills in an input element with some text. Example: ```javascript fillIn('#email', 'you@example.com').then(function() { // assert something }); ``` @method fillIn @param {String} selector jQuery selector finding an input element on the DOM to fill text with @param {String} text text to place inside the input element @return {RSVP.Promise} @public */ asyncHelper('fillIn', fillIn); /** Finds an element in the context of the app's container element. A simple alias for `app.$(selector)`. Example: ```javascript var $el = find('.my-selector'); ``` @method find @param {String} selector jQuery string selector for element lookup @return {Object} jQuery object representing the results of the query @public */ helper('find', find); /** Like `find`, but throws an error if the element selector returns no results. Example: ```javascript var $el = findWithAssert('.doesnt-exist'); // throws error ``` @method findWithAssert @param {String} selector jQuery selector string for finding an element within the DOM @return {Object} jQuery object representing the results of the query @throws {Error} throws error if jQuery object returned has a length of 0 @public */ helper('findWithAssert', findWithAssert); /** Causes the run loop to process any pending events. This is used to ensure that any async operations from other helpers (or your assertions) have been processed. This is most often used as the return value for the helper functions (see 'click', 'fillIn','visit',etc). Example: ```javascript Ember.Test.registerAsyncHelper('loginUser', function(app, username, password) { visit('secured/path/here') .fillIn('#username', username) .fillIn('#password', password) .click('.submit') return app.testHelpers.wait(); }); @method wait @param {Object} value The value to be returned. @return {RSVP.Promise} @public */ asyncHelper('wait', wait); asyncHelper('andThen', andThen); /** Returns the currently active route name. Example: ```javascript function validateRouteName() { equal(currentRouteName(), 'some.path', "correct route was transitioned into."); } visit('/some/path').then(validateRouteName) ``` @method currentRouteName @return {Object} The name of the currently active route. @since 1.5.0 @public */ helper('currentRouteName', currentRouteName); /** Returns the current path. Example: ```javascript function validateURL() { equal(currentPath(), 'some.path.index', "correct path was transitioned into."); } click('#some-link-id').then(validateURL); ``` @method currentPath @return {Object} The currently active path. @since 1.5.0 @public */ helper('currentPath', currentPath); /** Returns the current URL. Example: ```javascript function validateURL() { equal(currentURL(), '/some/path', "correct URL was transitioned into."); } click('#some-link-id').then(validateURL); ``` @method currentURL @return {Object} The currently active URL. @since 1.5.0 @public */ helper('currentURL', currentURL); /** Pauses the current test - this is useful for debugging while testing or for test-driving. It allows you to inspect the state of your application at any point. Example (The test will pause before clicking the button): ```javascript visit('/') return pauseTest(); click('.btn'); ``` @since 1.9.0 @method pauseTest @return {Object} A promise that will never resolve @public */ helper('pauseTest', pauseTest); /** Triggers the given DOM event on the element identified by the provided selector. Example: ```javascript triggerEvent('#some-elem-id', 'blur'); ``` This is actually used internally by the `keyEvent` helper like so: ```javascript triggerEvent('#some-elem-id', 'keypress', { keyCode: 13 }); ``` @method triggerEvent @param {String} selector jQuery selector for finding element on the DOM @param {String} [context] jQuery selector that will limit the selector argument to find only within the context's children @param {String} type The event type to be triggered. @param {Object} [options] The options to be passed to jQuery.Event. @return {RSVP.Promise} @since 1.5.0 @public */ asyncHelper('triggerEvent', triggerEvent); }); // Firefox does not trigger the `focusin` event if the window // does not have focus. If the document doesn't have focus just // use trigger('focusin') instead. enifed('ember-testing/index', ['exports', 'ember-metal/core', 'ember-testing/initializers', 'ember-testing/support', 'ember-testing/setup_for_testing', 'ember-testing/test', 'ember-testing/adapters/adapter', 'ember-testing/adapters/qunit', 'ember-testing/helpers'], function (exports, _emberMetalCore, _emberTestingInitializers, _emberTestingSupport, _emberTestingSetup_for_testing, _emberTestingTest, _emberTestingAdaptersAdapter, _emberTestingAdaptersQunit, _emberTestingHelpers) { 'use strict'; // adds helpers to helpers object in Test /** @module ember @submodule ember-testing */ _emberMetalCore.default.Test = _emberTestingTest.default; _emberMetalCore.default.Test.Adapter = _emberTestingAdaptersAdapter.default; _emberMetalCore.default.Test.QUnitAdapter = _emberTestingAdaptersQunit.default; _emberMetalCore.default.setupForTesting = _emberTestingSetup_for_testing.default; }); // to setup initializer // to handle various edge cases enifed('ember-testing/initializers', ['exports', 'ember-runtime/system/lazy_load'], function (exports, _emberRuntimeSystemLazy_load) { 'use strict'; var name = 'deferReadiness in `testing` mode'; _emberRuntimeSystemLazy_load.onLoad('Ember.Application', function (Application) { if (!Application.initializers[name]) { Application.initializer({ name: name, initialize: function (application) { if (application.testing) { application.deferReadiness(); } } }); } }); }); enifed('ember-testing/setup_for_testing', ['exports', 'ember-metal/core', 'ember-testing/adapters/qunit', 'ember-views/system/jquery'], function (exports, _emberMetalCore, _emberTestingAdaptersQunit, _emberViewsSystemJquery) { 'use strict'; exports.default = setupForTesting; var Test, requests; function incrementAjaxPendingRequests(_, xhr) { requests.push(xhr); Test.pendingAjaxRequests = requests.length; } function decrementAjaxPendingRequests(_, xhr) { for (var i = 0; i < requests.length; i++) { if (xhr === requests[i]) { requests.splice(i, 1); } } Test.pendingAjaxRequests = requests.length; } /** Sets Ember up for testing. This is useful to perform basic setup steps in order to unit test. Use `App.setupForTesting` to perform integration tests (full application testing). @method setupForTesting @namespace Ember @since 1.5.0 @private */ function setupForTesting() { if (!Test) { Test = requireModule('ember-testing/test')['default']; } _emberMetalCore.default.testing = true; // if adapter is not manually set default to QUnit if (!Test.adapter) { Test.adapter = _emberTestingAdaptersQunit.default.create(); } requests = []; Test.pendingAjaxRequests = requests.length; _emberViewsSystemJquery.default(document).off('ajaxSend', incrementAjaxPendingRequests); _emberViewsSystemJquery.default(document).off('ajaxComplete', decrementAjaxPendingRequests); _emberViewsSystemJquery.default(document).on('ajaxSend', incrementAjaxPendingRequests); _emberViewsSystemJquery.default(document).on('ajaxComplete', decrementAjaxPendingRequests); } }); // import Test from "ember-testing/test"; // ES6TODO: fix when cycles are supported enifed('ember-testing/support', ['exports', 'ember-metal/debug', 'ember-views/system/jquery', 'ember-metal/environment'], function (exports, _emberMetalDebug, _emberViewsSystemJquery, _emberMetalEnvironment) { 'use strict'; /** @module ember @submodule ember-testing */ var $ = _emberViewsSystemJquery.default; /** This method creates a checkbox and triggers the click event to fire the passed in handler. It is used to correct for a bug in older versions of jQuery (e.g 1.8.3). @private @method testCheckboxClick */ function testCheckboxClick(handler) { $('').css({ position: 'absolute', left: '-1000px', top: '-1000px' }).appendTo('body').on('click', handler).trigger('click').remove(); } if (_emberMetalEnvironment.default.hasDOM) { $(function () { /* Determine whether a checkbox checked using jQuery's "click" method will have the correct value for its checked property. If we determine that the current jQuery version exhibits this behavior, patch it to work correctly as in the commit for the actual fix: https://github.com/jquery/jquery/commit/1fb2f92. */ testCheckboxClick(function () { if (!this.checked && !$.event.special.click) { $.event.special.click = { // For checkbox, fire native event so checked state will be right trigger: function () { if ($.nodeName(this, 'input') && this.type === 'checkbox' && this.click) { this.click(); return false; } } }; } }); // Try again to verify that the patch took effect or blow up. testCheckboxClick(function () { _emberMetalDebug.warn('clicked checkboxes should be checked! the jQuery patch didn\'t work', this.checked, { id: 'ember-testing.test-checkbox-click' }); }); }); } }); enifed('ember-testing/test', ['exports', 'ember-metal/run_loop', 'ember-runtime/ext/rsvp', 'ember-testing/setup_for_testing', 'ember-application/system/application', 'ember-runtime/system/native_array'], function (exports, _emberMetalRun_loop, _emberRuntimeExtRsvp, _emberTestingSetup_for_testing, _emberApplicationSystemApplication, _emberRuntimeSystemNative_array) { 'use strict'; /** @module ember @submodule ember-testing */ var helpers = {}; var injectHelpersCallbacks = []; /** This is a container for an assortment of testing related functionality: * Choose your default test adapter (for your framework of choice). * Register/Unregister additional test helpers. * Setup callbacks to be fired when the test helpers are injected into your application. @class Test @namespace Ember @public */ var Test = { /** Hash containing all known test helpers. @property _helpers @private @since 1.7.0 */ _helpers: helpers, /** `registerHelper` is used to register a test helper that will be injected when `App.injectTestHelpers` is called. The helper method will always be called with the current Application as the first parameter. For example: ```javascript Ember.Test.registerHelper('boot', function(app) { Ember.run(app, app.advanceReadiness); }); ``` This helper can later be called without arguments because it will be called with `app` as the first parameter. ```javascript App = Ember.Application.create(); App.injectTestHelpers(); boot(); ``` @public @method registerHelper @param {String} name The name of the helper method to add. @param {Function} helperMethod @param options {Object} */ registerHelper: function (name, helperMethod) { helpers[name] = { method: helperMethod, meta: { wait: false } }; }, /** `registerAsyncHelper` is used to register an async test helper that will be injected when `App.injectTestHelpers` is called. The helper method will always be called with the current Application as the first parameter. For example: ```javascript Ember.Test.registerAsyncHelper('boot', function(app) { Ember.run(app, app.advanceReadiness); }); ``` The advantage of an async helper is that it will not run until the last async helper has completed. All async helpers after it will wait for it complete before running. For example: ```javascript Ember.Test.registerAsyncHelper('deletePost', function(app, postId) { click('.delete-' + postId); }); // ... in your test visit('/post/2'); deletePost(2); visit('/post/3'); deletePost(3); ``` @public @method registerAsyncHelper @param {String} name The name of the helper method to add. @param {Function} helperMethod @since 1.2.0 */ registerAsyncHelper: function (name, helperMethod) { helpers[name] = { method: helperMethod, meta: { wait: true } }; }, /** Remove a previously added helper method. Example: ```javascript Ember.Test.unregisterHelper('wait'); ``` @public @method unregisterHelper @param {String} name The helper to remove. */ unregisterHelper: function (name) { delete helpers[name]; delete Test.Promise.prototype[name]; }, /** Used to register callbacks to be fired whenever `App.injectTestHelpers` is called. The callback will receive the current application as an argument. Example: ```javascript Ember.Test.onInjectHelpers(function() { Ember.$(document).ajaxSend(function() { Test.pendingAjaxRequests++; }); Ember.$(document).ajaxComplete(function() { Test.pendingAjaxRequests--; }); }); ``` @public @method onInjectHelpers @param {Function} callback The function to be called. */ onInjectHelpers: function (callback) { injectHelpersCallbacks.push(callback); }, /** This returns a thenable tailored for testing. It catches failed `onSuccess` callbacks and invokes the `Ember.Test.adapter.exception` callback in the last chained then. This method should be returned by async helpers such as `wait`. @public @method promise @param {Function} resolver The function used to resolve the promise. @param {String} label An optional string for identifying the promise. */ promise: function (resolver, label) { var fullLabel = 'Ember.Test.promise: ' + (label || ''); return new Test.Promise(resolver, fullLabel); }, /** Used to allow ember-testing to communicate with a specific testing framework. You can manually set it before calling `App.setupForTesting()`. Example: ```javascript Ember.Test.adapter = MyCustomAdapter.create() ``` If you do not set it, ember-testing will default to `Ember.Test.QUnitAdapter`. @public @property adapter @type {Class} The adapter to be used. @default Ember.Test.QUnitAdapter */ adapter: null, /** Replacement for `Ember.RSVP.resolve` The only difference is this uses an instance of `Ember.Test.Promise` @public @method resolve @param {Mixed} The value to resolve @since 1.2.0 */ resolve: function (val) { return Test.promise(function (resolve) { return resolve(val); }); }, /** This allows ember-testing to play nicely with other asynchronous events, such as an application that is waiting for a CSS3 transition or an IndexDB transaction. For example: ```javascript Ember.Test.registerWaiter(function() { return myPendingTransactions() == 0; }); ``` The `context` argument allows you to optionally specify the `this` with which your callback will be invoked. For example: ```javascript Ember.Test.registerWaiter(MyDB, MyDB.hasPendingTransactions); ``` @public @method registerWaiter @param {Object} context (optional) @param {Function} callback @since 1.2.0 */ registerWaiter: function (context, callback) { if (arguments.length === 1) { callback = context; context = null; } if (!this.waiters) { this.waiters = _emberRuntimeSystemNative_array.A(); } this.waiters.push([context, callback]); }, /** `unregisterWaiter` is used to unregister a callback that was registered with `registerWaiter`. @public @method unregisterWaiter @param {Object} context (optional) @param {Function} callback @since 1.2.0 */ unregisterWaiter: function (context, callback) { if (!this.waiters) { return; } if (arguments.length === 1) { callback = context; context = null; } this.waiters = _emberRuntimeSystemNative_array.A(this.waiters.filter(function (elt) { return !(elt[0] === context && elt[1] === callback); })); } }; function helper(app, name) { var fn = helpers[name].method; var meta = helpers[name].meta; return function () { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var lastPromise; args.unshift(app); // some helpers are not async and // need to return a value immediately. // example: `find` if (!meta.wait) { return fn.apply(app, args); } lastPromise = run(function () { return Test.resolve(Test.lastPromise); }); // wait for last helper's promise to resolve and then // execute. To be safe, we need to tell the adapter we're going // asynchronous here, because fn may not be invoked before we // return. Test.adapter.asyncStart(); return lastPromise.then(function () { return fn.apply(app, args); }).finally(function () { Test.adapter.asyncEnd(); }); }; } function run(fn) { if (!_emberMetalRun_loop.default.currentRunLoop) { return _emberMetalRun_loop.default(fn); } else { return fn(); } } _emberApplicationSystemApplication.default.reopen({ /** This property contains the testing helpers for the current application. These are created once you call `injectTestHelpers` on your `Ember.Application` instance. The included helpers are also available on the `window` object by default, but can be used from this object on the individual application also. @property testHelpers @type {Object} @default {} @public */ testHelpers: {}, /** This property will contain the original methods that were registered on the `helperContainer` before `injectTestHelpers` is called. When `removeTestHelpers` is called, these methods are restored to the `helperContainer`. @property originalMethods @type {Object} @default {} @private @since 1.3.0 */ originalMethods: {}, /** This property indicates whether or not this application is currently in testing mode. This is set when `setupForTesting` is called on the current application. @property testing @type {Boolean} @default false @since 1.3.0 @public */ testing: false, /** This hook defers the readiness of the application, so that you can start the app when your tests are ready to run. It also sets the router's location to 'none', so that the window's location will not be modified (preventing both accidental leaking of state between tests and interference with your testing framework). Example: ``` App.setupForTesting(); ``` @method setupForTesting @public */ setupForTesting: function () { _emberTestingSetup_for_testing.default(); this.testing = true; this.Router.reopen({ location: 'none' }); }, /** This will be used as the container to inject the test helpers into. By default the helpers are injected into `window`. @property helperContainer @type {Object} The object to be used for test helpers. @default window @since 1.2.0 @private */ helperContainer: null, /** This injects the test helpers into the `helperContainer` object. If an object is provided it will be used as the helperContainer. If `helperContainer` is not set it will default to `window`. If a function of the same name has already been defined it will be cached (so that it can be reset if the helper is removed with `unregisterHelper` or `removeTestHelpers`). Any callbacks registered with `onInjectHelpers` will be called once the helpers have been injected. Example: ``` App.injectTestHelpers(); ``` @method injectTestHelpers @public */ injectTestHelpers: function (helperContainer) { if (helperContainer) { this.helperContainer = helperContainer; } else { this.helperContainer = window; } this.reopen({ willDestroy: function () { this._super.apply(this, arguments); this.removeTestHelpers(); } }); this.testHelpers = {}; for (var name in helpers) { this.originalMethods[name] = this.helperContainer[name]; this.testHelpers[name] = this.helperContainer[name] = helper(this, name); protoWrap(Test.Promise.prototype, name, helper(this, name), helpers[name].meta.wait); } for (var i = 0, l = injectHelpersCallbacks.length; i < l; i++) { injectHelpersCallbacks[i](this); } }, /** This removes all helpers that have been registered, and resets and functions that were overridden by the helpers. Example: ```javascript App.removeTestHelpers(); ``` @public @method removeTestHelpers */ removeTestHelpers: function () { if (!this.helperContainer) { return; } for (var name in helpers) { this.helperContainer[name] = this.originalMethods[name]; delete Test.Promise.prototype[name]; delete this.testHelpers[name]; delete this.originalMethods[name]; } } }); // This method is no longer needed // But still here for backwards compatibility // of helper chaining function protoWrap(proto, name, callback, isAsync) { proto[name] = function () { for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } if (isAsync) { return callback.apply(this, args); } else { return this.then(function () { return callback.apply(this, args); }); } }; } Test.Promise = function () { _emberRuntimeExtRsvp.default.Promise.apply(this, arguments); Test.lastPromise = this; }; Test.Promise.prototype = Object.create(_emberRuntimeExtRsvp.default.Promise.prototype); Test.Promise.prototype.constructor = Test.Promise; Test.Promise.resolve = Test.resolve; // Patch `then` to isolate async methods // specifically `Ember.Test.lastPromise` var originalThen = _emberRuntimeExtRsvp.default.Promise.prototype.then; Test.Promise.prototype.then = function (onSuccess, onFailure) { return originalThen.call(this, function (val) { return isolate(onSuccess, val); }, onFailure); }; // This method isolates nested async methods // so that they don't conflict with other last promises. // // 1. Set `Ember.Test.lastPromise` to null // 2. Invoke method // 3. Return the last promise created during method function isolate(fn, val) { var value, lastPromise; // Reset lastPromise for nested helpers Test.lastPromise = null; value = fn(val); lastPromise = Test.lastPromise; Test.lastPromise = null; // If the method returned a promise // return that promise. If not, // return the last async helper's promise if (value && value instanceof Test.Promise || !lastPromise) { return value; } else { return run(function () { return Test.resolve(lastPromise).then(function () { return value; }); }); } } exports.default = Test; }); requireModule("ember-testing"); }());