');
});
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', '