(function() {
/*!
* @overview Ember - JavaScript Application Framework
* @copyright Copyright 2011-2018 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 3.8.0
*/
/*globals process */
var enifed, requireModule, Ember;
// Used in @ember/-internals/environment/lib/global.js
mainContext = this; // eslint-disable-line no-undef
(function() {
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;
}
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 = Object.create(null);
var seen = Object.create(null);
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 Boolean(registry[moduleName]) || Boolean(registry[moduleName + '/index']);
};
requireModule._eak_seen = registry;
Ember.__loader = {
define: enifed,
require: requireModule,
registry: registry,
};
} else {
enifed = Ember.__loader.define;
requireModule = Ember.__loader.require;
}
})();
enifed("@ember/-internals/container/tests/container_test", ["ember-babel", "@ember/-internals/owner", "@ember/polyfills", "@ember/-internals/container", "internal-test-helpers"], function (_emberBabel, _owner, _polyfills, _container, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Container',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test A registered factory returns the same instance each time'] = function testARegisteredFactoryReturnsTheSameInstanceEachTime(assert) {
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');
assert.ok(postController instanceof PostController, 'The lookup is an instance of the factory');
assert.equal(postController, container.lookup('controller:post'));
};
_proto['@test uses create time injections if factory has no extend'] = function testUsesCreateTimeInjectionsIfFactoryHasNoExtend(assert) {
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');
assert.ok(postController.apple instanceof AppleController, 'instance receives an apple of instance AppleController');
};
_proto['@test A registered factory returns a fresh instance if singleton: false is passed as an option'] = function testARegisteredFactoryReturnsAFreshInstanceIfSingletonFalseIsPassedAsAnOption(assert) {
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');
assert.equal(postController1.toString(), postController4.toString(), 'Singleton factories looked up normally return the same value');
assert.notEqual(postController1.toString(), postController2.toString(), 'Singleton factories are not equal to factories looked up with singleton: false');
assert.notEqual(postController2.toString(), postController3.toString(), 'Two factories looked up with singleton: false are not equal');
assert.notEqual(postController3.toString(), postController4.toString(), 'A singleton factory looked up after a factory called with singleton: false is not equal');
assert.ok(postController1 instanceof PostController, 'All instances are instances of the registered factory');
assert.ok(postController2 instanceof PostController, 'All instances are instances of the registered factory');
assert.ok(postController3 instanceof PostController, 'All instances are instances of the registered factory');
assert.ok(postController4 instanceof PostController, 'All instances are instances of the registered factory');
};
_proto["@test A factory type with a registered injection's instances receive that injection"] = function testAFactoryTypeWithARegisteredInjectionSInstancesReceiveThatInjection(assert) {
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');
assert.equal(postController.store, store);
};
_proto['@test An individual factory with a registered injection receives the injection'] = function testAnIndividualFactoryWithARegisteredInjectionReceivesTheInjection(assert) {
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');
assert.equal(postController.store, store, 'has the correct store injected');
};
_proto['@test A factory with both type and individual injections'] = function testAFactoryWithBothTypeAndIndividualInjections(assert) {
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');
assert.equal(postController.store, store);
assert.equal(postController.router, router);
};
_proto['@test A non-singleton instance is never cached'] = function testANonSingletonInstanceIsNeverCached(assert) {
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');
assert.ok(postView1 !== postView2, 'Non-singletons are not cached');
};
_proto['@test A non-instantiated property is not instantiated'] = function testANonInstantiatedPropertyIsNotInstantiated(assert) {
var registry = new _container.Registry();
var container = registry.container();
var template = function () {};
registry.register('template:foo', template, {
instantiate: false
});
assert.equal(container.lookup('template:foo'), template);
};
_proto['@test A failed lookup returns undefined'] = function testAFailedLookupReturnsUndefined(assert) {
var registry = new _container.Registry();
var container = registry.container();
assert.equal(container.lookup('doesnot:exist'), undefined);
};
_proto['@test An invalid factory throws an error'] = function testAnInvalidFactoryThrowsAnError(assert) {
var registry = new _container.Registry();
var container = registry.container();
registry.register('controller:foo', {});
assert.throws(function () {
container.lookup('controller:foo');
}, /Failed to create an instance of \'controller:foo\'/);
};
_proto['@test Injecting a failed lookup raises an error'] = function testInjectingAFailedLookupRaisesAnError(assert) {
var registry = new _container.Registry();
var container = registry.container();
var fooInstance = {};
var fooFactory = {};
var Foo = {
create: function () {
return fooInstance;
},
extend: function () {
return fooFactory;
}
};
registry.register('model:foo', Foo);
registry.injection('model:foo', 'store', 'store:main');
assert.throws(function () {
container.lookup('model:foo');
});
};
_proto['@test Injecting a falsy value does not raise an error'] = function testInjectingAFalsyValueDoesNotRaiseAnError(assert) {
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');
assert.strictEqual(container.lookup('controller:application').currentUser, null);
};
_proto['@test The container returns same value each time even if the value is falsy'] = function testTheContainerReturnsSameValueEachTimeEvenIfTheValueIsFalsy(assert) {
var registry = new _container.Registry();
var container = registry.container();
registry.register('falsy:value', null, {
instantiate: false
});
assert.strictEqual(container.lookup('falsy:value'), container.lookup('falsy:value'));
};
_proto['@test Destroying the container destroys any cached singletons'] = function testDestroyingTheContainerDestroysAnyCachedSingletons(assert) {
var registry = new _container.Registry();
var container = registry.container();
var PostController = (0, _internalTestHelpers.factory)();
var PostView = (0, _internalTestHelpers.factory)();
var template = function () {};
registry.register('controller:post', PostController);
registry.register('view:post', PostView, {
singleton: false
});
registry.register('template:post', template, {
instantiate: false
});
registry.injection('controller:post', 'postView', 'view:post');
var postController = container.lookup('controller:post');
var postView = postController.postView;
assert.ok(postView instanceof PostView, 'The non-singleton was injected');
container.destroy();
assert.ok(postController.isDestroyed, 'Singletons are destroyed');
assert.ok(!postView.isDestroyed, 'Non-singletons are not destroyed');
};
_proto['@test The container can use a registry hook to resolve factories lazily'] = function testTheContainerCanUseARegistryHookToResolveFactoriesLazily(assert) {
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');
assert.ok(postController instanceof PostController, 'The correct factory was provided');
};
_proto['@test The container normalizes names before resolving'] = function testTheContainerNormalizesNamesBeforeResolving(assert) {
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');
assert.ok(postController instanceof PostController, 'Normalizes the name before resolving');
};
_proto['@test The container normalizes names when looking factory up'] = function testTheContainerNormalizesNamesWhenLookingFactoryUp(assert) {
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 = container.factoryFor('controller:normalized');
var factInstance = fact.create();
assert.ok(factInstance instanceof PostController, 'Normalizes the name');
};
_proto['@test Options can be registered that should be applied to a given factory'] = function testOptionsCanBeRegisteredThatShouldBeAppliedToAGivenFactory(assert) {
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');
assert.ok(postView1 instanceof PostView, 'The correct factory was provided');
assert.ok(postView2 instanceof PostView, 'The correct factory was provided');
assert.ok(postView1 !== postView2, 'The two lookups are different');
};
_proto['@test Options can be registered that should be applied to all factories for a given type'] = function testOptionsCanBeRegisteredThatShouldBeAppliedToAllFactoriesForAGivenType(assert) {
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');
assert.ok(postView1 instanceof PostView, 'The correct factory was provided');
assert.ok(postView2 instanceof PostView, 'The correct factory was provided');
assert.ok(postView1 !== postView2, 'The two lookups are different');
};
_proto['@test An injected non-singleton instance is never cached'] = function testAnInjectedNonSingletonInstanceIsNeverCached(assert) {
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');
assert.ok(postView1.viewHelper !== postView2.viewHelper, 'Injected non-singletons are not cached');
};
_proto['@test Factory resolves are cached'] = function testFactoryResolvesAreCached(assert) {
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;
};
assert.deepEqual(resolveWasCalled, []);
container.factoryFor('controller:post');
assert.deepEqual(resolveWasCalled, ['controller:post']);
container.factoryFor('controller:post');
assert.deepEqual(resolveWasCalled, ['controller:post']);
};
_proto['@test factory for non extendables (MODEL) resolves are cached'] = function testFactoryForNonExtendablesMODELResolvesAreCached(assert) {
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;
};
assert.deepEqual(resolveWasCalled, []);
container.factoryFor('model:post');
assert.deepEqual(resolveWasCalled, ['model:post']);
container.factoryFor('model:post');
assert.deepEqual(resolveWasCalled, ['model:post']);
};
_proto['@test factory for non extendables resolves are cached'] = function testFactoryForNonExtendablesResolvesAreCached(assert) {
var registry = new _container.Registry();
var container = registry.container();
var PostController = {};
var resolveWasCalled = [];
registry.resolve = function (fullName) {
resolveWasCalled.push(fullName);
return PostController;
};
assert.deepEqual(resolveWasCalled, []);
container.factoryFor('foo:post');
assert.deepEqual(resolveWasCalled, ['foo:post']);
container.factoryFor('foo:post');
assert.deepEqual(resolveWasCalled, ['foo:post']);
};
_proto["@test A factory's lazy injections are validated when first instantiated"] = function (assert) {
var registry = new _container.Registry();
var container = registry.container();
var Apple = (0, _internalTestHelpers.factory)();
var Orange = (0, _internalTestHelpers.factory)();
Apple.reopenClass({
_lazyInjections: function () {
return [{
specifier: 'orange:main'
}, {
specifier: 'banana:main'
}];
}
});
registry.register('apple:main', Apple);
registry.register('orange:main', Orange);
assert.throws(function () {
container.lookup('apple:main');
}, /Attempting to inject an unknown injection: 'banana:main'/);
};
_proto['@test Lazy injection validations are cached'] = function testLazyInjectionValidationsAreCached(assert) {
assert.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 () {
assert.ok(true, 'should call lazy injection method');
return [{
specifier: 'orange:main'
}];
}
});
registry.register('apple:main', Apple);
registry.register('orange:main', Orange);
container.lookup('apple:main');
container.lookup('apple:main');
};
_proto['@test An object with its owner pre-set should be returned from ownerInjection'] = function testAnObjectWithItsOwnerPreSetShouldBeReturnedFromOwnerInjection(assert) {
var owner = {};
var registry = new _container.Registry();
var container = registry.container({
owner: owner
});
var result = container.ownerInjection();
assert.equal(result[_owner.OWNER], owner, 'owner is properly included');
};
_proto['@test lookup passes options through to expandlocallookup'] = function testLookupPassesOptionsThroughToExpandlocallookup(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);
};
_proto['@test #factoryFor class is registered class'] = function testFactoryForClassIsRegisteredClass(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');
};
_proto['@test #factoryFor must supply a fullname'] = function testFactoryForMustSupplyAFullname() {
var registry = new _container.Registry();
var container = registry.container();
expectAssertion(function () {
container.factoryFor('chad-bar');
}, /fullName must be a proper full name/);
};
_proto['@test #factoryFor returns a factory manager'] = function testFactoryForReturnsAFactoryManager(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);
};
_proto['@test #factoryFor returns a cached factory manager for the same type'] = function testFactoryForReturnsACachedFactoryManagerForTheSameType(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');
};
_proto['@test #factoryFor class returns the factory function'] = function testFactoryForClassReturnsTheFactoryFunction(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');
};
_proto['@test #factoryFor instance have a common parent'] = function testFactoryForInstanceHaveACommonParent(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);
};
_proto['@test can properly reset cache'] = function testCanProperlyResetCache(assert) {
var registry = new _container.Registry();
var container = registry.container();
var Component = (0, _internalTestHelpers.factory)();
registry.register('component:foo-bar', Component);
var factory1 = container.factoryFor('component:foo-bar');
var factory2 = container.factoryFor('component:foo-bar');
var instance1 = container.lookup('component:foo-bar');
var instance2 = container.lookup('component:foo-bar');
assert.equal(instance1, instance2);
assert.equal(factory1, factory2);
container.reset();
var factory3 = container.factoryFor('component:foo-bar');
var instance3 = container.lookup('component:foo-bar');
assert.notEqual(instance1, instance3);
assert.notEqual(factory1, factory3);
};
_proto['@test #factoryFor created instances come with instance injections'] = function testFactoryForCreatedInstancesComeWithInstanceInjections(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);
};
_proto['@test #factoryFor options passed to create clobber injections'] = function testFactoryForOptionsPassedToCreateClobberInjections(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');
};
_proto['@test #factoryFor does not add properties to the object being instantiated when _initFactory is present'] = function testFactoryForDoesNotAddPropertiesToTheObjectBeingInstantiatedWhen_initFactoryIsPresent(assert) {
var registry = new _container.Registry();
var container = registry.container();
var Component =
/*#__PURE__*/
function () {
function Component() {}
Component._initFactory = function _initFactory() {};
Component.create = function create(options) {
var instance = new this();
(0, _polyfills.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), []);
};
_proto["@test assert when calling lookup after destroy on a container"] = function (assert) {
var registry = new _container.Registry();
var container = registry.container();
var Component = (0, _internalTestHelpers.factory)();
registry.register('component:foo-bar', Component);
var instance = container.lookup('component:foo-bar');
assert.ok(instance, 'precond lookup successful');
(0, _internalTestHelpers.runTask)(function () {
container.destroy();
container.finalizeDestroy();
});
expectAssertion(function () {
container.lookup('component:foo-bar');
});
};
_proto["@test assert when calling factoryFor after destroy on a container"] = function (assert) {
var registry = new _container.Registry();
var container = registry.container();
var Component = (0, _internalTestHelpers.factory)();
registry.register('component:foo-bar', Component);
var instance = container.factoryFor('component:foo-bar');
assert.ok(instance, 'precond lookup successful');
(0, _internalTestHelpers.runTask)(function () {
container.destroy();
container.finalizeDestroy();
});
expectAssertion(function () {
container.factoryFor('component:foo-bar');
});
} // this is skipped until templates and the glimmer environment do not require `OWNER` to be
// passed in as constructor args
;
_proto['@skip #factoryFor does not add properties to the object being instantiated'] = function skipFactoryForDoesNotAddPropertiesToTheObjectBeingInstantiated(assert) {
var registry = new _container.Registry();
var container = registry.container();
var Component =
/*#__PURE__*/
function () {
function Component() {}
Component.create = function create(options) {
var instance = new this();
(0, _polyfills.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), []);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
if (false
/* EMBER_MODULE_UNIFICATION */
) {
(0, _internalTestHelpers.moduleFor)('Container module unification',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test The container can expand and resolve a source to factoryFor'] = function testTheContainerCanExpandAndResolveASourceToFactoryFor(assert) {
var _this = this;
var PrivateComponent = (0, _internalTestHelpers.factory)();
var lookup = 'component:my-input';
var expectedSource = 'template:routes/application';
var registry = new _container.Registry();
var resolveCount = 0;
var expandedKey = 'boom, special expanded key';
registry.expandLocalLookup = function (specifier, options) {
_this.assert.strictEqual(specifier, lookup, 'specifier is expanded');
_this.assert.strictEqual(options.source, expectedSource, 'source is expanded');
return expandedKey;
};
registry.resolve = function (fullName) {
resolveCount++;
if (fullName === expandedKey) {
return PrivateComponent;
}
};
var container = registry.container();
assert.strictEqual(container.factoryFor(lookup, {
source: expectedSource
}).class, PrivateComponent, 'The correct factory was provided');
assert.strictEqual(container.factoryFor(lookup, {
source: expectedSource
}).class, PrivateComponent, 'The correct factory was provided again');
assert.equal(resolveCount, 1, 'resolve called only once and a cached factory was returned the second time');
};
_proto2['@test The container can expand and resolve a source to lookup'] = function testTheContainerCanExpandAndResolveASourceToLookup() {
var _this2 = this;
var PrivateComponent = (0, _internalTestHelpers.factory)();
var lookup = 'component:my-input';
var expectedSource = 'template:routes/application';
var registry = new _container.Registry();
var expandedKey = 'boom, special expanded key';
registry.expandLocalLookup = function (specifier, options) {
_this2.assert.strictEqual(specifier, lookup, 'specifier is expanded');
_this2.assert.strictEqual(options.source, expectedSource, 'source is expanded');
return expandedKey;
};
registry.resolve = function (fullName) {
if (fullName === expandedKey) {
return PrivateComponent;
}
};
var container = registry.container();
var result = container.lookup(lookup, {
source: expectedSource
});
this.assert.ok(result instanceof PrivateComponent, 'The correct factory was provided');
this.assert.ok(container.cache[expandedKey] instanceof PrivateComponent, 'The correct factory was stored in the cache with the correct key which includes the source.');
};
_proto2['@test The container can expand and resolve a namespace to factoryFor'] = function testTheContainerCanExpandAndResolveANamespaceToFactoryFor(assert) {
var _this3 = this;
var PrivateComponent = (0, _internalTestHelpers.factory)();
var lookup = 'component:my-input';
var expectedNamespace = 'my-addon';
var registry = new _container.Registry();
var resolveCount = 0;
var expandedKey = 'boom, special expanded key';
registry.expandLocalLookup = function (specifier, options) {
_this3.assert.strictEqual(specifier, lookup, 'specifier is expanded');
_this3.assert.strictEqual(options.namespace, expectedNamespace, 'namespace is expanded');
return expandedKey;
};
registry.resolve = function (fullName) {
resolveCount++;
if (fullName === expandedKey) {
return PrivateComponent;
}
};
var container = registry.container();
assert.strictEqual(container.factoryFor(lookup, {
namespace: expectedNamespace
}).class, PrivateComponent, 'The correct factory was provided');
assert.strictEqual(container.factoryFor(lookup, {
namespace: expectedNamespace
}).class, PrivateComponent, 'The correct factory was provided again');
assert.equal(resolveCount, 1, 'resolve called only once and a cached factory was returned the second time');
};
_proto2['@test The container can expand and resolve a namespace to lookup'] = function testTheContainerCanExpandAndResolveANamespaceToLookup() {
var _this4 = this;
var PrivateComponent = (0, _internalTestHelpers.factory)();
var lookup = 'component:my-input';
var expectedNamespace = 'my-addon';
var registry = new _container.Registry();
var expandedKey = 'boom, special expanded key';
registry.expandLocalLookup = function (specifier, options) {
_this4.assert.strictEqual(specifier, lookup, 'specifier is expanded');
_this4.assert.strictEqual(options.namespace, expectedNamespace, 'namespace is expanded');
return expandedKey;
};
registry.resolve = function (fullName) {
if (fullName === expandedKey) {
return PrivateComponent;
}
};
var container = registry.container();
var result = container.lookup(lookup, {
namespace: expectedNamespace
});
this.assert.ok(result instanceof PrivateComponent, 'The correct factory was provided');
this.assert.ok(container.cache[expandedKey] instanceof PrivateComponent, 'The correct factory was stored in the cache with the correct key which includes the source.');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
}
});
enifed("@ember/-internals/container/tests/owner_test", ["ember-babel", "@ember/-internals/owner", "internal-test-helpers"], function (_emberBabel, _owner, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Owner',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test An owner can be set with `setOwner` and retrieved with `getOwner`'] = function testAnOwnerCanBeSetWithSetOwnerAndRetrievedWithGetOwner(assert) {
var owner = {};
var obj = {};
assert.strictEqual((0, _owner.getOwner)(obj), undefined, 'owner has not been set');
(0, _owner.setOwner)(obj, owner);
assert.strictEqual((0, _owner.getOwner)(obj), owner, 'owner has been set');
assert.strictEqual(obj[_owner.OWNER], owner, 'owner has been set to the OWNER symbol');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/container/tests/registry_test", ["ember-babel", "@ember/-internals/container", "internal-test-helpers"], function (_emberBabel, _container, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Registry',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test A registered factory is returned from resolve'] = function testARegisteredFactoryIsReturnedFromResolve(assert) {
var registry = new _container.Registry();
var PostController = (0, _internalTestHelpers.factory)();
registry.register('controller:post', PostController);
var PostControllerFactory = registry.resolve('controller:post');
assert.ok(PostControllerFactory, 'factory is returned');
assert.ok(PostControllerFactory.create() instanceof PostController, 'The return of factory.create is an instance of PostController');
};
_proto['@test The registered factory returned from resolve is the same factory each time'] = function testTheRegisteredFactoryReturnedFromResolveIsTheSameFactoryEachTime(assert) {
var registry = new _container.Registry();
var PostController = (0, _internalTestHelpers.factory)();
registry.register('controller:post', PostController);
assert.deepEqual(registry.resolve('controller:post'), registry.resolve('controller:post'), 'The return of resolve is always the same');
};
_proto['@test The registered value returned from resolve is the same value each time even if the value is falsy'] = function testTheRegisteredValueReturnedFromResolveIsTheSameValueEachTimeEvenIfTheValueIsFalsy(assert) {
var registry = new _container.Registry();
registry.register('falsy:value', null, {
instantiate: false
});
assert.strictEqual(registry.resolve('falsy:value'), registry.resolve('falsy:value'), 'The return of resolve is always the same');
};
_proto['@test The value returned from resolver is the same value as the original value even if the value is falsy'] = function testTheValueReturnedFromResolverIsTheSameValueAsTheOriginalValueEvenIfTheValueIsFalsy(assert) {
var resolver = {
resolve: function (fullName) {
if (fullName === 'falsy:value') {
return null;
}
}
};
var registry = new _container.Registry({
resolver: resolver
});
assert.strictEqual(registry.resolve('falsy:value'), null);
};
_proto['@test A registered factory returns true for `has` if an item is registered'] = function testARegisteredFactoryReturnsTrueForHasIfAnItemIsRegistered(assert) {
var registry = new _container.Registry();
var PostController = (0, _internalTestHelpers.factory)();
registry.register('controller:post', PostController);
assert.equal(registry.has('controller:post'), true, 'The `has` method returned true for registered factories');
assert.equal(registry.has('controller:posts'), false, 'The `has` method returned false for unregistered factories');
};
_proto['@test Throw exception when trying to inject `type:thing` on all type(s)'] = function testThrowExceptionWhenTryingToInjectTypeThingOnAllTypeS() {
var registry = new _container.Registry();
var PostController = (0, _internalTestHelpers.factory)();
registry.register('controller:post', PostController);
expectAssertion(function () {
registry.typeInjection('controller', 'injected', 'controller:post');
}, /Cannot inject a 'controller:post' on other controller\(s\)\./);
};
_proto['@test The registry can take a hook to resolve factories lazily'] = function testTheRegistryCanTakeAHookToResolveFactoriesLazily(assert) {
var PostController = (0, _internalTestHelpers.factory)();
var resolver = {
resolve: function (fullName) {
if (fullName === 'controller:post') {
return PostController;
}
}
};
var registry = new _container.Registry({
resolver: resolver
});
assert.strictEqual(registry.resolve('controller:post'), PostController, 'The correct factory was provided');
};
_proto['@test The registry respects the resolver hook for `has`'] = function testTheRegistryRespectsTheResolverHookForHas(assert) {
var PostController = (0, _internalTestHelpers.factory)();
var resolver = {
resolve: function (fullName) {
if (fullName === 'controller:post') {
return PostController;
}
}
};
var registry = new _container.Registry({
resolver: resolver
});
assert.ok(registry.has('controller:post'), 'the `has` method uses the resolver hook');
};
_proto['@test The registry normalizes names when resolving'] = function testTheRegistryNormalizesNamesWhenResolving(assert) {
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');
assert.strictEqual(type, PostController, 'Normalizes the name when resolving');
};
_proto['@test The registry normalizes names when checking if the factory is registered'] = function testTheRegistryNormalizesNamesWhenCheckingIfTheFactoryIsRegistered(assert) {
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');
assert.equal(isPresent, true, 'Normalizes the name when checking if the factory or instance is present');
};
_proto['@test The registry normalizes names when injecting'] = function testTheRegistryNormalizesNamesWhenInjecting(assert) {
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');
assert.deepEqual(registry.resolve('controller:post'), user, 'Normalizes the name when injecting');
};
_proto['@test cannot register an `undefined` factory'] = function testCannotRegisterAnUndefinedFactory(assert) {
var registry = new _container.Registry();
assert.throws(function () {
registry.register('controller:apple', undefined);
}, '');
};
_proto['@test can re-register a factory'] = function testCanReRegisterAFactory(assert) {
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);
assert.ok(registry.resolve('controller:apple').create() instanceof SecondApple);
};
_proto['@test cannot re-register a factory if it has been resolved'] = function testCannotReRegisterAFactoryIfItHasBeenResolved(assert) {
var registry = new _container.Registry();
var FirstApple = (0, _internalTestHelpers.factory)('first');
var SecondApple = (0, _internalTestHelpers.factory)('second');
registry.register('controller:apple', FirstApple);
assert.strictEqual(registry.resolve('controller:apple'), FirstApple);
expectAssertion(function () {
registry.register('controller:apple', SecondApple);
}, /Cannot re-register: 'controller:apple', as it has already been resolved\./);
assert.strictEqual(registry.resolve('controller:apple'), FirstApple);
};
_proto['@test registry.has should not accidentally cause injections on that factory to be run. (Mitigate merely on observing)'] = function testRegistryHasShouldNotAccidentallyCauseInjectionsOnThatFactoryToBeRunMitigateMerelyOnObserving(assert) {
assert.expect(1);
var registry = new _container.Registry();
var FirstApple = (0, _internalTestHelpers.factory)('first');
var SecondApple = (0, _internalTestHelpers.factory)('second');
SecondApple.extend = function () {
assert.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');
assert.ok(registry.has('controller:apple'));
};
_proto['@test registry.has should not error for invalid fullNames'] = function testRegistryHasShouldNotErrorForInvalidFullNames(assert) {
var registry = new _container.Registry();
assert.ok(!registry.has('foo:bar:baz'));
};
_proto['@test once resolved, always return the same result'] = function testOnceResolvedAlwaysReturnTheSameResult(assert) {
var registry = new _container.Registry();
registry.resolver = {
resolve: function () {
return 'bar';
}
};
var Bar = registry.resolve('models:bar');
registry.resolver = {
resolve: function () {
return 'not bar';
}
};
assert.equal(registry.resolve('models:bar'), Bar);
};
_proto['@test factory resolves are cached'] = function testFactoryResolvesAreCached(assert) {
var registry = new _container.Registry();
var PostController = (0, _internalTestHelpers.factory)();
var resolveWasCalled = [];
registry.resolver = {
resolve: function (fullName) {
resolveWasCalled.push(fullName);
return PostController;
}
};
assert.deepEqual(resolveWasCalled, []);
registry.resolve('controller:post');
assert.deepEqual(resolveWasCalled, ['controller:post']);
registry.resolve('controller:post');
assert.deepEqual(resolveWasCalled, ['controller:post']);
};
_proto['@test factory for non extendables (MODEL) resolves are cached'] = function testFactoryForNonExtendablesMODELResolvesAreCached(assert) {
var registry = new _container.Registry();
var PostController = (0, _internalTestHelpers.factory)();
var resolveWasCalled = [];
registry.resolver = {
resolve: function (fullName) {
resolveWasCalled.push(fullName);
return PostController;
}
};
assert.deepEqual(resolveWasCalled, []);
registry.resolve('model:post');
assert.deepEqual(resolveWasCalled, ['model:post']);
registry.resolve('model:post');
assert.deepEqual(resolveWasCalled, ['model:post']);
};
_proto['@test factory for non extendables resolves are cached'] = function testFactoryForNonExtendablesResolvesAreCached(assert) {
var registry = new _container.Registry();
var PostController = {};
var resolveWasCalled = [];
registry.resolver = {
resolve: function (fullName) {
resolveWasCalled.push(fullName);
return PostController;
}
};
assert.deepEqual(resolveWasCalled, []);
registry.resolve('foo:post');
assert.deepEqual(resolveWasCalled, ['foo:post']);
registry.resolve('foo:post');
assert.deepEqual(resolveWasCalled, ['foo:post']);
};
_proto['@test registry.container creates a container'] = function testRegistryContainerCreatesAContainer(assert) {
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');
assert.ok(postController instanceof PostController, 'The lookup is an instance of the registered factory');
};
_proto['@test `describe` will be handled by the resolver, then by the fallback registry, if available'] = function testDescribeWillBeHandledByTheResolverThenByTheFallbackRegistryIfAvailable(assert) {
var fallback = {
describe: function (fullName) {
return fullName + "-fallback";
}
};
var resolver = {
lookupDescription: function (fullName) {
return fullName + "-resolver";
}
};
var registry = new _container.Registry({
fallback: fallback,
resolver: resolver
});
assert.equal(registry.describe('controller:post'), 'controller:post-resolver', '`describe` handled by the resolver first.');
registry.resolver = null;
assert.equal(registry.describe('controller:post'), 'controller:post-fallback', '`describe` handled by fallback registry next.');
registry.fallback = null;
assert.equal(registry.describe('controller:post'), 'controller:post', '`describe` by default returns argument.');
};
_proto['@test `normalizeFullName` will be handled by the resolver, then by the fallback registry, if available'] = function testNormalizeFullNameWillBeHandledByTheResolverThenByTheFallbackRegistryIfAvailable(assert) {
var fallback = {
normalizeFullName: function (fullName) {
return fullName + "-fallback";
}
};
var resolver = {
normalize: function (fullName) {
return fullName + "-resolver";
}
};
var registry = new _container.Registry({
fallback: fallback,
resolver: resolver
});
assert.equal(registry.normalizeFullName('controller:post'), 'controller:post-resolver', '`normalizeFullName` handled by the resolver first.');
registry.resolver = null;
assert.equal(registry.normalizeFullName('controller:post'), 'controller:post-fallback', '`normalizeFullName` handled by fallback registry next.');
registry.fallback = null;
assert.equal(registry.normalizeFullName('controller:post'), 'controller:post', '`normalizeFullName` by default returns argument.');
};
_proto['@test `makeToString` will be handled by the resolver, then by the fallback registry, if available'] = function testMakeToStringWillBeHandledByTheResolverThenByTheFallbackRegistryIfAvailable(assert) {
var fallback = {
makeToString: function (fullName) {
return fullName + "-fallback";
}
};
var resolver = {
makeToString: function (fullName) {
return fullName + "-resolver";
}
};
var registry = new _container.Registry({
fallback: fallback,
resolver: resolver
});
assert.equal(registry.makeToString('controller:post'), 'controller:post-resolver', '`makeToString` handled by the resolver first.');
registry.resolver = null;
assert.equal(registry.makeToString('controller:post'), 'controller:post-fallback', '`makeToString` handled by fallback registry next.');
registry.fallback = null;
assert.equal(registry.makeToString('controller:post'), 'controller:post', '`makeToString` by default returns argument.');
};
_proto['@test `resolve` can be handled by a fallback registry'] = function testResolveCanBeHandledByAFallbackRegistry(assert) {
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');
assert.ok(PostControllerFactory, 'factory is returned');
assert.ok(PostControllerFactory.create() instanceof PostController, 'The return of factory.create is an instance of PostController');
};
_proto['@test `has` can be handled by a fallback registry'] = function testHasCanBeHandledByAFallbackRegistry(assert) {
var fallback = new _container.Registry();
var registry = new _container.Registry({
fallback: fallback
});
var PostController = (0, _internalTestHelpers.factory)();
fallback.register('controller:post', PostController);
assert.equal(registry.has('controller:post'), true, 'Fallback registry is checked for registration');
};
_proto['@test `getInjections` includes injections from a fallback registry'] = function testGetInjectionsIncludesInjectionsFromAFallbackRegistry(assert) {
var fallback = new _container.Registry();
var registry = new _container.Registry({
fallback: fallback
});
assert.strictEqual(registry.getInjections('model:user'), undefined, 'No injections in the primary registry');
fallback.injection('model:user', 'post', 'model:post');
assert.equal(registry.getInjections('model:user').length, 1, 'Injections from the fallback registry are merged');
};
_proto['@test `getTypeInjections` includes type injections from a fallback registry'] = function testGetTypeInjectionsIncludesTypeInjectionsFromAFallbackRegistry(assert) {
var fallback = new _container.Registry();
var registry = new _container.Registry({
fallback: fallback
});
assert.strictEqual(registry.getTypeInjections('model'), undefined, 'No injections in the primary registry');
fallback.injection('model', 'source', 'source:main');
assert.equal(registry.getTypeInjections('model').length, 1, 'Injections from the fallback registry are merged');
};
_proto['@test `knownForType` contains keys for each item of a given type'] = function testKnownForTypeContainsKeysForEachItemOfAGivenType(assert) {
var registry = new _container.Registry();
registry.register('foo:bar-baz', 'baz');
registry.register('foo:qux-fez', 'fez');
var found = registry.knownForType('foo');
assert.deepEqual(found, {
'foo:bar-baz': true,
'foo:qux-fez': true
});
};
_proto['@test `knownForType` includes fallback registry results'] = function testKnownForTypeIncludesFallbackRegistryResults(assert) {
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');
assert.deepEqual(found, {
'foo:bar-baz': true,
'foo:qux-fez': true,
'foo:zurp-zorp': true
});
};
_proto['@test `knownForType` is called on the resolver if present'] = function testKnownForTypeIsCalledOnTheResolverIfPresent(assert) {
assert.expect(3);
var resolver = {
knownForType: function (type) {
assert.ok(true, 'knownForType called on the resolver');
assert.equal(type, 'foo', 'the type was passed through');
return {
'foo:yorp': true
};
}
};
var registry = new _container.Registry({
resolver: resolver
});
registry.register('foo:bar-baz', 'baz');
var found = registry.knownForType('foo');
assert.deepEqual(found, {
'foo:yorp': true,
'foo:bar-baz': true
});
};
_proto['@test resolver.expandLocalLookup is not required'] = function testResolverExpandLocalLookupIsNotRequired(assert) {
var registry = new _container.Registry({
resolver: {}
});
var result = registry.expandLocalLookup('foo:bar', {
source: 'baz:qux'
});
assert.equal(result, null);
};
_proto['@test expandLocalLookup is called on the resolver if present'] = function testExpandLocalLookupIsCalledOnTheResolverIfPresent(assert) {
assert.expect(4);
var 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 registry = new _container.Registry({
resolver: resolver
});
var result = registry.expandLocalLookup('foo:bar', {
source: 'baz:qux'
});
assert.equal(result, 'foo:qux/bar');
};
_proto['@test `expandLocalLookup` is handled by the resolver, then by the fallback registry, if available'] = function testExpandLocalLookupIsHandledByTheResolverThenByTheFallbackRegistryIfAvailable(assert) {
assert.expect(9);
var fallbackResolver = {
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 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 fallbackRegistry = new _container.Registry({
resolver: fallbackResolver
});
var registry = new _container.Registry({
fallback: fallbackRegistry,
resolver: 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');
};
_proto['@test resolver.expandLocalLookup result is cached'] = function testResolverExpandLocalLookupResultIsCached(assert) {
assert.expect(3);
var result;
var resolver = {
expandLocalLookup: function () {
assert.ok(true, 'expandLocalLookup is called on the resolver');
return 'foo:qux/bar';
}
};
var registry = new _container.Registry({
resolver: resolver
});
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');
};
_proto['@test resolver.expandLocalLookup cache is busted when any unregister is called'] = function testResolverExpandLocalLookupCacheIsBustedWhenAnyUnregisterIsCalled(assert) {
assert.expect(4);
var result;
var resolver = {
expandLocalLookup: function () {
assert.ok(true, 'expandLocalLookup is called on the resolver');
return 'foo:qux/bar';
}
};
var registry = new _container.Registry({
resolver: resolver
});
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');
};
_proto['@test resolve calls expandLocallookup when it receives options.source'] = function testResolveCallsExpandLocallookupWhenItReceivesOptionsSource(assert) {
assert.expect(3);
var 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';
}
};
var registry = new _container.Registry({
resolver: resolver
});
registry.resolve('foo:bar', {
source: 'baz:qux'
});
};
_proto['@test has uses expandLocalLookup'] = function testHasUsesExpandLocalLookup(assert) {
assert.expect(5);
var resolvedFullNames = [];
var result;
var 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;
}
}
};
var registry = new _container.Registry({
resolver: resolver
});
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);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Registry privatize',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test valid format'] = function testValidFormat(assert) {
var privatized = (0, _container.privatize)(['secret:factory']);
var matched = privatized.match(/^([^:]+):([^:]+)-(\d+)$/);
assert.ok(matched, 'privatized format was recognized');
assert.equal(matched[1], 'secret');
assert.equal(matched[2], 'factory');
assert.ok(/^\d+$/.test(matched[3]));
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
if (false
/* EMBER_MODULE_UNIFICATION */
) {
(0, _internalTestHelpers.moduleFor)('Registry module unification',
/*#__PURE__*/
function (_AbstractTestCase3) {
(0, _emberBabel.inheritsLoose)(_class3, _AbstractTestCase3);
function _class3() {
return _AbstractTestCase3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3['@test The registry can pass a source to the resolver'] = function testTheRegistryCanPassASourceToTheResolver(assert) {
var PrivateComponent = (0, _internalTestHelpers.factory)();
var type = 'component';
var name = 'my-input';
var specifier = type + ":" + name;
var source = 'template:routes/application';
var resolver = new _internalTestHelpers.ModuleBasedTestResolver();
resolver.add({
specifier: specifier,
source: source
}, PrivateComponent);
var registry = new _container.Registry({
resolver: resolver
});
assert.strictEqual(registry.resolve(specifier), undefined, 'Not returned when specifier not scoped');
assert.strictEqual(registry.resolve(specifier, {
source: source
}), PrivateComponent, 'The correct factory was provided');
assert.strictEqual(registry.resolve(specifier, {
source: source
}), PrivateComponent, 'The correct factory was provided again');
};
_proto3['@test The registry can pass a namespace to the resolver'] = function testTheRegistryCanPassANamespaceToTheResolver(assert) {
var PrivateComponent = (0, _internalTestHelpers.factory)();
var type = 'component';
var name = 'my-input';
var specifier = type + ":" + name;
var source = 'template:routes/application';
var namespace = 'my-addon';
var resolver = new _internalTestHelpers.ModuleBasedTestResolver();
resolver.add({
specifier: specifier,
source: source,
namespace: namespace
}, PrivateComponent);
var registry = new _container.Registry({
resolver: resolver
});
assert.strictEqual(registry.resolve(specifier), undefined, 'Not returned when specifier not scoped');
assert.strictEqual(registry.resolve(specifier, {
source: source
}), undefined, 'Not returned when specifier is missing namespace');
assert.strictEqual(registry.resolve(specifier, {
source: source,
namespace: namespace
}), PrivateComponent, 'The correct factory was provided');
assert.strictEqual(registry.resolve(specifier, {
source: source,
namespace: namespace
}), PrivateComponent, 'The correct factory was provided again');
};
return _class3;
}(_internalTestHelpers.AbstractTestCase));
}
});
enifed("@ember/-internals/extension-support/tests/container_debug_adapter_test", ["ember-babel", "internal-test-helpers", "@ember/polyfills", "@ember/runloop", "@ember/controller", "@ember/-internals/extension-support/index", "@ember/debug"], function (_emberBabel, _internalTestHelpers, _polyfills, _runloop, _controller, _index, _debug) {
"use strict";
// Must be required to export Ember.ContainerDebugAdapter.
var originalDebug = (0, _debug.getDebugFunction)('debug');
(0, _internalTestHelpers.moduleFor)('Container Debug Adapter',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
var _this;
(0, _debug.setDebugFunction)('debug', function () {});
_this = _ApplicationTestCase.call(this) || this;
_this.adapter = _this.application.__deprecatedInstance__.lookup('container-debug-adapter:main');
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
var _this2 = this;
(0, _debug.setDebugFunction)('debug', originalDebug);
(0, _runloop.run)(function () {
_this2.adapter.destroy();
});
_ApplicationTestCase.prototype.teardown.call(this);
};
_proto['@test default ContainerDebugAdapter cannot catalog certain entries by type'] = function testDefaultContainerDebugAdapterCannotCatalogCertainEntriesByType(assert) {
assert.equal(this.adapter.canCatalogEntriesByType('model'), false, 'canCatalogEntriesByType should return false for model');
assert.equal(this.adapter.canCatalogEntriesByType('template'), false, 'canCatalogEntriesByType should return false for template');
};
_proto['@test default ContainerDebugAdapter can catalog typical entries by type'] = function testDefaultContainerDebugAdapterCanCatalogTypicalEntriesByType(assert) {
assert.equal(this.adapter.canCatalogEntriesByType('controller'), true, 'canCatalogEntriesByType should return true for controller');
assert.equal(this.adapter.canCatalogEntriesByType('route'), true, 'canCatalogEntriesByType should return true for route');
assert.equal(this.adapter.canCatalogEntriesByType('view'), true, 'canCatalogEntriesByType should return true for view');
};
_proto['@test default ContainerDebugAdapter catalogs controller entries'] = function testDefaultContainerDebugAdapterCatalogsControllerEntries(assert) {
this.application.PostController = _controller.default.extend();
var controllerClasses = this.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, _polyfills.assign)(_ApplicationTestCase.prototype.applicationOptions, {
autoboot: true
});
}
}]);
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("@ember/-internals/extension-support/tests/data_adapter_test", ["ember-babel", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/runtime", "@ember/-internals/extension-support/lib/data_adapter", "internal-test-helpers"], function (_emberBabel, _runloop, _metal, _runtime, _data_adapter, _internalTestHelpers) {
"use strict";
var adapter;
var Model = _runtime.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, _runtime.A)(['post']);
}
});
}
});
(0, _internalTestHelpers.moduleFor)('Data Adapter',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_ApplicationTestCase.prototype.teardown.call(this);
adapter = undefined;
};
_proto['@test Model types added'] = function testModelTypesAdded(assert) {
var _this = this;
this.add('data-adapter:main', DataAdapter.extend({
getRecords: function () {
return (0, _runtime.A)([1, 2, 3]);
},
columnsForType: function () {
return [{
name: 'title',
desc: 'Title'
}];
}
}));
this.add('model:post', PostClass);
return this.visit('/').then(function () {
var adapter = _this.applicationInstance.lookup('data-adapter:main');
function modelTypesAdded(types) {
assert.equal(types.length, 1);
var postType = types[0];
assert.equal(postType.name, 'post', 'Correctly sets the name');
assert.equal(postType.count, 3, 'Correctly sets the record count');
assert.strictEqual(postType.object, PostClass, 'Correctly sets the object');
assert.deepEqual(postType.columns, [{
name: 'title',
desc: 'Title'
}], 'Correctly sets the columns');
}
adapter.watchModelTypes(modelTypesAdded);
});
};
_proto['@test getRecords gets a model name as second argument'] = function testGetRecordsGetsAModelNameAsSecondArgument(assert) {
var _this2 = this;
this.add('data-adapter:main', DataAdapter.extend({
getRecords: function (klass, name) {
assert.equal(name, 'post');
return (0, _runtime.A)();
}
}));
this.add('model:post', PostClass);
return this.visit('/').then(function () {
adapter = _this2.applicationInstance.lookup('data-adapter:main');
adapter.watchModelTypes(function () {});
});
};
_proto['@test Model types added with custom container-debug-adapter'] = function testModelTypesAddedWithCustomContainerDebugAdapter(assert) {
var _this3 = this;
var StubContainerDebugAdapter = _runtime.Object.extend({
canCatalogEntriesByType: function () {
return true;
},
catalogEntriesByType: function () {
return (0, _runtime.A)(['post']);
}
});
this.add('container-debug-adapter:main', StubContainerDebugAdapter);
this.add('data-adapter:main', DataAdapter.extend({
getRecords: function () {
return (0, _runtime.A)([1, 2, 3]);
},
columnsForType: function () {
return [{
name: 'title',
desc: 'Title'
}];
}
}));
this.add('model:post', PostClass);
return this.visit('/').then(function () {
var adapter = _this3.applicationInstance.lookup('data-adapter:main');
function modelTypesAdded(types) {
assert.equal(types.length, 1);
var postType = types[0];
assert.equal(postType.name, 'post', 'Correctly sets the name');
assert.equal(postType.count, 3, 'Correctly sets the record count');
assert.strictEqual(postType.object, PostClass, 'Correctly sets the object');
assert.deepEqual(postType.columns, [{
name: 'title',
desc: 'Title'
}], 'Correctly sets the columns');
}
adapter.watchModelTypes(modelTypesAdded);
});
};
_proto['@test Model Types Updated'] = function testModelTypesUpdated(assert) {
var _this4 = this;
var records = (0, _runtime.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 = _this4.applicationInstance.lookup('data-adapter:main');
function modelTypesAdded() {
(0, _runloop.run)(function () {
records.pushObject(4);
});
}
function modelTypesUpdated(types) {
var postType = types[0];
assert.equal(postType.count, 4, 'Correctly updates the count');
}
adapter.watchModelTypes(modelTypesAdded, modelTypesUpdated);
});
};
_proto['@test Model Types Updated but Unchanged Do not Trigger Callbacks'] = function testModelTypesUpdatedButUnchangedDoNotTriggerCallbacks(assert) {
var _this5 = this;
assert.expect(0);
var records = (0, _runtime.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');
function modelTypesAdded() {
(0, _runloop.run)(function () {
records.arrayContentDidChange(0, 0, 0);
});
}
function modelTypesUpdated() {
assert.ok(false, "modelTypesUpdated should not be triggered if the array didn't change");
}
adapter.watchModelTypes(modelTypesAdded, modelTypesUpdated);
});
};
_proto['@test Records Added'] = function testRecordsAdded(assert) {
var _this6 = this;
var countAdded = 1;
var post = PostClass.create();
var recordList = (0, _runtime.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');
function recordsAdded(records) {
var record = records[0];
assert.equal(record.color, 'blue', 'Sets the color correctly');
assert.deepEqual(record.columnValues, {
title: 'Post ' + countAdded
}, 'Sets the column values correctly');
assert.deepEqual(record.searchKeywords, ['Post ' + countAdded], 'Sets search keywords correctly');
assert.strictEqual(record.object, post, 'Sets the object to the record instance');
}
adapter.watchRecords('post', recordsAdded);
countAdded++;
post = PostClass.create();
recordList.pushObject(post);
});
};
_proto['@test Observes and releases a record correctly'] = function testObservesAndReleasesARecordCorrectly(assert) {
var _this7 = this;
var updatesCalled = 0;
var post = PostClass.create({
title: 'Post'
});
var recordList = (0, _runtime.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, _metal.addObserver)(record, 'title', callback);
return function () {
(0, _metal.removeObserver)(record, 'title', callback);
};
},
getRecordColumnValues: function (record) {
return {
title: (0, _metal.get)(record, 'title')
};
}
}));
this.add('model:post', PostClass);
return this.visit('/').then(function () {
adapter = _this7.applicationInstance.lookup('data-adapter:main');
function recordsAdded() {
(0, _metal.set)(post, 'title', 'Post Modified');
}
function recordsUpdated(records) {
updatesCalled++;
assert.equal(records[0].columnValues.title, 'Post Modified');
}
var release = adapter.watchRecords('post', recordsAdded, recordsUpdated);
release();
(0, _metal.set)(post, 'title', 'New Title');
assert.equal(updatesCalled, 1, 'Release function removes observers');
});
};
_proto['@test _nameToClass does not error when not found'] = function test_nameToClassDoesNotErrorWhenNotFound(assert) {
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');
assert.equal(klass, undefined, 'returns undefined');
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/application/actions-test", ["ember-babel", "internal-test-helpers", "@ember/controller", "@ember/debug", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _controller, _debug, _helpers) {
"use strict";
var originalDebug = (0, _debug.getDebugFunction)('debug');
var noop = function () {};
(0, _internalTestHelpers.moduleFor)('Application test: actions',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
(0, _debug.setDebugFunction)('debug', noop);
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
(0, _debug.setDebugFunction)('debug', originalDebug);
};
_proto['@test actions in top level template application template target application controller'] = function testActionsInTopLevelTemplateApplicationTemplateTargetApplicationController(assert) {
var _this = this;
assert.expect(1);
this.add('controller:application', _controller.default.extend({
actions: {
handleIt: function () {
assert.ok(true, 'controller received action properly');
}
}
}));
this.addTemplate('application', '');
return this.visit('/').then(function () {
(0, _internalTestHelpers.runTask)(function () {
return _this.$('#handle-it').click();
});
});
};
_proto['@test actions in nested outlet template target their controller'] = function testActionsInNestedOutletTemplateTargetTheirController(assert) {
var _this2 = this;
assert.expect(1);
this.add('controller:application', _controller.default.extend({
actions: {
handleIt: function () {
assert.ok(false, 'application controller should not have received action!');
}
}
}));
this.add('controller:index', _controller.default.extend({
actions: {
handleIt: function () {
assert.ok(true, 'controller received action properly');
}
}
}));
this.addTemplate('index', '');
return this.visit('/').then(function () {
(0, _internalTestHelpers.runTask)(function () {
return _this2.$('#handle-it').click();
});
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Rendering test: non-interactive actions',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class2, _RenderingTestCase);
function _class2() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2.getBootOptions = function getBootOptions() {
return {
isInteractive: false
};
};
_proto2["@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;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/application/engine-test", ["ember-babel", "internal-test-helpers", "@ember/controller", "@ember/-internals/runtime", "@ember/-internals/glimmer", "@ember/engine", "@ember/-internals/routing", "@ember/runloop", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _controller, _runtime, _glimmer, _engine, _routing, _runloop, _helpers) {
"use strict";
function _templateObject6() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
Component!
\n "]);
_templateObject6 = function () {
return data;
};
return data;
}
function _templateObject5() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
Engine
\n {{my-component}}\n {{outlet}}\n "]);
_templateObject5 = function () {
return data;
};
return data;
}
function _templateObject4() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
Application
\n {{my-component ambiguous-curlies=\"Local Data!\"}}\n {{outlet}}\n "]);
_templateObject4 = function () {
return data;
};
return data;
}
function _templateObject3() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{ambiguous-curlies}}\n "]);
_templateObject3 = function () {
return data;
};
return data;
}
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
Component!
\n "]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
{{contextType}}
\n {{ambiguous-curlies}}\n\n {{outlet}}\n "]);
_templateObject = function () {
return data;
};
return data;
}
(0, _internalTestHelpers.moduleFor)('Application test: engine rendering',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.setupAppAndRoutableEngine = function setupAppAndRoutableEngine() {
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', _routing.Route.extend({
model: function () {
hooks.push('application - application');
}
}));
this.add('engine:blog', _engine.default.extend({
init: function () {
this._super.apply(this, arguments);
this.register('controller:application', _controller.default.extend({
queryParams: ['lang'],
lang: ''
}));
this.register('controller:category', _controller.default.extend({
queryParams: ['type']
}));
this.register('controller:authorKtrl', _controller.default.extend({
queryParams: ['official']
}));
this.register('template:application', (0, _helpers.compile)('Engine{{lang}}{{outlet}}'));
this.register('route:application', _routing.Route.extend({
model: function () {
hooks.push('engine - application');
}
}));
this.register('route:author', _routing.Route.extend({
controllerName: 'authorKtrl'
}));
if (self._additionalEngineRegistrations) {
self._additionalEngineRegistrations.call(this);
}
}
}));
};
_proto.setupAppAndRoutelessEngine = function setupAppAndRoutelessEngine(hooks) {
this.setupRoutelessEngine(hooks);
this.add('engine:chat-engine', _engine.default.extend({
init: function () {
this._super.apply(this, arguments);
this.register('template:application', (0, _helpers.compile)('Engine'));
this.register('controller:application', _controller.default.extend({
init: function () {
this._super.apply(this, arguments);
hooks.push('engine - application');
}
}));
}
}));
};
_proto.setupAppAndRoutableEngineWithPartial = function setupAppAndRoutableEngineWithPartial(hooks) {
this.addTemplate('application', 'Application{{outlet}}');
this.router.map(function () {
this.mount('blog');
});
this.add('route-map:blog', function () {});
this.add('route:application', _routing.Route.extend({
model: function () {
hooks.push('application - application');
}
}));
this.add('engine:blog', _engine.default.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', _routing.Route.extend({
model: function () {
hooks.push('engine - application');
}
}));
}
}));
};
_proto.setupRoutelessEngine = function setupRoutelessEngine(hooks) {
this.addTemplate('application', 'Application{{mount "chat-engine"}}');
this.add('route:application', _routing.Route.extend({
model: function () {
hooks.push('application - application');
}
}));
};
_proto.setupAppAndRoutlessEngineWithPartial = function setupAppAndRoutlessEngineWithPartial(hooks) {
this.setupRoutelessEngine(hooks);
this.add('engine:chat-engine', _engine.default.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', _controller.default.extend({
init: function () {
this._super.apply(this, arguments);
hooks.push('engine - application');
}
}));
}
}));
};
_proto.additionalEngineRegistrations = function additionalEngineRegistrations(callback) {
this._additionalEngineRegistrations = callback;
};
_proto.setupEngineWithAttrs = function setupEngineWithAttrs() {
this.addTemplate('application', 'Application{{mount "chat-engine"}}');
this.add('engine:chat-engine', _engine.default.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', _controller.default.extend({
contextType: 'Engine'
}));
this.register('template:application', (0, _helpers.compile)('Engine {{foo-bar wat=contextType}}'));
}
}));
};
_proto.stringsEndWith = function stringsEndWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
};
_proto['@test attrs in an engine'] = function testAttrsInAnEngine() {
var _this = this;
this.setupEngineWithAttrs([]);
return this.visit('/').then(function () {
_this.assertText('ApplicationEngine Engine');
});
};
_proto['@test sharing a template between engine and application has separate refinements'] = function testSharingATemplateBetweenEngineAndApplicationHasSeparateRefinements() {
var _this2 = this;
this.assert.expect(1);
var sharedTemplate = (0, _helpers.compile)((0, _internalTestHelpers.strip)(_templateObject()));
this.add('template:application', sharedTemplate);
this.add('controller:application', _controller.default.extend({
contextType: 'Application',
'ambiguous-curlies': 'Controller Data!'
}));
this.router.map(function () {
this.mount('blog');
});
this.add('route-map:blog', function () {});
this.add('engine:blog', _engine.default.extend({
init: function () {
this._super.apply(this, arguments);
this.register('controller:application', _controller.default.extend({
contextType: 'Engine'
}));
this.register('template:application', sharedTemplate);
this.register('template:components/ambiguous-curlies', (0, _helpers.compile)((0, _internalTestHelpers.strip)(_templateObject2())));
}
}));
return this.visit('/blog').then(function () {
_this2.assertText('ApplicationController Data!EngineComponent!');
});
};
_proto['@test sharing a layout between engine and application has separate refinements'] = function testSharingALayoutBetweenEngineAndApplicationHasSeparateRefinements() {
var _this3 = this;
this.assert.expect(1);
var sharedLayout = (0, _helpers.compile)((0, _internalTestHelpers.strip)(_templateObject3()));
var sharedComponent = _glimmer.Component.extend({
layout: sharedLayout
});
this.addTemplate('application', (0, _internalTestHelpers.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', _engine.default.extend({
init: function () {
this._super.apply(this, arguments);
this.register('template:application', (0, _helpers.compile)((0, _internalTestHelpers.strip)(_templateObject5())));
this.register('component:my-component', sharedComponent);
this.register('template:components/ambiguous-curlies', (0, _helpers.compile)((0, _internalTestHelpers.strip)(_templateObject6())));
}
}));
return this.visit('/blog').then(function () {
_this3.assertText('ApplicationLocal Data!EngineComponent!');
});
};
_proto['@test visit() with `shouldRender: true` returns a promise that resolves when application and engine templates have rendered'] = function testVisitWithShouldRenderTrueReturnsAPromiseThatResolvesWhenApplicationAndEngineTemplatesHaveRendered(assert) {
var _this4 = this;
assert.expect(2);
var hooks = [];
this.setupAppAndRoutableEngine(hooks);
return this.visit('/blog', {
shouldRender: true
}).then(function () {
_this4.assertText('ApplicationEngine');
_this4.assert.deepEqual(hooks, ['application - application', 'engine - application'], 'the expected model hooks were fired');
});
};
_proto['@test visit() with `shouldRender: false` returns a promise that resolves without rendering'] = function testVisitWithShouldRenderFalseReturnsAPromiseThatResolvesWithoutRendering(assert) {
var _this5 = this;
assert.expect(2);
var hooks = [];
this.setupAppAndRoutableEngine(hooks);
return this.visit('/blog', {
shouldRender: false
}).then(function () {
assert.strictEqual(document.getElementById('qunit-fixture').children.length, 0, "there are no elements in the qunit-fixture element");
_this5.assert.deepEqual(hooks, ['application - application', 'engine - application'], 'the expected model hooks were fired');
});
};
_proto['@test visit() with `shouldRender: true` returns a promise that resolves when application and routeless engine templates have rendered'] = function testVisitWithShouldRenderTrueReturnsAPromiseThatResolvesWhenApplicationAndRoutelessEngineTemplatesHaveRendered(assert) {
var _this6 = this;
assert.expect(2);
var hooks = [];
this.setupAppAndRoutelessEngine(hooks);
return this.visit('/', {
shouldRender: true
}).then(function () {
_this6.assertText('ApplicationEngine');
_this6.assert.deepEqual(hooks, ['application - application', 'engine - application'], 'the expected hooks were fired');
});
};
_proto['@test visit() with partials in routable engine'] = function testVisitWithPartialsInRoutableEngine(assert) {
var _this7 = this;
assert.expect(2);
var hooks = [];
this.setupAppAndRoutableEngineWithPartial(hooks);
return this.visit('/blog', {
shouldRender: true
}).then(function () {
_this7.assertText('ApplicationEngine foo partial');
_this7.assert.deepEqual(hooks, ['application - application', 'engine - application'], 'the expected hooks were fired');
});
};
_proto['@test visit() with partials in non-routable engine'] = function testVisitWithPartialsInNonRoutableEngine(assert) {
var _this8 = this;
assert.expect(2);
var hooks = [];
this.setupAppAndRoutlessEngineWithPartial(hooks);
return this.visit('/', {
shouldRender: true
}).then(function () {
_this8.assertText('ApplicationEngine foo partial');
_this8.assert.deepEqual(hooks, ['application - application', 'engine - application'], 'the expected hooks were fired');
});
};
_proto['@test deactivate should be called on Engine Routes before destruction'] = function testDeactivateShouldBeCalledOnEngineRoutesBeforeDestruction(assert) {
var _this9 = this;
assert.expect(3);
this.setupAppAndRoutableEngine();
this.add('engine:blog', _engine.default.extend({
init: function () {
this._super.apply(this, arguments);
this.register('template:application', (0, _helpers.compile)('Engine{{outlet}}'));
this.register('route:application', _routing.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 () {
_this9.assertText('ApplicationEngine');
});
};
_proto['@test engine should lookup and use correct controller'] = function testEngineShouldLookupAndUseCorrectController() {
var _this10 = this;
this.setupAppAndRoutableEngine();
return this.visit('/blog?lang=English').then(function () {
_this10.assertText('ApplicationEngineEnglish');
});
};
_proto['@test error substate route works for the application route of an Engine'] = function testErrorSubstateRouteWorksForTheApplicationRouteOfAnEngine(assert) {
var _this11 = this;
assert.expect(2);
var errorEntered = _runtime.RSVP.defer();
this.setupAppAndRoutableEngine();
this.additionalEngineRegistrations(function () {
this.register('route:application_error', _routing.Route.extend({
activate: function () {
(0, _runloop.next)(errorEntered.resolve);
}
}));
this.register('template:application_error', (0, _helpers.compile)('Error! {{model.message}}'));
this.register('route:post', _routing.Route.extend({
model: function () {
return _runtime.RSVP.reject(new Error('Oh, noes!'));
}
}));
});
return this.visit('/').then(function () {
_this11.assertText('Application');
return _this11.transitionTo('blog.post');
}).then(function () {
return errorEntered.promise;
}).then(function () {
_this11.assertText('ApplicationError! Oh, noes!');
});
};
_proto['@test error route works for the application route of an Engine'] = function testErrorRouteWorksForTheApplicationRouteOfAnEngine(assert) {
var _this12 = this;
assert.expect(2);
var errorEntered = _runtime.RSVP.defer();
this.setupAppAndRoutableEngine();
this.additionalEngineRegistrations(function () {
this.register('route:error', _routing.Route.extend({
activate: function () {
(0, _runloop.next)(errorEntered.resolve);
}
}));
this.register('template:error', (0, _helpers.compile)('Error! {{model.message}}'));
this.register('route:post', _routing.Route.extend({
model: function () {
return _runtime.RSVP.reject(new Error('Oh, noes!'));
}
}));
});
return this.visit('/').then(function () {
_this12.assertText('Application');
return _this12.transitionTo('blog.post');
}).then(function () {
return errorEntered.promise;
}).then(function () {
_this12.assertText('ApplicationEngineError! Oh, noes!');
});
};
_proto['@test error substate route works for a child route of an Engine'] = function testErrorSubstateRouteWorksForAChildRouteOfAnEngine(assert) {
var _this13 = this;
assert.expect(2);
var errorEntered = _runtime.RSVP.defer();
this.setupAppAndRoutableEngine();
this.additionalEngineRegistrations(function () {
this.register('route:post_error', _routing.Route.extend({
activate: function () {
(0, _runloop.next)(errorEntered.resolve);
}
}));
this.register('template:post_error', (0, _helpers.compile)('Error! {{model.message}}'));
this.register('route:post', _routing.Route.extend({
model: function () {
return _runtime.RSVP.reject(new Error('Oh, noes!'));
}
}));
});
return this.visit('/').then(function () {
_this13.assertText('Application');
return _this13.transitionTo('blog.post');
}).then(function () {
return errorEntered.promise;
}).then(function () {
_this13.assertText('ApplicationEngineError! Oh, noes!');
});
};
_proto['@test error route works for a child route of an Engine'] = function testErrorRouteWorksForAChildRouteOfAnEngine(assert) {
var _this14 = this;
assert.expect(2);
var errorEntered = _runtime.RSVP.defer();
this.setupAppAndRoutableEngine();
this.additionalEngineRegistrations(function () {
this.register('route:post.error', _routing.Route.extend({
activate: function () {
(0, _runloop.next)(errorEntered.resolve);
}
}));
this.register('template:post.error', (0, _helpers.compile)('Error! {{model.message}}'));
this.register('route:post.comments', _routing.Route.extend({
model: function () {
return _runtime.RSVP.reject(new Error('Oh, noes!'));
}
}));
});
return this.visit('/').then(function () {
_this14.assertText('Application');
return _this14.transitionTo('blog.post.comments');
}).then(function () {
return errorEntered.promise;
}).then(function () {
_this14.assertText('ApplicationEngineError! Oh, noes!');
});
};
_proto['@test loading substate route works for the application route of an Engine'] = function testLoadingSubstateRouteWorksForTheApplicationRouteOfAnEngine(assert) {
var _this15 = this;
assert.expect(3);
var done = assert.async();
var loadingEntered = _runtime.RSVP.defer();
var resolveLoading = _runtime.RSVP.defer();
this.setupAppAndRoutableEngine();
this.additionalEngineRegistrations(function () {
this.register('route:application_loading', _routing.Route.extend({
activate: function () {
(0, _runloop.next)(loadingEntered.resolve);
}
}));
this.register('template:application_loading', (0, _helpers.compile)('Loading'));
this.register('template:post', (0, _helpers.compile)('Post'));
this.register('route:post', _routing.Route.extend({
model: function () {
return resolveLoading.promise;
}
}));
});
return this.visit('/').then(function () {
_this15.assertText('Application');
var transition = _this15.transitionTo('blog.post');
loadingEntered.promise.then(function () {
_this15.assertText('ApplicationLoading');
resolveLoading.resolve();
return (0, _internalTestHelpers.runTaskNext)().then(function () {
_this15.assertText('ApplicationEnginePost');
done();
});
});
return transition;
});
};
_proto['@test loading route works for the application route of an Engine'] = function testLoadingRouteWorksForTheApplicationRouteOfAnEngine(assert) {
var _this16 = this;
assert.expect(3);
var done = assert.async();
var loadingEntered = _runtime.RSVP.defer();
var resolveLoading = _runtime.RSVP.defer();
this.setupAppAndRoutableEngine();
this.additionalEngineRegistrations(function () {
this.register('route:loading', _routing.Route.extend({
activate: function () {
(0, _runloop.next)(loadingEntered.resolve);
}
}));
this.register('template:loading', (0, _helpers.compile)('Loading'));
this.register('template:post', (0, _helpers.compile)('Post'));
this.register('route:post', _routing.Route.extend({
model: function () {
return resolveLoading.promise;
}
}));
});
return this.visit('/').then(function () {
_this16.assertText('Application');
var transition = _this16.transitionTo('blog.post');
loadingEntered.promise.then(function () {
_this16.assertText('ApplicationEngineLoading');
resolveLoading.resolve();
return (0, _internalTestHelpers.runTaskNext)().then(function () {
_this16.assertText('ApplicationEnginePost');
done();
});
});
return transition;
});
};
_proto['@test loading substate route works for a child route of an Engine'] = function testLoadingSubstateRouteWorksForAChildRouteOfAnEngine(assert) {
var _this17 = this;
assert.expect(3);
var resolveLoading;
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', _routing.Route.extend({
model: function () {
return new _runtime.RSVP.Promise(function (resolve) {
resolveLoading = resolve;
});
}
}));
});
return this.visit('/blog/post/comments').then(function () {
_this17.assertText('ApplicationEngineComments');
var transition = _this17.transitionTo('blog.post.likes');
(0, _internalTestHelpers.runTaskNext)().then(function () {
_this17.assertText('ApplicationEngineLoading');
resolveLoading();
});
return transition.then(function () {
return (0, _internalTestHelpers.runTaskNext)();
}).then(function () {
return _this17.assertText('ApplicationEngineLikes');
});
});
};
_proto['@test loading route works for a child route of an Engine'] = function testLoadingRouteWorksForAChildRouteOfAnEngine(assert) {
var _this18 = this;
assert.expect(3);
var done = assert.async();
var loadingEntered = _runtime.RSVP.defer();
var resolveLoading = _runtime.RSVP.defer();
this.setupAppAndRoutableEngine();
this.additionalEngineRegistrations(function () {
this.register('template:post', (0, _helpers.compile)('{{outlet}}'));
this.register('template:post.comments', (0, _helpers.compile)('Comments'));
this.register('route:post.loading', _routing.Route.extend({
activate: function () {
(0, _runloop.next)(loadingEntered.resolve);
}
}));
this.register('template:post.loading', (0, _helpers.compile)('Loading'));
this.register('template:post.likes', (0, _helpers.compile)('Likes'));
this.register('route:post.likes', _routing.Route.extend({
model: function () {
return resolveLoading.promise;
}
}));
});
return this.visit('/blog/post/comments').then(function () {
_this18.assertText('ApplicationEngineComments');
var transition = _this18.transitionTo('blog.post.likes');
loadingEntered.promise.then(function () {
_this18.assertText('ApplicationEngineLoading');
resolveLoading.resolve();
return (0, _internalTestHelpers.runTaskNext)().then(function () {
_this18.assertText('ApplicationEngineLikes');
done();
});
});
return transition;
});
};
_proto["@test query params don't have stickiness by default between model"] = function testQueryParamsDonTHaveStickinessByDefaultBetweenModel(assert) {
var _this19 = this;
assert.expect(1);
var tmpl = '{{#link-to "blog.category" 1337}}Category 1337{{/link-to}}';
this.setupAppAndRoutableEngine();
this.additionalEngineRegistrations(function () {
this.register('template:category', (0, _helpers.compile)(tmpl));
});
return this.visit('/blog/category/1?type=news').then(function () {
var suffix = '/blog/category/1337';
var href = _this19.element.querySelector('a').href; // check if link ends with the suffix
assert.ok(_this19.stringsEndWith(href, suffix));
});
};
_proto['@test query params in customized controllerName have stickiness by default between model'] = function testQueryParamsInCustomizedControllerNameHaveStickinessByDefaultBetweenModel(assert) {
var _this20 = this;
assert.expect(2);
var tmpl = '{{#link-to "blog.author" 1337 class="author-1337"}}Author 1337{{/link-to}}{{#link-to "blog.author" 1 class="author-1"}}Author 1{{/link-to}}';
this.setupAppAndRoutableEngine();
this.additionalEngineRegistrations(function () {
this.register('template:author', (0, _helpers.compile)(tmpl));
});
return this.visit('/blog/author/1?official=true').then(function () {
var suffix1 = '/blog/author/1?official=true';
var href1 = _this20.element.querySelector('.author-1').href;
var suffix1337 = '/blog/author/1337';
var href1337 = _this20.element.querySelector('.author-1337').href; // check if link ends with the suffix
assert.ok(_this20.stringsEndWith(href1, suffix1), href1 + " ends with " + suffix1);
assert.ok(_this20.stringsEndWith(href1337, suffix1337), href1337 + " ends with " + suffix1337);
});
};
_proto['@test visit() routable engine which errors on init'] = function testVisitRoutableEngineWhichErrorsOnInit(assert) {
var _this21 = this;
assert.expect(1);
var hooks = [];
this.additionalEngineRegistrations(function () {
this.register('route:application', _routing.Route.extend({
init: function () {
throw new Error('Whoops! Something went wrong...');
}
}));
});
this.setupAppAndRoutableEngine(hooks);
return this.visit('/', {
shouldRender: true
}).then(function () {
return _this21.visit('/blog');
}).catch(function (error) {
assert.equal(error.message, 'Whoops! Something went wrong...');
});
};
(0, _emberBabel.createClass)(_class, [{
key: "routerOptions",
get: function () {
return {
location: 'none',
setupRouter: function () {
var _this22 = this;
this._super.apply(this, arguments);
var getRoute = this._routerMicrolib.getRoute;
this._enginePromises = Object.create(null);
this._resolvedEngines = Object.create(null);
this._routerMicrolib.getRoute = function (name) {
var engineInfo = _this22._engineInfoByRoute[name];
if (!engineInfo) {
return getRoute(name);
}
var engineName = engineInfo.name;
if (_this22._resolvedEngines[engineName]) {
return getRoute(name);
}
var enginePromise = _this22._enginePromises[engineName];
if (!enginePromise) {
enginePromise = new _runtime.RSVP.Promise(function (resolve) {
setTimeout(function () {
_this22._resolvedEngines[engineName] = true;
resolve();
}, 1);
});
_this22._enginePromises[engineName] = enginePromise;
}
return enginePromise.then(function () {
return getRoute(name);
});
};
}
};
}
}]);
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/application/hot-reload-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/environment", "@ember/service", "@ember/-internals/glimmer", "@glimmer/util"], function (_emberBabel, _internalTestHelpers, _environment, _service, _glimmer, _util) {
"use strict";
function _templateObject12() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [x-foo: first (8)]\n [x-foo: second (9)]\n [x-bar (10)]\n "]);
_templateObject12 = function () {
return data;
};
return data;
}
function _templateObject11() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [x-foofirst (6)]\n [x-foosecond (7)]\n [
wow (5)
]\n "]);
_templateObject11 = function () {
return data;
};
return data;
}
function _templateObject10() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [
first (3)
]\n [
second (4)
]\n [
wow (5)
]\n "]);
_templateObject10 = function () {
return data;
};
return data;
}
function _templateObject9() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [
first (3)
]\n [
second (4)
]\n [x-bar (2)]\n "]);
_templateObject9 = function () {
return data;
};
return data;
}
function _templateObject8() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [x-foo: first (0)]\n [x-foo: second (1)]\n [x-bar (2)]\n "]);
_templateObject8 = function () {
return data;
};
return data;
}
function _templateObject7() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [{{component (hot-reload \"x-foo\") name=\"first\"}}]\n [{{component (hot-reload \"x-foo\") name=\"second\"}}]\n [{{component (hot-reload \"x-bar\")}}]\n "]);
_templateObject7 = function () {
return data;
};
return data;
}
function _templateObject6() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [x-foo: first]\n [x-foo: second]\n [x-bar]\n "]);
_templateObject6 = function () {
return data;
};
return data;
}
function _templateObject5() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [x-foofirst]\n [x-foosecond]\n [
wow
]\n "]);
_templateObject5 = function () {
return data;
};
return data;
}
function _templateObject4() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [
first
]\n [
second
]\n [
wow
]\n "]);
_templateObject4 = function () {
return data;
};
return data;
}
function _templateObject3() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [
first
]\n [
second
]\n [x-bar]\n "]);
_templateObject3 = function () {
return data;
};
return data;
}
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [x-foo: first]\n [x-foo: second]\n [x-bar]\n "]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [{{component (hot-reload \"x-foo\") name=\"first\"}}]\n [{{component (hot-reload \"x-foo\") name=\"second\"}}]\n [{{component (hot-reload \"x-bar\")}}]\n "]);
_templateObject = function () {
return data;
};
return data;
}
// This simuates what the template hot-reloading would do in development mode
// to avoid regressions
(0, _internalTestHelpers.moduleFor)('Appliation test: template hot reloading',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
var _this;
_this = _ApplicationTestCase.apply(this, arguments) || this;
_this._APPLICATION_TEMPLATE_WRAPPER = _environment.ENV._APPLICATION_TEMPLATE_WRAPPER;
_this._TEMPLATE_ONLY_GLIMMER_COMPONENTS = _environment.ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS;
_environment.ENV._APPLICATION_TEMPLATE_WRAPPER = false;
_environment.ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS = true;
var didCreateReloader = function (reloader) {
_this.reloader = reloader;
};
_this.add('service:reloader', _service.default.extend({
init: function () {
this._super.apply(this, arguments);
this.revisions = {};
this.callbacks = [];
didCreateReloader(this);
},
onReload: function (callback) {
this.callbacks.push(callback);
},
revisionFor: function (name) {
return this.revisions[name];
},
invalidate: function (name) {
var revision = this.revisions[name];
if (revision === undefined) {
revision = 0;
}
this.revisions[name] = ++revision;
this.callbacks.forEach(function (callback) {
return callback();
});
}
}));
_this.add('helper:hot-reload', _glimmer.Helper.extend({
reloader: (0, _service.inject)(),
init: function () {
var _this2 = this;
this._super.apply(this, arguments);
this.reloader.onReload(function () {
return _this2.recompute();
});
},
compute: function (_ref) {
var name = _ref[0];
var revision = this.reloader.revisionFor(name);
if (revision === undefined) {
return name;
} else {
return name + "--hot-reload-" + revision;
}
}
}));
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_ApplicationTestCase.prototype.teardown.call(this);
_environment.ENV._APPLICATION_TEMPLATE_WRAPPER = this._APPLICATION_TEMPLATE_WRAPPER;
_environment.ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS = this._TEMPLATE_ONLY_GLIMMER_COMPONENTS;
};
_proto.hotReload = function hotReload(name, template) {
var reloader = (0, _util.expect)(this.reloader);
var revision = (reloader.revisionFor(name) || 0) + 1;
var ComponentClass = this.applicationInstance.resolveRegistration("component:" + name) || null;
this.addComponent(name + "--hot-reload-" + revision, {
ComponentClass: ComponentClass,
template: template
});
reloader.invalidate(name);
};
_proto['@test hot reloading template-only components'] = function testHotReloadingTemplateOnlyComponents() {
var _this3 = this;
this.addTemplate('application', (0, _internalTestHelpers.strip)(_templateObject()));
this.addComponent('x-foo', {
ComponentClass: null,
template: 'x-foo: {{@name}}'
});
this.addComponent('x-bar', {
ComponentClass: null,
template: 'x-bar'
});
return this.visit('/').then(function () {
_this3.assertInnerHTML((0, _internalTestHelpers.strip)(_templateObject2()));
(0, _internalTestHelpers.runTask)(function () {
_this3.hotReload('x-foo', '
'
});
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)');
(0, _internalTestHelpers.runTask)(function () {
return _this66.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 () {
(0, _internalTestHelpers.runTask)(function () {
return outer.set('value', 2);
});
}, expectedBacktrackingMessage);
};
_proto["@test when a shared dependency is changed during children's rendering"] = function testWhenASharedDependencyIsChangedDuringChildrenSRendering() {
var _this67 = this;
this.registerComponent('x-outer', {
ComponentClass: _helpers.Component.extend({
value: 1,
wrapper: _runtime.Object.create({
content: null
})
}),
template: '
\n "]);
_templateObject11 = function () {
return data;
};
return data;
}
function _templateObject10() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each items as |item|}}\n ", "\n {{else}}\n ", "\n {{/each}}\n "]);
_templateObject10 = function () {
return data;
};
return data;
}
function _templateObject9() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#nested-item}}Nothing to see here{{/nested-item}}\n "]);
_templateObject9 = function () {
return data;
};
return data;
}
function _templateObject8() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#nested-item}}Item: {{count}}{{/nested-item}}\n "]);
_templateObject8 = function () {
return data;
};
return data;
}
function _templateObject7() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n Bottom: {{", "}}\n
"]);
_templateObject7 = function () {
return data;
};
return data;
}
function _templateObject6() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n Middle: ", "\n
"]);
_templateObject6 = function () {
return data;
};
return data;
}
function _templateObject5() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n Top: ", "\n
"]);
_templateObject5 = function () {
return data;
};
return data;
}
function _templateObject4() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n ", "|\n ", "|\n ", "\n
"]);
_templateObject4 = function () {
return data;
};
return data;
}
function _templateObject3() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n Website: {{", "}}\n
"]);
_templateObject3 = function () {
return data;
};
return data;
}
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n Name: {{", "}}|\n ", "\n
"]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n Twitter: {{", "}}|\n ", "\n
"]);
_templateObject = function () {
return data;
};
return data;
}
var LifeCycleHooksTest =
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(LifeCycleHooksTest, _RenderingTestCase);
function LifeCycleHooksTest() {
var _this;
_this = _RenderingTestCase.apply(this, arguments) || this;
_this.hooks = [];
_this.components = {};
_this.componentRegistry = [];
_this.teardownAssertions = [];
_this.viewRegistry = _this.owner.lookup('-view-registry:main');
return _this;
}
var _proto = LifeCycleHooksTest.prototype;
_proto.afterEach = function afterEach() {
_RenderingTestCase.prototype.afterEach.call(this);
for (var i = 0; i < this.teardownAssertions.length; i++) {
this.teardownAssertions[i]();
}
};
_proto.getBootOptions = function getBootOptions() {
return {
isInteractive: this.isInteractive
};
}
/* abstract */
;
/* abstract */
_proto.invocationFor = function invocationFor()
/* name, namedArgs = {} */
{
throw new Error('Not implemented: `invocationFor`');
}
/* abstract */
;
_proto.attrFor = function attrFor()
/* name */
{
throw new Error('Not implemented: `attrFor`');
};
_proto.assertRegisteredViews = function assertRegisteredViews(label) {
var viewRegistry = this.viewRegistry;
var topLevelId = (0, _views.getViewId)(this.component);
var actual = Object.keys(viewRegistry).sort().filter(function (id) {
return id !== topLevelId;
});
if (this.isInteractive) {
var 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');
}
};
_proto.registerComponent = function registerComponent(name, _ref) {
var _this2 = this;
var _ref$template = _ref.template,
template = _ref$template === void 0 ? null : _ref$template;
var pushComponent = function (instance) {
_this2.components[name] = instance;
_this2.componentRegistry.push((0, _views.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, _views.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, _views.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;
this._super.apply(this, arguments);
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)');
});
(0, _runloop.schedule)('afterRender', function () {
_this3.isInitialRender = false;
});
},
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);
}
});
_RenderingTestCase.prototype.registerComponent.call(this, name, {
ComponentClass: ComponentClass,
template: template
});
};
_proto.assertHooks = function assertHooks(_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(void 0, raw);
});
this.assert.deepEqual(json(this.hooks), json(hooks), label);
this.hooks = [];
};
_proto['@test lifecycle hooks are invoked in a predictable order'] = function testLifecycleHooksAreInvokedInAPredictableOrder() {
var _this4 = this;
var _this$boundHelpers = this.boundHelpers,
attr = _this$boundHelpers.attr,
invoke = _this$boundHelpers.invoke;
this.registerComponent('the-top', {
template: (0, _internalTestHelpers.strip)(_templateObject(), attr('twitter'), invoke('the-middle', {
name: string('Tom Dale')
}))
});
this.registerComponent('the-middle', {
template: (0, _internalTestHelpers.strip)(_templateObject2(), attr('name'), invoke('the-bottom', {
website: string('tomdale.net')
}))
});
this.registerComponent('the-bottom', {
template: (0, _internalTestHelpers.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');
this.assertHooks({
label: 'after initial render',
interactive: [// Sync hooks
['the-top', 'init'], ['the-top', 'on(init)'], ['the-top', 'didReceiveAttrs'], ['the-top', 'willRender'], ['the-top', 'willInsertElement'], ['the-middle', 'init'], ['the-middle', 'on(init)'], ['the-middle', 'didReceiveAttrs'], ['the-middle', 'willRender'], ['the-middle', 'willInsertElement'], ['the-bottom', 'init'], ['the-bottom', 'on(init)'], ['the-bottom', 'didReceiveAttrs'], ['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', 'on(init)'], ['the-top', 'didReceiveAttrs'], ['the-middle', 'init'], ['the-middle', 'on(init)'], ['the-middle', 'didReceiveAttrs'], ['the-bottom', 'init'], ['the-bottom', 'on(init)'], ['the-bottom', 'didReceiveAttrs']]
});
(0, _internalTestHelpers.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: []
});
(0, _internalTestHelpers.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: []
});
(0, _internalTestHelpers.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: []
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.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.
this.assertHooks({
label: 'after update',
interactive: [// Sync hooks
['the-top', 'didUpdateAttrs'], ['the-top', 'didReceiveAttrs'], ['the-top', 'willUpdate'], ['the-top', 'willRender'], // Async hooks
['the-top', 'didUpdate'], ['the-top', 'didRender']],
nonInteractive: [// Sync hooks
['the-top', 'didUpdateAttrs'], ['the-top', 'didReceiveAttrs']]
});
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');
});
};
_proto['@test lifecycle hooks are invoked in a correct sibling order'] = function testLifecycleHooksAreInvokedInACorrectSiblingOrder() {
var _this5 = this;
var _this$boundHelpers2 = this.boundHelpers,
attr = _this$boundHelpers2.attr,
invoke = _this$boundHelpers2.invoke;
this.registerComponent('the-parent', {
template: (0, _internalTestHelpers.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');
this.assertHooks({
label: 'after initial render',
interactive: [// Sync hooks
['the-parent', 'init'], ['the-parent', 'on(init)'], ['the-parent', 'didReceiveAttrs'], ['the-parent', 'willRender'], ['the-parent', 'willInsertElement'], ['the-first-child', 'init'], ['the-first-child', 'on(init)'], ['the-first-child', 'didReceiveAttrs'], ['the-first-child', 'willRender'], ['the-first-child', 'willInsertElement'], ['the-second-child', 'init'], ['the-second-child', 'on(init)'], ['the-second-child', 'didReceiveAttrs'], ['the-second-child', 'willRender'], ['the-second-child', 'willInsertElement'], ['the-last-child', 'init'], ['the-last-child', 'on(init)'], ['the-last-child', 'didReceiveAttrs'], ['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', 'on(init)'], ['the-parent', 'didReceiveAttrs'], ['the-first-child', 'init'], ['the-first-child', 'on(init)'], ['the-first-child', 'didReceiveAttrs'], ['the-second-child', 'init'], ['the-second-child', 'on(init)'], ['the-second-child', 'didReceiveAttrs'], ['the-last-child', 'init'], ['the-last-child', 'on(init)'], ['the-last-child', 'didReceiveAttrs']]
});
(0, _internalTestHelpers.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: []
});
(0, _internalTestHelpers.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: []
});
(0, _internalTestHelpers.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: []
});
(0, _internalTestHelpers.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: []
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.setProperties)(_this5.context, {
twitter: '@horsetomdale',
name: 'Horse Tom Dale',
website: 'horsetomdale.net'
});
});
this.assertText('Twitter: @horsetomdale|Name: Horse Tom Dale|Website: horsetomdale.net');
this.assertHooks({
label: 'after update',
interactive: [// Sync hooks
['the-parent', 'didUpdateAttrs'], ['the-parent', 'didReceiveAttrs'], ['the-parent', 'willUpdate'], ['the-parent', 'willRender'], ['the-first-child', 'didUpdateAttrs'], ['the-first-child', 'didReceiveAttrs'], ['the-first-child', 'willUpdate'], ['the-first-child', 'willRender'], ['the-second-child', 'didUpdateAttrs'], ['the-second-child', 'didReceiveAttrs'], ['the-second-child', 'willUpdate'], ['the-second-child', 'willRender'], ['the-last-child', 'didUpdateAttrs'], ['the-last-child', 'didReceiveAttrs'], ['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'], ['the-parent', 'didReceiveAttrs'], ['the-first-child', 'didUpdateAttrs'], ['the-first-child', 'didReceiveAttrs'], ['the-second-child', 'didUpdateAttrs'], ['the-second-child', 'didReceiveAttrs'], ['the-last-child', 'didUpdateAttrs'], ['the-last-child', 'didReceiveAttrs']]
});
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');
});
};
_proto['@test passing values through attrs causes lifecycle hooks to fire if the attribute values have changed'] = function testPassingValuesThroughAttrsCausesLifecycleHooksToFireIfTheAttributeValuesHaveChanged() {
var _this6 = this;
var _this$boundHelpers3 = this.boundHelpers,
attr = _this$boundHelpers3.attr,
invoke = _this$boundHelpers3.invoke;
this.registerComponent('the-top', {
template: (0, _internalTestHelpers.strip)(_templateObject5(), invoke('the-middle', {
twitterTop: expr(attr('twitter'))
}))
});
this.registerComponent('the-middle', {
template: (0, _internalTestHelpers.strip)(_templateObject6(), invoke('the-bottom', {
twitterMiddle: expr(attr('twitterTop'))
}))
});
this.registerComponent('the-bottom', {
template: (0, _internalTestHelpers.strip)(_templateObject7(), attr('twitterMiddle'))
});
this.render(invoke('the-top', {
twitter: expr('twitter')
}), {
twitter: '@tomdale'
});
this.assertText('Top: Middle: Bottom: @tomdale');
this.assertRegisteredViews('intial render');
this.assertHooks({
label: 'after initial render',
interactive: [// Sync hooks
['the-top', 'init'], ['the-top', 'on(init)'], ['the-top', 'didReceiveAttrs'], ['the-top', 'willRender'], ['the-top', 'willInsertElement'], ['the-middle', 'init'], ['the-middle', 'on(init)'], ['the-middle', 'didReceiveAttrs'], ['the-middle', 'willRender'], ['the-middle', 'willInsertElement'], ['the-bottom', 'init'], ['the-bottom', 'on(init)'], ['the-bottom', 'didReceiveAttrs'], ['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', 'on(init)'], ['the-top', 'didReceiveAttrs'], ['the-middle', 'init'], ['the-middle', 'on(init)'], ['the-middle', 'didReceiveAttrs'], ['the-bottom', 'init'], ['the-bottom', 'on(init)'], ['the-bottom', 'didReceiveAttrs']]
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.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.
this.assertHooks({
label: 'after updating (root)',
interactive: [// Sync hooks
['the-top', 'didUpdateAttrs'], ['the-top', 'didReceiveAttrs'], ['the-top', 'willUpdate'], ['the-top', 'willRender'], ['the-middle', 'didUpdateAttrs'], ['the-middle', 'didReceiveAttrs'], ['the-middle', 'willUpdate'], ['the-middle', 'willRender'], ['the-bottom', 'didUpdateAttrs'], ['the-bottom', 'didReceiveAttrs'], ['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'], ['the-top', 'didReceiveAttrs'], ['the-middle', 'didUpdateAttrs'], ['the-middle', 'didReceiveAttrs'], ['the-bottom', 'didUpdateAttrs'], ['the-bottom', 'didReceiveAttrs']]
});
(0, _internalTestHelpers.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.
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');
});
};
_proto['@test components rendered from `{{each}}` have correct life-cycle hooks to be called'] = function testComponentsRenderedFromEachHaveCorrectLifeCycleHooksToBeCalled() {
var _this7 = this;
var invoke = this.boundHelpers.invoke;
this.registerComponent('nested-item', {
template: "{{yield}}"
});
this.registerComponent('an-item', {
template: (0, _internalTestHelpers.strip)(_templateObject8())
});
this.registerComponent('no-items', {
template: (0, _internalTestHelpers.strip)(_templateObject9())
});
this.render((0, _internalTestHelpers.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 () {
var ret = [['an-item', 'init'], ['an-item', 'on(init)'], ['an-item', 'didReceiveAttrs']];
if (_this7.isInteractive) {
ret.push(['an-item', 'willRender'], ['an-item', 'willInsertElement']);
}
ret.push(['nested-item', 'init'], ['nested-item', 'on(init)'], ['nested-item', 'didReceiveAttrs']);
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');
}
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.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', 'on(init)'], ['no-items', 'didReceiveAttrs'], ['no-items', 'willRender'], ['no-items', 'willInsertElement'], ['nested-item', 'init'], ['nested-item', 'on(init)'], ['nested-item', 'didReceiveAttrs'], ['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', 'on(init)'], ['no-items', 'didReceiveAttrs'], ['nested-item', 'init'], ['nested-item', 'on(init)'], ['nested-item', 'didReceiveAttrs'], ['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;
}(_internalTestHelpers.RenderingTestCase);
var CurlyComponentsTest =
/*#__PURE__*/
function (_LifeCycleHooksTest) {
(0, _emberBabel.inheritsLoose)(CurlyComponentsTest, _LifeCycleHooksTest);
function CurlyComponentsTest() {
return _LifeCycleHooksTest.apply(this, arguments) || this;
}
var _proto2 = CurlyComponentsTest.prototype;
_proto2.invocationFor = function invocationFor(name) {
var _this8 = this;
var namedArgs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var attrs = Object.keys(namedArgs).map(function (k) {
return k + "=" + _this8.val(namedArgs[k]);
}).join(' ');
return "{{" + name + " " + attrs + "}}";
};
_proto2.attrFor = function attrFor(name) {
return "" + name;
}
/* private */
;
_proto2.val = function val(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, _internalTestHelpers.moduleFor)('Components test: interactive lifecycle hooks (curly components)',
/*#__PURE__*/
function (_CurlyComponentsTest) {
(0, _emberBabel.inheritsLoose)(_class, _CurlyComponentsTest);
function _class() {
return _CurlyComponentsTest.apply(this, arguments) || this;
}
(0, _emberBabel.createClass)(_class, [{
key: "isInteractive",
get: function () {
return true;
}
}]);
return _class;
}(CurlyComponentsTest));
(0, _internalTestHelpers.moduleFor)('Components test: non-interactive lifecycle hooks (curly components)',
/*#__PURE__*/
function (_CurlyComponentsTest2) {
(0, _emberBabel.inheritsLoose)(_class2, _CurlyComponentsTest2);
function _class2() {
return _CurlyComponentsTest2.apply(this, arguments) || this;
}
(0, _emberBabel.createClass)(_class2, [{
key: "isInteractive",
get: function () {
return false;
}
}]);
return _class2;
}(CurlyComponentsTest));
(0, _internalTestHelpers.moduleFor)('Components test: interactive lifecycle hooks (tagless curly components)',
/*#__PURE__*/
function (_CurlyComponentsTest3) {
(0, _emberBabel.inheritsLoose)(_class3, _CurlyComponentsTest3);
function _class3() {
return _CurlyComponentsTest3.apply(this, arguments) || this;
}
(0, _emberBabel.createClass)(_class3, [{
key: "ComponentClass",
get: function () {
return _helpers.Component.extend({
tagName: ''
});
}
}, {
key: "isInteractive",
get: function () {
return true;
}
}]);
return _class3;
}(CurlyComponentsTest));
(0, _internalTestHelpers.moduleFor)('Components test: non-interactive lifecycle hooks (tagless curly components)',
/*#__PURE__*/
function (_CurlyComponentsTest4) {
(0, _emberBabel.inheritsLoose)(_class4, _CurlyComponentsTest4);
function _class4() {
return _CurlyComponentsTest4.apply(this, arguments) || this;
}
(0, _emberBabel.createClass)(_class4, [{
key: "ComponentClass",
get: function () {
return _helpers.Component.extend({
tagName: ''
});
}
}, {
key: "isInteractive",
get: function () {
return false;
}
}]);
return _class4;
}(CurlyComponentsTest));
(0, _internalTestHelpers.moduleFor)('Run loop and lifecycle hooks',
/*#__PURE__*/
function (_RenderingTestCase2) {
(0, _emberBabel.inheritsLoose)(_class5, _RenderingTestCase2);
function _class5() {
return _RenderingTestCase2.apply(this, arguments) || this;
}
var _proto3 = _class5.prototype;
_proto3['@test afterRender set'] = function testAfterRenderSet() {
var _this10 = this;
var ComponentClass = _helpers.Component.extend({
width: '5',
didInsertElement: function () {
var _this9 = this;
(0, _runloop.schedule)('afterRender', function () {
_this9.set('width', '10');
});
}
});
var template = "{{width}}";
this.registerComponent('foo-bar', {
ComponentClass: ComponentClass,
template: template
});
this.render('{{foo-bar}}');
this.assertText('10');
(0, _internalTestHelpers.runTask)(function () {
return _this10.rerender();
});
this.assertText('10');
};
_proto3['@test afterRender set on parent'] = function testAfterRenderSetOnParent() {
var _this12 = this;
var ComponentClass = _helpers.Component.extend({
didInsertElement: function () {
var _this11 = this;
(0, _runloop.schedule)('afterRender', function () {
var parent = _this11.get('parent');
parent.set('foo', 'wat');
});
}
});
var template = "{{foo}}";
this.registerComponent('foo-bar', {
ComponentClass: ComponentClass,
template: template
});
this.render('{{foo-bar parent=this foo=foo}}');
this.assertText('wat');
(0, _internalTestHelpers.runTask)(function () {
return _this12.rerender();
});
this.assertText('wat');
};
_proto3['@test `willRender` can set before render (GH#14458)'] = function testWillRenderCanSetBeforeRenderGH14458() {
var ComponentClass = _helpers.Component.extend({
tagName: 'a',
customHref: 'http://google.com',
attributeBindings: ['customHref:href'],
willRender: function () {
this.set('customHref', 'http://willRender.com');
}
});
var template = "Hello World";
this.registerComponent('foo-bar', {
ComponentClass: ComponentClass,
template: template
});
this.render("{{foo-bar id=\"foo\"}}");
this.assertElement(this.firstChild, {
tagName: 'a',
attrs: {
id: 'foo',
href: 'http://willRender.com',
class: (0, _internalTestHelpers.classes)('ember-view')
}
});
};
_proto3['@test that thing about destroying'] = function testThatThingAboutDestroying(assert) {
var _this13 = this;
var ParentDestroyedElements = [];
var ChildDestroyedElements = [];
var ParentComponent = _helpers.Component.extend({
willDestroyElement: function () {
ParentDestroyedElements.push({
id: this.itemId,
name: 'parent-component',
hasParent: Boolean(this.element.parentNode),
nextSibling: Boolean(this.element.nextSibling),
previousSibling: Boolean(this.element.previousSibling)
});
}
});
var PartentTemplate = (0, _internalTestHelpers.strip)(_templateObject11());
var NestedComponent = _helpers.Component.extend({
willDestroyElement: function () {
ChildDestroyedElements.push({
id: this.nestedId,
name: 'nested-component',
hasParent: Boolean(this.element.parentNode),
nextSibling: Boolean(this.element.nextSibling),
previousSibling: Boolean(this.element.previousSibling)
});
}
});
var NestedTemplate = "{{yield}}";
this.registerComponent('parent-component', {
ComponentClass: ParentComponent,
template: PartentTemplate
});
this.registerComponent('nested-component', {
ComponentClass: NestedComponent,
template: NestedTemplate
});
var array = (0, _runtime.A)([{
id: 1
}, {
id: 2
}, {
id: 3
}, {
id: 4
}, {
id: 5
}]);
this.render((0, _internalTestHelpers.strip)(_templateObject12()), {
items: array,
model: {
shouldShow: true
}
});
this.assertText('1AB2AB3AB4AB5AB6AB7AB');
(0, _internalTestHelpers.runTask)(function () {
array.removeAt(2);
array.removeAt(2);
(0, _metal.set)(_this13.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
}]);
};
_proto3['@test lifecycle hooks exist on the base class'] = function testLifecycleHooksExistOnTheBaseClass(assert) {
// Make sure we get the finalized component prototype
var prototype = _helpers.Component.proto();
assert.equal(typeof prototype.didDestroyElement, 'function', 'didDestroyElement exists');
assert.equal(typeof prototype.didInsertElement, 'function', 'didInsertElement exists');
assert.equal(typeof prototype.didReceiveAttrs, 'function', 'didReceiveAttrs exists');
assert.equal(typeof prototype.didRender, 'function', 'didRender exists');
assert.equal(typeof prototype.didUpdate, 'function', 'didUpdate exists');
assert.equal(typeof prototype.didUpdateAttrs, 'function', 'didUpdateAttrs exists');
assert.equal(typeof prototype.willClearRender, 'function', 'willClearRender exists');
assert.equal(typeof prototype.willDestroy, 'function', 'willDestroy exists');
assert.equal(typeof prototype.willDestroyElement, 'function', 'willDestroyElement exists');
assert.equal(typeof prototype.willInsertElement, 'function', 'willInsertElement exists');
assert.equal(typeof prototype.willRender, 'function', 'willRender exists');
assert.equal(typeof prototype.willUpdate, 'function', 'willUpdate exists');
};
return _class5;
}(_internalTestHelpers.RenderingTestCase));
if (!_views.jQueryDisabled) {
(0, _internalTestHelpers.moduleFor)('Run loop and lifecycle hooks - jQuery only',
/*#__PURE__*/
function (_RenderingTestCase3) {
(0, _emberBabel.inheritsLoose)(_class6, _RenderingTestCase3);
function _class6() {
return _RenderingTestCase3.apply(this, arguments) || this;
}
var _proto4 = _class6.prototype;
_proto4['@test lifecycle hooks have proper access to this.$()'] = function testLifecycleHooksHaveProperAccessToThis$(assert) {
assert.expect(6);
var component;
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);
(0, _internalTestHelpers.runTask)(function () {
return (0, _utils.tryInvoke)(component, 'destroy');
});
};
return _class6;
}(_internalTestHelpers.RenderingTestCase));
}
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 () {
for (var _len = arguments.length, args = new 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/-internals/glimmer/tests/integration/components/link-to-test", ["ember-babel", "internal-test-helpers", "@ember/controller", "@ember/-internals/metal", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _controller, _metal, _helpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Link-to component',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.visitWithDeprecation = function visitWithDeprecation(path, deprecation) {
var _this = this;
var p;
expectDeprecation(function () {
p = _this.visit(path);
}, deprecation);
return p;
};
_proto['@test should be able to be inserted in DOM when the router is not present'] = function testShouldBeAbleToBeInsertedInDOMWhenTheRouterIsNotPresent() {
var _this2 = this;
this.addTemplate('application', "{{#link-to 'index'}}Go to Index{{/link-to}}");
return this.visit('/').then(function () {
_this2.assertText('Go to Index');
});
};
_proto['@test re-renders when title changes'] = function testReRendersWhenTitleChanges() {
var _this3 = this;
var controller;
this.addTemplate('application', '{{link-to title routeName}}');
this.add('controller:application', _controller.default.extend({
init: function () {
this._super.apply(this, arguments);
controller = this;
},
title: 'foo',
routeName: 'index'
}));
return this.visit('/').then(function () {
_this3.assertText('foo');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(controller, 'title', 'bar');
});
_this3.assertText('bar');
});
};
_proto['@test re-computes active class when params change'] = function testReComputesActiveClassWhenParamsChange(assert) {
var _this4 = this;
var controller;
this.addTemplate('application', '{{link-to "foo" routeName}}');
this.add('controller:application', _controller.default.extend({
init: function () {
this._super.apply(this, arguments);
controller = this;
},
routeName: 'index'
}));
this.router.map(function () {
this.route('bar', {
path: '/bar'
});
});
return this.visit('/bar').then(function () {
assert.equal(_this4.firstChild.classList.contains('active'), false);
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(controller, 'routeName', 'bar');
});
assert.equal(_this4.firstChild.classList.contains('active'), true);
});
};
_proto['@test escaped inline form (double curlies) escapes link title'] = function testEscapedInlineFormDoubleCurliesEscapesLinkTitle() {
var _this5 = this;
this.addTemplate('application', "{{link-to title 'index'}}");
this.add('controller:application', _controller.default.extend({
title: 'blah'
}));
return this.visit('/').then(function () {
_this5.assertText('blah');
});
};
_proto['@test escaped inline form with (-html-safe) does not escape link title'] = function testEscapedInlineFormWithHtmlSafeDoesNotEscapeLinkTitle(assert) {
var _this6 = this;
this.addTemplate('application', "{{link-to (-html-safe title) 'index'}}");
this.add('controller:application', _controller.default.extend({
title: 'blah'
}));
return this.visit('/').then(function () {
_this6.assertText('blah');
assert.equal(_this6.$('b').length, 1);
});
};
_proto['@test unescaped inline form (triple curlies) does not escape link title'] = function testUnescapedInlineFormTripleCurliesDoesNotEscapeLinkTitle(assert) {
var _this7 = this;
this.addTemplate('application', "{{{link-to title 'index'}}}");
this.add('controller:application', _controller.default.extend({
title: 'blah'
}));
return this.visit('/').then(function () {
_this7.assertText('blah');
assert.equal(_this7.$('b').length, 1);
});
};
_proto['@test able to safely extend the built-in component and use the normal path'] = function testAbleToSafelyExtendTheBuiltInComponentAndUseTheNormalPath() {
var _this8 = 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', _controller.default.extend({
title: 'Hello'
}));
return this.visit('/').then(function () {
_this8.assertText('Hello');
});
};
_proto['@test [GH#13432] able to safely extend the built-in component and invoke it inline'] = function testGH13432AbleToSafelyExtendTheBuiltInComponentAndInvokeItInline() {
var _this9 = this;
this.addComponent('custom-link-to', {
ComponentClass: _helpers.LinkComponent.extend()
});
this.addTemplate('application', "{{custom-link-to title 'index'}}");
this.add('controller:application', _controller.default.extend({
title: 'Hello'
}));
return this.visit('/').then(function () {
_this9.assertText('Hello');
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Link-to component with query-params',
/*#__PURE__*/
function (_ApplicationTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _ApplicationTestCase2);
function _class2() {
var _this10;
_this10 = _ApplicationTestCase2.apply(this, arguments) || this;
_this10.add('controller:index', _controller.default.extend({
queryParams: ['foo'],
foo: '123',
bar: 'yes'
}));
return _this10;
}
var _proto2 = _class2.prototype;
_proto2['@test populates href with fully supplied query param values'] = function testPopulatesHrefWithFullySuppliedQueryParamValues() {
var _this11 = this;
this.addTemplate('index', "{{#link-to 'index' (query-params foo='456' bar='NAW')}}Index{{/link-to}}");
return this.visit('/').then(function () {
_this11.assertComponentElement(_this11.firstChild, {
tagName: 'a',
attrs: {
href: '/?bar=NAW&foo=456'
},
content: 'Index'
});
});
};
_proto2['@test populates href with partially supplied query param values, but omits if value is default value'] = function testPopulatesHrefWithPartiallySuppliedQueryParamValuesButOmitsIfValueIsDefaultValue() {
var _this12 = this;
this.addTemplate('index', "{{#link-to 'index' (query-params foo='123')}}Index{{/link-to}}");
return this.visit('/').then(function () {
_this12.assertComponentElement(_this12.firstChild, {
tagName: 'a',
attrs: {
href: '/',
class: (0, _internalTestHelpers.classes)('ember-view active')
},
content: 'Index'
});
});
};
return _class2;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Link-to component',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class3, _RenderingTestCase);
function _class3() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3['@test should be able to be inserted in DOM when the router is not present - block'] = function testShouldBeAbleToBeInsertedInDOMWhenTheRouterIsNotPresentBlock() {
this.render("{{#link-to 'index'}}Go to Index{{/link-to}}");
this.assertText('Go to Index');
};
_proto3['@test should be able to be inserted in DOM when the router is not present - inline'] = function testShouldBeAbleToBeInsertedInDOMWhenTheRouterIsNotPresentInline() {
this.render("{{link-to 'Go to Index' 'index'}}");
this.assertText('Go to Index');
};
return _class3;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/components/local-lookup-test", ["ember-babel", "internal-test-helpers", "ember-template-compiler", "@ember/-internals/glimmer", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _emberTemplateCompiler, _glimmer, _helpers) {
"use strict";
var LocalLookupTest =
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(LocalLookupTest, _RenderingTestCase);
function LocalLookupTest() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = LocalLookupTest.prototype;
_proto['@test it can lookup a local template'] = function testItCanLookupALocalTemplate() {
var _this = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
this.assertText('Nested template says: Hi!', 'Re-render works');
};
_proto['@test tagless blockless component can lookup local template'] = function testTaglessBlocklessComponentCanLookupLocalTemplate() {
var _this2 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertText('Nested template says: Hi!', 'Re-render works');
};
_proto['@test it can lookup a local component template'] = function testItCanLookupALocalComponentTemplate() {
var _this3 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this3.rerender();
});
this.assertText('Nested template says: Hi!', 'Re-render works');
};
_proto['@test it can local lookup a dynamic component'] = function testItCanLocalLookupADynamicComponent() {
var _this4 = 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?');
(0, _internalTestHelpers.runTask)(function () {
return _this4.rerender();
});
this.assertText('yall finished or yall done?');
};
_proto['@test it can local lookup a dynamic component from a dynamic component'] = function testItCanLocalLookupADynamicComponentFromADynamicComponent() {
var _this5 = 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?');
(0, _internalTestHelpers.runTask)(function () {
return _this5.rerender();
});
this.assertText('yall finished or yall done?');
};
_proto['@test it can local lookup a dynamic component from a passed named argument'] = function testItCanLocalLookupADynamicComponentFromAPassedNamedArgument() {
var _this6 = 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?');
(0, _internalTestHelpers.runTask)(function () {
return _this6.rerender();
});
this.assertText('yall finished or yall done?');
};
_proto['@test it can local lookup a re-wrapped dynamic component from a passed named argument'] = function testItCanLocalLookupAReWrappedDynamicComponentFromAPassedNamedArgument() {
var _this7 = 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?');
(0, _internalTestHelpers.runTask)(function () {
return _this7.rerender();
});
this.assertText('yall finished or yall done?');
};
_proto['@test it can nest local lookups of dynamic components from a passed named argument'] = function testItCanNestLocalLookupsOfDynamicComponentsFromAPassedNamedArgument() {
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}}{{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?');
(0, _internalTestHelpers.runTask)(function () {
return _this8.rerender();
});
this.assertText('yall finished or yall done?');
};
_proto['@test it can switch from local to global lookups of dynamic components from a passed named argument'] = function testItCanSwitchFromLocalToGlobalLookupsOfDynamicComponentsFromAPassedNamedArgument() {
var _this9 = 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?');
(0, _internalTestHelpers.runTask)(function () {
return _this9.context.set('bar', 'global-bar');
});
(0, _internalTestHelpers.runTask)(function () {
return _this9.rerender();
});
this.assertText('yall finished or yall ready?');
};
_proto['@test it can lookup a local helper'] = function testItCanLookupALocalHelper() {
var _this10 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this10.rerender();
});
this.assertText('Who dat? Who dis?', 'Re-render works');
};
_proto['@test it overrides global helper lookup'] = function testItOverridesGlobalHelperLookup() {
var _this11 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this11.rerender();
});
this.assertText('Who dat? Who dis? I dunno', 'Re-render works');
};
_proto['@test lookup without match issues standard assertion (with local helper name)'] = function testLookupWithoutMatchIssuesStandardAssertionWithLocalHelperName() {
var _this12 = this;
this.registerComponent('x-outer', {
template: '{{#x-inner}}Hi!{{/x-inner}}'
});
expectAssertion(function () {
_this12.render('{{x-outer}}');
}, /A component or helper named "x-inner" could not be found/);
};
_proto['@test overrides global lookup'] = function testOverridesGlobalLookup() {
var _this13 = 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!');
(0, _internalTestHelpers.runTask)(function () {
return _this13.rerender();
});
this.assertText('Nested template says (from global): Hi! Nested template says (from local): Hi! Nested template says (from local): Hi!');
};
return LocalLookupTest;
}(_internalTestHelpers.RenderingTestCase); // first run these tests with expandLocalLookup
function buildResolver() {
var resolver = {
resolve: function () {},
expandLocalLookup: function (fullName, sourceFullName) {
if (!sourceFullName) {
return null;
}
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];
sourceName = sourceName.replace('my-app/', '');
if (sourceType === 'template' && sourceName.slice(0, 21) === 'templates/components/') {
sourceName = sourceName.slice(21);
}
name = name.replace('my-app/', '');
if (type === 'template' && name.slice(0, 11) === 'components/') {
name = name.slice(11);
sourceName = "components/" + sourceName;
}
sourceName = sourceName.replace('.hbs', '');
var result = type + ":" + sourceName + "/" + name;
return result;
}
};
return resolver;
}
(0, _internalTestHelpers.moduleFor)('Components test: local lookup with expandLocalLookup feature',
/*#__PURE__*/
function (_LocalLookupTest) {
(0, _emberBabel.inheritsLoose)(_class, _LocalLookupTest);
function _class() {
return _LocalLookupTest.apply(this, arguments) || this;
}
var _proto2 = _class.prototype;
_proto2.getResolver = function getResolver() {
return buildResolver();
};
return _class;
}(LocalLookupTest));
if (false
/* EMBER_MODULE_UNIFICATION */
) {
var LocalLookupTestResolver =
/*#__PURE__*/
function (_ModuleBasedTestResol) {
(0, _emberBabel.inheritsLoose)(LocalLookupTestResolver, _ModuleBasedTestResol);
function LocalLookupTestResolver() {
return _ModuleBasedTestResol.apply(this, arguments) || this;
}
var _proto3 = LocalLookupTestResolver.prototype;
_proto3.expandLocalLookup = function expandLocalLookup(specifier, source) {
if (source && source.indexOf('components/') !== -1) {
var namespace = source.split('components/')[1];
var _specifier$split = specifier.split(':'),
type = _specifier$split[0],
name = _specifier$split[1];
name = name.replace('components/', '');
namespace = namespace.replace('.hbs', '');
return type + ":" + (type === 'template' ? 'components/' : '') + namespace + "/" + name;
}
return _ModuleBasedTestResol.prototype.expandLocalLookup.call(this, specifier, source);
};
return LocalLookupTestResolver;
}(_internalTestHelpers.ModuleBasedTestResolver);
/*
* This sub-classing changes `registerXXX` methods to use the resolver.
* Required for testing the module unification-friendly `resolve` call
* with a `referrer` argument.
*
* In theory all these tests can be ported to use the resolver instead of
* the registry.
*/
(0, _internalTestHelpers.moduleFor)('Components test: local lookup with resolution referrer',
/*#__PURE__*/
function (_LocalLookupTest2) {
(0, _emberBabel.inheritsLoose)(_class2, _LocalLookupTest2);
function _class2() {
return _LocalLookupTest2.apply(this, arguments) || this;
}
var _proto4 = _class2.prototype;
_proto4.getResolver = function getResolver() {
return new LocalLookupTestResolver();
};
_proto4.registerComponent = function registerComponent(name, _ref) {
var _ref$ComponentClass = _ref.ComponentClass,
ComponentClass = _ref$ComponentClass === void 0 ? _helpers.Component : _ref$ComponentClass,
_ref$template = _ref.template,
template = _ref$template === void 0 ? null : _ref$template;
var resolver = this.resolver;
if (ComponentClass) {
resolver.add("component:" + name, ComponentClass);
}
if (typeof template === 'string') {
resolver.add("template:components/" + name, this.compile(template, {
moduleName: "my-name/templates/components/" + name + ".hbs"
}));
}
};
_proto4.registerTemplate = function registerTemplate(name, template) {
var resolver = this.resolver;
if (typeof template === 'string') {
resolver.add("template:" + name, this.compile(template, {
moduleName: "my-name/templates/" + name + ".hbs"
}));
} else {
throw new Error("Registered template \"" + name + "\" must be a string");
}
};
_proto4.registerHelper = function registerHelper(name, funcOrClassBody) {
var resolver = this.resolver;
var type = typeof funcOrClassBody;
if (type === 'function') {
resolver.add("helper:" + name, (0, _glimmer.helper)(funcOrClassBody));
} else if (type === 'object' && type !== null) {
resolver.add("helper:" + name, _glimmer.Helper.extend(funcOrClassBody));
} else {
throw new Error("Cannot register " + funcOrClassBody + " as a helper");
}
};
(0, _emberBabel.createClass)(_class2, [{
key: "resolver",
get: function () {
return this.owner.__registry__.fallback.resolver;
}
}]);
return _class2;
}(LocalLookupTest));
}
if (false
/* EMBER_MODULE_UNIFICATION */
) {
(0, _internalTestHelpers.moduleFor)('Components test: local lookup with resolution referrer (MU)',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class3, _ApplicationTestCase);
function _class3() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto5 = _class3.prototype;
_proto5['@test Ensure that the same specifier with two sources does not share a cache key'] = function testEnsureThatTheSameSpecifierWithTwoSourcesDoesNotShareACacheKey(assert) {
var _this14 = this;
this.add({
specifier: 'template:components/x-not-shared',
source: 'template:my-app/templates/components/x-top.hbs'
}, (0, _emberTemplateCompiler.compile)('child-x-not-shared'));
this.add({
specifier: 'template:components/x-top',
source: 'template:my-app/templates/application.hbs'
}, (0, _emberTemplateCompiler.compile)('top-level-x-top ({{x-not-shared}})', {
moduleName: 'my-app/templates/components/x-top.hbs'
}));
this.add({
specifier: 'template:components/x-not-shared',
source: 'template:my-app/templates/application.hbs'
}, (0, _emberTemplateCompiler.compile)('top-level-x-not-shared'));
this.addTemplate('application', '{{x-not-shared}} {{x-top}} {{x-not-shared}} {{x-top}}');
return this.visit('/').then(function () {
assert.equal(_this14.element.textContent, 'top-level-x-not-shared top-level-x-top (child-x-not-shared) top-level-x-not-shared top-level-x-top (child-x-not-shared)');
});
};
return _class3;
}(_internalTestHelpers.ApplicationTestCase));
}
});
enifed("@ember/-internals/glimmer/tests/integration/components/namespaced-lookup-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/glimmer"], function (_emberBabel, _internalTestHelpers, _glimmer) {
"use strict";
if (false
/* EMBER_MODULE_UNIFICATION */
) {
(0, _internalTestHelpers.moduleFor)('Namespaced lookup',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test it can render a namespaced component'] = function testItCanRenderANamespacedComponent() {
var _this = this;
this.addTemplate({
specifier: 'template:components/my-component',
namespace: 'my-addon'
}, 'namespaced template {{myProp}}');
this.add({
specifier: 'component:my-component',
namespace: 'my-addon'
}, _glimmer.Component.extend({
myProp: 'My property'
}));
this.addComponent('x-outer', {
template: '{{my-addon::my-component}}'
});
this.render('{{x-outer}}');
this.assertText('namespaced template My property');
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
this.assertText('namespaced template My property');
};
_proto['@test it can render a nested namespaced component'] = function testItCanRenderANestedNamespacedComponent() {
var _this2 = this;
this.addTemplate({
specifier: 'template:components/my-component',
namespace: 'second-addon'
}, 'second namespaced template');
this.addTemplate({
specifier: 'template:components/my-component',
namespace: 'first-addon'
}, 'first namespaced template - {{second-addon::my-component}}');
this.addComponent('x-outer', {
template: '{{first-addon::my-component}}'
});
this.render('{{x-outer}}');
this.assertText('first namespaced template - second namespaced template');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertText('first namespaced template - second namespaced template');
};
_proto['@test it can render a nested un-namespaced component'] = function testItCanRenderANestedUnNamespacedComponent() {
var _this3 = this;
this.addTemplate({
specifier: 'template:components/addon-component',
source: 'template:first-addon/src/ui/components/my-component.hbs'
}, 'un-namespaced addon template');
this.addTemplate({
specifier: 'template:components/my-component',
moduleName: 'first-addon/src/ui/components/my-component.hbs',
namespace: 'first-addon'
}, '{{addon-component}}');
this.addComponent('x-outer', {
template: '{{first-addon::my-component}}'
});
this.render('{{x-outer}}');
this.assertText('un-namespaced addon template');
(0, _internalTestHelpers.runTask)(function () {
return _this3.rerender();
});
this.assertText('un-namespaced addon template');
};
_proto['@test it can render a namespaced main component'] = function testItCanRenderANamespacedMainComponent() {
var _this4 = this;
this.addTemplate({
specifier: 'template:components/addon-component',
soruce: 'template:first-addon/src/ui/components/main.hbs'
}, 'Nested namespaced component');
this.addTemplate({
specifier: 'template:components/first-addon',
moduleName: 'first-addon/src/ui/components/main.hbs'
}, '{{addon-component}}');
this.addComponent('x-outer', {
template: '{{first-addon}}'
});
this.render('{{x-outer}}');
this.assertText('Nested namespaced component');
(0, _internalTestHelpers.runTask)(function () {
return _this4.rerender();
});
this.assertText('Nested namespaced component');
};
_proto['@test it does not render a main component when using a namespace'] = function testItDoesNotRenderAMainComponentWhenUsingANamespace() {
var _this5 = this;
this.addTemplate({
specifier: 'template:components/main',
namespace: 'my-addon'
}, 'namespaced template {{myProp}}');
this.add({
specifier: 'component:main',
namespace: 'my-addon'
}, _glimmer.Component.extend({
myProp: 'My property'
}));
this.add({
specifier: 'helper:my-addon',
namespace: 'empty-namespace'
}, (0, _glimmer.helper)(function () {
return 'my helper';
}));
this.render('{{empty-namespace::my-addon}}');
this.assertText('my helper'); // component should be not found
(0, _internalTestHelpers.runTask)(function () {
return _this5.rerender();
});
this.assertText('my helper');
};
_proto['@test it renders a namespaced helper'] = function testItRendersANamespacedHelper() {
var _this6 = this;
this.add({
specifier: 'helper:my-helper',
namespace: 'my-namespace'
}, (0, _glimmer.helper)(function () {
return 'my helper';
}));
this.render('{{my-namespace::my-helper}}');
this.assertText('my helper');
(0, _internalTestHelpers.runTask)(function () {
return _this6.rerender();
});
this.assertText('my helper');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
}
});
enifed("@ember/-internals/glimmer/tests/integration/components/render-to-element-test", [], function () {
"use strict";
});
enifed("@ember/-internals/glimmer/tests/integration/components/target-action-test", ["ember-babel", "internal-test-helpers", "@ember/polyfills", "@ember/-internals/metal", "@ember/controller", "@ember/-internals/runtime", "@ember/-internals/routing", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _polyfills, _metal, _controller, _runtime, _routing, _helpers) {
"use strict";
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#component-a}}\n {{component-b bar=\"derp\"}}\n {{/component-a}}\n "]);
_templateObject = function () {
return data;
};
return data;
}
function expectSendActionDeprecation(fn) {
expectDeprecation(fn, /You called (.*).sendAction\((.*)\) but Component#sendAction is deprecated. Please use closure actions instead./);
}
(0, _internalTestHelpers.moduleFor)('Components test: sendAction',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
var _this;
_this = _RenderingTestCase.apply(this, arguments) || this;
_this.actionCounts = {};
_this.sendCount = 0;
_this.actionArguments = null;
var self = (0, _emberBabel.assertThisInitialized)((0, _emberBabel.assertThisInitialized)(_this));
_this.registerComponent('action-delegate', {
ComponentClass: _helpers.Component.extend({
init: function () {
this._super();
self.delegate = this;
this.name = 'action-delegate';
}
})
});
return _this;
}
var _proto = _class.prototype;
_proto.renderDelegate = function renderDelegate() {
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, _polyfills.assign)(context, {
send: function (actionName) {
root.sendCount++;
root.actionCounts[actionName] = root.actionCounts[actionName] || 0;
root.actionCounts[actionName]++;
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
root.actionArguments = args;
}
});
this.render(template, context);
};
_proto.assertSendCount = function assertSendCount(count) {
this.assert.equal(this.sendCount, count, "Send was called " + count + " time(s)");
};
_proto.assertNamedSendCount = function assertNamedSendCount(actionName, count) {
this.assert.equal(this.actionCounts[actionName], count, "An action named '" + actionName + "' was sent " + count + " times");
};
_proto.assertSentWithArgs = function assertSentWithArgs(expected) {
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'arguments were sent with the action';
this.assert.deepEqual(this.actionArguments, expected, message);
};
_proto['@test Calling sendAction on a component without an action defined does nothing'] = function testCallingSendActionOnAComponentWithoutAnActionDefinedDoesNothing() {
var _this2 = this;
this.renderDelegate();
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
return _this2.delegate.sendAction();
});
});
this.assertSendCount(0);
};
_proto['@test Calling sendAction on a component with an action defined calls send on the controller'] = function testCallingSendActionOnAComponentWithAnActionDefinedCallsSendOnTheController() {
var _this3 = this;
this.renderDelegate();
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this3.delegate, 'action', 'addItem');
_this3.delegate.sendAction();
});
});
this.assertSendCount(1);
this.assertNamedSendCount('addItem', 1);
};
_proto['@test Calling sendAction on a component with a function calls the function'] = function testCallingSendActionOnAComponentWithAFunctionCallsTheFunction() {
var _this4 = this;
this.assert.expect(2);
this.renderDelegate();
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this4.delegate, 'action', function () {
return _this4.assert.ok(true, 'function is called');
});
_this4.delegate.sendAction();
});
});
};
_proto['@test Calling sendAction on a component with a function calls the function with arguments'] = function testCallingSendActionOnAComponentWithAFunctionCallsTheFunctionWithArguments() {
var _this5 = this;
this.assert.expect(2);
var argument = {};
this.renderDelegate();
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this5.delegate, 'action', function (actualArgument) {
_this5.assert.deepEqual(argument, actualArgument, 'argument is passed');
});
_this5.delegate.sendAction('action', argument);
});
});
} // TODO consolidate these next 2 tests
;
_proto['@test Calling sendAction on a component with a reference attr calls the function with arguments'] = function testCallingSendActionOnAComponentWithAReferenceAttrCallsTheFunctionWithArguments() {
var _this6 = this;
this.renderDelegate('{{action-delegate playing=playing}}', {
playing: null
});
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
return _this6.delegate.sendAction();
});
});
this.assertSendCount(0);
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this6.context, 'playing', 'didStartPlaying');
});
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
_this6.delegate.sendAction('playing');
});
});
this.assertSendCount(1);
this.assertNamedSendCount('didStartPlaying', 1);
};
_proto['@test Calling sendAction on a component with a {{mut}} attr calls the function with arguments'] = function testCallingSendActionOnAComponentWithAMutAttrCallsTheFunctionWithArguments() {
var _this7 = this;
this.renderDelegate('{{action-delegate playing=(mut playing)}}', {
playing: null
});
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
return _this7.delegate.sendAction('playing');
});
});
this.assertSendCount(0);
(0, _internalTestHelpers.runTask)(function () {
return _this7.delegate.attrs.playing.update('didStartPlaying');
});
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
return _this7.delegate.sendAction('playing');
});
});
this.assertSendCount(1);
this.assertNamedSendCount('didStartPlaying', 1);
};
_proto["@test Calling sendAction with a named action uses the component's property as the action name"] = function testCallingSendActionWithANamedActionUsesTheComponentSPropertyAsTheActionName() {
var _this8 = this;
this.renderDelegate();
var component = this.delegate;
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this8.delegate, 'playing', 'didStartPlaying');
component.sendAction('playing');
});
});
this.assertSendCount(1);
this.assertNamedSendCount('didStartPlaying', 1);
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
return component.sendAction('playing');
});
});
this.assertSendCount(2);
this.assertNamedSendCount('didStartPlaying', 2);
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(component, 'action', 'didDoSomeBusiness');
component.sendAction();
});
});
this.assertSendCount(3);
this.assertNamedSendCount('didDoSomeBusiness', 1);
};
_proto['@test Calling sendAction when the action name is not a string raises an exception'] = function testCallingSendActionWhenTheActionNameIsNotAStringRaisesAnException() {
var _this9 = this;
this.renderDelegate();
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this9.delegate, 'action', {});
(0, _metal.set)(_this9.delegate, 'playing', {});
});
expectSendActionDeprecation(function () {
expectAssertion(function () {
return _this9.delegate.sendAction();
});
});
expectSendActionDeprecation(function () {
expectAssertion(function () {
return _this9.delegate.sendAction('playing');
});
});
};
_proto['@test Calling sendAction on a component with contexts'] = function testCallingSendActionOnAComponentWithContexts() {
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'
};
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.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');
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.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');
};
_proto['@test calling sendAction on a component within a block sends to the outer scope GH#14216'] = function testCallingSendActionOnAComponentWithinABlockSendsToTheOuterScopeGH14216(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, _internalTestHelpers.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;
this.registerComponent('component-b', {
ComponentClass: _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerChild = this;
this.name = 'component-b';
}
})
});
this.renderDelegate();
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
return innerChild.sendAction('bar', 'something special');
});
});
};
_proto['@test asserts if called on a destroyed component'] = function testAssertsIfCalledOnADestroyedComponent() {
var _this11 = this;
var component;
this.registerComponent('rip-alley', {
ComponentClass: _helpers.Component.extend({
init: function () {
this._super();
component = this;
},
toString: function () {
return 'component:rip-alley';
}
})
});
this.render('{{#if shouldRender}}{{rip-alley}}{{/if}}', {
shouldRender: true
});
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this11.context, 'shouldRender', false);
});
expectAssertion(function () {
component.sendAction('trigger-me-dead');
}, "Attempted to call .sendAction() with the action 'trigger-me-dead' on the destroyed object 'component:rip-alley'.");
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
(0, _internalTestHelpers.moduleFor)('Components test: sendAction to a controller',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class2, _ApplicationTestCase);
function _class2() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2["@test sendAction should trigger an action on the parent component's controller if it exists"] = function testSendActionShouldTriggerAnActionOnTheParentComponentSControllerIfItExists(assert) {
var _this12 = this;
assert.expect(20);
var component;
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', _controller.default.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', _routing.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', _routing.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', _routing.Route.extend({}));
this.add('controller:c.d', _controller.default.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', _routing.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 () {
expectSendActionDeprecation(function () {
return component.sendAction('poke', 'top');
});
}).then(function () {
_this12.assertText('a');
return _this12.visit('/b');
}).then(function () {
expectSendActionDeprecation(function () {
return component.sendAction('poke', 'top no controller');
});
}).then(function () {
_this12.assertText('b');
return _this12.visit('/c');
}).then(function () {
expectSendActionDeprecation(function () {
component.sendAction('poke', 'top with nested no controller');
});
}).then(function () {
_this12.assertText('c');
return _this12.visit('/c/d');
}).then(function () {
expectSendActionDeprecation(function () {
return component.sendAction('poke', 'nested');
});
}).then(function () {
_this12.assertText('c.d');
return _this12.visit('/c/e');
}).then(function () {
expectSendActionDeprecation(function () {
return component.sendAction('poke', 'nested no controller');
});
}).then(function () {
return _this12.assertText('c.e');
});
};
_proto2["@test sendAction should not trigger an action in an outlet's controller if a parent component handles it"] = function testSendActionShouldNotTriggerAnActionInAnOutletSControllerIfAParentComponentHandlesIt(assert) {
assert.expect(2);
var component;
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', _controller.default.extend({
send: function () {
throw new Error('controller action should not be called');
}
}));
return this.visit('/').then(function () {
expectSendActionDeprecation(function () {
return component.sendAction('poke');
});
});
};
return _class2;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Components test: sendAction of a closure action',
/*#__PURE__*/
function (_RenderingTestCase2) {
(0, _emberBabel.inheritsLoose)(_class3, _RenderingTestCase2);
function _class3() {
return _RenderingTestCase2.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3['@test action should be called'] = function testActionShouldBeCalled(assert) {
assert.expect(2);
var component;
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}}');
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
return component.sendAction('submitAction');
});
});
};
_proto3['@test contexts passed to sendAction are appended to the bound arguments on a closure action'] = function testContextsPassedToSendActionAreAppendedToTheBoundArgumentsOnAClosureAction() {
var first = 'mitch';
var second = 'martin';
var third = 'matt';
var fourth = 'wacky wycats';
var innerComponent;
var actualArgs;
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 = Array.prototype.slice.call(arguments);
}
}
}),
template: "{{inner-component innerSubmit=(action (action \"outerSubmit\" \"" + first + "\") \"" + second + "\" third)}}"
});
this.render('{{outer-component}}');
expectSendActionDeprecation(function () {
(0, _internalTestHelpers.runTask)(function () {
return innerComponent.sendAction('innerSubmit', fourth);
});
});
this.assert.deepEqual(actualArgs, [first, second, third, fourth], 'action has the correct args');
};
return _class3;
}(_internalTestHelpers.RenderingTestCase));
(0, _internalTestHelpers.moduleFor)('Components test: send',
/*#__PURE__*/
function (_RenderingTestCase3) {
(0, _emberBabel.inheritsLoose)(_class4, _RenderingTestCase3);
function _class4() {
return _RenderingTestCase3.apply(this, arguments) || this;
}
var _proto4 = _class4.prototype;
_proto4['@test sending to undefined actions triggers an error'] = function testSendingToUndefinedActionsTriggersAnError(assert) {
assert.expect(2);
var component;
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}}');
(0, _internalTestHelpers.runTask)(function () {
return component.send('foo', 'bar');
});
expectAssertion(function () {
return component.send('baz', 'bar');
}, /had no action handler for: baz/);
};
_proto4['@test `send` will call send from a target if it is defined'] = function testSendWillCallSendFromATargetIfItIsDefined() {
var _this13 = this;
var component;
var target = {
send: function (message, payload) {
_this13.assert.equal('foo', message);
_this13.assert.equal('baz', payload);
}
};
this.registerComponent('foo-bar', {
ComponentClass: _helpers.Component.extend({
init: function () {
this._super();
component = this;
},
target: target
})
});
this.render('{{foo-bar}}');
(0, _internalTestHelpers.runTask)(function () {
return component.send('foo', 'baz');
});
};
_proto4['@test a handled action can be bubbled to the target for continued processing'] = function testAHandledActionCanBeBubbledToTheTargetForContinuedProcessing() {
var _this14 = this;
this.assert.expect(2);
var component;
this.registerComponent('foo-bar', {
ComponentClass: _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
actions: {
poke: function () {
_this14.assert.ok(true, 'component action called');
return true;
}
},
target: _controller.default.extend({
actions: {
poke: function () {
_this14.assert.ok(true, 'action bubbled to controller');
}
}
}).create()
})
});
this.render('{{foo-bar poke="poke"}}');
(0, _internalTestHelpers.runTask)(function () {
return component.send('poke');
});
};
_proto4["@test action can be handled by a superclass' actions object"] = function testActionCanBeHandledByASuperclassActionsObject(assert) {
this.assert.expect(4);
var component;
var SuperComponent = _helpers.Component.extend({
actions: {
foo: function () {
assert.ok(true, 'foo');
},
bar: function (msg) {
assert.equal(msg, 'HELLO');
}
}
});
var BarViewMixin = _metal.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}}');
(0, _internalTestHelpers.runTask)(function () {
component.send('foo');
component.send('bar', 'HELLO');
component.send('baz');
});
};
_proto4['@test actions cannot be provided at create time'] = function testActionsCannotBeProvidedAtCreateTime(assert) {
this.registerComponent('foo-bar', _helpers.Component.extend());
var ComponentFactory = this.owner.factoryFor('component:foo-bar');
expectAssertion(function () {
ComponentFactory.create({
actions: {
foo: function () {
assert.ok(true, 'foo');
}
}
});
}, /`actions` must be provided at extend time, not at create time/); // but should be OK on an object that doesn't mix in Ember.ActionHandler
_runtime.Object.create({
actions: ['foo']
});
};
_proto4['@test asserts if called on a destroyed component'] = function testAssertsIfCalledOnADestroyedComponent() {
var _this15 = this;
var component;
this.registerComponent('rip-alley', {
ComponentClass: _helpers.Component.extend({
init: function () {
this._super();
component = this;
},
toString: function () {
return 'component:rip-alley';
}
})
});
this.render('{{#if shouldRender}}{{rip-alley}}{{/if}}', {
shouldRender: true
});
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this15.context, 'shouldRender', false);
});
expectAssertion(function () {
component.send('trigger-me-dead');
}, "Attempted to call .send() with the action 'trigger-me-dead' on the destroyed object 'component:rip-alley'.");
};
return _class4;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/components/template-only-components-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/environment"], function (_emberBabel, _internalTestHelpers, _environment) {
"use strict";
var TemplateOnlyComponentsTest =
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(TemplateOnlyComponentsTest, _RenderingTestCase);
function TemplateOnlyComponentsTest() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = TemplateOnlyComponentsTest.prototype;
_proto.registerComponent = function registerComponent(name, template) {
_RenderingTestCase.prototype.registerComponent.call(this, name, {
template: template,
ComponentClass: null
});
};
return TemplateOnlyComponentsTest;
}(_internalTestHelpers.RenderingTestCase);
(0, _internalTestHelpers.moduleFor)('Components test: template-only components (glimmer components)',
/*#__PURE__*/
function (_TemplateOnlyComponen) {
(0, _emberBabel.inheritsLoose)(_class, _TemplateOnlyComponen);
function _class() {
var _this;
_this = _TemplateOnlyComponen.apply(this, arguments) || this;
_this._TEMPLATE_ONLY_GLIMMER_COMPONENTS = _environment.ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS;
_environment.ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS = true;
return _this;
}
var _proto2 = _class.prototype;
_proto2.teardown = function teardown() {
_TemplateOnlyComponen.prototype.teardown.call(this);
_environment.ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS = this._TEMPLATE_ONLY_GLIMMER_COMPONENTS;
};
_proto2['@test it can render a template-only component'] = function testItCanRenderATemplateOnlyComponent() {
this.registerComponent('foo-bar', 'hello');
this.render('{{foo-bar}}');
this.assertInnerHTML('hello');
this.assertStableRerender();
};
_proto2['@feature(ember-glimmer-named-arguments) it can render named arguments'] = function featureEmberGlimmerNamedArgumentsItCanRenderNamedArguments() {
var _this2 = this;
this.registerComponent('foo-bar', '|{{@foo}}|{{@bar}}|');
this.render('{{foo-bar foo=foo bar=bar}}', {
foo: 'foo',
bar: 'bar'
});
this.assertInnerHTML('|foo|bar|');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this2.context.set('foo', 'FOO');
});
this.assertInnerHTML('|FOO|bar|');
(0, _internalTestHelpers.runTask)(function () {
return _this2.context.set('bar', 'BAR');
});
this.assertInnerHTML('|FOO|BAR|');
(0, _internalTestHelpers.runTask)(function () {
return _this2.context.setProperties({
foo: 'foo',
bar: 'bar'
});
});
this.assertInnerHTML('|foo|bar|');
};
_proto2['@test it does not reflected arguments as properties'] = function testItDoesNotReflectedArgumentsAsProperties() {
var _this3 = this;
this.registerComponent('foo-bar', '|{{foo}}|{{this.bar}}|');
this.render('{{foo-bar foo=foo bar=bar}}', {
foo: 'foo',
bar: 'bar'
});
this.assertInnerHTML('|||');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this3.context.set('foo', 'FOO');
});
this.assertInnerHTML('|||');
(0, _internalTestHelpers.runTask)(function () {
return _this3.context.set('bar', null);
});
this.assertInnerHTML('|||');
(0, _internalTestHelpers.runTask)(function () {
return _this3.context.setProperties({
foo: 'foo',
bar: 'bar'
});
});
this.assertInnerHTML('|||');
};
_proto2['@test it does not have curly component features'] = function testItDoesNotHaveCurlyComponentFeatures() {
var _this4 = this;
this.registerComponent('foo-bar', 'hello');
this.render('{{foo-bar tagName="p" class=class}}', {
class: 'foo bar'
});
this.assertInnerHTML('hello');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this4.context.set('class', 'foo');
});
this.assertInnerHTML('hello');
(0, _internalTestHelpers.runTask)(function () {
return _this4.context.set('class', null);
});
this.assertInnerHTML('hello');
(0, _internalTestHelpers.runTask)(function () {
return _this4.context.set('class', 'foo bar');
});
this.assertInnerHTML('hello');
};
return _class;
}(TemplateOnlyComponentsTest));
(0, _internalTestHelpers.moduleFor)('Components test: template-only components (curly components)',
/*#__PURE__*/
function (_TemplateOnlyComponen2) {
(0, _emberBabel.inheritsLoose)(_class2, _TemplateOnlyComponen2);
function _class2() {
var _this5;
_this5 = _TemplateOnlyComponen2.apply(this, arguments) || this;
_this5._TEMPLATE_ONLY_GLIMMER_COMPONENTS = _environment.ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS;
_environment.ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS = false;
return _this5;
}
var _proto3 = _class2.prototype;
_proto3.teardown = function teardown() {
_TemplateOnlyComponen2.prototype.teardown.call(this);
_environment.ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS = this._TEMPLATE_ONLY_GLIMMER_COMPONENTS;
};
_proto3['@test it can render a template-only component'] = function testItCanRenderATemplateOnlyComponent() {
this.registerComponent('foo-bar', 'hello');
this.render('{{foo-bar}}');
this.assertComponentElement(this.firstChild, {
content: 'hello'
});
this.assertStableRerender();
};
_proto3['@feature(ember-glimmer-named-arguments) it can render named arguments'] = function featureEmberGlimmerNamedArgumentsItCanRenderNamedArguments() {
var _this6 = this;
this.registerComponent('foo-bar', '|{{@foo}}|{{@bar}}|');
this.render('{{foo-bar foo=foo bar=bar}}', {
foo: 'foo',
bar: 'bar'
});
this.assertComponentElement(this.firstChild, {
content: '|foo|bar|'
});
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this6.context.set('foo', 'FOO');
});
this.assertComponentElement(this.firstChild, {
content: '|FOO|bar|'
});
(0, _internalTestHelpers.runTask)(function () {
return _this6.context.set('bar', 'BAR');
});
this.assertComponentElement(this.firstChild, {
content: '|FOO|BAR|'
});
(0, _internalTestHelpers.runTask)(function () {
return _this6.context.setProperties({
foo: 'foo',
bar: 'bar'
});
});
this.assertComponentElement(this.firstChild, {
content: '|foo|bar|'
});
};
_proto3['@test it renders named arguments as reflected properties'] = function testItRendersNamedArgumentsAsReflectedProperties() {
var _this7 = this;
this.registerComponent('foo-bar', '|{{foo}}|{{this.bar}}|');
this.render('{{foo-bar foo=foo bar=bar}}', {
foo: 'foo',
bar: 'bar'
});
this.assertComponentElement(this.firstChild, {
content: '|foo|bar|'
});
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this7.context.set('foo', 'FOO');
});
this.assertComponentElement(this.firstChild, {
content: '|FOO|bar|'
});
(0, _internalTestHelpers.runTask)(function () {
return _this7.context.set('bar', null);
});
this.assertComponentElement(this.firstChild, {
content: '|FOO||'
});
(0, _internalTestHelpers.runTask)(function () {
return _this7.context.setProperties({
foo: 'foo',
bar: 'bar'
});
});
this.assertComponentElement(this.firstChild, {
content: '|foo|bar|'
});
};
_proto3['@test it has curly component features'] = function testItHasCurlyComponentFeatures() {
var _this8 = this;
this.registerComponent('foo-bar', 'hello');
this.render('{{foo-bar tagName="p" class=class}}', {
class: 'foo bar'
});
this.assertComponentElement(this.firstChild, {
tagName: 'p',
attrs: {
class: (0, _internalTestHelpers.classes)('foo bar ember-view')
},
content: 'hello'
});
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this8.context.set('class', 'foo');
});
this.assertComponentElement(this.firstChild, {
tagName: 'p',
attrs: {
class: (0, _internalTestHelpers.classes)('foo ember-view')
},
content: 'hello'
});
(0, _internalTestHelpers.runTask)(function () {
return _this8.context.set('class', null);
});
this.assertComponentElement(this.firstChild, {
tagName: 'p',
attrs: {
class: (0, _internalTestHelpers.classes)('ember-view')
},
content: 'hello'
});
(0, _internalTestHelpers.runTask)(function () {
return _this8.context.set('class', 'foo bar');
});
this.assertComponentElement(this.firstChild, {
tagName: 'p',
attrs: {
class: (0, _internalTestHelpers.classes)('foo bar ember-view')
},
content: 'hello'
});
};
return _class2;
}(TemplateOnlyComponentsTest));
});
enifed("@ember/-internals/glimmer/tests/integration/components/to-string-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/glimmer"], function (_emberBabel, _internalTestHelpers, _glimmer) {
"use strict";
(0, _internalTestHelpers.moduleFor)('built-in component toString',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(AbstractAppendTest, _RenderingTestCase);
function AbstractAppendTest() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = AbstractAppendTest.prototype;
_proto['@test text-field has the correct toString value'] = function testTextFieldHasTheCorrectToStringValue(assert) {
assert.strictEqual(_glimmer.TextField.toString(), '@ember/component/text-field');
};
_proto['@test checkbox has the correct toString value'] = function testCheckboxHasTheCorrectToStringValue(assert) {
assert.strictEqual(_glimmer.Checkbox.toString(), '@ember/component/checkbox');
};
_proto['@test text-area has the correct toString value'] = function testTextAreaHasTheCorrectToStringValue(assert) {
assert.strictEqual(_glimmer.TextArea.toString(), '@ember/component/text-area');
};
_proto['@test component has the correct toString value'] = function testComponentHasTheCorrectToStringValue(assert) {
assert.strictEqual(_glimmer.Component.toString(), '@ember/component');
};
_proto['@test LinkTo has the correct toString value'] = function testLinkToHasTheCorrectToStringValue(assert) {
assert.strictEqual(_glimmer.LinkComponent.toString(), '@ember/routing/link-component');
};
return AbstractAppendTest;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/components/utils-test", ["ember-babel", "internal-test-helpers", "@ember/controller", "@ember/-internals/views", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _controller, _views, _helpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('View tree tests',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
var _this;
_this = _ApplicationTestCase.apply(this, arguments) || this;
_this.addComponent('x-tagless', {
ComponentClass: _helpers.Component.extend({
tagName: ''
}),
template: '
"
});
this.render("{{hi-mom}}");
var _getViewBounds = (0, _views.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');
};
_proto2['@test getViewBounds on a tagless component'] = function testGetViewBoundsOnATaglessComponent(assert) {
var component;
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, _views.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');
};
_proto2['@test getViewClientRects'] = function testGetViewClientRects(assert) {
if (!hasGetClientRects || !ClientRectListCtor) {
assert.ok(true, 'The test environment does not support the DOM API required to run this test.');
return;
}
var component;
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, _views.getViewClientRects)(component) instanceof ClientRectListCtor);
};
_proto2['@test getViewBoundingClientRect'] = function testGetViewBoundingClientRect(assert) {
if (!hasGetBoundingClientRect || !ClientRectCtor) {
assert.ok(true, 'The test environment does not support the DOM API required to run this test.');
return;
}
var component;
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, _views.getViewBoundingClientRect)(component) instanceof ClientRectCtor);
};
return _class2;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/components/web-component-fallback-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _metal) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Components test: web component fallback',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test custom elements are rendered'] = function testCustomElementsAreRendered() {
var template = "hello";
this.render(template);
this.assertHTML(template);
this.assertStableRerender();
};
_proto['@test custom elements can have bound attributes'] = function testCustomElementsCanHaveBoundAttributes() {
var _this = this;
var template = "hello";
this.render(template, {
name: 'Robert'
});
this.assertHTML("hello");
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'name', 'Kris');
});
this.assertHTML("hello");
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'name', 'Robert');
});
this.assertHTML("hello");
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/components/will-destroy-element-hook-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _metal, _helpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Component willDestroyElement hook',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test it calls willDestroyElement when removed by if'] = function testItCallsWillDestroyElementWhenRemovedByIf(assert) {
var _this = 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'
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'switch', false);
});
assert.equal(willDestroyElementCount, 1, 'willDestroyElement was called once');
this.assertText('');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/content-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/debug", "@ember/object/computed", "@ember/-internals/runtime", "@ember/-internals/views", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _metal, _debug, _computed, _runtime, _views, _helpers) {
"use strict";
/* globals EmberDev */
(0, _internalTestHelpers.moduleFor)('Static content tests',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test it can render a static text node'] = function testItCanRenderAStaticTextNode() {
var _this = this;
this.render('hello');
var text1 = this.assertTextNode(this.firstChild, 'hello');
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
var text2 = this.assertTextNode(this.firstChild, 'hello');
this.assertSameNode(text1, text2);
};
_proto['@test it can render a static element'] = function testItCanRenderAStaticElement() {
var _this2 = this;
this.render('
hello
');
var p1 = this.assertElement(this.firstChild, {
tagName: 'p'
});
var text1 = this.assertTextNode(this.firstChild.firstChild, 'hello');
(0, _internalTestHelpers.runTask)(function () {
return _this2.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);
};
_proto['@test it can render a static template'] = function testItCanRenderAStaticTemplate() {
var _this3 = this;
var template = "\n
\n
Welcome to Ember.js
\n
\n
\n
Why you should use Ember.js?
\n \n
It's great
\n
It's awesome
\n
It's Ember.js
\n \n
\n \n ";
this.render(template);
this.assertHTML(template);
(0, _internalTestHelpers.runTask)(function () {
return _this3.rerender();
});
this.assertHTML(template);
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
var DynamicContentTest =
/*#__PURE__*/
function (_RenderingTestCase2) {
(0, _emberBabel.inheritsLoose)(DynamicContentTest, _RenderingTestCase2);
function DynamicContentTest() {
return _RenderingTestCase2.apply(this, arguments) || this;
}
var _proto2 = DynamicContentTest.prototype;
/* abstract */
_proto2.renderPath = function renderPath()
/* path, context = {} */
{
throw new Error('Not implemented: `renderValues`');
};
_proto2.assertIsEmpty = function assertIsEmpty() {
this.assert.strictEqual(this.firstChild, null);
}
/* abstract */
;
_proto2.assertContent = function assertContent()
/* content */
{
throw new Error('Not implemented: `assertContent`');
};
_proto2['@test it can render a dynamic path'] = function testItCanRenderADynamicPath() {
var _this4 = this;
this.renderPath('message', {
message: 'hello'
});
this.assertContent('hello');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'message', 'goodbye');
});
this.assertContent('goodbye');
this.assertInvariants();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'message', 'hello');
});
this.assertContent('hello');
this.assertInvariants();
};
_proto2['@test resolves the string length properly'] = function testResolvesTheStringLengthProperly() {
var _this5 = this;
this.render('
");
};
_proto['@test it can render a basic component with custom component manager with a factory'] = function testItCanRenderABasicComponentWithCustomComponentManagerWithAFactory() {
var ComponentClass = (0, _glimmer.setComponentManager)(function () {
return BasicComponentManager.create();
}, _runtime.Object.extend({
greeting: 'hello'
}));
this.registerComponent('foo-bar', {
template: "
");
assert.verifySteps(['createComponent', 'getContext', 'didCreateComponent']);
(0, _internalTestHelpers.runTask)(function () {
return _this8.context.set('value', 'bar');
});
assert.verifySteps(['didUpdateComponent']);
};
return _class2;
}(ComponentManagerTest));
}
}
});
enifed("@ember/-internals/glimmer/tests/integration/custom-modifier-manager-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime", "@ember/-internals/glimmer", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _runtime, _glimmer, _metal) {
"use strict";
if (true
/* GLIMMER_MODIFIER_MANAGER */
) {
var ModifierManagerTest =
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(ModifierManagerTest, _RenderingTestCase);
function ModifierManagerTest() {
return _RenderingTestCase.apply(this, arguments) || this;
}
return ModifierManagerTest;
}(_internalTestHelpers.RenderingTestCase);
var CustomModifierManager =
/*#__PURE__*/
function () {
function CustomModifierManager(owner) {
this.owner = owner;
}
var _proto = CustomModifierManager.prototype;
_proto.createModifier = function createModifier(factory, args) {
return factory.create(args);
};
_proto.installModifier = function installModifier(instance, element, args) {
instance.element = element;
var positional = args.positional,
named = args.named;
instance.didInsertElement(positional, named);
};
_proto.updateModifier = function updateModifier(instance, args) {
var positional = args.positional,
named = args.named;
instance.didUpdate(positional, named);
};
_proto.destroyModifier = function destroyModifier(instance) {
instance.willDestroyElement();
};
return CustomModifierManager;
}();
(0, _internalTestHelpers.moduleFor)('Basic Custom Modifier Manager',
/*#__PURE__*/
function (_ModifierManagerTest) {
(0, _emberBabel.inheritsLoose)(_class, _ModifierManagerTest);
function _class() {
return _ModifierManagerTest.apply(this, arguments) || this;
}
var _proto2 = _class.prototype;
_proto2['@test can register a custom element modifier and render it'] = function testCanRegisterACustomElementModifierAndRenderIt(assert) {
var ModifierClass = (0, _glimmer.setModifierManager)(function (owner) {
return new CustomModifierManager(owner);
}, _runtime.Object.extend({
didInsertElement: function () {},
didUpdate: function () {},
willDestroyElement: function () {}
}));
this.registerModifier('foo-bar', ModifierClass.extend({
didInsertElement: function () {
assert.ok(true, 'Called didInsertElement');
}
}));
this.render('
hello world
');
this.assertHTML("
hello world
");
};
_proto2['@test custom lifecycle hooks'] = function testCustomLifecycleHooks(assert) {
var _this = this;
assert.expect(9);
var ModifierClass = (0, _glimmer.setModifierManager)(function (owner) {
return new CustomModifierManager(owner);
}, _runtime.Object.extend({
didInsertElement: function () {},
didUpdate: function () {},
willDestroyElement: function () {}
}));
this.registerModifier('foo-bar', ModifierClass.extend({
didUpdate: function (_ref) {
var truthy = _ref[0];
assert.ok(true, 'Called didUpdate');
assert.equal(truthy, 'true', 'gets updated args');
},
didInsertElement: function (_ref2) {
var truthy = _ref2[0];
assert.ok(true, 'Called didInsertElement');
assert.equal(truthy, true, 'gets initial args');
},
willDestroyElement: function () {
assert.ok(true, 'Called willDestroyElement');
}
}));
this.render('{{#if truthy}}
hello world
{{/if}}', {
truthy: true
});
this.assertHTML("
hello world
");
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'truthy', 'true');
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'truthy', false);
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'truthy', true);
});
};
_proto2['@test associates manager even through an inheritance structure'] = function testAssociatesManagerEvenThroughAnInheritanceStructure(assert) {
assert.expect(5);
var ModifierClass = (0, _glimmer.setModifierManager)(function (owner) {
return new CustomModifierManager(owner);
}, _runtime.Object.extend({
didInsertElement: function () {},
didUpdate: function () {},
willDestroyElement: function () {}
}));
ModifierClass = ModifierClass.extend({
didInsertElement: function (_ref3) {
var truthy = _ref3[0];
this._super.apply(this, arguments);
assert.ok(true, 'Called didInsertElement');
assert.equal(truthy, true, 'gets initial args');
}
});
this.registerModifier('foo-bar', ModifierClass.extend({
didInsertElement: function (_ref4) {
var truthy = _ref4[0];
this._super.apply(this, arguments);
assert.ok(true, 'Called didInsertElement');
assert.equal(truthy, true, 'gets initial args');
}
}));
this.render('
hello world
', {
truthy: true
});
this.assertHTML("
hello world
");
};
_proto2['@test can give consistent access to underlying DOM element'] = function testCanGiveConsistentAccessToUnderlyingDOMElement(assert) {
var _this2 = this;
assert.expect(4);
var ModifierClass = (0, _glimmer.setModifierManager)(function (owner) {
return new CustomModifierManager(owner);
}, _runtime.Object.extend({
didInsertElement: function () {},
didUpdate: function () {},
willDestroyElement: function () {}
}));
this.registerModifier('foo-bar', ModifierClass.extend({
savedElement: undefined,
didInsertElement: function () {
assert.equal(this.element.tagName, 'H1');
this.set('savedElement', this.element);
},
didUpdate: function () {
assert.equal(this.element, this.savedElement);
},
willDestroyElement: function () {
assert.equal(this.element, this.savedElement);
}
}));
this.render('
hello world
', {
truthy: true
});
this.assertHTML("
hello world
");
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'truthy', 'true');
});
};
return _class;
}(ModifierManagerTest));
}
});
enifed("@ember/-internals/glimmer/tests/integration/event-dispatcher-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/glimmer/tests/utils/helpers", "@ember/runloop", "@ember/instrumentation", "@ember/-internals/views", "@ember/-internals/utils"], function (_emberBabel, _internalTestHelpers, _helpers, _runloop, _instrumentation, _views, _utils) {
"use strict";
var canDataTransfer = Boolean(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, _internalTestHelpers.moduleFor)('EventDispatcher',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test events bubble view hierarchy for form elements'] = function testEventsBubbleViewHierarchyForFormElements(assert) {
var _this = this;
var receivedEvent;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
change: function (event) {
receivedEvent = event;
}
}),
template: ""
});
this.render("{{x-foo}}");
(0, _internalTestHelpers.runTask)(function () {
return _this.$('#is-done').trigger('change');
});
assert.ok(receivedEvent, 'change event was triggered');
assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]);
};
_proto['@test case insensitive events'] = function testCaseInsensitiveEvents(assert) {
var _this2 = this;
var receivedEvent;
this.registerComponent('x-bar', {
ComponentClass: _helpers.Component.extend({
clicked: function (event) {
receivedEvent = event;
}
}),
template: ""
});
this.render("{{x-bar}}");
(0, _internalTestHelpers.runTask)(function () {
return _this2.$('#is-done').trigger('click');
});
assert.ok(receivedEvent, 'change event was triggered');
assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]);
};
_proto['@test case sensitive events'] = function testCaseSensitiveEvents(assert) {
var _this3 = this;
var receivedEvent;
this.registerComponent('x-bar', {
ComponentClass: _helpers.Component.extend({
clicked: function (event) {
receivedEvent = event;
}
}),
template: ""
});
this.render("{{x-bar}}");
(0, _internalTestHelpers.runTask)(function () {
return _this3.$('#is-done').trigger('click');
});
assert.ok(receivedEvent, 'change event was triggered');
assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]);
};
_proto['@test events bubble to parent view'] = function testEventsBubbleToParentView(assert) {
var _this4 = this;
var receivedEvent;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
change: function (event) {
receivedEvent = event;
}
}),
template: "{{yield}}"
});
this.registerComponent('x-bar', {
ComponentClass: _helpers.Component.extend({
change: function () {}
}),
template: ""
});
this.render("{{#x-foo}}{{x-bar}}{{/x-foo}}");
(0, _internalTestHelpers.runTask)(function () {
return _this4.$('#is-done').trigger('change');
});
assert.ok(receivedEvent, 'change event was triggered');
assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]);
};
_proto['@test events bubbling up can be prevented'] = function testEventsBubblingUpCanBePrevented(assert) {
var _this5 = this;
var hasReceivedEvent;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
change: function () {
hasReceivedEvent = true;
}
}),
template: "{{yield}}"
});
this.registerComponent('x-bar', {
ComponentClass: _helpers.Component.extend({
change: function () {
return false;
}
}),
template: ""
});
this.render("{{#x-foo}}{{x-bar}}{{/x-foo}}");
(0, _internalTestHelpers.runTask)(function () {
return _this5.$('#is-done').trigger('change');
});
assert.notOk(hasReceivedEvent, 'change event has not been received');
};
_proto['@test event handlers are wrapped in a run loop'] = function testEventHandlersAreWrappedInARunLoop(assert) {
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
change: function () {
assert.ok((0, _runloop.getCurrentRunLoop)(), 'a run loop should have started');
}
}),
template: ""
});
this.render("{{x-foo}}");
this.$('#is-done').trigger('click');
};
_proto['@test delegated event listeners work for mouseEnter/Leave'] = function testDelegatedEventListenersWorkForMouseEnterLeave(assert) {
var _this6 = this;
var receivedEnterEvents = [];
var receivedLeaveEvents = [];
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
mouseEnter: function (event) {
receivedEnterEvents.push(event);
},
mouseLeave: function (event) {
receivedLeaveEvents.push(event);
}
}),
template: ""
});
this.render("{{x-foo id=\"outer\"}}");
var parent = this.element;
var outer = this.$('#outer')[0];
var inner = this.$('#inner')[0]; // mouse moves over #outer
(0, _internalTestHelpers.runTask)(function () {
_this6.$(outer).trigger('mouseenter', {
canBubble: false,
relatedTarget: parent
});
_this6.$(outer).trigger('mouseover', {
relatedTarget: parent
});
_this6.$(parent).trigger('mouseout', {
relatedTarget: outer
});
});
assert.equal(receivedEnterEvents.length, 1, 'mouseenter event was triggered');
assert.strictEqual(receivedEnterEvents[0].target, outer); // mouse moves over #inner
(0, _internalTestHelpers.runTask)(function () {
_this6.$(inner).trigger('mouseover', {
relatedTarget: outer
});
_this6.$(outer).trigger('mouseout', {
relatedTarget: inner
});
});
assert.equal(receivedEnterEvents.length, 1, 'mouseenter event was not triggered again'); // mouse moves out of #inner
(0, _internalTestHelpers.runTask)(function () {
_this6.$(inner).trigger('mouseout', {
relatedTarget: outer
});
_this6.$(outer).trigger('mouseover', {
relatedTarget: inner
});
});
assert.equal(receivedLeaveEvents.length, 0, 'mouseleave event was not triggered'); // mouse moves out of #outer
(0, _internalTestHelpers.runTask)(function () {
_this6.$(outer).trigger('mouseleave', {
canBubble: false,
relatedTarget: parent
});
_this6.$(outer).trigger('mouseout', {
relatedTarget: parent
});
_this6.$(parent).trigger('mouseover', {
relatedTarget: outer
});
});
assert.equal(receivedLeaveEvents.length, 1, 'mouseleave event was triggered');
assert.strictEqual(receivedLeaveEvents[0].target, outer);
};
_proto['@test delegated event listeners work for mouseEnter on SVG elements'] = function testDelegatedEventListenersWorkForMouseEnterOnSVGElements(assert) {
var _this7 = this;
var receivedEnterEvents = [];
var receivedLeaveEvents = [];
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
tagName: 'svg',
mouseEnter: function (event) {
receivedEnterEvents.push(event);
},
mouseLeave: function (event) {
receivedLeaveEvents.push(event);
}
}),
template: ""
});
this.render("{{x-foo id=\"outer\"}}");
var parent = this.element;
var outer = this.$('#outer')[0];
var inner = this.$('#inner')[0]; // mouse moves over #outer
(0, _internalTestHelpers.runTask)(function () {
_this7.$(outer).trigger('mouseenter', {
canBubble: false,
relatedTarget: parent
});
_this7.$(outer).trigger('mouseover', {
relatedTarget: parent
});
_this7.$(parent).trigger('mouseout', {
relatedTarget: outer
});
});
assert.equal(receivedEnterEvents.length, 1, 'mouseenter event was triggered');
assert.strictEqual(receivedEnterEvents[0].target, outer); // mouse moves over #inner
(0, _internalTestHelpers.runTask)(function () {
_this7.$(inner).trigger('mouseover', {
relatedTarget: outer
});
_this7.$(outer).trigger('mouseout', {
relatedTarget: inner
});
});
assert.equal(receivedEnterEvents.length, 1, 'mouseenter event was not triggered again'); // mouse moves out of #inner
(0, _internalTestHelpers.runTask)(function () {
_this7.$(inner).trigger('mouseout', {
relatedTarget: outer
});
_this7.$(outer).trigger('mouseover', {
relatedTarget: inner
});
});
assert.equal(receivedLeaveEvents.length, 0, 'mouseleave event was not triggered'); // mouse moves out of #outer
(0, _internalTestHelpers.runTask)(function () {
_this7.$(outer).trigger('mouseleave', {
canBubble: false,
relatedTarget: parent
});
_this7.$(outer).trigger('mouseout', {
relatedTarget: parent
});
_this7.$(parent).trigger('mouseover', {
relatedTarget: outer
});
});
assert.equal(receivedLeaveEvents.length, 1, 'mouseleave event was triggered');
assert.strictEqual(receivedLeaveEvents[0].target, outer);
};
_proto['@test delegated event listeners work for mouseEnter/Leave with skipped events'] = function testDelegatedEventListenersWorkForMouseEnterLeaveWithSkippedEvents(assert) {
var _this8 = this;
var receivedEnterEvents = [];
var receivedLeaveEvents = [];
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
mouseEnter: function (event) {
receivedEnterEvents.push(event);
},
mouseLeave: function (event) {
receivedLeaveEvents.push(event);
}
}),
template: ""
});
this.render("{{x-foo id=\"outer\"}}");
var parent = this.element;
var outer = this.$('#outer')[0];
var inner = this.$('#inner')[0]; // we replicate fast mouse movement, where mouseover is fired directly in #inner, skipping #outer
(0, _internalTestHelpers.runTask)(function () {
_this8.$(outer).trigger('mouseenter', {
canBubble: false,
relatedTarget: parent
});
_this8.$(inner).trigger('mouseover', {
relatedTarget: parent
});
_this8.$(parent).trigger('mouseout', {
relatedTarget: inner
});
});
assert.equal(receivedEnterEvents.length, 1, 'mouseenter event was triggered');
assert.strictEqual(receivedEnterEvents[0].target, inner); // mouse moves out of #outer
(0, _internalTestHelpers.runTask)(function () {
_this8.$(outer).trigger('mouseleave', {
canBubble: false,
relatedTarget: parent
});
_this8.$(inner).trigger('mouseout', {
relatedTarget: parent
});
_this8.$(parent).trigger('mouseover', {
relatedTarget: inner
});
});
assert.equal(receivedLeaveEvents.length, 1, 'mouseleave event was triggered');
assert.strictEqual(receivedLeaveEvents[0].target, inner);
};
_proto['@test delegated event listeners work for mouseEnter/Leave with skipped events and subcomponent'] = function testDelegatedEventListenersWorkForMouseEnterLeaveWithSkippedEventsAndSubcomponent(assert) {
var _this9 = this;
var receivedEnterEvents = [];
var receivedLeaveEvents = [];
this.registerComponent('x-outer', {
ComponentClass: _helpers.Component.extend({
mouseEnter: function (event) {
receivedEnterEvents.push(event);
},
mouseLeave: function (event) {
receivedLeaveEvents.push(event);
}
}),
template: "{{yield}}"
});
this.registerComponent('x-inner', {
ComponentClass: _helpers.Component.extend(),
template: ""
});
this.render("{{#x-outer id=\"outer\"}}{{x-inner id=\"inner\"}}{{/x-outer}}");
var parent = this.element;
var outer = this.$('#outer')[0];
var inner = this.$('#inner')[0]; // we replicate fast mouse movement, where mouseover is fired directly in #inner, skipping #outer
(0, _internalTestHelpers.runTask)(function () {
_this9.$(outer).trigger('mouseenter', {
canBubble: false,
relatedTarget: parent
});
_this9.$(inner).trigger('mouseover', {
relatedTarget: parent
});
_this9.$(parent).trigger('mouseout', {
relatedTarget: inner
});
});
assert.equal(receivedEnterEvents.length, 1, 'mouseenter event was triggered');
assert.strictEqual(receivedEnterEvents[0].target, inner); // mouse moves out of #inner
(0, _internalTestHelpers.runTask)(function () {
_this9.$(outer).trigger('mouseleave', {
canBubble: false,
relatedTarget: parent
});
_this9.$(inner).trigger('mouseout', {
relatedTarget: parent
});
_this9.$(parent).trigger('mouseover', {
relatedTarget: inner
});
});
assert.equal(receivedLeaveEvents.length, 1, 'mouseleave event was triggered');
assert.strictEqual(receivedLeaveEvents[0].target, inner);
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
(0, _internalTestHelpers.moduleFor)('EventDispatcher#setup',
/*#__PURE__*/
function (_RenderingTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _RenderingTestCase2);
function _class2() {
var _this10;
_this10 = _RenderingTestCase2.apply(this, arguments) || this;
var dispatcher = _this10.owner.lookup('event_dispatcher:main');
(0, _runloop.run)(dispatcher, 'destroy');
_this10.owner.__container__.reset('event_dispatcher:main');
_this10.dispatcher = _this10.owner.lookup('event_dispatcher:main');
return _this10;
}
var _proto2 = _class2.prototype;
_proto2['@test additional events can be specified'] = function testAdditionalEventsCanBeSpecified(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');
};
_proto2['@test a rootElement can be specified'] = function testARootElementCanBeSpecified(assert) {
this.element.innerHTML = ''; // 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');
};
_proto2['@test default events can be disabled via `customEvents`'] = function testDefaultEventsCanBeDisabledViaCustomEvents(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');
};
_proto2['@test throws if specified rootElement does not exist'] = function testThrowsIfSpecifiedRootElementDoesNotExist(assert) {
var _this11 = this;
assert.throws(function () {
_this11.dispatcher.setup({
myevent: 'myEvent'
}, '#app');
});
};
return _class2;
}(_internalTestHelpers.RenderingTestCase));
if (false
/* EMBER_IMPROVED_INSTRUMENTATION */
) {
(0, _internalTestHelpers.moduleFor)('EventDispatcher - Instrumentation',
/*#__PURE__*/
function (_RenderingTestCase3) {
(0, _emberBabel.inheritsLoose)(_class3, _RenderingTestCase3);
function _class3() {
return _RenderingTestCase3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3.teardown = function teardown() {
_RenderingTestCase3.prototype.teardown.call(this);
(0, _instrumentation.reset)();
};
_proto3['@test instruments triggered events'] = function testInstrumentsTriggeredEvents(assert) {
var clicked = 0;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function () {
clicked++;
}
}),
template: "
hello
"
});
this.render("{{x-foo}}");
this.$('div').trigger('click');
assert.equal(clicked, 1, 'precond - the click handler was invoked');
var clickInstrumented = 0;
(0, _instrumentation.subscribe)('interaction.click', {
before: function () {
clickInstrumented++;
assert.equal(clicked, 1, 'invoked before event is handled');
},
after: function () {
clickInstrumented++;
assert.equal(clicked, 2, 'invoked after event is handled');
}
});
var keypressInstrumented = 0;
(0, _instrumentation.subscribe)('interaction.keypress', {
before: function () {
keypressInstrumented++;
},
after: function () {
keypressInstrumented++;
}
});
this.$('div').trigger('click');
this.$('div').trigger('change');
assert.equal(clicked, 2, 'precond - The click handler was invoked');
assert.equal(clickInstrumented, 2, 'The click was instrumented');
assert.strictEqual(keypressInstrumented, 0, 'The keypress was not instrumented');
};
return _class3;
}(_internalTestHelpers.RenderingTestCase));
}
if (canDataTransfer) {
(0, _internalTestHelpers.moduleFor)('EventDispatcher - Event Properties',
/*#__PURE__*/
function (_RenderingTestCase4) {
(0, _emberBabel.inheritsLoose)(_class4, _RenderingTestCase4);
function _class4() {
return _RenderingTestCase4.apply(this, arguments) || this;
}
var _proto4 = _class4.prototype;
_proto4['@test dataTransfer property is added to drop event'] = function testDataTransferPropertyIsAddedToDropEvent(assert) {
var receivedEvent;
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;
}(_internalTestHelpers.RenderingTestCase));
}
if (_views.jQueryDisabled) {
(0, _internalTestHelpers.moduleFor)('EventDispatcher#native-events',
/*#__PURE__*/
function (_RenderingTestCase5) {
(0, _emberBabel.inheritsLoose)(_class5, _RenderingTestCase5);
function _class5() {
return _RenderingTestCase5.apply(this, arguments) || this;
}
var _proto5 = _class5.prototype;
_proto5['@test native events are passed when jQuery is not present'] = function testNativeEventsArePassedWhenJQueryIsNotPresent(assert) {
var _this12 = this;
var receivedEvent;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function (event) {
receivedEvent = event;
}
}),
template: ""
});
this.render("{{x-foo}}");
(0, _internalTestHelpers.runTask)(function () {
return _this12.$('#foo').click();
});
assert.ok(receivedEvent, 'click event was triggered');
assert.notOk(receivedEvent.originalEvent, 'event is not a jQuery.Event');
};
return _class5;
}(_internalTestHelpers.RenderingTestCase));
} else {
(0, _internalTestHelpers.moduleFor)('EventDispatcher#jquery-events',
/*#__PURE__*/
function (_RenderingTestCase6) {
(0, _emberBabel.inheritsLoose)(_class6, _RenderingTestCase6);
function _class6() {
return _RenderingTestCase6.apply(this, arguments) || this;
}
var _proto6 = _class6.prototype;
_proto6.beforeEach = function beforeEach() {
this.jqueryIntegration = window.ENV._JQUERY_INTEGRATION;
};
_proto6.afterEach = function afterEach() {
window.ENV._JQUERY_INTEGRATION = this.jqueryIntegration;
};
_proto6['@test jQuery events are passed when jQuery is present'] = function testJQueryEventsArePassedWhenJQueryIsPresent(assert) {
var _this13 = this;
var receivedEvent;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function (event) {
receivedEvent = event;
}
}),
template: ""
});
this.render("{{x-foo}}");
(0, _internalTestHelpers.runTask)(function () {
return _this13.$('#foo').click();
});
assert.ok(receivedEvent, 'click event was triggered');
assert.ok(receivedEvent instanceof _views.jQuery.Event, 'event is a jQuery.Event');
};
_proto6["@" + (_utils.HAS_NATIVE_PROXY ? 'test' : 'skip') + " accessing jQuery.Event#originalEvent is deprecated"] = function (assert) {
var _this14 = this;
var receivedEvent;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function (event) {
receivedEvent = event;
}
}),
template: ""
});
this.render("{{x-foo}}");
(0, _internalTestHelpers.runTask)(function () {
return _this14.$('#foo').click();
});
expectDeprecation(function () {
var _receivedEvent = receivedEvent,
originalEvent = _receivedEvent.originalEvent;
assert.ok(originalEvent, 'jQuery event has originalEvent property');
assert.equal(originalEvent.type, 'click', 'properties of originalEvent are available');
}, 'Accessing jQuery.Event specific properties is deprecated. Either use the ember-jquery-legacy addon to normalize events to native events, or explicitly opt into jQuery integration using @ember/optional-features.');
};
_proto6['@test other jQuery.Event properties do not trigger deprecation'] = function testOtherJQueryEventPropertiesDoNotTriggerDeprecation(assert) {
var _this15 = this;
var receivedEvent;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function (event) {
receivedEvent = event;
}
}),
template: ""
});
this.render("{{x-foo}}");
(0, _internalTestHelpers.runTask)(function () {
return _this15.$('#foo').click();
});
expectNoDeprecation(function () {
receivedEvent.stopPropagation();
receivedEvent.stopImmediatePropagation();
receivedEvent.preventDefault();
assert.ok(receivedEvent.bubbles, 'properties of jQuery event are available');
assert.equal(receivedEvent.type, 'click', 'properties of jQuery event are available');
});
};
_proto6['@test accessing jQuery.Event#originalEvent does not trigger deprecations when jquery integration is explicitly enabled'] = function testAccessingJQueryEventOriginalEventDoesNotTriggerDeprecationsWhenJqueryIntegrationIsExplicitlyEnabled(assert) {
var _this16 = this;
var receivedEvent;
window.ENV._JQUERY_INTEGRATION = true;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function (event) {
receivedEvent = event;
}
}),
template: ""
});
this.render("{{x-foo}}");
(0, _internalTestHelpers.runTask)(function () {
return _this16.$('#foo').click();
});
expectNoDeprecation(function () {
var _receivedEvent2 = receivedEvent,
originalEvent = _receivedEvent2.originalEvent;
assert.ok(originalEvent, 'jQuery event has originalEvent property');
assert.equal(originalEvent.type, 'click', 'properties of originalEvent are available');
});
};
_proto6["@" + (_utils.HAS_NATIVE_PROXY && true
/* DEBUG */
? 'test' : 'skip') + " accessing jQuery.Event#__originalEvent does not trigger deprecations to support ember-jquery-legacy"] = function (assert) {
var _this17 = this;
var receivedEvent;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function (event) {
receivedEvent = event;
}
}),
template: ""
});
this.render("{{x-foo}}");
(0, _internalTestHelpers.runTask)(function () {
return _this17.$('#foo').click();
});
expectNoDeprecation(function () {
var _receivedEvent3 = receivedEvent,
originalEvent = _receivedEvent3.__originalEvent;
assert.ok(originalEvent, 'jQuery event has __originalEvent property');
assert.equal(originalEvent.type, 'click', 'properties of __originalEvent are available');
});
};
return _class6;
}(_internalTestHelpers.RenderingTestCase));
}
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/-class-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _metal) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Helpers test: {{-class}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test casts binding to dasherized class'] = function testCastsBindingToDasherizedClass() {
var _this = 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, _internalTestHelpers.classes)('some-truth ember-view')
}
});
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
class: (0, _internalTestHelpers.classes)('some-truth ember-view')
}
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'someTruth', false);
});
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
class: (0, _internalTestHelpers.classes)('ember-view')
}
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'someTruth', true);
});
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
class: (0, _internalTestHelpers.classes)('some-truth ember-view')
}
});
};
_proto['@tests casts leaf path of binding to dasherized class'] = function testsCastsLeafPathOfBindingToDasherizedClass() {
var _this2 = 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, _internalTestHelpers.classes)('some-truth ember-view')
}
});
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
class: (0, _internalTestHelpers.classes)('some-truth ember-view')
}
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'model.someTruth', false);
});
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
class: (0, _internalTestHelpers.classes)('ember-view')
}
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'model', {
someTruth: true
});
});
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
class: (0, _internalTestHelpers.classes)('some-truth ember-view')
}
});
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/array-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _metal, _helpers) {
"use strict";
function _templateObject11() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["{{foo-bar people=(array \"Tom\" personTwo)}}"]);
_templateObject11 = function () {
return data;
};
return data;
}
function _templateObject10() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each people as |personName|}}\n {{personName}},\n {{/each}}"]);
_templateObject10 = function () {
return data;
};
return data;
}
function _templateObject9() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["{{foo-bar people=(array \"Tom\" personTwo)}}"]);
_templateObject9 = function () {
return data;
};
return data;
}
function _templateObject8() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each people as |personName|}}\n {{personName}},\n {{/each}}"]);
_templateObject8 = function () {
return data;
};
return data;
}
function _templateObject7() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["{{#foo-bar personTwo=model.personTwo as |values|}}\n {{#each values.people as |personName|}}\n {{personName}},\n {{/each}}\n {{/foo-bar}}"]);
_templateObject7 = function () {
return data;
};
return data;
}
function _templateObject6() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#foo-bar as |values|}}\n {{#each values.people as |personName|}}\n {{personName}}\n {{/each}}\n {{/foo-bar}}"]);
_templateObject6 = function () {
return data;
};
return data;
}
function _templateObject5() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["{{#with (array (array personOne personTwo)) as |listOfPeople|}}\n {{#each listOfPeople as |people|}}\n List:\n {{#each people as |personName|}}\n {{personName}},\n {{/each}}\n {{/each}}\n {{/with}}"]);
_templateObject5 = function () {
return data;
};
return data;
}
function _templateObject4() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["{{#with (array personOne personTwo) as |people|}}\n {{#each people as |personName|}}\n {{personName}},\n {{/each}}\n {{/with}}"]);
_templateObject4 = function () {
return data;
};
return data;
}
function _templateObject3() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["{{#with (array personOne) as |people|}}\n {{#each people as |personName|}}\n {{personName}}\n {{/each}}\n {{/with}}"]);
_templateObject3 = function () {
return data;
};
return data;
}
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#with (array \"Sergio\" \"Robert\") as |people|}}\n {{#each people as |personName|}}\n {{personName}},\n {{/each}}\n {{/with}}"]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#with (array \"Sergio\") as |people|}}\n {{#each people as |personName|}}\n {{personName}}\n {{/each}}\n {{/with}}"]);
_templateObject = function () {
return data;
};
return data;
}
if (true
/* EMBER_GLIMMER_ARRAY_HELPER */
) {
(0, _internalTestHelpers.moduleFor)('Helpers test: {{array}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test returns an array'] = function testReturnsAnArray() {
this.render((0, _internalTestHelpers.strip)(_templateObject()));
this.assertText('Sergio');
this.assertStableRerender();
};
_proto['@test can have more than one value'] = function testCanHaveMoreThanOneValue() {
this.render((0, _internalTestHelpers.strip)(_templateObject2()));
this.assertText('Sergio,Robert,');
this.assertStableRerender();
};
_proto['@test binds values when variables are used'] = function testBindsValuesWhenVariablesAreUsed() {
var _this = this;
this.render((0, _internalTestHelpers.strip)(_templateObject3()), {
personOne: 'Tom'
});
this.assertText('Tom');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'personOne', 'Yehuda');
});
this.assertText('Yehuda');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'personOne', 'Tom');
});
this.assertText('Tom');
};
_proto['@test binds multiple values when variables are used'] = function testBindsMultipleValuesWhenVariablesAreUsed() {
var _this2 = this;
this.render((0, _internalTestHelpers.strip)(_templateObject4()), {
personOne: 'Tom',
personTwo: 'Yehuda'
});
this.assertText('Tom,Yehuda,');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'personOne', 'Sergio');
});
this.assertText('Sergio,Yehuda,');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'personTwo', 'Tom');
});
this.assertText('Sergio,Tom,');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this2.context, 'personOne', 'Tom');
(0, _metal.set)(_this2.context, 'personTwo', 'Yehuda');
});
this.assertText('Tom,Yehuda,');
};
_proto['@test array helpers can be nested'] = function testArrayHelpersCanBeNested() {
var _this3 = this;
this.render((0, _internalTestHelpers.strip)(_templateObject5()), {
personOne: 'Tom',
personTwo: 'Yehuda'
});
this.assertText('List:Tom,Yehuda,');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'personOne', 'Chad');
});
this.assertText('List:Chad,Yehuda,');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'personTwo', 'Balint');
});
this.assertText('List:Chad,Balint,');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this3.context, 'personOne', 'Tom');
(0, _metal.set)(_this3.context, 'personTwo', 'Yehuda');
});
this.assertText('List:Tom,Yehuda,');
};
_proto['@test should yield hash of an array of internal properties'] = function testShouldYieldHashOfAnArrayOfInternalProperties() {
var fooBarInstance;
var FooBarComponent = _helpers.Component.extend({
init: function () {
this._super();
fooBarInstance = this;
this.model = {
personOne: 'Chad'
};
}
});
this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: "{{yield (hash people=(array model.personOne))}}"
});
this.render((0, _internalTestHelpers.strip)(_templateObject6()));
this.assertText('Chad');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(fooBarInstance, 'model.personOne', 'Godfrey');
});
this.assertText('Godfrey');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(fooBarInstance, 'model', {
personOne: 'Chad'
});
});
this.assertText('Chad');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(fooBarInstance, 'model.personOne', 'Godfrey');
});
this.assertText('Godfrey');
};
_proto['@test should yield hash of an array of internal and external properties'] = function testShouldYieldHashOfAnArrayOfInternalAndExternalProperties() {
var _this4 = this;
var fooBarInstance;
var FooBarComponent = _helpers.Component.extend({
init: function () {
this._super();
fooBarInstance = this;
this.model = {
personOne: 'Chad'
};
}
});
this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: "{{yield (hash people=(array model.personOne personTwo))}}"
});
this.render((0, _internalTestHelpers.strip)(_templateObject7()), {
model: {
personTwo: 'Tom'
}
});
this.assertText('Chad,Tom,');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(fooBarInstance, 'model.personOne', 'Godfrey');
(0, _metal.set)(_this4.context, 'model.personTwo', 'Yehuda');
});
this.assertText('Godfrey,Yehuda,');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(fooBarInstance, 'model', {
personOne: 'Chad'
});
(0, _metal.set)(_this4.context, 'model', {
personTwo: 'Tom'
});
});
this.assertText('Chad,Tom,');
};
_proto['@test should render when passing as argument to a component invocation'] = function testShouldRenderWhenPassingAsArgumentToAComponentInvocation() {
var _this5 = this;
var FooBarComponent = _helpers.Component.extend({});
this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: (0, _internalTestHelpers.strip)(_templateObject8())
});
this.render((0, _internalTestHelpers.strip)(_templateObject9()), {
personTwo: 'Chad'
});
this.assertText('Tom,Chad,');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'personTwo', 'Godfrey');
});
this.assertText('Tom,Godfrey,');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'personTwo', 'Chad');
});
this.assertText('Tom,Chad,');
};
_proto['@test should return an entirely new array when any argument change'] = function testShouldReturnAnEntirelyNewArrayWhenAnyArgumentChange() {
var _this6 = this;
var fooBarInstance;
var FooBarComponent = _helpers.Component.extend({
init: function () {
this._super();
fooBarInstance = this;
}
});
this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: (0, _internalTestHelpers.strip)(_templateObject10())
});
this.render((0, _internalTestHelpers.strip)(_templateObject11()), {
personTwo: 'Chad'
});
var firstArray = fooBarInstance.people;
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'personTwo', 'Godfrey');
});
this.assert.ok(firstArray !== fooBarInstance.people, 'should have created an entirely new array');
};
_proto['@test capture array values in JS to assert deep equal'] = function testCaptureArrayValuesInJSToAssertDeepEqual() {
var _this7 = this;
var captured;
this.registerHelper('capture', function (_ref) {
var array = _ref[0];
captured = array;
return 'captured';
});
this.render("{{capture (array 'Tom' personTwo)}}", {
personTwo: 'Godfrey'
});
this.assert.deepEqual(captured, ['Tom', 'Godfrey']);
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this7.context, 'personTwo', 'Robert');
});
this.assert.deepEqual(captured, ['Tom', 'Robert']);
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this7.context, 'personTwo', 'Godfrey');
});
this.assert.deepEqual(captured, ['Tom', 'Godfrey']);
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
}
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/closure-action-test", ["ember-babel", "internal-test-helpers", "@ember/instrumentation", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _instrumentation, _runloop, _metal, _helpers) {
"use strict";
function _templateObject() {
var data = (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 "]);
_templateObject = function () {
return data;
};
return data;
}
if (false
/* EMBER_IMPROVED_INSTRUMENTATION */
) {
(0, _internalTestHelpers.moduleFor)('Helpers test: closure {{action}} improved instrumentation',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.subscribe = function subscribe(eventName, options) {
this.subscriber = (0, _instrumentation.subscribe)(eventName, options);
};
_proto.teardown = function teardown() {
if (this.subscriber) {
(0, _instrumentation.unsubscribe)(this.subscriber);
}
_RenderingTestCase.prototype.teardown.call(this);
};
_proto['@test interaction event subscriber should be passed parameters'] = function testInteractionEventSubscriberShouldBePassedParameters() {
var _this = this;
var actionParam = 'So krispy';
var beforeParameters = [];
var afterParameters = [];
var InnerComponent = _helpers.Component.extend({
actions: {
fireAction: function () {
this.attrs.submit(actionParam);
}
}
});
var OuterComponent = _helpers.Component.extend({
outerSubmit: function () {}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: ''
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerSubmit)}}'
});
this.subscribe('interaction.ember-action', {
before: function (name, timestamp, payload) {
beforeParameters.push(payload.args);
},
after: function (name, timestamp, payload) {
afterParameters.push(payload.args);
}
});
this.render("{{outer-component}}");
(0, _internalTestHelpers.runTask)(function () {
_this.$('#instrument-button').trigger('click');
});
this.assert.deepEqual(beforeParameters, [[], [actionParam]], 'instrumentation subscriber before function was passed closure action parameters');
this.assert.deepEqual(afterParameters, [[actionParam], []], 'instrumentation subscriber after function was passed closure action parameters');
};
_proto['@test interaction event subscriber should be passed target'] = function testInteractionEventSubscriberShouldBePassedTarget() {
var _this2 = this;
var beforeParameters = [];
var afterParameters = [];
var InnerComponent = _helpers.Component.extend({
myProperty: 'inner-thing',
actions: {
fireAction: function () {
this.attrs.submit();
}
}
});
var OuterComponent = _helpers.Component.extend({
myProperty: 'outer-thing',
outerSubmit: function () {}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: ''
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerSubmit)}}'
});
this.subscribe('interaction.ember-action', {
before: function (name, timestamp, payload) {
beforeParameters.push(payload.target.get('myProperty'));
},
after: function (name, timestamp, payload) {
afterParameters.push(payload.target.get('myProperty'));
}
});
this.render("{{outer-component}}");
(0, _internalTestHelpers.runTask)(function () {
_this2.$('#instrument-button').trigger('click');
});
this.assert.deepEqual(beforeParameters, ['inner-thing', 'outer-thing'], 'instrumentation subscriber before function was passed target');
this.assert.deepEqual(afterParameters, ['outer-thing', 'inner-thing'], 'instrumentation subscriber after function was passed target');
};
_proto['@test instrumented action should return value'] = function testInstrumentedActionShouldReturnValue() {
var _this3 = this;
var returnedValue = 'Chris P is so krispy';
var actualReturnedValue;
var InnerComponent = _helpers.Component.extend({
actions: {
fireAction: function () {
actualReturnedValue = this.attrs.submit();
}
}
});
var OuterComponent = _helpers.Component.extend({
outerSubmit: function () {
return returnedValue;
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: ''
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerSubmit)}}'
});
this.subscribe('interaction.ember-action', {
before: function () {},
after: function () {}
});
this.render("{{outer-component}}");
(0, _internalTestHelpers.runTask)(function () {
_this3.$('#instrument-button').trigger('click');
});
this.assert.equal(actualReturnedValue, returnedValue, 'action can return to caller');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
}
(0, _internalTestHelpers.moduleFor)('Helpers test: closure {{action}}',
/*#__PURE__*/
function (_RenderingTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _RenderingTestCase2);
function _class2() {
return _RenderingTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test action should be called'] = function testActionShouldBeCalled() {
var outerActionCalled = false;
var component;
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}}');
(0, _internalTestHelpers.runTask)(function () {
component.fireAction();
});
this.assert.ok(outerActionCalled, 'the action was called');
};
_proto2['@test an error is triggered when bound action function is undefined'] = function testAnErrorIsTriggeredWhenBoundActionFunctionIsUndefined() {
var _this4 = this;
this.registerComponent('inner-component', {
template: 'inner'
});
this.registerComponent('outer-component', {
template: '{{inner-component submit=(action somethingThatIsUndefined)}}'
});
expectAssertion(function () {
_this4.render('{{outer-component}}');
}, /Action passed is null or undefined in \(action[^)]*\) from .*\./);
};
_proto2['@test an error is triggered when bound action being passed in is a non-function'] = function testAnErrorIsTriggeredWhenBoundActionBeingPassedInIsANonFunction() {
var _this5 = this;
this.registerComponent('inner-component', {
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: _helpers.Component.extend({
nonFunctionThing: {}
}),
template: '{{inner-component submit=(action nonFunctionThing)}}'
});
expectAssertion(function () {
_this5.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 .*\./);
};
_proto2['@test [#12718] a nice error is shown when a bound action function is undefined and it is passed as attrs.foo'] = function test12718ANiceErrorIsShownWhenABoundActionFunctionIsUndefinedAndItIsPassedAsAttrsFoo() {
var _this6 = this;
this.registerComponent('inner-component', {
template: ''
});
this.registerComponent('outer-component', {
template: '{{inner-component}}'
});
expectAssertion(function () {
_this6.render('{{outer-component}}');
}, /Action passed is null or undefined in \(action[^)]*\) from .*\./);
};
_proto2['@test action value is returned'] = function testActionValueIsReturned() {
var expectedValue = 'terrible tom';
var returnedValue;
var innerComponent;
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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.equal(returnedValue, expectedValue, 'action can return to caller');
};
_proto2['@test action should be called on the correct scope'] = function testActionShouldBeCalledOnTheCorrectScope() {
var innerComponent;
var outerComponent;
var actualComponent;
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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.equal(actualComponent, outerComponent, 'action has the correct context');
this.assert.ok(actualComponent.isOuterComponent, 'action has the correct context');
};
_proto2['@test arguments to action are passed, curry'] = function testArgumentsToActionArePassedCurry() {
var first = 'mitch';
var second = 'martin';
var third = 'matt';
var fourth = 'wacky wycats';
var innerComponent;
var actualArgs;
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 () {
// eslint-disable-line no-unused-vars
actualArgs = 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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.deepEqual(actualArgs, [first, second, third, fourth], 'action has the correct args');
};
_proto2['@test `this` can be passed as an argument'] = function testThisCanBePassedAsAnArgument() {
var value = {};
var component;
var innerComponent;
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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.strictEqual(value, component, 'the component is passed at `this`');
};
_proto2['@test arguments to action are bound'] = function testArgumentsToActionAreBound() {
var value = 'lazy leah';
var innerComponent;
var outerComponent;
var actualArg;
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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.strictEqual(actualArg, '', 'action has the correct first arg');
(0, _internalTestHelpers.runTask)(function () {
outerComponent.set('value', value);
});
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.strictEqual(actualArg, value, 'action has the correct first arg');
};
_proto2['@test array arguments are passed correctly to action'] = function testArrayArgumentsArePassedCorrectlyToAction() {
var first = 'foo';
var second = [3, 5];
var third = [4, 9];
var actualFirst;
var actualSecond;
var actualThird;
var innerComponent;
var outerComponent;
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}}');
(0, _internalTestHelpers.runTask)(function () {
outerComponent.set('first', first);
outerComponent.set('second', second);
});
(0, _internalTestHelpers.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');
};
_proto2['@test mut values can be wrapped in actions, are settable'] = function testMutValuesCanBeWrappedInActionsAreSettable() {
var newValue = 'trollin trek';
var innerComponent;
var outerComponent;
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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.equal(outerComponent.get('outerMut'), newValue, 'mut value is set');
};
_proto2['@test mut values can be wrapped in actions, are settable with a curry'] = function testMutValuesCanBeWrappedInActionsAreSettableWithACurry() {
var newValue = 'trollin trek';
var innerComponent;
var outerComponent;
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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.equal(outerComponent.get('outerMut'), newValue, 'mut value is set');
};
_proto2['@test action can create closures over actions'] = function testActionCanCreateClosuresOverActions() {
var first = 'raging robert';
var second = 'mild machty';
var returnValue = 'butch brian';
var actualFirst;
var actualSecond;
var actualReturnedValue;
var innerComponent;
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}}');
(0, _internalTestHelpers.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');
};
_proto2['@test provides a helpful error if an action is not present'] = function testProvidesAHelpfulErrorIfAnActionIsNotPresent() {
var _this7 = 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 () {
_this7.render('{{outer-component}}');
}, /An action named 'doesNotExist' was not found in /);
};
_proto2['@test provides a helpful error if actions hash is not present'] = function testProvidesAHelpfulErrorIfActionsHashIsNotPresent() {
var _this8 = 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 () {
_this8.render('{{outer-component}}');
}, /An action named 'doesNotExist' was not found in /);
};
_proto2['@test action can create closures over actions with target'] = function testActionCanCreateClosuresOverActionsWithTarget() {
var innerComponent;
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, _metal.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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.ok(actionCalled, 'action called on otherComponent');
};
_proto2['@test value can be used with action over actions'] = function testValueCanBeUsedWithActionOverActions() {
var newValue = 'yelping yehuda';
var innerComponent;
var actualValue;
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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.equal(actualValue, newValue, 'value is read');
};
_proto2['@test action will read the value of a first property'] = function testActionWillReadTheValueOfAFirstProperty() {
var newValue = 'irate igor';
var innerComponent;
var actualValue;
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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.equal(actualValue, newValue, 'property is read');
};
_proto2['@test action will read the value of a curried first argument property'] = function testActionWillReadTheValueOfACurriedFirstArgumentProperty() {
var newValue = 'kissing kris';
var innerComponent;
var actualValue;
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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.equal(actualValue, newValue, 'property is read');
};
_proto2['@test action closure does not get auto-mut wrapped'] = function testActionClosureDoesNotGetAutoMutWrapped(assert) {
var first = 'raging robert';
var second = 'mild machty';
var returnValue = 'butch brian';
var innerComponent;
var actualFirst;
var actualSecond;
var actualReturnedValue;
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}}');
(0, _internalTestHelpers.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');
};
_proto2['@test action should be called within a run loop'] = function testActionShouldBeCalledWithinARunLoop() {
var innerComponent;
var capturedRunLoop;
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 = (0, _runloop.getCurrentRunLoop)();
}
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: "{{inner-component submit=(action 'submit')}}"
});
this.render('{{outer-component}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.ok(capturedRunLoop, 'action is called within a run loop');
};
_proto2['@test objects that define INVOKE can be casted to actions'] = function testObjectsThatDefineINVOKECanBeCastedToActions() {
var innerComponent;
var actionArgs;
var invokableArgs;
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, _metal.computed)(function () {
var _this9 = this,
_ref;
return _ref = {}, _ref[_helpers.INVOKE] = function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
invokableArgs = args;
return _this9.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}}');
(0, _internalTestHelpers.runTask)(function () {
innerComponent.fireAction();
});
this.assert.equal(actionArgs, 123);
this.assert.deepEqual(invokableArgs, [1, 2, 3, 4, 5, 6]);
};
_proto2['@test closure action with `(mut undefinedThing)` works properly [GH#13959]'] = function testClosureActionWithMutUndefinedThingWorksProperlyGH13959() {
var _this10 = this;
var component;
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();
(0, _internalTestHelpers.runTask)(function () {
_this10.$('button').click();
});
this.assertText('Clicked!');
(0, _internalTestHelpers.runTask)(function () {
component.set('label', 'Dun clicked');
});
this.assertText('Dun clicked');
(0, _internalTestHelpers.runTask)(function () {
_this10.$('button').click();
});
this.assertText('Clicked!');
(0, _internalTestHelpers.runTask)(function () {
component.set('label', undefined);
});
this.assertText('Click me');
};
_proto2['@test closure actions does not cause component hooks to fire unnecessarily [GH#14305] [GH#14654]'] = function testClosureActionsDoesNotCauseComponentHooksToFireUnnecessarilyGH14305GH14654(assert) {
var _this12 = 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;
var OuterComponent = _helpers.Component.extend({
clicked: 0,
actions: {
'on-click': function () {
this.incrementProperty('clicked');
}
},
init: function () {
var _this11 = this;
this._super();
outer = this;
this.set('onClick', function () {
return _this11.incrementProperty('clicked');
});
}
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: (0, _internalTestHelpers.strip)(_templateObject())
});
this.render('{{outer-component foo=foo}}', {
foo: 1
});
this.assertText('clicked: 0; foo: 1');
assert.equal(didReceiveAttrsFired, 3);
(0, _internalTestHelpers.runTask)(function () {
return _this12.rerender();
});
this.assertText('clicked: 0; foo: 1');
assert.equal(didReceiveAttrsFired, 3);
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'foo', 2);
});
this.assertText('clicked: 0; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
(0, _internalTestHelpers.runTask)(function () {
return _this12.$('#string-action').click();
});
this.assertText('clicked: 1; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
(0, _internalTestHelpers.runTask)(function () {
return _this12.$('#function-action').click();
});
this.assertText('clicked: 2; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(outer, 'onClick', function () {
outer.incrementProperty('clicked');
});
});
this.assertText('clicked: 2; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
(0, _internalTestHelpers.runTask)(function () {
return _this12.$('#function-action').click();
});
this.assertText('clicked: 3; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
(0, _internalTestHelpers.runTask)(function () {
return _this12.$('#mut-action').click();
});
this.assertText('clicked: 4; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
};
return _class2;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/concat-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _metal) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Helpers test: {{concat}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test it concats static arguments'] = function testItConcatsStaticArguments() {
this.render("{{concat \"foo\" \" \" \"bar\" \" \" \"baz\"}}");
this.assertText('foo bar baz');
};
_proto['@test it updates for bound arguments'] = function testItUpdatesForBoundArguments() {
var _this = this;
this.render("{{concat model.first model.second}}", {
model: {
first: 'one',
second: 'two'
}
});
this.assertText('onetwo');
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
this.assertText('onetwo');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'model.first', 'three');
});
this.assertText('threetwo');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'model.second', 'four');
});
this.assertText('threefour');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'model', {
first: 'one',
second: 'two'
});
});
this.assertText('onetwo');
};
_proto['@test it can be used as a sub-expression'] = function testItCanBeUsedAsASubExpression() {
var _this2 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertText('onetwothreefour');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'model.first', 'five');
});
this.assertText('fivetwothreefour');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this2.context, 'model.second', 'six');
(0, _metal.set)(_this2.context, 'model.third', 'seven');
});
this.assertText('fivesixsevenfour');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this2.context, 'model', {
first: 'one',
second: 'two',
third: 'three',
fourth: 'four'
});
});
this.assertText('onetwothreefour');
};
_proto['@test it can be used as input for other helpers'] = function testItCanBeUsedAsInputForOtherHelpers() {
var _this3 = 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!');
(0, _internalTestHelpers.runTask)(function () {
return _this3.rerender();
});
this.assertText('Truthy!');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'model.first', 'three');
});
this.assertText('False');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'model', {
first: 'one',
second: 'two'
});
});
this.assertText('Truthy!');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/custom-helper-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _metal) {
"use strict";
/* globals EmberDev */
(0, _internalTestHelpers.moduleFor)('Helpers test: custom helpers',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test it cannot override built-in syntax'] = function testItCannotOverrideBuiltInSyntax() {
var _this = this;
this.registerHelper('if', function () {
return 'Nope';
});
expectAssertion(function () {
_this.render("{{if foo 'LOL'}}", {
foo: true
});
}, /You attempted to overwrite the built-in helper \"if\" which is not allowed. Please rename the helper./);
};
_proto['@test it can resolve custom simple helpers with or without dashes'] = function testItCanResolveCustomSimpleHelpersWithOrWithoutDashes() {
var _this2 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertText('hello | hello world');
};
_proto['@test it does not resolve helpers with a `.` (period)'] = function testItDoesNotResolveHelpersWithAPeriod() {
var _this3 = this;
this.registerHelper('hello.world', function () {
return 'hello world';
});
this.render('{{hello.world}}', {
hello: {
world: ''
}
});
this.assertText('');
this.assertStableRerender();
this.assertText('');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'hello', {
world: 'hello world!'
});
});
this.assertText('hello world!');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this3.context, 'hello', {
world: ''
});
});
this.assertText('');
};
_proto['@test it can resolve custom class-based helpers with or without dashes'] = function testItCanResolveCustomClassBasedHelpersWithOrWithoutDashes() {
var _this4 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this4.rerender();
});
this.assertText('hello | hello world');
};
_proto['@test throws if `this._super` is not called from `init`'] = function testThrowsIfThis_superIsNotCalledFromInit() {
var _this5 = this;
this.registerHelper('hello-world', {
init: function () {}
});
expectAssertion(function () {
_this5.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`./);
};
_proto['@test class-based helper can recompute a new value'] = function testClassBasedHelperCanRecomputeANewValue(assert) {
var _this6 = this;
var destroyCount = 0;
var computeCount = 0;
var helper;
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');
(0, _internalTestHelpers.runTask)(function () {
return _this6.rerender();
});
this.assertText('1');
(0, _internalTestHelpers.runTask)(function () {
return helper.recompute();
});
this.assertText('2');
assert.strictEqual(destroyCount, 0, 'destroy is not called on recomputation');
};
_proto['@test class-based helper with static arguments can recompute a new value'] = function testClassBasedHelperWithStaticArgumentsCanRecomputeANewValue(assert) {
var _this7 = this;
var destroyCount = 0;
var computeCount = 0;
var helper;
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');
(0, _internalTestHelpers.runTask)(function () {
return _this7.rerender();
});
this.assertText('1');
(0, _internalTestHelpers.runTask)(function () {
return helper.recompute();
});
this.assertText('2');
assert.strictEqual(destroyCount, 0, 'destroy is not called on recomputation');
};
_proto['@test helper params can be returned'] = function testHelperParamsCanBeReturned() {
this.registerHelper('hello-world', function (values) {
return values;
});
this.render('{{#each (hello-world model) as |item|}}({{item}}){{/each}}', {
model: ['bob']
});
this.assertText('(bob)');
};
_proto['@test helper hash can be returned'] = function testHelperHashCanBeReturned() {
this.registerHelper('hello-world', function (_, hash) {
return hash.model;
});
this.render("{{get (hello-world model=model) 'name'}}", {
model: {
name: 'bob'
}
});
this.assertText('bob');
};
_proto['@test simple helper is called for param changes'] = function testSimpleHelperIsCalledForParamChanges(assert) {
var _this8 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this8.rerender();
});
this.assertText('bob-value');
assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this8.context, 'model.name', 'sal');
});
this.assertText('sal-value');
assert.strictEqual(computeCount, 2, 'compute is called exactly 2 times');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this8.context, 'model', {
name: 'bob'
});
});
this.assertText('bob-value');
assert.strictEqual(computeCount, 3, 'compute is called exactly 3 times');
};
_proto['@test class-based helper compute is called for param changes'] = function testClassBasedHelperComputeIsCalledForParamChanges(assert) {
var _this9 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this9.rerender();
});
this.assertText('bob-value');
assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this9.context, 'model.name', 'sal');
});
this.assertText('sal-value');
assert.strictEqual(computeCount, 2, 'compute is called exactly 2 times');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this9.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');
};
_proto['@test simple helper receives params, hash'] = function testSimpleHelperReceivesParamsHash() {
var _this10 = 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"}');
(0, _internalTestHelpers.runTask)(function () {
return _this10.rerender();
});
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this10.context, 'model.name', 'sal');
});
this.assertText('params: ["sal","rich"], hash: {"first":42,"last":"sam"}');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this10.context, 'model.age', 28);
});
this.assertText('params: ["sal","rich"], hash: {"first":28,"last":"sam"}');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this10.context, 'model', {
name: 'bob',
age: 42
});
});
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
};
_proto['@test class-based helper receives params, hash'] = function testClassBasedHelperReceivesParamsHash() {
var _this11 = 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"}');
(0, _internalTestHelpers.runTask)(function () {
return _this11.rerender();
});
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'model.name', 'sal');
});
this.assertText('params: ["sal","rich"], hash: {"first":42,"last":"sam"}');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'model.age', 28);
});
this.assertText('params: ["sal","rich"], hash: {"first":28,"last":"sam"}');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'model', {
name: 'bob',
age: 42
});
});
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
};
_proto['@test class-based helper usable in subexpressions'] = function testClassBasedHelperUsableInSubexpressions() {
var _this12 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this12.rerender();
});
this.assertText('Who overcomes by force hath overcome but half his foe');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'model.reason', 'Nickleback');
});
this.assertText('Who overcomes by Nickleback hath overcome but half his foe');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'model', {
reason: 'force'
});
});
this.assertText('Who overcomes by force hath overcome but half his foe');
};
_proto['@test parameterless helper is usable in subexpressions'] = function testParameterlessHelperIsUsableInSubexpressions() {
var _this13 = this;
this.registerHelper('should-show', function () {
return true;
});
this.render("{{#if (should-show)}}true{{/if}}");
this.assertText('true');
(0, _internalTestHelpers.runTask)(function () {
return _this13.rerender();
});
this.assertText('true');
};
_proto['@test parameterless helper is usable in attributes'] = function testParameterlessHelperIsUsableInAttributes() {
var _this14 = this;
this.registerHelper('foo-bar', function () {
return 'baz';
});
this.render("");
this.assertHTML('');
(0, _internalTestHelpers.runTask)(function () {
return _this14.rerender();
});
this.assertHTML('');
};
_proto['@test simple helper not usable with a block'] = function testSimpleHelperNotUsableWithABlock() {
var _this15 = this;
this.registerHelper('some-helper', function () {});
expectAssertion(function () {
_this15.render("{{#some-helper}}{{/some-helper}}");
}, /Helpers may not be used in the block form/);
};
_proto['@test class-based helper not usable with a block'] = function testClassBasedHelperNotUsableWithABlock() {
var _this16 = this;
this.registerHelper('some-helper', {
compute: function () {}
});
expectAssertion(function () {
_this16.render("{{#some-helper}}{{/some-helper}}");
}, /Helpers may not be used in the block form/);
};
_proto['@test simple helper not usable within element'] = function testSimpleHelperNotUsableWithinElement() {
var _this17 = this;
this.registerHelper('some-helper', function () {});
this.assert.throws(function () {
_this17.render("");
}, /Compile Error some-helper is not a modifier: Helpers may not be used in the element form/);
};
_proto['@test class-based helper not usable within element'] = function testClassBasedHelperNotUsableWithinElement() {
var _this18 = this;
this.registerHelper('some-helper', {
compute: function () {}
});
this.assert.throws(function () {
_this18.render("");
}, /Compile Error some-helper is not a modifier: Helpers may not be used in the element form/);
};
_proto['@test class-based helper is torn down'] = function testClassBasedHelperIsTornDown(assert) {
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');
};
_proto['@test class-based helper used in subexpression can recompute'] = function testClassBasedHelperUsedInSubexpressionCanRecompute() {
var _this19 = this;
var helper;
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');
(0, _internalTestHelpers.runTask)(function () {
return _this19.rerender();
});
this.assertText('Who overcomes by force hath overcome but half his foe');
phrase = 'believes his';
(0, _internalTestHelpers.runTask)(function () {
return helper.recompute();
});
this.assertText('Who believes his force hath overcome but half his foe');
phrase = 'overcomes by';
(0, _internalTestHelpers.runTask)(function () {
return helper.recompute();
});
this.assertText('Who overcomes by force hath overcome but half his foe');
};
_proto['@test class-based helper used in subexpression can recompute component'] = function testClassBasedHelperUsedInSubexpressionCanRecomputeComponent() {
var _this20 = this;
var helper;
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');
(0, _internalTestHelpers.runTask)(function () {
return _this20.rerender();
});
this.assertText('Who overcomes by force hath overcome but half his foe');
phrase = 'believes his';
(0, _internalTestHelpers.runTask)(function () {
return helper.recompute();
});
this.assertText('Who believes his force hath overcome but half his foe');
phrase = 'overcomes by';
(0, _internalTestHelpers.runTask)(function () {
return helper.recompute();
});
this.assertText('Who overcomes by force hath overcome but half his foe');
};
_proto['@test class-based helper used in subexpression is destroyed'] = function testClassBasedHelperUsedInSubexpressionIsDestroyed(assert) {
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);
assert.equal(destroyCount, 1, 'destroy is called after a view is destroyed');
};
_proto['@test simple helper can be invoked manually via `owner.factoryFor(...).create().compute()'] = function testSimpleHelperCanBeInvokedManuallyViaOwnerFactoryForCreateCompute(assert) {
this.registerHelper('some-helper', function () {
assert.ok(true, 'some-helper helper invoked');
return 'lolol';
});
var instance = this.owner.factoryFor('helper:some-helper').create();
assert.equal(typeof instance.compute, 'function', 'expected instance.compute to be present');
assert.equal(instance.compute(), 'lolol', 'can invoke `.compute`');
};
_proto['@test class-based helper can be invoked manually via `owner.factoryFor(...).create().compute()'] = function testClassBasedHelperCanBeInvokedManuallyViaOwnerFactoryForCreateCompute(assert) {
this.registerHelper('some-helper', {
compute: function () {
assert.ok(true, 'some-helper helper invoked');
return 'lolol';
}
});
var instance = this.owner.factoryFor('helper:some-helper').create();
assert.equal(typeof instance.compute, 'function', 'expected instance.compute to be present');
assert.equal(instance.compute(), 'lolol', 'can invoke `.compute`');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
if (!EmberDev.runningProdBuild) {
var HelperMutatingArgsTests =
/*#__PURE__*/
function (_RenderingTestCase2) {
(0, _emberBabel.inheritsLoose)(HelperMutatingArgsTests, _RenderingTestCase2);
function HelperMutatingArgsTests() {
return _RenderingTestCase2.apply(this, arguments) || this;
}
var _proto2 = HelperMutatingArgsTests.prototype;
_proto2.buildCompute = function buildCompute() {
var _this21 = this;
return function (params, hash) {
_this21.assert.throws(function () {
params.push('foo'); // cannot assert error message as it varies by platform
});
_this21.assert.throws(function () {
hash.foo = 'bar'; // cannot assert error message as it varies by platform
});
_this21.assert.throws(function () {
hash.someUnusedHashProperty = 'bar'; // cannot assert error message as it varies by platform
});
};
};
_proto2['@test cannot mutate params - no positional specified / named specified'] = function testCannotMutateParamsNoPositionalSpecifiedNamedSpecified() {
this.render('{{test-helper foo=bar}}', {
bar: 'derp'
});
};
_proto2['@test cannot mutate params - positional specified / no named specified'] = function testCannotMutateParamsPositionalSpecifiedNoNamedSpecified() {
this.render('{{test-helper bar}}', {
bar: 'derp'
});
};
_proto2['@test cannot mutate params - positional specified / named specified'] = function testCannotMutateParamsPositionalSpecifiedNamedSpecified() {
this.render('{{test-helper bar foo=qux}}', {
bar: 'derp',
qux: 'baz'
});
};
_proto2['@test cannot mutate params - no positional specified / no named specified'] = function testCannotMutateParamsNoPositionalSpecifiedNoNamedSpecified() {
this.render('{{test-helper}}', {
bar: 'derp',
qux: 'baz'
});
};
return HelperMutatingArgsTests;
}(_internalTestHelpers.RenderingTestCase);
(0, _internalTestHelpers.moduleFor)('Helpers test: mutation triggers errors - class based helper',
/*#__PURE__*/
function (_HelperMutatingArgsTe) {
(0, _emberBabel.inheritsLoose)(_class2, _HelperMutatingArgsTe);
function _class2() {
var _this22;
_this22 = _HelperMutatingArgsTe.apply(this, arguments) || this;
var compute = _this22.buildCompute();
_this22.registerHelper('test-helper', {
compute: compute
});
return _this22;
}
return _class2;
}(HelperMutatingArgsTests));
(0, _internalTestHelpers.moduleFor)('Helpers test: mutation triggers errors - simple helper',
/*#__PURE__*/
function (_HelperMutatingArgsTe2) {
(0, _emberBabel.inheritsLoose)(_class3, _HelperMutatingArgsTe2);
function _class3() {
var _this23;
_this23 = _HelperMutatingArgsTe2.apply(this, arguments) || this;
var compute = _this23.buildCompute();
_this23.registerHelper('test-helper', compute);
return _this23;
}
return _class3;
}(HelperMutatingArgsTests));
}
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/element-action-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/instrumentation", "@ember/-internals/runtime", "@ember/-internals/views", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _metal, _instrumentation, _runtime, _views, _helpers) {
"use strict";
function _templateObject6() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n \n {{yield}}\n "]);
_templateObject6 = function () {
return data;
};
return data;
}
function _templateObject5() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#middle-component}}\n {{inner-component action=\"hey\"}}\n {{/middle-component}}\n "]);
_templateObject5 = function () {
return data;
};
return data;
}
function _templateObject4() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n click me"]);
_templateObject4 = function () {
return data;
};
return data;
}
function _templateObject3() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#target-component as |aTarget|}}\n click me\n {{/target-component}}\n "]);
_templateObject3 = function () {
return data;
};
return data;
}
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#target-component as |parent|}}\n {{other-component anotherTarget=parent}}\n {{/target-component}}\n "]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#inner-component}}\n \n {{/inner-component}}\n "]);
_templateObject = function () {
return data;
};
return data;
}
function getActionAttributes(element) {
var attributes = element.attributes;
var actionAttrs = [];
for (var i = 0; i < attributes.length; i++) {
var 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);
});
}
var isIE11 = !window.ActiveXObject && 'ActiveXObject' in window;
if (false
/* EMBER_IMPROVED_INSTRUMENTATION */
) {
(0, _internalTestHelpers.moduleFor)('Helpers test: element action instrumentation',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_RenderingTestCase.prototype.teardown.call(this);
(0, _instrumentation.reset)();
};
_proto['@test action should fire interaction event with proper params'] = function testActionShouldFireInteractionEventWithProperParams() {
var _this = this;
var subscriberCallCount = 0;
var subscriberPayload = null;
var ExampleComponent = _helpers.Component.extend({
actions: {
foo: function () {}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: ''
});
(0, _instrumentation.subscribe)('interaction.ember-action', {
before: function () {
subscriberCallCount++;
},
after: function (name, time, payload) {
subscriberPayload = payload;
}
});
this.render('{{example-component}}');
this.assert.equal(subscriberCallCount, 0, 'subscriber has not been called');
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
this.assert.equal(subscriberCallCount, 0, 'subscriber has not been called');
(0, _internalTestHelpers.runTask)(function () {
_this.$('button').click();
});
this.assert.equal(subscriberCallCount, 1, 'subscriber has been called 1 time');
this.assert.equal(subscriberPayload.name, 'foo', 'subscriber called with correct name');
this.assert.equal(subscriberPayload.args[0], 'bar', 'subscriber called with correct args');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
}
(0, _internalTestHelpers.moduleFor)('Helpers test: element action',
/*#__PURE__*/
function (_RenderingTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _RenderingTestCase2);
function _class2() {
return _RenderingTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test it can call an action on its enclosing component'] = function testItCanCallAnActionOnItsEnclosingComponent() {
var _this2 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assert.equal(fooCallCount, 0, 'foo has not been called');
(0, _internalTestHelpers.runTask)(function () {
_this2.$('button').click();
});
this.assert.equal(fooCallCount, 1, 'foo has been called 1 time');
(0, _internalTestHelpers.runTask)(function () {
_this2.$('button').click();
});
this.assert.equal(fooCallCount, 2, 'foo has been called 2 times');
};
_proto2['@test it can call an action with parameters'] = function testItCanCallAnActionWithParameters() {
var _this3 = this;
var fooArgs = [];
var component;
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');
(0, _internalTestHelpers.runTask)(function () {
return _this3.rerender();
});
this.assert.deepEqual(fooArgs, [], 'foo has not been called');
(0, _internalTestHelpers.runTask)(function () {
_this3.$('button').click();
});
this.assert.deepEqual(fooArgs, ['a'], 'foo has not been called');
(0, _internalTestHelpers.runTask)(function () {
component.set('member', 'b');
});
(0, _internalTestHelpers.runTask)(function () {
_this3.$('button').click();
});
this.assert.deepEqual(fooArgs, ['a', 'b'], 'foo has been called with an updated value');
};
_proto2['@test it should output a marker attribute with a guid'] = function testItShouldOutputAMarkerAttributeWithAGuid() {
this.render('');
var button = this.$('button');
var attributes = getActionAttributes(button[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');
};
_proto2['@test it should allow alternative events to be handled'] = function testItShouldAllowAlternativeEventsToBeHandled() {
var _this4 = 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}}');
(0, _internalTestHelpers.runTask)(function () {
_this4.$('#show').trigger('mouseup');
});
this.assert.ok(showCalled, 'show action was called on mouseUp');
};
_proto2['@test inside a yield, the target points at the original target'] = function testInsideAYieldTheTargetPointsAtTheOriginalTarget() {
var _this5 = 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, _internalTestHelpers.strip)(_templateObject())
});
this.render('{{target-component}}');
(0, _internalTestHelpers.runTask)(function () {
_this5.$('button').click();
});
this.assert.ok(targetWatted, 'the correct target was watted');
this.assert.notOk(innerWatted, 'the inner target was not watted');
};
_proto2['@test it should allow a target to be specified'] = function testItShouldAllowATargetToBeSpecified() {
var _this6 = 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, _internalTestHelpers.strip)(_templateObject2()));
(0, _internalTestHelpers.runTask)(function () {
_this6.$('a').click();
});
this.assert.equal(targetWatted, true, 'the specified target was watted');
};
_proto2['@test it should lazily evaluate the target'] = function testItShouldLazilyEvaluateTheTarget() {
var _this7 = this;
var firstEdit = 0;
var secondEdit = 0;
var component;
var first = {
edit: function () {
firstEdit++;
}
};
var second = {
edit: function () {
secondEdit++;
}
};
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
theTarget: first
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: 'Edit'
});
this.render('{{example-component}}');
(0, _internalTestHelpers.runTask)(function () {
_this7.$('a').click();
});
this.assert.equal(firstEdit, 1);
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(component, 'theTarget', second);
});
(0, _internalTestHelpers.runTask)(function () {
_this7.$('a').click();
});
this.assert.equal(firstEdit, 1);
this.assert.equal(secondEdit, 1);
};
_proto2['@test it should register an event handler'] = function testItShouldRegisterAnEventHandler() {
var _this8 = 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}}');
(0, _internalTestHelpers.runTask)(function () {
_this8.$('a[data-ember-action]').trigger('click', {
altKey: true
});
});
this.assert.equal(editHandlerWasCalled, true, 'the event handler was called');
(0, _internalTestHelpers.runTask)(function () {
_this8.$('div[data-ember-action]').trigger('click', {
ctrlKey: true
});
});
this.assert.equal(shortcutHandlerWasCalled, true, 'the "any" shortcut\'s event handler was called');
};
_proto2['@test it handles whitelisted bound modifier keys'] = function testItHandlesWhitelistedBoundModifierKeys() {
var _this9 = 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}}');
(0, _internalTestHelpers.runTask)(function () {
_this9.$('a[data-ember-action]').trigger('click', {
altKey: true
});
});
this.assert.equal(editHandlerWasCalled, true, 'the event handler was called');
(0, _internalTestHelpers.runTask)(function () {
_this9.$('div[data-ember-action]').trigger('click', {
ctrlKey: true
});
});
this.assert.equal(shortcutHandlerWasCalled, true, 'the "any" shortcut\'s event handler was called');
};
_proto2['@test it handles whitelisted bound modifier keys with current value'] = function testItHandlesWhitelistedBoundModifierKeysWithCurrentValue() {
var _this10 = this;
var editHandlerWasCalled = false;
var component;
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}}');
(0, _internalTestHelpers.runTask)(function () {
_this10.$('a[data-ember-action]').trigger('click', {
altKey: true
});
});
this.assert.equal(editHandlerWasCalled, true, 'the event handler was called');
editHandlerWasCalled = false;
(0, _internalTestHelpers.runTask)(function () {
component.set('acceptedKeys', '');
});
(0, _internalTestHelpers.runTask)(function () {
_this10.$('div[data-ember-action]').click();
});
this.assert.equal(editHandlerWasCalled, false, 'the event handler was not called');
};
_proto2['@test should be able to use action more than once for the same event within a view'] = function testShouldBeAbleToUseActionMoreThanOnceForTheSameEventWithinAView() {
var _this11 = this;
var editHandlerWasCalled = false;
var deleteHandlerWasCalled = false;
var originalHandlerWasCalled = false;
var component;
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}}');
(0, _internalTestHelpers.runTask)(function () {
_this11.$('#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;
(0, _internalTestHelpers.runTask)(function () {
_this11.$('#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;
(0, _internalTestHelpers.runTask)(function () {
_this11.wrap(component.element).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');
};
_proto2['@test the event should not bubble if `bubbles=false` is passed'] = function testTheEventShouldNotBubbleIfBubblesFalseIsPassed() {
var _this12 = this;
var editHandlerWasCalled = false;
var deleteHandlerWasCalled = false;
var originalHandlerWasCalled = false;
var component;
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}}');
(0, _internalTestHelpers.runTask)(function () {
_this12.$('#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;
(0, _internalTestHelpers.runTask)(function () {
_this12.$('#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;
(0, _internalTestHelpers.runTask)(function () {
_this12.wrap(component.element).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');
};
_proto2['@test the event should not bubble if `bubbles=false` is passed bound'] = function testTheEventShouldNotBubbleIfBubblesFalseIsPassedBound() {
var _this13 = this;
var editHandlerWasCalled = false;
var deleteHandlerWasCalled = false;
var originalHandlerWasCalled = false;
var component;
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}}');
(0, _internalTestHelpers.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, false, 'the click handler was not called');
editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false;
(0, _internalTestHelpers.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, false, 'the click handler was not called');
editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false;
(0, _internalTestHelpers.runTask)(function () {
_this13.wrap(component.element).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');
};
_proto2['@test the bubbling depends on the bound parameter'] = function testTheBubblingDependsOnTheBoundParameter() {
var _this14 = this;
var editHandlerWasCalled = false;
var originalHandlerWasCalled = false;
var component;
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}}');
(0, _internalTestHelpers.runTask)(function () {
_this14.$('#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;
(0, _internalTestHelpers.runTask)(function () {
component.set('shouldBubble', true);
});
(0, _internalTestHelpers.runTask)(function () {
_this14.$('#edit').click();
});
this.assert.equal(editHandlerWasCalled, true, 'the edit action was called');
this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called');
};
_proto2['@test it should work properly in an #each block'] = function testItShouldWorkProperlyInAnEachBlock() {
var _this15 = this;
var editHandlerWasCalled = false;
var ExampleComponent = _helpers.Component.extend({
items: (0, _runtime.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}}');
(0, _internalTestHelpers.runTask)(function () {
_this15.$('a').click();
});
this.assert.equal(editHandlerWasCalled, true, 'the event handler was called');
};
_proto2['@test it should work properly in a {{#with foo as |bar|}} block'] = function testItShouldWorkProperlyInAWithFooAsBarBlock() {
var _this16 = 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}}');
(0, _internalTestHelpers.runTask)(function () {
_this16.$('a').click();
});
this.assert.equal(editHandlerWasCalled, true, 'the event handler was called');
};
_proto2['@test it should unregister event handlers when an element action is removed'] = function testItShouldUnregisterEventHandlersWhenAnElementActionIsRemoved(assert) {
var _this17 = 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
});
assert.equal(this.$('a[data-ember-action]').length, 1, 'The element is rendered');
var actionId;
actionId = getActionIds(this.$('a[data-ember-action]')[0])[0];
assert.ok(_views.ActionManager.registeredActions[actionId], 'An action is registered');
(0, _internalTestHelpers.runTask)(function () {
return _this17.rerender();
});
assert.equal(this.$('a[data-ember-action]').length, 1, 'The element is still present');
assert.ok(_views.ActionManager.registeredActions[actionId], 'The action is still registered');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this17.context, 'isActive', false);
});
assert.strictEqual(this.$('a[data-ember-action]').length, 0, 'The element is removed');
assert.ok(!_views.ActionManager.registeredActions[actionId], 'The action is unregistered');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this17.context, 'isActive', true);
});
assert.equal(this.$('a[data-ember-action]').length, 1, 'The element is rendered');
actionId = getActionIds(this.$('a[data-ember-action]')[0])[0];
assert.ok(_views.ActionManager.registeredActions[actionId], 'A new action is registered');
};
_proto2['@test it should capture events from child elements and allow them to trigger the action'] = function testItShouldCaptureEventsFromChildElementsAndAllowThemToTriggerTheAction() {
var _this18 = 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}}');
(0, _internalTestHelpers.runTask)(function () {
_this18.$('button').click();
});
this.assert.ok(editHandlerWasCalled, 'event on a child target triggered the action of its parent');
};
_proto2['@test it should allow bubbling of events from action helper to original parent event'] = function testItShouldAllowBubblingOfEventsFromActionHelperToOriginalParentEvent() {
var _this19 = 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}}');
(0, _internalTestHelpers.runTask)(function () {
_this19.$('a').click();
});
this.assert.ok(editHandlerWasCalled && originalHandlerWasCalled, 'both event handlers were called');
};
_proto2['@test it should not bubble an event from action helper to original parent event if `bubbles=false` is passed'] = function testItShouldNotBubbleAnEventFromActionHelperToOriginalParentEventIfBubblesFalseIsPassed() {
var _this20 = 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}}');
(0, _internalTestHelpers.runTask)(function () {
_this20.$('a').click();
});
this.assert.ok(editHandlerWasCalled, 'the child event handler was called');
this.assert.notOk(originalHandlerWasCalled, 'the parent handler was not called');
};
_proto2['@test it should allow "send" as the action name (#594)'] = function testItShouldAllowSendAsTheActionName594() {
var _this21 = 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}}');
(0, _internalTestHelpers.runTask)(function () {
_this21.$('a').click();
});
this.assert.ok(sendHandlerWasCalled, 'the event handler was called');
};
_proto2['@test it should send the view, event, and current context to the action'] = function testItShouldSendTheViewEventAndCurrentContextToTheAction() {
var _this22 = this;
var passedTarget;
var passedContext;
var targetThis;
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;
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, _internalTestHelpers.strip)(_templateObject3())
});
this.render('{{example-component}}');
(0, _internalTestHelpers.runTask)(function () {
_this22.$('#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');
};
_proto2['@test it should only trigger actions for the event they were registered on'] = function testItShouldOnlyTriggerActionsForTheEventTheyWereRegisteredOn() {
var _this23 = 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}}');
(0, _internalTestHelpers.runTask)(function () {
_this23.$('a').click();
});
this.assert.ok(editHandlerWasCalled, 'the event handler was called on click');
editHandlerWasCalled = false;
(0, _internalTestHelpers.runTask)(function () {
_this23.$('a').trigger('mouseover');
});
this.assert.notOk(editHandlerWasCalled, 'the event handler was not called on mouseover');
};
_proto2['@test it should allow multiple contexts to be specified'] = function testItShouldAllowMultipleContextsToBeSpecified() {
var _this24 = this;
var passedContexts;
var models = [_runtime.Object.create(), _runtime.Object.create()];
var ExampleComponent = _helpers.Component.extend({
modelA: models[0],
modelB: models[1],
actions: {
edit: function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
passedContexts = args;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: ''
});
this.render('{{example-component}}');
(0, _internalTestHelpers.runTask)(function () {
_this24.$('button').click();
});
this.assert.deepEqual(passedContexts, models, 'the action was called with the passed contexts');
};
_proto2['@test it should allow multiple contexts to be specified mixed with string args'] = function testItShouldAllowMultipleContextsToBeSpecifiedMixedWithStringArgs() {
var _this25 = this;
var passedContexts;
var model = _runtime.Object.create();
var ExampleComponent = _helpers.Component.extend({
model: model,
actions: {
edit: function () {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
passedContexts = args;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: ''
});
this.render('{{example-component}}');
(0, _internalTestHelpers.runTask)(function () {
_this25.$('button').click();
});
this.assert.deepEqual(passedContexts, ['herp', model], 'the action was called with the passed contexts');
};
_proto2['@test it should not trigger action with special clicks'] = function testItShouldNotTriggerActionWithSpecialClicks() {
var _this26 = this;
var showCalled = false;
var component;
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;
var checkClick = function (prop, value, expected) {
var _this26$wrap$findAll$;
showCalled = false;
var event = _this26.wrap(component.element).findAll('button').trigger('click', (_this26$wrap$findAll$ = {}, _this26$wrap$findAll$[prop] = value, _this26$wrap$findAll$))[0];
if (expected) {
assert.ok(showCalled, "should call action with " + prop + ":" + value); // IE11 does not allow simulated events to have a valid `defaultPrevented`
if (!isIE11) {
assert.ok(event.defaultPrevented, 'should prevent default');
}
} else {
assert.notOk(showCalled, "should not call action with " + prop + ":" + value);
assert.notOk(event.defaultPrevented, 'should not prevent default');
}
};
checkClick('ctrlKey', true, false);
checkClick('altKey', true, false);
checkClick('metaKey', true, false);
checkClick('shiftKey', true, false);
checkClick('button', 0, true);
checkClick('button', 1, false);
checkClick('button', 2, false);
checkClick('button', 3, false);
checkClick('button', 4, false);
};
_proto2['@test it can trigger actions for keyboard events'] = function testItCanTriggerActionsForKeyboardEvents() {
var _this27 = 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}}');
(0, _internalTestHelpers.runTask)(function () {
_this27.$('input').trigger('keyup', {
char: 'a',
which: 65
});
});
this.assert.ok(showCalled, 'the action was called with keyup');
};
_proto2['@test a quoteless parameter should allow dynamic lookup of the actionName'] = function testAQuotelessParameterShouldAllowDynamicLookupOfTheActionName() {
var _this28 = this;
var lastAction;
var actionOrder = [];
var component;
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;
var testBoundAction = function (propertyValue) {
(0, _internalTestHelpers.runTask)(function () {
component.set('hookMeUp', propertyValue);
});
(0, _internalTestHelpers.runTask)(function () {
_this28.wrap(component.element).findAll('#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');
};
_proto2['@test a quoteless string parameter should resolve actionName, including path'] = function testAQuotelessStringParameterShouldResolveActionNameIncludingPath() {
var _this29 = this;
var lastAction;
var actionOrder = [];
var component;
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
allactions: (0, _runtime.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;
var testBoundAction = function (propertyValue) {
(0, _internalTestHelpers.runTask)(function () {
_this29.wrap(component.element).findAll("#" + 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');
};
_proto2['@test a quoteless function parameter should be called, including arguments'] = function testAQuotelessFunctionParameterShouldBeCalledIncludingArguments() {
var _this30 = this;
var submitCalled = false;
var incomingArg;
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}}');
(0, _internalTestHelpers.runTask)(function () {
_this30.$('a').click();
});
this.assert.ok(submitCalled, 'submit function called');
this.assert.equal(incomingArg, arg, 'argument passed');
};
_proto2['@test a quoteless parameter that does not resolve to a value asserts'] = function testAQuotelessParameterThatDoesNotResolveToAValueAsserts() {
var _this31 = this;
var ExampleComponent = _helpers.Component.extend({
actions: {
ohNoeNotValid: function () {}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: 'Hi'
});
expectAssertion(function () {
_this31.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"}}).');
};
_proto2['@test allows multiple actions on a single element'] = function testAllowsMultipleActionsOnASingleElement() {
var _this32 = 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, _internalTestHelpers.strip)(_templateObject4())
});
this.render('{{example-component}}');
(0, _internalTestHelpers.runTask)(function () {
_this32.$('a').trigger('click');
});
this.assert.ok(clickActionWasCalled, 'the clicked action was called');
(0, _internalTestHelpers.runTask)(function () {
_this32.$('a').trigger('dblclick');
});
this.assert.ok(doubleClickActionWasCalled, 'the doubleClicked action was called');
};
_proto2['@test it should respect preventDefault option if provided'] = function testItShouldRespectPreventDefaultOptionIfProvided() {
var _this33 = this;
var ExampleComponent = _helpers.Component.extend({
actions: {
show: function () {}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: 'Hi'
});
this.render('{{example-component}}');
var event;
(0, _internalTestHelpers.runTask)(function () {
event = _this33.$('a').click()[0];
});
this.assert.equal(event.defaultPrevented, false, 'should not preventDefault');
};
_proto2['@test it should respect preventDefault option if provided bound'] = function testItShouldRespectPreventDefaultOptionIfProvidedBound() {
var _this34 = this;
var component;
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;
(0, _internalTestHelpers.runTask)(function () {
event = _this34.$('a').trigger(event)[0];
});
this.assert.equal(event.defaultPrevented, false, 'should not preventDefault');
(0, _internalTestHelpers.runTask)(function () {
component.set('shouldPreventDefault', true);
event = _this34.$('a').trigger('click')[0];
}); // IE11 does not allow simulated events to have a valid `defaultPrevented`
if (!isIE11) {
this.assert.equal(event.defaultPrevented, true, 'should preventDefault');
}
};
_proto2['@test it should target the proper component when `action` is in yielded block [GH #12409]'] = function testItShouldTargetTheProperComponentWhenActionIsInYieldedBlockGH12409() {
var _this36 = 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 () {
var _this35 = this;
innerClickCalled = true;
expectDeprecation(function () {
_this35.sendAction();
}, /You called (.*).sendAction\((.*)\) but Component#sendAction is deprecated. Please use closure actions instead./);
}
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: (0, _internalTestHelpers.strip)(_templateObject5())
});
this.registerComponent('middle-component', {
ComponentClass: MiddleComponent,
template: '{{yield}}'
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: (0, _internalTestHelpers.strip)(_templateObject6())
});
this.render('{{outer-component}}');
(0, _internalTestHelpers.runTask)(function () {
_this36.$('button').click();
});
this.assert.ok(outerActionCalled, 'the action fired on the proper target');
this.assert.ok(innerClickCalled, 'the click was triggered');
};
_proto2['@test element action with (mut undefinedThing) works properly'] = function testElementActionWithMutUndefinedThingWorksProperly() {
var _this37 = this;
var component;
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();
(0, _internalTestHelpers.runTask)(function () {
_this37.$('button').click();
});
this.assertText('Clicked!');
(0, _internalTestHelpers.runTask)(function () {
component.set('label', 'Dun clicked');
});
this.assertText('Dun clicked');
(0, _internalTestHelpers.runTask)(function () {
_this37.$('button').click();
});
this.assertText('Clicked!');
(0, _internalTestHelpers.runTask)(function () {
component.set('label', undefined);
});
this.assertText('Click me');
};
_proto2['@test it supports non-registered actions [GH#14888]'] = function testItSupportsNonRegisteredActionsGH14888() {
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.
(0, _internalTestHelpers.runTask)(function () {
document.getElementById('ddButton').focus();
document.getElementById('ddButton').click();
});
};
_proto2["@test action handler that shifts element attributes doesn't trigger multiple invocations"] = function testActionHandlerThatShiftsElementAttributesDoesnTTriggerMultipleInvocations() {
var _this38 = 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}}');
(0, _internalTestHelpers.runTask)(function () {
_this38.$('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");
(0, _internalTestHelpers.runTask)(function () {
_this38.$('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;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/get-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _metal, _helpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Helpers test: {{get}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should be able to get an object value with a static key'] = function testShouldBeAbleToGetAnObjectValueWithAStaticKey() {
var _this = this;
this.render("[{{get colors 'apple'}}] [{{if true (get colors 'apple')}}]", {
colors: {
apple: 'red'
}
});
this.assertText('[red] [red]');
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
this.assertText('[red] [red]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'colors.apple', 'green');
});
this.assertText('[green] [green]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'colors', {
apple: 'red'
});
});
this.assertText('[red] [red]');
};
_proto['@test should be able to get an object value with nested static key'] = function testShouldBeAbleToGetAnObjectValueWithNestedStaticKey() {
var _this2 = 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]');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertText('[red and yellow] [red and yellow]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'colors.apple.gala', 'yellow and red striped');
});
this.assertText('[yellow and red striped] [yellow and red striped]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'colors', {
apple: {
gala: 'red and yellow'
}
});
});
this.assertText('[red and yellow] [red and yellow]');
};
_proto['@test should be able to get an object value with a number'] = function testShouldBeAbleToGetAnObjectValueWithANumber() {
var _this3 = this;
this.render("[{{get items 1}}][{{get items 2}}][{{get items 3}}]", {
indexes: [1, 2, 3],
items: {
1: 'First',
2: 'Second',
3: 'Third'
}
});
this.assertText('[First][Second][Third]');
(0, _internalTestHelpers.runTask)(function () {
return _this3.rerender();
});
this.assertText('[First][Second][Third]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'items.1', 'Qux');
});
this.assertText('[Qux][Second][Third]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'items', {
1: 'First',
2: 'Second',
3: 'Third'
});
});
this.assertText('[First][Second][Third]');
};
_proto['@test should be able to get an array value with a number'] = function testShouldBeAbleToGetAnArrayValueWithANumber() {
var _this4 = this;
this.render("[{{get numbers 0}}][{{get numbers 1}}][{{get numbers 2}}]", {
numbers: [1, 2, 3]
});
this.assertText('[1][2][3]');
(0, _internalTestHelpers.runTask)(function () {
return _this4.rerender();
});
this.assertText('[1][2][3]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'numbers', [3, 2, 1]);
});
this.assertText('[3][2][1]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'numbers', [1, 2, 3]);
});
this.assertText('[1][2][3]');
};
_proto['@test should be able to get an object value with a path evaluating to a number'] = function testShouldBeAbleToGetAnObjectValueWithAPathEvaluatingToANumber() {
var _this5 = this;
this.render("{{#each indexes as |index|}}[{{get items index}}]{{/each}}", {
indexes: [1, 2, 3],
items: {
1: 'First',
2: 'Second',
3: 'Third'
}
});
this.assertText('[First][Second][Third]');
(0, _internalTestHelpers.runTask)(function () {
return _this5.rerender();
});
this.assertText('[First][Second][Third]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'items.1', 'Qux');
});
this.assertText('[Qux][Second][Third]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'items', {
1: 'First',
2: 'Second',
3: 'Third'
});
});
this.assertText('[First][Second][Third]');
};
_proto['@test should be able to get an array value with a path evaluating to a number'] = function testShouldBeAbleToGetAnArrayValueWithAPathEvaluatingToANumber() {
var _this6 = this;
this.render("{{#each numbers as |num index|}}[{{get numbers index}}]{{/each}}", {
numbers: [1, 2, 3]
});
this.assertText('[1][2][3]');
(0, _internalTestHelpers.runTask)(function () {
return _this6.rerender();
});
this.assertText('[1][2][3]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'numbers', [3, 2, 1]);
});
this.assertText('[3][2][1]');
};
_proto['@test should be able to get an object value with a bound/dynamic key'] = function testShouldBeAbleToGetAnObjectValueWithABoundDynamicKey() {
var _this7 = this;
this.render("[{{get colors key}}] [{{if true (get colors key)}}]", {
colors: {
apple: 'red',
banana: 'yellow'
},
key: 'apple'
});
this.assertText('[red] [red]');
(0, _internalTestHelpers.runTask)(function () {
return _this7.rerender();
});
this.assertText('[red] [red]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this7.context, 'key', 'banana');
});
this.assertText('[yellow] [yellow]');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this7.context, 'colors.apple', 'green');
(0, _metal.set)(_this7.context, 'colors.banana', 'purple');
});
this.assertText('[purple] [purple]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this7.context, 'key', 'apple');
});
this.assertText('[green] [green]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this7.context, 'colors', {
apple: 'red'
});
});
this.assertText('[red] [red]');
};
_proto['@test should be able to get an object value with nested dynamic key'] = function testShouldBeAbleToGetAnObjectValueWithNestedDynamicKey() {
var _this8 = 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]');
(0, _internalTestHelpers.runTask)(function () {
return _this8.rerender();
});
this.assertText('[red and yellow] [red and yellow]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this8.context, 'key', 'apple.mcintosh');
});
this.assertText('[red] [red]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this8.context, 'key', 'banana');
});
this.assertText('[yellow] [yellow]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this8.context, 'key', 'apple.gala');
});
this.assertText('[red and yellow] [red and yellow]');
};
_proto['@test should be able to get an object value with subexpression returning nested key'] = function testShouldBeAbleToGetAnObjectValueWithSubexpressionReturningNestedKey() {
var _this9 = 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]');
(0, _internalTestHelpers.runTask)(function () {
return _this9.rerender();
});
this.assertText('[red and yellow] [red and yellow]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this9.context, 'colors.apple.gala', 'yellow and red striped');
});
this.assertText('[yellow and red striped] [yellow and red striped]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this9.context, 'colors.apple.gala', 'yellow-redish');
});
this.assertText('[yellow-redish] [yellow-redish]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this9.context, 'colors', {
apple: {
gala: 'red and yellow',
mcintosh: 'red'
}
});
});
this.assertText('[red and yellow] [red and yellow]');
};
_proto['@test should be able to get an object value with a get helper as the key'] = function testShouldBeAbleToGetAnObjectValueWithAGetHelperAsTheKey() {
var _this10 = 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]');
(0, _internalTestHelpers.runTask)(function () {
return _this10.rerender();
});
this.assertText('[red] [red]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this10.context, 'key', 'key2');
});
this.assertText('[yellow] [yellow]');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this10.context, 'colors.apple', 'green');
(0, _metal.set)(_this10.context, 'colors.banana', 'purple');
});
this.assertText('[purple] [purple]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this10.context, 'key', 'key1');
});
this.assertText('[green] [green]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this10.context, 'colors', {
apple: 'red',
banana: 'yellow'
});
});
this.assertText('[red] [red]');
};
_proto['@test should be able to get an object value with a get helper value as a bound/dynamic key'] = function testShouldBeAbleToGetAnObjectValueWithAGetHelperValueAsABoundDynamicKey() {
var _this11 = 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]');
(0, _internalTestHelpers.runTask)(function () {
return _this11.rerender();
});
this.assertText('[red] [red]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'objectKey', 'colors2');
});
this.assertText('[green] [green]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'objectKey', 'colors1');
});
this.assertText('[red] [red]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'key', 'banana');
});
this.assertText('[yellow] [yellow]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'objectKey', 'colors2');
});
this.assertText('[purple] [purple]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'objectKey', 'colors1');
});
this.assertText('[yellow] [yellow]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'key', 'apple');
});
};
_proto['@test should be able to get an object value with a get helper as the value and a get helper as the key'] = function testShouldBeAbleToGetAnObjectValueWithAGetHelperAsTheValueAndAGetHelperAsTheKey() {
var _this12 = 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]');
(0, _internalTestHelpers.runTask)(function () {
return _this12.rerender();
});
this.assertText('[red] [red]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'objectKey', 'colors2');
});
this.assertText('[green] [green]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'objectKey', 'colors1');
});
this.assertText('[red] [red]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'key', 'key2');
});
this.assertText('[yellow] [yellow]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'objectKey', 'colors2');
});
this.assertText('[purple] [purple]');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this12.context, 'objectKey', 'colors1');
(0, _metal.set)(_this12.context, 'key', 'key1');
});
this.assertText('[red] [red]');
};
_proto['@test the result of a get helper can be yielded'] = function testTheResultOfAGetHelperCanBeYielded() {
var _this13 = this;
var fooBarInstance;
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');
(0, _internalTestHelpers.runTask)(function () {
return _this13.rerender();
});
this.assertText('banana');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(fooBarInstance, 'mcintosh', 'yellow');
(0, _metal.set)(_this13.context, 'colors', {
yellow: 'bus'
});
});
this.assertText('bus');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(fooBarInstance, 'mcintosh', 'red');
(0, _metal.set)(_this13.context, 'colors', {
red: 'banana'
});
});
this.assertText('banana');
};
_proto['@test should handle object values as nulls'] = function testShouldHandleObjectValuesAsNulls() {
var _this14 = this;
this.render("[{{get colors 'apple'}}] [{{if true (get colors 'apple')}}]", {
colors: null
});
this.assertText('[] []');
(0, _internalTestHelpers.runTask)(function () {
return _this14.rerender();
});
this.assertText('[] []');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this14.context, 'colors', {
apple: 'green',
banana: 'purple'
});
});
this.assertText('[green] [green]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this14.context, 'colors', null);
});
this.assertText('[] []');
};
_proto['@test should handle object keys as nulls'] = function testShouldHandleObjectKeysAsNulls() {
var _this15 = this;
this.render("[{{get colors key}}] [{{if true (get colors key)}}]", {
colors: {
apple: 'red',
banana: 'yellow'
},
key: null
});
this.assertText('[] []');
(0, _internalTestHelpers.runTask)(function () {
return _this15.rerender();
});
this.assertText('[] []');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this15.context, 'key', 'banana');
});
this.assertText('[yellow] [yellow]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this15.context, 'key', null);
});
this.assertText('[] []');
};
_proto['@test should handle object values and keys as nulls'] = function testShouldHandleObjectValuesAndKeysAsNulls() {
this.render("[{{get colors 'apple'}}] [{{if true (get colors key)}}]", {
colors: null,
key: null
});
this.assertText('[] []');
};
_proto['@test get helper value should be updatable using {{input}} and (mut) - static key'] = function testGetHelperValueShouldBeUpdatableUsingInputAndMutStaticKey(assert) {
var _this16 = this;
this.render("{{input type='text' value=(mut (get source 'banana')) id='get-input'}}", {
source: {
banana: 'banana'
}
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
(0, _internalTestHelpers.runTask)(function () {
return _this16.rerender();
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this16.context, 'source.banana', 'yellow');
});
assert.strictEqual(this.$('#get-input').val(), 'yellow');
(0, _internalTestHelpers.runTask)(function () {
return _this16.$('#get-input').val('some value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'some value');
assert.strictEqual((0, _metal.get)(this.context, 'source.banana'), 'some value');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this16.context, 'source', {
banana: 'banana'
});
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
};
_proto['@test get helper value should be updatable using {{input}} and (mut) - dynamic key'] = function testGetHelperValueShouldBeUpdatableUsingInputAndMutDynamicKey(assert) {
var _this17 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this17.rerender();
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this17.context, 'source.banana', 'yellow');
});
assert.strictEqual(this.$('#get-input').val(), 'yellow');
(0, _internalTestHelpers.runTask)(function () {
return _this17.$('#get-input').val('some value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'some value');
assert.strictEqual((0, _metal.get)(this.context, 'source.banana'), 'some value');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this17.context, 'key', 'apple');
});
assert.strictEqual(this.$('#get-input').val(), 'apple');
(0, _internalTestHelpers.runTask)(function () {
return _this17.$('#get-input').val('some other value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'some other value');
assert.strictEqual((0, _metal.get)(this.context, 'source.apple'), 'some other value');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this17.context, 'key', 'banana');
(0, _metal.set)(_this17.context, 'source', {
banana: 'banana'
});
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
};
_proto['@test get helper value should be updatable using {{input}} and (mut) - dynamic nested key'] = function testGetHelperValueShouldBeUpdatableUsingInputAndMutDynamicNestedKey(assert) {
var _this18 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this18.rerender();
});
assert.strictEqual(this.$('#get-input').val(), 'mcintosh');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this18.context, 'source.apple.mcintosh', 'red');
});
assert.strictEqual(this.$('#get-input').val(), 'red');
(0, _internalTestHelpers.runTask)(function () {
return _this18.$('#get-input').val('some value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'some value');
assert.strictEqual((0, _metal.get)(this.context, 'source.apple.mcintosh'), 'some value');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this18.context, 'key', 'apple.gala');
});
assert.strictEqual(this.$('#get-input').val(), 'gala');
(0, _internalTestHelpers.runTask)(function () {
return _this18.$('#get-input').val('some other value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'some other value');
assert.strictEqual((0, _metal.get)(this.context, 'source.apple.gala'), 'some other value');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this18.context, 'key', 'banana');
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
(0, _internalTestHelpers.runTask)(function () {
return _this18.$('#get-input').val('yet another value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'yet another value');
assert.strictEqual((0, _metal.get)(this.context, 'source.banana'), 'yet another value');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this18.context, 'key', 'apple.mcintosh');
(0, _metal.set)(_this18.context, 'source', {
apple: {
gala: 'gala',
mcintosh: 'mcintosh'
},
banana: 'banana'
});
});
assert.strictEqual(this.$('#get-input').val(), 'mcintosh');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/hash-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/glimmer/tests/utils/helpers", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _helpers, _metal) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Helpers test: {{hash}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test returns a hash with the right key-value'] = function testReturnsAHashWithTheRightKeyValue() {
var _this = this;
this.render("{{#with (hash name=\"Sergio\") as |person|}}{{person.name}}{{/with}}");
this.assertText('Sergio');
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
this.assertText('Sergio');
};
_proto['@test can have more than one key-value'] = function testCanHaveMoreThanOneKeyValue() {
var _this2 = this;
this.render("{{#with (hash name=\"Sergio\" lastName=\"Arbeo\") as |person|}}{{person.name}} {{person.lastName}}{{/with}}");
this.assertText('Sergio Arbeo');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertText('Sergio Arbeo');
};
_proto['@test binds values when variables are used'] = function testBindsValuesWhenVariablesAreUsed() {
var _this3 = this;
this.render("{{#with (hash name=model.firstName lastName=\"Arbeo\") as |person|}}{{person.name}} {{person.lastName}}{{/with}}", {
model: {
firstName: 'Marisa'
}
});
this.assertText('Marisa Arbeo');
(0, _internalTestHelpers.runTask)(function () {
return _this3.rerender();
});
this.assertText('Marisa Arbeo');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'model.firstName', 'Sergio');
});
this.assertText('Sergio Arbeo');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'model', {
firstName: 'Marisa'
});
});
this.assertText('Marisa Arbeo');
};
_proto['@test binds multiple values when variables are used'] = function testBindsMultipleValuesWhenVariablesAreUsed() {
var _this4 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this4.rerender();
});
this.assertText('Marisa Arbeo');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'model.firstName', 'Sergio');
});
this.assertText('Sergio Arbeo');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'model.lastName', 'Smith');
});
this.assertText('Sergio Smith');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'model', {
firstName: 'Marisa',
lastName: 'Arbeo'
});
});
this.assertText('Marisa Arbeo');
};
_proto['@test hash helpers can be nested'] = function testHashHelpersCanBeNested() {
var _this5 = this;
this.render("{{#with (hash person=(hash name=model.firstName)) as |ctx|}}{{ctx.person.name}}{{/with}}", {
model: {
firstName: 'Balint'
}
});
this.assertText('Balint');
(0, _internalTestHelpers.runTask)(function () {
return _this5.rerender();
});
this.assertText('Balint');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'model.firstName', 'Chad');
});
this.assertText('Chad');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'model', {
firstName: 'Balint'
});
});
this.assertText('Balint');
};
_proto['@test should yield hash of internal properties'] = function testShouldYieldHashOfInternalProperties() {
var _this6 = this;
var fooBarInstance;
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');
(0, _internalTestHelpers.runTask)(function () {
return _this6.rerender();
});
this.assertText('Chad');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(fooBarInstance, 'model.firstName', 'Godfrey');
});
this.assertText('Godfrey');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(fooBarInstance, 'model', {
firstName: 'Chad'
});
});
this.assertText('Chad');
};
_proto['@test should yield hash of internal and external properties'] = function testShouldYieldHashOfInternalAndExternalProperties() {
var _this7 = this;
var fooBarInstance;
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');
(0, _internalTestHelpers.runTask)(function () {
return _this7.rerender();
});
this.assertText('Chad Hietala');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(fooBarInstance, 'model.firstName', 'Godfrey');
(0, _metal.set)(_this7.context, 'model.lastName', 'Chan');
});
this.assertText('Godfrey Chan');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(fooBarInstance, 'model', {
firstName: 'Chad'
});
(0, _metal.set)(_this7.context, 'model', {
lastName: 'Hietala'
});
});
this.assertText('Chad Hietala');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/if-unless-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/glimmer/tests/utils/shared-conditional-tests"], function (_emberBabel, _internalTestHelpers, _sharedConditionalTests) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Helpers test: inline {{if}}',
/*#__PURE__*/
function (_IfUnlessHelperTest) {
(0, _emberBabel.inheritsLoose)(_class, _IfUnlessHelperTest);
function _class() {
return _IfUnlessHelperTest.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.templateFor = function templateFor(_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return "{{if " + cond + " " + truthy + " " + falsy + "}}";
};
_proto['@test it raises when there are more than three arguments'] = function testItRaisesWhenThereAreMoreThanThreeArguments() {
var _this = this;
expectAssertion(function () {
_this.render("{{if condition 'a' 'b' 'c'}}", {
condition: true
});
}, "The inline form of the 'if' helper expects two or three arguments. ('-top-level' @ L1:C0) ");
};
_proto['@test it raises when there are less than two arguments'] = function testItRaisesWhenThereAreLessThanTwoArguments() {
var _this2 = this;
expectAssertion(function () {
_this2.render("{{if condition}}", {
condition: true
});
}, "The inline form of the 'if' helper expects two or three arguments. ('-top-level' @ L1:C0) ");
};
return _class;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _internalTestHelpers.moduleFor)('Helpers test: nested {{if}} helpers (returning truthy values)',
/*#__PURE__*/
function (_IfUnlessHelperTest2) {
(0, _emberBabel.inheritsLoose)(_class2, _IfUnlessHelperTest2);
function _class2() {
return _IfUnlessHelperTest2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2.templateFor = function templateFor(_ref2) {
var cond = _ref2.cond,
truthy = _ref2.truthy,
falsy = _ref2.falsy;
return "{{if (if " + cond + " " + cond + " false) " + truthy + " " + falsy + "}}";
};
return _class2;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _internalTestHelpers.moduleFor)('Helpers test: nested {{if}} helpers (returning falsy values)',
/*#__PURE__*/
function (_IfUnlessHelperTest3) {
(0, _emberBabel.inheritsLoose)(_class3, _IfUnlessHelperTest3);
function _class3() {
return _IfUnlessHelperTest3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3.templateFor = function templateFor(_ref3) {
var cond = _ref3.cond,
truthy = _ref3.truthy,
falsy = _ref3.falsy;
return "{{if (if " + cond + " true " + cond + ") " + truthy + " " + falsy + "}}";
};
return _class3;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _internalTestHelpers.moduleFor)('Helpers test: {{if}} used with another helper',
/*#__PURE__*/
function (_IfUnlessHelperTest4) {
(0, _emberBabel.inheritsLoose)(_class4, _IfUnlessHelperTest4);
function _class4() {
return _IfUnlessHelperTest4.apply(this, arguments) || this;
}
var _proto4 = _class4.prototype;
_proto4.wrapperFor = function wrapperFor(templates) {
return "{{concat " + templates.join(' ') + "}}";
};
_proto4.templateFor = function templateFor(_ref4) {
var cond = _ref4.cond,
truthy = _ref4.truthy,
falsy = _ref4.falsy;
return "(if " + cond + " " + truthy + " " + falsy + ")";
};
return _class4;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _internalTestHelpers.moduleFor)('Helpers test: {{if}} used in attribute position',
/*#__PURE__*/
function (_IfUnlessHelperTest5) {
(0, _emberBabel.inheritsLoose)(_class5, _IfUnlessHelperTest5);
function _class5() {
return _IfUnlessHelperTest5.apply(this, arguments) || this;
}
var _proto5 = _class5.prototype;
_proto5.wrapperFor = function wrapperFor(templates) {
return "";
};
_proto5.templateFor = function templateFor(_ref5) {
var cond = _ref5.cond,
truthy = _ref5.truthy,
falsy = _ref5.falsy;
return "{{if " + cond + " " + truthy + " " + falsy + "}}";
};
_proto5.textValue = function textValue() {
return this.$('div').attr('data-foo');
};
return _class5;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _internalTestHelpers.moduleFor)('Helpers test: inline {{if}} and {{unless}} without the inverse argument',
/*#__PURE__*/
function (_IfUnlessHelperTest6) {
(0, _emberBabel.inheritsLoose)(_class6, _IfUnlessHelperTest6);
function _class6() {
return _IfUnlessHelperTest6.apply(this, arguments) || this;
}
var _proto6 = _class6.prototype;
_proto6.templateFor = function templateFor(_ref6) {
var cond = _ref6.cond,
truthy = _ref6.truthy,
falsy = _ref6.falsy;
return "{{if " + cond + " " + truthy + "}}{{unless " + cond + " " + falsy + "}}";
};
return _class6;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _internalTestHelpers.moduleFor)('Helpers test: inline {{unless}}',
/*#__PURE__*/
function (_IfUnlessHelperTest7) {
(0, _emberBabel.inheritsLoose)(_class7, _IfUnlessHelperTest7);
function _class7() {
return _IfUnlessHelperTest7.apply(this, arguments) || this;
}
var _proto7 = _class7.prototype;
_proto7.templateFor = function templateFor(_ref7) {
var cond = _ref7.cond,
truthy = _ref7.truthy,
falsy = _ref7.falsy;
return "{{unless " + cond + " " + falsy + " " + truthy + "}}";
};
_proto7['@test it raises when there are more than three arguments'] = function testItRaisesWhenThereAreMoreThanThreeArguments() {
var _this3 = this;
expectAssertion(function () {
_this3.render("{{unless condition 'a' 'b' 'c'}}", {
condition: true
});
}, /The inline form of the `unless` helper expects two or three arguments/);
};
_proto7['@test it raises when there are less than two arguments'] = function testItRaisesWhenThereAreLessThanTwoArguments() {
var _this4 = this;
expectAssertion(function () {
_this4.render("{{unless condition}}", {
condition: true
});
}, /The inline form of the `unless` helper expects two or three arguments/);
};
return _class7;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _internalTestHelpers.moduleFor)('Helpers test: nested {{unless}} helpers (returning truthy values)',
/*#__PURE__*/
function (_IfUnlessHelperTest8) {
(0, _emberBabel.inheritsLoose)(_class8, _IfUnlessHelperTest8);
function _class8() {
return _IfUnlessHelperTest8.apply(this, arguments) || this;
}
var _proto8 = _class8.prototype;
_proto8.templateFor = function templateFor(_ref8) {
var cond = _ref8.cond,
truthy = _ref8.truthy,
falsy = _ref8.falsy;
return "{{unless (unless " + cond + " false " + cond + ") " + falsy + " " + truthy + "}}";
};
return _class8;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _internalTestHelpers.moduleFor)('Helpers test: nested {{unless}} helpers (returning falsy values)',
/*#__PURE__*/
function (_IfUnlessHelperTest9) {
(0, _emberBabel.inheritsLoose)(_class9, _IfUnlessHelperTest9);
function _class9() {
return _IfUnlessHelperTest9.apply(this, arguments) || this;
}
var _proto9 = _class9.prototype;
_proto9.templateFor = function templateFor(_ref9) {
var cond = _ref9.cond,
truthy = _ref9.truthy,
falsy = _ref9.falsy;
return "{{unless (unless " + cond + " " + cond + " true) " + falsy + " " + truthy + "}}";
};
return _class9;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _internalTestHelpers.moduleFor)('Helpers test: {{unless}} used with another helper',
/*#__PURE__*/
function (_IfUnlessHelperTest10) {
(0, _emberBabel.inheritsLoose)(_class10, _IfUnlessHelperTest10);
function _class10() {
return _IfUnlessHelperTest10.apply(this, arguments) || this;
}
var _proto10 = _class10.prototype;
_proto10.wrapperFor = function wrapperFor(templates) {
return "{{concat " + templates.join(' ') + "}}";
};
_proto10.templateFor = function templateFor(_ref10) {
var cond = _ref10.cond,
truthy = _ref10.truthy,
falsy = _ref10.falsy;
return "(unless " + cond + " " + falsy + " " + truthy + ")";
};
return _class10;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _internalTestHelpers.moduleFor)('Helpers test: {{unless}} used in attribute position',
/*#__PURE__*/
function (_IfUnlessHelperTest11) {
(0, _emberBabel.inheritsLoose)(_class11, _IfUnlessHelperTest11);
function _class11() {
return _IfUnlessHelperTest11.apply(this, arguments) || this;
}
var _proto11 = _class11.prototype;
_proto11.wrapperFor = function wrapperFor(templates) {
return "";
};
_proto11.templateFor = function templateFor(_ref11) {
var cond = _ref11.cond,
truthy = _ref11.truthy,
falsy = _ref11.falsy;
return "{{unless " + cond + " " + falsy + " " + truthy + "}}";
};
_proto11.textValue = function textValue() {
return this.$('div').attr('data-foo');
};
return _class11;
}(_sharedConditionalTests.IfUnlessHelperTest));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/input-test", ["ember-babel", "internal-test-helpers", "@ember/polyfills", "@ember/-internals/metal", "@ember/-internals/views", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _polyfills, _metal, _views, _helpers) {
"use strict";
var InputRenderingTest =
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(InputRenderingTest, _RenderingTestCase);
function InputRenderingTest() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = InputRenderingTest.prototype;
_proto.$input = function $input() {
return this.$('input');
};
_proto.inputID = function inputID() {
return this.$input().prop('id');
};
_proto.assertDisabled = function assertDisabled() {
this.assert.ok(this.$('input').prop('disabled'), 'The input is disabled');
};
_proto.assertNotDisabled = function assertNotDisabled() {
this.assert.ok(this.$('input').is(':not(:disabled)'), 'The input is not disabled');
};
_proto.assertInputId = function assertInputId(expectedId) {
this.assert.equal(this.inputID(), expectedId, 'the input id should be `expectedId`');
};
_proto.assertSingleInput = function assertSingleInput() {
this.assert.equal(this.$('input').length, 1, 'A single text field was inserted');
};
_proto.assertSingleCheckbox = function assertSingleCheckbox() {
this.assert.equal(this.$('input[type=checkbox]').length, 1, 'A single checkbox is added');
};
_proto.assertCheckboxIsChecked = function assertCheckboxIsChecked() {
this.assert.equal(this.$input().prop('checked'), true, 'the checkbox is checked');
};
_proto.assertCheckboxIsNotChecked = function assertCheckboxIsNotChecked() {
this.assert.equal(this.$input().prop('checked'), false, 'the checkbox is not checked');
};
_proto.assertValue = function assertValue(expected) {
this.assert.equal(this.$input().val(), expected, "the input value should be " + expected);
};
_proto.assertAttr = function assertAttr(name, expected) {
this.assert.equal(this.$input().attr(name), expected, "the input " + name + " attribute has the value '" + expected + "'");
};
_proto.assertAllAttrs = function assertAllAttrs(names, expected) {
var _this = this;
names.forEach(function (name) {
return _this.assertAttr(name, expected);
});
};
_proto.assertSelectionRange = function assertSelectionRange(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);
};
_proto.triggerEvent = function triggerEvent(type, options) {
var event = document.createEvent('Events');
event.initEvent(type, true, true);
(0, _polyfills.assign)(event, options);
var element = this.$input()[0];
(0, _internalTestHelpers.runTask)(function () {
element.dispatchEvent(event);
});
};
return InputRenderingTest;
}(_internalTestHelpers.RenderingTestCase);
(0, _internalTestHelpers.moduleFor)('Helpers test: {{input}}',
/*#__PURE__*/
function (_InputRenderingTest) {
(0, _emberBabel.inheritsLoose)(_class, _InputRenderingTest);
function _class() {
return _InputRenderingTest.apply(this, arguments) || this;
}
var _proto2 = _class.prototype;
_proto2['@test a single text field is inserted into the DOM'] = function testASingleTextFieldIsInsertedIntoTheDOM() {
var _this2 = this;
this.render("{{input type=\"text\" value=value}}", {
value: 'hello'
});
var id = this.inputID();
this.assertValue('hello');
this.assertSingleInput();
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertValue('hello');
this.assertSingleInput();
this.assertInputId(id);
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'value', 'goodbye');
});
this.assertValue('goodbye');
this.assertSingleInput();
this.assertInputId(id);
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'value', 'hello');
});
this.assertValue('hello');
this.assertSingleInput();
this.assertInputId(id);
};
_proto2['@test default type'] = function testDefaultType() {
var _this3 = this;
this.render("{{input}}");
this.assertAttr('type', 'text');
(0, _internalTestHelpers.runTask)(function () {
return _this3.rerender();
});
this.assertAttr('type', 'text');
};
_proto2['@test dynamic attributes'] = function testDynamicAttributes() {
var _this4 = this;
this.render("\n {{input type=\"text\"\n disabled=disabled\n value=value\n placeholder=placeholder\n name=name\n maxlength=maxlength\n minlength=minlength\n size=size\n tabindex=tabindex\n }}", {
disabled: false,
value: 'Original value',
placeholder: 'Original placeholder',
name: 'original-name',
maxlength: 10,
minlength: 5,
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('minlength', '5'); // this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
(0, _internalTestHelpers.runTask)(function () {
return _this4.rerender();
});
this.assertNotDisabled();
this.assertValue('Original value');
this.assertAttr('placeholder', 'Original placeholder');
this.assertAttr('name', 'original-name');
this.assertAttr('maxlength', '10');
this.assertAttr('minlength', '5'); // this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this4.context, 'value', 'Updated value');
(0, _metal.set)(_this4.context, 'disabled', true);
(0, _metal.set)(_this4.context, 'placeholder', 'Updated placeholder');
(0, _metal.set)(_this4.context, 'name', 'updated-name');
(0, _metal.set)(_this4.context, 'maxlength', 11);
(0, _metal.set)(_this4.context, 'minlength', 6); // 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('minlength', '6'); // this.assertAttr('size', '21'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '31'); //NOTE: failing in IE (TEST_SUITE=sauce)
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this4.context, 'value', 'Original value');
(0, _metal.set)(_this4.context, 'disabled', false);
(0, _metal.set)(_this4.context, 'placeholder', 'Original placeholder');
(0, _metal.set)(_this4.context, 'name', 'original-name');
(0, _metal.set)(_this4.context, 'maxlength', 10);
(0, _metal.set)(_this4.context, 'minlength', 5); // 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('minlength', '5'); // this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
};
_proto2['@test static attributes'] = function testStaticAttributes() {
var _this5 = 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 minlength=5\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('minlength', '5'); // this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
(0, _internalTestHelpers.runTask)(function () {
return _this5.rerender();
});
this.assertDisabled();
this.assertValue('Original value');
this.assertAttr('placeholder', 'Original placeholder');
this.assertAttr('name', 'original-name');
this.assertAttr('maxlength', '10');
this.assertAttr('minlength', '5'); // this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
};
_proto2['@test cursor selection range'] = function testCursorSelectionRange() {
var _this6 = 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)
(0, _internalTestHelpers.runTask)(function () {
return _this6.rerender();
}); // this.assertSelectionRange(8, 8); //NOTE: this is (0, 0) on Firefox (TEST_SUITE=sauce)
(0, _internalTestHelpers.runTask)(function () {
input.selectionStart = 2;
input.selectionEnd = 4;
});
this.assertSelectionRange(2, 4);
(0, _internalTestHelpers.runTask)(function () {
return _this6.rerender();
});
this.assertSelectionRange(2, 4); // runTask(() => set(this.context, 'value', 'updated'));
//
// this.assertSelectionRange(7, 7); //NOTE: this fails in IE, the range is 0 -> 0 (TEST_SUITE=sauce)
//
// runTask(() => set(this.context, 'value', 'original'));
//
// this.assertSelectionRange(8, 8); //NOTE: this fails in IE, the range is 0 -> 0 (TEST_SUITE=sauce)
};
_proto2['@test [DEPRECATED] sends an action with `{{input enter="foo"}}` when is pressed'] = function testDEPRECATEDSendsAnActionWithInputEnterFooWhenEnterIsPressed(assert) {
var _this7 = this;
assert.expect(4);
expectDeprecation(function () {
_this7.render("{{input enter='foo'}}", {
actions: {
foo: function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof _views.jQuery.Event, 'jQuery event was passed.');
}
}
});
}, 'Please refactor `{{input enter="foo"}}` to `{{input enter=(action "foo")}}. (\'-top-level\' @ L1:C0) ');
expectDeprecation(function () {
_this7.triggerEvent('keyup', {
keyCode: 13
});
}, 'Passing actions to components as strings (like {{input enter="foo"}}) is deprecated. Please use closure actions instead ({{input enter=(action "foo")}})');
};
_proto2['@test sends an action with `{{input enter=(action "foo")}}` when is pressed'] = function testSendsAnActionWithInputEnterActionFooWhenEnterIsPressed(assert) {
assert.expect(2);
this.render("{{input enter=(action 'foo')}}", {
actions: {
foo: function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof _views.jQuery.Event, 'jQuery event was passed');
}
}
});
this.triggerEvent('keyup', {
keyCode: 13
});
};
_proto2['@test [DEPRECATED] sends an action with `{{input key-press="foo"}}` is pressed'] = function testDEPRECATEDSendsAnActionWithInputKeyPressFooIsPressed(assert) {
var _this8 = this;
assert.expect(4);
expectDeprecation(function () {
_this8.render("{{input value=value key-press='foo'}}", {
value: 'initial',
actions: {
foo: function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof _views.jQuery.Event, 'jQuery event was passed');
}
}
});
}, 'Please refactor `{{input key-press="foo"}}` to `{{input key-press=(action "foo")}}. (\'-top-level\' @ L1:C0) ');
expectDeprecation(function () {
_this8.triggerEvent('keypress', {
keyCode: 65
});
}, 'Passing actions to components as strings (like {{input key-press="foo"}}) is deprecated. Please use closure actions instead ({{input key-press=(action "foo")}})');
};
_proto2['@test sends an action with `{{input key-press=(action "foo")}}` is pressed'] = function testSendsAnActionWithInputKeyPressActionFooIsPressed(assert) {
assert.expect(2);
this.render("{{input value=value key-press=(action 'foo')}}", {
value: 'initial',
actions: {
foo: function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof _views.jQuery.Event, 'jQuery event was passed');
}
}
});
this.triggerEvent('keypress', {
keyCode: 65
});
};
_proto2['@test sends an action to the parent level when `bubbles=true` is provided'] = function testSendsAnActionToTheParentLevelWhenBubblesTrueIsProvided(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');
};
_proto2['@test triggers `focus-in` when focused'] = function testTriggersFocusInWhenFocused(assert) {
var _this9 = this;
var wasFocused = false;
this.render("{{input focus-in=(action 'foo')}}", {
actions: {
foo: function () {
wasFocused = true;
}
}
});
(0, _internalTestHelpers.runTask)(function () {
_this9.$input().focus();
});
assert.ok(wasFocused, 'action was triggered');
};
_proto2['@test sends `insert-newline` when is pressed'] = function testSendsInsertNewlineWhenEnterIsPressed(assert) {
assert.expect(2);
this.render("{{input insert-newline=(action 'foo')}}", {
actions: {
foo: function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof _views.jQuery.Event, 'jQuery event was passed');
}
}
});
this.triggerEvent('keyup', {
keyCode: 13
});
};
_proto2['@test [DEPRECATED] sends an action with `{{input escape-press="foo"}}` when is pressed'] = function testDEPRECATEDSendsAnActionWithInputEscapePressFooWhenEscapeIsPressed(assert) {
var _this10 = this;
assert.expect(4);
expectDeprecation(function () {
_this10.render("{{input escape-press='foo'}}", {
actions: {
foo: function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof _views.jQuery.Event, 'jQuery event was passed');
}
}
});
}, 'Please refactor `{{input escape-press="foo"}}` to `{{input escape-press=(action "foo")}}. (\'-top-level\' @ L1:C0) ');
expectDeprecation(function () {
_this10.triggerEvent('keyup', {
keyCode: 27
});
}, 'Passing actions to components as strings (like {{input escape-press="foo"}}) is deprecated. Please use closure actions instead ({{input escape-press=(action "foo")}})');
};
_proto2['@test sends an action with `{{input escape-press=(action "foo")}}` when is pressed'] = function testSendsAnActionWithInputEscapePressActionFooWhenEscapeIsPressed(assert) {
assert.expect(2);
this.render("{{input escape-press=(action 'foo')}}", {
actions: {
foo: function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof _views.jQuery.Event, 'jQuery event was passed');
}
}
});
this.triggerEvent('keyup', {
keyCode: 27
});
};
_proto2['@test [DEPRECATED] sends an action with `{{input key-down="foo"}}` when a key is pressed'] = function testDEPRECATEDSendsAnActionWithInputKeyDownFooWhenAKeyIsPressed(assert) {
var _this11 = this;
assert.expect(4);
expectDeprecation(function () {
_this11.render("{{input key-down='foo'}}", {
actions: {
foo: function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof _views.jQuery.Event, 'jQuery event was passed');
}
}
});
}, 'Please refactor `{{input key-down="foo"}}` to `{{input key-down=(action "foo")}}. (\'-top-level\' @ L1:C0) ');
expectDeprecation(function () {
_this11.triggerEvent('keydown', {
keyCode: 65
});
}, 'Passing actions to components as strings (like {{input key-down="foo"}}) is deprecated. Please use closure actions instead ({{input key-down=(action "foo")}})');
};
_proto2['@test sends an action with `{{input key-down=(action "foo")}}` when a key is pressed'] = function testSendsAnActionWithInputKeyDownActionFooWhenAKeyIsPressed(assert) {
assert.expect(2);
this.render("{{input key-down=(action 'foo')}}", {
actions: {
foo: function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof _views.jQuery.Event, 'jQuery event was passed');
}
}
});
this.triggerEvent('keydown', {
keyCode: 65
});
};
_proto2['@test [DEPRECATED] sends an action with `{{input key-up="foo"}}` when a key is pressed'] = function testDEPRECATEDSendsAnActionWithInputKeyUpFooWhenAKeyIsPressed(assert) {
var _this12 = this;
assert.expect(4);
expectDeprecation(function () {
_this12.render("{{input key-up='foo'}}", {
actions: {
foo: function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof _views.jQuery.Event, 'jQuery event was passed');
}
}
});
}, 'Please refactor `{{input key-up="foo"}}` to `{{input key-up=(action "foo")}}. (\'-top-level\' @ L1:C0) ');
expectDeprecation(function () {
_this12.triggerEvent('keyup', {
keyCode: 65
});
}, 'Passing actions to components as strings (like {{input key-up="foo"}}) is deprecated. Please use closure actions instead ({{input key-up=(action "foo")}})');
};
_proto2['@test [DEPRECATED] sends an action with `{{input key-up=(action "foo")}}` when a key is pressed'] = function testDEPRECATEDSendsAnActionWithInputKeyUpActionFooWhenAKeyIsPressed(assert) {
assert.expect(2);
this.render("{{input key-up=(action 'foo')}}", {
actions: {
foo: function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof _views.jQuery.Event, 'jQuery event was passed');
}
}
});
this.triggerEvent('keyup', {
keyCode: 65
});
};
_proto2['@test GH#14727 can render a file input after having had render an input of other type'] = function testGH14727CanRenderAFileInputAfterHavingHadRenderAnInputOfOtherType() {
this.render("{{input type=\"text\"}}{{input type=\"file\"}}");
this.assert.equal(this.$input()[0].type, 'text');
this.assert.equal(this.$input()[1].type, 'file');
};
return _class;
}(InputRenderingTest));
(0, _internalTestHelpers.moduleFor)('Helpers test: {{input}} with dynamic type',
/*#__PURE__*/
function (_InputRenderingTest2) {
(0, _emberBabel.inheritsLoose)(_class2, _InputRenderingTest2);
function _class2() {
return _InputRenderingTest2.apply(this, arguments) || this;
}
var _proto3 = _class2.prototype;
_proto3['@test a bound property can be used to determine type'] = function testABoundPropertyCanBeUsedToDetermineType() {
var _this13 = this;
this.render("{{input type=type}}", {
type: 'password'
});
this.assertAttr('type', 'password');
(0, _internalTestHelpers.runTask)(function () {
return _this13.rerender();
});
this.assertAttr('type', 'password');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this13.context, 'type', 'text');
});
this.assertAttr('type', 'text');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this13.context, 'type', 'password');
});
this.assertAttr('type', 'password');
};
_proto3['@test a subexpression can be used to determine type'] = function testASubexpressionCanBeUsedToDetermineType() {
var _this14 = this;
this.render("{{input type=(if isTruthy trueType falseType)}}", {
isTruthy: true,
trueType: 'text',
falseType: 'password'
});
this.assertAttr('type', 'text');
(0, _internalTestHelpers.runTask)(function () {
return _this14.rerender();
});
this.assertAttr('type', 'text');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this14.context, 'isTruthy', false);
});
this.assertAttr('type', 'password');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this14.context, 'isTruthy', true);
});
this.assertAttr('type', 'text');
};
_proto3['@test GH16256 input macro does not modify params in place'] = function testGH16256InputMacroDoesNotModifyParamsInPlace() {
this.registerComponent('my-input', {
template: "{{input type=inputType}}"
});
this.render("{{my-input inputType=firstType}}{{my-input inputType=secondType}}", {
firstType: 'password',
secondType: 'email'
});
var inputs = this.element.querySelectorAll('input');
this.assert.equal(inputs.length, 2, 'there are two inputs');
this.assert.equal(inputs[0].getAttribute('type'), 'password');
this.assert.equal(inputs[1].getAttribute('type'), 'email');
};
return _class2;
}(InputRenderingTest));
(0, _internalTestHelpers.moduleFor)("Helpers test: {{input type='checkbox'}}",
/*#__PURE__*/
function (_InputRenderingTest3) {
(0, _emberBabel.inheritsLoose)(_class3, _InputRenderingTest3);
function _class3() {
return _InputRenderingTest3.apply(this, arguments) || this;
}
var _proto4 = _class3.prototype;
_proto4['@test dynamic attributes'] = function testDynamicAttributes() {
var _this15 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this15.rerender();
});
this.assertSingleCheckbox();
this.assertNotDisabled();
this.assertAttr('name', 'original-name');
this.assertAttr('tabindex', '10');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this15.context, 'disabled', true);
(0, _metal.set)(_this15.context, 'name', 'updated-name');
(0, _metal.set)(_this15.context, 'tabindex', 11);
});
this.assertSingleCheckbox();
this.assertDisabled();
this.assertAttr('name', 'updated-name');
this.assertAttr('tabindex', '11');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this15.context, 'disabled', false);
(0, _metal.set)(_this15.context, 'name', 'original-name');
(0, _metal.set)(_this15.context, 'tabindex', 10);
});
this.assertSingleCheckbox();
this.assertNotDisabled();
this.assertAttr('name', 'original-name');
this.assertAttr('tabindex', '10');
};
_proto4['@test `value` property assertion'] = function testValuePropertyAssertion() {
var _this16 = this;
expectAssertion(function () {
_this16.render("{{input type=\"checkbox\" value=value}}", {
value: 'value'
});
}, /you must use `checked=/);
};
_proto4['@test with a bound type'] = function testWithABoundType() {
var _this17 = this;
this.render("{{input type=inputType checked=isChecked}}", {
inputType: 'checkbox',
isChecked: true
});
this.assertSingleCheckbox();
this.assertCheckboxIsChecked();
(0, _internalTestHelpers.runTask)(function () {
return _this17.rerender();
});
this.assertCheckboxIsChecked();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this17.context, 'isChecked', false);
});
this.assertCheckboxIsNotChecked();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this17.context, 'isChecked', true);
});
this.assertCheckboxIsChecked();
};
_proto4['@test native click changes check property'] = function testNativeClickChangesCheckProperty() {
this.render("{{input type=\"checkbox\"}}");
this.assertSingleCheckbox();
this.assertCheckboxIsNotChecked();
this.$input()[0].click();
this.assertCheckboxIsChecked();
this.$input()[0].click();
this.assertCheckboxIsNotChecked();
};
_proto4['@test with static values'] = function testWithStaticValues() {
var _this18 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this18.rerender();
});
this.assertSingleCheckbox();
this.assertCheckboxIsNotChecked();
this.assertNotDisabled();
this.assertAttr('tabindex', '10');
this.assertAttr('name', 'original-name');
};
return _class3;
}(InputRenderingTest));
(0, _internalTestHelpers.moduleFor)("Helpers test: {{input type='text'}}",
/*#__PURE__*/
function (_InputRenderingTest4) {
(0, _emberBabel.inheritsLoose)(_class4, _InputRenderingTest4);
function _class4() {
return _InputRenderingTest4.apply(this, arguments) || this;
}
var _proto5 = _class4.prototype;
_proto5['@test null values'] = function testNullValues() {
var _this19 = 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);
(0, _internalTestHelpers.runTask)(function () {
return _this19.rerender();
});
this.assertValue('');
this.assertAllAttrs(attributes, undefined);
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this19.context, 'disabled', true);
(0, _metal.set)(_this19.context, 'value', 'Updated value');
(0, _metal.set)(_this19.context, 'placeholder', 'Updated placeholder');
(0, _metal.set)(_this19.context, 'name', 'updated-name');
(0, _metal.set)(_this19.context, 'maxlength', 11);
(0, _metal.set)(_this19.context, 'size', 21);
(0, _metal.set)(_this19.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');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this19.context, 'disabled', null);
(0, _metal.set)(_this19.context, 'value', null);
(0, _metal.set)(_this19.context, 'placeholder', null);
(0, _metal.set)(_this19.context, 'name', null);
(0, _metal.set)(_this19.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, _metal.set)(_this19.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)); // These are the permutations of the set:
// ['type="range"', 'min="-5" max="50"', 'value="%x"']
['type="range" min="-5" max="50" value="%x"', 'type="range" value="%x" min="-5" max="50"', 'min="-5" max="50" type="range" value="%x"', 'min="-5" max="50" value="%x" type="range"', 'value="%x" min="-5" max="50" type="range"', 'value="%x" type="range" min="-5" max="50"'].forEach(function (attrs) {
(0, _internalTestHelpers.moduleFor)("[GH#15675] Helpers test: {{input " + attrs + "}}",
/*#__PURE__*/
function (_InputRenderingTest5) {
(0, _emberBabel.inheritsLoose)(_class5, _InputRenderingTest5);
function _class5() {
return _InputRenderingTest5.apply(this, arguments) || this;
}
var _proto6 = _class5.prototype;
_proto6.renderInput = function renderInput() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 25;
this.render("{{input " + attrs.replace('%x', value) + "}}");
};
_proto6['@test value over default max but below set max is kept'] = function testValueOverDefaultMaxButBelowSetMaxIsKept() {
this.renderInput('25');
this.assertValue('25');
};
_proto6['@test value below default min but above set min is kept'] = function testValueBelowDefaultMinButAboveSetMinIsKept() {
this.renderInput('-2');
this.assertValue('-2');
};
_proto6['@test in the valid default range is kept'] = function testInTheValidDefaultRangeIsKept() {
this.renderInput('5');
this.assertValue('5');
};
_proto6['@test value above max is reset to max'] = function testValueAboveMaxIsResetToMax() {
this.renderInput('55');
this.assertValue('50');
};
_proto6['@test value below min is reset to min'] = function testValueBelowMinIsResetToMin() {
this.renderInput('-10');
this.assertValue('-5');
};
return _class5;
}(InputRenderingTest));
});
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/loc-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/string"], function (_emberBabel, _internalTestHelpers, _metal, _string) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Helpers test: {{loc}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
var _this;
_this = _RenderingTestCase.apply(this, arguments) || this;
(0, _string._setStrings)({
'Hello Friend': 'Hallo Freund',
Hello: 'Hallo, %@'
});
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_RenderingTestCase.prototype.teardown.call(this);
(0, _string._setStrings)({});
};
_proto['@test it lets the original value through by default'] = function testItLetsTheOriginalValueThroughByDefault() {
var _this2 = this;
this.render("{{loc \"Hiya buddy!\"}}");
this.assertText('Hiya buddy!', 'the unlocalized string is correct');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertText('Hiya buddy!', 'the unlocalized string is correct after rerender');
};
_proto['@test it localizes a simple string'] = function testItLocalizesASimpleString() {
var _this3 = this;
this.render("{{loc \"Hello Friend\"}}");
this.assertText('Hallo Freund', 'the localized string is correct');
(0, _internalTestHelpers.runTask)(function () {
return _this3.rerender();
});
this.assertText('Hallo Freund', 'the localized string is correct after rerender');
};
_proto['@test it takes passed formats into an account'] = function testItTakesPassedFormatsIntoAnAccount() {
var _this4 = this;
this.render("{{loc \"%@, %@\" \"Hello\" \"Mr. Pitkin\"}}");
this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct');
(0, _internalTestHelpers.runTask)(function () {
return _this4.rerender();
});
this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct after rerender');
};
_proto['@test it updates when bound params change'] = function testItUpdatesWhenBoundParamsChange() {
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');
(0, _internalTestHelpers.runTask)(function () {
return _this5.rerender();
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after rerender');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'simple', "G'day mate");
});
this.assertText("G'day mate - Hallo, Mr. Pitkin", 'the bound value is correct after update');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'simple', 'Hello Friend');
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after reset');
};
_proto['@test it updates when nested bound params change'] = function testItUpdatesWhenNestedBoundParamsChange() {
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');
(0, _internalTestHelpers.runTask)(function () {
return _this6.rerender();
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after rerender');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'greetings.simple', "G'day mate");
});
this.assertText("G'day mate - Hallo, Mr. Pitkin", 'the bound value is correct after interior mutation');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'greetings', {
simple: 'Hello Friend',
personal: 'Hello'
});
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after replacement');
};
_proto['@test it can be overriden'] = function testItCanBeOverriden() {
this.registerHelper('loc', function () {
return 'Yup';
});
this.render("{{loc greeting}}", {
greeting: 'Hello Friend'
});
this.assertText('Yup', 'the localized string is correct');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/log-test", ["ember-babel", "internal-test-helpers"], function (_emberBabel, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Helpers test: {{log}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
var _this;
_this = _RenderingTestCase.apply(this, arguments) || this;
/* eslint-disable no-console */
_this.originalLog = console.log;
_this.logCalls = [];
console.log = function () {
var _this$logCalls;
(_this$logCalls = _this.logCalls).push.apply(_this$logCalls, arguments);
/* eslint-enable no-console */
};
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_RenderingTestCase.prototype.teardown.call(this);
/* eslint-disable no-console */
console.log = this.originalLog;
/* eslint-enable no-console */
};
_proto.assertLog = function assertLog(values) {
this.assertText('');
this.assert.strictEqual(this.logCalls.length, values.length);
for (var i = 0, len = values.length; i < len; i++) {
this.assert.strictEqual(this.logCalls[i], values[i]);
}
};
_proto['@test correctly logs primitives'] = function testCorrectlyLogsPrimitives() {
this.render("{{log \"one\" 1 true}}");
this.assertLog(['one', 1, true]);
};
_proto['@test correctly logs a property'] = function testCorrectlyLogsAProperty() {
this.render("{{log value}}", {
value: 'one'
});
this.assertLog(['one']);
};
_proto['@test correctly logs multiple arguments'] = function testCorrectlyLogsMultipleArguments() {
this.render("{{log \"my variable:\" value}}", {
value: 'one'
});
this.assertLog(['my variable:', 'one']);
};
_proto['@test correctly logs `this`'] = function testCorrectlyLogsThis() {
this.render("{{log this}}");
this.assertLog([this.context]);
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/mut-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _metal, _helpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Helpers test: {{mut}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test a simple mutable binding using `mut` propagates properly'] = function testASimpleMutableBindingUsingMutPropagatesProperly() {
var _this = this;
var bottom;
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();
(0, _internalTestHelpers.runTask)(function () {
return bottom.attrs.setMe.update(13);
});
this.assertText('13', 'the set took effect');
this.assert.strictEqual((0, _metal.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, _metal.get)(this.context, 'val'), 13, 'the set propagated back up');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(bottom, 'setMe', 14);
});
this.assertText('14', 'the set took effect');
this.assert.strictEqual((0, _metal.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, _metal.get)(this.context, 'val'), 14, 'the set propagated back up');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'val', 12);
});
this.assertText('12');
};
_proto['@test a simple mutable binding using `mut` inserts into the DOM'] = function testASimpleMutableBindingUsingMutInsertsIntoTheDOM() {
var _this2 = this;
var bottom, middle;
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();
(0, _internalTestHelpers.runTask)(function () {
return bottom.attrs.setMe.update(13);
});
this.assertText('13', 'the set took effect');
this.assert.strictEqual((0, _metal.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, _metal.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, _metal.get)(this.context, 'val'), 13, 'the set propagated back up');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(bottom, 'setMe', 14);
});
this.assertText('14', 'the set took effect');
this.assert.strictEqual((0, _metal.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, _metal.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, _metal.get)(this.context, 'val'), 14, 'the set propagated back up');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'val', 12);
});
this.assertText('12');
};
_proto['@test passing a literal results in a assertion'] = function testPassingALiteralResultsInAAssertion() {
var _this3 = this;
this.registerComponent('bottom-mut', {
template: '{{setMe}}'
});
expectAssertion(function () {
_this3.render('{{bottom-mut setMe=(mut "foo bar")}}');
}, 'You can only pass a path to mut');
};
_proto['@test passing the result of a helper invocation results in an assertion'] = function testPassingTheResultOfAHelperInvocationResultsInAnAssertion() {
var _this4 = this;
this.registerComponent('bottom-mut', {
template: '{{setMe}}'
});
expectAssertion(function () {
_this4.render('{{bottom-mut setMe=(mut (concat "foo" " " "bar"))}}');
}, 'You can only pass a path to mut');
} // See https://github.com/emberjs/ember.js/commit/807a0cd for an explanation of this test
;
_proto['@test using a string value through middle tier does not trigger assertion (due to the auto-mut transform)'] = function testUsingAStringValueThroughMiddleTierDoesNotTriggerAssertionDueToTheAutoMutTransform() {
var bottom;
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, _metal.get)(bottom, 'stuff'), 'foo', 'the data propagated');
this.assertText('foo');
this.assertStableRerender(); // No U-R for this test
};
_proto['@test {{readonly}} of a {{mut}} is converted into an immutable binding'] = function testReadonlyOfAMutIsConvertedIntoAnImmutableBinding() {
var _this5 = this;
var middle, bottom;
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();
(0, _internalTestHelpers.runTask)(function () {
return middle.attrs.value.update(13);
});
this.assert.strictEqual((0, _metal.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");
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(middle, 'value', 14);
});
this.assert.strictEqual((0, _metal.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, _metal.get)(this.context, 'val'), 14, 'the set propagated back up');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'val', 12);
});
this.assertText('12');
};
_proto['@test mutable bindings work inside of yielded content'] = function testMutableBindingsWorkInsideOfYieldedContent() {
var _this6 = 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();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'model.name', 'Joel Kang');
});
this.assertText('Joel Kang');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'model', {
name: 'Matthew Beale'
});
});
this.assertText('Matthew Beale');
};
_proto['@test a simple mutable binding using {{mut}} is available in hooks'] = function testASimpleMutableBindingUsingMutIsAvailableInHooks() {
var _this7 = this;
var bottom;
var willRender = [];
var didInsert = [];
this.registerComponent('bottom-mut', {
ComponentClass: _helpers.Component.extend({
willRender: function () {
willRender.push((0, _metal.get)(this, 'setMe'));
},
didInsertElement: function () {
didInsert.push((0, _metal.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, _metal.get)(bottom, 'setMe'), 12, 'the data propagated');
(0, _internalTestHelpers.runTask)(function () {
return bottom.attrs.setMe.update(13);
});
this.assert.strictEqual((0, _metal.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, _metal.get)(this.context, 'val'), 13, 'the set propagated back up');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(bottom, 'setMe', 14);
});
this.assert.strictEqual((0, _metal.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, _metal.get)(this.context, 'val'), 14, 'the set propagated back up');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this7.context, 'val', 12);
});
this.assertText('12');
};
_proto['@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 testAMutableBindingWithABackingComputedPropertyAndAttributePresentInTheRootOfTheComponentIsUpdatedWhenTheUpstreamPropertyInvalidates11023() {
var bottom, middle;
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, _metal.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, _metal.get)(bottom, 'thingy'), 12, 'data propagated');
this.assertText('12');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(middle, 'baseValue', 13);
});
this.assert.strictEqual((0, _metal.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, _metal.get)(bottom, 'thingy'), 13, "the set propagated down to bottom's prop");
this.assertText('13');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(middle, 'baseValue', 12);
});
this.assertText('12');
};
_proto['@test automatic mutable bindings exposes a mut cell in attrs'] = function testAutomaticMutableBindingsExposesAMutCellInAttrs() {
var inner;
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();
(0, _internalTestHelpers.runTask)(function () {
return inner.attrs.foo.update('bar');
});
this.assert.equal(inner.attrs.foo.value, 'bar');
this.assert.equal((0, _metal.get)(inner, 'foo'), 'bar');
this.assertText('bar');
(0, _internalTestHelpers.runTask)(function () {
return inner.attrs.foo.update('foo');
});
this.assertText('foo');
};
_proto['@test automatic mutable bindings tolerate undefined non-stream inputs and attempts to set them'] = function testAutomaticMutableBindingsTolerateUndefinedNonStreamInputsAndAttemptsToSetThem() {
var inner;
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();
(0, _internalTestHelpers.runTask)(function () {
return inner.attrs.model.update(42);
});
this.assert.equal(inner.attrs.model.value, 42);
this.assert.equal((0, _metal.get)(inner, 'model'), 42);
this.assertText('42');
(0, _internalTestHelpers.runTask)(function () {
return inner.attrs.model.update(undefined);
});
this.assertText('');
};
_proto['@test automatic mutable bindings tolerate constant non-stream inputs and attempts to set them'] = function testAutomaticMutableBindingsTolerateConstantNonStreamInputsAndAttemptsToSetThem() {
var inner;
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();
(0, _internalTestHelpers.runTask)(function () {
return inner.attrs.model.update(42);
});
this.assert.equal(inner.attrs.model.value, 42);
this.assert.equal((0, _metal.get)(inner, 'model'), 42);
this.assertText('hello42');
(0, _internalTestHelpers.runTask)(function () {
return inner.attrs.model.update('foo');
});
this.assertText('hellofoo');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
(0, _internalTestHelpers.moduleFor)('Mutable Bindings used in Computed Properties that are bound as attributeBindings',
/*#__PURE__*/
function (_RenderingTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _RenderingTestCase2);
function _class2() {
return _RenderingTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test an attribute binding of a computed property of a 2-way bound attr recomputes when the attr changes'] = function testAnAttributeBindingOfAComputedPropertyOfA2WayBoundAttrRecomputesWhenTheAttrChanges() {
var _this8 = this;
var input, output;
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, _metal.computed)('height', function () {
var height = this.get('height');
return (0, _helpers.htmlSafe)("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, _internalTestHelpers.styles)('height: 60px;')
},
content: '60'
});
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return input.attrs.height.update(35);
});
this.assert.strictEqual((0, _metal.get)(output, 'height'), 35, 'the set took effect');
this.assert.strictEqual((0, _metal.get)(this.context, 'height'), 35, 'the set propagated back up');
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
style: (0, _internalTestHelpers.styles)('height: 35px;')
},
content: '35'
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(input, 'height', 36);
});
this.assert.strictEqual((0, _metal.get)(output, 'height'), 36, 'the set took effect');
this.assert.strictEqual((0, _metal.get)(this.context, 'height'), 36, 'the set propagated back up');
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
style: (0, _internalTestHelpers.styles)('height: 36px;')
},
content: '36'
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this8.context, 'height', 60);
});
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
style: (0, _internalTestHelpers.styles)('height: 60px;')
},
content: '60'
});
this.assert.strictEqual((0, _metal.get)(input, 'height'), 60);
};
_proto2['@test an attribute binding of a computed property with a setter of a 2-way bound attr recomputes when the attr changes'] = function testAnAttributeBindingOfAComputedPropertyWithASetterOfA2WayBoundAttrRecomputesWhenTheAttrChanges() {
var _this9 = this;
var input, output;
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, _metal.computed)('height', 'width', function () {
var height = this.get('height');
var width = this.get('width');
return (0, _helpers.htmlSafe)("height: " + height + "px; width: " + width + "px;");
}),
height: 20,
width: (0, _metal.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, _internalTestHelpers.styles)('height: 35px; width: 70px;')
},
content: '70x35'
});
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(input, 'width', 80);
});
this.assert.strictEqual((0, _metal.get)(output, 'width'), 80, 'the set took effect');
this.assert.strictEqual((0, _metal.get)(this.context, 'width'), 80, 'the set propagated back up');
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
style: (0, _internalTestHelpers.styles)('height: 40px; width: 80px;')
},
content: '80x40'
});
(0, _internalTestHelpers.runTask)(function () {
return input.attrs.width.update(90);
});
this.assert.strictEqual((0, _metal.get)(output, 'width'), 90, 'the set took effect');
this.assert.strictEqual((0, _metal.get)(this.context, 'width'), 90, 'the set propagated back up');
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
style: (0, _internalTestHelpers.styles)('height: 45px; width: 90px;')
},
content: '90x45'
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this9.context, 'width', 70);
});
this.assertComponentElement(this.firstChild, {
tagName: 'div',
attrs: {
style: (0, _internalTestHelpers.styles)('height: 35px; width: 70px;')
},
content: '70x35'
});
this.assert.strictEqual((0, _metal.get)(input, 'width'), 70);
};
return _class2;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/partial-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/runtime"], function (_emberBabel, _internalTestHelpers, _metal, _runtime) {
"use strict";
function _templateObject14() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#outer-component name=name as |outer|}}\n {{partial 'some-partial'}}\n {{/outer-component}}"]);
_templateObject14 = function () {
return data;
};
return data;
}
function _templateObject13() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#outer.inner as |inner|}}\n inner.name: {{inner.name}}\n {{/outer.inner}}\n "]);
_templateObject13 = function () {
return data;
};
return data;
}
function _templateObject12() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#with item.thing as |t|}}\n {{partial t}}\n {{else}}\n Nothing!\n {{/with}}"]);
_templateObject12 = function () {
return data;
};
return data;
}
function _templateObject11() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each model.items as |template i|}}\n {{model.type}}: {{partial template}}\n {{/each}}"]);
_templateObject11 = function () {
return data;
};
return data;
}
function _templateObject10() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#with 'Sophie' as |person1|}}\n Hi {{person1}} (aged {{age}}). {{partial 'person2-partial'}}\n {{/with}}"]);
_templateObject10 = function () {
return data;
};
return data;
}
function _templateObject9() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#with 'Sarah' as |person4|}}\n Hi {{person1}} (aged {{age}}), {{person2}}, {{person3}} and {{person4}}.\n {{/with}}\n "]);
_templateObject9 = function () {
return data;
};
return data;
}
function _templateObject8() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#with 'Alex' as |person3|}}\n Hi {{person1}} (aged {{age}}), {{person2}} and {{person3}}. {{partial 'person4-partial'}}\n {{/with}}\n "]);
_templateObject8 = function () {
return data;
};
return data;
}
function _templateObject7() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#with 'Ben' as |person2|}}\n Hi {{person1}} (aged {{age}}) and {{person2}}. {{partial 'person3-partial'}}\n {{/with}}\n "]);
_templateObject7 = function () {
return data;
};
return data;
}
function _templateObject6() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each names as |name i|}}\n {{i}}: {{partial 'outer-partial'}}\n {{/each}}"]);
_templateObject6 = function () {
return data;
};
return data;
}
function _templateObject5() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n [outer: {{name}}] {{partial 'inner-partial'}}\n "]);
_templateObject5 = function () {
return data;
};
return data;
}
function _templateObject4() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each items as |item|}}\n {{item}}: {{partial 'show-item'}} |\n {{/each}}"]);
_templateObject4 = function () {
return data;
};
return data;
}
function _templateObject3() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each items as |item|}}\n {{item.id}}: {{partial 'show-item'}} |\n {{/each}}"]);
_templateObject3 = function () {
return data;
};
return data;
}
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#with model as |item|}}\n {{item.name}}: {{partial 'show-id'}}\n {{/with}}"]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each model.items as |item|}}\n {{item}}: {{partial 'show-item'}} |\n {{/each}}"]);
_templateObject = function () {
return data;
};
return data;
}
(0, _internalTestHelpers.moduleFor)('Helpers test: {{partial}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should render other templates registered with the container'] = function testShouldRenderOtherTemplatesRegisteredWithTheContainer() {
this.registerPartial('_subTemplateFromContainer', 'sub-template');
this.render("This {{partial \"subTemplateFromContainer\"}} is pretty great.");
this.assertStableRerender();
this.assertText('This sub-template is pretty great.');
};
_proto['@test should render other slash-separated templates registered with the container'] = function testShouldRenderOtherSlashSeparatedTemplatesRegisteredWithTheContainer() {
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.');
};
_proto['@test should use the current context'] = function testShouldUseTheCurrentContext() {
var _this = 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?');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'model.firstName', 'Kelly');
});
this.assertText('Who is Kelly Selden?');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'model', {
firstName: 'Kris',
lastName: 'Selden'
});
});
this.assertText('Who is Kris Selden?');
};
_proto['@test Quoteless parameters passed to {{partial}} perform a bound property lookup of the partial name'] = function testQuotelessParametersPassedToPartialPerformABoundPropertyLookupOfThePartialName() {
var _this2 = 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.');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'templates.partialName', 'otherTemplate');
});
this.assertText('This other-template is pretty great.');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'templates.partialName', null);
});
this.assertText('This is pretty great.');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'templates', {
partialName: 'subTemplate'
});
});
this.assertText('This sub-template is pretty great.');
};
_proto['@test partial using data from {{#each}}'] = function testPartialUsingDataFromEach() {
var _this3 = this;
this.registerPartial('show-item', '{{item}}');
this.render((0, _internalTestHelpers.strip)(_templateObject()), {
model: {
items: (0, _runtime.A)(['apple', 'orange', 'banana'])
}
});
this.assertStableRerender();
this.assertText('apple: apple |orange: orange |banana: banana |');
(0, _internalTestHelpers.runTask)(function () {
return _this3.context.model.items.pushObject('strawberry');
});
this.assertText('apple: apple |orange: orange |banana: banana |strawberry: strawberry |');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'model', {
items: (0, _runtime.A)(['apple', 'orange', 'banana'])
});
});
this.assertText('apple: apple |orange: orange |banana: banana |');
};
_proto['@test partial using `{{get` on data from {{#with}}'] = function testPartialUsingGetOnDataFromWith() {
var _this4 = this;
this.registerPartial('show-id', '{{get item "id"}}');
this.render((0, _internalTestHelpers.strip)(_templateObject2()), {
model: {
id: 1,
name: 'foo'
}
});
this.assertStableRerender();
this.assertText('foo: 1');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'model.id', 2);
});
this.assertText('foo: 2');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'model.name', 'bar');
});
this.assertText('bar: 2');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'model', {
id: 1,
name: 'foo'
});
});
this.assertText('foo: 1');
};
_proto['@test partial using `{{get` on data from {{#each}}'] = function testPartialUsingGetOnDataFromEach() {
var _this5 = this;
this.registerPartial('show-item', '{{get item "id"}}');
this.render((0, _internalTestHelpers.strip)(_templateObject3()), {
items: (0, _runtime.A)([{
id: 1
}, {
id: 2
}, {
id: 3
}])
});
this.assertStableRerender();
this.assertText('1: 1 |2: 2 |3: 3 |');
(0, _internalTestHelpers.runTask)(function () {
return _this5.context.items.pushObject({
id: 4
});
});
this.assertText('1: 1 |2: 2 |3: 3 |4: 4 |');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'items', (0, _runtime.A)([{
id: 1
}, {
id: 2
}, {
id: 3
}]));
});
this.assertText('1: 1 |2: 2 |3: 3 |');
};
_proto['@test partial using conditional on data from {{#each}}'] = function testPartialUsingConditionalOnDataFromEach() {
var _this6 = this;
this.registerPartial('show-item', '{{#if item}}{{item}}{{/if}}');
this.render((0, _internalTestHelpers.strip)(_templateObject4()), {
items: (0, _runtime.A)(['apple', null, 'orange', 'banana'])
});
this.assertStableRerender();
this.assertText('apple: apple |: |orange: orange |banana: banana |');
(0, _internalTestHelpers.runTask)(function () {
return _this6.context.items.pushObject('strawberry');
});
this.assertText('apple: apple |: |orange: orange |banana: banana |strawberry: strawberry |');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'items', (0, _runtime.A)(['apple', null, 'orange', 'banana']));
});
this.assertText('apple: apple |: |orange: orange |banana: banana |');
};
_proto['@test nested partials using data from {{#each}}'] = function testNestedPartialsUsingDataFromEach() {
var _this7 = this;
this.registerPartial('_outer-partial', (0, _internalTestHelpers.strip)(_templateObject5()));
this.registerPartial('inner-partial', '[inner: {{name}}]');
this.render((0, _internalTestHelpers.strip)(_templateObject6()), {
names: (0, _runtime.A)(['Alex', 'Ben'])
});
this.assertStableRerender();
this.assertText('0: [outer: Alex] [inner: Alex]1: [outer: Ben] [inner: Ben]');
(0, _internalTestHelpers.runTask)(function () {
return _this7.context.names.pushObject('Sophie');
});
this.assertText('0: [outer: Alex] [inner: Alex]1: [outer: Ben] [inner: Ben]2: [outer: Sophie] [inner: Sophie]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this7.context, 'names', (0, _runtime.A)(['Alex', 'Ben']));
});
this.assertText('0: [outer: Alex] [inner: Alex]1: [outer: Ben] [inner: Ben]');
};
_proto['@test nested partials within nested `{{#with}}` blocks'] = function testNestedPartialsWithinNestedWithBlocks() {
var _this8 = this;
this.registerPartial('_person2-partial', (0, _internalTestHelpers.strip)(_templateObject7()));
this.registerPartial('_person3-partial', (0, _internalTestHelpers.strip)(_templateObject8()));
this.registerPartial('_person4-partial', (0, _internalTestHelpers.strip)(_templateObject9()));
this.render((0, _internalTestHelpers.strip)(_templateObject10()), {
age: 0
});
this.assertStableRerender();
this.assertText('Hi Sophie (aged 0). Hi Sophie (aged 0) and Ben. Hi Sophie (aged 0), Ben and Alex. Hi Sophie (aged 0), Ben, Alex and Sarah.');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this8.context, 'age', 1);
});
this.assertText('Hi Sophie (aged 1). Hi Sophie (aged 1) and Ben. Hi Sophie (aged 1), Ben and Alex. Hi Sophie (aged 1), Ben, Alex and Sarah.');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this8.context, 'age', 0);
});
this.assertText('Hi Sophie (aged 0). Hi Sophie (aged 0) and Ben. Hi Sophie (aged 0), Ben and Alex. Hi Sophie (aged 0), Ben, Alex and Sarah.');
};
_proto['@test dynamic partials in {{#each}}'] = function testDynamicPartialsInEach() {
var _this9 = this;
this.registerPartial('_odd', 'ODD{{i}}');
this.registerPartial('_even', 'EVEN{{i}}');
this.render((0, _internalTestHelpers.strip)(_templateObject11()), {
model: {
items: ['even', 'odd', 'even', 'odd'],
type: 'number'
}
});
this.assertStableRerender();
this.assertText('number: EVEN0number: ODD1number: EVEN2number: ODD3');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this9.context, 'model.type', 'integer');
});
this.assertText('integer: EVEN0integer: ODD1integer: EVEN2integer: ODD3');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this9.context, 'model', {
items: ['even', 'odd', 'even', 'odd'],
type: 'number'
});
});
this.assertText('number: EVEN0number: ODD1number: EVEN2number: ODD3');
};
_proto['@test dynamic partials in {{#with}}'] = function testDynamicPartialsInWith() {
var _this10 = this;
this.registerPartial('_thing', '{{t}}');
this.render((0, _internalTestHelpers.strip)(_templateObject12()), {
item: {
thing: false
}
});
this.assertStableRerender();
this.assertText('Nothing!');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this10.context, 'item.thing', 'thing');
});
this.assertText('thing');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this10.context, 'item', {
thing: false
});
});
this.assertText('Nothing!');
};
_proto['@test partials which contain contextual components'] = function testPartialsWhichContainContextualComponents() {
var _this11 = this;
this.registerComponent('outer-component', {
template: '{{yield (hash inner=(component "inner-component" name=name))}}'
});
this.registerComponent('inner-component', {
template: '{{yield (hash name=name)}}'
});
this.registerPartial('_some-partial', (0, _internalTestHelpers.strip)(_templateObject13()));
this.render((0, _internalTestHelpers.strip)(_templateObject14()), {
name: 'Sophie'
});
this.assertStableRerender();
this.assertText('inner.name: Sophie');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'name', 'Ben');
});
this.assertText('inner.name: Ben');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'name', 'Sophie');
});
this.assertText('inner.name: Sophie');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/readonly-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _metal, _helpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Helpers test: {{readonly}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test {{readonly}} of a path should work'] = function testReadonlyOfAPathShouldWork() {
var component;
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();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(component, 'value', 13);
});
this.assert.notOk(component.attrs.value.update);
this.assertText('13', 'local property is updated');
this.assert.equal((0, _metal.get)(this.context, 'val'), 12, 'upstream attribute is not updated'); // No U-R
};
_proto['@test passing an action to {{readonly}} avoids mutable cell wrapping'] = function testPassingAnActionToReadonlyAvoidsMutableCellWrapping(assert) {
assert.expect(4);
var outer, inner;
this.registerComponent('x-inner', {
ComponentClass: _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
inner = this;
}
})
});
this.registerComponent('x-outer', {
ComponentClass: _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
outer = this;
}
}),
template: '{{x-inner onClick=(readonly onClick)}}'
});
this.render('{{x-outer onClick=(action doIt)}}', {
doIt: function () {
assert.ok(true, 'action was called');
}
});
assert.equal(typeof outer.attrs.onClick, 'function', 'function itself is present in outer component attrs');
outer.attrs.onClick();
assert.equal(typeof inner.attrs.onClick, 'function', 'function itself is present in inner component attrs');
inner.attrs.onClick();
};
_proto['@test updating a {{readonly}} property from above works'] = function testUpdatingAReadonlyPropertyFromAboveWorks(assert) {
var _this = this;
var component;
this.registerComponent('foo-bar', {
ComponentClass: _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
}
}),
template: '{{value}}'
});
this.render('{{foo-bar value=(readonly thing)}}', {
thing: 'initial'
});
this.assertText('initial');
this.assertStableRerender();
assert.strictEqual(component.attrs.value, 'initial', 'no mutable cell');
assert.strictEqual((0, _metal.get)(component, 'value'), 'initial', 'no mutable cell');
assert.strictEqual(this.context.thing, 'initial');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'thing', 'updated!');
});
this.assertText('updated!');
assert.strictEqual(component.attrs.value, 'updated!', 'passed down value was set in attrs');
assert.strictEqual((0, _metal.get)(component, 'value'), 'updated!', 'passed down value was set');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'thing', 'initial');
});
this.assertText('initial');
};
_proto['@test updating a nested path of a {{readonly}}'] = function testUpdatingANestedPathOfAReadonly(assert) {
var component;
this.registerComponent('foo-bar', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
component = this;
}
}),
template: '{{value.prop}}'
});
this.render('{{foo-bar value=(readonly thing)}}', {
thing: {
prop: 'initial'
}
});
this.assertText('initial');
this.assertStableRerender();
assert.notOk(component.attrs.value.update, 'no update available');
assert.deepEqual((0, _metal.get)(component, 'value'), {
prop: 'initial'
});
assert.deepEqual(this.context.thing, {
prop: 'initial'
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(component, 'value.prop', 'updated!');
});
this.assertText('updated!', 'nested path is updated');
assert.deepEqual((0, _metal.get)(component, 'value'), {
prop: 'updated!'
});
assert.deepEqual(this.context.thing, {
prop: 'updated!'
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(component, 'value.prop', 'initial');
});
this.assertText('initial');
};
_proto['@test {{readonly}} of a string renders correctly'] = function testReadonlyOfAStringRendersCorrectly() {
var component;
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, _metal.get)(component, 'value'), '12');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(component, 'value', '13');
});
this.assertText('13', 'local property is updated');
this.assert.strictEqual((0, _metal.get)(component, 'value'), '13');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(component, 'value', '12');
});
this.assertText('12');
};
_proto['@test {{mut}} of a {{readonly}} mutates only the middle and bottom tiers'] = function testMutOfAReadonlyMutatesOnlyTheMiddleAndBottomTiers() {
var _this2 = this;
var middle, bottom;
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, _metal.get)(bottom, 'bar'), 12, "bottom's local bar received the value");
this.assert.equal((0, _metal.get)(middle, 'foo'), 12, "middle's local foo received the value"); // updating the mut-cell directly
(0, _internalTestHelpers.runTask)(function () {
return bottom.attrs.bar.update(13);
});
this.assert.equal((0, _metal.get)(bottom, 'bar'), 13, "bottom's local bar was updated after set of bottom's bar");
this.assert.equal((0, _metal.get)(middle, 'foo'), 13, "middle's local foo was updated after set of bottom's bar");
this.assertText('13 13');
this.assert.equal((0, _metal.get)(this.context, 'val'), 12, 'But context val is not updated');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(bottom, 'bar', 14);
});
this.assert.equal((0, _metal.get)(bottom, 'bar'), 14, "bottom's local bar was updated after set of bottom's bar");
this.assert.equal((0, _metal.get)(middle, 'foo'), 14, "middle's local foo was updated after set of bottom's bar");
this.assertText('14 14');
this.assert.equal((0, _metal.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");
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(middle, 'foo', 15);
});
this.assertText('15 15');
this.assert.equal((0, _metal.get)(middle, 'foo'), 15, "set of middle's foo took effect");
this.assert.equal((0, _metal.get)(bottom, 'bar'), 15, "bottom's local bar was updated after set of middle's foo");
this.assert.equal((0, _metal.get)(this.context, 'val'), 12, 'Context val remains unchanged');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'val', 10);
});
this.assertText('10 10');
this.assert.equal((0, _metal.get)(bottom, 'bar'), 10, "bottom's local bar was updated after set of context's val");
this.assert.equal((0, _metal.get)(middle, 'foo'), 10, "middle's local foo was updated after set of context's val"); // setting as a normal property
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(bottom, 'bar', undefined);
});
this.assertText(' ');
this.assert.equal((0, _metal.get)(bottom, 'bar'), undefined, "bottom's local bar was updated to a falsy value");
this.assert.equal((0, _metal.get)(middle, 'foo'), undefined, "middle's local foo was updated to a falsy value");
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'val', 12);
});
this.assertText('12 12', 'bottom and middle were both reset');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/text-area-test", ["ember-babel", "internal-test-helpers", "@ember/polyfills", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _polyfills, _metal) {
"use strict";
var TextAreaRenderingTest =
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(TextAreaRenderingTest, _RenderingTestCase);
function TextAreaRenderingTest() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = TextAreaRenderingTest.prototype;
_proto.assertTextArea = function assertTextArea() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
attrs = _ref.attrs,
value = _ref.value;
var mergedAttrs = (0, _polyfills.assign)({
class: (0, _internalTestHelpers.classes)('ember-view ember-text-area')
}, attrs);
this.assertComponentElement(this.firstChild, {
tagName: 'textarea',
attrs: mergedAttrs
});
if (value) {
this.assert.strictEqual(value, this.firstChild.value);
}
};
_proto.triggerEvent = function triggerEvent(type) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var event = document.createEvent('Events');
event.initEvent(type, true, true);
(0, _polyfills.assign)(event, options);
this.firstChild.dispatchEvent(event);
};
return TextAreaRenderingTest;
}(_internalTestHelpers.RenderingTestCase);
var BoundTextAreaAttributes =
/*#__PURE__*/
function () {
function BoundTextAreaAttributes(cases) {
this.cases = cases;
}
var _proto2 = BoundTextAreaAttributes.prototype;
_proto2.generate = function generate(_ref2) {
var _ref3;
var attribute = _ref2.attribute,
first = _ref2.first,
second = _ref2.second;
return _ref3 = {}, _ref3["@test " + attribute] = function () {
var _attrs,
_this = this,
_attrs2,
_attrs3;
this.render("{{textarea " + attribute + "=value}}", {
value: first
});
this.assertTextArea({
attrs: (_attrs = {}, _attrs[attribute] = first, _attrs)
});
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'value', second);
});
this.assertTextArea({
attrs: (_attrs2 = {}, _attrs2[attribute] = second, _attrs2)
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'value', first);
});
this.assertTextArea({
attrs: (_attrs3 = {}, _attrs3[attribute] = first, _attrs3)
});
}, _ref3;
};
return BoundTextAreaAttributes;
}();
(0, _internalTestHelpers.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, _internalTestHelpers.moduleFor)('Helpers test: {{textarea}}',
/*#__PURE__*/
function (_TextAreaRenderingTes) {
(0, _emberBabel.inheritsLoose)(_class, _TextAreaRenderingTes);
function _class() {
return _TextAreaRenderingTes.apply(this, arguments) || this;
}
var _proto3 = _class.prototype;
_proto3['@test Should insert a textarea'] = function testShouldInsertATextarea(assert) {
this.render('{{textarea}}');
assert.equal(this.$('textarea').length, 1);
this.assertStableRerender();
};
_proto3['@test Should respect disabled'] = function testShouldRespectDisabled(assert) {
this.render('{{textarea disabled=disabled}}', {
disabled: true
});
assert.ok(this.$('textarea').is(':disabled'));
};
_proto3['@test Should respect disabled when false'] = function testShouldRespectDisabledWhenFalse(assert) {
this.render('{{textarea disabled=disabled}}', {
disabled: false
});
assert.ok(this.$('textarea').is(':not(:disabled)'));
};
_proto3['@test Should become disabled when the context changes'] = function testShouldBecomeDisabledWhenTheContextChanges(assert) {
var _this2 = this;
this.render('{{textarea disabled=disabled}}');
assert.ok(this.$('textarea').is(':not(:disabled)'));
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'disabled', true);
});
assert.ok(this.$('textarea').is(':disabled'));
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'disabled', false);
});
assert.ok(this.$('textarea').is(':not(:disabled)'));
};
_proto3['@test Should bind its contents to the specified value'] = function testShouldBindItsContentsToTheSpecifiedValue() {
var _this3 = this;
this.render('{{textarea value=model.val}}', {
model: {
val: 'A beautiful day in Seattle'
}
});
this.assertTextArea({
value: 'A beautiful day in Seattle'
});
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'model.val', 'Auckland');
});
this.assertTextArea({
value: 'Auckland'
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'model', {
val: 'A beautiful day in Seattle'
});
});
this.assertTextArea({
value: 'A beautiful day in Seattle'
});
};
_proto3['@test GH#14001 Should correctly handle an empty string bound value'] = function testGH14001ShouldCorrectlyHandleAnEmptyStringBoundValue() {
var _this4 = this;
this.render('{{textarea value=message}}', {
message: ''
});
this.assert.strictEqual(this.firstChild.value, '');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'message', 'hello');
});
this.assert.strictEqual(this.firstChild.value, 'hello');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'message', '');
});
this.assert.strictEqual(this.firstChild.value, '');
};
_proto3['@test should update the value for `cut` / `input` / `change` events'] = function testShouldUpdateTheValueForCutInputChangeEvents() {
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();
(0, _internalTestHelpers.runTask)(function () {
_this5.firstChild.value = 'Auckland';
_this5.triggerEvent('cut');
});
this.assertTextArea({
value: 'Auckland'
});
(0, _internalTestHelpers.runTask)(function () {
_this5.firstChild.value = 'Hope';
_this5.triggerEvent('paste');
});
this.assertTextArea({
value: 'Hope'
});
(0, _internalTestHelpers.runTask)(function () {
_this5.firstChild.value = 'Boston';
_this5.triggerEvent('input');
});
this.assertTextArea({
value: 'Boston'
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'model', {
val: 'A beautiful day in Seattle'
});
});
this.assertTextArea({
value: 'A beautiful day in Seattle'
});
};
return _class;
}(TextAreaRenderingTest));
});
enifed("@ember/-internals/glimmer/tests/integration/helpers/unbound-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/runtime", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _metal, _runtime, _helpers) {
"use strict";
function _templateObject3() {
var data = (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}}"]);
_templateObject3 = function () {
return data;
};
return data;
}
function _templateObject2() {
var data = (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}}"]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n "]);
_templateObject = function () {
return data;
};
return data;
}
(0, _internalTestHelpers.moduleFor)('Helpers test: {{unbound}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should be able to output a property without binding'] = function testShouldBeAbleToOutputAPropertyWithoutBinding() {
var _this = this;
this.render("
{{/with}}'
});
this.render('{{#kiwi-comp}}{{item}}{{/kiwi-comp}}', {
item: 'Outer'
});
this.assertText('InnerOuter');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this10.context, 'item', 'Otherworld');
});
this.assertText('InnerOtherworld');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this10.context, 'item', 'Outer');
});
this.assertText('InnerOuter');
};
_proto['@test can bind a block param to a component and use it in yield'] = function testCanBindABlockParamToAComponentAndUseItInYield() {
var _this11 = 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();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'boundText', 'Update');
});
this.assertText('UpdateUpdate');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'boundText', 'Outer');
});
this.assertText('OuterOuter');
} // INUR not need with no data update
;
_proto['@test yield should not introduce a view'] = function testYieldShouldNotIntroduceAView(assert) {
var ParentCompComponent = _helpers.Component.extend({
isParentComponent: true
});
var ChildCompComponent = _helpers.Component.extend({
didReceiveAttrs: function () {
this._super();
var parentView = this.get('parentView');
assert.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}}');
};
_proto['@test yield with nested components (#3220)'] = function testYieldWithNestedComponents3220() {
var _this12 = 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();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'boundText', 'update');
});
this.assertText('Hello update');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'boundText', 'world');
});
this.assertText('Hello world');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/input-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _metal) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Input element tests',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.runAttributeTest = function runAttributeTest(attributeName, values) {
var _this = this;
var template = "";
this.render(template, {
value: values[0]
});
this.assertAttributeHasValue(attributeName, values[0], attributeName + " is set on initial render");
(0, _internalTestHelpers.runTask)(function () {
return _this.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");
};
_proto.runPropertyTest = function runPropertyTest(propertyName, values) {
var _this2 = this;
var attributeName = propertyName;
var template = "";
this.render(template, {
value: values[0]
});
this.assertPropertyHasValue(propertyName, values[0], propertyName + " is set on initial render");
(0, _internalTestHelpers.runTask)(function () {
return _this2.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");
};
_proto.runFalsyValueProperty = function runFalsyValueProperty(values) {
var _this3 = this;
var value = 'value';
var template = "";
this.render(template, {
value: values[0]
});
this.assertPropertyHasValue(value, '', value + " is set on initial render");
(0, _internalTestHelpers.runTask)(function () {
return _this3.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");
};
_proto['@test input disabled attribute'] = function testInputDisabledAttribute() {
var _this4 = this;
var model = {
model: {
value: false
}
};
this.render("", model);
this.assert.equal(this.$inputElement().prop('disabled'), false);
(0, _internalTestHelpers.runTask)(function () {
return _this4.rerender();
});
this.assert.equal(this.$inputElement().prop('disabled'), false);
(0, _internalTestHelpers.runTask)(function () {
return _this4.context.set('model.value', true);
});
this.assert.equal(this.$inputElement().prop('disabled'), true);
this.assertHTML(''); // Note the DOM output is
(0, _internalTestHelpers.runTask)(function () {
return _this4.context.set('model.value', 'wat');
});
this.assert.equal(this.$inputElement().prop('disabled'), true);
this.assertHTML(''); // Note the DOM output is
(0, _internalTestHelpers.runTask)(function () {
return _this4.context.set('model', {
value: false
});
});
this.assert.equal(this.$inputElement().prop('disabled'), false);
this.assertHTML('');
};
_proto['@test input value attribute'] = function testInputValueAttribute() {
this.runPropertyTest('value', ['foo', 'bar']);
};
_proto['@test input placeholder attribute'] = function testInputPlaceholderAttribute() {
this.runAttributeTest('placeholder', ['foo', 'bar']);
};
_proto['@test input name attribute'] = function testInputNameAttribute() {
this.runAttributeTest('name', ['nam', 'name']);
};
_proto['@test input maxlength attribute'] = function testInputMaxlengthAttribute() {
this.runAttributeTest('maxlength', [2, 3]);
};
_proto['@test input size attribute'] = function testInputSizeAttribute() {
this.runAttributeTest('size', [2, 3]);
};
_proto['@test input tabindex attribute'] = function testInputTabindexAttribute() {
this.runAttributeTest('tabindex', [2, 3]);
};
_proto['@test null input value'] = function testNullInputValue() {
this.runFalsyValueProperty([null, 'hello']);
};
_proto['@test undefined input value'] = function testUndefinedInputValue() {
this.runFalsyValueProperty([undefined, 'hello']);
};
_proto['@test undefined `toString` method as input value'] = function testUndefinedToStringMethodAsInputValue() {
this.runFalsyValueProperty([Object.create(null), 'hello']);
};
_proto['@test cursor position is not lost when updating content'] = function testCursorPositionIsNotLostWhenUpdatingContent() {
var template = "";
this.render(template, {
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.
};
_proto['@test input can be updated multiple times'] = function testInputCanBeUpdatedMultipleTimes() {
var template = "";
this.render(template, {
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');
};
_proto['@test DOM is SSOT if value is set'] = function testDOMIsSSOTIfValueIsSet() {
var template = "";
this.render(template, {
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');
} // private helpers and assertions
;
_proto.setDOMValue = function setDOMValue(value) {
this.inputElement().value = value;
};
_proto.setComponentValue = function setComponentValue(value) {
var _this5 = this;
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'value', value);
});
};
_proto.setSelectionRange = function setSelectionRange(start, end) {
this.inputElement().selectionStart = start;
this.inputElement().selectionEnd = end;
};
_proto.inputElement = function inputElement() {
return this.$inputElement()[0];
};
_proto.$inputElement = function $inputElement() {
return this.$('input');
};
_proto.assertValue = function assertValue(value, message) {
this.assertPropertyHasValue('value', value, message);
};
_proto.assertAttributeHasValue = function assertAttributeHasValue(attribute, value, message) {
this.assert.equal(this.$inputElement().attr(attribute), value, attribute + " " + message);
};
_proto.assertPropertyHasValue = function assertPropertyHasValue(property, value, message) {
this.assert.equal(this.$inputElement().prop(property), value, property + " " + message);
};
_proto.assertSelectionRange = function assertSelectionRange(start, end) {
this.assert.equal(this.inputElement().selectionStart, start);
this.assert.equal(this.inputElement().selectionEnd, end);
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/mount-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/owner", "@ember/-internals/glimmer/tests/utils/helpers", "@ember/controller", "@ember/-internals/metal", "@ember/engine"], function (_emberBabel, _internalTestHelpers, _owner, _helpers, _controller, _metal, _engine) {
"use strict";
if (true
/* EMBER_ENGINES_MOUNT_PARAMS */
) {
(0, _internalTestHelpers.moduleFor)('{{mount}} single param assertion',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test it asserts that only a single param is passed'] = function testItAssertsThatOnlyASingleParamIsPassed() {
var _this = this;
expectAssertion(function () {
_this.render('{{mount "chat" "foo"}}');
}, /You can only pass a single positional argument to the {{mount}} helper, e.g. {{mount "chat-engine"}}./i);
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
} else {
(0, _internalTestHelpers.moduleFor)('{{mount}} single param assertion',
/*#__PURE__*/
function (_RenderingTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _RenderingTestCase2);
function _class2() {
return _RenderingTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test it asserts that only a single param is passed'] = function testItAssertsThatOnlyASingleParamIsPassed() {
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);
};
return _class2;
}(_internalTestHelpers.RenderingTestCase));
}
(0, _internalTestHelpers.moduleFor)('{{mount}} assertions',
/*#__PURE__*/
function (_RenderingTestCase3) {
(0, _emberBabel.inheritsLoose)(_class3, _RenderingTestCase3);
function _class3() {
return _RenderingTestCase3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3['@test it asserts when an invalid engine name is provided'] = function testItAssertsWhenAnInvalidEngineNameIsProvided() {
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);
};
_proto3['@test it asserts that the specified engine is registered'] = function testItAssertsThatTheSpecifiedEngineIsRegistered() {
var _this4 = this;
expectAssertion(function () {
_this4.render('{{mount "chat"}}');
}, /You used `{{mount 'chat'}}`, but the engine 'chat' can not be found./i);
};
return _class3;
}(_internalTestHelpers.RenderingTestCase));
(0, _internalTestHelpers.moduleFor)('{{mount}} test',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class4, _ApplicationTestCase);
function _class4() {
var _this5;
_this5 = _ApplicationTestCase.apply(this, arguments) || this;
var engineRegistrations = _this5.engineRegistrations = {};
_this5.add('engine:chat', _engine.default.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;
}
var _proto4 = _class4.prototype;
_proto4['@test it boots an engine, instantiates its application controller, and renders its application template'] = function testItBootsAnEngineInstantiatesItsApplicationControllerAndRendersItsApplicationTemplate(assert) {
var _this7 = this;
this.engineRegistrations['template:application'] = (0, _helpers.compile)('
Chat here, {{username}}
', {
moduleName: 'my-app/templates/application.hbs'
});
var controller;
this.engineRegistrations['controller:application'] = _controller.default.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, _owner.getOwner)(controller);
assert.strictEqual((0, _engine.getEngineParent)(engineInstance), _this7.applicationInstance, 'engine instance has the application instance as its parent');
_this7.assertInnerHTML('
\n "]);
_templateObject14 = function () {
return data;
};
return data;
}
function _templateObject13() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n
one: foo
\n
two: bar
\n
\n "]);
_templateObject13 = function () {
return data;
};
return data;
}
function _templateObject12() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n {{#each-in map key=\"@identity\" as |key value|}}\n
{{key.name}}: {{value}}
\n {{/each-in}}\n
"]);
_templateObject12 = function () {
return data;
};
return data;
}
function _templateObject11() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n
Smartphones: 8203
\n
JavaScript Frameworks: Infinity
\n
\n "]);
_templateObject11 = function () {
return data;
};
return data;
}
function _templateObject10() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n
Smartphones: 100
\n
Tablets: 20
\n
\n "]);
_templateObject10 = function () {
return data;
};
return data;
}
function _templateObject9() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n
Smartphones: 100
\n
JavaScript Frameworks: Infinity
\n
Tweets: 443115
\n
\n "]);
_templateObject9 = function () {
return data;
};
return data;
}
function _templateObject8() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n
Smartphones: 8203
\n
JavaScript Frameworks: Infinity
\n
\n "]);
_templateObject8 = function () {
return data;
};
return data;
}
function _templateObject7() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n {{#each-in categories as |category count|}}\n
{{category}}: {{count}}
\n {{/each-in}}\n
\n "]);
_templateObject7 = function () {
return data;
};
return data;
}
function _templateObject6() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each-in arr as |key value|}}\n [{{key}}:{{value}}]\n {{/each-in}}"]);
_templateObject6 = function () {
return data;
};
return data;
}
function _templateObject5() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each-in arr as |key value|}}\n [{{key}}:{{value}}]\n {{/each-in}}"]);
_templateObject5 = function () {
return data;
};
return data;
}
function _templateObject4() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n
Smartphones: 8203
\n
JavaScript Frameworks: Infinity
\n
\n "]);
_templateObject4 = function () {
return data;
};
return data;
}
function _templateObject3() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n
Emberinios: 123456
\n
\n "]);
_templateObject3 = function () {
return data;
};
return data;
}
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n
Smartphones: 8203
\n
JavaScript Frameworks: Infinity
\n
\n "]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
\n {{#each-in categories as |category count|}}\n
{{category}}: {{count}}
\n {{/each-in}}\n
\n "]);
_templateObject = function () {
return data;
};
return data;
}
function EmptyFunction() {}
function NonEmptyFunction() {}
NonEmptyFunction.foo = 'bar';
var EmptyConstructor = function EmptyConstructor() {};
var NonEmptyConstructor = function NonEmptyConstructor() {};
NonEmptyConstructor.foo = 'bar';
var TogglingEachInTest =
/*#__PURE__*/
function (_TogglingSyntaxCondit) {
(0, _emberBabel.inheritsLoose)(TogglingEachInTest, _TogglingSyntaxCondit);
function TogglingEachInTest() {
return _TogglingSyntaxCondit.apply(this, arguments) || this;
}
var _proto = TogglingEachInTest.prototype;
_proto.templateFor = function templateFor(_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return "{{#each-in " + cond + " as |key|}}" + truthy + "{{else}}" + falsy + "{{/each-in}}";
};
return TogglingEachInTest;
}(_sharedConditionalTests.TogglingSyntaxConditionalsTest);
var BasicEachInTest =
/*#__PURE__*/
function (_TogglingEachInTest) {
(0, _emberBabel.inheritsLoose)(BasicEachInTest, _TogglingEachInTest);
function BasicEachInTest() {
return _TogglingEachInTest.apply(this, arguments) || this;
}
return BasicEachInTest;
}(TogglingEachInTest);
var BasicSyntaxTest =
/*#__PURE__*/
function (_BasicEachInTest) {
(0, _emberBabel.inheritsLoose)(BasicSyntaxTest, _BasicEachInTest);
function BasicSyntaxTest() {
return _BasicEachInTest.apply(this, arguments) || this;
}
(0, _emberBabel.createClass)(BasicSyntaxTest, [{
key: "truthyValue",
get: function () {
return {
'Not Empty': 1
};
}
}, {
key: "falsyValue",
get: function () {
return {};
}
}]);
return BasicSyntaxTest;
}(BasicEachInTest);
var EachInProxyTest =
/*#__PURE__*/
function (_TogglingEachInTest2) {
(0, _emberBabel.inheritsLoose)(EachInProxyTest, _TogglingEachInTest2);
function EachInProxyTest() {
return _TogglingEachInTest2.apply(this, arguments) || this;
}
return EachInProxyTest;
}(TogglingEachInTest);
(0, _internalTestHelpers.applyMixins)(BasicEachInTest, new _sharedConditionalTests.TruthyGenerator([{
foo: 1
}, _runtime.Object.create({
'Not Empty': 1
}), [1], NonEmptyFunction, NonEmptyConstructor]), new _sharedConditionalTests.FalsyGenerator([null, undefined, false, '', 0, [], EmptyFunction, EmptyConstructor, {}, Object.create(null), Object.create({}), Object.create({
'Not Empty': 1
}), _runtime.Object.create()]));
(0, _internalTestHelpers.applyMixins)(EachInProxyTest, new _sharedConditionalTests.TruthyGenerator([_runtime.ObjectProxy.create({
content: {
'Not empty': 1
}
})]), new _sharedConditionalTests.FalsyGenerator([_runtime.ObjectProxy.create(), _runtime.ObjectProxy.create({
content: null
}), _runtime.ObjectProxy.create({
content: {}
}), _runtime.ObjectProxy.create({
content: Object.create(null)
}), _runtime.ObjectProxy.create({
content: Object.create({})
}), _runtime.ObjectProxy.create({
content: Object.create({
'Not Empty': 1
})
}), _runtime.ObjectProxy.create({
content: _runtime.Object.create()
})])); // Truthy/Falsy tests
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each-in}} with `ObjectProxy`',
/*#__PURE__*/
function (_EachInProxyTest) {
(0, _emberBabel.inheritsLoose)(_class, _EachInProxyTest);
function _class() {
return _EachInProxyTest.apply(this, arguments) || this;
}
(0, _emberBabel.createClass)(_class, [{
key: "truthyValue",
get: function () {
return _runtime.ObjectProxy.create({
content: {
'Not Empty': 1
}
});
}
}, {
key: "falsyValue",
get: function () {
return _runtime.ObjectProxy.create({
content: null
});
}
}]);
return _class;
}(EachInProxyTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each-in}}', BasicSyntaxTest); // Rendering tests
var AbstractEachInTest =
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(AbstractEachInTest, _RenderingTestCase);
function AbstractEachInTest() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto2 = AbstractEachInTest.prototype;
_proto2.createHash = function createHash()
/* hash */
{
throw new Error('Not implemented: `createHash`');
};
_proto2.makeHash = function makeHash(obj) {
var _this$createHash = this.createHash(obj),
hash = _this$createHash.hash,
delegate = _this$createHash.delegate;
this.hash = hash;
this.delegate = delegate;
return hash;
};
_proto2.replaceHash = function replaceHash(hash) {
var _this = this;
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'hash', _this.createHash(hash).hash);
});
};
_proto2.clear = function clear() {
var _this2 = this;
return (0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'hash', _this2.createHash({}).hash);
});
};
_proto2.setProp = function setProp(key, value) {
var _this3 = this;
return (0, _internalTestHelpers.runTask)(function () {
return _this3.delegate.setProp(_this3.context, key, value);
});
};
_proto2.updateNestedValue = function updateNestedValue(key, innerKey, value) {
var _this4 = this;
return (0, _internalTestHelpers.runTask)(function () {
return _this4.delegate.updateNestedValue(_this4.context, key, innerKey, value);
});
};
_proto2.render = function render(template) {
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (this.hash !== undefined) {
context.hash = this.hash;
}
if (this.type !== undefined) {
context.type = this.type;
}
context.secretKey = 'asd';
return _RenderingTestCase.prototype.render.call(this, template, context);
};
return AbstractEachInTest;
}(_internalTestHelpers.RenderingTestCase);
var EachInTest =
/*#__PURE__*/
function (_AbstractEachInTest) {
(0, _emberBabel.inheritsLoose)(EachInTest, _AbstractEachInTest);
function EachInTest() {
return _AbstractEachInTest.apply(this, arguments) || this;
}
var _proto3 = EachInTest.prototype;
_proto3["@test it repeats the given block for each item in the hash"] = function () {
this.makeHash({
Smartphones: 8203,
'JavaScript Frameworks': Infinity
});
this.render("
{{#each-in hash as |category count|}}
{{category}}: {{count}}
{{else}}Empty!{{/each-in}}
");
this.assertText('Smartphones: 8203JavaScript Frameworks: Infinity');
this.assertStableRerender();
if (this.allowsSetProp) {
// Not al backing data structures allow kvo tracking. Maps and Iterables don't
this.setProp('Tweets', 100);
this.assertText('Smartphones: 8203JavaScript Frameworks: InfinityTweets: 100');
}
this.clear();
this.assertText('Empty!');
};
_proto3["@test it can render sub-paths of each item"] = function (assert) {
var _this5 = this;
this.makeHash({
Smartphones: {
reports: {
unitsSold: 8203
}
},
'JavaScript Frameworks': {
reports: {
unitsSold: Infinity
}
}
});
this.render("
{{#each-in hash key='@identity' as |category count|}}
{{category}}: {{count}}
{{/each-in}}
");
this.assertText('Smartphones: 8203Tablets: 8203JavaScript Frameworks: InfinityBugs: Infinity');
this.assertStableRerender();
if (this.allowsSetProp) {
this.setProp('Smartphones', 100);
this.setProp('Tweets', 443115);
this.assertText('Smartphones: 100Tablets: 8203JavaScript Frameworks: InfinityBugs: InfinityTweets: 443115');
}
this.clear();
this.assertText('');
};
_proto3["@test it repeats the given block when the hash is dynamic"] = function () {
var _this$createHash2 = this.createHash({
Smartphones: 8203,
'JavaScript Frameworks': Infinity
}),
categories = _this$createHash2.hash;
var _this$createHash3 = this.createHash({
Emberinios: 533462,
Tweets: 7323
}),
otherCategories = _this$createHash3.hash;
var context = {
hashes: {
categories: categories,
otherCategories: otherCategories,
type: 'categories'
}
};
this.render("
{{#each-in (get hashes hashes.type) as |category count|}}
{{category}}: {{count}}
{{else}}Empty!{{/each-in}}
", context);
this.assertText('Smartphones: 8203JavaScript Frameworks: Infinity');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(context, 'hashes.type', 'otherCategories');
});
this.assertText('Emberinios: 533462Tweets: 7323');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(context, 'hashes.type', 'categories');
});
this.assertText('Smartphones: 8203JavaScript Frameworks: Infinity');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(context, 'hashes.type', 'nonExistent');
});
this.clear();
this.assertText('Empty!');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(context, 'hashes.type', 'categories');
});
this.assertText('Smartphones: 8203JavaScript Frameworks: Infinity');
};
_proto3['@test keying off of `undefined` does not render'] = function testKeyingOffOfUndefinedDoesNotRender() {
this.makeHash({});
this.render("{{#each-in hash as |key value|}}{{key}}: {{value.baz}}{{else}}Empty!{{/each-in}}");
this.assertText('Empty!');
this.assertStableRerender();
this.replaceHash({
bar: {
baz: 'Here!'
}
});
this.assertText('bar: Here!');
this.clear();
this.assertText('Empty!');
};
_proto3["@test it can render items with a key of empty string"] = function () {
this.makeHash({
'': 'empty-string',
a: 'a'
});
this.render("
{{#each-in hash as |key value|}}
{{key}}: {{value}}
{{else}}Empty!{{/each-in}}
");
this.assertText(': empty-stringa: a');
this.assertStableRerender();
this.clear();
this.assertText('Empty!');
};
return EachInTest;
}(AbstractEachInTest);
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each-in}} with POJOs',
/*#__PURE__*/
function (_EachInTest) {
(0, _emberBabel.inheritsLoose)(_class2, _EachInTest);
function _class2() {
var _this6;
_this6 = _EachInTest.apply(this, arguments) || this;
_this6.allowsSetProp = true;
return _this6;
}
var _proto4 = _class2.prototype;
_proto4.createHash = function createHash(pojo) {
return {
hash: pojo,
delegate: {
setProp: function (context, key, value) {
(0, _metal.set)(context.hash, key, value);
},
updateNestedValue: function (context, key, innerKey, value) {
var target = context.hash[key];
(0, _metal.set)(target, innerKey, value);
}
}
};
};
_proto4["@test it only iterates over an object's own properties"] = function () {
var protoCategories = {
Smartphones: 8203,
'JavaScript Frameworks': Infinity
};
var categories = Object.create(protoCategories);
categories['Televisions'] = 183;
categories['Alarm Clocks'] = 999;
this.render("
{{#each-in categories as |category count|}}
{{category}}: {{count}}
{{else}}Empty!{{/each-in}}
", {
categories: categories
});
this.assertText('Televisions: 183Alarm Clocks: 999');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(protoCategories, 'Robots', 666);
(0, _metal.set)(categories, 'Tweets', 443115);
});
this.assertText('Televisions: 183Alarm Clocks: 999Tweets: 443115');
categories = Object.create(protoCategories);
categories['Televisions'] = 183;
categories['Alarm Clocks'] = 999;
};
_proto4["@test it does not observe direct property mutations (not going through set) on the object"] = function () {
var _this7 = this;
this.render((0, _internalTestHelpers.strip)(_templateObject()), {
categories: {
Smartphones: 8203,
'JavaScript Frameworks': Infinity
}
});
this.assertHTML((0, _internalTestHelpers.strip)(_templateObject2()));
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
var categories = (0, _metal.get)(_this7.context, 'categories');
delete categories.Smartphones;
});
this.assertInvariants();
(0, _internalTestHelpers.runTask)(function () {
var categories = (0, _metal.get)(_this7.context, 'categories');
categories['Emberinios'] = 123456;
});
this.assertInvariants();
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this7.context, 'categories', {
Emberinios: 123456
});
});
this.assertHTML((0, _internalTestHelpers.strip)(_templateObject3()));
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this7.context, 'categories', {
Smartphones: 8203,
'JavaScript Frameworks': Infinity
});
});
this.assertHTML((0, _internalTestHelpers.strip)(_templateObject4()));
};
_proto4['@test it skips holes in sparse arrays'] = function testItSkipsHolesInSparseArrays() {
var arr = [];
arr[5] = 'foo';
arr[6] = 'bar';
this.render((0, _internalTestHelpers.strip)(_templateObject5()), {
arr: arr
});
this.assertText('[5:foo][6:bar]');
this.assertStableRerender();
};
_proto4['@test it iterate over array with `in` instead of walking over elements'] = function testItIterateOverArrayWithInInsteadOfWalkingOverElements() {
var _this8 = this;
var arr = [1, 2, 3];
arr.foo = 'bar';
this.render((0, _internalTestHelpers.strip)(_templateObject6()), {
arr: arr
});
this.assertText('[0:1][1:2][2:3][foo:bar]');
(0, _internalTestHelpers.runTask)(function () {
return _this8.rerender();
});
this.assertText('[0:1][1:2][2:3][foo:bar]');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(arr, 'zomg', 'lol');
});
this.assertText('[0:1][1:2][2:3][foo:bar][zomg:lol]');
arr = [1, 2, 3];
arr.foo = 'bar';
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this8.context, 'arr', arr);
});
this.assertText('[0:1][1:2][2:3][foo:bar]');
};
return _class2;
}(EachInTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each-in}} with EmberObjects',
/*#__PURE__*/
function (_EachInTest2) {
(0, _emberBabel.inheritsLoose)(_class3, _EachInTest2);
function _class3() {
var _this9;
_this9 = _EachInTest2.apply(this, arguments) || this;
_this9.allowsSetProp = true;
return _this9;
}
var _proto5 = _class3.prototype;
_proto5.createHash = function createHash(pojo) {
var hash = _runtime.Object.create(pojo);
return {
hash: hash,
delegate: {
setProp: function (context, key, value) {
(0, _metal.set)(context, "hash." + key, value);
},
updateNestedValue: function (context, key, innerKey, value) {
var target = (0, _metal.get)(context.hash, key);
(0, _metal.set)(target, innerKey, value);
}
}
};
};
return _class3;
}(EachInTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each-in}} with object proxies',
/*#__PURE__*/
function (_EachInTest3) {
(0, _emberBabel.inheritsLoose)(_class4, _EachInTest3);
function _class4() {
var _this10;
_this10 = _EachInTest3.apply(this, arguments) || this;
_this10.allowsSetProp = true;
return _this10;
}
var _proto6 = _class4.prototype;
_proto6.createHash = function createHash(pojo) {
var hash = _runtime.ObjectProxy.create({
content: pojo
});
return {
hash: hash,
delegate: {
setProp: function (context, key, value) {
(0, _metal.set)(context, "hash." + key, value);
},
updateNestedValue: function (context, key, innerKey, value) {
var target = (0, _metal.get)(context.hash, key);
(0, _metal.set)(target, innerKey, value);
}
}
};
};
_proto6['@test it iterates over the content, not the proxy'] = function testItIteratesOverTheContentNotTheProxy() {
var _this11 = this;
var content = {
Smartphones: 8203,
'JavaScript Frameworks': Infinity
};
var proxy = _runtime.ObjectProxy.create({
content: content,
foo: 'bar'
});
this.render((0, _internalTestHelpers.strip)(_templateObject7()), {
categories: proxy
});
this.assertHTML((0, _internalTestHelpers.strip)(_templateObject8()));
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(proxy, 'content.Smartphones', 100);
(0, _metal.set)(proxy, 'content.Tweets', 443115);
});
this.assertHTML((0, _internalTestHelpers.strip)(_templateObject9()));
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(proxy, 'content', {
Smartphones: 100,
Tablets: 20
});
});
this.assertHTML((0, _internalTestHelpers.strip)(_templateObject10()));
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'categories', _runtime.ObjectProxy.create({
content: {
Smartphones: 8203,
'JavaScript Frameworks': Infinity
}
}));
});
this.assertHTML((0, _internalTestHelpers.strip)(_templateObject11()));
};
return _class4;
}(EachInTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each-in}} with ES6 Maps',
/*#__PURE__*/
function (_EachInTest4) {
(0, _emberBabel.inheritsLoose)(_class5, _EachInTest4);
function _class5() {
return _EachInTest4.apply(this, arguments) || this;
}
var _proto7 = _class5.prototype;
_proto7.createHash = function createHash(pojo) {
var map = new Map();
Object.keys(pojo).forEach(function (key) {
map.set(key, pojo[key]);
});
return {
hash: map,
delegate: {
updateNestedValue: function (context, key, innerKey, value) {
var target = context.hash.get(key);
(0, _metal.set)(target, innerKey, value);
}
}
};
};
_proto7["@test it supports having objects as keys on ES6 Maps"] = function () {
var _this12 = this;
var map = new Map();
map.set({
name: 'one'
}, 'foo');
map.set({
name: 'two'
}, 'bar');
this.render((0, _internalTestHelpers.strip)(_templateObject12()), {
map: map
});
this.assertHTML((0, _internalTestHelpers.strip)(_templateObject13()));
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
var map = new Map();
map.set({
name: 'three'
}, 'qux');
(0, _metal.set)(_this12.context, 'map', map);
});
this.assertHTML((0, _internalTestHelpers.strip)(_templateObject14()));
};
return _class5;
}(EachInTest));
if (_utils.HAS_NATIVE_SYMBOL) {
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each-in}} with custom iterables',
/*#__PURE__*/
function (_EachInTest5) {
(0, _emberBabel.inheritsLoose)(_class6, _EachInTest5);
function _class6() {
return _EachInTest5.apply(this, arguments) || this;
}
var _proto8 = _class6.prototype;
_proto8.createHash = function createHash(pojo) {
var _iterable;
var ary = Object.keys(pojo).reduce(function (accum, key) {
return accum.concat([[key, pojo[key]]]);
}, []);
var iterable = (_iterable = {}, _iterable[Symbol.iterator] = function () {
return makeIterator(ary);
}, _iterable);
return {
hash: iterable,
delegate: {
updateNestedValue: function (context, key, innerKey, value) {
var ary = Array.from(context.hash);
var target = ary.find(function (_ref2) {
var k = _ref2[0];
return k === key;
})[1];
(0, _metal.set)(target, innerKey, value);
}
}
};
};
return _class6;
}(EachInTest));
} // Utils
function makeIterator(ary) {
var index = 0;
return {
next: function () {
return index < ary.length ? {
value: ary[index++],
done: false
} : {
done: true
};
}
};
}
});
enifed("@ember/-internals/glimmer/tests/integration/syntax/each-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/runtime", "@ember/-internals/utils", "@ember/-internals/glimmer/tests/utils/helpers", "@ember/-internals/glimmer/tests/utils/shared-conditional-tests"], function (_emberBabel, _internalTestHelpers, _metal, _runtime, _utils, _helpers, _sharedConditionalTests) {
"use strict";
function _templateObject8() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
Think Pieces\u2122
\n\n
\n
Rails is omakase
\n
Ember is omakase
\n
\n "]);
_templateObject8 = function () {
return data;
};
return data;
}
function _templateObject7() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
Essays
\n\n
\n
Rails is omakase
\n
Ember is omakase
\n
\n "]);
_templateObject7 = function () {
return data;
};
return data;
}
function _templateObject6() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
Blog Posts
\n\n
\n
Rails is omakase
\n
Ember is omakase
\n
\n "]);
_templateObject6 = function () {
return data;
};
return data;
}
function _templateObject5() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n
{{page.title}}
\n\n
\n {{#each model as |post|}}\n
{{post.title}}
\n {{/each}}\n
\n "]);
_templateObject5 = function () {
return data;
};
return data;
}
function _templateObject4() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each list as |value key|}}\n [{{key}}:{{value}}]\n {{/each}}"]);
_templateObject4 = function () {
return data;
};
return data;
}
function _templateObject3() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each foo.bar.baz as |thing|}}\n {{thing}}\n {{/each}}"]);
_templateObject3 = function () {
return data;
};
return data;
}
function _templateObject2() {
var data = (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 "]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#each list as |item|}}\n
Prev
\n {{foo-bar item=item}}\n
Next
\n {{/each}}\n "]);
_templateObject = function () {
return data;
};
return data;
}
var ArrayDelegate =
/*#__PURE__*/
function () {
function ArrayDelegate(content, target) {
this._array = content;
this._target = target || this;
} // The following methods are APIs used by the tests
var _proto = ArrayDelegate.prototype;
_proto.toArray = function toArray() {
return this._array.slice();
};
_proto.objectAt = function objectAt(idx) {
return this._array[idx];
};
_proto.clear = function clear() {
this._array.length = 0;
this.arrayContentDidChange();
};
_proto.replace = function replace(idx, del, ins) {
var _this$_array;
(_this$_array = this._array).splice.apply(_this$_array, [idx, del].concat(ins));
this.arrayContentDidChange();
};
_proto.unshiftObject = function unshiftObject(obj) {
this._array.unshift(obj);
this.arrayContentDidChange();
};
_proto.unshiftObjects = function unshiftObjects(arr) {
var _this$_array2;
(_this$_array2 = this._array).unshift.apply(_this$_array2, arr);
this.arrayContentDidChange();
};
_proto.pushObject = function pushObject(obj) {
this._array.push(obj);
this.arrayContentDidChange();
};
_proto.pushObjects = function pushObjects(arr) {
var _this$_array3;
(_this$_array3 = this._array).push.apply(_this$_array3, arr);
this.arrayContentDidChange();
};
_proto.shiftObject = function shiftObject() {
var obj = this._array.shift();
this.arrayContentDidChange();
return obj;
};
_proto.popObject = function popObject() {
var obj = this._array.pop();
this.arrayContentDidChange();
return obj;
};
_proto.insertAt = function insertAt(idx, obj) {
this._array.splice(idx, 0, obj);
this.arrayContentDidChange();
};
_proto.removeAt = function removeAt(idx) {
var len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
this._array.splice(idx, len);
this.arrayContentDidChange();
};
_proto.arrayContentDidChange = function arrayContentDidChange() {
(0, _metal.notifyPropertyChange)(this._target, '[]');
(0, _metal.notifyPropertyChange)(this._target, 'length');
};
_proto.toString = function toString() {
return "#<" + (this.constructor.name || 'UnknownArrayDelegate') + ">";
};
_proto.toJSON = function toJSON() {
return this.toString();
};
return ArrayDelegate;
}();
var makeSet = function () {
// IE11 does not support `new Set(items);`
var set = new Set([1, 2, 3]);
if (set.size === 3) {
return function (items) {
return new Set(items);
};
} else {
return function (items) {
var s = new Set();
items.forEach(function (value) {
return s.add(value);
});
return s;
};
}
}();
var SetDelegate =
/*#__PURE__*/
function (_ArrayDelegate) {
(0, _emberBabel.inheritsLoose)(SetDelegate, _ArrayDelegate);
function SetDelegate(set) {
var _this;
var array = [];
set.forEach(function (value) {
return array.push(value);
});
_this = _ArrayDelegate.call(this, array, set) || this;
_this._set = set;
return _this;
}
var _proto2 = SetDelegate.prototype;
_proto2.arrayContentDidChange = function arrayContentDidChange() {
var _this2 = this;
this._set.clear();
this._array.forEach(function (value) {
return _this2._set.add(value);
});
_ArrayDelegate.prototype.arrayContentDidChange.call(this);
};
return SetDelegate;
}(ArrayDelegate);
var ForEachable =
/*#__PURE__*/
function (_ArrayDelegate2) {
(0, _emberBabel.inheritsLoose)(ForEachable, _ArrayDelegate2);
function ForEachable() {
return _ArrayDelegate2.apply(this, arguments) || this;
}
var _proto3 = ForEachable.prototype;
_proto3.forEach = function forEach(callback) {
this._array.forEach(callback);
};
(0, _emberBabel.createClass)(ForEachable, [{
key: "length",
get: function () {
return this._array.length;
}
}]);
return ForEachable;
}(ArrayDelegate);
var ArrayIterable;
if (_utils.HAS_NATIVE_SYMBOL) {
ArrayIterable =
/*#__PURE__*/
function (_ArrayDelegate3) {
(0, _emberBabel.inheritsLoose)(ArrayIterable, _ArrayDelegate3);
function ArrayIterable() {
return _ArrayDelegate3.apply(this, arguments) || this;
}
var _proto4 = ArrayIterable.prototype;
_proto4[Symbol.iterator] = function () {
return this._array[Symbol.iterator]();
};
return ArrayIterable;
}(ArrayDelegate);
}
var TogglingEachTest =
/*#__PURE__*/
function (_TogglingSyntaxCondit) {
(0, _emberBabel.inheritsLoose)(TogglingEachTest, _TogglingSyntaxCondit);
function TogglingEachTest() {
return _TogglingSyntaxCondit.apply(this, arguments) || this;
}
(0, _emberBabel.createClass)(TogglingEachTest, [{
key: "truthyValue",
get: function () {
return ['non-empty'];
}
}, {
key: "falsyValue",
get: function () {
return [];
}
}]);
return TogglingEachTest;
}(_sharedConditionalTests.TogglingSyntaxConditionalsTest);
var BasicEachTest =
/*#__PURE__*/
function (_TogglingEachTest) {
(0, _emberBabel.inheritsLoose)(BasicEachTest, _TogglingEachTest);
function BasicEachTest() {
return _TogglingEachTest.apply(this, arguments) || this;
}
return BasicEachTest;
}(TogglingEachTest);
var TRUTHY_CASES = [['hello'], (0, _runtime.A)(['hello']), makeSet(['hello']), new ForEachable(['hello']), _runtime.ArrayProxy.create({
content: ['hello']
}), _runtime.ArrayProxy.create({
content: (0, _runtime.A)(['hello'])
})];
var FALSY_CASES = [null, undefined, false, '', 0, [], (0, _runtime.A)([]), makeSet([]), new ForEachable([]), _runtime.ArrayProxy.create({
content: []
}), _runtime.ArrayProxy.create({
content: (0, _runtime.A)([])
})];
if (_utils.HAS_NATIVE_SYMBOL) {
TRUTHY_CASES.push(new ArrayIterable(['hello']));
FALSY_CASES.push(new ArrayIterable([]));
}
(0, _internalTestHelpers.applyMixins)(BasicEachTest, new _sharedConditionalTests.TruthyGenerator(TRUTHY_CASES), new _sharedConditionalTests.FalsyGenerator(FALSY_CASES), _sharedConditionalTests.ArrayTestCases);
(0, _internalTestHelpers.moduleFor)('Syntax test: toggling {{#each}}',
/*#__PURE__*/
function (_BasicEachTest) {
(0, _emberBabel.inheritsLoose)(_class, _BasicEachTest);
function _class() {
return _BasicEachTest.apply(this, arguments) || this;
}
var _proto5 = _class.prototype;
_proto5.templateFor = function templateFor(_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return "{{#each " + cond + "}}" + truthy + "{{else}}" + falsy + "{{/each}}";
};
return _class;
}(BasicEachTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: toggling {{#each as}}',
/*#__PURE__*/
function (_BasicEachTest2) {
(0, _emberBabel.inheritsLoose)(_class2, _BasicEachTest2);
function _class2() {
return _BasicEachTest2.apply(this, arguments) || this;
}
var _proto6 = _class2.prototype;
_proto6.templateFor = function templateFor(_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 =
/*#__PURE__*/
function (_TogglingEachTest2) {
(0, _emberBabel.inheritsLoose)(EachEdgeCasesTest, _TogglingEachTest2);
function EachEdgeCasesTest() {
return _TogglingEachTest2.apply(this, arguments) || this;
}
return EachEdgeCasesTest;
}(TogglingEachTest);
(0, _internalTestHelpers.applyMixins)(EachEdgeCasesTest, new _sharedConditionalTests.FalsyGenerator([true, 'hello', 1, Object, function () {}, {}, {
foo: 'bar'
}, Object.create(null), Object.create({}), Object.create({
foo: 'bar'
})]));
(0, _internalTestHelpers.moduleFor)('Syntax test: toggling {{#each}}',
/*#__PURE__*/
function (_EachEdgeCasesTest) {
(0, _emberBabel.inheritsLoose)(_class3, _EachEdgeCasesTest);
function _class3() {
return _EachEdgeCasesTest.apply(this, arguments) || this;
}
var _proto7 = _class3.prototype;
_proto7.templateFor = function templateFor(_ref3) {
var cond = _ref3.cond,
truthy = _ref3.truthy,
falsy = _ref3.falsy;
return "{{#each " + cond + "}}" + truthy + "{{else}}" + falsy + "{{/each}}";
};
return _class3;
}(EachEdgeCasesTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: toggling {{#each as}}',
/*#__PURE__*/
function (_EachEdgeCasesTest2) {
(0, _emberBabel.inheritsLoose)(_class4, _EachEdgeCasesTest2);
function _class4() {
return _EachEdgeCasesTest2.apply(this, arguments) || this;
}
var _proto8 = _class4.prototype;
_proto8.templateFor = function templateFor(_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 =
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(AbstractEachTest, _RenderingTestCase);
function AbstractEachTest() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto9 = AbstractEachTest.prototype;
/* abstract */
_proto9.createList = function createList()
/* items */
{
throw new Error('Not implemented: `createList`');
};
_proto9.makeList = function makeList(items) {
var _this$createList = this.createList(items),
list = _this$createList.list,
delegate = _this$createList.delegate;
this.list = list;
this.delegate = delegate;
};
_proto9.replaceList = function replaceList(list) {
var _this3 = this;
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'list', _this3.createList(list).list);
});
};
_proto9.forEach = function forEach(callback) {
return this.delegate.toArray().forEach(callback);
};
_proto9.objectAt = function objectAt(idx) {
return this.delegate.objectAt(idx);
};
_proto9.clear = function clear() {
return this.delegate.clear();
};
_proto9.replace = function replace(idx, del, ins) {
return this.delegate.replace(idx, del, ins);
};
_proto9.unshiftObject = function unshiftObject(obj) {
return this.delegate.unshiftObject(obj);
};
_proto9.unshiftObjects = function unshiftObjects(arr) {
return this.delegate.unshiftObjects(arr);
};
_proto9.pushObject = function pushObject(obj) {
return this.delegate.pushObject(obj);
};
_proto9.pushObjects = function pushObjects(arr) {
return this.delegate.pushObjects(arr);
};
_proto9.shiftObject = function shiftObject() {
return this.delegate.shiftObject();
};
_proto9.popObject = function popObject() {
return this.delegate.popObject();
};
_proto9.insertAt = function insertAt(idx, obj) {
return this.delegate.insertAt(idx, obj);
};
_proto9.removeAt = function removeAt(idx, len) {
return this.delegate.removeAt(idx, len);
};
_proto9.render = function render(template) {
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (this.list !== undefined) {
context.list = this.list;
}
return _RenderingTestCase.prototype.render.call(this, template, context);
};
return AbstractEachTest;
}(_internalTestHelpers.RenderingTestCase);
var EachTest =
/*#__PURE__*/
function (_AbstractEachTest) {
(0, _emberBabel.inheritsLoose)(EachTest, _AbstractEachTest);
function EachTest() {
return _AbstractEachTest.apply(this, arguments) || this;
}
var _proto10 = EachTest.prototype;
/* single each */
_proto10['@test it repeats the given block for each item in the array'] = function testItRepeatsTheGivenBlockForEachItemInTheArray() {
var _this4 = this;
this.makeList([{
text: 'hello'
}]);
this.render("{{#each list as |item|}}{{item.text}}{{else}}Empty{{/each}}");
this.assertText('hello');
(0, _internalTestHelpers.runTask)(function () {
return _this4.rerender();
});
this.assertText('hello');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.objectAt(0), 'text', 'Hello');
});
this.assertText('Hello');
(0, _internalTestHelpers.runTask)(function () {
_this4.pushObject({
text: ' '
});
_this4.pushObject({
text: 'World'
});
});
this.assertText('Hello World');
(0, _internalTestHelpers.runTask)(function () {
_this4.pushObject({
text: 'Earth'
});
_this4.removeAt(1);
_this4.insertAt(1, {
text: 'Globe'
});
});
this.assertText('HelloGlobeWorldEarth');
(0, _internalTestHelpers.runTask)(function () {
_this4.pushObject({
text: 'Planet'
});
_this4.removeAt(1);
_this4.insertAt(1, {
text: ' '
});
_this4.pushObject({
text: ' '
});
_this4.pushObject({
text: 'Earth'
});
_this4.removeAt(3);
});
this.assertText('Hello WorldPlanet Earth');
(0, _internalTestHelpers.runTask)(function () {
_this4.pushObject({
text: 'Globe'
});
_this4.removeAt(1);
_this4.insertAt(1, {
text: ' '
});
_this4.pushObject({
text: ' '
});
_this4.pushObject({
text: 'World'
});
_this4.removeAt(2);
});
this.assertText('Hello Planet EarthGlobe World');
(0, _internalTestHelpers.runTask)(function () {
return _this4.replace(2, 4, [{
text: 'my'
}]);
});
this.assertText('Hello my World');
(0, _internalTestHelpers.runTask)(function () {
return _this4.clear();
});
this.assertText('Empty');
this.replaceList([{
text: 'hello'
}]);
this.assertText('hello');
};
_proto10['@test it receives the index as the second parameter'] = function testItReceivesTheIndexAsTheSecondParameter() {
var _this5 = 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();
(0, _internalTestHelpers.runTask)(function () {
return _this5.insertAt(1, {
text: 'my'
});
});
this.assertText('[0. hello][1. my][2. world]');
this.replaceList([{
text: 'hello'
}, {
text: 'world'
}]);
this.assertText('[0. hello][1. world]');
};
_proto10['@test it accepts a string key'] = function testItAcceptsAStringKey() {
var _this6 = this;
this.makeList([{
text: 'hello'
}, {
text: 'world'
}]);
this.render("{{#each list key='text' as |item|}}{{item.text}}{{/each}}");
this.assertText('helloworld');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this6.pushObject({
text: 'again'
});
});
this.assertText('helloworldagain');
this.replaceList([{
text: 'hello'
}, {
text: 'world'
}]);
this.assertText('helloworld');
};
_proto10['@test it accepts a numeric key'] = function testItAcceptsANumericKey() {
var _this7 = this;
this.makeList([{
id: 1
}, {
id: 2
}]);
this.render("{{#each list key='id' as |item|}}{{item.id}}{{/each}}");
this.assertText('12');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this7.pushObject({
id: 3
});
});
this.assertText('123');
this.replaceList([{
id: 1
}, {
id: 2
}]);
this.assertText('12');
};
_proto10['@test it can specify @index as the key'] = function testItCanSpecifyIndexAsTheKey() {
var _this8 = this;
this.makeList([{
id: 1
}, {
id: 2
}]);
this.render("{{#each list key='@index' as |item|}}{{item.id}}{{/each}}");
this.assertText('12');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this8.pushObject({
id: 3
});
});
this.assertText('123');
this.replaceList([{
id: 1
}, {
id: 2
}]);
this.assertText('12');
};
_proto10['@test it can specify @identity as the key for arrays of primitives'] = function testItCanSpecifyIdentityAsTheKeyForArraysOfPrimitives() {
var _this9 = this;
this.makeList([1, 2]);
this.render("{{#each list key='@identity' as |item|}}{{item}}{{/each}}");
this.assertText('12');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this9.pushObject(3);
});
this.assertText('123');
this.replaceList([1, 2]);
this.assertText('12');
};
_proto10['@test it can specify @identity as the key for mixed arrays of objects and primitives'] = function testItCanSpecifyIdentityAsTheKeyForMixedArraysOfObjectsAndPrimitives() {
var _this10 = 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();
(0, _internalTestHelpers.runTask)(function () {
return _this10.insertAt(2, {
id: 4
});
});
this.assertText('1243');
this.replaceList([1, {
id: 2
}, 3]);
this.assertText('123');
};
_proto10['@test it can render duplicate primitive items'] = function testItCanRenderDuplicatePrimitiveItems() {
var _this11 = this;
this.makeList(['a', 'a', 'a']);
this.render("{{#each list as |item|}}{{item}}{{/each}}");
this.assertText('aaa');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this11.pushObject('a');
});
this.assertText('aaaa');
(0, _internalTestHelpers.runTask)(function () {
return _this11.pushObject('a');
});
this.assertText('aaaaa');
this.replaceList(['a', 'a', 'a']);
this.assertText('aaa');
};
_proto10["@test updating and setting within #each"] = function () {
var _this12 = 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, _internalTestHelpers.strip)(_templateObject()));
this.assertText('Prev1NextPrev2NextPrev3Next');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.objectAt(0), 'value', 3);
});
this.assertText('PrevNextPrev2NextPrev3Next');
this.replaceList([{
value: 1
}, {
value: 2
}, {
value: 3
}]);
this.assertText('Prev1NextPrev2NextPrev3Next');
};
_proto10['@test it can render duplicate objects'] = function testItCanRenderDuplicateObjects() {
var _this13 = 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();
(0, _internalTestHelpers.runTask)(function () {
return _this13.pushObject(duplicateItem);
});
this.assertText('foofoobarbazfoo');
(0, _internalTestHelpers.runTask)(function () {
return _this13.pushObject(duplicateItem);
});
this.assertText('foofoobarbazfoofoo');
this.replaceList([duplicateItem, duplicateItem, {
text: 'bar'
}, {
text: 'baz'
}]);
this.assertText('foofoobarbaz');
};
_proto10["@test it maintains DOM stability when condition changes between objects with the same keys"] = function () {
var _this14 = 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();
(0, _internalTestHelpers.runTask)(function () {
_this14.popObject();
_this14.popObject();
_this14.pushObject({
text: ' '
});
_this14.pushObject({
text: 'world'
});
});
this.assertText('Hello world');
this.assertInvariants();
this.replaceList([{
text: 'Hello'
}, {
text: ' '
}, {
text: 'world'
}]);
this.assertText('Hello world');
this.assertInvariants();
};
_proto10["@test it maintains DOM stability for stable keys when list is updated"] = function () {
var _this15 = 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();
(0, _internalTestHelpers.runTask)(function () {
_this15.unshiftObject({
text: ', '
});
_this15.unshiftObject({
text: 'Hi'
});
_this15.pushObject({
text: '!'
});
_this15.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());
};
_proto10["@test it renders all items with duplicate key values"] = function () {
var _this16 = this;
this.makeList([{
text: 'Hello'
}, {
text: 'Hello'
}, {
text: 'Hello'
}]);
this.render("{{#each list key=\"text\" as |item|}}{{item.text}}{{/each}}");
this.assertText('HelloHelloHello');
(0, _internalTestHelpers.runTask)(function () {
_this16.forEach(function (hash) {
return (0, _metal.set)(hash, 'text', 'Goodbye');
});
});
this.assertText('GoodbyeGoodbyeGoodbye');
this.replaceList([{
text: 'Hello'
}, {
text: 'Hello'
}, {
text: 'Hello'
}]);
this.assertText('HelloHelloHello');
};
_proto10['@test context is not changed to the inner scope inside an {{#each as}} block'] = function testContextIsNotChangedToTheInnerScopeInsideAnEachAsBlock() {
var _this17 = 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();
(0, _internalTestHelpers.runTask)(function () {
return _this17.shiftObject();
});
this.assertText('Joel-JoelJoel-Joel');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this17.context, 'name', 'Godfrey');
});
this.assertText('Godfrey-GodfreyGodfrey-Godfrey');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this17.context, 'name', 'Joel');
});
this.replaceList([{
name: 'Chad'
}, {
name: 'Zack'
}, {
name: 'Asa'
}]);
this.assertText('Joel-JoelJoelJoel-Joel');
};
_proto10['@test can access the item and the original scope'] = function testCanAccessTheItemAndTheOriginalScope() {
var _this18 = 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]');
(0, _internalTestHelpers.runTask)(function () {
return _this18.rerender();
});
this.assertText('[Señor Engineer: Tom Dale][Señor Engineer: Yehuda Katz][Señor Engineer: Godfrey Chan]');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this18.objectAt(1), 'name', 'Stefan Penner');
_this18.removeAt(0);
_this18.pushObject({
name: 'Tom Dale'
});
_this18.insertAt(1, {
name: 'Chad Hietala'
});
(0, _metal.set)(_this18.context, 'title', 'Principal Engineer');
});
this.assertText('[Principal Engineer: Stefan Penner][Principal Engineer: Chad Hietala][Principal Engineer: Godfrey Chan][Principal Engineer: Tom Dale]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this18.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]');
};
_proto10['@test the scoped variable is not available outside the {{#each}} block.'] = function testTheScopedVariableIsNotAvailableOutsideTheEachBlock() {
var _this19 = this;
this.makeList(['Yehuda']);
this.render("{{name}}-{{#each list as |name|}}{{name}}{{/each}}-{{name}}", {
name: 'Stef'
});
this.assertText('Stef-Yehuda-Stef');
(0, _internalTestHelpers.runTask)(function () {
return _this19.rerender();
});
this.assertText('Stef-Yehuda-Stef');
(0, _internalTestHelpers.runTask)(function () {
return _this19.pushObjects([' ', 'Katz']);
});
this.assertText('Stef-Yehuda Katz-Stef');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this19.context, 'name', 'Tom');
});
this.assertText('Tom-Yehuda Katz-Tom');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this19.context, 'name', 'Stef');
});
this.replaceList(['Yehuda']);
this.assertText('Stef-Yehuda-Stef');
};
_proto10['@test inverse template is displayed with context'] = function testInverseTemplateIsDisplayedWithContext() {
var _this20 = this;
this.makeList([]);
this.render("{{#each list as |thing|}}Has Thing{{else}}No Thing {{otherThing}}{{/each}}", {
otherThing: 'bar'
});
this.assertText('No Thing bar');
(0, _internalTestHelpers.runTask)(function () {
return _this20.rerender();
});
this.assertText('No Thing bar');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this20.context, 'otherThing', 'biz');
});
this.assertText('No Thing biz');
(0, _internalTestHelpers.runTask)(function () {
return _this20.pushObject('non-empty');
});
this.assertText('Has Thing');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this20.context, 'otherThing', 'baz');
});
this.assertText('Has Thing');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this20.context, 'otherThing', 'bar');
});
this.replaceList([]);
this.assertText('No Thing bar');
};
_proto10['@test content that are not initially present updates correctly GH#13983'] = function testContentThatAreNotInitiallyPresentUpdatesCorrectlyGH13983() {
var _this21 = 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('');
(0, _internalTestHelpers.runTask)(function () {
return _this21.rerender();
});
this.assertText('');
(0, _internalTestHelpers.runTask)(function () {
return _this21.pushObject({
text: 'foo'
});
});
this.assertText('[foo]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this21.objectAt(0), 'text', 'FOO');
});
this.assertText('[FOO]');
(0, _internalTestHelpers.runTask)(function () {
return _this21.pushObject({
text: 'bar'
});
});
this.assertText('[FOO][bar]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this21.objectAt(1), 'text', 'BAR');
});
this.assertText('[FOO][BAR]');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this21.objectAt(1), 'text', 'baz');
});
this.assertText('[FOO][baz]');
(0, _internalTestHelpers.runTask)(function () {
return _this21.replace(1, 1, [{
text: 'BAZ'
}]);
});
this.assertText('[FOO][BAZ]');
this.replaceList([]);
this.assertText('');
};
_proto10['@test empty trusted content clears properly [GH#16314]'] = function testEmptyTrustedContentClearsProperlyGH16314() {
var _this22 = this;
this.makeList(['hello']);
this.render("before {{#each list as |value|}}{{{value}}}{{/each}} after");
this.assertText('before hello after');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return _this22.pushObjects([null, ' world']);
});
this.assertText('before hello world after');
(0, _internalTestHelpers.runTask)(function () {
return _this22.replace(1, 2, [undefined, ' world!']);
});
this.assertText('before hello world! after');
(0, _internalTestHelpers.runTask)(function () {
return _this22.replace(1, 2, [(0, _helpers.htmlSafe)(''), ' world!!']);
});
this.assertText('before hello world!! after');
this.replaceList(['hello']);
this.assertText('before hello after');
}
/* multi each */
;
_proto10['@test re-using the same variable with different {{#each}} blocks does not override each other'] = function testReUsingTheSameVariableWithDifferentEachBlocksDoesNotOverrideEachOther() {
var _this23 = this;
var admins = this.createList([{
name: 'Tom Dale'
}]);
var users = this.createList([{
name: 'Yehuda Katz'
}]);
this.render("Admin: {{#each admins key=\"name\" as |person|}}[{{person.name}}]{{/each}} User: {{#each users key=\"name\" as |person|}}[{{person.name}}]{{/each}}", {
admins: admins.list,
users: users.list
});
this.assertText('Admin: [Tom Dale] User: [Yehuda Katz]');
(0, _internalTestHelpers.runTask)(function () {
return _this23.rerender();
});
this.assertText('Admin: [Tom Dale] User: [Yehuda Katz]');
(0, _internalTestHelpers.runTask)(function () {
admins.delegate.pushObject({
name: 'Godfrey Chan'
});
(0, _metal.set)(users.delegate.objectAt(0), 'name', 'Stefan Penner');
});
this.assertText('Admin: [Tom Dale][Godfrey Chan] User: [Stefan Penner]');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this23.context, 'admins', _this23.createList([{
name: 'Tom Dale'
}]).list);
(0, _metal.set)(_this23.context, 'users', _this23.createList([{
name: 'Yehuda Katz'
}]).list);
});
this.assertText('Admin: [Tom Dale] User: [Yehuda Katz]');
};
_proto10["@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 _this24 = this;
var content = this.createList(['X', 'Y']);
var options = this.createList([{
label: 'One',
value: 1
}, {
label: 'Two',
value: 2
}]);
this.render((0, _internalTestHelpers.strip)(_templateObject2()), {
content: content.list,
options: options.list
});
this.assertText('X-1:One2:TwoY-1:One2:Two');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
content.delegate.pushObject('Z');
(0, _metal.set)(options.delegate.objectAt(0), 'value', 0);
});
this.assertText('X-0:One2:TwoY-0:One2:TwoZ-0:One2:Two');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this24.context, 'content', _this24.createList(['X', 'Y']).list);
(0, _metal.set)(_this24.context, 'options', _this24.createList([{
label: 'One',
value: 1
}, {
label: 'Two',
value: 2
}]).list);
});
this.assertText('X-1:One2:TwoY-1:One2:Two');
};
_proto10['@test the scoped variable is not available outside the {{#each}} block'] = function testTheScopedVariableIsNotAvailableOutsideTheEachBlock() {
var _this25 = this;
var first = this.createList(['Limbo']);
var fifth = this.createList(['Wrath']);
var ninth = this.createList(['Treachery']);
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: first.list,
fifth: fifth.list,
ninth: ninth.list
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
(0, _internalTestHelpers.runTask)(function () {
return _this25.rerender();
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this25.context, 'ring', 'O');
fifth.delegate.insertAt(0, 'D');
});
this.assertText('O-Limbo-D-Treachery-D-Wrath-Treachery-Wrath-Limbo-O');
(0, _internalTestHelpers.runTask)(function () {
first.delegate.pushObject('I');
ninth.delegate.replace(0, 1, ['K']);
});
this.assertText('O-Limbo-D-K-D-Wrath-K-Wrath-Limbo-I-D-K-D-Wrath-K-Wrath-I-O');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this25.context, 'ring', 'Greed');
(0, _metal.set)(_this25.context, 'first', _this25.createList(['Limbo']).list);
(0, _metal.set)(_this25.context, 'fifth', _this25.createList(['Wrath']).list);
(0, _metal.set)(_this25.context, 'ninth', _this25.createList(['Treachery']).list);
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
};
_proto10['@test it should support {{#each name as |foo|}}, then {{#each foo as |bar|}}'] = function testItShouldSupportEachNameAsFooThenEachFooAsBar() {
var _this26 = this;
var inner = this.createList(['caterpillar']);
var outer = this.createList([inner.list]);
this.render("{{#each name key=\"@index\" as |foo|}}{{#each foo as |bar|}}{{bar}}{{/each}}{{/each}}", {
name: outer.list
});
this.assertText('caterpillar');
(0, _internalTestHelpers.runTask)(function () {
return _this26.rerender();
});
this.assertText('caterpillar');
(0, _internalTestHelpers.runTask)(function () {
inner.delegate.replace(0, 1, ['lady']);
outer.delegate.pushObject(_this26.createList(['bird']).list);
});
this.assertText('ladybird');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this26.context, 'name', _this26.createList([_this26.createList(['caterpillar']).list]).list);
});
this.assertText('caterpillar');
};
return EachTest;
}(AbstractEachTest);
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each}} with native arrays',
/*#__PURE__*/
function (_EachTest) {
(0, _emberBabel.inheritsLoose)(_class5, _EachTest);
function _class5() {
return _EachTest.apply(this, arguments) || this;
}
var _proto11 = _class5.prototype;
_proto11.createList = function createList(items) {
return {
list: items,
delegate: new ArrayDelegate(items, items)
};
};
return _class5;
}(EachTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each}} with emberA-wrapped arrays',
/*#__PURE__*/
function (_EachTest2) {
(0, _emberBabel.inheritsLoose)(_class6, _EachTest2);
function _class6() {
return _EachTest2.apply(this, arguments) || this;
}
var _proto12 = _class6.prototype;
_proto12.createList = function createList(items) {
var wrapped = (0, _runtime.A)(items);
return {
list: wrapped,
delegate: wrapped
};
};
return _class6;
}(EachTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each}} with native Set',
/*#__PURE__*/
function (_EachTest3) {
(0, _emberBabel.inheritsLoose)(_class7, _EachTest3);
function _class7() {
return _EachTest3.apply(this, arguments) || this;
}
var _proto13 = _class7.prototype;
_proto13.createList = function createList(items) {
var set = makeSet(items);
return {
list: set,
delegate: new SetDelegate(set)
};
};
_proto13['@test it can render duplicate primitive items'] = function testItCanRenderDuplicatePrimitiveItems(assert) {
assert.ok(true, 'not supported by Set');
};
_proto13['@test it can render duplicate objects'] = function testItCanRenderDuplicateObjects(assert) {
assert.ok(true, 'not supported by Set');
};
return _class7;
}(EachTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each}} with array-like objects implementing forEach',
/*#__PURE__*/
function (_EachTest4) {
(0, _emberBabel.inheritsLoose)(_class8, _EachTest4);
function _class8() {
return _EachTest4.apply(this, arguments) || this;
}
var _proto14 = _class8.prototype;
_proto14.createList = function createList(items) {
var forEachable = new ForEachable(items);
return {
list: forEachable,
delegate: forEachable
};
};
return _class8;
}(EachTest));
if (_utils.HAS_NATIVE_SYMBOL) {
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each}} with array-like objects implementing Symbol.iterator',
/*#__PURE__*/
function (_EachTest5) {
(0, _emberBabel.inheritsLoose)(_class9, _EachTest5);
function _class9() {
return _EachTest5.apply(this, arguments) || this;
}
var _proto15 = _class9.prototype;
_proto15.createList = function createList(items) {
var iterable = new ArrayIterable(items);
return {
list: iterable,
delegate: iterable
};
};
return _class9;
}(EachTest));
}
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each}} with array proxies, modifying itself',
/*#__PURE__*/
function (_EachTest6) {
(0, _emberBabel.inheritsLoose)(_class10, _EachTest6);
function _class10() {
return _EachTest6.apply(this, arguments) || this;
}
var _proto16 = _class10.prototype;
_proto16.createList = function createList(items) {
var proxty = _runtime.ArrayProxy.create({
content: (0, _runtime.A)(items)
});
return {
list: proxty,
delegate: proxty
};
};
return _class10;
}(EachTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each}} with array proxies, replacing its content',
/*#__PURE__*/
function (_EachTest7) {
(0, _emberBabel.inheritsLoose)(_class11, _EachTest7);
function _class11() {
return _EachTest7.apply(this, arguments) || this;
}
var _proto17 = _class11.prototype;
_proto17.createList = function createList(items) {
var wrapped = (0, _runtime.A)(items);
return {
list: wrapped,
delegate: _runtime.ArrayProxy.create({
content: wrapped
})
};
};
return _class11;
}(EachTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each as}} undefined path',
/*#__PURE__*/
function (_RenderingTestCase2) {
(0, _emberBabel.inheritsLoose)(_class12, _RenderingTestCase2);
function _class12() {
return _RenderingTestCase2.apply(this, arguments) || this;
}
var _proto18 = _class12.prototype;
_proto18['@test keying off of `undefined` does not render'] = function testKeyingOffOfUndefinedDoesNotRender() {
var _this27 = this;
this.render((0, _internalTestHelpers.strip)(_templateObject3()), {
foo: {}
});
this.assertText('');
(0, _internalTestHelpers.runTask)(function () {
return _this27.rerender();
});
this.assertText('');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this27.context, 'foo', {
bar: {
baz: ['Here!']
}
});
});
this.assertText('Here!');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this27.context, 'foo', {});
});
this.assertText('');
};
return _class12;
}(_internalTestHelpers.RenderingTestCase));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each}} with sparse arrays',
/*#__PURE__*/
function (_RenderingTestCase3) {
(0, _emberBabel.inheritsLoose)(_class13, _RenderingTestCase3);
function _class13() {
return _RenderingTestCase3.apply(this, arguments) || this;
}
var _proto19 = _class13.prototype;
_proto19['@test it should itterate over holes'] = function testItShouldItterateOverHoles() {
var _this28 = this;
var sparseArray = [];
sparseArray[3] = 'foo';
sparseArray[4] = 'bar';
this.render((0, _internalTestHelpers.strip)(_templateObject4()), {
list: (0, _runtime.A)(sparseArray)
});
this.assertText('[0:][1:][2:][3:foo][4:bar]');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
var list = (0, _metal.get)(_this28.context, 'list');
list.pushObject('baz');
});
this.assertText('[0:][1:][2:][3:foo][4:bar][5:baz]');
};
return _class13;
}(_internalTestHelpers.RenderingTestCase));
/* globals MutationObserver: false */
if (typeof MutationObserver === 'function') {
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#each as}} DOM mutation test',
/*#__PURE__*/
function (_RenderingTestCase4) {
(0, _emberBabel.inheritsLoose)(_class14, _RenderingTestCase4);
function _class14() {
var _this29;
_this29 = _RenderingTestCase4.apply(this, arguments) || this;
_this29.observer = null;
return _this29;
}
var _proto20 = _class14.prototype;
_proto20.observe = function observe(element) {
var observer = this.observer = new MutationObserver(function () {});
observer.observe(element, {
childList: true,
characterData: true
});
};
_proto20.teardown = function teardown() {
if (this.observer) {
this.observer.disconnect();
}
_RenderingTestCase4.prototype.teardown.call(this);
};
_proto20.assertNoMutation = function assertNoMutation() {
this.assert.deepEqual(this.observer.takeRecords(), [], 'Expected no mutations');
};
_proto20.expectMutations = function expectMutations() {
this.assert.ok(this.observer.takeRecords().length > 0, 'Expected some mutations');
};
_proto20['@test {{#each}} should not mutate a subtree when the array has not changed [GH #14332]'] = function testEachShouldNotMutateASubtreeWhenTheArrayHasNotChangedGH14332() {
var _this30 = this;
var page = {
title: 'Blog Posts'
};
var model = [{
title: 'Rails is omakase'
}, {
title: 'Ember is omakase'
}];
this.render((0, _internalTestHelpers.strip)(_templateObject5()), {
page: page,
model: model
});
this.assertHTML((0, _internalTestHelpers.strip)(_templateObject6()));
this.observe(this.$('#posts')[0]); // MutationObserver is async
return _runtime.RSVP.Promise.resolve(function () {
_this30.assertStableRerender();
}).then(function () {
_this30.assertNoMutation();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this30.context, 'page', {
title: 'Essays'
});
});
_this30.assertHTML((0, _internalTestHelpers.strip)(_templateObject7()));
}).then(function () {
_this30.assertNoMutation();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this30.context.page, 'title', 'Think Pieces™');
});
_this30.assertHTML((0, _internalTestHelpers.strip)(_templateObject8()));
}).then(function () {
// The last set is localized to the `page` object, so we do not expect Glimmer
// to re-iterate the list
_this30.assertNoMutation();
});
};
return _class14;
}(_internalTestHelpers.RenderingTestCase));
}
});
enifed("@ember/-internals/glimmer/tests/integration/syntax/experimental-syntax-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/glimmer"], function (_emberBabel, _internalTestHelpers, _glimmer) {
"use strict";
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#-let obj as |bar|}}\n {{bar}}\n {{/-let}}\n "]);
_templateObject = function () {
return data;
};
return data;
}
(0, _internalTestHelpers.moduleFor)('registerMacros',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
var _this;
var originalMacros = _glimmer._experimentalMacros.slice();
(0, _glimmer._registerMacros)(function (blocks) {
blocks.add('-let', function (params, hash, _default, inverse, builder) {
builder.compileParams(params);
builder.invokeStaticBlock(_default, params.length);
});
});
_this = _RenderingTestCase.apply(this, arguments) || this;
_this.originalMacros = originalMacros;
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_glimmer._experimentalMacros.length = 0;
this.originalMacros.forEach(function (macro) {
return _glimmer._experimentalMacros.push(macro);
});
_RenderingTestCase.prototype.teardown.call(this);
};
_proto['@test allows registering custom syntax via private API'] = function testAllowsRegisteringCustomSyntaxViaPrivateAPI() {
this.render((0, _internalTestHelpers.strip)(_templateObject()), {
obj: 'hello world!'
});
this.assertText('hello world!');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/syntax/if-unless-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime", "@ember/-internals/metal", "@ember/-internals/glimmer/tests/utils/helpers", "@ember/-internals/glimmer/tests/utils/shared-conditional-tests"], function (_emberBabel, _internalTestHelpers, _runtime, _metal, _helpers, _sharedConditionalTests) {
"use strict";
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#if foo.bar.baz}}\n Here!\n {{else}}\n Nothing Here!\n {{/if}}"]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (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}}"]);
_templateObject = function () {
return data;
};
return data;
}
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#if}} with inverse',
/*#__PURE__*/
function (_IfUnlessWithSyntaxTe) {
(0, _emberBabel.inheritsLoose)(_class, _IfUnlessWithSyntaxTe);
function _class() {
return _IfUnlessWithSyntaxTe.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.templateFor = function templateFor(_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return "{{#if " + cond + "}}" + truthy + "{{else}}" + falsy + "{{/if}}";
};
return _class;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#unless}} with inverse',
/*#__PURE__*/
function (_IfUnlessWithSyntaxTe2) {
(0, _emberBabel.inheritsLoose)(_class2, _IfUnlessWithSyntaxTe2);
function _class2() {
return _IfUnlessWithSyntaxTe2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2.templateFor = function templateFor(_ref2) {
var cond = _ref2.cond,
truthy = _ref2.truthy,
falsy = _ref2.falsy;
return "{{#unless " + cond + "}}" + falsy + "{{else}}" + truthy + "{{/unless}}";
};
return _class2;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#if}} and {{#unless}} without inverse',
/*#__PURE__*/
function (_IfUnlessWithSyntaxTe3) {
(0, _emberBabel.inheritsLoose)(_class3, _IfUnlessWithSyntaxTe3);
function _class3() {
return _IfUnlessWithSyntaxTe3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3.templateFor = function templateFor(_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, _internalTestHelpers.moduleFor)('Syntax test: {{#if}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class4, _RenderingTestCase);
function _class4() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto4 = _class4.prototype;
_proto4['@test using `if` with an `{{each}}` destroys components when transitioning to and from inverse (GH #12267)'] = function testUsingIfWithAnEachDestroysComponentsWhenTransitioningToAndFromInverseGH12267(assert) {
var _this = this;
var destroyedChildrenCount = 0;
this.registerComponent('foo-bar', {
template: '{{number}}',
ComponentClass: _helpers.Component.extend({
willDestroy: function () {
this._super();
destroyedChildrenCount++;
}
})
});
this.render((0, _internalTestHelpers.strip)(_templateObject()), {
cond: true,
numbers: (0, _runtime.A)([1, 2, 3])
});
this.assertText('123');
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
this.assertText('123');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'cond', false);
});
this.assertText('Nothing Here!');
assert.equal(destroyedChildrenCount, 3, 'the children were properly destroyed');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'cond', true);
});
this.assertText('123');
};
_proto4['@test looking up `undefined` property defaults to false'] = function testLookingUpUndefinedPropertyDefaultsToFalse() {
var _this2 = this;
this.render((0, _internalTestHelpers.strip)(_templateObject2()), {
foo: {}
});
this.assertText('Nothing Here!');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertText('Nothing Here!');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'foo', {
bar: {
baz: true
}
});
});
this.assertText('Here!');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'foo', {});
});
this.assertText('Nothing Here!');
};
return _class4;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/syntax/in-element-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/glimmer", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _glimmer, _metal) {
"use strict";
function _templateObject3() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#if showModal}}\n {{#-in-element someElement}}\n {{modal-display text=text}}\n {{/-in-element}}\n {{/if}}\n "]);
_templateObject3 = function () {
return data;
};
return data;
}
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#-in-element someElement}}\n {{text}}\n {{/-in-element}}\n "]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["{{#in-element el}}{{/in-element}}"]);
_templateObject = function () {
return data;
};
return data;
}
(0, _internalTestHelpers.moduleFor)('{{-in-element}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test using {{#in-element whatever}} asserts'] = function testUsingInElementWhateverAsserts() {
var _this = this; // the in-element keyword is not yet public API this test should be removed
// once https://github.com/emberjs/rfcs/pull/287 lands and is enabled
var el = document.createElement('div');
expectAssertion(function () {
_this.render((0, _internalTestHelpers.strip)(_templateObject()), {
el: el
});
}, /The {{in-element}} helper cannot be used. \('-top-level' @ L1:C0\)/);
};
_proto['@test allows rendering into an external element'] = function testAllowsRenderingIntoAnExternalElement() {
var _this2 = this;
var someElement = document.createElement('div');
this.render((0, _internalTestHelpers.strip)(_templateObject2()), {
someElement: someElement,
text: 'Whoop!'
});
(0, _internalTestHelpers.equalTokens)(this.element, '');
(0, _internalTestHelpers.equalTokens)(someElement, 'Whoop!');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'text', 'Huzzah!!');
});
(0, _internalTestHelpers.equalTokens)(this.element, '');
(0, _internalTestHelpers.equalTokens)(someElement, 'Huzzah!!');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'text', 'Whoop!');
});
(0, _internalTestHelpers.equalTokens)(this.element, '');
(0, _internalTestHelpers.equalTokens)(someElement, 'Whoop!');
};
_proto['@test components are cleaned up properly'] = function testComponentsAreCleanedUpProperly(assert) {
var _this3 = this;
var hooks = [];
var someElement = document.createElement('div');
this.registerComponent('modal-display', {
ComponentClass: _glimmer.Component.extend({
didInsertElement: function () {
hooks.push('didInsertElement');
},
willDestroyElement: function () {
hooks.push('willDestroyElement');
}
}),
template: "{{text}}"
});
this.render((0, _internalTestHelpers.strip)(_templateObject3()), {
someElement: someElement,
text: 'Whoop!',
showModal: false
});
(0, _internalTestHelpers.equalTokens)(this.element, '');
(0, _internalTestHelpers.equalTokens)(someElement, '');
this.assertStableRerender();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'showModal', true);
});
(0, _internalTestHelpers.equalTokens)(this.element, '');
this.assertComponentElement(someElement.firstChild, {
content: 'Whoop!'
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'text', 'Huzzah!');
});
(0, _internalTestHelpers.equalTokens)(this.element, '');
this.assertComponentElement(someElement.firstChild, {
content: 'Huzzah!'
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'text', 'Whoop!');
});
(0, _internalTestHelpers.equalTokens)(this.element, '');
this.assertComponentElement(someElement.firstChild, {
content: 'Whoop!'
});
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'showModal', false);
});
(0, _internalTestHelpers.equalTokens)(this.element, '');
(0, _internalTestHelpers.equalTokens)(someElement, '');
assert.deepEqual(hooks, ['didInsertElement', 'willDestroyElement']);
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/syntax/let-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/runtime"], function (_emberBabel, _internalTestHelpers, _metal, _runtime) {
"use strict";
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{name}}\n {{#let committer1.name as |name|}}\n [{{name}}\n {{#let committer2.name as |name|}}\n [{{name}}]\n {{/let}}\n {{name}}]\n {{/let}}\n {{name}}\n {{#let committer2.name as |name|}}\n [{{name}}\n {{#let committer1.name as |name|}}\n [{{name}}]\n {{/let}}\n {{name}}]\n {{/let}}\n {{name}}\n "]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#let foo.bar.baz as |thing|}}\n value: \"{{thing}}\"\n {{/let}}"]);
_templateObject = function () {
return data;
};
return data;
}
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#let as}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.templateFor = function templateFor(_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return "{{#let " + cond + " as |test|}}" + truthy + "{{else}}" + falsy + "{{/let}}";
};
_proto['@test it renders the block if `undefined` is passed as an argument'] = function testItRendersTheBlockIfUndefinedIsPassedAsAnArgument() {
var _this = this;
this.render((0, _internalTestHelpers.strip)(_templateObject()), {
foo: {}
});
this.assertText('value: ""');
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
this.assertText('value: ""');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'foo', {
bar: {
baz: 'Here!'
}
});
});
this.assertText('value: "Here!"');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'foo', {});
});
this.assertText('value: ""');
};
_proto['@test it renders the block if arguments are falsey'] = function testItRendersTheBlockIfArgumentsAreFalsey() {
var _this2 = this;
this.render("{{#let cond1 cond2 as |cond|}}value: \"{{cond1}}\"{{/let}}", {
cond1: false
});
this.assertText('value: "false"');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertText('value: "false"');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'cond1', '');
});
this.assertText('value: ""');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'cond1', 0);
});
this.assertText('value: "0"');
};
_proto['@test it yields multiple arguments in order'] = function testItYieldsMultipleArgumentsInOrder() {
var _this3 = this;
this.render("{{#let foo bar baz.name as |a b c|}}{{a}} {{b}} {{c}}{{/let}}", {
foo: 'Señor Engineer',
bar: '',
baz: {
name: 'Dale'
}
});
this.assertText('Señor Engineer Dale');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'bar', 'Tom');
});
this.assertText('Señor Engineer Tom Dale');
};
_proto['@test can access alias and original scope'] = function testCanAccessAliasAndOriginalScope() {
var _this4 = this;
this.render("{{#let person as |tom|}}{{title}}: {{tom.name}}{{/let}}", {
title: 'Señor Engineer',
person: {
name: 'Tom Dale'
}
});
this.assertText('Señor Engineer: Tom Dale');
(0, _internalTestHelpers.runTask)(function () {
return _this4.rerender();
});
this.assertText('Señor Engineer: Tom Dale');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this4.context, 'person.name', 'Yehuda Katz');
(0, _metal.set)(_this4.context, 'title', 'Principal Engineer');
});
this.assertText('Principal Engineer: Yehuda Katz');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this4.context, 'person', {
name: 'Tom Dale'
});
(0, _metal.set)(_this4.context, 'title', 'Señor Engineer');
});
this.assertText('Señor Engineer: Tom Dale');
};
_proto['@test the scoped variable is not available outside the {{#let}} block.'] = function testTheScopedVariableIsNotAvailableOutsideTheLetBlock() {
var _this5 = this;
this.render("{{name}}-{{#let other as |name|}}{{name}}{{/let}}-{{name}}", {
name: 'Stef',
other: 'Yehuda'
});
this.assertText('Stef-Yehuda-Stef');
(0, _internalTestHelpers.runTask)(function () {
return _this5.rerender();
});
this.assertText('Stef-Yehuda-Stef');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'other', 'Chad');
});
this.assertText('Stef-Chad-Stef');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'name', 'Tom');
});
this.assertText('Tom-Chad-Tom');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this5.context, 'name', 'Stef');
(0, _metal.set)(_this5.context, 'other', 'Yehuda');
});
this.assertText('Stef-Yehuda-Stef');
};
_proto['@test can access alias of a proxy'] = function testCanAccessAliasOfAProxy() {
var _this6 = this;
this.render("{{#let proxy as |person|}}{{person.name}}{{/let}}", {
proxy: _runtime.ObjectProxy.create({
content: {
name: 'Tom Dale'
}
})
});
this.assertText('Tom Dale');
(0, _internalTestHelpers.runTask)(function () {
return _this6.rerender();
});
this.assertText('Tom Dale');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'proxy.name', 'Yehuda Katz');
});
this.assertText('Yehuda Katz');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'proxy.content', {
name: 'Godfrey Chan'
});
});
this.assertText('Godfrey Chan');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'proxy.content.name', 'Stefan Penner');
});
this.assertText('Stefan Penner');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'proxy.content', null);
});
this.assertText('');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'proxy', _runtime.ObjectProxy.create({
content: {
name: 'Tom Dale'
}
}));
});
this.assertText('Tom Dale');
};
_proto['@test can access alias of an array'] = function testCanAccessAliasOfAnArray() {
var _this7 = this;
this.render("{{#let arrayThing as |words|}}{{#each words as |word|}}{{word}}{{/each}}{{/let}}", {
arrayThing: (0, _runtime.A)(['Hello', ' ', 'world'])
});
this.assertText('Hello world');
(0, _internalTestHelpers.runTask)(function () {
return _this7.rerender();
});
this.assertText('Hello world');
(0, _internalTestHelpers.runTask)(function () {
var array = (0, _metal.get)(_this7.context, 'arrayThing');
array.replace(0, 1, ['Goodbye']);
(0, _runtime.removeAt)(array, 1);
array.insertAt(1, ', ');
array.pushObject('!');
});
this.assertText('Goodbye, world!');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this7.context, 'arrayThing', ['Hello', ' ', 'world']);
});
this.assertText('Hello world');
};
_proto['@test `attrs` can be used as a block param [GH#14678]'] = function testAttrsCanBeUsedAsABlockParamGH14678() {
var _this8 = this;
this.render('{{#let hash as |attrs|}}[{{hash.foo}}-{{attrs.foo}}]{{/let}}', {
hash: {
foo: 'foo'
}
});
this.assertText('[foo-foo]');
(0, _internalTestHelpers.runTask)(function () {
return _this8.rerender();
});
this.assertText('[foo-foo]');
(0, _internalTestHelpers.runTask)(function () {
return _this8.context.set('hash.foo', 'FOO');
});
this.assertText('[FOO-FOO]');
(0, _internalTestHelpers.runTask)(function () {
return _this8.context.set('hash.foo', 'foo');
});
this.assertText('[foo-foo]');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
(0, _internalTestHelpers.moduleFor)('Syntax test: Multiple {{#let as}} helpers',
/*#__PURE__*/
function (_RenderingTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _RenderingTestCase2);
function _class2() {
return _RenderingTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test re-using the same variable with different {{#let}} blocks does not override each other'] = function testReUsingTheSameVariableWithDifferentLetBlocksDoesNotOverrideEachOther() {
var _this9 = this;
this.render("Admin: {{#let admin as |person|}}{{person.name}}{{/let}} User: {{#let user as |person|}}{{person.name}}{{/let}}", {
admin: {
name: 'Tom Dale'
},
user: {
name: 'Yehuda Katz'
}
});
this.assertText('Admin: Tom Dale User: Yehuda Katz');
(0, _internalTestHelpers.runTask)(function () {
return _this9.rerender();
});
this.assertText('Admin: Tom Dale User: Yehuda Katz');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this9.context, 'admin.name', 'Godfrey Chan');
(0, _metal.set)(_this9.context, 'user.name', 'Stefan Penner');
});
this.assertText('Admin: Godfrey Chan User: Stefan Penner');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this9.context, 'admin', {
name: 'Tom Dale'
});
(0, _metal.set)(_this9.context, 'user', {
name: 'Yehuda Katz'
});
});
this.assertText('Admin: Tom Dale User: Yehuda Katz');
};
_proto2['@test the scoped variable is not available outside the {{#let}} block'] = function testTheScopedVariableIsNotAvailableOutsideTheLetBlock() {
var _this10 = this;
this.render("{{ring}}-{{#let first as |ring|}}{{ring}}-{{#let fifth as |ring|}}{{ring}}-{{#let ninth as |ring|}}{{ring}}-{{/let}}{{ring}}-{{/let}}{{ring}}-{{/let}}{{ring}}", {
ring: 'Greed',
first: 'Limbo',
fifth: 'Wrath',
ninth: 'Treachery'
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
(0, _internalTestHelpers.runTask)(function () {
return _this10.rerender();
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this10.context, 'ring', 'O');
(0, _metal.set)(_this10.context, 'fifth', 'D');
});
this.assertText('O-Limbo-D-Treachery-D-Limbo-O');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this10.context, 'first', 'I');
(0, _metal.set)(_this10.context, 'ninth', 'K');
});
this.assertText('O-I-D-K-D-I-O');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this10.context, 'ring', 'Greed');
(0, _metal.set)(_this10.context, 'first', 'Limbo');
(0, _metal.set)(_this10.context, 'fifth', 'Wrath');
(0, _metal.set)(_this10.context, 'ninth', 'Treachery');
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
};
_proto2['@test it should support {{#let name as |foo|}}, then {{#let foo as |bar|}}'] = function testItShouldSupportLetNameAsFooThenLetFooAsBar() {
var _this11 = this;
this.render("{{#let name as |foo|}}{{#let foo as |bar|}}{{bar}}{{/let}}{{/let}}", {
name: 'caterpillar'
});
this.assertText('caterpillar');
(0, _internalTestHelpers.runTask)(function () {
return _this11.rerender();
});
this.assertText('caterpillar');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'name', 'butterfly');
});
this.assertText('butterfly');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'name', 'caterpillar');
});
this.assertText('caterpillar');
};
_proto2['@test updating the context should update the alias'] = function testUpdatingTheContextShouldUpdateTheAlias() {
var _this12 = this;
this.render("{{#let this as |person|}}{{person.name}}{{/let}}", {
name: 'Los Pivots'
});
this.assertText('Los Pivots');
(0, _internalTestHelpers.runTask)(function () {
return _this12.rerender();
});
this.assertText('Los Pivots');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'name', "l'Pivots");
});
this.assertText("l'Pivots");
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'name', 'Los Pivots');
});
this.assertText('Los Pivots');
};
_proto2['@test nested {{#let}} blocks should have access to root context'] = function testNestedLetBlocksShouldHaveAccessToRootContext() {
var _this13 = this;
this.render((0, _internalTestHelpers.strip)(_templateObject2()), {
name: 'ebryn',
committer1: {
name: 'trek'
},
committer2: {
name: 'machty'
}
});
this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');
(0, _internalTestHelpers.runTask)(function () {
return _this13.rerender();
});
this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this13.context, 'name', 'chancancode');
});
this.assertText('chancancode[trek[machty]trek]chancancode[machty[trek]machty]chancancode');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this13.context, 'committer1', {
name: 'krisselden'
});
});
this.assertText('chancancode[krisselden[machty]krisselden]chancancode[machty[krisselden]machty]chancancode');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this13.context, 'committer1.name', 'wycats');
(0, _metal.set)(_this13.context, 'committer2', {
name: 'rwjblue'
});
});
this.assertText('chancancode[wycats[rwjblue]wycats]chancancode[rwjblue[wycats]rwjblue]chancancode');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this13.context, 'name', 'ebryn');
(0, _metal.set)(_this13.context, 'committer1', {
name: 'trek'
});
(0, _metal.set)(_this13.context, 'committer2', {
name: 'machty'
});
});
this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');
};
return _class2;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/syntax/with-dynamic-var-test", ["ember-babel", "internal-test-helpers"], function (_emberBabel, _internalTestHelpers) {
"use strict";
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#-with-dynamic-vars outletState=\"bar\"}}\n {{-get-dynamic-var 'outletState'}}\n {{/-with-dynamic-vars}}\n "]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#-with-dynamic-vars foo=\"bar\"}}\n {{-get-dynamic-var 'foo'}}\n {{/-with-dynamic-vars}}\n "]);
_templateObject = function () {
return data;
};
return data;
}
(0, _internalTestHelpers.moduleFor)('{{-with-dynamic-var}}',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test does not allow setting values other than outletState'] = function testDoesNotAllowSettingValuesOtherThanOutletState() {
var _this = this;
expectAssertion(function () {
_this.render((0, _internalTestHelpers.strip)(_templateObject()));
}, /Using `-with-dynamic-scope` is only supported for `outletState` \(you used `foo`\)./);
};
_proto['@test allows setting/getting outletState'] = function testAllowsSettingGettingOutletState() {
// 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, _internalTestHelpers.strip)(_templateObject2()));
this.assertText('bar');
};
_proto['@test does not allow setting values other than outletState'] = function testDoesNotAllowSettingValuesOtherThanOutletState() {
var _this2 = this;
expectAssertion(function () {
_this2.render("{{-get-dynamic-var 'foo'}}");
}, /Using `-get-dynamic-scope` is only supported for `outletState` \(you used `foo`\)./);
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/integration/syntax/with-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/runtime", "@ember/-internals/glimmer/tests/utils/shared-conditional-tests"], function (_emberBabel, _internalTestHelpers, _metal, _runtime, _sharedConditionalTests) {
"use strict";
function _templateObject2() {
var data = (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 "]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["\n {{#with foo.bar.baz as |thing|}}\n {{thing}}\n {{/with}}"]);
_templateObject = function () {
return data;
};
return data;
}
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#with}}',
/*#__PURE__*/
function (_IfUnlessWithSyntaxTe) {
(0, _emberBabel.inheritsLoose)(_class, _IfUnlessWithSyntaxTe);
function _class() {
return _IfUnlessWithSyntaxTe.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.templateFor = function templateFor(_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return "{{#with " + cond + "}}" + truthy + "{{else}}" + falsy + "{{/with}}";
};
return _class;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: {{#with as}}',
/*#__PURE__*/
function (_IfUnlessWithSyntaxTe2) {
(0, _emberBabel.inheritsLoose)(_class2, _IfUnlessWithSyntaxTe2);
function _class2() {
return _IfUnlessWithSyntaxTe2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2.templateFor = function templateFor(_ref2) {
var cond = _ref2.cond,
truthy = _ref2.truthy,
falsy = _ref2.falsy;
return "{{#with " + cond + " as |test|}}" + truthy + "{{else}}" + falsy + "{{/with}}";
};
_proto2['@test keying off of `undefined` does not render'] = function testKeyingOffOfUndefinedDoesNotRender() {
var _this = this;
this.render((0, _internalTestHelpers.strip)(_templateObject()), {
foo: {}
});
this.assertText('');
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
this.assertText('');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'foo', {
bar: {
baz: 'Here!'
}
});
});
this.assertText('Here!');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'foo', {});
});
this.assertText('');
};
_proto2['@test it renders and hides the given block based on the conditional'] = function testItRendersAndHidesTheGivenBlockBasedOnTheConditional() {
var _this2 = this;
this.render("{{#with cond1 as |cond|}}{{cond.greeting}}{{else}}False{{/with}}", {
cond1: {
greeting: 'Hello'
}
});
this.assertText('Hello');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertText('Hello');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'cond1.greeting', 'Hello world');
});
this.assertText('Hello world');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'cond1', false);
});
this.assertText('False');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'cond1', {
greeting: 'Hello'
});
});
this.assertText('Hello');
};
_proto2['@test can access alias and original scope'] = function testCanAccessAliasAndOriginalScope() {
var _this3 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this3.rerender();
});
this.assertText('Señor Engineer: Tom Dale');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this3.context, 'person.name', 'Yehuda Katz');
(0, _metal.set)(_this3.context, 'title', 'Principal Engineer');
});
this.assertText('Principal Engineer: Yehuda Katz');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this3.context, 'person', {
name: 'Tom Dale'
});
(0, _metal.set)(_this3.context, 'title', 'Señor Engineer');
});
this.assertText('Señor Engineer: Tom Dale');
};
_proto2['@test the scoped variable is not available outside the {{#with}} block.'] = function testTheScopedVariableIsNotAvailableOutsideTheWithBlock() {
var _this4 = this;
this.render("{{name}}-{{#with other as |name|}}{{name}}{{/with}}-{{name}}", {
name: 'Stef',
other: 'Yehuda'
});
this.assertText('Stef-Yehuda-Stef');
(0, _internalTestHelpers.runTask)(function () {
return _this4.rerender();
});
this.assertText('Stef-Yehuda-Stef');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'other', 'Chad');
});
this.assertText('Stef-Chad-Stef');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'name', 'Tom');
});
this.assertText('Tom-Chad-Tom');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this4.context, 'name', 'Stef');
(0, _metal.set)(_this4.context, 'other', 'Yehuda');
});
this.assertText('Stef-Yehuda-Stef');
};
_proto2['@test inverse template is displayed with context'] = function testInverseTemplateIsDisplayedWithContext() {
var _this5 = this;
this.render("{{#with falsyThing as |thing|}}Has Thing{{else}}No Thing {{otherThing}}{{/with}}", {
falsyThing: null,
otherThing: 'bar'
});
this.assertText('No Thing bar');
(0, _internalTestHelpers.runTask)(function () {
return _this5.rerender();
});
this.assertText('No Thing bar');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'otherThing', 'biz');
});
this.assertText('No Thing biz');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'falsyThing', true);
});
this.assertText('Has Thing');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'otherThing', 'baz');
});
this.assertText('Has Thing');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this5.context, 'otherThing', 'bar');
(0, _metal.set)(_this5.context, 'falsyThing', null);
});
this.assertText('No Thing bar');
};
_proto2['@test can access alias of a proxy'] = function testCanAccessAliasOfAProxy() {
var _this6 = this;
this.render("{{#with proxy as |person|}}{{person.name}}{{/with}}", {
proxy: _runtime.ObjectProxy.create({
content: {
name: 'Tom Dale'
}
})
});
this.assertText('Tom Dale');
(0, _internalTestHelpers.runTask)(function () {
return _this6.rerender();
});
this.assertText('Tom Dale');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'proxy.name', 'Yehuda Katz');
});
this.assertText('Yehuda Katz');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'proxy.content', {
name: 'Godfrey Chan'
});
});
this.assertText('Godfrey Chan');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'proxy.content.name', 'Stefan Penner');
});
this.assertText('Stefan Penner');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'proxy.content', null);
});
this.assertText('');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'proxy', _runtime.ObjectProxy.create({
content: {
name: 'Tom Dale'
}
}));
});
this.assertText('Tom Dale');
};
_proto2['@test can access alias of an array'] = function testCanAccessAliasOfAnArray() {
var _this7 = this;
this.render("{{#with arrayThing as |words|}}{{#each words as |word|}}{{word}}{{/each}}{{/with}}", {
arrayThing: (0, _runtime.A)(['Hello', ' ', 'world'])
});
this.assertText('Hello world');
(0, _internalTestHelpers.runTask)(function () {
return _this7.rerender();
});
this.assertText('Hello world');
(0, _internalTestHelpers.runTask)(function () {
var array = (0, _metal.get)(_this7.context, 'arrayThing');
array.replace(0, 1, ['Goodbye']);
(0, _runtime.removeAt)(array, 1);
array.insertAt(1, ', ');
array.pushObject('!');
});
this.assertText('Goodbye, world!');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this7.context, 'arrayThing', ['Hello', ' ', 'world']);
});
this.assertText('Hello world');
};
_proto2['@test `attrs` can be used as a block param [GH#14678]'] = function testAttrsCanBeUsedAsABlockParamGH14678() {
var _this8 = this;
this.render('{{#with hash as |attrs|}}[{{hash.foo}}-{{attrs.foo}}]{{/with}}', {
hash: {
foo: 'foo'
}
});
this.assertText('[foo-foo]');
(0, _internalTestHelpers.runTask)(function () {
return _this8.rerender();
});
this.assertText('[foo-foo]');
(0, _internalTestHelpers.runTask)(function () {
return _this8.context.set('hash.foo', 'FOO');
});
this.assertText('[FOO-FOO]');
(0, _internalTestHelpers.runTask)(function () {
return _this8.context.set('hash.foo', 'foo');
});
this.assertText('[foo-foo]');
};
return _class2;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _internalTestHelpers.moduleFor)('Syntax test: Multiple {{#with as}} helpers',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class3, _RenderingTestCase);
function _class3() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3['@test re-using the same variable with different {{#with}} blocks does not override each other'] = function testReUsingTheSameVariableWithDifferentWithBlocksDoesNotOverrideEachOther() {
var _this9 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this9.rerender();
});
this.assertText('Admin: Tom Dale User: Yehuda Katz');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this9.context, 'admin.name', 'Godfrey Chan');
(0, _metal.set)(_this9.context, 'user.name', 'Stefan Penner');
});
this.assertText('Admin: Godfrey Chan User: Stefan Penner');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this9.context, 'admin', {
name: 'Tom Dale'
});
(0, _metal.set)(_this9.context, 'user', {
name: 'Yehuda Katz'
});
});
this.assertText('Admin: Tom Dale User: Yehuda Katz');
};
_proto3['@test the scoped variable is not available outside the {{#with}} block'] = function testTheScopedVariableIsNotAvailableOutsideTheWithBlock() {
var _this10 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this10.rerender();
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this10.context, 'ring', 'O');
(0, _metal.set)(_this10.context, 'fifth', 'D');
});
this.assertText('O-Limbo-D-Treachery-D-Limbo-O');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this10.context, 'first', 'I');
(0, _metal.set)(_this10.context, 'ninth', 'K');
});
this.assertText('O-I-D-K-D-I-O');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this10.context, 'ring', 'Greed');
(0, _metal.set)(_this10.context, 'first', 'Limbo');
(0, _metal.set)(_this10.context, 'fifth', 'Wrath');
(0, _metal.set)(_this10.context, 'ninth', 'Treachery');
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
};
_proto3['@test it should support {{#with name as |foo|}}, then {{#with foo as |bar|}}'] = function testItShouldSupportWithNameAsFooThenWithFooAsBar() {
var _this11 = this;
this.render("{{#with name as |foo|}}{{#with foo as |bar|}}{{bar}}{{/with}}{{/with}}", {
name: 'caterpillar'
});
this.assertText('caterpillar');
(0, _internalTestHelpers.runTask)(function () {
return _this11.rerender();
});
this.assertText('caterpillar');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'name', 'butterfly');
});
this.assertText('butterfly');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this11.context, 'name', 'caterpillar');
});
this.assertText('caterpillar');
};
_proto3['@test updating the context should update the alias'] = function testUpdatingTheContextShouldUpdateTheAlias() {
var _this12 = this;
this.render("{{#with this as |person|}}{{person.name}}{{/with}}", {
name: 'Los Pivots'
});
this.assertText('Los Pivots');
(0, _internalTestHelpers.runTask)(function () {
return _this12.rerender();
});
this.assertText('Los Pivots');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'name', "l'Pivots");
});
this.assertText("l'Pivots");
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this12.context, 'name', 'Los Pivots');
});
this.assertText('Los Pivots');
};
_proto3['@test nested {{#with}} blocks should have access to root context'] = function testNestedWithBlocksShouldHaveAccessToRootContext() {
var _this13 = this;
this.render((0, _internalTestHelpers.strip)(_templateObject2()), {
name: 'ebryn',
committer1: {
name: 'trek'
},
committer2: {
name: 'machty'
}
});
this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');
(0, _internalTestHelpers.runTask)(function () {
return _this13.rerender();
});
this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this13.context, 'name', 'chancancode');
});
this.assertText('chancancode[trek[machty]trek]chancancode[machty[trek]machty]chancancode');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this13.context, 'committer1', {
name: 'krisselden'
});
});
this.assertText('chancancode[krisselden[machty]krisselden]chancancode[machty[krisselden]machty]chancancode');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this13.context, 'committer1.name', 'wycats');
(0, _metal.set)(_this13.context, 'committer2', {
name: 'rwjblue'
});
});
this.assertText('chancancode[wycats[rwjblue]wycats]chancancode[rwjblue[wycats]rwjblue]chancancode');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this13.context, 'name', 'ebryn');
(0, _metal.set)(_this13.context, 'committer1', {
name: 'trek'
});
(0, _metal.set)(_this13.context, 'committer2', {
name: 'machty'
});
});
this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');
};
return _class3;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/unit/outlet-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/glimmer", "@ember/runloop"], function (_emberBabel, _internalTestHelpers, _glimmer, _runloop) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Glimmer OutletView',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test render in the render queue'] = function testRenderInTheRenderQueue(assert) {
var didAppendOutletView = 0;
var expectedOutlet = '#foo.bar';
var renderer = {
appendOutletView: function (view, target) {
didAppendOutletView++;
assert.equal(view, outletView);
assert.equal(target, expectedOutlet);
}
};
var outletView = new _glimmer.OutletView({}, renderer);
(0, _runloop.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)');
(0, _runloop.schedule)('actions', function () {
return assert.equal(didAppendOutletView, 0, 'appendOutletView should not yet have been called (in actions)');
});
(0, _runloop.schedule)('render', function () {
return assert.equal(didAppendOutletView, 1, 'appendOutletView should be invoked in render');
});
});
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/glimmer/tests/unit/runtime-resolver-cache-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _metal, _helpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('ember-glimmer runtime resolver cache',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test a helper definition is only generated once'] = function testAHelperDefinitionIsOnlyGeneratedOnce(assert) {
var _this = this;
this.registerHelper('foo-bar', function () {
return 'foo-bar helper!';
});
this.registerHelper('baz-qux', function () {
return 'baz-qux helper!';
}); // assert precondition
var state = this.getCacheCounters();
assert.deepEqual(state, {
templateCacheHits: 0,
templateCacheMisses: 0,
componentDefinitionCount: 0,
helperDefinitionCount: 0
}, 'precondition');
this.render("\n {{~#if cond~}}\n {{foo-bar}}\n {{~else~}}\n {{baz-qux}}\n {{~/if}}", {
cond: true
});
this.assertText('foo-bar helper!');
state = this.expectCacheChanges({
helperDefinitionCount: 1
}, state, 'calculate foo-bar helper only'); // show component-two for the first time
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'cond', false);
});
this.assertText('baz-qux helper!');
state = this.expectCacheChanges({
helperDefinitionCount: 1
}, state, 'calculate baz-qux helper, misses cache'); // show foo-bar again
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'cond', true);
});
this.assertText('foo-bar helper!');
state = this.expectCacheChanges({}, state, 'toggle back to foo-bar cache hit'); // show baz-qux again
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'cond', false);
});
this.assertText('baz-qux helper!');
state = this.expectCacheChanges({}, state, 'toggle back to baz-qux cache hit');
};
_proto['@test a component definition is only generated once'] = function testAComponentDefinitionIsOnlyGeneratedOnce(assert) {
var _this2 = this; // static layout
this.registerComponent('component-one', {
template: 'One'
});
this.registerComponent('component-two', {
ComponentClass: _helpers.Component.extend(),
template: 'Two'
}); // assert precondition
var state = this.getCacheCounters();
assert.deepEqual(state, {
templateCacheHits: 0,
templateCacheMisses: 0,
componentDefinitionCount: 0,
helperDefinitionCount: 0
}, 'precondition'); // show component-one for the first time
this.render("{{component componentName}}", {
componentName: 'component-one'
});
this.assertText('One');
state = this.expectCacheChanges({
componentDefinitionCount: 1
}, state, 'test case component and component-one no change'); // show component-two for the first time
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'componentName', 'component-two');
});
this.assertText('Two');
state = this.expectCacheChanges({
componentDefinitionCount: 1
}, state, 'component-two first render'); // show component-one again
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'componentName', 'component-one');
});
this.assertText('One');
state = this.expectCacheChanges({}, state, 'toggle back to component-one no change'); // show component-two again
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'componentName', 'component-two');
});
this.assertText('Two');
state = this.expectCacheChanges({}, state, 'toggle back to component-two no change');
};
_proto['@test each template is only compiled once'] = function testEachTemplateIsOnlyCompiledOnce(assert) {
var _this3 = this; // static layout
this.registerComponent('component-one', {
template: 'One'
}); // test directly import template factory onto late bound layout
var Two = _helpers.Component.extend({
layout: this.compile('Two')
});
this.registerComponent('component-two', {
ComponentClass: Two
}); // inject layout onto component, share layout with component-one
this.registerComponent('root-component', {
ComponentClass: _helpers.Component
});
this.owner.inject('component:root-component', 'layout', 'template:components/component-one'); // template instance shared between to template managers
var rootFactory = this.owner.factoryFor('component:root-component'); // assert precondition
var state = this.getCacheCounters();
assert.deepEqual(state, {
templateCacheHits: 0,
templateCacheMisses: 0,
componentDefinitionCount: 0,
helperDefinitionCount: 0
}, 'precondition'); // show component-one for the first time
this.render("\n {{~#if cond~}}\n {{component-one}}\n {{~else~}}\n {{component-two}}\n {{~/if}}", {
cond: true
});
this.assertText('One');
state = this.expectCacheChanges({
componentDefinitionCount: 1
}, state, 'test case component and component-one no change'); // show component-two for the first time
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'cond', false);
});
this.assertText('Two');
state = this.expectCacheChanges({
templateCacheMisses: 1,
componentDefinitionCount: 1
}, state, 'component-two first render misses template cache'); // show component-one again
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'cond', true);
});
this.assertText('One');
state = this.expectCacheChanges({}, state, 'toggle back to component-one no change'); // show component-two again
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'cond', false);
});
this.assertText('Two');
state = this.expectCacheChanges({
templateCacheHits: 1
}, state, 'toggle back to component-two hits template cache'); // render new root append
var root = rootFactory.create();
try {
(0, _internalTestHelpers.runAppend)(root);
this.assertText('TwoOne'); // roots have different capabilities so this will hit
state = this.expectCacheChanges({}, state, 'append root with component-one no change'); // render new root append
var root2 = rootFactory.create();
try {
(0, _internalTestHelpers.runAppend)(root2);
this.assertText('TwoOneOne');
state = this.expectCacheChanges({}, state, 'append another root no change');
} finally {
(0, _internalTestHelpers.runDestroy)(root2);
}
} finally {
(0, _internalTestHelpers.runDestroy)(root);
}
};
_proto.getCacheCounters = function getCacheCounters() {
var _this$runtimeResolver = this.runtimeResolver,
templateCacheHits = _this$runtimeResolver.templateCacheHits,
templateCacheMisses = _this$runtimeResolver.templateCacheMisses,
componentDefinitionCount = _this$runtimeResolver.componentDefinitionCount,
helperDefinitionCount = _this$runtimeResolver.helperDefinitionCount;
return {
templateCacheHits: templateCacheHits,
templateCacheMisses: templateCacheMisses,
componentDefinitionCount: componentDefinitionCount,
helperDefinitionCount: helperDefinitionCount
};
};
_proto.expectCacheChanges = function expectCacheChanges(expected, lastState, message) {
var state = this.getCacheCounters();
var actual = diff(state, lastState);
this.assert.deepEqual(actual, expected, message);
return state;
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
function diff(state, lastState) {
var res = {};
Object.keys(state).forEach(function (key) {
var delta = state[key] - lastState[key];
if (delta !== 0) {
res[key] = state[key] - lastState[key];
}
});
return res;
}
});
enifed("@ember/-internals/glimmer/tests/unit/template-factory-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/glimmer", "ember-template-compiler", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _glimmer, _emberTemplateCompiler, _helpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Template factory test',
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _RenderingTestCase);
function _class() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test the template factory returned from precompile is the same as compile'] = function testTheTemplateFactoryReturnedFromPrecompileIsTheSameAsCompile(assert) {
var owner = this.owner;
var runtimeResolver = this.runtimeResolver;
var templateStr = 'Hello {{name}}';
var options = {
moduleName: 'my-app/templates/some-module.hbs'
};
var spec = (0, _emberTemplateCompiler.precompile)(templateStr, options);
var body = "exports.default = template(" + spec + ");";
var module = new Function('exports', 'template', body);
var exports = {};
module(exports, _glimmer.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(runtimeResolver.templateCacheMisses, 0, 'misses 0');
assert.equal(runtimeResolver.templateCacheHits, 0, 'hits 0');
var precompiled = runtimeResolver.createTemplate(Precompiled, owner);
assert.equal(runtimeResolver.templateCacheMisses, 1, 'misses 1');
assert.equal(runtimeResolver.templateCacheHits, 0, 'hits 0');
var compiled = runtimeResolver.createTemplate(Compiled, owner);
assert.equal(runtimeResolver.templateCacheMisses, 2, 'misses 2');
assert.equal(runtimeResolver.templateCacheHits, 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(runtimeResolver.templateCacheMisses, 2, 'misses 2');
assert.equal(runtimeResolver.templateCacheHits, 2, 'hits 2');
this.assertText('Hello precompiled Hello compiled');
};
return _class;
}(_internalTestHelpers.RenderingTestCase));
});
enifed("@ember/-internals/glimmer/tests/unit/utils/debug-stack-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/glimmer"], function (_emberBabel, _internalTestHelpers, _glimmer) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Glimmer DebugStack',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test pushing and popping'] = function testPushingAndPopping(assert) {
if (true
/* DEBUG */
) {
var stack = new _glimmer.DebugStack();
assert.equal(stack.peek(), undefined);
stack.push('template:application');
assert.equal(stack.peek(), '"template:application"');
stack.push('component:top-level-component');
assert.equal(stack.peek(), '"component:top-level-component"');
stack.pushEngine('engine:my-engine');
stack.push('component:component-in-engine');
assert.equal(stack.peek(), '"component:component-in-engine" (in "engine:my-engine")');
stack.pop();
stack.pop();
var item = stack.pop();
assert.equal(item, 'component:top-level-component');
assert.equal(stack.peek(), '"template:application"');
} else {
assert.expect(0);
}
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/glimmer/tests/utils/helpers", ["exports", "ember-template-compiler", "@ember/-internals/glimmer"], function (_exports, _emberTemplateCompiler, _glimmer) {
"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 _glimmer.INVOKE;
}
});
Object.defineProperty(_exports, "Helper", {
enumerable: true,
get: function () {
return _glimmer.Helper;
}
});
Object.defineProperty(_exports, "helper", {
enumerable: true,
get: function () {
return _glimmer.helper;
}
});
Object.defineProperty(_exports, "Component", {
enumerable: true,
get: function () {
return _glimmer.Component;
}
});
Object.defineProperty(_exports, "LinkComponent", {
enumerable: true,
get: function () {
return _glimmer.LinkComponent;
}
});
Object.defineProperty(_exports, "InteractiveRenderer", {
enumerable: true,
get: function () {
return _glimmer.InteractiveRenderer;
}
});
Object.defineProperty(_exports, "InertRenderer", {
enumerable: true,
get: function () {
return _glimmer.InertRenderer;
}
});
Object.defineProperty(_exports, "htmlSafe", {
enumerable: true,
get: function () {
return _glimmer.htmlSafe;
}
});
Object.defineProperty(_exports, "SafeString", {
enumerable: true,
get: function () {
return _glimmer.SafeString;
}
});
Object.defineProperty(_exports, "DOMChanges", {
enumerable: true,
get: function () {
return _glimmer.DOMChanges;
}
});
Object.defineProperty(_exports, "isHTMLSafe", {
enumerable: true,
get: function () {
return _glimmer.isHTMLSafe;
}
});
});
enifed("@ember/-internals/glimmer/tests/utils/shared-conditional-tests", ["exports", "ember-babel", "internal-test-helpers", "@ember/polyfills", "@ember/-internals/metal", "@ember/-internals/runtime", "@ember/-internals/glimmer/tests/utils/helpers"], function (_exports, _emberBabel, _internalTestHelpers, _polyfills, _metal, _runtime, _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 = void 0;
var _ObjectTestCases, _ArrayTestCases;
/* eslint-disable no-new-wrappers */
var AbstractConditionalsTest =
/*#__PURE__*/
function (_RenderingTestCase) {
(0, _emberBabel.inheritsLoose)(AbstractConditionalsTest, _RenderingTestCase);
function AbstractConditionalsTest() {
return _RenderingTestCase.apply(this, arguments) || this;
}
var _proto = AbstractConditionalsTest.prototype;
_proto.wrapperFor = function wrapperFor(templates) {
return templates.join('');
};
_proto.wrappedTemplateFor = function wrappedTemplateFor(options) {
return this.wrapperFor([this.templateFor(options)]);
}
/* abstract */
;
_proto.templateFor = function templateFor()
/* { cond, truthy, falsy } */
{
// e.g. `{{#if ${cond}}}${truthy}{{else}}${falsy}{{/if}}`
throw new Error('Not implemented: `templateFor`');
}
/* abstract */
;
_proto.renderValues = function renderValues()
/* ...values */
{
throw new Error('Not implemented: `renderValues`');
};
(0, _emberBabel.createClass)(AbstractConditionalsTest, [{
key: "truthyValue",
get: function () {
return true;
}
}, {
key: "falsyValue",
get: function () {
return false;
}
}]);
return AbstractConditionalsTest;
}(_internalTestHelpers.RenderingTestCase);
var AbstractGenerator =
/*#__PURE__*/
function () {
function AbstractGenerator(cases) {
this.cases = cases;
}
/* abstract */
var _proto2 = AbstractGenerator.prototype;
_proto2.generate = function generate()
/* value, idx */
{
throw new Error('Not implemented: `generate`');
};
return AbstractGenerator;
}();
/*
The test cases in this file generally follow the following pattern:
1. Render with [ truthy, ...(other truthy variations), falsy, ...(other falsy variations) ]
2. No-op rerender
3. Make all of them falsy (through interior mutation)
4. Make all of them truthy (through interior mutation, sometimes with some slight variations)
5. Reset them to their original values (through replacement)
*/
var TruthyGenerator =
/*#__PURE__*/
function (_AbstractGenerator) {
(0, _emberBabel.inheritsLoose)(TruthyGenerator, _AbstractGenerator);
function TruthyGenerator() {
return _AbstractGenerator.apply(this, arguments) || this;
}
var _proto3 = TruthyGenerator.prototype;
_proto3.generate = function generate(value, idx) {
var _ref;
return _ref = {}, _ref["@test it should consider " + JSON.stringify(value) + " truthy [" + idx + "]"] = function () {
var _this = this;
this.renderValues(value);
this.assertText('T1');
(0, _internalTestHelpers.runTask)(function () {
return _this.rerender();
});
this.assertText('T1');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'cond1', _this.falsyValue);
});
this.assertText('F1');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this.context, 'cond1', value);
});
this.assertText('T1');
}, _ref;
};
return TruthyGenerator;
}(AbstractGenerator);
_exports.TruthyGenerator = TruthyGenerator;
var FalsyGenerator =
/*#__PURE__*/
function (_AbstractGenerator2) {
(0, _emberBabel.inheritsLoose)(FalsyGenerator, _AbstractGenerator2);
function FalsyGenerator() {
return _AbstractGenerator2.apply(this, arguments) || this;
}
var _proto4 = FalsyGenerator.prototype;
_proto4.generate = function generate(value, idx) {
var _ref2;
return _ref2 = {}, _ref2["@test it should consider " + JSON.stringify(value) + " falsy [" + idx + "]"] = function () {
var _this2 = this;
this.renderValues(value);
this.assertText('F1');
(0, _internalTestHelpers.runTask)(function () {
return _this2.rerender();
});
this.assertText('F1');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'cond1', _this2.truthyValue);
});
this.assertText('T1');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this2.context, 'cond1', value);
});
this.assertText('F1');
}, _ref2;
};
return FalsyGenerator;
}(AbstractGenerator);
_exports.FalsyGenerator = FalsyGenerator;
var StableTruthyGenerator =
/*#__PURE__*/
function (_TruthyGenerator) {
(0, _emberBabel.inheritsLoose)(StableTruthyGenerator, _TruthyGenerator);
function StableTruthyGenerator() {
return _TruthyGenerator.apply(this, arguments) || this;
}
var _proto5 = StableTruthyGenerator.prototype;
_proto5.generate = function generate(value, idx) {
var _assign;
return (0, _polyfills.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 _this3 = this;
this.renderValues(value);
this.assertText('T1');
this.takeSnapshot();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'cond1', _this3.truthyValue);
});
this.assertText('T1');
this.assertInvariants();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this3.context, 'cond1', value);
});
this.assertText('T1');
this.assertInvariants();
}, _assign));
};
return StableTruthyGenerator;
}(TruthyGenerator);
_exports.StableTruthyGenerator = StableTruthyGenerator;
var StableFalsyGenerator =
/*#__PURE__*/
function (_FalsyGenerator) {
(0, _emberBabel.inheritsLoose)(StableFalsyGenerator, _FalsyGenerator);
function StableFalsyGenerator() {
return _FalsyGenerator.apply(this, arguments) || this;
}
var _proto6 = StableFalsyGenerator.prototype;
_proto6.generate = function generate(value, idx) {
var _assign2;
return (0, _polyfills.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 _this4 = this;
this.renderValues(value);
this.assertText('F1');
this.takeSnapshot();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'cond1', _this4.falsyValue);
});
this.assertText('F1');
this.assertInvariants();
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this4.context, 'cond1', value);
});
this.assertText('F1');
this.assertInvariants();
}, _assign2));
};
return StableFalsyGenerator;
}(FalsyGenerator);
_exports.StableFalsyGenerator = StableFalsyGenerator;
var ObjectProxyGenerator =
/*#__PURE__*/
function (_AbstractGenerator3) {
(0, _emberBabel.inheritsLoose)(ObjectProxyGenerator, _AbstractGenerator3);
function ObjectProxyGenerator() {
return _AbstractGenerator3.apply(this, arguments) || this;
}
var _proto7 = ObjectProxyGenerator.prototype;
_proto7.generate = function generate(value, idx) {
// This is inconsistent with our usual to-bool policy, but the current proxy implementation
// simply uses !!content to determine truthiness
if (value) {
var _ref3;
return _ref3 = {}, _ref3["@test it should consider an object proxy with `" + JSON.stringify(value) + "` truthy [" + idx + "]"] = function () {
var _this5 = this;
this.renderValues(_runtime.ObjectProxy.create({
content: value
}));
this.assertText('T1');
(0, _internalTestHelpers.runTask)(function () {
return _this5.rerender();
});
this.assertText('T1');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'cond1.content', _this5.falsyValue);
});
this.assertText('F1');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this5.context, 'cond1', _runtime.ObjectProxy.create({
content: value
}));
});
this.assertText('T1');
}, _ref3;
} else {
var _ref4;
return _ref4 = {}, _ref4["@test it should consider an object proxy with `" + JSON.stringify(value) + "` falsy [" + idx + "]"] = function () {
var _this6 = this;
this.renderValues(_runtime.ObjectProxy.create({
content: value
}));
this.assertText('F1');
(0, _internalTestHelpers.runTask)(function () {
return _this6.rerender();
});
this.assertText('F1');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'cond1.content', _this6.truthyValue);
});
this.assertText('T1');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this6.context, 'cond1', _runtime.ObjectProxy.create({
content: value
}));
});
this.assertText('F1');
}, _ref4;
}
};
return ObjectProxyGenerator;
}(AbstractGenerator); // Testing behaviors shared across all conditionals, i.e. {{#if}}, {{#unless}},
// {{#with}}, {{#each}}, {{#each-in}}, (if) and (unless)
var BasicConditionalsTest =
/*#__PURE__*/
function (_AbstractConditionals) {
(0, _emberBabel.inheritsLoose)(BasicConditionalsTest, _AbstractConditionals);
function BasicConditionalsTest() {
return _AbstractConditionals.apply(this, arguments) || this;
}
var _proto8 = BasicConditionalsTest.prototype;
_proto8['@test it renders the corresponding block based on the conditional'] = function testItRendersTheCorrespondingBlockBasedOnTheConditional() {
var _this7 = this;
this.renderValues(this.truthyValue, this.falsyValue);
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
return _this7.rerender();
});
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this7.context, 'cond1', _this7.falsyValue);
});
this.assertText('F1F2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this7.context, 'cond1', _this7.truthyValue);
(0, _metal.set)(_this7.context, 'cond2', _this7.truthyValue);
});
this.assertText('T1T2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this7.context, 'cond1', _this7.truthyValue);
(0, _metal.set)(_this7.context, 'cond2', _this7.falsyValue);
});
this.assertText('T1F2');
};
return BasicConditionalsTest;
}(AbstractConditionalsTest); // Testing behaviors related to ember objects, object proxies, etc
_exports.BasicConditionalsTest = BasicConditionalsTest;
var ObjectTestCases = (_ObjectTestCases = {}, _ObjectTestCases['@test it considers object proxies without content falsy'] = function () {
var _this8 = this;
this.renderValues(_runtime.ObjectProxy.create({
content: {}
}), _runtime.ObjectProxy.create({
content: _runtime.Object.create()
}), _runtime.ObjectProxy.create({
content: null
}));
this.assertText('T1T2F3');
(0, _internalTestHelpers.runTask)(function () {
return _this8.rerender();
});
this.assertText('T1T2F3');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this8.context, 'cond1.content', null);
(0, _metal.set)(_this8.context, 'cond2.content', null);
});
this.assertText('F1F2F3');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this8.context, 'cond1.content', _runtime.Object.create());
(0, _metal.set)(_this8.context, 'cond2.content', {});
(0, _metal.set)(_this8.context, 'cond3.content', {
foo: 'bar'
});
});
this.assertText('T1T2T3');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this8.context, 'cond1', _runtime.ObjectProxy.create({
content: {}
}));
(0, _metal.set)(_this8.context, 'cond2', _runtime.ObjectProxy.create({
content: _runtime.Object.create()
}));
(0, _metal.set)(_this8.context, 'cond3', _runtime.ObjectProxy.create({
content: null
}));
});
this.assertText('T1T2F3');
}, _ObjectTestCases); // Testing behaviors related to arrays and array proxies
_exports.ObjectTestCases = ObjectTestCases;
var ArrayTestCases = (_ArrayTestCases = {}, _ArrayTestCases['@test it considers empty arrays falsy'] = function () {
var _this9 = this;
this.renderValues((0, _runtime.A)(['hello']), (0, _runtime.A)());
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
return _this9.rerender();
});
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
return (0, _runtime.removeAt)((0, _metal.get)(_this9.context, 'cond1'), 0);
});
this.assertText('F1F2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.get)(_this9.context, 'cond1').pushObject('hello');
(0, _metal.get)(_this9.context, 'cond2').pushObjects([1]);
});
this.assertText('T1T2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this9.context, 'cond1', (0, _runtime.A)(['hello']));
(0, _metal.set)(_this9.context, 'cond2', (0, _runtime.A)());
});
this.assertText('T1F2');
}, _ArrayTestCases['@test it considers array proxies without content falsy'] = function () {
var _this10 = this;
this.renderValues(_runtime.ArrayProxy.create({
content: (0, _runtime.A)(['hello'])
}), _runtime.ArrayProxy.create({
content: null
}));
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
return _this10.rerender();
});
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this10.context, 'cond1.content', null);
(0, _metal.set)(_this10.context, 'cond2.content', null);
});
this.assertText('F1F2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this10.context, 'cond1.content', (0, _runtime.A)(['hello']));
(0, _metal.set)(_this10.context, 'cond2.content', (0, _runtime.A)([1]));
});
this.assertText('T1T2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this10.context, 'cond1', _runtime.ArrayProxy.create({
content: (0, _runtime.A)(['hello'])
}));
(0, _metal.set)(_this10.context, 'cond2', _runtime.ArrayProxy.create({
content: null
}));
});
this.assertText('T1F2');
}, _ArrayTestCases['@test it considers array proxies with empty arrays falsy'] = function () {
var _this11 = this;
this.renderValues(_runtime.ArrayProxy.create({
content: (0, _runtime.A)(['hello'])
}), _runtime.ArrayProxy.create({
content: (0, _runtime.A)()
}));
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
return _this11.rerender();
});
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
return (0, _runtime.removeAt)((0, _metal.get)(_this11.context, 'cond1.content'), 0);
});
this.assertText('F1F2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.get)(_this11.context, 'cond1.content').pushObject('hello');
(0, _metal.get)(_this11.context, 'cond2.content').pushObjects([1]);
});
this.assertText('T1T2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this11.context, 'cond1', _runtime.ArrayProxy.create({
content: (0, _runtime.A)(['hello'])
}));
(0, _metal.set)(_this11.context, 'cond2', _runtime.ArrayProxy.create({
content: (0, _runtime.A)()
}));
});
this.assertText('T1F2');
}, _ArrayTestCases);
_exports.ArrayTestCases = ArrayTestCases;
var IfUnlessWithTestCases = [new StableTruthyGenerator([true, ' ', 'hello', 'false', 'null', 'undefined', 1, ['hello'], (0, _runtime.A)(['hello']), {}, {
foo: 'bar'
}, _runtime.Object.create(), _runtime.Object.create({
foo: 'bar'
}), _runtime.ObjectProxy.create({
content: true
}), Object, function () {}, new String('hello'), new String(''), new Boolean(true), new Boolean(false), new Date()]), new StableFalsyGenerator([false, null, undefined, '', 0, [], (0, _runtime.A)(), _runtime.ObjectProxy.create({
content: undefined
})]), new ObjectProxyGenerator([true, ' ', 'hello', 'false', 'null', 'undefined', 1, ['hello'], (0, _runtime.A)(['hello']), _runtime.ArrayProxy.create({
content: ['hello']
}), _runtime.ArrayProxy.create({
content: []
}), {}, {
foo: 'bar'
}, _runtime.Object.create(), _runtime.Object.create({
foo: 'bar'
}), _runtime.ObjectProxy.create({
content: true
}), _runtime.ObjectProxy.create({
content: undefined
}), new String('hello'), new String(''), new Boolean(true), new Boolean(false), new Date(), false, null, undefined, '', 0, [], (0, _runtime.A)()]), ObjectTestCases, ArrayTestCases]; // Testing behaviors shared across the "toggling" conditionals, i.e. {{#if}},
// {{#unless}}, {{#with}}, {{#each}}, {{#each-in}}, (if) and (unless)
var TogglingConditionalsTest =
/*#__PURE__*/
function (_BasicConditionalsTes) {
(0, _emberBabel.inheritsLoose)(TogglingConditionalsTest, _BasicConditionalsTes);
function TogglingConditionalsTest() {
return _BasicConditionalsTes.apply(this, arguments) || this;
}
return TogglingConditionalsTest;
}(BasicConditionalsTest); // Testing behaviors shared across the (if) and (unless) helpers
_exports.TogglingConditionalsTest = TogglingConditionalsTest;
var TogglingHelperConditionalsTest =
/*#__PURE__*/
function (_TogglingConditionals) {
(0, _emberBabel.inheritsLoose)(TogglingHelperConditionalsTest, _TogglingConditionals);
function TogglingHelperConditionalsTest() {
return _TogglingConditionals.apply(this, arguments) || this;
}
var _proto9 = TogglingHelperConditionalsTest.prototype;
_proto9.renderValues = function renderValues() {
var templates = [];
var context = {};
for (var 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] = i - 1 < 0 || arguments.length <= i - 1 ? undefined : arguments[i - 1];
}
var wrappedTemplate = this.wrapperFor(templates);
this.render(wrappedTemplate, context);
};
_proto9['@test it has access to the outer scope from both templates'] = function testItHasAccessToTheOuterScopeFromBothTemplates() {
var _this12 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this12.rerender();
});
this.assertText('YESNO');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this12.context, 'truthy', 'YASS');
(0, _metal.set)(_this12.context, 'falsy', 'NOPE');
});
this.assertText('YASSNOPE');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this12.context, 'cond1', _this12.falsyValue);
(0, _metal.set)(_this12.context, 'cond2', _this12.truthyValue);
});
this.assertText('NOPEYASS');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this12.context, 'truthy', 'YES');
(0, _metal.set)(_this12.context, 'falsy', 'NO');
(0, _metal.set)(_this12.context, 'cond1', _this12.truthyValue);
(0, _metal.set)(_this12.context, 'cond2', _this12.falsyValue);
});
this.assertText('YESNO');
};
_proto9['@test it does not update when the unbound helper is used'] = function testItDoesNotUpdateWhenTheUnboundHelperIsUsed() {
var _this13 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this13.rerender();
});
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this13.context, 'cond1', _this13.falsyValue);
});
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this13.context, 'cond1', _this13.truthyValue);
(0, _metal.set)(_this13.context, 'cond2', _this13.truthyValue);
});
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this13.context, 'cond1', _this13.truthyValue);
(0, _metal.set)(_this13.context, 'cond2', _this13.falsyValue);
});
this.assertText('T1F2');
};
_proto9['@test evaluation should be lazy'] = function testEvaluationShouldBeLazy(assert) {
var _this14 = this;
var truthyEvaluated;
var falsyEvaluated;
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 _this14.render(template, {
cond: _this14.truthyValue
});
});
this.assertText('T');
withoutEvaluatingFalsy(function () {
return (0, _internalTestHelpers.runTask)(function () {
return _this14.rerender();
});
});
this.assertText('T');
withoutEvaluatingTruthy(function () {
return (0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this14.context, 'cond', _this14.falsyValue);
});
});
this.assertText('F');
withoutEvaluatingTruthy(function () {
return (0, _internalTestHelpers.runTask)(function () {
return _this14.rerender();
});
});
this.assertText('F');
withoutEvaluatingFalsy(function () {
return (0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this14.context, 'cond', _this14.truthyValue);
});
});
this.assertText('T');
};
return TogglingHelperConditionalsTest;
}(TogglingConditionalsTest);
_exports.TogglingHelperConditionalsTest = TogglingHelperConditionalsTest;
var IfUnlessHelperTest =
/*#__PURE__*/
function (_TogglingHelperCondit) {
(0, _emberBabel.inheritsLoose)(IfUnlessHelperTest, _TogglingHelperCondit);
function IfUnlessHelperTest() {
return _TogglingHelperCondit.apply(this, arguments) || this;
}
return IfUnlessHelperTest;
}(TogglingHelperConditionalsTest);
_exports.IfUnlessHelperTest = IfUnlessHelperTest;
_internalTestHelpers.applyMixins.apply(void 0, [IfUnlessHelperTest].concat(IfUnlessWithTestCases)); // Testing behaviors shared across the "toggling" syntatical constructs,
// i.e. {{#if}}, {{#unless}}, {{#with}}, {{#each}} and {{#each-in}}
var TogglingSyntaxConditionalsTest =
/*#__PURE__*/
function (_TogglingConditionals2) {
(0, _emberBabel.inheritsLoose)(TogglingSyntaxConditionalsTest, _TogglingConditionals2);
function TogglingSyntaxConditionalsTest() {
return _TogglingConditionals2.apply(this, arguments) || this;
}
var _proto10 = TogglingSyntaxConditionalsTest.prototype;
_proto10.renderValues = function renderValues() {
var templates = [];
var context = {};
for (var i = 1; i <= arguments.length; i++) {
templates.push(this.templateFor({
cond: "cond" + i,
truthy: "{{t}}" + i,
falsy: "{{f}}" + i
}));
context["cond" + i] = i - 1 < 0 || arguments.length <= i - 1 ? undefined : arguments[i - 1];
}
var wrappedTemplate = this.wrapperFor(templates);
this.render(wrappedTemplate, (0, _polyfills.assign)({
t: 'T',
f: 'F'
}, context));
};
_proto10['@test it does not update when the unbound helper is used'] = function testItDoesNotUpdateWhenTheUnboundHelperIsUsed() {
var _this15 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this15.rerender();
});
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this15.context, 'cond1', _this15.falsyValue);
});
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this15.context, 'cond1', _this15.truthyValue);
(0, _metal.set)(_this15.context, 'cond2', _this15.truthyValue);
});
this.assertText('T1F2');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this15.context, 'cond1', _this15.truthyValue);
(0, _metal.set)(_this15.context, 'cond2', _this15.falsyValue);
});
this.assertText('T1F2');
};
_proto10['@test it has access to the outer scope from both templates'] = function testItHasAccessToTheOuterScopeFromBothTemplates() {
var _this16 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this16.rerender();
});
this.assertText('YESNO');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this16.context, 'truthy', 'YASS');
(0, _metal.set)(_this16.context, 'falsy', 'NOPE');
});
this.assertText('YASSNOPE');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this16.context, 'cond1', _this16.falsyValue);
(0, _metal.set)(_this16.context, 'cond2', _this16.truthyValue);
});
this.assertText('NOPEYASS');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this16.context, 'truthy', 'YES');
(0, _metal.set)(_this16.context, 'falsy', 'NO');
(0, _metal.set)(_this16.context, 'cond1', _this16.truthyValue);
(0, _metal.set)(_this16.context, 'cond2', _this16.falsyValue);
});
this.assertText('YESNO');
};
_proto10['@test it updates correctly when enclosing another conditional'] = function testItUpdatesCorrectlyWhenEnclosingAnotherConditional() {
var _this17 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this17.rerender();
});
this.assertText('T-inner'); // Changes the inner bounds
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this17.context, 'inner', _this17.falsyValue);
});
this.assertText('F-inner'); // Now rerender the outer conditional, which require first clearing its bounds
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this17.context, 'outer', _this17.falsyValue);
});
this.assertText('F-outer');
};
_proto10['@test it updates correctly when enclosing #each'] = function testItUpdatesCorrectlyWhenEnclosingEach() {
var _this18 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this18.rerender();
});
this.assertText('inner-before'); // Changes the inner bounds
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this18.context, 'inner', ['inner-after']);
});
this.assertText('inner-after'); // Now rerender the outer conditional, which require first clearing its bounds
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this18.context, 'outer', _this18.falsyValue);
});
this.assertText('F-outer'); // Reset
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this18.context, 'inner', ['inner-again']);
(0, _metal.set)(_this18.context, 'outer', _this18.truthyValue);
});
this.assertText('inner-again'); // Now clear the inner bounds
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this18.context, 'inner', []);
});
this.assertText(''); // Now rerender the outer conditional, which require first clearing its bounds
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this18.context, 'outer', _this18.falsyValue);
});
this.assertText('F-outer');
};
_proto10['@test it updates correctly when enclosing triple-curlies'] = function testItUpdatesCorrectlyWhenEnclosingTripleCurlies() {
var _this19 = 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');
(0, _internalTestHelpers.runTask)(function () {
return _this19.rerender();
});
this.assertText('inner-before'); // Changes the inner bounds
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this19.context, 'inner', '
inner-after
');
});
this.assertText('inner-after'); // Now rerender the outer conditional, which require first clearing its bounds
(0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this19.context, 'outer', _this19.falsyValue);
});
this.assertText('F-outer');
};
_proto10['@test child conditional should not render children if parent conditional becomes false'] = function testChildConditionalShouldNotRenderChildrenIfParentConditionalBecomesFalse(assert) {
var _this20 = 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('');
(0, _internalTestHelpers.runTask)(function () {
return _this20.rerender();
});
assert.ok(!childCreated);
this.assertText('');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this20.context, 'cond2', _this20.truthyValue);
(0, _metal.set)(_this20.context, 'cond1', _this20.falsyValue);
});
assert.ok(!childCreated);
this.assertText('');
(0, _internalTestHelpers.runTask)(function () {
(0, _metal.set)(_this20.context, 'cond2', _this20.falsyValue);
(0, _metal.set)(_this20.context, 'cond1', _this20.truthyValue);
});
assert.ok(!childCreated);
this.assertText('');
};
_proto10['@test evaluation should be lazy'] = function testEvaluationShouldBeLazy(assert) {
var _this21 = this;
var truthyEvaluated;
var falsyEvaluated;
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 _this21.render(template, {
cond: _this21.truthyValue
});
});
this.assertText('T');
withoutEvaluatingFalsy(function () {
return (0, _internalTestHelpers.runTask)(function () {
return _this21.rerender();
});
});
this.assertText('T');
withoutEvaluatingTruthy(function () {
return (0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this21.context, 'cond', _this21.falsyValue);
});
});
this.assertText('F');
withoutEvaluatingTruthy(function () {
return (0, _internalTestHelpers.runTask)(function () {
return _this21.rerender();
});
});
this.assertText('F');
withoutEvaluatingFalsy(function () {
return (0, _internalTestHelpers.runTask)(function () {
return (0, _metal.set)(_this21.context, 'cond', _this21.truthyValue);
});
});
this.assertText('T');
};
return TogglingSyntaxConditionalsTest;
}(TogglingConditionalsTest);
_exports.TogglingSyntaxConditionalsTest = TogglingSyntaxConditionalsTest;
var IfUnlessWithSyntaxTest =
/*#__PURE__*/
function (_TogglingSyntaxCondit) {
(0, _emberBabel.inheritsLoose)(IfUnlessWithSyntaxTest, _TogglingSyntaxCondit);
function IfUnlessWithSyntaxTest() {
return _TogglingSyntaxCondit.apply(this, arguments) || this;
}
return IfUnlessWithSyntaxTest;
}(TogglingSyntaxConditionalsTest);
_exports.IfUnlessWithSyntaxTest = IfUnlessWithSyntaxTest;
_internalTestHelpers.applyMixins.apply(void 0, [IfUnlessWithSyntaxTest].concat(IfUnlessWithTestCases));
});
enifed("@ember/-internals/glimmer/tests/utils/string-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/glimmer/tests/utils/helpers"], function (_emberBabel, _internalTestHelpers, _helpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('SafeString',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test htmlSafe should return an instance of SafeString'] = function testHtmlSafeShouldReturnAnInstanceOfSafeString() {
var safeString = (0, _helpers.htmlSafe)('you need to be more bold');
this.assert.ok(safeString instanceof _helpers.SafeString, 'should be a SafeString');
};
_proto['@test htmlSafe should return an empty string for null'] = function testHtmlSafeShouldReturnAnEmptyStringForNull() {
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');
};
_proto['@test htmlSafe should return an instance of SafeString'] = function testHtmlSafeShouldReturnAnInstanceOfSafeString() {
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;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('SafeString isHTMLSafe',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test isHTMLSafe should detect SafeString'] = function testIsHTMLSafeShouldDetectSafeString() {
var safeString = (0, _helpers.htmlSafe)('Emphasize the important things.');
this.assert.ok((0, _helpers.isHTMLSafe)(safeString));
};
_proto2['@test isHTMLSafe should not detect SafeString on primatives'] = function testIsHTMLSafeShouldNotDetectSafeStringOnPrimatives() {
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;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/meta/tests/listeners_test", ["ember-babel", "internal-test-helpers", "@ember/-internals/meta"], function (_emberBabel, _internalTestHelpers, _meta) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember.meta listeners',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test basics'] = function testBasics(assert) {
var t = {};
var m = (0, _meta.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);
};
_proto['@test inheritance'] = function testInheritance(assert) {
var target = {};
var parent = {};
var parentMeta = (0, _meta.meta)(parent);
parentMeta.addToListeners('hello', target, 'm', 0);
var child = Object.create(parent);
var m = (0, _meta.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);
};
_proto['@test deduplication'] = function testDeduplication(assert) {
var t = {};
var m = (0, _meta.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);
};
_proto['@test parent caching'] = function testParentCaching(assert) {
_meta.counters.flattenedListenersCalls = 0;
_meta.counters.parentListenersUsed = 0;
var Class = function Class() {};
var classMeta = (0, _meta.meta)(Class.prototype);
classMeta.addToListeners('hello', null, 'm', 0);
var instance = new Class();
var m = (0, _meta.meta)(instance);
var matching = m.matchingListeners('hello');
assert.equal(matching.length, 3);
assert.equal(_meta.counters.flattenedListenersCalls, 2);
assert.equal(_meta.counters.parentListenersUsed, 1);
matching = m.matchingListeners('hello');
assert.equal(matching.length, 3);
assert.equal(_meta.counters.flattenedListenersCalls, 3);
assert.equal(_meta.counters.parentListenersUsed, 1);
};
_proto['@test parent cache invalidation'] = function testParentCacheInvalidation(assert) {
_meta.counters.flattenedListenersCalls = 0;
_meta.counters.parentListenersUsed = 0;
_meta.counters.listenersInherited = 0;
var Class = function Class() {};
var classMeta = (0, _meta.meta)(Class.prototype);
classMeta.addToListeners('hello', null, 'm', 0);
var instance = new Class();
var m = (0, _meta.meta)(instance);
var matching = m.matchingListeners('hello');
assert.equal(matching.length, 3);
assert.equal(_meta.counters.flattenedListenersCalls, 2);
assert.equal(_meta.counters.parentListenersUsed, 1);
assert.equal(_meta.counters.listenersInherited, 0);
m.addToListeners('hello', null, 'm2');
matching = m.matchingListeners('hello');
assert.equal(matching.length, 6);
assert.equal(_meta.counters.flattenedListenersCalls, 4);
assert.equal(_meta.counters.parentListenersUsed, 1);
assert.equal(_meta.counters.listenersInherited, 1);
};
_proto['@test reopen after flatten'] = function testReopenAfterFlatten(assert) {
// Ensure counter is zeroed
_meta.counters.reopensAfterFlatten = 0;
var Class1 = function Class1() {};
var class1Meta = (0, _meta.meta)(Class1.prototype);
class1Meta.addToListeners('hello', null, 'm', 0);
var instance1 = new Class1();
var m1 = (0, _meta.meta)(instance1);
var Class2 = function Class2() {};
var class2Meta = (0, _meta.meta)(Class2.prototype);
class2Meta.addToListeners('hello', null, 'm', 0);
var instance2 = new Class2();
var m2 = (0, _meta.meta)(instance2);
m1.matchingListeners('hello');
m2.matchingListeners('hello');
assert.equal(_meta.counters.reopensAfterFlatten, 0, 'no reopen calls yet');
m1.addToListeners('world', null, 'm', 0);
m2.addToListeners('world', null, 'm', 0);
m1.matchingListeners('world');
m2.matchingListeners('world');
assert.equal(_meta.counters.reopensAfterFlatten, 1, 'reopen calls after invalidating parent cache');
m1.addToListeners('world', null, 'm', 0);
m2.addToListeners('world', null, 'm', 0);
m1.matchingListeners('world');
m2.matchingListeners('world');
assert.equal(_meta.counters.reopensAfterFlatten, 1, 'no reopen calls after mutating leaf nodes');
class1Meta.removeFromListeners('hello', null, 'm');
class2Meta.removeFromListeners('hello', null, 'm');
m1.matchingListeners('hello');
m2.matchingListeners('hello');
assert.equal(_meta.counters.reopensAfterFlatten, 2, 'one reopen call after mutating parents');
class1Meta.addToListeners('hello', null, 'm', 0);
m1.matchingListeners('hello');
class2Meta.addToListeners('hello', null, 'm', 0);
m2.matchingListeners('hello');
assert.equal(_meta.counters.reopensAfterFlatten, 3, 'one reopen call after mutating parents and flattening out of order');
};
_proto['@test REMOVE_ALL does not interfere with future adds'] = function testREMOVE_ALLDoesNotInterfereWithFutureAdds(assert) {
expectDeprecation(function () {
var t = {};
var m = (0, _meta.meta)({});
m.addToListeners('hello', t, 'm', 0);
var matching = m.matchingListeners('hello');
assert.equal(matching.length, 3);
assert.equal(matching[0], t); // Remove all listeners
m.removeAllListeners('hello');
matching = m.matchingListeners('hello');
assert.equal(matching, undefined);
m.addToListeners('hello', t, 'm', 0);
matching = m.matchingListeners('hello'); // listener was added back successfully
assert.equal(matching.length, 3);
assert.equal(matching[0], t);
});
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/meta/tests/meta_test", ["ember-babel", "internal-test-helpers", "@ember/-internals/meta"], function (_emberBabel, _internalTestHelpers, _meta) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember.meta',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should return the same hash for an object'] = function testShouldReturnTheSameHashForAnObject(assert) {
var obj = {};
(0, _meta.meta)(obj).foo = 'bar';
assert.equal((0, _meta.meta)(obj).foo, 'bar', 'returns same hash with multiple calls to Ember.meta()');
};
_proto['@test meta is not enumerable'] = function testMetaIsNotEnumerable(assert) {
var proto, obj, props, prop;
proto = {
foo: 'bar'
};
(0, _meta.meta)(proto);
obj = Object.create(proto);
(0, _meta.meta)(obj);
obj.bar = 'baz';
props = [];
for (prop in obj) {
props.push(prop);
}
assert.deepEqual(props.sort(), ['bar', 'foo']);
if (typeof JSON !== 'undefined' && 'stringify' in JSON) {
try {
JSON.stringify(obj);
} catch (e) {
assert.ok(false, 'meta should not fail JSON.stringify');
}
}
};
_proto['@test meta.writeWatching issues useful error after destroy'] = function testMetaWriteWatchingIssuesUsefulErrorAfterDestroy() {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _meta.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writeWatching('hello', 1);
}, 'Cannot update watchers for `hello` on `` after it has been destroyed.');
};
_proto['@test meta.writableTag issues useful error after destroy'] = function testMetaWritableTagIssuesUsefulErrorAfterDestroy() {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _meta.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writableTag(function () {});
}, 'Cannot create a new tag for `` after it has been destroyed.');
};
_proto['@test meta.writableChainWatchers issues useful error after destroy'] = function testMetaWritableChainWatchersIssuesUsefulErrorAfterDestroy() {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _meta.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writableChainWatchers(function () {});
}, 'Cannot create a new chain watcher for `` after it has been destroyed.');
};
_proto['@test meta.writableChains issues useful error after destroy'] = function testMetaWritableChainsIssuesUsefulErrorAfterDestroy() {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _meta.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writableChains(function () {});
}, 'Cannot create a new chains for `` after it has been destroyed.');
};
_proto['@test meta.writeValues issues useful error after destroy'] = function testMetaWriteValuesIssuesUsefulErrorAfterDestroy() {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _meta.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writeValues('derp', 'ohai');
}, 'Cannot set the value of `derp` on `` after it has been destroyed.');
};
_proto['@test meta.writeDeps issues useful error after destroy'] = function testMetaWriteDepsIssuesUsefulErrorAfterDestroy() {
var target = {
toString: function () {
return '';
}
};
var targetMeta = (0, _meta.meta)(target);
targetMeta.destroy();
expectAssertion(function () {
targetMeta.writeDeps('derp', 'ohai', 1);
}, 'Cannot modify dependent keys for `ohai` on `` after it has been destroyed.');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/accessors/get_path_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
var obj;
(0, _internalTestHelpers.moduleFor)('get with path',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
var _this;
_this = _AbstractTestCase.call(this) || this;
obj = {
foo: {
bar: {
baz: {
biff: 'BIFF'
}
}
},
foothis: {
bar: {
baz: {
biff: 'BIFF'
}
}
},
falseValue: false,
emptyString: '',
Wuz: {
nar: 'foo'
},
nullValue: null
};
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
obj = undefined;
} // ..........................................................
// LOCAL PATHS
//
;
_proto['@test [obj, foo] -> obj.foo'] = function testObjFooObjFoo(assert) {
assert.deepEqual((0, _metal.get)(obj, 'foo'), obj.foo);
};
_proto['@test [obj, foo.bar] -> obj.foo.bar'] = function testObjFooBarObjFooBar(assert) {
assert.deepEqual((0, _metal.get)(obj, 'foo.bar'), obj.foo.bar);
};
_proto['@test [obj, foothis.bar] -> obj.foothis.bar'] = function testObjFoothisBarObjFoothisBar(assert) {
assert.deepEqual((0, _metal.get)(obj, 'foothis.bar'), obj.foothis.bar);
};
_proto['@test [obj, falseValue.notDefined] -> (undefined)'] = function testObjFalseValueNotDefinedUndefined(assert) {
assert.strictEqual((0, _metal.get)(obj, 'falseValue.notDefined'), undefined);
};
_proto['@test [obj, emptyString.length] -> 0'] = function testObjEmptyStringLength0(assert) {
assert.strictEqual((0, _metal.get)(obj, 'emptyString.length'), 0);
};
_proto['@test [obj, nullValue.notDefined] -> (undefined)'] = function testObjNullValueNotDefinedUndefined(assert) {
assert.strictEqual((0, _metal.get)(obj, 'nullValue.notDefined'), undefined);
} // ..........................................................
// GLOBAL PATHS TREATED LOCAL WITH GET
//
;
_proto['@test [obj, Wuz] -> obj.Wuz'] = function testObjWuzObjWuz(assert) {
assert.deepEqual((0, _metal.get)(obj, 'Wuz'), obj.Wuz);
};
_proto['@test [obj, Wuz.nar] -> obj.Wuz.nar'] = function testObjWuzNarObjWuzNar(assert) {
assert.deepEqual((0, _metal.get)(obj, 'Wuz.nar'), obj.Wuz.nar);
};
_proto['@test [obj, Foo] -> (undefined)'] = function testObjFooUndefined(assert) {
assert.strictEqual((0, _metal.get)(obj, 'Foo'), undefined);
};
_proto['@test [obj, Foo.bar] -> (undefined)'] = function testObjFooBarUndefined(assert) {
assert.strictEqual((0, _metal.get)(obj, 'Foo.bar'), undefined);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/accessors/get_properties_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('getProperties',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test can retrieve a hash of properties from an object via an argument list or array of property names'] = function testCanRetrieveAHashOfPropertiesFromAnObjectViaAnArgumentListOrArrayOfPropertyNames(assert) {
var obj = {
firstName: 'Steve',
lastName: 'Jobs',
companyName: 'Apple, Inc.'
};
assert.deepEqual((0, _metal.getProperties)(obj, 'firstName', 'lastName'), {
firstName: 'Steve',
lastName: 'Jobs'
});
assert.deepEqual((0, _metal.getProperties)(obj, 'firstName', 'lastName'), {
firstName: 'Steve',
lastName: 'Jobs'
});
assert.deepEqual((0, _metal.getProperties)(obj, 'lastName'), {
lastName: 'Jobs'
});
assert.deepEqual((0, _metal.getProperties)(obj), {});
assert.deepEqual((0, _metal.getProperties)(obj, ['firstName', 'lastName']), {
firstName: 'Steve',
lastName: 'Jobs'
});
assert.deepEqual((0, _metal.getProperties)(obj, ['firstName']), {
firstName: 'Steve'
});
assert.deepEqual((0, _metal.getProperties)(obj, []), {});
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/accessors/get_test", ["ember-babel", "@ember/-internals/environment", "@ember/-internals/runtime", "@ember/-internals/metal", "internal-test-helpers", "@ember/runloop"], function (_emberBabel, _environment, _runtime, _metal, _internalTestHelpers, _runloop) {
"use strict";
function aget(x, y) {
return x[y];
}
(0, _internalTestHelpers.moduleFor)('get',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should get arbitrary properties on an object'] = function testShouldGetArbitraryPropertiesOnAnObject(assert) {
var obj = {
string: 'string',
number: 23,
boolTrue: true,
boolFalse: false,
nullValue: null
};
for (var key in obj) {
if (!obj.hasOwnProperty(key)) {
continue;
}
assert.equal((0, _metal.get)(obj, key), obj[key], key);
}
};
_proto['@test should retrieve a number key on an object'] = function testShouldRetrieveANumberKeyOnAnObject(assert) {
var obj = {
1: 'first'
};
assert.equal((0, _metal.get)(obj, 1), 'first');
};
_proto['@test should retrieve an array index'] = function testShouldRetrieveAnArrayIndex(assert) {
var arr = ['first', 'second'];
assert.equal((0, _metal.get)(arr, 0), 'first');
assert.equal((0, _metal.get)(arr, 1), 'second');
};
_proto['@test should retrieve an empty string key on an object'] = function testShouldRetrieveAnEmptyStringKeyOnAnObject(assert) {
var obj = {
'': 'empty-string'
};
assert.equal((0, _metal.get)(obj, ''), 'empty-string');
};
_proto['@test should return undefined when passed an empty string if that key does not exist on an object'] = function testShouldReturnUndefinedWhenPassedAnEmptyStringIfThatKeyDoesNotExistOnAnObject(assert) {
var obj = {
tomster: true
};
assert.equal((0, _metal.get)(obj, ''), undefined);
};
_proto['@test should not access a property more than once'] = function testShouldNotAccessAPropertyMoreThanOnce(assert) {
var count = 0;
var obj = {
get id() {
return ++count;
}
};
(0, _metal.get)(obj, 'id');
assert.equal(count, 1);
};
_proto['@test should call unknownProperty on watched values if the value is undefined using getFromEmberMetal()/set()'] = function testShouldCallUnknownPropertyOnWatchedValuesIfTheValueIsUndefinedUsingGetFromEmberMetalSet(assert) {
var obj = {
unknownProperty: function (key) {
assert.equal(key, 'foo', 'should pass key');
return 'FOO';
}
};
assert.equal((0, _metal.get)(obj, 'foo'), 'FOO', 'should return value from unknown');
};
_proto['@test should call unknownProperty on watched values if the value is undefined using accessors'] = function testShouldCallUnknownPropertyOnWatchedValuesIfTheValueIsUndefinedUsingAccessors(assert) {
if (_environment.ENV.USES_ACCESSORS) {
var obj = {
unknownProperty: function (key) {
assert.equal(key, 'foo', 'should pass key');
return 'FOO';
}
};
assert.equal(aget(obj, 'foo'), 'FOO', 'should return value from unknown');
} else {
assert.ok('SKIPPING ACCESSORS');
}
};
_proto['@test get works with paths correctly'] = function testGetWorksWithPathsCorrectly(assert) {
var func = function () {};
func.bar = 'awesome';
var destroyedObj = _runtime.Object.create({
bar: 'great'
});
(0, _runloop.run)(function () {
return destroyedObj.destroy();
});
assert.equal((0, _metal.get)({
foo: null
}, 'foo.bar'), undefined);
assert.equal((0, _metal.get)({
foo: {
bar: 'hello'
}
}, 'foo.bar.length'), 5);
assert.equal((0, _metal.get)({
foo: func
}, 'foo.bar'), 'awesome');
assert.equal((0, _metal.get)({
foo: func
}, 'foo.bar.length'), 7);
assert.equal((0, _metal.get)({}, 'foo.bar.length'), undefined);
assert.equal((0, _metal.get)(function () {}, 'foo.bar.length'), undefined);
assert.equal((0, _metal.get)('', 'foo.bar.length'), undefined);
assert.equal((0, _metal.get)({
foo: destroyedObj
}, 'foo.bar'), undefined);
};
_proto['@test warn on attempts to call get with no arguments'] = function testWarnOnAttemptsToCallGetWithNoArguments() {
expectAssertion(function () {
(0, _metal.get)('aProperty');
}, /Get must be called with two arguments;/i);
};
_proto['@test warn on attempts to call get with only one argument'] = function testWarnOnAttemptsToCallGetWithOnlyOneArgument() {
expectAssertion(function () {
(0, _metal.get)('aProperty');
}, /Get must be called with two arguments;/i);
};
_proto['@test warn on attempts to call get with more then two arguments'] = function testWarnOnAttemptsToCallGetWithMoreThenTwoArguments() {
expectAssertion(function () {
(0, _metal.get)({}, 'aProperty', true);
}, /Get must be called with two arguments;/i);
};
_proto['@test warn on attempts to get a property of undefined'] = function testWarnOnAttemptsToGetAPropertyOfUndefined() {
expectAssertion(function () {
(0, _metal.get)(undefined, 'aProperty');
}, /Cannot call get with 'aProperty' on an undefined object/i);
};
_proto['@test warn on attempts to get a property path of undefined'] = function testWarnOnAttemptsToGetAPropertyPathOfUndefined() {
expectAssertion(function () {
(0, _metal.get)(undefined, 'aProperty.on.aPath');
}, /Cannot call get with 'aProperty.on.aPath' on an undefined object/);
};
_proto['@test warn on attempts to get a property of null'] = function testWarnOnAttemptsToGetAPropertyOfNull() {
expectAssertion(function () {
(0, _metal.get)(null, 'aProperty');
}, /Cannot call get with 'aProperty' on an undefined object/);
};
_proto['@test warn on attempts to get a property path of null'] = function testWarnOnAttemptsToGetAPropertyPathOfNull() {
expectAssertion(function () {
(0, _metal.get)(null, 'aProperty.on.aPath');
}, /Cannot call get with 'aProperty.on.aPath' on an undefined object/);
};
_proto['@test warn on attempts to use get with an unsupported property path'] = function testWarnOnAttemptsToUseGetWithAnUnsupportedPropertyPath() {
var obj = {};
expectAssertion(function () {
return (0, _metal.get)(obj, null);
}, /The key provided to get must be a string or number, you passed null/);
expectAssertion(function () {
return (0, _metal.get)(obj, NaN);
}, /The key provided to get must be a string or number, you passed NaN/);
expectAssertion(function () {
return (0, _metal.get)(obj, undefined);
}, /The key provided to get must be a string or number, you passed undefined/);
expectAssertion(function () {
return (0, _metal.get)(obj, false);
}, /The key provided to get must be a string or number, you passed false/);
} // ..........................................................
// BUGS
//
;
_proto['@test (regression) watched properties on unmodified inherited objects should still return their original value'] = function testRegressionWatchedPropertiesOnUnmodifiedInheritedObjectsShouldStillReturnTheirOriginalValue(assert) {
var MyMixin = _metal.Mixin.create({
someProperty: 'foo',
propertyDidChange: (0, _metal.observer)('someProperty', function () {})
});
var baseObject = MyMixin.apply({});
var theRealObject = Object.create(baseObject);
assert.equal((0, _metal.get)(theRealObject, 'someProperty'), 'foo', 'should return the set value, not false');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('getWithDefault',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test should get arbitrary properties on an object'] = function testShouldGetArbitraryPropertiesOnAnObject(assert) {
var obj = {
string: 'string',
number: 23,
boolTrue: true,
boolFalse: false,
nullValue: null
};
for (var key in obj) {
if (!obj.hasOwnProperty(key)) {
continue;
}
assert.equal((0, _metal.getWithDefault)(obj, key, 'fail'), obj[key], key);
}
obj = {
undef: undefined
};
assert.equal((0, _metal.getWithDefault)(obj, 'undef', 'default'), 'default', 'explicit undefined retrieves the default');
assert.equal((0, _metal.getWithDefault)(obj, 'not-present', 'default'), 'default', 'non-present key retrieves the default');
};
_proto2['@test should call unknownProperty if defined and value is undefined'] = function testShouldCallUnknownPropertyIfDefinedAndValueIsUndefined(assert) {
var obj = {
count: 0,
unknownProperty: function (key) {
assert.equal(key, 'foo', 'should pass key');
this.count++;
return 'FOO';
}
};
assert.equal((0, _metal.get)(obj, 'foo'), 'FOO', 'should return value from unknown');
assert.equal(obj.count, 1, 'should have invoked');
};
_proto2['@test if unknownProperty is present, it is called using getFromEmberMetal()/set()'] = function testIfUnknownPropertyIsPresentItIsCalledUsingGetFromEmberMetalSet(assert) {
var obj = {
unknownProperty: function (key) {
if (key === 'foo') {
assert.equal(key, 'foo', 'should pass key');
return 'FOO';
}
}
};
assert.equal((0, _metal.getWithDefault)(obj, 'foo', 'fail'), 'FOO', 'should return value from unknownProperty');
assert.equal((0, _metal.getWithDefault)(obj, 'bar', 'default'), 'default', 'should convert undefined from unknownProperty into default');
};
_proto2['@test if unknownProperty is present, it is called using accessors'] = function testIfUnknownPropertyIsPresentItIsCalledUsingAccessors(assert) {
if (_environment.ENV.USES_ACCESSORS) {
var obj = {
unknownProperty: function (key) {
if (key === 'foo') {
assert.equal(key, 'foo', 'should pass key');
return 'FOO';
}
}
};
assert.equal(aget(obj, 'foo', 'fail'), 'FOO', 'should return value from unknownProperty');
assert.equal(aget(obj, 'bar', 'default'), 'default', 'should convert undefined from unknownProperty into default');
} else {
assert.ok('SKIPPING ACCESSORS');
}
} // ..........................................................
// BUGS
//
;
_proto2['@test (regression) watched properties on unmodified inherited objects should still return their original value'] = function testRegressionWatchedPropertiesOnUnmodifiedInheritedObjectsShouldStillReturnTheirOriginalValue(assert) {
var MyMixin = _metal.Mixin.create({
someProperty: 'foo',
propertyDidChange: (0, _metal.observer)('someProperty', function () {
/* nothing to do */
})
});
var baseObject = MyMixin.apply({});
var theRealObject = Object.create(baseObject);
assert.equal((0, _metal.getWithDefault)(theRealObject, 'someProperty', 'fail'), 'foo', 'should return the set value, not false');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/accessors/mandatory_setters_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/meta", "internal-test-helpers"], function (_emberBabel, _metal, _meta, _internalTestHelpers) {
"use strict";
function hasMandatorySetter(object, property) {
try {
return Object.getOwnPropertyDescriptor(object, property).set.isMandatorySetter === true;
} catch (e) {
return false;
}
}
function hasMetaValue(object, property) {
return (0, _meta.meta)(object).peekValues(property) !== undefined;
}
if (true
/* DEBUG */
) {
(0, _internalTestHelpers.moduleFor)('mandory-setters',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test does not assert if property is not being watched'] = function testDoesNotAssertIfPropertyIsNotBeingWatched(assert) {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
obj.someProp = 'blastix';
assert.equal((0, _metal.get)(obj, 'someProp'), 'blastix');
};
_proto['@test should not setup mandatory-setter if property is not writable'] = function testShouldNotSetupMandatorySetterIfPropertyIsNotWritable(assert) {
assert.expect(6);
var obj = {};
Object.defineProperty(obj, 'a', {
value: true
});
Object.defineProperty(obj, 'b', {
value: false
});
Object.defineProperty(obj, 'c', {
value: undefined
});
Object.defineProperty(obj, 'd', {
value: undefined,
writable: false
});
Object.defineProperty(obj, 'e', {
value: undefined,
configurable: false
});
Object.defineProperty(obj, 'f', {
value: undefined,
configurable: true
});
(0, _metal.watch)(obj, 'a');
(0, _metal.watch)(obj, 'b');
(0, _metal.watch)(obj, 'c');
(0, _metal.watch)(obj, 'd');
(0, _metal.watch)(obj, 'e');
(0, _metal.watch)(obj, 'f');
assert.ok(!hasMandatorySetter(obj, 'a'), 'mandatory-setter should not be installed');
assert.ok(!hasMandatorySetter(obj, 'b'), 'mandatory-setter should not be installed');
assert.ok(!hasMandatorySetter(obj, 'c'), 'mandatory-setter should not be installed');
assert.ok(!hasMandatorySetter(obj, 'd'), 'mandatory-setter should not be installed');
assert.ok(!hasMandatorySetter(obj, 'e'), 'mandatory-setter should not be installed');
assert.ok(!hasMandatorySetter(obj, 'f'), 'mandatory-setter should not be installed');
};
_proto['@test should not teardown non mandatory-setter descriptor'] = function testShouldNotTeardownNonMandatorySetterDescriptor(assert) {
assert.expect(1);
var obj = {
get a() {
return 'hi';
}
};
(0, _metal.watch)(obj, 'a');
(0, _metal.unwatch)(obj, 'a');
assert.equal(obj.a, 'hi');
};
_proto['@test should not confuse non descriptor watched gets'] = function testShouldNotConfuseNonDescriptorWatchedGets(assert) {
assert.expect(2);
var obj = {
get a() {
return 'hi';
}
};
(0, _metal.watch)(obj, 'a');
assert.equal((0, _metal.get)(obj, 'a'), 'hi');
assert.equal(obj.a, 'hi');
};
_proto['@test should not setup mandatory-setter if setter is already setup on property'] = function testShouldNotSetupMandatorySetterIfSetterIsAlreadySetupOnProperty(assert) {
assert.expect(2);
var obj = {
someProp: null
};
Object.defineProperty(obj, 'someProp', {
get: function () {
return null;
},
set: function (value) {
assert.equal(value, 'foo-bar', 'custom setter was called');
}
});
(0, _metal.watch)(obj, 'someProp');
assert.ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed');
obj.someProp = 'foo-bar';
};
_proto['@test watched ES5 setter should not be smashed by mandatory setter'] = function testWatchedES5SetterShouldNotBeSmashedByMandatorySetter(assert) {
var value;
var obj = {
get foo() {
return value;
},
set foo(_value) {
value = _value;
}
};
(0, _metal.watch)(obj, 'foo');
(0, _metal.set)(obj, 'foo', 2);
assert.equal(value, 2);
};
_proto['@test should not setup mandatory-setter if setter is already setup on property in parent prototype'] = function testShouldNotSetupMandatorySetterIfSetterIsAlreadySetupOnPropertyInParentPrototype(assert) {
assert.expect(2);
function Foo() {}
Object.defineProperty(Foo.prototype, 'someProp', {
get: function () {
return null;
},
set: function (value) {
assert.equal(value, 'foo-bar', 'custom setter was called');
}
});
var obj = new Foo();
(0, _metal.watch)(obj, 'someProp');
assert.ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed');
obj.someProp = 'foo-bar';
};
_proto['@test should not setup mandatory-setter if setter is already setup on property in grandparent prototype'] = function testShouldNotSetupMandatorySetterIfSetterIsAlreadySetupOnPropertyInGrandparentPrototype(assert) {
assert.expect(2);
function Foo() {}
Object.defineProperty(Foo.prototype, 'someProp', {
get: function () {
return null;
},
set: function (value) {
assert.equal(value, 'foo-bar', 'custom setter was called');
}
});
function Bar() {}
Bar.prototype = Object.create(Foo.prototype);
Bar.prototype.constructor = Bar;
var obj = new Bar();
(0, _metal.watch)(obj, 'someProp');
assert.ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed');
obj.someProp = 'foo-bar';
};
_proto['@test should not setup mandatory-setter if setter is already setup on property in great grandparent prototype'] = function testShouldNotSetupMandatorySetterIfSetterIsAlreadySetupOnPropertyInGreatGrandparentPrototype(assert) {
assert.expect(2);
function Foo() {}
Object.defineProperty(Foo.prototype, 'someProp', {
get: function () {
return null;
},
set: function (value) {
assert.equal(value, 'foo-bar', 'custom setter was called');
}
});
function Bar() {}
Bar.prototype = Object.create(Foo.prototype);
Bar.prototype.constructor = Bar;
function Qux() {}
Qux.prototype = Object.create(Bar.prototype);
Qux.prototype.constructor = Qux;
var obj = new Qux();
(0, _metal.watch)(obj, 'someProp');
assert.ok(!hasMandatorySetter(obj, 'someProp'), 'mandatory-setter should not be installed');
obj.someProp = 'foo-bar';
};
_proto['@test should assert if set without set when property is being watched'] = function testShouldAssertIfSetWithoutSetWhenPropertyIsBeingWatched() {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
(0, _metal.watch)(obj, 'someProp');
expectAssertion(function () {
obj.someProp = 'foo-bar';
}, 'You must use set() to set the `someProp` property (of custom-object) to `foo-bar`.');
};
_proto['@test should not assert if set with set when property is being watched'] = function testShouldNotAssertIfSetWithSetWhenPropertyIsBeingWatched(assert) {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
(0, _metal.watch)(obj, 'someProp');
(0, _metal.set)(obj, 'someProp', 'foo-bar');
assert.equal((0, _metal.get)(obj, 'someProp'), 'foo-bar');
};
_proto['@test does not setup mandatory-setter if non-configurable'] = function testDoesNotSetupMandatorySetterIfNonConfigurable(assert) {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
Object.defineProperty(obj, 'someProp', {
configurable: false,
enumerable: true,
value: 'blastix'
});
(0, _metal.watch)(obj, 'someProp');
assert.ok(!hasMandatorySetter(obj, 'someProp'), 'blastix');
};
_proto['@test ensure after watch the property is restored (and the value is no-longer stored in meta) [non-enumerable]'] = function testEnsureAfterWatchThePropertyIsRestoredAndTheValueIsNoLongerStoredInMetaNonEnumerable(assert) {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
Object.defineProperty(obj, 'someProp', {
configurable: true,
enumerable: false,
value: 'blastix'
});
(0, _metal.watch)(obj, 'someProp');
assert.equal(hasMandatorySetter(obj, 'someProp'), true, 'should have a mandatory setter');
var descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
assert.equal(descriptor.enumerable, false, 'property should remain non-enumerable');
assert.equal(descriptor.configurable, true, 'property should remain configurable');
assert.equal(obj.someProp, 'blastix', 'expected value to be the getter');
assert.equal(descriptor.value, undefined, 'expected existing value to NOT remain');
assert.ok(hasMetaValue(obj, 'someProp'), 'someProp is stored in meta.values');
(0, _metal.unwatch)(obj, 'someProp');
assert.ok(!hasMetaValue(obj, 'someProp'), 'someProp is no longer stored in meta.values');
descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
assert.equal(hasMandatorySetter(obj, 'someProp'), false, 'should no longer have a mandatory setter');
assert.equal(descriptor.enumerable, false, 'property should remain non-enumerable');
assert.equal(descriptor.configurable, true, 'property should remain configurable');
assert.equal(obj.someProp, 'blastix', 'expected value to be the getter');
assert.equal(descriptor.value, 'blastix', 'expected existing value to remain');
obj.someProp = 'new value'; // make sure the descriptor remains correct (nothing funky, like a redefined, happened in the setter);
descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
assert.equal(descriptor.enumerable, false, 'property should remain non-enumerable');
assert.equal(descriptor.configurable, true, 'property should remain configurable');
assert.equal(descriptor.value, 'new value', 'expected existing value to NOT remain');
assert.equal(obj.someProp, 'new value', 'expected value to be the getter');
assert.equal(obj.someProp, 'new value');
};
_proto['@test ensure after watch the property is restored (and the value is no-longer stored in meta) [enumerable]'] = function testEnsureAfterWatchThePropertyIsRestoredAndTheValueIsNoLongerStoredInMetaEnumerable(assert) {
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
Object.defineProperty(obj, 'someProp', {
configurable: true,
enumerable: true,
value: 'blastix'
});
(0, _metal.watch)(obj, 'someProp');
assert.equal(hasMandatorySetter(obj, 'someProp'), true, 'should have a mandatory setter');
var descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
assert.equal(descriptor.enumerable, true, 'property should remain enumerable');
assert.equal(descriptor.configurable, true, 'property should remain configurable');
assert.equal(obj.someProp, 'blastix', 'expected value to be the getter');
assert.equal(descriptor.value, undefined, 'expected existing value to NOT remain');
assert.ok(hasMetaValue(obj, 'someProp'), 'someProp is stored in meta.values');
(0, _metal.unwatch)(obj, 'someProp');
assert.ok(!hasMetaValue(obj, 'someProp'), 'someProp is no longer stored in meta.values');
descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
assert.equal(hasMandatorySetter(obj, 'someProp'), false, 'should no longer have a mandatory setter');
assert.equal(descriptor.enumerable, true, 'property should remain enumerable');
assert.equal(descriptor.configurable, true, 'property should remain configurable');
assert.equal(obj.someProp, 'blastix', 'expected value to be the getter');
assert.equal(descriptor.value, 'blastix', 'expected existing value to remain');
obj.someProp = 'new value'; // make sure the descriptor remains correct (nothing funky, like a redefined, happened in the setter);
descriptor = Object.getOwnPropertyDescriptor(obj, 'someProp');
assert.equal(descriptor.enumerable, true, 'property should remain enumerable');
assert.equal(descriptor.configurable, true, 'property should remain configurable');
assert.equal(descriptor.value, 'new value', 'expected existing value to NOT remain');
assert.equal(obj.someProp, 'new value');
};
_proto['@test sets up mandatory-setter if property comes from prototype'] = function testSetsUpMandatorySetterIfPropertyComesFromPrototype(assert) {
assert.expect(2);
var obj = {
someProp: null,
toString: function () {
return 'custom-object';
}
};
var obj2 = Object.create(obj);
(0, _metal.watch)(obj2, 'someProp');
assert.ok(hasMandatorySetter(obj2, 'someProp'), 'mandatory setter has been setup');
expectAssertion(function () {
obj2.someProp = 'foo-bar';
}, 'You must use set() to set the `someProp` property (of custom-object) to `foo-bar`.');
};
_proto['@test inheritance remains live'] = function testInheritanceRemainsLive(assert) {
function Parent() {}
Parent.prototype.food = 'chips';
var child = new Parent();
assert.equal(child.food, 'chips');
(0, _metal.watch)(child, 'food');
assert.equal(child.food, 'chips');
Parent.prototype.food = 'icecreame';
assert.equal(child.food, 'icecreame');
(0, _metal.unwatch)(child, 'food');
assert.equal(child.food, 'icecreame');
Parent.prototype.food = 'chips';
assert.equal(child.food, 'chips');
};
_proto['@test inheritance remains live and preserves this'] = function testInheritanceRemainsLiveAndPreservesThis(assert) {
function Parent(food) {
this._food = food;
}
Object.defineProperty(Parent.prototype, 'food', {
get: function () {
return this._food;
}
});
var child = new Parent('chips');
assert.equal(child.food, 'chips');
(0, _metal.watch)(child, 'food');
assert.equal(child.food, 'chips');
child._food = 'icecreame';
assert.equal(child.food, 'icecreame');
(0, _metal.unwatch)(child, 'food');
assert.equal(child.food, 'icecreame');
var foodDesc = Object.getOwnPropertyDescriptor(Parent.prototype, 'food');
assert.ok(!foodDesc.configurable, 'Parent.prototype.food desc should be non configable');
assert.ok(!foodDesc.enumerable, 'Parent.prototype.food desc should be non enumerable');
assert.equal(foodDesc.get.call({
_food: 'hi'
}), 'hi');
assert.equal(foodDesc.set, undefined);
assert.equal(child.food, 'icecreame');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
}
});
enifed("@ember/-internals/metal/tests/accessors/set_path_test", ["ember-babel", "@ember/-internals/environment", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _environment, _metal, _internalTestHelpers) {
"use strict";
var originalLookup = _environment.context.lookup;
var lookup;
var obj;
function commonSetup() {
_environment.context.lookup = lookup = {};
obj = {
foo: {
bar: {
baz: {
biff: 'BIFF'
}
}
}
};
}
function commonTeardown() {
_environment.context.lookup = originalLookup;
obj = null;
}
(0, _internalTestHelpers.moduleFor)('set with path',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
var _this;
_this = _AbstractTestCase.call(this) || this;
commonSetup();
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
commonTeardown();
};
_proto['@test [Foo, bar] -> Foo.bar'] = function testFooBarFooBar(assert) {
lookup.Foo = {
toString: function () {
return 'Foo';
}
}; // Behave like an Ember.Namespace
(0, _metal.set)(lookup.Foo, 'bar', 'baz');
assert.equal((0, _metal.get)(lookup.Foo, 'bar'), 'baz');
} // ..........................................................
//
// LOCAL PATHS
;
_proto['@test [obj, foo] -> obj.foo'] = function testObjFooObjFoo(assert) {
(0, _metal.set)(obj, 'foo', 'BAM');
assert.equal((0, _metal.get)(obj, 'foo'), 'BAM');
};
_proto['@test [obj, foo.bar] -> obj.foo.bar'] = function testObjFooBarObjFooBar(assert) {
(0, _metal.set)(obj, 'foo.bar', 'BAM');
assert.equal((0, _metal.get)(obj, 'foo.bar'), 'BAM');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('set with path - deprecated',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
var _this2;
_this2 = _AbstractTestCase2.call(this) || this;
commonSetup();
return _this2;
}
var _proto2 = _class2.prototype;
_proto2.teardown = function teardown() {
commonTeardown();
} // ..........................................................
// DEPRECATED
//
;
_proto2['@test [obj, bla.bla] gives a proper exception message'] = function testObjBlaBlaGivesAProperExceptionMessage(assert) {
var exceptionMessage = 'Property set failed: object in path "bla" could not be found.';
try {
(0, _metal.set)(obj, 'bla.bla', 'BAM');
} catch (ex) {
assert.equal(ex.message, exceptionMessage);
}
};
_proto2['@test [obj, foo.baz.bat] -> EXCEPTION'] = function testObjFooBazBatEXCEPTION(assert) {
assert.throws(function () {
return (0, _metal.set)(obj, 'foo.baz.bat', 'BAM');
});
};
_proto2['@test [obj, foo.baz.bat] -> EXCEPTION'] = function testObjFooBazBatEXCEPTION(assert) {
(0, _metal.trySet)(obj, 'foo.baz.bat', 'BAM');
assert.ok(true, 'does not raise');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/accessors/set_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('set',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
(0, _metal.setHasViews)(function () {
return false;
});
};
_proto['@test should set arbitrary properties on an object'] = function testShouldSetArbitraryPropertiesOnAnObject(assert) {
var obj = {
string: 'string',
number: 23,
boolTrue: true,
boolFalse: false,
nullValue: null,
undefinedValue: undefined
};
var newObj = {};
for (var key in obj) {
if (!obj.hasOwnProperty(key)) {
continue;
}
assert.equal((0, _metal.set)(newObj, key, obj[key]), obj[key], 'should return value');
assert.ok(key in newObj, 'should have key');
assert.ok(newObj.hasOwnProperty(key), 'should have key');
assert.equal((0, _metal.get)(newObj, key), obj[key], 'should set value');
}
};
_proto['@test should set a number key on an object'] = function testShouldSetANumberKeyOnAnObject(assert) {
var obj = {};
(0, _metal.set)(obj, 1, 'first');
assert.equal(obj[1], 'first');
};
_proto['@test should set an array index'] = function testShouldSetAnArrayIndex(assert) {
var arr = ['first', 'second'];
(0, _metal.set)(arr, 1, 'lol');
assert.deepEqual(arr, ['first', 'lol']);
};
_proto['@test should call setUnknownProperty if defined and value is undefined'] = function testShouldCallSetUnknownPropertyIfDefinedAndValueIsUndefined(assert) {
var obj = {
count: 0,
unknownProperty: function () {
assert.ok(false, 'should not invoke unknownProperty if setUnknownProperty is defined');
},
setUnknownProperty: function (key, value) {
assert.equal(key, 'foo', 'should pass key');
assert.equal(value, 'BAR', 'should pass key');
this.count++;
return 'FOO';
}
};
assert.equal((0, _metal.set)(obj, 'foo', 'BAR'), 'BAR', 'should return set value');
assert.equal(obj.count, 1, 'should have invoked');
};
_proto['@test warn on attempts to call set with undefined as object'] = function testWarnOnAttemptsToCallSetWithUndefinedAsObject() {
expectAssertion(function () {
return (0, _metal.set)(undefined, 'aProperty', 'BAM');
}, /Cannot call set with 'aProperty' on an undefined object./);
};
_proto['@test warn on attempts to call set with null as object'] = function testWarnOnAttemptsToCallSetWithNullAsObject() {
expectAssertion(function () {
return (0, _metal.set)(null, 'aProperty', 'BAM');
}, /Cannot call set with 'aProperty' on an undefined object./);
};
_proto['@test warn on attempts to use set with an unsupported property path'] = function testWarnOnAttemptsToUseSetWithAnUnsupportedPropertyPath() {
var obj = {};
expectAssertion(function () {
return (0, _metal.set)(obj, null, 42);
}, /The key provided to set must be a string or number, you passed null/);
expectAssertion(function () {
return (0, _metal.set)(obj, NaN, 42);
}, /The key provided to set must be a string or number, you passed NaN/);
expectAssertion(function () {
return (0, _metal.set)(obj, undefined, 42);
}, /The key provided to set must be a string or number, you passed undefined/);
expectAssertion(function () {
return (0, _metal.set)(obj, false, 42);
}, /The key provided to set must be a string or number, you passed false/);
};
_proto['@test warn on attempts of calling set on a destroyed object'] = function testWarnOnAttemptsOfCallingSetOnADestroyedObject() {
var obj = {
isDestroyed: true
};
expectAssertion(function () {
return (0, _metal.set)(obj, 'favoriteFood', 'hot dogs');
}, 'calling set on destroyed object: [object Object].favoriteFood = hot dogs');
};
_proto['@test does not trigger auto-run assertion for objects that have not been tagged'] = function testDoesNotTriggerAutoRunAssertionForObjectsThatHaveNotBeenTagged(assert) {
(0, _metal.setHasViews)(function () {
return true;
});
var obj = {};
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(obj.foo, 'bar');
};
_proto['@test does not warn on attempts of calling set on a destroyed object with `trySet`'] = function testDoesNotWarnOnAttemptsOfCallingSetOnADestroyedObjectWithTrySet(assert) {
var obj = {
isDestroyed: true
};
(0, _metal.trySet)(obj, 'favoriteFood', 'hot dogs');
assert.equal(obj.favoriteFood, undefined, 'does not set and does not error');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/alias_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/meta", "internal-test-helpers"], function (_emberBabel, _metal, _meta, _internalTestHelpers) {
"use strict";
var obj, count;
function incrementCount() {
count++;
}
(0, _internalTestHelpers.moduleFor)('@ember/-internals/metal/alias',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
obj = {
foo: {
faz: 'FOO'
}
};
count = 0;
};
_proto.afterEach = function afterEach() {
obj = null;
};
_proto['@test should proxy get to alt key'] = function testShouldProxyGetToAltKey(assert) {
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.alias)('foo.faz'));
assert.equal((0, _metal.get)(obj, 'bar'), 'FOO');
};
_proto['@test should proxy set to alt key'] = function testShouldProxySetToAltKey(assert) {
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.alias)('foo.faz'));
(0, _metal.set)(obj, 'bar', 'BAR');
assert.equal((0, _metal.get)(obj, 'foo.faz'), 'BAR');
};
_proto['@test old dependent keys should not trigger property changes'] = function testOldDependentKeysShouldNotTriggerPropertyChanges(assert) {
var obj1 = Object.create(null);
(0, _metal.defineProperty)(obj1, 'foo', null, null);
(0, _metal.defineProperty)(obj1, 'bar', (0, _metal.alias)('foo'));
(0, _metal.defineProperty)(obj1, 'baz', (0, _metal.alias)('foo'));
(0, _metal.defineProperty)(obj1, 'baz', (0, _metal.alias)('bar')); // redefine baz
(0, _metal.addObserver)(obj1, 'baz', incrementCount);
(0, _metal.set)(obj1, 'foo', 'FOO');
assert.equal(count, 1);
(0, _metal.removeObserver)(obj1, 'baz', incrementCount);
(0, _metal.set)(obj1, 'foo', 'OOF');
assert.equal(count, 1);
};
_proto["@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 (assert) {
var obj1 = Object.create(null);
obj1.incrementCount = incrementCount;
(0, _meta.meta)(obj1).proto = obj1;
(0, _metal.defineProperty)(obj1, 'foo', null, null);
(0, _metal.defineProperty)(obj1, 'bar', (0, _metal.alias)('foo'));
(0, _metal.defineProperty)(obj1, 'baz', (0, _metal.alias)('foo'));
(0, _metal.addObserver)(obj1, 'baz', null, 'incrementCount');
var obj2 = Object.create(obj1);
(0, _metal.defineProperty)(obj2, 'baz', (0, _metal.alias)('bar')); // override baz
(0, _metal.set)(obj2, 'foo', 'FOO');
assert.equal(count, 1);
(0, _metal.removeObserver)(obj2, 'baz', null, 'incrementCount');
(0, _metal.set)(obj2, 'foo', 'OOF');
assert.equal(count, 1);
};
_proto['@test an observer of the alias works if added after defining the alias'] = function testAnObserverOfTheAliasWorksIfAddedAfterDefiningTheAlias(assert) {
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.alias)('foo.faz'));
(0, _metal.addObserver)(obj, 'bar', incrementCount);
assert.ok((0, _metal.isWatching)(obj, 'foo.faz'));
(0, _metal.set)(obj, 'foo.faz', 'BAR');
assert.equal(count, 1);
};
_proto['@test an observer of the alias works if added before defining the alias'] = function testAnObserverOfTheAliasWorksIfAddedBeforeDefiningTheAlias(assert) {
(0, _metal.addObserver)(obj, 'bar', incrementCount);
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.alias)('foo.faz'));
assert.ok((0, _metal.isWatching)(obj, 'foo.faz'));
(0, _metal.set)(obj, 'foo.faz', 'BAR');
assert.equal(count, 1);
};
_proto['@test object with alias is dirtied if interior object of alias is set after consumption'] = function testObjectWithAliasIsDirtiedIfInteriorObjectOfAliasIsSetAfterConsumption(assert) {
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.alias)('foo.faz'));
(0, _metal.get)(obj, 'bar');
var tag = (0, _metal.tagFor)(obj);
var tagValue = tag.value();
(0, _metal.set)(obj, 'foo.faz', 'BAR');
assert.ok(!tag.validate(tagValue), 'setting the aliased key should dirty the object');
};
_proto['@test setting alias on self should fail assertion'] = function testSettingAliasOnSelfShouldFailAssertion() {
expectAssertion(function () {
return (0, _metal.defineProperty)(obj, 'bar', (0, _metal.alias)('bar'));
}, "Setting alias 'bar' on self");
};
_proto['@test destroyed alias does not disturb watch count'] = function testDestroyedAliasDoesNotDisturbWatchCount(assert) {
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.alias)('foo.faz'));
assert.equal((0, _metal.get)(obj, 'bar'), 'FOO');
assert.ok((0, _metal.isWatching)(obj, 'foo.faz'));
(0, _metal.defineProperty)(obj, 'bar', null);
assert.notOk((0, _metal.isWatching)(obj, 'foo.faz'));
};
_proto['@test setting on oneWay alias does not disturb watch count'] = function testSettingOnOneWayAliasDoesNotDisturbWatchCount(assert) {
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.alias)('foo.faz').oneWay());
assert.equal((0, _metal.get)(obj, 'bar'), 'FOO');
assert.ok((0, _metal.isWatching)(obj, 'foo.faz'));
(0, _metal.set)(obj, 'bar', null);
assert.notOk((0, _metal.isWatching)(obj, 'foo.faz'));
};
_proto['@test redefined alias with observer does not disturb watch count'] = function testRedefinedAliasWithObserverDoesNotDisturbWatchCount(assert) {
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.alias)('foo.faz').oneWay());
assert.equal((0, _metal.get)(obj, 'bar'), 'FOO');
assert.ok((0, _metal.isWatching)(obj, 'foo.faz'));
(0, _metal.addObserver)(obj, 'bar', incrementCount);
assert.equal(count, 0);
(0, _metal.set)(obj, 'bar', null);
assert.equal(count, 1);
assert.notOk((0, _metal.isWatching)(obj, 'foo.faz'));
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.alias)('foo.faz'));
assert.equal(count, 1);
assert.ok((0, _metal.isWatching)(obj, 'foo.faz'));
(0, _metal.set)(obj, 'foo.faz', 'great');
assert.equal(count, 2);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/chains_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/meta", "internal-test-helpers"], function (_emberBabel, _metal, _meta, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Chains',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test finishChains should properly copy chains from prototypes to instances'] = function testFinishChainsShouldProperlyCopyChainsFromPrototypesToInstances(assert) {
function didChange() {}
var obj = {};
(0, _metal.addObserver)(obj, 'foo.bar', null, didChange);
var childObj = Object.create(obj);
var parentMeta = (0, _meta.meta)(obj);
var childMeta = (0, _meta.meta)(childObj);
(0, _metal.finishChains)(childMeta);
assert.ok(parentMeta.readableChains() !== childMeta.readableChains(), 'The chains object is copied');
};
_proto['@test does not observe primitive values'] = function testDoesNotObservePrimitiveValues(assert) {
var obj = {
foo: {
bar: 'STRING'
}
};
(0, _metal.addObserver)(obj, 'foo.bar.baz', null, function () {});
var meta = (0, _meta.peekMeta)(obj);
assert.notOk(meta._object);
};
_proto['@test observer and CP chains'] = function testObserverAndCPChains(assert) {
var obj = {};
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)('qux.[]', function () {}));
(0, _metal.defineProperty)(obj, 'qux', (0, _metal.computed)(function () {})); // create DK chains
(0, _metal.get)(obj, 'foo'); // create observer chain
(0, _metal.addObserver)(obj, 'qux.length', function () {});
/*
+-----+
| qux | root CP
+-----+
^
+------+-----+
| |
+--------+ +----+
| length | | [] | chainWatchers
+--------+ +----+
observer CP(foo, 'qux.[]')
*/
// invalidate qux
(0, _metal.notifyPropertyChange)(obj, 'qux'); // CP chain is blown away
/*
+-----+
| qux | root CP
+-----+
^
+------+xxxxxx
| x
+--------+ xxxxxx
| length | x [] x chainWatchers
+--------+ xxxxxx
observer CP(foo, 'qux.[]')
*/
(0, _metal.get)(obj, 'qux'); // CP chain re-recreated
assert.ok(true, 'no crash');
};
_proto['@test checks cache correctly'] = function testChecksCacheCorrectly(assert) {
var obj = {};
var parentChainNode = new _metal.ChainNode(null, null, obj);
var chainNode = new _metal.ChainNode(parentChainNode, 'foo');
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)(function () {
return undefined;
}));
(0, _metal.get)(obj, 'foo');
assert.strictEqual(chainNode.value(), undefined);
};
_proto['@test chains are watched correctly'] = function testChainsAreWatchedCorrectly(assert) {
var obj = {
foo: {
bar: {
baz: 1
}
}
};
(0, _metal.watch)(obj, 'foo.bar.baz');
assert.equal((0, _metal.watcherCount)(obj, 'foo'), 1);
assert.equal((0, _metal.watcherCount)(obj, 'foo.bar'), 0);
assert.equal((0, _metal.watcherCount)(obj, 'foo.bar.baz'), 1);
assert.equal((0, _metal.watcherCount)(obj.foo, 'bar'), 1);
assert.equal((0, _metal.watcherCount)(obj.foo, 'bar.baz'), 0);
assert.equal((0, _metal.watcherCount)(obj.foo.bar, 'baz'), 1);
(0, _metal.unwatch)(obj, 'foo.bar.baz');
assert.equal((0, _metal.watcherCount)(obj, 'foo'), 0);
assert.equal((0, _metal.watcherCount)(obj, 'foo.bar'), 0);
assert.equal((0, _metal.watcherCount)(obj, 'foo.bar.baz'), 0);
assert.equal((0, _metal.watcherCount)(obj.foo, 'bar'), 0);
assert.equal((0, _metal.watcherCount)(obj.foo, 'bar.baz'), 0);
assert.equal((0, _metal.watcherCount)(obj.foo.bar, 'baz'), 0);
};
_proto['@test chains with single character keys are watched correctly'] = function testChainsWithSingleCharacterKeysAreWatchedCorrectly(assert) {
var obj = {
a: {
b: {
c: 1
}
}
};
(0, _metal.watch)(obj, 'a.b.c');
assert.equal((0, _metal.watcherCount)(obj, 'a'), 1);
assert.equal((0, _metal.watcherCount)(obj, 'a.b'), 0);
assert.equal((0, _metal.watcherCount)(obj, 'a.b.c'), 1);
assert.equal((0, _metal.watcherCount)(obj.a, 'b'), 1);
assert.equal((0, _metal.watcherCount)(obj.a, 'b.c'), 0);
assert.equal((0, _metal.watcherCount)(obj.a.b, 'c'), 1);
(0, _metal.unwatch)(obj, 'a.b.c');
assert.equal((0, _metal.watcherCount)(obj, 'a'), 0);
assert.equal((0, _metal.watcherCount)(obj, 'a.b'), 0);
assert.equal((0, _metal.watcherCount)(obj, 'a.b.c'), 0);
assert.equal((0, _metal.watcherCount)(obj.a, 'b'), 0);
assert.equal((0, _metal.watcherCount)(obj.a, 'b.c'), 0);
assert.equal((0, _metal.watcherCount)(obj.a.b, 'c'), 0);
};
_proto['@test writable chains is not defined more than once'] = function testWritableChainsIsNotDefinedMoreThanOnce(assert) {
assert.expect(0);
var Base =
/*#__PURE__*/
function () {
function Base() {
(0, _metal.finishChains)((0, _meta.meta)(this));
}
var _proto2 = Base.prototype;
_proto2.didChange = function didChange() {};
return Base;
}();
Base.prototype.foo = {
bar: {
baz: {
value: 123
}
}
}; // Define a standard computed property, which will eventually setup dependencies
(0, _metal.defineProperty)(Base.prototype, 'bar', (0, _metal.computed)('foo.bar', {
get: function () {
return this.foo.bar;
}
})); // Define some aliases, which will proxy chains along
(0, _metal.defineProperty)(Base.prototype, 'baz', (0, _metal.alias)('bar.baz'));
(0, _metal.defineProperty)(Base.prototype, 'value', (0, _metal.alias)('baz.value')); // Define an observer, which will eagerly attempt to setup chains and watch
// their values. This follows the aliases eagerly, and forces the first
// computed to actually set up its values/dependencies for chains. If
// writableChains was not already defined, this results in multiple root
// chain nodes being defined on the same object meta.
(0, _metal.addObserver)(Base.prototype, 'value', null, 'didChange');
var Child =
/*#__PURE__*/
function (_Base) {
(0, _emberBabel.inheritsLoose)(Child, _Base);
function Child() {
return _Base.apply(this, arguments) || this;
}
return Child;
}(Base);
var childObj = new Child();
(0, _metal.set)(childObj, 'foo.bar', {
baz: {
value: 456
}
});
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/computed_test", ["ember-babel", "@ember/-internals/runtime", "@ember/-internals/metal", "@ember/-internals/meta", "internal-test-helpers"], function (_emberBabel, _runtime, _metal, _meta, _internalTestHelpers) {
"use strict";
var obj, count;
(0, _internalTestHelpers.moduleFor)('computed',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test computed property should be an instance of descriptor'] = function testComputedPropertyShouldBeAnInstanceOfDescriptor(assert) {
assert.ok((0, _metal.computed)(function () {}) instanceof _metal.Descriptor);
};
_proto['@test computed properties assert the presence of a getter or setter function'] = function testComputedPropertiesAssertThePresenceOfAGetterOrSetterFunction() {
expectAssertion(function () {
(0, _metal.computed)('nogetternorsetter', {});
}, 'Computed properties must receive a getter or a setter, you passed none.');
};
_proto['@test computed properties check for the presence of a function or configuration object'] = function testComputedPropertiesCheckForThePresenceOfAFunctionOrConfigurationObject() {
expectAssertion(function () {
(0, _metal.computed)('nolastargument');
}, 'computed expects a function or an object as last argument.');
};
_proto['@test computed properties defined with an object only allow `get` and `set` keys'] = function testComputedPropertiesDefinedWithAnObjectOnlyAllowGetAndSetKeys() {
expectAssertion(function () {
(0, _metal.computed)({
get: function () {},
set: function () {},
other: function () {}
});
}, 'Config object passed to computed can only contain `get` and `set` keys.');
};
_proto['@test computed property can be accessed without `get`'] = function testComputedPropertyCanBeAccessedWithoutGet(assert) {
var obj = {};
var count = 0;
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)(function (key) {
count++;
return 'computed ' + key;
}));
assert.equal(obj.foo, 'computed foo', 'should return value');
assert.equal(count, 1, 'should have invoked computed property');
};
_proto['@test defining computed property should invoke property on get'] = function testDefiningComputedPropertyShouldInvokePropertyOnGet(assert) {
var obj = {};
var count = 0;
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)(function (key) {
count++;
return 'computed ' + key;
}));
assert.equal((0, _metal.get)(obj, 'foo'), 'computed foo', 'should return value');
assert.equal(count, 1, 'should have invoked computed property');
};
_proto['@test can override volatile computed property'] = function testCanOverrideVolatileComputedProperty(assert) {
var obj = {};
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)(function () {}).volatile());
(0, _metal.set)(obj, 'foo', 'boom');
assert.equal(obj.foo, 'boom');
};
_proto['@test defining computed property should invoke property on set'] = function testDefiningComputedPropertyShouldInvokePropertyOnSet(assert) {
var obj = {};
var count = 0;
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)({
get: function (key) {
return this['__' + key];
},
set: function (key, value) {
count++;
this['__' + key] = 'computed ' + value;
return this['__' + key];
}
}));
assert.equal((0, _metal.set)(obj, 'foo', 'bar'), 'bar', 'should return set value');
assert.equal(count, 1, 'should have invoked computed property');
assert.equal((0, _metal.get)(obj, 'foo'), 'computed bar', 'should return new value');
};
_proto['@test defining a computed property with a dependent key ending with @each is expanded to []'] = function testDefiningAComputedPropertyWithADependentKeyEndingWithEachIsExpandedTo(assert) {
var cp = (0, _metal.computed)('blazo.@each', function () {});
assert.deepEqual(cp._dependentKeys, ['blazo.[]']);
cp = (0, _metal.computed)('qux', 'zoopa.@each', function () {});
assert.deepEqual(cp._dependentKeys, ['qux', 'zoopa.[]']);
};
_proto['@test defining a computed property with a dependent key more than one level deep beyond @each is not supported'] = function testDefiningAComputedPropertyWithADependentKeyMoreThanOneLevelDeepBeyondEachIsNotSupported() {
expectNoWarning(function () {
(0, _metal.computed)('todos', function () {});
});
expectNoWarning(function () {
(0, _metal.computed)('todos.@each.owner', function () {});
});
expectWarning(function () {
(0, _metal.computed)('todos.@each.owner.name', function () {});
}, /You used the key "todos\.@each\.owner\.name" which is invalid\. /);
expectWarning(function () {
(0, _metal.computed)('todos.@each.owner.@each.name', function () {});
}, /You used the key "todos\.@each\.owner\.@each\.name" which is invalid\. /);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
var objA, objB;
(0, _internalTestHelpers.moduleFor)('computed should inherit through prototype',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2.beforeEach = function beforeEach() {
objA = {
__foo: 'FOO'
};
(0, _metal.defineProperty)(objA, 'foo', (0, _metal.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;
};
_proto2.afterEach = function afterEach() {
objA = objB = null;
};
_proto2['@test using get() and set()'] = function testUsingGetAndSet(assert) {
assert.equal((0, _metal.get)(objA, 'foo'), 'FOO', 'should get FOO from A');
assert.equal((0, _metal.get)(objB, 'foo'), 'FOO', 'should get FOO from B');
(0, _metal.set)(objA, 'foo', 'BIFF');
assert.equal((0, _metal.get)(objA, 'foo'), 'computed BIFF', 'should change A');
assert.equal((0, _metal.get)(objB, 'foo'), 'FOO', 'should NOT change B');
(0, _metal.set)(objB, 'foo', 'bar');
assert.equal((0, _metal.get)(objB, 'foo'), 'computed bar', 'should change B');
assert.equal((0, _metal.get)(objA, 'foo'), 'computed BIFF', 'should NOT change A');
(0, _metal.set)(objA, 'foo', 'BAZ');
assert.equal((0, _metal.get)(objA, 'foo'), 'computed BAZ', 'should change A');
assert.equal((0, _metal.get)(objB, 'foo'), 'computed bar', 'should NOT change B');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('redefining computed property to normal',
/*#__PURE__*/
function (_AbstractTestCase3) {
(0, _emberBabel.inheritsLoose)(_class3, _AbstractTestCase3);
function _class3() {
return _AbstractTestCase3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3.beforeEach = function beforeEach() {
objA = {
__foo: 'FOO'
};
(0, _metal.defineProperty)(objA, 'foo', (0, _metal.computed)({
get: function (key) {
return this['__' + key];
},
set: function (key, value) {
this['__' + key] = 'computed ' + value;
return this['__' + key];
}
}));
objB = Object.create(objA);
(0, _metal.defineProperty)(objB, 'foo'); // make this just a normal property.
};
_proto3.afterEach = function afterEach() {
objA = objB = null;
};
_proto3['@test using get() and set()'] = function testUsingGetAndSet(assert) {
assert.equal((0, _metal.get)(objA, 'foo'), 'FOO', 'should get FOO from A');
assert.equal((0, _metal.get)(objB, 'foo'), undefined, 'should get undefined from B');
(0, _metal.set)(objA, 'foo', 'BIFF');
assert.equal((0, _metal.get)(objA, 'foo'), 'computed BIFF', 'should change A');
assert.equal((0, _metal.get)(objB, 'foo'), undefined, 'should NOT change B');
(0, _metal.set)(objB, 'foo', 'bar');
assert.equal((0, _metal.get)(objB, 'foo'), 'bar', 'should change B');
assert.equal((0, _metal.get)(objA, 'foo'), 'computed BIFF', 'should NOT change A');
(0, _metal.set)(objA, 'foo', 'BAZ');
assert.equal((0, _metal.get)(objA, 'foo'), 'computed BAZ', 'should change A');
assert.equal((0, _metal.get)(objB, 'foo'), 'bar', 'should NOT change B');
};
return _class3;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('redefining computed property to another property',
/*#__PURE__*/
function (_AbstractTestCase4) {
(0, _emberBabel.inheritsLoose)(_class4, _AbstractTestCase4);
function _class4() {
return _AbstractTestCase4.apply(this, arguments) || this;
}
var _proto4 = _class4.prototype;
_proto4.beforeEach = function beforeEach() {
objA = {
__foo: 'FOO'
};
(0, _metal.defineProperty)(objA, 'foo', (0, _metal.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, _metal.defineProperty)(objB, 'foo', (0, _metal.computed)({
get: function (key) {
return this['__' + key];
},
set: function (key, value) {
this['__' + key] = 'B ' + value;
return this['__' + key];
}
}));
};
_proto4.afterEach = function afterEach() {
objA = objB = null;
};
_proto4['@test using get() and set()'] = function testUsingGetAndSet(assert) {
assert.equal((0, _metal.get)(objA, 'foo'), 'FOO', 'should get FOO from A');
assert.equal((0, _metal.get)(objB, 'foo'), 'FOO', 'should get FOO from B');
(0, _metal.set)(objA, 'foo', 'BIFF');
assert.equal((0, _metal.get)(objA, 'foo'), 'A BIFF', 'should change A');
assert.equal((0, _metal.get)(objB, 'foo'), 'FOO', 'should NOT change B');
(0, _metal.set)(objB, 'foo', 'bar');
assert.equal((0, _metal.get)(objB, 'foo'), 'B bar', 'should change B');
assert.equal((0, _metal.get)(objA, 'foo'), 'A BIFF', 'should NOT change A');
(0, _metal.set)(objA, 'foo', 'BAZ');
assert.equal((0, _metal.get)(objA, 'foo'), 'A BAZ', 'should change A');
assert.equal((0, _metal.get)(objB, 'foo'), 'B bar', 'should NOT change B');
};
return _class4;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('computed - metadata',
/*#__PURE__*/
function (_AbstractTestCase5) {
(0, _emberBabel.inheritsLoose)(_class5, _AbstractTestCase5);
function _class5() {
return _AbstractTestCase5.apply(this, arguments) || this;
}
var _proto5 = _class5.prototype;
_proto5['@test can set metadata on a computed property'] = function testCanSetMetadataOnAComputedProperty(assert) {
var computedProperty = (0, _metal.computed)(function () {});
computedProperty.meta({
key: 'keyValue'
});
assert.equal(computedProperty.meta().key, 'keyValue', 'saves passed meta hash to the _meta property');
};
_proto5['@test meta should return an empty hash if no meta is set'] = function testMetaShouldReturnAnEmptyHashIfNoMetaIsSet(assert) {
var computedProperty = (0, _metal.computed)(function () {});
assert.deepEqual(computedProperty.meta(), {}, 'returned value is an empty hash');
};
return _class5;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// CACHEABLE
//
(0, _internalTestHelpers.moduleFor)('computed - cacheable',
/*#__PURE__*/
function (_AbstractTestCase6) {
(0, _emberBabel.inheritsLoose)(_class6, _AbstractTestCase6);
function _class6() {
return _AbstractTestCase6.apply(this, arguments) || this;
}
var _proto6 = _class6.prototype;
_proto6.beforeEach = function beforeEach() {
obj = {};
count = 0;
var func = function () {
count++;
return 'bar ' + count;
};
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)({
get: func,
set: func
}));
};
_proto6.afterEach = function afterEach() {
obj = count = null;
};
_proto6['@test cacheable should cache'] = function testCacheableShouldCache(assert) {
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 1', 'first get');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 1', 'second get');
assert.equal(count, 1, 'should only invoke once');
};
_proto6['@test modifying a cacheable property should update cache'] = function testModifyingACacheablePropertyShouldUpdateCache(assert) {
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 1', 'first get');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 1', 'second get');
assert.equal((0, _metal.set)(obj, 'foo', 'baz'), 'baz', 'setting');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 2', 'third get');
assert.equal(count, 2, 'should not invoke again');
};
_proto6['@test inherited property should not pick up cache'] = function testInheritedPropertyShouldNotPickUpCache(assert) {
var objB = Object.create(obj);
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 1', 'obj first get');
assert.equal((0, _metal.get)(objB, 'foo'), 'bar 2', 'objB first get');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 1', 'obj second get');
assert.equal((0, _metal.get)(objB, 'foo'), 'bar 2', 'objB second get');
(0, _metal.set)(obj, 'foo', 'baz'); // modify A
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 3', 'obj third get');
assert.equal((0, _metal.get)(objB, 'foo'), 'bar 2', 'objB third get');
};
_proto6['@test getCachedValueFor should return the cached value'] = function testGetCachedValueForShouldReturnTheCachedValue(assert) {
assert.equal((0, _metal.getCachedValueFor)(obj, 'foo'), undefined, 'should not yet be a cached value');
(0, _metal.get)(obj, 'foo');
assert.equal((0, _metal.getCachedValueFor)(obj, 'foo'), 'bar 1', 'should retrieve cached value');
};
_proto6['@test getCachedValueFor should return falsy cached values'] = function testGetCachedValueForShouldReturnFalsyCachedValues(assert) {
(0, _metal.defineProperty)(obj, 'falsy', (0, _metal.computed)(function () {
return false;
}));
assert.equal((0, _metal.getCachedValueFor)(obj, 'falsy'), undefined, 'should not yet be a cached value');
(0, _metal.get)(obj, 'falsy');
assert.equal((0, _metal.getCachedValueFor)(obj, 'falsy'), false, 'should retrieve cached value');
};
_proto6['@test setting a cached computed property passes the old value as the third argument'] = function testSettingACachedComputedPropertyPassesTheOldValueAsTheThirdArgument(assert) {
var obj = {
foo: 0
};
var receivedOldValue;
(0, _metal.defineProperty)(obj, 'plusOne', (0, _metal.computed)({
get: function () {},
set: function (key, value, oldValue) {
receivedOldValue = oldValue;
return value;
}
}).property('foo'));
(0, _metal.set)(obj, 'plusOne', 1);
assert.strictEqual(receivedOldValue, undefined, 'oldValue should be undefined');
(0, _metal.set)(obj, 'plusOne', 2);
assert.strictEqual(receivedOldValue, 1, 'oldValue should be 1');
(0, _metal.set)(obj, 'plusOne', 3);
assert.strictEqual(receivedOldValue, 2, 'oldValue should be 2');
};
return _class6;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// DEPENDENT KEYS
//
(0, _internalTestHelpers.moduleFor)('computed - dependentkey',
/*#__PURE__*/
function (_AbstractTestCase7) {
(0, _emberBabel.inheritsLoose)(_class7, _AbstractTestCase7);
function _class7() {
return _AbstractTestCase7.apply(this, arguments) || this;
}
var _proto7 = _class7.prototype;
_proto7.beforeEach = function beforeEach() {
obj = {
bar: 'baz'
};
count = 0;
var getterAndSetter = function () {
count++;
(0, _metal.get)(this, 'bar');
return 'bar ' + count;
};
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)({
get: getterAndSetter,
set: getterAndSetter
}).property('bar'));
};
_proto7.afterEach = function afterEach() {
obj = count = null;
};
_proto7['@test should lazily watch dependent keys on set'] = function testShouldLazilyWatchDependentKeysOnSet(assert) {
assert.equal((0, _metal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal((0, _metal.isWatching)(obj, 'bar'), true, 'lazily watching dependent key');
};
_proto7['@test should lazily watch dependent keys on get'] = function testShouldLazilyWatchDependentKeysOnGet(assert) {
assert.equal((0, _metal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
(0, _metal.get)(obj, 'foo');
assert.equal((0, _metal.isWatching)(obj, 'bar'), true, 'lazily watching dependent key');
};
_proto7['@test local dependent key should invalidate cache'] = function testLocalDependentKeyShouldInvalidateCache(assert) {
assert.equal((0, _metal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 1', 'get once');
assert.equal((0, _metal.isWatching)(obj, 'bar'), true, 'lazily setup watching dependent key');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 1', 'cached retrieve');
(0, _metal.set)(obj, 'bar', 'BIFF'); // should invalidate foo
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 2', 'should recache');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 2', 'cached retrieve');
};
_proto7['@test should invalidate multiple nested dependent keys'] = function testShouldInvalidateMultipleNestedDependentKeys(assert) {
var count = 0;
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.computed)(function () {
count++;
(0, _metal.get)(this, 'baz');
return 'baz ' + count;
}).property('baz'));
assert.equal((0, _metal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
assert.equal((0, _metal.isWatching)(obj, 'baz'), false, 'precond not watching dependent key');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 1', 'get once');
assert.equal((0, _metal.isWatching)(obj, 'bar'), true, 'lazily setup watching dependent key');
assert.equal((0, _metal.isWatching)(obj, 'baz'), true, 'lazily setup watching dependent key');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 1', 'cached retrieve');
(0, _metal.set)(obj, 'baz', 'BIFF'); // should invalidate bar -> foo
assert.equal((0, _metal.isWatching)(obj, 'bar'), false, 'should not be watching dependent key after cache cleared');
assert.equal((0, _metal.isWatching)(obj, 'baz'), false, 'should not be watching dependent key after cache cleared');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 2', 'should recache');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 2', 'cached retrieve');
assert.equal((0, _metal.isWatching)(obj, 'bar'), true, 'lazily setup watching dependent key');
assert.equal((0, _metal.isWatching)(obj, 'baz'), true, 'lazily setup watching dependent key');
};
_proto7['@test circular keys should not blow up'] = function testCircularKeysShouldNotBlowUp(assert) {
var func = function () {
count++;
return 'bar ' + count;
};
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.computed)({
get: func,
set: func
}).property('foo'));
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)(function () {
count++;
return 'foo ' + count;
}).property('bar'));
assert.equal((0, _metal.get)(obj, 'foo'), 'foo 1', 'get once');
assert.equal((0, _metal.get)(obj, 'foo'), 'foo 1', 'cached retrieve');
(0, _metal.set)(obj, 'bar', 'BIFF'); // should invalidate bar -> foo -> bar
assert.equal((0, _metal.get)(obj, 'foo'), 'foo 3', 'should recache');
assert.equal((0, _metal.get)(obj, 'foo'), 'foo 3', 'cached retrieve');
};
_proto7['@test redefining a property should undo old dependent keys'] = function testRedefiningAPropertyShouldUndoOldDependentKeys(assert) {
assert.equal((0, _metal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar 1');
assert.equal((0, _metal.isWatching)(obj, 'bar'), true, 'lazily watching dependent key');
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)(function () {
count++;
return 'baz ' + count;
}).property('baz'));
assert.equal((0, _metal.isWatching)(obj, 'bar'), false, 'after redefining should not be watching dependent key');
assert.equal((0, _metal.get)(obj, 'foo'), 'baz 2');
(0, _metal.set)(obj, 'bar', 'BIFF'); // should not kill cache
assert.equal((0, _metal.get)(obj, 'foo'), 'baz 2');
(0, _metal.set)(obj, 'baz', 'BOP');
assert.equal((0, _metal.get)(obj, 'foo'), 'baz 3');
};
_proto7['@test can watch multiple dependent keys specified declaratively via brace expansion'] = function testCanWatchMultipleDependentKeysSpecifiedDeclarativelyViaBraceExpansion(assert) {
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)(function () {
count++;
return 'foo ' + count;
}).property('qux.{bar,baz}'));
assert.equal((0, _metal.get)(obj, 'foo'), 'foo 1', 'get once');
assert.equal((0, _metal.get)(obj, 'foo'), 'foo 1', 'cached retrieve');
(0, _metal.set)(obj, 'qux', {});
(0, _metal.set)(obj, 'qux.bar', 'bar'); // invalidate foo
assert.equal((0, _metal.get)(obj, 'foo'), 'foo 2', 'foo invalidated from bar');
(0, _metal.set)(obj, 'qux.baz', 'baz'); // invalidate foo
assert.equal((0, _metal.get)(obj, 'foo'), 'foo 3', 'foo invalidated from baz');
(0, _metal.set)(obj, 'qux.quux', 'quux'); // do not invalidate foo
assert.equal((0, _metal.get)(obj, 'foo'), 'foo 3', 'foo not invalidated by quux');
};
_proto7['@test throws assertion if brace expansion notation has spaces'] = function testThrowsAssertionIfBraceExpansionNotationHasSpaces() {
expectAssertion(function () {
(0, _metal.defineProperty)(obj, 'roo', (0, _metal.computed)(function () {
count++;
return 'roo ' + count;
}).property('fee.{bar, baz,bop , }'));
}, /cannot contain spaces/);
};
_proto7['@test throws an assertion if an uncached `get` is called after object is destroyed'] = function testThrowsAnAssertionIfAnUncachedGetIsCalledAfterObjectIsDestroyed(assert) {
assert.equal((0, _metal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
var meta = (0, _meta.meta)(obj);
meta.destroy();
obj.toString = function () {
return '';
};
expectAssertion(function () {
(0, _metal.get)(obj, 'foo');
}, 'Cannot modify dependent keys for `foo` on `` after it has been destroyed.');
assert.equal((0, _metal.isWatching)(obj, 'bar'), false, 'deps were not updated');
};
return _class7;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// CHAINED DEPENDENT KEYS
//
var func;
(0, _internalTestHelpers.moduleFor)('computed - dependentkey with chained properties',
/*#__PURE__*/
function (_AbstractTestCase8) {
(0, _emberBabel.inheritsLoose)(_class8, _AbstractTestCase8);
function _class8() {
return _AbstractTestCase8.apply(this, arguments) || this;
}
var _proto8 = _class8.prototype;
_proto8.beforeEach = function beforeEach() {
obj = {
foo: {
bar: {
baz: {
biff: 'BIFF'
}
}
}
};
count = 0;
func = function () {
count++;
return (0, _metal.get)(obj, 'foo.bar.baz.biff') + ' ' + count;
};
};
_proto8.afterEach = function afterEach() {
obj = count = func = null;
};
_proto8['@test depending on simple chain'] = function testDependingOnSimpleChain(assert) {
// assign computed property
(0, _metal.defineProperty)(obj, 'prop', (0, _metal.computed)(func).property('foo.bar.baz.biff'));
assert.equal((0, _metal.get)(obj, 'prop'), 'BIFF 1');
(0, _metal.set)((0, _metal.get)(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
assert.equal((0, _metal.get)(obj, 'prop'), 'BUZZ 2');
assert.equal((0, _metal.get)(obj, 'prop'), 'BUZZ 2');
(0, _metal.set)((0, _metal.get)(obj, 'foo.bar'), 'baz', {
biff: 'BLOB'
});
assert.equal((0, _metal.get)(obj, 'prop'), 'BLOB 3');
assert.equal((0, _metal.get)(obj, 'prop'), 'BLOB 3');
(0, _metal.set)((0, _metal.get)(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
assert.equal((0, _metal.get)(obj, 'prop'), 'BUZZ 4');
assert.equal((0, _metal.get)(obj, 'prop'), 'BUZZ 4');
(0, _metal.set)((0, _metal.get)(obj, 'foo'), 'bar', {
baz: {
biff: 'BOOM'
}
});
assert.equal((0, _metal.get)(obj, 'prop'), 'BOOM 5');
assert.equal((0, _metal.get)(obj, 'prop'), 'BOOM 5');
(0, _metal.set)((0, _metal.get)(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
assert.equal((0, _metal.get)(obj, 'prop'), 'BUZZ 6');
assert.equal((0, _metal.get)(obj, 'prop'), 'BUZZ 6');
(0, _metal.set)(obj, 'foo', {
bar: {
baz: {
biff: 'BLARG'
}
}
});
assert.equal((0, _metal.get)(obj, 'prop'), 'BLARG 7');
assert.equal((0, _metal.get)(obj, 'prop'), 'BLARG 7');
(0, _metal.set)((0, _metal.get)(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
assert.equal((0, _metal.get)(obj, 'prop'), 'BUZZ 8');
assert.equal((0, _metal.get)(obj, 'prop'), 'BUZZ 8');
(0, _metal.defineProperty)(obj, 'prop');
(0, _metal.set)(obj, 'prop', 'NONE');
assert.equal((0, _metal.get)(obj, 'prop'), 'NONE');
(0, _metal.set)(obj, 'foo', {
bar: {
baz: {
biff: 'BLARG'
}
}
});
assert.equal((0, _metal.get)(obj, 'prop'), 'NONE'); // should do nothing
assert.equal(count, 8, 'should be not have invoked computed again');
};
_proto8['@test chained dependent keys should evaluate computed properties lazily'] = function testChainedDependentKeysShouldEvaluateComputedPropertiesLazily(assert) {
(0, _metal.defineProperty)(obj.foo.bar, 'b', (0, _metal.computed)(func));
(0, _metal.defineProperty)(obj.foo, 'c', (0, _metal.computed)(function () {}).property('bar.b'));
assert.equal(count, 0, 'b should not run');
};
return _class8;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// improved-cp-syntax
//
(0, _internalTestHelpers.moduleFor)('computed - improved cp syntax',
/*#__PURE__*/
function (_AbstractTestCase9) {
(0, _emberBabel.inheritsLoose)(_class9, _AbstractTestCase9);
function _class9() {
return _AbstractTestCase9.apply(this, arguments) || this;
}
var _proto9 = _class9.prototype;
_proto9['@test setter and getters are passed using an object'] = function testSetterAndGettersArePassedUsingAnObject(assert) {
var testObj = _runtime.Object.extend({
a: '1',
b: '2',
aInt: (0, _metal.computed)('a', {
get: function (keyName) {
assert.equal(keyName, 'aInt', 'getter receives the keyName');
return parseInt(this.get('a'));
},
set: function (keyName, value, oldValue) {
assert.equal(keyName, 'aInt', 'setter receives the keyName');
assert.equal(value, 123, 'setter receives the new value');
assert.equal(oldValue, 1, 'setter receives the old value');
this.set('a', String(value)); // side effect
return parseInt(this.get('a'));
}
})
}).create();
assert.ok(testObj.get('aInt') === 1, 'getter works');
testObj.set('aInt', 123);
assert.ok(testObj.get('a') === '123', 'setter works');
assert.ok(testObj.get('aInt') === 123, 'cp has been updated too');
};
_proto9['@test setter can be omited'] = function testSetterCanBeOmited(assert) {
var testObj = _runtime.Object.extend({
a: '1',
b: '2',
aInt: (0, _metal.computed)('a', {
get: function (keyName) {
assert.equal(keyName, 'aInt', 'getter receives the keyName');
return parseInt(this.get('a'));
}
})
}).create();
assert.ok(testObj.get('aInt') === 1, 'getter works');
assert.ok(testObj.get('a') === '1');
testObj.set('aInt', '123');
assert.ok(testObj.get('aInt') === '123', 'cp has been updated too');
};
_proto9['@test getter can be omited'] = function testGetterCanBeOmited(assert) {
var testObj = _runtime.Object.extend({
com: (0, _metal.computed)({
set: function (key, value) {
return value;
}
})
}).create();
assert.ok(testObj.get('com') === undefined);
testObj.set('com', '123');
assert.ok(testObj.get('com') === '123', 'cp has been updated');
};
_proto9['@test the return value of the setter gets cached'] = function testTheReturnValueOfTheSetterGetsCached(assert) {
var testObj = _runtime.Object.extend({
a: '1',
sampleCP: (0, _metal.computed)('a', {
get: function () {
assert.ok(false, 'The getter should not be invoked');
return 'get-value';
},
set: function () {
return 'set-value';
}
})
}).create();
testObj.set('sampleCP', 'abcd');
assert.ok(testObj.get('sampleCP') === 'set-value', 'The return value of the CP was cached');
};
return _class9;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// BUGS
//
(0, _internalTestHelpers.moduleFor)('computed edge cases',
/*#__PURE__*/
function (_AbstractTestCase10) {
(0, _emberBabel.inheritsLoose)(_class10, _AbstractTestCase10);
function _class10() {
return _AbstractTestCase10.apply(this, arguments) || this;
}
var _proto10 = _class10.prototype;
_proto10['@test adding a computed property should show up in key iteration'] = function testAddingAComputedPropertyShouldShowUpInKeyIteration(assert) {
var obj = {};
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)(function () {}));
var found = [];
for (var key in obj) {
found.push(key);
}
assert.ok(found.indexOf('foo') >= 0, 'should find computed property in iteration found=' + found);
assert.ok('foo' in obj, 'foo in obj should pass');
};
_proto10["@test when setting a value after it had been retrieved empty don't pass function UNDEFINED as oldValue"] = function testWhenSettingAValueAfterItHadBeenRetrievedEmptyDonTPassFunctionUNDEFINEDAsOldValue(assert) {
var obj = {};
var oldValueIsNoFunction = true;
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)({
get: function () {},
set: function (key, value, oldValue) {
if (typeof oldValue === 'function') {
oldValueIsNoFunction = false;
}
return undefined;
}
}));
(0, _metal.get)(obj, 'foo');
(0, _metal.set)(obj, 'foo', undefined);
assert.ok(oldValueIsNoFunction);
};
return _class10;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('computed - setter',
/*#__PURE__*/
function (_AbstractTestCase11) {
(0, _emberBabel.inheritsLoose)(_class11, _AbstractTestCase11);
function _class11() {
return _AbstractTestCase11.apply(this, arguments) || this;
}
var _proto11 = _class11.prototype;
_proto11['@test setting a watched computed property'] = function testSettingAWatchedComputedProperty(assert) {
var obj = {
firstName: 'Yehuda',
lastName: 'Katz'
};
(0, _metal.defineProperty)(obj, 'fullName', (0, _metal.computed)({
get: function () {
return (0, _metal.get)(this, 'firstName') + ' ' + (0, _metal.get)(this, 'lastName');
},
set: function (key, value) {
var values = value.split(' ');
(0, _metal.set)(this, 'firstName', values[0]);
(0, _metal.set)(this, 'lastName', values[1]);
return value;
}
}).property('firstName', 'lastName'));
var fullNameDidChange = 0;
var firstNameDidChange = 0;
var lastNameDidChange = 0;
(0, _metal.addObserver)(obj, 'fullName', function () {
fullNameDidChange++;
});
(0, _metal.addObserver)(obj, 'firstName', function () {
firstNameDidChange++;
});
(0, _metal.addObserver)(obj, 'lastName', function () {
lastNameDidChange++;
});
assert.equal((0, _metal.get)(obj, 'fullName'), 'Yehuda Katz');
(0, _metal.set)(obj, 'fullName', 'Yehuda Katz');
(0, _metal.set)(obj, 'fullName', 'Kris Selden');
assert.equal((0, _metal.get)(obj, 'fullName'), 'Kris Selden');
assert.equal((0, _metal.get)(obj, 'firstName'), 'Kris');
assert.equal((0, _metal.get)(obj, 'lastName'), 'Selden');
assert.equal(fullNameDidChange, 1);
assert.equal(firstNameDidChange, 1);
assert.equal(lastNameDidChange, 1);
};
_proto11['@test setting a cached computed property that modifies the value you give it'] = function testSettingACachedComputedPropertyThatModifiesTheValueYouGiveIt(assert) {
var obj = {
foo: 0
};
(0, _metal.defineProperty)(obj, 'plusOne', (0, _metal.computed)({
get: function () {
return (0, _metal.get)(this, 'foo') + 1;
},
set: function (key, value) {
(0, _metal.set)(this, 'foo', value);
return value + 1;
}
}).property('foo'));
var plusOneDidChange = 0;
(0, _metal.addObserver)(obj, 'plusOne', function () {
plusOneDidChange++;
});
assert.equal((0, _metal.get)(obj, 'plusOne'), 1);
(0, _metal.set)(obj, 'plusOne', 1);
assert.equal((0, _metal.get)(obj, 'plusOne'), 2);
(0, _metal.set)(obj, 'plusOne', 1);
assert.equal((0, _metal.get)(obj, 'plusOne'), 2);
assert.equal(plusOneDidChange, 1);
(0, _metal.set)(obj, 'foo', 5);
assert.equal((0, _metal.get)(obj, 'plusOne'), 6);
assert.equal(plusOneDidChange, 2);
};
return _class11;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('computed - default setter',
/*#__PURE__*/
function (_AbstractTestCase12) {
(0, _emberBabel.inheritsLoose)(_class12, _AbstractTestCase12);
function _class12() {
return _AbstractTestCase12.apply(this, arguments) || this;
}
var _proto12 = _class12.prototype;
_proto12["@test when setting a value on a computed property that doesn't handle sets"] = function testWhenSettingAValueOnAComputedPropertyThatDoesnTHandleSets(assert) {
var obj = {};
var observerFired = false;
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)(function () {
return 'foo';
}));
(0, _metal.addObserver)(obj, 'foo', null, function () {
return observerFired = true;
});
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar', 'The set value is properly returned');
assert.ok(typeof obj.foo === 'string', 'The computed property was removed');
assert.ok(observerFired, 'The observer was still notified');
};
return _class12;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('computed - readOnly',
/*#__PURE__*/
function (_AbstractTestCase13) {
(0, _emberBabel.inheritsLoose)(_class13, _AbstractTestCase13);
function _class13() {
return _AbstractTestCase13.apply(this, arguments) || this;
}
var _proto13 = _class13.prototype;
_proto13['@test is chainable'] = function testIsChainable(assert) {
var cp = (0, _metal.computed)(function () {}).readOnly();
assert.ok(cp instanceof _metal.Descriptor);
assert.ok(cp instanceof _metal.ComputedProperty);
};
_proto13['@test throws assertion if called over a CP with a setter defined with the new syntax'] = function testThrowsAssertionIfCalledOverACPWithASetterDefinedWithTheNewSyntax() {
expectAssertion(function () {
(0, _metal.computed)({
get: function () {},
set: function () {}
}).readOnly();
}, /Computed properties that define a setter using the new syntax cannot be read-only/);
};
_proto13['@test protects against setting'] = function testProtectsAgainstSetting(assert) {
var obj = {};
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.computed)(function () {
return 'barValue';
}).readOnly());
assert.equal((0, _metal.get)(obj, 'bar'), 'barValue');
assert.throws(function () {
(0, _metal.set)(obj, 'bar', 'newBar');
}, /Cannot set read\-only property "bar" on object:/);
assert.equal((0, _metal.get)(obj, 'bar'), 'barValue');
};
return _class13;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/descriptor_test", ["ember-babel", "@ember/-internals/runtime", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _runtime, _metal, _internalTestHelpers) {
"use strict";
var classes = [
/*#__PURE__*/
function () {
_class.module = function module(title) {
return title + ": using defineProperty on an object directly";
};
function _class() {
this.object = {};
}
var _proto = _class.prototype;
_proto.install = function install(key, desc, assert) {
var object = this.object;
(0, _metal.defineProperty)(object, key, desc);
assert.ok(object.hasOwnProperty(key));
};
_proto.set = function set(key, value) {
this.object[key] = value;
};
_proto.finalize = function finalize() {
return this.object;
};
_proto.source = function source() {
return this.object;
};
return _class;
}(),
/*#__PURE__*/
function () {
_class2.module = function module(title) {
return title + ": using defineProperty on a prototype";
};
function _class2() {
this.proto = {};
}
var _proto2 = _class2.prototype;
_proto2.install = function install(key, desc, assert) {
var proto = this.proto;
(0, _metal.defineProperty)(proto, key, desc);
assert.ok(proto.hasOwnProperty(key));
};
_proto2.set = function set(key, value) {
this.proto[key] = value;
};
_proto2.finalize = function finalize() {
return Object.create(this.proto);
};
_proto2.source = function source() {
return this.proto;
};
return _class2;
}(),
/*#__PURE__*/
function () {
_class3.module = function module(title) {
return title + ": in EmberObject.extend()";
};
function _class3() {
this.klass = null;
this.props = {};
}
var _proto3 = _class3.prototype;
_proto3.install = function install(key, desc) {
this.props[key] = desc;
};
_proto3.set = function set(key, value) {
this.props[key] = value;
};
_proto3.finalize = function finalize() {
this.klass = _runtime.Object.extend(this.props);
return this.klass.create();
};
_proto3.source = function source() {
return this.klass.prototype;
};
return _class3;
}(),
/*#__PURE__*/
function () {
_class4.module = function module(title) {
return title + ": in EmberObject.extend() through a mixin";
};
function _class4() {
this.klass = null;
this.props = {};
}
var _proto4 = _class4.prototype;
_proto4.install = function install(key, desc) {
this.props[key] = desc;
};
_proto4.set = function set(key, value) {
this.props[key] = value;
};
_proto4.finalize = function finalize() {
this.klass = _runtime.Object.extend(_metal.Mixin.create(this.props));
return this.klass.create();
};
_proto4.source = function source() {
return this.klass.prototype;
};
return _class4;
}(),
/*#__PURE__*/
function () {
_class5.module = function module(title) {
return title + ": inherited from another EmberObject super class";
};
function _class5() {
this.superklass = null;
this.props = {};
}
var _proto5 = _class5.prototype;
_proto5.install = function install(key, desc) {
this.props[key] = desc;
};
_proto5.set = function set(key, value) {
this.props[key] = value;
};
_proto5.finalize = function finalize() {
this.superklass = _runtime.Object.extend(this.props);
return this.superklass.extend().create();
};
_proto5.source = function source() {
return this.superklass.prototype;
};
return _class5;
}()];
classes.forEach(function (TestClass) {
(0, _internalTestHelpers.moduleFor)(TestClass.module('@ember/-internals/metal/descriptor'),
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class6, _AbstractTestCase);
function _class6() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto6 = _class6.prototype;
_proto6['@test defining a configurable property'] = function testDefiningAConfigurableProperty(assert) {
var factory = new TestClass(assert);
factory.install('foo', (0, _metal.descriptor)({
configurable: true,
value: 'bar'
}), assert);
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');
};
_proto6['@test defining a non-configurable property'] = function testDefiningANonConfigurableProperty(assert) {
var factory = new TestClass(assert);
factory.install('foo', (0, _metal.descriptor)({
configurable: false,
value: 'bar'
}), assert);
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
var source = factory.source();
assert.throws(function () {
return delete source.foo;
}, TypeError);
assert.throws(function () {
return Object.defineProperty(source, 'foo', {
configurable: true,
value: 'baz'
});
}, TypeError);
assert.equal(obj.foo, 'bar');
};
_proto6['@test defining an enumerable property'] = function testDefiningAnEnumerableProperty(assert) {
var factory = new TestClass(assert);
factory.install('foo', (0, _metal.descriptor)({
enumerable: true,
value: 'bar'
}), assert);
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
var source = factory.source();
assert.ok(Object.keys(source).indexOf('foo') !== -1);
};
_proto6['@test defining a non-enumerable property'] = function testDefiningANonEnumerableProperty(assert) {
var factory = new TestClass(assert);
factory.install('foo', (0, _metal.descriptor)({
enumerable: false,
value: 'bar'
}), assert);
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
var source = factory.source();
assert.ok(Object.keys(source).indexOf('foo') === -1);
};
_proto6['@test defining a writable property'] = function testDefiningAWritableProperty(assert) {
var factory = new TestClass(assert);
factory.install('foo', (0, _metal.descriptor)({
writable: true,
value: 'bar'
}), assert);
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');
};
_proto6['@test defining a non-writable property'] = function testDefiningANonWritableProperty(assert) {
var factory = new TestClass(assert);
factory.install('foo', (0, _metal.descriptor)({
writable: false,
value: 'bar'
}), assert);
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
var source = factory.source();
assert.throws(function () {
return source.foo = 'baz';
}, TypeError);
assert.throws(function () {
return obj.foo = 'baz';
}, TypeError);
assert.equal(obj.foo, 'bar');
};
_proto6['@test defining a getter'] = function testDefiningAGetter(assert) {
var factory = new TestClass(assert);
factory.install('foo', (0, _metal.descriptor)({
get: function () {
return this.__foo__;
}
}), assert);
factory.set('__foo__', 'bar');
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
obj.__foo__ = 'baz';
assert.equal(obj.foo, 'baz');
};
_proto6['@test defining a setter'] = function testDefiningASetter(assert) {
var factory = new TestClass(assert);
factory.install('foo', (0, _metal.descriptor)({
set: function (value) {
this.__foo__ = value;
}
}), assert);
factory.set('__foo__', 'bar');
var obj = factory.finalize();
assert.equal(obj.__foo__, 'bar');
obj.foo = 'baz';
assert.equal(obj.__foo__, 'baz');
};
_proto6['@test combining multiple setter and getters'] = function testCombiningMultipleSetterAndGetters(assert) {
var factory = new TestClass(assert);
factory.install('foo', (0, _metal.descriptor)({
get: function () {
return this.__foo__;
},
set: function (value) {
this.__foo__ = value;
}
}), assert);
factory.set('__foo__', 'foo');
factory.install('bar', (0, _metal.descriptor)({
get: function () {
return this.__bar__;
},
set: function (value) {
this.__bar__ = value;
}
}), assert);
factory.set('__bar__', 'bar');
factory.install('fooBar', (0, _metal.descriptor)({
get: function () {
return this.foo + '-' + this.bar;
}
}), assert);
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');
assert.throws(function () {
return obj.fooBar = 'foobar';
}, TypeError);
assert.equal(obj.fooBar, 'FOO-BAR');
};
return _class6;
}(_internalTestHelpers.AbstractTestCase));
});
});
enifed("@ember/-internals/metal/tests/events_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('system/props/events_test',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test listener should receive event - removing should remove'] = function testListenerShouldReceiveEventRemovingShouldRemove(assert) {
var obj = {};
var count = 0;
function F() {
count++;
}
(0, _metal.addListener)(obj, 'event!', F);
assert.equal(count, 0, 'nothing yet');
(0, _metal.sendEvent)(obj, 'event!');
assert.equal(count, 1, 'received event');
(0, _metal.removeListener)(obj, 'event!', F);
count = 0;
(0, _metal.sendEvent)(obj, 'event!');
assert.equal(count, 0, 'received event');
};
_proto['@test listeners should be inherited'] = function testListenersShouldBeInherited(assert) {
var count = 0;
var obj = {
func: function () {
count++;
}
};
(0, _metal.addListener)(obj, 'event!', null, 'func');
var obj2 = Object.create(obj);
assert.equal(count, 0, 'nothing yet');
(0, _metal.sendEvent)(obj2, 'event!');
assert.equal(count, 1, 'received event');
(0, _metal.removeListener)(obj2, 'event!', null, 'func');
count = 0;
(0, _metal.sendEvent)(obj2, 'event!');
assert.equal(count, 0, 'did not receive event');
(0, _metal.sendEvent)(obj, 'event!');
assert.equal(count, 1, 'should still invoke on parent');
};
_proto['@test adding a listener more than once should only invoke once'] = function testAddingAListenerMoreThanOnceShouldOnlyInvokeOnce(assert) {
var count = 0;
var obj = {
func: function () {
count++;
}
};
(0, _metal.addListener)(obj, 'event!', null, 'func');
(0, _metal.addListener)(obj, 'event!', null, 'func');
(0, _metal.sendEvent)(obj, 'event!');
assert.equal(count, 1, 'should only invoke once');
};
_proto['@test adding a listener with a target should invoke with target'] = function testAddingAListenerWithATargetShouldInvokeWithTarget(assert) {
var obj = {};
var target;
target = {
count: 0,
method: function () {
this.count++;
}
};
(0, _metal.addListener)(obj, 'event!', target, target.method);
(0, _metal.sendEvent)(obj, 'event!');
assert.equal(target.count, 1, 'should invoke');
};
_proto['@test adding a listener with string method should lookup method on event delivery'] = function testAddingAListenerWithStringMethodShouldLookupMethodOnEventDelivery(assert) {
var obj = {};
var target;
target = {
count: 0,
method: function () {}
};
(0, _metal.addListener)(obj, 'event!', target, 'method');
(0, _metal.sendEvent)(obj, 'event!');
assert.equal(target.count, 0, 'should invoke but do nothing');
target.method = function () {
this.count++;
};
(0, _metal.sendEvent)(obj, 'event!');
assert.equal(target.count, 1, 'should invoke now');
};
_proto['@test calling sendEvent with extra params should be passed to listeners'] = function testCallingSendEventWithExtraParamsShouldBePassedToListeners(assert) {
var obj = {};
var params = null;
(0, _metal.addListener)(obj, 'event!', function () {
params = Array.prototype.slice.call(arguments);
});
(0, _metal.sendEvent)(obj, 'event!', ['foo', 'bar']);
assert.deepEqual(params, ['foo', 'bar'], 'params should be saved');
};
_proto['@test hasListeners tells you if there are listeners for a given event'] = function testHasListenersTellsYouIfThereAreListenersForAGivenEvent(assert) {
var obj = {};
function F() {}
function F2() {}
assert.equal((0, _metal.hasListeners)(obj, 'event!'), false, 'no listeners at first');
(0, _metal.addListener)(obj, 'event!', F);
(0, _metal.addListener)(obj, 'event!', F2);
assert.equal((0, _metal.hasListeners)(obj, 'event!'), true, 'has listeners');
(0, _metal.removeListener)(obj, 'event!', F);
assert.equal((0, _metal.hasListeners)(obj, 'event!'), true, 'has listeners');
(0, _metal.removeListener)(obj, 'event!', F2);
assert.equal((0, _metal.hasListeners)(obj, 'event!'), false, 'has no more listeners');
(0, _metal.addListener)(obj, 'event!', F);
assert.equal((0, _metal.hasListeners)(obj, 'event!'), true, 'has listeners');
};
_proto['@test calling removeListener without method should remove all listeners'] = function testCallingRemoveListenerWithoutMethodShouldRemoveAllListeners(assert) {
expectDeprecation(function () {
var obj = {};
function F() {}
function F2() {}
assert.equal((0, _metal.hasListeners)(obj, 'event!'), false, 'no listeners at first');
(0, _metal.addListener)(obj, 'event!', F);
(0, _metal.addListener)(obj, 'event!', F2);
assert.equal((0, _metal.hasListeners)(obj, 'event!'), true, 'has listeners');
(0, _metal.removeListener)(obj, 'event!');
assert.equal((0, _metal.hasListeners)(obj, 'event!'), false, 'has no more listeners');
}, /The remove all functionality of removeListener and removeObserver has been deprecated/);
};
_proto['@test a listener can be added as part of a mixin'] = function testAListenerCanBeAddedAsPartOfAMixin(assert) {
var triggered = 0;
var MyMixin = _metal.Mixin.create({
foo1: (0, _metal.on)('bar', function () {
triggered++;
}),
foo2: (0, _metal.on)('bar', function () {
triggered++;
})
});
var obj = {};
MyMixin.apply(obj);
(0, _metal.sendEvent)(obj, 'bar');
assert.equal(triggered, 2, 'should invoke listeners');
};
_proto["@test 'on' asserts for invalid arguments"] = function () {
expectAssertion(function () {
_metal.Mixin.create({
foo1: (0, _metal.on)('bar')
});
}, 'on expects function as last argument');
expectAssertion(function () {
_metal.Mixin.create({
foo1: (0, _metal.on)(function () {})
});
}, 'on called without valid event names');
};
_proto['@test a listener added as part of a mixin may be overridden'] = function testAListenerAddedAsPartOfAMixinMayBeOverridden(assert) {
var triggered = 0;
var FirstMixin = _metal.Mixin.create({
foo: (0, _metal.on)('bar', function () {
triggered++;
})
});
var SecondMixin = _metal.Mixin.create({
foo: (0, _metal.on)('baz', function () {
triggered++;
})
});
var obj = {};
FirstMixin.apply(obj);
SecondMixin.apply(obj);
(0, _metal.sendEvent)(obj, 'bar');
assert.equal(triggered, 0, 'should not invoke from overridden property');
(0, _metal.sendEvent)(obj, 'baz');
assert.equal(triggered, 1, 'should invoke from subclass property');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/expand_properties_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
var foundProperties = [];
function addProperty(property) {
foundProperties.push(property);
}
(0, _internalTestHelpers.moduleFor)('Property Brace Expansion Test',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
foundProperties = [];
};
_proto['@test Properties without expansions are unaffected'] = function testPropertiesWithoutExpansionsAreUnaffected(assert) {
assert.expect(1);
(0, _metal.expandProperties)('a', addProperty);
(0, _metal.expandProperties)('a.b', addProperty);
(0, _metal.expandProperties)('a.b.[]', addProperty);
(0, _metal.expandProperties)('a.b.@each.c', addProperty);
assert.deepEqual(['a', 'a.b', 'a.b.[]', 'a.b.@each.c'].sort(), foundProperties.sort());
};
_proto['@test A single expansion at the end expands properly'] = function testASingleExpansionAtTheEndExpandsProperly(assert) {
assert.expect(1);
(0, _metal.expandProperties)('a.b.{c,d}', addProperty);
assert.deepEqual(['a.b.c', 'a.b.d'].sort(), foundProperties.sort());
};
_proto['@test A property with only a brace expansion expands correctly'] = function testAPropertyWithOnlyABraceExpansionExpandsCorrectly(assert) {
assert.expect(1);
(0, _metal.expandProperties)('{a,b,c}', addProperty);
var expected = ['a', 'b', 'c'];
assert.deepEqual(expected.sort(), foundProperties.sort());
};
_proto['@test Expansions with single properties only expand once'] = function testExpansionsWithSinglePropertiesOnlyExpandOnce(assert) {
assert.expect(1);
(0, _metal.expandProperties)('a.b.{c}.d.{e}', addProperty);
assert.deepEqual(['a.b.c.d.e'], foundProperties);
};
_proto['@test A single brace expansion expands correctly'] = function testASingleBraceExpansionExpandsCorrectly(assert) {
assert.expect(1);
(0, _metal.expandProperties)('a.{b,c,d}.e', addProperty);
var expected = ['a.b.e', 'a.c.e', 'a.d.e'];
assert.deepEqual(expected.sort(), foundProperties.sort());
};
_proto['@test Multiple brace expansions work correctly'] = function testMultipleBraceExpansionsWorkCorrectly(assert) {
assert.expect(1);
(0, _metal.expandProperties)('{a,b,c}.d.{e,f}.g', addProperty);
var expected = ['a.d.e.g', 'a.d.f.g', 'b.d.e.g', 'b.d.f.g', 'c.d.e.g', 'c.d.f.g'];
assert.deepEqual(expected.sort(), foundProperties.sort());
};
_proto['@test A property with only brace expansions expands correctly'] = function testAPropertyWithOnlyBraceExpansionsExpandsCorrectly(assert) {
assert.expect(1);
(0, _metal.expandProperties)('{a,b,c}.{d}.{e,f}', addProperty);
var expected = ['a.d.e', 'a.d.f', 'b.d.e', 'b.d.f', 'c.d.e', 'c.d.f'];
assert.deepEqual(expected.sort(), foundProperties.sort());
};
_proto['@test Nested brace expansions are not allowed'] = function testNestedBraceExpansionsAreNotAllowed() {
var nestedBraceProperties = ['a.{b.{c,d}}', 'a.{{b}.c}', 'a.{b,c}.{d.{e,f}.g', 'a.{b.{c}', 'a.{b,c}}', 'model.{bar,baz'];
nestedBraceProperties.forEach(function (invalidProperties) {
expectAssertion(function () {
return (0, _metal.expandProperties)(invalidProperties, addProperty);
});
}, /Brace expanded properties have to be balanced and cannot be nested/);
};
_proto['@test A property with no braces does not expand'] = function testAPropertyWithNoBracesDoesNotExpand(assert) {
assert.expect(1);
(0, _metal.expandProperties)('a,b,c.d.e,f', addProperty);
assert.deepEqual(foundProperties, ['a,b,c.d.e,f']);
};
_proto['@test A pattern must be a string'] = function testAPatternMustBeAString(assert) {
assert.expect(1);
expectAssertion(function () {
(0, _metal.expandProperties)([1, 2], addProperty);
}, /A computed property key must be a string/);
};
_proto['@test A pattern must not contain a space'] = function testAPatternMustNotContainASpace(assert) {
assert.expect(1);
expectAssertion(function () {
(0, _metal.expandProperties)('{a, b}', addProperty);
}, /Brace expanded properties cannot contain spaces, e.g. "user.{firstName, lastName}" should be "user.{firstName,lastName}"/);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/injected_property_test", ["ember-babel", "@ember/-internals/owner", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _owner, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('InjectedProperty',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test injected properties should be descriptors'] = function testInjectedPropertiesShouldBeDescriptors(assert) {
assert.ok(new _metal.InjectedProperty() instanceof _metal.Descriptor);
};
_proto['@test injected properties should be overridable'] = function testInjectedPropertiesShouldBeOverridable(assert) {
var obj = {};
(0, _metal.defineProperty)(obj, 'foo', new _metal.InjectedProperty());
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar', 'should return the overridden value');
};
_proto['@test getting on an object without an owner or container should fail assertion'] = function testGettingOnAnObjectWithoutAnOwnerOrContainerShouldFailAssertion() {
var obj = {};
(0, _metal.defineProperty)(obj, 'foo', new _metal.InjectedProperty('type', 'name'));
expectAssertion(function () {
(0, _metal.get)(obj, 'foo');
}, /Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container./);
};
_proto['@test getting on an object without an owner but with a container should not fail'] = function testGettingOnAnObjectWithoutAnOwnerButWithAContainerShouldNotFail(assert) {
var obj = {
container: {
lookup: function (key) {
assert.ok(true, 'should call container.lookup');
return key;
}
}
};
(0, _metal.defineProperty)(obj, 'foo', new _metal.InjectedProperty('type', 'name'));
assert.equal((0, _metal.get)(obj, 'foo'), 'type:name', 'should return the value of container.lookup');
};
_proto['@test getting should return a lookup on the container'] = function testGettingShouldReturnALookupOnTheContainer(assert) {
assert.expect(2);
var obj = {};
(0, _owner.setOwner)(obj, {
lookup: function (key) {
assert.ok(true, 'should call container.lookup');
return key;
}
});
(0, _metal.defineProperty)(obj, 'foo', new _metal.InjectedProperty('type', 'name'));
assert.equal((0, _metal.get)(obj, 'foo'), 'type:name', 'should return the value of container.lookup');
};
_proto['@test omitting the lookup name should default to the property name'] = function testOmittingTheLookupNameShouldDefaultToThePropertyName(assert) {
var obj = {};
(0, _owner.setOwner)(obj, {
lookup: function (key) {
return key;
}
});
(0, _metal.defineProperty)(obj, 'foo', new _metal.InjectedProperty('type'));
assert.equal((0, _metal.get)(obj, 'foo'), 'type:foo', 'should lookup the type using the property name');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/is_blank_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('isBlank',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test isBlank'] = function testIsBlank(assert) {
var string = 'string';
var fn = function () {};
var object = {
length: 0
};
assert.equal(true, (0, _metal.isBlank)(null), 'for null');
assert.equal(true, (0, _metal.isBlank)(undefined), 'for undefined');
assert.equal(true, (0, _metal.isBlank)(''), 'for an empty String');
assert.equal(true, (0, _metal.isBlank)(' '), 'for a whitespace String');
assert.equal(true, (0, _metal.isBlank)('\n\t'), 'for another whitespace String');
assert.equal(false, (0, _metal.isBlank)('\n\t Hi'), 'for a String with whitespaces');
assert.equal(false, (0, _metal.isBlank)(true), 'for true');
assert.equal(false, (0, _metal.isBlank)(false), 'for false');
assert.equal(false, (0, _metal.isBlank)(string), 'for a String');
assert.equal(false, (0, _metal.isBlank)(fn), 'for a Function');
assert.equal(false, (0, _metal.isBlank)(0), 'for 0');
assert.equal(true, (0, _metal.isBlank)([]), 'for an empty Array');
assert.equal(false, (0, _metal.isBlank)({}), 'for an empty Object');
assert.equal(true, (0, _metal.isBlank)(object), "for an Object that has zero 'length'");
assert.equal(false, (0, _metal.isBlank)([1, 2, 3]), 'for a non-empty array');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/is_empty_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('isEmpty',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test isEmpty'] = function testIsEmpty(assert) {
var string = 'string';
var fn = function () {};
var object = {
length: 0
};
assert.equal(true, (0, _metal.isEmpty)(null), 'for null');
assert.equal(true, (0, _metal.isEmpty)(undefined), 'for undefined');
assert.equal(true, (0, _metal.isEmpty)(''), 'for an empty String');
assert.equal(false, (0, _metal.isEmpty)(' '), 'for a whitespace String');
assert.equal(false, (0, _metal.isEmpty)('\n\t'), 'for another whitespace String');
assert.equal(false, (0, _metal.isEmpty)(true), 'for true');
assert.equal(false, (0, _metal.isEmpty)(false), 'for false');
assert.equal(false, (0, _metal.isEmpty)(string), 'for a String');
assert.equal(false, (0, _metal.isEmpty)(fn), 'for a Function');
assert.equal(false, (0, _metal.isEmpty)(0), 'for 0');
assert.equal(true, (0, _metal.isEmpty)([]), 'for an empty Array');
assert.equal(false, (0, _metal.isEmpty)({}), 'for an empty Object');
assert.equal(true, (0, _metal.isEmpty)(object), "for an Object that has zero 'length'");
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/is_none_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('isNone',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test isNone'] = function testIsNone(assert) {
var string = 'string';
var fn = function () {};
assert.equal(true, (0, _metal.isNone)(null), 'for null');
assert.equal(true, (0, _metal.isNone)(undefined), 'for undefined');
assert.equal(false, (0, _metal.isNone)(''), 'for an empty String');
assert.equal(false, (0, _metal.isNone)(true), 'for true');
assert.equal(false, (0, _metal.isNone)(false), 'for false');
assert.equal(false, (0, _metal.isNone)(string), 'for a String');
assert.equal(false, (0, _metal.isNone)(fn), 'for a Function');
assert.equal(false, (0, _metal.isNone)(0), 'for 0');
assert.equal(false, (0, _metal.isNone)([]), 'for an empty Array');
assert.equal(false, (0, _metal.isNone)({}), 'for an empty Object');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/is_present_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('isPresent',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test isPresent'] = function testIsPresent(assert) {
var string = 'string';
var fn = function () {};
var object = {
length: 0
};
assert.equal(false, (0, _metal.isPresent)(), 'for no params');
assert.equal(false, (0, _metal.isPresent)(null), 'for null');
assert.equal(false, (0, _metal.isPresent)(undefined), 'for undefined');
assert.equal(false, (0, _metal.isPresent)(''), 'for an empty String');
assert.equal(false, (0, _metal.isPresent)(' '), 'for a whitespace String');
assert.equal(false, (0, _metal.isPresent)('\n\t'), 'for another whitespace String');
assert.equal(true, (0, _metal.isPresent)('\n\t Hi'), 'for a String with whitespaces');
assert.equal(true, (0, _metal.isPresent)(true), 'for true');
assert.equal(true, (0, _metal.isPresent)(false), 'for false');
assert.equal(true, (0, _metal.isPresent)(string), 'for a String');
assert.equal(true, (0, _metal.isPresent)(fn), 'for a Function');
assert.equal(true, (0, _metal.isPresent)(0), 'for 0');
assert.equal(false, (0, _metal.isPresent)([]), 'for an empty Array');
assert.equal(true, (0, _metal.isPresent)({}), 'for an empty Object');
assert.equal(false, (0, _metal.isPresent)(object), "for an Object that has zero 'length'");
assert.equal(true, (0, _metal.isPresent)([1, 2, 3]), 'for a non-empty array');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/libraries_test", ["ember-babel", "@ember/debug", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _debug, _metal, _internalTestHelpers) {
"use strict";
/* globals EmberDev */
var libs, registry;
var originalWarn = (0, _debug.getDebugFunction)('warn');
function noop() {}
(0, _internalTestHelpers.moduleFor)('Libraries registry',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
libs = new _metal.Libraries();
registry = libs._registry;
};
_proto.afterEach = function afterEach() {
libs = null;
registry = null;
(0, _debug.setDebugFunction)('warn', originalWarn);
};
_proto['@test core libraries come before other libraries'] = function testCoreLibrariesComeBeforeOtherLibraries(assert) {
assert.expect(2);
libs.register('my-lib', '2.0.0a');
libs.registerCoreLibrary('DS', '1.0.0-beta.2');
assert.equal(registry[0].name, 'DS');
assert.equal(registry[1].name, 'my-lib');
};
_proto['@test only the first registration of a library is stored'] = function testOnlyTheFirstRegistrationOfALibraryIsStored(assert) {
assert.expect(3); // overwrite warn to supress the double registration warning (see https://github.com/emberjs/ember.js/issues/16391)
(0, _debug.setDebugFunction)('warn', noop);
libs.register('magic', 1.23);
libs.register('magic', 2.23);
assert.equal(registry[0].name, 'magic');
assert.equal(registry[0].version, 1.23);
assert.equal(registry.length, 1);
};
_proto['@test isRegistered returns correct value'] = function testIsRegisteredReturnsCorrectValue(assert) {
if (false
/* EMBER_LIBRARIES_ISREGISTERED */
) {
assert.expect(3);
assert.equal(libs.isRegistered('magic'), false);
libs.register('magic', 1.23);
assert.equal(libs.isRegistered('magic'), true);
libs.deRegister('magic');
assert.equal(libs.isRegistered('magic'), false);
} else {
assert.expect(0);
}
};
_proto['@test attempting to register a library that is already registered warns you'] = function testAttemptingToRegisterALibraryThatIsAlreadyRegisteredWarnsYou(assert) {
if (EmberDev && EmberDev.runningProdBuild) {
assert.ok(true, 'Logging does not occur in production builds');
return;
}
assert.expect(1);
libs.register('magic', 1.23);
(0, _debug.setDebugFunction)('warn', function (msg, test) {
if (!test) {
assert.equal(msg, 'Library "magic" is already registered with Ember.');
}
}); // Should warn us
libs.register('magic', 2.23);
};
_proto['@test libraries can be de-registered'] = function testLibrariesCanBeDeRegistered(assert) {
assert.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');
assert.equal(registry[0].name, 'lib2');
assert.equal(registry.length, 1);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/main_test", ["ember-babel", "ember/version", "internal-test-helpers"], function (_emberBabel, _version, _internalTestHelpers) {
"use strict";
// From https://github.com/semver/semver.org/issues/59 & https://regex101.com/r/vW1jA8/6
var SEMVER_REGEX = /^((?:0|(?:[1-9]\d*)))\.((?:0|(?:[1-9]\d*)))\.((?:0|(?:[1-9]\d*)))(?:-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$/;
(0, _internalTestHelpers.moduleFor)('@ember/-internals/metal/core/main',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Ember.VERSION is in alignment with SemVer v2.0.0'] = function testEmberVERSIONIsInAlignmentWithSemVerV200(assert) {
assert.ok(SEMVER_REGEX.test(_version.default), "Ember.VERSION (" + _version.default + ")is valid SemVer v2.0.0");
};
_proto['@test SEMVER_REGEX properly validates and invalidates version numbers'] = function testSEMVER_REGEXProperlyValidatesAndInvalidatesVersionNumbers(assert) {
function validateVersionString(versionString, expectedResult) {
assert.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);
validateVersionString('3.1.0-foobarBaz+30d70bd3', true); // Negative test cases
validateVersionString('1.11.3.aba18a', false);
validateVersionString('1.11', false);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/mixin/alias_method_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
function validateAliasMethod(assert, obj) {
assert.equal(obj.fooMethod(), 'FOO', 'obj.fooMethod()');
assert.equal(obj.barMethod(), 'FOO', 'obj.barMethod should be a copy of foo');
}
(0, _internalTestHelpers.moduleFor)('aliasMethod',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test methods of another name are aliased when the mixin is applied'] = function testMethodsOfAnotherNameAreAliasedWhenTheMixinIsApplied(assert) {
var MyMixin = _metal.Mixin.create({
fooMethod: function () {
return 'FOO';
},
barMethod: (0, _metal.aliasMethod)('fooMethod')
});
var obj = MyMixin.apply({});
validateAliasMethod(assert, obj);
};
_proto['@test should follow aliasMethods all the way down'] = function testShouldFollowAliasMethodsAllTheWayDown(assert) {
var MyMixin = _metal.Mixin.create({
bar: (0, _metal.aliasMethod)('foo'),
// put first to break ordered iteration
baz: function () {
return 'baz';
},
foo: (0, _metal.aliasMethod)('baz')
});
var obj = MyMixin.apply({});
assert.equal((0, _metal.get)(obj, 'bar')(), 'baz', 'should have followed aliasMethods');
};
_proto['@test should alias methods from other dependent mixins'] = function testShouldAliasMethodsFromOtherDependentMixins(assert) {
var BaseMixin = _metal.Mixin.create({
fooMethod: function () {
return 'FOO';
}
});
var MyMixin = _metal.Mixin.create(BaseMixin, {
barMethod: (0, _metal.aliasMethod)('fooMethod')
});
var obj = MyMixin.apply({});
validateAliasMethod(assert, obj);
};
_proto['@test should alias methods from other mixins applied at same time'] = function testShouldAliasMethodsFromOtherMixinsAppliedAtSameTime(assert) {
var BaseMixin = _metal.Mixin.create({
fooMethod: function () {
return 'FOO';
}
});
var MyMixin = _metal.Mixin.create({
barMethod: (0, _metal.aliasMethod)('fooMethod')
});
var obj = (0, _metal.mixin)({}, BaseMixin, MyMixin);
validateAliasMethod(assert, obj);
};
_proto['@test should alias methods from mixins already applied on object'] = function testShouldAliasMethodsFromMixinsAlreadyAppliedOnObject(assert) {
var BaseMixin = _metal.Mixin.create({
quxMethod: function () {
return 'qux';
}
});
var MyMixin = _metal.Mixin.create({
bar: (0, _metal.aliasMethod)('foo'),
barMethod: (0, _metal.aliasMethod)('fooMethod')
});
var obj = {
fooMethod: function () {
return 'FOO';
}
};
BaseMixin.apply(obj);
MyMixin.apply(obj);
validateAliasMethod(assert, obj);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/mixin/apply_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
function K() {}
(0, _internalTestHelpers.moduleFor)('Mixin.apply',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test using apply() should apply properties'] = function testUsingApplyShouldApplyProperties(assert) {
var MixinA = _metal.Mixin.create({
foo: 'FOO',
baz: K
});
var obj = {};
(0, _metal.mixin)(obj, MixinA);
assert.equal((0, _metal.get)(obj, 'foo'), 'FOO', 'should apply foo');
assert.equal((0, _metal.get)(obj, 'baz'), K, 'should apply foo');
};
_proto['@test applying anonymous properties'] = function testApplyingAnonymousProperties(assert) {
var obj = {};
(0, _metal.mixin)(obj, {
foo: 'FOO',
baz: K
});
assert.equal((0, _metal.get)(obj, 'foo'), 'FOO', 'should apply foo');
assert.equal((0, _metal.get)(obj, 'baz'), K, 'should apply foo');
};
_proto['@test applying null values'] = function testApplyingNullValues() {
expectAssertion(function () {
return (0, _metal.mixin)({}, null);
});
};
_proto['@test applying a property with an undefined value'] = function testApplyingAPropertyWithAnUndefinedValue(assert) {
var obj = {
tagName: ''
};
(0, _metal.mixin)(obj, {
tagName: undefined
});
assert.strictEqual((0, _metal.get)(obj, 'tagName'), '');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/mixin/computed_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
function K() {
return this;
}
(0, _internalTestHelpers.moduleFor)('Mixin Computed Properties',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test overriding computed properties'] = function testOverridingComputedProperties(assert) {
var MixinA, MixinB, MixinC, MixinD;
var obj;
MixinA = _metal.Mixin.create({
aProp: (0, _metal.computed)(function () {
return 'A';
})
});
MixinB = _metal.Mixin.create(MixinA, {
aProp: (0, _metal.computed)(function () {
return this._super.apply(this, arguments) + 'B';
})
});
MixinC = _metal.Mixin.create(MixinA, {
aProp: (0, _metal.computed)(function () {
return this._super.apply(this, arguments) + 'C';
})
});
MixinD = _metal.Mixin.create({
aProp: (0, _metal.computed)(function () {
return this._super.apply(this, arguments) + 'D';
})
});
obj = {};
MixinB.apply(obj);
assert.equal((0, _metal.get)(obj, 'aProp'), 'AB', 'should expose super for B');
obj = {};
MixinC.apply(obj);
assert.equal((0, _metal.get)(obj, 'aProp'), 'AC', 'should expose super for C');
obj = {};
MixinA.apply(obj);
MixinD.apply(obj);
assert.equal((0, _metal.get)(obj, 'aProp'), 'AD', 'should define super for D');
obj = {};
(0, _metal.defineProperty)(obj, 'aProp', (0, _metal.computed)(function () {
return 'obj';
}));
MixinD.apply(obj);
assert.equal((0, _metal.get)(obj, 'aProp'), 'objD', 'should preserve original computed property');
};
_proto['@test calling set on overridden computed properties'] = function testCallingSetOnOverriddenComputedProperties(assert) {
var SuperMixin, SubMixin;
var obj;
var superGetOccurred = false;
var superSetOccurred = false;
SuperMixin = _metal.Mixin.create({
aProp: (0, _metal.computed)({
get: function () {
superGetOccurred = true;
},
set: function () {
superSetOccurred = true;
}
})
});
SubMixin = _metal.Mixin.create(SuperMixin, {
aProp: (0, _metal.computed)({
get: function () {
return this._super.apply(this, arguments);
},
set: function () {
return this._super.apply(this, arguments);
}
})
});
obj = {};
SubMixin.apply(obj);
(0, _metal.set)(obj, 'aProp', 'set thyself');
assert.ok(superSetOccurred, 'should pass set to _super');
superSetOccurred = false; // reset the set assertion
obj = {};
SubMixin.apply(obj);
(0, _metal.get)(obj, 'aProp');
assert.ok(superGetOccurred, 'should pass get to _super');
(0, _metal.set)(obj, 'aProp', 'set thyself');
assert.ok(superSetOccurred, 'should pass set to _super after getting');
};
_proto['@test setter behavior works properly when overriding computed properties'] = function testSetterBehaviorWorksProperlyWhenOverridingComputedProperties(assert) {
var obj = {};
var MixinA = _metal.Mixin.create({
cpWithSetter2: (0, _metal.computed)(K),
cpWithSetter3: (0, _metal.computed)(K),
cpWithoutSetter: (0, _metal.computed)(K)
});
var cpWasCalled = false;
var MixinB = _metal.Mixin.create({
cpWithSetter2: (0, _metal.computed)({
get: K,
set: function () {
cpWasCalled = true;
}
}),
cpWithSetter3: (0, _metal.computed)({
get: K,
set: function () {
cpWasCalled = true;
}
}),
cpWithoutSetter: (0, _metal.computed)(function () {
cpWasCalled = true;
})
});
MixinA.apply(obj);
MixinB.apply(obj);
(0, _metal.set)(obj, 'cpWithSetter2', 'test');
assert.ok(cpWasCalled, 'The computed property setter was called when defined with two args');
cpWasCalled = false;
(0, _metal.set)(obj, 'cpWithSetter3', 'test');
assert.ok(cpWasCalled, 'The computed property setter was called when defined with three args');
cpWasCalled = false;
(0, _metal.set)(obj, 'cpWithoutSetter', 'test');
assert.equal((0, _metal.get)(obj, 'cpWithoutSetter'), 'test', 'The default setter was called, the value is correct');
assert.ok(!cpWasCalled, 'The default setter was called, not the CP itself');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/mixin/concatenated_properties_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Mixin concatenatedProperties',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test defining concatenated properties should concat future version'] = function testDefiningConcatenatedPropertiesShouldConcatFutureVersion(assert) {
var MixinA = _metal.Mixin.create({
concatenatedProperties: ['foo'],
foo: ['a', 'b', 'c']
});
var MixinB = _metal.Mixin.create({
foo: ['d', 'e', 'f']
});
var obj = (0, _metal.mixin)({}, MixinA, MixinB);
assert.deepEqual((0, _metal.get)(obj, 'foo'), ['a', 'b', 'c', 'd', 'e', 'f']);
};
_proto['@test defining concatenated properties should concat future version'] = function testDefiningConcatenatedPropertiesShouldConcatFutureVersion(assert) {
var MixinA = _metal.Mixin.create({
concatenatedProperties: null
});
var MixinB = _metal.Mixin.create({
concatenatedProperties: null
});
var obj = (0, _metal.mixin)({}, MixinA, MixinB);
assert.deepEqual(obj.concatenatedProperties, []);
};
_proto['@test concatenatedProperties should be concatenated'] = function testConcatenatedPropertiesShouldBeConcatenated(assert) {
var MixinA = _metal.Mixin.create({
concatenatedProperties: ['foo'],
foo: ['a', 'b', 'c']
});
var MixinB = _metal.Mixin.create({
concatenatedProperties: 'bar',
foo: ['d', 'e', 'f'],
bar: [1, 2, 3]
});
var MixinC = _metal.Mixin.create({
bar: [4, 5, 6]
});
var obj = (0, _metal.mixin)({}, MixinA, MixinB, MixinC);
assert.deepEqual((0, _metal.get)(obj, 'concatenatedProperties'), ['foo', 'bar'], 'get concatenatedProperties');
assert.deepEqual((0, _metal.get)(obj, 'foo'), ['a', 'b', 'c', 'd', 'e', 'f'], 'get foo');
assert.deepEqual((0, _metal.get)(obj, 'bar'), [1, 2, 3, 4, 5, 6], 'get bar');
};
_proto['@test adding a prop that is not an array should make array'] = function testAddingAPropThatIsNotAnArrayShouldMakeArray(assert) {
var MixinA = _metal.Mixin.create({
concatenatedProperties: ['foo'],
foo: [1, 2, 3]
});
var MixinB = _metal.Mixin.create({
foo: 4
});
var obj = (0, _metal.mixin)({}, MixinA, MixinB);
assert.deepEqual((0, _metal.get)(obj, 'foo'), [1, 2, 3, 4]);
};
_proto['@test adding a prop that is not an array should make array'] = function testAddingAPropThatIsNotAnArrayShouldMakeArray(assert) {
var MixinA = _metal.Mixin.create({
concatenatedProperties: ['foo'],
foo: 'bar'
});
var obj = (0, _metal.mixin)({}, MixinA);
assert.deepEqual((0, _metal.get)(obj, 'foo'), ['bar']);
};
_proto['@test adding a non-concatenable property that already has a defined value should result in an array with both values'] = function testAddingANonConcatenablePropertyThatAlreadyHasADefinedValueShouldResultInAnArrayWithBothValues(assert) {
var mixinA = _metal.Mixin.create({
foo: 1
});
var mixinB = _metal.Mixin.create({
concatenatedProperties: ['foo'],
foo: 2
});
var obj = (0, _metal.mixin)({}, mixinA, mixinB);
assert.deepEqual((0, _metal.get)(obj, 'foo'), [1, 2]);
};
_proto['@test adding a concatenable property that already has a defined value should result in a concatenated value'] = function testAddingAConcatenablePropertyThatAlreadyHasADefinedValueShouldResultInAConcatenatedValue(assert) {
var mixinA = _metal.Mixin.create({
foobar: 'foo'
});
var mixinB = _metal.Mixin.create({
concatenatedProperties: ['foobar'],
foobar: 'bar'
});
var obj = (0, _metal.mixin)({}, mixinA, mixinB);
assert.deepEqual((0, _metal.get)(obj, 'foobar'), ['foo', 'bar']);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/mixin/detect_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Mixin.detect',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test detect() finds a directly applied mixin'] = function testDetectFindsADirectlyAppliedMixin(assert) {
var MixinA = _metal.Mixin.create();
var obj = {};
assert.equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()');
MixinA.apply(obj);
assert.equal(MixinA.detect(obj), true, 'MixinA.detect(obj) after apply()');
};
_proto['@test detect() finds nested mixins'] = function testDetectFindsNestedMixins(assert) {
var MixinA = _metal.Mixin.create({});
var MixinB = _metal.Mixin.create(MixinA);
var obj = {};
assert.equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()');
MixinB.apply(obj);
assert.equal(MixinA.detect(obj), true, 'MixinA.detect(obj) after apply()');
};
_proto['@test detect() finds mixins on other mixins'] = function testDetectFindsMixinsOnOtherMixins(assert) {
var MixinA = _metal.Mixin.create({});
var MixinB = _metal.Mixin.create(MixinA);
assert.equal(MixinA.detect(MixinB), true, 'MixinA is part of MixinB');
assert.equal(MixinB.detect(MixinA), false, 'MixinB is not part of MixinA');
};
_proto['@test detect handles null values'] = function testDetectHandlesNullValues(assert) {
var MixinA = _metal.Mixin.create();
assert.equal(MixinA.detect(null), false);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/mixin/introspection_test", ["ember-babel", "@ember/-internals/utils", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _utils, _metal, _internalTestHelpers) {
"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 = _metal.Mixin.create({
_foo: '_FOO'
});
var PublicProperty = _metal.Mixin.create({
foo: 'FOO'
});
var PrivateMethod = _metal.Mixin.create({
_fooMethod: function () {}
});
var PublicMethod = _metal.Mixin.create({
fooMethod: function () {}
});
var BarProperties = _metal.Mixin.create({
_bar: '_BAR',
bar: 'bar'
});
var BarMethods = _metal.Mixin.create({
_barMethod: function () {},
barMethod: function () {}
});
var Combined = _metal.Mixin.create(BarProperties, BarMethods);
var obj;
(0, _internalTestHelpers.moduleFor)('Basic introspection',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
obj = {};
(0, _metal.mixin)(obj, PrivateProperty, PublicProperty, PrivateMethod, PublicMethod, Combined);
};
_proto['@test Ember.mixins()'] = function testEmberMixins(assert) {
function mapGuids(ary) {
return ary.map(function (x) {
return (0, _utils.guidFor)(x);
});
}
assert.deepEqual(mapGuids(_metal.Mixin.mixins(obj)), mapGuids([PrivateProperty, PublicProperty, PrivateMethod, PublicMethod, Combined, BarProperties, BarMethods]), 'should return included mixins');
};
_proto['@test setting a NAME_KEY on a mixin does not error'] = function testSettingANAME_KEYOnAMixinDoesNotError(assert) {
assert.expect(0);
var instance = _metal.Mixin.create();
instance[_utils.NAME_KEY] = 'My special name!';
};
_proto['@test setting a NAME_KEY on a mixin instance does not error'] = function testSettingANAME_KEYOnAMixinInstanceDoesNotError(assert) {
var _Mixin$create;
assert.expect(0);
_metal.Mixin.create((_Mixin$create = {}, _Mixin$create[_utils.NAME_KEY] = 'My special name', _Mixin$create));
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/mixin/merged_properties_test", ["ember-babel", "@ember/-internals/runtime", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _runtime, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Mixin mergedProperties',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test defining mergedProperties should merge future version'] = function testDefiningMergedPropertiesShouldMergeFutureVersion(assert) {
var MixinA = _metal.Mixin.create({
mergedProperties: ['foo'],
foo: {
a: true,
b: true,
c: true
}
});
var MixinB = _metal.Mixin.create({
foo: {
d: true,
e: true,
f: true
}
});
var obj = (0, _metal.mixin)({}, MixinA, MixinB);
assert.deepEqual((0, _metal.get)(obj, 'foo'), {
a: true,
b: true,
c: true,
d: true,
e: true,
f: true
});
};
_proto['@test defining mergedProperties on future mixin should merged into past'] = function testDefiningMergedPropertiesOnFutureMixinShouldMergedIntoPast(assert) {
var MixinA = _metal.Mixin.create({
foo: {
a: true,
b: true,
c: true
}
});
var MixinB = _metal.Mixin.create({
mergedProperties: ['foo'],
foo: {
d: true,
e: true,
f: true
}
});
var obj = (0, _metal.mixin)({}, MixinA, MixinB);
assert.deepEqual((0, _metal.get)(obj, 'foo'), {
a: true,
b: true,
c: true,
d: true,
e: true,
f: true
});
};
_proto['@test defining mergedProperties with null properties should keep properties null'] = function testDefiningMergedPropertiesWithNullPropertiesShouldKeepPropertiesNull(assert) {
var MixinA = _metal.Mixin.create({
mergedProperties: ['foo'],
foo: null
});
var MixinB = _metal.Mixin.create({
foo: null
});
var obj = (0, _metal.mixin)({}, MixinA, MixinB);
assert.equal((0, _metal.get)(obj, 'foo'), null);
};
_proto["@test mergedProperties' properties can get overwritten"] = function testMergedPropertiesPropertiesCanGetOverwritten(assert) {
var MixinA = _metal.Mixin.create({
mergedProperties: ['foo'],
foo: {
a: 1
}
});
var MixinB = _metal.Mixin.create({
foo: {
a: 2
}
});
var obj = (0, _metal.mixin)({}, MixinA, MixinB);
assert.deepEqual((0, _metal.get)(obj, 'foo'), {
a: 2
});
};
_proto['@test mergedProperties should be concatenated'] = function testMergedPropertiesShouldBeConcatenated(assert) {
var MixinA = _metal.Mixin.create({
mergedProperties: ['foo'],
foo: {
a: true,
b: true,
c: true
}
});
var MixinB = _metal.Mixin.create({
mergedProperties: 'bar',
foo: {
d: true,
e: true,
f: true
},
bar: {
a: true,
l: true
}
});
var MixinC = _metal.Mixin.create({
bar: {
e: true,
x: true
}
});
var obj = (0, _metal.mixin)({}, MixinA, MixinB, MixinC);
assert.deepEqual((0, _metal.get)(obj, 'mergedProperties'), ['foo', 'bar'], 'get mergedProperties');
assert.deepEqual((0, _metal.get)(obj, 'foo'), {
a: true,
b: true,
c: true,
d: true,
e: true,
f: true
}, 'get foo');
assert.deepEqual((0, _metal.get)(obj, 'bar'), {
a: true,
l: true,
e: true,
x: true
}, 'get bar');
};
_proto['@test mergedProperties should exist even if not explicitly set on create'] = function testMergedPropertiesShouldExistEvenIfNotExplicitlySetOnCreate(assert) {
var AnObj = _runtime.Object.extend({
mergedProperties: ['options'],
options: {
a: 'a',
b: {
c: 'ccc'
}
}
});
var obj = AnObj.create({
options: {
a: 'A'
}
});
assert.equal((0, _metal.get)(obj, 'options').a, 'A');
assert.equal((0, _metal.get)(obj, 'options').b.c, 'ccc');
};
_proto['@test defining mergedProperties at create time should not modify the prototype'] = function testDefiningMergedPropertiesAtCreateTimeShouldNotModifyThePrototype(assert) {
var AnObj = _runtime.Object.extend({
mergedProperties: ['options'],
options: {
a: 1
}
});
var objA = AnObj.create({
options: {
a: 2
}
});
var objB = AnObj.create({
options: {
a: 3
}
});
assert.equal((0, _metal.get)(objA, 'options').a, 2);
assert.equal((0, _metal.get)(objB, 'options').a, 3);
};
_proto["@test mergedProperties' overwriting methods can call _super"] = function testMergedPropertiesOverwritingMethodsCanCall_super(assert) {
assert.expect(4);
var MixinA = _metal.Mixin.create({
mergedProperties: ['foo'],
foo: {
meth: function (a) {
assert.equal(a, 'WOOT', "_super successfully called MixinA's `foo.meth` method");
return 'WAT';
}
}
});
var MixinB = _metal.Mixin.create({
foo: {
meth: function () {
assert.ok(true, "MixinB's `foo.meth` method called");
return this._super.apply(this, arguments);
}
}
});
var MixinC = _metal.Mixin.create({
foo: {
meth: function (a) {
assert.ok(true, "MixinC's `foo.meth` method called");
return this._super(a);
}
}
});
var obj = (0, _metal.mixin)({}, MixinA, MixinB, MixinC);
assert.equal(obj.foo.meth('WOOT'), 'WAT');
};
_proto['@test Merging an Array should raise an error'] = function testMergingAnArrayShouldRaiseAnError(assert) {
assert.expect(1);
var MixinA = _metal.Mixin.create({
mergedProperties: ['foo'],
foo: {
a: true,
b: true,
c: true
}
});
var MixinB = _metal.Mixin.create({
foo: ['a']
});
expectAssertion(function () {
(0, _metal.mixin)({}, MixinA, MixinB);
}, 'You passed in `["a"]` as the value for `foo` but `foo` cannot be an Array');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/mixin/method_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Mixin Methods',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test defining simple methods'] = function testDefiningSimpleMethods(assert) {
var MixinA, obj, props;
props = {
publicMethod: function () {
return 'publicMethod';
},
_privateMethod: function () {
return 'privateMethod';
}
};
MixinA = _metal.Mixin.create(props);
obj = {};
MixinA.apply(obj); // but should be defined
assert.equal(props.publicMethod(), 'publicMethod', 'publicMethod is func');
assert.equal(props._privateMethod(), 'privateMethod', 'privateMethod is func');
};
_proto['@test overriding public methods'] = function testOverridingPublicMethods(assert) {
var MixinA, MixinB, MixinD, MixinF, obj;
MixinA = _metal.Mixin.create({
publicMethod: function () {
return 'A';
}
});
MixinB = _metal.Mixin.create(MixinA, {
publicMethod: function () {
return this._super.apply(this, arguments) + 'B';
}
});
MixinD = _metal.Mixin.create(MixinA, {
publicMethod: function () {
return this._super.apply(this, arguments) + 'D';
}
});
MixinF = _metal.Mixin.create({
publicMethod: function () {
return this._super.apply(this, arguments) + 'F';
}
});
obj = {};
MixinB.apply(obj);
assert.equal(obj.publicMethod(), 'AB', 'should define super for A and B');
obj = {};
MixinD.apply(obj);
assert.equal(obj.publicMethod(), 'AD', 'should define super for A and B');
obj = {};
MixinA.apply(obj);
MixinF.apply(obj);
assert.equal(obj.publicMethod(), 'AF', 'should define super for A and F');
obj = {
publicMethod: function () {
return 'obj';
}
};
MixinF.apply(obj);
assert.equal(obj.publicMethod(), 'objF', 'should define super for F');
};
_proto['@test overriding inherited objects'] = function testOverridingInheritedObjects(assert) {
var cnt = 0;
var MixinA = _metal.Mixin.create({
foo: function () {
cnt++;
}
});
var MixinB = _metal.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();
assert.equal(cnt, 2, 'should invoke both methods');
cnt = 0;
objA.foo();
assert.equal(cnt, 1, 'should not screw w/ parent obj');
};
_proto['@test Including the same mixin more than once will only run once'] = function testIncludingTheSameMixinMoreThanOnceWillOnlyRunOnce(assert) {
var cnt = 0;
var MixinA = _metal.Mixin.create({
foo: function () {
cnt++;
}
});
var MixinB = _metal.Mixin.create(MixinA, {
foo: function () {
this._super.apply(this, arguments);
}
});
var MixinC = _metal.Mixin.create(MixinA, {
foo: function () {
this._super.apply(this, arguments);
}
});
var MixinD = _metal.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();
assert.equal(cnt, 1, 'should invoke MixinA.foo one time');
};
_proto['@test _super from a single mixin with no superclass does not error'] = function test_superFromASingleMixinWithNoSuperclassDoesNotError(assert) {
var MixinA = _metal.Mixin.create({
foo: function () {
this._super.apply(this, arguments);
}
});
var obj = {};
MixinA.apply(obj);
obj.foo();
assert.ok(true);
};
_proto['@test _super from a first-of-two mixins with no superclass function does not error'] = function test_superFromAFirstOfTwoMixinsWithNoSuperclassFunctionDoesNotError(assert) {
// _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 = _metal.Mixin.create({
foo: function () {
if (remaining-- > 0) {
this._super.apply(this, arguments);
}
}
});
var MixinB = _metal.Mixin.create({
foo: function () {
this._super.apply(this, arguments);
}
});
var obj = {};
MixinA.apply(obj);
MixinB.apply(obj);
obj.foo();
assert.ok(true);
};
return _class;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// CONFLICTS
//
(0, _internalTestHelpers.moduleFor)('Method Conflicts',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test overriding toString'] = function testOverridingToString(assert) {
var MixinA = _metal.Mixin.create({
toString: function () {
return 'FOO';
}
});
var obj = {};
MixinA.apply(obj);
assert.equal(obj.toString(), 'FOO', 'should override toString w/o error');
obj = {};
(0, _metal.mixin)(obj, {
toString: function () {
return 'FOO';
}
});
assert.equal(obj.toString(), 'FOO', 'should override toString w/o error');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// BUGS
//
(0, _internalTestHelpers.moduleFor)('system/mixin/method_test BUGS',
/*#__PURE__*/
function (_AbstractTestCase3) {
(0, _emberBabel.inheritsLoose)(_class3, _AbstractTestCase3);
function _class3() {
return _AbstractTestCase3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3['@test applying several mixins at once with sup already defined causes infinite loop'] = function testApplyingSeveralMixinsAtOnceWithSupAlreadyDefinedCausesInfiniteLoop(assert) {
var cnt = 0;
var MixinA = _metal.Mixin.create({
foo: function () {
cnt++;
}
});
var MixinB = _metal.Mixin.create({
foo: function () {
this._super.apply(this, arguments);
cnt++;
}
});
var MixinC = _metal.Mixin.create({
foo: function () {
this._super.apply(this, arguments);
cnt++;
}
});
var obj = {};
(0, _metal.mixin)(obj, MixinA); // sup already exists
(0, _metal.mixin)(obj, MixinB, MixinC); // must be more than one mixin
cnt = 0;
obj.foo();
assert.equal(cnt, 3, 'should invoke all 3 methods');
};
return _class3;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/mixin/observer_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Mixin observer',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test global observer helper'] = function testGlobalObserverHelper(assert) {
var MyMixin = _metal.Mixin.create({
count: 0,
foo: (0, _metal.observer)('bar', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj = (0, _metal.mixin)({}, MyMixin);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj, 'bar', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
_proto['@test global observer helper takes multiple params'] = function testGlobalObserverHelperTakesMultipleParams(assert) {
var MyMixin = _metal.Mixin.create({
count: 0,
foo: (0, _metal.observer)('bar', 'baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj = (0, _metal.mixin)({}, MyMixin);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj, 'bar', 'BAZ');
(0, _metal.set)(obj, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 2, 'should invoke observer after change');
};
_proto['@test replacing observer should remove old observer'] = function testReplacingObserverShouldRemoveOldObserver(assert) {
var MyMixin = _metal.Mixin.create({
count: 0,
foo: (0, _metal.observer)('bar', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var Mixin2 = _metal.Mixin.create({
foo: (0, _metal.observer)('baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 10);
})
});
var obj = (0, _metal.mixin)({}, MyMixin, Mixin2);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj, 'bar', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer after change');
(0, _metal.set)(obj, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 10, 'should invoke observer after change');
};
_proto['@test observing chain with property before'] = function testObservingChainWithPropertyBefore(assert) {
var obj2 = {
baz: 'baz'
};
var MyMixin = _metal.Mixin.create({
count: 0,
bar: obj2,
foo: (0, _metal.observer)('bar.baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj = (0, _metal.mixin)({}, MyMixin);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj2, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
_proto['@test observing chain with property after'] = function testObservingChainWithPropertyAfter(assert) {
var obj2 = {
baz: 'baz'
};
var MyMixin = _metal.Mixin.create({
count: 0,
foo: (0, _metal.observer)('bar.baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
}),
bar: obj2
});
var obj = (0, _metal.mixin)({}, MyMixin);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj2, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
_proto['@test observing chain with property in mixin applied later'] = function testObservingChainWithPropertyInMixinAppliedLater(assert) {
var obj2 = {
baz: 'baz'
};
var MyMixin = _metal.Mixin.create({
count: 0,
foo: (0, _metal.observer)('bar.baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var MyMixin2 = _metal.Mixin.create({
bar: obj2
});
var obj = (0, _metal.mixin)({}, MyMixin);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
MyMixin2.apply(obj);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj2, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
_proto['@test observing chain with existing property'] = function testObservingChainWithExistingProperty(assert) {
var obj2 = {
baz: 'baz'
};
var MyMixin = _metal.Mixin.create({
count: 0,
foo: (0, _metal.observer)('bar.baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj = (0, _metal.mixin)({
bar: obj2
}, MyMixin);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj2, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
_proto['@test observing chain with property in mixin before'] = function testObservingChainWithPropertyInMixinBefore(assert) {
var obj2 = {
baz: 'baz'
};
var MyMixin2 = _metal.Mixin.create({
bar: obj2
});
var MyMixin = _metal.Mixin.create({
count: 0,
foo: (0, _metal.observer)('bar.baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj = (0, _metal.mixin)({}, MyMixin2, MyMixin);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj2, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
_proto['@test observing chain with property in mixin after'] = function testObservingChainWithPropertyInMixinAfter(assert) {
var obj2 = {
baz: 'baz'
};
var MyMixin2 = _metal.Mixin.create({
bar: obj2
});
var MyMixin = _metal.Mixin.create({
count: 0,
foo: (0, _metal.observer)('bar.baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj = (0, _metal.mixin)({}, MyMixin, MyMixin2);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj2, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
_proto['@test observing chain with overridden property'] = function testObservingChainWithOverriddenProperty(assert) {
var obj2 = {
baz: 'baz'
};
var obj3 = {
baz: 'foo'
};
var MyMixin2 = _metal.Mixin.create({
bar: obj3
});
var MyMixin = _metal.Mixin.create({
count: 0,
foo: (0, _metal.observer)('bar.baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj = (0, _metal.mixin)({
bar: obj2
}, MyMixin, MyMixin2);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
assert.equal((0, _metal.isWatching)(obj2, 'baz'), false, 'should not be watching baz');
assert.equal((0, _metal.isWatching)(obj3, 'baz'), true, 'should be watching baz');
(0, _metal.set)(obj2, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer after change');
(0, _metal.set)(obj3, 'baz', 'BEAR');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/mixin/reopen_test", ["ember-babel", "@ember/-internals/runtime", "@ember/-internals/metal", "@ember/runloop", "internal-test-helpers"], function (_emberBabel, _runtime, _metal, _runloop, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Mixin#reopen',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test using reopen() to add more properties to a simple'] = function testUsingReopenToAddMorePropertiesToASimple(assert) {
var MixinA = _metal.Mixin.create({
foo: 'FOO',
baz: 'BAZ'
});
MixinA.reopen({
bar: 'BAR',
foo: 'FOO2'
});
var obj = {};
MixinA.apply(obj);
assert.equal((0, _metal.get)(obj, 'foo'), 'FOO2', 'mixin() should override');
assert.equal((0, _metal.get)(obj, 'baz'), 'BAZ', 'preserve MixinA props');
assert.equal((0, _metal.get)(obj, 'bar'), 'BAR', 'include MixinB props');
};
_proto['@test using reopen() and calling _super where there is not a super function does not cause infinite recursion'] = function testUsingReopenAndCalling_superWhereThereIsNotASuperFunctionDoesNotCauseInfiniteRecursion(assert) {
var Taco = _runtime.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;
(0, _runloop.run)(function () {
try {
result = taco.createBreakfast();
} catch (e) {
result = 'Your breakfast was interrupted by an infinite stack error.';
}
});
assert.equal(result, 'Breakfast!');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/mixin/without_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('without',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test without should create a new mixin excluding named properties'] = function testWithoutShouldCreateANewMixinExcludingNamedProperties(assert) {
var MixinA = _metal.Mixin.create({
foo: 'FOO',
bar: 'BAR'
});
var MixinB = MixinA.without('bar');
var obj = {};
MixinB.apply(obj);
assert.equal(obj.foo, 'FOO', 'should defined foo');
assert.equal(obj.bar, undefined, 'should not define bar');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/namespace_search_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('NamespaceSearch',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test classToString: null as this inside class must not throw error'] = function testClassToStringNullAsThisInsideClassMustNotThrowError(assert) {
var mixin = _metal.Mixin.create();
assert.equal(mixin.toString(), '(unknown)', 'this = null should be handled on Mixin.toString() call');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/observer_test", ["ember-babel", "@ember/-internals/environment", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _environment, _metal, _internalTestHelpers) {
"use strict";
function K() {} // ..........................................................
// ADD OBSERVER
//
(0, _internalTestHelpers.moduleFor)('addObserver',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test observer should assert to invalid input'] = function testObserverShouldAssertToInvalidInput() {
expectAssertion(function () {
(0, _metal.observer)(function () {});
}, 'observer called without valid path');
expectAssertion(function () {
(0, _metal.observer)(null);
}, 'observer called without a function');
};
_proto['@test observer should fire when property is modified'] = function testObserverShouldFireWhenPropertyIsModified(assert) {
var obj = {};
var count = 0;
(0, _metal.addObserver)(obj, 'foo', function () {
assert.equal((0, _metal.get)(obj, 'foo'), 'bar', 'should invoke AFTER value changed');
count++;
});
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(count, 1, 'should have invoked observer');
};
_proto['@test observer should fire when dependent property is modified'] = function testObserverShouldFireWhenDependentPropertyIsModified(assert) {
var obj = {
bar: 'bar'
};
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)(function () {
return (0, _metal.get)(this, 'bar').toUpperCase();
}).property('bar'));
(0, _metal.get)(obj, 'foo');
var count = 0;
(0, _metal.addObserver)(obj, 'foo', function () {
assert.equal((0, _metal.get)(obj, 'foo'), 'BAZ', 'should have invoked after prop change');
count++;
});
(0, _metal.set)(obj, 'bar', 'baz');
assert.equal(count, 1, 'should have invoked observer');
};
_proto['@test observer should continue to fire after dependent properties are accessed'] = function testObserverShouldContinueToFireAfterDependentPropertiesAreAccessed(assert) {
var observerCount = 0;
var obj = {};
(0, _metal.defineProperty)(obj, 'prop', (0, _metal.computed)(function () {
return Math.random();
}));
(0, _metal.defineProperty)(obj, 'anotherProp', (0, _metal.computed)('prop', function () {
return (0, _metal.get)(this, 'prop') + Math.random();
}));
(0, _metal.addObserver)(obj, 'prop', function () {
observerCount++;
});
(0, _metal.get)(obj, 'anotherProp');
for (var i = 0; i < 10; i++) {
(0, _metal.notifyPropertyChange)(obj, 'prop');
}
assert.equal(observerCount, 10, 'should continue to fire indefinitely');
};
_proto['@test observer added declaratively via brace expansion should fire when property changes'] = function testObserverAddedDeclarativelyViaBraceExpansionShouldFireWhenPropertyChanges(assert) {
if (_environment.ENV.EXTEND_PROTOTYPES.Function) {
var _obj = {};
var _count = 0;
(0, _metal.mixin)(_obj, {
observeFooAndBar: function () {
_count++;
}.observes('{foo,bar}')
});
(0, _metal.set)(_obj, 'foo', 'foo');
assert.equal(_count, 1, 'observer specified via brace expansion invoked on property change');
(0, _metal.set)(_obj, 'bar', 'bar');
assert.equal(_count, 2, 'observer specified via brace expansion invoked on property change');
(0, _metal.set)(_obj, 'baz', 'baz');
assert.equal(_count, 2, 'observer not invoked on unspecified property');
} else {
assert.expect(0);
}
};
_proto['@test observer specified declaratively via brace expansion should fire when dependent property changes'] = function testObserverSpecifiedDeclarativelyViaBraceExpansionShouldFireWhenDependentPropertyChanges(assert) {
if (_environment.ENV.EXTEND_PROTOTYPES.Function) {
var _obj2 = {
baz: 'Initial'
};
var _count2 = 0;
(0, _metal.defineProperty)(_obj2, 'foo', (0, _metal.computed)(function () {
return (0, _metal.get)(this, 'bar').toLowerCase();
}).property('bar'));
(0, _metal.defineProperty)(_obj2, 'bar', (0, _metal.computed)(function () {
return (0, _metal.get)(this, 'baz').toUpperCase();
}).property('baz'));
(0, _metal.mixin)(_obj2, {
fooAndBarWatcher: function () {
_count2++;
}.observes('{foo,bar}')
});
(0, _metal.get)(_obj2, 'foo');
(0, _metal.set)(_obj2, 'baz', 'Baz'); // fire once for foo, once for bar
assert.equal(_count2, 2, 'observer specified via brace expansion invoked on dependent property change');
(0, _metal.set)(_obj2, 'quux', 'Quux');
assert.equal(_count2, 2, 'observer not fired on unspecified property');
} else {
assert.expect(0);
}
};
_proto['@test observers watching multiple properties via brace expansion should fire when the properties change'] = function testObserversWatchingMultiplePropertiesViaBraceExpansionShouldFireWhenThePropertiesChange(assert) {
var obj = {};
var count = 0;
(0, _metal.mixin)(obj, {
observeFooAndBar: (0, _metal.observer)('{foo,bar}', function () {
count++;
})
});
(0, _metal.set)(obj, 'foo', 'foo');
assert.equal(count, 1, 'observer specified via brace expansion invoked on property change');
(0, _metal.set)(obj, 'bar', 'bar');
assert.equal(count, 2, 'observer specified via brace expansion invoked on property change');
(0, _metal.set)(obj, 'baz', 'baz');
assert.equal(count, 2, 'observer not invoked on unspecified property');
};
_proto['@test observers watching multiple properties via brace expansion should fire when dependent properties change'] = function testObserversWatchingMultiplePropertiesViaBraceExpansionShouldFireWhenDependentPropertiesChange(assert) {
var obj = {
baz: 'Initial'
};
var count = 0;
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)(function () {
return (0, _metal.get)(this, 'bar').toLowerCase();
}).property('bar'));
(0, _metal.defineProperty)(obj, 'bar', (0, _metal.computed)(function () {
return (0, _metal.get)(this, 'baz').toUpperCase();
}).property('baz'));
(0, _metal.mixin)(obj, {
fooAndBarWatcher: (0, _metal.observer)('{foo,bar}', function () {
count++;
})
});
(0, _metal.get)(obj, 'foo');
(0, _metal.set)(obj, 'baz', 'Baz'); // fire once for foo, once for bar
assert.equal(count, 2, 'observer specified via brace expansion invoked on dependent property change');
(0, _metal.set)(obj, 'quux', 'Quux');
assert.equal(count, 2, 'observer not fired on unspecified property');
};
_proto['@test nested observers should fire in order'] = function testNestedObserversShouldFireInOrder(assert) {
var obj = {
foo: 'foo',
bar: 'bar'
};
var fooCount = 0;
var barCount = 0;
(0, _metal.addObserver)(obj, 'foo', function () {
fooCount++;
});
(0, _metal.addObserver)(obj, 'bar', function () {
(0, _metal.set)(obj, 'foo', 'BAZ');
assert.equal(fooCount, 1, 'fooCount should have fired already');
barCount++;
});
(0, _metal.set)(obj, 'bar', 'BIFF');
assert.equal(barCount, 1, 'barCount should have fired');
assert.equal(fooCount, 1, 'foo should have fired');
};
_proto['@test removing an chain observer on change should not fail'] = function testRemovingAnChainObserverOnChangeShouldNotFail(assert) {
var foo = {
bar: 'bar'
};
var obj1 = {
foo: foo
};
var obj2 = {
foo: foo
};
var obj3 = {
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 observer3() {
count3++;
(0, _metal.removeObserver)(obj1, 'foo.bar', observer1);
(0, _metal.removeObserver)(obj2, 'foo.bar', observer2);
(0, _metal.removeObserver)(obj4, 'foo.bar', observer4);
}
function observer4() {
count4++;
}
(0, _metal.addObserver)(obj1, 'foo.bar', observer1);
(0, _metal.addObserver)(obj2, 'foo.bar', observer2);
(0, _metal.addObserver)(obj3, 'foo.bar', observer3);
(0, _metal.addObserver)(obj4, 'foo.bar', observer4);
(0, _metal.set)(foo, 'bar', 'baz');
assert.equal(count1, 1, 'observer1 fired');
assert.equal(count2, 1, 'observer2 fired');
assert.equal(count3, 1, 'observer3 fired');
assert.equal(count4, 0, 'observer4 did not fire');
};
_proto['@test deferring property change notifications'] = function testDeferringPropertyChangeNotifications(assert) {
var obj = {
foo: 'foo'
};
var fooCount = 0;
(0, _metal.addObserver)(obj, 'foo', function () {
fooCount++;
});
(0, _metal.beginPropertyChanges)();
(0, _metal.set)(obj, 'foo', 'BIFF');
(0, _metal.set)(obj, 'foo', 'BAZ');
(0, _metal.endPropertyChanges)();
assert.equal(fooCount, 1, 'foo should have fired once');
};
_proto['@test deferring property change notifications safely despite exceptions'] = function testDeferringPropertyChangeNotificationsSafelyDespiteExceptions(assert) {
var obj = {
foo: 'foo'
};
var fooCount = 0;
var exc = new Error('Something unexpected happened!');
assert.expect(2);
(0, _metal.addObserver)(obj, 'foo', function () {
fooCount++;
});
try {
(0, _metal.changeProperties)(function () {
(0, _metal.set)(obj, 'foo', 'BIFF');
(0, _metal.set)(obj, 'foo', 'BAZ');
throw exc;
});
} catch (err) {
if (err !== exc) {
throw err;
}
}
assert.equal(fooCount, 1, 'foo should have fired once');
(0, _metal.changeProperties)(function () {
(0, _metal.set)(obj, 'foo', 'BIFF2');
(0, _metal.set)(obj, 'foo', 'BAZ2');
});
assert.equal(fooCount, 2, 'foo should have fired again once');
};
_proto['@test addObserver should propagate through prototype'] = function testAddObserverShouldPropagateThroughPrototype(assert) {
var obj = {
foo: 'foo',
count: 0
};
var obj2;
(0, _metal.addObserver)(obj, 'foo', function () {
this.count++;
});
obj2 = Object.create(obj);
(0, _metal.set)(obj2, 'foo', 'bar');
assert.equal(obj2.count, 1, 'should have invoked observer on inherited');
assert.equal(obj.count, 0, 'should not have invoked observer on parent');
obj2.count = 0;
(0, _metal.set)(obj, 'foo', 'baz');
assert.equal(obj.count, 0, 'should not have invoked observer on parent');
assert.equal(obj2.count, 0, 'should not have invoked observer on inherited');
};
_proto['@test addObserver should respect targets with methods'] = function testAddObserverShouldRespectTargetsWithMethods(assert) {
var observed = {
foo: 'foo'
};
var target1 = {
count: 0,
didChange: function (obj, keyName) {
var value = (0, _metal.get)(obj, keyName);
assert.equal(this, target1, 'should invoke with this');
assert.equal(obj, observed, 'param1 should be observed object');
assert.equal(keyName, 'foo', 'param2 should be keyName');
assert.equal(value, 'BAZ', 'param3 should new value');
this.count++;
}
};
var target2 = {
count: 0,
didChange: function (obj, keyName) {
var value = (0, _metal.get)(obj, keyName);
assert.equal(this, target2, 'should invoke with this');
assert.equal(obj, observed, 'param1 should be observed object');
assert.equal(keyName, 'foo', 'param2 should be keyName');
assert.equal(value, 'BAZ', 'param3 should new value');
this.count++;
}
};
(0, _metal.addObserver)(observed, 'foo', target1, 'didChange');
(0, _metal.addObserver)(observed, 'foo', target2, target2.didChange);
(0, _metal.set)(observed, 'foo', 'BAZ');
assert.equal(target1.count, 1, 'target1 observer should have fired');
assert.equal(target2.count, 1, 'target2 observer should have fired');
};
_proto['@test addObserver should allow multiple objects to observe a property'] = function testAddObserverShouldAllowMultipleObjectsToObserveAProperty(assert) {
var observed = {
foo: 'foo'
};
var target1 = {
count: 0,
didChange: function () {
this.count++;
}
};
var target2 = {
count: 0,
didChange: function () {
this.count++;
}
};
(0, _metal.addObserver)(observed, 'foo', target1, 'didChange');
(0, _metal.addObserver)(observed, 'foo', target2, 'didChange');
(0, _metal.set)(observed, 'foo', 'BAZ');
assert.equal(target1.count, 1, 'target1 observer should have fired');
assert.equal(target2.count, 1, 'target2 observer should have fired');
};
return _class;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// REMOVE OBSERVER
//
(0, _internalTestHelpers.moduleFor)('removeObserver',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test removing observer should stop firing'] = function testRemovingObserverShouldStopFiring(assert) {
var obj = {};
var count = 0;
function F() {
count++;
}
(0, _metal.addObserver)(obj, 'foo', F);
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(count, 1, 'should have invoked observer');
(0, _metal.removeObserver)(obj, 'foo', F);
(0, _metal.set)(obj, 'foo', 'baz');
assert.equal(count, 1, "removed observer shouldn't fire");
};
_proto2['@test local observers can be removed'] = function testLocalObserversCanBeRemoved(assert) {
var barObserved = 0;
var MyMixin = _metal.Mixin.create({
foo1: (0, _metal.observer)('bar', function () {
barObserved++;
}),
foo2: (0, _metal.observer)('bar', function () {
barObserved++;
})
});
var obj = {};
MyMixin.apply(obj);
(0, _metal.set)(obj, 'bar', 'HI!');
assert.equal(barObserved, 2, 'precond - observers should be fired');
(0, _metal.removeObserver)(obj, 'bar', null, 'foo1');
barObserved = 0;
(0, _metal.set)(obj, 'bar', 'HI AGAIN!');
assert.equal(barObserved, 1, 'removed observers should not be called');
};
_proto2['@test removeObserver should respect targets with methods'] = function testRemoveObserverShouldRespectTargetsWithMethods(assert) {
var observed = {
foo: 'foo'
};
var target1 = {
count: 0,
didChange: function () {
this.count++;
}
};
var target2 = {
count: 0,
didChange: function () {
this.count++;
}
};
(0, _metal.addObserver)(observed, 'foo', target1, 'didChange');
(0, _metal.addObserver)(observed, 'foo', target2, target2.didChange);
(0, _metal.set)(observed, 'foo', 'BAZ');
assert.equal(target1.count, 1, 'target1 observer should have fired');
assert.equal(target2.count, 1, 'target2 observer should have fired');
(0, _metal.removeObserver)(observed, 'foo', target1, 'didChange');
(0, _metal.removeObserver)(observed, 'foo', target2, target2.didChange);
target1.count = target2.count = 0;
(0, _metal.set)(observed, 'foo', 'BAZ');
assert.equal(target1.count, 0, 'target1 observer should not fire again');
assert.equal(target2.count, 0, 'target2 observer should not fire again');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// CHAINED OBSERVERS
//
var obj, count;
(0, _internalTestHelpers.moduleFor)('addObserver - dependentkey with chained properties',
/*#__PURE__*/
function (_AbstractTestCase3) {
(0, _emberBabel.inheritsLoose)(_class3, _AbstractTestCase3);
function _class3() {
return _AbstractTestCase3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3.beforeEach = function beforeEach() {
obj = {
foo: {
bar: {
baz: {
biff: 'BIFF'
}
}
},
Capital: {
foo: {
bar: {
baz: {
biff: 'BIFF'
}
}
}
}
};
count = 0;
};
_proto3.afterEach = function afterEach() {
obj = count = null;
};
_proto3['@test depending on a chain with a computed property'] = function testDependingOnAChainWithAComputedProperty(assert) {
(0, _metal.defineProperty)(obj, 'computed', (0, _metal.computed)(function () {
return {
foo: 'bar'
};
}));
var changed = 0;
(0, _metal.addObserver)(obj, 'computed.foo', function () {
changed++;
});
assert.equal((0, _metal.getCachedValueFor)(obj, 'computed'), undefined, 'addObserver should not compute CP');
(0, _metal.set)(obj, 'computed.foo', 'baz');
assert.equal(changed, 1, 'should fire observer');
};
_proto3['@test depending on a simple chain'] = function testDependingOnASimpleChain(assert) {
var val;
(0, _metal.addObserver)(obj, 'foo.bar.baz.biff', function (target, key) {
val = (0, _metal.get)(target, key);
count++;
});
(0, _metal.set)((0, _metal.get)(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
assert.equal(val, 'BUZZ');
assert.equal(count, 1);
(0, _metal.set)((0, _metal.get)(obj, 'foo.bar'), 'baz', {
biff: 'BLARG'
});
assert.equal(val, 'BLARG');
assert.equal(count, 2);
(0, _metal.set)((0, _metal.get)(obj, 'foo'), 'bar', {
baz: {
biff: 'BOOM'
}
});
assert.equal(val, 'BOOM');
assert.equal(count, 3);
(0, _metal.set)(obj, 'foo', {
bar: {
baz: {
biff: 'BLARG'
}
}
});
assert.equal(val, 'BLARG');
assert.equal(count, 4);
(0, _metal.set)((0, _metal.get)(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
assert.equal(val, 'BUZZ');
assert.equal(count, 5);
var foo = (0, _metal.get)(obj, 'foo');
(0, _metal.set)(obj, 'foo', 'BOO');
assert.equal(val, undefined);
assert.equal(count, 6);
(0, _metal.set)(foo.bar.baz, 'biff', 'BOOM');
assert.equal(count, 6, 'should be not have invoked observer');
};
_proto3['@test depending on a chain with a capitalized first key'] = function testDependingOnAChainWithACapitalizedFirstKey(assert) {
var val;
(0, _metal.addObserver)(obj, 'Capital.foo.bar.baz.biff', function (target, key) {
val = (0, _metal.get)(obj, key);
count++;
});
(0, _metal.set)((0, _metal.get)(obj, 'Capital.foo.bar.baz'), 'biff', 'BUZZ');
assert.equal(val, 'BUZZ');
assert.equal(count, 1);
(0, _metal.set)((0, _metal.get)(obj, 'Capital.foo.bar'), 'baz', {
biff: 'BLARG'
});
assert.equal(val, 'BLARG');
assert.equal(count, 2);
(0, _metal.set)((0, _metal.get)(obj, 'Capital.foo'), 'bar', {
baz: {
biff: 'BOOM'
}
});
assert.equal(val, 'BOOM');
assert.equal(count, 3);
(0, _metal.set)(obj, 'Capital.foo', {
bar: {
baz: {
biff: 'BLARG'
}
}
});
assert.equal(val, 'BLARG');
assert.equal(count, 4);
(0, _metal.set)((0, _metal.get)(obj, 'Capital.foo.bar.baz'), 'biff', 'BUZZ');
assert.equal(val, 'BUZZ');
assert.equal(count, 5);
var foo = (0, _metal.get)(obj, 'foo');
(0, _metal.set)(obj, 'Capital.foo', 'BOO');
assert.equal(val, undefined);
assert.equal(count, 6);
(0, _metal.set)(foo.bar.baz, 'biff', 'BOOM');
assert.equal(count, 6, 'should be not have invoked observer');
};
return _class3;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// SETTING IDENTICAL VALUES
//
(0, _internalTestHelpers.moduleFor)('props/observer_test - setting identical values',
/*#__PURE__*/
function (_AbstractTestCase4) {
(0, _emberBabel.inheritsLoose)(_class4, _AbstractTestCase4);
function _class4() {
return _AbstractTestCase4.apply(this, arguments) || this;
}
var _proto4 = _class4.prototype;
_proto4['@test setting simple prop should not trigger'] = function testSettingSimplePropShouldNotTrigger(assert) {
var obj = {
foo: 'bar'
};
var count = 0;
(0, _metal.addObserver)(obj, 'foo', function () {
count++;
});
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(count, 0, 'should not trigger observer');
(0, _metal.set)(obj, 'foo', 'baz');
assert.equal(count, 1, 'should trigger observer');
(0, _metal.set)(obj, 'foo', 'baz');
assert.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.
;
_proto4['@test setting a cached computed property whose value has changed should trigger'] = function testSettingACachedComputedPropertyWhoseValueHasChangedShouldTrigger(assert) {
var obj = {};
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)({
get: function () {
return (0, _metal.get)(this, 'baz');
},
set: function (key, value) {
return value;
}
}).property('baz'));
var count = 0;
(0, _metal.addObserver)(obj, 'foo', function () {
count++;
});
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(count, 1);
assert.equal((0, _metal.get)(obj, 'foo'), 'bar');
(0, _metal.set)(obj, 'baz', 'qux');
assert.equal(count, 2);
assert.equal((0, _metal.get)(obj, 'foo'), 'qux');
(0, _metal.get)(obj, 'foo');
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(count, 3);
assert.equal((0, _metal.get)(obj, 'foo'), 'bar');
};
return _class4;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('changeProperties',
/*#__PURE__*/
function (_AbstractTestCase5) {
(0, _emberBabel.inheritsLoose)(_class5, _AbstractTestCase5);
function _class5() {
return _AbstractTestCase5.apply(this, arguments) || this;
}
var _proto5 = _class5.prototype;
_proto5['@test observers added/removed during changeProperties should do the right thing.'] = function testObserversAddedRemovedDuringChangePropertiesShouldDoTheRightThing(assert) {
var obj = {
foo: 0
};
function Observer() {
this.didChangeCount = 0;
}
Observer.prototype = {
add: function () {
(0, _metal.addObserver)(obj, 'foo', this, 'didChange');
},
remove: function () {
(0, _metal.removeObserver)(obj, 'foo', this, 'didChange');
},
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, _metal.changeProperties)(function () {
removedBeforeFirstChangeObserver.remove();
addedBeforeFirstChangeObserver.add();
(0, _metal.set)(obj, 'foo', 1);
assert.equal(addedBeforeFirstChangeObserver.didChangeCount, 0, 'addObserver called before the first change is deferred');
addedAfterFirstChangeObserver.add();
removedBeforeLastChangeObserver.remove();
(0, _metal.set)(obj, 'foo', 2);
assert.equal(addedAfterFirstChangeObserver.didChangeCount, 0, 'addObserver called after the first change is deferred');
addedAfterLastChangeObserver.add();
removedAfterLastChangeObserver.remove();
});
assert.equal(removedBeforeFirstChangeObserver.didChangeCount, 0, 'removeObserver called before the first change sees none');
assert.equal(addedBeforeFirstChangeObserver.didChangeCount, 1, 'addObserver called before the first change sees only 1');
assert.equal(addedAfterFirstChangeObserver.didChangeCount, 1, 'addObserver called after the first change sees 1');
assert.equal(addedAfterLastChangeObserver.didChangeCount, 1, 'addObserver called after the last change sees 1');
assert.equal(removedBeforeLastChangeObserver.didChangeCount, 0, 'removeObserver called before the last change sees none');
assert.equal(removedAfterLastChangeObserver.didChangeCount, 0, 'removeObserver called after the last change sees none');
};
_proto5['@test calling changeProperties while executing deferred observers works correctly'] = function testCallingChangePropertiesWhileExecutingDeferredObserversWorksCorrectly(assert) {
var obj = {
foo: 0
};
var fooDidChange = 0;
(0, _metal.addObserver)(obj, 'foo', function () {
fooDidChange++;
(0, _metal.changeProperties)(function () {});
});
(0, _metal.changeProperties)(function () {
(0, _metal.set)(obj, 'foo', 1);
});
assert.equal(fooDidChange, 1);
};
return _class5;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Keys behavior with observers',
/*#__PURE__*/
function (_AbstractTestCase6) {
(0, _emberBabel.inheritsLoose)(_class6, _AbstractTestCase6);
function _class6() {
return _AbstractTestCase6.apply(this, arguments) || this;
}
var _proto6 = _class6.prototype;
_proto6['@test should not leak properties on the prototype'] = function testShouldNotLeakPropertiesOnThePrototype(assert) {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
(0, _metal.addObserver)(beer, 'type', K);
assert.deepEqual(Object.keys(beer), []);
(0, _metal.removeObserver)(beer, 'type', K);
};
_proto6['@test observing a non existent property'] = function testObservingANonExistentProperty(assert) {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
(0, _metal.addObserver)(beer, 'brand', K);
assert.deepEqual(Object.keys(beer), []);
(0, _metal.set)(beer, 'brand', 'Corona');
assert.deepEqual(Object.keys(beer), ['brand']);
(0, _metal.removeObserver)(beer, 'brand', K);
};
_proto6['@test with observers switched on and off'] = function testWithObserversSwitchedOnAndOff(assert) {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
(0, _metal.addObserver)(beer, 'type', K);
(0, _metal.removeObserver)(beer, 'type', K);
assert.deepEqual(Object.keys(beer), []);
};
_proto6['@test observers switched on and off with setter in between'] = function testObserversSwitchedOnAndOffWithSetterInBetween(assert) {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
(0, _metal.addObserver)(beer, 'type', K);
(0, _metal.set)(beer, 'type', 'ale');
(0, _metal.removeObserver)(beer, 'type', K);
assert.deepEqual(Object.keys(beer), ['type']);
};
_proto6['@test observer switched on and off and then setter'] = function testObserverSwitchedOnAndOffAndThenSetter(assert) {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
(0, _metal.addObserver)(beer, 'type', K);
(0, _metal.removeObserver)(beer, 'type', K);
(0, _metal.set)(beer, 'type', 'ale');
assert.deepEqual(Object.keys(beer), ['type']);
};
_proto6['@test observers switched on and off with setter in between (observed property is not shadowing)'] = function testObserversSwitchedOnAndOffWithSetterInBetweenObservedPropertyIsNotShadowing(assert) {
function Beer() {}
var beer = new Beer();
(0, _metal.set)(beer, 'type', 'ale');
assert.deepEqual(Object.keys(beer), ['type'], 'only set');
var otherBeer = new Beer();
(0, _metal.addObserver)(otherBeer, 'type', K);
(0, _metal.set)(otherBeer, 'type', 'ale');
assert.deepEqual(Object.keys(otherBeer), ['type'], 'addObserver -> set');
var yetAnotherBeer = new Beer();
(0, _metal.addObserver)(yetAnotherBeer, 'type', K);
(0, _metal.set)(yetAnotherBeer, 'type', 'ale');
(0, _metal.addObserver)(beer, 'type', K);
(0, _metal.removeObserver)(beer, 'type', K);
assert.deepEqual(Object.keys(yetAnotherBeer), ['type'], 'addObserver -> set -> removeObserver');
var itsMyLastBeer = new Beer();
(0, _metal.set)(itsMyLastBeer, 'type', 'ale');
(0, _metal.addObserver)(beer, 'type', K);
(0, _metal.removeObserver)(beer, 'type', K);
assert.deepEqual(Object.keys(itsMyLastBeer), ['type'], 'set -> removeObserver');
};
_proto6['@test observers switched on and off with setter in between (observed property is shadowing one on the prototype)'] = function testObserversSwitchedOnAndOffWithSetterInBetweenObservedPropertyIsShadowingOneOnThePrototype(assert) {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
(0, _metal.set)(beer, 'type', 'ale');
assert.deepEqual(Object.keys(beer), ['type'], 'after set');
var otherBeer = new Beer();
(0, _metal.addObserver)(otherBeer, 'type', K);
(0, _metal.set)(otherBeer, 'type', 'ale');
assert.deepEqual(Object.keys(otherBeer), ['type'], 'addObserver -> set');
var yetAnotherBeer = new Beer();
(0, _metal.addObserver)(yetAnotherBeer, 'type', K);
(0, _metal.set)(yetAnotherBeer, 'type', 'ale');
(0, _metal.addObserver)(beer, 'type', K);
(0, _metal.removeObserver)(beer, 'type', K);
assert.deepEqual(Object.keys(yetAnotherBeer), ['type'], 'addObserver -> set -> removeObserver');
var itsMyLastBeer = new Beer();
(0, _metal.set)(itsMyLastBeer, 'type', 'ale');
(0, _metal.addObserver)(beer, 'type', K);
(0, _metal.removeObserver)(beer, 'type', K);
assert.deepEqual(Object.keys(itsMyLastBeer), ['type'], 'set -> removeObserver');
};
return _class6;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/performance_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"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.
*/
(0, _internalTestHelpers.moduleFor)('Computed Properties - Number of times evaluated',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test computed properties that depend on multiple properties should run only once per run loop'] = function testComputedPropertiesThatDependOnMultiplePropertiesShouldRunOnlyOncePerRunLoop(assert) {
var obj = {
a: 'a',
b: 'b',
c: 'c'
};
var cpCount = 0;
var obsCount = 0;
(0, _metal.defineProperty)(obj, 'abc', (0, _metal.computed)(function (key) {
cpCount++;
return 'computed ' + key;
}).property('a', 'b', 'c'));
(0, _metal.get)(obj, 'abc');
cpCount = 0;
(0, _metal.addObserver)(obj, 'abc', function () {
obsCount++;
});
(0, _metal.beginPropertyChanges)();
(0, _metal.set)(obj, 'a', 'aa');
(0, _metal.set)(obj, 'b', 'bb');
(0, _metal.set)(obj, 'c', 'cc');
(0, _metal.endPropertyChanges)();
(0, _metal.get)(obj, 'abc');
assert.equal(cpCount, 1, 'The computed property is only invoked once');
assert.equal(obsCount, 1, 'The observer is only invoked once');
};
_proto['@test computed properties are not executed if they are the last segment of an observer chain pain'] = function testComputedPropertiesAreNotExecutedIfTheyAreTheLastSegmentOfAnObserverChainPain(assert) {
var foo = {
bar: {
baz: {}
}
};
var count = 0;
(0, _metal.defineProperty)(foo.bar.baz, 'bam', (0, _metal.computed)(function () {
count++;
}));
(0, _metal.addObserver)(foo, 'bar.baz.bam', function () {});
(0, _metal.notifyPropertyChange)((0, _metal.get)(foo, 'bar.baz'), 'bam');
assert.equal(count, 0, 'should not have recomputed property');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/properties_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('defineProperty',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test toString'] = function testToString(assert) {
var obj = {};
(0, _metal.defineProperty)(obj, 'toString', undefined, function () {
return 'FOO';
});
assert.equal(obj.toString(), 'FOO', 'should replace toString');
};
_proto['@test for data properties, didDefineProperty hook should be called if implemented'] = function testForDataPropertiesDidDefinePropertyHookShouldBeCalledIfImplemented(assert) {
assert.expect(2);
var obj = {
didDefineProperty: function (obj, keyName, value) {
assert.equal(keyName, 'foo', 'key name should be foo');
assert.equal(value, 'bar', 'value should be bar');
}
};
(0, _metal.defineProperty)(obj, 'foo', undefined, 'bar');
};
_proto['@test for computed properties, didDefineProperty hook should be called if implemented'] = function testForComputedPropertiesDidDefinePropertyHookShouldBeCalledIfImplemented(assert) {
assert.expect(2);
var computedProperty = (0, _metal.computed)(function () {
return this;
});
var obj = {
didDefineProperty: function (obj, keyName, value) {
assert.equal(keyName, 'foo', 'key name should be foo');
assert.strictEqual(value, computedProperty, 'value should be passed as computed property');
}
};
(0, _metal.defineProperty)(obj, 'foo', computedProperty);
};
_proto['@test for descriptor properties, didDefineProperty hook should be called if implemented'] = function testForDescriptorPropertiesDidDefinePropertyHookShouldBeCalledIfImplemented(assert) {
assert.expect(2);
var descriptor = {
writable: true,
configurable: false,
enumerable: true,
value: 42
};
var obj = {
didDefineProperty: function (obj, keyName, value) {
assert.equal(keyName, 'answer', 'key name should be answer');
assert.strictEqual(value, descriptor, 'value should be passed as descriptor');
}
};
(0, _metal.defineProperty)(obj, 'answer', descriptor);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Ember.deprecateProperty',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test enables access to deprecated property and returns the value of the new property'] = function testEnablesAccessToDeprecatedPropertyAndReturnsTheValueOfTheNewProperty(assert) {
assert.expect(3);
var obj = {
foo: 'bar'
};
(0, _metal.deprecateProperty)(obj, 'baz', 'foo', {
id: 'baz-deprecation',
until: 'some.version'
});
expectDeprecation();
assert.equal(obj.baz, obj.foo, 'baz and foo are equal');
obj.foo = 'blammo';
assert.equal(obj.baz, obj.foo, 'baz and foo are equal');
};
_proto2['@test deprecatedKey is not enumerable'] = function testDeprecatedKeyIsNotEnumerable(assert) {
assert.expect(2);
var obj = {
foo: 'bar',
blammo: 'whammy'
};
(0, _metal.deprecateProperty)(obj, 'baz', 'foo', {
id: 'baz-deprecation',
until: 'some.version'
});
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
assert.notEqual(prop, 'baz');
}
}
};
_proto2['@test enables setter to deprecated property and updates the value of the new property'] = function testEnablesSetterToDeprecatedPropertyAndUpdatesTheValueOfTheNewProperty(assert) {
assert.expect(3);
var obj = {
foo: 'bar'
};
(0, _metal.deprecateProperty)(obj, 'baz', 'foo', {
id: 'baz-deprecation',
until: 'some.version'
});
expectDeprecation();
obj.baz = 'bloop';
assert.equal(obj.foo, 'bloop', 'updating baz updates foo');
assert.equal(obj.baz, obj.foo, 'baz and foo are equal');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/property_did_change_hook", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('PROPERTY_DID_CHANGE',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test alias and cp'] = function testAliasAndCp(assert) {
var _obj;
var counts = {};
var obj = (_obj = {
child: {}
}, _obj[_metal.PROPERTY_DID_CHANGE] = function (keyName) {
counts[keyName] = (counts[keyName] || 0) + 1;
}, _obj);
(0, _metal.defineProperty)(obj, 'cost', (0, _metal.alias)('child.cost'));
(0, _metal.defineProperty)(obj, 'tax', (0, _metal.alias)('child.tax'));
(0, _metal.defineProperty)(obj, 'total', (0, _metal.computed)('cost', 'tax', {
get: function () {
return (0, _metal.get)(this, 'cost') + (0, _metal.get)(this, 'tax');
}
}));
assert.ok(!(0, _metal.isWatching)(obj, 'child.cost'), 'precond alias target `child.cost` is not watched');
assert.equal((0, _metal.get)(obj, 'cost'), undefined); // this is how PROPERTY_DID_CHANGE will get notified
assert.ok((0, _metal.isWatching)(obj, 'child.cost'), 'alias target `child.cost` is watched after consumption');
assert.ok(!(0, _metal.isWatching)(obj, 'child.tax'), 'precond alias target `child.tax` is not watched');
assert.equal((0, _metal.get)(obj, 'tax'), undefined); // this is how PROPERTY_DID_CHANGE will get notified
assert.ok((0, _metal.isWatching)(obj, 'child.tax'), 'alias target `child.cost` is watched after consumption'); // increments the watching count on the alias itself to 1
assert.ok(isNaN((0, _metal.get)(obj, 'total')), 'total is initialized'); // decrements the watching count on the alias itself to 0
(0, _metal.set)(obj, 'child', {
cost: 399.0,
tax: 32.93
}); // this should have called PROPERTY_DID_CHANGE for all of them
assert.equal(counts['cost'], 1, 'PROPERTY_DID_CHANGE called with cost');
assert.equal(counts['tax'], 1, 'PROPERTY_DID_CHANGE called with tax');
assert.equal(counts['total'], 1, 'PROPERTY_DID_CHANGE called with total'); // we should still have a dependency installed
assert.ok((0, _metal.isWatching)(obj, 'child.cost'), 'watching child.cost');
assert.ok((0, _metal.isWatching)(obj, 'child.tax'), 'watching child.tax');
(0, _metal.set)(obj, 'child', {
cost: 100.0,
tax: 10.0
});
assert.equal(counts['cost'], 2, 'PROPERTY_DID_CHANGE called with cost');
assert.equal(counts['tax'], 2, 'PROPERTY_DID_CHANGE called with tax');
assert.equal(counts['total'], 1, 'PROPERTY_DID_CHANGE called with total');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/property_events_test", ["ember-babel", "@ember/-internals/meta", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _meta, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('notifyPropertyChange',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test notifies property changes on instances'] = function testNotifiesPropertyChangesOnInstances(assert) {
var Foo =
/*#__PURE__*/
function () {
function Foo() {}
var _proto2 = Foo.prototype;
_proto2[_metal.PROPERTY_DID_CHANGE] = function (prop) {
assert.equal(prop, 'bar', 'property change notified');
};
return Foo;
}();
var foo = new Foo();
(0, _metal.notifyPropertyChange)(foo, 'bar');
};
_proto['@test notifies property changes on instances with meta'] = function testNotifiesPropertyChangesOnInstancesWithMeta(assert) {
var Foo =
/*#__PURE__*/
function () {
function Foo() {}
var _proto3 = Foo.prototype;
_proto3[_metal.PROPERTY_DID_CHANGE] = function (prop) {
assert.equal(prop, 'bar', 'property change notified');
};
return Foo;
}();
var foo = new Foo();
(0, _meta.meta)(foo); // setup meta
(0, _metal.notifyPropertyChange)(foo, 'bar');
};
_proto['@test does not notify on class prototypes with meta'] = function testDoesNotNotifyOnClassPrototypesWithMeta(assert) {
assert.expect(0);
var Foo =
/*#__PURE__*/
function () {
function Foo() {}
var _proto4 = Foo.prototype;
_proto4[_metal.PROPERTY_DID_CHANGE] = function (prop) {
assert.equal(prop, 'bar', 'property change notified');
};
return Foo;
}();
var foo = new Foo();
(0, _meta.meta)(foo.constructor.prototype); // setup meta for prototype
(0, _metal.notifyPropertyChange)(foo.constructor.prototype, 'bar');
};
_proto['@test does not notify on non-class prototypes with meta'] = function testDoesNotNotifyOnNonClassPrototypesWithMeta(assert) {
var _foo;
assert.expect(0);
var foo = (_foo = {}, _foo[_metal.PROPERTY_DID_CHANGE] = function (prop) {
assert.equal(prop, 'baz', 'property change notified');
}, _foo);
var bar = Object.create(foo);
(0, _meta.meta)(foo); // setup meta for prototype
(0, _meta.meta)(bar); // setup meta for instance, switch prototype
(0, _metal.notifyPropertyChange)(foo, 'baz');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/set_properties_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('setProperties',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test supports setting multiple attributes at once'] = function testSupportsSettingMultipleAttributesAtOnce(assert) {
assert.deepEqual((0, _metal.setProperties)(null, null), null, 'noop for null properties and null object');
assert.deepEqual((0, _metal.setProperties)(undefined, undefined), undefined, 'noop for undefined properties and undefined object');
assert.deepEqual((0, _metal.setProperties)({}), undefined, 'noop for no properties');
assert.deepEqual((0, _metal.setProperties)({}, undefined), undefined, 'noop for undefined');
assert.deepEqual((0, _metal.setProperties)({}, null), null, 'noop for null');
assert.deepEqual((0, _metal.setProperties)({}, NaN), NaN, 'noop for NaN');
assert.deepEqual((0, _metal.setProperties)({}, {}), {}, 'meh');
var props = (0, _metal.setProperties)({}, {
foo: undefined
});
assert.deepEqual(props, {
foo: undefined
}, 'Setting undefined value');
assert.ok('foo' in props, 'Setting undefined value');
assert.deepEqual(Object.keys(props), ['foo'], 'Setting undefined value');
assert.deepEqual((0, _metal.setProperties)({}, {
foo: 1
}), {
foo: 1
}, 'Set a single property');
assert.deepEqual((0, _metal.setProperties)({}, {
foo: 1,
bar: 1
}), {
foo: 1,
bar: 1
}, 'Set multiple properties');
assert.deepEqual((0, _metal.setProperties)({
foo: 2,
baz: 2
}, {
foo: 1
}), {
foo: 1
}, 'Set one of multiple properties');
assert.deepEqual((0, _metal.setProperties)({
foo: 2,
baz: 2
}, {
bar: 2
}), {
bar: 2
}, 'Set an additional, previously unset property');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/tracked/computed_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
}
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
if (false
/* EMBER_METAL_TRACKED_PROPERTIES */
) {
(0, _internalTestHelpers.moduleFor)('@tracked getters',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test works without get'] = function testWorksWithoutGet(assert) {
var count = 0;
var Count =
/*#__PURE__*/
function () {
function Count() {}
(0, _emberBabel.createClass)(Count, [{
key: "foo",
get: function () {
count++;
return "computed foo";
}
}]);
return Count;
}();
__decorate([_metal.tracked], Count.prototype, "foo", null);
var obj = new Count();
assert.equal(obj.foo, 'computed foo', 'should return value');
assert.equal(count, 1, 'should have invoked computed property');
};
_proto['@test defining computed property should invoke property on get'] = function testDefiningComputedPropertyShouldInvokePropertyOnGet(assert) {
var count = 0;
var Count =
/*#__PURE__*/
function () {
function Count() {}
(0, _emberBabel.createClass)(Count, [{
key: "foo",
get: function () {
count++;
return "computed foo";
}
}]);
return Count;
}();
__decorate([_metal.tracked], Count.prototype, "foo", null);
var obj = new Count();
assert.equal((0, _metal.get)(obj, 'foo'), 'computed foo', 'should return value');
assert.equal(count, 1, 'should have invoked computed property');
};
_proto['@test defining computed property should invoke property on set'] = function testDefiningComputedPropertyShouldInvokePropertyOnSet(assert) {
var count = 0;
var Foo =
/*#__PURE__*/
function () {
function Foo() {
this.__foo = '';
}
(0, _emberBabel.createClass)(Foo, [{
key: "foo",
get: function () {
return this.__foo;
},
set: function (value) {
count++;
this.__foo = "computed " + value;
}
}]);
return Foo;
}();
__decorate([_metal.tracked], Foo.prototype, "foo", null);
var obj = new Foo();
assert.equal((0, _metal.set)(obj, 'foo', 'bar'), 'bar', 'should return set value');
assert.equal(count, 1, 'should have invoked computed property');
assert.equal((0, _metal.get)(obj, 'foo'), 'computed bar', 'should return new value');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
}
});
enifed("@ember/-internals/metal/tests/tracked/get_test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _metal) {
"use strict";
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
}
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
if (false
/* EMBER_METAL_TRACKED_PROPERTIES */
) {
var createObj = function () {
var Obj = function Obj() {
this.string = 'string';
this.number = 23;
this.boolTrue = true;
this.boolFalse = false;
this.nullValue = null;
};
__decorate([_metal.tracked], Obj.prototype, "string", void 0);
__decorate([_metal.tracked], Obj.prototype, "number", void 0);
__decorate([_metal.tracked], Obj.prototype, "boolTrue", void 0);
__decorate([_metal.tracked], Obj.prototype, "boolFalse", void 0);
__decorate([_metal.tracked], Obj.prototype, "nullValue", void 0);
return new Obj();
};
(0, _internalTestHelpers.moduleFor)('@tracked decorator: get',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should get arbitrary properties on an object'] = function testShouldGetArbitraryPropertiesOnAnObject() {
var obj = createObj();
for (var key in obj) {
this.assert.equal((0, _metal.get)(obj, key), obj[key], key);
}
};
_proto['@test should retrieve a number key on an object'] = function testShouldRetrieveANumberKeyOnAnObject() {
var Obj = function Obj() {
this[1] = 'first';
};
__decorate([_metal.tracked], Obj.prototype, 1, void 0);
var obj = new Obj();
this.assert.equal((0, _metal.get)(obj, '1'), 'first');
};
_proto['@test should retrieve an empty key on an object'] = function testShouldRetrieveAnEmptyKeyOnAnObject() {
var Obj = function Obj() {
this[''] = 'empty';
};
__decorate([_metal.tracked], Obj.prototype, "", void 0);
var obj = new Obj();
this.assert.equal((0, _metal.get)(obj, ''), 'empty');
};
_proto['@test should get a @tracked path'] = function testShouldGetATrackedPath() {
var Key = function Key() {
this.value = 'value';
};
__decorate([_metal.tracked], Key.prototype, "value", void 0);
var Path = function Path() {
this.key = new Key();
};
__decorate([_metal.tracked], Path.prototype, "key", void 0);
var Obj = function Obj() {
this.path = new Path();
};
__decorate([_metal.tracked], Obj.prototype, "path", void 0);
var obj = new Obj();
this.assert.equal((0, _metal.get)(obj, 'path.key.value'), 'value');
};
_proto['@test should not access a property more than once'] = function testShouldNotAccessAPropertyMoreThanOnce() {
var count = 20;
var Count =
/*#__PURE__*/
function () {
function Count() {}
(0, _emberBabel.createClass)(Count, [{
key: "id",
get: function () {
return ++count;
}
}]);
return Count;
}();
__decorate([_metal.tracked], Count.prototype, "id", null);
var obj = new Count();
(0, _metal.get)(obj, 'id');
this.assert.equal(count, 21);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('@tracked decorator: getWithDefault',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test should get arbitrary properties on an object'] = function testShouldGetArbitraryPropertiesOnAnObject() {
var obj = createObj();
for (var key in obj) {
this.assert.equal((0, _metal.getWithDefault)(obj, key, 'fail'), obj[key], key);
}
var Obj = function Obj() {
this.undef = undefined;
};
__decorate([_metal.tracked], Obj.prototype, "undef", void 0);
var obj2 = new Obj();
this.assert.equal((0, _metal.getWithDefault)(obj2, 'undef', 'default'), 'default', 'explicit undefined retrieves the default');
this.assert.equal((0, _metal.getWithDefault)(obj2, 'not-present', 'default'), 'default', 'non-present key retrieves the default');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
}
});
enifed("@ember/-internals/metal/tests/tracked/set_test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _metal) {
"use strict";
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
}
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
if (false
/* EMBER_METAL_TRACKED_PROPERTIES */
) {
var createObj = function () {
var Obj = function Obj() {
this.string = 'string';
this.number = 23;
this.boolTrue = true;
this.boolFalse = false;
this.nullValue = null;
this.undefinedValue = undefined;
};
__decorate([_metal.tracked], Obj.prototype, "string", void 0);
__decorate([_metal.tracked], Obj.prototype, "number", void 0);
__decorate([_metal.tracked], Obj.prototype, "boolTrue", void 0);
__decorate([_metal.tracked], Obj.prototype, "boolFalse", void 0);
__decorate([_metal.tracked], Obj.prototype, "nullValue", void 0);
__decorate([_metal.tracked], Obj.prototype, "undefinedValue", void 0);
return new Obj();
};
(0, _internalTestHelpers.moduleFor)('@tracked set',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should set arbitrary properties on an object'] = function testShouldSetArbitraryPropertiesOnAnObject(assert) {
var obj = createObj();
var Obj = function Obj() {
this.undefinedValue = 'emberjs';
};
__decorate([_metal.tracked], Obj.prototype, "undefinedValue", void 0);
var newObj = new Obj();
for (var key in obj) {
assert.equal((0, _metal.set)(newObj, key, obj[key]), obj[key], 'should return value');
assert.equal((0, _metal.get)(newObj, key), obj[key], 'should set value');
}
};
_proto['@test should set a number key on an object'] = function testShouldSetANumberKeyOnAnObject(assert) {
var Obj = function Obj() {
this[1] = 'original';
};
__decorate([_metal.tracked], Obj.prototype, 1, void 0);
var obj = new Obj();
(0, _metal.set)(obj, '1', 'first');
assert.equal(obj[1], 'first');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
}
});
enifed("@ember/-internals/metal/tests/tracked/support", ["exports", "@ember/-internals/metal"], function (_exports, _metal) {
"use strict";
_exports.createTracked = createTracked;
_exports.createWithDescriptors = createWithDescriptors;
function createTracked(values) {
var proto = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
function Class() {
for (var prop in values) {
this[prop] = values[prop];
}
}
for (var prop in values) {
Object.defineProperty(proto, prop, (0, _metal.tracked)(proto, prop, {
enumerable: true,
configurable: true,
writable: true,
value: values[prop]
}));
}
Class.prototype = proto;
return new Class();
}
function createWithDescriptors(values) {
function Class() {}
for (var prop in values) {
var descriptor = Object.getOwnPropertyDescriptor(values, prop);
Object.defineProperty(Class.prototype, prop, (0, _metal.tracked)(Class.prototype, prop, descriptor));
}
return new Class();
}
});
enifed("@ember/-internals/metal/tests/tracked/validation_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
}
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
if (false
/* EMBER_METAL_TRACKED_PROPERTIES */
) {
(0, _internalTestHelpers.moduleFor)('@tracked get validation',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto["@test validators for tracked getters with dependencies should invalidate when the dependencies invalidate"] = function (assert) {
var Tracked =
/*#__PURE__*/
function () {
function Tracked(first, last) {
this.first = undefined;
this.last = undefined;
this.first = first;
this.last = last;
}
(0, _emberBabel.createClass)(Tracked, [{
key: "full",
get: function () {
return this.first + " " + this.last;
}
}]);
return Tracked;
}();
__decorate([_metal.tracked], Tracked.prototype, "first", void 0);
__decorate([_metal.tracked], Tracked.prototype, "last", void 0);
__decorate([_metal.tracked], Tracked.prototype, "full", null);
var obj = new Tracked('Tom', 'Dale');
var tag = (0, _metal.tagForProperty)(obj, 'full');
var snapshot = tag.value();
var full = obj.full;
assert.equal(full, 'Tom Dale', 'The full name starts correct');
assert.equal(tag.validate(snapshot), true);
snapshot = tag.value();
assert.equal(tag.validate(snapshot), true);
obj.first = 'Thomas';
assert.equal(tag.validate(snapshot), false);
assert.equal(obj.full, 'Thomas Dale');
snapshot = tag.value();
assert.equal(tag.validate(snapshot), true);
};
_proto["@test interaction with Ember object model (tracked property depending on Ember property)"] = function (assert) {
var Tracked =
/*#__PURE__*/
function () {
function Tracked(name) {
this.name = name;
}
(0, _emberBabel.createClass)(Tracked, [{
key: "full",
get: function () {
return (0, _metal.get)(this.name, 'first') + " " + (0, _metal.get)(this.name, 'last');
}
}]);
return Tracked;
}();
__decorate([_metal.tracked], Tracked.prototype, "name", void 0);
__decorate([_metal.tracked], Tracked.prototype, "full", null);
var tom = {
first: 'Tom',
last: 'Dale'
};
var obj = new Tracked(tom);
var tag = (0, _metal.tagForProperty)(obj, 'full');
var snapshot = tag.value();
var full = obj.full;
assert.equal(full, 'Tom Dale');
assert.equal(tag.validate(snapshot), true);
snapshot = tag.value();
assert.equal(tag.validate(snapshot), true);
(0, _metal.set)(tom, 'first', 'Thomas');
assert.equal(tag.validate(snapshot), false, 'invalid after setting with Ember set');
assert.equal(obj.full, 'Thomas Dale');
snapshot = tag.value();
assert.equal(tag.validate(snapshot), true);
};
_proto["@test interaction with Ember object model (Ember computed property depending on tracked property)"] = function (assert) {
var EmberObject = function EmberObject(name) {
this.name = name;
};
(0, _metal.defineProperty)(EmberObject.prototype, 'full', (0, _metal.computed)('name', function () {
var name = (0, _metal.get)(this, 'name');
return name.first + " " + name.last;
}));
var Name = function Name(first, last) {
this.first = first;
this.last = last;
};
__decorate([_metal.tracked], Name.prototype, "first", void 0);
__decorate([_metal.tracked], Name.prototype, "last", void 0);
var tom = new Name('Tom', 'Dale');
var obj = new EmberObject(tom);
var tag = (0, _metal.tagForProperty)(obj, 'full');
var snapshot = tag.value();
var full = (0, _metal.get)(obj, 'full');
assert.equal(full, 'Tom Dale');
assert.equal(tag.validate(snapshot), true);
snapshot = tag.value();
assert.equal(tag.validate(snapshot), true);
tom.first = 'Thomas';
assert.equal(tag.validate(snapshot), false, 'invalid after setting with tracked properties');
assert.equal((0, _metal.get)(obj, 'full'), 'Thomas Dale');
snapshot = tag.value();
assert.equal(tag.validate(snapshot), true);
};
_proto['@test interaction with the Ember object model (paths going through tracked properties)'] = function testInteractionWithTheEmberObjectModelPathsGoingThroughTrackedProperties(assert) {
var self;
var EmberObject = function EmberObject(contact) {
this.contact = contact;
self = this;
};
(0, _metal.defineProperty)(EmberObject.prototype, 'full', (0, _metal.computed)('contact.name.first', 'contact.name.last', function () {
var contact = (0, _metal.get)(self, 'contact');
return (0, _metal.get)(contact.name, 'first') + " " + (0, _metal.get)(contact.name, 'last');
}));
var Contact = function Contact(name) {
this.name = undefined;
this.name = name;
};
__decorate([_metal.tracked], Contact.prototype, "name", void 0);
var EmberName = function EmberName(first, last) {
this.first = first;
this.last = last;
};
var tom = new EmberName('Tom', 'Dale');
var contact = new Contact(tom);
var obj = new EmberObject(contact);
var tag = (0, _metal.tagForProperty)(obj, 'full');
var snapshot = tag.value();
var full = (0, _metal.get)(obj, 'full');
assert.equal(full, 'Tom Dale');
assert.equal(tag.validate(snapshot), true);
snapshot = tag.value();
assert.equal(tag.validate(snapshot), true);
(0, _metal.set)(tom, 'first', 'Thomas');
assert.equal(tag.validate(snapshot), false, 'invalid after setting with Ember.set');
assert.equal((0, _metal.get)(obj, 'full'), 'Thomas Dale');
snapshot = tag.value();
tom = contact.name = new EmberName('T', 'Dale');
assert.equal(tag.validate(snapshot), false, 'invalid after setting with Ember.set');
assert.equal((0, _metal.get)(obj, 'full'), 'T Dale');
snapshot = tag.value();
(0, _metal.set)(tom, 'first', 'Tizzle');
assert.equal(tag.validate(snapshot), false, 'invalid after setting with Ember.set');
assert.equal((0, _metal.get)(obj, 'full'), 'Tizzle Dale');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
}
});
enifed("@ember/-internals/metal/tests/watching/is_watching_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
function testObserver(assert, setup, teardown) {
var key = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'key';
var obj = {};
assert.equal((0, _metal.isWatching)(obj, key), false, 'precond - isWatching is false by default');
setup(obj, key, 'fn');
assert.equal((0, _metal.isWatching)(obj, key), true, 'isWatching is true when observers are added');
teardown(obj, key, 'fn');
assert.equal((0, _metal.isWatching)(obj, key), false, 'isWatching is false after observers are removed');
}
(0, _internalTestHelpers.moduleFor)('isWatching',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test isWatching is true for regular local observers'] = function testIsWatchingIsTrueForRegularLocalObservers(assert) {
testObserver(assert, function (obj, key, fn) {
var _Mixin$create;
_metal.Mixin.create((_Mixin$create = {}, _Mixin$create[fn] = (0, _metal.observer)(key, function () {}), _Mixin$create)).apply(obj);
}, function (obj, key, fn) {
return (0, _metal.removeObserver)(obj, key, obj, fn);
});
};
_proto['@test isWatching is true for nonlocal observers'] = function testIsWatchingIsTrueForNonlocalObservers(assert) {
testObserver(assert, function (obj, key, fn) {
(0, _metal.addObserver)(obj, key, obj, fn);
}, function (obj, key, fn) {
return (0, _metal.removeObserver)(obj, key, obj, fn);
});
};
_proto['@test isWatching is true for chained observers'] = function testIsWatchingIsTrueForChainedObservers(assert) {
testObserver(assert, function (obj, key, fn) {
(0, _metal.addObserver)(obj, key + '.bar', obj, fn);
}, function (obj, key, fn) {
(0, _metal.removeObserver)(obj, key + '.bar', obj, fn);
});
};
_proto['@test isWatching is true for computed properties'] = function testIsWatchingIsTrueForComputedProperties(assert) {
testObserver(assert, function (obj, key, fn) {
(0, _metal.defineProperty)(obj, fn, (0, _metal.computed)(function () {}).property(key));
(0, _metal.get)(obj, fn);
}, function (obj, key, fn) {
return (0, _metal.defineProperty)(obj, fn, null);
});
};
_proto['@test isWatching is true for chained computed properties'] = function testIsWatchingIsTrueForChainedComputedProperties(assert) {
testObserver(assert, function (obj, key, fn) {
(0, _metal.defineProperty)(obj, fn, (0, _metal.computed)(function () {}).property(key + '.bar'));
(0, _metal.get)(obj, fn);
}, function (obj, key, fn) {
return (0, _metal.defineProperty)(obj, fn, null);
});
} // can't watch length on Array - it is special...
// But you should be able to watch a length property of an object
;
_proto["@test isWatching is true for 'length' property on object"] = function testIsWatchingIsTrueForLengthPropertyOnObject(assert) {
testObserver(assert, function (obj, key, fn) {
(0, _metal.defineProperty)(obj, 'length', null, '26.2 miles');
(0, _metal.addObserver)(obj, 'length', obj, fn);
}, function (obj, key, fn) {
return (0, _metal.removeObserver)(obj, 'length', obj, fn);
}, 'length');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/watching/unwatch_test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _metal, _internalTestHelpers) {
"use strict";
var didCount;
function addListeners(obj, keyPath) {
(0, _metal.addListener)(obj, keyPath + ':change', function () {
return didCount++;
});
}
(0, _internalTestHelpers.moduleFor)('unwatch',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
didCount = 0;
};
_proto['@test unwatching a computed property - regular get/set'] = function testUnwatchingAComputedPropertyRegularGetSet(assert) {
var obj = {};
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)({
get: function () {
return this.__foo;
},
set: function (keyName, value) {
this.__foo = value;
return this.__foo;
}
}));
addListeners(obj, 'foo');
(0, _metal.watch)(obj, 'foo');
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(didCount, 1, 'should have invoked didCount');
(0, _metal.unwatch)(obj, 'foo');
didCount = 0;
(0, _metal.set)(obj, 'foo', 'BAZ');
assert.equal(didCount, 0, 'should NOT have invoked didCount');
};
_proto['@test unwatching a regular property - regular get/set'] = function testUnwatchingARegularPropertyRegularGetSet(assert) {
var obj = {
foo: 'BIFF'
};
addListeners(obj, 'foo');
(0, _metal.watch)(obj, 'foo');
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(didCount, 1, 'should have invoked didCount');
(0, _metal.unwatch)(obj, 'foo');
didCount = 0;
(0, _metal.set)(obj, 'foo', 'BAZ');
assert.equal(didCount, 0, 'should NOT have invoked didCount');
};
_proto['@test unwatching should be nested'] = function testUnwatchingShouldBeNested(assert) {
var obj = {
foo: 'BIFF'
};
addListeners(obj, 'foo');
(0, _metal.watch)(obj, 'foo');
(0, _metal.watch)(obj, 'foo');
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(didCount, 1, 'should have invoked didCount');
(0, _metal.unwatch)(obj, 'foo');
didCount = 0;
(0, _metal.set)(obj, 'foo', 'BAZ');
assert.equal(didCount, 1, 'should NOT have invoked didCount');
(0, _metal.unwatch)(obj, 'foo');
didCount = 0;
(0, _metal.set)(obj, 'foo', 'BAZ');
assert.equal(didCount, 0, 'should NOT have invoked didCount');
};
_proto['@test unwatching "length" property on an object'] = function testUnwatchingLengthPropertyOnAnObject(assert) {
var obj = {
foo: 'RUN'
};
addListeners(obj, 'length'); // Can watch length when it is undefined
(0, _metal.watch)(obj, 'length');
(0, _metal.set)(obj, 'length', '10k');
assert.equal(didCount, 1, 'should have invoked didCount'); // Should stop watching despite length now being defined (making object 'array-like')
(0, _metal.unwatch)(obj, 'length');
didCount = 0;
(0, _metal.set)(obj, 'length', '5k');
assert.equal(didCount, 0, 'should NOT have invoked didCount');
};
_proto['@test unwatching should not destroy non MANDATORY_SETTER descriptor'] = function testUnwatchingShouldNotDestroyNonMANDATORY_SETTERDescriptor(assert) {
var obj = {
get foo() {
return 'RUN';
}
};
assert.equal(obj.foo, 'RUN', 'obj.foo');
(0, _metal.watch)(obj, 'foo');
assert.equal(obj.foo, 'RUN', 'obj.foo after watch');
(0, _metal.unwatch)(obj, 'foo');
assert.equal(obj.foo, 'RUN', 'obj.foo after unwatch');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/metal/tests/watching/watch_test", ["ember-babel", "@ember/-internals/environment", "@ember/-internals/metal", "@ember/-internals/meta", "internal-test-helpers"], function (_emberBabel, _environment, _metal, _meta, _internalTestHelpers) {
"use strict";
var didCount, didKeys, originalLookup;
function addListeners(obj, keyPath) {
(0, _metal.addListener)(obj, keyPath + ':change', function () {
didCount++;
didKeys.push(keyPath);
});
}
(0, _internalTestHelpers.moduleFor)('watch',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
didCount = 0;
didKeys = [];
originalLookup = _environment.context.lookup;
_environment.context.lookup = {};
};
_proto.afterEach = function afterEach() {
_environment.context.lookup = originalLookup;
};
_proto['@test watching a computed property'] = function testWatchingAComputedProperty(assert) {
var obj = {};
(0, _metal.defineProperty)(obj, 'foo', (0, _metal.computed)({
get: function () {
return this.__foo;
},
set: function (keyName, value) {
if (value !== undefined) {
this.__foo = value;
}
return this.__foo;
}
}));
addListeners(obj, 'foo');
(0, _metal.watch)(obj, 'foo');
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(didCount, 1, 'should have invoked didCount');
};
_proto['@test watching a regular defined property'] = function testWatchingARegularDefinedProperty(assert) {
var obj = {
foo: 'baz'
};
addListeners(obj, 'foo');
(0, _metal.watch)(obj, 'foo');
assert.equal((0, _metal.get)(obj, 'foo'), 'baz', 'should have original prop');
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(didCount, 1, 'should have invoked didCount');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar', 'should get new value');
assert.equal(obj.foo, 'bar', 'property should be accessible on obj');
};
_proto['@test watching a regular undefined property'] = function testWatchingARegularUndefinedProperty(assert) {
var obj = {};
addListeners(obj, 'foo');
(0, _metal.watch)(obj, 'foo');
assert.equal('foo' in obj, false, 'precond undefined');
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal(didCount, 1, 'should have invoked didCount');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar', 'should get new value');
assert.equal(obj.foo, 'bar', 'property should be accessible on obj');
};
_proto['@test watches should inherit'] = function testWatchesShouldInherit(assert) {
var obj = {
foo: 'baz'
};
var objB = Object.create(obj);
addListeners(obj, 'foo');
(0, _metal.watch)(obj, 'foo');
assert.equal((0, _metal.get)(obj, 'foo'), 'baz', 'should have original prop');
(0, _metal.set)(objB, 'foo', 'bar');
(0, _metal.set)(obj, 'foo', 'baz');
assert.equal(didCount, 1, 'should have invoked didCount once only');
};
_proto['@test watching an object THEN defining it should work also'] = function testWatchingAnObjectTHENDefiningItShouldWorkAlso(assert) {
var obj = {};
addListeners(obj, 'foo');
(0, _metal.watch)(obj, 'foo');
(0, _metal.defineProperty)(obj, 'foo');
(0, _metal.set)(obj, 'foo', 'bar');
assert.equal((0, _metal.get)(obj, 'foo'), 'bar', 'should have set');
assert.equal(didCount, 1, 'should have invoked didChange once');
};
_proto['@test watching a chain then defining the property'] = function testWatchingAChainThenDefiningTheProperty(assert) {
var obj = {};
var foo = {
bar: 'bar'
};
addListeners(obj, 'foo.bar');
addListeners(foo, 'bar');
(0, _metal.watch)(obj, 'foo.bar');
(0, _metal.defineProperty)(obj, 'foo', undefined, foo);
(0, _metal.set)(foo, 'bar', 'baz');
assert.deepEqual(didKeys, ['foo.bar', 'bar'], 'should have invoked didChange with bar, foo.bar');
assert.equal(didCount, 2, 'should have invoked didChange twice');
};
_proto['@test watching a chain then defining the nested property'] = function testWatchingAChainThenDefiningTheNestedProperty(assert) {
var bar = {};
var obj = {
foo: bar
};
var baz = {
baz: 'baz'
};
addListeners(obj, 'foo.bar.baz');
addListeners(baz, 'baz');
(0, _metal.watch)(obj, 'foo.bar.baz');
(0, _metal.defineProperty)(bar, 'bar', undefined, baz);
(0, _metal.set)(baz, 'baz', 'BOO');
assert.deepEqual(didKeys, ['foo.bar.baz', 'baz'], 'should have invoked didChange with bar, foo.bar');
assert.equal(didCount, 2, 'should have invoked didChange twice');
};
_proto['@test watching an object value then unwatching should restore old value'] = function testWatchingAnObjectValueThenUnwatchingShouldRestoreOldValue(assert) {
var obj = {
foo: {
bar: {
baz: {
biff: 'BIFF'
}
}
}
};
addListeners(obj, 'foo.bar.baz.biff');
(0, _metal.watch)(obj, 'foo.bar.baz.biff');
var foo = (0, _metal.get)(obj, 'foo');
assert.equal((0, _metal.get)((0, _metal.get)((0, _metal.get)(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist');
(0, _metal.unwatch)(obj, 'foo.bar.baz.biff');
assert.equal((0, _metal.get)((0, _metal.get)((0, _metal.get)(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist');
};
_proto['@test when watching another object, destroy should remove chain watchers from the other object'] = function testWhenWatchingAnotherObjectDestroyShouldRemoveChainWatchersFromTheOtherObject(assert) {
var objA = {};
var objB = {
foo: 'bar'
};
objA.b = objB;
addListeners(objA, 'b.foo');
(0, _metal.watch)(objA, 'b.foo');
var meta_objB = (0, _meta.meta)(objB);
var chainNode = (0, _meta.meta)(objA).readableChains().chains.b.chains.foo;
assert.equal(meta_objB.peekWatching('foo'), 1, 'should be watching foo');
assert.equal(meta_objB.readableChainWatchers().has('foo', chainNode), true, 'should have chain watcher');
(0, _meta.deleteMeta)(objA);
assert.equal(meta_objB.peekWatching('foo'), 0, 'should not be watching foo');
assert.equal(meta_objB.readableChainWatchers().has('foo', chainNode), false, 'should not have chain watcher');
} // TESTS for length property
;
_proto['@test watching "length" property on an object'] = function testWatchingLengthPropertyOnAnObject(assert) {
var obj = {
length: '26.2 miles'
};
addListeners(obj, 'length');
(0, _metal.watch)(obj, 'length');
assert.equal((0, _metal.get)(obj, 'length'), '26.2 miles', 'should have original prop');
(0, _metal.set)(obj, 'length', '10k');
assert.equal(didCount, 1, 'should have invoked didCount');
assert.equal((0, _metal.get)(obj, 'length'), '10k', 'should get new value');
assert.equal(obj.length, '10k', 'property should be accessible on obj');
};
_proto['@test watching "length" property on an array'] = function testWatchingLengthPropertyOnAnArray(assert) {
var arr = [];
addListeners(arr, 'length');
(0, _metal.watch)(arr, 'length');
assert.equal((0, _metal.get)(arr, 'length'), 0, 'should have original prop');
(0, _metal.set)(arr, 'length', '10');
assert.equal(didCount, 1, 'should NOT have invoked didCount');
assert.equal((0, _metal.get)(arr, 'length'), 10, 'should get new value');
assert.equal(arr.length, 10, 'property should be accessible on arr');
};
_proto['@test watch + ES5 getter'] = function testWatchES5Getter(assert) {
var parent = {
b: 1
};
var child = {
get b() {
return parent.b;
}
};
assert.equal(parent.b, 1, 'parent.b should be 1');
assert.equal(child.b, 1, 'child.b should be 1');
assert.equal((0, _metal.get)(child, 'b'), 1, 'get(child, "b") should be 1');
(0, _metal.watch)(child, 'b');
assert.equal(parent.b, 1, 'parent.b should be 1 (after watch)');
assert.equal(child.b, 1, 'child.b should be 1 (after watch)');
assert.equal((0, _metal.get)(child, 'b'), 1, 'get(child, "b") should be 1 (after watch)');
};
_proto['@test watch + set + no-descriptor'] = function testWatchSetNoDescriptor(assert) {
var child = {};
assert.equal(child.b, undefined, 'child.b ');
assert.equal((0, _metal.get)(child, 'b'), undefined, 'get(child, "b")');
(0, _metal.watch)(child, 'b');
(0, _metal.set)(child, 'b', 1);
assert.equal(child.b, 1, 'child.b (after watch)');
assert.equal((0, _metal.get)(child, 'b'), 1, 'get(child, "b") (after watch)');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/routing/tests/ext/controller_test", ["ember-babel", "@ember/-internals/owner", "@ember/controller", "internal-test-helpers"], function (_emberBabel, _owner, _controller, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('@ember/-internals/routing/ext/controller',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto["@test transitionToRoute considers an engine's mountPoint"] = function testTransitionToRouteConsidersAnEngineSMountPoint(assert) {
var router = {
transitionTo: function (route) {
return route;
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var controller = _controller.default.create({
target: router
});
(0, _owner.setOwner)(controller, engineInstance);
assert.strictEqual(controller.transitionToRoute('application'), 'foo.bar.application', 'properly prefixes application route');
assert.strictEqual(controller.transitionToRoute('posts'), 'foo.bar.posts', 'properly prefixes child routes');
assert.throws(function () {
return controller.transitionToRoute('/posts');
}, 'throws when trying to use a url');
var queryParams = {};
assert.strictEqual(controller.transitionToRoute(queryParams), queryParams, 'passes query param only transitions through');
};
_proto["@test replaceRoute considers an engine's mountPoint"] = function testReplaceRouteConsidersAnEngineSMountPoint(assert) {
var router = {
replaceWith: function (route) {
return route;
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var controller = _controller.default.create({
target: router
});
(0, _owner.setOwner)(controller, engineInstance);
assert.strictEqual(controller.replaceRoute('application'), 'foo.bar.application', 'properly prefixes application route');
assert.strictEqual(controller.replaceRoute('posts'), 'foo.bar.posts', 'properly prefixes child routes');
assert.throws(function () {
return controller.replaceRoute('/posts');
}, 'throws when trying to use a url');
var queryParams = {};
assert.strictEqual(controller.replaceRoute(queryParams), queryParams, 'passes query param only transitions through');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/routing/tests/location/auto_location_test", ["ember-babel", "@ember/-internals/owner", "@ember/polyfills", "@ember/-internals/browser-environment", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/routing/lib/location/auto_location", "@ember/-internals/routing/lib/location/history_location", "@ember/-internals/routing/lib/location/hash_location", "@ember/-internals/routing/lib/location/none_location", "internal-test-helpers"], function (_emberBabel, _owner, _polyfills, _browserEnvironment, _runloop, _metal, _auto_location, _history_location, _hash_location, _none_location, _internalTestHelpers) {
"use strict";
function mockBrowserLocation(overrides, assert) {
return (0, _polyfills.assign)({
href: 'http://test.com/',
pathname: '/',
hash: '',
search: '',
replace: function () {
assert.ok(false, 'location.replace should not be called during testing');
}
}, overrides);
}
function mockBrowserHistory(overrides, assert) {
return (0, _polyfills.assign)({
pushState: function () {
assert.ok(false, 'history.pushState should not be called during testing');
},
replaceState: function () {
assert.ok(false, 'history.replaceState should not be called during testing');
}
}, overrides);
}
function createLocation(location, history) {
var _AutoLocation$create;
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[_owner.OWNER] = owner, _AutoLocation$create.location = location, _AutoLocation$create.history = history, _AutoLocation$create.global = {}, _AutoLocation$create));
return autolocation;
}
var location, owner;
(0, _internalTestHelpers.moduleFor)('AutoLocation',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
if (owner) {
(0, _runloop.run)(owner, 'destroy');
owner = location = undefined;
}
};
_proto['@test AutoLocation should have the `global`'] = function testAutoLocationShouldHaveTheGlobal(assert) {
var location = _auto_location.default.create();
assert.ok(location.global, 'has a global defined');
assert.strictEqual(location.global, _browserEnvironment.window, 'has the environments window global');
};
_proto["@test AutoLocation should return concrete implementation's value for `getURL`"] = function testAutoLocationShouldReturnConcreteImplementationSValueForGetURL(assert) {
var browserLocation = mockBrowserLocation({}, assert);
var browserHistory = mockBrowserHistory({}, assert);
location = createLocation(browserLocation, browserHistory);
location.detect();
var concreteImplementation = (0, _metal.get)(location, 'concreteImplementation');
concreteImplementation.getURL = function () {
return '/lincoln/park';
};
assert.equal(location.getURL(), '/lincoln/park');
};
_proto['@test AutoLocation should use a HistoryLocation instance when pushStates is supported'] = function testAutoLocationShouldUseAHistoryLocationInstanceWhenPushStatesIsSupported(assert) {
var browserLocation = mockBrowserLocation({}, assert);
var browserHistory = mockBrowserHistory({}, assert);
location = createLocation(browserLocation, browserHistory);
location.detect();
assert.ok((0, _metal.get)(location, 'concreteImplementation') instanceof _history_location.default);
};
_proto['@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 testAutoLocationShouldUseAHashLocationInstanceWhenPushStatesAreNotSupportedButHashchangeEventsAreAndTheURLIsAlreadyInTheHashLocationFormat(assert) {
var browserLocation = mockBrowserLocation({
hash: '#/testd'
}, assert);
location = createLocation(browserLocation);
location.global = {
onhashchange: function () {}
};
location.detect();
assert.ok((0, _metal.get)(location, 'concreteImplementation') instanceof _hash_location.default);
};
_proto['@test AutoLocation should use a NoneLocation instance when neither history nor hashchange are supported.'] = function testAutoLocationShouldUseANoneLocationInstanceWhenNeitherHistoryNorHashchangeAreSupported(assert) {
location = createLocation(mockBrowserLocation({}, assert));
location.detect();
assert.ok((0, _metal.get)(location, 'concreteImplementation') instanceof _none_location.default);
};
_proto["@test AutoLocation should use an index path (i.e. '/') without any location.hash as OK for HashLocation"] = function testAutoLocationShouldUseAnIndexPathIEWithoutAnyLocationHashAsOKForHashLocation(assert) {
var browserLocation = mockBrowserLocation({
href: 'http://test.com/',
pathname: '/',
hash: '',
search: '',
replace: function () {
assert.ok(false, 'location.replace should not be called');
}
}, assert);
location = createLocation(browserLocation);
location.global = {
onhashchange: function () {}
};
location.detect();
assert.ok((0, _metal.get)(location, 'concreteImplementation') instanceof _hash_location.default, 'uses a HashLocation');
};
_proto['@test AutoLocation should transform the URL for hashchange-only browsers viewing a HistoryLocation-formatted path'] = function testAutoLocationShouldTransformTheURLForHashchangeOnlyBrowsersViewingAHistoryLocationFormattedPath(assert) {
assert.expect(3);
var browserLocation = mockBrowserLocation({
hash: '',
hostname: 'test.com',
href: 'http://test.com/test',
pathname: '/test',
protocol: 'http:',
port: '',
search: '',
replace: function (path) {
assert.equal(path, 'http://test.com/#/test', 'location.replace should be called with normalized HashLocation path');
}
}, assert);
var location = createLocation(browserLocation);
location.global = {
onhashchange: function () {}
};
location.detect();
assert.ok((0, _metal.get)(location, 'concreteImplementation') instanceof _none_location.default, 'NoneLocation should be used while we attempt to location.replace()');
assert.equal((0, _metal.get)(location, 'cancelRouterSetup'), true, 'cancelRouterSetup should be set so the router knows.');
};
_proto['@test AutoLocation should replace the URL for pushState-supported browsers viewing a HashLocation-formatted url'] = function testAutoLocationShouldReplaceTheURLForPushStateSupportedBrowsersViewingAHashLocationFormattedUrl(assert) {
assert.expect(2);
var browserLocation = mockBrowserLocation({
hash: '#/test',
hostname: 'test.com',
href: 'http://test.com/#/test',
pathname: '/',
protocol: 'http:',
port: '',
search: ''
}, assert);
var browserHistory = mockBrowserHistory({
replaceState: function (state, title, path) {
assert.equal(path, '/test', 'history.replaceState should be called with normalized HistoryLocation url');
}
}, assert);
var location = createLocation(browserLocation, browserHistory);
location.detect();
assert.ok((0, _metal.get)(location, 'concreteImplementation'), _history_location.default);
};
_proto['@test AutoLocation requires any rootURL given to end in a trailing forward slash'] = function testAutoLocationRequiresAnyRootURLGivenToEndInATrailingForwardSlash(assert) {
var browserLocation = mockBrowserLocation({}, assert);
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);
};
_proto['@test AutoLocation provides its rootURL to the concreteImplementation'] = function testAutoLocationProvidesItsRootURLToTheConcreteImplementation(assert) {
var browserLocation = mockBrowserLocation({
pathname: '/some/subdir/derp'
}, assert);
var browserHistory = mockBrowserHistory({}, assert);
location = createLocation(browserLocation, browserHistory);
location.rootURL = '/some/subdir/';
location.detect();
var concreteLocation = (0, _metal.get)(location, 'concreteImplementation');
assert.equal(location.rootURL, concreteLocation.rootURL);
};
_proto['@test getHistoryPath() should return a normalized, HistoryLocation-supported path'] = function testGetHistoryPathShouldReturnANormalizedHistoryLocationSupportedPath(assert) {
var browserLocation = mockBrowserLocation({
href: 'http://test.com/app/about?foo=bar#foo',
pathname: '/app/about',
search: '?foo=bar',
hash: '#foo'
}, assert);
assert.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'
}, assert);
assert.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'
}, assert);
assert.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");
};
_proto['@test getHashPath() should return a normalized, HashLocation-supported path'] = function testGetHashPathShouldReturnANormalizedHashLocationSupportedPath(assert) {
var browserLocation = mockBrowserLocation({
href: 'http://test.com/app/#/about?foo=bar#foo',
pathname: '/app/',
search: '',
hash: '#/about?foo=bar#foo'
}, assert);
assert.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'
}, assert);
assert.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'
}, assert);
assert.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");
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/routing/tests/location/hash_location_test", ["ember-babel", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/routing/lib/location/hash_location", "internal-test-helpers"], function (_emberBabel, _runloop, _metal, _hash_location, _internalTestHelpers) {
"use strict";
var location;
function createLocation(options, assert) {
var HashTestLocation = _hash_location.default.extend({
_location: {
href: 'http://test.com/',
pathname: '/',
hash: '',
search: '',
replace: function () {
assert.ok(false, 'location.replace should not be called during testing');
}
}
});
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);
}
(0, _internalTestHelpers.moduleFor)('HashLocation',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
(0, _runloop.run)(function () {
if (location) {
location.destroy();
}
});
};
_proto['@test HashLocation.getURL() returns the current url'] = function testHashLocationGetURLReturnsTheCurrentUrl(assert) {
createLocation({
_location: mockBrowserLocation('/#/foo/bar')
}, assert);
assert.equal(location.getURL(), '/foo/bar');
};
_proto['@test HashLocation.getURL() includes extra hashes'] = function testHashLocationGetURLIncludesExtraHashes(assert) {
createLocation({
_location: mockBrowserLocation('/#/foo#bar#car')
}, assert);
assert.equal(location.getURL(), '/foo#bar#car');
};
_proto['@test HashLocation.getURL() assumes location.hash without #/ prefix is not a route path'] = function testHashLocationGetURLAssumesLocationHashWithoutPrefixIsNotARoutePath(assert) {
createLocation({
_location: mockBrowserLocation('/#foo#bar')
}, assert);
assert.equal(location.getURL(), '/#foo#bar');
};
_proto['@test HashLocation.getURL() returns a normal forward slash when there is no location.hash'] = function testHashLocationGetURLReturnsANormalForwardSlashWhenThereIsNoLocationHash(assert) {
createLocation({
_location: mockBrowserLocation('/')
}, assert);
assert.equal(location.getURL(), '/');
};
_proto['@test HashLocation.setURL() correctly sets the url'] = function testHashLocationSetURLCorrectlySetsTheUrl(assert) {
createLocation({}, assert);
location.setURL('/bar');
assert.equal((0, _metal.get)(location, 'location.hash'), '/bar');
assert.equal((0, _metal.get)(location, 'lastSetURL'), '/bar');
};
_proto['@test HashLocation.replaceURL() correctly replaces to the path with a page reload'] = function testHashLocationReplaceURLCorrectlyReplacesToThePathWithAPageReload(assert) {
assert.expect(2);
createLocation({
_location: {
replace: function (path) {
assert.equal(path, '#/foo');
}
}
}, assert);
location.replaceURL('/foo');
assert.equal((0, _metal.get)(location, 'lastSetURL'), '/foo');
};
_proto['@test HashLocation.onUpdateURL callback executes as expected'] = function testHashLocationOnUpdateURLCallbackExecutesAsExpected(assert) {
assert.expect(1);
createLocation({
_location: mockBrowserLocation('/#/foo/bar')
}, assert);
var callback = function (param) {
assert.equal(param, '/foo/bar', 'path is passed as param');
};
location.onUpdateURL(callback);
triggerHashchange();
};
_proto["@test HashLocation.onUpdateURL doesn't execute callback if lastSetURL === path"] = function testHashLocationOnUpdateURLDoesnTExecuteCallbackIfLastSetURLPath(assert) {
assert.expect(0);
createLocation({
_location: {
hash: '#/foo/bar'
},
lastSetURL: '/foo/bar'
}, assert);
var callback = function () {
assert.ok(false, 'callback should not be called');
};
location.onUpdateURL(callback);
triggerHashchange();
};
_proto['@test HashLocation.formatURL() prepends a # to the provided string'] = function testHashLocationFormatURLPrependsAToTheProvidedString(assert) {
createLocation({}, assert);
assert.equal(location.formatURL('/foo#bar'), '#/foo#bar');
};
_proto['@test HashLocation.willDestroy() cleans up hashchange event listener'] = function testHashLocationWillDestroyCleansUpHashchangeEventListener(assert) {
assert.expect(1);
createLocation({}, assert);
var callback = function () {
assert.ok(true, 'should invoke callback once');
};
location.onUpdateURL(callback);
triggerHashchange();
(0, _runloop.run)(location, 'destroy');
location = null;
triggerHashchange();
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/routing/tests/location/history_location_test", ["ember-babel", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/routing/lib/location/history_location", "internal-test-helpers"], function (_emberBabel, _runloop, _metal, _history_location, _internalTestHelpers) {
"use strict";
var FakeHistory, HistoryTestLocation, location;
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
};
}
(0, _internalTestHelpers.moduleFor)('HistoryLocation',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
var _this;
_this = _AbstractTestCase.call(this) || this;
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
});
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
(0, _runloop.run)(function () {
if (location) {
location.destroy();
}
});
};
_proto['@test HistoryLocation initState does not get fired on init'] = function testHistoryLocationInitStateDoesNotGetFiredOnInit(assert) {
assert.expect(1);
HistoryTestLocation.reopen({
init: function () {
assert.ok(true, 'init was called');
this._super.apply(this, arguments);
},
initState: function () {
assert.ok(false, 'initState() should not be called automatically');
}
});
createLocation();
};
_proto["@test webkit doesn't fire popstate on page load"] = function testWebkitDoesnTFirePopstateOnPageLoad(assert) {
assert.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
assert.equal(this._previousURL, this.getURL());
}
});
createLocation();
location.initState();
};
_proto['@test base URL is removed when retrieving the current pathname'] = function testBaseURLIsRemovedWhenRetrievingTheCurrentPathname(assert) {
assert.expect(1);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'location', mockBrowserLocation('/base/foo/bar'));
(0, _metal.set)(this, 'baseURL', '/base/');
},
initState: function () {
this._super.apply(this, arguments);
assert.equal(this.getURL(), '/foo/bar');
}
});
createLocation();
location.initState();
};
_proto['@test base URL is preserved when moving around'] = function testBaseURLIsPreservedWhenMovingAround(assert) {
assert.expect(2);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'location', mockBrowserLocation('/base/foo/bar'));
(0, _metal.set)(this, 'baseURL', '/base/');
}
});
createLocation();
location.initState();
location.setURL('/one/two');
assert.equal(location._historyState.path, '/base/one/two');
assert.ok(location._historyState.uuid);
};
_proto['@test setURL continues to set even with a null state (iframes may set this)'] = function testSetURLContinuesToSetEvenWithANullStateIframesMaySetThis(assert) {
createLocation();
location.initState();
FakeHistory.pushState(null);
location.setURL('/three/four');
assert.equal(location._historyState.path, '/three/four');
assert.ok(location._historyState.uuid);
};
_proto['@test replaceURL continues to set even with a null state (iframes may set this)'] = function testReplaceURLContinuesToSetEvenWithANullStateIframesMaySetThis(assert) {
createLocation();
location.initState();
FakeHistory.pushState(null);
location.replaceURL('/three/four');
assert.equal(location._historyState.path, '/three/four');
assert.ok(location._historyState.uuid);
};
_proto['@test HistoryLocation.getURL() returns the current url, excluding both rootURL and baseURL'] = function testHistoryLocationGetURLReturnsTheCurrentUrlExcludingBothRootURLAndBaseURL(assert) {
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'location', mockBrowserLocation('/base/foo/bar'));
(0, _metal.set)(this, 'rootURL', '/app/');
(0, _metal.set)(this, 'baseURL', '/base/');
}
});
createLocation();
assert.equal(location.getURL(), '/foo/bar');
};
_proto['@test HistoryLocation.getURL() returns the current url, does not remove rootURL if its not at start of url'] = function testHistoryLocationGetURLReturnsTheCurrentUrlDoesNotRemoveRootURLIfItsNotAtStartOfUrl(assert) {
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'location', mockBrowserLocation('/foo/bar/baz'));
(0, _metal.set)(this, 'rootURL', '/bar/');
}
});
createLocation();
assert.equal(location.getURL(), '/foo/bar/baz');
};
_proto['@test HistoryLocation.getURL() will not remove the rootURL when only a partial match'] = function testHistoryLocationGetURLWillNotRemoveTheRootURLWhenOnlyAPartialMatch(assert) {
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'location', mockBrowserLocation('/bars/baz'));
(0, _metal.set)(this, 'rootURL', '/bar/');
}
});
createLocation();
assert.equal(location.getURL(), '/bars/baz');
};
_proto['@test HistoryLocation.getURL() returns the current url, does not remove baseURL if its not at start of url'] = function testHistoryLocationGetURLReturnsTheCurrentUrlDoesNotRemoveBaseURLIfItsNotAtStartOfUrl(assert) {
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'location', mockBrowserLocation('/foo/bar/baz'));
(0, _metal.set)(this, 'baseURL', '/bar/');
}
});
createLocation();
assert.equal(location.getURL(), '/foo/bar/baz');
};
_proto['@test HistoryLocation.getURL() will not remove the baseURL when only a partial match'] = function testHistoryLocationGetURLWillNotRemoveTheBaseURLWhenOnlyAPartialMatch(assert) {
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'location', mockBrowserLocation('/bars/baz'));
(0, _metal.set)(this, 'baseURL', '/bar/');
}
});
createLocation();
assert.equal(location.getURL(), '/bars/baz');
};
_proto['@test HistoryLocation.getURL() includes location.search'] = function testHistoryLocationGetURLIncludesLocationSearch(assert) {
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'location', mockBrowserLocation('/foo/bar?time=morphin'));
}
});
createLocation();
assert.equal(location.getURL(), '/foo/bar?time=morphin');
};
_proto['@test HistoryLocation.getURL() includes location.hash'] = function testHistoryLocationGetURLIncludesLocationHash(assert) {
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'location', mockBrowserLocation('/foo/bar#pink-power-ranger'));
}
});
createLocation();
assert.equal(location.getURL(), '/foo/bar#pink-power-ranger');
};
_proto['@test HistoryLocation.getURL() includes location.hash and location.search'] = function testHistoryLocationGetURLIncludesLocationHashAndLocationSearch(assert) {
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'location', mockBrowserLocation('/foo/bar?time=morphin#pink-power-ranger'));
}
});
createLocation();
assert.equal(location.getURL(), '/foo/bar?time=morphin#pink-power-ranger');
};
_proto['@test HistoryLocation.getURL() drops duplicate slashes'] = function testHistoryLocationGetURLDropsDuplicateSlashes(assert) {
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
var location = mockBrowserLocation('//');
location.pathname = '//'; // mockBrowserLocation does not allow for `//`, so force it
(0, _metal.set)(this, 'location', location);
}
});
createLocation();
assert.equal(location.getURL(), '/');
};
_proto['@test Existing state is preserved on init'] = function testExistingStateIsPreservedOnInit(assert) {
var existingState = {
path: '/route/path',
uuid: 'abcd'
};
FakeHistory.state = existingState;
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'location', mockBrowserLocation('/route/path'));
}
});
createLocation();
location.initState();
assert.deepEqual(location.getState(), existingState);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/routing/tests/location/none_location_test", ["ember-babel", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/routing/lib/location/none_location", "internal-test-helpers"], function (_emberBabel, _runloop, _metal, _none_location, _internalTestHelpers) {
"use strict";
var NoneTestLocation, location;
function createLocation(options) {
if (!options) {
options = {};
}
location = NoneTestLocation.create(options);
}
(0, _internalTestHelpers.moduleFor)('NoneLocation',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
var _this;
_this = _AbstractTestCase.call(this) || this;
NoneTestLocation = _none_location.default.extend({});
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
(0, _runloop.run)(function () {
if (location) {
location.destroy();
}
});
};
_proto['@test NoneLocation.formatURL() returns the current url always appending rootURL'] = function testNoneLocationFormatURLReturnsTheCurrentUrlAlwaysAppendingRootURL(assert) {
NoneTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'rootURL', '/en/');
}
});
createLocation();
assert.equal(location.formatURL('/foo/bar'), '/en/foo/bar');
};
_proto['@test NoneLocation.getURL() returns the current path minus rootURL'] = function testNoneLocationGetURLReturnsTheCurrentPathMinusRootURL(assert) {
NoneTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'rootURL', '/foo/');
(0, _metal.set)(this, 'path', '/foo/bar');
}
});
createLocation();
assert.equal(location.getURL(), '/bar');
};
_proto['@test NoneLocation.getURL() will remove the rootURL only from the beginning of a url'] = function testNoneLocationGetURLWillRemoveTheRootURLOnlyFromTheBeginningOfAUrl(assert) {
NoneTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'rootURL', '/bar/');
(0, _metal.set)(this, 'path', '/foo/bar/baz');
}
});
createLocation();
assert.equal(location.getURL(), '/foo/bar/baz');
};
_proto['@test NoneLocation.getURL() will not remove the rootURL when only a partial match'] = function testNoneLocationGetURLWillNotRemoveTheRootURLWhenOnlyAPartialMatch(assert) {
NoneTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'rootURL', '/bar/');
(0, _metal.set)(this, 'path', '/bars/baz');
}
});
createLocation();
assert.equal(location.getURL(), '/bars/baz');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/routing/tests/location/util_test", ["ember-babel", "@ember/polyfills", "@ember/-internals/routing/lib/location/util", "internal-test-helpers"], function (_emberBabel, _polyfills, _util, _internalTestHelpers) {
"use strict";
function mockBrowserLocation(overrides, assert) {
return (0, _polyfills.assign)({
href: 'http://test.com/',
pathname: '/',
hash: '',
search: '',
replace: function () {
assert.ok(false, 'location.replace should not be called during testing');
}
}, overrides);
}
(0, _internalTestHelpers.moduleFor)('Location Utilities',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test replacePath cannot be used to redirect to a different origin'] = function testReplacePathCannotBeUsedToRedirectToADifferentOrigin(assert) {
assert.expect(1);
var expectedURL;
var location = {
protocol: 'http:',
hostname: 'emberjs.com',
port: '1337',
replace: function (url) {
assert.equal(url, expectedURL);
}
};
expectedURL = 'http://emberjs.com:1337//google.com';
(0, _util.replacePath)(location, '//google.com');
};
_proto['@test getPath() should normalize location.pathname, making sure it always returns a leading slash'] = function testGetPathShouldNormalizeLocationPathnameMakingSureItAlwaysReturnsALeadingSlash(assert) {
var location = mockBrowserLocation({
pathname: 'test'
}, assert);
assert.equal((0, _util.getPath)(location), '/test', 'When there is no leading slash, one is added.');
location = mockBrowserLocation({
pathname: '/test'
}, assert);
assert.equal((0, _util.getPath)(location), '/test', "When a leading slash is already there, it isn't added again");
};
_proto['@test getQuery() should return location.search as-is'] = function testGetQueryShouldReturnLocationSearchAsIs(assert) {
var location = mockBrowserLocation({
search: '?foo=bar'
}, assert);
assert.equal((0, _util.getQuery)(location), '?foo=bar');
};
_proto['@test getFullPath() should return full pathname including query and hash'] = function testGetFullPathShouldReturnFullPathnameIncludingQueryAndHash(assert) {
var location = mockBrowserLocation({
href: 'http://test.com/about?foo=bar#foo',
pathname: '/about',
search: '?foo=bar',
hash: '#foo'
}, assert);
assert.equal((0, _util.getFullPath)(location), '/about?foo=bar#foo');
};
_proto['@test Feature-Detecting onhashchange'] = function testFeatureDetectingOnhashchange(assert) {
assert.equal((0, _util.supportsHashChange)(undefined, {
onhashchange: function () {}
}), true, 'When not in IE, use onhashchange existence as evidence of the feature');
assert.equal((0, _util.supportsHashChange)(undefined, {}), false, 'When not in IE, use onhashchange absence as evidence of the feature absence');
assert.equal((0, _util.supportsHashChange)(7, {
onhashchange: function () {}
}), false, 'When in IE7 compatibility mode, never report existence of the feature');
assert.equal((0, _util.supportsHashChange)(8, {
onhashchange: function () {}
}), true, 'When in IE8+, use onhashchange existence as evidence of the feature');
};
_proto['@test Feature-detecting the history API'] = function testFeatureDetectingTheHistoryAPI(assert) {
assert.equal((0, _util.supportsHistory)('', {
pushState: true
}), true, 'returns true if not Android Gingerbread and history.pushState exists');
assert.equal((0, _util.supportsHistory)('', {}), false, "returns false if history.pushState doesn't exist");
assert.equal((0, _util.supportsHistory)('', undefined), false, "returns false if history doesn't exist");
assert.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');
assert.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');
assert.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');
assert.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
assert.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');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/routing/tests/system/cache_test", ["ember-babel", "@ember/-internals/routing/lib/system/cache", "internal-test-helpers"], function (_emberBabel, _cache, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('BucketCache',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
var _this;
_this = _AbstractTestCase.call(this) || this;
_this.cache = new _cache.default();
return _this;
}
var _proto = _class.prototype;
_proto['@test has - returns false when bucket is not in cache'] = function testHasReturnsFalseWhenBucketIsNotInCache(assert) {
assert.strictEqual(this.cache.has('foo'), false);
assert.strictEqual(this.cache.has('constructor'), false);
};
_proto['@test has - returns true when bucket is in cache'] = function testHasReturnsTrueWhenBucketIsInCache(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);
};
_proto['@test lookup - returns stashed value if key does exist in bucket'] = function testLookupReturnsStashedValueIfKeyDoesExistInBucket(assert) {
var token = {};
var defaultValue = {};
this.cache.stash('foo', 'bar', token);
assert.strictEqual(this.cache.lookup('foo', 'bar', defaultValue), token);
};
_proto['@test lookup - returns default value if key does not exist in bucket'] = function testLookupReturnsDefaultValueIfKeyDoesNotExistInBucket(assert) {
var token = {};
var defaultValue = {};
this.cache.stash('foo', 'bar', token);
assert.strictEqual(this.cache.lookup('foo', 'boo', defaultValue), defaultValue);
assert.strictEqual(this.cache.lookup('foo', 'constructor', defaultValue), defaultValue);
};
_proto['@test lookup - returns default value if bucket does not exist'] = function testLookupReturnsDefaultValueIfBucketDoesNotExist(assert) {
var defaultValue = {};
assert.strictEqual(this.cache.lookup('boo', 'bar', defaultValue), defaultValue);
assert.strictEqual(this.cache.lookup('constructor', 'bar', defaultValue), defaultValue);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/routing/tests/system/controller_for_test", ["ember-babel", "@ember/controller", "@ember/-internals/routing/lib/system/controller_for", "@ember/-internals/routing/lib/system/generate_controller", "internal-test-helpers", "@ember/debug"], function (_emberBabel, _controller, _controller_for, _generate_controller, _internalTestHelpers, _debug) {
"use strict";
var originalDebug = (0, _debug.getDebugFunction)('debug');
var noop = function () {};
(0, _internalTestHelpers.moduleFor)('controllerFor',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
(0, _debug.setDebugFunction)('debug', noop);
return _ApplicationTestCase.call(this) || this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
(0, _debug.setDebugFunction)('debug', originalDebug);
};
_proto['@test controllerFor should lookup for registered controllers'] = function testControllerForShouldLookupForRegisteredControllers(assert) {
var _this = this;
this.add('controller:app', _controller.default.extend());
return this.visit('/').then(function () {
var appInstance = _this.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)('generateController',
/*#__PURE__*/
function (_ApplicationTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _ApplicationTestCase2);
function _class2() {
(0, _debug.setDebugFunction)('debug', noop);
return _ApplicationTestCase2.call(this) || this;
}
var _proto2 = _class2.prototype;
_proto2.teardown = function teardown() {
(0, _debug.setDebugFunction)('debug', originalDebug);
};
_proto2['@test generateController should return Controller'] = function testGenerateControllerShouldReturnController(assert) {
var _this2 = this;
return this.visit('/').then(function () {
var controller = (0, _generate_controller.default)(_this2.applicationInstance, 'home');
assert.ok(controller instanceof _controller.default, 'should return controller');
});
};
_proto2['@test generateController should return controller:basic if resolved'] = function testGenerateControllerShouldReturnControllerBasicIfResolved(assert) {
var _this3 = this;
var BasicController = _controller.default.extend();
this.add('controller:basic', BasicController);
return this.visit('/').then(function () {
var controller = (0, _generate_controller.default)(_this3.applicationInstance, 'home');
assert.ok(controller instanceof BasicController, 'should return controller');
});
};
_proto2['@test generateController should return controller:basic if registered'] = function testGenerateControllerShouldReturnControllerBasicIfRegistered(assert) {
var _this4 = this;
var BasicController = _controller.default.extend();
this.application.register('controller:basic', BasicController);
return this.visit('/').then(function () {
var controller = (0, _generate_controller.default)(_this4.applicationInstance, 'home');
assert.ok(controller instanceof BasicController, 'should return base class of controller');
});
};
return _class2;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("@ember/-internals/routing/tests/system/dsl_test", ["ember-babel", "@ember/-internals/owner", "@ember/-internals/routing/lib/system/router", "internal-test-helpers"], function (_emberBabel, _owner, _router, _internalTestHelpers) {
"use strict";
var Router;
(0, _internalTestHelpers.moduleFor)('Ember Router DSL',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
var _this;
_this = _AbstractTestCase.call(this) || this;
Router = _router.default.extend();
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
Router = null;
};
_proto['@test should fail when using a reserved route name'] = function testShouldFailWhenUsingAReservedRouteName(assert) {
var reservedNames = ['basic', 'application'];
assert.expect(reservedNames.length);
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.");
});
};
_proto['@test [GH#16642] better error when using a colon in a route name'] = function testGH16642BetterErrorWhenUsingAColonInARouteName() {
expectAssertion(function () {
Router = _router.default.extend();
Router.map(function () {
this.route('resource/:id');
});
var router = Router.create();
router._initRouterJs();
}, "'resource/:id' is not a valid route name. It cannot contain a ':'. You may want to use the 'path' option instead.");
};
_proto['@test should retain resource namespace if nested with routes'] = function testShouldRetainResourceNamespaceIfNestedWithRoutes(assert) {
Router = Router.map(function () {
this.route('bleep', function () {
this.route('bloop', function () {
this.route('blork');
});
});
});
var router = Router.create();
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.blork'], 'parent name was used as base of nested routes');
};
_proto['@test should add loading and error routes if _isRouterMapResult is true'] = function testShouldAddLoadingAndErrorRoutesIf_isRouterMapResultIsTrue(assert) {
Router.map(function () {
this.route('blork');
});
var router = Router.create({
_hasModuleBasedResolver: function () {
return true;
}
});
router._initRouterJs();
assert.ok(router._routerMicrolib.recognizer.names['blork'], 'main route was created');
assert.ok(router._routerMicrolib.recognizer.names['blork_loading'], 'loading route was added');
assert.ok(router._routerMicrolib.recognizer.names['blork_error'], 'error route was added');
};
_proto['@test should not add loading and error routes if _isRouterMapResult is false'] = function testShouldNotAddLoadingAndErrorRoutesIf_isRouterMapResultIsFalse(assert) {
Router.map(function () {
this.route('blork');
});
var router = Router.create();
router._initRouterJs(false);
assert.ok(router._routerMicrolib.recognizer.names['blork'], 'main route was created');
assert.ok(!router._routerMicrolib.recognizer.names['blork_loading'], 'loading route was not added');
assert.ok(!router._routerMicrolib.recognizer.names['blork_error'], 'error route was not added');
};
_proto['@test should reset namespace of loading and error routes for routes with resetNamespace'] = function testShouldResetNamespaceOfLoadingAndErrorRoutesForRoutesWithResetNamespace(assert) {
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();
assert.ok(router._routerMicrolib.recognizer.names['blork.blorp'], 'nested route was created');
assert.ok(router._routerMicrolib.recognizer.names['blork.blorp_loading'], 'nested loading route was added');
assert.ok(router._routerMicrolib.recognizer.names['blork.blorp_error'], 'nested error route was added');
assert.ok(router._routerMicrolib.recognizer.names['bleep'], 'reset route was created');
assert.ok(router._routerMicrolib.recognizer.names['bleep_loading'], 'reset loading route was added');
assert.ok(router._routerMicrolib.recognizer.names['bleep_error'], 'reset error route was added');
assert.ok(!router._routerMicrolib.recognizer.names['blork.bleep'], 'nested reset route was not created');
assert.ok(!router._routerMicrolib.recognizer.names['blork.bleep_loading'], 'nested reset loading route was not added');
assert.ok(!router._routerMicrolib.recognizer.names['blork.bleep_error'], 'nested reset error route was not added');
};
_proto['@test should throw an error when defining a route serializer outside an engine'] = function testShouldThrowAnErrorWhenDefiningARouteSerializerOutsideAnEngine(assert) {
Router.map(function () {
var _this2 = this;
assert.throws(function () {
_this2.route('posts', {
serialize: function () {}
});
}, /Defining a route serializer on route 'posts' outside an Engine is not allowed/);
});
Router.create()._initRouterJs();
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Ember Router DSL with engines',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
var _this3;
_this3 = _AbstractTestCase2.call(this) || this;
Router = _router.default.extend();
return _this3;
}
var _proto2 = _class2.prototype;
_proto2.teardown = function teardown() {
Router = null;
};
_proto2['@test should allow mounting of engines'] = function testShouldAllowMountingOfEngines(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, _owner.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');
};
_proto2['@test should allow mounting of engines at a custom path'] = function testShouldAllowMountingOfEnginesAtACustomPath(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, _owner.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');
};
_proto2['@test should allow aliasing of engine names with `as`'] = function testShouldAllowAliasingOfEngineNamesWithAs(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, _owner.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');
};
_proto2['@test should add loading and error routes to a mount if _isRouterMapResult is true'] = function testShouldAddLoadingAndErrorRoutesToAMountIf_isRouterMapResultIsTrue(assert) {
Router.map(function () {
this.mount('chat');
});
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true
}
});
var router = Router.create({
_hasModuleBasedResolver: function () {
return true;
}
});
(0, _owner.setOwner)(router, engineInstance);
router._initRouterJs();
assert.ok(router._routerMicrolib.recognizer.names['chat'], 'main route was created');
assert.ok(router._routerMicrolib.recognizer.names['chat_loading'], 'loading route was added');
assert.ok(router._routerMicrolib.recognizer.names['chat_error'], 'error route was added');
};
_proto2['@test should add loading and error routes to a mount alias if _isRouterMapResult is true'] = function testShouldAddLoadingAndErrorRoutesToAMountAliasIf_isRouterMapResultIsTrue(assert) {
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, _owner.setOwner)(router, engineInstance);
router._initRouterJs();
assert.ok(router._routerMicrolib.recognizer.names['shoutbox'], 'main route was created');
assert.ok(router._routerMicrolib.recognizer.names['shoutbox_loading'], 'loading route was added');
assert.ok(router._routerMicrolib.recognizer.names['shoutbox_error'], 'error route was added');
};
_proto2['@test should not add loading and error routes to a mount if _isRouterMapResult is false'] = function testShouldNotAddLoadingAndErrorRoutesToAMountIf_isRouterMapResultIsFalse(assert) {
Router.map(function () {
this.mount('chat');
});
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true
}
});
var router = Router.create();
(0, _owner.setOwner)(router, engineInstance);
router._initRouterJs(false);
assert.ok(router._routerMicrolib.recognizer.names['chat'], 'main route was created');
assert.ok(!router._routerMicrolib.recognizer.names['chat_loading'], 'loading route was not added');
assert.ok(!router._routerMicrolib.recognizer.names['chat_error'], 'error route was not added');
};
_proto2['@test should reset namespace of loading and error routes for mounts with resetNamespace'] = function testShouldResetNamespaceOfLoadingAndErrorRoutesForMountsWithResetNamespace(assert) {
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, _owner.setOwner)(router, engineInstance);
router._initRouterJs();
assert.ok(router._routerMicrolib.recognizer.names['news.chat'], 'nested route was created');
assert.ok(router._routerMicrolib.recognizer.names['news.chat_loading'], 'nested loading route was added');
assert.ok(router._routerMicrolib.recognizer.names['news.chat_error'], 'nested error route was added');
assert.ok(router._routerMicrolib.recognizer.names['blog'], 'reset route was created');
assert.ok(router._routerMicrolib.recognizer.names['blog_loading'], 'reset loading route was added');
assert.ok(router._routerMicrolib.recognizer.names['blog_error'], 'reset error route was added');
assert.ok(!router._routerMicrolib.recognizer.names['news.blog'], 'nested reset route was not created');
assert.ok(!router._routerMicrolib.recognizer.names['news.blog_loading'], 'nested reset loading route was not added');
assert.ok(!router._routerMicrolib.recognizer.names['news.blog_error'], 'nested reset error route was not added');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/routing/tests/system/route_test", ["ember-babel", "@ember/-internals/owner", "internal-test-helpers", "@ember/service", "@ember/-internals/runtime", "@ember/-internals/routing/lib/system/route"], function (_emberBabel, _owner, _internalTestHelpers, _service, _runtime, _route) {
"use strict";
var route, routeOne, routeTwo, lookupHash;
(0, _internalTestHelpers.moduleFor)('Route',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
var _this;
_this = _AbstractTestCase.call(this) || this;
route = _route.default.create();
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_AbstractTestCase.prototype.teardown.call(this);
(0, _internalTestHelpers.runDestroy)(route);
route = routeOne = routeTwo = lookupHash = undefined;
};
_proto['@test default store utilizes the container to acquire the model factory'] = function testDefaultStoreUtilizesTheContainerToAcquireTheModelFactory(assert) {
assert.expect(4);
var Post = _runtime.Object.extend();
var post = {};
Post.reopenClass({
find: function () {
return post;
}
});
var ownerOptions = {
ownerOptions: {
hasRegistration: function () {
return true;
},
factoryFor: function (fullName) {
assert.equal(fullName, 'model:post', 'correct factory was looked up');
return {
class: Post,
create: function () {
return Post.create();
}
};
}
}
};
var owner = (0, _internalTestHelpers.buildOwner)(ownerOptions);
(0, _owner.setOwner)(route, owner);
route.set('_qp', null);
assert.equal(route.model({
post_id: 1
}), post);
assert.equal(route.findModel('post', 1), post, '#findModel returns the correct post');
(0, _internalTestHelpers.runDestroy)(owner);
};
_proto["@test 'store' can be injected by data persistence frameworks"] = function testStoreCanBeInjectedByDataPersistenceFrameworks(assert) {
assert.expect(8);
(0, _internalTestHelpers.runDestroy)(route);
var owner = (0, _internalTestHelpers.buildOwner)();
var post = {
id: 1
};
var Store = _runtime.Object.extend({
find: function (type, value) {
assert.ok(true, 'injected model was called');
assert.equal(type, 'post', 'correct type was called');
assert.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');
assert.equal(route.model({
post_id: 1
}), post, '#model returns the correct post');
assert.equal(route.findModel('post', 1), post, '#findModel returns the correct post');
(0, _internalTestHelpers.runDestroy)(owner);
};
_proto["@test assert if 'store.find' method is not found"] = function testAssertIfStoreFindMethodIsNotFound() {
(0, _internalTestHelpers.runDestroy)(route);
var owner = (0, _internalTestHelpers.buildOwner)();
var Post = _runtime.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`.');
(0, _internalTestHelpers.runDestroy)(owner);
};
_proto['@test asserts if model class is not found'] = function testAssertsIfModelClassIsNotFound() {
(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./);
(0, _internalTestHelpers.runDestroy)(owner);
};
_proto["@test 'store' does not need to be injected"] = function testStoreDoesNotNeedToBeInjected(assert) {
(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
});
});
assert.ok(true, 'no error was raised');
(0, _internalTestHelpers.runDestroy)(owner);
};
_proto["@test modelFor doesn't require the router"] = function testModelForDoesnTRequireTheRouter(assert) {
var owner = (0, _internalTestHelpers.buildOwner)();
(0, _owner.setOwner)(route, owner);
var foo = {
name: 'foo'
};
var FooRoute = _route.default.extend({
currentModel: foo
});
owner.register('route:foo', FooRoute);
assert.strictEqual(route.modelFor('foo'), foo);
(0, _internalTestHelpers.runDestroy)(owner);
};
_proto["@test modelFor doesn't require the routerMicrolib"] = function testModelForDoesnTRequireTheRouterMicrolib(assert) {
var route = _route.default.create({
_router: {
_routerMicrolib: null
}
});
var owner = (0, _internalTestHelpers.buildOwner)();
(0, _owner.setOwner)(route, owner);
var foo = {
name: 'foo'
};
var FooRoute = _route.default.extend({
currentModel: foo
});
owner.register('route:foo', FooRoute);
assert.strictEqual(route.modelFor('foo'), foo);
(0, _internalTestHelpers.runDestroy)(owner);
};
_proto['@test .send just calls an action if the router is absent'] = function testSendJustCallsAnActionIfTheRouterIsAbsent(assert) {
assert.expect(7);
var route = _route.default.extend({
actions: {
returnsTrue: function (foo, bar) {
assert.equal(foo, 1);
assert.equal(bar, 2);
assert.equal(this, route);
return true;
},
returnsFalse: function () {
assert.ok(true, 'returnsFalse was called');
return false;
}
}
}).create();
assert.equal(route.send('returnsTrue', 1, 2), true);
assert.equal(route.send('returnsFalse'), false);
assert.equal(route.send('nonexistent', 1, 2, 3), undefined);
(0, _internalTestHelpers.runDestroy)(route);
};
_proto['@test .send just calls an action if the routers internal router property is absent'] = function testSendJustCallsAnActionIfTheRoutersInternalRouterPropertyIsAbsent(assert) {
assert.expect(7);
var route = _route.default.extend({
router: {},
actions: {
returnsTrue: function (foo, bar) {
assert.equal(foo, 1);
assert.equal(bar, 2);
assert.equal(this, route);
return true;
},
returnsFalse: function () {
assert.ok(true, 'returnsFalse was called');
return false;
}
}
}).create();
assert.equal(true, route.send('returnsTrue', 1, 2));
assert.equal(false, route.send('returnsFalse'));
assert.equal(undefined, route.send('nonexistent', 1, 2, 3));
(0, _internalTestHelpers.runDestroy)(route);
};
_proto['@test .send asserts if called on a destroyed route'] = function testSendAssertsIfCalledOnADestroyedRoute() {
route.routeName = 'rip-alley';
(0, _internalTestHelpers.runDestroy)(route);
expectAssertion(function () {
route.send('trigger-me-dead');
}, "Attempted to call .send() with the action 'trigger-me-dead' on the destroyed route 'rip-alley'.");
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Route serialize',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
var _this2;
_this2 = _AbstractTestCase2.call(this) || this;
route = _route.default.create();
return _this2;
}
var _proto2 = _class2.prototype;
_proto2.teardown = function teardown() {
(0, _internalTestHelpers.runDestroy)(route);
};
_proto2['@test returns the models properties if params does not include *_id'] = function testReturnsTheModelsPropertiesIfParamsDoesNotInclude_id(assert) {
var model = {
id: 2,
firstName: 'Ned',
lastName: 'Ryerson'
};
assert.deepEqual(route.serialize(model, ['firstName', 'lastName']), {
firstName: 'Ned',
lastName: 'Ryerson'
}, 'serialized correctly');
};
_proto2['@test returns model.id if params include *_id'] = function testReturnsModelIdIfParamsInclude_id(assert) {
var model = {
id: 2
};
assert.deepEqual(route.serialize(model, ['post_id']), {
post_id: 2
}, 'serialized correctly');
};
_proto2['@test returns checks for existence of model.post_id before trying model.id'] = function testReturnsChecksForExistenceOfModelPost_idBeforeTryingModelId(assert) {
var model = {
post_id: 3
};
assert.deepEqual(route.serialize(model, ['post_id']), {
post_id: 3
}, 'serialized correctly');
};
_proto2['@test returns undefined if model is not set'] = function testReturnsUndefinedIfModelIsNotSet(assert) {
assert.equal(route.serialize(undefined, ['post_id']), undefined, 'serialized correctly');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Route interaction',
/*#__PURE__*/
function (_AbstractTestCase3) {
(0, _emberBabel.inheritsLoose)(_class3, _AbstractTestCase3);
function _class3() {
var _this3;
_this3 = _AbstractTestCase3.call(this) || this;
var owner = {
lookup: function (fullName) {
return lookupHash[fullName];
}
};
routeOne = _route.default.create({
routeName: 'one'
});
routeTwo = _route.default.create({
routeName: 'two'
});
(0, _owner.setOwner)(routeOne, owner);
(0, _owner.setOwner)(routeTwo, owner);
lookupHash = {
'route:one': routeOne,
'route:two': routeTwo
};
return _this3;
}
var _proto3 = _class3.prototype;
_proto3.teardown = function teardown() {
(0, _internalTestHelpers.runDestroy)(routeOne);
(0, _internalTestHelpers.runDestroy)(routeTwo);
};
_proto3['@test route._qp does not crash if the controller has no QP, or setProperties'] = function testRoute_qpDoesNotCrashIfTheControllerHasNoQPOrSetProperties(assert) {
lookupHash['controller:test'] = {};
routeOne.controllerName = 'test';
var qp = routeOne.get('_qp');
assert.deepEqual(qp.map, {}, 'map should be empty');
assert.deepEqual(qp.propertyNames, [], 'property names should be empty');
assert.deepEqual(qp.qps, [], 'qps is should be empty');
};
_proto3["@test controllerFor uses route's controllerName if specified"] = function testControllerForUsesRouteSControllerNameIfSpecified(assert) {
var testController = {};
lookupHash['controller:test'] = testController;
routeOne.controllerName = 'test';
assert.equal(routeTwo.controllerFor('one'), testController);
};
return _class3;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Route injected properties',
/*#__PURE__*/
function (_AbstractTestCase4) {
(0, _emberBabel.inheritsLoose)(_class4, _AbstractTestCase4);
function _class4() {
return _AbstractTestCase4.apply(this, arguments) || this;
}
var _proto4 = _class4.prototype;
_proto4['@test services can be injected into routes'] = function testServicesCanBeInjectedIntoRoutes(assert) {
var owner = (0, _internalTestHelpers.buildOwner)();
owner.register('route:application', _route.default.extend({
authService: (0, _service.inject)('auth')
}));
owner.register('service:auth', _service.default.extend());
var appRoute = owner.lookup('route:application');
var authService = owner.lookup('service:auth');
assert.equal(authService, appRoute.get('authService'), 'service.auth is injected');
};
return _class4;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Route with engines',
/*#__PURE__*/
function (_AbstractTestCase5) {
(0, _emberBabel.inheritsLoose)(_class5, _AbstractTestCase5);
function _class5() {
return _AbstractTestCase5.apply(this, arguments) || this;
}
var _proto5 = _class5.prototype;
_proto5["@test paramsFor considers an engine's mountPoint"] = function testParamsForConsidersAnEngineSMountPoint(assert) {
var router = {
_deserializeQueryParams: function () {},
_routerMicrolib: {
state: {
routeInfos: [{
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, _owner.setOwner)(applicationRoute, engineInstance);
(0, _owner.setOwner)(postsRoute, engineInstance);
(0, _owner.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');
};
_proto5["@test modelFor considers an engine's mountPoint"] = function testModelForConsidersAnEngineSMountPoint(assert) {
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, _owner.setOwner)(applicationRoute, engineInstance);
(0, _owner.setOwner)(postsRoute, engineInstance);
(0, _owner.setOwner)(route, engineInstance);
assert.strictEqual(route.modelFor('application'), applicationModel);
assert.strictEqual(route.modelFor('posts'), postsModel);
};
_proto5["@test transitionTo considers an engine's mountPoint"] = function testTransitionToConsidersAnEngineSMountPoint(assert) {
var router = {
transitionTo: function (route) {
return route;
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var route = _route.default.create({
_router: router
});
(0, _owner.setOwner)(route, engineInstance);
assert.strictEqual(route.transitionTo('application'), 'foo.bar.application', 'properly prefixes application route');
assert.strictEqual(route.transitionTo('posts'), 'foo.bar.posts', 'properly prefixes child routes');
assert.throws(function () {
return route.transitionTo('/posts');
}, 'throws when trying to use a url');
var queryParams = {};
assert.strictEqual(route.transitionTo(queryParams), queryParams, 'passes query param only transitions through');
};
_proto5["@test intermediateTransitionTo considers an engine's mountPoint"] = function testIntermediateTransitionToConsidersAnEngineSMountPoint(assert) {
var lastRoute;
var router = {
intermediateTransitionTo: function (route) {
lastRoute = route;
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var route = _route.default.create({
_router: router
});
(0, _owner.setOwner)(route, engineInstance);
route.intermediateTransitionTo('application');
assert.strictEqual(lastRoute, 'foo.bar.application', 'properly prefixes application route');
route.intermediateTransitionTo('posts');
assert.strictEqual(lastRoute, 'foo.bar.posts', 'properly prefixes child routes');
assert.throws(function () {
return route.intermediateTransitionTo('/posts');
}, 'throws when trying to use a url');
var queryParams = {};
route.intermediateTransitionTo(queryParams);
assert.strictEqual(lastRoute, queryParams, 'passes query param only transitions through');
};
_proto5["@test replaceWith considers an engine's mountPoint"] = function testReplaceWithConsidersAnEngineSMountPoint(assert) {
var router = {
replaceWith: function (route) {
return route;
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var route = _route.default.create({
_router: router
});
(0, _owner.setOwner)(route, engineInstance);
assert.strictEqual(route.replaceWith('application'), 'foo.bar.application', 'properly prefixes application route');
assert.strictEqual(route.replaceWith('posts'), 'foo.bar.posts', 'properly prefixes child routes');
assert.throws(function () {
return route.replaceWith('/posts');
}, 'throws when trying to use a url');
var queryParams = {};
assert.strictEqual(route.replaceWith(queryParams), queryParams, 'passes query param only transitions through');
};
return _class5;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/routing/tests/system/router_test", ["ember-babel", "@ember/-internals/owner", "@ember/-internals/routing/lib/location/hash_location", "@ember/-internals/routing/lib/location/history_location", "@ember/-internals/routing/lib/location/auto_location", "@ember/-internals/routing/lib/location/none_location", "@ember/-internals/routing/lib/system/router", "internal-test-helpers"], function (_emberBabel, _owner, _hash_location, _history_location, _auto_location, _none_location, _router, _internalTestHelpers) {
"use strict";
var owner;
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, _owner.setOwner)(router, owner);
}
if (!options.disableSetup) {
router.setupRouter();
}
return router;
}
(0, _internalTestHelpers.moduleFor)('Ember Router',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
var _this;
_this = _AbstractTestCase.call(this) || this;
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);
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
(0, _internalTestHelpers.runDestroy)(owner);
owner = null;
};
_proto['@test can create a router without an owner'] = function testCanCreateARouterWithoutAnOwner(assert) {
createRouter(undefined, {
disableSetup: true,
skipOwner: true
});
assert.ok(true, 'no errors were thrown when creating without a container');
};
_proto['@test [GH#15237] EmberError is imported correctly'] = function testGH15237EmberErrorIsImportedCorrectly(assert) {
// If we get the right message it means Error is being imported correctly.
assert.throws(function () {
(0, _router.triggerEvent)(null, false, []);
}, /because your app hasn't finished transitioning/);
};
_proto['@test should not create a router.js instance upon init'] = function testShouldNotCreateARouterJsInstanceUponInit(assert) {
var router = createRouter(undefined, {
disableSetup: true
});
assert.ok(!router._routerMicrolib);
};
_proto['@test should not reify location until setupRouter is called'] = function testShouldNotReifyLocationUntilSetupRouterIsCalled(assert) {
var router = createRouter(undefined, {
disableSetup: true
});
assert.equal(typeof router.location, 'string', 'location is specified as a string');
router.setupRouter();
assert.equal(typeof router.location, 'object', 'location is reified into an object');
};
_proto['@test should destroy its location upon destroying the routers owner.'] = function testShouldDestroyItsLocationUponDestroyingTheRoutersOwner(assert) {
var router = createRouter();
var location = router.get('location');
(0, _internalTestHelpers.runDestroy)(owner);
assert.ok(location.isDestroyed, 'location should be destroyed');
};
_proto['@test should instantiate its location with its `rootURL`'] = function testShouldInstantiateItsLocationWithItsRootURL(assert) {
var router = createRouter({
rootURL: '/rootdir/'
});
var location = router.get('location');
assert.equal(location.get('rootURL'), '/rootdir/');
};
_proto['@test replacePath should be called with the right path'] = function testReplacePathShouldBeCalledWithTheRightPath(assert) {
assert.expect(1);
var location = owner.lookup('location:auto');
var browserLocation = {
href: 'http://test.com/rootdir/welcome',
origin: 'http://test.com',
pathname: '/rootdir/welcome',
hash: '',
search: '',
replace: function (url) {
assert.equal(url, 'http://test.com/rootdir/#/welcome');
}
};
location.location = browserLocation;
location.global = {
onhashchange: function () {}
};
location.history = null;
createRouter({
location: 'auto',
rootURL: '/rootdir/'
});
};
_proto['@test Router._routePath should consume identical prefixes'] = function testRouter_routePathShouldConsumeIdenticalPrefixes(assert) {
createRouter();
function routePath() {
var routeInfos = Array.prototype.slice.call(arguments).map(function (s) {
return {
name: s
};
});
routeInfos.unshift({
name: 'ignored'
});
return _router.default._routePath(routeInfos);
}
assert.equal(routePath('foo'), 'foo');
assert.equal(routePath('foo', 'bar', 'baz'), 'foo.bar.baz');
assert.equal(routePath('foo', 'foo.bar'), 'foo.bar');
assert.equal(routePath('foo', 'foo.bar', 'foo.bar.baz'), 'foo.bar.baz');
assert.equal(routePath('foo', 'foo.bar', 'foo.bar.baz.wow'), 'foo.bar.baz.wow');
assert.equal(routePath('foo', 'foo.bar.baz.wow'), 'foo.bar.baz.wow');
assert.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.
assert.equal(routePath('foo.bar.baz', 'foo'), 'foo.bar.baz.foo');
};
_proto['@test Router should cancel routing setup when the Location class says so via cancelRouterSetup'] = function testRouterShouldCancelRoutingSetupWhenTheLocationClassSaysSoViaCancelRouterSetup(assert) {
assert.expect(0);
var router;
var FakeLocation = {
cancelRouterSetup: true,
create: function () {
return this;
}
};
owner.register('location:fake', FakeLocation);
router = createRouter({
location: 'fake',
_setupRouter: function () {
assert.ok(false, '_setupRouter should not be called');
}
});
router.startRouting();
};
_proto["@test AutoLocation should replace the url when it's not in the preferred format"] = function testAutoLocationShouldReplaceTheUrlWhenItSNotInThePreferredFormat(assert) {
assert.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) {
assert.equal(url, 'http://test.com/rootdir/#/welcome');
}
};
location.history = null;
location.global = {
onhashchange: function () {}
};
createRouter({
location: 'auto',
rootURL: '/rootdir/'
});
};
_proto['@test Router#handleURL should remove any #hashes before doing URL transition'] = function testRouterHandleURLShouldRemoveAnyHashesBeforeDoingURLTransition(assert) {
assert.expect(2);
var router = createRouter({
_doURLTransition: function (routerJsMethod, url) {
assert.equal(routerJsMethod, 'handleURL');
assert.equal(url, '/foo/bar?time=morphin');
}
});
router.handleURL('/foo/bar?time=morphin#pink-power-ranger');
};
_proto['@test Router#triggerEvent allows actions to bubble when returning true'] = function testRouterTriggerEventAllowsActionsToBubbleWhenReturningTrue(assert) {
assert.expect(2);
var routeInfos = [{
name: 'application',
route: {
actions: {
loading: function () {
assert.ok(false, 'loading not handled by application route');
}
}
}
}, {
name: 'about',
route: {
actions: {
loading: function () {
assert.ok(true, 'loading handled by about route');
return false;
}
}
}
}, {
name: 'about.me',
route: {
actions: {
loading: function () {
assert.ok(true, 'loading handled by about.me route');
return true;
}
}
}
}];
(0, _router.triggerEvent)(routeInfos, false, ['loading']);
};
_proto['@test Router#triggerEvent ignores handlers that have not loaded yet'] = function testRouterTriggerEventIgnoresHandlersThatHaveNotLoadedYet(assert) {
assert.expect(1);
var routeInfos = [{
name: 'about',
route: {
actions: {
loading: function () {
assert.ok(true, 'loading handled by about route');
}
}
}
}, {
name: 'about.me',
route: undefined
}];
(0, _router.triggerEvent)(routeInfos, false, ['loading']);
};
_proto['@test transitionTo should throw an error when called after owner is destroyed'] = function testTransitionToShouldThrowAnErrorWhenCalledAfterOwnerIsDestroyed() {
var router = createRouter();
(0, _internalTestHelpers.runDestroy)(router);
router.currentRouteName = 'route-a';
expectAssertion(function () {
router.transitionTo('route-b');
}, "A transition was attempted from 'route-a' to 'route-b' but the application instance has already been destroyed.");
expectAssertion(function () {
router.transitionTo('./route-b/1');
}, "A transition was attempted from 'route-a' to './route-b/1' but the application instance has already been destroyed.");
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/routing/tests/utils_test", ["ember-babel", "@ember/-internals/routing/lib/utils", "internal-test-helpers"], function (_emberBabel, _utils, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Routing query parameter utils - normalizeControllerQueryParams',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test converts array style into verbose object style'] = function testConvertsArrayStyleIntoVerboseObjectStyle(assert) {
var paramName = 'foo';
var params = [paramName];
var normalized = (0, _utils.normalizeControllerQueryParams)(params);
assert.ok(normalized[paramName], 'turns the query param name into key');
assert.equal(normalized[paramName].as, null, "includes a blank alias in 'as' key");
assert.equal(normalized[paramName].scope, 'model', 'defaults scope to model');
};
_proto["@test converts object style [{foo: 'an_alias'}]"] = function testConvertsObjectStyleFooAn_alias(assert) {
var paramName = 'foo';
var params = [{
foo: 'an_alias'
}];
var normalized = (0, _utils.normalizeControllerQueryParams)(params);
assert.ok(normalized[paramName], 'retains the query param name as key');
assert.equal(normalized[paramName].as, 'an_alias', "includes the provided alias in 'as' key");
assert.equal(normalized[paramName].scope, 'model', 'defaults scope to model');
};
_proto["@test retains maximally verbose object style [{foo: {as: 'foo'}}]"] = function testRetainsMaximallyVerboseObjectStyleFooAsFoo(assert) {
var paramName = 'foo';
var params = [{
foo: {
as: 'an_alias'
}
}];
var normalized = (0, _utils.normalizeControllerQueryParams)(params);
assert.ok(normalized[paramName], 'retains the query param name as key');
assert.equal(normalized[paramName].as, 'an_alias', "includes the provided alias in 'as' key");
assert.equal(normalized[paramName].scope, 'model', 'defaults scope to model');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/array/any-test", ["ember-babel", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _array, _internalTestHelpers, _array2) {
"use strict";
var AnyTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(AnyTests, _AbstractTestCase);
function AnyTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = AnyTests.prototype;
_proto['@test any should should invoke callback on each item as long as you return false'] = function testAnyShouldShouldInvokeCallbackOnEachItemAsLongAsYouReturnFalse() {
var obj = this.newObject();
var ary = this.toArray(obj);
var found = [];
var result;
result = obj.any(function (i) {
found.push(i);
return false;
});
this.assert.equal(result, false, 'return value of obj.any');
this.assert.deepEqual(found, ary, 'items passed during any() should match');
};
_proto['@test any should stop invoking when you return true'] = function testAnyShouldStopInvokingWhenYouReturnTrue() {
var obj = this.newObject();
var ary = this.toArray(obj);
var cnt = ary.length - 2;
var exp = cnt;
var found = [];
var result;
result = obj.any(function (i) {
found.push(i);
return --cnt <= 0;
});
this.assert.equal(result, true, 'return value of obj.any');
this.assert.equal(found.length, exp, 'should invoke proper number of times');
this.assert.deepEqual(found, ary.slice(0, -2), 'items passed during any() should match');
};
_proto['@test any should return true if any object matches the callback'] = function testAnyShouldReturnTrueIfAnyObjectMatchesTheCallback() {
var obj = (0, _array.A)([0, 1, 2]);
var result;
result = obj.any(function (i) {
return Boolean(i);
});
this.assert.equal(result, true, 'return value of obj.any');
};
_proto['@test any should produce correct results even if the matching element is undefined'] = function testAnyShouldProduceCorrectResultsEvenIfTheMatchingElementIsUndefined(assert) {
var obj = (0, _array.A)([undefined]);
var result;
result = obj.any(function () {
return true;
});
assert.equal(result, true, 'return value of obj.any');
};
return AnyTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array2.runArrayTests)('any', AnyTests);
});
enifed("@ember/-internals/runtime/tests/array/apply-test", ["ember-babel", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _array, _internalTestHelpers) {
"use strict";
var ArrayPrototypeExtensionSelfReferenceTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(ArrayPrototypeExtensionSelfReferenceTests, _AbstractTestCase);
function ArrayPrototypeExtensionSelfReferenceTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = ArrayPrototypeExtensionSelfReferenceTests.prototype;
_proto['@test should not create non-Symbol, enumerable properties that refer to itself'] = function testShouldNotCreateNonSymbolEnumerablePropertiesThatReferToItself() {
// Don't want to pollute Array.prototype so we make a fake / simple prototype
function ThrowAwayArray() {} // Extend our throw-away prototype (like EXTEND_PROTOTYPES.Array would)
_array.NativeArray.apply(ThrowAwayArray.prototype); // Create an instance to test
var obj = new ThrowAwayArray(); // Make sure that no enumerable properties refer back to the object (creating a cyclic structure)
for (var p in obj) {
this.assert.notStrictEqual(obj[p], obj, ("Property \"" + p + "\" is an enumerable part of the prototype\n so must not refer back to the original array.\n Otherwise code that explores all properties,\n such as jQuery.extend and other \"deep cloning\" functions,\n will get stuck in an infinite loop.\n ").replace(/\s+/g, ' '));
}
};
return ArrayPrototypeExtensionSelfReferenceTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _internalTestHelpers.moduleFor)("NativeArray: apply", ArrayPrototypeExtensionSelfReferenceTests);
});
enifed("@ember/-internals/runtime/tests/array/compact-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var CompactTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(CompactTests, _AbstractTestCase);
function CompactTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = CompactTests.prototype;
_proto['@test removes null and undefined values from enumerable'] = function testRemovesNullAndUndefinedValuesFromEnumerable() {
var obj = this.newObject([null, 1, false, '', undefined, 0, null]);
var ary = obj.compact();
this.assert.deepEqual(ary, [1, false, '', 0]);
};
return CompactTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('compact', CompactTests);
});
enifed("@ember/-internals/runtime/tests/array/every-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array", "@ember/-internals/runtime/lib/system/object"], function (_emberBabel, _internalTestHelpers, _array, _object) {
"use strict";
var EveryTest =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(EveryTest, _AbstractTestCase);
function EveryTest() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = EveryTest.prototype;
_proto['@test every should should invoke callback on each item as long as you return true'] = function testEveryShouldShouldInvokeCallbackOnEachItemAsLongAsYouReturnTrue() {
var obj = this.newObject();
var ary = this.toArray(obj);
var found = [];
var result;
result = obj.every(function (i) {
found.push(i);
return true;
});
this.assert.equal(result, true, 'return value of obj.every');
this.assert.deepEqual(found, ary, 'items passed during every() should match');
};
_proto['@test every should stop invoking when you return false'] = function testEveryShouldStopInvokingWhenYouReturnFalse() {
var obj = this.newObject();
var ary = this.toArray(obj);
var cnt = ary.length - 2;
var exp = cnt;
var found = [];
var result;
result = obj.every(function (i) {
found.push(i);
return --cnt > 0;
});
this.assert.equal(result, false, 'return value of obj.every');
this.assert.equal(found.length, exp, 'should invoke proper number of times');
this.assert.deepEqual(found, ary.slice(0, -2), 'items passed during every() should match');
};
return EveryTest;
}(_internalTestHelpers.AbstractTestCase);
var IsEveryTest =
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(IsEveryTest, _AbstractTestCase2);
function IsEveryTest() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = IsEveryTest.prototype;
_proto2['@test should return true of every property matches'] = function testShouldReturnTrueOfEveryPropertyMatches() {
var obj = this.newObject([{
foo: 'foo',
bar: 'BAZ'
}, _object.default.create({
foo: 'foo',
bar: 'bar'
})]);
this.assert.equal(obj.isEvery('foo', 'foo'), true, 'isEvery(foo)');
this.assert.equal(obj.isEvery('bar', 'bar'), false, 'isEvery(bar)');
};
_proto2['@test should return true of every property is true'] = function testShouldReturnTrueOfEveryPropertyIsTrue() {
var obj = this.newObject([{
foo: 'foo',
bar: true
}, _object.default.create({
foo: 'bar',
bar: false
})]); // different values - all eval to true
this.assert.equal(obj.isEvery('foo'), true, 'isEvery(foo)');
this.assert.equal(obj.isEvery('bar'), false, 'isEvery(bar)');
};
_proto2['@test should return true if every property matches null'] = function testShouldReturnTrueIfEveryPropertyMatchesNull() {
var obj = this.newObject([{
foo: null,
bar: 'BAZ'
}, _object.default.create({
foo: null,
bar: null
})]);
this.assert.equal(obj.isEvery('foo', null), true, "isEvery('foo', null)");
this.assert.equal(obj.isEvery('bar', null), false, "isEvery('bar', null)");
};
_proto2['@test should return true if every property is undefined'] = function testShouldReturnTrueIfEveryPropertyIsUndefined() {
var obj = this.newObject([{
foo: undefined,
bar: 'BAZ'
}, _object.default.create({
bar: undefined
})]);
this.assert.equal(obj.isEvery('foo', undefined), true, "isEvery('foo', undefined)");
this.assert.equal(obj.isEvery('bar', undefined), false, "isEvery('bar', undefined)");
};
return IsEveryTest;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('every', EveryTest);
(0, _array.runArrayTests)('isEvery', IsEveryTest);
});
enifed("@ember/-internals/runtime/tests/array/filter-test", ["ember-babel", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _object, _internalTestHelpers, _array) {
"use strict";
var FilterTest =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(FilterTest, _AbstractTestCase);
function FilterTest() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = FilterTest.prototype;
_proto['@test filter should invoke on each item'] = function testFilterShouldInvokeOnEachItem() {
var obj = this.newObject();
var ary = this.toArray(obj);
var cnt = ary.length - 2;
var found = [];
var result; // return true on all but the last two
result = obj.filter(function (i) {
found.push(i);
return --cnt >= 0;
});
this.assert.deepEqual(found, ary, 'should have invoked on each item');
this.assert.deepEqual(result, ary.slice(0, -2), 'filtered array should exclude items');
};
return FilterTest;
}(_internalTestHelpers.AbstractTestCase);
var FilterByTest =
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(FilterByTest, _AbstractTestCase2);
function FilterByTest() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = FilterByTest.prototype;
_proto2['@test should filter based on object'] = function testShouldFilterBasedOnObject() {
var obj, ary;
ary = [{
foo: 'foo',
bar: 'BAZ'
}, _object.default.create({
foo: 'foo',
bar: 'bar'
})];
obj = this.newObject(ary);
this.assert.deepEqual(obj.filterBy('foo', 'foo'), ary, 'filterBy(foo)');
this.assert.deepEqual(obj.filterBy('bar', 'bar'), [ary[1]], 'filterBy(bar)');
};
_proto2['@test should include in result if property is true'] = function testShouldIncludeInResultIfPropertyIsTrue() {
var obj, ary;
ary = [{
foo: 'foo',
bar: true
}, _object.default.create({
foo: 'bar',
bar: false
})];
obj = this.newObject(ary); // different values - all eval to true
this.assert.deepEqual(obj.filterBy('foo'), ary, 'filterBy(foo)');
this.assert.deepEqual(obj.filterBy('bar'), [ary[0]], 'filterBy(bar)');
};
_proto2['@test should filter on second argument if provided'] = function testShouldFilterOnSecondArgumentIfProvided() {
var obj, ary;
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);
this.assert.deepEqual(obj.filterBy('foo', 3), [ary[0], ary[3]], "filterBy('foo', 3)')");
};
_proto2['@test should correctly filter null second argument'] = function testShouldCorrectlyFilterNullSecondArgument() {
var obj, ary;
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);
this.assert.deepEqual(obj.filterBy('foo', null), [ary[1], ary[2]], "filterBy('foo', 3)')");
};
_proto2['@test should not return all objects on undefined second argument'] = function testShouldNotReturnAllObjectsOnUndefinedSecondArgument() {
var obj, ary;
ary = [{
name: 'obj1',
foo: 3
}, _object.default.create({
name: 'obj2',
foo: 2
})];
obj = this.newObject(ary);
this.assert.deepEqual(obj.filterBy('foo', undefined), [], "filterBy('foo', 3)')");
};
_proto2['@test should correctly filter explicit undefined second argument'] = function testShouldCorrectlyFilterExplicitUndefinedSecondArgument() {
var obj, ary;
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);
this.assert.deepEqual(obj.filterBy('foo', undefined), ary.slice(2), "filterBy('foo', 3)')");
};
_proto2['@test should not match undefined properties without second argument'] = function testShouldNotMatchUndefinedPropertiesWithoutSecondArgument() {
var obj, ary;
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);
this.assert.deepEqual(obj.filterBy('foo'), ary.slice(0, 2), "filterBy('foo', 3)')");
};
return FilterByTest;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('filter', FilterTest);
(0, _array.runArrayTests)('filter', FilterByTest);
});
enifed("@ember/-internals/runtime/tests/array/find-test", ["ember-babel", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _object, _internalTestHelpers, _array) {
"use strict";
var FindTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(FindTests, _AbstractTestCase);
function FindTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = FindTests.prototype;
_proto['@test find should invoke callback on each item as long as you return false'] = function testFindShouldInvokeCallbackOnEachItemAsLongAsYouReturnFalse() {
var obj = this.newObject();
var ary = this.toArray(obj);
var found = [];
var result;
result = obj.find(function (i) {
found.push(i);
return false;
});
this.assert.equal(result, undefined, 'return value of obj.find');
this.assert.deepEqual(found, ary, 'items passed during find() should match');
};
_proto['@test every should stop invoking when you return true'] = function testEveryShouldStopInvokingWhenYouReturnTrue() {
var obj = this.newObject();
var ary = this.toArray(obj);
var cnt = ary.length - 2;
var exp = cnt;
var found = [];
var result;
result = obj.find(function (i) {
found.push(i);
return --cnt >= 0;
});
this.assert.equal(result, ary[exp - 1], 'return value of obj.find');
this.assert.equal(found.length, exp, 'should invoke proper number of times');
this.assert.deepEqual(found, ary.slice(0, -2), 'items passed during find() should match');
};
return FindTests;
}(_internalTestHelpers.AbstractTestCase);
var FindByTests =
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(FindByTests, _AbstractTestCase2);
function FindByTests() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = FindByTests.prototype;
_proto2['@test should return first object of property matches'] = function testShouldReturnFirstObjectOfPropertyMatches() {
var ary, obj;
ary = [{
foo: 'foo',
bar: 'BAZ'
}, _object.default.create({
foo: 'foo',
bar: 'bar'
})];
obj = this.newObject(ary);
this.assert.equal(obj.findBy('foo', 'foo'), ary[0], 'findBy(foo)');
this.assert.equal(obj.findBy('bar', 'bar'), ary[1], 'findBy(bar)');
};
_proto2['@test should return first object with truthy prop'] = function testShouldReturnFirstObjectWithTruthyProp() {
var ary, obj;
ary = [{
foo: 'foo',
bar: false
}, _object.default.create({
foo: 'bar',
bar: true
})];
obj = this.newObject(ary); // different values - all eval to true
this.assert.equal(obj.findBy('foo'), ary[0], 'findBy(foo)');
this.assert.equal(obj.findBy('bar'), ary[1], 'findBy(bar)');
};
_proto2['@test should return first null property match'] = function testShouldReturnFirstNullPropertyMatch() {
var ary, obj;
ary = [{
foo: null,
bar: 'BAZ'
}, _object.default.create({
foo: null,
bar: null
})];
obj = this.newObject(ary);
this.assert.equal(obj.findBy('foo', null), ary[0], "findBy('foo', null)");
this.assert.equal(obj.findBy('bar', null), ary[1], "findBy('bar', null)");
};
_proto2['@test should return first undefined property match'] = function testShouldReturnFirstUndefinedPropertyMatch() {
var ary, obj;
ary = [{
foo: undefined,
bar: 'BAZ'
}, _object.default.create({})];
obj = this.newObject(ary);
this.assert.equal(obj.findBy('foo', undefined), ary[0], "findBy('foo', undefined)");
this.assert.equal(obj.findBy('bar', undefined), ary[1], "findBy('bar', undefined)");
};
return FindByTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('find', FindTests);
(0, _array.runArrayTests)('findBy', FindByTests);
});
enifed("@ember/-internals/runtime/tests/array/firstObject-test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _metal, _internalTestHelpers, _array) {
"use strict";
var FirstObjectTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(FirstObjectTests, _AbstractTestCase);
function FirstObjectTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = FirstObjectTests.prototype;
_proto['@test returns first item in enumerable'] = function testReturnsFirstItemInEnumerable() {
var obj = this.newObject();
this.assert.equal((0, _metal.get)(obj, 'firstObject'), this.toArray(obj)[0]);
};
_proto['@test returns undefined if enumerable is empty'] = function testReturnsUndefinedIfEnumerableIsEmpty() {
var obj = this.newObject([]);
this.assert.equal((0, _metal.get)(obj, 'firstObject'), undefined);
};
_proto['@test can not be set'] = function testCanNotBeSet() {
var obj = this.newObject([]);
this.assert.equal((0, _metal.get)(obj, 'firstObject'), this.toArray(obj)[0]);
this.assert.throws(function () {
(0, _metal.set)(obj, 'firstObject', 'foo!');
}, /Cannot set read-only property "firstObject" on object/);
};
return FirstObjectTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('firstObject', FirstObjectTests);
});
enifed("@ember/-internals/runtime/tests/array/forEach-test", ["ember-babel", "@ember/-internals/utils", "@ember/-internals/metal", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _utils, _metal, _internalTestHelpers, _array) {
"use strict";
var ForEachTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(ForEachTests, _AbstractTestCase);
function ForEachTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = ForEachTests.prototype;
_proto['@test forEach should iterate over list'] = function testForEachShouldIterateOverList() {
var obj = this.newObject();
var ary = this.toArray(obj);
var found = [];
obj.forEach(function (i) {
return found.push(i);
});
this.assert.deepEqual(found, ary, 'items passed during forEach should match');
};
_proto['@test forEach should iterate over list after mutation'] = function testForEachShouldIterateOverListAfterMutation() {
if ((0, _metal.get)(this, 'canTestMutation')) {
this.assert.expect(0);
return;
}
var obj = this.newObject();
var ary = this.toArray(obj);
var found = [];
obj.forEach(function (i) {
return found.push(i);
});
this.assert.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);
});
this.assert.deepEqual(found, ary, 'items passed during forEach should match');
};
_proto['@test 2nd target parameter'] = function test2ndTargetParameter() {
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 () {
_this.assert.equal((0, _utils.guidFor)(_this), (0, _utils.guidFor)(target), 'should pass target as this if context');
}, target);
};
_proto['@test callback params'] = function testCallbackParams() {
var _this2 = this;
var obj = this.newObject();
var ary = this.toArray(obj);
var loc = 0;
obj.forEach(function (item, idx, enumerable) {
_this2.assert.equal(item, ary[loc], 'item param');
_this2.assert.equal(idx, loc, 'idx param');
_this2.assert.equal((0, _utils.guidFor)(enumerable), (0, _utils.guidFor)(obj), 'enumerable param');
loc++;
});
};
return ForEachTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('forEach', ForEachTests);
});
enifed("@ember/-internals/runtime/tests/array/includes-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var IncludesTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(IncludesTests, _AbstractTestCase);
function IncludesTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = IncludesTests.prototype;
_proto['@test includes returns correct value if startAt is positive'] = function testIncludesReturnsCorrectValueIfStartAtIsPositive() {
var data = (0, _array.newFixture)(3);
var obj = this.newObject(data);
this.assert.equal(obj.includes(data[1], 1), true, 'should return true if included');
this.assert.equal(obj.includes(data[0], 1), false, 'should return false if not included');
};
_proto['@test includes returns correct value if startAt is negative'] = function testIncludesReturnsCorrectValueIfStartAtIsNegative() {
var data = (0, _array.newFixture)(3);
var obj = this.newObject(data);
this.assert.equal(obj.includes(data[1], -2), true, 'should return true if included');
this.assert.equal(obj.includes(data[0], -2), false, 'should return false if not included');
};
_proto['@test includes returns true if startAt + length is still negative'] = function testIncludesReturnsTrueIfStartAtLengthIsStillNegative() {
var data = (0, _array.newFixture)(1);
var obj = this.newObject(data);
this.assert.equal(obj.includes(data[0], -2), true, 'should return true if included');
this.assert.equal(obj.includes((0, _array.newFixture)(1), -2), false, 'should return false if not included');
};
_proto['@test includes returns false if startAt out of bounds'] = function testIncludesReturnsFalseIfStartAtOutOfBounds() {
var data = (0, _array.newFixture)(1);
var obj = this.newObject(data);
this.assert.equal(obj.includes(data[0], 2), false, 'should return false if startAt >= length');
this.assert.equal(obj.includes((0, _array.newFixture)(1), 2), false, 'should return false if startAt >= length');
};
return IncludesTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('includes', IncludesTests);
});
enifed("@ember/-internals/runtime/tests/array/indexOf-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var IndexOfTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(IndexOfTests, _AbstractTestCase);
function IndexOfTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = IndexOfTests.prototype;
_proto['@test should return index of object'] = function testShouldReturnIndexOfObject() {
var expected = (0, _array.newFixture)(3);
var obj = this.newObject(expected);
var len = 3;
for (var idx = 0; idx < len; idx++) {
this.assert.equal(obj.indexOf(expected[idx]), idx, "obj.indexOf(" + expected[idx] + ") should match idx");
}
};
_proto['@test should return -1 when requesting object not in index'] = function testShouldReturn1WhenRequestingObjectNotInIndex() {
var obj = this.newObject((0, _array.newFixture)(3));
var foo = {};
this.assert.equal(obj.indexOf(foo), -1, 'obj.indexOf(foo) should be < 0');
};
return IndexOfTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('indexOf', IndexOfTests);
});
enifed("@ember/-internals/runtime/tests/array/invoke-test", ["ember-babel", "@ember/-internals/runtime/index", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _index, _internalTestHelpers, _array) {
"use strict";
var InvokeTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(InvokeTests, _AbstractTestCase);
function InvokeTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = InvokeTests.prototype;
_proto['@test invoke should call on each object that implements'] = function testInvokeShouldCallOnEachObjectThatImplements() {
var cnt, ary, obj;
function F(amt) {
cnt += amt === undefined ? 1 : amt;
}
cnt = 0;
ary = [{
foo: F
}, _index.Object.create({
foo: F
}), // NOTE: does not impl foo - invoke should just skip
_index.Object.create({
bar: F
}), {
foo: F
}];
obj = this.newObject(ary);
obj.invoke('foo');
this.assert.equal(cnt, 3, 'should have invoked 3 times');
cnt = 0;
obj.invoke('foo', 2);
this.assert.equal(cnt, 6, 'should have invoked 3 times, passing param');
};
_proto['@test invoke should return an array containing the results of each invoked method'] = function testInvokeShouldReturnAnArrayContainingTheResultsOfEachInvokedMethod(assert) {
var obj = this.newObject([{
foo: function () {
return 'one';
}
}, {}, // intentionally not including `foo` method
{
foo: function () {
return 'two';
}
}]);
var result = obj.invoke('foo');
assert.deepEqual(result, ['one', undefined, 'two']);
};
_proto['@test invoke should return an extended array (aka Ember.A)'] = function testInvokeShouldReturnAnExtendedArrayAkaEmberA(assert) {
var obj = this.newObject([{
foo: function () {}
}, {
foo: function () {}
}]);
var result = obj.invoke('foo');
assert.ok(_index.NativeArray.detect(result), 'NativeArray has been applied');
};
return InvokeTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('invoke', InvokeTests);
});
enifed("@ember/-internals/runtime/tests/array/isAny-test", ["ember-babel", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _object, _internalTestHelpers, _array) {
"use strict";
var IsAnyTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(IsAnyTests, _AbstractTestCase);
function IsAnyTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = IsAnyTests.prototype;
_proto['@test should return true of any property matches'] = function testShouldReturnTrueOfAnyPropertyMatches() {
var obj = this.newObject([{
foo: 'foo',
bar: 'BAZ'
}, _object.default.create({
foo: 'foo',
bar: 'bar'
})]);
this.assert.equal(obj.isAny('foo', 'foo'), true, 'isAny(foo)');
this.assert.equal(obj.isAny('bar', 'bar'), true, 'isAny(bar)');
this.assert.equal(obj.isAny('bar', 'BIFF'), false, 'isAny(BIFF)');
};
_proto['@test should return true of any property is true'] = function testShouldReturnTrueOfAnyPropertyIsTrue() {
var obj = this.newObject([{
foo: 'foo',
bar: true
}, _object.default.create({
foo: 'bar',
bar: false
})]); // different values - all eval to true
this.assert.equal(obj.isAny('foo'), true, 'isAny(foo)');
this.assert.equal(obj.isAny('bar'), true, 'isAny(bar)');
this.assert.equal(obj.isAny('BIFF'), false, 'isAny(biff)');
};
_proto['@test should return true if any property matches null'] = function testShouldReturnTrueIfAnyPropertyMatchesNull() {
var obj = this.newObject([{
foo: null,
bar: 'bar'
}, _object.default.create({
foo: 'foo',
bar: null
})]);
this.assert.equal(obj.isAny('foo', null), true, "isAny('foo', null)");
this.assert.equal(obj.isAny('bar', null), true, "isAny('bar', null)");
};
_proto['@test should return true if any property is undefined'] = function testShouldReturnTrueIfAnyPropertyIsUndefined() {
var obj = this.newObject([{
foo: undefined,
bar: 'bar'
}, _object.default.create({
foo: 'foo'
})]);
this.assert.equal(obj.isAny('foo', undefined), true, "isAny('foo', undefined)");
this.assert.equal(obj.isAny('bar', undefined), true, "isAny('bar', undefined)");
};
_proto['@test should not match undefined properties without second argument'] = function testShouldNotMatchUndefinedPropertiesWithoutSecondArgument() {
var obj = this.newObject([{
foo: undefined
}, _object.default.create({})]);
this.assert.equal(obj.isAny('foo'), false, "isAny('foo', undefined)");
};
return IsAnyTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('isAny', IsAnyTests);
});
enifed("@ember/-internals/runtime/tests/array/lastIndexOf-test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _metal, _internalTestHelpers, _array) {
"use strict";
var LastIndexOfTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(LastIndexOfTests, _AbstractTestCase);
function LastIndexOfTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = LastIndexOfTests.prototype;
_proto["@test should return index of object's last occurrence"] = function testShouldReturnIndexOfObjectSLastOccurrence() {
var expected = (0, _array.newFixture)(3);
var obj = this.newObject(expected);
var len = 3;
for (var idx = 0; idx < len; idx++) {
this.assert.equal(obj.lastIndexOf(expected[idx]), idx, "obj.lastIndexOf(" + expected[idx] + ") should match idx");
}
};
_proto["@test should return index of object's last occurrence even startAt search location is equal to length"] = function testShouldReturnIndexOfObjectSLastOccurrenceEvenStartAtSearchLocationIsEqualToLength() {
var expected = (0, _array.newFixture)(3);
var obj = this.newObject(expected);
var len = 3;
for (var idx = 0; idx < len; idx++) {
this.assert.equal(obj.lastIndexOf(expected[idx], len), idx, "obj.lastIndexOfs(" + expected[idx] + ") should match idx");
}
};
_proto["@test should return index of object's last occurrence even startAt search location is greater than length"] = function testShouldReturnIndexOfObjectSLastOccurrenceEvenStartAtSearchLocationIsGreaterThanLength() {
var expected = (0, _array.newFixture)(3);
var obj = this.newObject(expected);
var len = 3;
for (var idx = 0; idx < len; idx++) {
this.assert.equal(obj.lastIndexOf(expected[idx], len + 1), idx, "obj.lastIndexOf(" + expected[idx] + ") should match idx");
}
};
_proto['@test should return -1 when no match is found'] = function testShouldReturn1WhenNoMatchIsFound() {
var obj = this.newObject((0, _array.newFixture)(3));
var foo = {};
this.assert.equal(obj.lastIndexOf(foo), -1, 'obj.lastIndexOf(foo) should be -1');
};
_proto['@test should return -1 when no match is found even startAt search location is equal to length'] = function testShouldReturn1WhenNoMatchIsFoundEvenStartAtSearchLocationIsEqualToLength() {
var obj = this.newObject((0, _array.newFixture)(3));
var foo = {};
this.assert.equal(obj.lastIndexOf(foo, (0, _metal.get)(obj, 'length')), -1, 'obj.lastIndexOf(foo) should be -1');
};
_proto['@test should return -1 when no match is found even startAt search location is greater than length'] = function testShouldReturn1WhenNoMatchIsFoundEvenStartAtSearchLocationIsGreaterThanLength() {
var obj = this.newObject((0, _array.newFixture)(3));
var foo = {};
this.assert.equal(obj.lastIndexOf(foo, (0, _metal.get)(obj, 'length') + 1), -1, 'obj.lastIndexOf(foo) should be -1');
};
return LastIndexOfTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('lastIndexOf', LastIndexOfTests);
});
enifed("@ember/-internals/runtime/tests/array/lastObject-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _array, _metal) {
"use strict";
var LastObjectTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(LastObjectTests, _AbstractTestCase);
function LastObjectTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = LastObjectTests.prototype;
_proto['@test returns last item in enumerable'] = function testReturnsLastItemInEnumerable() {
var obj = this.newObject();
var ary = this.toArray(obj);
this.assert.equal((0, _metal.get)(obj, 'lastObject'), ary[ary.length - 1]);
};
_proto['@test returns undefined if enumerable is empty'] = function testReturnsUndefinedIfEnumerableIsEmpty() {
var obj = this.newObject([]);
this.assert.equal((0, _metal.get)(obj, 'lastObject'), undefined);
};
_proto['@test can not be set'] = function testCanNotBeSet() {
var obj = this.newObject();
var ary = this.toArray(obj);
this.assert.equal((0, _metal.get)(obj, 'lastObject'), ary[ary.length - 1]);
this.assert.throws(function () {
(0, _metal.set)(obj, 'lastObject', 'foo!');
}, /Cannot set read-only property "lastObject" on object/);
};
return LastObjectTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('lastObject', LastObjectTests);
});
enifed("@ember/-internals/runtime/tests/array/map-test", ["ember-babel", "@ember/-internals/utils", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array", "@ember/-internals/metal"], function (_emberBabel, _utils, _internalTestHelpers, _array, _metal) {
"use strict";
var mapFunc = function (item) {
return item ? item.toString() : null;
};
var MapTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(MapTests, _AbstractTestCase);
function MapTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = MapTests.prototype;
_proto['@test map should iterate over list'] = function testMapShouldIterateOverList() {
var obj = this.newObject();
var ary = this.toArray(obj).map(mapFunc);
var found = [];
found = obj.map(mapFunc);
this.assert.deepEqual(found, ary, 'mapped arrays should match');
};
_proto['@test map should iterate over list after mutation'] = function testMapShouldIterateOverListAfterMutation() {
if ((0, _metal.get)(this, 'canTestMutation')) {
this.assert.expect(0);
return;
}
var obj = this.newObject();
var ary = this.toArray(obj).map(mapFunc);
var found;
found = obj.map(mapFunc);
this.assert.deepEqual(found, ary, 'items passed during forEach should match');
this.mutate(obj);
ary = this.toArray(obj).map(mapFunc);
found = obj.map(mapFunc);
this.assert.deepEqual(found, ary, 'items passed during forEach should match');
};
_proto['@test 2nd target parameter'] = function test2ndTargetParameter() {
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 () {
_this.assert.equal((0, _utils.guidFor)(_this), (0, _utils.guidFor)(target), 'should pass target as this if context');
}, target);
};
_proto['@test callback params'] = function testCallbackParams() {
var _this2 = this;
var obj = this.newObject();
var ary = this.toArray(obj);
var loc = 0;
obj.map(function (item, idx, enumerable) {
_this2.assert.equal(item, ary[loc], 'item param');
_this2.assert.equal(idx, loc, 'idx param');
_this2.assert.equal((0, _utils.guidFor)(enumerable), (0, _utils.guidFor)(obj), 'enumerable param');
loc++;
});
};
return MapTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('map', MapTests);
});
enifed("@ember/-internals/runtime/tests/array/mapBy-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var MapByTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(MapByTests, _AbstractTestCase);
function MapByTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = MapByTests.prototype;
_proto['@test get value of each property'] = function testGetValueOfEachProperty() {
var obj = this.newObject([{
a: 1
}, {
a: 2
}]);
this.assert.equal(obj.mapBy('a').join(''), '12');
};
_proto['@test should work also through getEach alias'] = function testShouldWorkAlsoThroughGetEachAlias() {
var obj = this.newObject([{
a: 1
}, {
a: 2
}]);
this.assert.equal(obj.getEach('a').join(''), '12');
};
return MapByTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('mapBy', MapByTests);
});
enifed("@ember/-internals/runtime/tests/array/objectAt-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var ObjectAtTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(ObjectAtTests, _AbstractTestCase);
function ObjectAtTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = ObjectAtTests.prototype;
_proto['@test should return object at specified index'] = function testShouldReturnObjectAtSpecifiedIndex() {
var expected = (0, _array.newFixture)(3);
var obj = this.newObject(expected);
var len = expected.length;
for (var idx = 0; idx < len; idx++) {
this.assert.equal(obj.objectAt(idx), expected[idx], "obj.objectAt(" + idx + ") should match");
}
};
_proto['@test should return undefined when requesting objects beyond index'] = function testShouldReturnUndefinedWhenRequestingObjectsBeyondIndex() {
var obj;
obj = this.newObject((0, _array.newFixture)(3));
this.assert.equal(obj.objectAt(obj, 5), undefined, 'should return undefined for obj.objectAt(5) when len = 3');
obj = this.newObject([]);
this.assert.equal(obj.objectAt(obj, 0), undefined, 'should return undefined for obj.objectAt(0) when len = 0');
};
return ObjectAtTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('objectAt', ObjectAtTests);
});
enifed("@ember/-internals/runtime/tests/array/reduce-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var ReduceTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(ReduceTests, _AbstractTestCase);
function ReduceTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = ReduceTests.prototype;
_proto['@test collects a summary value from an enumeration'] = function testCollectsASummaryValueFromAnEnumeration() {
var obj = this.newObject([1, 2, 3]);
var res = obj.reduce(function (previousValue, item) {
return previousValue + item;
}, 0);
this.assert.equal(res, 6);
};
_proto['@test passes index of item to callback'] = function testPassesIndexOfItemToCallback() {
var obj = this.newObject([1, 2, 3]);
var res = obj.reduce(function (previousValue, item, index) {
return previousValue + index;
}, 0);
this.assert.equal(res, 3);
};
_proto['@test passes enumerable object to callback'] = function testPassesEnumerableObjectToCallback() {
var obj = this.newObject([1, 2, 3]);
var res = obj.reduce(function (previousValue, item, index, enumerable) {
return enumerable;
}, 0);
this.assert.equal(res, obj);
};
return ReduceTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('reduce', ReduceTests);
});
enifed("@ember/-internals/runtime/tests/array/reject-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array", "@ember/-internals/runtime/lib/system/object"], function (_emberBabel, _internalTestHelpers, _array, _object) {
"use strict";
var RejectTest =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(RejectTest, _AbstractTestCase);
function RejectTest() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = RejectTest.prototype;
_proto['@test should reject any item that does not meet the condition'] = function testShouldRejectAnyItemThatDoesNotMeetTheCondition() {
var obj = this.newObject([1, 2, 3, 4]);
var result;
result = obj.reject(function (i) {
return i < 3;
});
this.assert.deepEqual(result, [3, 4], 'reject the correct items');
};
_proto['@test should be the inverse of filter'] = function testShouldBeTheInverseOfFilter() {
var obj = this.newObject([1, 2, 3, 4]);
var isEven = function (i) {
return i % 2 === 0;
};
var filtered, rejected;
filtered = obj.filter(isEven);
rejected = obj.reject(isEven);
this.assert.deepEqual(filtered, [2, 4], 'filtered evens');
this.assert.deepEqual(rejected, [1, 3], 'rejected evens');
};
return RejectTest;
}(_internalTestHelpers.AbstractTestCase);
var RejectByTest =
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(RejectByTest, _AbstractTestCase2);
function RejectByTest() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = RejectByTest.prototype;
_proto2['@test should reject based on object'] = function testShouldRejectBasedOnObject() {
var obj, ary;
ary = [{
foo: 'foo',
bar: 'BAZ'
}, _object.default.create({
foo: 'foo',
bar: 'bar'
})];
obj = this.newObject(ary);
this.assert.deepEqual(obj.rejectBy('foo', 'foo'), [], 'rejectBy(foo)');
this.assert.deepEqual(obj.rejectBy('bar', 'bar'), [ary[0]], 'rejectBy(bar)');
};
_proto2['@test should include in result if property is false'] = function testShouldIncludeInResultIfPropertyIsFalse() {
var obj, ary;
ary = [{
foo: false,
bar: true
}, _object.default.create({
foo: false,
bar: false
})];
obj = this.newObject(ary);
this.assert.deepEqual(obj.rejectBy('foo'), ary, 'rejectBy(foo)');
this.assert.deepEqual(obj.rejectBy('bar'), [ary[1]], 'rejectBy(bar)');
};
_proto2['@test should reject on second argument if provided'] = function testShouldRejectOnSecondArgumentIfProvided() {
var obj, ary;
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);
this.assert.deepEqual(obj.rejectBy('foo', 3), [ary[1], ary[2]], "rejectBy('foo', 3)')");
};
_proto2['@test should correctly reject null second argument'] = function testShouldCorrectlyRejectNullSecondArgument() {
var obj, ary;
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);
this.assert.deepEqual(obj.rejectBy('foo', null), [ary[0], ary[3]], "rejectBy('foo', null)')");
};
_proto2['@test should correctly reject undefined second argument'] = function testShouldCorrectlyRejectUndefinedSecondArgument() {
var obj, ary;
ary = [{
name: 'obj1',
foo: 3
}, _object.default.create({
name: 'obj2',
foo: 2
})];
obj = this.newObject(ary);
this.assert.deepEqual(obj.rejectBy('bar', undefined), [], "rejectBy('bar', undefined)')");
};
_proto2['@test should correctly reject explicit undefined second argument'] = function testShouldCorrectlyRejectExplicitUndefinedSecondArgument() {
var obj, ary;
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);
this.assert.deepEqual(obj.rejectBy('foo', undefined), ary.slice(0, 2), "rejectBy('foo', undefined)')");
};
_proto2['@test should match undefined, null, or false properties without second argument'] = function testShouldMatchUndefinedNullOrFalsePropertiesWithoutSecondArgument() {
var obj, ary;
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);
this.assert.deepEqual(obj.rejectBy('foo'), ary.slice(2), "rejectBy('foo')')");
};
return RejectByTest;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('reject', RejectTest);
(0, _array.runArrayTests)('rejectBy', RejectByTest);
});
enifed("@ember/-internals/runtime/tests/array/sortBy-test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _metal, _internalTestHelpers, _array) {
"use strict";
var SortByTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(SortByTests, _AbstractTestCase);
function SortByTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = SortByTests.prototype;
_proto['@test sort by value of property'] = function testSortByValueOfProperty() {
var obj = this.newObject([{
a: 2
}, {
a: 1
}]);
var sorted = obj.sortBy('a');
this.assert.equal((0, _metal.get)(sorted[0], 'a'), 1);
this.assert.equal((0, _metal.get)(sorted[1], 'a'), 2);
};
_proto['@test supports multiple propertyNames'] = function testSupportsMultiplePropertyNames() {
var obj = this.newObject([{
a: 1,
b: 2
}, {
a: 1,
b: 1
}]);
var sorted = obj.sortBy('a', 'b');
this.assert.equal((0, _metal.get)(sorted[0], 'b'), 1);
this.assert.equal((0, _metal.get)(sorted[1], 'b'), 2);
};
return SortByTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('sortBy', SortByTests);
});
enifed("@ember/-internals/runtime/tests/array/toArray-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var ToArrayTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(ToArrayTests, _AbstractTestCase);
function ToArrayTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = ToArrayTests.prototype;
_proto['@test toArray should convert to an array'] = function testToArrayShouldConvertToAnArray() {
var obj = this.newObject();
this.assert.deepEqual(obj.toArray(), this.toArray(obj));
};
return ToArrayTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('toArray', ToArrayTests);
});
enifed("@ember/-internals/runtime/tests/array/uniq-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var UniqTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(UniqTests, _AbstractTestCase);
function UniqTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = UniqTests.prototype;
_proto['@test should return new instance with duplicates removed'] = function testShouldReturnNewInstanceWithDuplicatesRemoved() {
var before, after, obj, ret;
after = (0, _array.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();
this.assert.deepEqual(this.toArray(ret), after, 'should have removed item');
this.assert.deepEqual(this.toArray(obj), before, 'should not have changed original');
};
_proto['@test should return duplicate of same content if no duplicates found'] = function testShouldReturnDuplicateOfSameContentIfNoDuplicatesFound() {
var item, obj, ret;
obj = this.newObject((0, _array.newFixture)(3));
ret = obj.uniq(item);
this.assert.ok(ret !== obj, 'should not be same object');
this.assert.deepEqual(this.toArray(ret), this.toArray(obj), 'should be the same content');
};
return UniqTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('uniq', UniqTests);
});
enifed("@ember/-internals/runtime/tests/array/uniqBy-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var UniqByTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(UniqByTests, _AbstractTestCase);
function UniqByTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = UniqByTests.prototype;
_proto['@test should return new instance with duplicates removed'] = function testShouldReturnNewInstanceWithDuplicatesRemoved() {
var numbers = this.newObject([{
id: 1,
value: 'one'
}, {
id: 2,
value: 'two'
}, {
id: 1,
value: 'one'
}]);
this.assert.deepEqual(numbers.uniqBy('id'), [{
id: 1,
value: 'one'
}, {
id: 2,
value: 'two'
}]);
};
_proto['@test supports function as key'] = function testSupportsFunctionAsKey() {
var _this = this,
_arguments = arguments;
var numbers = this.newObject([{
id: 1,
value: 'boom'
}, {
id: 2,
value: 'boom'
}, {
id: 1,
value: 'doom'
}]);
var keyFunction = function (val) {
_this.assert.equal(_arguments.length, 1);
return val.value;
};
this.assert.deepEqual(numbers.uniqBy(keyFunction), [{
id: 1,
value: 'boom'
}, {
id: 1,
value: 'doom'
}]);
};
return UniqByTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('uniqBy', UniqByTests);
});
enifed("@ember/-internals/runtime/tests/array/without-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var WithoutTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(WithoutTests, _AbstractTestCase);
function WithoutTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = WithoutTests.prototype;
_proto['@test should return new instance with item removed'] = function testShouldReturnNewInstanceWithItemRemoved() {
var before, after, obj, ret;
before = (0, _array.newFixture)(3);
after = [before[0], before[2]];
obj = this.newObject(before);
ret = obj.without(before[1]);
this.assert.deepEqual(this.toArray(ret), after, 'should have removed item');
this.assert.deepEqual(this.toArray(obj), before, 'should not have changed original');
};
_proto['@test should remove NaN value'] = function testShouldRemoveNaNValue() {
var before, after, obj, ret;
before = [].concat((0, _array.newFixture)(2), [NaN]);
after = [before[0], before[1]];
obj = this.newObject(before);
ret = obj.without(NaN);
this.assert.deepEqual(this.toArray(ret), after, 'should have removed item');
};
_proto['@test should return same instance if object not found'] = function testShouldReturnSameInstanceIfObjectNotFound() {
var item, obj, ret;
item = (0, _array.newFixture)(1)[0];
obj = this.newObject((0, _array.newFixture)(3));
ret = obj.without(item);
this.assert.equal(ret, obj, 'should be same instance');
};
return WithoutTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('without', WithoutTests);
});
enifed("@ember/-internals/runtime/tests/copyable-array/copy-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var CopyTest =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(CopyTest, _AbstractTestCase);
function CopyTest() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = CopyTest.prototype;
_proto['@test should return an equivalent copy'] = function testShouldReturnAnEquivalentCopy() {
var obj = this.newObject();
var copy = obj.copy();
this.assert.ok(this.isEqual(obj, copy), 'old object and new object should be equivalent');
};
return CopyTest;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('copy', CopyTest, 'CopyableNativeArray', 'CopyableArray');
});
enifed("@ember/-internals/runtime/tests/core/compare_test", ["ember-babel", "@ember/-internals/runtime/lib/type-of", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/compare", "@ember/-internals/runtime/lib/mixins/comparable", "internal-test-helpers"], function (_emberBabel, _typeOf, _object, _compare, _comparable, _internalTestHelpers) {
"use strict";
var data = [];
var Comp = _object.default.extend(_comparable.default);
Comp.reopenClass({
compare: function (obj) {
return obj.get('val');
}
});
(0, _internalTestHelpers.moduleFor)('Ember.compare()',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
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');
};
_proto['@test ordering should work'] = function testOrderingShouldWork(assert) {
var suspect, comparable, failureMessage, suspectIndex, comparableIndex;
for (suspectIndex = 0; suspectIndex < data.length; suspectIndex++) {
suspect = data[suspectIndex];
assert.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, _typeOf.typeOf)(suspect) + ') should be smaller than data[' + comparableIndex + '] (' + (0, _typeOf.typeOf)(comparable) + ')';
assert.equal((0, _compare.default)(suspect, comparable), -1, failureMessage);
}
}
};
_proto['@test comparables should return values in the range of -1, 0, 1'] = function testComparablesShouldReturnValuesInTheRangeOf101(assert) {
var negOne = Comp.create({
val: -1
});
var zero = Comp.create({
val: 0
});
var one = Comp.create({
val: 1
});
assert.equal((0, _compare.default)(negOne, 'a'), -1, 'First item comparable - returns -1 (not negated)');
assert.equal((0, _compare.default)(zero, 'b'), 0, 'First item comparable - returns 0 (not negated)');
assert.equal((0, _compare.default)(one, 'c'), 1, 'First item comparable - returns 1 (not negated)');
assert.equal((0, _compare.default)('a', negOne), 1, 'Second item comparable - returns -1 (negated)');
assert.equal((0, _compare.default)('b', zero), 0, 'Second item comparable - returns 0 (negated)');
assert.equal((0, _compare.default)('c', one), -1, 'Second item comparable - returns 1 (negated)');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/core/copy_test", ["ember-babel", "@ember/-internals/runtime/lib/copy", "internal-test-helpers"], function (_emberBabel, _copy, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember Copy Method',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Ember.copy null'] = function testEmberCopyNull(assert) {
var obj = {
field: null
};
var copied = null;
expectDeprecation(function () {
copied = (0, _copy.default)(obj, true);
}, 'Use ember-copy addon instead of copy method and Copyable mixin.');
assert.equal(copied.field, null, 'null should still be null');
};
_proto['@test Ember.copy date'] = function testEmberCopyDate(assert) {
var date = new Date(2014, 7, 22);
var dateCopy = null;
expectDeprecation(function () {
dateCopy = (0, _copy.default)(date);
}, 'Use ember-copy addon instead of copy method and Copyable mixin.');
assert.equal(date.getTime(), dateCopy.getTime(), 'dates should be equivalent');
};
_proto['@test Ember.copy null prototype object'] = function testEmberCopyNullPrototypeObject(assert) {
var obj = Object.create(null);
obj.foo = 'bar';
var copied = null;
expectDeprecation(function () {
copied = (0, _copy.default)(obj);
}, 'Use ember-copy addon instead of copy method and Copyable mixin.');
assert.equal(copied.foo, 'bar', 'bar should still be bar');
};
_proto['@test Ember.copy Array'] = function testEmberCopyArray(assert) {
var array = [1, null, new Date(2015, 9, 9), 'four'];
var arrayCopy = null;
expectDeprecation(function () {
arrayCopy = (0, _copy.default)(array);
}, 'Use ember-copy addon instead of copy method and Copyable mixin.');
assert.deepEqual(array, arrayCopy, 'array content cloned successfully in new array');
};
_proto['@test Ember.copy cycle detection'] = function testEmberCopyCycleDetection(assert) {
var obj = {
foo: {
bar: 'bar'
}
};
obj.foo.foo = obj.foo;
var cycleCopy = null;
expectDeprecation(function () {
cycleCopy = (0, _copy.default)(obj, true);
}, 'Use ember-copy addon instead of copy method and Copyable mixin.');
assert.equal(cycleCopy.foo.bar, 'bar');
assert.notEqual(cycleCopy.foo.foo, obj.foo.foo);
assert.strictEqual(cycleCopy.foo.foo, cycleCopy.foo.foo);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/core/isEqual_test", ["ember-babel", "@ember/-internals/runtime/lib/is-equal", "internal-test-helpers"], function (_emberBabel, _isEqual, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('isEqual',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test undefined and null'] = function testUndefinedAndNull(assert) {
assert.ok((0, _isEqual.default)(undefined, undefined), 'undefined is equal to undefined');
assert.ok(!(0, _isEqual.default)(undefined, null), 'undefined is not equal to null');
assert.ok((0, _isEqual.default)(null, null), 'null is equal to null');
assert.ok(!(0, _isEqual.default)(null, undefined), 'null is not equal to undefined');
};
_proto['@test strings should be equal'] = function testStringsShouldBeEqual(assert) {
assert.ok(!(0, _isEqual.default)('Hello', 'Hi'), 'different Strings are unequal');
assert.ok((0, _isEqual.default)('Hello', 'Hello'), 'same Strings are equal');
};
_proto['@test numericals should be equal'] = function testNumericalsShouldBeEqual(assert) {
assert.ok((0, _isEqual.default)(24, 24), 'same numbers are equal');
assert.ok(!(0, _isEqual.default)(24, 21), 'different numbers are inequal');
};
_proto['@test dates should be equal'] = function testDatesShouldBeEqual(assert) {
assert.ok((0, _isEqual.default)(new Date(1985, 7, 22), new Date(1985, 7, 22)), 'same dates are equal');
assert.ok(!(0, _isEqual.default)(new Date(2014, 7, 22), new Date(1985, 7, 22)), 'different dates are not equal');
};
_proto['@test array should be equal'] = function testArrayShouldBeEqual(assert) {
// NOTE: We don't test for array contents -- that would be too expensive.
assert.ok(!(0, _isEqual.default)([1, 2], [1, 2]), 'two array instances with the same values should not be equal');
assert.ok(!(0, _isEqual.default)([1, 2], [1]), 'two array instances with different values should not be equal');
};
_proto['@test first object implements isEqual should use it'] = function testFirstObjectImplementsIsEqualShouldUseIt(assert) {
assert.ok((0, _isEqual.default)({
isEqual: function () {
return true;
}
}, null), 'should return true always');
var obj = {
isEqual: function () {
return false;
}
};
assert.equal((0, _isEqual.default)(obj, obj), false, 'should return false because isEqual returns false');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/core/is_array_test", ["ember-babel", "@ember/-internals/runtime/lib/mixins/array", "@ember/-internals/runtime/lib/system/array_proxy", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/browser-environment", "internal-test-helpers"], function (_emberBabel, _array, _array_proxy, _object, _browserEnvironment, _internalTestHelpers) {
"use strict";
var global = void 0;
(0, _internalTestHelpers.moduleFor)('Ember Type Checking',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Ember.isArray'] = function testEmberIsArray(assert) {
var numarray = [1, 2, 3];
var number = 23;
var strarray = ['Hello', 'Hi'];
var string = 'Hello';
var object = {};
var length = {
length: 12
};
var strangeLength = {
length: 'yes'
};
var fn = function () {};
var arrayProxy = _array_proxy.default.create({
content: (0, _array.A)()
});
assert.equal((0, _array.isArray)(numarray), true, '[1,2,3]');
assert.equal((0, _array.isArray)(number), false, '23');
assert.equal((0, _array.isArray)(strarray), true, '["Hello", "Hi"]');
assert.equal((0, _array.isArray)(string), false, '"Hello"');
assert.equal((0, _array.isArray)(object), false, '{}');
assert.equal((0, _array.isArray)(length), true, '{ length: 12 }');
assert.equal((0, _array.isArray)(strangeLength), false, '{ length: "yes" }');
assert.equal((0, _array.isArray)(global), false, 'global');
assert.equal((0, _array.isArray)(fn), false, 'function() {}');
assert.equal((0, _array.isArray)(arrayProxy), true, '[]');
};
_proto['@test Ember.isArray does not trigger proxy assertion when probing for length GH#16495'] = function testEmberIsArrayDoesNotTriggerProxyAssertionWhenProbingForLengthGH16495(assert) {
var instance = _object.default.extend({
// intentionally returning non-null / non-undefined
unknownProperty: function () {
return false;
}
}).create();
assert.equal((0, _array.isArray)(instance), false);
};
_proto['@test Ember.isArray(fileList)'] = function testEmberIsArrayFileList(assert) {
if (_browserEnvironment.window && typeof _browserEnvironment.window.FileList === 'function') {
var fileListElement = document.createElement('input');
fileListElement.type = 'file';
var fileList = fileListElement.files;
assert.equal((0, _array.isArray)(fileList), false, 'fileList');
} else {
assert.ok(true, 'FileList is not present on window');
}
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/core/is_empty_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/array_proxy", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _metal, _array_proxy, _array, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember.isEmpty',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Ember.isEmpty'] = function testEmberIsEmpty(assert) {
var arrayProxy = _array_proxy.default.create({
content: (0, _array.A)()
});
assert.equal(true, (0, _metal.isEmpty)(arrayProxy), 'for an ArrayProxy that has empty content');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/core/type_of_test", ["ember-babel", "@ember/-internals/runtime/lib/type-of", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/browser-environment", "internal-test-helpers"], function (_emberBabel, _typeOf, _object, _browserEnvironment, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember Type Checking',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Ember.typeOf'] = function testEmberTypeOf(assert) {
var MockedDate = function () {};
MockedDate.prototype = new Date();
var mockedDate = new MockedDate();
var date = new Date();
var error = new Error('boum');
var object = {
a: 'b'
};
var a = null;
var arr = [1, 2, 3];
var obj = {};
var instance = _object.default.create({
method: function () {}
});
assert.equal((0, _typeOf.typeOf)(), 'undefined', 'undefined');
assert.equal((0, _typeOf.typeOf)(null), 'null', 'null');
assert.equal((0, _typeOf.typeOf)('Cyril'), 'string', 'Cyril');
assert.equal((0, _typeOf.typeOf)(101), 'number', '101');
assert.equal((0, _typeOf.typeOf)(true), 'boolean', 'true');
assert.equal((0, _typeOf.typeOf)([1, 2, 90]), 'array', '[1,2,90]');
assert.equal((0, _typeOf.typeOf)(/abc/), 'regexp', '/abc/');
assert.equal((0, _typeOf.typeOf)(date), 'date', 'new Date()');
assert.equal((0, _typeOf.typeOf)(mockedDate), 'date', 'mocked date');
assert.equal((0, _typeOf.typeOf)(error), 'error', 'error');
assert.equal((0, _typeOf.typeOf)(object), 'object', 'object');
assert.equal((0, _typeOf.typeOf)(undefined), 'undefined', 'item of type undefined');
assert.equal((0, _typeOf.typeOf)(a), 'null', 'item of type null');
assert.equal((0, _typeOf.typeOf)(arr), 'array', 'item of type array');
assert.equal((0, _typeOf.typeOf)(obj), 'object', 'item of type object');
assert.equal((0, _typeOf.typeOf)(instance), 'instance', 'item of type instance');
assert.equal((0, _typeOf.typeOf)(instance.method), 'function', 'item of type function');
assert.equal((0, _typeOf.typeOf)(_object.default.extend()), 'class', 'item of type class');
assert.equal((0, _typeOf.typeOf)(new Error()), 'error', 'item of type error');
};
_proto['@test Ember.typeOf(fileList)'] = function testEmberTypeOfFileList(assert) {
if (_browserEnvironment.window && typeof _browserEnvironment.window.FileList === 'function') {
var fileListElement = document.createElement('input');
fileListElement.type = 'file';
var fileList = fileListElement.files;
assert.equal((0, _typeOf.typeOf)(fileList), 'filelist', 'item of type filelist');
} else {
assert.ok(true, 'FileList is not present on window');
}
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/ext/function_test", ["ember-babel", "@ember/-internals/environment", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/mixins/evented", "internal-test-helpers"], function (_emberBabel, _environment, _metal, _object, _evented, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Function.prototype.observes() helper',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test global observer helper takes multiple params'] = function testGlobalObserverHelperTakesMultipleParams(assert) {
if (!_environment.ENV.EXTEND_PROTOTYPES.Function) {
assert.ok('undefined' === typeof Function.prototype.observes, 'Function.prototype helper disabled');
return;
}
var MyMixin = _metal.Mixin.create({
count: 0,
foo: function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
}.observes('bar', 'baz')
});
var obj = (0, _metal.mixin)({}, MyMixin);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj, 'bar', 'BAZ');
(0, _metal.set)(obj, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 2, 'should invoke observer after change');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Function.prototype.on() helper',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test sets up an event listener, and can trigger the function on multiple events'] = function testSetsUpAnEventListenerAndCanTriggerTheFunctionOnMultipleEvents(assert) {
if (!_environment.ENV.EXTEND_PROTOTYPES.Function) {
assert.ok('undefined' === typeof Function.prototype.on, 'Function.prototype helper disabled');
return;
}
var MyMixin = _metal.Mixin.create({
count: 0,
foo: function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
}.on('bar', 'baz')
});
var obj = (0, _metal.mixin)({}, _evented.default, MyMixin);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke listener immediately');
obj.trigger('bar');
obj.trigger('baz');
assert.equal((0, _metal.get)(obj, 'count'), 2, 'should invoke listeners when events trigger');
};
_proto2['@test can be chained with observes'] = function testCanBeChainedWithObserves(assert) {
if (!_environment.ENV.EXTEND_PROTOTYPES.Function) {
assert.ok('Function.prototype helper disabled');
return;
}
var MyMixin = _metal.Mixin.create({
count: 0,
bay: 'bay',
foo: function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
}.observes('bay').on('bar')
});
var obj = (0, _metal.mixin)({}, _evented.default, MyMixin);
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke listener immediately');
(0, _metal.set)(obj, 'bay', 'BAY');
obj.trigger('bar');
assert.equal((0, _metal.get)(obj, 'count'), 2, 'should invoke observer and listener');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Function.prototype.property() helper',
/*#__PURE__*/
function (_AbstractTestCase3) {
(0, _emberBabel.inheritsLoose)(_class3, _AbstractTestCase3);
function _class3() {
return _AbstractTestCase3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3['@test sets up a ComputedProperty'] = function testSetsUpAComputedProperty(assert) {
if (!_environment.ENV.EXTEND_PROTOTYPES.Function) {
assert.ok('undefined' === typeof Function.prototype.property, 'Function.prototype helper disabled');
return;
}
var MyClass = _object.default.extend({
firstName: null,
lastName: null,
fullName: function () {
return (0, _metal.get)(this, 'firstName') + ' ' + (0, _metal.get)(this, 'lastName');
}.property('firstName', 'lastName')
});
var obj = MyClass.create({
firstName: 'Fred',
lastName: 'Flinstone'
});
assert.equal((0, _metal.get)(obj, 'fullName'), 'Fred Flinstone', 'should return the computed value');
(0, _metal.set)(obj, 'firstName', 'Wilma');
assert.equal((0, _metal.get)(obj, 'fullName'), 'Wilma Flinstone', 'should return the new computed value');
(0, _metal.set)(obj, 'lastName', '');
assert.equal((0, _metal.get)(obj, 'fullName'), 'Wilma ', 'should return the new computed value');
};
return _class3;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/ext/rsvp_test", ["ember-babel", "@ember/runloop", "@ember/-internals/error-handling", "@ember/-internals/runtime/lib/ext/rsvp", "@ember/debug", "internal-test-helpers"], function (_emberBabel, _runloop, _errorHandling, _rsvp, _debug, _internalTestHelpers) {
"use strict";
var ORIGINAL_ONERROR = (0, _errorHandling.getOnerror)();
(0, _internalTestHelpers.moduleFor)('Ember.RSVP',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.afterEach = function afterEach() {
(0, _errorHandling.setOnerror)(ORIGINAL_ONERROR);
};
_proto['@test Ensure that errors thrown from within a promise are sent to the console'] = function testEnsureThatErrorsThrownFromWithinAPromiseAreSentToTheConsole(assert) {
var error = new Error('Error thrown in a promise for testing purposes.');
try {
(0, _runloop.run)(function () {
new _rsvp.default.Promise(function () {
throw error;
});
});
assert.ok(false, 'expected assertion to be thrown');
} catch (e) {
assert.equal(e, error, 'error was re-thrown');
}
};
_proto['@test TransitionAborted errors are not re-thrown'] = function testTransitionAbortedErrorsAreNotReThrown(assert) {
assert.expect(1);
var fakeTransitionAbort = {
name: 'TransitionAborted'
};
(0, _runloop.run)(_rsvp.default, 'reject', fakeTransitionAbort);
assert.ok(true, 'did not throw an error when dealing with TransitionAborted');
};
_proto['@test Can reject with non-Error object'] = function testCanRejectWithNonErrorObject(assert) {
var wasEmberTesting = (0, _debug.isTesting)();
(0, _debug.setTesting)(false);
assert.expect(1);
try {
(0, _runloop.run)(_rsvp.default, 'reject', 'foo');
} catch (e) {
assert.equal(e, 'foo', 'should throw with rejection message');
} finally {
(0, _debug.setTesting)(wasEmberTesting);
}
};
_proto['@test Can reject with no arguments'] = function testCanRejectWithNoArguments(assert) {
var wasEmberTesting = (0, _debug.isTesting)();
(0, _debug.setTesting)(false);
assert.expect(1);
try {
(0, _runloop.run)(_rsvp.default, 'reject');
} catch (e) {
assert.ok(false, 'should not throw');
} finally {
(0, _debug.setTesting)(wasEmberTesting);
}
assert.ok(true);
};
_proto['@test rejections like jqXHR which have errorThrown property work'] = function testRejectionsLikeJqXHRWhichHaveErrorThrownPropertyWork(assert) {
assert.expect(2);
var wasEmberTesting = (0, _debug.isTesting)();
var wasOnError = (0, _errorHandling.getOnerror)();
try {
(0, _debug.setTesting)(false);
(0, _errorHandling.setOnerror)(function (error) {
assert.equal(error, actualError, 'expected the real error on the jqXHR');
assert.equal(error.__reason_with_error_thrown__, jqXHR, 'also retains a helpful reference to the rejection reason');
});
var actualError = new Error('OMG what really happened');
var jqXHR = {
errorThrown: actualError
};
(0, _runloop.run)(_rsvp.default, 'reject', jqXHR);
} finally {
(0, _errorHandling.setOnerror)(wasOnError);
(0, _debug.setTesting)(wasEmberTesting);
}
};
_proto['@test rejections where the errorThrown is a string should wrap the sting in an error object'] = function testRejectionsWhereTheErrorThrownIsAStringShouldWrapTheStingInAnErrorObject(assert) {
assert.expect(2);
var wasEmberTesting = (0, _debug.isTesting)();
var wasOnError = (0, _errorHandling.getOnerror)();
try {
(0, _debug.setTesting)(false);
(0, _errorHandling.setOnerror)(function (error) {
assert.equal(error.message, actualError, 'expected the real error on the jqXHR');
assert.equal(error.__reason_with_error_thrown__, jqXHR, 'also retains a helpful reference to the rejection reason');
});
var actualError = 'OMG what really happened';
var jqXHR = {
errorThrown: actualError
};
(0, _runloop.run)(_rsvp.default, 'reject', jqXHR);
} finally {
(0, _errorHandling.setOnerror)(wasOnError);
(0, _debug.setTesting)(wasEmberTesting);
}
};
_proto['@test rejections can be serialized to JSON'] = function testRejectionsCanBeSerializedToJSON(assert) {
assert.expect(2);
var wasEmberTesting = (0, _debug.isTesting)();
var wasOnError = (0, _errorHandling.getOnerror)();
try {
(0, _debug.setTesting)(false);
(0, _errorHandling.setOnerror)(function (error) {
assert.equal(error.message, 'a fail');
assert.ok(JSON.stringify(error), 'Error can be serialized');
});
var jqXHR = {
errorThrown: new Error('a fail')
};
(0, _runloop.run)(_rsvp.default, 'reject', jqXHR);
} finally {
(0, _errorHandling.setOnerror)(wasOnError);
(0, _debug.setTesting)(wasEmberTesting);
}
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
var reason = 'i failed';
function ajax() {
return new _rsvp.default.Promise(function (resolve) {
setTimeout(resolve, 0); // fake true / foreign async
});
}
(0, _internalTestHelpers.moduleFor)('Ember.test: rejection assertions',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test unambigiously unhandled rejection'] = function testUnambigiouslyUnhandledRejection(assert) {
assert.throws(function () {
(0, _runloop.run)(function () {
_rsvp.default.Promise.reject(reason);
}); // something is funky, we should likely assert
}, reason);
};
_proto2['@test sync handled'] = function testSyncHandled(assert) {
(0, _runloop.run)(function () {
_rsvp.default.Promise.reject(reason).catch(function () {});
}); // handled, we shouldn't need to assert.
assert.ok(true, 'reached end of test');
};
_proto2['@test handled within the same micro-task (via Ember.RVP.Promise)'] = function testHandledWithinTheSameMicroTaskViaEmberRVPPromise(assert) {
(0, _runloop.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.
assert.ok(true, 'reached end of test');
};
_proto2['@test handled within the same micro-task (via direct run-loop)'] = function testHandledWithinTheSameMicroTaskViaDirectRunLoop(assert) {
(0, _runloop.run)(function () {
var rejection = _rsvp.default.Promise.reject(reason);
(0, _runloop.schedule)('afterRender', function () {
return rejection.catch(function () {});
});
}); // handled, we shouldn't need to assert.
assert.ok(true, 'reached end of test');
};
_proto2['@test handled in the next microTask queue flush (next)'] = function testHandledInTheNextMicroTaskQueueFlushNext(assert) {
assert.expect(2);
var done = assert.async();
assert.throws(function () {
(0, _runloop.run)(function () {
var rejection = _rsvp.default.Promise.reject(reason);
(0, _runloop.next)(function () {
rejection.catch(function () {});
assert.ok(true, 'reached end of test');
done();
});
});
}, reason); // a promise rejection survived a full flush of the run-loop without being handled
// this is very likely an issue.
};
_proto2['@test handled in the same microTask Queue flush do to data locality'] = function testHandledInTheSameMicroTaskQueueFlushDoToDataLocality(assert) {
// 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, _runloop.run)(function () {
var rejection = _rsvp.default.Promise.reject(reason);
store.find('user', 1).then(function () {
return rejection.catch(function () {});
});
});
assert.ok(true, 'reached end of test');
};
_proto2['@test handled in a different microTask Queue flush do to data locality'] = function testHandledInADifferentMicroTaskQueueFlushDoToDataLocality(assert) {
var done = assert.async(); // an ambiguous scenario, this may or may not assert
// it depends on the locality of `user#1`
var store = {
find: function () {
return ajax();
}
};
assert.throws(function () {
(0, _runloop.run)(function () {
var rejection = _rsvp.default.Promise.reject(reason);
store.find('user', 1).then(function () {
rejection.catch(function () {});
assert.ok(true, 'reached end of test');
done();
});
});
}, reason);
};
_proto2['@test handled in the next microTask queue flush (ajax example)'] = function testHandledInTheNextMicroTaskQueueFlushAjaxExample(assert) {
var done = assert.async();
assert.throws(function () {
(0, _runloop.run)(function () {
var rejection = _rsvp.default.Promise.reject(reason);
ajax().then(function () {
rejection.catch(function () {});
assert.ok(true, 'reached end of test');
done();
});
});
}, reason);
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/helpers/array", ["exports", "ember-babel", "@ember/-internals/runtime/lib/system/array_proxy", "@ember/-internals/runtime/lib/mixins/array", "@ember/-internals/utils", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/mixins/copyable", "internal-test-helpers"], function (_exports, _emberBabel, _array_proxy, _array, _utils, _metal, _object, _copyable, _internalTestHelpers) {
"use strict";
_exports.newFixture = newFixture;
_exports.newObjectsFixture = newObjectsFixture;
_exports.runArrayTests = runArrayTests;
function newFixture(cnt) {
var ret = [];
while (--cnt >= 0) {
ret.push((0, _utils.generateGuid)());
}
return ret;
}
function newObjectsFixture(cnt) {
var ret = [];
var item;
while (--cnt >= 0) {
item = {};
(0, _utils.guidFor)(item);
ret.push(item);
}
return ret;
}
var ArrayTestsObserverClass = _object.default.extend({
init: function () {
this._super.apply(this, arguments);
this.isEnabled = true;
this.reset();
},
reset: function () {
this._keys = {};
this._values = {};
this._before = null;
this._after = null;
return this;
},
observe: function (obj) {
if (obj.addObserver) {
for (var _len = arguments.length, keys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
keys[_key - 1] = arguments[_key];
}
var loc = keys.length;
while (--loc >= 0) {
obj.addObserver(keys[loc], this, 'propertyDidChange');
}
} else {
this.isEnabled = false;
}
return this;
},
observeArray: function (obj) {
(0, _metal.addArrayObserver)(obj, this);
return this;
},
stopObserveArray: function (obj) {
(0, _metal.removeArrayObserver)(obj, this);
return this;
},
propertyDidChange: function (target, key, value) {
if (this._keys[key] === undefined) {
this._keys[key] = 0;
}
this._keys[key]++;
this._values[key] = value;
},
arrayWillChange: function () {
this.assert.equal(this._before, null, 'should only call once');
this._before = Array.prototype.slice.call(arguments);
},
arrayDidChange: function () {
this.assert.equal(this._after, null, 'should only call once');
this._after = Array.prototype.slice.call(arguments);
},
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;
}
},
timesCalled: function (key) {
return this._keys[key] || 0;
}
});
var AbstractArrayHelper =
/*#__PURE__*/
function () {
function AbstractArrayHelper() {}
var _proto = AbstractArrayHelper.prototype;
_proto.beforeEach = function beforeEach(assert) {
this.assert = assert;
};
_proto.newObject = function newObject(ary) {
return ary ? ary.slice() : newFixture(3);
};
_proto.toArray = function toArray(obj) {
return obj.slice();
};
_proto.newObserver = function newObserver() {
var ret = ArrayTestsObserverClass.create({
assert: this.assert
});
if (arguments.length > 0) {
ret.observe.apply(ret, arguments);
}
return ret;
};
return AbstractArrayHelper;
}();
var NativeArrayHelpers =
/*#__PURE__*/
function (_AbstractArrayHelper) {
(0, _emberBabel.inheritsLoose)(NativeArrayHelpers, _AbstractArrayHelper);
function NativeArrayHelpers() {
return _AbstractArrayHelper.apply(this, arguments) || this;
}
var _proto2 = NativeArrayHelpers.prototype;
_proto2.newObject = function newObject(ary) {
return (0, _array.A)(_AbstractArrayHelper.prototype.newObject.call(this, ary));
};
_proto2.mutate = function mutate(obj) {
obj.pushObject(obj.length + 1);
};
return NativeArrayHelpers;
}(AbstractArrayHelper);
var CopyableNativeArray =
/*#__PURE__*/
function (_AbstractArrayHelper2) {
(0, _emberBabel.inheritsLoose)(CopyableNativeArray, _AbstractArrayHelper2);
function CopyableNativeArray() {
return _AbstractArrayHelper2.apply(this, arguments) || this;
}
var _proto3 = CopyableNativeArray.prototype;
_proto3.newObject = function newObject() {
return (0, _array.A)([(0, _utils.generateGuid)()]);
};
_proto3.isEqual = function isEqual(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];
};
return CopyableNativeArray;
}(AbstractArrayHelper);
var CopyableArray =
/*#__PURE__*/
function (_AbstractArrayHelper3) {
(0, _emberBabel.inheritsLoose)(CopyableArray, _AbstractArrayHelper3);
function CopyableArray() {
return _AbstractArrayHelper3.apply(this, arguments) || this;
}
var _proto4 = CopyableArray.prototype;
_proto4.newObject = function newObject() {
return CopyableObject.create();
};
_proto4.isEqual = function isEqual(a, b) {
if (!(a instanceof CopyableObject) || !(b instanceof CopyableObject)) {
return false;
}
return (0, _metal.get)(a, 'id') === (0, _metal.get)(b, 'id');
};
return CopyableArray;
}(AbstractArrayHelper);
var ArrayProxyHelpers =
/*#__PURE__*/
function (_AbstractArrayHelper4) {
(0, _emberBabel.inheritsLoose)(ArrayProxyHelpers, _AbstractArrayHelper4);
function ArrayProxyHelpers() {
return _AbstractArrayHelper4.apply(this, arguments) || this;
}
var _proto5 = ArrayProxyHelpers.prototype;
_proto5.newObject = function newObject(ary) {
return _array_proxy.default.create({
content: (0, _array.A)(_AbstractArrayHelper4.prototype.newObject.call(this, ary))
});
};
_proto5.mutate = function mutate(obj) {
obj.pushObject((0, _metal.get)(obj, 'length') + 1);
};
_proto5.toArray = function toArray(obj) {
return obj.toArray ? obj.toArray() : obj.slice();
};
return ArrayProxyHelpers;
}(AbstractArrayHelper);
/*
Implement a basic fake mutable array. This validates that any non-native
enumerable can impl this API.
*/
var TestArray = _object.default.extend(_array.default, {
_content: null,
init: function () {
this._content = this._content || [];
},
// some methods to modify the array so we can test changes. Note that
// arrays can be modified even if they don't implement MutableArray. The
// MutableArray is just a standard API for mutation but not required.
addObject: function (obj) {
var idx = this._content.length;
(0, _metal.arrayContentWillChange)(this, idx, 0, 1);
this._content.push(obj);
(0, _metal.arrayContentDidChange)(this, idx, 0, 1);
},
removeFirst: function () {
(0, _metal.arrayContentWillChange)(this, 0, 1, 0);
this._content.shift();
(0, _metal.arrayContentDidChange)(this, 0, 1, 0);
},
objectAt: function (idx) {
return this._content[idx];
},
length: (0, _metal.computed)(function () {
return this._content.length;
})
});
/*
Implement a basic fake mutable array. This validates that any non-native
enumerable can impl this API.
*/
var TestMutableArray = _object.default.extend(_array.MutableArray, {
_content: null,
init: function () {
var ary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
this._content = (0, _array.A)(ary);
},
replace: function (idx, amt, objects) {
var args = objects ? objects.slice() : [];
var removeAmt = amt;
var addAmt = args.length;
(0, _metal.arrayContentWillChange)(this, idx, removeAmt, addAmt);
args.unshift(amt);
args.unshift(idx);
this._content.splice.apply(this._content, args);
(0, _metal.arrayContentDidChange)(this, idx, removeAmt, addAmt);
return this;
},
objectAt: function (idx) {
return this._content[idx];
},
length: (0, _metal.computed)(function () {
return this._content.length;
}),
slice: function () {
return this._content.slice();
}
});
var CopyableObject = _object.default.extend(_copyable.default, {
id: null,
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'id', (0, _utils.generateGuid)());
},
copy: function () {
var ret = CopyableObject.create();
(0, _metal.set)(ret, 'id', (0, _metal.get)(this, 'id'));
return ret;
}
});
var MutableArrayHelpers =
/*#__PURE__*/
function (_NativeArrayHelpers) {
(0, _emberBabel.inheritsLoose)(MutableArrayHelpers, _NativeArrayHelpers);
function MutableArrayHelpers() {
return _NativeArrayHelpers.apply(this, arguments) || this;
}
var _proto6 = MutableArrayHelpers.prototype;
_proto6.newObject = function newObject(ary) {
return TestMutableArray.create(_NativeArrayHelpers.prototype.newObject.call(this, ary));
} // allows for testing of the basic enumerable after an internal mutation
;
_proto6.mutate = function mutate(obj) {
obj.addObject(this.getFixture(1)[0]);
};
return MutableArrayHelpers;
}(NativeArrayHelpers);
var EmberArrayHelpers =
/*#__PURE__*/
function (_MutableArrayHelpers) {
(0, _emberBabel.inheritsLoose)(EmberArrayHelpers, _MutableArrayHelpers);
function EmberArrayHelpers() {
return _MutableArrayHelpers.apply(this, arguments) || this;
}
var _proto7 = EmberArrayHelpers.prototype;
_proto7.newObject = function newObject(ary) {
return TestArray.create(_MutableArrayHelpers.prototype.newObject.call(this, ary));
};
return EmberArrayHelpers;
}(MutableArrayHelpers);
function runArrayTests(name, Tests) {
for (var _len2 = arguments.length, types = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
types[_key2 - 2] = arguments[_key2];
}
if (types.length > 0) {
types.forEach(function (type) {
switch (type) {
case 'ArrayProxy':
(0, _internalTestHelpers.moduleFor)("ArrayProxy: " + name, Tests, ArrayProxyHelpers);
break;
case 'EmberArray':
(0, _internalTestHelpers.moduleFor)("EmberArray: " + name, Tests, EmberArrayHelpers);
break;
case 'MutableArray':
(0, _internalTestHelpers.moduleFor)("MutableArray: " + name, Tests, EmberArrayHelpers);
break;
case 'CopyableArray':
(0, _internalTestHelpers.moduleFor)("CopyableArray: " + name, Tests, CopyableArray);
break;
case 'CopyableNativeArray':
(0, _internalTestHelpers.moduleFor)("CopyableNativeArray: " + name, Tests, CopyableNativeArray);
break;
case 'NativeArray':
(0, _internalTestHelpers.moduleFor)("NativeArray: " + name, Tests, EmberArrayHelpers);
break;
}
});
} else {
(0, _internalTestHelpers.moduleFor)("ArrayProxy: " + name, Tests, ArrayProxyHelpers);
(0, _internalTestHelpers.moduleFor)("EmberArray: " + name, Tests, EmberArrayHelpers);
(0, _internalTestHelpers.moduleFor)("MutableArray: " + name, Tests, MutableArrayHelpers);
(0, _internalTestHelpers.moduleFor)("NativeArray: " + name, Tests, NativeArrayHelpers);
}
}
});
enifed("@ember/-internals/runtime/tests/inject_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _metal, _object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('inject',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test attempting to inject a nonexistent container key should error'] = function testAttemptingToInjectANonexistentContainerKeyShouldError() {
var owner = (0, _internalTestHelpers.buildOwner)();
var AnObject = _object.default.extend({
foo: new _metal.InjectedProperty('bar', 'baz')
});
owner.register('foo:main', AnObject);
expectAssertion(function () {
owner.lookup('foo:main');
}, /Attempting to inject an unknown injection: 'bar:baz'/);
};
_proto['@test factories should return a list of lazy injection full names'] = function testFactoriesShouldReturnAListOfLazyInjectionFullNames(assert) {
if (true
/* DEBUG */
) {
var AnObject = _object.default.extend({
foo: new _metal.InjectedProperty('foo', 'bar'),
bar: new _metal.InjectedProperty('quux')
});
assert.deepEqual(AnObject._lazyInjections(), {
foo: {
specifier: 'foo:bar',
source: undefined,
namespace: undefined
},
bar: {
specifier: 'quux:bar',
source: undefined,
namespace: undefined
}
}, 'should return injected container keys');
} else {
assert.expect(0);
}
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/legacy_1x/mixins/observable/chained_test", ["ember-babel", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _runloop, _metal, _object, _array, _internalTestHelpers) {
"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()
*/
(0, _internalTestHelpers.moduleFor)('Ember.Observable - Observing with @each',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test chained observers on enumerable properties are triggered when the observed property of any item changes'] = function testChainedObserversOnEnumerablePropertiesAreTriggeredWhenTheObservedPropertyOfAnyItemChanges(assert) {
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, _metal.set)(family, 'momma', momma);
(0, _metal.set)(momma, 'children', (0, _array.A)([child1, child2, child3]));
var observerFiredCount = 0;
(0, _metal.addObserver)(family, 'momma.children.@each.name', this, function () {
observerFiredCount++;
});
observerFiredCount = 0;
(0, _runloop.run)(function () {
return (0, _metal.get)(momma, 'children').setEach('name', 'Juan');
});
assert.equal(observerFiredCount, 3, 'observer fired after changing child names');
observerFiredCount = 0;
(0, _runloop.run)(function () {
return (0, _metal.get)(momma, 'children').pushObject(child4);
});
assert.equal(observerFiredCount, 1, 'observer fired after adding a new item');
observerFiredCount = 0;
(0, _runloop.run)(function () {
return (0, _metal.set)(child4, 'name', 'Herbert');
});
assert.equal(observerFiredCount, 1, 'observer fired after changing property on new object');
(0, _metal.set)(momma, 'children', []);
observerFiredCount = 0;
(0, _runloop.run)(function () {
return (0, _metal.set)(child1, 'name', 'Hanna');
});
assert.equal(observerFiredCount, 0, 'observer did not fire after removing changing property on a removed object');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/legacy_1x/mixins/observable/observable_test", ["ember-babel", "@ember/-internals/environment", "@ember/runloop", "@ember/-internals/metal", "@ember/string", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/mixins/observable", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _environment, _runloop, _metal, _string, _object, _observable, _array, _internalTestHelpers) {
"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.
* 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 = _environment.context.lookup; // ..........................................................
// GET()
//
(0, _internalTestHelpers.moduleFor)('object.get()',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
object = ObservableObject.extend(_observable.default, {
computed: (0, _metal.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
});
};
_proto['@test should get normal properties'] = function testShouldGetNormalProperties(assert) {
assert.equal(object.get('normal'), 'value');
};
_proto['@test should call computed properties and return their result'] = function testShouldCallComputedPropertiesAndReturnTheirResult(assert) {
assert.equal(object.get('computed'), 'value');
};
_proto['@test should return the function for a non-computed property'] = function testShouldReturnTheFunctionForANonComputedProperty(assert) {
var value = object.get('method');
assert.equal(typeof value, 'function');
};
_proto['@test should return null when property value is null'] = function testShouldReturnNullWhenPropertyValueIsNull(assert) {
assert.equal(object.get('nullProperty'), null);
};
_proto['@test should call unknownProperty when value is undefined'] = function testShouldCallUnknownPropertyWhenValueIsUndefined(assert) {
assert.equal(object.get('unknown'), 'unknown');
assert.equal(object.lastUnknownProperty, 'unknown');
};
return _class;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// Ember.GET()
//
(0, _internalTestHelpers.moduleFor)('Ember.get()',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2.beforeEach = function beforeEach() {
objectA = ObservableObject.extend({
computed: (0, _metal.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
};
};
_proto2['@test should get normal properties on Ember.Observable'] = function testShouldGetNormalPropertiesOnEmberObservable(assert) {
assert.equal((0, _metal.get)(objectA, 'normal'), 'value');
};
_proto2['@test should call computed properties on Ember.Observable and return their result'] = function testShouldCallComputedPropertiesOnEmberObservableAndReturnTheirResult(assert) {
assert.equal((0, _metal.get)(objectA, 'computed'), 'value');
};
_proto2['@test should return the function for a non-computed property on Ember.Observable'] = function testShouldReturnTheFunctionForANonComputedPropertyOnEmberObservable(assert) {
var value = (0, _metal.get)(objectA, 'method');
assert.equal(typeof value, 'function');
};
_proto2['@test should return null when property value is null on Ember.Observable'] = function testShouldReturnNullWhenPropertyValueIsNullOnEmberObservable(assert) {
assert.equal((0, _metal.get)(objectA, 'nullProperty'), null);
};
_proto2['@test should call unknownProperty when value is undefined on Ember.Observable'] = function testShouldCallUnknownPropertyWhenValueIsUndefinedOnEmberObservable(assert) {
assert.equal((0, _metal.get)(objectA, 'unknown'), 'unknown');
assert.equal(objectA.lastUnknownProperty, 'unknown');
};
_proto2['@test should get normal properties on standard objects'] = function testShouldGetNormalPropertiesOnStandardObjects(assert) {
assert.equal((0, _metal.get)(objectB, 'normal'), 'value');
};
_proto2['@test should return null when property is null on standard objects'] = function testShouldReturnNullWhenPropertyIsNullOnStandardObjects(assert) {
assert.equal((0, _metal.get)(objectB, 'nullProperty'), null);
};
_proto2['@test raise if the provided object is undefined'] = function testRaiseIfTheProvidedObjectIsUndefined() {
expectAssertion(function () {
(0, _metal.get)(undefined, 'key');
}, /Cannot call get with 'key' on an undefined object/i);
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Ember.get() with paths',
/*#__PURE__*/
function (_AbstractTestCase3) {
(0, _emberBabel.inheritsLoose)(_class3, _AbstractTestCase3);
function _class3() {
return _AbstractTestCase3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3['@test should return a property at a given path relative to the passed object'] = function testShouldReturnAPropertyAtAGivenPathRelativeToThePassedObject(assert) {
var foo = ObservableObject.create({
bar: ObservableObject.extend({
baz: (0, _metal.computed)(function () {
return 'blargh';
}).volatile()
}).create()
});
assert.equal((0, _metal.get)(foo, 'bar.baz'), 'blargh');
};
_proto3['@test should return a property at a given path relative to the passed object - JavaScript hash'] = function testShouldReturnAPropertyAtAGivenPathRelativeToThePassedObjectJavaScriptHash(assert) {
var foo = {
bar: {
baz: 'blargh'
}
};
assert.equal((0, _metal.get)(foo, 'bar.baz'), 'blargh');
};
return _class3;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// SET()
//
(0, _internalTestHelpers.moduleFor)('object.set()',
/*#__PURE__*/
function (_AbstractTestCase4) {
(0, _emberBabel.inheritsLoose)(_class4, _AbstractTestCase4);
function _class4() {
return _AbstractTestCase4.apply(this, arguments) || this;
}
var _proto4 = _class4.prototype;
_proto4.beforeEach = function beforeEach() {
object = ObservableObject.extend({
computed: (0, _metal.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();
};
_proto4['@test should change normal properties and return the value'] = function testShouldChangeNormalPropertiesAndReturnTheValue(assert) {
var ret = object.set('normal', 'changed');
assert.equal(object.get('normal'), 'changed');
assert.equal(ret, 'changed');
};
_proto4['@test should call computed properties passing value and return the value'] = function testShouldCallComputedPropertiesPassingValueAndReturnTheValue(assert) {
var ret = object.set('computed', 'changed');
assert.equal(object.get('_computed'), 'changed');
assert.equal(ret, 'changed');
};
_proto4['@test should change normal properties when passing undefined'] = function testShouldChangeNormalPropertiesWhenPassingUndefined(assert) {
var ret = object.set('normal', undefined);
assert.equal(object.get('normal'), undefined);
assert.equal(ret, undefined);
};
_proto4['@test should replace the function for a non-computed property and return the value'] = function testShouldReplaceTheFunctionForANonComputedPropertyAndReturnTheValue(assert) {
var ret = object.set('method', 'changed');
assert.equal(object.get('_method'), 'method'); // make sure this was NOT run
assert.ok(typeof object.get('method') !== 'function');
assert.equal(ret, 'changed');
};
_proto4['@test should replace prover when property value is null'] = function testShouldReplaceProverWhenPropertyValueIsNull(assert) {
var ret = object.set('nullProperty', 'changed');
assert.equal(object.get('nullProperty'), 'changed');
assert.equal(ret, 'changed');
};
_proto4['@test should call unknownProperty with value when property is undefined'] = function testShouldCallUnknownPropertyWithValueWhenPropertyIsUndefined(assert) {
var ret = object.set('unknown', 'changed');
assert.equal(object.get('_unknown'), 'changed');
assert.equal(ret, 'changed');
};
return _class4;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// COMPUTED PROPERTIES
//
(0, _internalTestHelpers.moduleFor)('Computed properties',
/*#__PURE__*/
function (_AbstractTestCase5) {
(0, _emberBabel.inheritsLoose)(_class5, _AbstractTestCase5);
function _class5() {
return _AbstractTestCase5.apply(this, arguments) || this;
}
var _proto5 = _class5.prototype;
_proto5.beforeEach = function beforeEach() {
lookup = _environment.context.lookup = {};
object = ObservableObject.extend({
computed: (0, _metal.computed)({
get: function () {
this.computedCalls.push('getter-called');
return 'computed';
},
set: function (key, value) {
this.computedCalls.push(value);
}
}).volatile(),
computedCached: (0, _metal.computed)({
get: function () {
this.computedCachedCalls.push('getter-called');
return 'computedCached';
},
set: function (key, value) {
this.computedCachedCalls.push(value);
}
}),
dependent: (0, _metal.computed)({
get: function () {
this.dependentCalls.push('getter-called');
return 'dependent';
},
set: function (key, value) {
this.dependentCalls.push(value);
}
}).property('changer').volatile(),
dependentFront: (0, _metal.computed)('changer', {
get: function () {
this.dependentFrontCalls.push('getter-called');
return 'dependentFront';
},
set: function (key, value) {
this.dependentFrontCalls.push(value);
}
}).volatile(),
dependentCached: (0, _metal.computed)({
get: function () {
this.dependentCachedCalls.push('getter-called!');
return 'dependentCached';
},
set: function (key, value) {
this.dependentCachedCalls.push(value);
}
}).property('changer'),
inc: (0, _metal.computed)('changer', function () {
return this.incCallCount++;
}),
nestedInc: (0, _metal.computed)(function () {
(0, _metal.get)(this, 'inc');
return this.nestedIncCallCount++;
}).property('inc'),
isOn: (0, _metal.computed)({
get: function () {
return this.get('state') === 'on';
},
set: function () {
this.set('state', 'on');
return this.get('state') === 'on';
}
}).property('state').volatile(),
isOff: (0, _metal.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'
});
};
_proto5.afterEach = function afterEach() {
_environment.context.lookup = originalLookup;
};
_proto5['@test getting values should call function return value'] = function testGettingValuesShouldCallFunctionReturnValue(assert) {
// get each property twice. Verify return.
var keys = (0, _string.w)('computed computedCached dependent dependentFront dependentCached');
keys.forEach(function (key) {
assert.equal(object.get(key), key, "Try #1: object.get(" + key + ") should run function");
assert.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) {
assert.equal(object[key].length, 2, "non-cached property " + key + " should be called 2x");
});
(0, _string.w)('computedCachedCalls dependentCachedCalls').forEach(function (key) {
assert.equal(object[key].length, 1, "non-cached property " + key + " should be called 1x");
});
};
_proto5['@test setting values should call function return value'] = function testSettingValuesShouldCallFunctionReturnValue(assert) {
// 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) {
assert.equal(object.set(key, values[0]), values[0], "Try #1: object.set(" + key + ", " + values[0] + ") should run function");
assert.equal(object.set(key, values[1]), values[1], "Try #2: object.set(" + key + ", " + values[1] + ") should run function");
assert.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;
assert.equal(calls.length, expectedLength, "set(" + key + ") should be called the right amount of times");
for (idx = 0; idx < 2; idx++) {
assert.equal(calls[idx], values[idx], "call #" + (idx + 1) + " to set(" + key + ") should have passed value " + values[idx]);
}
});
};
_proto5['@test notify change should clear cache'] = function testNotifyChangeShouldClearCache(assert) {
// call get several times to collect call count
object.get('computedCached'); // should run func
object.get('computedCached'); // should not run func
object.notifyPropertyChange('computedCached');
object.get('computedCached'); // should run again
assert.equal(object.computedCachedCalls.length, 2, 'should have invoked method 2x');
};
_proto5['@test change dependent should clear cache'] = function testChangeDependentShouldClearCache(assert) {
// call get several times to collect call count
var ret1 = object.get('inc'); // should run func
assert.equal(object.get('inc'), ret1, 'multiple calls should not run cached prop');
object.set('changer', 'bar');
assert.equal(object.get('inc'), ret1 + 1, 'should increment after dependent key changes'); // should run again
};
_proto5['@test just notifying change of dependent should clear cache'] = function testJustNotifyingChangeOfDependentShouldClearCache(assert) {
// call get several times to collect call count
var ret1 = object.get('inc'); // should run func
assert.equal(object.get('inc'), ret1, 'multiple calls should not run cached prop');
object.notifyPropertyChange('changer');
assert.equal(object.get('inc'), ret1 + 1, 'should increment after dependent key changes'); // should run again
};
_proto5['@test changing dependent should clear nested cache'] = function testChangingDependentShouldClearNestedCache(assert) {
// call get several times to collect call count
var ret1 = object.get('nestedInc'); // should run func
assert.equal(object.get('nestedInc'), ret1, 'multiple calls should not run cached prop');
object.set('changer', 'bar');
assert.equal(object.get('nestedInc'), ret1 + 1, 'should increment after dependent key changes'); // should run again
};
_proto5['@test just notifying change of dependent should clear nested cache'] = function testJustNotifyingChangeOfDependentShouldClearNestedCache(assert) {
// call get several times to collect call count
var ret1 = object.get('nestedInc'); // should run func
assert.equal(object.get('nestedInc'), ret1, 'multiple calls should not run cached prop');
object.notifyPropertyChange('changer');
assert.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.
;
_proto5['@test change dependent should clear cache when observers of dependent are called'] = function testChangeDependentShouldClearCacheWhenObserversOfDependentAreCalled(assert) {
// call get several times to collect call count
var ret1 = object.get('inc'); // should run func
assert.equal(object.get('inc'), ret1, 'multiple calls should not run cached prop'); // add observer to verify change...
object.addObserver('inc', this, function () {
assert.equal(object.get('inc'), ret1 + 1, 'should increment after dependent key changes'); // should run again
}); // now run
object.set('changer', 'bar');
};
_proto5['@test setting one of two computed properties that depend on a third property should clear the kvo cache'] = function testSettingOneOfTwoComputedPropertiesThatDependOnAThirdPropertyShouldClearTheKvoCache(assert) {
// 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);
assert.equal(object.get('isOff'), true, 'object.isOff should be true');
assert.equal(object.get('isOn'), false, 'object.isOn should be false');
};
_proto5['@test dependent keys should be able to be specified as property paths'] = function testDependentKeysShouldBeAbleToBeSpecifiedAsPropertyPaths(assert) {
var depObj = ObservableObject.extend({
menuPrice: (0, _metal.computed)(function () {
return this.get('menu.price');
}).property('menu.price')
}).create({
menu: ObservableObject.create({
price: 5
})
});
assert.equal(depObj.get('menuPrice'), 5, 'precond - initial value returns 5');
depObj.set('menu.price', 6);
assert.equal(depObj.get('menuPrice'), 6, 'cache is properly invalidated after nested property changes');
};
_proto5['@test cacheable nested dependent keys should clear after their dependencies update'] = function testCacheableNestedDependentKeysShouldClearAfterTheirDependenciesUpdate(assert) {
assert.ok(true);
var DepObj;
(0, _runloop.run)(function () {
lookup.DepObj = DepObj = ObservableObject.extend({
price: (0, _metal.computed)('restaurant.menu.price', function () {
return this.get('restaurant.menu.price');
})
}).create({
restaurant: ObservableObject.create({
menu: ObservableObject.create({
price: 5
})
})
});
});
assert.equal(DepObj.get('price'), 5, 'precond - computed property is correct');
(0, _runloop.run)(function () {
DepObj.set('restaurant.menu.price', 10);
});
assert.equal(DepObj.get('price'), 10, 'cacheable computed properties are invalidated even if no run loop occurred');
(0, _runloop.run)(function () {
DepObj.set('restaurant.menu.price', 20);
});
assert.equal(DepObj.get('price'), 20, 'cacheable computed properties are invalidated after a second get before a run loop');
assert.equal(DepObj.get('price'), 20, 'precond - computed properties remain correct after a run loop');
(0, _runloop.run)(function () {
DepObj.set('restaurant.menu', ObservableObject.create({
price: 15
}));
});
assert.equal(DepObj.get('price'), 15, 'cacheable computed properties are invalidated after a middle property changes');
(0, _runloop.run)(function () {
DepObj.set('restaurant.menu', ObservableObject.create({
price: 25
}));
});
assert.equal(DepObj.get('price'), 25, 'cacheable computed properties are invalidated after a middle property changes again, before a run loop');
};
return _class5;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// OBSERVABLE OBJECTS
//
(0, _internalTestHelpers.moduleFor)('Observable objects & object properties ',
/*#__PURE__*/
function (_AbstractTestCase6) {
(0, _emberBabel.inheritsLoose)(_class6, _AbstractTestCase6);
function _class6() {
return _AbstractTestCase6.apply(this, arguments) || this;
}
var _proto6 = _class6.prototype;
_proto6.beforeEach = function beforeEach() {
object = ObservableObject.extend({
getEach: function () {
var keys = ['normal', 'abnormal'];
var ret = [];
for (var idx = 0; idx < keys.length; idx++) {
ret[ret.length] = this.get(keys[idx]);
}
return ret;
},
newObserver: function () {
this.abnormal = 'changedValueObserved';
},
testObserver: (0, _metal.observer)('normal', function () {
this.abnormal = 'removedObserver';
}),
testArrayObserver: (0, _metal.observer)('normalArray.[]', function () {
this.abnormal = 'notifiedObserver';
})
}).create({
normal: 'value',
abnormal: 'zeroValue',
numberVal: 24,
toggleVal: true,
observedProperty: 'beingWatched',
testRemove: 'observerToBeRemoved',
normalArray: (0, _array.A)([1, 2, 3, 4, 5])
});
};
_proto6['@test incrementProperty and decrementProperty'] = function testIncrementPropertyAndDecrementProperty(assert) {
var newValue = object.incrementProperty('numberVal');
assert.equal(25, newValue, 'numerical value incremented');
object.numberVal = 24;
newValue = object.decrementProperty('numberVal');
assert.equal(23, newValue, 'numerical value decremented');
object.numberVal = 25;
newValue = object.incrementProperty('numberVal', 5);
assert.equal(30, newValue, 'numerical value incremented by specified increment');
object.numberVal = 25;
newValue = object.incrementProperty('numberVal', -5);
assert.equal(20, newValue, 'minus numerical value incremented by specified increment');
object.numberVal = 25;
newValue = object.incrementProperty('numberVal', 0);
assert.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);
assert.equal(25, newValue, 'Attempting to increment by non-numeric values should not increment value');
object.numberVal = 25;
newValue = object.decrementProperty('numberVal', 5);
assert.equal(20, newValue, 'numerical value decremented by specified increment');
object.numberVal = 25;
newValue = object.decrementProperty('numberVal', -5);
assert.equal(30, newValue, 'minus numerical value decremented by specified increment');
object.numberVal = 25;
newValue = object.decrementProperty('numberVal', 0);
assert.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);
assert.equal(25, newValue, 'Attempting to decrement by non-numeric values should not decrement value');
};
_proto6['@test toggle function, should be boolean'] = function testToggleFunctionShouldBeBoolean(assert) {
assert.equal(object.toggleProperty('toggleVal', true, false), object.get('toggleVal'));
assert.equal(object.toggleProperty('toggleVal', true, false), object.get('toggleVal'));
assert.equal(object.toggleProperty('toggleVal', undefined, undefined), object.get('toggleVal'));
};
_proto6['@test should notify array observer when array changes'] = function testShouldNotifyArrayObserverWhenArrayChanges(assert) {
(0, _metal.get)(object, 'normalArray').replace(0, 0, [6]);
assert.equal(object.abnormal, 'notifiedObserver', 'observer should be notified');
};
return _class6;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('object.addObserver()',
/*#__PURE__*/
function (_AbstractTestCase7) {
(0, _emberBabel.inheritsLoose)(_class7, _AbstractTestCase7);
function _class7() {
return _AbstractTestCase7.apply(this, arguments) || this;
}
var _proto7 = _class7.prototype;
_proto7.beforeEach = function beforeEach() {
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';
}
});
};
_proto7['@test should register an observer for a property'] = function testShouldRegisterAnObserverForAProperty(assert) {
ObjectC.addObserver('normal', ObjectC, 'action');
ObjectC.set('normal', 'newValue');
assert.equal(ObjectC.normal1, 'newZeroValue');
};
_proto7['@test should register an observer for a property - Special case of chained property'] = function testShouldRegisterAnObserverForAPropertySpecialCaseOfChainedProperty(assert) {
ObjectC.addObserver('objectE.propertyVal', ObjectC, 'chainedObserver');
ObjectC.objectE.set('propertyVal', 'chainedPropertyValue');
assert.equal('chainedPropertyObserved', ObjectC.normal2);
ObjectC.normal2 = 'dependentValue';
ObjectC.set('objectE', '');
assert.equal('chainedPropertyObserved', ObjectC.normal2);
};
return _class7;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('object.removeObserver()',
/*#__PURE__*/
function (_AbstractTestCase8) {
(0, _emberBabel.inheritsLoose)(_class8, _AbstractTestCase8);
function _class8() {
return _AbstractTestCase8.apply(this, arguments) || this;
}
var _proto8 = _class8.prototype;
_proto8.beforeEach = function beforeEach() {
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
}
});
};
_proto8['@test should unregister an observer for a property'] = function testShouldUnregisterAnObserverForAProperty(assert) {
ObjectD.addObserver('normal', ObjectD, 'addAction');
ObjectD.set('normal', 'newValue');
assert.equal(ObjectD.normal1, 'newZeroValue');
ObjectD.set('normal1', 'zeroValue');
ObjectD.removeObserver('normal', ObjectD, 'addAction');
ObjectD.set('normal', 'newValue');
assert.equal(ObjectD.normal1, 'zeroValue');
};
_proto8["@test should unregister an observer for a property - special case when key has a '.' in it."] = function testShouldUnregisterAnObserverForAPropertySpecialCaseWhenKeyHasAInIt(assert) {
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');
assert.equal('dependentValue', ObjectD.normal2);
ObjectD.set('objectF', '');
assert.equal('dependentValue', ObjectD.normal2);
};
_proto8['@test removing an observer inside of an observer shouldn’t cause any problems'] = function testRemovingAnObserverInsideOfAnObserverShouldnTCauseAnyProblems(assert) {
// 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, _runloop.run)(function () {
ObjectD.set('observableValue', 'hi world');
});
} catch (e) {
encounteredError = true;
}
assert.equal(encounteredError, false);
};
return _class8;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/legacy_1x/mixins/observable/propertyChanges_test", ["ember-babel", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/mixins/observable", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _object, _observable, _metal, _internalTestHelpers) {
"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:
* 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 ObservableObject = _object.default.extend(_observable.default);
var ObjectA;
(0, _internalTestHelpers.moduleFor)('object.propertyChanges',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
ObjectA = ObservableObject.extend({
action: (0, _metal.observer)('foo', function () {
this.set('prop', 'changedPropValue');
}),
notifyAction: (0, _metal.observer)('newFoo', function () {
this.set('newProp', 'changedNewPropValue');
}),
notifyAllAction: (0, _metal.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'
});
};
_proto['@test should observe the changes within the nested begin / end property changes'] = function testShouldObserveTheChangesWithinTheNestedBeginEndPropertyChanges(assert) {
//start the outer nest
ObjectA.beginPropertyChanges(); // Inner nest
ObjectA.beginPropertyChanges();
ObjectA.set('foo', 'changeFooValue');
assert.equal(ObjectA.prop, 'propValue');
ObjectA.endPropertyChanges(); //end inner nest
ObjectA.set('prop', 'changePropValue');
assert.equal(ObjectA.newFoo, 'newFooValue'); //close the outer nest
ObjectA.endPropertyChanges();
assert.equal(ObjectA.prop, 'changedPropValue');
assert.equal(ObjectA.newFoo, 'changedNewFooValue');
};
_proto['@test should observe the changes within the begin and end property changes'] = function testShouldObserveTheChangesWithinTheBeginAndEndPropertyChanges(assert) {
ObjectA.beginPropertyChanges();
ObjectA.set('foo', 'changeFooValue');
assert.equal(ObjectA.prop, 'propValue');
ObjectA.endPropertyChanges();
assert.equal(ObjectA.prop, 'changedPropValue');
};
_proto['@test should indicate that the property of an object has just changed'] = function testShouldIndicateThatThePropertyOfAnObjectHasJustChanged(assert) {
//change the value of foo.
ObjectA.set('foo', 'changeFooValue'); // Indicate the subscribers of foo that the value has just changed
ObjectA.notifyPropertyChange('foo', null); // Values of prop has just changed
assert.equal(ObjectA.prop, 'changedPropValue');
};
_proto['@test should notify that the property of an object has changed'] = function testShouldNotifyThatThePropertyOfAnObjectHasChanged(assert) {
// 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.
assert.equal(ObjectA.newProp, 'changedNewPropValue');
};
_proto['@test should invalidate function property cache when notifyPropertyChange is called'] = function testShouldInvalidateFunctionPropertyCacheWhenNotifyPropertyChangeIsCalled(assert) {
var a = ObservableObject.extend({
b: (0, _metal.computed)({
get: function () {
return this._b;
},
set: function (key, value) {
this._b = value;
return this;
}
}).volatile()
}).create({
_b: null
});
a.set('b', 'foo');
assert.equal(a.get('b'), 'foo', 'should have set the correct value for property b');
a._b = 'bar';
a.notifyPropertyChange('b');
a.set('b', 'foo');
assert.equal(a.get('b'), 'foo', 'should have invalidated the cache so that the newly set value is actually set');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/legacy_1x/system/object/base_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _metal, _object, _internalTestHelpers) {
"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, obj1; // global variables
(0, _internalTestHelpers.moduleFor)('A new EmberObject instance',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
obj = _object.default.create({
foo: 'bar',
total: 12345,
aMethodThatExists: function () {},
aMethodThatReturnsTrue: function () {
return true;
},
aMethodThatReturnsFoobar: function () {
return 'Foobar';
},
aMethodThatReturnsFalse: function () {
return false;
}
});
};
_proto.afterEach = function afterEach() {
obj = undefined;
};
_proto['@test Should return its properties when requested using EmberObject#get'] = function testShouldReturnItsPropertiesWhenRequestedUsingEmberObjectGet(assert) {
assert.equal((0, _metal.get)(obj, 'foo'), 'bar');
assert.equal((0, _metal.get)(obj, 'total'), 12345);
};
_proto['@test Should allow changing of those properties by calling EmberObject#set'] = function testShouldAllowChangingOfThosePropertiesByCallingEmberObjectSet(assert) {
assert.equal((0, _metal.get)(obj, 'foo'), 'bar');
assert.equal((0, _metal.get)(obj, 'total'), 12345);
(0, _metal.set)(obj, 'foo', 'Chunky Bacon');
(0, _metal.set)(obj, 'total', 12);
assert.equal((0, _metal.get)(obj, 'foo'), 'Chunky Bacon');
assert.equal((0, _metal.get)(obj, 'total'), 12);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('EmberObject superclass and subclasses',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2.beforeEach = function beforeEach() {
obj = _object.default.extend({
method1: function () {
return 'hello';
}
});
obj1 = obj.extend();
};
_proto2.afterEach = function afterEach() {
obj = undefined;
obj1 = undefined;
};
_proto2['@test Checking the detect() function on an object and its subclass'] = function testCheckingTheDetectFunctionOnAnObjectAndItsSubclass(assert) {
assert.equal(obj.detect(obj1), true);
assert.equal(obj1.detect(obj), false);
};
_proto2['@test Checking the detectInstance() function on an object and its subclass'] = function testCheckingTheDetectInstanceFunctionOnAnObjectAndItsSubclass(assert) {
assert.ok(_object.default.detectInstance(obj.create()));
assert.ok(obj.detectInstance(obj.create()));
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/legacy_1x/system/object/concatenated_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _metal, _object, _internalTestHelpers) {
"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;
(0, _internalTestHelpers.moduleFor)('EmberObject Concatenated Properties',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
klass = _object.default.extend({
concatenatedProperties: ['values', 'functions'],
values: ['a', 'b', 'c'],
functions: [K]
});
};
_proto['@test concatenates instances'] = function testConcatenatesInstances(assert) {
var obj = klass.create({
values: ['d', 'e', 'f']
});
var values = (0, _metal.get)(obj, 'values');
var expected = ['a', 'b', 'c', 'd', 'e', 'f'];
assert.deepEqual(values, expected, "should concatenate values property (expected: " + expected + ", got: " + values + ")");
};
_proto['@test concatenates subclasses'] = function testConcatenatesSubclasses(assert) {
var subKlass = klass.extend({
values: ['d', 'e', 'f']
});
var obj = subKlass.create();
var values = (0, _metal.get)(obj, 'values');
var expected = ['a', 'b', 'c', 'd', 'e', 'f'];
assert.deepEqual(values, expected, "should concatenate values property (expected: " + expected + ", got: " + values + ")");
};
_proto['@test concatenates reopen'] = function testConcatenatesReopen(assert) {
klass.reopen({
values: ['d', 'e', 'f']
});
var obj = klass.create();
var values = (0, _metal.get)(obj, 'values');
var expected = ['a', 'b', 'c', 'd', 'e', 'f'];
assert.deepEqual(values, expected, "should concatenate values property (expected: " + expected + ", got: " + values + ")");
};
_proto['@test concatenates mixin'] = function testConcatenatesMixin(assert) {
var mixin = {
values: ['d', 'e']
};
var subKlass = klass.extend(mixin, {
values: ['f']
});
var obj = subKlass.create();
var values = (0, _metal.get)(obj, 'values');
var expected = ['a', 'b', 'c', 'd', 'e', 'f'];
assert.deepEqual(values, expected, "should concatenate values property (expected: " + expected + ", got: " + values + ")");
};
_proto['@test concatenates reopen, subclass, and instance'] = function testConcatenatesReopenSubclassAndInstance(assert) {
klass.reopen({
values: ['d']
});
var subKlass = klass.extend({
values: ['e']
});
var obj = subKlass.create({
values: ['f']
});
var values = (0, _metal.get)(obj, 'values');
var expected = ['a', 'b', 'c', 'd', 'e', 'f'];
assert.deepEqual(values, expected, "should concatenate values property (expected: " + expected + ", got: " + values + ")");
};
_proto['@test concatenates subclasses when the values are functions'] = function testConcatenatesSubclassesWhenTheValuesAreFunctions(assert) {
var subKlass = klass.extend({
functions: K
});
var obj = subKlass.create();
var values = (0, _metal.get)(obj, 'functions');
var expected = [K, K];
assert.deepEqual(values, expected, "should concatenate functions property (expected: " + expected + ", got: " + values + ")");
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/mixins/array_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _metal, _object, _array, _internalTestHelpers) {
"use strict";
/*
Implement a basic fake mutable array. This validates that any non-native
enumerable can impl this API.
*/
var TestArray = _object.default.extend(_array.default, {
_content: null,
init: function () {
this._content = this._content || [];
},
// some methods to modify the array so we can test changes. Note that
// arrays can be modified even if they don't implement MutableArray. The
// MutableArray is just a standard API for mutation but not required.
addObject: function (obj) {
var idx = this._content.length;
(0, _metal.arrayContentWillChange)(this, idx, 0, 1);
this._content.push(obj);
(0, _metal.arrayContentDidChange)(this, idx, 0, 1);
},
removeFirst: function () {
(0, _metal.arrayContentWillChange)(this, 0, 1, 0);
this._content.shift();
(0, _metal.arrayContentDidChange)(this, 0, 1, 0);
},
objectAt: function (idx) {
return this._content[idx];
},
length: (0, _metal.computed)(function () {
return this._content.length;
})
});
(0, _internalTestHelpers.moduleFor)('Ember.Array',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test the return value of slice has Ember.Array applied'] = function testTheReturnValueOfSliceHasEmberArrayApplied(assert) {
var x = _object.default.extend(_array.default).create({
length: 0
});
var y = x.slice(1);
assert.equal(_array.default.detect(y), true, 'mixin should be applied');
};
_proto['@test slice supports negative index arguments'] = function testSliceSupportsNegativeIndexArguments(assert) {
var testArray = TestArray.create({
_content: [1, 2, 3, 4]
});
assert.deepEqual(testArray.slice(-2), [3, 4], 'slice(-2)');
assert.deepEqual(testArray.slice(-2, -1), [3], 'slice(-2, -1');
assert.deepEqual(testArray.slice(-2, -2), [], 'slice(-2, -2)');
assert.deepEqual(testArray.slice(-1, -2), [], 'slice(-1, -2)');
assert.deepEqual(testArray.slice(-4, 1), [1], 'slice(-4, 1)');
assert.deepEqual(testArray.slice(-4, 5), [1, 2, 3, 4], 'slice(-4, 5)');
assert.deepEqual(testArray.slice(-4), [1, 2, 3, 4], 'slice(-4)');
assert.deepEqual(testArray.slice(0, -1), [1, 2, 3], 'slice(0, -1)');
assert.deepEqual(testArray.slice(0, -4), [], 'slice(0, -4)');
assert.deepEqual(testArray.slice(0, -3), [1], 'slice(0, -3)');
};
return _class;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// CONTENT DID CHANGE
//
var DummyArray = _object.default.extend(_array.default, {
length: 0,
objectAt: function (idx) {
return 'ITEM-' + idx;
}
});
var obj, observer; // ..........................................................
// NOTIFY ARRAY OBSERVERS
//
(0, _internalTestHelpers.moduleFor)('mixins/array/arrayContent[Will|Did]Change',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2['@test should notify observers of []'] = function testShouldNotifyObserversOf(assert) {
obj = DummyArray.extend({
enumerablePropertyDidChange: (0, _metal.observer)('[]', function () {
this._count++;
})
}).create({
_count: 0
});
assert.equal(obj._count, 0, 'should not have invoked yet');
(0, _metal.arrayContentWillChange)(obj, 0, 1, 1);
(0, _metal.arrayContentDidChange)(obj, 0, 1, 1);
assert.equal(obj._count, 1, 'should have invoked');
};
return _class2;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// NOTIFY CHANGES TO LENGTH
//
(0, _internalTestHelpers.moduleFor)('notify observers of length',
/*#__PURE__*/
function (_AbstractTestCase3) {
(0, _emberBabel.inheritsLoose)(_class3, _AbstractTestCase3);
function _class3() {
return _AbstractTestCase3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3.beforeEach = function beforeEach(assert) {
obj = DummyArray.extend({
lengthDidChange: (0, _metal.observer)('length', function () {
this._after++;
})
}).create({
_after: 0
});
assert.equal(obj._after, 0, 'should not have fired yet');
};
_proto3.afterEach = function afterEach() {
obj = null;
};
_proto3['@test should notify observers when call with no params'] = function testShouldNotifyObserversWhenCallWithNoParams(assert) {
(0, _metal.arrayContentWillChange)(obj);
assert.equal(obj._after, 0);
(0, _metal.arrayContentDidChange)(obj);
assert.equal(obj._after, 1);
} // API variation that included items only
;
_proto3['@test should not notify when passed lengths are same'] = function testShouldNotNotifyWhenPassedLengthsAreSame(assert) {
(0, _metal.arrayContentWillChange)(obj, 0, 1, 1);
assert.equal(obj._after, 0);
(0, _metal.arrayContentDidChange)(obj, 0, 1, 1);
assert.equal(obj._after, 0);
};
_proto3['@test should notify when passed lengths are different'] = function testShouldNotifyWhenPassedLengthsAreDifferent(assert) {
(0, _metal.arrayContentWillChange)(obj, 0, 1, 2);
assert.equal(obj._after, 0);
(0, _metal.arrayContentDidChange)(obj, 0, 1, 2);
assert.equal(obj._after, 1);
};
return _class3;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// NOTIFY ARRAY OBSERVER
//
(0, _internalTestHelpers.moduleFor)('notify array observers',
/*#__PURE__*/
function (_AbstractTestCase4) {
(0, _emberBabel.inheritsLoose)(_class4, _AbstractTestCase4);
function _class4() {
return _AbstractTestCase4.apply(this, arguments) || this;
}
var _proto4 = _class4.prototype;
_proto4.beforeEach = function beforeEach(assert) {
obj = DummyArray.create();
observer = _object.default.extend({
arrayWillChange: function () {
assert.equal(this._before, null); // should only call once
this._before = Array.prototype.slice.call(arguments);
},
arrayDidChange: function () {
assert.equal(this._after, null); // should only call once
this._after = Array.prototype.slice.call(arguments);
}
}).create({
_before: null,
_after: null
});
(0, _metal.addArrayObserver)(obj, observer);
};
_proto4.afterEach = function afterEach() {
obj = observer = null;
};
_proto4['@test should notify array observers when called with no params'] = function testShouldNotifyArrayObserversWhenCalledWithNoParams(assert) {
(0, _metal.arrayContentWillChange)(obj);
assert.deepEqual(observer._before, [obj, 0, -1, -1]);
(0, _metal.arrayContentDidChange)(obj);
assert.deepEqual(observer._after, [obj, 0, -1, -1]);
} // API variation that included items only
;
_proto4['@test should notify when called with same length items'] = function testShouldNotifyWhenCalledWithSameLengthItems(assert) {
(0, _metal.arrayContentWillChange)(obj, 0, 1, 1);
assert.deepEqual(observer._before, [obj, 0, 1, 1]);
(0, _metal.arrayContentDidChange)(obj, 0, 1, 1);
assert.deepEqual(observer._after, [obj, 0, 1, 1]);
};
_proto4['@test should notify when called with diff length items'] = function testShouldNotifyWhenCalledWithDiffLengthItems(assert) {
(0, _metal.arrayContentWillChange)(obj, 0, 2, 1);
assert.deepEqual(observer._before, [obj, 0, 2, 1]);
(0, _metal.arrayContentDidChange)(obj, 0, 2, 1);
assert.deepEqual(observer._after, [obj, 0, 2, 1]);
};
_proto4['@test removing array observer should disable'] = function testRemovingArrayObserverShouldDisable(assert) {
(0, _metal.removeArrayObserver)(obj, observer);
(0, _metal.arrayContentWillChange)(obj);
assert.deepEqual(observer._before, null);
(0, _metal.arrayContentDidChange)(obj);
assert.deepEqual(observer._after, null);
};
return _class4;
}(_internalTestHelpers.AbstractTestCase)); // ..........................................................
// @each
//
var ary;
(0, _internalTestHelpers.moduleFor)('EmberArray.@each support',
/*#__PURE__*/
function (_AbstractTestCase5) {
(0, _emberBabel.inheritsLoose)(_class5, _AbstractTestCase5);
function _class5() {
return _AbstractTestCase5.apply(this, arguments) || this;
}
var _proto5 = _class5.prototype;
_proto5.beforeEach = function beforeEach() {
ary = TestArray.create({
_content: [{
isDone: true,
desc: 'Todo 1'
}, {
isDone: false,
desc: 'Todo 2'
}, {
isDone: true,
desc: 'Todo 3'
}, {
isDone: false,
desc: 'Todo 4'
}]
});
};
_proto5.afterEach = function afterEach() {
ary = null;
};
_proto5['@test adding an object should notify (@each.isDone)'] = function testAddingAnObjectShouldNotifyEachIsDone(assert) {
var called = 0;
var observerObject = _object.default.create({
wasCalled: function () {
called++;
}
});
(0, _metal.addObserver)(ary, '@each.isDone', observerObject, 'wasCalled');
ary.addObject(_object.default.create({
desc: 'foo',
isDone: false
}));
assert.equal(called, 1, 'calls observer when object is pushed');
};
_proto5['@test using @each to observe arrays that does not return objects raise error'] = function testUsingEachToObserveArraysThatDoesNotReturnObjectsRaiseError(assert) {
var called = 0;
var observerObject = _object.default.create({
wasCalled: function () {
called++;
}
});
ary = TestArray.create({
objectAt: function (idx) {
return (0, _metal.get)(this._content[idx], 'desc');
}
});
(0, _metal.addObserver)(ary, '@each.isDone', observerObject, 'wasCalled');
expectAssertion(function () {
ary.addObject(_object.default.create({
desc: 'foo',
isDone: false
}));
}, /When using @each to observe the array/);
assert.equal(called, 0, 'not calls observer when object is pushed');
};
_proto5['@test `objectAt` returns correct object'] = function testObjectAtReturnsCorrectObject(assert) {
var arr = ['first', 'second', 'third', 'fourth'];
assert.equal((0, _metal.objectAt)(arr, 2), 'third');
assert.equal((0, _metal.objectAt)(arr, 4), undefined);
};
_proto5['@test should be clear caches for computed properties that have dependent keys on arrays that are changed after object initialization'] = function testShouldBeClearCachesForComputedPropertiesThatHaveDependentKeysOnArraysThatAreChangedAfterObjectInitialization(assert) {
var obj = _object.default.extend({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'resources', (0, _array.A)());
},
common: (0, _metal.computed)('resources.@each.common', function () {
return (0, _metal.get)((0, _metal.objectAt)((0, _metal.get)(this, 'resources'), 0), 'common');
})
}).create();
(0, _metal.get)(obj, 'resources').pushObject(_object.default.create({
common: 'HI!'
}));
assert.equal('HI!', (0, _metal.get)(obj, 'common'));
(0, _metal.set)((0, _metal.objectAt)((0, _metal.get)(obj, 'resources'), 0), 'common', 'BYE!');
assert.equal('BYE!', (0, _metal.get)(obj, 'common'));
};
_proto5['@test observers that contain @each in the path should fire only once the first time they are accessed'] = function testObserversThatContainEachInThePathShouldFireOnlyOnceTheFirstTimeTheyAreAccessed(assert) {
var count = 0;
var obj = _object.default.extend({
init: function () {
this._super.apply(this, arguments); // Observer does not fire on init
(0, _metal.set)(this, 'resources', (0, _array.A)());
},
commonDidChange: (0, _metal.observer)('resources.@each.common', function () {
return count++;
})
}).create(); // Observer fires second time when new object is added
(0, _metal.get)(obj, 'resources').pushObject(_object.default.create({
common: 'HI!'
})); // Observer fires third time when property on an object is changed
(0, _metal.set)((0, _metal.objectAt)((0, _metal.get)(obj, 'resources'), 0), 'common', 'BYE!');
assert.equal(count, 2, 'observers should only be called once');
};
return _class5;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/mixins/comparable_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/compare", "@ember/-internals/runtime/lib/mixins/comparable", "internal-test-helpers"], function (_emberBabel, _metal, _object, _compare, _comparable, _internalTestHelpers) {
"use strict";
var Rectangle = _object.default.extend(_comparable.default, {
length: 0,
width: 0,
area: function () {
return (0, _metal.get)(this, 'length') * (0, _metal.get)(this, 'width');
},
compare: function (a, b) {
return (0, _compare.default)(a.area(), b.area());
}
});
var r1, r2;
(0, _internalTestHelpers.moduleFor)('Comparable',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
r1 = Rectangle.create({
length: 6,
width: 12
});
r2 = Rectangle.create({
length: 6,
width: 13
});
};
_proto['@test should be comparable and return the correct result'] = function testShouldBeComparableAndReturnTheCorrectResult(assert) {
assert.equal(_comparable.default.detect(r1), true);
assert.equal((0, _compare.default)(r1, r1), 0);
assert.equal((0, _compare.default)(r1, r2), -1);
assert.equal((0, _compare.default)(r2, r1), 1);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/mixins/container_proxy_test", ["ember-babel", "@ember/-internals/owner", "@ember/-internals/container", "@ember/-internals/runtime/lib/mixins/container_proxy", "@ember/-internals/runtime/lib/system/object", "@ember/runloop", "internal-test-helpers"], function (_emberBabel, _owner, _container, _container_proxy, _object, _runloop, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('@ember/-internals/runtime/mixins/container_proxy',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
this.Owner = _object.default.extend(_container_proxy.default);
this.instance = this.Owner.create();
this.registry = new _container.Registry();
this.instance.__container__ = new _container.Container(this.registry, {
owner: this.instance
});
};
_proto['@test provides ownerInjection helper method'] = function testProvidesOwnerInjectionHelperMethod(assert) {
var result = this.instance.ownerInjection();
assert.equal(result[_owner.OWNER], this.instance, 'returns an object with the OWNER symbol');
};
_proto['@test actions queue completes before destruction'] = function testActionsQueueCompletesBeforeDestruction(assert) {
var _this = this;
assert.expect(1);
this.registry.register('service:auth', _object.default.extend({
willDestroy: function () {
assert.ok((0, _owner.getOwner)(this).lookup('service:auth'), 'can still lookup');
}
}));
var service = this.instance.lookup('service:auth');
(0, _runloop.run)(function () {
(0, _runloop.schedule)('actions', service, 'destroy');
_this.instance.destroy();
});
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/mixins/enumerable_test", ["ember-babel", "@ember/-internals/runtime/lib/mixins/enumerable", "@ember/-internals/runtime/lib/system/array_proxy", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _enumerable, _array_proxy, _array, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Enumerable',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should be mixed into A()'] = function testShouldBeMixedIntoA(assert) {
assert.ok(_enumerable.default.detect((0, _array.A)()));
};
_proto['@test should be mixed into ArrayProxy'] = function testShouldBeMixedIntoArrayProxy(assert) {
assert.ok(_enumerable.default.detect(_array_proxy.default.create()));
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/mixins/evented_test", ["ember-babel", "@ember/-internals/runtime/lib/mixins/evented", "@ember/-internals/runtime/lib/system/core_object", "internal-test-helpers"], function (_emberBabel, _evented, _core_object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember.Evented',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test works properly on proxy-ish objects'] = function testWorksProperlyOnProxyIshObjects(assert) {
var eventedProxyObj = _core_object.default.extend(_evented.default, {
unknownProperty: function () {
return true;
}
}).create();
var noop = function () {};
eventedProxyObj.on('foo', noop);
eventedProxyObj.off('foo', noop);
assert.ok(true, 'An assertion was triggered');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/mixins/mutable_enumerable_test", ["ember-babel", "@ember/-internals/runtime/lib/mixins/mutable_enumerable", "@ember/-internals/runtime/lib/system/array_proxy", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _mutable_enumerable, _array_proxy, _array, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('MutableEnumerable',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should be mixed into A()'] = function testShouldBeMixedIntoA(assert) {
assert.ok(_mutable_enumerable.default.detect((0, _array.A)()));
};
_proto['@test should be mixed into ArrayProxy'] = function testShouldBeMixedIntoArrayProxy(assert) {
assert.ok(_mutable_enumerable.default.detect(_array_proxy.default.create()));
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/mixins/observable_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _metal, _object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('mixins/observable',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should be able to use getProperties to get a POJO of provided keys'] = function testShouldBeAbleToUseGetPropertiesToGetAPOJOOfProvidedKeys(assert) {
var obj = _object.default.create({
firstName: 'Steve',
lastName: 'Jobs',
companyName: 'Apple, Inc.'
});
var pojo = obj.getProperties('firstName', 'lastName');
assert.equal('Steve', pojo.firstName);
assert.equal('Jobs', pojo.lastName);
};
_proto['@test should be able to use getProperties with array parameter to get a POJO of provided keys'] = function testShouldBeAbleToUseGetPropertiesWithArrayParameterToGetAPOJOOfProvidedKeys(assert) {
var obj = _object.default.create({
firstName: 'Steve',
lastName: 'Jobs',
companyName: 'Apple, Inc.'
});
var pojo = obj.getProperties(['firstName', 'lastName']);
assert.equal('Steve', pojo.firstName);
assert.equal('Jobs', pojo.lastName);
};
_proto['@test should be able to use setProperties to set multiple properties at once'] = function testShouldBeAbleToUseSetPropertiesToSetMultiplePropertiesAtOnce(assert) {
var obj = _object.default.create({
firstName: 'Steve',
lastName: 'Jobs',
companyName: 'Apple, Inc.'
});
obj.setProperties({
firstName: 'Tim',
lastName: 'Cook'
});
assert.equal('Tim', obj.get('firstName'));
assert.equal('Cook', obj.get('lastName'));
};
_proto['@test calling setProperties completes safely despite exceptions'] = function testCallingSetPropertiesCompletesSafelyDespiteExceptions(assert) {
var exc = new Error('Something unexpected happened!');
var obj = _object.default.extend({
companyName: (0, _metal.computed)({
get: function () {
return 'Apple, Inc.';
},
set: function () {
throw exc;
}
})
}).create({
firstName: 'Steve',
lastName: 'Jobs'
});
var firstNameChangedCount = 0;
(0, _metal.addObserver)(obj, 'firstName', function () {
return firstNameChangedCount++;
});
try {
obj.setProperties({
firstName: 'Tim',
lastName: 'Cook',
companyName: 'Fruit Co., Inc.'
});
} catch (err) {
if (err !== exc) {
throw err;
}
}
assert.equal(firstNameChangedCount, 1, 'firstName should have fired once');
};
_proto['@test should be able to retrieve cached values of computed properties without invoking the computed property'] = function testShouldBeAbleToRetrieveCachedValuesOfComputedPropertiesWithoutInvokingTheComputedProperty(assert) {
var obj = _object.default.extend({
foo: (0, _metal.computed)(function () {
return 'foo';
})
}).create({
bar: 'bar'
});
assert.equal(obj.cacheFor('foo'), undefined, 'should return undefined if no value has been cached');
(0, _metal.get)(obj, 'foo');
assert.equal((0, _metal.get)(obj, 'foo'), 'foo', 'precond - should cache the value');
assert.equal(obj.cacheFor('foo'), 'foo', 'should return the cached value after it is invoked');
assert.equal(obj.cacheFor('bar'), undefined, 'returns undefined if the value is not a computed property');
};
_proto['@test incrementProperty should work even if value is number in string'] = function testIncrementPropertyShouldWorkEvenIfValueIsNumberInString(assert) {
var obj = _object.default.create({
age: '24'
});
obj.incrementProperty('age');
assert.equal(25, obj.get('age'));
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/mixins/promise_proxy_test", ["ember-babel", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object_proxy", "@ember/-internals/runtime/lib/mixins/promise_proxy", "@ember/-internals/runtime/lib/ext/rsvp", "rsvp", "internal-test-helpers"], function (_emberBabel, _runloop, _metal, _object_proxy, _promise_proxy, _rsvp, RSVP, _internalTestHelpers) {
"use strict";
var ObjectPromiseProxy;
(0, _internalTestHelpers.moduleFor)('Ember.PromiseProxy - ObjectProxy',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
ObjectPromiseProxy = _object_proxy.default.extend(_promise_proxy.default);
};
_proto.afterEach = function afterEach() {
RSVP.on('error', _rsvp.onerrorDefault);
};
_proto['@test present on ember namespace'] = function testPresentOnEmberNamespace(assert) {
assert.ok(_promise_proxy.default, 'expected PromiseProxyMixin to exist');
};
_proto['@test no promise, invoking then should raise'] = function testNoPromiseInvokingThenShouldRaise(assert) {
var proxy = ObjectPromiseProxy.create();
assert.throws(function () {
proxy.then(function () {
return this;
}, function () {
return this;
});
}, new RegExp("PromiseProxy's promise must be set"));
};
_proto['@test fulfillment'] = function testFulfillment(assert) {
var value = {
firstName: 'stef',
lastName: 'penner'
};
var deferred = RSVP.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
var didFulfillCount = 0;
var didRejectCount = 0;
proxy.then(function () {
return didFulfillCount++;
}, function () {
return didRejectCount++;
});
assert.equal((0, _metal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content');
assert.equal((0, _metal.get)(proxy, 'reason'), undefined, 'expects the proxy to have no reason');
assert.equal((0, _metal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
assert.equal(didFulfillCount, 0, 'should not yet have been fulfilled');
assert.equal(didRejectCount, 0, 'should not yet have been rejected');
(0, _runloop.run)(deferred, 'resolve', value);
assert.equal(didFulfillCount, 1, 'should have been fulfilled');
assert.equal(didRejectCount, 0, 'should not have been rejected');
assert.equal((0, _metal.get)(proxy, 'content'), value, 'expects the proxy to have content');
assert.equal((0, _metal.get)(proxy, 'reason'), undefined, 'expects the proxy to still have no reason');
assert.equal((0, _metal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is no longer loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), true, 'expects the proxy to indicate that it is fulfilled');
(0, _runloop.run)(deferred, 'resolve', value);
assert.equal(didFulfillCount, 1, 'should still have been only fulfilled once');
assert.equal(didRejectCount, 0, 'should still not have been rejected');
(0, _runloop.run)(deferred, 'reject', value);
assert.equal(didFulfillCount, 1, 'should still have been only fulfilled once');
assert.equal(didRejectCount, 0, 'should still not have been rejected');
assert.equal((0, _metal.get)(proxy, 'content'), value, 'expects the proxy to have still have same content');
assert.equal((0, _metal.get)(proxy, 'reason'), undefined, 'expects the proxy still to have no reason');
assert.equal((0, _metal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is no longer loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), true, 'expects the proxy to indicate that it is fulfilled'); // rest of the promise semantics are tested in directly in RSVP
};
_proto['@test rejection'] = function testRejection(assert) {
var reason = new Error('failure');
var deferred = RSVP.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
var didFulfillCount = 0;
var didRejectCount = 0;
proxy.then(function () {
return didFulfillCount++;
}, function () {
return didRejectCount++;
});
assert.equal((0, _metal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content');
assert.equal((0, _metal.get)(proxy, 'reason'), undefined, 'expects the proxy to have no reason');
assert.equal((0, _metal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
assert.equal(didFulfillCount, 0, 'should not yet have been fulfilled');
assert.equal(didRejectCount, 0, 'should not yet have been rejected');
(0, _runloop.run)(deferred, 'reject', reason);
assert.equal(didFulfillCount, 0, 'should not yet have been fulfilled');
assert.equal(didRejectCount, 1, 'should have been rejected');
assert.equal((0, _metal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content');
assert.equal((0, _metal.get)(proxy, 'reason'), reason, 'expects the proxy to have a reason');
assert.equal((0, _metal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is not longer loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), true, 'expects the proxy to indicate that it is rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
(0, _runloop.run)(deferred, 'reject', reason);
assert.equal(didFulfillCount, 0, 'should stll not yet have been fulfilled');
assert.equal(didRejectCount, 1, 'should still remain rejected');
(0, _runloop.run)(deferred, 'resolve', 1);
assert.equal(didFulfillCount, 0, 'should stll not yet have been fulfilled');
assert.equal(didRejectCount, 1, 'should still remain rejected');
assert.equal((0, _metal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content');
assert.equal((0, _metal.get)(proxy, 'reason'), reason, 'expects the proxy to have a reason');
assert.equal((0, _metal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is not longer loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), true, 'expects the proxy to indicate that it is rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
} // https://github.com/emberjs/ember.js/issues/15694
;
_proto['@test rejection without specifying reason'] = function testRejectionWithoutSpecifyingReason(assert) {
var deferred = RSVP.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
var didFulfillCount = 0;
var didRejectCount = 0;
proxy.then(function () {
return didFulfillCount++;
}, function () {
return didRejectCount++;
});
assert.equal((0, _metal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content');
assert.equal((0, _metal.get)(proxy, 'reason'), undefined, 'expects the proxy to have no reason');
assert.equal((0, _metal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
assert.equal(didFulfillCount, 0, 'should not yet have been fulfilled');
assert.equal(didRejectCount, 0, 'should not yet have been rejected');
(0, _runloop.run)(deferred, 'reject');
assert.equal(didFulfillCount, 0, 'should not yet have been fulfilled');
assert.equal(didRejectCount, 1, 'should have been rejected');
assert.equal((0, _metal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content');
assert.equal((0, _metal.get)(proxy, 'reason'), undefined, 'expects the proxy to have a reason');
assert.equal((0, _metal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is not longer loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), true, 'expects the proxy to indicate that it is rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
};
_proto["@test unhandled rejects still propagate to RSVP.on('error', ...) "] = function testUnhandledRejectsStillPropagateToRSVPOnError(assert) {
assert.expect(1);
RSVP.on('error', onerror);
RSVP.off('error', _rsvp.onerrorDefault);
var expectedReason = new Error('failure');
var deferred = RSVP.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.get('promise');
function onerror(reason) {
assert.equal(reason, expectedReason, 'expected reason');
}
RSVP.on('error', onerror);
RSVP.off('error', _rsvp.onerrorDefault);
(0, _runloop.run)(deferred, 'reject', expectedReason);
RSVP.on('error', _rsvp.onerrorDefault);
RSVP.off('error', onerror);
(0, _runloop.run)(deferred, 'reject', expectedReason);
RSVP.on('error', _rsvp.onerrorDefault);
RSVP.off('error', onerror);
};
_proto['@test should work with promise inheritance'] = function testShouldWorkWithPromiseInheritance(assert) {
var PromiseSubclass =
/*#__PURE__*/
function (_RSVP$Promise) {
(0, _emberBabel.inheritsLoose)(PromiseSubclass, _RSVP$Promise);
function PromiseSubclass() {
return _RSVP$Promise.apply(this, arguments) || this;
}
return PromiseSubclass;
}(RSVP.Promise);
var proxy = ObjectPromiseProxy.create({
promise: new PromiseSubclass(function () {})
});
assert.ok(proxy.then() instanceof PromiseSubclass, 'promise proxy respected inheritance');
};
_proto['@test should reset isFulfilled and isRejected when promise is reset'] = function testShouldResetIsFulfilledAndIsRejectedWhenPromiseIsReset(assert) {
var deferred = _rsvp.default.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
assert.equal((0, _metal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
(0, _runloop.run)(deferred, 'resolve');
assert.equal((0, _metal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is no longer loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), true, 'expects the proxy to indicate that it is fulfilled');
var anotherDeferred = _rsvp.default.defer();
proxy.set('promise', anotherDeferred.promise);
assert.equal((0, _metal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
(0, _runloop.run)(anotherDeferred, 'reject');
assert.equal((0, _metal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is not longer loading');
assert.equal((0, _metal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
assert.equal((0, _metal.get)(proxy, 'isRejected'), true, 'expects the proxy to indicate that it is rejected');
assert.equal((0, _metal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
};
_proto['@test should have content when isFulfilled is set'] = function testShouldHaveContentWhenIsFulfilledIsSet(assert) {
var deferred = _rsvp.default.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.addObserver('isFulfilled', function () {
return assert.equal((0, _metal.get)(proxy, 'content'), true);
});
(0, _runloop.run)(deferred, 'resolve', true);
};
_proto['@test should have reason when isRejected is set'] = function testShouldHaveReasonWhenIsRejectedIsSet(assert) {
var error = new Error('Y U REJECT?!?');
var deferred = _rsvp.default.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.addObserver('isRejected', function () {
return assert.equal((0, _metal.get)(proxy, 'reason'), error);
});
try {
(0, _runloop.run)(deferred, 'reject', error);
} catch (e) {
assert.equal(e, error);
}
};
_proto['@test should not error if promise is resolved after proxy has been destroyed'] = function testShouldNotErrorIfPromiseIsResolvedAfterProxyHasBeenDestroyed(assert) {
var deferred = _rsvp.default.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.then(function () {}, function () {});
(0, _runloop.run)(proxy, 'destroy');
(0, _runloop.run)(deferred, 'resolve', true);
assert.ok(true, 'resolving the promise after the proxy has been destroyed does not raise an error');
};
_proto['@test should not error if promise is rejected after proxy has been destroyed'] = function testShouldNotErrorIfPromiseIsRejectedAfterProxyHasBeenDestroyed(assert) {
var deferred = _rsvp.default.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.then(function () {}, function () {});
(0, _runloop.run)(proxy, 'destroy');
(0, _runloop.run)(deferred, 'reject', 'some reason');
assert.ok(true, 'rejecting the promise after the proxy has been destroyed does not raise an error');
};
_proto['@test promise chain is not broken if promised is resolved after proxy has been destroyed'] = function testPromiseChainIsNotBrokenIfPromisedIsResolvedAfterProxyHasBeenDestroyed(assert) {
var deferred = _rsvp.default.defer();
var expectedValue = {};
var receivedValue;
var didResolveCount = 0;
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.then(function (value) {
receivedValue = value;
didResolveCount++;
}, function () {});
(0, _runloop.run)(proxy, 'destroy');
(0, _runloop.run)(deferred, 'resolve', expectedValue);
assert.equal(didResolveCount, 1, 'callback called');
assert.equal(receivedValue, expectedValue, 'passed value is the value the promise was resolved with');
};
_proto['@test promise chain is not broken if promised is rejected after proxy has been destroyed'] = function testPromiseChainIsNotBrokenIfPromisedIsRejectedAfterProxyHasBeenDestroyed(assert) {
var deferred = _rsvp.default.defer();
var expectedReason = 'some reason';
var receivedReason;
var didRejectCount = 0;
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.then(function () {}, function (reason) {
receivedReason = reason;
didRejectCount++;
});
(0, _runloop.run)(proxy, 'destroy');
(0, _runloop.run)(deferred, 'reject', expectedReason);
assert.equal(didRejectCount, 1, 'callback called');
assert.equal(receivedReason, expectedReason, 'passed reason is the reason the promise was rejected for');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/mixins/target_action_support_test", ["ember-babel", "@ember/-internals/environment", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/mixins/target_action_support", "internal-test-helpers"], function (_emberBabel, _environment, _object, _target_action_support, _internalTestHelpers) {
"use strict";
var originalLookup = _environment.context.lookup;
var lookup;
(0, _internalTestHelpers.moduleFor)('TargetActionSupport',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
_environment.context.lookup = lookup = {};
};
_proto.afterEach = function afterEach() {
_environment.context.lookup = originalLookup;
};
_proto['@test it should return false if no target or action are specified'] = function testItShouldReturnFalseIfNoTargetOrActionAreSpecified(assert) {
assert.expect(1);
var obj = _object.default.extend(_target_action_support.default).create();
assert.ok(false === obj.triggerAction(), 'no target or action was specified');
};
_proto['@test it should support actions specified as strings'] = function testItShouldSupportActionsSpecifiedAsStrings(assert) {
assert.expect(2);
var obj = _object.default.extend(_target_action_support.default).create({
target: _object.default.create({
anEvent: function () {
assert.ok(true, 'anEvent method was called');
}
}),
action: 'anEvent'
});
assert.ok(true === obj.triggerAction(), 'a valid target and action were specified');
};
_proto['@test it should invoke the send() method on objects that implement it'] = function testItShouldInvokeTheSendMethodOnObjectsThatImplementIt(assert) {
assert.expect(3);
var obj = _object.default.extend(_target_action_support.default).create({
target: _object.default.create({
send: function (evt, context) {
assert.equal(evt, 'anEvent', 'send() method was invoked with correct event name');
assert.equal(context, obj, 'send() method was invoked with correct context');
}
}),
action: 'anEvent'
});
assert.ok(true === obj.triggerAction(), 'a valid target and action were specified');
};
_proto['@test it should find targets specified using a property path'] = function testItShouldFindTargetsSpecifiedUsingAPropertyPath(assert) {
assert.expect(2);
var Test = {};
lookup.Test = Test;
Test.targetObj = _object.default.create({
anEvent: function () {
assert.ok(true, 'anEvent method was called on global object');
}
});
var myObj = _object.default.extend(_target_action_support.default).create({
target: 'Test.targetObj',
action: 'anEvent'
});
assert.ok(true === myObj.triggerAction(), 'a valid target and action were specified');
};
_proto['@test it should use an actionContext object specified as a property on the object'] = function testItShouldUseAnActionContextObjectSpecifiedAsAPropertyOnTheObject(assert) {
assert.expect(2);
var obj = _object.default.extend(_target_action_support.default).create({
action: 'anEvent',
actionContext: {},
target: _object.default.create({
anEvent: function (ctx) {
assert.ok(obj.actionContext === ctx, 'anEvent method was called with the expected context');
}
})
});
assert.ok(true === obj.triggerAction(), 'a valid target and action were specified');
};
_proto['@test it should find an actionContext specified as a property path'] = function testItShouldFindAnActionContextSpecifiedAsAPropertyPath(assert) {
assert.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) {
assert.ok(Test.aContext === ctx, 'anEvent method was called with the expected context');
}
})
});
assert.ok(true === obj.triggerAction(), 'a valid target and action were specified');
};
_proto['@test it should use the target specified in the argument'] = function testItShouldUseTheTargetSpecifiedInTheArgument(assert) {
assert.expect(2);
var targetObj = _object.default.create({
anEvent: function () {
assert.ok(true, 'anEvent method was called');
}
});
var obj = _object.default.extend(_target_action_support.default).create({
action: 'anEvent'
});
assert.ok(true === obj.triggerAction({
target: targetObj
}), 'a valid target and action were specified');
};
_proto['@test it should use the action specified in the argument'] = function testItShouldUseTheActionSpecifiedInTheArgument(assert) {
assert.expect(2);
var obj = _object.default.extend(_target_action_support.default).create({
target: _object.default.create({
anEvent: function () {
assert.ok(true, 'anEvent method was called');
}
})
});
assert.ok(true === obj.triggerAction({
action: 'anEvent'
}), 'a valid target and action were specified');
};
_proto['@test it should use the actionContext specified in the argument'] = function testItShouldUseTheActionContextSpecifiedInTheArgument(assert) {
assert.expect(2);
var context = {};
var obj = _object.default.extend(_target_action_support.default).create({
target: _object.default.create({
anEvent: function (ctx) {
assert.ok(context === ctx, 'anEvent method was called with the expected context');
}
}),
action: 'anEvent'
});
assert.ok(true === obj.triggerAction({
actionContext: context
}), 'a valid target and action were specified');
};
_proto['@test it should allow multiple arguments from actionContext'] = function testItShouldAllowMultipleArgumentsFromActionContext(assert) {
assert.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) {
assert.ok(first === param1, 'anEvent method was called with the expected first argument');
assert.ok(second === param2, 'anEvent method was called with the expected second argument');
}
}),
action: 'anEvent'
});
assert.ok(true === obj.triggerAction({
actionContext: [param1, param2]
}), 'a valid target and action were specified');
};
_proto['@test it should use a null value specified in the actionContext argument'] = function testItShouldUseANullValueSpecifiedInTheActionContextArgument(assert) {
assert.expect(2);
var obj = _object.default.extend(_target_action_support.default).create({
target: _object.default.create({
anEvent: function (ctx) {
assert.ok(null === ctx, 'anEvent method was called with the expected context (null)');
}
}),
action: 'anEvent'
});
assert.ok(true === obj.triggerAction({
actionContext: null
}), 'a valid target and action were specified');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/mutable-array/addObject-test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _metal, _internalTestHelpers, _array) {
"use strict";
var AddObjectTest =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(AddObjectTest, _AbstractTestCase);
function AddObjectTest() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = AddObjectTest.prototype;
_proto['@test should return receiver'] = function testShouldReturnReceiver() {
var before = (0, _array.newFixture)(3);
var obj = this.newObject(before);
this.assert.equal(obj.addObject(before[1]), obj, 'should return receiver');
};
_proto['@test [A,B].addObject(C) => [A,B,C] + notify'] = function testABAddObjectCABCNotify() {
var before = (0, _array.newFixture)(2);
var item = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
}
};
_proto['@test [A,B,C].addObject(A) => [A,B,C] + NO notify'] = function testABCAddObjectAABCNONotify() {
var before = (0, _array.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
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
this.assert.equal(observer.validate('[]'), false, 'should NOT have notified []');
this.assert.equal(observer.validate('@each'), false, 'should NOT have notified @each');
this.assert.equal(observer.validate('length'), false, 'should NOT have notified length');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
}
};
return AddObjectTest;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('addObject', AddObjectTest, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/clear-test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _metal, _internalTestHelpers, _array) {
"use strict";
var ClearTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(ClearTests, _AbstractTestCase);
function ClearTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = ClearTests.prototype;
_proto['@test [].clear() => [] + notify'] = function testClearNotify() {
var before = [];
var after = [];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject');
/* Prime the cache */
this.assert.equal(obj.clear(), obj, 'return self');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.validate('[]'), false, 'should NOT have notified [] once');
this.assert.equal(observer.validate('@each'), false, 'should NOT have notified @each once');
this.assert.equal(observer.validate('length'), false, 'should NOT have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
};
_proto['@test [X].clear() => [] + notify'] = function testXClearNotify() {
var obj, before, after, observer;
before = (0, _array.newFixture)(1);
after = [];
obj = this.newObject(before);
observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject');
/* Prime the cache */
this.assert.equal(obj.clear(), obj, 'return self');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
};
return ClearTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('clear', ClearTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/insertAt-test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _metal, _internalTestHelpers, _array) {
"use strict";
var InsertAtTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(InsertAtTests, _AbstractTestCase);
function InsertAtTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = InsertAtTests.prototype;
_proto['@test [].insertAt(0, X) => [X] + notify'] = function testInsertAt0XXNotify() {
var after = (0, _array.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]);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] did change once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each did change once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length did change once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject did change once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject did change once');
};
_proto['@test [].insertAt(200,X) => OUT_OF_RANGE_EXCEPTION exception'] = function testInsertAt200XOUT_OF_RANGE_EXCEPTIONException() {
var obj = this.newObject([]);
var that = this;
this.assert.throws(function () {
return obj.insertAt(200, that.newFixture(1)[0]);
}, Error);
};
_proto['@test [A].insertAt(0, X) => [X,A] + notify'] = function testAInsertAt0XXANotify() {
var item = (0, _array.newFixture)(1)[0];
var before = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
};
_proto['@test [A].insertAt(1, X) => [A,X] + notify'] = function testAInsertAt1XAXNotify() {
var item = (0, _array.newFixture)(1)[0];
var before = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
};
_proto['@test [A].insertAt(200,X) => OUT_OF_RANGE exception'] = function testAInsertAt200XOUT_OF_RANGEException() {
var obj = this.newObject((0, _array.newFixture)(1));
var that = this;
this.assert.throws(function () {
return obj.insertAt(200, that.newFixture(1)[0]);
}, Error);
};
_proto['@test [A,B,C].insertAt(0,X) => [X,A,B,C] + notify'] = function testABCInsertAt0XXABCNotify() {
var item = (0, _array.newFixture)(1)[0];
var before = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
};
_proto['@test [A,B,C].insertAt(1,X) => [A,X,B,C] + notify'] = function testABCInsertAt1XAXBCNotify() {
var item = (0, _array.newFixture)(1)[0];
var before = (0, _array.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');
var objectAtCalls = [];
var objectAt = obj.objectAt;
obj.objectAt = function (ix) {
objectAtCalls.push(ix);
return objectAt.call(obj, ix);
};
obj.getProperties('firstObject', 'lastObject');
/* Prime the cache */
objectAtCalls.splice(0, objectAtCalls.length);
obj.insertAt(1, item);
this.assert.deepEqual(objectAtCalls, [], 'objectAt is not called when only inserting items');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
};
_proto['@test [A,B,C].insertAt(3,X) => [A,B,C,X] + notify'] = function testABCInsertAt3XABCXNotify() {
var item = (0, _array.newFixture)(1)[0];
var before = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
};
return InsertAtTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('instertAt', InsertAtTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/popObject-test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _metal, _internalTestHelpers, _array) {
"use strict";
var PopObjectTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(PopObjectTests, _AbstractTestCase);
function PopObjectTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = PopObjectTests.prototype;
_proto['@test [].popObject() => [] + returns undefined + NO notify'] = function testPopObjectReturnsUndefinedNONotify() {
var obj = this.newObject([]);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject');
/* Prime the cache */
this.assert.equal(obj.popObject(), undefined, 'popObject results');
this.assert.deepEqual(this.toArray(obj), [], 'post item results');
this.assert.equal(observer.validate('[]'), false, 'should NOT have notified []');
this.assert.equal(observer.validate('@each'), false, 'should NOT have notified @each');
this.assert.equal(observer.validate('length'), false, 'should NOT have notified length');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
};
_proto['@test [X].popObject() => [] + notify'] = function testXPopObjectNotify() {
var before = (0, _array.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();
this.assert.equal(ret, before[0], 'return object');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
};
_proto['@test [A,B,C].popObject() => [A,B] + notify'] = function testABCPopObjectABNotify() {
var before = (0, _array.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();
this.assert.equal(ret, before[2], 'return object');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
};
return PopObjectTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('popObject', PopObjectTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/pushObject-test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _metal, _internalTestHelpers, _array) {
"use strict";
var PushObjectTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(PushObjectTests, _AbstractTestCase);
function PushObjectTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = PushObjectTests.prototype;
_proto['@test returns pushed object'] = function testReturnsPushedObject() {
var exp = (0, _array.newFixture)(1)[0];
var obj = this.newObject([]);
this.assert.equal(obj.pushObject(exp), exp, 'should return pushed object');
};
_proto['@test [].pushObject(X) => [X] + notify'] = function testPushObjectXXNotify() {
var before = [];
var after = (0, _array.newFixture)(1);
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject');
/* Prime the cache */
obj.pushObject(after[0]);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
};
_proto['@test [A,B,C].pushObject(X) => [A,B,C,X] + notify'] = function testABCPushObjectXABCXNotify() {
var before = (0, _array.newFixture)(3);
var item = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
};
_proto['@test [A,B,C,C].pushObject(A) => [A,B,C,C] + notify'] = function testABCCPushObjectAABCCNotify() {
var before = (0, _array.newFixture)(3);
var item = before[2]; // note same object as current tail. should end up twice
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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
this.assert.equal(observer.validate('lastObject'), true, 'should have notified lastObject');
};
return PushObjectTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('pushObject', PushObjectTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/pushObjects-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var PushObjectsTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(PushObjectsTests, _AbstractTestCase);
function PushObjectsTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = PushObjectsTests.prototype;
_proto['@test should raise exception if not Ember.Enumerable is passed to pushObjects'] = function testShouldRaiseExceptionIfNotEmberEnumerableIsPassedToPushObjects() {
var obj = this.newObject([]);
expectAssertion(function () {
return obj.pushObjects('string');
});
};
return PushObjectsTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('pushObjects', PushObjectsTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/removeAt-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array", "@ember/-internals/runtime/lib/mixins/array", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _array, _array2, _metal) {
"use strict";
var RemoveAtTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(RemoveAtTests, _AbstractTestCase);
function RemoveAtTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = RemoveAtTests.prototype;
_proto['@test removeAt([X], 0) => [] + notify'] = function testRemoveAtX0Notify() {
var before = (0, _array.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 */
this.assert.equal((0, _array2.removeAt)(obj, 0), obj, 'return self');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
};
_proto['@test removeAt([], 200) => OUT_OF_RANGE_EXCEPTION exception'] = function testRemoveAt200OUT_OF_RANGE_EXCEPTIONException() {
var obj = this.newObject([]);
this.assert.throws(function () {
return (0, _array2.removeAt)(obj, 200);
}, Error);
};
_proto['@test removeAt([A,B], 0) => [B] + notify'] = function testRemoveAtAB0BNotify() {
var before = (0, _array.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 */
this.assert.equal((0, _array2.removeAt)(obj, 0), obj, 'return self');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
};
_proto['@test removeAt([A,B], 1) => [A] + notify'] = function testRemoveAtAB1ANotify() {
var before = (0, _array.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 */
this.assert.equal((0, _array2.removeAt)(obj, 1), obj, 'return self');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
};
_proto['@test removeAt([A,B,C], 1) => [A,C] + notify'] = function testRemoveAtABC1ACNotify() {
var before = (0, _array.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 */
this.assert.equal((0, _array2.removeAt)(obj, 1), obj, 'return self');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
};
_proto['@test removeAt([A,B,C,D], 1,2) => [A,D] + notify'] = function testRemoveAtABCD12ADNotify() {
var before = (0, _array.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 */
this.assert.equal((0, _array2.removeAt)(obj, 1, 2), obj, 'return self');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
};
_proto['@test [A,B,C,D].removeAt(1,2) => [A,D] + notify'] = function testABCDRemoveAt12ADNotify() {
var obj, before, after, observer;
before = (0, _array.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 */
this.assert.equal(obj.removeAt(1, 2), obj, 'return self');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
};
return RemoveAtTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('removeAt', RemoveAtTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/removeObject-test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _metal, _internalTestHelpers, _array) {
"use strict";
var RemoveObjectTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(RemoveObjectTests, _AbstractTestCase);
function RemoveObjectTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = RemoveObjectTests.prototype;
_proto['@test should return receiver'] = function testShouldReturnReceiver() {
var before = (0, _array.newFixture)(3);
var obj = this.newObject(before);
this.assert.equal(obj.removeObject(before[1]), obj, 'should return receiver');
};
_proto['@test [A,B,C].removeObject(B) => [A,C] + notify'] = function testABCRemoveObjectBACNotify() {
var before = (0, _array.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]);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
}
};
_proto['@test [A,B,C].removeObject(D) => [A,B,C]'] = function testABCRemoveObjectDABC() {
var before = (0, _array.newFixture)(3);
var after = before;
var item = (0, _array.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
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
this.assert.equal(observer.validate('[]'), false, 'should NOT have notified []');
this.assert.equal(observer.validate('@each'), false, 'should NOT have notified @each');
this.assert.equal(observer.validate('length'), false, 'should NOT have notified length');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
}
};
return RemoveObjectTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('removeObject', RemoveObjectTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/removeObjects-test", ["ember-babel", "@ember/-internals/metal", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array", "@ember/-internals/runtime/lib/mixins/array"], function (_emberBabel, _metal, _internalTestHelpers, _array, _array2) {
"use strict";
var RemoveObjectsTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(RemoveObjectsTests, _AbstractTestCase);
function RemoveObjectsTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = RemoveObjectsTests.prototype;
_proto['@test should return receiver'] = function testShouldReturnReceiver() {
var before = (0, _array2.A)((0, _array.newFixture)(3));
var obj = before;
this.assert.equal(obj.removeObjects(before[1]), obj, 'should return receiver');
};
_proto['@test [A,B,C].removeObjects([B]) => [A,C] + notify'] = function testABCRemoveObjectsBACNotify() {
var before = (0, _array2.A)((0, _array.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]]);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
};
_proto['@test [{A},{B},{C}].removeObjects([{B}]) => [{A},{C}] + notify'] = function testABCRemoveObjectsBACNotify() {
var before = (0, _array2.A)((0, _array.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]]);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
};
_proto['@test [A,B,C].removeObjects([A,B]) => [C] + notify'] = function testABCRemoveObjectsABCNotify() {
var before = (0, _array2.A)((0, _array.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]]);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
};
_proto['@test [{A},{B},{C}].removeObjects([{A},{B}]) => [{C}] + notify'] = function testABCRemoveObjectsABCNotify() {
var before = (0, _array2.A)((0, _array.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]]);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
};
_proto['@test [A,B,C].removeObjects([A,B,C]) => [] + notify'] = function testABCRemoveObjectsABCNotify() {
var before = (0, _array2.A)((0, _array.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]]);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject');
}
};
_proto['@test [{A},{B},{C}].removeObjects([{A},{B},{C}]) => [] + notify'] = function testABCRemoveObjectsABCNotify() {
var before = (0, _array2.A)((0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
this.assert.equal(observer.validate('lastObject'), 1, 'should have notified lastObject');
}
};
_proto['@test [A,B,C].removeObjects([D]) => [A,B,C]'] = function testABCRemoveObjectsDABC() {
var before = (0, _array2.A)((0, _array.newFixture)(3));
var after = before;
var item = (0, _array.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
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
this.assert.equal(observer.validate('[]'), false, 'should NOT have notified []');
this.assert.equal(observer.validate('length'), false, 'should NOT have notified length');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
};
return RemoveObjectsTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('removeObjects', RemoveObjectsTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/replace-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _array) {
"use strict";
var ReplaceTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(ReplaceTests, _AbstractTestCase);
function ReplaceTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = ReplaceTests.prototype;
_proto["@test [].replace(0,0,'X') => ['X'] + notify"] = function testReplace00XXNotify() {
var exp = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), exp, 'post item results');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
};
_proto['@test [].replace(0,0,"X") => ["X"] + avoid calling objectAt and notifying fistObject/lastObject when not in cache'] = function testReplace00XXAvoidCallingObjectAtAndNotifyingFistObjectLastObjectWhenNotInCache() {
var obj, exp, observer;
var called = 0;
exp = (0, _array.newFixture)(1);
obj = this.newObject([]);
obj.objectAt = function () {
called++;
};
observer = this.newObserver(obj, 'firstObject', 'lastObject');
obj.replace(0, 0, exp);
this.assert.equal(called, 0, 'should NOT have called objectAt upon replace when firstObject/lastObject are not cached');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject since not cached');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject since not cached');
};
_proto['@test [A,B,C,D].replace(1,2,X) => [A,X,D] + notify'] = function testABCDReplace12XAXDNotify() {
var before = (0, _array.newFixture)(4);
var replace = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
};
_proto['@test [A,B,C,D].replace(1,2,[X,Y]) => [A,X,Y,D] + notify'] = function testABCDReplace12XYAXYDNotify() {
var before = (0, _array.newFixture)(4);
var replace = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.validate('length'), false, 'should NOT have notified length');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
};
_proto['@test [A,B].replace(1,0,[X,Y]) => [A,X,Y,B] + notify'] = function testABReplace10XYAXYBNotify() {
var before = (0, _array.newFixture)(2);
var replace = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
};
_proto['@test [A,B,C,D].replace(2,2) => [A,B] + notify'] = function testABCDReplace22ABNotify() {
var before = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
};
_proto['@test [A,B,C,D].replace(-1,1) => [A,B,C] + notify'] = function testABCDReplace11ABCNotify() {
var before = (0, _array.newFixture)(4);
var after = [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.replace(-1, 1);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
};
_proto['@test Adding object should notify array observer'] = function testAddingObjectShouldNotifyArrayObserver() {
var fixtures = (0, _array.newFixture)(4);
var obj = this.newObject(fixtures);
var observer = this.newObserver(obj).observeArray(obj);
var item = (0, _array.newFixture)(1)[0];
obj.replace(2, 2, [item]);
this.assert.deepEqual(observer._before, [obj, 2, 2, 1], 'before');
this.assert.deepEqual(observer._after, [obj, 2, 2, 1], 'after');
};
return ReplaceTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('replace', ReplaceTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/reverseObjects-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _array, _metal) {
"use strict";
var ReverseObjectsTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(ReverseObjectsTests, _AbstractTestCase);
function ReverseObjectsTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = ReverseObjectsTests.prototype;
_proto['@test [A,B,C].reverseObjects() => [] + notify'] = function testABCReverseObjectsNotify() {
var before = (0, _array.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 */
this.assert.equal(obj.reverseObjects(), obj, 'return self');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 0, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
};
return ReverseObjectsTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('reverseObjects', ReverseObjectsTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/setObjects-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _array, _metal) {
"use strict";
var SetObjectsTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(SetObjectsTests, _AbstractTestCase);
function SetObjectsTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = SetObjectsTests.prototype;
_proto['@test [A,B,C].setObjects([]) = > [] + notify'] = function testABCSetObjectsNotify() {
var before = (0, _array.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 */
this.assert.equal(obj.setObjects(after), obj, 'return self');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
};
_proto['@test [A,B,C].setObjects([D, E, F, G]) = > [D, E, F, G] + notify'] = function testABCSetObjectsDEFGDEFGNotify() {
var before = (0, _array.newFixture)(3);
var after = (0, _array.newFixture)(4);
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject');
/* Prime the cache */
this.assert.equal(obj.setObjects(after), obj, 'return self');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
};
return SetObjectsTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('setObjects', SetObjectsTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/shiftObject-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/runtime/tests/helpers/array", "@ember/-internals/metal"], function (_emberBabel, _internalTestHelpers, _array, _metal) {
"use strict";
var ShiftObjectTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(ShiftObjectTests, _AbstractTestCase);
function ShiftObjectTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = ShiftObjectTests.prototype;
_proto['@test [].shiftObject() => [] + returns undefined + NO notify'] = function testShiftObjectReturnsUndefinedNONotify() {
var before = [];
var after = [];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject');
/* Prime the cache */
this.assert.equal(obj.shiftObject(), undefined);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.validate('[]', undefined, 1), false, 'should NOT have notified [] once');
this.assert.equal(observer.validate('@each', undefined, 1), false, 'should NOT have notified @each once');
this.assert.equal(observer.validate('length', undefined, 1), false, 'should NOT have notified length once');
this.assert.equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
};
_proto['@test [X].shiftObject() => [] + notify'] = function testXShiftObjectNotify() {
var before = (0, _array.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 */
this.assert.equal(obj.shiftObject(), before[0], 'should return object');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
};
_proto['@test [A,B,C].shiftObject() => [B,C] + notify'] = function testABCShiftObjectBCNotify() {
var before = (0, _array.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 */
this.assert.equal(obj.shiftObject(), before[0], 'should return object');
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
};
return ShiftObjectTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('shiftObject', ShiftObjectTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/unshiftObject-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _metal, _array) {
"use strict";
var UnshiftObjectTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(UnshiftObjectTests, _AbstractTestCase);
function UnshiftObjectTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = UnshiftObjectTests.prototype;
_proto['@test returns unshifted object'] = function testReturnsUnshiftedObject() {
var obj = this.newObject([]);
var item = (0, _array.newFixture)(1)[0];
this.assert.equal(obj.unshiftObject(item), item, 'should return unshifted object');
};
_proto['@test [].unshiftObject(X) => [X] + notify'] = function testUnshiftObjectXXNotify() {
var before = [];
var item = (0, _array.newFixture)(1)[0];
var after = [item];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject');
/* Prime the cache */
obj.unshiftObject(item);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
};
_proto['@test [A,B,C].unshiftObject(X) => [X,A,B,C] + notify'] = function testABCUnshiftObjectXXABCNotify() {
var before = (0, _array.newFixture)(3);
var item = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
};
_proto['@test [A,B,C].unshiftObject(A) => [A,A,B,C] + notify'] = function testABCUnshiftObjectAAABCNotify() {
var before = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), true, 'should have notified firstObject');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
};
return UnshiftObjectTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('unshiftObject', UnshiftObjectTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/mutable-array/unshiftObjects-test", ["ember-babel", "internal-test-helpers", "@ember/-internals/metal", "@ember/-internals/runtime/tests/helpers/array"], function (_emberBabel, _internalTestHelpers, _metal, _array) {
"use strict";
var UnshiftObjectsTests =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(UnshiftObjectsTests, _AbstractTestCase);
function UnshiftObjectsTests() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = UnshiftObjectsTests.prototype;
_proto['@test returns receiver'] = function testReturnsReceiver() {
var obj = this.newObject([]);
var items = (0, _array.newFixture)(3);
this.assert.equal(obj.unshiftObjects(items), obj, 'should return receiver');
};
_proto['@test [].unshiftObjects([A,B,C]) => [A,B,C] + notify'] = function testUnshiftObjectsABCABCNotify() {
var before = [];
var items = (0, _array.newFixture)(3);
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject');
/* Prime the cache */
obj.unshiftObjects(items);
this.assert.deepEqual(this.toArray(obj), items, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), items.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
};
_proto['@test [A,B,C].unshiftObjects([X,Y]) => [X,Y,A,B,C] + notify'] = function testABCUnshiftObjectsXYXYABCNotify() {
var before = (0, _array.newFixture)(3);
var items = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
};
_proto['@test [A,B,C].unshiftObjects([A,B]) => [A,B,A,B,C] + notify'] = function testABCUnshiftObjectsABABABCNotify() {
var before = (0, _array.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);
this.assert.deepEqual(this.toArray(obj), after, 'post item results');
this.assert.equal((0, _metal.get)(obj, 'length'), after.length, 'length');
this.assert.equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
this.assert.equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
this.assert.equal(observer.timesCalled('length'), 1, 'should have notified length once');
this.assert.equal(observer.validate('firstObject'), true, 'should NOT have notified firstObject');
this.assert.equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
};
return UnshiftObjectsTests;
}(_internalTestHelpers.AbstractTestCase);
(0, _array.runArrayTests)('unshiftObjects', UnshiftObjectsTests, 'MutableArray', 'NativeArray', 'ArrayProxy');
});
enifed("@ember/-internals/runtime/tests/system/array_proxy/arranged_content_test", ["ember-babel", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/array_proxy", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _runloop, _metal, _array_proxy, _array, _internalTestHelpers) {
"use strict";
var array;
(0, _internalTestHelpers.moduleFor)('ArrayProxy - arrangedContent',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
(0, _runloop.run)(function () {
array = _array_proxy.default.extend({
arrangedContent: (0, _metal.computed)('content.[]', function () {
var content = this.get('content');
return content && (0, _array.A)(content.slice().sort(function (a, b) {
if (a == null) {
a = -1;
}
if (b == null) {
b = -1;
}
return b - a;
}));
})
}).create({
content: (0, _array.A)([1, 2, 4, 5])
});
});
};
_proto.afterEach = function afterEach() {
(0, _runloop.run)(function () {
return array.destroy();
});
};
_proto['@test compact - returns arrangedContent without nulls and undefined'] = function testCompactReturnsArrangedContentWithoutNullsAndUndefined(assert) {
(0, _runloop.run)(function () {
return array.set('content', (0, _array.A)([1, 3, null, 2, undefined]));
});
assert.deepEqual(array.compact(), [3, 2, 1]);
};
_proto['@test indexOf - returns index of object in arrangedContent'] = function testIndexOfReturnsIndexOfObjectInArrangedContent(assert) {
assert.equal(array.indexOf(4), 1, 'returns arranged index');
};
_proto['@test lastIndexOf - returns last index of object in arrangedContent'] = function testLastIndexOfReturnsLastIndexOfObjectInArrangedContent(assert) {
array.get('content').pushObject(4);
assert.equal(array.lastIndexOf(4), 2, 'returns last arranged index');
};
_proto['@test objectAt - returns object at index in arrangedContent'] = function testObjectAtReturnsObjectAtIndexInArrangedContent(assert) {
assert.equal((0, _metal.objectAt)(array, 1), 4, 'returns object at index');
} // Not sure if we need a specific test for it, since it's internal
;
_proto['@test objectAtContent - returns object at index in arrangedContent'] = function testObjectAtContentReturnsObjectAtIndexInArrangedContent(assert) {
assert.equal(array.objectAtContent(1), 4, 'returns object at index');
};
_proto['@test objectsAt - returns objects at indices in arrangedContent'] = function testObjectsAtReturnsObjectsAtIndicesInArrangedContent(assert) {
assert.deepEqual(array.objectsAt([0, 2, 4]), [5, 2, undefined], 'returns objects at indices');
};
_proto['@test replace - mutating an arranged ArrayProxy is not allowed'] = function testReplaceMutatingAnArrangedArrayProxyIsNotAllowed() {
expectAssertion(function () {
array.replace(0, 0, [3]);
}, /Mutating an arranged ArrayProxy is not allowed/);
};
_proto['@test replaceContent - does a standard array replace on content'] = function testReplaceContentDoesAStandardArrayReplaceOnContent(assert) {
(0, _runloop.run)(function () {
return array.replaceContent(1, 2, [3]);
});
assert.deepEqual(array.get('content'), [1, 3, 5]);
};
_proto['@test slice - returns a slice of the arrangedContent'] = function testSliceReturnsASliceOfTheArrangedContent(assert) {
assert.deepEqual(array.slice(1, 3), [4, 2], 'returns sliced arrangedContent');
};
_proto['@test toArray - returns copy of arrangedContent'] = function testToArrayReturnsCopyOfArrangedContent(assert) {
assert.deepEqual(array.toArray(), [5, 4, 2, 1]);
};
_proto['@test without - returns arrangedContent without object'] = function testWithoutReturnsArrangedContentWithoutObject(assert) {
assert.deepEqual(array.without(2), [5, 4, 1], 'returns arranged without object');
};
_proto['@test lastObject - returns last arranged object'] = function testLastObjectReturnsLastArrangedObject(assert) {
assert.equal(array.get('lastObject'), 1, 'returns last arranged object');
};
_proto['@test firstObject - returns first arranged object'] = function testFirstObjectReturnsFirstArrangedObject(assert) {
assert.equal(array.get('firstObject'), 5, 'returns first arranged object');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('ArrayProxy - arrangedContent matching content',
/*#__PURE__*/
function (_AbstractTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _AbstractTestCase2);
function _class2() {
return _AbstractTestCase2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2.beforeEach = function beforeEach() {
(0, _runloop.run)(function () {
array = _array_proxy.default.create({
content: (0, _array.A)([1, 2, 4, 5])
});
});
};
_proto2.afterEach = function afterEach() {
(0, _runloop.run)(function () {
array.destroy();
});
};
_proto2['@test insertAt - inserts object at specified index'] = function testInsertAtInsertsObjectAtSpecifiedIndex(assert) {
(0, _runloop.run)(function () {
array.insertAt(2, 3);
});
assert.deepEqual(array.get('content'), [1, 2, 3, 4, 5]);
};
_proto2['@test replace - does a standard array replace'] = function testReplaceDoesAStandardArrayReplace(assert) {
(0, _runloop.run)(function () {
array.replace(1, 2, [3]);
});
assert.deepEqual(array.get('content'), [1, 3, 5]);
};
_proto2['@test reverseObjects - reverses content'] = function testReverseObjectsReversesContent(assert) {
(0, _runloop.run)(function () {
array.reverseObjects();
});
assert.deepEqual(array.get('content'), [5, 4, 2, 1]);
};
return _class2;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('ArrayProxy - arrangedContent with transforms',
/*#__PURE__*/
function (_AbstractTestCase3) {
(0, _emberBabel.inheritsLoose)(_class3, _AbstractTestCase3);
function _class3() {
return _AbstractTestCase3.apply(this, arguments) || this;
}
var _proto3 = _class3.prototype;
_proto3.beforeEach = function beforeEach() {
(0, _runloop.run)(function () {
array = _array_proxy.default.extend({
arrangedContent: (0, _metal.computed)(function () {
var content = this.get('content');
return content && (0, _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, _metal.objectAt)(this.get('arrangedContent'), idx);
return obj && obj.toString();
}
}).create({
content: (0, _array.A)([1, 2, 4, 5])
});
});
};
_proto3.afterEach = function afterEach() {
(0, _runloop.run)(function () {
array.destroy();
});
};
_proto3['@test indexOf - returns index of object in arrangedContent'] = function testIndexOfReturnsIndexOfObjectInArrangedContent(assert) {
assert.equal(array.indexOf('4'), 1, 'returns arranged index');
};
_proto3['@test lastIndexOf - returns last index of object in arrangedContent'] = function testLastIndexOfReturnsLastIndexOfObjectInArrangedContent(assert) {
array.get('content').pushObject(4);
assert.equal(array.lastIndexOf('4'), 2, 'returns last arranged index');
};
_proto3['@test objectAt - returns object at index in arrangedContent'] = function testObjectAtReturnsObjectAtIndexInArrangedContent(assert) {
assert.equal((0, _metal.objectAt)(array, 1), '4', 'returns object at index');
} // Not sure if we need a specific test for it, since it's internal
;
_proto3['@test objectAtContent - returns object at index in arrangedContent'] = function testObjectAtContentReturnsObjectAtIndexInArrangedContent(assert) {
assert.equal(array.objectAtContent(1), '4', 'returns object at index');
};
_proto3['@test objectsAt - returns objects at indices in arrangedContent'] = function testObjectsAtReturnsObjectsAtIndicesInArrangedContent(assert) {
assert.deepEqual(array.objectsAt([0, 2, 4]), ['5', '2', undefined], 'returns objects at indices');
};
_proto3['@test slice - returns a slice of the arrangedContent'] = function testSliceReturnsASliceOfTheArrangedContent(assert) {
assert.deepEqual(array.slice(1, 3), ['4', '2'], 'returns sliced arrangedContent');
};
_proto3['@test toArray - returns copy of arrangedContent'] = function testToArrayReturnsCopyOfArrangedContent(assert) {
assert.deepEqual(array.toArray(), ['5', '4', '2', '1']);
};
_proto3['@test without - returns arrangedContent without object'] = function testWithoutReturnsArrangedContentWithoutObject(assert) {
assert.deepEqual(array.without('2'), ['5', '4', '1'], 'returns arranged without object');
};
_proto3['@test lastObject - returns last arranged object'] = function testLastObjectReturnsLastArrangedObject(assert) {
assert.equal(array.get('lastObject'), '1', 'returns last arranged object');
};
_proto3['@test firstObject - returns first arranged object'] = function testFirstObjectReturnsFirstArrangedObject(assert) {
assert.equal(array.get('firstObject'), '5', 'returns first arranged object');
};
return _class3;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('ArrayProxy - with transforms',
/*#__PURE__*/
function (_AbstractTestCase4) {
(0, _emberBabel.inheritsLoose)(_class4, _AbstractTestCase4);
function _class4() {
return _AbstractTestCase4.apply(this, arguments) || this;
}
var _proto4 = _class4.prototype;
_proto4.beforeEach = function beforeEach() {
(0, _runloop.run)(function () {
array = _array_proxy.default.extend({
objectAtContent: function (idx) {
var obj = (0, _metal.objectAt)(this.get('arrangedContent'), idx);
return obj && obj.toString();
}
}).create({
content: (0, _array.A)([1, 2, 4, 5])
});
});
};
_proto4.afterEach = function afterEach() {
(0, _runloop.run)(function () {
array.destroy();
});
};
_proto4['@test popObject - removes last object in arrangedContent'] = function testPopObjectRemovesLastObjectInArrangedContent(assert) {
var popped = array.popObject();
assert.equal(popped, '5', 'returns last object');
assert.deepEqual(array.toArray(), ['1', '2', '4'], 'removes from content');
};
_proto4['@test removeObject - removes object from content'] = function testRemoveObjectRemovesObjectFromContent(assert) {
array.removeObject('2');
assert.deepEqual(array.toArray(), ['1', '4', '5']);
};
_proto4['@test removeObjects - removes objects from content'] = function testRemoveObjectsRemovesObjectsFromContent(assert) {
array.removeObjects(['2', '4', '6']);
assert.deepEqual(array.toArray(), ['1', '5']);
};
_proto4['@test shiftObject - removes from start of arrangedContent'] = function testShiftObjectRemovesFromStartOfArrangedContent(assert) {
var shifted = array.shiftObject();
assert.equal(shifted, '1', 'returns first object');
assert.deepEqual(array.toArray(), ['2', '4', '5'], 'removes object from content');
};
return _class4;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/array_proxy/array_observer_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/array_proxy", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _metal, _array_proxy, _array, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('ArrayProxy - array observers',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test mutating content'] = function testMutatingContent(assert) {
assert.expect(4);
var content = (0, _array.A)(['x', 'y', 'z']);
var proxy = _array_proxy.default.create({
content: content
});
proxy.addArrayObserver({
arrayWillChange: function (proxy, startIndex, removeCount, addCount) {
assert.deepEqual([startIndex, removeCount, addCount], [1, 1, 3]);
assert.deepEqual(proxy.toArray(), ['x', 'y', 'z']);
},
arrayDidChange: function (proxy, startIndex, removeCount, addCount) {
assert.deepEqual([startIndex, removeCount, addCount], [1, 1, 3]);
assert.deepEqual(proxy.toArray(), ['x', 'a', 'b', 'c', 'z']);
}
});
proxy.toArray();
content.replace(1, 1, ['a', 'b', 'c']);
};
_proto['@test assigning content'] = function testAssigningContent(assert) {
assert.expect(4);
var content = (0, _array.A)(['x', 'y', 'z']);
var proxy = _array_proxy.default.create({
content: content
});
proxy.addArrayObserver({
arrayWillChange: function (proxy, startIndex, removeCount, addCount) {
assert.deepEqual([startIndex, removeCount, addCount], [0, 3, 5]);
assert.deepEqual(proxy.toArray(), ['x', 'y', 'z']);
},
arrayDidChange: function (proxy, startIndex, removeCount, addCount) {
assert.deepEqual([startIndex, removeCount, addCount], [0, 3, 5]);
assert.deepEqual(proxy.toArray(), ['a', 'b', 'c', 'd', 'e']);
}
});
proxy.toArray();
(0, _metal.set)(proxy, 'content', (0, _array.A)(['a', 'b', 'c', 'd', 'e']));
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/array_proxy/content_change_test", ["ember-babel", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/array_proxy", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _runloop, _metal, _array_proxy, _array, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('ArrayProxy - content change',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto["@test The ArrayProxy doesn't explode when assigned a destroyed object"] = function testTheArrayProxyDoesnTExplodeWhenAssignedADestroyedObject(assert) {
var proxy1 = _array_proxy.default.create();
var proxy2 = _array_proxy.default.create();
(0, _runloop.run)(function () {
return proxy1.destroy();
});
(0, _metal.set)(proxy2, 'content', proxy1);
assert.ok(true, 'No exception was raised');
};
_proto['@test should update if content changes while change events are deferred'] = function testShouldUpdateIfContentChangesWhileChangeEventsAreDeferred(assert) {
var proxy = _array_proxy.default.create();
assert.deepEqual(proxy.toArray(), []);
(0, _metal.changeProperties)(function () {
proxy.set('content', (0, _array.A)([1, 2, 3]));
assert.deepEqual(proxy.toArray(), [1, 2, 3]);
});
};
_proto['@test objectAt recomputes the object cache correctly'] = function testObjectAtRecomputesTheObjectCacheCorrectly(assert) {
var indexes = [];
var proxy = _array_proxy.default.extend({
objectAtContent: function (index) {
indexes.push(index);
return this.content[index];
}
}).create({
content: (0, _array.A)([1, 2, 3, 4, 5])
});
assert.deepEqual(indexes, []);
assert.deepEqual(proxy.objectAt(0), 1);
assert.deepEqual(indexes, [0, 1, 2, 3, 4]);
indexes.length = 0;
proxy.set('content', (0, _array.A)([1, 2, 3]));
assert.deepEqual(proxy.objectAt(0), 1);
assert.deepEqual(indexes, [0, 1, 2]);
indexes.length = 0;
proxy.content.replace(2, 0, [4, 5]);
assert.deepEqual(proxy.objectAt(0), 1);
assert.deepEqual(proxy.objectAt(1), 2);
assert.deepEqual(indexes, []);
assert.deepEqual(proxy.objectAt(2), 4);
assert.deepEqual(indexes, [2, 3, 4]);
};
_proto['@test negative indexes are handled correctly'] = function testNegativeIndexesAreHandledCorrectly(assert) {
var indexes = [];
var proxy = _array_proxy.default.extend({
objectAtContent: function (index) {
indexes.push(index);
return this.content[index];
}
}).create({
content: (0, _array.A)([1, 2, 3, 4, 5])
});
assert.deepEqual(proxy.toArray(), [1, 2, 3, 4, 5]);
indexes.length = 0;
proxy.content.replace(-1, 0, [7]);
proxy.content.replace(-2, 0, [6]);
assert.deepEqual(proxy.toArray(), [1, 2, 3, 4, 6, 7, 5]);
assert.deepEqual(indexes, [4, 5, 6]);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/array_proxy/length_test", ["ember-babel", "@ember/-internals/runtime/lib/system/array_proxy", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/metal", "@ember/object/computed", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _array_proxy, _object, _metal, _computed, _array, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember.ArrayProxy - content change (length)',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should update length for null content'] = function testShouldUpdateLengthForNullContent(assert) {
var proxy = _array_proxy.default.create({
content: (0, _array.A)([1, 2, 3])
});
assert.equal(proxy.get('length'), 3, 'precond - length is 3');
proxy.set('content', null);
assert.equal(proxy.get('length'), 0, 'length updates');
};
_proto['@test should update length for null content when there is a computed property watching length'] = function testShouldUpdateLengthForNullContentWhenThereIsAComputedPropertyWatchingLength(assert) {
var proxy = _array_proxy.default.extend({
isEmpty: (0, _computed.not)('length')
}).create({
content: (0, _array.A)([1, 2, 3])
});
assert.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);
assert.equal(proxy.get('length'), 0, 'length updates');
};
_proto['@test getting length does not recompute the object cache'] = function testGettingLengthDoesNotRecomputeTheObjectCache(assert) {
var indexes = [];
var proxy = _array_proxy.default.extend({
objectAtContent: function (index) {
indexes.push(index);
return this.content[index];
}
}).create({
content: (0, _array.A)([1, 2, 3, 4, 5])
});
assert.equal((0, _metal.get)(proxy, 'length'), 5);
assert.deepEqual(indexes, []);
indexes.length = 0;
proxy.set('content', (0, _array.A)([6, 7, 8]));
assert.equal((0, _metal.get)(proxy, 'length'), 3);
assert.deepEqual(indexes, []);
indexes.length = 0;
proxy.content.replace(1, 0, [1, 2, 3]);
assert.equal((0, _metal.get)(proxy, 'length'), 6);
assert.deepEqual(indexes, []);
};
_proto['@test accessing length after content set to null'] = function testAccessingLengthAfterContentSetToNull(assert) {
var obj = _array_proxy.default.create({
content: ['foo', 'bar']
});
assert.equal(obj.length, 2, 'precond');
(0, _metal.set)(obj, 'content', null);
assert.equal(obj.length, 0, 'length is 0 without content');
assert.deepEqual(obj.content, null, 'content was updated');
};
_proto['@test accessing length after content set to null in willDestroy'] = function testAccessingLengthAfterContentSetToNullInWillDestroy(assert) {
var obj = _array_proxy.default.extend({
willDestroy: function () {
this.set('content', null);
this._super.apply(this, arguments);
}
}).create({
content: ['foo', 'bar']
});
assert.equal(obj.length, 2, 'precond');
(0, _internalTestHelpers.runTask)(function () {
return obj.destroy();
});
assert.equal(obj.length, 0, 'length is 0 without content');
assert.deepEqual(obj.content, null, 'content was updated');
};
_proto['@test setting length to 0'] = function testSettingLengthTo0(assert) {
var obj = _array_proxy.default.create({
content: ['foo', 'bar']
});
assert.equal(obj.length, 2, 'precond');
(0, _metal.set)(obj, 'length', 0);
assert.equal(obj.length, 0, 'length was updated');
assert.deepEqual(obj.content, [], 'content length was truncated');
};
_proto['@test setting length to smaller value'] = function testSettingLengthToSmallerValue(assert) {
var obj = _array_proxy.default.create({
content: ['foo', 'bar']
});
assert.equal(obj.length, 2, 'precond');
(0, _metal.set)(obj, 'length', 1);
assert.equal(obj.length, 1, 'length was updated');
assert.deepEqual(obj.content, ['foo'], 'content length was truncated');
};
_proto['@test setting length to larger value'] = function testSettingLengthToLargerValue(assert) {
var obj = _array_proxy.default.create({
content: ['foo', 'bar']
});
assert.equal(obj.length, 2, 'precond');
(0, _metal.set)(obj, 'length', 3);
assert.equal(obj.length, 3, 'length was updated');
assert.deepEqual(obj.content, ['foo', 'bar', undefined], 'content length was updated');
};
_proto['@test setting length after content set to null'] = function testSettingLengthAfterContentSetToNull(assert) {
var obj = _array_proxy.default.create({
content: ['foo', 'bar']
});
assert.equal(obj.length, 2, 'precond');
(0, _metal.set)(obj, 'content', null);
assert.equal(obj.length, 0, 'length was updated');
(0, _metal.set)(obj, 'length', 0);
assert.equal(obj.length, 0, 'length is still updated');
};
_proto['@test setting length to greater than zero'] = function testSettingLengthToGreaterThanZero(assert) {
var obj = _array_proxy.default.create({
content: ['foo', 'bar']
});
assert.equal(obj.length, 2, 'precond');
(0, _metal.set)(obj, 'length', 1);
assert.equal(obj.length, 1, 'length was updated');
assert.deepEqual(obj.content, ['foo'], 'content length was truncated');
};
_proto['@test array proxy + aliasedProperty complex test'] = function testArrayProxyAliasedPropertyComplexTest(assert) {
var aCalled, bCalled, cCalled, dCalled, eCalled;
aCalled = bCalled = cCalled = dCalled = eCalled = 0;
var obj = _object.default.extend({
colors: (0, _computed.oneWay)('model'),
length: (0, _computed.oneWay)('colors.length'),
a: (0, _metal.observer)('length', function () {
return aCalled++;
}),
b: (0, _metal.observer)('colors.length', function () {
return bCalled++;
}),
c: (0, _metal.observer)('colors.content.length', function () {
return cCalled++;
}),
d: (0, _metal.observer)('colors.[]', function () {
return dCalled++;
}),
e: (0, _metal.observer)('colors.content.[]', function () {
return eCalled++;
})
}).create();
obj.set('model', _array_proxy.default.create({
content: (0, _array.A)(['red', 'yellow', 'blue'])
}));
assert.equal(obj.get('colors.content.length'), 3);
assert.equal(obj.get('colors.length'), 3);
assert.equal(obj.get('length'), 3);
assert.equal(aCalled, 1, 'expected observer `length` to be called ONCE');
assert.equal(bCalled, 1, 'expected observer `colors.length` to be called ONCE');
assert.equal(cCalled, 1, 'expected observer `colors.content.length` to be called ONCE');
assert.equal(dCalled, 1, 'expected observer `colors.[]` to be called ONCE');
assert.equal(eCalled, 1, 'expected observer `colors.content.[]` to be called ONCE');
obj.get('colors').pushObjects(['green', 'red']);
assert.equal(obj.get('colors.content.length'), 5);
assert.equal(obj.get('colors.length'), 5);
assert.equal(obj.get('length'), 5);
assert.equal(aCalled, 2, 'expected observer `length` to be called TWICE');
assert.equal(bCalled, 2, 'expected observer `colors.length` to be called TWICE');
assert.equal(cCalled, 2, 'expected observer `colors.content.length` to be called TWICE');
assert.equal(dCalled, 2, 'expected observer `colors.[]` to be called TWICE');
assert.equal(eCalled, 2, 'expected observer `colors.content.[]` to be called TWICE');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/array_proxy/watching_and_listening_test", ["ember-babel", "@ember/-internals/meta", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/array_proxy", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _meta, _metal, _array_proxy, _array, _internalTestHelpers) {
"use strict";
function sortedListenersFor(obj, eventName) {
var listeners = (0, _meta.peekMeta)(obj).matchingListeners(eventName) || [];
var keys = [];
for (var i = 0; i < listeners.length; i += 3) {
keys.push(listeners[i + 1]);
}
return keys.sort();
}
(0, _internalTestHelpers.moduleFor)('ArrayProxy - watching and listening',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto["@test setting 'content' adds listeners correctly"] = function (assert) {
var content = (0, _array.A)();
var proxy = _array_proxy.default.create();
assert.deepEqual(sortedListenersFor(content, '@array:before'), []);
assert.deepEqual(sortedListenersFor(content, '@array:change'), []);
proxy.set('content', content);
assert.deepEqual(sortedListenersFor(content, '@array:before'), ['_arrangedContentArrayWillChange']);
assert.deepEqual(sortedListenersFor(content, '@array:change'), ['_arrangedContentArrayDidChange']);
};
_proto["@test changing 'content' adds and removes listeners correctly"] = function (assert) {
var content1 = (0, _array.A)();
var content2 = (0, _array.A)();
var proxy = _array_proxy.default.create({
content: content1
});
assert.deepEqual(sortedListenersFor(content1, '@array:before'), ['_arrangedContentArrayWillChange']);
assert.deepEqual(sortedListenersFor(content1, '@array:change'), ['_arrangedContentArrayDidChange']);
proxy.set('content', content2);
assert.deepEqual(sortedListenersFor(content1, '@array:before'), []);
assert.deepEqual(sortedListenersFor(content1, '@array:change'), []);
assert.deepEqual(sortedListenersFor(content2, '@array:before'), ['_arrangedContentArrayWillChange']);
assert.deepEqual(sortedListenersFor(content2, '@array:change'), ['_arrangedContentArrayDidChange']);
};
_proto["@test regression test for https://github.com/emberjs/ember.js/issues/12475"] = function (assert) {
var item1a = {
id: 1
};
var item1b = {
id: 2
};
var item1c = {
id: 3
};
var content1 = (0, _array.A)([item1a, item1b, item1c]);
var proxy = _array_proxy.default.create({
content: content1
});
var obj = {
proxy: proxy
};
(0, _metal.defineProperty)(obj, 'ids', (0, _metal.computed)('proxy.@each.id', function () {
return (0, _metal.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, _metal.addObserver)(item1a, 'id', function () {});
(0, _metal.addObserver)(item1b, 'id', function () {});
(0, _metal.addObserver)(item1c, 'id', function () {}); // The EachProxy has not yet been consumed. Only the manually added
// observers are watching.
assert.equal((0, _metal.watcherCount)(item1a, 'id'), 1);
assert.equal((0, _metal.watcherCount)(item1b, 'id'), 1);
assert.equal((0, _metal.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.
assert.deepEqual((0, _metal.get)(obj, 'ids'), [1, 2, 3]); // For each item, the two each proxy observers and one manual added observer
// are watching.
assert.equal((0, _metal.watcherCount)(item1a, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item1b, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item1c, 'id'), 2); // 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);
assert.equal((0, _metal.watcherCount)(item1a, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item1b, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item1c, 'id'), 2); // This is repeated to catch the regression. It should still be a no-op.
proxy.set('content', content1);
assert.equal((0, _metal.watcherCount)(item1a, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item1b, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item1c, 'id'), 2); // 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, _array.A)([item2a, item2b, item2c]);
(0, _metal.addObserver)(item2a, 'id', function () {});
(0, _metal.addObserver)(item2b, 'id', function () {});
(0, _metal.addObserver)(item2c, 'id', function () {});
proxy.set('content', content2);
assert.deepEqual((0, _metal.get)(obj, 'ids'), [4, 5, 6]);
assert.equal((0, _metal.watcherCount)(item2a, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item2b, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item2c, 'id'), 2); // Ensure that the observers added by the EachProxy on all items in the
// first content array have been torn down.
assert.equal((0, _metal.watcherCount)(item1a, 'id'), 1);
assert.equal((0, _metal.watcherCount)(item1b, 'id'), 1);
assert.equal((0, _metal.watcherCount)(item1c, 'id'), 1);
proxy.set('content', content2);
assert.equal((0, _metal.watcherCount)(item2a, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item2b, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item2c, 'id'), 2);
proxy.set('content', content2);
assert.equal((0, _metal.watcherCount)(item2a, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item2b, 'id'), 2);
assert.equal((0, _metal.watcherCount)(item2c, 'id'), 2);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/core_object_test", ["ember-babel", "@ember/-internals/owner", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/core_object", "internal-test-helpers"], function (_emberBabel, _owner, _metal, _core_object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember.CoreObject',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test throws deprecation with new (one arg)'] = function testThrowsDeprecationWithNewOneArg() {
expectDeprecation(function () {
new _core_object.default({
firstName: 'Stef',
lastName: 'Penner'
});
}, /using `new` with EmberObject has been deprecated/);
};
_proto['@test throws deprecation with new (> 1 arg)'] = function testThrowsDeprecationWithNew1Arg() {
expectDeprecation(function () {
new _core_object.default({
firstName: 'Stef',
lastName: 'Penner'
}, {
other: 'name'
});
}, /using `new` with EmberObject has been deprecated/);
};
_proto['@test toString should be not be added as a property when calling toString()'] = function testToStringShouldBeNotBeAddedAsAPropertyWhenCallingToString(assert) {
var obj = _core_object.default.create({
firstName: 'Foo',
lastName: 'Bar'
});
obj.toString();
assert.notOk(obj.hasOwnProperty('toString'), 'Calling toString() should not create a toString class property');
};
_proto['@test should not trigger proxy assertion when retrieving a proxy with (GH#16263)'] = function testShouldNotTriggerProxyAssertionWhenRetrievingAProxyWithGH16263(assert) {
var someProxyishThing = _core_object.default.extend({
unknownProperty: function () {
return true;
}
}).create();
var obj = _core_object.default.create({
someProxyishThing: someProxyishThing
});
var proxy = (0, _metal.get)(obj, 'someProxyishThing');
assert.equal((0, _metal.get)(proxy, 'lolol'), true, 'should be able to get data from a proxy');
};
_proto['@test should not trigger proxy assertion when retrieving a re-registered proxy (GH#16610)'] = function testShouldNotTriggerProxyAssertionWhenRetrievingAReRegisteredProxyGH16610(assert) {
var owner = (0, _internalTestHelpers.buildOwner)();
var someProxyishThing = _core_object.default.extend({
unknownProperty: function () {
return true;
}
}).create(); // emulates ember-engines's process of registering services provided
// by the host app down to the engine
owner.register('thing:one', someProxyishThing, {
instantiate: false
});
assert.equal(owner.lookup('thing:one'), someProxyishThing);
};
_proto['@test should not trigger proxy assertion when probing for a "symbol"'] = function testShouldNotTriggerProxyAssertionWhenProbingForASymbol(assert) {
var proxy = _core_object.default.extend({
unknownProperty: function () {
return true;
}
}).create();
assert.equal((0, _metal.get)(proxy, 'lolol'), true, 'should be able to get data from a proxy'); // should not trigger an assertion
(0, _owner.getOwner)(proxy);
};
_proto['@test can use getOwner in a proxy init GH#16484'] = function testCanUseGetOwnerInAProxyInitGH16484(assert) {
var owner = {};
var options = {};
(0, _owner.setOwner)(options, owner);
_core_object.default.extend({
init: function () {
this._super.apply(this, arguments);
var localOwner = (0, _owner.getOwner)(this);
assert.equal(localOwner, owner, 'should be able to `getOwner` in init');
},
unknownProperty: function () {
return undefined;
}
}).create(options);
};
_proto['@test observed properties are enumerable when set GH#14594'] = function testObservedPropertiesAreEnumerableWhenSetGH14594(assert) {
var callCount = 0;
var Test = _core_object.default.extend({
myProp: null,
anotherProp: undefined,
didChangeMyProp: (0, _metal.observer)('myProp', function () {
callCount++;
})
});
var test = Test.create();
(0, _metal.set)(test, 'id', '3');
(0, _metal.set)(test, 'myProp', {
id: 1
});
assert.deepEqual(Object.keys(test).sort(), ['id', 'myProp']);
(0, _metal.set)(test, 'anotherProp', 'nice');
assert.deepEqual(Object.keys(test).sort(), ['anotherProp', 'id', 'myProp']);
assert.equal(callCount, 1);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/namespace/base_test", ["ember-babel", "@ember/-internals/environment", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/utils", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/system/namespace", "internal-test-helpers"], function (_emberBabel, _environment, _runloop, _metal, _utils, _object, _namespace, _internalTestHelpers) {
"use strict";
var originalLookup = _environment.context.lookup;
var lookup;
(0, _internalTestHelpers.moduleFor)('Namespace',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
(0, _metal.setNamespaceSearchDisabled)(false);
lookup = _environment.context.lookup = {};
};
_proto.afterEach = function afterEach() {
(0, _metal.setNamespaceSearchDisabled)(false);
for (var prop in lookup) {
if (lookup[prop]) {
(0, _runloop.run)(lookup[prop], 'destroy');
}
}
_environment.context.lookup = originalLookup;
};
_proto['@test Namespace should be a subclass of EmberObject'] = function testNamespaceShouldBeASubclassOfEmberObject(assert) {
assert.ok(_object.default.detect(_namespace.default));
};
_proto['@test Namespace should be duck typed'] = function testNamespaceShouldBeDuckTyped(assert) {
var namespace = _namespace.default.create();
try {
assert.ok((0, _metal.get)(namespace, 'isNamespace'), 'isNamespace property is true');
} finally {
(0, _runloop.run)(namespace, 'destroy');
}
};
_proto['@test Namespace is found and named'] = function testNamespaceIsFoundAndNamed(assert) {
var nsA = lookup.NamespaceA = _namespace.default.create();
assert.equal(nsA.toString(), 'NamespaceA', 'namespaces should have a name if they are on lookup');
var nsB = lookup.NamespaceB = _namespace.default.create();
assert.equal(nsB.toString(), 'NamespaceB', 'namespaces work if created after the first namespace processing pass');
};
_proto['@test Classes under an Namespace are properly named'] = function testClassesUnderAnNamespaceAreProperlyNamed(assert) {
var nsA = lookup.NamespaceA = _namespace.default.create();
nsA.Foo = _object.default.extend();
assert.equal(nsA.Foo.toString(), 'NamespaceA.Foo', 'Classes pick up their parent namespace');
nsA.Bar = _object.default.extend();
assert.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();
assert.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");
//});
;
_proto['@test Lowercase namespaces are no longer supported'] = function testLowercaseNamespacesAreNoLongerSupported(assert) {
var nsC = lookup.namespaceC = _namespace.default.create();
assert.equal(nsC.toString(), (0, _utils.guidFor)(nsC));
};
_proto['@test A namespace can be assigned a custom name'] = function testANamespaceCanBeAssignedACustomName(assert) {
var nsA = _namespace.default.create({
name: 'NamespaceA'
});
try {
var nsB = lookup.NamespaceB = _namespace.default.create({
name: 'CustomNamespaceB'
});
nsA.Foo = _object.default.extend();
nsB.Foo = _object.default.extend();
assert.equal(nsA.Foo.toString(), 'NamespaceA.Foo', "The namespace's name is used when the namespace is not in the lookup object");
assert.equal(nsB.Foo.toString(), 'CustomNamespaceB.Foo', "The namespace's name is used when the namespace is in the lookup object");
} finally {
(0, _runloop.run)(nsA, 'destroy');
}
};
_proto['@test Calling namespace.nameClasses() eagerly names all classes'] = function testCallingNamespaceNameClassesEagerlyNamesAllClasses(assert) {
(0, _metal.setNamespaceSearchDisabled)(true);
var namespace = lookup.NS = _namespace.default.create();
namespace.ClassA = _object.default.extend();
namespace.ClassB = _object.default.extend();
_namespace.default.processAll();
assert.equal(namespace.ClassA.toString(), 'NS.ClassA');
assert.equal(namespace.ClassB.toString(), 'NS.ClassB');
};
_proto['@test A namespace can be looked up by its name'] = function testANamespaceCanBeLookedUpByItsName(assert) {
var NS = lookup.NS = _namespace.default.create();
var UI = lookup.UI = _namespace.default.create();
var CF = lookup.CF = _namespace.default.create();
assert.equal(_namespace.default.byName('NS'), NS);
assert.equal(_namespace.default.byName('UI'), UI);
assert.equal(_namespace.default.byName('CF'), CF);
};
_proto['@test A nested namespace can be looked up by its name'] = function testANestedNamespaceCanBeLookedUpByItsName(assert) {
var UI = lookup.UI = _namespace.default.create();
UI.Nav = _namespace.default.create();
assert.equal(_namespace.default.byName('UI.Nav'), UI.Nav);
(0, _runloop.run)(UI.Nav, 'destroy');
};
_proto['@test Destroying a namespace before caching lookup removes it from the list of namespaces'] = function testDestroyingANamespaceBeforeCachingLookupRemovesItFromTheListOfNamespaces(assert) {
var CF = lookup.CF = _namespace.default.create();
(0, _runloop.run)(CF, 'destroy');
assert.equal(_namespace.default.byName('CF'), undefined, 'namespace can not be found after destroyed');
};
_proto['@test Destroying a namespace after looking up removes it from the list of namespaces'] = function testDestroyingANamespaceAfterLookingUpRemovesItFromTheListOfNamespaces(assert) {
var CF = lookup.CF = _namespace.default.create();
assert.equal(_namespace.default.byName('CF'), CF, 'precondition - namespace can be looked up by name');
(0, _runloop.run)(CF, 'destroy');
assert.equal(_namespace.default.byName('CF'), undefined, 'namespace can not be found after destroyed');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/native_array/a_test", ["ember-babel", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _array, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember.A',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Ember.A'] = function testEmberA(assert) {
assert.deepEqual((0, _array.A)([1, 2]), [1, 2], 'array values were not be modified');
assert.deepEqual((0, _array.A)(), [], 'returned an array with no arguments');
assert.deepEqual((0, _array.A)(null), [], 'returned an array with a null argument');
assert.ok(_array.default.detect((0, _array.A)()), 'returned an ember array');
assert.ok(_array.default.detect((0, _array.A)([1, 2])), 'returned an ember array');
};
_proto['@test new Ember.A'] = function testNewEmberA(assert) {
expectDeprecation(function () {
assert.deepEqual(new _array.A([1, 2]), [1, 2], 'array values were not be modified');
assert.deepEqual(new _array.A(), [], 'returned an array with no arguments');
assert.deepEqual(new _array.A(null), [], 'returned an array with a null argument');
assert.ok(_array.default.detect(new _array.A()), 'returned an ember array');
assert.ok(_array.default.detect(new _array.A([1, 2])), 'returned an ember array');
});
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/native_array/replace_test", ["ember-babel", "@ember/-internals/runtime/lib/mixins/array", "internal-test-helpers"], function (_emberBabel, _array, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('NativeArray.replace',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test raises assertion if third argument is not an array'] = function testRaisesAssertionIfThirdArgumentIsNotAnArray() {
expectAssertion(function () {
(0, _array.A)([1, 2, 3]).replace(1, 1, '');
}, 'The third argument to replace needs to be an array.');
};
_proto['@test it does not raise an assertion if third parameter is not passed'] = function testItDoesNotRaiseAnAssertionIfThirdParameterIsNotPassed(assert) {
assert.deepEqual((0, _array.A)([1, 2, 3]).replace(1, 2), (0, _array.A)([1]), 'no assertion raised');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/computed_test", ["ember-babel", "@ember/-internals/metal", "@ember/object/computed", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _metal, _computed, _object, _internalTestHelpers) {
"use strict";
function K() {
return this;
}
function testWithDefault(assert, expect, x, y, z) {
assert.equal((0, _metal.get)(x, y), expect);
assert.equal((0, _metal.getWithDefault)(x, y, z), expect);
assert.equal(x.getWithDefault(y, z), expect);
}
(0, _internalTestHelpers.moduleFor)('EmberObject computed property',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test computed property on instance'] = function testComputedPropertyOnInstance(assert) {
var MyClass = _object.default.extend({
foo: (0, _metal.computed)(function () {
return 'FOO';
})
});
testWithDefault(assert, 'FOO', MyClass.create(), 'foo');
};
_proto['@test computed property on subclass'] = function testComputedPropertyOnSubclass(assert) {
var MyClass = _object.default.extend({
foo: (0, _metal.computed)(function () {
return 'FOO';
})
});
var Subclass = MyClass.extend({
foo: (0, _metal.computed)(function () {
return 'BAR';
})
});
testWithDefault(assert, 'BAR', Subclass.create(), 'foo');
};
_proto['@test replacing computed property with regular val'] = function testReplacingComputedPropertyWithRegularVal(assert) {
var MyClass = _object.default.extend({
foo: (0, _metal.computed)(function () {
return 'FOO';
})
});
var Subclass = MyClass.extend({
foo: 'BAR'
});
testWithDefault(assert, 'BAR', Subclass.create(), 'foo');
};
_proto['@test complex depndent keys'] = function testComplexDepndentKeys(assert) {
var MyClass = _object.default.extend({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'bar', {
baz: 'BIFF'
});
},
count: 0,
foo: (0, _metal.computed)(function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
return (0, _metal.get)((0, _metal.get)(this, 'bar'), 'baz') + ' ' + (0, _metal.get)(this, 'count');
}).property('bar.baz')
});
var Subclass = MyClass.extend({
count: 20
});
var obj1 = MyClass.create();
var obj2 = Subclass.create();
testWithDefault(assert, 'BIFF 1', obj1, 'foo');
testWithDefault(assert, 'BIFF 21', obj2, 'foo');
(0, _metal.set)((0, _metal.get)(obj1, 'bar'), 'baz', 'BLARG');
testWithDefault(assert, 'BLARG 2', obj1, 'foo');
testWithDefault(assert, 'BIFF 21', obj2, 'foo');
(0, _metal.set)((0, _metal.get)(obj2, 'bar'), 'baz', 'BOOM');
testWithDefault(assert, 'BLARG 2', obj1, 'foo');
testWithDefault(assert, 'BOOM 22', obj2, 'foo');
};
_proto['@test complex dependent keys changing complex dependent keys'] = function testComplexDependentKeysChangingComplexDependentKeys(assert) {
var MyClass = _object.default.extend({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'bar', {
baz: 'BIFF'
});
},
count: 0,
foo: (0, _metal.computed)(function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
return (0, _metal.get)((0, _metal.get)(this, 'bar'), 'baz') + ' ' + (0, _metal.get)(this, 'count');
}).property('bar.baz')
});
var Subclass = MyClass.extend({
init: function () {
this._super.apply(this, arguments);
(0, _metal.set)(this, 'bar2', {
baz: 'BIFF2'
});
},
count: 0,
foo: (0, _metal.computed)(function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
return (0, _metal.get)((0, _metal.get)(this, 'bar2'), 'baz') + ' ' + (0, _metal.get)(this, 'count');
}).property('bar2.baz')
});
var obj2 = Subclass.create();
testWithDefault(assert, 'BIFF2 1', obj2, 'foo');
(0, _metal.set)((0, _metal.get)(obj2, 'bar'), 'baz', 'BLARG');
testWithDefault(assert, 'BIFF2 1', obj2, 'foo'); // should not invalidate property
(0, _metal.set)((0, _metal.get)(obj2, 'bar2'), 'baz', 'BLARG');
testWithDefault(assert, 'BLARG 2', obj2, 'foo'); // should not invalidate property
};
_proto['@test can retrieve metadata for a computed property'] = function testCanRetrieveMetadataForAComputedProperty(assert) {
var MyClass = _object.default.extend({
computedProperty: (0, _metal.computed)(function () {}).meta({
key: 'keyValue'
})
});
assert.equal((0, _metal.get)(MyClass.metaForProperty('computedProperty'), 'key'), 'keyValue', 'metadata saved on the computed property can be retrieved');
var ClassWithNoMetadata = _object.default.extend({
computedProperty: (0, _metal.computed)(function () {}).volatile(),
staticProperty: 12
});
assert.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'.");
};
_proto['@test overriding a computed property with null removes it from eachComputedProperty iteration'] = function testOverridingAComputedPropertyWithNullRemovesItFromEachComputedPropertyIteration(assert) {
var MyClass = _object.default.extend({
foo: (0, _metal.computed)(function () {}),
fooDidChange: (0, _metal.observer)('foo', function () {}),
bar: (0, _metal.computed)(function () {})
});
var SubClass = MyClass.extend({
foo: null
});
var list = [];
SubClass.eachComputedProperty(function (name) {
return list.push(name);
});
assert.deepEqual(list.sort(), ['bar'], 'overridding with null removes from eachComputedProperty listing');
};
_proto['@test can iterate over a list of computed properties for a class'] = function testCanIterateOverAListOfComputedPropertiesForAClass(assert) {
var MyClass = _object.default.extend({
foo: (0, _metal.computed)(function () {}),
fooDidChange: (0, _metal.observer)('foo', function () {}),
bar: (0, _metal.computed)(function () {}),
qux: (0, _metal.alias)('foo')
});
var SubClass = MyClass.extend({
baz: (0, _metal.computed)(function () {})
});
SubClass.reopen({
bat: (0, _metal.computed)(function () {}).meta({
iAmBat: true
})
});
var list = [];
MyClass.eachComputedProperty(function (name) {
list.push(name);
});
assert.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') {
assert.deepEqual(meta, {
iAmBat: true
});
} else {
assert.deepEqual(meta, {});
}
});
assert.deepEqual(list.sort(), ['bar', 'bat', 'baz', 'foo', 'qux'], 'all inherited properties are included');
};
_proto['@test list of properties updates when an additional property is added (such cache busting)'] = function testListOfPropertiesUpdatesWhenAnAdditionalPropertyIsAddedSuchCacheBusting(assert) {
var MyClass = _object.default.extend({
foo: (0, _metal.computed)(K),
fooDidChange: (0, _metal.observer)('foo', function () {}),
bar: (0, _metal.computed)(K)
});
var list = [];
MyClass.eachComputedProperty(function (name) {
list.push(name);
});
assert.deepEqual(list.sort(), ['bar', 'foo'].sort(), 'expected two computed properties');
MyClass.reopen({
baz: (0, _metal.computed)(K)
});
MyClass.create(); // force apply mixins
list = [];
MyClass.eachComputedProperty(function (name) {
list.push(name);
});
assert.deepEqual(list.sort(), ['bar', 'foo', 'baz'].sort(), 'expected three computed properties');
(0, _metal.defineProperty)(MyClass.prototype, 'qux', (0, _metal.computed)(K));
list = [];
MyClass.eachComputedProperty(function (name) {
list.push(name);
});
assert.deepEqual(list.sort(), ['bar', 'foo', 'baz', 'qux'].sort(), 'expected four computed properties');
};
_proto['@test Calling _super in call outside the immediate function of a CP getter works'] = function testCalling_superInCallOutsideTheImmediateFunctionOfACPGetterWorks(assert) {
function macro(callback) {
return (0, _metal.computed)(function () {
return callback.call(this);
});
}
var MyClass = _object.default.extend({
foo: (0, _metal.computed)(function () {
return 'FOO';
})
});
var SubClass = MyClass.extend({
foo: macro(function () {
return this._super();
})
});
assert.ok((0, _metal.get)(SubClass.create(), 'foo'), 'FOO', 'super value is fetched');
};
_proto['@test Calling _super in apply outside the immediate function of a CP getter works'] = function testCalling_superInApplyOutsideTheImmediateFunctionOfACPGetterWorks(assert) {
function macro(callback) {
return (0, _metal.computed)(function () {
return callback.apply(this);
});
}
var MyClass = _object.default.extend({
foo: (0, _metal.computed)(function () {
return 'FOO';
})
});
var SubClass = MyClass.extend({
foo: macro(function () {
return this._super();
})
});
assert.ok((0, _metal.get)(SubClass.create(), 'foo'), 'FOO', 'super value is fetched');
};
_proto['@test observing computed.reads prop and overriding it in create() works'] = function testObservingComputedReadsPropAndOverridingItInCreateWorks(assert) {
var Obj = _object.default.extend({
name: (0, _computed.oneWay)('model.name'),
nameDidChange: (0, _metal.observer)('name', function () {})
});
var obj1 = Obj.create({
name: '1'
});
var obj2 = Obj.create({
name: '2'
});
assert.equal(obj1.get('name'), '1');
assert.equal(obj2.get('name'), '2');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/create_test", ["ember-babel", "@ember/-internals/owner", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _owner, _metal, _object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('EmberObject.create',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test simple properties are set'] = function testSimplePropertiesAreSet(assert) {
var o = _object.default.create({
ohai: 'there'
});
assert.equal(o.get('ohai'), 'there');
};
_proto['@test calls computed property setters'] = function testCallsComputedPropertySetters(assert) {
var MyClass = _object.default.extend({
foo: (0, _metal.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'
});
assert.equal(o.get('foo'), 'bar');
};
_proto['@test sets up mandatory setters for watched simple properties'] = function testSetsUpMandatorySettersForWatchedSimpleProperties(assert) {
if (true
/* DEBUG */
) {
var MyClass = _object.default.extend({
foo: null,
bar: null,
fooDidChange: (0, _metal.observer)('foo', function () {})
});
var o = MyClass.create({
foo: 'bar',
bar: 'baz'
});
assert.equal(o.get('foo'), 'bar');
var descriptor = Object.getOwnPropertyDescriptor(o, 'foo');
assert.ok(descriptor.set, 'Mandatory setter was setup');
descriptor = Object.getOwnPropertyDescriptor(o, 'bar');
assert.ok(!descriptor.set, 'Mandatory setter was not setup');
} else {
assert.expect(0);
}
};
_proto['@test calls setUnknownProperty if defined'] = function testCallsSetUnknownPropertyIfDefined(assert) {
var setUnknownPropertyCalled = false;
var MyClass = _object.default.extend({
setUnknownProperty: function ()
/* key, value */
{
setUnknownPropertyCalled = true;
}
});
MyClass.create({
foo: 'bar'
});
assert.ok(setUnknownPropertyCalled, 'setUnknownProperty was called');
};
_proto['@test throws if you try to define a computed property'] = function testThrowsIfYouTryToDefineAComputedProperty() {
expectAssertion(function () {
_object.default.create({
foo: (0, _metal.computed)(function () {})
});
}, 'EmberObject.create no longer supports defining computed properties. Define computed properties using extend() or reopen() before calling create().');
};
_proto['@test throws if you try to call _super in a method'] = function testThrowsIfYouTryToCall_superInAMethod() {
expectAssertion(function () {
_object.default.create({
foo: function () {
this._super.apply(this, arguments);
}
});
}, 'EmberObject.create no longer supports defining methods that call _super.');
};
_proto["@test throws if you try to 'mixin' a definition"] = function testThrowsIfYouTryToMixinADefinition() {
var myMixin = _metal.Mixin.create({
adder: function (arg1, arg2) {
return arg1 + arg2;
}
});
expectAssertion(function () {
_object.default.create(myMixin);
}, 'EmberObject.create no longer supports mixing in other definitions, use .extend & .create separately instead.');
};
_proto['@test inherits properties from passed in EmberObject'] = function testInheritsPropertiesFromPassedInEmberObject(assert) {
var baseObj = _object.default.create({
foo: 'bar'
});
var secondaryObj = _object.default.create(baseObj);
assert.equal(secondaryObj.foo, baseObj.foo, 'Em.O.create inherits properties from EmberObject parameter');
};
_proto['@test throws if you try to pass anything a string as a parameter'] = function testThrowsIfYouTryToPassAnythingAStringAsAParameter() {
var expected = 'EmberObject.create only accepts objects.';
expectAssertion(function () {
return _object.default.create('some-string');
}, expected);
};
_proto['@test EmberObject.create can take undefined as a parameter'] = function testEmberObjectCreateCanTakeUndefinedAsAParameter(assert) {
var o = _object.default.create(undefined);
assert.deepEqual(_object.default.create(), o);
};
_proto['@test can use getOwner in a proxy init GH#16484'] = function testCanUseGetOwnerInAProxyInitGH16484(assert) {
var owner = {};
var options = {};
(0, _owner.setOwner)(options, owner);
_object.default.extend({
init: function () {
this._super.apply(this, arguments);
var localOwner = (0, _owner.getOwner)(this);
assert.equal(localOwner, owner, 'should be able to `getOwner` in init');
},
unknownProperty: function () {
return undefined;
}
}).create(options);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/destroy_test", ["ember-babel", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/meta", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _runloop, _metal, _meta, _object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('@ember/-internals/runtime/system/object/destroy_test',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should schedule objects to be destroyed at the end of the run loop'] = function testShouldScheduleObjectsToBeDestroyedAtTheEndOfTheRunLoop(assert) {
var obj = _object.default.create();
var meta;
(0, _runloop.run)(function () {
obj.destroy();
meta = (0, _meta.peekMeta)(obj);
assert.ok(meta, 'meta is not destroyed immediately');
assert.ok((0, _metal.get)(obj, 'isDestroying'), 'object is marked as destroying immediately');
assert.ok(!(0, _metal.get)(obj, 'isDestroyed'), 'object is not destroyed immediately');
});
meta = (0, _meta.peekMeta)(obj);
assert.ok((0, _metal.get)(obj, 'isDestroyed'), 'object is destroyed after run loop finishes');
} // MANDATORY_SETTER moves value to meta.values
// a destroyed object removes meta but leaves the accessor
// that looks it up
;
_proto['@test should raise an exception when modifying watched properties on a destroyed object'] = function testShouldRaiseAnExceptionWhenModifyingWatchedPropertiesOnADestroyedObject(assert) {
if (true
/* DEBUG */
) {
var obj = _object.default.extend({
fooDidChange: (0, _metal.observer)('foo', function () {})
}).create({
foo: 'bar'
});
(0, _runloop.run)(function () {
return obj.destroy();
});
assert.throws(function () {
return (0, _metal.set)(obj, 'foo', 'baz');
}, Error, 'raises an exception');
} else {
assert.expect(0);
}
};
_proto['@test observers should not fire after an object has been destroyed'] = function testObserversShouldNotFireAfterAnObjectHasBeenDestroyed(assert) {
var count = 0;
var obj = _object.default.extend({
fooDidChange: (0, _metal.observer)('foo', function () {
count++;
})
}).create();
obj.set('foo', 'bar');
assert.equal(count, 1, 'observer was fired once');
(0, _runloop.run)(function () {
(0, _metal.beginPropertyChanges)();
obj.set('foo', 'quux');
obj.destroy();
(0, _metal.endPropertyChanges)();
});
assert.equal(count, 1, 'observer was not called after object was destroyed');
};
_proto['@test destroyed objects should not see each others changes during teardown but a long lived object should'] = function testDestroyedObjectsShouldNotSeeEachOthersChangesDuringTeardownButALongLivedObjectShould(assert) {
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, _metal.observer)('objs.b.isAlive', function () {
shouldNotChange++;
}),
cDidChange: (0, _metal.observer)('objs.c.isAlive', function () {
shouldNotChange++;
})
});
var B = _object.default.extend({
objs: objs,
isAlive: true,
willDestroy: function () {
this.set('isAlive', false);
},
aDidChange: (0, _metal.observer)('objs.a.isAlive', function () {
shouldNotChange++;
}),
cDidChange: (0, _metal.observer)('objs.c.isAlive', function () {
shouldNotChange++;
})
});
var C = _object.default.extend({
objs: objs,
isAlive: true,
willDestroy: function () {
this.set('isAlive', false);
},
aDidChange: (0, _metal.observer)('objs.a.isAlive', function () {
shouldNotChange++;
}),
bDidChange: (0, _metal.observer)('objs.b.isAlive', function () {
shouldNotChange++;
})
});
var LongLivedObject = _object.default.extend({
objs: objs,
isAliveDidChange: (0, _metal.observer)('objs.a.isAlive', function () {
shouldChange++;
})
});
objs.a = A.create();
objs.b = B.create();
objs.c = C.create();
LongLivedObject.create();
(0, _runloop.run)(function () {
var keys = Object.keys(objs);
for (var i = 0; i < keys.length; i++) {
objs[keys[i]].destroy();
}
});
assert.equal(shouldNotChange, 0, 'destroyed graph objs should not see change in willDestroy');
assert.equal(shouldChange, 1, 'long lived should see change in willDestroy');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/detectInstance_test", ["ember-babel", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('system/object/detectInstance',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test detectInstance detects instances correctly'] = function testDetectInstanceDetectsInstancesCorrectly(assert) {
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();
assert.ok(_object.default.detectInstance(o), 'o is an instance of EmberObject');
assert.ok(_object.default.detectInstance(a), 'a is an instance of EmberObject');
assert.ok(_object.default.detectInstance(b), 'b is an instance of EmberObject');
assert.ok(_object.default.detectInstance(c), 'c is an instance of EmberObject');
assert.ok(!A.detectInstance(o), 'o is not an instance of A');
assert.ok(A.detectInstance(a), 'a is an instance of A');
assert.ok(A.detectInstance(b), 'b is an instance of A');
assert.ok(A.detectInstance(c), 'c is an instance of A');
assert.ok(!B.detectInstance(o), 'o is not an instance of B');
assert.ok(!B.detectInstance(a), 'a is not an instance of B');
assert.ok(B.detectInstance(b), 'b is an instance of B');
assert.ok(!B.detectInstance(c), 'c is not an instance of B');
assert.ok(!C.detectInstance(o), 'o is not an instance of C');
assert.ok(!C.detectInstance(a), 'a is not an instance of C');
assert.ok(!C.detectInstance(b), 'b is not an instance of C');
assert.ok(C.detectInstance(c), 'c is an instance of C');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/detect_test", ["ember-babel", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('system/object/detect',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test detect detects classes correctly'] = function testDetectDetectsClassesCorrectly(assert) {
var A = _object.default.extend();
var B = A.extend();
var C = A.extend();
assert.ok(_object.default.detect(_object.default), 'EmberObject is an EmberObject class');
assert.ok(_object.default.detect(A), 'A is an EmberObject class');
assert.ok(_object.default.detect(B), 'B is an EmberObject class');
assert.ok(_object.default.detect(C), 'C is an EmberObject class');
assert.ok(!A.detect(_object.default), 'EmberObject is not an A class');
assert.ok(A.detect(A), 'A is an A class');
assert.ok(A.detect(B), 'B is an A class');
assert.ok(A.detect(C), 'C is an A class');
assert.ok(!B.detect(_object.default), 'EmberObject is not a B class');
assert.ok(!B.detect(A), 'A is not a B class');
assert.ok(B.detect(B), 'B is a B class');
assert.ok(!B.detect(C), 'C is not a B class');
assert.ok(!C.detect(_object.default), 'EmberObject is not a C class');
assert.ok(!C.detect(A), 'A is not a C class');
assert.ok(!C.detect(B), 'B is not a C class');
assert.ok(C.detect(C), 'C is a C class');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/es-compatibility-test", ["ember-babel", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/metal", "internal-test-helpers"], function (_emberBabel, _object, _metal, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('EmberObject ES Compatibility',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test extending an Ember.Object'] = function testExtendingAnEmberObject(assert) {
var calls = [];
var MyObject =
/*#__PURE__*/
function (_EmberObject) {
(0, _emberBabel.inheritsLoose)(MyObject, _EmberObject);
function MyObject() {
var _this;
calls.push('constructor');
_this = _EmberObject.apply(this, arguments) || this;
_this.postInitProperty = 'post-init-property';
return _this;
}
var _proto2 = MyObject.prototype;
_proto2.init = function init() {
calls.push('init');
_EmberObject.prototype.init.apply(this, 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)');
};
_proto['@test normal method super'] = function testNormalMethodSuper(assert) {
var calls = [];
var Foo = _object.default.extend({
method: function () {
calls.push('foo');
}
});
var Bar = Foo.extend({
method: function () {
this._super();
calls.push('bar');
}
});
var Baz =
/*#__PURE__*/
function (_Bar) {
(0, _emberBabel.inheritsLoose)(Baz, _Bar);
function Baz() {
return _Bar.apply(this, arguments) || this;
}
var _proto3 = Baz.prototype;
_proto3.method = function method() {
_Bar.prototype.method.call(this);
calls.push('baz');
};
return Baz;
}(Bar);
var Qux = Baz.extend({
method: function () {
this._super();
calls.push('qux');
}
});
var Quux = Qux.extend({
method: function () {
this._super();
calls.push('quux');
}
});
var Corge =
/*#__PURE__*/
function (_Quux) {
(0, _emberBabel.inheritsLoose)(Corge, _Quux);
function Corge() {
return _Quux.apply(this, arguments) || this;
}
var _proto4 = Corge.prototype;
_proto4.method = function method() {
_Quux.prototype.method.call(this);
calls.push('corge');
};
return Corge;
}(Quux);
var callValues = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge'];
[Foo, Bar, Baz, Qux, Quux, Corge].forEach(function (Class, index) {
calls = [];
Class.create().method();
assert.deepEqual(calls, callValues.slice(0, index + 1), 'chain of static methods called with super');
});
};
_proto['@test static method super'] = function testStaticMethodSuper(assert) {
var calls;
var Foo = _object.default.extend();
Foo.reopenClass({
method: function () {
calls.push('foo');
}
});
var Bar = Foo.extend();
Bar.reopenClass({
method: function () {
this._super();
calls.push('bar');
}
});
var Baz =
/*#__PURE__*/
function (_Bar2) {
(0, _emberBabel.inheritsLoose)(Baz, _Bar2);
function Baz() {
return _Bar2.apply(this, arguments) || this;
}
Baz.method = function method() {
_Bar2.method.call(this);
calls.push('baz');
};
return Baz;
}(Bar);
var Qux = Baz.extend();
Qux.reopenClass({
method: function () {
this._super();
calls.push('qux');
}
});
var Quux = Qux.extend();
Quux.reopenClass({
method: function () {
this._super();
calls.push('quux');
}
});
var Corge =
/*#__PURE__*/
function (_Quux2) {
(0, _emberBabel.inheritsLoose)(Corge, _Quux2);
function Corge() {
return _Quux2.apply(this, arguments) || this;
}
Corge.method = function method() {
_Quux2.method.call(this);
calls.push('corge');
};
return Corge;
}(Quux);
var callValues = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge'];
[Foo, Bar, Baz, Qux, Quux, Corge].forEach(function (Class, index) {
calls = [];
Class.method();
assert.deepEqual(calls, callValues.slice(0, index + 1), 'chain of static methods called with super');
});
};
_proto['@test using mixins'] = function testUsingMixins(assert) {
var Mixin1 = _metal.Mixin.create({
property1: 'data-1'
});
var Mixin2 = _metal.Mixin.create({
property2: 'data-2'
});
var MyObject =
/*#__PURE__*/
function (_EmberObject$extend) {
(0, _emberBabel.inheritsLoose)(MyObject, _EmberObject$extend);
function MyObject() {
return _EmberObject$extend.apply(this, arguments) || this;
}
return MyObject;
}(_object.default.extend(Mixin1, Mixin2));
var myObject = MyObject.create();
assert.equal(myObject.property1, 'data-1', 'includes the first mixin');
assert.equal(myObject.property2, 'data-2', 'includes the second mixin');
};
_proto['@test using instanceof'] = function testUsingInstanceof(assert) {
var MyObject =
/*#__PURE__*/
function (_EmberObject2) {
(0, _emberBabel.inheritsLoose)(MyObject, _EmberObject2);
function MyObject() {
return _EmberObject2.apply(this, arguments) || this;
}
return MyObject;
}(_object.default);
var myObject = MyObject.create();
assert.ok(myObject instanceof MyObject);
assert.ok(myObject instanceof _object.default);
};
_proto['@test using Ember.Object#detect'] = function testUsingEmberObjectDetect(assert) {
var Parent = _object.default.extend();
var Child =
/*#__PURE__*/
function (_Parent) {
(0, _emberBabel.inheritsLoose)(Child, _Parent);
function Child() {
return _Parent.apply(this, arguments) || this;
}
return Child;
}(Parent);
var Grandchild = Child.extend();
assert.ok(Parent.detect(Child), 'Parent.detect(Child)');
assert.ok(Child.detect(Grandchild), 'Child.detect(Grandchild)');
};
_proto['@test extending an ES subclass of EmberObject'] = function testExtendingAnESSubclassOfEmberObject(assert) {
var calls = [];
var SubEmberObject =
/*#__PURE__*/
function (_EmberObject3) {
(0, _emberBabel.inheritsLoose)(SubEmberObject, _EmberObject3);
function SubEmberObject() {
calls.push('constructor');
return _EmberObject3.apply(this, arguments) || this;
}
var _proto5 = SubEmberObject.prototype;
_proto5.init = function init() {
calls.push('init');
_EmberObject3.prototype.init.apply(this, arguments);
};
return SubEmberObject;
}(_object.default);
var MyObject =
/*#__PURE__*/
function (_SubEmberObject) {
(0, _emberBabel.inheritsLoose)(MyObject, _SubEmberObject);
function MyObject() {
return _SubEmberObject.apply(this, arguments) || this;
}
return MyObject;
}(SubEmberObject);
MyObject.create();
assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (create)');
};
_proto['@test calling extend on an ES subclass of EmberObject'] = function testCallingExtendOnAnESSubclassOfEmberObject(assert) {
var calls = [];
var SubEmberObject =
/*#__PURE__*/
function (_EmberObject4) {
(0, _emberBabel.inheritsLoose)(SubEmberObject, _EmberObject4);
function SubEmberObject() {
var _this2;
calls.push('before constructor');
_this2 = _EmberObject4.apply(this, arguments) || this;
calls.push('after constructor');
_this2.foo = 123;
return _this2;
}
var _proto6 = SubEmberObject.prototype;
_proto6.init = function init() {
calls.push('init');
_EmberObject4.prototype.init.apply(this, arguments);
};
return SubEmberObject;
}(_object.default);
var MyObject = SubEmberObject.extend({});
MyObject.create();
assert.deepEqual(calls, ['before constructor', 'after constructor', 'init'], 'constructor then init called (create)');
var obj = MyObject.create({
foo: 456,
bar: 789
});
assert.equal(obj.foo, 456, 'sets class fields on instance correctly');
assert.equal(obj.bar, 789, 'sets passed in properties on instance correctly');
};
_proto['@test calling metaForProperty on a native class works'] = function testCallingMetaForPropertyOnANativeClassWorks(assert) {
assert.expect(0);
var SubEmberObject =
/*#__PURE__*/
function (_EmberObject5) {
(0, _emberBabel.inheritsLoose)(SubEmberObject, _EmberObject5);
function SubEmberObject() {
return _EmberObject5.apply(this, arguments) || this;
}
return SubEmberObject;
}(_object.default);
(0, _metal.defineProperty)(SubEmberObject.prototype, 'foo', (0, _metal.computed)('foo', {
get: function () {
return 'bar';
}
})); // able to get meta without throwing an error
SubEmberObject.metaForProperty('foo');
};
_proto['@test observes / removeObserver on / removeListener interop'] = function testObservesRemoveObserverOnRemoveListenerInterop(assert) {
var fooDidChangeBase = 0;
var fooDidChangeA = 0;
var fooDidChangeB = 0;
var someEventBase = 0;
var someEventA = 0;
var someEventB = 0;
var A =
/*#__PURE__*/
function (_EmberObject$extend2) {
(0, _emberBabel.inheritsLoose)(A, _EmberObject$extend2);
function A() {
return _EmberObject$extend2.apply(this, arguments) || this;
}
var _proto7 = A.prototype;
_proto7.init = function init() {
_EmberObject$extend2.prototype.init.call(this);
this.foo = 'bar';
};
_proto7.fooDidChange = function fooDidChange() {
_EmberObject$extend2.prototype.fooDidChange.call(this);
fooDidChangeA++;
};
_proto7.onSomeEvent = function onSomeEvent() {
_EmberObject$extend2.prototype.onSomeEvent.call(this);
someEventA++;
};
return A;
}(_object.default.extend({
fooDidChange: (0, _metal.observer)('foo', function () {
fooDidChangeBase++;
}),
onSomeEvent: (0, _metal.on)('someEvent', function () {
someEventBase++;
})
}));
var B =
/*#__PURE__*/
function (_A) {
(0, _emberBabel.inheritsLoose)(B, _A);
function B() {
return _A.apply(this, arguments) || this;
}
var _proto8 = B.prototype;
_proto8.fooDidChange = function fooDidChange() {
_A.prototype.fooDidChange.call(this);
fooDidChangeB++;
};
_proto8.onSomeEvent = function onSomeEvent() {
_A.prototype.onSomeEvent.call(this);
someEventB++;
};
return B;
}(A);
(0, _metal.removeObserver)(B.prototype, 'foo', null, 'fooDidChange');
(0, _metal.removeListener)(B.prototype, 'someEvent', null, 'onSomeEvent');
assert.equal(fooDidChangeBase, 0);
assert.equal(fooDidChangeA, 0);
assert.equal(fooDidChangeB, 0);
assert.equal(someEventBase, 0);
assert.equal(someEventA, 0);
assert.equal(someEventB, 0);
var a = A.create();
a.set('foo', 'something');
assert.equal(fooDidChangeBase, 1);
assert.equal(fooDidChangeA, 1);
assert.equal(fooDidChangeB, 0);
(0, _metal.sendEvent)(a, 'someEvent');
assert.equal(someEventBase, 1);
assert.equal(someEventA, 1);
assert.equal(someEventB, 0);
var b = B.create();
b.set('foo', 'something');
assert.equal(fooDidChangeBase, 1);
assert.equal(fooDidChangeA, 1);
assert.equal(fooDidChangeB, 0);
(0, _metal.sendEvent)(b, 'someEvent');
assert.equal(someEventBase, 1);
assert.equal(someEventA, 1);
assert.equal(someEventB, 0);
};
_proto['@test super and _super interop between old and new methods'] = function testSuperAnd_superInteropBetweenOldAndNewMethods(assert) {
var calls = [];
var changes = [];
var events = [];
var lastProps;
var A =
/*#__PURE__*/
function (_EmberObject6) {
(0, _emberBabel.inheritsLoose)(A, _EmberObject6);
function A() {
return _EmberObject6.apply(this, arguments) || this;
}
var _proto9 = A.prototype;
_proto9.init = function init(props) {
calls.push('A init');
lastProps = props;
};
return A;
}(_object.default);
var Mixin1 = _metal.Mixin.create({
init: function () {
calls.push('Mixin1 init before _super');
this._super.apply(this, arguments);
calls.push('Mixin1 init after _super');
}
});
var Mixin2 = _metal.Mixin.create({
init: function () {
calls.push('Mixin2 init before _super');
this._super.apply(this, arguments);
calls.push('Mixin2 init after _super');
}
});
var B =
/*#__PURE__*/
function (_A$extend) {
(0, _emberBabel.inheritsLoose)(B, _A$extend);
function B() {
return _A$extend.apply(this, arguments) || this;
}
var _proto10 = B.prototype;
_proto10.init = function init() {
calls.push('B init before super.init');
_A$extend.prototype.init.apply(this, arguments);
calls.push('B init after super.init');
};
_proto10.onSomeEvent = function onSomeEvent(evt) {
events.push("B onSomeEvent " + evt);
};
_proto10.fullNameDidChange = function fullNameDidChange() {
changes.push('B fullNameDidChange');
};
return B;
}(A.extend(Mixin1, Mixin2)); // // define a CP
(0, _metal.defineProperty)(B.prototype, 'full', (0, _metal.computed)('first', 'last', {
get: function () {
return this.first + ' ' + this.last;
}
})); // Only string observers are allowed for prototypes
(0, _metal.addObserver)(B.prototype, 'full', null, 'fullNameDidChange'); // Only string listeners are allowed for prototypes
(0, _metal.addListener)(B.prototype, 'someEvent', null, 'onSomeEvent');
B.reopen({
init: function () {
calls.push('reopen init before _super');
this._super.apply(this, arguments);
calls.push('reopen init after _super');
}
});
var C = B.extend({
init: function () {
calls.push('C init before _super');
this._super.apply(this, arguments);
calls.push('C init after _super');
},
onSomeEvent: function (evt) {
calls.push('C onSomeEvent before _super');
this._super(evt);
calls.push('C onSomeEvent after _super');
},
fullNameDidChange: function () {
calls.push('C fullNameDidChange before _super');
this._super();
calls.push('C fullNameDidChange after _super');
}
});
var D =
/*#__PURE__*/
function (_C) {
(0, _emberBabel.inheritsLoose)(D, _C);
function D() {
return _C.apply(this, arguments) || this;
}
var _proto11 = D.prototype;
_proto11.init = function init() {
calls.push('D init before super.init');
_C.prototype.init.apply(this, arguments);
calls.push('D init after super.init');
};
_proto11.onSomeEvent = function onSomeEvent(evt) {
events.push('D onSomeEvent before super.onSomeEvent');
_C.prototype.onSomeEvent.call(this, evt);
events.push('D onSomeEvent after super.onSomeEvent');
};
_proto11.fullNameDidChange = function fullNameDidChange() {
changes.push('D fullNameDidChange before super.fullNameDidChange');
_C.prototype.fullNameDidChange.call(this);
changes.push('D fullNameDidChange after super.fullNameDidChange');
};
_proto11.triggerSomeEvent = function triggerSomeEvent() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
(0, _metal.sendEvent)(this, 'someEvent', args);
};
return D;
}(C);
assert.deepEqual(calls, [], 'nothing has been called');
assert.deepEqual(changes, [], 'full has not changed');
assert.deepEqual(events, [], 'onSomeEvent has not been triggered');
var d = D.create({
first: 'Robert',
last: 'Jackson'
});
assert.deepEqual(calls, ['D init before super.init', 'C init before _super', 'reopen init before _super', 'B init before super.init', 'Mixin2 init before _super', 'Mixin1 init before _super', 'A init', 'Mixin1 init after _super', 'Mixin2 init after _super', 'B init after super.init', 'reopen init after _super', 'C init after _super', 'D init after super.init']);
assert.deepEqual(changes, [], 'full has not changed');
assert.deepEqual(events, [], 'onSomeEvent has not been triggered');
assert.deepEqual(lastProps, {
first: 'Robert',
last: 'Jackson'
});
assert.equal(d.full, 'Robert Jackson');
d.setProperties({
first: 'Kris',
last: 'Selden'
});
assert.deepEqual(changes, ['D fullNameDidChange before super.fullNameDidChange', 'B fullNameDidChange', 'D fullNameDidChange after super.fullNameDidChange']);
assert.equal(d.full, 'Kris Selden');
d.triggerSomeEvent('event arg');
assert.deepEqual(events, ['D onSomeEvent before super.onSomeEvent', 'B onSomeEvent event arg', 'D onSomeEvent after super.onSomeEvent']);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/events_test", ["ember-babel", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/mixins/evented", "internal-test-helpers"], function (_emberBabel, _object, _evented, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Object events',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test a listener can be added to an object'] = function testAListenerCanBeAddedToAnObject(assert) {
var count = 0;
var F = function () {
count++;
};
var obj = _object.default.extend(_evented.default).create();
obj.on('event!', F);
obj.trigger('event!');
assert.equal(count, 1, 'the event was triggered');
obj.trigger('event!');
assert.equal(count, 2, 'the event was triggered');
};
_proto['@test a listener can be added and removed automatically the first time it is triggered'] = function testAListenerCanBeAddedAndRemovedAutomaticallyTheFirstTimeItIsTriggered(assert) {
var count = 0;
var F = function () {
count++;
};
var obj = _object.default.extend(_evented.default).create();
obj.one('event!', F);
obj.trigger('event!');
assert.equal(count, 1, 'the event was triggered');
obj.trigger('event!');
assert.equal(count, 1, 'the event was not triggered again');
};
_proto['@test triggering an event can have arguments'] = function testTriggeringAnEventCanHaveArguments(assert) {
var self, args;
var obj = _object.default.extend(_evented.default).create();
obj.on('event!', function () {
args = [].slice.call(arguments);
self = this;
});
obj.trigger('event!', 'foo', 'bar');
assert.deepEqual(args, ['foo', 'bar']);
assert.equal(self, obj);
};
_proto['@test a listener can be added and removed automatically and have arguments'] = function testAListenerCanBeAddedAndRemovedAutomaticallyAndHaveArguments(assert) {
var self, args;
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');
assert.deepEqual(args, ['foo', 'bar']);
assert.equal(self, obj);
assert.equal(count, 1, 'the event is triggered once');
obj.trigger('event!', 'baz', 'bat');
assert.deepEqual(args, ['foo', 'bar']);
assert.equal(count, 1, 'the event was not triggered again');
assert.equal(self, obj);
};
_proto['@test binding an event can specify a different target'] = function testBindingAnEventCanSpecifyADifferentTarget(assert) {
var self, args;
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');
assert.deepEqual(args, ['foo', 'bar']);
assert.equal(self, target);
};
_proto['@test a listener registered with one can take method as string and can be added with different target'] = function testAListenerRegisteredWithOneCanTakeMethodAsStringAndCanBeAddedWithDifferentTarget(assert) {
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!');
assert.equal(count, 1, 'the event was triggered');
obj.trigger('event!');
assert.equal(count, 1, 'the event was not triggered again');
};
_proto['@test a listener registered with one can be removed with off'] = function testAListenerRegisteredWithOneCanBeRemovedWithOff(assert) {
var obj = _object.default.extend(_evented.default, {
F: function () {}
}).create();
var F = function () {};
obj.one('event!', F);
obj.one('event!', obj, 'F');
assert.equal(obj.has('event!'), true, 'has events');
obj.off('event!', F);
obj.off('event!', obj, 'F');
assert.equal(obj.has('event!'), false, 'has no more events');
};
_proto['@test adding and removing listeners should be chainable'] = function testAddingAndRemovingListenersShouldBeChainable(assert) {
var obj = _object.default.extend(_evented.default).create();
var F = function () {};
var ret = obj.on('event!', F);
assert.equal(ret, obj, '#on returns self');
ret = obj.off('event!', F);
assert.equal(ret, obj, '#off returns self');
ret = obj.one('event!', F);
assert.equal(ret, obj, '#one returns self');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/extend_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _metal, _object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('EmberObject.extend',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Basic extend'] = function testBasicExtend(assert) {
var SomeClass = _object.default.extend({
foo: 'BAR'
});
assert.ok(SomeClass.isClass, 'A class has isClass of true');
var obj = SomeClass.create();
assert.equal(obj.foo, 'BAR');
};
_proto['@test Sub-subclass'] = function testSubSubclass(assert) {
var SomeClass = _object.default.extend({
foo: 'BAR'
});
var AnotherClass = SomeClass.extend({
bar: 'FOO'
});
var obj = AnotherClass.create();
assert.equal(obj.foo, 'BAR');
assert.equal(obj.bar, 'FOO');
};
_proto['@test Overriding a method several layers deep'] = function testOverridingAMethodSeveralLayersDeep(assert) {
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 = FinalClass.create();
obj.foo();
obj.bar();
assert.equal(obj.fooCnt, 2, 'should invoke both');
assert.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();
assert.equal(obj.fooCnt, 3, 'should invoke final as well');
assert.equal(obj.barCnt, 2, 'should invoke both');
};
_proto['@test With concatenatedProperties'] = function testWithConcatenatedProperties(assert) {
var SomeClass = _object.default.extend({
things: 'foo',
concatenatedProperties: ['things']
});
var AnotherClass = SomeClass.extend({
things: 'bar'
});
var YetAnotherClass = SomeClass.extend({
things: 'baz'
});
var some = SomeClass.create();
var another = AnotherClass.create();
var yetAnother = YetAnotherClass.create();
assert.deepEqual(some.get('things'), ['foo'], 'base class should have just its value');
assert.deepEqual(another.get('things'), ['foo', 'bar'], "subclass should have base class' and its own");
assert.deepEqual(yetAnother.get('things'), ['foo', 'baz'], "subclass should have base class' and its own");
};
_proto['@test With concatenatedProperties class properties'] = function testWithConcatenatedPropertiesClassProperties(assert) {
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 = SomeClass.create();
var another = AnotherClass.create();
var yetAnother = YetAnotherClass.create();
assert.deepEqual((0, _metal.get)(some.constructor, 'things'), ['foo'], 'base class should have just its value');
assert.deepEqual((0, _metal.get)(another.constructor, 'things'), ['foo', 'bar'], "subclass should have base class' and its own");
assert.deepEqual((0, _metal.get)(yetAnother.constructor, 'things'), ['foo', 'baz'], "subclass should have base class' and its own");
};
_proto['@test Overriding a computed property with an observer'] = function testOverridingAComputedPropertyWithAnObserver(assert) {
var Parent = _object.default.extend({
foo: (0, _metal.computed)(function () {
return 'FOO';
})
});
var seen = [];
var Child = Parent.extend({
foo: (0, _metal.observer)('bar', function () {
seen.push(this.get('bar'));
})
});
var child = Child.create({
bar: 0
});
assert.deepEqual(seen, []);
child.set('bar', 1);
assert.deepEqual(seen, [1]);
child.set('bar', 2);
assert.deepEqual(seen, [1, 2]);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/observer_test", ["ember-babel", "@ember/runloop", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _runloop, _metal, _object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('EmberObject observer',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test observer on class'] = function testObserverOnClass(assert) {
var MyClass = _object.default.extend({
count: 0,
foo: (0, _metal.observer)('bar', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj = MyClass.create();
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj, 'bar', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
_proto['@test observer on subclass'] = function testObserverOnSubclass(assert) {
var MyClass = _object.default.extend({
count: 0,
foo: (0, _metal.observer)('bar', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var Subclass = MyClass.extend({
foo: (0, _metal.observer)('baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj = Subclass.create();
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj, 'bar', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer after change');
(0, _metal.set)(obj, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
_proto['@test observer on instance'] = function testObserverOnInstance(assert) {
var obj = _object.default.extend({
foo: (0, _metal.observer)('bar', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
}).create({
count: 0
});
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj, 'bar', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
_proto['@test observer on instance overriding class'] = function testObserverOnInstanceOverridingClass(assert) {
var MyClass = _object.default.extend({
count: 0,
foo: (0, _metal.observer)('bar', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj = MyClass.extend({
foo: (0, _metal.observer)('baz', function () {
// <-- change property we observe
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
}).create();
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer immediately');
(0, _metal.set)(obj, 'bar', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer after change');
(0, _metal.set)(obj, 'baz', 'BAZ');
assert.equal((0, _metal.get)(obj, 'count'), 1, 'should invoke observer after change');
};
_proto['@test observer should not fire after being destroyed'] = function testObserverShouldNotFireAfterBeingDestroyed(assert) {
var obj = _object.default.extend({
count: 0,
foo: (0, _metal.observer)('bar', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
}).create();
assert.equal((0, _metal.get)(obj, 'count'), 0, 'precond - should not invoke observer immediately');
(0, _runloop.run)(function () {
return obj.destroy();
});
expectAssertion(function () {
(0, _metal.set)(obj, 'bar', 'BAZ');
}, "calling set on destroyed object: " + obj + ".bar = BAZ");
assert.equal((0, _metal.get)(obj, 'count'), 0, 'should not invoke observer after change');
} // ..........................................................
// COMPLEX PROPERTIES
//
;
_proto['@test chain observer on class'] = function testChainObserverOnClass(assert) {
var MyClass = _object.default.extend({
count: 0,
foo: (0, _metal.observer)('bar.baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj1 = MyClass.create({
bar: {
baz: 'biff'
}
});
var obj2 = MyClass.create({
bar: {
baz: 'biff2'
}
});
assert.equal((0, _metal.get)(obj1, 'count'), 0, 'should not invoke yet');
assert.equal((0, _metal.get)(obj2, 'count'), 0, 'should not invoke yet');
(0, _metal.set)((0, _metal.get)(obj1, 'bar'), 'baz', 'BIFF1');
assert.equal((0, _metal.get)(obj1, 'count'), 1, 'should invoke observer on obj1');
assert.equal((0, _metal.get)(obj2, 'count'), 0, 'should not invoke yet');
(0, _metal.set)((0, _metal.get)(obj2, 'bar'), 'baz', 'BIFF2');
assert.equal((0, _metal.get)(obj1, 'count'), 1, 'should not invoke again');
assert.equal((0, _metal.get)(obj2, 'count'), 1, 'should invoke observer on obj2');
};
_proto['@test chain observer on class'] = function testChainObserverOnClass(assert) {
var MyClass = _object.default.extend({
count: 0,
foo: (0, _metal.observer)('bar.baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
});
var obj1 = MyClass.extend().create({
bar: {
baz: 'biff'
}
});
var obj2 = MyClass.extend({
foo: (0, _metal.observer)('bar2.baz', function () {
(0, _metal.set)(this, 'count', (0, _metal.get)(this, 'count') + 1);
})
}).create({
bar: {
baz: 'biff2'
},
bar2: {
baz: 'biff3'
}
});
assert.equal((0, _metal.get)(obj1, 'count'), 0, 'should not invoke yet');
assert.equal((0, _metal.get)(obj2, 'count'), 0, 'should not invoke yet');
(0, _metal.set)((0, _metal.get)(obj1, 'bar'), 'baz', 'BIFF1');
assert.equal((0, _metal.get)(obj1, 'count'), 1, 'should invoke observer on obj1');
assert.equal((0, _metal.get)(obj2, 'count'), 0, 'should not invoke yet');
(0, _metal.set)((0, _metal.get)(obj2, 'bar'), 'baz', 'BIFF2');
assert.equal((0, _metal.get)(obj1, 'count'), 1, 'should not invoke again');
assert.equal((0, _metal.get)(obj2, 'count'), 0, 'should not invoke yet');
(0, _metal.set)((0, _metal.get)(obj2, 'bar2'), 'baz', 'BIFF3');
assert.equal((0, _metal.get)(obj1, 'count'), 1, 'should not invoke again');
assert.equal((0, _metal.get)(obj2, 'count'), 1, 'should invoke observer on obj2');
};
_proto['@test chain observer on class that has a reference to an uninitialized object will finish chains that reference it'] = function testChainObserverOnClassThatHasAReferenceToAnUninitializedObjectWillFinishChainsThatReferenceIt(assert) {
var changed = false;
var ChildClass = _object.default.extend({
parent: null,
parentOneTwoDidChange: (0, _metal.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 = ParentClass.create();
assert.equal(changed, false, 'precond');
(0, _metal.set)(parent, 'one.two', 'new');
assert.equal(changed, true, 'child should have been notified of change to path');
(0, _metal.set)(parent, 'one', {
two: 'newer'
});
assert.equal(changed, true, 'child should have been notified of change to path');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/reopenClass_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _metal, _object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('system/object/reopenClass',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test adds new properties to subclass'] = function testAddsNewPropertiesToSubclass(assert) {
var Subclass = _object.default.extend();
Subclass.reopenClass({
foo: function () {
return 'FOO';
},
bar: 'BAR'
});
assert.equal(Subclass.foo(), 'FOO', 'Adds method');
assert.equal((0, _metal.get)(Subclass, 'bar'), 'BAR', 'Adds property');
};
_proto['@test class properties inherited by subclasses'] = function testClassPropertiesInheritedBySubclasses(assert) {
var Subclass = _object.default.extend();
Subclass.reopenClass({
foo: function () {
return 'FOO';
},
bar: 'BAR'
});
var SubSub = Subclass.extend();
assert.equal(SubSub.foo(), 'FOO', 'Adds method');
assert.equal((0, _metal.get)(SubSub, 'bar'), 'BAR', 'Adds property');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/reopen_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _metal, _object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('system/core_object/reopen',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test adds new properties to subclass instance'] = function testAddsNewPropertiesToSubclassInstance(assert) {
var Subclass = _object.default.extend();
Subclass.reopen({
foo: function () {
return 'FOO';
},
bar: 'BAR'
});
assert.equal(Subclass.create().foo(), 'FOO', 'Adds method');
assert.equal((0, _metal.get)(Subclass.create(), 'bar'), 'BAR', 'Adds property');
};
_proto['@test reopened properties inherited by subclasses'] = function testReopenedPropertiesInheritedBySubclasses(assert) {
var Subclass = _object.default.extend();
var SubSub = Subclass.extend();
Subclass.reopen({
foo: function () {
return 'FOO';
},
bar: 'BAR'
});
assert.equal(SubSub.create().foo(), 'FOO', 'Adds method');
assert.equal((0, _metal.get)(SubSub.create(), 'bar'), 'BAR', 'Adds property');
};
_proto['@test allows reopening already instantiated classes'] = function testAllowsReopeningAlreadyInstantiatedClasses(assert) {
var Subclass = _object.default.extend();
Subclass.create();
Subclass.reopen({
trololol: true
});
assert.equal(Subclass.create().get('trololol'), true, 'reopen works');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/strict-mode-test", ["ember-babel", "@ember/-internals/runtime/lib/system/object", "internal-test-helpers"], function (_emberBabel, _object, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('strict mode tests',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test __superWrapper does not throw errors in strict mode'] = function test__superWrapperDoesNotThrowErrorsInStrictMode(assert) {
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();
assert.equal(bar.callBlah(), 'bar', 'can call local function without call/apply');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object/toString_test", ["ember-babel", "@ember/runloop", "@ember/-internals/utils", "@ember/-internals/environment", "@ember/-internals/runtime/lib/system/object", "@ember/-internals/runtime/lib/system/namespace", "internal-test-helpers"], function (_emberBabel, _runloop, _utils, _environment, _object, _namespace, _internalTestHelpers) {
"use strict";
var originalLookup = _environment.context.lookup;
var lookup;
(0, _internalTestHelpers.moduleFor)('system/object/toString',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
_environment.context.lookup = lookup = {};
};
_proto.afterEach = function afterEach() {
_environment.context.lookup = originalLookup;
};
_proto['@test toString() returns the same value if called twice'] = function testToStringReturnsTheSameValueIfCalledTwice(assert) {
var Foo = _namespace.default.create();
Foo.toString = function () {
return 'Foo';
};
Foo.Bar = _object.default.extend();
assert.equal(Foo.Bar.toString(), 'Foo.Bar');
assert.equal(Foo.Bar.toString(), 'Foo.Bar');
var obj = Foo.Bar.create();
assert.equal(obj.toString(), '');
assert.equal(obj.toString(), '');
assert.equal(Foo.Bar.toString(), 'Foo.Bar');
(0, _runloop.run)(Foo, 'destroy');
};
_proto['@test toString on a class returns a useful value when nested in a namespace'] = function testToStringOnAClassReturnsAUsefulValueWhenNestedInANamespace(assert) {
var obj;
var Foo = _namespace.default.create();
Foo.toString = function () {
return 'Foo';
};
Foo.Bar = _object.default.extend();
assert.equal(Foo.Bar.toString(), 'Foo.Bar');
obj = Foo.Bar.create();
assert.equal(obj.toString(), '');
Foo.Baz = Foo.Bar.extend();
assert.equal(Foo.Baz.toString(), 'Foo.Baz');
obj = Foo.Baz.create();
assert.equal(obj.toString(), '');
obj = Foo.Bar.create();
assert.equal(obj.toString(), '');
(0, _runloop.run)(Foo, 'destroy');
};
_proto['@test toString on a namespace finds the namespace in lookup'] = function testToStringOnANamespaceFindsTheNamespaceInLookup(assert) {
var Foo = lookup.Foo = _namespace.default.create();
assert.equal(Foo.toString(), 'Foo');
(0, _runloop.run)(Foo, 'destroy');
};
_proto['@test toString on a namespace finds the namespace in lookup'] = function testToStringOnANamespaceFindsTheNamespaceInLookup(assert) {
var Foo = lookup.Foo = _namespace.default.create();
var obj;
Foo.Bar = _object.default.extend();
assert.equal(Foo.Bar.toString(), 'Foo.Bar');
obj = Foo.Bar.create();
assert.equal(obj.toString(), '');
(0, _runloop.run)(Foo, 'destroy');
};
_proto['@test toString on a namespace falls back to modulePrefix, if defined'] = function testToStringOnANamespaceFallsBackToModulePrefixIfDefined(assert) {
var Foo = _namespace.default.create({
modulePrefix: 'foo'
});
assert.equal(Foo.toString(), 'foo');
(0, _runloop.run)(Foo, 'destroy');
};
_proto['@test toString includes toStringExtension if defined'] = function testToStringIncludesToStringExtensionIfDefined(assert) {
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
(0, _utils.setName)(Foo, 'Foo');
(0, _utils.setName)(Bar, 'Bar');
assert.equal(bar.toString(), '', 'does not include toStringExtension part');
assert.equal(foo.toString(), '', 'Includes toStringExtension result');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/runtime/tests/system/object_proxy_test", ["ember-babel", "@ember/-internals/metal", "@ember/-internals/utils", "@ember/-internals/runtime/lib/system/object_proxy", "internal-test-helpers"], function (_emberBabel, _metal, _utils, _object_proxy, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('ObjectProxy',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test should not proxy properties passed to create'] = function testShouldNotProxyPropertiesPassedToCreate(assert) {
var Proxy = _object_proxy.default.extend({
cp: (0, _metal.computed)({
get: function () {
return this._cp;
},
set: function (key, value) {
this._cp = value;
return this._cp;
}
})
});
var proxy = Proxy.create({
prop: 'Foo',
cp: 'Bar'
});
assert.equal((0, _metal.get)(proxy, 'prop'), 'Foo', 'should not have tried to proxy set');
assert.equal(proxy._cp, 'Bar', 'should use CP setter');
};
_proto['@test should proxy properties to content'] = function testShouldProxyPropertiesToContent(assert) {
var content = {
firstName: 'Tom',
lastName: 'Dale',
unknownProperty: function (key) {
return key + ' unknown';
}
};
var proxy = _object_proxy.default.create();
assert.equal((0, _metal.get)(proxy, 'firstName'), undefined, 'get on proxy without content should return undefined');
expectAssertion(function () {
(0, _metal.set)(proxy, 'firstName', 'Foo');
}, /Cannot delegate set\('firstName', Foo\) to the 'content'/i);
(0, _metal.set)(proxy, 'content', content);
assert.equal((0, _metal.get)(proxy, 'firstName'), 'Tom', 'get on proxy with content should forward to content');
assert.equal((0, _metal.get)(proxy, 'lastName'), 'Dale', 'get on proxy with content should forward to content');
assert.equal((0, _metal.get)(proxy, 'foo'), 'foo unknown', 'get on proxy with content should forward to content');
(0, _metal.set)(proxy, 'lastName', 'Huda');
assert.equal((0, _metal.get)(content, 'lastName'), 'Huda', 'content should have new value from set on proxy');
assert.equal((0, _metal.get)(proxy, 'lastName'), 'Huda', 'proxy should have new value from set on proxy');
(0, _metal.set)(proxy, 'content', {
firstName: 'Yehuda',
lastName: 'Katz'
});
assert.equal((0, _metal.get)(proxy, 'firstName'), 'Yehuda', 'proxy should reflect updated content');
assert.equal((0, _metal.get)(proxy, 'lastName'), 'Katz', 'proxy should reflect updated content');
};
_proto['@test getting proxied properties with Ember.get should work'] = function testGettingProxiedPropertiesWithEmberGetShouldWork(assert) {
var proxy = _object_proxy.default.create({
content: {
foo: 'FOO'
}
});
assert.equal((0, _metal.get)(proxy, 'foo'), 'FOO');
};
_proto["@test JSON.stringify doens't assert"] = function (assert) {
var proxy = _object_proxy.default.create({
content: {
foo: 'FOO'
}
});
assert.equal(JSON.stringify(proxy), JSON.stringify({
content: {
foo: 'FOO'
}
}));
};
_proto['@test calling a function on the proxy avoids the assertion'] = function testCallingAFunctionOnTheProxyAvoidsTheAssertion(assert) {
if (true
/* DEBUG */
&& _utils.HAS_NATIVE_PROXY) {
var proxy = _object_proxy.default.extend({
init: function () {
if (!this.foobar) {
this.foobar = function () {
var content = (0, _metal.get)(this, 'content');
return content.foobar.apply(content, []);
};
}
}
}).create({
content: {
foobar: function () {
return 'xoxo';
}
}
});
assert.equal(proxy.foobar(), 'xoxo', 'should be able to use a function from a proxy');
} else {
assert.expect(0);
}
};
_proto["@test setting a property on the proxy avoids the assertion"] = function (assert) {
var proxy = _object_proxy.default.create({
toJSON: undefined,
content: {
toJSON: function () {
return 'hello';
}
}
});
assert.equal(JSON.stringify(proxy), JSON.stringify({
content: 'hello'
}));
};
_proto["@test setting a property on the proxy's prototype avoids the assertion"] = function (assert) {
var proxy = _object_proxy.default.extend({
toJSON: null
}).create({
content: {
toJSON: function () {
return 'hello';
}
}
});
assert.equal(JSON.stringify(proxy), JSON.stringify({
content: 'hello'
}));
};
_proto['@test getting proxied properties with [] should be an error'] = function testGettingProxiedPropertiesWithShouldBeAnError(assert) {
if (true
/* DEBUG */
&& _utils.HAS_NATIVE_PROXY) {
var proxy = _object_proxy.default.create({
content: {
foo: 'FOO'
}
});
expectAssertion(function () {
return proxy.foo;
}, /\.get\('foo'\)/);
} else {
assert.expect(0);
}
};
_proto['@test should work with watched properties'] = function testShouldWorkWithWatchedProperties(assert) {
var content1 = {
firstName: 'Tom',
lastName: 'Dale'
};
var content2 = {
firstName: 'Yehuda',
lastName: 'Katz'
};
var count = 0;
var last;
var Proxy = _object_proxy.default.extend({
fullName: (0, _metal.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, _metal.addObserver)(proxy, 'fullName', function () {
last = (0, _metal.get)(proxy, 'fullName');
count++;
}); // proxy without content returns undefined
assert.equal((0, _metal.get)(proxy, 'fullName'), undefined); // setting content causes all watched properties to change
(0, _metal.set)(proxy, 'content', content1); // both dependent keys changed
assert.equal(count, 2);
assert.equal(last, 'Tom Dale'); // setting property in content causes proxy property to change
(0, _metal.set)(content1, 'lastName', 'Huda');
assert.equal(count, 3);
assert.equal(last, 'Tom Huda'); // replacing content causes all watched properties to change
(0, _metal.set)(proxy, 'content', content2); // both dependent keys changed
assert.equal(count, 5);
assert.equal(last, 'Yehuda Katz'); // content1 is no longer watched
assert.ok(!(0, _metal.isWatching)(content1, 'firstName'), 'not watching firstName');
assert.ok(!(0, _metal.isWatching)(content1, 'lastName'), 'not watching lastName'); // setting property in new content
(0, _metal.set)(content2, 'firstName', 'Tomhuda');
assert.equal(last, 'Tomhuda Katz');
assert.equal(count, 6); // setting property in proxy syncs with new content
(0, _metal.set)(proxy, 'lastName', 'Katzdale');
assert.equal(count, 7);
assert.equal(last, 'Tomhuda Katzdale');
assert.equal((0, _metal.get)(content2, 'firstName'), 'Tomhuda');
assert.equal((0, _metal.get)(content2, 'lastName'), 'Katzdale');
};
_proto['@test set and get should work with paths'] = function testSetAndGetShouldWorkWithPaths(assert) {
var content = {
foo: {
bar: 'baz'
}
};
var proxy = _object_proxy.default.create({
content: content
});
var count = 0;
proxy.set('foo.bar', 'hello');
assert.equal(proxy.get('foo.bar'), 'hello');
assert.equal(proxy.get('content.foo.bar'), 'hello');
proxy.addObserver('foo.bar', function () {
count++;
});
proxy.set('foo.bar', 'bye');
assert.equal(count, 1);
assert.equal(proxy.get('foo.bar'), 'bye');
assert.equal(proxy.get('content.foo.bar'), 'bye');
};
_proto['@test should transition between watched and unwatched strategies'] = function testShouldTransitionBetweenWatchedAndUnwatchedStrategies(assert) {
var content = {
foo: 'foo'
};
var proxy = _object_proxy.default.create({
content: content
});
var count = 0;
function observer() {
count++;
}
assert.equal((0, _metal.get)(proxy, 'foo'), 'foo');
(0, _metal.set)(content, 'foo', 'bar');
assert.equal((0, _metal.get)(proxy, 'foo'), 'bar');
(0, _metal.set)(proxy, 'foo', 'foo');
assert.equal((0, _metal.get)(content, 'foo'), 'foo');
assert.equal((0, _metal.get)(proxy, 'foo'), 'foo');
(0, _metal.addObserver)(proxy, 'foo', observer);
assert.equal(count, 0);
assert.equal((0, _metal.get)(proxy, 'foo'), 'foo');
(0, _metal.set)(content, 'foo', 'bar');
assert.equal(count, 1);
assert.equal((0, _metal.get)(proxy, 'foo'), 'bar');
(0, _metal.set)(proxy, 'foo', 'foo');
assert.equal(count, 2);
assert.equal((0, _metal.get)(content, 'foo'), 'foo');
assert.equal((0, _metal.get)(proxy, 'foo'), 'foo');
(0, _metal.removeObserver)(proxy, 'foo', observer);
(0, _metal.set)(content, 'foo', 'bar');
assert.equal((0, _metal.get)(proxy, 'foo'), 'bar');
(0, _metal.set)(proxy, 'foo', 'foo');
assert.equal((0, _metal.get)(content, 'foo'), 'foo');
assert.equal((0, _metal.get)(proxy, 'foo'), 'foo');
};
_proto['@test setting `undefined` to a proxied content property should override its existing value'] = function testSettingUndefinedToAProxiedContentPropertyShouldOverrideItsExistingValue(assert) {
var proxyObject = _object_proxy.default.create({
content: {
prop: 'emberjs'
}
});
(0, _metal.set)(proxyObject, 'prop', undefined);
assert.equal((0, _metal.get)(proxyObject, 'prop'), undefined, 'sets the `undefined` value to the proxied content');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/utils/tests/cache_test", ["ember-babel", "@ember/-internals/utils", "internal-test-helpers"], function (_emberBabel, _utils, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Cache',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test basic'] = function testBasic(assert) {
var cache = new _utils.Cache(100, function (key) {
return key.toUpperCase();
});
assert.equal(cache.get('foo'), 'FOO');
assert.equal(cache.get('bar'), 'BAR');
assert.equal(cache.get('foo'), 'FOO');
};
_proto['@test explicit sets'] = function testExplicitSets(assert) {
var cache = new _utils.Cache(100, function (key) {
return key.toUpperCase();
});
assert.equal(cache.get('foo'), 'FOO');
assert.equal(cache.set('foo', 'FOO!!!'), 'FOO!!!');
assert.equal(cache.get('foo'), 'FOO!!!');
assert.strictEqual(cache.set('foo', undefined), undefined);
assert.strictEqual(cache.get('foo'), undefined);
};
_proto['@test caches computation correctly'] = function testCachesComputationCorrectly(assert) {
var count = 0;
var cache = new _utils.Cache(100, function (key) {
count++;
return key.toUpperCase();
});
assert.equal(count, 0);
cache.get('foo');
assert.equal(count, 1);
cache.get('bar');
assert.equal(count, 2);
cache.get('bar');
assert.equal(count, 2);
cache.get('foo');
assert.equal(count, 2);
};
_proto['@test handles undefined value correctly'] = function testHandlesUndefinedValueCorrectly(assert) {
var count = 0;
var cache = new _utils.Cache(100, function () {
count++;
});
assert.equal(count, 0);
assert.strictEqual(cache.get('foo'), undefined);
assert.equal(count, 1);
assert.strictEqual(cache.get('bar'), undefined);
assert.equal(count, 2);
assert.strictEqual(cache.get('bar'), undefined);
assert.equal(count, 2);
assert.strictEqual(cache.get('foo'), undefined);
assert.equal(count, 2);
};
_proto['@test continues working after reaching cache limit'] = function testContinuesWorkingAfterReachingCacheLimit(assert) {
var cache = new _utils.Cache(3, function (key) {
return key.toUpperCase();
});
cache.get('a');
cache.get('b');
cache.get('c');
assert.equal(cache.get('d'), 'D');
assert.equal(cache.get('a'), 'A');
assert.equal(cache.get('b'), 'B');
assert.equal(cache.get('c'), 'C');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/utils/tests/can_invoke_test", ["ember-babel", "@ember/-internals/utils", "internal-test-helpers"], function (_emberBabel, _utils, _internalTestHelpers) {
"use strict";
var obj;
(0, _internalTestHelpers.moduleFor)('Ember.canInvoke',
/*#__PURE__*/
function (_TestCase) {
(0, _emberBabel.inheritsLoose)(_class, _TestCase);
function _class() {
var _this;
_this = _TestCase.call(this) || this;
obj = {
foobar: 'foobar',
aMethodThatExists: function () {}
};
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
obj = undefined;
};
_proto["@test should return false if the object doesn't exist"] = function testShouldReturnFalseIfTheObjectDoesnTExist(assert) {
assert.equal((0, _utils.canInvoke)(undefined, 'aMethodThatDoesNotExist'), false);
};
_proto['@test should return true for falsy values that have methods'] = function testShouldReturnTrueForFalsyValuesThatHaveMethods(assert) {
assert.equal((0, _utils.canInvoke)(false, 'valueOf'), true);
assert.equal((0, _utils.canInvoke)('', 'charAt'), true);
assert.equal((0, _utils.canInvoke)(0, 'toFixed'), true);
};
_proto['@test should return true if the method exists on the object'] = function testShouldReturnTrueIfTheMethodExistsOnTheObject(assert) {
assert.equal((0, _utils.canInvoke)(obj, 'aMethodThatExists'), true);
};
_proto["@test should return false if the method doesn't exist on the object"] = function testShouldReturnFalseIfTheMethodDoesnTExistOnTheObject(assert) {
assert.equal((0, _utils.canInvoke)(obj, 'aMethodThatDoesNotExist'), false);
};
_proto['@test should return false if the property exists on the object but is a non-function'] = function testShouldReturnFalseIfThePropertyExistsOnTheObjectButIsANonFunction(assert) {
assert.equal((0, _utils.canInvoke)(obj, 'foobar'), false);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/utils/tests/checkHasSuper_test", ["ember-babel", "@ember/-internals/browser-environment", "@ember/-internals/utils", "internal-test-helpers"], function (_emberBabel, _browserEnvironment, _utils, _internalTestHelpers) {
"use strict";
// Only run this test on browsers that we are certain should have function
// source available. This allows the test suite to continue to pass on other
// platforms that correctly (for them) fall back to the "always wrap" code.
if (_browserEnvironment.isChrome || _browserEnvironment.isFirefox) {
(0, _internalTestHelpers.moduleFor)('checkHasSuper',
/*#__PURE__*/
function (_TestCase) {
(0, _emberBabel.inheritsLoose)(_class, _TestCase);
function _class() {
return _TestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test does not super wrap needlessly [GH #12462]'] = function testDoesNotSuperWrapNeedlesslyGH12462(assert) {
assert.notOk((0, _utils.checkHasSuper)(function () {}), 'empty function does not have super');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
}
});
enifed("@ember/-internals/utils/tests/generate_guid_test", ["ember-babel", "@ember/-internals/utils", "internal-test-helpers"], function (_emberBabel, _utils, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember.generateGuid',
/*#__PURE__*/
function (_TestCase) {
(0, _emberBabel.inheritsLoose)(_class, _TestCase);
function _class() {
return _TestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Prefix'] = function testPrefix(assert) {
var a = {};
assert.ok((0, _utils.generateGuid)(a, 'tyrell').indexOf('tyrell') > -1, 'guid can be prefixed');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/utils/tests/guid_for_test", ["ember-babel", "@ember/-internals/utils", "internal-test-helpers"], function (_emberBabel, _utils, _internalTestHelpers) {
"use strict";
function sameGuid(assert, a, b, message) {
assert.equal((0, _utils.guidFor)(a), (0, _utils.guidFor)(b), message);
}
function diffGuid(assert, a, b, message) {
assert.ok((0, _utils.guidFor)(a) !== (0, _utils.guidFor)(b), message);
}
function nanGuid(assert, obj) {
var type = typeof obj;
assert.ok(isNaN(parseInt((0, _utils.guidFor)(obj), 0)), 'guids for ' + type + "don't parse to numbers");
}
(0, _internalTestHelpers.moduleFor)('guidFor',
/*#__PURE__*/
function (_TestCase) {
(0, _emberBabel.inheritsLoose)(_class, _TestCase);
function _class() {
return _TestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Object'] = function testObject(assert) {
var a = {};
var b = {};
sameGuid(assert, a, a, 'same object always yields same guid');
diffGuid(assert, a, b, 'different objects yield different guids');
nanGuid(assert, a);
};
_proto['@test strings'] = function testStrings(assert) {
var a = 'string A';
var aprime = 'string A';
var b = 'String B';
sameGuid(assert, a, a, 'same string always yields same guid');
sameGuid(assert, a, aprime, 'identical strings always yield the same guid');
diffGuid(assert, a, b, 'different strings yield different guids');
nanGuid(assert, a);
};
_proto['@test numbers'] = function testNumbers(assert) {
var a = 23;
var aprime = 23;
var b = 34;
sameGuid(assert, a, a, 'same numbers always yields same guid');
sameGuid(assert, a, aprime, 'identical numbers always yield the same guid');
diffGuid(assert, a, b, 'different numbers yield different guids');
nanGuid(assert, a);
};
_proto['@test symbols'] = function testSymbols(assert) {
if (typeof Symbol === 'undefined') {
assert.ok(true, 'symbols are not supported on this browser');
return;
}
var a = Symbol('a');
var b = Symbol('b');
sameGuid(assert, a, a, 'same symbols always yields same guid');
diffGuid(assert, a, b, 'different symbols yield different guids');
nanGuid(assert, a);
};
_proto['@test booleans'] = function testBooleans(assert) {
var a = true;
var aprime = true;
var b = false;
sameGuid(assert, a, a, 'same booleans always yields same guid');
sameGuid(assert, a, aprime, 'identical booleans always yield the same guid');
diffGuid(assert, a, b, 'different boolean yield different guids');
nanGuid(assert, a);
nanGuid(assert, b);
};
_proto['@test null and undefined'] = function testNullAndUndefined(assert) {
var a = null;
var aprime = null;
var b;
sameGuid(assert, a, a, 'null always returns the same guid');
sameGuid(assert, b, b, 'undefined always returns the same guid');
sameGuid(assert, a, aprime, 'different nulls return the same guid');
diffGuid(assert, a, b, 'null and undefined return different guids');
nanGuid(assert, a);
nanGuid(assert, b);
};
_proto['@test arrays'] = function testArrays(assert) {
var a = ['a', 'b', 'c'];
var aprime = ['a', 'b', 'c'];
var b = ['1', '2', '3'];
sameGuid(assert, a, a, 'same instance always yields same guid');
diffGuid(assert, a, aprime, 'identical arrays always yield the same guid');
diffGuid(assert, a, b, 'different arrays yield different guids');
nanGuid(assert, a);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/utils/tests/inspect_test", ["ember-babel", "@ember/-internals/utils", "internal-test-helpers"], function (_emberBabel, _utils, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember.inspect',
/*#__PURE__*/
function (_TestCase) {
(0, _emberBabel.inheritsLoose)(_class, _TestCase);
function _class() {
return _TestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test strings'] = function testStrings(assert) {
assert.equal((0, _utils.inspect)('foo'), '"foo"');
};
_proto['@test numbers'] = function testNumbers(assert) {
assert.equal((0, _utils.inspect)(2.6), '2.6');
};
_proto['@test null'] = function testNull(assert) {
assert.equal((0, _utils.inspect)(null), 'null');
};
_proto['@test undefined'] = function testUndefined(assert) {
assert.equal((0, _utils.inspect)(undefined), 'undefined');
};
_proto['@test true'] = function testTrue(assert) {
assert.equal((0, _utils.inspect)(true), 'true');
};
_proto['@test false'] = function testFalse(assert) {
assert.equal((0, _utils.inspect)(false), 'false');
};
_proto['@test object'] = function testObject(assert) {
assert.equal((0, _utils.inspect)({}), '{ }');
assert.equal((0, _utils.inspect)({
foo: 'bar'
}), '{ foo: "bar" }');
var obj = {
foo: function () {
return this;
}
}; // IE 11 doesn't have function name
if (obj.foo.name) {
assert.equal((0, _utils.inspect)(obj), "{ foo: [Function:foo] }");
} else {
assert.equal((0, _utils.inspect)(obj), "{ foo: [Function] }");
}
};
_proto['@test objects without a prototype'] = function testObjectsWithoutAPrototype(assert) {
var prototypelessObj = Object.create(null);
prototypelessObj.a = 1;
prototypelessObj.b = [Object.create(null)];
assert.equal((0, _utils.inspect)({
foo: prototypelessObj
}), '{ foo: { a: 1, b: [ { } ] } }');
};
_proto['@test array'] = function testArray(assert) {
assert.equal((0, _utils.inspect)([1, 2, 3]), '[ 1, 2, 3 ]');
};
_proto['@test array list limit'] = function testArrayListLimit(assert) {
var a = [];
for (var i = 0; i < 120; i++) {
a.push(1);
}
assert.equal((0, _utils.inspect)(a), "[ " + a.slice(0, 100).join(', ') + ", ... 20 more items ]");
};
_proto['@test object list limit'] = function testObjectListLimit(assert) {
var obj = {};
var pairs = [];
for (var i = 0; i < 120; i++) {
obj['key' + i] = i;
pairs.push("key" + i + ": " + i);
}
assert.equal((0, _utils.inspect)(obj), "{ " + pairs.slice(0, 100).join(', ') + ", ... 20 more keys }");
};
_proto['@test depth limit'] = function testDepthLimit(assert) {
assert.equal((0, _utils.inspect)([[[['here', {
a: 1
}, [1]]]]]), '[ [ [ [ "here", [Object], [Array] ] ] ] ]');
};
_proto['@test odd key'] = function testOddKey(assert) {
var _inspect;
assert.equal((0, _utils.inspect)((_inspect = {}, _inspect["Hello world!\nHow are you?"] = 1, _inspect)), '{ "Hello world!\\nHow are you?": 1 }');
};
_proto['@test node call'] = function testNodeCall(assert) {
var obj = {
a: 1
};
obj.inspect = _utils.inspect;
var depth = 2;
var options = {};
assert.equal(obj.inspect(depth, options), obj);
};
_proto['@test cycle'] = function testCycle(assert) {
var obj = {};
obj.a = obj;
var arr = [obj];
arr.push(arr);
assert.equal((0, _utils.inspect)(arr), '[ { a: [Circular] }, [Circular] ]');
};
_proto['@test custom toString'] = function testCustomToString(assert) {
var Component =
/*#__PURE__*/
function () {
function Component() {}
Component.toString = function toString() {
return '@ember/component';
};
var _proto2 = Component.prototype;
_proto2.toString = function toString() {
return "<" + this.constructor + ":ember234>";
};
return Component;
}();
assert.equal((0, _utils.inspect)([new Component(), Component]), '[ <@ember/component:ember234>, @ember/component ]');
};
_proto['@test regexp'] = function testRegexp(assert) {
assert.equal((0, _utils.inspect)(/regexp/), '/regexp/');
};
_proto['@test date'] = function testDate(assert) {
var inspected = (0, _utils.inspect)(new Date('Sat Apr 30 2011 13:24:11'));
assert.ok(inspected.match(/Sat Apr 30/), 'The inspected date has its date');
assert.ok(inspected.match(/2011/), 'The inspected date has its year');
assert.ok(inspected.match(/13:24:11/), 'The inspected date has its time');
};
_proto['@test inspect outputs the toString() representation of Symbols'] = function testInspectOutputsTheToStringRepresentationOfSymbols(assert) {
if (_utils.HAS_NATIVE_SYMBOL) {
var symbol = Symbol('test');
assert.equal((0, _utils.inspect)(symbol), 'Symbol(test)');
} else {
assert.expect(0);
}
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/utils/tests/is_proxy_test", ["ember-babel", "@ember/-internals/utils", "internal-test-helpers"], function (_emberBabel, _utils, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('@ember/-internals/utils isProxy',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test basic'] = function testBasic(assert) {
var proxy = {};
(0, _utils.setProxy)(proxy);
assert.equal((0, _utils.isProxy)(proxy), true);
assert.equal((0, _utils.isProxy)({}), false);
assert.equal((0, _utils.isProxy)(undefined), false);
assert.equal((0, _utils.isProxy)(null), false);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/utils/tests/make_array_test", ["ember-babel", "@ember/-internals/utils", "internal-test-helpers"], function (_emberBabel, _utils, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Ember.makeArray',
/*#__PURE__*/
function (_TestCase) {
(0, _emberBabel.inheritsLoose)(_class, _TestCase);
function _class() {
return _TestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test undefined'] = function testUndefined(assert) {
assert.deepEqual((0, _utils.makeArray)(), []);
assert.deepEqual((0, _utils.makeArray)(undefined), []);
};
_proto['@test null'] = function testNull(assert) {
assert.deepEqual((0, _utils.makeArray)(null), []);
};
_proto['@test string'] = function testString(assert) {
assert.deepEqual((0, _utils.makeArray)('lindsay'), ['lindsay']);
};
_proto['@test number'] = function testNumber(assert) {
assert.deepEqual((0, _utils.makeArray)(0), [0]);
assert.deepEqual((0, _utils.makeArray)(1), [1]);
};
_proto['@test array'] = function testArray(assert) {
assert.deepEqual((0, _utils.makeArray)([1, 2, 42]), [1, 2, 42]);
};
_proto['@test true'] = function testTrue(assert) {
assert.deepEqual((0, _utils.makeArray)(true), [true]);
};
_proto['@test false'] = function testFalse(assert) {
assert.deepEqual((0, _utils.makeArray)(false), [false]);
};
_proto['@test object'] = function testObject(assert) {
assert.deepEqual((0, _utils.makeArray)({}), [{}]);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/utils/tests/to-string-test", ["ember-babel", "@ember/-internals/utils", "internal-test-helpers"], function (_emberBabel, _utils, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('@ember/-internals/utils toString',
/*#__PURE__*/
function (_TestCase) {
(0, _emberBabel.inheritsLoose)(_class, _TestCase);
function _class() {
return _TestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto["@test toString uses an object's toString method when available"] = function (assert) {
var obj = {
toString: function () {
return 'bob';
}
};
assert.strictEqual((0, _utils.toString)(obj), 'bob');
};
_proto['@test toString falls back to Object.prototype.toString'] = function testToStringFallsBackToObjectPrototypeToString(assert) {
var obj = Object.create(null);
assert.strictEqual((0, _utils.toString)(obj), {}.toString());
};
_proto['@test toString does not fail when called on Arrays with objects without toString method'] = function testToStringDoesNotFailWhenCalledOnArraysWithObjectsWithoutToStringMethod(assert) {
var obj = Object.create(null);
var arr = [obj, 2];
assert.strictEqual((0, _utils.toString)(arr), {}.toString() + ",2");
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/-internals/utils/tests/try_invoke_test", ["ember-babel", "@ember/-internals/utils", "internal-test-helpers"], function (_emberBabel, _utils, _internalTestHelpers) {
"use strict";
var obj;
(0, _internalTestHelpers.moduleFor)('Ember.tryInvoke',
/*#__PURE__*/
function (_TestCase) {
(0, _emberBabel.inheritsLoose)(_class, _TestCase);
function _class() {
var _this;
_this = _TestCase.call(this) || this;
obj = {
aMethodThatExists: function () {
return true;
},
aMethodThatTakesArguments: function (arg1, arg2) {
return arg1 === arg2;
}
};
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
obj = undefined;
};
_proto["@test should return undefined when the object doesn't exist"] = function testShouldReturnUndefinedWhenTheObjectDoesnTExist(assert) {
assert.equal((0, _utils.tryInvoke)(undefined, 'aMethodThatDoesNotExist'), undefined);
};
_proto["@test should return undefined when asked to perform a method that doesn't exist on the object"] = function testShouldReturnUndefinedWhenAskedToPerformAMethodThatDoesnTExistOnTheObject(assert) {
assert.equal((0, _utils.tryInvoke)(obj, 'aMethodThatDoesNotExist'), undefined);
};
_proto['@test should return what the method returns when asked to perform a method that exists on the object'] = function testShouldReturnWhatTheMethodReturnsWhenAskedToPerformAMethodThatExistsOnTheObject(assert) {
assert.equal((0, _utils.tryInvoke)(obj, 'aMethodThatExists'), true);
};
_proto['@test should return what the method returns when asked to perform a method that takes arguments and exists on the object'] = function testShouldReturnWhatTheMethodReturnsWhenAskedToPerformAMethodThatTakesArgumentsAndExistsOnTheObject(assert) {
assert.equal((0, _utils.tryInvoke)(obj, 'aMethodThatTakesArguments', [true, true]), true);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/application/tests/application_instance_test", ["ember-babel", "@ember/engine", "@ember/application", "@ember/application/instance", "@ember/runloop", "@ember/-internals/container", "internal-test-helpers", "@ember/-internals/runtime", "@ember/debug"], function (_emberBabel, _engine, _application, _instance, _runloop, _container, _internalTestHelpers, _runtime, _debug) {
"use strict";
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["-bucket-cache:main"]);
_templateObject = function () {
return data;
};
return data;
}
var originalDebug = (0, _debug.getDebugFunction)('debug');
var noop = function () {};
var application, appInstance;
(0, _internalTestHelpers.moduleFor)('ApplicationInstance',
/*#__PURE__*/
function (_TestCase) {
(0, _emberBabel.inheritsLoose)(_class, _TestCase);
function _class() {
var _this;
(0, _debug.setDebugFunction)('debug', noop);
_this = _TestCase.call(this) || this;
document.getElementById('qunit-fixture').innerHTML = "\n
HI
HI
\n ";
application = (0, _runloop.run)(function () {
return _application.default.create({
rootElement: '#one',
router: null
});
});
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
(0, _debug.setDebugFunction)('debug', originalDebug);
if (appInstance) {
(0, _runloop.run)(appInstance, 'destroy');
appInstance = null;
}
if (application) {
(0, _runloop.run)(application, 'destroy');
application = null;
}
document.getElementById('qunit-fixture').innerHTML = '';
};
_proto['@test an application instance can be created based upon an application'] = function testAnApplicationInstanceCanBeCreatedBasedUponAnApplication(assert) {
appInstance = (0, _runloop.run)(function () {
return _instance.default.create({
application: application
});
});
assert.ok(appInstance, 'instance should be created');
assert.equal(appInstance.application, application, 'application should be set to parent');
};
_proto['@test customEvents added to the application before setupEventDispatcher'] = function testCustomEventsAddedToTheApplicationBeforeSetupEventDispatcher(assert) {
assert.expect(1);
appInstance = (0, _runloop.run)(function () {
return _instance.default.create({
application: application
});
});
appInstance.setupRegistry();
application.customEvents = {
awesome: 'sauce'
};
var eventDispatcher = appInstance.lookup('event_dispatcher:main');
eventDispatcher.setup = function (events) {
assert.equal(events.awesome, 'sauce');
};
appInstance.setupEventDispatcher();
};
_proto['@test customEvents added to the application before setupEventDispatcher'] = function testCustomEventsAddedToTheApplicationBeforeSetupEventDispatcher(assert) {
assert.expect(1);
appInstance = (0, _runloop.run)(function () {
return _instance.default.create({
application: application
});
});
appInstance.setupRegistry();
application.customEvents = {
awesome: 'sauce'
};
var eventDispatcher = appInstance.lookup('event_dispatcher:main');
eventDispatcher.setup = function (events) {
assert.equal(events.awesome, 'sauce');
};
appInstance.setupEventDispatcher();
};
_proto['@test customEvents added to the application instance before setupEventDispatcher'] = function testCustomEventsAddedToTheApplicationInstanceBeforeSetupEventDispatcher(assert) {
assert.expect(1);
appInstance = (0, _runloop.run)(function () {
return _instance.default.create({
application: application
});
});
appInstance.setupRegistry();
appInstance.customEvents = {
awesome: 'sauce'
};
var eventDispatcher = appInstance.lookup('event_dispatcher:main');
eventDispatcher.setup = function (events) {
assert.equal(events.awesome, 'sauce');
};
appInstance.setupEventDispatcher();
};
_proto['@test unregistering a factory clears all cached instances of that factory'] = function testUnregisteringAFactoryClearsAllCachedInstancesOfThatFactory(assert) {
assert.expect(5);
appInstance = (0, _runloop.run)(function () {
return _instance.default.create({
application: application
});
});
var PostController1 = (0, _internalTestHelpers.factory)();
var PostController2 = (0, _internalTestHelpers.factory)();
appInstance.register('controller:post', PostController1);
var postController1 = appInstance.lookup('controller:post');
var postController1Factory = appInstance.factoryFor('controller:post');
assert.ok(postController1 instanceof PostController1, 'precond - lookup creates instance');
assert.equal(PostController1, postController1Factory.class, 'precond - factoryFor().class matches');
appInstance.unregister('controller:post');
appInstance.register('controller:post', PostController2);
var postController2 = appInstance.lookup('controller:post');
var postController2Factory = appInstance.factoryFor('controller:post');
assert.ok(postController2 instanceof PostController2, 'lookup creates instance');
assert.equal(PostController2, postController2Factory.class, 'factoryFor().class matches');
assert.notStrictEqual(postController1, postController2, 'lookup creates a brand new instance, because the previous one was reset');
};
_proto['@skip unregistering a factory clears caches with source of that factory'] = function skipUnregisteringAFactoryClearsCachesWithSourceOfThatFactory(assert) {
assert.expect(1);
appInstance = (0, _runloop.run)(function () {
return _instance.default.create({
application: application
});
});
var PostController1 = (0, _internalTestHelpers.factory)();
var PostController2 = (0, _internalTestHelpers.factory)();
appInstance.register('controller:post', PostController1);
appInstance.lookup('controller:post');
var postControllerLookupWithSource = appInstance.lookup('controller:post', {
source: 'doesnt-even-matter'
});
appInstance.unregister('controller:post');
appInstance.register('controller:post', PostController2); // The cache that is source-specific is not cleared
assert.ok(postControllerLookupWithSource !== appInstance.lookup('controller:post', {
source: 'doesnt-even-matter'
}), 'lookup with source creates a new instance');
};
_proto['@test can build and boot a registered engine'] = function testCanBuildAndBootARegisteredEngine(assert) {
assert.expect(11);
var ChatEngine = _engine.default.extend();
var chatEngineInstance;
application.register('engine:chat', ChatEngine);
(0, _runloop.run)(function () {
appInstance = _instance.default.create({
application: application
});
appInstance.setupRegistry();
chatEngineInstance = appInstance.buildChildEngineInstance('chat');
});
return chatEngineInstance.boot().then(function () {
assert.ok(true, 'boot successful');
var registrations = ['route:basic', 'service:-routing', 'service:-glimmer-environment'];
registrations.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', 'event_dispatcher:main'];
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 + "'");
});
});
};
_proto['@test can build a registry via ApplicationInstance.setupRegistry() -- simulates ember-test-helpers'] = function testCanBuildARegistryViaApplicationInstanceSetupRegistrySimulatesEmberTestHelpers(assert) {
var namespace = _runtime.Object.create({
Resolver: {
create: function () {}
}
});
var registry = _application.default.buildRegistry(namespace);
_instance.default.setupRegistry(registry);
assert.equal(registry.resolve('service:-document'), document);
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/application/tests/application_test", ["ember-babel", "ember/version", "@ember/-internals/environment", "@ember/-internals/metal", "@ember/debug", "@ember/application", "@ember/-internals/routing", "@ember/-internals/views", "@ember/controller", "@ember/-internals/runtime", "@ember/-internals/glimmer", "@ember/-internals/container", "@ember/polyfills", "internal-test-helpers", "@ember/runloop"], function (_emberBabel, _version, _environment, _metal, _debug, _application, _routing, _views, _controller, _runtime, _glimmer, _container, _polyfills, _internalTestHelpers, _runloop) {
"use strict";
function _templateObject5() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["template-compiler:main"]);
_templateObject5 = function () {
return data;
};
return data;
}
function _templateObject4() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["template:components/-default"]);
_templateObject4 = function () {
return data;
};
return data;
}
function _templateObject3() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["-bucket-cache:main"]);
_templateObject3 = function () {
return data;
};
return data;
}
function _templateObject2() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["-bucket-cache:main"]);
_templateObject2 = function () {
return data;
};
return data;
}
function _templateObject() {
var data = (0, _emberBabel.taggedTemplateLiteralLoose)(["-bucket-cache:main"]);
_templateObject = function () {
return data;
};
return data;
}
/*globals EmberDev */
(0, _internalTestHelpers.moduleFor)('Application, autobooting multiple apps',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.createSecondApplication = function createSecondApplication(options) {
var myOptions = (0, _polyfills.assign)(this.applicationOptions, options);
return this.secondApp = _application.default.create(myOptions);
};
_proto.teardown = function teardown() {
var _this = this;
_ApplicationTestCase.prototype.teardown.call(this);
if (this.secondApp) {
(0, _internalTestHelpers.runTask)(function () {
return _this.secondApp.destroy();
});
}
};
_proto["@test you can make a new application in a non-overlapping element"] = function (assert) {
var _this2 = this;
var app = (0, _internalTestHelpers.runTask)(function () {
return _this2.createSecondApplication({
rootElement: '#two'
});
});
(0, _internalTestHelpers.runTask)(function () {
return app.destroy();
});
assert.ok(true, 'should not raise');
};
_proto["@test you cannot make a new application that is a parent of an existing application"] = function () {
var _this3 = this;
expectAssertion(function () {
(0, _internalTestHelpers.runTask)(function () {
return _this3.createSecondApplication({
rootElement: _this3.applicationOptions.rootElement
});
});
});
};
_proto["@test you cannot make a new application that is a descendant of an existing application"] = function () {
var _this4 = this;
expectAssertion(function () {
(0, _internalTestHelpers.runTask)(function () {
return _this4.createSecondApplication({
rootElement: '#one-child'
});
});
});
};
_proto["@test you cannot make a new application that is a duplicate of an existing application"] = function () {
var _this5 = this;
expectAssertion(function () {
(0, _internalTestHelpers.runTask)(function () {
return _this5.createSecondApplication({
rootElement: '#one'
});
});
});
};
_proto["@test you cannot make two default applications without a rootElement error"] = function () {
var _this6 = this;
expectAssertion(function () {
(0, _internalTestHelpers.runTask)(function () {
return _this6.createSecondApplication();
});
});
};
(0, _emberBabel.createClass)(_class, [{
key: "fixture",
get: function () {
return "\n
');
});
this.assertText('Hi from index');
};
_proto4["@test ready hook is called before routing begins"] = function (assert) {
var _this13 = this;
assert.expect(2);
(0, _internalTestHelpers.runTask)(function () {
function registerRoute(application, name, callback) {
var route = _routing.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 = _this13.createApplication({}, MyApplication);
registerRoute(app, 'application', function () {
return assert.ok(true, 'normal route is activated');
});
});
};
_proto4["@test initialize application via initialize call"] = function (assert) {
var _this14 = this;
(0, _internalTestHelpers.runTask)(function () {
return _this14.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.applicationInstance.lookup('router:main');
assert.equal(router instanceof _routing.Router, true, 'Router was set from initialize call');
assert.equal(router.location instanceof _routing.NoneLocation, true, 'Location was set from location implementation name');
};
_proto4["@test initialize application with stateManager via initialize call from Router class"] = function (assert) {
var _this15 = this;
(0, _internalTestHelpers.runTask)(function () {
_this15.createApplication();
_this15.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 _routing.Router, true, 'Router was set from initialize call');
this.assertText('Hello!');
};
_proto4["@test Application Controller backs the appplication template"] = function () {
var _this16 = this;
(0, _internalTestHelpers.runTask)(function () {
_this16.createApplication();
_this16.addTemplate('application', '
{{greeting}}
');
_this16.add('controller:application', _controller.default.extend({
greeting: 'Hello!'
}));
});
this.assertText('Hello!');
};
_proto4["@test enable log of libraries with an ENV var"] = function (assert) {
var _this17 = this;
if (EmberDev && EmberDev.runningProdBuild) {
assert.ok(true, 'Logging does not occur in production builds');
return;
}
var messages = [];
_environment.ENV.LOG_VERSION = true;
(0, _debug.setDebugFunction)('debug', function (message) {
return messages.push(message);
});
_metal.libraries.register('my-lib', '2.0.0a');
(0, _internalTestHelpers.runTask)(function () {
return _this17.createApplication();
});
assert.equal(messages[1], 'Ember : ' + _version.default);
if (_views.jQueryDisabled) {
assert.equal(messages[2], 'my-lib : ' + '2.0.0a');
} else {
assert.equal(messages[2], 'jQuery : ' + (0, _views.jQuery)().jquery);
assert.equal(messages[3], 'my-lib : ' + '2.0.0a');
}
_metal.libraries.deRegister('my-lib');
};
_proto4["@test disable log of version of libraries with an ENV var"] = function (assert) {
var _this18 = this;
var logged = false;
_environment.ENV.LOG_VERSION = false;
(0, _debug.setDebugFunction)('debug', function () {
return logged = true;
});
(0, _internalTestHelpers.runTask)(function () {
return _this18.createApplication();
});
assert.ok(!logged, 'library version logging skipped');
};
_proto4["@test can resolve custom router"] = function (assert) {
var _this19 = this;
var CustomRouter = _routing.Router.extend();
(0, _internalTestHelpers.runTask)(function () {
_this19.createApplication();
_this19.add('router:main', CustomRouter);
});
assert.ok(this.application.__deprecatedInstance__.lookup('router:main') instanceof CustomRouter, 'application resolved the correct router');
};
_proto4["@test does not leak itself in onLoad._loaded"] = function (assert) {
var _this20 = this;
assert.equal(_application._loaded.application, undefined);
(0, _internalTestHelpers.runTask)(function () {
return _this20.createApplication();
});
assert.equal(_application._loaded.application, this.application);
(0, _internalTestHelpers.runTask)(function () {
return _this20.application.destroy();
});
assert.equal(_application._loaded.application, undefined);
};
_proto4["@test can build a registry via Application.buildRegistry() --- simulates ember-test-helpers"] = function (assert) {
var namespace = _runtime.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)('Application#buildRegistry',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class5, _AbstractTestCase);
function _class5() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto5 = _class5.prototype;
_proto5["@test can build a registry via Application.buildRegistry() --- simulates ember-test-helpers"] = function (assert) {
var namespace = _runtime.Object.create({
Resolver: {
create: function () {}
}
});
var registry = _application.default.buildRegistry(namespace);
assert.equal(registry.resolve('application:main'), namespace);
};
return _class5;
}(_internalTestHelpers.AbstractTestCase));
(0, _internalTestHelpers.moduleFor)('Application - instance tracking',
/*#__PURE__*/
function (_ApplicationTestCase3) {
(0, _emberBabel.inheritsLoose)(_class6, _ApplicationTestCase3);
function _class6() {
return _ApplicationTestCase3.apply(this, arguments) || this;
}
var _proto6 = _class6.prototype;
_proto6['@test tracks built instance'] = function testTracksBuiltInstance(assert) {
var _this21 = this;
var instance = this.application.buildInstance();
(0, _runloop.run)(function () {
_this21.application.destroy();
});
assert.ok(instance.isDestroyed, 'instance was destroyed');
};
_proto6['@test tracks built instances'] = function testTracksBuiltInstances(assert) {
var _this22 = this;
var instanceA = this.application.buildInstance();
var instanceB = this.application.buildInstance();
(0, _runloop.run)(function () {
_this22.application.destroy();
});
assert.ok(instanceA.isDestroyed, 'instanceA was destroyed');
assert.ok(instanceB.isDestroyed, 'instanceB was destroyed');
};
return _class6;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("@ember/application/tests/bootstrap-test", ["ember-babel", "@ember/polyfills", "internal-test-helpers"], function (_emberBabel, _polyfills, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Application with default resolver and autoboot',
/*#__PURE__*/
function (_DefaultResolverAppli) {
(0, _emberBabel.inheritsLoose)(_class, _DefaultResolverAppli);
function _class() {
return _DefaultResolverAppli.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test templates in script tags are extracted at application creation'] = function testTemplatesInScriptTagsAreExtractedAtApplicationCreation(assert) {
var _this = this;
(0, _internalTestHelpers.runTask)(function () {
return _this.createApplication();
});
assert.equal(document.getElementById('app').textContent, 'Hello World!');
};
(0, _emberBabel.createClass)(_class, [{
key: "fixture",
get: function () {
return "\n \n\n \n \n ";
}
}, {
key: "applicationOptions",
get: function () {
return (0, _polyfills.assign)(_DefaultResolverAppli.prototype.applicationOptions, {
autoboot: true,
rootElement: '#app'
});
}
}]);
return _class;
}(_internalTestHelpers.DefaultResolverApplicationTestCase));
});
enifed("@ember/application/tests/dependency_injection/custom_resolver_test", ["ember-babel", "@ember/application/globals-resolver", "@ember/polyfills", "internal-test-helpers"], function (_emberBabel, _globalsResolver, _polyfills, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Application with extended default resolver and autoboot',
/*#__PURE__*/
function (_DefaultResolverAppli) {
(0, _emberBabel.inheritsLoose)(_class, _DefaultResolverAppli);
function _class() {
return _DefaultResolverAppli.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto["@test a resolver can be supplied to application"] = function () {
var _this = this;
(0, _internalTestHelpers.runTask)(function () {
return _this.createApplication();
});
this.assertText('Fallback');
};
(0, _emberBabel.createClass)(_class, [{
key: "applicationOptions",
get: function () {
var applicationTemplate = this.compile("
Fallback
");
var Resolver = _globalsResolver.default.extend({
resolveTemplate: function (resolvable) {
if (resolvable.fullNameWithoutType === 'application') {
return applicationTemplate;
} else {
return this._super(resolvable);
}
}
});
return (0, _polyfills.assign)(_DefaultResolverAppli.prototype.applicationOptions, {
Resolver: Resolver,
autoboot: true
});
}
}]);
return _class;
}(_internalTestHelpers.DefaultResolverApplicationTestCase));
});
enifed("@ember/application/tests/dependency_injection/default_resolver_test", ["ember-babel", "internal-test-helpers", "@ember/-internals/environment", "@ember/controller", "@ember/service", "@ember/-internals/runtime", "@ember/-internals/routing", "@ember/-internals/glimmer", "@ember/debug"], function (_emberBabel, _internalTestHelpers, _environment, _controller, _service, _runtime, _routing, _glimmer, _debug) {
"use strict";
/* globals EmberDev */
(0, _internalTestHelpers.moduleFor)('Application Dependency Injection - Integration - default resolver',
/*#__PURE__*/
function (_DefaultResolverAppli) {
(0, _emberBabel.inheritsLoose)(_class, _DefaultResolverAppli);
function _class() {
return _DefaultResolverAppli.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
var _this = this;
(0, _internalTestHelpers.runTask)(function () {
return _this.createApplication();
});
return this.visit('/');
};
/*
* This first batch of tests are integration tests against the public
* applicationInstance API.
*/
_proto["@test the default resolver looks up templates in Ember.TEMPLATES"] = function (assert) {
var fooTemplate = this.addTemplate('foo', "foo template");
var fooBarTemplate = this.addTemplate('fooBar', "fooBar template");
var fooBarBazTemplate = this.addTemplate('fooBar/baz', "fooBar/baz template");
assert.equal(this.applicationInstance.factoryFor('template:foo').class, fooTemplate, 'resolves template:foo');
assert.equal(this.applicationInstance.factoryFor('template:fooBar').class, fooBarTemplate, 'resolves template:foo_bar');
assert.equal(this.applicationInstance.factoryFor('template:fooBar.baz').class, fooBarBazTemplate, 'resolves template:foo_bar.baz');
};
_proto["@test the default resolver looks up basic name as no prefix"] = function (assert) {
var instance = this.applicationInstance.lookup('controller:basic');
assert.ok(_controller.default.detect(instance), 'locator looks up correct controller');
};
_proto["@test the default resolver looks up arbitrary types on the namespace"] = function (assert) {
var Class = this.application.FooManager = _runtime.Object.extend();
var resolvedClass = this.application.resolveRegistration('manager:foo');
assert.equal(Class, resolvedClass, 'looks up FooManager on application');
};
_proto["@test the default resolver resolves models on the namespace"] = function (assert) {
var Class = this.application.Post = _runtime.Object.extend();
var factoryClass = this.applicationInstance.factoryFor('model:post').class;
assert.equal(Class, factoryClass, 'looks up Post model on application');
};
_proto["@test the default resolver resolves *:main on the namespace"] = function (assert) {
var Class = this.application.FooBar = _runtime.Object.extend();
var factoryClass = this.applicationInstance.factoryFor('foo-bar:main').class;
assert.equal(Class, factoryClass, 'looks up FooBar type without name on application');
};
_proto["@test the default resolver resolves container-registered helpers"] = function (assert) {
var shorthandHelper = (0, _glimmer.helper)(function () {});
var helper = _glimmer.Helper.extend();
this.application.register('helper:shorthand', shorthandHelper);
this.application.register('helper:complete', helper);
var lookedUpShorthandHelper = this.applicationInstance.factoryFor('helper:shorthand').class;
assert.ok(lookedUpShorthandHelper.isHelperFactory, 'shorthand helper isHelper');
var lookedUpHelper = this.applicationInstance.factoryFor('helper:complete').class;
assert.ok(lookedUpHelper.isHelperFactory, 'complete helper is factory');
assert.ok(helper.detect(lookedUpHelper), 'looked up complete helper');
};
_proto["@test the default resolver resolves container-registered helpers via lookupFor"] = function (assert) {
var shorthandHelper = (0, _glimmer.helper)(function () {});
var helper = _glimmer.Helper.extend();
this.application.register('helper:shorthand', shorthandHelper);
this.application.register('helper:complete', helper);
var lookedUpShorthandHelper = this.applicationInstance.factoryFor('helper:shorthand').class;
assert.ok(lookedUpShorthandHelper.isHelperFactory, 'shorthand helper isHelper');
var lookedUpHelper = this.applicationInstance.factoryFor('helper:complete').class;
assert.ok(lookedUpHelper.isHelperFactory, 'complete helper is factory');
assert.ok(helper.detect(lookedUpHelper), 'looked up complete helper');
};
_proto["@test the default resolver resolves helpers on the namespace"] = function (assert) {
var ShorthandHelper = (0, _glimmer.helper)(function () {});
var CompleteHelper = _glimmer.Helper.extend();
this.application.ShorthandHelper = ShorthandHelper;
this.application.CompleteHelper = CompleteHelper;
var resolvedShorthand = this.application.resolveRegistration('helper:shorthand');
var resolvedComplete = this.application.resolveRegistration('helper:complete');
assert.equal(resolvedShorthand, ShorthandHelper, 'resolve fetches the shorthand helper factory');
assert.equal(resolvedComplete, CompleteHelper, 'resolve fetches the complete helper factory');
};
_proto["@test the default resolver resolves to the same instance, no matter the notation "] = function (assert) {
this.application.NestedPostController = _controller.default.extend({});
assert.equal(this.applicationInstance.lookup('controller:nested-post'), this.applicationInstance.lookup('controller:nested_post'), 'looks up NestedPost controller on application');
};
_proto["@test the default resolver throws an error if the fullName to resolve is invalid"] = function () {
var _this2 = this;
expectAssertion(function () {
_this2.applicationInstance.resolveRegistration(undefined);
}, /fullName must be a proper full name/);
expectAssertion(function () {
_this2.applicationInstance.resolveRegistration(null);
}, /fullName must be a proper full name/);
expectAssertion(function () {
_this2.applicationInstance.resolveRegistration('');
}, /fullName must be a proper full name/);
expectAssertion(function () {
_this2.applicationInstance.resolveRegistration('');
}, /fullName must be a proper full name/);
expectAssertion(function () {
_this2.applicationInstance.resolveRegistration(':');
}, /fullName must be a proper full name/);
expectAssertion(function () {
_this2.applicationInstance.resolveRegistration('model');
}, /fullName must be a proper full name/);
expectAssertion(function () {
_this2.applicationInstance.resolveRegistration('model:');
}, /fullName must be a proper full name/);
expectAssertion(function () {
_this2.applicationInstance.resolveRegistration(':type');
}, /fullName must be a proper full name/);
}
/*
* The following are integration tests against the private registry API.
*/
;
_proto["@test lookup description"] = function (assert) {
this.application.toString = function () {
return 'App';
};
assert.equal(this.privateRegistry.describe('controller:foo'), 'App.FooController', 'Type gets appended at the end');
assert.equal(this.privateRegistry.describe('controller:foo.bar'), 'App.FooBarController', 'dots are removed');
assert.equal(this.privateRegistry.describe('model:foo'), 'App.Foo', "models don't get appended at the end");
};
_proto["@test assertion for routes without isRouteFactory property"] = function () {
var _this3 = this;
this.application.FooRoute = _glimmer.Component.extend();
expectAssertion(function () {
_this3.privateRegistry.resolve("route:foo");
}, /to resolve to an Ember.Route/, 'Should assert');
};
_proto["@test no assertion for routes that extend from Route"] = function (assert) {
assert.expect(0);
this.application.FooRoute = _routing.Route.extend();
this.privateRegistry.resolve("route:foo");
};
_proto["@test deprecation warning for service factories without isServiceFactory property"] = function () {
var _this4 = this;
expectAssertion(function () {
_this4.application.FooService = _runtime.Object.extend();
_this4.privateRegistry.resolve('service:foo');
}, /Expected service:foo to resolve to an Ember.Service but instead it was TestApp\.FooService\./);
};
_proto["@test no deprecation warning for service factories that extend from Service"] = function (assert) {
assert.expect(0);
this.application.FooService = _service.default.extend();
this.privateRegistry.resolve('service:foo');
};
_proto["@test deprecation warning for component factories without isComponentFactory property"] = function () {
var _this5 = this;
expectAssertion(function () {
_this5.application.FooComponent = _runtime.Object.extend();
_this5.privateRegistry.resolve('component:foo');
}, /Expected component:foo to resolve to an Ember\.Component but instead it was TestApp\.FooComponent\./);
};
_proto["@test no deprecation warning for component factories that extend from Component"] = function () {
expectNoDeprecation();
this.application.FooView = _glimmer.Component.extend();
this.privateRegistry.resolve('component:foo');
};
_proto["@test knownForType returns each item for a given type found"] = function (assert) {
this.application.FooBarHelper = 'foo';
this.application.BazQuxHelper = 'bar';
var found = this.privateRegistry.resolver.knownForType('helper');
assert.deepEqual(found, {
'helper:foo-bar': true,
'helper:baz-qux': true
});
};
_proto["@test knownForType is not required to be present on the resolver"] = function (assert) {
delete this.privateRegistry.resolver.knownForType;
this.privateRegistry.resolver.knownForType('helper', function () {});
assert.ok(true, 'does not error');
};
(0, _emberBabel.createClass)(_class, [{
key: "privateRegistry",
get: function () {
return this.application.__registry__;
}
}]);
return _class;
}(_internalTestHelpers.DefaultResolverApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Application Dependency Injection - Integration - default resolver w/ other namespace',
/*#__PURE__*/
function (_DefaultResolverAppli2) {
(0, _emberBabel.inheritsLoose)(_class2, _DefaultResolverAppli2);
function _class2() {
return _DefaultResolverAppli2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2.beforeEach = function beforeEach() {
var _this6 = this;
this.UserInterface = _environment.context.lookup.UserInterface = _runtime.Namespace.create();
(0, _internalTestHelpers.runTask)(function () {
return _this6.createApplication();
});
return this.visit('/');
};
_proto2.teardown = function teardown() {
var UserInterfaceNamespace = _runtime.Namespace.NAMESPACES_BY_ID['UserInterface'];
if (UserInterfaceNamespace) {
(0, _internalTestHelpers.runTask)(function () {
UserInterfaceNamespace.destroy();
});
}
_DefaultResolverAppli2.prototype.teardown.call(this);
};
_proto2["@test the default resolver can look things up in other namespaces"] = function (assert) {
this.UserInterface.NavigationController = _controller.default.extend();
var nav = this.applicationInstance.lookup('controller:userInterface/navigation');
assert.ok(nav instanceof this.UserInterface.NavigationController, 'the result should be an instance of the specified class');
};
return _class2;
}(_internalTestHelpers.DefaultResolverApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Application Dependency Injection - Integration - default resolver',
/*#__PURE__*/
function (_DefaultResolverAppli3) {
(0, _emberBabel.inheritsLoose)(_class3, _DefaultResolverAppli3);
function _class3() {
var _this7;
_this7 = _DefaultResolverAppli3.call(this) || this;
_this7._originalLookup = _environment.context.lookup;
_this7._originalInfo = (0, _debug.getDebugFunction)('info');
return _this7;
}
var _proto3 = _class3.prototype;
_proto3.beforeEach = function beforeEach() {
var _this8 = this;
(0, _internalTestHelpers.runTask)(function () {
return _this8.createApplication();
});
return this.visit('/');
};
_proto3.teardown = function teardown() {
(0, _debug.setDebugFunction)('info', this._originalInfo);
_environment.context.lookup = this._originalLookup;
_DefaultResolverAppli3.prototype.teardown.call(this);
};
_proto3["@test the default resolver logs hits if 'LOG_RESOLVER' is set"] = function (assert) {
if (EmberDev && EmberDev.runningProdBuild) {
assert.ok(true, 'Logging does not occur in production builds');
return;
}
assert.expect(3);
this.application.LOG_RESOLVER = true;
this.application.ScoobyDoo = _runtime.Object.extend();
this.application.toString = function () {
return 'App';
};
(0, _debug.setDebugFunction)('info', function (symbol, name, padding, lookupDescription) {
assert.equal(symbol, '[✓]', 'proper symbol is printed when a module is found');
assert.equal(name, 'doo:scooby', 'proper lookup value is logged');
assert.equal(lookupDescription, 'App.ScoobyDoo');
});
this.applicationInstance.resolveRegistration('doo:scooby');
};
_proto3["@test the default resolver logs misses if 'LOG_RESOLVER' is set"] = function (assert) {
if (EmberDev && EmberDev.runningProdBuild) {
assert.ok(true, 'Logging does not occur in production builds');
return;
}
assert.expect(3);
this.application.LOG_RESOLVER = true;
this.application.toString = function () {
return 'App';
};
(0, _debug.setDebugFunction)('info', function (symbol, name, padding, lookupDescription) {
assert.equal(symbol, '[ ]', 'proper symbol is printed when a module is not found');
assert.equal(name, 'doo:scooby', 'proper lookup value is logged');
assert.equal(lookupDescription, 'App.ScoobyDoo');
});
this.applicationInstance.resolveRegistration('doo:scooby');
};
_proto3["@test doesn't log without LOG_RESOLVER"] = function (assert) {
if (EmberDev && EmberDev.runningProdBuild) {
assert.ok(true, 'Logging does not occur in production builds');
return;
}
var infoCount = 0;
this.application.ScoobyDoo = _runtime.Object.extend();
(0, _debug.setDebugFunction)('info', function () {
return infoCount = infoCount + 1;
});
this.applicationInstance.resolveRegistration('doo:scooby');
this.applicationInstance.resolveRegistration('doo:scrappy');
assert.equal(infoCount, 0, 'console.info should not be called if LOG_RESOLVER is not set');
};
return _class3;
}(_internalTestHelpers.DefaultResolverApplicationTestCase));
});
enifed("@ember/application/tests/dependency_injection/normalization_test", ["ember-babel", "@ember/runloop", "@ember/application", "internal-test-helpers"], function (_emberBabel, _runloop, _application, _internalTestHelpers) {
"use strict";
var application, registry;
(0, _internalTestHelpers.moduleFor)('Application Dependency Injection - normalize',
/*#__PURE__*/
function (_TestCase) {
(0, _emberBabel.inheritsLoose)(_class, _TestCase);
function _class() {
var _this;
_this = _TestCase.call(this) || this;
application = (0, _runloop.run)(_application.default, 'create');
registry = application.__registry__;
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_TestCase.prototype.teardown.call(this);
(0, _runloop.run)(application, 'destroy');
application = undefined;
registry = undefined;
};
_proto['@test normalization'] = function testNormalization(assert) {
assert.ok(registry.normalize, 'registry#normalize is present');
assert.equal(registry.normalize('foo:bar'), 'foo:bar');
assert.equal(registry.normalize('controller:posts'), 'controller:posts');
assert.equal(registry.normalize('controller:posts_index'), 'controller:postsIndex');
assert.equal(registry.normalize('controller:posts.index'), 'controller:postsIndex');
assert.equal(registry.normalize('controller:posts-index'), 'controller:postsIndex');
assert.equal(registry.normalize('controller:posts.post.index'), 'controller:postsPostIndex');
assert.equal(registry.normalize('controller:posts_post.index'), 'controller:postsPostIndex');
assert.equal(registry.normalize('controller:posts.post_index'), 'controller:postsPostIndex');
assert.equal(registry.normalize('controller:posts.post-index'), 'controller:postsPostIndex');
assert.equal(registry.normalize('controller:postsIndex'), 'controller:postsIndex');
assert.equal(registry.normalize('controller:blogPosts.index'), 'controller:blogPostsIndex');
assert.equal(registry.normalize('controller:blog/posts.index'), 'controller:blog/postsIndex');
assert.equal(registry.normalize('controller:blog/posts-index'), 'controller:blog/postsIndex');
assert.equal(registry.normalize('controller:blog/posts.post.index'), 'controller:blog/postsPostIndex');
assert.equal(registry.normalize('controller:blog/posts_post.index'), 'controller:blog/postsPostIndex');
assert.equal(registry.normalize('controller:blog/posts_post-index'), 'controller:blog/postsPostIndex');
assert.equal(registry.normalize('template:blog/posts_index'), 'template:blog/posts_index');
};
_proto['@test normalization is indempotent'] = function testNormalizationIsIndempotent(assert) {
var examples = ['controller:posts', 'controller:posts.post.index', 'controller:blog/posts.post_index', 'template:foo_bar'];
examples.forEach(function (example) {
assert.equal(registry.normalize(registry.normalize(example)), registry.normalize(example));
});
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/application/tests/dependency_injection/to_string_test", ["ember-babel", "@ember/polyfills", "@ember/-internals/utils", "@ember/-internals/runtime", "internal-test-helpers"], function (_emberBabel, _polyfills, _utils, _runtime, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Application Dependency Injection - DefaultResolver#toString',
/*#__PURE__*/
function (_DefaultResolverAppli) {
(0, _emberBabel.inheritsLoose)(_class, _DefaultResolverAppli);
function _class() {
var _this;
_this = _DefaultResolverAppli.call(this) || this;
(0, _internalTestHelpers.runTask)(function () {
return _this.createApplication();
});
_this.application.Post = _runtime.Object.extend();
return _this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
return this.visit('/');
};
_proto['@test factories'] = function testFactories(assert) {
var PostFactory = this.applicationInstance.factoryFor('model:post').class;
assert.equal(PostFactory.toString(), 'TestApp.Post', 'expecting the model to be post');
};
_proto['@test instances'] = function testInstances(assert) {
var post = this.applicationInstance.lookup('model:post');
var guid = (0, _utils.guidFor)(post);
assert.equal(post.toString(), '', 'expecting the model to be post');
};
return _class;
}(_internalTestHelpers.DefaultResolverApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Application Dependency Injection - Resolver#toString',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class2, _ApplicationTestCase);
function _class2() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2.beforeEach = function beforeEach() {
return this.visit('/');
};
_proto2['@test toString called on a resolver'] = function testToStringCalledOnAResolver(assert) {
this.add('model:peter', _runtime.Object.extend());
var peter = this.applicationInstance.lookup('model:peter');
var guid = (0, _utils.guidFor)(peter);
assert.equal(peter.toString(), "", 'expecting the supermodel to be peter');
};
(0, _emberBabel.createClass)(_class2, [{
key: "applicationOptions",
get: function () {
return (0, _polyfills.assign)(_ApplicationTestCase.prototype.applicationOptions, {
Resolver:
/*#__PURE__*/
function (_ModuleBasedTestResol) {
(0, _emberBabel.inheritsLoose)(Resolver, _ModuleBasedTestResol);
function Resolver() {
return _ModuleBasedTestResol.apply(this, arguments) || this;
}
var _proto3 = Resolver.prototype;
_proto3.makeToString = function makeToString(_, fullName) {
return fullName;
};
return Resolver;
}(_internalTestHelpers.ModuleBasedTestResolver)
});
}
}]);
return _class2;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("@ember/application/tests/dependency_injection_test", ["ember-babel", "@ember/-internals/environment", "@ember/runloop", "@ember/-internals/runtime", "@ember/application", "internal-test-helpers"], function (_emberBabel, _environment, _runloop, _runtime, _application, _internalTestHelpers) {
"use strict";
var originalLookup = _environment.context.lookup;
var registry, locator, application;
(0, _internalTestHelpers.moduleFor)('Application Dependency Injection',
/*#__PURE__*/
function (_TestCase) {
(0, _emberBabel.inheritsLoose)(_class, _TestCase);
function _class() {
var _this;
_this = _TestCase.call(this) || this;
application = (0, _runloop.run)(_application.default, 'create');
application.Person = _runtime.Object.extend({});
application.Orange = _runtime.Object.extend({});
application.Email = _runtime.Object.extend({});
application.User = _runtime.Object.extend({});
application.PostIndexController = _runtime.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__;
_environment.context.lookup = {};
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_TestCase.prototype.teardown.call(this);
(0, _runloop.run)(application, 'destroy');
registry = application = locator = null;
_environment.context.lookup = originalLookup;
};
_proto['@test container lookup is normalized'] = function testContainerLookupIsNormalized(assert) {
var dotNotationController = locator.lookup('controller:post.index');
var camelCaseController = locator.lookup('controller:postIndex');
assert.ok(dotNotationController instanceof application.PostIndexController);
assert.ok(camelCaseController instanceof application.PostIndexController);
assert.equal(dotNotationController, camelCaseController);
};
_proto['@test registered entities can be looked up later'] = function testRegisteredEntitiesCanBeLookedUpLater(assert) {
assert.equal(registry.resolve('model:person'), application.Person);
assert.equal(registry.resolve('model:user'), application.User);
assert.equal(registry.resolve('fruit:favorite'), application.Orange);
assert.equal(registry.resolve('communication:main'), application.Email);
assert.equal(registry.resolve('controller:postIndex'), application.PostIndexController);
assert.equal(locator.lookup('fruit:favorite'), locator.lookup('fruit:favorite'), 'singleton lookup worked');
assert.ok(locator.lookup('model:user') !== locator.lookup('model:user'), 'non-singleton lookup worked');
};
_proto['@test injections'] = function testInjections(assert) {
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');
assert.equal(user.get('fruit'), fruit);
assert.equal(person.get('fruit'), fruit);
assert.ok(application.Email.detectInstance(user.get('communication')));
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/application/tests/initializers_test", ["ember-babel", "@ember/polyfills", "internal-test-helpers", "@ember/application"], function (_emberBabel, _polyfills, _internalTestHelpers, _application) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Application initializers',
/*#__PURE__*/
function (_AutobootApplicationT) {
(0, _emberBabel.inheritsLoose)(_class, _AutobootApplicationT);
function _class() {
return _AutobootApplicationT.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.createSecondApplication = function createSecondApplication(options) {
var MyApplication = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _application.default;
var myOptions = (0, _polyfills.assign)(this.applicationOptions, {
rootElement: '#two'
}, options);
var secondApp = this.secondApp = MyApplication.create(myOptions);
return secondApp;
};
_proto.teardown = function teardown() {
var _this = this;
_AutobootApplicationT.prototype.teardown.call(this);
if (this.secondApp) {
(0, _internalTestHelpers.runTask)(function () {
return _this.secondApp.destroy();
});
}
};
_proto["@test initializers require proper 'name' and 'initialize' properties"] = function () {
var MyApplication = _application.default.extend();
expectAssertion(function () {
MyApplication.initializer({
name: 'initializer'
});
});
expectAssertion(function () {
MyApplication.initializer({
initialize: function () {}
});
});
};
_proto["@test initializers that throw errors cause the boot promise to reject with the error"] = function (assert) {
var _this2 = this;
assert.expect(2);
var MyApplication = _application.default.extend();
MyApplication.initializer({
name: 'initializer',
initialize: function () {
throw new Error('boot failure');
}
});
(0, _internalTestHelpers.runTask)(function () {
_this2.createApplication({
autoboot: false
}, MyApplication);
});
var app = this.application;
try {
(0, _internalTestHelpers.runTask)(function () {
app.boot().then(function () {
assert.ok(false, 'The boot promise should not resolve when there is a boot error');
}, function (error) {
assert.ok(error instanceof Error, 'The boot promise should reject with an error');
assert.equal(error.message, 'boot failure');
});
});
} catch (error) {
assert.ok(false, 'The boot method should not throw');
throw error;
}
};
_proto["@test initializers are passed an App"] = function (assert) {
var _this3 = this;
var MyApplication = _application.default.extend();
MyApplication.initializer({
name: 'initializer',
initialize: function (App) {
assert.ok(App instanceof _application.default, 'initialize is passed an Application');
}
});
(0, _internalTestHelpers.runTask)(function () {
return _this3.createApplication({}, MyApplication);
});
};
_proto["@test initializers can be registered in a specified order"] = function (assert) {
var _this4 = this;
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, _internalTestHelpers.runTask)(function () {
return _this4.createApplication({}, MyApplication);
});
assert.deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']);
};
_proto["@test initializers can be registered in a specified order as an array"] = function (assert) {
var _this5 = this;
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, _internalTestHelpers.runTask)(function () {
return _this5.createApplication({}, MyApplication);
});
assert.deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']);
};
_proto["@test initializers can have multiple dependencies"] = function (assert) {
var _this6 = this;
var order = [];
var MyApplication = _application.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');
}
};
MyApplication.initializer(b);
MyApplication.initializer(a);
MyApplication.initializer(afterC);
MyApplication.initializer(afterB);
MyApplication.initializer(c);
(0, _internalTestHelpers.runTask)(function () {
return _this6.createApplication({}, MyApplication);
});
assert.ok(order.indexOf(a.name) < order.indexOf(b.name), 'a < b');
assert.ok(order.indexOf(b.name) < order.indexOf(c.name), 'b < c');
assert.ok(order.indexOf(b.name) < order.indexOf(afterB.name), 'b < afterB');
assert.ok(order.indexOf(c.name) < order.indexOf(afterC.name), 'c < afterC');
};
_proto["@test initializers set on Application subclasses are not shared between apps"] = function (assert) {
var _this7 = this;
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, _internalTestHelpers.runTask)(function () {
return _this7.createApplication({}, FirstApp);
});
assert.equal(firstInitializerRunCount, 1, 'first initializer only was run');
assert.equal(secondInitializerRunCount, 0, 'first initializer only was run');
(0, _internalTestHelpers.runTask)(function () {
return _this7.createSecondApplication({}, SecondApp);
});
assert.equal(firstInitializerRunCount, 1, 'second initializer only was run');
assert.equal(secondInitializerRunCount, 1, 'second initializer only was run');
};
_proto["@test initializers are concatenated"] = function (assert) {
var _this8 = this;
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, _internalTestHelpers.runTask)(function () {
return _this8.createApplication({}, FirstApp);
});
assert.equal(firstInitializerRunCount, 1, 'first initializer only was run when base class created');
assert.equal(secondInitializerRunCount, 0, 'first initializer only was run when base class created');
firstInitializerRunCount = 0;
(0, _internalTestHelpers.runTask)(function () {
return _this8.createSecondApplication({}, SecondApp);
});
assert.equal(firstInitializerRunCount, 1, 'first initializer was run when subclass created');
assert.equal(secondInitializerRunCount, 1, 'second initializers was run when subclass created');
};
_proto["@test initializers are per-app"] = function (assert) {
assert.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 () {}
});
assert.ok(true, 'Two apps can have initializers named the same.');
};
_proto["@test initializers are executed in their own context"] = function (assert) {
var _this9 = this;
assert.expect(1);
var MyApplication = _application.default.extend();
MyApplication.initializer({
name: 'coolInitializer',
myProperty: 'cool',
initialize: function () {
assert.equal(this.myProperty, 'cool', 'should have access to its own context');
}
});
(0, _internalTestHelpers.runTask)(function () {
return _this9.createApplication({}, MyApplication);
});
};
(0, _emberBabel.createClass)(_class, [{
key: "fixture",
get: function () {
return "
ONE
\n
TWO
\n ";
}
}, {
key: "applicationOptions",
get: function () {
return (0, _polyfills.assign)(_AutobootApplicationT.prototype.applicationOptions, {
rootElement: '#one'
});
}
}]);
return _class;
}(_internalTestHelpers.AutobootApplicationTestCase));
});
enifed("@ember/application/tests/instance_initializers_test", ["ember-babel", "@ember/polyfills", "internal-test-helpers", "@ember/application/instance", "@ember/application"], function (_emberBabel, _polyfills, _internalTestHelpers, _instance, _application) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Application instance initializers',
/*#__PURE__*/
function (_AutobootApplicationT) {
(0, _emberBabel.inheritsLoose)(_class, _AutobootApplicationT);
function _class() {
return _AutobootApplicationT.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.createSecondApplication = function createSecondApplication(options) {
var MyApplication = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _application.default;
var myOptions = (0, _polyfills.assign)(this.applicationOptions, {
rootElement: '#two'
}, options);
var secondApp = this.secondApp = MyApplication.create(myOptions);
return secondApp;
};
_proto.teardown = function teardown() {
var _this = this;
_AutobootApplicationT.prototype.teardown.call(this);
if (this.secondApp) {
(0, _internalTestHelpers.runTask)(function () {
return _this.secondApp.destroy();
});
}
};
_proto["@test initializers require proper 'name' and 'initialize' properties"] = function () {
var _this2 = this;
var MyApplication = _application.default.extend();
expectAssertion(function () {
MyApplication.instanceInitializer({
name: 'initializer'
});
});
expectAssertion(function () {
MyApplication.instanceInitializer({
initialize: function () {}
});
});
(0, _internalTestHelpers.runTask)(function () {
return _this2.createApplication({}, MyApplication);
});
};
_proto["@test initializers are passed an app instance"] = function (assert) {
var _this3 = this;
var MyApplication = _application.default.extend();
MyApplication.instanceInitializer({
name: 'initializer',
initialize: function (instance) {
assert.ok(instance instanceof _instance.default, 'initialize is passed an application instance');
}
});
(0, _internalTestHelpers.runTask)(function () {
return _this3.createApplication({}, MyApplication);
});
};
_proto["@test initializers can be registered in a specified order"] = function (assert) {
var _this4 = this;
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, _internalTestHelpers.runTask)(function () {
return _this4.createApplication({}, MyApplication);
});
assert.deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']);
};
_proto["@test initializers can be registered in a specified order as an array"] = function (assert) {
var _this5 = this;
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, _internalTestHelpers.runTask)(function () {
return _this5.createApplication({}, MyApplication);
});
assert.deepEqual(order, ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']);
};
_proto["@test initializers can have multiple dependencies"] = function (assert) {
var _this6 = this;
var order = [];
var MyApplication = _application.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');
}
};
MyApplication.instanceInitializer(b);
MyApplication.instanceInitializer(a);
MyApplication.instanceInitializer(afterC);
MyApplication.instanceInitializer(afterB);
MyApplication.instanceInitializer(c);
(0, _internalTestHelpers.runTask)(function () {
return _this6.createApplication({}, MyApplication);
});
assert.ok(order.indexOf(a.name) < order.indexOf(b.name), 'a < b');
assert.ok(order.indexOf(b.name) < order.indexOf(c.name), 'b < c');
assert.ok(order.indexOf(b.name) < order.indexOf(afterB.name), 'b < afterB');
assert.ok(order.indexOf(c.name) < order.indexOf(afterC.name), 'c < afterC');
};
_proto["@test initializers set on Application subclasses should not be shared between apps"] = function (assert) {
var _this7 = this;
var firstInitializerRunCount = 0;
var secondInitializerRunCount = 0;
var FirstApp = _application.default.extend();
FirstApp.instanceInitializer({
name: 'first',
initialize: function () {
firstInitializerRunCount++;
}
});
var SecondApp = _application.default.extend();
SecondApp.instanceInitializer({
name: 'second',
initialize: function () {
secondInitializerRunCount++;
}
});
(0, _internalTestHelpers.runTask)(function () {
return _this7.createApplication({}, FirstApp);
});
assert.equal(firstInitializerRunCount, 1, 'first initializer only was run');
assert.equal(secondInitializerRunCount, 0, 'first initializer only was run');
(0, _internalTestHelpers.runTask)(function () {
return _this7.createSecondApplication({}, SecondApp);
});
assert.equal(firstInitializerRunCount, 1, 'second initializer only was run');
assert.equal(secondInitializerRunCount, 1, 'second initializer only was run');
};
_proto["@test initializers are concatenated"] = function (assert) {
var _this8 = this;
var firstInitializerRunCount = 0;
var secondInitializerRunCount = 0;
var FirstApp = _application.default.extend();
FirstApp.instanceInitializer({
name: 'first',
initialize: function () {
firstInitializerRunCount++;
}
});
var SecondApp = FirstApp.extend();
SecondApp.instanceInitializer({
name: 'second',
initialize: function () {
secondInitializerRunCount++;
}
});
(0, _internalTestHelpers.runTask)(function () {
return _this8.createApplication({}, FirstApp);
});
assert.equal(firstInitializerRunCount, 1, 'first initializer only was run when base class created');
assert.equal(secondInitializerRunCount, 0, 'first initializer only was run when base class created');
firstInitializerRunCount = 0;
(0, _internalTestHelpers.runTask)(function () {
return _this8.createSecondApplication({}, SecondApp);
});
assert.equal(firstInitializerRunCount, 1, 'first initializer was run when subclass created');
assert.equal(secondInitializerRunCount, 1, 'second initializers was run when subclass created');
};
_proto["@test initializers are per-app"] = function (assert) {
var _this9 = this;
assert.expect(2);
var FirstApp = _application.default.extend();
FirstApp.instanceInitializer({
name: 'abc',
initialize: function () {}
});
expectAssertion(function () {
FirstApp.instanceInitializer({
name: 'abc',
initialize: function () {}
});
});
(0, _internalTestHelpers.runTask)(function () {
return _this9.createApplication({}, FirstApp);
});
var SecondApp = _application.default.extend();
SecondApp.instanceInitializer({
name: 'abc',
initialize: function () {}
});
(0, _internalTestHelpers.runTask)(function () {
return _this9.createSecondApplication({}, SecondApp);
});
assert.ok(true, 'Two apps can have initializers named the same.');
};
_proto["@test initializers are run before ready hook"] = function (assert) {
var _this10 = this;
assert.expect(2);
var MyApplication = _application.default.extend({
ready: function () {
assert.ok(true, 'ready is called');
readyWasCalled = false;
}
});
var readyWasCalled = false;
MyApplication.instanceInitializer({
name: 'initializer',
initialize: function () {
assert.ok(!readyWasCalled, 'ready is not yet called');
}
});
(0, _internalTestHelpers.runTask)(function () {
return _this10.createApplication({}, MyApplication);
});
};
_proto["@test initializers are executed in their own context"] = function (assert) {
var _this11 = this;
assert.expect(1);
var MyApplication = _application.default.extend();
MyApplication.instanceInitializer({
name: 'coolInitializer',
myProperty: 'cool',
initialize: function () {
assert.equal(this.myProperty, 'cool', 'should have access to its own context');
}
});
(0, _internalTestHelpers.runTask)(function () {
return _this11.createApplication({}, MyApplication);
});
};
_proto["@test initializers get an instance on app reset"] = function (assert) {
var _this12 = this;
assert.expect(2);
var MyApplication = _application.default.extend();
MyApplication.instanceInitializer({
name: 'giveMeAnInstance',
initialize: function (instance) {
assert.ok(Boolean(instance), 'Initializer got an instance');
}
});
(0, _internalTestHelpers.runTask)(function () {
return _this12.createApplication({}, MyApplication);
});
(0, _internalTestHelpers.runTask)(function () {
return _this12.application.reset();
});
};
(0, _emberBabel.createClass)(_class, [{
key: "fixture",
get: function () {
return "
ONE
\n
TWO
\n ";
}
}, {
key: "applicationOptions",
get: function () {
return (0, _polyfills.assign)(_AutobootApplicationT.prototype.applicationOptions, {
rootElement: '#one'
});
}
}]);
return _class;
}(_internalTestHelpers.AutobootApplicationTestCase));
});
enifed("@ember/application/tests/lazy_load_test", ["ember-babel", "@ember/runloop", "@ember/application", "internal-test-helpers"], function (_emberBabel, _runloop, _application, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Lazy Loading',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.afterEach = function afterEach() {
var keys = Object.keys(_application._loaded);
for (var i = 0; i < keys.length; i++) {
delete _application._loaded[keys[i]];
}
};
_proto['@test if a load hook is registered, it is executed when runLoadHooks are exected'] = function testIfALoadHookIsRegisteredItIsExecutedWhenRunLoadHooksAreExected(assert) {
var count = 0;
(0, _runloop.run)(function () {
(0, _application.onLoad)('__test_hook__', function (object) {
count += object;
});
});
(0, _runloop.run)(function () {
(0, _application.runLoadHooks)('__test_hook__', 1);
});
assert.equal(count, 1, 'the object was passed into the load hook');
};
_proto['@test if runLoadHooks was already run, it executes newly added hooks immediately'] = function testIfRunLoadHooksWasAlreadyRunItExecutesNewlyAddedHooksImmediately(assert) {
var count = 0;
(0, _runloop.run)(function () {
(0, _application.onLoad)('__test_hook__', function (object) {
return count += object;
});
});
(0, _runloop.run)(function () {
return (0, _application.runLoadHooks)('__test_hook__', 1);
});
count = 0;
(0, _runloop.run)(function () {
(0, _application.onLoad)('__test_hook__', function (object) {
return count += object;
});
});
assert.equal(count, 1, 'the original object was passed into the load hook');
};
_proto["@test hooks in ENV.EMBER_LOAD_HOOKS['hookName'] get executed"] = function testHooksInENVEMBER_LOAD_HOOKSHookNameGetExecuted(assert) {
// Note that the necessary code to perform this test is run before
// the Ember lib is loaded in tests/index.html
(0, _runloop.run)(function () {
(0, _application.runLoadHooks)('__before_ember_test_hook__', 1);
});
assert.equal(window.ENV.__test_hook_count__, 1, 'the object was passed into the load hook');
};
_proto['@test load hooks trigger a custom event'] = function testLoadHooksTriggerACustomEvent(assert) {
if (typeof window === 'object' && typeof window.dispatchEvent === 'function' && typeof CustomEvent === 'function') {
var eventObject = 'super duper awesome events';
window.addEventListener('__test_hook_for_events__', function (e) {
assert.ok(true, 'custom event was fired');
assert.equal(e.detail, eventObject, 'event details are provided properly');
});
(0, _runloop.run)(function () {
(0, _application.runLoadHooks)('__test_hook_for_events__', eventObject);
});
} else {
assert.expect(0);
}
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("@ember/application/tests/logging_test", ["ember-babel", "internal-test-helpers", "@ember/controller", "@ember/-internals/routing", "@ember/polyfills"], function (_emberBabel, _internalTestHelpers, _controller, _routing, _polyfills) {
"use strict";
/*globals EmberDev */
var LoggingApplicationTestCase =
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(LoggingApplicationTestCase, _ApplicationTestCase);
function LoggingApplicationTestCase() {
var _this;
_this = _ApplicationTestCase.call(this) || this;
_this.logs = {};
/* eslint-disable no-console */
_this._originalLogger = console.info;
console.info = function (_, _ref) {
var fullName = _ref.fullName;
if (!_this.logs.hasOwnProperty(fullName)) {
_this.logs[fullName] = 0;
}
/* eslint-ensable no-console */
_this.logs[fullName]++;
};
_this.router.map(function () {
this.route('posts', {
resetNamespace: true
});
});
return _this;
}
var _proto = LoggingApplicationTestCase.prototype;
_proto.teardown = function teardown() {
/* eslint-disable no-console */
console.info = this._originalLogger;
/* eslint-enable no-console */
_ApplicationTestCase.prototype.teardown.call(this);
};
return LoggingApplicationTestCase;
}(_internalTestHelpers.ApplicationTestCase);
(0, _internalTestHelpers.moduleFor)('Application with LOG_ACTIVE_GENERATION=true',
/*#__PURE__*/
function (_LoggingApplicationTe) {
(0, _emberBabel.inheritsLoose)(_class, _LoggingApplicationTe);
function _class() {
return _LoggingApplicationTe.apply(this, arguments) || this;
}
var _proto2 = _class.prototype;
_proto2['@test log class generation if logging enabled'] = function testLogClassGenerationIfLoggingEnabled(assert) {
var _this2 = this;
if (EmberDev && EmberDev.runningProdBuild) {
assert.ok(true, 'Logging does not occur in production builds');
return;
}
return this.visit('/posts').then(function () {
assert.equal(Object.keys(_this2.logs).length, 4, 'expected logs');
});
};
_proto2['@test actively generated classes get logged'] = function testActivelyGeneratedClassesGetLogged(assert) {
var _this3 = this;
if (EmberDev && EmberDev.runningProdBuild) {
assert.ok(true, 'Logging does not occur in production builds');
return;
}
return this.visit('/posts').then(function () {
assert.equal(_this3.logs['controller:application'], 1, 'expected: ApplicationController was generated');
assert.equal(_this3.logs['controller:posts'], 1, 'expected: PostsController was generated');
assert.equal(_this3.logs['route:application'], 1, 'expected: ApplicationRoute was generated');
assert.equal(_this3.logs['route:posts'], 1, 'expected: PostsRoute was generated');
});
};
_proto2['@test predefined classes do not get logged'] = function testPredefinedClassesDoNotGetLogged(assert) {
var _this4 = this;
this.add('controller:application', _controller.default.extend());
this.add('controller:posts', _controller.default.extend());
this.add('route:application', _routing.Route.extend());
this.add('route:posts', _routing.Route.extend());
return this.visit('/posts').then(function () {
assert.ok(!_this4.logs['controller:application'], 'did not expect: ApplicationController was generated');
assert.ok(!_this4.logs['controller:posts'], 'did not expect: PostsController was generated');
assert.ok(!_this4.logs['route:application'], 'did not expect: ApplicationRoute was generated');
assert.ok(!_this4.logs['route:posts'], 'did not expect: PostsRoute was generated');
});
};
(0, _emberBabel.createClass)(_class, [{
key: "applicationOptions",
get: function () {
return (0, _polyfills.assign)(_LoggingApplicationTe.prototype.applicationOptions, {
LOG_ACTIVE_GENERATION: true
});
}
}]);
return _class;
}(LoggingApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Application when LOG_ACTIVE_GENERATION=false',
/*#__PURE__*/
function (_LoggingApplicationTe2) {
(0, _emberBabel.inheritsLoose)(_class2, _LoggingApplicationTe2);
function _class2() {
return _LoggingApplicationTe2.apply(this, arguments) || this;
}
var _proto3 = _class2.prototype;
_proto3["@test do NOT log class generation if logging disabled"] = function (assert) {
var _this5 = this;
return this.visit('/posts').then(function () {
assert.equal(Object.keys(_this5.logs).length, 0, 'expected logs');
});
};
(0, _emberBabel.createClass)(_class2, [{
key: "applicationOptions",
get: function () {
return (0, _polyfills.assign)(_LoggingApplicationTe2.prototype.applicationOptions, {
LOG_ACTIVE_GENERATION: false
});
}
}]);
return _class2;
}(LoggingApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Application with LOG_VIEW_LOOKUPS=true',
/*#__PURE__*/
function (_LoggingApplicationTe3) {
(0, _emberBabel.inheritsLoose)(_class3, _LoggingApplicationTe3);
function _class3() {
return _LoggingApplicationTe3.apply(this, arguments) || this;
}
var _proto4 = _class3.prototype;
_proto4["@test log when template and view are missing when flag is active"] = function (assert) {
var _this6 = this;
if (EmberDev && EmberDev.runningProdBuild) {
assert.ok(true, 'Logging does not occur in production builds');
return;
}
this.addTemplate('application', '{{outlet}}');
return this.visit('/').then(function () {
return _this6.visit('/posts');
}).then(function () {
assert.equal(_this6.logs['template:application'], undefined, 'expected: Should not log template:application since it exists.');
assert.equal(_this6.logs['template:index'], 1, 'expected: Could not find "index" template or view.');
assert.equal(_this6.logs['template:posts'], 1, 'expected: Could not find "posts" template or view.');
});
};
(0, _emberBabel.createClass)(_class3, [{
key: "applicationOptions",
get: function () {
return (0, _polyfills.assign)(_LoggingApplicationTe3.prototype.applicationOptions, {
LOG_VIEW_LOOKUPS: true
});
}
}]);
return _class3;
}(LoggingApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Application with LOG_VIEW_LOOKUPS=false',
/*#__PURE__*/
function (_LoggingApplicationTe4) {
(0, _emberBabel.inheritsLoose)(_class4, _LoggingApplicationTe4);
function _class4() {
return _LoggingApplicationTe4.apply(this, arguments) || this;
}
var _proto5 = _class4.prototype;
_proto5["@test do not log when template and view are missing when flag is not true"] = function (assert) {
var _this7 = this;
return this.visit('/posts').then(function () {
assert.equal(Object.keys(_this7.logs).length, 0, 'expected no logs');
});
};
_proto5["@test do not log which views are used with templates when flag is not true"] = function (assert) {
var _this8 = this;
return this.visit('/posts').then(function () {
assert.equal(Object.keys(_this8.logs).length, 0, 'expected no logs');
});
};
(0, _emberBabel.createClass)(_class4, [{
key: "applicationOptions",
get: function () {
return (0, _polyfills.assign)(_LoggingApplicationTe4.prototype.applicationOptions, {
LOG_VIEW_LOOKUPS: false
});
}
}]);
return _class4;
}(LoggingApplicationTestCase));
});
enifed("@ember/application/tests/readiness_test", ["ember-babel", "internal-test-helpers", "@ember/runloop", "@ember/application"], function (_emberBabel, _internalTestHelpers, _runloop, _application) {
"use strict";
var jQuery, application, Application;
var readyWasCalled, domReady, readyCallbacks; // 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.
(0, _internalTestHelpers.moduleFor)('Application readiness',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
var _this;
_this = _ApplicationTestCase.call(this) || this;
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 () {
if (domReadyCalled !== 0) {
return;
}
domReadyCalled++;
for (var i = 0; i < readyCallbacks.length; i++) {
readyCallbacks[i]();
}
};
Application = _application.default.extend({
$: jQuery,
ready: function () {
readyWasCalled++;
}
});
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
if (application) {
(0, _runloop.run)(function () {
return application.destroy();
});
jQuery = readyCallbacks = domReady = Application = application = undefined;
}
} // 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.
;
_proto["@test Application's ready event is called right away if jQuery is already ready"] = function testApplicationSReadyEventIsCalledRightAwayIfJQueryIsAlreadyReady(assert) {
jQuery.isReady = true;
(0, _runloop.run)(function () {
application = Application.create({
router: false
});
assert.equal(readyWasCalled, 0, 'ready is not called until later');
});
assert.equal(readyWasCalled, 1, 'ready was called');
domReady();
assert.equal(readyWasCalled, 1, "application's ready was not called again");
};
_proto["@test Application's ready event is called after the document becomes ready"] = function testApplicationSReadyEventIsCalledAfterTheDocumentBecomesReady(assert) {
(0, _runloop.run)(function () {
application = Application.create({
router: false
});
});
assert.equal(readyWasCalled, 0, "ready wasn't called yet");
domReady();
assert.equal(readyWasCalled, 1, 'ready was called now that DOM is ready');
};
_proto["@test Application's ready event can be deferred by other components"] = function testApplicationSReadyEventCanBeDeferredByOtherComponents(assert) {
(0, _runloop.run)(function () {
application = Application.create({
router: false
});
application.deferReadiness();
});
assert.equal(readyWasCalled, 0, "ready wasn't called yet");
domReady();
assert.equal(readyWasCalled, 0, "ready wasn't called yet");
(0, _runloop.run)(function () {
application.advanceReadiness();
assert.equal(readyWasCalled, 0);
});
assert.equal(readyWasCalled, 1, 'ready was called now all readiness deferrals are advanced');
};
_proto["@test Application's ready event can be deferred by other components"] = function testApplicationSReadyEventCanBeDeferredByOtherComponents(assert) {
jQuery.isReady = false;
(0, _runloop.run)(function () {
application = Application.create({
router: false
});
application.deferReadiness();
assert.equal(readyWasCalled, 0, "ready wasn't called yet");
});
domReady();
assert.equal(readyWasCalled, 0, "ready wasn't called yet");
(0, _runloop.run)(function () {
application.advanceReadiness();
});
assert.equal(readyWasCalled, 1, 'ready was called now all readiness deferrals are advanced');
expectAssertion(function () {
application.deferReadiness();
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("@ember/application/tests/reset_test", ["ember-babel", "@ember/runloop", "@ember/-internals/metal", "@ember/controller", "@ember/-internals/routing", "internal-test-helpers"], function (_emberBabel, _runloop, _metal, _controller, _routing, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Application - resetting',
/*#__PURE__*/
function (_AutobootApplicationT) {
(0, _emberBabel.inheritsLoose)(_class, _AutobootApplicationT);
function _class() {
return _AutobootApplicationT.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Brings its own run-loop if not provided'] = function testBringsItsOwnRunLoopIfNotProvided(assert) {
var _this = this;
assert.expect(0);
(0, _runloop.run)(function () {
return _this.createApplication();
});
this.application.reset();
};
_proto['@test Does not bring its own run loop if one is already provided'] = function testDoesNotBringItsOwnRunLoopIfOneIsAlreadyProvided(assert) {
var _this2 = this;
assert.expect(3);
var didBecomeReady = false;
(0, _runloop.run)(function () {
return _this2.createApplication();
});
(0, _runloop.run)(function () {
_this2.application.ready = function () {
didBecomeReady = true;
};
_this2.application.reset();
_this2.application.deferReadiness();
assert.ok(!didBecomeReady, 'app is not ready');
});
assert.ok(!didBecomeReady, 'app is not ready');
(0, _runloop.run)(this.application, 'advanceReadiness');
assert.ok(didBecomeReady, 'app is ready');
};
_proto['@test When an application is reset, new instances of controllers are generated'] = function testWhenAnApplicationIsResetNewInstancesOfControllersAreGenerated(assert) {
var _this3 = this;
(0, _runloop.run)(function () {
_this3.createApplication();
_this3.add('controller:academic', _controller.default.extend());
});
var firstController = this.applicationInstance.lookup('controller:academic');
var secondController = this.applicationInstance.lookup('controller:academic');
this.application.reset();
var thirdController = this.applicationInstance.lookup('controller:academic');
assert.strictEqual(firstController, secondController, 'controllers looked up in succession should be the same instance');
assert.ok(firstController.isDestroying, 'controllers are destroyed when their application is reset');
assert.notStrictEqual(firstController, thirdController, 'controllers looked up after the application is reset should not be the same instance');
};
_proto['@test When an application is reset, the eventDispatcher is destroyed and recreated'] = function testWhenAnApplicationIsResetTheEventDispatcherIsDestroyedAndRecreated(assert) {
var _this4 = this;
var eventDispatcherWasSetup = 0;
var eventDispatcherWasDestroyed = 0;
var mockEventDispatcher = {
setup: function () {
eventDispatcherWasSetup++;
},
destroy: function () {
eventDispatcherWasDestroyed++;
}
};
(0, _runloop.run)(function () {
_this4.createApplication();
_this4.add('event_dispatcher:main', {
create: function () {
return mockEventDispatcher;
}
});
assert.equal(eventDispatcherWasSetup, 0);
assert.equal(eventDispatcherWasDestroyed, 0);
});
assert.equal(eventDispatcherWasSetup, 1);
assert.equal(eventDispatcherWasDestroyed, 0);
this.application.reset();
assert.equal(eventDispatcherWasDestroyed, 1);
assert.equal(eventDispatcherWasSetup, 2, 'setup called after reset');
};
_proto['@test When an application is reset, the router URL is reset to `/`'] = function testWhenAnApplicationIsResetTheRouterURLIsResetTo(assert) {
var _this5 = this;
(0, _runloop.run)(function () {
_this5.createApplication();
_this5.add('router:main', _routing.Router.extend({
location: 'none'
}));
_this5.router.map(function () {
this.route('one');
this.route('two');
});
});
var initialRouter, initialApplicationController;
return this.visit('/one').then(function () {
initialApplicationController = _this5.applicationInstance.lookup('controller:application');
initialRouter = _this5.applicationInstance.lookup('router:main');
var location = initialRouter.get('location');
assert.equal(location.getURL(), '/one');
assert.equal((0, _metal.get)(initialApplicationController, 'currentPath'), 'one');
_this5.application.reset();
return _this5.application._bootPromise;
}).then(function () {
var applicationController = _this5.applicationInstance.lookup('controller:application');
assert.strictEqual(applicationController, undefined, 'application controller no longer exists');
return _this5.visit('/one');
}).then(function () {
var applicationController = _this5.applicationInstance.lookup('controller:application');
var router = _this5.applicationInstance.lookup('router:main');
var location = router.get('location');
assert.notEqual(initialRouter, router, 'a different router instance was created');
assert.notEqual(initialApplicationController, applicationController, 'a different application controller is created');
assert.equal(location.getURL(), '/one');
assert.equal((0, _metal.get)(applicationController, 'currentPath'), 'one');
});
};
_proto['@test When an application with advance/deferReadiness is reset, the app does correctly become ready after reset'] = function testWhenAnApplicationWithAdvanceDeferReadinessIsResetTheAppDoesCorrectlyBecomeReadyAfterReset(assert) {
var _this6 = this;
var readyCallCount = 0;
(0, _runloop.run)(function () {
_this6.createApplication({
ready: function () {
readyCallCount++;
}
});
_this6.application.deferReadiness();
assert.equal(readyCallCount, 0, 'ready has not yet been called');
});
(0, _runloop.run)(this.application, 'advanceReadiness');
assert.equal(readyCallCount, 1, 'ready was called once');
this.application.reset();
assert.equal(readyCallCount, 2, 'ready was called twice');
};
return _class;
}(_internalTestHelpers.AutobootApplicationTestCase));
});
enifed("@ember/application/tests/visit_test", ["ember-babel", "internal-test-helpers", "@ember/service", "@ember/-internals/runtime", "@ember/runloop", "@ember/application", "@ember/application/instance", "@ember/engine", "@ember/-internals/routing", "@ember/-internals/glimmer", "ember-template-compiler", "@ember/-internals/environment"], function (_emberBabel, _internalTestHelpers, _service, _runtime, _runloop, _application, _instance, _engine, _routing, _glimmer, _emberTemplateCompiler, _environment) {
"use strict";
function expectAsyncError() {
_runtime.RSVP.off('error');
}
(0, _internalTestHelpers.moduleFor)('Application - visit()',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_runtime.RSVP.on('error', _runtime.onerrorDefault);
_environment.ENV._APPLICATION_TEMPLATE_WRAPPER = false;
_ApplicationTestCase.prototype.teardown.call(this);
};
_proto.createApplication = function createApplication(options) {
return _ApplicationTestCase.prototype.createApplication.call(this, options, _application.default.extend());
};
_proto.assertEmptyFixture = function assertEmptyFixture(message) {
this.assert.strictEqual(document.getElementById('qunit-fixture').children.length, 0, "there are no elements in the fixture element " + (message ? message : ''));
};
_proto["@test does not add serialize-mode markers by default"] = function (assert) {
var templateContent = '
Hi, Mom!
';
this.addTemplate('index', templateContent);
var rootElement = document.createElement('div');
var bootOptions = {
isBrowser: false,
rootElement: rootElement
};
_environment.ENV._APPLICATION_TEMPLATE_WRAPPER = false;
return this.visit('/', bootOptions).then(function () {
assert.equal(rootElement.innerHTML, templateContent, 'without serialize flag renders as expected');
});
};
_proto["@test _renderMode: rehydration"] = function (assert) {
var _this = this;
assert.expect(2);
var indexTemplate = '
Hi, Mom!
';
this.addTemplate('index', indexTemplate);
var rootElement = document.createElement('div');
var bootOptions = {
isBrowser: false,
rootElement: rootElement,
_renderMode: 'serialize'
};
_environment.ENV._APPLICATION_TEMPLATE_WRAPPER = false;
return this.visit('/', bootOptions).then(function (instance) {
assert.ok((0, _glimmer.isSerializationFirstNode)(instance.rootElement.firstChild), 'glimmer-vm comment node was not found');
}).then(function () {
return (0, _internalTestHelpers.runTask)(function () {
_this.applicationInstance.destroy();
_this.applicationInstance = null;
});
}).then(function () {
bootOptions = {
isBrowser: false,
rootElement: rootElement,
_renderMode: 'rehydrate'
};
_this.application.visit('/', bootOptions).then(function (instance) {
assert.equal(instance.rootElement.innerHTML, indexTemplate, 'was not properly rehydrated');
});
});
} // 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.
;
_proto["@test Applications with autoboot set to false do not autoboot"] = function (assert) {
var _this2 = this;
function delay(time) {
return new _runtime.RSVP.Promise(function (resolve) {
return (0, _runloop.later)(resolve, time);
});
}
var appBooted = 0;
var instanceBooted = 0;
this.application.initializer({
name: 'assert-no-autoboot',
initialize: function () {
appBooted++;
}
});
this.application.instanceInitializer({
name: 'assert-no-autoboot',
initialize: function () {
instanceBooted++;
}
});
assert.ok(!this.applicationInstance, 'precond - no instance');
assert.ok(appBooted === 0, 'precond - not booted');
assert.ok(instanceBooted === 0, 'precond - not booted'); // Continue after 500ms
return delay(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, _internalTestHelpers.runTask)(function () {
return _this2.application.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()');
});
};
_proto["@test calling visit() on an app without first calling boot() should boot the app"] = function (assert) {
var appBooted = 0;
var instanceBooted = 0;
this.application.initializer({
name: 'assert-no-autoboot',
initialize: function () {
appBooted++;
}
});
this.application.instanceInitializer({
name: 'assert-no-autoboot',
initialize: function () {
instanceBooted++;
}
});
return this.visit('/').then(function () {
assert.ok(appBooted === 1, 'the app should be booted`');
assert.ok(instanceBooted === 1, 'an instances should be booted');
});
};
_proto["@test calling visit() on an already booted app should not boot it again"] = function (assert) {
var _this3 = this;
var appBooted = 0;
var instanceBooted = 0;
this.application.initializer({
name: 'assert-no-autoboot',
initialize: function () {
appBooted++;
}
});
this.application.instanceInitializer({
name: 'assert-no-autoboot',
initialize: function () {
instanceBooted++;
}
});
return (0, _internalTestHelpers.runTask)(function () {
return _this3.application.boot();
}).then(function () {
assert.ok(appBooted === 1, 'the app should be booted');
assert.ok(instanceBooted === 0, 'no instances should be booted');
return _this3.visit('/');
}).then(function () {
assert.ok(appBooted === 1, 'the app should not be booted again');
assert.ok(instanceBooted === 1, 'an instance should be booted');
/*
* Destroy the instance.
*/
return (0, _internalTestHelpers.runTask)(function () {
_this3.applicationInstance.destroy();
_this3.applicationInstance = null;
});
}).then(function () {
/*
* Visit on the application a second time. The application should remain
* booted, but a new instance will be created.
*/
return _this3.application.visit('/').then(function (instance) {
_this3.applicationInstance = instance;
});
}).then(function () {
assert.ok(appBooted === 1, 'the app should not be booted again');
assert.ok(instanceBooted === 2, 'another instance should be booted');
});
};
_proto["@test visit() rejects on application boot failure"] = function (assert) {
this.application.initializer({
name: 'error',
initialize: function () {
throw new Error('boot failure');
}
});
expectAsyncError();
return this.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');
});
};
_proto["@test visit() rejects on instance boot failure"] = function (assert) {
this.application.instanceInitializer({
name: 'error',
initialize: function () {
throw new Error('boot failure');
}
});
expectAsyncError();
return this.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');
});
};
_proto["@test visit() follows redirects"] = function (assert) {
this.router.map(function () {
this.route('a');
this.route('b', {
path: '/b/:b'
});
this.route('c', {
path: '/c/:c'
});
});
this.add('route:a', _routing.Route.extend({
afterModel: function () {
this.replaceWith('b', 'zomg');
}
}));
this.add('route:b', _routing.Route.extend({
afterModel: function (params) {
this.transitionTo('c', params.b);
}
}));
/*
* First call to `visit` is `this.application.visit` and returns the
* applicationInstance.
*/
return this.visit('/a').then(function (instance) {
assert.ok(instance instanceof _instance.default, 'promise is resolved with an ApplicationInstance');
assert.equal(instance.getURL(), '/c/zomg', 'It should follow all redirects');
});
};
_proto["@test visit() rejects if an error occurred during a transition"] = function (assert) {
this.router.map(function () {
this.route('a');
this.route('b', {
path: '/b/:b'
});
this.route('c', {
path: '/c/:c'
});
});
this.add('route:a', _routing.Route.extend({
afterModel: function () {
this.replaceWith('b', 'zomg');
}
}));
this.add('route:b', _routing.Route.extend({
afterModel: function (params) {
this.transitionTo('c', params.b);
}
}));
this.add('route:c', _routing.Route.extend({
afterModel: function () {
throw new Error('transition failure');
}
}));
expectAsyncError();
return this.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');
});
};
_proto["@test visit() chain"] = function (assert) {
this.router.map(function () {
this.route('a');
this.route('b');
this.route('c');
});
return this.visit('/').then(function (instance) {
assert.ok(instance instanceof _instance.default, 'promise is resolved with an ApplicationInstance');
assert.equal(instance.getURL(), '/');
return instance.visit('/a');
}).then(function (instance) {
assert.ok(instance instanceof _instance.default, 'promise is resolved with an ApplicationInstance');
assert.equal(instance.getURL(), '/a');
return instance.visit('/b');
}).then(function (instance) {
assert.ok(instance instanceof _instance.default, 'promise is resolved with an ApplicationInstance');
assert.equal(instance.getURL(), '/b');
return instance.visit('/c');
}).then(function (instance) {
assert.ok(instance instanceof _instance.default, 'promise is resolved with an ApplicationInstance');
assert.equal(instance.getURL(), '/c');
});
};
_proto["@test visit() returns a promise that resolves when the view has rendered"] = function (assert) {
var _this4 = this;
this.addTemplate('application', "
Hello world
");
this.assertEmptyFixture();
return this.visit('/').then(function (instance) {
assert.ok(instance instanceof _instance.default, 'promise is resolved with an ApplicationInstance');
assert.equal(_this4.element.textContent, 'Hello world', 'the application was rendered once the promise resolves');
});
};
_proto["@test visit() returns a promise that resolves without rendering when shouldRender is set to false"] = function (assert) {
var _this5 = this;
assert.expect(3);
this.addTemplate('application', '
Hello world
');
this.assertEmptyFixture();
return this.visit('/', {
shouldRender: false
}).then(function (instance) {
assert.ok(instance instanceof _instance.default, 'promise is resolved with an ApplicationInstance');
_this5.assertEmptyFixture('after visit');
});
};
_proto["@test visit() renders a template when shouldRender is set to true"] = function (assert) {
assert.expect(3);
this.addTemplate('application', '
Hello world
');
this.assertEmptyFixture();
return this.visit('/', {
shouldRender: true
}).then(function (instance) {
assert.ok(instance instanceof _instance.default, 'promise is resolved with an ApplicationInstance');
assert.strictEqual(document.querySelector('#qunit-fixture').children.length, 1, 'there is 1 element in the fixture element after visit');
});
};
_proto["@test visit() returns a promise that resolves without rendering when shouldRender is set to false with Engines"] = function (assert) {
var _this6 = this;
assert.expect(3);
this.router.map(function () {
this.mount('blog');
});
this.addTemplate('application', '
Hello world
'); // Register engine
var BlogEngine = _engine.default.extend();
this.add('engine:blog', BlogEngine); // Register engine route map
var BlogMap = function () {};
this.add('route-map:blog', BlogMap);
this.assertEmptyFixture();
return this.visit('/blog', {
shouldRender: false
}).then(function (instance) {
assert.ok(instance instanceof _instance.default, 'promise is resolved with an ApplicationInstance');
_this6.assertEmptyFixture('after visit');
});
};
_proto["@test visit() does not setup the event_dispatcher:main if isInteractive is false (with Engines) GH#15615"] = function (assert) {
var _this7 = this;
assert.expect(3);
this.router.map(function () {
this.mount('blog');
});
this.addTemplate('application', '
Hello world
{{outlet}}');
this.add('event_dispatcher:main', {
create: function () {
throw new Error('should not happen!');
}
}); // Register engine
var BlogEngine = _engine.default.extend({
init: function () {
for (var _len = arguments.length, args = new 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', _glimmer.Component.extend({}));
}
});
this.add('engine:blog', BlogEngine); // Register engine route map
var BlogMap = function () {};
this.add('route-map:blog', BlogMap);
this.assertEmptyFixture();
return this.visit('/blog', {
isInteractive: false
}).then(function (instance) {
assert.ok(instance instanceof _instance.default, 'promise is resolved with an ApplicationInstance');
assert.strictEqual(_this7.element.querySelector('p').textContent, 'Dis cache money', 'Engine component is resolved');
});
};
_proto["@test visit() on engine resolves engine component"] = function (assert) {
var _this8 = this;
assert.expect(2);
this.router.map(function () {
this.mount('blog');
}); // Register engine
var BlogEngine = _engine.default.extend({
init: function () {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
this._super.apply(this, args);
this.register('template:application', (0, _emberTemplateCompiler.compile)('{{cache-money}}'));
this.register('template:components/cache-money', (0, _emberTemplateCompiler.compile)("\n
\n ");
this.addTemplate('index', "{{index-wrapper}}");
(0, _internalTestHelpers.runTask)(function () {
_this25.application.advanceReadiness();
});
var _this$application$tes10 = this.application.testHelpers,
wait = _this$application$tes10.wait,
triggerEvent = _this$application$tes10.triggerEvent;
return wait().then(function () {
return triggerEvent('.input', '#limited', 'keydown', {
keyCode: 13
});
}).then(function () {
assert.equal(event.keyCode, 13, 'options were passed');
assert.equal(event.type, 'keydown', 'correct event was triggered');
assert.equal(event.target.getAttribute('id'), 'inside-scope', 'triggered on the correct element');
});
};
return _class2;
}(HelpersApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing: debugging helpers',
/*#__PURE__*/
function (_HelpersApplicationTe2) {
(0, _emberBabel.inheritsLoose)(_class3, _HelpersApplicationTe2);
var _proto4 = _class3.prototype;
_proto4.afterEach = function afterEach() {
_HelpersApplicationTe2.prototype.afterEach.call(this);
(0, _debug.setDebugFunction)('info', originalInfo);
};
function _class3() {
var _this26;
_this26 = _HelpersApplicationTe2.call(this) || this;
(0, _internalTestHelpers.runTask)(function () {
_this26.application.advanceReadiness();
});
return _this26;
}
_proto4["@test pauseTest pauses"] = function (assert) {
assert.expect(1); // overwrite info to supress the console output (see https://github.com/emberjs/ember.js/issues/16391)
(0, _debug.setDebugFunction)('info', noop);
var _this$application$tes11 = this.application.testHelpers,
andThen = _this$application$tes11.andThen,
pauseTest = _this$application$tes11.pauseTest;
andThen(function () {
_test.default.adapter.asyncStart = function () {
assert.ok(true, 'Async start should be called after waiting for other helpers');
};
});
pauseTest();
};
_proto4["@test resumeTest resumes paused tests"] = function (assert) {
assert.expect(1); // overwrite info to supress the console output (see https://github.com/emberjs/ember.js/issues/16391)
(0, _debug.setDebugFunction)('info', noop);
var _this$application$tes12 = this.application.testHelpers,
pauseTest = _this$application$tes12.pauseTest,
resumeTest = _this$application$tes12.resumeTest;
(0, _runloop.later)(function () {
return resumeTest();
}, 20);
return pauseTest().then(function () {
assert.ok(true, 'pauseTest promise was resolved');
});
};
_proto4["@test resumeTest throws if nothing to resume"] = function (assert) {
var _this27 = this;
assert.expect(1);
assert.throws(function () {
_this27.application.testHelpers.resumeTest();
}, /Testing has not been paused. There is nothing to resume./);
};
return _class3;
}(HelpersApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing: routing helpers',
/*#__PURE__*/
function (_HelpersTestCase3) {
(0, _emberBabel.inheritsLoose)(_class4, _HelpersTestCase3);
function _class4() {
var _this28;
_this28 = _HelpersTestCase3.call(this) || this;
(0, _internalTestHelpers.runTask)(function () {
_this28.createApplication();
_this28.application.setupForTesting();
_this28.application.injectTestHelpers();
_this28.router.map(function () {
this.route('posts', {
resetNamespace: true
}, function () {
this.route('new');
this.route('edit', {
resetNamespace: true
});
});
});
});
(0, _internalTestHelpers.runTask)(function () {
_this28.application.advanceReadiness();
});
return _this28;
}
var _proto5 = _class4.prototype;
_proto5["@test currentRouteName for '/'"] = function (assert) {
assert.expect(3);
var testHelpers = this.application.testHelpers;
return testHelpers.visit('/').then(function () {
assert.equal(testHelpers.currentRouteName(), 'index', "should equal 'index'.");
assert.equal(testHelpers.currentPath(), 'index', "should equal 'index'.");
assert.equal(testHelpers.currentURL(), '/', "should equal '/'.");
});
};
_proto5["@test currentRouteName for '/posts'"] = function (assert) {
assert.expect(3);
var testHelpers = this.application.testHelpers;
return testHelpers.visit('/posts').then(function () {
assert.equal(testHelpers.currentRouteName(), 'posts.index', "should equal 'posts.index'.");
assert.equal(testHelpers.currentPath(), 'posts.index', "should equal 'posts.index'.");
assert.equal(testHelpers.currentURL(), '/posts', "should equal '/posts'.");
});
};
_proto5["@test currentRouteName for '/posts/new'"] = function (assert) {
assert.expect(3);
var testHelpers = this.application.testHelpers;
return testHelpers.visit('/posts/new').then(function () {
assert.equal(testHelpers.currentRouteName(), 'posts.new', "should equal 'posts.new'.");
assert.equal(testHelpers.currentPath(), 'posts.new', "should equal 'posts.new'.");
assert.equal(testHelpers.currentURL(), '/posts/new', "should equal '/posts/new'.");
});
};
_proto5["@test currentRouteName for '/posts/edit'"] = function (assert) {
assert.expect(3);
var testHelpers = this.application.testHelpers;
return testHelpers.visit('/posts/edit').then(function () {
assert.equal(testHelpers.currentRouteName(), 'edit', "should equal 'edit'.");
assert.equal(testHelpers.currentPath(), 'posts.edit', "should equal 'posts.edit'.");
assert.equal(testHelpers.currentURL(), '/posts/edit', "should equal '/posts/edit'.");
});
};
return _class4;
}(HelpersTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing: pendingRequests',
/*#__PURE__*/
function (_HelpersApplicationTe3) {
(0, _emberBabel.inheritsLoose)(_class5, _HelpersApplicationTe3);
function _class5() {
return _HelpersApplicationTe3.apply(this, arguments) || this;
}
var _proto6 = _class5.prototype;
_proto6.trigger = function trigger(type, xhr) {
(0, _views.jQuery)(document).trigger(type, xhr);
};
_proto6["@test pendingRequests is maintained for ajaxSend and ajaxComplete events"] = function (assert) {
var done = assert.async();
assert.equal((0, _pending_requests.pendingRequests)(), 0);
var xhr = {
some: 'xhr'
};
this.trigger('ajaxSend', xhr);
assert.equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests was incremented');
this.trigger('ajaxComplete', xhr);
setTimeout(function () {
assert.equal((0, _pending_requests.pendingRequests)(), 0, 'Ember.Test.pendingRequests was decremented');
done();
}, 0);
};
_proto6["@test pendingRequests is ignores ajaxComplete events from past setupForTesting calls"] = function (assert) {
assert.equal((0, _pending_requests.pendingRequests)(), 0);
var xhr = {
some: 'xhr'
};
this.trigger('ajaxSend', xhr);
assert.equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests was incremented');
(0, _setup_for_testing.default)();
assert.equal((0, _pending_requests.pendingRequests)(), 0, 'Ember.Test.pendingRequests was reset');
var altXhr = {
some: 'more xhr'
};
this.trigger('ajaxSend', altXhr);
assert.equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests was incremented');
this.trigger('ajaxComplete', xhr);
assert.equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests is not impressed with your unexpected complete');
};
_proto6["@test pendingRequests is reset by setupForTesting"] = function (assert) {
(0, _pending_requests.incrementPendingRequests)();
(0, _setup_for_testing.default)();
assert.equal((0, _pending_requests.pendingRequests)(), 0, 'pendingRequests is reset');
};
return _class5;
}(HelpersApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing: async router',
/*#__PURE__*/
function (_HelpersTestCase4) {
(0, _emberBabel.inheritsLoose)(_class6, _HelpersTestCase4);
function _class6() {
var _this29;
_this29 = _HelpersTestCase4.call(this) || this;
(0, _internalTestHelpers.runTask)(function () {
_this29.createApplication();
_this29.router.map(function () {
this.route('user', {
resetNamespace: true
}, function () {
this.route('profile');
this.route('edit');
});
}); // Emulate a long-running unscheduled async operation.
var resolveLater = function () {
return new _runtime.RSVP.Promise(function (resolve) {
/*
* The wait() helper has a 10ms tick. We should resolve() after
* at least one tick to test whether wait() held off while the
* async router was still loading. 20ms should be enough.
*/
(0, _runloop.later)(resolve, {
firstName: 'Tom'
}, 20);
});
};
_this29.add('route:user', _routing.Route.extend({
model: function () {
return resolveLater();
}
}));
_this29.add('route:user.profile', _routing.Route.extend({
beforeModel: function () {
var _this30 = this;
return resolveLater().then(function () {
return _this30.transitionTo('user.edit');
});
}
}));
_this29.application.setupForTesting();
});
_this29.application.injectTestHelpers();
(0, _internalTestHelpers.runTask)(function () {
_this29.application.advanceReadiness();
});
return _this29;
}
var _proto7 = _class6.prototype;
_proto7["@test currentRouteName for '/user'"] = function (assert) {
var _this31 = this;
assert.expect(4);
var testHelpers = this.application.testHelpers;
return testHelpers.visit('/user').then(function () {
assert.equal(testHelpers.currentRouteName(), 'user.index', "should equal 'user.index'.");
assert.equal(testHelpers.currentPath(), 'user.index', "should equal 'user.index'.");
assert.equal(testHelpers.currentURL(), '/user', "should equal '/user'.");
var userRoute = _this31.applicationInstance.lookup('route:user');
assert.equal(userRoute.get('controller.model.firstName'), 'Tom', "should equal 'Tom'.");
});
};
_proto7["@test currentRouteName for '/user/profile'"] = function (assert) {
var _this32 = this;
assert.expect(4);
var testHelpers = this.application.testHelpers;
return testHelpers.visit('/user/profile').then(function () {
assert.equal(testHelpers.currentRouteName(), 'user.edit', "should equal 'user.edit'.");
assert.equal(testHelpers.currentPath(), 'user.edit', "should equal 'user.edit'.");
assert.equal(testHelpers.currentURL(), '/user/edit', "should equal '/user/edit'.");
var userRoute = _this32.applicationInstance.lookup('route:user');
assert.equal(userRoute.get('controller.model.firstName'), 'Tom', "should equal 'Tom'.");
});
};
return _class6;
}(HelpersTestCase));
(0, _internalTestHelpers.moduleFor)('ember-testing: can override built-in helpers',
/*#__PURE__*/
function (_HelpersTestCase5) {
(0, _emberBabel.inheritsLoose)(_class7, _HelpersTestCase5);
function _class7() {
var _this33;
_this33 = _HelpersTestCase5.call(this) || this;
(0, _internalTestHelpers.runTask)(function () {
_this33.createApplication();
_this33.application.setupForTesting();
});
_this33._originalVisitHelper = _test.default._helpers.visit;
_this33._originalFindHelper = _test.default._helpers.find;
return _this33;
}
var _proto8 = _class7.prototype;
_proto8.teardown = function teardown() {
_test.default._helpers.visit = this._originalVisitHelper;
_test.default._helpers.find = this._originalFindHelper;
_HelpersTestCase5.prototype.teardown.call(this);
};
_proto8["@test can override visit helper"] = function (assert) {
assert.expect(1);
_test.default.registerHelper('visit', function () {
assert.ok(true, 'custom visit helper was called');
});
this.application.injectTestHelpers();
return this.application.testHelpers.visit();
};
_proto8["@test can override find helper"] = function (assert) {
assert.expect(1);
_test.default.registerHelper('find', function () {
assert.ok(true, 'custom find helper was called');
return ['not empty array'];
});
this.application.injectTestHelpers();
return this.application.testHelpers.findWithAssert('.who-cares');
};
return _class7;
}(HelpersTestCase));
}
});
enifed("ember-testing/tests/integration_test", ["ember-babel", "internal-test-helpers", "ember-testing/lib/test", "@ember/-internals/runtime", "@ember/-internals/routing", "@ember/-internals/views"], function (_emberBabel, _internalTestHelpers, _test, _runtime, _routing, _views) {
"use strict";
(0, _internalTestHelpers.moduleFor)('ember-testing Integration tests of acceptance',
/*#__PURE__*/
function (_AutobootApplicationT) {
(0, _emberBabel.inheritsLoose)(_class, _AutobootApplicationT);
function _class() {
var _this;
_this = _AutobootApplicationT.call(this) || this;
_this.modelContent = [];
_this._originalAdapter = _test.default.adapter;
(0, _internalTestHelpers.runTask)(function () {
_this.createApplication();
_this.addTemplate('people', "\n
\n {{#each model as |person|}}\n
{{person.firstName}}
\n {{/each}}\n
\n ");
_this.router.map(function () {
this.route('people', {
path: '/'
});
});
_this.add('route:people', _routing.Route.extend({
model: function () {
return _this.modelContent;
}
}));
_this.application.setupForTesting();
});
(0, _internalTestHelpers.runTask)(function () {
_this.application.reset();
});
_this.application.injectTestHelpers();
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_AutobootApplicationT.prototype.teardown.call(this);
_test.default.adapter = this._originalAdapter;
};
_proto["@test template is bound to empty array of people"] = function (assert) {
var _this2 = this;
if (!_views.jQueryDisabled) {
(0, _internalTestHelpers.runTask)(function () {
return _this2.application.advanceReadiness();
});
window.visit('/').then(function () {
var rows = window.find('.name').length;
assert.equal(rows, 0, 'successfully stubbed an empty array of people');
});
} else {
(0, _internalTestHelpers.runTask)(function () {
return _this2.application.advanceReadiness();
});
window.visit('/').then(function () {
expectAssertion(function () {
return window.find('.name');
}, 'If jQuery is disabled, please import and use helpers from @ember/test-helpers [https://github.com/emberjs/ember-test-helpers]. Note: `find` is not an available helper.');
});
}
};
_proto["@test template is bound to array of 2 people"] = function (assert) {
var _this3 = this;
if (!_views.jQueryDisabled) {
this.modelContent = (0, _runtime.A)([]);
this.modelContent.pushObject({
firstName: 'x'
});
this.modelContent.pushObject({
firstName: 'y'
});
(0, _internalTestHelpers.runTask)(function () {
return _this3.application.advanceReadiness();
});
window.visit('/').then(function () {
var rows = window.find('.name').length;
assert.equal(rows, 2, 'successfully stubbed a non empty array of people');
});
} else {
assert.expect(0);
}
};
_proto["@test 'visit' can be called without advanceReadiness."] = function (assert) {
if (!_views.jQueryDisabled) {
window.visit('/').then(function () {
var rows = window.find('.name').length;
assert.equal(rows, 0, 'stubbed an empty array of people without calling advanceReadiness.');
});
} else {
assert.expect(0);
}
};
return _class;
}(_internalTestHelpers.AutobootApplicationTestCase));
});
enifed("ember-testing/tests/reexports_test", ["ember-babel", "ember", "internal-test-helpers"], function (_emberBabel, _ember, _internalTestHelpers) {
"use strict";
var ReexportsTestCase =
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(ReexportsTestCase, _AbstractTestCase);
function ReexportsTestCase() {
return _AbstractTestCase.apply(this, arguments) || this;
}
return ReexportsTestCase;
}(_internalTestHelpers.AbstractTestCase);
[// ember-testing
['Test', 'ember-testing'], ['Test.Adapter', 'ember-testing', 'Adapter'], ['Test.QUnitAdapter', 'ember-testing', 'QUnitAdapter'], ['setupForTesting', 'ember-testing']].forEach(function (reexport) {
var path = reexport[0],
moduleId = reexport[1],
exportName = reexport[2]; // default path === exportName if none present
if (!exportName) {
exportName = path;
}
ReexportsTestCase.prototype["@test Ember." + path + " exports correctly"] = function (assert) {
(0, _internalTestHelpers.confirmExport)(_ember.default, assert, path, moduleId, exportName);
};
});
(0, _internalTestHelpers.moduleFor)('ember-testing reexports', ReexportsTestCase);
});
enifed("ember-testing/tests/test/waiters-test", ["ember-babel", "ember-testing/lib/test/waiters", "internal-test-helpers"], function (_emberBabel, _waiters, _internalTestHelpers) {
"use strict";
var Waiters =
/*#__PURE__*/
function () {
function Waiters() {
this._waiters = [];
}
var _proto = Waiters.prototype;
_proto.add = function add() {
this._waiters.push(Array.prototype.slice.call(arguments));
};
_proto.register = function register() {
this.forEach(function () {
_waiters.registerWaiter.apply(void 0, arguments);
});
};
_proto.unregister = function unregister() {
this.forEach(function () {
_waiters.unregisterWaiter.apply(void 0, arguments);
});
};
_proto.forEach = function forEach(callback) {
for (var i = 0; i < this._waiters.length; i++) {
var args = this._waiters[i];
callback.apply(void 0, args);
}
};
_proto.check = function check() {
this.register();
var result = (0, _waiters.checkWaiters)();
this.unregister();
return result;
};
return Waiters;
}();
(0, _internalTestHelpers.moduleFor)('ember-testing: waiters',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
var _this;
_this = _AbstractTestCase.call(this) || this;
_this.waiters = new Waiters();
return _this;
}
var _proto2 = _class.prototype;
_proto2.teardown = function teardown() {
this.waiters.unregister();
};
_proto2['@test registering a waiter'] = function testRegisteringAWaiter(assert) {
assert.expect(2);
var obj = {
foo: true
};
this.waiters.add(obj, function () {
assert.ok(this.foo, 'has proper `this` context');
return true;
});
this.waiters.add(function () {
assert.ok(true, 'is called');
return true;
});
this.waiters.check();
};
_proto2['@test unregistering a waiter'] = function testUnregisteringAWaiter(assert) {
assert.expect(2);
var obj = {
foo: true
};
this.waiters.add(obj, function () {
assert.ok(true, 'precond - waiter with context is registered');
return true;
});
this.waiters.add(function () {
assert.ok(true, 'precond - waiter without context is registered');
return true;
});
this.waiters.check();
this.waiters.unregister();
(0, _waiters.checkWaiters)();
};
_proto2['@test checkWaiters returns false if all waiters return true'] = function testCheckWaitersReturnsFalseIfAllWaitersReturnTrue(assert) {
assert.expect(3);
this.waiters.add(function () {
assert.ok(true, 'precond - waiter is registered');
return true;
});
this.waiters.add(function () {
assert.ok(true, 'precond - waiter is registered');
return true;
});
assert.notOk(this.waiters.check(), 'checkWaiters returns true if all waiters return true');
};
_proto2['@test checkWaiters returns true if any waiters return false'] = function testCheckWaitersReturnsTrueIfAnyWaitersReturnFalse(assert) {
assert.expect(3);
this.waiters.add(function () {
assert.ok(true, 'precond - waiter is registered');
return true;
});
this.waiters.add(function () {
assert.ok(true, 'precond - waiter is registered');
return false;
});
assert.ok(this.waiters.check(), 'checkWaiters returns false if any waiters return false');
};
_proto2['@test checkWaiters short circuits after first falsey waiter'] = function testCheckWaitersShortCircuitsAfterFirstFalseyWaiter(assert) {
assert.expect(2);
this.waiters.add(function () {
assert.ok(true, 'precond - waiter is registered');
return false;
});
this.waiters.add(function () {
assert.notOk(true, 'waiter should not be called');
});
assert.ok(this.waiters.check(), 'checkWaiters returns false if any waiters return false');
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("ember/tests/application_lifecycle_test", ["ember-babel", "internal-test-helpers", "@ember/application", "@ember/-internals/routing", "@ember/-internals/glimmer", "@ember/debug"], function (_emberBabel, _internalTestHelpers, _application, _routing, _glimmer, _debug) {
"use strict";
var originalDebug = (0, _debug.getDebugFunction)('debug');
var noop = function () {};
(0, _internalTestHelpers.moduleFor)('Application Lifecycle - route hooks',
/*#__PURE__*/
function (_AutobootApplicationT) {
(0, _emberBabel.inheritsLoose)(_class, _AutobootApplicationT);
var _proto = _class.prototype;
_proto.createApplication = function createApplication() {
var application = _AutobootApplicationT.prototype.createApplication.apply(this, arguments);
this.add('router:main', _routing.Router.extend({
location: 'none'
}));
return application;
};
function _class() {
var _this;
(0, _debug.setDebugFunction)('debug', noop);
_this = _AutobootApplicationT.call(this) || this;
var menuItem = _this.menuItem = {};
(0, _internalTestHelpers.runTask)(function () {
_this.createApplication();
var SettingRoute = _routing.Route.extend({
setupController: function () {
this.controller.set('selectedMenuItem', menuItem);
},
deactivate: function () {
this.controller.set('selectedMenuItem', null);
}
});
_this.add('route:index', SettingRoute);
_this.add('route:application', SettingRoute);
});
return _this;
}
_proto.teardown = function teardown() {
(0, _debug.setDebugFunction)('debug', originalDebug);
};
_proto["@test Resetting the application allows controller properties to be set when a route deactivates"] = function (assert) {
var indexController = this.indexController,
applicationController = this.applicationController;
assert.equal(indexController.get('selectedMenuItem'), this.menuItem);
assert.equal(applicationController.get('selectedMenuItem'), this.menuItem);
this.application.reset();
assert.equal(indexController.get('selectedMenuItem'), null);
assert.equal(applicationController.get('selectedMenuItem'), null);
};
_proto["@test Destroying the application resets the router before the appInstance is destroyed"] = function (assert) {
var _this2 = this;
var indexController = this.indexController,
applicationController = this.applicationController;
assert.equal(indexController.get('selectedMenuItem'), this.menuItem);
assert.equal(applicationController.get('selectedMenuItem'), this.menuItem);
(0, _internalTestHelpers.runTask)(function () {
_this2.application.destroy();
});
assert.equal(indexController.get('selectedMenuItem'), null);
assert.equal(applicationController.get('selectedMenuItem'), null);
};
(0, _emberBabel.createClass)(_class, [{
key: "indexController",
get: function () {
return this.applicationInstance.lookup('controller:index');
}
}, {
key: "applicationController",
get: function () {
return this.applicationInstance.lookup('controller:application');
}
}]);
return _class;
}(_internalTestHelpers.AutobootApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Application Lifecycle',
/*#__PURE__*/
function (_AutobootApplicationT2) {
(0, _emberBabel.inheritsLoose)(_class2, _AutobootApplicationT2);
function _class2() {
return _AutobootApplicationT2.apply(this, arguments) || this;
}
var _proto2 = _class2.prototype;
_proto2.createApplication = function createApplication() {
var application = _AutobootApplicationT2.prototype.createApplication.apply(this, arguments);
this.add('router:main', _routing.Router.extend({
location: 'none'
}));
return application;
};
_proto2["@test Destroying a route after the router does create an undestroyed 'toplevelView'"] = function (assert) {
var _this3 = this;
(0, _internalTestHelpers.runTask)(function () {
_this3.createApplication();
_this3.addTemplate('index', "Index!");
_this3.addTemplate('application', "Application! {{outlet}}");
});
var router = this.applicationInstance.lookup('router:main');
var route = this.applicationInstance.lookup('route:index');
(0, _internalTestHelpers.runTask)(function () {
return router.destroy();
});
assert.equal(router._toplevelView, null, 'the toplevelView was cleared');
(0, _internalTestHelpers.runTask)(function () {
return route.destroy();
});
assert.equal(router._toplevelView, null, 'the toplevelView was not reinitialized');
(0, _internalTestHelpers.runTask)(function () {
return _this3.application.destroy();
});
assert.equal(router._toplevelView, null, 'the toplevelView was not reinitialized');
};
_proto2["@test initializers can augment an applications customEvents hash"] = function (assert) {
var _this4 = this;
assert.expect(1);
var MyApplication = _application.default.extend();
MyApplication.initializer({
name: 'customize-things',
initialize: function (application) {
application.customEvents = {
wowza: 'wowza'
};
}
});
(0, _internalTestHelpers.runTask)(function () {
_this4.createApplication({}, MyApplication);
_this4.add('component:foo-bar', _glimmer.Component.extend({
wowza: function () {
assert.ok(true, 'fired the event!');
}
}));
_this4.addTemplate('application', "{{foo-bar}}");
_this4.addTemplate('components/foo-bar', "");
});
this.$('#wowza-thingy').trigger('wowza');
};
_proto2["@test instanceInitializers can augment an the customEvents hash"] = function (assert) {
var _this5 = this;
assert.expect(1);
var MyApplication = _application.default.extend();
MyApplication.instanceInitializer({
name: 'customize-things',
initialize: function (application) {
application.customEvents = {
herky: 'jerky'
};
}
});
(0, _internalTestHelpers.runTask)(function () {
_this5.createApplication({}, MyApplication);
_this5.add('component:foo-bar', _glimmer.Component.extend({
jerky: function () {
assert.ok(true, 'fired the event!');
}
}));
_this5.addTemplate('application', "{{foo-bar}}");
_this5.addTemplate('components/foo-bar', "");
});
this.$('#herky-thingy').trigger('herky');
};
return _class2;
}(_internalTestHelpers.AutobootApplicationTestCase));
});
enifed("ember/tests/component_context_test", ["ember-babel", "@ember/controller", "@ember/-internals/glimmer", "internal-test-helpers"], function (_emberBabel, _controller, _glimmer, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Application Lifecycle - Component Context',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Components with a block should have the proper content when a template is provided'] = function testComponentsWithABlockShouldHaveTheProperContentWhenATemplateIsProvided(assert) {
var _this = this;
this.addTemplate('application', "\n
\n {{#my-component}}{{text}}{{/my-component}}\n
\n ");
this.add('controller:application', _controller.default.extend({
text: 'outer'
}));
this.addComponent('my-component', {
ComponentClass: _glimmer.Component.extend({
text: 'inner'
}),
template: "{{text}}-{{yield}}"
});
return this.visit('/').then(function () {
var text = (0, _internalTestHelpers.getTextOf)(_this.element.querySelector('#wrapper'));
assert.equal(text, 'inner-outer', 'The component is composed correctly');
});
};
_proto['@test Components with a block should yield the proper content without a template provided'] = function testComponentsWithABlockShouldYieldTheProperContentWithoutATemplateProvided(assert) {
var _this2 = this;
this.addTemplate('application', "\n
\n {{#my-component}}{{text}}{{/my-component}}\n
\n ");
this.add('controller:application', _controller.default.extend({
text: 'outer'
}));
this.addComponent('my-component', {
ComponentClass: _glimmer.Component.extend({
text: 'inner'
})
});
return this.visit('/').then(function () {
var text = (0, _internalTestHelpers.getTextOf)(_this2.element.querySelector('#wrapper'));
assert.equal(text, 'outer', 'The component is composed correctly');
});
};
_proto['@test Components without a block should have the proper content when a template is provided'] = function testComponentsWithoutABlockShouldHaveTheProperContentWhenATemplateIsProvided(assert) {
var _this3 = this;
this.addTemplate('application', "\n
{{my-component}}
\n ");
this.add('controller:application', _controller.default.extend({
text: 'outer'
}));
this.addComponent('my-component', {
ComponentClass: _glimmer.Component.extend({
text: 'inner'
}),
template: '{{text}}'
});
return this.visit('/').then(function () {
var text = (0, _internalTestHelpers.getTextOf)(_this3.element.querySelector('#wrapper'));
assert.equal(text, 'inner', 'The component is composed correctly');
});
};
_proto['@test Components without a block should have the proper content'] = function testComponentsWithoutABlockShouldHaveTheProperContent(assert) {
var _this4 = this;
this.addTemplate('application', "\n
{{my-component}}
\n ");
this.add('controller:application', _controller.default.extend({
text: 'outer'
}));
this.addComponent('my-component', {
ComponentClass: _glimmer.Component.extend({
didInsertElement: function () {
this.element.innerHTML = 'Some text inserted';
}
})
});
return this.visit('/').then(function () {
var text = (0, _internalTestHelpers.getTextOf)(_this4.element.querySelector('#wrapper'));
assert.equal(text, 'Some text inserted', 'The component is composed correctly');
});
};
_proto['@test properties of a component without a template should not collide with internal structures [DEPRECATED]'] = function testPropertiesOfAComponentWithoutATemplateShouldNotCollideWithInternalStructuresDEPRECATED(assert) {
var _this5 = this;
this.addTemplate('application', "\n
{{my-component data=foo}}
");
this.add('controller:application', _controller.default.extend({
text: 'outer',
foo: 'Some text inserted'
}));
this.addComponent('my-component', {
ComponentClass: _glimmer.Component.extend({
didInsertElement: function () {
this.element.innerHTML = this.get('data');
}
})
});
return this.visit('/').then(function () {
var text = (0, _internalTestHelpers.getTextOf)(_this5.element.querySelector('#wrapper'));
assert.equal(text, 'Some text inserted', 'The component is composed correctly');
});
};
_proto['@test attrs property of a component without a template should not collide with internal structures'] = function testAttrsPropertyOfAComponentWithoutATemplateShouldNotCollideWithInternalStructures(assert) {
var _this6 = this;
this.addTemplate('application', "\n
{{my-component attrs=foo}}
\n ");
this.add('controller:application', _controller.default.extend({
text: 'outer',
foo: 'Some text inserted'
}));
this.addComponent('my-component', {
ComponentClass: _glimmer.Component.extend({
didInsertElement: function () {
this.element.innerHTML = this.get('attrs.attrs.value');
}
})
});
return this.visit('/').then(function () {
var text = (0, _internalTestHelpers.getTextOf)(_this6.element.querySelector('#wrapper'));
assert.equal(text, 'Some text inserted', 'The component is composed correctly');
});
};
_proto['@test Components trigger actions in the parents context when called from within a block'] = function testComponentsTriggerActionsInTheParentsContextWhenCalledFromWithinABlock(assert) {
var _this7 = this;
this.addTemplate('application', "\n
\n ");
this.add('controller:application', _controller.default.extend({
actions: {
fizzbuzz: function () {
assert.ok(true, 'action triggered on parent');
}
}
}));
this.addComponent('my-component', {
ComponentClass: _glimmer.Component.extend({})
});
return this.visit('/').then(function () {
_this7.$('#fizzbuzz', '#wrapper').click();
});
};
_proto['@test Components trigger actions in the components context when called from within its template'] = function testComponentsTriggerActionsInTheComponentsContextWhenCalledFromWithinItsTemplate(assert) {
var _this8 = this;
this.addTemplate('application', "\n
{{#my-component}}{{text}}{{/my-component}}
\n ");
this.add('controller:application', _controller.default.extend({
actions: {
fizzbuzz: function () {
assert.ok(false, 'action on the wrong context');
}
}
}));
this.addComponent('my-component', {
ComponentClass: _glimmer.Component.extend({
actions: {
fizzbuzz: function () {
assert.ok(true, 'action triggered on component');
}
}
}),
template: "Fizzbuzz"
});
return this.visit('/').then(function () {
_this8.$('#fizzbuzz', '#wrapper').click();
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("ember/tests/component_registration_test", ["ember-babel", "@ember/application", "@ember/controller", "@ember/-internals/glimmer", "ember-template-compiler", "internal-test-helpers", "@ember/-internals/environment"], function (_emberBabel, _application, _controller, _glimmer, _emberTemplateCompiler, _internalTestHelpers, _environment) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Application Lifecycle - Component Registration',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype; // This is necessary for this.application.instanceInitializer to not leak between tests
_proto.createApplication = function createApplication(options) {
return _ApplicationTestCase.prototype.createApplication.call(this, options, _application.default.extend());
};
_proto['@test The helper becomes the body of the component'] = function testTheHelperBecomesTheBodyOfTheComponent() {
var _this = this;
this.addTemplate('components/expand-it', '
hello {{yield}}
');
this.addTemplate('application', 'Hello world {{#expand-it}}world{{/expand-it}}');
return this.visit('/').then(function () {
_this.assertText('Hello world hello world');
_this.assertComponentElement(_this.element.firstElementChild, {
tagName: 'div',
content: '
hello world
'
});
});
};
_proto['@test The helper becomes the body of the component (ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS = true;)'] = function testTheHelperBecomesTheBodyOfTheComponentENV_TEMPLATE_ONLY_GLIMMER_COMPONENTSTrue() {
var _this2 = this;
_environment.ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS = true;
this.addTemplate('components/expand-it', '
hello {{yield}}
');
this.addTemplate('application', 'Hello world {{#expand-it}}world{{/expand-it}}');
return this.visit('/').then(function () {
_this2.assertInnerHTML('Hello world
hello world
');
_environment.ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS = false;
});
};
_proto['@test If a component is registered, it is used'] = function testIfAComponentIsRegisteredItIsUsed(assert) {
var _this3 = this;
this.addTemplate('components/expand-it', '
hello {{yield}}
');
this.addTemplate('application', "Hello world {{#expand-it}}world{{/expand-it}}");
this.application.instanceInitializer({
name: 'expand-it-component',
initialize: function (applicationInstance) {
applicationInstance.register('component:expand-it', _glimmer.Component.extend({
classNames: 'testing123'
}));
}
});
return this.visit('/').then(function () {
var text = _this3.$('div.testing123').text().trim();
assert.equal(text, 'hello world', 'The component is composed correctly');
});
};
_proto['@test Late-registered components can be rendered with custom `layout` property'] = function testLateRegisteredComponentsCanBeRenderedWithCustomLayoutProperty(assert) {
var _this4 = this;
this.addTemplate('application', "
there goes {{my-hero}}
");
this.application.instanceInitializer({
name: 'my-hero-component',
initialize: function (applicationInstance) {
applicationInstance.register('component:my-hero', _glimmer.Component.extend({
classNames: 'testing123',
layout: (0, _emberTemplateCompiler.compile)('watch him as he GOES')
}));
}
});
return this.visit('/').then(function () {
var text = _this4.$('#wrapper').text().trim();
assert.equal(text, 'there goes watch him as he GOES', 'The component is composed correctly');
});
};
_proto['@test Late-registered components can be rendered with template registered on the container'] = function testLateRegisteredComponentsCanBeRenderedWithTemplateRegisteredOnTheContainer(assert) {
var _this5 = this;
this.addTemplate('application', "
hello world {{sally-rutherford}}-{{#sally-rutherford}}!!!{{/sally-rutherford}}
");
this.application.instanceInitializer({
name: 'sally-rutherford-component-template',
initialize: function (applicationInstance) {
applicationInstance.register('template:components/sally-rutherford', (0, _emberTemplateCompiler.compile)('funkytowny{{yield}}'));
}
});
this.application.instanceInitializer({
name: 'sally-rutherford-component',
initialize: function (applicationInstance) {
applicationInstance.register('component:sally-rutherford', _glimmer.Component);
}
});
return this.visit('/').then(function () {
var text = _this5.$('#wrapper').text().trim();
assert.equal(text, 'hello world funkytowny-funkytowny!!!', 'The component is composed correctly');
});
};
_proto['@test Late-registered components can be rendered with ONLY the template registered on the container'] = function testLateRegisteredComponentsCanBeRenderedWithONLYTheTemplateRegisteredOnTheContainer(assert) {
var _this6 = this;
this.addTemplate('application', "
hello world {{borf-snorlax}}-{{#borf-snorlax}}!!!{{/borf-snorlax}}
");
this.application.instanceInitializer({
name: 'borf-snorlax-component-template',
initialize: function (applicationInstance) {
applicationInstance.register('template:components/borf-snorlax', (0, _emberTemplateCompiler.compile)('goodfreakingTIMES{{yield}}'));
}
});
return this.visit('/').then(function () {
var text = _this6.$('#wrapper').text().trim();
assert.equal(text, 'hello world goodfreakingTIMES-goodfreakingTIMES!!!', 'The component is composed correctly');
});
};
_proto['@test Assigning layoutName to a component should setup the template as a layout'] = function testAssigningLayoutNameToAComponentShouldSetupTheTemplateAsALayout(assert) {
var _this7 = this;
assert.expect(1);
this.addTemplate('application', "
{{#my-component}}{{text}}{{/my-component}}
");
this.addTemplate('foo-bar-baz', '{{text}}-{{yield}}');
this.application.instanceInitializer({
name: 'application-controller',
initialize: function (applicationInstance) {
applicationInstance.register('controller:application', _controller.default.extend({
text: 'outer'
}));
}
});
this.application.instanceInitializer({
name: 'my-component-component',
initialize: function (applicationInstance) {
applicationInstance.register('component:my-component', _glimmer.Component.extend({
text: 'inner',
layoutName: 'foo-bar-baz'
}));
}
});
return this.visit('/').then(function () {
var text = _this7.$('#wrapper').text().trim();
assert.equal(text, 'inner-outer', 'The component is composed correctly');
});
};
_proto['@test Assigning layoutName and layout to a component should use the `layout` value'] = function testAssigningLayoutNameAndLayoutToAComponentShouldUseTheLayoutValue(assert) {
var _this8 = this;
assert.expect(1);
this.addTemplate('application', "
{{#my-component}}{{text}}{{/my-component}}
");
this.addTemplate('foo-bar-baz', 'No way!');
this.application.instanceInitializer({
name: 'application-controller-layout',
initialize: function (applicationInstance) {
applicationInstance.register('controller:application', _controller.default.extend({
text: 'outer'
}));
}
});
this.application.instanceInitializer({
name: 'my-component-component-layout',
initialize: function (applicationInstance) {
applicationInstance.register('component:my-component', _glimmer.Component.extend({
text: 'inner',
layoutName: 'foo-bar-baz',
layout: (0, _emberTemplateCompiler.compile)('{{text}}-{{yield}}')
}));
}
});
return this.visit('/').then(function () {
var text = _this8.$('#wrapper').text().trim();
assert.equal(text, 'inner-outer', 'The component is composed correctly');
});
};
_proto['@test Using name of component that does not exist'] = function testUsingNameOfComponentThatDoesNotExist() {
var _this9 = this;
this.addTemplate('application', "
{{#no-good}} {{/no-good}}
"); // TODO: Use the async form of expectAssertion here when it is available
expectAssertion(function () {
_this9.visit('/');
}, /.* named "no-good" .*/);
return (0, _internalTestHelpers.runLoopSettled)();
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("ember/tests/controller_test", ["ember-babel", "@ember/controller", "internal-test-helpers", "@ember/-internals/glimmer"], function (_emberBabel, _controller, _internalTestHelpers, _glimmer) {
"use strict";
/*
In Ember 1.x, controllers subtly affect things like template scope
and action targets in exciting and often inscrutable ways. This test
file contains integration tests that verify the correct behavior of
the many parts of the system that change and rely upon controller scope,
from the runtime up to the templating layer.
*/
(0, _internalTestHelpers.moduleFor)('Template scoping examples',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Actions inside an outlet go to the associated controller'] = function testActionsInsideAnOutletGoToTheAssociatedController(assert) {
var _this = this;
this.add('controller:index', _controller.default.extend({
actions: {
componentAction: function () {
assert.ok(true, 'controller received the action');
}
}
}));
this.addComponent('component-with-action', {
ComponentClass: _glimmer.Component.extend({
classNames: ['component-with-action'],
click: function () {
this.action();
}
})
});
this.addTemplate('index', '{{component-with-action action=(action "componentAction")}}');
return this.visit('/').then(function () {
(0, _internalTestHelpers.runTask)(function () {
return _this.$('.component-with-action').click();
});
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("ember/tests/error_handler_test", ["ember-babel", "@ember/debug", "@ember/runloop", "@ember/-internals/error-handling", "rsvp", "internal-test-helpers"], function (_emberBabel, _debug, _runloop, _errorHandling, _rsvp, _internalTestHelpers) {
"use strict";
var WINDOW_ONERROR;
function runThatThrowsSync() {
var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Error for testing error handling';
return (0, _runloop.run)(function () {
throw new Error(message);
});
}
(0, _internalTestHelpers.moduleFor)('error_handler',
/*#__PURE__*/
function (_AbstractTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _AbstractTestCase);
function _class() {
return _AbstractTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
// capturing this outside of module scope to ensure we grab
// the test frameworks own window.onerror to reset it
WINDOW_ONERROR = window.onerror;
};
_proto.afterEach = function afterEach() {
(0, _debug.setTesting)(_debug.isTesting);
window.onerror = WINDOW_ONERROR;
(0, _errorHandling.setOnerror)(undefined);
};
_proto['@test by default there is no onerror - sync run'] = function testByDefaultThereIsNoOnerrorSyncRun(assert) {
assert.strictEqual((0, _errorHandling.getOnerror)(), undefined, 'precond - there should be no Ember.onerror set by default');
assert.throws(runThatThrowsSync, Error, 'errors thrown sync are catchable');
};
_proto['@test when Ember.onerror (which rethrows) is registered - sync run'] = function testWhenEmberOnerrorWhichRethrowsIsRegisteredSyncRun(assert) {
assert.expect(2);
(0, _errorHandling.setOnerror)(function (error) {
assert.ok(true, 'onerror called');
throw error;
});
assert.throws(runThatThrowsSync, Error, 'error is thrown');
};
_proto['@test when Ember.onerror (which does not rethrow) is registered - sync run'] = function testWhenEmberOnerrorWhichDoesNotRethrowIsRegisteredSyncRun(assert) {
assert.expect(2);
(0, _errorHandling.setOnerror)(function () {
assert.ok(true, 'onerror called');
});
runThatThrowsSync();
assert.ok(true, 'no error was thrown, Ember.onerror can intercept errors');
};
_proto['@test does not swallow exceptions by default (Ember.testing = true, no Ember.onerror) - sync run'] = function testDoesNotSwallowExceptionsByDefaultEmberTestingTrueNoEmberOnerrorSyncRun(assert) {
(0, _debug.setTesting)(true);
var error = new Error('the error');
assert.throws(function () {
(0, _runloop.run)(function () {
throw error;
});
}, error);
};
_proto['@test does not swallow exceptions by default (Ember.testing = false, no Ember.onerror) - sync run'] = function testDoesNotSwallowExceptionsByDefaultEmberTestingFalseNoEmberOnerrorSyncRun(assert) {
(0, _debug.setTesting)(false);
var error = new Error('the error');
assert.throws(function () {
(0, _runloop.run)(function () {
throw error;
});
}, error);
};
_proto['@test does not swallow exceptions (Ember.testing = false, Ember.onerror which rethrows) - sync run'] = function testDoesNotSwallowExceptionsEmberTestingFalseEmberOnerrorWhichRethrowsSyncRun(assert) {
assert.expect(2);
(0, _debug.setTesting)(false);
(0, _errorHandling.setOnerror)(function (error) {
assert.ok(true, 'Ember.onerror was called');
throw error;
});
var error = new Error('the error');
assert.throws(function () {
(0, _runloop.run)(function () {
throw error;
});
}, error);
};
_proto['@test Ember.onerror can intercept errors (aka swallow) by not rethrowing (Ember.testing = false) - sync run'] = function testEmberOnerrorCanInterceptErrorsAkaSwallowByNotRethrowingEmberTestingFalseSyncRun(assert) {
assert.expect(1);
(0, _debug.setTesting)(false);
(0, _errorHandling.setOnerror)(function () {
assert.ok(true, 'Ember.onerror was called');
});
var error = new Error('the error');
try {
(0, _runloop.run)(function () {
throw error;
});
} catch (e) {
assert.notOk(true, 'Ember.onerror that does not rethrow is intentionally swallowing errors, try / catch wrapping does not see error');
}
};
_proto['@test does not swallow exceptions by default (Ember.testing = true, no Ember.onerror) - async run'] = function testDoesNotSwallowExceptionsByDefaultEmberTestingTrueNoEmberOnerrorAsyncRun(assert) {
var done = assert.async();
var caughtByWindowOnerror;
(0, _debug.setTesting)(true);
window.onerror = function (message) {
caughtByWindowOnerror = message; // prevent "bubbling" and therefore failing the test
return true;
};
(0, _runloop.later)(function () {
throw new Error('the error');
}, 10);
setTimeout(function () {
assert.pushResult({
result: /the error/.test(caughtByWindowOnerror),
actual: caughtByWindowOnerror,
expected: 'to include `the error`',
message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)'
});
done();
}, 20);
};
_proto['@test does not swallow exceptions by default (Ember.testing = false, no Ember.onerror) - async run'] = function testDoesNotSwallowExceptionsByDefaultEmberTestingFalseNoEmberOnerrorAsyncRun(assert) {
var done = assert.async();
var caughtByWindowOnerror;
(0, _debug.setTesting)(false);
window.onerror = function (message) {
caughtByWindowOnerror = message; // prevent "bubbling" and therefore failing the test
return true;
};
(0, _runloop.later)(function () {
throw new Error('the error');
}, 10);
setTimeout(function () {
assert.pushResult({
result: /the error/.test(caughtByWindowOnerror),
actual: caughtByWindowOnerror,
expected: 'to include `the error`',
message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)'
});
done();
}, 20);
};
_proto['@test Ember.onerror can intercept errors (aka swallow) by not rethrowing (Ember.testing = false) - async run'] = function testEmberOnerrorCanInterceptErrorsAkaSwallowByNotRethrowingEmberTestingFalseAsyncRun(assert) {
var done = assert.async();
(0, _debug.setTesting)(false);
window.onerror = function () {
assert.notOk(true, 'window.onerror is never invoked when Ember.onerror intentionally swallows errors'); // prevent "bubbling" and therefore failing the test
return true;
};
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called with the error');
});
(0, _runloop.later)(function () {
throw thrown;
}, 10);
setTimeout(done, 20);
};
_proto["@test errors in promise constructor when Ember.onerror which does not rethrow is present - rsvp"] = function (assert) {
assert.expect(1);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
});
new _rsvp.default.Promise(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
});
};
_proto["@test errors in promise constructor when Ember.onerror which does rethrow is present - rsvp"] = function (assert) {
assert.expect(2);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
throw error;
});
window.onerror = function (message) {
assert.pushResult({
result: /the error/.test(message),
actual: message,
expected: 'to include `the error`',
message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)'
}); // prevent "bubbling" and therefore failing the test
return true;
};
new _rsvp.default.Promise(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
});
};
_proto["@test errors in promise constructor when Ember.onerror which does not rethrow is present (Ember.testing = false) - rsvp"] = function (assert) {
assert.expect(1);
(0, _debug.setTesting)(false);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
});
new _rsvp.default.Promise(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
});
};
_proto["@test errors in promise constructor when Ember.onerror which does rethrow is present (Ember.testing = false) - rsvp"] = function (assert) {
assert.expect(2);
(0, _debug.setTesting)(false);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
throw error;
});
window.onerror = function (message) {
assert.pushResult({
result: /the error/.test(message),
actual: message,
expected: 'to include `the error`',
message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)'
}); // prevent "bubbling" and therefore failing the test
return true;
};
new _rsvp.default.Promise(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
});
};
_proto["@test errors in promise .then callback when Ember.onerror which does not rethrow is present - rsvp"] = function (assert) {
assert.expect(1);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
});
_rsvp.default.resolve().then(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
});
};
_proto["@test errors in promise .then callback when Ember.onerror which does rethrow is present - rsvp"] = function (assert) {
assert.expect(2);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
throw error;
});
window.onerror = function (message) {
assert.pushResult({
result: /the error/.test(message),
actual: message,
expected: 'to include `the error`',
message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)'
}); // prevent "bubbling" and therefore failing the test
return true;
};
_rsvp.default.resolve().then(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
});
};
_proto["@test errors in promise .then callback when Ember.onerror which does not rethrow is present (Ember.testing = false) - rsvp"] = function (assert) {
assert.expect(1);
(0, _debug.setTesting)(false);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
});
_rsvp.default.resolve().then(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
});
};
_proto["@test errors in promise .then callback when Ember.onerror which does rethrow is present (Ember.testing = false) - rsvp"] = function (assert) {
assert.expect(2);
(0, _debug.setTesting)(false);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
throw error;
});
window.onerror = function (message) {
assert.pushResult({
result: /the error/.test(message),
actual: message,
expected: 'to include `the error`',
message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)'
}); // prevent "bubbling" and therefore failing the test
return true;
};
_rsvp.default.resolve().then(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
});
};
_proto["@test errors in async promise .then callback when Ember.onerror which does not rethrow is present - rsvp"] = function (assert) {
assert.expect(1);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
});
new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
}).then(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 20);
});
};
_proto["@test errors in async promise .then callback when Ember.onerror which does rethrow is present - rsvp"] = function (assert) {
assert.expect(2);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
throw error;
});
window.onerror = function (message) {
assert.pushResult({
result: /the error/.test(message),
actual: message,
expected: 'to include `the error`',
message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)'
}); // prevent "bubbling" and therefore failing the test
return true;
};
new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
}).then(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 20);
});
};
_proto["@test errors in async promise .then callback when Ember.onerror which does not rethrow is present (Ember.testing = false) - rsvp"] = function (assert) {
assert.expect(1);
(0, _debug.setTesting)(false);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
});
new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
}).then(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 20);
});
};
_proto["@test errors in async promise .then callback when Ember.onerror which does rethrow is present (Ember.testing = false) - rsvp"] = function (assert) {
assert.expect(2);
(0, _debug.setTesting)(false);
var thrown = new Error('the error');
(0, _errorHandling.setOnerror)(function (error) {
assert.strictEqual(error, thrown, 'Ember.onerror is called for errors thrown in RSVP promises');
throw error;
});
window.onerror = function (message) {
assert.pushResult({
result: /the error/.test(message),
actual: message,
expected: 'to include `the error`',
message: 'error should bubble out to window.onerror, and therefore fail tests (due to QUnit implementing window.onerror)'
}); // prevent "bubbling" and therefore failing the test
return true;
};
new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 10);
}).then(function () {
throw thrown;
}); // RSVP.Promise's are configured to settle within the run loop, this
// ensures that run loop has completed
return new _rsvp.default.Promise(function (resolve) {
return setTimeout(resolve, 20);
});
};
return _class;
}(_internalTestHelpers.AbstractTestCase));
});
enifed("ember/tests/helpers/helper_registration_test", ["ember-babel", "internal-test-helpers", "@ember/controller", "@ember/service", "@ember/-internals/glimmer"], function (_emberBabel, _internalTestHelpers, _controller, _service, _glimmer) {
"use strict";
(0, _internalTestHelpers.moduleFor)('Application Lifecycle - Helper Registration',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Unbound dashed helpers registered on the container can be late-invoked'] = function testUnboundDashedHelpersRegisteredOnTheContainerCanBeLateInvoked(assert) {
var _this = this;
this.addTemplate('application', "
{{x-borf}} {{x-borf 'YES'}}
");
var myHelper = (0, _glimmer.helper)(function (params) {
return params[0] || 'BORF';
});
this.application.register('helper:x-borf', myHelper);
return this.visit('/').then(function () {
assert.equal(_this.$('#wrapper').text(), 'BORF YES', 'The helper was invoked from the container');
});
};
_proto['@test Bound helpers registered on the container can be late-invoked'] = function testBoundHelpersRegisteredOnTheContainerCanBeLateInvoked(assert) {
var _this2 = this;
this.addTemplate('application', "
{{x-reverse}} {{x-reverse foo}}
");
this.add('controller:application', _controller.default.extend({
foo: 'alex'
}));
this.application.register('helper:x-reverse', (0, _glimmer.helper)(function (_ref) {
var value = _ref[0];
return value ? value.split('').reverse().join('') : '--';
}));
return this.visit('/').then(function () {
assert.equal(_this2.$('#wrapper').text(), '-- xela', 'The bound helper was invoked from the container');
});
};
_proto['@test Undashed helpers registered on the container can be invoked'] = function testUndashedHelpersRegisteredOnTheContainerCanBeInvoked(assert) {
var _this3 = this;
this.addTemplate('application', "
{{omg}}|{{yorp 'boo'}}|{{yorp 'ya'}}
");
this.application.register('helper:omg', (0, _glimmer.helper)(function () {
return 'OMG';
}));
this.application.register('helper:yorp', (0, _glimmer.helper)(function (_ref2) {
var value = _ref2[0];
return value;
}));
return this.visit('/').then(function () {
assert.equal(_this3.$('#wrapper').text(), 'OMG|boo|ya', 'The helper was invoked from the container');
});
};
_proto['@test Helpers can receive injections'] = function testHelpersCanReceiveInjections(assert) {
this.addTemplate('application', "
{{full-name}}
");
var serviceCalled = false;
this.add('service:name-builder', _service.default.extend({
build: function () {
serviceCalled = true;
}
}));
this.add('helper:full-name', _glimmer.Helper.extend({
nameBuilder: (0, _service.inject)('name-builder'),
compute: function () {
this.get('nameBuilder').build();
}
}));
return this.visit('/').then(function () {
assert.ok(serviceCalled, 'service was injected, method called');
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("ember/tests/helpers/link_to_test", ["ember-babel", "internal-test-helpers", "@ember/controller", "@ember/-internals/runtime", "@ember/-internals/metal", "@ember/instrumentation", "@ember/-internals/routing"], function (_emberBabel, _internalTestHelpers, _controller, _runtime, _metal, _instrumentation, _routing) {
"use strict";
// IE includes the host name
function normalizeUrl(url) {
return url.replace(/https?:\/\/[^\/]+/, '');
}
function shouldNotBeActive(assert, element) {
checkActive(assert, element, false);
}
function shouldBeActive(assert, element) {
checkActive(assert, element, true);
}
function checkActive(assert, element, active) {
var classList = element.attr('class');
assert.equal(classList.indexOf('active') > -1, active, element + " active should be " + active);
}
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper - basic tests',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
var _this;
_this = _ApplicationTestCase.call(this) || this;
_this.router.map(function () {
this.route('about');
});
_this.addTemplate('index', "\n
\n {{#link-to 'index' id='home-link'}}Home{{/link-to}}\n {{#link-to 'about' id='self-link'}}Self{{/link-to}}\n ");
return _this;
}
var _proto = _class.prototype;
_proto['@test The {{link-to}} helper moves into the named route'] = function testTheLinkToHelperMovesIntoTheNamedRoute(assert) {
var _this2 = this;
return this.visit('/').then(function () {
assert.equal(_this2.$('h3.home').length, 1, 'The home template was rendered');
assert.equal(_this2.$('#self-link.active').length, 1, 'The self-link was rendered with active class');
assert.equal(_this2.$('#about-link:not(.active)').length, 1, 'The other link was rendered without active class');
return _this2.click('#about-link');
}).then(function () {
assert.equal(_this2.$('h3.about').length, 1, 'The about template was rendered');
assert.equal(_this2.$('#self-link.active').length, 1, 'The self-link was rendered with active class');
assert.equal(_this2.$('#home-link:not(.active)').length, 1, 'The other link was rendered without active class');
});
};
_proto["@test the {{link-to}} helper doesn't add an href when the tagName isn't 'a'"] = function (assert) {
var _this3 = this;
this.addTemplate('index', "\n {{#link-to 'about' id='about-link' tagName='div'}}About{{/link-to}}\n ");
return this.visit('/').then(function () {
assert.equal(_this3.$('#about-link').attr('href'), undefined, 'there is no href attribute');
});
};
_proto["@test the {{link-to}} applies a 'disabled' class when disabled"] = function (assert) {
var _this4 = this;
this.addTemplate('index', "\n {{#link-to \"about\" id=\"about-link-static\" disabledWhen=\"shouldDisable\"}}About{{/link-to}}\n {{#link-to \"about\" id=\"about-link-dynamic\" disabledWhen=dynamicDisabledWhen}}About{{/link-to}}\n ");
this.add('controller:index', _controller.default.extend({
shouldDisable: true,
dynamicDisabledWhen: 'shouldDisable'
}));
return this.visit('/').then(function () {
assert.equal(_this4.$('#about-link-static.disabled').length, 1, 'The static link is disabled when its disabledWhen is true');
assert.equal(_this4.$('#about-link-dynamic.disabled').length, 1, 'The dynamic link is disabled when its disabledWhen is true');
var controller = _this4.applicationInstance.lookup('controller:index');
(0, _internalTestHelpers.runTask)(function () {
return controller.set('dynamicDisabledWhen', false);
});
assert.equal(_this4.$('#about-link-dynamic.disabled').length, 0, 'The dynamic link is re-enabled when its disabledWhen becomes false');
});
};
_proto["@test the {{link-to}} doesn't apply a 'disabled' class if disabledWhen is not provided"] = function (assert) {
var _this5 = this;
this.addTemplate('index', "{{#link-to \"about\" id=\"about-link\"}}About{{/link-to}}");
return this.visit('/').then(function () {
assert.ok(!_this5.$('#about-link').hasClass('disabled'), 'The link is not disabled if disabledWhen not provided');
});
};
_proto["@test the {{link-to}} helper supports a custom disabledClass"] = function (assert) {
var _this6 = this;
this.addTemplate('index', "\n {{#link-to \"about\" id=\"about-link\" disabledWhen=true disabledClass=\"do-not-want\"}}About{{/link-to}}\n ");
return this.visit('/').then(function () {
assert.equal(_this6.$('#about-link.do-not-want').length, 1, 'The link can apply a custom disabled class');
});
};
_proto["@test the {{link-to}} helper supports a custom disabledClass set via bound param"] = function (assert) {
var _this7 = this;
this.addTemplate('index', "\n {{#link-to \"about\" id=\"about-link\" disabledWhen=true disabledClass=disabledClass}}About{{/link-to}}\n ");
this.add('controller:index', _controller.default.extend({
disabledClass: 'do-not-want'
}));
return this.visit('/').then(function () {
assert.equal(_this7.$('#about-link.do-not-want').length, 1, 'The link can apply a custom disabled class via bound param');
});
};
_proto["@test the {{link-to}} helper does not respond to clicks when disabledWhen"] = function (assert) {
var _this8 = this;
this.addTemplate('index', "\n {{#link-to \"about\" id=\"about-link\" disabledWhen=true}}About{{/link-to}}\n ");
return this.visit('/').then(function () {
return _this8.click('#about-link');
}).then(function () {
assert.equal(_this8.$('h3.about').length, 0, 'Transitioning did not occur');
});
};
_proto["@test the {{link-to}} helper does not respond to clicks when disabled"] = function (assert) {
var _this9 = this;
this.addTemplate('index', "\n {{#link-to \"about\" id=\"about-link\" disabled=true}}About{{/link-to}}\n ");
return this.visit('/').then(function () {
return _this9.click('#about-link');
}).then(function () {
assert.equal(_this9.$('h3.about').length, 0, 'Transitioning did not occur');
});
};
_proto["@test the {{link-to}} helper responds to clicks according to its disabledWhen bound param"] = function (assert) {
var _this10 = this;
this.addTemplate('index', "\n {{#link-to \"about\" id=\"about-link\" disabledWhen=disabledWhen}}About{{/link-to}}\n ");
this.add('controller:index', _controller.default.extend({
disabledWhen: true
}));
return this.visit('/').then(function () {
return _this10.click('#about-link');
}).then(function () {
assert.equal(_this10.$('h3.about').length, 0, 'Transitioning did not occur');
var controller = _this10.applicationInstance.lookup('controller:index');
controller.set('disabledWhen', false);
return (0, _internalTestHelpers.runLoopSettled)();
}).then(function () {
return _this10.click('#about-link');
}).then(function () {
assert.equal(_this10.$('h3.about').length, 1, 'Transitioning did occur when disabledWhen became false');
});
};
_proto["@test The {{link-to}} helper supports a custom activeClass"] = function (assert) {
var _this11 = this;
this.addTemplate('index', "\n
Home
\n {{#link-to 'about' id='about-link'}}About{{/link-to}}\n {{#link-to 'index' id='self-link' activeClass='zomg-active'}}Self{{/link-to}}\n ");
return this.visit('/').then(function () {
assert.equal(_this11.$('h3.home').length, 1, 'The home template was rendered');
assert.equal(_this11.$('#self-link.zomg-active').length, 1, 'The self-link was rendered with active class');
assert.equal(_this11.$('#about-link:not(.active)').length, 1, 'The other link was rendered without active class');
});
};
_proto["@test The {{link-to}} helper supports a custom activeClass from a bound param"] = function (assert) {
var _this12 = this;
this.addTemplate('index', "\n
Home
\n {{#link-to 'about' id='about-link'}}About{{/link-to}}\n {{#link-to 'index' id='self-link' activeClass=activeClass}}Self{{/link-to}}\n ");
this.add('controller:index', _controller.default.extend({
activeClass: 'zomg-active'
}));
return this.visit('/').then(function () {
assert.equal(_this12.$('h3.home').length, 1, 'The home template was rendered');
assert.equal(_this12.$('#self-link.zomg-active').length, 1, 'The self-link was rendered with active class');
assert.equal(_this12.$('#about-link:not(.active)').length, 1, 'The other link was rendered without active class');
});
};
_proto["@test The {{link-to}} helper supports 'classNameBindings' with custom values [GH #11699]"] = function (assert) {
var _this13 = this;
this.addTemplate('index', "\n
Home
\n {{#link-to 'about' id='about-link' classNameBindings='foo:foo-is-true:foo-is-false'}}About{{/link-to}}\n ");
this.add('controller:index', _controller.default.extend({
foo: false
}));
return this.visit('/').then(function () {
assert.equal(_this13.$('#about-link.foo-is-false').length, 1, 'The about-link was rendered with the falsy class');
var controller = _this13.applicationInstance.lookup('controller:index');
(0, _internalTestHelpers.runTask)(function () {
return controller.set('foo', true);
});
assert.equal(_this13.$('#about-link.foo-is-true').length, 1, 'The about-link was rendered with the truthy class after toggling the property');
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper - location hooks',
/*#__PURE__*/
function (_ApplicationTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _ApplicationTestCase2);
function _class2() {
var _this14;
_this14 = _ApplicationTestCase2.call(this) || this;
_this14.updateCount = 0;
_this14.replaceCount = 0;
var testContext = (0, _emberBabel.assertThisInitialized)((0, _emberBabel.assertThisInitialized)(_this14));
_this14.add('location:none', _routing.NoneLocation.extend({
setURL: function () {
testContext.updateCount++;
return this._super.apply(this, arguments);
},
replaceURL: function () {
testContext.replaceCount++;
return this._super.apply(this, arguments);
}
}));
_this14.router.map(function () {
this.route('about');
});
_this14.addTemplate('index', "\n
{{outlet}}");
this.addTemplate('index.about', "\n {{#link-to 'item' id='other-link' current-when='index'}}ITEM{{/link-to}}\n ");
return this.visit('/about').then(function () {
assert.equal(_this21.$('#other-link.active').length, 1, 'The link is active since current-when is a parent route');
});
};
_proto4["@test The {{link-to}} helper does not disregard current-when when it is given explicitly for a route"] = function (assert) {
var _this22 = this;
this.router.map(function () {
this.route('index', {
path: '/'
}, function () {
this.route('about');
});
this.route('items', function () {
this.route('item');
});
});
this.addTemplate('index', "
Home
{{outlet}}");
this.addTemplate('index.about', "\n {{#link-to 'items' id='other-link' current-when='index'}}ITEM{{/link-to}}\n ");
return this.visit('/about').then(function () {
assert.equal(_this22.$('#other-link.active').length, 1, 'The link is active when current-when is given for explicitly for a route');
});
};
_proto4['@test The {{link-to}} helper does not disregard current-when when it is set via a bound param'] = function testTheLinkToHelperDoesNotDisregardCurrentWhenWhenItIsSetViaABoundParam(assert) {
var _this23 = this;
this.router.map(function () {
this.route('index', {
path: '/'
}, function () {
this.route('about');
});
this.route('items', function () {
this.route('item');
});
});
this.add('controller:index.about', _controller.default.extend({
currentWhen: 'index'
}));
this.addTemplate('index', "
Home
{{outlet}}");
this.addTemplate('index.about', "{{#link-to 'items' id='other-link' current-when=currentWhen}}ITEM{{/link-to}}");
return this.visit('/about').then(function () {
assert.equal(_this23.$('#other-link.active').length, 1, 'The link is active when current-when is given for explicitly for a route');
});
};
_proto4['@test The {{link-to}} helper supports multiple current-when routes'] = function testTheLinkToHelperSupportsMultipleCurrentWhenRoutes(assert) {
var _this24 = this;
this.router.map(function () {
this.route('index', {
path: '/'
}, function () {
this.route('about');
});
this.route('item');
this.route('foo');
});
this.addTemplate('index', "
Home
{{outlet}}");
this.addTemplate('index.about', "{{#link-to 'item' id='link1' current-when='item index'}}ITEM{{/link-to}}");
this.addTemplate('item', "{{#link-to 'item' id='link2' current-when='item index'}}ITEM{{/link-to}}");
this.addTemplate('foo', "{{#link-to 'item' id='link3' current-when='item index'}}ITEM{{/link-to}}");
return this.visit('/about').then(function () {
assert.equal(_this24.$('#link1.active').length, 1, 'The link is active since current-when contains the parent route');
return _this24.visit('/item');
}).then(function () {
assert.equal(_this24.$('#link2.active').length, 1, 'The link is active since you are on the active route');
return _this24.visit('/foo');
}).then(function () {
assert.equal(_this24.$('#link3.active').length, 0, 'The link is not active since current-when does not contain the active route');
});
};
_proto4['@test The {{link-to}} helper supports boolean values for current-when'] = function testTheLinkToHelperSupportsBooleanValuesForCurrentWhen(assert) {
var _this25 = this;
this.router.map(function () {
this.route('index', {
path: '/'
}, function () {
this.route('about');
});
this.route('item');
});
this.addTemplate('index.about', "\n {{#link-to 'index' id='index-link' current-when=isCurrent}}index{{/link-to}}\n {{#link-to 'item' id='about-link' current-when=true}}ITEM{{/link-to}}\n ");
this.add('controller:index.about', _controller.default.extend({
isCurrent: false
}));
return this.visit('/about').then(function () {
assert.ok(_this25.$('#about-link').hasClass('active'), 'The link is active since current-when is true');
assert.notOk(_this25.$('#index-link').hasClass('active'), 'The link is not active since current-when is false');
var controller = _this25.applicationInstance.lookup('controller:index.about');
(0, _internalTestHelpers.runTask)(function () {
return controller.set('isCurrent', true);
});
assert.ok(_this25.$('#index-link').hasClass('active'), 'The link is active since current-when is true');
});
};
_proto4['@test The {{link-to}} helper defaults to bubbling'] = function testTheLinkToHelperDefaultsToBubbling(assert) {
var _this26 = this;
this.addTemplate('about', "\n
\n {{link-to 'Home' 'index' id='home-link'}}\n {{link-to 'Self' 'contact' id='self-link'}}\n ");
return this.visit('/').then(function () {
return _this45.click('#contact-link');
}).then(function () {
assert.equal(_this45.$('h3.contact').length, 1, 'The contact template was rendered');
assert.equal(_this45.$('#self-link.active').length, 1, 'The self-link was rendered with active class');
assert.equal(_this45.$('#home-link:not(.active)').length, 1, 'The other link was rendered without active class');
});
};
_proto4["@test The non-block form {{link-to}} helper updates the link text when it is a binding"] = function (assert) {
var _this46 = this;
assert.expect(8);
this.router.map(function () {
this.route('contact');
});
this.add('controller:index', _controller.default.extend({
contactName: 'Jane'
}));
this.addTemplate('index', "\n
\n {{link-to 'Home' 'index' id='home-link'}}\n {{link-to 'Self' 'contact' id='self-link'}}\n ");
return this.visit('/').then(function () {
assert.equal(_this46.$('#contact-link').text(), 'Jane', 'The link title is correctly resolved');
var controller = _this46.applicationInstance.lookup('controller:index');
(0, _internalTestHelpers.runTask)(function () {
return controller.set('contactName', 'Joe');
});
assert.equal(_this46.$('#contact-link').text(), 'Joe', 'The link title is correctly updated when the bound property changes');
(0, _internalTestHelpers.runTask)(function () {
return controller.set('contactName', 'Robert');
});
assert.equal(_this46.$('#contact-link').text(), 'Robert', 'The link title is correctly updated when the bound property changes a second time');
return _this46.click('#contact-link');
}).then(function () {
assert.equal(_this46.$('h3.contact').length, 1, 'The contact template was rendered');
assert.equal(_this46.$('#self-link.active').length, 1, 'The self-link was rendered with active class');
assert.equal(_this46.$('#home-link:not(.active)').length, 1, 'The other link was rendered without active class');
return _this46.click('#home-link');
}).then(function () {
assert.equal(_this46.$('h3.home').length, 1, 'The index template was rendered');
assert.equal(_this46.$('#contact-link').text(), 'Robert', 'The link title is correctly updated when the route changes');
});
};
_proto4["@test The non-block form {{link-to}} helper moves into the named route with context"] = function (assert) {
var _this47 = this;
assert.expect(5);
this.router.map(function () {
this.route('item', {
path: '/item/:id'
});
});
this.add('route:index', _routing.Route.extend({
model: function () {
return [{
id: 'yehuda',
name: 'Yehuda Katz'
}, {
id: 'tom',
name: 'Tom Dale'
}, {
id: 'erik',
name: 'Erik Brynroflsson'
}];
}
}));
this.addTemplate('index', "\n
Home
\n
\n {{#each model as |person|}}\n
\n {{link-to person.name 'item' person id=person.id}}\n
\n {{/each}}\n
\n ");
this.addTemplate('item', "\n
Item
\n
{{model.name}}
\n {{#link-to 'index' id='home-link'}}Home{{/link-to}}\n ");
return this.visit('/').then(function () {
return _this47.click('#yehuda');
}).then(function () {
assert.equal(_this47.$('h3.item').length, 1, 'The item template was rendered');
assert.equal(_this47.$('p').text(), 'Yehuda Katz', 'The name is correct');
return _this47.click('#home-link');
}).then(function () {
assert.equal(normalizeUrl(_this47.$('li a#yehuda').attr('href')), '/item/yehuda');
assert.equal(normalizeUrl(_this47.$('li a#tom').attr('href')), '/item/tom');
assert.equal(normalizeUrl(_this47.$('li a#erik').attr('href')), '/item/erik');
});
};
_proto4["@test The non-block form {{link-to}} performs property lookup"] = function (assert) {
var _this48 = this;
this.router.map(function () {
this.route('about');
});
this.addTemplate('index', "\n {{link-to 'string' 'index' id='string-link'}}\n {{link-to path foo id='path-link'}}\n ");
this.add('controller:index', _controller.default.extend({
foo: 'index'
}));
return this.visit('/').then(function () {
var assertEquality = function (href) {
assert.equal(normalizeUrl(_this48.$('#string-link').attr('href')), '/');
assert.equal(normalizeUrl(_this48.$('#path-link').attr('href')), href);
};
assertEquality('/');
var controller = _this48.applicationInstance.lookup('controller:index');
(0, _internalTestHelpers.runTask)(function () {
return controller.set('foo', 'about');
});
assertEquality('/about');
});
};
_proto4["@test The non-block form {{link-to}} protects against XSS"] = function (assert) {
var _this49 = this;
this.addTemplate('application', "{{link-to display 'index' id='link'}}");
this.add('controller:application', _controller.default.extend({
display: 'blahzorz'
}));
return this.visit('/').then(function () {
assert.equal(_this49.$('#link').text(), 'blahzorz');
var controller = _this49.applicationInstance.lookup('controller:application');
(0, _internalTestHelpers.runTask)(function () {
return controller.set('display', 'BLAMMO');
});
assert.equal(_this49.$('#link').text(), 'BLAMMO');
assert.equal(_this49.$('b').length, 0);
});
};
_proto4["@test the {{link-to}} helper throws a useful error if you invoke it wrong"] = function (assert) {
var _this50 = this;
assert.expect(1);
this.router.map(function () {
this.route('post', {
path: 'post/:post_id'
});
});
this.addTemplate('application', "{{#link-to 'post'}}Post{{/link-to}}");
assert.throws(function () {
_this50.visit('/');
}, /(You attempted to define a `\{\{link-to "post"\}\}` but did not pass the parameters required for generating its dynamic segments.|You must provide param `post_id` to `generate`)/);
return (0, _internalTestHelpers.runLoopSettled)();
};
_proto4["@test the {{link-to}} helper does not throw an error if its route has exited"] = function (assert) {
var _this51 = this;
assert.expect(0);
this.router.map(function () {
this.route('post', {
path: 'post/:post_id'
});
});
this.addTemplate('application', "\n {{#link-to 'index' id='home-link'}}Home{{/link-to}}\n {{#link-to 'post' defaultPost id='default-post-link'}}Default Post{{/link-to}}\n {{#if currentPost}}\n {{#link-to 'post' currentPost id='current-post-link'}}Current Post{{/link-to}}\n {{/if}}\n ");
this.add('controller:application', _controller.default.extend({
defaultPost: {
id: 1
},
postController: (0, _controller.inject)('post'),
currentPost: (0, _metal.alias)('postController.model')
}));
this.add('controller:post', _controller.default.extend());
this.add('route:post', _routing.Route.extend({
model: function () {
return {
id: 2
};
},
serialize: function (model) {
return {
post_id: model.id
};
}
}));
return this.visit('/').then(function () {
return _this51.click('#default-post-link');
}).then(function () {
return _this51.click('#home-link');
}).then(function () {
return _this51.click('#current-post-link');
}).then(function () {
return _this51.click('#home-link');
});
};
_proto4["@test {{link-to}} active property respects changing parent route context"] = function (assert) {
var _this52 = this;
this.router.map(function () {
this.route('things', {
path: '/things/:name'
}, function () {
this.route('other');
});
});
this.addTemplate('application', "\n {{link-to 'OMG' 'things' 'omg' id='omg-link'}}\n {{link-to 'LOL' 'things' 'lol' id='lol-link'}}\n ");
return this.visit('/things/omg').then(function () {
shouldBeActive(assert, _this52.$('#omg-link'));
shouldNotBeActive(assert, _this52.$('#lol-link'));
return _this52.visit('/things/omg/other');
}).then(function () {
shouldBeActive(assert, _this52.$('#omg-link'));
shouldNotBeActive(assert, _this52.$('#lol-link'));
});
};
_proto4["@test {{link-to}} populates href with default query param values even without query-params object"] = function (assert) {
var _this53 = this;
this.add('controller:index', _controller.default.extend({
queryParams: ['foo'],
foo: '123'
}));
this.addTemplate('index', "{{#link-to 'index' id='the-link'}}Index{{/link-to}}");
return this.visit('/').then(function () {
assert.equal(_this53.$('#the-link').attr('href'), '/', 'link has right href');
});
};
_proto4["@test {{link-to}} populates href with default query param values with empty query-params object"] = function (assert) {
var _this54 = this;
this.add('controller:index', _controller.default.extend({
queryParams: ['foo'],
foo: '123'
}));
this.addTemplate('index', "\n {{#link-to 'index' (query-params) id='the-link'}}Index{{/link-to}}\n ");
return this.visit('/').then(function () {
assert.equal(_this54.$('#the-link').attr('href'), '/', 'link has right href');
});
};
_proto4["@test {{link-to}} with only query-params and a block updates when route changes"] = function (assert) {
var _this55 = this;
this.router.map(function () {
this.route('about');
});
this.add('controller:application', _controller.default.extend({
queryParams: ['foo', 'bar'],
foo: '123',
bar: 'yes'
}));
this.addTemplate('application', "\n {{#link-to (query-params foo='456' bar='NAW') id='the-link'}}Index{{/link-to}}\n ");
return this.visit('/').then(function () {
assert.equal(_this55.$('#the-link').attr('href'), '/?bar=NAW&foo=456', 'link has right href');
return _this55.visit('/about');
}).then(function () {
assert.equal(_this55.$('#the-link').attr('href'), '/about?bar=NAW&foo=456', 'link has right href');
});
};
_proto4["@test Block-less {{link-to}} with only query-params updates when route changes"] = function (assert) {
var _this56 = this;
this.router.map(function () {
this.route('about');
});
this.add('controller:application', _controller.default.extend({
queryParams: ['foo', 'bar'],
foo: '123',
bar: 'yes'
}));
this.addTemplate('application', "\n {{link-to \"Index\" (query-params foo='456' bar='NAW') id='the-link'}}\n ");
return this.visit('/').then(function () {
assert.equal(_this56.$('#the-link').attr('href'), '/?bar=NAW&foo=456', 'link has right href');
return _this56.visit('/about');
}).then(function () {
assert.equal(_this56.$('#the-link').attr('href'), '/about?bar=NAW&foo=456', 'link has right href');
});
};
_proto4["@test The {{link-to}} helper can use dynamic params"] = function (assert) {
var _this57 = this;
this.router.map(function () {
this.route('foo', {
path: 'foo/:some/:thing'
});
this.route('bar', {
path: 'bar/:some/:thing/:else'
});
});
this.add('controller:index', _controller.default.extend({
init: function () {
this._super.apply(this, arguments);
this.dynamicLinkParams = ['foo', 'one', 'two'];
}
}));
this.addTemplate('index', "\n
Home
\n {{#link-to params=dynamicLinkParams id=\"dynamic-link\"}}Dynamic{{/link-to}}\n ");
return this.visit('/').then(function () {
var link = _this57.$('#dynamic-link');
assert.equal(link.attr('href'), '/foo/one/two');
var controller = _this57.applicationInstance.lookup('controller:index');
(0, _internalTestHelpers.runTask)(function () {
controller.set('dynamicLinkParams', ['bar', 'one', 'two', 'three']);
});
assert.equal(link.attr('href'), '/bar/one/two/three');
});
};
_proto4["@test GJ: {{link-to}} to a parent root model hook which performs a 'transitionTo' has correct active class #13256"] = function (assert) {
var _this58 = this;
assert.expect(1);
this.router.map(function () {
this.route('parent', function () {
this.route('child');
});
});
this.add('route:parent', _routing.Route.extend({
afterModel: function () {
this.transitionTo('parent.child');
}
}));
this.addTemplate('application', "\n {{link-to 'Parent' 'parent' id='parent-link'}}\n ");
return this.visit('/').then(function () {
return _this58.click('#parent-link');
}).then(function () {
shouldBeActive(assert, _this58.$('#parent-link'));
});
};
return _class4;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper - loading states and warnings',
/*#__PURE__*/
function (_ApplicationTestCase5) {
(0, _emberBabel.inheritsLoose)(_class5, _ApplicationTestCase5);
function _class5() {
return _ApplicationTestCase5.apply(this, arguments) || this;
}
var _proto5 = _class5.prototype;
_proto5["@test link-to with null/undefined dynamic parameters are put in a loading state"] = function (assert) {
var _this59 = this;
assert.expect(19);
var warningMessage = 'This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid.';
this.router.map(function () {
this.route('thing', {
path: '/thing/:thing_id'
});
this.route('about');
});
this.addTemplate('index', "\n {{#link-to destinationRoute routeContext loadingClass='i-am-loading' id='context-link'}}\n string\n {{/link-to}}\n {{#link-to secondRoute loadingClass=loadingClass id='static-link'}}\n string\n {{/link-to}}\n ");
this.add('controller:index', _controller.default.extend({
destinationRoute: null,
routeContext: null,
loadingClass: 'i-am-loading'
}));
this.add('route:about', _routing.Route.extend({
activate: function () {
assert.ok(true, 'About was entered');
}
}));
function assertLinkStatus(link, url) {
if (url) {
assert.equal(normalizeUrl(link.attr('href')), url, 'loaded link-to has expected href');
assert.ok(!link.hasClass('i-am-loading'), 'loaded linkComponent has no loadingClass');
} else {
assert.equal(normalizeUrl(link.attr('href')), '#', "unloaded link-to has href='#'");
assert.ok(link.hasClass('i-am-loading'), 'loading linkComponent has loadingClass');
}
}
var contextLink, staticLink, controller;
return this.visit('/').then(function () {
contextLink = _this59.$('#context-link');
staticLink = _this59.$('#static-link');
controller = _this59.applicationInstance.lookup('controller:index');
assertLinkStatus(contextLink);
assertLinkStatus(staticLink);
return expectWarning(function () {
return _this59.click(contextLink[0]);
}, warningMessage);
}).then(function () {
// Set the destinationRoute (context is still null).
(0, _internalTestHelpers.runTask)(function () {
return controller.set('destinationRoute', 'thing');
});
assertLinkStatus(contextLink); // Set the routeContext to an id
(0, _internalTestHelpers.runTask)(function () {
return controller.set('routeContext', '456');
});
assertLinkStatus(contextLink, '/thing/456'); // Test that 0 isn't interpreted as falsy.
(0, _internalTestHelpers.runTask)(function () {
return controller.set('routeContext', 0);
});
assertLinkStatus(contextLink, '/thing/0'); // Set the routeContext to an object
(0, _internalTestHelpers.runTask)(function () {
controller.set('routeContext', {
id: 123
});
});
assertLinkStatus(contextLink, '/thing/123'); // Set the destinationRoute back to null.
(0, _internalTestHelpers.runTask)(function () {
return controller.set('destinationRoute', null);
});
assertLinkStatus(contextLink);
return expectWarning(function () {
return _this59.click(staticLink[0]);
}, warningMessage);
}).then(function () {
(0, _internalTestHelpers.runTask)(function () {
return controller.set('secondRoute', 'about');
});
assertLinkStatus(staticLink, '/about'); // Click the now-active link
return _this59.click(staticLink[0]);
});
};
return _class5;
}(_internalTestHelpers.ApplicationTestCase));
function assertNav(options, callback, assert) {
var nav = false;
function check(event) {
assert.equal(event.defaultPrevented, options.prevented, "expected defaultPrevented=" + options.prevented);
nav = true;
event.preventDefault();
}
try {
document.addEventListener('click', check);
callback();
} finally {
document.removeEventListener('click', check);
assert.ok(nav, 'Expected a link to be clicked');
}
}
});
enifed("ember/tests/helpers/link_to_test/link_to_transitioning_classes_test", ["ember-babel", "@ember/-internals/runtime", "@ember/-internals/routing", "internal-test-helpers"], function (_emberBabel, _runtime, _routing, _internalTestHelpers) {
"use strict";
function assertHasClass(assert, selector, label) {
var testLabel = selector.attr('id') + " should have class " + label;
assert.equal(selector.hasClass(label), true, testLabel);
}
function assertHasNoClass(assert, selector, label) {
var testLabel = selector.attr('id') + " should not have class " + label;
assert.equal(selector.hasClass(label), false, testLabel);
}
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper: .transitioning-in .transitioning-out CSS classes',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
var _this2;
_this2 = _ApplicationTestCase.call(this) || this;
_this2.aboutDefer = _runtime.RSVP.defer();
_this2.otherDefer = _runtime.RSVP.defer();
_this2.newsDefer = _runtime.RSVP.defer();
var _this = (0, _emberBabel.assertThisInitialized)((0, _emberBabel.assertThisInitialized)(_this2));
_this2.router.map(function () {
this.route('about');
this.route('other');
this.route('news');
});
_this2.add('route:about', _routing.Route.extend({
model: function () {
return _this.aboutDefer.promise;
}
}));
_this2.add('route:other', _routing.Route.extend({
model: function () {
return _this.otherDefer.promise;
}
}));
_this2.add('route:news', _routing.Route.extend({
model: function () {
return _this.newsDefer.promise;
}
}));
_this2.addTemplate('application', "\n {{outlet}}\n {{link-to 'Index' 'index' id='index-link'}}\n {{link-to 'About' 'about' id='about-link'}}\n {{link-to 'Other' 'other' id='other-link'}}\n {{link-to 'News' 'news' activeClass=false id='news-link'}}\n ");
return _this2;
}
var _proto = _class.prototype;
_proto.beforeEach = function beforeEach() {
return this.visit('/');
};
_proto.afterEach = function afterEach() {
_ApplicationTestCase.prototype.afterEach.call(this);
this.aboutDefer = null;
this.otherDefer = null;
this.newsDefer = null;
};
_proto['@test while a transition is underway'] = function testWhileATransitionIsUnderway(assert) {
var _this3 = this;
var $index = this.$('#index-link');
var $about = this.$('#about-link');
var $other = this.$('#other-link');
$about.click();
assertHasClass(assert, $index, 'active');
assertHasNoClass(assert, $about, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
(0, _internalTestHelpers.runTask)(function () {
return _this3.aboutDefer.resolve();
});
assertHasNoClass(assert, $index, 'active');
assertHasClass(assert, $about, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasNoClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
};
_proto['@test while a transition is underway with activeClass is false'] = function testWhileATransitionIsUnderwayWithActiveClassIsFalse(assert) {
var _this4 = this;
var $index = this.$('#index-link');
var $news = this.$('#news-link');
var $other = this.$('#other-link');
$news.click();
assertHasClass(assert, $index, 'active');
assertHasNoClass(assert, $news, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasClass(assert, $news, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $news, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
(0, _internalTestHelpers.runTask)(function () {
return _this4.newsDefer.resolve();
});
assertHasNoClass(assert, $index, 'active');
assertHasNoClass(assert, $news, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasNoClass(assert, $news, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $news, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)("The {{link-to}} helper: .transitioning-in .transitioning-out CSS classes - nested link-to's",
/*#__PURE__*/
function (_ApplicationTestCase2) {
(0, _emberBabel.inheritsLoose)(_class2, _ApplicationTestCase2);
function _class2() {
var _this5;
_this5 = _ApplicationTestCase2.call(this) || this;
_this5.aboutDefer = _runtime.RSVP.defer();
_this5.otherDefer = _runtime.RSVP.defer();
var _this = (0, _emberBabel.assertThisInitialized)((0, _emberBabel.assertThisInitialized)(_this5));
_this5.router.map(function () {
this.route('parent-route', function () {
this.route('about');
this.route('other');
});
});
_this5.add('route:parent-route.about', _routing.Route.extend({
model: function () {
return _this.aboutDefer.promise;
}
}));
_this5.add('route:parent-route.other', _routing.Route.extend({
model: function () {
return _this.otherDefer.promise;
}
}));
_this5.addTemplate('application', "\n {{outlet}}\n {{#link-to 'index' tagName='li'}}\n {{link-to 'Index' 'index' id='index-link'}}\n {{/link-to}}\n {{#link-to 'parent-route.about' tagName='li'}}\n {{link-to 'About' 'parent-route.about' id='about-link'}}\n {{/link-to}}\n {{#link-to 'parent-route.other' tagName='li'}}\n {{link-to 'Other' 'parent-route.other' id='other-link'}}\n {{/link-to}}\n ");
return _this5;
}
var _proto2 = _class2.prototype;
_proto2.beforeEach = function beforeEach() {
return this.visit('/');
};
_proto2.resolveAbout = function resolveAbout() {
var _this6 = this;
return (0, _internalTestHelpers.runTask)(function () {
_this6.aboutDefer.resolve();
_this6.aboutDefer = _runtime.RSVP.defer();
});
};
_proto2.resolveOther = function resolveOther() {
var _this7 = this;
return (0, _internalTestHelpers.runTask)(function () {
_this7.otherDefer.resolve();
_this7.otherDefer = _runtime.RSVP.defer();
});
};
_proto2.teardown = function teardown() {
_ApplicationTestCase2.prototype.teardown.call(this);
this.aboutDefer = null;
this.otherDefer = null;
};
_proto2["@test while a transition is underway with nested link-to's"] = function (assert) {
// TODO undo changes to this test but currently this test navigates away if navigation
// outlet is not stable and the second $about.click() is triggered.
var $about = this.$('#about-link');
$about.click();
var $index = this.$('#index-link');
$about = this.$('#about-link');
var $other = this.$('#other-link');
assertHasClass(assert, $index, 'active');
assertHasNoClass(assert, $about, 'active');
assertHasNoClass(assert, $about, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
this.resolveAbout();
$index = this.$('#index-link');
$about = this.$('#about-link');
$other = this.$('#other-link');
assertHasNoClass(assert, $index, 'active');
assertHasClass(assert, $about, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasNoClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
$other.click();
$index = this.$('#index-link');
$about = this.$('#about-link');
$other = this.$('#other-link');
assertHasNoClass(assert, $index, 'active');
assertHasClass(assert, $about, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasNoClass(assert, $about, 'ember-transitioning-in');
assertHasClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
this.resolveOther();
$index = this.$('#index-link');
$about = this.$('#about-link');
$other = this.$('#other-link');
assertHasNoClass(assert, $index, 'active');
assertHasNoClass(assert, $about, 'active');
assertHasClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasNoClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
$about.click();
$index = this.$('#index-link');
$about = this.$('#about-link');
$other = this.$('#other-link');
assertHasNoClass(assert, $index, 'active');
assertHasNoClass(assert, $about, 'active');
assertHasClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasClass(assert, $other, 'ember-transitioning-out');
this.resolveAbout();
$index = this.$('#index-link');
$about = this.$('#about-link');
$other = this.$('#other-link');
assertHasNoClass(assert, $index, 'active');
assertHasClass(assert, $about, 'active');
assertHasNoClass(assert, $other, 'active');
assertHasNoClass(assert, $index, 'ember-transitioning-in');
assertHasNoClass(assert, $about, 'ember-transitioning-in');
assertHasNoClass(assert, $other, 'ember-transitioning-in');
assertHasNoClass(assert, $index, 'ember-transitioning-out');
assertHasNoClass(assert, $about, 'ember-transitioning-out');
assertHasNoClass(assert, $other, 'ember-transitioning-out');
};
return _class2;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("ember/tests/helpers/link_to_test/link_to_with_query_params_test", ["ember-babel", "@ember/controller", "@ember/-internals/runtime", "@ember/-internals/routing", "internal-test-helpers"], function (_emberBabel, _controller, _runtime, _routing, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('The {{link-to}} helper: invoking with query params',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
var _this;
_this = _ApplicationTestCase.call(this) || this;
var indexProperties = {
foo: '123',
bar: 'abc'
};
_this.add('controller:index', _controller.default.extend({
queryParams: ['foo', 'bar', 'abool'],
foo: indexProperties.foo,
bar: indexProperties.bar,
boundThing: 'OMG',
abool: true
}));
_this.add('controller:about', _controller.default.extend({
queryParams: ['baz', 'bat'],
baz: 'alex',
bat: 'borf'
}));
_this.indexProperties = indexProperties;
return _this;
}
var _proto = _class.prototype;
_proto.shouldNotBeActive = function shouldNotBeActive(assert, selector) {
this.checkActive(assert, selector, false);
};
_proto.shouldBeActive = function shouldBeActive(assert, selector) {
this.checkActive(assert, selector, true);
};
_proto.getController = function getController(name) {
return this.applicationInstance.lookup("controller:" + name);
};
_proto.checkActive = function checkActive(assert, selector, active) {
var classList = this.$(selector)[0].className;
assert.equal(classList.indexOf('active') > -1, active, selector + ' active should be ' + active.toString());
};
_proto["@test doesn't update controller QP properties on current route when invoked"] = function (assert) {
var _this2 = this;
this.addTemplate('index', "\n {{#link-to 'index' id='the-link'}}Index{{/link-to}}\n ");
return this.visit('/').then(function () {
_this2.click('#the-link');
var indexController = _this2.getController('index');
assert.deepEqual(indexController.getProperties('foo', 'bar'), _this2.indexProperties, 'controller QP properties do not update');
});
};
_proto["@test doesn't update controller QP properties on current route when invoked (empty query-params obj)"] = function (assert) {
var _this3 = this;
this.addTemplate('index', "\n {{#link-to 'index' (query-params) id='the-link'}}Index{{/link-to}}\n ");
return this.visit('/').then(function () {
_this3.click('#the-link');
var indexController = _this3.getController('index');
assert.deepEqual(indexController.getProperties('foo', 'bar'), _this3.indexProperties, 'controller QP properties do not update');
});
};
_proto["@test doesn't update controller QP properties on current route when invoked (empty query-params obj, inferred route)"] = function (assert) {
var _this4 = this;
this.addTemplate('index', "\n {{#link-to (query-params) id='the-link'}}Index{{/link-to}}\n ");
return this.visit('/').then(function () {
_this4.click('#the-link');
var indexController = _this4.getController('index');
assert.deepEqual(indexController.getProperties('foo', 'bar'), _this4.indexProperties, 'controller QP properties do not update');
});
};
_proto['@test updates controller QP properties on current route when invoked'] = function testUpdatesControllerQPPropertiesOnCurrentRouteWhenInvoked(assert) {
var _this5 = this;
this.addTemplate('index', "\n {{#link-to 'index' (query-params foo='456') id=\"the-link\"}}\n Index\n {{/link-to}}\n ");
return this.visit('/').then(function () {
_this5.click('#the-link');
var indexController = _this5.getController('index');
assert.deepEqual(indexController.getProperties('foo', 'bar'), {
foo: '456',
bar: 'abc'
}, 'controller QP properties updated');
});
};
_proto['@test updates controller QP properties on current route when invoked (inferred route)'] = function testUpdatesControllerQPPropertiesOnCurrentRouteWhenInvokedInferredRoute(assert) {
var _this6 = this;
this.addTemplate('index', "\n {{#link-to (query-params foo='456') id=\"the-link\"}}\n Index\n {{/link-to}}\n ");
return this.visit('/').then(function () {
_this6.click('#the-link');
var indexController = _this6.getController('index');
assert.deepEqual(indexController.getProperties('foo', 'bar'), {
foo: '456',
bar: 'abc'
}, 'controller QP properties updated');
});
};
_proto['@test updates controller QP properties on other route after transitioning to that route'] = function testUpdatesControllerQPPropertiesOnOtherRouteAfterTransitioningToThatRoute(assert) {
var _this7 = this;
this.router.map(function () {
this.route('about');
});
this.addTemplate('index', "\n {{#link-to 'about' (query-params baz='lol') id='the-link'}}\n About\n {{/link-to}}\n ");
return this.visit('/').then(function () {
var theLink = _this7.$('#the-link');
assert.equal(theLink.attr('href'), '/about?baz=lol');
(0, _internalTestHelpers.runTask)(function () {
return _this7.click('#the-link');
});
var aboutController = _this7.getController('about');
assert.deepEqual(aboutController.getProperties('baz', 'bat'), {
baz: 'lol',
bat: 'borf'
}, 'about controller QP properties updated');
});
};
_proto['@test supplied QP properties can be bound'] = function testSuppliedQPPropertiesCanBeBound(assert) {
var _this8 = this;
this.addTemplate('index', "\n {{#link-to (query-params foo=boundThing) id='the-link'}}Index{{/link-to}}\n ");
return this.visit('/').then(function () {
var indexController = _this8.getController('index');
var theLink = _this8.$('#the-link');
assert.equal(theLink.attr('href'), '/?foo=OMG');
(0, _internalTestHelpers.runTask)(function () {
return indexController.set('boundThing', 'ASL');
});
assert.equal(theLink.attr('href'), '/?foo=ASL');
});
};
_proto['@test supplied QP properties can be bound (booleans)'] = function testSuppliedQPPropertiesCanBeBoundBooleans(assert) {
var _this9 = this;
this.addTemplate('index', "\n {{#link-to (query-params abool=boundThing) id='the-link'}}\n Index\n {{/link-to}}\n ");
return this.visit('/').then(function () {
var indexController = _this9.getController('index');
var theLink = _this9.$('#the-link');
assert.equal(theLink.attr('href'), '/?abool=OMG');
(0, _internalTestHelpers.runTask)(function () {
return indexController.set('boundThing', false);
});
assert.equal(theLink.attr('href'), '/?abool=false');
_this9.click('#the-link');
assert.deepEqual(indexController.getProperties('foo', 'bar', 'abool'), {
foo: '123',
bar: 'abc',
abool: false
}, 'bound bool QP properties update');
});
};
_proto['@test href updates when unsupplied controller QP props change'] = function testHrefUpdatesWhenUnsuppliedControllerQPPropsChange(assert) {
var _this10 = this;
this.addTemplate('index', "\n {{#link-to (query-params foo='lol') id='the-link'}}Index{{/link-to}}\n ");
return this.visit('/').then(function () {
var indexController = _this10.getController('index');
var theLink = _this10.$('#the-link');
assert.equal(theLink.attr('href'), '/?foo=lol');
(0, _internalTestHelpers.runTask)(function () {
return indexController.set('bar', 'BORF');
});
assert.equal(theLink.attr('href'), '/?bar=BORF&foo=lol');
(0, _internalTestHelpers.runTask)(function () {
return indexController.set('foo', 'YEAH');
});
assert.equal(theLink.attr('href'), '/?bar=BORF&foo=lol');
});
};
_proto['@test The {{link-to}} with only query params always transitions to the current route with the query params applied'] = function testTheLinkToWithOnlyQueryParamsAlwaysTransitionsToTheCurrentRouteWithTheQueryParamsApplied(assert) {
var _this11 = this; // Test harness for bug #12033
this.addTemplate('cars', "\n {{#link-to 'cars.create' id='create-link'}}Create new car{{/link-to}}\n {{#link-to (query-params page='2') id='page2-link'}}Page 2{{/link-to}}\n {{outlet}}\n ");
this.addTemplate('cars.create', "{{#link-to 'cars' id='close-link'}}Close create form{{/link-to}}");
this.router.map(function () {
this.route('cars', function () {
this.route('create');
});
});
this.add('controller:cars', _controller.default.extend({
queryParams: ['page'],
page: 1
}));
return this.visit('/cars/create').then(function () {
var router = _this11.appRouter;
var carsController = _this11.getController('cars');
assert.equal(router.currentRouteName, 'cars.create');
(0, _internalTestHelpers.runTask)(function () {
return _this11.click('#close-link');
});
assert.equal(router.currentRouteName, 'cars.index');
assert.equal(router.get('url'), '/cars');
assert.equal(carsController.get('page'), 1, 'The page query-param is 1');
(0, _internalTestHelpers.runTask)(function () {
return _this11.click('#page2-link');
});
assert.equal(router.currentRouteName, 'cars.index', 'The active route is still cars');
assert.equal(router.get('url'), '/cars?page=2', 'The url has been updated');
assert.equal(carsController.get('page'), 2, 'The query params have been updated');
});
};
_proto['@test the {{link-to}} applies activeClass when query params are not changed'] = function testTheLinkToAppliesActiveClassWhenQueryParamsAreNotChanged(assert) {
var _this12 = this;
this.addTemplate('index', "\n {{#link-to (query-params foo='cat') id='cat-link'}}Index{{/link-to}}\n {{#link-to (query-params foo='dog') id='dog-link'}}Index{{/link-to}}\n {{#link-to 'index' id='change-nothing'}}Index{{/link-to}}\n ");
this.addTemplate('search', "\n {{#link-to (query-params search='same') id='same-search'}}Index{{/link-to}}\n {{#link-to (query-params search='change') id='change-search'}}Index{{/link-to}}\n {{#link-to (query-params search='same' archive=true) id='same-search-add-archive'}}Index{{/link-to}}\n {{#link-to (query-params archive=true) id='only-add-archive'}}Index{{/link-to}}\n {{#link-to (query-params search='same' archive=true) id='both-same'}}Index{{/link-to}}\n {{#link-to (query-params search='different' archive=true) id='change-one'}}Index{{/link-to}}\n {{#link-to (query-params search='different' archive=false) id='remove-one'}}Index{{/link-to}}\n {{outlet}}\n ");
this.addTemplate('search.results', "\n {{#link-to (query-params sort='title') id='same-sort-child-only'}}Index{{/link-to}}\n {{#link-to (query-params search='same') id='same-search-parent-only'}}Index{{/link-to}}\n {{#link-to (query-params search='change') id='change-search-parent-only'}}Index{{/link-to}}\n {{#link-to (query-params search='same' sort='title') id='same-search-same-sort-child-and-parent'}}Index{{/link-to}}\n {{#link-to (query-params search='same' sort='author') id='same-search-different-sort-child-and-parent'}}Index{{/link-to}}\n {{#link-to (query-params search='change' sort='title') id='change-search-same-sort-child-and-parent'}}Index{{/link-to}}\n {{#link-to (query-params foo='dog') id='dog-link'}}Index{{/link-to}}\n ");
this.router.map(function () {
this.route('search', function () {
this.route('results');
});
});
this.add('controller:search', _controller.default.extend({
queryParams: ['search', 'archive'],
search: '',
archive: false
}));
this.add('controller:search.results', _controller.default.extend({
queryParams: ['sort', 'showDetails'],
sort: 'title',
showDetails: true
}));
return this.visit('/').then(function () {
_this12.shouldNotBeActive(assert, '#cat-link');
_this12.shouldNotBeActive(assert, '#dog-link');
return _this12.visit('/?foo=cat');
}).then(function () {
_this12.shouldBeActive(assert, '#cat-link');
_this12.shouldNotBeActive(assert, '#dog-link');
return _this12.visit('/?foo=dog');
}).then(function () {
_this12.shouldBeActive(assert, '#dog-link');
_this12.shouldNotBeActive(assert, '#cat-link');
_this12.shouldBeActive(assert, '#change-nothing');
return _this12.visit('/search?search=same');
}).then(function () {
_this12.shouldBeActive(assert, '#same-search');
_this12.shouldNotBeActive(assert, '#change-search');
_this12.shouldNotBeActive(assert, '#same-search-add-archive');
_this12.shouldNotBeActive(assert, '#only-add-archive');
_this12.shouldNotBeActive(assert, '#remove-one');
return _this12.visit('/search?search=same&archive=true');
}).then(function () {
_this12.shouldBeActive(assert, '#both-same');
_this12.shouldNotBeActive(assert, '#change-one');
return _this12.visit('/search/results?search=same&sort=title&showDetails=true');
}).then(function () {
_this12.shouldBeActive(assert, '#same-sort-child-only');
_this12.shouldBeActive(assert, '#same-search-parent-only');
_this12.shouldNotBeActive(assert, '#change-search-parent-only');
_this12.shouldBeActive(assert, '#same-search-same-sort-child-and-parent');
_this12.shouldNotBeActive(assert, '#same-search-different-sort-child-and-parent');
_this12.shouldNotBeActive(assert, '#change-search-same-sort-child-and-parent');
});
};
_proto['@test the {{link-to}} applies active class when query-param is a number'] = function testTheLinkToAppliesActiveClassWhenQueryParamIsANumber(assert) {
var _this13 = this;
this.addTemplate('index', "\n {{#link-to (query-params page=pageNumber) id='page-link'}}\n Index\n {{/link-to}}\n ");
this.add('controller:index', _controller.default.extend({
queryParams: ['page'],
page: 1,
pageNumber: 5
}));
return this.visit('/').then(function () {
_this13.shouldNotBeActive(assert, '#page-link');
return _this13.visit('/?page=5');
}).then(function () {
_this13.shouldBeActive(assert, '#page-link');
});
};
_proto['@test the {{link-to}} applies active class when query-param is an array'] = function testTheLinkToAppliesActiveClassWhenQueryParamIsAnArray(assert) {
var _this14 = this;
this.addTemplate('index', "\n {{#link-to (query-params pages=pagesArray) id='array-link'}}Index{{/link-to}}\n {{#link-to (query-params pages=biggerArray) id='bigger-link'}}Index{{/link-to}}\n {{#link-to (query-params pages=emptyArray) id='empty-link'}}Index{{/link-to}}\n ");
this.add('controller:index', _controller.default.extend({
queryParams: ['pages'],
pages: [],
pagesArray: [1, 2],
biggerArray: [1, 2, 3],
emptyArray: []
}));
return this.visit('/').then(function () {
_this14.shouldNotBeActive(assert, '#array-link');
return _this14.visit('/?pages=%5B1%2C2%5D');
}).then(function () {
_this14.shouldBeActive(assert, '#array-link');
_this14.shouldNotBeActive(assert, '#bigger-link');
_this14.shouldNotBeActive(assert, '#empty-link');
return _this14.visit('/?pages=%5B2%2C1%5D');
}).then(function () {
_this14.shouldNotBeActive(assert, '#array-link');
_this14.shouldNotBeActive(assert, '#bigger-link');
_this14.shouldNotBeActive(assert, '#empty-link');
return _this14.visit('/?pages=%5B1%2C2%2C3%5D');
}).then(function () {
_this14.shouldBeActive(assert, '#bigger-link');
_this14.shouldNotBeActive(assert, '#array-link');
_this14.shouldNotBeActive(assert, '#empty-link');
});
};
_proto['@test the {{link-to}} helper applies active class to the parent route'] = function testTheLinkToHelperAppliesActiveClassToTheParentRoute(assert) {
var _this15 = this;
this.router.map(function () {
this.route('parent', function () {
this.route('child');
});
});
this.addTemplate('application', "\n {{#link-to 'parent' id='parent-link'}}Parent{{/link-to}}\n {{#link-to 'parent.child' id='parent-child-link'}}Child{{/link-to}}\n {{#link-to 'parent' (query-params foo=cat) id='parent-link-qp'}}Parent{{/link-to}}\n {{outlet}}\n ");
this.add('controller:parent.child', _controller.default.extend({
queryParams: ['foo'],
foo: 'bar'
}));
return this.visit('/').then(function () {
_this15.shouldNotBeActive(assert, '#parent-link');
_this15.shouldNotBeActive(assert, '#parent-child-link');
_this15.shouldNotBeActive(assert, '#parent-link-qp');
return _this15.visit('/parent/child?foo=dog');
}).then(function () {
_this15.shouldBeActive(assert, '#parent-link');
_this15.shouldNotBeActive(assert, '#parent-link-qp');
});
};
_proto['@test The {{link-to}} helper disregards query-params in activeness computation when current-when is specified'] = function testTheLinkToHelperDisregardsQueryParamsInActivenessComputationWhenCurrentWhenIsSpecified(assert) {
var _this16 = this;
var appLink;
this.router.map(function () {
this.route('parent');
});
this.addTemplate('application', "\n {{#link-to 'parent' (query-params page=1) current-when='parent' id='app-link'}}\n Parent\n {{/link-to}}\n {{outlet}}\n ");
this.addTemplate('parent', "\n {{#link-to 'parent' (query-params page=1) current-when='parent' id='parent-link'}}\n Parent\n {{/link-to}}\n {{outlet}}\n ");
this.add('controller:parent', _controller.default.extend({
queryParams: ['page'],
page: 1
}));
return this.visit('/').then(function () {
appLink = _this16.$('#app-link');
assert.equal(appLink.attr('href'), '/parent');
_this16.shouldNotBeActive(assert, '#app-link');
return _this16.visit('/parent?page=2');
}).then(function () {
appLink = _this16.$('#app-link');
var router = _this16.appRouter;
assert.equal(appLink.attr('href'), '/parent');
_this16.shouldBeActive(assert, '#app-link');
assert.equal(_this16.$('#parent-link').attr('href'), '/parent');
_this16.shouldBeActive(assert, '#parent-link');
var parentController = _this16.getController('parent');
assert.equal(parentController.get('page'), 2);
(0, _internalTestHelpers.runTask)(function () {
return parentController.set('page', 3);
});
assert.equal(router.get('location.path'), '/parent?page=3');
_this16.shouldBeActive(assert, '#app-link');
_this16.shouldBeActive(assert, '#parent-link');
(0, _internalTestHelpers.runTask)(function () {
return _this16.click('#app-link');
});
assert.equal(router.get('location.path'), '/parent');
});
};
_proto['@test link-to default query params while in active transition regression test'] = function testLinkToDefaultQueryParamsWhileInActiveTransitionRegressionTest(assert) {
var _this17 = this;
this.router.map(function () {
this.route('foos');
this.route('bars');
});
var foos = _runtime.RSVP.defer();
var bars = _runtime.RSVP.defer();
this.addTemplate('application', "\n {{link-to 'Foos' 'foos' id='foos-link'}}\n {{link-to 'Baz Foos' 'foos' (query-params baz=true) id='baz-foos-link'}}\n {{link-to 'Quux Bars' 'bars' (query-params quux=true) id='bars-link'}}\n ");
this.add('controller:foos', _controller.default.extend({
queryParams: ['status'],
baz: false
}));
this.add('route:foos', _routing.Route.extend({
model: function () {
return foos.promise;
}
}));
this.add('controller:bars', _controller.default.extend({
queryParams: ['status'],
quux: false
}));
this.add('route:bars', _routing.Route.extend({
model: function () {
return bars.promise;
}
}));
return this.visit('/').then(function () {
var router = _this17.appRouter;
var foosLink = _this17.$('#foos-link');
var barsLink = _this17.$('#bars-link');
var bazLink = _this17.$('#baz-foos-link');
assert.equal(foosLink.attr('href'), '/foos');
assert.equal(bazLink.attr('href'), '/foos?baz=true');
assert.equal(barsLink.attr('href'), '/bars?quux=true');
assert.equal(router.get('location.path'), '/');
_this17.shouldNotBeActive(assert, '#foos-link');
_this17.shouldNotBeActive(assert, '#baz-foos-link');
_this17.shouldNotBeActive(assert, '#bars-link');
(0, _internalTestHelpers.runTask)(function () {
return barsLink.click();
});
_this17.shouldNotBeActive(assert, '#bars-link');
(0, _internalTestHelpers.runTask)(function () {
return foosLink.click();
});
_this17.shouldNotBeActive(assert, '#foos-link');
(0, _internalTestHelpers.runTask)(function () {
return foos.resolve();
});
assert.equal(router.get('location.path'), '/foos');
_this17.shouldBeActive(assert, '#foos-link');
});
};
_proto["@test the {{link-to}} helper throws a useful error if you invoke it wrong"] = function (assert) {
var _this18 = this;
assert.expect(1);
this.addTemplate('application', "{{#link-to id='the-link'}}Index{{/link-to}}");
expectAssertion(function () {
_this18.visit('/');
}, /You must provide one or more parameters to the link-to component/);
return (0, _internalTestHelpers.runLoopSettled)();
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("ember/tests/homepage_example_test", ["ember-babel", "@ember/-internals/routing", "@ember/-internals/metal", "@ember/-internals/runtime", "internal-test-helpers"], function (_emberBabel, _routing, _metal, _runtime, _internalTestHelpers) {
"use strict";
(0, _internalTestHelpers.moduleFor)('The example renders correctly',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
return _ApplicationTestCase.apply(this, arguments) || this;
}
var _proto = _class.prototype;
_proto['@test Render index template into application outlet'] = function testRenderIndexTemplateIntoApplicationOutlet(assert) {
var _this = this;
this.addTemplate('application', '{{outlet}}');
this.addTemplate('index', '
People
{{#each model as |person|}}
Hello, {{person.fullName}}!
{{/each}}
');
var Person = _runtime.Object.extend({
firstName: null,
lastName: null,
fullName: (0, _metal.computed)('firstName', 'lastName', function () {
return this.get('firstName') + " " + this.get('lastName');
})
});
this.add('route:index', _routing.Route.extend({
model: function () {
return (0, _runtime.A)([Person.create({
firstName: 'Tom',
lastName: 'Dale'
}), Person.create({
firstName: 'Yehuda',
lastName: 'Katz'
})]);
}
}));
return this.visit('/').then(function () {
var $ = _this.$();
assert.equal($.findAll('h1').text(), 'People');
assert.equal($.findAll('li').length, 2);
assert.equal($.findAll('li:nth-of-type(1)').text(), 'Hello, Tom Dale!');
assert.equal($.findAll('li:nth-of-type(2)').text(), 'Hello, Yehuda Katz!');
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed("ember/tests/integration/multiple-app-test", ["ember-babel", "internal-test-helpers", "@ember/application", "@ember/-internals/glimmer", "@ember/-internals/owner", "@ember/polyfills", "rsvp"], function (_emberBabel, _internalTestHelpers, _application, _glimmer, _owner, _polyfills, _rsvp) {
"use strict";
(0, _internalTestHelpers.moduleFor)('View Integration',
/*#__PURE__*/
function (_ApplicationTestCase) {
(0, _emberBabel.inheritsLoose)(_class, _ApplicationTestCase);
function _class() {
var _this;
document.getElementById('qunit-fixture').innerHTML = "\n \n \n ";
_this = _ApplicationTestCase.call(this) || this;
(0, _internalTestHelpers.runTask)(function () {
_this.createSecondApplication();
});
return _this;
}
var _proto = _class.prototype;
_proto.createSecondApplication = function createSecondApplication(options) {
var applicationOptions = this.applicationOptions;
var secondApplicationOptions = {
rootElement: '#two'
};
var myOptions = (0, _polyfills.assign)(applicationOptions, secondApplicationOptions, options);
this.secondApp = _application.default.create(myOptions);
this.secondResolver = this.secondApp.__registry__.resolver;
return this.secondApp;
};
_proto.teardown = function teardown() {
var _this2 = this;
_ApplicationTestCase.prototype.teardown.call(this);
if (this.secondApp) {
(0, _internalTestHelpers.runTask)(function () {
_this2.secondApp.destroy();
});
}
};
_proto.addFactoriesToResolver = function addFactoriesToResolver(actions, resolver) {
resolver.add('component:special-button', _glimmer.Component.extend({
actions: {
doStuff: function () {
var rootElement = (0, _owner.getOwner)(this).application.rootElement;
actions.push(rootElement);
}
}
}));
resolver.add('template:index', this.compile("\n
');
_this.router.map(function () {
this.route('home', {
path: '/'
});
});
originalConsoleError = console.error;
return _this;
}
var _proto = _class.prototype;
_proto.teardown = function teardown() {
_ApplicationTestCase.prototype.teardown.call(this);
console.error = originalConsoleError;
};
_proto.getController = function getController(name) {
return this.applicationInstance.lookup("controller:" + name);
};
_proto.handleURLAborts = function handleURLAborts(assert, path, deprecated) {
var _this2 = this;
(0, _runloop.run)(function () {
var router = _this2.applicationInstance.lookup('router:main');
var result;
if (deprecated !== undefined) {
expectDeprecation(function () {
result = router.handleURL(path);
});
} else {
result = router.handleURL(path);
}
result.then(function () {
assert.ok(false, 'url: `' + path + '` was NOT to be handled');
}, function (reason) {
assert.ok(reason && reason.message === 'TransitionAborted', 'url: `' + path + '` was to be aborted');
});
});
};
_proto.handleURLRejectsWith = function handleURLRejectsWith(context, assert, path, expectedReason) {
return context.visit(path).then(function () {
assert.ok(false, 'expected handleURLing: `' + path + '` to fail');
}).catch(function (reason) {
assert.equal(reason.message, expectedReason);
});
};
_proto['@test warn on URLs not included in the route set'] = function testWarnOnURLsNotIncludedInTheRouteSet() {
var _this3 = this;
return this.visit('/').then(function () {
expectAssertion(function () {
_this3.visit('/what-is-this-i-dont-even');
}, /'\/what-is-this-i-dont-even' did not match any routes/);
});
};
_proto['@test The Homepage'] = function testTheHomepage(assert) {
var _this4 = this;
return this.visit('/').then(function () {
assert.equal(_this4.currentPath, 'home', 'currently on the home route');
var text = _this4.$('.hours').text();
assert.equal(text, 'Hours', 'the home template was rendered');
});
};
_proto["@test The Homepage and the Camelot page with multiple Router.map calls"] = function (assert) {
var _this5 = this;
this.router.map(function () {
this.route('camelot', {
path: '/camelot'
});
});
return this.visit('/camelot').then(function () {
assert.equal(_this5.currentPath, 'camelot');
var text = _this5.$('#camelot').text();
assert.equal(text, 'Is a silly place', 'the camelot template was rendered');
return _this5.visit('/');
}).then(function () {
assert.equal(_this5.currentPath, 'home');
var text = _this5.$('.hours').text();
assert.equal(text, 'Hours', 'the home template was rendered');
});
};
_proto["@test The Homepage with explicit template name in renderTemplate"] = function (assert) {
var _this6 = this;
this.add('route:home', _routing.Route.extend({
renderTemplate: function () {
this.render('homepage');
}
}));
return this.visit('/').then(function () {
var text = _this6.$('#troll').text();
assert.equal(text, 'Megatroll', 'the homepage template was rendered');
});
};
_proto["@test an alternate template will pull in an alternate controller"] = function (assert) {
var _this7 = this;
this.add('route:home', _routing.Route.extend({
renderTemplate: function () {
this.render('homepage');
}
}));
this.add('controller:homepage', _controller.default.extend({
model: {
home: 'Comes from homepage'
}
}));
return this.visit('/').then(function () {
var text = _this7.$('p').text();
assert.equal(text, 'Comes from homepage', 'the homepage template was rendered');
});
};
_proto["@test An alternate template will pull in an alternate controller instead of controllerName"] = function (assert) {
var _this8 = this;
this.add('route:home', _routing.Route.extend({
controllerName: 'foo',
renderTemplate: function () {
this.render('homepage');
}
}));
this.add('controller:foo', _controller.default.extend({
model: {
home: 'Comes from foo'
}
}));
this.add('controller:homepage', _controller.default.extend({
model: {
home: 'Comes from homepage'
}
}));
return this.visit('/').then(function () {
var text = _this8.$('p').text();
assert.equal(text, 'Comes from homepage', 'the homepage template was rendered');
});
};
_proto["@test The template will pull in an alternate controller via key/value"] = function (assert) {
var _this9 = this;
this.router.map(function () {
this.route('homepage', {
path: '/'
});
});
this.add('route:homepage', _routing.Route.extend({
renderTemplate: function () {
this.render({
controller: 'home'
});
}
}));
this.add('controller:home', _controller.default.extend({
model: {
home: 'Comes from home.'
}
}));
return this.visit('/').then(function () {
var text = _this9.$('p').text();
assert.equal(text, 'Comes from home.', 'the homepage template was rendered from data from the HomeController');
});
};
_proto["@test The Homepage with explicit template name in renderTemplate and controller"] = function (assert) {
var _this10 = this;
this.add('controller:home', _controller.default.extend({
model: {
home: 'YES I AM HOME'
}
}));
this.add('route:home', _routing.Route.extend({
renderTemplate: function () {
this.render('homepage');
}
}));
return this.visit('/').then(function () {
var text = _this10.$('p').text();
assert.equal(text, 'YES I AM HOME', 'The homepage template was rendered');
});
};
_proto["@test Model passed via renderTemplate model is set as controller's model"] = function (assert) {
var _this11 = this;
this.addTemplate('bio', '
{{model.name}}
');
this.add('route:home', _routing.Route.extend({
renderTemplate: function () {
this.render('bio', {
model: {
name: 'emberjs'
}
});
}
}));
return this.visit('/').then(function () {
var text = _this11.$('p').text();
assert.equal(text, 'emberjs', "Passed model was set as controller's model");
});
};
_proto['@test render uses templateName from route'] = function testRenderUsesTemplateNameFromRoute(assert) {
var _this12 = this;
this.addTemplate('the_real_home_template', '
THIS IS THE REAL HOME
');
this.add('route:home', _routing.Route.extend({
templateName: 'the_real_home_template'
}));
return this.visit('/').then(function () {
var text = _this12.$('p').text();
assert.equal(text, 'THIS IS THE REAL HOME', 'the homepage template was rendered');
});
};
_proto['@test defining templateName allows other templates to be rendered'] = function testDefiningTemplateNameAllowsOtherTemplatesToBeRendered(assert) {
var _this13 = this;
this.addTemplate('alert', "
Invader!
");
this.addTemplate('the_real_home_template', "
THIS IS THE REAL HOME
{{outlet 'alert'}}");
this.add('route:home', _routing.Route.extend({
templateName: 'the_real_home_template',
actions: {
showAlert: function () {
this.render('alert', {
into: 'home',
outlet: 'alert'
});
}
}
}));
return this.visit('/').then(function () {
var text = _this13.$('p').text();
assert.equal(text, 'THIS IS THE REAL HOME', 'the homepage template was rendered');
return (0, _internalTestHelpers.runTask)(function () {
return _this13.appRouter.send('showAlert');
});
}).then(function () {
var text = _this13.$('.alert-box').text();
assert.equal(text, 'Invader!', 'Template for alert was rendered into the outlet');
});
};
_proto['@test templateName is still used when calling render with no name and options'] = function testTemplateNameIsStillUsedWhenCallingRenderWithNoNameAndOptions(assert) {
var _this14 = this;
this.addTemplate('alert', "
Invader!
");
this.addTemplate('home', "
THIS IS THE REAL HOME
{{outlet 'alert'}}");
this.add('route:home', _routing.Route.extend({
templateName: 'alert',
renderTemplate: function () {
this.render({});
}
}));
return this.visit('/').then(function () {
var text = _this14.$('.alert-box').text();
assert.equal(text, 'Invader!', 'default templateName was rendered into outlet');
});
};
_proto['@test The Homepage with a `setupController` hook'] = function testTheHomepageWithASetupControllerHook(assert) {
var _this15 = this;
this.addTemplate('home', "
{{#each hours as |entry|}}\n
{{entry}}
\n {{/each}}\n
\n ");
this.add('route:home', _routing.Route.extend({
setupController: function (controller) {
controller.set('hours', ['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm']);
}
}));
return this.visit('/').then(function () {
var text = _this15.$('ul li:nth-child(3)').text();
assert.equal(text, 'Sunday: Noon to 6pm', 'The template was rendered with the hours context');
});
};
_proto["@test The route controller is still set when overriding the setupController hook"] = function (assert) {
var _this16 = this;
this.add('route:home', _routing.Route.extend({
setupController: function () {// no-op
// importantly, we are not calling this._super
}
}));
this.add('controller:home', _controller.default.extend());
return this.visit('/').then(function () {
var homeRoute = _this16.applicationInstance.lookup('route:home');
var homeController = _this16.applicationInstance.lookup('controller:home');
assert.equal(homeRoute.controller, homeController, 'route controller is the home controller');
});
};
_proto['@test the route controller can be specified via controllerName'] = function testTheRouteControllerCanBeSpecifiedViaControllerName(assert) {
var _this17 = this;
this.addTemplate('home', '
{{myValue}}
');
this.add('route:home', _routing.Route.extend({
controllerName: 'myController'
}));
this.add('controller:myController', _controller.default.extend({
myValue: 'foo'
}));
return this.visit('/').then(function () {
var homeRoute = _this17.applicationInstance.lookup('route:home');
var myController = _this17.applicationInstance.lookup('controller:myController');
var text = _this17.$('p').text();
assert.equal(homeRoute.controller, myController, 'route controller is set by controllerName');
assert.equal(text, 'foo', 'The homepage template was rendered with data from the custom controller');
});
};
_proto["@test The route controller specified via controllerName is used in render"] = function (assert) {
var _this18 = this;
this.router.map(function () {
this.route('home', {
path: '/'
});
});
this.add('route:home', _routing.Route.extend({
controllerName: 'myController',
renderTemplate: function () {
this.render('alternative_home');
}
}));
this.add('controller:myController', _controller.default.extend({
myValue: 'foo'
}));
this.addTemplate('alternative_home', '
alternative home: {{myValue}}
');
return this.visit('/').then(function () {
var homeRoute = _this18.applicationInstance.lookup('route:home');
var myController = _this18.applicationInstance.lookup('controller:myController');
var text = _this18.$('p').text();
assert.equal(homeRoute.controller, myController, 'route controller is set by controllerName');
assert.equal(text, 'alternative home: foo', 'The homepage template was rendered with data from the custom controller');
});
};
_proto["@test The route controller specified via controllerName is used in render even when a controller with the routeName is available"] = function (assert) {
var _this19 = this;
this.router.map(function () {
this.route('home', {
path: '/'
});
});
this.addTemplate('home', '
home: {{myValue}}
');
this.add('route:home', _routing.Route.extend({
controllerName: 'myController'
}));
this.add('controller:home', _controller.default.extend({
myValue: 'home'
}));
this.add('controller:myController', _controller.default.extend({
myValue: 'myController'
}));
return this.visit('/').then(function () {
var homeRoute = _this19.applicationInstance.lookup('route:home');
var myController = _this19.applicationInstance.lookup('controller:myController');
var text = _this19.$('p').text();
assert.equal(homeRoute.controller, myController, 'route controller is set by controllerName');
assert.equal(text, 'home: myController', 'The homepage template was rendered with data from the custom controller');
});
};
_proto["@test The Homepage with a 'setupController' hook modifying other controllers"] = function (assert) {
var _this20 = this;
this.router.map(function () {
this.route('home', {
path: '/'
});
});
this.add('route:home', _routing.Route.extend({
setupController: function ()
/* controller */
{
this.controllerFor('home').set('hours', ['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm']);
}
}));
this.addTemplate('home', '
{{#each hours as |entry|}}
{{entry}}
{{/each}}
');
return this.visit('/').then(function () {
var text = _this20.$('ul li:nth-child(3)').text();
assert.equal(text, 'Sunday: Noon to 6pm', 'The template was rendered with the hours context');
});
};
_proto["@test The Homepage with a computed model that does not get overridden"] = function (assert) {
var _this21 = this;
this.router.map(function () {
this.route('home', {
path: '/'
});
});
this.add('controller:home', _controller.default.extend({
model: (0, _metal.computed)(function () {
return ['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm'];
})
}));
this.addTemplate('home', '
{{#each model as |passage|}}
{{passage}}
{{/each}}
');
return this.visit('/').then(function () {
var text = _this21.$('ul li:nth-child(3)').text();
assert.equal(text, 'Sunday: Noon to 6pm', 'The template was rendered with the context intact');
});
};
_proto["@test The Homepage getting its controller context via model"] = function (assert) {
var _this22 = this;
this.router.map(function () {
this.route('home', {
path: '/'
});
});
this.add('route:home', _routing.Route.extend({
model: function () {
return ['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm'];
},
setupController: function (controller, model) {
assert.equal(this.controllerFor('home'), controller);
this.controllerFor('home').set('hours', model);
}
}));
this.addTemplate('home', '
{{#each hours as |entry|}}
{{entry}}
{{/each}}
');
return this.visit('/').then(function () {
var text = _this22.$('ul li:nth-child(3)').text();
assert.equal(text, 'Sunday: Noon to 6pm', 'The template was rendered with the hours context');
});
};
_proto["@test The Specials Page getting its controller context by deserializing the params hash"] = function (assert) {
var _this23 = this;
this.router.map(function () {
this.route('home', {
path: '/'
});
this.route('special', {
path: '/specials/:menu_item_id'
});
});
this.add('route:special', _routing.Route.extend({
model: function (params) {
return _runtime.Object.create({
menuItemId: params.menu_item_id
});
}
}));
this.addTemplate('special', '
{{model.menuItemId}}
');
return this.visit('/specials/1').then(function () {
var text = _this23.$('p').text();
assert.equal(text, '1', 'The model was used to render the template');
});
};
_proto['@test The Specials Page defaults to looking models up via `find`'] = function testTheSpecialsPageDefaultsToLookingModelsUpViaFind() {
var _this24 = this;
var MenuItem = _runtime.Object.extend();
MenuItem.reopenClass({
find: function (id) {
return MenuItem.create({
id: id
});
}
});
this.add('model:menu_item', MenuItem);
this.router.map(function () {
this.route('home', {
path: '/'
});
this.route('special', {
path: '/specials/:menu_item_id'
});
});
this.addTemplate('special', '{{model.id}}');
return this.visit('/specials/1').then(function () {
_this24.assertText('1', 'The model was used to render the template');
});
};
_proto['@test The Special Page returning a promise puts the app into a loading state until the promise is resolved'] = function testTheSpecialPageReturningAPromisePutsTheAppIntoALoadingStateUntilThePromiseIsResolved() {
var _this25 = this;
this.router.map(function () {
this.route('home', {
path: '/'
});
this.route('special', {
path: '/specials/:menu_item_id'
});
});
var menuItem, resolve;
var MenuItem = _runtime.Object.extend();
MenuItem.reopenClass({
find: function (id) {
menuItem = MenuItem.create({
id: id
});
return new _rsvp.default.Promise(function (res) {
resolve = res;
});
}
});
this.add('model:menu_item', MenuItem);
this.addTemplate('special', '
{{model.id}}
');
this.addTemplate('loading', '
LOADING!
');
var visited = this.visit('/specials/1');
this.assertText('LOADING!', 'The app is in the loading state');
resolve(menuItem);
return visited.then(function () {
_this25.assertText('1', 'The app is now in the specials state');
});
};
_proto["@test The loading state doesn't get entered for promises that resolve on the same run loop"] = function (assert) {
var _this26 = this;
this.router.map(function () {
this.route('home', {
path: '/'
});
this.route('special', {
path: '/specials/:menu_item_id'
});
});
var MenuItem = _runtime.Object.extend();
MenuItem.reopenClass({
find: function (id) {
return {
id: id
};
}
});
this.add('model:menu_item', MenuItem);
this.add('route:loading', _routing.Route.extend({
enter: function () {
assert.ok(false, "LoadingRoute shouldn't have been entered.");
}
}));
this.addTemplate('special', '
{{model.id}}
');
this.addTemplate('loading', '
LOADING!
');
return this.visit('/specials/1').then(function () {
var text = _this26.$('p').text();
assert.equal(text, '1', 'The app is now in the specials state');
});
};
_proto["@test The Special page returning an error invokes SpecialRoute's error handler"] = function testTheSpecialPageReturningAnErrorInvokesSpecialRouteSErrorHandler(assert) {
this.router.map(function () {
this.route('home', {
path: '/'
});
this.route('special', {
path: '/specials/:menu_item_id'
});
});
var menuItem, promise, resolve;
var MenuItem = _runtime.Object.extend();
MenuItem.reopenClass({
find: function (id) {
menuItem = MenuItem.create({
id: id
});
promise = new _rsvp.default.Promise(function (res) {
return resolve = res;
});
return promise;
}
});
this.add('model:menu_item', MenuItem);
this.add('route:special', _routing.Route.extend({
setup: function () {
throw new Error('Setup error');
},
actions: {
error: function (reason) {
assert.equal(reason.message, 'Setup error', 'SpecialRoute#error received the error thrown from setup');
return true;
}
}
}));
this.handleURLRejectsWith(this, assert, 'specials/1', 'Setup error');
(0, _runloop.run)(function () {
return resolve(menuItem);
});
};
_proto["@test ApplicationRoute's default error handler can be overridden"] = function testApplicationRouteSDefaultErrorHandlerCanBeOverridden(assert) {
assert.expect(2);
this.router.map(function () {
this.route('home', {
path: '/'
});
this.route('special', {
path: '/specials/:menu_item_id'
});
});
var menuItem, resolve;
var MenuItem = _runtime.Object.extend();
MenuItem.reopenClass({
find: function (id) {
menuItem = MenuItem.create({
id: id
});
return new _rsvp.default.Promise(function (res) {
return resolve = res;
});
}
});
this.add('model:menu_item', MenuItem);
this.add('route:application', _routing.Route.extend({
actions: {
error: function (reason) {
assert.equal(reason.message, 'Setup error', 'error was correctly passed to custom ApplicationRoute handler');
return true;
}
}
}));
this.add('route:special', _routing.Route.extend({
setup: function () {
throw new Error('Setup error');
}
}));
this.handleURLRejectsWith(this, assert, '/specials/1', 'Setup error');
(0, _runloop.run)(function () {
return resolve(menuItem);
});
};
_proto['@test Moving from one page to another triggers the correct callbacks'] = function testMovingFromOnePageToAnotherTriggersTheCorrectCallbacks(assert) {
var _this27 = this;
assert.expect(3);
this.router.map(function () {
this.route('home', {
path: '/'
});
this.route('special', {
path: '/specials/:menu_item_id'
});
});
var MenuItem = _runtime.Object.extend();
MenuItem.reopenClass({
find: function (id) {
return MenuItem.create({
id: id
});
}
});
this.add('model:menu_item', MenuItem);
this.addTemplate('home', '
Home
');
this.addTemplate('special', '
{{model.id}}
');
return this.visit('/').then(function () {
_this27.assertText('Home', 'The app is now in the initial state');
var promiseContext = MenuItem.create({
id: 1
});
return _this27.visit('/specials/1', promiseContext);
}).then(function () {
assert.equal(_this27.currentURL, '/specials/1');
_this27.assertText('1', 'The app is now transitioned');
});
};
_proto['@test Nested callbacks are not exited when moving to siblings'] = function testNestedCallbacksAreNotExitedWhenMovingToSiblings(assert) {
var _this28 = this;
var rootSetup = 0;
var rootRender = 0;
var rootModel = 0;
var rootSerialize = 0;
var menuItem;
var rootElement;
var MenuItem = _runtime.Object.extend();
MenuItem.reopenClass({
find: function (id) {
menuItem = MenuItem.create({
id: id
});
return menuItem;
}
});
this.router.map(function () {
this.route('root', {
path: '/'
}, function () {
this.route('special', {
path: '/specials/:menu_item_id',
resetNamespace: true
});
});
});
this.add('route:root', _routing.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);
}
}));
this.add('route:loading', _routing.Route.extend({}));
this.add('route:home', _routing.Route.extend({}));
this.add('route:special', _routing.Route.extend({
model: function (_ref) {
var menu_item_id = _ref.menu_item_id;
return MenuItem.find(menu_item_id);
},
setupController: function (controller, model) {
(0, _metal.set)(controller, 'model', model);
}
}));
this.addTemplate('root.index', '
Home
');
this.addTemplate('special', '
{{model.id}}
');
this.addTemplate('loading', '
LOADING!
');
return this.visit('/').then(function () {
rootElement = document.getElementById('qunit-fixture');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('h3')), 'Home', 'The app is now in the initial state');
assert.equal(rootSetup, 1, 'The root setup was triggered');
assert.equal(rootRender, 1, 'The root render was triggered');
assert.equal(rootSerialize, 0, 'The root serialize was not called');
assert.equal(rootModel, 1, 'The root model was called');
var router = _this28.applicationInstance.lookup('router:main');
var menuItem = MenuItem.create({
id: 1
});
return router.transitionTo('special', menuItem).then(function () {
assert.equal(rootSetup, 1, 'The root setup was not triggered again');
assert.equal(rootRender, 1, 'The root render was not triggered again');
assert.equal(rootSerialize, 0, 'The root serialize was not called'); // TODO: Should this be changed?
assert.equal(rootModel, 1, 'The root model was called again');
assert.deepEqual(router.location.path, '/specials/1');
assert.equal(router.currentPath, 'root.special');
});
});
};
_proto['@test Events are triggered on the controller if a matching action name is implemented'] = function testEventsAreTriggeredOnTheControllerIfAMatchingActionNameIsImplemented(assert) {
var done = assert.async();
this.router.map(function () {
this.route('home', {
path: '/'
});
});
var model = {
name: 'Tom Dale'
};
var stateIsNotCalled = true;
this.add('route:home', _routing.Route.extend({
model: function () {
return model;
},
actions: {
showStuff: function () {
stateIsNotCalled = false;
}
}
}));
this.addTemplate('home', '{{name}}');
this.add('controller:home', _controller.default.extend({
actions: {
showStuff: function (context) {
assert.ok(stateIsNotCalled, 'an event on the state is not triggered');
assert.deepEqual(context, {
name: 'Tom Dale'
}, 'an event with context is passed');
done();
}
}
}));
this.visit('/').then(function () {
document.getElementById('qunit-fixture').querySelector('a').click();
});
};
_proto['@test Events are triggered on the current state when defined in `actions` object'] = function testEventsAreTriggeredOnTheCurrentStateWhenDefinedInActionsObject(assert) {
var done = assert.async();
this.router.map(function () {
this.route('home', {
path: '/'
});
});
var model = {
name: 'Tom Dale'
};
var HomeRoute = _routing.Route.extend({
model: function () {
return model;
},
actions: {
showStuff: function (obj) {
assert.ok(this instanceof HomeRoute, 'the handler is an App.HomeRoute');
assert.deepEqual((0, _polyfills.assign)({}, obj), {
name: 'Tom Dale'
}, 'the context is correct');
done();
}
}
});
this.add('route:home', HomeRoute);
this.addTemplate('home', '{{model.name}}');
this.visit('/').then(function () {
document.getElementById('qunit-fixture').querySelector('a').click();
});
};
_proto['@test Events defined in `actions` object are triggered on the current state when routes are nested'] = function testEventsDefinedInActionsObjectAreTriggeredOnTheCurrentStateWhenRoutesAreNested(assert) {
var done = assert.async();
this.router.map(function () {
this.route('root', {
path: '/'
}, function () {
this.route('index', {
path: '/'
});
});
});
var model = {
name: 'Tom Dale'
};
var RootRoute = _routing.Route.extend({
actions: {
showStuff: function (obj) {
assert.ok(this instanceof RootRoute, 'the handler is an App.HomeRoute');
assert.deepEqual((0, _polyfills.assign)({}, obj), {
name: 'Tom Dale'
}, 'the context is correct');
done();
}
}
});
this.add('route:root', RootRoute);
this.add('route:root.index', _routing.Route.extend({
model: function () {
return model;
}
}));
this.addTemplate('root.index', '{{model.name}}');
this.visit('/').then(function () {
document.getElementById('qunit-fixture').querySelector('a').click();
});
};
_proto['@test Events can be handled by inherited event handlers'] = function testEventsCanBeHandledByInheritedEventHandlers(assert) {
assert.expect(4);
var SuperRoute = _routing.Route.extend({
actions: {
foo: function () {
assert.ok(true, 'foo');
},
bar: function (msg) {
assert.equal(msg, 'HELLO', 'bar hander in super route');
}
}
});
var RouteMixin = _metal.Mixin.create({
actions: {
bar: function (msg) {
assert.equal(msg, 'HELLO', 'bar handler in mixin');
this._super(msg);
}
}
});
this.add('route:home', SuperRoute.extend(RouteMixin, {
actions: {
baz: function () {
assert.ok(true, 'baz', 'baz hander in route');
}
}
}));
this.addTemplate('home', "\n Do foo\n Do bar with arg\n Do bar\n ");
return this.visit('/').then(function () {
var rootElement = document.getElementById('qunit-fixture');
rootElement.querySelector('.do-foo').click();
rootElement.querySelector('.do-bar-with-arg').click();
rootElement.querySelector('.do-baz').click();
});
};
_proto['@test Actions are not triggered on the controller if a matching action name is implemented as a method'] = function testActionsAreNotTriggeredOnTheControllerIfAMatchingActionNameIsImplementedAsAMethod(assert) {
var done = assert.async();
this.router.map(function () {
this.route('home', {
path: '/'
});
});
var model = {
name: 'Tom Dale'
};
var stateIsNotCalled = true;
this.add('route:home', _routing.Route.extend({
model: function () {
return model;
},
actions: {
showStuff: function (context) {
assert.ok(stateIsNotCalled, 'an event on the state is not triggered');
assert.deepEqual(context, {
name: 'Tom Dale'
}, 'an event with context is passed');
done();
}
}
}));
this.addTemplate('home', '{{name}}');
this.add('controller:home', _controller.default.extend({
showStuff: function () {
stateIsNotCalled = false;
assert.ok(stateIsNotCalled, 'an event on the state is not triggered');
}
}));
this.visit('/').then(function () {
document.getElementById('qunit-fixture').querySelector('a').click();
});
};
_proto['@test actions can be triggered with multiple arguments'] = function testActionsCanBeTriggeredWithMultipleArguments(assert) {
var done = assert.async();
this.router.map(function () {
this.route('root', {
path: '/'
}, function () {
this.route('index', {
path: '/'
});
});
});
var model1 = {
name: 'Tilde'
};
var model2 = {
name: 'Tom Dale'
};
var RootRoute = _routing.Route.extend({
actions: {
showStuff: function (obj1, obj2) {
assert.ok(this instanceof RootRoute, 'the handler is an App.HomeRoute');
assert.deepEqual((0, _polyfills.assign)({}, obj1), {
name: 'Tilde'
}, 'the first context is correct');
assert.deepEqual((0, _polyfills.assign)({}, obj2), {
name: 'Tom Dale'
}, 'the second context is correct');
done();
}
}
});
this.add('route:root', RootRoute);
this.add('controller:root.index', _controller.default.extend({
model1: model1,
model2: model2
}));
this.addTemplate('root.index', '{{model1.name}}');
this.visit('/').then(function () {
document.getElementById('qunit-fixture').querySelector('a').click();
});
};
_proto['@test transitioning multiple times in a single run loop only sets the URL once'] = function testTransitioningMultipleTimesInASingleRunLoopOnlySetsTheURLOnce(assert) {
var _this29 = this;
this.router.map(function () {
this.route('root', {
path: '/'
});
this.route('foo');
this.route('bar');
});
return this.visit('/').then(function () {
var urlSetCount = 0;
var router = _this29.applicationInstance.lookup('router:main');
router.get('location').setURL = function (path) {
urlSetCount++;
(0, _metal.set)(this, 'path', path);
};
assert.equal(urlSetCount, 0);
(0, _runloop.run)(function () {
router.transitionTo('foo');
router.transitionTo('bar');
});
assert.equal(urlSetCount, 1);
assert.equal(router.get('location').getURL(), '/bar');
});
};
_proto['@test navigating away triggers a url property change'] = function testNavigatingAwayTriggersAUrlPropertyChange(assert) {
var _this30 = this;
assert.expect(3);
this.router.map(function () {
this.route('root', {
path: '/'
});
this.route('foo', {
path: '/foo'
});
this.route('bar', {
path: '/bar'
});
});
return this.visit('/').then(function () {
var router = _this30.applicationInstance.lookup('router:main');
(0, _metal.addObserver)(router, 'url', function () {
assert.ok(true, 'url change event was fired');
});
['foo', 'bar', '/foo'].forEach(function (destination) {
return (0, _runloop.run)(router, 'transitionTo', destination);
});
});
};
_proto['@test using replaceWith calls location.replaceURL if available'] = function testUsingReplaceWithCallsLocationReplaceURLIfAvailable(assert) {
var _this31 = this;
var setCount = 0;
var replaceCount = 0;
this.router.reopen({
location: _routing.NoneLocation.create({
setURL: function (path) {
setCount++;
(0, _metal.set)(this, 'path', path);
},
replaceURL: function (path) {
replaceCount++;
(0, _metal.set)(this, 'path', path);
}
})
});
this.router.map(function () {
this.route('root', {
path: '/'
});
this.route('foo');
});
return this.visit('/').then(function () {
var router = _this31.applicationInstance.lookup('router:main');
assert.equal(setCount, 1);
assert.equal(replaceCount, 0);
(0, _runloop.run)(function () {
return router.replaceWith('foo');
});
assert.equal(setCount, 1, 'should not call setURL');
assert.equal(replaceCount, 1, 'should call replaceURL once');
assert.equal(router.get('location').getURL(), '/foo');
});
};
_proto['@test using replaceWith calls setURL if location.replaceURL is not defined'] = function testUsingReplaceWithCallsSetURLIfLocationReplaceURLIsNotDefined(assert) {
var _this32 = this;
var setCount = 0;
this.router.reopen({
location: _routing.NoneLocation.create({
setURL: function (path) {
setCount++;
(0, _metal.set)(this, 'path', path);
}
})
});
this.router.map(function () {
this.route('root', {
path: '/'
});
this.route('foo');
});
return this.visit('/').then(function () {
var router = _this32.applicationInstance.lookup('router:main');
assert.equal(setCount, 1);
(0, _runloop.run)(function () {
return router.replaceWith('foo');
});
assert.equal(setCount, 2, 'should call setURL once');
assert.equal(router.get('location').getURL(), '/foo');
});
};
_proto['@test Route inherits model from parent route'] = function testRouteInheritsModelFromParentRoute(assert) {
var _this33 = this;
assert.expect(9);
this.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 post1 = {};
var post2 = {};
var post3 = {};
var share1 = {};
var share2 = {};
var share3 = {};
var posts = {
1: post1,
2: post2,
3: post3
};
var shares = {
1: share1,
2: share2,
3: share3
};
this.add('route:the-post', _routing.Route.extend({
model: function (params) {
return posts[params.post_id];
}
}));
this.add('route:the-post.comments', _routing.Route.extend({
afterModel: function (post
/*, transition */
) {
var parent_model = this.modelFor('the-post');
assert.equal(post, parent_model);
}
}));
this.add('route:shares', _routing.Route.extend({
model: function (params) {
return shares[params.share_id];
}
}));
this.add('route:shares.share', _routing.Route.extend({
afterModel: function (share
/*, transition */
) {
var parent_model = this.modelFor('shares');
assert.equal(share, parent_model);
}
}));
return this.visit('/posts/1/comments').then(function () {
assert.ok(true, 'url: /posts/1/comments was handled');
return _this33.visit('/posts/1/shares/1');
}).then(function () {
assert.ok(true, 'url: /posts/1/shares/1 was handled');
return _this33.visit('/posts/2/comments');
}).then(function () {
assert.ok(true, 'url: /posts/2/comments was handled');
return _this33.visit('/posts/2/shares/2');
}).then(function () {
assert.ok(true, 'url: /posts/2/shares/2 was handled');
return _this33.visit('/posts/3/comments');
}).then(function () {
assert.ok(true, 'url: /posts/3/shares was handled');
return _this33.visit('/posts/3/shares/3');
}).then(function () {
assert.ok(true, 'url: /posts/3/shares/3 was handled');
});
};
_proto['@test Routes with { resetNamespace: true } inherits model from parent route'] = function testRoutesWithResetNamespaceTrueInheritsModelFromParentRoute(assert) {
var _this34 = this;
assert.expect(6);
this.router.map(function () {
this.route('the-post', {
path: '/posts/:post_id'
}, function () {
this.route('comments', {
resetNamespace: true
}, function () {});
});
});
var post1 = {};
var post2 = {};
var post3 = {};
var posts = {
1: post1,
2: post2,
3: post3
};
this.add('route:the-post', _routing.Route.extend({
model: function (params) {
return posts[params.post_id];
}
}));
this.add('route:comments', _routing.Route.extend({
afterModel: function (post
/*, transition */
) {
var parent_model = this.modelFor('the-post');
assert.equal(post, parent_model);
}
}));
return this.visit('/posts/1/comments').then(function () {
assert.ok(true, '/posts/1/comments');
return _this34.visit('/posts/2/comments');
}).then(function () {
assert.ok(true, '/posts/2/comments');
return _this34.visit('/posts/3/comments');
}).then(function () {
assert.ok(true, '/posts/3/comments');
});
};
_proto['@test It is possible to get the model from a parent route'] = function testItIsPossibleToGetTheModelFromAParentRoute(assert) {
var _this35 = this;
assert.expect(6);
this.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;
var posts = {
1: post1,
2: post2,
3: post3
};
this.add('route:the-post', _routing.Route.extend({
model: function (params) {
return posts[params.post_id];
}
}));
this.add('route:comments', _routing.Route.extend({
model: function () {
assert.equal(this.modelFor('the-post'), currentPost);
}
}));
currentPost = post1;
return this.visit('/posts/1/comments').then(function () {
assert.ok(true, '/posts/1/comments has been handled');
currentPost = post2;
return _this35.visit('/posts/2/comments');
}).then(function () {
assert.ok(true, '/posts/2/comments has been handled');
currentPost = post3;
return _this35.visit('/posts/3/comments');
}).then(function () {
assert.ok(true, '/posts/3/comments has been handled');
});
};
_proto['@test A redirection hook is provided'] = function testARedirectionHookIsProvided(assert) {
var _this36 = this;
this.router.map(function () {
this.route('choose', {
path: '/'
});
this.route('home');
});
var chooseFollowed = 0;
var destination = 'home';
this.add('route:choose', _routing.Route.extend({
redirect: function () {
if (destination) {
this.transitionTo(destination);
}
},
setupController: function () {
chooseFollowed++;
}
}));
return this.visit('/').then(function () {
var rootElement = document.getElementById('qunit-fixture');
assert.equal(chooseFollowed, 0, "The choose route wasn't entered since a transition occurred");
assert.equal(rootElement.querySelectorAll('h3.hours').length, 1, 'The home template was rendered');
assert.equal(_this36.applicationInstance.lookup('controller:application').get('currentPath'), 'home');
});
};
_proto['@test Redirecting from the middle of a route aborts the remainder of the routes'] = function testRedirectingFromTheMiddleOfARouteAbortsTheRemainderOfTheRoutes(assert) {
var _this37 = this;
assert.expect(3);
this.router.map(function () {
this.route('home');
this.route('foo', function () {
this.route('bar', {
resetNamespace: true
}, function () {
this.route('baz');
});
});
});
this.add('route:bar', _routing.Route.extend({
redirect: function () {
this.transitionTo('home');
},
setupController: function () {
assert.ok(false, 'Should transition before setupController');
}
}));
this.add('route:bar-baz', _routing.Route.extend({
enter: function () {
assert.ok(false, 'Should abort transition getting to next route');
}
}));
return this.visit('/').then(function () {
var router = _this37.applicationInstance.lookup('router:main');
_this37.handleURLAborts(assert, '/foo/bar/baz');
assert.equal(_this37.applicationInstance.lookup('controller:application').get('currentPath'), 'home');
assert.equal(router.get('location').getURL(), '/home');
});
};
_proto['@test Redirecting to the current target in the middle of a route does not abort initial routing'] = function testRedirectingToTheCurrentTargetInTheMiddleOfARouteDoesNotAbortInitialRouting(assert) {
var _this38 = this;
assert.expect(5);
this.router.map(function () {
this.route('home');
this.route('foo', function () {
this.route('bar', {
resetNamespace: true
}, function () {
this.route('baz');
});
});
});
var successCount = 0;
this.add('route:bar', _routing.Route.extend({
redirect: function () {
return this.transitionTo('bar.baz').then(function () {
successCount++;
});
},
setupController: function () {
assert.ok(true, "Should still invoke bar's setupController");
}
}));
this.add('route:bar.baz', _routing.Route.extend({
setupController: function () {
assert.ok(true, "Should still invoke bar.baz's setupController");
}
}));
return this.visit('/foo/bar/baz').then(function () {
assert.ok(true, '/foo/bar/baz has been handled');
assert.equal(_this38.applicationInstance.lookup('controller:application').get('currentPath'), 'foo.bar.baz');
assert.equal(successCount, 1, 'transitionTo success handler was called once');
});
};
_proto['@test Redirecting to the current target with a different context aborts the remainder of the routes'] = function testRedirectingToTheCurrentTargetWithADifferentContextAbortsTheRemainderOfTheRoutes(assert) {
var _this39 = this;
assert.expect(4);
this.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;
this.add('route:bar', _routing.Route.extend({
afterModel: function () {
if (count++ > 10) {
assert.ok(false, 'infinite loop');
} else {
this.transitionTo('bar.baz', model);
}
}
}));
this.add('route:bar.baz', _routing.Route.extend({
setupController: function () {
assert.ok(true, 'Should still invoke setupController');
}
}));
return this.visit('/').then(function () {
_this39.handleURLAborts(assert, '/foo/bar/1/baz');
assert.equal(_this39.applicationInstance.lookup('controller:application').get('currentPath'), 'foo.bar.baz');
assert.equal(_this39.applicationInstance.lookup('router:main').get('location').getURL(), '/foo/bar/2/baz');
});
};
_proto['@test Transitioning from a parent event does not prevent currentPath from being set'] = function testTransitioningFromAParentEventDoesNotPreventCurrentPathFromBeingSet(assert) {
var _this40 = this;
this.router.map(function () {
this.route('foo', function () {
this.route('bar', {
resetNamespace: true
}, function () {
this.route('baz');
});
this.route('qux');
});
});
this.add('route:foo', _routing.Route.extend({
actions: {
goToQux: function () {
this.transitionTo('foo.qux');
}
}
}));
return this.visit('/foo/bar/baz').then(function () {
assert.ok(true, '/foo/bar/baz has been handled');
var applicationController = _this40.applicationInstance.lookup('controller:application');
var router = _this40.applicationInstance.lookup('router:main');
assert.equal(applicationController.get('currentPath'), 'foo.bar.baz');
(0, _runloop.run)(function () {
return router.send('goToQux');
});
assert.equal(applicationController.get('currentPath'), 'foo.qux');
assert.equal(router.get('location').getURL(), '/foo/qux');
});
};
_proto['@test Generated names can be customized when providing routes with dot notation'] = function testGeneratedNamesCanBeCustomizedWhenProvidingRoutesWithDotNotation(assert) {
assert.expect(4);
this.addTemplate('index', '
Index
');
this.addTemplate('application', "
Home
{{outlet}}
");
this.addTemplate('foo', "
{{outlet}}
");
this.addTemplate('bar', "
{{outlet}}
");
this.addTemplate('bar.baz', '
{{name}}Bottom!
');
this.router.map(function () {
this.route('foo', {
path: '/top'
}, function () {
this.route('bar', {
path: '/middle',
resetNamespace: true
}, function () {
this.route('baz', {
path: '/bottom'
});
});
});
});
this.add('route:foo', _routing.Route.extend({
renderTemplate: function () {
assert.ok(true, 'FooBarRoute was called');
return this._super.apply(this, arguments);
}
}));
this.add('route:bar.baz', _routing.Route.extend({
renderTemplate: function () {
assert.ok(true, 'BarBazRoute was called');
return this._super.apply(this, arguments);
}
}));
this.add('controller:bar', _controller.default.extend({
name: 'Bar'
}));
this.add('controller:bar.baz', _controller.default.extend({
name: 'BarBaz'
}));
return this.visit('/top/middle/bottom').then(function () {
assert.ok(true, '/top/middle/bottom has been handled');
var rootElement = document.getElementById('qunit-fixture');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('.main .middle .bottom p')), 'BarBazBottom!', 'The templates were rendered into their appropriate parents');
});
};
_proto["@test Child routes render into their parent route's template by default"] = function testChildRoutesRenderIntoTheirParentRouteSTemplateByDefault(assert) {
this.addTemplate('index', '
Index
');
this.addTemplate('application', "
Home
{{outlet}}
");
this.addTemplate('top', "
{{outlet}}
");
this.addTemplate('middle', "
{{outlet}}
");
this.addTemplate('middle.bottom', '
Bottom!
');
this.router.map(function () {
this.route('top', function () {
this.route('middle', {
resetNamespace: true
}, function () {
this.route('bottom');
});
});
});
return this.visit('/top/middle/bottom').then(function () {
assert.ok(true, '/top/middle/bottom has been handled');
var rootElement = document.getElementById('qunit-fixture');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('.main .middle .bottom p')), 'Bottom!', 'The templates were rendered into their appropriate parents');
});
};
_proto['@test Child routes render into specified template'] = function testChildRoutesRenderIntoSpecifiedTemplate(assert) {
this.addTemplate('index', '
Index
');
this.addTemplate('application', "
Home
{{outlet}}
");
this.addTemplate('top', "
{{outlet}}
");
this.addTemplate('middle', "
{{outlet}}
");
this.addTemplate('middle.bottom', '
Bottom!
');
this.router.map(function () {
this.route('top', function () {
this.route('middle', {
resetNamespace: true
}, function () {
this.route('bottom');
});
});
});
this.add('route:middle.bottom', _routing.Route.extend({
renderTemplate: function () {
this.render('middle/bottom', {
into: 'top'
});
}
}));
return this.visit('/top/middle/bottom').then(function () {
assert.ok(true, '/top/middle/bottom has been handled');
var rootElement = document.getElementById('qunit-fixture');
assert.equal(rootElement.querySelectorAll('.main .middle .bottom p').length, 0, 'should not render into the middle template');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('.main .middle > p')), 'Bottom!', 'The template was rendered into the top template');
});
};
_proto['@test Rendering into specified template with slash notation'] = function testRenderingIntoSpecifiedTemplateWithSlashNotation(assert) {
this.addTemplate('person.profile', 'profile {{outlet}}');
this.addTemplate('person.details', 'details!');
this.router.map(function () {
this.route('home', {
path: '/'
});
});
this.add('route:home', _routing.Route.extend({
renderTemplate: function () {
this.render('person/profile');
this.render('person/details', {
into: 'person/profile'
});
}
}));
return this.visit('/').then(function () {
var rootElement = document.getElementById('qunit-fixture');
assert.equal(rootElement.textContent.trim(), 'profile details!', 'The templates were rendered');
});
};
_proto['@test Parent route context change'] = function testParentRouteContextChange(assert) {
var _this41 = this;
var editCount = 0;
var editedPostIds = (0, _runtime.A)();
this.addTemplate('application', '{{outlet}}');
this.addTemplate('posts', '{{outlet}}');
this.addTemplate('post', '{{outlet}}');
this.addTemplate('post/index', 'showing');
this.addTemplate('post/edit', 'editing');
this.router.map(function () {
this.route('posts', function () {
this.route('post', {
path: '/:postId',
resetNamespace: true
}, function () {
this.route('edit');
});
});
});
this.add('route:posts', _routing.Route.extend({
actions: {
showPost: function (context) {
this.transitionTo('post', context);
}
}
}));
this.add('route:post', _routing.Route.extend({
model: function (params) {
return {
id: params.postId
};
},
serialize: function (model) {
return {
postId: model.id
};
},
actions: {
editPost: function () {
this.transitionTo('post.edit');
}
}
}));
this.add('route:post.edit', _routing.Route.extend({
model: function () {
var postId = this.modelFor('post').id;
editedPostIds.push(postId);
return null;
},
setup: function () {
this._super.apply(this, arguments);
editCount++;
}
}));
return this.visit('/posts/1').then(function () {
assert.ok(true, '/posts/1 has been handled');
var router = _this41.applicationInstance.lookup('router:main');
(0, _runloop.run)(function () {
return router.send('editPost');
});
(0, _runloop.run)(function () {
return router.send('showPost', {
id: '2'
});
});
(0, _runloop.run)(function () {
return router.send('editPost');
});
assert.equal(editCount, 2, 'set up the edit route twice without failure');
assert.deepEqual(editedPostIds, ['1', '2'], 'modelFor posts.post returns the right context');
});
};
_proto['@test Router accounts for rootURL on page load when using history location'] = function testRouterAccountsForRootURLOnPageLoadWhenUsingHistoryLocation(assert) {
var rootURL = window.location.pathname + '/app';
var postsTemplateRendered = false;
var setHistory;
setHistory = function (obj, path) {
obj.set('history', {
state: {
path: path
}
});
};
var location = _routing.HistoryLocation.create({
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);
}
});
this.router.reopen({
// location: 'historyTest',
location: location,
rootURL: rootURL
});
this.router.map(function () {
this.route('posts', {
path: '/posts'
});
});
this.add('route:posts', _routing.Route.extend({
model: function () {},
renderTemplate: function () {
postsTemplateRendered = true;
}
}));
return this.visit('/').then(function () {
assert.ok(postsTemplateRendered, 'Posts route successfully stripped from rootURL');
(0, _internalTestHelpers.runDestroy)(location);
location = null;
});
};
_proto['@test The rootURL is passed properly to the location implementation'] = function testTheRootURLIsPassedProperlyToTheLocationImplementation(assert) {
assert.expect(1);
var rootURL = '/blahzorz';
this.add('location:history-test', _routing.HistoryLocation.extend({
rootURL: 'this is not the URL you are looking for',
history: {
pushState: function () {}
},
initState: function () {
assert.equal(this.get('rootURL'), rootURL);
}
}));
this.router.reopen({
location: 'history-test',
rootURL: rootURL,
// if we transition in this test we will receive failures
// if the tests are run from a static file
_doURLTransition: function () {
return _rsvp.default.resolve('');
}
});
return this.visit('/');
};
_proto['@test Only use route rendered into main outlet for default into property on child'] = function testOnlyUseRouteRenderedIntoMainOutletForDefaultIntoPropertyOnChild(assert) {
this.addTemplate('application', "{{outlet 'menu'}}{{outlet}}");
this.addTemplate('posts', '{{outlet}}');
this.addTemplate('posts.index', '
postsIndex
');
this.addTemplate('posts.menu', '
postsMenu
');
this.router.map(function () {
this.route('posts', function () {});
});
this.add('route:posts', _routing.Route.extend({
renderTemplate: function () {
this.render();
this.render('posts/menu', {
into: 'application',
outlet: 'menu'
});
}
}));
return this.visit('/posts').then(function () {
assert.ok(true, '/posts has been handled');
var rootElement = document.getElementById('qunit-fixture');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('div.posts-menu')), 'postsMenu', 'The posts/menu template was rendered');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('p.posts-index')), 'postsIndex', 'The posts/index template was rendered');
});
};
_proto['@test Generating a URL should not affect currentModel'] = function testGeneratingAURLShouldNotAffectCurrentModel(assert) {
var _this42 = this;
this.router.map(function () {
this.route('post', {
path: '/posts/:post_id'
});
});
var posts = {
1: {
id: 1
},
2: {
id: 2
}
};
this.add('route:post', _routing.Route.extend({
model: function (params) {
return posts[params.post_id];
}
}));
return this.visit('/posts/1').then(function () {
assert.ok(true, '/posts/1 has been handled');
var route = _this42.applicationInstance.lookup('route:post');
assert.equal(route.modelFor('post'), posts[1]);
var url = _this42.applicationInstance.lookup('router:main').generate('post', posts[2]);
assert.equal(url, '/posts/2');
assert.equal(route.modelFor('post'), posts[1]);
});
};
_proto["@test Nested index route is not overridden by parent's implicit index route"] = function testNestedIndexRouteIsNotOverriddenByParentSImplicitIndexRoute(assert) {
var _this43 = this;
this.router.map(function () {
this.route('posts', function () {
this.route('index', {
path: ':category'
});
});
});
return this.visit('/').then(function () {
var router = _this43.applicationInstance.lookup('router:main');
return router.transitionTo('posts', {
category: 'emberjs'
});
}).then(function () {
var router = _this43.applicationInstance.lookup('router:main');
assert.deepEqual(router.location.path, '/posts/emberjs');
});
};
_proto['@test Application template does not duplicate when re-rendered'] = function testApplicationTemplateDoesNotDuplicateWhenReRendered(assert) {
this.addTemplate('application', '
I render once
{{outlet}}');
this.router.map(function () {
this.route('posts');
});
this.add('route:application', _routing.Route.extend({
model: function () {
return (0, _runtime.A)();
}
}));
return this.visit('/posts').then(function () {
assert.ok(true, '/posts has been handled');
var rootElement = document.getElementById('qunit-fixture');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('h3.render-once')), 'I render once');
});
};
_proto['@test Child routes should render inside the application template if the application template causes a redirect'] = function testChildRoutesShouldRenderInsideTheApplicationTemplateIfTheApplicationTemplateCausesARedirect(assert) {
this.addTemplate('application', '
App
{{outlet}}');
this.addTemplate('posts', 'posts');
this.router.map(function () {
this.route('posts');
this.route('photos');
});
this.add('route:application', _routing.Route.extend({
afterModel: function () {
this.transitionTo('posts');
}
}));
return this.visit('/posts').then(function () {
var rootElement = document.getElementById('qunit-fixture');
assert.equal(rootElement.textContent.trim(), 'App posts');
});
};
_proto["@test The template is not re-rendered when the route's context changes"] = function testTheTemplateIsNotReRenderedWhenTheRouteSContextChanges(assert) {
var _this44 = this;
this.router.map(function () {
this.route('page', {
path: '/page/:name'
});
});
this.add('route:page', _routing.Route.extend({
model: function (params) {
return _runtime.Object.create({
name: params.name
});
}
}));
var insertionCount = 0;
this.add('component:foo-bar', _glimmer.Component.extend({
didInsertElement: function () {
insertionCount += 1;
}
}));
this.addTemplate('page', '
{{model.name}}{{foo-bar}}
');
var rootElement = document.getElementById('qunit-fixture');
return this.visit('/page/first').then(function () {
assert.ok(true, '/page/first has been handled');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('p')), 'first');
assert.equal(insertionCount, 1);
return _this44.visit('/page/second');
}).then(function () {
assert.ok(true, '/page/second has been handled');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('p')), 'second');
assert.equal(insertionCount, 1, 'view should have inserted only once');
var router = _this44.applicationInstance.lookup('router:main');
return (0, _runloop.run)(function () {
return router.transitionTo('page', _runtime.Object.create({
name: 'third'
}));
});
}).then(function () {
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('p')), 'third');
assert.equal(insertionCount, 1, 'view should still have inserted only once');
});
};
_proto['@test The template is not re-rendered when two routes present the exact same template & controller'] = function testTheTemplateIsNotReRenderedWhenTwoRoutesPresentTheExactSameTemplateController(assert) {
var _this45 = this;
this.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;
this.add('component:x-input', _glimmer.Component.extend({
didInsertElement: function () {
insertionCount += 1;
}
}));
var SharedRoute = _routing.Route.extend({
setupController: function () {
this.controllerFor('shared').set('message', 'This is the ' + this.routeName + ' message');
},
renderTemplate: function () {
this.render('shared', {
controller: 'shared'
});
}
});
this.add('route:shared', SharedRoute);
this.add('route:first', SharedRoute.extend());
this.add('route:second', SharedRoute.extend());
this.add('route:third', SharedRoute.extend());
this.add('route:fourth', SharedRoute.extend());
this.add('controller:shared', _controller.default.extend());
this.addTemplate('shared', '
{{message}}{{x-input}}
');
var rootElement = document.getElementById('qunit-fixture');
return this.visit('/first').then(function () {
assert.ok(true, '/first has been handled');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('p')), 'This is the first message');
assert.equal(insertionCount, 1, 'expected one assertion');
return _this45.visit('/second');
}).then(function () {
assert.ok(true, '/second has been handled');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('p')), 'This is the second message');
assert.equal(insertionCount, 1, 'expected one assertion');
return (0, _runloop.run)(function () {
_this45.applicationInstance.lookup('router:main').transitionTo('third').then(function () {
assert.ok(true, 'expected transition');
}, function (reason) {
assert.ok(false, 'unexpected transition failure: ', QUnit.jsDump.parse(reason));
});
});
}).then(function () {
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('p')), 'This is the third message');
assert.equal(insertionCount, 1, 'expected one assertion');
return _this45.visit('fourth');
}).then(function () {
assert.ok(true, '/fourth has been handled');
assert.equal(insertionCount, 1, 'expected one assertion');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('p')), 'This is the fourth message');
});
};
_proto['@test ApplicationRoute with model does not proxy the currentPath'] = function testApplicationRouteWithModelDoesNotProxyTheCurrentPath(assert) {
var model = {};
var currentPath;
this.router.map(function () {
this.route('index', {
path: '/'
});
});
this.add('route:application', _routing.Route.extend({
model: function () {
return model;
}
}));
this.add('controller:application', _controller.default.extend({
currentPathDidChange: (0, _metal.observer)('currentPath', function () {
currentPath = this.currentPath;
})
}));
return this.visit('/').then(function () {
assert.equal(currentPath, 'index', 'currentPath is index');
assert.equal('currentPath' in model, false, 'should have defined currentPath on controller');
});
};
_proto['@test Promises encountered on app load put app into loading state until resolved'] = function testPromisesEncounteredOnAppLoadPutAppIntoLoadingStateUntilResolved(assert) {
var _this46 = this;
assert.expect(2);
var deferred = _rsvp.default.defer();
this.router.map(function () {
this.route('index', {
path: '/'
});
});
this.add('route:index', _routing.Route.extend({
model: function () {
return deferred.promise;
}
}));
this.addTemplate('index', '
INDEX
');
this.addTemplate('loading', '
LOADING
');
(0, _runloop.run)(function () {
return _this46.visit('/');
});
var rootElement = document.getElementById('qunit-fixture');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('p')), 'LOADING', 'The loading state is displaying.');
(0, _runloop.run)(deferred.resolve);
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('p')), 'INDEX', 'The index route is display.');
};
_proto['@test Route should tear down multiple outlets'] = function testRouteShouldTearDownMultipleOutlets(assert) {
var _this47 = this;
this.addTemplate('application', "{{outlet 'menu'}}{{outlet}}{{outlet 'footer'}}");
this.addTemplate('posts', '{{outlet}}');
this.addTemplate('users', 'users');
this.addTemplate('posts.index', '
postsIndex
');
this.addTemplate('posts.menu', '
postsMenu
');
this.addTemplate('posts.footer', '');
this.router.map(function () {
this.route('posts', function () {});
this.route('users', function () {});
});
this.add('route:posts', _routing.Route.extend({
renderTemplate: function () {
this.render('posts/menu', {
into: 'application',
outlet: 'menu'
});
this.render();
this.render('posts/footer', {
into: 'application',
outlet: 'footer'
});
}
}));
var rootElement = document.getElementById('qunit-fixture');
return this.visit('/posts').then(function () {
assert.ok(true, '/posts has been handled');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('div.posts-menu')), 'postsMenu', 'The posts/menu template was rendered');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('p.posts-index')), 'postsIndex', 'The posts/index template was rendered');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('div.posts-footer')), 'postsFooter', 'The posts/footer template was rendered');
return _this47.visit('/users');
}).then(function () {
assert.ok(true, '/users has been handled');
assert.equal(rootElement.querySelector('div.posts-menu'), null, 'The posts/menu template was removed');
assert.equal(rootElement.querySelector('p.posts-index'), null, 'The posts/index template was removed');
assert.equal(rootElement.querySelector('div.posts-footer'), null, 'The posts/footer template was removed');
});
};
_proto['@test Route supports clearing outlet explicitly'] = function testRouteSupportsClearingOutletExplicitly(assert) {
var _this48 = this;
this.addTemplate('application', "{{outlet}}{{outlet 'modal'}}");
this.addTemplate('posts', '{{outlet}}');
this.addTemplate('users', 'users');
this.addTemplate('posts.index', '
postsIndex {{outlet}}
');
this.addTemplate('posts.modal', '
postsModal
');
this.addTemplate('posts.extra', '
postsExtra
');
this.router.map(function () {
this.route('posts', function () {});
this.route('users', function () {});
});
this.add('route:posts', _routing.Route.extend({
actions: {
showModal: function () {
this.render('posts/modal', {
into: 'application',
outlet: 'modal'
});
},
hideModal: function () {
this.disconnectOutlet({
outlet: 'modal',
parentView: 'application'
});
}
}
}));
this.add('route:posts.index', _routing.Route.extend({
actions: {
showExtra: function () {
this.render('posts/extra', {
into: 'posts/index'
});
},
hideExtra: function () {
this.disconnectOutlet({
parentView: 'posts/index'
});
}
}
}));
var rootElement = document.getElementById('qunit-fixture');
return this.visit('/posts').then(function () {
var router = _this48.applicationInstance.lookup('router:main');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('div.posts-index')), 'postsIndex', 'The posts/index template was rendered');
(0, _runloop.run)(function () {
return router.send('showModal');
});
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('div.posts-modal')), 'postsModal', 'The posts/modal template was rendered');
(0, _runloop.run)(function () {
return router.send('showExtra');
});
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('div.posts-extra')), 'postsExtra', 'The posts/extra template was rendered');
(0, _runloop.run)(function () {
return router.send('hideModal');
});
assert.equal(rootElement.querySelector('div.posts-modal'), null, 'The posts/modal template was removed');
(0, _runloop.run)(function () {
return router.send('hideExtra');
});
assert.equal(rootElement.querySelector('div.posts-extra'), null, 'The posts/extra template was removed');
(0, _runloop.run)(function () {
router.send('showModal');
});
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('div.posts-modal')), 'postsModal', 'The posts/modal template was rendered');
(0, _runloop.run)(function () {
router.send('showExtra');
});
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('div.posts-extra')), 'postsExtra', 'The posts/extra template was rendered');
return _this48.visit('/users');
}).then(function () {
assert.equal(rootElement.querySelector('div.posts-index'), null, 'The posts/index template was removed');
assert.equal(rootElement.querySelector('div.posts-modal'), null, 'The posts/modal template was removed');
assert.equal(rootElement.querySelector('div.posts-extra'), null, 'The posts/extra template was removed');
});
};
_proto['@test Route supports clearing outlet using string parameter'] = function testRouteSupportsClearingOutletUsingStringParameter(assert) {
var _this49 = this;
this.addTemplate('application', "{{outlet}}{{outlet 'modal'}}");
this.addTemplate('posts', '{{outlet}}');
this.addTemplate('users', 'users');
this.addTemplate('posts.index', '
postsIndex {{outlet}}
');
this.addTemplate('posts.modal', '
postsModal
');
this.router.map(function () {
this.route('posts', function () {});
this.route('users', function () {});
});
this.add('route:posts', _routing.Route.extend({
actions: {
showModal: function () {
this.render('posts/modal', {
into: 'application',
outlet: 'modal'
});
},
hideModal: function () {
this.disconnectOutlet('modal');
}
}
}));
var rootElement = document.getElementById('qunit-fixture');
return this.visit('/posts').then(function () {
var router = _this49.applicationInstance.lookup('router:main');
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('div.posts-index')), 'postsIndex', 'The posts/index template was rendered');
(0, _runloop.run)(function () {
return router.send('showModal');
});
assert.equal((0, _internalTestHelpers.getTextOf)(rootElement.querySelector('div.posts-modal')), 'postsModal', 'The posts/modal template was rendered');
(0, _runloop.run)(function () {
return router.send('hideModal');
});
assert.equal(rootElement.querySelector('div.posts-modal'), null, 'The posts/modal template was removed');
return _this49.visit('/users');
}).then(function () {
assert.equal(rootElement.querySelector('div.posts-index'), null, 'The posts/index template was removed');
assert.equal(rootElement.querySelector('div.posts-modal'), null, 'The posts/modal template was removed');
});
};
_proto['@test Route silently fails when cleaning an outlet from an inactive view'] = function testRouteSilentlyFailsWhenCleaningAnOutletFromAnInactiveView(assert) {
var _this50 = this;
assert.expect(1); // handleURL
this.addTemplate('application', '{{outlet}}');
this.addTemplate('posts', "{{outlet 'modal'}}");
this.addTemplate('modal', 'A Yo.');
this.router.map(function () {
this.route('posts');
});
this.add('route:posts', _routing.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'
});
}
}
}));
return this.visit('/posts').then(function () {
assert.ok(true, '/posts has been handled');
var router = _this50.applicationInstance.lookup('router:main');
(0, _runloop.run)(function () {
return router.send('showModal');
});
(0, _runloop.run)(function () {
return router.send('hideSelf');
});
(0, _runloop.run)(function () {
return router.send('hideModal');
});
});
};
_proto['@test Router `willTransition` hook passes in cancellable transition'] = function testRouterWillTransitionHookPassesInCancellableTransition(assert) {
var _this51 = this;
assert.expect(8);
this.router.reopen({
willTransition: function (_, _2, transition) {
assert.ok(true, 'willTransition was called');
if (transition.intent.url !== '/') {
transition.abort();
}
}
});
this.router.map(function () {
this.route('nork');
this.route('about');
});
this.add('route:loading', _routing.Route.extend({
activate: function () {
assert.ok(false, 'LoadingRoute was not entered');
}
}));
this.add('route:nork', _routing.Route.extend({
activate: function () {
assert.ok(false, 'NorkRoute was not entered');
}
}));
this.add('route:about', _routing.Route.extend({
activate: function () {
assert.ok(false, 'AboutRoute was not entered');
}
}));
var deprecation = /You attempted to override the "willTransition" method which is deprecated\./;
return expectDeprecation(function () {
return _this51.visit('/').then(function () {
_this51.handleURLAborts(assert, '/nork', deprecation);
_this51.handleURLAborts(assert, '/about', deprecation);
});
}, deprecation);
};
_proto['@test Aborting/redirecting the transition in `willTransition` prevents LoadingRoute from being entered'] = function testAbortingRedirectingTheTransitionInWillTransitionPreventsLoadingRouteFromBeingEntered(assert) {
var _this52 = this;
assert.expect(5);
this.router.map(function () {
this.route('index');
this.route('nork');
this.route('about');
});
var redirect = false;
this.add('route:index', _routing.Route.extend({
actions: {
willTransition: function (transition) {
assert.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;
this.add('route:loading', _routing.Route.extend({
activate: function () {
assert.ok(deferred, 'LoadingRoute should be entered at this time');
},
deactivate: function () {
assert.ok(true, 'LoadingRoute was exited');
}
}));
this.add('route:nork', _routing.Route.extend({
activate: function () {
assert.ok(true, 'NorkRoute was entered');
}
}));
this.add('route:about', _routing.Route.extend({
activate: function () {
assert.ok(true, 'AboutRoute was entered');
},
model: function () {
if (deferred) {
return deferred.promise;
}
}
}));
return this.visit('/').then(function () {
var router = _this52.applicationInstance.lookup('router:main'); // Attempted transitions out of index should abort.
(0, _runloop.run)(router, 'transitionTo', 'nork');
(0, _runloop.run)(router, 'handleURL', '/nork'); // Attempted transitions out of index should redirect to about
redirect = true;
(0, _runloop.run)(router, 'transitionTo', 'nork');
(0, _runloop.run)(router, 'transitionTo', 'index'); // Redirected transitions out of index to a route with a
// promise model should pause the transition and
// activate LoadingRoute
deferred = _rsvp.default.defer();
(0, _runloop.run)(router, 'transitionTo', 'nork');
(0, _runloop.run)(deferred.resolve);
});
};
_proto['@test `didTransition` event fires on the router'] = function testDidTransitionEventFiresOnTheRouter(assert) {
var _this53 = this;
assert.expect(3);
this.router.map(function () {
this.route('nork');
});
return this.visit('/').then(function () {
var router = _this53.applicationInstance.lookup('router:main');
router.one('didTransition', function () {
assert.ok(true, 'didTransition fired on initial routing');
});
_this53.visit('/');
}).then(function () {
var router = _this53.applicationInstance.lookup('router:main');
router.one('didTransition', function () {
assert.ok(true, 'didTransition fired on the router');
assert.equal(router.get('url'), '/nork', 'The url property is updated by the time didTransition fires');
});
return _this53.visit('/nork');
});
};
_proto['@test `didTransition` can be reopened'] = function testDidTransitionCanBeReopened(assert) {
assert.expect(1);
this.router.map(function () {
this.route('nork');
});
if (true
/* EMBER_ROUTING_ROUTER_SERVICE */
) {
assert.ok(true, 'no longer a valid test');
return;
} else {
this.router.reopen({
didTransition: function () {
this._super.apply(this, arguments);
assert.ok(true, 'reopened didTransition was called');
}
});
}
return this.visit('/');
};
_proto['@test `activate` event fires on the route'] = function testActivateEventFiresOnTheRoute(assert) {
assert.expect(2);
var eventFired = 0;
this.router.map(function () {
this.route('nork');
});
this.add('route:nork', _routing.Route.extend({
init: function () {
this._super.apply(this, arguments);
this.on('activate', function () {
assert.equal(++eventFired, 1, 'activate event is fired once');
});
},
activate: function () {
assert.ok(true, 'activate hook is called');
}
}));
return this.visit('/nork');
};
_proto['@test `deactivate` event fires on the route'] = function testDeactivateEventFiresOnTheRoute(assert) {
var _this54 = this;
assert.expect(2);
var eventFired = 0;
this.router.map(function () {
this.route('nork');
this.route('dork');
});
this.add('route:nork', _routing.Route.extend({
init: function () {
this._super.apply(this, arguments);
this.on('deactivate', function () {
assert.equal(++eventFired, 1, 'deactivate event is fired once');
});
},
deactivate: function () {
assert.ok(true, 'deactivate hook is called');
}
}));
return this.visit('/nork').then(function () {
return _this54.visit('/dork');
});
};
_proto['@test Actions can be handled by inherited action handlers'] = function testActionsCanBeHandledByInheritedActionHandlers(assert) {
assert.expect(4);
var SuperRoute = _routing.Route.extend({
actions: {
foo: function () {
assert.ok(true, 'foo');
},
bar: function (msg) {
assert.equal(msg, 'HELLO');
}
}
});
var RouteMixin = _metal.Mixin.create({
actions: {
bar: function (msg) {
assert.equal(msg, 'HELLO');
this._super(msg);
}
}
});
this.add('route:home', SuperRoute.extend(RouteMixin, {
actions: {
baz: function () {
assert.ok(true, 'baz');
}
}
}));
this.addTemplate('home', "\n Do foo\n Do bar with arg\n Do bar\n ");
return this.visit('/').then(function () {
var rootElement = document.getElementById('qunit-fixture');
rootElement.querySelector('.do-foo').click();
rootElement.querySelector('.do-bar-with-arg').click();
rootElement.querySelector('.do-baz').click();
});
};
_proto['@test transitionTo returns Transition when passed a route name'] = function testTransitionToReturnsTransitionWhenPassedARouteName(assert) {
var _this55 = this;
assert.expect(1);
this.router.map(function () {
this.route('root', {
path: '/'
});
this.route('bar');
});
return this.visit('/').then(function () {
var router = _this55.applicationInstance.lookup('router:main');
var transition = (0, _runloop.run)(function () {
return router.transitionTo('bar');
});
assert.equal(transition instanceof _router_js.InternalTransition, true);
});
};
_proto['@test transitionTo returns Transition when passed a url'] = function testTransitionToReturnsTransitionWhenPassedAUrl(assert) {
var _this56 = this;
assert.expect(1);
this.router.map(function () {
this.route('root', {
path: '/'
});
this.route('bar', function () {
this.route('baz');
});
});
return this.visit('/').then(function () {
var router = _this56.applicationInstance.lookup('router:main');
var transition = (0, _runloop.run)(function () {
return router.transitionTo('/bar/baz');
});
assert.equal(transition instanceof _router_js.InternalTransition, true);
});
};
_proto['@test currentRouteName is a property installed on ApplicationController that can be used in transitionTo'] = function testCurrentRouteNameIsAPropertyInstalledOnApplicationControllerThatCanBeUsedInTransitionTo(assert) {
var _this57 = this;
assert.expect(24);
this.router.map(function () {
this.route('index', {
path: '/'
});
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');
});
});
});
});
});
return this.visit('/').then(function () {
var appController = _this57.applicationInstance.lookup('controller:application');
var router = _this57.applicationInstance.lookup('router:main');
function transitionAndCheck(path, expectedPath, expectedRouteName) {
if (path) {
(0, _runloop.run)(router, 'transitionTo', path);
}
assert.equal(appController.get('currentPath'), expectedPath);
assert.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');
});
};
_proto['@test Route model hook finds the same model as a manual find'] = function testRouteModelHookFindsTheSameModelAsAManualFind(assert) {
var post;
var Post = _runtime.Object.extend();
this.add('model:post', Post);
Post.reopenClass({
find: function () {
post = this;
return {};
}
});
this.router.map(function () {
this.route('post', {
path: '/post/:post_id'
});
});
return this.visit('/post/1').then(function () {
assert.equal(Post, post);
});
};
_proto['@test Routes can refresh themselves causing their model hooks to be re-run'] = function testRoutesCanRefreshThemselvesCausingTheirModelHooksToBeReRun(assert) {
var _this58 = this;
this.router.map(function () {
this.route('parent', {
path: '/parent/:parent_id'
}, function () {
this.route('child');
});
});
var appcount = 0;
this.add('route:application', _routing.Route.extend({
model: function () {
++appcount;
}
}));
var parentcount = 0;
this.add('route:parent', _routing.Route.extend({
model: function (params) {
assert.equal(params.parent_id, '123');
++parentcount;
},
actions: {
refreshParent: function () {
this.refresh();
}
}
}));
var childcount = 0;
this.add('route:parent.child', _routing.Route.extend({
model: function () {
++childcount;
}
}));
var router;
return this.visit('/').then(function () {
router = _this58.applicationInstance.lookup('router:main');
assert.equal(appcount, 1);
assert.equal(parentcount, 0);
assert.equal(childcount, 0);
return (0, _runloop.run)(router, 'transitionTo', 'parent.child', '123');
}).then(function () {
assert.equal(appcount, 1);
assert.equal(parentcount, 1);
assert.equal(childcount, 1);
return (0, _runloop.run)(router, 'send', 'refreshParent');
}).then(function () {
assert.equal(appcount, 1);
assert.equal(parentcount, 2);
assert.equal(childcount, 2);
});
};
_proto['@test Specifying non-existent controller name in route#render throws'] = function testSpecifyingNonExistentControllerNameInRouteRenderThrows(assert) {
assert.expect(1);
this.router.map(function () {
this.route('home', {
path: '/'
});
});
this.add('route:home', _routing.Route.extend({
renderTemplate: function () {
var _this59 = this;
expectAssertion(function () {
_this59.render('homepage', {
controller: 'stefanpenneristhemanforme'
});
}, "You passed `controller: 'stefanpenneristhemanforme'` into the `render` method, but no such controller could be found.");
}
}));
return this.visit('/');
};
_proto["@test Redirecting with null model doesn't error out"] = function testRedirectingWithNullModelDoesnTErrorOut(assert) {
var _this60 = this;
this.router.map(function () {
this.route('home', {
path: '/'
});
this.route('about', {
path: '/about/:hurhurhur'
});
});
this.add('route:about', _routing.Route.extend({
serialize: function (model) {
if (model === null) {
return {
hurhurhur: 'TreeklesMcGeekles'
};
}
}
}));
this.add('route:home', _routing.Route.extend({
beforeModel: function () {
this.transitionTo('about', null);
}
}));
return this.visit('/').then(function () {
var router = _this60.applicationInstance.lookup('router:main');
assert.equal(router.get('location.path'), '/about/TreeklesMcGeekles');
});
};
_proto['@test rejecting the model hooks promise with a non-error prints the `message` property'] = function testRejectingTheModelHooksPromiseWithANonErrorPrintsTheMessageProperty(assert) {
var _this61 = this;
assert.expect(5);
var rejectedMessage = 'OMG!! SOOOOOO BAD!!!!';
var rejectedStack = 'Yeah, buddy: stack gets printed too.';
this.router.map(function () {
this.route('yippie', {
path: '/'
});
});
console.error = function (initialMessage, errorMessage, errorStack) {
assert.equal(initialMessage, 'Error while processing route: yippie', 'a message with the current route name is printed');
assert.equal(errorMessage, rejectedMessage, "the rejected reason's message property is logged");
assert.equal(errorStack, rejectedStack, "the rejected reason's stack property is logged");
};
this.add('route:yippie', _routing.Route.extend({
model: function () {
return _rsvp.default.reject({
message: rejectedMessage,
stack: rejectedStack
});
}
}));
return assert.throws(function () {
return _this61.visit('/');
}, function (err) {
assert.equal(err.message, rejectedMessage);
return true;
}, 'expected an exception');
};
_proto['@test rejecting the model hooks promise with an error with `errorThrown` property prints `errorThrown.message` property'] = function testRejectingTheModelHooksPromiseWithAnErrorWithErrorThrownPropertyPrintsErrorThrownMessageProperty(assert) {
var _this62 = this;
assert.expect(5);
var rejectedMessage = 'OMG!! SOOOOOO BAD!!!!';
var rejectedStack = 'Yeah, buddy: stack gets printed too.';
this.router.map(function () {
this.route('yippie', {
path: '/'
});
});
console.error = function (initialMessage, errorMessage, errorStack) {
assert.equal(initialMessage, 'Error while processing route: yippie', 'a message with the current route name is printed');
assert.equal(errorMessage, rejectedMessage, "the rejected reason's message property is logged");
assert.equal(errorStack, rejectedStack, "the rejected reason's stack property is logged");
};
this.add('route:yippie', _routing.Route.extend({
model: function () {
return _rsvp.default.reject({
errorThrown: {
message: rejectedMessage,
stack: rejectedStack
}
});
}
}));
assert.throws(function () {
return _this62.visit('/');
}, function (err) {
assert.equal(err.message, rejectedMessage);
return true;
}, 'expected an exception');
};
_proto['@test rejecting the model hooks promise with no reason still logs error'] = function testRejectingTheModelHooksPromiseWithNoReasonStillLogsError(assert) {
var _this63 = this;
assert.expect(2);
this.router.map(function () {
this.route('wowzers', {
path: '/'
});
});
console.error = function (initialMessage) {
assert.equal(initialMessage, 'Error while processing route: wowzers', 'a message with the current route name is printed');
};
this.add('route:wowzers', _routing.Route.extend({
model: function () {
return _rsvp.default.reject();
}
}));
return assert.throws(function () {
return _this63.visit('/');
});
};
_proto['@test rejecting the model hooks promise with a string shows a good error'] = function testRejectingTheModelHooksPromiseWithAStringShowsAGoodError(assert) {
var _this64 = this;
assert.expect(3);
var rejectedMessage = 'Supercalifragilisticexpialidocious';
this.router.map(function () {
this.route('yondo', {
path: '/'
});
});
console.error = function (initialMessage, errorMessage) {
assert.equal(initialMessage, 'Error while processing route: yondo', 'a message with the current route name is printed');
assert.equal(errorMessage, rejectedMessage, "the rejected reason's message property is logged");
};
this.add('route:yondo', _routing.Route.extend({
model: function () {
return _rsvp.default.reject(rejectedMessage);
}
}));
assert.throws(function () {
return _this64.visit('/');
}, new RegExp(rejectedMessage), 'expected an exception');
};
_proto["@test willLeave, willChangeContext, willChangeModel actions don't fire unless feature flag enabled"] = function testWillLeaveWillChangeContextWillChangeModelActionsDonTFireUnlessFeatureFlagEnabled(assert) {
assert.expect(1);
this.router.map(function () {
this.route('about');
});
function shouldNotFire() {
assert.ok(false, "this action shouldn't have been received");
}
this.add('route:index', _routing.Route.extend({
actions: {
willChangeModel: shouldNotFire,
willChangeContext: shouldNotFire,
willLeave: shouldNotFire
}
}));
this.add('route:about', _routing.Route.extend({
setupController: function () {
assert.ok(true, 'about route was entered');
}
}));
return this.visit('/about');
};
_proto['@test Errors in transitionTo within redirect hook are logged'] = function testErrorsInTransitionToWithinRedirectHookAreLogged(assert) {
var _this65 = this;
assert.expect(4);
var actual = [];
this.router.map(function () {
this.route('yondo', {
path: '/'
});
this.route('stink-bomb');
});
this.add('route:yondo', _routing.Route.extend({
redirect: function () {
this.transitionTo('stink-bomb', {
something: 'goes boom'
});
}
}));
console.error = function () {
// push the arguments onto an array so we can detect if the error gets logged twice
actual.push(arguments);
};
assert.throws(function () {
return _this65.visit('/');
}, /More context objects were passed/);
assert.equal(actual.length, 1, 'the error is only logged once');
assert.equal(actual[0][0], 'Error while processing route: yondo', 'source route is printed');
assert.ok(actual[0][1].match(/More context objects were passed than there are dynamic segments for the route: stink-bomb/), 'the error is printed');
};
_proto['@test Errors in transition show error template if available'] = function testErrorsInTransitionShowErrorTemplateIfAvailable(assert) {
this.addTemplate('error', "
Error!
");
this.router.map(function () {
this.route('yondo', {
path: '/'
});
this.route('stink-bomb');
});
this.add('route:yondo', _routing.Route.extend({
redirect: function () {
this.transitionTo('stink-bomb', {
something: 'goes boom'
});
}
}));
console.error = function () {};
return this.visit('/').then(function () {
var rootElement = document.querySelector('#qunit-fixture');
assert.equal(rootElement.querySelectorAll('#error').length, 1, 'Error template was rendered.');
});
};
_proto['@test Route#resetController gets fired when changing models and exiting routes'] = function testRouteResetControllerGetsFiredWhenChangingModelsAndExitingRoutes(assert) {
var _this66 = this;
assert.expect(4);
this.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 = _routing.Route.extend({
setupController: function ()
/* controller, model, transition */
{
calls.push(['setup', this.routeName]);
},
resetController: function ()
/* controller */
{
calls.push(['reset', this.routeName]);
}
});
this.add('route:a', SpyRoute.extend());
this.add('route:b', SpyRoute.extend());
this.add('route:c', SpyRoute.extend());
this.add('route:out', SpyRoute.extend());
var router;
return this.visit('/').then(function () {
router = _this66.applicationInstance.lookup('router:main');
assert.deepEqual(calls, []);
return (0, _runloop.run)(router, 'transitionTo', 'b', 'b-1');
}).then(function () {
assert.deepEqual(calls, [['setup', 'a'], ['setup', 'b']]);
calls.length = 0;
return (0, _runloop.run)(router, 'transitionTo', 'c', 'c-1');
}).then(function () {
assert.deepEqual(calls, [['reset', 'b'], ['setup', 'c']]);
calls.length = 0;
return (0, _runloop.run)(router, 'transitionTo', 'out');
}).then(function () {
assert.deepEqual(calls, [['reset', 'c'], ['reset', 'a'], ['setup', 'out']]);
});
};
_proto['@test Exception during initialization of non-initial route is not swallowed'] = function testExceptionDuringInitializationOfNonInitialRouteIsNotSwallowed(assert) {
var _this67 = this;
this.router.map(function () {
this.route('boom');
});
this.add('route:boom', _routing.Route.extend({
init: function () {
throw new Error('boom!');
}
}));
return assert.throws(function () {
return _this67.visit('/boom');
}, /\bboom\b/);
};
_proto['@test Exception during initialization of initial route is not swallowed'] = function testExceptionDuringInitializationOfInitialRouteIsNotSwallowed(assert) {
var _this68 = this;
this.router.map(function () {
this.route('boom', {
path: '/'
});
});
this.add('route:boom', _routing.Route.extend({
init: function () {
throw new Error('boom!');
}
}));
return assert.throws(function () {
return _this68.visit('/');
}, /\bboom\b/);
};
_proto['@test {{outlet}} works when created after initial render'] = function testOutletWorksWhenCreatedAfterInitialRender(assert) {
var _this69 = this;
this.addTemplate('sample', 'Hi{{#if showTheThing}}{{outlet}}{{/if}}Bye');
this.addTemplate('sample.inner', 'Yay');
this.addTemplate('sample.inner2', 'Boo');
this.router.map(function () {
this.route('sample', {
path: '/'
}, function () {
this.route('inner', {
path: '/'
});
this.route('inner2', {
path: '/2'
});
});
});
var rootElement;
return this.visit('/').then(function () {
rootElement = document.getElementById('qunit-fixture');
assert.equal(rootElement.textContent.trim(), 'HiBye', 'initial render');
(0, _runloop.run)(function () {
return _this69.applicationInstance.lookup('controller:sample').set('showTheThing', true);
});
assert.equal(rootElement.textContent.trim(), 'HiYayBye', 'second render');
return _this69.visit('/2');
}).then(function () {
assert.equal(rootElement.textContent.trim(), 'HiBooBye', 'third render');
});
};
_proto['@test Can render into a named outlet at the top level'] = function testCanRenderIntoANamedOutletAtTheTopLevel(assert) {
this.addTemplate('application', 'A-{{outlet}}-B-{{outlet "other"}}-C');
this.addTemplate('modal', 'Hello world');
this.addTemplate('index', 'The index');
this.router.map(function () {
this.route('index', {
path: '/'
});
});
this.add('route:application', _routing.Route.extend({
renderTemplate: function () {
this.render();
this.render('modal', {
into: 'application',
outlet: 'other'
});
}
}));
return this.visit('/').then(function () {
var rootElement = document.getElementById('qunit-fixture');
assert.equal(rootElement.textContent.trim(), 'A-The index-B-Hello world-C', 'initial render');
});
};
_proto['@test Can disconnect a named outlet at the top level'] = function testCanDisconnectANamedOutletAtTheTopLevel(assert) {
var _this70 = this;
this.addTemplate('application', 'A-{{outlet}}-B-{{outlet "other"}}-C');
this.addTemplate('modal', 'Hello world');
this.addTemplate('index', 'The index');
this.router.map(function () {
this.route('index', {
path: '/'
});
});
this.add('route:application', _routing.Route.extend({
renderTemplate: function () {
this.render();
this.render('modal', {
into: 'application',
outlet: 'other'
});
},
actions: {
banish: function () {
this.disconnectOutlet({
parentView: 'application',
outlet: 'other'
});
}
}
}));
return this.visit('/').then(function () {
var rootElement = document.getElementById('qunit-fixture');
assert.equal(rootElement.textContent.trim(), 'A-The index-B-Hello world-C', 'initial render');
(0, _runloop.run)(_this70.applicationInstance.lookup('router:main'), 'send', 'banish');
assert.equal(rootElement.textContent.trim(), 'A-The index-B--C', 'second render');
});
};
_proto['@test Can render into a named outlet at the top level, with empty main outlet'] = function testCanRenderIntoANamedOutletAtTheTopLevelWithEmptyMainOutlet(assert) {
this.addTemplate('application', 'A-{{outlet}}-B-{{outlet "other"}}-C');
this.addTemplate('modal', 'Hello world');
this.router.map(function () {
this.route('hasNoTemplate', {
path: '/'
});
});
this.add('route:application', _routing.Route.extend({
renderTemplate: function () {
this.render();
this.render('modal', {
into: 'application',
outlet: 'other'
});
}
}));
return this.visit('/').then(function () {
var rootElement = document.getElementById('qunit-fixture');
assert.equal(rootElement.textContent.trim(), 'A--B-Hello world-C', 'initial render');
});
};
_proto['@test Can render into a named outlet at the top level, later'] = function testCanRenderIntoANamedOutletAtTheTopLevelLater(assert) {
var _this71 = this;
this.addTemplate('application', 'A-{{outlet}}-B-{{outlet "other"}}-C');
this.addTemplate('modal', 'Hello world');
this.addTemplate('index', 'The index');
this.router.map(function () {
this.route('index', {
path: '/'
});
});
this.add('route:application', _routing.Route.extend({
actions: {
launch: function () {
this.render('modal', {
into: 'application',
outlet: 'other'
});
}
}
}));
return this.visit('/').then(function () {
var rootElement = document.getElementById('qunit-fixture');
assert.equal(rootElement.textContent.trim(), 'A-The index-B--C', 'initial render');
(0, _runloop.run)(_this71.applicationInstance.lookup('router:main'), 'send', 'launch');
assert.equal(rootElement.textContent.trim(), 'A-The index-B-Hello world-C', 'second render');
});
};
_proto["@test Can render routes with no 'main' outlet and their children"] = function testCanRenderRoutesWithNoMainOutletAndTheirChildren(assert) {
var _this72 = this;
this.addTemplate('application', '