(function() { /*! * @overview Ember - JavaScript Application Framework * @copyright Copyright 2011-2017 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.14.0-beta.1 */ var enifed, requireModule, Ember; var mainContext = this; // Used in ember-environment/lib/global.js (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; }; requireModule = function(name) { return internalRequire(name, null); }; // setup `require` module requireModule['default'] = requireModule; requireModule.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 reified = new Array(deps.length); for (var i = 0; i < deps.length; i++) { if (deps[i] === 'exports') { reified[i] = exports; } else if (deps[i] === 'require') { reified[i] = requireModule; } else { reified[i] = internalRequire(deps[i], name); } } callback.apply(this, reified); return exports; } requireModule._eak_seen = registry; Ember.__loader = { define: enifed, require: requireModule, registry: registry }; } else { enifed = Ember.__loader.define; requireModule = Ember.__loader.require; } })(); enifed('container/tests/container_test', ['ember-utils', 'ember-environment', 'ember-metal', 'container', 'internal-test-helpers'], function (_emberUtils, _emberEnvironment, _emberMetal, _container, _internalTestHelpers) { 'use strict'; var originalModelInjections = void 0; QUnit.module('Container', { setup: function () { originalModelInjections = _emberEnvironment.ENV.MODEL_FACTORY_INJECTIONS; }, teardown: function () { _emberEnvironment.ENV.MODEL_FACTORY_INJECTIONS = originalModelInjections; } }); function lookupFactory(name, container, options) { var factory = void 0; expectDeprecation(function () { factory = container.lookupFactory(name, options); }, 'Using "_lookupFactory" is deprecated. Please use container.factoryFor instead.'); return factory; } QUnit.test('A registered factory returns the same instance each time', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); var postController = container.lookup('controller:post'); ok(postController instanceof PostController, 'The lookup is an instance of the factory'); equal(postController, container.lookup('controller:post')); }); QUnit.test('A registered factory is returned from lookupFactory', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); var PostControllerFactory = lookupFactory('controller:post', container); ok(PostControllerFactory, 'factory is returned'); ok(PostControllerFactory.create() instanceof PostController, 'The return of factory.create is an instance of PostController'); }); QUnit.test('A registered factory is returned from lookupFactory is the same factory each time', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); var Post1 = lookupFactory('controller:post', container); var Post2 = lookupFactory('controller:post', container); deepEqual(Post1, Post2, 'The return of lookupFactory is always the same'); }); QUnit.test('A factory returned from lookupFactory has a debugkey', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); var PostFactory = lookupFactory('controller:post', container); equal(PostFactory._debugContainerKey, 'controller:post', 'factory instance receives _debugContainerKey'); }); QUnit.test('uses create time injections if factory has no extend', function () { var registry = new _container.Registry(); var container = registry.container(); var AppleController = (0, _internalTestHelpers.factory)(); var PostController = (0, _internalTestHelpers.factory)(); PostController.extend = undefined; // remove extend registry.register('controller:apple', AppleController); registry.register('controller:post', PostController); registry.injection('controller:post', 'apple', 'controller:apple'); var postController = container.lookup('controller:post'); ok(postController.apple instanceof AppleController, 'instance receives an apple of instance AppleController'); }); QUnit.test('The descendants of a factory returned from lookupFactory have a container and debugkey', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); var instance = void 0; registry.register('controller:post', PostController); instance = lookupFactory('controller:post', container).create(); equal(instance._debugContainerKey, 'controller:post', 'factory instance receives _debugContainerKey'); ok(instance instanceof PostController, 'factory instance is instance of factory'); }); QUnit.test('A registered factory returns a fresh instance if singleton: false is passed as an option', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); var postController1 = container.lookup('controller:post'); var postController2 = container.lookup('controller:post', { singleton: false }); var postController3 = container.lookup('controller:post', { singleton: false }); var postController4 = container.lookup('controller:post'); equal(postController1.toString(), postController4.toString(), 'Singleton factories looked up normally return the same value'); notEqual(postController1.toString(), postController2.toString(), 'Singleton factories are not equal to factories looked up with singleton: false'); notEqual(postController2.toString(), postController3.toString(), 'Two factories looked up with singleton: false are not equal'); notEqual(postController3.toString(), postController4.toString(), 'A singleton factory looked up after a factory called with singleton: false is not equal'); ok(postController1 instanceof PostController, 'All instances are instances of the registered factory'); ok(postController2 instanceof PostController, 'All instances are instances of the registered factory'); ok(postController3 instanceof PostController, 'All instances are instances of the registered factory'); ok(postController4 instanceof PostController, 'All instances are instances of the registered factory'); }); QUnit.test('A factory type with a registered injection\'s instances receive that injection', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); var Store = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); registry.register('store:main', Store); registry.typeInjection('controller', 'store', 'store:main'); var postController = container.lookup('controller:post'); var store = container.lookup('store:main'); equal(postController.store, store); }); QUnit.test('An individual factory with a registered injection receives the injection', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); var Store = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); registry.register('store:main', Store); registry.injection('controller:post', 'store', 'store:main'); var postController = container.lookup('controller:post'); var store = container.lookup('store:main'); equal(postController.store, store, 'has the correct store injected'); }); QUnit.test('A factory with both type and individual injections', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); var Store = (0, _internalTestHelpers.factory)(); var Router = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); registry.register('store:main', Store); registry.register('router:main', Router); registry.injection('controller:post', 'store', 'store:main'); registry.typeInjection('controller', 'router', 'router:main'); var postController = container.lookup('controller:post'); var store = container.lookup('store:main'); var router = container.lookup('router:main'); equal(postController.store, store); equal(postController.router, router); }); QUnit.test('A factory with both type and individual factoryInjections', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); var Store = (0, _internalTestHelpers.factory)(); var Router = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); registry.register('store:main', Store); registry.register('router:main', Router); registry.factoryInjection('controller:post', 'store', 'store:main'); registry.factoryTypeInjection('controller', 'router', 'router:main'); var PostControllerFactory = lookupFactory('controller:post', container); var store = container.lookup('store:main'); var router = container.lookup('router:main'); equal(PostControllerFactory.store, store, 'PostControllerFactory has the instance of store'); equal(PostControllerFactory.router, router, 'PostControllerFactory has the route instance'); }); QUnit.test('A non-singleton instance is never cached', function () { var registry = new _container.Registry(); var container = registry.container(); var PostView = (0, _internalTestHelpers.factory)(); registry.register('view:post', PostView, { singleton: false }); var postView1 = container.lookup('view:post'); var postView2 = container.lookup('view:post'); ok(postView1 !== postView2, 'Non-singletons are not cached'); }); QUnit.test('A non-instantiated property is not instantiated', function () { var registry = new _container.Registry(); var container = registry.container(); var template = function () {}; registry.register('template:foo', template, { instantiate: false }); equal(container.lookup('template:foo'), template); }); QUnit.test('A failed lookup returns undefined', function () { var registry = new _container.Registry(); var container = registry.container(); equal(container.lookup('doesnot:exist'), undefined); }); QUnit.test('An invalid factory throws an error', function () { var registry = new _container.Registry(); var container = registry.container(); registry.register('controller:foo', {}); throws(function () { container.lookup('controller:foo'); }, /Failed to create an instance of \'controller:foo\'/); }); QUnit.test('Injecting a failed lookup raises an error', function () { _emberEnvironment.ENV.MODEL_FACTORY_INJECTIONS = true; var registry = new _container.Registry(); var container = registry.container(); var fooInstance = {}; var fooFactory = {}; registry.register('model:foo', { create: function () { return fooInstance; }, extend: function () { return fooFactory; } }); registry.injection('model:foo', 'store', 'store:main'); throws(function () { container.lookup('model:foo'); }); }); QUnit.test('Injecting a falsy value does not raise an error', function () { var registry = new _container.Registry(); var container = registry.container(); var ApplicationController = (0, _internalTestHelpers.factory)(); registry.register('controller:application', ApplicationController); registry.register('user:current', null, { instantiate: false }); registry.injection('controller:application', 'currentUser', 'user:current'); strictEqual(container.lookup('controller:application').currentUser, null); }); QUnit.test('The container returns same value each time even if the value is falsy', function () { var registry = new _container.Registry(); var container = registry.container(); registry.register('falsy:value', null, { instantiate: false }); strictEqual(container.lookup('falsy:value'), container.lookup('falsy:value')); }); QUnit.test('Destroying the container destroys any cached singletons', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); var PostView = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); registry.register('view:post', PostView, { singleton: false }); registry.register('template:post', function () {}, { instantiate: false }); registry.injection('controller:post', 'postView', 'view:post'); var postController = container.lookup('controller:post'); var postView = postController.postView; ok(postView instanceof PostView, 'The non-singleton was injected'); container.destroy(); ok(postController.isDestroyed, 'Singletons are destroyed'); ok(!postView.isDestroyed, 'Non-singletons are not destroyed'); }); QUnit.test('The container can use a registry hook to resolve factories lazily', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); registry.resolver = { resolve: function (fullName) { if (fullName === 'controller:post') { return PostController; } } }; var postController = container.lookup('controller:post'); ok(postController instanceof PostController, 'The correct factory was provided'); }); QUnit.test('The container normalizes names before resolving', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); registry.normalizeFullName = function () { return 'controller:post'; }; registry.register('controller:post', PostController); var postController = container.lookup('controller:normalized'); ok(postController instanceof PostController, 'Normalizes the name before resolving'); }); QUnit.test('The container normalizes names when looking factory up', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); registry.normalizeFullName = function () { return 'controller:post'; }; registry.register('controller:post', PostController); var fact = lookupFactory('controller:normalized', container); equal(fact.toString() === PostController.extend().toString(), true, 'Normalizes the name when looking factory up'); }); QUnit.test('Options can be registered that should be applied to a given factory', function () { var registry = new _container.Registry(); var container = registry.container(); var PostView = (0, _internalTestHelpers.factory)(); registry.resolver = { resolve: function (fullName) { if (fullName === 'view:post') { return PostView; } } }; registry.options('view:post', { instantiate: true, singleton: false }); var postView1 = container.lookup('view:post'); var postView2 = container.lookup('view:post'); ok(postView1 instanceof PostView, 'The correct factory was provided'); ok(postView2 instanceof PostView, 'The correct factory was provided'); ok(postView1 !== postView2, 'The two lookups are different'); }); QUnit.test('Options can be registered that should be applied to all factories for a given type', function () { var registry = new _container.Registry(); var container = registry.container(); var PostView = (0, _internalTestHelpers.factory)(); registry.resolver = { resolve: function (fullName) { if (fullName === 'view:post') { return PostView; } } }; registry.optionsForType('view', { singleton: false }); var postView1 = container.lookup('view:post'); var postView2 = container.lookup('view:post'); ok(postView1 instanceof PostView, 'The correct factory was provided'); ok(postView2 instanceof PostView, 'The correct factory was provided'); ok(postView1 !== postView2, 'The two lookups are different'); }); QUnit.test('An injected non-singleton instance is never cached', function () { var registry = new _container.Registry(); var container = registry.container(); var PostView = (0, _internalTestHelpers.factory)(); var PostViewHelper = (0, _internalTestHelpers.factory)(); registry.register('view:post', PostView, { singleton: false }); registry.register('view_helper:post', PostViewHelper, { singleton: false }); registry.injection('view:post', 'viewHelper', 'view_helper:post'); var postView1 = container.lookup('view:post'); var postView2 = container.lookup('view:post'); ok(postView1.viewHelper !== postView2.viewHelper, 'Injected non-singletons are not cached'); }); QUnit.test('Factory resolves are cached', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); var resolveWasCalled = []; registry.resolve = function (fullName) { resolveWasCalled.push(fullName); return PostController; }; deepEqual(resolveWasCalled, []); lookupFactory('controller:post', container); deepEqual(resolveWasCalled, ['controller:post']); lookupFactory('controller:post', container); deepEqual(resolveWasCalled, ['controller:post']); }); QUnit.test('factory for non extendables (MODEL) resolves are cached', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); var resolveWasCalled = []; registry.resolve = function (fullName) { resolveWasCalled.push(fullName); return PostController; }; deepEqual(resolveWasCalled, []); lookupFactory('model:post', container); deepEqual(resolveWasCalled, ['model:post']); lookupFactory('model:post', container); deepEqual(resolveWasCalled, ['model:post']); }); QUnit.test('factory for non extendables resolves are cached', function () { var registry = new _container.Registry(); var container = registry.container(); var PostController = {}; var resolveWasCalled = []; registry.resolve = function (fullName) { resolveWasCalled.push(fullName); return PostController; }; deepEqual(resolveWasCalled, []); lookupFactory('foo:post', container); deepEqual(resolveWasCalled, ['foo:post']); lookupFactory('foo:post', container); deepEqual(resolveWasCalled, ['foo:post']); }); QUnit.test('The `_onLookup` hook is called on factories when looked up the first time', function () { expect(4); // 2 are from expectDeprecation in `lookupFactory` var registry = new _container.Registry(); var container = registry.container(); var Apple = (0, _internalTestHelpers.factory)(); Apple.reopenClass({ _onLookup: function (fullName) { equal(fullName, 'apple:main', 'calls lazy injection method with the lookup full name'); equal(this, Apple, 'calls lazy injection method in the factory context'); } }); registry.register('apple:main', Apple); lookupFactory('apple:main', container); lookupFactory('apple:main', container); }); QUnit.test('A factory\'s lazy injections are validated when first instantiated', function () { var registry = new _container.Registry(); var container = registry.container(); var Apple = (0, _internalTestHelpers.factory)(); var Orange = (0, _internalTestHelpers.factory)(); Apple.reopenClass({ _lazyInjections: function () { return ['orange:main', 'banana:main']; } }); registry.register('apple:main', Apple); registry.register('orange:main', Orange); throws(function () { container.lookup('apple:main'); }, /Attempting to inject an unknown injection: 'banana:main'/); }); QUnit.test('Lazy injection validations are cached', function () { expect(1); var registry = new _container.Registry(); var container = registry.container(); var Apple = (0, _internalTestHelpers.factory)(); var Orange = (0, _internalTestHelpers.factory)(); Apple.reopenClass({ _lazyInjections: function () { ok(true, 'should call lazy injection method'); return ['orange:main']; } }); registry.register('apple:main', Apple); registry.register('orange:main', Orange); container.lookup('apple:main'); container.lookup('apple:main'); }); QUnit.test('An object with its owner pre-set should be returned from ownerInjection', function () { var owner = {}; var registry = new _container.Registry(); var container = registry.container({ owner: owner }); var result = container.ownerInjection(); equal(result[_emberUtils.OWNER], owner, 'owner is properly included'); }); QUnit.test('A deprecated `container` property is appended to every object instantiated from an extendable factory', function () { var owner = {}; var registry = new _container.Registry(); var container = owner.__container__ = registry.container({ owner: owner }); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); var postController = container.lookup('controller:post'); expectDeprecation(function () { (0, _emberMetal.get)(postController, 'container'); }, 'Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.'); expectDeprecation(function () { var c = postController.container; strictEqual(c, container); }, 'Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.'); }); QUnit.test('An extendable factory can provide `container` upon create, with a deprecation', function (assert) { var registry = new _container.Registry(); var container = registry.container(); registry.register('controller:post', (0, _internalTestHelpers.factory)()); var PostController = lookupFactory('controller:post', container); var postController = void 0; expectDeprecation(function () { postController = PostController.create({ container: 'foo' }); }, /Providing the \`container\` property to .+ is deprecated. Please use \`Ember.setOwner\` or \`owner.ownerInjection\(\)\` instead to provide an owner to the instance being created/); expectDeprecation(function () { var c = postController.container; assert.equal(c, 'foo', 'the `container` provided to `.create`was used'); }, 'Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.'); }); QUnit.test('lookupFactory passes options through to expandlocallookup', function (assert) { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); registry.expandLocalLookup = function (fullName, options) { assert.ok(true, 'expandLocalLookup was called'); assert.equal(fullName, 'foo:bar'); assert.deepEqual(options, { source: 'baz:qux' }); return 'controller:post'; }; var PostControllerFactory = lookupFactory('foo:bar', container, { source: 'baz:qux' }); assert.ok(PostControllerFactory.create() instanceof PostController, 'The return of factory.create is an instance of PostController'); }); QUnit.test('lookup passes options through to expandlocallookup', function (assert) { var registry = new _container.Registry(); var container = registry.container(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); registry.expandLocalLookup = function (fullName, options) { assert.ok(true, 'expandLocalLookup was called'); assert.equal(fullName, 'foo:bar'); assert.deepEqual(options, { source: 'baz:qux' }); return 'controller:post'; }; var PostControllerLookupResult = container.lookup('foo:bar', { source: 'baz:qux' }); assert.ok(PostControllerLookupResult instanceof PostController); }); QUnit.test('#factoryFor class is registered class', function (assert) { var registry = new _container.Registry(); var container = registry.container(); var Component = (0, _internalTestHelpers.factory)(); registry.register('component:foo-bar', Component); var factoryManager = container.factoryFor('component:foo-bar'); assert.deepEqual(factoryManager.class, Component, 'No double extend'); }); QUnit.test('#factoryFor must supply a fullname', function (assert) { var registry = new _container.Registry(); var container = registry.container(); assert.throws(function () { container.factoryFor('chad-bar'); }, /Invalid Fullname, expected: 'type:name' got: chad-bar/); }); QUnit.test('#factoryFor returns a factory manager', function (assert) { var registry = new _container.Registry(); var container = registry.container(); var Component = (0, _internalTestHelpers.factory)(); registry.register('component:foo-bar', Component); var factoryManager = container.factoryFor('component:foo-bar'); assert.ok(factoryManager.create); assert.ok(factoryManager.class); }); QUnit.test('#factoryFor returns a cached factory manager for the same type', function (assert) { var registry = new _container.Registry(); var container = registry.container(); var Component = (0, _internalTestHelpers.factory)(); registry.register('component:foo-bar', Component); registry.register('component:baz-bar', Component); var factoryManager1 = container.factoryFor('component:foo-bar'); var factoryManager2 = container.factoryFor('component:foo-bar'); var factoryManager3 = container.factoryFor('component:baz-bar'); assert.equal(factoryManager1, factoryManager2, 'cache hit'); assert.notEqual(factoryManager1, factoryManager3, 'cache miss'); }); QUnit.test('#factoryFor class returns the factory function', function (assert) { var registry = new _container.Registry(); var container = registry.container(); var Component = (0, _internalTestHelpers.factory)(); registry.register('component:foo-bar', Component); var factoryManager = container.factoryFor('component:foo-bar'); assert.deepEqual(factoryManager.class, Component, 'No double extend'); }); QUnit.test('#factoryFor instance have a common parent', function (assert) { var registry = new _container.Registry(); var container = registry.container(); var Component = (0, _internalTestHelpers.factory)(); registry.register('component:foo-bar', Component); var factoryManager1 = container.factoryFor('component:foo-bar'); var factoryManager2 = container.factoryFor('component:foo-bar'); var instance1 = factoryManager1.create({ foo: 'foo' }); var instance2 = factoryManager2.create({ bar: 'bar' }); assert.deepEqual(instance1.constructor, instance2.constructor); }); QUnit.test('#factoryFor created instances come with instance injections', function (assert) { var registry = new _container.Registry(); var container = registry.container(); var Component = (0, _internalTestHelpers.factory)(); var Ajax = (0, _internalTestHelpers.factory)(); registry.register('component:foo-bar', Component); registry.register('util:ajax', Ajax); registry.injection('component:foo-bar', 'ajax', 'util:ajax'); var componentFactory = container.factoryFor('component:foo-bar'); var component = componentFactory.create(); assert.ok(component.ajax); assert.ok(component.ajax instanceof Ajax); }); QUnit.test('#factoryFor options passed to create clobber injections', function (assert) { var registry = new _container.Registry(); var container = registry.container(); var Component = (0, _internalTestHelpers.factory)(); var Ajax = (0, _internalTestHelpers.factory)(); registry.register('component:foo-bar', Component); registry.register('util:ajax', Ajax); registry.injection('component:foo-bar', 'ajax', 'util:ajax'); var componentFactory = container.factoryFor('component:foo-bar'); var instrance = componentFactory.create({ ajax: 'fetch' }); assert.equal(instrance.ajax, 'fetch'); }); QUnit.test('#factoryFor does not add properties to the object being instantiated when _initFactory is present', function (assert) { var registry = new _container.Registry(); var container = registry.container(); var Component = function () { function Component() {} Component._initFactory = function (_factory) {}; Component.create = function (options) { var instance = new this(); (0, _emberUtils.assign)(instance, options); return instance; }; return Component; }(); registry.register('component:foo-bar', Component); var componentFactory = container.factoryFor('component:foo-bar'); var instance = componentFactory.create(); // note: _guid and isDestroyed are being set in the `factory` constructor // not via registry/container shenanigans assert.deepEqual(Object.keys(instance), []); }); // this is skipped until templates and the glimmer environment do not require `OWNER` to be // passed in as constructor args QUnit.skip('#factoryFor does not add properties to the object being instantiated', function (assert) { var registry = new _container.Registry(); var container = registry.container(); var Component = function () { function Component() {} Component.create = function (options) { var instance = new this(); (0, _emberUtils.assign)(instance, options); return instance; }; return Component; }(); registry.register('component:foo-bar', Component); var componentFactory = container.factoryFor('component:foo-bar'); var instance = componentFactory.create(); // note: _guid and isDestroyed are being set in the `factory` constructor // not via registry/container shenanigans assert.deepEqual(Object.keys(instance), []); }); }); enifed('container/tests/owner_test', ['ember-utils'], function (_emberUtils) { 'use strict'; QUnit.module('Owner', {}); QUnit.test('An owner can be set with `setOwner` and retrieved with `getOwner`', function () { var owner = {}; var obj = {}; strictEqual((0, _emberUtils.getOwner)(obj), undefined, 'owner has not been set'); (0, _emberUtils.setOwner)(obj, owner); strictEqual((0, _emberUtils.getOwner)(obj), owner, 'owner has been set'); strictEqual(obj[_emberUtils.OWNER], owner, 'owner has been set to the OWNER symbol'); }); }); enifed('container/tests/registry_test', ['container', 'internal-test-helpers'], function (_container, _internalTestHelpers) { 'use strict'; QUnit.module('Registry'); QUnit.test('A registered factory is returned from resolve', function () { var registry = new _container.Registry(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); var PostControllerFactory = registry.resolve('controller:post'); ok(PostControllerFactory, 'factory is returned'); ok(PostControllerFactory.create() instanceof PostController, 'The return of factory.create is an instance of PostController'); }); QUnit.test('The registered factory returned from resolve is the same factory each time', function () { var registry = new _container.Registry(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); deepEqual(registry.resolve('controller:post'), registry.resolve('controller:post'), 'The return of resolve is always the same'); }); QUnit.test('The registered value returned from resolve is the same value each time even if the value is falsy', function () { var registry = new _container.Registry(); registry.register('falsy:value', null, { instantiate: false }); strictEqual(registry.resolve('falsy:value'), registry.resolve('falsy:value'), 'The return of resolve is always the same'); }); QUnit.test('The value returned from resolver is the same value as the original value even if the value is falsy', function () { var registry = new _container.Registry({ resolver: { resolve: function (fullName) { if (fullName === 'falsy:value') { return null; } } } }); strictEqual(registry.resolve('falsy:value'), null); }); QUnit.test('A registered factory returns true for `has` if an item is registered', function () { var registry = new _container.Registry(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); equal(registry.has('controller:post'), true, 'The `has` method returned true for registered factories'); equal(registry.has('controller:posts'), false, 'The `has` method returned false for unregistered factories'); }); QUnit.test('Throw exception when trying to inject `type:thing` on all type(s)', function () { var registry = new _container.Registry(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); throws(function () { registry.typeInjection('controller', 'injected', 'controller:post'); }, /Cannot inject a 'controller:post' on other controller\(s\)\./); }); QUnit.test('The registry can take a hook to resolve factories lazily', function () { var PostController = (0, _internalTestHelpers.factory)(); var registry = new _container.Registry({ resolver: { resolve: function (fullName) { if (fullName === 'controller:post') { return PostController; } } } }); strictEqual(registry.resolve('controller:post'), PostController, 'The correct factory was provided'); }); QUnit.test('The registry respects the resolver hook for `has`', function () { var PostController = (0, _internalTestHelpers.factory)(); var registry = new _container.Registry({ resolver: { resolve: function (fullName) { if (fullName === 'controller:post') { return PostController; } } } }); ok(registry.has('controller:post'), 'the `has` method uses the resolver hook'); }); QUnit.test('The registry normalizes names when resolving', function () { var registry = new _container.Registry(); var PostController = (0, _internalTestHelpers.factory)(); registry.normalizeFullName = function () { return 'controller:post'; }; registry.register('controller:post', PostController); var type = registry.resolve('controller:normalized'); strictEqual(type, PostController, 'Normalizes the name when resolving'); }); QUnit.test('The registry normalizes names when checking if the factory is registered', function () { var registry = new _container.Registry(); var PostController = (0, _internalTestHelpers.factory)(); registry.normalizeFullName = function (fullName) { return fullName === 'controller:normalized' ? 'controller:post' : fullName; }; registry.register('controller:post', PostController); var isPresent = registry.has('controller:normalized'); equal(isPresent, true, 'Normalizes the name when checking if the factory or instance is present'); }); QUnit.test('validateFullName throws an error if name is incorrect', function () { expect(2); var registry = new _container.Registry(); var PostController = (0, _internalTestHelpers.factory)(); registry.normalize = function () { return 'controller:post'; }; registry.register('controller:post', PostController); throws(function () { registry.validateFullName('post'); }, /TypeError: Invalid Fullname, expected: 'type:name' got: post/); throws(function () { registry.validateFullName('route:http://foo.bar.com/baz'); }, /TypeError: Invalid Fullname, expected: 'type:name' got: route:http:\/\/foo.bar.com\/baz/); }); QUnit.test('The registry normalizes names when injecting', function () { var registry = new _container.Registry(); var PostController = (0, _internalTestHelpers.factory)(); var user = { name: 'Stef' }; registry.normalize = function () { return 'controller:post'; }; registry.register('controller:post', PostController); registry.register('user:post', user, { instantiate: false }); registry.injection('controller:post', 'user', 'controller:normalized'); deepEqual(registry.resolve('controller:post'), user, 'Normalizes the name when injecting'); }); QUnit.test('cannot register an `undefined` factory', function () { var registry = new _container.Registry(); throws(function () { registry.register('controller:apple', undefined); }, ''); }); QUnit.test('can re-register a factory', function () { var registry = new _container.Registry(); var FirstApple = (0, _internalTestHelpers.factory)('first'); var SecondApple = (0, _internalTestHelpers.factory)('second'); registry.register('controller:apple', FirstApple); registry.register('controller:apple', SecondApple); ok(registry.resolve('controller:apple').create() instanceof SecondApple); }); QUnit.test('cannot re-register a factory if it has been resolved', function () { var registry = new _container.Registry(); var FirstApple = (0, _internalTestHelpers.factory)('first'); var SecondApple = (0, _internalTestHelpers.factory)('second'); registry.register('controller:apple', FirstApple); strictEqual(registry.resolve('controller:apple'), FirstApple); throws(function () { registry.register('controller:apple', SecondApple); }, /Cannot re-register: 'controller:apple', as it has already been resolved\./); strictEqual(registry.resolve('controller:apple'), FirstApple); }); QUnit.test('registry.has should not accidentally cause injections on that factory to be run. (Mitigate merely on observing)', function () { expect(1); var registry = new _container.Registry(); var FirstApple = (0, _internalTestHelpers.factory)('first'); var SecondApple = (0, _internalTestHelpers.factory)('second'); SecondApple.extend = function () { ok(false, 'should not extend or touch the injected model, merely to inspect existence of another'); }; registry.register('controller:apple', FirstApple); registry.register('controller:second-apple', SecondApple); registry.injection('controller:apple', 'badApple', 'controller:second-apple'); ok(registry.has('controller:apple')); }); QUnit.test('registry.has should not error for invalid fullNames)', function () { expect(1); var registry = new _container.Registry(); ok(!registry.has('foo:bar:baz')); }); QUnit.test('once resolved, always return the same result', function () { expect(1); var registry = new _container.Registry(); registry.resolver = { resolve: function () { return 'bar'; } }; var Bar = registry.resolve('models:bar'); registry.resolver = { resolve: function () { return 'not bar'; } }; equal(registry.resolve('models:bar'), Bar); }); QUnit.test('factory resolves are cached', function () { var registry = new _container.Registry(); var PostController = (0, _internalTestHelpers.factory)(); var resolveWasCalled = []; registry.resolver = { resolve: function (fullName) { resolveWasCalled.push(fullName); return PostController; } }; deepEqual(resolveWasCalled, []); registry.resolve('controller:post'); deepEqual(resolveWasCalled, ['controller:post']); registry.resolve('controller:post'); deepEqual(resolveWasCalled, ['controller:post']); }); QUnit.test('factory for non extendables (MODEL) resolves are cached', function () { var registry = new _container.Registry(); var PostController = (0, _internalTestHelpers.factory)(); var resolveWasCalled = []; registry.resolver = { resolve: function (fullName) { resolveWasCalled.push(fullName); return PostController; } }; deepEqual(resolveWasCalled, []); registry.resolve('model:post'); deepEqual(resolveWasCalled, ['model:post']); registry.resolve('model:post'); deepEqual(resolveWasCalled, ['model:post']); }); QUnit.test('factory for non extendables resolves are cached', function () { var registry = new _container.Registry(); var PostController = {}; var resolveWasCalled = []; registry.resolver = { resolve: function (fullName) { resolveWasCalled.push(fullName); return PostController; } }; deepEqual(resolveWasCalled, []); registry.resolve('foo:post'); deepEqual(resolveWasCalled, ['foo:post']); registry.resolve('foo:post'); deepEqual(resolveWasCalled, ['foo:post']); }); QUnit.test('registry.container creates a container', function () { var registry = new _container.Registry(); var PostController = (0, _internalTestHelpers.factory)(); registry.register('controller:post', PostController); var container = registry.container(); var postController = container.lookup('controller:post'); ok(postController instanceof PostController, 'The lookup is an instance of the registered factory'); }); QUnit.test('`describe` will be handled by the resolver, then by the fallback registry, if available', function () { var registry = new _container.Registry({ fallback: { describe: function (fullName) { return fullName + '-fallback'; } }, resolver: { lookupDescription: function (fullName) { return fullName + '-resolver'; } } }); equal(registry.describe('controller:post'), 'controller:post-resolver', '`describe` handled by the resolver first.'); registry.resolver = null; equal(registry.describe('controller:post'), 'controller:post-fallback', '`describe` handled by fallback registry next.'); registry.fallback = null; equal(registry.describe('controller:post'), 'controller:post', '`describe` by default returns argument.'); }); QUnit.test('`normalizeFullName` will be handled by the resolver, then by the fallback registry, if available', function () { var registry = new _container.Registry({ fallback: { normalizeFullName: function (fullName) { return fullName + '-fallback'; } }, resolver: { normalize: function (fullName) { return fullName + '-resolver'; } } }); equal(registry.normalizeFullName('controller:post'), 'controller:post-resolver', '`normalizeFullName` handled by the resolver first.'); registry.resolver = null; equal(registry.normalizeFullName('controller:post'), 'controller:post-fallback', '`normalizeFullName` handled by fallback registry next.'); registry.fallback = null; equal(registry.normalizeFullName('controller:post'), 'controller:post', '`normalizeFullName` by default returns argument.'); }); QUnit.test('`makeToString` will be handled by the resolver, then by the fallback registry, if available', function () { var registry = new _container.Registry({ fallback: { makeToString: function (fullName) { return fullName + '-fallback'; } }, resolver: { makeToString: function (fullName) { return fullName + '-resolver'; } } }); equal(registry.makeToString('controller:post'), 'controller:post-resolver', '`makeToString` handled by the resolver first.'); registry.resolver = null; equal(registry.makeToString('controller:post'), 'controller:post-fallback', '`makeToString` handled by fallback registry next.'); registry.fallback = null; equal(registry.makeToString('controller:post'), 'controller:post', '`makeToString` by default returns argument.'); }); QUnit.test('`resolve` can be handled by a fallback registry', function () { var fallback = new _container.Registry(); var registry = new _container.Registry({ fallback: fallback }); var PostController = (0, _internalTestHelpers.factory)(); fallback.register('controller:post', PostController); var PostControllerFactory = registry.resolve('controller:post'); ok(PostControllerFactory, 'factory is returned'); ok(PostControllerFactory.create() instanceof PostController, 'The return of factory.create is an instance of PostController'); }); QUnit.test('`has` can be handled by a fallback registry', function () { var fallback = new _container.Registry(); var registry = new _container.Registry({ fallback: fallback }); var PostController = (0, _internalTestHelpers.factory)(); fallback.register('controller:post', PostController); equal(registry.has('controller:post'), true, 'Fallback registry is checked for registration'); }); QUnit.test('`getInjections` includes injections from a fallback registry', function () { var fallback = new _container.Registry(); var registry = new _container.Registry({ fallback: fallback }); equal(registry.getInjections('model:user').length, 0, 'No injections in the primary registry'); fallback.injection('model:user', 'post', 'model:post'); equal(registry.getInjections('model:user').length, 1, 'Injections from the fallback registry are merged'); }); QUnit.test('`getTypeInjections` includes type injections from a fallback registry', function () { var fallback = new _container.Registry(); var registry = new _container.Registry({ fallback: fallback }); equal(registry.getTypeInjections('model').length, 0, 'No injections in the primary registry'); fallback.injection('model', 'source', 'source:main'); equal(registry.getTypeInjections('model').length, 1, 'Injections from the fallback registry are merged'); }); QUnit.test('`getFactoryInjections` includes factory injections from a fallback registry', function () { var fallback = new _container.Registry(); var registry = new _container.Registry({ fallback: fallback }); equal(registry.getFactoryInjections('model:user').length, 0, 'No factory injections in the primary registry'); fallback.factoryInjection('model:user', 'store', 'store:main'); equal(registry.getFactoryInjections('model:user').length, 1, 'Factory injections from the fallback registry are merged'); }); QUnit.test('`getFactoryTypeInjections` includes factory type injections from a fallback registry', function () { var fallback = new _container.Registry(); var registry = new _container.Registry({ fallback: fallback }); equal(registry.getFactoryTypeInjections('model').length, 0, 'No factory type injections in the primary registry'); fallback.factoryInjection('model', 'store', 'store:main'); equal(registry.getFactoryTypeInjections('model').length, 1, 'Factory type injections from the fallback registry are merged'); }); QUnit.test('`knownForType` contains keys for each item of a given type', function () { var registry = new _container.Registry(); registry.register('foo:bar-baz', 'baz'); registry.register('foo:qux-fez', 'fez'); var found = registry.knownForType('foo'); deepEqual(found, { 'foo:bar-baz': true, 'foo:qux-fez': true }); }); QUnit.test('`knownForType` includes fallback registry results', function () { var fallback = new _container.Registry(); var registry = new _container.Registry({ fallback: fallback }); registry.register('foo:bar-baz', 'baz'); registry.register('foo:qux-fez', 'fez'); fallback.register('foo:zurp-zorp', 'zorp'); var found = registry.knownForType('foo'); deepEqual(found, { 'foo:bar-baz': true, 'foo:qux-fez': true, 'foo:zurp-zorp': true }); }); QUnit.test('`knownForType` is called on the resolver if present', function () { expect(3); var registry = new _container.Registry({ resolver: { knownForType: function (type) { ok(true, 'knownForType called on the resolver'); equal(type, 'foo', 'the type was passed through'); return { 'foo:yorp': true }; } } }); registry.register('foo:bar-baz', 'baz'); var found = registry.knownForType('foo'); deepEqual(found, { 'foo:yorp': true, 'foo:bar-baz': true }); }); QUnit.test('A registry can be created with a deprecated `resolver` function instead of an object', function () { expect(2); var registry = void 0; expectDeprecation(function () { registry = new _container.Registry({ resolver: function (fullName) { return fullName + '-resolved'; } }); }, 'Passing a `resolver` function into a Registry is deprecated. Please pass in a Resolver object with a `resolve` method.'); equal(registry.resolve('foo:bar'), 'foo:bar-resolved', '`resolve` still calls the deprecated function'); }); QUnit.test('resolver.expandLocalLookup is not required', function (assert) { assert.expect(1); var registry = new _container.Registry({ resolver: {} }); var result = registry.expandLocalLookup('foo:bar', { source: 'baz:qux' }); assert.equal(result, null); }); QUnit.test('expandLocalLookup is called on the resolver if present', function (assert) { assert.expect(4); var registry = new _container.Registry({ resolver: { expandLocalLookup: function (targetFullName, sourceFullName) { assert.ok(true, 'expandLocalLookup is called on the resolver'); assert.equal(targetFullName, 'foo:bar', 'the targetFullName was passed through'); assert.equal(sourceFullName, 'baz:qux', 'the sourceFullName was passed through'); return 'foo:qux/bar'; } } }); var result = registry.expandLocalLookup('foo:bar', { source: 'baz:qux' }); assert.equal(result, 'foo:qux/bar'); }); QUnit.test('`expandLocalLookup` is handled by the resolver, then by the fallback registry, if available', function (assert) { assert.expect(9); var fallbackRegistry = new _container.Registry({ resolver: { expandLocalLookup: function (targetFullName, sourceFullName) { assert.ok(true, 'expandLocalLookup is called on the fallback resolver'); assert.equal(targetFullName, 'foo:bar', 'the targetFullName was passed through'); assert.equal(sourceFullName, 'baz:qux', 'the sourceFullName was passed through'); return 'foo:qux/bar-fallback'; } } }); var registry = new _container.Registry({ fallback: fallbackRegistry, resolver: { expandLocalLookup: function (targetFullName, sourceFullName) { assert.ok(true, 'expandLocalLookup is called on the resolver'); assert.equal(targetFullName, 'foo:bar', 'the targetFullName was passed through'); assert.equal(sourceFullName, 'baz:qux', 'the sourceFullName was passed through'); return 'foo:qux/bar-resolver'; } } }); var result = registry.expandLocalLookup('foo:bar', { source: 'baz:qux' }); assert.equal(result, 'foo:qux/bar-resolver', 'handled by the resolver'); registry.resolver = null; result = registry.expandLocalLookup('foo:bar', { source: 'baz:qux' }); assert.equal(result, 'foo:qux/bar-fallback', 'handled by the fallback registry'); registry.fallback = null; result = registry.expandLocalLookup('foo:bar', { source: 'baz:qux' }); assert.equal(result, null, 'null is returned by default when no resolver or fallback registry is present'); }); QUnit.test('resolver.expandLocalLookup result is cached', function (assert) { assert.expect(3); var result = void 0; var registry = new _container.Registry({ resolver: { expandLocalLookup: function () { assert.ok(true, 'expandLocalLookup is called on the resolver'); return 'foo:qux/bar'; } } }); result = registry.expandLocalLookup('foo:bar', { source: 'baz:qux' }); assert.equal(result, 'foo:qux/bar'); result = registry.expandLocalLookup('foo:bar', { source: 'baz:qux' }); assert.equal(result, 'foo:qux/bar'); }); QUnit.test('resolver.expandLocalLookup cache is busted when any unregister is called', function (assert) { assert.expect(4); var result = void 0; var registry = new _container.Registry({ resolver: { expandLocalLookup: function () { assert.ok(true, 'expandLocalLookup is called on the resolver'); return 'foo:qux/bar'; } } }); result = registry.expandLocalLookup('foo:bar', { source: 'baz:qux' }); assert.equal(result, 'foo:qux/bar'); registry.unregister('foo:bar'); result = registry.expandLocalLookup('foo:bar', { source: 'baz:qux' }); assert.equal(result, 'foo:qux/bar'); }); QUnit.test('resolve calls expandLocallookup when it receives options.source', function (assert) { assert.expect(3); var registry = new _container.Registry({ resolver: { resolve: function () {}, expandLocalLookup: function (targetFullName, sourceFullName) { assert.ok(true, 'expandLocalLookup is called on the resolver'); assert.equal(targetFullName, 'foo:bar', 'the targetFullName was passed through'); assert.equal(sourceFullName, 'baz:qux', 'the sourceFullName was passed through'); return 'foo:qux/bar'; } } }); registry.resolve('foo:bar', { source: 'baz:qux' }); }); QUnit.test('has uses expandLocalLookup', function (assert) { assert.expect(5); var resolvedFullNames = []; var result = void 0; var registry = new _container.Registry({ resolver: { resolve: function (name) { resolvedFullNames.push(name); return 'yippie!'; }, expandLocalLookup: function (targetFullName) { assert.ok(true, 'expandLocalLookup is called on the resolver'); if (targetFullName === 'foo:bar') { return 'foo:qux/bar'; } else { return null; } } } }); result = registry.has('foo:bar', { source: 'baz:qux' }); assert.ok(result, 'found foo:bar/qux'); result = registry.has('foo:baz', { source: 'baz:qux' }); assert.ok(!result, 'foo:baz/qux not found'); assert.deepEqual(['foo:qux/bar'], resolvedFullNames); }); }); enifed('ember-application/tests/system/application_instance_test', ['ember-babel', 'ember-application/system/engine', 'ember-application/system/application', 'ember-application/system/application-instance', 'ember-metal', 'ember-views', 'container', 'internal-test-helpers', 'ember-runtime'], function (_emberBabel, _engine, _application, _applicationInstance, _emberMetal, _emberViews, _container, _internalTestHelpers, _emberRuntime) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['-bucket-cache:main'], ['-bucket-cache:main']); var application = void 0, appInstance = void 0; QUnit.module('Ember.ApplicationInstance', { setup: function () { (0, _emberViews.jQuery)('#qunit-fixture').html('
HI
HI
'); application = (0, _emberMetal.run)(function () { return _application.default.create({ rootElement: '#one', router: null }); }); }, teardown: function () { (0, _emberViews.jQuery)('#qunit-fixture').empty(); if (appInstance) { (0, _emberMetal.run)(appInstance, 'destroy'); } if (application) { (0, _emberMetal.run)(application, 'destroy'); } } }); QUnit.test('an application instance can be created based upon an application', function () { appInstance = (0, _emberMetal.run)(function () { return appInstance = _applicationInstance.default.create({ application: application }); }); ok(appInstance, 'instance should be created'); equal(appInstance.application, application, 'application should be set to parent'); }); QUnit.test('properties (and aliases) are correctly assigned for accessing the container and registry', function () { expect(9); appInstance = (0, _emberMetal.run)(function () { return _applicationInstance.default.create({ application: application }); }); ok(appInstance, 'instance should be created'); ok(appInstance.__container__, '#__container__ is accessible'); ok(appInstance.__registry__, '#__registry__ is accessible'); ok(typeof appInstance.container.lookup === 'function', '#container.lookup is available as a function'); // stub with a no-op to keep deprecation test simple appInstance.__container__.lookup = function () { ok(true, '#loookup alias is called correctly'); }; expectDeprecation(function () { appInstance.container.lookup(); }, /Using `ApplicationInstance.container.lookup` is deprecated. Please use `ApplicationInstance.lookup` instead./); ok(typeof appInstance.registry.register === 'function', '#registry.register is available as a function'); appInstance.__registry__.register = function () { ok(true, '#register alias is called correctly'); }; expectDeprecation(function () { appInstance.registry.register(); }, /Using `ApplicationInstance.registry.register` is deprecated. Please use `ApplicationInstance.register` instead./); }); QUnit.test('customEvents added to the application before setupEventDispatcher', function (assert) { assert.expect(1); appInstance = (0, _emberMetal.run)(function () { return _applicationInstance.default.create({ application: application }); }); application.customEvents = { awesome: 'sauce' }; var eventDispatcher = appInstance.lookup('event_dispatcher:main'); eventDispatcher.setup = function (events) { assert.equal(events.awesome, 'sauce'); }; appInstance.setupEventDispatcher(); }); QUnit.test('customEvents added to the application before setupEventDispatcher', function (assert) { assert.expect(1); (0, _emberMetal.run)(function () { return appInstance = _applicationInstance.default.create({ application: application }); }); application.customEvents = { awesome: 'sauce' }; var eventDispatcher = appInstance.lookup('event_dispatcher:main'); eventDispatcher.setup = function (events) { assert.equal(events.awesome, 'sauce'); }; appInstance.setupEventDispatcher(); }); QUnit.test('customEvents added to the application instance before setupEventDispatcher', function (assert) { assert.expect(1); appInstance = (0, _emberMetal.run)(function () { return _applicationInstance.default.create({ application: application }); }); appInstance.customEvents = { awesome: 'sauce' }; var eventDispatcher = appInstance.lookup('event_dispatcher:main'); eventDispatcher.setup = function (events) { assert.equal(events.awesome, 'sauce'); }; appInstance.setupEventDispatcher(); }); QUnit.test('unregistering a factory clears all cached instances of that factory', function (assert) { assert.expect(3); appInstance = (0, _emberMetal.run)(function () { return _applicationInstance.default.create({ application: application }); }); var PostController = (0, _internalTestHelpers.factory)(); appInstance.register('controller:post', PostController); var postController1 = appInstance.lookup('controller:post'); assert.ok(postController1, 'lookup creates instance'); appInstance.unregister('controller:post'); appInstance.register('controller:post', PostController); var postController2 = appInstance.lookup('controller:post'); assert.ok(postController2, 'lookup creates instance'); assert.notStrictEqual(postController1, postController2, 'lookup creates a brand new instance, because the previous one was reset'); }); QUnit.test('can build and boot a registered engine', function (assert) { assert.expect(11); var ChatEngine = _engine.default.extend(); var chatEngineInstance = void 0; application.register('engine:chat', ChatEngine); (0, _emberMetal.run)(function () { appInstance = _applicationInstance.default.create({ application: application }); appInstance.setupRegistry(); chatEngineInstance = appInstance.buildChildEngineInstance('chat'); }); return chatEngineInstance.boot().then(function () { assert.ok(true, 'boot successful'); ['route:basic', 'event_dispatcher:main', 'service:-routing', 'service:-glimmer-environment'].forEach(function (key) { assert.strictEqual(chatEngineInstance.resolveRegistration(key), appInstance.resolveRegistration(key), 'Engine and parent app share registrations for \'' + key + '\''); }); var singletons = ['router:main', (0, _container.privatize)(_templateObject), '-view-registry:main', '-environment:main', 'service:-document']; var env = appInstance.lookup('-environment:main'); singletons.push(env.isInteractive ? 'renderer:-dom' : 'renderer:-inert'); singletons.forEach(function (key) { assert.strictEqual(chatEngineInstance.lookup(key), appInstance.lookup(key), 'Engine and parent app share singleton \'' + key + '\''); }); }); }); QUnit.test('can build a registry via Ember.ApplicationInstance.setupRegistry() -- simulates ember-test-helpers', function (assert) { var namespace = _emberRuntime.Object.create({ Resolver: { create: function () {} } }); var registry = _application.default.buildRegistry(namespace); _applicationInstance.default.setupRegistry(registry); assert.equal(registry.resolve('service:-document'), document); }); }); enifed('ember-application/tests/system/application_test', ['ember-babel', 'ember', 'ember-environment', 'ember-metal', 'ember-debug', 'ember-application/system/application', 'ember-application/system/resolver', 'ember-routing', 'ember-views', 'ember-runtime', 'ember-template-compiler', 'ember-glimmer', 'container', 'ember-application/tests/test-helpers/registry-check', 'ember-utils', 'internal-test-helpers'], function (_emberBabel, _ember, _emberEnvironment, _emberMetal, _emberDebug, _application, _resolver, _emberRouting, _emberViews, _emberRuntime, _emberTemplateCompiler, _emberGlimmer, _container, _registryCheck, _emberUtils, _internalTestHelpers) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['-bucket-cache:main'], ['-bucket-cache:main']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['template:components/-default'], ['template:components/-default']); var trim = _emberViews.jQuery.trim; (0, _internalTestHelpers.moduleFor)('Ember.Application, autobooting multiple apps', function (_ApplicationTestCase) { (0, _emberBabel.inherits)(_class, _ApplicationTestCase); function _class() { (0, _emberViews.jQuery)('#qunit-fixture').html('\n
\n
HI
\n
\n
HI
\n '); return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this)); } _class.prototype.buildSecondApplication = function (options) { var myOptions = (0, _emberUtils.assign)(this.applicationOptions, options); return this.secondApp = _application.default.create(myOptions); }; _class.prototype.teardown = function () { _ApplicationTestCase.prototype.teardown.call(this); if (this.secondApp) { (0, _emberMetal.run)(this.secondApp, 'destroy'); } }; _class.prototype['@test you can make a new application in a non-overlapping element'] = function (assert) { var _this2 = this; var app = (0, _emberMetal.run)(function () { return _this2.buildSecondApplication({ rootElement: '#two' }); }); (0, _emberMetal.run)(app, 'destroy'); assert.ok(true, 'should not raise'); }; _class.prototype['@test you cannot make a new application that is a parent of an existing application'] = function () { var _this3 = this; expectAssertion(function () { (0, _emberMetal.run)(function () { return _this3.buildSecondApplication({ rootElement: '#qunit-fixture' }); }); }); }; _class.prototype['@test you cannot make a new application that is a descendant of an existing application'] = function () { var _this4 = this; expectAssertion(function () { (0, _emberMetal.run)(function () { return _this4.buildSecondApplication({ rootElement: '#one-child' }); }); }); }; _class.prototype['@test you cannot make a new application that is a duplicate of an existing application'] = function () { var _this5 = this; expectAssertion(function () { (0, _emberMetal.run)(function () { return _this5.buildSecondApplication({ rootElement: '#one' }); }); }); }; _class.prototype['@test you cannot make two default applications without a rootElement error'] = function () { var _this6 = this; expectAssertion(function () { (0, _emberMetal.run)(function () { return _this6.buildSecondApplication(); }); }); }; (0, _emberBabel.createClass)(_class, [{ key: 'applicationOptions', get: function () { return (0, _emberUtils.assign)(_ApplicationTestCase.prototype.applicationOptions, { rootElement: '#one', router: null, autoboot: true }); } }]); return _class; }(_internalTestHelpers.ApplicationTestCase)); (0, _internalTestHelpers.moduleFor)('Ember.Application', function (_ApplicationTestCase2) { (0, _emberBabel.inherits)(_class2, _ApplicationTestCase2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase2.apply(this, arguments)); } _class2.prototype['@test includes deprecated access to `application.registry`'] = function (assert) { var _this8 = this; assert.expect(3); assert.ok(typeof this.application.registry.register === 'function', '#registry.register is available as a function'); this.application.__registry__.register = function () { assert.ok(true, '#register alias is called correctly'); }; expectDeprecation(function () { _this8.application.registry.register(); }, /Using `Application.registry.register` is deprecated. Please use `Application.register` instead./); }; _class2.prototype['@test builds a registry'] = function (assert) { var application = this.application; assert.strictEqual(application.resolveRegistration('application:main'), application, 'application:main is registered'); assert.deepEqual(application.registeredOptionsForType('component'), { singleton: false }, 'optionsForType \'component\''); assert.deepEqual(application.registeredOptionsForType('view'), { singleton: false }, 'optionsForType \'view\''); (0, _registryCheck.verifyRegistration)(application, 'controller:basic'); (0, _registryCheck.verifyRegistration)(application, '-view-registry:main'); (0, _registryCheck.verifyInjection)(application, 'view', '_viewRegistry', '-view-registry:main'); (0, _registryCheck.verifyInjection)(application, 'route', '_topLevelViewTemplate', 'template:-outlet'); (0, _registryCheck.verifyRegistration)(application, 'route:basic'); (0, _registryCheck.verifyRegistration)(application, 'event_dispatcher:main'); (0, _registryCheck.verifyInjection)(application, 'router:main', 'namespace', 'application:main'); (0, _registryCheck.verifyInjection)(application, 'view:-outlet', 'namespace', 'application:main'); (0, _registryCheck.verifyRegistration)(application, 'location:auto'); (0, _registryCheck.verifyRegistration)(application, 'location:hash'); (0, _registryCheck.verifyRegistration)(application, 'location:history'); (0, _registryCheck.verifyRegistration)(application, 'location:none'); (0, _registryCheck.verifyInjection)(application, 'controller', 'target', 'router:main'); (0, _registryCheck.verifyInjection)(application, 'controller', 'namespace', 'application:main'); (0, _registryCheck.verifyRegistration)(application, (0, _container.privatize)(_templateObject)); (0, _registryCheck.verifyInjection)(application, 'router', '_bucketCache', (0, _container.privatize)(_templateObject)); (0, _registryCheck.verifyInjection)(application, 'route', '_bucketCache', (0, _container.privatize)(_templateObject)); (0, _registryCheck.verifyInjection)(application, 'route', 'router', 'router:main'); (0, _registryCheck.verifyRegistration)(application, 'component:-text-field'); (0, _registryCheck.verifyRegistration)(application, 'component:-text-area'); (0, _registryCheck.verifyRegistration)(application, 'component:-checkbox'); (0, _registryCheck.verifyRegistration)(application, 'component:link-to'); (0, _registryCheck.verifyRegistration)(application, 'service:-routing'); (0, _registryCheck.verifyInjection)(application, 'service:-routing', 'router', 'router:main'); // DEBUGGING (0, _registryCheck.verifyRegistration)(application, 'resolver-for-debugging:main'); (0, _registryCheck.verifyInjection)(application, 'container-debug-adapter:main', 'resolver', 'resolver-for-debugging:main'); (0, _registryCheck.verifyInjection)(application, 'data-adapter:main', 'containerDebugAdapter', 'container-debug-adapter:main'); (0, _registryCheck.verifyRegistration)(application, 'container-debug-adapter:main'); (0, _registryCheck.verifyRegistration)(application, 'component-lookup:main'); (0, _registryCheck.verifyRegistration)(application, 'service:-glimmer-environment'); (0, _registryCheck.verifyRegistration)(application, 'service:-dom-changes'); (0, _registryCheck.verifyRegistration)(application, 'service:-dom-tree-construction'); (0, _registryCheck.verifyInjection)(application, 'service:-glimmer-environment', 'appendOperations', 'service:-dom-tree-construction'); (0, _registryCheck.verifyInjection)(application, 'service:-glimmer-environment', 'updateOperations', 'service:-dom-changes'); (0, _registryCheck.verifyInjection)(application, 'renderer', 'env', 'service:-glimmer-environment'); (0, _registryCheck.verifyRegistration)(application, 'view:-outlet'); (0, _registryCheck.verifyRegistration)(application, 'renderer:-dom'); (0, _registryCheck.verifyRegistration)(application, 'renderer:-inert'); (0, _registryCheck.verifyRegistration)(application, (0, _container.privatize)(_templateObject2)); (0, _registryCheck.verifyRegistration)(application, 'template:-outlet'); (0, _registryCheck.verifyInjection)(application, 'view:-outlet', 'template', 'template:-outlet'); (0, _registryCheck.verifyInjection)(application, 'template', 'env', 'service:-glimmer-environment'); assert.deepEqual(application.registeredOptionsForType('helper'), { instantiate: false }, 'optionsForType \'helper\''); }; return _class2; }(_internalTestHelpers.ApplicationTestCase)); (0, _internalTestHelpers.moduleFor)('Ember.Application, default resolver with autoboot', function (_AutobootApplicationT) { (0, _emberBabel.inherits)(_class3, _AutobootApplicationT); function _class3() { var _this9 = (0, _emberBabel.possibleConstructorReturn)(this, _AutobootApplicationT.call(this)); _this9.originalLookup = _emberEnvironment.context.lookup; return _this9; } _class3.prototype.teardown = function () { _emberEnvironment.context.lookup = this.originalLookup; _AutobootApplicationT.prototype.teardown.call(this); (0, _emberGlimmer.setTemplates)({}); }; _class3.prototype.createApplication = function (options) { var myOptions = (0, _emberUtils.assign)({ Resolver: _resolver.default }, options); return _AutobootApplicationT.prototype.createApplication.call(this, myOptions); }; _class3.prototype['@test acts like a namespace'] = function (assert) { var _this10 = this; var lookup = _emberEnvironment.context.lookup = {}; (0, _emberMetal.run)(function () { lookup.TestApp = _this10.createApplication(); }); (0, _emberRuntime.setNamespaceSearchDisabled)(false); var Foo = this.application.Foo = _emberRuntime.Object.extend(); assert.equal(Foo.toString(), 'TestApp.Foo', 'Classes pick up their parent namespace'); }; _class3.prototype['@test can specify custom router'] = function (assert) { var _this11 = this; var MyRouter = _emberRouting.Router.extend(); (0, _emberMetal.run)(function () { var app = _this11.createApplication(); app.Router = MyRouter; }); assert.ok(this.application.__deprecatedInstance__.lookup('router:main') instanceof MyRouter, 'application resolved the correct router'); }; _class3.prototype['@test Minimal Application initialized with just an application template'] = function () { var _this12 = this; (0, _emberViews.jQuery)('#qunit-fixture').html(''); (0, _emberMetal.run)(function () { _this12.createApplication(); }); equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'Hello World'); }; return _class3; }(_internalTestHelpers.AutobootApplicationTestCase)); (0, _internalTestHelpers.moduleFor)('Ember.Application, autobooting', function (_AutobootApplicationT2) { (0, _emberBabel.inherits)(_class4, _AutobootApplicationT2); function _class4() { var _this13 = (0, _emberBabel.possibleConstructorReturn)(this, _AutobootApplicationT2.call(this)); _this13.originalLogVersion = _emberEnvironment.ENV.LOG_VERSION; _this13.originalDebug = (0, _emberDebug.getDebugFunction)('debug'); _this13.originalWarn = (0, _emberDebug.getDebugFunction)('warn'); return _this13; } _class4.prototype.teardown = function () { (0, _emberDebug.setDebugFunction)('warn', this.originalWarn); (0, _emberDebug.setDebugFunction)('debug', this.originalDebug); _emberEnvironment.ENV.LOG_VERSION = this.originalLogVersion; _AutobootApplicationT2.prototype.teardown.call(this); }; _class4.prototype.createApplication = function (options, MyApplication) { var application = _AutobootApplicationT2.prototype.createApplication.call(this, options, MyApplication); this.add('router:main', _emberRouting.Router.extend({ location: 'none' })); return application; }; _class4.prototype['@test initialized application goes to initial route'] = function (assert) { var _this14 = this; (0, _emberMetal.run)(function () { _this14.createApplication(); _this14.addTemplate('application', '{{outlet}}'); _this14.addTemplate('index', '

Hi from index

'); }); assert.equal((0, _emberViews.jQuery)('#qunit-fixture h1').text(), 'Hi from index'); }; _class4.prototype['@test ready hook is called before routing begins'] = function (assert) { var _this15 = this; assert.expect(2); (0, _emberMetal.run)(function () { function registerRoute(application, name, callback) { var route = _emberRouting.Route.extend({ activate: callback }); application.register('route:' + name, route); } var MyApplication = _application.default.extend({ ready: function () { registerRoute(this, 'index', function () { assert.ok(true, 'last-minute route is activated'); }); } }); var app = _this15.createApplication({}, MyApplication); registerRoute(app, 'application', function () { return ok(true, 'normal route is activated'); }); }); }; _class4.prototype['@test initialize application via initialize call'] = function (assert) { var _this16 = this; (0, _emberMetal.run)(function () { _this16.createApplication(); }); // This is not a public way to access the container; we just // need to make some assertions about the created router var router = this.application.__deprecatedInstance__.lookup('router:main'); assert.equal(router instanceof _emberRouting.Router, true, 'Router was set from initialize call'); assert.equal(router.location instanceof _emberRouting.NoneLocation, true, 'Location was set from location implementation name'); }; _class4.prototype['@test initialize application with stateManager via initialize call from Router class'] = function (assert) { var _this17 = this; (0, _emberMetal.run)(function () { _this17.createApplication(); _this17.addTemplate('application', '

Hello!

'); }); // This is not a public way to access the container; we just // need to make some assertions about the created router var router = this.application.__deprecatedInstance__.lookup('router:main'); assert.equal(router instanceof _emberRouting.Router, true, 'Router was set from initialize call'); assert.equal((0, _emberViews.jQuery)('#qunit-fixture h1').text(), 'Hello!'); }; _class4.prototype['@test Application Controller backs the appplication template'] = function (assert) { var _this18 = this; (0, _emberMetal.run)(function () { _this18.createApplication(); _this18.addTemplate('application', '

{{greeting}}

'); _this18.add('controller:application', _emberRuntime.Controller.extend({ greeting: 'Hello!' })); }); assert.equal((0, _emberViews.jQuery)('#qunit-fixture h1').text(), 'Hello!'); }; _class4.prototype['@test enable log of libraries with an ENV var'] = function (assert) { var _this19 = this; if (EmberDev && EmberDev.runningProdBuild) { assert.ok(true, 'Logging does not occur in production builds'); return; } var messages = []; _emberEnvironment.ENV.LOG_VERSION = true; (0, _emberDebug.setDebugFunction)('debug', function (message) { return messages.push(message); }); _emberMetal.libraries.register('my-lib', '2.0.0a'); (0, _emberMetal.run)(function () { _this19.createApplication(); }); assert.equal(messages[1], 'Ember : ' + _ember.VERSION); assert.equal(messages[2], 'jQuery : ' + (0, _emberViews.jQuery)().jquery); assert.equal(messages[3], 'my-lib : ' + '2.0.0a'); _emberMetal.libraries.deRegister('my-lib'); }; _class4.prototype['@test disable log of version of libraries with an ENV var'] = function (assert) { var _this20 = this; var logged = false; _emberEnvironment.ENV.LOG_VERSION = false; (0, _emberDebug.setDebugFunction)('debug', function () { return logged = true; }); (0, _emberMetal.run)(function () { _this20.createApplication(); }); assert.ok(!logged, 'library version logging skipped'); }; _class4.prototype['@test can resolve custom router'] = function (assert) { var _this21 = this; var CustomRouter = _emberRouting.Router.extend(); (0, _emberMetal.run)(function () { _this21.createApplication(); _this21.add('router:main', CustomRouter); }); assert.ok(this.application.__deprecatedInstance__.lookup('router:main') instanceof CustomRouter, 'application resolved the correct router'); }; _class4.prototype['@test does not leak itself in onLoad._loaded'] = function (assert) { var _this22 = this; assert.equal(_emberRuntime._loaded.application, undefined); (0, _emberMetal.run)(function () { return _this22.createApplication(); }); assert.equal(_emberRuntime._loaded.application, this.application); (0, _emberMetal.run)(this.application, 'destroy'); assert.equal(_emberRuntime._loaded.application, undefined); }; _class4.prototype['@test can build a registry via Ember.Application.buildRegistry() --- simulates ember-test-helpers'] = function (assert) { var namespace = _emberRuntime.Object.create({ Resolver: { create: function () {} } }); var registry = _application.default.buildRegistry(namespace); assert.equal(registry.resolve('application:main'), namespace); }; return _class4; }(_internalTestHelpers.AutobootApplicationTestCase)); (0, _internalTestHelpers.moduleFor)('Ember.Application#buildRegistry', function (_AbstractTestCase) { (0, _emberBabel.inherits)(_class5, _AbstractTestCase); function _class5() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractTestCase.apply(this, arguments)); } _class5.prototype['@test can build a registry via Ember.Application.buildRegistry() --- simulates ember-test-helpers'] = function (assert) { var namespace = _emberRuntime.Object.create({ Resolver: { create: function () {} } }); var registry = _application.default.buildRegistry(namespace); assert.equal(registry.resolve('application:main'), namespace); }; return _class5; }(_internalTestHelpers.AbstractTestCase)); }); enifed('ember-application/tests/system/bootstrap-test', ['ember-babel', 'ember-routing', 'ember-utils', 'ember-views', 'internal-test-helpers', 'ember-glimmer', 'ember-application/system/resolver'], function (_emberBabel, _emberRouting, _emberUtils, _emberViews, _internalTestHelpers, _emberGlimmer, _resolver) { 'use strict'; (0, _internalTestHelpers.moduleFor)('Ember.Application with default resolver and autoboot', function (_ApplicationTestCase) { (0, _emberBabel.inherits)(_class, _ApplicationTestCase); function _class() { (0, _emberViews.jQuery)('#qunit-fixture').html('\n
\n\n \n \n '); return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this)); } _class.prototype.teardown = function () { (0, _emberGlimmer.setTemplates)({}); }; _class.prototype['@test templates in script tags are extracted at application creation'] = function (assert) { assert.equal((0, _emberViews.jQuery)('#app').text(), 'Hello World!'); }; (0, _emberBabel.createClass)(_class, [{ key: 'applicationOptions', get: function () { return (0, _emberUtils.assign)(_ApplicationTestCase.prototype.applicationOptions, { autoboot: true, rootElement: '#app', Resolver: _resolver.default, Router: _emberRouting.Router.extend({ location: 'none' }) }); } }]); return _class; }(_internalTestHelpers.ApplicationTestCase)); }); enifed('ember-application/tests/system/dependency_injection/custom_resolver_test', ['ember-views', 'ember-metal', 'ember-application/system/application', 'ember-application/system/resolver', 'ember-template-compiler'], function (_emberViews, _emberMetal, _application, _resolver, _emberTemplateCompiler) { 'use strict'; var application = void 0; QUnit.module('Ember.Application Dependency Injection – customResolver', { setup: function () { var fallbackTemplate = (0, _emberTemplateCompiler.compile)('

Fallback

'); var Resolver = _resolver.default.extend({ resolveTemplate: function (resolvable) { var resolvedTemplate = this._super(resolvable); if (resolvedTemplate) { return resolvedTemplate; } if (resolvable.fullNameWithoutType === 'application') { return fallbackTemplate; } else {} } }); application = (0, _emberMetal.run)(function () { return _application.default.create({ Resolver: Resolver, rootElement: '#qunit-fixture' }); }); }, teardown: function () { (0, _emberMetal.run)(application, 'destroy'); } }); QUnit.test('a resolver can be supplied to application', function () { equal((0, _emberViews.jQuery)('h1', application.rootElement).text(), 'Fallback'); }); }); enifed('ember-application/tests/system/dependency_injection/default_resolver_test', ['ember-environment', 'ember-metal', 'ember-runtime', 'ember-routing', 'ember-application/system/application', 'ember-glimmer', 'ember-template-compiler', 'ember-debug'], function (_emberEnvironment, _emberMetal, _emberRuntime, _emberRouting, _application, _emberGlimmer, _emberTemplateCompiler, _emberDebug) { 'use strict'; /* globals EmberDev */ var registry = void 0, locator = void 0, application = void 0, originalLookup = void 0, originalInfo = void 0; QUnit.module('Ember.Application Dependency Injection - default resolver', { setup: function () { originalLookup = _emberEnvironment.context.lookup; application = (0, _emberMetal.run)(_application.default, 'create'); registry = application.__registry__; locator = application.__container__; originalInfo = (0, _emberDebug.getDebugFunction)('info'); }, teardown: function () { (0, _emberGlimmer.setTemplates)({}); _emberEnvironment.context.lookup = originalLookup; (0, _emberMetal.run)(application, 'destroy'); var UserInterfaceNamespace = _emberRuntime.Namespace.NAMESPACES_BY_ID['UserInterface']; if (UserInterfaceNamespace) { (0, _emberMetal.run)(UserInterfaceNamespace, 'destroy'); } (0, _emberDebug.setDebugFunction)('info', originalInfo); } }); QUnit.test('the default resolver can look things up in other namespaces', function () { var UserInterface = _emberEnvironment.context.lookup.UserInterface = _emberRuntime.Namespace.create(); UserInterface.NavigationController = _emberRuntime.Controller.extend(); var nav = locator.lookup('controller:userInterface/navigation'); ok(nav instanceof UserInterface.NavigationController, 'the result should be an instance of the specified class'); }); QUnit.test('the default resolver looks up templates in Ember.TEMPLATES', function () { var fooTemplate = (0, _emberTemplateCompiler.compile)('foo template'); var fooBarTemplate = (0, _emberTemplateCompiler.compile)('fooBar template'); var fooBarBazTemplate = (0, _emberTemplateCompiler.compile)('fooBar/baz template'); (0, _emberGlimmer.setTemplate)('foo', fooTemplate); (0, _emberGlimmer.setTemplate)('fooBar', fooBarTemplate); (0, _emberGlimmer.setTemplate)('fooBar/baz', fooBarBazTemplate); ignoreDeprecation(function () { equal(locator.lookupFactory('template:foo'), fooTemplate, 'resolves template:foo'); equal(locator.lookupFactory('template:fooBar'), fooBarTemplate, 'resolves template:foo_bar'); equal(locator.lookupFactory('template:fooBar.baz'), fooBarBazTemplate, 'resolves template:foo_bar.baz'); }); equal(locator.factoryFor('template:foo').class, fooTemplate, 'resolves template:foo'); equal(locator.factoryFor('template:fooBar').class, fooBarTemplate, 'resolves template:foo_bar'); equal(locator.factoryFor('template:fooBar.baz').class, fooBarBazTemplate, 'resolves template:foo_bar.baz'); }); QUnit.test('the default resolver looks up basic name as no prefix', function () { ok(_emberRuntime.Controller.detect(locator.lookup('controller:basic')), 'locator looks up correct controller'); }); function detectEqual(first, second, message) { ok(first.detect(second), message); } QUnit.test('the default resolver looks up arbitrary types on the namespace', function () { application.FooManager = _emberRuntime.Object.extend({}); detectEqual(application.FooManager, registry.resolve('manager:foo'), 'looks up FooManager on application'); }); QUnit.test('the default resolver resolves models on the namespace', function () { application.Post = _emberRuntime.Object.extend({}); ignoreDeprecation(function () { detectEqual(application.Post, locator.lookupFactory('model:post'), 'looks up Post model on application'); }); detectEqual(application.Post, locator.factoryFor('model:post').class, 'looks up Post model on application'); }); QUnit.test('the default resolver resolves *:main on the namespace', function () { application.FooBar = _emberRuntime.Object.extend({}); ignoreDeprecation(function () { detectEqual(application.FooBar, locator.lookupFactory('foo-bar:main'), 'looks up FooBar type without name on application'); }); detectEqual(application.FooBar, locator.factoryFor('foo-bar:main').class, 'looks up FooBar type without name on application'); }); QUnit.test('the default resolver resolves container-registered helpers', function () { var shorthandHelper = (0, _emberGlimmer.helper)(function () {}); var helper = _emberGlimmer.Helper.extend(); application.register('helper:shorthand', shorthandHelper); application.register('helper:complete', helper); var lookedUpShorthandHelper = locator.factoryFor('helper:shorthand').class; ok(lookedUpShorthandHelper.isHelperInstance, 'shorthand helper isHelper'); var lookedUpHelper = locator.factoryFor('helper:complete').class; ok(lookedUpHelper.isHelperFactory, 'complete helper is factory'); ok(helper.detect(lookedUpHelper), 'looked up complete helper'); }); QUnit.test('the default resolver resolves container-registered helpers via lookupFor', function () { var shorthandHelper = (0, _emberGlimmer.helper)(function () {}); var helper = _emberGlimmer.Helper.extend(); application.register('helper:shorthand', shorthandHelper); application.register('helper:complete', helper); ignoreDeprecation(function () { var lookedUpShorthandHelper = locator.lookupFactory('helper:shorthand'); ok(lookedUpShorthandHelper.isHelperInstance, 'shorthand helper isHelper'); var lookedUpHelper = locator.lookupFactory('helper:complete'); ok(lookedUpHelper.isHelperFactory, 'complete helper is factory'); ok(helper.detect(lookedUpHelper), 'looked up complete helper'); }); }); QUnit.test('the default resolver resolves helpers on the namespace', function () { var ShorthandHelper = (0, _emberGlimmer.helper)(function () {}); var CompleteHelper = _emberGlimmer.Helper.extend(); application.ShorthandHelper = ShorthandHelper; application.CompleteHelper = CompleteHelper; var resolvedShorthand = registry.resolve('helper:shorthand'); var resolvedComplete = registry.resolve('helper:complete'); equal(resolvedShorthand, ShorthandHelper, 'resolve fetches the shorthand helper factory'); equal(resolvedComplete, CompleteHelper, 'resolve fetches the complete helper factory'); }); QUnit.test('the default resolver resolves to the same instance, no matter the notation ', function () { application.NestedPostController = _emberRuntime.Controller.extend({}); equal(locator.lookup('controller:nested-post'), locator.lookup('controller:nested_post'), 'looks up NestedPost controller on application'); }); QUnit.test('the default resolver throws an error if the fullName to resolve is invalid', function () { throws(function () { registry.resolve(undefined); }, TypeError, /Invalid fullName/); throws(function () { registry.resolve(null); }, TypeError, /Invalid fullName/); throws(function () { registry.resolve(''); }, TypeError, /Invalid fullName/); throws(function () { registry.resolve(''); }, TypeError, /Invalid fullName/); throws(function () { registry.resolve(':'); }, TypeError, /Invalid fullName/); throws(function () { registry.resolve('model'); }, TypeError, /Invalid fullName/); throws(function () { registry.resolve('model:'); }, TypeError, /Invalid fullName/); throws(function () { registry.resolve(':type'); }, TypeError, /Invalid fullName/); }); QUnit.test('the default resolver logs hits if `LOG_RESOLVER` is set', function () { if (EmberDev && EmberDev.runningProdBuild) { ok(true, 'Logging does not occur in production builds'); return; } expect(3); application.LOG_RESOLVER = true; application.ScoobyDoo = _emberRuntime.Object.extend(); application.toString = function () { return 'App'; }; (0, _emberDebug.setDebugFunction)('info', function (symbol, name, padding, lookupDescription) { equal(symbol, '[✓]', 'proper symbol is printed when a module is found'); equal(name, 'doo:scooby', 'proper lookup value is logged'); equal(lookupDescription, 'App.ScoobyDoo'); }); registry.resolve('doo:scooby'); }); QUnit.test('the default resolver logs misses if `LOG_RESOLVER` is set', function () { if (EmberDev && EmberDev.runningProdBuild) { ok(true, 'Logging does not occur in production builds'); return; } expect(3); application.LOG_RESOLVER = true; application.toString = function () { return 'App'; }; (0, _emberDebug.setDebugFunction)('info', function (symbol, name, padding, lookupDescription) { equal(symbol, '[ ]', 'proper symbol is printed when a module is not found'); equal(name, 'doo:scooby', 'proper lookup value is logged'); equal(lookupDescription, 'App.ScoobyDoo'); }); registry.resolve('doo:scooby'); }); QUnit.test('doesn\'t log without LOG_RESOLVER', function () { if (EmberDev && EmberDev.runningProdBuild) { ok(true, 'Logging does not occur in production builds'); return; } var infoCount = 0; application.ScoobyDoo = _emberRuntime.Object.extend(); (0, _emberDebug.setDebugFunction)('info', function () { return infoCount = infoCount + 1; }); registry.resolve('doo:scooby'); registry.resolve('doo:scrappy'); equal(infoCount, 0, 'Logger.info should not be called if LOG_RESOLVER is not set'); }); QUnit.test('lookup description', function () { application.toString = function () { return 'App'; }; equal(registry.describe('controller:foo'), 'App.FooController', 'Type gets appended at the end'); equal(registry.describe('controller:foo.bar'), 'App.FooBarController', 'dots are removed'); equal(registry.describe('model:foo'), 'App.Foo', 'models don\'t get appended at the end'); }); QUnit.test('assertion for routes without isRouteFactory property', function () { application.FooRoute = _emberGlimmer.Component.extend(); expectAssertion(function () { return registry.resolve('route:foo'); }, /to resolve to an Ember.Route/, 'Should assert'); }); QUnit.test('no assertion for routes that extend from Ember.Route', function () { expect(0); application.FooRoute = _emberRouting.Route.extend(); registry.resolve('route:foo'); }); QUnit.test('deprecation warning for service factories without isServiceFactory property', function () { expectAssertion(function () { application.FooService = _emberRuntime.Object.extend(); registry.resolve('service:foo'); }, /Expected service:foo to resolve to an Ember.Service but instead it was \.FooService\./); }); QUnit.test('no deprecation warning for service factories that extend from Ember.Service', function () { expect(0); application.FooService = _emberRuntime.Service.extend(); registry.resolve('service:foo'); }); QUnit.test('deprecation warning for component factories without isComponentFactory property', function () { expectAssertion(function () { application.FooComponent = _emberRuntime.Object.extend(); registry.resolve('component:foo'); }, /Expected component:foo to resolve to an Ember\.Component but instead it was \.FooComponent\./); }); QUnit.test('no deprecation warning for component factories that extend from Ember.Component', function () { expectNoDeprecation(); application.FooView = _emberGlimmer.Component.extend(); registry.resolve('component:foo'); }); QUnit.test('knownForType returns each item for a given type found', function () { application.FooBarHelper = 'foo'; application.BazQuxHelper = 'bar'; var found = registry.resolver.knownForType('helper'); // using `Object.keys` and manually confirming values over using `deepEqual` // due to an issue in QUnit (through at least 1.20.0) that are unable to properly compare // objects with an `undefined` constructor (like ember-metal/empty_object) var foundKeys = Object.keys(found); deepEqual(foundKeys, ['helper:foo-bar', 'helper:baz-qux']); ok(found['helper:foo-bar']); ok(found['helper:baz-qux']); }); QUnit.test('knownForType is not required to be present on the resolver', function () { delete registry.resolver.knownForType; registry.resolver.knownForType('helper', function () {}); ok(true, 'does not error'); }); }); enifed('ember-application/tests/system/dependency_injection/normalization_test', ['ember-metal', 'ember-application/system/application'], function (_emberMetal, _application) { 'use strict'; var application = void 0, registry = void 0; QUnit.module('Ember.Application Dependency Injection – normalization', { setup: function () { application = (0, _emberMetal.run)(_application.default, 'create'); registry = application.__registry__; }, teardown: function () { (0, _emberMetal.run)(application, 'destroy'); } }); QUnit.test('normalization', function () { ok(registry.normalize, 'registry#normalize is present'); equal(registry.normalize('foo:bar'), 'foo:bar'); equal(registry.normalize('controller:posts'), 'controller:posts'); equal(registry.normalize('controller:posts_index'), 'controller:postsIndex'); equal(registry.normalize('controller:posts.index'), 'controller:postsIndex'); equal(registry.normalize('controller:posts-index'), 'controller:postsIndex'); equal(registry.normalize('controller:posts.post.index'), 'controller:postsPostIndex'); equal(registry.normalize('controller:posts_post.index'), 'controller:postsPostIndex'); equal(registry.normalize('controller:posts.post_index'), 'controller:postsPostIndex'); equal(registry.normalize('controller:posts.post-index'), 'controller:postsPostIndex'); equal(registry.normalize('controller:postsIndex'), 'controller:postsIndex'); equal(registry.normalize('controller:blogPosts.index'), 'controller:blogPostsIndex'); equal(registry.normalize('controller:blog/posts.index'), 'controller:blog/postsIndex'); equal(registry.normalize('controller:blog/posts-index'), 'controller:blog/postsIndex'); equal(registry.normalize('controller:blog/posts.post.index'), 'controller:blog/postsPostIndex'); equal(registry.normalize('controller:blog/posts_post.index'), 'controller:blog/postsPostIndex'); equal(registry.normalize('controller:blog/posts_post-index'), 'controller:blog/postsPostIndex'); equal(registry.normalize('template:blog/posts_index'), 'template:blog/posts_index'); }); QUnit.test('normalization is indempotent', function () { ['controller:posts', 'controller:posts.post.index', 'controller:blog/posts.post_index', 'template:foo_bar'].forEach(function (example) { equal(registry.normalize(registry.normalize(example)), registry.normalize(example)); }); }); }); enifed('ember-application/tests/system/dependency_injection/to_string_test', ['ember-utils', 'ember-environment', 'ember-metal', 'ember-application/system/application', 'ember-runtime', 'ember-application/system/resolver'], function (_emberUtils, _emberEnvironment, _emberMetal, _application, _emberRuntime, _resolver) { 'use strict'; // lookup, etc var originalLookup = void 0, App = void 0, originalModelInjections = void 0; QUnit.module('Ember.Application Dependency Injection – toString', { setup: function () { originalModelInjections = _emberEnvironment.ENV.MODEL_FACTORY_INJECTIONS; _emberEnvironment.ENV.MODEL_FACTORY_INJECTIONS = true; originalLookup = _emberEnvironment.context.lookup; (0, _emberMetal.run)(function () { App = _application.default.create(); _emberEnvironment.context.lookup = { App: App }; }); App.Post = _emberRuntime.Object.extend(); }, teardown: function () { _emberEnvironment.context.lookup = originalLookup; (0, _emberMetal.run)(App, 'destroy'); _emberEnvironment.ENV.MODEL_FACTORY_INJECTIONS = originalModelInjections; } }); QUnit.test('factories', function () { var PostFactory = void 0; PostFactory = App.__container__.factoryFor('model:post').class; equal(PostFactory.toString(), 'App.Post', 'expecting the model to be post'); }); QUnit.test('instances', function () { var post = App.__container__.lookup('model:post'); var guid = (0, _emberUtils.guidFor)(post); equal(post.toString(), '', 'expecting the model to be post'); }); QUnit.test('with a custom resolver', function () { (0, _emberMetal.run)(App, 'destroy'); (0, _emberMetal.run)(function () { App = _application.default.create({ Resolver: _resolver.default.extend({ makeToString: function (factory, fullName) { return fullName; } }) }); }); App.register('model:peter', _emberRuntime.Object.extend()); var peter = App.__container__.lookup('model:peter'); var guid = (0, _emberUtils.guidFor)(peter); equal(peter.toString(), '', 'expecting the supermodel to be peter'); }); }); enifed('ember-application/tests/system/dependency_injection_test', ['ember-environment', 'ember-metal', 'ember-runtime', 'ember-application/system/application'], function (_emberEnvironment, _emberMetal, _emberRuntime, _application) { 'use strict'; var EmberApplication = _application.default; var originalLookup = _emberEnvironment.context.lookup; var registry = void 0, locator = void 0, application = void 0, originalModelInjections = void 0; QUnit.module('Ember.Application Dependency Injection', { setup: function () { originalModelInjections = _emberEnvironment.ENV.MODEL_FACTORY_INJECTIONS; _emberEnvironment.ENV.MODEL_FACTORY_INJECTIONS = true; application = (0, _emberMetal.run)(EmberApplication, 'create'); application.Person = _emberRuntime.Object.extend({}); application.Orange = _emberRuntime.Object.extend({}); application.Email = _emberRuntime.Object.extend({}); application.User = _emberRuntime.Object.extend({}); application.PostIndexController = _emberRuntime.Object.extend({}); application.register('model:person', application.Person, { singleton: false }); application.register('model:user', application.User, { singleton: false }); application.register('fruit:favorite', application.Orange); application.register('communication:main', application.Email, { singleton: false }); application.register('controller:postIndex', application.PostIndexController, { singleton: true }); registry = application.__registry__; locator = application.__container__; _emberEnvironment.context.lookup = {}; }, teardown: function () { (0, _emberMetal.run)(application, 'destroy'); application = locator = null; _emberEnvironment.context.lookup = originalLookup; _emberEnvironment.ENV.MODEL_FACTORY_INJECTIONS = originalModelInjections; } }); QUnit.test('container lookup is normalized', function () { var dotNotationController = locator.lookup('controller:post.index'); var camelCaseController = locator.lookup('controller:postIndex'); ok(dotNotationController instanceof application.PostIndexController); ok(camelCaseController instanceof application.PostIndexController); equal(dotNotationController, camelCaseController); }); QUnit.test('registered entities can be looked up later', function () { equal(registry.resolve('model:person'), application.Person); equal(registry.resolve('model:user'), application.User); equal(registry.resolve('fruit:favorite'), application.Orange); equal(registry.resolve('communication:main'), application.Email); equal(registry.resolve('controller:postIndex'), application.PostIndexController); equal(locator.lookup('fruit:favorite'), locator.lookup('fruit:favorite'), 'singleton lookup worked'); ok(locator.lookup('model:user') !== locator.lookup('model:user'), 'non-singleton lookup worked'); }); QUnit.test('injections', function () { application.inject('model', 'fruit', 'fruit:favorite'); application.inject('model:user', 'communication', 'communication:main'); var user = locator.lookup('model:user'); var person = locator.lookup('model:person'); var fruit = locator.lookup('fruit:favorite'); equal(user.get('fruit'), fruit); equal(person.get('fruit'), fruit); ok(application.Email.detectInstance(user.get('communication'))); }); }); enifed('ember-application/tests/system/engine_initializers_test', ['ember-metal', 'ember-application/system/engine'], function (_emberMetal, _engine) { 'use strict'; var MyEngine = void 0, myEngine = void 0, myEngineInstance = void 0; QUnit.module('Ember.Engine initializers', { setup: function () {}, teardown: function () { (0, _emberMetal.run)(function () { if (myEngineInstance) { myEngineInstance.destroy(); } if (myEngine) { myEngine.destroy(); } }); } }); QUnit.test('initializers require proper \'name\' and \'initialize\' properties', function () { MyEngine = _engine.default.extend(); expectAssertion(function () { (0, _emberMetal.run)(function () { MyEngine.initializer({ name: 'initializer' }); }); }); expectAssertion(function () { (0, _emberMetal.run)(function () { MyEngine.initializer({ initialize: function () {} }); }); }); }); QUnit.test('initializers are passed an Engine', function () { MyEngine = _engine.default.extend(); MyEngine.initializer({ name: 'initializer', initialize: function (engine) { ok(engine instanceof _engine.default, 'initialize is passed an Engine'); } }); myEngine = MyEngine.create(); myEngineInstance = myEngine.buildInstance(); }); QUnit.test('initializers can be registered in a specified order', function () { var order = []; MyEngine = _engine.default.extend(); MyEngine.initializer({ name: 'fourth', after: 'third', initialize: function () { order.push('fourth'); } }); MyEngine.initializer({ name: 'second', after: 'first', before: 'third', initialize: function () { order.push('second'); } }); MyEngine.initializer({ name: 'fifth', after: 'fourth', before: 'sixth', initialize: function () { order.push('fifth'); } }); MyEngine.initializer({ name: 'first', before: 'second', initialize: function () { order.push('first'); } }); MyEngine.initializer({ name: 'third', initialize: function () { order.push('third'); } }); MyEngine.initializer({ name: 'sixth', initialize: function () { order.push('sixth'); } }); myEngine = MyEngine.create(); myEngineInstance = myEngine.buildInstance(); deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']); }); QUnit.test('initializers can be registered in a specified order as an array', function () { var order = []; MyEngine = _engine.default.extend(); MyEngine.initializer({ name: 'third', initialize: function () { order.push('third'); } }); MyEngine.initializer({ name: 'second', after: 'first', before: ['third', 'fourth'], initialize: function () { order.push('second'); } }); MyEngine.initializer({ name: 'fourth', after: ['second', 'third'], initialize: function () { order.push('fourth'); } }); MyEngine.initializer({ name: 'fifth', after: 'fourth', before: 'sixth', initialize: function () { order.push('fifth'); } }); MyEngine.initializer({ name: 'first', before: ['second'], initialize: function () { order.push('first'); } }); MyEngine.initializer({ name: 'sixth', initialize: function () { order.push('sixth'); } }); myEngine = MyEngine.create(); myEngineInstance = myEngine.buildInstance(); deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']); }); QUnit.test('initializers can have multiple dependencies', function () { var order = []; MyEngine = _engine.default.extend(); var a = { name: 'a', before: 'b', initialize: function () { order.push('a'); } }; var b = { name: 'b', initialize: function () { order.push('b'); } }; var c = { name: 'c', after: 'b', initialize: function () { order.push('c'); } }; var afterB = { name: 'after b', after: 'b', initialize: function () { order.push('after b'); } }; var afterC = { name: 'after c', after: 'c', initialize: function () { order.push('after c'); } }; MyEngine.initializer(b); MyEngine.initializer(a); MyEngine.initializer(afterC); MyEngine.initializer(afterB); MyEngine.initializer(c); myEngine = MyEngine.create(); myEngineInstance = myEngine.buildInstance(); ok(order.indexOf(a.name) < order.indexOf(b.name), 'a < b'); ok(order.indexOf(b.name) < order.indexOf(c.name), 'b < c'); ok(order.indexOf(b.name) < order.indexOf(afterB.name), 'b < afterB'); ok(order.indexOf(c.name) < order.indexOf(afterC.name), 'c < afterC'); }); QUnit.test('initializers set on Engine subclasses are not shared between engines', function () { var firstInitializerRunCount = 0; var secondInitializerRunCount = 0; var FirstEngine = _engine.default.extend(); FirstEngine.initializer({ name: 'first', initialize: function () { firstInitializerRunCount++; } }); var SecondEngine = _engine.default.extend(); SecondEngine.initializer({ name: 'second', initialize: function () { secondInitializerRunCount++; } }); var firstEngine = FirstEngine.create(); var firstEngineInstance = firstEngine.buildInstance(); equal(firstInitializerRunCount, 1, 'first initializer only was run'); equal(secondInitializerRunCount, 0, 'first initializer only was run'); var secondEngine = SecondEngine.create(); var secondEngineInstance = secondEngine.buildInstance(); equal(firstInitializerRunCount, 1, 'second initializer only was run'); equal(secondInitializerRunCount, 1, 'second initializer only was run'); (0, _emberMetal.run)(function () { firstEngineInstance.destroy(); secondEngineInstance.destroy(); firstEngine.destroy(); secondEngine.destroy(); }); }); QUnit.test('initializers are concatenated', function () { var firstInitializerRunCount = 0; var secondInitializerRunCount = 0; var FirstEngine = _engine.default.extend(); FirstEngine.initializer({ name: 'first', initialize: function () { firstInitializerRunCount++; } }); var SecondEngine = FirstEngine.extend(); SecondEngine.initializer({ name: 'second', initialize: function () { secondInitializerRunCount++; } }); var firstEngine = FirstEngine.create(); var firstEngineInstance = firstEngine.buildInstance(); equal(firstInitializerRunCount, 1, 'first initializer only was run when base class created'); equal(secondInitializerRunCount, 0, 'second initializer was not run when first base class created'); firstInitializerRunCount = 0; var secondEngine = SecondEngine.create(); var secondEngineInstance = secondEngine.buildInstance(); equal(firstInitializerRunCount, 1, 'first initializer was run when subclass created'); equal(secondInitializerRunCount, 1, 'second initializers was run when subclass created'); (0, _emberMetal.run)(function () { firstEngineInstance.destroy(); secondEngineInstance.destroy(); firstEngine.destroy(); secondEngine.destroy(); }); }); QUnit.test('initializers are per-engine', function () { expect(2); var FirstEngine = _engine.default.extend(); FirstEngine.initializer({ name: 'abc', initialize: function () {} }); expectAssertion(function () { FirstEngine.initializer({ name: 'abc', initialize: function () {} }); }); var SecondEngine = _engine.default.extend(); SecondEngine.instanceInitializer({ name: 'abc', initialize: function () {} }); ok(true, 'Two engines can have initializers named the same.'); }); QUnit.test('initializers are executed in their own context', function () { expect(1); MyEngine = _engine.default.extend(); MyEngine.initializer({ name: 'coolInitializer', myProperty: 'cool', initialize: function () { equal(this.myProperty, 'cool', 'should have access to its own context'); } }); myEngine = MyEngine.create(); myEngineInstance = myEngine.buildInstance(); }); }); enifed('ember-application/tests/system/engine_instance_initializers_test', ['ember-metal', 'ember-application/system/engine', 'ember-application/system/engine-instance', 'ember-application/system/engine-parent'], function (_emberMetal, _engine, _engineInstance, _engineParent) { 'use strict'; var MyEngine = void 0, myEngine = void 0, myEngineInstance = void 0; function buildEngineInstance(EngineClass) { var engineInstance = EngineClass.buildInstance(); (0, _engineParent.setEngineParent)(engineInstance, { lookup: function () { return {}; }, resolveRegistration: function () { return {}; } }); return engineInstance; } QUnit.module('Ember.Engine instance initializers', { setup: function () {}, teardown: function () { (0, _emberMetal.run)(function () { if (myEngineInstance) { myEngineInstance.destroy(); } if (myEngine) { myEngine.destroy(); } }); } }); QUnit.test('initializers require proper \'name\' and \'initialize\' properties', function () { MyEngine = _engine.default.extend(); expectAssertion(function () { (0, _emberMetal.run)(function () { MyEngine.instanceInitializer({ name: 'initializer' }); }); }); expectAssertion(function () { (0, _emberMetal.run)(function () { MyEngine.instanceInitializer({ initialize: function () {} }); }); }); }); QUnit.test('initializers are passed an engine instance', function () { MyEngine = _engine.default.extend(); MyEngine.instanceInitializer({ name: 'initializer', initialize: function (instance) { ok(instance instanceof _engineInstance.default, 'initialize is passed an engine instance'); } }); myEngine = MyEngine.create(); myEngineInstance = buildEngineInstance(myEngine); return myEngineInstance.boot(); }); QUnit.test('initializers can be registered in a specified order', function () { var order = []; MyEngine = _engine.default.extend(); MyEngine.instanceInitializer({ name: 'fourth', after: 'third', initialize: function () { order.push('fourth'); } }); MyEngine.instanceInitializer({ name: 'second', after: 'first', before: 'third', initialize: function () { order.push('second'); } }); MyEngine.instanceInitializer({ name: 'fifth', after: 'fourth', before: 'sixth', initialize: function () { order.push('fifth'); } }); MyEngine.instanceInitializer({ name: 'first', before: 'second', initialize: function () { order.push('first'); } }); MyEngine.instanceInitializer({ name: 'third', initialize: function () { order.push('third'); } }); MyEngine.instanceInitializer({ name: 'sixth', initialize: function () { order.push('sixth'); } }); myEngine = MyEngine.create(); myEngineInstance = buildEngineInstance(myEngine); return myEngineInstance.boot().then(function () { deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']); }); }); QUnit.test('initializers can be registered in a specified order as an array', function () { var order = []; MyEngine = _engine.default.extend(); MyEngine.instanceInitializer({ name: 'third', initialize: function () { order.push('third'); } }); MyEngine.instanceInitializer({ name: 'second', after: 'first', before: ['third', 'fourth'], initialize: function () { order.push('second'); } }); MyEngine.instanceInitializer({ name: 'fourth', after: ['second', 'third'], initialize: function () { order.push('fourth'); } }); MyEngine.instanceInitializer({ name: 'fifth', after: 'fourth', before: 'sixth', initialize: function () { order.push('fifth'); } }); MyEngine.instanceInitializer({ name: 'first', before: ['second'], initialize: function () { order.push('first'); } }); MyEngine.instanceInitializer({ name: 'sixth', initialize: function () { order.push('sixth'); } }); myEngine = MyEngine.create(); myEngineInstance = buildEngineInstance(myEngine); return myEngineInstance.boot().then(function () { deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']); }); }); QUnit.test('initializers can have multiple dependencies', function () { var order = []; MyEngine = _engine.default.extend(); var a = { name: 'a', before: 'b', initialize: function () { order.push('a'); } }; var b = { name: 'b', initialize: function () { order.push('b'); } }; var c = { name: 'c', after: 'b', initialize: function () { order.push('c'); } }; var afterB = { name: 'after b', after: 'b', initialize: function () { order.push('after b'); } }; var afterC = { name: 'after c', after: 'c', initialize: function () { order.push('after c'); } }; MyEngine.instanceInitializer(b); MyEngine.instanceInitializer(a); MyEngine.instanceInitializer(afterC); MyEngine.instanceInitializer(afterB); MyEngine.instanceInitializer(c); myEngine = MyEngine.create(); myEngineInstance = buildEngineInstance(myEngine); return myEngineInstance.boot().then(function () { ok(order.indexOf(a.name) < order.indexOf(b.name), 'a < b'); ok(order.indexOf(b.name) < order.indexOf(c.name), 'b < c'); ok(order.indexOf(b.name) < order.indexOf(afterB.name), 'b < afterB'); ok(order.indexOf(c.name) < order.indexOf(afterC.name), 'c < afterC'); }); }); QUnit.test('initializers set on Engine subclasses should not be shared between engines', function () { var firstInitializerRunCount = 0; var secondInitializerRunCount = 0; var FirstEngine = _engine.default.extend(); var firstEngine = void 0, firstEngineInstance = void 0; FirstEngine.instanceInitializer({ name: 'first', initialize: function () { firstInitializerRunCount++; } }); var SecondEngine = _engine.default.extend(); var secondEngine = void 0, secondEngineInstance = void 0; SecondEngine.instanceInitializer({ name: 'second', initialize: function () { secondInitializerRunCount++; } }); firstEngine = FirstEngine.create(); firstEngineInstance = buildEngineInstance(firstEngine); return firstEngineInstance.boot().then(function () { equal(firstInitializerRunCount, 1, 'first initializer only was run'); equal(secondInitializerRunCount, 0, 'first initializer only was run'); secondEngine = SecondEngine.create(); secondEngineInstance = buildEngineInstance(secondEngine); return secondEngineInstance.boot(); }).then(function () { equal(firstInitializerRunCount, 1, 'second initializer only was run'); equal(secondInitializerRunCount, 1, 'second initializer only was run'); (0, _emberMetal.run)(function () { firstEngineInstance.destroy(); secondEngineInstance.destroy(); firstEngine.destroy(); secondEngine.destroy(); }); }); }); QUnit.test('initializers are concatenated', function () { var firstInitializerRunCount = 0; var secondInitializerRunCount = 0; var FirstEngine = _engine.default.extend(); FirstEngine.instanceInitializer({ name: 'first', initialize: function () { firstInitializerRunCount++; } }); var SecondEngine = FirstEngine.extend(); SecondEngine.instanceInitializer({ name: 'second', initialize: function () { secondInitializerRunCount++; } }); var firstEngine = FirstEngine.create(); var firstEngineInstance = buildEngineInstance(firstEngine); var secondEngine = void 0, secondEngineInstance = void 0; return firstEngineInstance.boot().then(function () { equal(firstInitializerRunCount, 1, 'first initializer only was run when base class created'); equal(secondInitializerRunCount, 0, 'second initializer was not run when first base class created'); firstInitializerRunCount = 0; secondEngine = SecondEngine.create(); secondEngineInstance = buildEngineInstance(secondEngine); return secondEngineInstance.boot(); }).then(function () { equal(firstInitializerRunCount, 1, 'first initializer was run when subclass created'); equal(secondInitializerRunCount, 1, 'second initializers was run when subclass created'); (0, _emberMetal.run)(function () { firstEngineInstance.destroy(); secondEngineInstance.destroy(); firstEngine.destroy(); secondEngine.destroy(); }); }); }); QUnit.test('initializers are per-engine', function () { expect(2); var FirstEngine = _engine.default.extend(); FirstEngine.instanceInitializer({ name: 'abc', initialize: function () {} }); expectAssertion(function () { FirstEngine.instanceInitializer({ name: 'abc', initialize: function () {} }); }); var SecondEngine = _engine.default.extend(); SecondEngine.instanceInitializer({ name: 'abc', initialize: function () {} }); ok(true, 'Two engines can have initializers named the same.'); }); QUnit.test('initializers are executed in their own context', function () { expect(1); var MyEngine = _engine.default.extend(); MyEngine.instanceInitializer({ name: 'coolInitializer', myProperty: 'cool', initialize: function () { equal(this.myProperty, 'cool', 'should have access to its own context'); } }); myEngine = MyEngine.create(); myEngineInstance = buildEngineInstance(myEngine); return myEngineInstance.boot(); }); }); enifed('ember-application/tests/system/engine_instance_test', ['ember-application/system/engine', 'ember-application/system/engine-instance', 'ember-application/system/engine-parent', 'ember-metal', 'internal-test-helpers'], function (_engine, _engineInstance, _engineParent, _emberMetal, _internalTestHelpers) { 'use strict'; var engine = void 0, engineInstance = void 0; QUnit.module('Ember.EngineInstance', { setup: function () { (0, _emberMetal.run)(function () { engine = _engine.default.create({ router: null }); }); }, teardown: function () { if (engineInstance) { (0, _emberMetal.run)(engineInstance, 'destroy'); } if (engine) { (0, _emberMetal.run)(engine, 'destroy'); } } }); QUnit.test('an engine instance can be created based upon a base engine', function () { (0, _emberMetal.run)(function () { engineInstance = _engineInstance.default.create({ base: engine }); }); ok(engineInstance, 'instance should be created'); equal(engineInstance.base, engine, 'base should be set to engine'); }); QUnit.test('unregistering a factory clears all cached instances of that factory', function (assert) { assert.expect(3); engineInstance = (0, _emberMetal.run)(function () { return _engineInstance.default.create({ base: engine }); }); var PostComponent = (0, _internalTestHelpers.factory)(); engineInstance.register('component:post', PostComponent); var postComponent1 = engineInstance.lookup('component:post'); assert.ok(postComponent1, 'lookup creates instance'); engineInstance.unregister('component:post'); engineInstance.register('component:post', PostComponent); var postComponent2 = engineInstance.lookup('component:post'); assert.ok(postComponent2, 'lookup creates instance'); assert.notStrictEqual(postComponent1, postComponent2, 'lookup creates a brand new instance because previous one was reset'); }); QUnit.test('can be booted when its parent has been set', function (assert) { assert.expect(3); engineInstance = (0, _emberMetal.run)(function () { return _engineInstance.default.create({ base: engine }); }); expectAssertion(function () { engineInstance._bootSync(); }, 'An engine instance\'s parent must be set via `setEngineParent(engine, parent)` prior to calling `engine.boot()`.'); (0, _engineParent.setEngineParent)(engineInstance, {}); // Stub `cloneParentDependencies`, the internals of which are tested along // with application instances. engineInstance.cloneParentDependencies = function () { assert.ok(true, 'parent dependencies are cloned'); }; return engineInstance.boot().then(function () { assert.ok(true, 'boot successful'); }); }); QUnit.test('can build a child instance of a registered engine', function (assert) { var ChatEngine = _engine.default.extend(); var chatEngineInstance = void 0; engine.register('engine:chat', ChatEngine); (0, _emberMetal.run)(function () { engineInstance = _engineInstance.default.create({ base: engine }); // Try to build an unregistered engine. throws(function () { engineInstance.buildChildEngineInstance('fake'); }, 'You attempted to mount the engine \'fake\', but it is not registered with its parent.'); // Build the `chat` engine, registered above. chatEngineInstance = engineInstance.buildChildEngineInstance('chat'); }); assert.ok(chatEngineInstance, 'child engine instance successfully created'); assert.strictEqual((0, _engineParent.getEngineParent)(chatEngineInstance), engineInstance, 'child engine instance is assigned the correct parent'); }); }); enifed('ember-application/tests/system/engine_parent_test', ['ember-application/system/engine-parent'], function (_engineParent) { 'use strict'; QUnit.module('EngineParent', {}); QUnit.test('An engine\'s parent can be set with `setEngineParent` and retrieved with `getEngineParent`', function () { var engine = {}; var parent = {}; strictEqual((0, _engineParent.getEngineParent)(engine), undefined, 'parent has not been set'); (0, _engineParent.setEngineParent)(engine, parent); strictEqual((0, _engineParent.getEngineParent)(engine), parent, 'parent has been set'); strictEqual(engine[_engineParent.ENGINE_PARENT], parent, 'parent has been set to the ENGINE_PARENT symbol'); }); }); enifed('ember-application/tests/system/engine_test', ['ember-babel', 'ember-environment', 'ember-metal', 'ember-application/system/engine', 'ember-runtime', 'container', 'ember-application/tests/test-helpers/registry-check'], function (_emberBabel, _emberEnvironment, _emberMetal, _engine, _emberRuntime, _container, _registryCheck) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['-bucket-cache:main'], ['-bucket-cache:main']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['template:components/-default'], ['template:components/-default']); var engine = void 0; var originalLookup = _emberEnvironment.context.lookup; var lookup = void 0; QUnit.module('Ember.Engine', { setup: function () { lookup = _emberEnvironment.context.lookup = {}; engine = (0, _emberMetal.run)(function () { return _engine.default.create(); }); }, teardown: function () { _emberEnvironment.context.lookup = originalLookup; if (engine) { (0, _emberMetal.run)(engine, 'destroy'); } } }); QUnit.test('acts like a namespace', function () { engine = (0, _emberMetal.run)(function () { return lookup.TestEngine = _engine.default.create(); }); engine.Foo = _emberRuntime.Object.extend(); equal(engine.Foo.toString(), 'TestEngine.Foo', 'Classes pick up their parent namespace'); }); QUnit.test('builds a registry', function () { strictEqual(engine.resolveRegistration('application:main'), engine, 'application:main is registered'); deepEqual(engine.registeredOptionsForType('component'), { singleton: false }, 'optionsForType \'component\''); deepEqual(engine.registeredOptionsForType('view'), { singleton: false }, 'optionsForType \'view\''); (0, _registryCheck.verifyRegistration)(engine, 'controller:basic'); (0, _registryCheck.verifyInjection)(engine, 'view', '_viewRegistry', '-view-registry:main'); (0, _registryCheck.verifyInjection)(engine, 'route', '_topLevelViewTemplate', 'template:-outlet'); (0, _registryCheck.verifyInjection)(engine, 'view:-outlet', 'namespace', 'application:main'); (0, _registryCheck.verifyInjection)(engine, 'controller', 'target', 'router:main'); (0, _registryCheck.verifyInjection)(engine, 'controller', 'namespace', 'application:main'); (0, _registryCheck.verifyInjection)(engine, 'router', '_bucketCache', (0, _container.privatize)(_templateObject)); (0, _registryCheck.verifyInjection)(engine, 'route', '_bucketCache', (0, _container.privatize)(_templateObject)); (0, _registryCheck.verifyInjection)(engine, 'route', 'router', 'router:main'); (0, _registryCheck.verifyRegistration)(engine, 'component:-text-field'); (0, _registryCheck.verifyRegistration)(engine, 'component:-text-area'); (0, _registryCheck.verifyRegistration)(engine, 'component:-checkbox'); (0, _registryCheck.verifyRegistration)(engine, 'component:link-to'); (0, _registryCheck.verifyRegistration)(engine, 'service:-routing'); (0, _registryCheck.verifyInjection)(engine, 'service:-routing', 'router', 'router:main'); // DEBUGGING (0, _registryCheck.verifyRegistration)(engine, 'resolver-for-debugging:main'); (0, _registryCheck.verifyInjection)(engine, 'container-debug-adapter:main', 'resolver', 'resolver-for-debugging:main'); (0, _registryCheck.verifyInjection)(engine, 'data-adapter:main', 'containerDebugAdapter', 'container-debug-adapter:main'); (0, _registryCheck.verifyRegistration)(engine, 'container-debug-adapter:main'); (0, _registryCheck.verifyRegistration)(engine, 'component-lookup:main'); (0, _registryCheck.verifyInjection)(engine, 'service:-dom-changes', 'document', 'service:-document'); (0, _registryCheck.verifyInjection)(engine, 'service:-dom-tree-construction', 'document', 'service:-document'); (0, _registryCheck.verifyRegistration)(engine, 'view:-outlet'); (0, _registryCheck.verifyRegistration)(engine, (0, _container.privatize)(_templateObject2)); (0, _registryCheck.verifyRegistration)(engine, 'template:-outlet'); (0, _registryCheck.verifyInjection)(engine, 'view:-outlet', 'template', 'template:-outlet'); (0, _registryCheck.verifyInjection)(engine, 'template', 'env', 'service:-glimmer-environment'); deepEqual(engine.registeredOptionsForType('helper'), { instantiate: false }, 'optionsForType \'helper\''); }); }); enifed('ember-application/tests/system/initializers_test', ['ember-metal', 'ember-application/system/application', 'ember-views'], function (_emberMetal, _application, _emberViews) { 'use strict'; var app = void 0; QUnit.module('Ember.Application initializers', { teardown: function () { if (app) { (0, _emberMetal.run)(function () { return app.destroy(); }); } } }); QUnit.test('initializers require proper \'name\' and \'initialize\' properties', function () { var MyApplication = _application.default.extend(); expectAssertion(function () { (0, _emberMetal.run)(function () { MyApplication.initializer({ name: 'initializer' }); }); }); expectAssertion(function () { (0, _emberMetal.run)(function () { MyApplication.initializer({ initialize: function () {} }); }); }); }); QUnit.test('initializers that throw errors cause the boot promise to reject with the error', function () { QUnit.expect(2); QUnit.stop(); var MyApplication = _application.default.extend(); MyApplication.initializer({ name: 'initializer', initialize: function () { throw new Error('boot failure'); } }); app = MyApplication.create({ autoboot: false }); try { app.boot().then(function () { QUnit.start(); ok(false, 'The boot promise should not resolve when there is a boot error'); }, function (err) { QUnit.start(); ok(err instanceof Error, 'The boot promise should reject with an error'); equal(err.message, 'boot failure'); }); } catch (e) { QUnit.start(); ok(false, 'The boot method should not throw'); throw e; } }); QUnit.test('initializers are passed an App', function () { var MyApplication = _application.default.extend(); MyApplication.initializer({ name: 'initializer', initialize: function (App) { ok(App instanceof _application.default, 'initialize is passed an Application'); } }); (0, _emberMetal.run)(function () { app = MyApplication.create({ router: false, rootElement: '#qunit-fixture' }); }); }); QUnit.test('initializers can be registered in a specified order', function () { var order = []; var MyApplication = _application.default.extend(); MyApplication.initializer({ name: 'fourth', after: 'third', initialize: function () { order.push('fourth'); } }); MyApplication.initializer({ name: 'second', after: 'first', before: 'third', initialize: function () { order.push('second'); } }); MyApplication.initializer({ name: 'fifth', after: 'fourth', before: 'sixth', initialize: function () { order.push('fifth'); } }); MyApplication.initializer({ name: 'first', before: 'second', initialize: function () { order.push('first'); } }); MyApplication.initializer({ name: 'third', initialize: function () { order.push('third'); } }); MyApplication.initializer({ name: 'sixth', initialize: function () { order.push('sixth'); } }); (0, _emberMetal.run)(function () { app = MyApplication.create({ router: false, rootElement: '#qunit-fixture' }); }); deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']); }); QUnit.test('initializers can be registered in a specified order as an array', function () { var order = []; var MyApplication = _application.default.extend(); MyApplication.initializer({ name: 'third', initialize: function () { order.push('third'); } }); MyApplication.initializer({ name: 'second', after: 'first', before: ['third', 'fourth'], initialize: function () { order.push('second'); } }); MyApplication.initializer({ name: 'fourth', after: ['second', 'third'], initialize: function () { order.push('fourth'); } }); MyApplication.initializer({ name: 'fifth', after: 'fourth', before: 'sixth', initialize: function () { order.push('fifth'); } }); MyApplication.initializer({ name: 'first', before: ['second'], initialize: function () { order.push('first'); } }); MyApplication.initializer({ name: 'sixth', initialize: function () { order.push('sixth'); } }); (0, _emberMetal.run)(function () { app = MyApplication.create({ router: false, rootElement: '#qunit-fixture' }); }); deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']); }); QUnit.test('initializers can have multiple dependencies', function () { var order = []; var a = { name: 'a', before: 'b', initialize: function () { order.push('a'); } }; var b = { name: 'b', initialize: function () { order.push('b'); } }; var c = { name: 'c', after: 'b', initialize: function () { order.push('c'); } }; var afterB = { name: 'after b', after: 'b', initialize: function () { order.push('after b'); } }; var afterC = { name: 'after c', after: 'c', initialize: function () { order.push('after c'); } }; _application.default.initializer(b); _application.default.initializer(a); _application.default.initializer(afterC); _application.default.initializer(afterB); _application.default.initializer(c); (0, _emberMetal.run)(function () { app = _application.default.create({ router: false, rootElement: '#qunit-fixture' }); }); ok(order.indexOf(a.name) < order.indexOf(b.name), 'a < b'); ok(order.indexOf(b.name) < order.indexOf(c.name), 'b < c'); ok(order.indexOf(b.name) < order.indexOf(afterB.name), 'b < afterB'); ok(order.indexOf(c.name) < order.indexOf(afterC.name), 'c < afterC'); }); QUnit.test('initializers set on Application subclasses are not shared between apps', function () { var firstInitializerRunCount = 0; var secondInitializerRunCount = 0; var FirstApp = _application.default.extend(); FirstApp.initializer({ name: 'first', initialize: function () { firstInitializerRunCount++; } }); var SecondApp = _application.default.extend(); SecondApp.initializer({ name: 'second', initialize: function () { secondInitializerRunCount++; } }); (0, _emberViews.jQuery)('#qunit-fixture').html('
'); var firstApp = (0, _emberMetal.run)(function () { return FirstApp.create({ router: false, rootElement: '#qunit-fixture #first' }); }); equal(firstInitializerRunCount, 1, 'first initializer only was run'); equal(secondInitializerRunCount, 0, 'first initializer only was run'); var secondApp = (0, _emberMetal.run)(function () { return SecondApp.create({ router: false, rootElement: '#qunit-fixture #second' }); }); equal(firstInitializerRunCount, 1, 'second initializer only was run'); equal(secondInitializerRunCount, 1, 'second initializer only was run'); (0, _emberMetal.run)(function () { firstApp.destroy(); secondApp.destroy(); }); }); QUnit.test('initializers are concatenated', function () { var firstInitializerRunCount = 0; var secondInitializerRunCount = 0; var FirstApp = _application.default.extend(); FirstApp.initializer({ name: 'first', initialize: function () { firstInitializerRunCount++; } }); var SecondApp = FirstApp.extend(); SecondApp.initializer({ name: 'second', initialize: function () { secondInitializerRunCount++; } }); (0, _emberViews.jQuery)('#qunit-fixture').html('
'); var firstApp = (0, _emberMetal.run)(function () { return FirstApp.create({ router: false, rootElement: '#qunit-fixture #first' }); }); equal(firstInitializerRunCount, 1, 'first initializer only was run when base class created'); equal(secondInitializerRunCount, 0, 'first initializer only was run when base class created'); firstInitializerRunCount = 0; var secondApp = (0, _emberMetal.run)(function () { return SecondApp.create({ router: false, rootElement: '#qunit-fixture #second' }); }); equal(firstInitializerRunCount, 1, 'first initializer was run when subclass created'); equal(secondInitializerRunCount, 1, 'second initializers was run when subclass created'); (0, _emberMetal.run)(function () { firstApp.destroy(); secondApp.destroy(); }); }); QUnit.test('initializers are per-app', function () { expect(2); var FirstApp = _application.default.extend(); FirstApp.initializer({ name: 'abc', initialize: function () {} }); expectAssertion(function () { FirstApp.initializer({ name: 'abc', initialize: function () {} }); }); var SecondApp = _application.default.extend(); SecondApp.instanceInitializer({ name: 'abc', initialize: function () {} }); ok(true, 'Two apps can have initializers named the same.'); }); QUnit.test('initializers are executed in their own context', function () { expect(1); var MyApplication = _application.default.extend(); MyApplication.initializer({ name: 'coolInitializer', myProperty: 'cool', initialize: function () { equal(this.myProperty, 'cool', 'should have access to its own context'); } }); (0, _emberMetal.run)(function () { app = MyApplication.create({ router: false, rootElement: '#qunit-fixture' }); }); }); QUnit.test('initializers throw a deprecation warning when receiving a second argument', function () { expect(1); var MyApplication = _application.default.extend(); MyApplication.initializer({ name: 'deprecated', initialize: function () {} }); expectDeprecation(function () { (0, _emberMetal.run)(function () { app = MyApplication.create({ router: false, rootElement: '#qunit-fixture' }); }); }, /The `initialize` method for Application initializer 'deprecated' should take only one argument - `App`, an instance of an `Application`./); }); }); enifed('ember-application/tests/system/instance_initializers_test', ['ember-metal', 'ember-application/system/application', 'ember-application/system/application-instance', 'ember-views'], function (_emberMetal, _application, _applicationInstance, _emberViews) { 'use strict'; var app = void 0; QUnit.module('Ember.Application instance initializers', { teardown: function () { if (app) { (0, _emberMetal.run)(function () { return app.destroy(); }); } } }); QUnit.test('initializers require proper \'name\' and \'initialize\' properties', function () { var MyApplication = _application.default.extend(); expectAssertion(function () { (0, _emberMetal.run)(function () { MyApplication.instanceInitializer({ name: 'initializer' }); }); }); expectAssertion(function () { (0, _emberMetal.run)(function () { MyApplication.instanceInitializer({ initialize: function () {} }); }); }); }); QUnit.test('initializers are passed an app instance', function () { var MyApplication = _application.default.extend(); MyApplication.instanceInitializer({ name: 'initializer', initialize: function (instance) { ok(instance instanceof _applicationInstance.default, 'initialize is passed an application instance'); } }); (0, _emberMetal.run)(function () { app = MyApplication.create({ router: false, rootElement: '#qunit-fixture' }); }); }); QUnit.test('initializers can be registered in a specified order', function () { var order = []; var MyApplication = _application.default.extend(); MyApplication.instanceInitializer({ name: 'fourth', after: 'third', initialize: function () { order.push('fourth'); } }); MyApplication.instanceInitializer({ name: 'second', after: 'first', before: 'third', initialize: function () { order.push('second'); } }); MyApplication.instanceInitializer({ name: 'fifth', after: 'fourth', before: 'sixth', initialize: function () { order.push('fifth'); } }); MyApplication.instanceInitializer({ name: 'first', before: 'second', initialize: function () { order.push('first'); } }); MyApplication.instanceInitializer({ name: 'third', initialize: function () { order.push('third'); } }); MyApplication.instanceInitializer({ name: 'sixth', initialize: function () { order.push('sixth'); } }); (0, _emberMetal.run)(function () { app = MyApplication.create({ router: false, rootElement: '#qunit-fixture' }); }); deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']); }); QUnit.test('initializers can be registered in a specified order as an array', function () { var order = []; var MyApplication = _application.default.extend(); MyApplication.instanceInitializer({ name: 'third', initialize: function () { order.push('third'); } }); MyApplication.instanceInitializer({ name: 'second', after: 'first', before: ['third', 'fourth'], initialize: function () { order.push('second'); } }); MyApplication.instanceInitializer({ name: 'fourth', after: ['second', 'third'], initialize: function () { order.push('fourth'); } }); MyApplication.instanceInitializer({ name: 'fifth', after: 'fourth', before: 'sixth', initialize: function () { order.push('fifth'); } }); MyApplication.instanceInitializer({ name: 'first', before: ['second'], initialize: function () { order.push('first'); } }); MyApplication.instanceInitializer({ name: 'sixth', initialize: function () { order.push('sixth'); } }); (0, _emberMetal.run)(function () { app = MyApplication.create({ router: false, rootElement: '#qunit-fixture' }); }); deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']); }); QUnit.test('initializers can have multiple dependencies', function () { var order = []; var a = { name: 'a', before: 'b', initialize: function () { order.push('a'); } }; var b = { name: 'b', initialize: function () { order.push('b'); } }; var c = { name: 'c', after: 'b', initialize: function () { order.push('c'); } }; var afterB = { name: 'after b', after: 'b', initialize: function () { order.push('after b'); } }; var afterC = { name: 'after c', after: 'c', initialize: function () { order.push('after c'); } }; _application.default.instanceInitializer(b); _application.default.instanceInitializer(a); _application.default.instanceInitializer(afterC); _application.default.instanceInitializer(afterB); _application.default.instanceInitializer(c); (0, _emberMetal.run)(function () { app = _application.default.create({ router: false, rootElement: '#qunit-fixture' }); }); ok(order.indexOf(a.name) < order.indexOf(b.name), 'a < b'); ok(order.indexOf(b.name) < order.indexOf(c.name), 'b < c'); ok(order.indexOf(b.name) < order.indexOf(afterB.name), 'b < afterB'); ok(order.indexOf(c.name) < order.indexOf(afterC.name), 'c < afterC'); }); QUnit.test('initializers set on Application subclasses should not be shared between apps', function () { var firstInitializerRunCount = 0; var secondInitializerRunCount = 0; var FirstApp = _application.default.extend(); var firstApp = void 0, secondApp = void 0; FirstApp.instanceInitializer({ name: 'first', initialize: function () { firstInitializerRunCount++; } }); var SecondApp = _application.default.extend(); SecondApp.instanceInitializer({ name: 'second', initialize: function () { secondInitializerRunCount++; } }); (0, _emberViews.jQuery)('#qunit-fixture').html('
'); (0, _emberMetal.run)(function () { firstApp = FirstApp.create({ router: false, rootElement: '#qunit-fixture #first' }); }); equal(firstInitializerRunCount, 1, 'first initializer only was run'); equal(secondInitializerRunCount, 0, 'first initializer only was run'); (0, _emberMetal.run)(function () { secondApp = SecondApp.create({ router: false, rootElement: '#qunit-fixture #second' }); }); equal(firstInitializerRunCount, 1, 'second initializer only was run'); equal(secondInitializerRunCount, 1, 'second initializer only was run'); (0, _emberMetal.run)(function () { firstApp.destroy(); secondApp.destroy(); }); }); QUnit.test('initializers are concatenated', function () { var firstInitializerRunCount = 0; var secondInitializerRunCount = 0; var FirstApp = _application.default.extend(); var firstApp = void 0, secondApp = void 0; FirstApp.instanceInitializer({ name: 'first', initialize: function () { firstInitializerRunCount++; } }); var SecondApp = FirstApp.extend(); SecondApp.instanceInitializer({ name: 'second', initialize: function () { secondInitializerRunCount++; } }); (0, _emberViews.jQuery)('#qunit-fixture').html('
'); (0, _emberMetal.run)(function () { firstApp = FirstApp.create({ router: false, rootElement: '#qunit-fixture #first' }); }); equal(firstInitializerRunCount, 1, 'first initializer only was run when base class created'); equal(secondInitializerRunCount, 0, 'first initializer only was run when base class created'); firstInitializerRunCount = 0; (0, _emberMetal.run)(function () { secondApp = SecondApp.create({ router: false, rootElement: '#qunit-fixture #second' }); }); equal(firstInitializerRunCount, 1, 'first initializer was run when subclass created'); equal(secondInitializerRunCount, 1, 'second initializers was run when subclass created'); (0, _emberMetal.run)(function () { firstApp.destroy(); secondApp.destroy(); }); }); QUnit.test('initializers are per-app', function () { expect(2); var FirstApp = _application.default.extend(); FirstApp.instanceInitializer({ name: 'abc', initialize: function () {} }); expectAssertion(function () { FirstApp.instanceInitializer({ name: 'abc', initialize: function () {} }); }); var SecondApp = _application.default.extend(); SecondApp.instanceInitializer({ name: 'abc', initialize: function () {} }); ok(true, 'Two apps can have initializers named the same.'); }); QUnit.test('initializers are run before ready hook', function () { expect(2); var readyWasCalled = false; var MyApplication = _application.default.extend({ ready: function () { ok(true, 'ready is called'); readyWasCalled = true; } }); MyApplication.instanceInitializer({ name: 'initializer', initialize: function () { ok(!readyWasCalled, 'ready is not yet called'); } }); (0, _emberMetal.run)(function () { app = MyApplication.create({ router: false, rootElement: '#qunit-fixture' }); }); }); QUnit.test('initializers are executed in their own context', function () { expect(1); var MyApplication = _application.default.extend(); MyApplication.instanceInitializer({ name: 'coolInitializer', myProperty: 'cool', initialize: function () { equal(this.myProperty, 'cool', 'should have access to its own context'); } }); (0, _emberMetal.run)(function () { app = MyApplication.create({ router: false, rootElement: '#qunit-fixture' }); }); }); QUnit.test('initializers get an instance on app reset', function () { expect(2); var MyApplication = _application.default.extend(); MyApplication.instanceInitializer({ name: 'giveMeAnInstance', initialize: function (instance) { ok(!!instance, 'Initializer got an instance'); } }); (0, _emberMetal.run)(function () { app = MyApplication.create({ router: false, rootElement: '#qunit-fixture' }); }); (0, _emberMetal.run)(app, 'reset'); }); }); enifed('ember-application/tests/system/logging_test', ['ember-console', 'ember-metal', 'ember-application/system/application', 'ember-runtime', 'ember-routing', 'ember-template-compiler'], function (_emberConsole, _emberMetal, _application, _emberRuntime, _emberRouting, _emberTemplateCompiler) { 'use strict'; /*globals EmberDev */ var App = void 0, logs = void 0, originalLogger = void 0; QUnit.module('Ember.Application – logging of generated classes', { setup: function () { logs = {}; originalLogger = _emberConsole.default.info; _emberConsole.default.info = function () { var fullName = arguments[1].fullName; logs[fullName] = logs[fullName] || 0; logs[fullName]++; }; (0, _emberMetal.run)(function () { App = _application.default.create({ LOG_ACTIVE_GENERATION: true }); App.Router.reopen({ location: 'none' }); App.Router.map(function () { this.route('posts', { resetNamespace: true }); }); App.deferReadiness(); }); }, teardown: function () { _emberConsole.default.info = originalLogger; (0, _emberMetal.run)(App, 'destroy'); logs = App = null; } }); function visit(path) { QUnit.stop(); var promise = (0, _emberMetal.run)(function () { return new _emberRuntime.RSVP.Promise(function (resolve) { var router = App.__container__.lookup('router:main'); resolve(router.handleURL(path).then(function (value) { QUnit.start(); ok(true, 'visited: `' + path + '`'); return value; }, function (reason) { QUnit.start(); ok(false, 'failed to visit:`' + path + '` reason: `' + QUnit.jsDump.parse(reason)); throw reason; })); }); }); return { then: function (resolve, reject) { (0, _emberMetal.run)(promise, 'then', resolve, reject); } }; } QUnit.test('log class generation if logging enabled', function () { if (EmberDev && EmberDev.runningProdBuild) { ok(true, 'Logging does not occur in production builds'); return; } (0, _emberMetal.run)(App, 'advanceReadiness'); visit('/posts').then(function () { equal(Object.keys(logs).length, 6, 'expected logs'); }); }); QUnit.test('do NOT log class generation if logging disabled', function () { App.reopen({ LOG_ACTIVE_GENERATION: false }); (0, _emberMetal.run)(App, 'advanceReadiness'); visit('/posts').then(function () { equal(Object.keys(logs).length, 0, 'expected no logs'); }); }); QUnit.test('actively generated classes get logged', function () { if (EmberDev && EmberDev.runningProdBuild) { ok(true, 'Logging does not occur in production builds'); return; } (0, _emberMetal.run)(App, 'advanceReadiness'); visit('/posts').then(function () { equal(logs['controller:application'], 1, 'expected: ApplicationController was generated'); equal(logs['controller:posts'], 1, 'expected: PostsController was generated'); equal(logs['route:application'], 1, 'expected: ApplicationRoute was generated'); equal(logs['route:posts'], 1, 'expected: PostsRoute was generated'); }); }); QUnit.test('predefined classes do not get logged', function () { App.ApplicationController = _emberRuntime.Controller.extend(); App.PostsController = _emberRuntime.Controller.extend(); App.ApplicationRoute = _emberRouting.Route.extend(); App.PostsRoute = _emberRouting.Route.extend(); (0, _emberMetal.run)(App, 'advanceReadiness'); visit('/posts').then(function () { ok(!logs['controller:application'], 'did not expect: ApplicationController was generated'); ok(!logs['controller:posts'], 'did not expect: PostsController was generated'); ok(!logs['route:application'], 'did not expect: ApplicationRoute was generated'); ok(!logs['route:posts'], 'did not expect: PostsRoute was generated'); }); }); QUnit.module('Ember.Application – logging of view lookups', { setup: function () { logs = {}; originalLogger = _emberConsole.default.info; _emberConsole.default.info = function () { var fullName = arguments[1].fullName; logs[fullName] = logs[fullName] || 0; logs[fullName]++; }; (0, _emberMetal.run)(function () { App = _application.default.create({ LOG_VIEW_LOOKUPS: true }); App.Router.reopen({ location: 'none' }); App.Router.map(function () { this.route('posts', { resetNamespace: true }); }); App.deferReadiness(); }); }, teardown: function () { _emberConsole.default.info = originalLogger; (0, _emberMetal.run)(App, 'destroy'); logs = App = null; } }); QUnit.test('log when template and view are missing when flag is active', function () { if (EmberDev && EmberDev.runningProdBuild) { ok(true, 'Logging does not occur in production builds'); return; } App.register('template:application', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberMetal.run)(App, 'advanceReadiness'); visit('/posts').then(function () { equal(logs['template:application'], undefined, 'expected: Should not log template:application since it exists.'); equal(logs['template:index'], 1, 'expected: Could not find "index" template or view.'); equal(logs['template:posts'], 1, 'expected: Could not find "posts" template or view.'); }); }); QUnit.test('do not log when template and view are missing when flag is not true', function () { App.reopen({ LOG_VIEW_LOOKUPS: false }); (0, _emberMetal.run)(App, 'advanceReadiness'); visit('/posts').then(function () { equal(Object.keys(logs).length, 0, 'expected no logs'); }); }); QUnit.test('do not log which views are used with templates when flag is not true', function () { App.reopen({ LOG_VIEW_LOOKUPS: false }); (0, _emberMetal.run)(App, 'advanceReadiness'); visit('/posts').then(function () { equal(Object.keys(logs).length, 0, 'expected no logs'); }); }); }); enifed('ember-application/tests/system/readiness_test', ['ember-metal', 'ember-application/system/application'], function (_emberMetal, _application) { 'use strict'; var jQuery = void 0, application = void 0, Application = void 0; var readyWasCalled = void 0, domReady = void 0, readyCallbacks = void 0; // We are using a small mock of jQuery because jQuery is third-party code with // very well-defined semantics, and we want to confirm that a jQuery stub run // in a more minimal server environment that implements this behavior will be // sufficient for Ember's requirements. QUnit.module('Application readiness', { setup: function () { readyWasCalled = 0; readyCallbacks = []; var jQueryInstance = { ready: function (callback) { readyCallbacks.push(callback); if (jQuery.isReady) { domReady(); } } }; jQuery = function () { return jQueryInstance; }; jQuery.isReady = false; var domReadyCalled = 0; domReady = function () { var i; if (domReadyCalled !== 0) { return; } domReadyCalled++; for (i = 0; i < readyCallbacks.length; i++) { readyCallbacks[i](); } }; Application = _application.default.extend({ $: jQuery, ready: function () { readyWasCalled++; } }); }, teardown: function () { if (application) { (0, _emberMetal.run)(function () { return application.destroy(); }); } } }); // These tests are confirming that if the callbacks passed into jQuery's ready hook is called // synchronously during the application's initialization, we get the same behavior as if // it was triggered after initialization. QUnit.test('Ember.Application\'s ready event is called right away if jQuery is already ready', function () { jQuery.isReady = true; (0, _emberMetal.run)(function () { application = Application.create({ router: false }); equal(readyWasCalled, 0, 'ready is not called until later'); }); equal(readyWasCalled, 1, 'ready was called'); domReady(); equal(readyWasCalled, 1, 'application\'s ready was not called again'); }); QUnit.test('Ember.Application\'s ready event is called after the document becomes ready', function () { (0, _emberMetal.run)(function () { application = Application.create({ router: false }); }); equal(readyWasCalled, 0, 'ready wasn\'t called yet'); domReady(); equal(readyWasCalled, 1, 'ready was called now that DOM is ready'); }); QUnit.test('Ember.Application\'s ready event can be deferred by other components', function () { (0, _emberMetal.run)(function () { application = Application.create({ router: false }); application.deferReadiness(); }); equal(readyWasCalled, 0, 'ready wasn\'t called yet'); domReady(); equal(readyWasCalled, 0, 'ready wasn\'t called yet'); (0, _emberMetal.run)(function () { application.advanceReadiness(); equal(readyWasCalled, 0); }); equal(readyWasCalled, 1, 'ready was called now all readiness deferrals are advanced'); }); QUnit.test('Ember.Application\'s ready event can be deferred by other components', function () { jQuery.isReady = false; (0, _emberMetal.run)(function () { application = Application.create({ router: false }); application.deferReadiness(); equal(readyWasCalled, 0, 'ready wasn\'t called yet'); }); domReady(); equal(readyWasCalled, 0, 'ready wasn\'t called yet'); (0, _emberMetal.run)(function () { application.advanceReadiness(); }); equal(readyWasCalled, 1, 'ready was called now all readiness deferrals are advanced'); expectAssertion(function () { application.deferReadiness(); }); }); }); enifed('ember-application/tests/system/reset_test', ['ember-metal', 'ember-application/system/application', 'ember-runtime', 'ember-routing', 'container'], function (_emberMetal, _application, _emberRuntime, _emberRouting, _container) { 'use strict'; var application = void 0, Application = void 0; QUnit.module('Ember.Application - resetting', { setup: function () { Application = _application.default.extend({ name: 'App', rootElement: '#qunit-fixture' }); }, teardown: function () { Application = null; if (application) { (0, _emberMetal.run)(application, 'destroy'); } } }); QUnit.test('Brings its own run-loop if not provided', function () { application = (0, _emberMetal.run)(Application, 'create'); application.ready = function () { QUnit.start(); ok(true, 'app booted'); }; QUnit.stop(); application.reset(); }); QUnit.test('Does not bring its own run loop if one is already provided', function () { expect(3); var didBecomeReady = false; application = (0, _emberMetal.run)(Application, 'create'); (0, _emberMetal.run)(function () { application.ready = function () { didBecomeReady = true; }; application.reset(); application.deferReadiness(); ok(!didBecomeReady, 'app is not ready'); }); ok(!didBecomeReady, 'app is not ready'); (0, _emberMetal.run)(application, 'advanceReadiness'); ok(didBecomeReady, 'app is ready'); }); QUnit.test('When an application is reset, new instances of controllers are generated', function () { (0, _emberMetal.run)(function () { application = Application.create(); application.AcademicController = _emberRuntime.Controller.extend(); }); var firstController = application.__container__.lookup('controller:academic'); var secondController = application.__container__.lookup('controller:academic'); application.reset(); var thirdController = application.__container__.lookup('controller:academic'); strictEqual(firstController, secondController, 'controllers looked up in succession should be the same instance'); ok(firstController.isDestroying, 'controllers are destroyed when their application is reset'); notStrictEqual(firstController, thirdController, 'controllers looked up after the application is reset should not be the same instance'); }); QUnit.test('When an application is reset, the eventDispatcher is destroyed and recreated', function () { var eventDispatcherWasSetup = void 0, eventDispatcherWasDestroyed = void 0; eventDispatcherWasSetup = 0; eventDispatcherWasDestroyed = 0; var mock_event_dispatcher = { create: function () { return { setup: function () { eventDispatcherWasSetup++; }, destroy: function () { eventDispatcherWasDestroyed++; } }; } }; // this is pretty awful. We should make this less Global-ly. var originalRegister = _container.Registry.prototype.register; _container.Registry.prototype.register = function (name, type, options) { if (name === 'event_dispatcher:main') { return mock_event_dispatcher; } else { return originalRegister.call(this, name, type, options); } }; try { (0, _emberMetal.run)(function () { application = Application.create(); equal(eventDispatcherWasSetup, 0); equal(eventDispatcherWasDestroyed, 0); }); equal(eventDispatcherWasSetup, 1); equal(eventDispatcherWasDestroyed, 0); application.reset(); equal(eventDispatcherWasDestroyed, 1); equal(eventDispatcherWasSetup, 2, 'setup called after reset'); } catch (error) { _container.Registry.prototype.register = originalRegister; } _container.Registry.prototype.register = originalRegister; }); QUnit.test('When an application is reset, the router URL is reset to `/`', function () { var location = void 0, router = void 0; (0, _emberMetal.run)(function () { application = Application.create(); application.Router = _emberRouting.Router.extend({ location: 'none' }); application.Router.map(function () { this.route('one'); this.route('two'); }); }); router = application.__container__.lookup('router:main'); location = router.get('location'); (0, _emberMetal.run)(function () { location.handleURL('/one'); }); application.reset(); var applicationController = application.__container__.lookup('controller:application'); router = application.__container__.lookup('router:main'); location = router.get('location'); equal(location.getURL(), ''); equal((0, _emberMetal.get)(applicationController, 'currentPath'), 'index'); location = application.__container__.lookup('router:main').get('location'); (0, _emberMetal.run)(function () { location.handleURL('/one'); }); equal((0, _emberMetal.get)(applicationController, 'currentPath'), 'one'); }); QUnit.test('When an application with advance/deferReadiness is reset, the app does correctly become ready after reset', function () { var readyCallCount = 0; (0, _emberMetal.run)(function () { application = Application.create({ ready: function () { readyCallCount++; } }); application.deferReadiness(); equal(readyCallCount, 0, 'ready has not yet been called'); }); (0, _emberMetal.run)(function () { application.advanceReadiness(); }); equal(readyCallCount, 1, 'ready was called once'); application.reset(); equal(readyCallCount, 2, 'ready was called twice'); }); QUnit.test('With ember-data like initializer and constant', function () { var DS = { Store: _emberRuntime.Object.extend({ init: function () { if (!(0, _emberMetal.get)(DS, 'defaultStore')) { (0, _emberMetal.set)(DS, 'defaultStore', this); } this._super.apply(this, arguments); }, willDestroy: function () { if ((0, _emberMetal.get)(DS, 'defaultStore') === this) { (0, _emberMetal.set)(DS, 'defaultStore', null); } } }) }; Application.initializer({ name: 'store', initialize: function (application) { application.unregister('store:main'); application.register('store:main', application.Store); application.__container__.lookup('store:main'); } }); (0, _emberMetal.run)(function () { application = Application.create(); application.Store = DS.Store; }); ok(DS.defaultStore, 'has defaultStore'); application.reset(); ok(DS.defaultStore, 'still has defaultStore'); ok(application.__container__.lookup('store:main'), 'store is still present'); }); }); enifed('ember-application/tests/system/visit_test', ['ember-runtime', 'ember-metal', 'ember-application/system/application', 'ember-application/system/application-instance', 'ember-application/system/engine', 'ember-routing', 'ember-glimmer', 'ember-template-compiler', 'ember-views'], function (_emberRuntime, _emberMetal, _application, _applicationInstance, _engine, _emberRouting, _emberGlimmer, _emberTemplateCompiler, _emberViews) { 'use strict'; var App = null; var instance = null; var instances = []; function createApplication(integration) { App = _application.default.extend().create({ autoboot: false, rootElement: '#qunit-fixture', LOG_TRANSITIONS: true, LOG_TRANSITIONS_INTERNAL: true, LOG_ACTIVE_GENERATION: true }); App.Router = _emberRouting.Router.extend({ location: 'none' }); if (integration) { App.instanceInitializer({ name: 'auto-cleanup', initialize: function (_instance) { instances.push(_instance); } }); } else { App.instanceInitializer({ name: 'auto-cleanup', initialize: function (_instance) { if (instance) { (0, _emberMetal.run)(instance, 'destroy'); } instance = _instance; } }); } return App; } function expectAsyncError() { _emberRuntime.RSVP.off('error'); } QUnit.module('Ember.Application - visit()', { teardown: function () { _emberRuntime.RSVP.on('error', _emberRuntime.onerrorDefault); if (instance) { (0, _emberMetal.run)(instance, 'destroy'); instance = null; } if (App) { (0, _emberMetal.run)(App, 'destroy'); App = null; } } }); // This tests whether the application is "autobooted" by registering an // instance initializer and asserting it never gets run. Since this is // inherently testing that async behavior *doesn't* happen, we set a // 500ms timeout to verify that when autoboot is set to false, the // instance initializer that would normally get called on DOM ready // does not fire. QUnit.test('Applications with autoboot set to false do not autoboot', function (assert) { var appBooted = 0; var instanceBooted = 0; (0, _emberMetal.run)(function () { createApplication(); App.initializer({ name: 'assert-no-autoboot', initialize: function () { appBooted++; } }); App.instanceInitializer({ name: 'assert-no-autoboot', initialize: function () { instanceBooted++; } }); }); // Continue after 500ms return function (time) { return new _emberRuntime.RSVP.Promise(function (resolve) { return _emberMetal.run.later(resolve, time); }); }(500).then(function () { assert.ok(appBooted === 0, '500ms elapsed without app being booted'); assert.ok(instanceBooted === 0, '500ms elapsed without instances being booted'); return (0, _emberMetal.run)(App, 'boot'); }).then(function () { assert.ok(appBooted === 1, 'app should boot when manually calling `app.boot()`'); assert.ok(instanceBooted === 0, 'no instances should be booted automatically when manually calling `app.boot()'); }); }); QUnit.test('calling visit() on an app without first calling boot() should boot the app', function (assert) { var appBooted = 0; var instanceBooted = 0; (0, _emberMetal.run)(function () { createApplication(); App.initializer({ name: 'assert-no-autoboot', initialize: function () { appBooted++; } }); App.instanceInitializer({ name: 'assert-no-autoboot', initialize: function () { instanceBooted++; } }); }); return (0, _emberMetal.run)(App, 'visit', '/').then(function () { assert.ok(appBooted === 1, 'the app should be booted`'); assert.ok(instanceBooted === 1, 'an instances should be booted'); }); }); QUnit.test('calling visit() on an already booted app should not boot it again', function (assert) { var appBooted = 0; var instanceBooted = 0; (0, _emberMetal.run)(function () { createApplication(); App.initializer({ name: 'assert-no-autoboot', initialize: function () { appBooted++; } }); App.instanceInitializer({ name: 'assert-no-autoboot', initialize: function () { instanceBooted++; } }); }); return (0, _emberMetal.run)(App, 'boot').then(function () { assert.ok(appBooted === 1, 'the app should be booted'); assert.ok(instanceBooted === 0, 'no instances should be booted'); return (0, _emberMetal.run)(App, 'visit', '/'); }).then(function () { assert.ok(appBooted === 1, 'the app should not be booted again'); assert.ok(instanceBooted === 1, 'an instance should be booted'); return (0, _emberMetal.run)(App, 'visit', '/'); }).then(function () { assert.ok(appBooted === 1, 'the app should not be booted again'); assert.ok(instanceBooted === 2, 'another instance should be booted'); }); }); QUnit.test('visit() rejects on application boot failure', function (assert) { (0, _emberMetal.run)(function () { createApplication(); App.initializer({ name: 'error', initialize: function () { throw new Error('boot failure'); } }); }); expectAsyncError(); return (0, _emberMetal.run)(App, 'visit', '/').then(function () { assert.ok(false, 'It should not resolve the promise'); }, function (error) { assert.ok(error instanceof Error, 'It should reject the promise with the boot error'); assert.equal(error.message, 'boot failure'); }); }); QUnit.test('visit() rejects on instance boot failure', function (assert) { (0, _emberMetal.run)(function () { createApplication(); App.instanceInitializer({ name: 'error', initialize: function () { throw new Error('boot failure'); } }); }); expectAsyncError(); return (0, _emberMetal.run)(App, 'visit', '/').then(function () { assert.ok(false, 'It should not resolve the promise'); }, function (error) { assert.ok(error instanceof Error, 'It should reject the promise with the boot error'); assert.equal(error.message, 'boot failure'); }); }); QUnit.test('visit() follows redirects', function (assert) { (0, _emberMetal.run)(function () { createApplication(); App.Router.map(function () { this.route('a'); this.route('b', { path: '/b/:b' }); this.route('c', { path: '/c/:c' }); }); App.register('route:a', _emberRouting.Route.extend({ afterModel: function () { this.replaceWith('b', 'zomg'); } })); App.register('route:b', _emberRouting.Route.extend({ afterModel: function (params) { this.transitionTo('c', params.b); } })); }); return (0, _emberMetal.run)(App, 'visit', '/a').then(function (instance) { assert.ok(instance instanceof _applicationInstance.default, 'promise is resolved with an ApplicationInstance'); assert.equal(instance.getURL(), '/c/zomg', 'It should follow all redirects'); }); }); QUnit.test('visit() rejects if an error occurred during a transition', function (assert) { (0, _emberMetal.run)(function () { createApplication(); App.Router.map(function () { this.route('a'); this.route('b', { path: '/b/:b' }); this.route('c', { path: '/c/:c' }); }); App.register('route:a', _emberRouting.Route.extend({ afterModel: function () { this.replaceWith('b', 'zomg'); } })); App.register('route:b', _emberRouting.Route.extend({ afterModel: function (params) { this.transitionTo('c', params.b); } })); App.register('route:c', _emberRouting.Route.extend({ afterModel: function () { throw new Error('transition failure'); } })); }); expectAsyncError(); return (0, _emberMetal.run)(App, 'visit', '/a').then(function () { assert.ok(false, 'It should not resolve the promise'); }, function (error) { assert.ok(error instanceof Error, 'It should reject the promise with the boot error'); assert.equal(error.message, 'transition failure'); }); }); QUnit.test('visit() chain', function (assert) { (0, _emberMetal.run)(function () { createApplication(); App.Router.map(function () { this.route('a'); this.route('b'); this.route('c'); }); }); return (0, _emberMetal.run)(App, 'visit', '/').then(function (instance) { assert.ok(instance instanceof _applicationInstance.default, 'promise is resolved with an ApplicationInstance'); assert.equal(instance.getURL(), '/'); return instance.visit('/a'); }).then(function (instance) { assert.ok(instance instanceof _applicationInstance.default, 'promise is resolved with an ApplicationInstance'); assert.equal(instance.getURL(), '/a'); return instance.visit('/b'); }).then(function (instance) { assert.ok(instance instanceof _applicationInstance.default, 'promise is resolved with an ApplicationInstance'); assert.equal(instance.getURL(), '/b'); return instance.visit('/c'); }).then(function (instance) { assert.ok(instance instanceof _applicationInstance.default, 'promise is resolved with an ApplicationInstance'); assert.equal(instance.getURL(), '/c'); }); }); QUnit.test('visit() returns a promise that resolves when the view has rendered', function (assert) { (0, _emberMetal.run)(function () { createApplication(); App.register('template:application', (0, _emberTemplateCompiler.compile)('

Hello world

')); }); assert.strictEqual((0, _emberViews.jQuery)('#qunit-fixture').children().length, 0, 'there are no elements in the fixture element'); return (0, _emberMetal.run)(App, 'visit', '/').then(function (instance) { assert.ok(instance instanceof _applicationInstance.default, 'promise is resolved with an ApplicationInstance'); assert.equal((0, _emberViews.jQuery)('#qunit-fixture > .ember-view h1').text(), 'Hello world', 'the application was rendered once the promise resolves'); }); }); QUnit.test('visit() returns a promise that resolves without rendering when shouldRender is set to false', function (assert) { assert.expect(3); (0, _emberMetal.run)(function () { createApplication(); App.register('template:application', (0, _emberTemplateCompiler.compile)('

Hello world

')); }); assert.strictEqual((0, _emberViews.jQuery)('#qunit-fixture').children().length, 0, 'there are no elements in the fixture element'); return (0, _emberMetal.run)(App, 'visit', '/', { shouldRender: false }).then(function (instance) { assert.ok(instance instanceof _applicationInstance.default, 'promise is resolved with an ApplicationInstance'); assert.strictEqual((0, _emberViews.jQuery)('#qunit-fixture').children().length, 0, 'there are still no elements in the fixture element after visit'); }); }); QUnit.test('visit() renders a template when shouldRender is set to true', function (assert) { assert.expect(3); (0, _emberMetal.run)(function () { createApplication(); App.register('template:application', (0, _emberTemplateCompiler.compile)('

Hello world

')); }); assert.strictEqual((0, _emberViews.jQuery)('#qunit-fixture').children().length, 0, 'there are no elements in the fixture element'); return (0, _emberMetal.run)(App, 'visit', '/', { shouldRender: true }).then(function (instance) { assert.ok(instance instanceof _applicationInstance.default, 'promise is resolved with an ApplicationInstance'); assert.strictEqual((0, _emberViews.jQuery)('#qunit-fixture').children().length, 1, 'there is 1 element in the fixture element after visit'); }); }); QUnit.test('visit() returns a promise that resolves without rendering when shouldRender is set to false with Engines', function (assert) { assert.expect(3); (0, _emberMetal.run)(function () { createApplication(); App.register('template:application', (0, _emberTemplateCompiler.compile)('

Hello world

')); // Register engine var BlogEngine = _engine.default.extend(); App.register('engine:blog', BlogEngine); // Register engine route map App.register('route-map:blog', function () {}); App.Router.map(function () { this.mount('blog'); }); }); assert.strictEqual((0, _emberViews.jQuery)('#qunit-fixture').children().length, 0, 'there are no elements in the fixture element'); return (0, _emberMetal.run)(App, 'visit', '/blog', { shouldRender: false }).then(function (instance) { assert.ok(instance instanceof _applicationInstance.default, 'promise is resolved with an ApplicationInstance'); assert.strictEqual((0, _emberViews.jQuery)('#qunit-fixture').children().length, 0, 'there are still no elements in the fixture element after visit'); }); }); QUnit.test('visit() on engine resolves engine component', function (assert) { assert.expect(2); (0, _emberMetal.run)(function () { createApplication(); // Register engine var BlogEngine = _engine.default.extend({ init: function () { var _len, args, _key; for (_len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } this._super.apply(this, args); this.register('template:application', (0, _emberTemplateCompiler.compile)('{{cache-money}}')); this.register('template:components/cache-money', (0, _emberTemplateCompiler.compile)('\n

Dis cache money

\n ')); this.register('component:cache-money', _emberGlimmer.Component.extend({})); } }); App.register('engine:blog', BlogEngine); // Register engine route map App.register('route-map:blog', function () {}); App.Router.map(function () { this.mount('blog'); }); }); assert.strictEqual((0, _emberViews.jQuery)('#qunit-fixture').children().length, 0, 'there are no elements in the fixture element'); return (0, _emberMetal.run)(App, 'visit', '/blog', { shouldRender: true }).then(function () { assert.strictEqual((0, _emberViews.jQuery)('#qunit-fixture').find('p').text(), 'Dis cache money', 'Engine component is resolved'); }); }); QUnit.test('visit() on engine resolves engine helper', function (assert) { assert.expect(2); (0, _emberMetal.run)(function () { createApplication(); // Register engine var BlogEngine = _engine.default.extend({ init: function () { var _len2, args, _key2; for (_len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } this._super.apply(this, args); this.register('template:application', (0, _emberTemplateCompiler.compile)('{{swag}}')); this.register('helper:swag', (0, _emberGlimmer.helper)(function () { return 'turnt up'; })); } }); App.register('engine:blog', BlogEngine); // Register engine route map App.register('route-map:blog', function () {}); App.Router.map(function () { this.mount('blog'); }); }); assert.strictEqual((0, _emberViews.jQuery)('#qunit-fixture').children().length, 0, 'there are no elements in the fixture element'); return (0, _emberMetal.run)(App, 'visit', '/blog', { shouldRender: true }).then(function () { assert.strictEqual((0, _emberViews.jQuery)('#qunit-fixture').text(), 'turnt up', 'Engine component is resolved'); }); }); QUnit.module('Ember.Application - visit() Integration Tests', { teardown: function () { if (instances) { (0, _emberMetal.run)(instances, 'forEach', function (i) { return i.destroy(); }); instances = []; } if (App) { (0, _emberMetal.run)(App, 'destroy'); App = null; } } }); QUnit.test('Ember Islands-style setup', function (assert) { var xFooInitCalled = false; var xFooDidInsertElementCalled = false; var xBarInitCalled = false; var xBarDidInsertElementCalled = false; (0, _emberMetal.run)(function () { createApplication(true); App.Router.map(function () { this.route('show', { path: '/:component_name' }); }); App.register('route:show', _emberRouting.Route.extend({ queryParams: { data: { refreshModel: true } }, model: function (params) { return { componentName: params.component_name, componentData: params.data ? JSON.parse(params.data) : undefined }; } })); var Counter = _emberRuntime.Object.extend({ value: 0, increment: function () { this.incrementProperty('value'); } }); App.register('service:isolated-counter', Counter); App.register('service:shared-counter', Counter.create(), { instantiate: false }); App.register('template:show', (0, _emberTemplateCompiler.compile)('{{component model.componentName model=model.componentData}}')); App.register('template:components/x-foo', (0, _emberTemplateCompiler.compile)('\n

X-Foo

\n

Hello {{model.name}}, I have been clicked {{isolatedCounter.value}} times ({{sharedCounter.value}} times combined)!

\n ')); App.register('component:x-foo', _emberGlimmer.Component.extend({ tagName: 'x-foo', isolatedCounter: _emberRuntime.inject.service(), sharedCounter: _emberRuntime.inject.service(), init: function () { this._super(); xFooInitCalled = true; }, didInsertElement: function () { xFooDidInsertElementCalled = true; }, click: function () { this.get('isolatedCounter').increment(); this.get('sharedCounter').increment(); } })); App.register('template:components/x-bar', (0, _emberTemplateCompiler.compile)('\n

X-Bar

\n \n ')); App.register('component:x-bar', _emberGlimmer.Component.extend({ counter: _emberRuntime.inject.service('shared-counter'), actions: { incrementCounter: function () { this.get('counter').increment(); } }, init: function () { this._super(); xBarInitCalled = true; }, didInsertElement: function () { xBarDidInsertElementCalled = true; } })); }); var $foo = (0, _emberViews.jQuery)('
').appendTo('#qunit-fixture'); var $bar = (0, _emberViews.jQuery)('
').appendTo('#qunit-fixture'); var data = encodeURIComponent(JSON.stringify({ name: 'Godfrey' })); return _emberRuntime.RSVP.all([(0, _emberMetal.run)(App, 'visit', '/x-foo?data=' + data, { rootElement: $foo[0] }), (0, _emberMetal.run)(App, 'visit', '/x-bar', { rootElement: $bar[0] })]).then(function () { assert.ok(xFooInitCalled); assert.ok(xFooDidInsertElementCalled); assert.ok(xBarInitCalled); assert.ok(xBarDidInsertElementCalled); assert.equal($foo.find('h1').text(), 'X-Foo'); assert.equal($foo.find('p').text(), 'Hello Godfrey, I have been clicked 0 times (0 times combined)!'); assert.ok($foo.text().indexOf('X-Bar') === -1); assert.equal($bar.find('h1').text(), 'X-Bar'); assert.equal($bar.find('button').text(), 'Join 0 others in clicking me!'); assert.ok($bar.text().indexOf('X-Foo') === -1); (0, _emberMetal.run)(function () { return $foo.find('x-foo').click(); }); assert.equal($foo.find('p').text(), 'Hello Godfrey, I have been clicked 1 times (1 times combined)!'); assert.equal($bar.find('button').text(), 'Join 1 others in clicking me!'); (0, _emberMetal.run)(function () { $bar.find('button').click(); $bar.find('button').click(); }); assert.equal($foo.find('p').text(), 'Hello Godfrey, I have been clicked 1 times (3 times combined)!'); assert.equal($bar.find('button').text(), 'Join 3 others in clicking me!'); }); }); QUnit.skip('Test setup', function () {}); QUnit.skip('iframe setup', function () {}); }); enifed('ember-application/tests/test-helpers/registry-check', ['exports'], function (exports) { 'use strict'; exports.verifyRegistration = function (owner, fullName) { ok(owner.resolveRegistration(fullName), 'has registration: ' + fullName); }; exports.verifyInjection = function (owner, fullName, property, injectionName) { var registry = owner.__registry__, i, l; var injections = void 0; if (fullName.indexOf(':') === -1) { injections = registry.getTypeInjections(fullName); } else { injections = registry.getInjections(registry.normalize(fullName)); } var normalizedName = registry.normalize(injectionName); var hasInjection = false; var injection = void 0; for (i = 0, l = injections.length; i < l; i++) { injection = injections[i]; if (injection.property === property && injection.fullName === normalizedName) { hasInjection = true; break; } } ok(hasInjection, 'has injection: ' + fullName + '.' + property + ' = ' + injectionName); }; }); enifed('ember-babel', ['exports'], function (exports) { 'use strict'; exports.inherits = inherits; exports.taggedTemplateLiteralLoose = taggedTemplateLiteralLoose; exports.createClass = createClass; exports.defaults = defaults; function inherits(subClass, superClass) { subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : defaults(subClass, superClass); } function taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; } function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function createClass(Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; } function defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } var possibleConstructorReturn = exports.possibleConstructorReturn = function (self, call) { return call && (typeof call === 'object' || typeof call === 'function') ? call : self; }; var slice = exports.slice = Array.prototype.slice; }); enifed('ember-debug/tests/error_test', ['ember-debug/error'], function (_error) { 'use strict'; QUnit.module('Ember Error Throwing'); QUnit.test('new Ember.Error displays provided message', function () { throws(function () { throw new _error.default('A Message'); }, function (e) { return e.message === 'A Message'; }, 'the assigned message was displayed'); }); }); enifed('ember-debug/tests/handlers-test', ['ember-debug/handlers'], function (_handlers) { 'use strict'; QUnit.module('ember-debug/handlers', { teardown: function () { delete _handlers.HANDLERS.blarz; } }); QUnit.test('calls handler on `invoke` when `falsey`', function (assert) { assert.expect(2); (0, _handlers.registerHandler)('blarz', function (message) { assert.ok(true, 'called handler'); assert.equal(message, 'Foo bar'); }); (0, _handlers.invoke)('blarz', 'Foo bar', false); }); QUnit.test('does not call handler on `invoke` when `truthy`', function (assert) { assert.expect(0); (0, _handlers.registerHandler)('blarz', function () { assert.ok(false, 'called handler'); }); (0, _handlers.invoke)('blarz', 'Foo bar', true); }); QUnit.test('calling `invoke` without handlers does not throw an error', function (assert) { assert.expect(0); (0, _handlers.invoke)('blarz', 'Foo bar', false); }); QUnit.test('invoking `next` argument calls the next handler', function (assert) { assert.expect(2); (0, _handlers.registerHandler)('blarz', function () { assert.ok(true, 'called handler1'); }); (0, _handlers.registerHandler)('blarz', function (message, options, next) { assert.ok(true, 'called handler2'); next(message, options); }); (0, _handlers.invoke)('blarz', 'Foo', false); }); QUnit.test('invoking `next` when no other handlers exists does not error', function (assert) { assert.expect(1); (0, _handlers.registerHandler)('blarz', function (message, options, next) { assert.ok(true, 'called handler1'); next(message, options); }); (0, _handlers.invoke)('blarz', 'Foo', false); }); QUnit.test('handlers are called in the proper order', function (assert) { assert.expect(11); var expectedMessage = 'This is the message'; var expectedOptions = { id: 'foo-bar' }; var expected = ['first', 'second', 'third', 'fourth', 'fifth']; var actualCalls = []; function generateHandler(item) { return function (message, options, next) { assert.equal(message, expectedMessage, 'message supplied to ' + item + ' handler is correct'); assert.equal(options, expectedOptions, 'options supplied to ' + item + ' handler is correct'); actualCalls.push(item); next(message, options); }; } expected.forEach(function (item) { return (0, _handlers.registerHandler)('blarz', generateHandler(item)); }); (0, _handlers.invoke)('blarz', expectedMessage, false, expectedOptions); assert.deepEqual(actualCalls, expected.reverse(), 'handlers were called in proper order'); }); QUnit.test('not invoking `next` prevents further handlers from being called', function (assert) { assert.expect(1); (0, _handlers.registerHandler)('blarz', function () { assert.ok(false, 'called handler1'); }); (0, _handlers.registerHandler)('blarz', function () { assert.ok(true, 'called handler2'); }); (0, _handlers.invoke)('blarz', 'Foo', false); }); QUnit.test('handlers can call `next` with custom message and/or options', function (assert) { assert.expect(4); var initialMessage = 'initial message'; var initialOptions = { id: 'initial-options' }; var handler2Message = 'Handler2 Message'; var handler2Options = { id: 'handler-2' }; (0, _handlers.registerHandler)('blarz', function (message, options) { assert.equal(message, handler2Message, 'handler2 message provided to handler1'); assert.equal(options, handler2Options, 'handler2 options provided to handler1'); }); (0, _handlers.registerHandler)('blarz', function (message, options, next) { assert.equal(message, initialMessage, 'initial message provided to handler2'); assert.equal(options, initialOptions, 'initial options proivided to handler2'); next(handler2Message, handler2Options); }); (0, _handlers.invoke)('blarz', initialMessage, false, initialOptions); }); }); enifed('ember-debug/tests/main_test', ['ember-environment', 'ember-runtime', 'ember-debug/handlers', 'ember-debug/deprecate', 'ember-debug/warn', 'ember-debug/index'], function (_emberEnvironment, _emberRuntime, _handlers, _deprecate, _warn, _index) { 'use strict'; var originalEnvValue = void 0; var originalDeprecateHandler = void 0; QUnit.module('ember-debug', { setup: function () { originalEnvValue = _emberEnvironment.ENV.RAISE_ON_DEPRECATION; originalDeprecateHandler = _handlers.HANDLERS.deprecate; _emberEnvironment.ENV.RAISE_ON_DEPRECATION = true; }, teardown: function () { _handlers.HANDLERS.deprecate = originalDeprecateHandler; _emberEnvironment.ENV.RAISE_ON_DEPRECATION = originalEnvValue; } }); QUnit.test('Ember.deprecate does not throw if RAISE_ON_DEPRECATION is false', function (assert) { assert.expect(1); _emberEnvironment.ENV.RAISE_ON_DEPRECATION = false; try { (0, _index.deprecate)('Should not throw', false, { id: 'test', until: 'forever' }); assert.ok(true, 'Ember.deprecate did not throw'); } catch (e) { assert.ok(false, 'Expected deprecate not to throw but it did: ' + e.message); } }); QUnit.test('Ember.deprecate resets deprecation level to RAISE if ENV.RAISE_ON_DEPRECATION is set', function (assert) { assert.expect(2); _emberEnvironment.ENV.RAISE_ON_DEPRECATION = false; try { (0, _index.deprecate)('Should not throw', false, { id: 'test', until: 'forever' }); assert.ok(true, 'Ember.deprecate did not throw'); } catch (e) { assert.ok(false, 'Expected deprecate not to throw but it did: ' + e.message); } _emberEnvironment.ENV.RAISE_ON_DEPRECATION = true; assert.throws(function () { (0, _index.deprecate)('Should throw', false, { id: 'test', until: 'forever' }); }, /Should throw/); }); QUnit.test('When ENV.RAISE_ON_DEPRECATION is true, it is still possible to silence a deprecation by id', function (assert) { assert.expect(3); _emberEnvironment.ENV.RAISE_ON_DEPRECATION = true; (0, _deprecate.registerHandler)(function (message, options, next) { if (!options || options.id !== 'my-deprecation') { next.apply(undefined, arguments); } }); try { (0, _index.deprecate)('should be silenced with matching id', false, { id: 'my-deprecation', until: 'forever' }); assert.ok(true, 'Did not throw when level is set by id'); } catch (e) { assert.ok(false, 'Expected deprecate not to throw but it did: ' + e.message); } assert.throws(function () { (0, _index.deprecate)('Should throw with no matching id', false, { id: 'test', until: 'forever' }); }, /Should throw with no matching id/); assert.throws(function () { (0, _index.deprecate)('Should throw with non-matching id', false, { id: 'other-id', until: 'forever' }); }, /Should throw with non-matching id/); }); QUnit.test('Ember.deprecate throws deprecation if second argument is falsy', function () { expect(3); throws(function () { return (0, _index.deprecate)('Deprecation is thrown', false, { id: 'test', until: 'forever' }); }); throws(function () { return (0, _index.deprecate)('Deprecation is thrown', '', { id: 'test', until: 'forever' }); }); throws(function () { return (0, _index.deprecate)('Deprecation is thrown', 0, { id: 'test', until: 'forever' }); }); }); QUnit.test('Ember.deprecate does not invoke a function as the second argument', function () { expect(1); (0, _index.deprecate)('Deprecation is thrown', function () { ok(false, 'this function should not be invoked'); }, { id: 'test', until: 'forever' }); ok(true, 'deprecations were not thrown'); }); QUnit.test('Ember.deprecate does not throw deprecations if second argument is truthy', function () { expect(1); (0, _index.deprecate)('Deprecation is thrown', true, { id: 'test', until: 'forever' }); (0, _index.deprecate)('Deprecation is thrown', '1', { id: 'test', until: 'forever' }); (0, _index.deprecate)('Deprecation is thrown', 1, { id: 'test', until: 'forever' }); ok(true, 'deprecations were not thrown'); }); QUnit.test('Ember.assert throws if second argument is falsy', function () { expect(3); throws(function () { return (0, _index.assert)('Assertion is thrown', false); }); throws(function () { return (0, _index.assert)('Assertion is thrown', ''); }); throws(function () { return (0, _index.assert)('Assertion is thrown', 0); }); }); QUnit.test('Ember.assert does not throw if second argument is a function', function (assert) { assert.expect(1); (0, _index.assert)('Assertion is thrown', function () { return true; }); ok(true, 'assertions were not thrown'); }); QUnit.test('Ember.assert does not throw if second argument is truthy', function () { expect(1); (0, _index.assert)('Assertion is thrown', true); (0, _index.assert)('Assertion is thrown', '1'); (0, _index.assert)('Assertion is thrown', 1); ok(true, 'assertions were not thrown'); }); QUnit.test('Ember.assert does not throw if second argument is an object', function () { expect(1); var Igor = _emberRuntime.Object.extend(); (0, _index.assert)('is truthy', Igor); (0, _index.assert)('is truthy', Igor.create()); ok(true, 'assertions were not thrown'); }); QUnit.test('Ember.deprecate does not throw a deprecation at log and silence levels', function () { expect(4); var id = 'ABC'; var until = 'forever'; var shouldThrow = false; (0, _deprecate.registerHandler)(function (message, options) { if (options && options.id === id) { if (shouldThrow) { throw new Error(message); } } }); try { (0, _index.deprecate)('Deprecation for testing purposes', false, { id: id, until: until }); ok(true, 'Deprecation did not throw'); } catch (e) { ok(false, 'Deprecation was thrown despite being added to blacklist'); } try { (0, _index.deprecate)('Deprecation for testing purposes', false, { id: id, until: until }); ok(true, 'Deprecation did not throw'); } catch (e) { ok(false, 'Deprecation was thrown despite being added to blacklist'); } shouldThrow = true; throws(function () { (0, _index.deprecate)('Deprecation is thrown', false, { id: id, until: until }); }); throws(function () { (0, _index.deprecate)('Deprecation is thrown', false, { id: id, until: until }); }); }); QUnit.test('Ember.deprecate without options triggers a deprecation', function (assert) { assert.expect(4); (0, _deprecate.registerHandler)(function (message) { if (message === _deprecate.missingOptionsDeprecation) { assert.ok(true, 'proper deprecation is triggered when options is missing'); } else if (message === 'foo') { assert.ok(true, 'original deprecation is still triggered'); } }); (0, _index.deprecate)('foo'); (0, _index.deprecate)('foo', false, {}); }); QUnit.test('Ember.deprecate without options.id triggers a deprecation', function (assert) { assert.expect(2); (0, _deprecate.registerHandler)(function (message) { if (message === _deprecate.missingOptionsIdDeprecation) { assert.ok(true, 'proper deprecation is triggered when options.id is missing'); } else if (message === 'foo') { assert.ok(true, 'original deprecation is still triggered'); } }); (0, _index.deprecate)('foo', false, { until: 'forever' }); }); QUnit.test('Ember.deprecate without options.until triggers a deprecation', function (assert) { assert.expect(2); (0, _deprecate.registerHandler)(function (message) { if (message === _deprecate.missingOptionsUntilDeprecation) { assert.ok(true, 'proper deprecation is triggered when options.until is missing'); } else if (message === 'foo') { assert.ok(true, 'original deprecation is still triggered'); } }); (0, _index.deprecate)('foo', false, { id: 'test' }); }); QUnit.test('warn without options triggers a deprecation', function (assert) { assert.expect(2); (0, _deprecate.registerHandler)(function (message) { assert.equal(message, _warn.missingOptionsDeprecation, 'deprecation is triggered when options is missing'); }); (0, _warn.registerHandler)(function (message) { assert.equal(message, 'foo', 'original warning is triggered'); }); (0, _index.warn)('foo'); }); QUnit.test('warn without options.id triggers a deprecation', function (assert) { assert.expect(2); (0, _deprecate.registerHandler)(function (message) { assert.equal(message, _warn.missingOptionsIdDeprecation, 'deprecation is triggered when options is missing'); }); (0, _warn.registerHandler)(function (message) { assert.equal(message, 'foo', 'original warning is triggered'); }); (0, _index.warn)('foo', false, {}); }); QUnit.test('warn without options.id nor test triggers a deprecation', function (assert) { assert.expect(2); (0, _deprecate.registerHandler)(function (message) { assert.equal(message, _warn.missingOptionsIdDeprecation, 'deprecation is triggered when options is missing'); }); (0, _warn.registerHandler)(function (message) { assert.equal(message, 'foo', 'original warning is triggered'); }); (0, _index.warn)('foo', {}); }); QUnit.test('warn without test but with options does not trigger a deprecation', function (assert) { assert.expect(1); (0, _deprecate.registerHandler)(function (message) { assert.ok(false, 'there should be no deprecation ' + message); }); (0, _warn.registerHandler)(function (message) { assert.equal(message, 'foo', 'warning was triggered'); }); (0, _index.warn)('foo', { id: 'ember-debug.do-not-raise' }); }); }); enifed('ember-debug/tests/warn_if_using_stripped_feature_flags_test', ['ember-environment', 'ember-debug', 'ember-debug/index'], function (_emberEnvironment, _emberDebug, _index) { 'use strict'; var oldWarn = void 0, oldRunInDebug = void 0, origEnvFeatures = void 0, origEnableOptional = void 0, features = void 0, knownFeatures = void 0; function confirmWarns(expectedMsg) { var featuresWereStripped = true; (0, _emberDebug.setDebugFunction)('warn', function (msg, test) { if (!test) { equal(msg, expectedMsg); } }); (0, _emberDebug.setDebugFunction)('runInDebug', function (func) { func(); }); // Should trigger our 1 warning (0, _index._warnIfUsingStrippedFeatureFlags)(features, knownFeatures, featuresWereStripped); // Shouldn't trigger any warnings now that we're "in canary" featuresWereStripped = false; (0, _index._warnIfUsingStrippedFeatureFlags)(features, knownFeatures, featuresWereStripped); } QUnit.module('ember-debug - _warnIfUsingStrippedFeatureFlags', { setup: function () { oldWarn = (0, _emberDebug.getDebugFunction)('warn'); oldRunInDebug = (0, _emberDebug.getDebugFunction)('runInDebug'); origEnvFeatures = _emberEnvironment.ENV.FEATURES; origEnableOptional = _emberEnvironment.ENV.ENABLE_OPTIONAL_FEATURES; knownFeatures = { 'fred': null, 'barney': null, 'wilma': null }; }, teardown: function () { (0, _emberDebug.setDebugFunction)('warn', oldWarn); (0, _emberDebug.setDebugFunction)('runInDebug', oldRunInDebug); _emberEnvironment.ENV.FEATURES = origEnvFeatures; _emberEnvironment.ENV.ENABLE_OPTIONAL_FEATURES = origEnableOptional; } }); QUnit.test('Setting Ember.ENV.ENABLE_OPTIONAL_FEATURES truthy in non-canary, debug build causes a warning', function () { expect(1); _emberEnvironment.ENV.ENABLE_OPTIONAL_FEATURES = true; features = {}; confirmWarns('Ember.ENV.ENABLE_OPTIONAL_FEATURES is only available in canary builds.'); }); QUnit.test('Enabling a known FEATURE flag in non-canary, debug build causes a warning', function () { expect(1); _emberEnvironment.ENV.ENABLE_OPTIONAL_FEATURES = false; features = { 'fred': true, 'barney': false, 'wilma': null }; confirmWarns('FEATURE["fred"] is set as enabled, but FEATURE flags are only available in canary builds.'); }); QUnit.test('Enabling an unknown FEATURE flag in non-canary debug build does not cause a warning', function () { expect(0); _emberEnvironment.ENV.ENABLE_OPTIONAL_FEATURES = false; features = { 'some-ember-data-feature-flag': true }; confirmWarns('FEATURE["fred"] is set as enabled, but FEATURE flags are only available in canary builds.'); }); QUnit.test('`ENV.FEATURES` being undefined does not cause an error', function () { expect(0); _emberEnvironment.ENV.ENABLE_OPTIONAL_FEATURES = false; features = undefined; confirmWarns(); }); }); enifed('ember-dev/test-helper/assertion', ['exports', 'ember-dev/test-helper/utils'], function (exports, _utils) { 'use strict'; exports.default = AssertionAssert; var BREAK = {}; /** This assertion class is used to test assertions made using Ember.assert. It injects two helpers onto `window`: - expectAssertion(func: Function, [expectedMessage: String | RegExp]) This function calls `func` and asserts that `Ember.assert` is invoked during the execution. Moreover, it takes a String or a RegExp as a second optional argument that can be used to test if a specific assertion message was generated. - ignoreAssertion(func: Function) This function calls `func` and disables `Ember.assert` during the execution. In particular, this prevents `Ember.assert` from throw errors that would disrupt the control flow. */ function AssertionAssert(env) { this.env = env; } AssertionAssert.prototype = { reset: function () {}, assert: function () {}, inject: function () { var _this = this; window.expectAssertion = function (func, expectedMessage) { if (_this.env.runningProdBuild) { QUnit.ok(true, 'Assertions disabled in production builds.'); return; } var sawCall = undefined; var actualMessage = undefined; // The try-catch statement is used to "exit" `func` as soon as // the first useful assertion has been produced. try { (0, _utils.callWithStub)(_this.env, 'assert', func, function (message, test) { sawCall = true; if ((0, _utils.checkTest)(test)) { return; } actualMessage = message; throw BREAK; }); } catch (e) { if (e !== BREAK) { throw e; } } assert(sawCall, actualMessage, expectedMessage); }; window.ignoreAssertion = function (func) { (0, _utils.callWithStub)(_this.env, 'assert', func); }; }, restore: function () { window.expectAssertion = null; window.ignoreAssertion = null; } }; function assert(sawCall, actualMessage, expectedMessage) { // Run assertions in an order that is useful when debugging a test failure. if (!sawCall) { QUnit.ok(false, 'Expected Ember.assert to be called (Not called with any value).'); } else if (!actualMessage) { QUnit.ok(false, 'Expected a failing Ember.assert (Ember.assert called, but without a failing test).'); } else { if (expectedMessage) { if (expectedMessage instanceof RegExp) { QUnit.ok(expectedMessage.test(actualMessage), 'Expected failing Ember.assert: \'' + expectedMessage + '\', but got \'' + actualMessage + '\'.'); } else { QUnit.equal(actualMessage, expectedMessage, 'Expected failing Ember.assert: \'' + expectedMessage + '\', but got \'' + actualMessage + '\'.'); } } else { // Positive assertion that assert was called QUnit.ok(true, 'Expected a failing Ember.assert.'); } } } }); enifed('ember-dev/test-helper/debug', ['exports', 'ember-dev/test-helper/method-call-tracker'], function (exports, _methodCallTracker) { 'use strict'; var _createClass = function () { function defineProperties(target, props) { var i, descriptor; for (i = 0; i < props.length; i++) { descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ('value' in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor); } }return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var DebugAssert = function () { function DebugAssert(methodName, env) { _classCallCheck(this, DebugAssert); this.methodName = methodName; this.env = env; } _createClass(DebugAssert, [{ key: 'inject', value: function () {} }, { key: 'restore', value: function () { this.reset(); } }, { key: 'reset', value: function () { if (this.tracker) { this.tracker.restoreMethod(); } this.tracker = null; } }, { key: 'assert', value: function () { if (this.tracker) { this.tracker.assert(); } } // Run an expectation callback within the context of a new tracker, optionally // accepting a function to run, which asserts immediately }, { key: 'runExpectation', value: function (func, callback) { var originalTracker = undefined; // When helpers are passed a callback, they get a new tracker context if (func) { originalTracker = this.tracker; this.tracker = null; } if (!this.tracker) { this.tracker = new _methodCallTracker.default(this.env, this.methodName); } // Yield to caller with tracker instance callback(this.tracker); // Once the given callback is invoked, the pending assertions should be // flushed immediately if (func) { func(); this.assert(); this.reset(); this.tracker = originalTracker; } } }]); return DebugAssert; }(); exports.default = DebugAssert; }); enifed('ember-dev/test-helper/deprecation', ['exports', 'ember-babel', 'ember-dev/test-helper/debug', 'ember-dev/test-helper/utils'], function (exports, _emberBabel, _debug, _utils) { 'use strict'; var _createClass = function () { function defineProperties(target, props) { var i, descriptor; for (i = 0; i < props.length; i++) { descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ('value' in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor); } }return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor; }; }(); var _get = function (_x, _x2, _x3) { var _again = true, object, property, receiver, desc, parent, getter;_function: while (_again) { object = _x, property = _x2, receiver = _x3; _again = false;if (object === null) object = Function.prototype;desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent;_x2 = property;_x3 = receiver;_again = true;desc = parent = undefined;continue _function; } } else if ('value' in desc) { return desc.value; } else { getter = desc.get; if (getter === undefined) { return undefined; }return getter.call(receiver); } } }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : (0, _emberBabel.defaults)(subClass, superClass); } var DeprecationAssert = function (_DebugAssert) { _inherits(DeprecationAssert, _DebugAssert); function DeprecationAssert(env) { _classCallCheck(this, DeprecationAssert); _get(Object.getPrototypeOf(DeprecationAssert.prototype), 'constructor', this).call(this, 'deprecate', env); } _createClass(DeprecationAssert, [{ key: 'inject', value: function () { var _this = this; // Expects no deprecation to happen within a function, or if no function is // passed, from the time of calling until the end of the test. // // expectNoDeprecation(function() { // fancyNewThing(); // }); // // expectNoDeprecation(); // Ember.deprecate("Old And Busted"); // // Expect a deprecation to happen within a function, or if no function // is pass, from the time of calling until the end of the test. Can be called // multiple times to assert deprecations with different specific messages // were fired. // // expectDeprecation(function() { // Ember.deprecate("Old And Busted"); // }, /* optionalStringOrRegex */); // // expectDeprecation(/* optionalStringOrRegex */); // Ember.deprecate("Old And Busted"); // window.expectNoDeprecation = function (func) { if (typeof func !== 'function') { func = null; } _this.runExpectation(func, function (tracker) { if (tracker.isExpectingCalls()) { throw new Error("expectNoDeprecation was called after expectDeprecation was called!"); } tracker.expectNoCalls(); }); }; window.expectDeprecation = function (func, message) { if (typeof func !== 'function') { message = func; func = null; } _this.runExpectation(func, function (tracker) { if (tracker.isExpectingNoCalls()) { throw new Error("expectDeprecation was called after expectNoDeprecation was called!"); } tracker.expectCall(message); }); }; window.ignoreDeprecation = function (func) { (0, _utils.callWithStub)(_this.env, 'deprecate', func); }; } }, { key: 'restore', value: function () { _get(Object.getPrototypeOf(DeprecationAssert.prototype), 'restore', this).call(this); window.expectDeprecation = null; window.expectNoDeprecation = null; window.ignoreDeprecation = null; } }]); return DeprecationAssert; }(_debug.default); exports.default = DeprecationAssert; }); enifed("ember-dev/test-helper/index", ["exports", "ember-dev/test-helper/deprecation", "ember-dev/test-helper/warning", "ember-dev/test-helper/remaining-view", "ember-dev/test-helper/remaining-template", "ember-dev/test-helper/assertion", "ember-dev/test-helper/run-loop", "ember-dev/test-helper/utils"], function (exports, _deprecation, _warning, _remainingView, _remainingTemplate, _assertion, _runLoop, _utils) { "use strict"; var EmberDevTestHelperAssert = (0, _utils.buildCompositeAssert)([_deprecation.default, _warning.default, _remainingView.default, _remainingTemplate.default, _assertion.default, _runLoop.default]); exports.default = EmberDevTestHelperAssert; }); enifed('ember-dev/test-helper/method-call-tracker', ['exports', 'ember-dev/test-helper/utils'], function (exports, _utils) { 'use strict'; var MethodCallTracker = function (env, methodName) { this._env = env; this._methodName = methodName; this._isExpectingNoCalls = false; this._expecteds = []; this._actuals = []; }; /* globals QUnit */ MethodCallTracker.prototype = { stubMethod: function () { var _this = this; if (this._originalMethod) { // Method is already stubbed return; } var env = this._env; var methodName = this._methodName; this._originalMethod = env.getDebugFunction(methodName); env.setDebugFunction(methodName, function (message, test) { var resultOfTest = (0, _utils.checkTest)(test); _this._actuals.push([message, resultOfTest]); }); }, restoreMethod: function () { if (this._originalMethod) { this._env.setDebugFunction(this._methodName, this._originalMethod); } }, expectCall: function (message) { this.stubMethod(); this._expecteds.push(message || /.*/); }, expectNoCalls: function () { this.stubMethod(); this._isExpectingNoCalls = true; }, isExpectingNoCalls: function () { return this._isExpectingNoCalls; }, isExpectingCalls: function () { return !this._isExpectingNoCalls && this._expecteds.length; }, assert: function () { var env = this._env, actualMessages; var methodName = this._methodName; var isExpectingNoCalls = this._isExpectingNoCalls; var expecteds = this._expecteds; var actuals = this._actuals; var o = undefined, i = undefined; if (!isExpectingNoCalls && expecteds.length === 0 && actuals.length === 0) { return; } if (env.runningProdBuild) { QUnit.ok(true, 'calls to Ember.' + methodName + ' disabled in production builds.'); return; } if (isExpectingNoCalls) { actualMessages = []; for (i = 0; i < actuals.length; i++) { if (!actuals[i][1]) { actualMessages.push(actuals[i][0]); } } QUnit.ok(actualMessages.length === 0, 'Expected no Ember.' + methodName + ' calls, got ' + actuals.length + ': ' + actualMessages.join(', ')); return; } var expected = undefined, actual = undefined, match = undefined; for (o = 0; o < expecteds.length; o++) { expected = expecteds[o]; for (i = 0; i < actuals.length; i++) { actual = actuals[i]; if (!actual[1]) { if (expected instanceof RegExp) { if (expected.test(actual[0])) { match = actual; break; } } else { if (expected === actual[0]) { match = actual; break; } } } } if (!actual) { QUnit.ok(false, 'Recieved no Ember.' + methodName + ' calls at all, expecting: ' + expected); } else if (match && !match[1]) { QUnit.ok(true, 'Recieved failing Ember.' + methodName + ' call with message: ' + match[0]); } else if (match && match[1]) { QUnit.ok(false, 'Expected failing Ember.' + methodName + ' call, got succeeding with message: ' + match[0]); } else if (actual[1]) { QUnit.ok(false, 'Did not receive failing Ember.' + methodName + ' call matching \'' + expected + '\', last was success with \'' + actual[0] + '\''); } else if (!actual[1]) { QUnit.ok(false, 'Did not receive failing Ember.' + methodName + ' call matching \'' + expected + '\', last was failure with \'' + actual[0] + '\''); } } } }; exports.default = MethodCallTracker; }); enifed("ember-dev/test-helper/remaining-template", ["exports"], function (exports) { "use strict"; /* globals QUnit */ var RemainingTemplateAssert = function (env) { this.env = env; }; RemainingTemplateAssert.prototype = { reset: function () {}, inject: function () {}, assert: function () { var templateNames, name; if (this.env.Ember && this.env.Ember.TEMPLATES) { templateNames = []; for (name in this.env.Ember.TEMPLATES) { if (this.env.Ember.TEMPLATES[name] != null) { templateNames.push(name); } } if (templateNames.length > 0) { QUnit.deepEqual(templateNames, [], "Ember.TEMPLATES should be empty"); this.env.Ember.TEMPLATES = {}; } } }, restore: function () {} }; exports.default = RemainingTemplateAssert; }); enifed("ember-dev/test-helper/remaining-view", ["exports"], function (exports) { "use strict"; /* globals QUnit */ var RemainingViewAssert = function (env) { this.env = env; }; RemainingViewAssert.prototype = { reset: function () {}, inject: function () {}, assert: function () { var viewIds, id; if (this.env.Ember && this.env.Ember.View) { viewIds = []; for (id in this.env.Ember.View.views) { if (this.env.Ember.View.views[id] != null) { viewIds.push(id); } } if (viewIds.length > 0) { QUnit.deepEqual(viewIds, [], "Ember.View.views should be empty"); this.env.Ember.View.views = []; } } }, restore: function () {} }; exports.default = RemainingViewAssert; }); enifed("ember-dev/test-helper/run-loop", ["exports"], function (exports) { "use strict"; /* globals QUnit */ function RunLoopAssertion(env) { this.env = env; } RunLoopAssertion.prototype = { reset: function () {}, inject: function () {}, assert: function () { var run = this.env.Ember.run; if (run.currentRunLoop) { QUnit.ok(false, "Should not be in a run loop at end of test"); while (run.currentRunLoop) { run.end(); } } if (run.hasScheduledTimers()) { QUnit.ok(false, "Ember run should not have scheduled timers at end of test"); run.cancelTimers(); } }, restore: function () {} }; exports.default = RunLoopAssertion; }); enifed("ember-dev/test-helper/setup-qunit", ["exports"], function (exports) { "use strict"; exports.default = /* globals QUnit */ function (assertion, _qunitGlobal) { var qunitGlobal = QUnit; if (_qunitGlobal) { qunitGlobal = _qunitGlobal; } var originalModule = qunitGlobal.module; qunitGlobal.module = function (name, _options) { var options = _options || {}; var originalSetup = options.setup || function () {}; var originalTeardown = options.teardown || function () {}; options.setup = function () { assertion.reset(); assertion.inject(); originalSetup.call(this); }; options.teardown = function () { originalTeardown.call(this); assertion.assert(); assertion.restore(); }; return originalModule(name, options); }; }; }); enifed('ember-dev/test-helper/utils', ['exports'], function (exports) { 'use strict'; exports.buildCompositeAssert = function (assertClasses) { function Composite(env) { this.asserts = assertClasses.map(function (Assert) { return new Assert(env); }); } Composite.prototype = { reset: callForEach('asserts', 'reset'), inject: callForEach('asserts', 'inject'), assert: callForEach('asserts', 'assert'), restore: callForEach('asserts', 'restore') }; return Composite; }; exports.callWithStub = function (env, name, func) { var debugStub = arguments.length <= 3 || arguments[3] === undefined ? noop : arguments[3]; var originalFunc = env.getDebugFunction(name); try { env.setDebugFunction(name, debugStub); func(); } finally { env.setDebugFunction(name, originalFunc); } }; exports.checkTest = function (test) { return typeof test === 'function' ? test() : test; }; function callForEach(prop, func) { return function () { var i, l; for (i = 0, l = this[prop].length; i < l; i++) { this[prop][i][func](); } }; } function noop() {} }); enifed('ember-dev/test-helper/warning', ['exports', 'ember-babel', 'ember-dev/test-helper/debug', 'ember-dev/test-helper/utils'], function (exports, _emberBabel, _debug, _utils) { 'use strict'; var _createClass = function () { function defineProperties(target, props) { var i, descriptor; for (i = 0; i < props.length; i++) { descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ('value' in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor); } }return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor; }; }(); var _get = function (_x, _x2, _x3) { var _again = true, object, property, receiver, desc, parent, getter;_function: while (_again) { object = _x, property = _x2, receiver = _x3; _again = false;if (object === null) object = Function.prototype;desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent;_x2 = property;_x3 = receiver;_again = true;desc = parent = undefined;continue _function; } } else if ('value' in desc) { return desc.value; } else { getter = desc.get; if (getter === undefined) { return undefined; }return getter.call(receiver); } } }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : (0, _emberBabel.defaults)(subClass, superClass); } var WarningAssert = function (_DebugAssert) { _inherits(WarningAssert, _DebugAssert); function WarningAssert(env) { _classCallCheck(this, WarningAssert); _get(Object.getPrototypeOf(WarningAssert.prototype), 'constructor', this).call(this, 'warn', env); } _createClass(WarningAssert, [{ key: 'inject', value: function () { var _this = this; // Expects no warning to happen within a function, or if no function is // passed, from the time of calling until the end of the test. // // expectNoWarning(function() { // fancyNewThing(); // }); // // expectNoWarning(); // Ember.warn("Oh snap, didn't expect that"); // // Expect a warning to happen within a function, or if no function is // passed, from the time of calling until the end of the test. Can be called // multiple times to assert warnings with different specific messages // happened. // // expectWarning(function() { // Ember.warn("Times they are a-changin'"); // }, /* optionalStringOrRegex */); // // expectWarning(/* optionalStringOrRegex */); // Ember.warn("Times definitely be changin'"); // window.expectNoWarning = function (func) { if (typeof func !== 'function') { func = null; } _this.runExpectation(func, function (tracker) { if (tracker.isExpectingCalls()) { throw new Error("expectNoWarning was called after expectWarning was called!"); } tracker.expectNoCalls(); }); }; window.expectWarning = function (fn, message) { if (typeof fn !== 'function') { message = fn; fn = null; } _this.runExpectation(fn, function (tracker) { if (tracker.isExpectingNoCalls()) { throw new Error("expectWarning was called after expectNoWarning was called!"); } tracker.expectCall(message); }); }; window.ignoreWarning = function (func) { (0, _utils.callWithStub)(_this.env, 'warn', func); }; } }, { key: 'restore', value: function () { _get(Object.getPrototypeOf(WarningAssert.prototype), 'restore', this).call(this); window.expectWarning = null; window.expectNoWarning = null; window.ignoreWarning = null; } }]); return WarningAssert; }(_debug.default); exports.default = WarningAssert; }); enifed('ember-extension-support/tests/container_debug_adapter_test', ['ember-babel', 'internal-test-helpers', 'ember-utils', 'ember-metal', 'ember-runtime', 'ember-extension-support/index'], function (_emberBabel, _internalTestHelpers, _emberUtils, _emberMetal, _emberRuntime) { 'use strict'; // Must be required to export Ember.ContainerDebugAdapter. var adapter = void 0; (0, _internalTestHelpers.moduleFor)('Container Debug Adapter', function (_ApplicationTestCase) { (0, _emberBabel.inherits)(_class, _ApplicationTestCase); function _class() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this)); adapter = _this.application.__deprecatedInstance__.lookup('container-debug-adapter:main'); return _this; } _class.prototype.teardown = function () { (0, _emberMetal.run)(function () { adapter.destroy(); }); _ApplicationTestCase.prototype.teardown.call(this); }; _class.prototype['@test default ContainerDebugAdapter cannot catalog certain entries by type'] = function (assert) { assert.equal(adapter.canCatalogEntriesByType('model'), false, 'canCatalogEntriesByType should return false for model'); assert.equal(adapter.canCatalogEntriesByType('template'), false, 'canCatalogEntriesByType should return false for template'); }; _class.prototype['@test default ContainerDebugAdapter can catalog typical entries by type'] = function (assert) { assert.equal(adapter.canCatalogEntriesByType('controller'), true, 'canCatalogEntriesByType should return true for controller'); assert.equal(adapter.canCatalogEntriesByType('route'), true, 'canCatalogEntriesByType should return true for route'); assert.equal(adapter.canCatalogEntriesByType('view'), true, 'canCatalogEntriesByType should return true for view'); }; _class.prototype['@test default ContainerDebugAdapter catalogs controller entries'] = function (assert) { this.application.PostController = _emberRuntime.Controller.extend(); var controllerClasses = adapter.catalogEntriesByType('controller'); assert.equal(controllerClasses.length, 1, 'found 1 class'); assert.equal(controllerClasses[0], 'post', 'found the right class'); }; (0, _emberBabel.createClass)(_class, [{ key: 'applicationOptions', get: function () { return (0, _emberUtils.assign)(_ApplicationTestCase.prototype.applicationOptions, { autoboot: true }); } }]); return _class; }(_internalTestHelpers.ApplicationTestCase)); }); enifed('ember-extension-support/tests/data_adapter_test', ['ember-babel', 'ember-metal', 'ember-runtime', 'ember-extension-support/data_adapter', 'internal-test-helpers'], function (_emberBabel, _emberMetal, _emberRuntime, _data_adapter, _internalTestHelpers) { 'use strict'; var adapter = void 0; var Model = _emberRuntime.Object.extend(); var PostClass = Model.extend(); var DataAdapter = _data_adapter.default.extend({ detect: function (klass) { return klass !== Model && Model.detect(klass); }, init: function () { this._super.apply(this, arguments); this.set('containerDebugAdapter', { canCatalogEntriesByType: function () { return true; }, catalogEntriesByType: function () { return (0, _emberRuntime.A)(['post']); } }); } }); (0, _internalTestHelpers.moduleFor)('Data Adapter', function (_ApplicationTestCase) { (0, _emberBabel.inherits)(_class, _ApplicationTestCase); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments)); } _class.prototype['@test Model types added'] = function () { var _this2 = this; this.add('data-adapter:main', DataAdapter.extend({ getRecords: function () { return (0, _emberRuntime.A)([1, 2, 3]); }, columnsForType: function () { return [{ name: 'title', desc: 'Title' }]; } })); this.add('model:post', PostClass); return this.visit('/').then(function () { var adapter = _this2.applicationInstance.lookup('data-adapter:main'); adapter.watchModelTypes(function (types) { equal(types.length, 1); var postType = types[0]; equal(postType.name, 'post', 'Correctly sets the name'); equal(postType.count, 3, 'Correctly sets the record count'); strictEqual(postType.object, PostClass, 'Correctly sets the object'); deepEqual(postType.columns, [{ name: 'title', desc: 'Title' }], 'Correctly sets the columns'); }); }); }; _class.prototype['@test getRecords gets a model name as second argument'] = function () { var _this3 = this; this.add('data-adapter:main', DataAdapter.extend({ getRecords: function (klass, name) { equal(name, 'post'); return (0, _emberRuntime.A)(); } })); this.add('model:post', PostClass); return this.visit('/').then(function () { adapter = _this3.applicationInstance.lookup('data-adapter:main'); adapter.watchModelTypes(function () {}); }); }; _class.prototype['@test Model types added with custom container-debug-adapter'] = function () { var _this4 = this; var StubContainerDebugAdapter = _emberRuntime.Object.extend({ canCatalogEntriesByType: function () { return true; }, catalogEntriesByType: function () { return (0, _emberRuntime.A)(['post']); } }); this.add('container-debug-adapter:main', StubContainerDebugAdapter); this.add('data-adapter:main', DataAdapter.extend({ getRecords: function () { return (0, _emberRuntime.A)([1, 2, 3]); }, columnsForType: function () { return [{ name: 'title', desc: 'Title' }]; } })); this.add('model:post', PostClass); return this.visit('/').then(function () { var adapter = _this4.applicationInstance.lookup('data-adapter:main'); adapter.watchModelTypes(function (types) { equal(types.length, 1); var postType = types[0]; equal(postType.name, 'post', 'Correctly sets the name'); equal(postType.count, 3, 'Correctly sets the record count'); strictEqual(postType.object, PostClass, 'Correctly sets the object'); deepEqual(postType.columns, [{ name: 'title', desc: 'Title' }], 'Correctly sets the columns'); }); }); }; _class.prototype['@test Model Types Updated'] = function () { var _this5 = this; var records = (0, _emberRuntime.A)([1, 2, 3]); this.add('data-adapter:main', DataAdapter.extend({ getRecords: function () { return records; } })); this.add('model:post', PostClass); return this.visit('/').then(function () { adapter = _this5.applicationInstance.lookup('data-adapter:main'); adapter.watchModelTypes(function () { (0, _emberMetal.run)(function () { records.pushObject(4); }); }, function (types) { var postType = types[0]; equal(postType.count, 4, 'Correctly updates the count'); }); }); }; _class.prototype['@test Records Added'] = function () { var _this6 = this; var countAdded = 1; var post = PostClass.create(); var recordList = (0, _emberRuntime.A)([post]); this.add('data-adapter:main', DataAdapter.extend({ getRecords: function () { return recordList; }, getRecordColor: function () { return 'blue'; }, getRecordColumnValues: function () { return { title: 'Post ' + countAdded }; }, getRecordKeywords: function () { return ['Post ' + countAdded]; } })); this.add('model:post', PostClass); return this.visit('/').then(function () { adapter = _this6.applicationInstance.lookup('data-adapter:main'); adapter.watchRecords('post', function (records) { var record = records[0]; equal(record.color, 'blue', 'Sets the color correctly'); deepEqual(record.columnValues, { title: 'Post ' + countAdded }, 'Sets the column values correctly'); deepEqual(record.searchKeywords, ['Post ' + countAdded], 'Sets search keywords correctly'); strictEqual(record.object, post, 'Sets the object to the record instance'); }); countAdded++; post = PostClass.create(); recordList.pushObject(post); }); }; _class.prototype['@test Observes and releases a record correctly'] = function () { var _this7 = this; var updatesCalled = 0; var post = PostClass.create({ title: 'Post' }); var recordList = (0, _emberRuntime.A)([post]); this.add('data-adapter:main', DataAdapter.extend({ getRecords: function () { return recordList; }, observeRecord: function (record, recordUpdated) { var self = this; function callback() { recordUpdated(self.wrapRecord(record)); } (0, _emberMetal.addObserver)(record, 'title', callback); return function () { (0, _emberMetal.removeObserver)(record, 'title', callback); }; }, getRecordColumnValues: function (record) { return { title: (0, _emberMetal.get)(record, 'title') }; } })); this.add('model:post', PostClass); return this.visit('/').then(function () { adapter = _this7.applicationInstance.lookup('data-adapter:main'); var release = adapter.watchRecords('post', function () { (0, _emberMetal.set)(post, 'title', 'Post Modified'); }, function (records) { updatesCalled++; equal(records[0].columnValues.title, 'Post Modified'); }); release(); (0, _emberMetal.set)(post, 'title', 'New Title'); equal(updatesCalled, 1, 'Release function removes observers'); }); }; _class.prototype['@test _nameToClass does not error when not found'] = function () { var _this8 = this; this.add('data-adapter:main', DataAdapter); return this.visit('/').then(function () { adapter = _this8.applicationInstance.lookup('data-adapter:main'); var klass = adapter._nameToClass('foo'); equal(klass, undefined, 'returns undefined'); }); }; return _class; }(_internalTestHelpers.ApplicationTestCase)); }); enifed('ember-glimmer/tests/integration/application/actions-test', ['ember-babel', 'ember-runtime', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers'], function (_emberBabel, _emberRuntime, _testCase, _helpers) { 'use strict'; (0, _testCase.moduleFor)('Application test: actions', function (_ApplicationTest) { (0, _emberBabel.inherits)(_class, _ApplicationTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTest.apply(this, arguments)); } _class.prototype['@test actions in top level template application template target application controller'] = function (assert) { var _this2 = this; assert.expect(1); this.add('controller:application', _emberRuntime.Controller.extend({ actions: { handleIt: function () { assert.ok(true, 'controller received action properly'); } } })); this.addTemplate('application', ''); return this.visit('/').then(function () { _this2.runTask(function () { return _this2.$('#handle-it').click(); }); }); }; _class.prototype['@test actions in nested outlet template target their controller'] = function (assert) { var _this3 = this; assert.expect(1); this.add('controller:application', _emberRuntime.Controller.extend({ actions: { handleIt: function () { assert.ok(false, 'application controller should not have received action!'); } } })); this.add('controller:index', _emberRuntime.Controller.extend({ actions: { handleIt: function () { assert.ok(true, 'controller received action properly'); } } })); this.addTemplate('index', ''); return this.visit('/').then(function () { _this3.runTask(function () { return _this3.$('#handle-it').click(); }); }); }; return _class; }(_testCase.ApplicationTest)); (0, _testCase.moduleFor)('Rendering test: non-interactive actions', function (_RenderingTest) { (0, _emberBabel.inherits)(_class2, _RenderingTest); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class2.prototype.getBootOptions = function () { return { isInteractive: false }; }; _class2.prototype['@test doesn\'t attatch actions'] = function (assert) { this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ actions: { fire: function () { assert.ok(false); } } }), template: '' }); this.render('{{foo-bar tagName=""}}'); this.assertHTML(''); this.$('button').click(); }; return _class2; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/application/engine-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/helpers', 'ember-runtime', 'ember-glimmer', 'ember-application', 'ember-routing'], function (_emberBabel, _testCase, _abstractTestCase, _helpers, _emberRuntime, _emberGlimmer, _emberApplication, _emberRouting) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n

{{contextType}}

\n {{ambiguous-curlies}}\n\n {{outlet}}\n '], ['\n

{{contextType}}

\n {{ambiguous-curlies}}\n\n {{outlet}}\n ']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n

Component!

\n '], ['\n

Component!

\n ']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{ambiguous-curlies}}\n '], ['\n {{ambiguous-curlies}}\n ']), _templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n

Application

\n {{my-component ambiguous-curlies="Local Data!"}}\n {{outlet}}\n '], ['\n

Application

\n {{my-component ambiguous-curlies="Local Data!"}}\n {{outlet}}\n ']), _templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n

Engine

\n {{my-component}}\n {{outlet}}\n '], ['\n

Engine

\n {{my-component}}\n {{outlet}}\n ']), _templateObject6 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n

Component!

\n '], ['\n

Component!

\n ']); (0, _testCase.moduleFor)('Application test: engine rendering', function (_ApplicationTest) { (0, _emberBabel.inherits)(_class, _ApplicationTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTest.apply(this, arguments)); } _class.prototype.setupAppAndRoutableEngine = function () { var hooks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var self = this; this.addTemplate('application', 'Application{{outlet}}'); this.router.map(function () { this.mount('blog'); }); this.add('route-map:blog', function () { this.route('post', function () { this.route('comments'); this.route('likes'); }); this.route('category', { path: 'category/:id' }); this.route('author', { path: 'author/:id' }); }); this.add('route:application', _emberRouting.Route.extend({ model: function () { hooks.push('application - application'); } })); this.add('engine:blog', _emberApplication.Engine.extend({ init: function () { this._super.apply(this, arguments); this.register('controller:application', _emberRuntime.Controller.extend({ queryParams: ['lang'], lang: '' })); this.register('controller:category', _emberRuntime.Controller.extend({ queryParams: ['type'] })); this.register('controller:authorKtrl', _emberRuntime.Controller.extend({ queryParams: ['official'] })); this.register('template:application', (0, _helpers.compile)('Engine{{lang}}{{outlet}}')); this.register('route:application', _emberRouting.Route.extend({ model: function () { hooks.push('engine - application'); } })); this.register('route:author', _emberRouting.Route.extend({ controllerName: 'authorKtrl' })); if (self._additionalEngineRegistrations) { self._additionalEngineRegistrations.call(this); } } })); }; _class.prototype.setupAppAndRoutelessEngine = function (hooks) { this.setupRoutelessEngine(hooks); this.add('engine:chat-engine', _emberApplication.Engine.extend({ init: function () { this._super.apply(this, arguments); this.register('template:application', (0, _helpers.compile)('Engine')); this.register('controller:application', _emberRuntime.Controller.extend({ init: function () { this._super.apply(this, arguments); hooks.push('engine - application'); } })); } })); }; _class.prototype.setupAppAndRoutableEngineWithPartial = function (hooks) { this.addTemplate('application', 'Application{{outlet}}'); this.router.map(function () { this.mount('blog'); }); this.add('route-map:blog', function () {}); this.add('route:application', _emberRouting.Route.extend({ model: function () { hooks.push('application - application'); } })); this.add('engine:blog', _emberApplication.Engine.extend({ init: function () { this._super.apply(this, arguments); this.register('template:foo', (0, _helpers.compile)('foo partial')); this.register('template:application', (0, _helpers.compile)('Engine{{outlet}} {{partial "foo"}}')); this.register('route:application', _emberRouting.Route.extend({ model: function () { hooks.push('engine - application'); } })); } })); }; _class.prototype.setupRoutelessEngine = function (hooks) { this.addTemplate('application', 'Application{{mount "chat-engine"}}'); this.add('route:application', _emberRouting.Route.extend({ model: function () { hooks.push('application - application'); } })); }; _class.prototype.setupAppAndRoutlessEngineWithPartial = function (hooks) { this.setupRoutelessEngine(hooks); this.add('engine:chat-engine', _emberApplication.Engine.extend({ init: function () { this._super.apply(this, arguments); this.register('template:foo', (0, _helpers.compile)('foo partial')); this.register('template:application', (0, _helpers.compile)('Engine {{partial "foo"}}')); this.register('controller:application', _emberRuntime.Controller.extend({ init: function () { this._super.apply(this, arguments); hooks.push('engine - application'); } })); } })); }; _class.prototype.additionalEngineRegistrations = function (callback) { this._additionalEngineRegistrations = callback; }; _class.prototype.setupEngineWithAttrs = function () { this.addTemplate('application', 'Application{{mount "chat-engine"}}'); this.add('engine:chat-engine', _emberApplication.Engine.extend({ init: function () { this._super.apply(this, arguments); this.register('template:components/foo-bar', (0, _helpers.compile)('{{partial "troll"}}')); this.register('template:troll', (0, _helpers.compile)('{{attrs.wat}}')); this.register('controller:application', _emberRuntime.Controller.extend({ contextType: 'Engine' })); this.register('template:application', (0, _helpers.compile)('Engine {{foo-bar wat=contextType}}')); } })); }; _class.prototype.stringsEndWith = function (str, suffix) { return str.indexOf(suffix, str.length - suffix.length) !== -1; }; _class.prototype['@test attrs in an engine'] = function () { var _this2 = this; this.setupEngineWithAttrs([]); return this.visit('/').then(function () { _this2.assertText('ApplicationEngine Engine'); }); }; _class.prototype['@test sharing a template between engine and application has separate refinements'] = function () { var _this3 = this; this.assert.expect(1); var sharedTemplate = (0, _helpers.compile)((0, _abstractTestCase.strip)(_templateObject)); this.add('template:application', sharedTemplate); this.add('controller:application', _emberRuntime.Controller.extend({ contextType: 'Application', 'ambiguous-curlies': 'Controller Data!' })); this.router.map(function () { this.mount('blog'); }); this.add('route-map:blog', function () {}); this.add('engine:blog', _emberApplication.Engine.extend({ init: function () { this._super.apply(this, arguments); this.register('controller:application', _emberRuntime.Controller.extend({ contextType: 'Engine' })); this.register('template:application', sharedTemplate); this.register('template:components/ambiguous-curlies', (0, _helpers.compile)((0, _abstractTestCase.strip)(_templateObject2))); } })); return this.visit('/blog').then(function () { _this3.assertText('ApplicationController Data!EngineComponent!'); }); }; _class.prototype['@test sharing a layout between engine and application has separate refinements'] = function () { var _this4 = this; this.assert.expect(1); var sharedLayout = (0, _helpers.compile)((0, _abstractTestCase.strip)(_templateObject3)); var sharedComponent = _emberGlimmer.Component.extend({ layout: sharedLayout }); this.addTemplate('application', (0, _abstractTestCase.strip)(_templateObject4)); this.add('component:my-component', sharedComponent); this.router.map(function () { this.mount('blog'); }); this.add('route-map:blog', function () {}); this.add('engine:blog', _emberApplication.Engine.extend({ init: function () { this._super.apply(this, arguments); this.register('template:application', (0, _helpers.compile)((0, _abstractTestCase.strip)(_templateObject5))); this.register('component:my-component', sharedComponent); this.register('template:components/ambiguous-curlies', (0, _helpers.compile)((0, _abstractTestCase.strip)(_templateObject6))); } })); return this.visit('/blog').then(function () { _this4.assertText('ApplicationLocal Data!EngineComponent!'); }); }; _class.prototype['@test visit() with `shouldRender: true` returns a promise that resolves when application and engine templates have rendered'] = function (assert) { var _this5 = this; assert.expect(2); var hooks = []; this.setupAppAndRoutableEngine(hooks); return this.visit('/blog', { shouldRender: true }).then(function () { _this5.assertText('ApplicationEngine'); _this5.assert.deepEqual(hooks, ['application - application', 'engine - application'], 'the expected model hooks were fired'); }); }; _class.prototype['@test visit() with `shouldRender: false` returns a promise that resolves without rendering'] = function (assert) { var _this6 = this; assert.expect(2); var hooks = []; this.setupAppAndRoutableEngine(hooks); return this.visit('/blog', { shouldRender: false }).then(function () { _this6.assertText(''); _this6.assert.deepEqual(hooks, ['application - application', 'engine - application'], 'the expected model hooks were fired'); }); }; _class.prototype['@test visit() with `shouldRender: true` returns a promise that resolves when application and routeless engine templates have rendered'] = function (assert) { var _this7 = this; assert.expect(2); var hooks = []; this.setupAppAndRoutelessEngine(hooks); return this.visit('/', { shouldRender: true }).then(function () { _this7.assertText('ApplicationEngine'); _this7.assert.deepEqual(hooks, ['application - application', 'engine - application'], 'the expected hooks were fired'); }); }; _class.prototype['@test visit() with partials in routable engine'] = function (assert) { var _this8 = this; assert.expect(2); var hooks = []; this.setupAppAndRoutableEngineWithPartial(hooks); return this.visit('/blog', { shouldRender: true }).then(function () { _this8.assertText('ApplicationEngine foo partial'); _this8.assert.deepEqual(hooks, ['application - application', 'engine - application'], 'the expected hooks were fired'); }); }; _class.prototype['@test visit() with partials in non-routable engine'] = function (assert) { var _this9 = this; assert.expect(2); var hooks = []; this.setupAppAndRoutlessEngineWithPartial(hooks); return this.visit('/', { shouldRender: true }).then(function () { _this9.assertText('ApplicationEngine foo partial'); _this9.assert.deepEqual(hooks, ['application - application', 'engine - application'], 'the expected hooks were fired'); }); }; _class.prototype['@test deactivate should be called on Engine Routes before destruction'] = function (assert) { var _this10 = this; assert.expect(3); this.setupAppAndRoutableEngine(); this.add('engine:blog', _emberApplication.Engine.extend({ init: function () { this._super.apply(this, arguments); this.register('template:application', (0, _helpers.compile)('Engine{{outlet}}')); this.register('route:application', _emberRouting.Route.extend({ deactivate: function () { assert.notOk(this.isDestroyed, 'Route is not destroyed'); assert.notOk(this.isDestroying, 'Route is not being destroyed'); } })); } })); return this.visit('/blog').then(function () { _this10.assertText('ApplicationEngine'); }); }; _class.prototype['@test engine should lookup and use correct controller'] = function () { var _this11 = this; this.setupAppAndRoutableEngine(); return this.visit('/blog?lang=English').then(function () { _this11.assertText('ApplicationEngineEnglish'); }); }; _class.prototype['@test error substate route works for the application route of an Engine'] = function (assert) { var _this12 = this; assert.expect(2); this.setupAppAndRoutableEngine(); this.additionalEngineRegistrations(function () { this.register('template:application_error', (0, _helpers.compile)('Error! {{model.message}}')); this.register('route:post', _emberRouting.Route.extend({ model: function () { return _emberRuntime.RSVP.reject(new Error('Oh, noes!')); } })); }); return this.visit('/').then(function () { _this12.assertText('Application'); return _this12.transitionTo('blog.post'); }).catch(function () { _this12.assertText('ApplicationError! Oh, noes!'); }); }; _class.prototype['@test error route works for the application route of an Engine'] = function (assert) { var _this13 = this; assert.expect(2); this.setupAppAndRoutableEngine(); this.additionalEngineRegistrations(function () { this.register('template:error', (0, _helpers.compile)('Error! {{model.message}}')); this.register('route:post', _emberRouting.Route.extend({ model: function () { return _emberRuntime.RSVP.reject(new Error('Oh, noes!')); } })); }); return this.visit('/').then(function () { _this13.assertText('Application'); return _this13.transitionTo('blog.post'); }).catch(function () { _this13.assertText('ApplicationEngineError! Oh, noes!'); }); }; _class.prototype['@test error substate route works for a child route of an Engine'] = function (assert) { var _this14 = this; assert.expect(2); this.setupAppAndRoutableEngine(); this.additionalEngineRegistrations(function () { this.register('template:post_error', (0, _helpers.compile)('Error! {{model.message}}')); this.register('route:post', _emberRouting.Route.extend({ model: function () { return _emberRuntime.RSVP.reject(new Error('Oh, noes!')); } })); }); return this.visit('/').then(function () { _this14.assertText('Application'); return _this14.transitionTo('blog.post'); }).catch(function () { _this14.assertText('ApplicationEngineError! Oh, noes!'); }); }; _class.prototype['@test error route works for a child route of an Engine'] = function (assert) { var _this15 = this; assert.expect(2); this.setupAppAndRoutableEngine(); this.additionalEngineRegistrations(function () { this.register('template:post.error', (0, _helpers.compile)('Error! {{model.message}}')); this.register('route:post.comments', _emberRouting.Route.extend({ model: function () { return _emberRuntime.RSVP.reject(new Error('Oh, noes!')); } })); }); return this.visit('/').then(function () { _this15.assertText('Application'); return _this15.transitionTo('blog.post.comments'); }).catch(function () { _this15.assertText('ApplicationEngineError! Oh, noes!'); }); }; _class.prototype['@test loading substate route works for the application route of an Engine'] = function (assert) { var _this16 = this; assert.expect(3); var resolveLoading = void 0; this.setupAppAndRoutableEngine(); this.additionalEngineRegistrations(function () { this.register('template:application_loading', (0, _helpers.compile)('Loading')); this.register('template:post', (0, _helpers.compile)('Post')); this.register('route:post', _emberRouting.Route.extend({ model: function () { return new _emberRuntime.RSVP.Promise(function (resolve) { resolveLoading = resolve; }); } })); }); return this.visit('/').then(function () { _this16.assertText('Application'); var transition = _this16.transitionTo('blog.post'); _this16.runTaskNext(function () { _this16.assertText('ApplicationLoading'); resolveLoading(); }); return transition.then(function () { _this16.runTaskNext(function () { return _this16.assertText('ApplicationEnginePost'); }); }); }); }; _class.prototype['@test loading route works for the application route of an Engine'] = function (assert) { var _this17 = this; assert.expect(3); var resolveLoading = void 0; this.setupAppAndRoutableEngine(); this.additionalEngineRegistrations(function () { this.register('template:loading', (0, _helpers.compile)('Loading')); this.register('template:post', (0, _helpers.compile)('Post')); this.register('route:post', _emberRouting.Route.extend({ model: function () { return new _emberRuntime.RSVP.Promise(function (resolve) { resolveLoading = resolve; }); } })); }); return this.visit('/').then(function () { _this17.assertText('Application'); var transition = _this17.transitionTo('blog.post'); _this17.runTaskNext(function () { _this17.assertText('ApplicationEngineLoading'); resolveLoading(); }); return transition.then(function () { _this17.runTaskNext(function () { return _this17.assertText('ApplicationEnginePost'); }); }); }); }; _class.prototype['@test loading substate route works for a child route of an Engine'] = function (assert) { var _this18 = this; assert.expect(3); var resolveLoading = void 0; this.setupAppAndRoutableEngine(); this.additionalEngineRegistrations(function () { this.register('template:post', (0, _helpers.compile)('{{outlet}}')); this.register('template:post.comments', (0, _helpers.compile)('Comments')); this.register('template:post.likes_loading', (0, _helpers.compile)('Loading')); this.register('template:post.likes', (0, _helpers.compile)('Likes')); this.register('route:post.likes', _emberRouting.Route.extend({ model: function () { return new _emberRuntime.RSVP.Promise(function (resolve) { resolveLoading = resolve; }); } })); }); return this.visit('/blog/post/comments').then(function () { _this18.assertText('ApplicationEngineComments'); var transition = _this18.transitionTo('blog.post.likes'); _this18.runTaskNext(function () { _this18.assertText('ApplicationEngineLoading'); resolveLoading(); }); return transition.then(function () { _this18.runTaskNext(function () { return _this18.assertText('ApplicationEngineLikes'); }); }); }); }; _class.prototype['@test loading route works for a child route of an Engine'] = function (assert) { var _this19 = this; assert.expect(3); var resolveLoading = void 0; this.setupAppAndRoutableEngine(); this.additionalEngineRegistrations(function () { this.register('template:post', (0, _helpers.compile)('{{outlet}}')); this.register('template:post.comments', (0, _helpers.compile)('Comments')); this.register('template:post.loading', (0, _helpers.compile)('Loading')); this.register('template:post.likes', (0, _helpers.compile)('Likes')); this.register('route:post.likes', _emberRouting.Route.extend({ model: function () { return new _emberRuntime.RSVP.Promise(function (resolve) { resolveLoading = resolve; }); } })); }); return this.visit('/blog/post/comments').then(function () { _this19.assertText('ApplicationEngineComments'); var transition = _this19.transitionTo('blog.post.likes'); _this19.runTaskNext(function () { _this19.assertText('ApplicationEngineLoading'); resolveLoading(); }); return transition.then(function () { _this19.runTaskNext(function () { return _this19.assertText('ApplicationEngineLikes'); }); }); }); }; _class.prototype['@test query params don\'t have stickiness by default between model'] = function (assert) { var _this20 = this; assert.expect(1); this.setupAppAndRoutableEngine(); this.additionalEngineRegistrations(function () { this.register('template:category', (0, _helpers.compile)('{{#link-to "blog.category" 1337}}Category 1337{{/link-to}}')); }); return this.visit('/blog/category/1?type=news').then(function () { var href = _this20.element.querySelector('a').href; // check if link ends with the suffix assert.ok(_this20.stringsEndWith(href, '/blog/category/1337')); }); }; _class.prototype['@test query params in customized controllerName have stickiness by default between model'] = function (assert) { var _this21 = this; assert.expect(2); this.setupAppAndRoutableEngine(); this.additionalEngineRegistrations(function () { this.register('template:author', (0, _helpers.compile)('{{#link-to "blog.author" 1337 class="author-1337"}}Author 1337{{/link-to}}{{#link-to "blog.author" 1 class="author-1"}}Author 1{{/link-to}}')); }); return this.visit('/blog/author/1?official=true').then(function () { var href1 = _this21.element.querySelector('.author-1').href; var href1337 = _this21.element.querySelector('.author-1337').href; // check if link ends with the suffix assert.ok(_this21.stringsEndWith(href1, '/blog/author/1?official=true')); assert.ok(_this21.stringsEndWith(href1337, '/blog/author/1337')); }); }; return _class; }(_testCase.ApplicationTest)); }); enifed('ember-glimmer/tests/integration/application/rendering-test', ['ember-babel', 'ember-runtime', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-routing', 'ember-glimmer'], function (_emberBabel, _emberRuntime, _testCase, _abstractTestCase, _emberRouting, _emberGlimmer) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n {{#each model as |item|}}\n
  • {{item}}
  • \n {{/each}}\n
\n '], ['\n
    \n {{#each model as |item|}}\n
  • {{item}}
  • \n {{/each}}\n
\n ']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n
  • red
  • \n
  • yellow
  • \n
  • blue
  • \n
\n '], ['\n
    \n
  • red
  • \n
  • yellow
  • \n
  • blue
  • \n
\n ']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n
{{outlet}}
\n '], ['\n \n
{{outlet}}
\n ']), _templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n Ember\n '], ['\n Ember\n ']), _templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n
\n
    \n
  • red
  • \n
  • yellow
  • \n
  • blue
  • \n
\n
\n '], ['\n \n
\n
    \n
  • red
  • \n
  • yellow
  • \n
  • blue
  • \n
\n
\n ']); (0, _testCase.moduleFor)('Application test: rendering', function (_ApplicationTest) { (0, _emberBabel.inherits)(_class, _ApplicationTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTest.apply(this, arguments)); } _class.prototype['@test it can render the application template'] = function () { var _this2 = this; this.addTemplate('application', 'Hello world!'); return this.visit('/').then(function () { _this2.assertText('Hello world!'); }); }; _class.prototype['@test it can access the model provided by the route'] = function () { var _this3 = this; this.add('route:application', _emberRouting.Route.extend({ model: function () { return ['red', 'yellow', 'blue']; } })); this.addTemplate('application', (0, _abstractTestCase.strip)(_templateObject)); return this.visit('/').then(function () { _this3.assertComponentElement(_this3.firstChild, { content: (0, _abstractTestCase.strip)(_templateObject2) }); }); }; _class.prototype['@test it can render a nested route'] = function () { var _this4 = this; this.router.map(function () { this.route('lists', function () { this.route('colors', function () { this.route('favorite'); }); }); }); // The "favorite" route will inherit the model this.add('route:lists.colors', _emberRouting.Route.extend({ model: function () { return ['red', 'yellow', 'blue']; } })); this.addTemplate('lists.colors.favorite', (0, _abstractTestCase.strip)(_templateObject)); return this.visit('/lists/colors/favorite').then(function () { _this4.assertComponentElement(_this4.firstChild, { content: (0, _abstractTestCase.strip)(_templateObject2) }); }); }; _class.prototype['@test it can render into named outlets'] = function () { var _this5 = this; this.router.map(function () { this.route('colors'); }); this.addTemplate('application', (0, _abstractTestCase.strip)(_templateObject3)); this.addTemplate('nav', (0, _abstractTestCase.strip)(_templateObject4)); this.add('route:application', _emberRouting.Route.extend({ renderTemplate: function () { this.render(); this.render('nav', { into: 'application', outlet: 'nav' }); } })); this.add('route:colors', _emberRouting.Route.extend({ model: function () { return ['red', 'yellow', 'blue']; } })); this.addTemplate('colors', (0, _abstractTestCase.strip)(_templateObject)); return this.visit('/colors').then(function () { _this5.assertComponentElement(_this5.firstChild, { content: (0, _abstractTestCase.strip)(_templateObject5) }); }); }; _class.prototype['@test it can render into named outlets'] = function () { var _this6 = this; this.router.map(function () { this.route('colors'); }); this.addTemplate('application', (0, _abstractTestCase.strip)(_templateObject3)); this.addTemplate('nav', (0, _abstractTestCase.strip)(_templateObject4)); this.add('route:application', _emberRouting.Route.extend({ renderTemplate: function () { this.render(); this.render('nav', { into: 'application', outlet: 'nav' }); } })); this.add('route:colors', _emberRouting.Route.extend({ model: function () { return ['red', 'yellow', 'blue']; } })); this.addTemplate('colors', (0, _abstractTestCase.strip)(_templateObject)); return this.visit('/colors').then(function () { _this6.assertComponentElement(_this6.firstChild, { content: (0, _abstractTestCase.strip)(_templateObject5) }); }); }; _class.prototype['@test it should update the outlets when switching between routes'] = function () { var _this7 = this; this.router.map(function () { this.route('a'); this.route('b', function () { this.route('c'); this.route('d'); }); }); this.addTemplate('a', 'A{{outlet}}'); this.addTemplate('b', 'B{{outlet}}'); this.addTemplate('b.c', 'C'); this.addTemplate('b.d', 'D'); return this.visit('/b/c').then(function () { // this.assertComponentElement(this.firstChild, { content: 'BC' }); _this7.assertText('BC'); return _this7.visit('/a'); }).then(function () { // this.assertComponentElement(this.firstChild, { content: 'A' }); _this7.assertText('A'); return _this7.visit('/b/d'); }).then(function () { _this7.assertText('BD'); // this.assertComponentElement(this.firstChild, { content: 'BD' }); }); }; _class.prototype['@test it should produce a stable DOM when the model changes'] = function () { var _this8 = this; this.router.map(function () { this.route('color', { path: '/colors/:color' }); }); this.add('route:color', _emberRouting.Route.extend({ model: function (params) { return params.color; } })); this.addTemplate('color', 'color: {{model}}'); return this.visit('/colors/red').then(function () { _this8.assertComponentElement(_this8.firstChild, { content: 'color: red' }); _this8.takeSnapshot(); return _this8.visit('/colors/green'); }).then(function () { _this8.assertComponentElement(_this8.firstChild, { content: 'color: green' }); _this8.assertInvariants(); }); }; _class.prototype['@test it should have the right controller in scope for the route template'] = function () { var _this9 = this; this.router.map(function () { this.route('a'); this.route('b'); }); this.add('controller:a', _emberRuntime.Controller.extend({ value: 'a' })); this.add('controller:b', _emberRuntime.Controller.extend({ value: 'b' })); this.addTemplate('a', '{{value}}'); this.addTemplate('b', '{{value}}'); return this.visit('/a').then(function () { _this9.assertText('a'); return _this9.visit('/b'); }).then(function () { return _this9.assertText('b'); }); }; _class.prototype['@test it should update correctly when the controller changes'] = function () { var _this10 = this; this.router.map(function () { this.route('color', { path: '/colors/:color' }); }); this.add('route:color', _emberRouting.Route.extend({ model: function (params) { return { color: params.color }; }, renderTemplate: function (controller, model) { this.render({ controller: model.color, model: model }); } })); this.add('controller:red', _emberRuntime.Controller.extend({ color: 'red' })); this.add('controller:green', _emberRuntime.Controller.extend({ color: 'green' })); this.addTemplate('color', 'model color: {{model.color}}, controller color: {{color}}'); return this.visit('/colors/red').then(function () { _this10.assertComponentElement(_this10.firstChild, { content: 'model color: red, controller color: red' }); _this10.takeSnapshot(); return _this10.visit('/colors/green'); }).then(function () { _this10.assertComponentElement(_this10.firstChild, { content: 'model color: green, controller color: green' }); _this10.assertInvariants(); }); }; _class.prototype['@test it should produce a stable DOM when two routes render the same template'] = function () { var _this11 = this; this.router.map(function () { this.route('a'); this.route('b'); }); this.add('route:a', _emberRouting.Route.extend({ model: function () { return 'A'; }, renderTemplate: function (controller, model) { this.render('common', { controller: 'common', model: model }); } })); this.add('route:b', _emberRouting.Route.extend({ model: function () { return 'B'; }, renderTemplate: function (controller, model) { this.render('common', { controller: 'common', model: model }); } })); this.add('controller:common', _emberRuntime.Controller.extend({ prefix: 'common' })); this.addTemplate('common', '{{prefix}} {{model}}'); return this.visit('/a').then(function () { _this11.assertComponentElement(_this11.firstChild, { content: 'common A' }); _this11.takeSnapshot(); return _this11.visit('/b'); }).then(function () { _this11.assertComponentElement(_this11.firstChild, { content: 'common B' }); _this11.assertInvariants(); }); }; _class.prototype['@test a child outlet is always a fragment'] = function () { var _this12 = this; this.addTemplate('application', '{{outlet}}'); this.addTemplate('index', '{{#if true}}1{{/if}}
2
'); return this.visit('/').then(function () { _this12.assertComponentElement(_this12.firstChild, { content: '1
2
' }); }); }; _class.prototype['@test it allows a transition during route activate'] = function () { var _this13 = this; this.router.map(function () { this.route('a'); }); this.add('route:index', _emberRouting.Route.extend({ activate: function () { this.transitionTo('a'); } })); this.addTemplate('a', 'Hello from A!'); return this.visit('/').then(function () { _this13.assertComponentElement(_this13.firstChild, { content: 'Hello from A!' }); }); }; _class.prototype['@test it emits a useful backtracking re-render assertion message'] = function () { var _this14 = this; this.router.map(function () { this.route('routeWithError'); }); this.add('route:routeWithError', _emberRouting.Route.extend({ model: function () { return { name: 'Alex' }; } })); this.addTemplate('routeWithError', 'Hi {{model.name}} {{x-foo person=model}}'); this.addComponent('x-foo', { ComponentClass: _emberGlimmer.Component.extend({ init: function () { this._super.apply(this, arguments); this.set('person.name', 'Ben'); } }), template: 'Hi {{person.name}} from component' }); var expectedBacktrackingMessage = /modified "model\.name" twice on \[object Object\] in a single render\. It was rendered in "template:routeWithError" and modified in "component:x-foo"/; return this.visit('/').then(function () { expectAssertion(function () { _this14.visit('/routeWithError'); }, expectedBacktrackingMessage); }); }; return _class; }(_testCase.ApplicationTest)); }); enifed('ember-glimmer/tests/integration/binding_integration_test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal'], function (_emberBabel, _testCase, _helpers, _emberMetal) { 'use strict'; (0, _testCase.moduleFor)('Binding integration tests', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test should accept bindings as a string or an Ember.binding'] = function () { var _this2 = this; var FooBarComponent = _helpers.Component.extend({ twoWayTestBinding: _emberMetal.Binding.from('direction'), stringTestBinding: 'direction', twoWayObjectTestBinding: _emberMetal.Binding.from('displacement.distance'), stringObjectTestBinding: 'displacement.distance' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'two way: {{twoWayTest}}, string: {{stringTest}}, object: {{twoWayObjectTest}}, string object: {{stringObjectTest}}' }); expectDeprecation(function () { _this2.render('{{foo-bar direction=direction displacement=displacement}}', { direction: 'down', displacement: { distance: 10 } }); }, /`Ember\.Binding` is deprecated/); this.assertText('two way: down, string: down, object: 10, string object: 10'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'direction', 'up'); }); this.assertText('two way: up, string: up, object: 10, string object: 10'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'displacement.distance', 20); }); this.assertText('two way: up, string: up, object: 20, string object: 20'); this.runTask(function () { (0, _emberMetal.set)(_this2.context, 'direction', 'right'); (0, _emberMetal.set)(_this2.context, 'displacement.distance', 30); }); this.assertText('two way: right, string: right, object: 30, string object: 30'); this.runTask(function () { (0, _emberMetal.set)(_this2.context, 'direction', 'down'); (0, _emberMetal.set)(_this2.context, 'displacement', { distance: 10 }); }); this.assertText('two way: down, string: down, object: 10, string object: 10'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/append-test', ['ember-babel', 'ember-metal', 'ember-views', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _emberMetal, _emberViews, _testCase, _helpers, _abstractTestCase) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if showFooBar}}\n {{foo-bar}}\n {{else}}\n {{baz-qux}}\n {{/if}}\n '], ['\n {{#if showFooBar}}\n {{foo-bar}}\n {{else}}\n {{baz-qux}}\n {{/if}}\n ']); var AbstractAppendTest = function (_RenderingTest) { (0, _emberBabel.inherits)(AbstractAppendTest, _RenderingTest); function AbstractAppendTest() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this)); _this.components = []; _this.ids = []; return _this; } AbstractAppendTest.prototype.teardown = function () { var _this2 = this; this.component = null; this.components.forEach(function (component) { _this2.runTask(function () { return component.destroy(); }); }); this.ids.forEach(function (id) { var $element = (0, _emberViews.jQuery)(id).remove(); _this2.assert.strictEqual($element.length, 0, 'Should not leak element: #' + id); }); _RenderingTest.prototype.teardown.call(this); }; AbstractAppendTest.prototype.didAppend = function (component) { this.components.push(component); this.ids.push(component.elementId); }; AbstractAppendTest.prototype['@test lifecycle hooks during component append'] = function (assert) { var _this4 = this; var hooks = []; var oldRegisterComponent = this.registerComponent; var componentsByName = {}; // TODO: refactor/combine with other life-cycle tests this.registerComponent = function (name, _options) { function pushHook(hookName) { hooks.push([name, hookName]); } var options = { ComponentClass: _options.ComponentClass.extend({ init: function () { var _this3 = this, _arguments = arguments; expectDeprecation(function () { _this3._super.apply(_this3, _arguments); }, /didInitAttrs called/); if (name in componentsByName) { throw new TypeError('Component named: ` ' + name + ' ` already registered'); } componentsByName[name] = this; pushHook('init'); this.on('init', function () { return pushHook('on(init)'); }); }, didInitAttrs: function (options) { pushHook('didInitAttrs', options); }, didReceiveAttrs: function () { pushHook('didReceiveAttrs'); }, willInsertElement: function () { pushHook('willInsertElement'); }, willRender: function () { pushHook('willRender'); }, didInsertElement: function () { pushHook('didInsertElement'); }, didRender: function () { pushHook('didRender'); }, didUpdateAttrs: function () { pushHook('didUpdateAttrs'); }, willUpdate: function () { pushHook('willUpdate'); }, didUpdate: function () { pushHook('didUpdate'); }, willDestroyElement: function () { pushHook('willDestroyElement'); }, willClearRender: function () { pushHook('willClearRender'); }, didDestroyElement: function () { pushHook('didDestroyElement'); }, willDestroy: function () { pushHook('willDestroy'); this._super.apply(this, arguments); } }), template: _options.template }; oldRegisterComponent.call(this, name, options); }; this.registerComponent('x-parent', { ComponentClass: _helpers.Component.extend({ layoutName: 'components/x-parent' }), template: '[parent: {{foo}}]{{#x-child bar=foo}}[yielded: {{foo}}]{{/x-child}}' }); this.registerComponent('x-child', { ComponentClass: _helpers.Component.extend({ tagName: '' }), template: '[child: {{bar}}]{{yield}}' }); var XParent = void 0; XParent = this.owner.factoryFor('component:x-parent'); this.component = XParent.create({ foo: 'zomg' }); assert.deepEqual(hooks, [['x-parent', 'init'], ['x-parent', 'didInitAttrs'], ['x-parent', 'didReceiveAttrs'], ['x-parent', 'on(init)']], 'creation of x-parent'); hooks.length = 0; this.element = this.append(this.component); assert.deepEqual(hooks, [['x-parent', 'willInsertElement'], ['x-child', 'init'], ['x-child', 'didInitAttrs'], ['x-child', 'didReceiveAttrs'], ['x-child', 'on(init)'], ['x-child', 'willRender'], ['x-child', 'willInsertElement'], ['x-child', 'didInsertElement'], ['x-child', 'didRender'], ['x-parent', 'didInsertElement'], ['x-parent', 'didRender']], 'appending of x-parent'); hooks.length = 0; this.runTask(function () { return componentsByName['x-parent'].rerender(); }); assert.deepEqual(hooks, [['x-parent', 'willUpdate'], ['x-parent', 'willRender'], ['x-parent', 'didUpdate'], ['x-parent', 'didRender']], 'rerender x-parent'); hooks.length = 0; this.runTask(function () { return componentsByName['x-child'].rerender(); }); assert.deepEqual(hooks, [['x-parent', 'willUpdate'], ['x-parent', 'willRender'], ['x-child', 'willUpdate'], ['x-child', 'willRender'], ['x-child', 'didUpdate'], ['x-child', 'didRender'], ['x-parent', 'didUpdate'], ['x-parent', 'didRender']], 'rerender x-child'); hooks.length = 0; this.runTask(function () { return (0, _emberMetal.set)(_this4.component, 'foo', 'wow'); }); assert.deepEqual(hooks, [['x-parent', 'willUpdate'], ['x-parent', 'willRender'], ['x-child', 'didUpdateAttrs'], ['x-child', 'didReceiveAttrs'], ['x-child', 'willUpdate'], ['x-child', 'willRender'], ['x-child', 'didUpdate'], ['x-child', 'didRender'], ['x-parent', 'didUpdate'], ['x-parent', 'didRender']], 'set foo = wow'); hooks.length = 0; this.runTask(function () { return (0, _emberMetal.set)(_this4.component, 'foo', 'zomg'); }); assert.deepEqual(hooks, [['x-parent', 'willUpdate'], ['x-parent', 'willRender'], ['x-child', 'didUpdateAttrs'], ['x-child', 'didReceiveAttrs'], ['x-child', 'willUpdate'], ['x-child', 'willRender'], ['x-child', 'didUpdate'], ['x-child', 'didRender'], ['x-parent', 'didUpdate'], ['x-parent', 'didRender']], 'set foo = zomg'); hooks.length = 0; this.runTask(function () { return _this4.component.destroy(); }); assert.deepEqual(hooks, [['x-parent', 'willDestroyElement'], ['x-parent', 'willClearRender'], ['x-child', 'willDestroyElement'], ['x-child', 'willClearRender'], ['x-child', 'didDestroyElement'], ['x-parent', 'didDestroyElement'], ['x-parent', 'willDestroy'], ['x-child', 'willDestroy']], 'destroy'); }; AbstractAppendTest.prototype['@test appending, updating and destroying a single component'] = function (assert) { var _this5 = this; var willDestroyCalled = 0; this.registerComponent('x-parent', { ComponentClass: _helpers.Component.extend({ layoutName: 'components/x-parent', willDestroyElement: function () { willDestroyCalled++; } }), template: '[parent: {{foo}}]{{#x-child bar=foo}}[yielded: {{foo}}]{{/x-child}}' }); this.registerComponent('x-child', { ComponentClass: _helpers.Component.extend({ tagName: '' }), template: '[child: {{bar}}]{{yield}}' }); var XParent = void 0; XParent = this.owner.factoryFor('component:x-parent'); this.component = XParent.create({ foo: 'zomg' }); assert.ok(!this.component.element, 'precond - should not have an element'); this.element = this.append(this.component); var componentElement = this.component.element; this.assertComponentElement(componentElement, { content: '[parent: zomg][child: zomg][yielded: zomg]' }); assert.equal(componentElement.parentElement, this.element, 'It should be attached to the target'); this.runTask(function () { return _this5.rerender(); }); this.assertComponentElement(componentElement, { content: '[parent: zomg][child: zomg][yielded: zomg]' }); assert.equal(componentElement.parentElement, this.element, 'It should be attached to the target'); this.runTask(function () { return (0, _emberMetal.set)(_this5.component, 'foo', 'wow'); }); this.assertComponentElement(componentElement, { content: '[parent: wow][child: wow][yielded: wow]' }); assert.equal(componentElement.parentElement, this.element, 'It should be attached to the target'); this.runTask(function () { return (0, _emberMetal.set)(_this5.component, 'foo', 'zomg'); }); this.assertComponentElement(componentElement, { content: '[parent: zomg][child: zomg][yielded: zomg]' }); assert.equal(componentElement.parentElement, this.element, 'It should be attached to the target'); this.runTask(function () { return _this5.component.destroy(); }); if (this.isHTMLBars) { // Bug in Glimmer – component should not have .element at this point assert.ok(!this.component.element, 'It should not have an element'); } assert.ok(!componentElement.parentElement, 'The component element should be detached'); this.assert.equal(willDestroyCalled, 1); }; AbstractAppendTest.prototype['@test appending, updating and destroying multiple components'] = function (assert) { var _this6 = this; var willDestroyCalled = 0; this.registerComponent('x-first', { ComponentClass: _helpers.Component.extend({ layoutName: 'components/x-first', willDestroyElement: function () { willDestroyCalled++; } }), template: 'x-first {{foo}}!' }); this.registerComponent('x-second', { ComponentClass: _helpers.Component.extend({ layoutName: 'components/x-second', willDestroyElement: function () { willDestroyCalled++; } }), template: 'x-second {{bar}}!' }); var First = void 0, Second = void 0; First = this.owner.factoryFor('component:x-first'); Second = this.owner.factoryFor('component:x-second'); var first = First.create({ foo: 'foo' }); var second = Second.create({ bar: 'bar' }); this.assert.ok(!first.element, 'precond - should not have an element'); this.assert.ok(!second.element, 'precond - should not have an element'); var wrapper1 = void 0, wrapper2 = void 0; this.runTask(function () { return wrapper1 = _this6.append(first); }); this.runTask(function () { return wrapper2 = _this6.append(second); }); var componentElement1 = first.element; var componentElement2 = second.element; this.assertComponentElement(componentElement1, { content: 'x-first foo!' }); this.assertComponentElement(componentElement2, { content: 'x-second bar!' }); assert.equal(componentElement1.parentElement, wrapper1, 'The first component should be attached to the target'); assert.equal(componentElement2.parentElement, wrapper2, 'The second component should be attached to the target'); this.runTask(function () { return (0, _emberMetal.set)(first, 'foo', 'FOO'); }); this.assertComponentElement(componentElement1, { content: 'x-first FOO!' }); this.assertComponentElement(componentElement2, { content: 'x-second bar!' }); assert.equal(componentElement1.parentElement, wrapper1, 'The first component should be attached to the target'); assert.equal(componentElement2.parentElement, wrapper2, 'The second component should be attached to the target'); this.runTask(function () { return (0, _emberMetal.set)(second, 'bar', 'BAR'); }); this.assertComponentElement(componentElement1, { content: 'x-first FOO!' }); this.assertComponentElement(componentElement2, { content: 'x-second BAR!' }); assert.equal(componentElement1.parentElement, wrapper1, 'The first component should be attached to the target'); assert.equal(componentElement2.parentElement, wrapper2, 'The second component should be attached to the target'); this.runTask(function () { (0, _emberMetal.set)(first, 'foo', 'foo'); (0, _emberMetal.set)(second, 'bar', 'bar'); }); this.assertComponentElement(componentElement1, { content: 'x-first foo!' }); this.assertComponentElement(componentElement2, { content: 'x-second bar!' }); assert.equal(componentElement1.parentElement, wrapper1, 'The first component should be attached to the target'); assert.equal(componentElement2.parentElement, wrapper2, 'The second component should be attached to the target'); this.runTask(function () { first.destroy(); second.destroy(); }); if (this.isHTMLBars) { // Bug in Glimmer – component should not have .element at this point assert.ok(!first.element, 'The first component should not have an element'); assert.ok(!second.element, 'The second component should not have an element'); } assert.ok(!componentElement1.parentElement, 'The first component element should be detached'); assert.ok(!componentElement2.parentElement, 'The second component element should be detached'); this.assert.equal(willDestroyCalled, 2); }; AbstractAppendTest.prototype['@test can appendTo while rendering'] = function () { var _this7 = this; var owner = this.owner; var append = function (component) { return _this7.append(component); }; var element1 = void 0, element2 = void 0; this.registerComponent('first-component', { ComponentClass: _helpers.Component.extend({ layout: (0, _helpers.compile)('component-one'), didInsertElement: function () { element1 = this.element; var SecondComponent = owner.factoryFor('component:second-component'); append(SecondComponent.create()); } }) }); this.registerComponent('second-component', { ComponentClass: _helpers.Component.extend({ layout: (0, _helpers.compile)('component-two'), didInsertElement: function () { element2 = this.element; } }) }); var FirstComponent = this.owner.factoryFor('component:first-component'); this.runTask(function () { return append(FirstComponent.create()); }); this.assertComponentElement(element1, { content: 'component-one' }); this.assertComponentElement(element2, { content: 'component-two' }); }; AbstractAppendTest.prototype['@test can appendTo and remove while rendering'] = function (assert) { var _this8 = this; var owner = this.owner; var append = function (component) { return _this8.append(component); }; var element1 = void 0, element2 = void 0, element3 = void 0, element4 = void 0, component1 = void 0, component2 = void 0; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ layout: (0, _helpers.compile)('foo-bar'), init: function () { this._super.apply(this, arguments); component1 = this; }, didInsertElement: function () { element1 = this.element; var OtherRoot = owner.factoryFor('component:other-root'); this._instance = OtherRoot.create({ didInsertElement: function () { element2 = this.element; } }); append(this._instance); }, willDestroy: function () { this._instance.destroy(); } }) }); this.registerComponent('baz-qux', { ComponentClass: _helpers.Component.extend({ layout: (0, _helpers.compile)('baz-qux'), init: function () { this._super.apply(this, arguments); component2 = this; }, didInsertElement: function () { element3 = this.element; var OtherRoot = owner.factoryFor('component:other-root'); this._instance = OtherRoot.create({ didInsertElement: function () { element4 = this.element; } }); append(this._instance); }, willDestroy: function () { this._instance.destroy(); } }) }); var instantiatedRoots = 0; var destroyedRoots = 0; this.registerComponent('other-root', { ComponentClass: _helpers.Component.extend({ layout: (0, _helpers.compile)('fake-thing: {{counter}}'), init: function () { this._super.apply(this, arguments); this.counter = instantiatedRoots++; }, willDestroy: function () { destroyedRoots++; this._super.apply(this, arguments); } }) }); this.render((0, _abstractTestCase.strip)(_templateObject), { showFooBar: true }); this.assertComponentElement(element1, {}); this.assertComponentElement(element2, { content: 'fake-thing: 0' }); assert.equal(instantiatedRoots, 1); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'showFooBar', false); }); assert.equal(instantiatedRoots, 2); assert.equal(destroyedRoots, 1); this.assertComponentElement(element3, {}); this.assertComponentElement(element4, { content: 'fake-thing: 1' }); this.runTask(function () { component1.destroy(); component2.destroy(); }); assert.equal(instantiatedRoots, 2); assert.equal(destroyedRoots, 2); }; return AbstractAppendTest; }(_testCase.RenderingTest); (0, _testCase.moduleFor)('append: no arguments (attaching to document.body)', function (_AbstractAppendTest) { (0, _emberBabel.inherits)(_class, _AbstractAppendTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractAppendTest.apply(this, arguments)); } _class.prototype.append = function (component) { this.runTask(function () { return component.append(); }); this.didAppend(component); return document.body; }; return _class; }(AbstractAppendTest)); (0, _testCase.moduleFor)('appendTo: a selector', function (_AbstractAppendTest2) { (0, _emberBabel.inherits)(_class2, _AbstractAppendTest2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractAppendTest2.apply(this, arguments)); } _class2.prototype.append = function (component) { this.runTask(function () { return component.appendTo('#qunit-fixture'); }); this.didAppend(component); return (0, _emberViews.jQuery)('#qunit-fixture')[0]; }; _class2.prototype['@test raises an assertion when the target does not exist in the DOM'] = function (assert) { var _this11 = this; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ layoutName: 'components/foo-bar' }), template: 'FOO BAR!' }); var FooBar = this.owner.factoryFor('component:foo-bar'); this.component = FooBar.create(); assert.ok(!this.component.element, 'precond - should not have an element'); this.runTask(function () { expectAssertion(function () { _this11.component.appendTo('#does-not-exist-in-dom'); }, /You tried to append to \(#does-not-exist-in-dom\) but that isn't in the DOM/); }); assert.ok(!this.component.element, 'component should not have an element'); }; return _class2; }(AbstractAppendTest)); (0, _testCase.moduleFor)('appendTo: an element', function (_AbstractAppendTest3) { (0, _emberBabel.inherits)(_class3, _AbstractAppendTest3); function _class3() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractAppendTest3.apply(this, arguments)); } _class3.prototype.append = function (component) { var element = (0, _emberViews.jQuery)('#qunit-fixture')[0]; this.runTask(function () { return component.appendTo(element); }); this.didAppend(component); return element; }; return _class3; }(AbstractAppendTest)); (0, _testCase.moduleFor)('appendTo: with multiple components', function (_AbstractAppendTest4) { (0, _emberBabel.inherits)(_class4, _AbstractAppendTest4); function _class4() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractAppendTest4.apply(this, arguments)); } _class4.prototype.append = function (component) { this.runTask(function () { return component.appendTo('#qunit-fixture'); }); this.didAppend(component); return (0, _emberViews.jQuery)('#qunit-fixture')[0]; }; return _class4; }(AbstractAppendTest)); (0, _testCase.moduleFor)('renderToElement: no arguments (defaults to a body context)', function (_AbstractAppendTest5) { (0, _emberBabel.inherits)(_class5, _AbstractAppendTest5); function _class5() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractAppendTest5.apply(this, arguments)); } _class5.prototype.append = function (component) { expectDeprecation(/Using the `renderToElement` is deprecated in favor of `appendTo`. Called in/); var wrapper = void 0; this.runTask(function () { return wrapper = component.renderToElement(); }); this.didAppend(component); this.assert.equal(wrapper.tagName, 'BODY', 'wrapper is a body element'); this.assert.notEqual(wrapper, document.body, 'wrapper is not document.body'); this.assert.ok(!wrapper.parentNode, 'wrapper is detached'); return wrapper; }; return _class5; }(AbstractAppendTest)); (0, _testCase.moduleFor)('renderToElement: a div', function (_AbstractAppendTest6) { (0, _emberBabel.inherits)(_class6, _AbstractAppendTest6); function _class6() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractAppendTest6.apply(this, arguments)); } _class6.prototype.append = function (component) { expectDeprecation(/Using the `renderToElement` is deprecated in favor of `appendTo`. Called in/); var wrapper = void 0; this.runTask(function () { return wrapper = component.renderToElement('div'); }); this.didAppend(component); this.assert.equal(wrapper.tagName, 'DIV', 'wrapper is a body element'); this.assert.ok(!wrapper.parentNode, 'wrapper is detached'); return wrapper; }; return _class6; }(AbstractAppendTest)); }); enifed('ember-glimmer/tests/integration/components/attribute-bindings-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-metal'], function (_emberBabel, _testCase, _helpers, _abstractTestCase, _emberMetal) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{foo-bar hasFoo=true foo=foo hasBar=false bar=bar}}\n {{foo-bar hasFoo=false foo=foo hasBar=true bar=bar}}\n {{foo-bar hasFoo=true foo=foo hasBar=true bar=bar}}\n {{foo-bar hasFoo=false foo=foo hasBar=false bar=bar}}\n '], ['\n {{foo-bar hasFoo=true foo=foo hasBar=false bar=bar}}\n {{foo-bar hasFoo=false foo=foo hasBar=true bar=bar}}\n {{foo-bar hasFoo=true foo=foo hasBar=true bar=bar}}\n {{foo-bar hasFoo=false foo=foo hasBar=false bar=bar}}\n ']); (0, _testCase.moduleFor)('Attribute bindings integration', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test it can have attribute bindings'] = function () { var _this2 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['foo:data-foo', 'bar:data-bar'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar foo=foo bar=bar}}', { foo: 'foo', bar: 'bar' }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo': 'foo', 'data-bar': 'bar' }, content: 'hello' }); this.runTask(function () { return _this2.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo': 'foo', 'data-bar': 'bar' }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this2.context, 'foo', 'FOO'); (0, _emberMetal.set)(_this2.context, 'bar', undefined); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo': 'FOO' }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this2.context, 'foo', 'foo'); (0, _emberMetal.set)(_this2.context, 'bar', 'bar'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo': 'foo', 'data-bar': 'bar' }, content: 'hello' }); }; _class.prototype['@test it can have attribute bindings with attrs'] = function () { var _this3 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['attrs.foo:data-foo', 'attrs.baz.bar:data-bar'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar foo=model.foo baz=model.baz}}', { model: { foo: undefined, baz: { bar: 'bar' } } }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'data-bar': 'bar' } }); this.runTask(function () { return _this3.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'data-bar': 'bar' } }); this.runTask(function () { (0, _emberMetal.set)(_this3.context, 'model.foo', 'foo'); (0, _emberMetal.set)(_this3.context, 'model.baz.bar', undefined); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo': 'foo' }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'model', { foo: undefined, baz: { bar: 'bar' } }); }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'data-bar': 'bar' } }); }; _class.prototype['@test it can have attribute bindings with a nested path'] = function () { var _this4 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['foo.bar:data-foo-bar'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar foo=foo}}', { foo: { bar: 'foo-bar' } }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo-bar': 'foo-bar' }, content: 'hello' }); this.runTask(function () { return _this4.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo-bar': 'foo-bar' }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'foo.bar', 'FOO-BAR'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo-bar': 'FOO-BAR' }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'foo.bar', undefined); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: {}, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'foo', undefined); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: {}, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'foo', { bar: 'foo-bar' }); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo-bar': 'foo-bar' }, content: 'hello' }); }; _class.prototype['@test handles non-microsyntax attributeBindings'] = function () { var _this5 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['type'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar type=submit}}', { submit: 'submit' }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { type: 'submit' }, content: 'hello' }); this.runTask(function () { return _this5.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { type: 'submit' }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'submit', 'password'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { type: 'password' }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'submit', null); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: {}, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'submit', 'submit'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { type: 'submit' }, content: 'hello' }); }; _class.prototype['@test non-microsyntax attributeBindings cannot contain nested paths'] = function () { var _this6 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['foo.bar'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); expectAssertion(function () { _this6.render('{{foo-bar foo=foo}}', { foo: { bar: 'foo-bar' } }); }, /Illegal attributeBinding: 'foo.bar' is not a valid attribute name./); }; _class.prototype['@test normalizes attributeBindings for property names'] = function () { var _this7 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['tiTLe'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar tiTLe=name}}', { name: 'qux' }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { title: 'qux' }, content: 'hello' }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'name', null); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: {}, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'name', 'qux'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { title: 'qux' }, content: 'hello' }); }; _class.prototype['@test normalizes attributeBindings for attribute names'] = function () { var _this8 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['foo:data-FOO'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar foo=foo}}', { foo: 'qux' }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo': 'qux' }, content: 'hello' }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'foo', null); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: {}, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'foo', 'qux'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo': 'qux' }, content: 'hello' }); }; _class.prototype['@test attributeBindings handles null/undefined'] = function () { var _this9 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['fizz', 'bar'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar fizz=fizz bar=bar}}', { fizz: null, bar: undefined }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: {}, content: 'hello' }); this.runTask(function () { return _this9.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: {}, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this9.context, 'fizz', 'fizz'); (0, _emberMetal.set)(_this9.context, 'bar', 'bar'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { fizz: 'fizz', bar: 'bar' }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this9.context, 'fizz', null); (0, _emberMetal.set)(_this9.context, 'bar', undefined); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: {}, content: 'hello' }); }; _class.prototype['@test attributeBindings handles number value'] = function () { var _this10 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['size'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar size=size}}', { size: 21 }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { size: '21' }, content: 'hello' }); this.runTask(function () { return _this10.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { size: '21' }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'size', 0); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { size: '0' }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'size', 21); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { size: '21' }, content: 'hello' }); }; _class.prototype['@test handles internal and external changes'] = function () { var _this11 = this; var component = void 0; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['type'], type: 'password', init: function () { this._super.apply(this, arguments); component = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar}}'); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { type: 'password' }, content: 'hello' }); this.runTask(function () { return _this11.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { type: 'password' }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(component, 'type', 'checkbox'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { type: 'checkbox' }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(component, 'type', 'password'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { type: 'password' }, content: 'hello' }); }; _class.prototype['@test can set attributeBindings on component with a different tagName'] = function () { var _this12 = this; var FooBarComponent = _helpers.Component.extend({ tagName: 'input', attributeBindings: ['type', 'isDisabled:disabled'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); this.render('{{foo-bar type=type isDisabled=disabled}}', { type: 'password', disabled: false }); this.assertComponentElement(this.firstChild, { tagName: 'input', attrs: { type: 'password' } }); this.runTask(function () { return _this12.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'input', attrs: { type: 'password' } }); this.runTask(function () { (0, _emberMetal.set)(_this12.context, 'type', 'checkbox'); (0, _emberMetal.set)(_this12.context, 'disabled', true); }); this.assertComponentElement(this.firstChild, { tagName: 'input', attrs: { type: 'checkbox', disabled: '' } }); this.runTask(function () { (0, _emberMetal.set)(_this12.context, 'type', 'password'); (0, _emberMetal.set)(_this12.context, 'disabled', false); }); this.assertComponentElement(this.firstChild, { tagName: 'input', attrs: { type: 'password' } }); }; _class.prototype['@test should allow namespaced attributes in micro syntax'] = function () { var _this13 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['xlinkHref:xlink:href'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); this.render('{{foo-bar type=type xlinkHref=xlinkHref}}', { xlinkHref: '/foo.png' }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'xlink:href': '/foo.png' } }); this.runTask(function () { return _this13.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'xlink:href': '/foo.png' } }); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'xlinkHref', '/lol.png'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'xlink:href': '/lol.png' } }); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'xlinkHref', '/foo.png'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'xlink:href': '/foo.png' } }); }; _class.prototype['@test should allow for String objects'] = function () { var _this14 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['foo'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); this.render('{{foo-bar foo=foo}}', { foo: function () { return this; }.call('bar') }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'foo': 'bar' } }); this.runTask(function () { return _this14.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'foo': 'bar' } }); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'foo', function () { return this; }.call('baz')); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'foo': 'baz' } }); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'foo', function () { return this; }.call('bar')); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'foo': 'bar' } }); }; _class.prototype['@test can set id initially via attributeBindings '] = function () { var _this15 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['specialSauce:id'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); this.render('{{foo-bar specialSauce=sauce}}', { sauce: 'special-sauce' }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'id': 'special-sauce' } }); this.runTask(function () { return _this15.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'id': 'special-sauce' } }); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'sauce', 'foo'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'id': 'special-sauce' } }); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'sauce', 'special-sauce'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'id': 'special-sauce' } }); }; _class.prototype['@test attributeBindings are overwritten'] = function () { var _this16 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['href'], href: 'a href' }); var FizzBarComponent = FooBarComponent.extend({ attributeBindings: ['newHref:href'] }); this.registerComponent('fizz-bar', { ComponentClass: FizzBarComponent }); this.render('{{fizz-bar newHref=href}}', { href: 'dog.html' }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { href: 'dog.html' } }); this.runTask(function () { return _this16.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { href: 'dog.html' } }); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'href', 'cat.html'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { href: 'cat.html' } }); }; _class.prototype['@test it can set attribute bindings in the constructor'] = function () { var _this17 = this; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); var bindings = []; if (this.get('hasFoo')) { bindings.push('foo:data-foo'); } if (this.get('hasBar')) { bindings.push('bar:data-bar'); } this.attributeBindings = bindings; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render((0, _abstractTestCase.strip)(_templateObject), { foo: 'foo', bar: 'bar' }); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'data-foo': 'foo' }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { 'data-bar': 'bar' }, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'data-foo': 'foo', 'data-bar': 'bar' }, content: 'hello' }); this.assertComponentElement(this.nthChild(3), { tagName: 'div', attrs: {}, content: 'hello' }); this.runTask(function () { return _this17.rerender(); }); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'data-foo': 'foo' }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { 'data-bar': 'bar' }, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'data-foo': 'foo', 'data-bar': 'bar' }, content: 'hello' }); this.assertComponentElement(this.nthChild(3), { tagName: 'div', attrs: {}, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this17.context, 'foo', 'FOO'); (0, _emberMetal.set)(_this17.context, 'bar', undefined); }); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'data-foo': 'FOO' }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: {}, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'data-foo': 'FOO' }, content: 'hello' }); this.assertComponentElement(this.nthChild(3), { tagName: 'div', attrs: {}, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'bar', 'BAR'); }); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'data-foo': 'FOO' }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { 'data-bar': 'BAR' }, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'data-foo': 'FOO', 'data-bar': 'BAR' }, content: 'hello' }); this.assertComponentElement(this.nthChild(3), { tagName: 'div', attrs: {}, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this17.context, 'foo', 'foo'); (0, _emberMetal.set)(_this17.context, 'bar', 'bar'); }); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'data-foo': 'foo' }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { 'data-bar': 'bar' }, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'data-foo': 'foo', 'data-bar': 'bar' }, content: 'hello' }); this.assertComponentElement(this.nthChild(3), { tagName: 'div', attrs: {}, content: 'hello' }); }; _class.prototype['@test it should not allow attributeBindings to be set'] = function () { var _this18 = this; this.registerComponent('foo-bar', { template: 'hello' }); expectAssertion(function () { _this18.render('{{foo-bar attributeBindings="one two"}}'); }, /Setting 'attributeBindings' via template helpers is not allowed/); }; _class.prototype['@test asserts if an attributeBinding is setup on class'] = function () { var _this19 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['class'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); expectAssertion(function () { _this19.render('{{foo-bar}}'); }, /You cannot use class as an attributeBinding, use classNameBindings instead./i); }; _class.prototype['@test blacklists href bindings based on protocol'] = function () { /* jshint scripturl:true */ var FooBarComponent = _helpers.Component.extend({ tagName: 'a', attributeBindings: ['href'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar href=xss}}', { xss: 'javascript:alert(\'foo\')' }); this.assertComponentElement(this.firstChild, { tagName: 'a', attrs: { href: 'unsafe:javascript:alert(\'foo\')' } }); }; _class.prototype['@test it can bind the role attribute (issue #14007)'] = function () { var _this20 = this; var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['role'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar role=role}}', { role: 'button' }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { role: 'button' } }); this.runTask(function () { return _this20.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { role: 'button' } }); this.runTask(function () { return (0, _emberMetal.set)(_this20.context, 'role', 'combobox'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { role: 'combobox' } }); this.runTask(function () { return (0, _emberMetal.set)(_this20.context, 'role', null); }); this.assertComponentElement(this.firstChild, { tagName: 'div' }); }; _class.prototype['@test component with an `id` attribute binding of undefined'] = function () { this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ attributeBindings: ['id'], id: undefined }) }); this.registerComponent('baz-qux', { ComponentClass: _helpers.Component.extend({ attributeBindings: ['somethingUndefined:id'], somethingUndefined: undefined }) }); this.render('{{foo-bar}}{{baz-qux}}'); this.assertComponentElement(this.nthChild(0), { content: '' }); this.assertComponentElement(this.nthChild(1), { content: '' }); this.assert.ok(this.nthChild(0).id.match(/ember\d+/), 'a valid `id` was used'); this.assert.ok(this.nthChild(1).id.match(/ember\d+/), 'a valid `id` was used'); }; _class.prototype['@test component with an `id` attribute binding of null'] = function () { this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ attributeBindings: ['id'], id: null }) }); this.registerComponent('baz-qux', { ComponentClass: _helpers.Component.extend({ attributeBindings: ['somethingNull:id'], somethingNull: null }) }); this.render('{{foo-bar}}{{baz-qux}}'); this.assertComponentElement(this.nthChild(0), { content: '' }); this.assertComponentElement(this.nthChild(1), { content: '' }); this.assert.ok(this.nthChild(0).id.match(/ember\d+/), 'a valid `id` was used'); this.assert.ok(this.nthChild(1).id.match(/ember\d+/), 'a valid `id` was used'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/attrs-lookup-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal', 'ember-glimmer/tests/utils/test-helpers'], function (_emberBabel, _testCase, _helpers, _emberMetal, _testHelpers) { 'use strict'; (0, _testCase.moduleFor)('Components test: attrs lookup', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test it should be able to lookup attrs without `attrs.` - template access'] = function () { var _this2 = this; this.registerComponent('foo-bar', { template: '{{first}}' }); this.render('{{foo-bar first=firstAttr}}', { firstAttr: 'first attr' }); this.assertText('first attr'); this.runTask(function () { return _this2.rerender(); }); this.assertText('first attr'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'firstAttr', 'second attr'); }); this.assertText('second attr'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'firstAttr', 'first attr'); }); this.assertText('first attr'); }; _class.prototype['@test it should be able to lookup attrs without `attrs.` - component access'] = function (assert) { var _this3 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); instance = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{first}}' }); this.render('{{foo-bar first=firstAttr}}', { firstAttr: 'first attr' }); assert.equal(instance.get('first'), 'first attr'); this.runTask(function () { return _this3.rerender(); }); assert.equal(instance.get('first'), 'first attr'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'firstAttr', 'second attr'); }); assert.equal(instance.get('first'), 'second attr'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'firstAttr', 'first attr'); }); this.assertText('first attr'); }; _class.prototype['@test should be able to modify a provided attr into local state #11571 / #11559'] = function (assert) { var _this4 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); instance = this; }, didReceiveAttrs: function () { this.set('first', this.get('first').toUpperCase()); } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{first}}' }); this.render('{{foo-bar first="first attr"}}'); assert.equal(instance.get('first'), 'FIRST ATTR', 'component lookup uses local state'); this.assertText('FIRST ATTR'); this.runTask(function () { return _this4.rerender(); }); assert.equal(instance.get('first'), 'FIRST ATTR', 'component lookup uses local state during rerender'); this.assertText('FIRST ATTR'); // This is testing that passing string literals for use as initial values, // so there is no update step }; _class.prototype['@test should be able to access unspecified attr #12035'] = function (assert) { var _this5 = this; var instance = void 0; var wootVal = 'yes'; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); instance = this; }, didReceiveAttrs: function () { assert.equal(this.get('woot'), wootVal, 'found attr in didReceiveAttrs'); } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); this.render('{{foo-bar woot=woot}}', { woot: wootVal }); assert.equal(instance.get('woot'), 'yes', 'component found attr'); this.runTask(function () { return _this5.rerender(); }); assert.equal(instance.get('woot'), 'yes', 'component found attr after rerender'); this.runTask(function () { wootVal = 'nope'; (0, _emberMetal.set)(_this5.context, 'woot', wootVal); }); assert.equal(instance.get('woot'), 'nope', 'component found attr after attr change'); this.runTask(function () { wootVal = 'yes'; (0, _emberMetal.set)(_this5.context, 'woot', wootVal); }); assert.equal(instance.get('woot'), 'yes', 'component found attr after reset'); }; _class.prototype['@test getAttr() should return the same value as get()'] = function (assert) { var _this6 = this; assert.expect(33); var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); instance = this; }, didReceiveAttrs: function () { var rootFirstPositional = this.get('firstPositional'); var rootFirst = this.get('first'); var rootSecond = this.get('second'); var attrFirstPositional = this.getAttr('firstPositional'); var attrFirst = this.getAttr('first'); var attrSecond = this.getAttr('second'); equal(rootFirstPositional, attrFirstPositional, 'root property matches attrs value'); equal(rootFirst, attrFirst, 'root property matches attrs value'); equal(rootSecond, attrSecond, 'root property matches attrs value'); } }); FooBarComponent.reopenClass({ positionalParams: ['firstPositional'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); this.render('{{foo-bar firstPositional first=first second=second}}', { firstPositional: 'firstPositional', first: 'first', second: 'second' }); assert.equal(instance.get('firstPositional'), 'firstPositional', 'matches known value'); assert.equal(instance.get('first'), 'first', 'matches known value'); assert.equal(instance.get('second'), 'second', 'matches known value'); this.runTask(function () { return _this6.rerender(); }); assert.equal(instance.get('firstPositional'), 'firstPositional', 'matches known value'); assert.equal(instance.get('first'), 'first', 'matches known value'); assert.equal(instance.get('second'), 'second', 'matches known value'); this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'first', 'third'); }); assert.equal(instance.get('firstPositional'), 'firstPositional', 'matches known value'); assert.equal(instance.get('first'), 'third', 'matches known value'); assert.equal(instance.get('second'), 'second', 'matches known value'); this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'second', 'fourth'); }); assert.equal(instance.get('firstPositional'), 'firstPositional', 'matches known value'); assert.equal(instance.get('first'), 'third', 'matches known value'); assert.equal(instance.get('second'), 'fourth', 'matches known value'); this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'firstPositional', 'fifth'); }); assert.equal(instance.get('firstPositional'), 'fifth', 'matches known value'); assert.equal(instance.get('first'), 'third', 'matches known value'); assert.equal(instance.get('second'), 'fourth', 'matches known value'); this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'firstPositional', 'firstPositional'); (0, _emberMetal.set)(_this6.context, 'first', 'first'); (0, _emberMetal.set)(_this6.context, 'second', 'second'); }); assert.equal(instance.get('firstPositional'), 'firstPositional', 'matches known value'); assert.equal(instance.get('first'), 'first', 'matches known value'); assert.equal(instance.get('second'), 'second', 'matches known value'); }; _class.prototype['@test bound computed properties can be overriden in extensions, set during init, and passed in as attrs'] = function () { var FooClass = _helpers.Component.extend({ attributeBindings: ['style'], style: (0, _emberMetal.computed)('height', 'color', function () { var height = this.get('height'); var color = this.get('color'); return 'height: ' + height + 'px; background-color: ' + color + ';'; }), color: 'red', height: 20 }); var BarClass = FooClass.extend({ init: function () { this._super.apply(this, arguments); this.height = 150; }, color: 'yellow' }); this.registerComponent('x-foo', { ComponentClass: FooClass }); this.registerComponent('x-bar', { ComponentClass: BarClass }); this.render('{{x-foo}}{{x-bar}}{{x-bar color="green"}}'); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 20px; background-color: red;') } }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 150px; background-color: yellow;') } }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 150px; background-color: green;') } }); this.assertStableRerender(); // No U-R }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/class-bindings-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/test-helpers', 'ember-metal', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _testCase, _helpers, _testHelpers, _emberMetal, _abstractTestCase) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{foo-bar foo=foo bindIsEnabled=true isEnabled=isEnabled bindIsHappy=false isHappy=isHappy}}\n {{foo-bar foo=foo bindIsEnabled=false isEnabled=isEnabled bindIsHappy=true isHappy=isHappy}}\n {{foo-bar foo=foo bindIsEnabled=true isEnabled=isEnabled bindIsHappy=true isHappy=isHappy}}\n {{foo-bar foo=foo bindIsEnabled=false isEnabled=isEnabled bindIsHappy=false isHappy=isHappy}}\n '], ['\n {{foo-bar foo=foo bindIsEnabled=true isEnabled=isEnabled bindIsHappy=false isHappy=isHappy}}\n {{foo-bar foo=foo bindIsEnabled=false isEnabled=isEnabled bindIsHappy=true isHappy=isHappy}}\n {{foo-bar foo=foo bindIsEnabled=true isEnabled=isEnabled bindIsHappy=true isHappy=isHappy}}\n {{foo-bar foo=foo bindIsEnabled=false isEnabled=isEnabled bindIsHappy=false isHappy=isHappy}}\n ']); (0, _testCase.moduleFor)('ClassNameBindings integration', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test it can have class name bindings on the class definition'] = function () { var _this2 = this; var FooBarComponent = _helpers.Component.extend({ classNameBindings: ['foo', 'isEnabled:enabled', 'isHappy:happy:sad'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar foo=foo isEnabled=isEnabled isHappy=isHappy}}', { foo: 'foo', isEnabled: true, isHappy: false }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo enabled sad') }, content: 'hello' }); this.runTask(function () { return _this2.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo enabled sad') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this2.context, 'foo', 'FOO'); (0, _emberMetal.set)(_this2.context, 'isEnabled', false); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view FOO sad') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this2.context, 'foo', undefined); (0, _emberMetal.set)(_this2.context, 'isHappy', true); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view happy') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this2.context, 'foo', 'foo'); (0, _emberMetal.set)(_this2.context, 'isEnabled', true); (0, _emberMetal.set)(_this2.context, 'isHappy', false); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo enabled sad') }, content: 'hello' }); }; _class.prototype['@test attrs in classNameBindings'] = function () { var _this3 = this; var FooBarComponent = _helpers.Component.extend({ classNameBindings: ['attrs.joker:purple:green', 'attrs.batman.robin:black:red'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar joker=model.wat batman=model.super}}', { model: { wat: false, super: { robin: true } } }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view green black') }, content: 'hello' }); this.runTask(function () { return _this3.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view green black') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this3.context, 'model.wat', true); (0, _emberMetal.set)(_this3.context, 'model.super.robin', false); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view purple red') }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'model', { wat: false, super: { robin: true } }); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view green black') }, content: 'hello' }); }; _class.prototype['@test it can have class name bindings in the template'] = function () { var _this4 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar classNameBindings="model.someInitiallyTrueProperty model.someInitiallyFalseProperty model.someInitiallyUndefinedProperty :static model.isBig:big model.isOpen:open:closed model.isUp::down model.bar:isTruthy:isFalsy"}}', { model: { someInitiallyTrueProperty: true, someInitiallyFalseProperty: false, isBig: true, isOpen: false, isUp: true, bar: true } }); this.assertComponentElement(this.firstChild, { attrs: { 'class': (0, _testHelpers.classes)('ember-view some-initially-true-property static big closed isTruthy') }, content: 'hello' }); this.runTask(function () { return _this4.rerender(); }); this.assertComponentElement(this.firstChild, { attrs: { 'class': (0, _testHelpers.classes)('ember-view some-initially-true-property static big closed isTruthy') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this4.context, 'model.someInitiallyTrueProperty', false); (0, _emberMetal.set)(_this4.context, 'model.someInitiallyFalseProperty', true); (0, _emberMetal.set)(_this4.context, 'model.someInitiallyUndefinedProperty', true); (0, _emberMetal.set)(_this4.context, 'model.isBig', false); (0, _emberMetal.set)(_this4.context, 'model.isOpen', true); (0, _emberMetal.set)(_this4.context, 'model.isUp', false); (0, _emberMetal.set)(_this4.context, 'model.bar', false); }); this.assertComponentElement(this.firstChild, { attrs: { 'class': (0, _testHelpers.classes)('ember-view some-initially-false-property some-initially-undefined-property static open down isFalsy') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this4.context, 'model', { someInitiallyTrueProperty: true, someInitiallyFalseProperty: false, someInitiallyUndefinedProperty: undefined, isBig: true, isOpen: false, isUp: true, bar: true }); }); this.assertComponentElement(this.firstChild, { attrs: { 'class': (0, _testHelpers.classes)('ember-view some-initially-true-property static big closed isTruthy') }, content: 'hello' }); }; _class.prototype['@test it can have class name bindings with nested paths'] = function () { var _this5 = this; var FooBarComponent = _helpers.Component.extend({ classNameBindings: ['foo.bar', 'is.enabled:enabled', 'is.happy:happy:sad'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar foo=foo is=is}}', { foo: { bar: 'foo-bar' }, is: { enabled: true, happy: false } }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo-bar enabled sad') }, content: 'hello' }); this.runTask(function () { return _this5.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo-bar enabled sad') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this5.context, 'foo.bar', 'FOO-BAR'); (0, _emberMetal.set)(_this5.context, 'is.enabled', false); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view FOO-BAR sad') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this5.context, 'foo.bar', null); (0, _emberMetal.set)(_this5.context, 'is.happy', true); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view happy') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this5.context, 'foo', null); (0, _emberMetal.set)(_this5.context, 'is', null); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view sad') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this5.context, 'foo', { bar: 'foo-bar' }); (0, _emberMetal.set)(_this5.context, 'is', { enabled: true, happy: false }); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo-bar enabled sad') }, content: 'hello' }); }; _class.prototype['@test it should dasherize the path when the it resolves to true'] = function () { var _this6 = this; var FooBarComponent = _helpers.Component.extend({ classNameBindings: ['fooBar', 'nested.fooBarBaz'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar fooBar=fooBar nested=nested}}', { fooBar: true, nested: { fooBarBaz: false } }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo-bar') }, content: 'hello' }); this.runTask(function () { return _this6.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo-bar') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'fooBar', false); (0, _emberMetal.set)(_this6.context, 'nested.fooBarBaz', true); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo-bar-baz') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'fooBar', 'FOO-BAR'); (0, _emberMetal.set)(_this6.context, 'nested.fooBarBaz', null); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view FOO-BAR') }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'nested', null); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view FOO-BAR') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'fooBar', true); (0, _emberMetal.set)(_this6.context, 'nested', { fooBarBaz: false }); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo-bar') }, content: 'hello' }); }; _class.prototype['@test const bindings can be set as attrs'] = function () { var _this7 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar classNameBindings="foo:enabled:disabled"}}', { foo: true }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view enabled') }, content: 'hello' }); this.runTask(function () { return _this7.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view enabled') }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'foo', false); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view disabled') }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'foo', true); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view enabled') }, content: 'hello' }); }; _class.prototype['@test :: class name syntax works with an empty true class'] = function () { var _this8 = this; var FooBarComponent = _helpers.Component.extend({ classNameBindings: ['isEnabled::not-enabled'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar isEnabled=enabled}}', { enabled: false }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view not-enabled') }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'enabled', true); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view') }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'enabled', false); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view not-enabled') }, content: 'hello' }); }; _class.prototype['@test uses all provided static class names (issue #11193)'] = function () { var _this9 = this; var FooBarComponent = _helpers.Component.extend({ classNameBindings: [':class-one', ':class-two'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar}}', { enabled: false }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view class-one class-two') }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'enabled', true); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view class-one class-two') }, content: 'hello' }); }; _class.prototype['@test Providing a binding with a space in it asserts'] = function () { var _this10 = this; var FooBarComponent = _helpers.Component.extend({ classNameBindings: 'i:think:i am:so:clever' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); expectAssertion(function () { _this10.render('{{foo-bar}}'); }, /classNameBindings must not have spaces in them/i); }; _class.prototype['@test it can set class name bindings in the constructor'] = function () { var _this11 = this; var FooBarComponent = _helpers.Component.extend({ classNameBindings: ['foo'], init: function () { this._super(); var bindings = this.classNameBindings = this.classNameBindings.slice(); if (this.get('bindIsEnabled')) { bindings.push('isEnabled:enabled'); } if (this.get('bindIsHappy')) { bindings.push('isHappy:happy:sad'); } } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render((0, _abstractTestCase.strip)(_templateObject), { foo: 'foo', isEnabled: true, isHappy: false }); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo enabled') }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo sad') }, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo enabled sad') }, content: 'hello' }); this.assertComponentElement(this.nthChild(3), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo') }, content: 'hello' }); this.runTask(function () { return _this11.rerender(); }); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo enabled') }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo sad') }, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo enabled sad') }, content: 'hello' }); this.assertComponentElement(this.nthChild(3), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this11.context, 'foo', 'FOO'); (0, _emberMetal.set)(_this11.context, 'isEnabled', false); }); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view FOO') }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view FOO sad') }, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view FOO sad') }, content: 'hello' }); this.assertComponentElement(this.nthChild(3), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view FOO') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this11.context, 'foo', undefined); (0, _emberMetal.set)(_this11.context, 'isHappy', true); }); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view') }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view happy') }, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view happy') }, content: 'hello' }); this.assertComponentElement(this.nthChild(3), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view') }, content: 'hello' }); this.runTask(function () { (0, _emberMetal.set)(_this11.context, 'foo', 'foo'); (0, _emberMetal.set)(_this11.context, 'isEnabled', true); (0, _emberMetal.set)(_this11.context, 'isHappy', false); }); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo enabled') }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo sad') }, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo enabled sad') }, content: 'hello' }); this.assertComponentElement(this.nthChild(3), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo') }, content: 'hello' }); }; _class.prototype['@test using a computed property for classNameBindings triggers an assertion'] = function () { var _this12 = this; var FooBarComponent = _helpers.Component.extend({ classNameBindings: (0, _emberMetal.computed)(function () { return ['isHappy:happy:sad']; }) }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); expectAssertion(function () { _this12.render('{{foo-bar}}'); }, /Only arrays are allowed/); }; return _class; }(_testCase.RenderingTest)); (0, _testCase.moduleFor)('ClassBinding integration', function (_RenderingTest2) { (0, _emberBabel.inherits)(_class2, _RenderingTest2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments)); } _class2.prototype['@test it should apply classBinding without condition always'] = function () { var _this14 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar classBinding=":foo"}}'); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo ember-view') } }); this.runTask(function () { return _this14.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo ember-view') } }); }; _class2.prototype['@test it should merge classBinding with class'] = function () { var _this15 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar classBinding="birdman:respeck" class="myName"}}', { birdman: true }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('respeck myName ember-view') } }); this.runTask(function () { return _this15.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('respeck myName ember-view') } }); }; _class2.prototype['@test it should apply classBinding with only truthy condition'] = function () { var _this16 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar classBinding="myName:respeck"}}', { myName: true }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('respeck ember-view') } }); this.runTask(function () { return _this16.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('respeck ember-view') } }); }; _class2.prototype['@test it should apply classBinding with only falsy condition'] = function () { var _this17 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar classBinding="myName::shade"}}', { myName: false }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('shade ember-view') } }); this.runTask(function () { return _this17.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('shade ember-view') } }); }; _class2.prototype['@test it should apply nothing when classBinding is falsy but only supplies truthy class'] = function () { var _this18 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar classBinding="myName:respeck"}}', { myName: false }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('ember-view') } }); this.runTask(function () { return _this18.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('ember-view') } }); }; _class2.prototype['@test it should apply nothing when classBinding is truthy but only supplies falsy class'] = function () { var _this19 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar classBinding="myName::shade"}}', { myName: true }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('ember-view') } }); this.runTask(function () { return _this19.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('ember-view') } }); }; _class2.prototype['@test it should apply classBinding with falsy condition'] = function () { var _this20 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar classBinding="swag:fresh:scrub"}}', { swag: false }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('scrub ember-view') } }); this.runTask(function () { return _this20.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('scrub ember-view') } }); }; _class2.prototype['@test it should apply classBinding with truthy condition'] = function () { var _this21 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar classBinding="swag:fresh:scrub"}}', { swag: true }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fresh ember-view') } }); this.runTask(function () { return _this21.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fresh ember-view') } }); }; return _class2; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/contextual-components-test', ['ember-babel', 'ember-utils', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case', 'ember-metal', 'ember-runtime/system/native_array'], function (_emberBabel, _emberUtils, _helpers, _abstractTestCase, _testCase, _emberMetal, _native_array) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{component (component "-looked-up") "Hodari" greeting="Hodi"}}'], ['\n {{component (component "-looked-up") "Hodari" greeting="Hodi"}}']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{component (component "-looked-up" "Hodari" greeting="Hodi")\n greeting="Hola"}}'], ['\n {{component (component "-looked-up" "Hodari" greeting="Hodi")\n greeting="Hola"}}']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with (hash comp=(component "-looked-up" greeting=model.greeting)) as |my|}}\n {{#my.comp}}{{/my.comp}}\n {{/with}}'], ['\n {{#with (hash comp=(component "-looked-up" greeting=model.greeting)) as |my|}}\n {{#my.comp}}{{/my.comp}}\n {{/with}}']), _templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with (component "-looked-up" greeting="Hola" name="Dolores" age=33) as |first|}}\n {{#with (component first greeting="Hej" name="Sigmundur") as |second|}}\n {{component second greeting=model.greeting}}\n {{/with}}\n {{/with}}'], ['\n {{#with (component "-looked-up" greeting="Hola" name="Dolores" age=33) as |first|}}\n {{#with (component first greeting="Hej" name="Sigmundur") as |second|}}\n {{component second greeting=model.greeting}}\n {{/with}}\n {{/with}}']), _templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with (hash lookedup=(component "-looked-up")) as |object|}}\n {{object.lookedup}}\n {{/with}}'], ['\n {{#with (hash lookedup=(component "-looked-up")) as |object|}}\n {{object.lookedup}}\n {{/with}}']), _templateObject6 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with (hash lookedup=(component "-looked-up")) as |object|}}\n {{object.lookedup expectedText=model.expectedText}}\n {{/with}}'], ['\n {{#with (hash lookedup=(component "-looked-up")) as |object|}}\n {{object.lookedup expectedText=model.expectedText}}\n {{/with}}']), _templateObject7 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with (hash lookedup=(component "-looked-up" expectedText=model.expectedText)) as |object|}}\n {{object.lookedup}}\n {{/with}}'], ['\n {{#with (hash lookedup=(component "-looked-up" expectedText=model.expectedText)) as |object|}}\n {{object.lookedup}}\n {{/with}}']), _templateObject8 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with (hash lookedup=(component "-looked-up")) as |object|}}\n {{object.lookedup model.expectedText "Hola"}}\n {{/with}}'], ['\n {{#with (hash lookedup=(component "-looked-up")) as |object|}}\n {{object.lookedup model.expectedText "Hola"}}\n {{/with}}']), _templateObject9 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with (hash my-component=(component \'my-component\' first)) as |c|}}\n {{c.my-component}}\n {{/with}}'], ['\n {{#with (hash my-component=(component \'my-component\' first)) as |c|}}\n {{c.my-component}}\n {{/with}}']), _templateObject10 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#my-component my-attr=myProp as |api|}}\n {{api.my-nested-component}}\n {{/my-component}}\n
\n '], ['\n {{#my-component my-attr=myProp as |api|}}\n {{api.my-nested-component}}\n {{/my-component}}\n
\n ']), _templateObject11 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#select-box as |sb|}}\n {{sb.option label="Foo"}}\n {{sb.option}}\n {{/select-box}}'], ['\n {{#select-box as |sb|}}\n {{sb.option label="Foo"}}\n {{sb.option}}\n {{/select-box}}']), _templateObject12 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n '], ['\n ']), _templateObject13 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{component (component "change-button" model.val2)}}\n {{model.val2}}'], ['\n {{component (component "change-button" model.val2)}}\n {{model.val2}}']), _templateObject14 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n message: {{message}}{{inner-component message=message}}\n '], ['\n ']); (0, _testCase.moduleFor)('Components test: contextual components', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test renders with component helper'] = function () { var _this2 = this; var expectedText = 'Hodi'; this.registerComponent('-looked-up', { template: expectedText }); this.render('{{component (component "-looked-up")}}'); this.assertText(expectedText); this.runTask(function () { return _this2.rerender(); }); this.assertText(expectedText); }; _class.prototype['@test renders with component helper with invocation params, hash'] = function () { var _this3 = this; this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name'] }), template: '{{greeting}} {{name}}' }); this.render((0, _abstractTestCase.strip)(_templateObject)); this.assertText('Hodi Hodari'); this.runTask(function () { return _this3.rerender(); }); this.assertText('Hodi Hodari'); }; _class.prototype['@test GH#13742 keeps nested rest positional parameters if rendered with no positional parameters'] = function () { var _this4 = this; this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'params' }), template: '{{#each params as |p|}}{{p}}{{/each}}' }); this.render('{{component (component "-looked-up" model.greeting model.name)}}', { model: { greeting: 'Gabon ', name: 'Zack' } }); this.assertText('Gabon Zack'); this.runTask(function () { return _this4.rerender(); }); this.assertText('Gabon Zack'); this.runTask(function () { return _this4.context.set('model.greeting', 'Good morning '); }); this.assertText('Good morning Zack'); this.runTask(function () { return _this4.context.set('model.name', 'Matthew'); }); this.assertText('Good morning Matthew'); this.runTask(function () { return _this4.context.set('model', { greeting: 'Gabon ', name: 'Zack' }); }); this.assertText('Gabon Zack'); }; _class.prototype['@test overwrites nested rest positional parameters if rendered with positional parameters'] = function () { var _this5 = this; this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'params' }), template: '{{#each params as |p|}}{{p}}{{/each}}' }); this.render('{{component (component "-looked-up" model.greeting model.name) model.name model.greeting}}', { model: { greeting: 'Gabon ', name: 'Zack' } }); this.assertText('ZackGabon '); this.runTask(function () { return _this5.rerender(); }); this.assertText('ZackGabon '); this.runTask(function () { return _this5.context.set('model.greeting', 'Good morning '); }); this.assertText('ZackGood morning '); this.runTask(function () { return _this5.context.set('model.name', 'Matthew'); }); this.assertText('MatthewGood morning '); this.runTask(function () { return _this5.context.set('model', { greeting: 'Gabon ', name: 'Zack' }); }); this.assertText('ZackGabon '); }; _class.prototype['@test GH#13742 keeps nested rest positional parameters if nested and rendered with no positional parameters'] = function () { var _this6 = this; this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'params' }), template: '{{#each params as |p|}}{{p}}{{/each}}' }); this.render('{{component (component (component "-looked-up" model.greeting model.name))}}', { model: { greeting: 'Gabon ', name: 'Zack' } }); this.assertText('Gabon Zack'); this.runTask(function () { return _this6.rerender(); }); this.assertText('Gabon Zack'); this.runTask(function () { return _this6.context.set('model.greeting', 'Good morning '); }); this.assertText('Good morning Zack'); this.runTask(function () { return _this6.context.set('model.name', 'Matthew'); }); this.assertText('Good morning Matthew'); this.runTask(function () { return _this6.context.set('model', { greeting: 'Gabon ', name: 'Zack' }); }); this.assertText('Gabon Zack'); }; _class.prototype['@test overwrites nested rest positional parameters if nested with new pos params and rendered with no positional parameters'] = function () { var _this7 = this; this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'params' }), template: '{{#each params as |p|}}{{p}}{{/each}}' }); this.render('{{component (component (component "-looked-up" model.greeting model.name) model.name model.greeting)}}', { model: { greeting: 'Gabon ', name: 'Zack' } }); this.assertText('ZackGabon '); this.runTask(function () { return _this7.rerender(); }); this.assertText('ZackGabon '); this.runTask(function () { return _this7.context.set('model.greeting', 'Good morning '); }); this.assertText('ZackGood morning '); this.runTask(function () { return _this7.context.set('model.name', 'Matthew'); }); this.assertText('MatthewGood morning '); this.runTask(function () { return _this7.context.set('model', { greeting: 'Gabon ', name: 'Zack' }); }); this.assertText('ZackGabon '); }; _class.prototype['@test renders with component helper with curried params, hash'] = function () { var _this8 = this; this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name'] }), template: '{{greeting}} {{name}}' }); this.render((0, _abstractTestCase.strip)(_templateObject2)); this.assertText('Hola Hodari'); this.runTask(function () { return _this8.rerender(); }); this.assertText('Hola Hodari'); }; _class.prototype['@test updates when component path is bound'] = function () { var _this9 = this; this.registerComponent('-mandarin', { template: 'ni hao' }); this.registerComponent('-hindi', { template: 'Namaste' }); this.render('{{component (component model.lookupComponent)}}', { model: { lookupComponent: '-mandarin' } }); this.assertText('ni hao'); this.runTask(function () { return _this9.rerender(); }); this.assertText('ni hao'); this.runTask(function () { return _this9.context.set('model.lookupComponent', '-hindi'); }); this.assertText('Namaste'); this.runTask(function () { return _this9.context.set('model', { lookupComponent: '-mandarin' }); }); this.assertText('ni hao'); }; _class.prototype['@test updates when curried hash argument is bound'] = function () { var _this10 = this; this.registerComponent('-looked-up', { template: '{{greeting}}' }); this.render('{{component (component "-looked-up" greeting=model.greeting)}}', { model: { greeting: 'Hodi' } }); this.assertText('Hodi'); this.runTask(function () { return _this10.rerender(); }); this.assertText('Hodi'); this.runTask(function () { return _this10.context.set('model.greeting', 'Hola'); }); this.assertText('Hola'); this.runTask(function () { return _this10.context.set('model', { greeting: 'Hodi' }); }); this.assertText('Hodi'); }; _class.prototype['@test updates when curried hash arguments is bound in block form'] = function () { var _this11 = this; this.registerComponent('-looked-up', { template: '{{greeting}}' }); this.render((0, _abstractTestCase.strip)(_templateObject3), { model: { greeting: 'Hodi' } }); this.assertText('Hodi'); this.runTask(function () { return _this11.rerender(); }); this.assertText('Hodi'); this.runTask(function () { return _this11.context.set('model.greeting', 'Hola'); }); this.assertText('Hola'); this.runTask(function () { return _this11.context.set('model', { greeting: 'Hodi' }); }); this.assertText('Hodi'); }; _class.prototype['@test nested components overwrite named positional parameters'] = function () { var _this12 = this; this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name', 'age'] }), template: '{{name}} {{age}}' }); this.render('{{component (component (component "-looked-up" "Sergio" 29) "Marvin" 21) "Hodari"}}'); this.assertText('Hodari 21'); this.runTask(function () { return _this12.rerender(); }); this.assertText('Hodari 21'); }; _class.prototype['@test nested components overwrite hash parameters'] = function () { var _this13 = this; this.registerComponent('-looked-up', { template: '{{greeting}} {{name}} {{age}}' }); this.render((0, _abstractTestCase.strip)(_templateObject4), { model: { greeting: 'Hodi' } }); this.assertText('Hodi Sigmundur 33'); this.runTask(function () { return _this13.rerender(); }); this.assertText('Hodi Sigmundur 33'); this.runTask(function () { return _this13.context.set('model.greeting', 'Kaixo'); }); this.assertText('Kaixo Sigmundur 33'); this.runTask(function () { return _this13.context.set('model', { greeting: 'Hodi' }); }); this.assertText('Hodi Sigmundur 33'); }; _class.prototype['@test bound outer named parameters get updated in the right scope'] = function () { var _this14 = this; this.registerComponent('-inner-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['comp'] }), template: '{{component comp "Inner"}}' }); this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name', 'age'] }), template: '{{name}} {{age}}' }); this.render('{{component "-inner-component" (component "-looked-up" model.outerName model.outerAge)}}', { model: { outerName: 'Outer', outerAge: 28 } }); this.assertText('Inner 28'); this.runTask(function () { return _this14.rerender(); }); this.assertText('Inner 28'); this.runTask(function () { return _this14.context.set('model.outerAge', 29); }); this.assertText('Inner 29'); this.runTask(function () { return _this14.context.set('model.outerName', 'Not outer'); }); this.assertText('Inner 29'); this.runTask(function () { _this14.context.set('model', { outerName: 'Outer', outerAge: 28 }); }); this.assertText('Inner 28'); }; _class.prototype['@test bound outer hash parameters get updated in the right scope'] = function () { var _this15 = this; this.registerComponent('-inner-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['comp'] }), template: '{{component comp name="Inner"}}' }); this.registerComponent('-looked-up', { template: '{{name}} {{age}}' }); this.render('{{component "-inner-component" (component "-looked-up" name=model.outerName age=model.outerAge)}}', { model: { outerName: 'Outer', outerAge: 28 } }); this.assertText('Inner 28'); this.runTask(function () { return _this15.rerender(); }); this.assertText('Inner 28'); this.runTask(function () { return _this15.context.set('model.outerAge', 29); }); this.assertText('Inner 29'); this.runTask(function () { return _this15.context.set('model.outerName', 'Not outer'); }); this.assertText('Inner 29'); this.runTask(function () { _this15.context.set('model', { outerName: 'Outer', outerAge: 28 }); }); this.assertText('Inner 28'); }; _class.prototype['@test conflicting positional and hash parameters raise and assertion if in the same component context'] = function () { var _this16 = this; this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name'] }), template: '{{greeting}} {{name}}' }); expectAssertion(function () { _this16.render('{{component (component "-looked-up" "Hodari" name="Sergio") "Hodari" greeting="Hodi"}}'); }, 'You cannot specify both a positional param (at position 0) and the hash argument `name`.'); }; _class.prototype['@test conflicting positional and hash parameters does not raise an assertion if rerendered'] = function () { var _this17 = this; // In some cases, rerendering with a positional param used to cause an // assertion. This test checks it does not. this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name'] }), template: '{{greeting}} {{name}}' }); this.render('{{component (component "-looked-up" model.name greeting="Hodi")}}', { model: { name: 'Hodari' } }); this.assertText('Hodi Hodari'); this.runTask(function () { return _this17.rerender(); }); this.assertText('Hodi Hodari'); this.runTask(function () { return _this17.context.set('model.name', 'Sergio'); }); this.assertText('Hodi Sergio'); this.runTask(function () { return _this17.context.set('model', { name: 'Hodari' }); }); this.assertText('Hodi Hodari'); }; _class.prototype['@test conflicting positional and hash parameters does not raise an assertion if in different component context'] = function () { var _this18 = this; this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name'] }), template: '{{greeting}} {{name}}' }); this.render('{{component (component "-looked-up" "Hodari") name="Sergio" greeting="Hodi"}}'); this.assertText('Hodi Sergio'); this.runTask(function () { return _this18.rerender(); }); this.assertText('Hodi Sergio'); }; _class.prototype['@test raises an asserton when component path is null'] = function () { var _this19 = this; expectAssertion(function () { _this19.render('{{component (component lookupComponent)}}'); }); }; _class.prototype['@test raises an assertion when component path is not a component name (static)'] = function () { var _this20 = this; expectAssertion(function () { _this20.render('{{component (component "not-a-component")}}'); }, 'The component helper cannot be used without a valid component name. You used "not-a-component" via (component "not-a-component")'); }; _class.prototype['@test raises an assertion when component path is not a component name (dynamic)'] = function () { var _this21 = this; expectAssertion(function () { _this21.render('{{component (component compName)}}', { compName: 'not-a-component' }); }, /The component helper cannot be used without a valid component name. You used "not-a-component" via \(component .*\)/); }; _class.prototype['@test renders with dot path'] = function () { var _this22 = this; var expectedText = 'Hodi'; this.registerComponent('-looked-up', { template: expectedText }); this.render((0, _abstractTestCase.strip)(_templateObject5)); this.assertText(expectedText); this.runTask(function () { return _this22.rerender(); }); this.assertText(expectedText); }; _class.prototype['@test renders with dot path and attr'] = function () { var _this23 = this; var expectedText = 'Hodi'; this.registerComponent('-looked-up', { template: '{{expectedText}}' }); this.render((0, _abstractTestCase.strip)(_templateObject6), { model: { expectedText: expectedText } }); this.assertText(expectedText); this.runTask(function () { return _this23.rerender(); }); this.assertText(expectedText); this.runTask(function () { return _this23.context.set('model.expectedText', 'Hola'); }); this.assertText('Hola'); this.runTask(function () { return _this23.context.set('model', { expectedText: expectedText }); }); this.assertText(expectedText); }; _class.prototype['@test renders with dot path and curried over attr'] = function () { var _this24 = this; var expectedText = 'Hodi'; this.registerComponent('-looked-up', { template: '{{expectedText}}' }); this.render((0, _abstractTestCase.strip)(_templateObject7), { model: { expectedText: expectedText } }); this.assertText(expectedText); this.runTask(function () { return _this24.rerender(); }); this.assertText(expectedText); this.runTask(function () { return _this24.context.set('model.expectedText', 'Hola'); }); this.assertText('Hola'); this.runTask(function () { return _this24.context.set('model', { expectedText: expectedText }); }); this.assertText(expectedText); }; _class.prototype['@test renders with dot path and with rest positional parameters'] = function () { var _this25 = this; this.registerComponent('-looked-up', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'params' }), template: '{{params}}' }); var expectedText = 'Hodi'; this.render((0, _abstractTestCase.strip)(_templateObject8), { model: { expectedText: expectedText } }); this.assertText(expectedText + ',Hola'); this.runTask(function () { return _this25.rerender(); }); this.assertText(expectedText + ',Hola'); this.runTask(function () { return _this25.context.set('model.expectedText', 'Kaixo'); }); this.assertText('Kaixo,Hola'); this.runTask(function () { return _this25.context.set('model', { expectedText: expectedText }); }); this.assertText(expectedText + ',Hola'); }; _class.prototype['@test renders with dot path and rest parameter does not leak'] = function (assert) { // In the original implementation, positional parameters were not handled // correctly causing the first positional parameter to be the contextual // component itself. var value = false; this.registerComponent('my-component', { ComponentClass: _helpers.Component.extend({ didReceiveAttrs: function () { value = this.getAttr('value'); } }).reopenClass({ positionalParams: ['value'] }) }); this.render((0, _abstractTestCase.strip)(_templateObject9), { first: 'first' }); assert.equal(value, 'first', 'value is the expected parameter'); }; _class.prototype['@test renders with dot path and updates attributes'] = function (assert) { var _this26 = this; this.registerComponent('my-nested-component', { ComponentClass: _helpers.Component.extend({ didReceiveAttrs: function () { this.set('myProp', this.getAttr('my-parent-attr')); } }), template: '{{myProp}}' }); this.registerComponent('my-component', { template: '{{yield (hash my-nested-component=(component "my-nested-component" my-parent-attr=my-attr))}}' }); this.registerComponent('my-action-component', { ComponentClass: _helpers.Component.extend({ actions: { changeValue: function () { this.incrementProperty('myProp'); } } }), template: (0, _abstractTestCase.strip)(_templateObject10) }); this.render('{{my-action-component myProp=model.myProp}}', { model: { myProp: 1 } }); assert.equal(this.$('#nested-prop').text(), '1'); this.runTask(function () { return _this26.rerender(); }); assert.equal(this.$('#nested-prop').text(), '1'); this.runTask(function () { return _this26.$('button').click(); }); assert.equal(this.$('#nested-prop').text(), '2'); this.runTask(function () { return _this26.$('button').click(); }); assert.equal(this.$('#nested-prop').text(), '3'); this.runTask(function () { return _this26.context.set('model', { myProp: 1 }); }); assert.equal(this.$('#nested-prop').text(), '1'); }; _class.prototype['@test adding parameters to a contextual component\'s instance does not add it to other instances'] = function () { var _this27 = this; // If parameters and attributes are not handled correctly, setting a value // in an invokation can leak to others invocation. this.registerComponent('select-box', { template: '{{yield (hash option=(component "select-box-option"))}}' }); this.registerComponent('select-box-option', { template: '{{label}}' }); this.render((0, _abstractTestCase.strip)(_templateObject11)); this.assertText('Foo'); this.runTask(function () { return _this27.rerender(); }); this.assertText('Foo'); }; _class.prototype['@test parameters in a contextual component are mutable when value is a param'] = function (assert) { var _this28 = this; // This checks that a `(mut)` is added to parameters and attributes to // contextual components when it is a param. this.registerComponent('change-button', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['val'] }), template: (0, _abstractTestCase.strip)(_templateObject12) }); this.render((0, _abstractTestCase.strip)(_templateObject13), { model: { val2: 8 } }); assert.equal(this.$('.value').text(), '8'); this.runTask(function () { return _this28.rerender(); }); assert.equal(this.$('.value').text(), '8'); this.runTask(function () { return _this28.$('.my-button').click(); }); assert.equal(this.$('.value').text(), '10'); this.runTask(function () { return _this28.context.set('model', { val2: 8 }); }); assert.equal(this.$('.value').text(), '8'); }; _class.prototype['@test tagless blockless components render'] = function (assert) { var _this29 = this; this.registerComponent('my-comp', { ComponentClass: _helpers.Component.extend({ tagName: '' }) }); this.render('{{my-comp}}'); this.runTask(function () { return _this29.rerender(); }); assert.equal(this.$().text(), ''); }; _class.prototype['@test GH#13494 tagless blockless component with property binding'] = function (assert) { var _this30 = this; this.registerComponent('outer-component', { ComponentClass: _helpers.Component.extend({ message: 'hello', actions: { change: function () { this.set('message', 'goodbye'); } } }), template: (0, _abstractTestCase.strip)(_templateObject14) }); this.registerComponent('inner-component', { ComponentClass: _helpers.Component.extend({ tagName: '' }) }); this.render('{{outer-component}}'); assert.equal(this.$().text(), 'message: hello'); this.runTask(function () { return _this30.rerender(); }); assert.equal(this.$().text(), 'message: hello'); this.runTask(function () { return _this30.$('button').click(); }); assert.equal(this.$().text(), 'message: goodbye'); this.runTask(function () { return _this30.rerender(); }); assert.equal(this.$().text(), 'message: goodbye'); }; _class.prototype['@test GH#13982 contextual component ref is stable even when bound params change'] = function (assert) { var _this31 = this; var instance = void 0, previousInstance = void 0; var initCount = 0; this.registerComponent('my-comp', { ComponentClass: _helpers.Component.extend({ init: function () { this._super(); previousInstance = instance; instance = this; initCount++; }, isOpen: undefined }), template: '{{if isOpen "open" "closed"}}' }); this.render((0, _abstractTestCase.strip)(_templateObject15), { isOpen: true }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'a instance was created'); assert.equal(previousInstance, undefined, 'no previous component exists'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'open', 'the componet text is "open"'); this.runTask(function () { return _this31.rerender(); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'open', 'the componet text is "open"'); this.runTask(function () { return _this31.context.set('isOpen', false); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'closed', 'the component text is "closed"'); this.runTask(function () { return _this31.rerender(); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'closed', 'the component text is "closed"'); this.runTask(function () { return _this31.context.set('isOpen', true); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'open', 'the componet text is "open"'); }; _class.prototype['@test GH#13982 contextual component ref is stable even when bound params change (bound name param)'] = function (assert) { var _this32 = this; var instance = void 0, previousInstance = void 0; var initCount = 0; this.registerComponent('my-comp', { ComponentClass: _helpers.Component.extend({ init: function () { this._super(); previousInstance = instance; instance = this; initCount++; }, isOpen: undefined }), template: '{{if isOpen "open" "closed"}}' }); this.render((0, _abstractTestCase.strip)(_templateObject16), { compName: 'my-comp', isOpen: true }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'a instance was created'); assert.equal(previousInstance, undefined, 'no previous component exists'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'open', 'the componet text is "open"'); this.runTask(function () { return _this32.rerender(); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'open', 'the componet text is "open"'); this.runTask(function () { return _this32.context.set('isOpen', false); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'closed', 'the component text is "closed"'); this.runTask(function () { return _this32.rerender(); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'closed', 'the component text is "closed"'); this.runTask(function () { return _this32.context.set('isOpen', true); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'the component instance exists'); assert.equal(previousInstance, undefined, 'no previous component exists'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'open', 'the componet text is "open"'); }; _class.prototype['@test GH#13982 contextual component ref is recomputed when component name param changes'] = function (assert) { var _this33 = this; var instance = void 0, previousInstance = void 0; var initCount = 0; this.registerComponent('my-comp', { ComponentClass: _helpers.Component.extend({ init: function () { this._super(); previousInstance = instance; instance = this; initCount++; }, isOpen: undefined }), template: 'my-comp: {{if isOpen "open" "closed"}}' }); this.registerComponent('your-comp', { ComponentClass: _helpers.Component.extend({ init: function () { this._super(); previousInstance = instance; instance = this; initCount++; }, isOpen: undefined }), template: 'your-comp: {{if isOpen "open" "closed"}}' }); this.render((0, _abstractTestCase.strip)(_templateObject16), { compName: 'my-comp', isOpen: true }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'a instance was created'); assert.equal(previousInstance, undefined, 'there is no previous instance'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'my-comp: open'); this.runTask(function () { return _this33.rerender(); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'a instance exists after rerender'); assert.equal(previousInstance, undefined, 'there is no previous instance after rerender'); assert.equal(initCount, 1, 'the component was constructed exactly 1 time'); assert.equal(this.$().text(), 'my-comp: open'); this.runTask(function () { return _this33.context.set('compName', 'your-comp'); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'an instance was created after component name changed'); assert.ok(!(0, _emberMetal.isEmpty)(previousInstance), 'a previous instance now exists'); assert.notEqual(instance, previousInstance, 'the instance and previous instance are not the same object'); assert.equal(initCount, 2, 'the component was constructed exactly 2 times'); assert.equal(this.$().text(), 'your-comp: open'); this.runTask(function () { return _this33.rerender(); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'an instance was created after component name changed (rerender)'); assert.ok(!(0, _emberMetal.isEmpty)(previousInstance), 'a previous instance now exists (rerender)'); assert.notEqual(instance, previousInstance, 'the instance and previous instance are not the same object (rerender)'); assert.equal(initCount, 2, 'the component was constructed exactly 2 times (rerender)'); assert.equal(this.$().text(), 'your-comp: open'); this.runTask(function () { return _this33.context.set('compName', 'my-comp'); }); assert.ok(!(0, _emberMetal.isEmpty)(instance), 'an instance was created after component name changed'); assert.ok(!(0, _emberMetal.isEmpty)(previousInstance), 'a previous instance still exists'); assert.notEqual(instance, previousInstance, 'the instance and previous instance are not the same object'); assert.equal(initCount, 3, 'the component was constructed exactly 3 times (rerender)'); assert.equal(this.$().text(), 'my-comp: open'); }; _class.prototype['@test GH#14508 rest positional params are received when passed as named parameter'] = function () { var _this34 = this; this.registerComponent('my-link', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'params' }), template: '{{#each params as |p|}}{{p}}{{/each}}' }); this.render('{{component (component "my-link") params=allParams}}', { allParams: (0, _native_array.A)(['a', 'b']) }); this.assertText('ab'); this.runTask(function () { return _this34.rerender(); }); this.assertText('ab'); this.runTask(function () { return _this34.context.get('allParams').pushObject('c'); }); this.assertText('abc'); this.runTask(function () { return _this34.context.get('allParams').popObject(); }); this.assertText('ab'); this.runTask(function () { return _this34.context.get('allParams').clear(); }); this.assertText(''); this.runTask(function () { return _this34.context.set('allParams', (0, _native_array.A)(['1', '2'])); }); this.assertText('12'); this.runTask(function () { return _this34.context.set('allParams', (0, _native_array.A)(['a', 'b'])); }); this.assertText('ab'); }; _class.prototype['@test GH#14508 rest positional params are received when passed as named parameter with dot notation'] = function () { var _this35 = this; this.registerComponent('my-link', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'params' }), template: '{{#each params as |p|}}{{p}}{{/each}}' }); this.render('{{#with (hash link=(component "my-link")) as |c|}}{{c.link params=allParams}}{{/with}}', { allParams: (0, _native_array.A)(['a', 'b']) }); this.assertText('ab'); this.runTask(function () { return _this35.rerender(); }); this.assertText('ab'); this.runTask(function () { return _this35.context.get('allParams').pushObject('c'); }); this.assertText('abc'); this.runTask(function () { return _this35.context.get('allParams').popObject(); }); this.assertText('ab'); this.runTask(function () { return _this35.context.get('allParams').clear(); }); this.assertText(''); this.runTask(function () { return _this35.context.set('allParams', (0, _native_array.A)(['1', '2'])); }); this.assertText('12'); this.runTask(function () { return _this35.context.set('allParams', (0, _native_array.A)(['a', 'b'])); }); this.assertText('ab'); }; _class.prototype['@test GH#14632 give useful warning when calling contextual components with input as a name'] = function () { var _this36 = this; expectAssertion(function () { _this36.render('{{component (component "input" type="text")}}'); }, 'You cannot use the input helper as a contextual helper. Please extend Ember.TextField or Ember.Checkbox to use it as a contextual component.'); }; _class.prototype['@test GH#14632 give useful warning when calling contextual components with textarea as a name'] = function () { var _this37 = this; expectAssertion(function () { _this37.render('{{component (component "textarea" type="text")}}'); }, 'You cannot use the textarea helper as a contextual helper. Please extend Ember.TextArea to use it as a contextual component.'); }; return _class; }(_testCase.RenderingTest)); var ContextualComponentMutableParamsTest = function (_RenderingTest2) { (0, _emberBabel.inherits)(ContextualComponentMutableParamsTest, _RenderingTest2); function ContextualComponentMutableParamsTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments)); } ContextualComponentMutableParamsTest.prototype.render = function (templateStr) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _RenderingTest2.prototype.render.call(this, templateStr + '{{model.val2}}', (0, _emberUtils.assign)(context, { model: { val2: 8 } })); }; return ContextualComponentMutableParamsTest; }(_testCase.RenderingTest); var MutableParamTestGenerator = function () { function MutableParamTestGenerator(cases) { this.cases = cases; } MutableParamTestGenerator.prototype.generate = function (_ref) { var _ref2; var title = _ref.title, setup = _ref.setup; return _ref2 = {}, _ref2['@test parameters in a contextual component are mutable when value is a ' + title] = function (assert) { var _this39 = this; this.registerComponent('change-button', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['val'] }), template: (0, _abstractTestCase.strip)(_templateObject17) }); setup.call(this, assert); assert.equal(this.$('.value').text(), '8'); this.runTask(function () { return _this39.rerender(); }); assert.equal(this.$('.value').text(), '8'); this.runTask(function () { return _this39.$('.my-button').click(); }); assert.equal(this.$('.value').text(), '10'); this.runTask(function () { return _this39.context.set('model', { val2: 8 }); }); assert.equal(this.$('.value').text(), '8'); }, _ref2; }; return MutableParamTestGenerator; }(); (0, _abstractTestCase.applyMixins)(ContextualComponentMutableParamsTest, new MutableParamTestGenerator([{ title: 'param', setup: function () { this.render('{{component (component "change-button" model.val2)}}'); } }, { title: 'nested param', setup: function () { this.registerComponent('my-comp', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['components'] }), template: '{{component components.comp}}' }); this.render('{{my-comp (hash comp=(component "change-button" model.val2))}}'); } }, { title: 'hash value', setup: function () { this.registerComponent('my-comp', { template: '{{component component}}' }); this.render('{{my-comp component=(component "change-button" val=model.val2)}}'); } }, { title: 'nested hash value', setup: function () { this.registerComponent('my-comp', { template: '{{component components.button}}' }); this.render('{{my-comp components=(hash button=(component "change-button" val=model.val2))}}'); } }])); (0, _testCase.moduleFor)('Components test: contextual components -- mutable params', ContextualComponentMutableParamsTest); }); enifed('ember-glimmer/tests/integration/components/curly-components-test', ['ember-babel', 'ember-metal', 'ember-runtime', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/test-helpers'], function (_emberBabel, _emberMetal, _emberRuntime, _helpers, _abstractTestCase, _testCase, _testHelpers) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{foo-bar class="bar baz"}}\n {{foo-bar classNames="bar baz"}}\n {{foo-bar}}\n '], ['\n {{foo-bar class="bar baz"}}\n {{foo-bar classNames="bar baz"}}\n {{foo-bar}}\n ']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if cond1}}\n {{#foo-bar id=1}}\n {{#if cond2}}\n {{#foo-bar id=2}}{{/foo-bar}}\n {{#if cond3}}\n {{#foo-bar id=3}}\n {{#if cond4}}\n {{#foo-bar id=4}}\n {{#if cond5}}\n {{#foo-bar id=5}}{{/foo-bar}}\n {{#foo-bar id=6}}{{/foo-bar}}\n {{#foo-bar id=7}}{{/foo-bar}}\n {{/if}}\n {{#foo-bar id=8}}{{/foo-bar}}\n {{/foo-bar}}\n {{/if}}\n {{/foo-bar}}\n {{/if}}\n {{/if}}\n {{/foo-bar}}\n {{/if}}'], ['\n {{#if cond1}}\n {{#foo-bar id=1}}\n {{#if cond2}}\n {{#foo-bar id=2}}{{/foo-bar}}\n {{#if cond3}}\n {{#foo-bar id=3}}\n {{#if cond4}}\n {{#foo-bar id=4}}\n {{#if cond5}}\n {{#foo-bar id=5}}{{/foo-bar}}\n {{#foo-bar id=6}}{{/foo-bar}}\n {{#foo-bar id=7}}{{/foo-bar}}\n {{/if}}\n {{#foo-bar id=8}}{{/foo-bar}}\n {{/foo-bar}}\n {{/if}}\n {{/foo-bar}}\n {{/if}}\n {{/if}}\n {{/foo-bar}}\n {{/if}}']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if isStream}}\n true\n {{else}}\n false\n {{/if}}\n '], ['\n {{#if isStream}}\n true\n {{else}}\n false\n {{/if}}\n ']), _templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n Args: {{this.attrs.value}} | {{attrs.value}} | {{value}}\n {{#each this.attrs.items as |item|}}\n {{item}}\n {{/each}}\n {{#each attrs.items as |item|}}\n {{item}}\n {{/each}}\n {{#each items as |item|}}\n {{item}}\n {{/each}}\n '], ['\n Args: {{this.attrs.value}} | {{attrs.value}} | {{value}}\n {{#each this.attrs.items as |item|}}\n {{item}}\n {{/each}}\n {{#each attrs.items as |item|}}\n {{item}}\n {{/each}}\n {{#each items as |item|}}\n {{item}}\n {{/each}}\n ']), _templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['Args: lul | lul | lul111'], ['Args: lul | lul | lul111']), _templateObject6 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with-block someProp=prop}}\n In template\n {{/with-block}}'], ['\n {{#with-block someProp=prop}}\n In template\n {{/with-block}}']), _templateObject7 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each names as |name|}}\n {{name}}\n {{/each}}'], ['\n {{#each names as |name|}}\n {{name}}\n {{/each}}']), _templateObject8 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{sample-component "Foo" 4 "Bar" elementId="args-3"}}\n {{sample-component "Foo" 4 "Bar" 5 "Baz" elementId="args-5"}}'], ['\n {{sample-component "Foo" 4 "Bar" elementId="args-3"}}\n {{sample-component "Foo" 4 "Bar" 5 "Baz" elementId="args-5"}}']), _templateObject9 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{sample-component "one" "two" elementId="two-positional"}}\n {{sample-component "one" second="two" elementId="one-positional"}}\n {{sample-component first="one" second="two" elementId="no-positional"}}'], ['\n {{sample-component "one" "two" elementId="two-positional"}}\n {{sample-component "one" second="two" elementId="one-positional"}}\n {{sample-component first="one" second="two" elementId="no-positional"}}']), _templateObject10 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each n as |name|}}\n {{name}}\n {{/each}}'], ['\n {{#each n as |name|}}\n {{name}}\n {{/each}}']), _templateObject11 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with-template name="with-block"}}\n [In block - {{name}}]\n {{/with-template}}\n {{with-template name="without-block"}}'], ['\n {{#with-template name="with-block"}}\n [In block - {{name}}]\n {{/with-template}}\n {{with-template name="without-block"}}']), _templateObject12 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if hasBlock}}\n {{yield}}\n {{else}}\n No Block!\n {{/if}}'], ['\n {{#if hasBlock}}\n {{yield}}\n {{else}}\n No Block!\n {{/if}}']), _templateObject13 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with-block}}\n In template\n {{/with-block}}'], ['\n {{#with-block}}\n In template\n {{/with-block}}']), _templateObject14 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if hasBlockParams}}\n {{yield this}} - In Component\n {{else}}\n {{yield}} No Block!\n {{/if}}'], ['\n {{#if hasBlockParams}}\n {{yield this}} - In Component\n {{else}}\n {{yield}} No Block!\n {{/if}}']), _templateObject15 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with-block as |something|}}\n In template\n {{/with-block}}'], ['\n {{#with-block as |something|}}\n In template\n {{/with-block}}']), _templateObject16 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if hasBlockParams}}\n {{yield this}}\n {{else}}\n {{yield}} No Block Param!\n {{/if}}'], ['\n {{#if hasBlockParams}}\n {{yield this}}\n {{else}}\n {{yield}} No Block Param!\n {{/if}}']), _templateObject17 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with-block}}\n In block\n {{/with-block}}'], ['\n {{#with-block}}\n In block\n {{/with-block}}']), _templateObject18 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if predicate}}\n Yes:{{yield someValue}}\n {{else}}\n No:{{yield to="inverse"}}\n {{/if}}'], ['\n {{#if predicate}}\n Yes:{{yield someValue}}\n {{else}}\n No:{{yield to="inverse"}}\n {{/if}}']), _templateObject19 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#my-if predicate=activated someValue=42 as |result|}}\n Hello{{result}}\n {{else}}\n Goodbye\n {{/my-if}}'], ['\n {{#my-if predicate=activated someValue=42 as |result|}}\n Hello{{result}}\n {{else}}\n Goodbye\n {{/my-if}}']), _templateObject20 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if (hasBlock "inverse")}}\n Yes\n {{else}}\n No\n {{/if}}'], ['\n {{#if (hasBlock "inverse")}}\n Yes\n {{else}}\n No\n {{/if}}']), _templateObject21 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#check-inverse}}{{/check-inverse}}\n {{#check-inverse}}{{else}}{{/check-inverse}}'], ['\n {{#check-inverse}}{{/check-inverse}}\n {{#check-inverse}}{{else}}{{/check-inverse}}']), _templateObject22 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if (hasBlock)}}\n Yes\n {{else}}\n No\n {{/if}}'], ['\n {{#if (hasBlock)}}\n Yes\n {{else}}\n No\n {{/if}}']), _templateObject23 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{check-block}}\n {{#check-block}}{{/check-block}}'], ['\n {{check-block}}\n {{#check-block}}{{/check-block}}']), _templateObject24 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if (hasBlockParams "inverse")}}\n Yes\n {{else}}\n No\n {{/if}}'], ['\n {{#if (hasBlockParams "inverse")}}\n Yes\n {{else}}\n No\n {{/if}}']), _templateObject25 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#check-inverse}}{{/check-inverse}}\n {{#check-inverse as |something|}}{{/check-inverse}}'], ['\n {{#check-inverse}}{{/check-inverse}}\n {{#check-inverse as |something|}}{{/check-inverse}}']), _templateObject26 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if (hasBlockParams)}}\n Yes\n {{else}}\n No\n {{/if}}'], ['\n {{#if (hasBlockParams)}}\n Yes\n {{else}}\n No\n {{/if}}']), _templateObject27 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#check-block}}{{/check-block}}\n {{#check-block as |something|}}{{/check-block}}'], ['\n {{#check-block}}{{/check-block}}\n {{#check-block as |something|}}{{/check-block}}']), _templateObject28 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if hasBlock}}\n Yes\n {{else}}\n No\n {{/if}}'], ['\n {{#if hasBlock}}\n Yes\n {{else}}\n No\n {{/if}}']), _templateObject29 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#check-params}}{{/check-params}}\n {{#check-params as |foo|}}{{/check-params}}'], ['\n {{#check-params}}{{/check-params}}\n {{#check-params as |foo|}}{{/check-params}}']), _templateObject30 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if hasBlockParams}}\n Yes\n {{else}}\n No\n {{/if}}'], ['\n {{#if hasBlockParams}}\n Yes\n {{else}}\n No\n {{/if}}']), _templateObject31 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{check-attr}}\n {{#check-attr}}{{/check-attr}}'], ['\n {{check-attr}}\n {{#check-attr}}{{/check-attr}}']), _templateObject32 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#check-attr}}{{/check-attr}}\n {{#check-attr}}{{else}}{{/check-attr}}'], ['\n {{#check-attr}}{{/check-attr}}\n {{#check-attr}}{{else}}{{/check-attr}}']), _templateObject33 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#check-attr}}{{/check-attr}}\n {{#check-attr as |something|}}{{/check-attr}}'], ['\n {{#check-attr}}{{/check-attr}}\n {{#check-attr as |something|}}{{/check-attr}}']), _templateObject34 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{check-helper}}\n {{#check-helper}}{{/check-helper}}'], ['\n {{check-helper}}\n {{#check-helper}}{{/check-helper}}']), _templateObject35 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#check-helper}}{{/check-helper}}\n {{#check-helper}}{{else}}{{/check-helper}}'], ['\n {{#check-helper}}{{/check-helper}}\n {{#check-helper}}{{else}}{{/check-helper}}']), _templateObject36 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#check-helper}}{{/check-helper}}\n {{#check-helper as |something|}}{{/check-helper}}'], ['\n {{#check-helper}}{{/check-helper}}\n {{#check-helper as |something|}}{{/check-helper}}']), _templateObject37 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#x-outer}}\n {{#if showInner}}\n {{x-inner}}\n {{/if}}\n {{/x-outer}}'], ['\n {{#x-outer}}\n {{#if showInner}}\n {{x-inner}}\n {{/if}}\n {{/x-outer}}']), _templateObject38 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n In layout. {{#each items as |item|}}\n [{{child-non-block item=item}}]\n {{/each}}'], ['\n In layout. {{#each items as |item|}}\n [{{child-non-block item=item}}]\n {{/each}}']), _templateObject39 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#some-clicky-thing classNames="baz"}}\n Click Me\n {{/some-clicky-thing}}'], ['\n {{#some-clicky-thing classNames="baz"}}\n Click Me\n {{/some-clicky-thing}}']), _templateObject40 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each blahzz as |p|}}\n {{p}}\n {{/each}}\n - {{yield}}'], ['\n {{#each blahzz as |p|}}\n {{p}}\n {{/each}}\n - {{yield}}']), _templateObject41 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#some-clicky-thing blahzz="baz"}}\n Click Me\n {{/some-clicky-thing}}'], ['\n {{#some-clicky-thing blahzz="baz"}}\n Click Me\n {{/some-clicky-thing}}']), _templateObject42 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#x-select value=value as |select|}}\n {{#x-option value="1" select=select}}1{{/x-option}}\n {{#x-option value="2" select=select}}2{{/x-option}}\n {{/x-select}}\n '], ['\n {{#x-select value=value as |select|}}\n {{#x-option value="1" select=select}}1{{/x-option}}\n {{#x-option value="2" select=select}}2{{/x-option}}\n {{/x-select}}\n ']), _templateObject43 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#list-items items=items as |thing|}}\n |{{thing}}|\n\n {{#if editMode}}\n Remove {{thing}}\n {{/if}}\n {{/list-items}}\n '], ['\n {{#list-items items=items as |thing|}}\n |{{thing}}|\n\n {{#if editMode}}\n Remove {{thing}}\n {{/if}}\n {{/list-items}}\n ']); (0, _testCase.moduleFor)('Components test: curly components', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test it can render a basic component'] = function () { var _this2 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar}}'); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return _this2.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello' }); }; _class.prototype['@test it can render a template only component'] = function () { var _this3 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar}}'); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return _this3.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello' }); }; _class.prototype['@test it can have a custom id and it is not bound'] = function () { var _this4 = this; this.registerComponent('foo-bar', { template: '{{id}} {{elementId}}' }); this.render('{{foo-bar id=customId}}', { customId: 'bizz' }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { id: 'bizz' }, content: 'bizz bizz' }); this.runTask(function () { return _this4.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { id: 'bizz' }, content: 'bizz bizz' }); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'customId', 'bar'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { id: 'bizz' }, content: 'bar bizz' }); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'customId', 'bizz'); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { id: 'bizz' }, content: 'bizz bizz' }); }; _class.prototype['@test elementId cannot change'] = function (assert) { var component = void 0, willThrow; var FooBarComponent = _helpers.Component.extend({ elementId: 'blahzorz', init: function () { this._super.apply(this, arguments); component = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{elementId}}' }); this.render('{{foo-bar}}'); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { id: 'blahzorz' }, content: 'blahzorz' }); if (EmberDev && !EmberDev.runningProdBuild) { willThrow = function () { return (0, _emberMetal.run)(null, _emberMetal.set, component, 'elementId', 'herpyderpy'); }; assert.throws(willThrow, /Changing a view's elementId after creation is not allowed/); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { id: 'blahzorz' }, content: 'blahzorz' }); } }; _class.prototype['@test can specify template with `layoutName` property'] = function () { var FooBarComponent = _helpers.Component.extend({ elementId: 'blahzorz', layoutName: 'fizz-bar', init: function () { this._super.apply(this, arguments); this.local = 'hey'; } }); this.registerTemplate('fizz-bar', 'FIZZ BAR {{local}}'); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); this.render('{{foo-bar}}'); this.assertText('FIZZ BAR hey'); }; _class.prototype['@test can specify template with `defaultLayout` property [DEPRECATED]'] = function () { expectDeprecation(/Specifying `defaultLayout` to .* is deprecated. Please use `layout` instead/); var FooBarComponent = _helpers.Component.extend({ elementId: 'blahzorz', defaultLayout: (0, _helpers.compile)('much wat {{lulz}}'), init: function () { this._super.apply(this, arguments); this.lulz = 'hey'; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); this.render('{{foo-bar}}'); this.assertText('much wat hey'); }; _class.prototype['@test layout takes precedence over defaultLayout'] = function () { var FooBarComponent = _helpers.Component.extend({ elementId: 'blahzorz', layout: (0, _helpers.compile)('so much layout wat {{lulz}}'), defaultLayout: (0, _helpers.compile)('much wat {{lulz}}'), init: function () { this._super.apply(this, arguments); this.lulz = 'hey'; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); this.render('{{foo-bar}}'); this.assertText('so much layout wat hey'); }; _class.prototype['@test layout supports computed property'] = function () { var FooBarComponent = _helpers.Component.extend({ elementId: 'blahzorz', layout: (0, _emberMetal.computed)(function () { return (0, _helpers.compile)('so much layout wat {{lulz}}'); }), init: function () { this._super.apply(this, arguments); this.lulz = 'heyo'; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); this.render('{{foo-bar}}'); this.assertText('so much layout wat heyo'); }; _class.prototype['@test passing undefined elementId results in a default elementId'] = function (assert) { var _this5 = this; var FooBarComponent = _helpers.Component.extend({ tagName: 'h1' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'something' }); this.render('{{foo-bar id=somethingUndefined}}'); var foundId = this.$('h1').attr('id'); assert.ok(/^ember/.test(foundId), 'Has a reasonable id attribute (found id=' + foundId + ').'); this.runTask(function () { return _this5.rerender(); }); var newFoundId = this.$('h1').attr('id'); assert.ok(/^ember/.test(newFoundId), 'Has a reasonable id attribute (found id=' + newFoundId + ').'); assert.equal(foundId, newFoundId); }; _class.prototype['@test id is an alias for elementId'] = function (assert) { var _this6 = this; var FooBarComponent = _helpers.Component.extend({ tagName: 'h1' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'something' }); this.render('{{foo-bar id="custom-id"}}'); var foundId = this.$('h1').attr('id'); assert.equal(foundId, 'custom-id'); this.runTask(function () { return _this6.rerender(); }); var newFoundId = this.$('h1').attr('id'); assert.equal(newFoundId, 'custom-id'); assert.equal(foundId, newFoundId); }; _class.prototype['@test cannot pass both id and elementId at the same time'] = function () { var _this7 = this; this.registerComponent('foo-bar', { template: '' }); expectAssertion(function () { _this7.render('{{foo-bar id="zomg" elementId="lol"}}'); }, /You cannot invoke a component with both 'id' and 'elementId' at the same time./); }; _class.prototype['@test it can have a custom tagName'] = function () { var _this8 = this; var FooBarComponent = _helpers.Component.extend({ tagName: 'foo-bar' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar}}'); this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' }); this.runTask(function () { return _this8.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' }); }; _class.prototype['@test it can have a custom tagName set in the constructor'] = function () { var _this9 = this; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); this.tagName = 'foo-bar'; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar}}'); this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' }); this.runTask(function () { return _this9.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' }); }; _class.prototype['@test it can have a custom tagName from the invocation'] = function () { var _this10 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar tagName="foo-bar"}}'); this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' }); this.runTask(function () { return _this10.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'foo-bar', content: 'hello' }); }; _class.prototype['@test tagName can not be a computed property'] = function () { var _this11 = this; var FooBarComponent = _helpers.Component.extend({ tagName: (0, _emberMetal.computed)(function () { return 'foo-bar'; }) }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); expectAssertion(function () { _this11.render('{{foo-bar}}'); }, /You cannot use a computed property for the component's `tagName` \(<\(.+>\)\./); }; _class.prototype['@test class is applied before didInsertElement'] = function (assert) { var componentClass = void 0; var FooBarComponent = _helpers.Component.extend({ didInsertElement: function () { componentClass = this.element.className; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar class="foo-bar"}}'); assert.equal(componentClass, 'foo-bar ember-view'); }; _class.prototype['@test it can have custom classNames'] = function () { var _this12 = this; var FooBarComponent = _helpers.Component.extend({ classNames: ['foo', 'bar'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar}}'); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo bar') }, content: 'hello' }); this.runTask(function () { return _this12.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo bar') }, content: 'hello' }); }; _class.prototype['@test should not apply falsy class name'] = function () { var _this13 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar class=somethingFalsy}}', { somethingFalsy: false }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: 'ember-view' }, content: 'hello' }); this.runTask(function () { return _this13.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: 'ember-view' }, content: 'hello' }); }; _class.prototype['@test should apply classes of the dasherized property name when bound property specified is true'] = function () { var _this14 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar class=model.someTruth}}', { model: { someTruth: true } }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('ember-view some-truth') }, content: 'hello' }); this.runTask(function () { return _this14.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('ember-view some-truth') }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'model.someTruth', false); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('ember-view') }, content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'model', { someTruth: true }); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('ember-view some-truth') }, content: 'hello' }); }; _class.prototype['@test class property on components can be dynamic'] = function () { var _this15 = this; this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar class=(if fooBar "foo-bar")}}', { fooBar: true }); this.assertComponentElement(this.firstChild, { content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo-bar') } }); this.runTask(function () { return _this15.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo-bar') } }); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'fooBar', false); }); this.assertComponentElement(this.firstChild, { content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('ember-view') } }); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'fooBar', true); }); this.assertComponentElement(this.firstChild, { content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo-bar') } }); }; _class.prototype['@test it can have custom classNames from constructor'] = function () { var _this16 = this; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); this.classNames = this.classNames.slice(); this.classNames.push('foo', 'bar', 'outside-' + this.get('extraClass')); } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar extraClass="baz"}}'); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo bar outside-baz') }, content: 'hello' }); this.runTask(function () { return _this16.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo bar outside-baz') }, content: 'hello' }); }; _class.prototype['@test it can set custom classNames from the invocation'] = function () { var _this17 = this; var FooBarComponent = _helpers.Component.extend({ classNames: ['foo'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render((0, _abstractTestCase.strip)(_templateObject)); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo bar baz') }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo bar baz') }, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo') }, content: 'hello' }); this.runTask(function () { return _this17.rerender(); }); this.assertComponentElement(this.nthChild(0), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo bar baz') }, content: 'hello' }); this.assertComponentElement(this.nthChild(1), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo bar baz') }, content: 'hello' }); this.assertComponentElement(this.nthChild(2), { tagName: 'div', attrs: { 'class': (0, _testHelpers.classes)('ember-view foo') }, content: 'hello' }); }; _class.prototype['@test it has an element'] = function () { var _this18 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); instance = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar}}'); var element1 = instance.element; this.assertComponentElement(element1, { content: 'hello' }); this.runTask(function () { return _this18.rerender(); }); var element2 = instance.element; this.assertComponentElement(element2, { content: 'hello' }); this.assertSameNode(element2, element1); }; _class.prototype['@test it has a jQuery proxy to the element'] = function () { var _this19 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); instance = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{foo-bar}}'); var element1 = instance.$()[0]; this.assertComponentElement(element1, { content: 'hello' }); this.runTask(function () { return _this19.rerender(); }); var element2 = instance.$()[0]; this.assertComponentElement(element2, { content: 'hello' }); this.assertSameNode(element2, element1); }; _class.prototype['@test it scopes the jQuery proxy to the component element'] = function (assert) { var _this20 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); instance = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'inner' }); this.render('outer{{foo-bar}}'); var $span = instance.$('span'); assert.equal($span.length, 1); assert.equal($span.attr('class'), 'inner'); this.runTask(function () { return _this20.rerender(); }); $span = instance.$('span'); assert.equal($span.length, 1); assert.equal($span.attr('class'), 'inner'); }; _class.prototype['@test an empty component does not have childNodes'] = function (assert) { var _this21 = this; var fooBarInstance = void 0; var FooBarComponent = _helpers.Component.extend({ tagName: 'input', init: function () { this._super(); fooBarInstance = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '' }); this.render('{{foo-bar}}'); this.assertComponentElement(this.firstChild, { tagName: 'input' }); assert.strictEqual(fooBarInstance.element.childNodes.length, 0); this.runTask(function () { return _this21.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'input' }); assert.strictEqual(fooBarInstance.element.childNodes.length, 0); }; _class.prototype['@test it has the right parentView and childViews'] = function (assert) { var _this22 = this; var fooBarInstance = void 0, fooBarBazInstance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); fooBarInstance = this; } }); var FooBarBazComponent = _helpers.Component.extend({ init: function () { this._super(); fooBarBazInstance = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'foo-bar {{foo-bar-baz}}' }); this.registerComponent('foo-bar-baz', { ComponentClass: FooBarBazComponent, template: 'foo-bar-baz' }); this.render('{{foo-bar}}'); this.assertText('foo-bar foo-bar-baz'); assert.equal(fooBarInstance.parentView, this.component); assert.equal(fooBarBazInstance.parentView, fooBarInstance); assert.deepEqual(this.component.childViews, [fooBarInstance]); assert.deepEqual(fooBarInstance.childViews, [fooBarBazInstance]); this.runTask(function () { return _this22.rerender(); }); this.assertText('foo-bar foo-bar-baz'); assert.equal(fooBarInstance.parentView, this.component); assert.equal(fooBarBazInstance.parentView, fooBarInstance); assert.deepEqual(this.component.childViews, [fooBarInstance]); assert.deepEqual(fooBarInstance.childViews, [fooBarBazInstance]); }; _class.prototype['@test it renders passed named arguments'] = function () { var _this23 = this; this.registerComponent('foo-bar', { template: '{{foo}}' }); this.render('{{foo-bar foo=model.bar}}', { model: { bar: 'Hola' } }); this.assertText('Hola'); this.runTask(function () { return _this23.rerender(); }); this.assertText('Hola'); this.runTask(function () { return _this23.context.set('model.bar', 'Hello'); }); this.assertText('Hello'); this.runTask(function () { return _this23.context.set('model', { bar: 'Hola' }); }); this.assertText('Hola'); }; _class.prototype['@test it can render a basic component with a block'] = function () { var _this24 = this; this.registerComponent('foo-bar', { template: '{{yield}} - In component' }); this.render('{{#foo-bar}}hello{{/foo-bar}}'); this.assertComponentElement(this.firstChild, { content: 'hello - In component' }); this.runTask(function () { return _this24.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello - In component' }); }; _class.prototype['@test it can render a basic component with a block when the yield is in a partial'] = function () { var _this25 = this; this.registerPartial('_partialWithYield', 'yielded: [{{yield}}]'); this.registerComponent('foo-bar', { template: '{{partial "partialWithYield"}} - In component' }); this.render('{{#foo-bar}}hello{{/foo-bar}}'); this.assertComponentElement(this.firstChild, { content: 'yielded: [hello] - In component' }); this.runTask(function () { return _this25.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'yielded: [hello] - In component' }); }; _class.prototype['@test it can render a basic component with a block param when the yield is in a partial'] = function () { var _this26 = this; this.registerPartial('_partialWithYield', 'yielded: [{{yield "hello"}}]'); this.registerComponent('foo-bar', { template: '{{partial "partialWithYield"}} - In component' }); this.render('{{#foo-bar as |value|}}{{value}}{{/foo-bar}}'); this.assertComponentElement(this.firstChild, { content: 'yielded: [hello] - In component' }); this.runTask(function () { return _this26.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'yielded: [hello] - In component' }); }; _class.prototype['@test it renders the layout with the component instance as the context'] = function () { var _this27 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); instance = this; this.set('message', 'hello'); } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{message}}' }); this.render('{{foo-bar}}'); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return _this27.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(instance, 'message', 'goodbye'); }); this.assertComponentElement(this.firstChild, { content: 'goodbye' }); this.runTask(function () { return (0, _emberMetal.set)(instance, 'message', 'hello'); }); this.assertComponentElement(this.firstChild, { content: 'hello' }); }; _class.prototype['@test it preserves the outer context when yielding'] = function () { var _this28 = this; this.registerComponent('foo-bar', { template: '{{yield}}' }); this.render('{{#foo-bar}}{{message}}{{/foo-bar}}', { message: 'hello' }); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return _this28.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this28.context, 'message', 'goodbye'); }); this.assertComponentElement(this.firstChild, { content: 'goodbye' }); this.runTask(function () { return (0, _emberMetal.set)(_this28.context, 'message', 'hello'); }); this.assertComponentElement(this.firstChild, { content: 'hello' }); }; _class.prototype['@test it can yield a block param named for reserved words [GH#14096]'] = function () { var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); instance = this; }, name: 'foo-bar' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{yield this}}' }); this.render('{{#foo-bar as |component|}}{{component.name}}{{/foo-bar}}'); this.assertComponentElement(this.firstChild, { content: 'foo-bar' }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(instance, 'name', 'derp-qux'); }); this.assertComponentElement(this.firstChild, { content: 'derp-qux' }); this.runTask(function () { return (0, _emberMetal.set)(instance, 'name', 'foo-bar'); }); this.assertComponentElement(this.firstChild, { content: 'foo-bar' }); }; _class.prototype['@test it can yield internal and external properties positionally'] = function () { var _this29 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); instance = this; }, greeting: 'hello' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{yield greeting greetee.firstName}}' }); this.render('{{#foo-bar greetee=person as |greeting name|}}{{name}} {{person.lastName}}, {{greeting}}{{/foo-bar}}', { person: { firstName: 'Joel', lastName: 'Kang' } }); this.assertComponentElement(this.firstChild, { content: 'Joel Kang, hello' }); this.runTask(function () { return _this29.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'Joel Kang, hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this29.context, 'person', { firstName: 'Dora', lastName: 'the Explorer' }); }); this.assertComponentElement(this.firstChild, { content: 'Dora the Explorer, hello' }); this.runTask(function () { return (0, _emberMetal.set)(instance, 'greeting', 'hola'); }); this.assertComponentElement(this.firstChild, { content: 'Dora the Explorer, hola' }); this.runTask(function () { (0, _emberMetal.set)(instance, 'greeting', 'hello'); (0, _emberMetal.set)(_this29.context, 'person', { firstName: 'Joel', lastName: 'Kang' }); }); this.assertComponentElement(this.firstChild, { content: 'Joel Kang, hello' }); }; _class.prototype['@test #11519 - block param infinite loop'] = function () { var _this30 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); instance = this; }, danger: 0 }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{danger}}{{yield danger}}' }); // On initial render, create streams. The bug will not have manifested yet, but at this point // we have created streams that create a circular invalidation. this.render('{{#foo-bar as |dangerBlockParam|}}{{/foo-bar}}'); this.assertText('0'); // Trigger a non-revalidating re-render. The yielded block will not be dirtied // nor will block param streams, and thus no infinite loop will occur. this.runTask(function () { return _this30.rerender(); }); this.assertText('0'); // Trigger a revalidation, which will cause an infinite loop without the fix // in place. Note that we do not see the infinite loop is in testing mode, // because a deprecation warning about re-renders is issued, which Ember // treats as an exception. this.runTask(function () { return (0, _emberMetal.set)(instance, 'danger', 1); }); this.assertText('1'); this.runTask(function () { return (0, _emberMetal.set)(instance, 'danger', 0); }); this.assertText('0'); }; _class.prototype['@test the component and its child components are destroyed'] = function (assert) { var _this31 = this; var destroyed = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0 }; this.registerComponent('foo-bar', { template: '{{id}} {{yield}}', ComponentClass: _helpers.Component.extend({ willDestroy: function () { this._super(); destroyed[this.get('id')]++; } }) }); this.render((0, _abstractTestCase.strip)(_templateObject2), { cond1: true, cond2: true, cond3: true, cond4: true, cond5: true }); this.assertText('1 2 3 4 5 6 7 8 '); this.runTask(function () { return _this31.rerender(); }); assert.deepEqual(destroyed, { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0 }); this.runTask(function () { return (0, _emberMetal.set)(_this31.context, 'cond5', false); }); this.assertText('1 2 3 4 8 '); assert.deepEqual(destroyed, { 1: 0, 2: 0, 3: 0, 4: 0, 5: 1, 6: 1, 7: 1, 8: 0 }); this.runTask(function () { (0, _emberMetal.set)(_this31.context, 'cond3', false); (0, _emberMetal.set)(_this31.context, 'cond5', true); (0, _emberMetal.set)(_this31.context, 'cond4', false); }); assert.deepEqual(destroyed, { 1: 0, 2: 0, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1 }); this.runTask(function () { (0, _emberMetal.set)(_this31.context, 'cond2', false); (0, _emberMetal.set)(_this31.context, 'cond1', false); }); assert.deepEqual(destroyed, { 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1 }); }; _class.prototype['@test should escape HTML in normal mustaches'] = function () { var _this32 = this; var component = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, output: 'you need to be more bold' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{output}}' }); this.render('{{foo-bar}}'); this.assertText('you need to be more bold'); this.runTask(function () { return _this32.rerender(); }); this.assertText('you need to be more bold'); this.runTask(function () { return (0, _emberMetal.set)(component, 'output', 'you are so super'); }); this.assertText('you are so super'); this.runTask(function () { return (0, _emberMetal.set)(component, 'output', 'you need to be more bold'); }); }; _class.prototype['@test should not escape HTML in triple mustaches'] = function () { var _this33 = this; var expectedHtmlBold = 'you need to be more bold'; var expectedHtmlItalic = 'you are so super'; var component = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, output: expectedHtmlBold }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{{output}}}' }); this.render('{{foo-bar}}'); (0, _testHelpers.equalTokens)(this.firstChild, expectedHtmlBold); this.runTask(function () { return _this33.rerender(); }); (0, _testHelpers.equalTokens)(this.firstChild, expectedHtmlBold); this.runTask(function () { return (0, _emberMetal.set)(component, 'output', expectedHtmlItalic); }); (0, _testHelpers.equalTokens)(this.firstChild, expectedHtmlItalic); this.runTask(function () { return (0, _emberMetal.set)(component, 'output', expectedHtmlBold); }); (0, _testHelpers.equalTokens)(this.firstChild, expectedHtmlBold); }; _class.prototype['@test should not escape HTML if string is a htmlSafe'] = function () { var _this34 = this; var expectedHtmlBold = 'you need to be more bold'; var expectedHtmlItalic = 'you are so super'; var component = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, output: (0, _helpers.htmlSafe)(expectedHtmlBold) }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{output}}' }); this.render('{{foo-bar}}'); (0, _testHelpers.equalTokens)(this.firstChild, expectedHtmlBold); this.runTask(function () { return _this34.rerender(); }); (0, _testHelpers.equalTokens)(this.firstChild, expectedHtmlBold); this.runTask(function () { return (0, _emberMetal.set)(component, 'output', (0, _helpers.htmlSafe)(expectedHtmlItalic)); }); (0, _testHelpers.equalTokens)(this.firstChild, expectedHtmlItalic); this.runTask(function () { return (0, _emberMetal.set)(component, 'output', (0, _helpers.htmlSafe)(expectedHtmlBold)); }); (0, _testHelpers.equalTokens)(this.firstChild, expectedHtmlBold); }; _class.prototype['@test late bound layouts return the same definition'] = function (assert) { var templateIds = []; // This is testing the scenario where you import a template and // set it to the layout property: // // import layout from './template'; // // export default Ember.Component.extend({ // layout // }); var hello = (0, _helpers.compile)('Hello'); var bye = (0, _helpers.compile)('Bye'); var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); this.layout = this.cond ? hello : bye; templateIds.push(this.layout.id); } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent }); this.render('{{foo-bar cond=true}}{{foo-bar cond=false}}{{foo-bar cond=true}}{{foo-bar cond=false}}'); var t1 = templateIds[0], t2 = templateIds[1], t3 = templateIds[2], t4 = templateIds[3]; assert.equal(t1, t3); assert.equal(t2, t4); }; _class.prototype['@test can use isStream property without conflict (#13271)'] = function () { var _this35 = this; var component = void 0; var FooBarComponent = _helpers.Component.extend({ isStream: true, init: function () { this._super.apply(this, arguments); component = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: (0, _abstractTestCase.strip)(_templateObject3) }); this.render('{{foo-bar}}'); this.assertComponentElement(this.firstChild, { content: 'true' }); this.runTask(function () { return _this35.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'true' }); this.runTask(function () { return (0, _emberMetal.set)(component, 'isStream', false); }); this.assertComponentElement(this.firstChild, { content: 'false' }); this.runTask(function () { return (0, _emberMetal.set)(component, 'isStream', true); }); this.assertComponentElement(this.firstChild, { content: 'true' }); }; _class.prototype['@test lookup of component takes priority over property'] = function () { var _this36 = this; this.registerComponent('some-component', { template: 'some-component' }); this.render('{{some-prop}} {{some-component}}', { 'some-component': 'not-some-component', 'some-prop': 'some-prop' }); this.assertText('some-prop some-component'); this.runTask(function () { return _this36.rerender(); }); this.assertText('some-prop some-component'); }; _class.prototype['@test component without dash is not looked up'] = function () { var _this37 = this; this.registerComponent('somecomponent', { template: 'somecomponent' }); this.render('{{somecomponent}}', { 'somecomponent': 'notsomecomponent' }); this.assertText('notsomecomponent'); this.runTask(function () { return _this37.rerender(); }); this.assertText('notsomecomponent'); this.runTask(function () { return _this37.context.set('somecomponent', 'not not notsomecomponent'); }); this.assertText('not not notsomecomponent'); this.runTask(function () { return _this37.context.set('somecomponent', 'notsomecomponent'); }); this.assertText('notsomecomponent'); }; _class.prototype['@test non-block with properties on attrs'] = function () { var _this38 = this; this.registerComponent('non-block', { template: 'In layout - someProp: {{attrs.someProp}}' }); this.render('{{non-block someProp=prop}}', { prop: 'something here' }); this.assertText('In layout - someProp: something here'); this.runTask(function () { return _this38.rerender(); }); this.assertText('In layout - someProp: something here'); this.runTask(function () { return _this38.context.set('prop', 'other thing there'); }); this.assertText('In layout - someProp: other thing there'); this.runTask(function () { return _this38.context.set('prop', 'something here'); }); this.assertText('In layout - someProp: something here'); }; _class.prototype['@test non-block with properties overridden in init'] = function () { var _this39 = this; var instance = void 0; this.registerComponent('non-block', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); instance = this; this.someProp = 'value set in instance'; } }), template: 'In layout - someProp: {{someProp}}' }); this.render('{{non-block someProp=prop}}', { prop: 'something passed when invoked' }); this.assertText('In layout - someProp: value set in instance'); this.runTask(function () { return _this39.rerender(); }); this.assertText('In layout - someProp: value set in instance'); this.runTask(function () { return _this39.context.set('prop', 'updated something passed when invoked'); }); this.assertText('In layout - someProp: updated something passed when invoked'); this.runTask(function () { return instance.set('someProp', 'update value set in instance'); }); this.assertText('In layout - someProp: update value set in instance'); this.runTask(function () { return _this39.context.set('prop', 'something passed when invoked'); }); this.runTask(function () { return instance.set('someProp', 'value set in instance'); }); this.assertText('In layout - someProp: value set in instance'); }; _class.prototype['@test rerendering component with attrs from parent'] = function (assert) { var _this40 = this; var willUpdateCount = 0; var didReceiveAttrsCount = 0; function expectHooks(_ref, callback) { var willUpdate = _ref.willUpdate, didReceiveAttrs = _ref.didReceiveAttrs; willUpdateCount = 0; didReceiveAttrsCount = 0; callback(); if (willUpdate) { assert.strictEqual(willUpdateCount, 1, 'The willUpdate hook was fired'); } else { assert.strictEqual(willUpdateCount, 0, 'The willUpdate hook was not fired'); } if (didReceiveAttrs) { assert.strictEqual(didReceiveAttrsCount, 1, 'The didReceiveAttrs hook was fired'); } else { assert.strictEqual(didReceiveAttrsCount, 0, 'The didReceiveAttrs hook was not fired'); } } this.registerComponent('non-block', { ComponentClass: _helpers.Component.extend({ didReceiveAttrs: function () { didReceiveAttrsCount++; }, willUpdate: function () { willUpdateCount++; } }), template: 'In layout - someProp: {{someProp}}' }); expectHooks({ willUpdate: false, didReceiveAttrs: true }, function () { _this40.render('{{non-block someProp=someProp}}', { someProp: 'wycats' }); }); this.assertText('In layout - someProp: wycats'); // Note: Hooks are not fired in Glimmer for idempotent re-renders expectHooks({ willUpdate: false, didReceiveAttrs: false }, function () { _this40.runTask(function () { return _this40.rerender(); }); }); this.assertText('In layout - someProp: wycats'); expectHooks({ willUpdate: true, didReceiveAttrs: true }, function () { _this40.runTask(function () { return _this40.context.set('someProp', 'tomdale'); }); }); this.assertText('In layout - someProp: tomdale'); // Note: Hooks are not fired in Glimmer for idempotent re-renders expectHooks({ willUpdate: false, didReceiveAttrs: false }, function () { _this40.runTask(function () { return _this40.rerender(); }); }); this.assertText('In layout - someProp: tomdale'); expectHooks({ willUpdate: true, didReceiveAttrs: true }, function () { _this40.runTask(function () { return _this40.context.set('someProp', 'wycats'); }); }); this.assertText('In layout - someProp: wycats'); }; _class.prototype['@test this.attrs.foo === attrs.foo === foo'] = function () { var _this41 = this; this.registerComponent('foo-bar', { template: (0, _abstractTestCase.strip)(_templateObject4) }); this.render('{{foo-bar value=model.value items=model.items}}', { model: { value: 'wat', items: [1, 2, 3] } }); this.assertStableRerender(); this.runTask(function () { _this41.context.set('model.value', 'lul'); _this41.context.set('model.items', [1]); }); this.assertText((0, _abstractTestCase.strip)(_templateObject5)); this.runTask(function () { return _this41.context.set('model', { value: 'wat', items: [1, 2, 3] }); }); this.assertText('Args: wat | wat | wat123123123'); }; _class.prototype['@test non-block with properties on self'] = function () { var _this42 = this; this.registerComponent('non-block', { template: 'In layout - someProp: {{someProp}}' }); this.render('{{non-block someProp=prop}}', { prop: 'something here' }); this.assertText('In layout - someProp: something here'); this.runTask(function () { return _this42.rerender(); }); this.assertText('In layout - someProp: something here'); this.runTask(function () { return _this42.context.set('prop', 'something else'); }); this.assertText('In layout - someProp: something else'); this.runTask(function () { return _this42.context.set('prop', 'something here'); }); this.assertText('In layout - someProp: something here'); }; _class.prototype['@test block with properties on self'] = function () { var _this43 = this; this.registerComponent('with-block', { template: 'In layout - someProp: {{someProp}} - {{yield}}' }); this.render((0, _abstractTestCase.strip)(_templateObject6), { prop: 'something here' }); this.assertText('In layout - someProp: something here - In template'); this.runTask(function () { return _this43.rerender(); }); this.assertText('In layout - someProp: something here - In template'); this.runTask(function () { return _this43.context.set('prop', 'something else'); }); this.assertText('In layout - someProp: something else - In template'); this.runTask(function () { return _this43.context.set('prop', 'something here'); }); this.assertText('In layout - someProp: something here - In template'); }; _class.prototype['@test block with properties on attrs'] = function () { var _this44 = this; this.registerComponent('with-block', { template: 'In layout - someProp: {{attrs.someProp}} - {{yield}}' }); this.render((0, _abstractTestCase.strip)(_templateObject6), { prop: 'something here' }); this.assertText('In layout - someProp: something here - In template'); this.runTask(function () { return _this44.rerender(); }); this.assertText('In layout - someProp: something here - In template'); this.runTask(function () { return _this44.context.set('prop', 'something else'); }); this.assertText('In layout - someProp: something else - In template'); this.runTask(function () { return _this44.context.set('prop', 'something here'); }); this.assertText('In layout - someProp: something here - In template'); }; _class.prototype['@test static arbitrary number of positional parameters'] = function (assert) { var _this45 = this; this.registerComponent('sample-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'names' }), template: (0, _abstractTestCase.strip)(_templateObject7) }); this.render((0, _abstractTestCase.strip)(_templateObject8)); assert.equal(this.$('#args-3').text(), 'Foo4Bar'); assert.equal(this.$('#args-5').text(), 'Foo4Bar5Baz'); this.runTask(function () { return _this45.rerender(); }); assert.equal(this.$('#args-3').text(), 'Foo4Bar'); assert.equal(this.$('#args-5').text(), 'Foo4Bar5Baz'); }; _class.prototype['@test arbitrary positional parameter conflict with hash parameter is reported'] = function () { var _this46 = this; this.registerComponent('sample-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'names' }), template: (0, _abstractTestCase.strip)(_templateObject7) }); expectAssertion(function () { _this46.render('{{sample-component "Foo" 4 "Bar" names=numbers id="args-3"}}', { numbers: [1, 2, 3] }); }, 'You cannot specify positional parameters and the hash argument `names`.'); }; _class.prototype['@test can use hash parameter instead of arbitrary positional param [GH #12444]'] = function () { var _this47 = this; this.registerComponent('sample-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'names' }), template: (0, _abstractTestCase.strip)(_templateObject7) }); this.render('{{sample-component names=things}}', { things: (0, _emberRuntime.A)(['Foo', 4, 'Bar']) }); this.assertText('Foo4Bar'); this.runTask(function () { return _this47.rerender(); }); this.assertText('Foo4Bar'); this.runTask(function () { return _this47.context.get('things').pushObject(5); }); this.assertText('Foo4Bar5'); this.runTask(function () { return _this47.context.get('things').shiftObject(); }); this.assertText('4Bar5'); this.runTask(function () { return _this47.context.get('things').clear(); }); this.assertText(''); this.runTask(function () { return _this47.context.set('things', (0, _emberRuntime.A)(['Foo', 4, 'Bar'])); }); this.assertText('Foo4Bar'); }; _class.prototype['@test can use hash parameter instead of positional param'] = function (assert) { var _this48 = this; this.registerComponent('sample-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['first', 'second'] }), template: '{{first}} - {{second}}' }); // TODO: Fix when id is implemented this.render((0, _abstractTestCase.strip)(_templateObject9)); assert.equal(this.$('#two-positional').text(), 'one - two'); assert.equal(this.$('#one-positional').text(), 'one - two'); assert.equal(this.$('#no-positional').text(), 'one - two'); this.runTask(function () { return _this48.rerender(); }); assert.equal(this.$('#two-positional').text(), 'one - two'); assert.equal(this.$('#one-positional').text(), 'one - two'); assert.equal(this.$('#no-positional').text(), 'one - two'); }; _class.prototype['@test dynamic arbitrary number of positional parameters'] = function () { var _this49 = this; this.registerComponent('sample-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'n' }), template: (0, _abstractTestCase.strip)(_templateObject10) }); this.render('{{sample-component user1 user2}}', { user1: 'Foo', user2: 4 }); this.assertText('Foo4'); this.runTask(function () { return _this49.rerender(); }); this.assertText('Foo4'); this.runTask(function () { return _this49.context.set('user1', 'Bar'); }); this.assertText('Bar4'); this.runTask(function () { return _this49.context.set('user2', '5'); }); this.assertText('Bar5'); this.runTask(function () { _this49.context.set('user1', 'Foo'); _this49.context.set('user2', 4); }); this.assertText('Foo4'); }; _class.prototype['@test with ariaRole specified'] = function () { var _this50 = this; this.registerComponent('aria-test', { template: 'Here!' }); this.render('{{aria-test ariaRole=role}}', { role: 'main' }); this.assertComponentElement(this.firstChild, { attrs: { role: 'main' } }); this.runTask(function () { return _this50.rerender(); }); this.assertComponentElement(this.firstChild, { attrs: { role: 'main' } }); this.runTask(function () { return _this50.context.set('role', 'input'); }); this.assertComponentElement(this.firstChild, { attrs: { role: 'input' } }); this.runTask(function () { return _this50.context.set('role', 'main'); }); this.assertComponentElement(this.firstChild, { attrs: { role: 'main' } }); }; _class.prototype['@test `template` specified in component is overriden by block'] = function () { var _this51 = this; this.registerComponent('with-template', { ComponentClass: _helpers.Component.extend({ template: (0, _helpers.compile)('Should not be used') }), template: '[In layout - {{name}}] {{yield}}' }); this.render((0, _abstractTestCase.strip)(_templateObject11), { name: 'Whoop, whoop!' }); this.assertText('[In layout - with-block] [In block - Whoop, whoop!][In layout - without-block] '); this.runTask(function () { return _this51.rerender(); }); this.assertText('[In layout - with-block] [In block - Whoop, whoop!][In layout - without-block] '); this.runTask(function () { return _this51.context.set('name', 'Ole, ole'); }); this.assertText('[In layout - with-block] [In block - Ole, ole][In layout - without-block] '); this.runTask(function () { return _this51.context.set('name', 'Whoop, whoop!'); }); this.assertText('[In layout - with-block] [In block - Whoop, whoop!][In layout - without-block] '); }; _class.prototype['@test hasBlock is true when block supplied'] = function () { var _this52 = this; this.registerComponent('with-block', { template: (0, _abstractTestCase.strip)(_templateObject12) }); this.render((0, _abstractTestCase.strip)(_templateObject13)); this.assertText('In template'); this.runTask(function () { return _this52.rerender(); }); this.assertText('In template'); }; _class.prototype['@test hasBlock is false when no block supplied'] = function () { var _this53 = this; this.registerComponent('with-block', { template: (0, _abstractTestCase.strip)(_templateObject12) }); this.render('{{with-block}}'); this.assertText('No Block!'); this.runTask(function () { return _this53.rerender(); }); this.assertText('No Block!'); }; _class.prototype['@test hasBlockParams is true when block param supplied'] = function () { var _this54 = this; this.registerComponent('with-block', { template: (0, _abstractTestCase.strip)(_templateObject14) }); this.render((0, _abstractTestCase.strip)(_templateObject15)); this.assertText('In template - In Component'); this.runTask(function () { return _this54.rerender(); }); this.assertText('In template - In Component'); }; _class.prototype['@test hasBlockParams is false when no block param supplied'] = function () { var _this55 = this; this.registerComponent('with-block', { template: (0, _abstractTestCase.strip)(_templateObject16) }); this.render((0, _abstractTestCase.strip)(_templateObject17)); this.assertText('In block No Block Param!'); this.runTask(function () { return _this55.rerender(); }); this.assertText('In block No Block Param!'); }; _class.prototype['@test static named positional parameters'] = function () { var _this56 = this; this.registerComponent('sample-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name', 'age'] }), template: '{{name}}{{age}}' }); this.render('{{sample-component "Quint" 4}}'); this.assertText('Quint4'); this.runTask(function () { return _this56.rerender(); }); this.assertText('Quint4'); }; _class.prototype['@test dynamic named positional parameters'] = function () { var _this57 = this; this.registerComponent('sample-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name', 'age'] }), template: '{{name}}{{age}}' }); this.render('{{sample-component myName myAge}}', { myName: 'Quint', myAge: 4 }); this.assertText('Quint4'); this.runTask(function () { return _this57.rerender(); }); this.assertText('Quint4'); this.runTask(function () { return _this57.context.set('myName', 'Sergio'); }); this.assertText('Sergio4'); this.runTask(function () { return _this57.context.set('myAge', 2); }); this.assertText('Sergio2'); this.runTask(function () { _this57.context.set('myName', 'Quint'); _this57.context.set('myAge', 4); }); this.assertText('Quint4'); }; _class.prototype['@test if a value is passed as a non-positional parameter, it raises an assertion'] = function () { var _this58 = this; this.registerComponent('sample-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name'] }), template: '{{name}}' }); expectAssertion(function () { _this58.render('{{sample-component notMyName name=myName}}', { myName: 'Quint', notMyName: 'Sergio' }); }, 'You cannot specify both a positional param (at position 0) and the hash argument `name`.'); }; _class.prototype['@test yield to inverse'] = function () { var _this59 = this; this.registerComponent('my-if', { template: (0, _abstractTestCase.strip)(_templateObject18) }); this.render((0, _abstractTestCase.strip)(_templateObject19), { activated: true }); this.assertText('Yes:Hello42'); this.runTask(function () { return _this59.rerender(); }); this.assertText('Yes:Hello42'); this.runTask(function () { return _this59.context.set('activated', false); }); this.assertText('No:Goodbye'); this.runTask(function () { return _this59.context.set('activated', true); }); this.assertText('Yes:Hello42'); }; _class.prototype['@test expression hasBlock inverse'] = function () { this.registerComponent('check-inverse', { template: (0, _abstractTestCase.strip)(_templateObject20) }); this.render((0, _abstractTestCase.strip)(_templateObject21)); this.assertComponentElement(this.firstChild, { content: 'No' }); this.assertComponentElement(this.nthChild(1), { content: 'Yes' }); this.assertStableRerender(); }; _class.prototype['@test expression hasBlock default'] = function () { this.registerComponent('check-block', { template: (0, _abstractTestCase.strip)(_templateObject22) }); this.render((0, _abstractTestCase.strip)(_templateObject23)); this.assertComponentElement(this.firstChild, { content: 'No' }); this.assertComponentElement(this.nthChild(1), { content: 'Yes' }); this.assertStableRerender(); }; _class.prototype['@test expression hasBlockParams inverse'] = function () { this.registerComponent('check-inverse', { template: (0, _abstractTestCase.strip)(_templateObject24) }); this.render((0, _abstractTestCase.strip)(_templateObject25)); this.assertComponentElement(this.firstChild, { content: 'No' }); this.assertComponentElement(this.nthChild(1), { content: 'No' }); this.assertStableRerender(); }; _class.prototype['@test expression hasBlockParams default'] = function () { this.registerComponent('check-block', { template: (0, _abstractTestCase.strip)(_templateObject26) }); this.render((0, _abstractTestCase.strip)(_templateObject27)); this.assertComponentElement(this.firstChild, { content: 'No' }); this.assertComponentElement(this.nthChild(1), { content: 'Yes' }); this.assertStableRerender(); }; _class.prototype['@test non-expression hasBlock'] = function () { this.registerComponent('check-block', { template: (0, _abstractTestCase.strip)(_templateObject28) }); this.render((0, _abstractTestCase.strip)(_templateObject23)); this.assertComponentElement(this.firstChild, { content: 'No' }); this.assertComponentElement(this.nthChild(1), { content: 'Yes' }); this.assertStableRerender(); }; _class.prototype['@test expression hasBlockParams'] = function () { this.registerComponent('check-params', { template: (0, _abstractTestCase.strip)(_templateObject26) }); this.render((0, _abstractTestCase.strip)(_templateObject29)); this.assertComponentElement(this.firstChild, { content: 'No' }); this.assertComponentElement(this.nthChild(1), { content: 'Yes' }); this.assertStableRerender(); }; _class.prototype['@test non-expression hasBlockParams'] = function () { this.registerComponent('check-params', { template: (0, _abstractTestCase.strip)(_templateObject30) }); this.render((0, _abstractTestCase.strip)(_templateObject29)); this.assertComponentElement(this.firstChild, { content: 'No' }); this.assertComponentElement(this.nthChild(1), { content: 'Yes' }); this.assertStableRerender(); }; _class.prototype['@test hasBlock expression in an attribute'] = function () { this.registerComponent('check-attr', { template: '' }); this.render((0, _abstractTestCase.strip)(_templateObject31)); (0, _testHelpers.equalsElement)(this.$('button')[0], 'button', { name: 'false' }, ''); (0, _testHelpers.equalsElement)(this.$('button')[1], 'button', { name: 'true' }, ''); this.assertStableRerender(); }; _class.prototype['@test hasBlock inverse expression in an attribute'] = function () { this.registerComponent('check-attr', { template: '' }, ''); this.render((0, _abstractTestCase.strip)(_templateObject32)); (0, _testHelpers.equalsElement)(this.$('button')[0], 'button', { name: 'false' }, ''); (0, _testHelpers.equalsElement)(this.$('button')[1], 'button', { name: 'true' }, ''); this.assertStableRerender(); }; _class.prototype['@test hasBlockParams expression in an attribute'] = function () { this.registerComponent('check-attr', { template: '' }); this.render((0, _abstractTestCase.strip)(_templateObject33)); (0, _testHelpers.equalsElement)(this.$('button')[0], 'button', { name: 'false' }, ''); (0, _testHelpers.equalsElement)(this.$('button')[1], 'button', { name: 'true' }, ''); this.assertStableRerender(); }; _class.prototype['@test hasBlockParams inverse expression in an attribute'] = function () { this.registerComponent('check-attr', { template: '' }, ''); this.render((0, _abstractTestCase.strip)(_templateObject33)); (0, _testHelpers.equalsElement)(this.$('button')[0], 'button', { name: 'false' }, ''); (0, _testHelpers.equalsElement)(this.$('button')[1], 'button', { name: 'false' }, ''); this.assertStableRerender(); }; _class.prototype['@test hasBlock as a param to a helper'] = function () { this.registerComponent('check-helper', { template: '{{if hasBlock "true" "false"}}' }); this.render((0, _abstractTestCase.strip)(_templateObject34)); this.assertComponentElement(this.firstChild, { content: 'false' }); this.assertComponentElement(this.nthChild(1), { content: 'true' }); this.assertStableRerender(); }; _class.prototype['@test hasBlock as an expression param to a helper'] = function () { this.registerComponent('check-helper', { template: '{{if (hasBlock) "true" "false"}}' }); this.render((0, _abstractTestCase.strip)(_templateObject34)); this.assertComponentElement(this.firstChild, { content: 'false' }); this.assertComponentElement(this.nthChild(1), { content: 'true' }); this.assertStableRerender(); }; _class.prototype['@test hasBlock inverse as a param to a helper'] = function () { this.registerComponent('check-helper', { template: '{{if (hasBlock "inverse") "true" "false"}}' }); this.render((0, _abstractTestCase.strip)(_templateObject35)); this.assertComponentElement(this.firstChild, { content: 'false' }); this.assertComponentElement(this.nthChild(1), { content: 'true' }); this.assertStableRerender(); }; _class.prototype['@test hasBlockParams as a param to a helper'] = function () { this.registerComponent('check-helper', { template: '{{if hasBlockParams "true" "false"}}' }); this.render((0, _abstractTestCase.strip)(_templateObject36)); this.assertComponentElement(this.firstChild, { content: 'false' }); this.assertComponentElement(this.nthChild(1), { content: 'true' }); this.assertStableRerender(); }; _class.prototype['@test hasBlockParams as an expression param to a helper'] = function () { this.registerComponent('check-helper', { template: '{{if (hasBlockParams) "true" "false"}}' }); this.render((0, _abstractTestCase.strip)(_templateObject36)); this.assertComponentElement(this.firstChild, { content: 'false' }); this.assertComponentElement(this.nthChild(1), { content: 'true' }); this.assertStableRerender(); }; _class.prototype['@test hasBlockParams inverse as a param to a helper'] = function () { this.registerComponent('check-helper', { template: '{{if (hasBlockParams "inverse") "true" "false"}}' }); this.render((0, _abstractTestCase.strip)(_templateObject36)); this.assertComponentElement(this.firstChild, { content: 'false' }); this.assertComponentElement(this.nthChild(1), { content: 'false' }); this.assertStableRerender(); }; _class.prototype['@test component in template of a yielding component should have the proper parentView'] = function (assert) { var _this60 = this; var outer = void 0, innerTemplate = void 0, innerLayout = void 0; this.registerComponent('x-outer', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); outer = this; } }), template: '{{x-inner-in-layout}}{{yield}}' }); this.registerComponent('x-inner-in-template', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerTemplate = this; } }) }); this.registerComponent('x-inner-in-layout', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerLayout = this; } }) }); this.render('{{#x-outer}}{{x-inner-in-template}}{{/x-outer}}'); assert.equal(innerTemplate.parentView, outer, 'receives the wrapping component as its parentView in template blocks'); assert.equal(innerLayout.parentView, outer, 'receives the wrapping component as its parentView in layout'); assert.equal(outer.parentView, this.context, 'x-outer receives the ambient scope as its parentView'); this.runTask(function () { return _this60.rerender(); }); assert.equal(innerTemplate.parentView, outer, 'receives the wrapping component as its parentView in template blocks'); assert.equal(innerLayout.parentView, outer, 'receives the wrapping component as its parentView in layout'); assert.equal(outer.parentView, this.context, 'x-outer receives the ambient scope as its parentView'); }; _class.prototype['@test newly-added sub-components get correct parentView'] = function (assert) { var _this61 = this; var outer = void 0, inner = void 0; this.registerComponent('x-outer', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); outer = this; } }) }); this.registerComponent('x-inner', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); inner = this; } }) }); this.render((0, _abstractTestCase.strip)(_templateObject37), { showInner: false }); assert.equal(outer.parentView, this.context, 'x-outer receives the ambient scope as its parentView'); this.runTask(function () { return _this61.rerender(); }); assert.equal(outer.parentView, this.context, 'x-outer receives the ambient scope as its parentView (after rerender)'); this.runTask(function () { return _this61.context.set('showInner', true); }); assert.equal(outer.parentView, this.context, 'x-outer receives the ambient scope as its parentView'); assert.equal(inner.parentView, outer, 'receives the wrapping component as its parentView in template blocks'); this.runTask(function () { return _this61.context.set('showInner', false); }); assert.equal(outer.parentView, this.context, 'x-outer receives the ambient scope as its parentView'); }; _class.prototype['@test when a property is changed during children\'s rendering'] = function (assert) { var _this62 = this; var outer = void 0, middle = void 0; this.registerComponent('x-outer', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); outer = this; }, value: 1 }), template: '{{#x-middle}}{{x-inner value=value}}{{/x-middle}}' }); this.registerComponent('x-middle', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); middle = this; }, value: null }), template: '
{{value}}
{{yield}}' }); this.registerComponent('x-inner', { ComponentClass: _helpers.Component.extend({ value: null, pushDataUp: (0, _emberMetal.observer)('value', function () { middle.set('value', this.get('value')); }) }), template: '
{{value}}
' }); this.render('{{x-outer}}'); assert.equal(this.$('#inner-value').text(), '1', 'initial render of inner'); assert.equal(this.$('#middle-value').text(), '', 'initial render of middle (observers do not run during init)'); this.runTask(function () { return _this62.rerender(); }); assert.equal(this.$('#inner-value').text(), '1', 'initial render of inner'); assert.equal(this.$('#middle-value').text(), '', 'initial render of middle (observers do not run during init)'); var expectedBacktrackingMessage = /modified "value" twice on <\(.+> in a single render\. It was rendered in "component:x-middle" and modified in "component:x-inner"/; expectAssertion(function () { _this62.runTask(function () { return outer.set('value', 2); }); }, expectedBacktrackingMessage); }; _class.prototype['@test when a shared dependency is changed during children\'s rendering'] = function (assert) { var _this63 = this; var outer = void 0; this.registerComponent('x-outer', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); outer = this; }, value: 1, wrapper: _emberRuntime.Object.create({ content: null }) }), template: '
{{wrapper.content}}
{{x-inner value=value wrapper=wrapper}}' }); this.registerComponent('x-inner', { ComponentClass: _helpers.Component.extend({ didReceiveAttrs: function () { this.get('wrapper').set('content', this.get('value')); }, value: null }), template: '
{{wrapper.content}}
' }); var expectedBacktrackingMessage = /modified "wrapper\.content" twice on in a single render\. It was rendered in "component:x-outer" and modified in "component:x-inner"/; expectAssertion(function () { _this63.render('{{x-outer}}'); }, expectedBacktrackingMessage); }; _class.prototype['@test non-block with each rendering child components'] = function () { var _this64 = this; this.registerComponent('non-block', { template: (0, _abstractTestCase.strip)(_templateObject38) }); this.registerComponent('child-non-block', { template: 'Child: {{item}}.' }); var items = (0, _emberRuntime.A)(['Tom', 'Dick', 'Harry']); this.render('{{non-block items=items}}', { items: items }); this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.]'); this.runTask(function () { return _this64.rerender(); }); this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.]'); this.runTask(function () { return _this64.context.get('items').pushObject('Sergio'); }); this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.][Child: Sergio.]'); this.runTask(function () { return _this64.context.get('items').shiftObject(); }); this.assertText('In layout. [Child: Dick.][Child: Harry.][Child: Sergio.]'); this.runTask(function () { return _this64.context.set('items', (0, _emberRuntime.A)(['Tom', 'Dick', 'Harry'])); }); this.assertText('In layout. [Child: Tom.][Child: Dick.][Child: Harry.]'); }; _class.prototype['@test specifying classNames results in correct class'] = function (assert) { var _this65 = this; this.registerComponent('some-clicky-thing', { ComponentClass: _helpers.Component.extend({ tagName: 'button', classNames: ['foo', 'bar'] }) }); this.render((0, _abstractTestCase.strip)(_templateObject39)); // TODO: ember-view is no longer viewable in the classNames array. Bug or // feature? var expectedClassNames = ['ember-view', 'foo', 'bar', 'baz']; assert.ok(this.$('button').is('.foo.bar.baz.ember-view'), 'the element has the correct classes: ' + this.$('button').attr('class')); // `ember-view` is no longer in classNames. // assert.deepEqual(clickyThing.get('classNames'), expectedClassNames, 'classNames are properly combined'); this.assertComponentElement(this.firstChild, { tagName: 'button', attrs: { 'class': (0, _testHelpers.classes)(expectedClassNames.join(' ')) } }); this.runTask(function () { return _this65.rerender(); }); assert.ok(this.$('button').is('.foo.bar.baz.ember-view'), 'the element has the correct classes: ' + this.$('button').attr('class') + ' (rerender)'); // `ember-view` is no longer in classNames. // assert.deepEqual(clickyThing.get('classNames'), expectedClassNames, 'classNames are properly combined (rerender)'); this.assertComponentElement(this.firstChild, { tagName: 'button', attrs: { 'class': (0, _testHelpers.classes)(expectedClassNames.join(' ')) } }); }; _class.prototype['@test specifying custom concatenatedProperties avoids clobbering'] = function () { var _this66 = this; this.registerComponent('some-clicky-thing', { ComponentClass: _helpers.Component.extend({ concatenatedProperties: ['blahzz'], blahzz: ['blark', 'pory'] }), template: (0, _abstractTestCase.strip)(_templateObject40) }); this.render((0, _abstractTestCase.strip)(_templateObject41)); this.assertText('blarkporybaz- Click Me'); this.runTask(function () { return _this66.rerender(); }); this.assertText('blarkporybaz- Click Me'); }; _class.prototype['@test a two way binding flows upstream when consumed in the template'] = function () { var _this67 = this; var component = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{bar}}' }); this.render('{{localBar}} - {{foo-bar bar=localBar}}', { localBar: 'initial value' }); this.assertText('initial value - initial value'); this.runTask(function () { return _this67.rerender(); }); this.assertText('initial value - initial value'); this.runTask(function () { component.set('bar', 'updated value'); }); this.assertText('updated value - updated value'); this.runTask(function () { component.set('bar', undefined); }); this.assertText(' - '); this.runTask(function () { _this67.component.set('localBar', 'initial value'); }); this.assertText('initial value - initial value'); }; _class.prototype['@test a two way binding flows upstream through a CP when consumed in the template'] = function () { var _this68 = this; var component = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, bar: (0, _emberMetal.computed)({ get: function () { return this._bar; }, set: function (key, value) { this._bar = value; return this._bar; } }) }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{bar}}' }); this.render('{{localBar}} - {{foo-bar bar=localBar}}', { localBar: 'initial value' }); this.assertText('initial value - initial value'); this.runTask(function () { return _this68.rerender(); }); this.assertText('initial value - initial value'); this.runTask(function () { component.set('bar', 'updated value'); }); this.assertText('updated value - updated value'); this.runTask(function () { _this68.component.set('localBar', 'initial value'); }); this.assertText('initial value - initial value'); }; _class.prototype['@test a two way binding flows upstream through a CP without template consumption'] = function () { var _this69 = this; var component = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, bar: (0, _emberMetal.computed)({ get: function () { return this._bar; }, set: function (key, value) { this._bar = value; return this._bar; } }) }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '' }); this.render('{{localBar}}{{foo-bar bar=localBar}}', { localBar: 'initial value' }); this.assertText('initial value'); this.runTask(function () { return _this69.rerender(); }); this.assertText('initial value'); this.runTask(function () { component.set('bar', 'updated value'); }); this.assertText('updated value'); this.runTask(function () { _this69.component.set('localBar', 'initial value'); }); this.assertText('initial value'); }; _class.prototype['@test services can be injected into components'] = function () { var _this70 = this; var service = void 0; this.registerService('name', _emberRuntime.Service.extend({ init: function () { this._super.apply(this, arguments); service = this; }, last: 'Jackson' })); this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ name: _emberRuntime.inject.service() }), template: '{{name.last}}' }); this.render('{{foo-bar}}'); this.assertText('Jackson'); this.runTask(function () { return _this70.rerender(); }); this.assertText('Jackson'); this.runTask(function () { service.set('last', 'McGuffey'); }); this.assertText('McGuffey'); this.runTask(function () { service.set('last', 'Jackson'); }); this.assertText('Jackson'); }; _class.prototype['@test injecting an unknown service raises an exception'] = function () { var _this71 = this; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ missingService: _emberRuntime.inject.service() }) }); expectAssertion(function () { _this71.render('{{foo-bar}}'); }, 'Attempting to inject an unknown injection: \'service:missingService\''); }; _class.prototype['@test can access `actions` hash via `_actions` [DEPRECATED]'] = function () { var _this72 = this; var component = void 0; function derp() {} this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, actions: { derp: derp } }) }); this.render('{{foo-bar}}'); this.assert.strictEqual(component.actions.derp, derp); expectDeprecation(function () { _this72.assert.strictEqual(component._actions.derp, derp); }, 'Usage of `_actions` is deprecated, use `actions` instead.'); }; _class.prototype['@test throws if `this._super` is not called from `init`'] = function () { var _this73 = this; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ init: function () {} }) }); expectAssertion(function () { _this73.render('{{foo-bar}}'); }, /You must call `this._super\(...arguments\);` when overriding `init` on a framework object. Please update .* to call `this._super\(...arguments\);` from `init`./); }; _class.prototype['@test should toggle visibility with isVisible'] = function (assert) { var _this74 = this; var assertStyle = function (expected) { var matcher = (0, _testHelpers.styles)(expected); var actual = _this74.firstChild.getAttribute('style'); assert.pushResult({ result: matcher.match(actual), message: matcher.message(), actual: actual, expected: expected }); }; this.registerComponent('foo-bar', { template: '

foo

' }); this.render('{{foo-bar id="foo-bar" isVisible=visible}}', { visible: false }); assertStyle('display: none;'); this.assertStableRerender(); this.runTask(function () { (0, _emberMetal.set)(_this74.context, 'visible', true); }); assertStyle(''); this.runTask(function () { (0, _emberMetal.set)(_this74.context, 'visible', false); }); assertStyle('display: none;'); }; _class.prototype['@test isVisible does not overwrite component style'] = function () { var _this75 = this; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ attributeBindings: ['style'], style: (0, _helpers.htmlSafe)('color: blue;') }), template: '

foo

' }); this.render('{{foo-bar id="foo-bar" isVisible=visible}}', { visible: false }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { id: 'foo-bar', style: (0, _testHelpers.styles)('color: blue; display: none;') } }); this.assertStableRerender(); this.runTask(function () { (0, _emberMetal.set)(_this75.context, 'visible', true); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { id: 'foo-bar', style: (0, _testHelpers.styles)('color: blue;') } }); this.runTask(function () { (0, _emberMetal.set)(_this75.context, 'visible', false); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { id: 'foo-bar', style: (0, _testHelpers.styles)('color: blue; display: none;') } }); }; _class.prototype['@test adds isVisible binding when style binding is missing and other bindings exist'] = function (assert) { var _this76 = this; var assertStyle = function (expected) { var matcher = (0, _testHelpers.styles)(expected); var actual = _this76.firstChild.getAttribute('style'); assert.pushResult({ result: matcher.match(actual), message: matcher.message(), actual: actual, expected: expected }); }; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ attributeBindings: ['foo'], foo: 'bar' }), template: '

foo

' }); this.render('{{foo-bar id="foo-bar" foo=foo isVisible=visible}}', { visible: false, foo: 'baz' }); assertStyle('display: none;'); this.assertStableRerender(); this.runTask(function () { (0, _emberMetal.set)(_this76.context, 'visible', true); }); assertStyle(''); this.runTask(function () { (0, _emberMetal.set)(_this76.context, 'visible', false); (0, _emberMetal.set)(_this76.context, 'foo', 'woo'); }); assertStyle('display: none;'); assert.equal(this.firstChild.getAttribute('foo'), 'woo'); }; _class.prototype['@test it can use readDOMAttr to read input value'] = function () { var _this77 = this; var component = void 0; var assertElement = function (expectedValue) { // value is a property, not an attribute _this77.assertHTML(''); _this77.assert.equal(_this77.firstChild.value, expectedValue, 'value property is correct'); _this77.assert.equal((0, _emberMetal.get)(component, 'value'), expectedValue, 'component.get("value") is correct'); }; this.registerComponent('one-way-input', { ComponentClass: _helpers.Component.extend({ tagName: 'input', attributeBindings: ['value'], init: function () { this._super.apply(this, arguments); component = this; }, change: function () { var value = this.readDOMAttr('value'); this.set('value', value); } }) }); this.render('{{one-way-input value=value}}', { value: 'foo' }); assertElement('foo'); this.assertStableRerender(); this.runTask(function () { _this77.firstChild.value = 'bar'; _this77.$('input').trigger('change'); }); assertElement('bar'); this.runTask(function () { _this77.firstChild.value = 'foo'; _this77.$('input').trigger('change'); }); assertElement('foo'); this.runTask(function () { (0, _emberMetal.set)(component, 'value', 'bar'); }); assertElement('bar'); this.runTask(function () { _this77.firstChild.value = 'foo'; _this77.$('input').trigger('change'); }); assertElement('foo'); }; _class.prototype['@test child triggers revalidate during parent destruction (GH#13846)'] = function () { this.registerComponent('x-select', { ComponentClass: _helpers.Component.extend({ tagName: 'select', init: function () { this._super(); this.options = (0, _emberRuntime.A)([]); this.value = null; }, updateValue: function () { var newValue = this.get('options.lastObject.value'); this.set('value', newValue); }, registerOption: function (option) { this.get('options').addObject(option); }, unregisterOption: function (option) { this.get('options').removeObject(option); this.updateValue(); } }), template: '{{yield this}}' }); this.registerComponent('x-option', { ComponentClass: _helpers.Component.extend({ tagName: 'option', attributeBindings: ['selected'], didInsertElement: function () { this._super.apply(this, arguments); this.get('select').registerOption(this); }, selected: (0, _emberMetal.computed)('select.value', function () { return this.get('value') === this.get('select.value'); }), willDestroyElement: function () { this._super.apply(this, arguments); this.get('select').unregisterOption(this); } }) }); this.render((0, _abstractTestCase.strip)(_templateObject42)); this.teardown(); this.assert.ok(true, 'no errors during teardown'); }; _class.prototype['@test setting a property in willDestroyElement does not assert (GH#14273)'] = function (assert) { assert.expect(2); this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); this.showFoo = true; }, willDestroyElement: function () { this.set('showFoo', false); assert.ok(true, 'willDestroyElement was fired'); this._super.apply(this, arguments); } }), template: '{{#if showFoo}}things{{/if}}' }); this.render('{{foo-bar}}'); this.assertText('things'); }; _class.prototype['@test using didInitAttrs as an event is deprecated'] = function (assert) { var _this78 = this; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ foo: (0, _emberMetal.on)('didInitAttrs', function () { assert.ok(true, 'should fire `didInitAttrs` event'); }) }) }); expectDeprecation(function () { _this78.render('{{foo-bar}}'); }, /didInitAttrs called/); }; _class.prototype['@test did{Init,Receive}Attrs fires even if component is not rendered'] = function (assert) { var _this79 = this; expectDeprecation(/didInitAttrs called/); var didInitAttrsCount = 0; var didReceiveAttrsCount = 0; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); this.didInit = true; }, didInitAttrs: function () { assert.ok(this.didInit, 'expected init to have run before didInitAttrs'); didInitAttrsCount++; }, didReceiveAttrs: function () { assert.ok(this.didInit, 'expected init to have run before didReceiveAttrs'); didReceiveAttrsCount++; }, willRender: function () { throw new Error('Unexpected render!'); } }) }); assert.strictEqual(didInitAttrsCount, 0, 'precond: didInitAttrs is not fired'); assert.strictEqual(didReceiveAttrsCount, 0, 'precond: didReceiveAttrs is not fired'); this.runTask(function () { return _this79.component = _this79.owner.lookup('component:foo-bar'); }); assert.strictEqual(didInitAttrsCount, 1, 'precond: didInitAttrs is fired'); assert.strictEqual(didReceiveAttrsCount, 1, 'precond: didReceiveAttrs is fired'); }; _class.prototype['@test did{Init,Receive}Attrs fires after .init() but before observers become active'] = function (assert) { var _this80 = this; expectDeprecation(/didInitAttrs called/); var fooCopyDidChangeCount = 0; var barCopyDidChangeCount = 0; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); this.didInit = true; }, didInitAttrs: function (_ref2) { var attrs = _ref2.attrs; assert.ok(this.didInit, 'expected init to have run before didInitAttrs'); this.set('fooCopy', attrs.foo.value + 1); }, didReceiveAttrs: function (_ref3) { var newAttrs = _ref3.newAttrs; assert.ok(this.didInit, 'expected init to have run before didReceiveAttrs'); this.set('barCopy', newAttrs.bar.value + 1); }, fooCopyDidChange: (0, _emberMetal.observer)('fooCopy', function () { fooCopyDidChangeCount++; }), barCopyDidChange: (0, _emberMetal.observer)('barCopy', function () { barCopyDidChangeCount++; }) }), template: '{{foo}}-{{fooCopy}}-{{bar}}-{{barCopy}}' }); this.render('{{foo-bar foo=foo bar=bar}}', { foo: 1, bar: 3 }); this.assertText('1-2-3-4'); assert.strictEqual(fooCopyDidChangeCount, 0, 'expected NO observer firing for: fooCopy'); assert.strictEqual(barCopyDidChangeCount, 0, 'expected NO observer firing for: barCopy'); this.runTask(function () { return (0, _emberMetal.set)(_this80.context, 'foo', 5); }); this.assertText('5-2-3-4'); assert.strictEqual(fooCopyDidChangeCount, 0, 'expected observer firing for: fooCopy'); assert.strictEqual(barCopyDidChangeCount, 0, 'expected NO observer firing for: barCopy'); this.runTask(function () { return (0, _emberMetal.set)(_this80.context, 'bar', 7); }); this.assertText('5-2-7-8'); assert.strictEqual(fooCopyDidChangeCount, 0, 'expected observer firing for: fooCopy'); assert.strictEqual(barCopyDidChangeCount, 1, 'expected observer firing for: barCopy'); }; _class.prototype['@test overriding didReceiveAttrs does not trigger deprecation'] = function (assert) { this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ didReceiveAttrs: function () { assert.equal(1, this.get('foo'), 'expected attrs to have correct value'); } }), template: '{{foo}}-{{fooCopy}}-{{bar}}-{{barCopy}}' }); this.render('{{foo-bar foo=foo bar=bar}}', { foo: 1, bar: 3 }); }; _class.prototype['@test can access didReceiveAttrs arguments [DEPRECATED]'] = function (assert) { expectDeprecation(/didReceiveAttrs.*stop taking arguments/); this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ didReceiveAttrs: function (_ref4) { var attrs = _ref4.attrs; assert.equal(1, attrs.foo.value, 'expected attrs to have correct value'); } }), template: '{{foo}}-{{fooCopy}}-{{bar}}-{{barCopy}}' }); this.render('{{foo-bar foo=foo bar=bar}}', { foo: 1, bar: 3 }); }; _class.prototype['@test can access didUpdateAttrs arguments [DEPRECATED]'] = function (assert) { var _this81 = this; expectDeprecation(/didUpdateAttrs.*stop taking arguments/); this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ didUpdateAttrs: function (_ref5) { var newAttrs = _ref5.newAttrs; assert.equal(5, newAttrs.foo.value, "expected newAttrs to have new value"); } }), template: '{{foo}}-{{fooCopy}}-{{bar}}-{{barCopy}}' }); this.render('{{foo-bar foo=foo bar=bar}}', { foo: 1, bar: 3 }); this.runTask(function () { return (0, _emberMetal.set)(_this81.context, 'foo', 5); }); }; _class.prototype['@test overriding didUpdateAttrs does not trigger deprecation'] = function (assert) { var _this82 = this; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ didUpdateAttrs: function () { assert.equal(5, this.get('foo'), "expected newAttrs to have new value"); } }), template: '{{foo}}-{{fooCopy}}-{{bar}}-{{barCopy}}' }); this.render('{{foo-bar foo=foo bar=bar}}', { foo: 1, bar: 3 }); this.runTask(function () { return (0, _emberMetal.set)(_this82.context, 'foo', 5); }); }; _class.prototype['@test returning `true` from an action does not bubble if `target` is not specified (GH#14275)'] = function (assert) { var _this83 = this; this.registerComponent('display-toggle', { ComponentClass: _helpers.Component.extend({ actions: { show: function () { assert.ok(true, 'display-toggle show action was called'); return true; } } }), template: '' }); this.render('{{display-toggle}}', { send: function () { assert.notOk(true, 'send should not be called when action is not "subscribed" to'); } }); this.assertText('Show'); this.runTask(function () { return _this83.$('button').click(); }); }; _class.prototype['@test returning `true` from an action bubbles to the `target` if specified'] = function (assert) { var _this84 = this; assert.expect(4); this.registerComponent('display-toggle', { ComponentClass: _helpers.Component.extend({ actions: { show: function () { assert.ok(true, 'display-toggle show action was called'); return true; } } }), template: '' }); this.render('{{display-toggle target=this}}', { send: function (actionName) { assert.ok(true, 'send should be called when action is "subscribed" to'); assert.equal(actionName, 'show'); } }); this.assertText('Show'); this.runTask(function () { return _this84.$('button').click(); }); }; _class.prototype['@test component yielding in an {{#each}} has correct block values after rerendering (GH#14284)'] = function () { var _this85 = this; this.registerComponent('list-items', { template: '{{#each items as |item|}}{{yield item}}{{/each}}' }); this.render((0, _abstractTestCase.strip)(_templateObject43), { editMode: false, items: ['foo', 'bar', 'qux', 'baz'] }); this.assertText('|foo||bar||qux||baz|'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this85.context, 'editMode', true); }); this.assertText('|foo|Remove foo|bar|Remove bar|qux|Remove qux|baz|Remove baz'); this.runTask(function () { return (0, _emberMetal.set)(_this85.context, 'editMode', false); }); this.assertText('|foo||bar||qux||baz|'); }; _class.prototype['@test unimplimented positionalParams do not cause an error GH#14416'] = function () { this.registerComponent('foo-bar', { template: 'hello' }); this.render('{{foo-bar wat}}'); this.assertText('hello'); }; _class.prototype['@test using attrs for positional params'] = function () { var MyComponent = _helpers.Component.extend(); this.registerComponent('foo-bar', { ComponentClass: MyComponent.reopenClass({ positionalParams: ['myVar'] }), template: 'MyVar1: {{attrs.myVar}} {{myVar}} MyVar2: {{myVar2}} {{attrs.myVar2}}' }); this.render('{{foo-bar 1 myVar2=2}}'); this.assertText('MyVar1: 1 1 MyVar2: 2 2'); }; _class.prototype['@test can use `{{this}}` to emit the component\'s toString value [GH#14581]'] = function () { this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ toString: function () { return 'special sauce goes here!'; } }), template: '{{this}}' }); this.render('{{foo-bar}}'); this.assertText('special sauce goes here!'); }; _class.prototype['@test can use `{{this` to access paths on current context [GH#14581]'] = function () { var instance = void 0; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); instance = this; }, foo: { bar: { baz: 'huzzah!' } } }), template: '{{this.foo.bar.baz}}' }); this.render('{{foo-bar}}'); this.assertText('huzzah!'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(instance, 'foo.bar.baz', 'yippie!'); }); this.assertText('yippie!'); this.runTask(function () { return (0, _emberMetal.set)(instance, 'foo.bar.baz', 'huzzah!'); }); this.assertText('huzzah!'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/destroy-test', ['ember-babel', 'ember-metal', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/test-case'], function (_emberBabel, _emberMetal, _helpers, _testCase) { 'use strict'; (0, _testCase.moduleFor)('Component destroy', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test it correctly releases the destroyed components'] = function (assert) { var _this2 = this; var FooBarComponent = _helpers.Component.extend({}); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{#if switch}}{{#foo-bar}}{{foo-bar}}{{/foo-bar}}{{/if}}', { switch: true }); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'switch', false); }); this.assertText(''); assert.equal(this.env.destroyedComponents.length, 0, 'environment.destroyedComponents should be empty'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/dynamic-components-test', ['ember-babel', 'ember-metal', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case'], function (_emberBabel, _emberMetal, _helpers, _abstractTestCase, _testCase) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if cond1}}\n {{#component "foo-bar" id=1}}\n {{#if cond2}}\n {{#component "foo-bar" id=2}}{{/component}}\n {{#if cond3}}\n {{#component "foo-bar" id=3}}\n {{#if cond4}}\n {{#component "foo-bar" id=4}}\n {{#if cond5}}\n {{#component "foo-bar" id=5}}{{/component}}\n {{#component "foo-bar" id=6}}{{/component}}\n {{#component "foo-bar" id=7}}{{/component}}\n {{/if}}\n {{#component "foo-bar" id=8}}{{/component}}\n {{/component}}\n {{/if}}\n {{/component}}\n {{/if}}\n {{/if}}\n {{/component}}\n {{/if}}'], ['\n {{#if cond1}}\n {{#component "foo-bar" id=1}}\n {{#if cond2}}\n {{#component "foo-bar" id=2}}{{/component}}\n {{#if cond3}}\n {{#component "foo-bar" id=3}}\n {{#if cond4}}\n {{#component "foo-bar" id=4}}\n {{#if cond5}}\n {{#component "foo-bar" id=5}}{{/component}}\n {{#component "foo-bar" id=6}}{{/component}}\n {{#component "foo-bar" id=7}}{{/component}}\n {{/if}}\n {{#component "foo-bar" id=8}}{{/component}}\n {{/component}}\n {{/if}}\n {{/component}}\n {{/if}}\n {{/if}}\n {{/component}}\n {{/if}}']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each names as |name|}}\n {{name}}\n {{/each}}'], ['\n {{#each names as |name|}}\n {{name}}\n {{/each}}']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each n as |name|}}\n {{name}}\n {{/each}}'], ['\n {{#each n as |name|}}\n {{name}}\n {{/each}}']); (0, _testCase.moduleFor)('Components test: dynamic components', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test it can render a basic component with a static component name argument'] = function () { var _this2 = this; this.registerComponent('foo-bar', { template: 'hello {{name}}' }); this.render('{{component "foo-bar" name=name}}', { name: 'Sarah' }); this.assertComponentElement(this.firstChild, { content: 'hello Sarah' }); this.runTask(function () { return _this2.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello Sarah' }); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'name', 'Gavin'); }); this.assertComponentElement(this.firstChild, { content: 'hello Gavin' }); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'name', 'Sarah'); }); this.assertComponentElement(this.firstChild, { content: 'hello Sarah' }); }; _class.prototype['@test it can render a basic component with a dynamic component name argument'] = function () { var _this3 = this; this.registerComponent('foo-bar', { template: 'hello {{name}} from foo-bar' }); this.registerComponent('foo-bar-baz', { template: 'hello {{name}} from foo-bar-baz' }); this.render('{{component componentName name=name}}', { componentName: 'foo-bar', name: 'Alex' }); this.assertComponentElement(this.firstChild, { content: 'hello Alex from foo-bar' }); this.runTask(function () { return _this3.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello Alex from foo-bar' }); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'name', 'Ben'); }); this.assertComponentElement(this.firstChild, { content: 'hello Ben from foo-bar' }); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'componentName', 'foo-bar-baz'); }); this.assertComponentElement(this.firstChild, { content: 'hello Ben from foo-bar-baz' }); this.runTask(function () { (0, _emberMetal.set)(_this3.context, 'componentName', 'foo-bar'); (0, _emberMetal.set)(_this3.context, 'name', 'Alex'); }); this.assertComponentElement(this.firstChild, { content: 'hello Alex from foo-bar' }); }; _class.prototype['@test it has an element'] = function () { var _this4 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); instance = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{component "foo-bar"}}'); var element1 = instance.element; this.assertComponentElement(element1, { content: 'hello' }); this.runTask(function () { return _this4.rerender(); }); var element2 = instance.element; this.assertComponentElement(element2, { content: 'hello' }); this.assertSameNode(element2, element1); }; _class.prototype['@test it has a jQuery proxy to the element'] = function () { var _this5 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); instance = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{component "foo-bar"}}'); var element1 = instance.$()[0]; this.assertComponentElement(element1, { content: 'hello' }); this.runTask(function () { return _this5.rerender(); }); var element2 = instance.$()[0]; this.assertComponentElement(element2, { content: 'hello' }); this.assertSameNode(element2, element1); }; _class.prototype['@test it scopes the jQuery proxy to the component element'] = function (assert) { var _this6 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); instance = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'inner' }); this.render('outer{{component "foo-bar"}}'); var $span = instance.$('span'); assert.equal($span.length, 1); assert.equal($span.attr('class'), 'inner'); this.runTask(function () { return _this6.rerender(); }); $span = instance.$('span'); assert.equal($span.length, 1); assert.equal($span.attr('class'), 'inner'); }; _class.prototype['@test it has the right parentView and childViews'] = function (assert) { var _this7 = this; var fooBarInstance = void 0, fooBarBazInstance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); fooBarInstance = this; } }); var FooBarBazComponent = _helpers.Component.extend({ init: function () { this._super(); fooBarBazInstance = this; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'foo-bar {{foo-bar-baz}}' }); this.registerComponent('foo-bar-baz', { ComponentClass: FooBarBazComponent, template: 'foo-bar-baz' }); this.render('{{component "foo-bar"}}'); this.assertText('foo-bar foo-bar-baz'); assert.equal(fooBarInstance.parentView, this.component); assert.equal(fooBarBazInstance.parentView, fooBarInstance); assert.deepEqual(this.component.childViews, [fooBarInstance]); assert.deepEqual(fooBarInstance.childViews, [fooBarBazInstance]); this.runTask(function () { return _this7.rerender(); }); this.assertText('foo-bar foo-bar-baz'); assert.equal(fooBarInstance.parentView, this.component); assert.equal(fooBarBazInstance.parentView, fooBarInstance); assert.deepEqual(this.component.childViews, [fooBarInstance]); assert.deepEqual(fooBarInstance.childViews, [fooBarBazInstance]); }; _class.prototype['@test it can render a basic component with a block'] = function () { var _this8 = this; this.registerComponent('foo-bar', { template: '{{yield}}' }); this.render('{{#component "foo-bar"}}hello{{/component}}'); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return _this8.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello' }); }; _class.prototype['@test it renders the layout with the component instance as the context'] = function () { var _this9 = this; var instance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); instance = this; this.set('message', 'hello'); } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{message}}' }); this.render('{{component "foo-bar"}}'); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return _this9.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(instance, 'message', 'goodbye'); }); this.assertComponentElement(this.firstChild, { content: 'goodbye' }); this.runTask(function () { return (0, _emberMetal.set)(instance, 'message', 'hello'); }); this.assertComponentElement(this.firstChild, { content: 'hello' }); }; _class.prototype['@test it preserves the outer context when yielding'] = function () { var _this10 = this; this.registerComponent('foo-bar', { template: '{{yield}}' }); this.render('{{#component "foo-bar"}}{{message}}{{/component}}', { message: 'hello' }); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return _this10.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'message', 'goodbye'); }); this.assertComponentElement(this.firstChild, { content: 'goodbye' }); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'message', 'hello'); }); this.assertComponentElement(this.firstChild, { content: 'hello' }); }; _class.prototype['@test the component and its child components are destroyed'] = function (assert) { var _this11 = this; var destroyed = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0 }; this.registerComponent('foo-bar', { template: '{{id}} {{yield}}', ComponentClass: _helpers.Component.extend({ willDestroy: function () { this._super(); destroyed[this.get('id')]++; } }) }); this.render((0, _abstractTestCase.strip)(_templateObject), { cond1: true, cond2: true, cond3: true, cond4: true, cond5: true }); this.assertText('1 2 3 4 5 6 7 8 '); this.runTask(function () { return _this11.rerender(); }); assert.deepEqual(destroyed, { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0 }); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'cond5', false); }); this.assertText('1 2 3 4 8 '); assert.deepEqual(destroyed, { 1: 0, 2: 0, 3: 0, 4: 0, 5: 1, 6: 1, 7: 1, 8: 0 }); this.runTask(function () { (0, _emberMetal.set)(_this11.context, 'cond3', false); (0, _emberMetal.set)(_this11.context, 'cond5', true); (0, _emberMetal.set)(_this11.context, 'cond4', false); }); assert.deepEqual(destroyed, { 1: 0, 2: 0, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1 }); this.runTask(function () { (0, _emberMetal.set)(_this11.context, 'cond2', false); (0, _emberMetal.set)(_this11.context, 'cond1', false); }); assert.deepEqual(destroyed, { 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1 }); }; _class.prototype['@test component helper destroys underlying component when it is swapped out'] = function (assert) { var _this12 = this; var destroyed = { 'foo-bar': 0, 'foo-bar-baz': 0 }; var testContext = this; this.registerComponent('foo-bar', { template: 'hello from foo-bar', ComponentClass: _helpers.Component.extend({ willDestroyElement: function () { assert.equal(testContext.$('#' + this.elementId).length, 1, 'element is still attached to the document'); }, willDestroy: function () { this._super(); destroyed['foo-bar']++; } }) }); this.registerComponent('foo-bar-baz', { template: 'hello from foo-bar-baz', ComponentClass: _helpers.Component.extend({ willDestroy: function () { this._super(); destroyed['foo-bar-baz']++; } }) }); this.render('{{component componentName name=name}}', { componentName: 'foo-bar' }); assert.deepEqual(destroyed, { 'foo-bar': 0, 'foo-bar-baz': 0 }); this.runTask(function () { return _this12.rerender(); }); assert.deepEqual(destroyed, { 'foo-bar': 0, 'foo-bar-baz': 0 }); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'componentName', 'foo-bar-baz'); }); assert.deepEqual(destroyed, { 'foo-bar': 1, 'foo-bar-baz': 0 }); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'componentName', 'foo-bar'); }); assert.deepEqual(destroyed, { 'foo-bar': 1, 'foo-bar-baz': 1 }); }; _class.prototype['@test component helper with bound properties are updating correctly in init of component'] = function () { var _this13 = this; this.registerComponent('foo-bar', { template: 'foo-bar {{location}} {{locationCopy}} {{yield}}', ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); this.set('locationCopy', this.get('location')); } }) }); this.registerComponent('foo-bar-baz', { template: 'foo-bar-baz {{location}} {{locationCopy}} {{yield}}', ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); this.set('locationCopy', this.get('location')); } }) }); this.registerComponent('outer-component', { template: '{{#component componentName location=location}}arepas!{{/component}}', ComponentClass: _helpers.Component.extend({ componentName: (0, _emberMetal.computed)('location', function () { if (this.get('location') === 'Caracas') { return 'foo-bar'; } else { return 'foo-bar-baz'; } }) }) }); this.render('{{outer-component location=location}}', { location: 'Caracas' }); this.assertText('foo-bar Caracas Caracas arepas!'); this.runTask(function () { return _this13.rerender(); }); this.assertText('foo-bar Caracas Caracas arepas!'); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'location', 'Loisaida'); }); this.assertText('foo-bar-baz Loisaida Loisaida arepas!'); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'location', 'Caracas'); }); this.assertText('foo-bar Caracas Caracas arepas!'); }; _class.prototype['@test component helper with actions'] = function (assert) { var _this15 = this; this.registerComponent('inner-component', { template: 'inner-component {{yield}}', ComponentClass: _helpers.Component.extend({ classNames: 'inner-component', didInsertElement: function () { var _this14 = this; // trigger action on click in absence of app's EventDispatcher this.$().on('click', function () { _this14.sendAction('somethingClicked'); }); }, willDestroyElement: function () { this.$().off('click'); } }) }); var actionTriggered = 0; this.registerComponent('outer-component', { template: '{{#component componentName somethingClicked="mappedAction"}}arepas!{{/component}}', ComponentClass: _helpers.Component.extend({ classNames: 'outer-component', componentName: 'inner-component', actions: { mappedAction: function () { actionTriggered++; } } }) }); this.render('{{outer-component}}'); assert.equal(actionTriggered, 0, 'action was not triggered'); this.runTask(function () { _this15.$('.inner-component').trigger('click'); }); assert.equal(actionTriggered, 1, 'action was triggered'); }; _class.prototype['@test nested component helpers'] = function () { var _this16 = this; this.registerComponent('foo-bar', { template: 'yippie! {{attrs.location}} {{yield}}' }); this.registerComponent('baz-qux', { template: 'yummy {{attrs.location}} {{yield}}' }); this.registerComponent('corge-grault', { template: 'delicious {{attrs.location}} {{yield}}' }); this.render('{{#component componentName1 location=location}}{{#component componentName2 location=location}}arepas!{{/component}}{{/component}}', { componentName1: 'foo-bar', componentName2: 'baz-qux', location: 'Caracas' }); this.assertText('yippie! Caracas yummy Caracas arepas!'); this.runTask(function () { return _this16.rerender(); }); this.assertText('yippie! Caracas yummy Caracas arepas!'); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'location', 'Loisaida'); }); this.assertText('yippie! Loisaida yummy Loisaida arepas!'); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'componentName1', 'corge-grault'); }); this.assertText('delicious Loisaida yummy Loisaida arepas!'); this.runTask(function () { (0, _emberMetal.set)(_this16.context, 'componentName1', 'foo-bar'); (0, _emberMetal.set)(_this16.context, 'location', 'Caracas'); }); this.assertText('yippie! Caracas yummy Caracas arepas!'); }; _class.prototype['@test component with dynamic name argument resolving to non-existent component'] = function () { var _this17 = this; expectAssertion(function () { _this17.render('{{component componentName}}', { componentName: 'does-not-exist' }); }, /Could not find component named "does-not-exist"/); }; _class.prototype['@test component with static name argument for non-existent component'] = function () { var _this18 = this; expectAssertion(function () { _this18.render('{{component "does-not-exist"}}'); }, /Could not find component named "does-not-exist"/); }; _class.prototype['@test component with dynamic component name resolving to a component, then non-existent component'] = function () { var _this19 = this; this.registerComponent('foo-bar', { template: 'hello {{name}}' }); this.render('{{component componentName name=name}}', { componentName: 'foo-bar', name: 'Alex' }); this.assertText('hello Alex'); this.runTask(function () { return _this19.rerender(); }); this.assertText('hello Alex'); this.runTask(function () { return (0, _emberMetal.set)(_this19.context, 'componentName', undefined); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this19.context, 'componentName', 'foo-bar'); }); this.assertText('hello Alex'); }; _class.prototype['@test component helper properly invalidates hash params inside an {{each}} invocation #11044'] = function () { var _this20 = this; this.registerComponent('foo-bar', { template: '[{{internalName}} - {{name}}]', ComponentClass: _helpers.Component.extend({ willRender: function () { // store internally available name to ensure that the name available in `this.attrs.name` // matches the template lookup name (0, _emberMetal.set)(this, 'internalName', this.get('name')); } }) }); this.render('{{#each items as |item|}}{{component "foo-bar" name=item.name}}{{/each}}', { items: [{ name: 'Robert' }, { name: 'Jacquie' }] }); this.assertText('[Robert - Robert][Jacquie - Jacquie]'); this.runTask(function () { return _this20.rerender(); }); this.assertText('[Robert - Robert][Jacquie - Jacquie]'); this.runTask(function () { return (0, _emberMetal.set)(_this20.context, 'items', [{ name: 'Max' }, { name: 'James' }]); }); this.assertText('[Max - Max][James - James]'); this.runTask(function () { return (0, _emberMetal.set)(_this20.context, 'items', [{ name: 'Robert' }, { name: 'Jacquie' }]); }); this.assertText('[Robert - Robert][Jacquie - Jacquie]'); }; _class.prototype['@test dashless components should not be found'] = function () { var _this21 = this; this.registerComponent('dashless2', { template: 'Do not render me!' }); expectAssertion(function () { _this21.render('{{component "dashless"}}'); }, /You cannot use 'dashless' as a component name. Component names must contain a hyphen./); }; _class.prototype['@test positional parameters does not clash when rendering different components'] = function () { var _this22 = this; this.registerComponent('foo-bar', { template: 'hello {{name}} ({{age}}) from foo-bar', ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name', 'age'] }) }); this.registerComponent('foo-bar-baz', { template: 'hello {{name}} ({{age}}) from foo-bar-baz', ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['name', 'age'] }) }); this.render('{{component componentName name age}}', { componentName: 'foo-bar', name: 'Alex', age: 29 }); this.assertComponentElement(this.firstChild, { content: 'hello Alex (29) from foo-bar' }); this.runTask(function () { return _this22.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'hello Alex (29) from foo-bar' }); this.runTask(function () { return (0, _emberMetal.set)(_this22.context, 'name', 'Ben'); }); this.assertComponentElement(this.firstChild, { content: 'hello Ben (29) from foo-bar' }); this.runTask(function () { return (0, _emberMetal.set)(_this22.context, 'age', 22); }); this.assertComponentElement(this.firstChild, { content: 'hello Ben (22) from foo-bar' }); this.runTask(function () { return (0, _emberMetal.set)(_this22.context, 'componentName', 'foo-bar-baz'); }); this.assertComponentElement(this.firstChild, { content: 'hello Ben (22) from foo-bar-baz' }); this.runTask(function () { (0, _emberMetal.set)(_this22.context, 'componentName', 'foo-bar'); (0, _emberMetal.set)(_this22.context, 'name', 'Alex'); (0, _emberMetal.set)(_this22.context, 'age', 29); }); this.assertComponentElement(this.firstChild, { content: 'hello Alex (29) from foo-bar' }); }; _class.prototype['@test positional parameters does not pollute the attributes when changing components'] = function () { var _this23 = this; this.registerComponent('normal-message', { template: 'Normal: {{something}}!', ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: ['something'] }) }); this.registerComponent('alternative-message', { template: 'Alternative: {{something}} {{somethingElse}}!', ComponentClass: _helpers.Component.extend({ something: 'Another' }).reopenClass({ positionalParams: ['somethingElse'] }) }); this.render('{{component componentName message}}', { componentName: 'normal-message', message: 'Hello' }); this.assertComponentElement(this.firstChild, { content: 'Normal: Hello!' }); this.runTask(function () { return _this23.rerender(); }); this.assertComponentElement(this.firstChild, { content: 'Normal: Hello!' }); this.runTask(function () { return (0, _emberMetal.set)(_this23.context, 'componentName', 'alternative-message'); }); this.assertComponentElement(this.firstChild, { content: 'Alternative: Another Hello!' }); this.runTask(function () { return (0, _emberMetal.set)(_this23.context, 'message', 'Hi'); }); this.assertComponentElement(this.firstChild, { content: 'Alternative: Another Hi!' }); this.runTask(function () { (0, _emberMetal.set)(_this23.context, 'componentName', 'normal-message'); (0, _emberMetal.set)(_this23.context, 'message', 'Hello'); }); this.assertComponentElement(this.firstChild, { content: 'Normal: Hello!' }); }; _class.prototype['@test static arbitrary number of positional parameters'] = function () { var _this24 = this; this.registerComponent('sample-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'names' }), template: (0, _abstractTestCase.strip)(_templateObject2) }); this.render('{{component "sample-component" "Foo" 4 "Bar" 5 "Baz" elementId="helper"}}'); this.assertText('Foo4Bar5Baz'); this.runTask(function () { return _this24.rerender(); }); this.assertText('Foo4Bar5Baz'); }; _class.prototype['@test dynamic arbitrary number of positional parameters'] = function () { var _this25 = this; this.registerComponent('sample-component', { ComponentClass: _helpers.Component.extend().reopenClass({ positionalParams: 'n' }), template: (0, _abstractTestCase.strip)(_templateObject3) }); this.render('{{component "sample-component" user1 user2}}', { user1: 'Foo', user2: 4 }); this.assertText('Foo4'); this.runTask(function () { return _this25.rerender(); }); this.assertText('Foo4'); this.runTask(function () { return _this25.context.set('user1', 'Bar'); }); this.assertText('Bar4'); this.runTask(function () { return _this25.context.set('user2', '5'); }); this.assertText('Bar5'); this.runTask(function () { _this25.context.set('user1', 'Foo'); _this25.context.set('user2', 4); }); this.assertText('Foo4'); }; _class.prototype['@test component helper emits useful backtracking re-render assertion message'] = function () { var _this26 = this; this.registerComponent('outer-component', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); this.set('person', { name: 'Alex' }); } }), template: 'Hi {{person.name}}! {{component "error-component" person=person}}' }); this.registerComponent('error-component', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); this.set('person.name', { name: 'Ben' }); } }), template: '{{person.name}}' }); var expectedBacktrackingMessage = /modified "person\.name" twice on \[object Object\] in a single render\. It was rendered in "component:outer-component" and modified in "component:error-component"/; expectAssertion(function () { _this26.render('{{component componentName}}', { componentName: 'outer-component' }); }, expectedBacktrackingMessage); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/fragment-components-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal'], function (_emberBabel, _testCase, _abstractTestCase, _helpers, _emberMetal) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['
Hey
bar'], ['
Hey
bar']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['bar'], ['bar']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['bizz'], ['bizz']); (0, _testCase.moduleFor)('Components test: fragment components', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype.getCustomDispatcherEvents = function () { return { hitDem: 'folks' }; }; _class.prototype['@test fragments do not render an outer tag'] = function () { var instance = void 0; var FooBarComponent = _helpers.Component.extend({ tagName: '', init: function () { this._super(); instance = this; this.foo = true; this.bar = 'bar'; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{#if foo}}
Hey
{{/if}}{{yield bar}}' }); this.render('{{#foo-bar as |bar|}}{{bar}}{{/foo-bar}}'); this.assertHTML((0, _abstractTestCase.strip)(_templateObject)); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(instance, 'foo', false); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject2)); this.runTask(function () { return (0, _emberMetal.set)(instance, 'bar', 'bizz'); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject3)); this.runTask(function () { (0, _emberMetal.set)(instance, 'bar', 'bar'); (0, _emberMetal.set)(instance, 'foo', true); }); }; _class.prototype['@test throws an error if an event function is defined in a tagless component'] = function () { var _this2 = this; var FooBarComponent = _helpers.Component.extend({ tagName: '', click: function () {} }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hit dem folks' }); expectAssertion(function () { _this2.render('{{#foo-bar}}{{/foo-bar}}'); }, /You can not define a function that handles DOM events in the .* tagless component since it doesn't have any DOM element./); }; _class.prototype['@test throws an error if a custom defined event function is defined in a tagless component'] = function () { var _this3 = this; var FooBarComponent = _helpers.Component.extend({ tagName: '', folks: function () {} }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hit dem folks' }); expectAssertion(function () { _this3.render('{{#foo-bar}}{{/foo-bar}}'); }, /You can not define a function that handles DOM events in the .* tagless component since it doesn't have any DOM element./); }; _class.prototype['@test throws an error if `tagName` is an empty string and `classNameBindings` are specified'] = function () { var _this4 = this; var FooBarComponent = _helpers.Component.extend({ tagName: '', foo: true, classNameBindings: ['foo:is-foo:is-bar'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hit dem folks' }); expectAssertion(function () { _this4.render('{{#foo-bar}}{{/foo-bar}}'); }, /You cannot use `classNameBindings` on a tag-less component/); }; _class.prototype['@test throws an error if `tagName` is an empty string and `attributeBindings` are specified'] = function () { var _this5 = this; var FooBarComponent = _helpers.Component.extend({ tagName: '', attributeBindings: ['href'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hit dem folks' }); expectAssertion(function () { _this5.render('{{#foo-bar}}{{/foo-bar}}'); }, /You cannot use `attributeBindings` on a tag-less component/); }; _class.prototype['@test throws an error if `tagName` is an empty string and `elementId` is specified via JS'] = function () { var _this6 = this; var FooBarComponent = _helpers.Component.extend({ tagName: '', elementId: 'turntUp' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hit dem folks' }); expectAssertion(function () { _this6.render('{{#foo-bar}}{{/foo-bar}}'); }, /You cannot use `elementId` on a tag-less component/); }; _class.prototype['@test throws an error if `tagName` is an empty string and `elementId` is specified via template'] = function () { var _this7 = this; var FooBarComponent = _helpers.Component.extend({ tagName: '' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hit dem folks' }); expectAssertion(function () { _this7.render('{{#foo-bar elementId=\'turntUp\'}}{{/foo-bar}}'); }, /You cannot use `elementId` on a tag-less component/); }; _class.prototype['@test does not throw an error if `tagName` is an empty string and `id` is specified via JS'] = function () { var FooBarComponent = _helpers.Component.extend({ tagName: '', id: 'baz' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{id}}' }); this.render('{{#foo-bar}}{{/foo-bar}}'); this.assertText('baz'); }; _class.prototype['@test does not throw an error if `tagName` is an empty string and `id` is specified via template'] = function () { var FooBarComponent = _helpers.Component.extend({ tagName: '' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{id}}' }); this.render('{{#foo-bar id=\'baz\'}}{{/foo-bar}}'); this.assertText('baz'); }; _class.prototype['@test does not throw an error if `tagName` is an empty string and `id` is bound property specified via template'] = function () { var _this8 = this; var FooBarComponent = _helpers.Component.extend({ tagName: '' }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{id}}' }); this.render('{{#foo-bar id=fooBarId}}{{/foo-bar}}', { fooBarId: 'baz' }); this.assertText('baz'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'fooBarId', 'qux'); }); this.assertText('qux'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'fooBarId', 'baz'); }); this.assertText('baz'); }; _class.prototype['@test does not throw an error if `tagName` is an empty string and `id` is specified via template and passed to child component'] = function () { var FooBarComponent = _helpers.Component.extend({ tagName: '' }); var BazChildComponent = _helpers.Component.extend(); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{#baz-child id=id}}{{/baz-child}}' }); this.registerComponent('baz-child', { ComponentClass: BazChildComponent, template: '{{id}}' }); this.render('{{#foo-bar id=\'baz\'}}{{/foo-bar}}'); this.assertText('baz'); }; _class.prototype['@test throws an error if when $() is accessed on component where `tagName` is an empty string'] = function () { var _this9 = this; var FooBarComponent = _helpers.Component.extend({ tagName: '', init: function () { this._super(); this.$(); } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hit dem folks' }); expectAssertion(function () { _this9.render('{{#foo-bar}}{{/foo-bar}}'); }, /You cannot access this.\$\(\) on a component with `tagName: \'\'` specified/); }; _class.prototype['@test renders a contained view with omitted start tag and tagless parent view context'] = function () { var _this10 = this; this.registerComponent('root-component', { ComponentClass: _helpers.Component.extend({ tagName: 'section' }), template: '{{frag-ment}}' }); this.registerComponent('frag-ment', { ComponentClass: _helpers.Component.extend({ tagName: '' }), template: '{{my-span}}' }); this.registerComponent('my-span', { ComponentClass: _helpers.Component.extend({ tagName: 'span' }), template: 'dab' }); this.render('{{root-component}}'); this.assertElement(this.firstChild, { tagName: 'section' }); this.assertElement(this.firstChild.firstElementChild, { tagName: 'span' }); this.runTask(function () { return _this10.rerender(); }); this.assertElement(this.firstChild, { tagName: 'section' }); this.assertElement(this.firstChild.firstElementChild, { tagName: 'span' }); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/instrumentation-compile-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal'], function (_emberBabel, _testCase, _helpers, _emberMetal) { 'use strict'; (0, _testCase.moduleFor)('Components compile instrumentation', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this)); _this.resetEvents(); (0, _emberMetal.instrumentationSubscribe)('render.getComponentDefinition', { before: function (name, timestamp, payload) { if (payload.view !== _this.component) { _this.actual.before.push(payload); } }, after: function (name, timestamp, payload) { if (payload.view !== _this.component) { _this.actual.after.push(payload); } } }); return _this; } _class.prototype.resetEvents = function () { this.expected = { before: [], after: [] }; this.actual = { before: [], after: [] }; }; _class.prototype.teardown = function () { this.assert.deepEqual(this.actual.before, [], 'No unexpected events (before)'); this.assert.deepEqual(this.actual.after, [], 'No unexpected events (after)'); _RenderingTest.prototype.teardown.call(this); (0, _emberMetal.instrumentationReset)(); }; _class.prototype['@test it should only receive an instrumentation event for initial render'] = function () { var _this2 = this; var testCase = this; var BaseClass = _helpers.Component.extend({ tagName: '', willRender: function () { testCase.expected.before.push(this); testCase.expected.after.unshift(this); } }); this.registerComponent('x-bar', { template: '[x-bar: {{bar}}]', ComponentClass: BaseClass.extend() }); this.render('[-top-level: {{foo}}] {{x-bar bar=bar}}', { foo: 'foo', bar: 'bar' }); this.assertText('[-top-level: foo] [x-bar: bar]'); this.assertEvents('after initial render'); this.runTask(function () { return _this2.rerender(); }); this.assertEvents('after no-op rerender'); }; _class.prototype.assertEvents = function (label) { var actual = this.actual, expected = this.expected; this.assert.strictEqual(actual.before.length, actual.after.length, label + ': before and after callbacks should be balanced'); this._assertEvents(label + ' (before):', actual.before, expected.before); this._assertEvents(label + ' (after):', actual.before, expected.before); this.resetEvents(); }; _class.prototype._assertEvents = function (label, actual, expected) { var _this3 = this; this.assert.equal(actual.length, expected.length, label + ': expected ' + expected.length + ' and got ' + actual.length); actual.forEach(function (payload, i) { return _this3.assertPayload(payload, expected[i]); }); }; _class.prototype.assertPayload = function (payload, component) { this.assert.equal(payload.object, component._debugContainerKey, 'payload.object'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/instrumentation-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal'], function (_emberBabel, _testCase, _helpers, _emberMetal) { 'use strict'; (0, _testCase.moduleFor)('Components instrumentation', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this)); _this.resetEvents(); (0, _emberMetal.instrumentationSubscribe)('render.component', { before: function (name, timestamp, payload) { if (payload.view !== _this.component) { _this.actual.before.push(payload); } }, after: function (name, timestamp, payload) { if (payload.view !== _this.component) { _this.actual.after.push(payload); } } }); return _this; } _class.prototype.resetEvents = function () { this.expected = { before: [], after: [] }; this.actual = { before: [], after: [] }; }; _class.prototype.teardown = function () { this.assert.deepEqual(this.actual.before, [], 'No unexpected events (before)'); this.assert.deepEqual(this.actual.after, [], 'No unexpected events (after)'); _RenderingTest.prototype.teardown.call(this); (0, _emberMetal.instrumentationReset)(); }; _class.prototype['@test zomg'] = function (assert) { assert.ok(true); }; _class.prototype['@test it should receive an instrumentation event for both initial render and updates'] = function () { var _this2 = this; var testCase = this; var BaseClass = _helpers.Component.extend({ tagName: '', willRender: function () { testCase.expected.before.push(this); testCase.expected.after.unshift(this); } }); this.registerComponent('x-bar', { template: '[x-bar: {{bar}}] {{yield}}', ComponentClass: BaseClass.extend() }); this.registerComponent('x-baz', { template: '[x-baz: {{baz}}]', ComponentClass: BaseClass.extend() }); this.registerComponent('x-bat', { template: '[x-bat: {{bat}}]', ComponentClass: BaseClass.extend() }); this.render('[-top-level: {{foo}}] {{#x-bar bar=bar}}{{x-baz baz=baz}}{{/x-bar}} {{x-bat bat=bat}}', { foo: 'foo', bar: 'bar', baz: 'baz', bat: 'bat' }); this.assertText('[-top-level: foo] [x-bar: bar] [x-baz: baz] [x-bat: bat]'); this.assertEvents('after initial render', true); this.runTask(function () { return _this2.rerender(); }); this.assertEvents('after no-op rerender'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'foo', 'FOO'); }); this.assertEvents('after updating top-level'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'baz', 'BAZ'); }); this.assertEvents('after updating inner-most'); this.runTask(function () { (0, _emberMetal.set)(_this2.context, 'bar', 'BAR'); (0, _emberMetal.set)(_this2.context, 'bat', 'BAT'); }); this.assertEvents('after updating the rest'); this.runTask(function () { (0, _emberMetal.set)(_this2.context, 'foo', 'FOO'); (0, _emberMetal.set)(_this2.context, 'bar', 'BAR'); (0, _emberMetal.set)(_this2.context, 'baz', 'BAZ'); (0, _emberMetal.set)(_this2.context, 'bat', 'BAT'); }); this.assertEvents('after reset'); }; _class.prototype.assertEvents = function (label) { var initialRender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var actual = this.actual, expected = this.expected; this.assert.strictEqual(actual.before.length, actual.after.length, label + ': before and after callbacks should be balanced'); this._assertEvents(label + ' (before):', actual.before, expected.before, initialRender); this._assertEvents(label + ' (after):', actual.before, expected.before, initialRender); this.resetEvents(); }; _class.prototype._assertEvents = function (label, actual, expected, initialRender) { var _this3 = this; this.assert.equal(actual.length, expected.length, label + ': expected ' + expected.length + ' and got ' + actual.length); actual.forEach(function (payload, i) { return _this3.assertPayload(payload, expected[i], initialRender); }); }; _class.prototype.assertPayload = function (payload, component, initialRender) { this.assert.equal(payload.object, component.toString(), 'payload.object'); this.assert.ok(payload.containerKey, 'the container key should be present'); this.assert.equal(payload.containerKey, component._debugContainerKey, 'payload.containerKey'); this.assert.equal(payload.view, component, 'payload.view'); this.assert.strictEqual(payload.initialRender, initialRender, 'payload.initialRender'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/life-cycle-test', ['ember-babel', 'ember-metal', 'ember-runtime', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case', 'ember-views', 'ember-glimmer/tests/utils/test-helpers', 'ember-utils', 'internal-test-helpers'], function (_emberBabel, _emberMetal, _emberRuntime, _helpers, _abstractTestCase, _testCase, _emberViews, _testHelpers, _emberUtils, _internalTestHelpers) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n Twitter: {{', '}}|\n ', '\n
'], ['\n
\n Twitter: {{', '}}|\n ', '\n
']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n Name: {{', '}}|\n ', '\n
'], ['\n
\n Name: {{', '}}|\n ', '\n
']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n Website: {{', '}}\n
'], ['\n
\n Website: {{', '}}\n
']), _templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n ', '|\n ', '|\n ', '\n
'], ['\n
\n ', '|\n ', '|\n ', '\n
']), _templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n Top: ', '\n
'], ['\n
\n Top: ', '\n
']), _templateObject6 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n Middle: ', '\n
'], ['\n
\n Middle: ', '\n
']), _templateObject7 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n Bottom: {{', '}}\n
'], ['\n
\n Bottom: {{', '}}\n
']), _templateObject8 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#nested-item}}Item: {{count}}{{/nested-item}}\n '], ['\n {{#nested-item}}Item: {{count}}{{/nested-item}}\n ']), _templateObject9 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#nested-item}}Nothing to see here{{/nested-item}}\n '], ['\n {{#nested-item}}Nothing to see here{{/nested-item}}\n ']), _templateObject10 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each items as |item|}}\n ', '\n {{else}}\n ', '\n {{/each}}\n '], ['\n {{#each items as |item|}}\n ', '\n {{else}}\n ', '\n {{/each}}\n ']), _templateObject11 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{yield}}\n
    \n {{#nested-component nestedId=(concat itemId \'-A\')}}A{{/nested-component}}\n {{#nested-component nestedId=(concat itemId \'-B\')}}B{{/nested-component}}\n
\n '], ['\n {{yield}}\n
    \n {{#nested-component nestedId=(concat itemId \'-A\')}}A{{/nested-component}}\n {{#nested-component nestedId=(concat itemId \'-B\')}}B{{/nested-component}}\n
\n ']), _templateObject12 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each items as |item|}}\n {{#parent-component itemId=item.id}}{{item.id}}{{/parent-component}}\n {{/each}}\n {{#if model.shouldShow}}\n {{#parent-component itemId=6}}6{{/parent-component}}\n {{/if}}\n {{#if model.shouldShow}}\n {{#parent-component itemId=7}}7{{/parent-component}}\n {{/if}}\n '], ['\n {{#each items as |item|}}\n {{#parent-component itemId=item.id}}{{item.id}}{{/parent-component}}\n {{/each}}\n {{#if model.shouldShow}}\n {{#parent-component itemId=6}}6{{/parent-component}}\n {{/if}}\n {{#if model.shouldShow}}\n {{#parent-component itemId=7}}7{{/parent-component}}\n {{/if}}\n ']); var LifeCycleHooksTest = function (_RenderingTest) { (0, _emberBabel.inherits)(LifeCycleHooksTest, _RenderingTest); function LifeCycleHooksTest() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this)); _this.hooks = []; _this.components = {}; _this.componentRegistry = []; _this.teardownAssertions = []; return _this; } LifeCycleHooksTest.prototype.teardown = function () { var i; _RenderingTest.prototype.teardown.call(this); for (i = 0; i < this.teardownAssertions.length; i++) { this.teardownAssertions[i](); } }; LifeCycleHooksTest.prototype.getBootOptions = function () { return { isInteractive: this.isInteractive }; }; LifeCycleHooksTest.prototype.invocationFor = function () { arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; throw new Error('Not implemented: `invocationFor`'); }; LifeCycleHooksTest.prototype.attrFor = function () { throw new Error('Not implemented: `attrFor`'); }; LifeCycleHooksTest.prototype.assertRegisteredViews = function (label) { var viewRegistry = this.owner.lookup('-view-registry:main'), expected; var topLevelId = (0, _emberViews.getViewId)(this.component); var actual = Object.keys(viewRegistry).sort().filter(function (id) { return id !== topLevelId; }); if (this.isInteractive) { expected = this.componentRegistry.sort(); this.assert.deepEqual(actual, expected, 'registered views - ' + label); } else { this.assert.deepEqual(actual, [], 'no views should be registered for non-interactive mode'); } }; LifeCycleHooksTest.prototype.registerComponent = function (name, _ref) { var _this2 = this; var _ref$template = _ref.template, template = _ref$template === undefined ? null : _ref$template; var pushComponent = function (instance) { _this2.components[name] = instance; _this2.componentRegistry.push((0, _emberViews.getViewId)(instance)); }; var removeComponent = function (instance) { var index = _this2.componentRegistry.indexOf(instance); _this2.componentRegistry.splice(index, 1); delete _this2.components[name]; }; var pushHook = function (hookName, args) { _this2.hooks.push(hook(name, hookName, args)); }; var assertParentView = function (hookName, instance) { _this2.assert.ok(instance.parentView, 'parentView should be present in ' + hookName); if (hookName === 'willDestroyElement') { _this2.assert.ok(instance.parentView.childViews.indexOf(instance) !== -1, 'view is still connected to parentView in ' + hookName); } }; var assertElement = function (hookName, instance) { var inDOM = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; if (instance.tagName === '') { return; } _this2.assert.ok((0, _emberViews.getViewElement)(instance), 'element should be present on ' + instance + ' during ' + hookName); if (_this2.isInteractive) { _this2.assert.ok(instance.element, 'this.element should be present on ' + instance + ' during ' + hookName); _this2.assert.equal(document.body.contains(instance.element), inDOM, 'element for ' + instance + ' ' + (inDOM ? 'should' : 'should not') + ' be in the DOM during ' + hookName); } else { _this2.assert.throws(function () { return instance.element; }, /Accessing `this.element` is not allowed in non-interactive environments/); } }; var assertNoElement = function (hookName, instance) { _this2.assert.strictEqual((0, _emberViews.getViewElement)(instance), null, 'element should not be present in ' + hookName); if (_this2.isInteractive) { _this2.assert.strictEqual(instance.element, null, 'this.element should not be present in ' + hookName); } else { _this2.assert.throws(function () { return instance.element; }, /Accessing `this.element` is not allowed in non-interactive environments/); } }; var assertState = function (hookName, expectedState, instance) { _this2.assert.equal(instance._state, expectedState, 'within ' + hookName + ' the expected _state is ' + expectedState); }; var isInteractive = this.isInteractive; var ComponentClass = this.ComponentClass.extend({ init: function () { var _this3 = this, _arguments = arguments; expectDeprecation(function () { _this3._super.apply(_this3, _arguments); }, /didInitAttrs called/); this.isInitialRender = true; this.componentName = name; pushHook('init'); pushComponent(this); assertParentView('init', this); assertNoElement('init', this); assertState('init', 'preRender', this); this.on('init', function () { return pushHook('on(init)'); }); _emberMetal.run.scheduleOnce('afterRender', function () { _this3.isInitialRender = false; }); }, didInitAttrs: function (options) { pushHook('didInitAttrs', options); assertParentView('didInitAttrs', this); assertNoElement('didInitAttrs', this); assertState('didInitAttrs', 'preRender', this); }, didReceiveAttrs: function (options) { pushHook('didReceiveAttrs', options); assertParentView('didReceiveAttrs', this); if (this.isInitialRender) { assertNoElement('didReceiveAttrs', this); assertState('didReceiveAttrs', 'preRender', this); } else { assertElement('didReceiveAttrs', this); if (isInteractive) { assertState('didReceiveAttrs', 'inDOM', this); } else { assertState('didReceiveAttrs', 'hasElement', this); } } }, willInsertElement: function () { pushHook('willInsertElement'); assertParentView('willInsertElement', this); assertElement('willInsertElement', this, false); assertState('willInsertElement', 'hasElement', this); }, willRender: function () { pushHook('willRender'); assertParentView('willRender', this); if (this.isInitialRender) { assertNoElement('willRender', this, false); assertState('willRender', 'preRender', this); } else { assertElement('willRender', this); assertState('willRender', 'inDOM', this); } }, didInsertElement: function () { pushHook('didInsertElement'); assertParentView('didInsertElement', this); assertElement('didInsertElement', this); assertState('didInsertElement', 'inDOM', this); }, didRender: function () { pushHook('didRender'); assertParentView('didRender', this); assertElement('didRender', this); assertState('didRender', 'inDOM', this); }, didUpdateAttrs: function (options) { pushHook('didUpdateAttrs', options); assertParentView('didUpdateAttrs', this); if (isInteractive) { assertState('didUpdateAttrs', 'inDOM', this); } else { assertState('didUpdateAttrs', 'hasElement', this); } }, willUpdate: function (options) { pushHook('willUpdate', options); assertParentView('willUpdate', this); assertElement('willUpdate', this); assertState('willUpdate', 'inDOM', this); }, didUpdate: function (options) { pushHook('didUpdate', options); assertParentView('didUpdate', this); assertElement('didUpdate', this); assertState('didUpdate', 'inDOM', this); }, willDestroyElement: function () { pushHook('willDestroyElement'); assertParentView('willDestroyElement', this); assertElement('willDestroyElement', this); assertState('willDestroyElement', 'inDOM', this); }, willClearRender: function () { pushHook('willClearRender'); assertParentView('willClearRender', this); assertElement('willClearRender', this); assertState('willClearRender', 'inDOM', this); }, didDestroyElement: function () { pushHook('didDestroyElement'); assertNoElement('didDestroyElement', this); assertState('didDestroyElement', 'destroying', this); }, willDestroy: function () { pushHook('willDestroy'); removeComponent(this); this._super.apply(this, arguments); } }); _RenderingTest.prototype.registerComponent.call(this, name, { ComponentClass: ComponentClass, template: template }); }; LifeCycleHooksTest.prototype.assertHooks = function (_ref2) { var label = _ref2.label, interactive = _ref2.interactive, nonInteractive = _ref2.nonInteractive; var rawHooks = this.isInteractive ? interactive : nonInteractive; var hooks = rawHooks.map(function (raw) { return hook.apply(undefined, raw); }); this.assert.deepEqual(json(this.hooks), json(hooks), label); this.hooks = []; }; LifeCycleHooksTest.prototype['@test lifecycle hooks are invoked in a predictable order'] = function () { var _this4 = this; var _boundHelpers = this.boundHelpers, attr = _boundHelpers.attr, invoke = _boundHelpers.invoke; this.registerComponent('the-top', { template: (0, _abstractTestCase.strip)(_templateObject, attr('twitter'), invoke('the-middle', { name: string('Tom Dale') })) }); this.registerComponent('the-middle', { template: (0, _abstractTestCase.strip)(_templateObject2, attr('name'), invoke('the-bottom', { website: string('tomdale.net') })) }); this.registerComponent('the-bottom', { template: (0, _abstractTestCase.strip)(_templateObject3, attr('website')) }); this.render(invoke('the-top', { twitter: expr('twitter') }), { twitter: '@tomdale' }); this.assertText('Twitter: @tomdale|Name: Tom Dale|Website: tomdale.net'); this.assertRegisteredViews('intial render'); var topAttrs = { twitter: '@tomdale' }; var middleAttrs = { name: 'Tom Dale' }; var bottomAttrs = { website: 'tomdale.net' }; this.assertHooks({ label: 'after initial render', interactive: [ // Sync hooks ['the-top', 'init'], ['the-top', 'didInitAttrs', { attrs: topAttrs, newAttrs: topAttrs }], ['the-top', 'didReceiveAttrs', { attrs: topAttrs, newAttrs: topAttrs }], ['the-top', 'on(init)'], ['the-top', 'willRender'], ['the-top', 'willInsertElement'], ['the-middle', 'init'], ['the-middle', 'didInitAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }], ['the-middle', 'didReceiveAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }], ['the-middle', 'on(init)'], ['the-middle', 'willRender'], ['the-middle', 'willInsertElement'], ['the-bottom', 'init'], ['the-bottom', 'didInitAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }], ['the-bottom', 'didReceiveAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }], ['the-bottom', 'on(init)'], ['the-bottom', 'willRender'], ['the-bottom', 'willInsertElement'], // Async hooks ['the-bottom', 'didInsertElement'], ['the-bottom', 'didRender'], ['the-middle', 'didInsertElement'], ['the-middle', 'didRender'], ['the-top', 'didInsertElement'], ['the-top', 'didRender']], nonInteractive: [ // Sync hooks ['the-top', 'init'], ['the-top', 'didInitAttrs', { attrs: topAttrs, newAttrs: topAttrs }], ['the-top', 'didReceiveAttrs', { attrs: topAttrs, newAttrs: topAttrs }], ['the-top', 'on(init)'], ['the-middle', 'init'], ['the-middle', 'didInitAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }], ['the-middle', 'didReceiveAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }], ['the-middle', 'on(init)'], ['the-bottom', 'init'], ['the-bottom', 'didInitAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }], ['the-bottom', 'didReceiveAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }], ['the-bottom', 'on(init)']] }); this.runTask(function () { return _this4.components['the-bottom'].rerender(); }); this.assertText('Twitter: @tomdale|Name: Tom Dale|Website: tomdale.net'); this.assertHooks({ label: 'after no-op rerender (bottom)', interactive: [ // Sync hooks ['the-top', 'willUpdate'], ['the-top', 'willRender'], ['the-middle', 'willUpdate'], ['the-middle', 'willRender'], ['the-bottom', 'willUpdate'], ['the-bottom', 'willRender'], // Async hooks ['the-bottom', 'didUpdate'], ['the-bottom', 'didRender'], ['the-middle', 'didUpdate'], ['the-middle', 'didRender'], ['the-top', 'didUpdate'], ['the-top', 'didRender']], nonInteractive: [] }); this.runTask(function () { return _this4.components['the-middle'].rerender(); }); this.assertText('Twitter: @tomdale|Name: Tom Dale|Website: tomdale.net'); this.assertHooks({ label: 'after no-op rerender (middle)', interactive: [ // Sync hooks ['the-top', 'willUpdate'], ['the-top', 'willRender'], ['the-middle', 'willUpdate'], ['the-middle', 'willRender'], // Async hooks ['the-middle', 'didUpdate'], ['the-middle', 'didRender'], ['the-top', 'didUpdate'], ['the-top', 'didRender']], nonInteractive: [] }); this.runTask(function () { return _this4.components['the-top'].rerender(); }); this.assertText('Twitter: @tomdale|Name: Tom Dale|Website: tomdale.net'); this.assertHooks({ label: 'after no-op rerender (top)', interactive: [ // Sync hooks ['the-top', 'willUpdate'], ['the-top', 'willRender'], // Async hooks ['the-top', 'didUpdate'], ['the-top', 'didRender']], nonInteractive: [] }); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'twitter', '@horsetomdale'); }); this.assertText('Twitter: @horsetomdale|Name: Tom Dale|Website: tomdale.net'); // Because the `twitter` attr is only used by the topmost component, // and not passed down, we do not expect to see lifecycle hooks // called for child components. If the `didReceiveAttrs` hook used // the new attribute to rerender itself imperatively, that would result // in lifecycle hooks being invoked for the child. topAttrs = { attrs: { twitter: '@horsetomdale' }, oldAttrs: { twitter: '@tomdale' }, newAttrs: { twitter: '@horsetomdale' } }; this.assertHooks({ label: 'after update', interactive: [ // Sync hooks ['the-top', 'didUpdateAttrs', topAttrs], ['the-top', 'didReceiveAttrs', topAttrs], ['the-top', 'willUpdate'], ['the-top', 'willRender'], // Async hooks ['the-top', 'didUpdate'], ['the-top', 'didRender']], nonInteractive: [ // Sync hooks ['the-top', 'didUpdateAttrs', topAttrs], ['the-top', 'didReceiveAttrs', topAttrs]] }); this.teardownAssertions.push(function () { _this4.assertHooks({ label: 'destroy', interactive: [['the-top', 'willDestroyElement'], ['the-top', 'willClearRender'], ['the-middle', 'willDestroyElement'], ['the-middle', 'willClearRender'], ['the-bottom', 'willDestroyElement'], ['the-bottom', 'willClearRender'], ['the-top', 'didDestroyElement'], ['the-middle', 'didDestroyElement'], ['the-bottom', 'didDestroyElement'], ['the-top', 'willDestroy'], ['the-middle', 'willDestroy'], ['the-bottom', 'willDestroy']], nonInteractive: [['the-top', 'willDestroy'], ['the-middle', 'willDestroy'], ['the-bottom', 'willDestroy']] }); _this4.assertRegisteredViews('after destroy'); }); }; LifeCycleHooksTest.prototype['@test lifecycle hooks are invoked in a correct sibling order'] = function () { var _this5 = this; var _boundHelpers2 = this.boundHelpers, attr = _boundHelpers2.attr, invoke = _boundHelpers2.invoke; this.registerComponent('the-parent', { template: (0, _abstractTestCase.strip)(_templateObject4, invoke('the-first-child', { twitter: expr(attr('twitter')) }), invoke('the-second-child', { name: expr(attr('name')) }), invoke('the-last-child', { website: expr(attr('website')) })) }); this.registerComponent('the-first-child', { template: 'Twitter: {{' + attr('twitter') + '}}' }); this.registerComponent('the-second-child', { template: 'Name: {{' + attr('name') + '}}' }); this.registerComponent('the-last-child', { template: 'Website: {{' + attr('website') + '}}' }); this.render(invoke('the-parent', { twitter: expr('twitter'), name: expr('name'), website: expr('website') }), { twitter: '@tomdale', name: 'Tom Dale', website: 'tomdale.net' }); this.assertText('Twitter: @tomdale|Name: Tom Dale|Website: tomdale.net'); this.assertRegisteredViews('intial render'); var parentAttrs = { twitter: '@tomdale', name: 'Tom Dale', website: 'tomdale.net' }; var firstAttrs = { twitter: '@tomdale' }; var secondAttrs = { name: 'Tom Dale' }; var lastAttrs = { website: 'tomdale.net' }; this.assertHooks({ label: 'after initial render', interactive: [ // Sync hooks ['the-parent', 'init'], ['the-parent', 'didInitAttrs', { attrs: parentAttrs, newAttrs: parentAttrs }], ['the-parent', 'didReceiveAttrs', { attrs: parentAttrs, newAttrs: parentAttrs }], ['the-parent', 'on(init)'], ['the-parent', 'willRender'], ['the-parent', 'willInsertElement'], ['the-first-child', 'init'], ['the-first-child', 'didInitAttrs', { attrs: firstAttrs, newAttrs: firstAttrs }], ['the-first-child', 'didReceiveAttrs', { attrs: firstAttrs, newAttrs: firstAttrs }], ['the-first-child', 'on(init)'], ['the-first-child', 'willRender'], ['the-first-child', 'willInsertElement'], ['the-second-child', 'init'], ['the-second-child', 'didInitAttrs', { attrs: secondAttrs, newAttrs: secondAttrs }], ['the-second-child', 'didReceiveAttrs', { attrs: secondAttrs, newAttrs: secondAttrs }], ['the-second-child', 'on(init)'], ['the-second-child', 'willRender'], ['the-second-child', 'willInsertElement'], ['the-last-child', 'init'], ['the-last-child', 'didInitAttrs', { attrs: lastAttrs, newAttrs: lastAttrs }], ['the-last-child', 'didReceiveAttrs', { attrs: lastAttrs, newAttrs: lastAttrs }], ['the-last-child', 'on(init)'], ['the-last-child', 'willRender'], ['the-last-child', 'willInsertElement'], // Async hooks ['the-first-child', 'didInsertElement'], ['the-first-child', 'didRender'], ['the-second-child', 'didInsertElement'], ['the-second-child', 'didRender'], ['the-last-child', 'didInsertElement'], ['the-last-child', 'didRender'], ['the-parent', 'didInsertElement'], ['the-parent', 'didRender']], nonInteractive: [ // Sync hooks ['the-parent', 'init'], ['the-parent', 'didInitAttrs', { attrs: parentAttrs, newAttrs: parentAttrs }], ['the-parent', 'didReceiveAttrs', { attrs: parentAttrs, newAttrs: parentAttrs }], ['the-parent', 'on(init)'], ['the-first-child', 'init'], ['the-first-child', 'didInitAttrs', { attrs: firstAttrs, newAttrs: firstAttrs }], ['the-first-child', 'didReceiveAttrs', { attrs: firstAttrs, newAttrs: firstAttrs }], ['the-first-child', 'on(init)'], ['the-second-child', 'init'], ['the-second-child', 'didInitAttrs', { attrs: secondAttrs, newAttrs: secondAttrs }], ['the-second-child', 'didReceiveAttrs', { attrs: secondAttrs, newAttrs: secondAttrs }], ['the-second-child', 'on(init)'], ['the-last-child', 'init'], ['the-last-child', 'didInitAttrs', { attrs: lastAttrs, newAttrs: lastAttrs }], ['the-last-child', 'didReceiveAttrs', { attrs: lastAttrs, newAttrs: lastAttrs }], ['the-last-child', 'on(init)']] }); this.runTask(function () { return _this5.components['the-first-child'].rerender(); }); this.assertText('Twitter: @tomdale|Name: Tom Dale|Website: tomdale.net'); this.assertHooks({ label: 'after no-op rerender (first child)', interactive: [ // Sync hooks ['the-parent', 'willUpdate'], ['the-parent', 'willRender'], ['the-first-child', 'willUpdate'], ['the-first-child', 'willRender'], // Async hooks ['the-first-child', 'didUpdate'], ['the-first-child', 'didRender'], ['the-parent', 'didUpdate'], ['the-parent', 'didRender']], nonInteractive: [] }); this.runTask(function () { return _this5.components['the-second-child'].rerender(); }); this.assertText('Twitter: @tomdale|Name: Tom Dale|Website: tomdale.net'); this.assertHooks({ label: 'after no-op rerender (second child)', interactive: [ // Sync hooks ['the-parent', 'willUpdate'], ['the-parent', 'willRender'], ['the-second-child', 'willUpdate'], ['the-second-child', 'willRender'], // Async hooks ['the-second-child', 'didUpdate'], ['the-second-child', 'didRender'], ['the-parent', 'didUpdate'], ['the-parent', 'didRender']], nonInteractive: [] }); this.runTask(function () { return _this5.components['the-last-child'].rerender(); }); this.assertText('Twitter: @tomdale|Name: Tom Dale|Website: tomdale.net'); this.assertHooks({ label: 'after no-op rerender (last child)', interactive: [ // Sync hooks ['the-parent', 'willUpdate'], ['the-parent', 'willRender'], ['the-last-child', 'willUpdate'], ['the-last-child', 'willRender'], // Async hooks ['the-last-child', 'didUpdate'], ['the-last-child', 'didRender'], ['the-parent', 'didUpdate'], ['the-parent', 'didRender']], nonInteractive: [] }); this.runTask(function () { return _this5.components['the-parent'].rerender(); }); this.assertText('Twitter: @tomdale|Name: Tom Dale|Website: tomdale.net'); this.assertHooks({ label: 'after no-op rerender (parent)', interactive: [ // Sync hooks ['the-parent', 'willUpdate'], ['the-parent', 'willRender'], // Async hooks ['the-parent', 'didUpdate'], ['the-parent', 'didRender']], nonInteractive: [] }); this.runTask(function () { return (0, _emberMetal.setProperties)(_this5.context, { twitter: '@horsetomdale', name: 'Horse Tom Dale', website: 'horsetomdale.net' }); }); this.assertText('Twitter: @horsetomdale|Name: Horse Tom Dale|Website: horsetomdale.net'); parentAttrs = { attrs: { twitter: '@horsetomdale', name: 'Horse Tom Dale', website: 'horsetomdale.net' }, oldAttrs: { twitter: '@tomdale', name: 'Tom Dale', website: 'tomdale.net' }, newAttrs: { twitter: '@horsetomdale', name: 'Horse Tom Dale', website: 'horsetomdale.net' } }; firstAttrs = { attrs: { twitter: '@horsetomdale' }, oldAttrs: { twitter: '@tomdale' }, newAttrs: { twitter: '@horsetomdale' } }; secondAttrs = { attrs: { name: 'Horse Tom Dale' }, oldAttrs: { name: 'Tom Dale' }, newAttrs: { name: 'Horse Tom Dale' } }; lastAttrs = { attrs: { website: 'horsetomdale.net' }, oldAttrs: { website: 'tomdale.net' }, newAttrs: { website: 'horsetomdale.net' } }; this.assertHooks({ label: 'after update', interactive: [ // Sync hooks ['the-parent', 'didUpdateAttrs', parentAttrs], ['the-parent', 'didReceiveAttrs', parentAttrs], ['the-parent', 'willUpdate'], ['the-parent', 'willRender'], ['the-first-child', 'didUpdateAttrs', firstAttrs], ['the-first-child', 'didReceiveAttrs', firstAttrs], ['the-first-child', 'willUpdate'], ['the-first-child', 'willRender'], ['the-second-child', 'didUpdateAttrs', secondAttrs], ['the-second-child', 'didReceiveAttrs', secondAttrs], ['the-second-child', 'willUpdate'], ['the-second-child', 'willRender'], ['the-last-child', 'didUpdateAttrs', lastAttrs], ['the-last-child', 'didReceiveAttrs', lastAttrs], ['the-last-child', 'willUpdate'], ['the-last-child', 'willRender'], // Async hooks ['the-first-child', 'didUpdate'], ['the-first-child', 'didRender'], ['the-second-child', 'didUpdate'], ['the-second-child', 'didRender'], ['the-last-child', 'didUpdate'], ['the-last-child', 'didRender'], ['the-parent', 'didUpdate'], ['the-parent', 'didRender']], nonInteractive: [ // Sync hooks ['the-parent', 'didUpdateAttrs', parentAttrs], ['the-parent', 'didReceiveAttrs', parentAttrs], ['the-first-child', 'didUpdateAttrs', firstAttrs], ['the-first-child', 'didReceiveAttrs', firstAttrs], ['the-second-child', 'didUpdateAttrs', secondAttrs], ['the-second-child', 'didReceiveAttrs', secondAttrs], ['the-last-child', 'didUpdateAttrs', lastAttrs], ['the-last-child', 'didReceiveAttrs', lastAttrs]] }); this.teardownAssertions.push(function () { _this5.assertHooks({ label: 'destroy', interactive: [['the-parent', 'willDestroyElement'], ['the-parent', 'willClearRender'], ['the-first-child', 'willDestroyElement'], ['the-first-child', 'willClearRender'], ['the-second-child', 'willDestroyElement'], ['the-second-child', 'willClearRender'], ['the-last-child', 'willDestroyElement'], ['the-last-child', 'willClearRender'], ['the-parent', 'didDestroyElement'], ['the-first-child', 'didDestroyElement'], ['the-second-child', 'didDestroyElement'], ['the-last-child', 'didDestroyElement'], ['the-parent', 'willDestroy'], ['the-first-child', 'willDestroy'], ['the-second-child', 'willDestroy'], ['the-last-child', 'willDestroy']], nonInteractive: [['the-parent', 'willDestroy'], ['the-first-child', 'willDestroy'], ['the-second-child', 'willDestroy'], ['the-last-child', 'willDestroy']] }); _this5.assertRegisteredViews('after destroy'); }); }; LifeCycleHooksTest.prototype['@test passing values through attrs causes lifecycle hooks to fire if the attribute values have changed'] = function () { var _this6 = this; var _boundHelpers3 = this.boundHelpers, attr = _boundHelpers3.attr, invoke = _boundHelpers3.invoke; this.registerComponent('the-top', { template: (0, _abstractTestCase.strip)(_templateObject5, invoke('the-middle', { twitterTop: expr(attr('twitter')) })) }); this.registerComponent('the-middle', { template: (0, _abstractTestCase.strip)(_templateObject6, invoke('the-bottom', { twitterMiddle: expr(attr('twitterTop')) })) }); this.registerComponent('the-bottom', { template: (0, _abstractTestCase.strip)(_templateObject7, attr('twitterMiddle')) }); this.render(invoke('the-top', { twitter: expr('twitter') }), { twitter: '@tomdale' }); this.assertText('Top: Middle: Bottom: @tomdale'); this.assertRegisteredViews('intial render'); var topAttrs = { twitter: '@tomdale' }; var middleAttrs = { twitterTop: '@tomdale' }; var bottomAttrs = { twitterMiddle: '@tomdale' }; this.assertHooks({ label: 'after initial render', interactive: [ // Sync hooks ['the-top', 'init'], ['the-top', 'didInitAttrs', { attrs: topAttrs, newAttrs: topAttrs }], ['the-top', 'didReceiveAttrs', { attrs: topAttrs, newAttrs: topAttrs }], ['the-top', 'on(init)'], ['the-top', 'willRender'], ['the-top', 'willInsertElement'], ['the-middle', 'init'], ['the-middle', 'didInitAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }], ['the-middle', 'didReceiveAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }], ['the-middle', 'on(init)'], ['the-middle', 'willRender'], ['the-middle', 'willInsertElement'], ['the-bottom', 'init'], ['the-bottom', 'didInitAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }], ['the-bottom', 'didReceiveAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }], ['the-bottom', 'on(init)'], ['the-bottom', 'willRender'], ['the-bottom', 'willInsertElement'], // Async hooks ['the-bottom', 'didInsertElement'], ['the-bottom', 'didRender'], ['the-middle', 'didInsertElement'], ['the-middle', 'didRender'], ['the-top', 'didInsertElement'], ['the-top', 'didRender']], nonInteractive: [ // Sync hooks ['the-top', 'init'], ['the-top', 'didInitAttrs', { attrs: topAttrs, newAttrs: topAttrs }], ['the-top', 'didReceiveAttrs', { attrs: topAttrs, newAttrs: topAttrs }], ['the-top', 'on(init)'], ['the-middle', 'init'], ['the-middle', 'didInitAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }], ['the-middle', 'didReceiveAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }], ['the-middle', 'on(init)'], ['the-bottom', 'init'], ['the-bottom', 'didInitAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }], ['the-bottom', 'didReceiveAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }], ['the-bottom', 'on(init)']] }); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'twitter', '@horsetomdale'); }); this.assertText('Top: Middle: Bottom: @horsetomdale'); // Because the `twitter` attr is used by the all of the components, // the lifecycle hooks are invoked for all components. topAttrs = { attrs: { twitter: '@horsetomdale' }, oldAttrs: { twitter: '@tomdale' }, newAttrs: { twitter: '@horsetomdale' } }; middleAttrs = { attrs: { twitterTop: '@horsetomdale' }, oldAttrs: { twitterTop: '@tomdale' }, newAttrs: { twitterTop: '@horsetomdale' } }; bottomAttrs = { attrs: { twitterMiddle: '@horsetomdale' }, oldAttrs: { twitterMiddle: '@tomdale' }, newAttrs: { twitterMiddle: '@horsetomdale' } }; this.assertHooks({ label: 'after updating (root)', interactive: [ // Sync hooks ['the-top', 'didUpdateAttrs', topAttrs], ['the-top', 'didReceiveAttrs', topAttrs], ['the-top', 'willUpdate'], ['the-top', 'willRender'], ['the-middle', 'didUpdateAttrs', middleAttrs], ['the-middle', 'didReceiveAttrs', middleAttrs], ['the-middle', 'willUpdate'], ['the-middle', 'willRender'], ['the-bottom', 'didUpdateAttrs', bottomAttrs], ['the-bottom', 'didReceiveAttrs', bottomAttrs], ['the-bottom', 'willUpdate'], ['the-bottom', 'willRender'], // Async hooks ['the-bottom', 'didUpdate'], ['the-bottom', 'didRender'], ['the-middle', 'didUpdate'], ['the-middle', 'didRender'], ['the-top', 'didUpdate'], ['the-top', 'didRender']], nonInteractive: [ // Sync hooks ['the-top', 'didUpdateAttrs', topAttrs], ['the-top', 'didReceiveAttrs', topAttrs], ['the-middle', 'didUpdateAttrs', middleAttrs], ['the-middle', 'didReceiveAttrs', middleAttrs], ['the-bottom', 'didUpdateAttrs', bottomAttrs], ['the-bottom', 'didReceiveAttrs', bottomAttrs]] }); this.runTask(function () { return _this6.rerender(); }); this.assertText('Top: Middle: Bottom: @horsetomdale'); // In this case, because the attrs are passed down, all child components are invoked. topAttrs = { attrs: { twitter: '@horsetomdale' }, oldAttrs: { twitter: '@horsetomdale' }, newAttrs: { twitter: '@horsetomdale' } }; middleAttrs = { attrs: { twitterTop: '@horsetomdale' }, oldAttrs: { twitterTop: '@horsetomdale' }, newAttrs: { twitterTop: '@horsetomdale' } }; bottomAttrs = { attrs: { twitterMiddle: '@horsetomdale' }, oldAttrs: { twitterMiddle: '@horsetomdale' }, newAttrs: { twitterMiddle: '@horsetomdale' } }; this.assertHooks({ label: 'after no-op rernder (root)', interactive: [], nonInteractive: [] }); this.teardownAssertions.push(function () { _this6.assertHooks({ label: 'destroy', interactive: [['the-top', 'willDestroyElement'], ['the-top', 'willClearRender'], ['the-middle', 'willDestroyElement'], ['the-middle', 'willClearRender'], ['the-bottom', 'willDestroyElement'], ['the-bottom', 'willClearRender'], ['the-top', 'didDestroyElement'], ['the-middle', 'didDestroyElement'], ['the-bottom', 'didDestroyElement'], ['the-top', 'willDestroy'], ['the-middle', 'willDestroy'], ['the-bottom', 'willDestroy']], nonInteractive: [['the-top', 'willDestroy'], ['the-middle', 'willDestroy'], ['the-bottom', 'willDestroy']] }); _this6.assertRegisteredViews('after destroy'); }); }; LifeCycleHooksTest.prototype['@test components rendered from `{{each}}` have correct life-cycle hooks to be called'] = function () { var _this7 = this; var invoke = this.boundHelpers.invoke; this.registerComponent('nested-item', { template: '{{yield}}' }); this.registerComponent('an-item', { template: (0, _abstractTestCase.strip)(_templateObject8) }); this.registerComponent('no-items', { template: (0, _abstractTestCase.strip)(_templateObject9) }); this.render((0, _abstractTestCase.strip)(_templateObject10, invoke('an-item', { count: expr('item') }), invoke('no-items')), { items: [1, 2, 3, 4, 5] }); this.assertText('Item: 1Item: 2Item: 3Item: 4Item: 5'); this.assertRegisteredViews('intial render'); var initialHooks = function (count) { var ret = [['an-item', 'init'], ['an-item', 'didInitAttrs', { attrs: { count: count }, newAttrs: { count: count } }], ['an-item', 'didReceiveAttrs', { attrs: { count: count }, newAttrs: { count: count } }], ['an-item', 'on(init)']]; if (_this7.isInteractive) { ret.push(['an-item', 'willRender'], ['an-item', 'willInsertElement']); } ret.push(['nested-item', 'init'], ['nested-item', 'didInitAttrs', { attrs: {}, newAttrs: {} }], ['nested-item', 'didReceiveAttrs', { attrs: {}, newAttrs: {} }], ['nested-item', 'on(init)']); if (_this7.isInteractive) { ret.push(['nested-item', 'willRender'], ['nested-item', 'willInsertElement']); } return ret; }; var initialAfterRenderHooks = function () { if (_this7.isInteractive) { return [['nested-item', 'didInsertElement'], ['nested-item', 'didRender'], ['an-item', 'didInsertElement'], ['an-item', 'didRender']]; } else { return []; } }; this.assertHooks({ label: 'after initial render', interactive: [].concat(initialHooks(1), initialHooks(2), initialHooks(3), initialHooks(4), initialHooks(5), initialAfterRenderHooks(5), initialAfterRenderHooks(4), initialAfterRenderHooks(3), initialAfterRenderHooks(2), initialAfterRenderHooks(1)), nonInteractive: [].concat(initialHooks(1), initialHooks(2), initialHooks(3), initialHooks(4), initialHooks(5), initialAfterRenderHooks(5), initialAfterRenderHooks(4), initialAfterRenderHooks(3), initialAfterRenderHooks(2), initialAfterRenderHooks(1)) }); // TODO: Is this correct? Should childViews be populated in non-interactive mode? if (this.isInteractive) { this.assert.equal(this.component.childViews.length, 5, 'childViews precond'); } this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'items', []); }); // TODO: Is this correct? Should childViews be populated in non-interactive mode? if (this.isInteractive) { this.assert.equal(this.component.childViews.length, 1, 'childViews updated'); } this.assertText('Nothing to see here'); this.assertHooks({ label: 'reset to empty array', interactive: [['an-item', 'willDestroyElement'], ['an-item', 'willClearRender'], ['nested-item', 'willDestroyElement'], ['nested-item', 'willClearRender'], ['an-item', 'willDestroyElement'], ['an-item', 'willClearRender'], ['nested-item', 'willDestroyElement'], ['nested-item', 'willClearRender'], ['an-item', 'willDestroyElement'], ['an-item', 'willClearRender'], ['nested-item', 'willDestroyElement'], ['nested-item', 'willClearRender'], ['an-item', 'willDestroyElement'], ['an-item', 'willClearRender'], ['nested-item', 'willDestroyElement'], ['nested-item', 'willClearRender'], ['an-item', 'willDestroyElement'], ['an-item', 'willClearRender'], ['nested-item', 'willDestroyElement'], ['nested-item', 'willClearRender'], ['no-items', 'init'], ['no-items', 'didInitAttrs', { attrs: {}, newAttrs: {} }], ['no-items', 'didReceiveAttrs', { attrs: {}, newAttrs: {} }], ['no-items', 'on(init)'], ['no-items', 'willRender'], ['no-items', 'willInsertElement'], ['nested-item', 'init'], ['nested-item', 'didInitAttrs', { attrs: {}, newAttrs: {} }], ['nested-item', 'didReceiveAttrs', { attrs: {}, newAttrs: {} }], ['nested-item', 'on(init)'], ['nested-item', 'willRender'], ['nested-item', 'willInsertElement'], ['an-item', 'didDestroyElement'], ['nested-item', 'didDestroyElement'], ['an-item', 'didDestroyElement'], ['nested-item', 'didDestroyElement'], ['an-item', 'didDestroyElement'], ['nested-item', 'didDestroyElement'], ['an-item', 'didDestroyElement'], ['nested-item', 'didDestroyElement'], ['an-item', 'didDestroyElement'], ['nested-item', 'didDestroyElement'], ['nested-item', 'didInsertElement'], ['nested-item', 'didRender'], ['no-items', 'didInsertElement'], ['no-items', 'didRender'], ['an-item', 'willDestroy'], ['nested-item', 'willDestroy'], ['an-item', 'willDestroy'], ['nested-item', 'willDestroy'], ['an-item', 'willDestroy'], ['nested-item', 'willDestroy'], ['an-item', 'willDestroy'], ['nested-item', 'willDestroy'], ['an-item', 'willDestroy'], ['nested-item', 'willDestroy']], nonInteractive: [['no-items', 'init'], ['no-items', 'didInitAttrs', { attrs: {}, newAttrs: {} }], ['no-items', 'didReceiveAttrs', { attrs: {}, newAttrs: {} }], ['no-items', 'on(init)'], ['nested-item', 'init'], ['nested-item', 'didInitAttrs', { attrs: {}, newAttrs: {} }], ['nested-item', 'didReceiveAttrs', { attrs: {}, newAttrs: {} }], ['nested-item', 'on(init)'], ['an-item', 'willDestroy'], ['nested-item', 'willDestroy'], ['an-item', 'willDestroy'], ['nested-item', 'willDestroy'], ['an-item', 'willDestroy'], ['nested-item', 'willDestroy'], ['an-item', 'willDestroy'], ['nested-item', 'willDestroy'], ['an-item', 'willDestroy'], ['nested-item', 'willDestroy']] }); this.teardownAssertions.push(function () { _this7.assertHooks({ label: 'destroy', interactive: [['no-items', 'willDestroyElement'], ['no-items', 'willClearRender'], ['nested-item', 'willDestroyElement'], ['nested-item', 'willClearRender'], ['no-items', 'didDestroyElement'], ['nested-item', 'didDestroyElement'], ['no-items', 'willDestroy'], ['nested-item', 'willDestroy']], nonInteractive: [['no-items', 'willDestroy'], ['nested-item', 'willDestroy']] }); _this7.assertRegisteredViews('after destroy'); }); }; (0, _emberBabel.createClass)(LifeCycleHooksTest, [{ key: 'isInteractive', get: function () { return true; } }, { key: 'ComponentClass', get: function () { throw new Error('Not implemented: `ComponentClass`'); } }, { key: 'boundHelpers', get: function () { return { invoke: bind(this.invocationFor, this), attr: bind(this.attrFor, this) }; } }]); return LifeCycleHooksTest; }(_testCase.RenderingTest); var CurlyComponentsTest = function (_LifeCycleHooksTest) { (0, _emberBabel.inherits)(CurlyComponentsTest, _LifeCycleHooksTest); function CurlyComponentsTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _LifeCycleHooksTest.apply(this, arguments)); } CurlyComponentsTest.prototype.invocationFor = function (name) { var _this9 = this; var namedArgs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var attrs = Object.keys(namedArgs).map(function (k) { return k + '=' + _this9.val(namedArgs[k]); }).join(' '); return '{{' + name + ' ' + attrs + '}}'; }; CurlyComponentsTest.prototype.attrFor = function (name) { return '' + name; }; CurlyComponentsTest.prototype.val = function (value) { if (value.isString) { return JSON.stringify(value.value); } else if (value.isExpr) { return '(readonly ' + value.value + ')'; } else { throw new Error('Unknown value: ' + value); } }; (0, _emberBabel.createClass)(CurlyComponentsTest, [{ key: 'ComponentClass', get: function () { return _helpers.Component; } }]); return CurlyComponentsTest; }(LifeCycleHooksTest); (0, _testCase.moduleFor)('Components test: interactive lifecycle hooks (curly components)', function (_CurlyComponentsTest) { (0, _emberBabel.inherits)(_class, _CurlyComponentsTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _CurlyComponentsTest.apply(this, arguments)); } (0, _emberBabel.createClass)(_class, [{ key: 'isInteractive', get: function () { return true; } }]); return _class; }(CurlyComponentsTest)); (0, _testCase.moduleFor)('Components test: non-interactive lifecycle hooks (curly components)', function (_CurlyComponentsTest2) { (0, _emberBabel.inherits)(_class2, _CurlyComponentsTest2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _CurlyComponentsTest2.apply(this, arguments)); } (0, _emberBabel.createClass)(_class2, [{ key: 'isInteractive', get: function () { return false; } }]); return _class2; }(CurlyComponentsTest)); (0, _testCase.moduleFor)('Components test: interactive lifecycle hooks (tagless curly components)', function (_CurlyComponentsTest3) { (0, _emberBabel.inherits)(_class3, _CurlyComponentsTest3); function _class3() { return (0, _emberBabel.possibleConstructorReturn)(this, _CurlyComponentsTest3.apply(this, arguments)); } (0, _emberBabel.createClass)(_class3, [{ key: 'ComponentClass', get: function () { return _helpers.Component.extend({ tagName: '' }); } }, { key: 'isInteractive', get: function () { return true; } }]); return _class3; }(CurlyComponentsTest)); (0, _testCase.moduleFor)('Components test: non-interactive lifecycle hooks (tagless curly components)', function (_CurlyComponentsTest4) { (0, _emberBabel.inherits)(_class4, _CurlyComponentsTest4); function _class4() { return (0, _emberBabel.possibleConstructorReturn)(this, _CurlyComponentsTest4.apply(this, arguments)); } (0, _emberBabel.createClass)(_class4, [{ key: 'ComponentClass', get: function () { return _helpers.Component.extend({ tagName: '' }); } }, { key: 'isInteractive', get: function () { return false; } }]); return _class4; }(CurlyComponentsTest)); (0, _testCase.moduleFor)('Run loop and lifecycle hooks', function (_RenderingTest2) { (0, _emberBabel.inherits)(_class5, _RenderingTest2); function _class5() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments)); } _class5.prototype['@test afterRender set'] = function () { var _this16 = this; var ComponentClass = _helpers.Component.extend({ width: '5', didInsertElement: function () { var _this15 = this; _emberMetal.run.scheduleOnce('afterRender', function () { _this15.set('width', '10'); }); } }); this.registerComponent('foo-bar', { ComponentClass: ComponentClass, template: '{{width}}' }); this.render('{{foo-bar}}'); this.assertText('10'); this.runTask(function () { return _this16.rerender(); }); this.assertText('10'); }; _class5.prototype['@test afterRender set on parent'] = function () { var _this18 = this; var ComponentClass = _helpers.Component.extend({ didInsertElement: function () { var _this17 = this; _emberMetal.run.scheduleOnce('afterRender', function () { var parent = _this17.get('parent'); parent.set('foo', 'wat'); }); } }); this.registerComponent('foo-bar', { ComponentClass: ComponentClass, template: '{{foo}}' }); this.render('{{foo-bar parent=this foo=foo}}'); this.assertText('wat'); this.runTask(function () { return _this18.rerender(); }); this.assertText('wat'); }; _class5.prototype['@test `willRender` can set before render (GH#14458)'] = function () { var ComponentClass = _helpers.Component.extend({ tagName: 'a', customHref: 'http://google.com', attributeBindings: ['customHref:href'], willRender: function () { this.set('customHref', 'http://willRender.com'); } }); this.registerComponent('foo-bar', { ComponentClass: ComponentClass, template: 'Hello World' }); this.render('{{foo-bar id="foo"}}'); this.assertElement(this.firstChild, { tagName: 'a', attrs: { id: 'foo', href: 'http://willRender.com', class: (0, _testHelpers.classes)('ember-view') } }); }; _class5.prototype['@test that thing about destroying'] = function (assert) { var _this19 = this; var ParentDestroyedElements = []; var ChildDestroyedElements = []; var ParentComponent = _helpers.Component.extend({ willDestroyElement: function () { ParentDestroyedElements.push({ id: this.itemId, name: 'parent-component', hasParent: !!this.element.parentNode, nextSibling: !!this.element.nextSibling, previousSibling: !!this.element.previousSibling }); } }); var PartentTemplate = (0, _abstractTestCase.strip)(_templateObject11); var NestedComponent = _helpers.Component.extend({ willDestroyElement: function () { ChildDestroyedElements.push({ id: this.nestedId, name: 'nested-component', hasParent: !!this.element.parentNode, nextSibling: !!this.element.nextSibling, previousSibling: !!this.element.previousSibling }); } }); this.registerComponent('parent-component', { ComponentClass: ParentComponent, template: PartentTemplate }); this.registerComponent('nested-component', { ComponentClass: NestedComponent, template: '{{yield}}' }); var array = (0, _emberRuntime.A)([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]); this.render((0, _abstractTestCase.strip)(_templateObject12), { items: array, model: { shouldShow: true } }); this.assertText('1AB2AB3AB4AB5AB6AB7AB'); this.runTask(function () { array.removeAt(2); array.removeAt(2); (0, _emberMetal.set)(_this19.context, 'model.shouldShow', false); }); this.assertText('1AB2AB5AB'); assertDestroyHooks(assert, [].concat(ParentDestroyedElements), [{ id: 3, hasParent: true, nextSibling: true, previousSibling: true }, { id: 4, hasParent: true, nextSibling: true, previousSibling: true }, { id: 6, hasParent: true, nextSibling: true, previousSibling: true }, { id: 7, hasParent: true, nextSibling: false, previousSibling: true }]); assertDestroyHooks(assert, [].concat(ChildDestroyedElements), [{ id: '3-A', hasParent: true, nextSibling: true, previousSibling: false }, { id: '3-B', hasParent: true, nextSibling: false, previousSibling: true }, { id: '4-A', hasParent: true, nextSibling: true, previousSibling: false }, { id: '4-B', hasParent: true, nextSibling: false, previousSibling: true }, { id: '6-A', hasParent: true, nextSibling: true, previousSibling: false }, { id: '6-B', hasParent: true, nextSibling: false, previousSibling: true }, { id: '7-A', hasParent: true, nextSibling: true, previousSibling: false }, { id: '7-B', hasParent: true, nextSibling: false, previousSibling: true }]); }; _class5.prototype['@test lifecycle hooks have proper access to this.$()'] = function (assert) { assert.expect(6); var component = void 0; var FooBarComponent = _helpers.Component.extend({ tagName: 'div', init: function () { assert.notOk(this.$(), 'no access to element via this.$() on init() enter'); this._super.apply(this, arguments); assert.notOk(this.$(), 'no access to element via this.$() after init() finished'); }, willInsertElement: function () { component = this; assert.ok(this.$(), 'willInsertElement has access to element via this.$()'); }, didInsertElement: function () { assert.ok(this.$(), 'didInsertElement has access to element via this.$()'); }, willDestroyElement: function () { assert.ok(this.$(), 'willDestroyElement has access to element via this.$()'); }, didDestroyElement: function () { assert.notOk(this.$(), 'didDestroyElement does not have access to element via this.$()'); } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); var owner = this.owner; var comp = owner.lookup('component:foo-bar'); (0, _internalTestHelpers.runAppend)(comp); this.runTask(function () { return (0, _emberUtils.tryInvoke)(component, 'destroy'); }); }; return _class5; }(_testCase.RenderingTest)); function assertDestroyHooks(assert, _actual, _expected) { _expected.forEach(function (expected, i) { var name = expected.name; assert.equal(expected.id, _actual[i].id, name + ' id is the same'); assert.equal(expected.hasParent, _actual[i].hasParent, name + ' has parent node'); assert.equal(expected.nextSibling, _actual[i].nextSibling, name + ' has next sibling node'); assert.equal(expected.previousSibling, _actual[i].previousSibling, name + ' has previous sibling node'); }); } function bind(func, thisArg) { return function () { var _len, args, _key; for (_len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return func.apply(thisArg, args); }; } function string(value) { return { isString: true, value: value }; } function expr(value) { return { isExpr: true, value: value }; } function hook(name, hook) { var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, attrs = _ref3.attrs, oldAttrs = _ref3.oldAttrs, newAttrs = _ref3.newAttrs; return { name: name, hook: hook, args: { attrs: attrs, oldAttrs: oldAttrs, newAttrs: newAttrs } }; } function json(serializable) { return JSON.parse(JSON.stringify(serializable)); } }); enifed('ember-glimmer/tests/integration/components/link-to-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-runtime', 'ember-metal', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/test-helpers'], function (_emberBabel, _testCase, _emberRuntime, _emberMetal, _helpers, _testHelpers) { 'use strict'; (0, _testCase.moduleFor)('Link-to component', function (_ApplicationTest) { (0, _emberBabel.inherits)(_class, _ApplicationTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTest.apply(this, arguments)); } _class.prototype.visitWithDeprecation = function (path, deprecation) { var _this2 = this; var p = void 0; expectDeprecation(function () { p = _this2.visit(path); }, deprecation); return p; }; _class.prototype['@test accessing `currentWhen` triggers a deprecation'] = function () { var component = void 0; this.addComponent('link-to', { ComponentClass: _helpers.LinkComponent.extend({ init: function () { this._super.apply(this, arguments); component = this; } }) }); this.addTemplate('application', '{{link-to \'Index\' \'index\'}}'); return this.visit('/').then(function () { expectDeprecation(function () { component.get('currentWhen'); }, /Usage of `currentWhen` is deprecated, use `current-when` instead/); }); }; _class.prototype['@test should be able to be inserted in DOM when the router is not present'] = function () { var _this3 = this; this.addTemplate('application', '{{#link-to \'index\'}}Go to Index{{/link-to}}'); return this.visit('/').then(function () { _this3.assertText('Go to Index'); }); }; _class.prototype['@test re-renders when title changes'] = function () { var _this4 = this; var controller = void 0; this.addTemplate('application', '{{link-to title routeName}}'); this.add('controller:application', _emberRuntime.Controller.extend({ init: function () { this._super.apply(this, arguments); controller = this; }, title: 'foo', routeName: 'index' })); return this.visit('/').then(function () { _this4.assertText('foo'); _this4.runTask(function () { return (0, _emberMetal.set)(controller, 'title', 'bar'); }); _this4.assertText('bar'); }); }; _class.prototype['@test escaped inline form (double curlies) escapes link title'] = function () { var _this5 = this; this.addTemplate('application', '{{link-to title \'index\'}}'); this.add('controller:application', _emberRuntime.Controller.extend({ title: 'blah' })); return this.visit('/').then(function () { _this5.assertText('blah'); }); }; _class.prototype['@test escaped inline form with (-html-safe) does not escape link title'] = function (assert) { var _this6 = this; this.addTemplate('application', '{{link-to (-html-safe title) \'index\'}}'); this.add('controller:application', _emberRuntime.Controller.extend({ title: 'blah' })); return this.visit('/').then(function () { _this6.assertText('blah'); assert.equal(_this6.$('b').length, 1); }); }; _class.prototype['@test unescaped inline form (triple curlies) does not escape link title'] = function (assert) { var _this7 = this; this.addTemplate('application', '{{{link-to title \'index\'}}}'); this.add('controller:application', _emberRuntime.Controller.extend({ title: 'blah' })); return this.visit('/').then(function () { _this7.assertText('blah'); assert.equal(_this7.$('b').length, 1); }); }; _class.prototype['@test unwraps controllers'] = function () { var _this8 = this; this.router.map(function () { this.route('profile', { path: '/profile/:id' }); }); this.addTemplate('application', '{{#link-to \'profile\' otherController}}Text{{/link-to}}'); this.add('controller:application', _emberRuntime.Controller.extend({ otherController: _emberRuntime.Controller.create({ model: 'foo' }) })); var deprecation = /Providing `{{link-to}}` with a param that is wrapped in a controller is deprecated./; return this.visitWithDeprecation('/', deprecation).then(function () { _this8.assertText('Text'); }); }; _class.prototype['@test able to safely extend the built-in component and use the normal path'] = function () { var _this9 = this; this.addComponent('custom-link-to', { ComponentClass: _helpers.LinkComponent.extend() }); this.addTemplate('application', '{{#custom-link-to \'index\'}}{{title}}{{/custom-link-to}}'); this.add('controller:application', _emberRuntime.Controller.extend({ title: 'Hello' })); return this.visit('/').then(function () { _this9.assertText('Hello'); }); }; _class.prototype['@test [GH#13432] able to safely extend the built-in component and invoke it inline'] = function () { var _this10 = this; this.addComponent('custom-link-to', { ComponentClass: _helpers.LinkComponent.extend() }); this.addTemplate('application', '{{custom-link-to title \'index\'}}'); this.add('controller:application', _emberRuntime.Controller.extend({ title: 'Hello' })); return this.visit('/').then(function () { _this10.assertText('Hello'); }); }; return _class; }(_testCase.ApplicationTest)); (0, _testCase.moduleFor)('Link-to component with query-params', function (_ApplicationTest2) { (0, _emberBabel.inherits)(_class2, _ApplicationTest2); function _class2() { var _this11 = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTest2.apply(this, arguments)); _this11.add('controller:index', _emberRuntime.Controller.extend({ queryParams: ['foo'], foo: '123', bar: 'yes' })); return _this11; } _class2.prototype['@test populates href with fully supplied query param values'] = function () { var _this12 = this; this.addTemplate('index', '{{#link-to \'index\' (query-params foo=\'456\' bar=\'NAW\')}}Index{{/link-to}}'); return this.visit('/').then(function () { _this12.assertComponentElement(_this12.firstChild.firstElementChild, { tagName: 'a', attrs: { href: '/?bar=NAW&foo=456' }, content: 'Index' }); }); }; _class2.prototype['@test populates href with partially supplied query param values, but omits if value is default value'] = function () { var _this13 = this; this.addTemplate('index', '{{#link-to \'index\' (query-params foo=\'123\')}}Index{{/link-to}}'); return this.visit('/').then(function () { _this13.assertComponentElement(_this13.firstChild.firstElementChild, { tagName: 'a', attrs: { href: '/', class: (0, _testHelpers.classes)('ember-view active') }, content: 'Index' }); }); }; return _class2; }(_testCase.ApplicationTest)); }); enifed('ember-glimmer/tests/integration/components/local-lookup-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers'], function (_emberBabel, _testCase, _helpers) { 'use strict'; function buildResolver() { return { resolve: function () {}, expandLocalLookup: function (fullName, sourceFullName) { var _sourceFullName$split = sourceFullName.split(':'), sourceType = _sourceFullName$split[0], sourceName = _sourceFullName$split[1]; var _fullName$split = fullName.split(':'), type = _fullName$split[0], name = _fullName$split[1]; if (type !== 'template' && sourceType === 'template' && sourceName.slice(0, 11) === 'components/') { sourceName = sourceName.slice(11); } if (type === 'template' && sourceType === 'template' && name.slice(0, 11) === 'components/') { name = name.slice(11); } var result = type + ':' + sourceName + '/' + name; return result; } }; } (0, _testCase.moduleFor)('Components test: local lookup', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype.getResolver = function () { return buildResolver(); }; _class.prototype['@test it can lookup a local template'] = function () { var _this2 = this; this.registerComponent('x-outer/x-inner', { template: 'Nested template says: {{yield}}' }); this.registerComponent('x-outer', { template: '{{#x-inner}}Hi!{{/x-inner}}' }); this.render('{{x-outer}}'); this.assertText('Nested template says: Hi!', 'Initial render works'); this.runTask(function () { return _this2.rerender(); }); this.assertText('Nested template says: Hi!', 'Re-render works'); }; _class.prototype['@test tagless blockless component can lookup local template'] = function () { var _this3 = this; this.registerComponent('x-outer/x-inner', { template: 'Nested template says: {{yield}}' }); this.registerTemplate('components/x-outer', '{{#x-inner}}Hi!{{/x-inner}}'); this.registerComponent('x-outer', { ComponentClass: _helpers.Component.extend({ tagName: '' }) }); this.render('{{x-outer}}'); this.assertText('Nested template says: Hi!', 'Re-render works'); this.runTask(function () { return _this3.rerender(); }); this.assertText('Nested template says: Hi!', 'Re-render works'); }; _class.prototype['@test it can lookup a local component template'] = function () { var _this4 = this; this.registerTemplate('components/x-outer/x-inner', 'Nested template says: {{yield}}'); this.registerTemplate('components/x-outer', '{{#x-inner}}Hi!{{/x-inner}}'); this.render('{{x-outer}}'); this.assertText('Nested template says: Hi!', 'Initial render works'); this.runTask(function () { return _this4.rerender(); }); this.assertText('Nested template says: Hi!', 'Re-render works'); }; _class.prototype['@test it can local lookup a dynamic component'] = function () { var _this5 = this; this.registerComponent('foo-bar', { template: 'yall finished {{component child}}' }); this.registerComponent('foo-bar/biz-baz', { template: 'or yall done?' }); this.render('{{foo-bar child=child}}', { child: 'biz-baz' }); this.assertText('yall finished or yall done?'); this.runTask(function () { return _this5.rerender(); }); this.assertText('yall finished or yall done?'); }; _class.prototype['@test it can local lookup a dynamic component from a dynamic component'] = function () { var _this6 = this; this.registerComponent('foo-bar', { template: 'yall finished {{component child}}' }); this.registerComponent('foo-bar/biz-baz', { template: 'or yall done?' }); this.render('{{component componentName child=child}}', { componentName: 'foo-bar', child: 'biz-baz' }); this.assertText('yall finished or yall done?'); this.runTask(function () { return _this6.rerender(); }); this.assertText('yall finished or yall done?'); }; _class.prototype['@test it can local lookup a dynamic component from a passed named argument'] = function () { var _this7 = this; this.registerComponent('parent-foo', { template: 'yall finished {{global-biz baz=(component \'local-bar\')}}' }); this.registerComponent('global-biz', { template: 'or {{component baz}}' }); this.registerComponent('parent-foo/local-bar', { template: 'yall done?' }); this.render('{{parent-foo}}'); this.assertText('yall finished or yall done?'); this.runTask(function () { return _this7.rerender(); }); this.assertText('yall finished or yall done?'); }; _class.prototype['@test it can local lookup a re-wrapped dynamic component from a passed named argument'] = function () { var _this8 = this; this.registerComponent('parent-foo', { template: 'yall finished {{global-x comp=(component \'local-bar\')}}' }); this.registerComponent('global-x', { template: 'or {{global-y comp=(component comp phrase=\'done\')}}' }); this.registerComponent('global-y', { template: '{{component comp}}?' }); this.registerComponent('parent-foo/local-bar', { template: 'yall {{phrase}}' }); this.render('{{parent-foo}}'); this.assertText('yall finished or yall done?'); this.runTask(function () { return _this8.rerender(); }); this.assertText('yall finished or yall done?'); }; _class.prototype['@test it can nest local lookups of dynamic components from a passed named argument'] = function () { var _this9 = this; this.registerComponent('parent-foo', { template: 'yall finished {{global-x comp=(component \'local-bar\')}}' }); this.registerComponent('global-x', { template: 'or {{global-y comp=(component comp phrase=\'done\')}}' }); this.registerComponent('global-y', { template: '{{component comp}}{{component \'local-bar\'}}' }); this.registerComponent('parent-foo/local-bar', { template: 'yall {{phrase}}' }); this.registerComponent('global-y/local-bar', { template: '?' }); this.render('{{parent-foo}}'); this.assertText('yall finished or yall done?'); this.runTask(function () { return _this9.rerender(); }); this.assertText('yall finished or yall done?'); }; _class.prototype['@test it can switch from local to global lookups of dynamic components from a passed named argument'] = function () { var _this10 = this; this.registerComponent('parent-foo', { template: 'yall finished {{global-x comp=(component bar)}}' }); this.registerComponent('global-x', { template: 'or yall {{component comp}}' }); this.registerComponent('parent-foo/local-bar', { template: 'done?' }); this.registerComponent('global-bar', { template: 'ready?' }); this.render('{{parent-foo bar=bar}}', { bar: 'local-bar' }); this.assertText('yall finished or yall done?'); this.runTask(function () { return _this10.context.set('bar', 'global-bar'); }); this.runTask(function () { return _this10.rerender(); }); this.assertText('yall finished or yall ready?'); }; _class.prototype['@test it can lookup a local helper'] = function () { var _this11 = this; this.registerHelper('x-outer/x-helper', function () { return 'Who dis?'; }); this.registerComponent('x-outer', { template: 'Who dat? {{x-helper}}' }); this.render('{{x-outer}}'); this.assertText('Who dat? Who dis?', 'Initial render works'); this.runTask(function () { return _this11.rerender(); }); this.assertText('Who dat? Who dis?', 'Re-render works'); }; _class.prototype['@test it overrides global helper lookup'] = function () { var _this12 = this; this.registerHelper('x-outer/x-helper', function () { return 'Who dis?'; }); this.registerHelper('x-helper', function () { return 'I dunno'; }); this.registerComponent('x-outer', { template: 'Who dat? {{x-helper}}' }); this.render('{{x-outer}} {{x-helper}}'); this.assertText('Who dat? Who dis? I dunno', 'Initial render works'); this.runTask(function () { return _this12.rerender(); }); this.assertText('Who dat? Who dis? I dunno', 'Re-render works'); }; _class.prototype['@test lookup without match issues standard assertion (with local helper name)'] = function () { var _this13 = this; this.registerComponent('x-outer', { template: '{{#x-inner}}Hi!{{/x-inner}}' }); expectAssertion(function () { _this13.render('{{x-outer}}'); }, /A component or helper named "x-inner" could not be found/); }; _class.prototype['@test overrides global lookup'] = function () { var _this14 = this; this.registerComponent('x-outer', { template: '{{#x-inner}}Hi!{{/x-inner}}' }); this.registerComponent('x-outer/x-inner', { template: 'Nested template says (from local): {{yield}}' }); this.registerComponent('x-inner', { template: 'Nested template says (from global): {{yield}}' }); this.render('{{#x-inner}}Hi!{{/x-inner}} {{x-outer}} {{#x-outer/x-inner}}Hi!{{/x-outer/x-inner}}'); this.assertText('Nested template says (from global): Hi! Nested template says (from local): Hi! Nested template says (from local): Hi!'); this.runTask(function () { return _this14.rerender(); }); this.assertText('Nested template says (from global): Hi! Nested template says (from local): Hi! Nested template says (from local): Hi!'); }; return _class; }(_testCase.RenderingTest)); }); enifed("ember-glimmer/tests/integration/components/render-to-element-test", [], function () { "use strict"; }); enifed('ember-glimmer/tests/integration/components/target-action-test', ['ember-babel', 'ember-utils', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-metal', 'ember-glimmer/tests/utils/helpers', 'ember-runtime', 'ember-routing'], function (_emberBabel, _emberUtils, _testCase, _abstractTestCase, _emberMetal, _helpers, _emberRuntime, _emberRouting) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#component-a}}\n {{component-b bar="derp"}}\n {{/component-a}}\n '], ['\n {{#component-a}}\n {{component-b bar="derp"}}\n {{/component-a}}\n ']); (0, _testCase.moduleFor)('Components test: sendAction', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this)); _this.actionCounts = {}; _this.sendCount = 0; _this.actionArguments = null; _this.registerComponent('action-delegate', { ComponentClass: _helpers.Component.extend({ init: function () { this._super(); _this.delegate = this; this.name = 'action-delegate'; } }) }); return _this; } _class.prototype.renderDelegate = function () { var template = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '{{action-delegate}}'; var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var root = this; context = (0, _emberUtils.assign)(context, { send: function (actionName) { var _len, args, _key; root.sendCount++; root.actionCounts[actionName] = root.actionCounts[actionName] || 0; root.actionCounts[actionName]++; for (_len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } root.actionArguments = args; } }); this.render(template, context); }; _class.prototype.assertSendCount = function (count) { this.assert.equal(this.sendCount, count, 'Send was called ' + count + ' time(s)'); }; _class.prototype.assertNamedSendCount = function (actionName, count) { this.assert.equal(this.actionCounts[actionName], count, 'An action named \'' + actionName + '\' was sent ' + count + ' times'); }; _class.prototype.assertSentWithArgs = function (expected) { var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'arguments were sent with the action'; this.assert.deepEqual(this.actionArguments, expected, message); }; _class.prototype['@test Calling sendAction on a component without an action defined does nothing'] = function () { var _this2 = this; this.renderDelegate(); this.runTask(function () { return _this2.delegate.sendAction(); }); this.assertSendCount(0); }; _class.prototype['@test Calling sendAction on a component with an action defined calls send on the controller'] = function () { var _this3 = this; this.renderDelegate(); this.runTask(function () { (0, _emberMetal.set)(_this3.delegate, 'action', 'addItem'); _this3.delegate.sendAction(); }); this.assertSendCount(1); this.assertNamedSendCount('addItem', 1); }; _class.prototype['@test Calling sendAction on a component with a function calls the function'] = function () { var _this4 = this; this.assert.expect(1); this.renderDelegate(); this.runTask(function () { (0, _emberMetal.set)(_this4.delegate, 'action', function () { return _this4.assert.ok(true, 'function is called'); }); _this4.delegate.sendAction(); }); }; _class.prototype['@test Calling sendAction on a component with a function calls the function with arguments'] = function () { var _this5 = this; this.assert.expect(1); var argument = {}; this.renderDelegate(); this.runTask(function () { (0, _emberMetal.set)(_this5.delegate, 'action', function (actualArgument) { _this5.assert.deepEqual(argument, actualArgument, 'argument is passed'); }); _this5.delegate.sendAction('action', argument); }); }; _class.prototype['@test Calling sendAction on a component with a reference attr calls the function with arguments'] = function () { var _this6 = this; this.renderDelegate('{{action-delegate playing=playing}}', { playing: null }); this.runTask(function () { return _this6.delegate.sendAction(); }); this.assertSendCount(0); this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'playing', 'didStartPlaying'); }); this.runTask(function () { _this6.delegate.sendAction('playing'); }); this.assertSendCount(1); this.assertNamedSendCount('didStartPlaying', 1); }; _class.prototype['@test Calling sendAction on a component with a {{mut}} attr calls the function with arguments'] = function () { var _this7 = this; this.renderDelegate('{{action-delegate playing=(mut playing)}}', { playing: null }); this.runTask(function () { return _this7.delegate.sendAction('playing'); }); this.assertSendCount(0); this.runTask(function () { return _this7.delegate.attrs.playing.update('didStartPlaying'); }); this.runTask(function () { return _this7.delegate.sendAction('playing'); }); this.assertSendCount(1); this.assertNamedSendCount('didStartPlaying', 1); }; _class.prototype['@test Calling sendAction with a named action uses the component\'s property as the action name'] = function () { var _this8 = this; this.renderDelegate(); var component = this.delegate; this.runTask(function () { (0, _emberMetal.set)(_this8.delegate, 'playing', 'didStartPlaying'); component.sendAction('playing'); }); this.assertSendCount(1); this.assertNamedSendCount('didStartPlaying', 1); this.runTask(function () { return component.sendAction('playing'); }); this.assertSendCount(2); this.assertNamedSendCount('didStartPlaying', 2); this.runTask(function () { (0, _emberMetal.set)(component, 'action', 'didDoSomeBusiness'); component.sendAction(); }); this.assertSendCount(3); this.assertNamedSendCount('didDoSomeBusiness', 1); }; _class.prototype['@test Calling sendAction when the action name is not a string raises an exception'] = function () { var _this9 = this; this.renderDelegate(); this.runTask(function () { (0, _emberMetal.set)(_this9.delegate, 'action', {}); (0, _emberMetal.set)(_this9.delegate, 'playing', {}); }); expectAssertion(function () { return _this9.delegate.sendAction(); }); expectAssertion(function () { return _this9.delegate.sendAction('playing'); }); }; _class.prototype['@test Calling sendAction on a component with contexts'] = function () { var _this10 = this; this.renderDelegate(); var testContext = { song: 'She Broke My Ember' }; var firstContext = { song: 'She Broke My Ember' }; var secondContext = { song: 'My Achey Breaky Ember' }; this.runTask(function () { (0, _emberMetal.set)(_this10.delegate, 'playing', 'didStartPlaying'); _this10.delegate.sendAction('playing', testContext); }); this.assertSendCount(1); this.assertNamedSendCount('didStartPlaying', 1); this.assertSentWithArgs([testContext], 'context was sent with the action'); this.runTask(function () { _this10.delegate.sendAction('playing', firstContext, secondContext); }); this.assertSendCount(2); this.assertNamedSendCount('didStartPlaying', 2); this.assertSentWithArgs([firstContext, secondContext], 'multiple contexts were sent to the action'); }; _class.prototype['@test calling sendAction on a component within a block sends to the outer scope GH#14216'] = function (assert) { var testContext = this; // overrides default action-delegate so actions can be added this.registerComponent('action-delegate', { ComponentClass: _helpers.Component.extend({ init: function () { this._super(); testContext.delegate = this; this.name = 'action-delegate'; }, actions: { derp: function (arg1) { assert.ok(true, 'action called on action-delgate'); assert.equal(arg1, 'something special', 'argument passed through properly'); } } }), template: (0, _abstractTestCase.strip)(_templateObject) }); this.registerComponent('component-a', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); this.name = 'component-a'; }, actions: { derp: function () { assert.ok(false, 'no! bad scoping!'); } } }) }); var innerChild = void 0; this.registerComponent('component-b', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerChild = this; this.name = 'component-b'; } }) }); this.renderDelegate(); this.runTask(function () { return innerChild.sendAction('bar', 'something special'); }); }; return _class; }(_testCase.RenderingTest)); (0, _testCase.moduleFor)('Components test: sendAction to a controller', function (_ApplicationTest) { (0, _emberBabel.inherits)(_class2, _ApplicationTest); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTest.apply(this, arguments)); } _class2.prototype['@test sendAction should trigger an action on the parent component\'s controller if it exists'] = function (assert) { var _this12 = this; assert.expect(15); var component = void 0; this.router.map(function () { this.route('a'); this.route('b'); this.route('c', function () { this.route('d'); this.route('e'); }); }); this.addComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; } }), template: '{{val}}' }); this.add('controller:a', _emberRuntime.Controller.extend({ send: function (actionName, actionContext) { assert.equal(actionName, 'poke', 'send() method was invoked from a top level controller'); assert.equal(actionContext, 'top', 'action arguments were passed into the top level controller'); } })); this.addTemplate('a', '{{foo-bar val="a" poke="poke"}}'); this.add('route:b', _emberRouting.Route.extend({ actions: { poke: function (actionContext) { assert.ok(true, 'Unhandled action sent to route'); assert.equal(actionContext, 'top no controller'); } } })); this.addTemplate('b', '{{foo-bar val="b" poke="poke"}}'); this.add('route:c', _emberRouting.Route.extend({ actions: { poke: function (actionContext) { assert.ok(true, 'Unhandled action sent to route'); assert.equal(actionContext, 'top with nested no controller'); } } })); this.addTemplate('c', '{{foo-bar val="c" poke="poke"}}{{outlet}}'); this.add('route:c.d', _emberRouting.Route.extend({})); this.add('controller:c.d', _emberRuntime.Controller.extend({ send: function (actionName, actionContext) { assert.equal(actionName, 'poke', 'send() method was invoked from a nested controller'); assert.equal(actionContext, 'nested', 'action arguments were passed into the nested controller'); } })); this.addTemplate('c.d', '{{foo-bar val=".d" poke="poke"}}'); this.add('route:c.e', _emberRouting.Route.extend({ actions: { poke: function (actionContext) { assert.ok(true, 'Unhandled action sent to route'); assert.equal(actionContext, 'nested no controller'); } } })); this.addTemplate('c.e', '{{foo-bar val=".e" poke="poke"}}'); return this.visit('/a').then(function () { return component.sendAction('poke', 'top'); }).then(function () { _this12.assertText('a'); return _this12.visit('/b'); }).then(function () { return component.sendAction('poke', 'top no controller'); }).then(function () { _this12.assertText('b'); return _this12.visit('/c'); }).then(function () { return component.sendAction('poke', 'top with nested no controller'); }).then(function () { _this12.assertText('c'); return _this12.visit('/c/d'); }).then(function () { return component.sendAction('poke', 'nested'); }).then(function () { _this12.assertText('c.d'); return _this12.visit('/c/e'); }).then(function () { return component.sendAction('poke', 'nested no controller'); }).then(function () { return _this12.assertText('c.e'); }); }; _class2.prototype['@test sendAction should not trigger an action in an outlet\'s controller if a parent component handles it'] = function (assert) { assert.expect(1); var component = void 0; this.addComponent('x-parent', { ComponentClass: _helpers.Component.extend({ actions: { poke: function () { assert.ok(true, 'parent component handled the aciton'); } } }), template: '{{x-child poke="poke"}}' }); this.addComponent('x-child', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; } }) }); this.addTemplate('application', '{{x-parent}}'); this.add('controller:application', _emberRuntime.Controller.extend({ send: function () { throw new Error('controller action should not be called'); } })); return this.visit('/').then(function () { return component.sendAction('poke'); }); }; return _class2; }(_testCase.ApplicationTest)); (0, _testCase.moduleFor)('Components test: sendAction of a closure action', function (_RenderingTest2) { (0, _emberBabel.inherits)(_class3, _RenderingTest2); function _class3() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments)); } _class3.prototype['@test action should be called'] = function (assert) { assert.expect(1); var component = void 0; this.registerComponent('inner-component', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; } }), template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: _helpers.Component.extend({ outerSubmit: function () { assert.ok(true, 'outerSubmit called'); } }), template: '{{inner-component submitAction=(action outerSubmit)}}' }); this.render('{{outer-component}}'); this.runTask(function () { return component.sendAction('submitAction'); }); }; _class3.prototype['@test contexts passed to sendAction are appended to the bound arguments on a closure action'] = function () { var first = 'mitch'; var second = 'martin'; var third = 'matt'; var fourth = 'wacky wycats'; var innerComponent = void 0; var actualArgs = void 0; this.registerComponent('inner-component', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; } }), template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: _helpers.Component.extend({ third: third, actions: { outerSubmit: function () { actualArgs = [].concat(Array.prototype.slice.call(arguments)); } } }), template: '{{inner-component innerSubmit=(action (action "outerSubmit" "' + first + '") "' + second + '" third)}}' }); this.render('{{outer-component}}'); this.runTask(function () { return innerComponent.sendAction('innerSubmit', fourth); }); this.assert.deepEqual(actualArgs, [first, second, third, fourth], 'action has the correct args'); }; return _class3; }(_testCase.RenderingTest)); (0, _testCase.moduleFor)('Components test: send', function (_RenderingTest3) { (0, _emberBabel.inherits)(_class4, _RenderingTest3); function _class4() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest3.apply(this, arguments)); } _class4.prototype['@test sending to undefined actions triggers an error'] = function (assert) { assert.expect(2); var component = void 0; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ init: function () { this._super(); component = this; }, actions: { foo: function (message) { assert.equal('bar', message); } } }) }); this.render('{{foo-bar}}'); this.runTask(function () { return component.send('foo', 'bar'); }); expectAssertion(function () { return component.send('baz', 'bar'); }, /had no action handler for: baz/); }; _class4.prototype['@test `send` will call send from a target if it is defined'] = function () { var _this15 = this; var component = void 0; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ init: function () { this._super(); component = this; }, target: { send: function (message, payload) { _this15.assert.equal('foo', message); _this15.assert.equal('baz', payload); } } }) }); this.render('{{foo-bar}}'); this.runTask(function () { return component.send('foo', 'baz'); }); }; _class4.prototype['@test a handled action can be bubbled to the target for continued processing'] = function () { var _this16 = this; this.assert.expect(2); var component = void 0; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, actions: { poke: function () { _this16.assert.ok(true, 'component action called'); return true; } }, target: _emberRuntime.Controller.extend({ actions: { poke: function () { _this16.assert.ok(true, 'action bubbled to controller'); } } }).create() }) }); this.render('{{foo-bar poke="poke"}}'); this.runTask(function () { return component.send('poke'); }); }; _class4.prototype['@test action can be handled by a superclass\' actions object'] = function (assert) { this.assert.expect(4); var component = void 0; var SuperComponent = _helpers.Component.extend({ actions: { foo: function () { assert.ok(true, 'foo'); }, bar: function (msg) { assert.equal(msg, 'HELLO'); } } }); var BarViewMixin = _emberMetal.Mixin.create({ actions: { bar: function (msg) { assert.equal(msg, 'HELLO'); this._super(msg); } } }); this.registerComponent('x-index', { ComponentClass: SuperComponent.extend(BarViewMixin, { init: function () { this._super.apply(this, arguments); component = this; }, actions: { baz: function () { assert.ok(true, 'baz'); } } }) }); this.render('{{x-index}}'); this.runTask(function () { component.send('foo'); component.send('bar', 'HELLO'); component.send('baz'); }); }; _class4.prototype['@test actions cannot be provided at create time'] = function (assert) { expectAssertion(function () { return _helpers.Component.create({ actions: { foo: function () { assert.ok(true, 'foo'); } } }); }); // but should be OK on an object that doesn't mix in Ember.ActionHandler _emberRuntime.Object.create({ actions: ['foo'] }); }; return _class4; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/utils-test', ['ember-babel', 'ember-runtime', 'ember-views', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers'], function (_emberBabel, _emberRuntime, _emberViews, _testCase, _helpers) { 'use strict'; (0, _testCase.moduleFor)('View tree tests', function (_ApplicationTest) { (0, _emberBabel.inherits)(_class, _ApplicationTest); function _class() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTest.call(this)); _this.addComponent('x-tagless', { ComponentClass: _helpers.Component.extend({ tagName: '' }), template: '
[{{id}}] {{#if isShowing}}{{yield}}{{/if}}
' }); _this.addComponent('x-toggle', { ComponentClass: _helpers.Component.extend({ isExpanded: true, click: function () { this.toggleProperty('isExpanded'); return false; } }), template: '[{{id}}] {{#if isExpanded}}{{yield}}{{/if}}' }); var ToggleController = _emberRuntime.Controller.extend({ isExpanded: true, actions: { toggle: function () { this.toggleProperty('isExpanded'); } } }); _this.add('controller:application', ToggleController); _this.addTemplate('application', '\n {{x-tagless id="root-1"}}\n\n {{#x-toggle id="root-2"}}\n {{x-toggle id="inner-1"}}\n\n {{#x-toggle id="inner-2"}}\n {{x-toggle id="inner-3"}}\n {{/x-toggle}}\n {{/x-toggle}}\n\n \n\n {{#if isExpanded}}\n {{x-toggle id="root-3"}}\n {{/if}}\n\n {{outlet}}\n '); _this.add('controller:index', ToggleController.extend({ isExpanded: false })); _this.addTemplate('index', '\n {{x-tagless id="root-4"}}\n\n {{#x-toggle id="root-5" isExpanded=false}}\n {{x-toggle id="inner-4"}}\n\n {{#x-toggle id="inner-5"}}\n {{x-toggle id="inner-6"}}\n {{/x-toggle}}\n {{/x-toggle}}\n\n \n\n {{#if isExpanded}}\n {{x-toggle id="root-6"}}\n {{/if}}\n '); _this.addTemplate('zomg', '\n {{x-tagless id="root-7"}}\n\n {{#x-toggle id="root-8"}}\n {{x-toggle id="inner-7"}}\n\n {{#x-toggle id="inner-8"}}\n {{x-toggle id="inner-9"}}\n {{/x-toggle}}\n {{/x-toggle}}\n\n {{#x-toggle id="root-9"}}\n {{outlet}}\n {{/x-toggle}}\n '); _this.addTemplate('zomg.lol', '\n {{x-toggle id="inner-10"}}\n '); _this.router.map(function () { this.route('zomg', function () { this.route('lol'); }); }); return _this; } _class.prototype['@test getRootViews'] = function () { var _this2 = this; return this.visit('/').then(function () { _this2.assertRootViews(['root-1', 'root-2', 'root-3', 'root-4', 'root-5']); _this2.runTask(function () { return (0, _emberViews.jQuery)('#toggle-application').click(); }); _this2.assertRootViews(['root-1', 'root-2', 'root-4', 'root-5']); _this2.runTask(function () { (0, _emberViews.jQuery)('#toggle-application').click(); (0, _emberViews.jQuery)('#toggle-index').click(); }); _this2.assertRootViews(['root-1', 'root-2', 'root-3', 'root-4', 'root-5', 'root-6']); return _this2.visit('/zomg/lol'); }).then(function () { _this2.assertRootViews(['root-1', 'root-2', 'root-3', 'root-7', 'root-8', 'root-9']); return _this2.visit('/'); }).then(function () { _this2.assertRootViews(['root-1', 'root-2', 'root-3', 'root-4', 'root-5', 'root-6']); }); }; _class.prototype.assertRootViews = function (ids) { var owner = this.applicationInstance; var actual = (0, _emberViews.getRootViews)(owner).map(function (view) { return view.id; }).sort(); var expected = ids.sort(); this.assert.deepEqual(actual, expected, 'root views'); }; _class.prototype['@test getChildViews'] = function () { var _this3 = this; return this.visit('/').then(function () { _this3.assertChildViews('root-2', ['inner-1', 'inner-2']); _this3.assertChildViews('root-5', []); _this3.assertChildViews('inner-2', ['inner-3']); _this3.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this3.assertChildViews('root-2', []); _this3.runTask(function () { return (0, _emberViews.jQuery)('#root-5').click(); }); _this3.assertChildViews('root-5', ['inner-4', 'inner-5']); _this3.assertChildViews('inner-5', ['inner-6']); return _this3.visit('/zomg'); }).then(function () { _this3.assertChildViews('root-2', []); _this3.assertChildViews('root-8', ['inner-7', 'inner-8']); _this3.assertChildViews('inner-8', ['inner-9']); _this3.assertChildViews('root-9', []); _this3.runTask(function () { return (0, _emberViews.jQuery)('#root-8').click(); }); _this3.assertChildViews('root-8', []); return _this3.visit('/zomg/lol'); }).then(function () { _this3.assertChildViews('root-2', []); _this3.assertChildViews('root-8', []); _this3.assertChildViews('root-9', ['inner-10']); return _this3.visit('/'); }).then(function () { _this3.assertChildViews('root-2', []); _this3.assertChildViews('root-5', []); _this3.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this3.runTask(function () { return (0, _emberViews.jQuery)('#inner-2').click(); }); _this3.assertChildViews('root-2', ['inner-1', 'inner-2']); _this3.assertChildViews('inner-2', []); }); }; _class.prototype['@test getChildViews does not return duplicates'] = function () { var _this4 = this; return this.visit('/').then(function () { _this4.assertChildViews('root-2', ['inner-1', 'inner-2']); _this4.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this4.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this4.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this4.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this4.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this4.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this4.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this4.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this4.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this4.runTask(function () { return (0, _emberViews.jQuery)('#root-2').click(); }); _this4.assertChildViews('root-2', ['inner-1', 'inner-2']); }); }; _class.prototype.assertChildViews = function (parentId, childIds) { var parentView = this.viewFor(parentId); var childViews = (0, _emberViews.getChildViews)(parentView); var actual = childViews.map(function (view) { return view.id; }).sort(); var expected = childIds.sort(); this.assert.deepEqual(actual, expected, 'child views for #' + parentId); }; _class.prototype.viewFor = function (id) { var owner = this.applicationInstance; var registry = owner.lookup('-view-registry:main'); return registry[id]; }; return _class; }(_testCase.ApplicationTest)); var hasGetClientRects = void 0, hasGetBoundingClientRect = void 0; var ClientRectListCtor = void 0, ClientRectCtor = void 0; (function () { var range, clientRectsList, clientRect; if (document.createRange) { range = document.createRange(); if (range.getClientRects) { clientRectsList = range.getClientRects(); hasGetClientRects = true; ClientRectListCtor = clientRectsList && clientRectsList.constructor; } if (range.getBoundingClientRect) { clientRect = range.getBoundingClientRect(); hasGetBoundingClientRect = true; ClientRectCtor = clientRect && clientRect.constructor; } } })(); (0, _testCase.moduleFor)('Bounds tests', function (_RenderingTest) { (0, _emberBabel.inherits)(_class2, _RenderingTest); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class2.prototype['@test getViewBounds on a regular component'] = function (assert) { var component = void 0; this.registerComponent('hi-mom', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; } }), template: '

Hi, mom!

' }); this.render('{{hi-mom}}'); var _getViewBounds = (0, _emberViews.getViewBounds)(component), parentElement = _getViewBounds.parentElement, firstNode = _getViewBounds.firstNode, lastNode = _getViewBounds.lastNode; assert.equal(parentElement, this.element, 'a regular component should have the right parentElement'); assert.equal(firstNode, component.element, 'a regular component should have a single node that is its element'); assert.equal(lastNode, component.element, 'a regular component should have a single node that is its element'); }; _class2.prototype['@test getViewBounds on a tagless component'] = function (assert) { var component = void 0; this.registerComponent('hi-mom', { ComponentClass: _helpers.Component.extend({ tagName: '', init: function () { this._super.apply(this, arguments); component = this; } }), template: 'Hi, mom!' }); this.render('{{hi-mom}}'); var _getViewBounds2 = (0, _emberViews.getViewBounds)(component), parentElement = _getViewBounds2.parentElement, firstNode = _getViewBounds2.firstNode, lastNode = _getViewBounds2.lastNode; assert.equal(parentElement, this.element, 'a tagless component should have the right parentElement'); assert.equal(firstNode, this.$('#start-node')[0], 'a tagless component should have a range enclosing all of its nodes'); assert.equal(lastNode, this.$('#before-end-node')[0].nextSibling, 'a tagless component should have a range enclosing all of its nodes'); }; _class2.prototype['@test getViewClientRects'] = function (assert) { if (!hasGetClientRects || !ClientRectListCtor) { assert.ok(true, 'The test environment does not support the DOM API required to run this test.'); return; } var component = void 0; this.registerComponent('hi-mom', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; } }), template: '

Hi, mom!

' }); this.render('{{hi-mom}}'); assert.ok((0, _emberViews.getViewClientRects)(component) instanceof ClientRectListCtor); }; _class2.prototype['@test getViewBoundingClientRect'] = function (assert) { if (!hasGetBoundingClientRect || !ClientRectCtor) { assert.ok(true, 'The test environment does not support the DOM API required to run this test.'); return; } var component = void 0; this.registerComponent('hi-mom', { ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; } }), template: '

Hi, mom!

' }); this.render('{{hi-mom}}'); assert.ok((0, _emberViews.getViewBoundingClientRect)(component) instanceof ClientRectCtor); }; return _class2; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/web-component-fallback-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal'], function (_emberBabel, _testCase, _emberMetal) { 'use strict'; (0, _testCase.moduleFor)('Components test: web component fallback', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test custom elements are rendered'] = function () { var template = 'hello'; this.render(template); this.assertHTML(template); this.assertStableRerender(); }; _class.prototype['@test custom elements can have bound attributes'] = function () { var _this2 = this; this.render('hello', { name: 'Robert' }); this.assertHTML('hello'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'name', 'Kris'); }); this.assertHTML('hello'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'name', 'Robert'); }); this.assertHTML('hello'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/components/will-destroy-element-hook-test', ['ember-babel', 'ember-metal', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/test-case'], function (_emberBabel, _emberMetal, _helpers, _testCase) { 'use strict'; (0, _testCase.moduleFor)('Component willDestroyElement hook', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test it calls willDestroyElement when removed by if'] = function (assert) { var _this2 = this; var didInsertElementCount = 0; var willDestroyElementCount = 0; var FooBarComponent = _helpers.Component.extend({ didInsertElement: function () { didInsertElementCount++; assert.notEqual(this.element.parentNode, null, 'precond component is in DOM'); }, willDestroyElement: function () { willDestroyElementCount++; assert.notEqual(this.element.parentNode, null, 'has not been removed from DOM yet'); } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); this.render('{{#if switch}}{{foo-bar}}{{/if}}', { switch: true }); assert.equal(didInsertElementCount, 1, 'didInsertElement was called once'); this.assertComponentElement(this.firstChild, { content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'switch', false); }); assert.equal(willDestroyElementCount, 1, 'willDestroyElement was called once'); this.assertText(''); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/content-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-metal', 'ember-debug', 'ember-runtime', 'ember-glimmer/tests/utils/test-helpers', 'ember-views', 'ember-glimmer/tests/utils/helpers'], function (_emberBabel, _testCase, _abstractTestCase, _emberMetal, _emberDebug, _emberRuntime, _testHelpers, _emberViews, _helpers) { 'use strict'; /* globals EmberDev */ (0, _testCase.moduleFor)('Static content tests', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test it can render a static text node'] = function () { var _this2 = this; this.render('hello'); var text1 = this.assertTextNode(this.firstChild, 'hello'); this.runTask(function () { return _this2.rerender(); }); var text2 = this.assertTextNode(this.firstChild, 'hello'); this.assertSameNode(text1, text2); }; _class.prototype['@test it can render a static element'] = function () { var _this3 = this; this.render('

hello

'); var p1 = this.assertElement(this.firstChild, { tagName: 'p' }); var text1 = this.assertTextNode(this.firstChild.firstChild, 'hello'); this.runTask(function () { return _this3.rerender(); }); var p2 = this.assertElement(this.firstChild, { tagName: 'p' }); var text2 = this.assertTextNode(this.firstChild.firstChild, 'hello'); this.assertSameNode(p1, p2); this.assertSameNode(text1, text2); }; _class.prototype['@test it can render a static template'] = function () { var _this4 = this; var template = '\n
\n

Welcome to Ember.js

\n
\n
\n

Why you should use Ember.js?

\n
    \n
  1. It\'s great
  2. \n
  3. It\'s awesome
  4. \n
  5. It\'s Ember.js
  6. \n
\n
\n \n '; this.render(template); this.assertHTML(template); this.runTask(function () { return _this4.rerender(); }); this.assertHTML(template); }; return _class; }(_testCase.RenderingTest)); var DynamicContentTest = function (_RenderingTest2) { (0, _emberBabel.inherits)(DynamicContentTest, _RenderingTest2); function DynamicContentTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments)); } DynamicContentTest.prototype.renderPath = function () { arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; throw new Error('Not implemented: `renderValues`'); }; DynamicContentTest.prototype.assertIsEmpty = function () { this.assert.strictEqual(this.firstChild, null); }; DynamicContentTest.prototype.assertContent = function () { throw new Error('Not implemented: `assertContent`'); }; DynamicContentTest.prototype['@test it can render a dynamic path'] = function () { var _this6 = this; this.renderPath('message', { message: 'hello' }); this.assertContent('hello'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'message', 'goodbye'); }); this.assertContent('goodbye'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'message', 'hello'); }); this.assertContent('hello'); this.assertInvariants(); }; DynamicContentTest.prototype['@test resolves the string length properly'] = function () { var _this7 = this; this.render('

{{foo.length}}

', { foo: undefined }); this.assertHTML('

'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'foo', 'foo'); }); this.assertHTML('

3

'); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'foo', ''); }); this.assertHTML('

0

'); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'foo', undefined); }); this.assertHTML('

'); }; DynamicContentTest.prototype['@test resolves the array length properly'] = function () { var _this8 = this; this.render('

{{foo.length}}

', { foo: undefined }); this.assertHTML('

'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'foo', [1, 2, 3]); }); this.assertHTML('

3

'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'foo', []); }); this.assertHTML('

0

'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'foo', undefined); }); this.assertHTML('

'); }; DynamicContentTest.prototype['@test it can render a capitalized path with no deprecation'] = function () { var _this9 = this; expectNoDeprecation(); this.renderPath('CaptializedPath', { CaptializedPath: 'no deprecation' }); this.assertContent('no deprecation'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'CaptializedPath', 'still no deprecation'); }); this.assertContent('still no deprecation'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'CaptializedPath', 'no deprecation'); }); this.assertContent('no deprecation'); this.assertInvariants(); }; DynamicContentTest.prototype['@test it can render undefined dynamic paths'] = function () { var _this10 = this; this.renderPath('name', {}); this.assertIsEmpty(); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'name', 'foo-bar'); }); this.assertContent('foo-bar'); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'name', undefined); }); this.assertIsEmpty(); }; DynamicContentTest.prototype['@test it can render a deeply nested dynamic path'] = function () { var _this11 = this; this.renderPath('a.b.c.d.e.f', { a: { b: { c: { d: { e: { f: 'hello' } } } } } }); this.assertContent('hello'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'a.b.c.d.e.f', 'goodbye'); }); this.assertContent('goodbye'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'a.b.c.d', { e: { f: 'aloha' } }); }); this.assertContent('aloha'); this.assertInvariants(); this.runTask(function () { (0, _emberMetal.set)(_this11.context, 'a', { b: { c: { d: { e: { f: 'hello' } } } } }); }); this.assertContent('hello'); this.assertInvariants(); }; DynamicContentTest.prototype['@test it can render a computed property'] = function () { var _this12 = this; var Formatter = _emberRuntime.Object.extend({ formattedMessage: (0, _emberMetal.computed)('message', function () { return this.get('message').toUpperCase(); }) }); var m = Formatter.create({ message: 'hello' }); this.renderPath('m.formattedMessage', { m: m }); this.assertContent('HELLO'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(m, 'message', 'goodbye'); }); this.assertContent('GOODBYE'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'm', Formatter.create({ message: 'hello' })); }); this.assertContent('HELLO'); this.assertInvariants(); }; DynamicContentTest.prototype['@test it can render a computed property with nested dependency'] = function () { var _this13 = this; var Formatter = _emberRuntime.Object.extend({ formattedMessage: (0, _emberMetal.computed)('messenger.message', function () { return this.get('messenger.message').toUpperCase(); }) }); var m = Formatter.create({ messenger: { message: 'hello' } }); this.renderPath('m.formattedMessage', { m: m }); this.assertContent('HELLO'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(m, 'messenger.message', 'goodbye'); }); this.assertContent('GOODBYE'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'm', Formatter.create({ messenger: { message: 'hello' } })); }); this.assertContent('HELLO'); this.assertInvariants(); }; DynamicContentTest.prototype['@test it can read from a proxy object'] = function () { var _this14 = this; this.renderPath('proxy.name', { proxy: _emberRuntime.ObjectProxy.create({ content: { name: 'Tom Dale' } }) }); this.assertContent('Tom Dale'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'proxy.content.name', 'Yehuda Katz'); }); this.assertContent('Yehuda Katz'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'proxy.content', { name: 'Godfrey Chan' }); }); this.assertContent('Godfrey Chan'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'proxy.name', 'Stefan Penner'); }); this.assertContent('Stefan Penner'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'proxy.content', null); }); this.assertIsEmpty(); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'proxy', _emberRuntime.ObjectProxy.create({ content: { name: 'Tom Dale' } })); }); this.assertContent('Tom Dale'); this.assertInvariants(); }; DynamicContentTest.prototype['@test it can read from a nested path in a proxy object'] = function () { var _this15 = this; this.renderPath('proxy.name.last', { proxy: _emberRuntime.ObjectProxy.create({ content: { name: { first: 'Tom', last: 'Dale' } } }) }); this.assertContent('Dale'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'proxy.content.name.last', 'Cruise'); }); this.assertContent('Cruise'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'proxy.content.name.first', 'Suri'); }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'proxy.content.name', { first: 'Yehuda', last: 'Katz' }); }); this.assertContent('Katz'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'proxy.content', { name: { first: 'Godfrey', last: 'Chan' } }); }); this.assertContent('Chan'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'proxy.name', { first: 'Stefan', last: 'Penner' }); }); this.assertContent('Penner'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'proxy', null); }); this.assertIsEmpty(); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'proxy', _emberRuntime.ObjectProxy.create({ content: { name: { first: 'Tom', last: 'Dale' } } })); }); this.assertContent('Dale'); this.assertInvariants(); }; DynamicContentTest.prototype['@test it can read from a path flipping between a proxy and a real object'] = function () { var _this16 = this; this.renderPath('proxyOrObject.name.last', { proxyOrObject: _emberRuntime.ObjectProxy.create({ content: { name: { first: 'Tom', last: 'Dale' } } }) }); this.assertContent('Dale'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'proxyOrObject', { name: { first: 'Tom', last: 'Dale' } }); }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'proxyOrObject.name.last', 'Cruise'); }); this.assertContent('Cruise'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'proxyOrObject.name.first', 'Suri'); }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'proxyOrObject', { name: { first: 'Yehuda', last: 'Katz' } }); }); this.assertContent('Katz'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'proxyOrObject', _emberRuntime.ObjectProxy.create({ content: { name: { first: 'Godfrey', last: 'Chan' } } })); }); this.assertContent('Chan'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'proxyOrObject.content.name', { first: 'Stefan', last: 'Penner' }); }); this.assertContent('Penner'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'proxyOrObject', null); }); this.assertIsEmpty(); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'proxyOrObject', _emberRuntime.ObjectProxy.create({ content: { name: { first: 'Tom', last: 'Dale' } } })); }); this.assertContent('Dale'); this.assertInvariants(); }; DynamicContentTest.prototype['@test it can read from a path flipping between a real object and a proxy'] = function () { var _this17 = this; this.renderPath('objectOrProxy.name.last', { objectOrProxy: { name: { first: 'Tom', last: 'Dale' } } }); this.assertContent('Dale'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'objectOrProxy', _emberRuntime.ObjectProxy.create({ content: { name: { first: 'Tom', last: 'Dale' } } })); }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'objectOrProxy.content.name.last', 'Cruise'); }); this.assertContent('Cruise'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'objectOrProxy.content.name.first', 'Suri'); }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'objectOrProxy.content', { name: { first: 'Yehuda', last: 'Katz' } }); }); this.assertContent('Katz'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'objectOrProxy', { name: { first: 'Godfrey', last: 'Chan' } }); }); this.assertContent('Chan'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'objectOrProxy.name', { first: 'Stefan', last: 'Penner' }); }); this.assertContent('Penner'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'objectOrProxy', null); }); this.assertIsEmpty(); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'objectOrProxy', { name: { first: 'Tom', last: 'Dale' } }); }); this.assertContent('Dale'); this.assertInvariants(); }; DynamicContentTest.prototype['@test it can read from a null object'] = function () { var _this18 = this; var nullObject = Object.create(null); nullObject['message'] = 'hello'; this.renderPath('nullObject.message', { nullObject: nullObject }); this.assertContent('hello'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(nullObject, 'message', 'goodbye'); }); this.assertContent('goodbye'); this.assertInvariants(); nullObject = Object.create(null); nullObject['message'] = 'hello'; this.runTask(function () { return (0, _emberMetal.set)(_this18.context, 'nullObject', nullObject); }); this.assertContent('hello'); this.assertInvariants(); }; DynamicContentTest.prototype['@test it can render a readOnly property of a path'] = function () { var _this19 = this; var Messenger = _emberRuntime.Object.extend({ message: _emberMetal.computed.readOnly('a.b.c') }); var messenger = Messenger.create({ a: { b: { c: 'hello' } } }); this.renderPath('messenger.message', { messenger: messenger }); this.assertContent('hello'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(messenger, 'a.b.c', 'hi'); }); this.assertContent('hi'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this19.context, 'messenger.a.b', { c: 'goodbye' }); }); this.assertContent('goodbye'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this19.context, 'messenger', { message: 'hello' }); }); this.assertContent('hello'); this.assertInvariants(); }; return DynamicContentTest; }(_testCase.RenderingTest); var EMPTY = {}; var ContentTestGenerator = function () { function ContentTestGenerator(cases) { var tag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '@test'; this.cases = cases; this.tag = tag; } ContentTestGenerator.prototype.generate = function (_ref) { var value = _ref[0], expected = _ref[1], label = _ref[2], _ref2, _ref3; var tag = this.tag; label = label || value; if (expected === EMPTY) { return _ref2 = {}, _ref2[tag + ' rendering ' + label] = function () { var _this20 = this; this.renderPath('value', { value: value }); this.assertIsEmpty(); this.runTask(function () { return (0, _emberMetal.set)(_this20.context, 'value', 'hello'); }); this.assertContent('hello'); this.runTask(function () { return (0, _emberMetal.set)(_this20.context, 'value', value); }); this.assertIsEmpty(); }, _ref2; } else { return _ref3 = {}, _ref3[tag + ' rendering ' + label] = function () { var _this21 = this; this.renderPath('value', { value: value }); this.assertContent(expected); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this21.context, 'value', 'hello'); }); this.assertContent('hello'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this21.context, 'value', value); }); this.assertContent(expected); this.assertInvariants(); }, _ref3; } }; return ContentTestGenerator; }(); var SharedContentTestCases = new ContentTestGenerator([['foo', 'foo'], [0, '0'], [-0, '0', '-0'], [1, '1'], [-1, '-1'], [0.0, '0', '0.0'], [0.5, '0.5'], [undefined, EMPTY], [null, EMPTY], [true, 'true'], [false, 'false'], [NaN, 'NaN'], [new Date(2000, 0, 1), String(new Date(2000, 0, 1)), 'a Date object'], [Infinity, 'Infinity'], [1 / -0, '-Infinity'], [{ foo: 'bar' }, '[object Object]', '{ foo: \'bar\' }'], [{ toString: function () { return 'foo'; } }, 'foo', 'an object with a custom toString function'], [{ valueOf: function () { return 1; } }, '[object Object]', 'an object with a custom valueOf function'], // Escaping tests ['MaxJames', 'MaxJames']]); var GlimmerContentTestCases = new ContentTestGenerator([[Object.create(null), EMPTY, 'an object with no toString']]); if (typeof Symbol !== 'undefined') { GlimmerContentTestCases.cases.push([Symbol('debug'), 'Symbol(debug)', 'a symbol']); } (0, _abstractTestCase.applyMixins)(DynamicContentTest, SharedContentTestCases, GlimmerContentTestCases); (0, _testCase.moduleFor)('Dynamic content tests (content position)', function (_DynamicContentTest) { (0, _emberBabel.inherits)(_class2, _DynamicContentTest); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _DynamicContentTest.apply(this, arguments)); } _class2.prototype.renderPath = function (path) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; this.render('{{' + path + '}}', context); }; _class2.prototype.assertContent = function (content) { this.assert.strictEqual(this.nodesCount, 1, 'It should render exactly one text node'); this.assertTextNode(this.firstChild, content); }; return _class2; }(DynamicContentTest)); (0, _testCase.moduleFor)('Dynamic content tests (content concat)', function (_DynamicContentTest2) { (0, _emberBabel.inherits)(_class3, _DynamicContentTest2); function _class3() { return (0, _emberBabel.possibleConstructorReturn)(this, _DynamicContentTest2.apply(this, arguments)); } _class3.prototype.renderPath = function (path) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; this.render('{{concat "" ' + path + ' ""}}', context); }; _class3.prototype.assertContent = function (content) { this.assert.strictEqual(this.nodesCount, 1, 'It should render exactly one text node'); this.assertTextNode(this.firstChild, content); }; return _class3; }(DynamicContentTest)); (0, _testCase.moduleFor)('Dynamic content tests (inside an element)', function (_DynamicContentTest3) { (0, _emberBabel.inherits)(_class4, _DynamicContentTest3); function _class4() { return (0, _emberBabel.possibleConstructorReturn)(this, _DynamicContentTest3.apply(this, arguments)); } _class4.prototype.renderPath = function (path) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; this.render('

{{' + path + '}}

', context); }; _class4.prototype.assertIsEmpty = function () { this.assert.strictEqual(this.nodesCount, 1, 'It should render exactly one

tag'); this.assertElement(this.firstChild, { tagName: 'p' }); this.assertText(''); }; _class4.prototype.assertContent = function (content) { this.assert.strictEqual(this.nodesCount, 1, 'It should render exactly one

tag'); this.assertElement(this.firstChild, { tagName: 'p' }); this.assertText(content); }; return _class4; }(DynamicContentTest)); (0, _testCase.moduleFor)('Dynamic content tests (attribute position)', function (_DynamicContentTest4) { (0, _emberBabel.inherits)(_class5, _DynamicContentTest4); function _class5() { return (0, _emberBabel.possibleConstructorReturn)(this, _DynamicContentTest4.apply(this, arguments)); } _class5.prototype.renderPath = function (path) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; this.render('

', context); }; _class5.prototype.assertIsEmpty = function () { this.assert.strictEqual(this.nodesCount, 1, 'It should render exactly one
tag'); this.assertElement(this.firstChild, { tagName: 'div', content: '' }); }; _class5.prototype.assertContent = function (content) { this.assert.strictEqual(this.nodesCount, 1, 'It should render exactly one
tag'); this.assertElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo': content }, content: '' }); }; return _class5; }(DynamicContentTest)); var TrustedContentTest = function (_DynamicContentTest5) { (0, _emberBabel.inherits)(TrustedContentTest, _DynamicContentTest5); function TrustedContentTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _DynamicContentTest5.apply(this, arguments)); } TrustedContentTest.prototype.assertIsEmpty = function () { this.assert.strictEqual(this.firstChild, null); }; TrustedContentTest.prototype.assertContent = function (content) { this.assertHTML(content); }; TrustedContentTest.prototype.assertStableRerender = function () { var _this27 = this; this.takeSnapshot(); this.runTask(function () { return _this27.rerender(); }); _DynamicContentTest5.prototype.assertInvariants.call(this); }; TrustedContentTest.prototype.assertInvariants = function () { // If it's not stable, we will wipe out all the content and replace them, // so there are no invariants }; return TrustedContentTest; }(DynamicContentTest); (0, _testCase.moduleFor)('Dynamic content tests (trusted)', function (_TrustedContentTest) { (0, _emberBabel.inherits)(_class6, _TrustedContentTest); function _class6() { return (0, _emberBabel.possibleConstructorReturn)(this, _TrustedContentTest.apply(this, arguments)); } _class6.prototype.renderPath = function (path) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; this.render('{{{' + path + '}}}', context); }; _class6.prototype['@test updating trusted curlies'] = function () { var _this29 = this; this.render('{{{htmlContent}}}{{{nested.htmlContent}}}', { htmlContent: 'Max', nested: { htmlContent: 'James' } }); this.assertContent('MaxJames'); this.runTask(function () { return _this29.rerender(); }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this29.context, 'htmlContent', 'Max'); }); this.assertContent('MaxJames'); this.runTask(function () { return (0, _emberMetal.set)(_this29.context, 'nested.htmlContent', 'Jammie'); }); this.assertContent('MaxJammie'); this.runTask(function () { (0, _emberMetal.set)(_this29.context, 'htmlContent', 'Max'); (0, _emberMetal.set)(_this29.context, 'nested', { htmlContent: 'James' }); }); this.assertContent('MaxJames'); }; return _class6; }(TrustedContentTest)); (0, _testCase.moduleFor)('Dynamic content tests (integration)', function (_RenderingTest3) { (0, _emberBabel.inherits)(_class7, _RenderingTest3); function _class7() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest3.apply(this, arguments)); } _class7.prototype['@test it can render a dynamic template'] = function () { var _this31 = this; var ember = '\n
\n

Welcome to Ember.js

\n
\n
\n

Why you should use Ember.js?

\n
    \n
  1. It\'s great
  2. \n
  3. It\'s awesome
  4. \n
  5. It\'s Ember.js
  6. \n
\n
\n \n '; this.render('\n
\n

Welcome to {{framework}}

\n
\n
\n

Why you should use {{framework}}?

\n
    \n
  1. It\'s great
  2. \n
  3. It\'s awesome
  4. \n
  5. It\'s {{framework}}
  6. \n
\n
\n \n ', { framework: 'Ember.js' }); this.assertHTML(ember); this.runTask(function () { return _this31.rerender(); }); this.assertHTML(ember); this.runTask(function () { return (0, _emberMetal.set)(_this31.context, 'framework', 'React'); }); this.assertHTML('\n
\n

Welcome to React

\n
\n
\n

Why you should use React?

\n
    \n
  1. It\'s great
  2. \n
  3. It\'s awesome
  4. \n
  5. It\'s React
  6. \n
\n
\n \n '); this.runTask(function () { return (0, _emberMetal.set)(_this31.context, 'framework', 'Ember.js'); }); this.assertHTML(ember); }; _class7.prototype['@test it should evaluate to nothing if part of the path is `undefined`'] = function () { var _this32 = this; this.render('{{foo.bar.baz.bizz}}', { foo: {} }); this.assertText(''); this.runTask(function () { return _this32.rerender(); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this32.context, 'foo', { bar: { baz: { bizz: 'Hey!' } } }); }); this.assertText('Hey!'); this.runTask(function () { return (0, _emberMetal.set)(_this32.context, 'foo', {}); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this32.context, 'foo', { bar: { baz: { bizz: 'Hello!' } } }); }); this.assertText('Hello!'); this.runTask(function () { return (0, _emberMetal.set)(_this32.context, 'foo', {}); }); this.assertText(''); }; _class7.prototype['@test it should evaluate to nothing if part of the path is a primative'] = function () { var _this33 = this; this.render('{{foo.bar.baz.bizz}}', { foo: { bar: true } }); this.assertText(''); this.runTask(function () { return _this33.rerender(); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this33.context, 'foo', { bar: false }); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this33.context, 'foo', { bar: 'Haha' }); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this33.context, 'foo', { bar: null }); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this33.context, 'foo', { bar: undefined }); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this33.context, 'foo', { bar: 1 }); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this33.context, 'foo', { bar: { baz: { bizz: 'Hello!' } } }); }); this.assertText('Hello!'); this.runTask(function () { return (0, _emberMetal.set)(_this33.context, 'foo', { bar: true }); }); this.assertText(''); }; _class7.prototype['@test can set dynamic href'] = function () { var _this34 = this; this.render('Example', { model: { url: 'http://example.com' } }); this.assertElement(this.firstChild, { tagName: 'a', content: 'Example', attrs: { 'href': 'http://example.com' } }); this.runTask(function () { return _this34.rerender(); }); this.assertElement(this.firstChild, { tagName: 'a', content: 'Example', attrs: { 'href': 'http://example.com' } }); this.runTask(function () { return (0, _emberMetal.set)(_this34.context, 'model.url', 'http://linkedin.com'); }); this.assertElement(this.firstChild, { tagName: 'a', content: 'Example', attrs: { 'href': 'http://linkedin.com' } }); this.runTask(function () { return (0, _emberMetal.set)(_this34.context, 'model', { url: 'http://example.com' }); }); this.assertElement(this.firstChild, { tagName: 'a', content: 'Example', attrs: { 'href': 'http://example.com' } }); }; _class7.prototype['@test quoteless class attributes update correctly'] = function () { var _this35 = this; this.render('
hello
', { fooBar: true }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } }); this.runTask(function () { return _this35.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } }); this.runTask(function () { return (0, _emberMetal.set)(_this35.context, 'fooBar', false); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello' }); this.runTask(function () { return (0, _emberMetal.set)(_this35.context, 'fooBar', true); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } }); }; _class7.prototype['@test quoted class attributes update correctly'] = function (assert) { var _this36 = this; this.render('
hello
', { fooBar: true }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } }); this.runTask(function () { return _this36.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } }); this.runTask(function () { return (0, _emberMetal.set)(_this36.context, 'fooBar', false); }); assert.equal(this.firstChild.className, ''); this.runTask(function () { return (0, _emberMetal.set)(_this36.context, 'fooBar', true); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } }); }; _class7.prototype['@test unquoted class attribute can contain multiple classes'] = function () { var _this37 = this; this.render('
hello
', { model: { classes: 'foo bar baz' } }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } }); this.runTask(function () { return _this37.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } }); this.runTask(function () { return (0, _emberMetal.set)(_this37.context, 'model.classes', 'fizz bizz'); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz bizz') } }); this.runTask(function () { return (0, _emberMetal.set)(_this37.context, 'model', { classes: 'foo bar baz' }); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } }); }; _class7.prototype['@test unquoted class attribute'] = function () { var _this38 = this; this.render('
hello
', { model: { foo: 'foo' } }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } }); this.runTask(function () { return _this38.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } }); this.runTask(function () { return (0, _emberMetal.set)(_this38.context, 'model.foo', 'fizz'); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz') } }); this.runTask(function () { return (0, _emberMetal.set)(_this38.context, 'model', { foo: 'foo' }); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } }); }; _class7.prototype['@test quoted class attribute'] = function () { var _this39 = this; this.render('
hello
', { model: { foo: 'foo' } }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } }); this.runTask(function () { return _this39.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } }); this.runTask(function () { return (0, _emberMetal.set)(_this39.context, 'model.foo', 'fizz'); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz') } }); this.runTask(function () { return (0, _emberMetal.set)(_this39.context, 'model', { foo: 'foo' }); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } }); }; _class7.prototype['@test quoted class attribute can contain multiple classes'] = function () { var _this40 = this; this.render('
hello
', { model: { classes: 'foo bar baz' } }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } }); this.runTask(function () { return _this40.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } }); this.runTask(function () { return (0, _emberMetal.set)(_this40.context, 'model.classes', 'fizz bizz'); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz bizz') } }); this.runTask(function () { return (0, _emberMetal.set)(_this40.context, 'model', { classes: 'foo bar baz' }); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } }); }; _class7.prototype['@test class attribute concats bound values'] = function () { var _this41 = this; this.render('
hello
', { model: { foo: 'foo', bar: 'bar', bizz: 'bizz' } }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar bizz') } }); this.runTask(function () { return _this41.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar bizz') } }); this.runTask(function () { return (0, _emberMetal.set)(_this41.context, 'model.foo', 'fizz'); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz bar bizz') } }); this.runTask(function () { return (0, _emberMetal.set)(_this41.context, 'model.bar', null); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz bizz') } }); this.runTask(function () { return (0, _emberMetal.set)(_this41.context, 'model', { foo: 'foo', bar: 'bar', bizz: 'bizz' }); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar bizz') } }); }; _class7.prototype['@test class attribute accepts nested helpers, and updates'] = function () { var _this42 = this; this.render('
hello
', { model: { size: 'large', hasSize: true, hasShape: false, shape: 'round' } }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('large') } }); this.runTask(function () { return _this42.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('large') } }); this.runTask(function () { return (0, _emberMetal.set)(_this42.context, 'model.hasShape', true); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('large round') } }); this.runTask(function () { return (0, _emberMetal.set)(_this42.context, 'model.hasSize', false); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('round') } }); this.runTask(function () { return (0, _emberMetal.set)(_this42.context, 'model', { size: 'large', hasSize: true, hasShape: false, shape: 'round' }); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('large') } }); }; _class7.prototype['@test Multiple dynamic classes'] = function () { var _this43 = this; this.render('
hello
', { model: { foo: 'foo', bar: 'bar', fizz: 'fizz', baz: 'baz' } }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar fizz baz') } }); this.runTask(function () { return _this43.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar fizz baz') } }); this.runTask(function () { (0, _emberMetal.set)(_this43.context, 'model.foo', null); (0, _emberMetal.set)(_this43.context, 'model.fizz', null); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('bar baz') } }); this.runTask(function () { (0, _emberMetal.set)(_this43.context, 'model', { foo: 'foo', bar: 'bar', fizz: 'fizz', baz: 'baz' }); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar fizz baz') } }); }; _class7.prototype['@test classes are ordered: See issue #9912'] = function () { var _this44 = this; this.render('
hello
', { model: { foo: 'foo', bar: 'bar' } }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': 'foo static bar' } }); this.runTask(function () { return _this44.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': 'foo static bar' } }); this.runTask(function () { (0, _emberMetal.set)(_this44.context, 'model.bar', null); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': 'foo static ' } }); this.runTask(function () { (0, _emberMetal.set)(_this44.context, 'model', { foo: 'foo', bar: 'bar' }); }); this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': 'foo static bar' } }); }; return _class7; }(_testCase.RenderingTest)); var warnings = void 0, originalWarn = void 0; var StyleTest = function (_RenderingTest4) { (0, _emberBabel.inherits)(StyleTest, _RenderingTest4); function StyleTest() { var _this45 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest4.apply(this, arguments)); warnings = []; originalWarn = (0, _emberDebug.getDebugFunction)('warn'); (0, _emberDebug.setDebugFunction)('warn', function (message, test) { if (!test) { warnings.push(message); } }); return _this45; } StyleTest.prototype.teardown = function () { var _RenderingTest4$proto; (_RenderingTest4$proto = _RenderingTest4.prototype.teardown).call.apply(_RenderingTest4$proto, [this].concat(Array.prototype.slice.call(arguments))); (0, _emberDebug.setDebugFunction)('warn', originalWarn); }; StyleTest.prototype.assertStyleWarning = function (style) { this.assert.deepEqual(warnings, [(0, _emberViews.constructStyleDeprecationMessage)(style)]); }; StyleTest.prototype.assertNoWarning = function () { this.assert.deepEqual(warnings, []); }; return StyleTest; }(_testCase.RenderingTest); (0, _testCase.moduleFor)('Inline style tests', function (_StyleTest) { (0, _emberBabel.inherits)(_class8, _StyleTest); function _class8() { return (0, _emberBabel.possibleConstructorReturn)(this, _StyleTest.apply(this, arguments)); } _class8.prototype['@test can set dynamic style'] = function () { var _this47 = this; this.render('
', { model: { style: 'width: 60px;' } }); this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } }); this.runTask(function () { return _this47.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } }); this.runTask(function () { return (0, _emberMetal.set)(_this47.context, 'model.style', 'height: 60px;'); }); this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'height: 60px;' } }); this.runTask(function () { return (0, _emberMetal.set)(_this47.context, 'model.style', null); }); this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: {} }); this.runTask(function () { return (0, _emberMetal.set)(_this47.context, 'model', { style: 'width: 60px;' }); }); this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } }); }; _class8.prototype['@test can set dynamic style with -html-safe'] = function () { var _this48 = this; this.render('
', { model: { style: 'width: 60px;' } }); this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } }); this.runTask(function () { return _this48.rerender(); }); this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } }); this.runTask(function () { return (0, _emberMetal.set)(_this48.context, 'model.style', 'height: 60px;'); }); this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'height: 60px;' } }); this.runTask(function () { return (0, _emberMetal.set)(_this48.context, 'model', { style: 'width: 60px;' }); }); this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } }); }; return _class8; }(StyleTest)); if (!EmberDev.runningProdBuild) { (0, _testCase.moduleFor)('Inline style tests - warnings', function (_StyleTest2) { (0, _emberBabel.inherits)(_class9, _StyleTest2); function _class9() { return (0, _emberBabel.possibleConstructorReturn)(this, _StyleTest2.apply(this, arguments)); } _class9.prototype['@test specifying
generates a warning'] = function () { var userValue = 'width: 42px'; this.render('
', { userValue: userValue }); this.assertStyleWarning(userValue); }; _class9.prototype['@test specifying `attributeBindings: ["style"]` generates a warning'] = function () { var FooBarComponent = _helpers.Component.extend({ attributeBindings: ['style'] }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); var userValue = 'width: 42px'; this.render('{{foo-bar style=userValue}}', { userValue: userValue }); this.assertStyleWarning(userValue); }; _class9.prototype['@test specifying `
` works properly without a warning'] = function () { this.render('
', { userValue: 'width: 42px' }); this.assertNoWarning(); }; _class9.prototype['@test specifying `
` works properly with a SafeString'] = function () { this.render('
', { userValue: new _helpers.SafeString('width: 42px') }); this.assertNoWarning(); }; _class9.prototype['@test null value do not generate htmlsafe warning'] = function () { this.render('
', { userValue: null }); this.assertNoWarning(); }; _class9.prototype['@test undefined value do not generate htmlsafe warning'] = function () { this.render('
'); this.assertNoWarning(); }; _class9.prototype['@test no warnings are triggered when using `-html-safe`'] = function () { this.render('
', { userValue: 'width: 42px' }); this.assertNoWarning(); }; _class9.prototype['@test no warnings are triggered when a safe string is quoted'] = function () { this.render('
', { userValue: new _helpers.SafeString('width: 42px') }); this.assertNoWarning(); }; _class9.prototype['@test binding warning is triggered when an unsafe string is quoted'] = function () { var userValue = 'width: 42px'; this.render('
', { userValue: userValue }); this.assertStyleWarning(userValue); }; _class9.prototype['@test binding warning is triggered when a safe string for a complete property is concatenated in place'] = function () { this.render('
', { userValue: new _helpers.SafeString('width: 42px') }); this.assertStyleWarning('color: green; ' + 'width: 42px'); }; _class9.prototype['@test binding warning is triggered when a safe string for a value is concatenated in place'] = function () { var userValue = '42px'; this.render('
', { userValue: new _helpers.SafeString(userValue) }); this.assertStyleWarning('color: green; width: ' + userValue); }; _class9.prototype['@test binding warning is triggered when a safe string for a property name is concatenated in place'] = function () { var userValue = 'width'; this.render('
', { userProperty: new _helpers.SafeString(userValue) }); this.assertStyleWarning('color: green; ' + userValue + ': 42px'); }; return _class9; }(StyleTest)); } }); enifed('ember-glimmer/tests/integration/event-dispatcher-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal', 'ember-views'], function (_emberBabel, _testCase, _helpers, _emberMetal, _emberViews) { 'use strict'; var canDataTransfer = !!document.createEvent('HTMLEvents').dataTransfer; function fireNativeWithDataTransfer(node, type, dataTransfer) { var event = document.createEvent('HTMLEvents'); event.initEvent(type, true, true); event.dataTransfer = dataTransfer; node.dispatchEvent(event); } (0, _testCase.moduleFor)('EventDispatcher', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test events bubble view hierarchy for form elements'] = function (assert) { var _this2 = this; var receivedEvent = void 0; this.registerComponent('x-foo', { ComponentClass: _helpers.Component.extend({ change: function (event) { receivedEvent = event; } }), template: '' }); this.render('{{x-foo}}'); this.runTask(function () { return _this2.$('#is-done').trigger('change'); }); assert.ok(receivedEvent, 'change event was triggered'); assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]); }; _class.prototype['@test dispatches to the nearest event manager'] = function (assert) { var _this3 = this; var receivedEvent = void 0; this.registerComponent('x-foo', { ComponentClass: _helpers.Component.extend({ click: function () { assert.notOk(true, 'should not trigger `click` on component'); }, eventManager: { click: function (event) { receivedEvent = event; } } }), template: '' }); expectDeprecation(/`eventManager` has been deprecated/); this.render('{{x-foo}}'); this.runTask(function () { return _this3.$('#is-done').trigger('click'); }); assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]); }; _class.prototype['@test event manager can re-dispatch to the component'] = function (assert) { var _this4 = this; var handlers = []; this.registerComponent('x-foo', { ComponentClass: _helpers.Component.extend({ click: function () { handlers.push('component'); }, eventManager: { click: function (event, component) { handlers.push('eventManager'); // Re-dispatch event when you get it. // // The second parameter tells the dispatcher // that this event has been handled. This // API will clearly need to be reworked since // multiple eventManagers in a single view // hierarchy would break, but it shows that // re-dispatching works component.$().trigger('click', this); } } }), template: '' }); expectDeprecation(/`eventManager` has been deprecated/); this.render('{{x-foo}}'); this.runTask(function () { return _this4.$('#is-done').trigger('click'); }); assert.deepEqual(handlers, ['eventManager', 'component']); }; _class.prototype['@test event handlers are wrapped in a run loop'] = function (assert) { this.registerComponent('x-foo', { ComponentClass: _helpers.Component.extend({ change: function () { assert.ok(_emberMetal.run.currentRunLoop, 'a run loop should have started'); } }), template: '' }); this.render('{{x-foo}}'); this.$('#is-done').trigger('click'); }; return _class; }(_testCase.RenderingTest)); (0, _testCase.moduleFor)('EventDispatcher#setup', function (_RenderingTest2) { (0, _emberBabel.inherits)(_class2, _RenderingTest2); function _class2() { var _this5 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.call(this)); var dispatcher = _this5.owner.lookup('event_dispatcher:main'); (0, _emberMetal.run)(dispatcher, 'destroy'); _this5.owner.__container__.reset('event_dispatcher:main'); _this5.dispatcher = _this5.owner.lookup('event_dispatcher:main'); return _this5; } _class2.prototype['@test additional events can be specified'] = function (assert) { this.dispatcher.setup({ myevent: 'myEvent' }); this.registerComponent('x-foo', { ComponentClass: _helpers.Component.extend({ myEvent: function () { assert.ok(true, 'custom event was triggered'); } }), template: '

Hello!

' }); this.render('{{x-foo}}'); this.$('div').trigger('myevent'); }; _class2.prototype['@test eventManager is deprecated'] = function () { this.registerComponent('x-foo', { ComponentClass: _helpers.Component.extend({ eventManager: { myEvent: function () {} } }), template: '

Hello!

' }); expectDeprecation(/`eventManager` has been deprecated/); this.render('{{x-foo}}'); }; _class2.prototype['@test canDispatchToEventManager is deprecated in EventDispatcher'] = function () { var MyDispatcher = _emberViews.EventDispatcher.extend({ canDispatchToEventManager: null }); expectDeprecation(/`canDispatchToEventManager` has been deprecated/); MyDispatcher.create(); }; _class2.prototype['@test a rootElement can be specified'] = function (assert) { this.$().append('
'); this.dispatcher.setup({ myevent: 'myEvent' }, '#app'); assert.ok(this.$('#app').hasClass('ember-application'), 'custom rootElement was used'); assert.equal(this.dispatcher.rootElement, '#app', 'the dispatchers rootElement was updated'); }; _class2.prototype['@test default events can be disabled via `customEvents`'] = function (assert) { this.dispatcher.setup({ click: null }); this.registerComponent('x-foo', { ComponentClass: _helpers.Component.extend({ click: function () { assert.ok(false, 'click method was called'); }, null: function () { assert.ok(false, 'null method was called'); }, doubleClick: function () { assert.ok(true, 'a non-disabled event is still handled properly'); } }), template: '

Hello!

' }); this.render('{{x-foo}}'); this.$('div').trigger('click'); this.$('div').trigger('dblclick'); }; _class2.prototype['@test throws if specified rootElement does not exist'] = function (assert) { var _this6 = this; assert.throws(function () { _this6.dispatcher.setup({ myevent: 'myEvent' }, '#app'); }); }; return _class2; }(_testCase.RenderingTest)); if (canDataTransfer) { (0, _testCase.moduleFor)('EventDispatcher - Event Properties', function (_RenderingTest4) { (0, _emberBabel.inherits)(_class4, _RenderingTest4); function _class4() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest4.apply(this, arguments)); } _class4.prototype['@test dataTransfer property is added to drop event'] = function (assert) { var receivedEvent = void 0; this.registerComponent('x-foo', { ComponentClass: _helpers.Component.extend({ drop: function (event) { receivedEvent = event; } }) }); this.render('{{x-foo}}'); fireNativeWithDataTransfer(this.$('div')[0], 'drop', 'success'); assert.equal(receivedEvent.dataTransfer, 'success'); }; return _class4; }(_testCase.RenderingTest)); } }); enifed('ember-glimmer/tests/integration/helpers/-class-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/test-helpers', 'ember-metal'], function (_emberBabel, _testCase, _testHelpers, _emberMetal) { 'use strict'; (0, _testCase.moduleFor)('Helpers test: {{-class}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test casts binding to dasherized class'] = function () { var _this2 = this; this.registerComponent('foo-bar', { template: '' }); this.render('{{foo-bar class=(-class someTruth "someTruth")}}', { someTruth: true }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } }); this.runTask(function () { return _this2.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } }); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'someTruth', false); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('ember-view') } }); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'someTruth', true); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } }); }; _class.prototype['@tests casts leaf path of binding to dasherized class'] = function () { var _this3 = this; this.registerComponent('foo-bar', { template: '' }); this.render('{{foo-bar class=(-class model.someTruth "someTruth")}}', { model: { someTruth: true } }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } }); this.runTask(function () { return _this3.rerender(); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } }); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'model.someTruth', false); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('ember-view') } }); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'model', { someTruth: true }); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } }); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/closure-action-test', ['ember-babel', 'ember-metal', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/helpers'], function (_emberBabel, _emberMetal, _testCase, _abstractTestCase, _helpers) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
clicked: {{clicked}}; foo: {{foo}}
\n\n {{click-me id="string-action" onClick=(action "on-click")}}\n {{click-me id="function-action" onClick=(action onClick)}}\n {{click-me id="mut-action" onClick=(action (mut clicked))}}\n '], ['\n
clicked: {{clicked}}; foo: {{foo}}
\n\n {{click-me id="string-action" onClick=(action "on-click")}}\n {{click-me id="function-action" onClick=(action onClick)}}\n {{click-me id="mut-action" onClick=(action (mut clicked))}}\n ']); (0, _testCase.moduleFor)('Helpers test: closure {{action}}', function (_RenderingTest2) { (0, _emberBabel.inherits)(_class2, _RenderingTest2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments)); } _class2.prototype['@test action should be called'] = function () { var outerActionCalled = false; var component = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, fireAction: function () { this.attrs.submit(); } }); var OuterComponent = _helpers.Component.extend({ outerSubmit: function () { outerActionCalled = true; } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action outerSubmit)}}' }); this.render('{{outer-component}}'); this.runTask(function () { component.fireAction(); }); this.assert.ok(outerActionCalled, 'the action was called'); }; _class2.prototype['@test an error is triggered when bound action function is undefined'] = function () { var _this6 = this; this.registerComponent('inner-component', { template: 'inner' }); this.registerComponent('outer-component', { template: '{{inner-component submit=(action somethingThatIsUndefined)}}' }); expectAssertion(function () { _this6.render('{{outer-component}}'); }, /Action passed is null or undefined in \(action[^)]*\) from .*\./); }; _class2.prototype['@test an error is triggered when bound action being passed in is a non-function'] = function () { var _this7 = this; this.registerComponent('inner-component', { template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: _helpers.Component.extend({ nonFunctionThing: {} }), template: '{{inner-component submit=(action nonFunctionThing)}}' }); expectAssertion(function () { _this7.render('{{outer-component}}'); }, /An action could not be made for `.*` in .*\. Please confirm that you are using either a quoted action name \(i\.e\. `\(action '.*'\)`\) or a function available in .*\./); }; _class2.prototype['@test [#12718] a nice error is shown when a bound action function is undefined and it is passed as attrs.foo'] = function () { var _this8 = this; this.registerComponent('inner-component', { template: '' }); this.registerComponent('outer-component', { template: '{{inner-component}}' }); expectAssertion(function () { _this8.render('{{outer-component}}'); }, /Action passed is null or undefined in \(action[^)]*\) from .*\./); }; _class2.prototype['@test action value is returned'] = function () { var expectedValue = 'terrible tom'; var returnedValue = void 0; var innerComponent = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { returnedValue = this.attrs.submit(); } }); var OuterComponent = _helpers.Component.extend({ outerSubmit: function () { return expectedValue; } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action outerSubmit)}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.equal(returnedValue, expectedValue, 'action can return to caller'); }; _class2.prototype['@test action should be called on the correct scope'] = function () { var innerComponent = void 0; var outerComponent = void 0; var actualComponent = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit(); } }); var OuterComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); outerComponent = this; }, isOuterComponent: true, outerSubmit: function () { actualComponent = this; } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action outerSubmit)}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.equal(actualComponent, outerComponent, 'action has the correct context'); this.assert.ok(actualComponent.isOuterComponent, 'action has the correct context'); }; _class2.prototype['@test arguments to action are passed, curry'] = function () { var first = 'mitch'; var second = 'martin'; var third = 'matt'; var fourth = 'wacky wycats'; var innerComponent = void 0; var actualArgs = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit(fourth); } }); var OuterComponent = _helpers.Component.extend({ third: third, outerSubmit: function () { actualArgs = [].concat(Array.prototype.slice.call(arguments)); } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action (action outerSubmit "' + first + '") "' + second + '" third)}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.deepEqual(actualArgs, [first, second, third, fourth], 'action has the correct args'); }; _class2.prototype['@test `this` can be passed as an argument'] = function () { var value = {}; var component = void 0; var innerComponent = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit(); } }); var OuterComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, actions: { outerAction: function (incomingValue) { value = incomingValue; } } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action "outerAction" this)}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.strictEqual(value, component, 'the component is passed at `this`'); }; _class2.prototype['@test arguments to action are bound'] = function () { var value = 'lazy leah'; var innerComponent = void 0; var outerComponent = void 0; var actualArg = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit(); } }); var OuterComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); outerComponent = this; }, value: '', outerSubmit: function (incomingValue) { actualArg = incomingValue; } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action outerSubmit value)}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.strictEqual(actualArg, '', 'action has the correct first arg'); this.runTask(function () { outerComponent.set('value', value); }); this.runTask(function () { innerComponent.fireAction(); }); this.assert.strictEqual(actualArg, value, 'action has the correct first arg'); }; _class2.prototype['@test array arguments are passed correctly to action'] = function () { var first = 'foo'; var second = [3, 5]; var third = [4, 9]; var actualFirst = void 0; var actualSecond = void 0; var actualThird = void 0; var innerComponent = void 0; var outerComponent = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit(second, third); } }); var OuterComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); outerComponent = this; }, outerSubmit: function (incomingFirst, incomingSecond, incomingThird) { actualFirst = incomingFirst; actualSecond = incomingSecond; actualThird = incomingThird; } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action outerSubmit first)}}' }); this.render('{{outer-component}}'); this.runTask(function () { outerComponent.set('first', first); outerComponent.set('second', second); }); this.runTask(function () { innerComponent.fireAction(); }); this.assert.equal(actualFirst, first, 'action has the correct first arg'); this.assert.equal(actualSecond, second, 'action has the correct second arg'); this.assert.equal(actualThird, third, 'action has the correct third arg'); }; _class2.prototype['@test mut values can be wrapped in actions, are settable'] = function () { var newValue = 'trollin trek'; var innerComponent = void 0; var outerComponent = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit(newValue); } }); var OuterComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); outerComponent = this; }, outerMut: 'patient peter' }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action (mut outerMut))}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.equal(outerComponent.get('outerMut'), newValue, 'mut value is set'); }; _class2.prototype['@test mut values can be wrapped in actions, are settable with a curry'] = function () { var newValue = 'trollin trek'; var innerComponent = void 0; var outerComponent = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit(); } }); var OuterComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); outerComponent = this; }, outerMut: 'patient peter' }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action (mut outerMut) \'' + newValue + '\')}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.equal(outerComponent.get('outerMut'), newValue, 'mut value is set'); }; _class2.prototype['@test action can create closures over actions'] = function () { var first = 'raging robert'; var second = 'mild machty'; var returnValue = 'butch brian'; var actualFirst = void 0; var actualSecond = void 0; var actualReturnedValue = void 0; var innerComponent = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { actualReturnedValue = this.attrs.submit(second); } }); var OuterComponent = _helpers.Component.extend({ actions: { outerAction: function (incomingFirst, incomingSecond) { actualFirst = incomingFirst; actualSecond = incomingSecond; return returnValue; } } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action \'outerAction\' \'' + first + '\')}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.equal(actualReturnedValue, returnValue, 'return value is present'); this.assert.equal(actualFirst, first, 'first argument is correct'); this.assert.equal(actualSecond, second, 'second argument is correct'); }; _class2.prototype['@test provides a helpful error if an action is not present'] = function () { var _this9 = this; var InnerComponent = _helpers.Component.extend({}); var OuterComponent = _helpers.Component.extend({ actions: { something: function () { // this is present to ensure `actions` hash is present // a different error is triggered if `actions` is missing // completely } } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action \'doesNotExist\')}}' }); expectAssertion(function () { _this9.render('{{outer-component}}'); }, /An action named 'doesNotExist' was not found in /); }; _class2.prototype['@test provides a helpful error if actions hash is not present'] = function () { var _this10 = this; var InnerComponent = _helpers.Component.extend({}); var OuterComponent = _helpers.Component.extend({}); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action \'doesNotExist\')}}' }); expectAssertion(function () { _this10.render('{{outer-component}}'); }, /An action named 'doesNotExist' was not found in /); }; _class2.prototype['@test action can create closures over actions with target'] = function () { var innerComponent = void 0; var actionCalled = false; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit(); } }); var OuterComponent = _helpers.Component.extend({ otherComponent: (0, _emberMetal.computed)(function () { return { actions: { outerAction: function () { actionCalled = true; } } }; }) }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action \'outerAction\' target=otherComponent)}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.ok(actionCalled, 'action called on otherComponent'); }; _class2.prototype['@test value can be used with action over actions'] = function () { var newValue = 'yelping yehuda'; var innerComponent = void 0; var actualValue = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit({ readProp: newValue }); } }); var OuterComponent = _helpers.Component.extend({ outerContent: { readProp: newValue }, actions: { outerAction: function (incomingValue) { actualValue = incomingValue; } } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action \'outerAction\' value="readProp")}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.equal(actualValue, newValue, 'value is read'); }; _class2.prototype['@test action will read the value of a first property'] = function () { var newValue = 'irate igor'; var innerComponent = void 0; var actualValue = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit({ readProp: newValue }); } }); var OuterComponent = _helpers.Component.extend({ outerAction: function (incomingValue) { actualValue = incomingValue; } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action outerAction value="readProp")}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.equal(actualValue, newValue, 'property is read'); }; _class2.prototype['@test action will read the value of a curried first argument property'] = function () { var newValue = 'kissing kris'; var innerComponent = void 0; var actualValue = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit(); } }); var OuterComponent = _helpers.Component.extend({ objectArgument: { readProp: newValue }, outerAction: function (incomingValue) { actualValue = incomingValue; } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action outerAction objectArgument value="readProp")}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.equal(actualValue, newValue, 'property is read'); }; _class2.prototype['@test action closure does not get auto-mut wrapped'] = function (assert) { var first = 'raging robert'; var second = 'mild machty'; var returnValue = 'butch brian'; var innerComponent = void 0; var actualFirst = void 0; var actualSecond = void 0; var actualReturnedValue = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.get('submit')(second); this.get('attrs-submit')(second); var attrsSubmitReturnValue = this.attrs['attrs-submit'](second); var submitReturnValue = this.attrs.submit(second); assert.equal(attrsSubmitReturnValue, submitReturnValue, 'both attrs.foo and foo should behave the same'); return submitReturnValue; } }); var MiddleComponent = _helpers.Component.extend({}); var OuterComponent = _helpers.Component.extend({ actions: { outerAction: function (incomingFirst, incomingSecond) { actualFirst = incomingFirst; actualSecond = incomingSecond; return returnValue; } } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('middle-component', { ComponentClass: MiddleComponent, template: '{{inner-component attrs-submit=attrs.submit submit=submit}}' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{middle-component submit=(action \'outerAction\' \'' + first + '\')}}' }); this.render('{{outer-component}}'); this.runTask(function () { actualReturnedValue = innerComponent.fireAction(); }); this.assert.equal(actualFirst, first, 'first argument is correct'); this.assert.equal(actualSecond, second, 'second argument is correct'); this.assert.equal(actualReturnedValue, returnValue, 'return value is present'); }; _class2.prototype['@test action should be called within a run loop'] = function () { var innerComponent = void 0; var capturedRunLoop = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { this.attrs.submit(); } }); var OuterComponent = _helpers.Component.extend({ actions: { submit: function () { capturedRunLoop = _emberMetal.run.currentRunLoop; } } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action \'submit\')}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.ok(capturedRunLoop, 'action is called within a run loop'); }; _class2.prototype['@test objects that define INVOKE can be casted to actions'] = function () { var innerComponent = void 0; var actionArgs = void 0; var invokableArgs = void 0; var InnerComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); innerComponent = this; }, fireAction: function () { actionArgs = this.attrs.submit(4, 5, 6); } }); var OuterComponent = _helpers.Component.extend({ foo: 123, submitTask: (0, _emberMetal.computed)(function () { var _this11 = this, _ref; return _ref = {}, _ref[_helpers.INVOKE] = function () { var _len, args, _key; for (_len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } invokableArgs = args; return _this11.foo; }, _ref; }) }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: '{{inner-component submit=(action submitTask 1 2 3)}}' }); this.render('{{outer-component}}'); this.runTask(function () { innerComponent.fireAction(); }); this.assert.equal(actionArgs, 123); this.assert.deepEqual(invokableArgs, [1, 2, 3, 4, 5, 6]); }; _class2.prototype['@test closure action with `(mut undefinedThing)` works properly [GH#13959]'] = function () { var _this12 = this; var component = void 0; var ExampleComponent = _helpers.Component.extend({ label: undefined, init: function () { this._super.apply(this, arguments); component = this; } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '' }); this.render('{{example-component}}'); this.assertText('Click me'); this.assertStableRerender(); this.runTask(function () { _this12.$('button').click(); }); this.assertText('Clicked!'); this.runTask(function () { component.set('label', 'Dun clicked'); }); this.assertText('Dun clicked'); this.runTask(function () { _this12.$('button').click(); }); this.assertText('Clicked!'); this.runTask(function () { component.set('label', undefined); }); this.assertText('Click me'); }; _class2.prototype['@test closure actions does not cause component hooks to fire unnecessarily [GH#14305] [GH#14654]'] = function (assert) { var _this14 = this; var clicked = 0; var didReceiveAttrsFired = 0; var ClickMeComponent = _helpers.Component.extend({ tagName: 'button', click: function () { this.get('onClick').call(undefined, ++clicked); }, didReceiveAttrs: function () { didReceiveAttrsFired++; } }); this.registerComponent('click-me', { ComponentClass: ClickMeComponent }); var outer = void 0; var OuterComponent = _helpers.Component.extend({ clicked: 0, actions: { 'on-click': function () { this.incrementProperty('clicked'); } }, init: function () { var _this13 = this; this._super(); outer = this; this.set('onClick', function () { return _this13.incrementProperty('clicked'); }); } }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: (0, _abstractTestCase.strip)(_templateObject) }); this.render('{{outer-component foo=foo}}', { foo: 1 }); this.assertText('clicked: 0; foo: 1'); assert.equal(didReceiveAttrsFired, 3); this.runTask(function () { return _this14.rerender(); }); this.assertText('clicked: 0; foo: 1'); assert.equal(didReceiveAttrsFired, 3); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'foo', 2); }); this.assertText('clicked: 0; foo: 2'); assert.equal(didReceiveAttrsFired, 3); this.runTask(function () { return _this14.$('#string-action').click(); }); this.assertText('clicked: 1; foo: 2'); assert.equal(didReceiveAttrsFired, 3); this.runTask(function () { return _this14.$('#function-action').click(); }); this.assertText('clicked: 2; foo: 2'); assert.equal(didReceiveAttrsFired, 3); this.runTask(function () { return (0, _emberMetal.set)(outer, 'onClick', function () { outer.incrementProperty('clicked'); }); }); this.assertText('clicked: 2; foo: 2'); assert.equal(didReceiveAttrsFired, 3); this.runTask(function () { return _this14.$('#function-action').click(); }); this.assertText('clicked: 3; foo: 2'); assert.equal(didReceiveAttrsFired, 3); this.runTask(function () { return _this14.$('#mut-action').click(); }); this.assertText('clicked: 4; foo: 2'); assert.equal(didReceiveAttrsFired, 3); }; return _class2; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/concat-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal'], function (_emberBabel, _testCase, _emberMetal) { 'use strict'; (0, _testCase.moduleFor)('Helpers test: {{concat}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test it concats static arguments'] = function () { this.render('{{concat "foo" " " "bar" " " "baz"}}'); this.assertText('foo bar baz'); }; _class.prototype['@test it updates for bound arguments'] = function () { var _this2 = this; this.render('{{concat model.first model.second}}', { model: { first: 'one', second: 'two' } }); this.assertText('onetwo'); this.runTask(function () { return _this2.rerender(); }); this.assertText('onetwo'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'model.first', 'three'); }); this.assertText('threetwo'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'model.second', 'four'); }); this.assertText('threefour'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'model', { first: 'one', second: 'two' }); }); this.assertText('onetwo'); }; _class.prototype['@test it can be used as a sub-expression'] = function () { var _this3 = this; this.render('{{concat (concat model.first model.second) (concat model.third model.fourth)}}', { model: { first: 'one', second: 'two', third: 'three', fourth: 'four' } }); this.assertText('onetwothreefour'); this.runTask(function () { return _this3.rerender(); }); this.assertText('onetwothreefour'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'model.first', 'five'); }); this.assertText('fivetwothreefour'); this.runTask(function () { (0, _emberMetal.set)(_this3.context, 'model.second', 'six'); (0, _emberMetal.set)(_this3.context, 'model.third', 'seven'); }); this.assertText('fivesixsevenfour'); this.runTask(function () { (0, _emberMetal.set)(_this3.context, 'model', { first: 'one', second: 'two', third: 'three', fourth: 'four' }); }); this.assertText('onetwothreefour'); }; _class.prototype['@test it can be used as input for other helpers'] = function () { var _this4 = this; this.registerHelper('x-eq', function (_ref) { var actual = _ref[0], expected = _ref[1]; return actual === expected; }); this.render('{{#if (x-eq (concat model.first model.second) "onetwo")}}Truthy!{{else}}False{{/if}}', { model: { first: 'one', second: 'two' } }); this.assertText('Truthy!'); this.runTask(function () { return _this4.rerender(); }); this.assertText('Truthy!'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'model.first', 'three'); }); this.assertText('False'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'model', { first: 'one', second: 'two' }); }); this.assertText('Truthy!'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/custom-helper-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'internal-test-helpers', 'ember-metal', 'ember-utils'], function (_emberBabel, _testCase, _internalTestHelpers, _emberMetal, _emberUtils) { 'use strict'; /* globals EmberDev */ var assert = QUnit.assert, HelperMutatingArgsTests; (0, _testCase.moduleFor)('Helpers test: custom helpers', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test it cannot override built-in syntax'] = function () { var _this2 = this; this.registerHelper('if', function () { return 'Nope'; }); expectAssertion(function () { _this2.render('{{if foo \'LOL\'}}', { foo: true }); }, /You attempted to overwrite the built-in helper \"if\" which is not allowed. Please rename the helper./); }; _class.prototype['@test it can resolve custom simple helpers with or without dashes'] = function () { var _this3 = this; this.registerHelper('hello', function () { return 'hello'; }); this.registerHelper('hello-world', function () { return 'hello world'; }); this.render('{{hello}} | {{hello-world}}'); this.assertText('hello | hello world'); this.runTask(function () { return _this3.rerender(); }); this.assertText('hello | hello world'); }; _class.prototype['@test it does not resolve helpers with a `.` (period)'] = function () { var _this4 = this; this.registerHelper('hello.world', function () { return 'hello world'; }); this.render('{{hello.world}}', { hello: { world: '' } }); this.assertText(''); this.assertStableRerender(); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'hello', { world: 'hello world!' }); }); this.assertText('hello world!'); this.runTask(function () { (0, _emberMetal.set)(_this4.context, 'hello', { world: '' }); }); this.assertText(''); }; _class.prototype['@test it can resolve custom class-based helpers with or without dashes'] = function () { var _this5 = this; this.registerHelper('hello', { compute: function () { return 'hello'; } }); this.registerHelper('hello-world', { compute: function () { return 'hello world'; } }); this.render('{{hello}} | {{hello-world}}'); this.assertText('hello | hello world'); this.runTask(function () { return _this5.rerender(); }); this.assertText('hello | hello world'); }; _class.prototype['@test throws if `this._super` is not called from `init`'] = function () { var _this6 = this; this.registerHelper('hello-world', { init: function () {} }); expectAssertion(function () { _this6.render('{{hello-world}}'); }, /You must call `this._super\(...arguments\);` when overriding `init` on a framework object. Please update .* to call `this._super\(...arguments\);` from `init`./); }; _class.prototype['@test class-based helper can recompute a new value'] = function () { var _this7 = this; var destroyCount = 0; var computeCount = 0; var helper = void 0; this.registerHelper('hello-world', { init: function () { this._super.apply(this, arguments); helper = this; }, compute: function () { return ++computeCount; }, destroy: function () { destroyCount++; this._super(); } }); this.render('{{hello-world}}'); this.assertText('1'); this.runTask(function () { return _this7.rerender(); }); this.assertText('1'); this.runTask(function () { return helper.recompute(); }); this.assertText('2'); assert.strictEqual(destroyCount, 0, 'destroy is not called on recomputation'); }; _class.prototype['@test class-based helper with static arguments can recompute a new value'] = function () { var _this8 = this; var destroyCount = 0; var computeCount = 0; var helper = void 0; this.registerHelper('hello-world', { init: function () { this._super.apply(this, arguments); helper = this; }, compute: function () { return ++computeCount; }, destroy: function () { destroyCount++; this._super(); } }); this.render('{{hello-world "whut"}}'); this.assertText('1'); this.runTask(function () { return _this8.rerender(); }); this.assertText('1'); this.runTask(function () { return helper.recompute(); }); this.assertText('2'); assert.strictEqual(destroyCount, 0, 'destroy is not called on recomputation'); }; _class.prototype['@test helper params can be returned'] = function () { this.registerHelper('hello-world', function (values) { return values; }); this.render('{{#each (hello-world model) as |item|}}({{item}}){{/each}}', { model: ['bob'] }); this.assertText('(bob)'); }; _class.prototype['@test helper hash can be returned'] = function () { this.registerHelper('hello-world', function (_, hash) { return hash.model; }); this.render('{{get (hello-world model=model) \'name\'}}', { model: { name: 'bob' } }); this.assertText('bob'); }; _class.prototype['@test simple helper is called for param changes'] = function () { var _this9 = this; var computeCount = 0; this.registerHelper('hello-world', function (_ref) { var value = _ref[0]; computeCount++; return value + '-value'; }); this.render('{{hello-world model.name}}', { model: { name: 'bob' } }); this.assertText('bob-value'); assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time'); this.runTask(function () { return _this9.rerender(); }); this.assertText('bob-value'); assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time'); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'model.name', 'sal'); }); this.assertText('sal-value'); assert.strictEqual(computeCount, 2, 'compute is called exactly 2 times'); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'model', { name: 'bob' }); }); this.assertText('bob-value'); assert.strictEqual(computeCount, 3, 'compute is called exactly 3 times'); }; _class.prototype['@test class-based helper compute is called for param changes'] = function () { var _this10 = this; var createCount = 0; var computeCount = 0; this.registerHelper('hello-world', { init: function () { this._super.apply(this, arguments); createCount++; }, compute: function (_ref2) { var value = _ref2[0]; computeCount++; return value + '-value'; } }); this.render('{{hello-world model.name}}', { model: { name: 'bob' } }); this.assertText('bob-value'); assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time'); this.runTask(function () { return _this10.rerender(); }); this.assertText('bob-value'); assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time'); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'model.name', 'sal'); }); this.assertText('sal-value'); assert.strictEqual(computeCount, 2, 'compute is called exactly 2 times'); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'model', { name: 'bob' }); }); this.assertText('bob-value'); assert.strictEqual(computeCount, 3, 'compute is called exactly 3 times'); assert.strictEqual(createCount, 1, 'helper is only created once'); }; _class.prototype['@test simple helper receives params, hash'] = function () { var _this11 = this; this.registerHelper('hello-world', function (_params, _hash) { return 'params: ' + JSON.stringify(_params) + ', hash: ' + JSON.stringify(_hash); }); this.render('{{hello-world model.name "rich" first=model.age last="sam"}}', { model: { name: 'bob', age: 42 } }); this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}'); this.runTask(function () { return _this11.rerender(); }); this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'model.name', 'sal'); }); this.assertText('params: ["sal","rich"], hash: {"first":42,"last":"sam"}'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'model.age', 28); }); this.assertText('params: ["sal","rich"], hash: {"first":28,"last":"sam"}'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'model', { name: 'bob', age: 42 }); }); this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}'); }; _class.prototype['@test class-based helper receives params, hash'] = function () { var _this12 = this; this.registerHelper('hello-world', { compute: function (_params, _hash) { return 'params: ' + JSON.stringify(_params) + ', hash: ' + JSON.stringify(_hash); } }); this.render('{{hello-world model.name "rich" first=model.age last="sam"}}', { model: { name: 'bob', age: 42 } }); this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}'); this.runTask(function () { return _this12.rerender(); }); this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}'); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'model.name', 'sal'); }); this.assertText('params: ["sal","rich"], hash: {"first":42,"last":"sam"}'); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'model.age', 28); }); this.assertText('params: ["sal","rich"], hash: {"first":28,"last":"sam"}'); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'model', { name: 'bob', age: 42 }); }); this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}'); }; _class.prototype['@test class-based helper usable in subexpressions'] = function () { var _this13 = this; this.registerHelper('join-words', { compute: function (params) { return params.join(' '); } }); this.render('{{join-words "Who"\n (join-words "overcomes" "by")\n model.reason\n (join-words (join-words "hath overcome but" "half"))\n (join-words "his" (join-words "foe"))}}', { model: { reason: 'force' } }); this.assertText('Who overcomes by force hath overcome but half his foe'); this.runTask(function () { return _this13.rerender(); }); this.assertText('Who overcomes by force hath overcome but half his foe'); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'model.reason', 'Nickleback'); }); this.assertText('Who overcomes by Nickleback hath overcome but half his foe'); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'model', { reason: 'force' }); }); this.assertText('Who overcomes by force hath overcome but half his foe'); }; _class.prototype['@test parameterless helper is usable in subexpressions'] = function () { var _this14 = this; this.registerHelper('should-show', function () { return true; }); this.render('{{#if (should-show)}}true{{/if}}'); this.assertText('true'); this.runTask(function () { return _this14.rerender(); }); this.assertText('true'); }; _class.prototype['@test parameterless helper is usable in attributes'] = function () { var _this15 = this; this.registerHelper('foo-bar', function () { return 'baz'; }); this.render('
'); this.assertHTML('
'); this.runTask(function () { return _this15.rerender(); }); this.assertHTML('
'); }; _class.prototype['@test simple helper not usable with a block'] = function () { var _this16 = this; this.registerHelper('some-helper', function () {}); expectAssertion(function () { _this16.render('{{#some-helper}}{{/some-helper}}'); }, /Helpers may not be used in the block form/); }; _class.prototype['@test class-based helper not usable with a block'] = function () { var _this17 = this; this.registerHelper('some-helper', { compute: function () {} }); expectAssertion(function () { _this17.render('{{#some-helper}}{{/some-helper}}'); }, /Helpers may not be used in the block form/); }; _class.prototype['@test simple helper not usable within element'] = function () { var _this18 = this; this.registerHelper('some-helper', function () {}); this.assert.throws(function () { _this18.render('
'); }, /Compile Error some-helper is not a modifier: Helpers may not be used in the element form/); }; _class.prototype['@test class-based helper not usable within element'] = function () { var _this19 = this; this.registerHelper('some-helper', { compute: function () {} }); this.assert.throws(function () { _this19.render('
'); }, /Compile Error some-helper is not a modifier: Helpers may not be used in the element form/); }; _class.prototype['@test class-based helper is torn down'] = function () { var destroyCalled = 0; this.registerHelper('some-helper', { destroy: function () { destroyCalled++; this._super.apply(this, arguments); }, compute: function () { return 'must define a compute'; } }); this.render('{{some-helper}}'); (0, _internalTestHelpers.runDestroy)(this.component); assert.strictEqual(destroyCalled, 1, 'destroy called once'); }; _class.prototype['@test class-based helper used in subexpression can recompute'] = function () { var _this20 = this; var helper = void 0; var phrase = 'overcomes by'; this.registerHelper('dynamic-segment', { init: function () { this._super.apply(this, arguments); helper = this; }, compute: function () { return phrase; } }); this.registerHelper('join-words', { compute: function (params) { return params.join(' '); } }); this.render('{{join-words "Who"\n (dynamic-segment)\n "force"\n (join-words (join-words "hath overcome but" "half"))\n (join-words "his" (join-words "foe"))}}'); this.assertText('Who overcomes by force hath overcome but half his foe'); this.runTask(function () { return _this20.rerender(); }); this.assertText('Who overcomes by force hath overcome but half his foe'); phrase = 'believes his'; this.runTask(function () { return helper.recompute(); }); this.assertText('Who believes his force hath overcome but half his foe'); phrase = 'overcomes by'; this.runTask(function () { return helper.recompute(); }); this.assertText('Who overcomes by force hath overcome but half his foe'); }; _class.prototype['@test class-based helper used in subexpression can recompute component'] = function () { var _this21 = this; var helper = void 0; var phrase = 'overcomes by'; this.registerHelper('dynamic-segment', { init: function () { this._super.apply(this, arguments); helper = this; }, compute: function () { return phrase; } }); this.registerHelper('join-words', { compute: function (params) { return params.join(' '); } }); this.registerComponent('some-component', { template: '{{first}} {{second}} {{third}} {{fourth}} {{fifth}}' }); this.render('{{some-component first="Who"\n second=(dynamic-segment)\n third="force"\n fourth=(join-words (join-words "hath overcome but" "half"))\n fifth=(join-words "his" (join-words "foe"))}}'); this.assertText('Who overcomes by force hath overcome but half his foe'); this.runTask(function () { return _this21.rerender(); }); this.assertText('Who overcomes by force hath overcome but half his foe'); phrase = 'believes his'; this.runTask(function () { return helper.recompute(); }); this.assertText('Who believes his force hath overcome but half his foe'); phrase = 'overcomes by'; this.runTask(function () { return helper.recompute(); }); this.assertText('Who overcomes by force hath overcome but half his foe'); }; _class.prototype['@test class-based helper used in subexpression is destroyed'] = function () { var destroyCount = 0; this.registerHelper('dynamic-segment', { phrase: 'overcomes by', init: function () { this._super.apply(this, arguments); }, compute: function () { return this.phrase; }, destroy: function () { destroyCount++; this._super.apply(this, arguments); } }); this.registerHelper('join-words', { compute: function (params) { return params.join(' '); } }); this.render('{{join-words "Who"\n (dynamic-segment)\n "force"\n (join-words (join-words "hath overcome but" "half"))\n (join-words "his" (join-words "foe"))}}'); (0, _internalTestHelpers.runDestroy)(this.component); equal(destroyCount, 1, 'destroy is called after a view is destroyed'); }; return _class; }(_testCase.RenderingTest)); // these feature detects prevent errors in these tests // on platforms (*cough* IE9 *cough*) that do not // property support `Object.freeze` var pushingIntoFrozenArrayThrows = function () { var array = []; Object.freeze(array); try { array.push('foo'); return false; } catch (e) { return true; } }(); var assigningExistingFrozenPropertyThrows = function () { var obj = { foo: 'asdf' }; Object.freeze(obj); try { obj.foo = 'derp'; return false; } catch (e) { return true; } }(); var addingPropertyToFrozenObjectThrows = function () { var obj = { foo: 'asdf' }; Object.freeze(obj); try { obj.bar = 'derp'; return false; } catch (e) { return true; } }(); if (!EmberDev.runningProdBuild && _emberUtils.HAS_NATIVE_WEAKMAP && (pushingIntoFrozenArrayThrows || assigningExistingFrozenPropertyThrows || addingPropertyToFrozenObjectThrows)) { HelperMutatingArgsTests = function (_RenderingTest2) { (0, _emberBabel.inherits)(HelperMutatingArgsTests, _RenderingTest2); function HelperMutatingArgsTests() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments)); } HelperMutatingArgsTests.prototype.buildCompute = function () { var _this23 = this; return function (params, hash) { if (pushingIntoFrozenArrayThrows) { _this23.assert.throws(function () { params.push('foo'); // cannot assert error message as it varies by platform }); } if (assigningExistingFrozenPropertyThrows) { _this23.assert.throws(function () { hash.foo = 'bar'; // cannot assert error message as it varies by platform }); } if (addingPropertyToFrozenObjectThrows) { _this23.assert.throws(function () { hash.someUnusedHashProperty = 'bar'; // cannot assert error message as it varies by platform }); } }; }; HelperMutatingArgsTests.prototype['@test cannot mutate params - no positional specified / named specified'] = function () { this.render('{{test-helper foo=bar}}', { bar: 'derp' }); }; HelperMutatingArgsTests.prototype['@test cannot mutate params - positional specified / no named specified'] = function () { this.render('{{test-helper bar}}', { bar: 'derp' }); }; HelperMutatingArgsTests.prototype['@test cannot mutate params - positional specified / named specified'] = function () { this.render('{{test-helper bar foo=qux}}', { bar: 'derp', qux: 'baz' }); }; HelperMutatingArgsTests.prototype['@test cannot mutate params - no positional specified / no named specified'] = function () { this.render('{{test-helper}}', { bar: 'derp', qux: 'baz' }); }; return HelperMutatingArgsTests; }(_testCase.RenderingTest); (0, _testCase.moduleFor)('Helpers test: mutation triggers errors - class based helper', function (_HelperMutatingArgsTe) { (0, _emberBabel.inherits)(_class2, _HelperMutatingArgsTe); function _class2() { var _this24 = (0, _emberBabel.possibleConstructorReturn)(this, _HelperMutatingArgsTe.call(this)); var compute = _this24.buildCompute(); _this24.registerHelper('test-helper', { compute: compute }); return _this24; } return _class2; }(HelperMutatingArgsTests)); (0, _testCase.moduleFor)('Helpers test: mutation triggers errors - simple helper', function (_HelperMutatingArgsTe2) { (0, _emberBabel.inherits)(_class3, _HelperMutatingArgsTe2); function _class3() { var _this25 = (0, _emberBabel.possibleConstructorReturn)(this, _HelperMutatingArgsTe2.call(this)); var compute = _this25.buildCompute(); _this25.registerHelper('test-helper', compute); return _this25; } return _class3; }(HelperMutatingArgsTests)); } }); enifed('ember-glimmer/tests/integration/helpers/element-action-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal', 'ember-runtime', 'ember-views'], function (_emberBabel, _testCase, _abstractTestCase, _helpers, _emberMetal, _emberRuntime, _emberViews) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#inner-component}}\n \n {{/inner-component}}\n '], ['\n {{#inner-component}}\n \n {{/inner-component}}\n ']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#target-component as |parent|}}\n {{other-component anotherTarget=parent}}\n {{/target-component}}\n '], ['\n {{#target-component as |parent|}}\n {{other-component anotherTarget=parent}}\n {{/target-component}}\n ']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#target-component as |aTarget|}}\n click me\n {{/target-component}}\n '], ['\n {{#target-component as |aTarget|}}\n click me\n {{/target-component}}\n ']), _templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n click me'], ['\n click me']), _templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#middle-component}}\n {{inner-component action="hey"}}\n {{/middle-component}}\n '], ['\n {{#middle-component}}\n {{inner-component action="hey"}}\n {{/middle-component}}\n ']), _templateObject6 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n {{yield}}\n '], ['\n \n {{yield}}\n ']); function getActionAttributes(element) { var attributes = element.attributes, i, attr; var actionAttrs = []; for (i = 0; i < attributes.length; i++) { attr = attributes.item(i); if (attr.name.indexOf('data-ember-action-') === 0) { actionAttrs.push(attr.name); } } return actionAttrs; } function getActionIds(element) { return getActionAttributes(element).map(function (attribute) { return attribute.slice('data-ember-action-'.length); }); } (0, _testCase.moduleFor)('Helpers test: element action', function (_RenderingTest2) { (0, _emberBabel.inherits)(_class2, _RenderingTest2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments)); } _class2.prototype['@test it can call an action on its enclosing component'] = function () { var _this4 = this; var fooCallCount = 0; var ExampleComponent = _helpers.Component.extend({ actions: { foo: function () { fooCallCount++; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '' }); this.render('{{example-component}}'); this.assert.equal(fooCallCount, 0, 'foo has not been called'); this.runTask(function () { return _this4.rerender(); }); this.assert.equal(fooCallCount, 0, 'foo has not been called'); this.runTask(function () { _this4.$('button').click(); }); this.assert.equal(fooCallCount, 1, 'foo has been called 1 time'); this.runTask(function () { _this4.$('button').click(); }); this.assert.equal(fooCallCount, 2, 'foo has been called 2 times'); }; _class2.prototype['@test it can call an action with parameters'] = function () { var _this5 = this; var fooArgs = []; var component = void 0; var ExampleComponent = _helpers.Component.extend({ member: 'a', init: function () { this._super.apply(this, arguments); component = this; }, actions: { foo: function (thing) { fooArgs.push(thing); } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '' }); this.render('{{example-component}}'); this.assert.deepEqual(fooArgs, [], 'foo has not been called'); this.runTask(function () { return _this5.rerender(); }); this.assert.deepEqual(fooArgs, [], 'foo has not been called'); this.runTask(function () { _this5.$('button').click(); }); this.assert.deepEqual(fooArgs, ['a'], 'foo has not been called'); this.runTask(function () { component.set('member', 'b'); }); this.runTask(function () { _this5.$('button').click(); }); this.assert.deepEqual(fooArgs, ['a', 'b'], 'foo has been called with an updated value'); }; _class2.prototype['@test it should output a marker attribute with a guid'] = function () { this.render(''); var button = this.$('button'); var attributes = getActionAttributes(button.get(0)); this.assert.ok(button.attr('data-ember-action').match(''), 'An empty data-ember-action attribute was added'); this.assert.ok(attributes[0].match(/data-ember-action-\d+/), 'A data-ember-action-xyz attribute with a guid was added'); }; _class2.prototype['@test it should allow alternative events to be handled'] = function () { var _this6 = this; var showCalled = false; var ExampleComponent = _helpers.Component.extend({ actions: { show: function () { showCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '
' }); this.render('{{example-component}}'); this.runTask(function () { var event = _emberViews.jQuery.Event('mouseup'); _this6.$('#show').trigger(event); }); this.assert.ok(showCalled, 'show action was called on mouseUp'); }; _class2.prototype['@test inside a yield, the target points at the original target'] = function () { var _this7 = this; var targetWatted = false; var innerWatted = false; var TargetComponent = _helpers.Component.extend({ actions: { wat: function () { targetWatted = true; } } }); var InnerComponent = _helpers.Component.extend({ actions: { wat: function () { innerWatted = true; } } }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: '{{yield}}' }); this.registerComponent('target-component', { ComponentClass: TargetComponent, template: (0, _abstractTestCase.strip)(_templateObject) }); this.render('{{target-component}}'); this.runTask(function () { _this7.$('button').click(); }); this.assert.ok(targetWatted, 'the correct target was watted'); this.assert.notOk(innerWatted, 'the inner target was not watted'); }; _class2.prototype['@test it should allow a target to be specified'] = function () { var _this8 = this; var targetWatted = false; var TargetComponent = _helpers.Component.extend({ actions: { wat: function () { targetWatted = true; } } }); var OtherComponent = _helpers.Component.extend({}); this.registerComponent('target-component', { ComponentClass: TargetComponent, template: '{{yield this}}' }); this.registerComponent('other-component', { ComponentClass: OtherComponent, template: 'Wat?' }); this.render((0, _abstractTestCase.strip)(_templateObject2)); this.runTask(function () { _this8.$('a').click(); }); this.assert.equal(targetWatted, true, 'the specified target was watted'); }; _class2.prototype['@test it should lazily evaluate the target'] = function () { var _this9 = this; var firstEdit = 0; var secondEdit = 0; var component = void 0; var second = { edit: function () { secondEdit++; } }; var ExampleComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, theTarget: { edit: function () { firstEdit++; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'Edit' }); this.render('{{example-component}}'); this.runTask(function () { _this9.$('a').click(); }); this.assert.equal(firstEdit, 1); this.runTask(function () { (0, _emberMetal.set)(component, 'theTarget', second); }); this.runTask(function () { _this9.$('a').click(); }); this.assert.equal(firstEdit, 1); this.assert.equal(secondEdit, 1); }; _class2.prototype['@test it should register an event handler'] = function () { var _this10 = this; var editHandlerWasCalled = false; var shortcutHandlerWasCalled = false; var ExampleComponent = _helpers.Component.extend({ actions: { edit: function () { editHandlerWasCalled = true; }, shortcut: function () { shortcutHandlerWasCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'click me
click me too
' }); this.render('{{example-component}}'); this.runTask(function () { var event = _emberViews.jQuery.Event('click'); event.altKey = true; _this10.$('a[data-ember-action]').trigger(event); }); this.assert.equal(editHandlerWasCalled, true, 'the event handler was called'); this.runTask(function () { var event = _emberViews.jQuery.Event('click'); event.ctrlKey = true; _this10.$('div[data-ember-action]').trigger(event); }); this.assert.equal(shortcutHandlerWasCalled, true, 'the "any" shortcut\'s event handler was called'); }; _class2.prototype['@test it handles whitelisted bound modifier keys'] = function () { var _this11 = this; var editHandlerWasCalled = false; var shortcutHandlerWasCalled = false; var ExampleComponent = _helpers.Component.extend({ altKey: 'alt', anyKey: 'any', actions: { edit: function () { editHandlerWasCalled = true; }, shortcut: function () { shortcutHandlerWasCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'click me
click me too
' }); this.render('{{example-component}}'); this.runTask(function () { var event = _emberViews.jQuery.Event('click'); event.altKey = true; _this11.$('a[data-ember-action]').trigger(event); }); this.assert.equal(editHandlerWasCalled, true, 'the event handler was called'); this.runTask(function () { var event = _emberViews.jQuery.Event('click'); event.ctrlKey = true; _this11.$('div[data-ember-action]').trigger(event); }); this.assert.equal(shortcutHandlerWasCalled, true, 'the "any" shortcut\'s event handler was called'); }; _class2.prototype['@test it handles whitelisted bound modifier keys with current value'] = function () { var _this12 = this; var editHandlerWasCalled = false; var component = void 0; var ExampleComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, acceptedKeys: 'alt', actions: { edit: function () { editHandlerWasCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'click me' }); this.render('{{example-component}}'); this.runTask(function () { var event = _emberViews.jQuery.Event('click'); event.altKey = true; _this12.$('a[data-ember-action]').trigger(event); }); this.assert.equal(editHandlerWasCalled, true, 'the event handler was called'); editHandlerWasCalled = false; this.runTask(function () { component.set('acceptedKeys', ''); }); this.runTask(function () { var event = _emberViews.jQuery.Event('click'); _this12.$('div[data-ember-action]').trigger(event); }); this.assert.equal(editHandlerWasCalled, false, 'the event handler was not called'); }; _class2.prototype['@test should be able to use action more than once for the same event within a view'] = function () { var _this13 = this; var editHandlerWasCalled = false; var deleteHandlerWasCalled = false; var originalHandlerWasCalled = false; var component = void 0; var ExampleComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, actions: { edit: function () { editHandlerWasCalled = true; }, 'delete': function () { deleteHandlerWasCalled = true; } }, click: function () { originalHandlerWasCalled = true; } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'editdelete' }); this.render('{{example-component}}'); this.runTask(function () { _this13.$('#edit').click(); }); this.assert.equal(editHandlerWasCalled, true, 'the edit action was called'); this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called'); this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called (due to bubbling)'); editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false; this.runTask(function () { _this13.$('#delete').click(); }); this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called'); this.assert.equal(deleteHandlerWasCalled, true, 'the delete action was called'); this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called (due to bubbling)'); editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false; this.runTask(function () { component.$().click(); }); this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called'); this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called'); this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called'); }; _class2.prototype['@test the event should not bubble if `bubbles=false` is passed'] = function () { var _this14 = this; var editHandlerWasCalled = false; var deleteHandlerWasCalled = false; var originalHandlerWasCalled = false; var component = void 0; var ExampleComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, actions: { edit: function () { editHandlerWasCalled = true; }, 'delete': function () { deleteHandlerWasCalled = true; } }, click: function () { originalHandlerWasCalled = true; } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'editdelete' }); this.render('{{example-component}}'); this.runTask(function () { _this14.$('#edit').click(); }); this.assert.equal(editHandlerWasCalled, true, 'the edit action was called'); this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called'); this.assert.equal(originalHandlerWasCalled, false, 'the click handler was not called'); editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false; this.runTask(function () { _this14.$('#delete').click(); }); this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called'); this.assert.equal(deleteHandlerWasCalled, true, 'the delete action was called'); this.assert.equal(originalHandlerWasCalled, false, 'the click handler was not called'); editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false; this.runTask(function () { component.$().click(); }); this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called'); this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called'); this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called'); }; _class2.prototype['@test the event should not bubble if `bubbles=false` is passed bound'] = function () { var _this15 = this; var editHandlerWasCalled = false; var deleteHandlerWasCalled = false; var originalHandlerWasCalled = false; var component = void 0; var ExampleComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, isFalse: false, actions: { edit: function () { editHandlerWasCalled = true; }, 'delete': function () { deleteHandlerWasCalled = true; } }, click: function () { originalHandlerWasCalled = true; } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'editdelete' }); this.render('{{example-component}}'); this.runTask(function () { _this15.$('#edit').click(); }); this.assert.equal(editHandlerWasCalled, true, 'the edit action was called'); this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called'); this.assert.equal(originalHandlerWasCalled, false, 'the click handler was not called'); editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false; this.runTask(function () { _this15.$('#delete').click(); }); this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called'); this.assert.equal(deleteHandlerWasCalled, true, 'the delete action was called'); this.assert.equal(originalHandlerWasCalled, false, 'the click handler was not called'); editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false; this.runTask(function () { component.$().click(); }); this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called'); this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called'); this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called'); }; _class2.prototype['@test the bubbling depends on the bound parameter'] = function () { var _this16 = this; var editHandlerWasCalled = false; var originalHandlerWasCalled = false; var component = void 0; var ExampleComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, shouldBubble: false, actions: { edit: function () { editHandlerWasCalled = true; } }, click: function () { originalHandlerWasCalled = true; } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'edit' }); this.render('{{example-component}}'); this.runTask(function () { _this16.$('#edit').click(); }); this.assert.equal(editHandlerWasCalled, true, 'the edit action was called'); this.assert.equal(originalHandlerWasCalled, false, 'the click handler was not called'); editHandlerWasCalled = originalHandlerWasCalled = false; this.runTask(function () { component.set('shouldBubble', true); }); this.runTask(function () { _this16.$('#edit').click(); }); this.assert.equal(editHandlerWasCalled, true, 'the edit action was called'); this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called'); }; _class2.prototype['@test it should work properly in an #each block'] = function () { var _this17 = this; var editHandlerWasCalled = false; var ExampleComponent = _helpers.Component.extend({ items: (0, _emberRuntime.A)([1, 2, 3, 4]), actions: { edit: function () { editHandlerWasCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '{{#each items as |item|}}click me{{/each}}' }); this.render('{{example-component}}'); this.runTask(function () { _this17.$('a').click(); }); this.assert.equal(editHandlerWasCalled, true, 'the event handler was called'); }; _class2.prototype['@test it should work properly in a {{#with foo as |bar|}} block'] = function () { var _this18 = this; var editHandlerWasCalled = false; var ExampleComponent = _helpers.Component.extend({ something: { ohai: 'there' }, actions: { edit: function () { editHandlerWasCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '{{#with something as |somethingElse|}}click me{{/with}}' }); this.render('{{example-component}}'); this.runTask(function () { _this18.$('a').click(); }); this.assert.equal(editHandlerWasCalled, true, 'the event handler was called'); }; _class2.prototype['@test it should unregister event handlers when an element action is removed'] = function () { var _this19 = this; var ExampleComponent = _helpers.Component.extend({ actions: { edit: function () {} } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '{{#if isActive}}click me{{/if}}' }); this.render('{{example-component isActive=isActive}}', { isActive: true }); equal(this.$('a[data-ember-action]').length, 1, 'The element is rendered'); var actionId = void 0; actionId = getActionIds(this.$('a[data-ember-action]').get(0))[0]; ok(_emberViews.ActionManager.registeredActions[actionId], 'An action is registered'); this.runTask(function () { return _this19.rerender(); }); equal(this.$('a[data-ember-action]').length, 1, 'The element is still present'); ok(_emberViews.ActionManager.registeredActions[actionId], 'The action is still registered'); this.runTask(function () { return (0, _emberMetal.set)(_this19.context, 'isActive', false); }); strictEqual(this.$('a[data-ember-action]').length, 0, 'The element is removed'); ok(!_emberViews.ActionManager.registeredActions[actionId], 'The action is unregistered'); this.runTask(function () { return (0, _emberMetal.set)(_this19.context, 'isActive', true); }); equal(this.$('a[data-ember-action]').length, 1, 'The element is rendered'); actionId = getActionIds(this.$('a[data-ember-action]').get(0))[0]; ok(_emberViews.ActionManager.registeredActions[actionId], 'A new action is registered'); }; _class2.prototype['@test it should capture events from child elements and allow them to trigger the action'] = function () { var _this20 = this; var editHandlerWasCalled = false; var ExampleComponent = _helpers.Component.extend({ actions: { edit: function () { editHandlerWasCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '
' }); this.render('{{example-component}}'); this.runTask(function () { _this20.$('button').click(); }); this.assert.ok(editHandlerWasCalled, 'event on a child target triggered the action of its parent'); }; _class2.prototype['@test it should allow bubbling of events from action helper to original parent event'] = function () { var _this21 = this; var editHandlerWasCalled = false; var originalHandlerWasCalled = false; var ExampleComponent = _helpers.Component.extend({ actions: { edit: function () { editHandlerWasCalled = true; } }, click: function () { originalHandlerWasCalled = true; } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'click me' }); this.render('{{example-component}}'); this.runTask(function () { _this21.$('a').click(); }); this.assert.ok(editHandlerWasCalled && originalHandlerWasCalled, 'both event handlers were called'); }; _class2.prototype['@test it should not bubble an event from action helper to original parent event if `bubbles=false` is passed'] = function () { var _this22 = this; var editHandlerWasCalled = false; var originalHandlerWasCalled = false; var ExampleComponent = _helpers.Component.extend({ actions: { edit: function () { editHandlerWasCalled = true; } }, click: function () { originalHandlerWasCalled = true; } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'click me' }); this.render('{{example-component}}'); this.runTask(function () { _this22.$('a').click(); }); this.assert.ok(editHandlerWasCalled, 'the child event handler was called'); this.assert.notOk(originalHandlerWasCalled, 'the parent handler was not called'); }; _class2.prototype['@test it should allow "send" as the action name (#594)'] = function () { var _this23 = this; var sendHandlerWasCalled = false; var ExampleComponent = _helpers.Component.extend({ actions: { send: function () { sendHandlerWasCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'click me' }); this.render('{{example-component}}'); this.runTask(function () { _this23.$('a').click(); }); this.assert.ok(sendHandlerWasCalled, 'the event handler was called'); }; _class2.prototype['@test it should send the view, event, and current context to the action'] = function () { var _this24 = this; var passedTarget = void 0; var passedContext = void 0; var targetThis = void 0; var TargetComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); targetThis = this; }, actions: { edit: function (context) { passedTarget = this === targetThis; passedContext = context; } } }); var aContext = void 0; var ExampleComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); aContext = this; } }); this.registerComponent('target-component', { ComponentClass: TargetComponent, template: '{{yield this}}' }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: (0, _abstractTestCase.strip)(_templateObject3) }); this.render('{{example-component}}'); this.runTask(function () { _this24.$('#edit').click(); }); this.assert.ok(passedTarget, 'the action is called with the target as this'); this.assert.strictEqual(passedContext, aContext, 'the parameter is passed along'); }; _class2.prototype['@test it should only trigger actions for the event they were registered on'] = function () { var _this25 = this; var editHandlerWasCalled = false; var ExampleComponent = _helpers.Component.extend({ actions: { edit: function () { editHandlerWasCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'click me' }); this.render('{{example-component}}'); this.runTask(function () { _this25.$('a').click(); }); this.assert.ok(editHandlerWasCalled, 'the event handler was called on click'); editHandlerWasCalled = false; this.runTask(function () { _this25.$('a').trigger('mouseover'); }); this.assert.notOk(editHandlerWasCalled, 'the event handler was not called on mouseover'); }; _class2.prototype['@test it should allow multiple contexts to be specified'] = function () { var _this26 = this; var passedContexts = void 0; var models = [_emberRuntime.Object.create(), _emberRuntime.Object.create()]; var ExampleComponent = _helpers.Component.extend({ modelA: models[0], modelB: models[1], actions: { edit: function () { var _len, args, _key; for (_len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } passedContexts = args; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '' }); this.render('{{example-component}}'); this.runTask(function () { _this26.$('button').click(); }); this.assert.deepEqual(passedContexts, models, 'the action was called with the passed contexts'); }; _class2.prototype['@test it should allow multiple contexts to be specified mixed with string args'] = function () { var _this27 = this; var passedContexts = void 0; var model = _emberRuntime.Object.create(); var ExampleComponent = _helpers.Component.extend({ model: model, actions: { edit: function () { var _len2, args, _key2; for (_len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } passedContexts = args; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '' }); this.render('{{example-component}}'); this.runTask(function () { _this27.$('button').click(); }); this.assert.deepEqual(passedContexts, ['herp', model], 'the action was called with the passed contexts'); }; _class2.prototype['@test it should not trigger action with special clicks'] = function () { var showCalled = false; var component = void 0; var ExampleComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, actions: { show: function () { showCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '' }); this.render('{{example-component}}'); var assert = this.assert; function checkClick(prop, value, expected) { var event = _emberViews.jQuery.Event('click'); event[prop] = value; component.$('button').trigger(event); if (expected) { assert.ok(showCalled, 'should call action with ' + prop + ':' + value); assert.ok(event.isDefaultPrevented(), 'should prevent default'); } else { assert.notOk(showCalled, 'should not call action with ' + prop + ':' + value); assert.notOk(event.isDefaultPrevented(), 'should not prevent default'); } } checkClick('ctrlKey', true, false); checkClick('altKey', true, false); checkClick('metaKey', true, false); checkClick('shiftKey', true, false); checkClick('which', 2, false); checkClick('which', 1, true); checkClick('which', undefined, true); // IE <9 }; _class2.prototype['@test it can trigger actions for keyboard events'] = function () { var _this28 = this; var showCalled = false; var ExampleComponent = _helpers.Component.extend({ actions: { show: function () { showCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '' }); this.render('{{example-component}}'); this.runTask(function () { var event = _emberViews.jQuery.Event('keyup'); event.char = 'a'; event.which = 65; _this28.$('input').trigger(event); }); this.assert.ok(showCalled, 'the action was called with keyup'); }; _class2.prototype['@test a quoteless parameter should allow dynamic lookup of the actionName'] = function () { var lastAction = void 0; var actionOrder = []; var component = void 0; var ExampleComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, hookMeUp: 'rock', actions: { rock: function () { lastAction = 'rock'; actionOrder.push('rock'); }, paper: function () { lastAction = 'paper'; actionOrder.push('paper'); }, scissors: function () { lastAction = 'scissors'; actionOrder.push('scissors'); } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'Whistle tips go woop woooop' }); this.render('{{example-component}}'); var test = this; function testBoundAction(propertyValue) { test.runTask(function () { component.set('hookMeUp', propertyValue); }); test.runTask(function () { component.$('#bound-param').click(); }); test.assert.ok(lastAction, propertyValue, 'lastAction set to ' + propertyValue); } testBoundAction('rock'); testBoundAction('paper'); testBoundAction('scissors'); this.assert.deepEqual(actionOrder, ['rock', 'paper', 'scissors'], 'action name was looked up properly'); }; _class2.prototype['@test a quoteless string parameter should resolve actionName, including path'] = function () { var lastAction = void 0; var actionOrder = []; var component = void 0; var ExampleComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); component = this; }, allactions: (0, _emberRuntime.A)([{ title: 'Rock', name: 'rock' }, { title: 'Paper', name: 'paper' }, { title: 'Scissors', name: 'scissors' }]), actions: { rock: function () { lastAction = 'rock'; actionOrder.push('rock'); }, paper: function () { lastAction = 'paper'; actionOrder.push('paper'); }, scissors: function () { lastAction = 'scissors'; actionOrder.push('scissors'); } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '{{#each allactions as |allaction|}}{{allaction.title}}{{/each}}' }); this.render('{{example-component}}'); var test = this; function testBoundAction(propertyValue) { test.runTask(function () { component.$('#' + propertyValue).click(); }); test.assert.ok(lastAction, propertyValue, 'lastAction set to ' + propertyValue); } testBoundAction('rock'); testBoundAction('paper'); testBoundAction('scissors'); this.assert.deepEqual(actionOrder, ['rock', 'paper', 'scissors'], 'action name was looked up properly'); }; _class2.prototype['@test a quoteless function parameter should be called, including arguments'] = function () { var _this29 = this; var submitCalled = false; var incomingArg = void 0; var arg = 'rough ray'; var ExampleComponent = _helpers.Component.extend({ submit: function (actualArg) { incomingArg = actualArg; submitCalled = true; } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'Hi' }); this.render('{{example-component}}'); this.runTask(function () { _this29.$('a').click(); }); this.assert.ok(submitCalled, 'submit function called'); this.assert.equal(incomingArg, arg, 'argument passed'); }; _class2.prototype['@test a quoteless parameter that does not resolve to a value asserts'] = function () { var _this30 = this; var ExampleComponent = _helpers.Component.extend({ actions: { ohNoeNotValid: function () {} } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'Hi' }); expectAssertion(function () { _this30.render('{{example-component}}'); }, 'You specified a quoteless path, `ohNoeNotValid`, to the {{action}} helper ' + 'which did not resolve to an action name (a string). ' + 'Perhaps you meant to use a quoted actionName? (e.g. {{action "ohNoeNotValid"}}).'); }; _class2.prototype['@test allows multiple actions on a single element'] = function () { var _this31 = this; var clickActionWasCalled = false; var doubleClickActionWasCalled = false; var ExampleComponent = _helpers.Component.extend({ actions: { clicked: function () { clickActionWasCalled = true; }, doubleClicked: function () { doubleClickActionWasCalled = true; } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: (0, _abstractTestCase.strip)(_templateObject4) }); this.render('{{example-component}}'); this.runTask(function () { _this31.$('a').trigger('click'); }); this.assert.ok(clickActionWasCalled, 'the clicked action was called'); this.runTask(function () { _this31.$('a').trigger('dblclick'); }); this.assert.ok(doubleClickActionWasCalled, 'the doubleClicked action was called'); }; _class2.prototype['@test it should respect preventDefault option if provided'] = function () { var _this32 = this; var ExampleComponent = _helpers.Component.extend({ actions: { show: function () {} } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'Hi' }); this.render('{{example-component}}'); var event = _emberViews.jQuery.Event('click'); this.runTask(function () { _this32.$('a').trigger(event); }); this.assert.equal(event.isDefaultPrevented(), false, 'should not preventDefault'); }; _class2.prototype['@test it should respect preventDefault option if provided bound'] = function () { var _this33 = this; var component = void 0; var ExampleComponent = _helpers.Component.extend({ shouldPreventDefault: false, init: function () { this._super.apply(this, arguments); component = this; }, actions: { show: function () {} } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: 'Hi' }); this.render('{{example-component}}'); var event = _emberViews.jQuery.Event('click'); this.runTask(function () { _this33.$('a').trigger(event); }); this.assert.equal(event.isDefaultPrevented(), false, 'should not preventDefault'); event = _emberViews.jQuery.Event('click'); this.runTask(function () { component.set('shouldPreventDefault', true); _this33.$('a').trigger(event); }); this.assert.equal(event.isDefaultPrevented(), true, 'should preventDefault'); }; _class2.prototype['@test it should target the proper component when `action` is in yielded block [GH #12409]'] = function () { var _this34 = this; var outerActionCalled = false; var innerClickCalled = false; var OuterComponent = _helpers.Component.extend({ actions: { hey: function () { outerActionCalled = true; } } }); var MiddleComponent = _helpers.Component.extend({}); var InnerComponent = _helpers.Component.extend({ click: function () { innerClickCalled = true; this.sendAction(); } }); this.registerComponent('outer-component', { ComponentClass: OuterComponent, template: (0, _abstractTestCase.strip)(_templateObject5) }); this.registerComponent('middle-component', { ComponentClass: MiddleComponent, template: '{{yield}}' }); this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: (0, _abstractTestCase.strip)(_templateObject6) }); this.render('{{outer-component}}'); this.runTask(function () { _this34.$('button').click(); }); this.assert.ok(outerActionCalled, 'the action fired on the proper target'); this.assert.ok(innerClickCalled, 'the click was triggered'); }; _class2.prototype['@test element action with (mut undefinedThing) works properly'] = function () { var _this35 = this; var component = void 0; var ExampleComponent = _helpers.Component.extend({ label: undefined, init: function () { this._super.apply(this, arguments); component = this; } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '' }); this.render('{{example-component}}'); this.assertText('Click me'); this.assertStableRerender(); this.runTask(function () { _this35.$('button').click(); }); this.assertText('Clicked!'); this.runTask(function () { component.set('label', 'Dun clicked'); }); this.assertText('Dun clicked'); this.runTask(function () { _this35.$('button').click(); }); this.assertText('Clicked!'); this.runTask(function () { component.set('label', undefined); }); this.assertText('Click me'); }; _class2.prototype['@test it supports non-registered actions [GH#14888]'] = function () { this.render('\n {{#if show}}\n \n {{/if}}\n ', { show: true }); this.assert.equal(this.$('button').text().trim(), 'Show (true)'); // We need to focus in to simulate an actual click. this.runTask(function () { document.getElementById('ddButton').focus(); document.getElementById('ddButton').click(); }); }; _class2.prototype['@test action handler that shifts element attributes doesn\'t trigger multiple invocations'] = function () { var _this36 = this; var actionCount = 0; var ExampleComponent = _helpers.Component.extend({ selected: false, actions: { toggleSelected: function () { actionCount++; this.toggleProperty('selected'); } } }); this.registerComponent('example-component', { ComponentClass: ExampleComponent, template: '' }); this.render('{{example-component}}'); this.runTask(function () { _this36.$('button').click(); }); this.assert.equal(actionCount, 1, 'Click action only fired once.'); this.assert.ok(this.$('button').hasClass('selected'), 'Element with action handler has properly updated it\'s conditional class'); this.runTask(function () { _this36.$('button').click(); }); this.assert.equal(actionCount, 2, 'Second click action only fired once.'); this.assert.ok(!this.$('button').hasClass('selected'), 'Element with action handler has properly updated it\'s conditional class'); }; return _class2; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/get-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal'], function (_emberBabel, _testCase, _helpers, _emberMetal) { 'use strict'; (0, _testCase.moduleFor)('Helpers test: {{get}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test should be able to get an object value with a static key'] = function () { var _this2 = this; this.render('[{{get colors \'apple\'}}] [{{if true (get colors \'apple\')}}]', { colors: { apple: 'red' } }); this.assertText('[red] [red]'); this.runTask(function () { return _this2.rerender(); }); this.assertText('[red] [red]'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'colors.apple', 'green'); }); this.assertText('[green] [green]'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'colors', { apple: 'red' }); }); this.assertText('[red] [red]'); }; _class.prototype['@test should be able to get an object value with nested static key'] = function () { var _this3 = this; this.render('[{{get colors "apple.gala"}}] [{{if true (get colors "apple.gala")}}]', { colors: { apple: { gala: 'red and yellow' } } }); this.assertText('[red and yellow] [red and yellow]'); this.runTask(function () { return _this3.rerender(); }); this.assertText('[red and yellow] [red and yellow]'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'colors.apple.gala', 'yellow and red striped'); }); this.assertText('[yellow and red striped] [yellow and red striped]'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'colors', { apple: { gala: 'red and yellow' } }); }); this.assertText('[red and yellow] [red and yellow]'); }; _class.prototype['@test should be able to get an object value with a bound/dynamic key'] = function () { var _this4 = this; this.render('[{{get colors key}}] [{{if true (get colors key)}}]', { colors: { apple: 'red', banana: 'yellow' }, key: 'apple' }); this.assertText('[red] [red]'); this.runTask(function () { return _this4.rerender(); }); this.assertText('[red] [red]'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'key', 'banana'); }); this.assertText('[yellow] [yellow]'); this.runTask(function () { (0, _emberMetal.set)(_this4.context, 'colors.apple', 'green'); (0, _emberMetal.set)(_this4.context, 'colors.banana', 'purple'); }); this.assertText('[purple] [purple]'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'key', 'apple'); }); this.assertText('[green] [green]'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'colors', { apple: 'red' }); }); this.assertText('[red] [red]'); }; _class.prototype['@test should be able to get an object value with nested dynamic key'] = function () { var _this5 = this; this.render('[{{get colors key}}] [{{if true (get colors key)}}]', { colors: { apple: { gala: 'red and yellow', mcintosh: 'red' }, banana: 'yellow' }, key: 'apple.gala' }); this.assertText('[red and yellow] [red and yellow]'); this.runTask(function () { return _this5.rerender(); }); this.assertText('[red and yellow] [red and yellow]'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'key', 'apple.mcintosh'); }); this.assertText('[red] [red]'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'key', 'banana'); }); this.assertText('[yellow] [yellow]'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'key', 'apple.gala'); }); this.assertText('[red and yellow] [red and yellow]'); }; _class.prototype['@test should be able to get an object value with subexpression returning nested key'] = function () { var _this6 = this; this.render('[{{get colors (concat \'apple\' \'.\' \'gala\')}}] [{{if true (get colors (concat \'apple\' \'.\' \'gala\'))}}]', { colors: { apple: { gala: 'red and yellow', mcintosh: 'red' } }, key: 'apple.gala' }); this.assertText('[red and yellow] [red and yellow]'); this.runTask(function () { return _this6.rerender(); }); this.assertText('[red and yellow] [red and yellow]'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'colors.apple.gala', 'yellow and red striped'); }); this.assertText('[yellow and red striped] [yellow and red striped]'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'colors.apple.gala', 'yellow-redish'); }); this.assertText('[yellow-redish] [yellow-redish]'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'colors', { apple: { gala: 'red and yellow', mcintosh: 'red' } }); }); this.assertText('[red and yellow] [red and yellow]'); }; _class.prototype['@test should be able to get an object value with a get helper as the key'] = function () { var _this7 = this; this.render('[{{get colors (get possibleKeys key)}}] [{{if true (get colors (get possibleKeys key))}}]', { colors: { apple: 'red', banana: 'yellow' }, key: 'key1', possibleKeys: { key1: 'apple', key2: 'banana' } }); this.assertText('[red] [red]'); this.runTask(function () { return _this7.rerender(); }); this.assertText('[red] [red]'); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'key', 'key2'); }); this.assertText('[yellow] [yellow]'); this.runTask(function () { (0, _emberMetal.set)(_this7.context, 'colors.apple', 'green'); (0, _emberMetal.set)(_this7.context, 'colors.banana', 'purple'); }); this.assertText('[purple] [purple]'); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'key', 'key1'); }); this.assertText('[green] [green]'); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'colors', { apple: 'red', banana: 'yellow' }); }); this.assertText('[red] [red]'); }; _class.prototype['@test should be able to get an object value with a get helper value as a bound/dynamic key'] = function () { var _this8 = this; this.render('[{{get (get possibleValues objectKey) key}}] [{{if true (get (get possibleValues objectKey) key)}}]', { possibleValues: { colors1: { apple: 'red', banana: 'yellow' }, colors2: { apple: 'green', banana: 'purple' } }, objectKey: 'colors1', key: 'apple' }); this.assertText('[red] [red]'); this.runTask(function () { return _this8.rerender(); }); this.assertText('[red] [red]'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'objectKey', 'colors2'); }); this.assertText('[green] [green]'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'objectKey', 'colors1'); }); this.assertText('[red] [red]'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'key', 'banana'); }); this.assertText('[yellow] [yellow]'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'objectKey', 'colors2'); }); this.assertText('[purple] [purple]'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'objectKey', 'colors1'); }); this.assertText('[yellow] [yellow]'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'key', 'apple'); }); }; _class.prototype['@test should be able to get an object value with a get helper as the value and a get helper as the key'] = function () { var _this9 = this; this.render('[{{get (get possibleValues objectKey) (get possibleKeys key)}}] [{{if true (get (get possibleValues objectKey) (get possibleKeys key))}}]', { possibleValues: { colors1: { apple: 'red', banana: 'yellow' }, colors2: { apple: 'green', banana: 'purple' } }, objectKey: 'colors1', possibleKeys: { key1: 'apple', key2: 'banana' }, key: 'key1' }); this.assertText('[red] [red]'); this.runTask(function () { return _this9.rerender(); }); this.assertText('[red] [red]'); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'objectKey', 'colors2'); }); this.assertText('[green] [green]'); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'objectKey', 'colors1'); }); this.assertText('[red] [red]'); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'key', 'key2'); }); this.assertText('[yellow] [yellow]'); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'objectKey', 'colors2'); }); this.assertText('[purple] [purple]'); this.runTask(function () { (0, _emberMetal.set)(_this9.context, 'objectKey', 'colors1'); (0, _emberMetal.set)(_this9.context, 'key', 'key1'); }); this.assertText('[red] [red]'); }; _class.prototype['@test the result of a get helper can be yielded'] = function () { var _this10 = this; var fooBarInstance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); fooBarInstance = this; this.mcintosh = 'red'; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{yield (get colors mcintosh)}}' }); this.render('{{#foo-bar colors=colors as |value|}}{{value}}{{/foo-bar}}', { colors: { red: 'banana' } }); this.assertText('banana'); this.runTask(function () { return _this10.rerender(); }); this.assertText('banana'); this.runTask(function () { (0, _emberMetal.set)(fooBarInstance, 'mcintosh', 'yellow'); (0, _emberMetal.set)(_this10.context, 'colors', { yellow: 'bus' }); }); this.assertText('bus'); this.runTask(function () { (0, _emberMetal.set)(fooBarInstance, 'mcintosh', 'red'); (0, _emberMetal.set)(_this10.context, 'colors', { red: 'banana' }); }); this.assertText('banana'); }; _class.prototype['@test should handle object values as nulls'] = function () { var _this11 = this; this.render('[{{get colors \'apple\'}}] [{{if true (get colors \'apple\')}}]', { colors: null }); this.assertText('[] []'); this.runTask(function () { return _this11.rerender(); }); this.assertText('[] []'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'colors', { apple: 'green', banana: 'purple' }); }); this.assertText('[green] [green]'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'colors', null); }); this.assertText('[] []'); }; _class.prototype['@test should handle object keys as nulls'] = function () { var _this12 = this; this.render('[{{get colors key}}] [{{if true (get colors key)}}]', { colors: { apple: 'red', banana: 'yellow' }, key: null }); this.assertText('[] []'); this.runTask(function () { return _this12.rerender(); }); this.assertText('[] []'); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'key', 'banana'); }); this.assertText('[yellow] [yellow]'); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'key', null); }); this.assertText('[] []'); }; _class.prototype['@test should handle object values and keys as nulls'] = function () { this.render('[{{get colors \'apple\'}}] [{{if true (get colors key)}}]', { colors: null, key: null }); this.assertText('[] []'); }; _class.prototype['@test get helper value should be updatable using {{input}} and (mut) - static key'] = function (assert) { var _this13 = this; this.render('{{input type=\'text\' value=(mut (get source \'banana\')) id=\'get-input\'}}', { source: { banana: 'banana' } }); assert.strictEqual(this.$('#get-input').val(), 'banana'); this.runTask(function () { return _this13.rerender(); }); assert.strictEqual(this.$('#get-input').val(), 'banana'); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'source.banana', 'yellow'); }); assert.strictEqual(this.$('#get-input').val(), 'yellow'); this.runTask(function () { return _this13.$('#get-input').val('some value').trigger('change'); }); assert.strictEqual(this.$('#get-input').val(), 'some value'); assert.strictEqual((0, _emberMetal.get)(this.context, 'source.banana'), 'some value'); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'source', { banana: 'banana' }); }); assert.strictEqual(this.$('#get-input').val(), 'banana'); }; _class.prototype['@test get helper value should be updatable using {{input}} and (mut) - dynamic key'] = function (assert) { var _this14 = this; this.render('{{input type=\'text\' value=(mut (get source key)) id=\'get-input\'}}', { source: { apple: 'apple', banana: 'banana' }, key: 'banana' }); assert.strictEqual(this.$('#get-input').val(), 'banana'); this.runTask(function () { return _this14.rerender(); }); assert.strictEqual(this.$('#get-input').val(), 'banana'); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'source.banana', 'yellow'); }); assert.strictEqual(this.$('#get-input').val(), 'yellow'); this.runTask(function () { return _this14.$('#get-input').val('some value').trigger('change'); }); assert.strictEqual(this.$('#get-input').val(), 'some value'); assert.strictEqual((0, _emberMetal.get)(this.context, 'source.banana'), 'some value'); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'key', 'apple'); }); assert.strictEqual(this.$('#get-input').val(), 'apple'); this.runTask(function () { return _this14.$('#get-input').val('some other value').trigger('change'); }); assert.strictEqual(this.$('#get-input').val(), 'some other value'); assert.strictEqual((0, _emberMetal.get)(this.context, 'source.apple'), 'some other value'); this.runTask(function () { (0, _emberMetal.set)(_this14.context, 'key', 'banana'); (0, _emberMetal.set)(_this14.context, 'source', { banana: 'banana' }); }); assert.strictEqual(this.$('#get-input').val(), 'banana'); }; _class.prototype['@test get helper value should be updatable using {{input}} and (mut) - dynamic nested key'] = function (assert) { var _this15 = this; this.render('{{input type=\'text\' value=(mut (get source key)) id=\'get-input\'}}', { source: { apple: { gala: 'gala', mcintosh: 'mcintosh' }, banana: 'banana' }, key: 'apple.mcintosh' }); assert.strictEqual(this.$('#get-input').val(), 'mcintosh'); this.runTask(function () { return _this15.rerender(); }); assert.strictEqual(this.$('#get-input').val(), 'mcintosh'); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'source.apple.mcintosh', 'red'); }); assert.strictEqual(this.$('#get-input').val(), 'red'); this.runTask(function () { return _this15.$('#get-input').val('some value').trigger('change'); }); assert.strictEqual(this.$('#get-input').val(), 'some value'); assert.strictEqual((0, _emberMetal.get)(this.context, 'source.apple.mcintosh'), 'some value'); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'key', 'apple.gala'); }); assert.strictEqual(this.$('#get-input').val(), 'gala'); this.runTask(function () { return _this15.$('#get-input').val('some other value').trigger('change'); }); assert.strictEqual(this.$('#get-input').val(), 'some other value'); assert.strictEqual((0, _emberMetal.get)(this.context, 'source.apple.gala'), 'some other value'); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'key', 'banana'); }); assert.strictEqual(this.$('#get-input').val(), 'banana'); this.runTask(function () { return _this15.$('#get-input').val('yet another value').trigger('change'); }); assert.strictEqual(this.$('#get-input').val(), 'yet another value'); assert.strictEqual((0, _emberMetal.get)(this.context, 'source.banana'), 'yet another value'); this.runTask(function () { (0, _emberMetal.set)(_this15.context, 'key', 'apple.mcintosh'); (0, _emberMetal.set)(_this15.context, 'source', { apple: { gala: 'gala', mcintosh: 'mcintosh' }, banana: 'banana' }); }); assert.strictEqual(this.$('#get-input').val(), 'mcintosh'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/hash-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal'], function (_emberBabel, _testCase, _helpers, _emberMetal) { 'use strict'; (0, _testCase.moduleFor)('Helpers test: {{hash}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test returns a hash with the right key-value'] = function () { var _this2 = this; this.render('{{#with (hash name="Sergio") as |person|}}{{person.name}}{{/with}}'); this.assertText('Sergio'); this.runTask(function () { return _this2.rerender(); }); this.assertText('Sergio'); }; _class.prototype['@test can have more than one key-value'] = function () { var _this3 = this; this.render('{{#with (hash name="Sergio" lastName="Arbeo") as |person|}}{{person.name}} {{person.lastName}}{{/with}}'); this.assertText('Sergio Arbeo'); this.runTask(function () { return _this3.rerender(); }); this.assertText('Sergio Arbeo'); }; _class.prototype['@test binds values when variables are used'] = function () { var _this4 = this; this.render('{{#with (hash name=model.firstName lastName="Arbeo") as |person|}}{{person.name}} {{person.lastName}}{{/with}}', { model: { firstName: 'Marisa' } }); this.assertText('Marisa Arbeo'); this.runTask(function () { return _this4.rerender(); }); this.assertText('Marisa Arbeo'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'model.firstName', 'Sergio'); }); this.assertText('Sergio Arbeo'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'model', { firstName: 'Marisa' }); }); this.assertText('Marisa Arbeo'); }; _class.prototype['@test binds multiple values when variables are used'] = function () { var _this5 = this; this.render('{{#with (hash name=model.firstName lastName=model.lastName) as |person|}}{{person.name}} {{person.lastName}}{{/with}}', { model: { firstName: 'Marisa', lastName: 'Arbeo' } }); this.assertText('Marisa Arbeo'); this.runTask(function () { return _this5.rerender(); }); this.assertText('Marisa Arbeo'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'model.firstName', 'Sergio'); }); this.assertText('Sergio Arbeo'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'model.lastName', 'Smith'); }); this.assertText('Sergio Smith'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'model', { firstName: 'Marisa', lastName: 'Arbeo' }); }); this.assertText('Marisa Arbeo'); }; _class.prototype['@test hash helpers can be nested'] = function () { var _this6 = this; this.render('{{#with (hash person=(hash name=model.firstName)) as |ctx|}}{{ctx.person.name}}{{/with}}', { model: { firstName: 'Balint' } }); this.assertText('Balint'); this.runTask(function () { return _this6.rerender(); }); this.assertText('Balint'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'model.firstName', 'Chad'); }); this.assertText('Chad'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'model', { firstName: 'Balint' }); }); this.assertText('Balint'); }; _class.prototype['@test should yield hash of internal properties'] = function () { var _this7 = this; var fooBarInstance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); fooBarInstance = this; this.model = { firstName: 'Chad' }; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{yield (hash firstName=model.firstName)}}' }); this.render('{{#foo-bar as |values|}}{{values.firstName}}{{/foo-bar}}'); this.assertText('Chad'); this.runTask(function () { return _this7.rerender(); }); this.assertText('Chad'); this.runTask(function () { return (0, _emberMetal.set)(fooBarInstance, 'model.firstName', 'Godfrey'); }); this.assertText('Godfrey'); this.runTask(function () { return (0, _emberMetal.set)(fooBarInstance, 'model', { firstName: 'Chad' }); }); this.assertText('Chad'); }; _class.prototype['@test should yield hash of internal and external properties'] = function () { var _this8 = this; var fooBarInstance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super(); fooBarInstance = this; this.model = { firstName: 'Chad' }; } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{yield (hash firstName=model.firstName lastName=lastName)}}' }); this.render('{{#foo-bar lastName=model.lastName as |values|}}{{values.firstName}} {{values.lastName}}{{/foo-bar}}', { model: { lastName: 'Hietala' } }); this.assertText('Chad Hietala'); this.runTask(function () { return _this8.rerender(); }); this.assertText('Chad Hietala'); this.runTask(function () { (0, _emberMetal.set)(fooBarInstance, 'model.firstName', 'Godfrey'); (0, _emberMetal.set)(_this8.context, 'model.lastName', 'Chan'); }); this.assertText('Godfrey Chan'); this.runTask(function () { (0, _emberMetal.set)(fooBarInstance, 'model', { firstName: 'Chad' }); (0, _emberMetal.set)(_this8.context, 'model', { lastName: 'Hietala' }); }); this.assertText('Chad Hietala'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/if-unless-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/shared-conditional-tests'], function (_emberBabel, _testCase, _sharedConditionalTests) { 'use strict'; (0, _testCase.moduleFor)('Helpers test: inline {{if}}', function (_IfUnlessHelperTest) { (0, _emberBabel.inherits)(_class, _IfUnlessHelperTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest.apply(this, arguments)); } _class.prototype.templateFor = function (_ref) { var cond = _ref.cond, truthy = _ref.truthy, falsy = _ref.falsy; return '{{if ' + cond + ' ' + truthy + ' ' + falsy + '}}'; }; _class.prototype['@test it raises when there are more than three arguments'] = function () { var _this2 = this; expectAssertion(function () { _this2.render('{{if condition \'a\' \'b\' \'c\'}}', { condition: true }); }, /The inline form of the `if` helper expects two or three arguments/); }; _class.prototype['@test it raises when there are less than two arguments'] = function () { var _this3 = this; expectAssertion(function () { _this3.render('{{if condition}}', { condition: true }); }, /The inline form of the `if` helper expects two or three arguments/); }; return _class; }(_sharedConditionalTests.IfUnlessHelperTest)); (0, _testCase.moduleFor)('Helpers test: nested {{if}} helpers (returning truthy values)', function (_IfUnlessHelperTest2) { (0, _emberBabel.inherits)(_class2, _IfUnlessHelperTest2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest2.apply(this, arguments)); } _class2.prototype.templateFor = function (_ref2) { var cond = _ref2.cond, truthy = _ref2.truthy, falsy = _ref2.falsy; return '{{if (if ' + cond + ' ' + cond + ' false) ' + truthy + ' ' + falsy + '}}'; }; return _class2; }(_sharedConditionalTests.IfUnlessHelperTest)); (0, _testCase.moduleFor)('Helpers test: nested {{if}} helpers (returning falsy values)', function (_IfUnlessHelperTest3) { (0, _emberBabel.inherits)(_class3, _IfUnlessHelperTest3); function _class3() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest3.apply(this, arguments)); } _class3.prototype.templateFor = function (_ref3) { var cond = _ref3.cond, truthy = _ref3.truthy, falsy = _ref3.falsy; return '{{if (if ' + cond + ' true ' + cond + ') ' + truthy + ' ' + falsy + '}}'; }; return _class3; }(_sharedConditionalTests.IfUnlessHelperTest)); (0, _testCase.moduleFor)('Helpers test: {{if}} used with another helper', function (_IfUnlessHelperTest4) { (0, _emberBabel.inherits)(_class4, _IfUnlessHelperTest4); function _class4() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest4.apply(this, arguments)); } _class4.prototype.wrapperFor = function (templates) { return '{{concat ' + templates.join(' ') + '}}'; }; _class4.prototype.templateFor = function (_ref4) { var cond = _ref4.cond, truthy = _ref4.truthy, falsy = _ref4.falsy; return '(if ' + cond + ' ' + truthy + ' ' + falsy + ')'; }; return _class4; }(_sharedConditionalTests.IfUnlessHelperTest)); (0, _testCase.moduleFor)('Helpers test: {{if}} used in attribute position', function (_IfUnlessHelperTest5) { (0, _emberBabel.inherits)(_class5, _IfUnlessHelperTest5); function _class5() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest5.apply(this, arguments)); } _class5.prototype.wrapperFor = function (templates) { return '
'; }; _class5.prototype.templateFor = function (_ref5) { var cond = _ref5.cond, truthy = _ref5.truthy, falsy = _ref5.falsy; return '{{if ' + cond + ' ' + truthy + ' ' + falsy + '}}'; }; _class5.prototype.textValue = function () { return this.$('div').attr('data-foo'); }; return _class5; }(_sharedConditionalTests.IfUnlessHelperTest)); (0, _testCase.moduleFor)('Helpers test: inline {{if}} and {{unless}} without the inverse argument', function (_IfUnlessHelperTest6) { (0, _emberBabel.inherits)(_class6, _IfUnlessHelperTest6); function _class6() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest6.apply(this, arguments)); } _class6.prototype.templateFor = function (_ref6) { var cond = _ref6.cond, truthy = _ref6.truthy, falsy = _ref6.falsy; return '{{if ' + cond + ' ' + truthy + '}}{{unless ' + cond + ' ' + falsy + '}}'; }; return _class6; }(_sharedConditionalTests.IfUnlessHelperTest)); (0, _testCase.moduleFor)('Helpers test: inline {{unless}}', function (_IfUnlessHelperTest7) { (0, _emberBabel.inherits)(_class7, _IfUnlessHelperTest7); function _class7() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest7.apply(this, arguments)); } _class7.prototype.templateFor = function (_ref7) { var cond = _ref7.cond, truthy = _ref7.truthy, falsy = _ref7.falsy; return '{{unless ' + cond + ' ' + falsy + ' ' + truthy + '}}'; }; _class7.prototype['@test it raises when there are more than three arguments'] = function () { var _this10 = this; expectAssertion(function () { _this10.render('{{unless condition \'a\' \'b\' \'c\'}}', { condition: true }); }, /The inline form of the `unless` helper expects two or three arguments/); }; _class7.prototype['@test it raises when there are less than two arguments'] = function () { var _this11 = this; expectAssertion(function () { _this11.render('{{unless condition}}', { condition: true }); }, /The inline form of the `unless` helper expects two or three arguments/); }; return _class7; }(_sharedConditionalTests.IfUnlessHelperTest)); (0, _testCase.moduleFor)('Helpers test: nested {{unless}} helpers (returning truthy values)', function (_IfUnlessHelperTest8) { (0, _emberBabel.inherits)(_class8, _IfUnlessHelperTest8); function _class8() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest8.apply(this, arguments)); } _class8.prototype.templateFor = function (_ref8) { var cond = _ref8.cond, truthy = _ref8.truthy, falsy = _ref8.falsy; return '{{unless (unless ' + cond + ' false ' + cond + ') ' + falsy + ' ' + truthy + '}}'; }; return _class8; }(_sharedConditionalTests.IfUnlessHelperTest)); (0, _testCase.moduleFor)('Helpers test: nested {{unless}} helpers (returning falsy values)', function (_IfUnlessHelperTest9) { (0, _emberBabel.inherits)(_class9, _IfUnlessHelperTest9); function _class9() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest9.apply(this, arguments)); } _class9.prototype.templateFor = function (_ref9) { var cond = _ref9.cond, truthy = _ref9.truthy, falsy = _ref9.falsy; return '{{unless (unless ' + cond + ' ' + cond + ' true) ' + falsy + ' ' + truthy + '}}'; }; return _class9; }(_sharedConditionalTests.IfUnlessHelperTest)); (0, _testCase.moduleFor)('Helpers test: {{unless}} used with another helper', function (_IfUnlessHelperTest10) { (0, _emberBabel.inherits)(_class10, _IfUnlessHelperTest10); function _class10() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest10.apply(this, arguments)); } _class10.prototype.wrapperFor = function (templates) { return '{{concat ' + templates.join(' ') + '}}'; }; _class10.prototype.templateFor = function (_ref10) { var cond = _ref10.cond, truthy = _ref10.truthy, falsy = _ref10.falsy; return '(unless ' + cond + ' ' + falsy + ' ' + truthy + ')'; }; return _class10; }(_sharedConditionalTests.IfUnlessHelperTest)); (0, _testCase.moduleFor)('Helpers test: {{unless}} used in attribute position', function (_IfUnlessHelperTest11) { (0, _emberBabel.inherits)(_class11, _IfUnlessHelperTest11); function _class11() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest11.apply(this, arguments)); } _class11.prototype.wrapperFor = function (templates) { return '
'; }; _class11.prototype.templateFor = function (_ref11) { var cond = _ref11.cond, truthy = _ref11.truthy, falsy = _ref11.falsy; return '{{unless ' + cond + ' ' + falsy + ' ' + truthy + '}}'; }; _class11.prototype.textValue = function () { return this.$('div').attr('data-foo'); }; return _class11; }(_sharedConditionalTests.IfUnlessHelperTest)); }); enifed('ember-glimmer/tests/integration/helpers/input-test', ['ember-babel', 'ember-utils', 'ember-metal', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/test-case', 'internal-test-helpers'], function (_emberBabel, _emberUtils, _emberMetal, _helpers, _testCase, _internalTestHelpers) { 'use strict'; var InputRenderingTest = function (_RenderingTest) { (0, _emberBabel.inherits)(InputRenderingTest, _RenderingTest); function InputRenderingTest() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this)); _this.registerComponent('-text-field', { ComponentClass: _helpers.TextField }); _this.registerComponent('-checkbox', { ComponentClass: _helpers.Checkbox }); return _this; } InputRenderingTest.prototype.$input = function () { return this.$('input'); }; InputRenderingTest.prototype.inputID = function () { return this.$input().prop('id'); }; InputRenderingTest.prototype.assertDisabled = function () { this.assert.ok(this.$('input').prop('disabled'), 'The input is disabled'); }; InputRenderingTest.prototype.assertNotDisabled = function () { this.assert.ok(this.$('input').is(':not(:disabled)'), 'The input is not disabled'); }; InputRenderingTest.prototype.assertInputId = function (expectedId) { this.assert.equal(this.inputID(), expectedId, 'the input id should be `expectedId`'); }; InputRenderingTest.prototype.assertSingleInput = function () { this.assert.equal(this.$('input').length, 1, 'A single text field was inserted'); }; InputRenderingTest.prototype.assertSingleCheckbox = function () { this.assert.equal(this.$('input[type=checkbox]').length, 1, 'A single checkbox is added'); }; InputRenderingTest.prototype.assertCheckboxIsChecked = function () { this.assert.equal(this.$input().prop('checked'), true, 'the checkbox is checked'); }; InputRenderingTest.prototype.assertCheckboxIsNotChecked = function () { this.assert.equal(this.$input().prop('checked'), false, 'the checkbox is not checked'); }; InputRenderingTest.prototype.assertValue = function (expected) { this.assert.equal(this.$input().val(), expected, 'the input value should be ' + expected); }; InputRenderingTest.prototype.assertAttr = function (name, expected) { this.assert.equal(this.$input().attr(name), expected, 'the input ' + name + ' attribute has the value \'' + expected + '\''); }; InputRenderingTest.prototype.assertAllAttrs = function (names, expected) { var _this2 = this; names.forEach(function (name) { return _this2.assertAttr(name, expected); }); }; InputRenderingTest.prototype.assertSelectionRange = function (start, end) { var input = this.$input()[0]; this.assert.equal(input.selectionStart, start, 'the cursor start position should be ' + start); this.assert.equal(input.selectionEnd, end, 'the cursor end position should be ' + end); }; InputRenderingTest.prototype.triggerEvent = function (type, options) { var event = document.createEvent('Events'); event.initEvent(type, true, true); (0, _emberUtils.assign)(event, options); var element = this.$input()[0]; this.runTask(function () { element.dispatchEvent(event); }); }; return InputRenderingTest; }(_testCase.RenderingTest); (0, _testCase.moduleFor)('Helpers test: {{input}}', function (_InputRenderingTest) { (0, _emberBabel.inherits)(_class, _InputRenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest.apply(this, arguments)); } _class.prototype['@test a single text field is inserted into the DOM'] = function () { var _this4 = this; this.render('{{input type="text" value=value}}', { value: 'hello' }); var id = this.inputID(); this.assertValue('hello'); this.assertSingleInput(); this.runTask(function () { return _this4.rerender(); }); this.assertValue('hello'); this.assertSingleInput(); this.assertInputId(id); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'value', 'goodbye'); }); this.assertValue('goodbye'); this.assertSingleInput(); this.assertInputId(id); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'value', 'hello'); }); this.assertValue('hello'); this.assertSingleInput(); this.assertInputId(id); }; _class.prototype['@test default type'] = function () { var _this5 = this; this.render('{{input}}'); this.assertAttr('type', 'text'); this.runTask(function () { return _this5.rerender(); }); this.assertAttr('type', 'text'); }; _class.prototype['@test dynamic attributes'] = function () { var _this6 = this; this.render('\n {{input type="text"\n disabled=disabled\n value=value\n placeholder=placeholder\n name=name\n maxlength=maxlength\n size=size\n tabindex=tabindex\n }}', { disabled: false, value: 'Original value', placeholder: 'Original placeholder', name: 'original-name', maxlength: 10, size: 20, tabindex: 30 }); this.assertNotDisabled(); this.assertValue('Original value'); this.assertAttr('placeholder', 'Original placeholder'); this.assertAttr('name', 'original-name'); this.assertAttr('maxlength', '10'); // this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce) // this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce) this.runTask(function () { return _this6.rerender(); }); this.assertNotDisabled(); this.assertValue('Original value'); this.assertAttr('placeholder', 'Original placeholder'); this.assertAttr('name', 'original-name'); this.assertAttr('maxlength', '10'); // this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce) // this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce) this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'value', 'Updated value'); (0, _emberMetal.set)(_this6.context, 'disabled', true); (0, _emberMetal.set)(_this6.context, 'placeholder', 'Updated placeholder'); (0, _emberMetal.set)(_this6.context, 'name', 'updated-name'); (0, _emberMetal.set)(_this6.context, 'maxlength', 11); // set(this.context, 'size', 21); //NOTE: failing in IE (TEST_SUITE=sauce) // set(this.context, 'tabindex', 31); //NOTE: failing in IE (TEST_SUITE=sauce) }); this.assertDisabled(); this.assertValue('Updated value'); this.assertAttr('placeholder', 'Updated placeholder'); this.assertAttr('name', 'updated-name'); this.assertAttr('maxlength', '11'); // this.assertAttr('size', '21'); //NOTE: failing in IE (TEST_SUITE=sauce) // this.assertAttr('tabindex', '31'); //NOTE: failing in IE (TEST_SUITE=sauce) this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'value', 'Original value'); (0, _emberMetal.set)(_this6.context, 'disabled', false); (0, _emberMetal.set)(_this6.context, 'placeholder', 'Original placeholder'); (0, _emberMetal.set)(_this6.context, 'name', 'original-name'); (0, _emberMetal.set)(_this6.context, 'maxlength', 10); // set(this.context, 'size', 20); //NOTE: failing in IE (TEST_SUITE=sauce) // set(this.context, 'tabindex', 30); //NOTE: failing in IE (TEST_SUITE=sauce) }); this.assertNotDisabled(); this.assertValue('Original value'); this.assertAttr('placeholder', 'Original placeholder'); this.assertAttr('name', 'original-name'); this.assertAttr('maxlength', '10'); // this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce) // this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce) }; _class.prototype['@test static attributes'] = function () { var _this7 = this; this.render('\n {{input type="text"\n disabled=true\n value="Original value"\n placeholder="Original placeholder"\n name="original-name"\n maxlength=10\n size=20\n tabindex=30\n }}'); this.assertDisabled(); this.assertValue('Original value'); this.assertAttr('placeholder', 'Original placeholder'); this.assertAttr('name', 'original-name'); this.assertAttr('maxlength', '10'); // this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce) // this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce) this.runTask(function () { return _this7.rerender(); }); this.assertDisabled(); this.assertValue('Original value'); this.assertAttr('placeholder', 'Original placeholder'); this.assertAttr('name', 'original-name'); this.assertAttr('maxlength', '10'); // this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce) // this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce) }; _class.prototype['@test cursor selection range'] = function () { var _this8 = this; // Modifying input.selectionStart, which is utilized in the cursor tests, // causes an event in Safari. (0, _internalTestHelpers.runDestroy)(this.owner.lookup('event_dispatcher:main')); this.render('{{input type="text" value=value}}', { value: 'original' }); var input = this.$input()[0]; // See https://ember-twiddle.com/33e506329f8176ae874422644d4cc08c?openFiles=components.input-component.js%2Ctemplates.components.input-component.hbs // this.assertSelectionRange(8, 8); //NOTE: this is (0, 0) on Firefox (TEST_SUITE=sauce) this.runTask(function () { return _this8.rerender(); }); // this.assertSelectionRange(8, 8); //NOTE: this is (0, 0) on Firefox (TEST_SUITE=sauce) this.runTask(function () { input.selectionStart = 2; input.selectionEnd = 4; }); this.assertSelectionRange(2, 4); this.runTask(function () { return _this8.rerender(); }); this.assertSelectionRange(2, 4); // this.runTask(() => set(this.context, 'value', 'updated')); // // this.assertSelectionRange(7, 7); //NOTE: this fails in IE, the range is 0 -> 0 (TEST_SUITE=sauce) // // this.runTask(() => set(this.context, 'value', 'original')); // // this.assertSelectionRange(8, 8); //NOTE: this fails in IE, the range is 0 -> 0 (TEST_SUITE=sauce) }; _class.prototype['@test specifying `on="someevent" action="foo"` results in a deprecation warning'] = function () { var _this9 = this; expectDeprecation(function () { _this9.render('{{input on="focus-in" action="doFoo" value="hello"}}'); }, 'Using \'{{input on="focus-in" action="doFoo"}}\' (\'-top-level\' @ L1:C0) is deprecated. Please use \'{{input focus-in="doFoo"}}\' instead.'); }; _class.prototype['@test sends an action with `{{input action="foo"}}` when is pressed [DEPRECATED]'] = function (assert) { var _this10 = this; assert.expect(2); expectDeprecation(function () { _this10.render('{{input action=\'foo\'}}', { actions: { foo: function () { assert.ok(true, 'action was triggered'); } } }); }, /Please use '{{input enter="foo"}}' instead/); this.triggerEvent('keyup', { keyCode: 13 }); }; _class.prototype['@test sends an action with `{{input enter="foo"}}` when is pressed'] = function (assert) { assert.expect(1); this.render('{{input enter=\'foo\'}}', { actions: { foo: function () { assert.ok(true, 'action was triggered'); } } }); this.triggerEvent('keyup', { keyCode: 13 }); }; _class.prototype['@test sends an action with `{{input key-press="foo"}}` is pressed'] = function (assert) { assert.expect(1); this.render('{{input value=value key-press=\'foo\'}}', { value: 'initial', actions: { foo: function () { assert.ok(true, 'action was triggered'); } } }); this.triggerEvent('keypress', { keyCode: 65 }); }; _class.prototype['@test sends an action to the parent level when `bubbles=true` is provided'] = function (assert) { assert.expect(1); var ParentComponent = _helpers.Component.extend({ change: function () { assert.ok(true, 'bubbled upwards'); } }); this.registerComponent('x-parent', { ComponentClass: ParentComponent, template: '{{input bubbles=true}}' }); this.render('{{x-parent}}'); this.triggerEvent('change'); }; _class.prototype['@test triggers `focus-in` when focused'] = function (assert) { var _this11 = this; assert.expect(1); this.render('{{input focus-in=\'foo\'}}', { actions: { foo: function () { assert.ok(true, 'action was triggered'); } } }); this.runTask(function () { _this11.$input().trigger('focusin'); }); }; _class.prototype['@test sends `insert-newline` when is pressed'] = function (assert) { assert.expect(1); this.render('{{input insert-newline=\'foo\'}}', { actions: { foo: function () { assert.ok(true, 'action was triggered'); } } }); this.triggerEvent('keyup', { keyCode: 13 }); }; _class.prototype['@test sends an action with `{{input escape-press="foo"}}` when is pressed'] = function (assert) { assert.expect(1); this.render('{{input escape-press=\'foo\'}}', { actions: { foo: function () { assert.ok(true, 'action was triggered'); } } }); this.triggerEvent('keyup', { keyCode: 27 }); }; _class.prototype['@test sends an action with `{{input key-down="foo"}}` when a key is pressed'] = function (assert) { assert.expect(1); this.render('{{input key-down=\'foo\'}}', { actions: { foo: function () { assert.ok(true, 'action was triggered'); } } }); this.triggerEvent('keydown', { keyCode: 65 }); }; _class.prototype['@test sends an action with `{{input key-up="foo"}}` when a key is pressed'] = function (assert) { assert.expect(1); this.render('{{input key-up=\'foo\'}}', { actions: { foo: function () { assert.ok(true, 'action was triggered'); } } }); this.triggerEvent('keyup', { keyCode: 65 }); }; return _class; }(InputRenderingTest)); (0, _testCase.moduleFor)('Helpers test: {{input}} with dynamic type', function (_InputRenderingTest2) { (0, _emberBabel.inherits)(_class2, _InputRenderingTest2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest2.apply(this, arguments)); } _class2.prototype['@test a bound property can be used to determine type'] = function () { var _this13 = this; this.render('{{input type=type}}', { type: 'password' }); this.assertAttr('type', 'password'); this.runTask(function () { return _this13.rerender(); }); this.assertAttr('type', 'password'); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'type', 'text'); }); this.assertAttr('type', 'text'); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'type', 'password'); }); this.assertAttr('type', 'password'); }; _class2.prototype['@test a subexpression can be used to determine type'] = function () { var _this14 = this; this.render('{{input type=(if isTruthy trueType falseType)}}', { isTruthy: true, trueType: 'text', falseType: 'password' }); this.assertAttr('type', 'text'); this.runTask(function () { return _this14.rerender(); }); this.assertAttr('type', 'text'); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'isTruthy', false); }); this.assertAttr('type', 'password'); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'isTruthy', true); }); this.assertAttr('type', 'text'); }; return _class2; }(InputRenderingTest)); (0, _testCase.moduleFor)('Helpers test: {{input type=\'checkbox\'}}', function (_InputRenderingTest3) { (0, _emberBabel.inherits)(_class3, _InputRenderingTest3); function _class3() { return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest3.apply(this, arguments)); } _class3.prototype['@test dynamic attributes'] = function () { var _this16 = this; this.render('{{input\n type=\'checkbox\'\n disabled=disabled\n name=name\n checked=checked\n tabindex=tabindex\n }}', { disabled: false, name: 'original-name', checked: false, tabindex: 10 }); this.assertSingleCheckbox(); this.assertNotDisabled(); this.assertAttr('name', 'original-name'); this.assertAttr('tabindex', '10'); this.runTask(function () { return _this16.rerender(); }); this.assertSingleCheckbox(); this.assertNotDisabled(); this.assertAttr('name', 'original-name'); this.assertAttr('tabindex', '10'); this.runTask(function () { (0, _emberMetal.set)(_this16.context, 'disabled', true); (0, _emberMetal.set)(_this16.context, 'name', 'updated-name'); (0, _emberMetal.set)(_this16.context, 'tabindex', 11); }); this.assertSingleCheckbox(); this.assertDisabled(); this.assertAttr('name', 'updated-name'); this.assertAttr('tabindex', '11'); this.runTask(function () { (0, _emberMetal.set)(_this16.context, 'disabled', false); (0, _emberMetal.set)(_this16.context, 'name', 'original-name'); (0, _emberMetal.set)(_this16.context, 'tabindex', 10); }); this.assertSingleCheckbox(); this.assertNotDisabled(); this.assertAttr('name', 'original-name'); this.assertAttr('tabindex', '10'); }; _class3.prototype['@test `value` property assertion'] = function () { var _this17 = this; expectAssertion(function () { _this17.render('{{input type="checkbox" value=value}}', { value: 'value' }); }, /you must use `checked=/); }; _class3.prototype['@test with a bound type'] = function () { var _this18 = this; this.render('{{input type=inputType checked=isChecked}}', { inputType: 'checkbox', isChecked: true }); this.assertSingleCheckbox(); this.assertCheckboxIsChecked(); this.runTask(function () { return _this18.rerender(); }); this.assertCheckboxIsChecked(); this.runTask(function () { return (0, _emberMetal.set)(_this18.context, 'isChecked', false); }); this.assertCheckboxIsNotChecked(); this.runTask(function () { return (0, _emberMetal.set)(_this18.context, 'isChecked', true); }); this.assertCheckboxIsChecked(); }; _class3.prototype['@test native click changes check property'] = function () { this.render('{{input type="checkbox"}}'); this.assertSingleCheckbox(); this.assertCheckboxIsNotChecked(); this.$input()[0].click(); this.assertCheckboxIsChecked(); this.$input()[0].click(); this.assertCheckboxIsNotChecked(); }; _class3.prototype['@test with static values'] = function () { var _this19 = this; this.render('{{input type="checkbox" disabled=false tabindex=10 name="original-name" checked=false}}'); this.assertSingleCheckbox(); this.assertCheckboxIsNotChecked(); this.assertNotDisabled(); this.assertAttr('tabindex', '10'); this.assertAttr('name', 'original-name'); this.runTask(function () { return _this19.rerender(); }); this.assertSingleCheckbox(); this.assertCheckboxIsNotChecked(); this.assertNotDisabled(); this.assertAttr('tabindex', '10'); this.assertAttr('name', 'original-name'); }; return _class3; }(InputRenderingTest)); (0, _testCase.moduleFor)('Helpers test: {{input type=\'text\'}}', function (_InputRenderingTest4) { (0, _emberBabel.inherits)(_class4, _InputRenderingTest4); function _class4() { return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest4.apply(this, arguments)); } _class4.prototype['@test null values'] = function () { var _this21 = this; var attributes = ['disabled', 'placeholder', 'name', 'maxlength', 'size', 'tabindex']; this.render('\n {{input type="text"\n disabled=disabled\n value=value\n placeholder=placeholder\n name=name\n maxlength=maxlength\n size=size\n tabindex=tabindex\n }}', { disabled: null, value: null, placeholder: null, name: null, maxlength: null, size: null, tabindex: null }); this.assertValue(''); this.assertAllAttrs(attributes, undefined); this.runTask(function () { return _this21.rerender(); }); this.assertValue(''); this.assertAllAttrs(attributes, undefined); this.runTask(function () { (0, _emberMetal.set)(_this21.context, 'disabled', true); (0, _emberMetal.set)(_this21.context, 'value', 'Updated value'); (0, _emberMetal.set)(_this21.context, 'placeholder', 'Updated placeholder'); (0, _emberMetal.set)(_this21.context, 'name', 'updated-name'); (0, _emberMetal.set)(_this21.context, 'maxlength', 11); (0, _emberMetal.set)(_this21.context, 'size', 21); (0, _emberMetal.set)(_this21.context, 'tabindex', 31); }); this.assertDisabled(); this.assertValue('Updated value'); this.assertAttr('placeholder', 'Updated placeholder'); this.assertAttr('name', 'updated-name'); this.assertAttr('maxlength', '11'); this.assertAttr('size', '21'); this.assertAttr('tabindex', '31'); this.runTask(function () { (0, _emberMetal.set)(_this21.context, 'disabled', null); (0, _emberMetal.set)(_this21.context, 'value', null); (0, _emberMetal.set)(_this21.context, 'placeholder', null); (0, _emberMetal.set)(_this21.context, 'name', null); (0, _emberMetal.set)(_this21.context, 'maxlength', null); // set(this.context, 'size', null); //NOTE: this fails with `Error: Failed to set the 'size' property on 'HTMLInputElement': The value provided is 0, which is an invalid size.` (TEST_SUITE=sauce) (0, _emberMetal.set)(_this21.context, 'tabindex', null); }); this.assertAttr('disabled', undefined); this.assertValue(''); // this.assertAttr('placeholder', undefined); //NOTE: this fails with a value of "null" (TEST_SUITE=sauce) // this.assertAttr('name', undefined); //NOTE: this fails with a value of "null" (TEST_SUITE=sauce) this.assertAttr('maxlength', undefined); // this.assertAttr('size', undefined); //NOTE: re-enable once `size` bug above has been addressed this.assertAttr('tabindex', undefined); }; return _class4; }(InputRenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/loc-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal', 'ember'], function (_emberBabel, _testCase, _emberMetal, _ember) { 'use strict'; (0, _testCase.moduleFor)('Helpers test: {{loc}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this)); _this.oldString = _ember.default.STRINGS; _ember.default.STRINGS = { 'Hello Friend': 'Hallo Freund', 'Hello': 'Hallo, %@' }; return _this; } _class.prototype.teardown = function () { _RenderingTest.prototype.teardown.call(this); _ember.default.STRINGS = this.oldString; }; _class.prototype['@test it lets the original value through by default'] = function () { var _this2 = this; this.render('{{loc "Hiya buddy!"}}'); this.assertText('Hiya buddy!', 'the unlocalized string is correct'); this.runTask(function () { return _this2.rerender(); }); this.assertText('Hiya buddy!', 'the unlocalized string is correct after rerender'); }; _class.prototype['@test it localizes a simple string'] = function () { var _this3 = this; this.render('{{loc "Hello Friend"}}'); this.assertText('Hallo Freund', 'the localized string is correct'); this.runTask(function () { return _this3.rerender(); }); this.assertText('Hallo Freund', 'the localized string is correct after rerender'); }; _class.prototype['@test it takes passed formats into an account'] = function () { var _this4 = this; this.render('{{loc "%@, %@" "Hello" "Mr. Pitkin"}}'); this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct'); this.runTask(function () { return _this4.rerender(); }); this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct after rerender'); }; _class.prototype['@test it updates when bound params change'] = function () { var _this5 = this; this.render('{{loc simple}} - {{loc personal \'Mr. Pitkin\'}}', { simple: 'Hello Friend', personal: 'Hello' }); this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct'); this.runTask(function () { return _this5.rerender(); }); this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after rerender'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'simple', 'G\'day mate'); }); this.assertText('G\'day mate - Hallo, Mr. Pitkin', 'the bound value is correct after update'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'simple', 'Hello Friend'); }); this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after reset'); }; _class.prototype['@test it updates when nested bound params change'] = function () { var _this6 = this; this.render('{{loc greetings.simple}} - {{loc greetings.personal \'Mr. Pitkin\'}}', { greetings: { simple: 'Hello Friend', personal: 'Hello' } }); this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct'); this.runTask(function () { return _this6.rerender(); }); this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after rerender'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'greetings.simple', 'G\'day mate'); }); this.assertText('G\'day mate - Hallo, Mr. Pitkin', 'the bound value is correct after interior mutation'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'greetings', { simple: 'Hello Friend', personal: 'Hello' }); }); this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after replacement'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/log-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-console'], function (_emberBabel, _testCase, _emberConsole) { 'use strict'; (0, _testCase.moduleFor)('Helpers test: {{log}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this)); _this.originalLog = _emberConsole.default.log; _this.logCalls = []; _emberConsole.default.log = function () { var _this$logCalls; (_this$logCalls = _this.logCalls).push.apply(_this$logCalls, arguments); }; return _this; } _class.prototype.teardown = function () { _RenderingTest.prototype.teardown.call(this); _emberConsole.default.log = this.originalLog; }; _class.prototype.assertLog = function (values) { var i, len; this.assertText(''); this.assert.strictEqual(this.logCalls.length, values.length); for (i = 0, len = values.length; i < len; i++) { this.assert.strictEqual(this.logCalls[i], values[i]); } }; _class.prototype['@test correctly logs primitives'] = function () { this.render('{{log "one" 1 true}}'); this.assertLog(['one', 1, true]); }; _class.prototype['@test correctly logs a property'] = function () { this.render('{{log value}}', { value: 'one' }); this.assertLog(['one']); }; _class.prototype['@test correctly logs multiple arguments'] = function () { this.render('{{log "my variable:" value}}', { value: 'one' }); this.assertLog(['my variable:', 'one']); }; _class.prototype['@test correctly logs `this`'] = function () { this.render('{{log this}}'); this.assertLog([this.context]); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/mut-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal', 'ember-glimmer/tests/utils/test-helpers'], function (_emberBabel, _testCase, _helpers, _emberMetal, _testHelpers) { 'use strict'; (0, _testCase.moduleFor)('Helpers test: {{mut}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test a simple mutable binding using `mut` propagates properly'] = function () { var _this2 = this; var bottom = void 0; this.registerComponent('bottom-mut', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { bottom = this; } }), template: '{{setMe}}' }); this.registerComponent('middle-mut', { template: '{{bottom-mut setMe=value}}' }); this.render('{{middle-mut value=(mut val)}}', { val: 12 }); this.assertText('12', 'the data propagated downwards'); this.assertStableRerender(); this.runTask(function () { return bottom.attrs.setMe.update(13); }); this.assertText('13', 'the set took effect'); this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 13, 'the set took effect on bottom\'s prop'); this.assert.strictEqual(bottom.attrs.setMe.value, 13, 'the set took effect on bottom\'s attr'); this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 13, 'the set propagated back up'); this.runTask(function () { return (0, _emberMetal.set)(bottom, 'setMe', 14); }); this.assertText('14', 'the set took effect'); this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 14, 'the set took effect on bottom\'s prop'); this.assert.strictEqual(bottom.attrs.setMe.value, 14, 'the set took effect on bottom\'s attr'); this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 14, 'the set propagated back up'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'val', 12); }); this.assertText('12'); }; _class.prototype['@test a simple mutable binding using `mut` inserts into the DOM'] = function () { var _this3 = this; var bottom = void 0, middle = void 0; this.registerComponent('bottom-mut', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { bottom = this; } }), template: '{{setMe}}' }); this.registerComponent('middle-mut', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { middle = this; } }), template: '{{bottom-mut setMe=(mut value)}}' }); this.render('{{middle-mut value=(mut val)}}', { val: 12 }); this.assertText('12', 'the data propagated downwards'); this.assertStableRerender(); this.runTask(function () { return bottom.attrs.setMe.update(13); }); this.assertText('13', 'the set took effect'); this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 13, 'the set took effect on bottom\'s prop'); this.assert.strictEqual(bottom.attrs.setMe.value, 13, 'the set took effect on bottom\'s attr'); this.assert.strictEqual((0, _emberMetal.get)(middle, 'value'), 13, 'the set propagated to middle\'s prop'); this.assert.strictEqual(middle.attrs.value.value, 13, 'the set propagated to middle\'s attr'); this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 13, 'the set propagated back up'); this.runTask(function () { return (0, _emberMetal.set)(bottom, 'setMe', 14); }); this.assertText('14', 'the set took effect'); this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 14, 'the set took effect on bottom\'s prop'); this.assert.strictEqual(bottom.attrs.setMe.value, 14, 'the set took effect on bottom\'s attr'); this.assert.strictEqual((0, _emberMetal.get)(middle, 'value'), 14, 'the set propagated to middle\'s prop'); this.assert.strictEqual(middle.attrs.value.value, 14, 'the set propagated to middle\'s attr'); this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 14, 'the set propagated back up'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'val', 12); }); this.assertText('12'); }; _class.prototype['@test passing a literal results in a assertion'] = function () { var _this4 = this; this.registerComponent('bottom-mut', { template: '{{setMe}}' }); expectAssertion(function () { _this4.render('{{bottom-mut setMe=(mut "foo bar")}}'); }, 'You can only pass a path to mut'); }; _class.prototype['@test passing the result of a helper invocation results in an assertion'] = function () { var _this5 = this; this.registerComponent('bottom-mut', { template: '{{setMe}}' }); expectAssertion(function () { _this5.render('{{bottom-mut setMe=(mut (concat "foo" " " "bar"))}}'); }, 'You can only pass a path to mut'); }; _class.prototype['@test using a string value through middle tier does not trigger assertion (due to the auto-mut transform)'] = function () { var bottom = void 0; this.registerComponent('bottom-mut', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { bottom = this; } }), template: '{{stuff}}' }); this.registerComponent('middle-mut', { template: '{{bottom-mut stuff=value}}' }); this.render('{{middle-mut value="foo"}}'); this.assert.equal((0, _emberMetal.get)(bottom, 'stuff'), 'foo', 'the data propagated'); this.assertText('foo'); this.assertStableRerender(); // No U-R for this test }; _class.prototype['@test {{readonly}} of a {{mut}} is converted into an immutable binding'] = function () { var _this6 = this; var middle = void 0, bottom = void 0; this.registerComponent('bottom-mut', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { bottom = this; } }), template: '{{setMe}}' }); this.registerComponent('middle-mut', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { middle = this; } }), template: '{{bottom-mut setMe=(readonly value)}}' }); this.render('{{middle-mut value=(mut val)}}', { val: 12 }); this.assertText('12'); this.assertStableRerender(); this.runTask(function () { return middle.attrs.value.update(13); }); this.assert.strictEqual((0, _emberMetal.get)(middle, 'value'), 13, 'the set took effect on middle\'s prop'); this.assert.strictEqual(middle.attrs.value.value, 13, 'the set took effect on middle\'s attr'); this.runTask(function () { return (0, _emberMetal.set)(middle, 'value', 14); }); this.assert.strictEqual((0, _emberMetal.get)(middle, 'value'), 14, 'the set took effect on middle\'s prop'); this.assert.strictEqual(middle.attrs.value.value, 14, 'the set took effect on middle\'s attr'); this.assert.strictEqual(bottom.attrs.setMe, 14, 'the mutable binding has been converted to an immutable cell'); this.assertText('14'); this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 14, 'the set propagated back up'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'val', 12); }); this.assertText('12'); }; _class.prototype['@test mutable bindings work inside of yielded content'] = function () { var _this7 = this; this.registerComponent('bottom-mut', { template: '{{yield}}' }); this.registerComponent('middle-mut', { template: '{{#bottom-mut}}{{model.name}}{{/bottom-mut}}' }); this.render('{{middle-mut model=(mut model)}}', { model: { name: 'Matthew Beale' } }); this.assertText('Matthew Beale'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'model.name', 'Joel Kang'); }); this.assertText('Joel Kang'); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'model', { name: 'Matthew Beale' }); }); this.assertText('Matthew Beale'); }; _class.prototype['@test a simple mutable binding using {{mut}} is available in hooks'] = function () { var _this8 = this; var bottom = void 0; var willRender = []; var didInsert = []; this.registerComponent('bottom-mut', { ComponentClass: _helpers.Component.extend({ willRender: function () { willRender.push((0, _emberMetal.get)(this, 'setMe')); }, didInsertElement: function () { didInsert.push((0, _emberMetal.get)(this, 'setMe')); bottom = this; } }), template: '{{setMe}}' }); this.registerComponent('middle-mut', { template: '{{bottom-mut setMe=(mut value)}}' }); this.render('{{middle-mut value=(mut val)}}', { val: 12 }); this.assert.deepEqual(willRender, [12], 'willReceive is [12]'); this.assert.deepEqual(didInsert, [12], 'didInsert is [12]'); this.assertText('12'); this.assertStableRerender(); this.assert.deepEqual(willRender, [12], 'willReceive is [12]'); this.assert.deepEqual(didInsert, [12], 'didInsert is [12]'); this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 12, 'the data propagated'); this.runTask(function () { return bottom.attrs.setMe.update(13); }); this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 13, 'the set took effect on bottom\'s prop'); this.assert.strictEqual(bottom.attrs.setMe.value, 13, 'the set took effect on bottom\'s attr'); this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 13, 'the set propagated back up'); this.runTask(function () { return (0, _emberMetal.set)(bottom, 'setMe', 14); }); this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 14, 'the set took effect on bottom\'s prop'); this.assert.strictEqual(bottom.attrs.setMe.value, 14, 'the set took effect on bottom\'s attr'); this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 14, 'the set propagated back up'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'val', 12); }); this.assertText('12'); }; _class.prototype['@test a mutable binding with a backing computed property and attribute present in the root of the component is updated when the upstream property invalidates #11023'] = function () { var bottom = void 0, middle = void 0; this.registerComponent('bottom-mut', { ComponentClass: _helpers.Component.extend({ thingy: null, didInsertElement: function () { bottom = this; } }), template: '{{thingy}}' }); this.registerComponent('middle-mut', { ComponentClass: _helpers.Component.extend({ baseValue: 12, val: (0, _emberMetal.computed)('baseValue', function () { return this.get('baseValue'); }), didInsertElement: function () { middle = this; } }), template: '{{bottom-mut thingy=(mut val)}}' }); this.render('{{middle-mut}}'); this.assert.strictEqual((0, _emberMetal.get)(bottom, 'thingy'), 12, 'data propagated'); this.assertText('12'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(middle, 'baseValue', 13); }); this.assert.strictEqual((0, _emberMetal.get)(middle, 'val'), 13, 'the set took effect'); this.assert.strictEqual(bottom.attrs.thingy.value, 13, 'the set propagated down to bottom\'s attrs'); this.assert.strictEqual((0, _emberMetal.get)(bottom, 'thingy'), 13, 'the set propagated down to bottom\'s prop'); this.assertText('13'); this.runTask(function () { return (0, _emberMetal.set)(middle, 'baseValue', 12); }); this.assertText('12'); }; _class.prototype['@test automatic mutable bindings exposes a mut cell in attrs'] = function () { var inner = void 0; this.registerComponent('x-inner', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { inner = this; } }), template: '{{foo}}' }); this.registerComponent('x-outer', { template: '{{x-inner foo=bar}}' }); this.render('{{x-outer bar=baz}}', { baz: 'foo' }); this.assertText('foo'); this.assertStableRerender(); this.runTask(function () { return inner.attrs.foo.update('bar'); }); this.assert.equal(inner.attrs.foo.value, 'bar'); this.assert.equal((0, _emberMetal.get)(inner, 'foo'), 'bar'); this.assertText('bar'); this.runTask(function () { return inner.attrs.foo.update('foo'); }); this.assertText('foo'); }; _class.prototype['@test automatic mutable bindings tolerate undefined non-stream inputs and attempts to set them'] = function () { var inner = void 0; this.registerComponent('x-inner', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { inner = this; } }), template: '{{model}}' }); this.registerComponent('x-outer', { template: '{{x-inner model=nonexistent}}' }); this.render('{{x-outer}}'); this.assertText(''); this.assertStableRerender(); this.runTask(function () { return inner.attrs.model.update(42); }); this.assert.equal(inner.attrs.model.value, 42); this.assert.equal((0, _emberMetal.get)(inner, 'model'), 42); this.assertText('42'); this.runTask(function () { return inner.attrs.model.update(undefined); }); this.assertText(''); }; _class.prototype['@test automatic mutable bindings tolerate constant non-stream inputs and attempts to set them'] = function () { var inner = void 0; this.registerComponent('x-inner', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { inner = this; } }), template: 'hello{{model}}' }); this.registerComponent('x-outer', { template: '{{x-inner model=x}}' }); this.render('{{x-outer x="foo"}}'); this.assertText('hellofoo'); this.assertStableRerender(); this.runTask(function () { return inner.attrs.model.update(42); }); this.assert.equal(inner.attrs.model.value, 42); this.assert.equal((0, _emberMetal.get)(inner, 'model'), 42); this.assertText('hello42'); this.runTask(function () { return inner.attrs.model.update('foo'); }); this.assertText('hellofoo'); }; return _class; }(_testCase.RenderingTest)); (0, _testCase.moduleFor)('Mutable Bindings used in Computed Properties that are bound as attributeBindings', function (_RenderingTest2) { (0, _emberBabel.inherits)(_class2, _RenderingTest2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments)); } _class2.prototype['@test an attribute binding of a computed property of a 2-way bound attr recomputes when the attr changes'] = function () { var _this10 = this; var input = void 0, output = void 0; this.registerComponent('x-input', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { input = this; } }) }); this.registerComponent('x-output', { ComponentClass: _helpers.Component.extend({ attributeBindings: ['style'], didInsertElement: function () { output = this; }, style: (0, _emberMetal.computed)('height', function () { var height = this.get('height'); return 'height: ' + height + 'px;'; }), height: 20 }), template: '{{height}}' }); this.render('{{x-output height=height}}{{x-input height=(mut height)}}', { height: 60 }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 60px;') }, content: '60' }); this.assertStableRerender(); this.runTask(function () { return input.attrs.height.update(35); }); this.assert.strictEqual((0, _emberMetal.get)(output, 'height'), 35, 'the set took effect'); this.assert.strictEqual((0, _emberMetal.get)(this.context, 'height'), 35, 'the set propagated back up'); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 35px;') }, content: '35' }); this.runTask(function () { return (0, _emberMetal.set)(input, 'height', 36); }); this.assert.strictEqual((0, _emberMetal.get)(output, 'height'), 36, 'the set took effect'); this.assert.strictEqual((0, _emberMetal.get)(this.context, 'height'), 36, 'the set propagated back up'); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 36px;') }, content: '36' }); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'height', 60); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 60px;') }, content: '60' }); this.assert.strictEqual((0, _emberMetal.get)(input, 'height'), 60); }; _class2.prototype['@test an attribute binding of a computed property with a setter of a 2-way bound attr recomputes when the attr changes'] = function () { var _this11 = this; var input = void 0, output = void 0; this.registerComponent('x-input', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { input = this; } }) }); this.registerComponent('x-output', { ComponentClass: _helpers.Component.extend({ attributeBindings: ['style'], didInsertElement: function () { output = this; }, style: (0, _emberMetal.computed)('height', 'width', function () { var height = this.get('height'); var width = this.get('width'); return 'height: ' + height + 'px; width: ' + width + 'px;'; }), height: 20, width: (0, _emberMetal.computed)('height', { get: function () { return this.get('height') * 2; }, set: function (keyName, width) { this.set('height', width / 2); return width; } }) }), template: '{{width}}x{{height}}' }); this.render('{{x-output width=width}}{{x-input width=(mut width)}}', { width: 70 }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 35px; width: 70px;') }, content: '70x35' }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(input, 'width', 80); }); this.assert.strictEqual((0, _emberMetal.get)(output, 'width'), 80, 'the set took effect'); this.assert.strictEqual((0, _emberMetal.get)(this.context, 'width'), 80, 'the set propagated back up'); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 40px; width: 80px;') }, content: '80x40' }); this.runTask(function () { return input.attrs.width.update(90); }); this.assert.strictEqual((0, _emberMetal.get)(output, 'width'), 90, 'the set took effect'); this.assert.strictEqual((0, _emberMetal.get)(this.context, 'width'), 90, 'the set propagated back up'); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 45px; width: 90px;') }, content: '90x45' }); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'width', 70); }); this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 35px; width: 70px;') }, content: '70x35' }); this.assert.strictEqual((0, _emberMetal.get)(input, 'width'), 70); }; return _class2; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/partial-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _testCase, _emberMetal, _abstractTestCase) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each model.items as |template i|}}\n {{model.type}}: {{partial template}}\n {{/each}}'], ['\n {{#each model.items as |template i|}}\n {{model.type}}: {{partial template}}\n {{/each}}']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with item.thing as |t|}}\n {{partial t}}\n {{else}}\n Nothing!\n {{/with}}'], ['\n {{#with item.thing as |t|}}\n {{partial t}}\n {{else}}\n Nothing!\n {{/with}}']); (0, _testCase.moduleFor)('Helpers test: {{partial}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test should render other templates registered with the container'] = function () { this.registerPartial('_subTemplateFromContainer', 'sub-template'); this.render('This {{partial "subTemplateFromContainer"}} is pretty great.'); this.assertStableRerender(); this.assertText('This sub-template is pretty great.'); }; _class.prototype['@test should render other slash-separated templates registered with the container'] = function () { this.registerPartial('child/_subTemplateFromContainer', 'sub-template'); this.render('This {{partial "child/subTemplateFromContainer"}} is pretty great.'); this.assertStableRerender(); this.assertText('This sub-template is pretty great.'); }; _class.prototype['@test should use the current context'] = function () { var _this2 = this; this.registerPartial('_person_name', '{{model.firstName}} {{model.lastName}}'); this.render('Who is {{partial "person_name"}}?', { model: { firstName: 'Kris', lastName: 'Selden' } }); this.assertStableRerender(); this.assertText('Who is Kris Selden?'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'model.firstName', 'Kelly'); }); this.assertText('Who is Kelly Selden?'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'model', { firstName: 'Kris', lastName: 'Selden' }); }); this.assertText('Who is Kris Selden?'); }; _class.prototype['@test Quoteless parameters passed to {{partial}} perform a bound property lookup of the partial name'] = function () { var _this3 = this; this.registerPartial('_subTemplate', 'sub-template'); this.registerPartial('_otherTemplate', 'other-template'); this.render('This {{partial templates.partialName}} is pretty {{partial nonexistent}}great.', { templates: { partialName: 'subTemplate' } }); this.assertStableRerender(); this.assertText('This sub-template is pretty great.'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'templates.partialName', 'otherTemplate'); }); this.assertText('This other-template is pretty great.'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'templates.partialName', null); }); this.assertText('This is pretty great.'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'templates', { partialName: 'subTemplate' }); }); this.assertText('This sub-template is pretty great.'); }; _class.prototype['@test dynamic partials in {{#each}}'] = function () { var _this4 = this; this.registerPartial('_odd', 'ODD{{i}}'); this.registerPartial('_even', 'EVEN{{i}}'); this.render((0, _abstractTestCase.strip)(_templateObject), { model: { items: ['even', 'odd', 'even', 'odd'], type: 'number' } }); this.assertStableRerender(); this.assertText('number: EVEN0number: ODD1number: EVEN2number: ODD3'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'model.type', 'integer'); }); this.assertText('integer: EVEN0integer: ODD1integer: EVEN2integer: ODD3'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'model', { items: ['even', 'odd', 'even', 'odd'], type: 'number' }); }); this.assertText('number: EVEN0number: ODD1number: EVEN2number: ODD3'); }; _class.prototype['@test dynamic partials in {{#with}}'] = function () { var _this5 = this; this.registerPartial('_thing', '{{t}}'); this.render((0, _abstractTestCase.strip)(_templateObject2), { item: { thing: false } }); this.assertStableRerender(); this.assertText('Nothing!'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'item.thing', 'thing'); }); this.assertText('thing'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'item', { thing: false }); }); this.assertText('Nothing!'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/readonly-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal'], function (_emberBabel, _testCase, _helpers, _emberMetal) { 'use strict'; (0, _testCase.moduleFor)('Helpers test: {{readonly}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test {{readonly}} of a path should work'] = function () { var component = void 0; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { component = this; } }), template: '{{value}}' }); this.render('{{foo-bar value=(readonly val)}}', { val: 12 }); this.assertText('12'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(component, 'value', 13); }); this.assert.notOk(component.attrs.value.update); this.assertText('13', 'local property is updated'); this.assert.equal((0, _emberMetal.get)(this.context, 'val'), 12, 'upstream attribute is not updated'); // No U-R }; _class.prototype['@test {{readonly}} of a string renders correctly'] = function () { var component = void 0; this.registerComponent('foo-bar', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { component = this; } }), template: '{{value}}' }); this.render('{{foo-bar value=(readonly "12")}}'); this.assertText('12'); this.assertStableRerender(); this.assert.notOk(component.attrs.value.update); this.assert.strictEqual((0, _emberMetal.get)(component, 'value'), '12'); this.runTask(function () { return (0, _emberMetal.set)(component, 'value', '13'); }); this.assertText('13', 'local property is updated'); this.assert.strictEqual((0, _emberMetal.get)(component, 'value'), '13'); this.runTask(function () { return (0, _emberMetal.set)(component, 'value', '12'); }); this.assertText('12'); }; _class.prototype['@test {{mut}} of a {{readonly}} mutates only the middle and bottom tiers'] = function () { var _this2 = this; var middle = void 0, bottom = void 0; this.registerComponent('x-bottom', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { bottom = this; } }), template: '{{bar}}' }); this.registerComponent('x-middle', { ComponentClass: _helpers.Component.extend({ didInsertElement: function () { middle = this; } }), template: '{{foo}} {{x-bottom bar=(mut foo)}}' }); this.render('{{x-middle foo=(readonly val)}}', { val: 12 }); this.assertText('12 12'); this.assertStableRerender(); this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), 12, 'bottom\'s local bar received the value'); this.assert.equal((0, _emberMetal.get)(middle, 'foo'), 12, 'middle\'s local foo received the value'); this.runTask(function () { return bottom.attrs.bar.update(13); }); this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), 13, 'bottom\'s local bar was updated after set of bottom\'s bar'); this.assert.equal((0, _emberMetal.get)(middle, 'foo'), 13, 'middle\'s local foo was updated after set of bottom\'s bar'); this.assertText('13 13'); this.assert.equal((0, _emberMetal.get)(this.context, 'val'), 12, 'But context val is not updated'); this.runTask(function () { return (0, _emberMetal.set)(bottom, 'bar', 14); }); this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), 14, 'bottom\'s local bar was updated after set of bottom\'s bar'); this.assert.equal((0, _emberMetal.get)(middle, 'foo'), 14, 'middle\'s local foo was updated after set of bottom\'s bar'); this.assertText('14 14'); this.assert.equal((0, _emberMetal.get)(this.context, 'val'), 12, 'But context val is not updated'); this.assert.notOk(middle.attrs.foo.update, 'middle\'s foo attr is not a mutable cell'); this.runTask(function () { return (0, _emberMetal.set)(middle, 'foo', 15); }); this.assertText('15 15'); this.assert.equal((0, _emberMetal.get)(middle, 'foo'), 15, 'set of middle\'s foo took effect'); this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), 15, 'bottom\'s local bar was updated after set of middle\'s foo'); this.assert.equal((0, _emberMetal.get)(this.context, 'val'), 12, 'Context val remains unchanged'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'val', 10); }); this.assertText('10 10'); this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), 10, 'bottom\'s local bar was updated after set of context\'s val'); this.assert.equal((0, _emberMetal.get)(middle, 'foo'), 10, 'middle\'s local foo was updated after set of context\'s val'); this.runTask(function () { return (0, _emberMetal.set)(bottom, 'bar', undefined); }); this.assertText(' '); this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), undefined, 'bottom\'s local bar was updated to a falsy value'); this.assert.equal((0, _emberMetal.get)(middle, 'foo'), undefined, 'middle\'s local foo was updated to a falsy value'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'val', 12); }); this.assertText('12 12', 'bottom and middle were both reset'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/render-test', ['ember-babel', 'ember-metal', 'ember-runtime', 'ember-glimmer/tests/utils/test-case'], function (_emberBabel, _emberMetal, _emberRuntime, _testCase) { 'use strict'; (0, _testCase.moduleFor)('Helpers test: {{render}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test should render given template'] = function () { var _this2 = this; this.registerTemplate('home', '

BYE

'); expectDeprecation(function () { _this2.render('

HI

{{render \'home\'}}'); }, /Please refactor [\w\{\}"` ]+ to a component/); this.assertText('HIBYE'); }; _class.prototype['@test uses `controller:basic` as the basis for a generated controller when none exists for specified name'] = function () { var _this3 = this; this.owner.register('controller:basic', _emberRuntime.Controller.extend({ isBasicController: true })); this.registerTemplate('home', '{{isBasicController}}'); expectDeprecation(function () { _this3.render('{{render \'home\'}}'); }, /Please refactor [\w\{\}"` ]+ to a component/); this.assertText('true'); }; _class.prototype['@test generates a controller if none exists'] = function () { var _this4 = this; this.registerTemplate('home', '

{{this}}

'); expectDeprecation(function () { _this4.render('

HI

{{render \'home\'}}'); }, /Please refactor [\w\{\}"` ]+ to a component/); this.assertText('HI(generated home controller)'); }; _class.prototype['@test should use controller with the same name as template if present'] = function () { var _this5 = this; this.owner.register('controller:home', _emberRuntime.Controller.extend({ name: 'home' })); this.registerTemplate('home', '{{name}}

BYE

'); expectDeprecation(function () { _this5.render('

HI

{{render \'home\'}}'); }, /Please refactor [\w\{\}"` ]+ to a component/); this.assertText('HIhomeBYE'); }; _class.prototype['@test should render nested helpers'] = function () { var _this6 = this; this.owner.register('controller:home', _emberRuntime.Controller.extend()); this.owner.register('controller:foo', _emberRuntime.Controller.extend()); this.owner.register('controller:bar', _emberRuntime.Controller.extend()); this.owner.register('controller:baz', _emberRuntime.Controller.extend()); this.registerTemplate('home', '

BYE

'); this.registerTemplate('baz', '

BAZ

'); expectDeprecation(function () { _this6.registerTemplate('foo', '

FOO

{{render \'bar\'}}'); _this6.registerTemplate('bar', '

BAR

{{render \'baz\'}}'); _this6.render('

HI

{{render \'foo\'}}'); }, /Please refactor [\w\{\}"` ]+ to a component/); this.assertText('HIFOOBARBAZ'); }; _class.prototype['@test should have assertion if the template does not exist'] = function () { var _this7 = this; this.owner.register('controller:oops', _emberRuntime.Controller.extend()); expectDeprecation(function () { expectAssertion(function () { _this7.render('

HI

{{render \'oops\'}}'); }, 'You used `{{render \'oops\'}}`, but \'oops\' can not be found as a template.'); }, /Please refactor [\w\{\}"` ]+ to a component/); }; _class.prototype['@test should render given template with the singleton controller as its context'] = function () { var _this8 = this; this.owner.register('controller:post', _emberRuntime.Controller.extend({ init: function () { this.set('title', 'It\'s Simple Made Easy'); } })); this.registerTemplate('post', '

{{title}}

'); expectDeprecation(function () { _this8.render('

HI

{{render \'post\'}}'); }, /Please refactor [\w\{\}"` ]+ to a component/); this.assertText('HIIt\'s Simple Made Easy'); this.runTask(function () { return _this8.rerender(); }); this.assertText('HIIt\'s Simple Made Easy'); var controller = this.owner.lookup('controller:post'); this.runTask(function () { return (0, _emberMetal.set)(controller, 'title', 'Rails is omakase'); }); this.assertText('HIRails is omakase'); this.runTask(function () { return (0, _emberMetal.set)(controller, 'title', 'It\'s Simple Made Easy'); }); this.assertText('HIIt\'s Simple Made Easy'); }; _class.prototype['@test should not destroy the singleton controller on teardown'] = function (assert) { var _this9 = this; var willDestroyFired = 0; this.owner.register('controller:post', _emberRuntime.Controller.extend({ init: function () { this.set('title', 'It\'s Simple Made Easy'); }, willDestroy: function () { this._super.apply(this, arguments); willDestroyFired++; } })); this.registerTemplate('post', '

{{title}}

'); expectDeprecation(function () { _this9.render('{{#if showPost}}{{render \'post\'}}{{else}}Nothing here{{/if}}', { showPost: false }); }, /Please refactor [\w\{\}"` ]+ to a component/); this.assertText('Nothing here'); assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller'); this.runTask(function () { return _this9.rerender(); }); this.assertText('Nothing here'); assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller'); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'showPost', true); }); this.assertText('It\'s Simple Made Easy'); assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller'); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'showPost', false); }); this.assertText('Nothing here'); assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller'); }; _class.prototype['@test should render given template with a supplied model'] = function () { var _this10 = this; this.owner.register('controller:post', _emberRuntime.Controller.extend()); this.registerTemplate('post', '

{{model.title}}

'); expectDeprecation(function () { _this10.render('

HI

{{render \'post\' post}}', { post: { title: 'It\'s Simple Made Easy' } }); }, /Please refactor [\w\{\}"` ]+ to a component/); this.assertText('HIIt\'s Simple Made Easy'); this.runTask(function () { return _this10.rerender(); }); this.assertText('HIIt\'s Simple Made Easy'); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'post.title', 'Rails is omakase'); }); this.assertText('HIRails is omakase'); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'post', { title: 'It\'s Simple Made Easy' }); }); this.assertText('HIIt\'s Simple Made Easy'); }; _class.prototype['@test should destroy the non-singleton controllers on teardown'] = function (assert) { var _this11 = this; var willDestroyFired = 0; this.owner.register('controller:post', _emberRuntime.Controller.extend({ willDestroy: function () { this._super.apply(this, arguments); willDestroyFired++; } })); this.registerTemplate('post', '

{{model.title}}

'); expectDeprecation(function () { _this11.render('{{#if showPost}}{{render \'post\' post}}{{else}}Nothing here{{/if}}', { showPost: false, post: { title: 'It\'s Simple Made Easy' } }); }, /Please refactor [\w\{\}"` ]+ to a component/); this.assertText('Nothing here'); assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller'); this.runTask(function () { return _this11.rerender(); }); this.assertText('Nothing here'); assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'showPost', true); }); this.assertText('It\'s Simple Made Easy'); assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'showPost', false); }); this.assertText('Nothing here'); assert.strictEqual(willDestroyFired, 1, 'it did destroy the controller'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'showPost', true); }); this.assertText('It\'s Simple Made Easy'); assert.strictEqual(willDestroyFired, 1, 'it did not destroy the controller'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'showPost', false); }); this.assertText('Nothing here'); assert.strictEqual(willDestroyFired, 2, 'it did destroy the controller'); }; _class.prototype['@test with a supplied model should not fire observers on the controller'] = function () { var _this12 = this; this.owner.register('controller:post', _emberRuntime.Controller.extend()); this.registerTemplate('post', '

{{model.title}}

'); var postDidChange = 0; expectDeprecation(function () { _this12.render('

HI

{{render \'post\' post}}', { postDidChange: (0, _emberMetal.observer)('post', function () { postDidChange++; }), post: { title: 'It\'s Simple Made Easy' } }); }, /Please refactor [\w\{\}"` ]+ to a component/); this.assertText('HIIt\'s Simple Made Easy'); this.runTask(function () { return _this12.rerender(); }); this.assertText('HIIt\'s Simple Made Easy'); }; _class.prototype['@test should raise an error when a given controller name does not resolve to a controller'] = function () { var _this13 = this; this.registerTemplate('home', '

BYE

'); this.owner.register('controller:posts', _emberRuntime.Controller.extend()); expectDeprecation(function () { expectAssertion(function () { _this13.render('

HI

{{render "home" controller="postss"}}'); }, /The controller name you supplied \'postss\' did not resolve to a controller./); }, /Please refactor [\w\{\}"` ]+ to a component/); }; _class.prototype['@test should render with given controller'] = function (assert) { var _this14 = this; this.registerTemplate('home', '{{uniqueId}}'); var id = 0; var model = {}; this.owner.register('controller:posts', _emberRuntime.Controller.extend({ init: function () { this._super.apply(this, arguments); this.uniqueId = id++; this.set('model', model); } })); expectDeprecation(function () { _this14.render('{{render "home" controller="posts"}}'); }, /Please refactor [\w\{\}"` ]+ to a component/); var renderedController = this.owner.lookup('controller:posts'); var uniqueId = renderedController.get('uniqueId'); var renderedModel = renderedController.get('model'); assert.equal(uniqueId, 0); assert.equal(renderedModel, model); this.assertText('0'); this.runTask(function () { return _this14.rerender(); }); assert.equal(uniqueId, 0); assert.equal(renderedModel, model); this.assertText('0'); }; _class.prototype['@test should render templates with models multiple times'] = function () { var _this15 = this; this.owner.register('controller:post', _emberRuntime.Controller.extend()); this.registerTemplate('post', '

{{model.title}}

'); expectDeprecation(function () { _this15.render('

HI

{{render \'post\' post1}} {{render \'post\' post2}}', { post1: { title: 'Me First' }, post2: { title: 'Then me' } }); }, /Please refactor [\w\{\}"` ]+ to a component/); this.assertText('HI Me First Then me'); this.runTask(function () { return _this15.rerender(); }); this.assertText('HI Me First Then me'); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'post1.title', 'I am new'); }); this.assertText('HI I am new Then me'); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'post1', { title: 'Me First' }); }); this.assertText('HI Me First Then me'); }; _class.prototype['@test should not treat invocations with falsy contexts as context-less'] = function (assert) { var _this16 = this; this.registerTemplate('post', '

{{#unless model.zero}}NOTHING{{/unless}}

'); this.owner.register('controller:post', _emberRuntime.Controller.extend()); expectDeprecation(function () { _this16.render('

HI

{{render \'post\' zero}} {{render \'post\' nonexistent}}', { model: { zero: false } }); }, /Please refactor [\w\{\}"` ]+ to a component/); assert.ok(this.$().text().match(/^HI ?NOTHING ?NOTHING$/)); }; _class.prototype['@test should render templates both with and without models'] = function (assert) { var _this17 = this; this.registerTemplate('post', '

Title:{{model.title}}

'); this.owner.register('controller:post', _emberRuntime.Controller.extend()); var post = { title: 'Rails is omakase' }; expectDeprecation(function () { _this17.render('

HI

{{render \'post\'}} {{render \'post\' post}}', { post: post }); }, /Please refactor [\w\{\}"` ]+ to a component/); assert.ok(this.$().text().match(/^HI ?Title: ?Title:Rails is omakase$/)); this.runTask(function () { return _this17.rerender(); }); assert.ok(this.$().text().match(/^HI ?Title: ?Title:Rails is omakase$/)); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'post.title', 'Simple Made Easy'); }); assert.ok(this.$().text().match(/^HI ?Title: ?Title:Simple Made Easy$/)); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'post', { title: 'Rails is omakase' }); }); assert.ok(this.$().text().match(/^HI ?Title: ?Title:Rails is omakase$/)); }; _class.prototype['@test works with dot notation'] = function () { var _this18 = this; this.registerTemplate('blog.post', '{{uniqueId}}'); var id = 0; this.owner.register('controller:blog.post', _emberRuntime.Controller.extend({ init: function () { this._super.apply(this, arguments); this.uniqueId = id++; } })); expectDeprecation(function () { _this18.render('{{render "blog.post"}}'); }, /Please refactor [\w\.{\}"` ]+ to a component/); this.assertText('0'); }; _class.prototype['@test throws an assertion if called with an unquoted template name'] = function () { var _this19 = this; this.registerTemplate('home', '

BYE

'); expectAssertion(function () { _this19.render('

HI

{{render home}}'); }, 'The first argument of {{render}} must be quoted, e.g. {{render "sidebar"}}.'); }; _class.prototype['@test throws an assertion if called with a literal for a model'] = function () { var _this20 = this; this.registerTemplate('home', '

BYE

'); expectAssertion(function () { _this20.render('

HI

{{render "home" "model"}}', { model: { title: 'Simple Made Easy' } }); }, 'The second argument of {{render}} must be a path, e.g. {{render "post" post}}.'); }; _class.prototype['@test should set router as target when action not found on parentController is not found'] = function (assert) { var _this21 = this; var postController = void 0; this.registerTemplate('post', 'post template'); this.owner.register('controller:post', _emberRuntime.Controller.extend({ init: function () { this._super.apply(this, arguments); postController = this; } })); this.owner.register('router:main', { send: function (actionName) { assert.equal(actionName, 'someAction'); assert.ok(true, 'routerStub#send called'); } }, { instantiate: false }); expectDeprecation(function () { _this21.render('{{render \'post\' post1}}'); }, /Please refactor [\w\{\}"` ]+ to a component/); postController.send('someAction'); }; _class.prototype['@test render helper emits useful backtracking re-render assertion message'] = function () { var _this22 = this; this.owner.register('controller:outer', _emberRuntime.Controller.extend()); this.owner.register('controller:inner', _emberRuntime.Controller.extend({ propertyWithError: (0, _emberMetal.computed)(function () { this.set('model.name', 'this will cause a backtracking error'); return 'foo'; }) })); var expectedBacktrackingMessage = /modified "model\.name" twice on \[object Object\] in a single render\. It was rendered in "controller:outer \(with the render helper\)" and modified in "controller:inner \(with the render helper\)"/; expectDeprecation(function () { var person = { name: 'Ben' }; _this22.registerTemplate('outer', 'Hi {{model.name}} | {{render \'inner\' model}}'); _this22.registerTemplate('inner', 'Hi {{propertyWithError}}'); expectAssertion(function () { _this22.render('{{render \'outer\' person}}', { person: person }); }, expectedBacktrackingMessage); }); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/text-area-test', ['ember-babel', 'ember-utils', 'ember-metal', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/test-helpers', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _emberUtils, _emberMetal, _helpers, _testCase, _testHelpers, _abstractTestCase) { 'use strict'; var TextAreaRenderingTest = function (_RenderingTest) { (0, _emberBabel.inherits)(TextAreaRenderingTest, _RenderingTest); function TextAreaRenderingTest() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this)); _this.registerComponent('-text-area', { ComponentClass: _helpers.TextArea }); return _this; } TextAreaRenderingTest.prototype.assertTextArea = function () { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, attrs = _ref.attrs, value = _ref.value; var mergedAttrs = (0, _emberUtils.assign)({ 'class': (0, _testHelpers.classes)('ember-view ember-text-area') }, attrs); this.assertComponentElement(this.firstChild, { tagName: 'textarea', attrs: mergedAttrs }); if (value) { this.assert.strictEqual(value, this.firstChild.value); } }; TextAreaRenderingTest.prototype.triggerEvent = function (type) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var event = document.createEvent('Events'); event.initEvent(type, true, true); (0, _emberUtils.assign)(event, options); this.firstChild.dispatchEvent(event); }; return TextAreaRenderingTest; }(_testCase.RenderingTest); var BoundTextAreaAttributes = function () { function BoundTextAreaAttributes(cases) { this.cases = cases; } BoundTextAreaAttributes.prototype.generate = function (_ref2) { var _ref3; var attribute = _ref2.attribute, first = _ref2.first, second = _ref2.second; return _ref3 = {}, _ref3['@test ' + attribute] = function () { var _attrs, _this2 = this, _attrs2, _attrs3; this.render('{{textarea ' + attribute + '=value}}', { value: first }); this.assertTextArea({ attrs: (_attrs = {}, _attrs[attribute] = first, _attrs) }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'value', second); }); this.assertTextArea({ attrs: (_attrs2 = {}, _attrs2[attribute] = second, _attrs2) }); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'value', first); }); this.assertTextArea({ attrs: (_attrs3 = {}, _attrs3[attribute] = first, _attrs3) }); }, _ref3; }; return BoundTextAreaAttributes; }(); (0, _abstractTestCase.applyMixins)(TextAreaRenderingTest, new BoundTextAreaAttributes([{ attribute: 'placeholder', first: 'Stuff here', second: 'Other stuff' }, { attribute: 'name', first: 'Stuff here', second: 'Other stuff' }, { attribute: 'title', first: 'Stuff here', second: 'Other stuff' }, { attribute: 'maxlength', first: '1', second: '2' }, { attribute: 'rows', first: '1', second: '2' }, { attribute: 'cols', first: '1', second: '2' }, { attribute: 'tabindex', first: '1', second: '2' }])); (0, _testCase.moduleFor)('Helpers test: {{textarea}}', function (_TextAreaRenderingTes) { (0, _emberBabel.inherits)(_class, _TextAreaRenderingTes); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _TextAreaRenderingTes.apply(this, arguments)); } _class.prototype['@test Should insert a textarea'] = function () { this.render('{{textarea}}'); equal(this.$('textarea').length, 1); this.assertStableRerender(); }; _class.prototype['@test Should respect disabled'] = function () { this.render('{{textarea disabled=disabled}}', { disabled: true }); ok(this.$('textarea').is(':disabled')); }; _class.prototype['@test Should respect disabled when false'] = function () { this.render('{{textarea disabled=disabled}}', { disabled: false }); ok(this.$('textarea').is(':not(:disabled)')); }; _class.prototype['@test Should become disabled when the context changes'] = function () { var _this4 = this; this.render('{{textarea disabled=disabled}}'); ok(this.$('textarea').is(':not(:disabled)')); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'disabled', true); }); ok(this.$('textarea').is(':disabled')); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'disabled', false); }); ok(this.$('textarea').is(':not(:disabled)')); }; _class.prototype['@test Should bind its contents to the specified value'] = function () { var _this5 = this; this.render('{{textarea value=model.val}}', { model: { val: 'A beautiful day in Seattle' } }); this.assertTextArea({ value: 'A beautiful day in Seattle' }); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'model.val', 'Auckland'); }); this.assertTextArea({ value: 'Auckland' }); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'model', { val: 'A beautiful day in Seattle' }); }); this.assertTextArea({ value: 'A beautiful day in Seattle' }); }; _class.prototype['@test GH#14001 Should correctly handle an empty string bound value'] = function () { var _this6 = this; this.render('{{textarea value=message}}', { message: '' }); this.assert.strictEqual(this.firstChild.value, ''); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'message', 'hello'); }); this.assert.strictEqual(this.firstChild.value, 'hello'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'message', ''); }); this.assert.strictEqual(this.firstChild.value, ''); }; _class.prototype['@test should update the value for `cut` / `input` / `change` events'] = function () { var _this7 = this; this.render('{{textarea value=model.val}}', { model: { val: 'A beautiful day in Seattle' } }); this.assertTextArea({ value: 'A beautiful day in Seattle' }); this.assertStableRerender(); this.runTask(function () { _this7.firstChild.value = 'Auckland'; _this7.triggerEvent('cut'); }); this.assertTextArea({ value: 'Auckland' }); this.runTask(function () { _this7.firstChild.value = 'Hope'; _this7.triggerEvent('paste'); }); this.assertTextArea({ value: 'Hope' }); this.runTask(function () { _this7.firstChild.value = 'Boston'; _this7.triggerEvent('input'); }); this.assertTextArea({ value: 'Boston' }); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'model', { val: 'A beautiful day in Seattle' }); }); this.assertTextArea({ value: 'A beautiful day in Seattle' }); }; return _class; }(TextAreaRenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/unbound-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-metal', 'ember-glimmer/tests/utils/helpers', 'ember-runtime'], function (_emberBabel, _testCase, _abstractTestCase, _emberMetal, _helpers, _emberRuntime) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n '], ['\n \n ']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{unbound (surround model.prefix model.value "bar")}} {{surround model.prefix model.value "bar"}} {{unbound (surround "bar" model.value model.suffix)}} {{surround "bar" model.value model.suffix}}'], ['\n {{unbound (surround model.prefix model.value "bar")}} {{surround model.prefix model.value "bar"}} {{unbound (surround "bar" model.value model.suffix)}} {{surround "bar" model.value model.suffix}}']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if (unbound model.foo)}}\n {{#if model.bar}}true{{/if}}\n {{#unless model.bar}}false{{/unless}}\n {{/if}}\n {{#unless (unbound model.notfoo)}}\n {{#if model.bar}}true{{/if}}\n {{#unless model.bar}}false{{/unless}}\n {{/unless}}'], ['\n {{#if (unbound model.foo)}}\n {{#if model.bar}}true{{/if}}\n {{#unless model.bar}}false{{/unless}}\n {{/if}}\n {{#unless (unbound model.notfoo)}}\n {{#if model.bar}}true{{/if}}\n {{#unless model.bar}}false{{/unless}}\n {{/unless}}']); (0, _testCase.moduleFor)('Helpers test: {{unbound}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test should be able to output a property without binding'] = function () { var _this2 = this; this.render('
{{unbound content.anUnboundString}}
', { content: { anUnboundString: 'No spans here, son.' } }); this.assertText('No spans here, son.'); this.runTask(function () { return _this2.rerender(); }); this.assertText('No spans here, son.'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'content.anUnboundString', 'HEY'); }); this.assertText('No spans here, son.'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'content', { anUnboundString: 'No spans here, son.' }); }); this.assertText('No spans here, son.'); }; _class.prototype['@test should be able to use unbound helper in #each helper'] = function () { var _this3 = this; this.render('
    {{#each items as |item|}}
  • {{unbound item}}
  • {{/each}}
', { items: (0, _emberRuntime.A)(['a', 'b', 'c', 1, 2, 3]) }); this.assertText('abc123'); this.runTask(function () { return _this3.rerender(); }); this.assertText('abc123'); }; _class.prototype['@test should be able to use unbound helper in #each helper (with objects)'] = function () { var _this4 = this; this.render('
    {{#each items as |item|}}
  • {{unbound item.wham}}
  • {{/each}}
', { items: (0, _emberRuntime.A)([{ wham: 'bam' }, { wham: 1 }]) }); this.assertText('bam1'); this.runTask(function () { return _this4.rerender(); }); this.assertText('bam1'); this.runTask(function () { return _this4.context.items.setEach('wham', 'HEY'); }); this.assertText('bam1'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'items', (0, _emberRuntime.A)([{ wham: 'bam' }, { wham: 1 }])); }); this.assertText('bam1'); }; _class.prototype['@test it should assert unbound cannot be called with multiple arguments'] = function () { var _this5 = this; expectAssertion(function () { _this5.render('{{unbound foo bar}}', { foo: 'BORK', bar: 'BLOOP' }); }, /unbound helper cannot be called with multiple params or hash params/); }; _class.prototype['@test should render on attributes'] = function () { var _this6 = this; this.render('', { model: { foo: 'BORK' } }); this.assertHTML(''); this.runTask(function () { return _this6.rerender(); }); this.assertHTML(''); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'model.foo', 'OOF'); }); this.assertHTML(''); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'model', { foo: 'BORK' }); }); this.assertHTML(''); }; _class.prototype['@test should property escape unsafe hrefs'] = function () { var _this7 = this; var unsafeUrls = (0, _emberRuntime.A)([{ name: 'Bob', url: 'javascript:bob-is-cool' // jshint ignore:line }, { name: 'James', url: 'vbscript:james-is-cool' // jshint ignore:line }, { name: 'Richard', url: 'javascript:richard-is-cool' // jshint ignore:line }]); this.render('', { people: unsafeUrls }); var escapedHtml = (0, _abstractTestCase.strip)(_templateObject); this.assertHTML(escapedHtml); this.runTask(function () { return _this7.rerender(); }); this.assertHTML(escapedHtml); this.runTask(function () { return _this7.context.people.setEach('url', 'http://google.com'); }); this.assertHTML(escapedHtml); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'people', unsafeUrls); }); this.assertHTML(escapedHtml); }; _class.prototype['@skip helper form updates on parent re-render'] = function () { var _this8 = this; this.render('{{unbound foo}}', { foo: 'BORK' }); this.assertText('BORK'); this.runTask(function () { return _this8.rerender(); }); this.assertText('BORK'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'foo', 'OOF'); }); this.assertText('BORK'); this.runTask(function () { return _this8.rerender(); }); this.assertText('OOF'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'foo', ''); }); this.assertText('OOF'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'foo', 'BORK'); }); this.runTask(function () { return _this8.rerender(); }); this.assertText('BORK'); }; _class.prototype['@test sexpr form does not update no matter what'] = function () { var _this9 = this; this.registerHelper('capitalize', function (args) { return args[0].toUpperCase(); }); this.render('{{capitalize (unbound foo)}}', { foo: 'bork' }); this.assertText('BORK'); this.runTask(function () { return _this9.rerender(); }); this.assertText('BORK'); this.runTask(function () { (0, _emberMetal.set)(_this9.context, 'foo', 'oof'); _this9.rerender(); }); this.assertText('BORK'); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'foo', 'blip'); }); this.assertText('BORK'); this.runTask(function () { (0, _emberMetal.set)(_this9.context, 'foo', 'bork'); _this9.rerender(); }); this.assertText('BORK'); }; _class.prototype['@test sexpr in helper form does not update on parent re-render'] = function () { var _this10 = this; this.registerHelper('capitalize', function (params) { return params[0].toUpperCase(); }); this.registerHelper('doublize', function (params) { return params[0] + ' ' + params[0]; }); this.render('{{capitalize (unbound (doublize foo))}}', { foo: 'bork' }); this.assertText('BORK BORK'); this.runTask(function () { return _this10.rerender(); }); this.assertText('BORK BORK'); this.runTask(function () { (0, _emberMetal.set)(_this10.context, 'foo', 'oof'); _this10.rerender(); }); this.assertText('BORK BORK'); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'foo', 'blip'); }); this.assertText('BORK BORK'); this.runTask(function () { (0, _emberMetal.set)(_this10.context, 'foo', 'bork'); _this10.rerender(); }); this.assertText('BORK BORK'); }; _class.prototype['@test should be able to render an unbound helper invocation'] = function () { var _this11 = this; this.registerHelper('repeat', function (_ref, _ref2) { var value = _ref[0]; var count = _ref2.count; var a = []; while (a.length < count) { a.push(value); } return a.join(''); }); this.render('{{unbound (repeat foo count=bar)}} {{repeat foo count=bar}} {{unbound (repeat foo count=2)}} {{repeat foo count=4}}', { foo: 'X', bar: 5 }); this.assertText('XXXXX XXXXX XX XXXX'); this.runTask(function () { return _this11.rerender(); }); this.assertText('XXXXX XXXXX XX XXXX'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'bar', 1); }); this.assertText('XXXXX X XX XXXX'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'bar', 5); }); this.assertText('XXXXX XXXXX XX XXXX'); }; _class.prototype['@test should be able to render an bound helper invocation mixed with static values'] = function () { var _this12 = this; this.registerHelper('surround', function (_ref3) { var prefix = _ref3[0], value = _ref3[1], suffix = _ref3[2]; return prefix + '-' + value + '-' + suffix; }); this.render((0, _abstractTestCase.strip)(_templateObject2), { model: { prefix: 'before', value: 'core', suffix: 'after' } }); this.assertText('before-core-bar before-core-bar bar-core-after bar-core-after'); this.runTask(function () { return _this12.rerender(); }); this.assertText('before-core-bar before-core-bar bar-core-after bar-core-after'); this.runTask(function () { (0, _emberMetal.setProperties)(_this12.context.model, { prefix: 'beforeChanged', value: 'coreChanged', suffix: 'afterChanged' }); }); this.assertText('before-core-bar beforeChanged-coreChanged-bar bar-core-after bar-coreChanged-afterChanged'); this.runTask(function () { (0, _emberMetal.set)(_this12.context, 'model', { prefix: 'before', value: 'core', suffix: 'after' }); }); this.assertText('before-core-bar before-core-bar bar-core-after bar-core-after'); }; _class.prototype['@test should be able to render unbound forms of multi-arg helpers'] = function () { var _this13 = this; this.registerHelper('fauxconcat', function (params) { return params.join(''); }); this.render('{{fauxconcat model.foo model.bar model.bing}} {{unbound (fauxconcat model.foo model.bar model.bing)}}', { model: { foo: 'a', bar: 'b', bing: 'c' } }); this.assertText('abc abc'); this.runTask(function () { return _this13.rerender(); }); this.assertText('abc abc'); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'model.bar', 'X'); }); this.assertText('aXc abc'); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'model', { foo: 'a', bar: 'b', bing: 'c' }); }); this.assertText('abc abc'); }; _class.prototype['@test should be able to render an unbound helper invocation for helpers with dependent keys'] = function () { var _this14 = this; this.registerHelper('capitalizeName', { destroy: function () { this.removeObserver('value.firstName'); this._super.apply(this, arguments); }, compute: function (_ref4) { var value = _ref4[0]; if (this.get('value')) { this.removeObserver('value.firstName'); } this.set('value', value); this.addObserver('value.firstName', this, this.recompute); return value ? (0, _emberMetal.get)(value, 'firstName').toUpperCase() : ''; } }); this.registerHelper('concatNames', { destroy: function () { this.teardown(); this._super.apply(this, arguments); }, teardown: function () { this.removeObserver('value.firstName'); this.removeObserver('value.lastName'); }, compute: function (_ref5) { var value = _ref5[0]; if (this.get('value')) { this.teardown(); } this.set('value', value); this.addObserver('value.firstName', this, this.recompute); this.addObserver('value.lastName', this, this.recompute); return (value ? (0, _emberMetal.get)(value, 'firstName') : '') + (value ? (0, _emberMetal.get)(value, 'lastName') : ''); } }); this.render('{{capitalizeName person}} {{unbound (capitalizeName person)}} {{concatNames person}} {{unbound (concatNames person)}}', { person: { firstName: 'shooby', lastName: 'taylor' } }); this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); this.runTask(function () { return _this14.rerender(); }); this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'person.firstName', 'sally'); }); this.assertText('SALLY SHOOBY sallytaylor shoobytaylor'); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'person', { firstName: 'shooby', lastName: 'taylor' }); }); this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); }; _class.prototype['@test should be able to render an unbound helper invocation in #each helper'] = function () { var _this15 = this; this.registerHelper('capitalize', function (params) { return params[0].toUpperCase(); }); this.render('{{#each people as |person|}}{{capitalize person.firstName}} {{unbound (capitalize person.firstName)}}{{/each}}', { people: (0, _emberRuntime.A)([{ firstName: 'shooby', lastName: 'taylor' }, { firstName: 'cindy', lastName: 'taylor' }]) }); this.assertText('SHOOBY SHOOBYCINDY CINDY'); this.runTask(function () { return _this15.rerender(); }); this.assertText('SHOOBY SHOOBYCINDY CINDY'); this.runTask(function () { return _this15.context.people.setEach('firstName', 'chad'); }); this.assertText('CHAD SHOOBYCHAD CINDY'); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'people', (0, _emberRuntime.A)([{ firstName: 'shooby', lastName: 'taylor' }, { firstName: 'cindy', lastName: 'taylor' }])); }); this.assertText('SHOOBY SHOOBYCINDY CINDY'); }; _class.prototype['@test should be able to render an unbound helper invocation with bound hash options'] = function () { var _this16 = this; this.registerHelper('capitalizeName', { destroy: function () { this.removeObserver('value.firstName'); this._super.apply(this, arguments); }, compute: function (_ref6) { var value = _ref6[0]; if (this.get('value')) { this.removeObserver('value.firstName'); } this.set('value', value); this.addObserver('value.firstName', this, this.recompute); return value ? (0, _emberMetal.get)(value, 'firstName').toUpperCase() : ''; } }); this.registerHelper('concatNames', { destroy: function () { this.teardown(); this._super.apply(this, arguments); }, teardown: function () { this.removeObserver('value.firstName'); this.removeObserver('value.lastName'); }, compute: function (_ref7) { var value = _ref7[0]; if (this.get('value')) { this.teardown(); } this.set('value', value); this.addObserver('value.firstName', this, this.recompute); this.addObserver('value.lastName', this, this.recompute); return (value ? (0, _emberMetal.get)(value, 'firstName') : '') + (value ? (0, _emberMetal.get)(value, 'lastName') : ''); } }); this.render('{{capitalizeName person}} {{unbound (capitalizeName person)}} {{concatNames person}} {{unbound (concatNames person)}}', { person: { firstName: 'shooby', lastName: 'taylor' } }); this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); this.runTask(function () { return _this16.rerender(); }); this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'person.firstName', 'sally'); }); this.assertText('SALLY SHOOBY sallytaylor shoobytaylor'); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'person', { firstName: 'shooby', lastName: 'taylor' }); }); this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor'); }; _class.prototype['@test should be able to render bound form of a helper inside unbound form of same helper'] = function () { var _this17 = this; this.render((0, _abstractTestCase.strip)(_templateObject3), { model: { foo: true, notfoo: false, bar: true } }); this.assertText('truetrue'); this.runTask(function () { return _this17.rerender(); }); this.assertText('truetrue'); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'model.bar', false); }); this.assertText('falsefalse'); this.runTask(function () { return (0, _emberMetal.set)(_this17.context, 'model', { foo: true, notfoo: false, bar: true }); }); this.assertText('truetrue'); }; _class.prototype['@test yielding unbound does not update'] = function () { var _this18 = this; var fooBarInstance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); fooBarInstance = this; }, model: { foo: 'bork' } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{yield (unbound model.foo)}}' }); this.render('{{#foo-bar as |value|}}{{value}}{{/foo-bar}}'); this.assertText('bork'); this.runTask(function () { return _this18.rerender(); }); this.assertText('bork'); this.runTask(function () { return (0, _emberMetal.set)(fooBarInstance, 'model.foo', 'oof'); }); this.assertText('bork'); this.runTask(function () { return (0, _emberMetal.set)(fooBarInstance, 'model', { foo: 'bork' }); }); this.assertText('bork'); }; _class.prototype['@test yielding unbound hash does not update'] = function () { var _this19 = this; var fooBarInstance = void 0; var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); fooBarInstance = this; }, model: { foo: 'bork' } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{yield (unbound (hash foo=model.foo))}}' }); this.render('{{#foo-bar as |value|}}{{value.foo}}{{/foo-bar}}'); this.assertText('bork'); this.runTask(function () { return _this19.rerender(); }); this.assertText('bork'); this.runTask(function () { return (0, _emberMetal.set)(fooBarInstance, 'model.foo', 'oof'); }); this.assertText('bork'); this.runTask(function () { return (0, _emberMetal.set)(fooBarInstance, 'model', { foo: 'bork' }); }); this.assertText('bork'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/helpers/yield-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal', 'ember-glimmer/tests/utils/helpers'], function (_emberBabel, _testCase, _emberMetal, _helpers) { 'use strict'; (0, _testCase.moduleFor)('Helpers test: {{yield}} helper', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test can yield to block'] = function () { var _this2 = this; this.registerComponent('yield-comp', { template: '[In layout:] {{yield}}' }); this.render('{{#yield-comp}}[In Block:] {{object.title}}{{/yield-comp}}', { object: { title: 'Seattle' } }); this.assertText('[In layout:] [In Block:] Seattle'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'object.title', 'Vancouver'); }); this.assertText('[In layout:] [In Block:] Vancouver'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'object', { title: 'Seattle' }); }); this.assertText('[In layout:] [In Block:] Seattle'); }; _class.prototype['@test templates should yield to block inside a nested component'] = function () { var _this3 = this; this.registerComponent('outer-comp', { template: '
[In layout:] {{yield}}
' }); this.registerComponent('inner-comp', { template: '{{#outer-comp}}[In Block:] {{object.title}}{{/outer-comp}}' }); this.render('{{inner-comp object=object}}', { object: { title: 'Seattle' } }); this.assertText('[In layout:] [In Block:] Seattle'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'object.title', 'Vancouver'); }); this.assertText('[In layout:] [In Block:] Vancouver'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'object', { title: 'Seattle' }); }); this.assertText('[In layout:] [In Block:] Seattle'); }; _class.prototype['@test templates should yield to block, when the yield is embedded in a each helper'] = function () { var _this4 = this; var list = [1, 2, 3]; this.registerComponent('outer-comp', { template: '{{#each list as |item|}}{{yield}}{{/each}}' }); this.render('{{#outer-comp list=list}}Hello{{/outer-comp}}', { list: list }); this.assertText('HelloHelloHello'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'list', [4, 5]); }); this.assertText('HelloHello'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'list', list); }); this.assertText('HelloHelloHello'); }; _class.prototype['@test templates should yield to block, when the yield is embedded in a if helper'] = function () { var _this5 = this; this.registerComponent('outer-comp', { template: '{{#if boolean}}{{yield}}{{/if}}' }); this.render('{{#outer-comp boolean=boolean}}Hello{{/outer-comp}}', { boolean: true }); this.assertText('Hello'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'boolean', false); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'boolean', true); }); this.assertText('Hello'); }; _class.prototype['@test simple curlies inside of a yielded clock should work when the yield is nested inside of another view'] = function () { var _this6 = this; this.registerComponent('kiwi-comp', { template: '{{#if falsy}}{{else}}{{yield}}{{/if}}' }); this.render('{{#kiwi-comp}}{{text}}{{/kiwi-comp}}', { text: 'ohai' }); this.assertText('ohai'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'text', 'portland'); }); this.assertText('portland'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'text', 'ohai'); }); this.assertText('ohai'); }; _class.prototype['@test nested simple curlies inside of a yielded block should work when the yield is nested inside of another view'] = function () { var _this7 = this; this.registerComponent('parent-comp', { template: '{{#if falsy}}{{else}}{{yield}}{{/if}}' }); this.registerComponent('child-comp', { template: '{{#if falsy}}{{else}}{{text}}{{/if}}' }); this.render('{{#parent-comp}}{{child-comp text=text}}{{/parent-comp}}', { text: 'ohai' }); this.assertText('ohai'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'text', 'portland'); }); this.assertText('portland'); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'text', 'ohai'); }); this.assertText('ohai'); }; _class.prototype['@test yielding to a non-existent block is not an error'] = function () { var _this8 = this; this.registerComponent('yielding-comp', { template: 'Hello:{{yield}}' }); this.registerComponent('outer-comp', { template: '{{yielding-comp}} {{title}}' }); this.render('{{outer-comp title=title}}', { title: 'Mr. Selden' }); this.assertText('Hello: Mr. Selden'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'title', 'Mr. Chag'); }); this.assertText('Hello: Mr. Chag'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'title', 'Mr. Selden'); }); this.assertText('Hello: Mr. Selden'); }; _class.prototype['@test yield uses the original context'] = function () { var _this9 = this; var KiwiCompComponent = _helpers.Component.extend({ boundText: 'Inner' }); this.registerComponent('kiwi-comp', { ComponentClass: KiwiCompComponent, template: '

{{boundText}}

{{yield}}

' }); this.render('{{#kiwi-comp}}{{boundText}}{{/kiwi-comp}}', { boundText: 'Original' }); this.assertText('InnerOriginal'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'boundText', 'Otherworld'); }); this.assertText('InnerOtherworld'); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'boundText', 'Original'); }); this.assertText('InnerOriginal'); }; _class.prototype['@test outer block param doesn\'t mask inner component property'] = function () { var _this10 = this; var KiwiCompComponent = _helpers.Component.extend({ boundText: 'Inner' }); this.registerComponent('kiwi-comp', { ComponentClass: KiwiCompComponent, template: '

{{boundText}}

{{yield}}

' }); this.render('{{#with boundText as |item|}}{{#kiwi-comp}}{{item}}{{/kiwi-comp}}{{/with}}', { boundText: 'Outer' }); this.assertText('InnerOuter'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'boundText', 'Otherworld'); }); this.assertText('InnerOtherworld'); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'boundText', 'Outer'); }); this.assertText('InnerOuter'); }; _class.prototype['@test inner block param doesn\'t mask yield property'] = function () { var _this11 = this; var KiwiCompComponent = _helpers.Component.extend({ boundText: 'Inner' }); this.registerComponent('kiwi-comp', { ComponentClass: KiwiCompComponent, template: '{{#with boundText as |item|}}

{{item}}

{{yield}}

{{/with}}' }); this.render('{{#kiwi-comp}}{{item}}{{/kiwi-comp}}', { item: 'Outer' }); this.assertText('InnerOuter'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'item', 'Otherworld'); }); this.assertText('InnerOtherworld'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'item', 'Outer'); }); this.assertText('InnerOuter'); }; _class.prototype['@test can bind a block param to a component and use it in yield'] = function () { var _this12 = this; this.registerComponent('kiwi-comp', { template: '

{{content}}

{{yield}}

' }); this.render('{{#with boundText as |item|}}{{#kiwi-comp content=item}}{{item}}{{/kiwi-comp}}{{/with}}', { boundText: 'Outer' }); this.assertText('OuterOuter'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'boundText', 'Update'); }); this.assertText('UpdateUpdate'); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'boundText', 'Outer'); }); this.assertText('OuterOuter'); }; _class.prototype['@test yield should not introduce a view'] = function () { var ParentCompComponent = _helpers.Component.extend({ isParentComponent: true }); var ChildCompComponent = _helpers.Component.extend({ didReceiveAttrs: function () { this._super(); var parentView = this.get('parentView'); ok(parentView.get('isParentComponent')); } }); this.registerComponent('parent-comp', { ComponentClass: ParentCompComponent, template: '{{yield}}' }); this.registerComponent('child-comp', { ComponentClass: ChildCompComponent }); this.render('{{#parent-comp}}{{child-comp}}{{/parent-comp}}'); }; _class.prototype['@test yield with nested components (#3220)'] = function () { var _this13 = this; this.registerComponent('inner-component', { template: '{{yield}}' }); this.registerComponent('outer-component', { template: '{{#inner-component}}{{yield}}{{/inner-component}}' }); this.render('{{#outer-component}}Hello {{boundText}}{{/outer-component}}', { boundText: 'world' }); this.assertText('Hello world'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'boundText', 'update'); }); this.assertText('Hello update'); this.runTask(function () { return (0, _emberMetal.set)(_this13.context, 'boundText', 'world'); }); this.assertText('Hello world'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/input-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal'], function (_emberBabel, _testCase, _emberMetal) { 'use strict'; (0, _testCase.moduleFor)('Input element tests', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype.runAttributeTest = function (attributeName, values) { var _this2 = this; this.render('', { value: values[0] }); this.assertAttributeHasValue(attributeName, values[0], attributeName + ' is set on initial render'); this.runTask(function () { return _this2.rerender(); }); this.assertAttributeHasValue(attributeName, values[0], attributeName + ' is set on noop rerender'); this.setComponentValue(values[1]); this.assertAttributeHasValue(attributeName, values[1], attributeName + ' is set on rerender'); this.setComponentValue(values[0]); this.assertAttributeHasValue(attributeName, values[0], attributeName + ' can be set back to the initial value'); }; _class.prototype.runPropertyTest = function (propertyName, values) { var _this3 = this; this.render('', { value: values[0] }); this.assertPropertyHasValue(propertyName, values[0], propertyName + ' is set on initial render'); this.runTask(function () { return _this3.rerender(); }); this.assertPropertyHasValue(propertyName, values[0], propertyName + ' is set on noop rerender'); this.setComponentValue(values[1]); this.assertPropertyHasValue(propertyName, values[1], propertyName + ' is set on rerender'); this.setComponentValue(values[0]); this.assertPropertyHasValue(propertyName, values[0], propertyName + ' can be set back to the initial value'); }; _class.prototype.runFalsyValueProperty = function (values) { var _this4 = this; var value = 'value'; this.render('', { value: values[0] }); this.assertPropertyHasValue(value, '', value + ' is set on initial render'); this.runTask(function () { return _this4.rerender(); }); this.assertPropertyHasValue(value, '', value + ' is set on noop rerender'); this.setComponentValue(values[1]); this.assertPropertyHasValue(value, values[1], value + ' is set on rerender'); this.setComponentValue(values[0]); this.assertPropertyHasValue(value, '', value + ' can be set back to the initial value'); }; _class.prototype['@test input disabled attribute'] = function () { var _this5 = this; this.render('', { model: { value: false } }); this.assert.equal(this.$inputElement().prop('disabled'), false); this.runTask(function () { return _this5.rerender(); }); this.assert.equal(this.$inputElement().prop('disabled'), false); this.runTask(function () { return _this5.context.set('model.value', true); }); this.assert.equal(this.$inputElement().prop('disabled'), true); this.assertHTML(''); // Note the DOM output is this.runTask(function () { return _this5.context.set('model.value', 'wat'); }); this.assert.equal(this.$inputElement().prop('disabled'), true); this.assertHTML(''); // Note the DOM output is this.runTask(function () { return _this5.context.set('model', { value: false }); }); this.assert.equal(this.$inputElement().prop('disabled'), false); this.assertHTML(''); }; _class.prototype['@test input value attribute'] = function () { this.runPropertyTest('value', ['foo', 'bar']); }; _class.prototype['@test input placeholder attribute'] = function () { this.runAttributeTest('placeholder', ['foo', 'bar']); }; _class.prototype['@test input name attribute'] = function () { this.runAttributeTest('name', ['nam', 'name']); }; _class.prototype['@test input maxlength attribute'] = function () { this.runAttributeTest('maxlength', [2, 3]); }; _class.prototype['@test input size attribute'] = function () { this.runAttributeTest('size', [2, 3]); }; _class.prototype['@test input tabindex attribute'] = function () { this.runAttributeTest('tabindex', [2, 3]); }; _class.prototype['@test null input value'] = function () { this.runFalsyValueProperty([null, 'hello']); }; _class.prototype['@test undefined input value'] = function () { this.runFalsyValueProperty([undefined, 'hello']); }; _class.prototype['@test undefined `toString` method as input value'] = function () { this.runFalsyValueProperty([Object.create(null), 'hello']); }; _class.prototype['@test cursor position is not lost when updating content'] = function () { this.render('', { value: 'hola' }); this.setDOMValue('hello'); this.setSelectionRange(1, 3); this.setComponentValue('hello'); this.assertSelectionRange(1, 3); // Note: We should eventually get around to testing reseting, however // browsers handle `selectionStart` and `selectionEnd` differently // when are synthetically testing movement of the cursor. }; _class.prototype['@test input can be updated multiple times'] = function () { this.render('', { value: 'hola' }); this.assertValue('hola', 'Value is initialised'); this.setComponentValue(''); this.assertValue('', 'Value is set in the DOM'); this.setDOMValue('hola'); this.setComponentValue('hola'); this.assertValue('hola', 'Value is updated the first time'); this.setComponentValue(''); this.assertValue('', 'Value is updated the second time'); }; _class.prototype['@test DOM is SSOT if value is set'] = function () { this.render('', { value: 'hola' }); this.assertValue('hola', 'Value is initialised'); this.setComponentValue('hello'); this.assertValue('hello', 'Value is initialised'); this.setDOMValue('hola'); this.assertValue('hola', 'DOM is used'); this.setComponentValue('bye'); this.assertValue('bye', 'Value is used'); // Simulates setting the input to the same value as it already is which won't cause a rerender this.setDOMValue('hola'); this.assertValue('hola', 'DOM is used'); this.setComponentValue('hola'); this.assertValue('hola', 'Value is used'); }; _class.prototype.setDOMValue = function (value) { this.inputElement().value = value; }; _class.prototype.setComponentValue = function (value) { var _this6 = this; this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'value', value); }); }; _class.prototype.setSelectionRange = function (start, end) { this.inputElement().selectionStart = start; this.inputElement().selectionEnd = end; }; _class.prototype.inputElement = function () { return this.$inputElement()[0]; }; _class.prototype.$inputElement = function () { return this.$('input'); }; _class.prototype.assertValue = function (value, message) { this.assertPropertyHasValue('value', value, message); }; _class.prototype.assertAttributeHasValue = function (attribute, value, message) { this.assert.equal(this.$inputElement().attr(attribute), value, attribute + ' ' + message); }; _class.prototype.assertPropertyHasValue = function (property, value, message) { this.assert.equal(this.$inputElement().prop(property), value, property + ' ' + message); }; _class.prototype.assertSelectionRange = function (start, end) { this.assert.equal(this.inputElement().selectionStart, start); this.assert.equal(this.inputElement().selectionEnd, end); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/mount-test', ['ember-babel', 'ember-utils', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-runtime', 'ember-metal', 'ember-application'], function (_emberBabel, _emberUtils, _testCase, _helpers, _emberRuntime, _emberMetal, _emberApplication) { 'use strict'; (0, _testCase.moduleFor)('{{mount}} assertions', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test it asserts that only a single param is passed'] = function () { var _this2 = this; expectAssertion(function () { _this2.render('{{mount "chat" "foo"}}'); }, /You can only pass a single argument to the {{mount}} helper, e.g. {{mount "chat-engine"}}./i); }; _class.prototype['@test it asserts when an invalid engine name is provided'] = function () { var _this3 = this; expectAssertion(function () { _this3.render('{{mount engineName}}', { engineName: {} }); }, /Invalid engine name '\[object Object\]' specified, engine name must be either a string, null or undefined./i); }; _class.prototype['@test it asserts that the specified engine is registered'] = function () { var _this4 = this; expectAssertion(function () { _this4.render('{{mount "chat"}}'); }, /You used `{{mount 'chat'}}`, but the engine 'chat' can not be found./i); }; return _class; }(_testCase.RenderingTest)); (0, _testCase.moduleFor)('{{mount}} test', function (_ApplicationTest) { (0, _emberBabel.inherits)(_class2, _ApplicationTest); function _class2() { var _this5 = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTest.call(this)); var engineRegistrations = _this5.engineRegistrations = {}; _this5.add('engine:chat', _emberApplication.Engine.extend({ router: null, init: function () { var _this6 = this; this._super.apply(this, arguments); Object.keys(engineRegistrations).forEach(function (fullName) { _this6.register(fullName, engineRegistrations[fullName]); }); } })); _this5.addTemplate('index', '{{mount "chat"}}'); return _this5; } _class2.prototype['@test it boots an engine, instantiates its application controller, and renders its application template'] = function (assert) { var _this7 = this; this.engineRegistrations['template:application'] = (0, _helpers.compile)('

Chat here, {{username}}

', { moduleName: 'application' }); var controller = void 0; this.engineRegistrations['controller:application'] = _emberRuntime.Controller.extend({ username: 'dgeb', init: function () { this._super(); controller = this; } }); return this.visit('/').then(function () { assert.ok(controller, 'engine\'s application controller has been instantiated'); var engineInstance = (0, _emberUtils.getOwner)(controller); assert.strictEqual((0, _emberApplication.getEngineParent)(engineInstance), _this7.applicationInstance, 'engine instance has the application instance as its parent'); _this7.assertComponentElement(_this7.firstChild, { content: '

Chat here, dgeb

' }); _this7.runTask(function () { return (0, _emberMetal.set)(controller, 'username', 'chancancode'); }); _this7.assertComponentElement(_this7.firstChild, { content: '

Chat here, chancancode

' }); _this7.runTask(function () { return (0, _emberMetal.set)(controller, 'username', 'dgeb'); }); _this7.assertComponentElement(_this7.firstChild, { content: '

Chat here, dgeb

' }); }); }; _class2.prototype['@test it emits a useful backtracking re-render assertion message'] = function () { var _this8 = this; this.router.map(function () { this.route('route-with-mount'); }); this.addTemplate('index', ''); this.addTemplate('route-with-mount', '{{mount "chat"}}'); this.engineRegistrations['template:application'] = (0, _helpers.compile)('hi {{person.name}} [{{component-with-backtracking-set person=person}}]', { moduleName: 'application' }); this.engineRegistrations['controller:application'] = _emberRuntime.Controller.extend({ person: { name: 'Alex' } }); this.engineRegistrations['template:components/component-with-backtracking-set'] = (0, _helpers.compile)('[component {{person.name}}]', { moduleName: 'components/component-with-backtracking-set' }); this.engineRegistrations['component:component-with-backtracking-set'] = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); this.set('person.name', 'Ben'); } }); var expectedBacktrackingMessage = /modified "person\.name" twice on \[object Object\] in a single render\. It was rendered in "template:route-with-mount" \(in "engine:chat"\) and modified in "component:component-with-backtracking-set" \(in "engine:chat"\)/; return this.visit('/').then(function () { expectAssertion(function () { _this8.visit('/route-with-mount'); }, expectedBacktrackingMessage); }); }; _class2.prototype['@test it renders with a bound engine name'] = function () { var _this9 = this; this.router.map(function () { this.route('bound-engine-name'); }); var controller = void 0; this.add('controller:bound-engine-name', _emberRuntime.Controller.extend({ engineName: null, init: function () { this._super(); controller = this; } })); this.addTemplate('bound-engine-name', '{{mount engineName}}'); this.add('engine:foo', _emberApplication.Engine.extend({ router: null, init: function () { this._super.apply(this, arguments); this.register('template:application', (0, _helpers.compile)('

Foo Engine

', { moduleName: 'application' })); } })); this.add('engine:bar', _emberApplication.Engine.extend({ router: null, init: function () { this._super.apply(this, arguments); this.register('template:application', (0, _helpers.compile)('

Bar Engine

', { moduleName: 'application' })); } })); return this.visit('/bound-engine-name').then(function () { _this9.assertComponentElement(_this9.firstChild, { content: '' }); _this9.runTask(function () { return (0, _emberMetal.set)(controller, 'engineName', 'foo'); }); _this9.assertComponentElement(_this9.firstChild, { content: '

Foo Engine

' }); _this9.runTask(function () { return (0, _emberMetal.set)(controller, 'engineName', undefined); }); _this9.assertComponentElement(_this9.firstChild, { content: '' }); _this9.runTask(function () { return (0, _emberMetal.set)(controller, 'engineName', 'foo'); }); _this9.assertComponentElement(_this9.firstChild, { content: '

Foo Engine

' }); _this9.runTask(function () { return (0, _emberMetal.set)(controller, 'engineName', 'bar'); }); _this9.assertComponentElement(_this9.firstChild, { content: '

Bar Engine

' }); _this9.runTask(function () { return (0, _emberMetal.set)(controller, 'engineName', 'foo'); }); _this9.assertComponentElement(_this9.firstChild, { content: '

Foo Engine

' }); _this9.runTask(function () { return (0, _emberMetal.set)(controller, 'engineName', null); }); _this9.assertComponentElement(_this9.firstChild, { content: '' }); }); }; return _class2; }(_testCase.ApplicationTest)); }); enifed('ember-glimmer/tests/integration/outlet-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'internal-test-helpers', 'ember-metal'], function (_emberBabel, _testCase, _internalTestHelpers, _emberMetal) { 'use strict'; (0, _testCase.moduleFor)('outlet view', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); var CoreOutlet = _this.owner.factoryFor('view:-outlet'); _this.component = CoreOutlet.create(); return _this; } _class.prototype['@test should not error when initial rendered template is undefined'] = function () { var _this2 = this; var outletState = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'application', controller: undefined, ViewClass: undefined, template: undefined }, outlets: Object.create(null) }; this.runTask(function () { return _this2.component.setOutletState(outletState); }); (0, _internalTestHelpers.runAppend)(this.component); this.assertText(''); }; _class.prototype['@test should render the outlet when set after DOM insertion'] = function () { var _this3 = this; var outletState = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'application', controller: undefined, ViewClass: undefined, template: undefined }, outlets: Object.create(null) }; this.runTask(function () { return _this3.component.setOutletState(outletState); }); (0, _internalTestHelpers.runAppend)(this.component); this.assertText(''); this.registerTemplate('application', 'HI{{outlet}}'); outletState = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'application', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:application') }, outlets: Object.create(null) }; this.runTask(function () { return _this3.component.setOutletState(outletState); }); this.assertText('HI'); this.assertStableRerender(); this.registerTemplate('index', '

BYE

'); outletState.outlets.main = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'index', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:index') }, outlets: Object.create(null) }; this.runTask(function () { return _this3.component.setOutletState(outletState); }); this.assertText('HIBYE'); }; _class.prototype['@test should render the outlet when set before DOM insertion'] = function () { var _this4 = this; this.registerTemplate('application', 'HI{{outlet}}'); var outletState = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'application', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:application') }, outlets: Object.create(null) }; this.runTask(function () { return _this4.component.setOutletState(outletState); }); (0, _internalTestHelpers.runAppend)(this.component); this.assertText('HI'); this.assertStableRerender(); this.registerTemplate('index', '

BYE

'); outletState.outlets.main = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'index', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:index') }, outlets: Object.create(null) }; this.runTask(function () { return _this4.component.setOutletState(outletState); }); this.assertText('HIBYE'); }; _class.prototype['@test should support an optional name'] = function () { var _this5 = this; this.registerTemplate('application', '

HI

{{outlet "special"}}'); var outletState = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'application', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:application') }, outlets: Object.create(null) }; this.runTask(function () { return _this5.component.setOutletState(outletState); }); (0, _internalTestHelpers.runAppend)(this.component); this.assertText('HI'); this.assertStableRerender(); this.registerTemplate('special', '

BYE

'); outletState.outlets.special = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'special', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:special') }, outlets: Object.create(null) }; this.runTask(function () { return _this5.component.setOutletState(outletState); }); this.assertText('HIBYE'); }; _class.prototype['@test does not default outlet name when positional argument is present'] = function () { var _this6 = this; this.registerTemplate('application', '

HI

{{outlet someUndefinedThing}}'); var outletState = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'application', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:application') }, outlets: Object.create(null) }; this.runTask(function () { return _this6.component.setOutletState(outletState); }); (0, _internalTestHelpers.runAppend)(this.component); this.assertText('HI'); this.assertStableRerender(); this.registerTemplate('special', '

BYE

'); outletState.outlets.main = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'special', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:special') }, outlets: Object.create(null) }; this.runTask(function () { return _this6.component.setOutletState(outletState); }); this.assertText('HI'); }; _class.prototype['@test should support bound outlet name'] = function () { var _this7 = this; var controller = { outletName: 'foo' }; this.registerTemplate('application', '

HI

{{outlet outletName}}'); var outletState = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'application', controller: controller, ViewClass: undefined, template: this.owner.lookup('template:application') }, outlets: Object.create(null) }; this.runTask(function () { return _this7.component.setOutletState(outletState); }); (0, _internalTestHelpers.runAppend)(this.component); this.assertText('HI'); this.assertStableRerender(); this.registerTemplate('foo', '

FOO

'); outletState.outlets.foo = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'foo', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:foo') }, outlets: Object.create(null) }; this.registerTemplate('bar', '

BAR

'); outletState.outlets.bar = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'bar', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:bar') }, outlets: Object.create(null) }; this.runTask(function () { return _this7.component.setOutletState(outletState); }); this.assertText('HIFOO'); this.runTask(function () { return (0, _emberMetal.set)(controller, 'outletName', 'bar'); }); this.assertText('HIBAR'); }; _class.prototype['@test outletState can pass through user code (liquid-fire initimate API) '] = function () { var _this8 = this; this.registerTemplate('outer', 'A{{#-with-dynamic-vars outletState=(identity (-get-dynamic-var "outletState"))}}B{{outlet}}D{{/-with-dynamic-vars}}E'); this.registerTemplate('inner', 'C'); // This looks like it doesn't do anything, but its presence // guarantees that the outletState gets converted from a reference // to a value and then back to a reference. That is what we're // testing here. this.registerHelper('identity', function (_ref) { var a = _ref[0]; return a; }); var outletState = { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'outer', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:outer') }, outlets: { main: { render: { owner: this.owner, into: undefined, outlet: 'main', name: 'inner', controller: {}, ViewClass: undefined, template: this.owner.lookup('template:inner') }, outlets: Object.create(null) } } }; this.runTask(function () { return _this8.component.setOutletState(outletState); }); (0, _internalTestHelpers.runAppend)(this.component); this.assertText('ABCDE'); this.assertStableRerender(); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/refinements-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-metal'], function (_emberBabel, _testCase, _abstractTestCase, _emberMetal) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with var as |foo|}}\n {{foo}}\n {{/with}}\n\n ---\n\n {{#with var as |render|}}\n {{render}}\n {{/with}}\n\n ---\n\n {{#with var as |outlet|}}\n {{outlet}}\n {{/with}}\n\n ---\n\n {{#with var as |mount|}}\n {{mount}}\n {{/with}}\n\n ---\n\n {{#with var as |component|}}\n {{component}}\n {{/with}}\n\n ---\n\n {{#with var as |input|}}\n {{input}}\n {{/with}}\n\n ---\n\n {{#with var as |-with-dynamic-vars|}}\n {{-with-dynamic-vars}}\n {{/with}}\n\n ---\n\n {{#with var as |-in-element|}}\n {{-in-element}}\n {{/with}}'], ['\n {{#with var as |foo|}}\n {{foo}}\n {{/with}}\n\n ---\n\n {{#with var as |render|}}\n {{render}}\n {{/with}}\n\n ---\n\n {{#with var as |outlet|}}\n {{outlet}}\n {{/with}}\n\n ---\n\n {{#with var as |mount|}}\n {{mount}}\n {{/with}}\n\n ---\n\n {{#with var as |component|}}\n {{component}}\n {{/with}}\n\n ---\n\n {{#with var as |input|}}\n {{input}}\n {{/with}}\n\n ---\n\n {{#with var as |-with-dynamic-vars|}}\n {{-with-dynamic-vars}}\n {{/with}}\n\n ---\n\n {{#with var as |-in-element|}}\n {{-in-element}}\n {{/with}}']); (0, _testCase.moduleFor)('syntax refinements', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test block params should not be refined'] = function () { var _this2 = this; this.registerHelper('foo', function () { return 'bar helper'; }); this.render((0, _abstractTestCase.strip)(_templateObject), { var: 'var' }); this.assertText('var---var---var---var---var---var---var---var'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'var', 'RARRR!!!'); }); this.assertText('RARRR!!!---RARRR!!!---RARRR!!!---RARRR!!!---RARRR!!!---RARRR!!!---RARRR!!!---RARRR!!!'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'var', 'var'); }); this.assertText('var---var---var---var---var---var---var---var'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/svg-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _testCase, _emberMetal, _abstractTestCase) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n \n
\n '], ['\n
\n \n
\n ']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n \n
\n '], ['\n
\n \n
\n ']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n \n
\n '], ['\n
\n \n
\n ']), _templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n \n
\n '], ['\n
\n \n
\n ']), _templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
\n \n
\n '], ['\n
\n \n
\n ']); (0, _testCase.moduleFor)('SVG element tests', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test unquoted viewBox property is output'] = function (assert) { var _this2 = this; var viewBoxString = '0 0 100 100'; this.render('
', { model: { viewBoxString: viewBoxString } }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString)); this.runTask(function () { return _this2.rerender(); }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString)); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'model.viewBoxString', null); }); assert.equal(this.firstChild.getAttribute('svg'), null); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'model', { viewBoxString: viewBoxString }); }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString)); }; _class.prototype['@test quoted viewBox property is output'] = function (assert) { var _this3 = this; var viewBoxString = '0 0 100 100'; this.render('
', { model: { viewBoxString: viewBoxString } }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString)); this.runTask(function () { return _this3.rerender(); }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString)); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'model.viewBoxString', null); }); assert.equal(this.firstChild.getAttribute('svg'), null); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'model', { viewBoxString: viewBoxString }); }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString)); }; _class.prototype['@test quoted viewBox property is concat'] = function () { var _this4 = this; var viewBoxString = '100 100'; this.render('
', { model: { viewBoxString: viewBoxString } }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject2, viewBoxString)); this.runTask(function () { return _this4.rerender(); }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject2, viewBoxString)); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'model.viewBoxString', '200 200'); }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject3)); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'model', { viewBoxString: viewBoxString }); }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject2, viewBoxString)); }; _class.prototype['@test class is output'] = function () { var _this5 = this; this.render('
', { model: { color: 'blue' } }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject4)); this.runTask(function () { return _this5.rerender(); }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject4)); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'model.color', 'yellow'); }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject5)); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'model', { color: 'blue' }); }); this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject4)); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/syntax/each-in-test', ['ember-babel', 'ember-metal', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case', 'ember-runtime', 'ember-glimmer/tests/utils/shared-conditional-tests'], function (_emberBabel, _emberMetal, _abstractTestCase, _testCase, _emberRuntime, _sharedConditionalTests) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n {{#each-in categories as |category count|}}\n
  • {{category}}: {{count}}
  • \n {{/each-in}}\n
\n '], ['\n
    \n {{#each-in categories as |category count|}}\n
  • {{category}}: {{count}}
  • \n {{/each-in}}\n
\n ']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n
  • Smartphones: 8203
  • \n
  • JavaScript Frameworks: Infinity
  • \n
\n '], ['\n
    \n
  • Smartphones: 8203
  • \n
  • JavaScript Frameworks: Infinity
  • \n
\n ']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n
  • Smartphones: 100
  • \n
  • JavaScript Frameworks: Infinity
  • \n
  • Tweets: 443115
  • \n
\n '], ['\n
    \n
  • Smartphones: 100
  • \n
  • JavaScript Frameworks: Infinity
  • \n
  • Tweets: 443115
  • \n
\n ']), _templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n {{#each-in categories as |category data|}}\n
  • {{category}}: {{data.reports.unitsSold}}
  • \n {{/each-in}}\n
\n '], ['\n
    \n {{#each-in categories as |category data|}}\n
  • {{category}}: {{data.reports.unitsSold}}
  • \n {{/each-in}}\n
\n ']), _templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n {{#each-in categories key=\'@identity\' as |category count|}}\n
  • {{category}}: {{count}}
  • \n {{/each-in}}\n
\n '], ['\n
    \n {{#each-in categories key=\'@identity\' as |category count|}}\n
  • {{category}}: {{count}}
  • \n {{/each-in}}\n
\n ']), _templateObject6 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n
  • Smartphones: 8203
  • \n
  • Tablets: 8203
  • \n
  • JavaScript Frameworks: Infinity
  • \n
  • Bugs: Infinity
  • \n
\n '], ['\n
    \n
  • Smartphones: 8203
  • \n
  • Tablets: 8203
  • \n
  • JavaScript Frameworks: Infinity
  • \n
  • Bugs: Infinity
  • \n
\n ']), _templateObject7 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n
  • Smartphones: 100
  • \n
  • Tablets: 8203
  • \n
  • JavaScript Frameworks: Infinity
  • \n
  • Bugs: Infinity
  • \n
  • Tweets: 443115
  • \n
\n '], ['\n
    \n
  • Smartphones: 100
  • \n
  • Tablets: 8203
  • \n
  • JavaScript Frameworks: Infinity
  • \n
  • Bugs: Infinity
  • \n
  • Tweets: 443115
  • \n
\n ']), _templateObject8 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n {{#each-in (get collection type) as |category count|}}\n
  • {{category}}: {{count}}
  • \n {{/each-in}}\n
\n '], ['\n
    \n {{#each-in (get collection type) as |category count|}}\n
  • {{category}}: {{count}}
  • \n {{/each-in}}\n
\n ']), _templateObject9 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n
  • Emberinios: 533462
  • \n
  • Tweets: 7323
  • \n
\n '], ['\n
    \n
  • Emberinios: 533462
  • \n
  • Tweets: 7323
  • \n
\n ']), _templateObject10 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n
  • Televisions: 183
  • \n
  • Alarm Clocks: 999
  • \n
\n '], ['\n
    \n
  • Televisions: 183
  • \n
  • Alarm Clocks: 999
  • \n
\n ']), _templateObject11 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n
  • Televisions: 183
  • \n
  • Alarm Clocks: 999
  • \n
  • Tweets: 443115
  • \n
\n '], ['\n
    \n
  • Televisions: 183
  • \n
  • Alarm Clocks: 999
  • \n
  • Tweets: 443115
  • \n
\n ']), _templateObject12 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n
  • Emberinios: 123456
  • \n
\n '], ['\n
    \n
  • Emberinios: 123456
  • \n
\n ']), _templateObject13 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each-in foo.bar.baz as |thing|}}\n {{thing}}\n {{/each-in}}'], ['\n {{#each-in foo.bar.baz as |thing|}}\n {{thing}}\n {{/each-in}}']), _templateObject14 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each-in arr as |key value|}}\n [{{key}}:{{value}}]\n {{/each-in}}'], ['\n {{#each-in arr as |key value|}}\n [{{key}}:{{value}}]\n {{/each-in}}']), _templateObject15 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
    \n
  • Smartphones: 100
  • \n
  • Tablets: 20
  • \n
\n '], ['\n
    \n
  • Smartphones: 100
  • \n
  • Tablets: 20
  • \n
\n ']); var EachInTest = function (_TogglingSyntaxCondit) { (0, _emberBabel.inherits)(EachInTest, _TogglingSyntaxCondit); function EachInTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingSyntaxCondit.apply(this, arguments)); } EachInTest.prototype.templateFor = function (_ref) { var cond = _ref.cond, truthy = _ref.truthy, falsy = _ref.falsy; return '{{#each-in ' + cond + ' as |key|}}' + truthy + '{{else}}' + falsy + '{{/each-in}}'; }; return EachInTest; }(_sharedConditionalTests.TogglingSyntaxConditionalsTest); function NonEmptyFunction() {} NonEmptyFunction.foo = 'bar'; var NonEmptyConstructor = function () {}; NonEmptyConstructor.foo = 'bar'; var BasicEachInTest = function (_EachInTest) { (0, _emberBabel.inherits)(BasicEachInTest, _EachInTest); function BasicEachInTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _EachInTest.apply(this, arguments)); } return BasicEachInTest; }(EachInTest); (0, _abstractTestCase.applyMixins)(BasicEachInTest, new _sharedConditionalTests.TruthyGenerator([{ foo: 1 }, _emberRuntime.Object.create({ 'Not Empty': 1 }), [1], NonEmptyFunction, NonEmptyConstructor]), new _sharedConditionalTests.FalsyGenerator([null, undefined, false, '', 0, [], function () {}, function () {}, {}, Object.create(null), Object.create({}), Object.create({ 'Not Empty': 1 }), _emberRuntime.Object.create()])); (0, _testCase.moduleFor)('Syntax test: {{#each-in}}', function (_BasicEachInTest) { (0, _emberBabel.inherits)(_class, _BasicEachInTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _BasicEachInTest.apply(this, arguments)); } _class.prototype['@test it repeats the given block for each item in the hash'] = function () { var _this4 = this; this.render((0, _abstractTestCase.strip)(_templateObject), { categories: { 'Smartphones': 8203, 'JavaScript Frameworks': Infinity } }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject2)); this.assertStableRerender(); this.runTask(function () { (0, _emberMetal.set)(_this4.context, 'categories.Smartphones', 100); (0, _emberMetal.set)(_this4.context, 'categories.Tweets', 443115); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject3)); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'categories', { 'Smartphones': 8203, 'JavaScript Frameworks': Infinity }); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject2)); }; _class.prototype['@test it can render sub-paths of each item'] = function () { var _this5 = this; this.render((0, _abstractTestCase.strip)(_templateObject4), { categories: { 'Smartphones': { reports: { unitsSold: 8203 } }, 'JavaScript Frameworks': { reports: { unitsSold: Infinity } } } }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject2)); this.assertStableRerender(); this.runTask(function () { (0, _emberMetal.set)(_this5.context, 'categories.Smartphones.reports.unitsSold', 100); (0, _emberMetal.set)(_this5.context, 'categories.Tweets', { reports: { unitsSold: 443115 } }); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject3)); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'categories', { 'Smartphones': { reports: { unitsSold: 8203 } }, 'JavaScript Frameworks': { reports: { unitsSold: Infinity } } }); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject2)); }; _class.prototype['@test it can render duplicate items'] = function () { var _this6 = this; this.render((0, _abstractTestCase.strip)(_templateObject5), { categories: { 'Smartphones': 8203, 'Tablets': 8203, 'JavaScript Frameworks': Infinity, 'Bugs': Infinity } }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject6)); this.assertStableRerender(); this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'categories.Smartphones', 100); (0, _emberMetal.set)(_this6.context, 'categories.Tweets', 443115); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject7)); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'categories', { 'Smartphones': 8203, 'Tablets': 8203, 'JavaScript Frameworks': Infinity, 'Bugs': Infinity }); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject6)); }; _class.prototype['@test it repeats the given block when the hash is dynamic'] = function () { var _this7 = this; this.render((0, _abstractTestCase.strip)(_templateObject8), { collection: { categories: { 'Smartphones': 8203, 'JavaScript Frameworks': Infinity }, otherCategories: { 'Emberinios': 533462, 'Tweets': 7323 } }, type: 'categories' }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject2)); this.assertStableRerender(); this.runTask(function () { (0, _emberMetal.set)(_this7.context, 'type', 'otherCategories'); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject9)); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'type', 'categories'); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject2)); }; _class.prototype['@test it only iterates over an object\'s own properties'] = function () { var _this8 = this; var protoCategories = { 'Smartphones': 8203, 'JavaScript Frameworks': Infinity }; var categories = Object.create(protoCategories); categories['Televisions'] = 183; categories['Alarm Clocks'] = 999; this.render((0, _abstractTestCase.strip)(_templateObject), { categories: categories }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject10)); this.assertStableRerender(); this.runTask(function () { (0, _emberMetal.set)(protoCategories, 'Robots', 666); (0, _emberMetal.set)(categories, 'Tweets', 443115); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject11)); categories = Object.create(protoCategories); categories['Televisions'] = 183; categories['Alarm Clocks'] = 999; this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'categories', categories); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject10)); }; _class.prototype['@test it does not observe direct property mutations (not going through set) on the object'] = function () { var _this9 = this; this.render((0, _abstractTestCase.strip)(_templateObject), { categories: { 'Smartphones': 8203, 'JavaScript Frameworks': Infinity } }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject2)); this.assertStableRerender(); this.runTask(function () { var categories = (0, _emberMetal.get)(_this9.context, 'categories'); delete categories.Smartphones; }); this.assertInvariants(); this.runTask(function () { var categories = (0, _emberMetal.get)(_this9.context, 'categories'); categories['Emberinios'] = 123456; }); this.assertInvariants(); this.runTask(function () { (0, _emberMetal.set)(_this9.context, 'categories', { Emberinios: 123456 }); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject12)); this.runTask(function () { (0, _emberMetal.set)(_this9.context, 'categories', { 'Smartphones': 8203, 'JavaScript Frameworks': Infinity }); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject2)); }; _class.prototype['@test keying off of `undefined` does not render'] = function () { var _this10 = this; this.render((0, _abstractTestCase.strip)(_templateObject13), { foo: {} }); this.assertText(''); this.runTask(function () { return _this10.rerender(); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'foo', { bar: { baz: { 'Here!': 1 } } }); }); this.assertText('Here!'); this.runTask(function () { return (0, _emberMetal.set)(_this10.context, 'foo', {}); }); this.assertText(''); }; _class.prototype['@test it iterate over array with `in` instead of walking over elements'] = function () { var _this11 = this; var arr = [1, 2, 3]; arr.foo = 'bar'; this.render((0, _abstractTestCase.strip)(_templateObject14), { arr: arr }); this.assertText('[0:1][1:2][2:3][foo:bar]'); this.runTask(function () { return _this11.rerender(); }); this.assertText('[0:1][1:2][2:3][foo:bar]'); this.runTask(function () { (0, _emberMetal.set)(arr, 'zomg', 'lol'); }); this.assertText('[0:1][1:2][2:3][foo:bar][zomg:lol]'); arr = [1, 2, 3]; arr.foo = 'bar'; this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'arr', arr); }); this.assertText('[0:1][1:2][2:3][foo:bar]'); }; _class.prototype['@test it skips holes in sparse arrays'] = function () { var arr = []; arr[5] = 'foo'; arr[6] = 'bar'; this.render((0, _abstractTestCase.strip)(_templateObject14), { arr: arr }); this.assertText('[5:foo][6:bar]'); this.assertStableRerender(); }; (0, _emberBabel.createClass)(_class, [{ key: 'truthyValue', get: function () { return { 'Not Empty': 1 }; } }, { key: 'falsyValue', get: function () { return {}; } }]); return _class; }(BasicEachInTest)); var EachInEdgeCasesTest = function (_EachInTest2) { (0, _emberBabel.inherits)(EachInEdgeCasesTest, _EachInTest2); function EachInEdgeCasesTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _EachInTest2.apply(this, arguments)); } return EachInEdgeCasesTest; }(EachInTest); (0, _abstractTestCase.applyMixins)(EachInEdgeCasesTest, new _sharedConditionalTests.FalsyGenerator([true, 1, 'hello'])); (0, _testCase.moduleFor)('Syntax test: {{#each-in}} edge cases', function (_EachInEdgeCasesTest) { (0, _emberBabel.inherits)(_class2, _EachInEdgeCasesTest); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _EachInEdgeCasesTest.apply(this, arguments)); } (0, _emberBabel.createClass)(_class2, [{ key: 'truthyValue', get: function () { return { 'Not Empty': 1 }; } }, { key: 'falsyValue', get: function () { return {}; } }]); return _class2; }(EachInEdgeCasesTest)); var EachInProxyTest = function (_EachInTest3) { (0, _emberBabel.inherits)(EachInProxyTest, _EachInTest3); function EachInProxyTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _EachInTest3.apply(this, arguments)); } return EachInProxyTest; }(EachInTest); (0, _abstractTestCase.applyMixins)(EachInProxyTest, new _sharedConditionalTests.TruthyGenerator([_emberRuntime.ObjectProxy.create({ content: { 'Not empty': 1 } })]), new _sharedConditionalTests.FalsyGenerator([_emberRuntime.ObjectProxy.create(), _emberRuntime.ObjectProxy.create({ content: null }), _emberRuntime.ObjectProxy.create({ content: {} }), _emberRuntime.ObjectProxy.create({ content: Object.create(null) }), _emberRuntime.ObjectProxy.create({ content: Object.create({}) }), _emberRuntime.ObjectProxy.create({ content: Object.create({ 'Not Empty': 1 }) }), _emberRuntime.ObjectProxy.create({ content: _emberRuntime.Object.create() })])); (0, _testCase.moduleFor)('Syntax test: {{#each-in}} with `ObjectProxy`', function (_EachInProxyTest) { (0, _emberBabel.inherits)(_class3, _EachInProxyTest); function _class3() { return (0, _emberBabel.possibleConstructorReturn)(this, _EachInProxyTest.apply(this, arguments)); } _class3.prototype['@test it iterates over the content, not the proxy'] = function () { var _this16 = this; var content = { 'Smartphones': 8203, 'JavaScript Frameworks': Infinity }; var proxy = _emberRuntime.ObjectProxy.create({ content: content, foo: 'bar' }); this.render((0, _abstractTestCase.strip)(_templateObject), { categories: proxy }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject2)); this.assertStableRerender(); this.runTask(function () { (0, _emberMetal.set)(proxy, 'content.Smartphones', 100); (0, _emberMetal.set)(proxy, 'content.Tweets', 443115); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject3)); this.runTask(function () { (0, _emberMetal.set)(proxy, 'content', { 'Smartphones': 100, 'Tablets': 20 }); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject15)); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'categories', _emberRuntime.ObjectProxy.create({ content: { 'Smartphones': 8203, 'JavaScript Frameworks': Infinity } })); }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject2)); }; (0, _emberBabel.createClass)(_class3, [{ key: 'truthyValue', get: function () { return _emberRuntime.ObjectProxy.create({ content: { 'Not Empty': 1 } }); } }, { key: 'falsyValue', get: function () { return _emberRuntime.ObjectProxy.create({ content: null }); } }]); return _class3; }(EachInProxyTest)); }); enifed('ember-glimmer/tests/integration/syntax/each-test', ['ember-babel', 'ember-metal', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case', 'ember-runtime', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/shared-conditional-tests'], function (_emberBabel, _emberMetal, _abstractTestCase, _testCase, _emberRuntime, _helpers, _sharedConditionalTests) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each list as |item|}}\n
  • Prev
  • \n {{foo-bar item=item}}\n
  • Next
  • \n {{/each}}\n '], ['\n {{#each list as |item|}}\n
  • Prev
  • \n {{foo-bar item=item}}\n
  • Next
  • \n {{/each}}\n ']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each content as |value|}}\n {{value}}-\n {{#each options as |option|}}\n {{option.value}}:{{option.label}}\n {{/each}}\n {{/each}}\n '], ['\n {{#each content as |value|}}\n {{value}}-\n {{#each options as |option|}}\n {{option.value}}:{{option.label}}\n {{/each}}\n {{/each}}\n ']), _templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each foo.bar.baz as |thing|}}\n {{thing}}\n {{/each}}'], ['\n {{#each foo.bar.baz as |thing|}}\n {{thing}}\n {{/each}}']), _templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each list as |value key|}}\n [{{key}}:{{value}}]\n {{/each}}'], ['\n {{#each list as |value key|}}\n [{{key}}:{{value}}]\n {{/each}}']), _templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n

    {{page.title}}

    \n\n
      \n {{#each model as |post|}}\n
    • {{post.title}}
    • \n {{/each}}\n
    \n '], ['\n

    {{page.title}}

    \n\n
      \n {{#each model as |post|}}\n
    • {{post.title}}
    • \n {{/each}}\n
    \n ']), _templateObject6 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n

    Blog Posts

    \n\n
      \n
    • Rails is omakase
    • \n
    • Ember is omakase
    • \n
    \n '], ['\n

    Blog Posts

    \n\n
      \n
    • Rails is omakase
    • \n
    • Ember is omakase
    • \n
    \n ']), _templateObject7 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n

    Essays

    \n\n
      \n
    • Rails is omakase
    • \n
    • Ember is omakase
    • \n
    \n '], ['\n

    Essays

    \n\n
      \n
    • Rails is omakase
    • \n
    • Ember is omakase
    • \n
    \n ']), _templateObject8 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n

    Think Pieces\u2122

    \n\n
      \n
    • Rails is omakase
    • \n
    • Ember is omakase
    • \n
    \n '], ['\n

    Think Pieces\u2122

    \n\n
      \n
    • Rails is omakase
    • \n
    • Ember is omakase
    • \n
    \n ']); var ArrayLike = function () { function ArrayLike(content) { this._array = content; } ArrayLike.prototype.forEach = function (callback) { this._array.forEach(callback); }; ArrayLike.prototype.objectAt = function (idx) { return this._array[idx]; }; ArrayLike.prototype.clear = function () { this._array.length = 0; this.arrayContentDidChange(); }; ArrayLike.prototype.replace = function (idx, del, ins) { var _array; (_array = this._array).splice.apply(_array, [idx, del].concat(ins)); this.arrayContentDidChange(); }; ArrayLike.prototype.unshiftObject = function (obj) { this._array.unshift(obj); this.arrayContentDidChange(); }; ArrayLike.prototype.unshiftObjects = function (arr) { var _array2; (_array2 = this._array).unshift.apply(_array2, arr); this.arrayContentDidChange(); }; ArrayLike.prototype.pushObject = function (obj) { this._array.push(obj); this.arrayContentDidChange(); }; ArrayLike.prototype.pushObjects = function (arr) { var _array3; (_array3 = this._array).push.apply(_array3, arr); this.arrayContentDidChange(); }; ArrayLike.prototype.shiftObject = function () { var obj = this._array.shift(); this.arrayContentDidChange(); return obj; }; ArrayLike.prototype.popObject = function () { var obj = this._array.pop(); this.arrayContentDidChange(); return obj; }; ArrayLike.prototype.insertAt = function (idx, obj) { this._array.splice(idx, 0, obj); this.arrayContentDidChange(); }; ArrayLike.prototype.removeAt = function (idx) { var len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; this._array.splice(idx, len); this.arrayContentDidChange(); }; ArrayLike.prototype.arrayContentDidChange = function () { (0, _emberMetal.propertyDidChange)(this, '[]'); (0, _emberMetal.propertyDidChange)(this, 'length'); }; (0, _emberBabel.createClass)(ArrayLike, [{ key: 'length', get: function () { return this._array.length; } }]); return ArrayLike; }(); var TogglingEachTest = function (_TogglingSyntaxCondit) { (0, _emberBabel.inherits)(TogglingEachTest, _TogglingSyntaxCondit); function TogglingEachTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingSyntaxCondit.apply(this, arguments)); } (0, _emberBabel.createClass)(TogglingEachTest, [{ key: 'truthyValue', get: function () { return ['non-empty']; } }, { key: 'falsyValue', get: function () { return []; } }]); return TogglingEachTest; }(_sharedConditionalTests.TogglingSyntaxConditionalsTest); var BasicEachTest = function (_TogglingEachTest) { (0, _emberBabel.inherits)(BasicEachTest, _TogglingEachTest); function BasicEachTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingEachTest.apply(this, arguments)); } return BasicEachTest; }(TogglingEachTest); (0, _abstractTestCase.applyMixins)(BasicEachTest, new _sharedConditionalTests.TruthyGenerator([['hello'], (0, _emberRuntime.A)(['hello']), new ArrayLike(['hello']), _emberRuntime.ArrayProxy.create({ content: ['hello'] }), _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(['hello']) })]), new _sharedConditionalTests.FalsyGenerator([null, undefined, false, '', 0, []]), _sharedConditionalTests.ArrayTestCases); (0, _testCase.moduleFor)('Syntax test: toggling {{#each}}', function (_BasicEachTest) { (0, _emberBabel.inherits)(_class, _BasicEachTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _BasicEachTest.apply(this, arguments)); } _class.prototype.templateFor = function (_ref) { var cond = _ref.cond, truthy = _ref.truthy, falsy = _ref.falsy; return '{{#each ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/each}}'; }; return _class; }(BasicEachTest)); (0, _testCase.moduleFor)('Syntax test: toggling {{#each as}}', function (_BasicEachTest2) { (0, _emberBabel.inherits)(_class2, _BasicEachTest2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _BasicEachTest2.apply(this, arguments)); } _class2.prototype.templateFor = function (_ref2) { var cond = _ref2.cond, truthy = _ref2.truthy, falsy = _ref2.falsy; return '{{#each ' + cond + ' as |test|}}' + truthy + '{{else}}' + falsy + '{{/each}}'; }; return _class2; }(BasicEachTest)); var EachEdgeCasesTest = function (_TogglingEachTest2) { (0, _emberBabel.inherits)(EachEdgeCasesTest, _TogglingEachTest2); function EachEdgeCasesTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingEachTest2.apply(this, arguments)); } return EachEdgeCasesTest; }(TogglingEachTest); (0, _abstractTestCase.applyMixins)(EachEdgeCasesTest, new _sharedConditionalTests.FalsyGenerator([true, 'hello', 1, Object, function () {}, {}, { foo: 'bar' }, Object.create(null), Object.create({}), Object.create({ foo: 'bar' })])); (0, _testCase.moduleFor)('Syntax test: toggling {{#each}}', function (_EachEdgeCasesTest) { (0, _emberBabel.inherits)(_class3, _EachEdgeCasesTest); function _class3() { return (0, _emberBabel.possibleConstructorReturn)(this, _EachEdgeCasesTest.apply(this, arguments)); } _class3.prototype.templateFor = function (_ref3) { var cond = _ref3.cond, truthy = _ref3.truthy, falsy = _ref3.falsy; return '{{#each ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/each}}'; }; return _class3; }(EachEdgeCasesTest)); (0, _testCase.moduleFor)('Syntax test: toggling {{#each as}}', function (_EachEdgeCasesTest2) { (0, _emberBabel.inherits)(_class4, _EachEdgeCasesTest2); function _class4() { return (0, _emberBabel.possibleConstructorReturn)(this, _EachEdgeCasesTest2.apply(this, arguments)); } _class4.prototype.templateFor = function (_ref4) { var cond = _ref4.cond, truthy = _ref4.truthy, falsy = _ref4.falsy; return '{{#each ' + cond + ' as |test|}}' + truthy + '{{else}}' + falsy + '{{/each}}'; }; return _class4; }(EachEdgeCasesTest)); var AbstractEachTest = function (_RenderingTest) { (0, _emberBabel.inherits)(AbstractEachTest, _RenderingTest); function AbstractEachTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } AbstractEachTest.prototype.makeList = function () { // this.list = this.delegate = ...; throw new Error('Not implemented: `makeList`'); }; AbstractEachTest.prototype.replaceList = function (list) { var _this9 = this; this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'list', _this9.makeList(list)); }); }; AbstractEachTest.prototype.forEach = function (callback) { return this.delegate.forEach(callback); }; AbstractEachTest.prototype.objectAt = function (idx) { return this.delegate.objectAt(idx); }; AbstractEachTest.prototype.clear = function () { return this.delegate.clear(); }; AbstractEachTest.prototype.replace = function (idx, del, ins) { return this.delegate.replace(idx, del, ins); }; AbstractEachTest.prototype.unshiftObject = function (obj) { return this.delegate.unshiftObject(obj); }; AbstractEachTest.prototype.unshiftObjects = function (arr) { return this.delegate.unshiftObjects(arr); }; AbstractEachTest.prototype.pushObject = function (obj) { return this.delegate.pushObject(obj); }; AbstractEachTest.prototype.pushObjects = function (arr) { return this.delegate.pushObjects(arr); }; AbstractEachTest.prototype.shiftObject = function () { return this.delegate.shiftObject(); }; AbstractEachTest.prototype.popObject = function () { return this.delegate.popObject(); }; AbstractEachTest.prototype.insertAt = function (idx, obj) { return this.delegate.insertAt(idx, obj); }; AbstractEachTest.prototype.removeAt = function (idx, len) { return this.delegate.removeAt(idx, len); }; AbstractEachTest.prototype.render = function (template) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (this.list === undefined) { throw new Error('Must call `this.makeList()` before calling this.render()'); } context.list = this.list; return _RenderingTest.prototype.render.call(this, template, context); }; return AbstractEachTest; }(_testCase.RenderingTest); var SingleEachTest = function (_AbstractEachTest) { (0, _emberBabel.inherits)(SingleEachTest, _AbstractEachTest); function SingleEachTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractEachTest.apply(this, arguments)); } SingleEachTest.prototype['@test it repeats the given block for each item in the array'] = function () { var _this11 = this; this.makeList([{ text: 'hello' }]); this.render('{{#each list as |item|}}{{item.text}}{{else}}Empty{{/each}}'); this.assertText('hello'); this.runTask(function () { return _this11.rerender(); }); this.assertText('hello'); this.runTask(function () { return (0, _emberMetal.set)(_this11.objectAt(0), 'text', 'Hello'); }); this.assertText('Hello'); this.runTask(function () { _this11.pushObject({ text: ' ' }); _this11.pushObject({ text: 'World' }); }); this.assertText('Hello World'); this.runTask(function () { _this11.pushObject({ text: 'Earth' }); _this11.removeAt(1); _this11.insertAt(1, { text: 'Globe' }); }); this.assertText('HelloGlobeWorldEarth'); this.runTask(function () { _this11.pushObject({ text: 'Planet' }); _this11.removeAt(1); _this11.insertAt(1, { text: ' ' }); _this11.pushObject({ text: ' ' }); _this11.pushObject({ text: 'Earth' }); _this11.removeAt(3); }); this.assertText('Hello WorldPlanet Earth'); this.runTask(function () { _this11.pushObject({ text: 'Globe' }); _this11.removeAt(1); _this11.insertAt(1, { text: ' ' }); _this11.pushObject({ text: ' ' }); _this11.pushObject({ text: 'World' }); _this11.removeAt(2); }); this.assertText('Hello Planet EarthGlobe World'); this.runTask(function () { return _this11.replace(2, 4, { text: 'my' }); }); this.assertText('Hello my World'); this.runTask(function () { return _this11.clear(); }); this.assertText('Empty'); this.replaceList([{ text: 'hello' }]); this.assertText('hello'); }; SingleEachTest.prototype['@test it receives the index as the second parameter'] = function () { var _this12 = this; this.makeList([{ text: 'hello' }, { text: 'world' }]); this.render('{{#each list as |item index|}}[{{index}}. {{item.text}}]{{/each}}'); this.assertText('[0. hello][1. world]'); this.assertStableRerender(); this.runTask(function () { return _this12.insertAt(1, { text: 'my' }); }); this.assertText('[0. hello][1. my][2. world]'); this.replaceList([{ text: 'hello' }, { text: 'world' }]); this.assertText('[0. hello][1. world]'); }; SingleEachTest.prototype['@test it accepts a string key'] = function () { var _this13 = this; this.makeList([{ text: 'hello' }, { text: 'world' }]); this.render('{{#each list key=\'text\' as |item|}}{{item.text}}{{/each}}'); this.assertText('helloworld'); this.assertStableRerender(); this.runTask(function () { return _this13.pushObject({ text: 'again' }); }); this.assertText('helloworldagain'); this.replaceList([{ text: 'hello' }, { text: 'world' }]); this.assertText('helloworld'); }; SingleEachTest.prototype['@test it accepts a numeric key'] = function () { var _this14 = this; this.makeList([{ id: 1 }, { id: 2 }]); this.render('{{#each list key=\'id\' as |item|}}{{item.id}}{{/each}}'); this.assertText('12'); this.assertStableRerender(); this.runTask(function () { return _this14.pushObject({ id: 3 }); }); this.assertText('123'); this.replaceList([{ id: 1 }, { id: 2 }]); this.assertText('12'); }; SingleEachTest.prototype['@test it can specify @index as the key'] = function () { var _this15 = this; this.makeList([{ id: 1 }, { id: 2 }]); this.render('{{#each list key=\'@index\' as |item|}}{{item.id}}{{/each}}'); this.assertText('12'); this.assertStableRerender(); this.runTask(function () { return _this15.pushObject({ id: 3 }); }); this.assertText('123'); this.replaceList([{ id: 1 }, { id: 2 }]); this.assertText('12'); }; SingleEachTest.prototype['@test it can specify @identity as the key for arrays of primitives'] = function () { var _this16 = this; this.makeList([1, 2]); this.render('{{#each list key=\'@identity\' as |item|}}{{item}}{{/each}}'); this.assertText('12'); this.assertStableRerender(); this.runTask(function () { return _this16.pushObject(3); }); this.assertText('123'); this.replaceList([1, 2]); this.assertText('12'); }; SingleEachTest.prototype['@test it can specify @identity as the key for mixed arrays of objects and primitives'] = function () { var _this17 = this; this.makeList([1, { id: 2 }, 3]); this.render('{{#each list key=\'@identity\' as |item|}}{{if item.id item.id item}}{{/each}}'); this.assertText('123'); this.assertStableRerender(); this.runTask(function () { return _this17.insertAt(2, { id: 4 }); }); this.assertText('1243'); this.replaceList([1, { id: 2 }, 3]); this.assertText('123'); }; SingleEachTest.prototype['@test it can render duplicate primitive items'] = function () { var _this18 = this; this.makeList(['a', 'a', 'a']); this.render('{{#each list as |item|}}{{item}}{{/each}}'); this.assertText('aaa'); this.assertStableRerender(); this.runTask(function () { return _this18.pushObject('a'); }); this.assertText('aaaa'); this.runTask(function () { return _this18.pushObject('a'); }); this.assertText('aaaaa'); this.replaceList(['a', 'a', 'a']); this.assertText('aaa'); }; SingleEachTest.prototype['@test updating and setting within #each'] = function () { var _this19 = this; this.makeList([{ value: 1 }, { value: 2 }, { value: 3 }]); var FooBarComponent = _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); this.isEven = true; this.tagName = 'li'; }, _isEven: function () { this.set('isEven', this.get('item.value') % 2 === 0); }, didUpdate: function () { this._isEven(); } }); this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{#if isEven}}{{item.value}}{{/if}}' }); this.render((0, _abstractTestCase.strip)(_templateObject)); this.assertText('Prev1NextPrev2NextPrev3Next'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this19.context.list.objectAt(0), 'value', 3); }); this.assertText('PrevNextPrev2NextPrev3Next'); this.replaceList([{ value: 1 }, { value: 2 }, { value: 3 }]); this.assertText('Prev1NextPrev2NextPrev3Next'); }; SingleEachTest.prototype['@test it can render duplicate objects'] = function () { var _this20 = this; var duplicateItem = { text: 'foo' }; this.makeList([duplicateItem, duplicateItem, { text: 'bar' }, { text: 'baz' }]); this.render('{{#each list as |item|}}{{item.text}}{{/each}}'); this.assertText('foofoobarbaz'); this.assertStableRerender(); this.runTask(function () { return _this20.pushObject(duplicateItem); }); this.assertText('foofoobarbazfoo'); this.runTask(function () { return _this20.pushObject(duplicateItem); }); this.assertText('foofoobarbazfoofoo'); this.replaceList([duplicateItem, duplicateItem, { text: 'bar' }, { text: 'baz' }]); this.assertText('foofoobarbaz'); }; SingleEachTest.prototype['@test it maintains DOM stability when condition changes between objects with the same keys'] = function () { var _this21 = this; this.makeList([{ text: 'Hello' }, { text: ' ' }, { text: 'world' }]); this.render('{{#each list key="text" as |item|}}{{item.text}}{{/each}}'); this.assertText('Hello world'); this.takeSnapshot(); this.runTask(function () { _this21.popObject(); _this21.popObject(); _this21.pushObject({ text: ' ' }); _this21.pushObject({ text: 'world' }); }); this.assertText('Hello world'); this.assertInvariants(); this.replaceList([{ text: 'Hello' }, { text: ' ' }, { text: 'world' }]); this.assertText('Hello world'); this.assertInvariants(); }; SingleEachTest.prototype['@test it maintains DOM stability for stable keys when list is updated'] = function () { var _this22 = this; this.makeList([{ text: 'Hello' }, { text: ' ' }, { text: 'world' }]); this.render('{{#each list key="text" as |item|}}{{item.text}}{{/each}}'); this.assertText('Hello world'); this.assertStableRerender(); var oldSnapshot = this.takeSnapshot(); this.runTask(function () { _this22.unshiftObject({ text: ', ' }); _this22.unshiftObject({ text: 'Hi' }); _this22.pushObject({ text: '!' }); _this22.pushObject({ text: 'earth' }); }); this.assertText('Hi, Hello world!earth'); this.assertPartialInvariants(2, 5); this.replaceList([{ text: 'Hello' }, { text: ' ' }, { text: 'world' }]); this.assertText('Hello world'); this.assertInvariants(oldSnapshot, this.takeSnapshot()); }; SingleEachTest.prototype['@test it renders all items with duplicate key values'] = function () { var _this23 = this; this.makeList([{ text: 'Hello' }, { text: 'Hello' }, { text: 'Hello' }]); this.render('{{#each list key="text" as |item|}}{{item.text}}{{/each}}'); this.assertText('HelloHelloHello'); this.runTask(function () { _this23.forEach(function (hash) { return (0, _emberMetal.set)(hash, 'text', 'Goodbye'); }); }); this.assertText('GoodbyeGoodbyeGoodbye'); this.replaceList([{ text: 'Hello' }, { text: 'Hello' }, { text: 'Hello' }]); this.assertText('HelloHelloHello'); }; SingleEachTest.prototype['@test context is not changed to the inner scope inside an {{#each as}} block'] = function () { var _this24 = this; this.makeList([{ name: 'Chad' }, { name: 'Zack' }, { name: 'Asa' }]); this.render('{{name}}-{{#each list as |person|}}{{name}}{{/each}}-{{name}}', { name: 'Joel' }); this.assertText('Joel-JoelJoelJoel-Joel'); this.assertStableRerender(); this.runTask(function () { return _this24.shiftObject(); }); this.assertText('Joel-JoelJoel-Joel'); this.runTask(function () { return (0, _emberMetal.set)(_this24.context, 'name', 'Godfrey'); }); this.assertText('Godfrey-GodfreyGodfrey-Godfrey'); this.runTask(function () { return (0, _emberMetal.set)(_this24.context, 'name', 'Joel'); }); this.replaceList([{ name: 'Chad' }, { name: 'Zack' }, { name: 'Asa' }]); this.assertText('Joel-JoelJoelJoel-Joel'); }; SingleEachTest.prototype['@test can access the item and the original scope'] = function () { var _this25 = this; this.makeList([{ name: 'Tom Dale' }, { name: 'Yehuda Katz' }, { name: 'Godfrey Chan' }]); this.render('{{#each list key="name" as |person|}}[{{title}}: {{person.name}}]{{/each}}', { title: 'Señor Engineer' }); this.assertText('[Señor Engineer: Tom Dale][Señor Engineer: Yehuda Katz][Señor Engineer: Godfrey Chan]'); this.runTask(function () { return _this25.rerender(); }); this.assertText('[Señor Engineer: Tom Dale][Señor Engineer: Yehuda Katz][Señor Engineer: Godfrey Chan]'); this.runTask(function () { (0, _emberMetal.set)(_this25.objectAt(1), 'name', 'Stefan Penner'); _this25.removeAt(0); _this25.pushObject({ name: 'Tom Dale' }); _this25.insertAt(1, { name: 'Chad Hietala' }); (0, _emberMetal.set)(_this25.context, 'title', 'Principal Engineer'); }); this.assertText('[Principal Engineer: Stefan Penner][Principal Engineer: Chad Hietala][Principal Engineer: Godfrey Chan][Principal Engineer: Tom Dale]'); this.runTask(function () { return (0, _emberMetal.set)(_this25.context, 'title', 'Señor Engineer'); }); this.replaceList([{ name: 'Tom Dale' }, { name: 'Yehuda Katz' }, { name: 'Godfrey Chan' }]); this.assertText('[Señor Engineer: Tom Dale][Señor Engineer: Yehuda Katz][Señor Engineer: Godfrey Chan]'); }; SingleEachTest.prototype['@test the scoped variable is not available outside the {{#each}} block.'] = function () { var _this26 = this; this.makeList(['Yehuda']); this.render('{{name}}-{{#each list as |name|}}{{name}}{{/each}}-{{name}}', { name: 'Stef' }); this.assertText('Stef-Yehuda-Stef'); this.runTask(function () { return _this26.rerender(); }); this.assertText('Stef-Yehuda-Stef'); this.runTask(function () { return _this26.pushObjects([' ', 'Katz']); }); this.assertText('Stef-Yehuda Katz-Stef'); this.runTask(function () { return (0, _emberMetal.set)(_this26.context, 'name', 'Tom'); }); this.assertText('Tom-Yehuda Katz-Tom'); this.runTask(function () { return (0, _emberMetal.set)(_this26.context, 'name', 'Stef'); }); this.replaceList(['Yehuda']); this.assertText('Stef-Yehuda-Stef'); }; SingleEachTest.prototype['@test inverse template is displayed with context'] = function () { var _this27 = this; this.makeList([]); this.render('{{#each list as |thing|}}Has Thing{{else}}No Thing {{otherThing}}{{/each}}', { otherThing: 'bar' }); this.assertText('No Thing bar'); this.runTask(function () { return _this27.rerender(); }); this.assertText('No Thing bar'); this.runTask(function () { return (0, _emberMetal.set)(_this27.context, 'otherThing', 'biz'); }); this.assertText('No Thing biz'); this.runTask(function () { return _this27.pushObject('non-empty'); }); this.assertText('Has Thing'); this.runTask(function () { return (0, _emberMetal.set)(_this27.context, 'otherThing', 'baz'); }); this.assertText('Has Thing'); this.runTask(function () { return (0, _emberMetal.set)(_this27.context, 'otherThing', 'bar'); }); this.replaceList([]); this.assertText('No Thing bar'); }; SingleEachTest.prototype['@test content that are not initially present updates correctly GH#13983'] = function () { var _this28 = this; // The root cause of this bug is that Glimmer did not call `didInitializeChildren` // on the inserted `TryOpcode`, causing that `TryOpcode` to have an uninitialized // tag. Currently the only way to observe this the "JUMP-IF-NOT-MODIFIED", i.e. by // wrapping it in an component. this.registerComponent('x-wrapper', { template: '{{yield}}' }); this.makeList([]); this.render('{{#x-wrapper}}{{#each list as |obj|}}[{{obj.text}}]{{/each}}{{/x-wrapper}}'); this.assertText(''); this.runTask(function () { return _this28.rerender(); }); this.assertText(''); this.runTask(function () { return _this28.pushObject({ text: 'foo' }); }); this.assertText('[foo]'); this.runTask(function () { return (0, _emberMetal.set)(_this28.objectAt(0), 'text', 'FOO'); }); this.assertText('[FOO]'); this.runTask(function () { return _this28.pushObject({ text: 'bar' }); }); this.assertText('[FOO][bar]'); this.runTask(function () { return (0, _emberMetal.set)(_this28.objectAt(1), 'text', 'BAR'); }); this.assertText('[FOO][BAR]'); this.runTask(function () { return (0, _emberMetal.set)(_this28.objectAt(1), 'text', 'baz'); }); this.assertText('[FOO][baz]'); this.runTask(function () { return _this28.replace(1, 1, [{ text: 'BAZ' }]); }); this.assertText('[FOO][BAZ]'); this.replaceList([]); this.assertText(''); }; return SingleEachTest; }(AbstractEachTest); (0, _testCase.moduleFor)('Syntax test: {{#each}} with arrays', function (_SingleEachTest) { (0, _emberBabel.inherits)(_class5, _SingleEachTest); function _class5() { return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest.apply(this, arguments)); } _class5.prototype.makeList = function (list) { return this.list = this.delegate = (0, _emberRuntime.A)(list); }; return _class5; }(SingleEachTest)); (0, _testCase.moduleFor)('Syntax test: {{#each}} with array-like objects', function (_SingleEachTest2) { (0, _emberBabel.inherits)(_class6, _SingleEachTest2); function _class6() { return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest2.apply(this, arguments)); } _class6.prototype.makeList = function (list) { return this.list = this.delegate = new ArrayLike(list); }; return _class6; }(SingleEachTest)); (0, _testCase.moduleFor)('Syntax test: {{#each}} with array proxies, modifying itself', function (_SingleEachTest3) { (0, _emberBabel.inherits)(_class7, _SingleEachTest3); function _class7() { return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest3.apply(this, arguments)); } _class7.prototype.makeList = function (list) { return this.list = this.delegate = _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(list) }); }; return _class7; }(SingleEachTest)); (0, _testCase.moduleFor)('Syntax test: {{#each}} with array proxies, replacing its content', function (_SingleEachTest4) { (0, _emberBabel.inherits)(_class8, _SingleEachTest4); function _class8() { return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest4.apply(this, arguments)); } _class8.prototype.makeList = function (list) { var content = this.delegate = (0, _emberRuntime.A)(list); return this.list = _emberRuntime.ArrayProxy.create({ content: content }); }; _class8.prototype.replaceList = function (list) { var _this33 = this; this.runTask(function () { return _this33.list.set('content', (0, _emberRuntime.A)(list)); }); }; return _class8; }(SingleEachTest)); // TODO: Refactor the following tests so we can run them against different kind of arrays (0, _testCase.moduleFor)('Syntax test: Multiple {{#each as}} helpers', function (_RenderingTest2) { (0, _emberBabel.inherits)(_class9, _RenderingTest2); function _class9() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments)); } _class9.prototype['@test re-using the same variable with different {{#each}} blocks does not override each other'] = function () { var _this35 = this; this.render('Admin: {{#each admins key="name" as |person|}}[{{person.name}}]{{/each}} User: {{#each users key="name" as |person|}}[{{person.name}}]{{/each}}', { admins: (0, _emberRuntime.A)([{ name: 'Tom Dale' }]), users: (0, _emberRuntime.A)([{ name: 'Yehuda Katz' }]) }); this.assertText('Admin: [Tom Dale] User: [Yehuda Katz]'); this.runTask(function () { return _this35.rerender(); }); this.assertText('Admin: [Tom Dale] User: [Yehuda Katz]'); this.runTask(function () { (0, _emberMetal.get)(_this35.context, 'admins').pushObject({ name: 'Godfrey Chan' }); (0, _emberMetal.set)((0, _emberMetal.get)(_this35.context, 'users').objectAt(0), 'name', 'Stefan Penner'); }); this.assertText('Admin: [Tom Dale][Godfrey Chan] User: [Stefan Penner]'); this.runTask(function () { (0, _emberMetal.set)(_this35.context, 'admins', [{ name: 'Tom Dale' }]); (0, _emberMetal.set)(_this35.context, 'users', [{ name: 'Yehuda Katz' }]); }); this.assertText('Admin: [Tom Dale] User: [Yehuda Katz]'); }; _class9.prototype['@test an outer {{#each}}\'s scoped variable does not clobber an inner {{#each}}\'s property if they share the same name - Issue #1315'] = function () { var _this36 = this; this.render((0, _abstractTestCase.strip)(_templateObject2), { content: (0, _emberRuntime.A)(['X', 'Y']), options: (0, _emberRuntime.A)([{ label: 'One', value: 1 }, { label: 'Two', value: 2 }]) }); this.assertText('X-1:One2:TwoY-1:One2:Two'); this.assertStableRerender(); this.runTask(function () { (0, _emberMetal.get)(_this36.context, 'content').pushObject('Z'); (0, _emberMetal.set)((0, _emberMetal.get)(_this36.context, 'options').objectAt(0), 'value', 0); }); this.assertText('X-0:One2:TwoY-0:One2:TwoZ-0:One2:Two'); this.runTask(function () { (0, _emberMetal.set)(_this36.context, 'content', ['X', 'Y']); (0, _emberMetal.set)(_this36.context, 'options', [{ label: 'One', value: 1 }, { label: 'Two', value: 2 }]); }); this.assertText('X-1:One2:TwoY-1:One2:Two'); }; _class9.prototype['@test the scoped variable is not available outside the {{#each}} block'] = function () { var _this37 = this; this.render('{{ring}}-{{#each first as |ring|}}{{ring}}-{{#each fifth as |ring|}}{{ring}}-{{#each ninth as |ring|}}{{ring}}-{{/each}}{{ring}}-{{/each}}{{ring}}-{{/each}}{{ring}}', { ring: 'Greed', first: (0, _emberRuntime.A)(['Limbo']), fifth: (0, _emberRuntime.A)(['Wrath']), ninth: (0, _emberRuntime.A)(['Treachery']) }); this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed'); this.runTask(function () { return _this37.rerender(); }); this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed'); this.runTask(function () { (0, _emberMetal.set)(_this37.context, 'ring', 'O'); (0, _emberMetal.get)(_this37.context, 'fifth').insertAt(0, 'D'); }); this.assertText('O-Limbo-D-Treachery-D-Wrath-Treachery-Wrath-Limbo-O'); this.runTask(function () { (0, _emberMetal.get)(_this37.context, 'first').pushObject('I'); (0, _emberMetal.get)(_this37.context, 'ninth').replace(0, 1, 'K'); }); this.assertText('O-Limbo-D-K-D-Wrath-K-Wrath-Limbo-I-D-K-D-Wrath-K-Wrath-I-O'); this.runTask(function () { (0, _emberMetal.set)(_this37.context, 'ring', 'Greed'); (0, _emberMetal.set)(_this37.context, 'first', ['Limbo']); (0, _emberMetal.set)(_this37.context, 'fifth', ['Wrath']); (0, _emberMetal.set)(_this37.context, 'ninth', ['Treachery']); }); this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed'); }; _class9.prototype['@test it should support {{#each name as |foo|}}, then {{#each foo as |bar|}}'] = function () { var _this38 = this; this.render('{{#each name key="@index" as |foo|}}{{#each foo as |bar|}}{{bar}}{{/each}}{{/each}}', { name: (0, _emberRuntime.A)([(0, _emberRuntime.A)(['caterpillar'])]) }); this.assertText('caterpillar'); this.runTask(function () { return _this38.rerender(); }); this.assertText('caterpillar'); this.runTask(function () { var name = (0, _emberMetal.get)(_this38.context, 'name'); name.objectAt(0).replace(0, 1, 'lady'); name.pushObject(['bird']); }); this.assertText('ladybird'); this.runTask(function () { return (0, _emberMetal.set)(_this38.context, 'name', [['caterpillar']]); }); this.assertText('caterpillar'); }; return _class9; }(_testCase.RenderingTest)); (0, _testCase.moduleFor)('Syntax test: {{#each as}} undefined path', function (_RenderingTest3) { (0, _emberBabel.inherits)(_class10, _RenderingTest3); function _class10() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest3.apply(this, arguments)); } _class10.prototype['@test keying off of `undefined` does not render'] = function () { var _this40 = this; this.render((0, _abstractTestCase.strip)(_templateObject3), { foo: {} }); this.assertText(''); this.runTask(function () { return _this40.rerender(); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this40.context, 'foo', { bar: { baz: ['Here!'] } }); }); this.assertText('Here!'); this.runTask(function () { return (0, _emberMetal.set)(_this40.context, 'foo', {}); }); this.assertText(''); }; return _class10; }(_testCase.RenderingTest)); (0, _testCase.moduleFor)('Syntax test: {{#each}} with sparse arrays', function (_RenderingTest4) { (0, _emberBabel.inherits)(_class11, _RenderingTest4); function _class11() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest4.apply(this, arguments)); } _class11.prototype['@test it should itterate over holes'] = function () { var _this42 = this; var sparseArray = []; sparseArray[3] = 'foo'; sparseArray[4] = 'bar'; this.render((0, _abstractTestCase.strip)(_templateObject4), { list: (0, _emberRuntime.A)(sparseArray) }); this.assertText('[0:][1:][2:][3:foo][4:bar]'); this.assertStableRerender(); this.runTask(function () { var list = (0, _emberMetal.get)(_this42.context, 'list'); list.pushObject('baz'); }); this.assertText('[0:][1:][2:][3:foo][4:bar][5:baz]'); }; return _class11; }(_testCase.RenderingTest)); /* globals MutationObserver: false */ if (typeof MutationObserver === 'function') { (0, _testCase.moduleFor)('Syntax test: {{#each as}} DOM mutation test', function (_RenderingTest5) { (0, _emberBabel.inherits)(_class12, _RenderingTest5); function _class12() { var _this43 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest5.call(this)); _this43.observer = null; return _this43; } _class12.prototype.observe = function (element) { var observer = this.observer = new MutationObserver(function () {}); observer.observe(element, { childList: true, characterData: true }); }; _class12.prototype.teardown = function () { if (this.observer) { this.observer.disconnect(); } _RenderingTest5.prototype.teardown.call(this); }; _class12.prototype.assertNoMutation = function () { this.assert.deepEqual(this.observer.takeRecords(), [], 'Expected no mutations'); }; _class12.prototype.expectMutations = function () { this.assert.ok(this.observer.takeRecords().length > 0, 'Expected some mutations'); }; _class12.prototype['@test {{#each}} should not mutate a subtree when the array has not changed [GH #14332]'] = function () { var _this44 = this; this.render((0, _abstractTestCase.strip)(_templateObject5), { page: { title: 'Blog Posts' }, model: [{ title: 'Rails is omakase' }, { title: 'Ember is omakase' }] }); this.assertHTML((0, _abstractTestCase.strip)(_templateObject6)); this.observe(this.$('#posts')[0]); // MutationObserver is async return _emberRuntime.RSVP.Promise.resolve(function () { _this44.assertStableRerender(); }).then(function () { _this44.assertNoMutation(); _this44.runTask(function () { return (0, _emberMetal.set)(_this44.context, 'page', { title: 'Essays' }); }); _this44.assertHTML((0, _abstractTestCase.strip)(_templateObject7)); }).then(function () { _this44.assertNoMutation(); _this44.runTask(function () { return (0, _emberMetal.set)(_this44.context.page, 'title', 'Think Pieces™'); }); _this44.assertHTML((0, _abstractTestCase.strip)(_templateObject8)); }).then(function () { // The last set is localized to the `page` object, so we do not expect Glimmer // to re-iterate the list _this44.assertNoMutation(); }); }; return _class12; }(_testCase.RenderingTest)); } }); enifed('ember-glimmer/tests/integration/syntax/if-unless-test', ['ember-babel', 'ember-glimmer/tests/utils/helpers', 'ember-runtime', 'ember-metal', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/shared-conditional-tests'], function (_emberBabel, _helpers, _emberRuntime, _emberMetal, _abstractTestCase, _testCase, _sharedConditionalTests) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if cond}}\n {{#each numbers as |number|}}\n {{foo-bar number=number}}\n {{/each}}\n {{else}}\n Nothing Here!\n {{/if}}'], ['\n {{#if cond}}\n {{#each numbers as |number|}}\n {{foo-bar number=number}}\n {{/each}}\n {{else}}\n Nothing Here!\n {{/if}}']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if foo.bar.baz}}\n Here!\n {{else}}\n Nothing Here!\n {{/if}}'], ['\n {{#if foo.bar.baz}}\n Here!\n {{else}}\n Nothing Here!\n {{/if}}']); (0, _testCase.moduleFor)('Syntax test: {{#if}} with inverse', function (_IfUnlessWithSyntaxTe) { (0, _emberBabel.inherits)(_class, _IfUnlessWithSyntaxTe); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe.apply(this, arguments)); } _class.prototype.templateFor = function (_ref) { var cond = _ref.cond, truthy = _ref.truthy, falsy = _ref.falsy; return '{{#if ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/if}}'; }; return _class; }(_sharedConditionalTests.IfUnlessWithSyntaxTest)); (0, _testCase.moduleFor)('Syntax test: {{#unless}} with inverse', function (_IfUnlessWithSyntaxTe2) { (0, _emberBabel.inherits)(_class2, _IfUnlessWithSyntaxTe2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe2.apply(this, arguments)); } _class2.prototype.templateFor = function (_ref2) { var cond = _ref2.cond, truthy = _ref2.truthy, falsy = _ref2.falsy; return '{{#unless ' + cond + '}}' + falsy + '{{else}}' + truthy + '{{/unless}}'; }; return _class2; }(_sharedConditionalTests.IfUnlessWithSyntaxTest)); (0, _testCase.moduleFor)('Syntax test: {{#if}} and {{#unless}} without inverse', function (_IfUnlessWithSyntaxTe3) { (0, _emberBabel.inherits)(_class3, _IfUnlessWithSyntaxTe3); function _class3() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe3.apply(this, arguments)); } _class3.prototype.templateFor = function (_ref3) { var cond = _ref3.cond, truthy = _ref3.truthy, falsy = _ref3.falsy; return '{{#if ' + cond + '}}' + truthy + '{{/if}}{{#unless ' + cond + '}}' + falsy + '{{/unless}}'; }; return _class3; }(_sharedConditionalTests.IfUnlessWithSyntaxTest)); (0, _testCase.moduleFor)('Syntax test: {{#if}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class4, _RenderingTest); function _class4() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class4.prototype['@test using `if` with an `{{each}}` destroys components when transitioning to and from inverse (GH #12267)'] = function (assert) { var _this5 = this; var destroyedChildrenCount = 0; this.registerComponent('foo-bar', { template: '{{number}}', ComponentClass: _helpers.Component.extend({ willDestroy: function () { this._super(); destroyedChildrenCount++; } }) }); this.render((0, _abstractTestCase.strip)(_templateObject), { cond: true, numbers: (0, _emberRuntime.A)([1, 2, 3]) }); this.assertText('123'); this.runTask(function () { return _this5.rerender(); }); this.assertText('123'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'cond', false); }); this.assertText('Nothing Here!'); assert.equal(destroyedChildrenCount, 3, 'the children were properly destroyed'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'cond', true); }); this.assertText('123'); }; _class4.prototype['@test looking up `undefined` property defaults to false'] = function () { var _this6 = this; this.render((0, _abstractTestCase.strip)(_templateObject2), { foo: {} }); this.assertText('Nothing Here!'); this.runTask(function () { return _this6.rerender(); }); this.assertText('Nothing Here!'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'foo', { bar: { baz: true } }); }); this.assertText('Here!'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'foo', {}); }); this.assertText('Nothing Here!'); }; return _class4; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/syntax/in-element-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/test-helpers', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/component', 'ember-metal'], function (_emberBabel, _testCase, _testHelpers, _abstractTestCase, _component, _emberMetal) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#-in-element someElement}}\n {{text}}\n {{/-in-element}}\n '], ['\n {{#-in-element someElement}}\n {{text}}\n {{/-in-element}}\n ']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if showModal}}\n {{#-in-element someElement}}\n {{modal-display text=text}}\n {{/-in-element}}\n {{/if}}\n '], ['\n {{#if showModal}}\n {{#-in-element someElement}}\n {{modal-display text=text}}\n {{/-in-element}}\n {{/if}}\n ']); (0, _testCase.moduleFor)('{{-in-element}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test allows rendering into an external element'] = function () { var _this2 = this; var someElement = document.createElement('div'); this.render((0, _abstractTestCase.strip)(_templateObject), { someElement: someElement, text: 'Whoop!' }); (0, _testHelpers.equalTokens)(this.element, ''); (0, _testHelpers.equalTokens)(someElement, 'Whoop!'); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'text', 'Huzzah!!'); }); (0, _testHelpers.equalTokens)(this.element, ''); (0, _testHelpers.equalTokens)(someElement, 'Huzzah!!'); this.runTask(function () { return (0, _emberMetal.set)(_this2.context, 'text', 'Whoop!'); }); (0, _testHelpers.equalTokens)(this.element, ''); (0, _testHelpers.equalTokens)(someElement, 'Whoop!'); }; _class.prototype['@test components are cleaned up properly'] = function (assert) { var _this3 = this; var hooks = []; var someElement = document.createElement('div'); this.registerComponent('modal-display', { ComponentClass: _component.default.extend({ didInsertElement: function () { hooks.push('didInsertElement'); }, willDestroyElement: function () { hooks.push('willDestroyElement'); } }), template: '{{text}}' }); this.render((0, _abstractTestCase.strip)(_templateObject2), { someElement: someElement, text: 'Whoop!', showModal: false }); (0, _testHelpers.equalTokens)(this.element, ''); (0, _testHelpers.equalTokens)(someElement, ''); this.assertStableRerender(); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'showModal', true); }); (0, _testHelpers.equalTokens)(this.element, ''); this.assertComponentElement(someElement.firstChild, { content: 'Whoop!' }); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'text', 'Huzzah!'); }); (0, _testHelpers.equalTokens)(this.element, ''); this.assertComponentElement(someElement.firstChild, { content: 'Huzzah!' }); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'text', 'Whoop!'); }); (0, _testHelpers.equalTokens)(this.element, ''); this.assertComponentElement(someElement.firstChild, { content: 'Whoop!' }); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'showModal', false); }); (0, _testHelpers.equalTokens)(this.element, ''); (0, _testHelpers.equalTokens)(someElement, ''); assert.deepEqual(hooks, ['didInsertElement', 'willDestroyElement']); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/syntax/with-dynamic-var-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _testCase, _abstractTestCase) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#-with-dynamic-vars foo="bar"}}\n {{-get-dynamic-var \'foo\'}}\n {{/-with-dynamic-vars}}\n '], ['\n {{#-with-dynamic-vars foo="bar"}}\n {{-get-dynamic-var \'foo\'}}\n {{/-with-dynamic-vars}}\n ']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#-with-dynamic-vars outletState="bar"}}\n {{-get-dynamic-var \'outletState\'}}\n {{/-with-dynamic-vars}}\n '], ['\n {{#-with-dynamic-vars outletState="bar"}}\n {{-get-dynamic-var \'outletState\'}}\n {{/-with-dynamic-vars}}\n ']); (0, _testCase.moduleFor)('{{-with-dynamic-var}}', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test does not allow setting values other than outletState'] = function () { var _this2 = this; expectAssertion(function () { _this2.render((0, _abstractTestCase.strip)(_templateObject)); }, /Using `-with-dynamic-scope` is only supported for `outletState` \(you used `foo`\)./); }; _class.prototype['@test allows setting/getting outletState'] = function () { // this is simply asserting that we can write and read outletState // the actual value being used here is not what is used in real life // feel free to change the value being set and asserted as needed this.render((0, _abstractTestCase.strip)(_templateObject2)); this.assertText('bar'); }; _class.prototype['@test does not allow setting values other than outletState'] = function () { var _this3 = this; expectAssertion(function () { _this3.render('{{-get-dynamic-var \'foo\'}}'); }, /Using `-get-dynamic-scope` is only supported for `outletState` \(you used `foo`\)./); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/integration/syntax/with-test', ['ember-babel', 'ember-metal', 'ember-runtime', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/shared-conditional-tests', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _emberMetal, _emberRuntime, _testCase, _sharedConditionalTests, _abstractTestCase) { 'use strict'; var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with foo.bar.baz as |thing|}}\n {{thing}}\n {{/with}}'], ['\n {{#with foo.bar.baz as |thing|}}\n {{thing}}\n {{/with}}']), _templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{name}}\n {{#with committer1.name as |name|}}\n [{{name}}\n {{#with committer2.name as |name|}}\n [{{name}}]\n {{/with}}\n {{name}}]\n {{/with}}\n {{name}}\n {{#with committer2.name as |name|}}\n [{{name}}\n {{#with committer1.name as |name|}}\n [{{name}}]\n {{/with}}\n {{name}}]\n {{/with}}\n {{name}}\n '], ['\n {{name}}\n {{#with committer1.name as |name|}}\n [{{name}}\n {{#with committer2.name as |name|}}\n [{{name}}]\n {{/with}}\n {{name}}]\n {{/with}}\n {{name}}\n {{#with committer2.name as |name|}}\n [{{name}}\n {{#with committer1.name as |name|}}\n [{{name}}]\n {{/with}}\n {{name}}]\n {{/with}}\n {{name}}\n ']); (0, _testCase.moduleFor)('Syntax test: {{#with}}', function (_IfUnlessWithSyntaxTe) { (0, _emberBabel.inherits)(_class, _IfUnlessWithSyntaxTe); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe.apply(this, arguments)); } _class.prototype.templateFor = function (_ref) { var cond = _ref.cond, truthy = _ref.truthy, falsy = _ref.falsy; return '{{#with ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/with}}'; }; return _class; }(_sharedConditionalTests.IfUnlessWithSyntaxTest)); (0, _testCase.moduleFor)('Syntax test: {{#with as}}', function (_IfUnlessWithSyntaxTe2) { (0, _emberBabel.inherits)(_class2, _IfUnlessWithSyntaxTe2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe2.apply(this, arguments)); } _class2.prototype.templateFor = function (_ref2) { var cond = _ref2.cond, truthy = _ref2.truthy, falsy = _ref2.falsy; return '{{#with ' + cond + ' as |test|}}' + truthy + '{{else}}' + falsy + '{{/with}}'; }; _class2.prototype['@test keying off of `undefined` does not render'] = function () { var _this3 = this; this.render((0, _abstractTestCase.strip)(_templateObject), { foo: {} }); this.assertText(''); this.runTask(function () { return _this3.rerender(); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'foo', { bar: { baz: 'Here!' } }); }); this.assertText('Here!'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'foo', {}); }); this.assertText(''); }; _class2.prototype['@test it renders and hides the given block based on the conditional'] = function () { var _this4 = this; this.render('{{#with cond1 as |cond|}}{{cond.greeting}}{{else}}False{{/with}}', { cond1: { greeting: 'Hello' } }); this.assertText('Hello'); this.runTask(function () { return _this4.rerender(); }); this.assertText('Hello'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'cond1.greeting', 'Hello world'); }); this.assertText('Hello world'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'cond1', false); }); this.assertText('False'); this.runTask(function () { return (0, _emberMetal.set)(_this4.context, 'cond1', { greeting: 'Hello' }); }); this.assertText('Hello'); }; _class2.prototype['@test can access alias and original scope'] = function () { var _this5 = this; this.render('{{#with person as |tom|}}{{title}}: {{tom.name}}{{/with}}', { title: 'Señor Engineer', person: { name: 'Tom Dale' } }); this.assertText('Señor Engineer: Tom Dale'); this.runTask(function () { return _this5.rerender(); }); this.assertText('Señor Engineer: Tom Dale'); this.runTask(function () { (0, _emberMetal.set)(_this5.context, 'person.name', 'Yehuda Katz'); (0, _emberMetal.set)(_this5.context, 'title', 'Principal Engineer'); }); this.assertText('Principal Engineer: Yehuda Katz'); this.runTask(function () { (0, _emberMetal.set)(_this5.context, 'person', { name: 'Tom Dale' }); (0, _emberMetal.set)(_this5.context, 'title', 'Señor Engineer'); }); this.assertText('Señor Engineer: Tom Dale'); }; _class2.prototype['@test the scoped variable is not available outside the {{#with}} block.'] = function () { var _this6 = this; this.render('{{name}}-{{#with other as |name|}}{{name}}{{/with}}-{{name}}', { name: 'Stef', other: 'Yehuda' }); this.assertText('Stef-Yehuda-Stef'); this.runTask(function () { return _this6.rerender(); }); this.assertText('Stef-Yehuda-Stef'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'other', 'Chad'); }); this.assertText('Stef-Chad-Stef'); this.runTask(function () { return (0, _emberMetal.set)(_this6.context, 'name', 'Tom'); }); this.assertText('Tom-Chad-Tom'); this.runTask(function () { (0, _emberMetal.set)(_this6.context, 'name', 'Stef'); (0, _emberMetal.set)(_this6.context, 'other', 'Yehuda'); }); this.assertText('Stef-Yehuda-Stef'); }; _class2.prototype['@test inverse template is displayed with context'] = function () { var _this7 = this; this.render('{{#with falsyThing as |thing|}}Has Thing{{else}}No Thing {{otherThing}}{{/with}}', { falsyThing: null, otherThing: 'bar' }); this.assertText('No Thing bar'); this.runTask(function () { return _this7.rerender(); }); this.assertText('No Thing bar'); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'otherThing', 'biz'); }); this.assertText('No Thing biz'); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'falsyThing', true); }); this.assertText('Has Thing'); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'otherThing', 'baz'); }); this.assertText('Has Thing'); this.runTask(function () { (0, _emberMetal.set)(_this7.context, 'otherThing', 'bar'); (0, _emberMetal.set)(_this7.context, 'falsyThing', null); }); this.assertText('No Thing bar'); }; _class2.prototype['@test can access alias of a proxy'] = function () { var _this8 = this; this.render('{{#with proxy as |person|}}{{person.name}}{{/with}}', { proxy: _emberRuntime.ObjectProxy.create({ content: { name: 'Tom Dale' } }) }); this.assertText('Tom Dale'); this.runTask(function () { return _this8.rerender(); }); this.assertText('Tom Dale'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'proxy.name', 'Yehuda Katz'); }); this.assertText('Yehuda Katz'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'proxy.content', { name: 'Godfrey Chan' }); }); this.assertText('Godfrey Chan'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'proxy.content.name', 'Stefan Penner'); }); this.assertText('Stefan Penner'); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'proxy.content', null); }); this.assertText(''); this.runTask(function () { return (0, _emberMetal.set)(_this8.context, 'proxy', _emberRuntime.ObjectProxy.create({ content: { name: 'Tom Dale' } })); }); this.assertText('Tom Dale'); }; _class2.prototype['@test can access alias of an array'] = function () { var _this9 = this; this.render('{{#with arrayThing as |words|}}{{#each words as |word|}}{{word}}{{/each}}{{/with}}', { arrayThing: (0, _emberRuntime.A)(['Hello', ' ', 'world']) }); this.assertText('Hello world'); this.runTask(function () { return _this9.rerender(); }); this.assertText('Hello world'); this.runTask(function () { var array = (0, _emberMetal.get)(_this9.context, 'arrayThing'); array.replace(0, 1, 'Goodbye'); (0, _emberRuntime.removeAt)(array, 1); array.insertAt(1, ', '); array.pushObject('!'); }); this.assertText('Goodbye, world!'); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'arrayThing', ['Hello', ' ', 'world']); }); this.assertText('Hello world'); }; _class2.prototype['@test `attrs` can be used as a block param [GH#14678]'] = function () { var _this10 = this; this.render('{{#with hash as |attrs|}}[{{hash.foo}}-{{attrs.foo}}]{{/with}}', { hash: { foo: 'foo' } }); this.assertText('[foo-foo]'); this.runTask(function () { return _this10.rerender(); }); this.assertText('[foo-foo]'); this.runTask(function () { return _this10.context.set('hash.foo', 'FOO'); }); this.assertText('[FOO-FOO]'); this.runTask(function () { return _this10.context.set('hash.foo', 'foo'); }); this.assertText('[foo-foo]'); }; return _class2; }(_sharedConditionalTests.IfUnlessWithSyntaxTest)); (0, _testCase.moduleFor)('Syntax test: Multiple {{#with as}} helpers', function (_RenderingTest) { (0, _emberBabel.inherits)(_class3, _RenderingTest); function _class3() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class3.prototype['@test re-using the same variable with different {{#with}} blocks does not override each other'] = function () { var _this12 = this; this.render('Admin: {{#with admin as |person|}}{{person.name}}{{/with}} User: {{#with user as |person|}}{{person.name}}{{/with}}', { admin: { name: 'Tom Dale' }, user: { name: 'Yehuda Katz' } }); this.assertText('Admin: Tom Dale User: Yehuda Katz'); this.runTask(function () { return _this12.rerender(); }); this.assertText('Admin: Tom Dale User: Yehuda Katz'); this.runTask(function () { (0, _emberMetal.set)(_this12.context, 'admin.name', 'Godfrey Chan'); (0, _emberMetal.set)(_this12.context, 'user.name', 'Stefan Penner'); }); this.assertText('Admin: Godfrey Chan User: Stefan Penner'); this.runTask(function () { (0, _emberMetal.set)(_this12.context, 'admin', { name: 'Tom Dale' }); (0, _emberMetal.set)(_this12.context, 'user', { name: 'Yehuda Katz' }); }); this.assertText('Admin: Tom Dale User: Yehuda Katz'); }; _class3.prototype['@test the scoped variable is not available outside the {{#with}} block'] = function () { var _this13 = this; this.render('{{ring}}-{{#with first as |ring|}}{{ring}}-{{#with fifth as |ring|}}{{ring}}-{{#with ninth as |ring|}}{{ring}}-{{/with}}{{ring}}-{{/with}}{{ring}}-{{/with}}{{ring}}', { ring: 'Greed', first: 'Limbo', fifth: 'Wrath', ninth: 'Treachery' }); this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed'); this.runTask(function () { return _this13.rerender(); }); this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed'); this.runTask(function () { (0, _emberMetal.set)(_this13.context, 'ring', 'O'); (0, _emberMetal.set)(_this13.context, 'fifth', 'D'); }); this.assertText('O-Limbo-D-Treachery-D-Limbo-O'); this.runTask(function () { (0, _emberMetal.set)(_this13.context, 'first', 'I'); (0, _emberMetal.set)(_this13.context, 'ninth', 'K'); }); this.assertText('O-I-D-K-D-I-O'); this.runTask(function () { (0, _emberMetal.set)(_this13.context, 'ring', 'Greed'); (0, _emberMetal.set)(_this13.context, 'first', 'Limbo'); (0, _emberMetal.set)(_this13.context, 'fifth', 'Wrath'); (0, _emberMetal.set)(_this13.context, 'ninth', 'Treachery'); }); this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed'); }; _class3.prototype['@test it should support {{#with name as |foo|}}, then {{#with foo as |bar|}}'] = function () { var _this14 = this; this.render('{{#with name as |foo|}}{{#with foo as |bar|}}{{bar}}{{/with}}{{/with}}', { name: 'caterpillar' }); this.assertText('caterpillar'); this.runTask(function () { return _this14.rerender(); }); this.assertText('caterpillar'); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'name', 'butterfly'); }); this.assertText('butterfly'); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'name', 'caterpillar'); }); this.assertText('caterpillar'); }; _class3.prototype['@test updating the context should update the alias'] = function () { var _this15 = this; this.render('{{#with this as |person|}}{{person.name}}{{/with}}', { name: 'Los Pivots' }); this.assertText('Los Pivots'); this.runTask(function () { return _this15.rerender(); }); this.assertText('Los Pivots'); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'name', 'l\'Pivots'); }); this.assertText('l\'Pivots'); this.runTask(function () { return (0, _emberMetal.set)(_this15.context, 'name', 'Los Pivots'); }); this.assertText('Los Pivots'); }; _class3.prototype['@test nested {{#with}} blocks should have access to root context'] = function () { var _this16 = this; this.render((0, _abstractTestCase.strip)(_templateObject2), { name: 'ebryn', committer1: { name: 'trek' }, committer2: { name: 'machty' } }); this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn'); this.runTask(function () { return _this16.rerender(); }); this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn'); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'name', 'chancancode'); }); this.assertText('chancancode[trek[machty]trek]chancancode[machty[trek]machty]chancancode'); this.runTask(function () { return (0, _emberMetal.set)(_this16.context, 'committer1', { name: 'krisselden' }); }); this.assertText('chancancode[krisselden[machty]krisselden]chancancode[machty[krisselden]machty]chancancode'); this.runTask(function () { (0, _emberMetal.set)(_this16.context, 'committer1.name', 'wycats'); (0, _emberMetal.set)(_this16.context, 'committer2', { name: 'rwjblue' }); }); this.assertText('chancancode[wycats[rwjblue]wycats]chancancode[rwjblue[wycats]rwjblue]chancancode'); this.runTask(function () { (0, _emberMetal.set)(_this16.context, 'name', 'ebryn'); (0, _emberMetal.set)(_this16.context, 'committer1', { name: 'trek' }); (0, _emberMetal.set)(_this16.context, 'committer2', { name: 'machty' }); }); this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn'); }; return _class3; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/unit/layout-cache-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', '@glimmer/runtime', 'ember-utils'], function (_emberBabel, _testCase, _runtime, _emberUtils) { 'use strict'; var Counter = function () { function Counter() { this.reset(); } Counter.prototype.increment = function (key) { this.total++; return this.counts[key] = (this.counts[key] || 0) + 1; }; Counter.prototype.get = function (key) { return this.counts[key] || 0; }; Counter.prototype.reset = function () { this.total = 0; this.counts = Object.create(null); }; return Counter; }(); var COUNTER = new Counter(); var BasicCompiler = function () { function BasicCompiler(template) { this.template = template; } BasicCompiler.prototype.compile = function (builder) { var template = this.template; COUNTER.increment(this.constructor.id + '+' + template.id); builder.wrapLayout(template.asLayout()); }; return BasicCompiler; }(); var TypeOneCompiler = function (_BasicCompiler) { (0, _emberBabel.inherits)(TypeOneCompiler, _BasicCompiler); function TypeOneCompiler() { return (0, _emberBabel.possibleConstructorReturn)(this, _BasicCompiler.apply(this, arguments)); } return TypeOneCompiler; }(BasicCompiler); var TypeTwoCompiler = function (_BasicCompiler2) { (0, _emberBabel.inherits)(TypeTwoCompiler, _BasicCompiler2); function TypeTwoCompiler() { return (0, _emberBabel.possibleConstructorReturn)(this, _BasicCompiler2.apply(this, arguments)); } return TypeTwoCompiler; }(BasicCompiler); TypeOneCompiler.id = 'type-one'; TypeTwoCompiler.id = 'type-two'; (0, _testCase.moduleFor)('Layout cache test', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { var _this3 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this)); COUNTER.reset(); return _this3; } _class.prototype.templateFor = function (content) { var Factory = this.compile(content); return this.env.getTemplate(Factory, this.owner); }; _class.prototype['@test each template is only compiled once'] = function (assert) { var env = this.env; var template1 = this.templateFor('Hello world!'); var template2 = this.templateFor('{{foo}} {{bar}}'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.strictEqual(COUNTER.get('type-one+' + template1.id), 1); assert.strictEqual(COUNTER.get('type-one+' + template2.id), 0); assert.strictEqual(COUNTER.total, 1); assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.strictEqual(COUNTER.get('type-one+' + template1.id), 1); assert.strictEqual(COUNTER.get('type-one+' + template2.id), 0); assert.strictEqual(COUNTER.total, 1); assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.strictEqual(COUNTER.get('type-one+' + template1.id), 1); assert.strictEqual(COUNTER.get('type-one+' + template2.id), 1); assert.strictEqual(COUNTER.total, 2); assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.strictEqual(COUNTER.get('type-one+' + template1.id), 1); assert.strictEqual(COUNTER.get('type-one+' + template2.id), 1); assert.strictEqual(COUNTER.total, 2); }; _class.prototype['@test each template/compiler pair is treated as unique'] = function (assert) { var env = this.env; var template = this.templateFor('Hello world!'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.strictEqual(COUNTER.get('type-one+' + template.id), 1); assert.strictEqual(COUNTER.get('type-two+' + template.id), 0); assert.strictEqual(COUNTER.total, 1); assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.strictEqual(COUNTER.get('type-one+' + template.id), 1); assert.strictEqual(COUNTER.get('type-two+' + template.id), 0); assert.strictEqual(COUNTER.total, 1); assert.ok(env.getCompiledBlock(TypeTwoCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.strictEqual(COUNTER.get('type-one+' + template.id), 1); assert.strictEqual(COUNTER.get('type-two+' + template.id), 1); assert.strictEqual(COUNTER.total, 2); assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeTwoCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeTwoCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeTwoCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.strictEqual(COUNTER.get('type-one+' + template.id), 1); assert.strictEqual(COUNTER.get('type-two+' + template.id), 1); assert.strictEqual(COUNTER.total, 2); }; _class.prototype['@test a template instance is returned (ensures templates can be injected into layout property)'] = function (assert) { var _this4 = this; var owner = this.owner, env = this.env; var templateInstanceFor = function (content) { var _Factory$create; var Factory = _this4.compile(content); return Factory.create((_Factory$create = {}, _Factory$create[_emberUtils.OWNER] = owner, _Factory$create.env = env, _Factory$create)); }; var template1 = templateInstanceFor('Hello world!'); var template2 = templateInstanceFor('{{foo}} {{bar}}'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/unit/outlet-test', ['ember-glimmer/views/outlet', 'ember-metal'], function (_outlet, _emberMetal) { 'use strict'; QUnit.module('Glimmer OutletView'); QUnit.test('render in the render queue', function (assert) { var didAppendOutletView = 0; var expectedOutlet = '#foo.bar'; var outletView = new _outlet.default({}, { appendOutletView: function (view, target) { didAppendOutletView++; assert.equal(view, outletView); assert.equal(target, expectedOutlet); } }); (0, _emberMetal.run)(function () { assert.equal(didAppendOutletView, 0, 'appendOutletView should not yet have been called (before appendTo)'); outletView.appendTo(expectedOutlet); assert.equal(didAppendOutletView, 0, 'appendOutletView should not yet have been called (sync after appendTo)'); _emberMetal.run.schedule('actions', function () { return assert.equal(didAppendOutletView, 0, 'appendOutletView should not yet have been called (in actions)'); }); _emberMetal.run.schedule('render', function () { return assert.equal(didAppendOutletView, 1, 'appendOutletView should be invoked in render'); }); }); }); }); enifed('ember-glimmer/tests/unit/template-factory-test', ['ember-babel', 'ember-template-compiler', 'ember-glimmer/index', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers'], function (_emberBabel, _emberTemplateCompiler, _index, _testCase, _helpers) { 'use strict'; (0, _testCase.moduleFor)('Template factory test', function (_RenderingTest) { (0, _emberBabel.inherits)(_class, _RenderingTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } _class.prototype['@test the template factory returned from precompile is the same as compile'] = function (assert) { var env = this.env; var templateStr = 'Hello {{name}}'; var options = { moduleName: 'some-module' }; var spec = (0, _emberTemplateCompiler.precompile)(templateStr, options); var module = new Function('exports', 'template', 'exports.default = template(' + spec + ');'); var exports = {}; module(exports, _index.template); var Precompiled = exports['default']; var Compiled = (0, _emberTemplateCompiler.compile)(templateStr, options); assert.equal(typeof Precompiled.create, 'function', 'precompiled is a factory'); assert.ok(Precompiled.id, 'precompiled has id'); assert.equal(typeof Compiled.create, 'function', 'compiled is a factory'); assert.ok(Compiled.id, 'compiled has id'); assert.equal(env._templateCache.misses, 0, 'misses 0'); assert.equal(env._templateCache.hits, 0, 'hits 0'); var precompiled = env.getTemplate(Precompiled, env.owner); assert.equal(env._templateCache.misses, 1, 'misses 1'); assert.equal(env._templateCache.hits, 0, 'hits 0'); var compiled = env.getTemplate(Compiled, env.owner); assert.equal(env._templateCache.misses, 2, 'misses 2'); assert.equal(env._templateCache.hits, 0, 'hits 0'); assert.ok(typeof precompiled.spec !== 'string', 'Spec has been parsed'); assert.ok(typeof compiled.spec !== 'string', 'Spec has been parsed'); this.registerComponent('x-precompiled', { ComponentClass: _helpers.Component.extend({ layout: Precompiled }) }); this.registerComponent('x-compiled', { ComponentClass: _helpers.Component.extend({ layout: Compiled }) }); this.render('{{x-precompiled name="precompiled"}} {{x-compiled name="compiled"}}'); assert.equal(env._templateCache.misses, 2, 'misses 2'); assert.equal(env._templateCache.hits, 2, 'hits 2'); this.assertText('Hello precompiled Hello compiled'); }; return _class; }(_testCase.RenderingTest)); }); enifed('ember-glimmer/tests/unit/utils/debug-stack-test', ['ember-glimmer/utils/debug-stack'], function () { 'use strict'; }); enifed('ember-glimmer/tests/unit/utils/iterable-test', ['ember-babel', 'ember', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/utils/iterable', 'ember-glimmer/utils/references', 'ember-glimmer/helpers/each-in', '@glimmer/runtime'], function (_emberBabel, _ember, _testCase, _iterable, _references, _eachIn, _runtime) { 'use strict'; var ITERATOR_KEY_GUID = 'be277757-bbbe-4620-9fcb-213ef433cca2'; (0, _testCase.moduleFor)('Iterable', function (_TestCase) { (0, _emberBabel.inherits)(_class, _TestCase); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _TestCase.apply(this, arguments)); } _class.prototype['@test iterates over an array'] = function () { var iterator = iteratorForArray(['foo', 'bar']); this.assert.deepEqual(iterator.next(), { key: 'foo', memo: 0, value: 'foo' }); this.assert.deepEqual(iterator.next(), { key: 'bar', memo: 1, value: 'bar' }); }; _class.prototype['@test iterates over an `Ember.A`'] = function () { var iterator = iteratorForArray(_ember.default.A(['foo', 'bar'])); this.assert.deepEqual(iterator.next(), { key: 'foo', memo: 0, value: 'foo' }); this.assert.deepEqual(iterator.next(), { key: 'bar', memo: 1, value: 'bar' }); }; _class.prototype['@test returns `null` when out of items'] = function () { var iterator = iteratorForArray(['foo']); this.assert.deepEqual(iterator.next(), { key: 'foo', memo: 0, value: 'foo' }); this.assert.deepEqual(iterator.next(), null); }; _class.prototype['@test iterates over an array with indices as keys'] = function () { var iterator = iteratorForArray(['foo', 'bar'], '@index'); this.assert.deepEqual(iterator.next(), { key: '0', memo: 0, value: 'foo' }); this.assert.deepEqual(iterator.next(), { key: '1', memo: 1, value: 'bar' }); }; _class.prototype['@test iterates over an array with identities as keys'] = function () { var iterator = iteratorForArray(['foo', 'bar'], '@identity'); this.assert.deepEqual(iterator.next(), { key: 'foo', memo: 0, value: 'foo' }); this.assert.deepEqual(iterator.next(), { key: 'bar', memo: 1, value: 'bar' }); }; _class.prototype['@test iterates over an array with arbitrary properties as keys'] = function () { var iterator = iteratorForArray([{ k: 'first', v: 'foo' }, { k: 'second', v: 'bar' }], 'k'); this.assert.deepEqual(iterator.next(), { key: 'first', memo: 0, value: { k: 'first', v: 'foo' } }); this.assert.deepEqual(iterator.next(), { key: 'second', memo: 1, value: { k: 'second', v: 'bar' } }); }; _class.prototype['@test errors on `#next` with an undefined ref'] = function () { var iterator = iteratorForArray(undefined), message; this.assert.expect(1); try { iterator.next(); } catch (_ref) { message = _ref.message; this.assert.equal(message, 'Cannot call next() on an empty iterator'); } }; _class.prototype['@test errors on `#next` with a null ref'] = function () { var iterator = iteratorForArray(null), message; this.assert.expect(1); try { iterator.next(); } catch (_ref2) { message = _ref2.message; this.assert.equal(message, 'Cannot call next() on an empty iterator'); } }; _class.prototype['@test errors on `#next` with an invalid ref type'] = function () { var iterator = iteratorForArray('string'), message; this.assert.expect(1); try { iterator.next(); } catch (_ref3) { message = _ref3.message; this.assert.equal(message, 'Cannot call next() on an empty iterator'); } }; _class.prototype['@test errors on `#next` with an empty array'] = function () { var iterator = iteratorForArray([]), message; this.assert.expect(1); try { iterator.next(); } catch (_ref4) { message = _ref4.message; this.assert.equal(message, 'Cannot call next() on an empty iterator'); } }; _class.prototype['@test iterates over an object\'s own properties'] = function () { var iterator = iteratorForObject({ first: 'foo', second: 'bar' }); this.assert.deepEqual(iterator.next(), { key: 'first', memo: 'first', value: 'foo' }); this.assert.deepEqual(iterator.next(), { key: 'second', memo: 'second', value: 'bar' }); }; _class.prototype['@test iterates over an object\'s own properties with indices as keys'] = function () { var iterator = iteratorForObject({ first: 'foo', second: 'bar' }, '@index'); this.assert.deepEqual(iterator.next(), { key: 'first', memo: 'first', value: 'foo' }); this.assert.deepEqual(iterator.next(), { key: 'second', memo: 'second', value: 'bar' }); }; _class.prototype['@test iterates over an object\'s own properties with identities as keys'] = function () { var iterator = iteratorForObject({ first: 'foo', second: 'bar' }, '@identity'); this.assert.deepEqual(iterator.next(), { key: 'foo', memo: 'first', value: 'foo' }); this.assert.deepEqual(iterator.next(), { key: 'bar', memo: 'second', value: 'bar' }); }; _class.prototype['@test iterates over an object\'s own properties with arbitrary properties as keys'] = function () { var iterator = iteratorForObject({ first: { k: 'uno', v: 'foo' }, second: { k: 'dos', v: 'bar' } }, 'k'); this.assert.deepEqual(iterator.next(), { key: 'uno', memo: 'first', value: { k: 'uno', v: 'foo' } }); this.assert.deepEqual(iterator.next(), { key: 'dos', memo: 'second', value: { k: 'dos', v: 'bar' } }); }; _class.prototype['@test each-in errors on `#next` with an undefined ref'] = function () { var iterator = iteratorForObject(undefined), message; this.assert.expect(1); try { iterator.next(); } catch (_ref5) { message = _ref5.message; this.assert.equal(message, 'Cannot call next() on an empty iterator'); } }; _class.prototype['@test each-in errors on `#next` with a null ref'] = function () { var iterator = iteratorForObject(null), message; this.assert.expect(1); try { iterator.next(); } catch (_ref6) { message = _ref6.message; this.assert.equal(message, 'Cannot call next() on an empty iterator'); } }; _class.prototype['@test each-in errors on `#next` with an invalid ref type'] = function () { var iterator = iteratorForObject('string'), message; this.assert.expect(1); try { iterator.next(); } catch (_ref7) { message = _ref7.message; this.assert.equal(message, 'Cannot call next() on an empty iterator'); } }; _class.prototype['@test ensures keys are unique'] = function () { var iterator = iteratorForArray([{ k: 'qux', v: 'foo' }, { k: 'qux', v: 'bar' }, { k: 'qux', v: 'baz' }], 'k'); this.assert.deepEqual(iterator.next(), { key: 'qux', memo: 0, value: { k: 'qux', v: 'foo' } }); this.assert.deepEqual(iterator.next(), { key: 'qux' + ITERATOR_KEY_GUID + '1', memo: 1, value: { k: 'qux', v: 'bar' } }); this.assert.deepEqual(iterator.next(), { key: 'qux' + ITERATOR_KEY_GUID + '2', memo: 2, value: { k: 'qux', v: 'baz' } }); }; return _class; }(_testCase.TestCase)); function iteratorForArray(arr, keyPath) { var ref = new _references.UpdatableReference(arr); var iterable = (0, _iterable.default)(ref, keyPath); return iterable.iterate(); } function iteratorForObject(obj, keyPath) { var positionalArgs = _runtime.EvaluatedPositionalArgs.create([new _references.UpdatableReference(obj)]); var ref = (0, _eachIn.default)(null, { positional: positionalArgs }); var iterable = (0, _iterable.default)(ref, keyPath); return iterable.iterate(); } }); enifed('ember-glimmer/tests/utils/abstract-test-case', ['exports', 'internal-test-helpers'], function (exports, _internalTestHelpers) { 'use strict'; Object.defineProperty(exports, 'TestCase', { enumerable: true, get: function () { return _internalTestHelpers.AbstractTestCase; } }); Object.defineProperty(exports, 'applyMixins', { enumerable: true, get: function () { return _internalTestHelpers.applyMixins; } }); Object.defineProperty(exports, 'strip', { enumerable: true, get: function () { return _internalTestHelpers.strip; } }); }); enifed('ember-glimmer/tests/utils/helpers', ['exports', 'ember-template-compiler', 'ember-glimmer'], function (exports, _emberTemplateCompiler, _emberGlimmer) { 'use strict'; Object.defineProperty(exports, 'compile', { enumerable: true, get: function () { return _emberTemplateCompiler.compile; } }); Object.defineProperty(exports, 'precompile', { enumerable: true, get: function () { return _emberTemplateCompiler.precompile; } }); Object.defineProperty(exports, 'INVOKE', { enumerable: true, get: function () { return _emberGlimmer.INVOKE; } }); Object.defineProperty(exports, 'Helper', { enumerable: true, get: function () { return _emberGlimmer.Helper; } }); Object.defineProperty(exports, 'helper', { enumerable: true, get: function () { return _emberGlimmer.helper; } }); Object.defineProperty(exports, 'Component', { enumerable: true, get: function () { return _emberGlimmer.Component; } }); Object.defineProperty(exports, 'TextArea', { enumerable: true, get: function () { return _emberGlimmer.TextArea; } }); Object.defineProperty(exports, 'LinkComponent', { enumerable: true, get: function () { return _emberGlimmer.LinkComponent; } }); Object.defineProperty(exports, 'TextField', { enumerable: true, get: function () { return _emberGlimmer.TextField; } }); Object.defineProperty(exports, 'InteractiveRender', { enumerable: true, get: function () { return _emberGlimmer.InteractiveRender; } }); Object.defineProperty(exports, 'InertRenderer', { enumerable: true, get: function () { return _emberGlimmer.InertRenderer; } }); Object.defineProperty(exports, 'htmlSafe', { enumerable: true, get: function () { return _emberGlimmer.htmlSafe; } }); Object.defineProperty(exports, 'SafeString', { enumerable: true, get: function () { return _emberGlimmer.SafeString; } }); Object.defineProperty(exports, 'DOMChanges', { enumerable: true, get: function () { return _emberGlimmer.DOMChanges; } }); Object.defineProperty(exports, 'isHTMLSafe', { enumerable: true, get: function () { return _emberGlimmer.isHTMLSafe; } }); }); enifed('ember-glimmer/tests/utils/shared-conditional-tests', ['exports', 'ember-babel', 'ember-utils', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case', 'ember-metal', 'ember-runtime', 'ember-glimmer/tests/utils/helpers'], function (exports, _emberBabel, _emberUtils, _abstractTestCase, _testCase, _emberMetal, _emberRuntime, _helpers) { 'use strict'; exports.IfUnlessWithSyntaxTest = exports.TogglingSyntaxConditionalsTest = exports.IfUnlessHelperTest = exports.TogglingHelperConditionalsTest = exports.TogglingConditionalsTest = exports.ArrayTestCases = exports.ObjectTestCases = exports.BasicConditionalsTest = exports.StableFalsyGenerator = exports.StableTruthyGenerator = exports.FalsyGenerator = exports.TruthyGenerator = undefined; var _ObjectTestCases, _ArrayTestCases; var AbstractConditionalsTest = function (_RenderingTest) { (0, _emberBabel.inherits)(AbstractConditionalsTest, _RenderingTest); function AbstractConditionalsTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments)); } AbstractConditionalsTest.prototype.wrapperFor = function (templates) { return templates.join(''); }; AbstractConditionalsTest.prototype.wrappedTemplateFor = function (options) { return this.wrapperFor([this.templateFor(options)]); }; AbstractConditionalsTest.prototype.templateFor = function (_ref) { var cond = _ref.cond, truthy = _ref.truthy, falsy = _ref.falsy; // e.g. `{{#if ${cond}}}${truthy}{{else}}${falsy}{{/if}}` throw new Error('Not implemented: `templateFor`'); }; AbstractConditionalsTest.prototype.renderValues = function () { throw new Error('Not implemented: `renderValues`'); }; (0, _emberBabel.createClass)(AbstractConditionalsTest, [{ key: 'truthyValue', get: function () { return true; } }, { key: 'falsyValue', get: function () { return false; } }]); return AbstractConditionalsTest; }(_testCase.RenderingTest); var AbstractGenerator = function () { function AbstractGenerator(cases) { this.cases = cases; } /* abstract */ AbstractGenerator.prototype.generate = function () { throw new Error('Not implemented: `generate`'); }; return AbstractGenerator; }(); var TruthyGenerator = exports.TruthyGenerator = function (_AbstractGenerator) { (0, _emberBabel.inherits)(TruthyGenerator, _AbstractGenerator); function TruthyGenerator() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractGenerator.apply(this, arguments)); } TruthyGenerator.prototype.generate = function (value, idx) { var _ref2; return _ref2 = {}, _ref2['@test it should consider ' + JSON.stringify(value) + ' truthy [' + idx + ']'] = function () { var _this3 = this; this.renderValues(value); this.assertText('T1'); this.runTask(function () { return _this3.rerender(); }); this.assertText('T1'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'cond1', _this3.falsyValue); }); this.assertText('F1'); this.runTask(function () { return (0, _emberMetal.set)(_this3.context, 'cond1', value); }); this.assertText('T1'); }, _ref2; }; return TruthyGenerator; }(AbstractGenerator); var FalsyGenerator = exports.FalsyGenerator = function (_AbstractGenerator2) { (0, _emberBabel.inherits)(FalsyGenerator, _AbstractGenerator2); function FalsyGenerator() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractGenerator2.apply(this, arguments)); } FalsyGenerator.prototype.generate = function (value, idx) { var _ref3; return _ref3 = {}, _ref3['@test it should consider ' + JSON.stringify(value) + ' falsy [' + idx + ']'] = function () { var _this5 = this; this.renderValues(value); this.assertText('F1'); this.runTask(function () { return _this5.rerender(); }); this.assertText('F1'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'cond1', _this5.truthyValue); }); this.assertText('T1'); this.runTask(function () { return (0, _emberMetal.set)(_this5.context, 'cond1', value); }); this.assertText('F1'); }, _ref3; }; return FalsyGenerator; }(AbstractGenerator); var StableTruthyGenerator = exports.StableTruthyGenerator = function (_TruthyGenerator) { (0, _emberBabel.inherits)(StableTruthyGenerator, _TruthyGenerator); function StableTruthyGenerator() { return (0, _emberBabel.possibleConstructorReturn)(this, _TruthyGenerator.apply(this, arguments)); } StableTruthyGenerator.prototype.generate = function (value, idx) { var _assign; return (0, _emberUtils.assign)(_TruthyGenerator.prototype.generate.call(this, value, idx), (_assign = {}, _assign['@test it maintains DOM stability when condition changes from ' + value + ' to another truthy value and back [' + idx + ']'] = function () { var _this7 = this; this.renderValues(value); this.assertText('T1'); this.takeSnapshot(); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'cond1', _this7.truthyValue); }); this.assertText('T1'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this7.context, 'cond1', value); }); this.assertText('T1'); this.assertInvariants(); }, _assign)); }; return StableTruthyGenerator; }(TruthyGenerator); var StableFalsyGenerator = exports.StableFalsyGenerator = function (_FalsyGenerator) { (0, _emberBabel.inherits)(StableFalsyGenerator, _FalsyGenerator); function StableFalsyGenerator() { return (0, _emberBabel.possibleConstructorReturn)(this, _FalsyGenerator.apply(this, arguments)); } StableFalsyGenerator.prototype.generate = function (value, idx) { var _assign2; return (0, _emberUtils.assign)(_FalsyGenerator.prototype.generate.call(this, value), (_assign2 = {}, _assign2['@test it maintains DOM stability when condition changes from ' + value + ' to another falsy value and back [' + idx + ']'] = function () { var _this9 = this; this.renderValues(value); this.assertText('F1'); this.takeSnapshot(); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'cond1', _this9.falsyValue); }); this.assertText('F1'); this.assertInvariants(); this.runTask(function () { return (0, _emberMetal.set)(_this9.context, 'cond1', value); }); this.assertText('F1'); this.assertInvariants(); }, _assign2)); }; return StableFalsyGenerator; }(FalsyGenerator); var ObjectProxyGenerator = function (_AbstractGenerator3) { (0, _emberBabel.inherits)(ObjectProxyGenerator, _AbstractGenerator3); function ObjectProxyGenerator() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractGenerator3.apply(this, arguments)); } ObjectProxyGenerator.prototype.generate = function (value, idx) { var _ref4, _ref5; // This is inconsistent with our usual to-bool policy, but the current proxy implementation // simply uses !!content to determine truthiness if (value) { return _ref4 = {}, _ref4['@test it should consider an object proxy with `' + JSON.stringify(value) + '` truthy [' + idx + ']'] = function () { var _this11 = this; this.renderValues(_emberRuntime.ObjectProxy.create({ content: value })); this.assertText('T1'); this.runTask(function () { return _this11.rerender(); }); this.assertText('T1'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'cond1.content', _this11.falsyValue); }); this.assertText('F1'); this.runTask(function () { return (0, _emberMetal.set)(_this11.context, 'cond1', _emberRuntime.ObjectProxy.create({ content: value })); }); this.assertText('T1'); }, _ref4; } else { return _ref5 = {}, _ref5['@test it should consider an object proxy with `' + JSON.stringify(value) + '` falsy [' + idx + ']'] = function () { var _this12 = this; this.renderValues(_emberRuntime.ObjectProxy.create({ content: value })); this.assertText('F1'); this.runTask(function () { return _this12.rerender(); }); this.assertText('F1'); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'cond1.content', _this12.truthyValue); }); this.assertText('T1'); this.runTask(function () { return (0, _emberMetal.set)(_this12.context, 'cond1', _emberRuntime.ObjectProxy.create({ content: value })); }); this.assertText('F1'); }, _ref5; } }; return ObjectProxyGenerator; }(AbstractGenerator); var BasicConditionalsTest = exports.BasicConditionalsTest = function (_AbstractConditionals) { (0, _emberBabel.inherits)(BasicConditionalsTest, _AbstractConditionals); function BasicConditionalsTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractConditionals.apply(this, arguments)); } BasicConditionalsTest.prototype['@test it renders the corresponding block based on the conditional'] = function () { var _this14 = this; this.renderValues(this.truthyValue, this.falsyValue); this.assertText('T1F2'); this.runTask(function () { return _this14.rerender(); }); this.assertText('T1F2'); this.runTask(function () { return (0, _emberMetal.set)(_this14.context, 'cond1', _this14.falsyValue); }); this.assertText('F1F2'); this.runTask(function () { (0, _emberMetal.set)(_this14.context, 'cond1', _this14.truthyValue); (0, _emberMetal.set)(_this14.context, 'cond2', _this14.truthyValue); }); this.assertText('T1T2'); this.runTask(function () { (0, _emberMetal.set)(_this14.context, 'cond1', _this14.truthyValue); (0, _emberMetal.set)(_this14.context, 'cond2', _this14.falsyValue); }); this.assertText('T1F2'); }; return BasicConditionalsTest; }(AbstractConditionalsTest); // Testing behaviors related to ember objects, object proxies, etc var ObjectTestCases = exports.ObjectTestCases = (_ObjectTestCases = {}, _ObjectTestCases['@test it considers object proxies without content falsy'] = function () { var _this15 = this; this.renderValues(_emberRuntime.ObjectProxy.create({ content: {} }), _emberRuntime.ObjectProxy.create({ content: _emberRuntime.Object.create() }), _emberRuntime.ObjectProxy.create({ content: null })); this.assertText('T1T2F3'); this.runTask(function () { return _this15.rerender(); }); this.assertText('T1T2F3'); this.runTask(function () { (0, _emberMetal.set)(_this15.context, 'cond1.content', null); (0, _emberMetal.set)(_this15.context, 'cond2.content', null); }); this.assertText('F1F2F3'); this.runTask(function () { (0, _emberMetal.set)(_this15.context, 'cond1.content', _emberRuntime.Object.create()); (0, _emberMetal.set)(_this15.context, 'cond2.content', {}); (0, _emberMetal.set)(_this15.context, 'cond3.content', { foo: 'bar' }); }); this.assertText('T1T2T3'); this.runTask(function () { (0, _emberMetal.set)(_this15.context, 'cond1', _emberRuntime.ObjectProxy.create({ content: {} })); (0, _emberMetal.set)(_this15.context, 'cond2', _emberRuntime.ObjectProxy.create({ content: _emberRuntime.Object.create() })); (0, _emberMetal.set)(_this15.context, 'cond3', _emberRuntime.ObjectProxy.create({ content: null })); }); this.assertText('T1T2F3'); }, _ObjectTestCases); // Testing behaviors related to arrays and array proxies var ArrayTestCases = exports.ArrayTestCases = (_ArrayTestCases = {}, _ArrayTestCases['@test it considers empty arrays falsy'] = function () { var _this16 = this; this.renderValues((0, _emberRuntime.A)(['hello']), (0, _emberRuntime.A)()); this.assertText('T1F2'); this.runTask(function () { return _this16.rerender(); }); this.assertText('T1F2'); this.runTask(function () { return (0, _emberRuntime.removeAt)((0, _emberMetal.get)(_this16.context, 'cond1'), 0); }); this.assertText('F1F2'); this.runTask(function () { (0, _emberMetal.get)(_this16.context, 'cond1').pushObject('hello'); (0, _emberMetal.get)(_this16.context, 'cond2').pushObjects([1]); }); this.assertText('T1T2'); this.runTask(function () { (0, _emberMetal.set)(_this16.context, 'cond1', (0, _emberRuntime.A)(['hello'])); (0, _emberMetal.set)(_this16.context, 'cond2', (0, _emberRuntime.A)()); }); this.assertText('T1F2'); }, _ArrayTestCases['@test it considers array proxies without content falsy'] = function () { var _this17 = this; this.renderValues(_emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(['hello']) }), _emberRuntime.ArrayProxy.create({ content: null })); this.assertText('T1F2'); this.runTask(function () { return _this17.rerender(); }); this.assertText('T1F2'); this.runTask(function () { (0, _emberMetal.set)(_this17.context, 'cond1.content', null); (0, _emberMetal.set)(_this17.context, 'cond2.content', null); }); this.assertText('F1F2'); this.runTask(function () { (0, _emberMetal.set)(_this17.context, 'cond1.content', (0, _emberRuntime.A)(['hello'])); (0, _emberMetal.set)(_this17.context, 'cond2.content', (0, _emberRuntime.A)([1])); }); this.assertText('T1T2'); this.runTask(function () { (0, _emberMetal.set)(_this17.context, 'cond1', _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(['hello']) })); (0, _emberMetal.set)(_this17.context, 'cond2', _emberRuntime.ArrayProxy.create({ content: null })); }); this.assertText('T1F2'); }, _ArrayTestCases['@test it considers array proxies with empty arrays falsy'] = function () { var _this18 = this; this.renderValues(_emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(['hello']) }), _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)() })); this.assertText('T1F2'); this.runTask(function () { return _this18.rerender(); }); this.assertText('T1F2'); this.runTask(function () { return (0, _emberRuntime.removeAt)((0, _emberMetal.get)(_this18.context, 'cond1.content'), 0); }); this.assertText('F1F2'); this.runTask(function () { (0, _emberMetal.get)(_this18.context, 'cond1.content').pushObject('hello'); (0, _emberMetal.get)(_this18.context, 'cond2.content').pushObjects([1]); }); this.assertText('T1T2'); this.runTask(function () { (0, _emberMetal.set)(_this18.context, 'cond1', _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(['hello']) })); (0, _emberMetal.set)(_this18.context, 'cond2', _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)() })); }); this.assertText('T1F2'); }, _ArrayTestCases); var IfUnlessWithTestCases = [new StableTruthyGenerator([true, ' ', 'hello', 'false', 'null', 'undefined', 1, ['hello'], (0, _emberRuntime.A)(['hello']), {}, { foo: 'bar' }, _emberRuntime.Object.create(), _emberRuntime.Object.create({ foo: 'bar' }), _emberRuntime.ObjectProxy.create({ content: true }), Object, function () {}, /*jshint -W053 */ new String('hello'), new String(''), new Boolean(true), new Boolean(false), /*jshint +W053 */ new Date()]), new StableFalsyGenerator([false, null, undefined, '', 0, [], (0, _emberRuntime.A)(), _emberRuntime.ObjectProxy.create({ content: undefined })]), new ObjectProxyGenerator([true, ' ', 'hello', 'false', 'null', 'undefined', 1, ['hello'], (0, _emberRuntime.A)(['hello']), _emberRuntime.ArrayProxy.create({ content: ['hello'] }), _emberRuntime.ArrayProxy.create({ content: [] }), {}, { foo: 'bar' }, _emberRuntime.Object.create(), _emberRuntime.Object.create({ foo: 'bar' }), _emberRuntime.ObjectProxy.create({ content: true }), _emberRuntime.ObjectProxy.create({ content: undefined }), /*jshint -W053 */ new String('hello'), new String(''), new Boolean(true), new Boolean(false), /*jshint +W053 */ new Date(), false, null, undefined, '', 0, [], (0, _emberRuntime.A)()]), ObjectTestCases, ArrayTestCases]; // Testing behaviors shared across the "toggling" conditionals, i.e. {{#if}}, // {{#unless}}, {{#with}}, {{#each}}, {{#each-in}}, (if) and (unless) var TogglingConditionalsTest = exports.TogglingConditionalsTest = function (_BasicConditionalsTes) { (0, _emberBabel.inherits)(TogglingConditionalsTest, _BasicConditionalsTes); function TogglingConditionalsTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _BasicConditionalsTes.apply(this, arguments)); } return TogglingConditionalsTest; }(BasicConditionalsTest); var TogglingHelperConditionalsTest = exports.TogglingHelperConditionalsTest = function (_TogglingConditionals) { (0, _emberBabel.inherits)(TogglingHelperConditionalsTest, _TogglingConditionals); function TogglingHelperConditionalsTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingConditionals.apply(this, arguments)); } TogglingHelperConditionalsTest.prototype.renderValues = function () { var templates = [], i; var context = {}; for (i = 1; i <= arguments.length; i++) { templates.push(this.templateFor({ cond: 'cond' + i, truthy: 't' + i, falsy: 'f' + i })); context['t' + i] = 'T' + i; context['f' + i] = 'F' + i; context['cond' + i] = arguments.length <= i - 1 ? undefined : arguments[i - 1]; } var wrappedTemplate = this.wrapperFor(templates); this.render(wrappedTemplate, context); }; TogglingHelperConditionalsTest.prototype['@test it has access to the outer scope from both templates'] = function () { var _this21 = this; var template = this.wrapperFor([this.templateFor({ cond: 'cond1', truthy: 'truthy', falsy: 'falsy' }), this.templateFor({ cond: 'cond2', truthy: 'truthy', falsy: 'falsy' })]); this.render(template, { cond1: this.truthyValue, cond2: this.falsyValue, truthy: 'YES', falsy: 'NO' }); this.assertText('YESNO'); this.runTask(function () { return _this21.rerender(); }); this.assertText('YESNO'); this.runTask(function () { (0, _emberMetal.set)(_this21.context, 'truthy', 'YASS'); (0, _emberMetal.set)(_this21.context, 'falsy', 'NOPE'); }); this.assertText('YASSNOPE'); this.runTask(function () { (0, _emberMetal.set)(_this21.context, 'cond1', _this21.falsyValue); (0, _emberMetal.set)(_this21.context, 'cond2', _this21.truthyValue); }); this.assertText('NOPEYASS'); this.runTask(function () { (0, _emberMetal.set)(_this21.context, 'truthy', 'YES'); (0, _emberMetal.set)(_this21.context, 'falsy', 'NO'); (0, _emberMetal.set)(_this21.context, 'cond1', _this21.truthyValue); (0, _emberMetal.set)(_this21.context, 'cond2', _this21.falsyValue); }); this.assertText('YESNO'); }; TogglingHelperConditionalsTest.prototype['@test it does not update when the unbound helper is used'] = function () { var _this22 = this; var template = this.wrapperFor([this.templateFor({ cond: '(unbound cond1)', truthy: '"T1"', falsy: '"F1"' }), this.templateFor({ cond: '(unbound cond2)', truthy: '"T2"', falsy: '"F2"' })]); this.render(template, { cond1: this.truthyValue, cond2: this.falsyValue }); this.assertText('T1F2'); this.runTask(function () { return _this22.rerender(); }); this.assertText('T1F2'); this.runTask(function () { return (0, _emberMetal.set)(_this22.context, 'cond1', _this22.falsyValue); }); this.assertText('T1F2'); this.runTask(function () { (0, _emberMetal.set)(_this22.context, 'cond1', _this22.truthyValue); (0, _emberMetal.set)(_this22.context, 'cond2', _this22.truthyValue); }); this.assertText('T1F2'); this.runTask(function () { (0, _emberMetal.set)(_this22.context, 'cond1', _this22.truthyValue); (0, _emberMetal.set)(_this22.context, 'cond2', _this22.falsyValue); }); this.assertText('T1F2'); }; TogglingHelperConditionalsTest.prototype['@test evaluation should be lazy'] = function (assert) { var _this23 = this; var truthyEvaluated = void 0; var falsyEvaluated = void 0; var withoutEvaluatingTruthy = function (callback) { truthyEvaluated = false; callback(); assert.ok(!truthyEvaluated, 'x-truthy is not evaluated'); }; var withoutEvaluatingFalsy = function (callback) { falsyEvaluated = false; callback(); assert.ok(!falsyEvaluated, 'x-falsy is not evaluated'); }; this.registerHelper('x-truthy', { compute: function () { truthyEvaluated = true; return 'T'; } }); this.registerHelper('x-falsy', { compute: function () { falsyEvaluated = true; return 'F'; } }); var template = this.wrappedTemplateFor({ cond: 'cond', truthy: '(x-truthy)', falsy: '(x-falsy)' }); withoutEvaluatingFalsy(function () { return _this23.render(template, { cond: _this23.truthyValue }); }); this.assertText('T'); withoutEvaluatingFalsy(function () { return _this23.runTask(function () { return _this23.rerender(); }); }); this.assertText('T'); withoutEvaluatingTruthy(function () { return _this23.runTask(function () { return (0, _emberMetal.set)(_this23.context, 'cond', _this23.falsyValue); }); }); this.assertText('F'); withoutEvaluatingTruthy(function () { return _this23.runTask(function () { return _this23.rerender(); }); }); this.assertText('F'); withoutEvaluatingFalsy(function () { return _this23.runTask(function () { return (0, _emberMetal.set)(_this23.context, 'cond', _this23.truthyValue); }); }); this.assertText('T'); }; return TogglingHelperConditionalsTest; }(TogglingConditionalsTest); var IfUnlessHelperTest = exports.IfUnlessHelperTest = function (_TogglingHelperCondit) { (0, _emberBabel.inherits)(IfUnlessHelperTest, _TogglingHelperCondit); function IfUnlessHelperTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingHelperCondit.apply(this, arguments)); } return IfUnlessHelperTest; }(TogglingHelperConditionalsTest); _abstractTestCase.applyMixins.apply(undefined, [IfUnlessHelperTest].concat(IfUnlessWithTestCases)); // Testing behaviors shared across the "toggling" syntatical constructs, // i.e. {{#if}}, {{#unless}}, {{#with}}, {{#each}} and {{#each-in}} var TogglingSyntaxConditionalsTest = exports.TogglingSyntaxConditionalsTest = function (_TogglingConditionals2) { (0, _emberBabel.inherits)(TogglingSyntaxConditionalsTest, _TogglingConditionals2); function TogglingSyntaxConditionalsTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingConditionals2.apply(this, arguments)); } TogglingSyntaxConditionalsTest.prototype.renderValues = function () { var templates = [], i; var context = {}; for (i = 1; i <= arguments.length; i++) { templates.push(this.templateFor({ cond: 'cond' + i, truthy: '{{t}}' + i, falsy: '{{f}}' + i })); context['cond' + i] = arguments.length <= i - 1 ? undefined : arguments[i - 1]; } var wrappedTemplate = this.wrapperFor(templates); this.render(wrappedTemplate, (0, _emberUtils.assign)({ t: 'T', f: 'F' }, context)); }; TogglingSyntaxConditionalsTest.prototype['@test it does not update when the unbound helper is used'] = function () { var _this26 = this; var template = '' + this.templateFor({ cond: '(unbound cond1)', truthy: 'T1', falsy: 'F1' }) + this.templateFor({ cond: '(unbound cond2)', truthy: 'T2', falsy: 'F2' }); this.render(template, { cond1: this.truthyValue, cond2: this.falsyValue }); this.assertText('T1F2'); this.runTask(function () { return _this26.rerender(); }); this.assertText('T1F2'); this.runTask(function () { return (0, _emberMetal.set)(_this26.context, 'cond1', _this26.falsyValue); }); this.assertText('T1F2'); this.runTask(function () { (0, _emberMetal.set)(_this26.context, 'cond1', _this26.truthyValue); (0, _emberMetal.set)(_this26.context, 'cond2', _this26.truthyValue); }); this.assertText('T1F2'); this.runTask(function () { (0, _emberMetal.set)(_this26.context, 'cond1', _this26.truthyValue); (0, _emberMetal.set)(_this26.context, 'cond2', _this26.falsyValue); }); this.assertText('T1F2'); }; TogglingSyntaxConditionalsTest.prototype['@test it has access to the outer scope from both templates'] = function () { var _this27 = this; var template = this.wrapperFor([this.templateFor({ cond: 'cond1', truthy: '{{truthy}}', falsy: '{{falsy}}' }), this.templateFor({ cond: 'cond2', truthy: '{{truthy}}', falsy: '{{falsy}}' })]); this.render(template, { cond1: this.truthyValue, cond2: this.falsyValue, truthy: 'YES', falsy: 'NO' }); this.assertText('YESNO'); this.runTask(function () { return _this27.rerender(); }); this.assertText('YESNO'); this.runTask(function () { (0, _emberMetal.set)(_this27.context, 'truthy', 'YASS'); (0, _emberMetal.set)(_this27.context, 'falsy', 'NOPE'); }); this.assertText('YASSNOPE'); this.runTask(function () { (0, _emberMetal.set)(_this27.context, 'cond1', _this27.falsyValue); (0, _emberMetal.set)(_this27.context, 'cond2', _this27.truthyValue); }); this.assertText('NOPEYASS'); this.runTask(function () { (0, _emberMetal.set)(_this27.context, 'truthy', 'YES'); (0, _emberMetal.set)(_this27.context, 'falsy', 'NO'); (0, _emberMetal.set)(_this27.context, 'cond1', _this27.truthyValue); (0, _emberMetal.set)(_this27.context, 'cond2', _this27.falsyValue); }); this.assertText('YESNO'); }; TogglingSyntaxConditionalsTest.prototype['@test it updates correctly when enclosing another conditional'] = function () { var _this28 = this; // This tests whether the outer conditional tracks its bounds correctly as its inner bounds changes var inner = this.templateFor({ cond: 'inner', truthy: 'T-inner', falsy: 'F-inner' }); var template = this.wrappedTemplateFor({ cond: 'outer', truthy: inner, falsy: 'F-outer' }); this.render(template, { outer: this.truthyValue, inner: this.truthyValue }); this.assertText('T-inner'); this.runTask(function () { return _this28.rerender(); }); this.assertText('T-inner'); // Changes the inner bounds this.runTask(function () { return (0, _emberMetal.set)(_this28.context, 'inner', _this28.falsyValue); }); this.assertText('F-inner'); // Now rerender the outer conditional, which require first clearing its bounds this.runTask(function () { return (0, _emberMetal.set)(_this28.context, 'outer', _this28.falsyValue); }); this.assertText('F-outer'); }; TogglingSyntaxConditionalsTest.prototype['@test it updates correctly when enclosing #each'] = function () { var _this29 = this; // This tests whether the outer conditional tracks its bounds correctly as its inner bounds changes var template = this.wrappedTemplateFor({ cond: 'outer', truthy: '{{#each inner as |text|}}{{text}}{{/each}}', falsy: 'F-outer' }); this.render(template, { outer: this.truthyValue, inner: ['inner', '-', 'before'] }); this.assertText('inner-before'); this.runTask(function () { return _this29.rerender(); }); this.assertText('inner-before'); // Changes the inner bounds this.runTask(function () { return (0, _emberMetal.set)(_this29.context, 'inner', ['inner-after']); }); this.assertText('inner-after'); // Now rerender the outer conditional, which require first clearing its bounds this.runTask(function () { return (0, _emberMetal.set)(_this29.context, 'outer', _this29.falsyValue); }); this.assertText('F-outer'); // Reset this.runTask(function () { (0, _emberMetal.set)(_this29.context, 'inner', ['inner-again']); (0, _emberMetal.set)(_this29.context, 'outer', _this29.truthyValue); }); this.assertText('inner-again'); // Now clear the inner bounds this.runTask(function () { return (0, _emberMetal.set)(_this29.context, 'inner', []); }); this.assertText(''); // Now rerender the outer conditional, which require first clearing its bounds this.runTask(function () { return (0, _emberMetal.set)(_this29.context, 'outer', _this29.falsyValue); }); this.assertText('F-outer'); }; TogglingSyntaxConditionalsTest.prototype['@test it updates correctly when enclosing triple-curlies'] = function () { var _this30 = this; // This tests whether the outer conditional tracks its bounds correctly as its inner bounds changes var template = this.wrappedTemplateFor({ cond: 'outer', truthy: '{{{inner}}}', falsy: 'F-outer' }); this.render(template, { outer: this.truthyValue, inner: 'inner-before' }); this.assertText('inner-before'); this.runTask(function () { return _this30.rerender(); }); this.assertText('inner-before'); // Changes the inner bounds this.runTask(function () { return (0, _emberMetal.set)(_this30.context, 'inner', '

    inner-after

    '); }); this.assertText('inner-after'); // Now rerender the outer conditional, which require first clearing its bounds this.runTask(function () { return (0, _emberMetal.set)(_this30.context, 'outer', _this30.falsyValue); }); this.assertText('F-outer'); }; TogglingSyntaxConditionalsTest.prototype['@test child conditional should not render children if parent conditional becomes false'] = function (assert) { var _this31 = this; var childCreated = false; this.registerComponent('foo-bar', { template: 'foo-bar', ComponentClass: _helpers.Component.extend({ init: function () { this._super.apply(this, arguments); childCreated = true; } }) }); var innerTemplate = this.templateFor({ cond: 'cond2', truthy: '{{foo-bar}}', falsy: '' }); var wrappedTemplate = this.wrappedTemplateFor({ cond: 'cond1', truthy: innerTemplate, falsy: '' }); this.render(wrappedTemplate, { cond1: this.truthyValue, cond2: this.falsyValue }); assert.ok(!childCreated); this.assertText(''); this.runTask(function () { return _this31.rerender(); }); assert.ok(!childCreated); this.assertText(''); this.runTask(function () { (0, _emberMetal.set)(_this31.context, 'cond2', _this31.truthyValue); (0, _emberMetal.set)(_this31.context, 'cond1', _this31.falsyValue); }); assert.ok(!childCreated); this.assertText(''); this.runTask(function () { (0, _emberMetal.set)(_this31.context, 'cond2', _this31.falsyValue); (0, _emberMetal.set)(_this31.context, 'cond1', _this31.truthyValue); }); assert.ok(!childCreated); this.assertText(''); }; TogglingSyntaxConditionalsTest.prototype['@test evaluation should be lazy'] = function (assert) { var _this32 = this; var truthyEvaluated = void 0; var falsyEvaluated = void 0; var withoutEvaluatingTruthy = function (callback) { truthyEvaluated = false; callback(); assert.ok(!truthyEvaluated, 'x-truthy is not evaluated'); }; var withoutEvaluatingFalsy = function (callback) { falsyEvaluated = false; callback(); assert.ok(!falsyEvaluated, 'x-falsy is not evaluated'); }; this.registerHelper('x-truthy', { compute: function () { truthyEvaluated = true; return 'T'; } }); this.registerHelper('x-falsy', { compute: function () { falsyEvaluated = true; return 'F'; } }); var template = this.wrappedTemplateFor({ cond: 'cond', truthy: '{{x-truthy}}', falsy: '{{x-falsy}}' }); withoutEvaluatingFalsy(function () { return _this32.render(template, { cond: _this32.truthyValue }); }); this.assertText('T'); withoutEvaluatingFalsy(function () { return _this32.runTask(function () { return _this32.rerender(); }); }); this.assertText('T'); withoutEvaluatingTruthy(function () { return _this32.runTask(function () { return (0, _emberMetal.set)(_this32.context, 'cond', _this32.falsyValue); }); }); this.assertText('F'); withoutEvaluatingTruthy(function () { return _this32.runTask(function () { return _this32.rerender(); }); }); this.assertText('F'); withoutEvaluatingFalsy(function () { return _this32.runTask(function () { return (0, _emberMetal.set)(_this32.context, 'cond', _this32.truthyValue); }); }); this.assertText('T'); }; return TogglingSyntaxConditionalsTest; }(TogglingConditionalsTest); var IfUnlessWithSyntaxTest = exports.IfUnlessWithSyntaxTest = function (_TogglingSyntaxCondit) { (0, _emberBabel.inherits)(IfUnlessWithSyntaxTest, _TogglingSyntaxCondit); function IfUnlessWithSyntaxTest() { return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingSyntaxCondit.apply(this, arguments)); } return IfUnlessWithSyntaxTest; }(TogglingSyntaxConditionalsTest); _abstractTestCase.applyMixins.apply(undefined, [IfUnlessWithSyntaxTest].concat(IfUnlessWithTestCases)); }); enifed('ember-glimmer/tests/utils/string-test', ['ember-babel', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case'], function (_emberBabel, _helpers, _abstractTestCase, _testCase) { 'use strict'; (0, _testCase.moduleFor)('SafeString', function (_TestCase) { (0, _emberBabel.inherits)(_class, _TestCase); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _TestCase.apply(this, arguments)); } _class.prototype['@test htmlSafe should return an instance of SafeString'] = function () { var safeString = (0, _helpers.htmlSafe)('you need to be more bold'); this.assert.ok(safeString instanceof _helpers.SafeString, 'should be a SafeString'); }; _class.prototype['@test htmlSafe should return an empty string for null'] = function () { var safeString = (0, _helpers.htmlSafe)(null); this.assert.equal(safeString instanceof _helpers.SafeString, true, 'should be a SafeString'); this.assert.equal(safeString.toString(), '', 'should return an empty string'); }; _class.prototype['@test htmlSafe should return an instance of SafeString'] = function () { var safeString = (0, _helpers.htmlSafe)(); this.assert.equal(safeString instanceof _helpers.SafeString, true, 'should be a SafeString'); this.assert.equal(safeString.toString(), '', 'should return an empty string'); }; return _class; }(_abstractTestCase.TestCase)); (0, _testCase.moduleFor)('SafeString isHTMLSafe', function (_TestCase2) { (0, _emberBabel.inherits)(_class2, _TestCase2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _TestCase2.apply(this, arguments)); } _class2.prototype['@test isHTMLSafe should detect SafeString'] = function () { var safeString = (0, _helpers.htmlSafe)('Emphasize the important things.'); this.assert.ok((0, _helpers.isHTMLSafe)(safeString)); }; _class2.prototype['@test isHTMLSafe should not detect SafeString on primatives'] = function () { this.assert.notOk((0, _helpers.isHTMLSafe)('Hello World')); this.assert.notOk((0, _helpers.isHTMLSafe)({})); this.assert.notOk((0, _helpers.isHTMLSafe)([])); this.assert.notOk((0, _helpers.isHTMLSafe)(10)); this.assert.notOk((0, _helpers.isHTMLSafe)(null)); }; return _class2; }(_abstractTestCase.TestCase)); }); enifed('ember-glimmer/tests/utils/test-case', ['exports', 'internal-test-helpers'], function (exports, _internalTestHelpers) { 'use strict'; Object.defineProperty(exports, 'TestCase', { enumerable: true, get: function () { return _internalTestHelpers.AbstractTestCase; } }); Object.defineProperty(exports, 'ApplicationTest', { enumerable: true, get: function () { return _internalTestHelpers.ApplicationTestCase; } }); Object.defineProperty(exports, 'RenderingTest', { enumerable: true, get: function () { return _internalTestHelpers.RenderingTestCase; } }); Object.defineProperty(exports, 'moduleFor', { enumerable: true, get: function () { return _internalTestHelpers.moduleFor; } }); }); enifed('ember-glimmer/tests/utils/test-helpers', ['exports', 'internal-test-helpers'], function (exports, _internalTestHelpers) { 'use strict'; Object.defineProperty(exports, 'styles', { enumerable: true, get: function () { return _internalTestHelpers.styles; } }); Object.defineProperty(exports, 'classes', { enumerable: true, get: function () { return _internalTestHelpers.classes; } }); Object.defineProperty(exports, 'equalTokens', { enumerable: true, get: function () { return _internalTestHelpers.equalTokens; } }); Object.defineProperty(exports, 'equalsElement', { enumerable: true, get: function () { return _internalTestHelpers.equalsElement; } }); }); enifed('ember-metal/tests/accessors/get_path_test', ['ember-metal'], function (_emberMetal) { 'use strict'; var obj = void 0; QUnit.module('Ember.get with path', { setup: function () { obj = { foo: { bar: { baz: { biff: 'BIFF' } } }, foothis: { bar: { baz: { biff: 'BIFF' } } }, falseValue: false, emptyString: '', Wuz: { nar: 'foo' }, nullValue: null }; }, teardown: function () { obj = undefined; } }); // .......................................................... // LOCAL PATHS // QUnit.test('[obj, foo] -> obj.foo', function () { deepEqual((0, _emberMetal.get)(obj, 'foo'), obj.foo); }); QUnit.test('[obj, foo.bar] -> obj.foo.bar', function () { deepEqual((0, _emberMetal.get)(obj, 'foo.bar'), obj.foo.bar); }); QUnit.test('[obj, foothis.bar] -> obj.foothis.bar', function () { deepEqual((0, _emberMetal.get)(obj, 'foothis.bar'), obj.foothis.bar); }); QUnit.test('[obj, falseValue.notDefined] -> (undefined)', function () { strictEqual((0, _emberMetal.get)(obj, 'falseValue.notDefined'), undefined); }); QUnit.test('[obj, emptyString.length] -> 0', function () { strictEqual((0, _emberMetal.get)(obj, 'emptyString.length'), 0); }); QUnit.test('[obj, nullValue.notDefined] -> (undefined)', function () { strictEqual((0, _emberMetal.get)(obj, 'nullValue.notDefined'), undefined); }); // .......................................................... // GLOBAL PATHS TREATED LOCAL WITH GET // QUnit.test('[obj, Wuz] -> obj.Wuz', function () { deepEqual((0, _emberMetal.get)(obj, 'Wuz'), obj.Wuz); }); QUnit.test('[obj, Wuz.nar] -> obj.Wuz.nar', function () { deepEqual((0, _emberMetal.get)(obj, 'Wuz.nar'), obj.Wuz.nar); }); QUnit.test('[obj, Foo] -> (undefined)', function () { strictEqual((0, _emberMetal.get)(obj, 'Foo'), undefined); }); QUnit.test('[obj, Foo.bar] -> (undefined)', function () { strictEqual((0, _emberMetal.get)(obj, 'Foo.bar'), undefined); }); }); enifed('ember-metal/tests/accessors/get_properties_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember.getProperties'); QUnit.test('can retrieve a hash of properties from an object via an argument list or array of property names', function () { var obj = { firstName: 'Steve', lastName: 'Jobs', companyName: 'Apple, Inc.' }; deepEqual((0, _emberMetal.getProperties)(obj, 'firstName', 'lastName'), { firstName: 'Steve', lastName: 'Jobs' }); deepEqual((0, _emberMetal.getProperties)(obj, 'firstName', 'lastName'), { firstName: 'Steve', lastName: 'Jobs' }); deepEqual((0, _emberMetal.getProperties)(obj, 'lastName'), { lastName: 'Jobs' }); deepEqual((0, _emberMetal.getProperties)(obj), {}); deepEqual((0, _emberMetal.getProperties)(obj, ['firstName', 'lastName']), { firstName: 'Steve', lastName: 'Jobs' }); deepEqual((0, _emberMetal.getProperties)(obj, ['firstName']), { firstName: 'Steve' }); deepEqual((0, _emberMetal.getProperties)(obj, []), {}); }); }); enifed('ember-metal/tests/accessors/get_test', ['internal-test-helpers', 'ember-metal'], function (_internalTestHelpers, _emberMetal) { 'use strict'; QUnit.module('Ember.get'); QUnit.test('should get arbitrary properties on an object', function () { var obj = { string: 'string', number: 23, boolTrue: true, boolFalse: false, nullValue: null }; for (var key in obj) { if (!obj.hasOwnProperty(key)) { continue; } equal((0, _emberMetal.get)(obj, key), obj[key], key); } }); QUnit.test('should not access a property more than once', function () { var count = 0; var obj = { get id() { return ++count; } }; (0, _emberMetal.get)(obj, 'id'); equal(count, 1); }); (0, _internalTestHelpers.testBoth)('should call unknownProperty on watched values if the value is undefined', function (get) { var obj = { count: 0, unknownProperty: function (key) { equal(key, 'foo', 'should pass key'); this.count++; return 'FOO'; } }; var count = 0; (0, _emberMetal.addObserver)(obj, 'foo', function () { count++; }); equal(get(obj, 'foo'), 'FOO', 'should return value from unknown'); }); QUnit.test('warn on attemps to call get with no arguments', function () { expectAssertion(function () { (0, _emberMetal.get)('aProperty'); }, /Get must be called with two arguments;/i); }); QUnit.test('warn on attemps to call get with only one argument', function () { expectAssertion(function () { (0, _emberMetal.get)('aProperty'); }, /Get must be called with two arguments;/i); }); QUnit.test('warn on attemps to call get with more then two arguments', function () { expectAssertion(function () { (0, _emberMetal.get)({}, 'aProperty', true); }, /Get must be called with two arguments;/i); }); QUnit.test('warn on attempts to get a property of undefined', function () { expectAssertion(function () { (0, _emberMetal.get)(undefined, 'aProperty'); }, /Cannot call get with 'aProperty' on an undefined object/i); }); QUnit.test('warn on attempts to get a property path of undefined', function () { expectAssertion(function () { (0, _emberMetal.get)(undefined, 'aProperty.on.aPath'); }, /Cannot call get with 'aProperty.on.aPath' on an undefined object/); }); QUnit.test('warn on attempts to get a property of null', function () { expectAssertion(function () { (0, _emberMetal.get)(null, 'aProperty'); }, /Cannot call get with 'aProperty' on an undefined object/); }); QUnit.test('warn on attempts to get a property path of null', function () { expectAssertion(function () { (0, _emberMetal.get)(null, 'aProperty.on.aPath'); }, /Cannot call get with 'aProperty.on.aPath' on an undefined object/); }); QUnit.test('warn on attempts to use get with an unsupported property path', function () { var obj = {}; expectAssertion(function () { return (0, _emberMetal.get)(obj, null); }, /The key provided to get must be a string, you passed null/); expectAssertion(function () { return (0, _emberMetal.get)(obj, NaN); }, /The key provided to get must be a string, you passed NaN/); expectAssertion(function () { return (0, _emberMetal.get)(obj, undefined); }, /The key provided to get must be a string, you passed undefined/); expectAssertion(function () { return (0, _emberMetal.get)(obj, false); }, /The key provided to get must be a string, you passed false/); expectAssertion(function () { return (0, _emberMetal.get)(obj, 42); }, /The key provided to get must be a string, you passed 42/); expectAssertion(function () { return (0, _emberMetal.get)(obj, ''); }, /Cannot call `Ember.get` with an empty string/); }); // .......................................................... // BUGS // QUnit.test('(regression) watched properties on unmodified inherited objects should still return their original value', function () { var MyMixin = _emberMetal.Mixin.create({ someProperty: 'foo', propertyDidChange: (0, _emberMetal.observer)('someProperty', function () {}) }); var baseObject = MyMixin.apply({}); var theRealObject = Object.create(baseObject); equal((0, _emberMetal.get)(theRealObject, 'someProperty'), 'foo', 'should return the set value, not false'); }); QUnit.module('Ember.getWithDefault'); QUnit.test('should get arbitrary properties on an object', function () { var obj = { string: 'string', number: 23, boolTrue: true, boolFalse: false, nullValue: null }; for (var key in obj) { if (!obj.hasOwnProperty(key)) { continue; } equal((0, _emberMetal.getWithDefault)(obj, key, 'fail'), obj[key], key); } obj = { undef: undefined }; equal((0, _emberMetal.getWithDefault)(obj, 'undef', 'default'), 'default', 'explicit undefined retrieves the default'); equal((0, _emberMetal.getWithDefault)(obj, 'not-present', 'default'), 'default', 'non-present key retrieves the default'); }); QUnit.test('should call unknownProperty if defined and value is undefined', function () { var obj = { count: 0, unknownProperty: function (key) { equal(key, 'foo', 'should pass key'); this.count++; return 'FOO'; } }; equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should return value from unknown'); equal(obj.count, 1, 'should have invoked'); }); (0, _internalTestHelpers.testBoth)('if unknownProperty is present, it is called', function () { var obj = { count: 0, unknownProperty: function (key) { if (key === 'foo') { equal(key, 'foo', 'should pass key'); this.count++; return 'FOO'; } } }; var count = 0; (0, _emberMetal.addObserver)(obj, 'foo', function () { return count++; }); equal((0, _emberMetal.getWithDefault)(obj, 'foo', 'fail'), 'FOO', 'should return value from unknownProperty'); equal((0, _emberMetal.getWithDefault)(obj, 'bar', 'default'), 'default', 'should convert undefined from unknownProperty into default'); }); // .......................................................... // BUGS // QUnit.test('(regression) watched properties on unmodified inherited objects should still return their original value', function () { var MyMixin = _emberMetal.Mixin.create({ someProperty: 'foo', propertyDidChange: (0, _emberMetal.observer)('someProperty', function () {/* nothing to do */}) }); var baseObject = MyMixin.apply({}); var theRealObject = Object.create(baseObject); equal((0, _emberMetal.getWithDefault)(theRealObject, 'someProperty', 'fail'), 'foo', 'should return the set value, not false'); }); }); enifed('ember-metal/tests/accessors/is_global_path_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember.isGlobalPath'); QUnit.test('global path\'s are recognized', function () { ok((0, _emberMetal.isGlobalPath)('App.myProperty')); ok((0, _emberMetal.isGlobalPath)('App.myProperty.subProperty')); }); QUnit.test('if there is a \'this\' in the path, it\'s not a global path', function () { ok(!(0, _emberMetal.isGlobalPath)('this.myProperty')); ok(!(0, _emberMetal.isGlobalPath)('this')); }); QUnit.test('if the path starts with a lowercase character, it is not a global path', function () { ok(!(0, _emberMetal.isGlobalPath)('myObj')); ok(!(0, _emberMetal.isGlobalPath)('myObj.SecondProperty')); }); }); enifed('ember-metal/tests/accessors/mandatory_setters_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('mandatory-setters'); }); enifed('ember-metal/tests/accessors/set_path_test', ['ember-environment', 'ember-metal'], function (_emberEnvironment, _emberMetal) { 'use strict'; var originalLookup = _emberEnvironment.context.lookup; var lookup = void 0; var obj = void 0; function commonSetup() { _emberEnvironment.context.lookup = lookup = {}; obj = { foo: { bar: { baz: { biff: 'BIFF' } } } }; } function commonTeardown() { _emberEnvironment.context.lookup = originalLookup; obj = null; } QUnit.module('set with path', { setup: commonSetup, teardown: commonTeardown }); QUnit.test('[Foo, bar] -> Foo.bar', function () { lookup.Foo = { toString: function () { return 'Foo'; } }; // Behave like an Ember.Namespace (0, _emberMetal.set)(lookup.Foo, 'bar', 'baz'); equal((0, _emberMetal.get)(lookup.Foo, 'bar'), 'baz'); }); // .......................................................... // // LOCAL PATHS QUnit.test('[obj, foo] -> obj.foo', function () { (0, _emberMetal.set)(obj, 'foo', 'BAM'); equal((0, _emberMetal.get)(obj, 'foo'), 'BAM'); }); QUnit.test('[obj, foo.bar] -> obj.foo.bar', function () { (0, _emberMetal.set)(obj, 'foo.bar', 'BAM'); equal((0, _emberMetal.get)(obj, 'foo.bar'), 'BAM'); }); // .......................................................... // DEPRECATED // QUnit.module('set with path - deprecated', { setup: commonSetup, teardown: commonTeardown }); QUnit.test('[obj, bla.bla] gives a proper exception message', function () { try { (0, _emberMetal.set)(obj, 'bla.bla', 'BAM'); } catch (ex) { equal(ex.message, 'Property set failed: object in path \"bla\" could not be found or was destroyed.'); } }); QUnit.test('[obj, foo.baz.bat] -> EXCEPTION', function () { throws(function () { return (0, _emberMetal.set)(obj, 'foo.baz.bat', 'BAM'); }); }); QUnit.test('[obj, foo.baz.bat] -> EXCEPTION', function () { (0, _emberMetal.trySet)(obj, 'foo.baz.bat', 'BAM'); ok(true, 'does not raise'); }); }); enifed('ember-metal/tests/accessors/set_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('set', { teardown: function () { (0, _emberMetal.setHasViews)(function () { return false; }); } }); QUnit.test('should set arbitrary properties on an object', function () { var obj = { string: 'string', number: 23, boolTrue: true, boolFalse: false, nullValue: null, undefinedValue: undefined }; var newObj = { undefinedValue: 'emberjs' }; for (var key in obj) { if (!obj.hasOwnProperty(key)) { continue; } equal((0, _emberMetal.set)(newObj, key, obj[key]), obj[key], 'should return value'); equal((0, _emberMetal.get)(newObj, key), obj[key], 'should set value'); } }); QUnit.test('should call setUnknownProperty if defined and value is undefined', function () { var obj = { count: 0, unknownProperty: function () { ok(false, 'should not invoke unknownProperty if setUnknownProperty is defined'); }, setUnknownProperty: function (key, value) { equal(key, 'foo', 'should pass key'); equal(value, 'BAR', 'should pass key'); this.count++; return 'FOO'; } }; equal((0, _emberMetal.set)(obj, 'foo', 'BAR'), 'BAR', 'should return set value'); equal(obj.count, 1, 'should have invoked'); }); QUnit.test('warn on attempts to call set with undefined as object', function () { expectAssertion(function () { return (0, _emberMetal.set)(undefined, 'aProperty', 'BAM'); }, /Cannot call set with 'aProperty' on an undefined object./); }); QUnit.test('warn on attempts to call set with null as object', function () { expectAssertion(function () { return (0, _emberMetal.set)(null, 'aProperty', 'BAM'); }, /Cannot call set with 'aProperty' on an undefined object./); }); QUnit.test('warn on attempts to use set with an unsupported property path', function () { var obj = {}; expectAssertion(function () { return (0, _emberMetal.set)(obj, null, 42); }, /The key provided to set must be a string, you passed null/); expectAssertion(function () { return (0, _emberMetal.set)(obj, NaN, 42); }, /The key provided to set must be a string, you passed NaN/); expectAssertion(function () { return (0, _emberMetal.set)(obj, undefined, 42); }, /The key provided to set must be a string, you passed undefined/); expectAssertion(function () { return (0, _emberMetal.set)(obj, false, 42); }, /The key provided to set must be a string, you passed false/); expectAssertion(function () { return (0, _emberMetal.set)(obj, 42, 42); }, /The key provided to set must be a string, you passed 42/); }); QUnit.test('warn on attempts of calling set on a destroyed object', function () { var obj = { isDestroyed: true }; expectAssertion(function () { return (0, _emberMetal.set)(obj, 'favoriteFood', 'hot dogs'); }, 'calling set on destroyed object: [object Object].favoriteFood = hot dogs'); }); QUnit.test('does not trigger auto-run assertion for objects that have not been tagged', function (assert) { (0, _emberMetal.setHasViews)(function () { return true; }); var obj = {}; (0, _emberMetal.set)(obj, 'foo', 'bar'); assert.equal(obj.foo, 'bar'); }); }); enifed('ember-metal/tests/alias_test', ['ember-metal'], function (_emberMetal) { 'use strict'; var obj = void 0, count = void 0; QUnit.module('ember-metal/alias', { setup: function () { obj = { foo: { faz: 'FOO' } }; count = 0; }, teardown: function () { obj = null; } }); function incrementCount() { count++; } QUnit.test('should proxy get to alt key', function () { (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('foo.faz')); equal((0, _emberMetal.get)(obj, 'bar'), 'FOO'); }); QUnit.test('should proxy set to alt key', function () { (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('foo.faz')); (0, _emberMetal.set)(obj, 'bar', 'BAR'); equal((0, _emberMetal.get)(obj, 'foo.faz'), 'BAR'); }); QUnit.test('old dependent keys should not trigger property changes', function () { var obj1 = Object.create(null); (0, _emberMetal.defineProperty)(obj1, 'foo', null, null); (0, _emberMetal.defineProperty)(obj1, 'bar', (0, _emberMetal.alias)('foo')); (0, _emberMetal.defineProperty)(obj1, 'baz', (0, _emberMetal.alias)('foo')); (0, _emberMetal.defineProperty)(obj1, 'baz', (0, _emberMetal.alias)('bar')); // redefine baz (0, _emberMetal.addObserver)(obj1, 'baz', incrementCount); (0, _emberMetal.set)(obj1, 'foo', 'FOO'); equal(count, 1); (0, _emberMetal.removeObserver)(obj1, 'baz', incrementCount); (0, _emberMetal.set)(obj1, 'foo', 'OOF'); equal(count, 1); }); QUnit.test('inheriting an observer of the alias from the prototype then\n redefining the alias on the instance to another property dependent on same key\n does not call the observer twice', function () { var obj1 = Object.create(null); (0, _emberMetal.meta)(obj1).proto = obj1; (0, _emberMetal.defineProperty)(obj1, 'foo', null, null); (0, _emberMetal.defineProperty)(obj1, 'bar', (0, _emberMetal.alias)('foo')); (0, _emberMetal.defineProperty)(obj1, 'baz', (0, _emberMetal.alias)('foo')); (0, _emberMetal.addObserver)(obj1, 'baz', incrementCount); var obj2 = Object.create(obj1); (0, _emberMetal.defineProperty)(obj2, 'baz', (0, _emberMetal.alias)('bar')); // override baz (0, _emberMetal.set)(obj2, 'foo', 'FOO'); equal(count, 1); (0, _emberMetal.removeObserver)(obj2, 'baz', incrementCount); (0, _emberMetal.set)(obj2, 'foo', 'OOF'); equal(count, 1); }); QUnit.test('an observer of the alias works if added after defining the alias', function () { (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('foo.faz')); (0, _emberMetal.addObserver)(obj, 'bar', incrementCount); ok((0, _emberMetal.isWatching)(obj, 'foo.faz')); (0, _emberMetal.set)(obj, 'foo.faz', 'BAR'); equal(count, 1); }); QUnit.test('an observer of the alias works if added before defining the alias', function () { (0, _emberMetal.addObserver)(obj, 'bar', incrementCount); (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('foo.faz')); ok((0, _emberMetal.isWatching)(obj, 'foo.faz')); (0, _emberMetal.set)(obj, 'foo.faz', 'BAR'); equal(count, 1); }); QUnit.test('object with alias is dirtied if interior object of alias is set after consumption', function () { (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('foo.faz')); (0, _emberMetal.get)(obj, 'bar'); assertDirty(obj, function () { return (0, _emberMetal.set)(obj, 'foo.faz', 'BAR'); }, 'setting the aliased key should dirty the object'); }); QUnit.test('setting alias on self should fail assertion', function () { expectAssertion(function () { return (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('bar')); }, 'Setting alias \'bar\' on self'); }); function assertDirty(obj, callback, label) { var tag = (0, _emberMetal.tagFor)(obj); var tagValue = tag.value(); callback(); ok(!tag.validate(tagValue), label); } }); enifed('ember-metal/tests/binding/connect_test', ['ember-environment', 'internal-test-helpers', 'ember-metal'], function (_emberEnvironment, _internalTestHelpers, _emberMetal) { 'use strict'; function performTest(binding, a, b, get, set, connect) { if (connect === undefined) { connect = function () { return binding.connect(a); }; } ok(!_emberMetal.run.currentRunLoop, 'performTest should not have a currentRunLoop'); equal(get(a, 'foo'), 'FOO', 'a should not have changed'); equal(get(b, 'bar'), 'BAR', 'b should not have changed'); connect(); equal(get(a, 'foo'), 'BAR', 'a should have changed'); equal(get(b, 'bar'), 'BAR', 'b should have changed'); // // make sure changes sync both ways (0, _emberMetal.run)(function () { return set(b, 'bar', 'BAZZ'); }); equal(get(a, 'foo'), 'BAZZ', 'a should have changed'); (0, _emberMetal.run)(function () { return set(a, 'foo', 'BARF'); }); equal(get(b, 'bar'), 'BARF', 'a should have changed'); } var originalLookup = void 0, lookup = void 0, GlobalB = void 0; QUnit.module('Ember.Binding', { setup: function () { originalLookup = _emberEnvironment.context.lookup; _emberEnvironment.context.lookup = lookup = {}; }, teardown: function () { lookup = null; _emberEnvironment.context.lookup = originalLookup; } }); (0, _internalTestHelpers.testBoth)('Connecting a binding between two properties', function (get, set) { var a = { foo: 'FOO', bar: 'BAR' }; // a.bar -> a.foo var binding = new _emberMetal.Binding('foo', 'bar'); expectDeprecation(function () { performTest(binding, a, a, get, set); }, /`Ember\.Binding` is deprecated./); }); (0, _internalTestHelpers.testBoth)('Connecting a oneWay binding raises a deprecation', function () { var a = { foo: 'FOO', bar: 'BAR', toString: function () { return ''; } }; // a.bar -> a.foo var binding = new _emberMetal.Binding('foo', 'bar').oneWay(); expectDeprecation(function () { binding.connect(a); }, /`Ember.Binding` is deprecated/); }); (0, _internalTestHelpers.testBoth)('Connecting a binding between two objects', function (get, set) { var b = { bar: 'BAR' }; var a = { foo: 'FOO', b: b }; // b.bar -> a.foo var binding = new _emberMetal.Binding('foo', 'b.bar'); expectDeprecation(function () { performTest(binding, a, b, get, set); }, /`Ember\.Binding` is deprecated./); }); (0, _internalTestHelpers.testBoth)('Connecting a binding to path', function (get, set) { var a = { foo: 'FOO' }; lookup['GlobalB'] = GlobalB = { b: { bar: 'BAR' } }; var b = get(GlobalB, 'b'); // globalB.b.bar -> a.foo var binding = new _emberMetal.Binding('foo', 'GlobalB.b.bar'); expectDeprecation(function () { performTest(binding, a, b, get, set); }, /`Ember\.Binding` is deprecated./); // make sure modifications update b = { bar: 'BIFF' }; (0, _emberMetal.run)(function () { return set(GlobalB, 'b', b); }); equal(get(a, 'foo'), 'BIFF', 'a should have changed'); }); (0, _internalTestHelpers.testBoth)('Calling connect more than once', function (get, set) { var b = { bar: 'BAR' }; var a = { foo: 'FOO', b: b }; // b.bar -> a.foo var binding = new _emberMetal.Binding('foo', 'b.bar'); expectDeprecation(function () { performTest(binding, a, b, get, set, function () { binding.connect(a); binding.connect(a); }); }, /`Ember\.Binding` is deprecated./); }); QUnit.test('inherited bindings should sync on create', function () { var a = void 0; (0, _emberMetal.run)(function () { function A() { (0, _emberMetal.bind)(this, 'foo', 'bar.baz'); } expectDeprecation(function () { return a = new A(); }, /`Ember\.Binding` is deprecated/); (0, _emberMetal.set)(a, 'bar', { baz: 'BAZ' }); }); equal((0, _emberMetal.get)(a, 'foo'), 'BAZ', 'should have synced binding on new obj'); }); }); enifed('ember-metal/tests/binding/sync_test', ['internal-test-helpers', 'ember-metal'], function (_internalTestHelpers, _emberMetal) { 'use strict'; QUnit.module('system/binding/sync_test.js'); (0, _internalTestHelpers.testBoth)('bindings should not sync twice in a single run loop', function (get, set) { var a = void 0, b = void 0, setValue = void 0; var setCalled = 0; var getCalled = 0; (0, _emberMetal.run)(function () { a = {}; (0, _emberMetal.defineProperty)(a, 'foo', (0, _emberMetal.computed)({ get: function () { getCalled++; return setValue; }, set: function (key, value) { setCalled++; (0, _emberMetal.propertyWillChange)(this, key); setValue = value; (0, _emberMetal.propertyDidChange)(this, key); return value; } }).volatile()); b = { a: a }; expectDeprecation(function () { return (0, _emberMetal.bind)(b, 'foo', 'a.foo'); }, /`Ember.Binding` is deprecated/); }); // reset after initial binding synchronization getCalled = 0; (0, _emberMetal.run)(function () { set(a, 'foo', 'trollface'); }); equal(get(b, 'foo'), 'trollface', 'the binding should sync'); equal(setCalled, 1, 'Set should only be called once'); equal(getCalled, 1, 'Get should only be called once'); }); (0, _internalTestHelpers.testBoth)('bindings should not infinite loop if computed properties return objects', function (get) { var a = void 0, b = void 0; var getCalled = 0; (0, _emberMetal.run)(function () { a = {}; (0, _emberMetal.defineProperty)(a, 'foo', (0, _emberMetal.computed)(function () { getCalled++; if (getCalled > 1000) { throw 'infinite loop detected'; } return ['foo', 'bar']; })); b = { a: a }; expectDeprecation(function () { return (0, _emberMetal.bind)(b, 'foo', 'a.foo'); }, /`Ember.Binding` is deprecated/); }); deepEqual(get(b, 'foo'), ['foo', 'bar'], 'the binding should sync'); equal(getCalled, 1, 'Get should only be called once'); }); (0, _internalTestHelpers.testBoth)('bindings should do the right thing when observers trigger bindings in the opposite direction', function (get, set) { var a = void 0, b = void 0, c = void 0; (0, _emberMetal.run)(function () { a = { foo: 'trololol' }; b = { a: a }; var deprecationMessage = /`Ember.Binding` is deprecated/; expectDeprecation(function () { return (0, _emberMetal.bind)(b, 'foo', 'a.foo'); }, deprecationMessage); c = { a: a }; expectDeprecation(function () { (0, _emberMetal.bind)(c, 'foo', 'a.foo'); }, deprecationMessage); }); (0, _emberMetal.addObserver)(b, 'foo', function () { return set(c, 'foo', 'what is going on'); }); (0, _emberMetal.run)(function () { return set(a, 'foo', 'trollface'); }); equal(get(a, 'foo'), 'what is going on'); }); (0, _internalTestHelpers.testBoth)('bindings should not try to sync destroyed objects', function (get, set) { var a = void 0, b = void 0; (0, _emberMetal.run)(function () { a = { foo: 'trololol' }; b = { a: a }; var deprecationMessage = /`Ember.Binding` is deprecated/; expectDeprecation(function () { return (0, _emberMetal.bind)(b, 'foo', 'a.foo'); }, deprecationMessage); }); (0, _emberMetal.run)(function () { set(a, 'foo', 'trollface'); set(b, 'isDestroyed', true); ok(true, 'should not raise'); }); (0, _emberMetal.run)(function () { a = { foo: 'trololol' }; b = { a: a }; var deprecationMessage = /`Ember.Binding` is deprecated/; expectDeprecation(function () { return (0, _emberMetal.bind)(b, 'foo', 'a.foo'); }, deprecationMessage); }); (0, _emberMetal.run)(function () { set(b, 'foo', 'trollface'); set(a, 'isDestroyed', true); ok(true, 'should not raise'); }); }); }); enifed('ember-metal/tests/cache_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Cache'); QUnit.test('basic', function () { var cache = new _emberMetal.Cache(100, function (key) { return key.toUpperCase(); }); equal(cache.get('foo'), 'FOO'); equal(cache.get('bar'), 'BAR'); equal(cache.get('foo'), 'FOO'); }); QUnit.test('explicit sets', function () { var cache = new _emberMetal.Cache(100, function (key) { return key.toUpperCase(); }); equal(cache.get('foo'), 'FOO'); equal(cache.set('foo', 'FOO!!!'), 'FOO!!!'); equal(cache.get('foo'), 'FOO!!!'); strictEqual(cache.set('foo', undefined), undefined); strictEqual(cache.get('foo'), undefined); }); QUnit.test('caches computation correctly', function () { var count = 0; var cache = new _emberMetal.Cache(100, function (key) { count++; return key.toUpperCase(); }); equal(count, 0); cache.get('foo'); equal(count, 1); cache.get('bar'); equal(count, 2); cache.get('bar'); equal(count, 2); cache.get('foo'); equal(count, 2); }); QUnit.test('caches computation correctly with custom cache keys', function () { var count = 0; var cache = new _emberMetal.Cache(100, function (obj) { count++; return obj.value.toUpperCase(); }, function (obj) { return obj.key; }); equal(count, 0); cache.get({ key: 'foo', value: 'foo' }); equal(count, 1); cache.get({ key: 'bar', value: 'bar' }); equal(count, 2); cache.get({ key: 'bar', value: 'bar' }); equal(count, 2); cache.get({ key: 'foo', value: 'foo' }); equal(count, 2); }); QUnit.test('handles undefined value correctly', function () { var count = 0; var cache = new _emberMetal.Cache(100, function () { count++; }); equal(count, 0); strictEqual(cache.get('foo'), undefined); equal(count, 1); strictEqual(cache.get('bar'), undefined); equal(count, 2); strictEqual(cache.get('bar'), undefined); equal(count, 2); strictEqual(cache.get('foo'), undefined); equal(count, 2); }); QUnit.test('continues working after reaching cache limit', function () { var cache = new _emberMetal.Cache(3, function (key) { return key.toUpperCase(); }); cache.get('a'); cache.get('b'); cache.get('c'); equal(cache.get('d'), 'D'); equal(cache.get('a'), 'A'); equal(cache.get('b'), 'B'); equal(cache.get('c'), 'C'); }); }); enifed('ember-metal/tests/chains_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Chains'); QUnit.test('finishChains should properly copy chains from prototypes to instances', function () { var obj = {}; (0, _emberMetal.addObserver)(obj, 'foo.bar', null, function () {}); var childObj = Object.create(obj); var parentMeta = (0, _emberMetal.meta)(obj); var childMeta = (0, _emberMetal.meta)(childObj); (0, _emberMetal.finishChains)(childMeta); ok(parentMeta.readableChains() !== childMeta.readableChains(), 'The chains object is copied'); }); QUnit.test('does not observe primitive values', function (assert) { var obj = { foo: { bar: 'STRING' } }; (0, _emberMetal.addObserver)(obj, 'foo.bar.baz', null, function () {}); var meta = (0, _emberMetal.peekMeta)(obj); assert.notOk(meta._object); }); QUnit.test('observer and CP chains', function () { var obj = {}; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)('qux.[]', function () {})); (0, _emberMetal.defineProperty)(obj, 'qux', (0, _emberMetal.computed)(function () {})); // create DK chains (0, _emberMetal.get)(obj, 'foo'); // create observer chain (0, _emberMetal.addObserver)(obj, 'qux.length', function () {}); /* +-----+ | qux | root CP +-----+ ^ +------+-----+ | | +--------+ +----+ | length | | [] | chainWatchers +--------+ +----+ observer CP(foo, 'qux.[]') */ // invalidate qux (0, _emberMetal.propertyDidChange)(obj, 'qux'); // CP chain is blown away /* +-----+ | qux | root CP +-----+ ^ +------+xxxxxx | x +--------+ xxxxxx | length | x [] x chainWatchers +--------+ xxxxxx observer CP(foo, 'qux.[]') */ (0, _emberMetal.get)(obj, 'qux'); // CP chain re-recreated ok(true, 'no crash'); }); QUnit.test('checks cache correctly', function (assert) { var obj = {}; var parentChainNode = new _emberMetal.ChainNode(null, null, obj); var chainNode = new _emberMetal.ChainNode(parentChainNode, 'foo'); (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () { return undefined; })); (0, _emberMetal.get)(obj, 'foo'); assert.strictEqual(chainNode.value(), undefined); }); }); enifed('ember-metal/tests/computed_test', ['ember-runtime', 'internal-test-helpers', 'ember-metal'], function (_emberRuntime, _internalTestHelpers, _emberMetal) { 'use strict'; var obj = void 0, count = void 0; QUnit.module('computed'); QUnit.test('computed property should be an instance of descriptor', function () { ok((0, _emberMetal.computed)(function () {}) instanceof _emberMetal.Descriptor); }); QUnit.test('computed properties assert the presence of a getter or setter function', function () { expectAssertion(function () { (0, _emberMetal.computed)('nogetternorsetter', {}); }, 'Computed properties must receive a getter or a setter, you passed none.'); }); QUnit.test('computed properties check for the presence of a function or configuration object', function () { expectAssertion(function () { (0, _emberMetal.computed)('nolastargument'); }, 'Ember.computed expects a function or an object as last argument.'); }); QUnit.test('computed properties defined with an object only allow `get` and `set` keys', function () { expectAssertion(function () { (0, _emberMetal.computed)({ get: function () {}, set: function () {}, other: function () {} }); }, 'Config object passed to an Ember.computed can only contain `get` or `set` keys.'); }); QUnit.test('defining computed property should invoke property on get', function () { var obj = {}; var count = 0; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function (key) { count++; return 'computed ' + key; })); equal((0, _emberMetal.get)(obj, 'foo'), 'computed foo', 'should return value'); equal(count, 1, 'should have invoked computed property'); }); QUnit.test('defining computed property should invoke property on set', function () { var obj = {}; var count = 0; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({ get: function (key) { return this['__' + key]; }, set: function (key, value) { count++; this['__' + key] = 'computed ' + value; return this['__' + key]; } })); equal((0, _emberMetal.set)(obj, 'foo', 'bar'), 'bar', 'should return set value'); equal(count, 1, 'should have invoked computed property'); equal((0, _emberMetal.get)(obj, 'foo'), 'computed bar', 'should return new value'); }); QUnit.test('defining a computed property with a dependent key ending with @each is expanded to []', function () { var cp = (0, _emberMetal.computed)('blazo.@each', function () {}); deepEqual(cp._dependentKeys, ['blazo.[]']); cp = (0, _emberMetal.computed)('qux', 'zoopa.@each', function () {}); deepEqual(cp._dependentKeys, ['qux', 'zoopa.[]']); }); QUnit.test('defining a computed property with a dependent key more than one level deep beyond @each is not supported', function () { expectNoWarning(function () { (0, _emberMetal.computed)('todos', function () {}); }); expectNoWarning(function () { (0, _emberMetal.computed)('todos.@each.owner', function () {}); }); expectWarning(function () { (0, _emberMetal.computed)('todos.@each.owner.name', function () {}); }, /You used the key "todos\.@each\.owner\.name" which is invalid\. /); expectWarning(function () { (0, _emberMetal.computed)('todos.@each.owner.@each.name', function () {}); }, /You used the key "todos\.@each\.owner\.@each\.name" which is invalid\. /); }); var objA = void 0, objB = void 0; QUnit.module('computed should inherit through prototype', { setup: function () { objA = { __foo: 'FOO' }; (0, _emberMetal.defineProperty)(objA, 'foo', (0, _emberMetal.computed)({ get: function (key) { return this['__' + key]; }, set: function (key, value) { this['__' + key] = 'computed ' + value; return this['__' + key]; } })); objB = Object.create(objA); objB.__foo = 'FOO'; // make a copy; }, teardown: function () { objA = objB = null; } }); (0, _internalTestHelpers.testBoth)('using get() and set()', function (get, set) { equal(get(objA, 'foo'), 'FOO', 'should get FOO from A'); equal(get(objB, 'foo'), 'FOO', 'should get FOO from B'); set(objA, 'foo', 'BIFF'); equal(get(objA, 'foo'), 'computed BIFF', 'should change A'); equal(get(objB, 'foo'), 'FOO', 'should NOT change B'); set(objB, 'foo', 'bar'); equal(get(objB, 'foo'), 'computed bar', 'should change B'); equal(get(objA, 'foo'), 'computed BIFF', 'should NOT change A'); set(objA, 'foo', 'BAZ'); equal(get(objA, 'foo'), 'computed BAZ', 'should change A'); equal(get(objB, 'foo'), 'computed bar', 'should NOT change B'); }); QUnit.module('redefining computed property to normal', { setup: function () { objA = { __foo: 'FOO' }; (0, _emberMetal.defineProperty)(objA, 'foo', (0, _emberMetal.computed)({ get: function (key) { return this['__' + key]; }, set: function (key, value) { this['__' + key] = 'computed ' + value; return this['__' + key]; } })); objB = Object.create(objA); (0, _emberMetal.defineProperty)(objB, 'foo'); // make this just a normal property. }, teardown: function () { objA = objB = null; } }); (0, _internalTestHelpers.testBoth)('using get() and set()', function (get, set) { equal(get(objA, 'foo'), 'FOO', 'should get FOO from A'); equal(get(objB, 'foo'), undefined, 'should get undefined from B'); set(objA, 'foo', 'BIFF'); equal(get(objA, 'foo'), 'computed BIFF', 'should change A'); equal(get(objB, 'foo'), undefined, 'should NOT change B'); set(objB, 'foo', 'bar'); equal(get(objB, 'foo'), 'bar', 'should change B'); equal(get(objA, 'foo'), 'computed BIFF', 'should NOT change A'); set(objA, 'foo', 'BAZ'); equal(get(objA, 'foo'), 'computed BAZ', 'should change A'); equal(get(objB, 'foo'), 'bar', 'should NOT change B'); }); QUnit.module('redefining computed property to another property', { setup: function () { objA = { __foo: 'FOO' }; (0, _emberMetal.defineProperty)(objA, 'foo', (0, _emberMetal.computed)({ get: function (key) { return this['__' + key]; }, set: function (key, value) { this['__' + key] = 'A ' + value; return this['__' + key]; } })); objB = Object.create(objA); objB.__foo = 'FOO'; (0, _emberMetal.defineProperty)(objB, 'foo', (0, _emberMetal.computed)({ get: function (key) { return this['__' + key]; }, set: function (key, value) { this['__' + key] = 'B ' + value; return this['__' + key]; } })); }, teardown: function () { objA = objB = null; } }); (0, _internalTestHelpers.testBoth)('using get() and set()', function (get, set) { equal(get(objA, 'foo'), 'FOO', 'should get FOO from A'); equal(get(objB, 'foo'), 'FOO', 'should get FOO from B'); set(objA, 'foo', 'BIFF'); equal(get(objA, 'foo'), 'A BIFF', 'should change A'); equal(get(objB, 'foo'), 'FOO', 'should NOT change B'); set(objB, 'foo', 'bar'); equal(get(objB, 'foo'), 'B bar', 'should change B'); equal(get(objA, 'foo'), 'A BIFF', 'should NOT change A'); set(objA, 'foo', 'BAZ'); equal(get(objA, 'foo'), 'A BAZ', 'should change A'); equal(get(objB, 'foo'), 'B bar', 'should NOT change B'); }); QUnit.module('computed - metadata'); QUnit.test('can set metadata on a computed property', function () { var computedProperty = (0, _emberMetal.computed)(function () {}); computedProperty.meta({ key: 'keyValue' }); equal(computedProperty.meta().key, 'keyValue', 'saves passed meta hash to the _meta property'); }); QUnit.test('meta should return an empty hash if no meta is set', function () { var computedProperty = (0, _emberMetal.computed)(function () {}); deepEqual(computedProperty.meta(), {}, 'returned value is an empty hash'); }); // .......................................................... // CACHEABLE // QUnit.module('computed - cacheable', { setup: function () { obj = {}; count = 0; var func = function () { count++; return 'bar ' + count; }; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({ get: func, set: func })); }, teardown: function () { obj = count = null; } }); (0, _internalTestHelpers.testBoth)('cacheable should cache', function (get) { equal(get(obj, 'foo'), 'bar 1', 'first get'); equal(get(obj, 'foo'), 'bar 1', 'second get'); equal(count, 1, 'should only invoke once'); }); (0, _internalTestHelpers.testBoth)('modifying a cacheable property should update cache', function (get, set) { equal(get(obj, 'foo'), 'bar 1', 'first get'); equal(get(obj, 'foo'), 'bar 1', 'second get'); equal(set(obj, 'foo', 'baz'), 'baz', 'setting'); equal(get(obj, 'foo'), 'bar 2', 'third get'); equal(count, 2, 'should not invoke again'); }); (0, _internalTestHelpers.testBoth)('inherited property should not pick up cache', function (get, set) { var objB = Object.create(obj); equal(get(obj, 'foo'), 'bar 1', 'obj first get'); equal(get(objB, 'foo'), 'bar 2', 'objB first get'); equal(get(obj, 'foo'), 'bar 1', 'obj second get'); equal(get(objB, 'foo'), 'bar 2', 'objB second get'); set(obj, 'foo', 'baz'); // modify A equal(get(obj, 'foo'), 'bar 3', 'obj third get'); equal(get(objB, 'foo'), 'bar 2', 'objB third get'); }); (0, _internalTestHelpers.testBoth)('cacheFor should return the cached value', function (get) { equal((0, _emberMetal.cacheFor)(obj, 'foo'), undefined, 'should not yet be a cached value'); get(obj, 'foo'); equal((0, _emberMetal.cacheFor)(obj, 'foo'), 'bar 1', 'should retrieve cached value'); }); (0, _internalTestHelpers.testBoth)('cacheFor should return falsy cached values', function (get) { (0, _emberMetal.defineProperty)(obj, 'falsy', (0, _emberMetal.computed)(function () { return false; })); equal((0, _emberMetal.cacheFor)(obj, 'falsy'), undefined, 'should not yet be a cached value'); get(obj, 'falsy'); equal((0, _emberMetal.cacheFor)(obj, 'falsy'), false, 'should retrieve cached value'); }); (0, _internalTestHelpers.testBoth)('setting a cached computed property passes the old value as the third argument', function (get, set) { var obj = { foo: 0 }; var receivedOldValue = void 0; (0, _emberMetal.defineProperty)(obj, 'plusOne', (0, _emberMetal.computed)({ get: function () {}, set: function (key, value, oldValue) { receivedOldValue = oldValue; return value; } }).property('foo')); set(obj, 'plusOne', 1); strictEqual(receivedOldValue, undefined, 'oldValue should be undefined'); set(obj, 'plusOne', 2); strictEqual(receivedOldValue, 1, 'oldValue should be 1'); set(obj, 'plusOne', 3); strictEqual(receivedOldValue, 2, 'oldValue should be 2'); }); // .......................................................... // DEPENDENT KEYS // QUnit.module('computed - dependentkey', { setup: function () { obj = { bar: 'baz' }; count = 0; var getterAndSetter = function () { count++; (0, _emberMetal.get)(this, 'bar'); return 'bar ' + count; }; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({ get: getterAndSetter, set: getterAndSetter }).property('bar')); }, teardown: function () { obj = count = null; } }); (0, _internalTestHelpers.testBoth)('should lazily watch dependent keys on set', function (get, set) { equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key'); set(obj, 'foo', 'bar'); equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily watching dependent key'); }); (0, _internalTestHelpers.testBoth)('should lazily watch dependent keys on get', function (get) { equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key'); get(obj, 'foo'); equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily watching dependent key'); }); (0, _internalTestHelpers.testBoth)('local dependent key should invalidate cache', function (get, set) { equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key'); equal(get(obj, 'foo'), 'bar 1', 'get once'); equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily setup watching dependent key'); equal(get(obj, 'foo'), 'bar 1', 'cached retrieve'); set(obj, 'bar', 'BIFF'); // should invalidate foo equal(get(obj, 'foo'), 'bar 2', 'should recache'); equal(get(obj, 'foo'), 'bar 2', 'cached retrieve'); }); (0, _internalTestHelpers.testBoth)('should invalidate multiple nested dependent keys', function (get, set) { var count = 0; (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)(function () { count++; get(this, 'baz'); return 'baz ' + count; }).property('baz')); equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key'); equal((0, _emberMetal.isWatching)(obj, 'baz'), false, 'precond not watching dependent key'); equal(get(obj, 'foo'), 'bar 1', 'get once'); equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily setup watching dependent key'); equal((0, _emberMetal.isWatching)(obj, 'baz'), true, 'lazily setup watching dependent key'); equal(get(obj, 'foo'), 'bar 1', 'cached retrieve'); set(obj, 'baz', 'BIFF'); // should invalidate bar -> foo equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'should not be watching dependent key after cache cleared'); equal((0, _emberMetal.isWatching)(obj, 'baz'), false, 'should not be watching dependent key after cache cleared'); equal(get(obj, 'foo'), 'bar 2', 'should recache'); equal(get(obj, 'foo'), 'bar 2', 'cached retrieve'); equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily setup watching dependent key'); equal((0, _emberMetal.isWatching)(obj, 'baz'), true, 'lazily setup watching dependent key'); }); (0, _internalTestHelpers.testBoth)('circular keys should not blow up', function (get, set) { var func = function () { count++; return 'bar ' + count; }; (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)({ get: func, set: func }).property('foo')); (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () { count++; return 'foo ' + count; }).property('bar')); equal(get(obj, 'foo'), 'foo 1', 'get once'); equal(get(obj, 'foo'), 'foo 1', 'cached retrieve'); set(obj, 'bar', 'BIFF'); // should invalidate bar -> foo -> bar equal(get(obj, 'foo'), 'foo 3', 'should recache'); equal(get(obj, 'foo'), 'foo 3', 'cached retrieve'); }); (0, _internalTestHelpers.testBoth)('redefining a property should undo old dependent keys', function (get, set) { equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key'); equal(get(obj, 'foo'), 'bar 1'); equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily watching dependent key'); (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () { count++; return 'baz ' + count; }).property('baz')); equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'after redefining should not be watching dependent key'); equal(get(obj, 'foo'), 'baz 2'); set(obj, 'bar', 'BIFF'); // should not kill cache equal(get(obj, 'foo'), 'baz 2'); set(obj, 'baz', 'BOP'); equal(get(obj, 'foo'), 'baz 3'); }); (0, _internalTestHelpers.testBoth)('can watch multiple dependent keys specified declaratively via brace expansion', function (get, set) { (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () { count++; return 'foo ' + count; }).property('qux.{bar,baz}')); equal(get(obj, 'foo'), 'foo 1', 'get once'); equal(get(obj, 'foo'), 'foo 1', 'cached retrieve'); set(obj, 'qux', {}); set(obj, 'qux.bar', 'bar'); // invalidate foo equal(get(obj, 'foo'), 'foo 2', 'foo invalidated from bar'); set(obj, 'qux.baz', 'baz'); // invalidate foo equal(get(obj, 'foo'), 'foo 3', 'foo invalidated from baz'); set(obj, 'qux.quux', 'quux'); // do not invalidate foo equal(get(obj, 'foo'), 'foo 3', 'foo not invalidated by quux'); }); (0, _internalTestHelpers.testBoth)('throws assertion if brace expansion notation has spaces', function () { expectAssertion(function () { (0, _emberMetal.defineProperty)(obj, 'roo', (0, _emberMetal.computed)(function () { count++; return 'roo ' + count; }).property('fee.{bar, baz,bop , }')); }, /cannot contain spaces/); }); // .......................................................... // CHAINED DEPENDENT KEYS // var func = void 0; QUnit.module('computed - dependentkey with chained properties', { setup: function () { obj = { foo: { bar: { baz: { biff: 'BIFF' } } } }; count = 0; func = function () { count++; return (0, _emberMetal.get)(obj, 'foo.bar.baz.biff') + ' ' + count; }; }, teardown: function () { obj = count = func = null; } }); (0, _internalTestHelpers.testBoth)('depending on simple chain', function (get, set) { // assign computed property (0, _emberMetal.defineProperty)(obj, 'prop', (0, _emberMetal.computed)(func).property('foo.bar.baz.biff')); equal(get(obj, 'prop'), 'BIFF 1'); set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ'); equal(get(obj, 'prop'), 'BUZZ 2'); equal(get(obj, 'prop'), 'BUZZ 2'); set(get(obj, 'foo.bar'), 'baz', { biff: 'BLOB' }); equal(get(obj, 'prop'), 'BLOB 3'); equal(get(obj, 'prop'), 'BLOB 3'); set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ'); equal(get(obj, 'prop'), 'BUZZ 4'); equal(get(obj, 'prop'), 'BUZZ 4'); set(get(obj, 'foo'), 'bar', { baz: { biff: 'BOOM' } }); equal(get(obj, 'prop'), 'BOOM 5'); equal(get(obj, 'prop'), 'BOOM 5'); set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ'); equal(get(obj, 'prop'), 'BUZZ 6'); equal(get(obj, 'prop'), 'BUZZ 6'); set(obj, 'foo', { bar: { baz: { biff: 'BLARG' } } }); equal(get(obj, 'prop'), 'BLARG 7'); equal(get(obj, 'prop'), 'BLARG 7'); set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ'); equal(get(obj, 'prop'), 'BUZZ 8'); equal(get(obj, 'prop'), 'BUZZ 8'); (0, _emberMetal.defineProperty)(obj, 'prop'); set(obj, 'prop', 'NONE'); equal(get(obj, 'prop'), 'NONE'); set(obj, 'foo', { bar: { baz: { biff: 'BLARG' } } }); equal(get(obj, 'prop'), 'NONE'); // should do nothing equal(count, 8, 'should be not have invoked computed again'); }); (0, _internalTestHelpers.testBoth)('chained dependent keys should evaluate computed properties lazily', function () { (0, _emberMetal.defineProperty)(obj.foo.bar, 'b', (0, _emberMetal.computed)(func)); (0, _emberMetal.defineProperty)(obj.foo, 'c', (0, _emberMetal.computed)(function () {}).property('bar.b')); equal(count, 0, 'b should not run'); }); // .......................................................... // improved-cp-syntax // QUnit.module('computed - improved cp syntax'); QUnit.test('setter and getters are passed using an object', function () { var testObj = _emberRuntime.Object.extend({ a: '1', b: '2', aInt: (0, _emberMetal.computed)('a', { get: function (keyName) { equal(keyName, 'aInt', 'getter receives the keyName'); return parseInt(this.get('a')); }, set: function (keyName, value, oldValue) { equal(keyName, 'aInt', 'setter receives the keyName'); equal(value, 123, 'setter receives the new value'); equal(oldValue, 1, 'setter receives the old value'); this.set('a', '' + value); // side effect return parseInt(this.get('a')); } }) }).create(); ok(testObj.get('aInt') === 1, 'getter works'); testObj.set('aInt', 123); ok(testObj.get('a') === '123', 'setter works'); ok(testObj.get('aInt') === 123, 'cp has been updated too'); }); QUnit.test('setter can be omited', function () { var testObj = _emberRuntime.Object.extend({ a: '1', b: '2', aInt: (0, _emberMetal.computed)('a', { get: function (keyName) { equal(keyName, 'aInt', 'getter receives the keyName'); return parseInt(this.get('a')); } }) }).create(); ok(testObj.get('aInt') === 1, 'getter works'); ok(testObj.get('a') === '1'); testObj.set('aInt', '123'); ok(testObj.get('aInt') === '123', 'cp has been updated too'); }); QUnit.test('the return value of the setter gets cached', function () { var testObj = _emberRuntime.Object.extend({ a: '1', sampleCP: (0, _emberMetal.computed)('a', { get: function () { ok(false, 'The getter should not be invoked'); return 'get-value'; }, set: function () { return 'set-value'; } }) }).create(); testObj.set('sampleCP', 'abcd'); ok(testObj.get('sampleCP') === 'set-value', 'The return value of the CP was cached'); }); // .......................................................... // BUGS // QUnit.module('computed edge cases'); QUnit.test('adding a computed property should show up in key iteration', function () { var obj = {}; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {})); var found = []; for (var key in obj) { found.push(key); } ok(found.indexOf('foo') >= 0, 'should find computed property in iteration found=' + found); ok('foo' in obj, 'foo in obj should pass'); }); (0, _internalTestHelpers.testBoth)('when setting a value after it had been retrieved empty don\'t pass function UNDEFINED as oldValue', function (get, set) { var obj = {}; var oldValueIsNoFunction = true; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({ get: function () {}, set: function (key, value, oldValue) { if (typeof oldValue === 'function') { oldValueIsNoFunction = false; } return undefined; } })); get(obj, 'foo'); set(obj, 'foo', undefined); ok(oldValueIsNoFunction); }); QUnit.module('computed - setter'); (0, _internalTestHelpers.testBoth)('setting a watched computed property', function (get, set) { var obj = { firstName: 'Yehuda', lastName: 'Katz' }; (0, _emberMetal.defineProperty)(obj, 'fullName', (0, _emberMetal.computed)({ get: function () { return get(this, 'firstName') + ' ' + get(this, 'lastName'); }, set: function (key, value) { var values = value.split(' '); set(this, 'firstName', values[0]); set(this, 'lastName', values[1]); return value; } }).property('firstName', 'lastName')); var fullNameWillChange = 0; var fullNameDidChange = 0; var firstNameWillChange = 0; var firstNameDidChange = 0; var lastNameWillChange = 0; var lastNameDidChange = 0; (0, _emberMetal._addBeforeObserver)(obj, 'fullName', function () { fullNameWillChange++; }); (0, _emberMetal.addObserver)(obj, 'fullName', function () { fullNameDidChange++; }); (0, _emberMetal._addBeforeObserver)(obj, 'firstName', function () { firstNameWillChange++; }); (0, _emberMetal.addObserver)(obj, 'firstName', function () { firstNameDidChange++; }); (0, _emberMetal._addBeforeObserver)(obj, 'lastName', function () { lastNameWillChange++; }); (0, _emberMetal.addObserver)(obj, 'lastName', function () { lastNameDidChange++; }); equal(get(obj, 'fullName'), 'Yehuda Katz'); set(obj, 'fullName', 'Yehuda Katz'); set(obj, 'fullName', 'Kris Selden'); equal(get(obj, 'fullName'), 'Kris Selden'); equal(get(obj, 'firstName'), 'Kris'); equal(get(obj, 'lastName'), 'Selden'); equal(fullNameWillChange, 1); equal(fullNameDidChange, 1); equal(firstNameWillChange, 1); equal(firstNameDidChange, 1); equal(lastNameWillChange, 1); equal(lastNameDidChange, 1); }); (0, _internalTestHelpers.testBoth)('setting a cached computed property that modifies the value you give it', function (get, set) { var obj = { foo: 0 }; (0, _emberMetal.defineProperty)(obj, 'plusOne', (0, _emberMetal.computed)({ get: function () { return get(this, 'foo') + 1; }, set: function (key, value) { set(this, 'foo', value); return value + 1; } }).property('foo')); var plusOneWillChange = 0; var plusOneDidChange = 0; (0, _emberMetal._addBeforeObserver)(obj, 'plusOne', function () { plusOneWillChange++; }); (0, _emberMetal.addObserver)(obj, 'plusOne', function () { plusOneDidChange++; }); equal(get(obj, 'plusOne'), 1); set(obj, 'plusOne', 1); equal(get(obj, 'plusOne'), 2); set(obj, 'plusOne', 1); equal(get(obj, 'plusOne'), 2); equal(plusOneWillChange, 1); equal(plusOneDidChange, 1); set(obj, 'foo', 5); equal(get(obj, 'plusOne'), 6); equal(plusOneWillChange, 2); equal(plusOneDidChange, 2); }); QUnit.module('computed - default setter'); (0, _internalTestHelpers.testBoth)('when setting a value on a computed property that doesn\'t handle sets', function (get, set) { var obj = {}; var observerFired = false; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () { return 'foo'; })); (0, _emberMetal.addObserver)(obj, 'foo', null, function () { return observerFired = true; }); set(obj, 'foo', 'bar'); equal(get(obj, 'foo'), 'bar', 'The set value is properly returned'); ok(typeof obj.foo === 'string', 'The computed property was removed'); ok(observerFired, 'The observer was still notified'); }); QUnit.module('computed - readOnly'); QUnit.test('is chainable', function () { var cp = (0, _emberMetal.computed)(function () {}).readOnly(); ok(cp instanceof _emberMetal.Descriptor); ok(cp instanceof _emberMetal.ComputedProperty); }); QUnit.test('throws assertion if called over a CP with a setter defined with the new syntax', function () { expectAssertion(function () { (0, _emberMetal.computed)({ get: function () {}, set: function () {} }).readOnly(); }, /Computed properties that define a setter using the new syntax cannot be read-only/); }); (0, _internalTestHelpers.testBoth)('protects against setting', function (get, set) { var obj = {}; (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)(function () { return 'barValue'; }).readOnly()); equal(get(obj, 'bar'), 'barValue'); throws(function () { set(obj, 'bar', 'newBar'); }, /Cannot set read\-only property "bar" on object:/); equal(get(obj, 'bar'), 'barValue'); }); }); enifed('ember-metal/tests/descriptor_test', ['ember-babel', 'ember-runtime', 'ember-metal'], function (_emberBabel, _emberRuntime, _emberMetal) { 'use strict'; // IE9 soft-fails when trying to delete a non-configurable property var hasCompliantDelete = function () { var obj = {}; Object.defineProperty(obj, 'zomg', { configurable: false, value: 'zomg' }); try { delete obj.zomg; } catch (e) { return true; } return false; }(); // IE9 soft-fails when trying to assign to a non-writable property var hasCompliantAssign = function () { var obj = {}; Object.defineProperty(obj, 'zomg', { writable: false, value: 'zomg' }); try { obj.zomg = 'lol'; } catch (e) { return true; } return false; }(); var DescriptorTest = function () { DescriptorTest.test = function (title, callback) { var _this = this; QUnit.test(title, function (assert) { callback(assert, new _this(assert)); }); }; function DescriptorTest(assert) { this.assert = assert; } /* abstract install(key: string, desc: Descriptor); */ /* abstract set(key: string, value: any); */ /* abstract finalize(): Object; */ return DescriptorTest; }(); var classes = [function (_DescriptorTest) { (0, _emberBabel.inherits)(_class, _DescriptorTest); _class.module = function (title) { QUnit.module(title + ': using defineProperty on an object directly'); }; function _class(assert) { var _this2 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest.call(this, assert)); _this2.object = {}; return _this2; } _class.prototype.install = function (key, desc) { var object = this.object, assert = this.assert; (0, _emberMetal.defineProperty)(object, key, desc); assert.ok(object.hasOwnProperty(key)); }; _class.prototype.set = function (key, value) { this.object[key] = value; }; _class.prototype.finalize = function () { return this.object; }; _class.prototype.source = function () { return this.object; }; return _class; }(DescriptorTest), function (_DescriptorTest2) { (0, _emberBabel.inherits)(_class2, _DescriptorTest2); _class2.module = function (title) { QUnit.module(title + ': using defineProperty on a prototype'); }; function _class2(assert) { var _this3 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest2.call(this, assert)); _this3.proto = {}; return _this3; } _class2.prototype.install = function (key, desc) { var proto = this.proto, assert = this.assert; (0, _emberMetal.defineProperty)(proto, key, desc); assert.ok(proto.hasOwnProperty(key)); }; _class2.prototype.set = function (key, value) { this.proto[key] = value; }; _class2.prototype.finalize = function () { return Object.create(this.proto); }; _class2.prototype.source = function () { return this.proto; }; return _class2; }(DescriptorTest), function (_DescriptorTest3) { (0, _emberBabel.inherits)(_class3, _DescriptorTest3); _class3.module = function (title) { QUnit.module(title + ': in EmberObject.extend()'); }; function _class3(assert) { var _this4 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest3.call(this, assert)); _this4.klass = null; _this4.props = {}; return _this4; } _class3.prototype.install = function (key, desc) { this.props[key] = desc; }; _class3.prototype.set = function (key, value) { this.props[key] = value; }; _class3.prototype.finalize = function () { this.klass = _emberRuntime.Object.extend(this.props); return this.klass.create(); }; _class3.prototype.source = function () { return this.klass.prototype; }; return _class3; }(DescriptorTest), function (_DescriptorTest4) { (0, _emberBabel.inherits)(_class4, _DescriptorTest4); _class4.module = function (title) { QUnit.module(title + ': in EmberObject.extend() through a mixin'); }; function _class4(assert) { var _this5 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest4.call(this, assert)); _this5.klass = null; _this5.props = {}; return _this5; } _class4.prototype.install = function (key, desc) { this.props[key] = desc; }; _class4.prototype.set = function (key, value) { this.props[key] = value; }; _class4.prototype.finalize = function () { this.klass = _emberRuntime.Object.extend(_emberMetal.Mixin.create(this.props)); return this.klass.create(); }; _class4.prototype.source = function () { return this.klass.prototype; }; return _class4; }(DescriptorTest), function (_DescriptorTest5) { (0, _emberBabel.inherits)(_class5, _DescriptorTest5); _class5.module = function (title) { QUnit.module(title + ': inherited from another EmberObject super class'); }; function _class5(assert) { var _this6 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest5.call(this, assert)); _this6.superklass = null; _this6.props = {}; return _this6; } _class5.prototype.install = function (key, desc) { this.props[key] = desc; }; _class5.prototype.set = function (key, value) { this.props[key] = value; }; _class5.prototype.finalize = function () { this.superklass = _emberRuntime.Object.extend(this.props); return this.superklass.extend().create(); }; _class5.prototype.source = function () { return this.superklass.prototype; }; return _class5; }(DescriptorTest)]; classes.forEach(function (TestClass) { TestClass.module('ember-metal/descriptor'); TestClass.test('defining a configurable property', function (assert, factory) { factory.install('foo', (0, _emberMetal.descriptor)({ configurable: true, value: 'bar' })); var obj = factory.finalize(); assert.equal(obj.foo, 'bar'); var source = factory.source(); delete source.foo; assert.strictEqual(obj.foo, undefined); Object.defineProperty(source, 'foo', { configurable: true, value: 'baz' }); assert.equal(obj.foo, 'baz'); }); TestClass.test('defining a non-configurable property', function (assert, factory) { factory.install('foo', (0, _emberMetal.descriptor)({ configurable: false, value: 'bar' })); var obj = factory.finalize(); assert.equal(obj.foo, 'bar'); var source = factory.source(); if (hasCompliantDelete) { assert.throws(function () { return delete source.foo; }, TypeError); } else { delete source.foo; } assert.throws(function () { return Object.defineProperty(source, 'foo', { configurable: true, value: 'baz' }); }, TypeError); assert.equal(obj.foo, 'bar'); }); TestClass.test('defining an enumerable property', function (assert, factory) { factory.install('foo', (0, _emberMetal.descriptor)({ enumerable: true, value: 'bar' })); var obj = factory.finalize(); assert.equal(obj.foo, 'bar'); var source = factory.source(); assert.ok(Object.keys(source).indexOf('foo') !== -1); }); TestClass.test('defining a non-enumerable property', function (assert, factory) { factory.install('foo', (0, _emberMetal.descriptor)({ enumerable: false, value: 'bar' })); var obj = factory.finalize(); assert.equal(obj.foo, 'bar'); var source = factory.source(); assert.ok(Object.keys(source).indexOf('foo') === -1); }); TestClass.test('defining a writable property', function (assert, factory) { factory.install('foo', (0, _emberMetal.descriptor)({ writable: true, value: 'bar' })); var obj = factory.finalize(); assert.equal(obj.foo, 'bar'); var source = factory.source(); source.foo = 'baz'; assert.equal(obj.foo, 'baz'); obj.foo = 'bat'; assert.equal(obj.foo, 'bat'); }); TestClass.test('defining a non-writable property', function (assert, factory) { factory.install('foo', (0, _emberMetal.descriptor)({ writable: false, value: 'bar' })); var obj = factory.finalize(); assert.equal(obj.foo, 'bar'); var source = factory.source(); if (hasCompliantAssign) { assert.throws(function () { return source.foo = 'baz'; }, TypeError); assert.throws(function () { return obj.foo = 'baz'; }, TypeError); } else { source.foo = 'baz'; obj.foo = 'baz'; } assert.equal(obj.foo, 'bar'); }); TestClass.test('defining a getter', function (assert, factory) { factory.install('foo', (0, _emberMetal.descriptor)({ get: function () { return this.__foo__; } })); factory.set('__foo__', 'bar'); var obj = factory.finalize(); assert.equal(obj.foo, 'bar'); obj.__foo__ = 'baz'; assert.equal(obj.foo, 'baz'); }); TestClass.test('defining a setter', function (assert, factory) { factory.install('foo', (0, _emberMetal.descriptor)({ set: function (value) { this.__foo__ = value; } })); factory.set('__foo__', 'bar'); var obj = factory.finalize(); assert.equal(obj.__foo__, 'bar'); obj.foo = 'baz'; assert.equal(obj.__foo__, 'baz'); }); TestClass.test('combining multiple setter and getters', function (assert, factory) { factory.install('foo', (0, _emberMetal.descriptor)({ get: function () { return this.__foo__; }, set: function (value) { this.__foo__ = value; } })); factory.set('__foo__', 'foo'); factory.install('bar', (0, _emberMetal.descriptor)({ get: function () { return this.__bar__; }, set: function (value) { this.__bar__ = value; } })); factory.set('__bar__', 'bar'); factory.install('fooBar', (0, _emberMetal.descriptor)({ get: function () { return this.foo + '-' + this.bar; } })); var obj = factory.finalize(); assert.equal(obj.fooBar, 'foo-bar'); obj.foo = 'FOO'; assert.equal(obj.fooBar, 'FOO-bar'); obj.__bar__ = 'BAR'; assert.equal(obj.fooBar, 'FOO-BAR'); if (hasCompliantAssign) { assert.throws(function () { return obj.fooBar = 'foobar'; }, TypeError); } else { obj.fooBar = 'foobar'; } assert.equal(obj.fooBar, 'FOO-BAR'); }); }); }); enifed('ember-metal/tests/events_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('system/props/events_test'); QUnit.test('listener should receive event - removing should remove', function () { var obj = {}; var count = 0; function F() { count++; } (0, _emberMetal.addListener)(obj, 'event!', F); equal(count, 0, 'nothing yet'); (0, _emberMetal.sendEvent)(obj, 'event!'); equal(count, 1, 'received event'); (0, _emberMetal.removeListener)(obj, 'event!', F); count = 0; (0, _emberMetal.sendEvent)(obj, 'event!'); equal(count, 0, 'received event'); }); QUnit.test('listeners should be inherited', function () { var obj = {}; var count = 0; var F = function () { count++; }; (0, _emberMetal.addListener)(obj, 'event!', F); var obj2 = Object.create(obj); equal(count, 0, 'nothing yet'); (0, _emberMetal.sendEvent)(obj2, 'event!'); equal(count, 1, 'received event'); (0, _emberMetal.removeListener)(obj2, 'event!', F); count = 0; (0, _emberMetal.sendEvent)(obj2, 'event!'); equal(count, 0, 'did not receive event'); (0, _emberMetal.sendEvent)(obj, 'event!'); equal(count, 1, 'should still invoke on parent'); }); QUnit.test('adding a listener more than once should only invoke once', function () { var obj = {}; var count = 0; function F() { count++; } (0, _emberMetal.addListener)(obj, 'event!', F); (0, _emberMetal.addListener)(obj, 'event!', F); (0, _emberMetal.sendEvent)(obj, 'event!'); equal(count, 1, 'should only invoke once'); }); QUnit.test('adding a listener with a target should invoke with target', function () { var obj = {}; var target = void 0; target = { count: 0, method: function () { this.count++; } }; (0, _emberMetal.addListener)(obj, 'event!', target, target.method); (0, _emberMetal.sendEvent)(obj, 'event!'); equal(target.count, 1, 'should invoke'); }); QUnit.test('suspending a listener should not invoke during callback', function () { var obj = {}; var target = void 0, otherTarget = void 0; target = { count: 0, method: function () { this.count++; } }; otherTarget = { count: 0, method: function () { this.count++; } }; (0, _emberMetal.addListener)(obj, 'event!', target, target.method); (0, _emberMetal.addListener)(obj, 'event!', otherTarget, otherTarget.method); (0, _emberMetal.sendEvent)(obj, 'event!'); equal((0, _emberMetal.suspendListener)(obj, 'event!', target, target.method, function () { /*jshint validthis:true */ equal(this, target); (0, _emberMetal.sendEvent)(obj, 'event!'); return 'result'; }), 'result'); (0, _emberMetal.sendEvent)(obj, 'event!'); equal(target.count, 2, 'should invoke'); equal(otherTarget.count, 3, 'should invoke'); }); QUnit.test('adding a listener with string method should lookup method on event delivery', function () { var obj = {}; var target = void 0; target = { count: 0, method: function () {} }; (0, _emberMetal.addListener)(obj, 'event!', target, 'method'); (0, _emberMetal.sendEvent)(obj, 'event!'); equal(target.count, 0, 'should invoke but do nothing'); target.method = function () { this.count++; }; (0, _emberMetal.sendEvent)(obj, 'event!'); equal(target.count, 1, 'should invoke now'); }); QUnit.test('calling sendEvent with extra params should be passed to listeners', function () { var obj = {}; var params = null; (0, _emberMetal.addListener)(obj, 'event!', function () { params = Array.prototype.slice.call(arguments); }); (0, _emberMetal.sendEvent)(obj, 'event!', ['foo', 'bar']); deepEqual(params, ['foo', 'bar'], 'params should be saved'); }); QUnit.test('hasListeners tells you if there are listeners for a given event', function () { var obj = {}; function F() {} function F2() {} equal((0, _emberMetal.hasListeners)(obj, 'event!'), false, 'no listeners at first'); (0, _emberMetal.addListener)(obj, 'event!', F); (0, _emberMetal.addListener)(obj, 'event!', F2); equal((0, _emberMetal.hasListeners)(obj, 'event!'), true, 'has listeners'); (0, _emberMetal.removeListener)(obj, 'event!', F); equal((0, _emberMetal.hasListeners)(obj, 'event!'), true, 'has listeners'); (0, _emberMetal.removeListener)(obj, 'event!', F2); equal((0, _emberMetal.hasListeners)(obj, 'event!'), false, 'has no more listeners'); (0, _emberMetal.addListener)(obj, 'event!', F); equal((0, _emberMetal.hasListeners)(obj, 'event!'), true, 'has listeners'); }); QUnit.test('calling removeListener without method should remove all listeners', function () { var obj = {}; equal((0, _emberMetal.hasListeners)(obj, 'event!'), false, 'no listeners at first'); (0, _emberMetal.addListener)(obj, 'event!', function () {}); (0, _emberMetal.addListener)(obj, 'event!', function () {}); equal((0, _emberMetal.hasListeners)(obj, 'event!'), true, 'has listeners'); (0, _emberMetal.removeListener)(obj, 'event!'); equal((0, _emberMetal.hasListeners)(obj, 'event!'), false, 'has no more listeners'); }); QUnit.test('while suspended, it should not be possible to add a duplicate listener', function () { var obj = {}; var target = void 0; target = { count: 0, method: function () { this.count++; } }; (0, _emberMetal.addListener)(obj, 'event!', target, target.method); function callback() { (0, _emberMetal.addListener)(obj, 'event!', target, target.method); } (0, _emberMetal.sendEvent)(obj, 'event!'); (0, _emberMetal.suspendListener)(obj, 'event!', target, target.method, callback); equal(target.count, 1, 'should invoke'); equal((0, _emberMetal.meta)(obj).matchingListeners('event!').length, 3, 'a duplicate listener wasn\'t added'); // now test suspendListeners... (0, _emberMetal.sendEvent)(obj, 'event!'); (0, _emberMetal.suspendListeners)(obj, ['event!'], target, target.method, callback); equal(target.count, 2, 'should have invoked again'); equal((0, _emberMetal.meta)(obj).matchingListeners('event!').length, 3, 'a duplicate listener wasn\'t added'); }); QUnit.test('a listener can be added as part of a mixin', function () { var triggered = 0; var MyMixin = _emberMetal.Mixin.create({ foo1: (0, _emberMetal.on)('bar', function () { triggered++; }), foo2: (0, _emberMetal.on)('bar', function () { triggered++; }) }); var obj = {}; MyMixin.apply(obj); (0, _emberMetal.sendEvent)(obj, 'bar'); equal(triggered, 2, 'should invoke listeners'); }); QUnit.test('a listener added as part of a mixin may be overridden', function () { var triggered = 0; var FirstMixin = _emberMetal.Mixin.create({ foo: (0, _emberMetal.on)('bar', function () { triggered++; }) }); var SecondMixin = _emberMetal.Mixin.create({ foo: (0, _emberMetal.on)('baz', function () { triggered++; }) }); var obj = {}; FirstMixin.apply(obj); SecondMixin.apply(obj); (0, _emberMetal.sendEvent)(obj, 'bar'); equal(triggered, 0, 'should not invoke from overriden property'); (0, _emberMetal.sendEvent)(obj, 'baz'); equal(triggered, 1, 'should invoke from subclass property'); }); }); enifed('ember-metal/tests/expand_properties_test', ['ember-metal'], function (_emberMetal) { 'use strict'; var foundProperties = []; function addProperty(property) { foundProperties.push(property); } QUnit.module('Property Brace Expansion Test', { setup: function () { foundProperties = []; } }); QUnit.test('Properties without expansions are unaffected', function () { expect(1); (0, _emberMetal.expandProperties)('a', addProperty); (0, _emberMetal.expandProperties)('a.b', addProperty); (0, _emberMetal.expandProperties)('a.b.[]', addProperty); (0, _emberMetal.expandProperties)('a.b.@each.c', addProperty); deepEqual(['a', 'a.b', 'a.b.[]', 'a.b.@each.c'].sort(), foundProperties.sort()); }); QUnit.test('A single expansion at the end expands properly', function () { expect(1); (0, _emberMetal.expandProperties)('a.b.{c,d}', addProperty); deepEqual(['a.b.c', 'a.b.d'].sort(), foundProperties.sort()); }); QUnit.test('A property with only a brace expansion expands correctly', function () { expect(1); (0, _emberMetal.expandProperties)('{a,b,c}', addProperty); deepEqual(['a', 'b', 'c'].sort(), foundProperties.sort()); }); QUnit.test('Expansions with single properties only expand once', function () { expect(1); (0, _emberMetal.expandProperties)('a.b.{c}.d.{e}', addProperty); deepEqual(['a.b.c.d.e'], foundProperties); }); QUnit.test('A single brace expansion expands correctly', function () { expect(1); (0, _emberMetal.expandProperties)('a.{b,c,d}.e', addProperty); deepEqual(['a.b.e', 'a.c.e', 'a.d.e'].sort(), foundProperties.sort()); }); QUnit.test('Multiple brace expansions work correctly', function () { expect(1); (0, _emberMetal.expandProperties)('{a,b,c}.d.{e,f}.g', addProperty); deepEqual(['a.d.e.g', 'a.d.f.g', 'b.d.e.g', 'b.d.f.g', 'c.d.e.g', 'c.d.f.g'].sort(), foundProperties.sort()); }); QUnit.test('A property with only brace expansions expands correctly', function () { expect(1); (0, _emberMetal.expandProperties)('{a,b,c}.{d}.{e,f}', addProperty); deepEqual(['a.d.e', 'a.d.f', 'b.d.e', 'b.d.f', 'c.d.e', 'c.d.f'].sort(), foundProperties.sort()); }); QUnit.test('Nested brace expansions are not allowed', function () { ['a.{b.{c,d}}', 'a.{{b}.c}', 'a.{b,c}.{d.{e,f}.g', 'a.{b.{c}', 'a.{b,c}}'].forEach(function (invalidProperties) { expectAssertion(function () { return (0, _emberMetal.expandProperties)(invalidProperties, addProperty); }); }, /Brace expanded properties have to be balanced and cannot be nested/); }); QUnit.test('A property with no braces does not expand', function () { expect(1); (0, _emberMetal.expandProperties)('a,b,c.d.e,f', addProperty); deepEqual(foundProperties, ['a,b,c.d.e,f']); }); QUnit.test('A pattern must be a string', function () { expect(1); expectAssertion(function () { (0, _emberMetal.expandProperties)([1, 2], addProperty); }, /A computed property key must be a string/); }); QUnit.test('A pattern must not contain a space', function () { expect(1); expectAssertion(function () { (0, _emberMetal.expandProperties)('{a, b}', addProperty); }, /Brace expanded properties cannot contain spaces, e.g. "user.{firstName, lastName}" should be "user.{firstName,lastName}"/); }); }); enifed('ember-metal/tests/injected_property_test', ['ember-utils', 'ember-metal'], function (_emberUtils, _emberMetal) { 'use strict'; QUnit.module('InjectedProperty'); QUnit.test('injected properties should be descriptors', function () { ok(new _emberMetal.InjectedProperty() instanceof _emberMetal.Descriptor); }); QUnit.test('injected properties should be overridable', function () { var obj = {}; (0, _emberMetal.defineProperty)(obj, 'foo', new _emberMetal.InjectedProperty()); (0, _emberMetal.set)(obj, 'foo', 'bar'); equal((0, _emberMetal.get)(obj, 'foo'), 'bar', 'should return the overriden value'); }); QUnit.test('getting on an object without an owner or container should fail assertion', function () { var obj = {}; (0, _emberMetal.defineProperty)(obj, 'foo', new _emberMetal.InjectedProperty('type', 'name')); expectAssertion(function () { (0, _emberMetal.get)(obj, 'foo'); }, /Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container./); }); QUnit.test('getting on an object without an owner but with a container should not fail', function () { var obj = { container: { lookup: function (key) { ok(true, 'should call container.lookup'); return key; } } }; (0, _emberMetal.defineProperty)(obj, 'foo', new _emberMetal.InjectedProperty('type', 'name')); equal((0, _emberMetal.get)(obj, 'foo'), 'type:name', 'should return the value of container.lookup'); }); QUnit.test('getting should return a lookup on the container', function () { expect(2); var obj = {}; (0, _emberUtils.setOwner)(obj, { lookup: function (key) { ok(true, 'should call container.lookup'); return key; } }); (0, _emberMetal.defineProperty)(obj, 'foo', new _emberMetal.InjectedProperty('type', 'name')); equal((0, _emberMetal.get)(obj, 'foo'), 'type:name', 'should return the value of container.lookup'); }); QUnit.test('omitting the lookup name should default to the property name', function () { var obj = {}; (0, _emberUtils.setOwner)(obj, { lookup: function (key) { return key; } }); (0, _emberMetal.defineProperty)(obj, 'foo', new _emberMetal.InjectedProperty('type')); equal((0, _emberMetal.get)(obj, 'foo'), 'type:foo', 'should lookup the type using the property name'); }); }); enifed('ember-metal/tests/instrumentation_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember Instrumentation', { teardown: function () { (0, _emberMetal.instrumentationReset)(); } }); QUnit.test('execute block even if no listeners', function () { var result = (0, _emberMetal.instrument)('render', {}, function () { return 'hello'; }); equal(result, 'hello', 'called block'); }); QUnit.test('subscribing to a simple path receives the listener', function () { expect(12); var sentPayload = {}; var count = 0; (0, _emberMetal.instrumentationSubscribe)('render', { before: function (name, timestamp, payload) { if (count === 0) { strictEqual(name, 'render'); } else { strictEqual(name, 'render.handlebars'); } ok(typeof timestamp === 'number'); strictEqual(payload, sentPayload); }, after: function (name, timestamp, payload) { if (count === 0) { strictEqual(name, 'render'); } else { strictEqual(name, 'render.handlebars'); } ok(typeof timestamp === 'number'); strictEqual(payload, sentPayload); count++; } }); (0, _emberMetal.instrument)('render', sentPayload, function () {}); (0, _emberMetal.instrument)('render.handlebars', sentPayload, function () {}); }); QUnit.test('returning a value from the before callback passes it to the after callback', function () { expect(2); var passthru1 = {}; var passthru2 = {}; (0, _emberMetal.instrumentationSubscribe)('render', { before: function () { return passthru1; }, after: function (name, timestamp, payload, beforeValue) { strictEqual(beforeValue, passthru1); } }); (0, _emberMetal.instrumentationSubscribe)('render', { before: function () { return passthru2; }, after: function (name, timestamp, payload, beforeValue) { strictEqual(beforeValue, passthru2); } }); (0, _emberMetal.instrument)('render', null, function () {}); }); QUnit.test('instrument with 2 args (name, callback) no payload', function () { expect(1); (0, _emberMetal.instrumentationSubscribe)('render', { before: function (name, timestamp, payload) { deepEqual(payload, {}); }, after: function () {} }); (0, _emberMetal.instrument)('render', function () {}); }); QUnit.test('instrument with 3 args (name, callback, binding) no payload', function () { expect(2); var binding = {}; (0, _emberMetal.instrumentationSubscribe)('render', { before: function (name, timestamp, payload) { deepEqual(payload, {}); }, after: function () {} }); (0, _emberMetal.instrument)('render', function () { deepEqual(this, binding); }, binding); }); QUnit.test('instrument with 3 args (name, payload, callback) with payload', function () { expect(1); var expectedPayload = { hi: 1 }; (0, _emberMetal.instrumentationSubscribe)('render', { before: function (name, timestamp, payload) { deepEqual(payload, expectedPayload); }, after: function () {} }); (0, _emberMetal.instrument)('render', expectedPayload, function () {}); }); QUnit.test('instrument with 4 args (name, payload, callback, binding) with payload', function () { expect(2); var expectedPayload = { hi: 1 }; var binding = {}; (0, _emberMetal.instrumentationSubscribe)('render', { before: function (name, timestamp, payload) { deepEqual(payload, expectedPayload); }, after: function () {} }); (0, _emberMetal.instrument)('render', expectedPayload, function () { deepEqual(this, binding); }, binding); }); QUnit.test('raising an exception in the instrumentation attaches it to the payload', function () { expect(2); var error = new Error('Instrumentation'); (0, _emberMetal.instrumentationSubscribe)('render', { before: function () {}, after: function (name, timestamp, payload) { strictEqual(payload.exception, error); } }); (0, _emberMetal.instrumentationSubscribe)('render', { before: function () {}, after: function (name, timestamp, payload) { strictEqual(payload.exception, error); } }); (0, _emberMetal.instrument)('render.handlebars', null, function () { throw error; }); }); QUnit.test('it is possible to add a new subscriber after the first instrument', function () { (0, _emberMetal.instrument)('render.handlebars', null, function () {}); (0, _emberMetal.instrumentationSubscribe)('render', { before: function () { ok(true, 'Before callback was called'); }, after: function () { ok(true, 'After callback was called'); } }); (0, _emberMetal.instrument)('render.handlebars', null, function () {}); }); QUnit.test('it is possible to remove a subscriber', function () { expect(4); var count = 0; var subscriber = (0, _emberMetal.instrumentationSubscribe)('render', { before: function () { equal(count, 0); ok(true, 'Before callback was called'); }, after: function () { equal(count, 0); ok(true, 'After callback was called'); count++; } }); (0, _emberMetal.instrument)('render.handlebars', null, function () {}); (0, _emberMetal.instrumentationUnsubscribe)(subscriber); (0, _emberMetal.instrument)('render.handlebars', null, function () {}); }); }); enifed('ember-metal/tests/is_blank_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember.isBlank'); QUnit.test('Ember.isBlank', function () { equal(true, (0, _emberMetal.isBlank)(null), 'for null'); equal(true, (0, _emberMetal.isBlank)(undefined), 'for undefined'); equal(true, (0, _emberMetal.isBlank)(''), 'for an empty String'); equal(true, (0, _emberMetal.isBlank)(' '), 'for a whitespace String'); equal(true, (0, _emberMetal.isBlank)('\n\t'), 'for another whitespace String'); equal(false, (0, _emberMetal.isBlank)('\n\t Hi'), 'for a String with whitespaces'); equal(false, (0, _emberMetal.isBlank)(true), 'for true'); equal(false, (0, _emberMetal.isBlank)(false), 'for false'); equal(false, (0, _emberMetal.isBlank)('string'), 'for a String'); equal(false, (0, _emberMetal.isBlank)(function () {}), 'for a Function'); equal(false, (0, _emberMetal.isBlank)(0), 'for 0'); equal(true, (0, _emberMetal.isBlank)([]), 'for an empty Array'); equal(false, (0, _emberMetal.isBlank)({}), 'for an empty Object'); equal(true, (0, _emberMetal.isBlank)({ length: 0 }), 'for an Object that has zero \'length\''); equal(false, (0, _emberMetal.isBlank)([1, 2, 3]), 'for a non-empty array'); }); }); enifed('ember-metal/tests/is_empty_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember.isEmpty'); QUnit.test('Ember.isEmpty', function () { equal(true, (0, _emberMetal.isEmpty)(null), 'for null'); equal(true, (0, _emberMetal.isEmpty)(undefined), 'for undefined'); equal(true, (0, _emberMetal.isEmpty)(''), 'for an empty String'); equal(false, (0, _emberMetal.isEmpty)(' '), 'for a whitespace String'); equal(false, (0, _emberMetal.isEmpty)('\n\t'), 'for another whitespace String'); equal(false, (0, _emberMetal.isEmpty)(true), 'for true'); equal(false, (0, _emberMetal.isEmpty)(false), 'for false'); equal(false, (0, _emberMetal.isEmpty)('string'), 'for a String'); equal(false, (0, _emberMetal.isEmpty)(function () {}), 'for a Function'); equal(false, (0, _emberMetal.isEmpty)(0), 'for 0'); equal(true, (0, _emberMetal.isEmpty)([]), 'for an empty Array'); equal(false, (0, _emberMetal.isEmpty)({}), 'for an empty Object'); equal(true, (0, _emberMetal.isEmpty)({ length: 0 }), 'for an Object that has zero \'length\''); }); QUnit.test('Ember.isEmpty Ember.Map', function () { var map = new _emberMetal.Map(); equal(true, (0, _emberMetal.isEmpty)(map), 'Empty map is empty'); map.set('foo', 'bar'); equal(false, (0, _emberMetal.isEmpty)(map), 'Map is not empty'); }); QUnit.test('Ember.isEmpty Ember.OrderedSet', function () { var orderedSet = new _emberMetal.OrderedSet(); equal(true, (0, _emberMetal.isEmpty)(orderedSet), 'Empty ordered set is empty'); orderedSet.add('foo'); equal(false, (0, _emberMetal.isEmpty)(orderedSet), 'Ordered set is not empty'); }); }); enifed('ember-metal/tests/is_none_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember.isNone'); QUnit.test('Ember.isNone', function () { equal(true, (0, _emberMetal.isNone)(null), 'for null'); equal(true, (0, _emberMetal.isNone)(undefined), 'for undefined'); equal(false, (0, _emberMetal.isNone)(''), 'for an empty String'); equal(false, (0, _emberMetal.isNone)(true), 'for true'); equal(false, (0, _emberMetal.isNone)(false), 'for false'); equal(false, (0, _emberMetal.isNone)('string'), 'for a String'); equal(false, (0, _emberMetal.isNone)(function () {}), 'for a Function'); equal(false, (0, _emberMetal.isNone)(0), 'for 0'); equal(false, (0, _emberMetal.isNone)([]), 'for an empty Array'); equal(false, (0, _emberMetal.isNone)({}), 'for an empty Object'); }); }); enifed('ember-metal/tests/is_present_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember.isPresent'); QUnit.test('Ember.isPresent', function () { equal(false, (0, _emberMetal.isPresent)(), 'for no params'); equal(false, (0, _emberMetal.isPresent)(null), 'for null'); equal(false, (0, _emberMetal.isPresent)(undefined), 'for undefined'); equal(false, (0, _emberMetal.isPresent)(''), 'for an empty String'); equal(false, (0, _emberMetal.isPresent)(' '), 'for a whitespace String'); equal(false, (0, _emberMetal.isPresent)('\n\t'), 'for another whitespace String'); equal(true, (0, _emberMetal.isPresent)('\n\t Hi'), 'for a String with whitespaces'); equal(true, (0, _emberMetal.isPresent)(true), 'for true'); equal(true, (0, _emberMetal.isPresent)(false), 'for false'); equal(true, (0, _emberMetal.isPresent)('string'), 'for a String'); equal(true, (0, _emberMetal.isPresent)(function () {}), 'for a Function'); equal(true, (0, _emberMetal.isPresent)(0), 'for 0'); equal(false, (0, _emberMetal.isPresent)([]), 'for an empty Array'); equal(true, (0, _emberMetal.isPresent)({}), 'for an empty Object'); equal(false, (0, _emberMetal.isPresent)({ length: 0 }), 'for an Object that has zero \'length\''); equal(true, (0, _emberMetal.isPresent)([1, 2, 3]), 'for a non-empty array'); }); }); enifed('ember-metal/tests/libraries_test', ['ember-debug', 'ember-metal'], function (_emberDebug, _emberMetal) { 'use strict'; /* globals EmberDev */ var libs = void 0, registry = void 0; var originalWarn = (0, _emberDebug.getDebugFunction)('warn'); QUnit.module('Libraries registry', { setup: function () { libs = new _emberMetal.Libraries(); registry = libs._registry; }, teardown: function () { libs = null; registry = null; (0, _emberDebug.setDebugFunction)('warn', originalWarn); } }); QUnit.test('core libraries come before other libraries', function () { expect(2); libs.register('my-lib', '2.0.0a'); libs.registerCoreLibrary('DS', '1.0.0-beta.2'); equal(registry[0].name, 'DS'); equal(registry[1].name, 'my-lib'); }); QUnit.test('only the first registration of a library is stored', function () { expect(3); libs.register('magic', 1.23); libs.register('magic', 2.23); equal(registry[0].name, 'magic'); equal(registry[0].version, 1.23); equal(registry.length, 1); }); QUnit.test('attempting to register a library that is already registered warns you', function () { if (EmberDev && EmberDev.runningProdBuild) { ok(true, 'Logging does not occur in production builds'); return; } expect(1); libs.register('magic', 1.23); (0, _emberDebug.setDebugFunction)('warn', function (msg, test) { if (!test) { equal(msg, 'Library "magic" is already registered with Ember.'); } }); // Should warn us libs.register('magic', 2.23); }); QUnit.test('libraries can be de-registered', function () { expect(2); libs.register('lib1', '1.0.0b'); libs.register('lib2', '1.0.0b'); libs.register('lib3', '1.0.0b'); libs.deRegister('lib1'); libs.deRegister('lib3'); equal(registry[0].name, 'lib2'); equal(registry.length, 1); }); }); enifed('ember-metal/tests/main_test', ['ember-metal'], function (_emberMetal) { 'use strict'; // testing reexports // From sindresourhus/semver-regex https://github.com/sindresorhus/semver-regex/blob/795b05628d96597ebcbe6d31ef4a432858365582/index.js#L3 var SEMVER_REGEX = /^\bv?(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?\b$/; QUnit.module('ember-metal/core/main'); QUnit.test('Ember registers itself', function () { var lib = _emberMetal.default.libraries._registry[0]; equal(lib.name, 'Ember'); equal(lib.version, _emberMetal.default.VERSION); }); QUnit.test('Ember.VERSION is in alignment with SemVer v2.0.0', function () { ok(SEMVER_REGEX.test(_emberMetal.default.VERSION), 'Ember.VERSION (' + _emberMetal.default.VERSION + ')is valid SemVer v2.0.0'); }); QUnit.test('SEMVER_REGEX properly validates and invalidates version numbers', function () { function validateVersionString(versionString, expectedResult) { equal(SEMVER_REGEX.test(versionString), expectedResult); } // Positive test cases validateVersionString('1.11.3', true); validateVersionString('1.0.0-beta.16.1', true); validateVersionString('1.12.1+canary.aba1412', true); validateVersionString('2.0.0-beta.1+canary.bb344775', true); // Negative test cases validateVersionString('1.11.3.aba18a', false); validateVersionString('1.11', false); }); QUnit.test('Ember.Backburner is deprecated', function () { expectDeprecation(function () { new _emberMetal.default.Backburner(['foo']); }, 'Usage of Ember.Backburner is deprecated.'); }); QUnit.test('Ember.K is deprecated', function (assert) { expectDeprecation(function () { var obj = { noop: _emberMetal.default.K }; assert.equal(obj, obj.noop()); }, 'Ember.K is deprecated in favor of defining a function inline.'); }); }); enifed('ember-metal/tests/map_test', ['ember-metal'], function (_emberMetal) { 'use strict'; var object = void 0, number = void 0, string = void 0, map = void 0, variety = void 0, i; var varieties = [['Map', _emberMetal.Map], ['MapWithDefault', _emberMetal.MapWithDefault]]; function testMap(nameAndFunc) { variety = nameAndFunc[0]; QUnit.module('Ember.' + variety + ' (forEach and get are implicitly tested)', { setup: function () { object = {}; number = 42; string = 'foo'; map = nameAndFunc[1].create(); } }); var mapHasLength = function (expected, theMap) { theMap = theMap || map; var length = 0; theMap.forEach(function () { length++; }); equal(length, expected, 'map should contain ' + expected + ' items'); }; var mapHasEntries = function (entries, theMap) { var i; theMap = theMap || map; for (i = 0; i < entries.length; i++) { equal(theMap.get(entries[i][0]), entries[i][1]); equal(theMap.has(entries[i][0]), true); } mapHasLength(entries.length, theMap); }; var unboundThis = void 0; (function () { unboundThis = this; })(); QUnit.test('set', function () { map.set(object, 'winning'); map.set(number, 'winning'); map.set(string, 'winning'); mapHasEntries([[object, 'winning'], [number, 'winning'], [string, 'winning']]); map.set(object, 'losing'); map.set(number, 'losing'); map.set(string, 'losing'); mapHasEntries([[object, 'losing'], [number, 'losing'], [string, 'losing']]); equal(map.has('nope'), false, 'expected the key `nope` to not be present'); equal(map.has({}), false, 'expected they key `{}` to not be present'); }); QUnit.test('set chaining', function () { map.set(object, 'winning').set(number, 'winning').set(string, 'winning'); mapHasEntries([[object, 'winning'], [number, 'winning'], [string, 'winning']]); map.set(object, 'losing').set(number, 'losing').set(string, 'losing'); mapHasEntries([[object, 'losing'], [number, 'losing'], [string, 'losing']]); equal(map.has('nope'), false, 'expected the key `nope` to not be present'); equal(map.has({}), false, 'expected they key `{}` to not be present'); }); QUnit.test('with key with undefined value', function () { map.set('foo', undefined); map.forEach(function (value, key) { equal(value, undefined); equal(key, 'foo'); }); ok(map.has('foo'), 'has key foo, even with undefined value'); equal(map.size, 1); }); QUnit.test('arity of forEach is 1 – es6 23.1.3.5', function () { equal(map.forEach.length, 1, 'expected arity for map.forEach is 1'); }); QUnit.test('forEach throws without a callback as the first argument', function () { equal(map.forEach.length, 1, 'expected arity for map.forEach is 1'); }); QUnit.test('has empty collection', function () { equal(map.has('foo'), false); equal(map.has(), false); }); QUnit.test('delete', function () { expectNoDeprecation(); map.set(object, 'winning'); map.set(number, 'winning'); map.set(string, 'winning'); map.delete(object); map.delete(number); map.delete(string); // doesn't explode map.delete({}); mapHasEntries([]); }); QUnit.test('copy and then update', function () { map.set(object, 'winning'); map.set(number, 'winning'); map.set(string, 'winning'); var map2 = map.copy(); map2.set(object, 'losing'); map2.set(number, 'losing'); map2.set(string, 'losing'); mapHasEntries([[object, 'winning'], [number, 'winning'], [string, 'winning']]); mapHasEntries([[object, 'losing'], [number, 'losing'], [string, 'losing']], map2); }); QUnit.test('copy and then delete', function () { map.set(object, 'winning'); map.set(number, 'winning'); map.set(string, 'winning'); var map2 = map.copy(); map2.delete(object); map2.delete(number); map2.delete(string); mapHasEntries([[object, 'winning'], [number, 'winning'], [string, 'winning']]); mapHasEntries([], map2); }); QUnit.test('size', function () { //Add a key twice equal(map.size, 0); map.set(string, 'a string'); equal(map.size, 1); map.set(string, 'the same string'); equal(map.size, 1); //Add another map.set(number, 'a number'); equal(map.size, 2); //Remove one that doesn't exist map.delete('does not exist'); equal(map.size, 2); //Check copy var copy = map.copy(); equal(copy.size, 2); //Remove a key twice map.delete(number); equal(map.size, 1); map.delete(number); equal(map.size, 1); //Remove the last key map.delete(string); equal(map.size, 0); map.delete(string); equal(map.size, 0); }); QUnit.test('forEach without proper callback', function () { QUnit.throws(function () { map.forEach(); }, '[object Undefined] is not a function'); QUnit.throws(function () { map.forEach(undefined); }, '[object Undefined] is not a function'); QUnit.throws(function () { map.forEach(1); }, '[object Number] is not a function'); QUnit.throws(function () { map.forEach({}); }, '[object Object] is not a function'); map.forEach(function (value, key) { map.delete(key); }); // ensure the error happens even if no data is present equal(map.size, 0); QUnit.throws(function () { map.forEach({}); }, '[object Object] is not a function'); }); QUnit.test('forEach basic', function () { map.set('a', 1); map.set('b', 2); map.set('c', 3); var iteration = 0; var expectations = [{ value: 1, key: 'a', context: unboundThis }, { value: 2, key: 'b', context: unboundThis }, { value: 3, key: 'c', context: unboundThis }]; map.forEach(function (value, key, theMap) { var expectation = expectations[iteration]; equal(value, expectation.value, 'value should be correct'); equal(key, expectation.key, 'key should be correct'); equal(this, expectation.context, 'context should be as if it was unbound'); equal(map, theMap, 'map being iterated over should be passed in'); iteration++; }); equal(iteration, 3, 'expected 3 iterations'); }); QUnit.test('forEach basic /w context', function () { map.set('a', 1); map.set('b', 2); map.set('c', 3); var iteration = 0; var context = {}; var expectations = [{ value: 1, key: 'a', context: context }, { value: 2, key: 'b', context: context }, { value: 3, key: 'c', context: context }]; map.forEach(function (value, key, theMap) { var expectation = expectations[iteration]; equal(value, expectation.value, 'value should be correct'); equal(key, expectation.key, 'key should be correct'); equal(this, expectation.context, 'context should be as if it was unbound'); equal(map, theMap, 'map being iterated over should be passed in'); iteration++; }, context); equal(iteration, 3, 'expected 3 iterations'); }); QUnit.test('forEach basic /w deletion while enumerating', function () { map.set('a', 1); map.set('b', 2); map.set('c', 3); var iteration = 0; var expectations = [{ value: 1, key: 'a', context: unboundThis }, { value: 2, key: 'b', context: unboundThis }]; map.forEach(function (value, key, theMap) { if (iteration === 0) { map.delete('c'); } var expectation = expectations[iteration]; equal(value, expectation.value, 'value should be correct'); equal(key, expectation.key, 'key should be correct'); equal(this, expectation.context, 'context should be as if it was unbound'); equal(map, theMap, 'map being iterated over should be passed in'); iteration++; }); equal(iteration, 2, 'expected 3 iterations'); }); QUnit.test('forEach basic /w addition while enumerating', function () { map.set('a', 1); map.set('b', 2); map.set('c', 3); var iteration = 0; var expectations = [{ value: 1, key: 'a', context: unboundThis }, { value: 2, key: 'b', context: unboundThis }, { value: 3, key: 'c', context: unboundThis }, { value: 4, key: 'd', context: unboundThis }]; map.forEach(function (value, key, theMap) { if (iteration === 0) { map.set('d', 4); } var expectation = expectations[iteration]; equal(value, expectation.value, 'value should be correct'); equal(key, expectation.key, 'key should be correct'); equal(this, expectation.context, 'context should be as if it was unbound'); equal(map, theMap, 'map being iterated over should be passed in'); iteration++; }); equal(iteration, 4, 'expected 3 iterations'); }); QUnit.test('clear', function () { var iterations = 0; map.set('a', 1); map.set('b', 2); map.set('c', 3); map.set('d', 4); equal(map.size, 4); map.forEach(function () { iterations++; }); equal(iterations, 4); map.clear(); equal(map.size, 0); iterations = 0; map.forEach(function () { iterations++; }); equal(iterations, 0); }); QUnit.test('-0', function () { equal(map.has(-0), false); equal(map.has(0), false); map.set(-0, 'zero'); equal(map.has(-0), true); equal(map.has(0), true); equal(map.get(0), 'zero'); equal(map.get(-0), 'zero'); map.forEach(function (value, key) { equal(1 / key, Infinity, 'spec says key should be positive zero'); }); }); QUnit.test('NaN', function () { equal(map.has(NaN), false); map.set(NaN, 'not-a-number'); equal(map.has(NaN), true); equal(map.get(NaN), 'not-a-number'); }); QUnit.test('NaN Boxed', function () { //jshint -W053 var boxed = new Number(NaN); equal(map.has(boxed), false); map.set(boxed, 'not-a-number'); equal(map.has(boxed), true); equal(map.has(NaN), false); equal(map.get(NaN), undefined); equal(map.get(boxed), 'not-a-number'); }); QUnit.test('0 value', function () { var obj = {}; equal(map.has(obj), false); equal(map.size, 0); map.set(obj, 0); equal(map.size, 1); equal(map.has(obj), true); equal(map.get(obj), 0); map.delete(obj); equal(map.has(obj), false); equal(map.get(obj), undefined); equal(map.size, 0); }); } for (i = 0; i < varieties.length; i++) { testMap(varieties[i]); } QUnit.module('MapWithDefault - default values'); QUnit.test('Retrieving a value that has not been set returns and sets a default value', function () { var map = _emberMetal.MapWithDefault.create({ defaultValue: function (key) { return [key]; } }); var value = map.get('ohai'); deepEqual(value, ['ohai']); strictEqual(value, map.get('ohai')); }); QUnit.test('Map.prototype.constructor', function () { var map = new _emberMetal.Map(); equal(map.constructor, _emberMetal.Map); }); QUnit.test('Map() without `new`', function () { QUnit.throws(function () { // jshint newcap:false (0, _emberMetal.Map)(); }, /Constructor Map requires 'new'/); }); QUnit.test('MapWithDefault.prototype.constructor', function () { var map = new _emberMetal.MapWithDefault({ defaultValue: function (key) { return key; } }); equal(map.constructor, _emberMetal.MapWithDefault); }); QUnit.test('Copying a MapWithDefault copies the default value', function () { var map = _emberMetal.MapWithDefault.create({ defaultValue: function (key) { return [key]; } }); map.set('ohai', 1); map.get('bai'); var map2 = map.copy(); equal(map2.get('ohai'), 1); deepEqual(map2.get('bai'), ['bai']); map2.set('kthx', 3); deepEqual(map.get('kthx'), ['kthx']); equal(map2.get('kthx'), 3); deepEqual(map2.get('default'), ['default']); map2.defaultValue = function (key) { return ['tom is on', key]; }; deepEqual(map2.get('drugs'), ['tom is on', 'drugs']); }); QUnit.module('OrderedSet', { setup: function () { object = {}; number = 42; string = 'foo'; map = _emberMetal.OrderedSet.create(); } }); QUnit.test('OrderedSet() without `new`', function () { QUnit.throws(function () { // jshint newcap:false (0, _emberMetal.OrderedSet)(); }, /Constructor OrderedSet requires 'new'/); }); QUnit.test('add returns the set', function () { var obj = {}; equal(map.add(obj), map); equal(map.add(obj), map, 'when it is already in the set'); }); }); enifed('ember-metal/tests/meta_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember.meta'); QUnit.test('should return the same hash for an object', function () { var obj = {}; (0, _emberMetal.meta)(obj).foo = 'bar'; equal((0, _emberMetal.meta)(obj).foo, 'bar', 'returns same hash with multiple calls to Ember.meta()'); }); QUnit.test('meta is not enumerable', function () { var proto = void 0, obj = void 0, props = void 0, prop = void 0; proto = { foo: 'bar' }; (0, _emberMetal.meta)(proto); obj = Object.create(proto); (0, _emberMetal.meta)(obj); obj.bar = 'baz'; props = []; for (prop in obj) { props.push(prop); } deepEqual(props.sort(), ['bar', 'foo']); if (typeof JSON !== 'undefined' && 'stringify' in JSON) { try { JSON.stringify(obj); } catch (e) { ok(false, 'meta should not fail JSON.stringify'); } } }); QUnit.test('meta.listeners basics', function (assert) { var t = {}; var m = (0, _emberMetal.meta)({}); m.addToListeners('hello', t, 'm', 0); var matching = m.matchingListeners('hello'); assert.equal(matching.length, 3); assert.equal(matching[0], t); m.removeFromListeners('hello', t, 'm'); matching = m.matchingListeners('hello'); assert.equal(matching, undefined); }); QUnit.test('meta.listeners inheritance', function (assert) { var target = {}; var parent = {}; var parentMeta = (0, _emberMetal.meta)(parent); parentMeta.addToListeners('hello', target, 'm', 0); var child = Object.create(parent); var m = (0, _emberMetal.meta)(child); var matching = m.matchingListeners('hello'); assert.equal(matching.length, 3); assert.equal(matching[0], target); assert.equal(matching[1], 'm'); assert.equal(matching[2], 0); m.removeFromListeners('hello', target, 'm'); matching = m.matchingListeners('hello'); assert.equal(matching, undefined); matching = parentMeta.matchingListeners('hello'); assert.equal(matching.length, 3); }); QUnit.test('meta.listeners deduplication', function (assert) { var t = {}; var m = (0, _emberMetal.meta)({}); m.addToListeners('hello', t, 'm', 0); m.addToListeners('hello', t, 'm', 0); var matching = m.matchingListeners('hello'); assert.equal(matching.length, 3); assert.equal(matching[0], t); }); }); enifed('ember-metal/tests/mixin/alias_method_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('aliasMethod'); function validateAliasMethod(obj) { equal(obj.fooMethod(), 'FOO', 'obj.fooMethod()'); equal(obj.barMethod(), 'FOO', 'obj.barMethod should be a copy of foo'); } QUnit.test('methods of another name are aliased when the mixin is applied', function () { var MyMixin = _emberMetal.Mixin.create({ fooMethod: function () { return 'FOO'; }, barMethod: (0, _emberMetal.aliasMethod)('fooMethod') }); var obj = MyMixin.apply({}); validateAliasMethod(obj); }); QUnit.test('should follow aliasMethods all the way down', function () { var MyMixin = _emberMetal.Mixin.create({ bar: (0, _emberMetal.aliasMethod)('foo'), baz: function () { return 'baz'; }, foo: (0, _emberMetal.aliasMethod)('baz') }); var obj = MyMixin.apply({}); equal((0, _emberMetal.get)(obj, 'bar')(), 'baz', 'should have followed aliasMethods'); }); QUnit.test('should alias methods from other dependent mixins', function () { var BaseMixin = _emberMetal.Mixin.create({ fooMethod: function () { return 'FOO'; } }); var MyMixin = _emberMetal.Mixin.create(BaseMixin, { barMethod: (0, _emberMetal.aliasMethod)('fooMethod') }); var obj = MyMixin.apply({}); validateAliasMethod(obj); }); QUnit.test('should alias methods from other mixins applied at same time', function () { var BaseMixin = _emberMetal.Mixin.create({ fooMethod: function () { return 'FOO'; } }); var MyMixin = _emberMetal.Mixin.create({ barMethod: (0, _emberMetal.aliasMethod)('fooMethod') }); var obj = (0, _emberMetal.mixin)({}, BaseMixin, MyMixin); validateAliasMethod(obj); }); QUnit.test('should alias methods from mixins already applied on object', function () { var BaseMixin = _emberMetal.Mixin.create({ quxMethod: function () { return 'qux'; } }); var MyMixin = _emberMetal.Mixin.create({ bar: (0, _emberMetal.aliasMethod)('foo'), barMethod: (0, _emberMetal.aliasMethod)('fooMethod') }); var obj = { fooMethod: function () { return 'FOO'; } }; BaseMixin.apply(obj); MyMixin.apply(obj); validateAliasMethod(obj); }); }); enifed('ember-metal/tests/mixin/apply_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember.Mixin.apply'); function K() {} QUnit.test('using apply() should apply properties', function () { var MixinA = _emberMetal.Mixin.create({ foo: 'FOO', baz: K }); var obj = {}; (0, _emberMetal.mixin)(obj, MixinA); equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should apply foo'); equal((0, _emberMetal.get)(obj, 'baz'), K, 'should apply foo'); }); QUnit.test('applying anonymous properties', function () { var obj = {}; (0, _emberMetal.mixin)(obj, { foo: 'FOO', baz: K }); equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should apply foo'); equal((0, _emberMetal.get)(obj, 'baz'), K, 'should apply foo'); }); QUnit.test('applying null values', function () { expectAssertion(function () { return (0, _emberMetal.mixin)({}, null); }); }); QUnit.test('applying a property with an undefined value', function () { var obj = { tagName: '' }; (0, _emberMetal.mixin)(obj, { tagName: undefined }); strictEqual((0, _emberMetal.get)(obj, 'tagName'), ''); }); }); enifed('ember-metal/tests/mixin/computed_test', ['ember-metal'], function (_emberMetal) { 'use strict'; function K() { return this; } QUnit.module('Mixin Computed Properties'); QUnit.test('overriding computed properties', function () { var MixinA = void 0, MixinB = void 0, MixinC = void 0, MixinD = void 0; var obj = void 0; MixinA = _emberMetal.Mixin.create({ aProp: (0, _emberMetal.computed)(function () { return 'A'; }) }); MixinB = _emberMetal.Mixin.create(MixinA, { aProp: (0, _emberMetal.computed)(function () { return this._super.apply(this, arguments) + 'B'; }) }); MixinC = _emberMetal.Mixin.create(MixinA, { aProp: (0, _emberMetal.computed)(function () { return this._super.apply(this, arguments) + 'C'; }) }); MixinD = _emberMetal.Mixin.create({ aProp: (0, _emberMetal.computed)(function () { return this._super.apply(this, arguments) + 'D'; }) }); obj = {}; MixinB.apply(obj); equal((0, _emberMetal.get)(obj, 'aProp'), 'AB', 'should expose super for B'); obj = {}; MixinC.apply(obj); equal((0, _emberMetal.get)(obj, 'aProp'), 'AC', 'should expose super for C'); obj = {}; MixinA.apply(obj); MixinD.apply(obj); equal((0, _emberMetal.get)(obj, 'aProp'), 'AD', 'should define super for D'); obj = {}; (0, _emberMetal.defineProperty)(obj, 'aProp', (0, _emberMetal.computed)(function () { return 'obj'; })); MixinD.apply(obj); equal((0, _emberMetal.get)(obj, 'aProp'), 'objD', 'should preserve original computed property'); }); QUnit.test('calling set on overridden computed properties', function () { var SuperMixin = void 0, SubMixin = void 0; var obj = void 0; var superGetOccurred = false; var superSetOccurred = false; SuperMixin = _emberMetal.Mixin.create({ aProp: (0, _emberMetal.computed)({ get: function () { superGetOccurred = true; }, set: function () { superSetOccurred = true; } }) }); SubMixin = _emberMetal.Mixin.create(SuperMixin, { aProp: (0, _emberMetal.computed)({ get: function () { return this._super.apply(this, arguments); }, set: function () { return this._super.apply(this, arguments); } }) }); obj = {}; SubMixin.apply(obj); (0, _emberMetal.set)(obj, 'aProp', 'set thyself'); ok(superSetOccurred, 'should pass set to _super'); superSetOccurred = false; // reset the set assertion obj = {}; SubMixin.apply(obj); (0, _emberMetal.get)(obj, 'aProp'); ok(superGetOccurred, 'should pass get to _super'); (0, _emberMetal.set)(obj, 'aProp', 'set thyself'); ok(superSetOccurred, 'should pass set to _super after getting'); }); QUnit.test('setter behavior works properly when overriding computed properties', function () { var obj = {}; var MixinA = _emberMetal.Mixin.create({ cpWithSetter2: (0, _emberMetal.computed)(K), cpWithSetter3: (0, _emberMetal.computed)(K), cpWithoutSetter: (0, _emberMetal.computed)(K) }); var cpWasCalled = false; var MixinB = _emberMetal.Mixin.create({ cpWithSetter2: (0, _emberMetal.computed)({ get: K, set: function () { cpWasCalled = true; } }), cpWithSetter3: (0, _emberMetal.computed)({ get: K, set: function () { cpWasCalled = true; } }), cpWithoutSetter: (0, _emberMetal.computed)(function () { cpWasCalled = true; }) }); MixinA.apply(obj); MixinB.apply(obj); (0, _emberMetal.set)(obj, 'cpWithSetter2', 'test'); ok(cpWasCalled, 'The computed property setter was called when defined with two args'); cpWasCalled = false; (0, _emberMetal.set)(obj, 'cpWithSetter3', 'test'); ok(cpWasCalled, 'The computed property setter was called when defined with three args'); cpWasCalled = false; (0, _emberMetal.set)(obj, 'cpWithoutSetter', 'test'); equal((0, _emberMetal.get)(obj, 'cpWithoutSetter'), 'test', 'The default setter was called, the value is correct'); ok(!cpWasCalled, 'The default setter was called, not the CP itself'); }); }); enifed('ember-metal/tests/mixin/concatenated_properties_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Mixin concatenatedProperties'); QUnit.test('defining concatenated properties should concat future version', function () { var MixinA = _emberMetal.Mixin.create({ concatenatedProperties: ['foo'], foo: ['a', 'b', 'c'] }); var MixinB = _emberMetal.Mixin.create({ foo: ['d', 'e', 'f'] }); var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB); deepEqual((0, _emberMetal.get)(obj, 'foo'), ['a', 'b', 'c', 'd', 'e', 'f']); }); QUnit.test('defining concatenated properties should concat future version', function () { var MixinA = _emberMetal.Mixin.create({ concatenatedProperties: null }); var MixinB = _emberMetal.Mixin.create({ concatenatedProperties: null }); var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB); deepEqual(obj.concatenatedProperties, []); }); QUnit.test('concatenatedProperties should be concatenated', function () { var MixinA = _emberMetal.Mixin.create({ concatenatedProperties: ['foo'], foo: ['a', 'b', 'c'] }); var MixinB = _emberMetal.Mixin.create({ concatenatedProperties: 'bar', foo: ['d', 'e', 'f'], bar: [1, 2, 3] }); var MixinC = _emberMetal.Mixin.create({ bar: [4, 5, 6] }); var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB, MixinC); deepEqual((0, _emberMetal.get)(obj, 'concatenatedProperties'), ['foo', 'bar'], 'get concatenatedProperties'); deepEqual((0, _emberMetal.get)(obj, 'foo'), ['a', 'b', 'c', 'd', 'e', 'f'], 'get foo'); deepEqual((0, _emberMetal.get)(obj, 'bar'), [1, 2, 3, 4, 5, 6], 'get bar'); }); QUnit.test('adding a prop that is not an array should make array', function () { var MixinA = _emberMetal.Mixin.create({ concatenatedProperties: ['foo'], foo: [1, 2, 3] }); var MixinB = _emberMetal.Mixin.create({ foo: 4 }); var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB); deepEqual((0, _emberMetal.get)(obj, 'foo'), [1, 2, 3, 4]); }); QUnit.test('adding a prop that is not an array should make array', function () { var MixinA = _emberMetal.Mixin.create({ concatenatedProperties: ['foo'], foo: 'bar' }); var obj = (0, _emberMetal.mixin)({}, MixinA); deepEqual((0, _emberMetal.get)(obj, 'foo'), ['bar']); }); QUnit.test('adding a non-concatenable property that already has a defined value should result in an array with both values', function () { var mixinA = _emberMetal.Mixin.create({ foo: 1 }); var mixinB = _emberMetal.Mixin.create({ concatenatedProperties: ['foo'], foo: 2 }); var obj = (0, _emberMetal.mixin)({}, mixinA, mixinB); deepEqual((0, _emberMetal.get)(obj, 'foo'), [1, 2]); }); QUnit.test('adding a concatenable property that already has a defined value should result in a concatenated value', function () { var mixinA = _emberMetal.Mixin.create({ foobar: 'foo' }); var mixinB = _emberMetal.Mixin.create({ concatenatedProperties: ['foobar'], foobar: 'bar' }); var obj = (0, _emberMetal.mixin)({}, mixinA, mixinB); deepEqual((0, _emberMetal.get)(obj, 'foobar'), ['foo', 'bar']); }); }); enifed('ember-metal/tests/mixin/detect_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Mixin.detect'); QUnit.test('detect() finds a directly applied mixin', function () { var MixinA = _emberMetal.Mixin.create(); var obj = {}; equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()'); MixinA.apply(obj); equal(MixinA.detect(obj), true, 'MixinA.detect(obj) after apply()'); }); QUnit.test('detect() finds nested mixins', function () { var MixinA = _emberMetal.Mixin.create({}); var MixinB = _emberMetal.Mixin.create(MixinA); var obj = {}; equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()'); MixinB.apply(obj); equal(MixinA.detect(obj), true, 'MixinA.detect(obj) after apply()'); }); QUnit.test('detect() finds mixins on other mixins', function () { var MixinA = _emberMetal.Mixin.create({}); var MixinB = _emberMetal.Mixin.create(MixinA); equal(MixinA.detect(MixinB), true, 'MixinA is part of MixinB'); equal(MixinB.detect(MixinA), false, 'MixinB is not part of MixinA'); }); QUnit.test('detect handles null values', function () { var MixinA = _emberMetal.Mixin.create(); equal(MixinA.detect(null), false); }); }); enifed('ember-metal/tests/mixin/introspection_test', ['ember-utils', 'ember-metal'], function (_emberUtils, _emberMetal) { 'use strict'; // NOTE: A previous iteration differentiated between public and private props // as well as methods vs props. We are just keeping these for testing; the // current impl doesn't care about the differences as much... var PrivateProperty = _emberMetal.Mixin.create({ _foo: '_FOO' }); var PublicProperty = _emberMetal.Mixin.create({ foo: 'FOO' }); var PrivateMethod = _emberMetal.Mixin.create({ _fooMethod: function () {} }); var PublicMethod = _emberMetal.Mixin.create({ fooMethod: function () {} }); var BarProperties = _emberMetal.Mixin.create({ _bar: '_BAR', bar: 'bar' }); var BarMethods = _emberMetal.Mixin.create({ _barMethod: function () {}, barMethod: function () {} }); var Combined = _emberMetal.Mixin.create(BarProperties, BarMethods); var obj = void 0; QUnit.module('Basic introspection', { setup: function () { obj = {}; (0, _emberMetal.mixin)(obj, PrivateProperty, PublicProperty, PrivateMethod, PublicMethod, Combined); } }); QUnit.test('Ember.mixins()', function () { function mapGuids(ary) { return ary.map(function (x) { return (0, _emberUtils.guidFor)(x); }); } deepEqual(mapGuids(_emberMetal.Mixin.mixins(obj)), mapGuids([PrivateProperty, PublicProperty, PrivateMethod, PublicMethod, Combined, BarProperties, BarMethods]), 'should return included mixins'); }); }); enifed('ember-metal/tests/mixin/merged_properties_test', ['ember-runtime', 'ember-metal'], function (_emberRuntime, _emberMetal) { 'use strict'; QUnit.module('Mixin mergedProperties'); QUnit.test('defining mergedProperties should merge future version', function () { var MixinA = _emberMetal.Mixin.create({ mergedProperties: ['foo'], foo: { a: true, b: true, c: true } }); var MixinB = _emberMetal.Mixin.create({ foo: { d: true, e: true, f: true } }); var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB); deepEqual((0, _emberMetal.get)(obj, 'foo'), { a: true, b: true, c: true, d: true, e: true, f: true }); }); QUnit.test('defining mergedProperties on future mixin should merged into past', function () { var MixinA = _emberMetal.Mixin.create({ foo: { a: true, b: true, c: true } }); var MixinB = _emberMetal.Mixin.create({ mergedProperties: ['foo'], foo: { d: true, e: true, f: true } }); var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB); deepEqual((0, _emberMetal.get)(obj, 'foo'), { a: true, b: true, c: true, d: true, e: true, f: true }); }); QUnit.test('defining mergedProperties with null properties should keep properties null', function () { var MixinA = _emberMetal.Mixin.create({ mergedProperties: ['foo'], foo: null }); var MixinB = _emberMetal.Mixin.create({ foo: null }); var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB); equal((0, _emberMetal.get)(obj, 'foo'), null); }); QUnit.test('mergedProperties\' properties can get overwritten', function () { var MixinA = _emberMetal.Mixin.create({ mergedProperties: ['foo'], foo: { a: 1 } }); var MixinB = _emberMetal.Mixin.create({ foo: { a: 2 } }); var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB); deepEqual((0, _emberMetal.get)(obj, 'foo'), { a: 2 }); }); QUnit.test('mergedProperties should be concatenated', function () { var MixinA = _emberMetal.Mixin.create({ mergedProperties: ['foo'], foo: { a: true, b: true, c: true } }); var MixinB = _emberMetal.Mixin.create({ mergedProperties: 'bar', foo: { d: true, e: true, f: true }, bar: { a: true, l: true } }); var MixinC = _emberMetal.Mixin.create({ bar: { e: true, x: true } }); var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB, MixinC); deepEqual((0, _emberMetal.get)(obj, 'mergedProperties'), ['foo', 'bar'], 'get mergedProperties'); deepEqual((0, _emberMetal.get)(obj, 'foo'), { a: true, b: true, c: true, d: true, e: true, f: true }, 'get foo'); deepEqual((0, _emberMetal.get)(obj, 'bar'), { a: true, l: true, e: true, x: true }, 'get bar'); }); QUnit.test('mergedProperties should exist even if not explicitly set on create', function () { var AnObj = _emberRuntime.Object.extend({ mergedProperties: ['options'], options: { a: 'a', b: { c: 'ccc' } } }); var obj = AnObj.create({ options: { a: 'A' } }); equal((0, _emberMetal.get)(obj, 'options').a, 'A'); equal((0, _emberMetal.get)(obj, 'options').b.c, 'ccc'); }); QUnit.test('defining mergedProperties at create time should not modify the prototype', function () { var AnObj = _emberRuntime.Object.extend({ mergedProperties: ['options'], options: { a: 1 } }); var objA = AnObj.create({ options: { a: 2 } }); var objB = AnObj.create({ options: { a: 3 } }); equal((0, _emberMetal.get)(objA, 'options').a, 2); equal((0, _emberMetal.get)(objB, 'options').a, 3); }); QUnit.test('mergedProperties\' overwriting methods can call _super', function () { expect(4); var MixinA = _emberMetal.Mixin.create({ mergedProperties: ['foo'], foo: { meth: function (a) { equal(a, 'WOOT', '_super successfully called MixinA\'s `foo.meth` method'); return 'WAT'; } } }); var MixinB = _emberMetal.Mixin.create({ foo: { meth: function () { ok(true, 'MixinB\'s `foo.meth` method called'); return this._super.apply(this, arguments); } } }); var MixinC = _emberMetal.Mixin.create({ foo: { meth: function (a) { ok(true, 'MixinC\'s `foo.meth` method called'); return this._super(a); } } }); var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB, MixinC); equal(obj.foo.meth('WOOT'), 'WAT'); }); QUnit.test('Merging an Array should raise an error', function () { expect(1); var MixinA = _emberMetal.Mixin.create({ mergedProperties: ['foo'], foo: { a: true, b: true, c: true } }); var MixinB = _emberMetal.Mixin.create({ foo: ['a'] }); expectAssertion(function () { (0, _emberMetal.mixin)({}, MixinA, MixinB); }, 'You passed in `["a"]` as the value for `foo` but `foo` cannot be an Array'); }); }); enifed('ember-metal/tests/mixin/method_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Mixin Methods'); QUnit.test('defining simple methods', function () { var MixinA = void 0, obj = void 0, props = void 0; props = { publicMethod: function () { return 'publicMethod'; }, _privateMethod: function () { return 'privateMethod'; } }; MixinA = _emberMetal.Mixin.create(props); obj = {}; MixinA.apply(obj); // but should be defined equal(props.publicMethod(), 'publicMethod', 'publicMethod is func'); equal(props._privateMethod(), 'privateMethod', 'privateMethod is func'); }); QUnit.test('overriding public methods', function () { var MixinA = void 0, MixinB = void 0, MixinD = void 0, MixinF = void 0, obj = void 0; MixinA = _emberMetal.Mixin.create({ publicMethod: function () { return 'A'; } }); MixinB = _emberMetal.Mixin.create(MixinA, { publicMethod: function () { return this._super.apply(this, arguments) + 'B'; } }); MixinD = _emberMetal.Mixin.create(MixinA, { publicMethod: function () { return this._super.apply(this, arguments) + 'D'; } }); MixinF = _emberMetal.Mixin.create({ publicMethod: function () { return this._super.apply(this, arguments) + 'F'; } }); obj = {}; MixinB.apply(obj); equal(obj.publicMethod(), 'AB', 'should define super for A and B'); obj = {}; MixinD.apply(obj); equal(obj.publicMethod(), 'AD', 'should define super for A and B'); obj = {}; MixinA.apply(obj); MixinF.apply(obj); equal(obj.publicMethod(), 'AF', 'should define super for A and F'); obj = { publicMethod: function () { return 'obj'; } }; MixinF.apply(obj); equal(obj.publicMethod(), 'objF', 'should define super for F'); }); QUnit.test('overriding inherited objects', function () { var cnt = 0; var MixinA = _emberMetal.Mixin.create({ foo: function () { cnt++; } }); var MixinB = _emberMetal.Mixin.create({ foo: function () { this._super.apply(this, arguments); cnt++; } }); var objA = {}; MixinA.apply(objA); var objB = Object.create(objA); MixinB.apply(objB); cnt = 0; objB.foo(); equal(cnt, 2, 'should invoke both methods'); cnt = 0; objA.foo(); equal(cnt, 1, 'should not screw w/ parent obj'); }); QUnit.test('Including the same mixin more than once will only run once', function () { var cnt = 0; var MixinA = _emberMetal.Mixin.create({ foo: function () { cnt++; } }); var MixinB = _emberMetal.Mixin.create(MixinA, { foo: function () { this._super.apply(this, arguments); } }); var MixinC = _emberMetal.Mixin.create(MixinA, { foo: function () { this._super.apply(this, arguments); } }); var MixinD = _emberMetal.Mixin.create(MixinB, MixinC, MixinA, { foo: function () { this._super.apply(this, arguments); } }); var obj = {}; MixinD.apply(obj); MixinA.apply(obj); // try to apply again.. cnt = 0; obj.foo(); equal(cnt, 1, 'should invoke MixinA.foo one time'); }); QUnit.test('_super from a single mixin with no superclass does not error', function () { var MixinA = _emberMetal.Mixin.create({ foo: function () { this._super.apply(this, arguments); } }); var obj = {}; MixinA.apply(obj); obj.foo(); ok(true); }); QUnit.test('_super from a first-of-two mixins with no superclass function does not error', function () { // _super was previously calling itself in the second assertion. // Use remaining count of calls to ensure it doesn't loop indefinitely. var remaining = 3; var MixinA = _emberMetal.Mixin.create({ foo: function () { if (remaining-- > 0) { this._super.apply(this, arguments); } } }); var MixinB = _emberMetal.Mixin.create({ foo: function () { this._super.apply(this, arguments); } }); var obj = {}; MixinA.apply(obj); MixinB.apply(obj); obj.foo(); ok(true); }); // .......................................................... // CONFLICTS // QUnit.module('Method Conflicts'); QUnit.test('overriding toString', function () { var MixinA = _emberMetal.Mixin.create({ toString: function () { return 'FOO'; } }); var obj = {}; MixinA.apply(obj); equal(obj.toString(), 'FOO', 'should override toString w/o error'); obj = {}; (0, _emberMetal.mixin)(obj, { toString: function () { return 'FOO'; } }); equal(obj.toString(), 'FOO', 'should override toString w/o error'); }); // .......................................................... // BUGS // QUnit.module('system/mixin/method_test BUGS'); QUnit.test('applying several mixins at once with sup already defined causes infinite loop', function () { var cnt = 0; var MixinA = _emberMetal.Mixin.create({ foo: function () { cnt++; } }); var MixinB = _emberMetal.Mixin.create({ foo: function () { this._super.apply(this, arguments); cnt++; } }); var MixinC = _emberMetal.Mixin.create({ foo: function () { this._super.apply(this, arguments); cnt++; } }); var obj = {}; (0, _emberMetal.mixin)(obj, MixinA); // sup already exists (0, _emberMetal.mixin)(obj, MixinB, MixinC); // must be more than one mixin cnt = 0; obj.foo(); equal(cnt, 3, 'should invoke all 3 methods'); }); }); enifed('ember-metal/tests/mixin/observer_test', ['internal-test-helpers', 'ember-metal'], function (_internalTestHelpers, _emberMetal) { 'use strict'; QUnit.module('Mixin observer'); (0, _internalTestHelpers.testBoth)('global observer helper', function (get, set) { var MyMixin = _emberMetal.Mixin.create({ count: 0, foo: (0, _emberMetal.observer)('bar', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj = (0, _emberMetal.mixin)({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('global observer helper takes multiple params', function (get, set) { var MyMixin = _emberMetal.Mixin.create({ count: 0, foo: (0, _emberMetal.observer)('bar', 'baz', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj = (0, _emberMetal.mixin)({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); set(obj, 'baz', 'BAZ'); equal(get(obj, 'count'), 2, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('replacing observer should remove old observer', function (get, set) { var MyMixin = _emberMetal.Mixin.create({ count: 0, foo: (0, _emberMetal.observer)('bar', function () { set(this, 'count', get(this, 'count') + 1); }) }); var Mixin2 = _emberMetal.Mixin.create({ foo: (0, _emberMetal.observer)('baz', function () { set(this, 'count', get(this, 'count') + 10); }) }); var obj = (0, _emberMetal.mixin)({}, MyMixin, Mixin2); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); equal(get(obj, 'count'), 0, 'should not invoke observer after change'); set(obj, 'baz', 'BAZ'); equal(get(obj, 'count'), 10, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('observing chain with property before', function (get, set) { var obj2 = { baz: 'baz' }; var MyMixin = _emberMetal.Mixin.create({ count: 0, bar: obj2, foo: (0, _emberMetal.observer)('bar.baz', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj = (0, _emberMetal.mixin)({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj2, 'baz', 'BAZ'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('observing chain with property after', function (get, set) { var obj2 = { baz: 'baz' }; var MyMixin = _emberMetal.Mixin.create({ count: 0, foo: (0, _emberMetal.observer)('bar.baz', function () { set(this, 'count', get(this, 'count') + 1); }), bar: obj2 }); var obj = (0, _emberMetal.mixin)({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj2, 'baz', 'BAZ'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('observing chain with property in mixin applied later', function (get, set) { var obj2 = { baz: 'baz' }; var MyMixin = _emberMetal.Mixin.create({ count: 0, foo: (0, _emberMetal.observer)('bar.baz', function () { set(this, 'count', get(this, 'count') + 1); }) }); var MyMixin2 = _emberMetal.Mixin.create({ bar: obj2 }); var obj = (0, _emberMetal.mixin)({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); MyMixin2.apply(obj); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj2, 'baz', 'BAZ'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('observing chain with existing property', function (get, set) { var obj2 = { baz: 'baz' }; var MyMixin = _emberMetal.Mixin.create({ count: 0, foo: (0, _emberMetal.observer)('bar.baz', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj = (0, _emberMetal.mixin)({ bar: obj2 }, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj2, 'baz', 'BAZ'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('observing chain with property in mixin before', function (get, set) { var obj2 = { baz: 'baz' }; var MyMixin2 = _emberMetal.Mixin.create({ bar: obj2 }); var MyMixin = _emberMetal.Mixin.create({ count: 0, foo: (0, _emberMetal.observer)('bar.baz', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj = (0, _emberMetal.mixin)({}, MyMixin2, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj2, 'baz', 'BAZ'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('observing chain with property in mixin after', function (get, set) { var obj2 = { baz: 'baz' }; var MyMixin2 = _emberMetal.Mixin.create({ bar: obj2 }); var MyMixin = _emberMetal.Mixin.create({ count: 0, foo: (0, _emberMetal.observer)('bar.baz', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj = (0, _emberMetal.mixin)({}, MyMixin, MyMixin2); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj2, 'baz', 'BAZ'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('observing chain with overriden property', function (get, set) { var obj2 = { baz: 'baz' }; var obj3 = { baz: 'foo' }; var MyMixin2 = _emberMetal.Mixin.create({ bar: obj3 }); var MyMixin = _emberMetal.Mixin.create({ count: 0, foo: (0, _emberMetal.observer)('bar.baz', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj = (0, _emberMetal.mixin)({ bar: obj2 }, MyMixin, MyMixin2); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); equal((0, _emberMetal.isWatching)(obj2, 'baz'), false, 'should not be watching baz'); equal((0, _emberMetal.isWatching)(obj3, 'baz'), true, 'should be watching baz'); set(obj2, 'baz', 'BAZ'); equal(get(obj, 'count'), 0, 'should not invoke observer after change'); set(obj3, 'baz', 'BEAR'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('providing the arguments in reverse order is deprecated', function (get, set) { expectDeprecation(/Passing the dependentKeys after the callback function in Ember\.observer is deprecated. Ensure the callback function is the last argument/); _emberMetal.Mixin.create({ count: 0, foo: (0, _emberMetal.observer)(function () { set(this, 'count', get(this, 'count') + 1); }, 'bar.baz') }); }); }); enifed('ember-metal/tests/mixin/reopen_test', ['ember-runtime', 'ember-metal'], function (_emberRuntime, _emberMetal) { 'use strict'; QUnit.module('Ember.Mixin#reopen'); QUnit.test('using reopen() to add more properties to a simple', function () { var MixinA = _emberMetal.Mixin.create({ foo: 'FOO', baz: 'BAZ' }); MixinA.reopen({ bar: 'BAR', foo: 'FOO2' }); var obj = {}; MixinA.apply(obj); equal((0, _emberMetal.get)(obj, 'foo'), 'FOO2', 'mixin() should override'); equal((0, _emberMetal.get)(obj, 'baz'), 'BAZ', 'preserve MixinA props'); equal((0, _emberMetal.get)(obj, 'bar'), 'BAR', 'include MixinB props'); }); QUnit.test('using reopen() and calling _super where there is not a super function does not cause infinite recursion', function () { var Taco = _emberRuntime.Object.extend({ createBreakfast: function () { // There is no original createBreakfast function. // Calling the wrapped _super function here // used to end in an infinite call loop this._super.apply(this, arguments); return 'Breakfast!'; } }); Taco.reopen({ createBreakfast: function () { return this._super.apply(this, arguments); } }); var taco = Taco.create(); var result = void 0; (0, _emberMetal.run)(function () { try { result = taco.createBreakfast(); } catch (e) { result = 'Your breakfast was interrupted by an infinite stack error.'; } }); equal(result, 'Breakfast!'); }); }); enifed('ember-metal/tests/mixin/required_test', ['ember-metal'], function (_emberMetal) { 'use strict'; var PartialMixin = void 0, FinalMixin = void 0, obj = void 0; QUnit.module('Module.required', { setup: function () { expectDeprecation(function () { PartialMixin = _emberMetal.Mixin.create({ foo: (0, _emberMetal.required)(), bar: 'BAR' }); }, 'Ember.required is deprecated as its behavior is inconsistent and unreliable.'); FinalMixin = _emberMetal.Mixin.create({ foo: 'FOO' }); obj = {}; }, teardown: function () { PartialMixin = FinalMixin = obj = null; } }); QUnit.test('applying a mixin to meet requirement', function () { FinalMixin.apply(obj); PartialMixin.apply(obj); equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should now be defined'); }); QUnit.test('combined mixins to meet requirement', function () { _emberMetal.Mixin.create(PartialMixin, FinalMixin).apply(obj); equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should now be defined'); }); QUnit.test('merged mixin', function () { _emberMetal.Mixin.create(PartialMixin, { foo: 'FOO' }).apply(obj); equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should now be defined'); }); QUnit.test('define property on source object', function () { obj.foo = 'FOO'; PartialMixin.apply(obj); equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should now be defined'); }); QUnit.test('using apply', function () { (0, _emberMetal.mixin)(obj, PartialMixin, { foo: 'FOO' }); equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should now be defined'); }); }); enifed('ember-metal/tests/mixin/without_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.test('without should create a new mixin excluding named properties', function () { var MixinA = _emberMetal.Mixin.create({ foo: 'FOO', bar: 'BAR' }); var MixinB = MixinA.without('bar'); var obj = {}; MixinB.apply(obj); equal(obj.foo, 'FOO', 'should defined foo'); equal(obj.bar, undefined, 'should not define bar'); }); }); enifed('ember-metal/tests/observer_test', ['ember-environment', 'internal-test-helpers', 'ember-metal'], function (_emberEnvironment, _internalTestHelpers, _emberMetal) { 'use strict'; function K() {} // .......................................................... // ADD OBSERVER // QUnit.module('addObserver'); (0, _internalTestHelpers.testBoth)('observer should fire when property is modified', function (get, set) { var obj = {}; var count = 0; (0, _emberMetal.addObserver)(obj, 'foo', function () { equal(get(obj, 'foo'), 'bar', 'should invoke AFTER value changed'); count++; }); set(obj, 'foo', 'bar'); equal(count, 1, 'should have invoked observer'); }); (0, _internalTestHelpers.testBoth)('observer should fire when dependent property is modified', function (get, set) { var obj = { bar: 'bar' }; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () { return get(this, 'bar').toUpperCase(); }).property('bar')); get(obj, 'foo'); var count = 0; (0, _emberMetal.addObserver)(obj, 'foo', function () { equal(get(obj, 'foo'), 'BAZ', 'should have invoked after prop change'); count++; }); set(obj, 'bar', 'baz'); equal(count, 1, 'should have invoked observer'); }); (0, _internalTestHelpers.testBoth)('observer should continue to fire after dependent properties are accessed', function (get) { var observerCount = 0, i; var obj = {}; (0, _emberMetal.defineProperty)(obj, 'prop', (0, _emberMetal.computed)(function () { return Math.random(); })); (0, _emberMetal.defineProperty)(obj, 'anotherProp', (0, _emberMetal.computed)('prop', function () { return get(this, 'prop') + Math.random(); })); (0, _emberMetal.addObserver)(obj, 'prop', function () { observerCount++; }); get(obj, 'anotherProp'); for (i = 0; i < 10; i++) { (0, _emberMetal.propertyWillChange)(obj, 'prop'); (0, _emberMetal.propertyDidChange)(obj, 'prop'); } equal(observerCount, 10, 'should continue to fire indefinitely'); }); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) { (0, _internalTestHelpers.testBoth)('observer added declaratively via brace expansion should fire when property changes', function (get, set) { var obj = {}; var count = 0; (0, _emberMetal.mixin)(obj, { observeFooAndBar: function () { count++; }.observes('{foo,bar}') }); set(obj, 'foo', 'foo'); equal(count, 1, 'observer specified via brace expansion invoked on property change'); set(obj, 'bar', 'bar'); equal(count, 2, 'observer specified via brace expansion invoked on property change'); set(obj, 'baz', 'baz'); equal(count, 2, 'observer not invoked on unspecified property'); }); (0, _internalTestHelpers.testBoth)('observer specified declaratively via brace expansion should fire when dependent property changes', function (get, set) { var obj = { baz: 'Initial' }; var count = 0; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () { return get(this, 'bar').toLowerCase(); }).property('bar')); (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)(function () { return get(this, 'baz').toUpperCase(); }).property('baz')); (0, _emberMetal.mixin)(obj, { fooAndBarWatcher: function () { count++; }.observes('{foo,bar}') }); get(obj, 'foo'); set(obj, 'baz', 'Baz'); // fire once for foo, once for bar equal(count, 2, 'observer specified via brace expansion invoked on dependent property change'); set(obj, 'quux', 'Quux'); equal(count, 2, 'observer not fired on unspecified property'); }); } (0, _internalTestHelpers.testBoth)('observers watching multiple properties via brace expansion should fire when the properties change', function (get, set) { var obj = {}; var count = 0; (0, _emberMetal.mixin)(obj, { observeFooAndBar: (0, _emberMetal.observer)('{foo,bar}', function () { count++; }) }); set(obj, 'foo', 'foo'); equal(count, 1, 'observer specified via brace expansion invoked on property change'); set(obj, 'bar', 'bar'); equal(count, 2, 'observer specified via brace expansion invoked on property change'); set(obj, 'baz', 'baz'); equal(count, 2, 'observer not invoked on unspecified property'); }); (0, _internalTestHelpers.testBoth)('observers watching multiple properties via brace expansion should fire when dependent properties change', function (get, set) { var obj = { baz: 'Initial' }; var count = 0; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () { return get(this, 'bar').toLowerCase(); }).property('bar')); (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)(function () { return get(this, 'baz').toUpperCase(); }).property('baz')); (0, _emberMetal.mixin)(obj, { fooAndBarWatcher: (0, _emberMetal.observer)('{foo,bar}', function () { count++; }) }); get(obj, 'foo'); set(obj, 'baz', 'Baz'); // fire once for foo, once for bar equal(count, 2, 'observer specified via brace expansion invoked on dependent property change'); set(obj, 'quux', 'Quux'); equal(count, 2, 'observer not fired on unspecified property'); }); (0, _internalTestHelpers.testBoth)('nested observers should fire in order', function (get, set) { var obj = { foo: 'foo', bar: 'bar' }; var fooCount = 0; var barCount = 0; (0, _emberMetal.addObserver)(obj, 'foo', function () { fooCount++; }); (0, _emberMetal.addObserver)(obj, 'bar', function () { set(obj, 'foo', 'BAZ'); equal(fooCount, 1, 'fooCount should have fired already'); barCount++; }); set(obj, 'bar', 'BIFF'); equal(barCount, 1, 'barCount should have fired'); equal(fooCount, 1, 'foo should have fired'); }); (0, _internalTestHelpers.testBoth)('removing an chain observer on change should not fail', function (get, set) { var foo = { bar: 'bar' }; var obj1 = { foo: foo }; var obj2 = { foo: foo }; var obj4 = { foo: foo }; var count1 = 0; var count2 = 0; var count3 = 0; var count4 = 0; function observer1() { count1++; } function observer2() { count2++; } function observer4() { count4++; } (0, _emberMetal.addObserver)(obj1, 'foo.bar', observer1); (0, _emberMetal.addObserver)(obj2, 'foo.bar', observer2); (0, _emberMetal.addObserver)({ foo: foo }, 'foo.bar', function () { count3++; (0, _emberMetal.removeObserver)(obj1, 'foo.bar', observer1); (0, _emberMetal.removeObserver)(obj2, 'foo.bar', observer2); (0, _emberMetal.removeObserver)(obj4, 'foo.bar', observer4); }); (0, _emberMetal.addObserver)(obj4, 'foo.bar', observer4); set(foo, 'bar', 'baz'); equal(count1, 1, 'observer1 fired'); equal(count2, 1, 'observer2 fired'); equal(count3, 1, 'observer3 fired'); equal(count4, 0, 'observer4 did not fire'); }); (0, _internalTestHelpers.testBoth)('removing an chain before observer on change should not fail', function (get, set) { var foo = { bar: 'bar' }; var obj1 = { foo: foo }; var obj2 = { foo: foo }; var obj4 = { foo: foo }; var count1 = 0; var count2 = 0; var count3 = 0; var count4 = 0; function observer1() { count1++; } function observer2() { count2++; } function observer4() { count4++; } (0, _emberMetal._addBeforeObserver)(obj1, 'foo.bar', observer1); (0, _emberMetal._addBeforeObserver)(obj2, 'foo.bar', observer2); (0, _emberMetal._addBeforeObserver)({ foo: foo }, 'foo.bar', function () { count3++; (0, _emberMetal._removeBeforeObserver)(obj1, 'foo.bar', observer1); (0, _emberMetal._removeBeforeObserver)(obj2, 'foo.bar', observer2); (0, _emberMetal._removeBeforeObserver)(obj4, 'foo.bar', observer4); }); (0, _emberMetal._addBeforeObserver)(obj4, 'foo.bar', observer4); set(foo, 'bar', 'baz'); equal(count1, 1, 'observer1 fired'); equal(count2, 1, 'observer2 fired'); equal(count3, 1, 'observer3 fired'); equal(count4, 0, 'observer4 did not fire'); }); (0, _internalTestHelpers.testBoth)('suspending an observer should not fire during callback', function (get, set) { var obj = {}; var target = void 0, otherTarget = void 0; target = { values: [], method: function () { this.values.push(get(obj, 'foo')); } }; otherTarget = { values: [], method: function () { this.values.push(get(obj, 'foo')); } }; (0, _emberMetal.addObserver)(obj, 'foo', target, target.method); (0, _emberMetal.addObserver)(obj, 'foo', otherTarget, otherTarget.method); set(obj, 'foo', '1'); equal((0, _emberMetal._suspendObserver)(obj, 'foo', target, target.method, function () { /*jshint validthis:true */ equal(this, target); set(obj, 'foo', '2'); return 'result'; }), 'result'); set(obj, 'foo', '3'); deepEqual(target.values, ['1', '3'], 'should invoke'); deepEqual(otherTarget.values, ['1', '2', '3'], 'should invoke'); }); (0, _internalTestHelpers.testBoth)('suspending an observer should not defer change notifications during callback', function (get, set) { var obj = {}; var target = void 0, otherTarget = void 0; target = { values: [], method: function () { this.values.push(get(obj, 'foo')); } }; otherTarget = { values: [], method: function () { this.values.push(get(obj, 'foo')); } }; (0, _emberMetal.addObserver)(obj, 'foo', target, target.method); (0, _emberMetal.addObserver)(obj, 'foo', otherTarget, otherTarget.method); set(obj, 'foo', '1'); (0, _emberMetal.beginPropertyChanges)(); equal((0, _emberMetal._suspendObserver)(obj, 'foo', target, target.method, function () { /*jshint validthis:true */ equal(this, target); set(obj, 'foo', '2'); return 'result'; }), 'result'); (0, _emberMetal.endPropertyChanges)(); set(obj, 'foo', '3'); deepEqual(target.values, ['1', '3'], 'should invoke'); deepEqual(otherTarget.values, ['1', '2', '3'], 'should invoke'); }); (0, _internalTestHelpers.testBoth)('suspending observers should not fire during callback', function (get, set) { var obj = {}; var target = void 0, otherTarget = void 0; target = { values: [], method: function () { this.values.push(get(obj, 'foo')); } }; otherTarget = { values: [], method: function () { this.values.push(get(obj, 'foo')); } }; (0, _emberMetal.addObserver)(obj, 'foo', target, target.method); (0, _emberMetal.addObserver)(obj, 'foo', otherTarget, otherTarget.method); set(obj, 'foo', '1'); equal((0, _emberMetal._suspendObservers)(obj, ['foo'], target, target.method, function () { /*jshint validthis:true */ equal(this, target); set(obj, 'foo', '2'); return 'result'; }), 'result'); set(obj, 'foo', '3'); deepEqual(target.values, ['1', '3'], 'should invoke'); deepEqual(otherTarget.values, ['1', '2', '3'], 'should invoke'); }); (0, _internalTestHelpers.testBoth)('suspending observers should not defer change notifications during callback', function (get, set) { var obj = {}; var target = void 0, otherTarget = void 0; target = { values: [], method: function () { this.values.push(get(obj, 'foo')); } }; otherTarget = { values: [], method: function () { this.values.push(get(obj, 'foo')); } }; (0, _emberMetal.addObserver)(obj, 'foo', target, target.method); (0, _emberMetal.addObserver)(obj, 'foo', otherTarget, otherTarget.method); set(obj, 'foo', '1'); (0, _emberMetal.beginPropertyChanges)(); equal((0, _emberMetal._suspendObservers)(obj, ['foo'], target, target.method, function () { /*jshint validthis:true */ equal(this, target); set(obj, 'foo', '2'); return 'result'; }), 'result'); (0, _emberMetal.endPropertyChanges)(); set(obj, 'foo', '3'); deepEqual(target.values, ['1', '3'], 'should invoke'); deepEqual(otherTarget.values, ['1', '2', '3'], 'should invoke'); }); (0, _internalTestHelpers.testBoth)('deferring property change notifications', function (get, set) { var obj = { foo: 'foo' }; var fooCount = 0; (0, _emberMetal.addObserver)(obj, 'foo', function () { fooCount++; }); (0, _emberMetal.beginPropertyChanges)(obj); set(obj, 'foo', 'BIFF'); set(obj, 'foo', 'BAZ'); (0, _emberMetal.endPropertyChanges)(obj); equal(fooCount, 1, 'foo should have fired once'); }); (0, _internalTestHelpers.testBoth)('deferring property change notifications safely despite exceptions', function (get, set) { var obj = { foo: 'foo' }; var fooCount = 0; var exc = new Error('Something unexpected happened!'); expect(2); (0, _emberMetal.addObserver)(obj, 'foo', function () { fooCount++; }); try { (0, _emberMetal.changeProperties)(function () { set(obj, 'foo', 'BIFF'); set(obj, 'foo', 'BAZ'); throw exc; }); } catch (err) { if (err !== exc) { throw err; } } equal(fooCount, 1, 'foo should have fired once'); (0, _emberMetal.changeProperties)(function () { set(obj, 'foo', 'BIFF2'); set(obj, 'foo', 'BAZ2'); }); equal(fooCount, 2, 'foo should have fired again once'); }); (0, _internalTestHelpers.testBoth)('deferring property change notifications will not defer before observers', function (get, set) { var obj = { foo: 'foo' }; var fooCount = 0; (0, _emberMetal._addBeforeObserver)(obj, 'foo', function () { fooCount++; }); (0, _emberMetal.beginPropertyChanges)(obj); set(obj, 'foo', 'BIFF'); equal(fooCount, 1, 'should fire before observer immediately'); set(obj, 'foo', 'BAZ'); (0, _emberMetal.endPropertyChanges)(obj); equal(fooCount, 1, 'should not fire before observer twice'); }); (0, _internalTestHelpers.testBoth)('addObserver should propagate through prototype', function (get, set) { var obj = { foo: 'foo', count: 0 }; var obj2 = void 0; (0, _emberMetal.addObserver)(obj, 'foo', function () { this.count++; }); obj2 = Object.create(obj); set(obj2, 'foo', 'bar'); equal(obj2.count, 1, 'should have invoked observer on inherited'); equal(obj.count, 0, 'should not have invoked observer on parent'); obj2.count = 0; set(obj, 'foo', 'baz'); equal(obj.count, 1, 'should have invoked observer on parent'); equal(obj2.count, 0, 'should not have invoked observer on inherited'); }); (0, _internalTestHelpers.testBoth)('addObserver should respect targets with methods', function (get, set) { var observed = { foo: 'foo' }; var target1 = { count: 0, didChange: function (obj, keyName) { var value = get(obj, keyName); equal(this, target1, 'should invoke with this'); equal(obj, observed, 'param1 should be observed object'); equal(keyName, 'foo', 'param2 should be keyName'); equal(value, 'BAZ', 'param3 should new value'); this.count++; } }; var target2 = { count: 0, didChange: function (obj, keyName) { var value = get(obj, keyName); equal(this, target2, 'should invoke with this'); equal(obj, observed, 'param1 should be observed object'); equal(keyName, 'foo', 'param2 should be keyName'); equal(value, 'BAZ', 'param3 should new value'); this.count++; } }; (0, _emberMetal.addObserver)(observed, 'foo', target1, 'didChange'); (0, _emberMetal.addObserver)(observed, 'foo', target2, target2.didChange); set(observed, 'foo', 'BAZ'); equal(target1.count, 1, 'target1 observer should have fired'); equal(target2.count, 1, 'target2 observer should have fired'); }); (0, _internalTestHelpers.testBoth)('addObserver should allow multiple objects to observe a property', function (get, set) { var observed = { foo: 'foo' }; var target1 = { count: 0, didChange: function () { this.count++; } }; var target2 = { count: 0, didChange: function () { this.count++; } }; (0, _emberMetal.addObserver)(observed, 'foo', target1, 'didChange'); (0, _emberMetal.addObserver)(observed, 'foo', target2, 'didChange'); set(observed, 'foo', 'BAZ'); equal(target1.count, 1, 'target1 observer should have fired'); equal(target2.count, 1, 'target2 observer should have fired'); }); // .......................................................... // REMOVE OBSERVER // QUnit.module('removeObserver'); (0, _internalTestHelpers.testBoth)('removing observer should stop firing', function (get, set) { var obj = {}; var count = 0; function F() { count++; } (0, _emberMetal.addObserver)(obj, 'foo', F); set(obj, 'foo', 'bar'); equal(count, 1, 'should have invoked observer'); (0, _emberMetal.removeObserver)(obj, 'foo', F); set(obj, 'foo', 'baz'); equal(count, 1, 'removed observer shouldn\'t fire'); }); (0, _internalTestHelpers.testBoth)('local observers can be removed', function (get, set) { var barObserved = 0; var MyMixin = _emberMetal.Mixin.create({ foo1: (0, _emberMetal.observer)('bar', function () { barObserved++; }), foo2: (0, _emberMetal.observer)('bar', function () { barObserved++; }) }); var obj = {}; MyMixin.apply(obj); set(obj, 'bar', 'HI!'); equal(barObserved, 2, 'precond - observers should be fired'); (0, _emberMetal.removeObserver)(obj, 'bar', null, 'foo1'); barObserved = 0; set(obj, 'bar', 'HI AGAIN!'); equal(barObserved, 1, 'removed observers should not be called'); }); (0, _internalTestHelpers.testBoth)('removeObserver should respect targets with methods', function (get, set) { var observed = { foo: 'foo' }; var target1 = { count: 0, didChange: function () { this.count++; } }; var target2 = { count: 0, didChange: function () { this.count++; } }; (0, _emberMetal.addObserver)(observed, 'foo', target1, 'didChange'); (0, _emberMetal.addObserver)(observed, 'foo', target2, target2.didChange); set(observed, 'foo', 'BAZ'); equal(target1.count, 1, 'target1 observer should have fired'); equal(target2.count, 1, 'target2 observer should have fired'); (0, _emberMetal.removeObserver)(observed, 'foo', target1, 'didChange'); (0, _emberMetal.removeObserver)(observed, 'foo', target2, target2.didChange); target1.count = target2.count = 0; set(observed, 'foo', 'BAZ'); equal(target1.count, 0, 'target1 observer should not fire again'); equal(target2.count, 0, 'target2 observer should not fire again'); }); // .......................................................... // BEFORE OBSERVER // QUnit.module('_addBeforeObserver'); (0, _internalTestHelpers.testBoth)('observer should fire before a property is modified', function (get, set) { var obj = { foo: 'foo' }; var count = 0; (0, _emberMetal._addBeforeObserver)(obj, 'foo', function () { equal(get(obj, 'foo'), 'foo', 'should invoke before value changed'); count++; }); set(obj, 'foo', 'bar'); equal(count, 1, 'should have invoked observer'); }); (0, _internalTestHelpers.testBoth)('observer should fire before dependent property is modified', function (get, set) { var obj = { bar: 'bar' }; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () { return get(this, 'bar').toUpperCase(); }).property('bar')); get(obj, 'foo'); var count = 0; (0, _emberMetal._addBeforeObserver)(obj, 'foo', function () { equal(get(obj, 'foo'), 'BAR', 'should have invoked after prop change'); count++; }); set(obj, 'bar', 'baz'); equal(count, 1, 'should have invoked observer'); }); (0, _internalTestHelpers.testBoth)('before observer watching multiple properties via brace expansion should fire when properties change', function (get, set) { var obj = {}; var count = 0; (0, _emberMetal.mixin)(obj, { fooAndBarWatcher: (0, _emberMetal._beforeObserver)('{foo,bar}', function () { count++; }) }); set(obj, 'foo', 'foo'); equal(count, 1, 'observer specified via brace expansion invoked on property change'); set(obj, 'bar', 'bar'); equal(count, 2, 'observer specified via brace expansion invoked on property change'); set(obj, 'baz', 'baz'); equal(count, 2, 'observer not invoked on unspecified property'); }); (0, _internalTestHelpers.testBoth)('before observer watching multiple properties via brace expansion should fire when dependent property changes', function (get, set) { var obj = { baz: 'Initial' }; var count = 0; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () { return get(this, 'bar').toLowerCase(); }).property('bar')); (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)(function () { return get(this, 'baz').toUpperCase(); }).property('baz')); (0, _emberMetal.mixin)(obj, { fooAndBarWatcher: (0, _emberMetal._beforeObserver)('{foo,bar}', function () { count++; }) }); get(obj, 'foo'); set(obj, 'baz', 'Baz'); // fire once for foo, once for bar equal(count, 2, 'observer specified via brace expansion invoked on dependent property change'); set(obj, 'quux', 'Quux'); equal(count, 2, 'observer not fired on unspecified property'); }); (0, _internalTestHelpers.testBoth)('_addBeforeObserver should propagate through prototype', function (get, set) { var obj = { foo: 'foo', count: 0 }; var obj2 = void 0; (0, _emberMetal._addBeforeObserver)(obj, 'foo', function () { this.count++; }); obj2 = Object.create(obj); set(obj2, 'foo', 'bar'); equal(obj2.count, 1, 'should have invoked observer on inherited'); equal(obj.count, 0, 'should not have invoked observer on parent'); obj2.count = 0; set(obj, 'foo', 'baz'); equal(obj.count, 1, 'should have invoked observer on parent'); equal(obj2.count, 0, 'should not have invoked observer on inherited'); }); (0, _internalTestHelpers.testBoth)('_addBeforeObserver should respect targets with methods', function (get, set) { var observed = { foo: 'foo' }; var target1 = { count: 0, willChange: function (obj, keyName) { var value = get(obj, keyName); equal(this, target1, 'should invoke with this'); equal(obj, observed, 'param1 should be observed object'); equal(keyName, 'foo', 'param2 should be keyName'); equal(value, 'foo', 'param3 should old value'); this.count++; } }; var target2 = { count: 0, willChange: function (obj, keyName) { var value = get(obj, keyName); equal(this, target2, 'should invoke with this'); equal(obj, observed, 'param1 should be observed object'); equal(keyName, 'foo', 'param2 should be keyName'); equal(value, 'foo', 'param3 should old value'); this.count++; } }; (0, _emberMetal._addBeforeObserver)(observed, 'foo', target1, 'willChange'); (0, _emberMetal._addBeforeObserver)(observed, 'foo', target2, target2.willChange); set(observed, 'foo', 'BAZ'); equal(target1.count, 1, 'target1 observer should have fired'); equal(target2.count, 1, 'target2 observer should have fired'); }); // .......................................................... // CHAINED OBSERVERS // var obj = void 0, count = void 0; QUnit.module('addObserver - dependentkey with chained properties', { setup: function () { obj = { foo: { bar: { baz: { biff: 'BIFF' } } }, Capital: { foo: { bar: { baz: { biff: 'BIFF' } } } } }; count = 0; }, teardown: function () { obj = count = null; } }); (0, _internalTestHelpers.testBoth)('depending on a chain with a computed property', function (get, set) { (0, _emberMetal.defineProperty)(obj, 'computed', (0, _emberMetal.computed)(function () { return { foo: 'bar' }; })); var changed = 0; (0, _emberMetal.addObserver)(obj, 'computed.foo', function () { changed++; }); equal((0, _emberMetal.cacheFor)(obj, 'computed'), undefined, 'addObserver should not compute CP'); set(obj, 'computed.foo', 'baz'); equal(changed, 1, 'should fire observer'); }); (0, _internalTestHelpers.testBoth)('depending on a simple chain', function (get, set) { var val = void 0; (0, _emberMetal.addObserver)(obj, 'foo.bar.baz.biff', function (target, key) { val = get(target, key); count++; }); set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ'); equal(val, 'BUZZ'); equal(count, 1); set(get(obj, 'foo.bar'), 'baz', { biff: 'BLARG' }); equal(val, 'BLARG'); equal(count, 2); set(get(obj, 'foo'), 'bar', { baz: { biff: 'BOOM' } }); equal(val, 'BOOM'); equal(count, 3); set(obj, 'foo', { bar: { baz: { biff: 'BLARG' } } }); equal(val, 'BLARG'); equal(count, 4); set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ'); equal(val, 'BUZZ'); equal(count, 5); var foo = get(obj, 'foo'); set(obj, 'foo', 'BOO'); equal(val, undefined); equal(count, 6); set(foo.bar.baz, 'biff', 'BOOM'); equal(count, 6, 'should be not have invoked observer'); }); (0, _internalTestHelpers.testBoth)('depending on a chain with a capitalized first key', function (get, set) { var val = void 0; (0, _emberMetal.addObserver)(obj, 'Capital.foo.bar.baz.biff', function (target, key) { val = get(obj, key); count++; }); set(get(obj, 'Capital.foo.bar.baz'), 'biff', 'BUZZ'); equal(val, 'BUZZ'); equal(count, 1); set(get(obj, 'Capital.foo.bar'), 'baz', { biff: 'BLARG' }); equal(val, 'BLARG'); equal(count, 2); set(get(obj, 'Capital.foo'), 'bar', { baz: { biff: 'BOOM' } }); equal(val, 'BOOM'); equal(count, 3); set(obj, 'Capital.foo', { bar: { baz: { biff: 'BLARG' } } }); equal(val, 'BLARG'); equal(count, 4); set(get(obj, 'Capital.foo.bar.baz'), 'biff', 'BUZZ'); equal(val, 'BUZZ'); equal(count, 5); var foo = get(obj, 'foo'); set(obj, 'Capital.foo', 'BOO'); equal(val, undefined); equal(count, 6); set(foo.bar.baz, 'biff', 'BOOM'); equal(count, 6, 'should be not have invoked observer'); }); QUnit.module('_removeBeforeObserver'); // .......................................................... // SETTING IDENTICAL VALUES // QUnit.module('props/observer_test - setting identical values'); (0, _internalTestHelpers.testBoth)('setting simple prop should not trigger', function (get, set) { var obj = { foo: 'bar' }; var count = 0; (0, _emberMetal.addObserver)(obj, 'foo', function () { count++; }); set(obj, 'foo', 'bar'); equal(count, 0, 'should not trigger observer'); set(obj, 'foo', 'baz'); equal(count, 1, 'should trigger observer'); set(obj, 'foo', 'baz'); equal(count, 1, 'should not trigger observer again'); }); // The issue here is when a computed property is directly set with a value, then has a // dependent key change (which triggers a cache expiration and recomputation), observers will // not be fired if the CP setter is called with the last set value. (0, _internalTestHelpers.testBoth)('setting a cached computed property whose value has changed should trigger', function (get, set) { var obj = {}; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({ get: function () { return get(this, 'baz'); }, set: function (key, value) { return value; } }).property('baz')); var count = 0; (0, _emberMetal.addObserver)(obj, 'foo', function () { count++; }); set(obj, 'foo', 'bar'); equal(count, 1); equal(get(obj, 'foo'), 'bar'); set(obj, 'baz', 'qux'); equal(count, 2); equal(get(obj, 'foo'), 'qux'); get(obj, 'foo'); set(obj, 'foo', 'bar'); equal(count, 3); equal(get(obj, 'foo'), 'bar'); }); QUnit.module('Ember.immediateObserver (Deprecated)'); (0, _internalTestHelpers.testBoth)('immediate observers should fire synchronously', function (get, set) { expectDeprecation(/Usage of `Ember.immediateObserver` is deprecated, use `Ember.observer` instead./); var obj = {}; var observerCalled = 0; var mixin = void 0; // explicitly create a run loop so we do not inadvertently // trigger deferred behavior (0, _emberMetal.run)(function () { mixin = _emberMetal.Mixin.create({ fooDidChange: (0, _emberMetal._immediateObserver)('foo', function () { observerCalled++; equal(get(this, 'foo'), 'barbaz', 'newly set value is immediately available'); }) }); mixin.apply(obj); (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({ get: function () { return 'yes hello this is foo'; }, set: function (key, value) { return value; } })); equal(get(obj, 'foo'), 'yes hello this is foo', 'precond - computed property returns a value'); equal(observerCalled, 0, 'observer has not yet been called'); set(obj, 'foo', 'barbaz'); equal(observerCalled, 1, 'observer was called once'); }); }); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) { (0, _internalTestHelpers.testBoth)('immediate observers added declaratively via brace expansion fire synchronously', function (get, set) { var obj = {}; var observerCalled = 0; var mixin = void 0; // explicitly create a run loop so we do not inadvertently // trigger deferred behavior (0, _emberMetal.run)(function () { expectDeprecation(function () { mixin = _emberMetal.Mixin.create({ fooDidChange: function () { observerCalled++; equal(get(this, 'foo'), 'barbaz', 'newly set value is immediately available'); }.observesImmediately('{foo,bar}') }); }, /Function#observesImmediately is deprecated. Use Function#observes instead/); mixin.apply(obj); (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({ get: function () { return 'yes hello this is foo'; }, set: function (key, value) { return value; } })); equal(get(obj, 'foo'), 'yes hello this is foo', 'precond - computed property returns a value'); equal(observerCalled, 0, 'observer has not yet been called'); set(obj, 'foo', 'barbaz'); equal(observerCalled, 1, 'observer was called once'); }); }); } (0, _internalTestHelpers.testBoth)('immediate observers watching multiple properties via brace expansion fire synchronously', function (get, set) { expectDeprecation(/Usage of `Ember.immediateObserver` is deprecated, use `Ember.observer` instead./); var obj = {}; var observerCalled = 0; var mixin = void 0; // explicitly create a run loop so we do not inadvertently // trigger deferred behavior (0, _emberMetal.run)(function () { mixin = _emberMetal.Mixin.create({ fooDidChange: (0, _emberMetal._immediateObserver)('{foo,bar}', function () { observerCalled++; equal(get(this, 'foo'), 'barbaz', 'newly set value is immediately available'); }) }); mixin.apply(obj); (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({ get: function () { return 'yes hello this is foo'; }, set: function (key, value) { return value; } })); equal(get(obj, 'foo'), 'yes hello this is foo', 'precond - computed property returns a value'); equal(observerCalled, 0, 'observer has not yet been called'); set(obj, 'foo', 'barbaz'); equal(observerCalled, 1, 'observer was called once'); }); }); (0, _internalTestHelpers.testBoth)('immediate observers are for internal properties only', function () { expectDeprecation(/Usage of `Ember.immediateObserver` is deprecated, use `Ember.observer` instead./); expectAssertion(function () { (0, _emberMetal._immediateObserver)('foo.bar', function () { return this; }); }, 'Immediate observers must observe internal properties only, not properties on other objects.'); }); QUnit.module('changeProperties'); (0, _internalTestHelpers.testBoth)('observers added/removed during changeProperties should do the right thing.', function (get, set) { var obj = { foo: 0 }; function Observer() { this.willChangeCount = 0; this.didChangeCount = 0; } Observer.prototype = { add: function () { (0, _emberMetal._addBeforeObserver)(obj, 'foo', this, 'willChange'); (0, _emberMetal.addObserver)(obj, 'foo', this, 'didChange'); }, remove: function () { (0, _emberMetal._removeBeforeObserver)(obj, 'foo', this, 'willChange'); (0, _emberMetal.removeObserver)(obj, 'foo', this, 'didChange'); }, willChange: function () { this.willChangeCount++; }, didChange: function () { this.didChangeCount++; } }; var addedBeforeFirstChangeObserver = new Observer(); var addedAfterFirstChangeObserver = new Observer(); var addedAfterLastChangeObserver = new Observer(); var removedBeforeFirstChangeObserver = new Observer(); var removedBeforeLastChangeObserver = new Observer(); var removedAfterLastChangeObserver = new Observer(); removedBeforeFirstChangeObserver.add(); removedBeforeLastChangeObserver.add(); removedAfterLastChangeObserver.add(); (0, _emberMetal.changeProperties)(function () { removedBeforeFirstChangeObserver.remove(); addedBeforeFirstChangeObserver.add(); set(obj, 'foo', 1); equal(addedBeforeFirstChangeObserver.willChangeCount, 1, '_addBeforeObserver called before the first change invoked immediately'); equal(addedBeforeFirstChangeObserver.didChangeCount, 0, 'addObserver called before the first change is deferred'); addedAfterFirstChangeObserver.add(); removedBeforeLastChangeObserver.remove(); set(obj, 'foo', 2); equal(addedAfterFirstChangeObserver.willChangeCount, 1, '_addBeforeObserver called after the first change invoked immediately'); equal(addedAfterFirstChangeObserver.didChangeCount, 0, 'addObserver called after the first change is deferred'); addedAfterLastChangeObserver.add(); removedAfterLastChangeObserver.remove(); }); equal(removedBeforeFirstChangeObserver.willChangeCount, 0, '_removeBeforeObserver called before the first change sees none'); equal(removedBeforeFirstChangeObserver.didChangeCount, 0, 'removeObserver called before the first change sees none'); equal(addedBeforeFirstChangeObserver.willChangeCount, 1, '_addBeforeObserver called before the first change sees only 1'); equal(addedBeforeFirstChangeObserver.didChangeCount, 1, 'addObserver called before the first change sees only 1'); equal(addedAfterFirstChangeObserver.willChangeCount, 1, '_addBeforeObserver called after the first change sees 1'); equal(addedAfterFirstChangeObserver.didChangeCount, 1, 'addObserver called after the first change sees 1'); equal(addedAfterLastChangeObserver.willChangeCount, 0, '_addBeforeObserver called after the last change sees none'); equal(addedAfterLastChangeObserver.didChangeCount, 0, 'addObserver called after the last change sees none'); equal(removedBeforeLastChangeObserver.willChangeCount, 1, '_removeBeforeObserver called before the last change still sees 1'); equal(removedBeforeLastChangeObserver.didChangeCount, 1, 'removeObserver called before the last change still sees 1'); equal(removedAfterLastChangeObserver.willChangeCount, 1, '_removeBeforeObserver called after the last change still sees 1'); equal(removedAfterLastChangeObserver.didChangeCount, 1, 'removeObserver called after the last change still sees 1'); }); QUnit.module('Keys behavior with observers'); (0, _internalTestHelpers.testBoth)('should not leak properties on the prototype', function () { function Beer() {} Beer.prototype.type = 'ipa'; var beer = new Beer(); (0, _emberMetal.addObserver)(beer, 'type', K); deepEqual(Object.keys(beer), []); (0, _emberMetal.removeObserver)(beer, 'type', K); }); (0, _internalTestHelpers.testBoth)('observing a non existent property', function (get, set) { function Beer() {} Beer.prototype.type = 'ipa'; var beer = new Beer(); (0, _emberMetal.addObserver)(beer, 'brand', K); deepEqual(Object.keys(beer), []); set(beer, 'brand', 'Corona'); deepEqual(Object.keys(beer), ['brand']); (0, _emberMetal.removeObserver)(beer, 'brand', K); }); (0, _internalTestHelpers.testBoth)('with observers switched on and off', function () { function Beer() {} Beer.prototype.type = 'ipa'; var beer = new Beer(); (0, _emberMetal.addObserver)(beer, 'type', K); (0, _emberMetal.removeObserver)(beer, 'type', K); deepEqual(Object.keys(beer), []); }); (0, _internalTestHelpers.testBoth)('observers switched on and off with setter in between', function (get, set) { function Beer() {} Beer.prototype.type = 'ipa'; var beer = new Beer(); (0, _emberMetal.addObserver)(beer, 'type', K); set(beer, 'type', 'ale'); (0, _emberMetal.removeObserver)(beer, 'type', K); deepEqual(Object.keys(beer), ['type']); }); (0, _internalTestHelpers.testBoth)('observer switched on and off and then setter', function (get, set) { function Beer() {} Beer.prototype.type = 'ipa'; var beer = new Beer(); (0, _emberMetal.addObserver)(beer, 'type', K); (0, _emberMetal.removeObserver)(beer, 'type', K); set(beer, 'type', 'ale'); deepEqual(Object.keys(beer), ['type']); }); (0, _internalTestHelpers.testBoth)('observers switched on and off with setter in between (observed property is not shadowing)', function (get, set) { function Beer() {} var beer = new Beer(); set(beer, 'type', 'ale'); deepEqual(Object.keys(beer), ['type'], 'only set'); var otherBeer = new Beer(); (0, _emberMetal.addObserver)(otherBeer, 'type', K); set(otherBeer, 'type', 'ale'); deepEqual(Object.keys(otherBeer), ['type'], 'addObserver -> set'); var yetAnotherBeer = new Beer(); (0, _emberMetal.addObserver)(yetAnotherBeer, 'type', K); set(yetAnotherBeer, 'type', 'ale'); (0, _emberMetal.removeObserver)(beer, 'type', K); deepEqual(Object.keys(yetAnotherBeer), ['type'], 'addObserver -> set -> removeObserver'); var itsMyLastBeer = new Beer(); set(itsMyLastBeer, 'type', 'ale'); (0, _emberMetal.removeObserver)(beer, 'type', K); deepEqual(Object.keys(itsMyLastBeer), ['type'], 'set -> removeObserver'); }); (0, _internalTestHelpers.testBoth)('observers switched on and off with setter in between (observed property is shadowing one on the prototype)', function (get, set) { function Beer() {} Beer.prototype.type = 'ipa'; var beer = new Beer(); set(beer, 'type', 'ale'); deepEqual(Object.keys(beer), ['type'], 'after set'); var otherBeer = new Beer(); (0, _emberMetal.addObserver)(otherBeer, 'type', K); set(otherBeer, 'type', 'ale'); deepEqual(Object.keys(otherBeer), ['type'], 'addObserver -> set'); var yetAnotherBeer = new Beer(); (0, _emberMetal.addObserver)(yetAnotherBeer, 'type', K); set(yetAnotherBeer, 'type', 'ale'); (0, _emberMetal.removeObserver)(beer, 'type', K); deepEqual(Object.keys(yetAnotherBeer), ['type'], 'addObserver -> set -> removeObserver'); var itsMyLastBeer = new Beer(); set(itsMyLastBeer, 'type', 'ale'); (0, _emberMetal.removeObserver)(beer, 'type', K); deepEqual(Object.keys(itsMyLastBeer), ['type'], 'set -> removeObserver'); }); }); enifed('ember-metal/tests/performance_test', ['ember-metal'], function (_emberMetal) { 'use strict'; /* This test file is designed to capture performance regressions related to deferred computation. Things like run loops, computed properties, and bindings should run the minimum amount of times to achieve best performance, so any bugs that cause them to get evaluated more than necessary should be put here. */ QUnit.module('Computed Properties - Number of times evaluated'); QUnit.test('computed properties that depend on multiple properties should run only once per run loop', function () { var obj = { a: 'a', b: 'b', c: 'c' }; var cpCount = 0; var obsCount = 0; (0, _emberMetal.defineProperty)(obj, 'abc', (0, _emberMetal.computed)(function (key) { cpCount++; return 'computed ' + key; }).property('a', 'b', 'c')); (0, _emberMetal.get)(obj, 'abc'); cpCount = 0; (0, _emberMetal.addObserver)(obj, 'abc', function () { obsCount++; }); (0, _emberMetal.beginPropertyChanges)(); (0, _emberMetal.set)(obj, 'a', 'aa'); (0, _emberMetal.set)(obj, 'b', 'bb'); (0, _emberMetal.set)(obj, 'c', 'cc'); (0, _emberMetal.endPropertyChanges)(); (0, _emberMetal.get)(obj, 'abc'); equal(cpCount, 1, 'The computed property is only invoked once'); equal(obsCount, 1, 'The observer is only invoked once'); }); QUnit.test('computed properties are not executed if they are the last segment of an observer chain pain', function () { var foo = { bar: { baz: {} } }; var count = 0; (0, _emberMetal.defineProperty)(foo.bar.baz, 'bam', (0, _emberMetal.computed)(function () { count++; })); (0, _emberMetal.addObserver)(foo, 'bar.baz.bam', function () {}); (0, _emberMetal.propertyDidChange)((0, _emberMetal.get)(foo, 'bar.baz'), 'bam'); equal(count, 0, 'should not have recomputed property'); }); }); enifed('ember-metal/tests/properties_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember.defineProperty'); QUnit.test('toString', function () { var obj = {}; (0, _emberMetal.defineProperty)(obj, 'toString', undefined, function () { return 'FOO'; }); equal(obj.toString(), 'FOO', 'should replace toString'); }); QUnit.test('for data properties, didDefineProperty hook should be called if implemented', function () { expect(2); (0, _emberMetal.defineProperty)({ didDefineProperty: function (obj, keyName, value) { equal(keyName, 'foo', 'key name should be foo'); equal(value, 'bar', 'value should be bar'); } }, 'foo', undefined, 'bar'); }); QUnit.test('for computed properties, didDefineProperty hook should be called if implemented', function () { expect(2); var computedProperty = (0, _emberMetal.computed)(function () { return this; }); (0, _emberMetal.defineProperty)({ didDefineProperty: function (obj, keyName, value) { equal(keyName, 'foo', 'key name should be foo'); strictEqual(value, computedProperty, 'value should be passed as computed property'); } }, 'foo', computedProperty); }); QUnit.test('for descriptor properties, didDefineProperty hook should be called if implemented', function () { expect(2); var descriptor = { writable: true, configurable: false, enumerable: true, value: 42 }; (0, _emberMetal.defineProperty)({ didDefineProperty: function (obj, keyName, value) { equal(keyName, 'answer', 'key name should be answer'); strictEqual(value, descriptor, 'value should be passed as descriptor'); } }, 'answer', descriptor); }); QUnit.module('Ember.deprecateProperty'); QUnit.test('enables access to deprecated property and returns the value of the new property', function () { expect(3); var obj = { foo: 'bar' }; (0, _emberMetal.deprecateProperty)(obj, 'baz', 'foo'); expectDeprecation(); equal(obj.baz, obj.foo, 'baz and foo are equal'); obj.foo = 'blammo'; equal(obj.baz, obj.foo, 'baz and foo are equal'); }); QUnit.test('deprecatedKey is not enumerable', function () { expect(2); var obj = { foo: 'bar', blammo: 'whammy' }; (0, _emberMetal.deprecateProperty)(obj, 'baz', 'foo'); for (var prop in obj) { if (obj.hasOwnProperty(prop)) { notEqual(prop, 'baz'); } } }); QUnit.test('enables setter to deprecated property and updates the value of the new property', function () { expect(3); var obj = { foo: 'bar' }; (0, _emberMetal.deprecateProperty)(obj, 'baz', 'foo'); expectDeprecation(); obj.baz = 'bloop'; equal(obj.foo, 'bloop', 'updating baz updates foo'); equal(obj.baz, obj.foo, 'baz and foo are equal'); }); }); enifed('ember-metal/tests/property_did_change_hook', ['internal-test-helpers', 'ember-metal'], function (_internalTestHelpers, _emberMetal) { 'use strict'; QUnit.module('PROPERTY_DID_CHANGE'); (0, _internalTestHelpers.testBoth)('alias and cp', function (get, set) { var _obj; var counts = {}; var obj = (_obj = { child: {} }, _obj[_emberMetal.PROPERTY_DID_CHANGE] = function (keyName) { counts[keyName] = (counts[keyName] || 0) + 1; }, _obj); (0, _emberMetal.defineProperty)(obj, 'cost', (0, _emberMetal.alias)('child.cost')); (0, _emberMetal.defineProperty)(obj, 'tax', (0, _emberMetal.alias)('child.tax')); (0, _emberMetal.defineProperty)(obj, 'total', (0, _emberMetal.computed)('cost', 'tax', { get: function () { return get(this, 'cost') + get(this, 'tax'); } })); ok(!(0, _emberMetal.isWatching)(obj, 'child.cost'), 'precond alias target `child.cost` is not watched'); equal(get(obj, 'cost'), undefined); // this is how PROPERTY_DID_CHANGE will get notified ok((0, _emberMetal.isWatching)(obj, 'child.cost'), 'alias target `child.cost` is watched after consumption'); ok(!(0, _emberMetal.isWatching)(obj, 'child.tax'), 'precond alias target `child.tax` is not watched'); equal(get(obj, 'tax'), undefined); // this is how PROPERTY_DID_CHANGE will get notified ok((0, _emberMetal.isWatching)(obj, 'child.tax'), 'alias target `child.cost` is watched after consumption'); // increments the watching count on the alias itself to 1 ok(isNaN(get(obj, 'total')), 'total is initialized'); // decrements the watching count on the alias itself to 0 set(obj, 'child', { cost: 399.00, tax: 32.93 }); // this should have called PROPERTY_DID_CHANGE for all of them equal(counts['cost'], 1, 'PROPERTY_DID_CHANGE called with cost'); equal(counts['tax'], 1, 'PROPERTY_DID_CHANGE called with tax'); equal(counts['total'], 1, 'PROPERTY_DID_CHANGE called with total'); // we should still have a dependency installed ok((0, _emberMetal.isWatching)(obj, 'child.cost'), 'watching child.cost'); ok((0, _emberMetal.isWatching)(obj, 'child.tax'), 'watching child.tax'); set(obj, 'child', { cost: 100.00, tax: 10.00 }); equal(counts['cost'], 2, 'PROPERTY_DID_CHANGE called with cost'); equal(counts['tax'], 2, 'PROPERTY_DID_CHANGE called with tax'); equal(counts['total'], 1, 'PROPERTY_DID_CHANGE called with total'); }); }); enifed('ember-metal/tests/run_loop/add_queue_test', ['ember-metal'], function (_emberMetal) { 'use strict'; var originalQueues = _emberMetal.run.queues; var queues = void 0; QUnit.module('system/run_loop/add_queue_test', { setup: function () { _emberMetal.run.queues = queues = ['blork', 'bleep']; }, teardown: function () { _emberMetal.run.queues = originalQueues; } }); QUnit.test('adds a queue after a specified one', function () { _emberMetal.run._addQueue('testeroo', 'blork'); equal(queues.indexOf('testeroo'), 1, 'new queue was added after specified queue'); }); QUnit.test('does not add the queue if it already exists', function () { _emberMetal.run._addQueue('testeroo', 'blork'); _emberMetal.run._addQueue('testeroo', 'blork'); equal(queues.length, 3, 'queue was not added twice'); }); }); enifed('ember-metal/tests/run_loop/debounce_test', ['ember-metal'], function (_emberMetal) { 'use strict'; var originalDebounce = _emberMetal.run.backburner.debounce; var wasCalled = false; QUnit.module('Ember.run.debounce', { setup: function () { _emberMetal.run.backburner.debounce = function () { wasCalled = true; }; }, teardown: function () { _emberMetal.run.backburner.debounce = originalDebounce; } }); QUnit.test('Ember.run.debounce uses Backburner.debounce', function () { _emberMetal.run.debounce(function () {}); ok(wasCalled, 'Ember.run.debounce used'); }); }); enifed('ember-metal/tests/run_loop/later_test', ['ember-metal'], function (_emberMetal) { 'use strict'; var originalSetTimeout = window.setTimeout; var originalDateValueOf = Date.prototype.valueOf; var originalPlatform = _emberMetal.run.backburner._platform; function wait(callback, maxWaitCount) { maxWaitCount = (0, _emberMetal.isNone)(maxWaitCount) ? 100 : maxWaitCount; originalSetTimeout(function () { if (maxWaitCount > 0 && (_emberMetal.run.hasScheduledTimers() || _emberMetal.run.currentRunLoop)) { wait(callback, maxWaitCount - 1); return; } callback(); }, 10); } // Synchronous "sleep". This simulates work being done // after run.later was called but before the run loop // has flushed. In previous versions, this would have // caused the run.later callback to have run from // within the run loop flush, since by the time the // run loop has to flush, it would have considered // the timer already expired. function pauseUntil(time) { // jscs:disable while (+new Date() < time) {} /* do nothing - sleeping */ // jscs:enable } QUnit.module('run.later', { teardown: function () { _emberMetal.run.backburner._platform = originalPlatform; window.setTimeout = originalSetTimeout; Date.prototype.valueOf = originalDateValueOf; } }); asyncTest('should invoke after specified period of time - function only', function () { var invoked = false; (0, _emberMetal.run)(function () { _emberMetal.run.later(function () { return invoked = true; }, 100); }); wait(function () { QUnit.start(); equal(invoked, true, 'should have invoked later item'); }); }); asyncTest('should invoke after specified period of time - target/method', function () { var obj = { invoked: false }; (0, _emberMetal.run)(function () { _emberMetal.run.later(obj, function () { this.invoked = true; }, 100); }); wait(function () { QUnit.start(); equal(obj.invoked, true, 'should have invoked later item'); }); }); asyncTest('should invoke after specified period of time - target/method/args', function () { var obj = { invoked: 0 }; (0, _emberMetal.run)(function () { _emberMetal.run.later(obj, function (amt) { this.invoked += amt; }, 10, 100); }); wait(function () { QUnit.start(); equal(obj.invoked, 10, 'should have invoked later item'); }); }); asyncTest('should always invoke within a separate runloop', function () { var obj = { invoked: 0 }; var firstRunLoop = void 0, secondRunLoop = void 0; (0, _emberMetal.run)(function () { firstRunLoop = _emberMetal.run.currentRunLoop; _emberMetal.run.later(obj, function (amt) { this.invoked += amt; secondRunLoop = _emberMetal.run.currentRunLoop; }, 10, 1); pauseUntil(+new Date() + 100); }); ok(firstRunLoop, 'first run loop captured'); ok(!_emberMetal.run.currentRunLoop, 'shouldn\'t be in a run loop after flush'); equal(obj.invoked, 0, 'shouldn\'t have invoked later item yet'); wait(function () { QUnit.start(); equal(obj.invoked, 10, 'should have invoked later item'); ok(secondRunLoop, 'second run loop took place'); ok(secondRunLoop !== firstRunLoop, 'two different run loops took place'); }); }); // Our current implementation doesn't allow us to correctly enforce this ordering. // We should probably implement a queue to provide this guarantee. // See https://github.com/emberjs/ember.js/issues/3526 for more information. // asyncTest('callback order', function() { // let array = []; // function fn(val) { array.push(val); } // run(function() { // run.later(this, fn, 4, 5); // run.later(this, fn, 1, 1); // run.later(this, fn, 5, 10); // run.later(this, fn, 2, 3); // run.later(this, fn, 3, 3); // }); // deepEqual(array, []); // wait(function() { // QUnit.start(); // deepEqual(array, [1,2,3,4,5], 'callbacks were called in expected order'); // }); // }); // Out current implementation doesn't allow us to properly enforce what is tested here. // We should probably fix it, but it's not technically a bug right now. // See https://github.com/emberjs/ember.js/issues/3522 for more information. // asyncTest('callbacks coalesce into same run loop if expiring at the same time', function() { // let array = []; // function fn(val) { array.push(run.currentRunLoop); } // run(function() { // // Force +new Date to return the same result while scheduling // // run.later timers. Otherwise: non-determinism! // let now = +new Date(); // Date.prototype.valueOf = function() { return now; }; // run.later(this, fn, 10); // run.later(this, fn, 200); // run.later(this, fn, 200); // Date.prototype.valueOf = originalDateValueOf; // }); // deepEqual(array, []); // wait(function() { // QUnit.start(); // equal(array.length, 3, 'all callbacks called'); // ok(array[0] !== array[1], 'first two callbacks have different run loops'); // ok(array[0], 'first runloop present'); // ok(array[1], 'second runloop present'); // equal(array[1], array[2], 'last two callbacks got the same run loop'); // }); // }); asyncTest('inception calls to run.later should run callbacks in separate run loops', function () { var runLoop = void 0, finished = void 0; (0, _emberMetal.run)(function () { runLoop = _emberMetal.run.currentRunLoop; ok(runLoop); _emberMetal.run.later(function () { ok(_emberMetal.run.currentRunLoop && _emberMetal.run.currentRunLoop !== runLoop, 'first later callback has own run loop'); runLoop = _emberMetal.run.currentRunLoop; _emberMetal.run.later(function () { ok(_emberMetal.run.currentRunLoop && _emberMetal.run.currentRunLoop !== runLoop, 'second later callback has own run loop'); finished = true; }, 40); }, 40); }); wait(function () { QUnit.start(); ok(finished, 'all .later callbacks run'); }); }); asyncTest('setTimeout should never run with a negative wait', function () { // Rationale: The old run loop code was susceptible to an occasional // bug where invokeLaterTimers would be scheduled with a setTimeout // with a negative wait. Modern browsers normalize this to 0, but // older browsers (IE <= 8) break with a negative wait, which // happens when an expired timer callback takes a while to run, // which is what we simulate here. var newSetTimeoutUsed = void 0; _emberMetal.run.backburner._platform = { setTimeout: function () { var wait = arguments[arguments.length - 1]; newSetTimeoutUsed = true; ok(!isNaN(wait) && wait >= 0, 'wait is a non-negative number'); return originalPlatform.setTimeout.apply(originalPlatform, arguments); } }; var count = 0; (0, _emberMetal.run)(function () { _emberMetal.run.later(function () { count++; // This will get run first. Waste some time. // This is intended to break invokeLaterTimers code by taking a // long enough time that other timers should technically expire. It's // fine that they're not called in this run loop; just need to // make sure that invokeLaterTimers doesn't end up scheduling // a negative setTimeout. pauseUntil(+new Date() + 60); }, 1); _emberMetal.run.later(function () { equal(count, 1, 'callbacks called in order'); }, 50); }); wait(function () { QUnit.start(); ok(newSetTimeoutUsed, 'stub setTimeout was used'); }); }); }); enifed('ember-metal/tests/run_loop/next_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('run.next'); asyncTest('should invoke immediately on next timeout', function () { var invoked = false; (0, _emberMetal.run)(function () { return _emberMetal.run.next(function () { return invoked = true; }); }); equal(invoked, false, 'should not have invoked yet'); setTimeout(function () { QUnit.start(); equal(invoked, true, 'should have invoked later item'); }, 20); }); asyncTest('callback should be called from within separate loop', function () { var firstRunLoop = void 0, secondRunLoop = void 0; (0, _emberMetal.run)(function () { firstRunLoop = _emberMetal.run.currentRunLoop; _emberMetal.run.next(function () { return secondRunLoop = _emberMetal.run.currentRunLoop; }); }); setTimeout(function () { QUnit.start(); ok(secondRunLoop, 'callback was called from within run loop'); ok(firstRunLoop && secondRunLoop !== firstRunLoop, 'two separate run loops were invoked'); }, 20); }); asyncTest('multiple calls to run.next share coalesce callbacks into same run loop', function () { var secondRunLoop = void 0, thirdRunLoop = void 0; (0, _emberMetal.run)(function () { _emberMetal.run.next(function () { return secondRunLoop = _emberMetal.run.currentRunLoop; }); _emberMetal.run.next(function () { return thirdRunLoop = _emberMetal.run.currentRunLoop; }); }); setTimeout(function () { QUnit.start(); ok(secondRunLoop && secondRunLoop === thirdRunLoop, 'callbacks coalesced into same run loop'); }, 20); }); }); enifed('ember-metal/tests/run_loop/once_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('system/run_loop/once_test'); QUnit.test('calling invokeOnce more than once invokes only once', function () { var count = 0; (0, _emberMetal.run)(function () { function F() { count++; } _emberMetal.run.once(F); _emberMetal.run.once(F); _emberMetal.run.once(F); }); equal(count, 1, 'should have invoked once'); }); QUnit.test('should differentiate based on target', function () { var A = { count: 0 }; var B = { count: 0 }; (0, _emberMetal.run)(function () { function F() { this.count++; } _emberMetal.run.once(A, F); _emberMetal.run.once(B, F); _emberMetal.run.once(A, F); _emberMetal.run.once(B, F); }); equal(A.count, 1, 'should have invoked once on A'); equal(B.count, 1, 'should have invoked once on B'); }); QUnit.test('should ignore other arguments - replacing previous ones', function () { var A = { count: 0 }; var B = { count: 0 }; (0, _emberMetal.run)(function () { function F(amt) { this.count += amt; } _emberMetal.run.once(A, F, 10); _emberMetal.run.once(B, F, 20); _emberMetal.run.once(A, F, 30); _emberMetal.run.once(B, F, 40); }); equal(A.count, 30, 'should have invoked once on A'); equal(B.count, 40, 'should have invoked once on B'); }); QUnit.test('should be inside of a runloop when running', function () { (0, _emberMetal.run)(function () { _emberMetal.run.once(function () { return ok(!!_emberMetal.run.currentRunLoop, 'should have a runloop'); }); }); }); }); enifed('ember-metal/tests/run_loop/onerror_test', ['ember-metal', 'ember-debug'], function (_emberMetal, _emberDebug) { 'use strict'; QUnit.module('system/run_loop/onerror_test'); QUnit.test('With Ember.onerror undefined, errors in Ember.run are thrown', function () { var thrown = new Error('Boom!'); var original = (0, _emberMetal.getOnerror)(); var caught = void 0; (0, _emberMetal.setOnerror)(undefined); try { (0, _emberMetal.run)(function () { throw thrown; }); } catch (error) { caught = error; } finally { (0, _emberMetal.setOnerror)(original); } deepEqual(caught, thrown); }); QUnit.test('With Ember.onerror set, errors in Ember.run are caught', function () { var thrown = new Error('Boom!'); var original = (0, _emberMetal.getOnerror)(); var originalDispatchOverride = (0, _emberMetal.getDispatchOverride)(); var originalIsTesting = (0, _emberDebug.isTesting)(); var caught = void 0; (0, _emberMetal.setOnerror)(function (error) { caught = error; }); (0, _emberMetal.setDispatchOverride)(null); (0, _emberDebug.setTesting)(false); try { (0, _emberMetal.run)(function () { throw thrown; }); } finally { (0, _emberMetal.setOnerror)(original); (0, _emberMetal.setDispatchOverride)(originalDispatchOverride); (0, _emberDebug.setTesting)(originalIsTesting); } deepEqual(caught, thrown); }); }); enifed('ember-metal/tests/run_loop/run_bind_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('system/run_loop/run_bind_test'); QUnit.test('Ember.run.bind builds a run-loop wrapped callback handler', function () { expect(3); var obj = { value: 0, increment: function (increment) { ok(_emberMetal.run.currentRunLoop, 'expected a run-loop'); return this.value += increment; } }; var proxiedFunction = _emberMetal.run.bind(obj, obj.increment, 1); equal(proxiedFunction(), 1); equal(obj.value, 1); }); QUnit.test('Ember.run.bind keeps the async callback arguments', function () { expect(4); function asyncCallback(increment, increment2, increment3) { ok(_emberMetal.run.currentRunLoop, 'expected a run-loop'); equal(increment, 1); equal(increment2, 2); equal(increment3, 3); } (function (fn) { fn(2, 3); })(_emberMetal.run.bind(asyncCallback, asyncCallback, 1)); }); }); enifed('ember-metal/tests/run_loop/run_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('system/run_loop/run_test'); QUnit.test('Ember.run invokes passed function, returning value', function () { var obj = { foo: function () { return [this.bar, 'FOO']; }, bar: 'BAR', checkArgs: function (arg1, arg2) { return [arg1, this.bar, arg2]; } }; equal((0, _emberMetal.run)(function () { return 'FOO'; }), 'FOO', 'pass function only'); deepEqual((0, _emberMetal.run)(obj, obj.foo), ['BAR', 'FOO'], 'pass obj and obj.method'); deepEqual((0, _emberMetal.run)(obj, 'foo'), ['BAR', 'FOO'], 'pass obj and "method"'); deepEqual((0, _emberMetal.run)(obj, obj.checkArgs, 'hello', 'world'), ['hello', 'BAR', 'world'], 'pass obj, obj.method, and extra arguments'); }); }); enifed('ember-metal/tests/run_loop/schedule_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('system/run_loop/schedule_test'); QUnit.test('scheduling item in queue should defer until finished', function () { var cnt = 0; (0, _emberMetal.run)(function () { _emberMetal.run.schedule('actions', function () { return cnt++; }); _emberMetal.run.schedule('actions', function () { return cnt++; }); equal(cnt, 0, 'should not run action yet'); }); equal(cnt, 2, 'should flush actions now'); }); QUnit.test('a scheduled item can be canceled', function (assert) { var hasRan = false; (0, _emberMetal.run)(function () { var cancelId = _emberMetal.run.schedule('actions', function () { return hasRan = true; }); _emberMetal.run.cancel(cancelId); }); assert.notOk(hasRan, 'should not have ran callback run'); }); QUnit.test('nested runs should queue each phase independently', function () { var cnt = 0; (0, _emberMetal.run)(function () { _emberMetal.run.schedule('actions', function () { return cnt++; }); equal(cnt, 0, 'should not run action yet'); (0, _emberMetal.run)(function () { _emberMetal.run.schedule('actions', function () { return cnt++; }); }); equal(cnt, 1, 'should not run action yet'); }); equal(cnt, 2, 'should flush actions now'); }); QUnit.test('prior queues should be flushed before moving on to next queue', function () { var order = []; (0, _emberMetal.run)(function () { var runLoop = _emberMetal.run.currentRunLoop; ok(runLoop, 'run loop present'); _emberMetal.run.schedule('sync', function () { order.push('sync'); equal(runLoop, _emberMetal.run.currentRunLoop, 'same run loop used'); }); _emberMetal.run.schedule('actions', function () { order.push('actions'); equal(runLoop, _emberMetal.run.currentRunLoop, 'same run loop used'); _emberMetal.run.schedule('actions', function () { order.push('actions'); equal(runLoop, _emberMetal.run.currentRunLoop, 'same run loop used'); }); _emberMetal.run.schedule('sync', function () { order.push('sync'); equal(runLoop, _emberMetal.run.currentRunLoop, 'same run loop used'); }); }); _emberMetal.run.schedule('destroy', function () { order.push('destroy'); equal(runLoop, _emberMetal.run.currentRunLoop, 'same run loop used'); }); }); deepEqual(order, ['sync', 'actions', 'sync', 'actions', 'destroy']); }); QUnit.test('makes sure it does not trigger an autorun during testing', function () { expectAssertion(function () { return _emberMetal.run.schedule('actions', function () {}); }, /wrap any code with asynchronous side-effects in a run/); // make sure not just the first violation is asserted. expectAssertion(function () { return _emberMetal.run.schedule('actions', function () {}); }, /wrap any code with asynchronous side-effects in a run/); }); }); enifed('ember-metal/tests/run_loop/sync_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('system/run_loop/sync_test'); QUnit.test('sync() will immediately flush the sync queue only', function () { var cnt = 0; (0, _emberMetal.run)(function () { function cntup() { cnt++; } function syncfunc() { if (++cnt < 5) { _emberMetal.run.schedule('sync', syncfunc); } _emberMetal.run.schedule('actions', cntup); } syncfunc(); equal(cnt, 1, 'should not run action yet'); _emberMetal.run.sync(); equal(cnt, 5, 'should have run sync queue continuously'); }); equal(cnt, 10, 'should flush actions now too'); }); QUnit.test('calling sync() outside a run loop does not cause an error', function () { expect(0); _emberMetal.run.sync(); }); }); enifed('ember-metal/tests/run_loop/unwind_test', ['ember-metal', 'ember-debug'], function (_emberMetal, _emberDebug) { 'use strict'; QUnit.module('system/run_loop/unwind_test'); QUnit.test('RunLoop unwinds despite unhandled exception', function () { var initialRunLoop = _emberMetal.run.currentRunLoop; throws(function () { (0, _emberMetal.run)(function () { _emberMetal.run.schedule('actions', function () { throw new _emberDebug.Error('boom!'); }); }); }, Error, 'boom!'); // The real danger at this point is that calls to autorun will stick // tasks into the already-dead runloop, which will never get // flushed. I can't easily demonstrate this in a unit test because // autorun explicitly doesn't work in test mode. - ef4 equal(_emberMetal.run.currentRunLoop, initialRunLoop, 'Previous run loop should be cleaned up despite exception'); // Prevent a failure in this test from breaking subsequent tests. _emberMetal.run.currentRunLoop = initialRunLoop; }); QUnit.test('run unwinds despite unhandled exception', function () { var initialRunLoop = _emberMetal.run.currentRunLoop; throws(function () { (0, _emberMetal.run)(function () { throw new _emberDebug.Error('boom!'); }); }, _emberDebug.Error, 'boom!'); equal(_emberMetal.run.currentRunLoop, initialRunLoop, 'Previous run loop should be cleaned up despite exception'); // Prevent a failure in this test from breaking subsequent tests. _emberMetal.run.currentRunLoop = initialRunLoop; }); }); enifed('ember-metal/tests/set_properties_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember.setProperties'); QUnit.test('supports setting multiple attributes at once', function () { deepEqual((0, _emberMetal.setProperties)(null, null), null, 'noop for null properties and null object'); deepEqual((0, _emberMetal.setProperties)(undefined, undefined), undefined, 'noop for undefined properties and undefined object'); deepEqual((0, _emberMetal.setProperties)({}), undefined, 'noop for no properties'); deepEqual((0, _emberMetal.setProperties)({}, undefined), undefined, 'noop for undefined'); deepEqual((0, _emberMetal.setProperties)({}, null), null, 'noop for null'); deepEqual((0, _emberMetal.setProperties)({}, NaN), NaN, 'noop for NaN'); deepEqual((0, _emberMetal.setProperties)({}, {}), {}, 'meh'); deepEqual((0, _emberMetal.setProperties)({}, { foo: 1 }), { foo: 1 }, 'Set a single property'); deepEqual((0, _emberMetal.setProperties)({}, { foo: 1, bar: 1 }), { foo: 1, bar: 1 }, 'Set multiple properties'); deepEqual((0, _emberMetal.setProperties)({ foo: 2, baz: 2 }, { foo: 1 }), { foo: 1 }, 'Set one of multiple properties'); deepEqual((0, _emberMetal.setProperties)({ foo: 2, baz: 2 }, { bar: 2 }), { bar: 2 }, 'Set an additional, previously unset property'); }); }); enifed('ember-metal/tests/watching/is_watching_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('isWatching'); function testObserver(setup, teardown) { var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'key'; var obj = {}; function fn() {} equal((0, _emberMetal.isWatching)(obj, key), false, 'precond - isWatching is false by default'); setup(obj, key, fn); equal((0, _emberMetal.isWatching)(obj, key), true, 'isWatching is true when observers are added'); teardown(obj, key, fn); equal((0, _emberMetal.isWatching)(obj, key), false, 'isWatching is false after observers are removed'); } QUnit.test('isWatching is true for regular local observers', function () { testObserver(function (obj, key, fn) { _emberMetal.Mixin.create({ didChange: (0, _emberMetal.observer)(key, fn) }).apply(obj); }, function (obj, key, fn) { return (0, _emberMetal.removeObserver)(obj, key, obj, fn); }); }); QUnit.test('isWatching is true for nonlocal observers', function () { testObserver(function (obj, key, fn) { (0, _emberMetal.addObserver)(obj, key, obj, fn); }, function (obj, key, fn) { return (0, _emberMetal.removeObserver)(obj, key, obj, fn); }); }); QUnit.test('isWatching is true for chained observers', function () { testObserver(function (obj, key, fn) { (0, _emberMetal.addObserver)(obj, key + '.bar', obj, fn); }, function (obj, key, fn) { (0, _emberMetal.removeObserver)(obj, key + '.bar', obj, fn); }); }); QUnit.test('isWatching is true for computed properties', function () { testObserver(function (obj, key, fn) { (0, _emberMetal.defineProperty)(obj, 'computed', (0, _emberMetal.computed)(fn).property(key)); (0, _emberMetal.get)(obj, 'computed'); }, function (obj) { return (0, _emberMetal.defineProperty)(obj, 'computed', null); }); }); QUnit.test('isWatching is true for chained computed properties', function () { testObserver(function (obj, key, fn) { (0, _emberMetal.defineProperty)(obj, 'computed', (0, _emberMetal.computed)(fn).property(key + '.bar')); (0, _emberMetal.get)(obj, 'computed'); }, function (obj) { return (0, _emberMetal.defineProperty)(obj, 'computed', null); }); }); // can't watch length on Array - it is special... // But you should be able to watch a length property of an object QUnit.test('isWatching is true for \'length\' property on object', function () { testObserver(function (obj, key, fn) { (0, _emberMetal.defineProperty)(obj, 'length', null, '26.2 miles'); (0, _emberMetal.addObserver)(obj, 'length', obj, fn); }, function (obj, key, fn) { return (0, _emberMetal.removeObserver)(obj, 'length', obj, fn); }, 'length'); }); }); enifed('ember-metal/tests/watching/unwatch_test', ['internal-test-helpers', 'ember-metal'], function (_internalTestHelpers, _emberMetal) { 'use strict'; var willCount = void 0, didCount = void 0; QUnit.module('unwatch', { setup: function () { willCount = didCount = 0; } }); function addListeners(obj, keyPath) { (0, _emberMetal.addListener)(obj, keyPath + ':before', function () { return willCount++; }); (0, _emberMetal.addListener)(obj, keyPath + ':change', function () { return didCount++; }); } (0, _internalTestHelpers.testBoth)('unwatching a computed property - regular get/set', function (get, set) { var obj = {}; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({ get: function () { return this.__foo; }, set: function (keyName, value) { this.__foo = value; return this.__foo; } })); addListeners(obj, 'foo'); (0, _emberMetal.watch)(obj, 'foo'); set(obj, 'foo', 'bar'); equal(willCount, 1, 'should have invoked willCount'); equal(didCount, 1, 'should have invoked didCount'); (0, _emberMetal.unwatch)(obj, 'foo'); willCount = didCount = 0; set(obj, 'foo', 'BAZ'); equal(willCount, 0, 'should NOT have invoked willCount'); equal(didCount, 0, 'should NOT have invoked didCount'); }); (0, _internalTestHelpers.testBoth)('unwatching a regular property - regular get/set', function (get, set) { var obj = { foo: 'BIFF' }; addListeners(obj, 'foo'); (0, _emberMetal.watch)(obj, 'foo'); set(obj, 'foo', 'bar'); equal(willCount, 1, 'should have invoked willCount'); equal(didCount, 1, 'should have invoked didCount'); (0, _emberMetal.unwatch)(obj, 'foo'); willCount = didCount = 0; set(obj, 'foo', 'BAZ'); equal(willCount, 0, 'should NOT have invoked willCount'); equal(didCount, 0, 'should NOT have invoked didCount'); }); QUnit.test('unwatching should be nested', function () { var obj = { foo: 'BIFF' }; addListeners(obj, 'foo'); (0, _emberMetal.watch)(obj, 'foo'); (0, _emberMetal.watch)(obj, 'foo'); (0, _emberMetal.set)(obj, 'foo', 'bar'); equal(willCount, 1, 'should have invoked willCount'); equal(didCount, 1, 'should have invoked didCount'); (0, _emberMetal.unwatch)(obj, 'foo'); willCount = didCount = 0; (0, _emberMetal.set)(obj, 'foo', 'BAZ'); equal(willCount, 1, 'should NOT have invoked willCount'); equal(didCount, 1, 'should NOT have invoked didCount'); (0, _emberMetal.unwatch)(obj, 'foo'); willCount = didCount = 0; (0, _emberMetal.set)(obj, 'foo', 'BAZ'); equal(willCount, 0, 'should NOT have invoked willCount'); equal(didCount, 0, 'should NOT have invoked didCount'); }); (0, _internalTestHelpers.testBoth)('unwatching "length" property on an object', function (get, set) { var obj = { foo: 'RUN' }; addListeners(obj, 'length'); // Can watch length when it is undefined (0, _emberMetal.watch)(obj, 'length'); set(obj, 'length', '10k'); equal(willCount, 1, 'should have invoked willCount'); equal(didCount, 1, 'should have invoked didCount'); // Should stop watching despite length now being defined (making object 'array-like') (0, _emberMetal.unwatch)(obj, 'length'); willCount = didCount = 0; set(obj, 'length', '5k'); equal(willCount, 0, 'should NOT have invoked willCount'); equal(didCount, 0, 'should NOT have invoked didCount'); }); (0, _internalTestHelpers.testBoth)('unwatching should not destroy non MANDATORY_SETTER descriptor', function () { var obj = { get foo() { return 'RUN'; } }; equal(obj.foo, 'RUN', 'obj.foo'); (0, _emberMetal.watch)(obj, 'foo'); equal(obj.foo, 'RUN', 'obj.foo after watch'); (0, _emberMetal.unwatch)(obj, 'foo'); equal(obj.foo, 'RUN', 'obj.foo after unwatch'); }); }); enifed('ember-metal/tests/watching/watch_test', ['ember-environment', 'ember-metal', 'internal-test-helpers'], function (_emberEnvironment, _emberMetal, _internalTestHelpers) { 'use strict'; var willCount = void 0, didCount = void 0, willKeys = void 0, didKeys = void 0, originalLookup = void 0; QUnit.module('watch', { setup: function () { willCount = didCount = 0; willKeys = []; didKeys = []; originalLookup = _emberEnvironment.context.lookup; _emberEnvironment.context.lookup = {}; }, teardown: function () { _emberEnvironment.context.lookup = originalLookup; } }); function addListeners(obj, keyPath) { (0, _emberMetal.addListener)(obj, keyPath + ':before', function () { willCount++; willKeys.push(keyPath); }); (0, _emberMetal.addListener)(obj, keyPath + ':change', function () { didCount++; didKeys.push(keyPath); }); } (0, _internalTestHelpers.testBoth)('watching a computed property', function (get, set) { var obj = {}; (0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({ get: function () { return this.__foo; }, set: function (keyName, value) { if (value !== undefined) { this.__foo = value; } return this.__foo; } })); addListeners(obj, 'foo'); (0, _emberMetal.watch)(obj, 'foo'); set(obj, 'foo', 'bar'); equal(willCount, 1, 'should have invoked willCount'); equal(didCount, 1, 'should have invoked didCount'); }); (0, _internalTestHelpers.testBoth)('watching a regular defined property', function (get, set) { var obj = { foo: 'baz' }; addListeners(obj, 'foo'); (0, _emberMetal.watch)(obj, 'foo'); equal(get(obj, 'foo'), 'baz', 'should have original prop'); set(obj, 'foo', 'bar'); equal(willCount, 1, 'should have invoked willCount'); equal(didCount, 1, 'should have invoked didCount'); equal(get(obj, 'foo'), 'bar', 'should get new value'); equal(obj.foo, 'bar', 'property should be accessible on obj'); }); (0, _internalTestHelpers.testBoth)('watching a regular undefined property', function (get, set) { var obj = {}; addListeners(obj, 'foo'); (0, _emberMetal.watch)(obj, 'foo'); equal('foo' in obj, false, 'precond undefined'); set(obj, 'foo', 'bar'); equal(willCount, 1, 'should have invoked willCount'); equal(didCount, 1, 'should have invoked didCount'); equal(get(obj, 'foo'), 'bar', 'should get new value'); equal(obj.foo, 'bar', 'property should be accessible on obj'); }); (0, _internalTestHelpers.testBoth)('watches should inherit', function (get, set) { var obj = { foo: 'baz' }; var objB = Object.create(obj); addListeners(obj, 'foo'); (0, _emberMetal.watch)(obj, 'foo'); equal(get(obj, 'foo'), 'baz', 'should have original prop'); set(obj, 'foo', 'bar'); set(objB, 'foo', 'baz'); equal(willCount, 2, 'should have invoked willCount once only'); equal(didCount, 2, 'should have invoked didCount once only'); }); QUnit.test('watching an object THEN defining it should work also', function () { var obj = {}; addListeners(obj, 'foo'); (0, _emberMetal.watch)(obj, 'foo'); (0, _emberMetal.defineProperty)(obj, 'foo'); (0, _emberMetal.set)(obj, 'foo', 'bar'); equal((0, _emberMetal.get)(obj, 'foo'), 'bar', 'should have set'); equal(willCount, 1, 'should have invoked willChange once'); equal(didCount, 1, 'should have invoked didChange once'); }); QUnit.test('watching a chain then defining the property', function () { var obj = {}; var foo = { bar: 'bar' }; addListeners(obj, 'foo.bar'); addListeners(foo, 'bar'); (0, _emberMetal.watch)(obj, 'foo.bar'); (0, _emberMetal.defineProperty)(obj, 'foo', undefined, foo); (0, _emberMetal.set)(foo, 'bar', 'baz'); deepEqual(willKeys, ['foo.bar', 'bar'], 'should have invoked willChange with bar, foo.bar'); deepEqual(didKeys, ['foo.bar', 'bar'], 'should have invoked didChange with bar, foo.bar'); equal(willCount, 2, 'should have invoked willChange twice'); equal(didCount, 2, 'should have invoked didChange twice'); }); QUnit.test('watching a chain then defining the nested property', function () { var bar = {}; var obj = { foo: bar }; var baz = { baz: 'baz' }; addListeners(obj, 'foo.bar.baz'); addListeners(baz, 'baz'); (0, _emberMetal.watch)(obj, 'foo.bar.baz'); (0, _emberMetal.defineProperty)(bar, 'bar', undefined, baz); (0, _emberMetal.set)(baz, 'baz', 'BOO'); deepEqual(willKeys, ['foo.bar.baz', 'baz'], 'should have invoked willChange with bar, foo.bar'); deepEqual(didKeys, ['foo.bar.baz', 'baz'], 'should have invoked didChange with bar, foo.bar'); equal(willCount, 2, 'should have invoked willChange twice'); equal(didCount, 2, 'should have invoked didChange twice'); }); (0, _internalTestHelpers.testBoth)('watching an object value then unwatching should restore old value', function (get) { var obj = { foo: { bar: { baz: { biff: 'BIFF' } } } }; addListeners(obj, 'foo.bar.baz.biff'); (0, _emberMetal.watch)(obj, 'foo.bar.baz.biff'); var foo = get(obj, 'foo'); equal(get(get(get(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist'); (0, _emberMetal.unwatch)(obj, 'foo.bar.baz.biff'); equal(get(get(get(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist'); }); QUnit.test('when watching another object, destroy should remove chain watchers from the other object', function () { var objA = {}; var objB = { foo: 'bar' }; objA.b = objB; addListeners(objA, 'b.foo'); (0, _emberMetal.watch)(objA, 'b.foo'); var meta_objB = (0, _emberMetal.meta)(objB); var chainNode = (0, _emberMetal.meta)(objA).readableChains()._chains.b._chains.foo; equal(meta_objB.peekWatching('foo'), 1, 'should be watching foo'); equal(meta_objB.readableChainWatchers().has('foo', chainNode), true, 'should have chain watcher'); (0, _emberMetal.destroy)(objA); equal(meta_objB.peekWatching('foo'), 0, 'should not be watching foo'); equal(meta_objB.readableChainWatchers().has('foo', chainNode), false, 'should not have chain watcher'); }); // TESTS for length property (0, _internalTestHelpers.testBoth)('watching "length" property on an object', function (get, set) { var obj = { length: '26.2 miles' }; addListeners(obj, 'length'); (0, _emberMetal.watch)(obj, 'length'); equal(get(obj, 'length'), '26.2 miles', 'should have original prop'); set(obj, 'length', '10k'); equal(willCount, 1, 'should have invoked willCount'); equal(didCount, 1, 'should have invoked didCount'); equal(get(obj, 'length'), '10k', 'should get new value'); equal(obj.length, '10k', 'property should be accessible on obj'); }); (0, _internalTestHelpers.testBoth)('watching "length" property on an array', function (get, set) { var arr = []; addListeners(arr, 'length'); (0, _emberMetal.watch)(arr, 'length'); equal(get(arr, 'length'), 0, 'should have original prop'); set(arr, 'length', '10'); equal(willCount, 1, 'should NOT have invoked willCount'); equal(didCount, 1, 'should NOT have invoked didCount'); equal(get(arr, 'length'), 10, 'should get new value'); equal(arr.length, 10, 'property should be accessible on arr'); }); (0, _internalTestHelpers.testBoth)('watch + ES5 getter', function (get) { var parent = { b: 1 }; var child = { get b() { return parent.b; } }; equal(parent.b, 1, 'parent.b should be 1'); equal(child.b, 1, 'child.b should be 1'); equal(get(child, 'b'), 1, 'Ember.get(child, "b") should be 1'); (0, _emberMetal.watch)(child, 'b'); equal(parent.b, 1, 'parent.b should be 1 (after watch)'); equal(child.b, 1, 'child.b should be 1 (after watch)'); equal(get(child, 'b'), 1, 'Ember.get(child, "b") should be 1 (after watch)'); }); (0, _internalTestHelpers.testBoth)('watch + Ember.set + no-descriptor', function (get, set) { var child = {}; equal(child.b, undefined, 'child.b '); equal(get(child, 'b'), undefined, 'Ember.get(child, "b")'); (0, _emberMetal.watch)(child, 'b'); set(child, 'b', 1); equal(child.b, 1, 'child.b (after watch)'); equal(get(child, 'b'), 1, 'Ember.get(child, "b") (after watch)'); }); }); enifed('ember-metal/tests/weak_map_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('Ember.WeakMap'); QUnit.test('has weakMap like qualities', function (assert) { var map = new _emberMetal.WeakMap(); var map2 = new _emberMetal.WeakMap(); var a = {}; var b = {}; var c = {}; assert.strictEqual(map.get(a), undefined); assert.strictEqual(map.get(b), undefined); assert.strictEqual(map.get(c), undefined); assert.strictEqual(map2.get(a), undefined); assert.strictEqual(map2.get(b), undefined); assert.strictEqual(map2.get(c), undefined); assert.strictEqual(map.set(a, 1), map, 'map.set should return itself'); assert.strictEqual(map.get(a), 1); assert.strictEqual(map.set(b, undefined), map); assert.strictEqual(map.set(a, 2), map); assert.strictEqual(map.get(a), 2); assert.strictEqual(map.set(b, undefined), map); assert.strictEqual(map2.get(a), undefined); assert.strictEqual(map2.get(b), undefined); assert.strictEqual(map2.get(c), undefined); assert.strictEqual(map.set(c, 1), map); assert.strictEqual(map.get(c), 1); assert.strictEqual(map.get(a), 2); assert.strictEqual(map.get(b), undefined); assert.strictEqual(map2.set(a, 3), map2); assert.strictEqual(map2.set(b, 4), map2); assert.strictEqual(map2.set(c, 5), map2); assert.strictEqual(map2.get(a), 3); assert.strictEqual(map2.get(b), 4); assert.strictEqual(map2.get(c), 5); assert.strictEqual(map.get(c), 1); assert.strictEqual(map.get(a), 2); assert.strictEqual(map.get(b), undefined); }); QUnit.test('WeakMap constructor requres new', function (assert) { var expectedError = new TypeError('Constructor WeakMap requires \'new\''); assert.throws(function () { // jshint newcap: false (0, _emberMetal.WeakMap)(); }, expectedError); }); QUnit.test('constructing a WeakMap with an invalid iterator throws an error', function (assert) { var expectedError = new TypeError('The weak map constructor polyfill only supports an array argument'); assert.throws(function () { new _emberMetal.WeakMap({ a: 1 }); }, expectedError); }); QUnit.test('constructing a WeakMap with a valid iterator inserts the entries', function (assert) { var a = {}; var b = {}; var c = {}; var map = new _emberMetal.WeakMap([[a, 1], [b, 2], [c, 3]]); assert.strictEqual(map.get(a), 1); assert.strictEqual(map.get(b), 2); assert.strictEqual(map.get(c), 3); }); QUnit.test('that error is thrown when using a primitive key', function (assert) { var expectedError = new TypeError('Invalid value used as weak map key'); var map = new _emberMetal.WeakMap(); assert.throws(function () { return map.set('a', 1); }, expectedError); assert.throws(function () { return map.set(1, 1); }, expectedError); assert.throws(function () { return map.set(true, 1); }, expectedError); assert.throws(function () { return map.set(null, 1); }, expectedError); assert.throws(function () { return map.set(undefined, 1); }, expectedError); }); QUnit.test('that .has and .delete work as expected', function (assert) { var map = new _emberMetal.WeakMap(); var a = {}; var foo = { id: 1, name: 'My file', progress: 0 }; assert.strictEqual(map.set(a, foo), map); assert.strictEqual(map.get(a), foo); assert.strictEqual(map.has(a), true); assert.strictEqual(map.has({}), false); assert.strictEqual(map.delete(a), true); assert.strictEqual(map.has(a), false); assert.strictEqual(map.delete(a), false); assert.strictEqual(map.set(a, undefined), map); assert.strictEqual(map.has(a), true); assert.strictEqual(map.delete(a), true); assert.strictEqual(map.delete(a), false); assert.strictEqual(map.has(a), false); }); QUnit.test('that .toString works as expected', function (assert) { var map = new _emberMetal.WeakMap(); assert.strictEqual(map.toString(), '[object WeakMap]'); }); }); enifed('ember-routing/tests/ext/controller_test', ['ember-utils', 'internal-test-helpers', 'ember-runtime'], function (_emberUtils, _internalTestHelpers, _emberRuntime) { 'use strict'; QUnit.module('ember-routing/ext/controller'); QUnit.test('transitionToRoute considers an engine\'s mountPoint', function () { expect(4); var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true, mountPoint: 'foo.bar' } }); var controller = _emberRuntime.Controller.create({ target: { transitionTo: function (route) { return route; } } }); (0, _emberUtils.setOwner)(controller, engineInstance); strictEqual(controller.transitionToRoute('application'), 'foo.bar.application', 'properly prefixes application route'); strictEqual(controller.transitionToRoute('posts'), 'foo.bar.posts', 'properly prefixes child routes'); throws(function () { return controller.transitionToRoute('/posts'); }, 'throws when trying to use a url'); var queryParams = {}; strictEqual(controller.transitionToRoute(queryParams), queryParams, 'passes query param only transitions through'); }); }); enifed('ember-routing/tests/location/auto_location_test', ['ember-utils', 'ember-environment', 'ember-metal', 'ember-routing/location/auto_location', 'ember-routing/location/history_location', 'ember-routing/location/hash_location', 'ember-routing/location/none_location', 'internal-test-helpers'], function (_emberUtils, _emberEnvironment, _emberMetal, _auto_location, _history_location, _hash_location, _none_location, _internalTestHelpers) { 'use strict'; function mockBrowserLocation(overrides) { return (0, _emberUtils.assign)({ href: 'http://test.com/', pathname: '/', hash: '', search: '', replace: function () { ok(false, 'location.replace should not be called during testing'); } }, overrides); } function mockBrowserHistory(overrides) { return (0, _emberUtils.assign)({ pushState: function () { ok(false, 'history.pushState should not be called during testing'); }, replaceState: function () { ok(false, 'history.replaceState should not be called during testing'); } }, overrides); } function createLocation(location, history) { var _AutoLocation$create; var owner = (0, _internalTestHelpers.buildOwner)(); owner.register('location:history', _history_location.default); owner.register('location:hash', _hash_location.default); owner.register('location:none', _none_location.default); var autolocation = _auto_location.default.create((_AutoLocation$create = {}, _AutoLocation$create[_emberUtils.OWNER] = owner, _AutoLocation$create.location = location, _AutoLocation$create.history = history, _AutoLocation$create.global = {}, _AutoLocation$create)); return autolocation; } var location = void 0; QUnit.module('Ember.AutoLocation', { teardown: function () { if (location) { (0, _emberMetal.run)(location, 'destroy'); } } }); QUnit.test('AutoLocation should have the `global`', function (assert) { var location = _auto_location.default.create(); assert.ok(location.global, 'has a global defined'); assert.strictEqual(location.global, _emberEnvironment.environment.window, 'has the environments window global'); }); QUnit.test('AutoLocation should return concrete implementation\'s value for `getURL`', function () { expect(1); var browserLocation = mockBrowserLocation(); var browserHistory = mockBrowserHistory(); location = createLocation(browserLocation, browserHistory); location.detect(); var concreteImplementation = (0, _emberMetal.get)(location, 'concreteImplementation'); concreteImplementation.getURL = function () { return '/lincoln/park'; }; equal(location.getURL(), '/lincoln/park'); }); QUnit.test('AutoLocation should use a HistoryLocation instance when pushStates is supported', function () { expect(1); var browserLocation = mockBrowserLocation(); var browserHistory = mockBrowserHistory(); location = createLocation(browserLocation, browserHistory); location.detect(); ok((0, _emberMetal.get)(location, 'concreteImplementation') instanceof _history_location.default); }); QUnit.test('AutoLocation should use a HashLocation instance when pushStates are not supported, but hashchange events are and the URL is already in the HashLocation format', function () { expect(1); var browserLocation = mockBrowserLocation({ hash: '#/testd' }); location = createLocation(browserLocation); location.global = { onhashchange: function () {} }; location.detect(); ok((0, _emberMetal.get)(location, 'concreteImplementation') instanceof _hash_location.default); }); QUnit.test('AutoLocation should use a NoneLocation instance when neither history nor hashchange are supported.', function () { expect(1); location = createLocation(mockBrowserLocation()); location.detect(); ok((0, _emberMetal.get)(location, 'concreteImplementation') instanceof _none_location.default); }); QUnit.test('AutoLocation should use an index path (i.e. \'/\') without any location.hash as OK for HashLocation', function () { expect(1); var browserLocation = mockBrowserLocation({ href: 'http://test.com/', pathname: '/', hash: '', search: '', replace: function () { ok(false, 'location.replace should not be called'); } }); location = createLocation(browserLocation); location.global = { onhashchange: function () {} }; location.detect(); ok((0, _emberMetal.get)(location, 'concreteImplementation') instanceof _hash_location.default, 'uses a HashLocation'); }); QUnit.test('AutoLocation should transform the URL for hashchange-only browsers viewing a HistoryLocation-formatted path', function () { expect(3); var browserLocation = mockBrowserLocation({ hash: '', hostname: 'test.com', href: 'http://test.com/test', pathname: '/test', protocol: 'http:', port: '', search: '', replace: function (path) { equal(path, 'http://test.com/#/test', 'location.replace should be called with normalized HashLocation path'); } }); var location = createLocation(browserLocation); location.global = { onhashchange: function () {} }; location.detect(); ok((0, _emberMetal.get)(location, 'concreteImplementation') instanceof _none_location.default, 'NoneLocation should be used while we attempt to location.replace()'); equal((0, _emberMetal.get)(location, 'cancelRouterSetup'), true, 'cancelRouterSetup should be set so the router knows.'); }); QUnit.test('AutoLocation should replace the URL for pushState-supported browsers viewing a HashLocation-formatted url', function () { expect(2); var browserLocation = mockBrowserLocation({ hash: '#/test', hostname: 'test.com', href: 'http://test.com/#/test', pathname: '/', protocol: 'http:', port: '', search: '' }); var browserHistory = mockBrowserHistory({ replaceState: function (state, title, path) { equal(path, '/test', 'history.replaceState should be called with normalized HistoryLocation url'); } }); var location = createLocation(browserLocation, browserHistory); location.detect(); ok((0, _emberMetal.get)(location, 'concreteImplementation'), _history_location.default); }); QUnit.test('AutoLocation requires any rootURL given to end in a trailing forward slash', function () { expect(3); var browserLocation = mockBrowserLocation(); var expectedMsg = /rootURL must end with a trailing forward slash e.g. "\/app\/"/; location = createLocation(browserLocation); location.rootURL = 'app'; expectAssertion(function () { location.detect(); }, expectedMsg); location.rootURL = '/app'; expectAssertion(function () { location.detect(); }, expectedMsg); // Note the trailing whitespace location.rootURL = '/app/ '; expectAssertion(function () { location.detect(); }, expectedMsg); }); QUnit.test('AutoLocation provides its rootURL to the concreteImplementation', function () { expect(1); var browserLocation = mockBrowserLocation({ pathname: '/some/subdir/derp' }); var browserHistory = mockBrowserHistory(); location = createLocation(browserLocation, browserHistory); location.rootURL = '/some/subdir/'; location.detect(); var concreteLocation = (0, _emberMetal.get)(location, 'concreteImplementation'); equal(location.rootURL, concreteLocation.rootURL); }); QUnit.test('getHistoryPath() should return a normalized, HistoryLocation-supported path', function () { expect(3); var browserLocation = mockBrowserLocation({ href: 'http://test.com/app/about?foo=bar#foo', pathname: '/app/about', search: '?foo=bar', hash: '#foo' }); equal((0, _auto_location.getHistoryPath)('/app/', browserLocation), '/app/about?foo=bar#foo', 'URLs already in HistoryLocation form should come out the same'); browserLocation = mockBrowserLocation({ href: 'http://test.com/app/#/about?foo=bar#foo', pathname: '/app/', search: '', hash: '#/about?foo=bar#foo' }); equal((0, _auto_location.getHistoryPath)('/app/', browserLocation), '/app/about?foo=bar#foo', 'HashLocation formed URLs should be normalized'); browserLocation = mockBrowserLocation({ href: 'http://test.com/app/#about?foo=bar#foo', pathname: '/app/', search: '', hash: '#about?foo=bar#foo' }); equal((0, _auto_location.getHistoryPath)('/app', browserLocation), '/app/#about?foo=bar#foo', 'URLs with a hash not following #/ convention shouldn\'t be normalized as a route'); }); QUnit.test('getHashPath() should return a normalized, HashLocation-supported path', function () { expect(3); var browserLocation = mockBrowserLocation({ href: 'http://test.com/app/#/about?foo=bar#foo', pathname: '/app/', search: '', hash: '#/about?foo=bar#foo' }); equal((0, _auto_location.getHashPath)('/app/', browserLocation), '/app/#/about?foo=bar#foo', 'URLs already in HistoryLocation form should come out the same'); browserLocation = mockBrowserLocation({ href: 'http://test.com/app/about?foo=bar#foo', pathname: '/app/about', search: '?foo=bar', hash: '#foo' }); equal((0, _auto_location.getHashPath)('/app/', browserLocation), '/app/#/about?foo=bar#foo', 'HistoryLocation formed URLs should be normalized'); browserLocation = mockBrowserLocation({ href: 'http://test.com/app/#about?foo=bar#foo', pathname: '/app/', search: '', hash: '#about?foo=bar#foo' }); equal((0, _auto_location.getHashPath)('/app/', browserLocation), '/app/#/#about?foo=bar#foo', 'URLs with a hash not following #/ convention shouldn\'t be normalized as a route'); }); }); enifed('ember-routing/tests/location/hash_location_test', ['ember-metal', 'ember-routing/location/hash_location'], function (_emberMetal, _hash_location) { 'use strict'; var HashTestLocation = void 0, location = void 0; function createLocation(options) { if (!options) { options = {}; } location = HashTestLocation.create(options); } function mockBrowserLocation(path) { // This is a neat trick to auto-magically extract the hostname from any // url by letting the browser do the work ;) var tmp = document.createElement('a'); tmp.href = path; var protocol = !tmp.protocol || tmp.protocol === ':' ? 'http' : tmp.protocol; var pathname = tmp.pathname.match(/^\//) ? tmp.pathname : '/' + tmp.pathname; return { hash: tmp.hash, host: tmp.host || 'localhost', hostname: tmp.hostname || 'localhost', href: tmp.href, pathname: pathname, port: tmp.port || '', protocol: protocol, search: tmp.search }; } function triggerHashchange() { var event = document.createEvent('HTMLEvents'); event.initEvent('hashchange', true, false); window.dispatchEvent(event); } QUnit.module('Ember.HashLocation', { setup: function () { HashTestLocation = _hash_location.default.extend({ _location: { href: 'http://test.com/', pathname: '/', hash: '', search: '', replace: function () { ok(false, 'location.replace should not be called during testing'); } } }); }, teardown: function () { (0, _emberMetal.run)(function () { if (location) { location.destroy(); } }); } }); QUnit.test('HashLocation.getURL() returns the current url', function () { expect(1); createLocation({ _location: mockBrowserLocation('/#/foo/bar') }); equal(location.getURL(), '/foo/bar'); }); QUnit.test('HashLocation.getURL() includes extra hashes', function () { expect(1); createLocation({ _location: mockBrowserLocation('/#/foo#bar#car') }); equal(location.getURL(), '/foo#bar#car'); }); QUnit.test('HashLocation.getURL() assumes location.hash without #/ prefix is not a route path', function () { expect(1); createLocation({ _location: mockBrowserLocation('/#foo#bar') }); equal(location.getURL(), '/#foo#bar'); }); QUnit.test('HashLocation.getURL() returns a normal forward slash when there is no location.hash', function () { expect(1); createLocation({ _location: mockBrowserLocation('/') }); equal(location.getURL(), '/'); }); QUnit.test('HashLocation.setURL() correctly sets the url', function () { expect(2); createLocation(); location.setURL('/bar'); equal((0, _emberMetal.get)(location, 'location.hash'), '/bar'); equal((0, _emberMetal.get)(location, 'lastSetURL'), '/bar'); }); QUnit.test('HashLocation.replaceURL() correctly replaces to the path with a page reload', function () { expect(2); createLocation({ _location: { replace: function (path) { equal(path, '#/foo'); } } }); location.replaceURL('/foo'); equal((0, _emberMetal.get)(location, 'lastSetURL'), '/foo'); }); QUnit.test('HashLocation.onUpdateURL callback executes as expected', function () { expect(1); createLocation({ _location: mockBrowserLocation('/#/foo/bar') }); location.onUpdateURL(function (param) { equal(param, '/foo/bar', 'path is passed as param'); }); triggerHashchange(); }); QUnit.test('HashLocation.onUpdateURL doesn\'t execute callback if lastSetURL === path', function () { expect(0); createLocation({ _location: { href: '/#/foo/bar' }, lastSetURL: '/foo/bar' }); location.onUpdateURL(function () { ok(false, 'callback should not be called'); }); triggerHashchange(); }); QUnit.test('HashLocation.formatURL() prepends a # to the provided string', function () { expect(1); createLocation(); equal(location.formatURL('/foo#bar'), '#/foo#bar'); }); QUnit.test('HashLocation.willDestroy() cleans up hashchange event listener', function () { expect(1); createLocation(); location.onUpdateURL(function () { ok(true, 'should invoke callback once'); }); triggerHashchange(); (0, _emberMetal.run)(location, 'destroy'); location = null; triggerHashchange(); }); }); enifed('ember-routing/tests/location/history_location_test', ['ember-metal', 'ember-routing/location/history_location'], function (_emberMetal, _history_location) { 'use strict'; var FakeHistory = void 0, HistoryTestLocation = void 0, location = void 0; function createLocation(options) { if (!options) { options = {}; } location = HistoryTestLocation.create(options); } function mockBrowserLocation(path) { // This is a neat trick to auto-magically extract the hostname from any // url by letting the browser do the work ;) var tmp = document.createElement('a'); tmp.href = path; var protocol = !tmp.protocol || tmp.protocol === ':' ? 'http' : tmp.protocol; var pathname = tmp.pathname.match(/^\//) ? tmp.pathname : '/' + tmp.pathname; return { hash: tmp.hash, host: tmp.host || 'localhost', hostname: tmp.hostname || 'localhost', href: tmp.href, pathname: pathname, port: tmp.port || '', protocol: protocol, search: tmp.search }; } QUnit.module('Ember.HistoryLocation', { setup: function () { FakeHistory = { state: null, _states: [], replaceState: function (state) { this.state = state; this._states[0] = state; }, pushState: function (state) { this.state = state; this._states.unshift(state); } }; HistoryTestLocation = _history_location.default.extend({ history: FakeHistory }); }, teardown: function () { (0, _emberMetal.run)(function () { if (location) { location.destroy(); } }); } }); QUnit.test('HistoryLocation initState does not get fired on init', function () { expect(1); HistoryTestLocation.reopen({ init: function () { ok(true, 'init was called'); this._super.apply(this, arguments); }, initState: function () { ok(false, 'initState() should not be called automatically'); } }); createLocation(); }); QUnit.test('webkit doesn\'t fire popstate on page load', function () { expect(1); HistoryTestLocation.reopen({ initState: function () { this._super.apply(this, arguments); // these two should be equal to be able // to successfully detect webkit initial popstate equal(this._previousURL, this.getURL()); } }); createLocation(); location.initState(); }); QUnit.test('base URL is removed when retrieving the current pathname', function () { expect(1); HistoryTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'location', mockBrowserLocation('/base/foo/bar')); (0, _emberMetal.set)(this, 'baseURL', '/base/'); }, initState: function () { this._super.apply(this, arguments); equal(this.getURL(), '/foo/bar'); } }); createLocation(); location.initState(); }); QUnit.test('base URL is preserved when moving around', function () { expect(2); HistoryTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'location', mockBrowserLocation('/base/foo/bar')); (0, _emberMetal.set)(this, 'baseURL', '/base/'); } }); createLocation(); location.initState(); location.setURL('/one/two'); equal(location._historyState.path, '/base/one/two'); ok(location._historyState.uuid); }); QUnit.test('setURL continues to set even with a null state (iframes may set this)', function () { expect(2); createLocation(); location.initState(); FakeHistory.pushState(null); location.setURL('/three/four'); equal(location._historyState.path, '/three/four'); ok(location._historyState.uuid); }); QUnit.test('replaceURL continues to set even with a null state (iframes may set this)', function () { expect(2); createLocation(); location.initState(); FakeHistory.pushState(null); location.replaceURL('/three/four'); equal(location._historyState.path, '/three/four'); ok(location._historyState.uuid); }); QUnit.test('HistoryLocation.getURL() returns the current url, excluding both rootURL and baseURL', function () { expect(1); HistoryTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'location', mockBrowserLocation('/base/foo/bar')); (0, _emberMetal.set)(this, 'rootURL', '/app/'); (0, _emberMetal.set)(this, 'baseURL', '/base/'); } }); createLocation(); equal(location.getURL(), '/foo/bar'); }); QUnit.test('HistoryLocation.getURL() returns the current url, does not remove rootURL if its not at start of url', function () { expect(1); HistoryTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'location', mockBrowserLocation('/foo/bar/baz')); (0, _emberMetal.set)(this, 'rootURL', '/bar/'); } }); createLocation(); equal(location.getURL(), '/foo/bar/baz'); }); QUnit.test('HistoryLocation.getURL() will not remove the rootURL when only a partial match', function () { expect(1); HistoryTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'location', mockBrowserLocation('/bars/baz')); (0, _emberMetal.set)(this, 'rootURL', '/bar/'); } }); createLocation(); equal(location.getURL(), '/bars/baz'); }); QUnit.test('HistoryLocation.getURL() returns the current url, does not remove baseURL if its not at start of url', function () { expect(1); HistoryTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'location', mockBrowserLocation('/foo/bar/baz')); (0, _emberMetal.set)(this, 'baseURL', '/bar/'); } }); createLocation(); equal(location.getURL(), '/foo/bar/baz'); }); QUnit.test('HistoryLocation.getURL() will not remove the baseURL when only a partial match', function () { expect(1); HistoryTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'location', mockBrowserLocation('/bars/baz')); (0, _emberMetal.set)(this, 'baseURL', '/bar/'); } }); createLocation(); equal(location.getURL(), '/bars/baz'); }); QUnit.test('HistoryLocation.getURL() includes location.search', function () { expect(1); HistoryTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'location', mockBrowserLocation('/foo/bar?time=morphin')); } }); createLocation(); equal(location.getURL(), '/foo/bar?time=morphin'); }); QUnit.test('HistoryLocation.getURL() includes location.hash', function () { expect(1); HistoryTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'location', mockBrowserLocation('/foo/bar#pink-power-ranger')); } }); createLocation(); equal(location.getURL(), '/foo/bar#pink-power-ranger'); }); QUnit.test('HistoryLocation.getURL() includes location.hash and location.search', function () { expect(1); HistoryTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'location', mockBrowserLocation('/foo/bar?time=morphin#pink-power-ranger')); } }); createLocation(); equal(location.getURL(), '/foo/bar?time=morphin#pink-power-ranger'); }); QUnit.test('HistoryLocation.getURL() drops duplicate slashes', function () { expect(1); HistoryTestLocation.reopen({ init: function () { this._super.apply(this, arguments); var location = mockBrowserLocation('//'); location.pathname = '//'; // mockBrowserLocation does not allow for `//`, so force it (0, _emberMetal.set)(this, 'location', location); } }); createLocation(); equal(location.getURL(), '/'); }); }); enifed('ember-routing/tests/location/none_location_test', ['ember-metal', 'ember-routing/location/none_location'], function (_emberMetal, _none_location) { 'use strict'; var NoneTestLocation = void 0, location = void 0; function createLocation(options) { if (!options) { options = {}; } location = NoneTestLocation.create(options); } QUnit.module('Ember.NoneLocation', { setup: function () { NoneTestLocation = _none_location.default.extend({}); }, teardown: function () { (0, _emberMetal.run)(function () { if (location) { location.destroy(); } }); } }); QUnit.test('NoneLocation.formatURL() returns the current url always appending rootURL', function () { expect(1); NoneTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'rootURL', '/en/'); } }); createLocation(); equal(location.formatURL('/foo/bar'), '/en/foo/bar'); }); QUnit.test('NoneLocation.getURL() returns the current path minus rootURL', function () { expect(1); NoneTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'rootURL', '/foo/'); (0, _emberMetal.set)(this, 'path', '/foo/bar'); } }); createLocation(); equal(location.getURL(), '/bar'); }); QUnit.test('NoneLocation.getURL() will remove the rootURL only from the beginning of a url', function () { expect(1); NoneTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'rootURL', '/bar/'); (0, _emberMetal.set)(this, 'path', '/foo/bar/baz'); } }); createLocation(); equal(location.getURL(), '/foo/bar/baz'); }); QUnit.test('NoneLocation.getURL() will not remove the rootURL when only a partial match', function () { expect(1); NoneTestLocation.reopen({ init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'rootURL', '/bar/'); (0, _emberMetal.set)(this, 'path', '/bars/baz'); } }); createLocation(); equal(location.getURL(), '/bars/baz'); }); }); enifed('ember-routing/tests/location/util_test', ['ember-utils', 'ember-routing/location/util'], function (_emberUtils, _util) { 'use strict'; function mockBrowserLocation(overrides) { return (0, _emberUtils.assign)({ href: 'http://test.com/', pathname: '/', hash: '', search: '', replace: function () { ok(false, 'location.replace should not be called during testing'); } }, overrides); } QUnit.module('Location Utilities'); QUnit.test('replacePath cannot be used to redirect to a different origin', function () { expect(1); var expectedURL = void 0; expectedURL = 'http://emberjs.com:1337//google.com'; (0, _util.replacePath)({ protocol: 'http:', hostname: 'emberjs.com', port: '1337', replace: function (url) { equal(url, expectedURL); } }, '//google.com'); }); QUnit.test('getPath() should normalize location.pathname, making sure it always returns a leading slash', function () { expect(2); var location = mockBrowserLocation({ pathname: 'test' }); equal((0, _util.getPath)(location), '/test', 'When there is no leading slash, one is added.'); location = mockBrowserLocation({ pathname: '/test' }); equal((0, _util.getPath)(location), '/test', 'When a leading slash is already there, it isn\'t added again'); }); QUnit.test('getQuery() should return location.search as-is', function () { expect(1); var location = mockBrowserLocation({ search: '?foo=bar' }); equal((0, _util.getQuery)(location), '?foo=bar'); }); QUnit.test('getFullPath() should return full pathname including query and hash', function () { expect(1); var location = mockBrowserLocation({ href: 'http://test.com/about?foo=bar#foo', pathname: '/about', search: '?foo=bar', hash: '#foo' }); equal((0, _util.getFullPath)(location), '/about?foo=bar#foo'); }); QUnit.test('Feature-Detecting onhashchange', function () { equal((0, _util.supportsHashChange)(undefined, { onhashchange: function () {} }), true, 'When not in IE, use onhashchange existence as evidence of the feature'); equal((0, _util.supportsHashChange)(undefined, {}), false, 'When not in IE, use onhashchange absence as evidence of the feature absence'); equal((0, _util.supportsHashChange)(7, { onhashchange: function () {} }), false, 'When in IE7 compatibility mode, never report existence of the feature'); equal((0, _util.supportsHashChange)(8, { onhashchange: function () {} }), true, 'When in IE8+, use onhashchange existence as evidence of the feature'); }); // jscs:disable QUnit.test("Feature-detecting the history API", function () { equal((0, _util.supportsHistory)("", { pushState: true }), true, "returns true if not Android Gingerbread and history.pushState exists"); equal((0, _util.supportsHistory)("", {}), false, "returns false if history.pushState doesn't exist"); equal((0, _util.supportsHistory)("", undefined), false, "returns false if history doesn't exist"); equal((0, _util.supportsHistory)("Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", { pushState: true }), false, "returns false if Android 2.x stock browser (not Chrome) claiming to support pushState"); equal((0, _util.supportsHistory)("Mozilla/5.0 (Linux; U; Android 4.0.3; nl-nl; GT-N7000 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", { pushState: true }), false, "returns false for Android 4.0.x stock browser (not Chrome) claiming to support pushState"); equal((0, _util.supportsHistory)("Mozilla/5.0 (Linux; U; Android 20.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", { pushState: true }), true, "returns true if Android version begins with 2, but is greater than 2"); equal((0, _util.supportsHistory)("Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19", { pushState: true }), true, "returns true for Chrome (not stock browser) on Android 4.0.x"); // Windows Phone UA and History API: https://github.com/Modernizr/Modernizr/issues/1471 equal((0, _util.supportsHistory)("Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Virtual) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537", { pushState: true }), true, "returns true for Windows Phone 8.1 with misleading user agent string"); }); // jscs:enable }); enifed('ember-routing/tests/system/cache_test', ['ember-routing/system/cache'], function (_cache) { 'use strict'; QUnit.module('BucketCache', { setup: function () { this.cache = _cache.default.create(); } }); QUnit.test('has - returns false when bucket is not in cache', function (assert) { assert.strictEqual(this.cache.has('foo'), false); assert.strictEqual(this.cache.has('constructor'), false); }); QUnit.test('has - returns true when bucket is in cache', function (assert) { var token = {}; this.cache.stash('foo', 'bar', token); this.cache.stash('constructor', 'bar', token); assert.strictEqual(this.cache.has('foo'), true); assert.strictEqual(this.cache.has('constructor'), true); }); QUnit.test('lookup - returns stashed value if key does exist in bucket', function (assert) { var token = {}; this.cache.stash('foo', 'bar', token); assert.strictEqual(this.cache.lookup('foo', 'bar', {}), token); }); QUnit.test('lookup - returns default value if key does not exist in bucket', function (assert) { var defaultValue = {}; this.cache.stash('foo', 'bar', {}); assert.strictEqual(this.cache.lookup('foo', 'boo', defaultValue), defaultValue); assert.strictEqual(this.cache.lookup('foo', 'constructor', defaultValue), defaultValue); }); QUnit.test('lookup - returns default value if bucket does not exist', function (assert) { var defaultValue = {}; assert.strictEqual(this.cache.lookup('boo', 'bar', defaultValue), defaultValue); assert.strictEqual(this.cache.lookup('constructor', 'bar', defaultValue), defaultValue); }); }); enifed('ember-routing/tests/system/controller_for_test', ['ember-babel', 'ember-runtime', 'ember-routing/system/controller_for', 'ember-routing/system/generate_controller', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _controller_for, _generate_controller, _internalTestHelpers) { 'use strict'; (0, _internalTestHelpers.moduleFor)('Ember.controllerFor', function (_ApplicationTestCase) { (0, _emberBabel.inherits)(_class, _ApplicationTestCase); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments)); } _class.prototype['@test controllerFor should lookup for registered controllers'] = function (assert) { var _this2 = this; this.add('controller:app', _emberRuntime.Controller.extend()); return this.visit('/').then(function () { var appInstance = _this2.applicationInstance; var appController = appInstance.lookup('controller:app'); var controller = (0, _controller_for.default)(appInstance, 'app'); assert.equal(appController, controller, 'should find app controller'); }); }; return _class; }(_internalTestHelpers.ApplicationTestCase)); (0, _internalTestHelpers.moduleFor)('Ember.generateController', function (_ApplicationTestCase2) { (0, _emberBabel.inherits)(_class2, _ApplicationTestCase2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase2.apply(this, arguments)); } _class2.prototype['@test generateController should return Ember.Controller'] = function (assert) { var _this4 = this; return this.visit('/').then(function () { var controller = (0, _generate_controller.default)(_this4.applicationInstance, 'home'); assert.ok(controller instanceof _emberRuntime.Controller, 'should return controller'); }); }; _class2.prototype['@test generateController should return controller:basic if resolved'] = function (assert) { var _this5 = this; var BasicController = _emberRuntime.Controller.extend(); this.add('controller:basic', BasicController); return this.visit('/').then(function () { var controller = (0, _generate_controller.default)(_this5.applicationInstance, 'home'); assert.ok(controller instanceof BasicController, 'should return controller'); }); }; _class2.prototype['@test generateController should return controller:basic if registered'] = function (assert) { var _this6 = this; var BasicController = _emberRuntime.Controller.extend(); this.application.register('controller:basic', BasicController); return this.visit('/').then(function () { var controller = (0, _generate_controller.default)(_this6.applicationInstance, 'home'); assert.ok(controller instanceof BasicController, 'should return base class of controller'); }); }; return _class2; }(_internalTestHelpers.ApplicationTestCase)); }); enifed('ember-routing/tests/system/dsl_test', ['ember-utils', 'ember-routing/system/router', 'internal-test-helpers'], function (_emberUtils, _router, _internalTestHelpers) { 'use strict'; var Router = void 0; function setup() { Router = _router.default.extend(); } function teardown() { Router = null; } QUnit.module('Ember Router DSL', { setup: setup, teardown: teardown }); QUnit.test('should fail when using a reserved route name', function () { expectDeprecation('this.resource() is deprecated. Use this.route(\'name\', { resetNamespace: true }, function () {}) instead.'); var reservedNames = ['array', 'basic', 'object', 'application']; expect(reservedNames.length * 2 + 1); reservedNames.forEach(function (reservedName) { expectAssertion(function () { Router = _router.default.extend(); Router.map(function () { this.route(reservedName); }); var router = Router.create(); router._initRouterJs(); }, '\'' + reservedName + '\' cannot be used as a route name.'); expectAssertion(function () { Router = _router.default.extend(); Router.map(function () { this.resource(reservedName); }); var router = Router.create(); router._initRouterJs(); }, '\'' + reservedName + '\' cannot be used as a route name.'); }); }); QUnit.test('should reset namespace if nested with resource', function () { expectDeprecation('this.resource() is deprecated. Use this.route(\'name\', { resetNamespace: true }, function () {}) instead.'); Router = Router.map(function () { this.resource('bleep', function () { this.resource('bloop', function () { this.resource('blork'); }); }); }); var router = Router.create(); router._initRouterJs(); ok(router._routerMicrolib.recognizer.names['bleep'], 'nested resources do not contain parent name'); ok(router._routerMicrolib.recognizer.names['bloop'], 'nested resources do not contain parent name'); ok(router._routerMicrolib.recognizer.names['blork'], 'nested resources do not contain parent name'); }); QUnit.test('should retain resource namespace if nested with routes', function () { Router = Router.map(function () { this.route('bleep', function () { this.route('bloop', function () { this.route('blork'); }); }); }); var router = Router.create(); router._initRouterJs(); ok(router._routerMicrolib.recognizer.names['bleep'], 'parent name was used as base of nested routes'); ok(router._routerMicrolib.recognizer.names['bleep.bloop'], 'parent name was used as base of nested routes'); ok(router._routerMicrolib.recognizer.names['bleep.bloop.blork'], 'parent name was used as base of nested routes'); }); QUnit.test('should add loading and error routes if _isRouterMapResult is true', function () { Router.map(function () { this.route('blork'); }); var router = Router.create({ _hasModuleBasedResolver: function () { return true; } }); router._initRouterJs(); ok(router._routerMicrolib.recognizer.names['blork'], 'main route was created'); ok(router._routerMicrolib.recognizer.names['blork_loading'], 'loading route was added'); ok(router._routerMicrolib.recognizer.names['blork_error'], 'error route was added'); }); QUnit.test('should not add loading and error routes if _isRouterMapResult is false', function () { Router.map(function () { this.route('blork'); }); var router = Router.create(); router._initRouterJs(false); ok(router._routerMicrolib.recognizer.names['blork'], 'main route was created'); ok(!router._routerMicrolib.recognizer.names['blork_loading'], 'loading route was not added'); ok(!router._routerMicrolib.recognizer.names['blork_error'], 'error route was not added'); }); QUnit.test('should reset namespace of loading and error routes for routes with resetNamespace', function () { Router.map(function () { this.route('blork', function () { this.route('blorp'); this.route('bleep', { resetNamespace: true }); }); }); var router = Router.create({ _hasModuleBasedResolver: function () { return true; } }); router._initRouterJs(); ok(router._routerMicrolib.recognizer.names['blork.blorp'], 'nested route was created'); ok(router._routerMicrolib.recognizer.names['blork.blorp_loading'], 'nested loading route was added'); ok(router._routerMicrolib.recognizer.names['blork.blorp_error'], 'nested error route was added'); ok(router._routerMicrolib.recognizer.names['bleep'], 'reset route was created'); ok(router._routerMicrolib.recognizer.names['bleep_loading'], 'reset loading route was added'); ok(router._routerMicrolib.recognizer.names['bleep_error'], 'reset error route was added'); ok(!router._routerMicrolib.recognizer.names['blork.bleep'], 'nested reset route was not created'); ok(!router._routerMicrolib.recognizer.names['blork.bleep_loading'], 'nested reset loading route was not added'); ok(!router._routerMicrolib.recognizer.names['blork.bleep_error'], 'nested reset error route was not added'); }); QUnit.test('should throw an error when defining a route serializer outside an engine', function () { Router.map(function () { var _this = this; throws(function () { _this.route('posts', { serialize: function () {} }); }, /Defining a route serializer on route 'posts' outside an Engine is not allowed/); }); Router.create()._initRouterJs(); }); QUnit.module('Ember Router DSL with engines', { setup: setup, teardown: teardown }); QUnit.test('should allow mounting of engines', function (assert) { assert.expect(3); Router = Router.map(function () { this.route('bleep', function () { this.route('bloop', function () { this.mount('chat'); }); }); }); var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true } }); var router = Router.create(); (0, _emberUtils.setOwner)(router, engineInstance); router._initRouterJs(); assert.ok(router._routerMicrolib.recognizer.names['bleep'], 'parent name was used as base of nested routes'); assert.ok(router._routerMicrolib.recognizer.names['bleep.bloop'], 'parent name was used as base of nested routes'); assert.ok(router._routerMicrolib.recognizer.names['bleep.bloop.chat'], 'parent name was used as base of mounted engine'); }); QUnit.test('should allow mounting of engines at a custom path', function (assert) { assert.expect(1); Router = Router.map(function () { this.route('bleep', function () { this.route('bloop', function () { this.mount('chat', { path: 'custom-chat' }); }); }); }); var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true } }); var router = Router.create(); (0, _emberUtils.setOwner)(router, engineInstance); router._initRouterJs(); assert.deepEqual(router._routerMicrolib.recognizer.names['bleep.bloop.chat'].segments.slice(1, 4).map(function (s) { return s.value; }), ['bleep', 'bloop', 'custom-chat'], 'segments are properly associated with mounted engine'); }); QUnit.test('should allow aliasing of engine names with `as`', function (assert) { assert.expect(1); Router = Router.map(function () { this.route('bleep', function () { this.route('bloop', function () { this.mount('chat', { as: 'blork' }); }); }); }); var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true } }); var router = Router.create(); (0, _emberUtils.setOwner)(router, engineInstance); router._initRouterJs(); assert.deepEqual(router._routerMicrolib.recognizer.names['bleep.bloop.blork'].segments.slice(1, 4).map(function (s) { return s.value; }), ['bleep', 'bloop', 'blork'], 'segments are properly associated with mounted engine with aliased name'); }); QUnit.test('should add loading and error routes to a mount if _isRouterMapResult is true', function () { Router.map(function () { this.mount('chat'); }); var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true } }); var router = Router.create({ _hasModuleBasedResolver: function () { return true; } }); (0, _emberUtils.setOwner)(router, engineInstance); router._initRouterJs(); ok(router._routerMicrolib.recognizer.names['chat'], 'main route was created'); ok(router._routerMicrolib.recognizer.names['chat_loading'], 'loading route was added'); ok(router._routerMicrolib.recognizer.names['chat_error'], 'error route was added'); }); QUnit.test('should add loading and error routes to a mount alias if _isRouterMapResult is true', function () { Router.map(function () { this.mount('chat', { as: 'shoutbox' }); }); var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true } }); var router = Router.create({ _hasModuleBasedResolver: function () { return true; } }); (0, _emberUtils.setOwner)(router, engineInstance); router._initRouterJs(); ok(router._routerMicrolib.recognizer.names['shoutbox'], 'main route was created'); ok(router._routerMicrolib.recognizer.names['shoutbox_loading'], 'loading route was added'); ok(router._routerMicrolib.recognizer.names['shoutbox_error'], 'error route was added'); }); QUnit.test('should not add loading and error routes to a mount if _isRouterMapResult is false', function () { Router.map(function () { this.mount('chat'); }); var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true } }); var router = Router.create(); (0, _emberUtils.setOwner)(router, engineInstance); router._initRouterJs(false); ok(router._routerMicrolib.recognizer.names['chat'], 'main route was created'); ok(!router._routerMicrolib.recognizer.names['chat_loading'], 'loading route was not added'); ok(!router._routerMicrolib.recognizer.names['chat_error'], 'error route was not added'); }); QUnit.test('should reset namespace of loading and error routes for mounts with resetNamespace', function () { Router.map(function () { this.route('news', function () { this.mount('chat'); this.mount('blog', { resetNamespace: true }); }); }); var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true } }); var router = Router.create({ _hasModuleBasedResolver: function () { return true; } }); (0, _emberUtils.setOwner)(router, engineInstance); router._initRouterJs(); ok(router._routerMicrolib.recognizer.names['news.chat'], 'nested route was created'); ok(router._routerMicrolib.recognizer.names['news.chat_loading'], 'nested loading route was added'); ok(router._routerMicrolib.recognizer.names['news.chat_error'], 'nested error route was added'); ok(router._routerMicrolib.recognizer.names['blog'], 'reset route was created'); ok(router._routerMicrolib.recognizer.names['blog_loading'], 'reset loading route was added'); ok(router._routerMicrolib.recognizer.names['blog_error'], 'reset error route was added'); ok(!router._routerMicrolib.recognizer.names['news.blog'], 'nested reset route was not created'); ok(!router._routerMicrolib.recognizer.names['news.blog_loading'], 'nested reset loading route was not added'); ok(!router._routerMicrolib.recognizer.names['news.blog_error'], 'nested reset error route was not added'); }); }); enifed('ember-routing/tests/system/route_test', ['ember-utils', 'internal-test-helpers', 'ember-runtime', 'ember-routing/system/route'], function (_emberUtils, _internalTestHelpers, _emberRuntime, _route) { 'use strict'; var route = void 0, routeOne = void 0, routeTwo = void 0, lookupHash = void 0; function setup() { route = _route.default.create(); } function teardown() { (0, _internalTestHelpers.runDestroy)(route); } QUnit.module('Ember.Route', { setup: setup, teardown: teardown }); QUnit.test('default store utilizes the container to acquire the model factory', function () { expect(4); var Post = _emberRuntime.Object.extend(); var post = {}; Post.reopenClass({ find: function () { return post; } }); (0, _emberUtils.setOwner)(route, (0, _internalTestHelpers.buildOwner)({ ownerOptions: { hasRegistration: function () { return true; }, factoryFor: function (fullName) { equal(fullName, 'model:post', 'correct factory was looked up'); return { class: Post, create: function () { return Post.create(); } }; } } })); route.set('_qp', null); equal(route.model({ post_id: 1 }), post); equal(route.findModel('post', 1), post, '#findModel returns the correct post'); }); QUnit.test('\'store\' can be injected by data persistence frameworks', function () { expect(8); (0, _internalTestHelpers.runDestroy)(route); var owner = (0, _internalTestHelpers.buildOwner)(); var post = { id: 1 }; var Store = _emberRuntime.Object.extend({ find: function (type, value) { ok(true, 'injected model was called'); equal(type, 'post', 'correct type was called'); equal(value, 1, 'correct value was called'); return post; } }); owner.register('route:index', _route.default); owner.register('store:main', Store); owner.inject('route', 'store', 'store:main'); route = owner.lookup('route:index'); equal(route.model({ post_id: 1 }), post, '#model returns the correct post'); equal(route.findModel('post', 1), post, '#findModel returns the correct post'); }); QUnit.test('assert if \'store.find\' method is not found', function () { expect(1); (0, _internalTestHelpers.runDestroy)(route); var owner = (0, _internalTestHelpers.buildOwner)(); var Post = _emberRuntime.Object.extend(); owner.register('route:index', _route.default); owner.register('model:post', Post); route = owner.lookup('route:index'); expectAssertion(function () { route.findModel('post', 1); }, 'Post has no method `find`.'); }); QUnit.test('asserts if model class is not found', function () { expect(1); (0, _internalTestHelpers.runDestroy)(route); var owner = (0, _internalTestHelpers.buildOwner)(); owner.register('route:index', _route.default); route = owner.lookup('route:index'); expectAssertion(function () { route.model({ post_id: 1 }); }, /You used the dynamic segment post_id in your route undefined, but .Post did not exist and you did not override your route\'s `model` hook./); }); QUnit.test('\'store\' does not need to be injected', function () { expect(1); (0, _internalTestHelpers.runDestroy)(route); var owner = (0, _internalTestHelpers.buildOwner)(); owner.register('route:index', _route.default); route = owner.lookup('route:index'); ignoreAssertion(function () { route.model({ post_id: 1 }); }); ok(true, 'no error was raised'); }); QUnit.test('modelFor doesn\'t require the router', function () { expect(1); var owner = (0, _internalTestHelpers.buildOwner)(); (0, _emberUtils.setOwner)(route, owner); var foo = { name: 'foo' }; var FooRoute = _route.default.extend({ currentModel: foo }); owner.register('route:foo', FooRoute); strictEqual(route.modelFor('foo'), foo); }); QUnit.test('.send just calls an action if the router is absent', function () { expect(7); var route = _route.default.extend({ actions: { returnsTrue: function (foo, bar) { equal(foo, 1); equal(bar, 2); equal(this, route); return true; }, returnsFalse: function () { ok(true, 'returnsFalse was called'); return false; } } }).create(); equal(true, route.send('returnsTrue', 1, 2)); equal(false, route.send('returnsFalse')); equal(undefined, route.send('nonexistent', 1, 2, 3)); }); QUnit.test('.send just calls an action if the routers internal router property is absent', function () { expect(7); var route = _route.default.extend({ router: {}, actions: { returnsTrue: function (foo, bar) { equal(foo, 1); equal(bar, 2); equal(this, route); return true; }, returnsFalse: function () { ok(true, 'returnsFalse was called'); return false; } } }).create(); equal(true, route.send('returnsTrue', 1, 2)); equal(false, route.send('returnsFalse')); equal(undefined, route.send('nonexistent', 1, 2, 3)); }); QUnit.test('can access `actions` hash via `_actions` [DEPRECATED]', function () { expect(2); var route = _route.default.extend({ actions: { foo: function () { ok(true, 'called foo action'); } } }).create(); expectDeprecation(function () { route._actions.foo(); }, 'Usage of `_actions` is deprecated, use `actions` instead.'); }); QUnit.test('actions in both `_actions` and `actions` results in an assertion', function () { expectAssertion(function () { _route.default.extend({ _actions: {}, actions: {} }).create(); }, 'Specifying `_actions` and `actions` in the same mixin is not supported.'); }); QUnit.test('actions added via `_actions` can be used [DEPRECATED]', function () { expect(3); var route = void 0; expectDeprecation(function () { route = _route.default.extend({ _actions: { bar: function () { ok(true, 'called bar action'); } } }, { actions: { foo: function () { ok(true, 'called foo action'); } } }).create(); }, 'Specifying actions in `_actions` is deprecated, please use `actions` instead.'); route.send('foo'); route.send('bar'); }); QUnit.module('Ember.Route serialize', { setup: setup, teardown: teardown }); QUnit.test('returns the models properties if params does not include *_id', function () { deepEqual(route.serialize({ id: 2, firstName: 'Ned', lastName: 'Ryerson' }, ['firstName', 'lastName']), { firstName: 'Ned', lastName: 'Ryerson' }, 'serialized correctly'); }); QUnit.test('returns model.id if params include *_id', function () { deepEqual(route.serialize({ id: 2 }, ['post_id']), { post_id: 2 }, 'serialized correctly'); }); QUnit.test('returns checks for existence of model.post_id before trying model.id', function () { deepEqual(route.serialize({ post_id: 3 }, ['post_id']), { post_id: 3 }, 'serialized correctly'); }); QUnit.test('returns undefined if model is not set', function () { equal(route.serialize(undefined, ['post_id']), undefined, 'serialized correctly'); }); QUnit.module('Ember.Route interaction', { setup: function () { var owner = { lookup: function (fullName) { return lookupHash[fullName]; } }; routeOne = _route.default.create({ routeName: 'one' }); routeTwo = _route.default.create({ routeName: 'two' }); (0, _emberUtils.setOwner)(routeOne, owner); (0, _emberUtils.setOwner)(routeTwo, owner); lookupHash = { 'route:one': routeOne, 'route:two': routeTwo }; }, teardown: function () { (0, _internalTestHelpers.runDestroy)(routeOne); (0, _internalTestHelpers.runDestroy)(routeTwo); } }); QUnit.test('controllerFor uses route\'s controllerName if specified', function () { var testController = {}; lookupHash['controller:test'] = testController; routeOne.controllerName = 'test'; equal(routeTwo.controllerFor('one'), testController); }); QUnit.module('Route injected properties'); QUnit.test('services can be injected into routes', function () { var owner = (0, _internalTestHelpers.buildOwner)(); owner.register('route:application', _route.default.extend({ authService: _emberRuntime.inject.service('auth') })); owner.register('service:auth', _emberRuntime.Service.extend()); var appRoute = owner.lookup('route:application'); var authService = owner.lookup('service:auth'); equal(authService, appRoute.get('authService'), 'service.auth is injected'); }); QUnit.module('Ember.Route with engines'); QUnit.test('paramsFor considers an engine\'s mountPoint', function (assert) { expect(2); var router = { _deserializeQueryParams: function () {}, _routerMicrolib: { state: { handlerInfos: [{ name: 'posts' }], params: { 'foo.bar': { a: 'b' }, 'foo.bar.posts': { c: 'd' } } } } }; var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true, mountPoint: 'foo.bar', lookup: function (name) { if (name === 'route:posts') { return postsRoute; } else if (name === 'route:application') { return applicationRoute; } } } }); var applicationRoute = _route.default.create({ router: router, routeName: 'application', fullRouteName: 'foo.bar' }); var postsRoute = _route.default.create({ router: router, routeName: 'posts', fullRouteName: 'foo.bar.posts' }); var route = _route.default.create({ router: router }); (0, _emberUtils.setOwner)(applicationRoute, engineInstance); (0, _emberUtils.setOwner)(postsRoute, engineInstance); (0, _emberUtils.setOwner)(route, engineInstance); assert.deepEqual(route.paramsFor('application'), { a: 'b' }, 'params match for root `application` route in engine'); assert.deepEqual(route.paramsFor('posts'), { c: 'd' }, 'params match for `posts` route in engine'); }); QUnit.test('modelFor considers an engine\'s mountPoint', function () { expect(2); var applicationModel = { id: '1' }; var postsModel = { id: '2' }; var router = { _routerMicrolib: { activeTransition: { resolvedModels: { 'foo.bar': applicationModel, 'foo.bar.posts': postsModel } } } }; var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true, mountPoint: 'foo.bar', lookup: function (name) { if (name === 'route:posts') { return postsRoute; } else if (name === 'route:application') { return applicationRoute; } } } }); var applicationRoute = _route.default.create({ router: router, routeName: 'application' }); var postsRoute = _route.default.create({ router: router, routeName: 'posts' }); var route = _route.default.create({ router: router }); (0, _emberUtils.setOwner)(applicationRoute, engineInstance); (0, _emberUtils.setOwner)(postsRoute, engineInstance); (0, _emberUtils.setOwner)(route, engineInstance); strictEqual(route.modelFor('application'), applicationModel); strictEqual(route.modelFor('posts'), postsModel); }); QUnit.test('transitionTo considers an engine\'s mountPoint', function () { expect(4); var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true, mountPoint: 'foo.bar' } }); var route = _route.default.create({ router: { transitionTo: function (route) { return route; } } }); (0, _emberUtils.setOwner)(route, engineInstance); strictEqual(route.transitionTo('application'), 'foo.bar.application', 'properly prefixes application route'); strictEqual(route.transitionTo('posts'), 'foo.bar.posts', 'properly prefixes child routes'); throws(function () { return route.transitionTo('/posts'); }, 'throws when trying to use a url'); var queryParams = {}; strictEqual(route.transitionTo(queryParams), queryParams, 'passes query param only transitions through'); }); QUnit.test('intermediateTransitionTo considers an engine\'s mountPoint', function () { expect(4); var lastRoute = void 0; var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true, mountPoint: 'foo.bar' } }); var route = _route.default.create({ router: { intermediateTransitionTo: function (route) { lastRoute = route; } } }); (0, _emberUtils.setOwner)(route, engineInstance); route.intermediateTransitionTo('application'); strictEqual(lastRoute, 'foo.bar.application', 'properly prefixes application route'); route.intermediateTransitionTo('posts'); strictEqual(lastRoute, 'foo.bar.posts', 'properly prefixes child routes'); throws(function () { return route.intermediateTransitionTo('/posts'); }, 'throws when trying to use a url'); var queryParams = {}; route.intermediateTransitionTo(queryParams); strictEqual(lastRoute, queryParams, 'passes query param only transitions through'); }); QUnit.test('replaceWith considers an engine\'s mountPoint', function () { expect(4); var engineInstance = (0, _internalTestHelpers.buildOwner)({ ownerOptions: { routable: true, mountPoint: 'foo.bar' } }); var route = _route.default.create({ router: { replaceWith: function (route) { return route; } } }); (0, _emberUtils.setOwner)(route, engineInstance); strictEqual(route.replaceWith('application'), 'foo.bar.application', 'properly prefixes application route'); strictEqual(route.replaceWith('posts'), 'foo.bar.posts', 'properly prefixes child routes'); throws(function () { return route.replaceWith('/posts'); }, 'throws when trying to use a url'); var queryParams = {}; strictEqual(route.replaceWith(queryParams), queryParams, 'passes query param only transitions through'); }); }); enifed('ember-routing/tests/system/router_test', ['ember-utils', 'ember-routing/location/hash_location', 'ember-routing/location/history_location', 'ember-routing/location/auto_location', 'ember-routing/location/none_location', 'ember-routing/system/router', 'internal-test-helpers'], function (_emberUtils, _hash_location, _history_location, _auto_location, _none_location, _router, _internalTestHelpers) { 'use strict'; var owner = void 0; function createRouter(settings) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var CustomRouter = _router.default.extend(); var router = CustomRouter.create(settings); if (!options.skipOwner) { (0, _emberUtils.setOwner)(router, owner); } if (!options.disableSetup) { router.setupRouter(); } return router; } QUnit.module('Ember Router', { setup: function () { owner = (0, _internalTestHelpers.buildOwner)(); //register the HashLocation (the default) owner.register('location:hash', _hash_location.default); owner.register('location:history', _history_location.default); owner.register('location:auto', _auto_location.default); owner.register('location:none', _none_location.default); }, teardown: function () { (0, _internalTestHelpers.runDestroy)(owner); owner = null; } }); QUnit.test('can create a router without an owner', function () { createRouter(null, { disableSetup: true, skipOwner: true }); ok(true, 'no errors were thrown when creating without a container'); }); QUnit.test('should not create a router.js instance upon init', function () { var router = createRouter(null, { disableSetup: true }); ok(!router._routerMicrolib); }); QUnit.test('should not reify location until setupRouter is called', function () { var router = createRouter(null, { disableSetup: true }); equal(typeof router.location, 'string', 'location is specified as a string'); router.setupRouter(); equal(typeof router.location, 'object', 'location is reified into an object'); }); QUnit.test('should destroy its location upon destroying the routers owner.', function () { var router = createRouter(); var location = router.get('location'); (0, _internalTestHelpers.runDestroy)(owner); ok(location.isDestroyed, 'location should be destroyed'); }); QUnit.test('should instantiate its location with its `rootURL`', function () { var router = createRouter({ rootURL: '/rootdir/' }); var location = router.get('location'); equal(location.get('rootURL'), '/rootdir/'); }); QUnit.test('replacePath should be called with the right path', function () { expect(1); var location = owner.lookup('location:auto'); location.location = { href: 'http://test.com/rootdir/welcome', origin: 'http://test.com', pathname: '/rootdir/welcome', hash: '', search: '', replace: function (url) { equal(url, 'http://test.com/rootdir/#/welcome'); } }; location.global = { onhashchange: function () {} }; location.history = null; createRouter({ location: 'auto', rootURL: '/rootdir/' }); }); QUnit.test('Ember.Router._routePath should consume identical prefixes', function () { createRouter(); expect(8); function routePath() { var handlerInfos = Array.prototype.slice.call(arguments).map(function (s) { return { name: s }; }); handlerInfos.unshift({ name: 'ignored' }); return _router.default._routePath(handlerInfos); } equal(routePath('foo'), 'foo'); equal(routePath('foo', 'bar', 'baz'), 'foo.bar.baz'); equal(routePath('foo', 'foo.bar'), 'foo.bar'); equal(routePath('foo', 'foo.bar', 'foo.bar.baz'), 'foo.bar.baz'); equal(routePath('foo', 'foo.bar', 'foo.bar.baz.wow'), 'foo.bar.baz.wow'); equal(routePath('foo', 'foo.bar.baz.wow'), 'foo.bar.baz.wow'); equal(routePath('foo.bar', 'bar.baz.wow'), 'foo.bar.baz.wow'); // This makes no sense, not trying to handle it, just // making sure it doesn't go boom. equal(routePath('foo.bar.baz', 'foo'), 'foo.bar.baz.foo'); }); QUnit.test('Router should cancel routing setup when the Location class says so via cancelRouterSetup', function () { expect(0); var router = void 0; owner.register('location:fake', { cancelRouterSetup: true, create: function () { return this; } }); router = createRouter({ location: 'fake', _setupRouter: function () { ok(false, '_setupRouter should not be called'); } }); router.startRouting(); }); QUnit.test('AutoLocation should replace the url when it\'s not in the preferred format', function () { expect(1); var location = owner.lookup('location:auto'); location.location = { href: 'http://test.com/rootdir/welcome', origin: 'http://test.com', pathname: '/rootdir/welcome', hash: '', search: '', replace: function (url) { equal(url, 'http://test.com/rootdir/#/welcome'); } }; location.history = null; location.global = { onhashchange: function () {} }; createRouter({ location: 'auto', rootURL: '/rootdir/' }); }); QUnit.test('Router#handleURL should remove any #hashes before doing URL transition', function () { expect(2); var router = createRouter({ _doURLTransition: function (routerJsMethod, url) { equal(routerJsMethod, 'handleURL'); equal(url, '/foo/bar?time=morphin'); } }); router.handleURL('/foo/bar?time=morphin#pink-power-ranger'); }); QUnit.test('Router#triggerEvent allows actions to bubble when returning true', function (assert) { assert.expect(2); (0, _router.triggerEvent)([{ name: 'application', handler: { actions: { loading: function () { assert.ok(false, 'loading not handled by application route'); } } } }, { name: 'about', handler: { actions: { loading: function () { assert.ok(true, 'loading handled by about route'); return false; } } } }, { name: 'about.me', handler: { actions: { loading: function () { assert.ok(true, 'loading handled by about.me route'); return true; } } } }], false, ['loading']); }); QUnit.test('Router#triggerEvent ignores handlers that have not loaded yet', function (assert) { assert.expect(1); var handlerInfos = [{ name: 'about', handler: { actions: { loading: function () { assert.ok(true, 'loading handled by about route'); } } } }, { name: 'about.me', handler: undefined }]; (0, _router.triggerEvent)(handlerInfos, false, ['loading']); }); QUnit.test('Router#router deprecates when called', function (assert) { assert.expect(2); var router = createRouter(); expectDeprecation(function () { assert.equal(router.router, router._routerMicrolib); }, 'Usage of `router` is deprecated, use `_routerMicrolib` instead.'); }); QUnit.test('Router#_routerMicrolib can be used without deprecation', function (assert) { assert.expect(1); var router = createRouter(); assert.ok(router._routerMicrolib, 'Router._routerMicrolib can be used without deprecation'); }); }); enifed('ember-routing/tests/utils_test', ['ember-routing/utils'], function (_utils) { 'use strict'; QUnit.module('Routing query parameter utils - normalizeControllerQueryParams'); QUnit.test('converts array style into verbose object style', function () { var paramName = 'foo'; var normalized = (0, _utils.normalizeControllerQueryParams)([paramName]); ok(normalized[paramName], 'turns the query param name into key'); equal(normalized[paramName].as, null, 'includes a blank alias in \'as\' key'); equal(normalized[paramName].scope, 'model', 'defaults scope to model'); }); QUnit.test('converts object style [{foo: \'an_alias\'}]', function () { var paramName = 'foo'; var normalized = (0, _utils.normalizeControllerQueryParams)([{ 'foo': 'an_alias' }]); ok(normalized[paramName], 'retains the query param name as key'); equal(normalized[paramName].as, 'an_alias', 'includes the provided alias in \'as\' key'); equal(normalized[paramName].scope, 'model', 'defaults scope to model'); }); QUnit.test('retains maximally verbose object style [{foo: {as: \'foo\'}}]', function () { var paramName = 'foo'; var normalized = (0, _utils.normalizeControllerQueryParams)([{ 'foo': { as: 'an_alias' } }]); ok(normalized[paramName], 'retains the query param name as key'); equal(normalized[paramName].as, 'an_alias', 'includes the provided alias in \'as\' key'); equal(normalized[paramName].scope, 'model', 'defaults scope to model'); }); }); enifed('ember-runtime/tests/computed/computed_macros_test', ['ember-metal', 'ember-runtime/computed/computed_macros', 'internal-test-helpers', 'ember-runtime/system/object', 'ember-runtime/system/native_array'], function (_emberMetal, _computed_macros, _internalTestHelpers, _object, _native_array) { 'use strict'; QUnit.module('CP macros'); (0, _internalTestHelpers.testBoth)('Ember.computed.empty', function (get, set) { var obj = _object.default.extend({ bestLannister: null, lannisters: null, bestLannisterUnspecified: (0, _computed_macros.empty)('bestLannister'), noLannistersKnown: (0, _computed_macros.empty)('lannisters') }).create({ lannisters: (0, _native_array.A)() }); equal(get(obj, 'bestLannisterUnspecified'), true, 'bestLannister initially empty'); equal(get(obj, 'noLannistersKnown'), true, 'lannisters initially empty'); get(obj, 'lannisters').pushObject('Tyrion'); set(obj, 'bestLannister', 'Tyrion'); equal(get(obj, 'bestLannisterUnspecified'), false, 'empty respects strings'); equal(get(obj, 'noLannistersKnown'), false, 'empty respects array mutations'); }); (0, _internalTestHelpers.testBoth)('Ember.computed.notEmpty', function (get, set) { var obj = _object.default.extend({ bestLannister: null, lannisters: null, bestLannisterSpecified: (0, _computed_macros.notEmpty)('bestLannister'), LannistersKnown: (0, _computed_macros.notEmpty)('lannisters') }).create({ lannisters: (0, _native_array.A)() }); equal(get(obj, 'bestLannisterSpecified'), false, 'bestLannister initially empty'); equal(get(obj, 'LannistersKnown'), false, 'lannisters initially empty'); get(obj, 'lannisters').pushObject('Tyrion'); set(obj, 'bestLannister', 'Tyrion'); equal(get(obj, 'bestLannisterSpecified'), true, 'empty respects strings'); equal(get(obj, 'LannistersKnown'), true, 'empty respects array mutations'); }); (0, _internalTestHelpers.testBoth)('computed.not', function (get) { var obj = { foo: true }; (0, _emberMetal.defineProperty)(obj, 'notFoo', (0, _computed_macros.not)('foo')); equal(get(obj, 'notFoo'), false); obj = { foo: { bar: true } }; (0, _emberMetal.defineProperty)(obj, 'notFoo', (0, _computed_macros.not)('foo.bar')); equal(get(obj, 'notFoo'), false); }); (0, _internalTestHelpers.testBoth)('computed.empty', function (get, set) { var obj = { foo: [], bar: undefined, baz: null, quz: '' }; (0, _emberMetal.defineProperty)(obj, 'fooEmpty', (0, _computed_macros.empty)('foo')); (0, _emberMetal.defineProperty)(obj, 'barEmpty', (0, _computed_macros.empty)('bar')); (0, _emberMetal.defineProperty)(obj, 'bazEmpty', (0, _computed_macros.empty)('baz')); (0, _emberMetal.defineProperty)(obj, 'quzEmpty', (0, _computed_macros.empty)('quz')); equal(get(obj, 'fooEmpty'), true); set(obj, 'foo', [1]); equal(get(obj, 'fooEmpty'), false); equal(get(obj, 'barEmpty'), true); equal(get(obj, 'bazEmpty'), true); equal(get(obj, 'quzEmpty'), true); set(obj, 'quz', 'asdf'); equal(get(obj, 'quzEmpty'), false); }); (0, _internalTestHelpers.testBoth)('computed.bool', function (get) { var obj = { foo: function () {}, bar: 'asdf', baz: null, quz: false }; (0, _emberMetal.defineProperty)(obj, 'fooBool', (0, _computed_macros.bool)('foo')); (0, _emberMetal.defineProperty)(obj, 'barBool', (0, _computed_macros.bool)('bar')); (0, _emberMetal.defineProperty)(obj, 'bazBool', (0, _computed_macros.bool)('baz')); (0, _emberMetal.defineProperty)(obj, 'quzBool', (0, _computed_macros.bool)('quz')); equal(get(obj, 'fooBool'), true); equal(get(obj, 'barBool'), true); equal(get(obj, 'bazBool'), false); equal(get(obj, 'quzBool'), false); }); (0, _internalTestHelpers.testBoth)('computed.alias', function (get, set) { var obj = { bar: 'asdf', baz: null, quz: false }; (0, _emberMetal.defineProperty)(obj, 'bay', (0, _emberMetal.computed)(function () { return 'apple'; })); (0, _emberMetal.defineProperty)(obj, 'barAlias', (0, _emberMetal.alias)('bar')); (0, _emberMetal.defineProperty)(obj, 'bazAlias', (0, _emberMetal.alias)('baz')); (0, _emberMetal.defineProperty)(obj, 'quzAlias', (0, _emberMetal.alias)('quz')); (0, _emberMetal.defineProperty)(obj, 'bayAlias', (0, _emberMetal.alias)('bay')); equal(get(obj, 'barAlias'), 'asdf'); equal(get(obj, 'bazAlias'), null); equal(get(obj, 'quzAlias'), false); equal(get(obj, 'bayAlias'), 'apple'); set(obj, 'barAlias', 'newBar'); set(obj, 'bazAlias', 'newBaz'); set(obj, 'quzAlias', null); equal(get(obj, 'barAlias'), 'newBar'); equal(get(obj, 'bazAlias'), 'newBaz'); equal(get(obj, 'quzAlias'), null); equal(get(obj, 'bar'), 'newBar'); equal(get(obj, 'baz'), 'newBaz'); equal(get(obj, 'quz'), null); }); (0, _internalTestHelpers.testBoth)('computed.alias set', function (get, set) { var obj = {}; var constantValue = 'always `a`'; (0, _emberMetal.defineProperty)(obj, 'original', (0, _emberMetal.computed)({ get: function () { return constantValue; }, set: function () { return constantValue; } })); (0, _emberMetal.defineProperty)(obj, 'aliased', (0, _emberMetal.alias)('original')); equal(get(obj, 'original'), constantValue); equal(get(obj, 'aliased'), constantValue); set(obj, 'aliased', 'should not set to this value'); equal(get(obj, 'original'), constantValue); equal(get(obj, 'aliased'), constantValue); }); (0, _internalTestHelpers.testBoth)('computed.match', function (get, set) { var obj = { name: 'Paul' }; (0, _emberMetal.defineProperty)(obj, 'isPaul', (0, _computed_macros.match)('name', /Paul/)); equal(get(obj, 'isPaul'), true, 'is Paul'); set(obj, 'name', 'Pierre'); equal(get(obj, 'isPaul'), false, 'is not Paul anymore'); }); (0, _internalTestHelpers.testBoth)('computed.notEmpty', function (get, set) { var obj = { items: [1] }; (0, _emberMetal.defineProperty)(obj, 'hasItems', (0, _computed_macros.notEmpty)('items')); equal(get(obj, 'hasItems'), true, 'is not empty'); set(obj, 'items', []); equal(get(obj, 'hasItems'), false, 'is empty'); }); (0, _internalTestHelpers.testBoth)('computed.equal', function (get, set) { var obj = { name: 'Paul' }; (0, _emberMetal.defineProperty)(obj, 'isPaul', (0, _computed_macros.equal)('name', 'Paul')); equal(get(obj, 'isPaul'), true, 'is Paul'); set(obj, 'name', 'Pierre'); equal(get(obj, 'isPaul'), false, 'is not Paul anymore'); }); (0, _internalTestHelpers.testBoth)('computed.gt', function (get, set) { var obj = { number: 2 }; (0, _emberMetal.defineProperty)(obj, 'isGreaterThenOne', (0, _computed_macros.gt)('number', 1)); equal(get(obj, 'isGreaterThenOne'), true, 'is gt'); set(obj, 'number', 1); equal(get(obj, 'isGreaterThenOne'), false, 'is not gt'); set(obj, 'number', 0); equal(get(obj, 'isGreaterThenOne'), false, 'is not gt'); }); (0, _internalTestHelpers.testBoth)('computed.gte', function (get, set) { var obj = { number: 2 }; (0, _emberMetal.defineProperty)(obj, 'isGreaterOrEqualThenOne', (0, _computed_macros.gte)('number', 1)); equal(get(obj, 'isGreaterOrEqualThenOne'), true, 'is gte'); set(obj, 'number', 1); equal(get(obj, 'isGreaterOrEqualThenOne'), true, 'is gte'); set(obj, 'number', 0); equal(get(obj, 'isGreaterOrEqualThenOne'), false, 'is not gte'); }); (0, _internalTestHelpers.testBoth)('computed.lt', function (get, set) { var obj = { number: 0 }; (0, _emberMetal.defineProperty)(obj, 'isLesserThenOne', (0, _computed_macros.lt)('number', 1)); equal(get(obj, 'isLesserThenOne'), true, 'is lt'); set(obj, 'number', 1); equal(get(obj, 'isLesserThenOne'), false, 'is not lt'); set(obj, 'number', 2); equal(get(obj, 'isLesserThenOne'), false, 'is not lt'); }); (0, _internalTestHelpers.testBoth)('computed.lte', function (get, set) { var obj = { number: 0 }; (0, _emberMetal.defineProperty)(obj, 'isLesserOrEqualThenOne', (0, _computed_macros.lte)('number', 1)); equal(get(obj, 'isLesserOrEqualThenOne'), true, 'is lte'); set(obj, 'number', 1); equal(get(obj, 'isLesserOrEqualThenOne'), true, 'is lte'); set(obj, 'number', 2); equal(get(obj, 'isLesserOrEqualThenOne'), false, 'is not lte'); }); (0, _internalTestHelpers.testBoth)('computed.and two properties', function (get, set) { var obj = { one: true, two: true }; (0, _emberMetal.defineProperty)(obj, 'oneAndTwo', (0, _computed_macros.and)('one', 'two')); equal(get(obj, 'oneAndTwo'), true, 'one and two'); set(obj, 'one', false); equal(get(obj, 'oneAndTwo'), false, 'one and not two'); set(obj, 'one', null); set(obj, 'two', 'Yes'); equal(get(obj, 'oneAndTwo'), null, 'returns falsy value as in &&'); set(obj, 'one', true); set(obj, 'two', 2); equal(get(obj, 'oneAndTwo'), 2, 'returns truthy value as in &&'); }); (0, _internalTestHelpers.testBoth)('computed.and three properties', function (get, set) { var obj = { one: true, two: true, three: true }; (0, _emberMetal.defineProperty)(obj, 'oneTwoThree', (0, _computed_macros.and)('one', 'two', 'three')); equal(get(obj, 'oneTwoThree'), true, 'one and two and three'); set(obj, 'one', false); equal(get(obj, 'oneTwoThree'), false, 'one and not two and not three'); set(obj, 'one', true); set(obj, 'two', 2); set(obj, 'three', 3); equal(get(obj, 'oneTwoThree'), 3, 'returns truthy value as in &&'); }); (0, _internalTestHelpers.testBoth)('computed.and expand properties', function (get, set) { var obj = { one: true, two: true, three: true }; (0, _emberMetal.defineProperty)(obj, 'oneTwoThree', (0, _computed_macros.and)('{one,two,three}')); equal(get(obj, 'oneTwoThree'), true, 'one and two and three'); set(obj, 'one', false); equal(get(obj, 'oneTwoThree'), false, 'one and not two and not three'); set(obj, 'one', true); set(obj, 'two', 2); set(obj, 'three', 3); equal(get(obj, 'oneTwoThree'), 3, 'returns truthy value as in &&'); }); (0, _internalTestHelpers.testBoth)('computed.or two properties', function (get, set) { var obj = { one: true, two: true }; (0, _emberMetal.defineProperty)(obj, 'oneOrTwo', (0, _computed_macros.or)('one', 'two')); equal(get(obj, 'oneOrTwo'), true, 'one or two'); set(obj, 'one', false); equal(get(obj, 'oneOrTwo'), true, 'one or two'); set(obj, 'two', false); equal(get(obj, 'oneOrTwo'), false, 'nor one nor two'); set(obj, 'two', null); equal(get(obj, 'oneOrTwo'), null, 'returns last falsy value as in ||'); set(obj, 'two', true); equal(get(obj, 'oneOrTwo'), true, 'one or two'); set(obj, 'one', 1); equal(get(obj, 'oneOrTwo'), 1, 'returns truthy value as in ||'); }); (0, _internalTestHelpers.testBoth)('computed.or three properties', function (get, set) { var obj = { one: true, two: true, three: true }; (0, _emberMetal.defineProperty)(obj, 'oneTwoThree', (0, _computed_macros.or)('one', 'two', 'three')); equal(get(obj, 'oneTwoThree'), true, 'one or two or three'); set(obj, 'one', false); equal(get(obj, 'oneTwoThree'), true, 'one or two or three'); set(obj, 'two', false); equal(get(obj, 'oneTwoThree'), true, 'one or two or three'); set(obj, 'three', false); equal(get(obj, 'oneTwoThree'), false, 'one or two or three'); set(obj, 'three', null); equal(get(obj, 'oneTwoThree'), null, 'returns last falsy value as in ||'); set(obj, 'two', true); equal(get(obj, 'oneTwoThree'), true, 'one or two or three'); set(obj, 'one', 1); equal(get(obj, 'oneTwoThree'), 1, 'returns truthy value as in ||'); }); (0, _internalTestHelpers.testBoth)('computed.or expand properties', function (get, set) { var obj = { one: true, two: true, three: true }; (0, _emberMetal.defineProperty)(obj, 'oneTwoThree', (0, _computed_macros.or)('{one,two,three}')); equal(get(obj, 'oneTwoThree'), true, 'one or two or three'); set(obj, 'one', false); equal(get(obj, 'oneTwoThree'), true, 'one or two or three'); set(obj, 'two', false); equal(get(obj, 'oneTwoThree'), true, 'one or two or three'); set(obj, 'three', false); equal(get(obj, 'oneTwoThree'), false, 'one or two or three'); set(obj, 'three', null); equal(get(obj, 'oneTwoThree'), null, 'returns last falsy value as in ||'); set(obj, 'two', true); equal(get(obj, 'oneTwoThree'), true, 'one or two or three'); set(obj, 'one', 1); equal(get(obj, 'oneTwoThree'), 1, 'returns truthy value as in ||'); }); (0, _internalTestHelpers.testBoth)('computed.or and computed.and warn about dependent keys with spaces', function () { var obj = { one: true, two: true }; expectAssertion(function () { (0, _emberMetal.defineProperty)(obj, 'oneOrTwo', (0, _computed_macros.or)('one', 'two three')); }, /Dependent keys passed to Ember\.computed\.or\(\) can't have spaces\./); expectAssertion(function () { (0, _emberMetal.defineProperty)(obj, 'oneAndTwo', (0, _computed_macros.and)('one', 'two three')); }, /Dependent keys passed to Ember\.computed\.and\(\) can't have spaces\./); }); (0, _internalTestHelpers.testBoth)('computed.oneWay', function (get, set) { var obj = { firstName: 'Teddy', lastName: 'Zeenny' }; (0, _emberMetal.defineProperty)(obj, 'nickName', (0, _computed_macros.oneWay)('firstName')); equal(get(obj, 'firstName'), 'Teddy'); equal(get(obj, 'lastName'), 'Zeenny'); equal(get(obj, 'nickName'), 'Teddy'); set(obj, 'nickName', 'TeddyBear'); equal(get(obj, 'firstName'), 'Teddy'); equal(get(obj, 'lastName'), 'Zeenny'); equal(get(obj, 'nickName'), 'TeddyBear'); set(obj, 'firstName', 'TEDDDDDDDDYYY'); equal(get(obj, 'nickName'), 'TeddyBear'); }); (0, _internalTestHelpers.testBoth)('computed.readOnly', function (get, set) { var obj = { firstName: 'Teddy', lastName: 'Zeenny' }; (0, _emberMetal.defineProperty)(obj, 'nickName', (0, _computed_macros.readOnly)('firstName')); equal(get(obj, 'firstName'), 'Teddy'); equal(get(obj, 'lastName'), 'Zeenny'); equal(get(obj, 'nickName'), 'Teddy'); throws(function () { set(obj, 'nickName', 'TeddyBear'); }, / /); equal(get(obj, 'firstName'), 'Teddy'); equal(get(obj, 'lastName'), 'Zeenny'); equal(get(obj, 'nickName'), 'Teddy'); set(obj, 'firstName', 'TEDDDDDDDDYYY'); equal(get(obj, 'nickName'), 'TEDDDDDDDDYYY'); }); (0, _internalTestHelpers.testBoth)('computed.deprecatingAlias', function (get, set) { var obj = { bar: 'asdf', baz: null, quz: false }; (0, _emberMetal.defineProperty)(obj, 'bay', (0, _emberMetal.computed)(function () { return 'apple'; })); (0, _emberMetal.defineProperty)(obj, 'barAlias', (0, _computed_macros.deprecatingAlias)('bar')); (0, _emberMetal.defineProperty)(obj, 'bazAlias', (0, _computed_macros.deprecatingAlias)('baz')); (0, _emberMetal.defineProperty)(obj, 'quzAlias', (0, _computed_macros.deprecatingAlias)('quz')); (0, _emberMetal.defineProperty)(obj, 'bayAlias', (0, _computed_macros.deprecatingAlias)('bay')); expectDeprecation(function () { equal(get(obj, 'barAlias'), 'asdf'); }, 'Usage of `barAlias` is deprecated, use `bar` instead.'); expectDeprecation(function () { equal(get(obj, 'bazAlias'), null); }, 'Usage of `bazAlias` is deprecated, use `baz` instead.'); expectDeprecation(function () { equal(get(obj, 'quzAlias'), false); }, 'Usage of `quzAlias` is deprecated, use `quz` instead.'); expectDeprecation(function () { equal(get(obj, 'bayAlias'), 'apple'); }, 'Usage of `bayAlias` is deprecated, use `bay` instead.'); expectDeprecation(function () { set(obj, 'barAlias', 'newBar'); }, 'Usage of `barAlias` is deprecated, use `bar` instead.'); expectDeprecation(function () { set(obj, 'bazAlias', 'newBaz'); }, 'Usage of `bazAlias` is deprecated, use `baz` instead.'); expectDeprecation(function () { set(obj, 'quzAlias', null); }, 'Usage of `quzAlias` is deprecated, use `quz` instead.'); equal(get(obj, 'barAlias'), 'newBar'); equal(get(obj, 'bazAlias'), 'newBaz'); equal(get(obj, 'quzAlias'), null); equal(get(obj, 'bar'), 'newBar'); equal(get(obj, 'baz'), 'newBaz'); equal(get(obj, 'quz'), null); }); }); enifed('ember-runtime/tests/computed/reduce_computed_macros_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object', 'ember-runtime/system/object_proxy', 'ember-runtime/computed/reduce_computed_macros', 'ember-runtime/utils', 'ember-runtime/system/native_array', 'ember-runtime/mixins/mutable_array'], function (_emberMetal, _internalTestHelpers, _object, _object_proxy, _reduce_computed_macros, _utils, _native_array, _mutable_array) { 'use strict'; var obj = void 0; QUnit.module('map', { setup: function () { obj = _object.default.extend({ mapped: (0, _reduce_computed_macros.map)('array.@each.v', function (item) { return item.v; }), mappedObjects: (0, _reduce_computed_macros.map)('arrayObjects.@each.v', function (item) { return { name: item.v.name }; }) }).create({ arrayObjects: (0, _native_array.A)([{ v: { name: 'Robert' } }, { v: { name: 'Leanna' } }]), array: (0, _native_array.A)([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('map is readOnly', function () { QUnit.throws(function () { obj.set('mapped', 1); }, /Cannot set read-only property "mapped" on object:/); }); QUnit.test('it maps simple properties', function () { deepEqual(obj.get('mapped'), [1, 3, 2, 1]); obj.get('array').pushObject({ v: 5 }); deepEqual(obj.get('mapped'), [1, 3, 2, 1, 5]); (0, _mutable_array.removeAt)(obj.get('array'), 3); deepEqual(obj.get('mapped'), [1, 3, 2, 5]); }); QUnit.test('it maps simple unshifted properties', function () { var array = (0, _native_array.A)(); obj = _object.default.extend({ mapped: (0, _reduce_computed_macros.map)('array', function (item) { return item.toUpperCase(); }) }).create({ array: array }); array.unshiftObject('c'); array.unshiftObject('b'); array.unshiftObject('a'); array.popObject(); deepEqual(obj.get('mapped'), ['A', 'B'], 'properties unshifted in sequence are mapped correctly'); }); QUnit.test('it has the correct `this`', function () { obj = _object.default.extend({ mapped: (0, _reduce_computed_macros.map)('array', function (item) { equal(this, obj, 'should have correct context'); return this.upperCase(item); }), upperCase: function (string) { return string.toUpperCase(); } }).create({ array: ['a', 'b', 'c'] }); deepEqual(obj.get('mapped'), ['A', 'B', 'C'], 'properties unshifted in sequence are mapped correctly'); }); QUnit.test('it passes the index to the callback', function () { obj = _object.default.extend({ mapped: (0, _reduce_computed_macros.map)('array', function (item, index) { return index; }) }).create({ array: ['a', 'b', 'c'] }); deepEqual(obj.get('mapped'), [0, 1, 2], 'index is passed to callback correctly'); }); QUnit.test('it maps objects', function () { deepEqual(obj.get('mappedObjects'), [{ name: 'Robert' }, { name: 'Leanna' }]); obj.get('arrayObjects').pushObject({ v: { name: 'Eddard' } }); deepEqual(obj.get('mappedObjects'), [{ name: 'Robert' }, { name: 'Leanna' }, { name: 'Eddard' }]); (0, _mutable_array.removeAt)(obj.get('arrayObjects'), 1); deepEqual(obj.get('mappedObjects'), [{ name: 'Robert' }, { name: 'Eddard' }]); (0, _emberMetal.set)(obj.get('arrayObjects')[0], 'v', { name: 'Stannis' }); deepEqual(obj.get('mappedObjects'), [{ name: 'Stannis' }, { name: 'Eddard' }]); }); QUnit.test('it maps unshifted objects with property observers', function () { var array = (0, _native_array.A)(); var cObj = { v: 'c' }; obj = _object.default.extend({ mapped: (0, _reduce_computed_macros.map)('array.@each.v', function (item) { return (0, _emberMetal.get)(item, 'v').toUpperCase(); }) }).create({ array: array }); array.unshiftObject(cObj); array.unshiftObject({ v: 'b' }); array.unshiftObject({ v: 'a' }); (0, _emberMetal.set)(cObj, 'v', 'd'); deepEqual(array.mapBy('v'), ['a', 'b', 'd'], 'precond - unmapped array is correct'); deepEqual(obj.get('mapped'), ['A', 'B', 'D'], 'properties unshifted in sequence are mapped correctly'); }); QUnit.module('mapBy', { setup: function () { obj = _object.default.extend({ mapped: (0, _reduce_computed_macros.mapBy)('array', 'v') }).create({ array: (0, _native_array.A)([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('mapBy is readOnly', function () { QUnit.throws(function () { obj.set('mapped', 1); }, /Cannot set read-only property "mapped" on object:/); }); QUnit.test('it maps properties', function () { deepEqual(obj.get('mapped'), [1, 3, 2, 1]); obj.get('array').pushObject({ v: 5 }); deepEqual(obj.get('mapped'), [1, 3, 2, 1, 5]); (0, _mutable_array.removeAt)(obj.get('array'), 3); deepEqual(obj.get('mapped'), [1, 3, 2, 5]); }); QUnit.test('it is observable', function () { var calls = 0; deepEqual(obj.get('mapped'), [1, 3, 2, 1]); (0, _emberMetal.addObserver)(obj, 'mapped.@each', function () { return calls++; }); obj.get('array').pushObject({ v: 5 }); equal(calls, 1, 'mapBy is observable'); }); QUnit.module('filter', { setup: function () { obj = _object.default.extend({ filtered: (0, _reduce_computed_macros.filter)('array', function (item) { return item % 2 === 0; }) }).create({ array: (0, _native_array.A)([1, 2, 3, 4, 5, 6, 7, 8]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('filter is readOnly', function () { QUnit.throws(function () { obj.set('filtered', 1); }, /Cannot set read-only property "filtered" on object:/); }); QUnit.test('it filters according to the specified filter function', function () { deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'filter filters by the specified function'); }); QUnit.test('it passes the index to the callback', function () { obj = _object.default.extend({ filtered: (0, _reduce_computed_macros.filter)('array', function (item, index) { return index === 1; }) }).create({ array: ['a', 'b', 'c'] }); deepEqual((0, _emberMetal.get)(obj, 'filtered'), ['b'], 'index is passed to callback correctly'); }); QUnit.test('it has the correct `this`', function () { obj = _object.default.extend({ filtered: (0, _reduce_computed_macros.filter)('array', function (item, index) { equal(this, obj); return this.isOne(index); }), isOne: function (value) { return value === 1; } }).create({ array: ['a', 'b', 'c'] }); deepEqual((0, _emberMetal.get)(obj, 'filtered'), ['b'], 'index is passed to callback correctly'); }); QUnit.test('it passes the array to the callback', function () { obj = _object.default.extend({ filtered: (0, _reduce_computed_macros.filter)('array', function (item, index, array) { return index === (0, _emberMetal.get)(array, 'length') - 2; }) }).create({ array: (0, _native_array.A)(['a', 'b', 'c']) }); deepEqual(obj.get('filtered'), ['b'], 'array is passed to callback correctly'); }); QUnit.test('it caches properly', function () { var array = obj.get('array'); var filtered = obj.get('filtered'); ok(filtered === obj.get('filtered')); array.addObject(11); var newFiltered = obj.get('filtered'); ok(filtered !== newFiltered); ok(obj.get('filtered') === newFiltered); }); QUnit.test('it updates as the array is modified', function () { var array = obj.get('array'); deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'precond - filtered array is initially correct'); array.addObject(11); deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'objects not passing the filter are not added'); array.addObject(12); deepEqual(obj.get('filtered'), [2, 4, 6, 8, 12], 'objects passing the filter are added'); array.removeObject(3); array.removeObject(4); deepEqual(obj.get('filtered'), [2, 6, 8, 12], 'objects removed from the dependent array are removed from the computed array'); }); QUnit.test('the dependent array can be cleared one at a time', function () { var array = (0, _emberMetal.get)(obj, 'array'); deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'precond - filtered array is initially correct'); // clear 1-8 but in a random order array.removeObject(3); array.removeObject(1); array.removeObject(2); array.removeObject(4); array.removeObject(8); array.removeObject(6); array.removeObject(5); array.removeObject(7); deepEqual(obj.get('filtered'), [], 'filtered array cleared correctly'); }); QUnit.test('the dependent array can be `clear`ed directly (#3272)', function () { deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'precond - filtered array is initially correct'); obj.get('array').clear(); deepEqual(obj.get('filtered'), [], 'filtered array cleared correctly'); }); QUnit.test('it updates as the array is replaced', function () { deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'precond - filtered array is initially correct'); obj.set('array', [20, 21, 22, 23, 24]); deepEqual(obj.get('filtered'), [20, 22, 24], 'computed array is updated when array is changed'); }); QUnit.module('filterBy', { setup: function () { obj = _object.default.extend({ a1s: (0, _reduce_computed_macros.filterBy)('array', 'a', 1), as: (0, _reduce_computed_macros.filterBy)('array', 'a'), bs: (0, _reduce_computed_macros.filterBy)('array', 'b') }).create({ array: (0, _native_array.A)([{ name: 'one', a: 1, b: false }, { name: 'two', a: 2, b: false }, { name: 'three', a: 1, b: true }, { name: 'four', b: true }]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('filterBy is readOnly', function () { QUnit.throws(function () { obj.set('as', 1); }, /Cannot set read-only property "as" on object:/); }); QUnit.test('properties can be filtered by truthiness', function () { deepEqual(obj.get('as').mapBy('name'), ['one', 'two', 'three'], 'properties can be filtered by existence'); deepEqual(obj.get('bs').mapBy('name'), ['three', 'four'], 'booleans can be filtered'); (0, _emberMetal.set)(obj.get('array')[0], 'a', undefined); (0, _emberMetal.set)(obj.get('array')[3], 'a', true); (0, _emberMetal.set)(obj.get('array')[0], 'b', true); (0, _emberMetal.set)(obj.get('array')[3], 'b', false); deepEqual(obj.get('as').mapBy('name'), ['two', 'three', 'four'], 'arrays computed by filter property respond to property changes'); deepEqual(obj.get('bs').mapBy('name'), ['one', 'three'], 'arrays computed by filtered property respond to property changes'); obj.get('array').pushObject({ name: 'five', a: 6, b: true }); deepEqual(obj.get('as').mapBy('name'), ['two', 'three', 'four', 'five'], 'arrays computed by filter property respond to added objects'); deepEqual(obj.get('bs').mapBy('name'), ['one', 'three', 'five'], 'arrays computed by filtered property respond to added objects'); obj.get('array').popObject(); deepEqual(obj.get('as').mapBy('name'), ['two', 'three', 'four'], 'arrays computed by filter property respond to removed objects'); deepEqual(obj.get('bs').mapBy('name'), ['one', 'three'], 'arrays computed by filtered property respond to removed objects'); obj.set('array', [{ name: 'six', a: 12, b: true }]); deepEqual(obj.get('as').mapBy('name'), ['six'], 'arrays computed by filter property respond to array changes'); deepEqual(obj.get('bs').mapBy('name'), ['six'], 'arrays computed by filtered property respond to array changes'); }); QUnit.test('properties can be filtered by values', function () { deepEqual(obj.get('a1s').mapBy('name'), ['one', 'three'], 'properties can be filtered by matching value'); obj.get('array').pushObject({ name: 'five', a: 1 }); deepEqual(obj.get('a1s').mapBy('name'), ['one', 'three', 'five'], 'arrays computed by matching value respond to added objects'); obj.get('array').popObject(); deepEqual(obj.get('a1s').mapBy('name'), ['one', 'three'], 'arrays computed by matching value respond to removed objects'); (0, _emberMetal.set)(obj.get('array')[1], 'a', 1); (0, _emberMetal.set)(obj.get('array')[2], 'a', 2); deepEqual(obj.get('a1s').mapBy('name'), ['one', 'two'], 'arrays computed by matching value respond to modified properties'); }); QUnit.test('properties values can be replaced', function () { obj = _object.default.extend({ a1s: (0, _reduce_computed_macros.filterBy)('array', 'a', 1), a1bs: (0, _reduce_computed_macros.filterBy)('a1s', 'b') }).create({ array: [] }); deepEqual(obj.get('a1bs').mapBy('name'), [], 'properties can be filtered by matching value'); (0, _emberMetal.set)(obj, 'array', [{ name: 'item1', a: 1, b: true }]); deepEqual(obj.get('a1bs').mapBy('name'), ['item1'], 'properties can be filtered by matching value'); }); [['uniq', _reduce_computed_macros.uniq], ['union', _reduce_computed_macros.union]].forEach(function (tuple) { var name = tuple[0], macro = tuple[1]; QUnit.module('computed.' + name, { setup: function () { obj = _object.default.extend({ union: macro('array', 'array2', 'array3') }).create({ array: (0, _native_array.A)([1, 2, 3, 4, 5, 6]), array2: (0, _native_array.A)([4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]), array3: (0, _native_array.A)([1, 8, 10]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test(name + ' is readOnly', function () { QUnit.throws(function () { obj.set('union', 1); }, /Cannot set read-only property "union" on object:/); }); QUnit.test('does not include duplicates', function () { var array = obj.get('array'); var array2 = obj.get('array2'); deepEqual(obj.get('union').sort(function (x, y) { return x - y; }), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], name + ' does not include duplicates'); array.pushObject(8); deepEqual(obj.get('union').sort(function (x, y) { return x - y; }), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], name + ' does not add existing items'); array.pushObject(11); deepEqual(obj.get('union').sort(function (x, y) { return x - y; }), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], name + ' adds new items'); (0, _mutable_array.removeAt)(array2, 6); // remove 7 deepEqual(obj.get('union').sort(function (x, y) { return x - y; }), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], name + ' does not remove items that are still in the dependent array'); array2.removeObject(7); deepEqual(obj.get('union').sort(function (x, y) { return x - y; }), [1, 2, 3, 4, 5, 6, 8, 9, 10, 11], name + ' removes items when their last instance is gone'); }); QUnit.test('has set-union semantics', function () { var array = obj.get('array'); deepEqual(obj.get('union').sort(function (x, y) { return x - y; }), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], name + ' is initially correct'); array.removeObject(6); deepEqual(obj.get('union').sort(function (x, y) { return x - y; }), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'objects are not removed if they exist in other dependent arrays'); array.clear(); deepEqual(obj.get('union').sort(function (x, y) { return x - y; }), [1, 4, 5, 6, 7, 8, 9, 10], 'objects are removed when they are no longer in any dependent array'); }); }); QUnit.module('computed.uniqBy', { setup: function () { obj = _object.default.extend({ list: null, uniqueById: (0, _reduce_computed_macros.uniqBy)('list', 'id') }).create({ list: (0, _native_array.A)([{ id: 1, value: 'one' }, { id: 2, value: 'two' }, { id: 1, value: 'one' }]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('uniqBy is readOnly', function () { QUnit.throws(function () { obj.set('uniqueById', 1); }, /Cannot set read-only property "uniqueById" on object:/); }); QUnit.test('does not include duplicates', function () { deepEqual(obj.get('uniqueById'), [{ id: 1, value: 'one' }, { id: 2, value: 'two' }]); }); QUnit.test('it does not share state among instances', function () { var MyObject = _object.default.extend({ list: [], uniqueByName: (0, _reduce_computed_macros.uniqBy)('list', 'name') }); var a = MyObject.create({ list: [{ name: 'bob' }, { name: 'mitch' }, { name: 'mitch' }] }); var b = MyObject.create({ list: [{ name: 'warren' }, { name: 'mitch' }] }); deepEqual(a.get('uniqueByName'), [{ name: 'bob' }, { name: 'mitch' }]); // Making sure that 'mitch' appears deepEqual(b.get('uniqueByName'), [{ name: 'warren' }, { name: 'mitch' }]); }); QUnit.test('it handles changes to the dependent array', function () { obj.get('list').pushObject({ id: 3, value: 'three' }); deepEqual(obj.get('uniqueById'), [{ id: 1, value: 'one' }, { id: 2, value: 'two' }, { id: 3, value: 'three' }], 'The list includes three'); obj.get('list').pushObject({ id: 3, value: 'three' }); deepEqual(obj.get('uniqueById'), [{ id: 1, value: 'one' }, { id: 2, value: 'two' }, { id: 3, value: 'three' }], 'The list does not include a duplicate three'); }); QUnit.test('it returns an empty array when computed on a non-array', function () { var MyObject = _object.default.extend({ list: null, uniq: (0, _reduce_computed_macros.uniqBy)('list', 'name') }); var a = MyObject.create({ list: 'not an array' }); deepEqual(a.get('uniq'), []); }); QUnit.module('computed.intersect', { setup: function () { obj = _object.default.extend({ intersection: (0, _reduce_computed_macros.intersect)('array', 'array2', 'array3') }).create({ array: (0, _native_array.A)([1, 2, 3, 4, 5, 6]), array2: (0, _native_array.A)([3, 3, 3, 4, 5]), array3: (0, _native_array.A)([3, 5, 6, 7, 8]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('intersect is readOnly', function () { QUnit.throws(function () { obj.set('intersection', 1); }, /Cannot set read-only property "intersection" on object:/); }); QUnit.test('it has set-intersection semantics', function () { var array2 = obj.get('array2'); var array3 = obj.get('array3'); deepEqual(obj.get('intersection').sort(function (x, y) { return x - y; }), [3, 5], 'intersection is initially correct'); array2.shiftObject(); deepEqual(obj.get('intersection').sort(function (x, y) { return x - y; }), [3, 5], 'objects are not removed when they are still in all dependent arrays'); array2.shiftObject(); deepEqual(obj.get('intersection').sort(function (x, y) { return x - y; }), [3, 5], 'objects are not removed when they are still in all dependent arrays'); array2.shiftObject(); deepEqual(obj.get('intersection'), [5], 'objects are removed once they are gone from all dependent arrays'); array2.pushObject(1); deepEqual(obj.get('intersection'), [5], 'objects are not added as long as they are missing from any dependent array'); array3.pushObject(1); deepEqual(obj.get('intersection').sort(function (x, y) { return x - y; }), [1, 5], 'objects added once they belong to all dependent arrays'); }); QUnit.module('setDiff', { setup: function () { obj = _object.default.extend({ diff: (0, _reduce_computed_macros.setDiff)('array', 'array2') }).create({ array: (0, _native_array.A)([1, 2, 3, 4, 5, 6, 7]), array2: (0, _native_array.A)([3, 4, 5, 10]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('setDiff is readOnly', function () { QUnit.throws(function () { obj.set('diff', 1); }, /Cannot set read-only property "diff" on object:/); }); QUnit.test('it throws an error if given fewer or more than two dependent properties', function () { throws(function () { _object.default.extend({ diff: (0, _reduce_computed_macros.setDiff)('array') }).create({ array: (0, _native_array.A)([1, 2, 3, 4, 5, 6, 7]), array2: (0, _native_array.A)([3, 4, 5]) }); }, /requires exactly two dependent arrays/, 'setDiff requires two dependent arrays'); throws(function () { _object.default.extend({ diff: (0, _reduce_computed_macros.setDiff)('array', 'array2', 'array3') }).create({ array: (0, _native_array.A)([1, 2, 3, 4, 5, 6, 7]), array2: (0, _native_array.A)([3, 4, 5]), array3: (0, _native_array.A)([7]) }); }, /requires exactly two dependent arrays/, 'setDiff requires two dependent arrays'); }); QUnit.test('it has set-diff semantics', function () { var array1 = obj.get('array'); var array2 = obj.get('array2'); deepEqual(obj.get('diff').sort(function (x, y) { return x - y; }), [1, 2, 6, 7], 'set-diff is initially correct'); array2.popObject(); deepEqual(obj.get('diff').sort(function (x, y) { return x - y; }), [1, 2, 6, 7], 'removing objects from the remove set has no effect if the object is not in the keep set'); array2.shiftObject(); deepEqual(obj.get('diff').sort(function (x, y) { return x - y; }), [1, 2, 3, 6, 7], 'removing objects from the remove set adds them if they\'re in the keep set'); array1.removeObject(3); deepEqual(obj.get('diff').sort(function (x, y) { return x - y; }), [1, 2, 6, 7], 'removing objects from the keep array removes them from the computed array'); array1.pushObject(5); deepEqual(obj.get('diff').sort(function (x, y) { return x - y; }), [1, 2, 6, 7], 'objects added to the keep array that are in the remove array are not added to the computed array'); array1.pushObject(22); deepEqual(obj.get('diff').sort(function (x, y) { return x - y; }), [1, 2, 6, 7, 22], 'objects added to the keep array not in the remove array are added to the computed array'); }); function commonSortTests() { QUnit.test('arrays are initially sorted', function () { deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'array is initially sorted'); }); QUnit.test('default sort order is correct', function () { deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'array is initially sorted'); }); QUnit.test('changing the dependent array updates the sorted array', function () { deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); obj.set('items', [{ fname: 'Roose', lname: 'Bolton' }, { fname: 'Theon', lname: 'Greyjoy' }, { fname: 'Ramsey', lname: 'Bolton' }, { fname: 'Stannis', lname: 'Baratheon' }]); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Stannis', 'Ramsey', 'Roose', 'Theon'], 'changing dependent array updates sorted array'); }); QUnit.test('adding to the dependent array updates the sorted array', function () { var items = obj.get('items'); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); items.pushObject({ fname: 'Tyrion', lname: 'Lannister' }); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb'], 'Adding to the dependent array updates the sorted array'); }); QUnit.test('removing from the dependent array updates the sorted array', function () { deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); obj.get('items').popObject(); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Robb'], 'Removing from the dependent array updates the sorted array'); }); QUnit.test('distinct items may be sort-equal, although their relative order will not be guaranteed', function () { // We recreate jaime and "Cersei" here only for test stability: we want // their guid-ordering to be deterministic var jaimeInDisguise = { fname: 'Cersei', lname: 'Lannister', age: 34 }; var items = obj.get('items'); items.replace(0, 1, { fname: 'Jaime', lname: 'Lannister', age: 34 }); items.replace(1, 1, jaimeInDisguise); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); (0, _emberMetal.set)(jaimeInDisguise, 'fname', 'Jaime'); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Jaime', 'Jaime', 'Bran', 'Robb'], 'sorted array is updated'); (0, _emberMetal.set)(jaimeInDisguise, 'fname', 'Cersei'); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'sorted array is updated'); }); QUnit.test('guid sort-order fallback with a search proxy is not confused by non-search ObjectProxys', function () { var tyrion = { fname: 'Tyrion', lname: 'Lannister' }; var tyrionInDisguise = _object_proxy.default.create({ fname: 'Yollo', lname: '', content: tyrion }); var items = obj.get('items'); items.pushObject(tyrion); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb']); items.pushObject(tyrionInDisguise); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Yollo', 'Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb']); }); } QUnit.module('sort - sortProperties', { setup: function () { obj = _object.default.extend({ sortedItems: (0, _reduce_computed_macros.sort)('items', 'itemSorting') }).create({ itemSorting: (0, _native_array.A)(['lname', 'fname']), items: (0, _native_array.A)([{ fname: 'Jaime', lname: 'Lannister', age: 34 }, { fname: 'Cersei', lname: 'Lannister', age: 34 }, { fname: 'Robb', lname: 'Stark', age: 16 }, { fname: 'Bran', lname: 'Stark', age: 8 }]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('sort is readOnly', function () { QUnit.throws(function () { obj.set('sortedItems', 1); }, /Cannot set read-only property "sortedItems" on object:/); }); commonSortTests(); QUnit.test('updating sort properties detaches observers for old sort properties', function () { var objectToRemove = obj.get('items')[3]; deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); obj.set('itemSorting', (0, _native_array.A)(['fname:desc'])); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Robb', 'Jaime', 'Cersei', 'Bran'], 'after updating sort properties array is updated'); obj.get('items').removeObject(objectToRemove); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Robb', 'Jaime', 'Cersei'], 'after removing item array is updated'); (0, _emberMetal.set)(objectToRemove, 'lname', 'Updated-Stark'); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Robb', 'Jaime', 'Cersei'], 'after changing removed item array is not updated'); }); QUnit.test('updating sort properties updates the sorted array', function () { deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); obj.set('itemSorting', (0, _native_array.A)(['fname:desc'])); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Robb', 'Jaime', 'Cersei', 'Bran'], 'after updating sort properties array is updated'); }); QUnit.test('updating sort properties invalidates the sorted array', function () { var sortProps = obj.get('itemSorting'); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); sortProps.clear(); sortProps.pushObject('fname'); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Bran', 'Cersei', 'Jaime', 'Robb'], 'after updating sort properties array is updated'); }); QUnit.test('updating new sort properties invalidates the sorted array', function () { deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); obj.set('itemSorting', (0, _native_array.A)(['age:desc', 'fname:asc'])); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Robb', 'Bran'], 'precond - array is correct after item sorting is changed'); (0, _emberMetal.set)(obj.get('items')[1], 'age', 29); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Jaime', 'Cersei', 'Robb', 'Bran'], 'after updating sort properties array is updated'); }); QUnit.test('sort direction defaults to ascending', function () { deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb']); }); QUnit.test('sort direction defaults to ascending (with sort property change)', function () { deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); obj.set('itemSorting', (0, _native_array.A)(['fname'])); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Bran', 'Cersei', 'Jaime', 'Robb'], 'sort direction defaults to ascending'); }); QUnit.test('updating an item\'s sort properties updates the sorted array', function () { var tyrionInDisguise = obj.get('items')[1]; deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); (0, _emberMetal.set)(tyrionInDisguise, 'fname', 'Tyrion'); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Jaime', 'Tyrion', 'Bran', 'Robb'], 'updating an item\'s sort properties updates the sorted array'); }); QUnit.test('updating several of an item\'s sort properties updated the sorted array', function () { var sansaInDisguise = obj.get('items')[1]; deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); (0, _emberMetal.setProperties)(sansaInDisguise, { fname: 'Sansa', lname: 'Stark' }); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Jaime', 'Bran', 'Robb', 'Sansa'], 'updating an item\'s sort properties updates the sorted array'); }); QUnit.test('updating an item\'s sort properties does not error when binary search does a self compare (#3273)', function () { var jaime = { name: 'Jaime', status: 1 }; var cersei = { name: 'Cersei', status: 2 }; var obj = _object.default.extend({ sortProps: ['status'], sortedPeople: (0, _reduce_computed_macros.sort)('people', 'sortProps') }).create({ people: [jaime, cersei] }); deepEqual(obj.get('sortedPeople'), [jaime, cersei], 'precond - array is initially sorted'); (0, _emberMetal.set)(cersei, 'status', 3); deepEqual(obj.get('sortedPeople'), [jaime, cersei], 'array is sorted correctly'); (0, _emberMetal.set)(cersei, 'status', 2); deepEqual(obj.get('sortedPeople'), [jaime, cersei], 'array is sorted correctly'); }); QUnit.test('array observers do not leak', function () { var sortProps = (0, _native_array.A)(['name']); var jaime = _object.default.extend({ sortedPeople: (0, _reduce_computed_macros.sort)('sisters', 'sortProps'), sortProps: sortProps }).create({ sisters: [{ name: 'Jane' }, { name: 'Daria' }] }); jaime.get('sortedPeople'); (0, _emberMetal.run)(jaime, 'destroy'); try { sortProps.pushObject({ name: 'Anna' }); ok(true); } catch (e) { ok(false, e); } }); QUnit.test('property paths in sort properties update the sorted array', function () { var jaime = { relatedObj: { status: 1, firstName: 'Jaime', lastName: 'Lannister' } }; var cersei = { relatedObj: { status: 2, firstName: 'Cersei', lastName: 'Lannister' } }; var sansa = _object.default.create({ relatedObj: { status: 3, firstName: 'Sansa', lastName: 'Stark' } }); var obj = _object.default.extend({ sortProps: ['relatedObj.status'], sortedPeople: (0, _reduce_computed_macros.sort)('people', 'sortProps') }).create({ people: [jaime, cersei, sansa] }); deepEqual(obj.get('sortedPeople'), [jaime, cersei, sansa], 'precond - array is initially sorted'); (0, _emberMetal.set)(cersei, 'status', 3); deepEqual(obj.get('sortedPeople'), [jaime, cersei, sansa], 'array is sorted correctly'); (0, _emberMetal.set)(cersei, 'status', 1); deepEqual(obj.get('sortedPeople'), [jaime, cersei, sansa], 'array is sorted correctly'); sansa.set('status', 1); deepEqual(obj.get('sortedPeople'), [jaime, cersei, sansa], 'array is sorted correctly'); obj.set('sortProps', ['relatedObj.firstName']); deepEqual(obj.get('sortedPeople'), [cersei, jaime, sansa], 'array is sorted correctly'); }); QUnit.test('if the dependentKey is neither an array nor object, it will return an empty array', function () { (0, _emberMetal.set)(obj, 'items', null); ok((0, _utils.isArray)(obj.get('sortedItems')), 'returns an empty arrays'); (0, _emberMetal.set)(obj, 'array', undefined); ok((0, _utils.isArray)(obj.get('sortedItems')), 'returns an empty arrays'); (0, _emberMetal.set)(obj, 'array', 'not an array'); ok((0, _utils.isArray)(obj.get('sortedItems')), 'returns an empty arrays'); }); function sortByLnameFname(a, b) { var lna = (0, _emberMetal.get)(a, 'lname'); var lnb = (0, _emberMetal.get)(b, 'lname'); if (lna !== lnb) { return lna > lnb ? 1 : -1; } return sortByFnameAsc(a, b); } function sortByFnameAsc(a, b) { var fna = (0, _emberMetal.get)(a, 'fname'); var fnb = (0, _emberMetal.get)(b, 'fname'); if (fna === fnb) { return 0; } return fna > fnb ? 1 : -1; } QUnit.module('sort - sort function', { setup: function () { obj = _object.default.extend({ sortedItems: (0, _reduce_computed_macros.sort)('items.@each.fname', sortByLnameFname) }).create({ items: (0, _native_array.A)([{ fname: 'Jaime', lname: 'Lannister', age: 34 }, { fname: 'Cersei', lname: 'Lannister', age: 34 }, { fname: 'Robb', lname: 'Stark', age: 16 }, { fname: 'Bran', lname: 'Stark', age: 8 }]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('sort has correct `this`', function () { var obj = _object.default.extend({ sortedItems: (0, _reduce_computed_macros.sort)('items.@each.fname', function (a, b) { equal(this, obj, 'expected the object to be `this`'); return this.sortByLastName(a, b); }), sortByLastName: function (a, b) { return sortByFnameAsc(a, b); } }).create({ items: (0, _native_array.A)([{ fname: 'Jaime', lname: 'Lannister', age: 34 }, { fname: 'Cersei', lname: 'Lannister', age: 34 }, { fname: 'Robb', lname: 'Stark', age: 16 }, { fname: 'Bran', lname: 'Stark', age: 8 }]) }); obj.get('sortedItems'); }); QUnit.test('sort (with function) is readOnly', function () { QUnit.throws(function () { obj.set('sortedItems', 1); }, /Cannot set read-only property "sortedItems" on object:/); }); commonSortTests(); QUnit.test('changing item properties specified via @each triggers a resort of the modified item', function () { var items = (0, _emberMetal.get)(obj, 'items'); var tyrionInDisguise = items[1]; deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); (0, _emberMetal.set)(tyrionInDisguise, 'fname', 'Tyrion'); deepEqual(obj.get('sortedItems').mapBy('fname'), ['Jaime', 'Tyrion', 'Bran', 'Robb'], 'updating a specified property on an item resorts it'); }); QUnit.test('changing item properties not specified via @each does not trigger a resort', function () { var items = obj.get('items'); var cersei = items[1]; deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted'); (0, _emberMetal.set)(cersei, 'lname', 'Stark'); // plot twist! (possibly not canon) // The array has become unsorted. If your sort function is sensitive to // properties, they *must* be specified as dependent item property keys or // we'll be doing binary searches on unsorted arrays. deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'updating an unspecified property on an item does not resort it'); }); QUnit.module('sort - stability', { setup: function () { obj = _object.default.extend({ sortProps: ['count', 'name'], sortedItems: (0, _reduce_computed_macros.sort)('items', 'sortProps') }).create({ items: [{ name: 'A', count: 1, thing: 4 }, { name: 'B', count: 1, thing: 3 }, { name: 'C', count: 1, thing: 2 }, { name: 'D', count: 1, thing: 4 }] }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('sorts correctly as only one property changes', function () { deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'initial'); (0, _emberMetal.set)(obj.get('items')[3], 'count', 2); deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'final'); }); var klass = void 0; QUnit.module('sort - concurrency', { setup: function () { klass = _object.default.extend({ sortProps: ['count'], sortedItems: (0, _reduce_computed_macros.sort)('items', 'sortProps'), customSortedItems: (0, _reduce_computed_macros.sort)('items.@each.count', function (a, b) { return a.count - b.count; }) }); obj = klass.create({ items: (0, _native_array.A)([{ name: 'A', count: 1, thing: 4, id: 1 }, { name: 'B', count: 2, thing: 3, id: 2 }, { name: 'C', count: 3, thing: 2, id: 3 }, { name: 'D', count: 4, thing: 1, id: 4 }]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('sorts correctly after mutation to the sort properties', function () { var sorted = obj.get('sortedItems'); deepEqual(sorted.mapBy('name'), ['A', 'B', 'C', 'D'], 'initial'); (0, _emberMetal.set)(obj.get('items')[1], 'count', 5); (0, _emberMetal.set)(obj.get('items')[2], 'count', 6); deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final'); }); QUnit.test('sort correctly after mutation to the sort', function () { deepEqual(obj.get('customSortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'initial'); (0, _emberMetal.set)(obj.get('items')[1], 'count', 5); (0, _emberMetal.set)(obj.get('items')[2], 'count', 6); deepEqual(obj.get('customSortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final'); deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final'); }); QUnit.test('sort correctly on multiple instances of the same class', function () { var obj2 = klass.create({ items: (0, _native_array.A)([{ name: 'W', count: 23, thing: 4 }, { name: 'X', count: 24, thing: 3 }, { name: 'Y', count: 25, thing: 2 }, { name: 'Z', count: 26, thing: 1 }]) }); deepEqual(obj2.get('sortedItems').mapBy('name'), ['W', 'X', 'Y', 'Z'], 'initial'); deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'initial'); (0, _emberMetal.set)(obj.get('items')[1], 'count', 5); (0, _emberMetal.set)(obj.get('items')[2], 'count', 6); (0, _emberMetal.set)(obj2.get('items')[1], 'count', 27); (0, _emberMetal.set)(obj2.get('items')[2], 'count', 28); deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final'); deepEqual(obj2.get('sortedItems').mapBy('name'), ['W', 'Z', 'X', 'Y'], 'final'); obj.set('sortProps', ['thing']); deepEqual(obj.get('sortedItems').mapBy('name'), ['D', 'C', 'B', 'A'], 'final'); obj2.notifyPropertyChange('sortedItems'); // invalidate to flush, to get DK refreshed obj2.get('sortedItems'); // flush to get updated DK obj2.set('items.firstObject.count', 9999); deepEqual(obj2.get('sortedItems').mapBy('name'), ['Z', 'X', 'Y', 'W'], 'final'); }); QUnit.test('sort correctly when multiple sorts are chained on the same instance of a class', function () { var obj2 = klass.extend({ items: (0, _emberMetal.computed)('sibling.sortedItems.[]', function () { return this.get('sibling.sortedItems'); }), asdf: (0, _emberMetal.observer)('sibling.sortedItems.[]', function () { this.get('sibling.sortedItems'); }) }).create({ sibling: obj }); /* ┌───────────┐ ┌────────────┐ │sortedProps│ │sortedProps2│ └───────────┘ └────────────┘ ▲ ▲ │ ╔═══════════╗ │ │─ ─ ─ ─ ─ ─ ─ ▶║ CP (sort) ║◀─ ─ ─ ─ ─ ─ ─ ┤ │ ╚═══════════╝ │ │ │ ┌───────────┐ ┏━━━━━━━━━━━┓ ┏━━━━━━━━━━━━┓ │ │ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ ┃ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ ┃ │ items │◀── items.@each.count │◀──┃sortedItems┃◀─── items.@each.count │◀───┃sortedItems2┃ │ │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ ┃ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ ┃ └───────────┘ ┗━━━━━━━━━━━┛ ┗━━━━━━━━━━━━┛ */ deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'obj.sortedItems.name should be sorted alpha'); deepEqual(obj2.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'obj2.sortedItems.name should be sorted alpha'); (0, _emberMetal.set)(obj.get('items')[1], 'count', 5); (0, _emberMetal.set)(obj.get('items')[2], 'count', 6); deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'obj.sortedItems.name should now have changed'); deepEqual(obj2.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'obj2.sortedItems.name should still mirror sortedItems2'); obj.set('sortProps', ['thing']); obj2.set('sortProps', ['id']); deepEqual(obj2.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'we now sort obj2 by id, so we expect a b c d'); deepEqual(obj.get('sortedItems').mapBy('name'), ['D', 'C', 'B', 'A'], 'we now sort obj by thing'); }); QUnit.module('max', { setup: function () { obj = _object.default.extend({ max: (0, _reduce_computed_macros.max)('items') }).create({ items: (0, _native_array.A)([1, 2, 3]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('max is readOnly', function () { QUnit.throws(function () { obj.set('max', 1); }, /Cannot set read-only property "max" on object:/); }); QUnit.test('max tracks the max number as objects are added', function () { equal(obj.get('max'), 3, 'precond - max is initially correct'); var items = obj.get('items'); items.pushObject(5); equal(obj.get('max'), 5, 'max updates when a larger number is added'); items.pushObject(2); equal(obj.get('max'), 5, 'max does not update when a smaller number is added'); }); QUnit.test('max recomputes when the current max is removed', function () { equal(obj.get('max'), 3, 'precond - max is initially correct'); obj.get('items').removeObject(2); equal(obj.get('max'), 3, 'max is unchanged when a non-max item is removed'); obj.get('items').removeObject(3); equal(obj.get('max'), 1, 'max is recomputed when the current max is removed'); }); QUnit.module('min', { setup: function () { obj = _object.default.extend({ min: (0, _reduce_computed_macros.min)('items') }).create({ items: (0, _native_array.A)([1, 2, 3]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('min is readOnly', function () { QUnit.throws(function () { obj.set('min', 1); }, /Cannot set read-only property "min" on object:/); }); QUnit.test('min tracks the min number as objects are added', function () { equal(obj.get('min'), 1, 'precond - min is initially correct'); obj.get('items').pushObject(-2); equal(obj.get('min'), -2, 'min updates when a smaller number is added'); obj.get('items').pushObject(2); equal(obj.get('min'), -2, 'min does not update when a larger number is added'); }); QUnit.test('min recomputes when the current min is removed', function () { var items = obj.get('items'); equal(obj.get('min'), 1, 'precond - min is initially correct'); items.removeObject(2); equal(obj.get('min'), 1, 'min is unchanged when a non-min item is removed'); items.removeObject(1); equal(obj.get('min'), 3, 'min is recomputed when the current min is removed'); }); QUnit.module('Ember.arrayComputed - mixed sugar', { setup: function () { obj = _object.default.extend({ lannisters: (0, _reduce_computed_macros.filterBy)('items', 'lname', 'Lannister'), lannisterSorting: (0, _native_array.A)(['fname']), sortedLannisters: (0, _reduce_computed_macros.sort)('lannisters', 'lannisterSorting'), starks: (0, _reduce_computed_macros.filterBy)('items', 'lname', 'Stark'), starkAges: (0, _reduce_computed_macros.mapBy)('starks', 'age'), oldestStarkAge: (0, _reduce_computed_macros.max)('starkAges') }).create({ items: (0, _native_array.A)([{ fname: 'Jaime', lname: 'Lannister', age: 34 }, { fname: 'Cersei', lname: 'Lannister', age: 34 }, { fname: 'Robb', lname: 'Stark', age: 16 }, { fname: 'Bran', lname: 'Stark', age: 8 }]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('filtering and sorting can be combined', function () { var items = obj.get('items'); deepEqual(obj.get('sortedLannisters').mapBy('fname'), ['Cersei', 'Jaime'], 'precond - array is initially filtered and sorted'); items.pushObject({ fname: 'Tywin', lname: 'Lannister' }); items.pushObject({ fname: 'Lyanna', lname: 'Stark' }); items.pushObject({ fname: 'Gerion', lname: 'Lannister' }); deepEqual(obj.get('sortedLannisters').mapBy('fname'), ['Cersei', 'Gerion', 'Jaime', 'Tywin'], 'updates propagate to array'); }); QUnit.test('filtering, sorting and reduce (max) can be combined', function () { var items = obj.get('items'); equal(16, obj.get('oldestStarkAge'), 'precond - end of chain is initially correct'); items.pushObject({ fname: 'Rickon', lname: 'Stark', age: 5 }); equal(16, obj.get('oldestStarkAge'), 'chain is updated correctly'); items.pushObject({ fname: 'Eddard', lname: 'Stark', age: 35 }); equal(35, obj.get('oldestStarkAge'), 'chain is updated correctly'); }); function todo(name, priority) { return _object.default.create({ name: name, priority: priority }); } function priorityComparator(todoA, todoB) { var pa = parseInt((0, _emberMetal.get)(todoA, 'priority'), 10); var pb = parseInt((0, _emberMetal.get)(todoB, 'priority'), 10); return pa - pb; } function evenPriorities(todo) { var p = parseInt((0, _emberMetal.get)(todo, 'priority'), 10); return p % 2 === 0; } QUnit.module('Ember.arrayComputed - chains', { setup: function () { obj = _object.default.extend({ sorted: (0, _reduce_computed_macros.sort)('todos.@each.priority', priorityComparator), filtered: (0, _reduce_computed_macros.filter)('sorted.@each.priority', evenPriorities) }).create({ todos: (0, _native_array.A)([todo('E', 4), todo('D', 3), todo('C', 2), todo('B', 1), todo('A', 0)]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('it can filter and sort when both depend on the same item property', function () { deepEqual(obj.get('todos').mapBy('name'), ['E', 'D', 'C', 'B', 'A'], 'precond - todos initially correct'); deepEqual(obj.get('sorted').mapBy('name'), ['A', 'B', 'C', 'D', 'E'], 'precond - sorted initially correct'); deepEqual(obj.get('filtered').mapBy('name'), ['A', 'C', 'E'], 'precond - filtered initially correct'); (0, _emberMetal.set)(obj.get('todos')[1], 'priority', 6); deepEqual(obj.get('todos').mapBy('name'), ['E', 'D', 'C', 'B', 'A'], 'precond - todos remain correct'); deepEqual(obj.get('sorted').mapBy('name'), ['A', 'B', 'C', 'E', 'D'], 'precond - sorted updated correctly'); deepEqual(obj.get('filtered').mapBy('name'), ['A', 'C', 'E', 'D'], 'filtered updated correctly'); }); var userFnCalls = void 0; QUnit.module('Chaining array and reduced CPs', { setup: function () { userFnCalls = 0; obj = _object.default.extend({ mapped: (0, _reduce_computed_macros.mapBy)('array', 'v'), max: (0, _reduce_computed_macros.max)('mapped'), maxDidChange: (0, _emberMetal.observer)('max', function () { return userFnCalls++; }) }).create({ array: (0, _native_array.A)([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('it computes interdependent array computed properties', function () { equal(obj.get('max'), 3, 'sanity - it properly computes the maximum value'); var calls = 0; (0, _emberMetal.addObserver)(obj, 'max', function () { return calls++; }); obj.get('array').pushObject({ v: 5 }); equal(obj.get('max'), 5, 'maximum value is updated correctly'); equal(userFnCalls, 1, 'object defined observers fire'); equal(calls, 1, 'runtime created observers fire'); }); QUnit.module('sum', { setup: function () { obj = _object.default.extend({ total: (0, _reduce_computed_macros.sum)('array') }).create({ array: (0, _native_array.A)([1, 2, 3]) }); }, teardown: function () { (0, _emberMetal.run)(obj, 'destroy'); } }); QUnit.test('sum is readOnly', function () { QUnit.throws(function () { obj.set('total', 1); }, /Cannot set read-only property "total" on object:/); }); QUnit.test('sums the values in the dependentKey', function () { equal(obj.get('total'), 6, 'sums the values'); }); QUnit.test('if the dependentKey is neither an array nor object, it will return `0`', function () { (0, _emberMetal.set)(obj, 'array', null); equal((0, _emberMetal.get)(obj, 'total'), 0, 'returns 0'); (0, _emberMetal.set)(obj, 'array', undefined); equal((0, _emberMetal.get)(obj, 'total'), 0, 'returns 0'); (0, _emberMetal.set)(obj, 'array', 'not an array'); equal((0, _emberMetal.get)(obj, 'total'), 0, 'returns 0'); }); QUnit.test('updates when array is modified', function () { obj.get('array').pushObject(1); equal(obj.get('total'), 7, 'recomputed when elements are added'); obj.get('array').popObject(); equal(obj.get('total'), 6, 'recomputes when elements are removed'); }); QUnit.module('collect'); (0, _internalTestHelpers.testBoth)('works', function (get, set) { var obj = { one: 'foo', two: 'bar', three: null }; (0, _emberMetal.defineProperty)(obj, 'all', (0, _reduce_computed_macros.collect)('one', 'two', 'three', 'four')); deepEqual(get(obj, 'all'), ['foo', 'bar', null, null], 'have all of them'); set(obj, 'four', true); deepEqual(get(obj, 'all'), ['foo', 'bar', null, true], 'have all of them'); var a = []; set(obj, 'one', 0); set(obj, 'three', a); deepEqual(get(obj, 'all'), [0, 'bar', a, true], 'have all of them'); }); }); enifed('ember-runtime/tests/controllers/controller_test', ['ember-runtime/controllers/controller', 'ember-runtime/system/service', 'ember-metal', 'ember-runtime/system/object', 'ember-runtime/inject', 'internal-test-helpers'], function (_controller, _service, _emberMetal, _object, _inject, _internalTestHelpers) { 'use strict'; /* global EmberDev */ QUnit.module('Controller event handling'); QUnit.test('can access `actions` hash via `_actions` [DEPRECATED]', function () { expect(2); var controller = _controller.default.extend({ actions: { foo: function () { ok(true, 'called foo action'); } } }).create(); expectDeprecation(function () { controller._actions.foo(); }, 'Usage of `_actions` is deprecated, use `actions` instead.'); }); QUnit.test('Action can be handled by a function on actions object', function () { expect(1); var TestController = _controller.default.extend({ actions: { poke: function () { ok(true, 'poked'); } } }); var controller = TestController.create(); controller.send('poke'); }); QUnit.test('A handled action can be bubbled to the target for continued processing', function () { expect(2); var TestController = _controller.default.extend({ actions: { poke: function () { ok(true, 'poked 1'); return true; } } }); var controller = TestController.create({ target: _controller.default.extend({ actions: { poke: function () { ok(true, 'poked 2'); } } }).create() }); controller.send('poke'); }); QUnit.test('Action can be handled by a superclass\' actions object', function () { expect(4); var SuperController = _controller.default.extend({ actions: { foo: function () { ok(true, 'foo'); }, bar: function (msg) { equal(msg, 'HELLO'); } } }); var BarControllerMixin = _emberMetal.Mixin.create({ actions: { bar: function (msg) { equal(msg, 'HELLO'); this._super(msg); } } }); var IndexController = SuperController.extend(BarControllerMixin, { actions: { baz: function () { ok(true, 'baz'); } } }); var controller = IndexController.create({}); controller.send('foo'); controller.send('bar', 'HELLO'); controller.send('baz'); }); QUnit.module('Controller deprecations'); QUnit.module('Controller Content -> Model Alias'); QUnit.test('`model` is aliased as `content`', function () { expect(1); var controller = _controller.default.extend({ model: 'foo-bar' }).create(); equal(controller.get('content'), 'foo-bar', 'content is an alias of model'); }); QUnit.test('`content` is moved to `model` when `model` is unset', function () { expect(2); var controller = void 0; ignoreDeprecation(function () { controller = _controller.default.extend({ content: 'foo-bar' }).create(); }); equal(controller.get('model'), 'foo-bar', 'model is set properly'); equal(controller.get('content'), 'foo-bar', 'content is set properly'); }); QUnit.test('specifying `content` (without `model` specified) results in deprecation', function () { expect(1); expectDeprecation(function () { _controller.default.extend({ content: 'foo-bar' }).create(); }, 'Do not specify `content` on a Controller, use `model` instead.'); }); QUnit.test('specifying `content` (with `model` specified) does not result in deprecation', function () { expect(3); expectNoDeprecation(); var controller = _controller.default.extend({ content: 'foo-bar', model: 'blammo' }).create(); equal((0, _emberMetal.get)(controller, 'content'), 'foo-bar'); equal((0, _emberMetal.get)(controller, 'model'), 'blammo'); }); QUnit.module('Controller injected properties'); if (!EmberDev.runningProdBuild) { QUnit.test('defining a controller on a non-controller should fail assertion', function () { expectAssertion(function () { var owner = (0, _internalTestHelpers.buildOwner)(); var AnObject = _object.default.extend({ foo: _inject.default.controller('bar') }); owner.register('foo:main', AnObject); expectDeprecation(function () { owner._lookupFactory('foo:main'); }, /Using "_lookupFactory" is deprecated. Please use container.factoryFor instead./); }, /Defining an injected controller property on a non-controller is not allowed./); }); } QUnit.test('controllers can be injected into controllers', function () { var owner = (0, _internalTestHelpers.buildOwner)(); owner.register('controller:post', _controller.default.extend({ postsController: _inject.default.controller('posts') })); owner.register('controller:posts', _controller.default.extend()); var postController = owner.lookup('controller:post'); var postsController = owner.lookup('controller:posts'); equal(postsController, postController.get('postsController'), 'controller.posts is injected'); }); QUnit.test('services can be injected into controllers', function () { var owner = (0, _internalTestHelpers.buildOwner)(); owner.register('controller:application', _controller.default.extend({ authService: _inject.default.service('auth') })); owner.register('service:auth', _service.default.extend()); var appController = owner.lookup('controller:application'); var authService = owner.lookup('service:auth'); equal(authService, appController.get('authService'), 'service.auth is injected'); }); }); enifed('ember-runtime/tests/core/compare_test', ['ember-runtime/utils', 'ember-runtime/system/object', 'ember-runtime/compare', 'ember-runtime/mixins/comparable'], function (_utils, _object, _compare, _comparable) { 'use strict'; var data = []; var Comp = _object.default.extend(_comparable.default); Comp.reopenClass({ compare: function (obj) { return obj.get('val'); } }); QUnit.module('Ember.compare()', { setup: function () { data[0] = null; data[1] = false; data[2] = true; data[3] = -12; data[4] = 3.5; data[5] = 'a string'; data[6] = 'another string'; data[7] = 'last string'; data[8] = [1, 2]; data[9] = [1, 2, 3]; data[10] = [1, 3]; data[11] = { a: 'hash' }; data[12] = _object.default.create(); data[13] = function (a) { return a; }; data[14] = new Date('2012/01/01'); data[15] = new Date('2012/06/06'); } }); QUnit.test('ordering should work', function () { var suspect = void 0, comparable = void 0, failureMessage = void 0, suspectIndex = void 0, comparableIndex = void 0; for (suspectIndex = 0; suspectIndex < data.length; suspectIndex++) { suspect = data[suspectIndex]; equal((0, _compare.default)(suspect, suspect), 0, suspectIndex + ' should equal itself'); for (comparableIndex = suspectIndex + 1; comparableIndex < data.length; comparableIndex++) { comparable = data[comparableIndex]; failureMessage = 'data[' + suspectIndex + '] (' + (0, _utils.typeOf)(suspect) + ') should be smaller than data[' + comparableIndex + '] (' + (0, _utils.typeOf)(comparable) + ')'; equal((0, _compare.default)(suspect, comparable), -1, failureMessage); } } }); QUnit.test('comparables should return values in the range of -1, 0, 1', function () { var negOne = Comp.create({ val: -1 }); var zero = Comp.create({ val: 0 }); var one = Comp.create({ val: 1 }); equal((0, _compare.default)(negOne, 'a'), -1, 'First item comparable - returns -1 (not negated)'); equal((0, _compare.default)(zero, 'b'), 0, 'First item comparable - returns 0 (not negated)'); equal((0, _compare.default)(one, 'c'), 1, 'First item comparable - returns 1 (not negated)'); equal((0, _compare.default)('a', negOne), 1, 'Second item comparable - returns -1 (negated)'); equal((0, _compare.default)('b', zero), 0, 'Second item comparable - returns 0 (negated)'); equal((0, _compare.default)('c', one), -1, 'Second item comparable - returns 1 (negated)'); }); }); enifed('ember-runtime/tests/core/copy_test', ['ember-runtime/copy'], function (_copy) { 'use strict'; QUnit.module('Ember Copy Method'); QUnit.test('Ember.copy null', function () { equal((0, _copy.default)({ field: null }, true).field, null, 'null should still be null'); }); QUnit.test('Ember.copy date', function () { var date = new Date(2014, 7, 22); var dateCopy = (0, _copy.default)(date); equal(date.getTime(), dateCopy.getTime(), 'dates should be equivalent'); }); QUnit.test('Ember.copy null prototype object', function () { var obj = Object.create(null); obj.foo = 'bar'; equal((0, _copy.default)(obj).foo, 'bar', 'bar should still be bar'); }); QUnit.test('Ember.copy Array', function () { var array = [1, null, new Date(2015, 9, 9), 'four']; var arrayCopy = (0, _copy.default)(array); deepEqual(array, arrayCopy, 'array content cloned successfully in new array'); }); }); enifed('ember-runtime/tests/core/isEqual_test', ['ember-runtime/is-equal'], function (_isEqual) { 'use strict'; QUnit.module('isEqual'); QUnit.test('undefined and null', function () { ok((0, _isEqual.default)(undefined, undefined), 'undefined is equal to undefined'); ok(!(0, _isEqual.default)(undefined, null), 'undefined is not equal to null'); ok((0, _isEqual.default)(null, null), 'null is equal to null'); ok(!(0, _isEqual.default)(null, undefined), 'null is not equal to undefined'); }); QUnit.test('strings should be equal', function () { ok(!(0, _isEqual.default)('Hello', 'Hi'), 'different Strings are unequal'); ok((0, _isEqual.default)('Hello', 'Hello'), 'same Strings are equal'); }); QUnit.test('numericals should be equal', function () { ok((0, _isEqual.default)(24, 24), 'same numbers are equal'); ok(!(0, _isEqual.default)(24, 21), 'different numbers are inequal'); }); QUnit.test('dates should be equal', function () { ok((0, _isEqual.default)(new Date(1985, 7, 22), new Date(1985, 7, 22)), 'same dates are equal'); ok(!(0, _isEqual.default)(new Date(2014, 7, 22), new Date(1985, 7, 22)), 'different dates are not equal'); }); QUnit.test('array should be equal', function () { // NOTE: We don't test for array contents -- that would be too expensive. ok(!(0, _isEqual.default)([1, 2], [1, 2]), 'two array instances with the same values should not be equal'); ok(!(0, _isEqual.default)([1, 2], [1]), 'two array instances with different values should not be equal'); }); QUnit.test('first object implements isEqual should use it', function () { ok((0, _isEqual.default)({ isEqual: function () { return true; } }, null), 'should return true always'); var obj = { isEqual: function () { return false; } }; equal((0, _isEqual.default)(obj, obj), false, 'should return false because isEqual returns false'); }); }); enifed('ember-runtime/tests/core/is_array_test', ['ember-runtime/utils', 'ember-runtime/system/native_array', 'ember-runtime/system/array_proxy', 'ember-environment'], function (_utils, _native_array, _array_proxy, _emberEnvironment) { 'use strict'; QUnit.module('Ember Type Checking'); var global = undefined; QUnit.test('Ember.isArray', function () { var arrayProxy = _array_proxy.default.create({ content: (0, _native_array.A)() }); equal((0, _utils.isArray)([1, 2, 3]), true, '[1,2,3]'); equal((0, _utils.isArray)(23), false, '23'); equal((0, _utils.isArray)(['Hello', 'Hi']), true, '["Hello", "Hi"]'); equal((0, _utils.isArray)('Hello'), false, '"Hello"'); equal((0, _utils.isArray)({}), false, '{}'); equal((0, _utils.isArray)({ length: 12 }), true, '{ length: 12 }'); equal((0, _utils.isArray)({ length: 'yes' }), false, '{ length: "yes" }'); equal((0, _utils.isArray)(global), false, 'global'); equal((0, _utils.isArray)(function () {}), false, 'function() {}'); equal((0, _utils.isArray)(arrayProxy), true, '[]'); }); if (_emberEnvironment.environment.window && typeof _emberEnvironment.environment.window.FileList === 'function') { QUnit.test('Ember.isArray(fileList)', function () { var fileListElement = document.createElement('input'); fileListElement.type = 'file'; var fileList = fileListElement.files; equal((0, _utils.isArray)(fileList), false, 'fileList'); }); } }); enifed('ember-runtime/tests/core/is_empty_test', ['ember-metal', 'ember-runtime/system/array_proxy', 'ember-runtime/system/native_array'], function (_emberMetal, _array_proxy, _native_array) { 'use strict'; QUnit.module('Ember.isEmpty'); QUnit.test('Ember.isEmpty', function () { var arrayProxy = _array_proxy.default.create({ content: (0, _native_array.A)() }); equal(true, (0, _emberMetal.isEmpty)(arrayProxy), 'for an ArrayProxy that has empty content'); }); }); enifed('ember-runtime/tests/core/type_of_test', ['ember-runtime/utils', 'ember-runtime/system/object', 'ember-environment'], function (_utils, _object, _emberEnvironment) { 'use strict'; QUnit.module('Ember Type Checking'); QUnit.test('Ember.typeOf', function () { var MockedDate = function () {}; MockedDate.prototype = new Date(); var mockedDate = new MockedDate(); var date = new Date(); var error = new Error('boum'); var instance = _object.default.create({ method: function () {} }); equal((0, _utils.typeOf)(), 'undefined', 'undefined'); equal((0, _utils.typeOf)(null), 'null', 'null'); equal((0, _utils.typeOf)('Cyril'), 'string', 'Cyril'); equal((0, _utils.typeOf)(101), 'number', '101'); equal((0, _utils.typeOf)(true), 'boolean', 'true'); equal((0, _utils.typeOf)([1, 2, 90]), 'array', '[1,2,90]'); equal((0, _utils.typeOf)(/abc/), 'regexp', '/abc/'); equal((0, _utils.typeOf)(date), 'date', 'new Date()'); equal((0, _utils.typeOf)(mockedDate), 'date', 'mocked date'); equal((0, _utils.typeOf)(error), 'error', 'error'); equal((0, _utils.typeOf)({ a: 'b' }), 'object', 'object'); equal((0, _utils.typeOf)(undefined), 'undefined', 'item of type undefined'); equal((0, _utils.typeOf)(null), 'null', 'item of type null'); equal((0, _utils.typeOf)([1, 2, 3]), 'array', 'item of type array'); equal((0, _utils.typeOf)({}), 'object', 'item of type object'); equal((0, _utils.typeOf)(instance), 'instance', 'item of type instance'); equal((0, _utils.typeOf)(instance.method), 'function', 'item of type function'); equal((0, _utils.typeOf)(_object.default.extend()), 'class', 'item of type class'); equal((0, _utils.typeOf)(new Error()), 'error', 'item of type error'); }); if (_emberEnvironment.environment.window && typeof _emberEnvironment.environment.window.FileList === 'function') { QUnit.test('Ember.typeOf(fileList)', function () { var fileListElement = document.createElement('input'); fileListElement.type = 'file'; var fileList = fileListElement.files; equal((0, _utils.typeOf)(fileList), 'filelist', 'item of type filelist'); }); } }); enifed('ember-runtime/tests/ext/function_test', ['ember-environment', 'ember-metal', 'internal-test-helpers', 'ember-runtime/system/object', 'ember-runtime/mixins/evented'], function (_emberEnvironment, _emberMetal, _internalTestHelpers, _object, _evented) { 'use strict'; QUnit.module('Function.prototype.observes() helper'); (0, _internalTestHelpers.testBoth)('global observer helper takes multiple params', function (get, set) { if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) { ok('undefined' === typeof Function.prototype.observes, 'Function.prototype helper disabled'); return; } var MyMixin = _emberMetal.Mixin.create({ count: 0, foo: function () { set(this, 'count', get(this, 'count') + 1); }.observes('bar', 'baz') }); var obj = (0, _emberMetal.mixin)({}, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); set(obj, 'baz', 'BAZ'); equal(get(obj, 'count'), 2, 'should invoke observer after change'); }); QUnit.module('Function.prototype.on() helper'); (0, _internalTestHelpers.testBoth)('sets up an event listener, and can trigger the function on multiple events', function (get, set) { if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) { ok('undefined' === typeof Function.prototype.on, 'Function.prototype helper disabled'); return; } var MyMixin = _emberMetal.Mixin.create({ count: 0, foo: function () { set(this, 'count', get(this, 'count') + 1); }.on('bar', 'baz') }); var obj = (0, _emberMetal.mixin)({}, _evented.default, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke listener immediately'); obj.trigger('bar'); obj.trigger('baz'); equal(get(obj, 'count'), 2, 'should invoke listeners when events trigger'); }); (0, _internalTestHelpers.testBoth)('can be chained with observes', function (get, set) { if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) { ok('Function.prototype helper disabled'); return; } var MyMixin = _emberMetal.Mixin.create({ count: 0, bay: 'bay', foo: function () { set(this, 'count', get(this, 'count') + 1); }.observes('bay').on('bar') }); var obj = (0, _emberMetal.mixin)({}, _evented.default, MyMixin); equal(get(obj, 'count'), 0, 'should not invoke listener immediately'); set(obj, 'bay', 'BAY'); obj.trigger('bar'); equal(get(obj, 'count'), 2, 'should invoke observer and listener'); }); QUnit.module('Function.prototype.property() helper'); (0, _internalTestHelpers.testBoth)('sets up a ComputedProperty', function (get, set) { if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) { ok('undefined' === typeof Function.prototype.property, 'Function.prototype helper disabled'); return; } var MyClass = _object.default.extend({ firstName: null, lastName: null, fullName: function () { return get(this, 'firstName') + ' ' + get(this, 'lastName'); }.property('firstName', 'lastName') }); var obj = MyClass.create({ firstName: 'Fred', lastName: 'Flinstone' }); equal(get(obj, 'fullName'), 'Fred Flinstone', 'should return the computed value'); set(obj, 'firstName', 'Wilma'); equal(get(obj, 'fullName'), 'Wilma Flinstone', 'should return the new computed value'); set(obj, 'lastName', ''); equal(get(obj, 'fullName'), 'Wilma ', 'should return the new computed value'); }); }); enifed('ember-runtime/tests/ext/mixin_test', ['ember-metal'], function (_emberMetal) { 'use strict'; QUnit.module('system/mixin/binding_test'); QUnit.test('Defining a property ending in Binding should setup binding when applied', function () { var MyMixin = _emberMetal.Mixin.create({ fooBinding: 'bar.baz' }); var obj = { bar: { baz: 'BIFF' } }; (0, _emberMetal.run)(function () { var deprecationMessage = /`Ember.Binding` is deprecated/; expectDeprecation(function () { MyMixin.apply(obj); }, deprecationMessage); }); ok((0, _emberMetal.get)(obj, 'fooBinding') instanceof _emberMetal.Binding, 'should be a binding object'); equal((0, _emberMetal.get)(obj, 'foo'), 'BIFF', 'binding should be created and synced'); }); QUnit.test('Defining a property ending in Binding should apply to prototype children', function () { var MyMixin = (0, _emberMetal.run)(function () { return _emberMetal.Mixin.create({ fooBinding: 'bar.baz' }); }); var obj = { bar: { baz: 'BIFF' } }; (0, _emberMetal.run)(function () { var deprecationMessage = /`Ember.Binding` is deprecated/; expectDeprecation(function () { MyMixin.apply(obj); }, deprecationMessage); }); var obj2 = Object.create(obj); (0, _emberMetal.run)(function () { return (0, _emberMetal.set)((0, _emberMetal.get)(obj2, 'bar'), 'baz', 'BARG'); }); ok((0, _emberMetal.get)(obj2, 'fooBinding') instanceof _emberMetal.Binding, 'should be a binding object'); equal((0, _emberMetal.get)(obj2, 'foo'), 'BARG', 'binding should be created and synced'); }); }); enifed('ember-runtime/tests/ext/rsvp_test', ['ember-metal', 'ember-runtime/ext/rsvp', 'ember-debug'], function (_emberMetal, _rsvp, _emberDebug) { 'use strict'; var ORIGINAL_ONERROR = (0, _emberMetal.getOnerror)(); QUnit.module('Ember.RSVP', { teardown: function () { (0, _emberMetal.setOnerror)(ORIGINAL_ONERROR); } }); QUnit.test('Ensure that errors thrown from within a promise are sent to the console', function () { var error = new Error('Error thrown in a promise for testing purposes.'); try { (0, _emberMetal.run)(function () { new _rsvp.default.Promise(function () { throw error; }); }); ok(false, 'expected assertion to be thrown'); } catch (e) { equal(e, error, 'error was re-thrown'); } }); QUnit.test('TransitionAborted errors are not re-thrown', function () { expect(1); (0, _emberMetal.run)(_rsvp.default, 'reject', { name: 'TransitionAborted' }); ok(true, 'did not throw an error when dealing with TransitionAborted'); }); QUnit.test('Can reject with non-Error object', function () { var wasEmberTesting = (0, _emberDebug.isTesting)(); (0, _emberDebug.setTesting)(false); expect(1); try { (0, _emberMetal.run)(_rsvp.default, 'reject', 'foo'); } catch (e) { ok(false, 'should not throw'); } finally { (0, _emberDebug.setTesting)(wasEmberTesting); } ok(true); }); QUnit.test('Can reject with no arguments', function () { var wasEmberTesting = (0, _emberDebug.isTesting)(); (0, _emberDebug.setTesting)(false); expect(1); try { (0, _emberMetal.run)(_rsvp.default, 'reject'); } catch (e) { ok(false, 'should not throw'); } finally { (0, _emberDebug.setTesting)(wasEmberTesting); } ok(true); }); QUnit.test('rejections like jqXHR which have errorThrown property work', function () { expect(2); var wasEmberTesting = (0, _emberDebug.isTesting)(), actualError, jqXHR; var wasOnError = (0, _emberMetal.getOnerror)(); try { (0, _emberDebug.setTesting)(false); (0, _emberMetal.setOnerror)(function (error) { equal(error, actualError, 'expected the real error on the jqXHR'); equal(error.__reason_with_error_thrown__, jqXHR, 'also retains a helpful reference to the rejection reason'); }); actualError = new Error('OMG what really happened'); jqXHR = { errorThrown: actualError }; (0, _emberMetal.run)(_rsvp.default, 'reject', jqXHR); } finally { (0, _emberMetal.setOnerror)(wasOnError); (0, _emberDebug.setTesting)(wasEmberTesting); } }); QUnit.test('rejections where the errorThrown is a string should wrap the sting in an error object', function () { expect(2); var wasEmberTesting = (0, _emberDebug.isTesting)(), actualError, jqXHR; var wasOnError = (0, _emberMetal.getOnerror)(); try { (0, _emberDebug.setTesting)(false); (0, _emberMetal.setOnerror)(function (error) { equal(error.message, actualError, 'expected the real error on the jqXHR'); equal(error.__reason_with_error_thrown__, jqXHR, 'also retains a helpful reference to the rejection reason'); }); actualError = 'OMG what really happened'; jqXHR = { errorThrown: actualError }; (0, _emberMetal.run)(_rsvp.default, 'reject', jqXHR); } finally { (0, _emberMetal.setOnerror)(wasOnError); (0, _emberDebug.setTesting)(wasEmberTesting); } }); QUnit.test('rejections can be serialized to JSON', function (assert) { expect(2); var wasEmberTesting = (0, _emberDebug.isTesting)(), jqXHR; var wasOnError = (0, _emberMetal.getOnerror)(); try { (0, _emberDebug.setTesting)(false); (0, _emberMetal.setOnerror)(function (error) { assert.equal(error.message, 'a fail'); assert.ok(JSON.stringify(error), 'Error can be serialized'); }); jqXHR = { errorThrown: new Error('a fail') }; (0, _emberMetal.run)(_rsvp.default, 'reject', jqXHR); } finally { (0, _emberMetal.setOnerror)(wasOnError); (0, _emberDebug.setTesting)(wasEmberTesting); } }); var reason = 'i failed'; QUnit.module('Ember.test: rejection assertions'); function ajax() { return _rsvp.default.Promise(function (resolve) { QUnit.stop(); setTimeout(function () { QUnit.start(); resolve(); }, 0); // fake true / foreign async }); } QUnit.test('unambigiously unhandled rejection', function () { QUnit.throws(function () { (0, _emberMetal.run)(function () { _rsvp.default.Promise.reject(reason); }); // something is funky, we should likely assert }, reason); }); QUnit.test('sync handled', function () { (0, _emberMetal.run)(function () { _rsvp.default.Promise.reject(reason).catch(function () {}); }); // handled, we shouldn't need to assert. ok(true, 'reached end of test'); }); QUnit.test('handled within the same micro-task (via Ember.RVP.Promise)', function () { (0, _emberMetal.run)(function () { var rejection = _rsvp.default.Promise.reject(reason); _rsvp.default.Promise.resolve(1).then(function () { return rejection.catch(function () {}); }); }); // handled, we shouldn't need to assert. ok(true, 'reached end of test'); }); QUnit.test('handled within the same micro-task (via direct run-loop)', function () { (0, _emberMetal.run)(function () { var rejection = _rsvp.default.Promise.reject(reason); _emberMetal.run.schedule('afterRender', function () { return rejection.catch(function () {}); }); }); // handled, we shouldn't need to assert. ok(true, 'reached end of test'); }); QUnit.test('handled in the next microTask queue flush (run.next)', function () { expect(2); QUnit.throws(function () { (0, _emberMetal.run)(function () { var rejection = _rsvp.default.Promise.reject(reason); QUnit.stop(); _emberMetal.run.next(function () { QUnit.start(); rejection.catch(function () {}); ok(true, 'reached end of test'); }); }); }, reason); // a promise rejection survived a full flush of the run-loop without being handled // this is very likely an issue. }); QUnit.test('handled in the same microTask Queue flush do to data locality', function () { // an ambiguous scenario, this may or may not assert // it depends on the locality of `user#1` var store = { find: function () { return _rsvp.default.Promise.resolve(1); } }; (0, _emberMetal.run)(function () { var rejection = _rsvp.default.Promise.reject(reason); store.find('user', 1).then(function () { return rejection.catch(function () {}); }); }); ok(true, 'reached end of test'); }); QUnit.test('handled in a different microTask Queue flush do to data locality', function () { // an ambiguous scenario, this may or may not assert // it depends on the locality of `user#1` var store = { find: function () { return ajax(); } }; QUnit.throws(function () { (0, _emberMetal.run)(function () { var rejection = _rsvp.default.Promise.reject(reason); store.find('user', 1).then(function () { rejection.catch(function () {}); ok(true, 'reached end of test'); }); }); }, reason); }); QUnit.test('handled in the next microTask queue flush (ajax example)', function () { QUnit.throws(function () { (0, _emberMetal.run)(function () { var rejection = _rsvp.default.Promise.reject(reason); ajax('/something/').then(function () { rejection.catch(function () {}); ok(true, 'reached end of test'); }); }); }, reason); }); }); enifed('ember-runtime/tests/inject_test', ['ember-metal', 'ember-runtime/inject', 'ember-runtime/system/object', 'internal-test-helpers'], function (_emberMetal, _inject, _object, _internalTestHelpers) { 'use strict'; QUnit.module('inject'); /* global EmberDev */ QUnit.test('calling `inject` directly should error', function () { expectAssertion(function () { (0, _inject.default)('foo'); }, /Injected properties must be created through helpers/); }); if (!EmberDev.runningProdBuild) { // this check is done via an assertion which is stripped from // production builds QUnit.test('injection type validation is run when first looked up', function () { (0, _inject.createInjectionHelper)('foo', function () { ok(true, 'should call validation method'); }); var owner = (0, _internalTestHelpers.buildOwner)(); var AnObject = _object.default.extend({ bar: _inject.default.foo(), baz: _inject.default.foo() }); owner.register('foo:main', AnObject); expect(2); expectDeprecation(function () { owner._lookupFactory('foo:main'); }, /Using "_lookupFactory" is deprecated. Please use container.factoryFor instead./); }); QUnit.test('attempting to inject a nonexistent container key should error', function () { var owner = (0, _internalTestHelpers.buildOwner)(); var AnObject = _object.default.extend({ foo: new _emberMetal.InjectedProperty('bar', 'baz') }); owner.register('foo:main', AnObject); throws(function () { owner.lookup('foo:main'); }, /Attempting to inject an unknown injection: 'bar:baz'/); }); } QUnit.test('factories should return a list of lazy injection full names', function () { var AnObject = _object.default.extend({ foo: new _emberMetal.InjectedProperty('foo', 'bar'), bar: new _emberMetal.InjectedProperty('quux') }); deepEqual(AnObject._lazyInjections(), { 'foo': 'foo:bar', 'bar': 'quux:bar' }, 'should return injected container keys'); }); }); enifed('ember-runtime/tests/legacy_1x/mixins/observable/chained_test', ['ember-metal', 'ember-runtime/system/object', 'ember-runtime/system/native_array'], function (_emberMetal, _object, _native_array) { 'use strict'; /* NOTE: This test is adapted from the 1.x series of unit tests. The tests are the same except for places where we intend to break the API we instead validate that we warn the developer appropriately. CHANGES FROM 1.6: * changed obj.set() and obj.get() to Ember.set() and Ember.get() * changed obj.addObserver() to addObserver() */ QUnit.module('Ember.Observable - Observing with @each'); QUnit.test('chained observers on enumerable properties are triggered when the observed property of any item changes', function () { var family = _object.default.create({ momma: null }); var momma = _object.default.create({ children: [] }); var child1 = _object.default.create({ name: 'Bartholomew' }); var child2 = _object.default.create({ name: 'Agnes' }); var child3 = _object.default.create({ name: 'Dan' }); var child4 = _object.default.create({ name: 'Nancy' }); (0, _emberMetal.set)(family, 'momma', momma); (0, _emberMetal.set)(momma, 'children', (0, _native_array.A)([child1, child2, child3])); var observerFiredCount = 0; (0, _emberMetal.addObserver)(family, 'momma.children.@each.name', this, function () { observerFiredCount++; }); observerFiredCount = 0; (0, _emberMetal.run)(function () { return (0, _emberMetal.get)(momma, 'children').setEach('name', 'Juan'); }); equal(observerFiredCount, 3, 'observer fired after changing child names'); observerFiredCount = 0; (0, _emberMetal.run)(function () { return (0, _emberMetal.get)(momma, 'children').pushObject(child4); }); equal(observerFiredCount, 1, 'observer fired after adding a new item'); observerFiredCount = 0; (0, _emberMetal.run)(function () { return (0, _emberMetal.set)(child4, 'name', 'Herbert'); }); equal(observerFiredCount, 1, 'observer fired after changing property on new object'); (0, _emberMetal.set)(momma, 'children', []); observerFiredCount = 0; (0, _emberMetal.run)(function () { return (0, _emberMetal.set)(child1, 'name', 'Hanna'); }); equal(observerFiredCount, 0, 'observer did not fire after removing changing property on a removed object'); }); }); enifed('ember-runtime/tests/legacy_1x/mixins/observable/observable_test', ['ember-environment', 'ember-metal', 'ember-runtime/system/string', 'ember-runtime/system/object', 'ember-runtime/mixins/observable', 'ember-runtime/system/native_array'], function (_emberEnvironment, _emberMetal, _string, _object, _observable, _native_array) { 'use strict'; /* NOTE: This test is adapted from the 1.x series of unit tests. The tests are the same except for places where we intend to break the API we instead validate that we warn the developer appropriately. CHANGES FROM 1.6: * Added ObservableObject which applies the Ember.Observable mixin. * Changed reference to Ember.T_FUNCTION to 'function' * Changed all references to sc_super to this._super(...arguments) * Changed Ember.objectForPropertyPath() to Ember.getPath() * Removed allPropertiesDidChange test - no longer supported * Changed test that uses 'ObjectE' as path to 'objectE' to reflect new rule on using capital letters for property paths. * Removed test passing context to addObserver. context param is no longer supported. * Changed calls to Ember.Binding.flushPendingChanges() -> run.sync() * removed test in observer around line 862 that expected key/value to be the last item in the chained path. Should be root and chained path */ // ======================================================================== // Ember.Observable Tests // ======================================================================== var object, ObjectC, ObjectD, objectA, objectB, lookup; var ObservableObject = _object.default.extend(_observable.default); var originalLookup = _emberEnvironment.context.lookup; // .......................................................... // GET() // QUnit.module('object.get()', { setup: function () { object = ObservableObject.extend(_observable.default, { computed: (0, _emberMetal.computed)(function () { return 'value'; }).volatile(), method: function () { return 'value'; }, unknownProperty: function (key) { this.lastUnknownProperty = key; return 'unknown'; } }).create({ normal: 'value', numberVal: 24, toggleVal: true, nullProperty: null }); } }); QUnit.test('should get normal properties', function () { equal(object.get('normal'), 'value'); }); QUnit.test('should call computed properties and return their result', function () { equal(object.get('computed'), 'value'); }); QUnit.test('should return the function for a non-computed property', function () { var value = object.get('method'); equal(typeof value, 'function'); }); QUnit.test('should return null when property value is null', function () { equal(object.get('nullProperty'), null); }); QUnit.test('should call unknownProperty when value is undefined', function () { equal(object.get('unknown'), 'unknown'); equal(object.lastUnknownProperty, 'unknown'); }); // .......................................................... // Ember.GET() // QUnit.module('Ember.get()', { setup: function () { objectA = ObservableObject.extend({ computed: (0, _emberMetal.computed)(function () { return 'value'; }).volatile(), method: function () { return 'value'; }, unknownProperty: function (key) { this.lastUnknownProperty = key; return 'unknown'; } }).create({ normal: 'value', numberVal: 24, toggleVal: true, nullProperty: null }); objectB = { normal: 'value', nullProperty: null }; } }); QUnit.test('should get normal properties on Ember.Observable', function () { equal((0, _emberMetal.get)(objectA, 'normal'), 'value'); }); QUnit.test('should call computed properties on Ember.Observable and return their result', function () { equal((0, _emberMetal.get)(objectA, 'computed'), 'value'); }); QUnit.test('should return the function for a non-computed property on Ember.Observable', function () { var value = (0, _emberMetal.get)(objectA, 'method'); equal(typeof value, 'function'); }); QUnit.test('should return null when property value is null on Ember.Observable', function () { equal((0, _emberMetal.get)(objectA, 'nullProperty'), null); }); QUnit.test('should call unknownProperty when value is undefined on Ember.Observable', function () { equal((0, _emberMetal.get)(objectA, 'unknown'), 'unknown'); equal(objectA.lastUnknownProperty, 'unknown'); }); QUnit.test('should get normal properties on standard objects', function () { equal((0, _emberMetal.get)(objectB, 'normal'), 'value'); }); QUnit.test('should return null when property is null on standard objects', function () { equal((0, _emberMetal.get)(objectB, 'nullProperty'), null); }); /* QUnit.test("raise if the provided object is null", function() { throws(function() { get(null, 'key'); }); }); */ QUnit.test('raise if the provided object is undefined', function () { expectAssertion(function () { (0, _emberMetal.get)(undefined, 'key'); }, /Cannot call get with 'key' on an undefined object/i); }); QUnit.module('Ember.get() with paths'); QUnit.test('should return a property at a given path relative to the passed object', function () { var foo = ObservableObject.create({ bar: ObservableObject.extend({ baz: (0, _emberMetal.computed)(function () { return 'blargh'; }).volatile() }).create() }); equal((0, _emberMetal.get)(foo, 'bar.baz'), 'blargh'); }); QUnit.test('should return a property at a given path relative to the passed object - JavaScript hash', function () { equal((0, _emberMetal.get)({ bar: { baz: 'blargh' } }, 'bar.baz'), 'blargh'); }); // .......................................................... // SET() // QUnit.module('object.set()', { setup: function () { object = ObservableObject.extend({ computed: (0, _emberMetal.computed)({ get: function () { return this._computed; }, set: function (key, value) { this._computed = value; return this._computed; } }).volatile(), method: function (key, value) { if (value !== undefined) { this._method = value; } return this._method; }, unknownProperty: function () { return this._unknown; }, setUnknownProperty: function (key, value) { this._unknown = value; return this._unknown; }, // normal property normal: 'value', // computed property _computed: 'computed', // method, but not a property _method: 'method', // null property nullProperty: null, // unknown property _unknown: 'unknown' }).create(); } }); QUnit.test('should change normal properties and return the value', function () { var ret = object.set('normal', 'changed'); equal(object.get('normal'), 'changed'); equal(ret, 'changed'); }); QUnit.test('should call computed properties passing value and return the value', function () { var ret = object.set('computed', 'changed'); equal(object.get('_computed'), 'changed'); equal(ret, 'changed'); }); QUnit.test('should change normal properties when passing undefined', function () { var ret = object.set('normal', undefined); equal(object.get('normal'), undefined); equal(ret, undefined); }); QUnit.test('should replace the function for a non-computed property and return the value', function () { var ret = object.set('method', 'changed'); equal(object.get('_method'), 'method'); // make sure this was NOT run ok(typeof object.get('method') !== 'function'); equal(ret, 'changed'); }); QUnit.test('should replace prover when property value is null', function () { var ret = object.set('nullProperty', 'changed'); equal(object.get('nullProperty'), 'changed'); equal(ret, 'changed'); }); QUnit.test('should call unknownProperty with value when property is undefined', function () { var ret = object.set('unknown', 'changed'); equal(object.get('_unknown'), 'changed'); equal(ret, 'changed'); }); // .......................................................... // COMPUTED PROPERTIES // QUnit.module('Computed properties', { setup: function () { lookup = _emberEnvironment.context.lookup = {}; object = ObservableObject.extend({ computed: (0, _emberMetal.computed)({ get: function () { this.computedCalls.push('getter-called'); return 'computed'; }, set: function (key, value) { this.computedCalls.push(value); } }).volatile(), computedCached: (0, _emberMetal.computed)({ get: function () { this.computedCachedCalls.push('getter-called'); return 'computedCached'; }, set: function (key, value) { this.computedCachedCalls.push(value); } }), dependent: (0, _emberMetal.computed)({ get: function () { this.dependentCalls.push('getter-called'); return 'dependent'; }, set: function (key, value) { this.dependentCalls.push(value); } }).property('changer').volatile(), dependentFront: (0, _emberMetal.computed)('changer', { get: function () { this.dependentFrontCalls.push('getter-called'); return 'dependentFront'; }, set: function (key, value) { this.dependentFrontCalls.push(value); } }).volatile(), dependentCached: (0, _emberMetal.computed)({ get: function () { this.dependentCachedCalls.push('getter-called!'); return 'dependentCached'; }, set: function (key, value) { this.dependentCachedCalls.push(value); } }).property('changer'), inc: (0, _emberMetal.computed)('changer', function () { return this.incCallCount++; }), nestedInc: (0, _emberMetal.computed)(function () { (0, _emberMetal.get)(this, 'inc'); return this.nestedIncCallCount++; }).property('inc'), isOn: (0, _emberMetal.computed)({ get: function () { return this.get('state') === 'on'; }, set: function () { this.set('state', 'on'); return this.get('state') === 'on'; } }).property('state').volatile(), isOff: (0, _emberMetal.computed)({ get: function () { return this.get('state') === 'off'; }, set: function () { this.set('state', 'off'); return this.get('state') === 'off'; } }).property('state').volatile() }).create({ computedCalls: [], computedCachedCalls: [], changer: 'foo', dependentCalls: [], dependentFrontCalls: [], dependentCachedCalls: [], incCallCount: 0, nestedIncCallCount: 0, state: 'on' }); }, teardown: function () { _emberEnvironment.context.lookup = originalLookup; } }); QUnit.test('getting values should call function return value', function () { // get each property twice. Verify return. var keys = (0, _string.w)('computed computedCached dependent dependentFront dependentCached'); keys.forEach(function (key) { equal(object.get(key), key, 'Try #1: object.get(' + key + ') should run function'); equal(object.get(key), key, 'Try #2: object.get(' + key + ') should run function'); }); // verify each call count. cached should only be called once (0, _string.w)('computedCalls dependentFrontCalls dependentCalls').forEach(function (key) { equal(object[key].length, 2, 'non-cached property ' + key + ' should be called 2x'); }); (0, _string.w)('computedCachedCalls dependentCachedCalls').forEach(function (key) { equal(object[key].length, 1, 'non-cached property ' + key + ' should be called 1x'); }); }); QUnit.test('setting values should call function return value', function () { // get each property twice. Verify return. var keys = (0, _string.w)('computed dependent dependentFront computedCached dependentCached'); var values = (0, _string.w)('value1 value2'); keys.forEach(function (key) { equal(object.set(key, values[0]), values[0], 'Try #1: object.set(' + key + ', ' + values[0] + ') should run function'); equal(object.set(key, values[1]), values[1], 'Try #2: object.set(' + key + ', ' + values[1] + ') should run function'); equal(object.set(key, values[1]), values[1], 'Try #3: object.set(' + key + ', ' + values[1] + ') should not run function since it is setting same value as before'); }); // verify each call count. cached should only be called once keys.forEach(function (key) { var calls = object[key + 'Calls']; var idx, expectedLength; // Cached properties first check their cached value before setting the // property. Other properties blindly call set. expectedLength = 3; equal(calls.length, expectedLength, 'set(' + key + ') should be called the right amount of times'); for (idx = 0; idx < 2; idx++) { equal(calls[idx], values[idx], 'call #' + (idx + 1) + ' to set(' + key + ') should have passed value ' + values[idx]); } }); }); QUnit.test('notify change should clear cache', function () { // call get several times to collect call count object.get('computedCached'); // should run func object.get('computedCached'); // should not run func object.propertyWillChange('computedCached').propertyDidChange('computedCached'); object.get('computedCached'); // should run again equal(object.computedCachedCalls.length, 2, 'should have invoked method 2x'); }); QUnit.test('change dependent should clear cache', function () { // call get several times to collect call count var ret1 = object.get('inc'); // should run func equal(object.get('inc'), ret1, 'multiple calls should not run cached prop'); object.set('changer', 'bar'); equal(object.get('inc'), ret1 + 1, 'should increment after dependent key changes'); // should run again }); QUnit.test('just notifying change of dependent should clear cache', function () { // call get several times to collect call count var ret1 = object.get('inc'); // should run func equal(object.get('inc'), ret1, 'multiple calls should not run cached prop'); object.notifyPropertyChange('changer'); equal(object.get('inc'), ret1 + 1, 'should increment after dependent key changes'); // should run again }); QUnit.test('changing dependent should clear nested cache', function () { // call get several times to collect call count var ret1 = object.get('nestedInc'); // should run func equal(object.get('nestedInc'), ret1, 'multiple calls should not run cached prop'); object.set('changer', 'bar'); equal(object.get('nestedInc'), ret1 + 1, 'should increment after dependent key changes'); // should run again }); QUnit.test('just notifying change of dependent should clear nested cache', function () { // call get several times to collect call count var ret1 = object.get('nestedInc'); // should run func equal(object.get('nestedInc'), ret1, 'multiple calls should not run cached prop'); object.notifyPropertyChange('changer'); equal(object.get('nestedInc'), ret1 + 1, 'should increment after dependent key changes'); // should run again }); // This verifies a specific bug encountered where observers for computed // properties would fire before their prop caches were cleared. QUnit.test('change dependent should clear cache when observers of dependent are called', function () { // call get several times to collect call count var ret1 = object.get('inc'); // should run func equal(object.get('inc'), ret1, 'multiple calls should not run cached prop'); // add observer to verify change... object.addObserver('inc', this, function () { equal(object.get('inc'), ret1 + 1, 'should increment after dependent key changes'); // should run again }); // now run object.set('changer', 'bar'); }); QUnit.test('setting one of two computed properties that depend on a third property should clear the kvo cache', function () { // we have to call set twice to fill up the cache object.set('isOff', true); object.set('isOn', true); // setting isOff to true should clear the kvo cache object.set('isOff', true); equal(object.get('isOff'), true, 'object.isOff should be true'); equal(object.get('isOn'), false, 'object.isOn should be false'); }); QUnit.test('dependent keys should be able to be specified as property paths', function () { var depObj = ObservableObject.extend({ menuPrice: (0, _emberMetal.computed)(function () { return this.get('menu.price'); }).property('menu.price') }).create({ menu: ObservableObject.create({ price: 5 }) }); equal(depObj.get('menuPrice'), 5, 'precond - initial value returns 5'); depObj.set('menu.price', 6); equal(depObj.get('menuPrice'), 6, 'cache is properly invalidated after nested property changes'); }); QUnit.test('nested dependent keys should propagate after they update', function () { var bindObj; (0, _emberMetal.run)(function () { lookup.DepObj = ObservableObject.extend({ price: (0, _emberMetal.computed)(function () { return this.get('restaurant.menu.price'); }).property('restaurant.menu.price') }).create({ restaurant: ObservableObject.create({ menu: ObservableObject.create({ price: 5 }) }) }); expectDeprecation(function () { bindObj = ObservableObject.extend({ priceBinding: 'DepObj.price' }).create(); }, /`Ember.Binding` is deprecated/); }); equal(bindObj.get('price'), 5, 'precond - binding propagates'); (0, _emberMetal.run)(function () { lookup.DepObj.set('restaurant.menu.price', 10); }); equal(bindObj.get('price'), 10, 'binding propagates after a nested dependent keys updates'); (0, _emberMetal.run)(function () { lookup.DepObj.set('restaurant.menu', ObservableObject.create({ price: 15 })); }); equal(bindObj.get('price'), 15, 'binding propagates after a middle dependent keys updates'); }); QUnit.test('cacheable nested dependent keys should clear after their dependencies update', function () { ok(true); var DepObj; (0, _emberMetal.run)(function () { lookup.DepObj = DepObj = ObservableObject.extend({ price: (0, _emberMetal.computed)('restaurant.menu.price', function () { return this.get('restaurant.menu.price'); }) }).create({ restaurant: ObservableObject.create({ menu: ObservableObject.create({ price: 5 }) }) }); }); equal(DepObj.get('price'), 5, 'precond - computed property is correct'); (0, _emberMetal.run)(function () { DepObj.set('restaurant.menu.price', 10); }); equal(DepObj.get('price'), 10, 'cacheable computed properties are invalidated even if no run loop occurred'); (0, _emberMetal.run)(function () { DepObj.set('restaurant.menu.price', 20); }); equal(DepObj.get('price'), 20, 'cacheable computed properties are invalidated after a second get before a run loop'); equal(DepObj.get('price'), 20, 'precond - computed properties remain correct after a run loop'); (0, _emberMetal.run)(function () { DepObj.set('restaurant.menu', ObservableObject.create({ price: 15 })); }); equal(DepObj.get('price'), 15, 'cacheable computed properties are invalidated after a middle property changes'); (0, _emberMetal.run)(function () { DepObj.set('restaurant.menu', ObservableObject.create({ price: 25 })); }); equal(DepObj.get('price'), 25, 'cacheable computed properties are invalidated after a middle property changes again, before a run loop'); }); // .......................................................... // OBSERVABLE OBJECTS // QUnit.module('Observable objects & object properties ', { setup: function () { object = ObservableObject.extend({ getEach: function () { var keys = ['normal', 'abnormal'], idx; var ret = []; for (idx = 0; idx < keys.length; idx++) { ret[ret.length] = this.get(keys[idx]); } return ret; }, newObserver: function () { this.abnormal = 'changedValueObserved'; }, testObserver: (0, _emberMetal.observer)('normal', function () { this.abnormal = 'removedObserver'; }), testArrayObserver: (0, _emberMetal.observer)('normalArray.[]', function () { this.abnormal = 'notifiedObserver'; }) }).create({ normal: 'value', abnormal: 'zeroValue', numberVal: 24, toggleVal: true, observedProperty: 'beingWatched', testRemove: 'observerToBeRemoved', normalArray: (0, _native_array.A)([1, 2, 3, 4, 5]) }); } }); QUnit.test('incrementProperty and decrementProperty', function () { var newValue = object.incrementProperty('numberVal'); equal(25, newValue, 'numerical value incremented'); object.numberVal = 24; newValue = object.decrementProperty('numberVal'); equal(23, newValue, 'numerical value decremented'); object.numberVal = 25; newValue = object.incrementProperty('numberVal', 5); equal(30, newValue, 'numerical value incremented by specified increment'); object.numberVal = 25; newValue = object.incrementProperty('numberVal', -5); equal(20, newValue, 'minus numerical value incremented by specified increment'); object.numberVal = 25; newValue = object.incrementProperty('numberVal', 0); equal(25, newValue, 'zero numerical value incremented by specified increment'); expectAssertion(function () { newValue = object.incrementProperty('numberVal', 0 - void 0); // Increment by NaN }, /Must pass a numeric value to incrementProperty/i); expectAssertion(function () { newValue = object.incrementProperty('numberVal', 'Ember'); // Increment by non-numeric String }, /Must pass a numeric value to incrementProperty/i); expectAssertion(function () { newValue = object.incrementProperty('numberVal', 1 / 0); // Increment by Infinity }, /Must pass a numeric value to incrementProperty/i); equal(25, newValue, 'Attempting to increment by non-numeric values should not increment value'); object.numberVal = 25; newValue = object.decrementProperty('numberVal', 5); equal(20, newValue, 'numerical value decremented by specified increment'); object.numberVal = 25; newValue = object.decrementProperty('numberVal', -5); equal(30, newValue, 'minus numerical value decremented by specified increment'); object.numberVal = 25; newValue = object.decrementProperty('numberVal', 0); equal(25, newValue, 'zero numerical value decremented by specified increment'); expectAssertion(function () { newValue = object.decrementProperty('numberVal', 0 - void 0); // Decrement by NaN }, /Must pass a numeric value to decrementProperty/i); expectAssertion(function () { newValue = object.decrementProperty('numberVal', 'Ember'); // Decrement by non-numeric String }, /Must pass a numeric value to decrementProperty/i); expectAssertion(function () { newValue = object.decrementProperty('numberVal', 1 / 0); // Decrement by Infinity }, /Must pass a numeric value to decrementProperty/i); equal(25, newValue, 'Attempting to decrement by non-numeric values should not decrement value'); }); QUnit.test('toggle function, should be boolean', function () { equal(object.toggleProperty('toggleVal', true, false), object.get('toggleVal')); equal(object.toggleProperty('toggleVal', true, false), object.get('toggleVal')); equal(object.toggleProperty('toggleVal', undefined, undefined), object.get('toggleVal')); }); QUnit.test('should notify array observer when array changes', function () { (0, _emberMetal.get)(object, 'normalArray').replace(0, 0, 6); equal(object.abnormal, 'notifiedObserver', 'observer should be notified'); }); QUnit.module('object.addObserver()', { setup: function () { ObjectC = ObservableObject.create({ objectE: ObservableObject.create({ propertyVal: 'chainedProperty' }), normal: 'value', normal1: 'zeroValue', normal2: 'dependentValue', incrementor: 10, action: function () { this.normal1 = 'newZeroValue'; }, observeOnceAction: function () { this.incrementor = this.incrementor + 1; }, chainedObserver: function () { this.normal2 = 'chainedPropertyObserved'; } }); } }); QUnit.test('should register an observer for a property', function () { ObjectC.addObserver('normal', ObjectC, 'action'); ObjectC.set('normal', 'newValue'); equal(ObjectC.normal1, 'newZeroValue'); }); QUnit.test('should register an observer for a property - Special case of chained property', function () { ObjectC.addObserver('objectE.propertyVal', ObjectC, 'chainedObserver'); ObjectC.objectE.set('propertyVal', 'chainedPropertyValue'); equal('chainedPropertyObserved', ObjectC.normal2); ObjectC.normal2 = 'dependentValue'; ObjectC.set('objectE', ''); equal('chainedPropertyObserved', ObjectC.normal2); }); QUnit.module('object.removeObserver()', { setup: function () { ObjectD = ObservableObject.create({ objectF: ObservableObject.create({ propertyVal: 'chainedProperty' }), normal: 'value', normal1: 'zeroValue', normal2: 'dependentValue', ArrayKeys: ['normal', 'normal1'], addAction: function () { this.normal1 = 'newZeroValue'; }, removeAction: function () { this.normal2 = 'newDependentValue'; }, removeChainedObserver: function () { this.normal2 = 'chainedPropertyObserved'; }, observableValue: 'hello world', observer1: function () { // Just an observer }, observer2: function () { this.removeObserver('observableValue', null, 'observer1'); this.removeObserver('observableValue', null, 'observer2'); this.hasObserverFor('observableValue'); // Tickle 'getMembers()' this.removeObserver('observableValue', null, 'observer3'); }, observer3: function () { // Just an observer } }); } }); QUnit.test('should unregister an observer for a property', function () { ObjectD.addObserver('normal', ObjectD, 'addAction'); ObjectD.set('normal', 'newValue'); equal(ObjectD.normal1, 'newZeroValue'); ObjectD.set('normal1', 'zeroValue'); ObjectD.removeObserver('normal', ObjectD, 'addAction'); ObjectD.set('normal', 'newValue'); equal(ObjectD.normal1, 'zeroValue'); }); QUnit.test('should unregister an observer for a property - special case when key has a \'.\' in it.', function () { ObjectD.addObserver('objectF.propertyVal', ObjectD, 'removeChainedObserver'); ObjectD.objectF.set('propertyVal', 'chainedPropertyValue'); ObjectD.removeObserver('objectF.propertyVal', ObjectD, 'removeChainedObserver'); ObjectD.normal2 = 'dependentValue'; ObjectD.objectF.set('propertyVal', 'removedPropertyValue'); equal('dependentValue', ObjectD.normal2); ObjectD.set('objectF', ''); equal('dependentValue', ObjectD.normal2); }); QUnit.test('removing an observer inside of an observer shouldn’t cause any problems', function () { // The observable system should be protected against clients removing // observers in the middle of observer notification. var encounteredError = false; try { ObjectD.addObserver('observableValue', null, 'observer1'); ObjectD.addObserver('observableValue', null, 'observer2'); ObjectD.addObserver('observableValue', null, 'observer3'); (0, _emberMetal.run)(function () { ObjectD.set('observableValue', 'hi world'); }); } catch (e) { encounteredError = true; } equal(encounteredError, false); }); QUnit.module('Bind function', { setup: function () { objectA = ObservableObject.create({ name: 'Sproutcore', location: 'Timbaktu' }); objectB = ObservableObject.create({ normal: 'value', computed: function () { this.normal = 'newValue'; } }); lookup = _emberEnvironment.context.lookup = { 'Namespace': { objectA: objectA, objectB: objectB } }; }, teardown: function () { _emberEnvironment.context.lookup = originalLookup; } }); QUnit.test('should bind property with method parameter as undefined', function () { // creating binding (0, _emberMetal.run)(function () { expectDeprecation(function () { objectA.bind('name', 'Namespace.objectB.normal', undefined); }, /`Ember.Binding` is deprecated/); }); // now make a change to see if the binding triggers. (0, _emberMetal.run)(function () { objectB.set('normal', 'changedValue'); }); // support new-style bindings if available equal('changedValue', objectA.get('name'), 'objectA.name is bound'); }); // .......................................................... // SPECIAL CASES // QUnit.test('changing chained observer object to null should not raise exception', function () { var obj = ObservableObject.create({ foo: ObservableObject.create({ bar: ObservableObject.create({ bat: 'BAT' }) }) }); var callCount = 0; obj.foo.addObserver('bar.bat', obj, function () { callCount++; }); (0, _emberMetal.run)(function () { obj.foo.set('bar', null); }); equal(callCount, 1, 'changing bar should trigger observer'); expect(1); }); }); enifed('ember-runtime/tests/legacy_1x/mixins/observable/observersForKey_test', ['ember-metal', 'ember-runtime/system/object', 'ember-runtime/mixins/observable'], function (_emberMetal, _object, _observable) { 'use strict'; var ObservableObject = _object.default.extend(_observable.default); // .......................................................... // GET() // /* NOTE: This test is adapted from the 1.x series of unit tests. The tests are the same except for places where we intend to break the API we instead validate that we warn the developer appropriately. CHANGES FROM 1.6: * Create ObservableObject which includes Ember.Observable */ // ======================================================================== // Ember.Observable Tests // ======================================================================== QUnit.module('object.observesForKey()'); QUnit.test('should get observers', function () { var o1 = ObservableObject.create({ foo: 100 }); var o2 = ObservableObject.create({ func: function () {} }); var o3 = ObservableObject.create({ func: function () {} }); var observers = null; equal((0, _emberMetal.get)(o1.observersForKey('foo'), 'length'), 0, 'o1.observersForKey should return empty array'); o1.addObserver('foo', o2, o2.func); o1.addObserver('foo', o3, o3.func); observers = o1.observersForKey('foo'); equal((0, _emberMetal.get)(observers, 'length'), 2, 'o2.observersForKey should return an array with length 2'); equal(observers[0][0], o2, 'first item in observers array should be o2'); equal(observers[1][0], o3, 'second item in observers array should be o3'); }); }); enifed('ember-runtime/tests/legacy_1x/mixins/observable/propertyChanges_test', ['ember-runtime/system/object', 'ember-runtime/mixins/observable', 'ember-metal'], function (_object, _observable, _emberMetal) { 'use strict'; var ObservableObject = _object.default.extend(_observable.default); /* NOTE: This test is adapted from the 1.x series of unit tests. The tests are the same except for places where we intend to break the API we instead validate that we warn the developer appropriately. CHANGES FROM 1.6: * Create ObservableObject which includes Ember.Observable * Remove test that tests internal _kvo_changeLevel property. This is an implementation detail. * Remove test for allPropertiesDidChange * Removed star observer test. no longer supported * Removed property revision test. no longer supported */ // ======================================================================== // Ember.Observable Tests // ======================================================================== var ObjectA = void 0; QUnit.module('object.propertyChanges', { setup: function () { ObjectA = ObservableObject.extend({ action: (0, _emberMetal.observer)('foo', function () { this.set('prop', 'changedPropValue'); }), notifyAction: (0, _emberMetal.observer)('newFoo', function () { this.set('newProp', 'changedNewPropValue'); }), notifyAllAction: (0, _emberMetal.observer)('prop', function () { this.set('newFoo', 'changedNewFooValue'); }), starObserver: function (target, key) { this.starProp = key; } }).create({ starProp: null, foo: 'fooValue', prop: 'propValue', newFoo: 'newFooValue', newProp: 'newPropValue' }); } }); QUnit.test('should observe the changes within the nested begin / end property changes', function () { //start the outer nest ObjectA.beginPropertyChanges(); // Inner nest ObjectA.beginPropertyChanges(); ObjectA.set('foo', 'changeFooValue'); equal(ObjectA.prop, 'propValue'); ObjectA.endPropertyChanges(); //end inner nest ObjectA.set('prop', 'changePropValue'); equal(ObjectA.newFoo, 'newFooValue'); //close the outer nest ObjectA.endPropertyChanges(); equal(ObjectA.prop, 'changedPropValue'); equal(ObjectA.newFoo, 'changedNewFooValue'); }); QUnit.test('should observe the changes within the begin and end property changes', function () { ObjectA.beginPropertyChanges(); ObjectA.set('foo', 'changeFooValue'); equal(ObjectA.prop, 'propValue'); ObjectA.endPropertyChanges(); equal(ObjectA.prop, 'changedPropValue'); }); QUnit.test('should indicate that the property of an object has just changed', function () { // indicate that property of foo will change to its subscribers ObjectA.propertyWillChange('foo'); //Value of the prop is unchanged yet as this will be changed when foo changes equal(ObjectA.prop, 'propValue'); //change the value of foo. ObjectA.set('foo', 'changeFooValue'); // Indicate the subscribers of foo that the value has just changed ObjectA.propertyDidChange('foo', null); // Values of prop has just changed equal(ObjectA.prop, 'changedPropValue'); }); QUnit.test('should notify that the property of an object has changed', function () { // Notify to its subscriber that the values of 'newFoo' will be changed. In this // case the observer is "newProp". Therefore this will call the notifyAction function // and value of "newProp" will be changed. ObjectA.notifyPropertyChange('newFoo', 'fooValue'); //value of newProp changed. equal(ObjectA.newProp, 'changedNewPropValue'); }); QUnit.test('should invalidate function property cache when notifyPropertyChange is called', function () { var a = ObservableObject.extend({ b: (0, _emberMetal.computed)({ get: function () { return this._b; }, set: function (key, value) { this._b = value; return this; } }).volatile() }).create({ _b: null }); a.set('b', 'foo'); equal(a.get('b'), 'foo', 'should have set the correct value for property b'); a._b = 'bar'; a.notifyPropertyChange('b'); a.set('b', 'foo'); equal(a.get('b'), 'foo', 'should have invalidated the cache so that the newly set value is actually set'); }); }); enifed('ember-runtime/tests/legacy_1x/system/binding_test', ['ember-environment', 'ember-metal', 'ember-runtime/system/object'], function (_emberEnvironment, _emberMetal, _object) { 'use strict'; /* NOTE: This test is adapted from the 1.x series of unit tests. The tests are the same except for places where we intend to break the API we instead validate that we warn the developer appropriately. CHANGES FROM 1.6: * All calls to run.sync() were changed to run.sync() * Bindings no longer accept a root object as their second param. Instead our test binding objects were put under a single object they could originate from. * tests that inspected internal properties were removed. * converted foo.get/foo.set to use get/Ember.set * Removed tests for Binding.isConnected. Since binding instances are now shared this property no longer makes sense. * Changed call calls for obj.bind(...) to bind(obj, ...); * Changed all calls to sc_super() to this._super(...arguments) * Changed all calls to disconnect() to pass the root object. * removed calls to Binding.destroy() as that method is no longer useful (or defined) * changed use of T_STRING to 'string' */ // ======================================================================== // Binding Tests // ======================================================================== var TestNamespace = void 0, fromObject = void 0, toObject = void 0, binding = void 0, Bon1 = void 0, bon2 = void 0, root = void 0; // global variables var originalLookup = _emberEnvironment.context.lookup; var lookup = void 0; QUnit.module('basic object binding', { setup: function () { fromObject = _object.default.create({ value: 'start' }); toObject = _object.default.create({ value: 'end' }); root = { fromObject: fromObject, toObject: toObject }; (0, _emberMetal.run)(function () { expectDeprecation(function () { binding = (0, _emberMetal.bind)(root, 'toObject.value', 'fromObject.value'); }, /`Ember\.Binding` is deprecated./); }); } }); QUnit.test('binding should have synced on connect', function () { equal((0, _emberMetal.get)(toObject, 'value'), 'start', 'toObject.value should match fromObject.value'); }); QUnit.test('fromObject change should propagate to toObject only after flush', function () { (0, _emberMetal.run)(function () { (0, _emberMetal.set)(fromObject, 'value', 'change'); equal((0, _emberMetal.get)(toObject, 'value'), 'start'); }); equal((0, _emberMetal.get)(toObject, 'value'), 'change'); }); QUnit.test('toObject change should propagate to fromObject only after flush', function () { (0, _emberMetal.run)(function () { (0, _emberMetal.set)(toObject, 'value', 'change'); equal((0, _emberMetal.get)(fromObject, 'value'), 'start'); }); equal((0, _emberMetal.get)(fromObject, 'value'), 'change'); }); QUnit.test('deferred observing during bindings', function () { // setup special binding fromObject = _object.default.create({ value1: 'value1', value2: 'value2' }); toObject = _object.default.extend({ observer: (0, _emberMetal.observer)('value1', 'value2', function () { equal((0, _emberMetal.get)(this, 'value1'), 'CHANGED', 'value1 when observer fires'); equal((0, _emberMetal.get)(this, 'value2'), 'CHANGED', 'value2 when observer fires'); this.callCount++; }) }).create({ value1: 'value1', value2: 'value2', callCount: 0 }); var root = { fromObject: fromObject, toObject: toObject }; (0, _emberMetal.run)(function () { expectDeprecation(function () { (0, _emberMetal.bind)(root, 'toObject.value1', 'fromObject.value1'); }, /`Ember\.Binding` is deprecated./); expectDeprecation(function () { (0, _emberMetal.bind)(root, 'toObject.value2', 'fromObject.value2'); }, /`Ember\.Binding` is deprecated./); // change both value1 + value2, then flush bindings. observer should only // fire after bindings are done flushing. (0, _emberMetal.set)(fromObject, 'value1', 'CHANGED'); (0, _emberMetal.set)(fromObject, 'value2', 'CHANGED'); }); equal(toObject.callCount, 2, 'should call observer twice'); }); QUnit.test('binding disconnection actually works', function () { binding.disconnect(root); (0, _emberMetal.run)(function () { (0, _emberMetal.set)(fromObject, 'value', 'change'); }); equal((0, _emberMetal.get)(toObject, 'value'), 'start'); }); var first = void 0, second = void 0, third = void 0; // global variables // .......................................................... // chained binding // QUnit.module('chained binding', { setup: function () { (0, _emberMetal.run)(function () { first = _object.default.create({ output: 'first' }); second = _object.default.extend({ inputDidChange: (0, _emberMetal.observer)('input', function () { (0, _emberMetal.set)(this, 'output', (0, _emberMetal.get)(this, 'input')); }) }).create({ input: 'second', output: 'second' }); third = _object.default.create({ input: 'third' }); root = { first: first, second: second, third: third }; expectDeprecation(function () { (0, _emberMetal.bind)(root, 'second.input', 'first.output'); }, /`Ember\.Binding` is deprecated./); expectDeprecation(function () { (0, _emberMetal.bind)(root, 'second.output', 'third.input'); }, /`Ember\.Binding` is deprecated./); }); }, teardown: function () { _emberMetal.run.cancelTimers(); } }); QUnit.test('changing first output should propagate to third after flush', function () { (0, _emberMetal.run)(function () { (0, _emberMetal.set)(first, 'output', 'change'); equal('change', (0, _emberMetal.get)(first, 'output'), 'first.output'); ok('change' !== (0, _emberMetal.get)(third, 'input'), 'third.input'); }); equal('change', (0, _emberMetal.get)(first, 'output'), 'first.output'); equal('change', (0, _emberMetal.get)(second, 'input'), 'second.input'); equal('change', (0, _emberMetal.get)(second, 'output'), 'second.output'); equal('change', (0, _emberMetal.get)(third, 'input'), 'third.input'); }); // .......................................................... // Custom Binding // QUnit.module('Custom Binding', { setup: function () { _emberEnvironment.context.lookup = lookup = {}; Bon1 = _object.default.extend({ value1: 'hi', value2: 83, array1: [] }); bon2 = _object.default.create({ val1: 'hello', val2: 25, arr: [1, 2, 3, 4] }); _emberEnvironment.context.lookup['TestNamespace'] = TestNamespace = { bon2: bon2, Bon1: Bon1 }; }, teardown: function () { _emberEnvironment.context.lookup = originalLookup; Bon1 = bon2 = TestNamespace = null; _emberMetal.run.cancelTimers(); } }); QUnit.test('two bindings to the same value should sync in the order they are initialized', function () { _emberMetal.run.begin(); var a = _object.default.create({ foo: 'bar' }); var b = _object.default.extend({ C: _object.default.extend({ foo: 'bee', fooBinding: 'owner.foo' }), init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'c', this.C.create({ owner: this })); } }); expectDeprecation(function () { b = b.create({ foo: 'baz', fooBinding: 'a.foo', a: a }); }, /`Ember\.Binding` is deprecated./); _emberMetal.run.end(); equal((0, _emberMetal.get)(a, 'foo'), 'bar', 'a.foo should not change'); equal((0, _emberMetal.get)(b, 'foo'), 'bar', 'a.foo should propagate up to b.foo'); equal((0, _emberMetal.get)(b.c, 'foo'), 'bar', 'a.foo should propagate up to b.c.foo'); }); // .......................................................... // propertyNameBinding with longhand // QUnit.module('propertyNameBinding with longhand', { setup: function () { _emberEnvironment.context.lookup = lookup = {}; lookup['TestNamespace'] = TestNamespace = {}; (0, _emberMetal.run)(function () { TestNamespace.fromObject = _object.default.create({ value: 'originalValue' }); expectDeprecation(function () { TestNamespace.toObject = _object.default.extend({ valueBinding: _emberMetal.Binding.from('TestNamespace.fromObject.value'), relativeBinding: _emberMetal.Binding.from('localValue') }).create({ localValue: 'originalLocal' }); }, /`Ember\.Binding` is deprecated./); }); }, teardown: function () { TestNamespace = undefined; _emberEnvironment.context.lookup = originalLookup; } }); QUnit.test('works with full path', function () { (0, _emberMetal.run)(function () { return (0, _emberMetal.set)(TestNamespace.fromObject, 'value', 'updatedValue'); }); equal((0, _emberMetal.get)(TestNamespace.toObject, 'value'), 'updatedValue'); (0, _emberMetal.run)(function () { return (0, _emberMetal.set)(TestNamespace.fromObject, 'value', 'newerValue'); }); equal((0, _emberMetal.get)(TestNamespace.toObject, 'value'), 'newerValue'); }); QUnit.test('works with local path', function () { (0, _emberMetal.run)(function () { return (0, _emberMetal.set)(TestNamespace.toObject, 'localValue', 'updatedValue'); }); equal((0, _emberMetal.get)(TestNamespace.toObject, 'relative'), 'updatedValue'); (0, _emberMetal.run)(function () { return (0, _emberMetal.set)(TestNamespace.toObject, 'localValue', 'newerValue'); }); equal((0, _emberMetal.get)(TestNamespace.toObject, 'relative'), 'newerValue'); }); }); enifed('ember-runtime/tests/legacy_1x/system/object/base_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) { 'use strict'; /* NOTE: This test is adapted from the 1.x series of unit tests. The tests are the same except for places where we intend to break the API we instead validate that we warn the developer appropriately. CHANGES FROM 1.6: * Changed get(obj, ) and set(obj, ) to Ember.get() and Ember.set() * Removed obj.instanceOf() and obj.kindOf() tests. use obj instanceof Foo instead * Removed respondsTo() and tryToPerform() tests. Can be brought back in a utils package. * Removed destroy() test. You can impl yourself but not built in * Changed Class.subclassOf() test to Class.detect() * Remove broken test for 'superclass' property. * Removed obj.didChangeFor() */ // ======================================================================== // EmberObject Base Tests // ======================================================================== var obj = void 0, obj1 = void 0; // global variables QUnit.module('A new EmberObject instance', { setup: function () { obj = _object.default.create({ foo: 'bar', total: 12345, aMethodThatExists: function () {}, aMethodThatReturnsTrue: function () { return true; }, aMethodThatReturnsFoobar: function () { return 'Foobar'; }, aMethodThatReturnsFalse: function () { return false; } }); }, teardown: function () { obj = undefined; } }); QUnit.test('Should return its properties when requested using EmberObject#get', function () { equal((0, _emberMetal.get)(obj, 'foo'), 'bar'); equal((0, _emberMetal.get)(obj, 'total'), 12345); }); QUnit.test('Should allow changing of those properties by calling EmberObject#set', function () { equal((0, _emberMetal.get)(obj, 'foo'), 'bar'); equal((0, _emberMetal.get)(obj, 'total'), 12345); (0, _emberMetal.set)(obj, 'foo', 'Chunky Bacon'); (0, _emberMetal.set)(obj, 'total', 12); equal((0, _emberMetal.get)(obj, 'foo'), 'Chunky Bacon'); equal((0, _emberMetal.get)(obj, 'total'), 12); }); QUnit.module('EmberObject superclass and subclasses', { setup: function () { obj = _object.default.extend({ method1: function () { return 'hello'; } }); obj1 = obj.extend(); }, teardown: function () { obj = undefined; obj1 = undefined; } }); QUnit.test('Checking the detect() function on an object and its subclass', function () { equal(obj.detect(obj1), true); equal(obj1.detect(obj), false); }); QUnit.test('Checking the detectInstance() function on an object and its subclass', function () { ok(_object.default.detectInstance(obj.create())); ok(obj.detectInstance(obj.create())); }); }); enifed('ember-runtime/tests/legacy_1x/system/object/bindings_test', ['ember-environment', 'ember-metal', 'ember-runtime/system/object'], function (_emberEnvironment, _emberMetal, _object) { 'use strict'; /* NOTE: This test is adapted from the 1.x series of unit tests. The tests are the same except for places where we intend to break the API we instead validate that we warn the developer appropriately. CHANGES FROM 1.6: * changed Ember.Bending.flushPendingChanges() -> run.sync(); * changes obj.set() and obj.get() to Ember.set() and Ember.get() * Fixed an actual bug in unit tests around line 133 * fixed 'bindings should disconnect on destroy' test to use destroy. */ // ======================================================================== // EmberObject bindings Tests // ======================================================================== var originalLookup = _emberEnvironment.context.lookup; var testObject = void 0, fromObject = void 0, TestObject = void 0; var TestNamespace = void 0, lookup = void 0; QUnit.module('bind() method', { setup: function () { _emberEnvironment.context.lookup = lookup = {}; testObject = _object.default.create({ foo: 'bar', bar: 'foo', extraObject: null }); fromObject = _object.default.create({ bar: 'foo', extraObject: null }); lookup['TestNamespace'] = TestNamespace = { fromObject: fromObject, testObject: testObject }; }, teardown: function () { testObject = fromObject = null; _emberEnvironment.context.lookup = originalLookup; } }); QUnit.test('bind(TestNamespace.fromObject.bar) should follow absolute path', function () { (0, _emberMetal.run)(function () { expectDeprecation(function () { // create binding testObject.bind('foo', 'TestNamespace.fromObject.bar'); }, /`Ember.Binding` is deprecated/); // now make a change to see if the binding triggers. (0, _emberMetal.set)(fromObject, 'bar', 'changedValue'); }); equal('changedValue', (0, _emberMetal.get)(testObject, 'foo'), 'testObject.foo'); }); QUnit.test('bind(.bar) should bind to relative path', function () { (0, _emberMetal.run)(function () { expectDeprecation(function () { // create binding testObject.bind('foo', 'bar'); }, /`Ember.Binding` is deprecated/); // now make a change to see if the binding triggers. (0, _emberMetal.set)(testObject, 'bar', 'changedValue'); }); equal('changedValue', (0, _emberMetal.get)(testObject, 'foo'), 'testObject.foo'); }); QUnit.module('fooBinding method', { setup: function () { _emberEnvironment.context.lookup = lookup = {}; TestObject = _object.default.extend({ foo: 'bar', bar: 'foo', extraObject: null }); fromObject = _object.default.create({ bar: 'foo', extraObject: null }); lookup['TestNamespace'] = TestNamespace = { fromObject: fromObject, testObject: TestObject }; }, teardown: function () { _emberEnvironment.context.lookup = originalLookup; TestObject = fromObject = null; // delete TestNamespace; } }); var deprecationMessage = /`Ember.Binding` is deprecated/; QUnit.test('fooBinding: TestNamespace.fromObject.bar should follow absolute path', function () { (0, _emberMetal.run)(function () { expectDeprecation(function () { // create binding testObject = TestObject.extend({ fooBinding: 'TestNamespace.fromObject.bar' }).create(); }, deprecationMessage); // now make a change to see if the binding triggers. (0, _emberMetal.set)(fromObject, 'bar', 'changedValue'); }); equal('changedValue', (0, _emberMetal.get)(testObject, 'foo'), 'testObject.foo'); }); QUnit.test('fooBinding: .bar should bind to relative path', function () { (0, _emberMetal.run)(function () { expectDeprecation(function () { // create binding testObject = TestObject.extend({ fooBinding: 'bar' }).create(); }, deprecationMessage); // now make a change to see if the binding triggers. (0, _emberMetal.set)(testObject, 'bar', 'changedValue'); }); equal('changedValue', (0, _emberMetal.get)(testObject, 'foo'), 'testObject.foo'); }); QUnit.test('fooBinding: should disconnect bindings when destroyed', function () { (0, _emberMetal.run)(function () { expectDeprecation(function () { // create binding testObject = TestObject.extend({ fooBinding: 'TestNamespace.fromObject.bar' }).create(); }, deprecationMessage); (0, _emberMetal.set)(TestNamespace.fromObject, 'bar', 'BAZ'); }); equal((0, _emberMetal.get)(testObject, 'foo'), 'BAZ', 'binding should have synced'); (0, _emberMetal.run)(function () { return testObject.destroy(); }); (0, _emberMetal.run)(function () { return (0, _emberMetal.set)(TestNamespace.fromObject, 'bar', 'BIFF'); }); ok((0, _emberMetal.get)(testObject, 'foo') !== 'bar', 'binding should not have synced'); }); }); enifed('ember-runtime/tests/legacy_1x/system/object/concatenated_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) { 'use strict'; /* NOTE: This test is adapted from the 1.x series of unit tests. The tests are the same except for places where we intend to break the API we instead validate that we warn the developer appropriately. CHANGES FROM 1.6: * changed get(obj, ) and set(obj, ) to Ember.get() and Ember.set() * converted uses of obj.isEqual() to use deepEqual() test since isEqual is not always defined */ function K() { return this; } var klass = void 0; QUnit.module('EmberObject Concatenated Properties', { setup: function () { klass = _object.default.extend({ concatenatedProperties: ['values', 'functions'], values: ['a', 'b', 'c'], functions: [K] }); } }); QUnit.test('concatenates instances', function () { var obj = klass.create({ values: ['d', 'e', 'f'] }); var values = (0, _emberMetal.get)(obj, 'values'); var expected = ['a', 'b', 'c', 'd', 'e', 'f']; deepEqual(values, expected, 'should concatenate values property (expected: ' + expected + ', got: ' + values + ')'); }); QUnit.test('concatenates subclasses', function () { var subKlass = klass.extend({ values: ['d', 'e', 'f'] }); var obj = subKlass.create(); var values = (0, _emberMetal.get)(obj, 'values'); var expected = ['a', 'b', 'c', 'd', 'e', 'f']; deepEqual(values, expected, 'should concatenate values property (expected: ' + expected + ', got: ' + values + ')'); }); QUnit.test('concatenates reopen', function () { klass.reopen({ values: ['d', 'e', 'f'] }); var obj = klass.create(); var values = (0, _emberMetal.get)(obj, 'values'); var expected = ['a', 'b', 'c', 'd', 'e', 'f']; deepEqual(values, expected, 'should concatenate values property (expected: ' + expected + ', got: ' + values + ')'); }); QUnit.test('concatenates mixin', function () { var subKlass = klass.extend({ values: ['d', 'e'] }, { values: ['f'] }); var obj = subKlass.create(); var values = (0, _emberMetal.get)(obj, 'values'); var expected = ['a', 'b', 'c', 'd', 'e', 'f']; deepEqual(values, expected, 'should concatenate values property (expected: ' + expected + ', got: ' + values + ')'); }); QUnit.test('concatenates reopen, subclass, and instance', function () { klass.reopen({ values: ['d'] }); var subKlass = klass.extend({ values: ['e'] }); var obj = subKlass.create({ values: ['f'] }); var values = (0, _emberMetal.get)(obj, 'values'); var expected = ['a', 'b', 'c', 'd', 'e', 'f']; deepEqual(values, expected, 'should concatenate values property (expected: ' + expected + ', got: ' + values + ')'); }); QUnit.test('concatenates subclasses when the values are functions', function () { var subKlass = klass.extend({ functions: K }); var obj = subKlass.create(); var values = (0, _emberMetal.get)(obj, 'functions'); var expected = [K, K]; deepEqual(values, expected, 'should concatenate functions property (expected: ' + expected + ', got: ' + values + ')'); }); }); enifed('ember-runtime/tests/legacy_1x/system/run_loop_test', ['ember-metal', 'ember-runtime/mixins/observable', 'ember-runtime/system/object'], function (_emberMetal, _observable, _object) { 'use strict'; /* NOTE: This test is adapted from the 1.x series of unit tests. The tests are the same except for places where we intend to break the API we instead validate that we warn the developer appropriately. CHANGES FROM 1.6: * Updated the API usage for setting up and syncing Binding since these are not the APIs this file is testing. * Disabled a call to invokeOnce() around line 127 because it appeared to be broken anyway. I don't think it ever even worked. */ var MyApp = void 0; QUnit.module('System:run_loop() - chained binding', { setup: function () { MyApp = {}; MyApp.first = _object.default.extend(_observable.default).create({ output: 'MyApp.first' }); MyApp.second = _object.default.extend(_observable.default, { inputDidChange: (0, _emberMetal.observer)('input', function () { this.set('output', this.get('input')); }) }).create({ input: 'MyApp.second', output: 'MyApp.second' }); MyApp.third = _object.default.extend(_observable.default).create({ input: 'MyApp.third' }); } }); var deprecationMessage = /`Ember.Binding` is deprecated/; QUnit.test('Should propagate bindings after the RunLoop completes (using Ember.RunLoop)', function () { (0, _emberMetal.run)(function () { //Binding of output of MyApp.first object to input of MyApp.second object expectDeprecation(function () { _emberMetal.Binding.from('first.output').to('second.input').connect(MyApp); }, deprecationMessage); //Binding of output of MyApp.second object to input of MyApp.third object expectDeprecation(function () { _emberMetal.Binding.from('second.output').to('third.input').connect(MyApp); }, deprecationMessage); }); (0, _emberMetal.run)(function () { // Based on the above binding if you change the output of MyApp.first // object it should change the all the variable of // MyApp.first,MyApp.second and MyApp.third object MyApp.first.set('output', 'change'); //Changes the output of the MyApp.first object equal(MyApp.first.get('output'), 'change'); //since binding has not taken into effect the value still remains as change. equal(MyApp.second.get('output'), 'MyApp.first'); }); // allows bindings to trigger... //Value of the output variable changed to 'change' equal(MyApp.first.get('output'), 'change'); //Since binding triggered after the end loop the value changed to 'change'. equal(MyApp.second.get('output'), 'change'); }); QUnit.test('Should propagate bindings after the RunLoop completes', function () { (0, _emberMetal.run)(function () { //Binding of output of MyApp.first object to input of MyApp.second object expectDeprecation(function () { _emberMetal.Binding.from('first.output').to('second.input').connect(MyApp); }, deprecationMessage); //Binding of output of MyApp.second object to input of MyApp.third object expectDeprecation(function () { _emberMetal.Binding.from('second.output').to('third.input').connect(MyApp); }, deprecationMessage); }); (0, _emberMetal.run)(function () { //Based on the above binding if you change the output of MyApp.first object it should //change the all the variable of MyApp.first,MyApp.second and MyApp.third object MyApp.first.set('output', 'change'); //Changes the output of the MyApp.first object equal(MyApp.first.get('output'), 'change'); //since binding has not taken into effect the value still remains as change. equal(MyApp.second.get('output'), 'MyApp.first'); }); //Value of the output variable changed to 'change' equal(MyApp.first.get('output'), 'change'); //Since binding triggered after the end loop the value changed to 'change'. equal(MyApp.second.get('output'), 'change'); }); }); enifed('ember-runtime/tests/main_test', ['ember-runtime/index'], function (_index) { 'use strict'; QUnit.module('ember-runtime/main'); QUnit.test('Ember.computed.collect', function () { var MyObj = _index.Object.extend({ props: (0, _index.collect)('foo', 'bar', 'baz') }); var myObj = MyObj.create({ foo: 3, bar: 5, baz: 'asdf' }); var propsValue = myObj.get('props'); deepEqual(propsValue, [3, 5, 'asdf']); }); }); enifed('ember-runtime/tests/mixins/array_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/tests/suites/array', 'ember-runtime/system/object', 'ember-runtime/mixins/array', 'ember-runtime/system/native_array'], function (_emberMetal, _internalTestHelpers, _array, _object, _array2, _native_array) { 'use strict'; /* Implement a basic fake mutable array. This validates that any non-native enumerable can impl this API. */ var TestArray = _object.default.extend(_array2.default, { _content: null, init: function () { var ary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; this._content = ary; }, addObject: function (obj) { var idx = this._content.length; (0, _array2.arrayContentWillChange)(this, idx, 0, 1); this._content.push(obj); (0, _array2.arrayContentDidChange)(this, idx, 0, 1); }, removeFirst: function () { (0, _array2.arrayContentWillChange)(this, 0, 1, 0); this._content.shift(); (0, _array2.arrayContentDidChange)(this, 0, 1, 0); }, objectAt: function (idx) { return this._content[idx]; }, length: (0, _emberMetal.computed)(function () { return this._content.length; }) }); _array.ArrayTests.extend({ name: 'Basic Mutable Array', newObject: function (ary) { ary = ary ? ary.slice() : this.newFixture(3); return new TestArray(ary); }, mutate: function (obj) { obj.addObject(this.getFixture(1)[0]); }, toArray: function (obj) { return obj.slice(); } }).run(); QUnit.test('the return value of slice has Ember.Array applied', function () { var x = _object.default.extend(_array2.default).create({ length: 0 }); var y = x.slice(1); equal(_array2.default.detect(y), true, 'mixin should be applied'); }); QUnit.test('slice supports negative index arguments', function () { var testArray = new TestArray([1, 2, 3, 4]); deepEqual(testArray.slice(-2), [3, 4], 'slice(-2)'); deepEqual(testArray.slice(-2, -1), [3], 'slice(-2, -1'); deepEqual(testArray.slice(-2, -2), [], 'slice(-2, -2)'); deepEqual(testArray.slice(-1, -2), [], 'slice(-1, -2)'); deepEqual(testArray.slice(-4, 1), [1], 'slice(-4, 1)'); deepEqual(testArray.slice(-4, 5), [1, 2, 3, 4], 'slice(-4, 5)'); deepEqual(testArray.slice(-4), [1, 2, 3, 4], 'slice(-4)'); deepEqual(testArray.slice(0, -1), [1, 2, 3], 'slice(0, -1)'); deepEqual(testArray.slice(0, -4), [], 'slice(0, -4)'); deepEqual(testArray.slice(0, -3), [1], 'slice(0, -3)'); }); // .......................................................... // CONTENT DID CHANGE // var DummyArray = _object.default.extend(_array2.default, { nextObject: function () {}, length: 0, objectAt: function (idx) { return 'ITEM-' + idx; } }); var obj = void 0, observer = void 0; // .......................................................... // NOTIFY ARRAY OBSERVERS // QUnit.module('mixins/array/arrayContent[Will|Did]Change'); QUnit.test('should notify observers of []', function () { obj = DummyArray.extend({ enumerablePropertyDidChange: (0, _emberMetal.observer)('[]', function () { this._count++; }) }).create({ _count: 0 }); equal(obj._count, 0, 'should not have invoked yet'); (0, _array2.arrayContentWillChange)(obj, 0, 1, 1); (0, _array2.arrayContentDidChange)(obj, 0, 1, 1); equal(obj._count, 1, 'should have invoked'); }); // .......................................................... // NOTIFY CHANGES TO LENGTH // QUnit.module('notify observers of length', { setup: function () { obj = DummyArray.extend({ lengthDidChange: (0, _emberMetal.observer)('length', function () { this._after++; }) }).create({ _after: 0 }); equal(obj._after, 0, 'should not have fired yet'); }, teardown: function () { obj = null; } }); QUnit.test('should notify observers when call with no params', function () { (0, _array2.arrayContentWillChange)(obj); equal(obj._after, 0); (0, _array2.arrayContentDidChange)(obj); equal(obj._after, 1); }); // API variation that included items only QUnit.test('should not notify when passed lengths are same', function () { (0, _array2.arrayContentWillChange)(obj, 0, 1, 1); equal(obj._after, 0); (0, _array2.arrayContentDidChange)(obj, 0, 1, 1); equal(obj._after, 0); }); QUnit.test('should notify when passed lengths are different', function () { (0, _array2.arrayContentWillChange)(obj, 0, 1, 2); equal(obj._after, 0); (0, _array2.arrayContentDidChange)(obj, 0, 1, 2); equal(obj._after, 1); }); // .......................................................... // NOTIFY ARRAY OBSERVER // QUnit.module('notify array observers', { setup: function () { obj = DummyArray.create(); observer = _object.default.extend({ arrayWillChange: function () { equal(this._before, null); // should only call once this._before = Array.prototype.slice.call(arguments); }, arrayDidChange: function () { equal(this._after, null); // should only call once this._after = Array.prototype.slice.call(arguments); } }).create({ _before: null, _after: null }); (0, _array2.addArrayObserver)(obj, observer); }, teardown: function () { obj = observer = null; } }); QUnit.test('should notify enumerable observers when called with no params', function () { (0, _array2.arrayContentWillChange)(obj); deepEqual(observer._before, [obj, 0, -1, -1]); (0, _array2.arrayContentDidChange)(obj); deepEqual(observer._after, [obj, 0, -1, -1]); }); // API variation that included items only QUnit.test('should notify when called with same length items', function () { (0, _array2.arrayContentWillChange)(obj, 0, 1, 1); deepEqual(observer._before, [obj, 0, 1, 1]); (0, _array2.arrayContentDidChange)(obj, 0, 1, 1); deepEqual(observer._after, [obj, 0, 1, 1]); }); QUnit.test('should notify when called with diff length items', function () { (0, _array2.arrayContentWillChange)(obj, 0, 2, 1); deepEqual(observer._before, [obj, 0, 2, 1]); (0, _array2.arrayContentDidChange)(obj, 0, 2, 1); deepEqual(observer._after, [obj, 0, 2, 1]); }); QUnit.test('removing enumerable observer should disable', function () { (0, _array2.removeArrayObserver)(obj, observer); (0, _array2.arrayContentWillChange)(obj); deepEqual(observer._before, null); (0, _array2.arrayContentDidChange)(obj); deepEqual(observer._after, null); }); // .......................................................... // NOTIFY ENUMERABLE OBSERVER // QUnit.module('notify enumerable observers as well', { setup: function () { obj = DummyArray.create(); observer = _object.default.extend({ enumerableWillChange: function () { equal(this._before, null); // should only call once this._before = Array.prototype.slice.call(arguments); }, enumerableDidChange: function () { equal(this._after, null); // should only call once this._after = Array.prototype.slice.call(arguments); } }).create({ _before: null, _after: null }); obj.addEnumerableObserver(observer); }, teardown: function () { obj = observer = null; } }); QUnit.test('should notify enumerable observers when called with no params', function () { (0, _array2.arrayContentWillChange)(obj); deepEqual(observer._before, [obj, null, null], 'before'); (0, _array2.arrayContentDidChange)(obj); deepEqual(observer._after, [obj, null, null], 'after'); }); // API variation that included items only QUnit.test('should notify when called with same length items', function () { (0, _array2.arrayContentWillChange)(obj, 0, 1, 1); deepEqual(observer._before, [obj, ['ITEM-0'], 1], 'before'); (0, _array2.arrayContentDidChange)(obj, 0, 1, 1); deepEqual(observer._after, [obj, 1, ['ITEM-0']], 'after'); }); QUnit.test('should notify when called with diff length items', function () { (0, _array2.arrayContentWillChange)(obj, 0, 2, 1); deepEqual(observer._before, [obj, ['ITEM-0', 'ITEM-1'], 1], 'before'); (0, _array2.arrayContentDidChange)(obj, 0, 2, 1); deepEqual(observer._after, [obj, 2, ['ITEM-0']], 'after'); }); QUnit.test('removing enumerable observer should disable', function () { obj.removeEnumerableObserver(observer); (0, _array2.arrayContentWillChange)(obj); deepEqual(observer._before, null, 'before'); (0, _array2.arrayContentDidChange)(obj); deepEqual(observer._after, null, 'after'); }); // .......................................................... // @each // var ary = void 0; QUnit.module('EmberArray.@each support', { setup: function () { ary = new TestArray([{ isDone: true, desc: 'Todo 1' }, { isDone: false, desc: 'Todo 2' }, { isDone: true, desc: 'Todo 3' }, { isDone: false, desc: 'Todo 4' }]); }, teardown: function () { ary = null; } }); QUnit.test('adding an object should notify (@each.isDone)', function () { var called = 0; var observerObject = _object.default.create({ wasCalled: function () { called++; } }); (0, _emberMetal.addObserver)(ary, '@each.isDone', observerObject, 'wasCalled'); ary.addObject(_object.default.create({ desc: 'foo', isDone: false })); equal(called, 1, 'calls observer when object is pushed'); }); QUnit.test('@each is readOnly', function () { expect(1); throws(function () { (0, _emberMetal.set)(ary, '@each', 'foo'); }, /Cannot set read-only property "@each"/); }); QUnit.test('using @each to observe arrays that does not return objects raise error', function () { var called = 0; var observerObject = _object.default.create({ wasCalled: function () { called++; } }); ary = TestArray.create({ objectAt: function (idx) { return (0, _emberMetal.get)(this._content[idx], 'desc'); } }); (0, _emberMetal.addObserver)(ary, '@each.isDone', observerObject, 'wasCalled'); expectAssertion(function () { ary.addObject(_object.default.create({ desc: 'foo', isDone: false })); }, /When using @each to observe the array/); equal(called, 0, 'not calls observer when object is pushed'); }); QUnit.test('modifying the array should also indicate the isDone prop itself has changed', function () { // NOTE: we never actually get the '@each.isDone' property here. This is // important because it tests the case where we don't have an isDone // EachArray materialized but just want to know when the property has // changed. var each = (0, _emberMetal.get)(ary, '@each'); var count = 0; (0, _emberMetal.addObserver)(each, 'isDone', function () { return count++; }); count = 0; var item = (0, _array2.objectAt)(ary, 2); (0, _emberMetal.set)(item, 'isDone', !(0, _emberMetal.get)(item, 'isDone')); equal(count, 1, '@each.isDone should have notified'); }); QUnit.test('`objectAt` returns correct object', function () { var arr = ['first', 'second', 'third', 'fourth']; equal((0, _array2.objectAt)(arr, 2), 'third'); equal((0, _array2.objectAt)(arr, 4), undefined); }); (0, _internalTestHelpers.testBoth)('should be clear caches for computed properties that have dependent keys on arrays that are changed after object initialization', function (get, set) { var obj = _object.default.extend({ init: function () { this._super.apply(this, arguments); set(this, 'resources', (0, _native_array.A)()); }, common: (0, _emberMetal.computed)('resources.@each.common', function () { return get((0, _array2.objectAt)(get(this, 'resources'), 0), 'common'); }) }).create(); get(obj, 'resources').pushObject(_object.default.create({ common: 'HI!' })); equal('HI!', get(obj, 'common')); set((0, _array2.objectAt)(get(obj, 'resources'), 0), 'common', 'BYE!'); equal('BYE!', get(obj, 'common')); }); (0, _internalTestHelpers.testBoth)('observers that contain @each in the path should fire only once the first time they are accessed', function (get, set) { var count = 0; var obj = _object.default.extend({ init: function () { this._super.apply(this, arguments); // Observer does not fire on init set(this, 'resources', (0, _native_array.A)()); }, commonDidChange: (0, _emberMetal.observer)('resources.@each.common', function () { return count++; }) }).create(); // Observer fires second time when new object is added get(obj, 'resources').pushObject(_object.default.create({ common: 'HI!' })); // Observer fires third time when property on an object is changed set((0, _array2.objectAt)(get(obj, 'resources'), 0), 'common', 'BYE!'); equal(count, 2, 'observers should only be called once'); }); }); enifed('ember-runtime/tests/mixins/comparable_test', ['ember-metal', 'ember-runtime/system/object', 'ember-runtime/compare', 'ember-runtime/mixins/comparable'], function (_emberMetal, _object, _compare, _comparable) { 'use strict'; var Rectangle = _object.default.extend(_comparable.default, { length: 0, width: 0, area: function () { return (0, _emberMetal.get)(this, 'length') * (0, _emberMetal.get)(this, 'width'); }, compare: function (a, b) { return (0, _compare.default)(a.area(), b.area()); } }); var r1 = void 0, r2 = void 0; QUnit.module('Comparable', { setup: function () { r1 = Rectangle.create({ length: 6, width: 12 }); r2 = Rectangle.create({ length: 6, width: 13 }); } }); QUnit.test('should be comparable and return the correct result', function () { equal(_comparable.default.detect(r1), true); equal((0, _compare.default)(r1, r1), 0); equal((0, _compare.default)(r1, r2), -1); equal((0, _compare.default)(r2, r1), 1); }); }); enifed('ember-runtime/tests/mixins/container_proxy_test', ['ember-utils', 'container', 'ember-runtime/mixins/container_proxy', 'ember-runtime/system/object'], function (_emberUtils, _container, _container_proxy, _object) { 'use strict'; QUnit.module('ember-runtime/mixins/container_proxy', { setup: function () { this.Owner = _object.default.extend(_container_proxy.default); this.instance = this.Owner.create(); var registry = new _container.Registry(); this.instance.__container__ = new _container.Container(registry, { owner: this.instance }); } }); QUnit.test('provides ownerInjection helper method', function (assert) { var result = this.instance.ownerInjection(); assert.equal(result[_emberUtils.OWNER], this.instance, 'returns an object with the OWNER symbol'); }); }); enifed('ember-runtime/tests/mixins/copyable_test', ['ember-utils', 'ember-runtime/tests/suites/copyable', 'ember-runtime/mixins/copyable', 'ember-runtime/mixins/freezable', 'ember-runtime/system/object', 'ember-metal'], function (_emberUtils, _copyable, _copyable2, _freezable, _object, _emberMetal) { 'use strict'; QUnit.module('Ember.Copyable.frozenCopy'); QUnit.test('should be deprecated', function () { expectDeprecation('`frozenCopy` is deprecated, use `Object.freeze` instead.'); var Obj = _object.default.extend(_freezable.Freezable, _copyable2.default, { copy: function () { return Obj.create(); } }); Obj.create().frozenCopy(); }); var CopyableObject = _object.default.extend(_copyable2.default, { id: null, init: function () { this._super.apply(this, arguments); (0, _emberMetal.set)(this, 'id', (0, _emberUtils.generateGuid)()); }, copy: function () { var ret = new CopyableObject(); (0, _emberMetal.set)(ret, 'id', (0, _emberMetal.get)(this, 'id')); return ret; } }); _copyable.default.extend({ name: 'Copyable Basic Test', newObject: function () { return new CopyableObject(); }, isEqual: function (a, b) { if (!(a instanceof CopyableObject) || !(b instanceof CopyableObject)) { return false; } return (0, _emberMetal.get)(a, 'id') === (0, _emberMetal.get)(b, 'id'); } }).run(); }); enifed('ember-runtime/tests/mixins/enumerable_test', ['ember-runtime/tests/suites/enumerable', 'ember-runtime/system/object', 'ember-runtime/mixins/enumerable', 'ember-runtime/mixins/array', 'ember-runtime/system/native_array', 'ember-metal'], function (_enumerable, _object, _enumerable2, _array, _native_array, _emberMetal) { 'use strict'; function K() { return this; } /* Implement a basic fake enumerable. This validates that any non-native enumerable can impl this API. */ var TestEnumerable = _object.default.extend(_enumerable2.default, { _content: null, init: function () { var ary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; this._content = ary; }, addObject: function (obj) { if (this._content.indexOf(obj) >= 0) { return this; } this._content.push(obj); this.enumerableContentDidChange(); }, nextObject: function (idx) { return idx >= (0, _emberMetal.get)(this, 'length') ? undefined : this._content[idx]; }, length: (0, _emberMetal.computed)(function () { return this._content.length; }), slice: function () { return this._content.slice(); } }); _enumerable.default.extend({ name: 'Basic Enumerable', newObject: function (ary) { ary = ary ? ary.slice() : this.newFixture(3); return new TestEnumerable(ary); }, mutate: function (obj) { obj.addObject(obj._content.length + 1); }, toArray: function (obj) { return obj.slice(); } }).run(); QUnit.module('Ember.Enumerable'); QUnit.test('should apply Ember.Array to return value of map', function () { var x = _object.default.extend(_enumerable2.default).create(); var y = x.map(K); equal(_array.default.detect(y), true, 'should have mixin applied'); }); QUnit.test('should apply Ember.Array to return value of filter', function () { var x = _object.default.extend(_enumerable2.default).create(); var y = x.filter(K); equal(_array.default.detect(y), true, 'should have mixin applied'); }); QUnit.test('should apply Ember.Array to return value of invoke', function () { var x = _object.default.extend(_enumerable2.default).create(); var y = x.invoke(K); equal(_array.default.detect(y), true, 'should have mixin applied'); }); QUnit.test('should apply Ember.Array to return value of toArray', function () { var x = _object.default.extend(_enumerable2.default).create(); var y = x.toArray(K); equal(_array.default.detect(y), true, 'should have mixin applied'); }); QUnit.test('should apply Ember.Array to return value of without', function () { var X = _object.default.extend(_enumerable2.default, { contains: function () { return true; }, includes: function () { return true; } }); var x = X.create(); var y = x.without(K); equal(_array.default.detect(y), true, 'should have mixin applied'); }); QUnit.test('should apply Ember.Array to return value of uniq', function () { var x = _object.default.extend(_enumerable2.default).create(); var y = x.uniq(K); equal(_array.default.detect(y), true, 'should have mixin applied'); }); QUnit.test('any', function () { var kittens = (0, _native_array.A)([{ color: 'white' }, { color: 'black' }, { color: 'white' }]); var foundWhite = kittens.any(function (kitten) { return kitten.color === 'white'; }); var foundWhite2 = kittens.isAny('color', 'white'); equal(foundWhite, true); equal(foundWhite2, true); }); QUnit.test('any with NaN', function () { var numbers = (0, _native_array.A)([1, 2, NaN, 4]); var hasNaN = numbers.any(function (n) { return isNaN(n); }); equal(hasNaN, true, 'works when matching NaN'); }); QUnit.test('every', function () { var allColorsKittens = (0, _native_array.A)([{ color: 'white' }, { color: 'black' }, { color: 'white' }]); var allWhiteKittens = (0, _native_array.A)([{ color: 'white' }, { color: 'white' }, { color: 'white' }]); var allWhite = false; var whiteKittenPredicate = function (kitten) { return kitten.color === 'white'; }; allWhite = allColorsKittens.every(whiteKittenPredicate); equal(allWhite, false); allWhite = allWhiteKittens.every(whiteKittenPredicate); equal(allWhite, true); allWhite = allColorsKittens.isEvery('color', 'white'); equal(allWhite, false); allWhite = allWhiteKittens.isEvery('color', 'white'); equal(allWhite, true); }); QUnit.test('should throw an error passing a second argument to includes', function () { var x = _object.default.extend(_enumerable2.default).create(); equal(x.includes('any'), false); expectAssertion(function () { x.includes('any', 1); }, /Enumerable#includes cannot accept a second argument "startAt" as enumerable items are unordered./); }); // .......................................................... // CONTENT DID CHANGE // var DummyEnum = _object.default.extend(_enumerable2.default, { nextObject: function () {}, length: 0 }); var obj = void 0, observer = void 0; // .......................................................... // NOTIFY ENUMERABLE PROPERTY // QUnit.module('mixins/enumerable/enumerableContentDidChange'); QUnit.test('should notify observers of []', function () { var obj = _object.default.extend(_enumerable2.default, { nextObject: function () {}, // avoid exceptions enumerablePropertyDidChange: (0, _emberMetal.observer)('[]', function () { this._count++; }) }).create({ _count: 0 }); equal(obj._count, 0, 'should not have invoked yet'); obj.enumerableContentWillChange(); obj.enumerableContentDidChange(); equal(obj._count, 1, 'should have invoked'); }); // .......................................................... // NOTIFY CHANGES TO LENGTH // QUnit.module('notify observers of length', { setup: function () { obj = DummyEnum.extend({ lengthDidChange: (0, _emberMetal.observer)('length', function () { this._after++; }) }).create({ _after: 0 }); equal(obj._after, 0, 'should not have fired yet'); }, teardown: function () { obj = null; } }); QUnit.test('should notify observers when call with no params', function () { obj.enumerableContentWillChange(); equal(obj._after, 0); obj.enumerableContentDidChange(); equal(obj._after, 1); }); // API variation that included items only QUnit.test('should not notify when passed arrays of same length', function () { var added = ['foo']; var removed = ['bar']; obj.enumerableContentWillChange(removed, added); equal(obj._after, 0); obj.enumerableContentDidChange(removed, added); equal(obj._after, 0); }); QUnit.test('should notify when passed arrays of different length', function () { var added = ['foo']; var removed = ['bar', 'baz']; obj.enumerableContentWillChange(removed, added); equal(obj._after, 0); obj.enumerableContentDidChange(removed, added); equal(obj._after, 1); }); // API variation passes indexes only QUnit.test('should not notify when passed with indexes', function () { obj.enumerableContentWillChange(1, 1); equal(obj._after, 0); obj.enumerableContentDidChange(1, 1); equal(obj._after, 0); }); QUnit.test('should notify when passed old index API with delta', function () { obj.enumerableContentWillChange(1, 2); equal(obj._after, 0); obj.enumerableContentDidChange(1, 2); equal(obj._after, 1); }); // .......................................................... // NOTIFY ENUMERABLE OBSERVER // QUnit.module('notify enumerable observers', { setup: function () { obj = DummyEnum.create(); observer = _object.default.extend({ enumerableWillChange: function () { equal(this._before, null); // should only call once this._before = Array.prototype.slice.call(arguments); }, enumerableDidChange: function () { equal(this._after, null); // should only call once this._after = Array.prototype.slice.call(arguments); } }).create({ _before: null, _after: null }); obj.addEnumerableObserver(observer); }, teardown: function () { obj = observer = null; } }); QUnit.test('should notify enumerable observers when called with no params', function () { obj.enumerableContentWillChange(); deepEqual(observer._before, [obj, null, null]); obj.enumerableContentDidChange(); deepEqual(observer._after, [obj, null, null]); }); // API variation that included items only QUnit.test('should notify when called with same length items', function () { var added = ['foo']; var removed = ['bar']; obj.enumerableContentWillChange(removed, added); deepEqual(observer._before, [obj, removed, added]); obj.enumerableContentDidChange(removed, added); deepEqual(observer._after, [obj, removed, added]); }); QUnit.test('should notify when called with diff length items', function () { var added = ['foo', 'baz']; var removed = ['bar']; obj.enumerableContentWillChange(removed, added); deepEqual(observer._before, [obj, removed, added]); obj.enumerableContentDidChange(removed, added); deepEqual(observer._after, [obj, removed, added]); }); QUnit.test('should not notify when passed with indexes only', function () { obj.enumerableContentWillChange(1, 2); deepEqual(observer._before, [obj, 1, 2]); obj.enumerableContentDidChange(1, 2); deepEqual(observer._after, [obj, 1, 2]); }); QUnit.test('removing enumerable observer should disable', function () { obj.removeEnumerableObserver(observer); obj.enumerableContentWillChange(); deepEqual(observer._before, null); obj.enumerableContentDidChange(); deepEqual(observer._after, null); }); }); enifed('ember-runtime/tests/mixins/freezable_test', ['ember-runtime/system/object', 'ember-runtime/mixins/freezable'], function (_object, _freezable) { 'use strict'; QUnit.module('Ember.Freezable'); QUnit.test('should be deprecated', function () { expectDeprecation('`Ember.Freezable` is deprecated, use `Object.freeze` instead.'); _object.default.extend(_freezable.Freezable).create(); }); }); enifed('ember-runtime/tests/mixins/mutable_array_test', ['ember-metal', 'ember-runtime/tests/suites/mutable_array', 'ember-runtime/mixins/mutable_array', 'ember-runtime/system/object', 'ember-runtime/system/native_array', 'ember-runtime/mixins/array'], function (_emberMetal, _mutable_array, _mutable_array2, _object, _native_array, _array) { 'use strict'; /* Implement a basic fake mutable array. This validates that any non-native enumerable can impl this API. */ var TestMutableArray = _object.default.extend(_mutable_array2.default, { _content: null, init: function () { var ary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; this._content = (0, _native_array.A)(ary); }, replace: function (idx, amt, objects) { var args = objects ? objects.slice() : []; var removeAmt = amt; var addAmt = args.length; (0, _array.arrayContentWillChange)(this, idx, removeAmt, addAmt); args.unshift(amt); args.unshift(idx); this._content.splice.apply(this._content, args); (0, _array.arrayContentDidChange)(this, idx, removeAmt, addAmt); return this; }, objectAt: function (idx) { return this._content[idx]; }, length: (0, _emberMetal.computed)(function () { return this._content.length; }), slice: function () { return this._content.slice(); } }); _mutable_array.default.extend({ name: 'Basic Mutable Array', newObject: function (ary) { ary = ary ? ary.slice() : this.newFixture(3); return new TestMutableArray(ary); }, mutate: function (obj) { obj.addObject(this.getFixture(1)[0]); }, toArray: function (obj) { return obj.slice(); } }).run(); }); enifed('ember-runtime/tests/mixins/mutable_enumerable_test', ['ember-runtime/tests/suites/mutable_enumerable', 'ember-runtime/mixins/mutable_enumerable', 'ember-runtime/system/object', 'ember-metal'], function (_mutable_enumerable, _mutable_enumerable2, _object, _emberMetal) { 'use strict'; /* Implement a basic fake mutable array. This validates that any non-native enumerable can impl this API. */ var TestMutableEnumerable = _object.default.extend(_mutable_enumerable2.default, { _content: null, addObject: function (obj) { if (this._content.indexOf(obj) >= 0) { return this; } this.enumerableContentWillChange(null, [obj]); this._content.push(obj); this.enumerableContentDidChange(null, [obj]); }, removeObject: function (obj) { var idx = this._content.indexOf(obj); if (idx < 0) { return this; } this.enumerableContentWillChange([obj], null); this._content.splice(idx, 1); this.enumerableContentDidChange([obj], null); return this; }, init: function (ary) { this._content = ary || []; }, nextObject: function (idx) { return idx >= (0, _emberMetal.get)(this, 'length') ? undefined : this._content[idx]; }, length: (0, _emberMetal.computed)(function () { return this._content.length; }), slice: function () { return this._content.slice(); } }); _mutable_enumerable.default.extend({ name: 'Basic Mutable Array', newObject: function (ary) { ary = ary ? ary.slice() : this.newFixture(3); return new TestMutableEnumerable(ary); }, mutate: function (obj) { obj.addObject(this.getFixture(1)[0]); }, toArray: function (obj) { return obj.slice(); } }).run(); }); enifed('ember-runtime/tests/mixins/observable_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object'], function (_emberMetal, _internalTestHelpers, _object) { 'use strict'; QUnit.module('mixins/observable'); QUnit.test('should be able to use getProperties to get a POJO of provided keys', function () { var obj = _object.default.create({ firstName: 'Steve', lastName: 'Jobs', companyName: 'Apple, Inc.' }); var pojo = obj.getProperties('firstName', 'lastName'); equal('Steve', pojo.firstName); equal('Jobs', pojo.lastName); }); QUnit.test('should be able to use getProperties with array parameter to get a POJO of provided keys', function () { var obj = _object.default.create({ firstName: 'Steve', lastName: 'Jobs', companyName: 'Apple, Inc.' }); var pojo = obj.getProperties(['firstName', 'lastName']); equal('Steve', pojo.firstName); equal('Jobs', pojo.lastName); }); QUnit.test('should be able to use setProperties to set multiple properties at once', function () { var obj = _object.default.create({ firstName: 'Steve', lastName: 'Jobs', companyName: 'Apple, Inc.' }); obj.setProperties({ firstName: 'Tim', lastName: 'Cook' }); equal('Tim', obj.get('firstName')); equal('Cook', obj.get('lastName')); }); (0, _internalTestHelpers.testBoth)('calling setProperties completes safely despite exceptions', function () { var exc = new Error('Something unexpected happened!'); var obj = _object.default.extend({ companyName: (0, _emberMetal.computed)({ get: function () { return 'Apple, Inc.'; }, set: function () { throw exc; } }) }).create({ firstName: 'Steve', lastName: 'Jobs' }); var firstNameChangedCount = 0; (0, _emberMetal.addObserver)(obj, 'firstName', function () { return firstNameChangedCount++; }); try { obj.setProperties({ firstName: 'Tim', lastName: 'Cook', companyName: 'Fruit Co., Inc.' }); } catch (err) { if (err !== exc) { throw err; } } equal(firstNameChangedCount, 1, 'firstName should have fired once'); }); (0, _internalTestHelpers.testBoth)('should be able to retrieve cached values of computed properties without invoking the computed property', function (get) { var obj = _object.default.extend({ foo: (0, _emberMetal.computed)(function () { return 'foo'; }) }).create({ bar: 'bar' }); equal(obj.cacheFor('foo'), undefined, 'should return undefined if no value has been cached'); get(obj, 'foo'); equal(get(obj, 'foo'), 'foo', 'precond - should cache the value'); equal(obj.cacheFor('foo'), 'foo', 'should return the cached value after it is invoked'); equal(obj.cacheFor('bar'), undefined, 'returns undefined if the value is not a computed property'); }); QUnit.test('incrementProperty should work even if value is number in string', function () { var obj = _object.default.create({ age: '24' }); obj.incrementProperty('age'); equal(25, obj.get('age')); }); }); enifed('ember-runtime/tests/mixins/promise_proxy_test', ['ember-metal', 'ember-runtime/system/object_proxy', 'ember-runtime/mixins/promise_proxy', 'ember-runtime/ext/rsvp', 'rsvp'], function (_emberMetal, _object_proxy, _promise_proxy, _rsvp, _rsvp2) { 'use strict'; var ObjectPromiseProxy = void 0; QUnit.test('present on ember namespace', function () { ok(_promise_proxy.default, 'expected PromiseProxyMixin to exist'); }); QUnit.module('Ember.PromiseProxy - ObjectProxy', { setup: function () { ObjectPromiseProxy = _object_proxy.default.extend(_promise_proxy.default); }, teardown: function () { _rsvp2.on('error', _rsvp.onerrorDefault); } }); QUnit.test('no promise, invoking then should raise', function () { var proxy = ObjectPromiseProxy.create(); throws(function () { proxy.then(function () { return this; }, function () { return this; }); }, new RegExp('PromiseProxy\'s promise must be set')); }); QUnit.test('fulfillment', function () { var value = { firstName: 'stef', lastName: 'penner' }; var deferred = _rsvp2.defer(); var proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); var didFulfillCount = 0; var didRejectCount = 0; proxy.then(function () { return didFulfillCount++; }, function () { return didRejectCount++; }); equal((0, _emberMetal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content'); equal((0, _emberMetal.get)(proxy, 'reason'), undefined, 'expects the proxy to have no reason'); equal((0, _emberMetal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading'); equal((0, _emberMetal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled'); equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected'); equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled'); equal(didFulfillCount, 0, 'should not yet have been fulfilled'); equal(didRejectCount, 0, 'should not yet have been rejected'); (0, _emberMetal.run)(deferred, 'resolve', value); equal(didFulfillCount, 1, 'should have been fulfilled'); equal(didRejectCount, 0, 'should not have been rejected'); equal((0, _emberMetal.get)(proxy, 'content'), value, 'expects the proxy to have content'); equal((0, _emberMetal.get)(proxy, 'reason'), undefined, 'expects the proxy to still have no reason'); equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is no longer loading'); equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled'); equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected'); equal((0, _emberMetal.get)(proxy, 'isFulfilled'), true, 'expects the proxy to indicate that it is fulfilled'); (0, _emberMetal.run)(deferred, 'resolve', value); equal(didFulfillCount, 1, 'should still have been only fulfilled once'); equal(didRejectCount, 0, 'should still not have been rejected'); (0, _emberMetal.run)(deferred, 'reject', value); equal(didFulfillCount, 1, 'should still have been only fulfilled once'); equal(didRejectCount, 0, 'should still not have been rejected'); equal((0, _emberMetal.get)(proxy, 'content'), value, 'expects the proxy to have still have same content'); equal((0, _emberMetal.get)(proxy, 'reason'), undefined, 'expects the proxy still to have no reason'); equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is no longer loading'); equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled'); equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected'); equal((0, _emberMetal.get)(proxy, 'isFulfilled'), true, 'expects the proxy to indicate that it is fulfilled'); // rest of the promise semantics are tested in directly in RSVP }); QUnit.test('rejection', function () { var reason = new Error('failure'); var deferred = _rsvp2.defer(); var proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); var didFulfillCount = 0; var didRejectCount = 0; proxy.then(function () { return didFulfillCount++; }, function () { return didRejectCount++; }); equal((0, _emberMetal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content'); equal((0, _emberMetal.get)(proxy, 'reason'), undefined, 'expects the proxy to have no reason'); equal((0, _emberMetal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading'); equal((0, _emberMetal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled'); equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected'); equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled'); equal(didFulfillCount, 0, 'should not yet have been fulfilled'); equal(didRejectCount, 0, 'should not yet have been rejected'); (0, _emberMetal.run)(deferred, 'reject', reason); equal(didFulfillCount, 0, 'should not yet have been fulfilled'); equal(didRejectCount, 1, 'should have been rejected'); equal((0, _emberMetal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content'); equal((0, _emberMetal.get)(proxy, 'reason'), reason, 'expects the proxy to have a reason'); equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is not longer loading'); equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled'); equal((0, _emberMetal.get)(proxy, 'isRejected'), true, 'expects the proxy to indicate that it is rejected'); equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled'); (0, _emberMetal.run)(deferred, 'reject', reason); equal(didFulfillCount, 0, 'should stll not yet have been fulfilled'); equal(didRejectCount, 1, 'should still remain rejected'); (0, _emberMetal.run)(deferred, 'resolve', 1); equal(didFulfillCount, 0, 'should stll not yet have been fulfilled'); equal(didRejectCount, 1, 'should still remain rejected'); equal((0, _emberMetal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content'); equal((0, _emberMetal.get)(proxy, 'reason'), reason, 'expects the proxy to have a reason'); equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is not longer loading'); equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled'); equal((0, _emberMetal.get)(proxy, 'isRejected'), true, 'expects the proxy to indicate that it is rejected'); equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled'); }); QUnit.test('unhandled rejects still propagate to RSVP.on(\'error\', ...) ', function () { expect(1); _rsvp2.on('error', onerror); _rsvp2.off('error', _rsvp.onerrorDefault); var expectedReason = new Error('failure'); var deferred = _rsvp2.defer(); var proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); proxy.get('promise'); function onerror(reason) { equal(reason, expectedReason, 'expected reason'); } _rsvp2.on('error', onerror); _rsvp2.off('error', _rsvp.onerrorDefault); (0, _emberMetal.run)(deferred, 'reject', expectedReason); _rsvp2.on('error', _rsvp.onerrorDefault); _rsvp2.off('error', onerror); (0, _emberMetal.run)(deferred, 'reject', expectedReason); _rsvp2.on('error', _rsvp.onerrorDefault); _rsvp2.off('error', onerror); }); QUnit.test('should work with promise inheritance', function () { function PromiseSubclass() { _rsvp2.Promise.apply(this, arguments); } PromiseSubclass.prototype = Object.create(_rsvp2.Promise.prototype); PromiseSubclass.prototype.constructor = PromiseSubclass; PromiseSubclass.cast = _rsvp2.Promise.cast; var proxy = ObjectPromiseProxy.create({ promise: new PromiseSubclass(function () {}) }); ok(proxy.then() instanceof PromiseSubclass, 'promise proxy respected inheritance'); }); QUnit.test('should reset isFulfilled and isRejected when promise is reset', function () { var deferred = _rsvp.default.defer(); var proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); equal((0, _emberMetal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading'); equal((0, _emberMetal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled'); equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected'); equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled'); (0, _emberMetal.run)(deferred, 'resolve'); equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is no longer loading'); equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled'); equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected'); equal((0, _emberMetal.get)(proxy, 'isFulfilled'), true, 'expects the proxy to indicate that it is fulfilled'); var anotherDeferred = _rsvp.default.defer(); proxy.set('promise', anotherDeferred.promise); equal((0, _emberMetal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading'); equal((0, _emberMetal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled'); equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected'); equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled'); (0, _emberMetal.run)(anotherDeferred, 'reject'); equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is not longer loading'); equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled'); equal((0, _emberMetal.get)(proxy, 'isRejected'), true, 'expects the proxy to indicate that it is rejected'); equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled'); }); QUnit.test('should have content when isFulfilled is set', function () { var deferred = _rsvp.default.defer(); var proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); proxy.addObserver('isFulfilled', function () { return equal((0, _emberMetal.get)(proxy, 'content'), true); }); (0, _emberMetal.run)(deferred, 'resolve', true); }); QUnit.test('should have reason when isRejected is set', function () { var error = new Error('Y U REJECT?!?'); var deferred = _rsvp.default.defer(); var proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); proxy.addObserver('isRejected', function () { return equal((0, _emberMetal.get)(proxy, 'reason'), error); }); try { (0, _emberMetal.run)(deferred, 'reject', error); } catch (e) { equal(e, error); } }); QUnit.test('should not error if promise is resolved after proxy has been destroyed', function () { var deferred = _rsvp.default.defer(); var proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); proxy.then(function () {}, function () {}); (0, _emberMetal.run)(proxy, 'destroy'); (0, _emberMetal.run)(deferred, 'resolve', true); ok(true, 'resolving the promise after the proxy has been destroyed does not raise an error'); }); QUnit.test('should not error if promise is rejected after proxy has been destroyed', function () { var deferred = _rsvp.default.defer(); var proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); proxy.then(function () {}, function () {}); (0, _emberMetal.run)(proxy, 'destroy'); (0, _emberMetal.run)(deferred, 'reject', 'some reason'); ok(true, 'rejecting the promise after the proxy has been destroyed does not raise an error'); }); QUnit.test('promise chain is not broken if promised is resolved after proxy has been destroyed', function () { var deferred = _rsvp.default.defer(); var expectedValue = {}; var receivedValue = void 0; var didResolveCount = 0; var proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); proxy.then(function (value) { receivedValue = value; didResolveCount++; }, function () {}); (0, _emberMetal.run)(proxy, 'destroy'); (0, _emberMetal.run)(deferred, 'resolve', expectedValue); equal(didResolveCount, 1, 'callback called'); equal(receivedValue, expectedValue, 'passed value is the value the promise was resolved with'); }); QUnit.test('promise chain is not broken if promised is rejected after proxy has been destroyed', function () { var deferred = _rsvp.default.defer(); var expectedReason = 'some reason'; var receivedReason = void 0; var didRejectCount = 0; var proxy = ObjectPromiseProxy.create({ promise: deferred.promise }); proxy.then(function () {}, function (reason) { receivedReason = reason; didRejectCount++; }); (0, _emberMetal.run)(proxy, 'destroy'); (0, _emberMetal.run)(deferred, 'reject', expectedReason); equal(didRejectCount, 1, 'callback called'); equal(receivedReason, expectedReason, 'passed reason is the reason the promise was rejected for'); }); }); enifed('ember-runtime/tests/mixins/target_action_support_test', ['ember-environment', 'ember-runtime/system/object', 'ember-runtime/mixins/target_action_support'], function (_emberEnvironment, _object, _target_action_support) { 'use strict'; var originalLookup = _emberEnvironment.context.lookup; var lookup = void 0; QUnit.module('TargetActionSupport', { setup: function () { _emberEnvironment.context.lookup = lookup = {}; }, teardown: function () { _emberEnvironment.context.lookup = originalLookup; } }); QUnit.test('it should return false if no target or action are specified', function () { expect(1); var obj = _object.default.extend(_target_action_support.default).create(); ok(false === obj.triggerAction(), 'no target or action was specified'); }); QUnit.test('it should support actions specified as strings', function () { expect(2); var obj = _object.default.extend(_target_action_support.default).create({ target: _object.default.create({ anEvent: function () { ok(true, 'anEvent method was called'); } }), action: 'anEvent' }); ok(true === obj.triggerAction(), 'a valid target and action were specified'); }); QUnit.test('it should invoke the send() method on objects that implement it', function () { expect(3); var obj = _object.default.extend(_target_action_support.default).create({ target: _object.default.create({ send: function (evt, context) { equal(evt, 'anEvent', 'send() method was invoked with correct event name'); equal(context, obj, 'send() method was invoked with correct context'); } }), action: 'anEvent' }); ok(true === obj.triggerAction(), 'a valid target and action were specified'); }); QUnit.test('it should find targets specified using a property path', function () { expect(2); var Test = {}; lookup.Test = Test; Test.targetObj = _object.default.create({ anEvent: function () { ok(true, 'anEvent method was called on global object'); } }); var myObj = _object.default.extend(_target_action_support.default).create({ target: 'Test.targetObj', action: 'anEvent' }); ok(true === myObj.triggerAction(), 'a valid target and action were specified'); }); QUnit.test('it should use an actionContext object specified as a property on the object', function () { expect(2); var obj = _object.default.extend(_target_action_support.default).create({ action: 'anEvent', actionContext: {}, target: _object.default.create({ anEvent: function (ctx) { ok(obj.actionContext === ctx, 'anEvent method was called with the expected context'); } }) }); ok(true === obj.triggerAction(), 'a valid target and action were specified'); }); QUnit.test('it should find an actionContext specified as a property path', function () { expect(2); var Test = {}; lookup.Test = Test; Test.aContext = {}; var obj = _object.default.extend(_target_action_support.default).create({ action: 'anEvent', actionContext: 'Test.aContext', target: _object.default.create({ anEvent: function (ctx) { ok(Test.aContext === ctx, 'anEvent method was called with the expected context'); } }) }); ok(true === obj.triggerAction(), 'a valid target and action were specified'); }); QUnit.test('it should use the target specified in the argument', function () { expect(2); var targetObj = _object.default.create({ anEvent: function () { ok(true, 'anEvent method was called'); } }); var obj = _object.default.extend(_target_action_support.default).create({ action: 'anEvent' }); ok(true === obj.triggerAction({ target: targetObj }), 'a valid target and action were specified'); }); QUnit.test('it should use the action specified in the argument', function () { expect(2); var obj = _object.default.extend(_target_action_support.default).create({ target: _object.default.create({ anEvent: function () { ok(true, 'anEvent method was called'); } }) }); ok(true === obj.triggerAction({ action: 'anEvent' }), 'a valid target and action were specified'); }); QUnit.test('it should use the actionContext specified in the argument', function () { expect(2); var context = {}; var obj = _object.default.extend(_target_action_support.default).create({ target: _object.default.create({ anEvent: function (ctx) { ok(context === ctx, 'anEvent method was called with the expected context'); } }), action: 'anEvent' }); ok(true === obj.triggerAction({ actionContext: context }), 'a valid target and action were specified'); }); QUnit.test('it should allow multiple arguments from actionContext', function () { expect(3); var param1 = 'someParam'; var param2 = 'someOtherParam'; var obj = _object.default.extend(_target_action_support.default).create({ target: _object.default.create({ anEvent: function (first, second) { ok(first === param1, 'anEvent method was called with the expected first argument'); ok(second === param2, 'anEvent method was called with the expected second argument'); } }), action: 'anEvent' }); ok(true === obj.triggerAction({ actionContext: [param1, param2] }), 'a valid target and action were specified'); }); QUnit.test('it should use a null value specified in the actionContext argument', function () { expect(2); var obj = _object.default.extend(_target_action_support.default).create({ target: _object.default.create({ anEvent: function (ctx) { ok(null === ctx, 'anEvent method was called with the expected context (null)'); } }), action: 'anEvent' }); ok(true === obj.triggerAction({ actionContext: null }), 'a valid target and action were specified'); }); }); enifed('ember-runtime/tests/suites/array', ['exports', 'ember-runtime/tests/suites/enumerable', 'ember-runtime/tests/suites/array/indexOf', 'ember-runtime/tests/suites/array/lastIndexOf', 'ember-runtime/tests/suites/array/objectAt', 'ember-runtime/tests/suites/array/includes', 'ember-runtime/mixins/array'], function (exports, _enumerable, _indexOf, _lastIndexOf, _objectAt, _includes, _array) { 'use strict'; exports.ObserverClass = exports.ArrayTests = undefined; var ObserverClass = _enumerable.ObserverClass.extend({ observeArray: function (obj) { (0, _array.addArrayObserver)(obj, this); return this; }, stopObserveArray: function (obj) { (0, _array.removeArrayObserver)(obj, this); return this; }, arrayWillChange: function () { equal(this._before, null, 'should only call once'); this._before = Array.prototype.slice.call(arguments); }, arrayDidChange: function () { equal(this._after, null, 'should only call once'); this._after = Array.prototype.slice.call(arguments); } }); var ArrayTests = _enumerable.EnumerableTests.extend({ observerClass: ObserverClass }); ArrayTests.ObserverClass = ObserverClass; ArrayTests.importModuleTests(_indexOf.default); ArrayTests.importModuleTests(_lastIndexOf.default); ArrayTests.importModuleTests(_objectAt.default); ArrayTests.importModuleTests(_includes.default); exports.ArrayTests = ArrayTests; exports.ObserverClass = ObserverClass; }); enifed('ember-runtime/tests/suites/array/includes', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('includes'); suite.test('includes returns correct value if startAt is positive', function () { var data = this.newFixture(3); var obj = this.newObject(data); equal(obj.includes(data[1], 1), true, 'should return true if included'); equal(obj.includes(data[0], 1), false, 'should return false if not included'); }); suite.test('includes returns correct value if startAt is negative', function () { var data = this.newFixture(3); var obj = this.newObject(data); equal(obj.includes(data[1], -2), true, 'should return true if included'); equal(obj.includes(data[0], -2), false, 'should return false if not included'); }); suite.test('includes returns true if startAt + length is still negative', function () { var data = this.newFixture(1); var obj = this.newObject(data); equal(obj.includes(data[0], -2), true, 'should return true if included'); equal(obj.includes(this.newFixture(1), -2), false, 'should return false if not included'); }); suite.test('includes returns false if startAt out of bounds', function () { var data = this.newFixture(1); var obj = this.newObject(data); equal(obj.includes(data[0], 2), false, 'should return false if startAt >= length'); equal(obj.includes(this.newFixture(1), 2), false, 'should return false if startAt >= length'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/array/indexOf', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('indexOf'); suite.test('should return index of object', function () { var expected = this.newFixture(3), idx; var obj = this.newObject(expected); for (idx = 0; idx < 3; idx++) { equal(obj.indexOf(expected[idx]), idx, 'obj.indexOf(' + expected[idx] + ') should match idx'); } }); suite.test('should return -1 when requesting object not in index', function () { var obj = this.newObject(this.newFixture(3)); equal(obj.indexOf({}), -1, 'obj.indexOf(foo) should be < 0'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/array/lastIndexOf', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('lastIndexOf'); suite.test('should return index of object\'s last occurrence', function () { var expected = this.newFixture(3), idx; var obj = this.newObject(expected); for (idx = 0; idx < 3; idx++) { equal(obj.lastIndexOf(expected[idx]), idx, 'obj.lastIndexOf(' + expected[idx] + ') should match idx'); } }); suite.test('should return index of object\'s last occurrence even startAt search location is equal to length', function () { var expected = this.newFixture(3), idx; var obj = this.newObject(expected); var len = 3; for (idx = 0; idx < len; idx++) { equal(obj.lastIndexOf(expected[idx], len), idx, 'obj.lastIndexOfs(' + expected[idx] + ') should match idx'); } }); suite.test('should return index of object\'s last occurrence even startAt search location is greater than length', function () { var expected = this.newFixture(3), idx; var obj = this.newObject(expected); var len = 3; for (idx = 0; idx < len; idx++) { equal(obj.lastIndexOf(expected[idx], len + 1), idx, 'obj.lastIndexOf(' + expected[idx] + ') should match idx'); } }); suite.test('should return -1 when no match is found', function () { var obj = this.newObject(this.newFixture(3)); equal(obj.lastIndexOf({}), -1, 'obj.lastIndexOf(foo) should be -1'); }); suite.test('should return -1 when no match is found even startAt search location is equal to length', function () { var obj = this.newObject(this.newFixture(3)); equal(obj.lastIndexOf({}, obj.length), -1, 'obj.lastIndexOf(foo) should be -1'); }); suite.test('should return -1 when no match is found even startAt search location is greater than length', function () { var obj = this.newObject(this.newFixture(3)); equal(obj.lastIndexOf({}, obj.length + 1), -1, 'obj.lastIndexOf(foo) should be -1'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/array/objectAt', ['exports', 'ember-runtime/tests/suites/suite', 'ember-runtime/mixins/array'], function (exports, _suite, _array) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('objectAt'); suite.test('should return object at specified index', function () { var expected = this.newFixture(3), idx; var obj = this.newObject(expected); var len = expected.length; for (idx = 0; idx < len; idx++) { equal((0, _array.objectAt)(obj, idx), expected[idx], 'obj.objectAt(' + idx + ') should match'); } }); suite.test('should return undefined when requesting objects beyond index', function () { var obj = void 0; obj = this.newObject(this.newFixture(3)); equal((0, _array.objectAt)(obj, 5), undefined, 'should return undefined for obj.objectAt(5) when len = 3'); obj = this.newObject([]); equal((0, _array.objectAt)(obj, 0), undefined, 'should return undefined for obj.objectAt(0) when len = 0'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/copyable', ['exports', 'ember-runtime/tests/suites/suite', 'ember-runtime/tests/suites/copyable/copy', 'ember-runtime/tests/suites/copyable/frozenCopy'], function (exports, _suite, _copy, _frozenCopy) { 'use strict'; var CopyableTests = _suite.Suite.extend({ /* __Required.__ You must implement this method to apply this mixin. Must be able to create a new object for testing. @returns {Object} object */ newObject: null, /* __Required.__ You must implement this method to apply this mixin. Compares the two passed in objects. Returns true if the two objects are logically equivalent. @param {Object} a First object @param {Object} b Second object @returns {Boolean} */ isEqual: null, /* Set this to true if you expect the objects you test to be freezable. The suite will verify that your objects actually match this. (i.e. if you say you can't test freezable it will verify that your objects really aren't freezable.) @type Boolean */ shouldBeFreezable: false }); CopyableTests.importModuleTests(_copy.default); CopyableTests.importModuleTests(_frozenCopy.default); exports.default = CopyableTests; }); enifed('ember-runtime/tests/suites/copyable/copy', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('copy'); suite.test('should return an equivalent copy', function () { var obj = this.newObject(); var copy = obj.copy(); ok(this.isEqual(obj, copy), 'old object and new object should be equivalent'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/copyable/frozenCopy', ['exports', 'ember-runtime/tests/suites/suite', 'ember-runtime/mixins/freezable', 'ember-metal'], function (exports, _suite, _freezable, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('frozenCopy'); suite.test('frozen objects should return same instance', function () { var obj = void 0, copy = void 0; obj = this.newObject(); if ((0, _emberMetal.get)(this, 'shouldBeFreezable')) { expectDeprecation('`frozenCopy` is deprecated, use Object.freeze instead.'); ok(!_freezable.Freezable || _freezable.Freezable.detect(obj), 'object should be freezable'); copy = obj.frozenCopy(); ok(this.isEqual(obj, copy), 'new copy should be equal'); ok((0, _emberMetal.get)(copy, 'isFrozen'), 'returned value should be frozen'); copy = obj.freeze().frozenCopy(); equal(copy, obj, 'returns frozen object should be same'); ok((0, _emberMetal.get)(copy, 'isFrozen'), 'returned object should be frozen'); } else { ok(!_freezable.Freezable || !_freezable.Freezable.detect(obj), 'object should not be freezable'); } }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable', ['exports', 'ember-utils', 'ember-runtime/tests/suites/suite', 'ember-runtime/system/object', 'ember-metal', 'ember-runtime/tests/suites/enumerable/any', 'ember-runtime/tests/suites/enumerable/is_any', 'ember-runtime/tests/suites/enumerable/compact', 'ember-runtime/tests/suites/enumerable/contains', 'ember-runtime/tests/suites/enumerable/includes', 'ember-runtime/tests/suites/enumerable/every', 'ember-runtime/tests/suites/enumerable/filter', 'ember-runtime/tests/suites/enumerable/find', 'ember-runtime/tests/suites/enumerable/firstObject', 'ember-runtime/tests/suites/enumerable/forEach', 'ember-runtime/tests/suites/enumerable/mapBy', 'ember-runtime/tests/suites/enumerable/invoke', 'ember-runtime/tests/suites/enumerable/lastObject', 'ember-runtime/tests/suites/enumerable/map', 'ember-runtime/tests/suites/enumerable/reduce', 'ember-runtime/tests/suites/enumerable/reject', 'ember-runtime/tests/suites/enumerable/sortBy', 'ember-runtime/tests/suites/enumerable/toArray', 'ember-runtime/tests/suites/enumerable/uniq', 'ember-runtime/tests/suites/enumerable/uniqBy', 'ember-runtime/tests/suites/enumerable/without'], function (exports, _emberUtils, _suite, _object, _emberMetal, _any, _is_any, _compact, _contains, _includes, _every, _filter, _find, _firstObject, _forEach, _mapBy, _invoke, _lastObject, _map, _reduce, _reject, _sortBy, _toArray, _uniq, _uniqBy, _without) { 'use strict'; exports.ObserverClass = exports.EnumerableTests = undefined; var ObserverClass = _object.default.extend({ _keysBefore: null, _keys: null, _values: null, _before: null, _after: null, isEnabled: true, init: function () { this._super.apply(this, arguments); this.reset(); }, propertyWillChange: function (target, key) { if (this._keysBefore[key] === undefined) { this._keysBefore[key] = 0; } this._keysBefore[key]++; }, propertyDidChange: function (target, key, value) { if (this._keys[key] === undefined) { this._keys[key] = 0; } this._keys[key]++; this._values[key] = value; }, reset: function () { this._keysBefore = {}; this._keys = {}; this._values = {}; this._before = null; this._after = null; return this; }, observeBefore: function (obj) { var keys = Array.prototype.slice.call(arguments, 1); var loc = keys.length; while (--loc >= 0) { (0, _emberMetal._addBeforeObserver)(obj, keys[loc], this, 'propertyWillChange'); } return this; }, observe: function (obj) { var keys, loc; if (obj.addObserver) { keys = Array.prototype.slice.call(arguments, 1); loc = keys.length; while (--loc >= 0) { obj.addObserver(keys[loc], this, 'propertyDidChange'); } } else { this.isEnabled = false; } return this; }, validate: function (key, value) { if (!this.isEnabled) { return true; } if (!this._keys[key]) { return false; } if (arguments.length > 1) { return this._values[key] === value; } else { return true; } }, timesCalledBefore: function (key) { return this._keysBefore[key] || 0; }, timesCalled: function (key) { return this._keys[key] || 0; }, observeEnumerable: function (obj) { obj.addEnumerableObserver(this); return this; }, stopObserveEnumerable: function (obj) { obj.removeEnumerableObserver(this); return this; }, enumerableWillChange: function () { equal(this._before, null, 'should only call once'); this._before = Array.prototype.slice.call(arguments); }, enumerableDidChange: function () { equal(this._after, null, 'should only call once'); this._after = Array.prototype.slice.call(arguments); } }); var EnumerableTests = _suite.Suite.extend({ /* __Required.__ You must implement this method to apply this mixin. Implement to return a new enumerable object for testing. Should accept either no parameters, a single number (indicating the desired length of the collection) or an array of objects. @param {Array} content An array of items to include in the enumerable optionally. @returns {Ember.Enumerable} a new enumerable */ newObject: null, newFixture: function (cnt) { var ret = []; while (--cnt >= 0) { ret.push((0, _emberUtils.generateGuid)()); } return ret; }, newObjectsFixture: function (cnt) { var ret = []; var item = void 0; while (--cnt >= 0) { item = {}; (0, _emberUtils.guidFor)(item); ret.push(item); } return ret; }, /* __Required.__ You must implement this method to apply this mixin. Implement accept an instance of the enumerable and return an array containing the objects in the enumerable. This is used only for testing so performance is not important. @param {Ember.Enumerable} enumerable The enumerable to convert. @returns {Array} array of items */ toArray: null, mutate: function () {}, /* Becomes true when you define a new mutate() method, indicating that mutation tests should run. This is calculated automatically. @type Boolean */ canTestMutation: (0, _emberMetal.computed)(function () { return this.mutate !== EnumerableTests.prototype.mutate; }), run: function () {}, newObserver: function () { var ret = (0, _emberMetal.get)(this, 'observerClass').create(); if (arguments.length > 0) { ret.observeBefore.apply(ret, arguments); } if (arguments.length > 0) { ret.observe.apply(ret, arguments); } return ret; }, observerClass: ObserverClass }); EnumerableTests.importModuleTests(_any.default); EnumerableTests.importModuleTests(_is_any.default); EnumerableTests.importModuleTests(_compact.default); EnumerableTests.importModuleTests(_contains.default); EnumerableTests.importModuleTests(_every.default); EnumerableTests.importModuleTests(_filter.default); EnumerableTests.importModuleTests(_find.default); EnumerableTests.importModuleTests(_firstObject.default); EnumerableTests.importModuleTests(_forEach.default); EnumerableTests.importModuleTests(_mapBy.default); EnumerableTests.importModuleTests(_invoke.default); EnumerableTests.importModuleTests(_lastObject.default); EnumerableTests.importModuleTests(_map.default); EnumerableTests.importModuleTests(_reduce.default); EnumerableTests.importModuleTests(_reject.default); EnumerableTests.importModuleTests(_sortBy.default); EnumerableTests.importModuleTests(_toArray.default); EnumerableTests.importModuleTests(_uniq.default); EnumerableTests.importModuleTests(_uniqBy.default); EnumerableTests.importModuleTests(_includes.default); EnumerableTests.importModuleTests(_without.default); exports.default = EnumerableTests; exports.EnumerableTests = EnumerableTests; exports.ObserverClass = ObserverClass; }); enifed('ember-runtime/tests/suites/enumerable/any', ['exports', 'ember-runtime/tests/suites/suite', 'ember-runtime/system/native_array'], function (exports, _suite, _native_array) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); // .......................................................... // any() // suite.module('any'); suite.test('any should should invoke callback on each item as long as you return false', function () { var obj = this.newObject(); var ary = this.toArray(obj); var found = []; var result = void 0; result = obj.any(function (i) { found.push(i); return false; }); equal(result, false, 'return value of obj.any'); deepEqual(found, ary, 'items passed during any() should match'); }); suite.test('any should stop invoking when you return true', function () { var obj = this.newObject(); var ary = this.toArray(obj); var cnt = ary.length - 2; var exp = cnt; var found = []; var result = void 0; result = obj.any(function (i) { found.push(i); return --cnt <= 0; }); equal(result, true, 'return value of obj.any'); equal(found.length, exp, 'should invoke proper number of times'); deepEqual(found, ary.slice(0, -2), 'items passed during any() should match'); }); suite.test('any should return true if any object matches the callback', function () { var obj = (0, _native_array.A)([0, 1, 2]); var result = void 0; result = obj.any(function (i) { return !!i; }); equal(result, true, 'return value of obj.any'); }); suite.test('any should return false if no object matches the callback', function () { var obj = (0, _native_array.A)([0, null, false]); var result = void 0; result = obj.any(function (i) { return !!i; }); equal(result, false, 'return value of obj.any'); }); suite.test('any should produce correct results even if the matching element is undefined', function () { var obj = (0, _native_array.A)([undefined]); var result = void 0; result = obj.any(function () { return true; }); equal(result, true, 'return value of obj.any'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/compact', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('compact'); suite.test('removes null and undefined values from enumerable', function () { var obj = this.newObject([null, 1, false, '', undefined, 0, null]); var ary = obj.compact(); deepEqual(ary, [1, false, '', 0]); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/contains', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('contains'); suite.test('contains returns true if item is in enumerable', function () { var data = this.newFixture(3); var obj = this.newObject(data); expectDeprecation('`Enumerable#contains` is deprecated, use `Enumerable#includes` instead.'); equal(obj.contains(data[1]), true, 'should return true if contained'); }); suite.test('contains returns false if item is not in enumerable', function () { var data = this.newFixture(1); var obj = this.newObject(this.newFixture(3)); expectDeprecation('`Enumerable#contains` is deprecated, use `Enumerable#includes` instead.'); equal(obj.contains(data[0]), false, 'should return false if not contained'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/every', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); // .......................................................... // every() // suite.module('every'); suite.test('every should should invoke callback on each item as long as you return true', function () { var obj = this.newObject(); var ary = this.toArray(obj); var found = []; var result = void 0; result = obj.every(function (i) { found.push(i); return true; }); equal(result, true, 'return value of obj.every'); deepEqual(found, ary, 'items passed during every() should match'); }); suite.test('every should stop invoking when you return false', function () { var obj = this.newObject(); var ary = this.toArray(obj); var cnt = ary.length - 2; var exp = cnt; var found = []; var result = void 0; result = obj.every(function (i) { found.push(i); return --cnt > 0; }); equal(result, false, 'return value of obj.every'); equal(found.length, exp, 'should invoke proper number of times'); deepEqual(found, ary.slice(0, -2), 'items passed during every() should match'); }); // .......................................................... // isEvery() // suite.module('isEvery'); suite.test('should return true of every property matches', function () { var obj = this.newObject([{ foo: 'foo', bar: 'BAZ' }, _object.default.create({ foo: 'foo', bar: 'bar' })]); equal(obj.isEvery('foo', 'foo'), true, 'isEvery(foo)'); equal(obj.isEvery('bar', 'bar'), false, 'isEvery(bar)'); }); suite.test('should return true of every property is true', function () { var obj = this.newObject([{ foo: 'foo', bar: true }, _object.default.create({ foo: 'bar', bar: false })]); // different values - all eval to true equal(obj.isEvery('foo'), true, 'isEvery(foo)'); equal(obj.isEvery('bar'), false, 'isEvery(bar)'); }); suite.test('should return true if every property matches null', function () { var obj = this.newObject([{ foo: null, bar: 'BAZ' }, _object.default.create({ foo: null, bar: null })]); equal(obj.isEvery('foo', null), true, 'isEvery(\'foo\', null)'); equal(obj.isEvery('bar', null), false, 'isEvery(\'bar\', null)'); }); suite.test('should return true if every property is undefined', function () { var obj = this.newObject([{ foo: undefined, bar: 'BAZ' }, _object.default.create({ bar: undefined })]); equal(obj.isEvery('foo', undefined), true, 'isEvery(\'foo\', undefined)'); equal(obj.isEvery('bar', undefined), false, 'isEvery(\'bar\', undefined)'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/filter', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); // .......................................................... // filter() // suite.module('filter'); suite.test('filter should invoke on each item', function () { var obj = this.newObject(); var ary = this.toArray(obj); var cnt = ary.length - 2; var found = []; var result = void 0; // return true on all but the last two result = obj.filter(function (i) { found.push(i); return --cnt >= 0; }); deepEqual(found, ary, 'should have invoked on each item'); deepEqual(result, ary.slice(0, -2), 'filtered array should exclude items'); }); // .......................................................... // filterBy() // suite.module('filterBy'); suite.test('should filter based on object', function () { var obj = void 0, ary = void 0; ary = [{ foo: 'foo', bar: 'BAZ' }, _object.default.create({ foo: 'foo', bar: 'bar' })]; obj = this.newObject(ary); deepEqual(obj.filterBy('foo', 'foo'), ary, 'filterBy(foo)'); deepEqual(obj.filterBy('bar', 'bar'), [ary[1]], 'filterBy(bar)'); }); suite.test('should include in result if property is true', function () { var obj = void 0, ary = void 0; ary = [{ foo: 'foo', bar: true }, _object.default.create({ foo: 'bar', bar: false })]; obj = this.newObject(ary); // different values - all eval to true deepEqual(obj.filterBy('foo'), ary, 'filterBy(foo)'); deepEqual(obj.filterBy('bar'), [ary[0]], 'filterBy(bar)'); }); suite.test('should filter on second argument if provided', function () { var obj = void 0, ary = void 0; ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 2 }), { name: 'obj3', foo: 2 }, _object.default.create({ name: 'obj4', foo: 3 })]; obj = this.newObject(ary); deepEqual(obj.filterBy('foo', 3), [ary[0], ary[3]], 'filterBy(\'foo\', 3)\')'); }); suite.test('should correctly filter null second argument', function () { var obj = void 0, ary = void 0; ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: null }), { name: 'obj3', foo: null }, _object.default.create({ name: 'obj4', foo: 3 })]; obj = this.newObject(ary); deepEqual(obj.filterBy('foo', null), [ary[1], ary[2]], 'filterBy(\'foo\', 3)\')'); }); suite.test('should not return all objects on undefined second argument', function () { var obj = void 0, ary = void 0; ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 2 })]; obj = this.newObject(ary); deepEqual(obj.filterBy('foo', undefined), [], 'filterBy(\'foo\', 3)\')'); }); suite.test('should correctly filter explicit undefined second argument', function () { var obj = void 0, ary = void 0; ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 3 }), { name: 'obj3', foo: undefined }, _object.default.create({ name: 'obj4', foo: undefined }), { name: 'obj5' }, _object.default.create({ name: 'obj6' })]; obj = this.newObject(ary); deepEqual(obj.filterBy('foo', undefined), ary.slice(2), 'filterBy(\'foo\', 3)\')'); }); suite.test('should not match undefined properties without second argument', function () { var obj = void 0, ary = void 0; ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 3 }), { name: 'obj3', foo: undefined }, _object.default.create({ name: 'obj4', foo: undefined }), { name: 'obj5' }, _object.default.create({ name: 'obj6' })]; obj = this.newObject(ary); deepEqual(obj.filterBy('foo'), ary.slice(0, 2), 'filterBy(\'foo\', 3)\')'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/find', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); // .......................................................... // find() // suite.module('find'); suite.test('find should invoke callback on each item as long as you return false', function () { var obj = this.newObject(); var ary = this.toArray(obj); var found = []; var result = void 0; result = obj.find(function (i) { found.push(i); return false; }); equal(result, undefined, 'return value of obj.find'); deepEqual(found, ary, 'items passed during find() should match'); }); suite.test('every should stop invoking when you return true', function () { var obj = this.newObject(); var ary = this.toArray(obj); var cnt = ary.length - 2; var exp = cnt; var found = []; var result = void 0; result = obj.find(function (i) { found.push(i); return --cnt >= 0; }); equal(result, ary[exp - 1], 'return value of obj.find'); equal(found.length, exp, 'should invoke proper number of times'); deepEqual(found, ary.slice(0, -2), 'items passed during find() should match'); }); // .......................................................... // findBy() // suite.module('findBy'); suite.test('should return first object of property matches', function () { var ary = void 0, obj = void 0; ary = [{ foo: 'foo', bar: 'BAZ' }, _object.default.create({ foo: 'foo', bar: 'bar' })]; obj = this.newObject(ary); equal(obj.findBy('foo', 'foo'), ary[0], 'findBy(foo)'); equal(obj.findBy('bar', 'bar'), ary[1], 'findBy(bar)'); }); suite.test('should return first object with truthy prop', function () { var ary = void 0, obj = void 0; ary = [{ foo: 'foo', bar: false }, _object.default.create({ foo: 'bar', bar: true })]; obj = this.newObject(ary); // different values - all eval to true equal(obj.findBy('foo'), ary[0], 'findBy(foo)'); equal(obj.findBy('bar'), ary[1], 'findBy(bar)'); }); suite.test('should return first null property match', function () { var ary = void 0, obj = void 0; ary = [{ foo: null, bar: 'BAZ' }, _object.default.create({ foo: null, bar: null })]; obj = this.newObject(ary); equal(obj.findBy('foo', null), ary[0], 'findBy(\'foo\', null)'); equal(obj.findBy('bar', null), ary[1], 'findBy(\'bar\', null)'); }); suite.test('should return first undefined property match', function () { var ary = void 0, obj = void 0; ary = [{ foo: undefined, bar: 'BAZ' }, _object.default.create({})]; obj = this.newObject(ary); equal(obj.findBy('foo', undefined), ary[0], 'findBy(\'foo\', undefined)'); equal(obj.findBy('bar', undefined), ary[1], 'findBy(\'bar\', undefined)'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/firstObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('firstObject'); suite.test('returns first item in enumerable', function () { var obj = this.newObject(); equal((0, _emberMetal.get)(obj, 'firstObject'), this.toArray(obj)[0]); }); suite.test('returns undefined if enumerable is empty', function () { var obj = this.newObject([]); equal((0, _emberMetal.get)(obj, 'firstObject'), undefined); }); suite.test('can not be set', function () { var obj = this.newObject([]); equal((0, _emberMetal.get)(obj, 'firstObject'), this.toArray(obj)[0]); throws(function () { (0, _emberMetal.set)(obj, 'firstObject', 'foo!'); }, /Cannot set read-only property "firstObject" on object/); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/forEach', ['exports', 'ember-utils', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _emberUtils, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('forEach'); suite.test('forEach should iterate over list', function () { var obj = this.newObject(); var ary = this.toArray(obj); var found = []; obj.forEach(function (i) { return found.push(i); }); deepEqual(found, ary, 'items passed during forEach should match'); }); suite.test('forEach should iterate over list after mutation', function () { if ((0, _emberMetal.get)(this, 'canTestMutation')) { expect(0); return; } var obj = this.newObject(); var ary = this.toArray(obj); var found = []; obj.forEach(function (i) { return found.push(i); }); deepEqual(found, ary, 'items passed during forEach should match'); this.mutate(obj); ary = this.toArray(obj); found = []; obj.forEach(function (i) { return found.push(i); }); deepEqual(found, ary, 'items passed during forEach should match'); }); suite.test('2nd target parameter', function () { var _this = this; var obj = this.newObject(); var target = this; obj.forEach(function () { // ES6TODO: When transpiled we will end up with "use strict" which disables automatically binding to the global context. // Therefore, the following test can never pass in strict mode unless we modify the `map` function implementation to // use `Ember.lookup` if target is not specified. // // equal(guidFor(this), guidFor(global), 'should pass the global object as this if no context'); }); obj.forEach(function () { equal((0, _emberUtils.guidFor)(_this), (0, _emberUtils.guidFor)(target), 'should pass target as this if context'); }, target); }); suite.test('callback params', function () { var obj = this.newObject(); var ary = this.toArray(obj); var loc = 0; obj.forEach(function (item, idx, enumerable) { equal(item, ary[loc], 'item param'); equal(idx, loc, 'idx param'); equal((0, _emberUtils.guidFor)(enumerable), (0, _emberUtils.guidFor)(obj), 'enumerable param'); loc++; }); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/includes', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('includes'); suite.test('includes returns true if item is in enumerable', function () { var data = this.newFixture(1); var obj = this.newObject([].concat(data, [NaN, undefined, null])); equal(obj.includes(data[0]), true, 'should return true if included'); equal(obj.includes(NaN), true, 'should return true if NaN included'); equal(obj.includes(undefined), true, 'should return true if undefined included'); equal(obj.includes(null), true, 'should return true if null included'); }); suite.test('includes returns false if item is not in enumerable', function () { var data = this.newFixture(1); var obj = this.newObject([].concat(this.newFixture(3), [null])); equal(obj.includes(data[0]), false, 'should return false if not included'); equal(obj.includes(undefined), false, 'should return false if undefined not included but null is included'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/invoke', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('invoke'); suite.test('invoke should call on each object that implements', function () { var cnt = void 0, ary = void 0, obj = void 0; function F(amt) { cnt += amt === undefined ? 1 : amt; } cnt = 0; ary = [{ foo: F }, _object.default.create({ foo: F }), // NOTE: does not impl foo - invoke should just skip _object.default.create({ bar: F }), { foo: F }]; obj = this.newObject(ary); obj.invoke('foo'); equal(cnt, 3, 'should have invoked 3 times'); cnt = 0; obj.invoke('foo', 2); equal(cnt, 6, 'should have invoked 3 times, passing param'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/is_any', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); // .......................................................... // isAny() // suite.module('isAny'); suite.test('should return true of any property matches', function () { var obj = this.newObject([{ foo: 'foo', bar: 'BAZ' }, _object.default.create({ foo: 'foo', bar: 'bar' })]); equal(obj.isAny('foo', 'foo'), true, 'isAny(foo)'); equal(obj.isAny('bar', 'bar'), true, 'isAny(bar)'); equal(obj.isAny('bar', 'BIFF'), false, 'isAny(BIFF)'); }); suite.test('should return true of any property is true', function () { var obj = this.newObject([{ foo: 'foo', bar: true }, _object.default.create({ foo: 'bar', bar: false })]); // different values - all eval to true equal(obj.isAny('foo'), true, 'isAny(foo)'); equal(obj.isAny('bar'), true, 'isAny(bar)'); equal(obj.isAny('BIFF'), false, 'isAny(biff)'); }); suite.test('should return true if any property matches null', function () { var obj = this.newObject([{ foo: null, bar: 'bar' }, _object.default.create({ foo: 'foo', bar: null })]); equal(obj.isAny('foo', null), true, 'isAny(\'foo\', null)'); equal(obj.isAny('bar', null), true, 'isAny(\'bar\', null)'); }); suite.test('should return true if any property is undefined', function () { var obj = this.newObject([{ foo: undefined, bar: 'bar' }, _object.default.create({ foo: 'foo' })]); equal(obj.isAny('foo', undefined), true, 'isAny(\'foo\', undefined)'); equal(obj.isAny('bar', undefined), true, 'isAny(\'bar\', undefined)'); }); suite.test('should not match undefined properties without second argument', function () { var obj = this.newObject([{ foo: undefined }, _object.default.create({})]); equal(obj.isAny('foo'), false, 'isAny(\'foo\', undefined)'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/lastObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('lastObject'); suite.test('returns last item in enumerable', function () { var obj = this.newObject(); var ary = this.toArray(obj); equal((0, _emberMetal.get)(obj, 'lastObject'), ary[ary.length - 1]); }); suite.test('returns undefined if enumerable is empty', function () { var obj = this.newObject([]); equal((0, _emberMetal.get)(obj, 'lastObject'), undefined); }); suite.test('can not be set', function () { var obj = this.newObject(); var ary = this.toArray(obj); equal((0, _emberMetal.get)(obj, 'lastObject'), ary[ary.length - 1]); throws(function () { (0, _emberMetal.set)(obj, 'lastObject', 'foo!'); }, /Cannot set read-only property "lastObject" on object/); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/map', ['exports', 'ember-utils', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _emberUtils, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('map'); var mapFunc = function (item) { return item ? item.toString() : null; }; suite.test('map should iterate over list', function () { var obj = this.newObject(); var ary = this.toArray(obj).map(mapFunc); var found = []; found = obj.map(mapFunc); deepEqual(found, ary, 'mapped arrays should match'); }); suite.test('map should iterate over list after mutation', function () { if ((0, _emberMetal.get)(this, 'canTestMutation')) { expect(0); return; } var obj = this.newObject(); var ary = this.toArray(obj).map(mapFunc); var found = void 0; found = obj.map(mapFunc); deepEqual(found, ary, 'items passed during forEach should match'); this.mutate(obj); ary = this.toArray(obj).map(mapFunc); found = obj.map(mapFunc); deepEqual(found, ary, 'items passed during forEach should match'); }); suite.test('2nd target parameter', function () { var _this = this; var obj = this.newObject(); var target = this; obj.map(function () { // ES6TODO: When transpiled we will end up with "use strict" which disables automatically binding to the global context. // Therefore, the following test can never pass in strict mode unless we modify the `map` function implementation to // use `Ember.lookup` if target is not specified. // // equal(guidFor(this), guidFor(global), 'should pass the global object as this if no context'); }); obj.map(function () { equal((0, _emberUtils.guidFor)(_this), (0, _emberUtils.guidFor)(target), 'should pass target as this if context'); }, target); }); suite.test('callback params', function () { var obj = this.newObject(); var ary = this.toArray(obj); var loc = 0; obj.map(function (item, idx, enumerable) { equal(item, ary[loc], 'item param'); equal(idx, loc, 'idx param'); equal((0, _emberUtils.guidFor)(enumerable), (0, _emberUtils.guidFor)(obj), 'enumerable param'); loc++; }); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/mapBy', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('mapBy'); suite.test('get value of each property', function () { var obj = this.newObject([{ a: 1 }, { a: 2 }]); equal(obj.mapBy('a').join(''), '12'); }); suite.test('should work also through getEach alias', function () { var obj = this.newObject([{ a: 1 }, { a: 2 }]); equal(obj.getEach('a').join(''), '12'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/reduce', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('reduce'); suite.test('collects a summary value from an enumeration', function () { var obj = this.newObject([1, 2, 3]); var res = obj.reduce(function (previousValue, item) { return previousValue + item; }, 0); equal(res, 6); }); suite.test('passes index of item to callback', function () { var obj = this.newObject([1, 2, 3]); var res = obj.reduce(function (previousValue, item, index) { return previousValue + index; }, 0); equal(res, 3); }); suite.test('passes enumerable object to callback', function () { var obj = this.newObject([1, 2, 3]); var res = obj.reduce(function (previousValue, item, index, enumerable) { return enumerable; }, 0); equal(res, obj); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/reject', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); // .......................................................... // reject() // suite.module('reject'); suite.test('should reject any item that does not meet the condition', function () { var obj = this.newObject([1, 2, 3, 4]); var result = void 0; result = obj.reject(function (i) { return i < 3; }); deepEqual(result, [3, 4], 'reject the correct items'); }); suite.test('should be the inverse of filter', function () { var obj = this.newObject([1, 2, 3, 4]); var isEven = function (i) { return i % 2 === 0; }; var filtered = void 0, rejected = void 0; filtered = obj.filter(isEven); rejected = obj.reject(isEven); deepEqual(filtered, [2, 4], 'filtered evens'); deepEqual(rejected, [1, 3], 'rejected evens'); }); // .......................................................... // rejectBy() // suite.module('rejectBy'); suite.test('should reject based on object', function () { var obj = void 0, ary = void 0; ary = [{ foo: 'foo', bar: 'BAZ' }, _object.default.create({ foo: 'foo', bar: 'bar' })]; obj = this.newObject(ary); deepEqual(obj.rejectBy('foo', 'foo'), [], 'rejectBy(foo)'); deepEqual(obj.rejectBy('bar', 'bar'), [ary[0]], 'rejectBy(bar)'); }); suite.test('should include in result if property is false', function () { var obj = void 0, ary = void 0; ary = [{ foo: false, bar: true }, _object.default.create({ foo: false, bar: false })]; obj = this.newObject(ary); deepEqual(obj.rejectBy('foo'), ary, 'rejectBy(foo)'); deepEqual(obj.rejectBy('bar'), [ary[1]], 'rejectBy(bar)'); }); suite.test('should reject on second argument if provided', function () { var obj = void 0, ary = void 0; ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 2 }), { name: 'obj3', foo: 2 }, _object.default.create({ name: 'obj4', foo: 3 })]; obj = this.newObject(ary); deepEqual(obj.rejectBy('foo', 3), [ary[1], ary[2]], 'rejectBy(\'foo\', 3)\')'); }); suite.test('should correctly reject null second argument', function () { var obj = void 0, ary = void 0; ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: null }), { name: 'obj3', foo: null }, _object.default.create({ name: 'obj4', foo: 3 })]; obj = this.newObject(ary); deepEqual(obj.rejectBy('foo', null), [ary[0], ary[3]], 'rejectBy(\'foo\', null)\')'); }); suite.test('should correctly reject undefined second argument', function () { var obj = void 0, ary = void 0; ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 2 })]; obj = this.newObject(ary); deepEqual(obj.rejectBy('bar', undefined), [], 'rejectBy(\'bar\', undefined)\')'); }); suite.test('should correctly reject explicit undefined second argument', function () { var obj = void 0, ary = void 0; ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 3 }), { name: 'obj3', foo: undefined }, _object.default.create({ name: 'obj4', foo: undefined }), { name: 'obj5' }, _object.default.create({ name: 'obj6' })]; obj = this.newObject(ary); deepEqual(obj.rejectBy('foo', undefined), ary.slice(0, 2), 'rejectBy(\'foo\', undefined)\')'); }); suite.test('should match undefined, null, or false properties without second argument', function () { var obj = void 0, ary = void 0; ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 3 }), { name: 'obj3', foo: undefined }, _object.default.create({ name: 'obj4', foo: undefined }), { name: 'obj5' }, _object.default.create({ name: 'obj6' }), { name: 'obj7', foo: null }, _object.default.create({ name: 'obj8', foo: null }), { name: 'obj9', foo: false }, _object.default.create({ name: 'obj10', foo: false })]; obj = this.newObject(ary); deepEqual(obj.rejectBy('foo'), ary.slice(2), 'rejectBy(\'foo\')\')'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/sortBy', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('sortBy'); suite.test('sort by value of property', function () { var obj = this.newObject([{ a: 2 }, { a: 1 }]); var sorted = obj.sortBy('a'); equal((0, _emberMetal.get)(sorted[0], 'a'), 1); equal((0, _emberMetal.get)(sorted[1], 'a'), 2); }); suite.test('supports multiple propertyNames', function () { var obj = this.newObject([{ a: 1, b: 2 }, { a: 1, b: 1 }]); var sorted = obj.sortBy('a', 'b'); equal((0, _emberMetal.get)(sorted[0], 'b'), 1); equal((0, _emberMetal.get)(sorted[1], 'b'), 2); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/toArray', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('toArray'); suite.test('toArray should convert to an array', function () { var obj = this.newObject(); deepEqual(obj.toArray(), this.toArray(obj)); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/uniq', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('uniq'); suite.test('should return new instance with duplicates removed', function () { var before = void 0, after = void 0, obj = void 0, ret = void 0; after = this.newFixture(3); before = [after[0], after[1], after[2], after[1], after[0]]; obj = this.newObject(before); before = obj.toArray(); // in case of set before will be different... ret = obj.uniq(); deepEqual(this.toArray(ret), after, 'should have removed item'); deepEqual(this.toArray(obj), before, 'should not have changed original'); }); suite.test('should return duplicate of same content if no duplicates found', function () { var obj = void 0, ret = void 0; obj = this.newObject(this.newFixture(3)); ret = obj.uniq(void 0); ok(ret !== obj, 'should not be same object'); deepEqual(this.toArray(ret), this.toArray(obj), 'should be the same content'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/uniqBy', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('uniqBy'); suite.test('should return new instance with duplicates removed', function () { var numbers = this.newObject([{ id: 1, value: 'one' }, { id: 2, value: 'two' }, { id: 1, value: 'one' }]); deepEqual(numbers.uniqBy('id'), [{ id: 1, value: 'one' }, { id: 2, value: 'two' }]); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/enumerable/without', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('without'); suite.test('should return new instance with item removed', function () { var before = void 0, after = void 0, obj = void 0, ret = void 0; before = this.newFixture(3); after = [before[0], before[2]]; obj = this.newObject(before); ret = obj.without(before[1]); deepEqual(this.toArray(ret), after, 'should have removed item'); deepEqual(this.toArray(obj), before, 'should not have changed original'); }); suite.test('should remove NaN value', function () { var before = void 0, after = void 0, obj = void 0, ret = void 0; before = [].concat(this.newFixture(2), [NaN]); after = [before[0], before[1]]; obj = this.newObject(before); ret = obj.without(NaN); deepEqual(this.toArray(ret), after, 'should have removed item'); }); suite.test('should return same instance if object not found', function () { var item = void 0, obj = void 0, ret = void 0; item = this.newFixture(1)[0]; obj = this.newObject(this.newFixture(3)); ret = obj.without(item); equal(ret, obj, 'should be same instance'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array', ['exports', 'ember-runtime/tests/suites/array', 'ember-runtime/tests/suites/mutable_array/insertAt', 'ember-runtime/tests/suites/mutable_array/popObject', 'ember-runtime/tests/suites/mutable_array/pushObject', 'ember-runtime/tests/suites/mutable_array/pushObjects', 'ember-runtime/tests/suites/mutable_array/removeAt', 'ember-runtime/tests/suites/mutable_array/replace', 'ember-runtime/tests/suites/mutable_array/shiftObject', 'ember-runtime/tests/suites/mutable_array/unshiftObject', 'ember-runtime/tests/suites/mutable_array/reverseObjects'], function (exports, _array, _insertAt, _popObject, _pushObject, _pushObjects, _removeAt, _replace, _shiftObject, _unshiftObject, _reverseObjects) { 'use strict'; var MutableArrayTests = _array.ArrayTests.extend(); MutableArrayTests.importModuleTests(_insertAt.default); MutableArrayTests.importModuleTests(_popObject.default); MutableArrayTests.importModuleTests(_pushObject.default); MutableArrayTests.importModuleTests(_pushObjects.default); MutableArrayTests.importModuleTests(_removeAt.default); MutableArrayTests.importModuleTests(_replace.default); MutableArrayTests.importModuleTests(_shiftObject.default); MutableArrayTests.importModuleTests(_unshiftObject.default); MutableArrayTests.importModuleTests(_reverseObjects.default); exports.default = MutableArrayTests; }); enifed('ember-runtime/tests/suites/mutable_array/addObject', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite'], function (exports, _emberMetal, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('addObject'); suite.test('should return receiver', function () { var before = this.newFixture(3); var obj = this.newObject(before); equal(obj.addObject(before[1]), obj, 'should return receiver'); }); suite.test('[A,B].addObject(C) => [A,B,C] + notify', function () { var before = this.newFixture(2); var item = this.newFixture(1)[0]; var after = [before[0], before[1], item]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.addObject(item); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); } }); suite.test('[A,B,C].addObject(A) => [A,B,C] + NO notify', function () { var before = this.newFixture(3); var after = before; var item = before[0]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.addObject(item); // note: item in set deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.validate('[]'), false, 'should NOT have notified []'); equal(observer.validate('@each'), false, 'should NOT have notified @each'); equal(observer.validate('length'), false, 'should NOT have notified length'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); } }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/clear', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite'], function (exports, _emberMetal, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('clear'); suite.test('[].clear() => [] + notify', function () { var after = []; var obj = this.newObject([]); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.clear(), obj, 'return self'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.validate('[]'), false, 'should NOT have notified [] once'); equal(observer.validate('@each'), false, 'should NOT have notified @each once'); equal(observer.validate('length'), false, 'should NOT have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); }); suite.test('[X].clear() => [] + notify', function () { var obj, before, after, observer; before = this.newFixture(1); after = []; obj = this.newObject(before); observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.clear(), obj, 'return self'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/insertAt', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('insertAt'); suite.test('[].insertAt(0, X) => [X] + notify', function () { var after = this.newFixture(1); var obj = this.newObject([]); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.insertAt(0, after[0]); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once'); equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once'); equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once'); equal(observer.timesCalledBefore('firstObject'), 1, 'should have notified firstObject will change once'); equal(observer.timesCalledBefore('lastObject'), 1, 'should have notified lastObject will change once'); equal(observer.timesCalled('[]'), 1, 'should have notified [] did change once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each did change once'); equal(observer.timesCalled('length'), 1, 'should have notified length did change once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject did change once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject did change once'); }); suite.test('[].insertAt(200,X) => OUT_OF_RANGE_EXCEPTION exception', function () { var obj = this.newObject([]); var that = this; throws(function () { return obj.insertAt(200, that.newFixture(1)[0]); }, Error); }); suite.test('[A].insertAt(0, X) => [X,A] + notify', function () { var item = this.newFixture(1)[0]; var before = this.newFixture(1); var after = [item, before[0]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.insertAt(0, item); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once'); equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once'); equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once'); equal(observer.timesCalledBefore('firstObject'), 1, 'should have notified firstObject will change once'); equal(observer.timesCalledBefore('lastObject'), 0, 'should NOT have notified lastObject will change once'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); }); suite.test('[A].insertAt(1, X) => [A,X] + notify', function () { var item = this.newFixture(1)[0]; var before = this.newFixture(1); var after = [before[0], item]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.insertAt(1, item); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once'); equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once'); equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once'); equal(observer.timesCalledBefore('firstObject'), 0, 'should NOT have notified firstObject will change once'); equal(observer.timesCalledBefore('lastObject'), 1, 'should have notified lastObject will change once'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); }); suite.test('[A].insertAt(200,X) => OUT_OF_RANGE exception', function () { var obj = this.newObject(this.newFixture(1)); var that = this; throws(function () { return obj.insertAt(200, that.newFixture(1)[0]); }, Error); }); suite.test('[A,B,C].insertAt(0,X) => [X,A,B,C] + notify', function () { var item = this.newFixture(1)[0]; var before = this.newFixture(3); var after = [item, before[0], before[1], before[2]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.insertAt(0, item); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once'); equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once'); equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once'); equal(observer.timesCalledBefore('firstObject'), 1, 'should have notified firstObject will change once'); equal(observer.timesCalledBefore('lastObject'), 0, 'should NOT have notified lastObject will change once'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); }); suite.test('[A,B,C].insertAt(1,X) => [A,X,B,C] + notify', function () { var item = this.newFixture(1)[0]; var before = this.newFixture(3); var after = [before[0], item, before[1], before[2]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.insertAt(1, item); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once'); equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once'); equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once'); equal(observer.timesCalledBefore('firstObject'), 0, 'should NOT have notified firstObject will change once'); equal(observer.timesCalledBefore('lastObject'), 0, 'should NOT have notified lastObject will change once'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); }); suite.test('[A,B,C].insertAt(3,X) => [A,B,C,X] + notify', function () { var item = this.newFixture(1)[0]; var before = this.newFixture(3); var after = [before[0], before[1], before[2], item]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.insertAt(3, item); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once'); equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once'); equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once'); equal(observer.timesCalledBefore('firstObject'), 0, 'should NOT have notified firstObject will change once'); equal(observer.timesCalledBefore('lastObject'), 1, 'should have notified lastObject will change once'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/popObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('popObject'); suite.test('[].popObject() => [] + returns undefined + NO notify', function () { var obj = this.newObject([]); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.popObject(), undefined, 'popObject results'); deepEqual(this.toArray(obj), [], 'post item results'); equal(observer.validate('[]'), false, 'should NOT have notified []'); equal(observer.validate('@each'), false, 'should NOT have notified @each'); equal(observer.validate('length'), false, 'should NOT have notified length'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); }); suite.test('[X].popObject() => [] + notify', function () { var before = this.newFixture(1); var after = []; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ var ret = obj.popObject(); equal(ret, before[0], 'return object'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); }); suite.test('[A,B,C].popObject() => [A,B] + notify', function () { var before = this.newFixture(3); var after = [before[0], before[1]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ var ret = obj.popObject(); equal(ret, before[2], 'return object'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/pushObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('pushObject'); suite.test('returns pushed object', function () { var exp = this.newFixture(1)[0]; var obj = this.newObject([]); equal(obj.pushObject(exp), exp, 'should return pushed object'); }); suite.test('[].pushObject(X) => [X] + notify', function () { var after = this.newFixture(1); var obj = this.newObject([]); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.pushObject(after[0]); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); }); suite.test('[A,B,C].pushObject(X) => [A,B,C,X] + notify', function () { var before = this.newFixture(3); var item = this.newFixture(1)[0]; var after = [before[0], before[1], before[2], item]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.pushObject(item); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/pushObjects', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('pushObjects'); suite.test('should raise exception if not Ember.Enumerable is passed to pushObjects', function () { var obj = this.newObject([]); throws(function () { return obj.pushObjects('string'); }); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/removeAt', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal', 'ember-runtime/mixins/mutable_array'], function (exports, _suite, _emberMetal, _mutable_array) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('removeAt'); suite.test('removeAt([X], 0) => [] + notify', function () { var before = this.newFixture(1); var after = []; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal((0, _mutable_array.removeAt)(obj, 0), obj, 'return self'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); }); suite.test('removeAt([], 200) => OUT_OF_RANGE_EXCEPTION exception', function () { var obj = this.newObject([]); throws(function () { return (0, _mutable_array.removeAt)(obj, 200); }, Error); }); suite.test('removeAt([A,B], 0) => [B] + notify', function () { var before = this.newFixture(2); var after = [before[1]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal((0, _mutable_array.removeAt)(obj, 0), obj, 'return self'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); }); suite.test('removeAt([A,B], 1) => [A] + notify', function () { var before = this.newFixture(2); var after = [before[0]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal((0, _mutable_array.removeAt)(obj, 1), obj, 'return self'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); }); suite.test('removeAt([A,B,C], 1) => [A,C] + notify', function () { var before = this.newFixture(3); var after = [before[0], before[2]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal((0, _mutable_array.removeAt)(obj, 1), obj, 'return self'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); }); suite.test('removeAt([A,B,C,D], 1,2) => [A,D] + notify', function () { var before = this.newFixture(4); var after = [before[0], before[3]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal((0, _mutable_array.removeAt)(obj, 1, 2), obj, 'return self'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); }); suite.test('[A,B,C,D].removeAt(1,2) => [A,D] + notify', function () { var obj, before, after, observer; before = this.newFixture(4); after = [before[0], before[3]]; obj = this.newObject(before); observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.removeAt(1, 2), obj, 'return self'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/removeObject', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite'], function (exports, _emberMetal, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('removeObject'); suite.test('should return receiver', function () { var before = this.newFixture(3); var obj = this.newObject(before); equal(obj.removeObject(before[1]), obj, 'should return receiver'); }); suite.test('[A,B,C].removeObject(B) => [A,C] + notify', function () { var before = this.newFixture(3); var after = [before[0], before[2]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.removeObject(before[1]); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); } }); suite.test('[A,B,C].removeObject(D) => [A,B,C]', function () { var before = this.newFixture(3); var after = before; var item = this.newFixture(1)[0]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.removeObject(item); // note: item not in set deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.validate('[]'), false, 'should NOT have notified []'); equal(observer.validate('@each'), false, 'should NOT have notified @each'); equal(observer.validate('length'), false, 'should NOT have notified length'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); } }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/replace', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('replace'); suite.test('[].replace(0,0,\'X\') => [\'X\'] + notify', function () { var exp = this.newFixture(1); var obj = this.newObject([]); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.replace(0, 0, exp); deepEqual(this.toArray(obj), exp, 'post item results'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); }); suite.test('[].replace(0,0,"X") => ["X"] + avoid calling objectAt and notifying fistObject/lastObject when not in cache', function () { var obj, exp, observer; var called = 0; exp = this.newFixture(1); obj = this.newObject([]); obj.objectAt = function () { called++; }; observer = this.newObserver(obj, 'firstObject', 'lastObject'); obj.replace(0, 0, exp); equal(called, 0, 'should NOT have called objectAt upon replace when firstObject/lastObject are not cached'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject since not cached'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject since not cached'); }); suite.test('[A,B,C,D].replace(1,2,X) => [A,X,D] + notify', function () { var before = this.newFixture(4); var replace = this.newFixture(1); var after = [before[0], replace[0], before[3]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.replace(1, 2, replace); deepEqual(this.toArray(obj), after, 'post item results'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); }); suite.test('[A,B,C,D].replace(1,2,[X,Y]) => [A,X,Y,D] + notify', function () { var before = this.newFixture(4); var replace = this.newFixture(2); var after = [before[0], replace[0], replace[1], before[3]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.replace(1, 2, replace); deepEqual(this.toArray(obj), after, 'post item results'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.validate('length'), false, 'should NOT have notified length'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); }); suite.test('[A,B].replace(1,0,[X,Y]) => [A,X,Y,B] + notify', function () { var before = this.newFixture(2); var replace = this.newFixture(2); var after = [before[0], replace[0], replace[1], before[1]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.replace(1, 0, replace); deepEqual(this.toArray(obj), after, 'post item results'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); }); suite.test('[A,B,C,D].replace(2,2) => [A,B] + notify', function () { var before = this.newFixture(4); var after = [before[0], before[1]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.replace(2, 2); deepEqual(this.toArray(obj), after, 'post item results'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); }); suite.test('Adding object should notify enumerable observer', function () { var fixtures = this.newFixture(4); var obj = this.newObject(fixtures); var observer = this.newObserver(obj).observeEnumerable(obj); var item = this.newFixture(1)[0]; obj.replace(2, 2, [item]); deepEqual(observer._before, [obj, [fixtures[2], fixtures[3]], 1], 'before'); deepEqual(observer._after, [obj, 2, [item]], 'after'); }); suite.test('Adding object should notify array observer', function () { var fixtures = this.newFixture(4); var obj = this.newObject(fixtures); var observer = this.newObserver(obj).observeArray(obj); var item = this.newFixture(1)[0]; obj.replace(2, 2, [item]); deepEqual(observer._before, [obj, 2, 2, 1], 'before'); deepEqual(observer._after, [obj, 2, 2, 1], 'after'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/reverseObjects', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('reverseObjects'); suite.test('[A,B,C].reverseObjects() => [] + notify', function () { var before = this.newFixture(3); var after = [before[2], before[1], before[0]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.reverseObjects(), obj, 'return self'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 0, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/setObjects', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite'], function (exports, _emberMetal, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('setObjects'); suite.test('[A,B,C].setObjects([]) = > [] + notify', function () { var before = this.newFixture(3); var after = []; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.setObjects(after), obj, 'return self'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); }); suite.test('[A,B,C].setObjects([D, E, F, G]) = > [D, E, F, G] + notify', function () { var before = this.newFixture(3); var after = this.newFixture(4); var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.setObjects(after), obj, 'return self'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/shiftObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('shiftObject'); suite.test('[].shiftObject() => [] + returns undefined + NO notify', function () { var after = []; var obj = this.newObject([]); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.shiftObject(), undefined); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.validate('[]', undefined, 1), false, 'should NOT have notified [] once'); equal(observer.validate('@each', undefined, 1), false, 'should NOT have notified @each once'); equal(observer.validate('length', undefined, 1), false, 'should NOT have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); }); suite.test('[X].shiftObject() => [] + notify', function () { var before = this.newFixture(1); var after = []; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.shiftObject(), before[0], 'should return object'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); }); suite.test('[A,B,C].shiftObject() => [B,C] + notify', function () { var before = this.newFixture(3); var after = [before[1], before[2]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ equal(obj.shiftObject(), before[0], 'should return object'); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/unshiftObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('unshiftObject'); suite.test('returns unshifted object', function () { var obj = this.newObject([]); var item = this.newFixture(1)[0]; equal(obj.unshiftObject(item), item, 'should return unshifted object'); }); suite.test('[].unshiftObject(X) => [X] + notify', function () { var item = this.newFixture(1)[0]; var after = [item]; var obj = this.newObject([]); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObject(item); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); }); suite.test('[A,B,C].unshiftObject(X) => [X,A,B,C] + notify', function () { var before = this.newFixture(3); var item = this.newFixture(1)[0]; var after = [item, before[0], before[1], before[2]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObject(item); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); }); suite.test('[A,B,C].unshiftObject(A) => [A,A,B,C] + notify', function () { var before = this.newFixture(3); var item = before[0]; // note same object as current head. should end up twice var after = [item, before[0], before[1], before[2]]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObject(item); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_array/unshiftObjects', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite'], function (exports, _emberMetal, _suite) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('unshiftObjects'); suite.test('returns receiver', function () { var obj = this.newObject([]); var items = this.newFixture(3); equal(obj.unshiftObjects(items), obj, 'should return receiver'); }); suite.test('[].unshiftObjects([A,B,C]) => [A,B,C] + notify', function () { var items = this.newFixture(3); var obj = this.newObject([]); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObjects(items); deepEqual(this.toArray(obj), items, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), items.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); }); suite.test('[A,B,C].unshiftObjects([X,Y]) => [X,Y,A,B,C] + notify', function () { var before = this.newFixture(3); var items = this.newFixture(2); var after = items.concat(before); var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObjects(items); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); }); suite.test('[A,B,C].unshiftObjects([A,B]) => [A,B,A,B,C] + notify', function () { var before = this.newFixture(3); var items = [before[0], before[1]]; // note same object as current head. should end up twice var after = items.concat(before); var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */ obj.unshiftObjects(items); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('@each'), 0, 'should not have notified @each once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_enumerable', ['exports', 'ember-runtime/tests/suites/enumerable', 'ember-runtime/tests/suites/mutable_enumerable/addObject', 'ember-runtime/tests/suites/mutable_enumerable/removeObject', 'ember-runtime/tests/suites/mutable_enumerable/removeObjects'], function (exports, _enumerable, _addObject, _removeObject, _removeObjects) { 'use strict'; var MutableEnumerableTests = _enumerable.EnumerableTests.extend(); MutableEnumerableTests.importModuleTests(_addObject.default); MutableEnumerableTests.importModuleTests(_removeObject.default); MutableEnumerableTests.importModuleTests(_removeObjects.default); exports.default = MutableEnumerableTests; }); enifed('ember-runtime/tests/suites/mutable_enumerable/addObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('addObject'); suite.test('should return receiver', function () { var before = this.newFixture(3); var obj = this.newObject(before); equal(obj.addObject(before[1]), obj, 'should return receiver'); }); suite.test('[A,B].addObject(C) => [A,B,C] + notify', function () { var before = this.newFixture(2); var item = this.newFixture(1)[0]; var after = [before[0], before[1], item]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); (0, _emberMetal.get)(obj, 'firstObject'); (0, _emberMetal.get)(obj, 'lastObject'); obj.addObject(item); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once'); // This gets called since MutableEnumerable is naive about changes equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once'); } }); suite.test('[A,B,C].addObject(A) => [A,B,C] + NO notify', function () { var before = this.newFixture(3); var after = before; var item = before[0]; var obj = this.newObject(before); var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.addObject(item); // note: item in set deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.validate('[]'), false, 'should NOT have notified []'); equal(observer.validate('length'), false, 'should NOT have notified length'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); } }); suite.test('Adding object should notify enumerable observer', function () { var obj = this.newObject(this.newFixture(3)); var observer = this.newObserver(obj).observeEnumerable(obj); var item = this.newFixture(1)[0]; obj.addObject(item); deepEqual(observer._before, [obj, null, [item]]); deepEqual(observer._after, [obj, null, [item]]); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_enumerable/removeObject', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite', 'ember-runtime/system/native_array'], function (exports, _emberMetal, _suite, _native_array) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('removeObject'); suite.test('should return receiver', function () { var before = this.newFixture(3); var obj = this.newObject(before); equal(obj.removeObject(before[1]), obj, 'should return receiver'); }); suite.test('[A,B,C].removeObject(B) => [A,C] + notify', function () { var before = (0, _native_array.A)(this.newFixture(3)); var after = [before[0], before[2]]; var obj = before; var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObject(before[1]); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); } }); suite.test('[A,B,C].removeObject(D) => [A,B,C]', function () { var before = (0, _native_array.A)(this.newFixture(3)); var after = before; var item = this.newFixture(1)[0]; var obj = before; var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObject(item); // Note: item not in set deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.validate('[]'), false, 'should NOT have notified []'); equal(observer.validate('length'), false, 'should NOT have notified length'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); } }); suite.test('Removing object should notify enumerable observer', function () { var fixtures = this.newFixture(3); var obj = this.newObject(fixtures); var observer = this.newObserver(obj).observeEnumerable(obj); var item = fixtures[1]; obj.removeObject(item); deepEqual(observer._before, [obj, [item], null]); deepEqual(observer._after, [obj, [item], null]); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/mutable_enumerable/removeObjects', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal', 'ember-runtime/system/native_array'], function (exports, _suite, _emberMetal, _native_array) { 'use strict'; var suite = _suite.SuiteModuleBuilder.create(); suite.module('removeObjects'); suite.test('should return receiver', function () { var before = (0, _native_array.A)(this.newFixture(3)); var obj = before; equal(obj.removeObjects(before[1]), obj, 'should return receiver'); }); suite.test('[A,B,C].removeObjects([B]) => [A,C] + notify', function () { var before = (0, _native_array.A)(this.newFixture(3)); var after = [before[0], before[2]]; var obj = before; var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([before[1]]); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); } }); suite.test('[{A},{B},{C}].removeObjects([{B}]) => [{A},{C}] + notify', function () { var before = (0, _native_array.A)(this.newObjectsFixture(3)); var after = [before[0], before[2]]; var obj = before; var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([before[1]]); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); } }); suite.test('[A,B,C].removeObjects([A,B]) => [C] + notify', function () { var before = (0, _native_array.A)(this.newFixture(3)); var after = [before[2]]; var obj = before; var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([before[0], before[1]]); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); } }); suite.test('[{A},{B},{C}].removeObjects([{A},{B}]) => [{C}] + notify', function () { var before = (0, _native_array.A)(this.newObjectsFixture(3)); var after = [before[2]]; var obj = before; var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([before[0], before[1]]); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); } }); suite.test('[A,B,C].removeObjects([A,B,C]) => [] + notify', function () { var before = (0, _native_array.A)(this.newFixture(3)); var after = []; var obj = before; var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([before[0], before[1], before[2]]); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject'); equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject'); } }); suite.test('[{A},{B},{C}].removeObjects([{A},{B},{C}]) => [] + notify', function () { var before = (0, _native_array.A)(this.newObjectsFixture(3)); var after = []; var obj = before; var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects(before); deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.timesCalled('[]'), 1, 'should have notified [] once'); equal(observer.timesCalled('length'), 1, 'should have notified length once'); equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject'); equal(observer.validate('lastObject'), 1, 'should have notified lastObject'); } }); suite.test('[A,B,C].removeObjects([D]) => [A,B,C]', function () { var before = (0, _native_array.A)(this.newFixture(3)); var after = before; var item = this.newFixture(1)[0]; var obj = before; var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject'); obj.getProperties('firstObject', 'lastObject'); // Prime the cache obj.removeObjects([item]); // Note: item not in set deepEqual(this.toArray(obj), after, 'post item results'); equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length'); if (observer.isEnabled) { equal(observer.validate('[]'), false, 'should NOT have notified []'); equal(observer.validate('length'), false, 'should NOT have notified length'); equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject'); equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject'); } }); suite.test('Removing objects should notify enumerable observer', function () { var fixtures = this.newFixture(3); var obj = this.newObject(fixtures); var observer = this.newObserver(obj).observeEnumerable(obj); var item = fixtures[1]; obj.removeObjects([item]); deepEqual(observer._before, [obj, [item], null]); deepEqual(observer._after, [obj, [item], null]); }); exports.default = suite; }); enifed('ember-runtime/tests/suites/suite', ['exports', 'ember-utils', 'ember-runtime/system/object', 'ember-metal'], function (exports, _emberUtils, _object, _emberMetal) { 'use strict'; exports.Suite = exports.SuiteModuleBuilder = undefined; /* @class A Suite can be used to define a reusable set of unit tests that can be applied to any object. Suites are most useful for defining tests that work against a mixin or plugin API. Developers implementing objects that use the mixin or support the API can then run these tests against their own code to verify compliance. To define a suite, you need to define the tests themselves as well as a callback API implementers can use to tie your tests to their specific class. ## Defining a Callback API To define the callback API, just extend this class and add your properties or methods that must be provided. ## Defining Unit Tests To add unit tests, use the suite.module() or suite.test() methods instead of a regular module() or test() method when defining your tests. This will add the tests to the suite. ## Using a Suite To use a Suite to test your own objects, extend the suite subclass and define any required methods. Then call run() on the new subclass. This will create an instance of your class and then defining the unit tests. @extends Ember.Object @private */ var Suite = _object.default.extend({ /* __Required.__ You must implement this method to apply this mixin. Define a name for these tests - all modules are prefixed w/ it. @type String */ name: null, run: function () {} }); Suite.reopenClass({ plan: null, run: function () { var C = this; return new C().run(); }, module: function (desc, opts) { if (!opts) { opts = {}; } var setup = opts.setup; var teardown = opts.teardown; this.reopen({ run: function () { this._super.apply(this, arguments); var title = (0, _emberMetal.get)(this, 'name') + ': ' + desc; var ctx = this; QUnit.module(title, { setup: function () { if (setup) { setup.call(ctx); } }, teardown: function () { if (teardown) { teardown.call(ctx); } } }); } }); }, test: function (name, func) { this.reopen({ run: function () { this._super.apply(this, arguments); var ctx = this; if (!func) { QUnit.test(name); // output warning } else { QUnit.test(name, function () { return func.call(ctx); }); } } }); }, same: function (actual, exp, message) { actual = actual && actual.map ? actual.map(function (x) { return (0, _emberUtils.guidFor)(x); }) : actual; exp = exp && exp.map ? exp.map(function (x) { return (0, _emberUtils.guidFor)(x); }) : exp; return deepEqual(actual, exp, message); }, notest: function () {}, importModuleTests: function (builder) { var _this = this; this.module(builder._module); builder._tests.forEach(function (descAndFunc) { _this.test.apply(_this, descAndFunc); }); } }); var SuiteModuleBuilder = _object.default.extend({ _module: null, _tests: null, init: function () { this._tests = []; }, module: function (name) { this._module = name; }, test: function (name, func) { this._tests.push([name, func]); } }); exports.SuiteModuleBuilder = SuiteModuleBuilder; exports.Suite = Suite; exports.default = Suite; }); enifed('ember-runtime/tests/system/application/base_test', ['ember-runtime/system/namespace', 'ember-runtime/system/application'], function (_namespace, _application) { 'use strict'; QUnit.module('Ember.Application'); QUnit.test('Ember.Application should be a subclass of Ember.Namespace', function () { ok(_namespace.default.detect(_application.default), 'Ember.Application subclass of Ember.Namespace'); }); }); enifed('ember-runtime/tests/system/array_proxy/arranged_content_test', ['ember-metal', 'ember-runtime/system/array_proxy', 'ember-runtime/system/native_array', 'ember-runtime/mixins/array'], function (_emberMetal, _array_proxy, _native_array, _array) { 'use strict'; var array = void 0; QUnit.module('ArrayProxy - arrangedContent', { setup: function () { (0, _emberMetal.run)(function () { array = _array_proxy.default.extend({ arrangedContent: (0, _emberMetal.computed)('content.[]', function () { var content = this.get('content'); return content && (0, _native_array.A)(content.slice().sort(function (a, b) { if (a == null) { a = -1; } if (b == null) { b = -1; } return b - a; })); }) }).create({ content: (0, _native_array.A)([1, 2, 4, 5]) }); }); }, teardown: function () { (0, _emberMetal.run)(function () { return array.destroy(); }); } }); QUnit.test('addObject - adds to end of \'content\' if not present', function () { (0, _emberMetal.run)(function () { return array.addObject(3); }); deepEqual(array.get('content'), [1, 2, 4, 5, 3], 'adds to end of content'); deepEqual(array.get('arrangedContent'), [5, 4, 3, 2, 1], 'arrangedContent stays sorted'); (0, _emberMetal.run)(function () { return array.addObject(1); }); deepEqual(array.get('content'), [1, 2, 4, 5, 3], 'does not add existing number to content'); }); QUnit.test('addObjects - adds to end of \'content\' if not present', function () { (0, _emberMetal.run)(function () { return array.addObjects([1, 3, 6]); }); deepEqual(array.get('content'), [1, 2, 4, 5, 3, 6], 'adds to end of content'); deepEqual(array.get('arrangedContent'), [6, 5, 4, 3, 2, 1], 'arrangedContent stays sorted'); }); QUnit.test('compact - returns arrangedContent without nulls and undefined', function () { (0, _emberMetal.run)(function () { return array.set('content', (0, _native_array.A)([1, 3, null, 2, undefined])); }); deepEqual(array.compact(), [3, 2, 1]); }); QUnit.test('indexOf - returns index of object in arrangedContent', function () { equal(array.indexOf(4), 1, 'returns arranged index'); }); QUnit.test('insertAt - raises, indeterminate behavior', function () { throws(function () { return (0, _emberMetal.run)(function () { return array.insertAt(2, 3); }); }); }); QUnit.test('lastIndexOf - returns last index of object in arrangedContent', function () { (0, _emberMetal.run)(function () { return array.pushObject(4); }); equal(array.lastIndexOf(4), 2, 'returns last arranged index'); }); QUnit.test('nextObject - returns object at index in arrangedContent', function () { equal(array.nextObject(1), 4, 'returns object at index'); }); QUnit.test('objectAt - returns object at index in arrangedContent', function () { equal((0, _array.objectAt)(array, 1), 4, 'returns object at index'); }); // Not sure if we need a specific test for it, since it's internal QUnit.test('objectAtContent - returns object at index in arrangedContent', function () { equal(array.objectAtContent(1), 4, 'returns object at index'); }); QUnit.test('objectsAt - returns objects at indices in arrangedContent', function () { deepEqual(array.objectsAt([0, 2, 4]), [5, 2, undefined], 'returns objects at indices'); }); QUnit.test('popObject - removes last object in arrangedContent', function () { var popped = void 0; (0, _emberMetal.run)(function () { return popped = array.popObject(); }); equal(popped, 1, 'returns last object'); deepEqual(array.get('content'), [2, 4, 5], 'removes from content'); }); QUnit.test('pushObject - adds to end of content even if it already exists', function () { (0, _emberMetal.run)(function () { return array.pushObject(1); }); deepEqual(array.get('content'), [1, 2, 4, 5, 1], 'adds to end of content'); }); QUnit.test('pushObjects - adds multiple to end of content even if it already exists', function () { (0, _emberMetal.run)(function () { return array.pushObjects([1, 2, 4]); }); deepEqual(array.get('content'), [1, 2, 4, 5, 1, 2, 4], 'adds to end of content'); }); QUnit.test('removeAt - removes from index in arrangedContent', function () { (0, _emberMetal.run)(function () { return array.removeAt(1, 2); }); deepEqual(array.get('content'), [1, 5]); }); QUnit.test('removeObject - removes object from content', function () { (0, _emberMetal.run)(function () { return array.removeObject(2); }); deepEqual(array.get('content'), [1, 4, 5]); }); QUnit.test('removeObjects - removes objects from content', function () { (0, _emberMetal.run)(function () { return array.removeObjects([2, 4, 6]); }); deepEqual(array.get('content'), [1, 5]); }); QUnit.test('replace - raises, indeterminate behavior', function () { throws(function () { return (0, _emberMetal.run)(function () { return array.replace(1, 2, [3]); }); }); }); QUnit.test('replaceContent - does a standard array replace on content', function () { (0, _emberMetal.run)(function () { return array.replaceContent(1, 2, [3]); }); deepEqual(array.get('content'), [1, 3, 5]); }); QUnit.test('reverseObjects - raises, use Sortable#sortAscending', function () { throws(function () { return (0, _emberMetal.run)(function () { return array.reverseObjects(); }); }); }); QUnit.test('setObjects - replaces entire content', function () { (0, _emberMetal.run)(function () { return array.setObjects([6, 7, 8]); }); deepEqual(array.get('content'), [6, 7, 8], 'replaces content'); }); QUnit.test('shiftObject - removes from start of arrangedContent', function () { var shifted = (0, _emberMetal.run)(function () { return array.shiftObject(); }); equal(shifted, 5, 'returns first object'); deepEqual(array.get('content'), [1, 2, 4], 'removes object from content'); }); QUnit.test('slice - returns a slice of the arrangedContent', function () { deepEqual(array.slice(1, 3), [4, 2], 'returns sliced arrangedContent'); }); QUnit.test('toArray - returns copy of arrangedContent', function () { deepEqual(array.toArray(), [5, 4, 2, 1]); }); QUnit.test('unshiftObject - adds to start of content', function () { (0, _emberMetal.run)(function () { return array.unshiftObject(6); }); deepEqual(array.get('content'), [6, 1, 2, 4, 5], 'adds to start of content'); }); QUnit.test('unshiftObjects - adds to start of content', function () { (0, _emberMetal.run)(function () { array.unshiftObjects([6, 7]); }); deepEqual(array.get('content'), [6, 7, 1, 2, 4, 5], 'adds to start of content'); }); QUnit.test('without - returns arrangedContent without object', function () { deepEqual(array.without(2), [5, 4, 1], 'returns arranged without object'); }); QUnit.test('lastObject - returns last arranged object', function () { equal(array.get('lastObject'), 1, 'returns last arranged object'); }); QUnit.test('firstObject - returns first arranged object', function () { equal(array.get('firstObject'), 5, 'returns first arranged object'); }); QUnit.module('ArrayProxy - arrangedContent matching content', { setup: function () { (0, _emberMetal.run)(function () { array = _array_proxy.default.create({ content: (0, _native_array.A)([1, 2, 4, 5]) }); }); }, teardown: function () { (0, _emberMetal.run)(function () { array.destroy(); }); } }); QUnit.test('insertAt - inserts object at specified index', function () { (0, _emberMetal.run)(function () { array.insertAt(2, 3); }); deepEqual(array.get('content'), [1, 2, 3, 4, 5]); }); QUnit.test('replace - does a standard array replace', function () { (0, _emberMetal.run)(function () { array.replace(1, 2, [3]); }); deepEqual(array.get('content'), [1, 3, 5]); }); QUnit.test('reverseObjects - reverses content', function () { (0, _emberMetal.run)(function () { array.reverseObjects(); }); deepEqual(array.get('content'), [5, 4, 2, 1]); }); QUnit.module('ArrayProxy - arrangedContent with transforms', { setup: function () { (0, _emberMetal.run)(function () { array = _array_proxy.default.extend({ arrangedContent: (0, _emberMetal.computed)(function () { var content = this.get('content'); return content && (0, _native_array.A)(content.slice().sort(function (a, b) { if (a == null) { a = -1; } if (b == null) { b = -1; } return b - a; })); }).property('content.[]'), objectAtContent: function (idx) { var obj = (0, _array.objectAt)(this.get('arrangedContent'), idx); return obj && obj.toString(); } }).create({ content: (0, _native_array.A)([1, 2, 4, 5]) }); }); }, teardown: function () { (0, _emberMetal.run)(function () { array.destroy(); }); } }); QUnit.test('indexOf - returns index of object in arrangedContent', function () { equal(array.indexOf('4'), 1, 'returns arranged index'); }); QUnit.test('lastIndexOf - returns last index of object in arrangedContent', function () { (0, _emberMetal.run)(function () { array.pushObject(4); }); equal(array.lastIndexOf('4'), 2, 'returns last arranged index'); }); QUnit.test('nextObject - returns object at index in arrangedContent', function () { equal(array.nextObject(1), '4', 'returns object at index'); }); QUnit.test('objectAt - returns object at index in arrangedContent', function () { equal((0, _array.objectAt)(array, 1), '4', 'returns object at index'); }); // Not sure if we need a specific test for it, since it's internal QUnit.test('objectAtContent - returns object at index in arrangedContent', function () { equal(array.objectAtContent(1), '4', 'returns object at index'); }); QUnit.test('objectsAt - returns objects at indices in arrangedContent', function () { deepEqual(array.objectsAt([0, 2, 4]), ['5', '2', undefined], 'returns objects at indices'); }); QUnit.test('popObject - removes last object in arrangedContent', function () { var popped = void 0; (0, _emberMetal.run)(function () { popped = array.popObject(); }); equal(popped, '1', 'returns last object'); deepEqual(array.get('content'), [2, 4, 5], 'removes from content'); }); QUnit.test('removeObject - removes object from content', function () { (0, _emberMetal.run)(function () { array.removeObject('2'); }); deepEqual(array.get('content'), [1, 4, 5]); }); QUnit.test('removeObjects - removes objects from content', function () { (0, _emberMetal.run)(function () { array.removeObjects(['2', '4', '6']); }); deepEqual(array.get('content'), [1, 5]); }); QUnit.test('shiftObject - removes from start of arrangedContent', function () { var shifted = void 0; (0, _emberMetal.run)(function () { shifted = array.shiftObject(); }); equal(shifted, '5', 'returns first object'); deepEqual(array.get('content'), [1, 2, 4], 'removes object from content'); }); QUnit.test('slice - returns a slice of the arrangedContent', function () { deepEqual(array.slice(1, 3), ['4', '2'], 'returns sliced arrangedContent'); }); QUnit.test('toArray - returns copy of arrangedContent', function () { deepEqual(array.toArray(), ['5', '4', '2', '1']); }); QUnit.test('without - returns arrangedContent without object', function () { deepEqual(array.without('2'), ['5', '4', '1'], 'returns arranged without object'); }); QUnit.test('lastObject - returns last arranged object', function () { equal(array.get('lastObject'), '1', 'returns last arranged object'); }); QUnit.test('firstObject - returns first arranged object', function () { equal(array.get('firstObject'), '5', 'returns first arranged object'); }); QUnit.test('arrangedContentArray{Will,Did}Change are called when the arranged content changes', function () { // The behaviour covered by this test may change in the future if we decide // that built-in array methods are not overridable. var willChangeCallCount = 0; var didChangeCallCount = 0; var content = (0, _native_array.A)([1, 2, 3]); _array_proxy.default.extend({ arrangedContentArrayWillChange: function () { willChangeCallCount++; this._super.apply(this, arguments); }, arrangedContentArrayDidChange: function () { didChangeCallCount++; this._super.apply(this, arguments); } }).create({ content: content }); equal(willChangeCallCount, 0); equal(didChangeCallCount, 0); content.pushObject(4); content.pushObject(5); equal(willChangeCallCount, 2); equal(didChangeCallCount, 2); }); }); enifed('ember-runtime/tests/system/array_proxy/content_change_test', ['ember-metal', 'ember-runtime/computed/computed_macros', 'ember-runtime/system/array_proxy', 'ember-runtime/system/native_array'], function (_emberMetal, _computed_macros, _array_proxy, _native_array) { 'use strict'; QUnit.module('ArrayProxy - content change'); QUnit.test('should update length for null content', function () { var proxy = _array_proxy.default.create({ content: (0, _native_array.A)([1, 2, 3]) }); equal(proxy.get('length'), 3, 'precond - length is 3'); proxy.set('content', null); equal(proxy.get('length'), 0, 'length updates'); }); QUnit.test('should update length for null content when there is a computed property watching length', function () { var proxy = _array_proxy.default.extend({ isEmpty: (0, _computed_macros.not)('length') }).create({ content: (0, _native_array.A)([1, 2, 3]) }); equal(proxy.get('length'), 3, 'precond - length is 3'); // Consume computed property that depends on length proxy.get('isEmpty'); // update content proxy.set('content', null); equal(proxy.get('length'), 0, 'length updates'); }); QUnit.test('The `arrangedContentWillChange` method is invoked before `content` is changed.', function () { var callCount = 0; var expectedLength = void 0; var proxy = _array_proxy.default.extend({ arrangedContentWillChange: function () { equal(this.get('arrangedContent.length'), expectedLength, 'hook should be invoked before array has changed'); callCount++; } }).create({ content: (0, _native_array.A)([1, 2, 3]) }); proxy.pushObject(4); equal(callCount, 0, 'pushing content onto the array doesn\'t trigger it'); proxy.get('content').pushObject(5); equal(callCount, 0, 'pushing content onto the content array doesn\'t trigger it'); expectedLength = 5; proxy.set('content', (0, _native_array.A)(['a', 'b'])); equal(callCount, 1, 'replacing the content array triggers the hook'); }); QUnit.test('The `arrangedContentDidChange` method is invoked after `content` is changed.', function () { var callCount = 0; var expectedLength = void 0; var proxy = _array_proxy.default.extend({ arrangedContentDidChange: function () { equal(this.get('arrangedContent.length'), expectedLength, 'hook should be invoked after array has changed'); callCount++; } }).create({ content: (0, _native_array.A)([1, 2, 3]) }); equal(callCount, 0, 'hook is not called after creating the object'); proxy.pushObject(4); equal(callCount, 0, 'pushing content onto the array doesn\'t trigger it'); proxy.get('content').pushObject(5); equal(callCount, 0, 'pushing content onto the content array doesn\'t trigger it'); expectedLength = 2; proxy.set('content', (0, _native_array.A)(['a', 'b'])); equal(callCount, 1, 'replacing the content array triggers the hook'); }); QUnit.test('The ArrayProxy doesn\'t explode when assigned a destroyed object', function () { var proxy1 = _array_proxy.default.create(); var proxy2 = _array_proxy.default.create(); (0, _emberMetal.run)(function () { return proxy1.destroy(); }); (0, _emberMetal.set)(proxy2, 'content', proxy1); ok(true, 'No exception was raised'); }); QUnit.test('arrayContent{Will,Did}Change are called when the content changes', function () { // The behaviour covered by this test may change in the future if we decide // that built-in array methods are not overridable. var willChangeCallCount = 0; var didChangeCallCount = 0; var content = (0, _native_array.A)([1, 2, 3]); _array_proxy.default.extend({ arrayContentWillChange: function () { willChangeCallCount++; this._super.apply(this, arguments); }, arrayContentDidChange: function () { didChangeCallCount++; this._super.apply(this, arguments); } }).create({ content: content }); equal(willChangeCallCount, 0); equal(didChangeCallCount, 0); content.pushObject(4); content.pushObject(5); equal(willChangeCallCount, 2); equal(didChangeCallCount, 2); }); }); enifed('ember-runtime/tests/system/array_proxy/content_update_test', ['ember-metal', 'ember-runtime/system/array_proxy', 'ember-runtime/system/native_array'], function (_emberMetal, _array_proxy, _native_array) { 'use strict'; QUnit.module('Ember.ArrayProxy - content update'); QUnit.test('The `contentArrayDidChange` method is invoked after `content` is updated.', function () { var observerCalled = false; var proxy = _array_proxy.default.extend({ arrangedContent: (0, _emberMetal.computed)('content', function () { return (0, _native_array.A)(this.get('content').slice()); }), contentArrayDidChange: function (array, idx, removedCount, addedCount) { observerCalled = true; return this._super(array, idx, removedCount, addedCount); } }).create({ content: (0, _native_array.A)() }); proxy.pushObject(1); ok(observerCalled, 'contentArrayDidChange is invoked'); }); }); enifed('ember-runtime/tests/system/array_proxy/length_test', ['ember-runtime/system/array_proxy', 'ember-runtime/system/object', 'ember-metal', 'ember-runtime/system/native_array'], function (_array_proxy, _object, _emberMetal, _native_array) { 'use strict'; QUnit.module('Ember.ArrayProxy - content change (length)'); QUnit.test('array proxy + aliasedProperty complex test', function () { var aCalled = void 0, bCalled = void 0, cCalled = void 0, dCalled = void 0, eCalled = void 0; aCalled = bCalled = cCalled = dCalled = eCalled = 0; var obj = _object.default.extend({ colors: _emberMetal.computed.reads('model'), length: _emberMetal.computed.reads('colors.length'), a: (0, _emberMetal.observer)('length', function () { return aCalled++; }), b: (0, _emberMetal.observer)('colors.length', function () { return bCalled++; }), c: (0, _emberMetal.observer)('colors.content.length', function () { return cCalled++; }), d: (0, _emberMetal.observer)('colors.[]', function () { return dCalled++; }), e: (0, _emberMetal.observer)('colors.content.[]', function () { return eCalled++; }) }).create(); obj.set('model', _array_proxy.default.create({ content: (0, _native_array.A)(['red', 'yellow', 'blue']) })); equal(obj.get('colors.content.length'), 3); equal(obj.get('colors.length'), 3); equal(obj.get('length'), 3); equal(aCalled, 1, 'expected observer `length` to be called ONCE'); equal(bCalled, 1, 'expected observer `colors.length` to be called ONCE'); equal(cCalled, 1, 'expected observer `colors.content.length` to be called ONCE'); equal(dCalled, 1, 'expected observer `colors.[]` to be called ONCE'); equal(eCalled, 1, 'expected observer `colors.content.[]` to be called ONCE'); obj.get('colors').pushObjects(['green', 'red']); equal(obj.get('colors.content.length'), 5); equal(obj.get('colors.length'), 5); equal(obj.get('length'), 5); equal(aCalled, 2, 'expected observer `length` to be called TWICE'); equal(bCalled, 2, 'expected observer `colors.length` to be called TWICE'); equal(cCalled, 2, 'expected observer `colors.content.length` to be called TWICE'); equal(dCalled, 2, 'expected observer `colors.[]` to be called TWICE'); equal(eCalled, 2, 'expected observer `colors.content.[]` to be called TWICE'); }); }); enifed('ember-runtime/tests/system/array_proxy/suite_test', ['ember-runtime/tests/suites/mutable_array', 'ember-runtime/system/array_proxy', 'ember-metal', 'ember-runtime/system/native_array'], function (_mutable_array, _array_proxy, _emberMetal, _native_array) { 'use strict'; _mutable_array.default.extend({ name: 'Ember.ArrayProxy', newObject: function (ary) { var ret = ary ? ary.slice() : this.newFixture(3); return _array_proxy.default.create({ content: (0, _native_array.A)(ret) }); }, mutate: function (obj) { obj.pushObject((0, _emberMetal.get)(obj, 'length') + 1); }, toArray: function (obj) { return obj.toArray ? obj.toArray() : obj.slice(); } }).run(); }); enifed('ember-runtime/tests/system/array_proxy/watching_and_listening_test', ['ember-metal', 'ember-runtime/system/array_proxy', 'ember-runtime/system/native_array'], function (_emberMetal, _array_proxy, _native_array) { 'use strict'; function sortedListenersFor(obj, eventName) { return (0, _emberMetal.listenersFor)(obj, eventName).sort(function (listener1, listener2) { return listener1[1] > listener2[1] ? -1 : 1; }); } QUnit.module('ArrayProxy - watching and listening'); QUnit.test('setting \'content\' adds listeners correctly', function () { var content = (0, _native_array.A)(); var proxy = _array_proxy.default.create(); deepEqual(sortedListenersFor(content, '@array:before'), []); deepEqual(sortedListenersFor(content, '@array:change'), []); proxy.set('content', content); deepEqual(sortedListenersFor(content, '@array:before'), [[proxy, 'contentArrayWillChange'], [proxy, 'arrangedContentArrayWillChange']]); deepEqual(sortedListenersFor(content, '@array:change'), [[proxy, 'contentArrayDidChange'], [proxy, 'arrangedContentArrayDidChange']]); }); QUnit.test('changing \'content\' adds and removes listeners correctly', function () { var content1 = (0, _native_array.A)(); var content2 = (0, _native_array.A)(); var proxy = _array_proxy.default.create({ content: content1 }); deepEqual(sortedListenersFor(content1, '@array:before'), [[proxy, 'contentArrayWillChange'], [proxy, 'arrangedContentArrayWillChange']]); deepEqual(sortedListenersFor(content1, '@array:change'), [[proxy, 'contentArrayDidChange'], [proxy, 'arrangedContentArrayDidChange']]); proxy.set('content', content2); deepEqual(sortedListenersFor(content1, '@array:before'), []); deepEqual(sortedListenersFor(content1, '@array:change'), []); deepEqual(sortedListenersFor(content2, '@array:before'), [[proxy, 'contentArrayWillChange'], [proxy, 'arrangedContentArrayWillChange']]); deepEqual(sortedListenersFor(content2, '@array:change'), [[proxy, 'contentArrayDidChange'], [proxy, 'arrangedContentArrayDidChange']]); }); QUnit.test('regression test for https://github.com/emberjs/ember.js/issues/12475', function () { var item1a = { id: 1 }; var item1b = { id: 2 }; var item1c = { id: 3 }; var content1 = (0, _native_array.A)([item1a, item1b, item1c]); var proxy = _array_proxy.default.create({ content: content1 }); var obj = { proxy: proxy }; (0, _emberMetal.defineProperty)(obj, 'ids', (0, _emberMetal.computed)('proxy.@each.id', function () { return (0, _emberMetal.get)(this, 'proxy').mapBy('id'); })); // These manually added observers are to simulate the observers added by the // rendering process in a template like: // // {{#each items as |item|}} // {{item.id}} // {{/each}} (0, _emberMetal.addObserver)(item1a, 'id', function () {}); (0, _emberMetal.addObserver)(item1b, 'id', function () {}); (0, _emberMetal.addObserver)(item1c, 'id', function () {}); // The EachProxy has not yet been consumed. Only the manually added // observers are watching. equal((0, _emberMetal.watcherCount)(item1a, 'id'), 1); equal((0, _emberMetal.watcherCount)(item1b, 'id'), 1); equal((0, _emberMetal.watcherCount)(item1c, 'id'), 1); // Consume the each proxy. This causes the EachProxy to add two observers // per item: one for "before" events and one for "after" events. deepEqual((0, _emberMetal.get)(obj, 'ids'), [1, 2, 3]); // For each item, the two each proxy observers and one manual added observer // are watching. equal((0, _emberMetal.watcherCount)(item1a, 'id'), 3); equal((0, _emberMetal.watcherCount)(item1b, 'id'), 3); equal((0, _emberMetal.watcherCount)(item1c, 'id'), 3); // This should be a no-op because observers do not fire if the value // 1. is an object and 2. is the same as the old value. proxy.set('content', content1); equal((0, _emberMetal.watcherCount)(item1a, 'id'), 3); equal((0, _emberMetal.watcherCount)(item1b, 'id'), 3); equal((0, _emberMetal.watcherCount)(item1c, 'id'), 3); // This is repeated to catch the regression. It should still be a no-op. proxy.set('content', content1); equal((0, _emberMetal.watcherCount)(item1a, 'id'), 3); equal((0, _emberMetal.watcherCount)(item1b, 'id'), 3); equal((0, _emberMetal.watcherCount)(item1c, 'id'), 3); // Set the content to a new array with completely different items and // repeat the process. var item2a = { id: 4 }; var item2b = { id: 5 }; var item2c = { id: 6 }; var content2 = (0, _native_array.A)([item2a, item2b, item2c]); (0, _emberMetal.addObserver)(item2a, 'id', function () {}); (0, _emberMetal.addObserver)(item2b, 'id', function () {}); (0, _emberMetal.addObserver)(item2c, 'id', function () {}); proxy.set('content', content2); deepEqual((0, _emberMetal.get)(obj, 'ids'), [4, 5, 6]); equal((0, _emberMetal.watcherCount)(item2a, 'id'), 3); equal((0, _emberMetal.watcherCount)(item2b, 'id'), 3); equal((0, _emberMetal.watcherCount)(item2c, 'id'), 3); // Ensure that the observers added by the EachProxy on all items in the // first content array have been torn down. equal((0, _emberMetal.watcherCount)(item1a, 'id'), 1); equal((0, _emberMetal.watcherCount)(item1b, 'id'), 1); equal((0, _emberMetal.watcherCount)(item1c, 'id'), 1); proxy.set('content', content2); equal((0, _emberMetal.watcherCount)(item2a, 'id'), 3); equal((0, _emberMetal.watcherCount)(item2b, 'id'), 3); equal((0, _emberMetal.watcherCount)(item2c, 'id'), 3); proxy.set('content', content2); equal((0, _emberMetal.watcherCount)(item2a, 'id'), 3); equal((0, _emberMetal.watcherCount)(item2b, 'id'), 3); equal((0, _emberMetal.watcherCount)(item2c, 'id'), 3); }); }); enifed('ember-runtime/tests/system/core_object_test', ['ember-runtime/system/core_object', 'ember-metal'], function (_core_object, _emberMetal) { 'use strict'; QUnit.module('Ember.CoreObject'); QUnit.test('works with new (one arg)', function () { var obj = new _core_object.default({ firstName: 'Stef', lastName: 'Penner' }); equal(obj.firstName, 'Stef'); equal(obj.lastName, 'Penner'); }); QUnit.test('works with new (> 1 arg)', function () { var obj = new _core_object.default({ firstName: 'Stef', lastName: 'Penner' }, { other: 'name' }); equal(obj.firstName, 'Stef'); equal(obj.lastName, 'Penner'); equal(obj.other, undefined); // doesn't support multiple pojo' to the constructor }); QUnit.test('toString should be not be added as a property when calling toString()', function () { var obj = new _core_object.default({ firstName: 'Foo', lastName: 'Bar' }); obj.toString(); notOk(obj.hasOwnProperty('toString'), 'Calling toString() should not create a toString class property'); }); QUnit.test('[POST_INIT] invoked during construction', function () { var _CoreObject$extend; var callCount = 0; var Obj = _core_object.default.extend((_CoreObject$extend = {}, _CoreObject$extend[_core_object.POST_INIT] = function () { callCount++; }, _CoreObject$extend)); equal(callCount, 0); Obj.create(); equal(callCount, 1); }); QUnit.test('[POST_INIT] invoked before finishChains', function () { var _CoreObject$extend2; var callCount = 0; var Obj = _core_object.default.extend((_CoreObject$extend2 = {}, _CoreObject$extend2[_core_object.POST_INIT] = function () { (0, _emberMetal.set)(this, 'hi', 1); }, _CoreObject$extend2.hiDidChange = (0, _emberMetal.observer)('hi', function () { callCount++; }), _CoreObject$extend2)); equal(callCount, 0); var obj = Obj.create(); equal(callCount, 0); (0, _emberMetal.set)(obj, 'hi', 2); equal(callCount, 1); }); }); enifed('ember-runtime/tests/system/lazy_load_test', ['ember-metal', 'ember-runtime/system/lazy_load'], function (_emberMetal, _lazy_load) { 'use strict'; QUnit.module('Lazy Loading', { teardown: function () { var keys = Object.keys(_lazy_load._loaded), i; for (i = 0; i < keys.length; i++) { delete _lazy_load._loaded[keys[i]]; } } }); QUnit.test('if a load hook is registered, it is executed when runLoadHooks are exected', function () { var count = 0; (0, _emberMetal.run)(function () { (0, _lazy_load.onLoad)('__test_hook__', function (object) { count += object; }); }); (0, _emberMetal.run)(function () { (0, _lazy_load.runLoadHooks)('__test_hook__', 1); }); equal(count, 1, 'the object was passed into the load hook'); }); QUnit.test('if runLoadHooks was already run, it executes newly added hooks immediately', function () { var count = 0; (0, _emberMetal.run)(function () { (0, _lazy_load.onLoad)('__test_hook__', function (object) { return count += object; }); }); (0, _emberMetal.run)(function () { return (0, _lazy_load.runLoadHooks)('__test_hook__', 1); }); count = 0; (0, _emberMetal.run)(function () { (0, _lazy_load.onLoad)('__test_hook__', function (object) { return count += object; }); }); equal(count, 1, 'the original object was passed into the load hook'); }); QUnit.test('hooks in ENV.EMBER_LOAD_HOOKS[\'hookName\'] get executed', function () { // Note that the necessary code to perform this test is run before // the Ember lib is loaded in tests/index.html (0, _emberMetal.run)(function () { (0, _lazy_load.runLoadHooks)('__before_ember_test_hook__', 1); }); equal(window.ENV.__test_hook_count__, 1, 'the object was passed into the load hook'); }); if (typeof window === 'object' && typeof window.dispatchEvent === 'function' && typeof CustomEvent === 'function') { QUnit.test('load hooks trigger a custom event', function () { var eventObject = 'super duper awesome events'; window.addEventListener('__test_hook_for_events__', function (e) { ok(true, 'custom event was fired'); equal(e.detail, eventObject, 'event details are provided properly'); }); (0, _emberMetal.run)(function () { (0, _lazy_load.runLoadHooks)('__test_hook_for_events__', eventObject); }); }); } }); enifed('ember-runtime/tests/system/namespace/base_test', ['ember-environment', 'ember-metal', 'ember-runtime/system/object', 'ember-runtime/system/namespace'], function (_emberEnvironment, _emberMetal, _object, _namespace) { 'use strict'; var originalLookup = _emberEnvironment.context.lookup; var lookup = void 0; QUnit.module('Namespace', { setup: function () { (0, _namespace.setSearchDisabled)(false); lookup = _emberEnvironment.context.lookup = {}; }, teardown: function () { (0, _namespace.setSearchDisabled)(false); for (var prop in lookup) { if (lookup[prop]) { (0, _emberMetal.run)(lookup[prop], 'destroy'); } } _emberEnvironment.context.lookup = originalLookup; } }); QUnit.test('Namespace should be a subclass of EmberObject', function () { ok(_object.default.detect(_namespace.default)); }); QUnit.test('Namespace should be duck typed', function () { ok((0, _emberMetal.get)(_namespace.default.create(), 'isNamespace'), 'isNamespace property is true'); }); QUnit.test('Namespace is found and named', function () { var nsA = lookup.NamespaceA = _namespace.default.create(); equal(nsA.toString(), 'NamespaceA', 'namespaces should have a name if they are on lookup'); var nsB = lookup.NamespaceB = _namespace.default.create(); equal(nsB.toString(), 'NamespaceB', 'namespaces work if created after the first namespace processing pass'); }); QUnit.test('Classes under an Namespace are properly named', function () { var nsA = lookup.NamespaceA = _namespace.default.create(); nsA.Foo = _object.default.extend(); equal(nsA.Foo.toString(), 'NamespaceA.Foo', 'Classes pick up their parent namespace'); nsA.Bar = _object.default.extend(); equal(nsA.Bar.toString(), 'NamespaceA.Bar', 'New Classes get the naming treatment too'); var nsB = lookup.NamespaceB = _namespace.default.create(); nsB.Foo = _object.default.extend(); equal(nsB.Foo.toString(), 'NamespaceB.Foo', 'Classes in new namespaces get the naming treatment'); }); //test("Classes under Ember are properly named", function() { // // ES6TODO: This test does not work reliably when running independent package build with Broccoli config. // Ember.TestObject = EmberObject.extend({}); // equal(Ember.TestObject.toString(), "Ember.TestObject", "class under Ember is given a string representation"); //}); QUnit.test('Lowercase namespaces are no longer supported', function () { var nsC = lookup.namespaceC = _namespace.default.create(); equal(nsC.toString(), undefined); }); QUnit.test('A namespace can be assigned a custom name', function () { var nsA = _namespace.default.create({ name: 'NamespaceA' }); var nsB = lookup.NamespaceB = _namespace.default.create({ name: 'CustomNamespaceB' }); nsA.Foo = _object.default.extend(); nsB.Foo = _object.default.extend(); equal(nsA.Foo.toString(), 'NamespaceA.Foo', 'The namespace\'s name is used when the namespace is not in the lookup object'); equal(nsB.Foo.toString(), 'CustomNamespaceB.Foo', 'The namespace\'s name is used when the namespace is in the lookup object'); }); QUnit.test('Calling namespace.nameClasses() eagerly names all classes', function () { (0, _namespace.setSearchDisabled)(true); var namespace = lookup.NS = _namespace.default.create(); namespace.ClassA = _object.default.extend(); namespace.ClassB = _object.default.extend(); _namespace.default.processAll(); equal(namespace.ClassA.toString(), 'NS.ClassA'); equal(namespace.ClassB.toString(), 'NS.ClassB'); }); QUnit.test('A namespace can be looked up by its name', function () { var NS = lookup.NS = _namespace.default.create(); var UI = lookup.UI = _namespace.default.create(); var CF = lookup.CF = _namespace.default.create(); equal(_namespace.default.byName('NS'), NS); equal(_namespace.default.byName('UI'), UI); equal(_namespace.default.byName('CF'), CF); }); QUnit.test('A nested namespace can be looked up by its name', function () { var UI = lookup.UI = _namespace.default.create(); UI.Nav = _namespace.default.create(); equal(_namespace.default.byName('UI.Nav'), UI.Nav); }); QUnit.test('Destroying a namespace before caching lookup removes it from the list of namespaces', function () { var CF = lookup.CF = _namespace.default.create(); (0, _emberMetal.run)(CF, 'destroy'); equal(_namespace.default.byName('CF'), undefined, 'namespace can not be found after destroyed'); }); QUnit.test('Destroying a namespace after looking up removes it from the list of namespaces', function () { var CF = lookup.CF = _namespace.default.create(); equal(_namespace.default.byName('CF'), CF, 'precondition - namespace can be looked up by name'); (0, _emberMetal.run)(CF, 'destroy'); equal(_namespace.default.byName('CF'), undefined, 'namespace can not be found after destroyed'); }); }); enifed('ember-runtime/tests/system/native_array/a_test', ['ember-runtime/mixins/array', 'ember-runtime/system/native_array'], function (_array, _native_array) { 'use strict'; QUnit.module('Ember.A'); QUnit.test('Ember.A', function () { deepEqual((0, _native_array.A)([1, 2]), [1, 2], 'array values were not be modified'); deepEqual((0, _native_array.A)(), [], 'returned an array with no arguments'); deepEqual((0, _native_array.A)(null), [], 'returned an array with a null argument'); ok(_array.default.detect((0, _native_array.A)()), 'returned an ember array'); ok(_array.default.detect((0, _native_array.A)([1, 2])), 'returned an ember array'); }); }); enifed('ember-runtime/tests/system/native_array/copyable_suite_test', ['ember-utils', 'ember-runtime/system/native_array', 'ember-runtime/tests/suites/copyable'], function (_emberUtils, _native_array, _copyable) { 'use strict'; _copyable.default.extend({ name: 'NativeArray Copyable', newObject: function () { return (0, _native_array.A)([(0, _emberUtils.generateGuid)()]); }, isEqual: function (a, b) { if (!(a instanceof Array)) { return false; } if (!(b instanceof Array)) { return false; } if (a.length !== b.length) { return false; } return a[0] === b[0]; }, shouldBeFreezable: false }).run(); QUnit.module('NativeArray Copyable'); QUnit.test('deep copy is respected', function () { var array = (0, _native_array.A)([{ id: 1 }, { id: 2 }, { id: 3 }]); var copiedArray = array.copy(true); deepEqual(copiedArray, array, 'copied array is equivalent'); ok(copiedArray[0] !== array[0], 'objects inside should be unique'); }); }); enifed('ember-runtime/tests/system/native_array/suite_test', ['ember-runtime/system/native_array', 'ember-runtime/tests/suites/mutable_array'], function (_native_array, _mutable_array) { 'use strict'; _mutable_array.default.extend({ name: 'Native Array', newObject: function (ary) { return (0, _native_array.A)(ary ? ary.slice() : this.newFixture(3)); }, mutate: function (obj) { obj.pushObject(obj.length + 1); }, toArray: function (obj) { return obj.slice(); // make a copy. } }).run(); }); enifed('ember-runtime/tests/system/object/computed_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object'], function (_emberMetal, _internalTestHelpers, _object) { 'use strict'; function K() { return this; } QUnit.module('EmberObject computed property'); (0, _internalTestHelpers.testWithDefault)('computed property on instance', function (get) { var MyClass = _object.default.extend({ foo: (0, _emberMetal.computed)(function () { return 'FOO'; }) }); equal(get(new MyClass(), 'foo'), 'FOO'); }); (0, _internalTestHelpers.testWithDefault)('computed property on subclass', function (get) { var MyClass = _object.default.extend({ foo: (0, _emberMetal.computed)(function () { return 'FOO'; }) }); var Subclass = MyClass.extend({ foo: (0, _emberMetal.computed)(function () { return 'BAR'; }) }); equal(get(new Subclass(), 'foo'), 'BAR'); }); (0, _internalTestHelpers.testWithDefault)('replacing computed property with regular val', function (get) { var MyClass = _object.default.extend({ foo: (0, _emberMetal.computed)(function () { return 'FOO'; }) }); var Subclass = MyClass.extend({ foo: 'BAR' }); equal(get(new Subclass(), 'foo'), 'BAR'); }); (0, _internalTestHelpers.testWithDefault)('complex depndent keys', function (get, set) { var MyClass = _object.default.extend({ init: function () { this._super.apply(this, arguments); set(this, 'bar', { baz: 'BIFF' }); }, count: 0, foo: (0, _emberMetal.computed)(function () { set(this, 'count', get(this, 'count') + 1); return (0, _emberMetal.get)(get(this, 'bar'), 'baz') + ' ' + get(this, 'count'); }).property('bar.baz') }); var Subclass = MyClass.extend({ count: 20 }); var obj1 = new MyClass(); var obj2 = new Subclass(); equal(get(obj1, 'foo'), 'BIFF 1'); equal(get(obj2, 'foo'), 'BIFF 21'); set(get(obj1, 'bar'), 'baz', 'BLARG'); equal(get(obj1, 'foo'), 'BLARG 2'); equal(get(obj2, 'foo'), 'BIFF 21'); set(get(obj2, 'bar'), 'baz', 'BOOM'); equal(get(obj1, 'foo'), 'BLARG 2'); equal(get(obj2, 'foo'), 'BOOM 22'); }); (0, _internalTestHelpers.testWithDefault)('complex dependent keys changing complex dependent keys', function (get, set) { var MyClass = _object.default.extend({ init: function () { this._super.apply(this, arguments); set(this, 'bar', { baz: 'BIFF' }); }, count: 0, foo: (0, _emberMetal.computed)(function () { set(this, 'count', get(this, 'count') + 1); return (0, _emberMetal.get)(get(this, 'bar'), 'baz') + ' ' + get(this, 'count'); }).property('bar.baz') }); var Subclass = MyClass.extend({ init: function () { this._super.apply(this, arguments); set(this, 'bar2', { baz: 'BIFF2' }); }, count: 0, foo: (0, _emberMetal.computed)(function () { set(this, 'count', get(this, 'count') + 1); return (0, _emberMetal.get)(get(this, 'bar2'), 'baz') + ' ' + get(this, 'count'); }).property('bar2.baz') }); var obj2 = new Subclass(); equal(get(obj2, 'foo'), 'BIFF2 1'); set(get(obj2, 'bar'), 'baz', 'BLARG'); equal(get(obj2, 'foo'), 'BIFF2 1', 'should not invalidate property'); set(get(obj2, 'bar2'), 'baz', 'BLARG'); equal(get(obj2, 'foo'), 'BLARG 2', 'should invalidate property'); }); QUnit.test('can retrieve metadata for a computed property', function () { var MyClass = _object.default.extend({ computedProperty: (0, _emberMetal.computed)(function () {}).meta({ key: 'keyValue' }) }); equal((0, _emberMetal.get)(MyClass.metaForProperty('computedProperty'), 'key'), 'keyValue', 'metadata saved on the computed property can be retrieved'); var ClassWithNoMetadata = _object.default.extend({ computedProperty: (0, _emberMetal.computed)(function () {}).volatile(), staticProperty: 12 }); equal(typeof ClassWithNoMetadata.metaForProperty('computedProperty'), 'object', 'returns empty hash if no metadata has been saved'); expectAssertion(function () { ClassWithNoMetadata.metaForProperty('nonexistentProperty'); }, 'metaForProperty() could not find a computed property with key \'nonexistentProperty\'.'); expectAssertion(function () { ClassWithNoMetadata.metaForProperty('staticProperty'); }, 'metaForProperty() could not find a computed property with key \'staticProperty\'.'); }); QUnit.test('can iterate over a list of computed properties for a class', function () { var MyClass = _object.default.extend({ foo: (0, _emberMetal.computed)(function () {}), fooDidChange: (0, _emberMetal.observer)('foo', function () {}), bar: (0, _emberMetal.computed)(function () {}), qux: (0, _emberMetal.alias)('foo') }); var SubClass = MyClass.extend({ baz: (0, _emberMetal.computed)(function () {}) }); SubClass.reopen({ bat: (0, _emberMetal.computed)(function () {}).meta({ iAmBat: true }) }); var list = []; MyClass.eachComputedProperty(function (name) { list.push(name); }); deepEqual(list.sort(), ['bar', 'foo', 'qux'], 'watched and unwatched computed properties are iterated'); list = []; SubClass.eachComputedProperty(function (name, meta) { list.push(name); if (name === 'bat') { deepEqual(meta, { iAmBat: true }); } else { deepEqual(meta, {}); } }); deepEqual(list.sort(), ['bar', 'bat', 'baz', 'foo', 'qux'], 'all inherited properties are included'); }); QUnit.test('list of properties updates when an additional property is added (such cache busting)', function () { var MyClass = _object.default.extend({ foo: (0, _emberMetal.computed)(K), fooDidChange: (0, _emberMetal.observer)('foo', function () {}), bar: (0, _emberMetal.computed)(K) }); var list = []; MyClass.eachComputedProperty(function (name) { list.push(name); }); deepEqual(list.sort(), ['bar', 'foo'].sort(), 'expected two computed properties'); MyClass.reopen({ baz: (0, _emberMetal.computed)(K) }); MyClass.create(); // force apply mixins list = []; MyClass.eachComputedProperty(function (name) { list.push(name); }); deepEqual(list.sort(), ['bar', 'foo', 'baz'].sort(), 'expected three computed properties'); }); QUnit.test('Calling _super in call outside the immediate function of a CP getter works', function () { var MyClass = _object.default.extend({ foo: (0, _emberMetal.computed)(function () { return 'FOO'; }) }); var SubClass = MyClass.extend({ foo: function (callback) { return (0, _emberMetal.computed)(function () { return callback.call(this); }); }(function () { return this._super(); }) }); ok((0, _emberMetal.get)(SubClass.create(), 'foo'), 'FOO', 'super value is fetched'); }); QUnit.test('Calling _super in apply outside the immediate function of a CP getter works', function () { var MyClass = _object.default.extend({ foo: (0, _emberMetal.computed)(function () { return 'FOO'; }) }); var SubClass = MyClass.extend({ foo: function (callback) { return (0, _emberMetal.computed)(function () { return callback.apply(this); }); }(function () { return this._super(); }) }); ok((0, _emberMetal.get)(SubClass.create(), 'foo'), 'FOO', 'super value is fetched'); }); }); enifed('ember-runtime/tests/system/object/create_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) { 'use strict'; QUnit.module('EmberObject.create', {}); QUnit.test('simple properties are set', function () { var o = _object.default.create({ ohai: 'there' }); equal(o.get('ohai'), 'there'); }); QUnit.test('calls computed property setters', function () { var MyClass = _object.default.extend({ foo: (0, _emberMetal.computed)({ get: function () { return 'this is not the value you\'re looking for'; }, set: function (key, value) { return value; } }) }); var o = MyClass.create({ foo: 'bar' }); equal(o.get('foo'), 'bar'); }); QUnit.test('allows bindings to be defined', function () { var obj = void 0; var deprecationMessage = /`Ember.Binding` is deprecated/; expectDeprecation(function () { obj = _object.default.create({ foo: 'foo', barBinding: 'foo' }); }, deprecationMessage); equal(obj.get('bar'), 'foo', 'The binding value is correct'); }); QUnit.test('calls setUnknownProperty if defined', function () { var setUnknownPropertyCalled = false; var MyClass = _object.default.extend({ setUnknownProperty: function () { setUnknownPropertyCalled = true; } }); MyClass.create({ foo: 'bar' }); ok(setUnknownPropertyCalled, 'setUnknownProperty was called'); }); QUnit.test('throws if you try to define a computed property', function () { expectAssertion(function () { _object.default.create({ foo: (0, _emberMetal.computed)(function () {}) }); }, 'Ember.Object.create no longer supports defining computed properties. Define computed properties using extend() or reopen() before calling create().'); }); QUnit.test('throws if you try to call _super in a method', function () { expectAssertion(function () { _object.default.create({ foo: function () { this._super.apply(this, arguments); } }); }, 'Ember.Object.create no longer supports defining methods that call _super.'); }); QUnit.test('throws if you try to \'mixin\' a definition', function () { var myMixin = _emberMetal.Mixin.create({ adder: function (arg1, arg2) { return arg1 + arg2; } }); expectAssertion(function () { _object.default.create(myMixin); }, 'Ember.Object.create no longer supports mixing in other definitions, use .extend & .create separately instead.'); }); // This test is for IE8. QUnit.test('property name is the same as own prototype property', function () { var MyClass = _object.default.extend({ toString: function () { return 'MyClass'; } }); equal(MyClass.create().toString(), 'MyClass', 'should inherit property from the arguments of `EmberObject.create`'); }); QUnit.test('inherits properties from passed in EmberObject', function () { var baseObj = _object.default.create({ foo: 'bar' }); var secondaryObj = _object.default.create(baseObj); equal(secondaryObj.foo, baseObj.foo, 'Em.O.create inherits properties from EmberObject parameter'); }); QUnit.test('throws if you try to pass anything a string as a parameter', function () { throws(function () { return _object.default.create('some-string'); }, 'EmberObject.create only accepts an objects.'); }); QUnit.test('EmberObject.create can take undefined as a parameter', function () { var o = _object.default.create(undefined); deepEqual(_object.default.create(), o); }); QUnit.test('EmberObject.create can take null as a parameter', function () { var o = _object.default.create(null); deepEqual(_object.default.create(), o); }); QUnit.test('EmberObject.create avoids allocating a binding map when not necessary', function () { var o = _object.default.create(); var m = (0, _emberMetal.meta)(o); ok(!m.peekBindings(), 'A binding map is not allocated'); }); }); enifed('ember-runtime/tests/system/object/destroy_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object'], function (_emberMetal, _internalTestHelpers, _object) { 'use strict'; QUnit.module('ember-runtime/system/object/destroy_test'); (0, _internalTestHelpers.testBoth)('should schedule objects to be destroyed at the end of the run loop', function (get) { var obj = _object.default.create(); var meta = void 0; (0, _emberMetal.run)(function () { obj.destroy(); meta = (0, _emberMetal.peekMeta)(obj); ok(meta, 'meta is not destroyed immediately'); ok(get(obj, 'isDestroying'), 'object is marked as destroying immediately'); ok(!get(obj, 'isDestroyed'), 'object is not destroyed immediately'); }); meta = (0, _emberMetal.peekMeta)(obj); ok(get(obj, 'isDestroyed'), 'object is destroyed after run loop finishes'); }); QUnit.test('observers should not fire after an object has been destroyed', function () { var count = 0; var obj = _object.default.extend({ fooDidChange: (0, _emberMetal.observer)('foo', function () { count++; }) }).create(); obj.set('foo', 'bar'); equal(count, 1, 'observer was fired once'); (0, _emberMetal.run)(function () { (0, _emberMetal.beginPropertyChanges)(); obj.set('foo', 'quux'); obj.destroy(); (0, _emberMetal.endPropertyChanges)(); }); equal(count, 1, 'observer was not called after object was destroyed'); }); QUnit.test('destroyed objects should not see each others changes during teardown but a long lived object should', function () { var shouldChange = 0; var shouldNotChange = 0; var objs = {}; var A = _object.default.extend({ objs: objs, isAlive: true, willDestroy: function () { this.set('isAlive', false); }, bDidChange: (0, _emberMetal.observer)('objs.b.isAlive', function () { shouldNotChange++; }), cDidChange: (0, _emberMetal.observer)('objs.c.isAlive', function () { shouldNotChange++; }) }); var B = _object.default.extend({ objs: objs, isAlive: true, willDestroy: function () { this.set('isAlive', false); }, aDidChange: (0, _emberMetal.observer)('objs.a.isAlive', function () { shouldNotChange++; }), cDidChange: (0, _emberMetal.observer)('objs.c.isAlive', function () { shouldNotChange++; }) }); var C = _object.default.extend({ objs: objs, isAlive: true, willDestroy: function () { this.set('isAlive', false); }, aDidChange: (0, _emberMetal.observer)('objs.a.isAlive', function () { shouldNotChange++; }), bDidChange: (0, _emberMetal.observer)('objs.b.isAlive', function () { shouldNotChange++; }) }); var LongLivedObject = _object.default.extend({ objs: objs, isAliveDidChange: (0, _emberMetal.observer)('objs.a.isAlive', function () { shouldChange++; }) }); objs.a = new A(); objs.b = new B(); objs.c = new C(); new LongLivedObject(); (0, _emberMetal.run)(function () { var keys = Object.keys(objs), i; for (i = 0; i < keys.length; i++) { objs[keys[i]].destroy(); } }); equal(shouldNotChange, 0, 'destroyed graph objs should not see change in willDestroy'); equal(shouldChange, 1, 'long lived should see change in willDestroy'); }); QUnit.test('bindings should be synced when are updated in the willDestroy hook', function () { var bar = _object.default.create({ value: false, willDestroy: function () { this.set('value', true); } }); var foo = _object.default.create({ value: null, bar: bar }); (0, _emberMetal.run)(function () { var deprecationMessage = /`Ember.Binding` is deprecated/; expectDeprecation(function () { (0, _emberMetal.bind)(foo, 'value', 'bar.value'); }, deprecationMessage); }); ok(bar.get('value') === false, 'the initial value has been bound'); (0, _emberMetal.run)(function () { return bar.destroy(); }); ok(foo.get('value'), 'foo is synced when the binding is updated in the willDestroy hook'); }); }); enifed('ember-runtime/tests/system/object/detectInstance_test', ['ember-runtime/system/object'], function (_object) { 'use strict'; QUnit.module('system/object/detectInstance'); QUnit.test('detectInstance detects instances correctly', function () { var A = _object.default.extend(); var B = A.extend(); var C = A.extend(); var o = _object.default.create(); var a = A.create(); var b = B.create(); var c = C.create(); ok(_object.default.detectInstance(o), 'o is an instance of EmberObject'); ok(_object.default.detectInstance(a), 'a is an instance of EmberObject'); ok(_object.default.detectInstance(b), 'b is an instance of EmberObject'); ok(_object.default.detectInstance(c), 'c is an instance of EmberObject'); ok(!A.detectInstance(o), 'o is not an instance of A'); ok(A.detectInstance(a), 'a is an instance of A'); ok(A.detectInstance(b), 'b is an instance of A'); ok(A.detectInstance(c), 'c is an instance of A'); ok(!B.detectInstance(o), 'o is not an instance of B'); ok(!B.detectInstance(a), 'a is not an instance of B'); ok(B.detectInstance(b), 'b is an instance of B'); ok(!B.detectInstance(c), 'c is not an instance of B'); ok(!C.detectInstance(o), 'o is not an instance of C'); ok(!C.detectInstance(a), 'a is not an instance of C'); ok(!C.detectInstance(b), 'b is not an instance of C'); ok(C.detectInstance(c), 'c is an instance of C'); }); }); enifed('ember-runtime/tests/system/object/detect_test', ['ember-runtime/system/object'], function (_object) { 'use strict'; QUnit.module('system/object/detect'); QUnit.test('detect detects classes correctly', function () { var A = _object.default.extend(); var B = A.extend(); var C = A.extend(); ok(_object.default.detect(_object.default), 'EmberObject is an EmberObject class'); ok(_object.default.detect(A), 'A is an EmberObject class'); ok(_object.default.detect(B), 'B is an EmberObject class'); ok(_object.default.detect(C), 'C is an EmberObject class'); ok(!A.detect(_object.default), 'EmberObject is not an A class'); ok(A.detect(A), 'A is an A class'); ok(A.detect(B), 'B is an A class'); ok(A.detect(C), 'C is an A class'); ok(!B.detect(_object.default), 'EmberObject is not a B class'); ok(!B.detect(A), 'A is not a B class'); ok(B.detect(B), 'B is a B class'); ok(!B.detect(C), 'C is not a B class'); ok(!C.detect(_object.default), 'EmberObject is not a C class'); ok(!C.detect(A), 'A is not a C class'); ok(!C.detect(B), 'B is not a C class'); ok(C.detect(C), 'C is a C class'); }); }); enifed('ember-runtime/tests/system/object/es-compatibility-test', ['ember-babel', 'ember-runtime/system/object', 'ember-metal'], function (_emberBabel, _object, _emberMetal) { 'use strict'; QUnit.module('EmberObject ES Compatibility'); QUnit.test('extending an Ember.Object', function (assert) { var calls = []; var MyObject = function (_EmberObject) { (0, _emberBabel.inherits)(MyObject, _EmberObject); function MyObject() { calls.push('constructor'); var _this = (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject.apply(this, arguments)); _this.postInitProperty = 'post-init-property'; return _this; } MyObject.prototype.init = function () { var _EmberObject$prototyp; calls.push('init'); (_EmberObject$prototyp = _EmberObject.prototype.init).call.apply(_EmberObject$prototyp, [this].concat(Array.prototype.slice.call(arguments))); this.initProperty = 'init-property'; }; return MyObject; }(_object.default); var myObject = MyObject.create({ passedProperty: 'passed-property' }); assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (create)'); assert.equal(myObject.postInitProperty, 'post-init-property', 'constructor property available on instance (create)'); assert.equal(myObject.initProperty, 'init-property', 'init property available on instance (create)'); assert.equal(myObject.passedProperty, 'passed-property', 'passed property available on instance (create)'); calls = []; myObject = new MyObject({ passedProperty: 'passed-property' }); assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (new)'); assert.equal(myObject.postInitProperty, 'post-init-property', 'constructor property available on instance (new)'); assert.equal(myObject.initProperty, 'init-property', 'init property available on instance (new)'); assert.equal(myObject.passedProperty, 'passed-property', 'passed property available on instance (new)'); }); QUnit.test('using super', function (assert) { var calls = []; var SuperSuperObject = _object.default.extend({ method: function () { calls.push('super-super-method'); } }); var SuperObject = SuperSuperObject.extend({ method: function () { this._super(); calls.push('super-method'); } }); var MyObject = function (_SuperObject) { (0, _emberBabel.inherits)(MyObject, _SuperObject); function MyObject() { return (0, _emberBabel.possibleConstructorReturn)(this, _SuperObject.apply(this, arguments)); } MyObject.prototype.method = function () { _SuperObject.prototype.method.call(this); calls.push('method'); }; return MyObject; }(SuperObject); var myObject = new MyObject(); myObject.method(); assert.deepEqual(calls, ['super-super-method', 'super-method', 'method'], 'chain of prototype methods called with super'); }); QUnit.test('using mixins', function (assert) { var Mixin1 = _emberMetal.Mixin.create({ property1: 'data-1' }); var Mixin2 = _emberMetal.Mixin.create({ property2: 'data-2' }); var MyObject = function (_EmberObject$extend) { (0, _emberBabel.inherits)(MyObject, _EmberObject$extend); function MyObject() { return (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject$extend.apply(this, arguments)); } return MyObject; }(_object.default.extend(Mixin1, Mixin2)); var myObject = new MyObject(); assert.equal(myObject.property1, 'data-1', 'includes the first mixin'); assert.equal(myObject.property2, 'data-2', 'includes the second mixin'); }); QUnit.test('using instanceof', function (assert) { var MyObject = function (_EmberObject2) { (0, _emberBabel.inherits)(MyObject, _EmberObject2); function MyObject() { return (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject2.apply(this, arguments)); } return MyObject; }(_object.default); var myObject1 = MyObject.create(); var myObject2 = new MyObject(); assert.ok(myObject1 instanceof MyObject); assert.ok(myObject1 instanceof _object.default); assert.ok(myObject2 instanceof MyObject); assert.ok(myObject2 instanceof _object.default); }); QUnit.test('extending an ES subclass of EmberObject', function (assert) { var calls = []; var SubEmberObject = function (_EmberObject3) { (0, _emberBabel.inherits)(SubEmberObject, _EmberObject3); function SubEmberObject() { calls.push('constructor'); return (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject3.apply(this, arguments)); } SubEmberObject.prototype.init = function () { var _EmberObject3$prototy; calls.push('init'); (_EmberObject3$prototy = _EmberObject3.prototype.init).call.apply(_EmberObject3$prototy, [this].concat(Array.prototype.slice.call(arguments))); }; return SubEmberObject; }(_object.default); var MyObject = function (_SubEmberObject) { (0, _emberBabel.inherits)(MyObject, _SubEmberObject); function MyObject() { return (0, _emberBabel.possibleConstructorReturn)(this, _SubEmberObject.apply(this, arguments)); } return MyObject; }(SubEmberObject); MyObject.create(); assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (create)'); calls = []; new MyObject(); assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (new)'); }); // TODO: Needs to be fixed. Currently only `init` is called. QUnit.skip('calling extend on an ES subclass of EmberObject', function (assert) { var calls = []; var SubEmberObject = function (_EmberObject4) { (0, _emberBabel.inherits)(SubEmberObject, _EmberObject4); function SubEmberObject() { calls.push('constructor'); return (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject4.apply(this, arguments)); } SubEmberObject.prototype.init = function () { var _EmberObject4$prototy; calls.push('init'); (_EmberObject4$prototy = _EmberObject4.prototype.init).call.apply(_EmberObject4$prototy, [this].concat(Array.prototype.slice.call(arguments))); }; return SubEmberObject; }(_object.default); var MyObject = SubEmberObject.extend({}); MyObject.create(); assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (create)'); calls = []; new MyObject(); assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (new)'); }); }); enifed('ember-runtime/tests/system/object/events_test', ['ember-runtime/system/object', 'ember-runtime/mixins/evented'], function (_object, _evented) { 'use strict'; QUnit.module('Object events'); QUnit.test('a listener can be added to an object', function () { var count = 0; var obj = _object.default.extend(_evented.default).create(); obj.on('event!', function () { count++; }); obj.trigger('event!'); equal(count, 1, 'the event was triggered'); obj.trigger('event!'); equal(count, 2, 'the event was triggered'); }); QUnit.test('a listener can be added and removed automatically the first time it is triggered', function () { var count = 0; var obj = _object.default.extend(_evented.default).create(); obj.one('event!', function () { count++; }); obj.trigger('event!'); equal(count, 1, 'the event was triggered'); obj.trigger('event!'); equal(count, 1, 'the event was not triggered again'); }); QUnit.test('triggering an event can have arguments', function () { var self = void 0, args = void 0; var obj = _object.default.extend(_evented.default).create(); obj.on('event!', function () { args = [].slice.call(arguments); self = this; }); obj.trigger('event!', 'foo', 'bar'); deepEqual(args, ['foo', 'bar']); equal(self, obj); }); QUnit.test('a listener can be added and removed automatically and have arguments', function () { var self = void 0, args = void 0; var count = 0; var obj = _object.default.extend(_evented.default).create(); obj.one('event!', function () { args = [].slice.call(arguments); self = this; count++; }); obj.trigger('event!', 'foo', 'bar'); deepEqual(args, ['foo', 'bar']); equal(self, obj); equal(count, 1, 'the event is triggered once'); obj.trigger('event!', 'baz', 'bat'); deepEqual(args, ['foo', 'bar']); equal(count, 1, 'the event was not triggered again'); equal(self, obj); }); QUnit.test('binding an event can specify a different target', function () { var self = void 0, args = void 0; var obj = _object.default.extend(_evented.default).create(); var target = {}; obj.on('event!', target, function () { args = [].slice.call(arguments); self = this; }); obj.trigger('event!', 'foo', 'bar'); deepEqual(args, ['foo', 'bar']); equal(self, target); }); QUnit.test('a listener registered with one can take method as string and can be added with different target', function () { var count = 0; var target = {}; target.fn = function () { count++; }; var obj = _object.default.extend(_evented.default).create(); obj.one('event!', target, 'fn'); obj.trigger('event!'); equal(count, 1, 'the event was triggered'); obj.trigger('event!'); equal(count, 1, 'the event was not triggered again'); }); QUnit.test('a listener registered with one can be removed with off', function () { var obj = _object.default.extend(_evented.default, { F: function () {} }).create(); var F = function () {}; obj.one('event!', F); obj.one('event!', obj, 'F'); equal(obj.has('event!'), true, 'has events'); obj.off('event!', F); obj.off('event!', obj, 'F'); equal(obj.has('event!'), false, 'has no more events'); }); QUnit.test('adding and removing listeners should be chainable', function () { var obj = _object.default.extend(_evented.default).create(); var F = function () {}; var ret = obj.on('event!', F); equal(ret, obj, '#on returns self'); ret = obj.off('event!', F); equal(ret, obj, '#off returns self'); ret = obj.one('event!', F); equal(ret, obj, '#one returns self'); }); }); enifed('ember-runtime/tests/system/object/extend_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) { 'use strict'; QUnit.module('EmberObject.extend'); QUnit.test('Basic extend', function () { var SomeClass = _object.default.extend({ foo: 'BAR' }); ok(SomeClass.isClass, 'A class has isClass of true'); var obj = new SomeClass(); equal(obj.foo, 'BAR'); }); QUnit.test('Sub-subclass', function () { var SomeClass = _object.default.extend({ foo: 'BAR' }); var AnotherClass = SomeClass.extend({ bar: 'FOO' }); var obj = new AnotherClass(); equal(obj.foo, 'BAR'); equal(obj.bar, 'FOO'); }); QUnit.test('Overriding a method several layers deep', function () { var SomeClass = _object.default.extend({ fooCnt: 0, foo: function () { this.fooCnt++; }, barCnt: 0, bar: function () { this.barCnt++; } }); var AnotherClass = SomeClass.extend({ barCnt: 0, bar: function () { this.barCnt++; this._super.apply(this, arguments); } }); var FinalClass = AnotherClass.extend({ fooCnt: 0, foo: function () { this.fooCnt++; this._super.apply(this, arguments); } }); var obj = new FinalClass(); obj.foo(); obj.bar(); equal(obj.fooCnt, 2, 'should invoke both'); equal(obj.barCnt, 2, 'should invoke both'); // Try overriding on create also obj = FinalClass.extend({ foo: function () { this.fooCnt++; this._super.apply(this, arguments); } }).create(); obj.foo(); obj.bar(); equal(obj.fooCnt, 3, 'should invoke final as well'); equal(obj.barCnt, 2, 'should invoke both'); }); QUnit.test('With concatenatedProperties', function () { var SomeClass = _object.default.extend({ things: 'foo', concatenatedProperties: ['things'] }); var AnotherClass = SomeClass.extend({ things: 'bar' }); var YetAnotherClass = SomeClass.extend({ things: 'baz' }); var some = new SomeClass(); var another = new AnotherClass(); var yetAnother = new YetAnotherClass(); deepEqual(some.get('things'), ['foo'], 'base class should have just its value'); deepEqual(another.get('things'), ['foo', 'bar'], 'subclass should have base class\' and its own'); deepEqual(yetAnother.get('things'), ['foo', 'baz'], 'subclass should have base class\' and its own'); }); QUnit.test('With concatenatedProperties class properties', function () { var SomeClass = _object.default.extend(); SomeClass.reopenClass({ concatenatedProperties: ['things'], things: 'foo' }); var AnotherClass = SomeClass.extend(); AnotherClass.reopenClass({ things: 'bar' }); var YetAnotherClass = SomeClass.extend(); YetAnotherClass.reopenClass({ things: 'baz' }); var some = new SomeClass(); var another = new AnotherClass(); var yetAnother = new YetAnotherClass(); deepEqual((0, _emberMetal.get)(some.constructor, 'things'), ['foo'], 'base class should have just its value'); deepEqual((0, _emberMetal.get)(another.constructor, 'things'), ['foo', 'bar'], 'subclass should have base class\' and its own'); deepEqual((0, _emberMetal.get)(yetAnother.constructor, 'things'), ['foo', 'baz'], 'subclass should have base class\' and its own'); }); }); enifed('ember-runtime/tests/system/object/observer_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object'], function (_emberMetal, _internalTestHelpers, _object) { 'use strict'; QUnit.module('EmberObject observer'); (0, _internalTestHelpers.testBoth)('observer on class', function (get, set) { var MyClass = _object.default.extend({ count: 0, foo: (0, _emberMetal.observer)('bar', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj = new MyClass(); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('observer on subclass', function (get, set) { var MyClass = _object.default.extend({ count: 0, foo: (0, _emberMetal.observer)('bar', function () { set(this, 'count', get(this, 'count') + 1); }) }); var Subclass = MyClass.extend({ foo: (0, _emberMetal.observer)('baz', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj = new Subclass(); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); equal(get(obj, 'count'), 0, 'should not invoke observer after change'); set(obj, 'baz', 'BAZ'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('observer on instance', function (get, set) { var obj = _object.default.extend({ foo: (0, _emberMetal.observer)('bar', function () { set(this, 'count', get(this, 'count') + 1); }) }).create({ count: 0 }); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('observer on instance overriding class', function (get, set) { var MyClass = _object.default.extend({ count: 0, foo: (0, _emberMetal.observer)('bar', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj = MyClass.extend({ foo: (0, _emberMetal.observer)('baz', function () { // <-- change property we observe set(this, 'count', get(this, 'count') + 1); }) }).create(); equal(get(obj, 'count'), 0, 'should not invoke observer immediately'); set(obj, 'bar', 'BAZ'); equal(get(obj, 'count'), 0, 'should not invoke observer after change'); set(obj, 'baz', 'BAZ'); equal(get(obj, 'count'), 1, 'should invoke observer after change'); }); (0, _internalTestHelpers.testBoth)('observer should not fire after being destroyed', function (get, set) { var obj = _object.default.extend({ count: 0, foo: (0, _emberMetal.observer)('bar', function () { set(this, 'count', get(this, 'count') + 1); }) }).create(); equal(get(obj, 'count'), 0, 'precond - should not invoke observer immediately'); (0, _emberMetal.run)(function () { return obj.destroy(); }); expectAssertion(function () { set(obj, 'bar', 'BAZ'); }, 'calling set on destroyed object: ' + obj + '.bar = BAZ'); equal(get(obj, 'count'), 0, 'should not invoke observer after change'); }); // .......................................................... // COMPLEX PROPERTIES // (0, _internalTestHelpers.testBoth)('chain observer on class', function (get, set) { var MyClass = _object.default.extend({ count: 0, foo: (0, _emberMetal.observer)('bar.baz', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj1 = MyClass.create({ bar: { baz: 'biff' } }); var obj2 = MyClass.create({ bar: { baz: 'biff2' } }); equal(get(obj1, 'count'), 0, 'should not invoke yet'); equal(get(obj2, 'count'), 0, 'should not invoke yet'); set(get(obj1, 'bar'), 'baz', 'BIFF1'); equal(get(obj1, 'count'), 1, 'should invoke observer on obj1'); equal(get(obj2, 'count'), 0, 'should not invoke yet'); set(get(obj2, 'bar'), 'baz', 'BIFF2'); equal(get(obj1, 'count'), 1, 'should not invoke again'); equal(get(obj2, 'count'), 1, 'should invoke observer on obj2'); }); (0, _internalTestHelpers.testBoth)('chain observer on class', function (get, set) { var MyClass = _object.default.extend({ count: 0, foo: (0, _emberMetal.observer)('bar.baz', function () { set(this, 'count', get(this, 'count') + 1); }) }); var obj1 = MyClass.extend().create({ bar: { baz: 'biff' } }); var obj2 = MyClass.extend({ foo: (0, _emberMetal.observer)('bar2.baz', function () { set(this, 'count', get(this, 'count') + 1); }) }).create({ bar: { baz: 'biff2' }, bar2: { baz: 'biff3' } }); equal(get(obj1, 'count'), 0, 'should not invoke yet'); equal(get(obj2, 'count'), 0, 'should not invoke yet'); set(get(obj1, 'bar'), 'baz', 'BIFF1'); equal(get(obj1, 'count'), 1, 'should invoke observer on obj1'); equal(get(obj2, 'count'), 0, 'should not invoke yet'); set(get(obj2, 'bar'), 'baz', 'BIFF2'); equal(get(obj1, 'count'), 1, 'should not invoke again'); equal(get(obj2, 'count'), 0, 'should not invoke yet'); set(get(obj2, 'bar2'), 'baz', 'BIFF3'); equal(get(obj1, 'count'), 1, 'should not invoke again'); equal(get(obj2, 'count'), 1, 'should invoke observer on obj2'); }); (0, _internalTestHelpers.testBoth)('chain observer on class that has a reference to an uninitialized object will finish chains that reference it', function () { var changed = false; var ChildClass = _object.default.extend({ parent: null, parentOneTwoDidChange: (0, _emberMetal.observer)('parent.one.two', function () { changed = true; }) }); var ParentClass = _object.default.extend({ one: { two: 'old' }, init: function () { this.child = ChildClass.create({ parent: this }); } }); var parent = new ParentClass(); equal(changed, false, 'precond'); parent.set('one.two', 'new'); equal(changed, true, 'child should have been notified of change to path'); parent.set('one', { two: 'newer' }); equal(changed, true, 'child should have been notified of change to path'); }); }); enifed('ember-runtime/tests/system/object/reopenClass_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) { 'use strict'; QUnit.module('system/object/reopenClass'); QUnit.test('adds new properties to subclass', function () { var Subclass = _object.default.extend(); Subclass.reopenClass({ foo: function () { return 'FOO'; }, bar: 'BAR' }); equal(Subclass.foo(), 'FOO', 'Adds method'); equal((0, _emberMetal.get)(Subclass, 'bar'), 'BAR', 'Adds property'); }); QUnit.test('class properties inherited by subclasses', function () { var Subclass = _object.default.extend(); Subclass.reopenClass({ foo: function () { return 'FOO'; }, bar: 'BAR' }); var SubSub = Subclass.extend(); equal(SubSub.foo(), 'FOO', 'Adds method'); equal((0, _emberMetal.get)(SubSub, 'bar'), 'BAR', 'Adds property'); }); }); enifed('ember-runtime/tests/system/object/reopen_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) { 'use strict'; QUnit.module('system/core_object/reopen'); QUnit.test('adds new properties to subclass instance', function () { var Subclass = _object.default.extend(); Subclass.reopen({ foo: function () { return 'FOO'; }, bar: 'BAR' }); equal(new Subclass().foo(), 'FOO', 'Adds method'); equal((0, _emberMetal.get)(new Subclass(), 'bar'), 'BAR', 'Adds property'); }); QUnit.test('reopened properties inherited by subclasses', function () { var Subclass = _object.default.extend(); var SubSub = Subclass.extend(); Subclass.reopen({ foo: function () { return 'FOO'; }, bar: 'BAR' }); equal(new SubSub().foo(), 'FOO', 'Adds method'); equal((0, _emberMetal.get)(new SubSub(), 'bar'), 'BAR', 'Adds property'); }); QUnit.test('allows reopening already instantiated classes', function () { var Subclass = _object.default.extend(); Subclass.create(); Subclass.reopen({ trololol: true }); equal(Subclass.create().get('trololol'), true, 'reopen works'); }); }); enifed('ember-runtime/tests/system/object/strict-mode-test', ['ember-runtime/system/object'], function (_object) { 'use strict'; QUnit.module('strict mode tests'); QUnit.test('__superWrapper does not throw errors in strict mode', function () { var Foo = _object.default.extend({ blah: function () { return 'foo'; } }); var Bar = Foo.extend({ blah: function () { return 'bar'; }, callBlah: function () { var blah = this.blah; return blah(); } }); var bar = Bar.create(); equal(bar.callBlah(), 'bar', 'can call local function without call/apply'); }); }); enifed('ember-runtime/tests/system/object/subclasses_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) { 'use strict'; QUnit.module('system/object/subclasses'); QUnit.test('chains should copy forward to subclasses when prototype created', function () { var ObjectWithChains = void 0, objWithChains = void 0, SubWithChains = void 0, SubSub = void 0, subSub = void 0; (0, _emberMetal.run)(function () { ObjectWithChains = _object.default.extend({ obj: { a: 'a', hi: 'hi' }, aBinding: 'obj.a' // add chain }); var deprecationMessage = /`Ember.Binding` is deprecated/; expectDeprecation(function () { // realize prototype objWithChains = ObjectWithChains.create(); }, deprecationMessage); // should not copy chains from parent yet SubWithChains = ObjectWithChains.extend({ hiBinding: 'obj.hi', // add chain hello: (0, _emberMetal.computed)(function () { return this.get('obj.hi') + ' world'; }).property('hi'), // observe chain greetingBinding: 'hello' }); SubSub = SubWithChains.extend(); expectDeprecation(function () { // should realize prototypes and copy forward chains subSub = SubSub.create(); }, deprecationMessage); }); equal(subSub.get('greeting'), 'hi world'); (0, _emberMetal.run)(function () { return objWithChains.set('obj.hi', 'hello'); }); equal(subSub.get('greeting'), 'hello world'); }); }); enifed('ember-runtime/tests/system/object/toString_test', ['ember-utils', 'ember-environment', 'ember-runtime/system/object', 'ember-runtime/system/namespace'], function (_emberUtils, _emberEnvironment, _object, _namespace) { 'use strict'; var originalLookup = _emberEnvironment.context.lookup; var lookup = void 0; QUnit.module('system/object/toString', { setup: function () { _emberEnvironment.context.lookup = lookup = {}; }, teardown: function () { _emberEnvironment.context.lookup = originalLookup; } }); QUnit.test('NAME_KEY slot is present on Class', function () { ok(_object.default.extend().hasOwnProperty(_emberUtils.NAME_KEY), 'Ember Class\'s have a NAME_KEY slot'); }); QUnit.test('toString() returns the same value if called twice', function () { var Foo = _namespace.default.create(); Foo.toString = function () { return 'Foo'; }; Foo.Bar = _object.default.extend(); equal(Foo.Bar.toString(), 'Foo.Bar'); equal(Foo.Bar.toString(), 'Foo.Bar'); var obj = Foo.Bar.create(); equal(obj.toString(), ''); equal(obj.toString(), ''); equal(Foo.Bar.toString(), 'Foo.Bar'); }); QUnit.test('toString on a class returns a useful value when nested in a namespace', function () { var obj = void 0; var Foo = _namespace.default.create(); Foo.toString = function () { return 'Foo'; }; Foo.Bar = _object.default.extend(); equal(Foo.Bar.toString(), 'Foo.Bar'); obj = Foo.Bar.create(); equal(obj.toString(), ''); Foo.Baz = Foo.Bar.extend(); equal(Foo.Baz.toString(), 'Foo.Baz'); obj = Foo.Baz.create(); equal(obj.toString(), ''); obj = Foo.Bar.create(); equal(obj.toString(), ''); }); QUnit.test('toString on a namespace finds the namespace in lookup', function () { var Foo = lookup.Foo = _namespace.default.create(); equal(Foo.toString(), 'Foo'); }); QUnit.test('toString on a namespace finds the namespace in lookup', function () { var Foo = lookup.Foo = _namespace.default.create(); var obj = void 0; Foo.Bar = _object.default.extend(); equal(Foo.Bar.toString(), 'Foo.Bar'); obj = Foo.Bar.create(); equal(obj.toString(), ''); }); QUnit.test('toString on a namespace falls back to modulePrefix, if defined', function () { var Foo = _namespace.default.create({ modulePrefix: 'foo' }); equal(Foo.toString(), 'foo'); }); QUnit.test('toString includes toStringExtension if defined', function () { var Foo = _object.default.extend({ toStringExtension: function () { return 'fooey'; } }); var foo = Foo.create(); var Bar = _object.default.extend({}); var bar = Bar.create(); // simulate these classes being defined on a Namespace Foo[_emberUtils.NAME_KEY] = 'Foo'; Bar[_emberUtils.NAME_KEY] = 'Bar'; equal(bar.toString(), '', 'does not include toStringExtension part'); equal(foo.toString(), '', 'Includes toStringExtension result'); }); }); enifed('ember-runtime/tests/system/object_proxy_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object_proxy'], function (_emberMetal, _internalTestHelpers, _object_proxy) { 'use strict'; QUnit.module('ObjectProxy'); (0, _internalTestHelpers.testBoth)('should not proxy properties passed to create', function (get) { var Proxy = _object_proxy.default.extend({ cp: (0, _emberMetal.computed)({ get: function () { return this._cp; }, set: function (key, value) { this._cp = value; return this._cp; } }) }); var proxy = Proxy.create({ prop: 'Foo', cp: 'Bar' }); equal(get(proxy, 'prop'), 'Foo', 'should not have tried to proxy set'); equal(proxy._cp, 'Bar', 'should use CP setter'); }); (0, _internalTestHelpers.testBoth)('should proxy properties to content', function (get, set) { var content = { firstName: 'Tom', lastName: 'Dale', unknownProperty: function (key) { return key + ' unknown'; } }; var proxy = _object_proxy.default.create(); equal(get(proxy, 'firstName'), undefined, 'get on proxy without content should return undefined'); expectAssertion(function () { set(proxy, 'firstName', 'Foo'); }, /Cannot delegate set\('firstName', Foo\) to the 'content'/i); set(proxy, 'content', content); equal(get(proxy, 'firstName'), 'Tom', 'get on proxy with content should forward to content'); equal(get(proxy, 'lastName'), 'Dale', 'get on proxy with content should forward to content'); equal(get(proxy, 'foo'), 'foo unknown', 'get on proxy with content should forward to content'); set(proxy, 'lastName', 'Huda'); equal(get(content, 'lastName'), 'Huda', 'content should have new value from set on proxy'); equal(get(proxy, 'lastName'), 'Huda', 'proxy should have new value from set on proxy'); set(proxy, 'content', { firstName: 'Yehuda', lastName: 'Katz' }); equal(get(proxy, 'firstName'), 'Yehuda', 'proxy should reflect updated content'); equal(get(proxy, 'lastName'), 'Katz', 'proxy should reflect updated content'); }); (0, _internalTestHelpers.testBoth)('should work with watched properties', function (get, set) { var content1 = { firstName: 'Tom', lastName: 'Dale' }; var content2 = { firstName: 'Yehuda', lastName: 'Katz' }; var count = 0; var last = void 0; var Proxy = _object_proxy.default.extend({ fullName: (0, _emberMetal.computed)(function () { var firstName = this.get('firstName'); var lastName = this.get('lastName'); if (firstName && lastName) { return firstName + ' ' + lastName; } return firstName || lastName; }).property('firstName', 'lastName') }); var proxy = Proxy.create(); (0, _emberMetal.addObserver)(proxy, 'fullName', function () { last = get(proxy, 'fullName'); count++; }); // proxy without content returns undefined equal(get(proxy, 'fullName'), undefined); // setting content causes all watched properties to change set(proxy, 'content', content1); // both dependent keys changed equal(count, 2); equal(last, 'Tom Dale'); // setting property in content causes proxy property to change set(content1, 'lastName', 'Huda'); equal(count, 3); equal(last, 'Tom Huda'); // replacing content causes all watched properties to change set(proxy, 'content', content2); // both dependent keys changed equal(count, 5); equal(last, 'Yehuda Katz'); // content1 is no longer watched ok(!(0, _emberMetal.isWatching)(content1, 'firstName'), 'not watching firstName'); ok(!(0, _emberMetal.isWatching)(content1, 'lastName'), 'not watching lastName'); // setting property in new content set(content2, 'firstName', 'Tomhuda'); equal(last, 'Tomhuda Katz'); equal(count, 6); // setting property in proxy syncs with new content set(proxy, 'lastName', 'Katzdale'); equal(count, 7); equal(last, 'Tomhuda Katzdale'); equal(get(content2, 'firstName'), 'Tomhuda'); equal(get(content2, 'lastName'), 'Katzdale'); }); QUnit.test('set and get should work with paths', function () { var proxy = _object_proxy.default.create({ content: { foo: { bar: 'baz' } } }); var count = 0; proxy.set('foo.bar', 'hello'); equal(proxy.get('foo.bar'), 'hello'); equal(proxy.get('content.foo.bar'), 'hello'); proxy.addObserver('foo.bar', function () { count++; }); proxy.set('foo.bar', 'bye'); equal(count, 1); equal(proxy.get('foo.bar'), 'bye'); equal(proxy.get('content.foo.bar'), 'bye'); }); (0, _internalTestHelpers.testBoth)('should transition between watched and unwatched strategies', function (get, set) { var content = { foo: 'foo' }; var proxy = _object_proxy.default.create({ content: content }); var count = 0; function observer() { count++; } equal(get(proxy, 'foo'), 'foo'); set(content, 'foo', 'bar'); equal(get(proxy, 'foo'), 'bar'); set(proxy, 'foo', 'foo'); equal(get(content, 'foo'), 'foo'); equal(get(proxy, 'foo'), 'foo'); (0, _emberMetal.addObserver)(proxy, 'foo', observer); equal(count, 0); equal(get(proxy, 'foo'), 'foo'); set(content, 'foo', 'bar'); equal(count, 1); equal(get(proxy, 'foo'), 'bar'); set(proxy, 'foo', 'foo'); equal(count, 2); equal(get(content, 'foo'), 'foo'); equal(get(proxy, 'foo'), 'foo'); (0, _emberMetal.removeObserver)(proxy, 'foo', observer); set(content, 'foo', 'bar'); equal(get(proxy, 'foo'), 'bar'); set(proxy, 'foo', 'foo'); equal(get(content, 'foo'), 'foo'); equal(get(proxy, 'foo'), 'foo'); }); (0, _internalTestHelpers.testBoth)('setting `undefined` to a proxied content property should override its existing value', function (get, set) { var proxyObject = _object_proxy.default.create({ content: { prop: 'emberjs' } }); set(proxyObject, 'prop', undefined); equal(get(proxyObject, 'prop'), undefined, 'sets the `undefined` value to the proxied content'); }); }); enifed('ember-runtime/tests/system/string/camelize_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) { 'use strict'; QUnit.module('EmberStringUtils.camelize'); if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { QUnit.test('String.prototype.camelize is not modified without EXTEND_PROTOTYPES', function () { ok('undefined' === typeof String.prototype.camelize, 'String.prototype helper disabled'); }); } QUnit.test('camelize normal string', function () { deepEqual((0, _string.camelize)('my favorite items'), 'myFavoriteItems'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('my favorite items'.camelize(), 'myFavoriteItems'); } }); QUnit.test('camelize capitalized string', function () { deepEqual((0, _string.camelize)('I Love Ramen'), 'iLoveRamen'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('I Love Ramen'.camelize(), 'iLoveRamen'); } }); QUnit.test('camelize dasherized string', function () { deepEqual((0, _string.camelize)('css-class-name'), 'cssClassName'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('css-class-name'.camelize(), 'cssClassName'); } }); QUnit.test('camelize underscored string', function () { deepEqual((0, _string.camelize)('action_name'), 'actionName'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('action_name'.camelize(), 'actionName'); } }); QUnit.test('camelize dot notation string', function () { deepEqual((0, _string.camelize)('action.name'), 'actionName'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('action.name'.camelize(), 'actionName'); } }); QUnit.test('does nothing with camelcased string', function () { deepEqual((0, _string.camelize)('innerHTML'), 'innerHTML'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('innerHTML'.camelize(), 'innerHTML'); } }); QUnit.test('camelize namespaced classified string', function () { deepEqual((0, _string.camelize)('PrivateDocs/OwnerInvoice'), 'privateDocs/ownerInvoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('PrivateDocs/OwnerInvoice'.camelize(), 'privateDocs/ownerInvoice'); } }); QUnit.test('camelize namespaced underscored string', function () { deepEqual((0, _string.camelize)('private_docs/owner_invoice'), 'privateDocs/ownerInvoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('private_docs/owner_invoice'.camelize(), 'privateDocs/ownerInvoice'); } }); QUnit.test('camelize namespaced dasherized string', function () { deepEqual((0, _string.camelize)('private-docs/owner-invoice'), 'privateDocs/ownerInvoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('private-docs/owner-invoice'.camelize(), 'privateDocs/ownerInvoice'); } }); }); enifed('ember-runtime/tests/system/string/capitalize_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) { 'use strict'; QUnit.module('EmberStringUtils.capitalize'); if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { QUnit.test('String.prototype.capitalize is not modified without EXTEND_PROTOTYPES', function () { ok('undefined' === typeof String.prototype.capitalize, 'String.prototype helper disabled'); }); } QUnit.test('capitalize normal string', function () { deepEqual((0, _string.capitalize)('my favorite items'), 'My favorite items'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('my favorite items'.capitalize(), 'My favorite items'); } }); QUnit.test('capitalize dasherized string', function () { deepEqual((0, _string.capitalize)('css-class-name'), 'Css-class-name'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('css-class-name'.capitalize(), 'Css-class-name'); } }); QUnit.test('capitalize underscored string', function () { deepEqual((0, _string.capitalize)('action_name'), 'Action_name'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('action_name'.capitalize(), 'Action_name'); } }); QUnit.test('capitalize camelcased string', function () { deepEqual((0, _string.capitalize)('innerHTML'), 'InnerHTML'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('innerHTML'.capitalize(), 'InnerHTML'); } }); QUnit.test('does nothing with capitalized string', function () { deepEqual((0, _string.capitalize)('Capitalized string'), 'Capitalized string'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('Capitalized string'.capitalize(), 'Capitalized string'); } }); QUnit.test('capitalize namespaced camelized string', function () { deepEqual((0, _string.capitalize)('privateDocs/ownerInvoice'), 'PrivateDocs/OwnerInvoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('privateDocs/ownerInvoice'.capitalize(), 'PrivateDocs/OwnerInvoice'); } }); QUnit.test('capitalize namespaced underscored string', function () { deepEqual((0, _string.capitalize)('private_docs/owner_invoice'), 'Private_docs/Owner_invoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('private_docs/owner_invoice'.capitalize(), 'Private_docs/Owner_invoice'); } }); QUnit.test('capitalize namespaced dasherized string', function () { deepEqual((0, _string.capitalize)('private-docs/owner-invoice'), 'Private-docs/Owner-invoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('private-docs/owner-invoice'.capitalize(), 'Private-docs/Owner-invoice'); } }); }); enifed('ember-runtime/tests/system/string/classify_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) { 'use strict'; QUnit.module('EmberStringUtils.classify'); if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { QUnit.test('String.prototype.classify is not modified without EXTEND_PROTOTYPES', function () { ok('undefined' === typeof String.prototype.classify, 'String.prototype helper disabled'); }); } function test(given, expected, description) { QUnit.test(description, function () { deepEqual((0, _string.classify)(given), expected); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual(given.classify(), expected); } }); } test('my favorite items', 'MyFavoriteItems', 'classify normal string'); test('css-class-name', 'CssClassName', 'classify dasherized string'); test('action_name', 'ActionName', 'classify underscored string'); test('privateDocs/ownerInvoice', 'PrivateDocs/OwnerInvoice', 'classify namespaced camelized string'); test('private_docs/owner_invoice', 'PrivateDocs/OwnerInvoice', 'classify namespaced underscored string'); test('private-docs/owner-invoice', 'PrivateDocs/OwnerInvoice', 'classify namespaced dasherized string'); test('-view-registry', '_ViewRegistry', 'classify prefixed dasherized string'); test('components/-text-field', 'Components/_TextField', 'classify namespaced prefixed dasherized string'); test('_Foo_Bar', '_FooBar', 'classify underscore-prefixed underscored string'); test('_Foo-Bar', '_FooBar', 'classify underscore-prefixed dasherized string'); test('_foo/_bar', '_Foo/_Bar', 'classify underscore-prefixed-namespaced underscore-prefixed string'); test('-foo/_bar', '_Foo/_Bar', 'classify dash-prefixed-namespaced underscore-prefixed string'); test('-foo/-bar', '_Foo/_Bar', 'classify dash-prefixed-namespaced dash-prefixed string'); test('InnerHTML', 'InnerHTML', 'does nothing with classified string'); test('_FooBar', '_FooBar', 'does nothing with classified prefixed string'); }); enifed('ember-runtime/tests/system/string/dasherize_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) { 'use strict'; QUnit.module('EmberStringUtils.dasherize'); if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { QUnit.test('String.prototype.dasherize is not modified without EXTEND_PROTOTYPES', function () { ok('undefined' === typeof String.prototype.dasherize, 'String.prototype helper disabled'); }); } QUnit.test('dasherize normal string', function () { deepEqual((0, _string.dasherize)('my favorite items'), 'my-favorite-items'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('my favorite items'.dasherize(), 'my-favorite-items'); } }); QUnit.test('does nothing with dasherized string', function () { deepEqual((0, _string.dasherize)('css-class-name'), 'css-class-name'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('css-class-name'.dasherize(), 'css-class-name'); } }); QUnit.test('dasherize underscored string', function () { deepEqual((0, _string.dasherize)('action_name'), 'action-name'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('action_name'.dasherize(), 'action-name'); } }); QUnit.test('dasherize camelcased string', function () { deepEqual((0, _string.dasherize)('innerHTML'), 'inner-html'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('innerHTML'.dasherize(), 'inner-html'); } }); QUnit.test('dasherize string that is the property name of Object.prototype', function () { deepEqual((0, _string.dasherize)('toString'), 'to-string'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('toString'.dasherize(), 'to-string'); } }); QUnit.test('dasherize namespaced classified string', function () { deepEqual((0, _string.dasherize)('PrivateDocs/OwnerInvoice'), 'private-docs/owner-invoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('PrivateDocs/OwnerInvoice'.dasherize(), 'private-docs/owner-invoice'); } }); QUnit.test('dasherize namespaced camelized string', function () { deepEqual((0, _string.dasherize)('privateDocs/ownerInvoice'), 'private-docs/owner-invoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('privateDocs/ownerInvoice'.dasherize(), 'private-docs/owner-invoice'); } }); QUnit.test('dasherize namespaced underscored string', function () { deepEqual((0, _string.dasherize)('private_docs/owner_invoice'), 'private-docs/owner-invoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('private_docs/owner_invoice'.dasherize(), 'private-docs/owner-invoice'); } }); }); enifed('ember-runtime/tests/system/string/decamelize_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) { 'use strict'; QUnit.module('EmberStringUtils.decamelize'); if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { QUnit.test('String.prototype.decamelize is not modified without EXTEND_PROTOTYPES', function () { ok('undefined' === typeof String.prototype.decamelize, 'String.prototype helper disabled'); }); } QUnit.test('does nothing with normal string', function () { deepEqual((0, _string.decamelize)('my favorite items'), 'my favorite items'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('my favorite items'.decamelize(), 'my favorite items'); } }); QUnit.test('does nothing with dasherized string', function () { deepEqual((0, _string.decamelize)('css-class-name'), 'css-class-name'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('css-class-name'.decamelize(), 'css-class-name'); } }); QUnit.test('does nothing with underscored string', function () { deepEqual((0, _string.decamelize)('action_name'), 'action_name'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('action_name'.decamelize(), 'action_name'); } }); QUnit.test('converts a camelized string into all lower case separated by underscores.', function () { deepEqual((0, _string.decamelize)('innerHTML'), 'inner_html'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('innerHTML'.decamelize(), 'inner_html'); } }); QUnit.test('decamelizes strings with numbers', function () { deepEqual((0, _string.decamelize)('size160Url'), 'size160_url'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('size160Url'.decamelize(), 'size160_url'); } }); QUnit.test('decamelize namespaced classified string', function () { deepEqual((0, _string.decamelize)('PrivateDocs/OwnerInvoice'), 'private_docs/owner_invoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('PrivateDocs/OwnerInvoice'.decamelize(), 'private_docs/owner_invoice'); } }); QUnit.test('decamelize namespaced camelized string', function () { deepEqual((0, _string.decamelize)('privateDocs/ownerInvoice'), 'private_docs/owner_invoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('privateDocs/ownerInvoice'.decamelize(), 'private_docs/owner_invoice'); } }); }); enifed('ember-runtime/tests/system/string/fmt_string_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) { 'use strict'; QUnit.module('EmberStringUtils.fmt'); if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { QUnit.test('String.prototype.fmt is not modified without EXTEND_PROTOTYPES', function () { ok('undefined' === typeof String.prototype.fmt, 'String.prototype helper disabled'); }); } QUnit.test('\'Hello %@ %@\'.fmt(\'John\', \'Doe\') => \'Hello John Doe\'', function () { expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.'); equal((0, _string.fmt)('Hello %@ %@', ['John', 'Doe']), 'Hello John Doe'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { equal('Hello %@ %@'.fmt('John', 'Doe'), 'Hello John Doe'); } }); QUnit.test('\'Hello %@2 %@1\'.fmt(\'John\', \'Doe\') => \'Hello Doe John\'', function () { expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.'); equal((0, _string.fmt)('Hello %@2 %@1', ['John', 'Doe']), 'Hello Doe John'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { equal('Hello %@2 %@1'.fmt('John', 'Doe'), 'Hello Doe John'); } }); QUnit.test('\'%@08 %@07 %@06 %@05 %@04 %@03 %@02 %@01\'.fmt(\'One\', \'Two\', \'Three\', \'Four\', \'Five\', \'Six\', \'Seven\', \'Eight\') => \'Eight Seven Six Five Four Three Two One\'', function () { expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.'); equal((0, _string.fmt)('%@08 %@07 %@06 %@05 %@04 %@03 %@02 %@01', ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']), 'Eight Seven Six Five Four Three Two One'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { equal('%@08 %@07 %@06 %@05 %@04 %@03 %@02 %@01'.fmt('One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight'), 'Eight Seven Six Five Four Three Two One'); } }); QUnit.test('\'data: %@\'.fmt({ id: 3 }) => \'data: {id: 3}\'', function () { expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.'); equal((0, _string.fmt)('data: %@', [{ id: 3 }]), 'data: {id: 3}'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { equal('data: %@'.fmt({ id: 3 }), 'data: {id: 3}'); } }); QUnit.test('works with argument form', function () { expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.'); equal((0, _string.fmt)('%@', 'John'), 'John'); equal((0, _string.fmt)('%@ %@', ['John'], 'Doe'), '[John] Doe'); }); }); enifed('ember-runtime/tests/system/string/loc_test', ['ember-metal', 'ember-environment', 'ember-runtime/system/string'], function (_emberMetal, _emberEnvironment, _string) { 'use strict'; // ES6TODO Ember.STRINGS var oldString = void 0; QUnit.module('EmberStringUtils.loc', { setup: function () { oldString = _emberMetal.default.STRINGS; _emberMetal.default.STRINGS = { '_Hello World': 'Bonjour le monde', '_Hello %@': 'Bonjour %@', '_Hello %@ %@': 'Bonjour %@ %@', '_Hello %@# %@#': 'Bonjour %@2 %@1' }; }, teardown: function () { _emberMetal.default.STRINGS = oldString; } }); if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { QUnit.test('String.prototype.loc is not available without EXTEND_PROTOTYPES', function () { ok('undefined' === typeof String.prototype.loc, 'String.prototype helper disabled'); }); } QUnit.test('\'_Hello World\'.loc() => \'Bonjour le monde\'', function () { equal((0, _string.loc)('_Hello World'), 'Bonjour le monde'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { equal('_Hello World'.loc(), 'Bonjour le monde'); } }); QUnit.test('\'_Hello %@ %@\'.loc(\'John\', \'Doe\') => \'Bonjour John Doe\'', function () { equal((0, _string.loc)('_Hello %@ %@', ['John', 'Doe']), 'Bonjour John Doe'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { equal('_Hello %@ %@'.loc('John', 'Doe'), 'Bonjour John Doe'); } }); QUnit.test('\'_Hello %@# %@#\'.loc(\'John\', \'Doe\') => \'Bonjour Doe John\'', function () { equal((0, _string.loc)('_Hello %@# %@#', ['John', 'Doe']), 'Bonjour Doe John'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { equal('_Hello %@# %@#'.loc('John', 'Doe'), 'Bonjour Doe John'); } }); QUnit.test('\'_Not In Strings\'.loc() => \'_Not In Strings\'', function () { equal((0, _string.loc)('_Not In Strings'), '_Not In Strings'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { equal('_Not In Strings'.loc(), '_Not In Strings'); } }); QUnit.test('works with argument form', function () { equal((0, _string.loc)('_Hello %@', 'John'), 'Bonjour John'); equal((0, _string.loc)('_Hello %@ %@', ['John'], 'Doe'), 'Bonjour [John] Doe'); }); }); enifed('ember-runtime/tests/system/string/underscore_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) { 'use strict'; QUnit.module('EmberStringUtils.underscore'); if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { QUnit.test('String.prototype.underscore is not available without EXTEND_PROTOTYPES', function () { ok('undefined' === typeof String.prototype.underscore, 'String.prototype helper disabled'); }); } QUnit.test('with normal string', function () { deepEqual((0, _string.underscore)('my favorite items'), 'my_favorite_items'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('my favorite items'.underscore(), 'my_favorite_items'); } }); QUnit.test('with dasherized string', function () { deepEqual((0, _string.underscore)('css-class-name'), 'css_class_name'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('css-class-name'.underscore(), 'css_class_name'); } }); QUnit.test('does nothing with underscored string', function () { deepEqual((0, _string.underscore)('action_name'), 'action_name'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('action_name'.underscore(), 'action_name'); } }); QUnit.test('with camelcased string', function () { deepEqual((0, _string.underscore)('innerHTML'), 'inner_html'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('innerHTML'.underscore(), 'inner_html'); } }); QUnit.test('underscore namespaced classified string', function () { deepEqual((0, _string.underscore)('PrivateDocs/OwnerInvoice'), 'private_docs/owner_invoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('PrivateDocs/OwnerInvoice'.underscore(), 'private_docs/owner_invoice'); } }); QUnit.test('underscore namespaced camelized string', function () { deepEqual((0, _string.underscore)('privateDocs/ownerInvoice'), 'private_docs/owner_invoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('privateDocs/ownerInvoice'.underscore(), 'private_docs/owner_invoice'); } }); QUnit.test('underscore namespaced dasherized string', function () { deepEqual((0, _string.underscore)('private-docs/owner-invoice'), 'private_docs/owner_invoice'); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('private-docs/owner-invoice'.underscore(), 'private_docs/owner_invoice'); } }); }); enifed('ember-runtime/tests/system/string/w_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) { 'use strict'; QUnit.module('EmberStringUtils.w'); if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { QUnit.test('String.prototype.w is not available without EXTEND_PROTOTYPES', function () { ok('undefined' === typeof String.prototype.w, 'String.prototype helper disabled'); }); } QUnit.test('\'one two three\'.w() => [\'one\',\'two\',\'three\']', function () { deepEqual((0, _string.w)('one two three'), ['one', 'two', 'three']); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('one two three'.w(), ['one', 'two', 'three']); } }); QUnit.test('\'one two three\'.w() with extra spaces between words => [\'one\',\'two\',\'three\']', function () { deepEqual((0, _string.w)('one two three'), ['one', 'two', 'three']); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('one two three'.w(), ['one', 'two', 'three']); } }); QUnit.test('\'one two three\'.w() with tabs', function () { deepEqual((0, _string.w)('one\ttwo three'), ['one', 'two', 'three']); if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) { deepEqual('one\ttwo three'.w(), ['one', 'two', 'three']); } }); }); enifed('ember-template-compiler/compat', ['ember-metal', 'ember-template-compiler/system/precompile', 'ember-template-compiler/system/compile', 'ember-template-compiler/system/compile-options'], function (_emberMetal, _precompile, _compile, _compileOptions) { 'use strict'; var EmberHandlebars = _emberMetal.default.Handlebars = _emberMetal.default.Handlebars || {}; // reexports var EmberHTMLBars = _emberMetal.default.HTMLBars = _emberMetal.default.HTMLBars || {}; EmberHTMLBars.precompile = EmberHandlebars.precompile = _precompile.default; EmberHTMLBars.compile = EmberHandlebars.compile = _compile.default; EmberHTMLBars.registerPlugin = _compileOptions.registerPlugin; }); enifed('ember-template-compiler/index', ['exports', 'ember-template-compiler/system/precompile', 'ember-template-compiler/system/compile', 'ember-template-compiler/system/compile-options', 'ember-template-compiler/plugins', 'ember-metal', 'ember/features', 'ember-environment', 'ember/version', 'ember-template-compiler/compat', 'ember-template-compiler/system/bootstrap'], function (exports, _precompile, _compile, _compileOptions, _plugins, _emberMetal, _features, _emberEnvironment, _version) { 'use strict'; exports.defaultPlugins = exports.registerPlugin = exports.compileOptions = exports.compile = exports.precompile = exports._Ember = undefined; Object.defineProperty(exports, 'precompile', { enumerable: true, get: function () { return _precompile.default; } }); Object.defineProperty(exports, 'compile', { enumerable: true, get: function () { return _compile.default; } }); Object.defineProperty(exports, 'compileOptions', { enumerable: true, get: function () { return _compileOptions.default; } }); Object.defineProperty(exports, 'registerPlugin', { enumerable: true, get: function () { return _compileOptions.registerPlugin; } }); Object.defineProperty(exports, 'defaultPlugins', { enumerable: true, get: function () { return _plugins.default; } }); // private API used by ember-cli-htmlbars to setup ENV and FEATURES if (!_emberMetal.default.ENV) { _emberMetal.default.ENV = _emberEnvironment.ENV; } if (!_emberMetal.default.FEATURES) { _emberMetal.default.FEATURES = _features.FEATURES; } if (!_emberMetal.default.VERSION) { _emberMetal.default.VERSION = _version.default; } exports._Ember = _emberMetal.default; }); enifed('ember-template-compiler/plugins/assert-reserved-named-arguments', ['exports', 'ember-debug', 'ember-template-compiler/system/calculate-location-display'], function (exports, _emberDebug, _calculateLocationDisplay) { 'use strict'; exports.default = AssertReservedNamedArguments; function AssertReservedNamedArguments(options) { this.syntax = null; this.options = options; } AssertReservedNamedArguments.prototype.transform = function AssertReservedNamedArguments_transform(ast) { var moduleName = this.options.meta.moduleName; this.syntax.traverse(ast, { PathExpression: function (node) { if (node.original[0] === '@') { (true && (0, _emberDebug.assert)(assertMessage(moduleName, node))); } } }); return ast; }; function assertMessage(moduleName, node) { var path = node.original; var source = (0, _calculateLocationDisplay.default)(moduleName, node.loc); return '\'' + path + '\' is not a valid path. ' + source; } }); enifed('ember-template-compiler/plugins/deprecate-render-model', ['exports', 'ember-debug', 'ember-template-compiler/system/calculate-location-display'], function (exports, _emberDebug, _calculateLocationDisplay) { 'use strict'; exports.default = DeprecateRenderModel; function DeprecateRenderModel(options) { this.syntax = null; this.options = options; } DeprecateRenderModel.prototype.transform = function DeprecateRenderModel_transform(ast) { var moduleName = this.options.meta.moduleName; var walker = new this.syntax.Walker(); walker.visit(ast, function (node) { if (!validate(node)) { return; } each(node.params, function (param) { if (param.type !== 'PathExpression') { return; } (true && !(false) && (0, _emberDebug.deprecate)(deprecationMessage(moduleName, node, param), false, { id: 'ember-template-compiler.deprecate-render-model', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x#toc_model-param-in-code-render-code-helper' })); }); }); return ast; }; function validate(node) { return node.type === 'MustacheStatement' && node.path.original === 'render' && node.params.length > 1; } function each(list, callback) { for (var i = 0, l = list.length; i < l; i++) { callback(list[i]); } } function deprecationMessage(moduleName, node, param) { var sourceInformation = (0, _calculateLocationDisplay.default)(moduleName, node.loc); var componentName = node.params[0].original; var modelName = param.original; var original = '{{render "' + componentName + '" ' + modelName + '}}'; var preferred = '{{' + componentName + ' model=' + modelName + '}}'; return 'Please refactor `' + original + '` to a component and invoke via' + (' `' + preferred + '`. ' + sourceInformation); } }); enifed('ember-template-compiler/plugins/deprecate-render', ['exports', 'ember-debug', 'ember-template-compiler/system/calculate-location-display'], function (exports, _emberDebug, _calculateLocationDisplay) { 'use strict'; exports.default = DeprecateRender; function DeprecateRender(options) { this.syntax = null; this.options = options; } DeprecateRender.prototype.transform = function DeprecateRender_transform(ast) { var moduleName = this.options.meta.moduleName; var walker = new this.syntax.Walker(); walker.visit(ast, function (node) { if (!validate(node)) { return; } each(node.params, function (param) { if (param.type !== 'StringLiteral') { return; } (true && !(false) && (0, _emberDebug.deprecate)(deprecationMessage(moduleName, node), false, { id: 'ember-template-compiler.deprecate-render', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x#toc_code-render-code-helper' })); }); }); return ast; }; function validate(node) { return node.type === 'MustacheStatement' && node.path.original === 'render' && node.params.length === 1; } function each(list, callback) { for (var i = 0, l = list.length; i < l; i++) { callback(list[i]); } } function deprecationMessage(moduleName, node) { var sourceInformation = (0, _calculateLocationDisplay.default)(moduleName, node.loc); var componentName = node.params[0].original; var original = '{{render "' + componentName + '"}}'; var preferred = '{{' + componentName + '}}'; return 'Please refactor `' + original + '` to a component and invoke via' + (' `' + preferred + '`. ' + sourceInformation); } }); enifed('ember-template-compiler/plugins/index', ['exports', 'ember-template-compiler/plugins/transform-old-binding-syntax', 'ember-template-compiler/plugins/transform-item-class', 'ember-template-compiler/plugins/transform-angle-bracket-components', 'ember-template-compiler/plugins/transform-input-on-to-onEvent', 'ember-template-compiler/plugins/transform-top-level-components', 'ember-template-compiler/plugins/transform-inline-link-to', 'ember-template-compiler/plugins/transform-old-class-binding-syntax', 'ember-template-compiler/plugins/transform-quoted-bindings-into-just-bindings', 'ember-template-compiler/plugins/deprecate-render-model', 'ember-template-compiler/plugins/deprecate-render', 'ember-template-compiler/plugins/assert-reserved-named-arguments', 'ember-template-compiler/plugins/transform-action-syntax', 'ember-template-compiler/plugins/transform-input-type-syntax', 'ember-template-compiler/plugins/transform-attrs-into-args', 'ember-template-compiler/plugins/transform-each-in-into-each', 'ember-template-compiler/plugins/transform-has-block-syntax', 'ember-template-compiler/plugins/transform-dot-component-invocation'], function (exports, _transformOldBindingSyntax, _transformItemClass, _transformAngleBracketComponents, _transformInputOnToOnEvent, _transformTopLevelComponents, _transformInlineLinkTo, _transformOldClassBindingSyntax, _transformQuotedBindingsIntoJustBindings, _deprecateRenderModel, _deprecateRender, _assertReservedNamedArguments, _transformActionSyntax, _transformInputTypeSyntax, _transformAttrsIntoArgs, _transformEachInIntoEach, _transformHasBlockSyntax, _transformDotComponentInvocation) { 'use strict'; exports.default = Object.freeze([_transformDotComponentInvocation.default, _transformOldBindingSyntax.default, _transformItemClass.default, _transformAngleBracketComponents.default, _transformInputOnToOnEvent.default, _transformTopLevelComponents.default, _transformInlineLinkTo.default, _transformOldClassBindingSyntax.default, _transformQuotedBindingsIntoJustBindings.default, _deprecateRenderModel.default, _deprecateRender.default, _assertReservedNamedArguments.default, _transformActionSyntax.default, _transformInputTypeSyntax.default, _transformAttrsIntoArgs.default, _transformEachInIntoEach.default, _transformHasBlockSyntax.default]); }); enifed('ember-template-compiler/plugins/transform-action-syntax', ['exports'], function (exports) { 'use strict'; exports.default = TransformActionSyntax; /** @module ember @submodule ember-glimmer */ /** A Glimmer2 AST transformation that replaces all instances of ```handlebars ', { moduleName: 'components/special-button' })); }); return application; } function handleURL(application, path) { var router = application.__container__.lookup('router:main'); return (0, _emberMetal.run)(router, 'handleURL', path); } QUnit.module('View Integration', { setup: function () { actions = []; (0, _emberViews.jQuery)('#qunit-fixture').html('
    '); App1 = startApp('#app-1'); App2 = startApp('#app-2'); }, teardown: function () { (0, _emberMetal.run)(App1, 'destroy'); (0, _emberMetal.run)(App2, 'destroy'); App1 = App2 = null; } }); QUnit.test('booting multiple applications can properly handle events', function (assert) { (0, _emberMetal.run)(App1, 'advanceReadiness'); (0, _emberMetal.run)(App2, 'advanceReadiness'); handleURL(App1, '/'); handleURL(App2, '/'); (0, _emberViews.jQuery)('#app-2 .do-stuff').click(); (0, _emberViews.jQuery)('#app-1 .do-stuff').click(); assert.deepEqual(actions, ['#app-2', '#app-1']); }); }); enifed('ember/tests/reexports_test', ['ember/index', 'internal-test-helpers'], function (_index, _internalTestHelpers) { 'use strict'; QUnit.module('ember reexports'); [ // ember-utils ['getOwner', 'ember-utils', 'getOwner'], ['setOwner', 'ember-utils', 'setOwner'], ['assign', 'ember-utils'], ['GUID_KEY', 'ember-utils'], ['uuid', 'ember-utils'], ['generateGuid', 'ember-utils'], ['guidFor', 'ember-utils'], ['inspect', 'ember-utils'], ['makeArray', 'ember-utils'], ['canInvoke', 'ember-utils'], ['tryInvoke', 'ember-utils'], ['wrap', 'ember-utils'], ['applyStr', 'ember-utils'], // ember-environment // ['ENV', 'ember-environment', 'ENV'], TODO: fix this, its failing because we are hitting the getter // container ['Registry', 'container', 'Registry'], ['Container', 'container', 'Container'], // ember-metal ['computed', 'ember-metal'], ['computed.alias', 'ember-metal', 'alias'], ['ComputedProperty', 'ember-metal'], ['cacheFor', 'ember-metal'], ['deprecateFunc', 'ember-debug'], ['assert', 'ember-debug'], ['warn', 'ember-debug'], ['debug', 'ember-debug'], ['runInDebug', 'ember-debug'], ['merge', 'ember-metal'], ['instrument', 'ember-metal'], ['Instrumentation.instrument', 'ember-metal', 'instrument'], ['Instrumentation.subscribe', 'ember-metal', 'instrumentationSubscribe'], ['Instrumentation.unsubscribe', 'ember-metal', 'instrumentationUnsubscribe'], ['Instrumentation.reset', 'ember-metal', 'instrumentationReset'], ['testing', 'ember-debug', { get: 'isTesting', set: 'setTesting' }], ['onerror', 'ember-metal', { get: 'getOnerror', set: 'setOnerror' }], // ['create'], TODO: figure out what to do here // ['keys'], TODO: figure out what to do here ['FEATURES', 'ember/features'], ['FEATURES.isEnabled', 'ember-debug', 'isFeatureEnabled'], ['Error', 'ember-debug'], ['META_DESC', 'ember-metal'], ['meta', 'ember-metal'], ['get', 'ember-metal'], ['set', 'ember-metal'], ['_getPath', 'ember-metal'], ['getWithDefault', 'ember-metal'], ['trySet', 'ember-metal'], ['_Cache', 'ember-metal', 'Cache'], ['on', 'ember-metal'], ['addListener', 'ember-metal'], ['removeListener', 'ember-metal'], ['_suspendListener', 'ember-metal', 'suspendListener'], ['_suspendListeners', 'ember-metal', 'suspendListeners'], ['sendEvent', 'ember-metal'], ['hasListeners', 'ember-metal'], ['watchedEvents', 'ember-metal'], ['listenersFor', 'ember-metal'], ['accumulateListeners', 'ember-metal'], ['isNone', 'ember-metal'], ['isEmpty', 'ember-metal'], ['isBlank', 'ember-metal'], ['isPresent', 'ember-metal'], ['_Backburner', 'backburner', 'default'], ['run', 'ember-metal'], ['_ObserverSet', 'ember-metal', 'ObserverSet'], ['propertyWillChange', 'ember-metal'], ['propertyDidChange', 'ember-metal'], ['overrideChains', 'ember-metal'], ['beginPropertyChanges', 'ember-metal'], ['beginPropertyChanges', 'ember-metal'], ['endPropertyChanges', 'ember-metal'], ['changeProperties', 'ember-metal'], ['defineProperty', 'ember-metal'], ['watchKey', 'ember-metal'], ['unwatchKey', 'ember-metal'], ['removeChainWatcher', 'ember-metal'], ['_ChainNode', 'ember-metal', 'ChainNode'], ['finishChains', 'ember-metal'], ['watchPath', 'ember-metal'], ['unwatchPath', 'ember-metal'], ['watch', 'ember-metal'], ['isWatching', 'ember-metal'], ['unwatch', 'ember-metal'], ['destroy', 'ember-metal'], ['libraries', 'ember-metal'], ['OrderedSet', 'ember-metal'], ['Map', 'ember-metal'], ['MapWithDefault', 'ember-metal'], ['getProperties', 'ember-metal'], ['setProperties', 'ember-metal'], ['expandProperties', 'ember-metal'], ['NAME_KEY', 'ember-utils'], ['addObserver', 'ember-metal'], ['observersFor', 'ember-metal'], ['removeObserver', 'ember-metal'], ['_suspendObserver', 'ember-metal'], ['_suspendObservers', 'ember-metal'], ['required', 'ember-metal'], ['aliasMethod', 'ember-metal'], ['observer', 'ember-metal'], ['immediateObserver', 'ember-metal', '_immediateObserver'], ['mixin', 'ember-metal'], ['Mixin', 'ember-metal'], ['bind', 'ember-metal'], ['Binding', 'ember-metal'], ['isGlobalPath', 'ember-metal'], // ember-views ['$', 'ember-views', 'jQuery'], ['ViewUtils.isSimpleClick', 'ember-views', 'isSimpleClick'], ['ViewUtils.getViewElement', 'ember-views', 'getViewElement'], ['ViewUtils.getViewBounds', 'ember-views', 'getViewBounds'], ['ViewUtils.getViewClientRects', 'ember-views', 'getViewClientRects'], ['ViewUtils.getViewBoundingClientRect', 'ember-views', 'getViewBoundingClientRect'], ['ViewUtils.getRootViews', 'ember-views', 'getRootViews'], ['ViewUtils.getChildViews', 'ember-views', 'getChildViews'], ['TextSupport', 'ember-views'], ['ComponentLookup', 'ember-views'], ['EventDispatcher', 'ember-views'], // ember-glimmer ['Component', 'ember-glimmer', 'Component'], ['Helper', 'ember-glimmer', 'Helper'], ['Helper.helper', 'ember-glimmer', 'helper'], ['Checkbox', 'ember-glimmer', 'Checkbox'], ['LinkComponent', 'ember-glimmer', 'LinkComponent'], ['TextArea', 'ember-glimmer', 'TextArea'], ['TextField', 'ember-glimmer', 'TextField'], ['TEMPLATES', 'ember-glimmer', { get: 'getTemplates', set: 'setTemplates' }], ['Handlebars.template', 'ember-glimmer', 'template'], ['Handlebars.SafeString', 'ember-glimmer', { get: '_getSafeString' }], ['Handlebars.Utils.escapeExpression', 'ember-glimmer', 'escapeExpression'], ['String.htmlSafe', 'ember-glimmer', 'htmlSafe'], // ember-runtime ['_RegistryProxyMixin', 'ember-runtime', 'RegistryProxyMixin'], ['_ContainerProxyMixin', 'ember-runtime', 'ContainerProxyMixin'], ['Object', 'ember-runtime'], ['String', 'ember-runtime'], ['compare', 'ember-runtime'], ['copy', 'ember-runtime'], ['isEqual', 'ember-runtime'], ['inject', 'ember-runtime'], ['Array', 'ember-runtime'], ['Comparable', 'ember-runtime'], ['Namespace', 'ember-runtime'], ['Enumerable', 'ember-runtime'], ['ArrayProxy', 'ember-runtime'], ['ObjectProxy', 'ember-runtime'], ['ActionHandler', 'ember-runtime'], ['CoreObject', 'ember-runtime'], ['NativeArray', 'ember-runtime'], ['Copyable', 'ember-runtime'], ['Freezable', 'ember-runtime'], ['FROZEN_ERROR', 'ember-runtime'], ['MutableEnumerable', 'ember-runtime'], ['MutableArray', 'ember-runtime'], ['TargetActionSupport', 'ember-runtime'], ['Evented', 'ember-runtime'], ['PromiseProxyMixin', 'ember-runtime'], ['Observable', 'ember-runtime'], ['typeOf', 'ember-runtime'], ['isArray', 'ember-runtime'], ['Object', 'ember-runtime'], ['onLoad', 'ember-runtime'], ['runLoadHooks', 'ember-runtime'], ['Controller', 'ember-runtime'], ['ControllerMixin', 'ember-runtime'], ['Service', 'ember-runtime'], ['_ProxyMixin', 'ember-runtime'], ['RSVP', 'ember-runtime'], ['STRINGS', 'ember-runtime', { get: 'getStrings', set: 'setStrings' }], ['BOOTED', 'ember-runtime', { get: 'isNamespaceSearchDisabled', set: 'setNamespaceSearchDisabled' }], // ember-routing ['Location', 'ember-routing'], ['AutoLocation', 'ember-routing'], ['HashLocation', 'ember-routing'], ['HistoryLocation', 'ember-routing'], ['NoneLocation', 'ember-routing'], ['controllerFor', 'ember-routing'], ['generateControllerFactory', 'ember-routing'], ['generateController', 'ember-routing'], ['RouterDSL', 'ember-routing'], ['Router', 'ember-routing'], ['Route', 'ember-routing'], // ember-application ['Application', 'ember-application'], ['ApplicationInstance', 'ember-application'], ['Engine', 'ember-application'], ['EngineInstance', 'ember-application'], ['Resolver', 'ember-application'], ['DefaultResolver', 'ember-application', 'Resolver'], // ember-extension-support ['DataAdapter', 'ember-extension-support'], ['ContainerDebugAdapter', 'ember-extension-support']].forEach(function (reexport) { var path = reexport[0], moduleId = reexport[1], exportName = reexport[2]; // default path === exportName if none present if (!exportName) { exportName = path; } QUnit.test('Ember.' + path + ' exports correctly', function (assert) { (0, _internalTestHelpers.confirmExport)(_index.default, assert, path, moduleId, exportName); }); }); QUnit.test('Ember.String.isHTMLSafe exports correctly', function (assert) { (0, _internalTestHelpers.confirmExport)(_index.default, assert, 'String.isHTMLSafe', 'ember-glimmer', 'isHTMLSafe'); }); }); enifed('ember/tests/routing/basic_test', ['ember-utils', 'ember-console', 'ember-runtime', 'ember-routing', 'ember-metal', 'ember-glimmer', 'ember-views', 'ember-template-compiler', 'ember-application', 'router'], function (_emberUtils, _emberConsole, _emberRuntime, _emberRouting, _emberMetal, _emberGlimmer, _emberViews, _emberTemplateCompiler, _emberApplication, _router) { 'use strict'; var trim = _emberViews.jQuery.trim; var Router = void 0, App = void 0, router = void 0, registry = void 0, container = void 0, originalLoggerError = void 0; function bootApplication() { router = container.lookup('router:main'); (0, _emberMetal.run)(App, 'advanceReadiness'); } function handleURL(path) { return (0, _emberMetal.run)(function () { return router.handleURL(path).then(function (value) { ok(true, 'url: `' + path + '` was handled'); return value; }, function (reason) { ok(false, 'failed to visit:`' + path + '` reason: `' + QUnit.jsDump.parse(reason)); throw reason; }); }); } function handleURLAborts(path) { (0, _emberMetal.run)(function () { router.handleURL(path).then(function () { ok(false, 'url: `' + path + '` was NOT to be handled'); }, function (reason) { ok(reason && reason.message === 'TransitionAborted', 'url: `' + path + '` was to be aborted'); }); }); } function handleURLRejectsWith(path, expectedReason) { (0, _emberMetal.run)(function () { router.handleURL(path).then(function () { ok(false, 'expected handleURLing: `' + path + '` to fail'); }, function (reason) { equal(reason, expectedReason); }); }); } QUnit.module('Basic Routing', { setup: function () { (0, _emberMetal.run)(function () { App = _emberApplication.Application.create({ name: 'App', rootElement: '#qunit-fixture' }); App.deferReadiness(); App.Router.reopen({ location: 'none' }); Router = App.Router; App.LoadingRoute = _emberRouting.Route.extend({}); registry = App.__registry__; container = App.__container__; (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('

    Hours

    ')); (0, _emberGlimmer.setTemplate)('homepage', (0, _emberTemplateCompiler.compile)('

    Megatroll

    {{model.home}}

    ')); (0, _emberGlimmer.setTemplate)('camelot', (0, _emberTemplateCompiler.compile)('

    Is a silly place

    ')); originalLoggerError = _emberConsole.default.error; }); }, teardown: function () { (0, _emberMetal.run)(function () { App.destroy(); App = null; (0, _emberGlimmer.setTemplates)({}); _emberConsole.default.error = originalLoggerError; }); } }); QUnit.test('warn on URLs not included in the route set', function () { Router.map(function () { this.route('home', { path: '/' }); }); bootApplication(); expectAssertion(function () { return (0, _emberMetal.run)(function () { return router.handleURL('/what-is-this-i-dont-even'); }); }, 'The URL \'/what-is-this-i-dont-even\' did not match any routes in your application'); }); QUnit.test('The Homepage', function () { Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({}); var currentPath = void 0; App.ApplicationController = _emberRuntime.Controller.extend({ currentPathDidChange: (0, _emberMetal.observer)('currentPath', function () { currentPath = (0, _emberMetal.get)(this, 'currentPath'); }) }); bootApplication(); equal(currentPath, 'home'); equal((0, _emberViews.jQuery)('h3:contains(Hours)', '#qunit-fixture').length, 1, 'The home template was rendered'); }); QUnit.test('The Home page and the Camelot page with multiple Router.map calls', function () { Router.map(function () { this.route('home', { path: '/' }); }); Router.map(function () { this.route('camelot', { path: '/camelot' }); }); App.HomeRoute = _emberRouting.Route.extend({}); App.CamelotRoute = _emberRouting.Route.extend({}); var currentPath = void 0; App.ApplicationController = _emberRuntime.Controller.extend({ currentPathDidChange: (0, _emberMetal.observer)('currentPath', function () { currentPath = (0, _emberMetal.get)(this, 'currentPath'); }) }); App.CamelotController = _emberRuntime.Controller.extend({ currentPathDidChange: (0, _emberMetal.observer)('currentPath', function () { currentPath = (0, _emberMetal.get)(this, 'currentPath'); }) }); bootApplication(); handleURL('/camelot'); equal(currentPath, 'camelot'); equal((0, _emberViews.jQuery)('h3:contains(silly)', '#qunit-fixture').length, 1, 'The camelot template was rendered'); handleURL('/'); equal(currentPath, 'home'); equal((0, _emberViews.jQuery)('h3:contains(Hours)', '#qunit-fixture').length, 1, 'The home template was rendered'); }); QUnit.test('The Homepage with explicit template name in renderTemplate', function () { Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render('homepage'); } }); bootApplication(); equal((0, _emberViews.jQuery)('h3:contains(Megatroll)', '#qunit-fixture').length, 1, 'The homepage template was rendered'); }); QUnit.test('An alternate template will pull in an alternate controller', function () { Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render('homepage'); } }); App.HomepageController = _emberRuntime.Controller.extend({ model: { home: 'Comes from homepage' } }); bootApplication(); equal((0, _emberViews.jQuery)('h3:contains(Megatroll) + p:contains(Comes from homepage)', '#qunit-fixture').length, 1, 'The homepage template was rendered'); }); QUnit.test('An alternate template will pull in an alternate controller instead of controllerName', function () { Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({ controllerName: 'foo', renderTemplate: function () { this.render('homepage'); } }); App.FooController = _emberRuntime.Controller.extend({ model: { home: 'Comes from Foo' } }); App.HomepageController = _emberRuntime.Controller.extend({ model: { home: 'Comes from homepage' } }); bootApplication(); equal((0, _emberViews.jQuery)('h3:contains(Megatroll) + p:contains(Comes from homepage)', '#qunit-fixture').length, 1, 'The homepage template was rendered'); }); QUnit.test('The template will pull in an alternate controller via key/value', function () { Router.map(function () { this.route('homepage', { path: '/' }); }); App.HomepageRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render({ controller: 'home' }); } }); App.HomeController = _emberRuntime.Controller.extend({ model: { home: 'Comes from home.' } }); bootApplication(); equal((0, _emberViews.jQuery)('h3:contains(Megatroll) + p:contains(Comes from home.)', '#qunit-fixture').length, 1, 'The homepage template was rendered from data from the HomeController'); }); QUnit.test('The Homepage with explicit template name in renderTemplate and controller', function () { Router.map(function () { this.route('home', { path: '/' }); }); App.HomeController = _emberRuntime.Controller.extend({ model: { home: 'YES I AM HOME' } }); App.HomeRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render('homepage'); } }); bootApplication(); equal((0, _emberViews.jQuery)('h3:contains(Megatroll) + p:contains(YES I AM HOME)', '#qunit-fixture').length, 1, 'The homepage template was rendered'); }); QUnit.test('Model passed via renderTemplate model is set as controller\'s model', function () { (0, _emberGlimmer.setTemplate)('bio', (0, _emberTemplateCompiler.compile)('

    {{model.name}}

    ')); App.BioController = _emberRuntime.Controller.extend(); Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render('bio', { model: { name: 'emberjs' } }); } }); bootApplication(); equal((0, _emberViews.jQuery)('p:contains(emberjs)', '#qunit-fixture').length, 1, 'Passed model was set as controllers model'); }); QUnit.test('render uses templateName from route', function () { Router.map(function () { this.route('home', { path: '/' }); }); (0, _emberGlimmer.setTemplate)('the_real_home_template', (0, _emberTemplateCompiler.compile)('

    THIS IS THE REAL HOME

    ')); App.HomeController = _emberRuntime.Controller.extend(); App.HomeRoute = _emberRouting.Route.extend({ templateName: 'the_real_home_template' }); bootApplication(); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'THIS IS THE REAL HOME', 'The homepage template was rendered'); }); QUnit.test('defining templateName allows other templates to be rendered', function () { Router.map(function () { this.route('home', { path: '/' }); }); (0, _emberGlimmer.setTemplate)('alert', (0, _emberTemplateCompiler.compile)('
    Invader!
    ')); (0, _emberGlimmer.setTemplate)('the_real_home_template', (0, _emberTemplateCompiler.compile)('

    THIS IS THE REAL HOME

    {{outlet \'alert\'}}')); App.HomeController = _emberRuntime.Controller.extend(); App.HomeRoute = _emberRouting.Route.extend({ templateName: 'the_real_home_template', actions: { showAlert: function () { this.render('alert', { into: 'home', outlet: 'alert' }); } } }); bootApplication(); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'THIS IS THE REAL HOME', 'The homepage template was rendered'); (0, _emberMetal.run)(function () { return router.send('showAlert'); }); equal((0, _emberViews.jQuery)('.alert-box', '#qunit-fixture').text(), 'Invader!', 'Template for alert was render into outlet'); }); QUnit.test('templateName is still used when calling render with no name and options', function () { Router.map(function () { this.route('home', { path: '/' }); }); (0, _emberGlimmer.setTemplate)('alert', (0, _emberTemplateCompiler.compile)('
    Invader!
    ')); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('

    THIS IS THE REAL HOME

    {{outlet \'alert\'}}')); App.HomeRoute = _emberRouting.Route.extend({ templateName: 'alert', renderTemplate: function () { this.render({}); } }); bootApplication(); equal((0, _emberViews.jQuery)('.alert-box', '#qunit-fixture').text(), 'Invader!', 'default templateName was rendered into outlet'); }); QUnit.test('The Homepage with a `setupController` hook', function () { Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({ setupController: function (controller) { (0, _emberMetal.set)(controller, 'hours', (0, _emberRuntime.A)(['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm'])); } }); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('
      {{#each hours as |entry|}}
    • {{entry}}
    • {{/each}}
    ')); bootApplication(); equal((0, _emberViews.jQuery)('ul li', '#qunit-fixture').eq(2).text(), 'Sunday: Noon to 6pm', 'The template was rendered with the hours context'); }); QUnit.test('The route controller is still set when overriding the setupController hook', function () { Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({ setupController: function () { // no-op // importantly, we are not calling this._super here } }); registry.register('controller:home', _emberRuntime.Controller.extend()); bootApplication(); deepEqual(container.lookup('route:home').controller, container.lookup('controller:home'), 'route controller is the home controller'); }); QUnit.test('The route controller can be specified via controllerName', function () { Router.map(function () { this.route('home', { path: '/' }); }); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('

    {{myValue}}

    ')); App.HomeRoute = _emberRouting.Route.extend({ controllerName: 'myController' }); registry.register('controller:myController', _emberRuntime.Controller.extend({ myValue: 'foo' })); bootApplication(); deepEqual(container.lookup('route:home').controller, container.lookup('controller:myController'), 'route controller is set by controllerName'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'foo', 'The homepage template was rendered with data from the custom controller'); }); QUnit.test('The route controller specified via controllerName is used in render', function () { Router.map(function () { this.route('home', { path: '/' }); }); (0, _emberGlimmer.setTemplate)('alternative_home', (0, _emberTemplateCompiler.compile)('

    alternative home: {{myValue}}

    ')); App.HomeRoute = _emberRouting.Route.extend({ controllerName: 'myController', renderTemplate: function () { this.render('alternative_home'); } }); registry.register('controller:myController', _emberRuntime.Controller.extend({ myValue: 'foo' })); bootApplication(); deepEqual(container.lookup('route:home').controller, container.lookup('controller:myController'), 'route controller is set by controllerName'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'alternative home: foo', 'The homepage template was rendered with data from the custom controller'); }); QUnit.test('The route controller specified via controllerName is used in render even when a controller with the routeName is available', function () { Router.map(function () { this.route('home', { path: '/' }); }); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('

    home: {{myValue}}

    ')); App.HomeRoute = _emberRouting.Route.extend({ controllerName: 'myController' }); registry.register('controller:home', _emberRuntime.Controller.extend({ myValue: 'home' })); registry.register('controller:myController', _emberRuntime.Controller.extend({ myValue: 'myController' })); bootApplication(); deepEqual(container.lookup('route:home').controller, container.lookup('controller:myController'), 'route controller is set by controllerName'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'home: myController', 'The homepage template was rendered with data from the custom controller'); }); QUnit.test('The Homepage with a `setupController` hook modifying other controllers', function () { Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({ setupController: function () { (0, _emberMetal.set)(this.controllerFor('home'), 'hours', (0, _emberRuntime.A)(['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm'])); } }); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('
      {{#each hours as |entry|}}
    • {{entry}}
    • {{/each}}
    ')); bootApplication(); equal((0, _emberViews.jQuery)('ul li', '#qunit-fixture').eq(2).text(), 'Sunday: Noon to 6pm', 'The template was rendered with the hours context'); }); QUnit.test('The Homepage with a computed context that does not get overridden', function () { Router.map(function () { this.route('home', { path: '/' }); }); App.HomeController = _emberRuntime.Controller.extend({ model: (0, _emberMetal.computed)(function () { return (0, _emberRuntime.A)(['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm']); }) }); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('
      {{#each model as |passage|}}
    • {{passage}}
    • {{/each}}
    ')); bootApplication(); equal((0, _emberViews.jQuery)('ul li', '#qunit-fixture').eq(2).text(), 'Sunday: Noon to 6pm', 'The template was rendered with the context intact'); }); QUnit.test('The Homepage getting its controller context via model', function () { Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({ model: function () { return (0, _emberRuntime.A)(['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm']); }, setupController: function (controller, model) { equal(this.controllerFor('home'), controller); (0, _emberMetal.set)(this.controllerFor('home'), 'hours', model); } }); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('
      {{#each hours as |entry|}}
    • {{entry}}
    • {{/each}}
    ')); bootApplication(); equal((0, _emberViews.jQuery)('ul li', '#qunit-fixture').eq(2).text(), 'Sunday: Noon to 6pm', 'The template was rendered with the hours context'); }); QUnit.test('The Specials Page getting its controller context by deserializing the params hash', function () { Router.map(function () { this.route('home', { path: '/' }); this.route('special', { path: '/specials/:menu_item_id' }); }); App.SpecialRoute = _emberRouting.Route.extend({ model: function (params) { return _emberRuntime.Object.create({ menuItemId: params.menu_item_id }); }, setupController: function (controller, model) { (0, _emberMetal.set)(controller, 'model', model); } }); (0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('

    {{model.menuItemId}}

    ')); bootApplication(); registry.register('controller:special', _emberRuntime.Controller.extend()); handleURL('/specials/1'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), '1', 'The model was used to render the template'); }); QUnit.test('The Specials Page defaults to looking models up via `find`', function () { Router.map(function () { this.route('home', { path: '/' }); this.route('special', { path: '/specials/:menu_item_id' }); }); App.MenuItem = _emberRuntime.Object.extend(); App.MenuItem.reopenClass({ find: function (id) { return App.MenuItem.create({ id: id }); } }); App.SpecialRoute = _emberRouting.Route.extend({ setupController: function (controller, model) { (0, _emberMetal.set)(controller, 'model', model); } }); (0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('

    {{model.id}}

    ')); bootApplication(); registry.register('controller:special', _emberRuntime.Controller.extend()); handleURL('/specials/1'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), '1', 'The model was used to render the template'); }); QUnit.test('The Special Page returning a promise puts the app into a loading state until the promise is resolved', function () { Router.map(function () { this.route('home', { path: '/' }); this.route('special', { path: '/specials/:menu_item_id' }); }); var menuItem = void 0, resolve = void 0; App.MenuItem = _emberRuntime.Object.extend(); App.MenuItem.reopenClass({ find: function (id) { menuItem = App.MenuItem.create({ id: id }); return new _emberRuntime.RSVP.Promise(function (res) { resolve = res; }); } }); App.LoadingRoute = _emberRouting.Route.extend({}); App.SpecialRoute = _emberRouting.Route.extend({ setupController: function (controller, model) { (0, _emberMetal.set)(controller, 'model', model); } }); (0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('

    {{model.id}}

    ')); (0, _emberGlimmer.setTemplate)('loading', (0, _emberTemplateCompiler.compile)('

    LOADING!

    ')); bootApplication(); registry.register('controller:special', _emberRuntime.Controller.extend()); handleURL('/specials/1'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'LOADING!', 'The app is in the loading state'); (0, _emberMetal.run)(function () { return resolve(menuItem); }); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), '1', 'The app is now in the specials state'); }); QUnit.test('The loading state doesn\'t get entered for promises that resolve on the same run loop', function () { Router.map(function () { this.route('home', { path: '/' }); this.route('special', { path: '/specials/:menu_item_id' }); }); App.MenuItem = _emberRuntime.Object.extend(); App.MenuItem.reopenClass({ find: function (id) { return { id: id }; } }); App.LoadingRoute = _emberRouting.Route.extend({ enter: function () { ok(false, 'LoadingRoute shouldn\'t have been entered.'); } }); App.SpecialRoute = _emberRouting.Route.extend({ setupController: function (controller, model) { (0, _emberMetal.set)(controller, 'model', model); } }); (0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('

    {{model.id}}

    ')); (0, _emberGlimmer.setTemplate)('loading', (0, _emberTemplateCompiler.compile)('

    LOADING!

    ')); bootApplication(); registry.register('controller:special', _emberRuntime.Controller.extend()); handleURL('/specials/1'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), '1', 'The app is now in the specials state'); }); /* asyncTest("The Special page returning an error fires the error hook on SpecialRoute", function() { Router.map(function() { this.route("home", { path: "/" }); this.route("special", { path: "/specials/:menu_item_id" }); }); let menuItem; App.MenuItem = Ember.Object.extend(); App.MenuItem.reopenClass({ find: function(id) { menuItem = App.MenuItem.create({ id: id }); run.later(function() { menuItem.resolve(menuItem); }, 1); return menuItem; } }); App.SpecialRoute = Route.extend({ setup: function() { throw 'Setup error'; }, actions: { error: function(reason) { equal(reason, 'Setup error'); QUnit.start(); } } }); bootApplication(); handleURLRejectsWith('/specials/1', 'Setup error'); }); */ QUnit.test('The Special page returning an error invokes SpecialRoute\'s error handler', function () { Router.map(function () { this.route('home', { path: '/' }); this.route('special', { path: '/specials/:menu_item_id' }); }); var menuItem = void 0, promise = void 0, resolve = void 0; App.MenuItem = _emberRuntime.Object.extend(); App.MenuItem.reopenClass({ find: function (id) { menuItem = App.MenuItem.create({ id: id }); promise = new _emberRuntime.RSVP.Promise(function (res) { resolve = res; }); return promise; } }); App.SpecialRoute = _emberRouting.Route.extend({ setup: function () { throw 'Setup error'; }, actions: { error: function (reason) { equal(reason, 'Setup error', 'SpecialRoute#error received the error thrown from setup'); return true; } } }); bootApplication(); handleURLRejectsWith('/specials/1', 'Setup error'); (0, _emberMetal.run)(function () { return resolve(menuItem); }); }); var testOverridableErrorHandler = function (handlersName) { expect(2); Router.map(function () { this.route('home', { path: '/' }); this.route('special', { path: '/specials/:menu_item_id' }); }); var menuItem = void 0, resolve = void 0; App.MenuItem = _emberRuntime.Object.extend(); App.MenuItem.reopenClass({ find: function (id) { menuItem = App.MenuItem.create({ id: id }); return new _emberRuntime.RSVP.Promise(function (res) { resolve = res; }); } }); var attrs = {}; attrs[handlersName] = { error: function (reason) { equal(reason, 'Setup error', 'error was correctly passed to custom ApplicationRoute handler'); return true; } }; App.ApplicationRoute = _emberRouting.Route.extend(attrs); App.SpecialRoute = _emberRouting.Route.extend({ setup: function () { throw 'Setup error'; } }); bootApplication(); handleURLRejectsWith('/specials/1', 'Setup error'); (0, _emberMetal.run)(function () { return resolve(menuItem); }); }; QUnit.test('ApplicationRoute\'s default error handler can be overridden', function () { testOverridableErrorHandler('actions'); }); QUnit.asyncTest('Moving from one page to another triggers the correct callbacks', function () { expect(3); Router.map(function () { this.route('home', { path: '/' }); this.route('special', { path: '/specials/:menu_item_id' }); }); App.MenuItem = _emberRuntime.Object.extend(); App.SpecialRoute = _emberRouting.Route.extend({ setupController: function (controller, model) { (0, _emberMetal.set)(controller, 'model', model); } }); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('

    Home

    ')); (0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('

    {{model.id}}

    ')); bootApplication(); registry.register('controller:special', _emberRuntime.Controller.extend()); var transition = handleURL('/'); (0, _emberMetal.run)(function () { transition.then(function () { equal((0, _emberViews.jQuery)('h3', '#qunit-fixture').text(), 'Home', 'The app is now in the initial state'); var promiseContext = App.MenuItem.create({ id: 1 }); _emberMetal.run.later(function () { return _emberRuntime.RSVP.resolve(promiseContext); }, 1); return router.transitionTo('special', promiseContext); }).then(function () { deepEqual(router.location.path, '/specials/1'); QUnit.start(); }); }); }); QUnit.asyncTest('Nested callbacks are not exited when moving to siblings', function () { Router.map(function () { this.route('root', { path: '/' }, function () { this.route('special', { path: '/specials/:menu_item_id', resetNamespace: true }); }); }); App.RootRoute = _emberRouting.Route.extend({ model: function () { rootModel++; return this._super.apply(this, arguments); }, setupController: function () { rootSetup++; }, renderTemplate: function () { rootRender++; }, serialize: function () { rootSerialize++; return this._super.apply(this, arguments); } }); var currentPath = void 0; App.ApplicationController = _emberRuntime.Controller.extend({ currentPathDidChange: (0, _emberMetal.observer)('currentPath', function () { currentPath = (0, _emberMetal.get)(this, 'currentPath'); }) }); var menuItem = void 0; App.MenuItem = _emberRuntime.Object.extend(); App.MenuItem.reopenClass({ find: function (id) { menuItem = App.MenuItem.create({ id: id }); return menuItem; } }); App.LoadingRoute = _emberRouting.Route.extend({}); App.HomeRoute = _emberRouting.Route.extend({}); App.SpecialRoute = _emberRouting.Route.extend({ setupController: function (controller, model) { (0, _emberMetal.set)(controller, 'model', model); } }); (0, _emberGlimmer.setTemplate)('root/index', (0, _emberTemplateCompiler.compile)('

    Home

    ')); (0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('

    {{model.id}}

    ')); (0, _emberGlimmer.setTemplate)('loading', (0, _emberTemplateCompiler.compile)('

    LOADING!

    ')); var rootSetup = 0; var rootRender = 0; var rootModel = 0; var rootSerialize = 0; bootApplication(); registry.register('controller:special', _emberRuntime.Controller.extend()); equal((0, _emberViews.jQuery)('h3', '#qunit-fixture').text(), 'Home', 'The app is now in the initial state'); equal(rootSetup, 1, 'The root setup was triggered'); equal(rootRender, 1, 'The root render was triggered'); equal(rootSerialize, 0, 'The root serialize was not called'); equal(rootModel, 1, 'The root model was called'); router = container.lookup('router:main'); (0, _emberMetal.run)(function () { var menuItem = App.MenuItem.create({ id: 1 }); _emberMetal.run.later(function () { return _emberRuntime.RSVP.resolve(menuItem); }, 1); router.transitionTo('special', menuItem).then(function () { equal(rootSetup, 1, 'The root setup was not triggered again'); equal(rootRender, 1, 'The root render was not triggered again'); equal(rootSerialize, 0, 'The root serialize was not called'); // TODO: Should this be changed? equal(rootModel, 1, 'The root model was called again'); deepEqual(router.location.path, '/specials/1'); equal(currentPath, 'root.special'); QUnit.start(); }); }); }); QUnit.asyncTest('Events are triggered on the controller if a matching action name is implemented', function () { Router.map(function () { this.route('home', { path: '/' }); }); var model = { name: 'Tom Dale' }; var stateIsNotCalled = true; App.HomeRoute = _emberRouting.Route.extend({ model: function () { return model; }, actions: { showStuff: function () { stateIsNotCalled = false; } } }); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('{{name}}')); var controller = _emberRuntime.Controller.extend({ actions: { showStuff: function (context) { ok(stateIsNotCalled, 'an event on the state is not triggered'); deepEqual(context, { name: 'Tom Dale' }, 'an event with context is passed'); QUnit.start(); } } }); registry.register('controller:home', controller); bootApplication(); (0, _emberViews.jQuery)('#qunit-fixture a').click(); }); QUnit.asyncTest('Events are triggered on the current state when defined in `actions` object', function () { Router.map(function () { this.route('home', { path: '/' }); }); var model = { name: 'Tom Dale' }; App.HomeRoute = _emberRouting.Route.extend({ model: function () { return model; }, actions: { showStuff: function (obj) { ok(this instanceof App.HomeRoute, 'the handler is an App.HomeRoute'); // Using Ember.copy removes any private Ember vars which older IE would be confused by deepEqual((0, _emberRuntime.copy)(obj, true), { name: 'Tom Dale' }, 'the context is correct'); QUnit.start(); } } }); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('{{model.name}}')); bootApplication(); (0, _emberViews.jQuery)('#qunit-fixture a').click(); }); QUnit.asyncTest('Events defined in `actions` object are triggered on the current state when routes are nested', function () { Router.map(function () { this.route('root', { path: '/' }, function () { this.route('index', { path: '/' }); }); }); var model = { name: 'Tom Dale' }; App.RootRoute = _emberRouting.Route.extend({ actions: { showStuff: function (obj) { ok(this instanceof App.RootRoute, 'the handler is an App.HomeRoute'); // Using Ember.copy removes any private Ember vars which older IE would be confused by deepEqual((0, _emberRuntime.copy)(obj, true), { name: 'Tom Dale' }, 'the context is correct'); QUnit.start(); } } }); App.RootIndexRoute = _emberRouting.Route.extend({ model: function () { return model; } }); (0, _emberGlimmer.setTemplate)('root/index', (0, _emberTemplateCompiler.compile)('{{model.name}}')); bootApplication(); (0, _emberViews.jQuery)('#qunit-fixture a').click(); }); QUnit.test('Events can be handled by inherited event handlers', function () { expect(4); App.SuperRoute = _emberRouting.Route.extend({ actions: { foo: function () { ok(true, 'foo'); }, bar: function (msg) { equal(msg, 'HELLO'); } } }); App.RouteMixin = _emberMetal.Mixin.create({ actions: { bar: function (msg) { equal(msg, 'HELLO'); this._super(msg); } } }); App.IndexRoute = App.SuperRoute.extend(App.RouteMixin, { actions: { baz: function () { ok(true, 'baz'); } } }); bootApplication(); router.send('foo'); router.send('bar', 'HELLO'); router.send('baz'); }); QUnit.asyncTest('Actions are not triggered on the controller if a matching action name is implemented as a method', function () { Router.map(function () { this.route('home', { path: '/' }); }); var model = { name: 'Tom Dale' }; var stateIsNotCalled = true; App.HomeRoute = _emberRouting.Route.extend({ model: function () { return model; }, actions: { showStuff: function (context) { ok(stateIsNotCalled, 'an event on the state is not triggered'); deepEqual(context, { name: 'Tom Dale' }, 'an event with context is passed'); QUnit.start(); } } }); (0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('{{name}}')); var controller = _emberRuntime.Controller.extend({ showStuff: function () { stateIsNotCalled = false; ok(stateIsNotCalled, 'an event on the state is not triggered'); } }); registry.register('controller:home', controller); bootApplication(); (0, _emberViews.jQuery)('#qunit-fixture a').click(); }); QUnit.asyncTest('actions can be triggered with multiple arguments', function () { Router.map(function () { this.route('root', { path: '/' }, function () { this.route('index', { path: '/' }); }); }); App.RootRoute = _emberRouting.Route.extend({ actions: { showStuff: function (obj1, obj2) { ok(this instanceof App.RootRoute, 'the handler is an App.HomeRoute'); // Using Ember.copy removes any private Ember vars which older IE would be confused by deepEqual((0, _emberRuntime.copy)(obj1, true), { name: 'Tilde' }, 'the first context is correct'); deepEqual((0, _emberRuntime.copy)(obj2, true), { name: 'Tom Dale' }, 'the second context is correct'); QUnit.start(); } } }); App.RootIndexController = _emberRuntime.Controller.extend({ model1: { name: 'Tilde' }, model2: { name: 'Tom Dale' } }); (0, _emberGlimmer.setTemplate)('root/index', (0, _emberTemplateCompiler.compile)('{{model1.name}}')); bootApplication(); (0, _emberViews.jQuery)('#qunit-fixture a').click(); }); QUnit.test('transitioning multiple times in a single run loop only sets the URL once', function () { Router.map(function () { this.route('root', { path: '/' }); this.route('foo'); this.route('bar'); }); bootApplication(); var urlSetCount = 0; router.get('location').setURL = function (path) { urlSetCount++; (0, _emberMetal.set)(this, 'path', path); }; equal(urlSetCount, 0); (0, _emberMetal.run)(function () { router.transitionTo('foo'); router.transitionTo('bar'); }); equal(urlSetCount, 1); equal(router.get('location').getURL(), '/bar'); }); QUnit.test('navigating away triggers a url property change', function () { expect(3); Router.map(function () { this.route('root', { path: '/' }); this.route('foo', { path: '/foo' }); this.route('bar', { path: '/bar' }); }); bootApplication(); (0, _emberMetal.run)(function () { (0, _emberMetal.addObserver)(router, 'url', function () { ok(true, 'url change event was fired'); }); }); ['foo', 'bar', '/foo'].forEach(function (destination) { return (0, _emberMetal.run)(router, 'transitionTo', destination); }); }); QUnit.test('using replaceWith calls location.replaceURL if available', function () { var setCount = 0; var replaceCount = 0; Router.reopen({ location: _emberRouting.NoneLocation.create({ setURL: function (path) { setCount++; (0, _emberMetal.set)(this, 'path', path); }, replaceURL: function (path) { replaceCount++; (0, _emberMetal.set)(this, 'path', path); } }) }); Router.map(function () { this.route('root', { path: '/' }); this.route('foo'); }); bootApplication(); equal(setCount, 0); equal(replaceCount, 0); (0, _emberMetal.run)(function () { return router.replaceWith('foo'); }); equal(setCount, 0, 'should not call setURL'); equal(replaceCount, 1, 'should call replaceURL once'); equal(router.get('location').getURL(), '/foo'); }); QUnit.test('using replaceWith calls setURL if location.replaceURL is not defined', function () { var setCount = 0; Router.reopen({ location: _emberRouting.NoneLocation.create({ setURL: function (path) { setCount++; (0, _emberMetal.set)(this, 'path', path); } }) }); Router.map(function () { this.route('root', { path: '/' }); this.route('foo'); }); bootApplication(); equal(setCount, 0); (0, _emberMetal.run)(function () { return router.replaceWith('foo'); }); equal(setCount, 1, 'should call setURL once'); equal(router.get('location').getURL(), '/foo'); }); QUnit.test('Route inherits model from parent route', function () { expect(9); Router.map(function () { this.route('the_post', { path: '/posts/:post_id' }, function () { this.route('comments'); this.route('shares', { path: '/shares/:share_id', resetNamespace: true }, function () { this.route('share'); }); }); }); var posts = { 1: {}, 2: {}, 3: {} }; var shares = { 1: {}, 2: {}, 3: {} }; App.ThePostRoute = _emberRouting.Route.extend({ model: function (params) { return posts[params.post_id]; } }); App.ThePostCommentsRoute = _emberRouting.Route.extend({ afterModel: function (post) { var parent_model = this.modelFor('thePost'); equal(post, parent_model); } }); App.SharesRoute = _emberRouting.Route.extend({ model: function (params) { return shares[params.share_id]; } }); App.SharesShareRoute = _emberRouting.Route.extend({ afterModel: function (share) { var parent_model = this.modelFor('shares'); equal(share, parent_model); } }); bootApplication(); handleURL('/posts/1/comments'); handleURL('/posts/1/shares/1'); handleURL('/posts/2/comments'); handleURL('/posts/2/shares/2'); handleURL('/posts/3/comments'); handleURL('/posts/3/shares/3'); }); QUnit.test('Routes with { resetNamespace: true } inherits model from parent route', function () { expect(6); Router.map(function () { this.route('the_post', { path: '/posts/:post_id' }, function () { this.route('comments', { resetNamespace: true }, function () {}); }); }); var posts = { 1: {}, 2: {}, 3: {} }; App.ThePostRoute = _emberRouting.Route.extend({ model: function (params) { return posts[params.post_id]; } }); App.CommentsRoute = _emberRouting.Route.extend({ afterModel: function (post) { var parent_model = this.modelFor('thePost'); equal(post, parent_model); } }); bootApplication(); handleURL('/posts/1/comments'); handleURL('/posts/2/comments'); handleURL('/posts/3/comments'); }); QUnit.test('It is possible to get the model from a parent route', function () { expect(9); Router.map(function () { this.route('the_post', { path: '/posts/:post_id' }, function () { this.route('comments', { resetNamespace: true }); }); }); var post1 = {}; var post2 = {}; var post3 = {}; var currentPost = void 0; var posts = { 1: post1, 2: post2, 3: post3 }; App.ThePostRoute = _emberRouting.Route.extend({ model: function (params) { return posts[params.post_id]; } }); App.CommentsRoute = _emberRouting.Route.extend({ model: function () { // Allow both underscore / camelCase format. equal(this.modelFor('thePost'), currentPost); equal(this.modelFor('the_post'), currentPost); } }); bootApplication(); currentPost = post1; handleURL('/posts/1/comments'); currentPost = post2; handleURL('/posts/2/comments'); currentPost = post3; handleURL('/posts/3/comments'); }); QUnit.test('A redirection hook is provided', function () { Router.map(function () { this.route('choose', { path: '/' }); this.route('home'); }); var chooseFollowed = 0; var destination = void 0; App.ChooseRoute = _emberRouting.Route.extend({ redirect: function () { if (destination) { this.transitionTo(destination); } }, setupController: function () { chooseFollowed++; } }); destination = 'home'; bootApplication(); equal(chooseFollowed, 0, 'The choose route wasn\'t entered since a transition occurred'); equal((0, _emberViews.jQuery)('h3:contains(Hours)', '#qunit-fixture').length, 1, 'The home template was rendered'); equal((0, _emberUtils.getOwner)(router).lookup('controller:application').get('currentPath'), 'home'); }); QUnit.test('Redirecting from the middle of a route aborts the remainder of the routes', function () { expect(3); Router.map(function () { this.route('home'); this.route('foo', function () { this.route('bar', { resetNamespace: true }, function () { this.route('baz'); }); }); }); App.BarRoute = _emberRouting.Route.extend({ redirect: function () { this.transitionTo('home'); }, setupController: function () { ok(false, 'Should transition before setupController'); } }); App.BarBazRoute = _emberRouting.Route.extend({ enter: function () { ok(false, 'Should abort transition getting to next route'); } }); bootApplication(); handleURLAborts('/foo/bar/baz'); equal((0, _emberUtils.getOwner)(router).lookup('controller:application').get('currentPath'), 'home'); equal(router.get('location').getURL(), '/home'); }); QUnit.test('Redirecting to the current target in the middle of a route does not abort initial routing', function () { expect(5); Router.map(function () { this.route('home'); this.route('foo', function () { this.route('bar', { resetNamespace: true }, function () { this.route('baz'); }); }); }); var successCount = 0; App.BarRoute = _emberRouting.Route.extend({ redirect: function () { this.transitionTo('bar.baz').then(function () { successCount++; }); }, setupController: function () { ok(true, 'Should still invoke bar\'s setupController'); } }); App.BarBazRoute = _emberRouting.Route.extend({ setupController: function () { ok(true, 'Should still invoke bar.baz\'s setupController'); } }); bootApplication(); handleURL('/foo/bar/baz'); equal((0, _emberUtils.getOwner)(router).lookup('controller:application').get('currentPath'), 'foo.bar.baz'); equal(successCount, 1, 'transitionTo success handler was called once'); }); QUnit.test('Redirecting to the current target with a different context aborts the remainder of the routes', function () { expect(4); Router.map(function () { this.route('home'); this.route('foo', function () { this.route('bar', { path: 'bar/:id', resetNamespace: true }, function () { this.route('baz'); }); }); }); var model = { id: 2 }; var count = 0; App.BarRoute = _emberRouting.Route.extend({ afterModel: function () { if (count++ > 10) { ok(false, 'infinite loop'); } else { this.transitionTo('bar.baz', model); } } }); App.BarBazRoute = _emberRouting.Route.extend({ setupController: function () { ok(true, 'Should still invoke setupController'); } }); bootApplication(); handleURLAborts('/foo/bar/1/baz'); equal((0, _emberUtils.getOwner)(router).lookup('controller:application').get('currentPath'), 'foo.bar.baz'); equal(router.get('location').getURL(), '/foo/bar/2/baz'); }); QUnit.test('Transitioning from a parent event does not prevent currentPath from being set', function () { Router.map(function () { this.route('foo', function () { this.route('bar', { resetNamespace: true }, function () { this.route('baz'); }); this.route('qux'); }); }); App.FooRoute = _emberRouting.Route.extend({ actions: { goToQux: function () { this.transitionTo('foo.qux'); } } }); bootApplication(); var applicationController = (0, _emberUtils.getOwner)(router).lookup('controller:application'); handleURL('/foo/bar/baz'); equal(applicationController.get('currentPath'), 'foo.bar.baz'); (0, _emberMetal.run)(function () { return router.send('goToQux'); }); equal(applicationController.get('currentPath'), 'foo.qux'); equal(router.get('location').getURL(), '/foo/qux'); }); QUnit.test('Generated names can be customized when providing routes with dot notation', function () { expect(4); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('
    Index
    ')); (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('

    Home

    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('foo', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('bar', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('bar/baz', (0, _emberTemplateCompiler.compile)('

    {{name}}Bottom!

    ')); Router.map(function () { this.route('foo', { path: '/top' }, function () { this.route('bar', { path: '/middle', resetNamespace: true }, function () { this.route('baz', { path: '/bottom' }); }); }); }); App.FooRoute = _emberRouting.Route.extend({ renderTemplate: function () { ok(true, 'FooBarRoute was called'); return this._super.apply(this, arguments); } }); App.BarBazRoute = _emberRouting.Route.extend({ renderTemplate: function () { ok(true, 'BarBazRoute was called'); return this._super.apply(this, arguments); } }); App.BarController = _emberRuntime.Controller.extend({ name: 'Bar' }); App.BarBazController = _emberRuntime.Controller.extend({ name: 'BarBaz' }); bootApplication(); handleURL('/top/middle/bottom'); equal((0, _emberViews.jQuery)('.main .middle .bottom p', '#qunit-fixture').text(), 'BarBazBottom!', 'The templates were rendered into their appropriate parents'); }); QUnit.test('Child routes render into their parent route\'s template by default', function () { (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('
    Index
    ')); (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('

    Home

    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('top', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('middle', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('middle/bottom', (0, _emberTemplateCompiler.compile)('

    Bottom!

    ')); Router.map(function () { this.route('top', function () { this.route('middle', { resetNamespace: true }, function () { this.route('bottom'); }); }); }); bootApplication(); handleURL('/top/middle/bottom'); equal((0, _emberViews.jQuery)('.main .middle .bottom p', '#qunit-fixture').text(), 'Bottom!', 'The templates were rendered into their appropriate parents'); }); QUnit.test('Child routes render into specified template', function () { (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('
    Index
    ')); (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('

    Home

    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('top', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('middle', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('middle/bottom', (0, _emberTemplateCompiler.compile)('

    Bottom!

    ')); Router.map(function () { this.route('top', function () { this.route('middle', { resetNamespace: true }, function () { this.route('bottom'); }); }); }); App.MiddleBottomRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render('middle/bottom', { into: 'top' }); } }); bootApplication(); handleURL('/top/middle/bottom'); equal((0, _emberViews.jQuery)('.main .middle .bottom p', '#qunit-fixture').length, 0, 'should not render into the middle template'); equal((0, _emberViews.jQuery)('.main .middle > p', '#qunit-fixture').text(), 'Bottom!', 'The template was rendered into the top template'); }); QUnit.test('Rendering into specified template with slash notation', function () { (0, _emberGlimmer.setTemplate)('person/profile', (0, _emberTemplateCompiler.compile)('profile {{outlet}}')); (0, _emberGlimmer.setTemplate)('person/details', (0, _emberTemplateCompiler.compile)('details!')); Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render('person/profile'); this.render('person/details', { into: 'person/profile' }); } }); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture:contains(profile details!)').length, 1, 'The templates were rendered'); }); QUnit.test('Parent route context change', function () { var editCount = 0; var editedPostIds = (0, _emberRuntime.A)(); (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberGlimmer.setTemplate)('post', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberGlimmer.setTemplate)('post/index', (0, _emberTemplateCompiler.compile)('showing')); (0, _emberGlimmer.setTemplate)('post/edit', (0, _emberTemplateCompiler.compile)('editing')); Router.map(function () { this.route('posts', function () { this.route('post', { path: '/:postId', resetNamespace: true }, function () { this.route('edit'); }); }); }); App.PostsRoute = _emberRouting.Route.extend({ actions: { showPost: function (context) { this.transitionTo('post', context); } } }); App.PostRoute = _emberRouting.Route.extend({ model: function (params) { return { id: params.postId }; }, serialize: function (model) { return { postId: model.id }; }, actions: { editPost: function () { this.transitionTo('post.edit'); } } }); App.PostEditRoute = _emberRouting.Route.extend({ model: function () { var postId = this.modelFor('post').id; editedPostIds.push(postId); return null; }, setup: function () { this._super.apply(this, arguments); editCount++; } }); bootApplication(); handleURL('/posts/1'); (0, _emberMetal.run)(function () { return router.send('editPost'); }); (0, _emberMetal.run)(function () { return router.send('showPost', { id: '2' }); }); (0, _emberMetal.run)(function () { return router.send('editPost'); }); equal(editCount, 2, 'set up the edit route twice without failure'); deepEqual(editedPostIds, ['1', '2'], 'modelFor posts.post returns the right context'); }); QUnit.test('Router accounts for rootURL on page load when using history location', function () { var rootURL = window.location.pathname + '/app'; var postsTemplateRendered = false; var setHistory = void 0, HistoryTestLocation = void 0; setHistory = function (obj, path) { obj.set('history', { state: { path: path } }); }; // Create new implementation that extends HistoryLocation // and set current location to rootURL + '/posts' HistoryTestLocation = _emberRouting.HistoryLocation.extend({ initState: function () { var path = rootURL + '/posts'; setHistory(this, path); this.set('location', { pathname: path, href: 'http://localhost/' + path }); }, replaceState: function (path) { setHistory(this, path); }, pushState: function (path) { setHistory(this, path); } }); registry.register('location:historyTest', HistoryTestLocation); Router.reopen({ location: 'historyTest', rootURL: rootURL }); Router.map(function () { this.route('posts', { path: '/posts' }); }); App.PostsRoute = _emberRouting.Route.extend({ model: function () {}, renderTemplate: function () { postsTemplateRendered = true; } }); bootApplication(); ok(postsTemplateRendered, 'Posts route successfully stripped from rootURL'); }); QUnit.test('The rootURL is passed properly to the location implementation', function () { expect(1); var rootURL = '/blahzorz'; var HistoryTestLocation = void 0; HistoryTestLocation = _emberRouting.HistoryLocation.extend({ rootURL: 'this is not the URL you are looking for', initState: function () { equal(this.get('rootURL'), rootURL); } }); registry.register('location:history-test', HistoryTestLocation); Router.reopen({ location: 'history-test', rootURL: rootURL, _doURLTransition: function () {} }); bootApplication(); }); QUnit.test('Only use route rendered into main outlet for default into property on child', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet \'menu\'}}{{outlet}}')); (0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberGlimmer.setTemplate)('posts/index', (0, _emberTemplateCompiler.compile)('

    postsIndex

    ')); (0, _emberGlimmer.setTemplate)('posts/menu', (0, _emberTemplateCompiler.compile)('
    postsMenu
    ')); Router.map(function () { this.route('posts', function () {}); }); App.PostsRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render(); this.render('posts/menu', { into: 'application', outlet: 'menu' }); } }); bootApplication(); handleURL('/posts'); equal((0, _emberViews.jQuery)('div.posts-menu:contains(postsMenu)', '#qunit-fixture').length, 1, 'The posts/menu template was rendered'); equal((0, _emberViews.jQuery)('p.posts-index:contains(postsIndex)', '#qunit-fixture').length, 1, 'The posts/index template was rendered'); }); QUnit.test('Generating a URL should not affect currentModel', function () { Router.map(function () { this.route('post', { path: '/posts/:post_id' }); }); var posts = { 1: { id: 1 }, 2: { id: 2 } }; App.PostRoute = _emberRouting.Route.extend({ model: function (params) { return posts[params.post_id]; } }); bootApplication(); handleURL('/posts/1'); var route = container.lookup('route:post'); equal(route.modelFor('post'), posts[1]); var url = router.generate('post', posts[2]); equal(url, '/posts/2'); equal(route.modelFor('post'), posts[1]); }); QUnit.test('Generated route should be an instance of App.Route if provided', function () { var generatedRoute = void 0; Router.map(function () { this.route('posts'); }); App.Route = _emberRouting.Route.extend(); bootApplication(); handleURL('/posts'); generatedRoute = container.lookup('route:posts'); ok(generatedRoute instanceof App.Route, 'should extend the correct route'); }); QUnit.test('Nested index route is not overriden by parent\'s implicit index route', function () { Router.map(function () { this.route('posts', function () { this.route('index', { path: ':category' }); }); }); bootApplication(); (0, _emberMetal.run)(function () { return router.transitionTo('posts', { category: 'emberjs' }); }); deepEqual(router.location.path, '/posts/emberjs'); }); QUnit.test('Application template does not duplicate when re-rendered', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('

    I Render Once

    {{outlet}}')); Router.map(function () { this.route('posts'); }); App.ApplicationRoute = _emberRouting.Route.extend({ model: function () { return (0, _emberRuntime.A)(); } }); bootApplication(); // should cause application template to re-render handleURL('/posts'); equal((0, _emberViews.jQuery)('h3:contains(I Render Once)').length, 1); }); QUnit.test('Child routes should render inside the application template if the application template causes a redirect', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('

    App

    {{outlet}}')); (0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('posts')); Router.map(function () { this.route('posts'); this.route('photos'); }); App.ApplicationRoute = _emberRouting.Route.extend({ afterModel: function () { this.transitionTo('posts'); } }); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture > div').text(), 'App posts'); }); QUnit.test('The template is not re-rendered when the route\'s context changes', function () { Router.map(function () { this.route('page', { path: '/page/:name' }); }); App.PageRoute = _emberRouting.Route.extend({ model: function (params) { return _emberRuntime.Object.create({ name: params.name }); } }); var insertionCount = 0; App.FooBarComponent = _emberGlimmer.Component.extend({ didInsertElement: function () { insertionCount += 1; } }); (0, _emberGlimmer.setTemplate)('page', (0, _emberTemplateCompiler.compile)('

    {{model.name}}{{foo-bar}}

    ')); bootApplication(); handleURL('/page/first'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'first'); equal(insertionCount, 1); handleURL('/page/second'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'second'); equal(insertionCount, 1, 'view should have inserted only once'); (0, _emberMetal.run)(function () { return router.transitionTo('page', _emberRuntime.Object.create({ name: 'third' })); }); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'third'); equal(insertionCount, 1, 'view should still have inserted only once'); }); QUnit.test('The template is not re-rendered when two routes present the exact same template & controller', function () { Router.map(function () { this.route('first'); this.route('second'); this.route('third'); this.route('fourth'); }); // Note add a component to test insertion var insertionCount = 0; App.XInputComponent = _emberGlimmer.Component.extend({ didInsertElement: function () { insertionCount += 1; } }); App.SharedRoute = _emberRouting.Route.extend({ setupController: function () { this.controllerFor('shared').set('message', 'This is the ' + this.routeName + ' message'); }, renderTemplate: function () { this.render('shared', { controller: 'shared' }); } }); App.FirstRoute = App.SharedRoute.extend(); App.SecondRoute = App.SharedRoute.extend(); App.ThirdRoute = App.SharedRoute.extend(); App.FourthRoute = App.SharedRoute.extend(); App.SharedController = _emberRuntime.Controller.extend(); (0, _emberGlimmer.setTemplate)('shared', (0, _emberTemplateCompiler.compile)('

    {{message}}{{x-input}}

    ')); bootApplication(); handleURL('/first'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'This is the first message'); equal(insertionCount, 1, 'expected one assertion'); // Transition by URL handleURL('/second'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'This is the second message'); equal(insertionCount, 1, 'expected one assertion'); // Then transition directly by route name (0, _emberMetal.run)(function () { router.transitionTo('third').then(function () { ok(true, 'expected transition'); }, function (reason) { ok(false, 'unexpected transition failure: ', QUnit.jsDump.parse(reason)); }); }); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'This is the third message'); equal(insertionCount, 1, 'expected one assertion'); // Lastly transition to a different view, with the same controller and template handleURL('/fourth'); equal(insertionCount, 1, 'expected one assertion'); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'This is the fourth message'); }); QUnit.test('ApplicationRoute with model does not proxy the currentPath', function () { var model = {}; var currentPath = void 0; App.ApplicationRoute = _emberRouting.Route.extend({ model: function () { return model; } }); App.ApplicationController = _emberRuntime.Controller.extend({ currentPathDidChange: (0, _emberMetal.observer)('currentPath', function () { currentPath = (0, _emberMetal.get)(this, 'currentPath'); }) }); bootApplication(); equal(currentPath, 'index', 'currentPath is index'); equal('currentPath' in model, false, 'should have defined currentPath on controller'); }); QUnit.test('Promises encountered on app load put app into loading state until resolved', function () { expect(2); var deferred = _emberRuntime.RSVP.defer(); App.IndexRoute = _emberRouting.Route.extend({ model: function () { return deferred.promise; } }); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('

    INDEX

    ')); (0, _emberGlimmer.setTemplate)('loading', (0, _emberTemplateCompiler.compile)('

    LOADING

    ')); bootApplication(); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'LOADING', 'The loading state is displaying.'); (0, _emberMetal.run)(deferred.resolve); equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'INDEX', 'The index route is display.'); }); QUnit.test('Route should tear down multiple outlets', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet \'menu\'}}{{outlet}}{{outlet \'footer\'}}')); (0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberGlimmer.setTemplate)('users', (0, _emberTemplateCompiler.compile)('users')); (0, _emberGlimmer.setTemplate)('posts/index', (0, _emberTemplateCompiler.compile)('

    postsIndex

    ')); (0, _emberGlimmer.setTemplate)('posts/menu', (0, _emberTemplateCompiler.compile)('
    postsMenu
    ')); (0, _emberGlimmer.setTemplate)('posts/footer', (0, _emberTemplateCompiler.compile)('')); Router.map(function () { this.route('posts', function () {}); this.route('users', function () {}); }); App.PostsRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render('posts/menu', { into: 'application', outlet: 'menu' }); this.render(); this.render('posts/footer', { into: 'application', outlet: 'footer' }); } }); bootApplication(); handleURL('/posts'); equal((0, _emberViews.jQuery)('div.posts-menu:contains(postsMenu)', '#qunit-fixture').length, 1, 'The posts/menu template was rendered'); equal((0, _emberViews.jQuery)('p.posts-index:contains(postsIndex)', '#qunit-fixture').length, 1, 'The posts/index template was rendered'); equal((0, _emberViews.jQuery)('div.posts-footer:contains(postsFooter)', '#qunit-fixture').length, 1, 'The posts/footer template was rendered'); handleURL('/users'); equal((0, _emberViews.jQuery)('div.posts-menu:contains(postsMenu)', '#qunit-fixture').length, 0, 'The posts/menu template was removed'); equal((0, _emberViews.jQuery)('p.posts-index:contains(postsIndex)', '#qunit-fixture').length, 0, 'The posts/index template was removed'); equal((0, _emberViews.jQuery)('div.posts-footer:contains(postsFooter)', '#qunit-fixture').length, 0, 'The posts/footer template was removed'); }); QUnit.test('Route will assert if you try to explicitly render {into: ...} a missing template', function () { expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./); Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render({ into: 'nonexistent' }); } }); expectAssertion(function () { return bootApplication(); }, 'You attempted to render into \'nonexistent\' but it was not found'); }); QUnit.test('Route supports clearing outlet explicitly', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}{{outlet \'modal\'}}')); (0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberGlimmer.setTemplate)('users', (0, _emberTemplateCompiler.compile)('users')); (0, _emberGlimmer.setTemplate)('posts/index', (0, _emberTemplateCompiler.compile)('
    postsIndex {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('posts/modal', (0, _emberTemplateCompiler.compile)('
    postsModal
    ')); (0, _emberGlimmer.setTemplate)('posts/extra', (0, _emberTemplateCompiler.compile)('
    postsExtra
    ')); Router.map(function () { this.route('posts', function () {}); this.route('users', function () {}); }); App.PostsRoute = _emberRouting.Route.extend({ actions: { showModal: function () { this.render('posts/modal', { into: 'application', outlet: 'modal' }); }, hideModal: function () { this.disconnectOutlet({ outlet: 'modal', parentView: 'application' }); } } }); App.PostsIndexRoute = _emberRouting.Route.extend({ actions: { showExtra: function () { this.render('posts/extra', { into: 'posts/index' }); }, hideExtra: function () { this.disconnectOutlet({ parentView: 'posts/index' }); } } }); bootApplication(); handleURL('/posts'); equal((0, _emberViews.jQuery)('div.posts-index:contains(postsIndex)', '#qunit-fixture').length, 1, 'The posts/index template was rendered'); (0, _emberMetal.run)(function () { return router.send('showModal'); }); equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 1, 'The posts/modal template was rendered'); (0, _emberMetal.run)(function () { return router.send('showExtra'); }); equal((0, _emberViews.jQuery)('div.posts-extra:contains(postsExtra)', '#qunit-fixture').length, 1, 'The posts/extra template was rendered'); (0, _emberMetal.run)(function () { return router.send('hideModal'); }); equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 0, 'The posts/modal template was removed'); (0, _emberMetal.run)(function () { return router.send('hideExtra'); }); equal((0, _emberViews.jQuery)('div.posts-extra:contains(postsExtra)', '#qunit-fixture').length, 0, 'The posts/extra template was removed'); (0, _emberMetal.run)(function () { router.send('showModal'); }); equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 1, 'The posts/modal template was rendered'); (0, _emberMetal.run)(function () { router.send('showExtra'); }); equal((0, _emberViews.jQuery)('div.posts-extra:contains(postsExtra)', '#qunit-fixture').length, 1, 'The posts/extra template was rendered'); handleURL('/users'); equal((0, _emberViews.jQuery)('div.posts-index:contains(postsIndex)', '#qunit-fixture').length, 0, 'The posts/index template was removed'); equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 0, 'The posts/modal template was removed'); equal((0, _emberViews.jQuery)('div.posts-extra:contains(postsExtra)', '#qunit-fixture').length, 0, 'The posts/extra template was removed'); }); QUnit.test('Route supports clearing outlet using string parameter', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}{{outlet \'modal\'}}')); (0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberGlimmer.setTemplate)('users', (0, _emberTemplateCompiler.compile)('users')); (0, _emberGlimmer.setTemplate)('posts/index', (0, _emberTemplateCompiler.compile)('
    postsIndex {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('posts/modal', (0, _emberTemplateCompiler.compile)('
    postsModal
    ')); Router.map(function () { this.route('posts', function () {}); this.route('users', function () {}); }); App.PostsRoute = _emberRouting.Route.extend({ actions: { showModal: function () { this.render('posts/modal', { into: 'application', outlet: 'modal' }); }, hideModal: function () { this.disconnectOutlet('modal'); } } }); bootApplication(); handleURL('/posts'); equal((0, _emberViews.jQuery)('div.posts-index:contains(postsIndex)', '#qunit-fixture').length, 1, 'The posts/index template was rendered'); (0, _emberMetal.run)(function () { return router.send('showModal'); }); equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 1, 'The posts/modal template was rendered'); (0, _emberMetal.run)(function () { return router.send('hideModal'); }); equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 0, 'The posts/modal template was removed'); handleURL('/users'); equal((0, _emberViews.jQuery)('div.posts-index:contains(postsIndex)', '#qunit-fixture').length, 0, 'The posts/index template was removed'); equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 0, 'The posts/modal template was removed'); }); QUnit.test('Route silently fails when cleaning an outlet from an inactive view', function () { expect(1); // handleURL (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet \'modal\'}}')); (0, _emberGlimmer.setTemplate)('modal', (0, _emberTemplateCompiler.compile)('A Yo.')); Router.map(function () { this.route('posts'); }); App.PostsRoute = _emberRouting.Route.extend({ actions: { hideSelf: function () { this.disconnectOutlet({ outlet: 'main', parentView: 'application' }); }, showModal: function () { this.render('modal', { into: 'posts', outlet: 'modal' }); }, hideModal: function () { this.disconnectOutlet({ outlet: 'modal', parentView: 'posts' }); } } }); bootApplication(); handleURL('/posts'); (0, _emberMetal.run)(function () { return router.send('showModal'); }); (0, _emberMetal.run)(function () { return router.send('hideSelf'); }); (0, _emberMetal.run)(function () { return router.send('hideModal'); }); }); QUnit.test('Router `willTransition` hook passes in cancellable transition', function () { // Should hit willTransition 3 times, once for the initial route, and then 2 more times // for the two handleURL calls below expect(3); Router.map(function () { this.route('nork'); this.route('about'); }); Router.reopen({ init: function () { this._super(); this.on('willTransition', this.testWillTransitionHook); }, testWillTransitionHook: function (transition, url) { ok(true, 'willTransition was called ' + url); transition.abort(); } }); App.LoadingRoute = _emberRouting.Route.extend({ activate: function () { ok(false, 'LoadingRoute was not entered'); } }); App.NorkRoute = _emberRouting.Route.extend({ activate: function () { ok(false, 'NorkRoute was not entered'); } }); App.AboutRoute = _emberRouting.Route.extend({ activate: function () { ok(false, 'AboutRoute was not entered'); } }); bootApplication(); // Attempted transitions out of index should abort. (0, _emberMetal.run)(router, 'handleURL', '/nork'); (0, _emberMetal.run)(router, 'handleURL', '/about'); }); QUnit.test('Aborting/redirecting the transition in `willTransition` prevents LoadingRoute from being entered', function () { expect(8); Router.map(function () { this.route('nork'); this.route('about'); }); var redirect = false; App.IndexRoute = _emberRouting.Route.extend({ actions: { willTransition: function (transition) { ok(true, 'willTransition was called'); if (redirect) { // router.js won't refire `willTransition` for this redirect this.transitionTo('about'); } else { transition.abort(); } } } }); var deferred = null; App.LoadingRoute = _emberRouting.Route.extend({ activate: function () { ok(deferred, 'LoadingRoute should be entered at this time'); }, deactivate: function () { ok(true, 'LoadingRoute was exited'); } }); App.NorkRoute = _emberRouting.Route.extend({ activate: function () { ok(true, 'NorkRoute was entered'); } }); App.AboutRoute = _emberRouting.Route.extend({ activate: function () { ok(true, 'AboutRoute was entered'); }, model: function () { if (deferred) { return deferred.promise; } } }); bootApplication(); // Attempted transitions out of index should abort. (0, _emberMetal.run)(router, 'transitionTo', 'nork'); (0, _emberMetal.run)(router, 'handleURL', '/nork'); // Attempted transitions out of index should redirect to about redirect = true; (0, _emberMetal.run)(router, 'transitionTo', 'nork'); (0, _emberMetal.run)(router, 'transitionTo', 'index'); // Redirected transitions out of index to a route with a // promise model should pause the transition and // activate LoadingRoute deferred = _emberRuntime.RSVP.defer(); (0, _emberMetal.run)(router, 'transitionTo', 'nork'); (0, _emberMetal.run)(deferred.resolve); }); QUnit.test('`didTransition` event fires on the router', function () { expect(3); Router.map(function () { this.route('nork'); }); router = container.lookup('router:main'); router.one('didTransition', function () { ok(true, 'didTransition fired on initial routing'); }); bootApplication(); router.one('didTransition', function () { ok(true, 'didTransition fired on the router'); equal(router.get('url'), '/nork', 'The url property is updated by the time didTransition fires'); }); (0, _emberMetal.run)(router, 'transitionTo', 'nork'); }); QUnit.test('`didTransition` can be reopened', function () { expect(1); Router.map(function () { this.route('nork'); }); Router.reopen({ didTransition: function () { this._super.apply(this, arguments); ok(true, 'reopened didTransition was called'); } }); bootApplication(); }); QUnit.test('`activate` event fires on the route', function () { expect(2); var eventFired = 0; Router.map(function () { this.route('nork'); }); App.NorkRoute = _emberRouting.Route.extend({ init: function () { this._super.apply(this, arguments); this.on('activate', function () { equal(++eventFired, 1, 'activate event is fired once'); }); }, activate: function () { ok(true, 'activate hook is called'); } }); bootApplication(); (0, _emberMetal.run)(router, 'transitionTo', 'nork'); }); QUnit.test('`deactivate` event fires on the route', function () { expect(2); var eventFired = 0; Router.map(function () { this.route('nork'); this.route('dork'); }); App.NorkRoute = _emberRouting.Route.extend({ init: function () { this._super.apply(this, arguments); this.on('deactivate', function () { equal(++eventFired, 1, 'deactivate event is fired once'); }); }, deactivate: function () { ok(true, 'deactivate hook is called'); } }); bootApplication(); (0, _emberMetal.run)(router, 'transitionTo', 'nork'); (0, _emberMetal.run)(router, 'transitionTo', 'dork'); }); QUnit.test('Actions can be handled by inherited action handlers', function () { expect(4); App.SuperRoute = _emberRouting.Route.extend({ actions: { foo: function () { ok(true, 'foo'); }, bar: function (msg) { equal(msg, 'HELLO'); } } }); App.RouteMixin = _emberMetal.Mixin.create({ actions: { bar: function (msg) { equal(msg, 'HELLO'); this._super(msg); } } }); App.IndexRoute = App.SuperRoute.extend(App.RouteMixin, { actions: { baz: function () { ok(true, 'baz'); } } }); bootApplication(); router.send('foo'); router.send('bar', 'HELLO'); router.send('baz'); }); QUnit.test('transitionTo returns Transition when passed a route name', function () { expect(1); Router.map(function () { this.route('root', { path: '/' }); this.route('bar'); }); bootApplication(); var transition = (0, _emberMetal.run)(function () { return router.transitionTo('bar'); }); equal(transition instanceof _router.Transition, true); }); QUnit.test('transitionTo returns Transition when passed a url', function () { expect(1); Router.map(function () { this.route('root', { path: '/' }); this.route('bar', function () { this.route('baz'); }); }); bootApplication(); var transition = (0, _emberMetal.run)(function () { return router.transitionTo('/bar/baz'); }); equal(transition instanceof _router.Transition, true); }); QUnit.test('currentRouteName is a property installed on ApplicationController that can be used in transitionTo', function () { expect(24); Router.map(function () { this.route('be', function () { this.route('excellent', { resetNamespace: true }, function () { this.route('to', { resetNamespace: true }, function () { this.route('each', { resetNamespace: true }, function () { this.route('other'); }); }); }); }); }); bootApplication(); var appController = (0, _emberUtils.getOwner)(router).lookup('controller:application'); function transitionAndCheck(path, expectedPath, expectedRouteName) { if (path) { (0, _emberMetal.run)(router, 'transitionTo', path); } equal(appController.get('currentPath'), expectedPath); equal(appController.get('currentRouteName'), expectedRouteName); } transitionAndCheck(null, 'index', 'index'); transitionAndCheck('/be', 'be.index', 'be.index'); transitionAndCheck('/be/excellent', 'be.excellent.index', 'excellent.index'); transitionAndCheck('/be/excellent/to', 'be.excellent.to.index', 'to.index'); transitionAndCheck('/be/excellent/to/each', 'be.excellent.to.each.index', 'each.index'); transitionAndCheck('/be/excellent/to/each/other', 'be.excellent.to.each.other', 'each.other'); transitionAndCheck('index', 'index', 'index'); transitionAndCheck('be', 'be.index', 'be.index'); transitionAndCheck('excellent', 'be.excellent.index', 'excellent.index'); transitionAndCheck('to.index', 'be.excellent.to.index', 'to.index'); transitionAndCheck('each', 'be.excellent.to.each.index', 'each.index'); transitionAndCheck('each.other', 'be.excellent.to.each.other', 'each.other'); }); QUnit.test('Route model hook finds the same model as a manual find', function () { var Post = void 0; App.Post = _emberRuntime.Object.extend(); App.Post.reopenClass({ find: function () { Post = this; return {}; } }); Router.map(function () { this.route('post', { path: '/post/:post_id' }); }); bootApplication(); handleURL('/post/1'); equal(App.Post, Post); }); QUnit.test('Routes can refresh themselves causing their model hooks to be re-run', function () { Router.map(function () { this.route('parent', { path: '/parent/:parent_id' }, function () { this.route('child'); }); }); var appcount = 0; App.ApplicationRoute = _emberRouting.Route.extend({ model: function () { ++appcount; } }); var parentcount = 0; App.ParentRoute = _emberRouting.Route.extend({ model: function (params) { equal(params.parent_id, '123'); ++parentcount; }, actions: { refreshParent: function () { this.refresh(); } } }); var childcount = 0; App.ParentChildRoute = _emberRouting.Route.extend({ model: function () { ++childcount; } }); bootApplication(); equal(appcount, 1); equal(parentcount, 0); equal(childcount, 0); (0, _emberMetal.run)(router, 'transitionTo', 'parent.child', '123'); equal(appcount, 1); equal(parentcount, 1); equal(childcount, 1); (0, _emberMetal.run)(router, 'send', 'refreshParent'); equal(appcount, 1); equal(parentcount, 2); equal(childcount, 2); }); QUnit.test('Specifying non-existent controller name in route#render throws', function () { expect(1); Router.map(function () { this.route('home', { path: '/' }); }); App.HomeRoute = _emberRouting.Route.extend({ renderTemplate: function () { try { this.render('homepage', { controller: 'stefanpenneristhemanforme' }); } catch (e) { equal(e.message, 'You passed `controller: \'stefanpenneristhemanforme\'` into the `render` method, but no such controller could be found.'); } } }); bootApplication(); }); QUnit.test('Redirecting with null model doesn\'t error out', function () { Router.map(function () { this.route('home', { path: '/' }); this.route('about', { path: '/about/:hurhurhur' }); }); App.AboutRoute = _emberRouting.Route.extend({ serialize: function (model) { if (model === null) { return { hurhurhur: 'TreeklesMcGeekles' }; } } }); App.HomeRoute = _emberRouting.Route.extend({ beforeModel: function () { this.transitionTo('about', null); } }); bootApplication(); equal(router.get('location.path'), '/about/TreeklesMcGeekles'); }); QUnit.test('rejecting the model hooks promise with a non-error prints the `message` property', function () { expect(5); var rejectedMessage = 'OMG!! SOOOOOO BAD!!!!'; var rejectedStack = 'Yeah, buddy: stack gets printed too.'; Router.map(function () { this.route('yippie', { path: '/' }); }); _emberConsole.default.error = function (initialMessage, errorMessage, errorStack) { equal(initialMessage, 'Error while processing route: yippie', 'a message with the current route name is printed'); equal(errorMessage, rejectedMessage, 'the rejected reason\'s message property is logged'); equal(errorStack, rejectedStack, 'the rejected reason\'s stack property is logged'); }; App.YippieRoute = _emberRouting.Route.extend({ model: function () { return _emberRuntime.RSVP.reject({ message: rejectedMessage, stack: rejectedStack }); } }); throws(function () { bootApplication(); }, function (err) { equal(err.message, rejectedMessage); return true; }, 'expected an exception'); }); QUnit.test('rejecting the model hooks promise with an error with `errorThrown` property prints `errorThrown.message` property', function () { expect(5); var rejectedMessage = 'OMG!! SOOOOOO BAD!!!!'; var rejectedStack = 'Yeah, buddy: stack gets printed too.'; Router.map(function () { this.route('yippie', { path: '/' }); }); _emberConsole.default.error = function (initialMessage, errorMessage, errorStack) { equal(initialMessage, 'Error while processing route: yippie', 'a message with the current route name is printed'); equal(errorMessage, rejectedMessage, 'the rejected reason\'s message property is logged'); equal(errorStack, rejectedStack, 'the rejected reason\'s stack property is logged'); }; App.YippieRoute = _emberRouting.Route.extend({ model: function () { return _emberRuntime.RSVP.reject({ errorThrown: { message: rejectedMessage, stack: rejectedStack } }); } }); throws(function () { return bootApplication(); }, function (err) { equal(err.message, rejectedMessage); return true; }, 'expected an exception'); }); QUnit.test('rejecting the model hooks promise with no reason still logs error', function () { Router.map(function () { this.route('wowzers', { path: '/' }); }); _emberConsole.default.error = function (initialMessage) { equal(initialMessage, 'Error while processing route: wowzers', 'a message with the current route name is printed'); }; App.WowzersRoute = _emberRouting.Route.extend({ model: function () { return _emberRuntime.RSVP.reject(); } }); bootApplication(); }); QUnit.test('rejecting the model hooks promise with a string shows a good error', function () { expect(3); var originalLoggerError = _emberConsole.default.error; var rejectedMessage = 'Supercalifragilisticexpialidocious'; Router.map(function () { this.route('yondo', { path: '/' }); }); _emberConsole.default.error = function (initialMessage, errorMessage) { equal(initialMessage, 'Error while processing route: yondo', 'a message with the current route name is printed'); equal(errorMessage, rejectedMessage, 'the rejected reason\'s message property is logged'); }; App.YondoRoute = _emberRouting.Route.extend({ model: function () { return _emberRuntime.RSVP.reject(rejectedMessage); } }); throws(function () { return bootApplication(); }, rejectedMessage, 'expected an exception'); _emberConsole.default.error = originalLoggerError; }); QUnit.test('willLeave, willChangeContext, willChangeModel actions don\'t fire unless feature flag enabled', function () { expect(1); App.Router.map(function () { this.route('about'); }); function shouldNotFire() { ok(false, 'this action shouldn\'t have been received'); } App.IndexRoute = _emberRouting.Route.extend({ actions: { willChangeModel: shouldNotFire, willChangeContext: shouldNotFire, willLeave: shouldNotFire } }); App.AboutRoute = _emberRouting.Route.extend({ setupController: function () { ok(true, 'about route was entered'); } }); bootApplication(); (0, _emberMetal.run)(router, 'transitionTo', 'about'); }); QUnit.test('Errors in transitionTo within redirect hook are logged', function () { expect(4); var actual = []; Router.map(function () { this.route('yondo', { path: '/' }); this.route('stink-bomb'); }); App.YondoRoute = _emberRouting.Route.extend({ redirect: function () { this.transitionTo('stink-bomb', { something: 'goes boom' }); } }); _emberConsole.default.error = function () { // push the arguments onto an array so we can detect if the error gets logged twice actual.push(arguments); }; throws(function () { return bootApplication(); }, /More context objects were passed/); equal(actual.length, 1, 'the error is only logged once'); equal(actual[0][0], 'Error while processing route: yondo', 'source route is printed'); ok(actual[0][1].match(/More context objects were passed than there are dynamic segments for the route: stink-bomb/), 'the error is printed'); }); QUnit.test('Errors in transition show error template if available', function () { (0, _emberGlimmer.setTemplate)('error', (0, _emberTemplateCompiler.compile)('
    Error!
    ')); Router.map(function () { this.route('yondo', { path: '/' }); this.route('stink-bomb'); }); App.YondoRoute = _emberRouting.Route.extend({ redirect: function () { this.transitionTo('stink-bomb', { something: 'goes boom' }); } }); throws(function () { return bootApplication(); }, /More context objects were passed/); equal((0, _emberViews.jQuery)('#error').length, 1, 'Error template was rendered.'); }); QUnit.test('Route#resetController gets fired when changing models and exiting routes', function () { expect(4); Router.map(function () { this.route('a', function () { this.route('b', { path: '/b/:id', resetNamespace: true }, function () {}); this.route('c', { path: '/c/:id', resetNamespace: true }, function () {}); }); this.route('out'); }); var calls = []; var SpyRoute = _emberRouting.Route.extend({ setupController: function () { calls.push(['setup', this.routeName]); }, resetController: function () { calls.push(['reset', this.routeName]); } }); App.ARoute = SpyRoute.extend(); App.BRoute = SpyRoute.extend(); App.CRoute = SpyRoute.extend(); App.OutRoute = SpyRoute.extend(); bootApplication(); deepEqual(calls, []); (0, _emberMetal.run)(router, 'transitionTo', 'b', 'b-1'); deepEqual(calls, [['setup', 'a'], ['setup', 'b']]); calls.length = 0; (0, _emberMetal.run)(router, 'transitionTo', 'c', 'c-1'); deepEqual(calls, [['reset', 'b'], ['setup', 'c']]); calls.length = 0; (0, _emberMetal.run)(router, 'transitionTo', 'out'); deepEqual(calls, [['reset', 'c'], ['reset', 'a'], ['setup', 'out']]); }); QUnit.test('Exception during initialization of non-initial route is not swallowed', function () { Router.map(function () { this.route('boom'); }); App.BoomRoute = _emberRouting.Route.extend({ init: function () { throw new Error('boom!'); } }); bootApplication(); throws(function () { return (0, _emberMetal.run)(router, 'transitionTo', 'boom'); }, /\bboom\b/); }); QUnit.test('Exception during load of non-initial route is not swallowed', function () { Router.map(function () { this.route('boom'); }); var lookup = container.lookup; container.lookup = function () { if (arguments[0] === 'route:boom') { throw new Error('boom!'); } return lookup.apply(this, arguments); }; App.BoomRoute = _emberRouting.Route.extend({ init: function () { throw new Error('boom!'); } }); bootApplication(); throws(function () { return (0, _emberMetal.run)(router, 'transitionTo', 'boom'); }); }); QUnit.test('Exception during initialization of initial route is not swallowed', function () { Router.map(function () { this.route('boom', { path: '/' }); }); App.BoomRoute = _emberRouting.Route.extend({ init: function () { throw new Error('boom!'); } }); throws(function () { return bootApplication(); }, /\bboom\b/); }); QUnit.test('Exception during load of initial route is not swallowed', function () { Router.map(function () { this.route('boom', { path: '/' }); }); var lookup = container.lookup; container.lookup = function () { if (arguments[0] === 'route:boom') { throw new Error('boom!'); } return lookup.apply(this, arguments); }; App.BoomRoute = _emberRouting.Route.extend({ init: function () { throw new Error('boom!'); } }); throws(function () { return bootApplication(); }, /\bboom\b/); }); QUnit.test('{{outlet}} works when created after initial render', function () { (0, _emberGlimmer.setTemplate)('sample', (0, _emberTemplateCompiler.compile)('Hi{{#if showTheThing}}{{outlet}}{{/if}}Bye')); (0, _emberGlimmer.setTemplate)('sample/inner', (0, _emberTemplateCompiler.compile)('Yay')); (0, _emberGlimmer.setTemplate)('sample/inner2', (0, _emberTemplateCompiler.compile)('Boo')); Router.map(function () { this.route('sample', { path: '/' }, function () { this.route('inner', { path: '/' }); this.route('inner2', { path: '/2' }); }); }); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'HiBye', 'initial render'); (0, _emberMetal.run)(function () { return container.lookup('controller:sample').set('showTheThing', true); }); equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'HiYayBye', 'second render'); handleURL('/2'); equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'HiBooBye', 'third render'); }); QUnit.test('Can render into a named outlet at the top level', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('A-{{outlet}}-B-{{outlet "other"}}-C')); (0, _emberGlimmer.setTemplate)('modal', (0, _emberTemplateCompiler.compile)('Hello world')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('The index')); registry.register('route:application', _emberRouting.Route.extend({ renderTemplate: function () { this.render(); this.render('modal', { into: 'application', outlet: 'other' }); } })); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A-The index-B-Hello world-C', 'initial render'); }); QUnit.test('Can disconnect a named outlet at the top level', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('A-{{outlet}}-B-{{outlet "other"}}-C')); (0, _emberGlimmer.setTemplate)('modal', (0, _emberTemplateCompiler.compile)('Hello world')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('The index')); registry.register('route:application', _emberRouting.Route.extend({ renderTemplate: function () { this.render(); this.render('modal', { into: 'application', outlet: 'other' }); }, actions: { banish: function () { this.disconnectOutlet({ parentView: 'application', outlet: 'other' }); } } })); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A-The index-B-Hello world-C', 'initial render'); (0, _emberMetal.run)(router, 'send', 'banish'); equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A-The index-B--C', 'second render'); }); QUnit.test('Can render into a named outlet at the top level, with empty main outlet', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('A-{{outlet}}-B-{{outlet "other"}}-C')); (0, _emberGlimmer.setTemplate)('modal', (0, _emberTemplateCompiler.compile)('Hello world')); Router.map(function () { this.route('hasNoTemplate', { path: '/' }); }); registry.register('route:application', _emberRouting.Route.extend({ renderTemplate: function () { this.render(); this.render('modal', { into: 'application', outlet: 'other' }); } })); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A--B-Hello world-C', 'initial render'); }); QUnit.test('Can render into a named outlet at the top level, later', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('A-{{outlet}}-B-{{outlet "other"}}-C')); (0, _emberGlimmer.setTemplate)('modal', (0, _emberTemplateCompiler.compile)('Hello world')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('The index')); registry.register('route:application', _emberRouting.Route.extend({ actions: { launch: function () { this.render('modal', { into: 'application', outlet: 'other' }); } } })); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A-The index-B--C', 'initial render'); (0, _emberMetal.run)(router, 'send', 'launch'); equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A-The index-B-Hello world-C', 'second render'); }); QUnit.test('Can render routes with no \'main\' outlet and their children', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('
    {{outlet "app"}}
    ')); (0, _emberGlimmer.setTemplate)('app', (0, _emberTemplateCompiler.compile)('
    {{outlet "common"}}
    {{outlet "sub"}}
    ')); (0, _emberGlimmer.setTemplate)('common', (0, _emberTemplateCompiler.compile)('
    ')); (0, _emberGlimmer.setTemplate)('sub', (0, _emberTemplateCompiler.compile)('
    ')); Router.map(function () { this.route('app', { path: '/app' }, function () { this.route('sub', { path: '/sub', resetNamespace: true }); }); }); App.AppRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render('app', { outlet: 'app', into: 'application' }); this.render('common', { outlet: 'common', into: 'app' }); } }); App.SubRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render('sub', { outlet: 'sub', into: 'app' }); } }); bootApplication(); handleURL('/app'); equal((0, _emberViews.jQuery)('#app-common #common').length, 1, 'Finds common while viewing /app'); handleURL('/app/sub'); equal((0, _emberViews.jQuery)('#app-common #common').length, 1, 'Finds common while viewing /app/sub'); equal((0, _emberViews.jQuery)('#app-sub #sub').length, 1, 'Finds sub while viewing /app/sub'); }); QUnit.test('Tolerates stacked renders', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}{{outlet "modal"}}')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('hi')); (0, _emberGlimmer.setTemplate)('layer', (0, _emberTemplateCompiler.compile)('layer')); App.ApplicationRoute = _emberRouting.Route.extend({ actions: { openLayer: function () { this.render('layer', { into: 'application', outlet: 'modal' }); }, close: function () { this.disconnectOutlet({ outlet: 'modal', parentView: 'application' }); } } }); bootApplication(); equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hi'); (0, _emberMetal.run)(router, 'send', 'openLayer'); equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hilayer'); (0, _emberMetal.run)(router, 'send', 'openLayer'); equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hilayer'); (0, _emberMetal.run)(router, 'send', 'close'); equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hi'); }); QUnit.test('Renders child into parent with non-default template name', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('exports/root', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('exports/index', (0, _emberTemplateCompiler.compile)('
    ')); Router.map(function () { this.route('root', function () {}); }); App.RootRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render('exports/root'); } }); App.RootIndexRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render('exports/index'); } }); bootApplication(); handleURL('/root'); equal((0, _emberViews.jQuery)('#qunit-fixture .a .b .c').length, 1); }); QUnit.test('Allows any route to disconnectOutlet another route\'s templates', function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}{{outlet "modal"}}')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('hi')); (0, _emberGlimmer.setTemplate)('layer', (0, _emberTemplateCompiler.compile)('layer')); App.ApplicationRoute = _emberRouting.Route.extend({ actions: { openLayer: function () { this.render('layer', { into: 'application', outlet: 'modal' }); } } }); App.IndexRoute = _emberRouting.Route.extend({ actions: { close: function () { this.disconnectOutlet({ parentView: 'application', outlet: 'modal' }); } } }); bootApplication(); equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hi'); (0, _emberMetal.run)(router, 'send', 'openLayer'); equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hilayer'); (0, _emberMetal.run)(router, 'send', 'close'); equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hi'); }); QUnit.test('Can this.render({into:...}) the render helper', function () { expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./); expectDeprecation(function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}')); }, /Please refactor [\w\{\}"` ]+ to a component/); (0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)('')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('other')); (0, _emberGlimmer.setTemplate)('bar', (0, _emberTemplateCompiler.compile)('bar')); App.IndexRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render({ into: 'sidebar' }); }, actions: { changeToBar: function () { this.disconnectOutlet({ parentView: 'sidebar', outlet: 'main' }); this.render('bar', { into: 'sidebar' }); } } }); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar').text(), 'other'); (0, _emberMetal.run)(router, 'send', 'changeToBar'); equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar').text(), 'bar'); }); QUnit.test('Can disconnect from the render helper', function () { expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./); expectDeprecation(function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}')); }, /Please refactor [\w\{\}"` ]+ to a component/); (0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)('')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('other')); App.IndexRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render({ into: 'sidebar' }); }, actions: { disconnect: function () { this.disconnectOutlet({ parentView: 'sidebar', outlet: 'main' }); } } }); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar').text(), 'other'); (0, _emberMetal.run)(router, 'send', 'disconnect'); equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar').text(), ''); }); QUnit.test('Can this.render({into:...}) the render helper\'s children', function () { expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./); expectDeprecation(function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}')); }, /Please refactor [\w\{\}"` ]+ to a component/); (0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)('')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('other', (0, _emberTemplateCompiler.compile)('other')); (0, _emberGlimmer.setTemplate)('bar', (0, _emberTemplateCompiler.compile)('bar')); App.IndexRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render({ into: 'sidebar' }); this.render('other', { into: 'index' }); }, actions: { changeToBar: function () { this.disconnectOutlet({ parentView: 'index', outlet: 'main' }); this.render('bar', { into: 'index' }); } } }); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar .index').text(), 'other'); (0, _emberMetal.run)(router, 'send', 'changeToBar'); equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar .index').text(), 'bar'); }); QUnit.test('Can disconnect from the render helper\'s children', function () { expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./); expectDeprecation(function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}')); }, /Please refactor [\w\{\}"` ]+ to a component/); (0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)('')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('other', (0, _emberTemplateCompiler.compile)('other')); App.IndexRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render({ into: 'sidebar' }); this.render('other', { into: 'index' }); }, actions: { disconnect: function () { this.disconnectOutlet({ parentView: 'index', outlet: 'main' }); } } }); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar .index').text(), 'other'); (0, _emberMetal.run)(router, 'send', 'disconnect'); equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar .index').text(), ''); }); QUnit.test('Can this.render({into:...}) nested render helpers', function () { expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./); expectDeprecation(function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}')); }, /Please refactor [\w\{\}"` ]+ to a component/); expectDeprecation(function () { (0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)('')); }, /Please refactor [\w\{\}"` ]+ to a component/); (0, _emberGlimmer.setTemplate)('cart', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('other')); (0, _emberGlimmer.setTemplate)('baz', (0, _emberTemplateCompiler.compile)('baz')); App.IndexRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render({ into: 'cart' }); }, actions: { changeToBaz: function () { this.disconnectOutlet({ parentView: 'cart', outlet: 'main' }); this.render('baz', { into: 'cart' }); } } }); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture .cart').text(), 'other'); (0, _emberMetal.run)(router, 'send', 'changeToBaz'); equal((0, _emberViews.jQuery)('#qunit-fixture .cart').text(), 'baz'); }); QUnit.test('Can disconnect from nested render helpers', function () { expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./); expectDeprecation(function () { (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}')); }, /Please refactor [\w\{\}"` ]+ to a component/); expectDeprecation(function () { (0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)('')); }, /Please refactor [\w\{\}"` ]+ to a component/); (0, _emberGlimmer.setTemplate)('cart', (0, _emberTemplateCompiler.compile)('
    {{outlet}}
    ')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('other')); App.IndexRoute = _emberRouting.Route.extend({ renderTemplate: function () { this.render({ into: 'cart' }); }, actions: { disconnect: function () { this.disconnectOutlet({ parentView: 'cart', outlet: 'main' }); } } }); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture .cart').text(), 'other'); (0, _emberMetal.run)(router, 'send', 'disconnect'); equal((0, _emberViews.jQuery)('#qunit-fixture .cart').text(), ''); }); QUnit.test('Components inside an outlet have their didInsertElement hook invoked when the route is displayed', function (assert) { (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#if showFirst}}{{my-component}}{{else}}{{other-component}}{{/if}}')); var myComponentCounter = 0; var otherComponentCounter = 0; var indexController = void 0; App.IndexController = _emberRuntime.Controller.extend({ showFirst: true }); App.IndexRoute = _emberRouting.Route.extend({ setupController: function (controller) { indexController = controller; } }); App.MyComponentComponent = _emberGlimmer.Component.extend({ didInsertElement: function () { myComponentCounter++; } }); App.OtherComponentComponent = _emberGlimmer.Component.extend({ didInsertElement: function () { otherComponentCounter++; } }); bootApplication(); assert.strictEqual(myComponentCounter, 1, 'didInsertElement invoked on displayed component'); assert.strictEqual(otherComponentCounter, 0, 'didInsertElement not invoked on displayed component'); (0, _emberMetal.run)(function () { return indexController.set('showFirst', false); }); assert.strictEqual(myComponentCounter, 1, 'didInsertElement not invoked on displayed component'); assert.strictEqual(otherComponentCounter, 1, 'didInsertElement invoked on displayed component'); }); QUnit.test('Doesnt swallow exception thrown from willTransition', function () { expect(1); (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('index')); (0, _emberGlimmer.setTemplate)('other', (0, _emberTemplateCompiler.compile)('other')); Router.map(function () { this.route('other', function () {}); }); App.IndexRoute = _emberRouting.Route.extend({ actions: { willTransition: function () { throw new Error('boom'); } } }); bootApplication(); throws(function () { (0, _emberMetal.run)(function () { return router.handleURL('/other'); }); }, /boom/, 'expected an exception but none was thrown'); }); QUnit.test('Exception if outlet name is undefined in render and disconnectOutlet', function () { App.ApplicationRoute = _emberRouting.Route.extend({ actions: { showModal: function () { this.render({ outlet: undefined, parentView: 'application' }); }, hideModal: function () { this.disconnectOutlet({ outlet: undefined, parentView: 'application' }); } } }); bootApplication(); throws(function () { (0, _emberMetal.run)(function () { return router.send('showModal'); }); }, /You passed undefined as the outlet name/); throws(function () { (0, _emberMetal.run)(function () { return router.send('hideModal'); }); }, /You passed undefined as the outlet name/); }); QUnit.test('Route serializers work for Engines', function () { expect(2); // Register engine var BlogEngine = _emberApplication.Engine.extend(); registry.register('engine:blog', BlogEngine); // Register engine route map var postSerialize = function (params) { ok(true, 'serialize hook runs'); return { post_id: params.id }; }; registry.register('route-map:blog', function () { this.route('post', { path: '/post/:post_id', serialize: postSerialize }); }); Router.map(function () { this.mount('blog'); }); bootApplication(); equal(router._routerMicrolib.generate('blog.post', { id: '13' }), '/blog/post/13', 'url is generated properly'); }); QUnit.test('Defining a Route#serialize method in an Engine throws an error', function () { expect(1); // Register engine var BlogEngine = _emberApplication.Engine.extend(); registry.register('engine:blog', BlogEngine); // Register engine route map registry.register('route-map:blog', function () { this.route('post'); }); Router.map(function () { this.mount('blog'); }); bootApplication(); var PostRoute = _emberRouting.Route.extend({ serialize: function () {} }); container.lookup('engine:blog').register('route:post', PostRoute); throws(function () { return router.transitionTo('blog.post'); }, /Defining a custom serialize method on an Engine route is not supported/); }); QUnit.test('App.destroy does not leave undestroyed views after clearing engines', function () { expect(4); var engineInstance = void 0; // Register engine var BlogEngine = _emberApplication.Engine.extend(); registry.register('engine:blog', BlogEngine); var EngineIndexRoute = _emberRouting.Route.extend({ init: function () { this._super.apply(this, arguments); engineInstance = (0, _emberUtils.getOwner)(this); } }); // Register engine route map registry.register('route-map:blog', function () { this.route('post'); }); Router.map(function () { this.mount('blog'); }); bootApplication(); var engine = container.lookup('engine:blog'); engine.register('route:index', EngineIndexRoute); engine.register('template:index', (0, _emberTemplateCompiler.compile)('Engine Post!')); handleURL('/blog'); var route = engineInstance.lookup('route:index'); (0, _emberMetal.run)(router, 'destroy'); equal(router._toplevelView, null, 'the toplevelView was cleared'); (0, _emberMetal.run)(route, 'destroy'); equal(router._toplevelView, null, 'the toplevelView was not reinitialized'); (0, _emberMetal.run)(App, 'destroy'); equal(router._toplevelView, null, 'the toplevelView was not reinitialized'); }); }); enifed('ember/tests/routing/query_params_test', ['ember-babel', 'ember-runtime', 'ember-metal', 'ember-routing', 'ember-views', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberMetal, _emberRouting, _emberViews, _internalTestHelpers) { 'use strict'; (0, _internalTestHelpers.moduleFor)('Query Params - main', function (_QueryParamTestCase) { (0, _emberBabel.inherits)(_class, _QueryParamTestCase); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments)); } _class.prototype.refreshModelWhileLoadingTest = function (loadingReturn) { var _actions, _this2 = this; var assert = this.assert; assert.expect(9); var appModelCount = 0; var promiseResolve = void 0; this.add('route:application', _emberRouting.Route.extend({ queryParams: { appomg: { defaultValue: 'applol' } }, model: function () { appModelCount++; } })); this.setSingleQPController('index', 'omg', undefined, { omg: undefined }); var actionName = typeof loadingReturn !== 'undefined' ? 'loading' : 'ignore'; var indexModelCount = 0; this.add('route:index', _emberRouting.Route.extend({ queryParams: { omg: { refreshModel: true } }, actions: (_actions = {}, _actions[actionName] = function () { return loadingReturn; }, _actions), model: function (params) { indexModelCount++; if (indexModelCount === 2) { assert.deepEqual(params, { omg: 'lex' }); return new _emberRuntime.RSVP.Promise(function (resolve) { promiseResolve = resolve; }); } else if (indexModelCount === 3) { assert.deepEqual(params, { omg: 'hello' }, 'Model hook reruns even if the previous one didn\'t finish'); } } })); return this.visit('/').then(function () { assert.equal(appModelCount, 1, 'appModelCount is 1'); assert.equal(indexModelCount, 1); var indexController = _this2.getController('index'); _this2.setAndFlush(indexController, 'omg', 'lex'); assert.equal(appModelCount, 1, 'appModelCount is 1'); assert.equal(indexModelCount, 2); _this2.setAndFlush(indexController, 'omg', 'hello'); assert.equal(appModelCount, 1, 'appModelCount is 1'); assert.equal(indexModelCount, 3); (0, _emberMetal.run)(function () { promiseResolve(); }); assert.equal((0, _emberMetal.get)(indexController, 'omg'), 'hello', 'At the end last value prevails'); }); }; _class.prototype['@test No replaceURL occurs on startup because default values don\'t show up in URL'] = function (assert) { assert.expect(1); this.setSingleQPController('index'); return this.visitAndAssert('/'); }; _class.prototype['@test Calling transitionTo does not lose query params already on the activeTransition'] = function (assert) { var _this3 = this; assert.expect(2); this.router.map(function () { this.route('parent', function () { this.route('child'); this.route('sibling'); }); }); this.add('route:parent.child', _emberRouting.Route.extend({ afterModel: function () { this.transitionTo('parent.sibling'); } })); this.setSingleQPController('parent'); return this.visit('/parent/child?foo=lol').then(function () { _this3.assertCurrentPath('/parent/sibling?foo=lol', 'redirected to the sibling route, instead of child route'); assert.equal(_this3.getController('parent').get('foo'), 'lol', 'controller has value from the active transition'); }); }; _class.prototype['@test Single query params can be set on the controller and reflected in the url'] = function (assert) { var _this4 = this; assert.expect(3); this.router.map(function () { this.route('home', { path: '/' }); }); this.setSingleQPController('home'); return this.visitAndAssert('/').then(function () { var controller = _this4.getController('home'); _this4.setAndFlush(controller, 'foo', '456'); _this4.assertCurrentPath('/?foo=456'); _this4.setAndFlush(controller, 'foo', '987'); _this4.assertCurrentPath('/?foo=987'); }); }; _class.prototype['@test Query params can map to different url keys configured on the controller'] = function (assert) { var _this5 = this; assert.expect(6); this.add('controller:index', _emberRuntime.Controller.extend({ queryParams: [{ foo: 'other_foo', bar: { as: 'other_bar' } }], foo: 'FOO', bar: 'BAR' })); return this.visitAndAssert('/').then(function () { var controller = _this5.getController('index'); _this5.setAndFlush(controller, 'foo', 'LEX'); _this5.assertCurrentPath('/?other_foo=LEX', 'QP mapped correctly without \'as\''); _this5.setAndFlush(controller, 'foo', 'WOO'); _this5.assertCurrentPath('/?other_foo=WOO', 'QP updated correctly without \'as\''); _this5.transitionTo('/?other_foo=NAW'); assert.equal(controller.get('foo'), 'NAW', 'QP managed correctly on URL transition'); _this5.setAndFlush(controller, 'bar', 'NERK'); _this5.assertCurrentPath('/?other_bar=NERK&other_foo=NAW', 'QP mapped correctly with \'as\''); _this5.setAndFlush(controller, 'bar', 'NUKE'); _this5.assertCurrentPath('/?other_bar=NUKE&other_foo=NAW', 'QP updated correctly with \'as\''); }); }; _class.prototype['@test Routes have a private overridable serializeQueryParamKey hook'] = function (assert) { var _this6 = this; assert.expect(2); this.add('route:index', _emberRouting.Route.extend({ serializeQueryParamKey: _emberRuntime.String.dasherize })); this.setSingleQPController('index', 'funTimes', ''); return this.visitAndAssert('/').then(function () { var controller = _this6.getController('index'); _this6.setAndFlush(controller, 'funTimes', 'woot'); _this6.assertCurrentPath('/?fun-times=woot'); }); }; _class.prototype['@test Can override inherited QP behavior by specifying queryParams as a computed property'] = function (assert) { var _this7 = this; assert.expect(3); this.setSingleQPController('index', 'a', 0, { queryParams: (0, _emberMetal.computed)(function () { return ['c']; }), c: true }); return this.visitAndAssert('/').then(function () { var indexController = _this7.getController('index'); _this7.setAndFlush(indexController, 'a', 1); _this7.assertCurrentPath('/', 'QP did not update due to being overriden'); _this7.setAndFlush(indexController, 'c', false); _this7.assertCurrentPath('/?c=false', 'QP updated with overriden param'); }); }; _class.prototype['@test Can concatenate inherited QP behavior by specifying queryParams as an array'] = function (assert) { var _this8 = this; assert.expect(3); this.setSingleQPController('index', 'a', 0, { queryParams: ['c'], c: true }); return this.visitAndAssert('/').then(function () { var indexController = _this8.getController('index'); _this8.setAndFlush(indexController, 'a', 1); _this8.assertCurrentPath('/?a=1', 'Inherited QP did update'); _this8.setAndFlush(indexController, 'c', false); _this8.assertCurrentPath('/?a=1&c=false', 'New QP did update'); }); }; _class.prototype['@test model hooks receives query params'] = function (assert) { assert.expect(2); this.setSingleQPController('index'); this.add('route:index', _emberRouting.Route.extend({ model: function (params) { assert.deepEqual(params, { foo: 'bar' }); } })); return this.visitAndAssert('/'); }; _class.prototype['@test model hooks receives query params with dynamic segment params'] = function (assert) { assert.expect(2); this.router.map(function () { this.route('index', { path: '/:id' }); }); this.setSingleQPController('index'); this.add('route:index', _emberRouting.Route.extend({ model: function (params) { assert.deepEqual(params, { foo: 'bar', id: 'baz' }); } })); return this.visitAndAssert('/baz'); }; _class.prototype['@test model hooks receives query params (overridden by incoming url value)'] = function (assert) { assert.expect(2); this.router.map(function () { this.route('index', { path: '/:id' }); }); this.setSingleQPController('index'); this.add('route:index', _emberRouting.Route.extend({ model: function (params) { assert.deepEqual(params, { foo: 'baz', id: 'boo' }); } })); return this.visitAndAssert('/boo?foo=baz'); }; _class.prototype['@test error is thrown if dynamic segment and query param have same name'] = function (assert) { var _this9 = this; assert.expect(1); this.router.map(function () { this.route('index', { path: '/:foo' }); }); this.setSingleQPController('index'); expectAssertion(function () { _this9.visitAndAssert('/boo?foo=baz'); }, 'The route \'index\' has both a dynamic segment and query param with name \'foo\'. Please rename one to avoid collisions.'); }; _class.prototype['@test query params have been set by the time setupController is called'] = function (assert) { assert.expect(2); this.setSingleQPController('application'); this.add('route:application', _emberRouting.Route.extend({ setupController: function (controller) { assert.equal(controller.get('foo'), 'YEAH', 'controller\'s foo QP property set before setupController called'); } })); return this.visitAndAssert('/?foo=YEAH'); }; _class.prototype['@test mapped query params have been set by the time setupController is called'] = function (assert) { assert.expect(2); this.setSingleQPController('application', { faz: 'foo' }); this.add('route:application', _emberRouting.Route.extend({ setupController: function (controller) { assert.equal(controller.get('faz'), 'YEAH', 'controller\'s foo QP property set before setupController called'); } })); return this.visitAndAssert('/?foo=YEAH'); }; _class.prototype['@test Route#paramsFor fetches query params with default value'] = function (assert) { assert.expect(2); this.router.map(function () { this.route('index', { path: '/:something' }); }); this.setSingleQPController('index'); this.add('route:index', _emberRouting.Route.extend({ model: function () { assert.deepEqual(this.paramsFor('index'), { something: 'baz', foo: 'bar' }, 'could retrieve params for index'); } })); return this.visitAndAssert('/baz'); }; _class.prototype['@test Route#paramsFor fetches query params with non-default value'] = function (assert) { assert.expect(2); this.router.map(function () { this.route('index', { path: '/:something' }); }); this.setSingleQPController('index'); this.add('route:index', _emberRouting.Route.extend({ model: function () { assert.deepEqual(this.paramsFor('index'), { something: 'baz', foo: 'boo' }, 'could retrieve params for index'); } })); return this.visitAndAssert('/baz?foo=boo'); }; _class.prototype['@test Route#paramsFor fetches default falsy query params'] = function (assert) { assert.expect(2); this.router.map(function () { this.route('index', { path: '/:something' }); }); this.setSingleQPController('index', 'foo', false); this.add('route:index', _emberRouting.Route.extend({ model: function () { assert.deepEqual(this.paramsFor('index'), { something: 'baz', foo: false }, 'could retrieve params for index'); } })); return this.visitAndAssert('/baz'); }; _class.prototype['@test Route#paramsFor fetches non-default falsy query params'] = function (assert) { assert.expect(2); this.router.map(function () { this.route('index', { path: '/:something' }); }); this.setSingleQPController('index', 'foo', true); this.add('route:index', _emberRouting.Route.extend({ model: function () { assert.deepEqual(this.paramsFor('index'), { something: 'baz', foo: false }, 'could retrieve params for index'); } })); return this.visitAndAssert('/baz?foo=false'); }; _class.prototype['@test model hook can query prefix-less application params'] = function (assert) { assert.expect(4); this.setSingleQPController('application', 'appomg', 'applol'); this.setSingleQPController('index', 'omg', 'lol'); this.add('route:application', _emberRouting.Route.extend({ model: function (params) { assert.deepEqual(params, { appomg: 'applol' }); } })); this.add('route:index', _emberRouting.Route.extend({ model: function (params) { assert.deepEqual(params, { omg: 'lol' }); assert.deepEqual(this.paramsFor('application'), { appomg: 'applol' }); } })); return this.visitAndAssert('/'); }; _class.prototype['@test model hook can query prefix-less application params (overridden by incoming url value)'] = function (assert) { assert.expect(4); this.setSingleQPController('application', 'appomg', 'applol'); this.setSingleQPController('index', 'omg', 'lol'); this.add('route:application', _emberRouting.Route.extend({ model: function (params) { assert.deepEqual(params, { appomg: 'appyes' }); } })); this.add('route:index', _emberRouting.Route.extend({ model: function (params) { assert.deepEqual(params, { omg: 'yes' }); assert.deepEqual(this.paramsFor('application'), { appomg: 'appyes' }); } })); return this.visitAndAssert('/?appomg=appyes&omg=yes'); }; _class.prototype['@test can opt into full transition by setting refreshModel in route queryParams'] = function (assert) { var _this10 = this; assert.expect(7); this.setSingleQPController('application', 'appomg', 'applol'); this.setSingleQPController('index', 'omg', 'lol'); var appModelCount = 0; this.add('route:application', _emberRouting.Route.extend({ model: function () { appModelCount++; } })); var indexModelCount = 0; this.add('route:index', _emberRouting.Route.extend({ queryParams: { omg: { refreshModel: true } }, model: function (params) { indexModelCount++; if (indexModelCount === 1) { assert.deepEqual(params, { omg: 'lol' }, 'params are correct on first pass'); } else if (indexModelCount === 2) { assert.deepEqual(params, { omg: 'lex' }, 'params are correct on second pass'); } } })); return this.visitAndAssert('/').then(function () { assert.equal(appModelCount, 1, 'app model hook ran'); assert.equal(indexModelCount, 1, 'index model hook ran'); var indexController = _this10.getController('index'); _this10.setAndFlush(indexController, 'omg', 'lex'); assert.equal(appModelCount, 1, 'app model hook did not run again'); assert.equal(indexModelCount, 2, 'index model hook ran again due to refreshModel'); }); }; _class.prototype['@test refreshModel and replace work together'] = function (assert) { var _this11 = this; assert.expect(8); this.setSingleQPController('application', 'appomg', 'applol'); this.setSingleQPController('index', 'omg', 'lol'); var appModelCount = 0; this.add('route:application', _emberRouting.Route.extend({ model: function () { appModelCount++; } })); var indexModelCount = 0; this.add('route:index', _emberRouting.Route.extend({ queryParams: { omg: { refreshModel: true, replace: true } }, model: function (params) { indexModelCount++; if (indexModelCount === 1) { assert.deepEqual(params, { omg: 'lol' }, 'params are correct on first pass'); } else if (indexModelCount === 2) { assert.deepEqual(params, { omg: 'lex' }, 'params are correct on second pass'); } } })); return this.visitAndAssert('/').then(function () { assert.equal(appModelCount, 1, 'app model hook ran'); assert.equal(indexModelCount, 1, 'index model hook ran'); var indexController = _this11.getController('index'); _this11.expectedReplaceURL = '/?omg=lex'; _this11.setAndFlush(indexController, 'omg', 'lex'); assert.equal(appModelCount, 1, 'app model hook did not run again'); assert.equal(indexModelCount, 2, 'index model hook ran again due to refreshModel'); }); }; _class.prototype['@test multiple QP value changes only cause a single model refresh'] = function (assert) { var _this12 = this; assert.expect(2); this.setSingleQPController('index', 'alex', 'lol'); this.setSingleQPController('index', 'steely', 'lel'); var refreshCount = 0; this.add('route:index', _emberRouting.Route.extend({ queryParams: { alex: { refreshModel: true }, steely: { refreshModel: true } }, refresh: function () { refreshCount++; } })); return this.visitAndAssert('/').then(function () { var indexController = _this12.getController('index'); (0, _emberMetal.run)(indexController, 'setProperties', { alex: 'fran', steely: 'david' }); assert.equal(refreshCount, 1, 'index refresh hook only run once'); }); }; _class.prototype['@test refreshModel does not cause a second transition during app boot '] = function (assert) { assert.expect(1); this.setSingleQPController('application', 'appomg', 'applol'); this.setSingleQPController('index', 'omg', 'lol'); this.add('route:index', _emberRouting.Route.extend({ queryParams: { omg: { refreshModel: true } }, refresh: function () { assert.ok(false); } })); return this.visitAndAssert('/?appomg=hello&omg=world'); }; _class.prototype['@test queryParams are updated when a controller property is set and the route is refreshed. Issue #13263 '] = function (assert) { var _this13 = this; this.addTemplate('application', '{{foo}}{{outlet}}'); this.setSingleQPController('application', 'foo', 1, { actions: { increment: function () { this.incrementProperty('foo'); this.send('refreshRoute'); } } }); this.add('route:application', _emberRouting.Route.extend({ actions: { refreshRoute: function () { this.refresh(); } } })); return this.visitAndAssert('/').then(function () { assert.equal((0, _emberViews.jQuery)('#test-value').text().trim(), '1'); (0, _emberMetal.run)((0, _emberViews.jQuery)('#test-button'), 'click'); assert.equal((0, _emberViews.jQuery)('#test-value').text().trim(), '2'); _this13.assertCurrentPath('/?foo=2'); (0, _emberMetal.run)((0, _emberViews.jQuery)('#test-button'), 'click'); assert.equal((0, _emberViews.jQuery)('#test-value').text().trim(), '3'); _this13.assertCurrentPath('/?foo=3'); }); }; _class.prototype['@test Use Ember.get to retrieve query params \'refreshModel\' configuration'] = function (assert) { var _this14 = this; assert.expect(7); this.setSingleQPController('application', 'appomg', 'applol'); this.setSingleQPController('index', 'omg', 'lol'); var appModelCount = 0; this.add('route:application', _emberRouting.Route.extend({ model: function () { appModelCount++; } })); var indexModelCount = 0; this.add('route:index', _emberRouting.Route.extend({ queryParams: _emberRuntime.Object.create({ unknownProperty: function () { return { refreshModel: true }; } }), model: function (params) { indexModelCount++; if (indexModelCount === 1) { assert.deepEqual(params, { omg: 'lol' }); } else if (indexModelCount === 2) { assert.deepEqual(params, { omg: 'lex' }); } } })); return this.visitAndAssert('/').then(function () { assert.equal(appModelCount, 1); assert.equal(indexModelCount, 1); var indexController = _this14.getController('index'); _this14.setAndFlush(indexController, 'omg', 'lex'); assert.equal(appModelCount, 1); assert.equal(indexModelCount, 2); }); }; _class.prototype['@test can use refreshModel even with URL changes that remove QPs from address bar'] = function (assert) { var _this15 = this; assert.expect(4); this.setSingleQPController('index', 'omg', 'lol'); var indexModelCount = 0; this.add('route:index', _emberRouting.Route.extend({ queryParams: { omg: { refreshModel: true } }, model: function (params) { indexModelCount++; var data = void 0; if (indexModelCount === 1) { data = 'foo'; } else if (indexModelCount === 2) { data = 'lol'; } assert.deepEqual(params, { omg: data }, 'index#model receives right data'); } })); return this.visitAndAssert('/?omg=foo').then(function () { _this15.transitionTo('/'); var indexController = _this15.getController('index'); assert.equal(indexController.get('omg'), 'lol'); }); }; _class.prototype['@test can opt into a replace query by specifying replace:true in the Route config hash'] = function (assert) { var _this16 = this; assert.expect(2); this.setSingleQPController('application', 'alex', 'matchneer'); this.add('route:application', _emberRouting.Route.extend({ queryParams: { alex: { replace: true } } })); return this.visitAndAssert('/').then(function () { var appController = _this16.getController('application'); _this16.expectedReplaceURL = '/?alex=wallace'; _this16.setAndFlush(appController, 'alex', 'wallace'); }); }; _class.prototype['@test Route query params config can be configured using property name instead of URL key'] = function (assert) { var _this17 = this; assert.expect(2); this.add('controller:application', _emberRuntime.Controller.extend({ queryParams: [{ commitBy: 'commit_by' }] })); this.add('route:application', _emberRouting.Route.extend({ queryParams: { commitBy: { replace: true } } })); return this.visitAndAssert('/').then(function () { var appController = _this17.getController('application'); _this17.expectedReplaceURL = '/?commit_by=igor_seb'; _this17.setAndFlush(appController, 'commitBy', 'igor_seb'); }); }; _class.prototype['@test An explicit replace:false on a changed QP always wins and causes a pushState'] = function (assert) { var _this18 = this; assert.expect(3); this.add('controller:application', _emberRuntime.Controller.extend({ queryParams: ['alex', 'steely'], alex: 'matchneer', steely: 'dan' })); this.add('route:application', _emberRouting.Route.extend({ queryParams: { alex: { replace: true }, steely: { replace: false } } })); return this.visit('/').then(function () { var appController = _this18.getController('application'); _this18.expectedPushURL = '/?alex=wallace&steely=jan'; (0, _emberMetal.run)(appController, 'setProperties', { alex: 'wallace', steely: 'jan' }); _this18.expectedPushURL = '/?alex=wallace&steely=fran'; (0, _emberMetal.run)(appController, 'setProperties', { steely: 'fran' }); _this18.expectedReplaceURL = '/?alex=sriracha&steely=fran'; (0, _emberMetal.run)(appController, 'setProperties', { alex: 'sriracha' }); }); }; _class.prototype['@test can opt into full transition by setting refreshModel in route queryParams when transitioning from child to parent'] = function (assert) { this.addTemplate('parent', '{{outlet}}'); this.addTemplate('parent.child', '{{link-to \'Parent\' \'parent\' (query-params foo=\'change\') id=\'parent-link\'}}'); this.router.map(function () { this.route('parent', function () { this.route('child'); }); }); var parentModelCount = 0; this.add('route:parent', _emberRouting.Route.extend({ model: function () { parentModelCount++; }, queryParams: { foo: { refreshModel: true } } })); this.setSingleQPController('parent', 'foo', 'abc'); return this.visit('/parent/child?foo=lol').then(function () { assert.equal(parentModelCount, 1); (0, _emberMetal.run)((0, _emberViews.jQuery)('#parent-link'), 'click'); assert.equal(parentModelCount, 2); }); }; _class.prototype['@test Use Ember.get to retrieve query params \'replace\' configuration'] = function (assert) { var _this19 = this; assert.expect(2); this.setSingleQPController('application', 'alex', 'matchneer'); this.add('route:application', _emberRouting.Route.extend({ queryParams: _emberRuntime.Object.create({ unknownProperty: function () { // We are simulating all qps requiring refresh return { replace: true }; } }) })); return this.visitAndAssert('/').then(function () { var appController = _this19.getController('application'); _this19.expectedReplaceURL = '/?alex=wallace'; _this19.setAndFlush(appController, 'alex', 'wallace'); }); }; _class.prototype['@test can override incoming QP values in setupController'] = function (assert) { var _this20 = this; assert.expect(3); this.router.map(function () { this.route('about'); }); this.setSingleQPController('index', 'omg', 'lol'); this.add('route:index', _emberRouting.Route.extend({ setupController: function (controller) { assert.ok(true, 'setupController called'); controller.set('omg', 'OVERRIDE'); }, actions: { queryParamsDidChange: function () { assert.ok(false, 'queryParamsDidChange shouldn\'t fire'); } } })); return this.visitAndAssert('/about').then(function () { _this20.transitionTo('index'); _this20.assertCurrentPath('/?omg=OVERRIDE'); }); }; _class.prototype['@test can override incoming QP array values in setupController'] = function (assert) { var _this21 = this; assert.expect(3); this.router.map(function () { this.route('about'); }); this.setSingleQPController('index', 'omg', ['lol']); this.add('route:index', _emberRouting.Route.extend({ setupController: function (controller) { assert.ok(true, 'setupController called'); controller.set('omg', ['OVERRIDE']); }, actions: { queryParamsDidChange: function () { assert.ok(false, 'queryParamsDidChange shouldn\'t fire'); } } })); return this.visitAndAssert('/about').then(function () { _this21.transitionTo('index'); _this21.assertCurrentPath('/?omg=' + encodeURIComponent(JSON.stringify(['OVERRIDE']))); }); }; _class.prototype['@test URL transitions that remove QPs still register as QP changes'] = function (assert) { var _this22 = this; assert.expect(2); this.setSingleQPController('index', 'omg', 'lol'); return this.visit('/?omg=borf').then(function () { var indexController = _this22.getController('index'); assert.equal(indexController.get('omg'), 'borf'); _this22.transitionTo('/'); assert.equal(indexController.get('omg'), 'lol'); }); }; _class.prototype['@test Subresource naming style is supported'] = function (assert) { var _this23 = this; assert.expect(5); this.router.map(function () { this.route('abc.def', { path: '/abcdef' }, function () { this.route('zoo'); }); }); this.addTemplate('application', '{{link-to \'A\' \'abc.def\' (query-params foo=\'123\') id=\'one\'}}{{link-to \'B\' \'abc.def.zoo\' (query-params foo=\'123\' bar=\'456\') id=\'two\'}}{{outlet}}'); this.setSingleQPController('abc.def', 'foo', 'lol'); this.setSingleQPController('abc.def.zoo', 'bar', 'haha'); return this.visitAndAssert('/').then(function () { assert.equal((0, _emberViews.jQuery)('#one').attr('href'), '/abcdef?foo=123'); assert.equal((0, _emberViews.jQuery)('#two').attr('href'), '/abcdef/zoo?bar=456&foo=123'); (0, _emberMetal.run)((0, _emberViews.jQuery)('#one'), 'click'); _this23.assertCurrentPath('/abcdef?foo=123'); (0, _emberMetal.run)((0, _emberViews.jQuery)('#two'), 'click'); _this23.assertCurrentPath('/abcdef/zoo?bar=456&foo=123'); }); }; _class.prototype['@test transitionTo supports query params'] = function () { var _this24 = this; this.setSingleQPController('index', 'foo', 'lol'); return this.visitAndAssert('/').then(function () { _this24.transitionTo({ queryParams: { foo: 'borf' } }); _this24.assertCurrentPath('/?foo=borf', 'shorthand supported'); _this24.transitionTo({ queryParams: { 'index:foo': 'blaf' } }); _this24.assertCurrentPath('/?foo=blaf', 'longform supported'); _this24.transitionTo({ queryParams: { 'index:foo': false } }); _this24.assertCurrentPath('/?foo=false', 'longform supported (bool)'); _this24.transitionTo({ queryParams: { foo: false } }); _this24.assertCurrentPath('/?foo=false', 'shorhand supported (bool)'); }); }; _class.prototype['@test transitionTo supports query params (multiple)'] = function () { var _this25 = this; this.add('controller:index', _emberRuntime.Controller.extend({ queryParams: ['foo', 'bar'], foo: 'lol', bar: 'wat' })); return this.visitAndAssert('/').then(function () { _this25.transitionTo({ queryParams: { foo: 'borf' } }); _this25.assertCurrentPath('/?foo=borf', 'shorthand supported'); _this25.transitionTo({ queryParams: { 'index:foo': 'blaf' } }); _this25.assertCurrentPath('/?foo=blaf', 'longform supported'); _this25.transitionTo({ queryParams: { 'index:foo': false } }); _this25.assertCurrentPath('/?foo=false', 'longform supported (bool)'); _this25.transitionTo({ queryParams: { foo: false } }); _this25.assertCurrentPath('/?foo=false', 'shorhand supported (bool)'); }); }; _class.prototype['@test setting controller QP to empty string doesn\'t generate null in URL'] = function (assert) { var _this26 = this; assert.expect(1); this.setSingleQPController('index', 'foo', '123'); return this.visit('/').then(function () { var controller = _this26.getController('index'); _this26.expectedPushURL = '/?foo='; _this26.setAndFlush(controller, 'foo', ''); }); }; _class.prototype['@test setting QP to empty string doesn\'t generate null in URL'] = function (assert) { var _this27 = this; assert.expect(1); this.add('route:index', _emberRouting.Route.extend({ queryParams: { foo: { defaultValue: '123' } } })); return this.visit('/').then(function () { var controller = _this27.getController('index'); _this27.expectedPushURL = '/?foo='; _this27.setAndFlush(controller, 'foo', ''); }); }; _class.prototype['@test A default boolean value deserializes QPs as booleans rather than strings'] = function (assert) { var _this28 = this; assert.expect(3); this.setSingleQPController('index', 'foo', false); this.add('route:index', _emberRouting.Route.extend({ model: function (params) { assert.equal(params.foo, true, 'model hook received foo as boolean true'); } })); return this.visit('/?foo=true').then(function () { var controller = _this28.getController('index'); assert.equal(controller.get('foo'), true); _this28.transitionTo('/?foo=false'); assert.equal(controller.get('foo'), false); }); }; _class.prototype['@test Query param without value are empty string'] = function (assert) { var _this29 = this; assert.expect(1); this.add('controller:index', _emberRuntime.Controller.extend({ queryParams: ['foo'], foo: '' })); return this.visit('/?foo=').then(function () { var controller = _this29.getController('index'); assert.equal(controller.get('foo'), ''); }); }; _class.prototype['@test Array query params can be set'] = function (assert) { var _this30 = this; assert.expect(2); this.router.map(function () { this.route('home', { path: '/' }); }); this.setSingleQPController('home', 'foo', []); return this.visit('/').then(function () { var controller = _this30.getController('home'); _this30.setAndFlush(controller, 'foo', [1, 2]); _this30.assertCurrentPath('/?foo=%5B1%2C2%5D'); _this30.setAndFlush(controller, 'foo', [3, 4]); _this30.assertCurrentPath('/?foo=%5B3%2C4%5D'); }); }; _class.prototype['@test (de)serialization: arrays'] = function (assert) { var _this31 = this; assert.expect(4); this.setSingleQPController('index', 'foo', [1]); return this.visitAndAssert('/').then(function () { _this31.transitionTo({ queryParams: { foo: [2, 3] } }); _this31.assertCurrentPath('/?foo=%5B2%2C3%5D', 'shorthand supported'); _this31.transitionTo({ queryParams: { 'index:foo': [4, 5] } }); _this31.assertCurrentPath('/?foo=%5B4%2C5%5D', 'longform supported'); _this31.transitionTo({ queryParams: { foo: [] } }); _this31.assertCurrentPath('/?foo=%5B%5D', 'longform supported'); }); }; _class.prototype['@test Url with array query param sets controller property to array'] = function (assert) { var _this32 = this; assert.expect(1); this.setSingleQPController('index', 'foo', ''); return this.visit('/?foo[]=1&foo[]=2&foo[]=3').then(function () { var controller = _this32.getController('index'); assert.deepEqual(controller.get('foo'), ['1', '2', '3']); }); }; _class.prototype['@test Array query params can be pushed/popped'] = function (assert) { var _this33 = this; assert.expect(17); this.router.map(function () { this.route('home', { path: '/' }); }); this.setSingleQPController('home', 'foo', (0, _emberRuntime.A)()); return this.visitAndAssert('/').then(function () { var controller = _this33.getController('home'); (0, _emberMetal.run)(controller.foo, 'pushObject', 1); _this33.assertCurrentPath('/?foo=%5B1%5D'); assert.deepEqual(controller.foo, [1]); (0, _emberMetal.run)(controller.foo, 'popObject'); _this33.assertCurrentPath('/'); assert.deepEqual(controller.foo, []); (0, _emberMetal.run)(controller.foo, 'pushObject', 1); _this33.assertCurrentPath('/?foo=%5B1%5D'); assert.deepEqual(controller.foo, [1]); (0, _emberMetal.run)(controller.foo, 'popObject'); _this33.assertCurrentPath('/'); assert.deepEqual(controller.foo, []); (0, _emberMetal.run)(controller.foo, 'pushObject', 1); _this33.assertCurrentPath('/?foo=%5B1%5D'); assert.deepEqual(controller.foo, [1]); (0, _emberMetal.run)(controller.foo, 'pushObject', 2); _this33.assertCurrentPath('/?foo=%5B1%2C2%5D'); assert.deepEqual(controller.foo, [1, 2]); (0, _emberMetal.run)(controller.foo, 'popObject'); _this33.assertCurrentPath('/?foo=%5B1%5D'); assert.deepEqual(controller.foo, [1]); (0, _emberMetal.run)(controller.foo, 'unshiftObject', 'lol'); _this33.assertCurrentPath('/?foo=%5B%22lol%22%2C1%5D'); assert.deepEqual(controller.foo, ['lol', 1]); }); }; _class.prototype['@test Overwriting with array with same content shouldn\'t refire update'] = function (assert) { var _this34 = this; assert.expect(4); this.router.map(function () { this.route('home', { path: '/' }); }); var modelCount = 0; this.add('route:home', _emberRouting.Route.extend({ model: function () { modelCount++; } })); this.setSingleQPController('home', 'foo', (0, _emberRuntime.A)([1])); return this.visitAndAssert('/').then(function () { assert.equal(modelCount, 1); var controller = _this34.getController('home'); _this34.setAndFlush(controller, 'model', (0, _emberRuntime.A)([1])); assert.equal(modelCount, 1); _this34.assertCurrentPath('/'); }); }; _class.prototype['@test Defaulting to params hash as the model should not result in that params object being watched'] = function (assert) { var _this35 = this; assert.expect(1); this.router.map(function () { this.route('other'); }); // This causes the params hash, which is returned as a route's // model if no other model could be resolved given the provided // params (and no custom model hook was defined), to be watched, // unless we return a copy of the params hash. this.setSingleQPController('application', 'woot', 'wat'); this.add('route:other', _emberRouting.Route.extend({ model: function (p, trans) { var m = (0, _emberMetal.meta)(trans.params.application); assert.ok(!m.peekWatching('woot'), 'A meta object isn\'t constructed for this params POJO'); } })); return this.visit('/').then(function () { _this35.transitionTo('other'); }); }; _class.prototype['@test A child of a resource route still defaults to parent route\'s model even if the child route has a query param'] = function (assert) { assert.expect(2); this.setSingleQPController('index', 'woot', undefined, { woot: undefined }); this.add('route:application', _emberRouting.Route.extend({ model: function () { return { woot: true }; } })); this.add('route:index', _emberRouting.Route.extend({ setupController: function (controller, model) { assert.deepEqual(model, { woot: true }, 'index route inherited model route from parent route'); } })); return this.visitAndAssert('/'); }; _class.prototype['@test opting into replace does not affect transitions between routes'] = function (assert) { var _this36 = this; assert.expect(5); this.addTemplate('application', '{{link-to \'Foo\' \'foo\' id=\'foo-link\'}}{{link-to \'Bar\' \'bar\' id=\'bar-no-qp-link\'}}{{link-to \'Bar\' \'bar\' (query-params raytiley=\'isthebest\') id=\'bar-link\'}}{{outlet}}'); this.router.map(function () { this.route('foo'); this.route('bar'); }); this.setSingleQPController('bar', 'raytiley', 'israd'); this.add('route:bar', _emberRouting.Route.extend({ queryParams: { raytiley: { replace: true } } })); return this.visit('/').then(function () { var controller = _this36.getController('bar'); _this36.expectedPushURL = '/foo'; (0, _emberMetal.run)((0, _emberViews.jQuery)('#foo-link'), 'click'); _this36.expectedPushURL = '/bar'; (0, _emberMetal.run)((0, _emberViews.jQuery)('#bar-no-qp-link'), 'click'); _this36.expectedReplaceURL = '/bar?raytiley=woot'; _this36.setAndFlush(controller, 'raytiley', 'woot'); _this36.expectedPushURL = '/foo'; (0, _emberMetal.run)((0, _emberViews.jQuery)('#foo-link'), 'click'); _this36.expectedPushURL = '/bar?raytiley=isthebest'; (0, _emberMetal.run)((0, _emberViews.jQuery)('#bar-link'), 'click'); }); }; _class.prototype['@test undefined isn\'t serialized or deserialized into a string'] = function (assert) { var _this37 = this; assert.expect(4); this.router.map(function () { this.route('example'); }); this.addTemplate('application', '{{link-to \'Example\' \'example\' (query-params foo=undefined) id=\'the-link\'}}'); this.setSingleQPController('example', 'foo', undefined, { foo: undefined }); this.add('route:example', _emberRouting.Route.extend({ model: function (params) { assert.deepEqual(params, { foo: undefined }); } })); return this.visitAndAssert('/').then(function () { assert.equal(_this37.$('#the-link').attr('href'), '/example', 'renders without undefined qp serialized'); return _this37.transitionTo('example', { queryParams: { foo: undefined } }).then(function () { _this37.assertCurrentPath('/example'); }); }); }; _class.prototype['@test when refreshModel is true and loading hook is undefined, model hook will rerun when QPs change even if previous did not finish'] = function () { return this.refreshModelWhileLoadingTest(); }; _class.prototype['@test when refreshModel is true and loading hook returns false, model hook will rerun when QPs change even if previous did not finish'] = function () { return this.refreshModelWhileLoadingTest(false); }; _class.prototype['@test when refreshModel is true and loading hook returns true, model hook will rerun when QPs change even if previous did not finish'] = function () { return this.refreshModelWhileLoadingTest(true); }; _class.prototype['@test warn user that Route\'s queryParams configuration must be an Object, not an Array'] = function (assert) { var _this38 = this; assert.expect(1); this.add('route:application', _emberRouting.Route.extend({ queryParams: [{ commitBy: { replace: true } }] })); expectAssertion(function () { _this38.visit('/'); }, 'You passed in `[{"commitBy":{"replace":true}}]` as the value for `queryParams` but `queryParams` cannot be an Array'); }; _class.prototype['@test handle route names that clash with Object.prototype properties'] = function (assert) { var _this39 = this; assert.expect(1); this.router.map(function () { this.route('constructor'); }); this.add('route:constructor', _emberRouting.Route.extend({ queryParams: { foo: { defaultValue: '123' } } })); return this.visit('/').then(function () { _this39.transitionTo('constructor', { queryParams: { foo: '999' } }); var controller = _this39.getController('constructor'); assert.equal((0, _emberMetal.get)(controller, 'foo'), '999'); }); }; return _class; }(_internalTestHelpers.QueryParamTestCase)); }); enifed('ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test', ['ember-babel', 'ember-runtime', 'ember-routing', 'ember-metal', 'ember-views', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberRouting, _emberMetal, _emberViews, _internalTestHelpers) { 'use strict'; var ModelDependentQPTestCase = function (_QueryParamTestCase) { (0, _emberBabel.inherits)(ModelDependentQPTestCase, _QueryParamTestCase); function ModelDependentQPTestCase() { return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments)); } ModelDependentQPTestCase.prototype.boot = function () { this.setupApplication(); return this.visitApplication(); }; ModelDependentQPTestCase.prototype.teardown = function () { var _QueryParamTestCase$p; (_QueryParamTestCase$p = _QueryParamTestCase.prototype.teardown).call.apply(_QueryParamTestCase$p, [this].concat(Array.prototype.slice.call(arguments))); this.assert.ok(!this.expectedModelHookParams, 'there should be no pending expectation of expected model hook params'); }; ModelDependentQPTestCase.prototype.reopenController = function (name, options) { this.application.resolveRegistration('controller:' + name).reopen(options); }; ModelDependentQPTestCase.prototype.reopenRoute = function (name, options) { this.application.resolveRegistration('route:' + name).reopen(options); }; ModelDependentQPTestCase.prototype.queryParamsStickyTest1 = function (urlPrefix) { var _this2 = this; var assert = this.assert; assert.expect(14); return this.boot().then(function () { (0, _emberMetal.run)(_this2.$link1, 'click'); _this2.assertCurrentPath(urlPrefix + '/a-1'); _this2.setAndFlush(_this2.controller, 'q', 'lol'); assert.equal(_this2.$link1.attr('href'), urlPrefix + '/a-1?q=lol'); assert.equal(_this2.$link2.attr('href'), urlPrefix + '/a-2'); assert.equal(_this2.$link3.attr('href'), urlPrefix + '/a-3'); (0, _emberMetal.run)(_this2.$link2, 'click'); assert.equal(_this2.controller.get('q'), 'wat'); assert.equal(_this2.controller.get('z'), 0); assert.deepEqual(_this2.controller.get('model'), { id: 'a-2' }); assert.equal(_this2.$link1.attr('href'), urlPrefix + '/a-1?q=lol'); assert.equal(_this2.$link2.attr('href'), urlPrefix + '/a-2'); assert.equal(_this2.$link3.attr('href'), urlPrefix + '/a-3'); }); }; ModelDependentQPTestCase.prototype.queryParamsStickyTest2 = function (urlPrefix) { var _this3 = this; var assert = this.assert; assert.expect(24); return this.boot().then(function () { _this3.expectedModelHookParams = { id: 'a-1', q: 'lol', z: 0 }; _this3.transitionTo(urlPrefix + '/a-1?q=lol'); assert.deepEqual(_this3.controller.get('model'), { id: 'a-1' }); assert.equal(_this3.controller.get('q'), 'lol'); assert.equal(_this3.controller.get('z'), 0); assert.equal(_this3.$link1.attr('href'), urlPrefix + '/a-1?q=lol'); assert.equal(_this3.$link2.attr('href'), urlPrefix + '/a-2'); assert.equal(_this3.$link3.attr('href'), urlPrefix + '/a-3'); _this3.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 0 }; _this3.transitionTo(urlPrefix + '/a-2?q=lol'); assert.deepEqual(_this3.controller.get('model'), { id: 'a-2' }, 'controller\'s model changed to a-2'); assert.equal(_this3.controller.get('q'), 'lol'); assert.equal(_this3.controller.get('z'), 0); assert.equal(_this3.$link1.attr('href'), urlPrefix + '/a-1?q=lol'); assert.equal(_this3.$link2.attr('href'), urlPrefix + '/a-2?q=lol'); assert.equal(_this3.$link3.attr('href'), urlPrefix + '/a-3'); _this3.expectedModelHookParams = { id: 'a-3', q: 'lol', z: 123 }; _this3.transitionTo(urlPrefix + '/a-3?q=lol&z=123'); assert.equal(_this3.controller.get('q'), 'lol'); assert.equal(_this3.controller.get('z'), 123); assert.equal(_this3.$link1.attr('href'), urlPrefix + '/a-1?q=lol'); assert.equal(_this3.$link2.attr('href'), urlPrefix + '/a-2?q=lol'); assert.equal(_this3.$link3.attr('href'), urlPrefix + '/a-3?q=lol&z=123'); }); }; ModelDependentQPTestCase.prototype.queryParamsStickyTest3 = function (urlPrefix, articleLookup) { var _this4 = this; var assert = this.assert; assert.expect(32); this.addTemplate('application', '{{#each articles as |a|}} {{link-to \'Article\' \'' + articleLookup + '\' a.id id=a.id}} {{/each}}'); return this.boot().then(function () { _this4.expectedModelHookParams = { id: 'a-1', q: 'wat', z: 0 }; _this4.transitionTo(articleLookup, 'a-1'); assert.deepEqual(_this4.controller.get('model'), { id: 'a-1' }); assert.equal(_this4.controller.get('q'), 'wat'); assert.equal(_this4.controller.get('z'), 0); assert.equal(_this4.$link1.attr('href'), urlPrefix + '/a-1'); assert.equal(_this4.$link2.attr('href'), urlPrefix + '/a-2'); assert.equal(_this4.$link3.attr('href'), urlPrefix + '/a-3'); _this4.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 0 }; _this4.transitionTo(articleLookup, 'a-2', { queryParams: { q: 'lol' } }); assert.deepEqual(_this4.controller.get('model'), { id: 'a-2' }); assert.equal(_this4.controller.get('q'), 'lol'); assert.equal(_this4.controller.get('z'), 0); assert.equal(_this4.$link1.attr('href'), urlPrefix + '/a-1'); assert.equal(_this4.$link2.attr('href'), urlPrefix + '/a-2?q=lol'); assert.equal(_this4.$link3.attr('href'), urlPrefix + '/a-3'); _this4.expectedModelHookParams = { id: 'a-3', q: 'hay', z: 0 }; _this4.transitionTo(articleLookup, 'a-3', { queryParams: { q: 'hay' } }); assert.deepEqual(_this4.controller.get('model'), { id: 'a-3' }); assert.equal(_this4.controller.get('q'), 'hay'); assert.equal(_this4.controller.get('z'), 0); assert.equal(_this4.$link1.attr('href'), urlPrefix + '/a-1'); assert.equal(_this4.$link2.attr('href'), urlPrefix + '/a-2?q=lol'); assert.equal(_this4.$link3.attr('href'), urlPrefix + '/a-3?q=hay'); _this4.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 1 }; _this4.transitionTo(articleLookup, 'a-2', { queryParams: { z: 1 } }); assert.deepEqual(_this4.controller.get('model'), { id: 'a-2' }); assert.equal(_this4.controller.get('q'), 'lol'); assert.equal(_this4.controller.get('z'), 1); assert.equal(_this4.$link1.attr('href'), urlPrefix + '/a-1'); assert.equal(_this4.$link2.attr('href'), urlPrefix + '/a-2?q=lol&z=1'); assert.equal(_this4.$link3.attr('href'), urlPrefix + '/a-3?q=hay'); }); }; ModelDependentQPTestCase.prototype.queryParamsStickyTest4 = function (urlPrefix, articleLookup) { var _this5 = this; var assert = this.assert; assert.expect(24); this.setupApplication(); this.reopenController(articleLookup, { queryParams: { q: { scope: 'controller' } } }); return this.visitApplication().then(function () { (0, _emberMetal.run)(_this5.$link1, 'click'); _this5.assertCurrentPath(urlPrefix + '/a-1'); _this5.setAndFlush(_this5.controller, 'q', 'lol'); assert.equal(_this5.$link1.attr('href'), urlPrefix + '/a-1?q=lol'); assert.equal(_this5.$link2.attr('href'), urlPrefix + '/a-2?q=lol'); assert.equal(_this5.$link3.attr('href'), urlPrefix + '/a-3?q=lol'); (0, _emberMetal.run)(_this5.$link2, 'click'); assert.equal(_this5.controller.get('q'), 'lol'); assert.equal(_this5.controller.get('z'), 0); assert.deepEqual(_this5.controller.get('model'), { id: 'a-2' }); assert.equal(_this5.$link1.attr('href'), urlPrefix + '/a-1?q=lol'); assert.equal(_this5.$link2.attr('href'), urlPrefix + '/a-2?q=lol'); assert.equal(_this5.$link3.attr('href'), urlPrefix + '/a-3?q=lol'); _this5.expectedModelHookParams = { id: 'a-3', q: 'haha', z: 123 }; _this5.transitionTo(urlPrefix + '/a-3?q=haha&z=123'); assert.deepEqual(_this5.controller.get('model'), { id: 'a-3' }); assert.equal(_this5.controller.get('q'), 'haha'); assert.equal(_this5.controller.get('z'), 123); assert.equal(_this5.$link1.attr('href'), urlPrefix + '/a-1?q=haha'); assert.equal(_this5.$link2.attr('href'), urlPrefix + '/a-2?q=haha'); assert.equal(_this5.$link3.attr('href'), urlPrefix + '/a-3?q=haha&z=123'); _this5.setAndFlush(_this5.controller, 'q', 'woot'); assert.equal(_this5.$link1.attr('href'), urlPrefix + '/a-1?q=woot'); assert.equal(_this5.$link2.attr('href'), urlPrefix + '/a-2?q=woot'); assert.equal(_this5.$link3.attr('href'), urlPrefix + '/a-3?q=woot&z=123'); }); }; ModelDependentQPTestCase.prototype.queryParamsStickyTest5 = function (urlPrefix, commentsLookupKey) { var _this6 = this; var assert = this.assert; assert.expect(12); return this.boot().then(function () { _this6.transitionTo(commentsLookupKey, 'a-1'); var commentsCtrl = _this6.getController(commentsLookupKey); assert.equal(commentsCtrl.get('page'), 1); _this6.assertCurrentPath(urlPrefix + '/a-1/comments'); _this6.setAndFlush(commentsCtrl, 'page', 2); _this6.assertCurrentPath(urlPrefix + '/a-1/comments?page=2'); _this6.setAndFlush(commentsCtrl, 'page', 3); _this6.assertCurrentPath(urlPrefix + '/a-1/comments?page=3'); _this6.transitionTo(commentsLookupKey, 'a-2'); assert.equal(commentsCtrl.get('page'), 1); _this6.assertCurrentPath(urlPrefix + '/a-2/comments'); _this6.transitionTo(commentsLookupKey, 'a-1'); assert.equal(commentsCtrl.get('page'), 3); _this6.assertCurrentPath(urlPrefix + '/a-1/comments?page=3'); }); }; ModelDependentQPTestCase.prototype.queryParamsStickyTest6 = function (urlPrefix, articleLookup, commentsLookup) { var _this7 = this; var assert = this.assert; assert.expect(13); this.setupApplication(); this.reopenRoute(articleLookup, { resetController: function (controller, isExiting) { this.controllerFor(commentsLookup).set('page', 1); if (isExiting) { controller.set('q', 'imdone'); } } }); this.addTemplate('about', '{{link-to \'A\' \'' + commentsLookup + '\' \'a-1\' id=\'one\'}} {{link-to \'B\' \'' + commentsLookup + '\' \'a-2\' id=\'two\'}}'); return this.visitApplication().then(function () { _this7.transitionTo(commentsLookup, 'a-1'); var commentsCtrl = _this7.getController(commentsLookup); assert.equal(commentsCtrl.get('page'), 1); _this7.assertCurrentPath(urlPrefix + '/a-1/comments'); _this7.setAndFlush(commentsCtrl, 'page', 2); _this7.assertCurrentPath(urlPrefix + '/a-1/comments?page=2'); _this7.transitionTo(commentsLookup, 'a-2'); assert.equal(commentsCtrl.get('page'), 1); assert.equal(_this7.controller.get('q'), 'wat'); _this7.transitionTo(commentsLookup, 'a-1'); _this7.assertCurrentPath(urlPrefix + '/a-1/comments'); assert.equal(commentsCtrl.get('page'), 1); _this7.transitionTo('about'); assert.equal((0, _emberViews.jQuery)('#one').attr('href'), urlPrefix + '/a-1/comments?q=imdone'); assert.equal((0, _emberViews.jQuery)('#two').attr('href'), urlPrefix + '/a-2/comments'); }); }; return ModelDependentQPTestCase; }(_internalTestHelpers.QueryParamTestCase); (0, _internalTestHelpers.moduleFor)('Query Params - model-dependent state', function (_ModelDependentQPTest) { (0, _emberBabel.inherits)(_class, _ModelDependentQPTest); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _ModelDependentQPTest.apply(this, arguments)); } _class.prototype.setupApplication = function () { this.router.map(function () { this.route('article', { path: '/a/:id' }, function () { this.route('comments', { resetNamespace: true }); }); this.route('about'); }); var articles = (0, _emberRuntime.A)([{ id: 'a-1' }, { id: 'a-2' }, { id: 'a-3' }]); this.add('controller:application', _emberRuntime.Controller.extend({ articles: articles })); var self = this; var assert = this.assert; this.add('route:article', _emberRouting.Route.extend({ model: function (params) { if (self.expectedModelHookParams) { assert.deepEqual(params, self.expectedModelHookParams, 'the ArticleRoute model hook received the expected merged dynamic segment + query params hash'); self.expectedModelHookParams = null; } return articles.findBy('id', params.id); } })); this.add('controller:article', _emberRuntime.Controller.extend({ queryParams: ['q', 'z'], q: 'wat', z: 0 })); this.add('controller:comments', _emberRuntime.Controller.extend({ queryParams: 'page', page: 1 })); this.addTemplate('application', '{{#each articles as |a|}} 1{{link-to \'Article\' \'article\' a id=a.id}} {{/each}} {{outlet}}'); }; _class.prototype.visitApplication = function () { var _this9 = this; return this.visit('/').then(function () { var assert = _this9.assert; _this9.$link1 = (0, _emberViews.jQuery)('#a-1'); _this9.$link2 = (0, _emberViews.jQuery)('#a-2'); _this9.$link3 = (0, _emberViews.jQuery)('#a-3'); assert.equal(_this9.$link1.attr('href'), '/a/a-1'); assert.equal(_this9.$link2.attr('href'), '/a/a-2'); assert.equal(_this9.$link3.attr('href'), '/a/a-3'); _this9.controller = _this9.getController('article'); }); }; _class.prototype['@test query params have \'model\' stickiness by default'] = function () { return this.queryParamsStickyTest1('/a'); }; _class.prototype['@test query params have \'model\' stickiness by default (url changes)'] = function () { return this.queryParamsStickyTest2('/a'); }; _class.prototype['@test query params have \'model\' stickiness by default (params-based transitions)'] = function () { return this.queryParamsStickyTest3('/a', 'article'); }; _class.prototype['@test \'controller\' stickiness shares QP state between models'] = function () { return this.queryParamsStickyTest4('/a', 'article'); }; _class.prototype['@test \'model\' stickiness is scoped to current or first dynamic parent route'] = function () { return this.queryParamsStickyTest5('/a', 'comments'); }; _class.prototype['@test can reset query params using the resetController hook'] = function () { return this.queryParamsStickyTest6('/a', 'article', 'comments'); }; return _class; }(ModelDependentQPTestCase)); (0, _internalTestHelpers.moduleFor)('Query Params - model-dependent state (nested)', function (_ModelDependentQPTest2) { (0, _emberBabel.inherits)(_class2, _ModelDependentQPTest2); function _class2() { return (0, _emberBabel.possibleConstructorReturn)(this, _ModelDependentQPTest2.apply(this, arguments)); } _class2.prototype.setupApplication = function () { this.router.map(function () { this.route('site', function () { this.route('article', { path: '/a/:id' }, function () { this.route('comments'); }); }); this.route('about'); }); var site_articles = (0, _emberRuntime.A)([{ id: 'a-1' }, { id: 'a-2' }, { id: 'a-3' }]); this.add('controller:application', _emberRuntime.Controller.extend({ articles: site_articles })); var self = this; var assert = this.assert; this.add('route:site.article', _emberRouting.Route.extend({ model: function (params) { if (self.expectedModelHookParams) { assert.deepEqual(params, self.expectedModelHookParams, 'the ArticleRoute model hook received the expected merged dynamic segment + query params hash'); self.expectedModelHookParams = null; } return site_articles.findBy('id', params.id); } })); this.add('controller:site.article', _emberRuntime.Controller.extend({ queryParams: ['q', 'z'], q: 'wat', z: 0 })); this.add('controller:site.article.comments', _emberRuntime.Controller.extend({ queryParams: 'page', page: 1 })); this.addTemplate('application', '{{#each articles as |a|}} {{link-to \'Article\' \'site.article\' a id=a.id}} {{/each}} {{outlet}}'); }; _class2.prototype.visitApplication = function () { var _this11 = this; return this.visit('/').then(function () { var assert = _this11.assert; _this11.$link1 = (0, _emberViews.jQuery)('#a-1'); _this11.$link2 = (0, _emberViews.jQuery)('#a-2'); _this11.$link3 = (0, _emberViews.jQuery)('#a-3'); assert.equal(_this11.$link1.attr('href'), '/site/a/a-1'); assert.equal(_this11.$link2.attr('href'), '/site/a/a-2'); assert.equal(_this11.$link3.attr('href'), '/site/a/a-3'); _this11.controller = _this11.getController('site.article'); }); }; _class2.prototype['@test query params have \'model\' stickiness by default'] = function () { return this.queryParamsStickyTest1('/site/a'); }; _class2.prototype['@test query params have \'model\' stickiness by default (url changes)'] = function () { return this.queryParamsStickyTest2('/site/a'); }; _class2.prototype['@test query params have \'model\' stickiness by default (params-based transitions)'] = function () { return this.queryParamsStickyTest3('/site/a', 'site.article'); }; _class2.prototype['@test \'controller\' stickiness shares QP state between models'] = function () { return this.queryParamsStickyTest4('/site/a', 'site.article'); }; _class2.prototype['@test \'model\' stickiness is scoped to current or first dynamic parent route'] = function () { return this.queryParamsStickyTest5('/site/a', 'site.article.comments'); }; _class2.prototype['@test can reset query params using the resetController hook'] = function () { return this.queryParamsStickyTest6('/site/a', 'site.article', 'site.article.comments'); }; return _class2; }(ModelDependentQPTestCase)); (0, _internalTestHelpers.moduleFor)('Query Params - model-dependent state (nested & more than 1 dynamic segment)', function (_ModelDependentQPTest3) { (0, _emberBabel.inherits)(_class3, _ModelDependentQPTest3); function _class3() { return (0, _emberBabel.possibleConstructorReturn)(this, _ModelDependentQPTest3.apply(this, arguments)); } _class3.prototype.setupApplication = function () { this.router.map(function () { this.route('site', { path: '/site/:site_id' }, function () { this.route('article', { path: '/a/:article_id' }, function () { this.route('comments'); }); }); }); var sites = (0, _emberRuntime.A)([{ id: 's-1' }, { id: 's-2' }, { id: 's-3' }]); var site_articles = (0, _emberRuntime.A)([{ id: 'a-1' }, { id: 'a-2' }, { id: 'a-3' }]); this.add('controller:application', _emberRuntime.Controller.extend({ siteArticles: site_articles, sites: sites, allSitesAllArticles: (0, _emberMetal.computed)({ get: function () { var ret = []; var siteArticles = this.siteArticles; var sites = this.sites; sites.forEach(function (site) { ret = ret.concat(siteArticles.map(function (article) { return { id: site.id + '-' + article.id, site_id: site.id, article_id: article.id }; })); }); return ret; } }) })); var self = this; var assert = this.assert; this.add('route:site', _emberRouting.Route.extend({ model: function (params) { if (self.expectedSiteModelHookParams) { assert.deepEqual(params, self.expectedSiteModelHookParams, 'the SiteRoute model hook received the expected merged dynamic segment + query params hash'); self.expectedSiteModelHookParams = null; } return sites.findBy('id', params.site_id); } })); this.add('route:site.article', _emberRouting.Route.extend({ model: function (params) { if (self.expectedArticleModelHookParams) { assert.deepEqual(params, self.expectedArticleModelHookParams, 'the SiteArticleRoute model hook received the expected merged dynamic segment + query params hash'); self.expectedArticleModelHookParams = null; } return site_articles.findBy('id', params.article_id); } })); this.add('controller:site', _emberRuntime.Controller.extend({ queryParams: ['country'], country: 'au' })); this.add('controller:site.article', _emberRuntime.Controller.extend({ queryParams: ['q', 'z'], q: 'wat', z: 0 })); this.add('controller:site.article.comments', _emberRuntime.Controller.extend({ queryParams: ['page'], page: 1 })); this.addTemplate('application', '{{#each allSitesAllArticles as |a|}} {{#link-to \'site.article\' a.site_id a.article_id id=a.id}}Article [{{a.site_id}}] [{{a.article_id}}]{{/link-to}} {{/each}} {{outlet}}'); }; _class3.prototype.visitApplication = function () { var _this13 = this; return this.visit('/').then(function () { var assert = _this13.assert; _this13.links = {}; _this13.links['s-1-a-1'] = (0, _emberViews.jQuery)('#s-1-a-1'); _this13.links['s-1-a-2'] = (0, _emberViews.jQuery)('#s-1-a-2'); _this13.links['s-1-a-3'] = (0, _emberViews.jQuery)('#s-1-a-3'); _this13.links['s-2-a-1'] = (0, _emberViews.jQuery)('#s-2-a-1'); _this13.links['s-2-a-2'] = (0, _emberViews.jQuery)('#s-2-a-2'); _this13.links['s-2-a-3'] = (0, _emberViews.jQuery)('#s-2-a-3'); _this13.links['s-3-a-1'] = (0, _emberViews.jQuery)('#s-3-a-1'); _this13.links['s-3-a-2'] = (0, _emberViews.jQuery)('#s-3-a-2'); _this13.links['s-3-a-3'] = (0, _emberViews.jQuery)('#s-3-a-3'); assert.equal(_this13.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1'); assert.equal(_this13.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2'); assert.equal(_this13.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3'); assert.equal(_this13.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1'); assert.equal(_this13.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2'); assert.equal(_this13.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3'); assert.equal(_this13.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1'); assert.equal(_this13.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2'); assert.equal(_this13.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3'); _this13.site_controller = _this13.getController('site'); _this13.article_controller = _this13.getController('site.article'); }); }; _class3.prototype['@test query params have \'model\' stickiness by default'] = function (assert) { var _this14 = this; assert.expect(59); return this.boot().then(function () { (0, _emberMetal.run)(_this14.links['s-1-a-1'], 'click'); assert.deepEqual(_this14.site_controller.get('model'), { id: 's-1' }); assert.deepEqual(_this14.article_controller.get('model'), { id: 'a-1' }); _this14.assertCurrentPath('/site/s-1/a/a-1'); _this14.setAndFlush(_this14.article_controller, 'q', 'lol'); assert.equal(_this14.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(_this14.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2'); assert.equal(_this14.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3'); assert.equal(_this14.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?q=lol'); assert.equal(_this14.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2'); assert.equal(_this14.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3'); assert.equal(_this14.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol'); assert.equal(_this14.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2'); assert.equal(_this14.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3'); _this14.setAndFlush(_this14.site_controller, 'country', 'us'); assert.equal(_this14.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?country=us&q=lol'); assert.equal(_this14.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?country=us'); assert.equal(_this14.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?country=us'); assert.equal(_this14.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?q=lol'); assert.equal(_this14.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2'); assert.equal(_this14.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3'); assert.equal(_this14.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol'); assert.equal(_this14.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2'); assert.equal(_this14.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3'); (0, _emberMetal.run)(_this14.links['s-1-a-2'], 'click'); assert.equal(_this14.site_controller.get('country'), 'us'); assert.equal(_this14.article_controller.get('q'), 'wat'); assert.equal(_this14.article_controller.get('z'), 0); assert.deepEqual(_this14.site_controller.get('model'), { id: 's-1' }); assert.deepEqual(_this14.article_controller.get('model'), { id: 'a-2' }); assert.equal(_this14.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?country=us&q=lol'); assert.equal(_this14.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?country=us'); assert.equal(_this14.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?country=us'); assert.equal(_this14.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?q=lol'); assert.equal(_this14.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2'); assert.equal(_this14.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3'); assert.equal(_this14.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol'); assert.equal(_this14.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2'); assert.equal(_this14.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3'); (0, _emberMetal.run)(_this14.links['s-2-a-2'], 'click'); assert.equal(_this14.site_controller.get('country'), 'au'); assert.equal(_this14.article_controller.get('q'), 'wat'); assert.equal(_this14.article_controller.get('z'), 0); assert.deepEqual(_this14.site_controller.get('model'), { id: 's-2' }); assert.deepEqual(_this14.article_controller.get('model'), { id: 'a-2' }); assert.equal(_this14.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?country=us&q=lol'); assert.equal(_this14.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?country=us'); assert.equal(_this14.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?country=us'); assert.equal(_this14.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?q=lol'); assert.equal(_this14.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2'); assert.equal(_this14.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3'); assert.equal(_this14.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol'); assert.equal(_this14.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2'); assert.equal(_this14.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3'); }); }; _class3.prototype['@test query params have \'model\' stickiness by default (url changes)'] = function (assert) { var _this15 = this; assert.expect(88); return this.boot().then(function () { _this15.expectedSiteModelHookParams = { site_id: 's-1', country: 'au' }; _this15.expectedArticleModelHookParams = { article_id: 'a-1', q: 'lol', z: 0 }; _this15.transitionTo('/site/s-1/a/a-1?q=lol'); assert.deepEqual(_this15.site_controller.get('model'), { id: 's-1' }, 'site controller\'s model is s-1'); assert.deepEqual(_this15.article_controller.get('model'), { id: 'a-1' }, 'article controller\'s model is a-1'); assert.equal(_this15.site_controller.get('country'), 'au'); assert.equal(_this15.article_controller.get('q'), 'lol'); assert.equal(_this15.article_controller.get('z'), 0); assert.equal(_this15.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(_this15.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2'); assert.equal(_this15.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3'); assert.equal(_this15.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?q=lol'); assert.equal(_this15.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2'); assert.equal(_this15.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3'); assert.equal(_this15.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol'); assert.equal(_this15.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2'); assert.equal(_this15.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3'); _this15.expectedSiteModelHookParams = { site_id: 's-2', country: 'us' }; _this15.expectedArticleModelHookParams = { article_id: 'a-1', q: 'lol', z: 0 }; _this15.transitionTo('/site/s-2/a/a-1?country=us&q=lol'); assert.deepEqual(_this15.site_controller.get('model'), { id: 's-2' }, 'site controller\'s model is s-2'); assert.deepEqual(_this15.article_controller.get('model'), { id: 'a-1' }, 'article controller\'s model is a-1'); assert.equal(_this15.site_controller.get('country'), 'us'); assert.equal(_this15.article_controller.get('q'), 'lol'); assert.equal(_this15.article_controller.get('z'), 0); assert.equal(_this15.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(_this15.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2'); assert.equal(_this15.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3'); assert.equal(_this15.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=lol'); assert.equal(_this15.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us'); assert.equal(_this15.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us'); assert.equal(_this15.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol'); assert.equal(_this15.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2'); assert.equal(_this15.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3'); _this15.expectedSiteModelHookParams = { site_id: 's-2', country: 'us' }; _this15.expectedArticleModelHookParams = { article_id: 'a-2', q: 'lol', z: 0 }; _this15.transitionTo('/site/s-2/a/a-2?country=us&q=lol'); assert.deepEqual(_this15.site_controller.get('model'), { id: 's-2' }, 'site controller\'s model is s-2'); assert.deepEqual(_this15.article_controller.get('model'), { id: 'a-2' }, 'article controller\'s model is a-2'); assert.equal(_this15.site_controller.get('country'), 'us'); assert.equal(_this15.article_controller.get('q'), 'lol'); assert.equal(_this15.article_controller.get('z'), 0); assert.equal(_this15.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(_this15.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(_this15.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3'); assert.equal(_this15.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=lol'); assert.equal(_this15.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol'); assert.equal(_this15.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us'); assert.equal(_this15.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol'); assert.equal(_this15.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol'); assert.equal(_this15.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3'); _this15.expectedSiteModelHookParams = { site_id: 's-2', country: 'us' }; _this15.expectedArticleModelHookParams = { article_id: 'a-3', q: 'lol', z: 123 }; _this15.transitionTo('/site/s-2/a/a-3?country=us&q=lol&z=123'); assert.deepEqual(_this15.site_controller.get('model'), { id: 's-2' }, 'site controller\'s model is s-2'); assert.deepEqual(_this15.article_controller.get('model'), { id: 'a-3' }, 'article controller\'s model is a-3'); assert.equal(_this15.site_controller.get('country'), 'us'); assert.equal(_this15.article_controller.get('q'), 'lol'); assert.equal(_this15.article_controller.get('z'), 123); assert.equal(_this15.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(_this15.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(_this15.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=lol&z=123'); assert.equal(_this15.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=lol'); assert.equal(_this15.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol'); assert.equal(_this15.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us&q=lol&z=123'); assert.equal(_this15.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol'); assert.equal(_this15.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol'); assert.equal(_this15.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?q=lol&z=123'); _this15.expectedSiteModelHookParams = { site_id: 's-3', country: 'nz' }; _this15.expectedArticleModelHookParams = { article_id: 'a-3', q: 'lol', z: 123 }; _this15.transitionTo('/site/s-3/a/a-3?country=nz&q=lol&z=123'); assert.deepEqual(_this15.site_controller.get('model'), { id: 's-3' }, 'site controller\'s model is s-3'); assert.deepEqual(_this15.article_controller.get('model'), { id: 'a-3' }, 'article controller\'s model is a-3'); assert.equal(_this15.site_controller.get('country'), 'nz'); assert.equal(_this15.article_controller.get('q'), 'lol'); assert.equal(_this15.article_controller.get('z'), 123); assert.equal(_this15.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol'); assert.equal(_this15.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(_this15.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=lol&z=123'); assert.equal(_this15.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=lol'); assert.equal(_this15.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol'); assert.equal(_this15.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us&q=lol&z=123'); assert.equal(_this15.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?country=nz&q=lol'); assert.equal(_this15.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?country=nz&q=lol'); assert.equal(_this15.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?country=nz&q=lol&z=123'); }); }; _class3.prototype['@test query params have \'model\' stickiness by default (params-based transitions)'] = function (assert) { var _this16 = this; assert.expect(118); return this.boot().then(function () { _this16.expectedSiteModelHookParams = { site_id: 's-1', country: 'au' }; _this16.expectedArticleModelHookParams = { article_id: 'a-1', q: 'wat', z: 0 }; _this16.transitionTo('site.article', 's-1', 'a-1'); assert.deepEqual(_this16.site_controller.get('model'), { id: 's-1' }); assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-1' }); assert.equal(_this16.site_controller.get('country'), 'au'); assert.equal(_this16.article_controller.get('q'), 'wat'); assert.equal(_this16.article_controller.get('z'), 0); assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1'); assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2'); assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3'); assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1'); assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2'); assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3'); assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1'); assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2'); assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3'); _this16.expectedSiteModelHookParams = { site_id: 's-1', country: 'au' }; _this16.expectedArticleModelHookParams = { article_id: 'a-2', q: 'lol', z: 0 }; _this16.transitionTo('site.article', 's-1', 'a-2', { queryParams: { q: 'lol' } }); assert.deepEqual(_this16.site_controller.get('model'), { id: 's-1' }); assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-2' }); assert.equal(_this16.site_controller.get('country'), 'au'); assert.equal(_this16.article_controller.get('q'), 'lol'); assert.equal(_this16.article_controller.get('z'), 0); assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1'); assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3'); assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1'); assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?q=lol'); assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3'); assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1'); assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol'); assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3'); _this16.expectedSiteModelHookParams = { site_id: 's-1', country: 'au' }; _this16.expectedArticleModelHookParams = { article_id: 'a-3', q: 'hay', z: 0 }; _this16.transitionTo('site.article', 's-1', 'a-3', { queryParams: { q: 'hay' } }); assert.deepEqual(_this16.site_controller.get('model'), { id: 's-1' }); assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-3' }); assert.equal(_this16.site_controller.get('country'), 'au'); assert.equal(_this16.article_controller.get('q'), 'hay'); assert.equal(_this16.article_controller.get('z'), 0); assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1'); assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol'); assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=hay'); assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1'); assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?q=lol'); assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?q=hay'); assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1'); assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol'); assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?q=hay'); _this16.expectedSiteModelHookParams = { site_id: 's-1', country: 'au' }; _this16.expectedArticleModelHookParams = { article_id: 'a-2', q: 'lol', z: 1 }; _this16.transitionTo('site.article', 's-1', 'a-2', { queryParams: { z: 1 } }); assert.deepEqual(_this16.site_controller.get('model'), { id: 's-1' }); assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-2' }); assert.equal(_this16.site_controller.get('country'), 'au'); assert.equal(_this16.article_controller.get('q'), 'lol'); assert.equal(_this16.article_controller.get('z'), 1); assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1'); assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=hay'); assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1'); assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?q=lol&z=1'); assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?q=hay'); assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1'); assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol&z=1'); assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?q=hay'); _this16.expectedSiteModelHookParams = { site_id: 's-2', country: 'us' }; _this16.expectedArticleModelHookParams = { article_id: 'a-2', q: 'lol', z: 1 }; _this16.transitionTo('site.article', 's-2', 'a-2', { queryParams: { country: 'us' } }); assert.deepEqual(_this16.site_controller.get('model'), { id: 's-2' }); assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-2' }); assert.equal(_this16.site_controller.get('country'), 'us'); assert.equal(_this16.article_controller.get('q'), 'lol'); assert.equal(_this16.article_controller.get('z'), 1); assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1'); assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=hay'); assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us'); assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol&z=1'); assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us&q=hay'); assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1'); assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol&z=1'); assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?q=hay'); _this16.expectedSiteModelHookParams = { site_id: 's-2', country: 'us' }; _this16.expectedArticleModelHookParams = { article_id: 'a-1', q: 'yeah', z: 0 }; _this16.transitionTo('site.article', 's-2', 'a-1', { queryParams: { q: 'yeah' } }); assert.deepEqual(_this16.site_controller.get('model'), { id: 's-2' }); assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-1' }); assert.equal(_this16.site_controller.get('country'), 'us'); assert.equal(_this16.article_controller.get('q'), 'yeah'); assert.equal(_this16.article_controller.get('z'), 0); assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=yeah'); assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=hay'); assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=yeah'); assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol&z=1'); assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us&q=hay'); assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=yeah'); assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol&z=1'); assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?q=hay'); _this16.expectedSiteModelHookParams = { site_id: 's-3', country: 'nz' }; _this16.expectedArticleModelHookParams = { article_id: 'a-3', q: 'hay', z: 3 }; _this16.transitionTo('site.article', 's-3', 'a-3', { queryParams: { country: 'nz', z: 3 } }); assert.deepEqual(_this16.site_controller.get('model'), { id: 's-3' }); assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-3' }); assert.equal(_this16.site_controller.get('country'), 'nz'); assert.equal(_this16.article_controller.get('q'), 'hay'); assert.equal(_this16.article_controller.get('z'), 3); assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=yeah'); assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol&z=1'); assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=hay&z=3'); assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=yeah'); assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol&z=1'); assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us&q=hay&z=3'); assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?country=nz&q=yeah'); assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?country=nz&q=lol&z=1'); assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?country=nz&q=hay&z=3'); }); }; return _class3; }(ModelDependentQPTestCase)); }); enifed('ember/tests/routing/query_params_test/overlapping_query_params_test', ['ember-babel', 'ember-runtime', 'ember-routing', 'ember-metal', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberRouting, _emberMetal, _internalTestHelpers) { 'use strict'; (0, _internalTestHelpers.moduleFor)('Query Params - overlapping query param property names', function (_QueryParamTestCase) { (0, _emberBabel.inherits)(_class, _QueryParamTestCase); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments)); } _class.prototype.setupBase = function () { this.router.map(function () { this.route('parent', function () { this.route('child'); }); }); return this.visit('/parent/child'); }; _class.prototype['@test can remap same-named qp props'] = function (assert) { var _this2 = this; assert.expect(7); this.setMappedQPController('parent'); this.setMappedQPController('parent.child', 'page', 'childPage'); return this.setupBase().then(function () { _this2.assertCurrentPath('/parent/child'); var parentController = _this2.getController('parent'); var parentChildController = _this2.getController('parent.child'); _this2.setAndFlush(parentController, 'page', 2); _this2.assertCurrentPath('/parent/child?parentPage=2'); _this2.setAndFlush(parentController, 'page', 1); _this2.assertCurrentPath('/parent/child'); _this2.setAndFlush(parentChildController, 'page', 2); _this2.assertCurrentPath('/parent/child?childPage=2'); _this2.setAndFlush(parentChildController, 'page', 1); _this2.assertCurrentPath('/parent/child'); (0, _emberMetal.run)(function () { parentController.set('page', 2); parentChildController.set('page', 2); }); _this2.assertCurrentPath('/parent/child?childPage=2&parentPage=2'); (0, _emberMetal.run)(function () { parentController.set('page', 1); parentChildController.set('page', 1); }); _this2.assertCurrentPath('/parent/child'); }); }; _class.prototype['@test query params can be either controller property or url key'] = function (assert) { var _this3 = this; assert.expect(3); this.setMappedQPController('parent'); return this.setupBase().then(function () { _this3.assertCurrentPath('/parent/child'); _this3.transitionTo('parent.child', { queryParams: { page: 2 } }); _this3.assertCurrentPath('/parent/child?parentPage=2'); _this3.transitionTo('parent.child', { queryParams: { parentPage: 3 } }); _this3.assertCurrentPath('/parent/child?parentPage=3'); }); }; _class.prototype['@test query param matching a url key and controller property'] = function (assert) { var _this4 = this; assert.expect(3); this.setMappedQPController('parent', 'page', 'parentPage'); this.setMappedQPController('parent.child', 'index', 'page'); return this.setupBase().then(function () { _this4.transitionTo('parent.child', { queryParams: { page: 2 } }); _this4.assertCurrentPath('/parent/child?parentPage=2'); _this4.transitionTo('parent.child', { queryParams: { parentPage: 3 } }); _this4.assertCurrentPath('/parent/child?parentPage=3'); _this4.transitionTo('parent.child', { queryParams: { index: 2, page: 2 } }); _this4.assertCurrentPath('/parent/child?page=2&parentPage=2'); }); }; _class.prototype['@test query param matching same property on two controllers use the urlKey higher in the chain'] = function (assert) { var _this5 = this; assert.expect(4); this.setMappedQPController('parent', 'page', 'parentPage'); this.setMappedQPController('parent.child', 'page', 'childPage'); return this.setupBase().then(function () { _this5.transitionTo('parent.child', { queryParams: { page: 2 } }); _this5.assertCurrentPath('/parent/child?parentPage=2'); _this5.transitionTo('parent.child', { queryParams: { parentPage: 3 } }); _this5.assertCurrentPath('/parent/child?parentPage=3'); _this5.transitionTo('parent.child', { queryParams: { childPage: 2, page: 2 } }); _this5.assertCurrentPath('/parent/child?childPage=2&parentPage=2'); _this5.transitionTo('parent.child', { queryParams: { childPage: 3, parentPage: 4 } }); _this5.assertCurrentPath('/parent/child?childPage=3&parentPage=4'); }); }; _class.prototype['@test query params does not error when a query parameter exists for route instances that share a controller'] = function (assert) { var _this6 = this; assert.expect(1); var parentController = _emberRuntime.Controller.extend({ queryParams: { page: 'page' } }); this.add('controller:parent', parentController); this.add('route:parent.child', _emberRouting.Route.extend({ controllerName: 'parent' })); return this.setupBase('/parent').then(function () { _this6.transitionTo('parent.child', { queryParams: { page: 2 } }); _this6.assertCurrentPath('/parent/child?page=2'); }); }; _class.prototype['@test query params in the same route hierarchy with the same url key get auto-scoped'] = function (assert) { var _this7 = this; assert.expect(1); this.setMappedQPController('parent'); this.setMappedQPController('parent.child'); expectAssertion(function () { _this7.setupBase(); }, 'You\'re not allowed to have more than one controller property map to the same query param key, but both `parent:page` and `parent.child:page` map to `parentPage`. You can fix this by mapping one of the controller properties to a different query param key via the `as` config option, e.g. `page: { as: \'other-page\' }`'); }; _class.prototype['@test Support shared but overridable mixin pattern'] = function (assert) { var _this8 = this; assert.expect(7); var HasPage = _emberMetal.Mixin.create({ queryParams: 'page', page: 1 }); this.add('controller:parent', _emberRuntime.Controller.extend(HasPage, { queryParams: { page: 'yespage' } })); this.add('controller:parent.child', _emberRuntime.Controller.extend(HasPage)); return this.setupBase().then(function () { _this8.assertCurrentPath('/parent/child'); var parentController = _this8.getController('parent'); var parentChildController = _this8.getController('parent.child'); _this8.setAndFlush(parentChildController, 'page', 2); _this8.assertCurrentPath('/parent/child?page=2'); assert.equal(parentController.get('page'), 1); assert.equal(parentChildController.get('page'), 2); _this8.setAndFlush(parentController, 'page', 2); _this8.assertCurrentPath('/parent/child?page=2&yespage=2'); assert.equal(parentController.get('page'), 2); assert.equal(parentChildController.get('page'), 2); }); }; return _class; }(_internalTestHelpers.QueryParamTestCase)); }); enifed('ember/tests/routing/query_params_test/query_param_async_get_handler_test', ['ember-babel', 'ember-metal', 'ember-runtime', 'ember-routing', 'internal-test-helpers'], function (_emberBabel, _emberMetal, _emberRuntime, _emberRouting, _internalTestHelpers) { 'use strict'; // These tests mimic what happens with lazily loaded Engines. (0, _internalTestHelpers.moduleFor)('Query Params - async get handler', function (_QueryParamTestCase) { (0, _emberBabel.inherits)(_class, _QueryParamTestCase); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments)); } _class.prototype['@test can render a link to an asynchronously loaded route without fetching the route'] = function (assert) { var _this2 = this; assert.expect(4); this.router.map(function () { this.route('post', { path: '/post/:id' }); }); this.setSingleQPController('post'); (function () { _this2.addTemplate('application', '\n {{link-to \'Post\' \'post\' 1337 (query-params foo=\'bar\') class=\'post-link\'}}\n {{link-to \'Post\' \'post\' 7331 (query-params foo=\'boo\') class=\'post-link\'}}\n {{outlet}}\n '); })(); return this.visitAndAssert('/').then(function () { assert.equal(_this2.$('.post-link').eq(0).attr('href'), '/post/1337?foo=bar', 'renders correctly with default QP value'); assert.equal(_this2.$('.post-link').eq(1).attr('href'), '/post/7331?foo=boo', 'renders correctly with non-default QP value'); assert.deepEqual(_this2.fetchedHandlers, ['application', 'index'], 'only fetched the handlers for the route we\'re on'); }); }; _class.prototype['@test can transitionTo to an asynchronously loaded route with simple query params'] = function (assert) { var _this3 = this; assert.expect(6); this.router.map(function () { this.route('post', { path: '/post/:id' }); this.route('posts'); }); this.setSingleQPController('post'); var postController = void 0; return this.visitAndAssert('/').then(function () { postController = _this3.getController('post'); return _this3.transitionTo('posts').then(function () { _this3.assertCurrentPath('/posts'); }); }).then(function () { return _this3.transitionTo('post', 1337, { queryParams: { foo: 'boo' } }).then(function () { assert.equal(postController.get('foo'), 'boo', 'simple QP is correctly set on controller'); _this3.assertCurrentPath('/post/1337?foo=boo'); }); }).then(function () { return _this3.transitionTo('post', 1337, { queryParams: { foo: 'bar' } }).then(function () { assert.equal(postController.get('foo'), 'bar', 'simple QP is correctly set with default value'); _this3.assertCurrentPath('/post/1337'); }); }); }; _class.prototype['@test can transitionTo to an asynchronously loaded route with array query params'] = function (assert) { var _this4 = this; assert.expect(5); this.router.map(function () { this.route('post', { path: '/post/:id' }); }); this.setSingleQPController('post', 'comments', []); var postController = void 0; return this.visitAndAssert('/').then(function () { postController = _this4.getController('post'); return _this4.transitionTo('post', 1337, { queryParams: { comments: [1, 2] } }).then(function () { assert.deepEqual(postController.get('comments'), [1, 2], 'array QP is correctly set with default value'); _this4.assertCurrentPath('/post/1337?comments=%5B1%2C2%5D'); }); }).then(function () { return _this4.transitionTo('post', 1338).then(function () { assert.deepEqual(postController.get('comments'), [], 'array QP is correctly set on controller'); _this4.assertCurrentPath('/post/1338'); }); }); }; _class.prototype['@test can transitionTo to an asynchronously loaded route with mapped query params'] = function (assert) { var _this5 = this; assert.expect(7); this.router.map(function () { this.route('post', { path: '/post/:id' }, function () { this.route('index', { path: '/' }); }); }); this.setSingleQPController('post'); this.setMappedQPController('post.index', 'comment', 'note'); var postController = void 0; var postIndexController = void 0; return this.visitAndAssert('/').then(function () { postController = _this5.getController('post'); postIndexController = _this5.getController('post.index'); return _this5.transitionTo('post.index', 1337, { queryParams: { note: 6, foo: 'boo' } }).then(function () { assert.equal(postController.get('foo'), 'boo', 'simple QP is correctly set on controller'); assert.equal(postIndexController.get('comment'), 6, 'mapped QP is correctly set on controller'); _this5.assertCurrentPath('/post/1337?foo=boo¬e=6'); }); }).then(function () { return _this5.transitionTo('post', 1337, { queryParams: { foo: 'bar' } }).then(function () { assert.equal(postController.get('foo'), 'bar', 'simple QP is correctly set with default value'); assert.equal(postIndexController.get('comment'), 6, 'mapped QP retains value scoped to model'); _this5.assertCurrentPath('/post/1337?note=6'); }); }); }; _class.prototype['@test can transitionTo with a URL'] = function (assert) { var _this6 = this; assert.expect(7); this.router.map(function () { this.route('post', { path: '/post/:id' }, function () { this.route('index', { path: '/' }); }); }); this.setSingleQPController('post'); this.setMappedQPController('post.index', 'comment', 'note'); var postController = void 0; var postIndexController = void 0; return this.visitAndAssert('/').then(function () { postController = _this6.getController('post'); postIndexController = _this6.getController('post.index'); return _this6.transitionTo('/post/1337?foo=boo¬e=6').then(function () { assert.equal(postController.get('foo'), 'boo', 'simple QP is correctly deserialized on controller'); assert.equal(postIndexController.get('comment'), 6, 'mapped QP is correctly deserialized on controller'); _this6.assertCurrentPath('/post/1337?foo=boo¬e=6'); }); }).then(function () { return _this6.transitionTo('/post/1337?note=6').then(function () { assert.equal(postController.get('foo'), 'bar', 'simple QP is correctly deserialized with default value'); assert.equal(postIndexController.get('comment'), 6, 'mapped QP retains value scoped to model'); _this6.assertCurrentPath('/post/1337?note=6'); }); }); }; _class.prototype['@test undefined isn\'t serialized or deserialized into a string'] = function (assert) { var _this7 = this; assert.expect(4); this.router.map(function () { this.route('example'); }); this.addTemplate('application', '{{link-to \'Example\' \'example\' (query-params foo=undefined) id=\'the-link\'}}'); this.setSingleQPController('example', 'foo', undefined, { foo: undefined }); this.add('route:example', _emberRouting.Route.extend({ model: function (params) { assert.deepEqual(params, { foo: undefined }); } })); return this.visitAndAssert('/').then(function () { assert.equal(_this7.$('#the-link').attr('href'), '/example', 'renders without undefined qp serialized'); return _this7.transitionTo('example', { queryParams: { foo: undefined } }).then(function () { _this7.assertCurrentPath('/example'); }); }); }; (0, _emberBabel.createClass)(_class, [{ key: 'routerOptions', get: function () { var fetchedHandlers = this.fetchedHandlers = []; return { location: 'test', init: function () { this._super.apply(this, arguments); this._seenHandlers = Object.create(null); this._handlerPromises = Object.create(null); }, _getQPMeta: function (handlerInfo) { var handler = this._seenHandlers[handlerInfo.name]; if (handler) { return (0, _emberMetal.get)(handler, '_qp'); } }, _getHandlerFunction: function () { var getHandler = this._super.apply(this, arguments); var handlerPromises = this._handlerPromises; var seenHandlers = this._seenHandlers; return function (routeName) { fetchedHandlers.push(routeName); // Cache the returns so we don't have more than one Promise for a // given handler. return handlerPromises[routeName] || (handlerPromises[routeName] = new _emberRuntime.RSVP.Promise(function (resolve) { setTimeout(function () { var handler = getHandler(routeName); seenHandlers[routeName] = handler; resolve(handler); }, 10); })); }; } }; } }]); return _class; }(_internalTestHelpers.QueryParamTestCase)); }); enifed('ember/tests/routing/query_params_test/query_params_paramless_link_to_test', ['ember-babel', 'ember-runtime', 'ember-views', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberViews, _internalTestHelpers) { 'use strict'; (0, _internalTestHelpers.moduleFor)('Query Params - paramless link-to', function (_QueryParamTestCase) { (0, _emberBabel.inherits)(_class, _QueryParamTestCase); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments)); } _class.prototype.testParamlessLinks = function (assert, routeName) { assert.expect(1); this.addTemplate(routeName, '{{link-to \'index\' \'index\' id=\'index-link\'}}'); this.add('controller:' + routeName, _emberRuntime.Controller.extend({ queryParams: ['foo'], foo: 'wat' })); return this.visit('/?foo=YEAH').then(function () { assert.equal((0, _emberViews.jQuery)('#index-link').attr('href'), '/?foo=YEAH'); }); }; _class.prototype['@test param-less links in an app booted with query params in the URL don\'t reset the query params: application'] = function (assert) { return this.testParamlessLinks(assert, 'application'); }; _class.prototype['@test param-less links in an app booted with query params in the URL don\'t reset the query params: index'] = function (assert) { return this.testParamlessLinks(assert, 'index'); }; return _class; }(_internalTestHelpers.QueryParamTestCase)); }); enifed('ember/tests/routing/query_params_test/shared_state_test', ['ember-babel', 'ember-runtime', 'ember', 'ember-metal', 'ember-views', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _ember, _emberMetal, _emberViews, _internalTestHelpers) { 'use strict'; (0, _internalTestHelpers.moduleFor)('Query Params - shared service state', function (_QueryParamTestCase) { (0, _emberBabel.inherits)(_class, _QueryParamTestCase); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments)); } _class.prototype.boot = function () { this.setupApplication(); return this.visitApplication(); }; _class.prototype.setupApplication = function () { this.router.map(function () { this.route('home', { path: '/' }); this.route('dashboard'); }); this.add('service:filters', _emberRuntime.Service.extend({ shared: true })); this.add('controller:home', _emberRuntime.Controller.extend({ filters: _ember.default.inject.service() })); this.add('controller:dashboard', _emberRuntime.Controller.extend({ filters: _ember.default.inject.service(), queryParams: [{ 'filters.shared': 'shared' }] })); this.addTemplate('application', '{{link-to \'Home\' \'home\' }}
    {{outlet}}
    '); this.addTemplate('home', '{{link-to \'Dashboard\' \'dashboard\' }}{{input type="checkbox" id=\'filters-checkbox\' checked=(mut filters.shared) }}'); this.addTemplate('dashboard', '{{link-to \'Home\' \'home\' }}'); }; _class.prototype.visitApplication = function () { return this.visit('/'); }; _class.prototype['@test can modify shared state before transition'] = function (assert) { var _this2 = this; assert.expect(1); return this.boot().then(function () { _this2.$input = (0, _emberViews.jQuery)('#filters-checkbox'); // click the checkbox once to set filters.shared to false (0, _emberMetal.run)(_this2.$input, 'click'); return _this2.visit('/dashboard').then(function () { assert.ok(true, 'expecting navigating to dashboard to succeed'); }); }); }; _class.prototype['@test can modify shared state back to the default value before transition'] = function (assert) { var _this3 = this; assert.expect(1); return this.boot().then(function () { _this3.$input = (0, _emberViews.jQuery)('#filters-checkbox'); // click the checkbox twice to set filters.shared to false and back to true (0, _emberMetal.run)(_this3.$input, 'click'); (0, _emberMetal.run)(_this3.$input, 'click'); return _this3.visit('/dashboard').then(function () { assert.ok(true, 'expecting navigating to dashboard to succeed'); }); }); }; return _class; }(_internalTestHelpers.QueryParamTestCase)); }); enifed('ember/tests/routing/router_map_test', ['ember-babel', 'internal-test-helpers', 'ember-metal', 'ember-routing'], function (_emberBabel, _internalTestHelpers, _emberMetal, _emberRouting) { 'use strict'; (0, _internalTestHelpers.moduleFor)('Router.map', function (_ApplicationTestCase) { (0, _emberBabel.inherits)(_class, _ApplicationTestCase); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments)); } _class.prototype['@test Router.map returns an Ember Router class'] = function (assert) { assert.expect(1); var ret = this.router.map(function () { this.route('hello'); }); assert.ok(_emberRouting.Router.detect(ret)); }; _class.prototype['@test Router.map can be called multiple times'] = function (assert) { var _this2 = this; assert.expect(2); this.addTemplate('hello', 'Hello!'); this.addTemplate('goodbye', 'Goodbye!'); this.router.map(function () { this.route('hello'); }); this.router.map(function () { this.route('goodbye'); }); return (0, _emberMetal.run)(function () { return _this2.visit('/hello').then(function () { _this2.assertText('Hello!'); }).then(function () { return _this2.visit('/goodbye'); }).then(function () { _this2.assertText('Goodbye!'); }); }); }; return _class; }(_internalTestHelpers.ApplicationTestCase)); }); enifed('ember/tests/routing/router_service_test/basic_test', ['ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers'], function () { 'use strict'; }); enifed('ember/tests/routing/router_service_test/currenturl_lifecycle_test', ['ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers'], function () { 'use strict'; }); enifed('ember/tests/routing/router_service_test/replaceWith_test', ['ember-routing', 'internal-test-helpers', 'router'], function () { 'use strict'; }); enifed('ember/tests/routing/router_service_test/transitionTo_test', ['ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers', 'router'], function () { 'use strict'; }); enifed('ember/tests/routing/router_service_test/urlFor_test', ['ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers'], function (_emberRuntime) { 'use strict'; }); enifed('ember/tests/routing/substates_test', ['ember-runtime', 'ember-routing', 'ember-metal', 'ember-template-compiler', 'ember-application', 'ember-views', 'ember-glimmer'], function (_emberRuntime, _emberRouting, _emberMetal, _emberTemplateCompiler, _emberApplication, _emberViews, _emberGlimmer) { 'use strict'; var Router = void 0, App = void 0, templates = void 0, router = void 0, container = void 0, counter = void 0; function step(expectedValue, description) { equal(counter, expectedValue, 'Step ' + expectedValue + ': ' + description); counter++; } function bootApplication(startingURL) { for (var name in templates) { (0, _emberGlimmer.setTemplate)(name, (0, _emberTemplateCompiler.compile)(templates[name])); } if (startingURL) { _emberRouting.NoneLocation.reopen({ path: startingURL }); } startingURL = startingURL || ''; router = container.lookup('router:main'); (0, _emberMetal.run)(App, 'advanceReadiness'); } QUnit.module('Loading/Error Substates', { setup: function () { counter = 1; (0, _emberMetal.run)(function () { App = _emberApplication.Application.create({ name: 'App', rootElement: '#qunit-fixture', // fake a modules resolver Resolver: _emberApplication.Resolver.extend({ moduleBasedResolver: true }) }); App.deferReadiness(); App.Router.reopen({ location: 'none' }); Router = App.Router; container = App.__container__; templates = { application: '
    {{outlet}}
    ', index: 'INDEX', loading: 'LOADING', bro: 'BRO', sis: 'SIS' }; }); }, teardown: function () { (0, _emberMetal.run)(function () { App.destroy(); App = null; (0, _emberGlimmer.setTemplates)({}); }); _emberRouting.NoneLocation.reopen({ path: '' }); } }); QUnit.test('Slow promise from a child route of application enters nested loading state', function () { var broDeferred = _emberRuntime.RSVP.defer(); Router.map(function () { this.route('bro'); }); App.ApplicationRoute = _emberRouting.Route.extend({ setupController: function () { step(2, 'ApplicationRoute#setup'); } }); App.BroRoute = _emberRouting.Route.extend({ model: function () { step(1, 'BroRoute#model'); return broDeferred.promise; } }); bootApplication('/bro'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'LOADING', 'The Loading template is nested in application template\'s outlet'); (0, _emberMetal.run)(broDeferred, 'resolve', {}); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'BRO', 'bro template has loaded and replaced loading template'); }); QUnit.test('Slow promises waterfall on startup', function () { expect(7); var grandmaDeferred = _emberRuntime.RSVP.defer(); var sallyDeferred = _emberRuntime.RSVP.defer(); Router.map(function () { this.route('grandma', function () { this.route('mom', { resetNamespace: true }, function () { this.route('sally'); }); }); }); templates.grandma = 'GRANDMA {{outlet}}'; templates.mom = 'MOM {{outlet}}'; templates['mom/loading'] = 'MOMLOADING'; templates['mom/sally'] = 'SALLY'; App.GrandmaRoute = _emberRouting.Route.extend({ model: function () { step(1, 'GrandmaRoute#model'); return grandmaDeferred.promise; } }); App.MomRoute = _emberRouting.Route.extend({ model: function () { step(2, 'Mom#model'); return {}; } }); App.MomSallyRoute = _emberRouting.Route.extend({ model: function () { step(3, 'SallyRoute#model'); return sallyDeferred.promise; }, setupController: function () { step(4, 'SallyRoute#setupController'); } }); bootApplication('/grandma/mom/sally'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'LOADING', 'The Loading template is nested in application template\'s outlet'); (0, _emberMetal.run)(grandmaDeferred, 'resolve', {}); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA MOM MOMLOADING', 'Mom\'s child loading route is displayed due to sally\'s slow promise'); (0, _emberMetal.run)(sallyDeferred, 'resolve', {}); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA MOM SALLY', 'Sally template displayed'); }); QUnit.test('ApplicationRoute#currentPath reflects loading state path', function () { expect(4); var momDeferred = _emberRuntime.RSVP.defer(); Router.map(function () { this.route('grandma', function () { this.route('mom'); }); }); templates.grandma = 'GRANDMA {{outlet}}'; templates['grandma/loading'] = 'GRANDMALOADING'; templates['grandma/mom'] = 'MOM'; App.GrandmaMomRoute = _emberRouting.Route.extend({ model: function () { return momDeferred.promise; } }); bootApplication('/grandma/mom'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA GRANDMALOADING'); var appController = container.lookup('controller:application'); equal(appController.get('currentPath'), 'grandma.loading', 'currentPath reflects loading state'); (0, _emberMetal.run)(momDeferred, 'resolve', {}); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA MOM'); equal(appController.get('currentPath'), 'grandma.mom', 'currentPath reflects final state'); }); QUnit.test('Slow promises returned from ApplicationRoute#model don\'t enter LoadingRoute', function () { expect(2); var appDeferred = _emberRuntime.RSVP.defer(); App.ApplicationRoute = _emberRouting.Route.extend({ model: function () { return appDeferred.promise; } }); App.LoadingRoute = _emberRouting.Route.extend({ setupController: function () { ok(false, 'shouldn\'t get here'); } }); bootApplication(); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), '', 'nothing has been rendered yet'); (0, _emberMetal.run)(appDeferred, 'resolve', {}); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX'); }); QUnit.test('Don\'t enter loading route unless either route or template defined', function () { delete templates.loading; expect(2); var indexDeferred = _emberRuntime.RSVP.defer(); App.ApplicationController = _emberRuntime.Controller.extend(); App.IndexRoute = _emberRouting.Route.extend({ model: function () { return indexDeferred.promise; } }); bootApplication(); var appController = container.lookup('controller:application'); ok(appController.get('currentPath') !== 'loading', 'loading state not entered'); (0, _emberMetal.run)(indexDeferred, 'resolve', {}); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX'); }); QUnit.test('Enter loading route if only LoadingRoute defined', function () { delete templates.loading; expect(4); var indexDeferred = _emberRuntime.RSVP.defer(); App.IndexRoute = _emberRouting.Route.extend({ model: function () { step(1, 'IndexRoute#model'); return indexDeferred.promise; } }); App.LoadingRoute = _emberRouting.Route.extend({ setupController: function () { step(2, 'LoadingRoute#setupController'); } }); bootApplication(); var appController = container.lookup('controller:application'); equal(appController.get('currentPath'), 'loading', 'loading state entered'); (0, _emberMetal.run)(indexDeferred, 'resolve', {}); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX'); }); QUnit.test('Enter child loading state of pivot route', function () { expect(4); var deferred = _emberRuntime.RSVP.defer(); Router.map(function () { this.route('grandma', function () { this.route('mom', { resetNamespace: true }, function () { this.route('sally'); }); this.route('smells'); }); }); templates['grandma/loading'] = 'GMONEYLOADING'; App.ApplicationController = _emberRuntime.Controller.extend(); App.MomSallyRoute = _emberRouting.Route.extend({ setupController: function () { step(1, 'SallyRoute#setupController'); } }); App.GrandmaSmellsRoute = _emberRouting.Route.extend({ model: function () { return deferred.promise; } }); bootApplication('/grandma/mom/sally'); var appController = container.lookup('controller:application'); equal(appController.get('currentPath'), 'grandma.mom.sally', 'Initial route fully loaded'); (0, _emberMetal.run)(router, 'transitionTo', 'grandma.smells'); equal(appController.get('currentPath'), 'grandma.loading', 'in pivot route\'s child loading state'); (0, _emberMetal.run)(deferred, 'resolve', {}); equal(appController.get('currentPath'), 'grandma.smells', 'Finished transition'); }); QUnit.test('Loading actions bubble to root, but don\'t enter substates above pivot', function () { expect(6); delete templates.loading; var sallyDeferred = _emberRuntime.RSVP.defer(); var smellsDeferred = _emberRuntime.RSVP.defer(); Router.map(function () { this.route('grandma', function () { this.route('mom', { resetNamespace: true }, function () { this.route('sally'); }); this.route('smells'); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); App.ApplicationRoute = _emberRouting.Route.extend({ actions: { loading: function () { ok(true, 'loading action received on ApplicationRoute'); } } }); App.MomSallyRoute = _emberRouting.Route.extend({ model: function () { return sallyDeferred.promise; } }); App.GrandmaSmellsRoute = _emberRouting.Route.extend({ model: function () { return smellsDeferred.promise; } }); bootApplication('/grandma/mom/sally'); var appController = container.lookup('controller:application'); ok(!appController.get('currentPath'), 'Initial route fully loaded'); (0, _emberMetal.run)(sallyDeferred, 'resolve', {}); equal(appController.get('currentPath'), 'grandma.mom.sally', 'transition completed'); (0, _emberMetal.run)(router, 'transitionTo', 'grandma.smells'); equal(appController.get('currentPath'), 'grandma.mom.sally', 'still in initial state because the only loading state is above the pivot route'); (0, _emberMetal.run)(smellsDeferred, 'resolve', {}); equal(appController.get('currentPath'), 'grandma.smells', 'Finished transition'); }); QUnit.test('Default error event moves into nested route', function () { expect(6); templates['grandma'] = 'GRANDMA {{outlet}}'; templates['grandma/error'] = 'ERROR: {{model.msg}}'; Router.map(function () { this.route('grandma', function () { this.route('mom', { resetNamespace: true }, function () { this.route('sally'); }); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); App.MomSallyRoute = _emberRouting.Route.extend({ model: function () { step(1, 'MomSallyRoute#model'); return _emberRuntime.RSVP.reject({ msg: 'did it broke?' }); }, actions: { error: function () { step(2, 'MomSallyRoute#actions.error'); return true; } } }); throws(function () { bootApplication('/grandma/mom/sally'); }, function (err) { return err.msg === 'did it broke?'; }); step(3, 'App finished booting'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA ERROR: did it broke?', 'error bubbles'); var appController = container.lookup('controller:application'); equal(appController.get('currentPath'), 'grandma.error', 'Initial route fully loaded'); }); QUnit.test('Error events that aren\'t bubbled don\t throw application assertions', function () { expect(2); templates['grandma'] = 'GRANDMA {{outlet}}'; Router.map(function () { this.route('grandma', function () { this.route('mom', { resetNamespace: true }, function () { this.route('sally'); }); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); App.MomSallyRoute = _emberRouting.Route.extend({ model: function () { step(1, 'MomSallyRoute#model'); return _emberRuntime.RSVP.reject({ msg: 'did it broke?' }); }, actions: { error: function (err) { equal(err.msg, 'did it broke?'); return false; } } }); bootApplication('/grandma/mom/sally'); }); QUnit.test('Non-bubbled errors that re-throw aren\'t swallowed', function () { expect(2); templates['grandma'] = 'GRANDMA {{outlet}}'; Router.map(function () { this.route('grandma', function () { this.route('mom', { resetNamespace: true }, function () { this.route('sally'); }); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); App.MomSallyRoute = _emberRouting.Route.extend({ model: function () { step(1, 'MomSallyRoute#model'); return _emberRuntime.RSVP.reject({ msg: 'did it broke?' }); }, actions: { error: function (err) { // returns undefined which is falsey throw err; } } }); throws(function () { bootApplication('/grandma/mom/sally'); }, function (err) { return err.msg === 'did it broke?'; }); }); QUnit.test('Handled errors that re-throw aren\'t swallowed', function () { expect(4); var handledError = void 0; templates['grandma'] = 'GRANDMA {{outlet}}'; Router.map(function () { this.route('grandma', function () { this.route('mom', { resetNamespace: true }, function () { this.route('sally'); this.route('this-route-throws'); }); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); App.MomSallyRoute = _emberRouting.Route.extend({ model: function () { step(1, 'MomSallyRoute#model'); return _emberRuntime.RSVP.reject({ msg: 'did it broke?' }); }, actions: { error: function (err) { step(2, 'MomSallyRoute#error'); handledError = err; this.transitionTo('mom.this-route-throws'); // Marks error as handled return false; } } }); App.MomThisRouteThrowsRoute = _emberRouting.Route.extend({ model: function () { step(3, 'MomThisRouteThrows#model'); throw handledError; } }); throws(function () { bootApplication('/grandma/mom/sally'); }, function (err) { return err.msg === 'did it broke?'; }); }); QUnit.test('Handled errors that bubble can be handled at a higher level', function () { expect(4); var handledError = void 0; templates['grandma'] = 'GRANDMA {{outlet}}'; Router.map(function () { this.route('grandma', function () { this.route('mom', { resetNamespace: true }, function () { this.route('sally'); }); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); App.MomRoute = _emberRouting.Route.extend({ actions: { error: function (err) { step(3, 'MomRoute#error'); equal(err, handledError, 'error handled and rebubbled is handleable at higher route'); } } }); App.MomSallyRoute = _emberRouting.Route.extend({ model: function () { step(1, 'MomSallyRoute#model'); return _emberRuntime.RSVP.reject({ msg: 'did it broke?' }); }, actions: { error: function (err) { step(2, 'MomSallyRoute#error'); handledError = err; return true; } } }); bootApplication('/grandma/mom/sally'); }); QUnit.test('errors that are bubbled are thrown at a higher level if not handled', function () { expect(3); templates['grandma'] = 'GRANDMA {{outlet}}'; Router.map(function () { this.route('grandma', function () { this.route('mom', { resetNamespace: true }, function () { this.route('sally'); }); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); App.MomSallyRoute = _emberRouting.Route.extend({ model: function () { step(1, 'MomSallyRoute#model'); return _emberRuntime.RSVP.reject({ msg: 'did it broke?' }); }, actions: { error: function () { step(2, 'MomSallyRoute#error'); return true; } } }); throws(function () { bootApplication('/grandma/mom/sally'); }, function (err) { return err.msg === 'did it broke?'; }, 'Correct error was thrown'); }); QUnit.test('Handled errors that are thrown through rejection aren\'t swallowed', function () { expect(4); var handledError = void 0; templates['grandma'] = 'GRANDMA {{outlet}}'; Router.map(function () { this.route('grandma', function () { this.route('mom', { resetNamespace: true }, function () { this.route('sally'); this.route('this-route-throws'); }); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); App.MomSallyRoute = _emberRouting.Route.extend({ model: function () { step(1, 'MomSallyRoute#model'); return _emberRuntime.RSVP.reject({ msg: 'did it broke?' }); }, actions: { error: function (err) { step(2, 'MomSallyRoute#error'); handledError = err; this.transitionTo('mom.this-route-throws'); // Marks error as handled return false; } } }); App.MomThisRouteThrowsRoute = _emberRouting.Route.extend({ model: function () { step(3, 'MomThisRouteThrows#model'); return _emberRuntime.RSVP.reject(handledError); } }); throws(function () { bootApplication('/grandma/mom/sally'); }, function (err) { return err.msg === 'did it broke?'; }); }); QUnit.test('Setting a query param during a slow transition should work', function () { var deferred = _emberRuntime.RSVP.defer(); Router.map(function () { this.route('grandma', { path: '/grandma/:seg' }, function () {}); }); templates['grandma/loading'] = 'GMONEYLOADING'; App.ApplicationController = _emberRuntime.Controller.extend(); App.IndexRoute = _emberRouting.Route.extend({ beforeModel: function () { this.transitionTo('grandma', 1); } }); App.GrandmaRoute = _emberRouting.Route.extend({ queryParams: { test: { defaultValue: 1 } } }); App.GrandmaIndexRoute = _emberRouting.Route.extend({ model: function () { return deferred.promise; } }); bootApplication('/'); var appController = container.lookup('controller:application'); var grandmaController = container.lookup('controller:grandma'); equal(appController.get('currentPath'), 'grandma.loading', 'Initial route should be loading'); (0, _emberMetal.run)(function () { grandmaController.set('test', 3); }); equal(appController.get('currentPath'), 'grandma.loading', 'Route should still be loading'); equal(grandmaController.get('test'), 3, 'Controller query param value should have changed'); (0, _emberMetal.run)(deferred, 'resolve', {}); equal(appController.get('currentPath'), 'grandma.index', 'Transition should be complete'); }); QUnit.test('Slow promises returned from ApplicationRoute#model enter ApplicationLoadingRoute if present', function () { expect(2); var appDeferred = _emberRuntime.RSVP.defer(); App.ApplicationRoute = _emberRouting.Route.extend({ model: function () { return appDeferred.promise; } }); var loadingRouteEntered = false; App.ApplicationLoadingRoute = _emberRouting.Route.extend({ setupController: function () { loadingRouteEntered = true; } }); bootApplication(); ok(loadingRouteEntered, 'ApplicationLoadingRoute was entered'); (0, _emberMetal.run)(appDeferred, 'resolve', {}); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX'); }); QUnit.test('Slow promises returned from ApplicationRoute#model enter application_loading if template present', function () { expect(3); templates['application_loading'] = '
    TOPLEVEL LOADING
    '; var appDeferred = _emberRuntime.RSVP.defer(); App.ApplicationRoute = _emberRouting.Route.extend({ model: function () { return appDeferred.promise; } }); bootApplication(); equal((0, _emberViews.jQuery)('#qunit-fixture #toplevel-loading').text(), 'TOPLEVEL LOADING'); (0, _emberMetal.run)(appDeferred, 'resolve', {}); equal((0, _emberViews.jQuery)('#toplevel-loading', '#qunit-fixture').length, 0, 'top-level loading View has been entirely removed from DOM'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX'); }); QUnit.test('Default error event moves into nested route, prioritizing more specifically named error route', function () { expect(6); templates['grandma'] = 'GRANDMA {{outlet}}'; templates['grandma/error'] = 'ERROR: {{model.msg}}'; templates['mom_error'] = 'MOM ERROR: {{model.msg}}'; Router.map(function () { this.route('grandma', function () { this.route('mom', { resetNamespace: true }, function () { this.route('sally'); }); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); App.MomSallyRoute = _emberRouting.Route.extend({ model: function () { step(1, 'MomSallyRoute#model'); return _emberRuntime.RSVP.reject({ msg: 'did it broke?' }); }, actions: { error: function () { step(2, 'MomSallyRoute#actions.error'); return true; } } }); throws(function () { bootApplication('/grandma/mom/sally'); }, function (err) { return err.msg === 'did it broke?'; }); step(3, 'App finished booting'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA MOM ERROR: did it broke?', 'the more specifically-named mom error substate was entered over the other error route'); var appController = container.lookup('controller:application'); equal(appController.get('currentPath'), 'grandma.mom_error', 'Initial route fully loaded'); }); QUnit.test('Prioritized substate entry works with preserved-namespace nested routes', function () { expect(2); templates['foo/bar_loading'] = 'FOOBAR LOADING'; templates['foo/bar/index'] = 'YAY'; Router.map(function () { this.route('foo', function () { this.route('bar', { path: '/bar' }, function () {}); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); var deferred = _emberRuntime.RSVP.defer(); App.FooBarRoute = _emberRouting.Route.extend({ model: function () { return deferred.promise; } }); bootApplication('/foo/bar'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'FOOBAR LOADING', 'foo.bar_loading was entered (as opposed to something like foo/foo/bar_loading)'); (0, _emberMetal.run)(deferred, 'resolve'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'YAY'); }); QUnit.test('Prioritized substate entry works with reset-namespace nested routes', function () { expect(2); templates['bar_loading'] = 'BAR LOADING'; templates['bar/index'] = 'YAY'; Router.map(function () { this.route('foo', function () { this.route('bar', { path: '/bar', resetNamespace: true }, function () {}); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); var deferred = _emberRuntime.RSVP.defer(); App.BarRoute = _emberRouting.Route.extend({ model: function () { return deferred.promise; } }); bootApplication('/foo/bar'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'BAR LOADING', 'foo.bar_loading was entered (as opposed to something like foo/foo/bar_loading)'); (0, _emberMetal.run)(deferred, 'resolve'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'YAY'); }); QUnit.test('Prioritized loading substate entry works with preserved-namespace nested routes', function () { expect(2); templates['foo/bar_loading'] = 'FOOBAR LOADING'; templates['foo/bar'] = 'YAY'; Router.map(function () { this.route('foo', function () { this.route('bar'); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); var deferred = _emberRuntime.RSVP.defer(); App.FooBarRoute = _emberRouting.Route.extend({ model: function () { return deferred.promise; } }); bootApplication('/foo/bar'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'FOOBAR LOADING', 'foo.bar_loading was entered (as opposed to something like foo/foo/bar_loading)'); (0, _emberMetal.run)(deferred, 'resolve'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'YAY'); }); QUnit.test('Prioritized error substate entry works with preserved-namespace nested routes', function () { expect(2); templates['foo/bar_error'] = 'FOOBAR ERROR: {{model.msg}}'; templates['foo/bar'] = 'YAY'; Router.map(function () { this.route('foo', function () { this.route('bar'); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); App.FooBarRoute = _emberRouting.Route.extend({ model: function () { return _emberRuntime.RSVP.reject({ msg: 'did it broke?' }); } }); throws(function () { bootApplication('/foo/bar'); }, function (err) { return err.msg === 'did it broke?'; }); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'FOOBAR ERROR: did it broke?', 'foo.bar_error was entered (as opposed to something like foo/foo/bar_error)'); }); QUnit.test('Prioritized loading substate entry works with auto-generated index routes', function () { expect(2); templates['foo/index_loading'] = 'FOO LOADING'; templates['foo/index'] = 'YAY'; templates['foo'] = '{{outlet}}'; Router.map(function () { this.route('foo', function () { this.route('bar'); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); var deferred = _emberRuntime.RSVP.defer(); App.FooIndexRoute = _emberRouting.Route.extend({ model: function () { return deferred.promise; } }); App.FooRoute = _emberRouting.Route.extend({ model: function () { return true; } }); bootApplication('/foo'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'FOO LOADING', 'foo.index_loading was entered'); (0, _emberMetal.run)(deferred, 'resolve'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'YAY'); }); QUnit.test('Prioritized error substate entry works with auto-generated index routes', function () { expect(2); templates['foo/index_error'] = 'FOO ERROR: {{model.msg}}'; templates['foo/index'] = 'YAY'; templates['foo'] = '{{outlet}}'; Router.map(function () { this.route('foo', function () { this.route('bar'); }); }); App.ApplicationController = _emberRuntime.Controller.extend(); App.FooIndexRoute = _emberRouting.Route.extend({ model: function () { return _emberRuntime.RSVP.reject({ msg: 'did it broke?' }); } }); App.FooRoute = _emberRouting.Route.extend({ model: function () { return true; } }); throws(function () { return bootApplication('/foo'); }, function (err) { return err.msg === 'did it broke?'; }); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'FOO ERROR: did it broke?', 'foo.index_error was entered'); }); QUnit.test('Rejected promises returned from ApplicationRoute transition into top-level application_error', function () { expect(3); templates['application_error'] = '

    TOPLEVEL ERROR: {{model.msg}}

    '; var reject = true; App.ApplicationRoute = _emberRouting.Route.extend({ model: function () { if (reject) { return _emberRuntime.RSVP.reject({ msg: 'BAD NEWS BEARS' }); } else { return {}; } } }); throws(function () { return bootApplication(); }, function (err) { return err.msg === 'BAD NEWS BEARS'; }); equal((0, _emberViews.jQuery)('#toplevel-error', '#qunit-fixture').text(), 'TOPLEVEL ERROR: BAD NEWS BEARS'); reject = false; (0, _emberMetal.run)(router, 'transitionTo', 'index'); equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX'); }); }); enifed('ember/tests/routing/toplevel_dom_test', ['ember-babel', 'internal-test-helpers'], function (_emberBabel, _internalTestHelpers) { 'use strict'; (0, _internalTestHelpers.moduleFor)('Top Level DOM Structure', function (_ApplicationTestCase) { (0, _emberBabel.inherits)(_class, _ApplicationTestCase); function _class() { return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments)); } _class.prototype['@test Topmost template always get an element'] = function (assert) { var _this2 = this; this.addTemplate('application', 'hello world'); return this.visit('/').then(function () { assert.equal(_this2.$('> .ember-view').text(), 'hello world'); }); }; return _class; }(_internalTestHelpers.ApplicationTestCase)); }); enifed('ember/tests/view_instrumentation_test', ['ember-metal', 'ember-views', 'ember-application', 'ember-template-compiler', 'ember-glimmer'], function (_emberMetal, _emberViews, _emberApplication, _emberTemplateCompiler, _emberGlimmer) { 'use strict'; var App = void 0, $fixture = void 0; function setupExample() { // setup templates (0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}')); (0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('

    Index

    ')); (0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('

    Posts

    ')); App.Router.map(function () { this.route('posts'); }); } function handleURL(path) { var router = App.__container__.lookup('router:main'); return (0, _emberMetal.run)(router, 'handleURL', path); } QUnit.module('View Instrumentation', { setup: function () { (0, _emberMetal.run)(function () { App = _emberApplication.Application.create({ rootElement: '#qunit-fixture' }); App.deferReadiness(); App.Router.reopen({ location: 'none' }); }); $fixture = (0, _emberViews.jQuery)('#qunit-fixture'); setupExample(); }, teardown: function () { (0, _emberMetal.instrumentationReset)(); (0, _emberMetal.run)(App, 'destroy'); App = null; (0, _emberGlimmer.setTemplates)({}); } }); QUnit.test('Nodes without view instances are instrumented', function (assert) { var called = false; (0, _emberMetal.instrumentationSubscribe)('render', { before: function () { called = true; }, after: function () {} }); (0, _emberMetal.run)(App, 'advanceReadiness'); assert.equal($fixture.text(), 'Index', 'It rendered the right template'); assert.ok(called, 'Instrumentation called on first render'); called = false; handleURL('/posts'); assert.equal($fixture.text(), 'Posts', 'It rendered the right template'); assert.ok(called, 'instrumentation called on transition to non-view backed route'); }); }); enifed('internal-test-helpers/apply-mixins', ['exports', 'ember-utils'], function (exports, _emberUtils) { 'use strict'; exports.default = function (TestClass) { var _len, mixins, _key; for (_len = arguments.length, mixins = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { mixins[_key - 1] = arguments[_key]; } mixins.forEach(function (mixinOrGenerator) { var mixin = void 0, generator; if (isGenerator(mixinOrGenerator)) { generator = mixinOrGenerator; mixin = {}; generator.cases.forEach(function (value, idx) { (0, _emberUtils.assign)(mixin, generator.generate(value, idx)); }); } else { mixin = mixinOrGenerator; } (0, _emberUtils.assign)(TestClass.prototype, mixin); }); return TestClass; }; function isGenerator(mixin) { return Array.isArray(mixin.cases) && typeof mixin.generate === 'function'; } }); enifed('internal-test-helpers/build-owner', ['exports', 'container', 'ember-routing', 'ember-application', 'ember-runtime'], function (exports, _container, _emberRouting, _emberApplication, _emberRuntime) { 'use strict'; exports.default = function () { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var ownerOptions = options.ownerOptions || {}; var resolver = options.resolver; var bootOptions = options.bootOptions || {}; var Owner = _emberRuntime.Object.extend(_emberRuntime.RegistryProxyMixin, _emberRuntime.ContainerProxyMixin); var namespace = _emberRuntime.Object.create({ Resolver: { create: function () { return resolver; } } }); var fallbackRegistry = _emberApplication.Application.buildRegistry(namespace); fallbackRegistry.register('router:main', _emberRouting.Router); var registry = new _container.Registry({ fallback: fallbackRegistry }); _emberApplication.ApplicationInstance.setupRegistry(registry, bootOptions); var owner = Owner.create({ __registry__: registry, __container__: null }, ownerOptions); var container = registry.container({ owner: owner }); owner.__container__ = container; return owner; }; }); enifed('internal-test-helpers/confirm-export', ['exports', 'require'], function (exports, _require2) { 'use strict'; exports.default = function (Ember, assert, path, moduleId, exportName) { var desc = getDescriptor(Ember, path); assert.ok(desc, 'the property exists on the global'); var mod = (0, _require2.default)(moduleId); if (typeof exportName === 'string') { assert.equal(desc.value, mod[exportName], 'Ember.' + path + ' is exported correctly'); assert.notEqual(mod[exportName], undefined, 'Ember.' + path + ' is not `undefined`'); } else { assert.equal(desc.get, mod[exportName.get], 'Ember.' + path + ' getter is exported correctly'); assert.notEqual(desc.get, undefined, 'Ember.' + path + ' getter is not undefined'); if (exportName.set) { assert.equal(desc.set, mod[exportName.set], 'Ember.' + path + ' setter is exported correctly'); assert.notEqual(desc.set, undefined, 'Ember.' + path + ' setter is not undefined'); } } }; function getDescriptor(obj, path) { var parts = path.split('.'), i, part; var value = obj; for (i = 0; i < parts.length - 1; i++) { part = parts[i]; value = value[part]; if (!value) { return undefined; } } var last = parts[parts.length - 1]; return Object.getOwnPropertyDescriptor(value, last); } }); enifed('internal-test-helpers/equal-inner-html', ['exports'], function (exports) { 'use strict'; exports.default = function (fragment, html) { var actualHTML = normalizeInnerHTML(fragment.innerHTML); QUnit.push(actualHTML === html, actualHTML, html); }; // detect side-effects of cloning svg elements in IE9-11 var ieSVGInnerHTML = function () { if (!document.createElementNS) { return false; } var div = document.createElement('div'); var node = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); div.appendChild(node); var clone = div.cloneNode(true); return clone.innerHTML === ''; }(); function normalizeInnerHTML(actualHTML) { if (ieSVGInnerHTML) { // Replace `` with ``, etc. // drop namespace attribute // replace self-closing elements actualHTML = actualHTML.replace(/ xmlns="[^"]+"/, '').replace(/<([^ >]+) [^\/>]*\/>/gi, function (tag, tagName) { return tag.slice(0, tag.length - 3) + '>'; }); } return actualHTML; } }); enifed('internal-test-helpers/equal-tokens', ['exports', 'simple-html-tokenizer'], function (exports, _simpleHtmlTokenizer) { 'use strict'; exports.default = function (actualContainer, expectedHTML) { var message = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var actual = generateTokens(actualContainer); var expected = generateTokens(expectedHTML); normalizeTokens(actual.tokens); normalizeTokens(expected.tokens); var equiv = QUnit.equiv(actual.tokens, expected.tokens); if (equiv && expected.html !== actual.html) { deepEqual(actual.tokens, expected.tokens, message); } else { QUnit.push(QUnit.equiv(actual.tokens, expected.tokens), actual.html, expected.html, message); } }; function generateTokens(containerOrHTML) { if (typeof containerOrHTML === 'string') { return { tokens: (0, _simpleHtmlTokenizer.tokenize)(containerOrHTML), html: containerOrHTML }; } else { return { tokens: (0, _simpleHtmlTokenizer.tokenize)(containerOrHTML.innerHTML), html: containerOrHTML.innerHTML }; } } function normalizeTokens(tokens) { tokens.forEach(function (token) { if (token.type === 'StartTag') { token.attributes = token.attributes.sort(function (a, b) { if (a[0] > b[0]) { return 1; } if (a[0] < b[0]) { return -1; } return 0; }); } }); } }); enifed('internal-test-helpers/factory', ['exports'], function (exports) { 'use strict'; exports.default = function () { /*jshint validthis: true */ function Klass(options) { setProperties(this, options); this._guid = guids++; this.isDestroyed = false; } Klass.prototype.constructor = Klass; Klass.prototype.destroy = function () { this.isDestroyed = true; }; Klass.prototype.toString = function () { return ''; }; Klass.create = create; Klass.extend = extend; Klass.reopen = extend; Klass.reopenClass = reopenClass; return Klass; function create(options) { return new this.prototype.constructor(options); } function reopenClass(options) { setProperties(this, options); } function extend(options) { function Child(options) { Klass.call(this, options); } var Parent = this; Child.prototype = new Parent(); Child.prototype.constructor = Child; setProperties(Child, Klass); setProperties(Child.prototype, options); Child.create = create; Child.extend = extend; Child.reopen = extend; Child.reopenClass = reopenClass; return Child; } }; function setProperties(object, properties) { for (var key in properties) { if (properties.hasOwnProperty(key)) { object[key] = properties[key]; } } } var guids = 0; }); enifed('internal-test-helpers/index', ['exports', 'internal-test-helpers/factory', 'internal-test-helpers/build-owner', 'internal-test-helpers/confirm-export', 'internal-test-helpers/equal-inner-html', 'internal-test-helpers/equal-tokens', 'internal-test-helpers/module-for', 'internal-test-helpers/strip', 'internal-test-helpers/apply-mixins', 'internal-test-helpers/matchers', 'internal-test-helpers/run', 'internal-test-helpers/test-groups', 'internal-test-helpers/test-cases/abstract', 'internal-test-helpers/test-cases/abstract-application', 'internal-test-helpers/test-cases/application', 'internal-test-helpers/test-cases/query-param', 'internal-test-helpers/test-cases/abstract-rendering', 'internal-test-helpers/test-cases/rendering', 'internal-test-helpers/test-cases/router', 'internal-test-helpers/test-cases/autoboot-application', 'internal-test-helpers/test-resolver'], function (exports, _factory, _buildOwner, _confirmExport, _equalInnerHtml, _equalTokens, _moduleFor, _strip, _applyMixins, _matchers, _run, _testGroups, _abstract, _abstractApplication, _application, _queryParam, _abstractRendering, _rendering, _router, _autobootApplication, _testResolver) { 'use strict'; Object.defineProperty(exports, 'factory', { enumerable: true, get: function () { return _factory.default; } }); Object.defineProperty(exports, 'buildOwner', { enumerable: true, get: function () { return _buildOwner.default; } }); Object.defineProperty(exports, 'confirmExport', { enumerable: true, get: function () { return _confirmExport.default; } }); Object.defineProperty(exports, 'equalInnerHTML', { enumerable: true, get: function () { return _equalInnerHtml.default; } }); Object.defineProperty(exports, 'equalTokens', { enumerable: true, get: function () { return _equalTokens.default; } }); Object.defineProperty(exports, 'moduleFor', { enumerable: true, get: function () { return _moduleFor.default; } }); Object.defineProperty(exports, 'strip', { enumerable: true, get: function () { return _strip.default; } }); Object.defineProperty(exports, 'applyMixins', { enumerable: true, get: function () { return _applyMixins.default; } }); Object.defineProperty(exports, 'equalsElement', { enumerable: true, get: function () { return _matchers.equalsElement; } }); Object.defineProperty(exports, 'classes', { enumerable: true, get: function () { return _matchers.classes; } }); Object.defineProperty(exports, 'styles', { enumerable: true, get: function () { return _matchers.styles; } }); Object.defineProperty(exports, 'regex', { enumerable: true, get: function () { return _matchers.regex; } }); Object.defineProperty(exports, 'runAppend', { enumerable: true, get: function () { return _run.runAppend; } }); Object.defineProperty(exports, 'runDestroy', { enumerable: true, get: function () { return _run.runDestroy; } }); Object.defineProperty(exports, 'testBoth', { enumerable: true, get: function () { return _testGroups.testBoth; } }); Object.defineProperty(exports, 'testWithDefault', { enumerable: true, get: function () { return _testGroups.testWithDefault; } }); Object.defineProperty(exports, 'AbstractTestCase', { enumerable: true, get: function () { return _abstract.default; } }); Object.defineProperty(exports, 'AbstractApplicationTestCase', { enumerable: true, get: function () { return _abstractApplication.default; } }); Object.defineProperty(exports, 'ApplicationTestCase', { enumerable: true, get: function () { return _application.default; } }); Object.defineProperty(exports, 'QueryParamTestCase', { enumerable: true, get: function () { return _queryParam.default; } }); Object.defineProperty(exports, 'AbstractRenderingTestCase', { enumerable: true, get: function () { return _abstractRendering.default; } }); Object.defineProperty(exports, 'RenderingTestCase', { enumerable: true, get: function () { return _rendering.default; } }); Object.defineProperty(exports, 'RouterTestCase', { enumerable: true, get: function () { return _router.default; } }); Object.defineProperty(exports, 'AutobootApplicationTestCase', { enumerable: true, get: function () { return _autobootApplication.default; } }); Object.defineProperty(exports, 'TestResolver', { enumerable: true, get: function () { return _testResolver.default; } }); Object.defineProperty(exports, 'ModuleBasedTestResolver', { enumerable: true, get: function () { return _testResolver.ModuleBasedResolver; } }); }); enifed('internal-test-helpers/matchers', ['exports'], function (exports) { 'use strict'; exports.regex = function (r) { var _ref2; return _ref2 = {}, _ref2[MATCHER_BRAND] = true, _ref2.match = function (v) { return r.test(v); }, _ref2.expected = function () { return r.toString(); }, _ref2.message = function () { return 'should match ' + this.expected(); }, _ref2; }; exports.classes = function (expected) { var _ref3; return _ref3 = {}, _ref3[MATCHER_BRAND] = true, _ref3.match = function (actual) { actual = actual.trim(); return actual && expected.split(/\s+/).sort().join(' ') === actual.trim().split(/\s+/).sort().join(' '); }, _ref3.expected = function () { return expected; }, _ref3.message = function () { return 'should match ' + this.expected(); }, _ref3; }; exports.styles = function (expected) { var _ref4; return _ref4 = {}, _ref4[MATCHER_BRAND] = true, _ref4.match = function (actual) { // coerce `null` or `undefined` to an empty string // needed for matching empty styles on IE9 - IE11 actual = actual || ''; actual = actual.trim(); return expected.split(';').map(function (s) { return s.trim(); }).filter(function (s) { return s; }).sort().join('; ') === actual.split(';').map(function (s) { return s.trim(); }).filter(function (s) { return s; }).sort().join('; '); }, _ref4.expected = function () { return expected; }, _ref4.message = function () { return 'should match ' + this.expected(); }, _ref4; }; exports.equalsElement = function (element, tagName, attributes, content) { QUnit.push(element.tagName === tagName.toUpperCase(), element.tagName.toLowerCase(), tagName, 'expect tagName to be ' + tagName); var expectedAttrs = {}, expected, matcher, i, l; var expectedCount = 0; for (var name in attributes) { expected = attributes[name]; if (expected !== null) { expectedCount++; } matcher = isMatcher(expected) ? expected : equalsAttr(expected); expectedAttrs[name] = matcher; QUnit.push(expectedAttrs[name].match(element.getAttribute(name)), element.getAttribute(name), matcher.expected(), 'Element\'s ' + name + ' attribute ' + matcher.message()); } var actualAttributes = {}; for (i = 0, l = element.attributes.length; i < l; i++) { actualAttributes[element.attributes[i].name] = element.attributes[i].value; } if (!(element instanceof HTMLElement)) { QUnit.push(element instanceof HTMLElement, null, null, 'Element must be an HTML Element, not an SVG Element'); } else { QUnit.push(element.attributes.length === expectedCount || !attributes, element.attributes.length, expectedCount, 'Expected ' + expectedCount + ' attributes; got ' + element.outerHTML); if (content !== null) { QUnit.push(element.innerHTML === content, element.innerHTML, content, 'The element had \'' + content + '\' as its content'); } } }; var HTMLElement = window.HTMLElement; var MATCHER_BRAND = '3d4ef194-13be-4ccf-8dc7-862eea02c93e'; function isMatcher(obj) { return typeof obj === 'object' && obj !== null && MATCHER_BRAND in obj; } function equalsAttr(expected) { var _ref; return _ref = {}, _ref[MATCHER_BRAND] = true, _ref.match = function (actual) { return expected === actual; }, _ref.expected = function () { return expected; }, _ref.message = function () { return 'should equal ' + this.expected(); }, _ref; } }); enifed('internal-test-helpers/module-for', ['exports', 'internal-test-helpers/apply-mixins'], function (exports, _applyMixins) { 'use strict'; exports.default = function (description, TestClass) { var context = void 0, _len, mixins, _key; QUnit.module(description, { setup: function () { context = new TestClass(); }, teardown: function () { context.teardown(); } }); for (_len = arguments.length, mixins = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { mixins[_key - 2] = arguments[_key]; } (0, _applyMixins.default)(TestClass, mixins); var proto = TestClass.prototype; while (proto !== Object.prototype) { Object.keys(proto).forEach(generateTest); proto = Object.getPrototypeOf(proto); } function generateTest(name) { if (name.indexOf('@test ') === 0) { QUnit.test(name.slice(5), function (assert) { return context[name](assert); }); } else if (name.indexOf('@skip ') === 0) { QUnit.skip(name.slice(5), function (assert) { return context[name](assert); }); } } }; }); enifed('internal-test-helpers/run', ['exports', 'ember-metal'], function (exports, _emberMetal) { 'use strict'; exports.runAppend = function (view) { (0, _emberMetal.run)(view, 'appendTo', '#qunit-fixture'); }; exports.runDestroy = function (toDestroy) { if (toDestroy) { (0, _emberMetal.run)(toDestroy, 'destroy'); } }; }); enifed('internal-test-helpers/strip', ['exports'], function (exports) { 'use strict'; exports.default = function (_ref) { for (_len = arguments.length, values = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { values[_key - 1] = arguments[_key]; } var strings = _ref.slice(0), _len, values, _key; var str = strings.map(function (string, index) { var interpolated = values[index]; return string + (interpolated !== undefined ? interpolated : ''); }).join(''); return str.split('\n').map(function (s) { return s.trim(); }).join(''); }; }); enifed('internal-test-helpers/test-cases/abstract-application', ['exports', 'ember-babel', 'ember-metal', 'ember-views', 'ember-application', 'ember-routing', 'ember-template-compiler', 'internal-test-helpers/test-cases/abstract', 'internal-test-helpers/test-resolver', 'internal-test-helpers/run'], function (exports, _emberBabel, _emberMetal, _emberViews, _emberApplication, _emberRouting, _emberTemplateCompiler, _abstract, _testResolver, _run) { 'use strict'; var AbstractApplicationTestCase = function (_AbstractTestCase) { (0, _emberBabel.inherits)(AbstractApplicationTestCase, _AbstractTestCase); function AbstractApplicationTestCase() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AbstractTestCase.call(this)); _this.element = (0, _emberViews.jQuery)('#qunit-fixture')[0]; var applicationOptions = _this.applicationOptions; _this.application = (0, _emberMetal.run)(_emberApplication.Application, 'create', applicationOptions); _this.resolver = applicationOptions.Resolver.lastInstance; if (_this.resolver) { _this.resolver.add('router:main', _emberRouting.Router.extend(_this.routerOptions)); } _this.applicationInstance = null; return _this; } AbstractApplicationTestCase.prototype.teardown = function () { (0, _run.runDestroy)(this.applicationInstance); (0, _run.runDestroy)(this.application); }; AbstractApplicationTestCase.prototype.visit = function (url, options) { var _this2 = this; var applicationInstance = this.applicationInstance; if (applicationInstance) { return (0, _emberMetal.run)(applicationInstance, 'visit', url, options); } else { return (0, _emberMetal.run)(this.application, 'visit', url, options).then(function (instance) { _this2.applicationInstance = instance; }); } }; AbstractApplicationTestCase.prototype.transitionTo = function () { return _emberMetal.run.apply(undefined, [this.appRouter, 'transitionTo'].concat(Array.prototype.slice.call(arguments))); }; AbstractApplicationTestCase.prototype.compile = function () { return _emberTemplateCompiler.compile.apply(undefined, arguments); }; AbstractApplicationTestCase.prototype.add = function (specifier, factory) { this.resolver.add(specifier, factory); }; AbstractApplicationTestCase.prototype.addTemplate = function (templateName, templateString) { this.resolver.add('template:' + templateName, this.compile(templateString, { moduleName: templateName })); }; AbstractApplicationTestCase.prototype.addComponent = function (name, _ref) { var _ref$ComponentClass = _ref.ComponentClass, ComponentClass = _ref$ComponentClass === undefined ? null : _ref$ComponentClass, _ref$template = _ref.template, template = _ref$template === undefined ? null : _ref$template; if (ComponentClass) { this.resolver.add('component:' + name, ComponentClass); } if (typeof template === 'string') { this.resolver.add('template:components/' + name, this.compile(template, { moduleName: 'components/' + name })); } }; (0, _emberBabel.createClass)(AbstractApplicationTestCase, [{ key: 'applicationOptions', get: function () { return { rootElement: '#qunit-fixture', autoboot: false, Resolver: _testResolver.ModuleBasedResolver }; } }, { key: 'routerOptions', get: function () { return { location: 'none' }; } }, { key: 'router', get: function () { return this.application.resolveRegistration('router:main'); } }, { key: 'appRouter', get: function () { return this.applicationInstance.lookup('router:main'); } }]); return AbstractApplicationTestCase; }(_abstract.default); exports.default = AbstractApplicationTestCase; }); enifed('internal-test-helpers/test-cases/abstract-rendering', ['exports', 'ember-babel', 'ember-utils', 'ember-template-compiler', 'ember-views', 'ember-glimmer', 'internal-test-helpers/test-cases/abstract', 'internal-test-helpers/build-owner', 'internal-test-helpers/run'], function (exports, _emberBabel, _emberUtils, _emberTemplateCompiler, _emberViews, _emberGlimmer, _abstract, _buildOwner, _run) { 'use strict'; var TextNode = window.Text; var AbstractRenderingTestCase = function (_AbstractTestCase) { (0, _emberBabel.inherits)(AbstractRenderingTestCase, _AbstractTestCase); function AbstractRenderingTestCase() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AbstractTestCase.call(this)); var owner = _this.owner = (0, _buildOwner.default)({ ownerOptions: _this.getOwnerOptions(), bootOptions: _this.getBootOptions(), resolver: _this.getResolver() }); _this.renderer = _this.owner.lookup('renderer:-dom'); _this.element = (0, _emberViews.jQuery)('#qunit-fixture')[0]; _this.component = null; owner.register('event_dispatcher:main', _emberViews.EventDispatcher); owner.inject('event_dispatcher:main', '_viewRegistry', '-view-registry:main'); owner.lookup('event_dispatcher:main').setup(_this.getCustomDispatcherEvents(), _this.element); return _this; } AbstractRenderingTestCase.prototype.compile = function () { return _emberTemplateCompiler.compile.apply(undefined, arguments); }; AbstractRenderingTestCase.prototype.getCustomDispatcherEvents = function () { return {}; }; AbstractRenderingTestCase.prototype.getOwnerOptions = function () {}; AbstractRenderingTestCase.prototype.getBootOptions = function () {}; AbstractRenderingTestCase.prototype.getResolver = function () {}; AbstractRenderingTestCase.prototype.teardown = function () { if (this.component) { (0, _run.runDestroy)(this.component); } if (this.owner) { (0, _run.runDestroy)(this.owner); } }; AbstractRenderingTestCase.prototype.render = function (templateStr) { var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var owner = this.owner; owner.register('template:-top-level', this.compile(templateStr, { moduleName: '-top-level' })); var attrs = (0, _emberUtils.assign)({}, context, { tagName: '', layoutName: '-top-level' }); owner.register('component:-top-level', _emberGlimmer.Component.extend(attrs)); this.component = owner.lookup('component:-top-level'); (0, _run.runAppend)(this.component); }; AbstractRenderingTestCase.prototype.rerender = function () { this.component.rerender(); }; AbstractRenderingTestCase.prototype.registerHelper = function (name, funcOrClassBody) { var type = typeof funcOrClassBody; if (type === 'function') { this.owner.register('helper:' + name, (0, _emberGlimmer.helper)(funcOrClassBody)); } else if (type === 'object' && type !== null) { this.owner.register('helper:' + name, _emberGlimmer.Helper.extend(funcOrClassBody)); } else { throw new Error('Cannot register ' + funcOrClassBody + ' as a helper'); } }; AbstractRenderingTestCase.prototype.registerPartial = function (name, template) { var owner = this.env.owner || this.owner, moduleName; if (typeof template === 'string') { moduleName = 'template:' + name; owner.register(moduleName, this.compile(template, { moduleName: moduleName })); } }; AbstractRenderingTestCase.prototype.registerComponent = function (name, _ref) { var _ref$ComponentClass = _ref.ComponentClass, ComponentClass = _ref$ComponentClass === undefined ? null : _ref$ComponentClass, _ref$template = _ref.template, template = _ref$template === undefined ? null : _ref$template; var owner = this.owner; if (ComponentClass) { owner.register('component:' + name, ComponentClass); } if (typeof template === 'string') { owner.register('template:components/' + name, this.compile(template, { moduleName: 'components/' + name })); } }; AbstractRenderingTestCase.prototype.registerTemplate = function (name, template) { var owner = this.owner; if (typeof template === 'string') { owner.register('template:' + name, this.compile(template, { moduleName: name })); } else { throw new Error('Registered template "' + name + '" must be a string'); } }; AbstractRenderingTestCase.prototype.registerService = function (name, klass) { this.owner.register('service:' + name, klass); }; AbstractRenderingTestCase.prototype.assertTextNode = function (node, text) { if (!(node instanceof TextNode)) { throw new Error('Expecting a text node, but got ' + node); } this.assert.strictEqual(node.textContent, text, 'node.textContent'); }; (0, _emberBabel.createClass)(AbstractRenderingTestCase, [{ key: 'context', get: function () { return this.component; } }]); return AbstractRenderingTestCase; }(_abstract.default); exports.default = AbstractRenderingTestCase; }); enifed('internal-test-helpers/test-cases/abstract', ['exports', 'ember-babel', 'ember-utils', 'ember-metal', 'ember-views', 'internal-test-helpers/equal-inner-html', 'internal-test-helpers/equal-tokens', 'internal-test-helpers/matchers'], function (exports, _emberBabel, _emberUtils, _emberMetal, _emberViews, _equalInnerHtml, _equalTokens, _matchers) { 'use strict'; var TextNode = window.Text; var HTMLElement = window.HTMLElement; var Comment = window.Comment; function isMarker(node) { if (node instanceof Comment && node.textContent === '') { return true; } if (node instanceof TextNode && node.textContent === '') { return true; } return false; } var AbstractTestCase = function () { function AbstractTestCase() { this.element = null; this.snapshot = null; this.assert = QUnit.config.current.assert; } AbstractTestCase.prototype.teardown = function () {}; AbstractTestCase.prototype.runTask = function (callback) { (0, _emberMetal.run)(callback); }; AbstractTestCase.prototype.runTaskNext = function (callback) { _emberMetal.run.next(callback); }; AbstractTestCase.prototype.nthChild = function (n) { var i = 0; var node = this.element.firstChild; while (node) { if (!isMarker(node)) { i++; } if (i > n) { break; } else { node = node.nextSibling; } } return node; }; AbstractTestCase.prototype.$ = function (sel) { return sel ? (0, _emberViews.jQuery)(sel, this.element) : (0, _emberViews.jQuery)(this.element); }; AbstractTestCase.prototype.textValue = function () { return this.$().text(); }; AbstractTestCase.prototype.takeSnapshot = function () { var snapshot = this.snapshot = []; var node = this.element.firstChild; while (node) { if (!isMarker(node)) { snapshot.push(node); } node = node.nextSibling; } return snapshot; }; AbstractTestCase.prototype.assertText = function (text) { this.assert.strictEqual(this.textValue(), text, '#qunit-fixture content should be: `' + text + '`'); }; AbstractTestCase.prototype.assertInnerHTML = function (html) { (0, _equalInnerHtml.default)(this.element, html); }; AbstractTestCase.prototype.assertHTML = function (html) { (0, _equalTokens.default)(this.element, html, '#qunit-fixture content should be: `' + html + '`'); }; AbstractTestCase.prototype.assertElement = function (node, _ref) { var _ref$ElementType = _ref.ElementType, ElementType = _ref$ElementType === undefined ? HTMLElement : _ref$ElementType, tagName = _ref.tagName, _ref$attrs = _ref.attrs, attrs = _ref$attrs === undefined ? null : _ref$attrs, _ref$content = _ref.content, content = _ref$content === undefined ? null : _ref$content; if (!(node instanceof ElementType)) { throw new Error('Expecting a ' + ElementType.name + ', but got ' + node); } (0, _matchers.equalsElement)(node, tagName, attrs, content); }; AbstractTestCase.prototype.assertComponentElement = function (node, _ref2) { var _ref2$ElementType = _ref2.ElementType, ElementType = _ref2$ElementType === undefined ? HTMLElement : _ref2$ElementType, _ref2$tagName = _ref2.tagName, tagName = _ref2$tagName === undefined ? 'div' : _ref2$tagName, _ref2$attrs = _ref2.attrs, attrs = _ref2$attrs === undefined ? null : _ref2$attrs, _ref2$content = _ref2.content, content = _ref2$content === undefined ? null : _ref2$content; attrs = (0, _emberUtils.assign)({}, { id: (0, _matchers.regex)(/^ember\d*$/), class: (0, _matchers.classes)('ember-view') }, attrs || {}); this.assertElement(node, { ElementType: ElementType, tagName: tagName, attrs: attrs, content: content }); }; AbstractTestCase.prototype.assertSameNode = function (actual, expected) { this.assert.strictEqual(actual, expected, 'DOM node stability'); }; AbstractTestCase.prototype.assertInvariants = function (oldSnapshot, newSnapshot) { var i; oldSnapshot = oldSnapshot || this.snapshot; newSnapshot = newSnapshot || this.takeSnapshot(); this.assert.strictEqual(newSnapshot.length, oldSnapshot.length, 'Same number of nodes'); for (i = 0; i < oldSnapshot.length; i++) { this.assertSameNode(newSnapshot[i], oldSnapshot[i]); } }; AbstractTestCase.prototype.assertPartialInvariants = function (start, end) { this.assertInvariants(this.snapshot, this.takeSnapshot().slice(start, end)); }; AbstractTestCase.prototype.assertStableRerender = function () { var _this = this; this.takeSnapshot(); this.runTask(function () { return _this.rerender(); }); this.assertInvariants(); }; (0, _emberBabel.createClass)(AbstractTestCase, [{ key: 'firstChild', get: function () { return this.nthChild(0); } }, { key: 'nodesCount', get: function () { var count = 0; var node = this.element.firstChild; while (node) { if (!isMarker(node)) { count++; } node = node.nextSibling; } return count; } }]); return AbstractTestCase; }(); exports.default = AbstractTestCase; }); enifed('internal-test-helpers/test-cases/application', ['exports', 'ember-babel', 'internal-test-helpers/test-cases/abstract-application'], function (exports, _emberBabel, _abstractApplication) { 'use strict'; var ApplicationTestCase = function (_AbstractApplicationT) { (0, _emberBabel.inherits)(ApplicationTestCase, _AbstractApplicationT); function ApplicationTestCase() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractApplicationT.apply(this, arguments)); } return ApplicationTestCase; }(_abstractApplication.default); exports.default = ApplicationTestCase; }); enifed('internal-test-helpers/test-cases/autoboot-application', ['exports', 'ember-babel', 'internal-test-helpers/test-cases/abstract', 'internal-test-helpers/test-resolver', 'ember-application', 'ember-utils', 'internal-test-helpers/run'], function (exports, _emberBabel, _abstract, _testResolver, _emberApplication, _emberUtils, _run) { 'use strict'; var AutobootApplicationTestCase = function (_AbstractTestCase) { (0, _emberBabel.inherits)(AutobootApplicationTestCase, _AbstractTestCase); function AutobootApplicationTestCase() { return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractTestCase.apply(this, arguments)); } AutobootApplicationTestCase.prototype.teardown = function () { (0, _run.runDestroy)(this.application); _AbstractTestCase.prototype.teardown.call(this); }; AutobootApplicationTestCase.prototype.createApplication = function (options) { var MyApplication = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _emberApplication.Application; var myOptions = (0, _emberUtils.assign)({ rootElement: '#qunit-fixture', Resolver: _testResolver.default }, options); var application = this.application = MyApplication.create(myOptions); this.resolver = myOptions.Resolver.lastInstance; return application; }; AutobootApplicationTestCase.prototype.add = function (specifier, factory) { this.resolver.add(specifier, factory); }; AutobootApplicationTestCase.prototype.addTemplate = function (templateName, templateString) { this.resolver.addTemplate(templateName, templateString); }; return AutobootApplicationTestCase; }(_abstract.default); exports.default = AutobootApplicationTestCase; }); enifed('internal-test-helpers/test-cases/query-param', ['exports', 'ember-babel', 'ember-runtime', 'ember-routing', 'ember-metal', 'internal-test-helpers/test-cases/application'], function (exports, _emberBabel, _emberRuntime, _emberRouting, _emberMetal, _application) { 'use strict'; var QueryParamTestCase = function (_ApplicationTestCase) { (0, _emberBabel.inherits)(QueryParamTestCase, _ApplicationTestCase); function QueryParamTestCase() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this)); var testCase = _this; testCase.expectedPushURL = null; testCase.expectedReplaceURL = null; _this.add('location:test', _emberRouting.NoneLocation.extend({ setURL: function (path) { if (testCase.expectedReplaceURL) { testCase.assert.ok(false, 'pushState occurred but a replaceState was expected'); } if (testCase.expectedPushURL) { testCase.assert.equal(path, testCase.expectedPushURL, 'an expected pushState occurred'); testCase.expectedPushURL = null; } this.set('path', path); }, replaceURL: function (path) { if (testCase.expectedPushURL) { testCase.assert.ok(false, 'replaceState occurred but a pushState was expected'); } if (testCase.expectedReplaceURL) { testCase.assert.equal(path, testCase.expectedReplaceURL, 'an expected replaceState occurred'); testCase.expectedReplaceURL = null; } this.set('path', path); } })); return _this; } QueryParamTestCase.prototype.visitAndAssert = function (path) { var _this2 = this; return this.visit.apply(this, arguments).then(function () { _this2.assertCurrentPath(path); }); }; QueryParamTestCase.prototype.getController = function (name) { return this.applicationInstance.lookup('controller:' + name); }; QueryParamTestCase.prototype.getRoute = function (name) { return this.applicationInstance.lookup('route:' + name); }; QueryParamTestCase.prototype.setAndFlush = function (obj, prop, value) { return (0, _emberMetal.run)(obj, 'set', prop, value); }; QueryParamTestCase.prototype.assertCurrentPath = function (path) { var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'current path equals \'' + path + '\''; this.assert.equal(this.appRouter.get('location.path'), path, message); }; QueryParamTestCase.prototype.setSingleQPController = function (routeName) { var param = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'foo'; var _Controller$extend; var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'bar'; var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; this.add('controller:' + routeName, _emberRuntime.Controller.extend((_Controller$extend = { queryParams: [param] }, _Controller$extend[param] = defaultValue, _Controller$extend), options)); }; QueryParamTestCase.prototype.setMappedQPController = function (routeName) { var prop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'page'; var urlKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'parentPage'; var _queryParams, _Controller$extend2; var defaultValue = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1; var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; this.add('controller:' + routeName, _emberRuntime.Controller.extend((_Controller$extend2 = { queryParams: (_queryParams = {}, _queryParams[prop] = urlKey, _queryParams) }, _Controller$extend2[prop] = defaultValue, _Controller$extend2), options)); }; (0, _emberBabel.createClass)(QueryParamTestCase, [{ key: 'routerOptions', get: function () { return { location: 'test' }; } }]); return QueryParamTestCase; }(_application.default); exports.default = QueryParamTestCase; }); enifed('internal-test-helpers/test-cases/rendering', ['exports', 'ember-babel', 'ember-views', 'internal-test-helpers/test-cases/abstract-rendering'], function (exports, _emberBabel, _emberViews, _abstractRendering) { 'use strict'; var RenderingTestCase = function (_AbstractRenderingTes) { (0, _emberBabel.inherits)(RenderingTestCase, _AbstractRenderingTes); function RenderingTestCase() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AbstractRenderingTes.call(this)); var owner = _this.owner; _this.env = owner.lookup('service:-glimmer-environment'); owner.register('component-lookup:main', _emberViews.ComponentLookup); owner.registerOptionsForType('helper', { instantiate: false }); owner.registerOptionsForType('component', { singleton: false }); return _this; } return RenderingTestCase; }(_abstractRendering.default); exports.default = RenderingTestCase; }); enifed('internal-test-helpers/test-cases/router', ['exports', 'ember-babel', 'internal-test-helpers/test-cases/application'], function (exports, _emberBabel, _application) { 'use strict'; var RouterTestCase = function (_ApplicationTestCase) { (0, _emberBabel.inherits)(RouterTestCase, _ApplicationTestCase); function RouterTestCase() { var _this = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this)); _this.router.map(function () { this.route('parent', { path: '/' }, function () { this.route('child'); this.route('sister'); this.route('brother'); }); this.route('dynamic', { path: '/dynamic/:dynamic_id' }); }); return _this; } (0, _emberBabel.createClass)(RouterTestCase, [{ key: 'routerService', get: function () { return this.applicationInstance.lookup('service:router'); } }]); return RouterTestCase; }(_application.default); exports.default = RouterTestCase; }); enifed('internal-test-helpers/test-groups', ['exports', 'ember-environment', 'ember-metal'], function (exports, _emberEnvironment, _emberMetal) { 'use strict'; exports.testBoth = // used by unit tests to test both accessor mode and non-accessor mode function (testname, callback) { function emberget(x, y) { return (0, _emberMetal.get)(x, y); } function emberset(x, y, z) { return (0, _emberMetal.set)(x, y, z); } function aget(x, y) { return x[y]; } function aset(x, y, z) { return x[y] = z; } QUnit.test(testname + ' using getFromEmberMetal()/Ember.set()', function () { callback(emberget, emberset); }); QUnit.test(testname + ' using accessors', function () { if (_emberEnvironment.ENV.USES_ACCESSORS) { callback(aget, aset); } else { ok('SKIPPING ACCESSORS'); } }); }; exports.testWithDefault = function (testname, callback) { function emberget(x, y) { return (0, _emberMetal.get)(x, y); } function embergetwithdefault(x, y, z) { return (0, _emberMetal.getWithDefault)(x, y, z); } function getwithdefault(x, y, z) { return x.getWithDefault(y, z); } function emberset(x, y, z) { return (0, _emberMetal.set)(x, y, z); } function aget(x, y) { return x[y]; } function aset(x, y, z) { return x[y] = z; } QUnit.test(testname + ' using obj.get()', function () { callback(emberget, emberset); }); QUnit.test(testname + ' using obj.getWithDefault()', function () { callback(getwithdefault, emberset); }); QUnit.test(testname + ' using getFromEmberMetal()', function () { callback(emberget, emberset); }); QUnit.test(testname + ' using Ember.getWithDefault()', function () { callback(embergetwithdefault, emberset); }); QUnit.test(testname + ' using accessors', function () { if (_emberEnvironment.ENV.USES_ACCESSORS) { callback(aget, aset); } else { ok('SKIPPING ACCESSORS'); } }); }; }); enifed('internal-test-helpers/test-resolver', ['exports', 'ember-babel', 'ember-template-compiler'], function (exports, _emberBabel, _emberTemplateCompiler) { 'use strict'; exports.ModuleBasedResolver = undefined; var Resolver = function () { function Resolver() { this._registered = {}; this.constructor.lastInstance = this; } Resolver.prototype.resolve = function (specifier) { return this._registered[specifier]; }; Resolver.prototype.add = function (specifier, factory) { if (specifier.indexOf(':') === -1) { throw new Error('Specifiers added to the resolver must be in the format of type:name'); } return this._registered[specifier] = factory; }; Resolver.prototype.addTemplate = function (templateName, template) { var templateType = typeof template; if (templateType !== 'string') { throw new Error('You called addTemplate for "' + templateName + '" with a template argument of type of \'' + templateType + '\'. addTemplate expects an argument of an uncompiled template as a string.'); } return this._registered['template:' + templateName] = (0, _emberTemplateCompiler.compile)(template, { moduleName: templateName }); }; Resolver.create = function () { return new this(); }; return Resolver; }(); exports.default = Resolver; var ModuleBasedResolver = function (_Resolver) { (0, _emberBabel.inherits)(ModuleBasedResolver, _Resolver); function ModuleBasedResolver() { return (0, _emberBabel.possibleConstructorReturn)(this, _Resolver.apply(this, arguments)); } (0, _emberBabel.createClass)(ModuleBasedResolver, [{ key: 'moduleBasedResolver', get: function () { return true; } }]); return ModuleBasedResolver; }(Resolver); exports.ModuleBasedResolver = ModuleBasedResolver; }); enifed('internal-test-helpers/tests/index-test', [], function () { 'use strict'; QUnit.module('internal-test-helpers'); QUnit.test('module present', function (assert) { assert.ok(true, 'each package needs at least one test to be able to run through `npm test`'); }); }); enifed('node-module', ['exports'], function(_exports) { var IS_NODE = typeof module === 'object' && typeof module.require === 'function'; if (IS_NODE) { _exports.require = module.require; _exports.module = module; _exports.IS_NODE = IS_NODE } else { _exports.require = null; _exports.module = null; _exports.IS_NODE = IS_NODE } }); enifed("simple-html-tokenizer", ["exports"], function (exports) { "use strict"; var namedCharRefs = { Aacute: "Á", aacute: "á", Abreve: "Ă", abreve: "ă", ac: "∾", acd: "∿", acE: "∾̳", Acirc: "Â", acirc: "â", acute: "´", Acy: "А", acy: "а", AElig: "Æ", aelig: "æ", af: "\u2061", Afr: "𝔄", afr: "𝔞", Agrave: "À", agrave: "à", alefsym: "ℵ", aleph: "ℵ", Alpha: "Α", alpha: "α", Amacr: "Ā", amacr: "ā", amalg: "⨿", AMP: "&", amp: "&", And: "⩓", and: "∧", andand: "⩕", andd: "⩜", andslope: "⩘", andv: "⩚", ang: "∠", ange: "⦤", angle: "∠", angmsd: "∡", angmsdaa: "⦨", angmsdab: "⦩", angmsdac: "⦪", angmsdad: "⦫", angmsdae: "⦬", angmsdaf: "⦭", angmsdag: "⦮", angmsdah: "⦯", angrt: "∟", angrtvb: "⊾", angrtvbd: "⦝", angsph: "∢", angst: "Å", angzarr: "⍼", Aogon: "Ą", aogon: "ą", Aopf: "𝔸", aopf: "𝕒", ap: "≈", apacir: "⩯", apE: "⩰", ape: "≊", apid: "≋", apos: "'", ApplyFunction: "\u2061", approx: "≈", approxeq: "≊", Aring: "Å", aring: "å", Ascr: "𝒜", ascr: "𝒶", Assign: "≔", ast: "*", asymp: "≈", asympeq: "≍", Atilde: "Ã", atilde: "ã", Auml: "Ä", auml: "ä", awconint: "∳", awint: "⨑", backcong: "≌", backepsilon: "϶", backprime: "‵", backsim: "∽", backsimeq: "⋍", Backslash: "∖", Barv: "⫧", barvee: "⊽", Barwed: "⌆", barwed: "⌅", barwedge: "⌅", bbrk: "⎵", bbrktbrk: "⎶", bcong: "≌", Bcy: "Б", bcy: "б", bdquo: "„", becaus: "∵", Because: "∵", because: "∵", bemptyv: "⦰", bepsi: "϶", bernou: "ℬ", Bernoullis: "ℬ", Beta: "Β", beta: "β", beth: "ℶ", between: "≬", Bfr: "𝔅", bfr: "𝔟", bigcap: "⋂", bigcirc: "◯", bigcup: "⋃", bigodot: "⨀", bigoplus: "⨁", bigotimes: "⨂", bigsqcup: "⨆", bigstar: "★", bigtriangledown: "▽", bigtriangleup: "△", biguplus: "⨄", bigvee: "⋁", bigwedge: "⋀", bkarow: "⤍", blacklozenge: "⧫", blacksquare: "▪", blacktriangle: "▴", blacktriangledown: "▾", blacktriangleleft: "◂", blacktriangleright: "▸", blank: "␣", blk12: "▒", blk14: "░", blk34: "▓", block: "█", bne: "=⃥", bnequiv: "≡⃥", bNot: "⫭", bnot: "⌐", Bopf: "𝔹", bopf: "𝕓", bot: "⊥", bottom: "⊥", bowtie: "⋈", boxbox: "⧉", boxDL: "╗", boxDl: "╖", boxdL: "╕", boxdl: "┐", boxDR: "╔", boxDr: "╓", boxdR: "╒", boxdr: "┌", boxH: "═", boxh: "─", boxHD: "╦", boxHd: "╤", boxhD: "╥", boxhd: "┬", boxHU: "╩", boxHu: "╧", boxhU: "╨", boxhu: "┴", boxminus: "⊟", boxplus: "⊞", boxtimes: "⊠", boxUL: "╝", boxUl: "╜", boxuL: "╛", boxul: "┘", boxUR: "╚", boxUr: "╙", boxuR: "╘", boxur: "└", boxV: "║", boxv: "│", boxVH: "╬", boxVh: "╫", boxvH: "╪", boxvh: "┼", boxVL: "╣", boxVl: "╢", boxvL: "╡", boxvl: "┤", boxVR: "╠", boxVr: "╟", boxvR: "╞", boxvr: "├", bprime: "‵", Breve: "˘", breve: "˘", brvbar: "¦", Bscr: "ℬ", bscr: "𝒷", bsemi: "⁏", bsim: "∽", bsime: "⋍", bsol: "\\", bsolb: "⧅", bsolhsub: "⟈", bull: "•", bullet: "•", bump: "≎", bumpE: "⪮", bumpe: "≏", Bumpeq: "≎", bumpeq: "≏", Cacute: "Ć", cacute: "ć", Cap: "⋒", cap: "∩", capand: "⩄", capbrcup: "⩉", capcap: "⩋", capcup: "⩇", capdot: "⩀", CapitalDifferentialD: "ⅅ", caps: "∩︀", caret: "⁁", caron: "ˇ", Cayleys: "ℭ", ccaps: "⩍", Ccaron: "Č", ccaron: "č", Ccedil: "Ç", ccedil: "ç", Ccirc: "Ĉ", ccirc: "ĉ", Cconint: "∰", ccups: "⩌", ccupssm: "⩐", Cdot: "Ċ", cdot: "ċ", cedil: "¸", Cedilla: "¸", cemptyv: "⦲", cent: "¢", CenterDot: "·", centerdot: "·", Cfr: "ℭ", cfr: "𝔠", CHcy: "Ч", chcy: "ч", check: "✓", checkmark: "✓", Chi: "Χ", chi: "χ", cir: "○", circ: "ˆ", circeq: "≗", circlearrowleft: "↺", circlearrowright: "↻", circledast: "⊛", circledcirc: "⊚", circleddash: "⊝", CircleDot: "⊙", circledR: "®", circledS: "Ⓢ", CircleMinus: "⊖", CirclePlus: "⊕", CircleTimes: "⊗", cirE: "⧃", cire: "≗", cirfnint: "⨐", cirmid: "⫯", cirscir: "⧂", ClockwiseContourIntegral: "∲", CloseCurlyDoubleQuote: "”", CloseCurlyQuote: "’", clubs: "♣", clubsuit: "♣", Colon: "∷", colon: ":", Colone: "⩴", colone: "≔", coloneq: "≔", comma: ",", commat: "@", comp: "∁", compfn: "∘", complement: "∁", complexes: "ℂ", cong: "≅", congdot: "⩭", Congruent: "≡", Conint: "∯", conint: "∮", ContourIntegral: "∮", Copf: "ℂ", copf: "𝕔", coprod: "∐", Coproduct: "∐", COPY: "©", copy: "©", copysr: "℗", CounterClockwiseContourIntegral: "∳", crarr: "↵", Cross: "⨯", cross: "✗", Cscr: "𝒞", cscr: "𝒸", csub: "⫏", csube: "⫑", csup: "⫐", csupe: "⫒", ctdot: "⋯", cudarrl: "⤸", cudarrr: "⤵", cuepr: "⋞", cuesc: "⋟", cularr: "↶", cularrp: "⤽", Cup: "⋓", cup: "∪", cupbrcap: "⩈", CupCap: "≍", cupcap: "⩆", cupcup: "⩊", cupdot: "⊍", cupor: "⩅", cups: "∪︀", curarr: "↷", curarrm: "⤼", curlyeqprec: "⋞", curlyeqsucc: "⋟", curlyvee: "⋎", curlywedge: "⋏", curren: "¤", curvearrowleft: "↶", curvearrowright: "↷", cuvee: "⋎", cuwed: "⋏", cwconint: "∲", cwint: "∱", cylcty: "⌭", Dagger: "‡", dagger: "†", daleth: "ℸ", Darr: "↡", dArr: "⇓", darr: "↓", dash: "‐", Dashv: "⫤", dashv: "⊣", dbkarow: "⤏", dblac: "˝", Dcaron: "Ď", dcaron: "ď", Dcy: "Д", dcy: "д", DD: "ⅅ", dd: "ⅆ", ddagger: "‡", ddarr: "⇊", DDotrahd: "⤑", ddotseq: "⩷", deg: "°", Del: "∇", Delta: "Δ", delta: "δ", demptyv: "⦱", dfisht: "⥿", Dfr: "𝔇", dfr: "𝔡", dHar: "⥥", dharl: "⇃", dharr: "⇂", DiacriticalAcute: "´", DiacriticalDot: "˙", DiacriticalDoubleAcute: "˝", DiacriticalGrave: "`", DiacriticalTilde: "˜", diam: "⋄", Diamond: "⋄", diamond: "⋄", diamondsuit: "♦", diams: "♦", die: "¨", DifferentialD: "ⅆ", digamma: "ϝ", disin: "⋲", div: "÷", divide: "÷", divideontimes: "⋇", divonx: "⋇", DJcy: "Ђ", djcy: "ђ", dlcorn: "⌞", dlcrop: "⌍", dollar: "$", Dopf: "𝔻", dopf: "𝕕", Dot: "¨", dot: "˙", DotDot: "⃜", doteq: "≐", doteqdot: "≑", DotEqual: "≐", dotminus: "∸", dotplus: "∔", dotsquare: "⊡", doublebarwedge: "⌆", DoubleContourIntegral: "∯", DoubleDot: "¨", DoubleDownArrow: "⇓", DoubleLeftArrow: "⇐", DoubleLeftRightArrow: "⇔", DoubleLeftTee: "⫤", DoubleLongLeftArrow: "⟸", DoubleLongLeftRightArrow: "⟺", DoubleLongRightArrow: "⟹", DoubleRightArrow: "⇒", DoubleRightTee: "⊨", DoubleUpArrow: "⇑", DoubleUpDownArrow: "⇕", DoubleVerticalBar: "∥", DownArrow: "↓", Downarrow: "⇓", downarrow: "↓", DownArrowBar: "⤓", DownArrowUpArrow: "⇵", DownBreve: "̑", downdownarrows: "⇊", downharpoonleft: "⇃", downharpoonright: "⇂", DownLeftRightVector: "⥐", DownLeftTeeVector: "⥞", DownLeftVector: "↽", DownLeftVectorBar: "⥖", DownRightTeeVector: "⥟", DownRightVector: "⇁", DownRightVectorBar: "⥗", DownTee: "⊤", DownTeeArrow: "↧", drbkarow: "⤐", drcorn: "⌟", drcrop: "⌌", Dscr: "𝒟", dscr: "𝒹", DScy: "Ѕ", dscy: "ѕ", dsol: "⧶", Dstrok: "Đ", dstrok: "đ", dtdot: "⋱", dtri: "▿", dtrif: "▾", duarr: "⇵", duhar: "⥯", dwangle: "⦦", DZcy: "Џ", dzcy: "џ", dzigrarr: "⟿", Eacute: "É", eacute: "é", easter: "⩮", Ecaron: "Ě", ecaron: "ě", ecir: "≖", Ecirc: "Ê", ecirc: "ê", ecolon: "≕", Ecy: "Э", ecy: "э", eDDot: "⩷", Edot: "Ė", eDot: "≑", edot: "ė", ee: "ⅇ", efDot: "≒", Efr: "𝔈", efr: "𝔢", eg: "⪚", Egrave: "È", egrave: "è", egs: "⪖", egsdot: "⪘", el: "⪙", Element: "∈", elinters: "⏧", ell: "ℓ", els: "⪕", elsdot: "⪗", Emacr: "Ē", emacr: "ē", empty: "∅", emptyset: "∅", EmptySmallSquare: "◻", emptyv: "∅", EmptyVerySmallSquare: "▫", emsp: " ", emsp13: " ", emsp14: " ", ENG: "Ŋ", eng: "ŋ", ensp: " ", Eogon: "Ę", eogon: "ę", Eopf: "𝔼", eopf: "𝕖", epar: "⋕", eparsl: "⧣", eplus: "⩱", epsi: "ε", Epsilon: "Ε", epsilon: "ε", epsiv: "ϵ", eqcirc: "≖", eqcolon: "≕", eqsim: "≂", eqslantgtr: "⪖", eqslantless: "⪕", Equal: "⩵", equals: "=", EqualTilde: "≂", equest: "≟", Equilibrium: "⇌", equiv: "≡", equivDD: "⩸", eqvparsl: "⧥", erarr: "⥱", erDot: "≓", Escr: "ℰ", escr: "ℯ", esdot: "≐", Esim: "⩳", esim: "≂", Eta: "Η", eta: "η", ETH: "Ð", eth: "ð", Euml: "Ë", euml: "ë", euro: "€", excl: "!", exist: "∃", Exists: "∃", expectation: "ℰ", ExponentialE: "ⅇ", exponentiale: "ⅇ", fallingdotseq: "≒", Fcy: "Ф", fcy: "ф", female: "♀", ffilig: "ffi", fflig: "ff", ffllig: "ffl", Ffr: "𝔉", ffr: "𝔣", filig: "fi", FilledSmallSquare: "◼", FilledVerySmallSquare: "▪", fjlig: "fj", flat: "♭", fllig: "fl", fltns: "▱", fnof: "ƒ", Fopf: "𝔽", fopf: "𝕗", ForAll: "∀", forall: "∀", fork: "⋔", forkv: "⫙", Fouriertrf: "ℱ", fpartint: "⨍", frac12: "½", frac13: "⅓", frac14: "¼", frac15: "⅕", frac16: "⅙", frac18: "⅛", frac23: "⅔", frac25: "⅖", frac34: "¾", frac35: "⅗", frac38: "⅜", frac45: "⅘", frac56: "⅚", frac58: "⅝", frac78: "⅞", frasl: "⁄", frown: "⌢", Fscr: "ℱ", fscr: "𝒻", gacute: "ǵ", Gamma: "Γ", gamma: "γ", Gammad: "Ϝ", gammad: "ϝ", gap: "⪆", Gbreve: "Ğ", gbreve: "ğ", Gcedil: "Ģ", Gcirc: "Ĝ", gcirc: "ĝ", Gcy: "Г", gcy: "г", Gdot: "Ġ", gdot: "ġ", gE: "≧", ge: "≥", gEl: "⪌", gel: "⋛", geq: "≥", geqq: "≧", geqslant: "⩾", ges: "⩾", gescc: "⪩", gesdot: "⪀", gesdoto: "⪂", gesdotol: "⪄", gesl: "⋛︀", gesles: "⪔", Gfr: "𝔊", gfr: "𝔤", Gg: "⋙", gg: "≫", ggg: "⋙", gimel: "ℷ", GJcy: "Ѓ", gjcy: "ѓ", gl: "≷", gla: "⪥", glE: "⪒", glj: "⪤", gnap: "⪊", gnapprox: "⪊", gnE: "≩", gne: "⪈", gneq: "⪈", gneqq: "≩", gnsim: "⋧", Gopf: "𝔾", gopf: "𝕘", grave: "`", GreaterEqual: "≥", GreaterEqualLess: "⋛", GreaterFullEqual: "≧", GreaterGreater: "⪢", GreaterLess: "≷", GreaterSlantEqual: "⩾", GreaterTilde: "≳", Gscr: "𝒢", gscr: "ℊ", gsim: "≳", gsime: "⪎", gsiml: "⪐", GT: ">", Gt: "≫", gt: ">", gtcc: "⪧", gtcir: "⩺", gtdot: "⋗", gtlPar: "⦕", gtquest: "⩼", gtrapprox: "⪆", gtrarr: "⥸", gtrdot: "⋗", gtreqless: "⋛", gtreqqless: "⪌", gtrless: "≷", gtrsim: "≳", gvertneqq: "≩︀", gvnE: "≩︀", Hacek: "ˇ", hairsp: " ", half: "½", hamilt: "ℋ", HARDcy: "Ъ", hardcy: "ъ", hArr: "⇔", harr: "↔", harrcir: "⥈", harrw: "↭", Hat: "^", hbar: "ℏ", Hcirc: "Ĥ", hcirc: "ĥ", hearts: "♥", heartsuit: "♥", hellip: "…", hercon: "⊹", Hfr: "ℌ", hfr: "𝔥", HilbertSpace: "ℋ", hksearow: "⤥", hkswarow: "⤦", hoarr: "⇿", homtht: "∻", hookleftarrow: "↩", hookrightarrow: "↪", Hopf: "ℍ", hopf: "𝕙", horbar: "―", HorizontalLine: "─", Hscr: "ℋ", hscr: "𝒽", hslash: "ℏ", Hstrok: "Ħ", hstrok: "ħ", HumpDownHump: "≎", HumpEqual: "≏", hybull: "⁃", hyphen: "‐", Iacute: "Í", iacute: "í", ic: "\u2063", Icirc: "Î", icirc: "î", Icy: "И", icy: "и", Idot: "İ", IEcy: "Е", iecy: "е", iexcl: "¡", iff: "⇔", Ifr: "ℑ", ifr: "𝔦", Igrave: "Ì", igrave: "ì", ii: "ⅈ", iiiint: "⨌", iiint: "∭", iinfin: "⧜", iiota: "℩", IJlig: "IJ", ijlig: "ij", Im: "ℑ", Imacr: "Ī", imacr: "ī", image: "ℑ", ImaginaryI: "ⅈ", imagline: "ℐ", imagpart: "ℑ", imath: "ı", imof: "⊷", imped: "Ƶ", Implies: "⇒", in: "∈", incare: "℅", infin: "∞", infintie: "⧝", inodot: "ı", Int: "∬", int: "∫", intcal: "⊺", integers: "ℤ", Integral: "∫", intercal: "⊺", Intersection: "⋂", intlarhk: "⨗", intprod: "⨼", InvisibleComma: "\u2063", InvisibleTimes: "\u2062", IOcy: "Ё", iocy: "ё", Iogon: "Į", iogon: "į", Iopf: "𝕀", iopf: "𝕚", Iota: "Ι", iota: "ι", iprod: "⨼", iquest: "¿", Iscr: "ℐ", iscr: "𝒾", isin: "∈", isindot: "⋵", isinE: "⋹", isins: "⋴", isinsv: "⋳", isinv: "∈", it: "\u2062", Itilde: "Ĩ", itilde: "ĩ", Iukcy: "І", iukcy: "і", Iuml: "Ï", iuml: "ï", Jcirc: "Ĵ", jcirc: "ĵ", Jcy: "Й", jcy: "й", Jfr: "𝔍", jfr: "𝔧", jmath: "ȷ", Jopf: "𝕁", jopf: "𝕛", Jscr: "𝒥", jscr: "𝒿", Jsercy: "Ј", jsercy: "ј", Jukcy: "Є", jukcy: "є", Kappa: "Κ", kappa: "κ", kappav: "ϰ", Kcedil: "Ķ", kcedil: "ķ", Kcy: "К", kcy: "к", Kfr: "𝔎", kfr: "𝔨", kgreen: "ĸ", KHcy: "Х", khcy: "х", KJcy: "Ќ", kjcy: "ќ", Kopf: "𝕂", kopf: "𝕜", Kscr: "𝒦", kscr: "𝓀", lAarr: "⇚", Lacute: "Ĺ", lacute: "ĺ", laemptyv: "⦴", lagran: "ℒ", Lambda: "Λ", lambda: "λ", Lang: "⟪", lang: "⟨", langd: "⦑", langle: "⟨", lap: "⪅", Laplacetrf: "ℒ", laquo: "«", Larr: "↞", lArr: "⇐", larr: "←", larrb: "⇤", larrbfs: "⤟", larrfs: "⤝", larrhk: "↩", larrlp: "↫", larrpl: "⤹", larrsim: "⥳", larrtl: "↢", lat: "⪫", lAtail: "⤛", latail: "⤙", late: "⪭", lates: "⪭︀", lBarr: "⤎", lbarr: "⤌", lbbrk: "❲", lbrace: "{", lbrack: "[", lbrke: "⦋", lbrksld: "⦏", lbrkslu: "⦍", Lcaron: "Ľ", lcaron: "ľ", Lcedil: "Ļ", lcedil: "ļ", lceil: "⌈", lcub: "{", Lcy: "Л", lcy: "л", ldca: "⤶", ldquo: "“", ldquor: "„", ldrdhar: "⥧", ldrushar: "⥋", ldsh: "↲", lE: "≦", le: "≤", LeftAngleBracket: "⟨", LeftArrow: "←", Leftarrow: "⇐", leftarrow: "←", LeftArrowBar: "⇤", LeftArrowRightArrow: "⇆", leftarrowtail: "↢", LeftCeiling: "⌈", LeftDoubleBracket: "⟦", LeftDownTeeVector: "⥡", LeftDownVector: "⇃", LeftDownVectorBar: "⥙", LeftFloor: "⌊", leftharpoondown: "↽", leftharpoonup: "↼", leftleftarrows: "⇇", LeftRightArrow: "↔", Leftrightarrow: "⇔", leftrightarrow: "↔", leftrightarrows: "⇆", leftrightharpoons: "⇋", leftrightsquigarrow: "↭", LeftRightVector: "⥎", LeftTee: "⊣", LeftTeeArrow: "↤", LeftTeeVector: "⥚", leftthreetimes: "⋋", LeftTriangle: "⊲", LeftTriangleBar: "⧏", LeftTriangleEqual: "⊴", LeftUpDownVector: "⥑", LeftUpTeeVector: "⥠", LeftUpVector: "↿", LeftUpVectorBar: "⥘", LeftVector: "↼", LeftVectorBar: "⥒", lEg: "⪋", leg: "⋚", leq: "≤", leqq: "≦", leqslant: "⩽", les: "⩽", lescc: "⪨", lesdot: "⩿", lesdoto: "⪁", lesdotor: "⪃", lesg: "⋚︀", lesges: "⪓", lessapprox: "⪅", lessdot: "⋖", lesseqgtr: "⋚", lesseqqgtr: "⪋", LessEqualGreater: "⋚", LessFullEqual: "≦", LessGreater: "≶", lessgtr: "≶", LessLess: "⪡", lesssim: "≲", LessSlantEqual: "⩽", LessTilde: "≲", lfisht: "⥼", lfloor: "⌊", Lfr: "𝔏", lfr: "𝔩", lg: "≶", lgE: "⪑", lHar: "⥢", lhard: "↽", lharu: "↼", lharul: "⥪", lhblk: "▄", LJcy: "Љ", ljcy: "љ", Ll: "⋘", ll: "≪", llarr: "⇇", llcorner: "⌞", Lleftarrow: "⇚", llhard: "⥫", lltri: "◺", Lmidot: "Ŀ", lmidot: "ŀ", lmoust: "⎰", lmoustache: "⎰", lnap: "⪉", lnapprox: "⪉", lnE: "≨", lne: "⪇", lneq: "⪇", lneqq: "≨", lnsim: "⋦", loang: "⟬", loarr: "⇽", lobrk: "⟦", LongLeftArrow: "⟵", Longleftarrow: "⟸", longleftarrow: "⟵", LongLeftRightArrow: "⟷", Longleftrightarrow: "⟺", longleftrightarrow: "⟷", longmapsto: "⟼", LongRightArrow: "⟶", Longrightarrow: "⟹", longrightarrow: "⟶", looparrowleft: "↫", looparrowright: "↬", lopar: "⦅", Lopf: "𝕃", lopf: "𝕝", loplus: "⨭", lotimes: "⨴", lowast: "∗", lowbar: "_", LowerLeftArrow: "↙", LowerRightArrow: "↘", loz: "◊", lozenge: "◊", lozf: "⧫", lpar: "(", lparlt: "⦓", lrarr: "⇆", lrcorner: "⌟", lrhar: "⇋", lrhard: "⥭", lrm: "\u200e", lrtri: "⊿", lsaquo: "‹", Lscr: "ℒ", lscr: "𝓁", Lsh: "↰", lsh: "↰", lsim: "≲", lsime: "⪍", lsimg: "⪏", lsqb: "[", lsquo: "‘", lsquor: "‚", Lstrok: "Ł", lstrok: "ł", LT: "<", Lt: "≪", lt: "<", ltcc: "⪦", ltcir: "⩹", ltdot: "⋖", lthree: "⋋", ltimes: "⋉", ltlarr: "⥶", ltquest: "⩻", ltri: "◃", ltrie: "⊴", ltrif: "◂", ltrPar: "⦖", lurdshar: "⥊", luruhar: "⥦", lvertneqq: "≨︀", lvnE: "≨︀", macr: "¯", male: "♂", malt: "✠", maltese: "✠", Map: "⤅", map: "↦", mapsto: "↦", mapstodown: "↧", mapstoleft: "↤", mapstoup: "↥", marker: "▮", mcomma: "⨩", Mcy: "М", mcy: "м", mdash: "—", mDDot: "∺", measuredangle: "∡", MediumSpace: " ", Mellintrf: "ℳ", Mfr: "𝔐", mfr: "𝔪", mho: "℧", micro: "µ", mid: "∣", midast: "*", midcir: "⫰", middot: "·", minus: "−", minusb: "⊟", minusd: "∸", minusdu: "⨪", MinusPlus: "∓", mlcp: "⫛", mldr: "…", mnplus: "∓", models: "⊧", Mopf: "𝕄", mopf: "𝕞", mp: "∓", Mscr: "ℳ", mscr: "𝓂", mstpos: "∾", Mu: "Μ", mu: "μ", multimap: "⊸", mumap: "⊸", nabla: "∇", Nacute: "Ń", nacute: "ń", nang: "∠⃒", nap: "≉", napE: "⩰̸", napid: "≋̸", napos: "ʼn", napprox: "≉", natur: "♮", natural: "♮", naturals: "ℕ", nbsp: " ", nbump: "≎̸", nbumpe: "≏̸", ncap: "⩃", Ncaron: "Ň", ncaron: "ň", Ncedil: "Ņ", ncedil: "ņ", ncong: "≇", ncongdot: "⩭̸", ncup: "⩂", Ncy: "Н", ncy: "н", ndash: "–", ne: "≠", nearhk: "⤤", neArr: "⇗", nearr: "↗", nearrow: "↗", nedot: "≐̸", NegativeMediumSpace: "​", NegativeThickSpace: "​", NegativeThinSpace: "​", NegativeVeryThinSpace: "​", nequiv: "≢", nesear: "⤨", nesim: "≂̸", NestedGreaterGreater: "≫", NestedLessLess: "≪", NewLine: "\u000a", nexist: "∄", nexists: "∄", Nfr: "𝔑", nfr: "𝔫", ngE: "≧̸", nge: "≱", ngeq: "≱", ngeqq: "≧̸", ngeqslant: "⩾̸", nges: "⩾̸", nGg: "⋙̸", ngsim: "≵", nGt: "≫⃒", ngt: "≯", ngtr: "≯", nGtv: "≫̸", nhArr: "⇎", nharr: "↮", nhpar: "⫲", ni: "∋", nis: "⋼", nisd: "⋺", niv: "∋", NJcy: "Њ", njcy: "њ", nlArr: "⇍", nlarr: "↚", nldr: "‥", nlE: "≦̸", nle: "≰", nLeftarrow: "⇍", nleftarrow: "↚", nLeftrightarrow: "⇎", nleftrightarrow: "↮", nleq: "≰", nleqq: "≦̸", nleqslant: "⩽̸", nles: "⩽̸", nless: "≮", nLl: "⋘̸", nlsim: "≴", nLt: "≪⃒", nlt: "≮", nltri: "⋪", nltrie: "⋬", nLtv: "≪̸", nmid: "∤", NoBreak: "\u2060", NonBreakingSpace: " ", Nopf: "ℕ", nopf: "𝕟", Not: "⫬", not: "¬", NotCongruent: "≢", NotCupCap: "≭", NotDoubleVerticalBar: "∦", NotElement: "∉", NotEqual: "≠", NotEqualTilde: "≂̸", NotExists: "∄", NotGreater: "≯", NotGreaterEqual: "≱", NotGreaterFullEqual: "≧̸", NotGreaterGreater: "≫̸", NotGreaterLess: "≹", NotGreaterSlantEqual: "⩾̸", NotGreaterTilde: "≵", NotHumpDownHump: "≎̸", NotHumpEqual: "≏̸", notin: "∉", notindot: "⋵̸", notinE: "⋹̸", notinva: "∉", notinvb: "⋷", notinvc: "⋶", NotLeftTriangle: "⋪", NotLeftTriangleBar: "⧏̸", NotLeftTriangleEqual: "⋬", NotLess: "≮", NotLessEqual: "≰", NotLessGreater: "≸", NotLessLess: "≪̸", NotLessSlantEqual: "⩽̸", NotLessTilde: "≴", NotNestedGreaterGreater: "⪢̸", NotNestedLessLess: "⪡̸", notni: "∌", notniva: "∌", notnivb: "⋾", notnivc: "⋽", NotPrecedes: "⊀", NotPrecedesEqual: "⪯̸", NotPrecedesSlantEqual: "⋠", NotReverseElement: "∌", NotRightTriangle: "⋫", NotRightTriangleBar: "⧐̸", NotRightTriangleEqual: "⋭", NotSquareSubset: "⊏̸", NotSquareSubsetEqual: "⋢", NotSquareSuperset: "⊐̸", NotSquareSupersetEqual: "⋣", NotSubset: "⊂⃒", NotSubsetEqual: "⊈", NotSucceeds: "⊁", NotSucceedsEqual: "⪰̸", NotSucceedsSlantEqual: "⋡", NotSucceedsTilde: "≿̸", NotSuperset: "⊃⃒", NotSupersetEqual: "⊉", NotTilde: "≁", NotTildeEqual: "≄", NotTildeFullEqual: "≇", NotTildeTilde: "≉", NotVerticalBar: "∤", npar: "∦", nparallel: "∦", nparsl: "⫽⃥", npart: "∂̸", npolint: "⨔", npr: "⊀", nprcue: "⋠", npre: "⪯̸", nprec: "⊀", npreceq: "⪯̸", nrArr: "⇏", nrarr: "↛", nrarrc: "⤳̸", nrarrw: "↝̸", nRightarrow: "⇏", nrightarrow: "↛", nrtri: "⋫", nrtrie: "⋭", nsc: "⊁", nsccue: "⋡", nsce: "⪰̸", Nscr: "𝒩", nscr: "𝓃", nshortmid: "∤", nshortparallel: "∦", nsim: "≁", nsime: "≄", nsimeq: "≄", nsmid: "∤", nspar: "∦", nsqsube: "⋢", nsqsupe: "⋣", nsub: "⊄", nsubE: "⫅̸", nsube: "⊈", nsubset: "⊂⃒", nsubseteq: "⊈", nsubseteqq: "⫅̸", nsucc: "⊁", nsucceq: "⪰̸", nsup: "⊅", nsupE: "⫆̸", nsupe: "⊉", nsupset: "⊃⃒", nsupseteq: "⊉", nsupseteqq: "⫆̸", ntgl: "≹", Ntilde: "Ñ", ntilde: "ñ", ntlg: "≸", ntriangleleft: "⋪", ntrianglelefteq: "⋬", ntriangleright: "⋫", ntrianglerighteq: "⋭", Nu: "Ν", nu: "ν", num: "#", numero: "№", numsp: " ", nvap: "≍⃒", nVDash: "⊯", nVdash: "⊮", nvDash: "⊭", nvdash: "⊬", nvge: "≥⃒", nvgt: ">⃒", nvHarr: "⤄", nvinfin: "⧞", nvlArr: "⤂", nvle: "≤⃒", nvlt: "<⃒", nvltrie: "⊴⃒", nvrArr: "⤃", nvrtrie: "⊵⃒", nvsim: "∼⃒", nwarhk: "⤣", nwArr: "⇖", nwarr: "↖", nwarrow: "↖", nwnear: "⤧", Oacute: "Ó", oacute: "ó", oast: "⊛", ocir: "⊚", Ocirc: "Ô", ocirc: "ô", Ocy: "О", ocy: "о", odash: "⊝", Odblac: "Ő", odblac: "ő", odiv: "⨸", odot: "⊙", odsold: "⦼", OElig: "Œ", oelig: "œ", ofcir: "⦿", Ofr: "𝔒", ofr: "𝔬", ogon: "˛", Ograve: "Ò", ograve: "ò", ogt: "⧁", ohbar: "⦵", ohm: "Ω", oint: "∮", olarr: "↺", olcir: "⦾", olcross: "⦻", oline: "‾", olt: "⧀", Omacr: "Ō", omacr: "ō", Omega: "Ω", omega: "ω", Omicron: "Ο", omicron: "ο", omid: "⦶", ominus: "⊖", Oopf: "𝕆", oopf: "𝕠", opar: "⦷", OpenCurlyDoubleQuote: "“", OpenCurlyQuote: "‘", operp: "⦹", oplus: "⊕", Or: "⩔", or: "∨", orarr: "↻", ord: "⩝", order: "ℴ", orderof: "ℴ", ordf: "ª", ordm: "º", origof: "⊶", oror: "⩖", orslope: "⩗", orv: "⩛", oS: "Ⓢ", Oscr: "𝒪", oscr: "ℴ", Oslash: "Ø", oslash: "ø", osol: "⊘", Otilde: "Õ", otilde: "õ", Otimes: "⨷", otimes: "⊗", otimesas: "⨶", Ouml: "Ö", ouml: "ö", ovbar: "⌽", OverBar: "‾", OverBrace: "⏞", OverBracket: "⎴", OverParenthesis: "⏜", par: "∥", para: "¶", parallel: "∥", parsim: "⫳", parsl: "⫽", part: "∂", PartialD: "∂", Pcy: "П", pcy: "п", percnt: "%", period: ".", permil: "‰", perp: "⊥", pertenk: "‱", Pfr: "𝔓", pfr: "𝔭", Phi: "Φ", phi: "φ", phiv: "ϕ", phmmat: "ℳ", phone: "☎", Pi: "Π", pi: "π", pitchfork: "⋔", piv: "ϖ", planck: "ℏ", planckh: "ℎ", plankv: "ℏ", plus: "+", plusacir: "⨣", plusb: "⊞", pluscir: "⨢", plusdo: "∔", plusdu: "⨥", pluse: "⩲", PlusMinus: "±", plusmn: "±", plussim: "⨦", plustwo: "⨧", pm: "±", Poincareplane: "ℌ", pointint: "⨕", Popf: "ℙ", popf: "𝕡", pound: "£", Pr: "⪻", pr: "≺", prap: "⪷", prcue: "≼", prE: "⪳", pre: "⪯", prec: "≺", precapprox: "⪷", preccurlyeq: "≼", Precedes: "≺", PrecedesEqual: "⪯", PrecedesSlantEqual: "≼", PrecedesTilde: "≾", preceq: "⪯", precnapprox: "⪹", precneqq: "⪵", precnsim: "⋨", precsim: "≾", Prime: "″", prime: "′", primes: "ℙ", prnap: "⪹", prnE: "⪵", prnsim: "⋨", prod: "∏", Product: "∏", profalar: "⌮", profline: "⌒", profsurf: "⌓", prop: "∝", Proportion: "∷", Proportional: "∝", propto: "∝", prsim: "≾", prurel: "⊰", Pscr: "𝒫", pscr: "𝓅", Psi: "Ψ", psi: "ψ", puncsp: " ", Qfr: "𝔔", qfr: "𝔮", qint: "⨌", Qopf: "ℚ", qopf: "𝕢", qprime: "⁗", Qscr: "𝒬", qscr: "𝓆", quaternions: "ℍ", quatint: "⨖", quest: "?", questeq: "≟", QUOT: "\"", quot: "\"", rAarr: "⇛", race: "∽̱", Racute: "Ŕ", racute: "ŕ", radic: "√", raemptyv: "⦳", Rang: "⟫", rang: "⟩", rangd: "⦒", range: "⦥", rangle: "⟩", raquo: "»", Rarr: "↠", rArr: "⇒", rarr: "→", rarrap: "⥵", rarrb: "⇥", rarrbfs: "⤠", rarrc: "⤳", rarrfs: "⤞", rarrhk: "↪", rarrlp: "↬", rarrpl: "⥅", rarrsim: "⥴", Rarrtl: "⤖", rarrtl: "↣", rarrw: "↝", rAtail: "⤜", ratail: "⤚", ratio: "∶", rationals: "ℚ", RBarr: "⤐", rBarr: "⤏", rbarr: "⤍", rbbrk: "❳", rbrace: "}", rbrack: "]", rbrke: "⦌", rbrksld: "⦎", rbrkslu: "⦐", Rcaron: "Ř", rcaron: "ř", Rcedil: "Ŗ", rcedil: "ŗ", rceil: "⌉", rcub: "}", Rcy: "Р", rcy: "р", rdca: "⤷", rdldhar: "⥩", rdquo: "”", rdquor: "”", rdsh: "↳", Re: "ℜ", real: "ℜ", realine: "ℛ", realpart: "ℜ", reals: "ℝ", rect: "▭", REG: "®", reg: "®", ReverseElement: "∋", ReverseEquilibrium: "⇋", ReverseUpEquilibrium: "⥯", rfisht: "⥽", rfloor: "⌋", Rfr: "ℜ", rfr: "𝔯", rHar: "⥤", rhard: "⇁", rharu: "⇀", rharul: "⥬", Rho: "Ρ", rho: "ρ", rhov: "ϱ", RightAngleBracket: "⟩", RightArrow: "→", Rightarrow: "⇒", rightarrow: "→", RightArrowBar: "⇥", RightArrowLeftArrow: "⇄", rightarrowtail: "↣", RightCeiling: "⌉", RightDoubleBracket: "⟧", RightDownTeeVector: "⥝", RightDownVector: "⇂", RightDownVectorBar: "⥕", RightFloor: "⌋", rightharpoondown: "⇁", rightharpoonup: "⇀", rightleftarrows: "⇄", rightleftharpoons: "⇌", rightrightarrows: "⇉", rightsquigarrow: "↝", RightTee: "⊢", RightTeeArrow: "↦", RightTeeVector: "⥛", rightthreetimes: "⋌", RightTriangle: "⊳", RightTriangleBar: "⧐", RightTriangleEqual: "⊵", RightUpDownVector: "⥏", RightUpTeeVector: "⥜", RightUpVector: "↾", RightUpVectorBar: "⥔", RightVector: "⇀", RightVectorBar: "⥓", ring: "˚", risingdotseq: "≓", rlarr: "⇄", rlhar: "⇌", rlm: "\u200f", rmoust: "⎱", rmoustache: "⎱", rnmid: "⫮", roang: "⟭", roarr: "⇾", robrk: "⟧", ropar: "⦆", Ropf: "ℝ", ropf: "𝕣", roplus: "⨮", rotimes: "⨵", RoundImplies: "⥰", rpar: ")", rpargt: "⦔", rppolint: "⨒", rrarr: "⇉", Rrightarrow: "⇛", rsaquo: "›", Rscr: "ℛ", rscr: "𝓇", Rsh: "↱", rsh: "↱", rsqb: "]", rsquo: "’", rsquor: "’", rthree: "⋌", rtimes: "⋊", rtri: "▹", rtrie: "⊵", rtrif: "▸", rtriltri: "⧎", RuleDelayed: "⧴", ruluhar: "⥨", rx: "℞", Sacute: "Ś", sacute: "ś", sbquo: "‚", Sc: "⪼", sc: "≻", scap: "⪸", Scaron: "Š", scaron: "š", sccue: "≽", scE: "⪴", sce: "⪰", Scedil: "Ş", scedil: "ş", Scirc: "Ŝ", scirc: "ŝ", scnap: "⪺", scnE: "⪶", scnsim: "⋩", scpolint: "⨓", scsim: "≿", Scy: "С", scy: "с", sdot: "⋅", sdotb: "⊡", sdote: "⩦", searhk: "⤥", seArr: "⇘", searr: "↘", searrow: "↘", sect: "§", semi: ";", seswar: "⤩", setminus: "∖", setmn: "∖", sext: "✶", Sfr: "𝔖", sfr: "𝔰", sfrown: "⌢", sharp: "♯", SHCHcy: "Щ", shchcy: "щ", SHcy: "Ш", shcy: "ш", ShortDownArrow: "↓", ShortLeftArrow: "←", shortmid: "∣", shortparallel: "∥", ShortRightArrow: "→", ShortUpArrow: "↑", shy: "\u00ad", Sigma: "Σ", sigma: "σ", sigmaf: "ς", sigmav: "ς", sim: "∼", simdot: "⩪", sime: "≃", simeq: "≃", simg: "⪞", simgE: "⪠", siml: "⪝", simlE: "⪟", simne: "≆", simplus: "⨤", simrarr: "⥲", slarr: "←", SmallCircle: "∘", smallsetminus: "∖", smashp: "⨳", smeparsl: "⧤", smid: "∣", smile: "⌣", smt: "⪪", smte: "⪬", smtes: "⪬︀", SOFTcy: "Ь", softcy: "ь", sol: "/", solb: "⧄", solbar: "⌿", Sopf: "𝕊", sopf: "𝕤", spades: "♠", spadesuit: "♠", spar: "∥", sqcap: "⊓", sqcaps: "⊓︀", sqcup: "⊔", sqcups: "⊔︀", Sqrt: "√", sqsub: "⊏", sqsube: "⊑", sqsubset: "⊏", sqsubseteq: "⊑", sqsup: "⊐", sqsupe: "⊒", sqsupset: "⊐", sqsupseteq: "⊒", squ: "□", Square: "□", square: "□", SquareIntersection: "⊓", SquareSubset: "⊏", SquareSubsetEqual: "⊑", SquareSuperset: "⊐", SquareSupersetEqual: "⊒", SquareUnion: "⊔", squarf: "▪", squf: "▪", srarr: "→", Sscr: "𝒮", sscr: "𝓈", ssetmn: "∖", ssmile: "⌣", sstarf: "⋆", Star: "⋆", star: "☆", starf: "★", straightepsilon: "ϵ", straightphi: "ϕ", strns: "¯", Sub: "⋐", sub: "⊂", subdot: "⪽", subE: "⫅", sube: "⊆", subedot: "⫃", submult: "⫁", subnE: "⫋", subne: "⊊", subplus: "⪿", subrarr: "⥹", Subset: "⋐", subset: "⊂", subseteq: "⊆", subseteqq: "⫅", SubsetEqual: "⊆", subsetneq: "⊊", subsetneqq: "⫋", subsim: "⫇", subsub: "⫕", subsup: "⫓", succ: "≻", succapprox: "⪸", succcurlyeq: "≽", Succeeds: "≻", SucceedsEqual: "⪰", SucceedsSlantEqual: "≽", SucceedsTilde: "≿", succeq: "⪰", succnapprox: "⪺", succneqq: "⪶", succnsim: "⋩", succsim: "≿", SuchThat: "∋", Sum: "∑", sum: "∑", sung: "♪", Sup: "⋑", sup: "⊃", sup1: "¹", sup2: "²", sup3: "³", supdot: "⪾", supdsub: "⫘", supE: "⫆", supe: "⊇", supedot: "⫄", Superset: "⊃", SupersetEqual: "⊇", suphsol: "⟉", suphsub: "⫗", suplarr: "⥻", supmult: "⫂", supnE: "⫌", supne: "⊋", supplus: "⫀", Supset: "⋑", supset: "⊃", supseteq: "⊇", supseteqq: "⫆", supsetneq: "⊋", supsetneqq: "⫌", supsim: "⫈", supsub: "⫔", supsup: "⫖", swarhk: "⤦", swArr: "⇙", swarr: "↙", swarrow: "↙", swnwar: "⤪", szlig: "ß", Tab: "\u0009", target: "⌖", Tau: "Τ", tau: "τ", tbrk: "⎴", Tcaron: "Ť", tcaron: "ť", Tcedil: "Ţ", tcedil: "ţ", Tcy: "Т", tcy: "т", tdot: "⃛", telrec: "⌕", Tfr: "𝔗", tfr: "𝔱", there4: "∴", Therefore: "∴", therefore: "∴", Theta: "Θ", theta: "θ", thetasym: "ϑ", thetav: "ϑ", thickapprox: "≈", thicksim: "∼", ThickSpace: "  ", thinsp: " ", ThinSpace: " ", thkap: "≈", thksim: "∼", THORN: "Þ", thorn: "þ", Tilde: "∼", tilde: "˜", TildeEqual: "≃", TildeFullEqual: "≅", TildeTilde: "≈", times: "×", timesb: "⊠", timesbar: "⨱", timesd: "⨰", tint: "∭", toea: "⤨", top: "⊤", topbot: "⌶", topcir: "⫱", Topf: "𝕋", topf: "𝕥", topfork: "⫚", tosa: "⤩", tprime: "‴", TRADE: "™", trade: "™", triangle: "▵", triangledown: "▿", triangleleft: "◃", trianglelefteq: "⊴", triangleq: "≜", triangleright: "▹", trianglerighteq: "⊵", tridot: "◬", trie: "≜", triminus: "⨺", TripleDot: "⃛", triplus: "⨹", trisb: "⧍", tritime: "⨻", trpezium: "⏢", Tscr: "𝒯", tscr: "𝓉", TScy: "Ц", tscy: "ц", TSHcy: "Ћ", tshcy: "ћ", Tstrok: "Ŧ", tstrok: "ŧ", twixt: "≬", twoheadleftarrow: "↞", twoheadrightarrow: "↠", Uacute: "Ú", uacute: "ú", Uarr: "↟", uArr: "⇑", uarr: "↑", Uarrocir: "⥉", Ubrcy: "Ў", ubrcy: "ў", Ubreve: "Ŭ", ubreve: "ŭ", Ucirc: "Û", ucirc: "û", Ucy: "У", ucy: "у", udarr: "⇅", Udblac: "Ű", udblac: "ű", udhar: "⥮", ufisht: "⥾", Ufr: "𝔘", ufr: "𝔲", Ugrave: "Ù", ugrave: "ù", uHar: "⥣", uharl: "↿", uharr: "↾", uhblk: "▀", ulcorn: "⌜", ulcorner: "⌜", ulcrop: "⌏", ultri: "◸", Umacr: "Ū", umacr: "ū", uml: "¨", UnderBar: "_", UnderBrace: "⏟", UnderBracket: "⎵", UnderParenthesis: "⏝", Union: "⋃", UnionPlus: "⊎", Uogon: "Ų", uogon: "ų", Uopf: "𝕌", uopf: "𝕦", UpArrow: "↑", Uparrow: "⇑", uparrow: "↑", UpArrowBar: "⤒", UpArrowDownArrow: "⇅", UpDownArrow: "↕", Updownarrow: "⇕", updownarrow: "↕", UpEquilibrium: "⥮", upharpoonleft: "↿", upharpoonright: "↾", uplus: "⊎", UpperLeftArrow: "↖", UpperRightArrow: "↗", Upsi: "ϒ", upsi: "υ", upsih: "ϒ", Upsilon: "Υ", upsilon: "υ", UpTee: "⊥", UpTeeArrow: "↥", upuparrows: "⇈", urcorn: "⌝", urcorner: "⌝", urcrop: "⌎", Uring: "Ů", uring: "ů", urtri: "◹", Uscr: "𝒰", uscr: "𝓊", utdot: "⋰", Utilde: "Ũ", utilde: "ũ", utri: "▵", utrif: "▴", uuarr: "⇈", Uuml: "Ü", uuml: "ü", uwangle: "⦧", vangrt: "⦜", varepsilon: "ϵ", varkappa: "ϰ", varnothing: "∅", varphi: "ϕ", varpi: "ϖ", varpropto: "∝", vArr: "⇕", varr: "↕", varrho: "ϱ", varsigma: "ς", varsubsetneq: "⊊︀", varsubsetneqq: "⫋︀", varsupsetneq: "⊋︀", varsupsetneqq: "⫌︀", vartheta: "ϑ", vartriangleleft: "⊲", vartriangleright: "⊳", Vbar: "⫫", vBar: "⫨", vBarv: "⫩", Vcy: "В", vcy: "в", VDash: "⊫", Vdash: "⊩", vDash: "⊨", vdash: "⊢", Vdashl: "⫦", Vee: "⋁", vee: "∨", veebar: "⊻", veeeq: "≚", vellip: "⋮", Verbar: "‖", verbar: "|", Vert: "‖", vert: "|", VerticalBar: "∣", VerticalLine: "|", VerticalSeparator: "❘", VerticalTilde: "≀", VeryThinSpace: " ", Vfr: "𝔙", vfr: "𝔳", vltri: "⊲", vnsub: "⊂⃒", vnsup: "⊃⃒", Vopf: "𝕍", vopf: "𝕧", vprop: "∝", vrtri: "⊳", Vscr: "𝒱", vscr: "𝓋", vsubnE: "⫋︀", vsubne: "⊊︀", vsupnE: "⫌︀", vsupne: "⊋︀", Vvdash: "⊪", vzigzag: "⦚", Wcirc: "Ŵ", wcirc: "ŵ", wedbar: "⩟", Wedge: "⋀", wedge: "∧", wedgeq: "≙", weierp: "℘", Wfr: "𝔚", wfr: "𝔴", Wopf: "𝕎", wopf: "𝕨", wp: "℘", wr: "≀", wreath: "≀", Wscr: "𝒲", wscr: "𝓌", xcap: "⋂", xcirc: "◯", xcup: "⋃", xdtri: "▽", Xfr: "𝔛", xfr: "𝔵", xhArr: "⟺", xharr: "⟷", Xi: "Ξ", xi: "ξ", xlArr: "⟸", xlarr: "⟵", xmap: "⟼", xnis: "⋻", xodot: "⨀", Xopf: "𝕏", xopf: "𝕩", xoplus: "⨁", xotime: "⨂", xrArr: "⟹", xrarr: "⟶", Xscr: "𝒳", xscr: "𝓍", xsqcup: "⨆", xuplus: "⨄", xutri: "△", xvee: "⋁", xwedge: "⋀", Yacute: "Ý", yacute: "ý", YAcy: "Я", yacy: "я", Ycirc: "Ŷ", ycirc: "ŷ", Ycy: "Ы", ycy: "ы", yen: "¥", Yfr: "𝔜", yfr: "𝔶", YIcy: "Ї", yicy: "ї", Yopf: "𝕐", yopf: "𝕪", Yscr: "𝒴", yscr: "𝓎", YUcy: "Ю", yucy: "ю", Yuml: "Ÿ", yuml: "ÿ", Zacute: "Ź", zacute: "ź", Zcaron: "Ž", zcaron: "ž", Zcy: "З", zcy: "з", Zdot: "Ż", zdot: "ż", zeetrf: "ℨ", ZeroWidthSpace: "​", Zeta: "Ζ", zeta: "ζ", Zfr: "ℨ", zfr: "𝔷", ZHcy: "Ж", zhcy: "ж", zigrarr: "⇝", Zopf: "ℤ", zopf: "𝕫", Zscr: "𝒵", zscr: "𝓏", zwj: "\u200d", zwnj: "\u200c" }; var HEXCHARCODE = /^#[xX]([A-Fa-f0-9]+)$/; var CHARCODE = /^#([0-9]+)$/; var NAMED = /^([A-Za-z0-9]+)$/; var EntityParser = function () { function EntityParser(named) { this.named = named; } EntityParser.prototype.parse = function (entity) { if (!entity) { return; } var matches = entity.match(HEXCHARCODE); if (matches) { return String.fromCharCode(parseInt(matches[1], 16)); } matches = entity.match(CHARCODE); if (matches) { return String.fromCharCode(parseInt(matches[1], 10)); } matches = entity.match(NAMED); if (matches) { return this.named[matches[1]]; } }; return EntityParser; }(); var WSP = /[\t\n\f ]/; var ALPHA = /[A-Za-z]/; var CRLF = /\r\n?/g; function isSpace(char) { return WSP.test(char); } function isAlpha(char) { return ALPHA.test(char); } function preprocessInput(input) { return input.replace(CRLF, "\n"); } var EventedTokenizer = function () { function EventedTokenizer(delegate, entityParser) { this.delegate = delegate; this.entityParser = entityParser; this.state = null; this.input = null; this.index = -1; this.tagLine = -1; this.tagColumn = -1; this.line = -1; this.column = -1; this.states = { beforeData: function () { var char = this.peek(); if (char === "<") { this.state = 'tagOpen'; this.markTagStart(); this.consume(); } else { this.state = 'data'; this.delegate.beginData(); } }, data: function () { var char = this.peek(); if (char === "<") { this.delegate.finishData(); this.state = 'tagOpen'; this.markTagStart(); this.consume(); } else if (char === "&") { this.consume(); this.delegate.appendToData(this.consumeCharRef() || "&"); } else { this.consume(); this.delegate.appendToData(char); } }, tagOpen: function () { var char = this.consume(); if (char === "!") { this.state = 'markupDeclaration'; } else if (char === "/") { this.state = 'endTagOpen'; } else if (isAlpha(char)) { this.state = 'tagName'; this.delegate.beginStartTag(); this.delegate.appendToTagName(char.toLowerCase()); } }, markupDeclaration: function () { var char = this.consume(); if (char === "-" && this.input.charAt(this.index) === "-") { this.consume(); this.state = 'commentStart'; this.delegate.beginComment(); } }, commentStart: function () { var char = this.consume(); if (char === "-") { this.state = 'commentStartDash'; } else if (char === ">") { this.delegate.finishComment(); this.state = 'beforeData'; } else { this.delegate.appendToCommentData(char); this.state = 'comment'; } }, commentStartDash: function () { var char = this.consume(); if (char === "-") { this.state = 'commentEnd'; } else if (char === ">") { this.delegate.finishComment(); this.state = 'beforeData'; } else { this.delegate.appendToCommentData("-"); this.state = 'comment'; } }, comment: function () { var char = this.consume(); if (char === "-") { this.state = 'commentEndDash'; } else { this.delegate.appendToCommentData(char); } }, commentEndDash: function () { var char = this.consume(); if (char === "-") { this.state = 'commentEnd'; } else { this.delegate.appendToCommentData("-" + char); this.state = 'comment'; } }, commentEnd: function () { var char = this.consume(); if (char === ">") { this.delegate.finishComment(); this.state = 'beforeData'; } else { this.delegate.appendToCommentData("--" + char); this.state = 'comment'; } }, tagName: function () { var char = this.consume(); if (isSpace(char)) { this.state = 'beforeAttributeName'; } else if (char === "/") { this.state = 'selfClosingStartTag'; } else if (char === ">") { this.delegate.finishTag(); this.state = 'beforeData'; } else { this.delegate.appendToTagName(char); } }, beforeAttributeName: function () { var char = this.peek(); if (isSpace(char)) { this.consume(); return; } else if (char === "/") { this.state = 'selfClosingStartTag'; this.consume(); } else if (char === ">") { this.consume(); this.delegate.finishTag(); this.state = 'beforeData'; } else if (char === '=') { this.delegate.reportSyntaxError("attribute name cannot start with equals sign"); this.state = 'attributeName'; this.delegate.beginAttribute(); this.consume(); this.delegate.appendToAttributeName(char); } else { this.state = 'attributeName'; this.delegate.beginAttribute(); } }, attributeName: function () { var char = this.peek(); if (isSpace(char)) { this.state = 'afterAttributeName'; this.consume(); } else if (char === "/") { this.delegate.beginAttributeValue(false); this.delegate.finishAttributeValue(); this.consume(); this.state = 'selfClosingStartTag'; } else if (char === "=") { this.state = 'beforeAttributeValue'; this.consume(); } else if (char === ">") { this.delegate.beginAttributeValue(false); this.delegate.finishAttributeValue(); this.consume(); this.delegate.finishTag(); this.state = 'beforeData'; } else if (char === '"' || char === "'" || char === '<') { this.delegate.reportSyntaxError(char + " is not a valid character within attribute names"); this.consume(); this.delegate.appendToAttributeName(char); } else { this.consume(); this.delegate.appendToAttributeName(char); } }, afterAttributeName: function () { var char = this.peek(); if (isSpace(char)) { this.consume(); return; } else if (char === "/") { this.delegate.beginAttributeValue(false); this.delegate.finishAttributeValue(); this.consume(); this.state = 'selfClosingStartTag'; } else if (char === "=") { this.consume(); this.state = 'beforeAttributeValue'; } else if (char === ">") { this.delegate.beginAttributeValue(false); this.delegate.finishAttributeValue(); this.consume(); this.delegate.finishTag(); this.state = 'beforeData'; } else { this.delegate.beginAttributeValue(false); this.delegate.finishAttributeValue(); this.consume(); this.state = 'attributeName'; this.delegate.beginAttribute(); this.delegate.appendToAttributeName(char); } }, beforeAttributeValue: function () { var char = this.peek(); if (isSpace(char)) { this.consume(); } else if (char === '"') { this.state = 'attributeValueDoubleQuoted'; this.delegate.beginAttributeValue(true); this.consume(); } else if (char === "'") { this.state = 'attributeValueSingleQuoted'; this.delegate.beginAttributeValue(true); this.consume(); } else if (char === ">") { this.delegate.beginAttributeValue(false); this.delegate.finishAttributeValue(); this.consume(); this.delegate.finishTag(); this.state = 'beforeData'; } else { this.state = 'attributeValueUnquoted'; this.delegate.beginAttributeValue(false); this.consume(); this.delegate.appendToAttributeValue(char); } }, attributeValueDoubleQuoted: function () { var char = this.consume(); if (char === '"') { this.delegate.finishAttributeValue(); this.state = 'afterAttributeValueQuoted'; } else if (char === "&") { this.delegate.appendToAttributeValue(this.consumeCharRef('"') || "&"); } else { this.delegate.appendToAttributeValue(char); } }, attributeValueSingleQuoted: function () { var char = this.consume(); if (char === "'") { this.delegate.finishAttributeValue(); this.state = 'afterAttributeValueQuoted'; } else if (char === "&") { this.delegate.appendToAttributeValue(this.consumeCharRef("'") || "&"); } else { this.delegate.appendToAttributeValue(char); } }, attributeValueUnquoted: function () { var char = this.peek(); if (isSpace(char)) { this.delegate.finishAttributeValue(); this.consume(); this.state = 'beforeAttributeName'; } else if (char === "&") { this.consume(); this.delegate.appendToAttributeValue(this.consumeCharRef(">") || "&"); } else if (char === ">") { this.delegate.finishAttributeValue(); this.consume(); this.delegate.finishTag(); this.state = 'beforeData'; } else { this.consume(); this.delegate.appendToAttributeValue(char); } }, afterAttributeValueQuoted: function () { var char = this.peek(); if (isSpace(char)) { this.consume(); this.state = 'beforeAttributeName'; } else if (char === "/") { this.consume(); this.state = 'selfClosingStartTag'; } else if (char === ">") { this.consume(); this.delegate.finishTag(); this.state = 'beforeData'; } else { this.state = 'beforeAttributeName'; } }, selfClosingStartTag: function () { var char = this.peek(); if (char === ">") { this.consume(); this.delegate.markTagAsSelfClosing(); this.delegate.finishTag(); this.state = 'beforeData'; } else { this.state = 'beforeAttributeName'; } }, endTagOpen: function () { var char = this.consume(); if (isAlpha(char)) { this.state = 'tagName'; this.delegate.beginEndTag(); this.delegate.appendToTagName(char.toLowerCase()); } } }; this.reset(); } EventedTokenizer.prototype.reset = function () { this.state = 'beforeData'; this.input = ''; this.index = 0; this.line = 1; this.column = 0; this.tagLine = -1; this.tagColumn = -1; this.delegate.reset(); }; EventedTokenizer.prototype.tokenize = function (input) { this.reset(); this.tokenizePart(input); this.tokenizeEOF(); }; EventedTokenizer.prototype.tokenizePart = function (input) { this.input += preprocessInput(input); while (this.index < this.input.length) { this.states[this.state].call(this); } }; EventedTokenizer.prototype.tokenizeEOF = function () { this.flushData(); }; EventedTokenizer.prototype.flushData = function () { if (this.state === 'data') { this.delegate.finishData(); this.state = 'beforeData'; } }; EventedTokenizer.prototype.peek = function () { return this.input.charAt(this.index); }; EventedTokenizer.prototype.consume = function () { var char = this.peek(); this.index++; if (char === "\n") { this.line++; this.column = 0; } else { this.column++; } return char; }; EventedTokenizer.prototype.consumeCharRef = function () { var endIndex = this.input.indexOf(';', this.index); if (endIndex === -1) { return; } var entity = this.input.slice(this.index, endIndex); var chars = this.entityParser.parse(entity); if (chars) { var count = entity.length; // consume the entity chars while (count) { this.consume(); count--; } // consume the `;` this.consume(); return chars; } }; EventedTokenizer.prototype.markTagStart = function () { // these properties to be removed in next major bump this.tagLine = this.line; this.tagColumn = this.column; if (this.delegate.tagOpen) { this.delegate.tagOpen(); } }; return EventedTokenizer; }(); var Tokenizer = function () { function Tokenizer(entityParser, options) { if (options === void 0) { options = {}; } this.options = options; this.token = null; this.startLine = 1; this.startColumn = 0; this.tokens = []; this.currentAttribute = null; this.tokenizer = new EventedTokenizer(this, entityParser); } Tokenizer.prototype.tokenize = function (input) { this.tokens = []; this.tokenizer.tokenize(input); return this.tokens; }; Tokenizer.prototype.tokenizePart = function (input) { this.tokens = []; this.tokenizer.tokenizePart(input); return this.tokens; }; Tokenizer.prototype.tokenizeEOF = function () { this.tokens = []; this.tokenizer.tokenizeEOF(); return this.tokens[0]; }; Tokenizer.prototype.reset = function () { this.token = null; this.startLine = 1; this.startColumn = 0; }; Tokenizer.prototype.addLocInfo = function () { if (this.options.loc) { this.token.loc = { start: { line: this.startLine, column: this.startColumn }, end: { line: this.tokenizer.line, column: this.tokenizer.column } }; } this.startLine = this.tokenizer.line; this.startColumn = this.tokenizer.column; }; // Data Tokenizer.prototype.beginData = function () { this.token = { type: 'Chars', chars: '' }; this.tokens.push(this.token); }; Tokenizer.prototype.appendToData = function (char) { this.token.chars += char; }; Tokenizer.prototype.finishData = function () { this.addLocInfo(); }; // Comment Tokenizer.prototype.beginComment = function () { this.token = { type: 'Comment', chars: '' }; this.tokens.push(this.token); }; Tokenizer.prototype.appendToCommentData = function (char) { this.token.chars += char; }; Tokenizer.prototype.finishComment = function () { this.addLocInfo(); }; // Tags - basic Tokenizer.prototype.beginStartTag = function () { this.token = { type: 'StartTag', tagName: '', attributes: [], selfClosing: false }; this.tokens.push(this.token); }; Tokenizer.prototype.beginEndTag = function () { this.token = { type: 'EndTag', tagName: '' }; this.tokens.push(this.token); }; Tokenizer.prototype.finishTag = function () { this.addLocInfo(); }; Tokenizer.prototype.markTagAsSelfClosing = function () { this.token.selfClosing = true; }; // Tags - name Tokenizer.prototype.appendToTagName = function (char) { this.token.tagName += char; }; // Tags - attributes Tokenizer.prototype.beginAttribute = function () { this.currentAttribute = ["", "", null]; this.token.attributes.push(this.currentAttribute); }; Tokenizer.prototype.appendToAttributeName = function (char) { this.currentAttribute[0] += char; }; Tokenizer.prototype.beginAttributeValue = function (isQuoted) { this.currentAttribute[2] = isQuoted; }; Tokenizer.prototype.appendToAttributeValue = function (char) { this.currentAttribute[1] = this.currentAttribute[1] || ""; this.currentAttribute[1] += char; }; Tokenizer.prototype.finishAttributeValue = function () {}; Tokenizer.prototype.reportSyntaxError = function (message) { this.token.syntaxError = message; }; return Tokenizer; }(); function tokenize(input, options) { var tokenizer = new Tokenizer(new EntityParser(namedCharRefs), options); return tokenizer.tokenize(input); } exports.HTML5NamedCharRefs = namedCharRefs; exports.EntityParser = EntityParser; exports.EventedTokenizer = EventedTokenizer; exports.Tokenizer = Tokenizer; exports.tokenize = tokenize; }); }()); //# sourceMappingURL=ember-tests.prod.map