tag');
this.assertElement(this.firstChild, { tagName: 'div', content: '' });
};
_class5.prototype.assertContent = function (content) {
this.assert.strictEqual(this.nodesCount, 1, 'It should render exactly one
tag');
this.assertElement(this.firstChild, { tagName: 'div', attrs: { 'data-foo': content }, content: '' });
};
return _class5;
}(DynamicContentTest));
var TrustedContentTest = function (_DynamicContentTest5) {
(0, _emberBabel.inherits)(TrustedContentTest, _DynamicContentTest5);
function TrustedContentTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _DynamicContentTest5.apply(this, arguments));
}
TrustedContentTest.prototype.assertIsEmpty = function () {
this.assert.strictEqual(this.firstChild, null);
};
TrustedContentTest.prototype.assertContent = function (content) {
this.assertHTML(content);
};
TrustedContentTest.prototype.assertStableRerender = function () {
var _this27 = this;
this.takeSnapshot();
this.runTask(function () {
return _this27.rerender();
});
_DynamicContentTest5.prototype.assertInvariants.call(this);
};
TrustedContentTest.prototype.assertInvariants = function () {
// If it's not stable, we will wipe out all the content and replace them,
// so there are no invariants
};
return TrustedContentTest;
}(DynamicContentTest);
(0, _testCase.moduleFor)('Dynamic content tests (trusted)', function (_TrustedContentTest) {
(0, _emberBabel.inherits)(_class6, _TrustedContentTest);
function _class6() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TrustedContentTest.apply(this, arguments));
}
_class6.prototype.renderPath = function (path) {
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.render('{{{' + path + '}}}', context);
};
_class6.prototype['@test updating trusted curlies'] = function () {
var _this29 = this;
this.render('{{{htmlContent}}}{{{nested.htmlContent}}}', {
htmlContent: '
Max ',
nested: { htmlContent: '
James ' }
});
this.assertContent('
Max James ');
this.runTask(function () {
return _this29.rerender();
});
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this29.context, 'htmlContent', '
M a x ');
});
this.assertContent('
M a x James ');
this.runTask(function () {
return (0, _emberMetal.set)(_this29.context, 'nested.htmlContent', 'Jammie');
});
this.assertContent('
M a x Jammie');
this.runTask(function () {
(0, _emberMetal.set)(_this29.context, 'htmlContent', '
Max ');
(0, _emberMetal.set)(_this29.context, 'nested', { htmlContent: '
James ' });
});
this.assertContent('
Max James ');
};
return _class6;
}(TrustedContentTest));
(0, _testCase.moduleFor)('Dynamic content tests (integration)', function (_RenderingTest3) {
(0, _emberBabel.inherits)(_class7, _RenderingTest3);
function _class7() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest3.apply(this, arguments));
}
_class7.prototype['@test it can render a dynamic template'] = function () {
var _this31 = this;
var ember = '\n \n
\n
Why you should use Ember.js? \n
\n It\'s great \n It\'s awesome \n It\'s Ember.js \n \n
\n \n ';
this.render('\n \n
\n
Why you should use {{framework}}? \n
\n It\'s great \n It\'s awesome \n It\'s {{framework}} \n \n
\n \n ', {
framework: 'Ember.js'
});
this.assertHTML(ember);
this.runTask(function () {
return _this31.rerender();
});
this.assertHTML(ember);
this.runTask(function () {
return (0, _emberMetal.set)(_this31.context, 'framework', 'React');
});
this.assertHTML('\n \n
\n
Why you should use React? \n
\n It\'s great \n It\'s awesome \n It\'s React \n \n
\n \n ');
this.runTask(function () {
return (0, _emberMetal.set)(_this31.context, 'framework', 'Ember.js');
});
this.assertHTML(ember);
};
_class7.prototype['@test it should evaluate to nothing if part of the path is `undefined`'] = function () {
var _this32 = this;
this.render('{{foo.bar.baz.bizz}}', {
foo: {}
});
this.assertText('');
this.runTask(function () {
return _this32.rerender();
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this32.context, 'foo', {
bar: { baz: { bizz: 'Hey!' } }
});
});
this.assertText('Hey!');
this.runTask(function () {
return (0, _emberMetal.set)(_this32.context, 'foo', {});
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this32.context, 'foo', {
bar: { baz: { bizz: 'Hello!' } }
});
});
this.assertText('Hello!');
this.runTask(function () {
return (0, _emberMetal.set)(_this32.context, 'foo', {});
});
this.assertText('');
};
_class7.prototype['@test it should evaluate to nothing if part of the path is a primative'] = function () {
var _this33 = this;
this.render('{{foo.bar.baz.bizz}}', {
foo: { bar: true }
});
this.assertText('');
this.runTask(function () {
return _this33.rerender();
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this33.context, 'foo', {
bar: false
});
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this33.context, 'foo', {
bar: 'Haha'
});
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this33.context, 'foo', {
bar: null
});
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this33.context, 'foo', {
bar: undefined
});
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this33.context, 'foo', {
bar: 1
});
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this33.context, 'foo', {
bar: { baz: { bizz: 'Hello!' } }
});
});
this.assertText('Hello!');
this.runTask(function () {
return (0, _emberMetal.set)(_this33.context, 'foo', {
bar: true
});
});
this.assertText('');
};
_class7.prototype['@test can set dynamic href'] = function () {
var _this34 = this;
this.render('
Example ', {
model: {
url: 'http://example.com'
}
});
this.assertElement(this.firstChild, { tagName: 'a', content: 'Example', attrs: { 'href': 'http://example.com' } });
this.runTask(function () {
return _this34.rerender();
});
this.assertElement(this.firstChild, { tagName: 'a', content: 'Example', attrs: { 'href': 'http://example.com' } });
this.runTask(function () {
return (0, _emberMetal.set)(_this34.context, 'model.url', 'http://linkedin.com');
});
this.assertElement(this.firstChild, { tagName: 'a', content: 'Example', attrs: { 'href': 'http://linkedin.com' } });
this.runTask(function () {
return (0, _emberMetal.set)(_this34.context, 'model', { url: 'http://example.com' });
});
this.assertElement(this.firstChild, { tagName: 'a', content: 'Example', attrs: { 'href': 'http://example.com' } });
};
_class7.prototype['@test quoteless class attributes update correctly'] = function () {
var _this35 = this;
this.render('
hello
', {
fooBar: true
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } });
this.runTask(function () {
return _this35.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this35.context, 'fooBar', false);
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello' });
this.runTask(function () {
return (0, _emberMetal.set)(_this35.context, 'fooBar', true);
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } });
};
_class7.prototype['@test quoted class attributes update correctly'] = function (assert) {
var _this36 = this;
this.render('
hello
', {
fooBar: true
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } });
this.runTask(function () {
return _this36.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this36.context, 'fooBar', false);
});
assert.equal(this.firstChild.className, '');
this.runTask(function () {
return (0, _emberMetal.set)(_this36.context, 'fooBar', true);
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo-bar') } });
};
_class7.prototype['@test unquoted class attribute can contain multiple classes'] = function () {
var _this37 = this;
this.render('
hello
', {
model: {
classes: 'foo bar baz'
}
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } });
this.runTask(function () {
return _this37.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this37.context, 'model.classes', 'fizz bizz');
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz bizz') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this37.context, 'model', { classes: 'foo bar baz' });
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } });
};
_class7.prototype['@test unquoted class attribute'] = function () {
var _this38 = this;
this.render('
hello
', {
model: {
foo: 'foo'
}
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } });
this.runTask(function () {
return _this38.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this38.context, 'model.foo', 'fizz');
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this38.context, 'model', { foo: 'foo' });
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } });
};
_class7.prototype['@test quoted class attribute'] = function () {
var _this39 = this;
this.render('
hello
', {
model: {
foo: 'foo'
}
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } });
this.runTask(function () {
return _this39.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this39.context, 'model.foo', 'fizz');
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this39.context, 'model', { foo: 'foo' });
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo') } });
};
_class7.prototype['@test quoted class attribute can contain multiple classes'] = function () {
var _this40 = this;
this.render('
hello
', {
model: {
classes: 'foo bar baz'
}
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } });
this.runTask(function () {
return _this40.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this40.context, 'model.classes', 'fizz bizz');
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz bizz') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this40.context, 'model', { classes: 'foo bar baz' });
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar baz') } });
};
_class7.prototype['@test class attribute concats bound values'] = function () {
var _this41 = this;
this.render('
hello
', {
model: {
foo: 'foo',
bar: 'bar',
bizz: 'bizz'
}
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar bizz') } });
this.runTask(function () {
return _this41.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar bizz') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this41.context, 'model.foo', 'fizz');
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz bar bizz') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this41.context, 'model.bar', null);
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('fizz bizz') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this41.context, 'model', {
foo: 'foo',
bar: 'bar',
bizz: 'bizz'
});
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar bizz') } });
};
_class7.prototype['@test class attribute accepts nested helpers, and updates'] = function () {
var _this42 = this;
this.render('
hello
', {
model: {
size: 'large',
hasSize: true,
hasShape: false,
shape: 'round'
}
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('large') } });
this.runTask(function () {
return _this42.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('large') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this42.context, 'model.hasShape', true);
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('large round') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this42.context, 'model.hasSize', false);
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('round') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this42.context, 'model', {
size: 'large',
hasSize: true,
hasShape: false,
shape: 'round'
});
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('large') } });
};
_class7.prototype['@test Multiple dynamic classes'] = function () {
var _this43 = this;
this.render('
hello
', {
model: {
foo: 'foo',
bar: 'bar',
fizz: 'fizz',
baz: 'baz'
}
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar fizz baz') } });
this.runTask(function () {
return _this43.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar fizz baz') } });
this.runTask(function () {
(0, _emberMetal.set)(_this43.context, 'model.foo', null);
(0, _emberMetal.set)(_this43.context, 'model.fizz', null);
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('bar baz') } });
this.runTask(function () {
(0, _emberMetal.set)(_this43.context, 'model', {
foo: 'foo',
bar: 'bar',
fizz: 'fizz',
baz: 'baz'
});
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': (0, _testHelpers.classes)('foo bar fizz baz') } });
};
_class7.prototype['@test classes are ordered: See issue #9912'] = function () {
var _this44 = this;
this.render('
hello
', {
model: {
foo: 'foo',
bar: 'bar'
}
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': 'foo static bar' } });
this.runTask(function () {
return _this44.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': 'foo static bar' } });
this.runTask(function () {
(0, _emberMetal.set)(_this44.context, 'model.bar', null);
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': 'foo static ' } });
this.runTask(function () {
(0, _emberMetal.set)(_this44.context, 'model', {
foo: 'foo',
bar: 'bar'
});
});
this.assertElement(this.firstChild, { tagName: 'div', content: 'hello', attrs: { 'class': 'foo static bar' } });
};
return _class7;
}(_testCase.RenderingTest));
var warnings = void 0,
originalWarn = void 0;
var StyleTest = function (_RenderingTest4) {
(0, _emberBabel.inherits)(StyleTest, _RenderingTest4);
function StyleTest() {
var _this45 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest4.apply(this, arguments));
warnings = [];
originalWarn = (0, _emberDebug.getDebugFunction)('warn');
(0, _emberDebug.setDebugFunction)('warn', function (message, test) {
if (!test) {
warnings.push(message);
}
});
return _this45;
}
StyleTest.prototype.teardown = function () {
var _RenderingTest4$proto;
(_RenderingTest4$proto = _RenderingTest4.prototype.teardown).call.apply(_RenderingTest4$proto, [this].concat(Array.prototype.slice.call(arguments)));
(0, _emberDebug.setDebugFunction)('warn', originalWarn);
};
StyleTest.prototype.assertStyleWarning = function (style) {
this.assert.deepEqual(warnings, [(0, _emberViews.constructStyleDeprecationMessage)(style)]);
};
StyleTest.prototype.assertNoWarning = function () {
this.assert.deepEqual(warnings, []);
};
return StyleTest;
}(_testCase.RenderingTest);
(0, _testCase.moduleFor)('Inline style tests', function (_StyleTest) {
(0, _emberBabel.inherits)(_class8, _StyleTest);
function _class8() {
return (0, _emberBabel.possibleConstructorReturn)(this, _StyleTest.apply(this, arguments));
}
_class8.prototype['@test can set dynamic style'] = function () {
var _this47 = this;
this.render('
', {
model: {
style: 'width: 60px;'
}
});
this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } });
this.runTask(function () {
return _this47.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } });
this.runTask(function () {
return (0, _emberMetal.set)(_this47.context, 'model.style', 'height: 60px;');
});
this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'height: 60px;' } });
this.runTask(function () {
return (0, _emberMetal.set)(_this47.context, 'model.style', null);
});
this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: {} });
this.runTask(function () {
return (0, _emberMetal.set)(_this47.context, 'model', { style: 'width: 60px;' });
});
this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } });
};
_class8.prototype['@test can set dynamic style with -html-safe'] = function () {
var _this48 = this;
this.render('
', {
model: {
style: 'width: 60px;'
}
});
this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } });
this.runTask(function () {
return _this48.rerender();
});
this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } });
this.runTask(function () {
return (0, _emberMetal.set)(_this48.context, 'model.style', 'height: 60px;');
});
this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'height: 60px;' } });
this.runTask(function () {
return (0, _emberMetal.set)(_this48.context, 'model', { style: 'width: 60px;' });
});
this.assertElement(this.firstChild, { tagName: 'div', content: '', attrs: { 'style': 'width: 60px;' } });
};
return _class8;
}(StyleTest));
if (!EmberDev.runningProdBuild) {
(0, _testCase.moduleFor)('Inline style tests - warnings', function (_StyleTest2) {
(0, _emberBabel.inherits)(_class9, _StyleTest2);
function _class9() {
return (0, _emberBabel.possibleConstructorReturn)(this, _StyleTest2.apply(this, arguments));
}
_class9.prototype['@test specifying
generates a warning'] = function () {
var userValue = 'width: 42px';
this.render('
', {
userValue: userValue
});
this.assertStyleWarning(userValue);
};
_class9.prototype['@test specifying `attributeBindings: ["style"]` generates a warning'] = function () {
var FooBarComponent = _helpers.Component.extend({
attributeBindings: ['style']
});
this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' });
var userValue = 'width: 42px';
this.render('{{foo-bar style=userValue}}', {
userValue: userValue
});
this.assertStyleWarning(userValue);
};
_class9.prototype['@test specifying `
` works properly without a warning'] = function () {
this.render('
', {
userValue: 'width: 42px'
});
this.assertNoWarning();
};
_class9.prototype['@test specifying `
` works properly with a SafeString'] = function () {
this.render('
', {
userValue: new _helpers.SafeString('width: 42px')
});
this.assertNoWarning();
};
_class9.prototype['@test null value do not generate htmlsafe warning'] = function () {
this.render('
', {
userValue: null
});
this.assertNoWarning();
};
_class9.prototype['@test undefined value do not generate htmlsafe warning'] = function () {
this.render('
');
this.assertNoWarning();
};
_class9.prototype['@test no warnings are triggered when using `-html-safe`'] = function () {
this.render('
', {
userValue: 'width: 42px'
});
this.assertNoWarning();
};
_class9.prototype['@test no warnings are triggered when a safe string is quoted'] = function () {
this.render('
', {
userValue: new _helpers.SafeString('width: 42px')
});
this.assertNoWarning();
};
_class9.prototype['@test binding warning is triggered when an unsafe string is quoted'] = function () {
var userValue = 'width: 42px';
this.render('
', {
userValue: userValue
});
this.assertStyleWarning(userValue);
};
_class9.prototype['@test binding warning is triggered when a safe string for a complete property is concatenated in place'] = function () {
this.render('
', {
userValue: new _helpers.SafeString('width: 42px')
});
this.assertStyleWarning('color: green; ' + 'width: 42px');
};
_class9.prototype['@test binding warning is triggered when a safe string for a value is concatenated in place'] = function () {
var userValue = '42px';
this.render('
', {
userValue: new _helpers.SafeString(userValue)
});
this.assertStyleWarning('color: green; width: ' + userValue);
};
_class9.prototype['@test binding warning is triggered when a safe string for a property name is concatenated in place'] = function () {
var userValue = 'width';
this.render('
', {
userProperty: new _helpers.SafeString(userValue)
});
this.assertStyleWarning('color: green; ' + userValue + ': 42px');
};
return _class9;
}(StyleTest));
}
});
enifed('ember-glimmer/tests/integration/event-dispatcher-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal', 'ember-views'], function (_emberBabel, _testCase, _helpers, _emberMetal, _emberViews) {
'use strict';
var canDataTransfer = !!document.createEvent('HTMLEvents').dataTransfer;
function fireNativeWithDataTransfer(node, type, dataTransfer) {
var event = document.createEvent('HTMLEvents');
event.initEvent(type, true, true);
event.dataTransfer = dataTransfer;
node.dispatchEvent(event);
}
(0, _testCase.moduleFor)('EventDispatcher', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test events bubble view hierarchy for form elements'] = function (assert) {
var _this2 = this;
var receivedEvent = void 0;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
change: function (event) {
receivedEvent = event;
}
}),
template: '
'
});
this.render('{{x-foo}}');
this.runTask(function () {
return _this2.$('#is-done').trigger('change');
});
assert.ok(receivedEvent, 'change event was triggered');
assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]);
};
_class.prototype['@test dispatches to the nearest event manager'] = function (assert) {
var _this3 = this;
var receivedEvent = void 0;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function () {
assert.notOk(true, 'should not trigger `click` on component');
},
eventManager: {
click: function (event) {
receivedEvent = event;
}
}
}),
template: '
'
});
expectDeprecation(/`eventManager` has been deprecated/);
this.render('{{x-foo}}');
this.runTask(function () {
return _this3.$('#is-done').trigger('click');
});
assert.strictEqual(receivedEvent.target, this.$('#is-done')[0]);
};
_class.prototype['@test event manager can re-dispatch to the component'] = function (assert) {
var _this4 = this;
var handlers = [];
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function () {
handlers.push('component');
},
eventManager: {
click: function (event, component) {
handlers.push('eventManager');
// Re-dispatch event when you get it.
//
// The second parameter tells the dispatcher
// that this event has been handled. This
// API will clearly need to be reworked since
// multiple eventManagers in a single view
// hierarchy would break, but it shows that
// re-dispatching works
component.$().trigger('click', this);
}
}
}),
template: '
'
});
expectDeprecation(/`eventManager` has been deprecated/);
this.render('{{x-foo}}');
this.runTask(function () {
return _this4.$('#is-done').trigger('click');
});
assert.deepEqual(handlers, ['eventManager', 'component']);
};
_class.prototype['@test event handlers are wrapped in a run loop'] = function (assert) {
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
change: function () {
assert.ok(_emberMetal.run.currentRunLoop, 'a run loop should have started');
}
}),
template: '
'
});
this.render('{{x-foo}}');
this.$('#is-done').trigger('click');
};
return _class;
}(_testCase.RenderingTest));
(0, _testCase.moduleFor)('EventDispatcher#setup', function (_RenderingTest2) {
(0, _emberBabel.inherits)(_class2, _RenderingTest2);
function _class2() {
var _this5 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.call(this));
var dispatcher = _this5.owner.lookup('event_dispatcher:main');
(0, _emberMetal.run)(dispatcher, 'destroy');
_this5.owner.__container__.reset('event_dispatcher:main');
_this5.dispatcher = _this5.owner.lookup('event_dispatcher:main');
return _this5;
}
_class2.prototype['@test additional events can be specified'] = function (assert) {
this.dispatcher.setup({ myevent: 'myEvent' });
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
myEvent: function () {
assert.ok(true, 'custom event was triggered');
}
}),
template: '
Hello!
'
});
this.render('{{x-foo}}');
this.$('div').trigger('myevent');
};
_class2.prototype['@test eventManager is deprecated'] = function () {
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
eventManager: {
myEvent: function () {}
}
}),
template: '
Hello!
'
});
expectDeprecation(/`eventManager` has been deprecated/);
this.render('{{x-foo}}');
};
_class2.prototype['@test canDispatchToEventManager is deprecated in EventDispatcher'] = function () {
var MyDispatcher = _emberViews.EventDispatcher.extend({
canDispatchToEventManager: null
});
expectDeprecation(/`canDispatchToEventManager` has been deprecated/);
MyDispatcher.create();
};
_class2.prototype['@test a rootElement can be specified'] = function (assert) {
this.$().append('
');
this.dispatcher.setup({ myevent: 'myEvent' }, '#app');
assert.ok(this.$('#app').hasClass('ember-application'), 'custom rootElement was used');
assert.equal(this.dispatcher.rootElement, '#app', 'the dispatchers rootElement was updated');
};
_class2.prototype['@test default events can be disabled via `customEvents`'] = function (assert) {
this.dispatcher.setup({ click: null });
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
click: function () {
assert.ok(false, 'click method was called');
},
null: function () {
assert.ok(false, 'null method was called');
},
doubleClick: function () {
assert.ok(true, 'a non-disabled event is still handled properly');
}
}),
template: '
Hello!
'
});
this.render('{{x-foo}}');
this.$('div').trigger('click');
this.$('div').trigger('dblclick');
};
_class2.prototype['@test throws if specified rootElement does not exist'] = function (assert) {
var _this6 = this;
assert.throws(function () {
_this6.dispatcher.setup({ myevent: 'myEvent' }, '#app');
});
};
return _class2;
}(_testCase.RenderingTest));
if (canDataTransfer) {
(0, _testCase.moduleFor)('EventDispatcher - Event Properties', function (_RenderingTest4) {
(0, _emberBabel.inherits)(_class4, _RenderingTest4);
function _class4() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest4.apply(this, arguments));
}
_class4.prototype['@test dataTransfer property is added to drop event'] = function (assert) {
var receivedEvent = void 0;
this.registerComponent('x-foo', {
ComponentClass: _helpers.Component.extend({
drop: function (event) {
receivedEvent = event;
}
})
});
this.render('{{x-foo}}');
fireNativeWithDataTransfer(this.$('div')[0], 'drop', 'success');
assert.equal(receivedEvent.dataTransfer, 'success');
};
return _class4;
}(_testCase.RenderingTest));
}
});
enifed('ember-glimmer/tests/integration/helpers/-class-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/test-helpers', 'ember-metal'], function (_emberBabel, _testCase, _testHelpers, _emberMetal) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: {{-class}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test casts binding to dasherized class'] = function () {
var _this2 = this;
this.registerComponent('foo-bar', { template: '' });
this.render('{{foo-bar class=(-class someTruth "someTruth")}}', {
someTruth: true
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } });
this.runTask(function () {
return _this2.rerender();
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'someTruth', false);
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('ember-view') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'someTruth', true);
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } });
};
_class.prototype['@tests casts leaf path of binding to dasherized class'] = function () {
var _this3 = this;
this.registerComponent('foo-bar', { template: '' });
this.render('{{foo-bar class=(-class model.someTruth "someTruth")}}', {
model: {
someTruth: true
}
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } });
this.runTask(function () {
return _this3.rerender();
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'model.someTruth', false);
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('ember-view') } });
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'model', { someTruth: true });
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { class: (0, _testHelpers.classes)('some-truth ember-view') } });
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/closure-action-test', ['ember-babel', 'ember-metal', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/helpers'], function (_emberBabel, _emberMetal, _testCase, _abstractTestCase, _helpers) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
clicked: {{clicked}}; foo: {{foo}}
\n\n {{click-me id="string-action" onClick=(action "on-click")}}\n {{click-me id="function-action" onClick=(action onClick)}}\n {{click-me id="mut-action" onClick=(action (mut clicked))}}\n '], ['\n
clicked: {{clicked}}; foo: {{foo}}
\n\n {{click-me id="string-action" onClick=(action "on-click")}}\n {{click-me id="function-action" onClick=(action onClick)}}\n {{click-me id="mut-action" onClick=(action (mut clicked))}}\n ']);
(0, _testCase.moduleFor)('Helpers test: closure {{action}}', function (_RenderingTest2) {
(0, _emberBabel.inherits)(_class2, _RenderingTest2);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments));
}
_class2.prototype['@test action should be called'] = function () {
var outerActionCalled = false;
var component = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
fireAction: function () {
this.attrs.submit();
}
});
var OuterComponent = _helpers.Component.extend({
outerSubmit: function () {
outerActionCalled = true;
}
});
this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' });
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerSubmit)}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
component.fireAction();
});
this.assert.ok(outerActionCalled, 'the action was called');
};
_class2.prototype['@test an error is triggered when bound action function is undefined'] = function () {
var _this6 = this;
this.registerComponent('inner-component', {
template: 'inner'
});
this.registerComponent('outer-component', {
template: '{{inner-component submit=(action somethingThatIsUndefined)}}'
});
expectAssertion(function () {
_this6.render('{{outer-component}}');
}, /Action passed is null or undefined in \(action[^)]*\) from .*\./);
};
_class2.prototype['@test an error is triggered when bound action being passed in is a non-function'] = function () {
var _this7 = this;
this.registerComponent('inner-component', {
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: _helpers.Component.extend({
nonFunctionThing: {}
}),
template: '{{inner-component submit=(action nonFunctionThing)}}'
});
expectAssertion(function () {
_this7.render('{{outer-component}}');
}, /An action could not be made for `.*` in .*\. Please confirm that you are using either a quoted action name \(i\.e\. `\(action '.*'\)`\) or a function available in .*\./);
};
_class2.prototype['@test [#12718] a nice error is shown when a bound action function is undefined and it is passed as attrs.foo'] = function () {
var _this8 = this;
this.registerComponent('inner-component', {
template: '
Click me '
});
this.registerComponent('outer-component', {
template: '{{inner-component}}'
});
expectAssertion(function () {
_this8.render('{{outer-component}}');
}, /Action passed is null or undefined in \(action[^)]*\) from .*\./);
};
_class2.prototype['@test action value is returned'] = function () {
var expectedValue = 'terrible tom';
var returnedValue = void 0;
var innerComponent = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
returnedValue = this.attrs.submit();
}
});
var OuterComponent = _helpers.Component.extend({
outerSubmit: function () {
return expectedValue;
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerSubmit)}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.equal(returnedValue, expectedValue, 'action can return to caller');
};
_class2.prototype['@test action should be called on the correct scope'] = function () {
var innerComponent = void 0;
var outerComponent = void 0;
var actualComponent = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit();
}
});
var OuterComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
outerComponent = this;
},
isOuterComponent: true,
outerSubmit: function () {
actualComponent = this;
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerSubmit)}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.equal(actualComponent, outerComponent, 'action has the correct context');
this.assert.ok(actualComponent.isOuterComponent, 'action has the correct context');
};
_class2.prototype['@test arguments to action are passed, curry'] = function () {
var first = 'mitch';
var second = 'martin';
var third = 'matt';
var fourth = 'wacky wycats';
var innerComponent = void 0;
var actualArgs = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit(fourth);
}
});
var OuterComponent = _helpers.Component.extend({
third: third,
outerSubmit: function () {
actualArgs = [].concat(Array.prototype.slice.call(arguments));
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action (action outerSubmit "' + first + '") "' + second + '" third)}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.deepEqual(actualArgs, [first, second, third, fourth], 'action has the correct args');
};
_class2.prototype['@test `this` can be passed as an argument'] = function () {
var value = {};
var component = void 0;
var innerComponent = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit();
}
});
var OuterComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
actions: {
outerAction: function (incomingValue) {
value = incomingValue;
}
}
});
this.registerComponent('inner-component', { ComponentClass: InnerComponent, template: 'inner' });
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action "outerAction" this)}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.strictEqual(value, component, 'the component is passed at `this`');
};
_class2.prototype['@test arguments to action are bound'] = function () {
var value = 'lazy leah';
var innerComponent = void 0;
var outerComponent = void 0;
var actualArg = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit();
}
});
var OuterComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
outerComponent = this;
},
value: '',
outerSubmit: function (incomingValue) {
actualArg = incomingValue;
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerSubmit value)}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.strictEqual(actualArg, '', 'action has the correct first arg');
this.runTask(function () {
outerComponent.set('value', value);
});
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.strictEqual(actualArg, value, 'action has the correct first arg');
};
_class2.prototype['@test array arguments are passed correctly to action'] = function () {
var first = 'foo';
var second = [3, 5];
var third = [4, 9];
var actualFirst = void 0;
var actualSecond = void 0;
var actualThird = void 0;
var innerComponent = void 0;
var outerComponent = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit(second, third);
}
});
var OuterComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
outerComponent = this;
},
outerSubmit: function (incomingFirst, incomingSecond, incomingThird) {
actualFirst = incomingFirst;
actualSecond = incomingSecond;
actualThird = incomingThird;
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerSubmit first)}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
outerComponent.set('first', first);
outerComponent.set('second', second);
});
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.equal(actualFirst, first, 'action has the correct first arg');
this.assert.equal(actualSecond, second, 'action has the correct second arg');
this.assert.equal(actualThird, third, 'action has the correct third arg');
};
_class2.prototype['@test mut values can be wrapped in actions, are settable'] = function () {
var newValue = 'trollin trek';
var innerComponent = void 0;
var outerComponent = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit(newValue);
}
});
var OuterComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
outerComponent = this;
},
outerMut: 'patient peter'
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action (mut outerMut))}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.equal(outerComponent.get('outerMut'), newValue, 'mut value is set');
};
_class2.prototype['@test mut values can be wrapped in actions, are settable with a curry'] = function () {
var newValue = 'trollin trek';
var innerComponent = void 0;
var outerComponent = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit();
}
});
var OuterComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
outerComponent = this;
},
outerMut: 'patient peter'
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action (mut outerMut) \'' + newValue + '\')}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.equal(outerComponent.get('outerMut'), newValue, 'mut value is set');
};
_class2.prototype['@test action can create closures over actions'] = function () {
var first = 'raging robert';
var second = 'mild machty';
var returnValue = 'butch brian';
var actualFirst = void 0;
var actualSecond = void 0;
var actualReturnedValue = void 0;
var innerComponent = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
actualReturnedValue = this.attrs.submit(second);
}
});
var OuterComponent = _helpers.Component.extend({
actions: {
outerAction: function (incomingFirst, incomingSecond) {
actualFirst = incomingFirst;
actualSecond = incomingSecond;
return returnValue;
}
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action \'outerAction\' \'' + first + '\')}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.equal(actualReturnedValue, returnValue, 'return value is present');
this.assert.equal(actualFirst, first, 'first argument is correct');
this.assert.equal(actualSecond, second, 'second argument is correct');
};
_class2.prototype['@test provides a helpful error if an action is not present'] = function () {
var _this9 = this;
var InnerComponent = _helpers.Component.extend({});
var OuterComponent = _helpers.Component.extend({
actions: {
something: function () {
// this is present to ensure `actions` hash is present
// a different error is triggered if `actions` is missing
// completely
}
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action \'doesNotExist\')}}'
});
expectAssertion(function () {
_this9.render('{{outer-component}}');
}, /An action named 'doesNotExist' was not found in /);
};
_class2.prototype['@test provides a helpful error if actions hash is not present'] = function () {
var _this10 = this;
var InnerComponent = _helpers.Component.extend({});
var OuterComponent = _helpers.Component.extend({});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action \'doesNotExist\')}}'
});
expectAssertion(function () {
_this10.render('{{outer-component}}');
}, /An action named 'doesNotExist' was not found in /);
};
_class2.prototype['@test action can create closures over actions with target'] = function () {
var innerComponent = void 0;
var actionCalled = false;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit();
}
});
var OuterComponent = _helpers.Component.extend({
otherComponent: (0, _emberMetal.computed)(function () {
return {
actions: {
outerAction: function () {
actionCalled = true;
}
}
};
})
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action \'outerAction\' target=otherComponent)}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.ok(actionCalled, 'action called on otherComponent');
};
_class2.prototype['@test value can be used with action over actions'] = function () {
var newValue = 'yelping yehuda';
var innerComponent = void 0;
var actualValue = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit({
readProp: newValue
});
}
});
var OuterComponent = _helpers.Component.extend({
outerContent: {
readProp: newValue
},
actions: {
outerAction: function (incomingValue) {
actualValue = incomingValue;
}
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action \'outerAction\' value="readProp")}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.equal(actualValue, newValue, 'value is read');
};
_class2.prototype['@test action will read the value of a first property'] = function () {
var newValue = 'irate igor';
var innerComponent = void 0;
var actualValue = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit({
readProp: newValue
});
}
});
var OuterComponent = _helpers.Component.extend({
outerAction: function (incomingValue) {
actualValue = incomingValue;
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerAction value="readProp")}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.equal(actualValue, newValue, 'property is read');
};
_class2.prototype['@test action will read the value of a curried first argument property'] = function () {
var newValue = 'kissing kris';
var innerComponent = void 0;
var actualValue = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit();
}
});
var OuterComponent = _helpers.Component.extend({
objectArgument: {
readProp: newValue
},
outerAction: function (incomingValue) {
actualValue = incomingValue;
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action outerAction objectArgument value="readProp")}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.equal(actualValue, newValue, 'property is read');
};
_class2.prototype['@test action closure does not get auto-mut wrapped'] = function (assert) {
var first = 'raging robert';
var second = 'mild machty';
var returnValue = 'butch brian';
var innerComponent = void 0;
var actualFirst = void 0;
var actualSecond = void 0;
var actualReturnedValue = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.get('submit')(second);
this.get('attrs-submit')(second);
var attrsSubmitReturnValue = this.attrs['attrs-submit'](second);
var submitReturnValue = this.attrs.submit(second);
assert.equal(attrsSubmitReturnValue, submitReturnValue, 'both attrs.foo and foo should behave the same');
return submitReturnValue;
}
});
var MiddleComponent = _helpers.Component.extend({});
var OuterComponent = _helpers.Component.extend({
actions: {
outerAction: function (incomingFirst, incomingSecond) {
actualFirst = incomingFirst;
actualSecond = incomingSecond;
return returnValue;
}
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('middle-component', {
ComponentClass: MiddleComponent,
template: '{{inner-component attrs-submit=attrs.submit submit=submit}}'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{middle-component submit=(action \'outerAction\' \'' + first + '\')}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
actualReturnedValue = innerComponent.fireAction();
});
this.assert.equal(actualFirst, first, 'first argument is correct');
this.assert.equal(actualSecond, second, 'second argument is correct');
this.assert.equal(actualReturnedValue, returnValue, 'return value is present');
};
_class2.prototype['@test action should be called within a run loop'] = function () {
var innerComponent = void 0;
var capturedRunLoop = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
this.attrs.submit();
}
});
var OuterComponent = _helpers.Component.extend({
actions: {
submit: function () {
capturedRunLoop = _emberMetal.run.currentRunLoop;
}
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action \'submit\')}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.ok(capturedRunLoop, 'action is called within a run loop');
};
_class2.prototype['@test objects that define INVOKE can be casted to actions'] = function () {
var innerComponent = void 0;
var actionArgs = void 0;
var invokableArgs = void 0;
var InnerComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
innerComponent = this;
},
fireAction: function () {
actionArgs = this.attrs.submit(4, 5, 6);
}
});
var OuterComponent = _helpers.Component.extend({
foo: 123,
submitTask: (0, _emberMetal.computed)(function () {
var _this11 = this,
_ref;
return _ref = {}, _ref[_helpers.INVOKE] = function () {
var _len, args, _key;
for (_len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
invokableArgs = args;
return _this11.foo;
}, _ref;
})
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: 'inner'
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: '{{inner-component submit=(action submitTask 1 2 3)}}'
});
this.render('{{outer-component}}');
this.runTask(function () {
innerComponent.fireAction();
});
this.assert.equal(actionArgs, 123);
this.assert.deepEqual(invokableArgs, [1, 2, 3, 4, 5, 6]);
};
_class2.prototype['@test closure action with `(mut undefinedThing)` works properly [GH#13959]'] = function () {
var _this12 = this;
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
label: undefined,
init: function () {
this._super.apply(this, arguments);
component = this;
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
{{if label label "Click me"}} '
});
this.render('{{example-component}}');
this.assertText('Click me');
this.assertStableRerender();
this.runTask(function () {
_this12.$('button').click();
});
this.assertText('Clicked!');
this.runTask(function () {
component.set('label', 'Dun clicked');
});
this.assertText('Dun clicked');
this.runTask(function () {
_this12.$('button').click();
});
this.assertText('Clicked!');
this.runTask(function () {
component.set('label', undefined);
});
this.assertText('Click me');
};
_class2.prototype['@test closure actions does not cause component hooks to fire unnecessarily [GH#14305] [GH#14654]'] = function (assert) {
var _this14 = this;
var clicked = 0;
var didReceiveAttrsFired = 0;
var ClickMeComponent = _helpers.Component.extend({
tagName: 'button',
click: function () {
this.get('onClick').call(undefined, ++clicked);
},
didReceiveAttrs: function () {
didReceiveAttrsFired++;
}
});
this.registerComponent('click-me', {
ComponentClass: ClickMeComponent
});
var outer = void 0;
var OuterComponent = _helpers.Component.extend({
clicked: 0,
actions: {
'on-click': function () {
this.incrementProperty('clicked');
}
},
init: function () {
var _this13 = this;
this._super();
outer = this;
this.set('onClick', function () {
return _this13.incrementProperty('clicked');
});
}
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: (0, _abstractTestCase.strip)(_templateObject)
});
this.render('{{outer-component foo=foo}}', { foo: 1 });
this.assertText('clicked: 0; foo: 1');
assert.equal(didReceiveAttrsFired, 3);
this.runTask(function () {
return _this14.rerender();
});
this.assertText('clicked: 0; foo: 1');
assert.equal(didReceiveAttrsFired, 3);
this.runTask(function () {
return (0, _emberMetal.set)(_this14.context, 'foo', 2);
});
this.assertText('clicked: 0; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
this.runTask(function () {
return _this14.$('#string-action').click();
});
this.assertText('clicked: 1; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
this.runTask(function () {
return _this14.$('#function-action').click();
});
this.assertText('clicked: 2; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
this.runTask(function () {
return (0, _emberMetal.set)(outer, 'onClick', function () {
outer.incrementProperty('clicked');
});
});
this.assertText('clicked: 2; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
this.runTask(function () {
return _this14.$('#function-action').click();
});
this.assertText('clicked: 3; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
this.runTask(function () {
return _this14.$('#mut-action').click();
});
this.assertText('clicked: 4; foo: 2');
assert.equal(didReceiveAttrsFired, 3);
};
return _class2;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/concat-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal'], function (_emberBabel, _testCase, _emberMetal) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: {{concat}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test it concats static arguments'] = function () {
this.render('{{concat "foo" " " "bar" " " "baz"}}');
this.assertText('foo bar baz');
};
_class.prototype['@test it updates for bound arguments'] = function () {
var _this2 = this;
this.render('{{concat model.first model.second}}', {
model: { first: 'one', second: 'two' }
});
this.assertText('onetwo');
this.runTask(function () {
return _this2.rerender();
});
this.assertText('onetwo');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'model.first', 'three');
});
this.assertText('threetwo');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'model.second', 'four');
});
this.assertText('threefour');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'model', { first: 'one', second: 'two' });
});
this.assertText('onetwo');
};
_class.prototype['@test it can be used as a sub-expression'] = function () {
var _this3 = this;
this.render('{{concat (concat model.first model.second) (concat model.third model.fourth)}}', {
model: {
first: 'one',
second: 'two',
third: 'three',
fourth: 'four'
}
});
this.assertText('onetwothreefour');
this.runTask(function () {
return _this3.rerender();
});
this.assertText('onetwothreefour');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'model.first', 'five');
});
this.assertText('fivetwothreefour');
this.runTask(function () {
(0, _emberMetal.set)(_this3.context, 'model.second', 'six');
(0, _emberMetal.set)(_this3.context, 'model.third', 'seven');
});
this.assertText('fivesixsevenfour');
this.runTask(function () {
(0, _emberMetal.set)(_this3.context, 'model', {
first: 'one',
second: 'two',
third: 'three',
fourth: 'four'
});
});
this.assertText('onetwothreefour');
};
_class.prototype['@test it can be used as input for other helpers'] = function () {
var _this4 = this;
this.registerHelper('x-eq', function (_ref) {
var actual = _ref[0],
expected = _ref[1];
return actual === expected;
});
this.render('{{#if (x-eq (concat model.first model.second) "onetwo")}}Truthy!{{else}}False{{/if}}', {
model: {
first: 'one',
second: 'two'
}
});
this.assertText('Truthy!');
this.runTask(function () {
return _this4.rerender();
});
this.assertText('Truthy!');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'model.first', 'three');
});
this.assertText('False');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'model', { first: 'one', second: 'two' });
});
this.assertText('Truthy!');
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/custom-helper-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'internal-test-helpers', 'ember-metal', 'ember-utils'], function (_emberBabel, _testCase, _internalTestHelpers, _emberMetal, _emberUtils) {
'use strict';
/* globals EmberDev */
var assert = QUnit.assert,
HelperMutatingArgsTests;
(0, _testCase.moduleFor)('Helpers test: custom helpers', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test it cannot override built-in syntax'] = function () {
var _this2 = this;
this.registerHelper('if', function () {
return 'Nope';
});
expectAssertion(function () {
_this2.render('{{if foo \'LOL\'}}', { foo: true });
}, /You attempted to overwrite the built-in helper \"if\" which is not allowed. Please rename the helper./);
};
_class.prototype['@test it can resolve custom simple helpers with or without dashes'] = function () {
var _this3 = this;
this.registerHelper('hello', function () {
return 'hello';
});
this.registerHelper('hello-world', function () {
return 'hello world';
});
this.render('{{hello}} | {{hello-world}}');
this.assertText('hello | hello world');
this.runTask(function () {
return _this3.rerender();
});
this.assertText('hello | hello world');
};
_class.prototype['@test it does not resolve helpers with a `.` (period)'] = function () {
var _this4 = this;
this.registerHelper('hello.world', function () {
return 'hello world';
});
this.render('{{hello.world}}', {
hello: {
world: ''
}
});
this.assertText('');
this.assertStableRerender();
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'hello', { world: 'hello world!' });
});
this.assertText('hello world!');
this.runTask(function () {
(0, _emberMetal.set)(_this4.context, 'hello', {
world: ''
});
});
this.assertText('');
};
_class.prototype['@test it can resolve custom class-based helpers with or without dashes'] = function () {
var _this5 = this;
this.registerHelper('hello', {
compute: function () {
return 'hello';
}
});
this.registerHelper('hello-world', {
compute: function () {
return 'hello world';
}
});
this.render('{{hello}} | {{hello-world}}');
this.assertText('hello | hello world');
this.runTask(function () {
return _this5.rerender();
});
this.assertText('hello | hello world');
};
_class.prototype['@test throws if `this._super` is not called from `init`'] = function () {
var _this6 = this;
this.registerHelper('hello-world', {
init: function () {}
});
expectAssertion(function () {
_this6.render('{{hello-world}}');
}, /You must call `this._super\(...arguments\);` when overriding `init` on a framework object. Please update .* to call `this._super\(...arguments\);` from `init`./);
};
_class.prototype['@test class-based helper can recompute a new value'] = function () {
var _this7 = this;
var destroyCount = 0;
var computeCount = 0;
var helper = void 0;
this.registerHelper('hello-world', {
init: function () {
this._super.apply(this, arguments);
helper = this;
},
compute: function () {
return ++computeCount;
},
destroy: function () {
destroyCount++;
this._super();
}
});
this.render('{{hello-world}}');
this.assertText('1');
this.runTask(function () {
return _this7.rerender();
});
this.assertText('1');
this.runTask(function () {
return helper.recompute();
});
this.assertText('2');
assert.strictEqual(destroyCount, 0, 'destroy is not called on recomputation');
};
_class.prototype['@test class-based helper with static arguments can recompute a new value'] = function () {
var _this8 = this;
var destroyCount = 0;
var computeCount = 0;
var helper = void 0;
this.registerHelper('hello-world', {
init: function () {
this._super.apply(this, arguments);
helper = this;
},
compute: function () {
return ++computeCount;
},
destroy: function () {
destroyCount++;
this._super();
}
});
this.render('{{hello-world "whut"}}');
this.assertText('1');
this.runTask(function () {
return _this8.rerender();
});
this.assertText('1');
this.runTask(function () {
return helper.recompute();
});
this.assertText('2');
assert.strictEqual(destroyCount, 0, 'destroy is not called on recomputation');
};
_class.prototype['@test helper params can be returned'] = function () {
this.registerHelper('hello-world', function (values) {
return values;
});
this.render('{{#each (hello-world model) as |item|}}({{item}}){{/each}}', {
model: ['bob']
});
this.assertText('(bob)');
};
_class.prototype['@test helper hash can be returned'] = function () {
this.registerHelper('hello-world', function (_, hash) {
return hash.model;
});
this.render('{{get (hello-world model=model) \'name\'}}', {
model: { name: 'bob' }
});
this.assertText('bob');
};
_class.prototype['@test simple helper is called for param changes'] = function () {
var _this9 = this;
var computeCount = 0;
this.registerHelper('hello-world', function (_ref) {
var value = _ref[0];
computeCount++;
return value + '-value';
});
this.render('{{hello-world model.name}}', {
model: { name: 'bob' }
});
this.assertText('bob-value');
assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time');
this.runTask(function () {
return _this9.rerender();
});
this.assertText('bob-value');
assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'model.name', 'sal');
});
this.assertText('sal-value');
assert.strictEqual(computeCount, 2, 'compute is called exactly 2 times');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'model', { name: 'bob' });
});
this.assertText('bob-value');
assert.strictEqual(computeCount, 3, 'compute is called exactly 3 times');
};
_class.prototype['@test class-based helper compute is called for param changes'] = function () {
var _this10 = this;
var createCount = 0;
var computeCount = 0;
this.registerHelper('hello-world', {
init: function () {
this._super.apply(this, arguments);
createCount++;
},
compute: function (_ref2) {
var value = _ref2[0];
computeCount++;
return value + '-value';
}
});
this.render('{{hello-world model.name}}', {
model: { name: 'bob' }
});
this.assertText('bob-value');
assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time');
this.runTask(function () {
return _this10.rerender();
});
this.assertText('bob-value');
assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'model.name', 'sal');
});
this.assertText('sal-value');
assert.strictEqual(computeCount, 2, 'compute is called exactly 2 times');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'model', { name: 'bob' });
});
this.assertText('bob-value');
assert.strictEqual(computeCount, 3, 'compute is called exactly 3 times');
assert.strictEqual(createCount, 1, 'helper is only created once');
};
_class.prototype['@test simple helper receives params, hash'] = function () {
var _this11 = this;
this.registerHelper('hello-world', function (_params, _hash) {
return 'params: ' + JSON.stringify(_params) + ', hash: ' + JSON.stringify(_hash);
});
this.render('{{hello-world model.name "rich" first=model.age last="sam"}}', {
model: {
name: 'bob',
age: 42
}
});
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
this.runTask(function () {
return _this11.rerender();
});
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'model.name', 'sal');
});
this.assertText('params: ["sal","rich"], hash: {"first":42,"last":"sam"}');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'model.age', 28);
});
this.assertText('params: ["sal","rich"], hash: {"first":28,"last":"sam"}');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'model', { name: 'bob', age: 42 });
});
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
};
_class.prototype['@test class-based helper receives params, hash'] = function () {
var _this12 = this;
this.registerHelper('hello-world', {
compute: function (_params, _hash) {
return 'params: ' + JSON.stringify(_params) + ', hash: ' + JSON.stringify(_hash);
}
});
this.render('{{hello-world model.name "rich" first=model.age last="sam"}}', {
model: {
name: 'bob',
age: 42
}
});
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
this.runTask(function () {
return _this12.rerender();
});
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
this.runTask(function () {
return (0, _emberMetal.set)(_this12.context, 'model.name', 'sal');
});
this.assertText('params: ["sal","rich"], hash: {"first":42,"last":"sam"}');
this.runTask(function () {
return (0, _emberMetal.set)(_this12.context, 'model.age', 28);
});
this.assertText('params: ["sal","rich"], hash: {"first":28,"last":"sam"}');
this.runTask(function () {
return (0, _emberMetal.set)(_this12.context, 'model', { name: 'bob', age: 42 });
});
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
};
_class.prototype['@test class-based helper usable in subexpressions'] = function () {
var _this13 = this;
this.registerHelper('join-words', {
compute: function (params) {
return params.join(' ');
}
});
this.render('{{join-words "Who"\n (join-words "overcomes" "by")\n model.reason\n (join-words (join-words "hath overcome but" "half"))\n (join-words "his" (join-words "foe"))}}', { model: { reason: 'force' } });
this.assertText('Who overcomes by force hath overcome but half his foe');
this.runTask(function () {
return _this13.rerender();
});
this.assertText('Who overcomes by force hath overcome but half his foe');
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'model.reason', 'Nickleback');
});
this.assertText('Who overcomes by Nickleback hath overcome but half his foe');
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'model', { reason: 'force' });
});
this.assertText('Who overcomes by force hath overcome but half his foe');
};
_class.prototype['@test parameterless helper is usable in subexpressions'] = function () {
var _this14 = this;
this.registerHelper('should-show', function () {
return true;
});
this.render('{{#if (should-show)}}true{{/if}}');
this.assertText('true');
this.runTask(function () {
return _this14.rerender();
});
this.assertText('true');
};
_class.prototype['@test parameterless helper is usable in attributes'] = function () {
var _this15 = this;
this.registerHelper('foo-bar', function () {
return 'baz';
});
this.render('
');
this.assertHTML('
');
this.runTask(function () {
return _this15.rerender();
});
this.assertHTML('
');
};
_class.prototype['@test simple helper not usable with a block'] = function () {
var _this16 = this;
this.registerHelper('some-helper', function () {});
expectAssertion(function () {
_this16.render('{{#some-helper}}{{/some-helper}}');
}, /Helpers may not be used in the block form/);
};
_class.prototype['@test class-based helper not usable with a block'] = function () {
var _this17 = this;
this.registerHelper('some-helper', {
compute: function () {}
});
expectAssertion(function () {
_this17.render('{{#some-helper}}{{/some-helper}}');
}, /Helpers may not be used in the block form/);
};
_class.prototype['@test simple helper not usable within element'] = function () {
var _this18 = this;
this.registerHelper('some-helper', function () {});
this.assert.throws(function () {
_this18.render('
');
}, /Compile Error some-helper is not a modifier: Helpers may not be used in the element form/);
};
_class.prototype['@test class-based helper not usable within element'] = function () {
var _this19 = this;
this.registerHelper('some-helper', {
compute: function () {}
});
this.assert.throws(function () {
_this19.render('
');
}, /Compile Error some-helper is not a modifier: Helpers may not be used in the element form/);
};
_class.prototype['@test class-based helper is torn down'] = function () {
var destroyCalled = 0;
this.registerHelper('some-helper', {
destroy: function () {
destroyCalled++;
this._super.apply(this, arguments);
},
compute: function () {
return 'must define a compute';
}
});
this.render('{{some-helper}}');
(0, _internalTestHelpers.runDestroy)(this.component);
assert.strictEqual(destroyCalled, 1, 'destroy called once');
};
_class.prototype['@test class-based helper used in subexpression can recompute'] = function () {
var _this20 = this;
var helper = void 0;
var phrase = 'overcomes by';
this.registerHelper('dynamic-segment', {
init: function () {
this._super.apply(this, arguments);
helper = this;
},
compute: function () {
return phrase;
}
});
this.registerHelper('join-words', {
compute: function (params) {
return params.join(' ');
}
});
this.render('{{join-words "Who"\n (dynamic-segment)\n "force"\n (join-words (join-words "hath overcome but" "half"))\n (join-words "his" (join-words "foe"))}}');
this.assertText('Who overcomes by force hath overcome but half his foe');
this.runTask(function () {
return _this20.rerender();
});
this.assertText('Who overcomes by force hath overcome but half his foe');
phrase = 'believes his';
this.runTask(function () {
return helper.recompute();
});
this.assertText('Who believes his force hath overcome but half his foe');
phrase = 'overcomes by';
this.runTask(function () {
return helper.recompute();
});
this.assertText('Who overcomes by force hath overcome but half his foe');
};
_class.prototype['@test class-based helper used in subexpression can recompute component'] = function () {
var _this21 = this;
var helper = void 0;
var phrase = 'overcomes by';
this.registerHelper('dynamic-segment', {
init: function () {
this._super.apply(this, arguments);
helper = this;
},
compute: function () {
return phrase;
}
});
this.registerHelper('join-words', {
compute: function (params) {
return params.join(' ');
}
});
this.registerComponent('some-component', {
template: '{{first}} {{second}} {{third}} {{fourth}} {{fifth}}'
});
this.render('{{some-component first="Who"\n second=(dynamic-segment)\n third="force"\n fourth=(join-words (join-words "hath overcome but" "half"))\n fifth=(join-words "his" (join-words "foe"))}}');
this.assertText('Who overcomes by force hath overcome but half his foe');
this.runTask(function () {
return _this21.rerender();
});
this.assertText('Who overcomes by force hath overcome but half his foe');
phrase = 'believes his';
this.runTask(function () {
return helper.recompute();
});
this.assertText('Who believes his force hath overcome but half his foe');
phrase = 'overcomes by';
this.runTask(function () {
return helper.recompute();
});
this.assertText('Who overcomes by force hath overcome but half his foe');
};
_class.prototype['@test class-based helper used in subexpression is destroyed'] = function () {
var destroyCount = 0;
this.registerHelper('dynamic-segment', {
phrase: 'overcomes by',
init: function () {
this._super.apply(this, arguments);
},
compute: function () {
return this.phrase;
},
destroy: function () {
destroyCount++;
this._super.apply(this, arguments);
}
});
this.registerHelper('join-words', {
compute: function (params) {
return params.join(' ');
}
});
this.render('{{join-words "Who"\n (dynamic-segment)\n "force"\n (join-words (join-words "hath overcome but" "half"))\n (join-words "his" (join-words "foe"))}}');
(0, _internalTestHelpers.runDestroy)(this.component);
equal(destroyCount, 1, 'destroy is called after a view is destroyed');
};
return _class;
}(_testCase.RenderingTest));
// these feature detects prevent errors in these tests
// on platforms (*cough* IE9 *cough*) that do not
// property support `Object.freeze`
var pushingIntoFrozenArrayThrows = function () {
var array = [];
Object.freeze(array);
try {
array.push('foo');
return false;
} catch (e) {
return true;
}
}();
var assigningExistingFrozenPropertyThrows = function () {
var obj = { foo: 'asdf' };
Object.freeze(obj);
try {
obj.foo = 'derp';
return false;
} catch (e) {
return true;
}
}();
var addingPropertyToFrozenObjectThrows = function () {
var obj = { foo: 'asdf' };
Object.freeze(obj);
try {
obj.bar = 'derp';
return false;
} catch (e) {
return true;
}
}();
if (!EmberDev.runningProdBuild && _emberUtils.HAS_NATIVE_WEAKMAP && (pushingIntoFrozenArrayThrows || assigningExistingFrozenPropertyThrows || addingPropertyToFrozenObjectThrows)) {
HelperMutatingArgsTests = function (_RenderingTest2) {
(0, _emberBabel.inherits)(HelperMutatingArgsTests, _RenderingTest2);
function HelperMutatingArgsTests() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments));
}
HelperMutatingArgsTests.prototype.buildCompute = function () {
var _this23 = this;
return function (params, hash) {
if (pushingIntoFrozenArrayThrows) {
_this23.assert.throws(function () {
params.push('foo');
// cannot assert error message as it varies by platform
});
}
if (assigningExistingFrozenPropertyThrows) {
_this23.assert.throws(function () {
hash.foo = 'bar';
// cannot assert error message as it varies by platform
});
}
if (addingPropertyToFrozenObjectThrows) {
_this23.assert.throws(function () {
hash.someUnusedHashProperty = 'bar';
// cannot assert error message as it varies by platform
});
}
};
};
HelperMutatingArgsTests.prototype['@test cannot mutate params - no positional specified / named specified'] = function () {
this.render('{{test-helper foo=bar}}', { bar: 'derp' });
};
HelperMutatingArgsTests.prototype['@test cannot mutate params - positional specified / no named specified'] = function () {
this.render('{{test-helper bar}}', { bar: 'derp' });
};
HelperMutatingArgsTests.prototype['@test cannot mutate params - positional specified / named specified'] = function () {
this.render('{{test-helper bar foo=qux}}', { bar: 'derp', qux: 'baz' });
};
HelperMutatingArgsTests.prototype['@test cannot mutate params - no positional specified / no named specified'] = function () {
this.render('{{test-helper}}', { bar: 'derp', qux: 'baz' });
};
return HelperMutatingArgsTests;
}(_testCase.RenderingTest);
(0, _testCase.moduleFor)('Helpers test: mutation triggers errors - class based helper', function (_HelperMutatingArgsTe) {
(0, _emberBabel.inherits)(_class2, _HelperMutatingArgsTe);
function _class2() {
var _this24 = (0, _emberBabel.possibleConstructorReturn)(this, _HelperMutatingArgsTe.call(this));
var compute = _this24.buildCompute();
_this24.registerHelper('test-helper', {
compute: compute
});
return _this24;
}
return _class2;
}(HelperMutatingArgsTests));
(0, _testCase.moduleFor)('Helpers test: mutation triggers errors - simple helper', function (_HelperMutatingArgsTe2) {
(0, _emberBabel.inherits)(_class3, _HelperMutatingArgsTe2);
function _class3() {
var _this25 = (0, _emberBabel.possibleConstructorReturn)(this, _HelperMutatingArgsTe2.call(this));
var compute = _this25.buildCompute();
_this25.registerHelper('test-helper', compute);
return _this25;
}
return _class3;
}(HelperMutatingArgsTests));
}
});
enifed('ember-glimmer/tests/integration/helpers/element-action-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal', 'ember-runtime', 'ember-views'], function (_emberBabel, _testCase, _abstractTestCase, _helpers, _emberMetal, _emberRuntime, _emberViews) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#inner-component}}\n
Wat me! \n {{/inner-component}}\n '], ['\n {{#inner-component}}\n
Wat me! \n {{/inner-component}}\n ']),
_templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#target-component as |parent|}}\n {{other-component anotherTarget=parent}}\n {{/target-component}}\n '], ['\n {{#target-component as |parent|}}\n {{other-component anotherTarget=parent}}\n {{/target-component}}\n ']),
_templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#target-component as |aTarget|}}\n
click me \n {{/target-component}}\n '], ['\n {{#target-component as |aTarget|}}\n
click me \n {{/target-component}}\n ']),
_templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
click me '], ['\n
click me ']),
_templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#middle-component}}\n {{inner-component action="hey"}}\n {{/middle-component}}\n '], ['\n {{#middle-component}}\n {{inner-component action="hey"}}\n {{/middle-component}}\n ']),
_templateObject6 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n
Click Me \n {{yield}}\n '], ['\n
Click Me \n {{yield}}\n ']);
function getActionAttributes(element) {
var attributes = element.attributes,
i,
attr;
var actionAttrs = [];
for (i = 0; i < attributes.length; i++) {
attr = attributes.item(i);
if (attr.name.indexOf('data-ember-action-') === 0) {
actionAttrs.push(attr.name);
}
}
return actionAttrs;
}
function getActionIds(element) {
return getActionAttributes(element).map(function (attribute) {
return attribute.slice('data-ember-action-'.length);
});
}
(0, _testCase.moduleFor)('Helpers test: element action', function (_RenderingTest2) {
(0, _emberBabel.inherits)(_class2, _RenderingTest2);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments));
}
_class2.prototype['@test it can call an action on its enclosing component'] = function () {
var _this4 = this;
var fooCallCount = 0;
var ExampleComponent = _helpers.Component.extend({
actions: {
foo: function () {
fooCallCount++;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Click me '
});
this.render('{{example-component}}');
this.assert.equal(fooCallCount, 0, 'foo has not been called');
this.runTask(function () {
return _this4.rerender();
});
this.assert.equal(fooCallCount, 0, 'foo has not been called');
this.runTask(function () {
_this4.$('button').click();
});
this.assert.equal(fooCallCount, 1, 'foo has been called 1 time');
this.runTask(function () {
_this4.$('button').click();
});
this.assert.equal(fooCallCount, 2, 'foo has been called 2 times');
};
_class2.prototype['@test it can call an action with parameters'] = function () {
var _this5 = this;
var fooArgs = [];
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
member: 'a',
init: function () {
this._super.apply(this, arguments);
component = this;
},
actions: {
foo: function (thing) {
fooArgs.push(thing);
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Click me '
});
this.render('{{example-component}}');
this.assert.deepEqual(fooArgs, [], 'foo has not been called');
this.runTask(function () {
return _this5.rerender();
});
this.assert.deepEqual(fooArgs, [], 'foo has not been called');
this.runTask(function () {
_this5.$('button').click();
});
this.assert.deepEqual(fooArgs, ['a'], 'foo has not been called');
this.runTask(function () {
component.set('member', 'b');
});
this.runTask(function () {
_this5.$('button').click();
});
this.assert.deepEqual(fooArgs, ['a', 'b'], 'foo has been called with an updated value');
};
_class2.prototype['@test it should output a marker attribute with a guid'] = function () {
this.render('
me the money ');
var button = this.$('button');
var attributes = getActionAttributes(button.get(0));
this.assert.ok(button.attr('data-ember-action').match(''), 'An empty data-ember-action attribute was added');
this.assert.ok(attributes[0].match(/data-ember-action-\d+/), 'A data-ember-action-xyz attribute with a guid was added');
};
_class2.prototype['@test it should allow alternative events to be handled'] = function () {
var _this6 = this;
var showCalled = false;
var ExampleComponent = _helpers.Component.extend({
actions: {
show: function () {
showCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
'
});
this.render('{{example-component}}');
this.runTask(function () {
var event = _emberViews.jQuery.Event('mouseup');
_this6.$('#show').trigger(event);
});
this.assert.ok(showCalled, 'show action was called on mouseUp');
};
_class2.prototype['@test inside a yield, the target points at the original target'] = function () {
var _this7 = this;
var targetWatted = false;
var innerWatted = false;
var TargetComponent = _helpers.Component.extend({
actions: {
wat: function () {
targetWatted = true;
}
}
});
var InnerComponent = _helpers.Component.extend({
actions: {
wat: function () {
innerWatted = true;
}
}
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: '{{yield}}'
});
this.registerComponent('target-component', {
ComponentClass: TargetComponent,
template: (0, _abstractTestCase.strip)(_templateObject)
});
this.render('{{target-component}}');
this.runTask(function () {
_this7.$('button').click();
});
this.assert.ok(targetWatted, 'the correct target was watted');
this.assert.notOk(innerWatted, 'the inner target was not watted');
};
_class2.prototype['@test it should allow a target to be specified'] = function () {
var _this8 = this;
var targetWatted = false;
var TargetComponent = _helpers.Component.extend({
actions: {
wat: function () {
targetWatted = true;
}
}
});
var OtherComponent = _helpers.Component.extend({});
this.registerComponent('target-component', {
ComponentClass: TargetComponent,
template: '{{yield this}}'
});
this.registerComponent('other-component', {
ComponentClass: OtherComponent,
template: '
Wat? '
});
this.render((0, _abstractTestCase.strip)(_templateObject2));
this.runTask(function () {
_this8.$('a').click();
});
this.assert.equal(targetWatted, true, 'the specified target was watted');
};
_class2.prototype['@test it should lazily evaluate the target'] = function () {
var _this9 = this;
var firstEdit = 0;
var secondEdit = 0;
var component = void 0;
var second = {
edit: function () {
secondEdit++;
}
};
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
theTarget: {
edit: function () {
firstEdit++;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Edit '
});
this.render('{{example-component}}');
this.runTask(function () {
_this9.$('a').click();
});
this.assert.equal(firstEdit, 1);
this.runTask(function () {
(0, _emberMetal.set)(component, 'theTarget', second);
});
this.runTask(function () {
_this9.$('a').click();
});
this.assert.equal(firstEdit, 1);
this.assert.equal(secondEdit, 1);
};
_class2.prototype['@test it should register an event handler'] = function () {
var _this10 = this;
var editHandlerWasCalled = false;
var shortcutHandlerWasCalled = false;
var ExampleComponent = _helpers.Component.extend({
actions: {
edit: function () {
editHandlerWasCalled = true;
},
shortcut: function () {
shortcutHandlerWasCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
click me click me too
'
});
this.render('{{example-component}}');
this.runTask(function () {
var event = _emberViews.jQuery.Event('click');
event.altKey = true;
_this10.$('a[data-ember-action]').trigger(event);
});
this.assert.equal(editHandlerWasCalled, true, 'the event handler was called');
this.runTask(function () {
var event = _emberViews.jQuery.Event('click');
event.ctrlKey = true;
_this10.$('div[data-ember-action]').trigger(event);
});
this.assert.equal(shortcutHandlerWasCalled, true, 'the "any" shortcut\'s event handler was called');
};
_class2.prototype['@test it handles whitelisted bound modifier keys'] = function () {
var _this11 = this;
var editHandlerWasCalled = false;
var shortcutHandlerWasCalled = false;
var ExampleComponent = _helpers.Component.extend({
altKey: 'alt',
anyKey: 'any',
actions: {
edit: function () {
editHandlerWasCalled = true;
},
shortcut: function () {
shortcutHandlerWasCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
click me click me too
'
});
this.render('{{example-component}}');
this.runTask(function () {
var event = _emberViews.jQuery.Event('click');
event.altKey = true;
_this11.$('a[data-ember-action]').trigger(event);
});
this.assert.equal(editHandlerWasCalled, true, 'the event handler was called');
this.runTask(function () {
var event = _emberViews.jQuery.Event('click');
event.ctrlKey = true;
_this11.$('div[data-ember-action]').trigger(event);
});
this.assert.equal(shortcutHandlerWasCalled, true, 'the "any" shortcut\'s event handler was called');
};
_class2.prototype['@test it handles whitelisted bound modifier keys with current value'] = function () {
var _this12 = this;
var editHandlerWasCalled = false;
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
acceptedKeys: 'alt',
actions: {
edit: function () {
editHandlerWasCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
click me '
});
this.render('{{example-component}}');
this.runTask(function () {
var event = _emberViews.jQuery.Event('click');
event.altKey = true;
_this12.$('a[data-ember-action]').trigger(event);
});
this.assert.equal(editHandlerWasCalled, true, 'the event handler was called');
editHandlerWasCalled = false;
this.runTask(function () {
component.set('acceptedKeys', '');
});
this.runTask(function () {
var event = _emberViews.jQuery.Event('click');
_this12.$('div[data-ember-action]').trigger(event);
});
this.assert.equal(editHandlerWasCalled, false, 'the event handler was not called');
};
_class2.prototype['@test should be able to use action more than once for the same event within a view'] = function () {
var _this13 = this;
var editHandlerWasCalled = false;
var deleteHandlerWasCalled = false;
var originalHandlerWasCalled = false;
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
actions: {
edit: function () {
editHandlerWasCalled = true;
},
'delete': function () {
deleteHandlerWasCalled = true;
}
},
click: function () {
originalHandlerWasCalled = true;
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
edit delete '
});
this.render('{{example-component}}');
this.runTask(function () {
_this13.$('#edit').click();
});
this.assert.equal(editHandlerWasCalled, true, 'the edit action was called');
this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called');
this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called (due to bubbling)');
editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false;
this.runTask(function () {
_this13.$('#delete').click();
});
this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called');
this.assert.equal(deleteHandlerWasCalled, true, 'the delete action was called');
this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called (due to bubbling)');
editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false;
this.runTask(function () {
component.$().click();
});
this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called');
this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called');
this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called');
};
_class2.prototype['@test the event should not bubble if `bubbles=false` is passed'] = function () {
var _this14 = this;
var editHandlerWasCalled = false;
var deleteHandlerWasCalled = false;
var originalHandlerWasCalled = false;
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
actions: {
edit: function () {
editHandlerWasCalled = true;
},
'delete': function () {
deleteHandlerWasCalled = true;
}
},
click: function () {
originalHandlerWasCalled = true;
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
edit delete '
});
this.render('{{example-component}}');
this.runTask(function () {
_this14.$('#edit').click();
});
this.assert.equal(editHandlerWasCalled, true, 'the edit action was called');
this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called');
this.assert.equal(originalHandlerWasCalled, false, 'the click handler was not called');
editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false;
this.runTask(function () {
_this14.$('#delete').click();
});
this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called');
this.assert.equal(deleteHandlerWasCalled, true, 'the delete action was called');
this.assert.equal(originalHandlerWasCalled, false, 'the click handler was not called');
editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false;
this.runTask(function () {
component.$().click();
});
this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called');
this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called');
this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called');
};
_class2.prototype['@test the event should not bubble if `bubbles=false` is passed bound'] = function () {
var _this15 = this;
var editHandlerWasCalled = false;
var deleteHandlerWasCalled = false;
var originalHandlerWasCalled = false;
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
isFalse: false,
actions: {
edit: function () {
editHandlerWasCalled = true;
},
'delete': function () {
deleteHandlerWasCalled = true;
}
},
click: function () {
originalHandlerWasCalled = true;
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
edit delete '
});
this.render('{{example-component}}');
this.runTask(function () {
_this15.$('#edit').click();
});
this.assert.equal(editHandlerWasCalled, true, 'the edit action was called');
this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called');
this.assert.equal(originalHandlerWasCalled, false, 'the click handler was not called');
editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false;
this.runTask(function () {
_this15.$('#delete').click();
});
this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called');
this.assert.equal(deleteHandlerWasCalled, true, 'the delete action was called');
this.assert.equal(originalHandlerWasCalled, false, 'the click handler was not called');
editHandlerWasCalled = deleteHandlerWasCalled = originalHandlerWasCalled = false;
this.runTask(function () {
component.$().click();
});
this.assert.equal(editHandlerWasCalled, false, 'the edit action was not called');
this.assert.equal(deleteHandlerWasCalled, false, 'the delete action was not called');
this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called');
};
_class2.prototype['@test the bubbling depends on the bound parameter'] = function () {
var _this16 = this;
var editHandlerWasCalled = false;
var originalHandlerWasCalled = false;
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
shouldBubble: false,
actions: {
edit: function () {
editHandlerWasCalled = true;
}
},
click: function () {
originalHandlerWasCalled = true;
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
edit '
});
this.render('{{example-component}}');
this.runTask(function () {
_this16.$('#edit').click();
});
this.assert.equal(editHandlerWasCalled, true, 'the edit action was called');
this.assert.equal(originalHandlerWasCalled, false, 'the click handler was not called');
editHandlerWasCalled = originalHandlerWasCalled = false;
this.runTask(function () {
component.set('shouldBubble', true);
});
this.runTask(function () {
_this16.$('#edit').click();
});
this.assert.equal(editHandlerWasCalled, true, 'the edit action was called');
this.assert.equal(originalHandlerWasCalled, true, 'the click handler was called');
};
_class2.prototype['@test it should work properly in an #each block'] = function () {
var _this17 = this;
var editHandlerWasCalled = false;
var ExampleComponent = _helpers.Component.extend({
items: (0, _emberRuntime.A)([1, 2, 3, 4]),
actions: {
edit: function () {
editHandlerWasCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '{{#each items as |item|}}
click me {{/each}}'
});
this.render('{{example-component}}');
this.runTask(function () {
_this17.$('a').click();
});
this.assert.equal(editHandlerWasCalled, true, 'the event handler was called');
};
_class2.prototype['@test it should work properly in a {{#with foo as |bar|}} block'] = function () {
var _this18 = this;
var editHandlerWasCalled = false;
var ExampleComponent = _helpers.Component.extend({
something: { ohai: 'there' },
actions: {
edit: function () {
editHandlerWasCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '{{#with something as |somethingElse|}}
click me {{/with}}'
});
this.render('{{example-component}}');
this.runTask(function () {
_this18.$('a').click();
});
this.assert.equal(editHandlerWasCalled, true, 'the event handler was called');
};
_class2.prototype['@test it should unregister event handlers when an element action is removed'] = function () {
var _this19 = this;
var ExampleComponent = _helpers.Component.extend({
actions: {
edit: function () {}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '{{#if isActive}}
click me {{/if}}'
});
this.render('{{example-component isActive=isActive}}', { isActive: true });
equal(this.$('a[data-ember-action]').length, 1, 'The element is rendered');
var actionId = void 0;
actionId = getActionIds(this.$('a[data-ember-action]').get(0))[0];
ok(_emberViews.ActionManager.registeredActions[actionId], 'An action is registered');
this.runTask(function () {
return _this19.rerender();
});
equal(this.$('a[data-ember-action]').length, 1, 'The element is still present');
ok(_emberViews.ActionManager.registeredActions[actionId], 'The action is still registered');
this.runTask(function () {
return (0, _emberMetal.set)(_this19.context, 'isActive', false);
});
strictEqual(this.$('a[data-ember-action]').length, 0, 'The element is removed');
ok(!_emberViews.ActionManager.registeredActions[actionId], 'The action is unregistered');
this.runTask(function () {
return (0, _emberMetal.set)(_this19.context, 'isActive', true);
});
equal(this.$('a[data-ember-action]').length, 1, 'The element is rendered');
actionId = getActionIds(this.$('a[data-ember-action]').get(0))[0];
ok(_emberViews.ActionManager.registeredActions[actionId], 'A new action is registered');
};
_class2.prototype['@test it should capture events from child elements and allow them to trigger the action'] = function () {
var _this20 = this;
var editHandlerWasCalled = false;
var ExampleComponent = _helpers.Component.extend({
actions: {
edit: function () {
editHandlerWasCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
click me
'
});
this.render('{{example-component}}');
this.runTask(function () {
_this20.$('button').click();
});
this.assert.ok(editHandlerWasCalled, 'event on a child target triggered the action of its parent');
};
_class2.prototype['@test it should allow bubbling of events from action helper to original parent event'] = function () {
var _this21 = this;
var editHandlerWasCalled = false;
var originalHandlerWasCalled = false;
var ExampleComponent = _helpers.Component.extend({
actions: {
edit: function () {
editHandlerWasCalled = true;
}
},
click: function () {
originalHandlerWasCalled = true;
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
click me '
});
this.render('{{example-component}}');
this.runTask(function () {
_this21.$('a').click();
});
this.assert.ok(editHandlerWasCalled && originalHandlerWasCalled, 'both event handlers were called');
};
_class2.prototype['@test it should not bubble an event from action helper to original parent event if `bubbles=false` is passed'] = function () {
var _this22 = this;
var editHandlerWasCalled = false;
var originalHandlerWasCalled = false;
var ExampleComponent = _helpers.Component.extend({
actions: {
edit: function () {
editHandlerWasCalled = true;
}
},
click: function () {
originalHandlerWasCalled = true;
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
click me '
});
this.render('{{example-component}}');
this.runTask(function () {
_this22.$('a').click();
});
this.assert.ok(editHandlerWasCalled, 'the child event handler was called');
this.assert.notOk(originalHandlerWasCalled, 'the parent handler was not called');
};
_class2.prototype['@test it should allow "send" as the action name (#594)'] = function () {
var _this23 = this;
var sendHandlerWasCalled = false;
var ExampleComponent = _helpers.Component.extend({
actions: {
send: function () {
sendHandlerWasCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
click me '
});
this.render('{{example-component}}');
this.runTask(function () {
_this23.$('a').click();
});
this.assert.ok(sendHandlerWasCalled, 'the event handler was called');
};
_class2.prototype['@test it should send the view, event, and current context to the action'] = function () {
var _this24 = this;
var passedTarget = void 0;
var passedContext = void 0;
var targetThis = void 0;
var TargetComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
targetThis = this;
},
actions: {
edit: function (context) {
passedTarget = this === targetThis;
passedContext = context;
}
}
});
var aContext = void 0;
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
aContext = this;
}
});
this.registerComponent('target-component', {
ComponentClass: TargetComponent,
template: '{{yield this}}'
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: (0, _abstractTestCase.strip)(_templateObject3)
});
this.render('{{example-component}}');
this.runTask(function () {
_this24.$('#edit').click();
});
this.assert.ok(passedTarget, 'the action is called with the target as this');
this.assert.strictEqual(passedContext, aContext, 'the parameter is passed along');
};
_class2.prototype['@test it should only trigger actions for the event they were registered on'] = function () {
var _this25 = this;
var editHandlerWasCalled = false;
var ExampleComponent = _helpers.Component.extend({
actions: {
edit: function () {
editHandlerWasCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
click me '
});
this.render('{{example-component}}');
this.runTask(function () {
_this25.$('a').click();
});
this.assert.ok(editHandlerWasCalled, 'the event handler was called on click');
editHandlerWasCalled = false;
this.runTask(function () {
_this25.$('a').trigger('mouseover');
});
this.assert.notOk(editHandlerWasCalled, 'the event handler was not called on mouseover');
};
_class2.prototype['@test it should allow multiple contexts to be specified'] = function () {
var _this26 = this;
var passedContexts = void 0;
var models = [_emberRuntime.Object.create(), _emberRuntime.Object.create()];
var ExampleComponent = _helpers.Component.extend({
modelA: models[0],
modelB: models[1],
actions: {
edit: function () {
var _len, args, _key;
for (_len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
passedContexts = args;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
click me '
});
this.render('{{example-component}}');
this.runTask(function () {
_this26.$('button').click();
});
this.assert.deepEqual(passedContexts, models, 'the action was called with the passed contexts');
};
_class2.prototype['@test it should allow multiple contexts to be specified mixed with string args'] = function () {
var _this27 = this;
var passedContexts = void 0;
var model = _emberRuntime.Object.create();
var ExampleComponent = _helpers.Component.extend({
model: model,
actions: {
edit: function () {
var _len2, args, _key2;
for (_len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
passedContexts = args;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
click me '
});
this.render('{{example-component}}');
this.runTask(function () {
_this27.$('button').click();
});
this.assert.deepEqual(passedContexts, ['herp', model], 'the action was called with the passed contexts');
};
_class2.prototype['@test it should not trigger action with special clicks'] = function () {
var showCalled = false;
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
actions: {
show: function () {
showCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Howdy '
});
this.render('{{example-component}}');
var assert = this.assert;
function checkClick(prop, value, expected) {
var event = _emberViews.jQuery.Event('click');
event[prop] = value;
component.$('button').trigger(event);
if (expected) {
assert.ok(showCalled, 'should call action with ' + prop + ':' + value);
assert.ok(event.isDefaultPrevented(), 'should prevent default');
} else {
assert.notOk(showCalled, 'should not call action with ' + prop + ':' + value);
assert.notOk(event.isDefaultPrevented(), 'should not prevent default');
}
}
checkClick('ctrlKey', true, false);
checkClick('altKey', true, false);
checkClick('metaKey', true, false);
checkClick('shiftKey', true, false);
checkClick('which', 2, false);
checkClick('which', 1, true);
checkClick('which', undefined, true); // IE <9
};
_class2.prototype['@test it can trigger actions for keyboard events'] = function () {
var _this28 = this;
var showCalled = false;
var ExampleComponent = _helpers.Component.extend({
actions: {
show: function () {
showCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
'
});
this.render('{{example-component}}');
this.runTask(function () {
var event = _emberViews.jQuery.Event('keyup');
event.char = 'a';
event.which = 65;
_this28.$('input').trigger(event);
});
this.assert.ok(showCalled, 'the action was called with keyup');
};
_class2.prototype['@test a quoteless parameter should allow dynamic lookup of the actionName'] = function () {
var lastAction = void 0;
var actionOrder = [];
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
hookMeUp: 'rock',
actions: {
rock: function () {
lastAction = 'rock';
actionOrder.push('rock');
},
paper: function () {
lastAction = 'paper';
actionOrder.push('paper');
},
scissors: function () {
lastAction = 'scissors';
actionOrder.push('scissors');
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Whistle tips go woop woooop '
});
this.render('{{example-component}}');
var test = this;
function testBoundAction(propertyValue) {
test.runTask(function () {
component.set('hookMeUp', propertyValue);
});
test.runTask(function () {
component.$('#bound-param').click();
});
test.assert.ok(lastAction, propertyValue, 'lastAction set to ' + propertyValue);
}
testBoundAction('rock');
testBoundAction('paper');
testBoundAction('scissors');
this.assert.deepEqual(actionOrder, ['rock', 'paper', 'scissors'], 'action name was looked up properly');
};
_class2.prototype['@test a quoteless string parameter should resolve actionName, including path'] = function () {
var lastAction = void 0;
var actionOrder = [];
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
component = this;
},
allactions: (0, _emberRuntime.A)([{ title: 'Rock', name: 'rock' }, { title: 'Paper', name: 'paper' }, { title: 'Scissors', name: 'scissors' }]),
actions: {
rock: function () {
lastAction = 'rock';
actionOrder.push('rock');
},
paper: function () {
lastAction = 'paper';
actionOrder.push('paper');
},
scissors: function () {
lastAction = 'scissors';
actionOrder.push('scissors');
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '{{#each allactions as |allaction|}}
{{allaction.title}} {{/each}}'
});
this.render('{{example-component}}');
var test = this;
function testBoundAction(propertyValue) {
test.runTask(function () {
component.$('#' + propertyValue).click();
});
test.assert.ok(lastAction, propertyValue, 'lastAction set to ' + propertyValue);
}
testBoundAction('rock');
testBoundAction('paper');
testBoundAction('scissors');
this.assert.deepEqual(actionOrder, ['rock', 'paper', 'scissors'], 'action name was looked up properly');
};
_class2.prototype['@test a quoteless function parameter should be called, including arguments'] = function () {
var _this29 = this;
var submitCalled = false;
var incomingArg = void 0;
var arg = 'rough ray';
var ExampleComponent = _helpers.Component.extend({
submit: function (actualArg) {
incomingArg = actualArg;
submitCalled = true;
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Hi '
});
this.render('{{example-component}}');
this.runTask(function () {
_this29.$('a').click();
});
this.assert.ok(submitCalled, 'submit function called');
this.assert.equal(incomingArg, arg, 'argument passed');
};
_class2.prototype['@test a quoteless parameter that does not resolve to a value asserts'] = function () {
var _this30 = this;
var ExampleComponent = _helpers.Component.extend({
actions: {
ohNoeNotValid: function () {}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Hi '
});
expectAssertion(function () {
_this30.render('{{example-component}}');
}, 'You specified a quoteless path, `ohNoeNotValid`, to the {{action}} helper ' + 'which did not resolve to an action name (a string). ' + 'Perhaps you meant to use a quoted actionName? (e.g. {{action "ohNoeNotValid"}}).');
};
_class2.prototype['@test allows multiple actions on a single element'] = function () {
var _this31 = this;
var clickActionWasCalled = false;
var doubleClickActionWasCalled = false;
var ExampleComponent = _helpers.Component.extend({
actions: {
clicked: function () {
clickActionWasCalled = true;
},
doubleClicked: function () {
doubleClickActionWasCalled = true;
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: (0, _abstractTestCase.strip)(_templateObject4)
});
this.render('{{example-component}}');
this.runTask(function () {
_this31.$('a').trigger('click');
});
this.assert.ok(clickActionWasCalled, 'the clicked action was called');
this.runTask(function () {
_this31.$('a').trigger('dblclick');
});
this.assert.ok(doubleClickActionWasCalled, 'the doubleClicked action was called');
};
_class2.prototype['@test it should respect preventDefault option if provided'] = function () {
var _this32 = this;
var ExampleComponent = _helpers.Component.extend({
actions: {
show: function () {}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Hi '
});
this.render('{{example-component}}');
var event = _emberViews.jQuery.Event('click');
this.runTask(function () {
_this32.$('a').trigger(event);
});
this.assert.equal(event.isDefaultPrevented(), false, 'should not preventDefault');
};
_class2.prototype['@test it should respect preventDefault option if provided bound'] = function () {
var _this33 = this;
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
shouldPreventDefault: false,
init: function () {
this._super.apply(this, arguments);
component = this;
},
actions: {
show: function () {}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Hi '
});
this.render('{{example-component}}');
var event = _emberViews.jQuery.Event('click');
this.runTask(function () {
_this33.$('a').trigger(event);
});
this.assert.equal(event.isDefaultPrevented(), false, 'should not preventDefault');
event = _emberViews.jQuery.Event('click');
this.runTask(function () {
component.set('shouldPreventDefault', true);
_this33.$('a').trigger(event);
});
this.assert.equal(event.isDefaultPrevented(), true, 'should preventDefault');
};
_class2.prototype['@test it should target the proper component when `action` is in yielded block [GH #12409]'] = function () {
var _this34 = this;
var outerActionCalled = false;
var innerClickCalled = false;
var OuterComponent = _helpers.Component.extend({
actions: {
hey: function () {
outerActionCalled = true;
}
}
});
var MiddleComponent = _helpers.Component.extend({});
var InnerComponent = _helpers.Component.extend({
click: function () {
innerClickCalled = true;
this.sendAction();
}
});
this.registerComponent('outer-component', {
ComponentClass: OuterComponent,
template: (0, _abstractTestCase.strip)(_templateObject5)
});
this.registerComponent('middle-component', {
ComponentClass: MiddleComponent,
template: '{{yield}}'
});
this.registerComponent('inner-component', {
ComponentClass: InnerComponent,
template: (0, _abstractTestCase.strip)(_templateObject6)
});
this.render('{{outer-component}}');
this.runTask(function () {
_this34.$('button').click();
});
this.assert.ok(outerActionCalled, 'the action fired on the proper target');
this.assert.ok(innerClickCalled, 'the click was triggered');
};
_class2.prototype['@test element action with (mut undefinedThing) works properly'] = function () {
var _this35 = this;
var component = void 0;
var ExampleComponent = _helpers.Component.extend({
label: undefined,
init: function () {
this._super.apply(this, arguments);
component = this;
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
{{if label label "Click me"}} '
});
this.render('{{example-component}}');
this.assertText('Click me');
this.assertStableRerender();
this.runTask(function () {
_this35.$('button').click();
});
this.assertText('Clicked!');
this.runTask(function () {
component.set('label', 'Dun clicked');
});
this.assertText('Dun clicked');
this.runTask(function () {
_this35.$('button').click();
});
this.assertText('Clicked!');
this.runTask(function () {
component.set('label', undefined);
});
this.assertText('Click me');
};
_class2.prototype['@test it supports non-registered actions [GH#14888]'] = function () {
this.render('\n {{#if show}}\n
\n Show ({{show}})\n \n {{/if}}\n ', { show: true });
this.assert.equal(this.$('button').text().trim(), 'Show (true)');
// We need to focus in to simulate an actual click.
this.runTask(function () {
document.getElementById('ddButton').focus();
document.getElementById('ddButton').click();
});
};
_class2.prototype['@test action handler that shifts element attributes doesn\'t trigger multiple invocations'] = function () {
var _this36 = this;
var actionCount = 0;
var ExampleComponent = _helpers.Component.extend({
selected: false,
actions: {
toggleSelected: function () {
actionCount++;
this.toggleProperty('selected');
}
}
});
this.registerComponent('example-component', {
ComponentClass: ExampleComponent,
template: '
Toggle Selected '
});
this.render('{{example-component}}');
this.runTask(function () {
_this36.$('button').click();
});
this.assert.equal(actionCount, 1, 'Click action only fired once.');
this.assert.ok(this.$('button').hasClass('selected'), 'Element with action handler has properly updated it\'s conditional class');
this.runTask(function () {
_this36.$('button').click();
});
this.assert.equal(actionCount, 2, 'Second click action only fired once.');
this.assert.ok(!this.$('button').hasClass('selected'), 'Element with action handler has properly updated it\'s conditional class');
};
return _class2;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/get-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal'], function (_emberBabel, _testCase, _helpers, _emberMetal) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: {{get}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test should be able to get an object value with a static key'] = function () {
var _this2 = this;
this.render('[{{get colors \'apple\'}}] [{{if true (get colors \'apple\')}}]', {
colors: { apple: 'red' }
});
this.assertText('[red] [red]');
this.runTask(function () {
return _this2.rerender();
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'colors.apple', 'green');
});
this.assertText('[green] [green]');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'colors', {
apple: 'red'
});
});
this.assertText('[red] [red]');
};
_class.prototype['@test should be able to get an object value with nested static key'] = function () {
var _this3 = this;
this.render('[{{get colors "apple.gala"}}] [{{if true (get colors "apple.gala")}}]', {
colors: {
apple: {
gala: 'red and yellow'
}
}
});
this.assertText('[red and yellow] [red and yellow]');
this.runTask(function () {
return _this3.rerender();
});
this.assertText('[red and yellow] [red and yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'colors.apple.gala', 'yellow and red striped');
});
this.assertText('[yellow and red striped] [yellow and red striped]');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'colors', { apple: { gala: 'red and yellow' } });
});
this.assertText('[red and yellow] [red and yellow]');
};
_class.prototype['@test should be able to get an object value with a bound/dynamic key'] = function () {
var _this4 = this;
this.render('[{{get colors key}}] [{{if true (get colors key)}}]', {
colors: { apple: 'red', banana: 'yellow' },
key: 'apple'
});
this.assertText('[red] [red]');
this.runTask(function () {
return _this4.rerender();
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'key', 'banana');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
(0, _emberMetal.set)(_this4.context, 'colors.apple', 'green');
(0, _emberMetal.set)(_this4.context, 'colors.banana', 'purple');
});
this.assertText('[purple] [purple]');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'key', 'apple');
});
this.assertText('[green] [green]');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'colors', { apple: 'red' });
});
this.assertText('[red] [red]');
};
_class.prototype['@test should be able to get an object value with nested dynamic key'] = function () {
var _this5 = this;
this.render('[{{get colors key}}] [{{if true (get colors key)}}]', {
colors: {
apple: {
gala: 'red and yellow',
mcintosh: 'red'
},
banana: 'yellow'
},
key: 'apple.gala'
});
this.assertText('[red and yellow] [red and yellow]');
this.runTask(function () {
return _this5.rerender();
});
this.assertText('[red and yellow] [red and yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'key', 'apple.mcintosh');
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'key', 'banana');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'key', 'apple.gala');
});
this.assertText('[red and yellow] [red and yellow]');
};
_class.prototype['@test should be able to get an object value with subexpression returning nested key'] = function () {
var _this6 = this;
this.render('[{{get colors (concat \'apple\' \'.\' \'gala\')}}] [{{if true (get colors (concat \'apple\' \'.\' \'gala\'))}}]', {
colors: {
apple: {
gala: 'red and yellow',
mcintosh: 'red'
}
},
key: 'apple.gala'
});
this.assertText('[red and yellow] [red and yellow]');
this.runTask(function () {
return _this6.rerender();
});
this.assertText('[red and yellow] [red and yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'colors.apple.gala', 'yellow and red striped');
});
this.assertText('[yellow and red striped] [yellow and red striped]');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'colors.apple.gala', 'yellow-redish');
});
this.assertText('[yellow-redish] [yellow-redish]');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'colors', {
apple: {
gala: 'red and yellow',
mcintosh: 'red'
}
});
});
this.assertText('[red and yellow] [red and yellow]');
};
_class.prototype['@test should be able to get an object value with a get helper as the key'] = function () {
var _this7 = this;
this.render('[{{get colors (get possibleKeys key)}}] [{{if true (get colors (get possibleKeys key))}}]', {
colors: { apple: 'red', banana: 'yellow' },
key: 'key1',
possibleKeys: { key1: 'apple', key2: 'banana' }
});
this.assertText('[red] [red]');
this.runTask(function () {
return _this7.rerender();
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'key', 'key2');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
(0, _emberMetal.set)(_this7.context, 'colors.apple', 'green');
(0, _emberMetal.set)(_this7.context, 'colors.banana', 'purple');
});
this.assertText('[purple] [purple]');
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'key', 'key1');
});
this.assertText('[green] [green]');
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'colors', { apple: 'red', banana: 'yellow' });
});
this.assertText('[red] [red]');
};
_class.prototype['@test should be able to get an object value with a get helper value as a bound/dynamic key'] = function () {
var _this8 = this;
this.render('[{{get (get possibleValues objectKey) key}}] [{{if true (get (get possibleValues objectKey) key)}}]', {
possibleValues: {
colors1: { apple: 'red', banana: 'yellow' },
colors2: { apple: 'green', banana: 'purple' }
},
objectKey: 'colors1',
key: 'apple'
});
this.assertText('[red] [red]');
this.runTask(function () {
return _this8.rerender();
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'objectKey', 'colors2');
});
this.assertText('[green] [green]');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'objectKey', 'colors1');
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'key', 'banana');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'objectKey', 'colors2');
});
this.assertText('[purple] [purple]');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'objectKey', 'colors1');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'key', 'apple');
});
};
_class.prototype['@test should be able to get an object value with a get helper as the value and a get helper as the key'] = function () {
var _this9 = this;
this.render('[{{get (get possibleValues objectKey) (get possibleKeys key)}}] [{{if true (get (get possibleValues objectKey) (get possibleKeys key))}}]', {
possibleValues: {
colors1: { apple: 'red', banana: 'yellow' },
colors2: { apple: 'green', banana: 'purple' }
},
objectKey: 'colors1',
possibleKeys: {
key1: 'apple',
key2: 'banana'
},
key: 'key1'
});
this.assertText('[red] [red]');
this.runTask(function () {
return _this9.rerender();
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'objectKey', 'colors2');
});
this.assertText('[green] [green]');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'objectKey', 'colors1');
});
this.assertText('[red] [red]');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'key', 'key2');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'objectKey', 'colors2');
});
this.assertText('[purple] [purple]');
this.runTask(function () {
(0, _emberMetal.set)(_this9.context, 'objectKey', 'colors1');
(0, _emberMetal.set)(_this9.context, 'key', 'key1');
});
this.assertText('[red] [red]');
};
_class.prototype['@test the result of a get helper can be yielded'] = function () {
var _this10 = this;
var fooBarInstance = void 0;
var FooBarComponent = _helpers.Component.extend({
init: function () {
this._super();
fooBarInstance = this;
this.mcintosh = 'red';
}
});
this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: '{{yield (get colors mcintosh)}}'
});
this.render('{{#foo-bar colors=colors as |value|}}{{value}}{{/foo-bar}}', {
colors: {
red: 'banana'
}
});
this.assertText('banana');
this.runTask(function () {
return _this10.rerender();
});
this.assertText('banana');
this.runTask(function () {
(0, _emberMetal.set)(fooBarInstance, 'mcintosh', 'yellow');
(0, _emberMetal.set)(_this10.context, 'colors', { yellow: 'bus' });
});
this.assertText('bus');
this.runTask(function () {
(0, _emberMetal.set)(fooBarInstance, 'mcintosh', 'red');
(0, _emberMetal.set)(_this10.context, 'colors', { red: 'banana' });
});
this.assertText('banana');
};
_class.prototype['@test should handle object values as nulls'] = function () {
var _this11 = this;
this.render('[{{get colors \'apple\'}}] [{{if true (get colors \'apple\')}}]', {
colors: null
});
this.assertText('[] []');
this.runTask(function () {
return _this11.rerender();
});
this.assertText('[] []');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'colors', { apple: 'green', banana: 'purple' });
});
this.assertText('[green] [green]');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'colors', null);
});
this.assertText('[] []');
};
_class.prototype['@test should handle object keys as nulls'] = function () {
var _this12 = this;
this.render('[{{get colors key}}] [{{if true (get colors key)}}]', {
colors: {
apple: 'red',
banana: 'yellow'
},
key: null
});
this.assertText('[] []');
this.runTask(function () {
return _this12.rerender();
});
this.assertText('[] []');
this.runTask(function () {
return (0, _emberMetal.set)(_this12.context, 'key', 'banana');
});
this.assertText('[yellow] [yellow]');
this.runTask(function () {
return (0, _emberMetal.set)(_this12.context, 'key', null);
});
this.assertText('[] []');
};
_class.prototype['@test should handle object values and keys as nulls'] = function () {
this.render('[{{get colors \'apple\'}}] [{{if true (get colors key)}}]', {
colors: null,
key: null
});
this.assertText('[] []');
};
_class.prototype['@test get helper value should be updatable using {{input}} and (mut) - static key'] = function (assert) {
var _this13 = this;
this.render('{{input type=\'text\' value=(mut (get source \'banana\')) id=\'get-input\'}}', {
source: {
banana: 'banana'
}
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
this.runTask(function () {
return _this13.rerender();
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'source.banana', 'yellow');
});
assert.strictEqual(this.$('#get-input').val(), 'yellow');
this.runTask(function () {
return _this13.$('#get-input').val('some value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'some value');
assert.strictEqual((0, _emberMetal.get)(this.context, 'source.banana'), 'some value');
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'source', { banana: 'banana' });
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
};
_class.prototype['@test get helper value should be updatable using {{input}} and (mut) - dynamic key'] = function (assert) {
var _this14 = this;
this.render('{{input type=\'text\' value=(mut (get source key)) id=\'get-input\'}}', {
source: {
apple: 'apple',
banana: 'banana'
},
key: 'banana'
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
this.runTask(function () {
return _this14.rerender();
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
this.runTask(function () {
return (0, _emberMetal.set)(_this14.context, 'source.banana', 'yellow');
});
assert.strictEqual(this.$('#get-input').val(), 'yellow');
this.runTask(function () {
return _this14.$('#get-input').val('some value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'some value');
assert.strictEqual((0, _emberMetal.get)(this.context, 'source.banana'), 'some value');
this.runTask(function () {
return (0, _emberMetal.set)(_this14.context, 'key', 'apple');
});
assert.strictEqual(this.$('#get-input').val(), 'apple');
this.runTask(function () {
return _this14.$('#get-input').val('some other value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'some other value');
assert.strictEqual((0, _emberMetal.get)(this.context, 'source.apple'), 'some other value');
this.runTask(function () {
(0, _emberMetal.set)(_this14.context, 'key', 'banana');
(0, _emberMetal.set)(_this14.context, 'source', { banana: 'banana' });
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
};
_class.prototype['@test get helper value should be updatable using {{input}} and (mut) - dynamic nested key'] = function (assert) {
var _this15 = this;
this.render('{{input type=\'text\' value=(mut (get source key)) id=\'get-input\'}}', {
source: {
apple: {
gala: 'gala',
mcintosh: 'mcintosh'
},
banana: 'banana'
},
key: 'apple.mcintosh'
});
assert.strictEqual(this.$('#get-input').val(), 'mcintosh');
this.runTask(function () {
return _this15.rerender();
});
assert.strictEqual(this.$('#get-input').val(), 'mcintosh');
this.runTask(function () {
return (0, _emberMetal.set)(_this15.context, 'source.apple.mcintosh', 'red');
});
assert.strictEqual(this.$('#get-input').val(), 'red');
this.runTask(function () {
return _this15.$('#get-input').val('some value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'some value');
assert.strictEqual((0, _emberMetal.get)(this.context, 'source.apple.mcintosh'), 'some value');
this.runTask(function () {
return (0, _emberMetal.set)(_this15.context, 'key', 'apple.gala');
});
assert.strictEqual(this.$('#get-input').val(), 'gala');
this.runTask(function () {
return _this15.$('#get-input').val('some other value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'some other value');
assert.strictEqual((0, _emberMetal.get)(this.context, 'source.apple.gala'), 'some other value');
this.runTask(function () {
return (0, _emberMetal.set)(_this15.context, 'key', 'banana');
});
assert.strictEqual(this.$('#get-input').val(), 'banana');
this.runTask(function () {
return _this15.$('#get-input').val('yet another value').trigger('change');
});
assert.strictEqual(this.$('#get-input').val(), 'yet another value');
assert.strictEqual((0, _emberMetal.get)(this.context, 'source.banana'), 'yet another value');
this.runTask(function () {
(0, _emberMetal.set)(_this15.context, 'key', 'apple.mcintosh');
(0, _emberMetal.set)(_this15.context, 'source', {
apple: {
gala: 'gala',
mcintosh: 'mcintosh'
},
banana: 'banana'
});
});
assert.strictEqual(this.$('#get-input').val(), 'mcintosh');
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/hash-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal'], function (_emberBabel, _testCase, _helpers, _emberMetal) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: {{hash}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test returns a hash with the right key-value'] = function () {
var _this2 = this;
this.render('{{#with (hash name="Sergio") as |person|}}{{person.name}}{{/with}}');
this.assertText('Sergio');
this.runTask(function () {
return _this2.rerender();
});
this.assertText('Sergio');
};
_class.prototype['@test can have more than one key-value'] = function () {
var _this3 = this;
this.render('{{#with (hash name="Sergio" lastName="Arbeo") as |person|}}{{person.name}} {{person.lastName}}{{/with}}');
this.assertText('Sergio Arbeo');
this.runTask(function () {
return _this3.rerender();
});
this.assertText('Sergio Arbeo');
};
_class.prototype['@test binds values when variables are used'] = function () {
var _this4 = this;
this.render('{{#with (hash name=model.firstName lastName="Arbeo") as |person|}}{{person.name}} {{person.lastName}}{{/with}}', {
model: {
firstName: 'Marisa'
}
});
this.assertText('Marisa Arbeo');
this.runTask(function () {
return _this4.rerender();
});
this.assertText('Marisa Arbeo');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'model.firstName', 'Sergio');
});
this.assertText('Sergio Arbeo');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'model', { firstName: 'Marisa' });
});
this.assertText('Marisa Arbeo');
};
_class.prototype['@test binds multiple values when variables are used'] = function () {
var _this5 = this;
this.render('{{#with (hash name=model.firstName lastName=model.lastName) as |person|}}{{person.name}} {{person.lastName}}{{/with}}', {
model: {
firstName: 'Marisa',
lastName: 'Arbeo'
}
});
this.assertText('Marisa Arbeo');
this.runTask(function () {
return _this5.rerender();
});
this.assertText('Marisa Arbeo');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'model.firstName', 'Sergio');
});
this.assertText('Sergio Arbeo');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'model.lastName', 'Smith');
});
this.assertText('Sergio Smith');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'model', {
firstName: 'Marisa',
lastName: 'Arbeo'
});
});
this.assertText('Marisa Arbeo');
};
_class.prototype['@test hash helpers can be nested'] = function () {
var _this6 = this;
this.render('{{#with (hash person=(hash name=model.firstName)) as |ctx|}}{{ctx.person.name}}{{/with}}', {
model: { firstName: 'Balint' }
});
this.assertText('Balint');
this.runTask(function () {
return _this6.rerender();
});
this.assertText('Balint');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'model.firstName', 'Chad');
});
this.assertText('Chad');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'model', { firstName: 'Balint' });
});
this.assertText('Balint');
};
_class.prototype['@test should yield hash of internal properties'] = function () {
var _this7 = this;
var fooBarInstance = void 0;
var FooBarComponent = _helpers.Component.extend({
init: function () {
this._super();
fooBarInstance = this;
this.model = { firstName: 'Chad' };
}
});
this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: '{{yield (hash firstName=model.firstName)}}'
});
this.render('{{#foo-bar as |values|}}{{values.firstName}}{{/foo-bar}}');
this.assertText('Chad');
this.runTask(function () {
return _this7.rerender();
});
this.assertText('Chad');
this.runTask(function () {
return (0, _emberMetal.set)(fooBarInstance, 'model.firstName', 'Godfrey');
});
this.assertText('Godfrey');
this.runTask(function () {
return (0, _emberMetal.set)(fooBarInstance, 'model', { firstName: 'Chad' });
});
this.assertText('Chad');
};
_class.prototype['@test should yield hash of internal and external properties'] = function () {
var _this8 = this;
var fooBarInstance = void 0;
var FooBarComponent = _helpers.Component.extend({
init: function () {
this._super();
fooBarInstance = this;
this.model = { firstName: 'Chad' };
}
});
this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: '{{yield (hash firstName=model.firstName lastName=lastName)}}'
});
this.render('{{#foo-bar lastName=model.lastName as |values|}}{{values.firstName}} {{values.lastName}}{{/foo-bar}}', {
model: { lastName: 'Hietala' }
});
this.assertText('Chad Hietala');
this.runTask(function () {
return _this8.rerender();
});
this.assertText('Chad Hietala');
this.runTask(function () {
(0, _emberMetal.set)(fooBarInstance, 'model.firstName', 'Godfrey');
(0, _emberMetal.set)(_this8.context, 'model.lastName', 'Chan');
});
this.assertText('Godfrey Chan');
this.runTask(function () {
(0, _emberMetal.set)(fooBarInstance, 'model', { firstName: 'Chad' });
(0, _emberMetal.set)(_this8.context, 'model', { lastName: 'Hietala' });
});
this.assertText('Chad Hietala');
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/if-unless-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/shared-conditional-tests'], function (_emberBabel, _testCase, _sharedConditionalTests) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: inline {{if}}', function (_IfUnlessHelperTest) {
(0, _emberBabel.inherits)(_class, _IfUnlessHelperTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest.apply(this, arguments));
}
_class.prototype.templateFor = function (_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return '{{if ' + cond + ' ' + truthy + ' ' + falsy + '}}';
};
_class.prototype['@test it raises when there are more than three arguments'] = function () {
var _this2 = this;
expectAssertion(function () {
_this2.render('{{if condition \'a\' \'b\' \'c\'}}', { condition: true });
}, /The inline form of the `if` helper expects two or three arguments/);
};
_class.prototype['@test it raises when there are less than two arguments'] = function () {
var _this3 = this;
expectAssertion(function () {
_this3.render('{{if condition}}', { condition: true });
}, /The inline form of the `if` helper expects two or three arguments/);
};
return _class;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: nested {{if}} helpers (returning truthy values)', function (_IfUnlessHelperTest2) {
(0, _emberBabel.inherits)(_class2, _IfUnlessHelperTest2);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest2.apply(this, arguments));
}
_class2.prototype.templateFor = function (_ref2) {
var cond = _ref2.cond,
truthy = _ref2.truthy,
falsy = _ref2.falsy;
return '{{if (if ' + cond + ' ' + cond + ' false) ' + truthy + ' ' + falsy + '}}';
};
return _class2;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: nested {{if}} helpers (returning falsy values)', function (_IfUnlessHelperTest3) {
(0, _emberBabel.inherits)(_class3, _IfUnlessHelperTest3);
function _class3() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest3.apply(this, arguments));
}
_class3.prototype.templateFor = function (_ref3) {
var cond = _ref3.cond,
truthy = _ref3.truthy,
falsy = _ref3.falsy;
return '{{if (if ' + cond + ' true ' + cond + ') ' + truthy + ' ' + falsy + '}}';
};
return _class3;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: {{if}} used with another helper', function (_IfUnlessHelperTest4) {
(0, _emberBabel.inherits)(_class4, _IfUnlessHelperTest4);
function _class4() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest4.apply(this, arguments));
}
_class4.prototype.wrapperFor = function (templates) {
return '{{concat ' + templates.join(' ') + '}}';
};
_class4.prototype.templateFor = function (_ref4) {
var cond = _ref4.cond,
truthy = _ref4.truthy,
falsy = _ref4.falsy;
return '(if ' + cond + ' ' + truthy + ' ' + falsy + ')';
};
return _class4;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: {{if}} used in attribute position', function (_IfUnlessHelperTest5) {
(0, _emberBabel.inherits)(_class5, _IfUnlessHelperTest5);
function _class5() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest5.apply(this, arguments));
}
_class5.prototype.wrapperFor = function (templates) {
return '
';
};
_class5.prototype.templateFor = function (_ref5) {
var cond = _ref5.cond,
truthy = _ref5.truthy,
falsy = _ref5.falsy;
return '{{if ' + cond + ' ' + truthy + ' ' + falsy + '}}';
};
_class5.prototype.textValue = function () {
return this.$('div').attr('data-foo');
};
return _class5;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: inline {{if}} and {{unless}} without the inverse argument', function (_IfUnlessHelperTest6) {
(0, _emberBabel.inherits)(_class6, _IfUnlessHelperTest6);
function _class6() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest6.apply(this, arguments));
}
_class6.prototype.templateFor = function (_ref6) {
var cond = _ref6.cond,
truthy = _ref6.truthy,
falsy = _ref6.falsy;
return '{{if ' + cond + ' ' + truthy + '}}{{unless ' + cond + ' ' + falsy + '}}';
};
return _class6;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: inline {{unless}}', function (_IfUnlessHelperTest7) {
(0, _emberBabel.inherits)(_class7, _IfUnlessHelperTest7);
function _class7() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest7.apply(this, arguments));
}
_class7.prototype.templateFor = function (_ref7) {
var cond = _ref7.cond,
truthy = _ref7.truthy,
falsy = _ref7.falsy;
return '{{unless ' + cond + ' ' + falsy + ' ' + truthy + '}}';
};
_class7.prototype['@test it raises when there are more than three arguments'] = function () {
var _this10 = this;
expectAssertion(function () {
_this10.render('{{unless condition \'a\' \'b\' \'c\'}}', { condition: true });
}, /The inline form of the `unless` helper expects two or three arguments/);
};
_class7.prototype['@test it raises when there are less than two arguments'] = function () {
var _this11 = this;
expectAssertion(function () {
_this11.render('{{unless condition}}', { condition: true });
}, /The inline form of the `unless` helper expects two or three arguments/);
};
return _class7;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: nested {{unless}} helpers (returning truthy values)', function (_IfUnlessHelperTest8) {
(0, _emberBabel.inherits)(_class8, _IfUnlessHelperTest8);
function _class8() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest8.apply(this, arguments));
}
_class8.prototype.templateFor = function (_ref8) {
var cond = _ref8.cond,
truthy = _ref8.truthy,
falsy = _ref8.falsy;
return '{{unless (unless ' + cond + ' false ' + cond + ') ' + falsy + ' ' + truthy + '}}';
};
return _class8;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: nested {{unless}} helpers (returning falsy values)', function (_IfUnlessHelperTest9) {
(0, _emberBabel.inherits)(_class9, _IfUnlessHelperTest9);
function _class9() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest9.apply(this, arguments));
}
_class9.prototype.templateFor = function (_ref9) {
var cond = _ref9.cond,
truthy = _ref9.truthy,
falsy = _ref9.falsy;
return '{{unless (unless ' + cond + ' ' + cond + ' true) ' + falsy + ' ' + truthy + '}}';
};
return _class9;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: {{unless}} used with another helper', function (_IfUnlessHelperTest10) {
(0, _emberBabel.inherits)(_class10, _IfUnlessHelperTest10);
function _class10() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest10.apply(this, arguments));
}
_class10.prototype.wrapperFor = function (templates) {
return '{{concat ' + templates.join(' ') + '}}';
};
_class10.prototype.templateFor = function (_ref10) {
var cond = _ref10.cond,
truthy = _ref10.truthy,
falsy = _ref10.falsy;
return '(unless ' + cond + ' ' + falsy + ' ' + truthy + ')';
};
return _class10;
}(_sharedConditionalTests.IfUnlessHelperTest));
(0, _testCase.moduleFor)('Helpers test: {{unless}} used in attribute position', function (_IfUnlessHelperTest11) {
(0, _emberBabel.inherits)(_class11, _IfUnlessHelperTest11);
function _class11() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessHelperTest11.apply(this, arguments));
}
_class11.prototype.wrapperFor = function (templates) {
return '
';
};
_class11.prototype.templateFor = function (_ref11) {
var cond = _ref11.cond,
truthy = _ref11.truthy,
falsy = _ref11.falsy;
return '{{unless ' + cond + ' ' + falsy + ' ' + truthy + '}}';
};
_class11.prototype.textValue = function () {
return this.$('div').attr('data-foo');
};
return _class11;
}(_sharedConditionalTests.IfUnlessHelperTest));
});
enifed('ember-glimmer/tests/integration/helpers/input-test', ['ember-babel', 'ember-utils', 'ember-metal', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/test-case', 'internal-test-helpers'], function (_emberBabel, _emberUtils, _emberMetal, _helpers, _testCase, _internalTestHelpers) {
'use strict';
var InputRenderingTest = function (_RenderingTest) {
(0, _emberBabel.inherits)(InputRenderingTest, _RenderingTest);
function InputRenderingTest() {
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this));
_this.registerComponent('-text-field', { ComponentClass: _helpers.TextField });
_this.registerComponent('-checkbox', { ComponentClass: _helpers.Checkbox });
return _this;
}
InputRenderingTest.prototype.$input = function () {
return this.$('input');
};
InputRenderingTest.prototype.inputID = function () {
return this.$input().prop('id');
};
InputRenderingTest.prototype.assertDisabled = function () {
this.assert.ok(this.$('input').prop('disabled'), 'The input is disabled');
};
InputRenderingTest.prototype.assertNotDisabled = function () {
this.assert.ok(this.$('input').is(':not(:disabled)'), 'The input is not disabled');
};
InputRenderingTest.prototype.assertInputId = function (expectedId) {
this.assert.equal(this.inputID(), expectedId, 'the input id should be `expectedId`');
};
InputRenderingTest.prototype.assertSingleInput = function () {
this.assert.equal(this.$('input').length, 1, 'A single text field was inserted');
};
InputRenderingTest.prototype.assertSingleCheckbox = function () {
this.assert.equal(this.$('input[type=checkbox]').length, 1, 'A single checkbox is added');
};
InputRenderingTest.prototype.assertCheckboxIsChecked = function () {
this.assert.equal(this.$input().prop('checked'), true, 'the checkbox is checked');
};
InputRenderingTest.prototype.assertCheckboxIsNotChecked = function () {
this.assert.equal(this.$input().prop('checked'), false, 'the checkbox is not checked');
};
InputRenderingTest.prototype.assertValue = function (expected) {
this.assert.equal(this.$input().val(), expected, 'the input value should be ' + expected);
};
InputRenderingTest.prototype.assertAttr = function (name, expected) {
this.assert.equal(this.$input().attr(name), expected, 'the input ' + name + ' attribute has the value \'' + expected + '\'');
};
InputRenderingTest.prototype.assertAllAttrs = function (names, expected) {
var _this2 = this;
names.forEach(function (name) {
return _this2.assertAttr(name, expected);
});
};
InputRenderingTest.prototype.assertSelectionRange = function (start, end) {
var input = this.$input()[0];
this.assert.equal(input.selectionStart, start, 'the cursor start position should be ' + start);
this.assert.equal(input.selectionEnd, end, 'the cursor end position should be ' + end);
};
InputRenderingTest.prototype.triggerEvent = function (type, options) {
var event = document.createEvent('Events');
event.initEvent(type, true, true);
(0, _emberUtils.assign)(event, options);
var element = this.$input()[0];
this.runTask(function () {
element.dispatchEvent(event);
});
};
return InputRenderingTest;
}(_testCase.RenderingTest);
(0, _testCase.moduleFor)('Helpers test: {{input}}', function (_InputRenderingTest) {
(0, _emberBabel.inherits)(_class, _InputRenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest.apply(this, arguments));
}
_class.prototype['@test a single text field is inserted into the DOM'] = function () {
var _this4 = this;
this.render('{{input type="text" value=value}}', { value: 'hello' });
var id = this.inputID();
this.assertValue('hello');
this.assertSingleInput();
this.runTask(function () {
return _this4.rerender();
});
this.assertValue('hello');
this.assertSingleInput();
this.assertInputId(id);
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'value', 'goodbye');
});
this.assertValue('goodbye');
this.assertSingleInput();
this.assertInputId(id);
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'value', 'hello');
});
this.assertValue('hello');
this.assertSingleInput();
this.assertInputId(id);
};
_class.prototype['@test default type'] = function () {
var _this5 = this;
this.render('{{input}}');
this.assertAttr('type', 'text');
this.runTask(function () {
return _this5.rerender();
});
this.assertAttr('type', 'text');
};
_class.prototype['@test dynamic attributes'] = function () {
var _this6 = this;
this.render('\n {{input type="text"\n disabled=disabled\n value=value\n placeholder=placeholder\n name=name\n maxlength=maxlength\n size=size\n tabindex=tabindex\n }}', {
disabled: false,
value: 'Original value',
placeholder: 'Original placeholder',
name: 'original-name',
maxlength: 10,
size: 20,
tabindex: 30
});
this.assertNotDisabled();
this.assertValue('Original value');
this.assertAttr('placeholder', 'Original placeholder');
this.assertAttr('name', 'original-name');
this.assertAttr('maxlength', '10');
// this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
this.runTask(function () {
return _this6.rerender();
});
this.assertNotDisabled();
this.assertValue('Original value');
this.assertAttr('placeholder', 'Original placeholder');
this.assertAttr('name', 'original-name');
this.assertAttr('maxlength', '10');
// this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
this.runTask(function () {
(0, _emberMetal.set)(_this6.context, 'value', 'Updated value');
(0, _emberMetal.set)(_this6.context, 'disabled', true);
(0, _emberMetal.set)(_this6.context, 'placeholder', 'Updated placeholder');
(0, _emberMetal.set)(_this6.context, 'name', 'updated-name');
(0, _emberMetal.set)(_this6.context, 'maxlength', 11);
// set(this.context, 'size', 21); //NOTE: failing in IE (TEST_SUITE=sauce)
// set(this.context, 'tabindex', 31); //NOTE: failing in IE (TEST_SUITE=sauce)
});
this.assertDisabled();
this.assertValue('Updated value');
this.assertAttr('placeholder', 'Updated placeholder');
this.assertAttr('name', 'updated-name');
this.assertAttr('maxlength', '11');
// this.assertAttr('size', '21'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '31'); //NOTE: failing in IE (TEST_SUITE=sauce)
this.runTask(function () {
(0, _emberMetal.set)(_this6.context, 'value', 'Original value');
(0, _emberMetal.set)(_this6.context, 'disabled', false);
(0, _emberMetal.set)(_this6.context, 'placeholder', 'Original placeholder');
(0, _emberMetal.set)(_this6.context, 'name', 'original-name');
(0, _emberMetal.set)(_this6.context, 'maxlength', 10);
// set(this.context, 'size', 20); //NOTE: failing in IE (TEST_SUITE=sauce)
// set(this.context, 'tabindex', 30); //NOTE: failing in IE (TEST_SUITE=sauce)
});
this.assertNotDisabled();
this.assertValue('Original value');
this.assertAttr('placeholder', 'Original placeholder');
this.assertAttr('name', 'original-name');
this.assertAttr('maxlength', '10');
// this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
};
_class.prototype['@test static attributes'] = function () {
var _this7 = this;
this.render('\n {{input type="text"\n disabled=true\n value="Original value"\n placeholder="Original placeholder"\n name="original-name"\n maxlength=10\n size=20\n tabindex=30\n }}');
this.assertDisabled();
this.assertValue('Original value');
this.assertAttr('placeholder', 'Original placeholder');
this.assertAttr('name', 'original-name');
this.assertAttr('maxlength', '10');
// this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
this.runTask(function () {
return _this7.rerender();
});
this.assertDisabled();
this.assertValue('Original value');
this.assertAttr('placeholder', 'Original placeholder');
this.assertAttr('name', 'original-name');
this.assertAttr('maxlength', '10');
// this.assertAttr('size', '20'); //NOTE: failing in IE (TEST_SUITE=sauce)
// this.assertAttr('tabindex', '30'); //NOTE: failing in IE (TEST_SUITE=sauce)
};
_class.prototype['@test cursor selection range'] = function () {
var _this8 = this;
// Modifying input.selectionStart, which is utilized in the cursor tests,
// causes an event in Safari.
(0, _internalTestHelpers.runDestroy)(this.owner.lookup('event_dispatcher:main'));
this.render('{{input type="text" value=value}}', { value: 'original' });
var input = this.$input()[0];
// See https://ember-twiddle.com/33e506329f8176ae874422644d4cc08c?openFiles=components.input-component.js%2Ctemplates.components.input-component.hbs
// this.assertSelectionRange(8, 8); //NOTE: this is (0, 0) on Firefox (TEST_SUITE=sauce)
this.runTask(function () {
return _this8.rerender();
});
// this.assertSelectionRange(8, 8); //NOTE: this is (0, 0) on Firefox (TEST_SUITE=sauce)
this.runTask(function () {
input.selectionStart = 2;
input.selectionEnd = 4;
});
this.assertSelectionRange(2, 4);
this.runTask(function () {
return _this8.rerender();
});
this.assertSelectionRange(2, 4);
// this.runTask(() => set(this.context, 'value', 'updated'));
//
// this.assertSelectionRange(7, 7); //NOTE: this fails in IE, the range is 0 -> 0 (TEST_SUITE=sauce)
//
// this.runTask(() => set(this.context, 'value', 'original'));
//
// this.assertSelectionRange(8, 8); //NOTE: this fails in IE, the range is 0 -> 0 (TEST_SUITE=sauce)
};
_class.prototype['@test specifying `on="someevent" action="foo"` results in a deprecation warning'] = function () {
var _this9 = this;
expectDeprecation(function () {
_this9.render('{{input on="focus-in" action="doFoo" value="hello"}}');
}, 'Using \'{{input on="focus-in" action="doFoo"}}\' (\'-top-level\' @ L1:C0) is deprecated. Please use \'{{input focus-in="doFoo"}}\' instead.');
};
_class.prototype['@test sends an action with `{{input action="foo"}}` when
is pressed [DEPRECATED]'] = function (assert) {
var _this10 = this;
assert.expect(2);
expectDeprecation(function () {
_this10.render('{{input action=\'foo\'}}', {
actions: {
foo: function () {
assert.ok(true, 'action was triggered');
}
}
});
}, /Please use '{{input enter="foo"}}' instead/);
this.triggerEvent('keyup', {
keyCode: 13
});
};
_class.prototype['@test sends an action with `{{input enter="foo"}}` when is pressed'] = function (assert) {
assert.expect(1);
this.render('{{input enter=\'foo\'}}', {
actions: {
foo: function () {
assert.ok(true, 'action was triggered');
}
}
});
this.triggerEvent('keyup', {
keyCode: 13
});
};
_class.prototype['@test sends an action with `{{input key-press="foo"}}` is pressed'] = function (assert) {
assert.expect(1);
this.render('{{input value=value key-press=\'foo\'}}', {
value: 'initial',
actions: {
foo: function () {
assert.ok(true, 'action was triggered');
}
}
});
this.triggerEvent('keypress', {
keyCode: 65
});
};
_class.prototype['@test sends an action to the parent level when `bubbles=true` is provided'] = function (assert) {
assert.expect(1);
var ParentComponent = _helpers.Component.extend({
change: function () {
assert.ok(true, 'bubbled upwards');
}
});
this.registerComponent('x-parent', {
ComponentClass: ParentComponent,
template: '{{input bubbles=true}}'
});
this.render('{{x-parent}}');
this.triggerEvent('change');
};
_class.prototype['@test triggers `focus-in` when focused'] = function (assert) {
var _this11 = this;
assert.expect(1);
this.render('{{input focus-in=\'foo\'}}', {
actions: {
foo: function () {
assert.ok(true, 'action was triggered');
}
}
});
this.runTask(function () {
_this11.$input().trigger('focusin');
});
};
_class.prototype['@test sends `insert-newline` when is pressed'] = function (assert) {
assert.expect(1);
this.render('{{input insert-newline=\'foo\'}}', {
actions: {
foo: function () {
assert.ok(true, 'action was triggered');
}
}
});
this.triggerEvent('keyup', {
keyCode: 13
});
};
_class.prototype['@test sends an action with `{{input escape-press="foo"}}` when is pressed'] = function (assert) {
assert.expect(1);
this.render('{{input escape-press=\'foo\'}}', {
actions: {
foo: function () {
assert.ok(true, 'action was triggered');
}
}
});
this.triggerEvent('keyup', {
keyCode: 27
});
};
_class.prototype['@test sends an action with `{{input key-down="foo"}}` when a key is pressed'] = function (assert) {
assert.expect(1);
this.render('{{input key-down=\'foo\'}}', {
actions: {
foo: function () {
assert.ok(true, 'action was triggered');
}
}
});
this.triggerEvent('keydown', {
keyCode: 65
});
};
_class.prototype['@test sends an action with `{{input key-up="foo"}}` when a key is pressed'] = function (assert) {
assert.expect(1);
this.render('{{input key-up=\'foo\'}}', {
actions: {
foo: function () {
assert.ok(true, 'action was triggered');
}
}
});
this.triggerEvent('keyup', {
keyCode: 65
});
};
return _class;
}(InputRenderingTest));
(0, _testCase.moduleFor)('Helpers test: {{input}} with dynamic type', function (_InputRenderingTest2) {
(0, _emberBabel.inherits)(_class2, _InputRenderingTest2);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest2.apply(this, arguments));
}
_class2.prototype['@test a bound property can be used to determine type'] = function () {
var _this13 = this;
this.render('{{input type=type}}', { type: 'password' });
this.assertAttr('type', 'password');
this.runTask(function () {
return _this13.rerender();
});
this.assertAttr('type', 'password');
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'type', 'text');
});
this.assertAttr('type', 'text');
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'type', 'password');
});
this.assertAttr('type', 'password');
};
_class2.prototype['@test a subexpression can be used to determine type'] = function () {
var _this14 = this;
this.render('{{input type=(if isTruthy trueType falseType)}}', {
isTruthy: true,
trueType: 'text',
falseType: 'password'
});
this.assertAttr('type', 'text');
this.runTask(function () {
return _this14.rerender();
});
this.assertAttr('type', 'text');
this.runTask(function () {
return (0, _emberMetal.set)(_this14.context, 'isTruthy', false);
});
this.assertAttr('type', 'password');
this.runTask(function () {
return (0, _emberMetal.set)(_this14.context, 'isTruthy', true);
});
this.assertAttr('type', 'text');
};
return _class2;
}(InputRenderingTest));
(0, _testCase.moduleFor)('Helpers test: {{input type=\'checkbox\'}}', function (_InputRenderingTest3) {
(0, _emberBabel.inherits)(_class3, _InputRenderingTest3);
function _class3() {
return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest3.apply(this, arguments));
}
_class3.prototype['@test dynamic attributes'] = function () {
var _this16 = this;
this.render('{{input\n type=\'checkbox\'\n disabled=disabled\n name=name\n checked=checked\n tabindex=tabindex\n }}', {
disabled: false,
name: 'original-name',
checked: false,
tabindex: 10
});
this.assertSingleCheckbox();
this.assertNotDisabled();
this.assertAttr('name', 'original-name');
this.assertAttr('tabindex', '10');
this.runTask(function () {
return _this16.rerender();
});
this.assertSingleCheckbox();
this.assertNotDisabled();
this.assertAttr('name', 'original-name');
this.assertAttr('tabindex', '10');
this.runTask(function () {
(0, _emberMetal.set)(_this16.context, 'disabled', true);
(0, _emberMetal.set)(_this16.context, 'name', 'updated-name');
(0, _emberMetal.set)(_this16.context, 'tabindex', 11);
});
this.assertSingleCheckbox();
this.assertDisabled();
this.assertAttr('name', 'updated-name');
this.assertAttr('tabindex', '11');
this.runTask(function () {
(0, _emberMetal.set)(_this16.context, 'disabled', false);
(0, _emberMetal.set)(_this16.context, 'name', 'original-name');
(0, _emberMetal.set)(_this16.context, 'tabindex', 10);
});
this.assertSingleCheckbox();
this.assertNotDisabled();
this.assertAttr('name', 'original-name');
this.assertAttr('tabindex', '10');
};
_class3.prototype['@test `value` property assertion'] = function () {
var _this17 = this;
expectAssertion(function () {
_this17.render('{{input type="checkbox" value=value}}', { value: 'value' });
}, /you must use `checked=/);
};
_class3.prototype['@test with a bound type'] = function () {
var _this18 = this;
this.render('{{input type=inputType checked=isChecked}}', { inputType: 'checkbox', isChecked: true });
this.assertSingleCheckbox();
this.assertCheckboxIsChecked();
this.runTask(function () {
return _this18.rerender();
});
this.assertCheckboxIsChecked();
this.runTask(function () {
return (0, _emberMetal.set)(_this18.context, 'isChecked', false);
});
this.assertCheckboxIsNotChecked();
this.runTask(function () {
return (0, _emberMetal.set)(_this18.context, 'isChecked', true);
});
this.assertCheckboxIsChecked();
};
_class3.prototype['@test native click changes check property'] = function () {
this.render('{{input type="checkbox"}}');
this.assertSingleCheckbox();
this.assertCheckboxIsNotChecked();
this.$input()[0].click();
this.assertCheckboxIsChecked();
this.$input()[0].click();
this.assertCheckboxIsNotChecked();
};
_class3.prototype['@test with static values'] = function () {
var _this19 = this;
this.render('{{input type="checkbox" disabled=false tabindex=10 name="original-name" checked=false}}');
this.assertSingleCheckbox();
this.assertCheckboxIsNotChecked();
this.assertNotDisabled();
this.assertAttr('tabindex', '10');
this.assertAttr('name', 'original-name');
this.runTask(function () {
return _this19.rerender();
});
this.assertSingleCheckbox();
this.assertCheckboxIsNotChecked();
this.assertNotDisabled();
this.assertAttr('tabindex', '10');
this.assertAttr('name', 'original-name');
};
return _class3;
}(InputRenderingTest));
(0, _testCase.moduleFor)('Helpers test: {{input type=\'text\'}}', function (_InputRenderingTest4) {
(0, _emberBabel.inherits)(_class4, _InputRenderingTest4);
function _class4() {
return (0, _emberBabel.possibleConstructorReturn)(this, _InputRenderingTest4.apply(this, arguments));
}
_class4.prototype['@test null values'] = function () {
var _this21 = this;
var attributes = ['disabled', 'placeholder', 'name', 'maxlength', 'size', 'tabindex'];
this.render('\n {{input type="text"\n disabled=disabled\n value=value\n placeholder=placeholder\n name=name\n maxlength=maxlength\n size=size\n tabindex=tabindex\n }}', {
disabled: null,
value: null,
placeholder: null,
name: null,
maxlength: null,
size: null,
tabindex: null
});
this.assertValue('');
this.assertAllAttrs(attributes, undefined);
this.runTask(function () {
return _this21.rerender();
});
this.assertValue('');
this.assertAllAttrs(attributes, undefined);
this.runTask(function () {
(0, _emberMetal.set)(_this21.context, 'disabled', true);
(0, _emberMetal.set)(_this21.context, 'value', 'Updated value');
(0, _emberMetal.set)(_this21.context, 'placeholder', 'Updated placeholder');
(0, _emberMetal.set)(_this21.context, 'name', 'updated-name');
(0, _emberMetal.set)(_this21.context, 'maxlength', 11);
(0, _emberMetal.set)(_this21.context, 'size', 21);
(0, _emberMetal.set)(_this21.context, 'tabindex', 31);
});
this.assertDisabled();
this.assertValue('Updated value');
this.assertAttr('placeholder', 'Updated placeholder');
this.assertAttr('name', 'updated-name');
this.assertAttr('maxlength', '11');
this.assertAttr('size', '21');
this.assertAttr('tabindex', '31');
this.runTask(function () {
(0, _emberMetal.set)(_this21.context, 'disabled', null);
(0, _emberMetal.set)(_this21.context, 'value', null);
(0, _emberMetal.set)(_this21.context, 'placeholder', null);
(0, _emberMetal.set)(_this21.context, 'name', null);
(0, _emberMetal.set)(_this21.context, 'maxlength', null);
// set(this.context, 'size', null); //NOTE: this fails with `Error: Failed to set the 'size' property on 'HTMLInputElement': The value provided is 0, which is an invalid size.` (TEST_SUITE=sauce)
(0, _emberMetal.set)(_this21.context, 'tabindex', null);
});
this.assertAttr('disabled', undefined);
this.assertValue('');
// this.assertAttr('placeholder', undefined); //NOTE: this fails with a value of "null" (TEST_SUITE=sauce)
// this.assertAttr('name', undefined); //NOTE: this fails with a value of "null" (TEST_SUITE=sauce)
this.assertAttr('maxlength', undefined);
// this.assertAttr('size', undefined); //NOTE: re-enable once `size` bug above has been addressed
this.assertAttr('tabindex', undefined);
};
return _class4;
}(InputRenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/loc-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal', 'ember'], function (_emberBabel, _testCase, _emberMetal, _ember) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: {{loc}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this));
_this.oldString = _ember.default.STRINGS;
_ember.default.STRINGS = {
'Hello Friend': 'Hallo Freund',
'Hello': 'Hallo, %@'
};
return _this;
}
_class.prototype.teardown = function () {
_RenderingTest.prototype.teardown.call(this);
_ember.default.STRINGS = this.oldString;
};
_class.prototype['@test it lets the original value through by default'] = function () {
var _this2 = this;
this.render('{{loc "Hiya buddy!"}}');
this.assertText('Hiya buddy!', 'the unlocalized string is correct');
this.runTask(function () {
return _this2.rerender();
});
this.assertText('Hiya buddy!', 'the unlocalized string is correct after rerender');
};
_class.prototype['@test it localizes a simple string'] = function () {
var _this3 = this;
this.render('{{loc "Hello Friend"}}');
this.assertText('Hallo Freund', 'the localized string is correct');
this.runTask(function () {
return _this3.rerender();
});
this.assertText('Hallo Freund', 'the localized string is correct after rerender');
};
_class.prototype['@test it takes passed formats into an account'] = function () {
var _this4 = this;
this.render('{{loc "%@, %@" "Hello" "Mr. Pitkin"}}');
this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct');
this.runTask(function () {
return _this4.rerender();
});
this.assertText('Hello, Mr. Pitkin', 'the formatted string is correct after rerender');
};
_class.prototype['@test it updates when bound params change'] = function () {
var _this5 = this;
this.render('{{loc simple}} - {{loc personal \'Mr. Pitkin\'}}', {
simple: 'Hello Friend',
personal: 'Hello'
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct');
this.runTask(function () {
return _this5.rerender();
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after rerender');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'simple', 'G\'day mate');
});
this.assertText('G\'day mate - Hallo, Mr. Pitkin', 'the bound value is correct after update');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'simple', 'Hello Friend');
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after reset');
};
_class.prototype['@test it updates when nested bound params change'] = function () {
var _this6 = this;
this.render('{{loc greetings.simple}} - {{loc greetings.personal \'Mr. Pitkin\'}}', {
greetings: {
simple: 'Hello Friend',
personal: 'Hello'
}
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct');
this.runTask(function () {
return _this6.rerender();
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after rerender');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'greetings.simple', 'G\'day mate');
});
this.assertText('G\'day mate - Hallo, Mr. Pitkin', 'the bound value is correct after interior mutation');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'greetings', {
simple: 'Hello Friend',
personal: 'Hello'
});
});
this.assertText('Hallo Freund - Hallo, Mr. Pitkin', 'the bound value is correct after replacement');
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/log-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-console'], function (_emberBabel, _testCase, _emberConsole) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: {{log}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this));
_this.originalLog = _emberConsole.default.log;
_this.logCalls = [];
_emberConsole.default.log = function () {
var _this$logCalls;
(_this$logCalls = _this.logCalls).push.apply(_this$logCalls, arguments);
};
return _this;
}
_class.prototype.teardown = function () {
_RenderingTest.prototype.teardown.call(this);
_emberConsole.default.log = this.originalLog;
};
_class.prototype.assertLog = function (values) {
var i, len;
this.assertText('');
this.assert.strictEqual(this.logCalls.length, values.length);
for (i = 0, len = values.length; i < len; i++) {
this.assert.strictEqual(this.logCalls[i], values[i]);
}
};
_class.prototype['@test correctly logs primitives'] = function () {
this.render('{{log "one" 1 true}}');
this.assertLog(['one', 1, true]);
};
_class.prototype['@test correctly logs a property'] = function () {
this.render('{{log value}}', {
value: 'one'
});
this.assertLog(['one']);
};
_class.prototype['@test correctly logs multiple arguments'] = function () {
this.render('{{log "my variable:" value}}', {
value: 'one'
});
this.assertLog(['my variable:', 'one']);
};
_class.prototype['@test correctly logs `this`'] = function () {
this.render('{{log this}}');
this.assertLog([this.context]);
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/mut-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal', 'ember-glimmer/tests/utils/test-helpers'], function (_emberBabel, _testCase, _helpers, _emberMetal, _testHelpers) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: {{mut}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test a simple mutable binding using `mut` propagates properly'] = function () {
var _this2 = this;
var bottom = void 0;
this.registerComponent('bottom-mut', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
bottom = this;
}
}),
template: '{{setMe}}'
});
this.registerComponent('middle-mut', {
template: '{{bottom-mut setMe=value}}'
});
this.render('{{middle-mut value=(mut val)}}', {
val: 12
});
this.assertText('12', 'the data propagated downwards');
this.assertStableRerender();
this.runTask(function () {
return bottom.attrs.setMe.update(13);
});
this.assertText('13', 'the set took effect');
this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 13, 'the set took effect on bottom\'s prop');
this.assert.strictEqual(bottom.attrs.setMe.value, 13, 'the set took effect on bottom\'s attr');
this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 13, 'the set propagated back up');
this.runTask(function () {
return (0, _emberMetal.set)(bottom, 'setMe', 14);
});
this.assertText('14', 'the set took effect');
this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 14, 'the set took effect on bottom\'s prop');
this.assert.strictEqual(bottom.attrs.setMe.value, 14, 'the set took effect on bottom\'s attr');
this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 14, 'the set propagated back up');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'val', 12);
});
this.assertText('12');
};
_class.prototype['@test a simple mutable binding using `mut` inserts into the DOM'] = function () {
var _this3 = this;
var bottom = void 0,
middle = void 0;
this.registerComponent('bottom-mut', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
bottom = this;
}
}),
template: '{{setMe}}'
});
this.registerComponent('middle-mut', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
middle = this;
}
}),
template: '{{bottom-mut setMe=(mut value)}}'
});
this.render('{{middle-mut value=(mut val)}}', {
val: 12
});
this.assertText('12', 'the data propagated downwards');
this.assertStableRerender();
this.runTask(function () {
return bottom.attrs.setMe.update(13);
});
this.assertText('13', 'the set took effect');
this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 13, 'the set took effect on bottom\'s prop');
this.assert.strictEqual(bottom.attrs.setMe.value, 13, 'the set took effect on bottom\'s attr');
this.assert.strictEqual((0, _emberMetal.get)(middle, 'value'), 13, 'the set propagated to middle\'s prop');
this.assert.strictEqual(middle.attrs.value.value, 13, 'the set propagated to middle\'s attr');
this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 13, 'the set propagated back up');
this.runTask(function () {
return (0, _emberMetal.set)(bottom, 'setMe', 14);
});
this.assertText('14', 'the set took effect');
this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 14, 'the set took effect on bottom\'s prop');
this.assert.strictEqual(bottom.attrs.setMe.value, 14, 'the set took effect on bottom\'s attr');
this.assert.strictEqual((0, _emberMetal.get)(middle, 'value'), 14, 'the set propagated to middle\'s prop');
this.assert.strictEqual(middle.attrs.value.value, 14, 'the set propagated to middle\'s attr');
this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 14, 'the set propagated back up');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'val', 12);
});
this.assertText('12');
};
_class.prototype['@test passing a literal results in a assertion'] = function () {
var _this4 = this;
this.registerComponent('bottom-mut', { template: '{{setMe}}' });
expectAssertion(function () {
_this4.render('{{bottom-mut setMe=(mut "foo bar")}}');
}, 'You can only pass a path to mut');
};
_class.prototype['@test passing the result of a helper invocation results in an assertion'] = function () {
var _this5 = this;
this.registerComponent('bottom-mut', { template: '{{setMe}}' });
expectAssertion(function () {
_this5.render('{{bottom-mut setMe=(mut (concat "foo" " " "bar"))}}');
}, 'You can only pass a path to mut');
};
_class.prototype['@test using a string value through middle tier does not trigger assertion (due to the auto-mut transform)'] = function () {
var bottom = void 0;
this.registerComponent('bottom-mut', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
bottom = this;
}
}),
template: '{{stuff}}'
});
this.registerComponent('middle-mut', {
template: '{{bottom-mut stuff=value}}'
});
this.render('{{middle-mut value="foo"}}');
this.assert.equal((0, _emberMetal.get)(bottom, 'stuff'), 'foo', 'the data propagated');
this.assertText('foo');
this.assertStableRerender();
// No U-R for this test
};
_class.prototype['@test {{readonly}} of a {{mut}} is converted into an immutable binding'] = function () {
var _this6 = this;
var middle = void 0,
bottom = void 0;
this.registerComponent('bottom-mut', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
bottom = this;
}
}),
template: '{{setMe}}'
});
this.registerComponent('middle-mut', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
middle = this;
}
}),
template: '{{bottom-mut setMe=(readonly value)}}'
});
this.render('{{middle-mut value=(mut val)}}', {
val: 12
});
this.assertText('12');
this.assertStableRerender();
this.runTask(function () {
return middle.attrs.value.update(13);
});
this.assert.strictEqual((0, _emberMetal.get)(middle, 'value'), 13, 'the set took effect on middle\'s prop');
this.assert.strictEqual(middle.attrs.value.value, 13, 'the set took effect on middle\'s attr');
this.runTask(function () {
return (0, _emberMetal.set)(middle, 'value', 14);
});
this.assert.strictEqual((0, _emberMetal.get)(middle, 'value'), 14, 'the set took effect on middle\'s prop');
this.assert.strictEqual(middle.attrs.value.value, 14, 'the set took effect on middle\'s attr');
this.assert.strictEqual(bottom.attrs.setMe, 14, 'the mutable binding has been converted to an immutable cell');
this.assertText('14');
this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 14, 'the set propagated back up');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'val', 12);
});
this.assertText('12');
};
_class.prototype['@test mutable bindings work inside of yielded content'] = function () {
var _this7 = this;
this.registerComponent('bottom-mut', {
template: '{{yield}}'
});
this.registerComponent('middle-mut', {
template: '{{#bottom-mut}}{{model.name}}{{/bottom-mut}}'
});
this.render('{{middle-mut model=(mut model)}}', {
model: { name: 'Matthew Beale' }
});
this.assertText('Matthew Beale');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'model.name', 'Joel Kang');
});
this.assertText('Joel Kang');
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'model', { name: 'Matthew Beale' });
});
this.assertText('Matthew Beale');
};
_class.prototype['@test a simple mutable binding using {{mut}} is available in hooks'] = function () {
var _this8 = this;
var bottom = void 0;
var willRender = [];
var didInsert = [];
this.registerComponent('bottom-mut', {
ComponentClass: _helpers.Component.extend({
willRender: function () {
willRender.push((0, _emberMetal.get)(this, 'setMe'));
},
didInsertElement: function () {
didInsert.push((0, _emberMetal.get)(this, 'setMe'));
bottom = this;
}
}),
template: '{{setMe}}'
});
this.registerComponent('middle-mut', {
template: '{{bottom-mut setMe=(mut value)}}'
});
this.render('{{middle-mut value=(mut val)}}', {
val: 12
});
this.assert.deepEqual(willRender, [12], 'willReceive is [12]');
this.assert.deepEqual(didInsert, [12], 'didInsert is [12]');
this.assertText('12');
this.assertStableRerender();
this.assert.deepEqual(willRender, [12], 'willReceive is [12]');
this.assert.deepEqual(didInsert, [12], 'didInsert is [12]');
this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 12, 'the data propagated');
this.runTask(function () {
return bottom.attrs.setMe.update(13);
});
this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 13, 'the set took effect on bottom\'s prop');
this.assert.strictEqual(bottom.attrs.setMe.value, 13, 'the set took effect on bottom\'s attr');
this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 13, 'the set propagated back up');
this.runTask(function () {
return (0, _emberMetal.set)(bottom, 'setMe', 14);
});
this.assert.strictEqual((0, _emberMetal.get)(bottom, 'setMe'), 14, 'the set took effect on bottom\'s prop');
this.assert.strictEqual(bottom.attrs.setMe.value, 14, 'the set took effect on bottom\'s attr');
this.assert.strictEqual((0, _emberMetal.get)(this.context, 'val'), 14, 'the set propagated back up');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'val', 12);
});
this.assertText('12');
};
_class.prototype['@test a mutable binding with a backing computed property and attribute present in the root of the component is updated when the upstream property invalidates #11023'] = function () {
var bottom = void 0,
middle = void 0;
this.registerComponent('bottom-mut', {
ComponentClass: _helpers.Component.extend({
thingy: null,
didInsertElement: function () {
bottom = this;
}
}),
template: '{{thingy}}'
});
this.registerComponent('middle-mut', {
ComponentClass: _helpers.Component.extend({
baseValue: 12,
val: (0, _emberMetal.computed)('baseValue', function () {
return this.get('baseValue');
}),
didInsertElement: function () {
middle = this;
}
}),
template: '{{bottom-mut thingy=(mut val)}}'
});
this.render('{{middle-mut}}');
this.assert.strictEqual((0, _emberMetal.get)(bottom, 'thingy'), 12, 'data propagated');
this.assertText('12');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(middle, 'baseValue', 13);
});
this.assert.strictEqual((0, _emberMetal.get)(middle, 'val'), 13, 'the set took effect');
this.assert.strictEqual(bottom.attrs.thingy.value, 13, 'the set propagated down to bottom\'s attrs');
this.assert.strictEqual((0, _emberMetal.get)(bottom, 'thingy'), 13, 'the set propagated down to bottom\'s prop');
this.assertText('13');
this.runTask(function () {
return (0, _emberMetal.set)(middle, 'baseValue', 12);
});
this.assertText('12');
};
_class.prototype['@test automatic mutable bindings exposes a mut cell in attrs'] = function () {
var inner = void 0;
this.registerComponent('x-inner', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
inner = this;
}
}),
template: '{{foo}}'
});
this.registerComponent('x-outer', {
template: '{{x-inner foo=bar}}'
});
this.render('{{x-outer bar=baz}}', { baz: 'foo' });
this.assertText('foo');
this.assertStableRerender();
this.runTask(function () {
return inner.attrs.foo.update('bar');
});
this.assert.equal(inner.attrs.foo.value, 'bar');
this.assert.equal((0, _emberMetal.get)(inner, 'foo'), 'bar');
this.assertText('bar');
this.runTask(function () {
return inner.attrs.foo.update('foo');
});
this.assertText('foo');
};
_class.prototype['@test automatic mutable bindings tolerate undefined non-stream inputs and attempts to set them'] = function () {
var inner = void 0;
this.registerComponent('x-inner', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
inner = this;
}
}),
template: '{{model}}'
});
this.registerComponent('x-outer', {
template: '{{x-inner model=nonexistent}}'
});
this.render('{{x-outer}}');
this.assertText('');
this.assertStableRerender();
this.runTask(function () {
return inner.attrs.model.update(42);
});
this.assert.equal(inner.attrs.model.value, 42);
this.assert.equal((0, _emberMetal.get)(inner, 'model'), 42);
this.assertText('42');
this.runTask(function () {
return inner.attrs.model.update(undefined);
});
this.assertText('');
};
_class.prototype['@test automatic mutable bindings tolerate constant non-stream inputs and attempts to set them'] = function () {
var inner = void 0;
this.registerComponent('x-inner', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
inner = this;
}
}),
template: 'hello{{model}}'
});
this.registerComponent('x-outer', {
template: '{{x-inner model=x}}'
});
this.render('{{x-outer x="foo"}}');
this.assertText('hellofoo');
this.assertStableRerender();
this.runTask(function () {
return inner.attrs.model.update(42);
});
this.assert.equal(inner.attrs.model.value, 42);
this.assert.equal((0, _emberMetal.get)(inner, 'model'), 42);
this.assertText('hello42');
this.runTask(function () {
return inner.attrs.model.update('foo');
});
this.assertText('hellofoo');
};
return _class;
}(_testCase.RenderingTest));
(0, _testCase.moduleFor)('Mutable Bindings used in Computed Properties that are bound as attributeBindings', function (_RenderingTest2) {
(0, _emberBabel.inherits)(_class2, _RenderingTest2);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments));
}
_class2.prototype['@test an attribute binding of a computed property of a 2-way bound attr recomputes when the attr changes'] = function () {
var _this10 = this;
var input = void 0,
output = void 0;
this.registerComponent('x-input', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
input = this;
}
})
});
this.registerComponent('x-output', {
ComponentClass: _helpers.Component.extend({
attributeBindings: ['style'],
didInsertElement: function () {
output = this;
},
style: (0, _emberMetal.computed)('height', function () {
var height = this.get('height');
return 'height: ' + height + 'px;';
}),
height: 20
}),
template: '{{height}}'
});
this.render('{{x-output height=height}}{{x-input height=(mut height)}}', {
height: 60
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 60px;') }, content: '60' });
this.assertStableRerender();
this.runTask(function () {
return input.attrs.height.update(35);
});
this.assert.strictEqual((0, _emberMetal.get)(output, 'height'), 35, 'the set took effect');
this.assert.strictEqual((0, _emberMetal.get)(this.context, 'height'), 35, 'the set propagated back up');
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 35px;') }, content: '35' });
this.runTask(function () {
return (0, _emberMetal.set)(input, 'height', 36);
});
this.assert.strictEqual((0, _emberMetal.get)(output, 'height'), 36, 'the set took effect');
this.assert.strictEqual((0, _emberMetal.get)(this.context, 'height'), 36, 'the set propagated back up');
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 36px;') }, content: '36' });
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'height', 60);
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 60px;') }, content: '60' });
this.assert.strictEqual((0, _emberMetal.get)(input, 'height'), 60);
};
_class2.prototype['@test an attribute binding of a computed property with a setter of a 2-way bound attr recomputes when the attr changes'] = function () {
var _this11 = this;
var input = void 0,
output = void 0;
this.registerComponent('x-input', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
input = this;
}
})
});
this.registerComponent('x-output', {
ComponentClass: _helpers.Component.extend({
attributeBindings: ['style'],
didInsertElement: function () {
output = this;
},
style: (0, _emberMetal.computed)('height', 'width', function () {
var height = this.get('height');
var width = this.get('width');
return 'height: ' + height + 'px; width: ' + width + 'px;';
}),
height: 20,
width: (0, _emberMetal.computed)('height', {
get: function () {
return this.get('height') * 2;
},
set: function (keyName, width) {
this.set('height', width / 2);
return width;
}
})
}),
template: '{{width}}x{{height}}'
});
this.render('{{x-output width=width}}{{x-input width=(mut width)}}', {
width: 70
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 35px; width: 70px;') }, content: '70x35' });
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(input, 'width', 80);
});
this.assert.strictEqual((0, _emberMetal.get)(output, 'width'), 80, 'the set took effect');
this.assert.strictEqual((0, _emberMetal.get)(this.context, 'width'), 80, 'the set propagated back up');
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 40px; width: 80px;') }, content: '80x40' });
this.runTask(function () {
return input.attrs.width.update(90);
});
this.assert.strictEqual((0, _emberMetal.get)(output, 'width'), 90, 'the set took effect');
this.assert.strictEqual((0, _emberMetal.get)(this.context, 'width'), 90, 'the set propagated back up');
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 45px; width: 90px;') }, content: '90x45' });
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'width', 70);
});
this.assertComponentElement(this.firstChild, { tagName: 'div', attrs: { style: (0, _testHelpers.styles)('height: 35px; width: 70px;') }, content: '70x35' });
this.assert.strictEqual((0, _emberMetal.get)(input, 'width'), 70);
};
return _class2;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/partial-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _testCase, _emberMetal, _abstractTestCase) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each model.items as |template i|}}\n {{model.type}}: {{partial template}}\n {{/each}}'], ['\n {{#each model.items as |template i|}}\n {{model.type}}: {{partial template}}\n {{/each}}']),
_templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with item.thing as |t|}}\n {{partial t}}\n {{else}}\n Nothing!\n {{/with}}'], ['\n {{#with item.thing as |t|}}\n {{partial t}}\n {{else}}\n Nothing!\n {{/with}}']);
(0, _testCase.moduleFor)('Helpers test: {{partial}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test should render other templates registered with the container'] = function () {
this.registerPartial('_subTemplateFromContainer', 'sub-template');
this.render('This {{partial "subTemplateFromContainer"}} is pretty great.');
this.assertStableRerender();
this.assertText('This sub-template is pretty great.');
};
_class.prototype['@test should render other slash-separated templates registered with the container'] = function () {
this.registerPartial('child/_subTemplateFromContainer', 'sub-template');
this.render('This {{partial "child/subTemplateFromContainer"}} is pretty great.');
this.assertStableRerender();
this.assertText('This sub-template is pretty great.');
};
_class.prototype['@test should use the current context'] = function () {
var _this2 = this;
this.registerPartial('_person_name', '{{model.firstName}} {{model.lastName}}');
this.render('Who is {{partial "person_name"}}?', {
model: {
firstName: 'Kris',
lastName: 'Selden'
}
});
this.assertStableRerender();
this.assertText('Who is Kris Selden?');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'model.firstName', 'Kelly');
});
this.assertText('Who is Kelly Selden?');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'model', { firstName: 'Kris', lastName: 'Selden' });
});
this.assertText('Who is Kris Selden?');
};
_class.prototype['@test Quoteless parameters passed to {{partial}} perform a bound property lookup of the partial name'] = function () {
var _this3 = this;
this.registerPartial('_subTemplate', 'sub-template');
this.registerPartial('_otherTemplate', 'other-template');
this.render('This {{partial templates.partialName}} is pretty {{partial nonexistent}}great.', {
templates: { partialName: 'subTemplate' }
});
this.assertStableRerender();
this.assertText('This sub-template is pretty great.');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'templates.partialName', 'otherTemplate');
});
this.assertText('This other-template is pretty great.');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'templates.partialName', null);
});
this.assertText('This is pretty great.');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'templates', { partialName: 'subTemplate' });
});
this.assertText('This sub-template is pretty great.');
};
_class.prototype['@test dynamic partials in {{#each}}'] = function () {
var _this4 = this;
this.registerPartial('_odd', 'ODD{{i}}');
this.registerPartial('_even', 'EVEN{{i}}');
this.render((0, _abstractTestCase.strip)(_templateObject), {
model: {
items: ['even', 'odd', 'even', 'odd'],
type: 'number'
}
});
this.assertStableRerender();
this.assertText('number: EVEN0number: ODD1number: EVEN2number: ODD3');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'model.type', 'integer');
});
this.assertText('integer: EVEN0integer: ODD1integer: EVEN2integer: ODD3');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'model', {
items: ['even', 'odd', 'even', 'odd'],
type: 'number'
});
});
this.assertText('number: EVEN0number: ODD1number: EVEN2number: ODD3');
};
_class.prototype['@test dynamic partials in {{#with}}'] = function () {
var _this5 = this;
this.registerPartial('_thing', '{{t}}');
this.render((0, _abstractTestCase.strip)(_templateObject2), {
item: { thing: false }
});
this.assertStableRerender();
this.assertText('Nothing!');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'item.thing', 'thing');
});
this.assertText('thing');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'item', { thing: false });
});
this.assertText('Nothing!');
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/readonly-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-metal'], function (_emberBabel, _testCase, _helpers, _emberMetal) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: {{readonly}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test {{readonly}} of a path should work'] = function () {
var component = void 0;
this.registerComponent('foo-bar', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
component = this;
}
}),
template: '{{value}}'
});
this.render('{{foo-bar value=(readonly val)}}', {
val: 12
});
this.assertText('12');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(component, 'value', 13);
});
this.assert.notOk(component.attrs.value.update);
this.assertText('13', 'local property is updated');
this.assert.equal((0, _emberMetal.get)(this.context, 'val'), 12, 'upstream attribute is not updated');
// No U-R
};
_class.prototype['@test {{readonly}} of a string renders correctly'] = function () {
var component = void 0;
this.registerComponent('foo-bar', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
component = this;
}
}),
template: '{{value}}'
});
this.render('{{foo-bar value=(readonly "12")}}');
this.assertText('12');
this.assertStableRerender();
this.assert.notOk(component.attrs.value.update);
this.assert.strictEqual((0, _emberMetal.get)(component, 'value'), '12');
this.runTask(function () {
return (0, _emberMetal.set)(component, 'value', '13');
});
this.assertText('13', 'local property is updated');
this.assert.strictEqual((0, _emberMetal.get)(component, 'value'), '13');
this.runTask(function () {
return (0, _emberMetal.set)(component, 'value', '12');
});
this.assertText('12');
};
_class.prototype['@test {{mut}} of a {{readonly}} mutates only the middle and bottom tiers'] = function () {
var _this2 = this;
var middle = void 0,
bottom = void 0;
this.registerComponent('x-bottom', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
bottom = this;
}
}),
template: '{{bar}}'
});
this.registerComponent('x-middle', {
ComponentClass: _helpers.Component.extend({
didInsertElement: function () {
middle = this;
}
}),
template: '{{foo}} {{x-bottom bar=(mut foo)}}'
});
this.render('{{x-middle foo=(readonly val)}}', {
val: 12
});
this.assertText('12 12');
this.assertStableRerender();
this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), 12, 'bottom\'s local bar received the value');
this.assert.equal((0, _emberMetal.get)(middle, 'foo'), 12, 'middle\'s local foo received the value');
this.runTask(function () {
return bottom.attrs.bar.update(13);
});
this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), 13, 'bottom\'s local bar was updated after set of bottom\'s bar');
this.assert.equal((0, _emberMetal.get)(middle, 'foo'), 13, 'middle\'s local foo was updated after set of bottom\'s bar');
this.assertText('13 13');
this.assert.equal((0, _emberMetal.get)(this.context, 'val'), 12, 'But context val is not updated');
this.runTask(function () {
return (0, _emberMetal.set)(bottom, 'bar', 14);
});
this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), 14, 'bottom\'s local bar was updated after set of bottom\'s bar');
this.assert.equal((0, _emberMetal.get)(middle, 'foo'), 14, 'middle\'s local foo was updated after set of bottom\'s bar');
this.assertText('14 14');
this.assert.equal((0, _emberMetal.get)(this.context, 'val'), 12, 'But context val is not updated');
this.assert.notOk(middle.attrs.foo.update, 'middle\'s foo attr is not a mutable cell');
this.runTask(function () {
return (0, _emberMetal.set)(middle, 'foo', 15);
});
this.assertText('15 15');
this.assert.equal((0, _emberMetal.get)(middle, 'foo'), 15, 'set of middle\'s foo took effect');
this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), 15, 'bottom\'s local bar was updated after set of middle\'s foo');
this.assert.equal((0, _emberMetal.get)(this.context, 'val'), 12, 'Context val remains unchanged');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'val', 10);
});
this.assertText('10 10');
this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), 10, 'bottom\'s local bar was updated after set of context\'s val');
this.assert.equal((0, _emberMetal.get)(middle, 'foo'), 10, 'middle\'s local foo was updated after set of context\'s val');
this.runTask(function () {
return (0, _emberMetal.set)(bottom, 'bar', undefined);
});
this.assertText(' ');
this.assert.equal((0, _emberMetal.get)(bottom, 'bar'), undefined, 'bottom\'s local bar was updated to a falsy value');
this.assert.equal((0, _emberMetal.get)(middle, 'foo'), undefined, 'middle\'s local foo was updated to a falsy value');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'val', 12);
});
this.assertText('12 12', 'bottom and middle were both reset');
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/render-test', ['ember-babel', 'ember-metal', 'ember-runtime', 'ember-glimmer/tests/utils/test-case'], function (_emberBabel, _emberMetal, _emberRuntime, _testCase) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: {{render}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test should render given template'] = function () {
var _this2 = this;
this.registerTemplate('home', 'BYE
');
expectDeprecation(function () {
_this2.render('HI {{render \'home\'}}');
}, /Please refactor [\w\{\}"` ]+ to a component/);
this.assertText('HIBYE');
};
_class.prototype['@test uses `controller:basic` as the basis for a generated controller when none exists for specified name'] = function () {
var _this3 = this;
this.owner.register('controller:basic', _emberRuntime.Controller.extend({
isBasicController: true
}));
this.registerTemplate('home', '{{isBasicController}}');
expectDeprecation(function () {
_this3.render('{{render \'home\'}}');
}, /Please refactor [\w\{\}"` ]+ to a component/);
this.assertText('true');
};
_class.prototype['@test generates a controller if none exists'] = function () {
var _this4 = this;
this.registerTemplate('home', '{{this}}
');
expectDeprecation(function () {
_this4.render('HI {{render \'home\'}}');
}, /Please refactor [\w\{\}"` ]+ to a component/);
this.assertText('HI(generated home controller)');
};
_class.prototype['@test should use controller with the same name as template if present'] = function () {
var _this5 = this;
this.owner.register('controller:home', _emberRuntime.Controller.extend({ name: 'home' }));
this.registerTemplate('home', '{{name}}BYE
');
expectDeprecation(function () {
_this5.render('HI {{render \'home\'}}');
}, /Please refactor [\w\{\}"` ]+ to a component/);
this.assertText('HIhomeBYE');
};
_class.prototype['@test should render nested helpers'] = function () {
var _this6 = this;
this.owner.register('controller:home', _emberRuntime.Controller.extend());
this.owner.register('controller:foo', _emberRuntime.Controller.extend());
this.owner.register('controller:bar', _emberRuntime.Controller.extend());
this.owner.register('controller:baz', _emberRuntime.Controller.extend());
this.registerTemplate('home', 'BYE
');
this.registerTemplate('baz', 'BAZ
');
expectDeprecation(function () {
_this6.registerTemplate('foo', 'FOO
{{render \'bar\'}}');
_this6.registerTemplate('bar', 'BAR
{{render \'baz\'}}');
_this6.render('HI {{render \'foo\'}}');
}, /Please refactor [\w\{\}"` ]+ to a component/);
this.assertText('HIFOOBARBAZ');
};
_class.prototype['@test should have assertion if the template does not exist'] = function () {
var _this7 = this;
this.owner.register('controller:oops', _emberRuntime.Controller.extend());
expectDeprecation(function () {
expectAssertion(function () {
_this7.render('HI {{render \'oops\'}}');
}, 'You used `{{render \'oops\'}}`, but \'oops\' can not be found as a template.');
}, /Please refactor [\w\{\}"` ]+ to a component/);
};
_class.prototype['@test should render given template with the singleton controller as its context'] = function () {
var _this8 = this;
this.owner.register('controller:post', _emberRuntime.Controller.extend({
init: function () {
this.set('title', 'It\'s Simple Made Easy');
}
}));
this.registerTemplate('post', '{{title}}
');
expectDeprecation(function () {
_this8.render('HI {{render \'post\'}}');
}, /Please refactor [\w\{\}"` ]+ to a component/);
this.assertText('HIIt\'s Simple Made Easy');
this.runTask(function () {
return _this8.rerender();
});
this.assertText('HIIt\'s Simple Made Easy');
var controller = this.owner.lookup('controller:post');
this.runTask(function () {
return (0, _emberMetal.set)(controller, 'title', 'Rails is omakase');
});
this.assertText('HIRails is omakase');
this.runTask(function () {
return (0, _emberMetal.set)(controller, 'title', 'It\'s Simple Made Easy');
});
this.assertText('HIIt\'s Simple Made Easy');
};
_class.prototype['@test should not destroy the singleton controller on teardown'] = function (assert) {
var _this9 = this;
var willDestroyFired = 0;
this.owner.register('controller:post', _emberRuntime.Controller.extend({
init: function () {
this.set('title', 'It\'s Simple Made Easy');
},
willDestroy: function () {
this._super.apply(this, arguments);
willDestroyFired++;
}
}));
this.registerTemplate('post', '{{title}}
');
expectDeprecation(function () {
_this9.render('{{#if showPost}}{{render \'post\'}}{{else}}Nothing here{{/if}}', { showPost: false });
}, /Please refactor [\w\{\}"` ]+ to a component/);
this.assertText('Nothing here');
assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller');
this.runTask(function () {
return _this9.rerender();
});
this.assertText('Nothing here');
assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'showPost', true);
});
this.assertText('It\'s Simple Made Easy');
assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'showPost', false);
});
this.assertText('Nothing here');
assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller');
};
_class.prototype['@test should render given template with a supplied model'] = function () {
var _this10 = this;
this.owner.register('controller:post', _emberRuntime.Controller.extend());
this.registerTemplate('post', '{{model.title}}
');
expectDeprecation(function () {
_this10.render('HI {{render \'post\' post}}', {
post: {
title: 'It\'s Simple Made Easy'
}
});
}, /Please refactor [\w\{\}"` ]+ to a component/);
this.assertText('HIIt\'s Simple Made Easy');
this.runTask(function () {
return _this10.rerender();
});
this.assertText('HIIt\'s Simple Made Easy');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'post.title', 'Rails is omakase');
});
this.assertText('HIRails is omakase');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'post', { title: 'It\'s Simple Made Easy' });
});
this.assertText('HIIt\'s Simple Made Easy');
};
_class.prototype['@test should destroy the non-singleton controllers on teardown'] = function (assert) {
var _this11 = this;
var willDestroyFired = 0;
this.owner.register('controller:post', _emberRuntime.Controller.extend({
willDestroy: function () {
this._super.apply(this, arguments);
willDestroyFired++;
}
}));
this.registerTemplate('post', '{{model.title}}
');
expectDeprecation(function () {
_this11.render('{{#if showPost}}{{render \'post\' post}}{{else}}Nothing here{{/if}}', {
showPost: false,
post: {
title: 'It\'s Simple Made Easy'
}
});
}, /Please refactor [\w\{\}"` ]+ to a component/);
this.assertText('Nothing here');
assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller');
this.runTask(function () {
return _this11.rerender();
});
this.assertText('Nothing here');
assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'showPost', true);
});
this.assertText('It\'s Simple Made Easy');
assert.strictEqual(willDestroyFired, 0, 'it did not destroy the controller');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'showPost', false);
});
this.assertText('Nothing here');
assert.strictEqual(willDestroyFired, 1, 'it did destroy the controller');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'showPost', true);
});
this.assertText('It\'s Simple Made Easy');
assert.strictEqual(willDestroyFired, 1, 'it did not destroy the controller');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'showPost', false);
});
this.assertText('Nothing here');
assert.strictEqual(willDestroyFired, 2, 'it did destroy the controller');
};
_class.prototype['@test with a supplied model should not fire observers on the controller'] = function () {
var _this12 = this;
this.owner.register('controller:post', _emberRuntime.Controller.extend());
this.registerTemplate('post', '{{model.title}}
');
var postDidChange = 0;
expectDeprecation(function () {
_this12.render('HI {{render \'post\' post}}', {
postDidChange: (0, _emberMetal.observer)('post', function () {
postDidChange++;
}),
post: {
title: 'It\'s Simple Made Easy'
}
});
}, /Please refactor [\w\{\}"` ]+ to a component/);
this.assertText('HIIt\'s Simple Made Easy');
this.runTask(function () {
return _this12.rerender();
});
this.assertText('HIIt\'s Simple Made Easy');
};
_class.prototype['@test should raise an error when a given controller name does not resolve to a controller'] = function () {
var _this13 = this;
this.registerTemplate('home', 'BYE
');
this.owner.register('controller:posts', _emberRuntime.Controller.extend());
expectDeprecation(function () {
expectAssertion(function () {
_this13.render('HI {{render "home" controller="postss"}}');
}, /The controller name you supplied \'postss\' did not resolve to a controller./);
}, /Please refactor [\w\{\}"` ]+ to a component/);
};
_class.prototype['@test should render with given controller'] = function (assert) {
var _this14 = this;
this.registerTemplate('home', '{{uniqueId}}');
var id = 0;
var model = {};
this.owner.register('controller:posts', _emberRuntime.Controller.extend({
init: function () {
this._super.apply(this, arguments);
this.uniqueId = id++;
this.set('model', model);
}
}));
expectDeprecation(function () {
_this14.render('{{render "home" controller="posts"}}');
}, /Please refactor [\w\{\}"` ]+ to a component/);
var renderedController = this.owner.lookup('controller:posts');
var uniqueId = renderedController.get('uniqueId');
var renderedModel = renderedController.get('model');
assert.equal(uniqueId, 0);
assert.equal(renderedModel, model);
this.assertText('0');
this.runTask(function () {
return _this14.rerender();
});
assert.equal(uniqueId, 0);
assert.equal(renderedModel, model);
this.assertText('0');
};
_class.prototype['@test should render templates with models multiple times'] = function () {
var _this15 = this;
this.owner.register('controller:post', _emberRuntime.Controller.extend());
this.registerTemplate('post', '{{model.title}}
');
expectDeprecation(function () {
_this15.render('HI {{render \'post\' post1}} {{render \'post\' post2}}', {
post1: {
title: 'Me First'
},
post2: {
title: 'Then me'
}
});
}, /Please refactor [\w\{\}"` ]+ to a component/);
this.assertText('HI Me First Then me');
this.runTask(function () {
return _this15.rerender();
});
this.assertText('HI Me First Then me');
this.runTask(function () {
return (0, _emberMetal.set)(_this15.context, 'post1.title', 'I am new');
});
this.assertText('HI I am new Then me');
this.runTask(function () {
return (0, _emberMetal.set)(_this15.context, 'post1', { title: 'Me First' });
});
this.assertText('HI Me First Then me');
};
_class.prototype['@test should not treat invocations with falsy contexts as context-less'] = function (assert) {
var _this16 = this;
this.registerTemplate('post', '{{#unless model.zero}}NOTHING{{/unless}}
');
this.owner.register('controller:post', _emberRuntime.Controller.extend());
expectDeprecation(function () {
_this16.render('HI {{render \'post\' zero}} {{render \'post\' nonexistent}}', {
model: {
zero: false
}
});
}, /Please refactor [\w\{\}"` ]+ to a component/);
assert.ok(this.$().text().match(/^HI ?NOTHING ?NOTHING$/));
};
_class.prototype['@test should render templates both with and without models'] = function (assert) {
var _this17 = this;
this.registerTemplate('post', 'Title:{{model.title}}
');
this.owner.register('controller:post', _emberRuntime.Controller.extend());
var post = {
title: 'Rails is omakase'
};
expectDeprecation(function () {
_this17.render('HI {{render \'post\'}} {{render \'post\' post}}', {
post: post
});
}, /Please refactor [\w\{\}"` ]+ to a component/);
assert.ok(this.$().text().match(/^HI ?Title: ?Title:Rails is omakase$/));
this.runTask(function () {
return _this17.rerender();
});
assert.ok(this.$().text().match(/^HI ?Title: ?Title:Rails is omakase$/));
this.runTask(function () {
return (0, _emberMetal.set)(_this17.context, 'post.title', 'Simple Made Easy');
});
assert.ok(this.$().text().match(/^HI ?Title: ?Title:Simple Made Easy$/));
this.runTask(function () {
return (0, _emberMetal.set)(_this17.context, 'post', { title: 'Rails is omakase' });
});
assert.ok(this.$().text().match(/^HI ?Title: ?Title:Rails is omakase$/));
};
_class.prototype['@test works with dot notation'] = function () {
var _this18 = this;
this.registerTemplate('blog.post', '{{uniqueId}}');
var id = 0;
this.owner.register('controller:blog.post', _emberRuntime.Controller.extend({
init: function () {
this._super.apply(this, arguments);
this.uniqueId = id++;
}
}));
expectDeprecation(function () {
_this18.render('{{render "blog.post"}}');
}, /Please refactor [\w\.{\}"` ]+ to a component/);
this.assertText('0');
};
_class.prototype['@test throws an assertion if called with an unquoted template name'] = function () {
var _this19 = this;
this.registerTemplate('home', 'BYE
');
expectAssertion(function () {
_this19.render('HI {{render home}}');
}, 'The first argument of {{render}} must be quoted, e.g. {{render "sidebar"}}.');
};
_class.prototype['@test throws an assertion if called with a literal for a model'] = function () {
var _this20 = this;
this.registerTemplate('home', 'BYE
');
expectAssertion(function () {
_this20.render('HI {{render "home" "model"}}', {
model: {
title: 'Simple Made Easy'
}
});
}, 'The second argument of {{render}} must be a path, e.g. {{render "post" post}}.');
};
_class.prototype['@test should set router as target when action not found on parentController is not found'] = function (assert) {
var _this21 = this;
var postController = void 0;
this.registerTemplate('post', 'post template');
this.owner.register('controller:post', _emberRuntime.Controller.extend({
init: function () {
this._super.apply(this, arguments);
postController = this;
}
}));
this.owner.register('router:main', {
send: function (actionName) {
assert.equal(actionName, 'someAction');
assert.ok(true, 'routerStub#send called');
}
}, { instantiate: false });
expectDeprecation(function () {
_this21.render('{{render \'post\' post1}}');
}, /Please refactor [\w\{\}"` ]+ to a component/);
postController.send('someAction');
};
_class.prototype['@test render helper emits useful backtracking re-render assertion message'] = function () {
var _this22 = this;
this.owner.register('controller:outer', _emberRuntime.Controller.extend());
this.owner.register('controller:inner', _emberRuntime.Controller.extend({
propertyWithError: (0, _emberMetal.computed)(function () {
this.set('model.name', 'this will cause a backtracking error');
return 'foo';
})
}));
var expectedBacktrackingMessage = /modified "model\.name" twice on \[object Object\] in a single render\. It was rendered in "controller:outer \(with the render helper\)" and modified in "controller:inner \(with the render helper\)"/;
expectDeprecation(function () {
var person = { name: 'Ben' };
_this22.registerTemplate('outer', 'Hi {{model.name}} | {{render \'inner\' model}}');
_this22.registerTemplate('inner', 'Hi {{propertyWithError}}');
expectAssertion(function () {
_this22.render('{{render \'outer\' person}}', { person: person });
}, expectedBacktrackingMessage);
});
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/text-area-test', ['ember-babel', 'ember-utils', 'ember-metal', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/test-helpers', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _emberUtils, _emberMetal, _helpers, _testCase, _testHelpers, _abstractTestCase) {
'use strict';
var TextAreaRenderingTest = function (_RenderingTest) {
(0, _emberBabel.inherits)(TextAreaRenderingTest, _RenderingTest);
function TextAreaRenderingTest() {
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this));
_this.registerComponent('-text-area', { ComponentClass: _helpers.TextArea });
return _this;
}
TextAreaRenderingTest.prototype.assertTextArea = function () {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
attrs = _ref.attrs,
value = _ref.value;
var mergedAttrs = (0, _emberUtils.assign)({ 'class': (0, _testHelpers.classes)('ember-view ember-text-area') }, attrs);
this.assertComponentElement(this.firstChild, { tagName: 'textarea', attrs: mergedAttrs });
if (value) {
this.assert.strictEqual(value, this.firstChild.value);
}
};
TextAreaRenderingTest.prototype.triggerEvent = function (type) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var event = document.createEvent('Events');
event.initEvent(type, true, true);
(0, _emberUtils.assign)(event, options);
this.firstChild.dispatchEvent(event);
};
return TextAreaRenderingTest;
}(_testCase.RenderingTest);
var BoundTextAreaAttributes = function () {
function BoundTextAreaAttributes(cases) {
this.cases = cases;
}
BoundTextAreaAttributes.prototype.generate = function (_ref2) {
var _ref3;
var attribute = _ref2.attribute,
first = _ref2.first,
second = _ref2.second;
return _ref3 = {}, _ref3['@test ' + attribute] = function () {
var _attrs,
_this2 = this,
_attrs2,
_attrs3;
this.render('{{textarea ' + attribute + '=value}}', {
value: first
});
this.assertTextArea({ attrs: (_attrs = {}, _attrs[attribute] = first, _attrs) });
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'value', second);
});
this.assertTextArea({ attrs: (_attrs2 = {}, _attrs2[attribute] = second, _attrs2) });
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'value', first);
});
this.assertTextArea({ attrs: (_attrs3 = {}, _attrs3[attribute] = first, _attrs3) });
}, _ref3;
};
return BoundTextAreaAttributes;
}();
(0, _abstractTestCase.applyMixins)(TextAreaRenderingTest, new BoundTextAreaAttributes([{ attribute: 'placeholder', first: 'Stuff here', second: 'Other stuff' }, { attribute: 'name', first: 'Stuff here', second: 'Other stuff' }, { attribute: 'title', first: 'Stuff here', second: 'Other stuff' }, { attribute: 'maxlength', first: '1', second: '2' }, { attribute: 'rows', first: '1', second: '2' }, { attribute: 'cols', first: '1', second: '2' }, { attribute: 'tabindex', first: '1', second: '2' }]));
(0, _testCase.moduleFor)('Helpers test: {{textarea}}', function (_TextAreaRenderingTes) {
(0, _emberBabel.inherits)(_class, _TextAreaRenderingTes);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TextAreaRenderingTes.apply(this, arguments));
}
_class.prototype['@test Should insert a textarea'] = function () {
this.render('{{textarea}}');
equal(this.$('textarea').length, 1);
this.assertStableRerender();
};
_class.prototype['@test Should respect disabled'] = function () {
this.render('{{textarea disabled=disabled}}', {
disabled: true
});
ok(this.$('textarea').is(':disabled'));
};
_class.prototype['@test Should respect disabled when false'] = function () {
this.render('{{textarea disabled=disabled}}', {
disabled: false
});
ok(this.$('textarea').is(':not(:disabled)'));
};
_class.prototype['@test Should become disabled when the context changes'] = function () {
var _this4 = this;
this.render('{{textarea disabled=disabled}}');
ok(this.$('textarea').is(':not(:disabled)'));
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'disabled', true);
});
ok(this.$('textarea').is(':disabled'));
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'disabled', false);
});
ok(this.$('textarea').is(':not(:disabled)'));
};
_class.prototype['@test Should bind its contents to the specified value'] = function () {
var _this5 = this;
this.render('{{textarea value=model.val}}', {
model: { val: 'A beautiful day in Seattle' }
});
this.assertTextArea({ value: 'A beautiful day in Seattle' });
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'model.val', 'Auckland');
});
this.assertTextArea({ value: 'Auckland' });
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'model', { val: 'A beautiful day in Seattle' });
});
this.assertTextArea({ value: 'A beautiful day in Seattle' });
};
_class.prototype['@test GH#14001 Should correctly handle an empty string bound value'] = function () {
var _this6 = this;
this.render('{{textarea value=message}}', { message: '' });
this.assert.strictEqual(this.firstChild.value, '');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'message', 'hello');
});
this.assert.strictEqual(this.firstChild.value, 'hello');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'message', '');
});
this.assert.strictEqual(this.firstChild.value, '');
};
_class.prototype['@test should update the value for `cut` / `input` / `change` events'] = function () {
var _this7 = this;
this.render('{{textarea value=model.val}}', {
model: { val: 'A beautiful day in Seattle' }
});
this.assertTextArea({ value: 'A beautiful day in Seattle' });
this.assertStableRerender();
this.runTask(function () {
_this7.firstChild.value = 'Auckland';
_this7.triggerEvent('cut');
});
this.assertTextArea({ value: 'Auckland' });
this.runTask(function () {
_this7.firstChild.value = 'Hope';
_this7.triggerEvent('paste');
});
this.assertTextArea({ value: 'Hope' });
this.runTask(function () {
_this7.firstChild.value = 'Boston';
_this7.triggerEvent('input');
});
this.assertTextArea({ value: 'Boston' });
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'model', { val: 'A beautiful day in Seattle' });
});
this.assertTextArea({ value: 'A beautiful day in Seattle' });
};
return _class;
}(TextAreaRenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/unbound-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-metal', 'ember-glimmer/tests/utils/helpers', 'ember-runtime'], function (_emberBabel, _testCase, _abstractTestCase, _emberMetal, _helpers, _emberRuntime) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n '], ['\n \n ']),
_templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{unbound (surround model.prefix model.value "bar")}} {{surround model.prefix model.value "bar"}} {{unbound (surround "bar" model.value model.suffix)}} {{surround "bar" model.value model.suffix}}'], ['\n {{unbound (surround model.prefix model.value "bar")}} {{surround model.prefix model.value "bar"}} {{unbound (surround "bar" model.value model.suffix)}} {{surround "bar" model.value model.suffix}}']),
_templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if (unbound model.foo)}}\n {{#if model.bar}}true{{/if}}\n {{#unless model.bar}}false{{/unless}}\n {{/if}}\n {{#unless (unbound model.notfoo)}}\n {{#if model.bar}}true{{/if}}\n {{#unless model.bar}}false{{/unless}}\n {{/unless}}'], ['\n {{#if (unbound model.foo)}}\n {{#if model.bar}}true{{/if}}\n {{#unless model.bar}}false{{/unless}}\n {{/if}}\n {{#unless (unbound model.notfoo)}}\n {{#if model.bar}}true{{/if}}\n {{#unless model.bar}}false{{/unless}}\n {{/unless}}']);
(0, _testCase.moduleFor)('Helpers test: {{unbound}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test should be able to output a property without binding'] = function () {
var _this2 = this;
this.render('{{unbound content.anUnboundString}}
', {
content: {
anUnboundString: 'No spans here, son.'
}
});
this.assertText('No spans here, son.');
this.runTask(function () {
return _this2.rerender();
});
this.assertText('No spans here, son.');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'content.anUnboundString', 'HEY');
});
this.assertText('No spans here, son.');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'content', {
anUnboundString: 'No spans here, son.'
});
});
this.assertText('No spans here, son.');
};
_class.prototype['@test should be able to use unbound helper in #each helper'] = function () {
var _this3 = this;
this.render('{{#each items as |item|}}{{unbound item}} {{/each}} ', {
items: (0, _emberRuntime.A)(['a', 'b', 'c', 1, 2, 3])
});
this.assertText('abc123');
this.runTask(function () {
return _this3.rerender();
});
this.assertText('abc123');
};
_class.prototype['@test should be able to use unbound helper in #each helper (with objects)'] = function () {
var _this4 = this;
this.render('{{#each items as |item|}}{{unbound item.wham}} {{/each}} ', {
items: (0, _emberRuntime.A)([{ wham: 'bam' }, { wham: 1 }])
});
this.assertText('bam1');
this.runTask(function () {
return _this4.rerender();
});
this.assertText('bam1');
this.runTask(function () {
return _this4.context.items.setEach('wham', 'HEY');
});
this.assertText('bam1');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'items', (0, _emberRuntime.A)([{ wham: 'bam' }, { wham: 1 }]));
});
this.assertText('bam1');
};
_class.prototype['@test it should assert unbound cannot be called with multiple arguments'] = function () {
var _this5 = this;
expectAssertion(function () {
_this5.render('{{unbound foo bar}}', {
foo: 'BORK',
bar: 'BLOOP'
});
}, /unbound helper cannot be called with multiple params or hash params/);
};
_class.prototype['@test should render on attributes'] = function () {
var _this6 = this;
this.render(' ', {
model: { foo: 'BORK' }
});
this.assertHTML(' ');
this.runTask(function () {
return _this6.rerender();
});
this.assertHTML(' ');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'model.foo', 'OOF');
});
this.assertHTML(' ');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'model', { foo: 'BORK' });
});
this.assertHTML(' ');
};
_class.prototype['@test should property escape unsafe hrefs'] = function () {
var _this7 = this;
var unsafeUrls = (0, _emberRuntime.A)([{
name: 'Bob',
url: 'javascript:bob-is-cool' // jshint ignore:line
}, {
name: 'James',
url: 'vbscript:james-is-cool' // jshint ignore:line
}, {
name: 'Richard',
url: 'javascript:richard-is-cool' // jshint ignore:line
}]);
this.render('', {
people: unsafeUrls
});
var escapedHtml = (0, _abstractTestCase.strip)(_templateObject);
this.assertHTML(escapedHtml);
this.runTask(function () {
return _this7.rerender();
});
this.assertHTML(escapedHtml);
this.runTask(function () {
return _this7.context.people.setEach('url', 'http://google.com');
});
this.assertHTML(escapedHtml);
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'people', unsafeUrls);
});
this.assertHTML(escapedHtml);
};
_class.prototype['@skip helper form updates on parent re-render'] = function () {
var _this8 = this;
this.render('{{unbound foo}}', {
foo: 'BORK'
});
this.assertText('BORK');
this.runTask(function () {
return _this8.rerender();
});
this.assertText('BORK');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'foo', 'OOF');
});
this.assertText('BORK');
this.runTask(function () {
return _this8.rerender();
});
this.assertText('OOF');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'foo', '');
});
this.assertText('OOF');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'foo', 'BORK');
});
this.runTask(function () {
return _this8.rerender();
});
this.assertText('BORK');
};
_class.prototype['@test sexpr form does not update no matter what'] = function () {
var _this9 = this;
this.registerHelper('capitalize', function (args) {
return args[0].toUpperCase();
});
this.render('{{capitalize (unbound foo)}}', {
foo: 'bork'
});
this.assertText('BORK');
this.runTask(function () {
return _this9.rerender();
});
this.assertText('BORK');
this.runTask(function () {
(0, _emberMetal.set)(_this9.context, 'foo', 'oof');
_this9.rerender();
});
this.assertText('BORK');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'foo', 'blip');
});
this.assertText('BORK');
this.runTask(function () {
(0, _emberMetal.set)(_this9.context, 'foo', 'bork');
_this9.rerender();
});
this.assertText('BORK');
};
_class.prototype['@test sexpr in helper form does not update on parent re-render'] = function () {
var _this10 = this;
this.registerHelper('capitalize', function (params) {
return params[0].toUpperCase();
});
this.registerHelper('doublize', function (params) {
return params[0] + ' ' + params[0];
});
this.render('{{capitalize (unbound (doublize foo))}}', {
foo: 'bork'
});
this.assertText('BORK BORK');
this.runTask(function () {
return _this10.rerender();
});
this.assertText('BORK BORK');
this.runTask(function () {
(0, _emberMetal.set)(_this10.context, 'foo', 'oof');
_this10.rerender();
});
this.assertText('BORK BORK');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'foo', 'blip');
});
this.assertText('BORK BORK');
this.runTask(function () {
(0, _emberMetal.set)(_this10.context, 'foo', 'bork');
_this10.rerender();
});
this.assertText('BORK BORK');
};
_class.prototype['@test should be able to render an unbound helper invocation'] = function () {
var _this11 = this;
this.registerHelper('repeat', function (_ref, _ref2) {
var value = _ref[0];
var count = _ref2.count;
var a = [];
while (a.length < count) {
a.push(value);
}
return a.join('');
});
this.render('{{unbound (repeat foo count=bar)}} {{repeat foo count=bar}} {{unbound (repeat foo count=2)}} {{repeat foo count=4}}', {
foo: 'X',
bar: 5
});
this.assertText('XXXXX XXXXX XX XXXX');
this.runTask(function () {
return _this11.rerender();
});
this.assertText('XXXXX XXXXX XX XXXX');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'bar', 1);
});
this.assertText('XXXXX X XX XXXX');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'bar', 5);
});
this.assertText('XXXXX XXXXX XX XXXX');
};
_class.prototype['@test should be able to render an bound helper invocation mixed with static values'] = function () {
var _this12 = this;
this.registerHelper('surround', function (_ref3) {
var prefix = _ref3[0],
value = _ref3[1],
suffix = _ref3[2];
return prefix + '-' + value + '-' + suffix;
});
this.render((0, _abstractTestCase.strip)(_templateObject2), {
model: {
prefix: 'before',
value: 'core',
suffix: 'after'
}
});
this.assertText('before-core-bar before-core-bar bar-core-after bar-core-after');
this.runTask(function () {
return _this12.rerender();
});
this.assertText('before-core-bar before-core-bar bar-core-after bar-core-after');
this.runTask(function () {
(0, _emberMetal.setProperties)(_this12.context.model, {
prefix: 'beforeChanged',
value: 'coreChanged',
suffix: 'afterChanged'
});
});
this.assertText('before-core-bar beforeChanged-coreChanged-bar bar-core-after bar-coreChanged-afterChanged');
this.runTask(function () {
(0, _emberMetal.set)(_this12.context, 'model', {
prefix: 'before',
value: 'core',
suffix: 'after'
});
});
this.assertText('before-core-bar before-core-bar bar-core-after bar-core-after');
};
_class.prototype['@test should be able to render unbound forms of multi-arg helpers'] = function () {
var _this13 = this;
this.registerHelper('fauxconcat', function (params) {
return params.join('');
});
this.render('{{fauxconcat model.foo model.bar model.bing}} {{unbound (fauxconcat model.foo model.bar model.bing)}}', {
model: {
foo: 'a',
bar: 'b',
bing: 'c'
}
});
this.assertText('abc abc');
this.runTask(function () {
return _this13.rerender();
});
this.assertText('abc abc');
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'model.bar', 'X');
});
this.assertText('aXc abc');
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'model', {
foo: 'a',
bar: 'b',
bing: 'c'
});
});
this.assertText('abc abc');
};
_class.prototype['@test should be able to render an unbound helper invocation for helpers with dependent keys'] = function () {
var _this14 = this;
this.registerHelper('capitalizeName', {
destroy: function () {
this.removeObserver('value.firstName');
this._super.apply(this, arguments);
},
compute: function (_ref4) {
var value = _ref4[0];
if (this.get('value')) {
this.removeObserver('value.firstName');
}
this.set('value', value);
this.addObserver('value.firstName', this, this.recompute);
return value ? (0, _emberMetal.get)(value, 'firstName').toUpperCase() : '';
}
});
this.registerHelper('concatNames', {
destroy: function () {
this.teardown();
this._super.apply(this, arguments);
},
teardown: function () {
this.removeObserver('value.firstName');
this.removeObserver('value.lastName');
},
compute: function (_ref5) {
var value = _ref5[0];
if (this.get('value')) {
this.teardown();
}
this.set('value', value);
this.addObserver('value.firstName', this, this.recompute);
this.addObserver('value.lastName', this, this.recompute);
return (value ? (0, _emberMetal.get)(value, 'firstName') : '') + (value ? (0, _emberMetal.get)(value, 'lastName') : '');
}
});
this.render('{{capitalizeName person}} {{unbound (capitalizeName person)}} {{concatNames person}} {{unbound (concatNames person)}}', {
person: {
firstName: 'shooby',
lastName: 'taylor'
}
});
this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor');
this.runTask(function () {
return _this14.rerender();
});
this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor');
this.runTask(function () {
return (0, _emberMetal.set)(_this14.context, 'person.firstName', 'sally');
});
this.assertText('SALLY SHOOBY sallytaylor shoobytaylor');
this.runTask(function () {
return (0, _emberMetal.set)(_this14.context, 'person', {
firstName: 'shooby',
lastName: 'taylor'
});
});
this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor');
};
_class.prototype['@test should be able to render an unbound helper invocation in #each helper'] = function () {
var _this15 = this;
this.registerHelper('capitalize', function (params) {
return params[0].toUpperCase();
});
this.render('{{#each people as |person|}}{{capitalize person.firstName}} {{unbound (capitalize person.firstName)}}{{/each}}', {
people: (0, _emberRuntime.A)([{
firstName: 'shooby',
lastName: 'taylor'
}, {
firstName: 'cindy',
lastName: 'taylor'
}])
});
this.assertText('SHOOBY SHOOBYCINDY CINDY');
this.runTask(function () {
return _this15.rerender();
});
this.assertText('SHOOBY SHOOBYCINDY CINDY');
this.runTask(function () {
return _this15.context.people.setEach('firstName', 'chad');
});
this.assertText('CHAD SHOOBYCHAD CINDY');
this.runTask(function () {
return (0, _emberMetal.set)(_this15.context, 'people', (0, _emberRuntime.A)([{
firstName: 'shooby',
lastName: 'taylor'
}, {
firstName: 'cindy',
lastName: 'taylor'
}]));
});
this.assertText('SHOOBY SHOOBYCINDY CINDY');
};
_class.prototype['@test should be able to render an unbound helper invocation with bound hash options'] = function () {
var _this16 = this;
this.registerHelper('capitalizeName', {
destroy: function () {
this.removeObserver('value.firstName');
this._super.apply(this, arguments);
},
compute: function (_ref6) {
var value = _ref6[0];
if (this.get('value')) {
this.removeObserver('value.firstName');
}
this.set('value', value);
this.addObserver('value.firstName', this, this.recompute);
return value ? (0, _emberMetal.get)(value, 'firstName').toUpperCase() : '';
}
});
this.registerHelper('concatNames', {
destroy: function () {
this.teardown();
this._super.apply(this, arguments);
},
teardown: function () {
this.removeObserver('value.firstName');
this.removeObserver('value.lastName');
},
compute: function (_ref7) {
var value = _ref7[0];
if (this.get('value')) {
this.teardown();
}
this.set('value', value);
this.addObserver('value.firstName', this, this.recompute);
this.addObserver('value.lastName', this, this.recompute);
return (value ? (0, _emberMetal.get)(value, 'firstName') : '') + (value ? (0, _emberMetal.get)(value, 'lastName') : '');
}
});
this.render('{{capitalizeName person}} {{unbound (capitalizeName person)}} {{concatNames person}} {{unbound (concatNames person)}}', {
person: {
firstName: 'shooby',
lastName: 'taylor'
}
});
this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor');
this.runTask(function () {
return _this16.rerender();
});
this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor');
this.runTask(function () {
return (0, _emberMetal.set)(_this16.context, 'person.firstName', 'sally');
});
this.assertText('SALLY SHOOBY sallytaylor shoobytaylor');
this.runTask(function () {
return (0, _emberMetal.set)(_this16.context, 'person', {
firstName: 'shooby',
lastName: 'taylor'
});
});
this.assertText('SHOOBY SHOOBY shoobytaylor shoobytaylor');
};
_class.prototype['@test should be able to render bound form of a helper inside unbound form of same helper'] = function () {
var _this17 = this;
this.render((0, _abstractTestCase.strip)(_templateObject3), {
model: {
foo: true,
notfoo: false,
bar: true
}
});
this.assertText('truetrue');
this.runTask(function () {
return _this17.rerender();
});
this.assertText('truetrue');
this.runTask(function () {
return (0, _emberMetal.set)(_this17.context, 'model.bar', false);
});
this.assertText('falsefalse');
this.runTask(function () {
return (0, _emberMetal.set)(_this17.context, 'model', {
foo: true,
notfoo: false,
bar: true
});
});
this.assertText('truetrue');
};
_class.prototype['@test yielding unbound does not update'] = function () {
var _this18 = this;
var fooBarInstance = void 0;
var FooBarComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
fooBarInstance = this;
},
model: { foo: 'bork' }
});
this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: '{{yield (unbound model.foo)}}'
});
this.render('{{#foo-bar as |value|}}{{value}}{{/foo-bar}}');
this.assertText('bork');
this.runTask(function () {
return _this18.rerender();
});
this.assertText('bork');
this.runTask(function () {
return (0, _emberMetal.set)(fooBarInstance, 'model.foo', 'oof');
});
this.assertText('bork');
this.runTask(function () {
return (0, _emberMetal.set)(fooBarInstance, 'model', { foo: 'bork' });
});
this.assertText('bork');
};
_class.prototype['@test yielding unbound hash does not update'] = function () {
var _this19 = this;
var fooBarInstance = void 0;
var FooBarComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
fooBarInstance = this;
},
model: { foo: 'bork' }
});
this.registerComponent('foo-bar', {
ComponentClass: FooBarComponent,
template: '{{yield (unbound (hash foo=model.foo))}}'
});
this.render('{{#foo-bar as |value|}}{{value.foo}}{{/foo-bar}}');
this.assertText('bork');
this.runTask(function () {
return _this19.rerender();
});
this.assertText('bork');
this.runTask(function () {
return (0, _emberMetal.set)(fooBarInstance, 'model.foo', 'oof');
});
this.assertText('bork');
this.runTask(function () {
return (0, _emberMetal.set)(fooBarInstance, 'model', { foo: 'bork' });
});
this.assertText('bork');
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/helpers/yield-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal', 'ember-glimmer/tests/utils/helpers'], function (_emberBabel, _testCase, _emberMetal, _helpers) {
'use strict';
(0, _testCase.moduleFor)('Helpers test: {{yield}} helper', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test can yield to block'] = function () {
var _this2 = this;
this.registerComponent('yield-comp', { template: '[In layout:] {{yield}}' });
this.render('{{#yield-comp}}[In Block:] {{object.title}}{{/yield-comp}}', { object: { title: 'Seattle' } });
this.assertText('[In layout:] [In Block:] Seattle');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'object.title', 'Vancouver');
});
this.assertText('[In layout:] [In Block:] Vancouver');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'object', { title: 'Seattle' });
});
this.assertText('[In layout:] [In Block:] Seattle');
};
_class.prototype['@test templates should yield to block inside a nested component'] = function () {
var _this3 = this;
this.registerComponent('outer-comp', { template: '[In layout:] {{yield}}
' });
this.registerComponent('inner-comp', { template: '{{#outer-comp}}[In Block:] {{object.title}}{{/outer-comp}}' });
this.render('{{inner-comp object=object}}', { object: { title: 'Seattle' } });
this.assertText('[In layout:] [In Block:] Seattle');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'object.title', 'Vancouver');
});
this.assertText('[In layout:] [In Block:] Vancouver');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'object', { title: 'Seattle' });
});
this.assertText('[In layout:] [In Block:] Seattle');
};
_class.prototype['@test templates should yield to block, when the yield is embedded in a each helper'] = function () {
var _this4 = this;
var list = [1, 2, 3];
this.registerComponent('outer-comp', { template: '{{#each list as |item|}}{{yield}}{{/each}}' });
this.render('{{#outer-comp list=list}}Hello{{/outer-comp}}', { list: list });
this.assertText('HelloHelloHello');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'list', [4, 5]);
});
this.assertText('HelloHello');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'list', list);
});
this.assertText('HelloHelloHello');
};
_class.prototype['@test templates should yield to block, when the yield is embedded in a if helper'] = function () {
var _this5 = this;
this.registerComponent('outer-comp', { template: '{{#if boolean}}{{yield}}{{/if}}' });
this.render('{{#outer-comp boolean=boolean}}Hello{{/outer-comp}}', { boolean: true });
this.assertText('Hello');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'boolean', false);
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'boolean', true);
});
this.assertText('Hello');
};
_class.prototype['@test simple curlies inside of a yielded clock should work when the yield is nested inside of another view'] = function () {
var _this6 = this;
this.registerComponent('kiwi-comp', { template: '{{#if falsy}}{{else}}{{yield}}{{/if}}' });
this.render('{{#kiwi-comp}}{{text}}{{/kiwi-comp}}', { text: 'ohai' });
this.assertText('ohai');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'text', 'portland');
});
this.assertText('portland');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'text', 'ohai');
});
this.assertText('ohai');
};
_class.prototype['@test nested simple curlies inside of a yielded block should work when the yield is nested inside of another view'] = function () {
var _this7 = this;
this.registerComponent('parent-comp', { template: '{{#if falsy}}{{else}}{{yield}}{{/if}}' });
this.registerComponent('child-comp', { template: '{{#if falsy}}{{else}}{{text}}{{/if}}' });
this.render('{{#parent-comp}}{{child-comp text=text}}{{/parent-comp}}', { text: 'ohai' });
this.assertText('ohai');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'text', 'portland');
});
this.assertText('portland');
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'text', 'ohai');
});
this.assertText('ohai');
};
_class.prototype['@test yielding to a non-existent block is not an error'] = function () {
var _this8 = this;
this.registerComponent('yielding-comp', { template: 'Hello:{{yield}}' });
this.registerComponent('outer-comp', { template: '{{yielding-comp}} {{title}}' });
this.render('{{outer-comp title=title}}', { title: 'Mr. Selden' });
this.assertText('Hello: Mr. Selden');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'title', 'Mr. Chag');
});
this.assertText('Hello: Mr. Chag');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'title', 'Mr. Selden');
});
this.assertText('Hello: Mr. Selden');
};
_class.prototype['@test yield uses the original context'] = function () {
var _this9 = this;
var KiwiCompComponent = _helpers.Component.extend({ boundText: 'Inner' });
this.registerComponent('kiwi-comp', { ComponentClass: KiwiCompComponent, template: '{{boundText}}
{{yield}}
' });
this.render('{{#kiwi-comp}}{{boundText}}{{/kiwi-comp}}', { boundText: 'Original' });
this.assertText('InnerOriginal');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'boundText', 'Otherworld');
});
this.assertText('InnerOtherworld');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'boundText', 'Original');
});
this.assertText('InnerOriginal');
};
_class.prototype['@test outer block param doesn\'t mask inner component property'] = function () {
var _this10 = this;
var KiwiCompComponent = _helpers.Component.extend({ boundText: 'Inner' });
this.registerComponent('kiwi-comp', { ComponentClass: KiwiCompComponent, template: '{{boundText}}
{{yield}}
' });
this.render('{{#with boundText as |item|}}{{#kiwi-comp}}{{item}}{{/kiwi-comp}}{{/with}}', { boundText: 'Outer' });
this.assertText('InnerOuter');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'boundText', 'Otherworld');
});
this.assertText('InnerOtherworld');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'boundText', 'Outer');
});
this.assertText('InnerOuter');
};
_class.prototype['@test inner block param doesn\'t mask yield property'] = function () {
var _this11 = this;
var KiwiCompComponent = _helpers.Component.extend({ boundText: 'Inner' });
this.registerComponent('kiwi-comp', { ComponentClass: KiwiCompComponent, template: '{{#with boundText as |item|}}{{item}}
{{yield}}
{{/with}}' });
this.render('{{#kiwi-comp}}{{item}}{{/kiwi-comp}}', { item: 'Outer' });
this.assertText('InnerOuter');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'item', 'Otherworld');
});
this.assertText('InnerOtherworld');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'item', 'Outer');
});
this.assertText('InnerOuter');
};
_class.prototype['@test can bind a block param to a component and use it in yield'] = function () {
var _this12 = this;
this.registerComponent('kiwi-comp', { template: '{{content}}
{{yield}}
' });
this.render('{{#with boundText as |item|}}{{#kiwi-comp content=item}}{{item}}{{/kiwi-comp}}{{/with}}', { boundText: 'Outer' });
this.assertText('OuterOuter');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this12.context, 'boundText', 'Update');
});
this.assertText('UpdateUpdate');
this.runTask(function () {
return (0, _emberMetal.set)(_this12.context, 'boundText', 'Outer');
});
this.assertText('OuterOuter');
};
_class.prototype['@test yield should not introduce a view'] = function () {
var ParentCompComponent = _helpers.Component.extend({ isParentComponent: true });
var ChildCompComponent = _helpers.Component.extend({
didReceiveAttrs: function () {
this._super();
var parentView = this.get('parentView');
ok(parentView.get('isParentComponent'));
}
});
this.registerComponent('parent-comp', { ComponentClass: ParentCompComponent, template: '{{yield}}' });
this.registerComponent('child-comp', { ComponentClass: ChildCompComponent });
this.render('{{#parent-comp}}{{child-comp}}{{/parent-comp}}');
};
_class.prototype['@test yield with nested components (#3220)'] = function () {
var _this13 = this;
this.registerComponent('inner-component', { template: '{{yield}}' });
this.registerComponent('outer-component', { template: '{{#inner-component}}{{yield}} {{/inner-component}}' });
this.render('{{#outer-component}}Hello {{boundText}}{{/outer-component}}', { boundText: 'world' });
this.assertText('Hello world');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'boundText', 'update');
});
this.assertText('Hello update');
this.runTask(function () {
return (0, _emberMetal.set)(_this13.context, 'boundText', 'world');
});
this.assertText('Hello world');
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/input-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal'], function (_emberBabel, _testCase, _emberMetal) {
'use strict';
(0, _testCase.moduleFor)('Input element tests', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype.runAttributeTest = function (attributeName, values) {
var _this2 = this;
this.render(' ', { value: values[0] });
this.assertAttributeHasValue(attributeName, values[0], attributeName + ' is set on initial render');
this.runTask(function () {
return _this2.rerender();
});
this.assertAttributeHasValue(attributeName, values[0], attributeName + ' is set on noop rerender');
this.setComponentValue(values[1]);
this.assertAttributeHasValue(attributeName, values[1], attributeName + ' is set on rerender');
this.setComponentValue(values[0]);
this.assertAttributeHasValue(attributeName, values[0], attributeName + ' can be set back to the initial value');
};
_class.prototype.runPropertyTest = function (propertyName, values) {
var _this3 = this;
this.render(' ', { value: values[0] });
this.assertPropertyHasValue(propertyName, values[0], propertyName + ' is set on initial render');
this.runTask(function () {
return _this3.rerender();
});
this.assertPropertyHasValue(propertyName, values[0], propertyName + ' is set on noop rerender');
this.setComponentValue(values[1]);
this.assertPropertyHasValue(propertyName, values[1], propertyName + ' is set on rerender');
this.setComponentValue(values[0]);
this.assertPropertyHasValue(propertyName, values[0], propertyName + ' can be set back to the initial value');
};
_class.prototype.runFalsyValueProperty = function (values) {
var _this4 = this;
var value = 'value';
this.render(' ', { value: values[0] });
this.assertPropertyHasValue(value, '', value + ' is set on initial render');
this.runTask(function () {
return _this4.rerender();
});
this.assertPropertyHasValue(value, '', value + ' is set on noop rerender');
this.setComponentValue(values[1]);
this.assertPropertyHasValue(value, values[1], value + ' is set on rerender');
this.setComponentValue(values[0]);
this.assertPropertyHasValue(value, '', value + ' can be set back to the initial value');
};
_class.prototype['@test input disabled attribute'] = function () {
var _this5 = this;
this.render(' ', { model: { value: false } });
this.assert.equal(this.$inputElement().prop('disabled'), false);
this.runTask(function () {
return _this5.rerender();
});
this.assert.equal(this.$inputElement().prop('disabled'), false);
this.runTask(function () {
return _this5.context.set('model.value', true);
});
this.assert.equal(this.$inputElement().prop('disabled'), true);
this.assertHTML(' '); // Note the DOM output is
this.runTask(function () {
return _this5.context.set('model.value', 'wat');
});
this.assert.equal(this.$inputElement().prop('disabled'), true);
this.assertHTML(' '); // Note the DOM output is
this.runTask(function () {
return _this5.context.set('model', { value: false });
});
this.assert.equal(this.$inputElement().prop('disabled'), false);
this.assertHTML(' ');
};
_class.prototype['@test input value attribute'] = function () {
this.runPropertyTest('value', ['foo', 'bar']);
};
_class.prototype['@test input placeholder attribute'] = function () {
this.runAttributeTest('placeholder', ['foo', 'bar']);
};
_class.prototype['@test input name attribute'] = function () {
this.runAttributeTest('name', ['nam', 'name']);
};
_class.prototype['@test input maxlength attribute'] = function () {
this.runAttributeTest('maxlength', [2, 3]);
};
_class.prototype['@test input size attribute'] = function () {
this.runAttributeTest('size', [2, 3]);
};
_class.prototype['@test input tabindex attribute'] = function () {
this.runAttributeTest('tabindex', [2, 3]);
};
_class.prototype['@test null input value'] = function () {
this.runFalsyValueProperty([null, 'hello']);
};
_class.prototype['@test undefined input value'] = function () {
this.runFalsyValueProperty([undefined, 'hello']);
};
_class.prototype['@test undefined `toString` method as input value'] = function () {
this.runFalsyValueProperty([Object.create(null), 'hello']);
};
_class.prototype['@test cursor position is not lost when updating content'] = function () {
this.render(' ', { value: 'hola' });
this.setDOMValue('hello');
this.setSelectionRange(1, 3);
this.setComponentValue('hello');
this.assertSelectionRange(1, 3);
// Note: We should eventually get around to testing reseting, however
// browsers handle `selectionStart` and `selectionEnd` differently
// when are synthetically testing movement of the cursor.
};
_class.prototype['@test input can be updated multiple times'] = function () {
this.render(' ', { value: 'hola' });
this.assertValue('hola', 'Value is initialised');
this.setComponentValue('');
this.assertValue('', 'Value is set in the DOM');
this.setDOMValue('hola');
this.setComponentValue('hola');
this.assertValue('hola', 'Value is updated the first time');
this.setComponentValue('');
this.assertValue('', 'Value is updated the second time');
};
_class.prototype['@test DOM is SSOT if value is set'] = function () {
this.render(' ', { value: 'hola' });
this.assertValue('hola', 'Value is initialised');
this.setComponentValue('hello');
this.assertValue('hello', 'Value is initialised');
this.setDOMValue('hola');
this.assertValue('hola', 'DOM is used');
this.setComponentValue('bye');
this.assertValue('bye', 'Value is used');
// Simulates setting the input to the same value as it already is which won't cause a rerender
this.setDOMValue('hola');
this.assertValue('hola', 'DOM is used');
this.setComponentValue('hola');
this.assertValue('hola', 'Value is used');
};
_class.prototype.setDOMValue = function (value) {
this.inputElement().value = value;
};
_class.prototype.setComponentValue = function (value) {
var _this6 = this;
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'value', value);
});
};
_class.prototype.setSelectionRange = function (start, end) {
this.inputElement().selectionStart = start;
this.inputElement().selectionEnd = end;
};
_class.prototype.inputElement = function () {
return this.$inputElement()[0];
};
_class.prototype.$inputElement = function () {
return this.$('input');
};
_class.prototype.assertValue = function (value, message) {
this.assertPropertyHasValue('value', value, message);
};
_class.prototype.assertAttributeHasValue = function (attribute, value, message) {
this.assert.equal(this.$inputElement().attr(attribute), value, attribute + ' ' + message);
};
_class.prototype.assertPropertyHasValue = function (property, value, message) {
this.assert.equal(this.$inputElement().prop(property), value, property + ' ' + message);
};
_class.prototype.assertSelectionRange = function (start, end) {
this.assert.equal(this.inputElement().selectionStart, start);
this.assert.equal(this.inputElement().selectionEnd, end);
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/mount-test', ['ember-babel', 'ember-utils', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers', 'ember-runtime', 'ember-metal', 'ember-application'], function (_emberBabel, _emberUtils, _testCase, _helpers, _emberRuntime, _emberMetal, _emberApplication) {
'use strict';
(0, _testCase.moduleFor)('{{mount}} assertions', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test it asserts that only a single param is passed'] = function () {
var _this2 = this;
expectAssertion(function () {
_this2.render('{{mount "chat" "foo"}}');
}, /You can only pass a single argument to the {{mount}} helper, e.g. {{mount "chat-engine"}}./i);
};
_class.prototype['@test it asserts when an invalid engine name is provided'] = function () {
var _this3 = this;
expectAssertion(function () {
_this3.render('{{mount engineName}}', { engineName: {} });
}, /Invalid engine name '\[object Object\]' specified, engine name must be either a string, null or undefined./i);
};
_class.prototype['@test it asserts that the specified engine is registered'] = function () {
var _this4 = this;
expectAssertion(function () {
_this4.render('{{mount "chat"}}');
}, /You used `{{mount 'chat'}}`, but the engine 'chat' can not be found./i);
};
return _class;
}(_testCase.RenderingTest));
(0, _testCase.moduleFor)('{{mount}} test', function (_ApplicationTest) {
(0, _emberBabel.inherits)(_class2, _ApplicationTest);
function _class2() {
var _this5 = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTest.call(this));
var engineRegistrations = _this5.engineRegistrations = {};
_this5.add('engine:chat', _emberApplication.Engine.extend({
router: null,
init: function () {
var _this6 = this;
this._super.apply(this, arguments);
Object.keys(engineRegistrations).forEach(function (fullName) {
_this6.register(fullName, engineRegistrations[fullName]);
});
}
}));
_this5.addTemplate('index', '{{mount "chat"}}');
return _this5;
}
_class2.prototype['@test it boots an engine, instantiates its application controller, and renders its application template'] = function (assert) {
var _this7 = this;
this.engineRegistrations['template:application'] = (0, _helpers.compile)('Chat here, {{username}} ', { moduleName: 'application' });
var controller = void 0;
this.engineRegistrations['controller:application'] = _emberRuntime.Controller.extend({
username: 'dgeb',
init: function () {
this._super();
controller = this;
}
});
return this.visit('/').then(function () {
assert.ok(controller, 'engine\'s application controller has been instantiated');
var engineInstance = (0, _emberUtils.getOwner)(controller);
assert.strictEqual((0, _emberApplication.getEngineParent)(engineInstance), _this7.applicationInstance, 'engine instance has the application instance as its parent');
_this7.assertComponentElement(_this7.firstChild, { content: 'Chat here, dgeb ' });
_this7.runTask(function () {
return (0, _emberMetal.set)(controller, 'username', 'chancancode');
});
_this7.assertComponentElement(_this7.firstChild, { content: 'Chat here, chancancode ' });
_this7.runTask(function () {
return (0, _emberMetal.set)(controller, 'username', 'dgeb');
});
_this7.assertComponentElement(_this7.firstChild, { content: 'Chat here, dgeb ' });
});
};
_class2.prototype['@test it emits a useful backtracking re-render assertion message'] = function () {
var _this8 = this;
this.router.map(function () {
this.route('route-with-mount');
});
this.addTemplate('index', '');
this.addTemplate('route-with-mount', '{{mount "chat"}}');
this.engineRegistrations['template:application'] = (0, _helpers.compile)('hi {{person.name}} [{{component-with-backtracking-set person=person}}]', { moduleName: 'application' });
this.engineRegistrations['controller:application'] = _emberRuntime.Controller.extend({
person: { name: 'Alex' }
});
this.engineRegistrations['template:components/component-with-backtracking-set'] = (0, _helpers.compile)('[component {{person.name}}]', { moduleName: 'components/component-with-backtracking-set' });
this.engineRegistrations['component:component-with-backtracking-set'] = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
this.set('person.name', 'Ben');
}
});
var expectedBacktrackingMessage = /modified "person\.name" twice on \[object Object\] in a single render\. It was rendered in "template:route-with-mount" \(in "engine:chat"\) and modified in "component:component-with-backtracking-set" \(in "engine:chat"\)/;
return this.visit('/').then(function () {
expectAssertion(function () {
_this8.visit('/route-with-mount');
}, expectedBacktrackingMessage);
});
};
_class2.prototype['@test it renders with a bound engine name'] = function () {
var _this9 = this;
this.router.map(function () {
this.route('bound-engine-name');
});
var controller = void 0;
this.add('controller:bound-engine-name', _emberRuntime.Controller.extend({
engineName: null,
init: function () {
this._super();
controller = this;
}
}));
this.addTemplate('bound-engine-name', '{{mount engineName}}');
this.add('engine:foo', _emberApplication.Engine.extend({
router: null,
init: function () {
this._super.apply(this, arguments);
this.register('template:application', (0, _helpers.compile)('Foo Engine ', { moduleName: 'application' }));
}
}));
this.add('engine:bar', _emberApplication.Engine.extend({
router: null,
init: function () {
this._super.apply(this, arguments);
this.register('template:application', (0, _helpers.compile)('Bar Engine ', { moduleName: 'application' }));
}
}));
return this.visit('/bound-engine-name').then(function () {
_this9.assertComponentElement(_this9.firstChild, { content: '' });
_this9.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', 'foo');
});
_this9.assertComponentElement(_this9.firstChild, { content: 'Foo Engine ' });
_this9.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', undefined);
});
_this9.assertComponentElement(_this9.firstChild, { content: '' });
_this9.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', 'foo');
});
_this9.assertComponentElement(_this9.firstChild, { content: 'Foo Engine ' });
_this9.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', 'bar');
});
_this9.assertComponentElement(_this9.firstChild, { content: 'Bar Engine ' });
_this9.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', 'foo');
});
_this9.assertComponentElement(_this9.firstChild, { content: 'Foo Engine ' });
_this9.runTask(function () {
return (0, _emberMetal.set)(controller, 'engineName', null);
});
_this9.assertComponentElement(_this9.firstChild, { content: '' });
});
};
return _class2;
}(_testCase.ApplicationTest));
});
enifed('ember-glimmer/tests/integration/outlet-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'internal-test-helpers', 'ember-metal'], function (_emberBabel, _testCase, _internalTestHelpers, _emberMetal) {
'use strict';
(0, _testCase.moduleFor)('outlet view', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
var CoreOutlet = _this.owner.factoryFor('view:-outlet');
_this.component = CoreOutlet.create();
return _this;
}
_class.prototype['@test should not error when initial rendered template is undefined'] = function () {
var _this2 = this;
var outletState = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'application',
controller: undefined,
ViewClass: undefined,
template: undefined
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this2.component.setOutletState(outletState);
});
(0, _internalTestHelpers.runAppend)(this.component);
this.assertText('');
};
_class.prototype['@test should render the outlet when set after DOM insertion'] = function () {
var _this3 = this;
var outletState = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'application',
controller: undefined,
ViewClass: undefined,
template: undefined
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this3.component.setOutletState(outletState);
});
(0, _internalTestHelpers.runAppend)(this.component);
this.assertText('');
this.registerTemplate('application', 'HI{{outlet}}');
outletState = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'application',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:application')
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this3.component.setOutletState(outletState);
});
this.assertText('HI');
this.assertStableRerender();
this.registerTemplate('index', 'BYE
');
outletState.outlets.main = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'index',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:index')
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this3.component.setOutletState(outletState);
});
this.assertText('HIBYE');
};
_class.prototype['@test should render the outlet when set before DOM insertion'] = function () {
var _this4 = this;
this.registerTemplate('application', 'HI{{outlet}}');
var outletState = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'application',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:application')
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this4.component.setOutletState(outletState);
});
(0, _internalTestHelpers.runAppend)(this.component);
this.assertText('HI');
this.assertStableRerender();
this.registerTemplate('index', 'BYE
');
outletState.outlets.main = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'index',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:index')
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this4.component.setOutletState(outletState);
});
this.assertText('HIBYE');
};
_class.prototype['@test should support an optional name'] = function () {
var _this5 = this;
this.registerTemplate('application', 'HI {{outlet "special"}}');
var outletState = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'application',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:application')
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this5.component.setOutletState(outletState);
});
(0, _internalTestHelpers.runAppend)(this.component);
this.assertText('HI');
this.assertStableRerender();
this.registerTemplate('special', 'BYE
');
outletState.outlets.special = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'special',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:special')
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this5.component.setOutletState(outletState);
});
this.assertText('HIBYE');
};
_class.prototype['@test does not default outlet name when positional argument is present'] = function () {
var _this6 = this;
this.registerTemplate('application', 'HI {{outlet someUndefinedThing}}');
var outletState = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'application',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:application')
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this6.component.setOutletState(outletState);
});
(0, _internalTestHelpers.runAppend)(this.component);
this.assertText('HI');
this.assertStableRerender();
this.registerTemplate('special', 'BYE
');
outletState.outlets.main = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'special',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:special')
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this6.component.setOutletState(outletState);
});
this.assertText('HI');
};
_class.prototype['@test should support bound outlet name'] = function () {
var _this7 = this;
var controller = { outletName: 'foo' };
this.registerTemplate('application', 'HI {{outlet outletName}}');
var outletState = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'application',
controller: controller,
ViewClass: undefined,
template: this.owner.lookup('template:application')
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this7.component.setOutletState(outletState);
});
(0, _internalTestHelpers.runAppend)(this.component);
this.assertText('HI');
this.assertStableRerender();
this.registerTemplate('foo', 'FOO
');
outletState.outlets.foo = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'foo',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:foo')
},
outlets: Object.create(null)
};
this.registerTemplate('bar', 'BAR
');
outletState.outlets.bar = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'bar',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:bar')
},
outlets: Object.create(null)
};
this.runTask(function () {
return _this7.component.setOutletState(outletState);
});
this.assertText('HIFOO');
this.runTask(function () {
return (0, _emberMetal.set)(controller, 'outletName', 'bar');
});
this.assertText('HIBAR');
};
_class.prototype['@test outletState can pass through user code (liquid-fire initimate API) '] = function () {
var _this8 = this;
this.registerTemplate('outer', 'A{{#-with-dynamic-vars outletState=(identity (-get-dynamic-var "outletState"))}}B{{outlet}}D{{/-with-dynamic-vars}}E');
this.registerTemplate('inner', 'C');
// This looks like it doesn't do anything, but its presence
// guarantees that the outletState gets converted from a reference
// to a value and then back to a reference. That is what we're
// testing here.
this.registerHelper('identity', function (_ref) {
var a = _ref[0];
return a;
});
var outletState = {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'outer',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:outer')
},
outlets: {
main: {
render: {
owner: this.owner,
into: undefined,
outlet: 'main',
name: 'inner',
controller: {},
ViewClass: undefined,
template: this.owner.lookup('template:inner')
},
outlets: Object.create(null)
}
}
};
this.runTask(function () {
return _this8.component.setOutletState(outletState);
});
(0, _internalTestHelpers.runAppend)(this.component);
this.assertText('ABCDE');
this.assertStableRerender();
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/refinements-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-metal'], function (_emberBabel, _testCase, _abstractTestCase, _emberMetal) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with var as |foo|}}\n {{foo}}\n {{/with}}\n\n ---\n\n {{#with var as |render|}}\n {{render}}\n {{/with}}\n\n ---\n\n {{#with var as |outlet|}}\n {{outlet}}\n {{/with}}\n\n ---\n\n {{#with var as |mount|}}\n {{mount}}\n {{/with}}\n\n ---\n\n {{#with var as |component|}}\n {{component}}\n {{/with}}\n\n ---\n\n {{#with var as |input|}}\n {{input}}\n {{/with}}\n\n ---\n\n {{#with var as |-with-dynamic-vars|}}\n {{-with-dynamic-vars}}\n {{/with}}\n\n ---\n\n {{#with var as |-in-element|}}\n {{-in-element}}\n {{/with}}'], ['\n {{#with var as |foo|}}\n {{foo}}\n {{/with}}\n\n ---\n\n {{#with var as |render|}}\n {{render}}\n {{/with}}\n\n ---\n\n {{#with var as |outlet|}}\n {{outlet}}\n {{/with}}\n\n ---\n\n {{#with var as |mount|}}\n {{mount}}\n {{/with}}\n\n ---\n\n {{#with var as |component|}}\n {{component}}\n {{/with}}\n\n ---\n\n {{#with var as |input|}}\n {{input}}\n {{/with}}\n\n ---\n\n {{#with var as |-with-dynamic-vars|}}\n {{-with-dynamic-vars}}\n {{/with}}\n\n ---\n\n {{#with var as |-in-element|}}\n {{-in-element}}\n {{/with}}']);
(0, _testCase.moduleFor)('syntax refinements', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test block params should not be refined'] = function () {
var _this2 = this;
this.registerHelper('foo', function () {
return 'bar helper';
});
this.render((0, _abstractTestCase.strip)(_templateObject), { var: 'var' });
this.assertText('var---var---var---var---var---var---var---var');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'var', 'RARRR!!!');
});
this.assertText('RARRR!!!---RARRR!!!---RARRR!!!---RARRR!!!---RARRR!!!---RARRR!!!---RARRR!!!---RARRR!!!');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'var', 'var');
});
this.assertText('var---var---var---var---var---var---var---var');
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/svg-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-metal', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _testCase, _emberMetal, _abstractTestCase) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n \n
\n '], ['\n \n \n
\n ']),
_templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n \n
\n '], ['\n \n \n
\n ']),
_templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n \n
\n '], ['\n \n \n
\n ']),
_templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n \n
\n '], ['\n \n \n
\n ']),
_templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n \n
\n '], ['\n \n \n
\n ']);
(0, _testCase.moduleFor)('SVG element tests', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test unquoted viewBox property is output'] = function (assert) {
var _this2 = this;
var viewBoxString = '0 0 100 100';
this.render('
', {
model: {
viewBoxString: viewBoxString
}
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString));
this.runTask(function () {
return _this2.rerender();
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString));
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'model.viewBoxString', null);
});
assert.equal(this.firstChild.getAttribute('svg'), null);
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'model', { viewBoxString: viewBoxString });
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString));
};
_class.prototype['@test quoted viewBox property is output'] = function (assert) {
var _this3 = this;
var viewBoxString = '0 0 100 100';
this.render('
', {
model: {
viewBoxString: viewBoxString
}
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString));
this.runTask(function () {
return _this3.rerender();
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString));
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'model.viewBoxString', null);
});
assert.equal(this.firstChild.getAttribute('svg'), null);
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'model', { viewBoxString: viewBoxString });
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject, viewBoxString));
};
_class.prototype['@test quoted viewBox property is concat'] = function () {
var _this4 = this;
var viewBoxString = '100 100';
this.render('
', {
model: {
viewBoxString: viewBoxString
}
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject2, viewBoxString));
this.runTask(function () {
return _this4.rerender();
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject2, viewBoxString));
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'model.viewBoxString', '200 200');
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject3));
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'model', { viewBoxString: viewBoxString });
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject2, viewBoxString));
};
_class.prototype['@test class is output'] = function () {
var _this5 = this;
this.render('
', {
model: {
color: 'blue'
}
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject4));
this.runTask(function () {
return _this5.rerender();
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject4));
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'model.color', 'yellow');
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject5));
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'model', { color: 'blue' });
});
this.assertInnerHTML((0, _abstractTestCase.strip)(_templateObject4));
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/syntax/each-in-test', ['ember-babel', 'ember-metal', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case', 'ember-runtime', 'ember-glimmer/tests/utils/shared-conditional-tests'], function (_emberBabel, _emberMetal, _abstractTestCase, _testCase, _emberRuntime, _sharedConditionalTests) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n {{#each-in categories as |category count|}}\n {{category}}: {{count}} \n {{/each-in}}\n \n '], ['\n \n {{#each-in categories as |category count|}}\n {{category}}: {{count}} \n {{/each-in}}\n \n ']),
_templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n Smartphones: 8203 \n JavaScript Frameworks: Infinity \n \n '], ['\n \n Smartphones: 8203 \n JavaScript Frameworks: Infinity \n \n ']),
_templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n Smartphones: 100 \n JavaScript Frameworks: Infinity \n Tweets: 443115 \n \n '], ['\n \n Smartphones: 100 \n JavaScript Frameworks: Infinity \n Tweets: 443115 \n \n ']),
_templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n {{#each-in categories as |category data|}}\n {{category}}: {{data.reports.unitsSold}} \n {{/each-in}}\n \n '], ['\n \n {{#each-in categories as |category data|}}\n {{category}}: {{data.reports.unitsSold}} \n {{/each-in}}\n \n ']),
_templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n {{#each-in categories key=\'@identity\' as |category count|}}\n {{category}}: {{count}} \n {{/each-in}}\n \n '], ['\n \n {{#each-in categories key=\'@identity\' as |category count|}}\n {{category}}: {{count}} \n {{/each-in}}\n \n ']),
_templateObject6 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n Smartphones: 8203 \n Tablets: 8203 \n JavaScript Frameworks: Infinity \n Bugs: Infinity \n \n '], ['\n \n Smartphones: 8203 \n Tablets: 8203 \n JavaScript Frameworks: Infinity \n Bugs: Infinity \n \n ']),
_templateObject7 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n Smartphones: 100 \n Tablets: 8203 \n JavaScript Frameworks: Infinity \n Bugs: Infinity \n Tweets: 443115 \n \n '], ['\n \n Smartphones: 100 \n Tablets: 8203 \n JavaScript Frameworks: Infinity \n Bugs: Infinity \n Tweets: 443115 \n \n ']),
_templateObject8 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n {{#each-in (get collection type) as |category count|}}\n {{category}}: {{count}} \n {{/each-in}}\n \n '], ['\n \n {{#each-in (get collection type) as |category count|}}\n {{category}}: {{count}} \n {{/each-in}}\n \n ']),
_templateObject9 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n Emberinios: 533462 \n Tweets: 7323 \n \n '], ['\n \n Emberinios: 533462 \n Tweets: 7323 \n \n ']),
_templateObject10 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n Televisions: 183 \n Alarm Clocks: 999 \n \n '], ['\n \n Televisions: 183 \n Alarm Clocks: 999 \n \n ']),
_templateObject11 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n Televisions: 183 \n Alarm Clocks: 999 \n Tweets: 443115 \n \n '], ['\n \n Televisions: 183 \n Alarm Clocks: 999 \n Tweets: 443115 \n \n ']),
_templateObject12 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n '], ['\n \n ']),
_templateObject13 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each-in foo.bar.baz as |thing|}}\n {{thing}}\n {{/each-in}}'], ['\n {{#each-in foo.bar.baz as |thing|}}\n {{thing}}\n {{/each-in}}']),
_templateObject14 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each-in arr as |key value|}}\n [{{key}}:{{value}}]\n {{/each-in}}'], ['\n {{#each-in arr as |key value|}}\n [{{key}}:{{value}}]\n {{/each-in}}']),
_templateObject15 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n \n Smartphones: 100 \n Tablets: 20 \n \n '], ['\n \n Smartphones: 100 \n Tablets: 20 \n \n ']);
var EachInTest = function (_TogglingSyntaxCondit) {
(0, _emberBabel.inherits)(EachInTest, _TogglingSyntaxCondit);
function EachInTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingSyntaxCondit.apply(this, arguments));
}
EachInTest.prototype.templateFor = function (_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return '{{#each-in ' + cond + ' as |key|}}' + truthy + '{{else}}' + falsy + '{{/each-in}}';
};
return EachInTest;
}(_sharedConditionalTests.TogglingSyntaxConditionalsTest);
function NonEmptyFunction() {}
NonEmptyFunction.foo = 'bar';
var NonEmptyConstructor = function () {};
NonEmptyConstructor.foo = 'bar';
var BasicEachInTest = function (_EachInTest) {
(0, _emberBabel.inherits)(BasicEachInTest, _EachInTest);
function BasicEachInTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _EachInTest.apply(this, arguments));
}
return BasicEachInTest;
}(EachInTest);
(0, _abstractTestCase.applyMixins)(BasicEachInTest, new _sharedConditionalTests.TruthyGenerator([{ foo: 1 }, _emberRuntime.Object.create({ 'Not Empty': 1 }), [1], NonEmptyFunction, NonEmptyConstructor]), new _sharedConditionalTests.FalsyGenerator([null, undefined, false, '', 0, [], function () {}, function () {}, {}, Object.create(null), Object.create({}), Object.create({ 'Not Empty': 1 }), _emberRuntime.Object.create()]));
(0, _testCase.moduleFor)('Syntax test: {{#each-in}}', function (_BasicEachInTest) {
(0, _emberBabel.inherits)(_class, _BasicEachInTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _BasicEachInTest.apply(this, arguments));
}
_class.prototype['@test it repeats the given block for each item in the hash'] = function () {
var _this4 = this;
this.render((0, _abstractTestCase.strip)(_templateObject), {
categories: {
'Smartphones': 8203,
'JavaScript Frameworks': Infinity
}
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject2));
this.assertStableRerender();
this.runTask(function () {
(0, _emberMetal.set)(_this4.context, 'categories.Smartphones', 100);
(0, _emberMetal.set)(_this4.context, 'categories.Tweets', 443115);
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject3));
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'categories', {
'Smartphones': 8203,
'JavaScript Frameworks': Infinity
});
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject2));
};
_class.prototype['@test it can render sub-paths of each item'] = function () {
var _this5 = this;
this.render((0, _abstractTestCase.strip)(_templateObject4), {
categories: {
'Smartphones': { reports: { unitsSold: 8203 } },
'JavaScript Frameworks': { reports: { unitsSold: Infinity } }
}
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject2));
this.assertStableRerender();
this.runTask(function () {
(0, _emberMetal.set)(_this5.context, 'categories.Smartphones.reports.unitsSold', 100);
(0, _emberMetal.set)(_this5.context, 'categories.Tweets', { reports: { unitsSold: 443115 } });
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject3));
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'categories', {
'Smartphones': { reports: { unitsSold: 8203 } },
'JavaScript Frameworks': { reports: { unitsSold: Infinity } }
});
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject2));
};
_class.prototype['@test it can render duplicate items'] = function () {
var _this6 = this;
this.render((0, _abstractTestCase.strip)(_templateObject5), {
categories: {
'Smartphones': 8203,
'Tablets': 8203,
'JavaScript Frameworks': Infinity,
'Bugs': Infinity
}
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject6));
this.assertStableRerender();
this.runTask(function () {
(0, _emberMetal.set)(_this6.context, 'categories.Smartphones', 100);
(0, _emberMetal.set)(_this6.context, 'categories.Tweets', 443115);
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject7));
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'categories', {
'Smartphones': 8203,
'Tablets': 8203,
'JavaScript Frameworks': Infinity,
'Bugs': Infinity
});
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject6));
};
_class.prototype['@test it repeats the given block when the hash is dynamic'] = function () {
var _this7 = this;
this.render((0, _abstractTestCase.strip)(_templateObject8), {
collection: {
categories: {
'Smartphones': 8203,
'JavaScript Frameworks': Infinity
},
otherCategories: {
'Emberinios': 533462,
'Tweets': 7323
}
},
type: 'categories'
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject2));
this.assertStableRerender();
this.runTask(function () {
(0, _emberMetal.set)(_this7.context, 'type', 'otherCategories');
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject9));
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'type', 'categories');
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject2));
};
_class.prototype['@test it only iterates over an object\'s own properties'] = function () {
var _this8 = this;
var protoCategories = {
'Smartphones': 8203,
'JavaScript Frameworks': Infinity
};
var categories = Object.create(protoCategories);
categories['Televisions'] = 183;
categories['Alarm Clocks'] = 999;
this.render((0, _abstractTestCase.strip)(_templateObject), { categories: categories });
this.assertHTML((0, _abstractTestCase.strip)(_templateObject10));
this.assertStableRerender();
this.runTask(function () {
(0, _emberMetal.set)(protoCategories, 'Robots', 666);
(0, _emberMetal.set)(categories, 'Tweets', 443115);
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject11));
categories = Object.create(protoCategories);
categories['Televisions'] = 183;
categories['Alarm Clocks'] = 999;
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'categories', categories);
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject10));
};
_class.prototype['@test it does not observe direct property mutations (not going through set) on the object'] = function () {
var _this9 = this;
this.render((0, _abstractTestCase.strip)(_templateObject), {
categories: {
'Smartphones': 8203,
'JavaScript Frameworks': Infinity
}
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject2));
this.assertStableRerender();
this.runTask(function () {
var categories = (0, _emberMetal.get)(_this9.context, 'categories');
delete categories.Smartphones;
});
this.assertInvariants();
this.runTask(function () {
var categories = (0, _emberMetal.get)(_this9.context, 'categories');
categories['Emberinios'] = 123456;
});
this.assertInvariants();
this.runTask(function () {
(0, _emberMetal.set)(_this9.context, 'categories', {
Emberinios: 123456
});
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject12));
this.runTask(function () {
(0, _emberMetal.set)(_this9.context, 'categories', {
'Smartphones': 8203,
'JavaScript Frameworks': Infinity
});
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject2));
};
_class.prototype['@test keying off of `undefined` does not render'] = function () {
var _this10 = this;
this.render((0, _abstractTestCase.strip)(_templateObject13), { foo: {} });
this.assertText('');
this.runTask(function () {
return _this10.rerender();
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'foo', { bar: { baz: { 'Here!': 1 } } });
});
this.assertText('Here!');
this.runTask(function () {
return (0, _emberMetal.set)(_this10.context, 'foo', {});
});
this.assertText('');
};
_class.prototype['@test it iterate over array with `in` instead of walking over elements'] = function () {
var _this11 = this;
var arr = [1, 2, 3];
arr.foo = 'bar';
this.render((0, _abstractTestCase.strip)(_templateObject14), { arr: arr });
this.assertText('[0:1][1:2][2:3][foo:bar]');
this.runTask(function () {
return _this11.rerender();
});
this.assertText('[0:1][1:2][2:3][foo:bar]');
this.runTask(function () {
(0, _emberMetal.set)(arr, 'zomg', 'lol');
});
this.assertText('[0:1][1:2][2:3][foo:bar][zomg:lol]');
arr = [1, 2, 3];
arr.foo = 'bar';
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'arr', arr);
});
this.assertText('[0:1][1:2][2:3][foo:bar]');
};
_class.prototype['@test it skips holes in sparse arrays'] = function () {
var arr = [];
arr[5] = 'foo';
arr[6] = 'bar';
this.render((0, _abstractTestCase.strip)(_templateObject14), { arr: arr });
this.assertText('[5:foo][6:bar]');
this.assertStableRerender();
};
(0, _emberBabel.createClass)(_class, [{
key: 'truthyValue',
get: function () {
return { 'Not Empty': 1 };
}
}, {
key: 'falsyValue',
get: function () {
return {};
}
}]);
return _class;
}(BasicEachInTest));
var EachInEdgeCasesTest = function (_EachInTest2) {
(0, _emberBabel.inherits)(EachInEdgeCasesTest, _EachInTest2);
function EachInEdgeCasesTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _EachInTest2.apply(this, arguments));
}
return EachInEdgeCasesTest;
}(EachInTest);
(0, _abstractTestCase.applyMixins)(EachInEdgeCasesTest, new _sharedConditionalTests.FalsyGenerator([true, 1, 'hello']));
(0, _testCase.moduleFor)('Syntax test: {{#each-in}} edge cases', function (_EachInEdgeCasesTest) {
(0, _emberBabel.inherits)(_class2, _EachInEdgeCasesTest);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _EachInEdgeCasesTest.apply(this, arguments));
}
(0, _emberBabel.createClass)(_class2, [{
key: 'truthyValue',
get: function () {
return { 'Not Empty': 1 };
}
}, {
key: 'falsyValue',
get: function () {
return {};
}
}]);
return _class2;
}(EachInEdgeCasesTest));
var EachInProxyTest = function (_EachInTest3) {
(0, _emberBabel.inherits)(EachInProxyTest, _EachInTest3);
function EachInProxyTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _EachInTest3.apply(this, arguments));
}
return EachInProxyTest;
}(EachInTest);
(0, _abstractTestCase.applyMixins)(EachInProxyTest, new _sharedConditionalTests.TruthyGenerator([_emberRuntime.ObjectProxy.create({ content: { 'Not empty': 1 } })]), new _sharedConditionalTests.FalsyGenerator([_emberRuntime.ObjectProxy.create(), _emberRuntime.ObjectProxy.create({ content: null }), _emberRuntime.ObjectProxy.create({ content: {} }), _emberRuntime.ObjectProxy.create({ content: Object.create(null) }), _emberRuntime.ObjectProxy.create({ content: Object.create({}) }), _emberRuntime.ObjectProxy.create({ content: Object.create({ 'Not Empty': 1 }) }), _emberRuntime.ObjectProxy.create({ content: _emberRuntime.Object.create() })]));
(0, _testCase.moduleFor)('Syntax test: {{#each-in}} with `ObjectProxy`', function (_EachInProxyTest) {
(0, _emberBabel.inherits)(_class3, _EachInProxyTest);
function _class3() {
return (0, _emberBabel.possibleConstructorReturn)(this, _EachInProxyTest.apply(this, arguments));
}
_class3.prototype['@test it iterates over the content, not the proxy'] = function () {
var _this16 = this;
var content = {
'Smartphones': 8203,
'JavaScript Frameworks': Infinity
};
var proxy = _emberRuntime.ObjectProxy.create({
content: content,
foo: 'bar'
});
this.render((0, _abstractTestCase.strip)(_templateObject), { categories: proxy });
this.assertHTML((0, _abstractTestCase.strip)(_templateObject2));
this.assertStableRerender();
this.runTask(function () {
(0, _emberMetal.set)(proxy, 'content.Smartphones', 100);
(0, _emberMetal.set)(proxy, 'content.Tweets', 443115);
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject3));
this.runTask(function () {
(0, _emberMetal.set)(proxy, 'content', {
'Smartphones': 100,
'Tablets': 20
});
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject15));
this.runTask(function () {
return (0, _emberMetal.set)(_this16.context, 'categories', _emberRuntime.ObjectProxy.create({
content: {
'Smartphones': 8203,
'JavaScript Frameworks': Infinity
}
}));
});
this.assertHTML((0, _abstractTestCase.strip)(_templateObject2));
};
(0, _emberBabel.createClass)(_class3, [{
key: 'truthyValue',
get: function () {
return _emberRuntime.ObjectProxy.create({ content: { 'Not Empty': 1 } });
}
}, {
key: 'falsyValue',
get: function () {
return _emberRuntime.ObjectProxy.create({ content: null });
}
}]);
return _class3;
}(EachInProxyTest));
});
enifed('ember-glimmer/tests/integration/syntax/each-test', ['ember-babel', 'ember-metal', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case', 'ember-runtime', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/shared-conditional-tests'], function (_emberBabel, _emberMetal, _abstractTestCase, _testCase, _emberRuntime, _helpers, _sharedConditionalTests) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each list as |item|}}\n Prev \n {{foo-bar item=item}}\n Next \n {{/each}}\n '], ['\n {{#each list as |item|}}\n Prev \n {{foo-bar item=item}}\n Next \n {{/each}}\n ']),
_templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each content as |value|}}\n {{value}}-\n {{#each options as |option|}}\n {{option.value}}:{{option.label}}\n {{/each}}\n {{/each}}\n '], ['\n {{#each content as |value|}}\n {{value}}-\n {{#each options as |option|}}\n {{option.value}}:{{option.label}}\n {{/each}}\n {{/each}}\n ']),
_templateObject3 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each foo.bar.baz as |thing|}}\n {{thing}}\n {{/each}}'], ['\n {{#each foo.bar.baz as |thing|}}\n {{thing}}\n {{/each}}']),
_templateObject4 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#each list as |value key|}}\n [{{key}}:{{value}}]\n {{/each}}'], ['\n {{#each list as |value key|}}\n [{{key}}:{{value}}]\n {{/each}}']),
_templateObject5 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{page.title}} \n\n \n {{#each model as |post|}}\n {{post.title}} \n {{/each}}\n \n '], ['\n {{page.title}} \n\n \n {{#each model as |post|}}\n {{post.title}} \n {{/each}}\n \n ']),
_templateObject6 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n Blog Posts \n\n \n Rails is omakase \n Ember is omakase \n \n '], ['\n Blog Posts \n\n \n Rails is omakase \n Ember is omakase \n \n ']),
_templateObject7 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n Essays \n\n \n Rails is omakase \n Ember is omakase \n \n '], ['\n Essays \n\n \n Rails is omakase \n Ember is omakase \n \n ']),
_templateObject8 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n Think Pieces\u2122 \n\n \n Rails is omakase \n Ember is omakase \n \n '], ['\n Think Pieces\u2122 \n\n \n Rails is omakase \n Ember is omakase \n \n ']);
var ArrayLike = function () {
function ArrayLike(content) {
this._array = content;
}
ArrayLike.prototype.forEach = function (callback) {
this._array.forEach(callback);
};
ArrayLike.prototype.objectAt = function (idx) {
return this._array[idx];
};
ArrayLike.prototype.clear = function () {
this._array.length = 0;
this.arrayContentDidChange();
};
ArrayLike.prototype.replace = function (idx, del, ins) {
var _array;
(_array = this._array).splice.apply(_array, [idx, del].concat(ins));
this.arrayContentDidChange();
};
ArrayLike.prototype.unshiftObject = function (obj) {
this._array.unshift(obj);
this.arrayContentDidChange();
};
ArrayLike.prototype.unshiftObjects = function (arr) {
var _array2;
(_array2 = this._array).unshift.apply(_array2, arr);
this.arrayContentDidChange();
};
ArrayLike.prototype.pushObject = function (obj) {
this._array.push(obj);
this.arrayContentDidChange();
};
ArrayLike.prototype.pushObjects = function (arr) {
var _array3;
(_array3 = this._array).push.apply(_array3, arr);
this.arrayContentDidChange();
};
ArrayLike.prototype.shiftObject = function () {
var obj = this._array.shift();
this.arrayContentDidChange();
return obj;
};
ArrayLike.prototype.popObject = function () {
var obj = this._array.pop();
this.arrayContentDidChange();
return obj;
};
ArrayLike.prototype.insertAt = function (idx, obj) {
this._array.splice(idx, 0, obj);
this.arrayContentDidChange();
};
ArrayLike.prototype.removeAt = function (idx) {
var len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
this._array.splice(idx, len);
this.arrayContentDidChange();
};
ArrayLike.prototype.arrayContentDidChange = function () {
(0, _emberMetal.propertyDidChange)(this, '[]');
(0, _emberMetal.propertyDidChange)(this, 'length');
};
(0, _emberBabel.createClass)(ArrayLike, [{
key: 'length',
get: function () {
return this._array.length;
}
}]);
return ArrayLike;
}();
var TogglingEachTest = function (_TogglingSyntaxCondit) {
(0, _emberBabel.inherits)(TogglingEachTest, _TogglingSyntaxCondit);
function TogglingEachTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingSyntaxCondit.apply(this, arguments));
}
(0, _emberBabel.createClass)(TogglingEachTest, [{
key: 'truthyValue',
get: function () {
return ['non-empty'];
}
}, {
key: 'falsyValue',
get: function () {
return [];
}
}]);
return TogglingEachTest;
}(_sharedConditionalTests.TogglingSyntaxConditionalsTest);
var BasicEachTest = function (_TogglingEachTest) {
(0, _emberBabel.inherits)(BasicEachTest, _TogglingEachTest);
function BasicEachTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingEachTest.apply(this, arguments));
}
return BasicEachTest;
}(TogglingEachTest);
(0, _abstractTestCase.applyMixins)(BasicEachTest, new _sharedConditionalTests.TruthyGenerator([['hello'], (0, _emberRuntime.A)(['hello']), new ArrayLike(['hello']), _emberRuntime.ArrayProxy.create({ content: ['hello'] }), _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(['hello']) })]), new _sharedConditionalTests.FalsyGenerator([null, undefined, false, '', 0, []]), _sharedConditionalTests.ArrayTestCases);
(0, _testCase.moduleFor)('Syntax test: toggling {{#each}}', function (_BasicEachTest) {
(0, _emberBabel.inherits)(_class, _BasicEachTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _BasicEachTest.apply(this, arguments));
}
_class.prototype.templateFor = function (_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return '{{#each ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/each}}';
};
return _class;
}(BasicEachTest));
(0, _testCase.moduleFor)('Syntax test: toggling {{#each as}}', function (_BasicEachTest2) {
(0, _emberBabel.inherits)(_class2, _BasicEachTest2);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _BasicEachTest2.apply(this, arguments));
}
_class2.prototype.templateFor = function (_ref2) {
var cond = _ref2.cond,
truthy = _ref2.truthy,
falsy = _ref2.falsy;
return '{{#each ' + cond + ' as |test|}}' + truthy + '{{else}}' + falsy + '{{/each}}';
};
return _class2;
}(BasicEachTest));
var EachEdgeCasesTest = function (_TogglingEachTest2) {
(0, _emberBabel.inherits)(EachEdgeCasesTest, _TogglingEachTest2);
function EachEdgeCasesTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingEachTest2.apply(this, arguments));
}
return EachEdgeCasesTest;
}(TogglingEachTest);
(0, _abstractTestCase.applyMixins)(EachEdgeCasesTest, new _sharedConditionalTests.FalsyGenerator([true, 'hello', 1, Object, function () {}, {}, { foo: 'bar' }, Object.create(null), Object.create({}), Object.create({ foo: 'bar' })]));
(0, _testCase.moduleFor)('Syntax test: toggling {{#each}}', function (_EachEdgeCasesTest) {
(0, _emberBabel.inherits)(_class3, _EachEdgeCasesTest);
function _class3() {
return (0, _emberBabel.possibleConstructorReturn)(this, _EachEdgeCasesTest.apply(this, arguments));
}
_class3.prototype.templateFor = function (_ref3) {
var cond = _ref3.cond,
truthy = _ref3.truthy,
falsy = _ref3.falsy;
return '{{#each ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/each}}';
};
return _class3;
}(EachEdgeCasesTest));
(0, _testCase.moduleFor)('Syntax test: toggling {{#each as}}', function (_EachEdgeCasesTest2) {
(0, _emberBabel.inherits)(_class4, _EachEdgeCasesTest2);
function _class4() {
return (0, _emberBabel.possibleConstructorReturn)(this, _EachEdgeCasesTest2.apply(this, arguments));
}
_class4.prototype.templateFor = function (_ref4) {
var cond = _ref4.cond,
truthy = _ref4.truthy,
falsy = _ref4.falsy;
return '{{#each ' + cond + ' as |test|}}' + truthy + '{{else}}' + falsy + '{{/each}}';
};
return _class4;
}(EachEdgeCasesTest));
var AbstractEachTest = function (_RenderingTest) {
(0, _emberBabel.inherits)(AbstractEachTest, _RenderingTest);
function AbstractEachTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
AbstractEachTest.prototype.makeList = function () {
// this.list = this.delegate = ...;
throw new Error('Not implemented: `makeList`');
};
AbstractEachTest.prototype.replaceList = function (list) {
var _this9 = this;
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'list', _this9.makeList(list));
});
};
AbstractEachTest.prototype.forEach = function (callback) {
return this.delegate.forEach(callback);
};
AbstractEachTest.prototype.objectAt = function (idx) {
return this.delegate.objectAt(idx);
};
AbstractEachTest.prototype.clear = function () {
return this.delegate.clear();
};
AbstractEachTest.prototype.replace = function (idx, del, ins) {
return this.delegate.replace(idx, del, ins);
};
AbstractEachTest.prototype.unshiftObject = function (obj) {
return this.delegate.unshiftObject(obj);
};
AbstractEachTest.prototype.unshiftObjects = function (arr) {
return this.delegate.unshiftObjects(arr);
};
AbstractEachTest.prototype.pushObject = function (obj) {
return this.delegate.pushObject(obj);
};
AbstractEachTest.prototype.pushObjects = function (arr) {
return this.delegate.pushObjects(arr);
};
AbstractEachTest.prototype.shiftObject = function () {
return this.delegate.shiftObject();
};
AbstractEachTest.prototype.popObject = function () {
return this.delegate.popObject();
};
AbstractEachTest.prototype.insertAt = function (idx, obj) {
return this.delegate.insertAt(idx, obj);
};
AbstractEachTest.prototype.removeAt = function (idx, len) {
return this.delegate.removeAt(idx, len);
};
AbstractEachTest.prototype.render = function (template) {
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (this.list === undefined) {
throw new Error('Must call `this.makeList()` before calling this.render()');
}
context.list = this.list;
return _RenderingTest.prototype.render.call(this, template, context);
};
return AbstractEachTest;
}(_testCase.RenderingTest);
var SingleEachTest = function (_AbstractEachTest) {
(0, _emberBabel.inherits)(SingleEachTest, _AbstractEachTest);
function SingleEachTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractEachTest.apply(this, arguments));
}
SingleEachTest.prototype['@test it repeats the given block for each item in the array'] = function () {
var _this11 = this;
this.makeList([{ text: 'hello' }]);
this.render('{{#each list as |item|}}{{item.text}}{{else}}Empty{{/each}}');
this.assertText('hello');
this.runTask(function () {
return _this11.rerender();
});
this.assertText('hello');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.objectAt(0), 'text', 'Hello');
});
this.assertText('Hello');
this.runTask(function () {
_this11.pushObject({ text: ' ' });
_this11.pushObject({ text: 'World' });
});
this.assertText('Hello World');
this.runTask(function () {
_this11.pushObject({ text: 'Earth' });
_this11.removeAt(1);
_this11.insertAt(1, { text: 'Globe' });
});
this.assertText('HelloGlobeWorldEarth');
this.runTask(function () {
_this11.pushObject({ text: 'Planet' });
_this11.removeAt(1);
_this11.insertAt(1, { text: ' ' });
_this11.pushObject({ text: ' ' });
_this11.pushObject({ text: 'Earth' });
_this11.removeAt(3);
});
this.assertText('Hello WorldPlanet Earth');
this.runTask(function () {
_this11.pushObject({ text: 'Globe' });
_this11.removeAt(1);
_this11.insertAt(1, { text: ' ' });
_this11.pushObject({ text: ' ' });
_this11.pushObject({ text: 'World' });
_this11.removeAt(2);
});
this.assertText('Hello Planet EarthGlobe World');
this.runTask(function () {
return _this11.replace(2, 4, { text: 'my' });
});
this.assertText('Hello my World');
this.runTask(function () {
return _this11.clear();
});
this.assertText('Empty');
this.replaceList([{ text: 'hello' }]);
this.assertText('hello');
};
SingleEachTest.prototype['@test it receives the index as the second parameter'] = function () {
var _this12 = this;
this.makeList([{ text: 'hello' }, { text: 'world' }]);
this.render('{{#each list as |item index|}}[{{index}}. {{item.text}}]{{/each}}');
this.assertText('[0. hello][1. world]');
this.assertStableRerender();
this.runTask(function () {
return _this12.insertAt(1, { text: 'my' });
});
this.assertText('[0. hello][1. my][2. world]');
this.replaceList([{ text: 'hello' }, { text: 'world' }]);
this.assertText('[0. hello][1. world]');
};
SingleEachTest.prototype['@test it accepts a string key'] = function () {
var _this13 = this;
this.makeList([{ text: 'hello' }, { text: 'world' }]);
this.render('{{#each list key=\'text\' as |item|}}{{item.text}}{{/each}}');
this.assertText('helloworld');
this.assertStableRerender();
this.runTask(function () {
return _this13.pushObject({ text: 'again' });
});
this.assertText('helloworldagain');
this.replaceList([{ text: 'hello' }, { text: 'world' }]);
this.assertText('helloworld');
};
SingleEachTest.prototype['@test it accepts a numeric key'] = function () {
var _this14 = this;
this.makeList([{ id: 1 }, { id: 2 }]);
this.render('{{#each list key=\'id\' as |item|}}{{item.id}}{{/each}}');
this.assertText('12');
this.assertStableRerender();
this.runTask(function () {
return _this14.pushObject({ id: 3 });
});
this.assertText('123');
this.replaceList([{ id: 1 }, { id: 2 }]);
this.assertText('12');
};
SingleEachTest.prototype['@test it can specify @index as the key'] = function () {
var _this15 = this;
this.makeList([{ id: 1 }, { id: 2 }]);
this.render('{{#each list key=\'@index\' as |item|}}{{item.id}}{{/each}}');
this.assertText('12');
this.assertStableRerender();
this.runTask(function () {
return _this15.pushObject({ id: 3 });
});
this.assertText('123');
this.replaceList([{ id: 1 }, { id: 2 }]);
this.assertText('12');
};
SingleEachTest.prototype['@test it can specify @identity as the key for arrays of primitives'] = function () {
var _this16 = this;
this.makeList([1, 2]);
this.render('{{#each list key=\'@identity\' as |item|}}{{item}}{{/each}}');
this.assertText('12');
this.assertStableRerender();
this.runTask(function () {
return _this16.pushObject(3);
});
this.assertText('123');
this.replaceList([1, 2]);
this.assertText('12');
};
SingleEachTest.prototype['@test it can specify @identity as the key for mixed arrays of objects and primitives'] = function () {
var _this17 = this;
this.makeList([1, { id: 2 }, 3]);
this.render('{{#each list key=\'@identity\' as |item|}}{{if item.id item.id item}}{{/each}}');
this.assertText('123');
this.assertStableRerender();
this.runTask(function () {
return _this17.insertAt(2, { id: 4 });
});
this.assertText('1243');
this.replaceList([1, { id: 2 }, 3]);
this.assertText('123');
};
SingleEachTest.prototype['@test it can render duplicate primitive items'] = function () {
var _this18 = this;
this.makeList(['a', 'a', 'a']);
this.render('{{#each list as |item|}}{{item}}{{/each}}');
this.assertText('aaa');
this.assertStableRerender();
this.runTask(function () {
return _this18.pushObject('a');
});
this.assertText('aaaa');
this.runTask(function () {
return _this18.pushObject('a');
});
this.assertText('aaaaa');
this.replaceList(['a', 'a', 'a']);
this.assertText('aaa');
};
SingleEachTest.prototype['@test updating and setting within #each'] = function () {
var _this19 = this;
this.makeList([{ value: 1 }, { value: 2 }, { value: 3 }]);
var FooBarComponent = _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
this.isEven = true;
this.tagName = 'li';
},
_isEven: function () {
this.set('isEven', this.get('item.value') % 2 === 0);
},
didUpdate: function () {
this._isEven();
}
});
this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: '{{#if isEven}}{{item.value}}{{/if}}' });
this.render((0, _abstractTestCase.strip)(_templateObject));
this.assertText('Prev1NextPrev2NextPrev3Next');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this19.context.list.objectAt(0), 'value', 3);
});
this.assertText('PrevNextPrev2NextPrev3Next');
this.replaceList([{ value: 1 }, { value: 2 }, { value: 3 }]);
this.assertText('Prev1NextPrev2NextPrev3Next');
};
SingleEachTest.prototype['@test it can render duplicate objects'] = function () {
var _this20 = this;
var duplicateItem = { text: 'foo' };
this.makeList([duplicateItem, duplicateItem, { text: 'bar' }, { text: 'baz' }]);
this.render('{{#each list as |item|}}{{item.text}}{{/each}}');
this.assertText('foofoobarbaz');
this.assertStableRerender();
this.runTask(function () {
return _this20.pushObject(duplicateItem);
});
this.assertText('foofoobarbazfoo');
this.runTask(function () {
return _this20.pushObject(duplicateItem);
});
this.assertText('foofoobarbazfoofoo');
this.replaceList([duplicateItem, duplicateItem, { text: 'bar' }, { text: 'baz' }]);
this.assertText('foofoobarbaz');
};
SingleEachTest.prototype['@test it maintains DOM stability when condition changes between objects with the same keys'] = function () {
var _this21 = this;
this.makeList([{ text: 'Hello' }, { text: ' ' }, { text: 'world' }]);
this.render('{{#each list key="text" as |item|}}{{item.text}}{{/each}}');
this.assertText('Hello world');
this.takeSnapshot();
this.runTask(function () {
_this21.popObject();
_this21.popObject();
_this21.pushObject({ text: ' ' });
_this21.pushObject({ text: 'world' });
});
this.assertText('Hello world');
this.assertInvariants();
this.replaceList([{ text: 'Hello' }, { text: ' ' }, { text: 'world' }]);
this.assertText('Hello world');
this.assertInvariants();
};
SingleEachTest.prototype['@test it maintains DOM stability for stable keys when list is updated'] = function () {
var _this22 = this;
this.makeList([{ text: 'Hello' }, { text: ' ' }, { text: 'world' }]);
this.render('{{#each list key="text" as |item|}}{{item.text}}{{/each}}');
this.assertText('Hello world');
this.assertStableRerender();
var oldSnapshot = this.takeSnapshot();
this.runTask(function () {
_this22.unshiftObject({ text: ', ' });
_this22.unshiftObject({ text: 'Hi' });
_this22.pushObject({ text: '!' });
_this22.pushObject({ text: 'earth' });
});
this.assertText('Hi, Hello world!earth');
this.assertPartialInvariants(2, 5);
this.replaceList([{ text: 'Hello' }, { text: ' ' }, { text: 'world' }]);
this.assertText('Hello world');
this.assertInvariants(oldSnapshot, this.takeSnapshot());
};
SingleEachTest.prototype['@test it renders all items with duplicate key values'] = function () {
var _this23 = this;
this.makeList([{ text: 'Hello' }, { text: 'Hello' }, { text: 'Hello' }]);
this.render('{{#each list key="text" as |item|}}{{item.text}}{{/each}}');
this.assertText('HelloHelloHello');
this.runTask(function () {
_this23.forEach(function (hash) {
return (0, _emberMetal.set)(hash, 'text', 'Goodbye');
});
});
this.assertText('GoodbyeGoodbyeGoodbye');
this.replaceList([{ text: 'Hello' }, { text: 'Hello' }, { text: 'Hello' }]);
this.assertText('HelloHelloHello');
};
SingleEachTest.prototype['@test context is not changed to the inner scope inside an {{#each as}} block'] = function () {
var _this24 = this;
this.makeList([{ name: 'Chad' }, { name: 'Zack' }, { name: 'Asa' }]);
this.render('{{name}}-{{#each list as |person|}}{{name}}{{/each}}-{{name}}', {
name: 'Joel'
});
this.assertText('Joel-JoelJoelJoel-Joel');
this.assertStableRerender();
this.runTask(function () {
return _this24.shiftObject();
});
this.assertText('Joel-JoelJoel-Joel');
this.runTask(function () {
return (0, _emberMetal.set)(_this24.context, 'name', 'Godfrey');
});
this.assertText('Godfrey-GodfreyGodfrey-Godfrey');
this.runTask(function () {
return (0, _emberMetal.set)(_this24.context, 'name', 'Joel');
});
this.replaceList([{ name: 'Chad' }, { name: 'Zack' }, { name: 'Asa' }]);
this.assertText('Joel-JoelJoelJoel-Joel');
};
SingleEachTest.prototype['@test can access the item and the original scope'] = function () {
var _this25 = this;
this.makeList([{ name: 'Tom Dale' }, { name: 'Yehuda Katz' }, { name: 'Godfrey Chan' }]);
this.render('{{#each list key="name" as |person|}}[{{title}}: {{person.name}}]{{/each}}', {
title: 'Señor Engineer'
});
this.assertText('[Señor Engineer: Tom Dale][Señor Engineer: Yehuda Katz][Señor Engineer: Godfrey Chan]');
this.runTask(function () {
return _this25.rerender();
});
this.assertText('[Señor Engineer: Tom Dale][Señor Engineer: Yehuda Katz][Señor Engineer: Godfrey Chan]');
this.runTask(function () {
(0, _emberMetal.set)(_this25.objectAt(1), 'name', 'Stefan Penner');
_this25.removeAt(0);
_this25.pushObject({ name: 'Tom Dale' });
_this25.insertAt(1, { name: 'Chad Hietala' });
(0, _emberMetal.set)(_this25.context, 'title', 'Principal Engineer');
});
this.assertText('[Principal Engineer: Stefan Penner][Principal Engineer: Chad Hietala][Principal Engineer: Godfrey Chan][Principal Engineer: Tom Dale]');
this.runTask(function () {
return (0, _emberMetal.set)(_this25.context, 'title', 'Señor Engineer');
});
this.replaceList([{ name: 'Tom Dale' }, { name: 'Yehuda Katz' }, { name: 'Godfrey Chan' }]);
this.assertText('[Señor Engineer: Tom Dale][Señor Engineer: Yehuda Katz][Señor Engineer: Godfrey Chan]');
};
SingleEachTest.prototype['@test the scoped variable is not available outside the {{#each}} block.'] = function () {
var _this26 = this;
this.makeList(['Yehuda']);
this.render('{{name}}-{{#each list as |name|}}{{name}}{{/each}}-{{name}}', {
name: 'Stef'
});
this.assertText('Stef-Yehuda-Stef');
this.runTask(function () {
return _this26.rerender();
});
this.assertText('Stef-Yehuda-Stef');
this.runTask(function () {
return _this26.pushObjects([' ', 'Katz']);
});
this.assertText('Stef-Yehuda Katz-Stef');
this.runTask(function () {
return (0, _emberMetal.set)(_this26.context, 'name', 'Tom');
});
this.assertText('Tom-Yehuda Katz-Tom');
this.runTask(function () {
return (0, _emberMetal.set)(_this26.context, 'name', 'Stef');
});
this.replaceList(['Yehuda']);
this.assertText('Stef-Yehuda-Stef');
};
SingleEachTest.prototype['@test inverse template is displayed with context'] = function () {
var _this27 = this;
this.makeList([]);
this.render('{{#each list as |thing|}}Has Thing{{else}}No Thing {{otherThing}}{{/each}}', {
otherThing: 'bar'
});
this.assertText('No Thing bar');
this.runTask(function () {
return _this27.rerender();
});
this.assertText('No Thing bar');
this.runTask(function () {
return (0, _emberMetal.set)(_this27.context, 'otherThing', 'biz');
});
this.assertText('No Thing biz');
this.runTask(function () {
return _this27.pushObject('non-empty');
});
this.assertText('Has Thing');
this.runTask(function () {
return (0, _emberMetal.set)(_this27.context, 'otherThing', 'baz');
});
this.assertText('Has Thing');
this.runTask(function () {
return (0, _emberMetal.set)(_this27.context, 'otherThing', 'bar');
});
this.replaceList([]);
this.assertText('No Thing bar');
};
SingleEachTest.prototype['@test content that are not initially present updates correctly GH#13983'] = function () {
var _this28 = this;
// The root cause of this bug is that Glimmer did not call `didInitializeChildren`
// on the inserted `TryOpcode`, causing that `TryOpcode` to have an uninitialized
// tag. Currently the only way to observe this the "JUMP-IF-NOT-MODIFIED", i.e. by
// wrapping it in an component.
this.registerComponent('x-wrapper', { template: '{{yield}}' });
this.makeList([]);
this.render('{{#x-wrapper}}{{#each list as |obj|}}[{{obj.text}}]{{/each}}{{/x-wrapper}}');
this.assertText('');
this.runTask(function () {
return _this28.rerender();
});
this.assertText('');
this.runTask(function () {
return _this28.pushObject({ text: 'foo' });
});
this.assertText('[foo]');
this.runTask(function () {
return (0, _emberMetal.set)(_this28.objectAt(0), 'text', 'FOO');
});
this.assertText('[FOO]');
this.runTask(function () {
return _this28.pushObject({ text: 'bar' });
});
this.assertText('[FOO][bar]');
this.runTask(function () {
return (0, _emberMetal.set)(_this28.objectAt(1), 'text', 'BAR');
});
this.assertText('[FOO][BAR]');
this.runTask(function () {
return (0, _emberMetal.set)(_this28.objectAt(1), 'text', 'baz');
});
this.assertText('[FOO][baz]');
this.runTask(function () {
return _this28.replace(1, 1, [{ text: 'BAZ' }]);
});
this.assertText('[FOO][BAZ]');
this.replaceList([]);
this.assertText('');
};
return SingleEachTest;
}(AbstractEachTest);
(0, _testCase.moduleFor)('Syntax test: {{#each}} with arrays', function (_SingleEachTest) {
(0, _emberBabel.inherits)(_class5, _SingleEachTest);
function _class5() {
return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest.apply(this, arguments));
}
_class5.prototype.makeList = function (list) {
return this.list = this.delegate = (0, _emberRuntime.A)(list);
};
return _class5;
}(SingleEachTest));
(0, _testCase.moduleFor)('Syntax test: {{#each}} with array-like objects', function (_SingleEachTest2) {
(0, _emberBabel.inherits)(_class6, _SingleEachTest2);
function _class6() {
return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest2.apply(this, arguments));
}
_class6.prototype.makeList = function (list) {
return this.list = this.delegate = new ArrayLike(list);
};
return _class6;
}(SingleEachTest));
(0, _testCase.moduleFor)('Syntax test: {{#each}} with array proxies, modifying itself', function (_SingleEachTest3) {
(0, _emberBabel.inherits)(_class7, _SingleEachTest3);
function _class7() {
return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest3.apply(this, arguments));
}
_class7.prototype.makeList = function (list) {
return this.list = this.delegate = _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(list) });
};
return _class7;
}(SingleEachTest));
(0, _testCase.moduleFor)('Syntax test: {{#each}} with array proxies, replacing its content', function (_SingleEachTest4) {
(0, _emberBabel.inherits)(_class8, _SingleEachTest4);
function _class8() {
return (0, _emberBabel.possibleConstructorReturn)(this, _SingleEachTest4.apply(this, arguments));
}
_class8.prototype.makeList = function (list) {
var content = this.delegate = (0, _emberRuntime.A)(list);
return this.list = _emberRuntime.ArrayProxy.create({ content: content });
};
_class8.prototype.replaceList = function (list) {
var _this33 = this;
this.runTask(function () {
return _this33.list.set('content', (0, _emberRuntime.A)(list));
});
};
return _class8;
}(SingleEachTest));
// TODO: Refactor the following tests so we can run them against different kind of arrays
(0, _testCase.moduleFor)('Syntax test: Multiple {{#each as}} helpers', function (_RenderingTest2) {
(0, _emberBabel.inherits)(_class9, _RenderingTest2);
function _class9() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest2.apply(this, arguments));
}
_class9.prototype['@test re-using the same variable with different {{#each}} blocks does not override each other'] = function () {
var _this35 = this;
this.render('Admin: {{#each admins key="name" as |person|}}[{{person.name}}]{{/each}} User: {{#each users key="name" as |person|}}[{{person.name}}]{{/each}}', {
admins: (0, _emberRuntime.A)([{ name: 'Tom Dale' }]),
users: (0, _emberRuntime.A)([{ name: 'Yehuda Katz' }])
});
this.assertText('Admin: [Tom Dale] User: [Yehuda Katz]');
this.runTask(function () {
return _this35.rerender();
});
this.assertText('Admin: [Tom Dale] User: [Yehuda Katz]');
this.runTask(function () {
(0, _emberMetal.get)(_this35.context, 'admins').pushObject({ name: 'Godfrey Chan' });
(0, _emberMetal.set)((0, _emberMetal.get)(_this35.context, 'users').objectAt(0), 'name', 'Stefan Penner');
});
this.assertText('Admin: [Tom Dale][Godfrey Chan] User: [Stefan Penner]');
this.runTask(function () {
(0, _emberMetal.set)(_this35.context, 'admins', [{ name: 'Tom Dale' }]);
(0, _emberMetal.set)(_this35.context, 'users', [{ name: 'Yehuda Katz' }]);
});
this.assertText('Admin: [Tom Dale] User: [Yehuda Katz]');
};
_class9.prototype['@test an outer {{#each}}\'s scoped variable does not clobber an inner {{#each}}\'s property if they share the same name - Issue #1315'] = function () {
var _this36 = this;
this.render((0, _abstractTestCase.strip)(_templateObject2), {
content: (0, _emberRuntime.A)(['X', 'Y']),
options: (0, _emberRuntime.A)([{ label: 'One', value: 1 }, { label: 'Two', value: 2 }])
});
this.assertText('X-1:One2:TwoY-1:One2:Two');
this.assertStableRerender();
this.runTask(function () {
(0, _emberMetal.get)(_this36.context, 'content').pushObject('Z');
(0, _emberMetal.set)((0, _emberMetal.get)(_this36.context, 'options').objectAt(0), 'value', 0);
});
this.assertText('X-0:One2:TwoY-0:One2:TwoZ-0:One2:Two');
this.runTask(function () {
(0, _emberMetal.set)(_this36.context, 'content', ['X', 'Y']);
(0, _emberMetal.set)(_this36.context, 'options', [{ label: 'One', value: 1 }, { label: 'Two', value: 2 }]);
});
this.assertText('X-1:One2:TwoY-1:One2:Two');
};
_class9.prototype['@test the scoped variable is not available outside the {{#each}} block'] = function () {
var _this37 = this;
this.render('{{ring}}-{{#each first as |ring|}}{{ring}}-{{#each fifth as |ring|}}{{ring}}-{{#each ninth as |ring|}}{{ring}}-{{/each}}{{ring}}-{{/each}}{{ring}}-{{/each}}{{ring}}', {
ring: 'Greed',
first: (0, _emberRuntime.A)(['Limbo']),
fifth: (0, _emberRuntime.A)(['Wrath']),
ninth: (0, _emberRuntime.A)(['Treachery'])
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
this.runTask(function () {
return _this37.rerender();
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
this.runTask(function () {
(0, _emberMetal.set)(_this37.context, 'ring', 'O');
(0, _emberMetal.get)(_this37.context, 'fifth').insertAt(0, 'D');
});
this.assertText('O-Limbo-D-Treachery-D-Wrath-Treachery-Wrath-Limbo-O');
this.runTask(function () {
(0, _emberMetal.get)(_this37.context, 'first').pushObject('I');
(0, _emberMetal.get)(_this37.context, 'ninth').replace(0, 1, 'K');
});
this.assertText('O-Limbo-D-K-D-Wrath-K-Wrath-Limbo-I-D-K-D-Wrath-K-Wrath-I-O');
this.runTask(function () {
(0, _emberMetal.set)(_this37.context, 'ring', 'Greed');
(0, _emberMetal.set)(_this37.context, 'first', ['Limbo']);
(0, _emberMetal.set)(_this37.context, 'fifth', ['Wrath']);
(0, _emberMetal.set)(_this37.context, 'ninth', ['Treachery']);
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
};
_class9.prototype['@test it should support {{#each name as |foo|}}, then {{#each foo as |bar|}}'] = function () {
var _this38 = this;
this.render('{{#each name key="@index" as |foo|}}{{#each foo as |bar|}}{{bar}}{{/each}}{{/each}}', {
name: (0, _emberRuntime.A)([(0, _emberRuntime.A)(['caterpillar'])])
});
this.assertText('caterpillar');
this.runTask(function () {
return _this38.rerender();
});
this.assertText('caterpillar');
this.runTask(function () {
var name = (0, _emberMetal.get)(_this38.context, 'name');
name.objectAt(0).replace(0, 1, 'lady');
name.pushObject(['bird']);
});
this.assertText('ladybird');
this.runTask(function () {
return (0, _emberMetal.set)(_this38.context, 'name', [['caterpillar']]);
});
this.assertText('caterpillar');
};
return _class9;
}(_testCase.RenderingTest));
(0, _testCase.moduleFor)('Syntax test: {{#each as}} undefined path', function (_RenderingTest3) {
(0, _emberBabel.inherits)(_class10, _RenderingTest3);
function _class10() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest3.apply(this, arguments));
}
_class10.prototype['@test keying off of `undefined` does not render'] = function () {
var _this40 = this;
this.render((0, _abstractTestCase.strip)(_templateObject3), { foo: {} });
this.assertText('');
this.runTask(function () {
return _this40.rerender();
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this40.context, 'foo', { bar: { baz: ['Here!'] } });
});
this.assertText('Here!');
this.runTask(function () {
return (0, _emberMetal.set)(_this40.context, 'foo', {});
});
this.assertText('');
};
return _class10;
}(_testCase.RenderingTest));
(0, _testCase.moduleFor)('Syntax test: {{#each}} with sparse arrays', function (_RenderingTest4) {
(0, _emberBabel.inherits)(_class11, _RenderingTest4);
function _class11() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest4.apply(this, arguments));
}
_class11.prototype['@test it should itterate over holes'] = function () {
var _this42 = this;
var sparseArray = [];
sparseArray[3] = 'foo';
sparseArray[4] = 'bar';
this.render((0, _abstractTestCase.strip)(_templateObject4), { list: (0, _emberRuntime.A)(sparseArray) });
this.assertText('[0:][1:][2:][3:foo][4:bar]');
this.assertStableRerender();
this.runTask(function () {
var list = (0, _emberMetal.get)(_this42.context, 'list');
list.pushObject('baz');
});
this.assertText('[0:][1:][2:][3:foo][4:bar][5:baz]');
};
return _class11;
}(_testCase.RenderingTest));
/* globals MutationObserver: false */
if (typeof MutationObserver === 'function') {
(0, _testCase.moduleFor)('Syntax test: {{#each as}} DOM mutation test', function (_RenderingTest5) {
(0, _emberBabel.inherits)(_class12, _RenderingTest5);
function _class12() {
var _this43 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest5.call(this));
_this43.observer = null;
return _this43;
}
_class12.prototype.observe = function (element) {
var observer = this.observer = new MutationObserver(function () {});
observer.observe(element, { childList: true, characterData: true });
};
_class12.prototype.teardown = function () {
if (this.observer) {
this.observer.disconnect();
}
_RenderingTest5.prototype.teardown.call(this);
};
_class12.prototype.assertNoMutation = function () {
this.assert.deepEqual(this.observer.takeRecords(), [], 'Expected no mutations');
};
_class12.prototype.expectMutations = function () {
this.assert.ok(this.observer.takeRecords().length > 0, 'Expected some mutations');
};
_class12.prototype['@test {{#each}} should not mutate a subtree when the array has not changed [GH #14332]'] = function () {
var _this44 = this;
this.render((0, _abstractTestCase.strip)(_templateObject5), { page: { title: 'Blog Posts' }, model: [{ title: 'Rails is omakase' }, { title: 'Ember is omakase' }] });
this.assertHTML((0, _abstractTestCase.strip)(_templateObject6));
this.observe(this.$('#posts')[0]);
// MutationObserver is async
return _emberRuntime.RSVP.Promise.resolve(function () {
_this44.assertStableRerender();
}).then(function () {
_this44.assertNoMutation();
_this44.runTask(function () {
return (0, _emberMetal.set)(_this44.context, 'page', { title: 'Essays' });
});
_this44.assertHTML((0, _abstractTestCase.strip)(_templateObject7));
}).then(function () {
_this44.assertNoMutation();
_this44.runTask(function () {
return (0, _emberMetal.set)(_this44.context.page, 'title', 'Think Pieces™');
});
_this44.assertHTML((0, _abstractTestCase.strip)(_templateObject8));
}).then(function () {
// The last set is localized to the `page` object, so we do not expect Glimmer
// to re-iterate the list
_this44.assertNoMutation();
});
};
return _class12;
}(_testCase.RenderingTest));
}
});
enifed('ember-glimmer/tests/integration/syntax/if-unless-test', ['ember-babel', 'ember-glimmer/tests/utils/helpers', 'ember-runtime', 'ember-metal', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/shared-conditional-tests'], function (_emberBabel, _helpers, _emberRuntime, _emberMetal, _abstractTestCase, _testCase, _sharedConditionalTests) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if cond}}\n {{#each numbers as |number|}}\n {{foo-bar number=number}}\n {{/each}}\n {{else}}\n Nothing Here!\n {{/if}}'], ['\n {{#if cond}}\n {{#each numbers as |number|}}\n {{foo-bar number=number}}\n {{/each}}\n {{else}}\n Nothing Here!\n {{/if}}']),
_templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if foo.bar.baz}}\n Here!\n {{else}}\n Nothing Here!\n {{/if}}'], ['\n {{#if foo.bar.baz}}\n Here!\n {{else}}\n Nothing Here!\n {{/if}}']);
(0, _testCase.moduleFor)('Syntax test: {{#if}} with inverse', function (_IfUnlessWithSyntaxTe) {
(0, _emberBabel.inherits)(_class, _IfUnlessWithSyntaxTe);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe.apply(this, arguments));
}
_class.prototype.templateFor = function (_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return '{{#if ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/if}}';
};
return _class;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _testCase.moduleFor)('Syntax test: {{#unless}} with inverse', function (_IfUnlessWithSyntaxTe2) {
(0, _emberBabel.inherits)(_class2, _IfUnlessWithSyntaxTe2);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe2.apply(this, arguments));
}
_class2.prototype.templateFor = function (_ref2) {
var cond = _ref2.cond,
truthy = _ref2.truthy,
falsy = _ref2.falsy;
return '{{#unless ' + cond + '}}' + falsy + '{{else}}' + truthy + '{{/unless}}';
};
return _class2;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _testCase.moduleFor)('Syntax test: {{#if}} and {{#unless}} without inverse', function (_IfUnlessWithSyntaxTe3) {
(0, _emberBabel.inherits)(_class3, _IfUnlessWithSyntaxTe3);
function _class3() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe3.apply(this, arguments));
}
_class3.prototype.templateFor = function (_ref3) {
var cond = _ref3.cond,
truthy = _ref3.truthy,
falsy = _ref3.falsy;
return '{{#if ' + cond + '}}' + truthy + '{{/if}}{{#unless ' + cond + '}}' + falsy + '{{/unless}}';
};
return _class3;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _testCase.moduleFor)('Syntax test: {{#if}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class4, _RenderingTest);
function _class4() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class4.prototype['@test using `if` with an `{{each}}` destroys components when transitioning to and from inverse (GH #12267)'] = function (assert) {
var _this5 = this;
var destroyedChildrenCount = 0;
this.registerComponent('foo-bar', {
template: '{{number}}',
ComponentClass: _helpers.Component.extend({
willDestroy: function () {
this._super();
destroyedChildrenCount++;
}
})
});
this.render((0, _abstractTestCase.strip)(_templateObject), { cond: true, numbers: (0, _emberRuntime.A)([1, 2, 3]) });
this.assertText('123');
this.runTask(function () {
return _this5.rerender();
});
this.assertText('123');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'cond', false);
});
this.assertText('Nothing Here!');
assert.equal(destroyedChildrenCount, 3, 'the children were properly destroyed');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'cond', true);
});
this.assertText('123');
};
_class4.prototype['@test looking up `undefined` property defaults to false'] = function () {
var _this6 = this;
this.render((0, _abstractTestCase.strip)(_templateObject2), { foo: {} });
this.assertText('Nothing Here!');
this.runTask(function () {
return _this6.rerender();
});
this.assertText('Nothing Here!');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'foo', { bar: { baz: true } });
});
this.assertText('Here!');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'foo', {});
});
this.assertText('Nothing Here!');
};
return _class4;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/syntax/in-element-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/test-helpers', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/component', 'ember-metal'], function (_emberBabel, _testCase, _testHelpers, _abstractTestCase, _component, _emberMetal) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#-in-element someElement}}\n {{text}}\n {{/-in-element}}\n '], ['\n {{#-in-element someElement}}\n {{text}}\n {{/-in-element}}\n ']),
_templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#if showModal}}\n {{#-in-element someElement}}\n {{modal-display text=text}}\n {{/-in-element}}\n {{/if}}\n '], ['\n {{#if showModal}}\n {{#-in-element someElement}}\n {{modal-display text=text}}\n {{/-in-element}}\n {{/if}}\n ']);
(0, _testCase.moduleFor)('{{-in-element}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test allows rendering into an external element'] = function () {
var _this2 = this;
var someElement = document.createElement('div');
this.render((0, _abstractTestCase.strip)(_templateObject), {
someElement: someElement,
text: 'Whoop!'
});
(0, _testHelpers.equalTokens)(this.element, '');
(0, _testHelpers.equalTokens)(someElement, 'Whoop!');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'text', 'Huzzah!!');
});
(0, _testHelpers.equalTokens)(this.element, '');
(0, _testHelpers.equalTokens)(someElement, 'Huzzah!!');
this.runTask(function () {
return (0, _emberMetal.set)(_this2.context, 'text', 'Whoop!');
});
(0, _testHelpers.equalTokens)(this.element, '');
(0, _testHelpers.equalTokens)(someElement, 'Whoop!');
};
_class.prototype['@test components are cleaned up properly'] = function (assert) {
var _this3 = this;
var hooks = [];
var someElement = document.createElement('div');
this.registerComponent('modal-display', {
ComponentClass: _component.default.extend({
didInsertElement: function () {
hooks.push('didInsertElement');
},
willDestroyElement: function () {
hooks.push('willDestroyElement');
}
}),
template: '{{text}}'
});
this.render((0, _abstractTestCase.strip)(_templateObject2), {
someElement: someElement,
text: 'Whoop!',
showModal: false
});
(0, _testHelpers.equalTokens)(this.element, '');
(0, _testHelpers.equalTokens)(someElement, '');
this.assertStableRerender();
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'showModal', true);
});
(0, _testHelpers.equalTokens)(this.element, '');
this.assertComponentElement(someElement.firstChild, { content: 'Whoop!' });
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'text', 'Huzzah!');
});
(0, _testHelpers.equalTokens)(this.element, '');
this.assertComponentElement(someElement.firstChild, { content: 'Huzzah!' });
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'text', 'Whoop!');
});
(0, _testHelpers.equalTokens)(this.element, '');
this.assertComponentElement(someElement.firstChild, { content: 'Whoop!' });
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'showModal', false);
});
(0, _testHelpers.equalTokens)(this.element, '');
(0, _testHelpers.equalTokens)(someElement, '');
assert.deepEqual(hooks, ['didInsertElement', 'willDestroyElement']);
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/syntax/with-dynamic-var-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _testCase, _abstractTestCase) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#-with-dynamic-vars foo="bar"}}\n {{-get-dynamic-var \'foo\'}}\n {{/-with-dynamic-vars}}\n '], ['\n {{#-with-dynamic-vars foo="bar"}}\n {{-get-dynamic-var \'foo\'}}\n {{/-with-dynamic-vars}}\n ']),
_templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#-with-dynamic-vars outletState="bar"}}\n {{-get-dynamic-var \'outletState\'}}\n {{/-with-dynamic-vars}}\n '], ['\n {{#-with-dynamic-vars outletState="bar"}}\n {{-get-dynamic-var \'outletState\'}}\n {{/-with-dynamic-vars}}\n ']);
(0, _testCase.moduleFor)('{{-with-dynamic-var}}', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test does not allow setting values other than outletState'] = function () {
var _this2 = this;
expectAssertion(function () {
_this2.render((0, _abstractTestCase.strip)(_templateObject));
}, /Using `-with-dynamic-scope` is only supported for `outletState` \(you used `foo`\)./);
};
_class.prototype['@test allows setting/getting outletState'] = function () {
// this is simply asserting that we can write and read outletState
// the actual value being used here is not what is used in real life
// feel free to change the value being set and asserted as needed
this.render((0, _abstractTestCase.strip)(_templateObject2));
this.assertText('bar');
};
_class.prototype['@test does not allow setting values other than outletState'] = function () {
var _this3 = this;
expectAssertion(function () {
_this3.render('{{-get-dynamic-var \'foo\'}}');
}, /Using `-get-dynamic-scope` is only supported for `outletState` \(you used `foo`\)./);
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/integration/syntax/with-test', ['ember-babel', 'ember-metal', 'ember-runtime', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/shared-conditional-tests', 'ember-glimmer/tests/utils/abstract-test-case'], function (_emberBabel, _emberMetal, _emberRuntime, _testCase, _sharedConditionalTests, _abstractTestCase) {
'use strict';
var _templateObject = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{#with foo.bar.baz as |thing|}}\n {{thing}}\n {{/with}}'], ['\n {{#with foo.bar.baz as |thing|}}\n {{thing}}\n {{/with}}']),
_templateObject2 = (0, _emberBabel.taggedTemplateLiteralLoose)(['\n {{name}}\n {{#with committer1.name as |name|}}\n [{{name}}\n {{#with committer2.name as |name|}}\n [{{name}}]\n {{/with}}\n {{name}}]\n {{/with}}\n {{name}}\n {{#with committer2.name as |name|}}\n [{{name}}\n {{#with committer1.name as |name|}}\n [{{name}}]\n {{/with}}\n {{name}}]\n {{/with}}\n {{name}}\n '], ['\n {{name}}\n {{#with committer1.name as |name|}}\n [{{name}}\n {{#with committer2.name as |name|}}\n [{{name}}]\n {{/with}}\n {{name}}]\n {{/with}}\n {{name}}\n {{#with committer2.name as |name|}}\n [{{name}}\n {{#with committer1.name as |name|}}\n [{{name}}]\n {{/with}}\n {{name}}]\n {{/with}}\n {{name}}\n ']);
(0, _testCase.moduleFor)('Syntax test: {{#with}}', function (_IfUnlessWithSyntaxTe) {
(0, _emberBabel.inherits)(_class, _IfUnlessWithSyntaxTe);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe.apply(this, arguments));
}
_class.prototype.templateFor = function (_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
return '{{#with ' + cond + '}}' + truthy + '{{else}}' + falsy + '{{/with}}';
};
return _class;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _testCase.moduleFor)('Syntax test: {{#with as}}', function (_IfUnlessWithSyntaxTe2) {
(0, _emberBabel.inherits)(_class2, _IfUnlessWithSyntaxTe2);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _IfUnlessWithSyntaxTe2.apply(this, arguments));
}
_class2.prototype.templateFor = function (_ref2) {
var cond = _ref2.cond,
truthy = _ref2.truthy,
falsy = _ref2.falsy;
return '{{#with ' + cond + ' as |test|}}' + truthy + '{{else}}' + falsy + '{{/with}}';
};
_class2.prototype['@test keying off of `undefined` does not render'] = function () {
var _this3 = this;
this.render((0, _abstractTestCase.strip)(_templateObject), { foo: {} });
this.assertText('');
this.runTask(function () {
return _this3.rerender();
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'foo', { bar: { baz: 'Here!' } });
});
this.assertText('Here!');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'foo', {});
});
this.assertText('');
};
_class2.prototype['@test it renders and hides the given block based on the conditional'] = function () {
var _this4 = this;
this.render('{{#with cond1 as |cond|}}{{cond.greeting}}{{else}}False{{/with}}', {
cond1: { greeting: 'Hello' }
});
this.assertText('Hello');
this.runTask(function () {
return _this4.rerender();
});
this.assertText('Hello');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'cond1.greeting', 'Hello world');
});
this.assertText('Hello world');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'cond1', false);
});
this.assertText('False');
this.runTask(function () {
return (0, _emberMetal.set)(_this4.context, 'cond1', { greeting: 'Hello' });
});
this.assertText('Hello');
};
_class2.prototype['@test can access alias and original scope'] = function () {
var _this5 = this;
this.render('{{#with person as |tom|}}{{title}}: {{tom.name}}{{/with}}', {
title: 'Señor Engineer',
person: { name: 'Tom Dale' }
});
this.assertText('Señor Engineer: Tom Dale');
this.runTask(function () {
return _this5.rerender();
});
this.assertText('Señor Engineer: Tom Dale');
this.runTask(function () {
(0, _emberMetal.set)(_this5.context, 'person.name', 'Yehuda Katz');
(0, _emberMetal.set)(_this5.context, 'title', 'Principal Engineer');
});
this.assertText('Principal Engineer: Yehuda Katz');
this.runTask(function () {
(0, _emberMetal.set)(_this5.context, 'person', { name: 'Tom Dale' });
(0, _emberMetal.set)(_this5.context, 'title', 'Señor Engineer');
});
this.assertText('Señor Engineer: Tom Dale');
};
_class2.prototype['@test the scoped variable is not available outside the {{#with}} block.'] = function () {
var _this6 = this;
this.render('{{name}}-{{#with other as |name|}}{{name}}{{/with}}-{{name}}', {
name: 'Stef',
other: 'Yehuda'
});
this.assertText('Stef-Yehuda-Stef');
this.runTask(function () {
return _this6.rerender();
});
this.assertText('Stef-Yehuda-Stef');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'other', 'Chad');
});
this.assertText('Stef-Chad-Stef');
this.runTask(function () {
return (0, _emberMetal.set)(_this6.context, 'name', 'Tom');
});
this.assertText('Tom-Chad-Tom');
this.runTask(function () {
(0, _emberMetal.set)(_this6.context, 'name', 'Stef');
(0, _emberMetal.set)(_this6.context, 'other', 'Yehuda');
});
this.assertText('Stef-Yehuda-Stef');
};
_class2.prototype['@test inverse template is displayed with context'] = function () {
var _this7 = this;
this.render('{{#with falsyThing as |thing|}}Has Thing{{else}}No Thing {{otherThing}}{{/with}}', {
falsyThing: null,
otherThing: 'bar'
});
this.assertText('No Thing bar');
this.runTask(function () {
return _this7.rerender();
});
this.assertText('No Thing bar');
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'otherThing', 'biz');
});
this.assertText('No Thing biz');
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'falsyThing', true);
});
this.assertText('Has Thing');
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'otherThing', 'baz');
});
this.assertText('Has Thing');
this.runTask(function () {
(0, _emberMetal.set)(_this7.context, 'otherThing', 'bar');
(0, _emberMetal.set)(_this7.context, 'falsyThing', null);
});
this.assertText('No Thing bar');
};
_class2.prototype['@test can access alias of a proxy'] = function () {
var _this8 = this;
this.render('{{#with proxy as |person|}}{{person.name}}{{/with}}', {
proxy: _emberRuntime.ObjectProxy.create({ content: { name: 'Tom Dale' } })
});
this.assertText('Tom Dale');
this.runTask(function () {
return _this8.rerender();
});
this.assertText('Tom Dale');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'proxy.name', 'Yehuda Katz');
});
this.assertText('Yehuda Katz');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'proxy.content', { name: 'Godfrey Chan' });
});
this.assertText('Godfrey Chan');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'proxy.content.name', 'Stefan Penner');
});
this.assertText('Stefan Penner');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'proxy.content', null);
});
this.assertText('');
this.runTask(function () {
return (0, _emberMetal.set)(_this8.context, 'proxy', _emberRuntime.ObjectProxy.create({ content: { name: 'Tom Dale' } }));
});
this.assertText('Tom Dale');
};
_class2.prototype['@test can access alias of an array'] = function () {
var _this9 = this;
this.render('{{#with arrayThing as |words|}}{{#each words as |word|}}{{word}}{{/each}}{{/with}}', {
arrayThing: (0, _emberRuntime.A)(['Hello', ' ', 'world'])
});
this.assertText('Hello world');
this.runTask(function () {
return _this9.rerender();
});
this.assertText('Hello world');
this.runTask(function () {
var array = (0, _emberMetal.get)(_this9.context, 'arrayThing');
array.replace(0, 1, 'Goodbye');
(0, _emberRuntime.removeAt)(array, 1);
array.insertAt(1, ', ');
array.pushObject('!');
});
this.assertText('Goodbye, world!');
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'arrayThing', ['Hello', ' ', 'world']);
});
this.assertText('Hello world');
};
_class2.prototype['@test `attrs` can be used as a block param [GH#14678]'] = function () {
var _this10 = this;
this.render('{{#with hash as |attrs|}}[{{hash.foo}}-{{attrs.foo}}]{{/with}}', {
hash: { foo: 'foo' }
});
this.assertText('[foo-foo]');
this.runTask(function () {
return _this10.rerender();
});
this.assertText('[foo-foo]');
this.runTask(function () {
return _this10.context.set('hash.foo', 'FOO');
});
this.assertText('[FOO-FOO]');
this.runTask(function () {
return _this10.context.set('hash.foo', 'foo');
});
this.assertText('[foo-foo]');
};
return _class2;
}(_sharedConditionalTests.IfUnlessWithSyntaxTest));
(0, _testCase.moduleFor)('Syntax test: Multiple {{#with as}} helpers', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class3, _RenderingTest);
function _class3() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class3.prototype['@test re-using the same variable with different {{#with}} blocks does not override each other'] = function () {
var _this12 = this;
this.render('Admin: {{#with admin as |person|}}{{person.name}}{{/with}} User: {{#with user as |person|}}{{person.name}}{{/with}}', {
admin: { name: 'Tom Dale' },
user: { name: 'Yehuda Katz' }
});
this.assertText('Admin: Tom Dale User: Yehuda Katz');
this.runTask(function () {
return _this12.rerender();
});
this.assertText('Admin: Tom Dale User: Yehuda Katz');
this.runTask(function () {
(0, _emberMetal.set)(_this12.context, 'admin.name', 'Godfrey Chan');
(0, _emberMetal.set)(_this12.context, 'user.name', 'Stefan Penner');
});
this.assertText('Admin: Godfrey Chan User: Stefan Penner');
this.runTask(function () {
(0, _emberMetal.set)(_this12.context, 'admin', { name: 'Tom Dale' });
(0, _emberMetal.set)(_this12.context, 'user', { name: 'Yehuda Katz' });
});
this.assertText('Admin: Tom Dale User: Yehuda Katz');
};
_class3.prototype['@test the scoped variable is not available outside the {{#with}} block'] = function () {
var _this13 = this;
this.render('{{ring}}-{{#with first as |ring|}}{{ring}}-{{#with fifth as |ring|}}{{ring}}-{{#with ninth as |ring|}}{{ring}}-{{/with}}{{ring}}-{{/with}}{{ring}}-{{/with}}{{ring}}', {
ring: 'Greed',
first: 'Limbo',
fifth: 'Wrath',
ninth: 'Treachery'
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
this.runTask(function () {
return _this13.rerender();
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
this.runTask(function () {
(0, _emberMetal.set)(_this13.context, 'ring', 'O');
(0, _emberMetal.set)(_this13.context, 'fifth', 'D');
});
this.assertText('O-Limbo-D-Treachery-D-Limbo-O');
this.runTask(function () {
(0, _emberMetal.set)(_this13.context, 'first', 'I');
(0, _emberMetal.set)(_this13.context, 'ninth', 'K');
});
this.assertText('O-I-D-K-D-I-O');
this.runTask(function () {
(0, _emberMetal.set)(_this13.context, 'ring', 'Greed');
(0, _emberMetal.set)(_this13.context, 'first', 'Limbo');
(0, _emberMetal.set)(_this13.context, 'fifth', 'Wrath');
(0, _emberMetal.set)(_this13.context, 'ninth', 'Treachery');
});
this.assertText('Greed-Limbo-Wrath-Treachery-Wrath-Limbo-Greed');
};
_class3.prototype['@test it should support {{#with name as |foo|}}, then {{#with foo as |bar|}}'] = function () {
var _this14 = this;
this.render('{{#with name as |foo|}}{{#with foo as |bar|}}{{bar}}{{/with}}{{/with}}', {
name: 'caterpillar'
});
this.assertText('caterpillar');
this.runTask(function () {
return _this14.rerender();
});
this.assertText('caterpillar');
this.runTask(function () {
return (0, _emberMetal.set)(_this14.context, 'name', 'butterfly');
});
this.assertText('butterfly');
this.runTask(function () {
return (0, _emberMetal.set)(_this14.context, 'name', 'caterpillar');
});
this.assertText('caterpillar');
};
_class3.prototype['@test updating the context should update the alias'] = function () {
var _this15 = this;
this.render('{{#with this as |person|}}{{person.name}}{{/with}}', {
name: 'Los Pivots'
});
this.assertText('Los Pivots');
this.runTask(function () {
return _this15.rerender();
});
this.assertText('Los Pivots');
this.runTask(function () {
return (0, _emberMetal.set)(_this15.context, 'name', 'l\'Pivots');
});
this.assertText('l\'Pivots');
this.runTask(function () {
return (0, _emberMetal.set)(_this15.context, 'name', 'Los Pivots');
});
this.assertText('Los Pivots');
};
_class3.prototype['@test nested {{#with}} blocks should have access to root context'] = function () {
var _this16 = this;
this.render((0, _abstractTestCase.strip)(_templateObject2), {
name: 'ebryn',
committer1: { name: 'trek' },
committer2: { name: 'machty' }
});
this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');
this.runTask(function () {
return _this16.rerender();
});
this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');
this.runTask(function () {
return (0, _emberMetal.set)(_this16.context, 'name', 'chancancode');
});
this.assertText('chancancode[trek[machty]trek]chancancode[machty[trek]machty]chancancode');
this.runTask(function () {
return (0, _emberMetal.set)(_this16.context, 'committer1', { name: 'krisselden' });
});
this.assertText('chancancode[krisselden[machty]krisselden]chancancode[machty[krisselden]machty]chancancode');
this.runTask(function () {
(0, _emberMetal.set)(_this16.context, 'committer1.name', 'wycats');
(0, _emberMetal.set)(_this16.context, 'committer2', { name: 'rwjblue' });
});
this.assertText('chancancode[wycats[rwjblue]wycats]chancancode[rwjblue[wycats]rwjblue]chancancode');
this.runTask(function () {
(0, _emberMetal.set)(_this16.context, 'name', 'ebryn');
(0, _emberMetal.set)(_this16.context, 'committer1', { name: 'trek' });
(0, _emberMetal.set)(_this16.context, 'committer2', { name: 'machty' });
});
this.assertText('ebryn[trek[machty]trek]ebryn[machty[trek]machty]ebryn');
};
return _class3;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/unit/layout-cache-test', ['ember-babel', 'ember-glimmer/tests/utils/test-case', '@glimmer/runtime', 'ember-utils'], function (_emberBabel, _testCase, _runtime, _emberUtils) {
'use strict';
var Counter = function () {
function Counter() {
this.reset();
}
Counter.prototype.increment = function (key) {
this.total++;
return this.counts[key] = (this.counts[key] || 0) + 1;
};
Counter.prototype.get = function (key) {
return this.counts[key] || 0;
};
Counter.prototype.reset = function () {
this.total = 0;
this.counts = Object.create(null);
};
return Counter;
}();
var COUNTER = new Counter();
var BasicCompiler = function () {
function BasicCompiler(template) {
this.template = template;
}
BasicCompiler.prototype.compile = function (builder) {
var template = this.template;
COUNTER.increment(this.constructor.id + '+' + template.id);
builder.wrapLayout(template.asLayout());
};
return BasicCompiler;
}();
var TypeOneCompiler = function (_BasicCompiler) {
(0, _emberBabel.inherits)(TypeOneCompiler, _BasicCompiler);
function TypeOneCompiler() {
return (0, _emberBabel.possibleConstructorReturn)(this, _BasicCompiler.apply(this, arguments));
}
return TypeOneCompiler;
}(BasicCompiler);
var TypeTwoCompiler = function (_BasicCompiler2) {
(0, _emberBabel.inherits)(TypeTwoCompiler, _BasicCompiler2);
function TypeTwoCompiler() {
return (0, _emberBabel.possibleConstructorReturn)(this, _BasicCompiler2.apply(this, arguments));
}
return TypeTwoCompiler;
}(BasicCompiler);
TypeOneCompiler.id = 'type-one';
TypeTwoCompiler.id = 'type-two';
(0, _testCase.moduleFor)('Layout cache test', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
var _this3 = (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.call(this));
COUNTER.reset();
return _this3;
}
_class.prototype.templateFor = function (content) {
var Factory = this.compile(content);
return this.env.getTemplate(Factory, this.owner);
};
_class.prototype['@test each template is only compiled once'] = function (assert) {
var env = this.env;
var template1 = this.templateFor('Hello world!');
var template2 = this.templateFor('{{foo}} {{bar}}');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.strictEqual(COUNTER.get('type-one+' + template1.id), 1);
assert.strictEqual(COUNTER.get('type-one+' + template2.id), 0);
assert.strictEqual(COUNTER.total, 1);
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.strictEqual(COUNTER.get('type-one+' + template1.id), 1);
assert.strictEqual(COUNTER.get('type-one+' + template2.id), 0);
assert.strictEqual(COUNTER.total, 1);
assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.strictEqual(COUNTER.get('type-one+' + template1.id), 1);
assert.strictEqual(COUNTER.get('type-one+' + template2.id), 1);
assert.strictEqual(COUNTER.total, 2);
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.strictEqual(COUNTER.get('type-one+' + template1.id), 1);
assert.strictEqual(COUNTER.get('type-one+' + template2.id), 1);
assert.strictEqual(COUNTER.total, 2);
};
_class.prototype['@test each template/compiler pair is treated as unique'] = function (assert) {
var env = this.env;
var template = this.templateFor('Hello world!');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.strictEqual(COUNTER.get('type-one+' + template.id), 1);
assert.strictEqual(COUNTER.get('type-two+' + template.id), 0);
assert.strictEqual(COUNTER.total, 1);
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.strictEqual(COUNTER.get('type-one+' + template.id), 1);
assert.strictEqual(COUNTER.get('type-two+' + template.id), 0);
assert.strictEqual(COUNTER.total, 1);
assert.ok(env.getCompiledBlock(TypeTwoCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.strictEqual(COUNTER.get('type-one+' + template.id), 1);
assert.strictEqual(COUNTER.get('type-two+' + template.id), 1);
assert.strictEqual(COUNTER.total, 2);
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeTwoCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeTwoCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeTwoCompiler, template) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.strictEqual(COUNTER.get('type-one+' + template.id), 1);
assert.strictEqual(COUNTER.get('type-two+' + template.id), 1);
assert.strictEqual(COUNTER.total, 2);
};
_class.prototype['@test a template instance is returned (ensures templates can be injected into layout property)'] = function (assert) {
var _this4 = this;
var owner = this.owner,
env = this.env;
var templateInstanceFor = function (content) {
var _Factory$create;
var Factory = _this4.compile(content);
return Factory.create((_Factory$create = {}, _Factory$create[_emberUtils.OWNER] = owner, _Factory$create.env = env, _Factory$create));
};
var template1 = templateInstanceFor('Hello world!');
var template2 = templateInstanceFor('{{foo}} {{bar}}');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template1) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
assert.ok(env.getCompiledBlock(TypeOneCompiler, template2) instanceof _runtime.CompiledBlock, 'should return a CompiledBlock');
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/unit/outlet-test', ['ember-glimmer/views/outlet', 'ember-metal'], function (_outlet, _emberMetal) {
'use strict';
QUnit.module('Glimmer OutletView');
QUnit.test('render in the render queue', function (assert) {
var didAppendOutletView = 0;
var expectedOutlet = '#foo.bar';
var outletView = new _outlet.default({}, {
appendOutletView: function (view, target) {
didAppendOutletView++;
assert.equal(view, outletView);
assert.equal(target, expectedOutlet);
}
});
(0, _emberMetal.run)(function () {
assert.equal(didAppendOutletView, 0, 'appendOutletView should not yet have been called (before appendTo)');
outletView.appendTo(expectedOutlet);
assert.equal(didAppendOutletView, 0, 'appendOutletView should not yet have been called (sync after appendTo)');
_emberMetal.run.schedule('actions', function () {
return assert.equal(didAppendOutletView, 0, 'appendOutletView should not yet have been called (in actions)');
});
_emberMetal.run.schedule('render', function () {
return assert.equal(didAppendOutletView, 1, 'appendOutletView should be invoked in render');
});
});
});
});
enifed('ember-glimmer/tests/unit/template-factory-test', ['ember-babel', 'ember-template-compiler', 'ember-glimmer/index', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/tests/utils/helpers'], function (_emberBabel, _emberTemplateCompiler, _index, _testCase, _helpers) {
'use strict';
(0, _testCase.moduleFor)('Template factory test', function (_RenderingTest) {
(0, _emberBabel.inherits)(_class, _RenderingTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
_class.prototype['@test the template factory returned from precompile is the same as compile'] = function (assert) {
var env = this.env;
var templateStr = 'Hello {{name}}';
var options = { moduleName: 'some-module' };
var spec = (0, _emberTemplateCompiler.precompile)(templateStr, options);
var module = new Function('exports', 'template', 'exports.default = template(' + spec + ');');
var exports = {};
module(exports, _index.template);
var Precompiled = exports['default'];
var Compiled = (0, _emberTemplateCompiler.compile)(templateStr, options);
assert.equal(typeof Precompiled.create, 'function', 'precompiled is a factory');
assert.ok(Precompiled.id, 'precompiled has id');
assert.equal(typeof Compiled.create, 'function', 'compiled is a factory');
assert.ok(Compiled.id, 'compiled has id');
assert.equal(env._templateCache.misses, 0, 'misses 0');
assert.equal(env._templateCache.hits, 0, 'hits 0');
var precompiled = env.getTemplate(Precompiled, env.owner);
assert.equal(env._templateCache.misses, 1, 'misses 1');
assert.equal(env._templateCache.hits, 0, 'hits 0');
var compiled = env.getTemplate(Compiled, env.owner);
assert.equal(env._templateCache.misses, 2, 'misses 2');
assert.equal(env._templateCache.hits, 0, 'hits 0');
assert.ok(typeof precompiled.spec !== 'string', 'Spec has been parsed');
assert.ok(typeof compiled.spec !== 'string', 'Spec has been parsed');
this.registerComponent('x-precompiled', {
ComponentClass: _helpers.Component.extend({
layout: Precompiled
})
});
this.registerComponent('x-compiled', {
ComponentClass: _helpers.Component.extend({
layout: Compiled
})
});
this.render('{{x-precompiled name="precompiled"}} {{x-compiled name="compiled"}}');
assert.equal(env._templateCache.misses, 2, 'misses 2');
assert.equal(env._templateCache.hits, 2, 'hits 2');
this.assertText('Hello precompiled Hello compiled');
};
return _class;
}(_testCase.RenderingTest));
});
enifed('ember-glimmer/tests/unit/utils/debug-stack-test', ['ember-glimmer/utils/debug-stack'], function () {
'use strict';
});
enifed('ember-glimmer/tests/unit/utils/iterable-test', ['ember-babel', 'ember', 'ember-glimmer/tests/utils/test-case', 'ember-glimmer/utils/iterable', 'ember-glimmer/utils/references', 'ember-glimmer/helpers/each-in', '@glimmer/runtime'], function (_emberBabel, _ember, _testCase, _iterable, _references, _eachIn, _runtime) {
'use strict';
var ITERATOR_KEY_GUID = 'be277757-bbbe-4620-9fcb-213ef433cca2';
(0, _testCase.moduleFor)('Iterable', function (_TestCase) {
(0, _emberBabel.inherits)(_class, _TestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TestCase.apply(this, arguments));
}
_class.prototype['@test iterates over an array'] = function () {
var iterator = iteratorForArray(['foo', 'bar']);
this.assert.deepEqual(iterator.next(), { key: 'foo', memo: 0, value: 'foo' });
this.assert.deepEqual(iterator.next(), { key: 'bar', memo: 1, value: 'bar' });
};
_class.prototype['@test iterates over an `Ember.A`'] = function () {
var iterator = iteratorForArray(_ember.default.A(['foo', 'bar']));
this.assert.deepEqual(iterator.next(), { key: 'foo', memo: 0, value: 'foo' });
this.assert.deepEqual(iterator.next(), { key: 'bar', memo: 1, value: 'bar' });
};
_class.prototype['@test returns `null` when out of items'] = function () {
var iterator = iteratorForArray(['foo']);
this.assert.deepEqual(iterator.next(), { key: 'foo', memo: 0, value: 'foo' });
this.assert.deepEqual(iterator.next(), null);
};
_class.prototype['@test iterates over an array with indices as keys'] = function () {
var iterator = iteratorForArray(['foo', 'bar'], '@index');
this.assert.deepEqual(iterator.next(), { key: '0', memo: 0, value: 'foo' });
this.assert.deepEqual(iterator.next(), { key: '1', memo: 1, value: 'bar' });
};
_class.prototype['@test iterates over an array with identities as keys'] = function () {
var iterator = iteratorForArray(['foo', 'bar'], '@identity');
this.assert.deepEqual(iterator.next(), { key: 'foo', memo: 0, value: 'foo' });
this.assert.deepEqual(iterator.next(), { key: 'bar', memo: 1, value: 'bar' });
};
_class.prototype['@test iterates over an array with arbitrary properties as keys'] = function () {
var iterator = iteratorForArray([{ k: 'first', v: 'foo' }, { k: 'second', v: 'bar' }], 'k');
this.assert.deepEqual(iterator.next(), { key: 'first', memo: 0, value: { k: 'first', v: 'foo' } });
this.assert.deepEqual(iterator.next(), { key: 'second', memo: 1, value: { k: 'second', v: 'bar' } });
};
_class.prototype['@test errors on `#next` with an undefined ref'] = function () {
var iterator = iteratorForArray(undefined),
message;
this.assert.expect(1);
try {
iterator.next();
} catch (_ref) {
message = _ref.message;
this.assert.equal(message, 'Cannot call next() on an empty iterator');
}
};
_class.prototype['@test errors on `#next` with a null ref'] = function () {
var iterator = iteratorForArray(null),
message;
this.assert.expect(1);
try {
iterator.next();
} catch (_ref2) {
message = _ref2.message;
this.assert.equal(message, 'Cannot call next() on an empty iterator');
}
};
_class.prototype['@test errors on `#next` with an invalid ref type'] = function () {
var iterator = iteratorForArray('string'),
message;
this.assert.expect(1);
try {
iterator.next();
} catch (_ref3) {
message = _ref3.message;
this.assert.equal(message, 'Cannot call next() on an empty iterator');
}
};
_class.prototype['@test errors on `#next` with an empty array'] = function () {
var iterator = iteratorForArray([]),
message;
this.assert.expect(1);
try {
iterator.next();
} catch (_ref4) {
message = _ref4.message;
this.assert.equal(message, 'Cannot call next() on an empty iterator');
}
};
_class.prototype['@test iterates over an object\'s own properties'] = function () {
var iterator = iteratorForObject({ first: 'foo', second: 'bar' });
this.assert.deepEqual(iterator.next(), { key: 'first', memo: 'first', value: 'foo' });
this.assert.deepEqual(iterator.next(), { key: 'second', memo: 'second', value: 'bar' });
};
_class.prototype['@test iterates over an object\'s own properties with indices as keys'] = function () {
var iterator = iteratorForObject({ first: 'foo', second: 'bar' }, '@index');
this.assert.deepEqual(iterator.next(), { key: 'first', memo: 'first', value: 'foo' });
this.assert.deepEqual(iterator.next(), { key: 'second', memo: 'second', value: 'bar' });
};
_class.prototype['@test iterates over an object\'s own properties with identities as keys'] = function () {
var iterator = iteratorForObject({ first: 'foo', second: 'bar' }, '@identity');
this.assert.deepEqual(iterator.next(), { key: 'foo', memo: 'first', value: 'foo' });
this.assert.deepEqual(iterator.next(), { key: 'bar', memo: 'second', value: 'bar' });
};
_class.prototype['@test iterates over an object\'s own properties with arbitrary properties as keys'] = function () {
var iterator = iteratorForObject({ first: { k: 'uno', v: 'foo' }, second: { k: 'dos', v: 'bar' } }, 'k');
this.assert.deepEqual(iterator.next(), { key: 'uno', memo: 'first', value: { k: 'uno', v: 'foo' } });
this.assert.deepEqual(iterator.next(), { key: 'dos', memo: 'second', value: { k: 'dos', v: 'bar' } });
};
_class.prototype['@test each-in errors on `#next` with an undefined ref'] = function () {
var iterator = iteratorForObject(undefined),
message;
this.assert.expect(1);
try {
iterator.next();
} catch (_ref5) {
message = _ref5.message;
this.assert.equal(message, 'Cannot call next() on an empty iterator');
}
};
_class.prototype['@test each-in errors on `#next` with a null ref'] = function () {
var iterator = iteratorForObject(null),
message;
this.assert.expect(1);
try {
iterator.next();
} catch (_ref6) {
message = _ref6.message;
this.assert.equal(message, 'Cannot call next() on an empty iterator');
}
};
_class.prototype['@test each-in errors on `#next` with an invalid ref type'] = function () {
var iterator = iteratorForObject('string'),
message;
this.assert.expect(1);
try {
iterator.next();
} catch (_ref7) {
message = _ref7.message;
this.assert.equal(message, 'Cannot call next() on an empty iterator');
}
};
_class.prototype['@test ensures keys are unique'] = function () {
var iterator = iteratorForArray([{ k: 'qux', v: 'foo' }, { k: 'qux', v: 'bar' }, { k: 'qux', v: 'baz' }], 'k');
this.assert.deepEqual(iterator.next(), { key: 'qux', memo: 0, value: { k: 'qux', v: 'foo' } });
this.assert.deepEqual(iterator.next(), { key: 'qux' + ITERATOR_KEY_GUID + '1', memo: 1, value: { k: 'qux', v: 'bar' } });
this.assert.deepEqual(iterator.next(), { key: 'qux' + ITERATOR_KEY_GUID + '2', memo: 2, value: { k: 'qux', v: 'baz' } });
};
return _class;
}(_testCase.TestCase));
function iteratorForArray(arr, keyPath) {
var ref = new _references.UpdatableReference(arr);
var iterable = (0, _iterable.default)(ref, keyPath);
return iterable.iterate();
}
function iteratorForObject(obj, keyPath) {
var positionalArgs = _runtime.EvaluatedPositionalArgs.create([new _references.UpdatableReference(obj)]);
var ref = (0, _eachIn.default)(null, { positional: positionalArgs });
var iterable = (0, _iterable.default)(ref, keyPath);
return iterable.iterate();
}
});
enifed('ember-glimmer/tests/utils/abstract-test-case', ['exports', 'internal-test-helpers'], function (exports, _internalTestHelpers) {
'use strict';
Object.defineProperty(exports, 'TestCase', {
enumerable: true,
get: function () {
return _internalTestHelpers.AbstractTestCase;
}
});
Object.defineProperty(exports, 'applyMixins', {
enumerable: true,
get: function () {
return _internalTestHelpers.applyMixins;
}
});
Object.defineProperty(exports, 'strip', {
enumerable: true,
get: function () {
return _internalTestHelpers.strip;
}
});
});
enifed('ember-glimmer/tests/utils/helpers', ['exports', 'ember-template-compiler', 'ember-glimmer'], function (exports, _emberTemplateCompiler, _emberGlimmer) {
'use strict';
Object.defineProperty(exports, 'compile', {
enumerable: true,
get: function () {
return _emberTemplateCompiler.compile;
}
});
Object.defineProperty(exports, 'precompile', {
enumerable: true,
get: function () {
return _emberTemplateCompiler.precompile;
}
});
Object.defineProperty(exports, 'INVOKE', {
enumerable: true,
get: function () {
return _emberGlimmer.INVOKE;
}
});
Object.defineProperty(exports, 'Helper', {
enumerable: true,
get: function () {
return _emberGlimmer.Helper;
}
});
Object.defineProperty(exports, 'helper', {
enumerable: true,
get: function () {
return _emberGlimmer.helper;
}
});
Object.defineProperty(exports, 'Component', {
enumerable: true,
get: function () {
return _emberGlimmer.Component;
}
});
Object.defineProperty(exports, 'TextArea', {
enumerable: true,
get: function () {
return _emberGlimmer.TextArea;
}
});
Object.defineProperty(exports, 'LinkComponent', {
enumerable: true,
get: function () {
return _emberGlimmer.LinkComponent;
}
});
Object.defineProperty(exports, 'TextField', {
enumerable: true,
get: function () {
return _emberGlimmer.TextField;
}
});
Object.defineProperty(exports, 'InteractiveRender', {
enumerable: true,
get: function () {
return _emberGlimmer.InteractiveRender;
}
});
Object.defineProperty(exports, 'InertRenderer', {
enumerable: true,
get: function () {
return _emberGlimmer.InertRenderer;
}
});
Object.defineProperty(exports, 'htmlSafe', {
enumerable: true,
get: function () {
return _emberGlimmer.htmlSafe;
}
});
Object.defineProperty(exports, 'SafeString', {
enumerable: true,
get: function () {
return _emberGlimmer.SafeString;
}
});
Object.defineProperty(exports, 'DOMChanges', {
enumerable: true,
get: function () {
return _emberGlimmer.DOMChanges;
}
});
Object.defineProperty(exports, 'isHTMLSafe', {
enumerable: true,
get: function () {
return _emberGlimmer.isHTMLSafe;
}
});
});
enifed('ember-glimmer/tests/utils/shared-conditional-tests', ['exports', 'ember-babel', 'ember-utils', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case', 'ember-metal', 'ember-runtime', 'ember-glimmer/tests/utils/helpers'], function (exports, _emberBabel, _emberUtils, _abstractTestCase, _testCase, _emberMetal, _emberRuntime, _helpers) {
'use strict';
exports.IfUnlessWithSyntaxTest = exports.TogglingSyntaxConditionalsTest = exports.IfUnlessHelperTest = exports.TogglingHelperConditionalsTest = exports.TogglingConditionalsTest = exports.ArrayTestCases = exports.ObjectTestCases = exports.BasicConditionalsTest = exports.StableFalsyGenerator = exports.StableTruthyGenerator = exports.FalsyGenerator = exports.TruthyGenerator = undefined;
var _ObjectTestCases, _ArrayTestCases;
var AbstractConditionalsTest = function (_RenderingTest) {
(0, _emberBabel.inherits)(AbstractConditionalsTest, _RenderingTest);
function AbstractConditionalsTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _RenderingTest.apply(this, arguments));
}
AbstractConditionalsTest.prototype.wrapperFor = function (templates) {
return templates.join('');
};
AbstractConditionalsTest.prototype.wrappedTemplateFor = function (options) {
return this.wrapperFor([this.templateFor(options)]);
};
AbstractConditionalsTest.prototype.templateFor = function (_ref) {
var cond = _ref.cond,
truthy = _ref.truthy,
falsy = _ref.falsy;
// e.g. `{{#if ${cond}}}${truthy}{{else}}${falsy}{{/if}}`
throw new Error('Not implemented: `templateFor`');
};
AbstractConditionalsTest.prototype.renderValues = function () {
throw new Error('Not implemented: `renderValues`');
};
(0, _emberBabel.createClass)(AbstractConditionalsTest, [{
key: 'truthyValue',
get: function () {
return true;
}
}, {
key: 'falsyValue',
get: function () {
return false;
}
}]);
return AbstractConditionalsTest;
}(_testCase.RenderingTest);
var AbstractGenerator = function () {
function AbstractGenerator(cases) {
this.cases = cases;
}
/* abstract */
AbstractGenerator.prototype.generate = function () {
throw new Error('Not implemented: `generate`');
};
return AbstractGenerator;
}();
var TruthyGenerator = exports.TruthyGenerator = function (_AbstractGenerator) {
(0, _emberBabel.inherits)(TruthyGenerator, _AbstractGenerator);
function TruthyGenerator() {
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractGenerator.apply(this, arguments));
}
TruthyGenerator.prototype.generate = function (value, idx) {
var _ref2;
return _ref2 = {}, _ref2['@test it should consider ' + JSON.stringify(value) + ' truthy [' + idx + ']'] = function () {
var _this3 = this;
this.renderValues(value);
this.assertText('T1');
this.runTask(function () {
return _this3.rerender();
});
this.assertText('T1');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'cond1', _this3.falsyValue);
});
this.assertText('F1');
this.runTask(function () {
return (0, _emberMetal.set)(_this3.context, 'cond1', value);
});
this.assertText('T1');
}, _ref2;
};
return TruthyGenerator;
}(AbstractGenerator);
var FalsyGenerator = exports.FalsyGenerator = function (_AbstractGenerator2) {
(0, _emberBabel.inherits)(FalsyGenerator, _AbstractGenerator2);
function FalsyGenerator() {
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractGenerator2.apply(this, arguments));
}
FalsyGenerator.prototype.generate = function (value, idx) {
var _ref3;
return _ref3 = {}, _ref3['@test it should consider ' + JSON.stringify(value) + ' falsy [' + idx + ']'] = function () {
var _this5 = this;
this.renderValues(value);
this.assertText('F1');
this.runTask(function () {
return _this5.rerender();
});
this.assertText('F1');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'cond1', _this5.truthyValue);
});
this.assertText('T1');
this.runTask(function () {
return (0, _emberMetal.set)(_this5.context, 'cond1', value);
});
this.assertText('F1');
}, _ref3;
};
return FalsyGenerator;
}(AbstractGenerator);
var StableTruthyGenerator = exports.StableTruthyGenerator = function (_TruthyGenerator) {
(0, _emberBabel.inherits)(StableTruthyGenerator, _TruthyGenerator);
function StableTruthyGenerator() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TruthyGenerator.apply(this, arguments));
}
StableTruthyGenerator.prototype.generate = function (value, idx) {
var _assign;
return (0, _emberUtils.assign)(_TruthyGenerator.prototype.generate.call(this, value, idx), (_assign = {}, _assign['@test it maintains DOM stability when condition changes from ' + value + ' to another truthy value and back [' + idx + ']'] = function () {
var _this7 = this;
this.renderValues(value);
this.assertText('T1');
this.takeSnapshot();
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'cond1', _this7.truthyValue);
});
this.assertText('T1');
this.assertInvariants();
this.runTask(function () {
return (0, _emberMetal.set)(_this7.context, 'cond1', value);
});
this.assertText('T1');
this.assertInvariants();
}, _assign));
};
return StableTruthyGenerator;
}(TruthyGenerator);
var StableFalsyGenerator = exports.StableFalsyGenerator = function (_FalsyGenerator) {
(0, _emberBabel.inherits)(StableFalsyGenerator, _FalsyGenerator);
function StableFalsyGenerator() {
return (0, _emberBabel.possibleConstructorReturn)(this, _FalsyGenerator.apply(this, arguments));
}
StableFalsyGenerator.prototype.generate = function (value, idx) {
var _assign2;
return (0, _emberUtils.assign)(_FalsyGenerator.prototype.generate.call(this, value), (_assign2 = {}, _assign2['@test it maintains DOM stability when condition changes from ' + value + ' to another falsy value and back [' + idx + ']'] = function () {
var _this9 = this;
this.renderValues(value);
this.assertText('F1');
this.takeSnapshot();
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'cond1', _this9.falsyValue);
});
this.assertText('F1');
this.assertInvariants();
this.runTask(function () {
return (0, _emberMetal.set)(_this9.context, 'cond1', value);
});
this.assertText('F1');
this.assertInvariants();
}, _assign2));
};
return StableFalsyGenerator;
}(FalsyGenerator);
var ObjectProxyGenerator = function (_AbstractGenerator3) {
(0, _emberBabel.inherits)(ObjectProxyGenerator, _AbstractGenerator3);
function ObjectProxyGenerator() {
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractGenerator3.apply(this, arguments));
}
ObjectProxyGenerator.prototype.generate = function (value, idx) {
var _ref4, _ref5;
// This is inconsistent with our usual to-bool policy, but the current proxy implementation
// simply uses !!content to determine truthiness
if (value) {
return _ref4 = {}, _ref4['@test it should consider an object proxy with `' + JSON.stringify(value) + '` truthy [' + idx + ']'] = function () {
var _this11 = this;
this.renderValues(_emberRuntime.ObjectProxy.create({ content: value }));
this.assertText('T1');
this.runTask(function () {
return _this11.rerender();
});
this.assertText('T1');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'cond1.content', _this11.falsyValue);
});
this.assertText('F1');
this.runTask(function () {
return (0, _emberMetal.set)(_this11.context, 'cond1', _emberRuntime.ObjectProxy.create({ content: value }));
});
this.assertText('T1');
}, _ref4;
} else {
return _ref5 = {}, _ref5['@test it should consider an object proxy with `' + JSON.stringify(value) + '` falsy [' + idx + ']'] = function () {
var _this12 = this;
this.renderValues(_emberRuntime.ObjectProxy.create({ content: value }));
this.assertText('F1');
this.runTask(function () {
return _this12.rerender();
});
this.assertText('F1');
this.runTask(function () {
return (0, _emberMetal.set)(_this12.context, 'cond1.content', _this12.truthyValue);
});
this.assertText('T1');
this.runTask(function () {
return (0, _emberMetal.set)(_this12.context, 'cond1', _emberRuntime.ObjectProxy.create({ content: value }));
});
this.assertText('F1');
}, _ref5;
}
};
return ObjectProxyGenerator;
}(AbstractGenerator);
var BasicConditionalsTest = exports.BasicConditionalsTest = function (_AbstractConditionals) {
(0, _emberBabel.inherits)(BasicConditionalsTest, _AbstractConditionals);
function BasicConditionalsTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractConditionals.apply(this, arguments));
}
BasicConditionalsTest.prototype['@test it renders the corresponding block based on the conditional'] = function () {
var _this14 = this;
this.renderValues(this.truthyValue, this.falsyValue);
this.assertText('T1F2');
this.runTask(function () {
return _this14.rerender();
});
this.assertText('T1F2');
this.runTask(function () {
return (0, _emberMetal.set)(_this14.context, 'cond1', _this14.falsyValue);
});
this.assertText('F1F2');
this.runTask(function () {
(0, _emberMetal.set)(_this14.context, 'cond1', _this14.truthyValue);
(0, _emberMetal.set)(_this14.context, 'cond2', _this14.truthyValue);
});
this.assertText('T1T2');
this.runTask(function () {
(0, _emberMetal.set)(_this14.context, 'cond1', _this14.truthyValue);
(0, _emberMetal.set)(_this14.context, 'cond2', _this14.falsyValue);
});
this.assertText('T1F2');
};
return BasicConditionalsTest;
}(AbstractConditionalsTest);
// Testing behaviors related to ember objects, object proxies, etc
var ObjectTestCases = exports.ObjectTestCases = (_ObjectTestCases = {}, _ObjectTestCases['@test it considers object proxies without content falsy'] = function () {
var _this15 = this;
this.renderValues(_emberRuntime.ObjectProxy.create({ content: {} }), _emberRuntime.ObjectProxy.create({ content: _emberRuntime.Object.create() }), _emberRuntime.ObjectProxy.create({ content: null }));
this.assertText('T1T2F3');
this.runTask(function () {
return _this15.rerender();
});
this.assertText('T1T2F3');
this.runTask(function () {
(0, _emberMetal.set)(_this15.context, 'cond1.content', null);
(0, _emberMetal.set)(_this15.context, 'cond2.content', null);
});
this.assertText('F1F2F3');
this.runTask(function () {
(0, _emberMetal.set)(_this15.context, 'cond1.content', _emberRuntime.Object.create());
(0, _emberMetal.set)(_this15.context, 'cond2.content', {});
(0, _emberMetal.set)(_this15.context, 'cond3.content', { foo: 'bar' });
});
this.assertText('T1T2T3');
this.runTask(function () {
(0, _emberMetal.set)(_this15.context, 'cond1', _emberRuntime.ObjectProxy.create({ content: {} }));
(0, _emberMetal.set)(_this15.context, 'cond2', _emberRuntime.ObjectProxy.create({ content: _emberRuntime.Object.create() }));
(0, _emberMetal.set)(_this15.context, 'cond3', _emberRuntime.ObjectProxy.create({ content: null }));
});
this.assertText('T1T2F3');
}, _ObjectTestCases);
// Testing behaviors related to arrays and array proxies
var ArrayTestCases = exports.ArrayTestCases = (_ArrayTestCases = {}, _ArrayTestCases['@test it considers empty arrays falsy'] = function () {
var _this16 = this;
this.renderValues((0, _emberRuntime.A)(['hello']), (0, _emberRuntime.A)());
this.assertText('T1F2');
this.runTask(function () {
return _this16.rerender();
});
this.assertText('T1F2');
this.runTask(function () {
return (0, _emberRuntime.removeAt)((0, _emberMetal.get)(_this16.context, 'cond1'), 0);
});
this.assertText('F1F2');
this.runTask(function () {
(0, _emberMetal.get)(_this16.context, 'cond1').pushObject('hello');
(0, _emberMetal.get)(_this16.context, 'cond2').pushObjects([1]);
});
this.assertText('T1T2');
this.runTask(function () {
(0, _emberMetal.set)(_this16.context, 'cond1', (0, _emberRuntime.A)(['hello']));
(0, _emberMetal.set)(_this16.context, 'cond2', (0, _emberRuntime.A)());
});
this.assertText('T1F2');
}, _ArrayTestCases['@test it considers array proxies without content falsy'] = function () {
var _this17 = this;
this.renderValues(_emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(['hello']) }), _emberRuntime.ArrayProxy.create({ content: null }));
this.assertText('T1F2');
this.runTask(function () {
return _this17.rerender();
});
this.assertText('T1F2');
this.runTask(function () {
(0, _emberMetal.set)(_this17.context, 'cond1.content', null);
(0, _emberMetal.set)(_this17.context, 'cond2.content', null);
});
this.assertText('F1F2');
this.runTask(function () {
(0, _emberMetal.set)(_this17.context, 'cond1.content', (0, _emberRuntime.A)(['hello']));
(0, _emberMetal.set)(_this17.context, 'cond2.content', (0, _emberRuntime.A)([1]));
});
this.assertText('T1T2');
this.runTask(function () {
(0, _emberMetal.set)(_this17.context, 'cond1', _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(['hello']) }));
(0, _emberMetal.set)(_this17.context, 'cond2', _emberRuntime.ArrayProxy.create({ content: null }));
});
this.assertText('T1F2');
}, _ArrayTestCases['@test it considers array proxies with empty arrays falsy'] = function () {
var _this18 = this;
this.renderValues(_emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(['hello']) }), _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)() }));
this.assertText('T1F2');
this.runTask(function () {
return _this18.rerender();
});
this.assertText('T1F2');
this.runTask(function () {
return (0, _emberRuntime.removeAt)((0, _emberMetal.get)(_this18.context, 'cond1.content'), 0);
});
this.assertText('F1F2');
this.runTask(function () {
(0, _emberMetal.get)(_this18.context, 'cond1.content').pushObject('hello');
(0, _emberMetal.get)(_this18.context, 'cond2.content').pushObjects([1]);
});
this.assertText('T1T2');
this.runTask(function () {
(0, _emberMetal.set)(_this18.context, 'cond1', _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)(['hello']) }));
(0, _emberMetal.set)(_this18.context, 'cond2', _emberRuntime.ArrayProxy.create({ content: (0, _emberRuntime.A)() }));
});
this.assertText('T1F2');
}, _ArrayTestCases);
var IfUnlessWithTestCases = [new StableTruthyGenerator([true, ' ', 'hello', 'false', 'null', 'undefined', 1, ['hello'], (0, _emberRuntime.A)(['hello']), {}, { foo: 'bar' }, _emberRuntime.Object.create(), _emberRuntime.Object.create({ foo: 'bar' }), _emberRuntime.ObjectProxy.create({ content: true }), Object, function () {},
/*jshint -W053 */
new String('hello'), new String(''), new Boolean(true), new Boolean(false),
/*jshint +W053 */
new Date()]), new StableFalsyGenerator([false, null, undefined, '', 0, [], (0, _emberRuntime.A)(), _emberRuntime.ObjectProxy.create({ content: undefined })]), new ObjectProxyGenerator([true, ' ', 'hello', 'false', 'null', 'undefined', 1, ['hello'], (0, _emberRuntime.A)(['hello']), _emberRuntime.ArrayProxy.create({ content: ['hello'] }), _emberRuntime.ArrayProxy.create({ content: [] }), {}, { foo: 'bar' }, _emberRuntime.Object.create(), _emberRuntime.Object.create({ foo: 'bar' }), _emberRuntime.ObjectProxy.create({ content: true }), _emberRuntime.ObjectProxy.create({ content: undefined }),
/*jshint -W053 */
new String('hello'), new String(''), new Boolean(true), new Boolean(false),
/*jshint +W053 */
new Date(), false, null, undefined, '', 0, [], (0, _emberRuntime.A)()]), ObjectTestCases, ArrayTestCases];
// Testing behaviors shared across the "toggling" conditionals, i.e. {{#if}},
// {{#unless}}, {{#with}}, {{#each}}, {{#each-in}}, (if) and (unless)
var TogglingConditionalsTest = exports.TogglingConditionalsTest = function (_BasicConditionalsTes) {
(0, _emberBabel.inherits)(TogglingConditionalsTest, _BasicConditionalsTes);
function TogglingConditionalsTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _BasicConditionalsTes.apply(this, arguments));
}
return TogglingConditionalsTest;
}(BasicConditionalsTest);
var TogglingHelperConditionalsTest = exports.TogglingHelperConditionalsTest = function (_TogglingConditionals) {
(0, _emberBabel.inherits)(TogglingHelperConditionalsTest, _TogglingConditionals);
function TogglingHelperConditionalsTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingConditionals.apply(this, arguments));
}
TogglingHelperConditionalsTest.prototype.renderValues = function () {
var templates = [],
i;
var context = {};
for (i = 1; i <= arguments.length; i++) {
templates.push(this.templateFor({ cond: 'cond' + i, truthy: 't' + i, falsy: 'f' + i }));
context['t' + i] = 'T' + i;
context['f' + i] = 'F' + i;
context['cond' + i] = arguments.length <= i - 1 ? undefined : arguments[i - 1];
}
var wrappedTemplate = this.wrapperFor(templates);
this.render(wrappedTemplate, context);
};
TogglingHelperConditionalsTest.prototype['@test it has access to the outer scope from both templates'] = function () {
var _this21 = this;
var template = this.wrapperFor([this.templateFor({ cond: 'cond1', truthy: 'truthy', falsy: 'falsy' }), this.templateFor({ cond: 'cond2', truthy: 'truthy', falsy: 'falsy' })]);
this.render(template, { cond1: this.truthyValue, cond2: this.falsyValue, truthy: 'YES', falsy: 'NO' });
this.assertText('YESNO');
this.runTask(function () {
return _this21.rerender();
});
this.assertText('YESNO');
this.runTask(function () {
(0, _emberMetal.set)(_this21.context, 'truthy', 'YASS');
(0, _emberMetal.set)(_this21.context, 'falsy', 'NOPE');
});
this.assertText('YASSNOPE');
this.runTask(function () {
(0, _emberMetal.set)(_this21.context, 'cond1', _this21.falsyValue);
(0, _emberMetal.set)(_this21.context, 'cond2', _this21.truthyValue);
});
this.assertText('NOPEYASS');
this.runTask(function () {
(0, _emberMetal.set)(_this21.context, 'truthy', 'YES');
(0, _emberMetal.set)(_this21.context, 'falsy', 'NO');
(0, _emberMetal.set)(_this21.context, 'cond1', _this21.truthyValue);
(0, _emberMetal.set)(_this21.context, 'cond2', _this21.falsyValue);
});
this.assertText('YESNO');
};
TogglingHelperConditionalsTest.prototype['@test it does not update when the unbound helper is used'] = function () {
var _this22 = this;
var template = this.wrapperFor([this.templateFor({ cond: '(unbound cond1)', truthy: '"T1"', falsy: '"F1"' }), this.templateFor({ cond: '(unbound cond2)', truthy: '"T2"', falsy: '"F2"' })]);
this.render(template, { cond1: this.truthyValue, cond2: this.falsyValue });
this.assertText('T1F2');
this.runTask(function () {
return _this22.rerender();
});
this.assertText('T1F2');
this.runTask(function () {
return (0, _emberMetal.set)(_this22.context, 'cond1', _this22.falsyValue);
});
this.assertText('T1F2');
this.runTask(function () {
(0, _emberMetal.set)(_this22.context, 'cond1', _this22.truthyValue);
(0, _emberMetal.set)(_this22.context, 'cond2', _this22.truthyValue);
});
this.assertText('T1F2');
this.runTask(function () {
(0, _emberMetal.set)(_this22.context, 'cond1', _this22.truthyValue);
(0, _emberMetal.set)(_this22.context, 'cond2', _this22.falsyValue);
});
this.assertText('T1F2');
};
TogglingHelperConditionalsTest.prototype['@test evaluation should be lazy'] = function (assert) {
var _this23 = this;
var truthyEvaluated = void 0;
var falsyEvaluated = void 0;
var withoutEvaluatingTruthy = function (callback) {
truthyEvaluated = false;
callback();
assert.ok(!truthyEvaluated, 'x-truthy is not evaluated');
};
var withoutEvaluatingFalsy = function (callback) {
falsyEvaluated = false;
callback();
assert.ok(!falsyEvaluated, 'x-falsy is not evaluated');
};
this.registerHelper('x-truthy', {
compute: function () {
truthyEvaluated = true;
return 'T';
}
});
this.registerHelper('x-falsy', {
compute: function () {
falsyEvaluated = true;
return 'F';
}
});
var template = this.wrappedTemplateFor({ cond: 'cond', truthy: '(x-truthy)', falsy: '(x-falsy)' });
withoutEvaluatingFalsy(function () {
return _this23.render(template, { cond: _this23.truthyValue });
});
this.assertText('T');
withoutEvaluatingFalsy(function () {
return _this23.runTask(function () {
return _this23.rerender();
});
});
this.assertText('T');
withoutEvaluatingTruthy(function () {
return _this23.runTask(function () {
return (0, _emberMetal.set)(_this23.context, 'cond', _this23.falsyValue);
});
});
this.assertText('F');
withoutEvaluatingTruthy(function () {
return _this23.runTask(function () {
return _this23.rerender();
});
});
this.assertText('F');
withoutEvaluatingFalsy(function () {
return _this23.runTask(function () {
return (0, _emberMetal.set)(_this23.context, 'cond', _this23.truthyValue);
});
});
this.assertText('T');
};
return TogglingHelperConditionalsTest;
}(TogglingConditionalsTest);
var IfUnlessHelperTest = exports.IfUnlessHelperTest = function (_TogglingHelperCondit) {
(0, _emberBabel.inherits)(IfUnlessHelperTest, _TogglingHelperCondit);
function IfUnlessHelperTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingHelperCondit.apply(this, arguments));
}
return IfUnlessHelperTest;
}(TogglingHelperConditionalsTest);
_abstractTestCase.applyMixins.apply(undefined, [IfUnlessHelperTest].concat(IfUnlessWithTestCases));
// Testing behaviors shared across the "toggling" syntatical constructs,
// i.e. {{#if}}, {{#unless}}, {{#with}}, {{#each}} and {{#each-in}}
var TogglingSyntaxConditionalsTest = exports.TogglingSyntaxConditionalsTest = function (_TogglingConditionals2) {
(0, _emberBabel.inherits)(TogglingSyntaxConditionalsTest, _TogglingConditionals2);
function TogglingSyntaxConditionalsTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingConditionals2.apply(this, arguments));
}
TogglingSyntaxConditionalsTest.prototype.renderValues = function () {
var templates = [],
i;
var context = {};
for (i = 1; i <= arguments.length; i++) {
templates.push(this.templateFor({ cond: 'cond' + i, truthy: '{{t}}' + i, falsy: '{{f}}' + i }));
context['cond' + i] = arguments.length <= i - 1 ? undefined : arguments[i - 1];
}
var wrappedTemplate = this.wrapperFor(templates);
this.render(wrappedTemplate, (0, _emberUtils.assign)({ t: 'T', f: 'F' }, context));
};
TogglingSyntaxConditionalsTest.prototype['@test it does not update when the unbound helper is used'] = function () {
var _this26 = this;
var template = '' + this.templateFor({ cond: '(unbound cond1)', truthy: 'T1', falsy: 'F1' }) + this.templateFor({ cond: '(unbound cond2)', truthy: 'T2', falsy: 'F2' });
this.render(template, { cond1: this.truthyValue, cond2: this.falsyValue });
this.assertText('T1F2');
this.runTask(function () {
return _this26.rerender();
});
this.assertText('T1F2');
this.runTask(function () {
return (0, _emberMetal.set)(_this26.context, 'cond1', _this26.falsyValue);
});
this.assertText('T1F2');
this.runTask(function () {
(0, _emberMetal.set)(_this26.context, 'cond1', _this26.truthyValue);
(0, _emberMetal.set)(_this26.context, 'cond2', _this26.truthyValue);
});
this.assertText('T1F2');
this.runTask(function () {
(0, _emberMetal.set)(_this26.context, 'cond1', _this26.truthyValue);
(0, _emberMetal.set)(_this26.context, 'cond2', _this26.falsyValue);
});
this.assertText('T1F2');
};
TogglingSyntaxConditionalsTest.prototype['@test it has access to the outer scope from both templates'] = function () {
var _this27 = this;
var template = this.wrapperFor([this.templateFor({ cond: 'cond1', truthy: '{{truthy}}', falsy: '{{falsy}}' }), this.templateFor({ cond: 'cond2', truthy: '{{truthy}}', falsy: '{{falsy}}' })]);
this.render(template, { cond1: this.truthyValue, cond2: this.falsyValue, truthy: 'YES', falsy: 'NO' });
this.assertText('YESNO');
this.runTask(function () {
return _this27.rerender();
});
this.assertText('YESNO');
this.runTask(function () {
(0, _emberMetal.set)(_this27.context, 'truthy', 'YASS');
(0, _emberMetal.set)(_this27.context, 'falsy', 'NOPE');
});
this.assertText('YASSNOPE');
this.runTask(function () {
(0, _emberMetal.set)(_this27.context, 'cond1', _this27.falsyValue);
(0, _emberMetal.set)(_this27.context, 'cond2', _this27.truthyValue);
});
this.assertText('NOPEYASS');
this.runTask(function () {
(0, _emberMetal.set)(_this27.context, 'truthy', 'YES');
(0, _emberMetal.set)(_this27.context, 'falsy', 'NO');
(0, _emberMetal.set)(_this27.context, 'cond1', _this27.truthyValue);
(0, _emberMetal.set)(_this27.context, 'cond2', _this27.falsyValue);
});
this.assertText('YESNO');
};
TogglingSyntaxConditionalsTest.prototype['@test it updates correctly when enclosing another conditional'] = function () {
var _this28 = this;
// This tests whether the outer conditional tracks its bounds correctly as its inner bounds changes
var inner = this.templateFor({ cond: 'inner', truthy: 'T-inner', falsy: 'F-inner' });
var template = this.wrappedTemplateFor({ cond: 'outer', truthy: inner, falsy: 'F-outer' });
this.render(template, { outer: this.truthyValue, inner: this.truthyValue });
this.assertText('T-inner');
this.runTask(function () {
return _this28.rerender();
});
this.assertText('T-inner');
// Changes the inner bounds
this.runTask(function () {
return (0, _emberMetal.set)(_this28.context, 'inner', _this28.falsyValue);
});
this.assertText('F-inner');
// Now rerender the outer conditional, which require first clearing its bounds
this.runTask(function () {
return (0, _emberMetal.set)(_this28.context, 'outer', _this28.falsyValue);
});
this.assertText('F-outer');
};
TogglingSyntaxConditionalsTest.prototype['@test it updates correctly when enclosing #each'] = function () {
var _this29 = this;
// This tests whether the outer conditional tracks its bounds correctly as its inner bounds changes
var template = this.wrappedTemplateFor({ cond: 'outer', truthy: '{{#each inner as |text|}}{{text}}{{/each}}', falsy: 'F-outer' });
this.render(template, { outer: this.truthyValue, inner: ['inner', '-', 'before'] });
this.assertText('inner-before');
this.runTask(function () {
return _this29.rerender();
});
this.assertText('inner-before');
// Changes the inner bounds
this.runTask(function () {
return (0, _emberMetal.set)(_this29.context, 'inner', ['inner-after']);
});
this.assertText('inner-after');
// Now rerender the outer conditional, which require first clearing its bounds
this.runTask(function () {
return (0, _emberMetal.set)(_this29.context, 'outer', _this29.falsyValue);
});
this.assertText('F-outer');
// Reset
this.runTask(function () {
(0, _emberMetal.set)(_this29.context, 'inner', ['inner-again']);
(0, _emberMetal.set)(_this29.context, 'outer', _this29.truthyValue);
});
this.assertText('inner-again');
// Now clear the inner bounds
this.runTask(function () {
return (0, _emberMetal.set)(_this29.context, 'inner', []);
});
this.assertText('');
// Now rerender the outer conditional, which require first clearing its bounds
this.runTask(function () {
return (0, _emberMetal.set)(_this29.context, 'outer', _this29.falsyValue);
});
this.assertText('F-outer');
};
TogglingSyntaxConditionalsTest.prototype['@test it updates correctly when enclosing triple-curlies'] = function () {
var _this30 = this;
// This tests whether the outer conditional tracks its bounds correctly as its inner bounds changes
var template = this.wrappedTemplateFor({ cond: 'outer', truthy: '{{{inner}}}', falsy: 'F-outer' });
this.render(template, { outer: this.truthyValue, inner: 'inner -before ' });
this.assertText('inner-before');
this.runTask(function () {
return _this30.rerender();
});
this.assertText('inner-before');
// Changes the inner bounds
this.runTask(function () {
return (0, _emberMetal.set)(_this30.context, 'inner', 'inner-after
');
});
this.assertText('inner-after');
// Now rerender the outer conditional, which require first clearing its bounds
this.runTask(function () {
return (0, _emberMetal.set)(_this30.context, 'outer', _this30.falsyValue);
});
this.assertText('F-outer');
};
TogglingSyntaxConditionalsTest.prototype['@test child conditional should not render children if parent conditional becomes false'] = function (assert) {
var _this31 = this;
var childCreated = false;
this.registerComponent('foo-bar', {
template: 'foo-bar',
ComponentClass: _helpers.Component.extend({
init: function () {
this._super.apply(this, arguments);
childCreated = true;
}
})
});
var innerTemplate = this.templateFor({ cond: 'cond2', truthy: '{{foo-bar}}', falsy: '' });
var wrappedTemplate = this.wrappedTemplateFor({ cond: 'cond1', truthy: innerTemplate, falsy: '' });
this.render(wrappedTemplate, { cond1: this.truthyValue, cond2: this.falsyValue });
assert.ok(!childCreated);
this.assertText('');
this.runTask(function () {
return _this31.rerender();
});
assert.ok(!childCreated);
this.assertText('');
this.runTask(function () {
(0, _emberMetal.set)(_this31.context, 'cond2', _this31.truthyValue);
(0, _emberMetal.set)(_this31.context, 'cond1', _this31.falsyValue);
});
assert.ok(!childCreated);
this.assertText('');
this.runTask(function () {
(0, _emberMetal.set)(_this31.context, 'cond2', _this31.falsyValue);
(0, _emberMetal.set)(_this31.context, 'cond1', _this31.truthyValue);
});
assert.ok(!childCreated);
this.assertText('');
};
TogglingSyntaxConditionalsTest.prototype['@test evaluation should be lazy'] = function (assert) {
var _this32 = this;
var truthyEvaluated = void 0;
var falsyEvaluated = void 0;
var withoutEvaluatingTruthy = function (callback) {
truthyEvaluated = false;
callback();
assert.ok(!truthyEvaluated, 'x-truthy is not evaluated');
};
var withoutEvaluatingFalsy = function (callback) {
falsyEvaluated = false;
callback();
assert.ok(!falsyEvaluated, 'x-falsy is not evaluated');
};
this.registerHelper('x-truthy', {
compute: function () {
truthyEvaluated = true;
return 'T';
}
});
this.registerHelper('x-falsy', {
compute: function () {
falsyEvaluated = true;
return 'F';
}
});
var template = this.wrappedTemplateFor({ cond: 'cond', truthy: '{{x-truthy}}', falsy: '{{x-falsy}}' });
withoutEvaluatingFalsy(function () {
return _this32.render(template, { cond: _this32.truthyValue });
});
this.assertText('T');
withoutEvaluatingFalsy(function () {
return _this32.runTask(function () {
return _this32.rerender();
});
});
this.assertText('T');
withoutEvaluatingTruthy(function () {
return _this32.runTask(function () {
return (0, _emberMetal.set)(_this32.context, 'cond', _this32.falsyValue);
});
});
this.assertText('F');
withoutEvaluatingTruthy(function () {
return _this32.runTask(function () {
return _this32.rerender();
});
});
this.assertText('F');
withoutEvaluatingFalsy(function () {
return _this32.runTask(function () {
return (0, _emberMetal.set)(_this32.context, 'cond', _this32.truthyValue);
});
});
this.assertText('T');
};
return TogglingSyntaxConditionalsTest;
}(TogglingConditionalsTest);
var IfUnlessWithSyntaxTest = exports.IfUnlessWithSyntaxTest = function (_TogglingSyntaxCondit) {
(0, _emberBabel.inherits)(IfUnlessWithSyntaxTest, _TogglingSyntaxCondit);
function IfUnlessWithSyntaxTest() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TogglingSyntaxCondit.apply(this, arguments));
}
return IfUnlessWithSyntaxTest;
}(TogglingSyntaxConditionalsTest);
_abstractTestCase.applyMixins.apply(undefined, [IfUnlessWithSyntaxTest].concat(IfUnlessWithTestCases));
});
enifed('ember-glimmer/tests/utils/string-test', ['ember-babel', 'ember-glimmer/tests/utils/helpers', 'ember-glimmer/tests/utils/abstract-test-case', 'ember-glimmer/tests/utils/test-case'], function (_emberBabel, _helpers, _abstractTestCase, _testCase) {
'use strict';
(0, _testCase.moduleFor)('SafeString', function (_TestCase) {
(0, _emberBabel.inherits)(_class, _TestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TestCase.apply(this, arguments));
}
_class.prototype['@test htmlSafe should return an instance of SafeString'] = function () {
var safeString = (0, _helpers.htmlSafe)('you need to be more bold ');
this.assert.ok(safeString instanceof _helpers.SafeString, 'should be a SafeString');
};
_class.prototype['@test htmlSafe should return an empty string for null'] = function () {
var safeString = (0, _helpers.htmlSafe)(null);
this.assert.equal(safeString instanceof _helpers.SafeString, true, 'should be a SafeString');
this.assert.equal(safeString.toString(), '', 'should return an empty string');
};
_class.prototype['@test htmlSafe should return an instance of SafeString'] = function () {
var safeString = (0, _helpers.htmlSafe)();
this.assert.equal(safeString instanceof _helpers.SafeString, true, 'should be a SafeString');
this.assert.equal(safeString.toString(), '', 'should return an empty string');
};
return _class;
}(_abstractTestCase.TestCase));
(0, _testCase.moduleFor)('SafeString isHTMLSafe', function (_TestCase2) {
(0, _emberBabel.inherits)(_class2, _TestCase2);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _TestCase2.apply(this, arguments));
}
_class2.prototype['@test isHTMLSafe should detect SafeString'] = function () {
var safeString = (0, _helpers.htmlSafe)('Emphasize the important things.');
this.assert.ok((0, _helpers.isHTMLSafe)(safeString));
};
_class2.prototype['@test isHTMLSafe should not detect SafeString on primatives'] = function () {
this.assert.notOk((0, _helpers.isHTMLSafe)('Hello World'));
this.assert.notOk((0, _helpers.isHTMLSafe)({}));
this.assert.notOk((0, _helpers.isHTMLSafe)([]));
this.assert.notOk((0, _helpers.isHTMLSafe)(10));
this.assert.notOk((0, _helpers.isHTMLSafe)(null));
};
return _class2;
}(_abstractTestCase.TestCase));
});
enifed('ember-glimmer/tests/utils/test-case', ['exports', 'internal-test-helpers'], function (exports, _internalTestHelpers) {
'use strict';
Object.defineProperty(exports, 'TestCase', {
enumerable: true,
get: function () {
return _internalTestHelpers.AbstractTestCase;
}
});
Object.defineProperty(exports, 'ApplicationTest', {
enumerable: true,
get: function () {
return _internalTestHelpers.ApplicationTestCase;
}
});
Object.defineProperty(exports, 'RenderingTest', {
enumerable: true,
get: function () {
return _internalTestHelpers.RenderingTestCase;
}
});
Object.defineProperty(exports, 'moduleFor', {
enumerable: true,
get: function () {
return _internalTestHelpers.moduleFor;
}
});
});
enifed('ember-glimmer/tests/utils/test-helpers', ['exports', 'internal-test-helpers'], function (exports, _internalTestHelpers) {
'use strict';
Object.defineProperty(exports, 'styles', {
enumerable: true,
get: function () {
return _internalTestHelpers.styles;
}
});
Object.defineProperty(exports, 'classes', {
enumerable: true,
get: function () {
return _internalTestHelpers.classes;
}
});
Object.defineProperty(exports, 'equalTokens', {
enumerable: true,
get: function () {
return _internalTestHelpers.equalTokens;
}
});
Object.defineProperty(exports, 'equalsElement', {
enumerable: true,
get: function () {
return _internalTestHelpers.equalsElement;
}
});
});
enifed('ember-metal/tests/accessors/get_path_test', ['ember-metal'], function (_emberMetal) {
'use strict';
var obj = void 0;
QUnit.module('Ember.get with path', {
setup: function () {
obj = {
foo: {
bar: {
baz: { biff: 'BIFF' }
}
},
foothis: {
bar: {
baz: { biff: 'BIFF' }
}
},
falseValue: false,
emptyString: '',
Wuz: {
nar: 'foo'
},
nullValue: null
};
},
teardown: function () {
obj = undefined;
}
});
// ..........................................................
// LOCAL PATHS
//
QUnit.test('[obj, foo] -> obj.foo', function () {
deepEqual((0, _emberMetal.get)(obj, 'foo'), obj.foo);
});
QUnit.test('[obj, foo.bar] -> obj.foo.bar', function () {
deepEqual((0, _emberMetal.get)(obj, 'foo.bar'), obj.foo.bar);
});
QUnit.test('[obj, foothis.bar] -> obj.foothis.bar', function () {
deepEqual((0, _emberMetal.get)(obj, 'foothis.bar'), obj.foothis.bar);
});
QUnit.test('[obj, falseValue.notDefined] -> (undefined)', function () {
strictEqual((0, _emberMetal.get)(obj, 'falseValue.notDefined'), undefined);
});
QUnit.test('[obj, emptyString.length] -> 0', function () {
strictEqual((0, _emberMetal.get)(obj, 'emptyString.length'), 0);
});
QUnit.test('[obj, nullValue.notDefined] -> (undefined)', function () {
strictEqual((0, _emberMetal.get)(obj, 'nullValue.notDefined'), undefined);
});
// ..........................................................
// GLOBAL PATHS TREATED LOCAL WITH GET
//
QUnit.test('[obj, Wuz] -> obj.Wuz', function () {
deepEqual((0, _emberMetal.get)(obj, 'Wuz'), obj.Wuz);
});
QUnit.test('[obj, Wuz.nar] -> obj.Wuz.nar', function () {
deepEqual((0, _emberMetal.get)(obj, 'Wuz.nar'), obj.Wuz.nar);
});
QUnit.test('[obj, Foo] -> (undefined)', function () {
strictEqual((0, _emberMetal.get)(obj, 'Foo'), undefined);
});
QUnit.test('[obj, Foo.bar] -> (undefined)', function () {
strictEqual((0, _emberMetal.get)(obj, 'Foo.bar'), undefined);
});
});
enifed('ember-metal/tests/accessors/get_properties_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.getProperties');
QUnit.test('can retrieve a hash of properties from an object via an argument list or array of property names', function () {
var obj = {
firstName: 'Steve',
lastName: 'Jobs',
companyName: 'Apple, Inc.'
};
deepEqual((0, _emberMetal.getProperties)(obj, 'firstName', 'lastName'), { firstName: 'Steve', lastName: 'Jobs' });
deepEqual((0, _emberMetal.getProperties)(obj, 'firstName', 'lastName'), { firstName: 'Steve', lastName: 'Jobs' });
deepEqual((0, _emberMetal.getProperties)(obj, 'lastName'), { lastName: 'Jobs' });
deepEqual((0, _emberMetal.getProperties)(obj), {});
deepEqual((0, _emberMetal.getProperties)(obj, ['firstName', 'lastName']), { firstName: 'Steve', lastName: 'Jobs' });
deepEqual((0, _emberMetal.getProperties)(obj, ['firstName']), { firstName: 'Steve' });
deepEqual((0, _emberMetal.getProperties)(obj, []), {});
});
});
enifed('ember-metal/tests/accessors/get_test', ['internal-test-helpers', 'ember-metal'], function (_internalTestHelpers, _emberMetal) {
'use strict';
QUnit.module('Ember.get');
QUnit.test('should get arbitrary properties on an object', function () {
var obj = {
string: 'string',
number: 23,
boolTrue: true,
boolFalse: false,
nullValue: null
};
for (var key in obj) {
if (!obj.hasOwnProperty(key)) {
continue;
}
equal((0, _emberMetal.get)(obj, key), obj[key], key);
}
});
QUnit.test('should not access a property more than once', function () {
var count = 0;
var obj = {
get id() {
return ++count;
}
};
(0, _emberMetal.get)(obj, 'id');
equal(count, 1);
});
(0, _internalTestHelpers.testBoth)('should call unknownProperty on watched values if the value is undefined', function (get) {
var obj = {
count: 0,
unknownProperty: function (key) {
equal(key, 'foo', 'should pass key');
this.count++;
return 'FOO';
}
};
var count = 0;
(0, _emberMetal.addObserver)(obj, 'foo', function () {
count++;
});
equal(get(obj, 'foo'), 'FOO', 'should return value from unknown');
});
QUnit.test('warn on attemps to call get with no arguments', function () {
expectAssertion(function () {
(0, _emberMetal.get)('aProperty');
}, /Get must be called with two arguments;/i);
});
QUnit.test('warn on attemps to call get with only one argument', function () {
expectAssertion(function () {
(0, _emberMetal.get)('aProperty');
}, /Get must be called with two arguments;/i);
});
QUnit.test('warn on attemps to call get with more then two arguments', function () {
expectAssertion(function () {
(0, _emberMetal.get)({}, 'aProperty', true);
}, /Get must be called with two arguments;/i);
});
QUnit.test('warn on attempts to get a property of undefined', function () {
expectAssertion(function () {
(0, _emberMetal.get)(undefined, 'aProperty');
}, /Cannot call get with 'aProperty' on an undefined object/i);
});
QUnit.test('warn on attempts to get a property path of undefined', function () {
expectAssertion(function () {
(0, _emberMetal.get)(undefined, 'aProperty.on.aPath');
}, /Cannot call get with 'aProperty.on.aPath' on an undefined object/);
});
QUnit.test('warn on attempts to get a property of null', function () {
expectAssertion(function () {
(0, _emberMetal.get)(null, 'aProperty');
}, /Cannot call get with 'aProperty' on an undefined object/);
});
QUnit.test('warn on attempts to get a property path of null', function () {
expectAssertion(function () {
(0, _emberMetal.get)(null, 'aProperty.on.aPath');
}, /Cannot call get with 'aProperty.on.aPath' on an undefined object/);
});
QUnit.test('warn on attempts to use get with an unsupported property path', function () {
var obj = {};
expectAssertion(function () {
return (0, _emberMetal.get)(obj, null);
}, /The key provided to get must be a string, you passed null/);
expectAssertion(function () {
return (0, _emberMetal.get)(obj, NaN);
}, /The key provided to get must be a string, you passed NaN/);
expectAssertion(function () {
return (0, _emberMetal.get)(obj, undefined);
}, /The key provided to get must be a string, you passed undefined/);
expectAssertion(function () {
return (0, _emberMetal.get)(obj, false);
}, /The key provided to get must be a string, you passed false/);
expectAssertion(function () {
return (0, _emberMetal.get)(obj, 42);
}, /The key provided to get must be a string, you passed 42/);
expectAssertion(function () {
return (0, _emberMetal.get)(obj, '');
}, /Cannot call `Ember.get` with an empty string/);
});
// ..........................................................
// BUGS
//
QUnit.test('(regression) watched properties on unmodified inherited objects should still return their original value', function () {
var MyMixin = _emberMetal.Mixin.create({
someProperty: 'foo',
propertyDidChange: (0, _emberMetal.observer)('someProperty', function () {})
});
var baseObject = MyMixin.apply({});
var theRealObject = Object.create(baseObject);
equal((0, _emberMetal.get)(theRealObject, 'someProperty'), 'foo', 'should return the set value, not false');
});
QUnit.module('Ember.getWithDefault');
QUnit.test('should get arbitrary properties on an object', function () {
var obj = {
string: 'string',
number: 23,
boolTrue: true,
boolFalse: false,
nullValue: null
};
for (var key in obj) {
if (!obj.hasOwnProperty(key)) {
continue;
}
equal((0, _emberMetal.getWithDefault)(obj, key, 'fail'), obj[key], key);
}
obj = {
undef: undefined
};
equal((0, _emberMetal.getWithDefault)(obj, 'undef', 'default'), 'default', 'explicit undefined retrieves the default');
equal((0, _emberMetal.getWithDefault)(obj, 'not-present', 'default'), 'default', 'non-present key retrieves the default');
});
QUnit.test('should call unknownProperty if defined and value is undefined', function () {
var obj = {
count: 0,
unknownProperty: function (key) {
equal(key, 'foo', 'should pass key');
this.count++;
return 'FOO';
}
};
equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should return value from unknown');
equal(obj.count, 1, 'should have invoked');
});
(0, _internalTestHelpers.testBoth)('if unknownProperty is present, it is called', function () {
var obj = {
count: 0,
unknownProperty: function (key) {
if (key === 'foo') {
equal(key, 'foo', 'should pass key');
this.count++;
return 'FOO';
}
}
};
var count = 0;
(0, _emberMetal.addObserver)(obj, 'foo', function () {
return count++;
});
equal((0, _emberMetal.getWithDefault)(obj, 'foo', 'fail'), 'FOO', 'should return value from unknownProperty');
equal((0, _emberMetal.getWithDefault)(obj, 'bar', 'default'), 'default', 'should convert undefined from unknownProperty into default');
});
// ..........................................................
// BUGS
//
QUnit.test('(regression) watched properties on unmodified inherited objects should still return their original value', function () {
var MyMixin = _emberMetal.Mixin.create({
someProperty: 'foo',
propertyDidChange: (0, _emberMetal.observer)('someProperty', function () {/* nothing to do */})
});
var baseObject = MyMixin.apply({});
var theRealObject = Object.create(baseObject);
equal((0, _emberMetal.getWithDefault)(theRealObject, 'someProperty', 'fail'), 'foo', 'should return the set value, not false');
});
});
enifed('ember-metal/tests/accessors/is_global_path_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.isGlobalPath');
QUnit.test('global path\'s are recognized', function () {
ok((0, _emberMetal.isGlobalPath)('App.myProperty'));
ok((0, _emberMetal.isGlobalPath)('App.myProperty.subProperty'));
});
QUnit.test('if there is a \'this\' in the path, it\'s not a global path', function () {
ok(!(0, _emberMetal.isGlobalPath)('this.myProperty'));
ok(!(0, _emberMetal.isGlobalPath)('this'));
});
QUnit.test('if the path starts with a lowercase character, it is not a global path', function () {
ok(!(0, _emberMetal.isGlobalPath)('myObj'));
ok(!(0, _emberMetal.isGlobalPath)('myObj.SecondProperty'));
});
});
enifed('ember-metal/tests/accessors/mandatory_setters_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('mandatory-setters');
});
enifed('ember-metal/tests/accessors/set_path_test', ['ember-environment', 'ember-metal'], function (_emberEnvironment, _emberMetal) {
'use strict';
var originalLookup = _emberEnvironment.context.lookup;
var lookup = void 0;
var obj = void 0;
function commonSetup() {
_emberEnvironment.context.lookup = lookup = {};
obj = {
foo: {
bar: {
baz: { biff: 'BIFF' }
}
}
};
}
function commonTeardown() {
_emberEnvironment.context.lookup = originalLookup;
obj = null;
}
QUnit.module('set with path', {
setup: commonSetup,
teardown: commonTeardown
});
QUnit.test('[Foo, bar] -> Foo.bar', function () {
lookup.Foo = {
toString: function () {
return 'Foo';
}
}; // Behave like an Ember.Namespace
(0, _emberMetal.set)(lookup.Foo, 'bar', 'baz');
equal((0, _emberMetal.get)(lookup.Foo, 'bar'), 'baz');
});
// ..........................................................
//
// LOCAL PATHS
QUnit.test('[obj, foo] -> obj.foo', function () {
(0, _emberMetal.set)(obj, 'foo', 'BAM');
equal((0, _emberMetal.get)(obj, 'foo'), 'BAM');
});
QUnit.test('[obj, foo.bar] -> obj.foo.bar', function () {
(0, _emberMetal.set)(obj, 'foo.bar', 'BAM');
equal((0, _emberMetal.get)(obj, 'foo.bar'), 'BAM');
});
// ..........................................................
// DEPRECATED
//
QUnit.module('set with path - deprecated', {
setup: commonSetup,
teardown: commonTeardown
});
QUnit.test('[obj, bla.bla] gives a proper exception message', function () {
try {
(0, _emberMetal.set)(obj, 'bla.bla', 'BAM');
} catch (ex) {
equal(ex.message, 'Property set failed: object in path \"bla\" could not be found or was destroyed.');
}
});
QUnit.test('[obj, foo.baz.bat] -> EXCEPTION', function () {
throws(function () {
return (0, _emberMetal.set)(obj, 'foo.baz.bat', 'BAM');
});
});
QUnit.test('[obj, foo.baz.bat] -> EXCEPTION', function () {
(0, _emberMetal.trySet)(obj, 'foo.baz.bat', 'BAM');
ok(true, 'does not raise');
});
});
enifed('ember-metal/tests/accessors/set_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('set', {
teardown: function () {
(0, _emberMetal.setHasViews)(function () {
return false;
});
}
});
QUnit.test('should set arbitrary properties on an object', function () {
var obj = {
string: 'string',
number: 23,
boolTrue: true,
boolFalse: false,
nullValue: null,
undefinedValue: undefined
};
var newObj = {
undefinedValue: 'emberjs'
};
for (var key in obj) {
if (!obj.hasOwnProperty(key)) {
continue;
}
equal((0, _emberMetal.set)(newObj, key, obj[key]), obj[key], 'should return value');
equal((0, _emberMetal.get)(newObj, key), obj[key], 'should set value');
}
});
QUnit.test('should call setUnknownProperty if defined and value is undefined', function () {
var obj = {
count: 0,
unknownProperty: function () {
ok(false, 'should not invoke unknownProperty if setUnknownProperty is defined');
},
setUnknownProperty: function (key, value) {
equal(key, 'foo', 'should pass key');
equal(value, 'BAR', 'should pass key');
this.count++;
return 'FOO';
}
};
equal((0, _emberMetal.set)(obj, 'foo', 'BAR'), 'BAR', 'should return set value');
equal(obj.count, 1, 'should have invoked');
});
QUnit.test('warn on attempts to call set with undefined as object', function () {
expectAssertion(function () {
return (0, _emberMetal.set)(undefined, 'aProperty', 'BAM');
}, /Cannot call set with 'aProperty' on an undefined object./);
});
QUnit.test('warn on attempts to call set with null as object', function () {
expectAssertion(function () {
return (0, _emberMetal.set)(null, 'aProperty', 'BAM');
}, /Cannot call set with 'aProperty' on an undefined object./);
});
QUnit.test('warn on attempts to use set with an unsupported property path', function () {
var obj = {};
expectAssertion(function () {
return (0, _emberMetal.set)(obj, null, 42);
}, /The key provided to set must be a string, you passed null/);
expectAssertion(function () {
return (0, _emberMetal.set)(obj, NaN, 42);
}, /The key provided to set must be a string, you passed NaN/);
expectAssertion(function () {
return (0, _emberMetal.set)(obj, undefined, 42);
}, /The key provided to set must be a string, you passed undefined/);
expectAssertion(function () {
return (0, _emberMetal.set)(obj, false, 42);
}, /The key provided to set must be a string, you passed false/);
expectAssertion(function () {
return (0, _emberMetal.set)(obj, 42, 42);
}, /The key provided to set must be a string, you passed 42/);
});
QUnit.test('warn on attempts of calling set on a destroyed object', function () {
var obj = { isDestroyed: true };
expectAssertion(function () {
return (0, _emberMetal.set)(obj, 'favoriteFood', 'hot dogs');
}, 'calling set on destroyed object: [object Object].favoriteFood = hot dogs');
});
QUnit.test('does not trigger auto-run assertion for objects that have not been tagged', function (assert) {
(0, _emberMetal.setHasViews)(function () {
return true;
});
var obj = {};
(0, _emberMetal.set)(obj, 'foo', 'bar');
assert.equal(obj.foo, 'bar');
});
});
enifed('ember-metal/tests/alias_test', ['ember-metal'], function (_emberMetal) {
'use strict';
var obj = void 0,
count = void 0;
QUnit.module('ember-metal/alias', {
setup: function () {
obj = { foo: { faz: 'FOO' } };
count = 0;
},
teardown: function () {
obj = null;
}
});
function incrementCount() {
count++;
}
QUnit.test('should proxy get to alt key', function () {
(0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('foo.faz'));
equal((0, _emberMetal.get)(obj, 'bar'), 'FOO');
});
QUnit.test('should proxy set to alt key', function () {
(0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('foo.faz'));
(0, _emberMetal.set)(obj, 'bar', 'BAR');
equal((0, _emberMetal.get)(obj, 'foo.faz'), 'BAR');
});
QUnit.test('old dependent keys should not trigger property changes', function () {
var obj1 = Object.create(null);
(0, _emberMetal.defineProperty)(obj1, 'foo', null, null);
(0, _emberMetal.defineProperty)(obj1, 'bar', (0, _emberMetal.alias)('foo'));
(0, _emberMetal.defineProperty)(obj1, 'baz', (0, _emberMetal.alias)('foo'));
(0, _emberMetal.defineProperty)(obj1, 'baz', (0, _emberMetal.alias)('bar')); // redefine baz
(0, _emberMetal.addObserver)(obj1, 'baz', incrementCount);
(0, _emberMetal.set)(obj1, 'foo', 'FOO');
equal(count, 1);
(0, _emberMetal.removeObserver)(obj1, 'baz', incrementCount);
(0, _emberMetal.set)(obj1, 'foo', 'OOF');
equal(count, 1);
});
QUnit.test('inheriting an observer of the alias from the prototype then\n redefining the alias on the instance to another property dependent on same key\n does not call the observer twice', function () {
var obj1 = Object.create(null);
(0, _emberMetal.meta)(obj1).proto = obj1;
(0, _emberMetal.defineProperty)(obj1, 'foo', null, null);
(0, _emberMetal.defineProperty)(obj1, 'bar', (0, _emberMetal.alias)('foo'));
(0, _emberMetal.defineProperty)(obj1, 'baz', (0, _emberMetal.alias)('foo'));
(0, _emberMetal.addObserver)(obj1, 'baz', incrementCount);
var obj2 = Object.create(obj1);
(0, _emberMetal.defineProperty)(obj2, 'baz', (0, _emberMetal.alias)('bar')); // override baz
(0, _emberMetal.set)(obj2, 'foo', 'FOO');
equal(count, 1);
(0, _emberMetal.removeObserver)(obj2, 'baz', incrementCount);
(0, _emberMetal.set)(obj2, 'foo', 'OOF');
equal(count, 1);
});
QUnit.test('an observer of the alias works if added after defining the alias', function () {
(0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('foo.faz'));
(0, _emberMetal.addObserver)(obj, 'bar', incrementCount);
ok((0, _emberMetal.isWatching)(obj, 'foo.faz'));
(0, _emberMetal.set)(obj, 'foo.faz', 'BAR');
equal(count, 1);
});
QUnit.test('an observer of the alias works if added before defining the alias', function () {
(0, _emberMetal.addObserver)(obj, 'bar', incrementCount);
(0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('foo.faz'));
ok((0, _emberMetal.isWatching)(obj, 'foo.faz'));
(0, _emberMetal.set)(obj, 'foo.faz', 'BAR');
equal(count, 1);
});
QUnit.test('object with alias is dirtied if interior object of alias is set after consumption', function () {
(0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('foo.faz'));
(0, _emberMetal.get)(obj, 'bar');
assertDirty(obj, function () {
return (0, _emberMetal.set)(obj, 'foo.faz', 'BAR');
}, 'setting the aliased key should dirty the object');
});
QUnit.test('setting alias on self should fail assertion', function () {
expectAssertion(function () {
return (0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.alias)('bar'));
}, 'Setting alias \'bar\' on self');
});
function assertDirty(obj, callback, label) {
var tag = (0, _emberMetal.tagFor)(obj);
var tagValue = tag.value();
callback();
ok(!tag.validate(tagValue), label);
}
});
enifed('ember-metal/tests/binding/connect_test', ['ember-environment', 'internal-test-helpers', 'ember-metal'], function (_emberEnvironment, _internalTestHelpers, _emberMetal) {
'use strict';
function performTest(binding, a, b, get, set, connect) {
if (connect === undefined) {
connect = function () {
return binding.connect(a);
};
}
ok(!_emberMetal.run.currentRunLoop, 'performTest should not have a currentRunLoop');
equal(get(a, 'foo'), 'FOO', 'a should not have changed');
equal(get(b, 'bar'), 'BAR', 'b should not have changed');
connect();
equal(get(a, 'foo'), 'BAR', 'a should have changed');
equal(get(b, 'bar'), 'BAR', 'b should have changed');
//
// make sure changes sync both ways
(0, _emberMetal.run)(function () {
return set(b, 'bar', 'BAZZ');
});
equal(get(a, 'foo'), 'BAZZ', 'a should have changed');
(0, _emberMetal.run)(function () {
return set(a, 'foo', 'BARF');
});
equal(get(b, 'bar'), 'BARF', 'a should have changed');
}
var originalLookup = void 0,
lookup = void 0,
GlobalB = void 0;
QUnit.module('Ember.Binding', {
setup: function () {
originalLookup = _emberEnvironment.context.lookup;
_emberEnvironment.context.lookup = lookup = {};
},
teardown: function () {
lookup = null;
_emberEnvironment.context.lookup = originalLookup;
}
});
(0, _internalTestHelpers.testBoth)('Connecting a binding between two properties', function (get, set) {
var a = { foo: 'FOO', bar: 'BAR' };
// a.bar -> a.foo
var binding = new _emberMetal.Binding('foo', 'bar');
expectDeprecation(function () {
performTest(binding, a, a, get, set);
}, /`Ember\.Binding` is deprecated./);
});
(0, _internalTestHelpers.testBoth)('Connecting a oneWay binding raises a deprecation', function () {
var a = { foo: 'FOO', bar: 'BAR', toString: function () {
return '';
}
};
// a.bar -> a.foo
var binding = new _emberMetal.Binding('foo', 'bar').oneWay();
expectDeprecation(function () {
binding.connect(a);
}, /`Ember.Binding` is deprecated/);
});
(0, _internalTestHelpers.testBoth)('Connecting a binding between two objects', function (get, set) {
var b = { bar: 'BAR' };
var a = { foo: 'FOO', b: b };
// b.bar -> a.foo
var binding = new _emberMetal.Binding('foo', 'b.bar');
expectDeprecation(function () {
performTest(binding, a, b, get, set);
}, /`Ember\.Binding` is deprecated./);
});
(0, _internalTestHelpers.testBoth)('Connecting a binding to path', function (get, set) {
var a = { foo: 'FOO' };
lookup['GlobalB'] = GlobalB = {
b: { bar: 'BAR' }
};
var b = get(GlobalB, 'b');
// globalB.b.bar -> a.foo
var binding = new _emberMetal.Binding('foo', 'GlobalB.b.bar');
expectDeprecation(function () {
performTest(binding, a, b, get, set);
}, /`Ember\.Binding` is deprecated./);
// make sure modifications update
b = { bar: 'BIFF' };
(0, _emberMetal.run)(function () {
return set(GlobalB, 'b', b);
});
equal(get(a, 'foo'), 'BIFF', 'a should have changed');
});
(0, _internalTestHelpers.testBoth)('Calling connect more than once', function (get, set) {
var b = { bar: 'BAR' };
var a = { foo: 'FOO', b: b };
// b.bar -> a.foo
var binding = new _emberMetal.Binding('foo', 'b.bar');
expectDeprecation(function () {
performTest(binding, a, b, get, set, function () {
binding.connect(a);
binding.connect(a);
});
}, /`Ember\.Binding` is deprecated./);
});
QUnit.test('inherited bindings should sync on create', function () {
var a = void 0;
(0, _emberMetal.run)(function () {
function A() {
(0, _emberMetal.bind)(this, 'foo', 'bar.baz');
}
expectDeprecation(function () {
return a = new A();
}, /`Ember\.Binding` is deprecated/);
(0, _emberMetal.set)(a, 'bar', { baz: 'BAZ' });
});
equal((0, _emberMetal.get)(a, 'foo'), 'BAZ', 'should have synced binding on new obj');
});
});
enifed('ember-metal/tests/binding/sync_test', ['internal-test-helpers', 'ember-metal'], function (_internalTestHelpers, _emberMetal) {
'use strict';
QUnit.module('system/binding/sync_test.js');
(0, _internalTestHelpers.testBoth)('bindings should not sync twice in a single run loop', function (get, set) {
var a = void 0,
b = void 0,
setValue = void 0;
var setCalled = 0;
var getCalled = 0;
(0, _emberMetal.run)(function () {
a = {};
(0, _emberMetal.defineProperty)(a, 'foo', (0, _emberMetal.computed)({
get: function () {
getCalled++;
return setValue;
},
set: function (key, value) {
setCalled++;
(0, _emberMetal.propertyWillChange)(this, key);
setValue = value;
(0, _emberMetal.propertyDidChange)(this, key);
return value;
}
}).volatile());
b = {
a: a
};
expectDeprecation(function () {
return (0, _emberMetal.bind)(b, 'foo', 'a.foo');
}, /`Ember.Binding` is deprecated/);
});
// reset after initial binding synchronization
getCalled = 0;
(0, _emberMetal.run)(function () {
set(a, 'foo', 'trollface');
});
equal(get(b, 'foo'), 'trollface', 'the binding should sync');
equal(setCalled, 1, 'Set should only be called once');
equal(getCalled, 1, 'Get should only be called once');
});
(0, _internalTestHelpers.testBoth)('bindings should not infinite loop if computed properties return objects', function (get) {
var a = void 0,
b = void 0;
var getCalled = 0;
(0, _emberMetal.run)(function () {
a = {};
(0, _emberMetal.defineProperty)(a, 'foo', (0, _emberMetal.computed)(function () {
getCalled++;
if (getCalled > 1000) {
throw 'infinite loop detected';
}
return ['foo', 'bar'];
}));
b = {
a: a
};
expectDeprecation(function () {
return (0, _emberMetal.bind)(b, 'foo', 'a.foo');
}, /`Ember.Binding` is deprecated/);
});
deepEqual(get(b, 'foo'), ['foo', 'bar'], 'the binding should sync');
equal(getCalled, 1, 'Get should only be called once');
});
(0, _internalTestHelpers.testBoth)('bindings should do the right thing when observers trigger bindings in the opposite direction', function (get, set) {
var a = void 0,
b = void 0,
c = void 0;
(0, _emberMetal.run)(function () {
a = {
foo: 'trololol'
};
b = {
a: a
};
var deprecationMessage = /`Ember.Binding` is deprecated/;
expectDeprecation(function () {
return (0, _emberMetal.bind)(b, 'foo', 'a.foo');
}, deprecationMessage);
c = {
a: a
};
expectDeprecation(function () {
(0, _emberMetal.bind)(c, 'foo', 'a.foo');
}, deprecationMessage);
});
(0, _emberMetal.addObserver)(b, 'foo', function () {
return set(c, 'foo', 'what is going on');
});
(0, _emberMetal.run)(function () {
return set(a, 'foo', 'trollface');
});
equal(get(a, 'foo'), 'what is going on');
});
(0, _internalTestHelpers.testBoth)('bindings should not try to sync destroyed objects', function (get, set) {
var a = void 0,
b = void 0;
(0, _emberMetal.run)(function () {
a = {
foo: 'trololol'
};
b = {
a: a
};
var deprecationMessage = /`Ember.Binding` is deprecated/;
expectDeprecation(function () {
return (0, _emberMetal.bind)(b, 'foo', 'a.foo');
}, deprecationMessage);
});
(0, _emberMetal.run)(function () {
set(a, 'foo', 'trollface');
set(b, 'isDestroyed', true);
ok(true, 'should not raise');
});
(0, _emberMetal.run)(function () {
a = {
foo: 'trololol'
};
b = {
a: a
};
var deprecationMessage = /`Ember.Binding` is deprecated/;
expectDeprecation(function () {
return (0, _emberMetal.bind)(b, 'foo', 'a.foo');
}, deprecationMessage);
});
(0, _emberMetal.run)(function () {
set(b, 'foo', 'trollface');
set(a, 'isDestroyed', true);
ok(true, 'should not raise');
});
});
});
enifed('ember-metal/tests/cache_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Cache');
QUnit.test('basic', function () {
var cache = new _emberMetal.Cache(100, function (key) {
return key.toUpperCase();
});
equal(cache.get('foo'), 'FOO');
equal(cache.get('bar'), 'BAR');
equal(cache.get('foo'), 'FOO');
});
QUnit.test('explicit sets', function () {
var cache = new _emberMetal.Cache(100, function (key) {
return key.toUpperCase();
});
equal(cache.get('foo'), 'FOO');
equal(cache.set('foo', 'FOO!!!'), 'FOO!!!');
equal(cache.get('foo'), 'FOO!!!');
strictEqual(cache.set('foo', undefined), undefined);
strictEqual(cache.get('foo'), undefined);
});
QUnit.test('caches computation correctly', function () {
var count = 0;
var cache = new _emberMetal.Cache(100, function (key) {
count++;
return key.toUpperCase();
});
equal(count, 0);
cache.get('foo');
equal(count, 1);
cache.get('bar');
equal(count, 2);
cache.get('bar');
equal(count, 2);
cache.get('foo');
equal(count, 2);
});
QUnit.test('caches computation correctly with custom cache keys', function () {
var count = 0;
var cache = new _emberMetal.Cache(100, function (obj) {
count++;
return obj.value.toUpperCase();
}, function (obj) {
return obj.key;
});
equal(count, 0);
cache.get({ key: 'foo', value: 'foo' });
equal(count, 1);
cache.get({ key: 'bar', value: 'bar' });
equal(count, 2);
cache.get({ key: 'bar', value: 'bar' });
equal(count, 2);
cache.get({ key: 'foo', value: 'foo' });
equal(count, 2);
});
QUnit.test('handles undefined value correctly', function () {
var count = 0;
var cache = new _emberMetal.Cache(100, function () {
count++;
});
equal(count, 0);
strictEqual(cache.get('foo'), undefined);
equal(count, 1);
strictEqual(cache.get('bar'), undefined);
equal(count, 2);
strictEqual(cache.get('bar'), undefined);
equal(count, 2);
strictEqual(cache.get('foo'), undefined);
equal(count, 2);
});
QUnit.test('continues working after reaching cache limit', function () {
var cache = new _emberMetal.Cache(3, function (key) {
return key.toUpperCase();
});
cache.get('a');
cache.get('b');
cache.get('c');
equal(cache.get('d'), 'D');
equal(cache.get('a'), 'A');
equal(cache.get('b'), 'B');
equal(cache.get('c'), 'C');
});
});
enifed('ember-metal/tests/chains_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Chains');
QUnit.test('finishChains should properly copy chains from prototypes to instances', function () {
var obj = {};
(0, _emberMetal.addObserver)(obj, 'foo.bar', null, function () {});
var childObj = Object.create(obj);
var parentMeta = (0, _emberMetal.meta)(obj);
var childMeta = (0, _emberMetal.meta)(childObj);
(0, _emberMetal.finishChains)(childMeta);
ok(parentMeta.readableChains() !== childMeta.readableChains(), 'The chains object is copied');
});
QUnit.test('does not observe primitive values', function (assert) {
var obj = {
foo: { bar: 'STRING' }
};
(0, _emberMetal.addObserver)(obj, 'foo.bar.baz', null, function () {});
var meta = (0, _emberMetal.peekMeta)(obj);
assert.notOk(meta._object);
});
QUnit.test('observer and CP chains', function () {
var obj = {};
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)('qux.[]', function () {}));
(0, _emberMetal.defineProperty)(obj, 'qux', (0, _emberMetal.computed)(function () {}));
// create DK chains
(0, _emberMetal.get)(obj, 'foo');
// create observer chain
(0, _emberMetal.addObserver)(obj, 'qux.length', function () {});
/*
+-----+
| qux | root CP
+-----+
^
+------+-----+
| |
+--------+ +----+
| length | | [] | chainWatchers
+--------+ +----+
observer CP(foo, 'qux.[]')
*/
// invalidate qux
(0, _emberMetal.propertyDidChange)(obj, 'qux');
// CP chain is blown away
/*
+-----+
| qux | root CP
+-----+
^
+------+xxxxxx
| x
+--------+ xxxxxx
| length | x [] x chainWatchers
+--------+ xxxxxx
observer CP(foo, 'qux.[]')
*/
(0, _emberMetal.get)(obj, 'qux'); // CP chain re-recreated
ok(true, 'no crash');
});
QUnit.test('checks cache correctly', function (assert) {
var obj = {};
var parentChainNode = new _emberMetal.ChainNode(null, null, obj);
var chainNode = new _emberMetal.ChainNode(parentChainNode, 'foo');
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {
return undefined;
}));
(0, _emberMetal.get)(obj, 'foo');
assert.strictEqual(chainNode.value(), undefined);
});
});
enifed('ember-metal/tests/computed_test', ['ember-runtime', 'internal-test-helpers', 'ember-metal'], function (_emberRuntime, _internalTestHelpers, _emberMetal) {
'use strict';
var obj = void 0,
count = void 0;
QUnit.module('computed');
QUnit.test('computed property should be an instance of descriptor', function () {
ok((0, _emberMetal.computed)(function () {}) instanceof _emberMetal.Descriptor);
});
QUnit.test('computed properties assert the presence of a getter or setter function', function () {
expectAssertion(function () {
(0, _emberMetal.computed)('nogetternorsetter', {});
}, 'Computed properties must receive a getter or a setter, you passed none.');
});
QUnit.test('computed properties check for the presence of a function or configuration object', function () {
expectAssertion(function () {
(0, _emberMetal.computed)('nolastargument');
}, 'Ember.computed expects a function or an object as last argument.');
});
QUnit.test('computed properties defined with an object only allow `get` and `set` keys', function () {
expectAssertion(function () {
(0, _emberMetal.computed)({
get: function () {},
set: function () {},
other: function () {}
});
}, 'Config object passed to an Ember.computed can only contain `get` or `set` keys.');
});
QUnit.test('defining computed property should invoke property on get', function () {
var obj = {};
var count = 0;
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function (key) {
count++;
return 'computed ' + key;
}));
equal((0, _emberMetal.get)(obj, 'foo'), 'computed foo', 'should return value');
equal(count, 1, 'should have invoked computed property');
});
QUnit.test('defining computed property should invoke property on set', function () {
var obj = {};
var count = 0;
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({
get: function (key) {
return this['__' + key];
},
set: function (key, value) {
count++;
this['__' + key] = 'computed ' + value;
return this['__' + key];
}
}));
equal((0, _emberMetal.set)(obj, 'foo', 'bar'), 'bar', 'should return set value');
equal(count, 1, 'should have invoked computed property');
equal((0, _emberMetal.get)(obj, 'foo'), 'computed bar', 'should return new value');
});
QUnit.test('defining a computed property with a dependent key ending with @each is expanded to []', function () {
var cp = (0, _emberMetal.computed)('blazo.@each', function () {});
deepEqual(cp._dependentKeys, ['blazo.[]']);
cp = (0, _emberMetal.computed)('qux', 'zoopa.@each', function () {});
deepEqual(cp._dependentKeys, ['qux', 'zoopa.[]']);
});
QUnit.test('defining a computed property with a dependent key more than one level deep beyond @each is not supported', function () {
expectNoWarning(function () {
(0, _emberMetal.computed)('todos', function () {});
});
expectNoWarning(function () {
(0, _emberMetal.computed)('todos.@each.owner', function () {});
});
expectWarning(function () {
(0, _emberMetal.computed)('todos.@each.owner.name', function () {});
}, /You used the key "todos\.@each\.owner\.name" which is invalid\. /);
expectWarning(function () {
(0, _emberMetal.computed)('todos.@each.owner.@each.name', function () {});
}, /You used the key "todos\.@each\.owner\.@each\.name" which is invalid\. /);
});
var objA = void 0,
objB = void 0;
QUnit.module('computed should inherit through prototype', {
setup: function () {
objA = { __foo: 'FOO' };
(0, _emberMetal.defineProperty)(objA, 'foo', (0, _emberMetal.computed)({
get: function (key) {
return this['__' + key];
},
set: function (key, value) {
this['__' + key] = 'computed ' + value;
return this['__' + key];
}
}));
objB = Object.create(objA);
objB.__foo = 'FOO'; // make a copy;
},
teardown: function () {
objA = objB = null;
}
});
(0, _internalTestHelpers.testBoth)('using get() and set()', function (get, set) {
equal(get(objA, 'foo'), 'FOO', 'should get FOO from A');
equal(get(objB, 'foo'), 'FOO', 'should get FOO from B');
set(objA, 'foo', 'BIFF');
equal(get(objA, 'foo'), 'computed BIFF', 'should change A');
equal(get(objB, 'foo'), 'FOO', 'should NOT change B');
set(objB, 'foo', 'bar');
equal(get(objB, 'foo'), 'computed bar', 'should change B');
equal(get(objA, 'foo'), 'computed BIFF', 'should NOT change A');
set(objA, 'foo', 'BAZ');
equal(get(objA, 'foo'), 'computed BAZ', 'should change A');
equal(get(objB, 'foo'), 'computed bar', 'should NOT change B');
});
QUnit.module('redefining computed property to normal', {
setup: function () {
objA = { __foo: 'FOO' };
(0, _emberMetal.defineProperty)(objA, 'foo', (0, _emberMetal.computed)({
get: function (key) {
return this['__' + key];
},
set: function (key, value) {
this['__' + key] = 'computed ' + value;
return this['__' + key];
}
}));
objB = Object.create(objA);
(0, _emberMetal.defineProperty)(objB, 'foo'); // make this just a normal property.
},
teardown: function () {
objA = objB = null;
}
});
(0, _internalTestHelpers.testBoth)('using get() and set()', function (get, set) {
equal(get(objA, 'foo'), 'FOO', 'should get FOO from A');
equal(get(objB, 'foo'), undefined, 'should get undefined from B');
set(objA, 'foo', 'BIFF');
equal(get(objA, 'foo'), 'computed BIFF', 'should change A');
equal(get(objB, 'foo'), undefined, 'should NOT change B');
set(objB, 'foo', 'bar');
equal(get(objB, 'foo'), 'bar', 'should change B');
equal(get(objA, 'foo'), 'computed BIFF', 'should NOT change A');
set(objA, 'foo', 'BAZ');
equal(get(objA, 'foo'), 'computed BAZ', 'should change A');
equal(get(objB, 'foo'), 'bar', 'should NOT change B');
});
QUnit.module('redefining computed property to another property', {
setup: function () {
objA = { __foo: 'FOO' };
(0, _emberMetal.defineProperty)(objA, 'foo', (0, _emberMetal.computed)({
get: function (key) {
return this['__' + key];
},
set: function (key, value) {
this['__' + key] = 'A ' + value;
return this['__' + key];
}
}));
objB = Object.create(objA);
objB.__foo = 'FOO';
(0, _emberMetal.defineProperty)(objB, 'foo', (0, _emberMetal.computed)({
get: function (key) {
return this['__' + key];
},
set: function (key, value) {
this['__' + key] = 'B ' + value;
return this['__' + key];
}
}));
},
teardown: function () {
objA = objB = null;
}
});
(0, _internalTestHelpers.testBoth)('using get() and set()', function (get, set) {
equal(get(objA, 'foo'), 'FOO', 'should get FOO from A');
equal(get(objB, 'foo'), 'FOO', 'should get FOO from B');
set(objA, 'foo', 'BIFF');
equal(get(objA, 'foo'), 'A BIFF', 'should change A');
equal(get(objB, 'foo'), 'FOO', 'should NOT change B');
set(objB, 'foo', 'bar');
equal(get(objB, 'foo'), 'B bar', 'should change B');
equal(get(objA, 'foo'), 'A BIFF', 'should NOT change A');
set(objA, 'foo', 'BAZ');
equal(get(objA, 'foo'), 'A BAZ', 'should change A');
equal(get(objB, 'foo'), 'B bar', 'should NOT change B');
});
QUnit.module('computed - metadata');
QUnit.test('can set metadata on a computed property', function () {
var computedProperty = (0, _emberMetal.computed)(function () {});
computedProperty.meta({ key: 'keyValue' });
equal(computedProperty.meta().key, 'keyValue', 'saves passed meta hash to the _meta property');
});
QUnit.test('meta should return an empty hash if no meta is set', function () {
var computedProperty = (0, _emberMetal.computed)(function () {});
deepEqual(computedProperty.meta(), {}, 'returned value is an empty hash');
});
// ..........................................................
// CACHEABLE
//
QUnit.module('computed - cacheable', {
setup: function () {
obj = {};
count = 0;
var func = function () {
count++;
return 'bar ' + count;
};
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({ get: func, set: func }));
},
teardown: function () {
obj = count = null;
}
});
(0, _internalTestHelpers.testBoth)('cacheable should cache', function (get) {
equal(get(obj, 'foo'), 'bar 1', 'first get');
equal(get(obj, 'foo'), 'bar 1', 'second get');
equal(count, 1, 'should only invoke once');
});
(0, _internalTestHelpers.testBoth)('modifying a cacheable property should update cache', function (get, set) {
equal(get(obj, 'foo'), 'bar 1', 'first get');
equal(get(obj, 'foo'), 'bar 1', 'second get');
equal(set(obj, 'foo', 'baz'), 'baz', 'setting');
equal(get(obj, 'foo'), 'bar 2', 'third get');
equal(count, 2, 'should not invoke again');
});
(0, _internalTestHelpers.testBoth)('inherited property should not pick up cache', function (get, set) {
var objB = Object.create(obj);
equal(get(obj, 'foo'), 'bar 1', 'obj first get');
equal(get(objB, 'foo'), 'bar 2', 'objB first get');
equal(get(obj, 'foo'), 'bar 1', 'obj second get');
equal(get(objB, 'foo'), 'bar 2', 'objB second get');
set(obj, 'foo', 'baz'); // modify A
equal(get(obj, 'foo'), 'bar 3', 'obj third get');
equal(get(objB, 'foo'), 'bar 2', 'objB third get');
});
(0, _internalTestHelpers.testBoth)('cacheFor should return the cached value', function (get) {
equal((0, _emberMetal.cacheFor)(obj, 'foo'), undefined, 'should not yet be a cached value');
get(obj, 'foo');
equal((0, _emberMetal.cacheFor)(obj, 'foo'), 'bar 1', 'should retrieve cached value');
});
(0, _internalTestHelpers.testBoth)('cacheFor should return falsy cached values', function (get) {
(0, _emberMetal.defineProperty)(obj, 'falsy', (0, _emberMetal.computed)(function () {
return false;
}));
equal((0, _emberMetal.cacheFor)(obj, 'falsy'), undefined, 'should not yet be a cached value');
get(obj, 'falsy');
equal((0, _emberMetal.cacheFor)(obj, 'falsy'), false, 'should retrieve cached value');
});
(0, _internalTestHelpers.testBoth)('setting a cached computed property passes the old value as the third argument', function (get, set) {
var obj = {
foo: 0
};
var receivedOldValue = void 0;
(0, _emberMetal.defineProperty)(obj, 'plusOne', (0, _emberMetal.computed)({
get: function () {},
set: function (key, value, oldValue) {
receivedOldValue = oldValue;
return value;
}
}).property('foo'));
set(obj, 'plusOne', 1);
strictEqual(receivedOldValue, undefined, 'oldValue should be undefined');
set(obj, 'plusOne', 2);
strictEqual(receivedOldValue, 1, 'oldValue should be 1');
set(obj, 'plusOne', 3);
strictEqual(receivedOldValue, 2, 'oldValue should be 2');
});
// ..........................................................
// DEPENDENT KEYS
//
QUnit.module('computed - dependentkey', {
setup: function () {
obj = { bar: 'baz' };
count = 0;
var getterAndSetter = function () {
count++;
(0, _emberMetal.get)(this, 'bar');
return 'bar ' + count;
};
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({
get: getterAndSetter,
set: getterAndSetter
}).property('bar'));
},
teardown: function () {
obj = count = null;
}
});
(0, _internalTestHelpers.testBoth)('should lazily watch dependent keys on set', function (get, set) {
equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
set(obj, 'foo', 'bar');
equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily watching dependent key');
});
(0, _internalTestHelpers.testBoth)('should lazily watch dependent keys on get', function (get) {
equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
get(obj, 'foo');
equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily watching dependent key');
});
(0, _internalTestHelpers.testBoth)('local dependent key should invalidate cache', function (get, set) {
equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
equal(get(obj, 'foo'), 'bar 1', 'get once');
equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily setup watching dependent key');
equal(get(obj, 'foo'), 'bar 1', 'cached retrieve');
set(obj, 'bar', 'BIFF'); // should invalidate foo
equal(get(obj, 'foo'), 'bar 2', 'should recache');
equal(get(obj, 'foo'), 'bar 2', 'cached retrieve');
});
(0, _internalTestHelpers.testBoth)('should invalidate multiple nested dependent keys', function (get, set) {
var count = 0;
(0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)(function () {
count++;
get(this, 'baz');
return 'baz ' + count;
}).property('baz'));
equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
equal((0, _emberMetal.isWatching)(obj, 'baz'), false, 'precond not watching dependent key');
equal(get(obj, 'foo'), 'bar 1', 'get once');
equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily setup watching dependent key');
equal((0, _emberMetal.isWatching)(obj, 'baz'), true, 'lazily setup watching dependent key');
equal(get(obj, 'foo'), 'bar 1', 'cached retrieve');
set(obj, 'baz', 'BIFF'); // should invalidate bar -> foo
equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'should not be watching dependent key after cache cleared');
equal((0, _emberMetal.isWatching)(obj, 'baz'), false, 'should not be watching dependent key after cache cleared');
equal(get(obj, 'foo'), 'bar 2', 'should recache');
equal(get(obj, 'foo'), 'bar 2', 'cached retrieve');
equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily setup watching dependent key');
equal((0, _emberMetal.isWatching)(obj, 'baz'), true, 'lazily setup watching dependent key');
});
(0, _internalTestHelpers.testBoth)('circular keys should not blow up', function (get, set) {
var func = function () {
count++;
return 'bar ' + count;
};
(0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)({ get: func, set: func }).property('foo'));
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {
count++;
return 'foo ' + count;
}).property('bar'));
equal(get(obj, 'foo'), 'foo 1', 'get once');
equal(get(obj, 'foo'), 'foo 1', 'cached retrieve');
set(obj, 'bar', 'BIFF'); // should invalidate bar -> foo -> bar
equal(get(obj, 'foo'), 'foo 3', 'should recache');
equal(get(obj, 'foo'), 'foo 3', 'cached retrieve');
});
(0, _internalTestHelpers.testBoth)('redefining a property should undo old dependent keys', function (get, set) {
equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'precond not watching dependent key');
equal(get(obj, 'foo'), 'bar 1');
equal((0, _emberMetal.isWatching)(obj, 'bar'), true, 'lazily watching dependent key');
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {
count++;
return 'baz ' + count;
}).property('baz'));
equal((0, _emberMetal.isWatching)(obj, 'bar'), false, 'after redefining should not be watching dependent key');
equal(get(obj, 'foo'), 'baz 2');
set(obj, 'bar', 'BIFF'); // should not kill cache
equal(get(obj, 'foo'), 'baz 2');
set(obj, 'baz', 'BOP');
equal(get(obj, 'foo'), 'baz 3');
});
(0, _internalTestHelpers.testBoth)('can watch multiple dependent keys specified declaratively via brace expansion', function (get, set) {
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {
count++;
return 'foo ' + count;
}).property('qux.{bar,baz}'));
equal(get(obj, 'foo'), 'foo 1', 'get once');
equal(get(obj, 'foo'), 'foo 1', 'cached retrieve');
set(obj, 'qux', {});
set(obj, 'qux.bar', 'bar'); // invalidate foo
equal(get(obj, 'foo'), 'foo 2', 'foo invalidated from bar');
set(obj, 'qux.baz', 'baz'); // invalidate foo
equal(get(obj, 'foo'), 'foo 3', 'foo invalidated from baz');
set(obj, 'qux.quux', 'quux'); // do not invalidate foo
equal(get(obj, 'foo'), 'foo 3', 'foo not invalidated by quux');
});
(0, _internalTestHelpers.testBoth)('throws assertion if brace expansion notation has spaces', function () {
expectAssertion(function () {
(0, _emberMetal.defineProperty)(obj, 'roo', (0, _emberMetal.computed)(function () {
count++;
return 'roo ' + count;
}).property('fee.{bar, baz,bop , }'));
}, /cannot contain spaces/);
});
// ..........................................................
// CHAINED DEPENDENT KEYS
//
var func = void 0;
QUnit.module('computed - dependentkey with chained properties', {
setup: function () {
obj = {
foo: {
bar: {
baz: {
biff: 'BIFF'
}
}
}
};
count = 0;
func = function () {
count++;
return (0, _emberMetal.get)(obj, 'foo.bar.baz.biff') + ' ' + count;
};
},
teardown: function () {
obj = count = func = null;
}
});
(0, _internalTestHelpers.testBoth)('depending on simple chain', function (get, set) {
// assign computed property
(0, _emberMetal.defineProperty)(obj, 'prop', (0, _emberMetal.computed)(func).property('foo.bar.baz.biff'));
equal(get(obj, 'prop'), 'BIFF 1');
set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
equal(get(obj, 'prop'), 'BUZZ 2');
equal(get(obj, 'prop'), 'BUZZ 2');
set(get(obj, 'foo.bar'), 'baz', { biff: 'BLOB' });
equal(get(obj, 'prop'), 'BLOB 3');
equal(get(obj, 'prop'), 'BLOB 3');
set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
equal(get(obj, 'prop'), 'BUZZ 4');
equal(get(obj, 'prop'), 'BUZZ 4');
set(get(obj, 'foo'), 'bar', { baz: { biff: 'BOOM' } });
equal(get(obj, 'prop'), 'BOOM 5');
equal(get(obj, 'prop'), 'BOOM 5');
set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
equal(get(obj, 'prop'), 'BUZZ 6');
equal(get(obj, 'prop'), 'BUZZ 6');
set(obj, 'foo', { bar: { baz: { biff: 'BLARG' } } });
equal(get(obj, 'prop'), 'BLARG 7');
equal(get(obj, 'prop'), 'BLARG 7');
set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
equal(get(obj, 'prop'), 'BUZZ 8');
equal(get(obj, 'prop'), 'BUZZ 8');
(0, _emberMetal.defineProperty)(obj, 'prop');
set(obj, 'prop', 'NONE');
equal(get(obj, 'prop'), 'NONE');
set(obj, 'foo', { bar: { baz: { biff: 'BLARG' } } });
equal(get(obj, 'prop'), 'NONE'); // should do nothing
equal(count, 8, 'should be not have invoked computed again');
});
(0, _internalTestHelpers.testBoth)('chained dependent keys should evaluate computed properties lazily', function () {
(0, _emberMetal.defineProperty)(obj.foo.bar, 'b', (0, _emberMetal.computed)(func));
(0, _emberMetal.defineProperty)(obj.foo, 'c', (0, _emberMetal.computed)(function () {}).property('bar.b'));
equal(count, 0, 'b should not run');
});
// ..........................................................
// improved-cp-syntax
//
QUnit.module('computed - improved cp syntax');
QUnit.test('setter and getters are passed using an object', function () {
var testObj = _emberRuntime.Object.extend({
a: '1',
b: '2',
aInt: (0, _emberMetal.computed)('a', {
get: function (keyName) {
equal(keyName, 'aInt', 'getter receives the keyName');
return parseInt(this.get('a'));
},
set: function (keyName, value, oldValue) {
equal(keyName, 'aInt', 'setter receives the keyName');
equal(value, 123, 'setter receives the new value');
equal(oldValue, 1, 'setter receives the old value');
this.set('a', '' + value); // side effect
return parseInt(this.get('a'));
}
})
}).create();
ok(testObj.get('aInt') === 1, 'getter works');
testObj.set('aInt', 123);
ok(testObj.get('a') === '123', 'setter works');
ok(testObj.get('aInt') === 123, 'cp has been updated too');
});
QUnit.test('setter can be omited', function () {
var testObj = _emberRuntime.Object.extend({
a: '1',
b: '2',
aInt: (0, _emberMetal.computed)('a', {
get: function (keyName) {
equal(keyName, 'aInt', 'getter receives the keyName');
return parseInt(this.get('a'));
}
})
}).create();
ok(testObj.get('aInt') === 1, 'getter works');
ok(testObj.get('a') === '1');
testObj.set('aInt', '123');
ok(testObj.get('aInt') === '123', 'cp has been updated too');
});
QUnit.test('the return value of the setter gets cached', function () {
var testObj = _emberRuntime.Object.extend({
a: '1',
sampleCP: (0, _emberMetal.computed)('a', {
get: function () {
ok(false, 'The getter should not be invoked');
return 'get-value';
},
set: function () {
return 'set-value';
}
})
}).create();
testObj.set('sampleCP', 'abcd');
ok(testObj.get('sampleCP') === 'set-value', 'The return value of the CP was cached');
});
// ..........................................................
// BUGS
//
QUnit.module('computed edge cases');
QUnit.test('adding a computed property should show up in key iteration', function () {
var obj = {};
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {}));
var found = [];
for (var key in obj) {
found.push(key);
}
ok(found.indexOf('foo') >= 0, 'should find computed property in iteration found=' + found);
ok('foo' in obj, 'foo in obj should pass');
});
(0, _internalTestHelpers.testBoth)('when setting a value after it had been retrieved empty don\'t pass function UNDEFINED as oldValue', function (get, set) {
var obj = {};
var oldValueIsNoFunction = true;
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({
get: function () {},
set: function (key, value, oldValue) {
if (typeof oldValue === 'function') {
oldValueIsNoFunction = false;
}
return undefined;
}
}));
get(obj, 'foo');
set(obj, 'foo', undefined);
ok(oldValueIsNoFunction);
});
QUnit.module('computed - setter');
(0, _internalTestHelpers.testBoth)('setting a watched computed property', function (get, set) {
var obj = {
firstName: 'Yehuda',
lastName: 'Katz'
};
(0, _emberMetal.defineProperty)(obj, 'fullName', (0, _emberMetal.computed)({
get: function () {
return get(this, 'firstName') + ' ' + get(this, 'lastName');
},
set: function (key, value) {
var values = value.split(' ');
set(this, 'firstName', values[0]);
set(this, 'lastName', values[1]);
return value;
}
}).property('firstName', 'lastName'));
var fullNameWillChange = 0;
var fullNameDidChange = 0;
var firstNameWillChange = 0;
var firstNameDidChange = 0;
var lastNameWillChange = 0;
var lastNameDidChange = 0;
(0, _emberMetal._addBeforeObserver)(obj, 'fullName', function () {
fullNameWillChange++;
});
(0, _emberMetal.addObserver)(obj, 'fullName', function () {
fullNameDidChange++;
});
(0, _emberMetal._addBeforeObserver)(obj, 'firstName', function () {
firstNameWillChange++;
});
(0, _emberMetal.addObserver)(obj, 'firstName', function () {
firstNameDidChange++;
});
(0, _emberMetal._addBeforeObserver)(obj, 'lastName', function () {
lastNameWillChange++;
});
(0, _emberMetal.addObserver)(obj, 'lastName', function () {
lastNameDidChange++;
});
equal(get(obj, 'fullName'), 'Yehuda Katz');
set(obj, 'fullName', 'Yehuda Katz');
set(obj, 'fullName', 'Kris Selden');
equal(get(obj, 'fullName'), 'Kris Selden');
equal(get(obj, 'firstName'), 'Kris');
equal(get(obj, 'lastName'), 'Selden');
equal(fullNameWillChange, 1);
equal(fullNameDidChange, 1);
equal(firstNameWillChange, 1);
equal(firstNameDidChange, 1);
equal(lastNameWillChange, 1);
equal(lastNameDidChange, 1);
});
(0, _internalTestHelpers.testBoth)('setting a cached computed property that modifies the value you give it', function (get, set) {
var obj = {
foo: 0
};
(0, _emberMetal.defineProperty)(obj, 'plusOne', (0, _emberMetal.computed)({
get: function () {
return get(this, 'foo') + 1;
},
set: function (key, value) {
set(this, 'foo', value);
return value + 1;
}
}).property('foo'));
var plusOneWillChange = 0;
var plusOneDidChange = 0;
(0, _emberMetal._addBeforeObserver)(obj, 'plusOne', function () {
plusOneWillChange++;
});
(0, _emberMetal.addObserver)(obj, 'plusOne', function () {
plusOneDidChange++;
});
equal(get(obj, 'plusOne'), 1);
set(obj, 'plusOne', 1);
equal(get(obj, 'plusOne'), 2);
set(obj, 'plusOne', 1);
equal(get(obj, 'plusOne'), 2);
equal(plusOneWillChange, 1);
equal(plusOneDidChange, 1);
set(obj, 'foo', 5);
equal(get(obj, 'plusOne'), 6);
equal(plusOneWillChange, 2);
equal(plusOneDidChange, 2);
});
QUnit.module('computed - default setter');
(0, _internalTestHelpers.testBoth)('when setting a value on a computed property that doesn\'t handle sets', function (get, set) {
var obj = {};
var observerFired = false;
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {
return 'foo';
}));
(0, _emberMetal.addObserver)(obj, 'foo', null, function () {
return observerFired = true;
});
set(obj, 'foo', 'bar');
equal(get(obj, 'foo'), 'bar', 'The set value is properly returned');
ok(typeof obj.foo === 'string', 'The computed property was removed');
ok(observerFired, 'The observer was still notified');
});
QUnit.module('computed - readOnly');
QUnit.test('is chainable', function () {
var cp = (0, _emberMetal.computed)(function () {}).readOnly();
ok(cp instanceof _emberMetal.Descriptor);
ok(cp instanceof _emberMetal.ComputedProperty);
});
QUnit.test('throws assertion if called over a CP with a setter defined with the new syntax', function () {
expectAssertion(function () {
(0, _emberMetal.computed)({
get: function () {},
set: function () {}
}).readOnly();
}, /Computed properties that define a setter using the new syntax cannot be read-only/);
});
(0, _internalTestHelpers.testBoth)('protects against setting', function (get, set) {
var obj = {};
(0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)(function () {
return 'barValue';
}).readOnly());
equal(get(obj, 'bar'), 'barValue');
throws(function () {
set(obj, 'bar', 'newBar');
}, /Cannot set read\-only property "bar" on object:/);
equal(get(obj, 'bar'), 'barValue');
});
});
enifed('ember-metal/tests/descriptor_test', ['ember-babel', 'ember-runtime', 'ember-metal'], function (_emberBabel, _emberRuntime, _emberMetal) {
'use strict';
// IE9 soft-fails when trying to delete a non-configurable property
var hasCompliantDelete = function () {
var obj = {};
Object.defineProperty(obj, 'zomg', { configurable: false, value: 'zomg' });
try {
delete obj.zomg;
} catch (e) {
return true;
}
return false;
}();
// IE9 soft-fails when trying to assign to a non-writable property
var hasCompliantAssign = function () {
var obj = {};
Object.defineProperty(obj, 'zomg', { writable: false, value: 'zomg' });
try {
obj.zomg = 'lol';
} catch (e) {
return true;
}
return false;
}();
var DescriptorTest = function () {
DescriptorTest.test = function (title, callback) {
var _this = this;
QUnit.test(title, function (assert) {
callback(assert, new _this(assert));
});
};
function DescriptorTest(assert) {
this.assert = assert;
}
/* abstract install(key: string, desc: Descriptor); */
/* abstract set(key: string, value: any); */
/* abstract finalize(): Object; */
return DescriptorTest;
}();
var classes = [function (_DescriptorTest) {
(0, _emberBabel.inherits)(_class, _DescriptorTest);
_class.module = function (title) {
QUnit.module(title + ': using defineProperty on an object directly');
};
function _class(assert) {
var _this2 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest.call(this, assert));
_this2.object = {};
return _this2;
}
_class.prototype.install = function (key, desc) {
var object = this.object,
assert = this.assert;
(0, _emberMetal.defineProperty)(object, key, desc);
assert.ok(object.hasOwnProperty(key));
};
_class.prototype.set = function (key, value) {
this.object[key] = value;
};
_class.prototype.finalize = function () {
return this.object;
};
_class.prototype.source = function () {
return this.object;
};
return _class;
}(DescriptorTest), function (_DescriptorTest2) {
(0, _emberBabel.inherits)(_class2, _DescriptorTest2);
_class2.module = function (title) {
QUnit.module(title + ': using defineProperty on a prototype');
};
function _class2(assert) {
var _this3 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest2.call(this, assert));
_this3.proto = {};
return _this3;
}
_class2.prototype.install = function (key, desc) {
var proto = this.proto,
assert = this.assert;
(0, _emberMetal.defineProperty)(proto, key, desc);
assert.ok(proto.hasOwnProperty(key));
};
_class2.prototype.set = function (key, value) {
this.proto[key] = value;
};
_class2.prototype.finalize = function () {
return Object.create(this.proto);
};
_class2.prototype.source = function () {
return this.proto;
};
return _class2;
}(DescriptorTest), function (_DescriptorTest3) {
(0, _emberBabel.inherits)(_class3, _DescriptorTest3);
_class3.module = function (title) {
QUnit.module(title + ': in EmberObject.extend()');
};
function _class3(assert) {
var _this4 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest3.call(this, assert));
_this4.klass = null;
_this4.props = {};
return _this4;
}
_class3.prototype.install = function (key, desc) {
this.props[key] = desc;
};
_class3.prototype.set = function (key, value) {
this.props[key] = value;
};
_class3.prototype.finalize = function () {
this.klass = _emberRuntime.Object.extend(this.props);
return this.klass.create();
};
_class3.prototype.source = function () {
return this.klass.prototype;
};
return _class3;
}(DescriptorTest), function (_DescriptorTest4) {
(0, _emberBabel.inherits)(_class4, _DescriptorTest4);
_class4.module = function (title) {
QUnit.module(title + ': in EmberObject.extend() through a mixin');
};
function _class4(assert) {
var _this5 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest4.call(this, assert));
_this5.klass = null;
_this5.props = {};
return _this5;
}
_class4.prototype.install = function (key, desc) {
this.props[key] = desc;
};
_class4.prototype.set = function (key, value) {
this.props[key] = value;
};
_class4.prototype.finalize = function () {
this.klass = _emberRuntime.Object.extend(_emberMetal.Mixin.create(this.props));
return this.klass.create();
};
_class4.prototype.source = function () {
return this.klass.prototype;
};
return _class4;
}(DescriptorTest), function (_DescriptorTest5) {
(0, _emberBabel.inherits)(_class5, _DescriptorTest5);
_class5.module = function (title) {
QUnit.module(title + ': inherited from another EmberObject super class');
};
function _class5(assert) {
var _this6 = (0, _emberBabel.possibleConstructorReturn)(this, _DescriptorTest5.call(this, assert));
_this6.superklass = null;
_this6.props = {};
return _this6;
}
_class5.prototype.install = function (key, desc) {
this.props[key] = desc;
};
_class5.prototype.set = function (key, value) {
this.props[key] = value;
};
_class5.prototype.finalize = function () {
this.superklass = _emberRuntime.Object.extend(this.props);
return this.superklass.extend().create();
};
_class5.prototype.source = function () {
return this.superklass.prototype;
};
return _class5;
}(DescriptorTest)];
classes.forEach(function (TestClass) {
TestClass.module('ember-metal/descriptor');
TestClass.test('defining a configurable property', function (assert, factory) {
factory.install('foo', (0, _emberMetal.descriptor)({ configurable: true, value: 'bar' }));
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
var source = factory.source();
delete source.foo;
assert.strictEqual(obj.foo, undefined);
Object.defineProperty(source, 'foo', { configurable: true, value: 'baz' });
assert.equal(obj.foo, 'baz');
});
TestClass.test('defining a non-configurable property', function (assert, factory) {
factory.install('foo', (0, _emberMetal.descriptor)({ configurable: false, value: 'bar' }));
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
var source = factory.source();
if (hasCompliantDelete) {
assert.throws(function () {
return delete source.foo;
}, TypeError);
} else {
delete source.foo;
}
assert.throws(function () {
return Object.defineProperty(source, 'foo', { configurable: true, value: 'baz' });
}, TypeError);
assert.equal(obj.foo, 'bar');
});
TestClass.test('defining an enumerable property', function (assert, factory) {
factory.install('foo', (0, _emberMetal.descriptor)({ enumerable: true, value: 'bar' }));
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
var source = factory.source();
assert.ok(Object.keys(source).indexOf('foo') !== -1);
});
TestClass.test('defining a non-enumerable property', function (assert, factory) {
factory.install('foo', (0, _emberMetal.descriptor)({ enumerable: false, value: 'bar' }));
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
var source = factory.source();
assert.ok(Object.keys(source).indexOf('foo') === -1);
});
TestClass.test('defining a writable property', function (assert, factory) {
factory.install('foo', (0, _emberMetal.descriptor)({ writable: true, value: 'bar' }));
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
var source = factory.source();
source.foo = 'baz';
assert.equal(obj.foo, 'baz');
obj.foo = 'bat';
assert.equal(obj.foo, 'bat');
});
TestClass.test('defining a non-writable property', function (assert, factory) {
factory.install('foo', (0, _emberMetal.descriptor)({ writable: false, value: 'bar' }));
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
var source = factory.source();
if (hasCompliantAssign) {
assert.throws(function () {
return source.foo = 'baz';
}, TypeError);
assert.throws(function () {
return obj.foo = 'baz';
}, TypeError);
} else {
source.foo = 'baz';
obj.foo = 'baz';
}
assert.equal(obj.foo, 'bar');
});
TestClass.test('defining a getter', function (assert, factory) {
factory.install('foo', (0, _emberMetal.descriptor)({
get: function () {
return this.__foo__;
}
}));
factory.set('__foo__', 'bar');
var obj = factory.finalize();
assert.equal(obj.foo, 'bar');
obj.__foo__ = 'baz';
assert.equal(obj.foo, 'baz');
});
TestClass.test('defining a setter', function (assert, factory) {
factory.install('foo', (0, _emberMetal.descriptor)({
set: function (value) {
this.__foo__ = value;
}
}));
factory.set('__foo__', 'bar');
var obj = factory.finalize();
assert.equal(obj.__foo__, 'bar');
obj.foo = 'baz';
assert.equal(obj.__foo__, 'baz');
});
TestClass.test('combining multiple setter and getters', function (assert, factory) {
factory.install('foo', (0, _emberMetal.descriptor)({
get: function () {
return this.__foo__;
},
set: function (value) {
this.__foo__ = value;
}
}));
factory.set('__foo__', 'foo');
factory.install('bar', (0, _emberMetal.descriptor)({
get: function () {
return this.__bar__;
},
set: function (value) {
this.__bar__ = value;
}
}));
factory.set('__bar__', 'bar');
factory.install('fooBar', (0, _emberMetal.descriptor)({
get: function () {
return this.foo + '-' + this.bar;
}
}));
var obj = factory.finalize();
assert.equal(obj.fooBar, 'foo-bar');
obj.foo = 'FOO';
assert.equal(obj.fooBar, 'FOO-bar');
obj.__bar__ = 'BAR';
assert.equal(obj.fooBar, 'FOO-BAR');
if (hasCompliantAssign) {
assert.throws(function () {
return obj.fooBar = 'foobar';
}, TypeError);
} else {
obj.fooBar = 'foobar';
}
assert.equal(obj.fooBar, 'FOO-BAR');
});
});
});
enifed('ember-metal/tests/events_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('system/props/events_test');
QUnit.test('listener should receive event - removing should remove', function () {
var obj = {};
var count = 0;
function F() {
count++;
}
(0, _emberMetal.addListener)(obj, 'event!', F);
equal(count, 0, 'nothing yet');
(0, _emberMetal.sendEvent)(obj, 'event!');
equal(count, 1, 'received event');
(0, _emberMetal.removeListener)(obj, 'event!', F);
count = 0;
(0, _emberMetal.sendEvent)(obj, 'event!');
equal(count, 0, 'received event');
});
QUnit.test('listeners should be inherited', function () {
var obj = {};
var count = 0;
var F = function () {
count++;
};
(0, _emberMetal.addListener)(obj, 'event!', F);
var obj2 = Object.create(obj);
equal(count, 0, 'nothing yet');
(0, _emberMetal.sendEvent)(obj2, 'event!');
equal(count, 1, 'received event');
(0, _emberMetal.removeListener)(obj2, 'event!', F);
count = 0;
(0, _emberMetal.sendEvent)(obj2, 'event!');
equal(count, 0, 'did not receive event');
(0, _emberMetal.sendEvent)(obj, 'event!');
equal(count, 1, 'should still invoke on parent');
});
QUnit.test('adding a listener more than once should only invoke once', function () {
var obj = {};
var count = 0;
function F() {
count++;
}
(0, _emberMetal.addListener)(obj, 'event!', F);
(0, _emberMetal.addListener)(obj, 'event!', F);
(0, _emberMetal.sendEvent)(obj, 'event!');
equal(count, 1, 'should only invoke once');
});
QUnit.test('adding a listener with a target should invoke with target', function () {
var obj = {};
var target = void 0;
target = {
count: 0,
method: function () {
this.count++;
}
};
(0, _emberMetal.addListener)(obj, 'event!', target, target.method);
(0, _emberMetal.sendEvent)(obj, 'event!');
equal(target.count, 1, 'should invoke');
});
QUnit.test('suspending a listener should not invoke during callback', function () {
var obj = {};
var target = void 0,
otherTarget = void 0;
target = {
count: 0,
method: function () {
this.count++;
}
};
otherTarget = {
count: 0,
method: function () {
this.count++;
}
};
(0, _emberMetal.addListener)(obj, 'event!', target, target.method);
(0, _emberMetal.addListener)(obj, 'event!', otherTarget, otherTarget.method);
(0, _emberMetal.sendEvent)(obj, 'event!');
equal((0, _emberMetal.suspendListener)(obj, 'event!', target, target.method, function () {
/*jshint validthis:true */
equal(this, target);
(0, _emberMetal.sendEvent)(obj, 'event!');
return 'result';
}), 'result');
(0, _emberMetal.sendEvent)(obj, 'event!');
equal(target.count, 2, 'should invoke');
equal(otherTarget.count, 3, 'should invoke');
});
QUnit.test('adding a listener with string method should lookup method on event delivery', function () {
var obj = {};
var target = void 0;
target = {
count: 0,
method: function () {}
};
(0, _emberMetal.addListener)(obj, 'event!', target, 'method');
(0, _emberMetal.sendEvent)(obj, 'event!');
equal(target.count, 0, 'should invoke but do nothing');
target.method = function () {
this.count++;
};
(0, _emberMetal.sendEvent)(obj, 'event!');
equal(target.count, 1, 'should invoke now');
});
QUnit.test('calling sendEvent with extra params should be passed to listeners', function () {
var obj = {};
var params = null;
(0, _emberMetal.addListener)(obj, 'event!', function () {
params = Array.prototype.slice.call(arguments);
});
(0, _emberMetal.sendEvent)(obj, 'event!', ['foo', 'bar']);
deepEqual(params, ['foo', 'bar'], 'params should be saved');
});
QUnit.test('hasListeners tells you if there are listeners for a given event', function () {
var obj = {};
function F() {}
function F2() {}
equal((0, _emberMetal.hasListeners)(obj, 'event!'), false, 'no listeners at first');
(0, _emberMetal.addListener)(obj, 'event!', F);
(0, _emberMetal.addListener)(obj, 'event!', F2);
equal((0, _emberMetal.hasListeners)(obj, 'event!'), true, 'has listeners');
(0, _emberMetal.removeListener)(obj, 'event!', F);
equal((0, _emberMetal.hasListeners)(obj, 'event!'), true, 'has listeners');
(0, _emberMetal.removeListener)(obj, 'event!', F2);
equal((0, _emberMetal.hasListeners)(obj, 'event!'), false, 'has no more listeners');
(0, _emberMetal.addListener)(obj, 'event!', F);
equal((0, _emberMetal.hasListeners)(obj, 'event!'), true, 'has listeners');
});
QUnit.test('calling removeListener without method should remove all listeners', function () {
var obj = {};
equal((0, _emberMetal.hasListeners)(obj, 'event!'), false, 'no listeners at first');
(0, _emberMetal.addListener)(obj, 'event!', function () {});
(0, _emberMetal.addListener)(obj, 'event!', function () {});
equal((0, _emberMetal.hasListeners)(obj, 'event!'), true, 'has listeners');
(0, _emberMetal.removeListener)(obj, 'event!');
equal((0, _emberMetal.hasListeners)(obj, 'event!'), false, 'has no more listeners');
});
QUnit.test('while suspended, it should not be possible to add a duplicate listener', function () {
var obj = {};
var target = void 0;
target = {
count: 0,
method: function () {
this.count++;
}
};
(0, _emberMetal.addListener)(obj, 'event!', target, target.method);
function callback() {
(0, _emberMetal.addListener)(obj, 'event!', target, target.method);
}
(0, _emberMetal.sendEvent)(obj, 'event!');
(0, _emberMetal.suspendListener)(obj, 'event!', target, target.method, callback);
equal(target.count, 1, 'should invoke');
equal((0, _emberMetal.meta)(obj).matchingListeners('event!').length, 3, 'a duplicate listener wasn\'t added');
// now test suspendListeners...
(0, _emberMetal.sendEvent)(obj, 'event!');
(0, _emberMetal.suspendListeners)(obj, ['event!'], target, target.method, callback);
equal(target.count, 2, 'should have invoked again');
equal((0, _emberMetal.meta)(obj).matchingListeners('event!').length, 3, 'a duplicate listener wasn\'t added');
});
QUnit.test('a listener can be added as part of a mixin', function () {
var triggered = 0;
var MyMixin = _emberMetal.Mixin.create({
foo1: (0, _emberMetal.on)('bar', function () {
triggered++;
}),
foo2: (0, _emberMetal.on)('bar', function () {
triggered++;
})
});
var obj = {};
MyMixin.apply(obj);
(0, _emberMetal.sendEvent)(obj, 'bar');
equal(triggered, 2, 'should invoke listeners');
});
QUnit.test('a listener added as part of a mixin may be overridden', function () {
var triggered = 0;
var FirstMixin = _emberMetal.Mixin.create({
foo: (0, _emberMetal.on)('bar', function () {
triggered++;
})
});
var SecondMixin = _emberMetal.Mixin.create({
foo: (0, _emberMetal.on)('baz', function () {
triggered++;
})
});
var obj = {};
FirstMixin.apply(obj);
SecondMixin.apply(obj);
(0, _emberMetal.sendEvent)(obj, 'bar');
equal(triggered, 0, 'should not invoke from overriden property');
(0, _emberMetal.sendEvent)(obj, 'baz');
equal(triggered, 1, 'should invoke from subclass property');
});
});
enifed('ember-metal/tests/expand_properties_test', ['ember-metal'], function (_emberMetal) {
'use strict';
var foundProperties = [];
function addProperty(property) {
foundProperties.push(property);
}
QUnit.module('Property Brace Expansion Test', {
setup: function () {
foundProperties = [];
}
});
QUnit.test('Properties without expansions are unaffected', function () {
expect(1);
(0, _emberMetal.expandProperties)('a', addProperty);
(0, _emberMetal.expandProperties)('a.b', addProperty);
(0, _emberMetal.expandProperties)('a.b.[]', addProperty);
(0, _emberMetal.expandProperties)('a.b.@each.c', addProperty);
deepEqual(['a', 'a.b', 'a.b.[]', 'a.b.@each.c'].sort(), foundProperties.sort());
});
QUnit.test('A single expansion at the end expands properly', function () {
expect(1);
(0, _emberMetal.expandProperties)('a.b.{c,d}', addProperty);
deepEqual(['a.b.c', 'a.b.d'].sort(), foundProperties.sort());
});
QUnit.test('A property with only a brace expansion expands correctly', function () {
expect(1);
(0, _emberMetal.expandProperties)('{a,b,c}', addProperty);
deepEqual(['a', 'b', 'c'].sort(), foundProperties.sort());
});
QUnit.test('Expansions with single properties only expand once', function () {
expect(1);
(0, _emberMetal.expandProperties)('a.b.{c}.d.{e}', addProperty);
deepEqual(['a.b.c.d.e'], foundProperties);
});
QUnit.test('A single brace expansion expands correctly', function () {
expect(1);
(0, _emberMetal.expandProperties)('a.{b,c,d}.e', addProperty);
deepEqual(['a.b.e', 'a.c.e', 'a.d.e'].sort(), foundProperties.sort());
});
QUnit.test('Multiple brace expansions work correctly', function () {
expect(1);
(0, _emberMetal.expandProperties)('{a,b,c}.d.{e,f}.g', addProperty);
deepEqual(['a.d.e.g', 'a.d.f.g', 'b.d.e.g', 'b.d.f.g', 'c.d.e.g', 'c.d.f.g'].sort(), foundProperties.sort());
});
QUnit.test('A property with only brace expansions expands correctly', function () {
expect(1);
(0, _emberMetal.expandProperties)('{a,b,c}.{d}.{e,f}', addProperty);
deepEqual(['a.d.e', 'a.d.f', 'b.d.e', 'b.d.f', 'c.d.e', 'c.d.f'].sort(), foundProperties.sort());
});
QUnit.test('Nested brace expansions are not allowed', function () {
['a.{b.{c,d}}', 'a.{{b}.c}', 'a.{b,c}.{d.{e,f}.g', 'a.{b.{c}', 'a.{b,c}}'].forEach(function (invalidProperties) {
expectAssertion(function () {
return (0, _emberMetal.expandProperties)(invalidProperties, addProperty);
});
}, /Brace expanded properties have to be balanced and cannot be nested/);
});
QUnit.test('A property with no braces does not expand', function () {
expect(1);
(0, _emberMetal.expandProperties)('a,b,c.d.e,f', addProperty);
deepEqual(foundProperties, ['a,b,c.d.e,f']);
});
QUnit.test('A pattern must be a string', function () {
expect(1);
expectAssertion(function () {
(0, _emberMetal.expandProperties)([1, 2], addProperty);
}, /A computed property key must be a string/);
});
QUnit.test('A pattern must not contain a space', function () {
expect(1);
expectAssertion(function () {
(0, _emberMetal.expandProperties)('{a, b}', addProperty);
}, /Brace expanded properties cannot contain spaces, e.g. "user.{firstName, lastName}" should be "user.{firstName,lastName}"/);
});
});
enifed('ember-metal/tests/injected_property_test', ['ember-utils', 'ember-metal'], function (_emberUtils, _emberMetal) {
'use strict';
QUnit.module('InjectedProperty');
QUnit.test('injected properties should be descriptors', function () {
ok(new _emberMetal.InjectedProperty() instanceof _emberMetal.Descriptor);
});
QUnit.test('injected properties should be overridable', function () {
var obj = {};
(0, _emberMetal.defineProperty)(obj, 'foo', new _emberMetal.InjectedProperty());
(0, _emberMetal.set)(obj, 'foo', 'bar');
equal((0, _emberMetal.get)(obj, 'foo'), 'bar', 'should return the overriden value');
});
QUnit.test('getting on an object without an owner or container should fail assertion', function () {
var obj = {};
(0, _emberMetal.defineProperty)(obj, 'foo', new _emberMetal.InjectedProperty('type', 'name'));
expectAssertion(function () {
(0, _emberMetal.get)(obj, 'foo');
}, /Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container./);
});
QUnit.test('getting on an object without an owner but with a container should not fail', function () {
var obj = {
container: {
lookup: function (key) {
ok(true, 'should call container.lookup');
return key;
}
}
};
(0, _emberMetal.defineProperty)(obj, 'foo', new _emberMetal.InjectedProperty('type', 'name'));
equal((0, _emberMetal.get)(obj, 'foo'), 'type:name', 'should return the value of container.lookup');
});
QUnit.test('getting should return a lookup on the container', function () {
expect(2);
var obj = {};
(0, _emberUtils.setOwner)(obj, {
lookup: function (key) {
ok(true, 'should call container.lookup');
return key;
}
});
(0, _emberMetal.defineProperty)(obj, 'foo', new _emberMetal.InjectedProperty('type', 'name'));
equal((0, _emberMetal.get)(obj, 'foo'), 'type:name', 'should return the value of container.lookup');
});
QUnit.test('omitting the lookup name should default to the property name', function () {
var obj = {};
(0, _emberUtils.setOwner)(obj, {
lookup: function (key) {
return key;
}
});
(0, _emberMetal.defineProperty)(obj, 'foo', new _emberMetal.InjectedProperty('type'));
equal((0, _emberMetal.get)(obj, 'foo'), 'type:foo', 'should lookup the type using the property name');
});
});
enifed('ember-metal/tests/instrumentation_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember Instrumentation', {
teardown: function () {
(0, _emberMetal.instrumentationReset)();
}
});
QUnit.test('execute block even if no listeners', function () {
var result = (0, _emberMetal.instrument)('render', {}, function () {
return 'hello';
});
equal(result, 'hello', 'called block');
});
QUnit.test('subscribing to a simple path receives the listener', function () {
expect(12);
var sentPayload = {};
var count = 0;
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function (name, timestamp, payload) {
if (count === 0) {
strictEqual(name, 'render');
} else {
strictEqual(name, 'render.handlebars');
}
ok(typeof timestamp === 'number');
strictEqual(payload, sentPayload);
},
after: function (name, timestamp, payload) {
if (count === 0) {
strictEqual(name, 'render');
} else {
strictEqual(name, 'render.handlebars');
}
ok(typeof timestamp === 'number');
strictEqual(payload, sentPayload);
count++;
}
});
(0, _emberMetal.instrument)('render', sentPayload, function () {});
(0, _emberMetal.instrument)('render.handlebars', sentPayload, function () {});
});
QUnit.test('returning a value from the before callback passes it to the after callback', function () {
expect(2);
var passthru1 = {};
var passthru2 = {};
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function () {
return passthru1;
},
after: function (name, timestamp, payload, beforeValue) {
strictEqual(beforeValue, passthru1);
}
});
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function () {
return passthru2;
},
after: function (name, timestamp, payload, beforeValue) {
strictEqual(beforeValue, passthru2);
}
});
(0, _emberMetal.instrument)('render', null, function () {});
});
QUnit.test('instrument with 2 args (name, callback) no payload', function () {
expect(1);
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function (name, timestamp, payload) {
deepEqual(payload, {});
},
after: function () {}
});
(0, _emberMetal.instrument)('render', function () {});
});
QUnit.test('instrument with 3 args (name, callback, binding) no payload', function () {
expect(2);
var binding = {};
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function (name, timestamp, payload) {
deepEqual(payload, {});
},
after: function () {}
});
(0, _emberMetal.instrument)('render', function () {
deepEqual(this, binding);
}, binding);
});
QUnit.test('instrument with 3 args (name, payload, callback) with payload', function () {
expect(1);
var expectedPayload = { hi: 1 };
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function (name, timestamp, payload) {
deepEqual(payload, expectedPayload);
},
after: function () {}
});
(0, _emberMetal.instrument)('render', expectedPayload, function () {});
});
QUnit.test('instrument with 4 args (name, payload, callback, binding) with payload', function () {
expect(2);
var expectedPayload = { hi: 1 };
var binding = {};
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function (name, timestamp, payload) {
deepEqual(payload, expectedPayload);
},
after: function () {}
});
(0, _emberMetal.instrument)('render', expectedPayload, function () {
deepEqual(this, binding);
}, binding);
});
QUnit.test('raising an exception in the instrumentation attaches it to the payload', function () {
expect(2);
var error = new Error('Instrumentation');
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function () {},
after: function (name, timestamp, payload) {
strictEqual(payload.exception, error);
}
});
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function () {},
after: function (name, timestamp, payload) {
strictEqual(payload.exception, error);
}
});
(0, _emberMetal.instrument)('render.handlebars', null, function () {
throw error;
});
});
QUnit.test('it is possible to add a new subscriber after the first instrument', function () {
(0, _emberMetal.instrument)('render.handlebars', null, function () {});
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function () {
ok(true, 'Before callback was called');
},
after: function () {
ok(true, 'After callback was called');
}
});
(0, _emberMetal.instrument)('render.handlebars', null, function () {});
});
QUnit.test('it is possible to remove a subscriber', function () {
expect(4);
var count = 0;
var subscriber = (0, _emberMetal.instrumentationSubscribe)('render', {
before: function () {
equal(count, 0);
ok(true, 'Before callback was called');
},
after: function () {
equal(count, 0);
ok(true, 'After callback was called');
count++;
}
});
(0, _emberMetal.instrument)('render.handlebars', null, function () {});
(0, _emberMetal.instrumentationUnsubscribe)(subscriber);
(0, _emberMetal.instrument)('render.handlebars', null, function () {});
});
});
enifed('ember-metal/tests/is_blank_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.isBlank');
QUnit.test('Ember.isBlank', function () {
equal(true, (0, _emberMetal.isBlank)(null), 'for null');
equal(true, (0, _emberMetal.isBlank)(undefined), 'for undefined');
equal(true, (0, _emberMetal.isBlank)(''), 'for an empty String');
equal(true, (0, _emberMetal.isBlank)(' '), 'for a whitespace String');
equal(true, (0, _emberMetal.isBlank)('\n\t'), 'for another whitespace String');
equal(false, (0, _emberMetal.isBlank)('\n\t Hi'), 'for a String with whitespaces');
equal(false, (0, _emberMetal.isBlank)(true), 'for true');
equal(false, (0, _emberMetal.isBlank)(false), 'for false');
equal(false, (0, _emberMetal.isBlank)('string'), 'for a String');
equal(false, (0, _emberMetal.isBlank)(function () {}), 'for a Function');
equal(false, (0, _emberMetal.isBlank)(0), 'for 0');
equal(true, (0, _emberMetal.isBlank)([]), 'for an empty Array');
equal(false, (0, _emberMetal.isBlank)({}), 'for an empty Object');
equal(true, (0, _emberMetal.isBlank)({ length: 0 }), 'for an Object that has zero \'length\'');
equal(false, (0, _emberMetal.isBlank)([1, 2, 3]), 'for a non-empty array');
});
});
enifed('ember-metal/tests/is_empty_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.isEmpty');
QUnit.test('Ember.isEmpty', function () {
equal(true, (0, _emberMetal.isEmpty)(null), 'for null');
equal(true, (0, _emberMetal.isEmpty)(undefined), 'for undefined');
equal(true, (0, _emberMetal.isEmpty)(''), 'for an empty String');
equal(false, (0, _emberMetal.isEmpty)(' '), 'for a whitespace String');
equal(false, (0, _emberMetal.isEmpty)('\n\t'), 'for another whitespace String');
equal(false, (0, _emberMetal.isEmpty)(true), 'for true');
equal(false, (0, _emberMetal.isEmpty)(false), 'for false');
equal(false, (0, _emberMetal.isEmpty)('string'), 'for a String');
equal(false, (0, _emberMetal.isEmpty)(function () {}), 'for a Function');
equal(false, (0, _emberMetal.isEmpty)(0), 'for 0');
equal(true, (0, _emberMetal.isEmpty)([]), 'for an empty Array');
equal(false, (0, _emberMetal.isEmpty)({}), 'for an empty Object');
equal(true, (0, _emberMetal.isEmpty)({ length: 0 }), 'for an Object that has zero \'length\'');
});
QUnit.test('Ember.isEmpty Ember.Map', function () {
var map = new _emberMetal.Map();
equal(true, (0, _emberMetal.isEmpty)(map), 'Empty map is empty');
map.set('foo', 'bar');
equal(false, (0, _emberMetal.isEmpty)(map), 'Map is not empty');
});
QUnit.test('Ember.isEmpty Ember.OrderedSet', function () {
var orderedSet = new _emberMetal.OrderedSet();
equal(true, (0, _emberMetal.isEmpty)(orderedSet), 'Empty ordered set is empty');
orderedSet.add('foo');
equal(false, (0, _emberMetal.isEmpty)(orderedSet), 'Ordered set is not empty');
});
});
enifed('ember-metal/tests/is_none_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.isNone');
QUnit.test('Ember.isNone', function () {
equal(true, (0, _emberMetal.isNone)(null), 'for null');
equal(true, (0, _emberMetal.isNone)(undefined), 'for undefined');
equal(false, (0, _emberMetal.isNone)(''), 'for an empty String');
equal(false, (0, _emberMetal.isNone)(true), 'for true');
equal(false, (0, _emberMetal.isNone)(false), 'for false');
equal(false, (0, _emberMetal.isNone)('string'), 'for a String');
equal(false, (0, _emberMetal.isNone)(function () {}), 'for a Function');
equal(false, (0, _emberMetal.isNone)(0), 'for 0');
equal(false, (0, _emberMetal.isNone)([]), 'for an empty Array');
equal(false, (0, _emberMetal.isNone)({}), 'for an empty Object');
});
});
enifed('ember-metal/tests/is_present_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.isPresent');
QUnit.test('Ember.isPresent', function () {
equal(false, (0, _emberMetal.isPresent)(), 'for no params');
equal(false, (0, _emberMetal.isPresent)(null), 'for null');
equal(false, (0, _emberMetal.isPresent)(undefined), 'for undefined');
equal(false, (0, _emberMetal.isPresent)(''), 'for an empty String');
equal(false, (0, _emberMetal.isPresent)(' '), 'for a whitespace String');
equal(false, (0, _emberMetal.isPresent)('\n\t'), 'for another whitespace String');
equal(true, (0, _emberMetal.isPresent)('\n\t Hi'), 'for a String with whitespaces');
equal(true, (0, _emberMetal.isPresent)(true), 'for true');
equal(true, (0, _emberMetal.isPresent)(false), 'for false');
equal(true, (0, _emberMetal.isPresent)('string'), 'for a String');
equal(true, (0, _emberMetal.isPresent)(function () {}), 'for a Function');
equal(true, (0, _emberMetal.isPresent)(0), 'for 0');
equal(false, (0, _emberMetal.isPresent)([]), 'for an empty Array');
equal(true, (0, _emberMetal.isPresent)({}), 'for an empty Object');
equal(false, (0, _emberMetal.isPresent)({ length: 0 }), 'for an Object that has zero \'length\'');
equal(true, (0, _emberMetal.isPresent)([1, 2, 3]), 'for a non-empty array');
});
});
enifed('ember-metal/tests/libraries_test', ['ember-debug', 'ember-metal'], function (_emberDebug, _emberMetal) {
'use strict';
/* globals EmberDev */
var libs = void 0,
registry = void 0;
var originalWarn = (0, _emberDebug.getDebugFunction)('warn');
QUnit.module('Libraries registry', {
setup: function () {
libs = new _emberMetal.Libraries();
registry = libs._registry;
},
teardown: function () {
libs = null;
registry = null;
(0, _emberDebug.setDebugFunction)('warn', originalWarn);
}
});
QUnit.test('core libraries come before other libraries', function () {
expect(2);
libs.register('my-lib', '2.0.0a');
libs.registerCoreLibrary('DS', '1.0.0-beta.2');
equal(registry[0].name, 'DS');
equal(registry[1].name, 'my-lib');
});
QUnit.test('only the first registration of a library is stored', function () {
expect(3);
libs.register('magic', 1.23);
libs.register('magic', 2.23);
equal(registry[0].name, 'magic');
equal(registry[0].version, 1.23);
equal(registry.length, 1);
});
QUnit.test('attempting to register a library that is already registered warns you', function () {
if (EmberDev && EmberDev.runningProdBuild) {
ok(true, 'Logging does not occur in production builds');
return;
}
expect(1);
libs.register('magic', 1.23);
(0, _emberDebug.setDebugFunction)('warn', function (msg, test) {
if (!test) {
equal(msg, 'Library "magic" is already registered with Ember.');
}
});
// Should warn us
libs.register('magic', 2.23);
});
QUnit.test('libraries can be de-registered', function () {
expect(2);
libs.register('lib1', '1.0.0b');
libs.register('lib2', '1.0.0b');
libs.register('lib3', '1.0.0b');
libs.deRegister('lib1');
libs.deRegister('lib3');
equal(registry[0].name, 'lib2');
equal(registry.length, 1);
});
});
enifed('ember-metal/tests/main_test', ['ember-metal'], function (_emberMetal) {
'use strict';
// testing reexports
// From sindresourhus/semver-regex https://github.com/sindresorhus/semver-regex/blob/795b05628d96597ebcbe6d31ef4a432858365582/index.js#L3
var SEMVER_REGEX = /^\bv?(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?\b$/;
QUnit.module('ember-metal/core/main');
QUnit.test('Ember registers itself', function () {
var lib = _emberMetal.default.libraries._registry[0];
equal(lib.name, 'Ember');
equal(lib.version, _emberMetal.default.VERSION);
});
QUnit.test('Ember.VERSION is in alignment with SemVer v2.0.0', function () {
ok(SEMVER_REGEX.test(_emberMetal.default.VERSION), 'Ember.VERSION (' + _emberMetal.default.VERSION + ')is valid SemVer v2.0.0');
});
QUnit.test('SEMVER_REGEX properly validates and invalidates version numbers', function () {
function validateVersionString(versionString, expectedResult) {
equal(SEMVER_REGEX.test(versionString), expectedResult);
}
// Positive test cases
validateVersionString('1.11.3', true);
validateVersionString('1.0.0-beta.16.1', true);
validateVersionString('1.12.1+canary.aba1412', true);
validateVersionString('2.0.0-beta.1+canary.bb344775', true);
// Negative test cases
validateVersionString('1.11.3.aba18a', false);
validateVersionString('1.11', false);
});
QUnit.test('Ember.Backburner is deprecated', function () {
expectDeprecation(function () {
new _emberMetal.default.Backburner(['foo']);
}, 'Usage of Ember.Backburner is deprecated.');
});
QUnit.test('Ember.K is deprecated', function (assert) {
expectDeprecation(function () {
var obj = {
noop: _emberMetal.default.K
};
assert.equal(obj, obj.noop());
}, 'Ember.K is deprecated in favor of defining a function inline.');
});
});
enifed('ember-metal/tests/map_test', ['ember-metal'], function (_emberMetal) {
'use strict';
var object = void 0,
number = void 0,
string = void 0,
map = void 0,
variety = void 0,
i;
var varieties = [['Map', _emberMetal.Map], ['MapWithDefault', _emberMetal.MapWithDefault]];
function testMap(nameAndFunc) {
variety = nameAndFunc[0];
QUnit.module('Ember.' + variety + ' (forEach and get are implicitly tested)', {
setup: function () {
object = {};
number = 42;
string = 'foo';
map = nameAndFunc[1].create();
}
});
var mapHasLength = function (expected, theMap) {
theMap = theMap || map;
var length = 0;
theMap.forEach(function () {
length++;
});
equal(length, expected, 'map should contain ' + expected + ' items');
};
var mapHasEntries = function (entries, theMap) {
var i;
theMap = theMap || map;
for (i = 0; i < entries.length; i++) {
equal(theMap.get(entries[i][0]), entries[i][1]);
equal(theMap.has(entries[i][0]), true);
}
mapHasLength(entries.length, theMap);
};
var unboundThis = void 0;
(function () {
unboundThis = this;
})();
QUnit.test('set', function () {
map.set(object, 'winning');
map.set(number, 'winning');
map.set(string, 'winning');
mapHasEntries([[object, 'winning'], [number, 'winning'], [string, 'winning']]);
map.set(object, 'losing');
map.set(number, 'losing');
map.set(string, 'losing');
mapHasEntries([[object, 'losing'], [number, 'losing'], [string, 'losing']]);
equal(map.has('nope'), false, 'expected the key `nope` to not be present');
equal(map.has({}), false, 'expected they key `{}` to not be present');
});
QUnit.test('set chaining', function () {
map.set(object, 'winning').set(number, 'winning').set(string, 'winning');
mapHasEntries([[object, 'winning'], [number, 'winning'], [string, 'winning']]);
map.set(object, 'losing').set(number, 'losing').set(string, 'losing');
mapHasEntries([[object, 'losing'], [number, 'losing'], [string, 'losing']]);
equal(map.has('nope'), false, 'expected the key `nope` to not be present');
equal(map.has({}), false, 'expected they key `{}` to not be present');
});
QUnit.test('with key with undefined value', function () {
map.set('foo', undefined);
map.forEach(function (value, key) {
equal(value, undefined);
equal(key, 'foo');
});
ok(map.has('foo'), 'has key foo, even with undefined value');
equal(map.size, 1);
});
QUnit.test('arity of forEach is 1 – es6 23.1.3.5', function () {
equal(map.forEach.length, 1, 'expected arity for map.forEach is 1');
});
QUnit.test('forEach throws without a callback as the first argument', function () {
equal(map.forEach.length, 1, 'expected arity for map.forEach is 1');
});
QUnit.test('has empty collection', function () {
equal(map.has('foo'), false);
equal(map.has(), false);
});
QUnit.test('delete', function () {
expectNoDeprecation();
map.set(object, 'winning');
map.set(number, 'winning');
map.set(string, 'winning');
map.delete(object);
map.delete(number);
map.delete(string);
// doesn't explode
map.delete({});
mapHasEntries([]);
});
QUnit.test('copy and then update', function () {
map.set(object, 'winning');
map.set(number, 'winning');
map.set(string, 'winning');
var map2 = map.copy();
map2.set(object, 'losing');
map2.set(number, 'losing');
map2.set(string, 'losing');
mapHasEntries([[object, 'winning'], [number, 'winning'], [string, 'winning']]);
mapHasEntries([[object, 'losing'], [number, 'losing'], [string, 'losing']], map2);
});
QUnit.test('copy and then delete', function () {
map.set(object, 'winning');
map.set(number, 'winning');
map.set(string, 'winning');
var map2 = map.copy();
map2.delete(object);
map2.delete(number);
map2.delete(string);
mapHasEntries([[object, 'winning'], [number, 'winning'], [string, 'winning']]);
mapHasEntries([], map2);
});
QUnit.test('size', function () {
//Add a key twice
equal(map.size, 0);
map.set(string, 'a string');
equal(map.size, 1);
map.set(string, 'the same string');
equal(map.size, 1);
//Add another
map.set(number, 'a number');
equal(map.size, 2);
//Remove one that doesn't exist
map.delete('does not exist');
equal(map.size, 2);
//Check copy
var copy = map.copy();
equal(copy.size, 2);
//Remove a key twice
map.delete(number);
equal(map.size, 1);
map.delete(number);
equal(map.size, 1);
//Remove the last key
map.delete(string);
equal(map.size, 0);
map.delete(string);
equal(map.size, 0);
});
QUnit.test('forEach without proper callback', function () {
QUnit.throws(function () {
map.forEach();
}, '[object Undefined] is not a function');
QUnit.throws(function () {
map.forEach(undefined);
}, '[object Undefined] is not a function');
QUnit.throws(function () {
map.forEach(1);
}, '[object Number] is not a function');
QUnit.throws(function () {
map.forEach({});
}, '[object Object] is not a function');
map.forEach(function (value, key) {
map.delete(key);
});
// ensure the error happens even if no data is present
equal(map.size, 0);
QUnit.throws(function () {
map.forEach({});
}, '[object Object] is not a function');
});
QUnit.test('forEach basic', function () {
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);
var iteration = 0;
var expectations = [{ value: 1, key: 'a', context: unboundThis }, { value: 2, key: 'b', context: unboundThis }, { value: 3, key: 'c', context: unboundThis }];
map.forEach(function (value, key, theMap) {
var expectation = expectations[iteration];
equal(value, expectation.value, 'value should be correct');
equal(key, expectation.key, 'key should be correct');
equal(this, expectation.context, 'context should be as if it was unbound');
equal(map, theMap, 'map being iterated over should be passed in');
iteration++;
});
equal(iteration, 3, 'expected 3 iterations');
});
QUnit.test('forEach basic /w context', function () {
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);
var iteration = 0;
var context = {};
var expectations = [{ value: 1, key: 'a', context: context }, { value: 2, key: 'b', context: context }, { value: 3, key: 'c', context: context }];
map.forEach(function (value, key, theMap) {
var expectation = expectations[iteration];
equal(value, expectation.value, 'value should be correct');
equal(key, expectation.key, 'key should be correct');
equal(this, expectation.context, 'context should be as if it was unbound');
equal(map, theMap, 'map being iterated over should be passed in');
iteration++;
}, context);
equal(iteration, 3, 'expected 3 iterations');
});
QUnit.test('forEach basic /w deletion while enumerating', function () {
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);
var iteration = 0;
var expectations = [{ value: 1, key: 'a', context: unboundThis }, { value: 2, key: 'b', context: unboundThis }];
map.forEach(function (value, key, theMap) {
if (iteration === 0) {
map.delete('c');
}
var expectation = expectations[iteration];
equal(value, expectation.value, 'value should be correct');
equal(key, expectation.key, 'key should be correct');
equal(this, expectation.context, 'context should be as if it was unbound');
equal(map, theMap, 'map being iterated over should be passed in');
iteration++;
});
equal(iteration, 2, 'expected 3 iterations');
});
QUnit.test('forEach basic /w addition while enumerating', function () {
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);
var iteration = 0;
var expectations = [{ value: 1, key: 'a', context: unboundThis }, { value: 2, key: 'b', context: unboundThis }, { value: 3, key: 'c', context: unboundThis }, { value: 4, key: 'd', context: unboundThis }];
map.forEach(function (value, key, theMap) {
if (iteration === 0) {
map.set('d', 4);
}
var expectation = expectations[iteration];
equal(value, expectation.value, 'value should be correct');
equal(key, expectation.key, 'key should be correct');
equal(this, expectation.context, 'context should be as if it was unbound');
equal(map, theMap, 'map being iterated over should be passed in');
iteration++;
});
equal(iteration, 4, 'expected 3 iterations');
});
QUnit.test('clear', function () {
var iterations = 0;
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);
map.set('d', 4);
equal(map.size, 4);
map.forEach(function () {
iterations++;
});
equal(iterations, 4);
map.clear();
equal(map.size, 0);
iterations = 0;
map.forEach(function () {
iterations++;
});
equal(iterations, 0);
});
QUnit.test('-0', function () {
equal(map.has(-0), false);
equal(map.has(0), false);
map.set(-0, 'zero');
equal(map.has(-0), true);
equal(map.has(0), true);
equal(map.get(0), 'zero');
equal(map.get(-0), 'zero');
map.forEach(function (value, key) {
equal(1 / key, Infinity, 'spec says key should be positive zero');
});
});
QUnit.test('NaN', function () {
equal(map.has(NaN), false);
map.set(NaN, 'not-a-number');
equal(map.has(NaN), true);
equal(map.get(NaN), 'not-a-number');
});
QUnit.test('NaN Boxed', function () {
//jshint -W053
var boxed = new Number(NaN);
equal(map.has(boxed), false);
map.set(boxed, 'not-a-number');
equal(map.has(boxed), true);
equal(map.has(NaN), false);
equal(map.get(NaN), undefined);
equal(map.get(boxed), 'not-a-number');
});
QUnit.test('0 value', function () {
var obj = {};
equal(map.has(obj), false);
equal(map.size, 0);
map.set(obj, 0);
equal(map.size, 1);
equal(map.has(obj), true);
equal(map.get(obj), 0);
map.delete(obj);
equal(map.has(obj), false);
equal(map.get(obj), undefined);
equal(map.size, 0);
});
}
for (i = 0; i < varieties.length; i++) {
testMap(varieties[i]);
}
QUnit.module('MapWithDefault - default values');
QUnit.test('Retrieving a value that has not been set returns and sets a default value', function () {
var map = _emberMetal.MapWithDefault.create({
defaultValue: function (key) {
return [key];
}
});
var value = map.get('ohai');
deepEqual(value, ['ohai']);
strictEqual(value, map.get('ohai'));
});
QUnit.test('Map.prototype.constructor', function () {
var map = new _emberMetal.Map();
equal(map.constructor, _emberMetal.Map);
});
QUnit.test('Map() without `new`', function () {
QUnit.throws(function () {
// jshint newcap:false
(0, _emberMetal.Map)();
}, /Constructor Map requires 'new'/);
});
QUnit.test('MapWithDefault.prototype.constructor', function () {
var map = new _emberMetal.MapWithDefault({
defaultValue: function (key) {
return key;
}
});
equal(map.constructor, _emberMetal.MapWithDefault);
});
QUnit.test('Copying a MapWithDefault copies the default value', function () {
var map = _emberMetal.MapWithDefault.create({
defaultValue: function (key) {
return [key];
}
});
map.set('ohai', 1);
map.get('bai');
var map2 = map.copy();
equal(map2.get('ohai'), 1);
deepEqual(map2.get('bai'), ['bai']);
map2.set('kthx', 3);
deepEqual(map.get('kthx'), ['kthx']);
equal(map2.get('kthx'), 3);
deepEqual(map2.get('default'), ['default']);
map2.defaultValue = function (key) {
return ['tom is on', key];
};
deepEqual(map2.get('drugs'), ['tom is on', 'drugs']);
});
QUnit.module('OrderedSet', {
setup: function () {
object = {};
number = 42;
string = 'foo';
map = _emberMetal.OrderedSet.create();
}
});
QUnit.test('OrderedSet() without `new`', function () {
QUnit.throws(function () {
// jshint newcap:false
(0, _emberMetal.OrderedSet)();
}, /Constructor OrderedSet requires 'new'/);
});
QUnit.test('add returns the set', function () {
var obj = {};
equal(map.add(obj), map);
equal(map.add(obj), map, 'when it is already in the set');
});
});
enifed('ember-metal/tests/meta_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.meta');
QUnit.test('should return the same hash for an object', function () {
var obj = {};
(0, _emberMetal.meta)(obj).foo = 'bar';
equal((0, _emberMetal.meta)(obj).foo, 'bar', 'returns same hash with multiple calls to Ember.meta()');
});
QUnit.test('meta is not enumerable', function () {
var proto = void 0,
obj = void 0,
props = void 0,
prop = void 0;
proto = { foo: 'bar' };
(0, _emberMetal.meta)(proto);
obj = Object.create(proto);
(0, _emberMetal.meta)(obj);
obj.bar = 'baz';
props = [];
for (prop in obj) {
props.push(prop);
}
deepEqual(props.sort(), ['bar', 'foo']);
if (typeof JSON !== 'undefined' && 'stringify' in JSON) {
try {
JSON.stringify(obj);
} catch (e) {
ok(false, 'meta should not fail JSON.stringify');
}
}
});
QUnit.test('meta.listeners basics', function (assert) {
var t = {};
var m = (0, _emberMetal.meta)({});
m.addToListeners('hello', t, 'm', 0);
var matching = m.matchingListeners('hello');
assert.equal(matching.length, 3);
assert.equal(matching[0], t);
m.removeFromListeners('hello', t, 'm');
matching = m.matchingListeners('hello');
assert.equal(matching, undefined);
});
QUnit.test('meta.listeners inheritance', function (assert) {
var target = {};
var parent = {};
var parentMeta = (0, _emberMetal.meta)(parent);
parentMeta.addToListeners('hello', target, 'm', 0);
var child = Object.create(parent);
var m = (0, _emberMetal.meta)(child);
var matching = m.matchingListeners('hello');
assert.equal(matching.length, 3);
assert.equal(matching[0], target);
assert.equal(matching[1], 'm');
assert.equal(matching[2], 0);
m.removeFromListeners('hello', target, 'm');
matching = m.matchingListeners('hello');
assert.equal(matching, undefined);
matching = parentMeta.matchingListeners('hello');
assert.equal(matching.length, 3);
});
QUnit.test('meta.listeners deduplication', function (assert) {
var t = {};
var m = (0, _emberMetal.meta)({});
m.addToListeners('hello', t, 'm', 0);
m.addToListeners('hello', t, 'm', 0);
var matching = m.matchingListeners('hello');
assert.equal(matching.length, 3);
assert.equal(matching[0], t);
});
});
enifed('ember-metal/tests/mixin/alias_method_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('aliasMethod');
function validateAliasMethod(obj) {
equal(obj.fooMethod(), 'FOO', 'obj.fooMethod()');
equal(obj.barMethod(), 'FOO', 'obj.barMethod should be a copy of foo');
}
QUnit.test('methods of another name are aliased when the mixin is applied', function () {
var MyMixin = _emberMetal.Mixin.create({
fooMethod: function () {
return 'FOO';
},
barMethod: (0, _emberMetal.aliasMethod)('fooMethod')
});
var obj = MyMixin.apply({});
validateAliasMethod(obj);
});
QUnit.test('should follow aliasMethods all the way down', function () {
var MyMixin = _emberMetal.Mixin.create({
bar: (0, _emberMetal.aliasMethod)('foo'), baz: function () {
return 'baz';
},
foo: (0, _emberMetal.aliasMethod)('baz')
});
var obj = MyMixin.apply({});
equal((0, _emberMetal.get)(obj, 'bar')(), 'baz', 'should have followed aliasMethods');
});
QUnit.test('should alias methods from other dependent mixins', function () {
var BaseMixin = _emberMetal.Mixin.create({
fooMethod: function () {
return 'FOO';
}
});
var MyMixin = _emberMetal.Mixin.create(BaseMixin, {
barMethod: (0, _emberMetal.aliasMethod)('fooMethod')
});
var obj = MyMixin.apply({});
validateAliasMethod(obj);
});
QUnit.test('should alias methods from other mixins applied at same time', function () {
var BaseMixin = _emberMetal.Mixin.create({
fooMethod: function () {
return 'FOO';
}
});
var MyMixin = _emberMetal.Mixin.create({
barMethod: (0, _emberMetal.aliasMethod)('fooMethod')
});
var obj = (0, _emberMetal.mixin)({}, BaseMixin, MyMixin);
validateAliasMethod(obj);
});
QUnit.test('should alias methods from mixins already applied on object', function () {
var BaseMixin = _emberMetal.Mixin.create({
quxMethod: function () {
return 'qux';
}
});
var MyMixin = _emberMetal.Mixin.create({
bar: (0, _emberMetal.aliasMethod)('foo'),
barMethod: (0, _emberMetal.aliasMethod)('fooMethod')
});
var obj = {
fooMethod: function () {
return 'FOO';
}
};
BaseMixin.apply(obj);
MyMixin.apply(obj);
validateAliasMethod(obj);
});
});
enifed('ember-metal/tests/mixin/apply_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.Mixin.apply');
function K() {}
QUnit.test('using apply() should apply properties', function () {
var MixinA = _emberMetal.Mixin.create({ foo: 'FOO', baz: K });
var obj = {};
(0, _emberMetal.mixin)(obj, MixinA);
equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should apply foo');
equal((0, _emberMetal.get)(obj, 'baz'), K, 'should apply foo');
});
QUnit.test('applying anonymous properties', function () {
var obj = {};
(0, _emberMetal.mixin)(obj, {
foo: 'FOO',
baz: K
});
equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should apply foo');
equal((0, _emberMetal.get)(obj, 'baz'), K, 'should apply foo');
});
QUnit.test('applying null values', function () {
expectAssertion(function () {
return (0, _emberMetal.mixin)({}, null);
});
});
QUnit.test('applying a property with an undefined value', function () {
var obj = { tagName: '' };
(0, _emberMetal.mixin)(obj, { tagName: undefined });
strictEqual((0, _emberMetal.get)(obj, 'tagName'), '');
});
});
enifed('ember-metal/tests/mixin/computed_test', ['ember-metal'], function (_emberMetal) {
'use strict';
function K() {
return this;
}
QUnit.module('Mixin Computed Properties');
QUnit.test('overriding computed properties', function () {
var MixinA = void 0,
MixinB = void 0,
MixinC = void 0,
MixinD = void 0;
var obj = void 0;
MixinA = _emberMetal.Mixin.create({
aProp: (0, _emberMetal.computed)(function () {
return 'A';
})
});
MixinB = _emberMetal.Mixin.create(MixinA, {
aProp: (0, _emberMetal.computed)(function () {
return this._super.apply(this, arguments) + 'B';
})
});
MixinC = _emberMetal.Mixin.create(MixinA, {
aProp: (0, _emberMetal.computed)(function () {
return this._super.apply(this, arguments) + 'C';
})
});
MixinD = _emberMetal.Mixin.create({
aProp: (0, _emberMetal.computed)(function () {
return this._super.apply(this, arguments) + 'D';
})
});
obj = {};
MixinB.apply(obj);
equal((0, _emberMetal.get)(obj, 'aProp'), 'AB', 'should expose super for B');
obj = {};
MixinC.apply(obj);
equal((0, _emberMetal.get)(obj, 'aProp'), 'AC', 'should expose super for C');
obj = {};
MixinA.apply(obj);
MixinD.apply(obj);
equal((0, _emberMetal.get)(obj, 'aProp'), 'AD', 'should define super for D');
obj = {};
(0, _emberMetal.defineProperty)(obj, 'aProp', (0, _emberMetal.computed)(function () {
return 'obj';
}));
MixinD.apply(obj);
equal((0, _emberMetal.get)(obj, 'aProp'), 'objD', 'should preserve original computed property');
});
QUnit.test('calling set on overridden computed properties', function () {
var SuperMixin = void 0,
SubMixin = void 0;
var obj = void 0;
var superGetOccurred = false;
var superSetOccurred = false;
SuperMixin = _emberMetal.Mixin.create({
aProp: (0, _emberMetal.computed)({
get: function () {
superGetOccurred = true;
},
set: function () {
superSetOccurred = true;
}
})
});
SubMixin = _emberMetal.Mixin.create(SuperMixin, {
aProp: (0, _emberMetal.computed)({
get: function () {
return this._super.apply(this, arguments);
},
set: function () {
return this._super.apply(this, arguments);
}
})
});
obj = {};
SubMixin.apply(obj);
(0, _emberMetal.set)(obj, 'aProp', 'set thyself');
ok(superSetOccurred, 'should pass set to _super');
superSetOccurred = false; // reset the set assertion
obj = {};
SubMixin.apply(obj);
(0, _emberMetal.get)(obj, 'aProp');
ok(superGetOccurred, 'should pass get to _super');
(0, _emberMetal.set)(obj, 'aProp', 'set thyself');
ok(superSetOccurred, 'should pass set to _super after getting');
});
QUnit.test('setter behavior works properly when overriding computed properties', function () {
var obj = {};
var MixinA = _emberMetal.Mixin.create({
cpWithSetter2: (0, _emberMetal.computed)(K),
cpWithSetter3: (0, _emberMetal.computed)(K),
cpWithoutSetter: (0, _emberMetal.computed)(K)
});
var cpWasCalled = false;
var MixinB = _emberMetal.Mixin.create({
cpWithSetter2: (0, _emberMetal.computed)({
get: K,
set: function () {
cpWasCalled = true;
}
}),
cpWithSetter3: (0, _emberMetal.computed)({
get: K,
set: function () {
cpWasCalled = true;
}
}),
cpWithoutSetter: (0, _emberMetal.computed)(function () {
cpWasCalled = true;
})
});
MixinA.apply(obj);
MixinB.apply(obj);
(0, _emberMetal.set)(obj, 'cpWithSetter2', 'test');
ok(cpWasCalled, 'The computed property setter was called when defined with two args');
cpWasCalled = false;
(0, _emberMetal.set)(obj, 'cpWithSetter3', 'test');
ok(cpWasCalled, 'The computed property setter was called when defined with three args');
cpWasCalled = false;
(0, _emberMetal.set)(obj, 'cpWithoutSetter', 'test');
equal((0, _emberMetal.get)(obj, 'cpWithoutSetter'), 'test', 'The default setter was called, the value is correct');
ok(!cpWasCalled, 'The default setter was called, not the CP itself');
});
});
enifed('ember-metal/tests/mixin/concatenated_properties_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Mixin concatenatedProperties');
QUnit.test('defining concatenated properties should concat future version', function () {
var MixinA = _emberMetal.Mixin.create({
concatenatedProperties: ['foo'],
foo: ['a', 'b', 'c']
});
var MixinB = _emberMetal.Mixin.create({
foo: ['d', 'e', 'f']
});
var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB);
deepEqual((0, _emberMetal.get)(obj, 'foo'), ['a', 'b', 'c', 'd', 'e', 'f']);
});
QUnit.test('defining concatenated properties should concat future version', function () {
var MixinA = _emberMetal.Mixin.create({
concatenatedProperties: null
});
var MixinB = _emberMetal.Mixin.create({
concatenatedProperties: null
});
var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB);
deepEqual(obj.concatenatedProperties, []);
});
QUnit.test('concatenatedProperties should be concatenated', function () {
var MixinA = _emberMetal.Mixin.create({
concatenatedProperties: ['foo'],
foo: ['a', 'b', 'c']
});
var MixinB = _emberMetal.Mixin.create({
concatenatedProperties: 'bar',
foo: ['d', 'e', 'f'],
bar: [1, 2, 3]
});
var MixinC = _emberMetal.Mixin.create({
bar: [4, 5, 6]
});
var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB, MixinC);
deepEqual((0, _emberMetal.get)(obj, 'concatenatedProperties'), ['foo', 'bar'], 'get concatenatedProperties');
deepEqual((0, _emberMetal.get)(obj, 'foo'), ['a', 'b', 'c', 'd', 'e', 'f'], 'get foo');
deepEqual((0, _emberMetal.get)(obj, 'bar'), [1, 2, 3, 4, 5, 6], 'get bar');
});
QUnit.test('adding a prop that is not an array should make array', function () {
var MixinA = _emberMetal.Mixin.create({
concatenatedProperties: ['foo'],
foo: [1, 2, 3]
});
var MixinB = _emberMetal.Mixin.create({
foo: 4
});
var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB);
deepEqual((0, _emberMetal.get)(obj, 'foo'), [1, 2, 3, 4]);
});
QUnit.test('adding a prop that is not an array should make array', function () {
var MixinA = _emberMetal.Mixin.create({
concatenatedProperties: ['foo'],
foo: 'bar'
});
var obj = (0, _emberMetal.mixin)({}, MixinA);
deepEqual((0, _emberMetal.get)(obj, 'foo'), ['bar']);
});
QUnit.test('adding a non-concatenable property that already has a defined value should result in an array with both values', function () {
var mixinA = _emberMetal.Mixin.create({
foo: 1
});
var mixinB = _emberMetal.Mixin.create({
concatenatedProperties: ['foo'],
foo: 2
});
var obj = (0, _emberMetal.mixin)({}, mixinA, mixinB);
deepEqual((0, _emberMetal.get)(obj, 'foo'), [1, 2]);
});
QUnit.test('adding a concatenable property that already has a defined value should result in a concatenated value', function () {
var mixinA = _emberMetal.Mixin.create({
foobar: 'foo'
});
var mixinB = _emberMetal.Mixin.create({
concatenatedProperties: ['foobar'],
foobar: 'bar'
});
var obj = (0, _emberMetal.mixin)({}, mixinA, mixinB);
deepEqual((0, _emberMetal.get)(obj, 'foobar'), ['foo', 'bar']);
});
});
enifed('ember-metal/tests/mixin/detect_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Mixin.detect');
QUnit.test('detect() finds a directly applied mixin', function () {
var MixinA = _emberMetal.Mixin.create();
var obj = {};
equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()');
MixinA.apply(obj);
equal(MixinA.detect(obj), true, 'MixinA.detect(obj) after apply()');
});
QUnit.test('detect() finds nested mixins', function () {
var MixinA = _emberMetal.Mixin.create({});
var MixinB = _emberMetal.Mixin.create(MixinA);
var obj = {};
equal(MixinA.detect(obj), false, 'MixinA.detect(obj) before apply()');
MixinB.apply(obj);
equal(MixinA.detect(obj), true, 'MixinA.detect(obj) after apply()');
});
QUnit.test('detect() finds mixins on other mixins', function () {
var MixinA = _emberMetal.Mixin.create({});
var MixinB = _emberMetal.Mixin.create(MixinA);
equal(MixinA.detect(MixinB), true, 'MixinA is part of MixinB');
equal(MixinB.detect(MixinA), false, 'MixinB is not part of MixinA');
});
QUnit.test('detect handles null values', function () {
var MixinA = _emberMetal.Mixin.create();
equal(MixinA.detect(null), false);
});
});
enifed('ember-metal/tests/mixin/introspection_test', ['ember-utils', 'ember-metal'], function (_emberUtils, _emberMetal) {
'use strict';
// NOTE: A previous iteration differentiated between public and private props
// as well as methods vs props. We are just keeping these for testing; the
// current impl doesn't care about the differences as much...
var PrivateProperty = _emberMetal.Mixin.create({
_foo: '_FOO'
});
var PublicProperty = _emberMetal.Mixin.create({
foo: 'FOO'
});
var PrivateMethod = _emberMetal.Mixin.create({
_fooMethod: function () {}
});
var PublicMethod = _emberMetal.Mixin.create({
fooMethod: function () {}
});
var BarProperties = _emberMetal.Mixin.create({
_bar: '_BAR',
bar: 'bar'
});
var BarMethods = _emberMetal.Mixin.create({
_barMethod: function () {},
barMethod: function () {}
});
var Combined = _emberMetal.Mixin.create(BarProperties, BarMethods);
var obj = void 0;
QUnit.module('Basic introspection', {
setup: function () {
obj = {};
(0, _emberMetal.mixin)(obj, PrivateProperty, PublicProperty, PrivateMethod, PublicMethod, Combined);
}
});
QUnit.test('Ember.mixins()', function () {
function mapGuids(ary) {
return ary.map(function (x) {
return (0, _emberUtils.guidFor)(x);
});
}
deepEqual(mapGuids(_emberMetal.Mixin.mixins(obj)), mapGuids([PrivateProperty, PublicProperty, PrivateMethod, PublicMethod, Combined, BarProperties, BarMethods]), 'should return included mixins');
});
});
enifed('ember-metal/tests/mixin/merged_properties_test', ['ember-runtime', 'ember-metal'], function (_emberRuntime, _emberMetal) {
'use strict';
QUnit.module('Mixin mergedProperties');
QUnit.test('defining mergedProperties should merge future version', function () {
var MixinA = _emberMetal.Mixin.create({
mergedProperties: ['foo'],
foo: { a: true, b: true, c: true }
});
var MixinB = _emberMetal.Mixin.create({
foo: { d: true, e: true, f: true }
});
var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB);
deepEqual((0, _emberMetal.get)(obj, 'foo'), { a: true, b: true, c: true, d: true, e: true, f: true });
});
QUnit.test('defining mergedProperties on future mixin should merged into past', function () {
var MixinA = _emberMetal.Mixin.create({
foo: { a: true, b: true, c: true }
});
var MixinB = _emberMetal.Mixin.create({
mergedProperties: ['foo'],
foo: { d: true, e: true, f: true }
});
var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB);
deepEqual((0, _emberMetal.get)(obj, 'foo'), { a: true, b: true, c: true, d: true, e: true, f: true });
});
QUnit.test('defining mergedProperties with null properties should keep properties null', function () {
var MixinA = _emberMetal.Mixin.create({
mergedProperties: ['foo'],
foo: null
});
var MixinB = _emberMetal.Mixin.create({
foo: null
});
var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB);
equal((0, _emberMetal.get)(obj, 'foo'), null);
});
QUnit.test('mergedProperties\' properties can get overwritten', function () {
var MixinA = _emberMetal.Mixin.create({
mergedProperties: ['foo'],
foo: { a: 1 }
});
var MixinB = _emberMetal.Mixin.create({
foo: { a: 2 }
});
var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB);
deepEqual((0, _emberMetal.get)(obj, 'foo'), { a: 2 });
});
QUnit.test('mergedProperties should be concatenated', function () {
var MixinA = _emberMetal.Mixin.create({
mergedProperties: ['foo'],
foo: { a: true, b: true, c: true }
});
var MixinB = _emberMetal.Mixin.create({
mergedProperties: 'bar',
foo: { d: true, e: true, f: true },
bar: { a: true, l: true }
});
var MixinC = _emberMetal.Mixin.create({
bar: { e: true, x: true }
});
var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB, MixinC);
deepEqual((0, _emberMetal.get)(obj, 'mergedProperties'), ['foo', 'bar'], 'get mergedProperties');
deepEqual((0, _emberMetal.get)(obj, 'foo'), { a: true, b: true, c: true, d: true, e: true, f: true }, 'get foo');
deepEqual((0, _emberMetal.get)(obj, 'bar'), { a: true, l: true, e: true, x: true }, 'get bar');
});
QUnit.test('mergedProperties should exist even if not explicitly set on create', function () {
var AnObj = _emberRuntime.Object.extend({
mergedProperties: ['options'],
options: {
a: 'a',
b: {
c: 'ccc'
}
}
});
var obj = AnObj.create({
options: {
a: 'A'
}
});
equal((0, _emberMetal.get)(obj, 'options').a, 'A');
equal((0, _emberMetal.get)(obj, 'options').b.c, 'ccc');
});
QUnit.test('defining mergedProperties at create time should not modify the prototype', function () {
var AnObj = _emberRuntime.Object.extend({
mergedProperties: ['options'],
options: {
a: 1
}
});
var objA = AnObj.create({
options: {
a: 2
}
});
var objB = AnObj.create({
options: {
a: 3
}
});
equal((0, _emberMetal.get)(objA, 'options').a, 2);
equal((0, _emberMetal.get)(objB, 'options').a, 3);
});
QUnit.test('mergedProperties\' overwriting methods can call _super', function () {
expect(4);
var MixinA = _emberMetal.Mixin.create({
mergedProperties: ['foo'],
foo: {
meth: function (a) {
equal(a, 'WOOT', '_super successfully called MixinA\'s `foo.meth` method');
return 'WAT';
}
}
});
var MixinB = _emberMetal.Mixin.create({
foo: {
meth: function () {
ok(true, 'MixinB\'s `foo.meth` method called');
return this._super.apply(this, arguments);
}
}
});
var MixinC = _emberMetal.Mixin.create({
foo: {
meth: function (a) {
ok(true, 'MixinC\'s `foo.meth` method called');
return this._super(a);
}
}
});
var obj = (0, _emberMetal.mixin)({}, MixinA, MixinB, MixinC);
equal(obj.foo.meth('WOOT'), 'WAT');
});
QUnit.test('Merging an Array should raise an error', function () {
expect(1);
var MixinA = _emberMetal.Mixin.create({
mergedProperties: ['foo'],
foo: { a: true, b: true, c: true }
});
var MixinB = _emberMetal.Mixin.create({
foo: ['a']
});
expectAssertion(function () {
(0, _emberMetal.mixin)({}, MixinA, MixinB);
}, 'You passed in `["a"]` as the value for `foo` but `foo` cannot be an Array');
});
});
enifed('ember-metal/tests/mixin/method_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Mixin Methods');
QUnit.test('defining simple methods', function () {
var MixinA = void 0,
obj = void 0,
props = void 0;
props = {
publicMethod: function () {
return 'publicMethod';
},
_privateMethod: function () {
return 'privateMethod';
}
};
MixinA = _emberMetal.Mixin.create(props);
obj = {};
MixinA.apply(obj);
// but should be defined
equal(props.publicMethod(), 'publicMethod', 'publicMethod is func');
equal(props._privateMethod(), 'privateMethod', 'privateMethod is func');
});
QUnit.test('overriding public methods', function () {
var MixinA = void 0,
MixinB = void 0,
MixinD = void 0,
MixinF = void 0,
obj = void 0;
MixinA = _emberMetal.Mixin.create({
publicMethod: function () {
return 'A';
}
});
MixinB = _emberMetal.Mixin.create(MixinA, {
publicMethod: function () {
return this._super.apply(this, arguments) + 'B';
}
});
MixinD = _emberMetal.Mixin.create(MixinA, {
publicMethod: function () {
return this._super.apply(this, arguments) + 'D';
}
});
MixinF = _emberMetal.Mixin.create({
publicMethod: function () {
return this._super.apply(this, arguments) + 'F';
}
});
obj = {};
MixinB.apply(obj);
equal(obj.publicMethod(), 'AB', 'should define super for A and B');
obj = {};
MixinD.apply(obj);
equal(obj.publicMethod(), 'AD', 'should define super for A and B');
obj = {};
MixinA.apply(obj);
MixinF.apply(obj);
equal(obj.publicMethod(), 'AF', 'should define super for A and F');
obj = {
publicMethod: function () {
return 'obj';
}
};
MixinF.apply(obj);
equal(obj.publicMethod(), 'objF', 'should define super for F');
});
QUnit.test('overriding inherited objects', function () {
var cnt = 0;
var MixinA = _emberMetal.Mixin.create({
foo: function () {
cnt++;
}
});
var MixinB = _emberMetal.Mixin.create({
foo: function () {
this._super.apply(this, arguments);
cnt++;
}
});
var objA = {};
MixinA.apply(objA);
var objB = Object.create(objA);
MixinB.apply(objB);
cnt = 0;
objB.foo();
equal(cnt, 2, 'should invoke both methods');
cnt = 0;
objA.foo();
equal(cnt, 1, 'should not screw w/ parent obj');
});
QUnit.test('Including the same mixin more than once will only run once', function () {
var cnt = 0;
var MixinA = _emberMetal.Mixin.create({
foo: function () {
cnt++;
}
});
var MixinB = _emberMetal.Mixin.create(MixinA, {
foo: function () {
this._super.apply(this, arguments);
}
});
var MixinC = _emberMetal.Mixin.create(MixinA, {
foo: function () {
this._super.apply(this, arguments);
}
});
var MixinD = _emberMetal.Mixin.create(MixinB, MixinC, MixinA, {
foo: function () {
this._super.apply(this, arguments);
}
});
var obj = {};
MixinD.apply(obj);
MixinA.apply(obj); // try to apply again..
cnt = 0;
obj.foo();
equal(cnt, 1, 'should invoke MixinA.foo one time');
});
QUnit.test('_super from a single mixin with no superclass does not error', function () {
var MixinA = _emberMetal.Mixin.create({
foo: function () {
this._super.apply(this, arguments);
}
});
var obj = {};
MixinA.apply(obj);
obj.foo();
ok(true);
});
QUnit.test('_super from a first-of-two mixins with no superclass function does not error', function () {
// _super was previously calling itself in the second assertion.
// Use remaining count of calls to ensure it doesn't loop indefinitely.
var remaining = 3;
var MixinA = _emberMetal.Mixin.create({
foo: function () {
if (remaining-- > 0) {
this._super.apply(this, arguments);
}
}
});
var MixinB = _emberMetal.Mixin.create({
foo: function () {
this._super.apply(this, arguments);
}
});
var obj = {};
MixinA.apply(obj);
MixinB.apply(obj);
obj.foo();
ok(true);
});
// ..........................................................
// CONFLICTS
//
QUnit.module('Method Conflicts');
QUnit.test('overriding toString', function () {
var MixinA = _emberMetal.Mixin.create({
toString: function () {
return 'FOO';
}
});
var obj = {};
MixinA.apply(obj);
equal(obj.toString(), 'FOO', 'should override toString w/o error');
obj = {};
(0, _emberMetal.mixin)(obj, {
toString: function () {
return 'FOO';
}
});
equal(obj.toString(), 'FOO', 'should override toString w/o error');
});
// ..........................................................
// BUGS
//
QUnit.module('system/mixin/method_test BUGS');
QUnit.test('applying several mixins at once with sup already defined causes infinite loop', function () {
var cnt = 0;
var MixinA = _emberMetal.Mixin.create({
foo: function () {
cnt++;
}
});
var MixinB = _emberMetal.Mixin.create({
foo: function () {
this._super.apply(this, arguments);
cnt++;
}
});
var MixinC = _emberMetal.Mixin.create({
foo: function () {
this._super.apply(this, arguments);
cnt++;
}
});
var obj = {};
(0, _emberMetal.mixin)(obj, MixinA); // sup already exists
(0, _emberMetal.mixin)(obj, MixinB, MixinC); // must be more than one mixin
cnt = 0;
obj.foo();
equal(cnt, 3, 'should invoke all 3 methods');
});
});
enifed('ember-metal/tests/mixin/observer_test', ['internal-test-helpers', 'ember-metal'], function (_internalTestHelpers, _emberMetal) {
'use strict';
QUnit.module('Mixin observer');
(0, _internalTestHelpers.testBoth)('global observer helper', function (get, set) {
var MyMixin = _emberMetal.Mixin.create({
count: 0,
foo: (0, _emberMetal.observer)('bar', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj = (0, _emberMetal.mixin)({}, MyMixin);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj, 'bar', 'BAZ');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('global observer helper takes multiple params', function (get, set) {
var MyMixin = _emberMetal.Mixin.create({
count: 0,
foo: (0, _emberMetal.observer)('bar', 'baz', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj = (0, _emberMetal.mixin)({}, MyMixin);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj, 'bar', 'BAZ');
set(obj, 'baz', 'BAZ');
equal(get(obj, 'count'), 2, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('replacing observer should remove old observer', function (get, set) {
var MyMixin = _emberMetal.Mixin.create({
count: 0,
foo: (0, _emberMetal.observer)('bar', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var Mixin2 = _emberMetal.Mixin.create({
foo: (0, _emberMetal.observer)('baz', function () {
set(this, 'count', get(this, 'count') + 10);
})
});
var obj = (0, _emberMetal.mixin)({}, MyMixin, Mixin2);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj, 'bar', 'BAZ');
equal(get(obj, 'count'), 0, 'should not invoke observer after change');
set(obj, 'baz', 'BAZ');
equal(get(obj, 'count'), 10, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('observing chain with property before', function (get, set) {
var obj2 = { baz: 'baz' };
var MyMixin = _emberMetal.Mixin.create({
count: 0,
bar: obj2,
foo: (0, _emberMetal.observer)('bar.baz', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj = (0, _emberMetal.mixin)({}, MyMixin);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj2, 'baz', 'BAZ');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('observing chain with property after', function (get, set) {
var obj2 = { baz: 'baz' };
var MyMixin = _emberMetal.Mixin.create({
count: 0,
foo: (0, _emberMetal.observer)('bar.baz', function () {
set(this, 'count', get(this, 'count') + 1);
}),
bar: obj2
});
var obj = (0, _emberMetal.mixin)({}, MyMixin);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj2, 'baz', 'BAZ');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('observing chain with property in mixin applied later', function (get, set) {
var obj2 = { baz: 'baz' };
var MyMixin = _emberMetal.Mixin.create({
count: 0,
foo: (0, _emberMetal.observer)('bar.baz', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var MyMixin2 = _emberMetal.Mixin.create({ bar: obj2 });
var obj = (0, _emberMetal.mixin)({}, MyMixin);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
MyMixin2.apply(obj);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj2, 'baz', 'BAZ');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('observing chain with existing property', function (get, set) {
var obj2 = { baz: 'baz' };
var MyMixin = _emberMetal.Mixin.create({
count: 0,
foo: (0, _emberMetal.observer)('bar.baz', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj = (0, _emberMetal.mixin)({ bar: obj2 }, MyMixin);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj2, 'baz', 'BAZ');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('observing chain with property in mixin before', function (get, set) {
var obj2 = { baz: 'baz' };
var MyMixin2 = _emberMetal.Mixin.create({ bar: obj2 });
var MyMixin = _emberMetal.Mixin.create({
count: 0,
foo: (0, _emberMetal.observer)('bar.baz', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj = (0, _emberMetal.mixin)({}, MyMixin2, MyMixin);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj2, 'baz', 'BAZ');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('observing chain with property in mixin after', function (get, set) {
var obj2 = { baz: 'baz' };
var MyMixin2 = _emberMetal.Mixin.create({ bar: obj2 });
var MyMixin = _emberMetal.Mixin.create({
count: 0,
foo: (0, _emberMetal.observer)('bar.baz', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj = (0, _emberMetal.mixin)({}, MyMixin, MyMixin2);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj2, 'baz', 'BAZ');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('observing chain with overriden property', function (get, set) {
var obj2 = { baz: 'baz' };
var obj3 = { baz: 'foo' };
var MyMixin2 = _emberMetal.Mixin.create({ bar: obj3 });
var MyMixin = _emberMetal.Mixin.create({
count: 0,
foo: (0, _emberMetal.observer)('bar.baz', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj = (0, _emberMetal.mixin)({ bar: obj2 }, MyMixin, MyMixin2);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
equal((0, _emberMetal.isWatching)(obj2, 'baz'), false, 'should not be watching baz');
equal((0, _emberMetal.isWatching)(obj3, 'baz'), true, 'should be watching baz');
set(obj2, 'baz', 'BAZ');
equal(get(obj, 'count'), 0, 'should not invoke observer after change');
set(obj3, 'baz', 'BEAR');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('providing the arguments in reverse order is deprecated', function (get, set) {
expectDeprecation(/Passing the dependentKeys after the callback function in Ember\.observer is deprecated. Ensure the callback function is the last argument/);
_emberMetal.Mixin.create({
count: 0,
foo: (0, _emberMetal.observer)(function () {
set(this, 'count', get(this, 'count') + 1);
}, 'bar.baz')
});
});
});
enifed('ember-metal/tests/mixin/reopen_test', ['ember-runtime', 'ember-metal'], function (_emberRuntime, _emberMetal) {
'use strict';
QUnit.module('Ember.Mixin#reopen');
QUnit.test('using reopen() to add more properties to a simple', function () {
var MixinA = _emberMetal.Mixin.create({ foo: 'FOO', baz: 'BAZ' });
MixinA.reopen({ bar: 'BAR', foo: 'FOO2' });
var obj = {};
MixinA.apply(obj);
equal((0, _emberMetal.get)(obj, 'foo'), 'FOO2', 'mixin() should override');
equal((0, _emberMetal.get)(obj, 'baz'), 'BAZ', 'preserve MixinA props');
equal((0, _emberMetal.get)(obj, 'bar'), 'BAR', 'include MixinB props');
});
QUnit.test('using reopen() and calling _super where there is not a super function does not cause infinite recursion', function () {
var Taco = _emberRuntime.Object.extend({
createBreakfast: function () {
// There is no original createBreakfast function.
// Calling the wrapped _super function here
// used to end in an infinite call loop
this._super.apply(this, arguments);
return 'Breakfast!';
}
});
Taco.reopen({
createBreakfast: function () {
return this._super.apply(this, arguments);
}
});
var taco = Taco.create();
var result = void 0;
(0, _emberMetal.run)(function () {
try {
result = taco.createBreakfast();
} catch (e) {
result = 'Your breakfast was interrupted by an infinite stack error.';
}
});
equal(result, 'Breakfast!');
});
});
enifed('ember-metal/tests/mixin/required_test', ['ember-metal'], function (_emberMetal) {
'use strict';
var PartialMixin = void 0,
FinalMixin = void 0,
obj = void 0;
QUnit.module('Module.required', {
setup: function () {
expectDeprecation(function () {
PartialMixin = _emberMetal.Mixin.create({
foo: (0, _emberMetal.required)(),
bar: 'BAR'
});
}, 'Ember.required is deprecated as its behavior is inconsistent and unreliable.');
FinalMixin = _emberMetal.Mixin.create({
foo: 'FOO'
});
obj = {};
},
teardown: function () {
PartialMixin = FinalMixin = obj = null;
}
});
QUnit.test('applying a mixin to meet requirement', function () {
FinalMixin.apply(obj);
PartialMixin.apply(obj);
equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should now be defined');
});
QUnit.test('combined mixins to meet requirement', function () {
_emberMetal.Mixin.create(PartialMixin, FinalMixin).apply(obj);
equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should now be defined');
});
QUnit.test('merged mixin', function () {
_emberMetal.Mixin.create(PartialMixin, { foo: 'FOO' }).apply(obj);
equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should now be defined');
});
QUnit.test('define property on source object', function () {
obj.foo = 'FOO';
PartialMixin.apply(obj);
equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should now be defined');
});
QUnit.test('using apply', function () {
(0, _emberMetal.mixin)(obj, PartialMixin, { foo: 'FOO' });
equal((0, _emberMetal.get)(obj, 'foo'), 'FOO', 'should now be defined');
});
});
enifed('ember-metal/tests/mixin/without_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.test('without should create a new mixin excluding named properties', function () {
var MixinA = _emberMetal.Mixin.create({
foo: 'FOO',
bar: 'BAR'
});
var MixinB = MixinA.without('bar');
var obj = {};
MixinB.apply(obj);
equal(obj.foo, 'FOO', 'should defined foo');
equal(obj.bar, undefined, 'should not define bar');
});
});
enifed('ember-metal/tests/observer_test', ['ember-environment', 'internal-test-helpers', 'ember-metal'], function (_emberEnvironment, _internalTestHelpers, _emberMetal) {
'use strict';
function K() {}
// ..........................................................
// ADD OBSERVER
//
QUnit.module('addObserver');
(0, _internalTestHelpers.testBoth)('observer should fire when property is modified', function (get, set) {
var obj = {};
var count = 0;
(0, _emberMetal.addObserver)(obj, 'foo', function () {
equal(get(obj, 'foo'), 'bar', 'should invoke AFTER value changed');
count++;
});
set(obj, 'foo', 'bar');
equal(count, 1, 'should have invoked observer');
});
(0, _internalTestHelpers.testBoth)('observer should fire when dependent property is modified', function (get, set) {
var obj = { bar: 'bar' };
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {
return get(this, 'bar').toUpperCase();
}).property('bar'));
get(obj, 'foo');
var count = 0;
(0, _emberMetal.addObserver)(obj, 'foo', function () {
equal(get(obj, 'foo'), 'BAZ', 'should have invoked after prop change');
count++;
});
set(obj, 'bar', 'baz');
equal(count, 1, 'should have invoked observer');
});
(0, _internalTestHelpers.testBoth)('observer should continue to fire after dependent properties are accessed', function (get) {
var observerCount = 0,
i;
var obj = {};
(0, _emberMetal.defineProperty)(obj, 'prop', (0, _emberMetal.computed)(function () {
return Math.random();
}));
(0, _emberMetal.defineProperty)(obj, 'anotherProp', (0, _emberMetal.computed)('prop', function () {
return get(this, 'prop') + Math.random();
}));
(0, _emberMetal.addObserver)(obj, 'prop', function () {
observerCount++;
});
get(obj, 'anotherProp');
for (i = 0; i < 10; i++) {
(0, _emberMetal.propertyWillChange)(obj, 'prop');
(0, _emberMetal.propertyDidChange)(obj, 'prop');
}
equal(observerCount, 10, 'should continue to fire indefinitely');
});
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) {
(0, _internalTestHelpers.testBoth)('observer added declaratively via brace expansion should fire when property changes', function (get, set) {
var obj = {};
var count = 0;
(0, _emberMetal.mixin)(obj, {
observeFooAndBar: function () {
count++;
}.observes('{foo,bar}')
});
set(obj, 'foo', 'foo');
equal(count, 1, 'observer specified via brace expansion invoked on property change');
set(obj, 'bar', 'bar');
equal(count, 2, 'observer specified via brace expansion invoked on property change');
set(obj, 'baz', 'baz');
equal(count, 2, 'observer not invoked on unspecified property');
});
(0, _internalTestHelpers.testBoth)('observer specified declaratively via brace expansion should fire when dependent property changes', function (get, set) {
var obj = { baz: 'Initial' };
var count = 0;
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {
return get(this, 'bar').toLowerCase();
}).property('bar'));
(0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)(function () {
return get(this, 'baz').toUpperCase();
}).property('baz'));
(0, _emberMetal.mixin)(obj, {
fooAndBarWatcher: function () {
count++;
}.observes('{foo,bar}')
});
get(obj, 'foo');
set(obj, 'baz', 'Baz');
// fire once for foo, once for bar
equal(count, 2, 'observer specified via brace expansion invoked on dependent property change');
set(obj, 'quux', 'Quux');
equal(count, 2, 'observer not fired on unspecified property');
});
}
(0, _internalTestHelpers.testBoth)('observers watching multiple properties via brace expansion should fire when the properties change', function (get, set) {
var obj = {};
var count = 0;
(0, _emberMetal.mixin)(obj, {
observeFooAndBar: (0, _emberMetal.observer)('{foo,bar}', function () {
count++;
})
});
set(obj, 'foo', 'foo');
equal(count, 1, 'observer specified via brace expansion invoked on property change');
set(obj, 'bar', 'bar');
equal(count, 2, 'observer specified via brace expansion invoked on property change');
set(obj, 'baz', 'baz');
equal(count, 2, 'observer not invoked on unspecified property');
});
(0, _internalTestHelpers.testBoth)('observers watching multiple properties via brace expansion should fire when dependent properties change', function (get, set) {
var obj = { baz: 'Initial' };
var count = 0;
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {
return get(this, 'bar').toLowerCase();
}).property('bar'));
(0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)(function () {
return get(this, 'baz').toUpperCase();
}).property('baz'));
(0, _emberMetal.mixin)(obj, {
fooAndBarWatcher: (0, _emberMetal.observer)('{foo,bar}', function () {
count++;
})
});
get(obj, 'foo');
set(obj, 'baz', 'Baz');
// fire once for foo, once for bar
equal(count, 2, 'observer specified via brace expansion invoked on dependent property change');
set(obj, 'quux', 'Quux');
equal(count, 2, 'observer not fired on unspecified property');
});
(0, _internalTestHelpers.testBoth)('nested observers should fire in order', function (get, set) {
var obj = { foo: 'foo', bar: 'bar' };
var fooCount = 0;
var barCount = 0;
(0, _emberMetal.addObserver)(obj, 'foo', function () {
fooCount++;
});
(0, _emberMetal.addObserver)(obj, 'bar', function () {
set(obj, 'foo', 'BAZ');
equal(fooCount, 1, 'fooCount should have fired already');
barCount++;
});
set(obj, 'bar', 'BIFF');
equal(barCount, 1, 'barCount should have fired');
equal(fooCount, 1, 'foo should have fired');
});
(0, _internalTestHelpers.testBoth)('removing an chain observer on change should not fail', function (get, set) {
var foo = { bar: 'bar' };
var obj1 = { foo: foo };
var obj2 = { foo: foo };
var obj4 = { foo: foo };
var count1 = 0;
var count2 = 0;
var count3 = 0;
var count4 = 0;
function observer1() {
count1++;
}
function observer2() {
count2++;
}
function observer4() {
count4++;
}
(0, _emberMetal.addObserver)(obj1, 'foo.bar', observer1);
(0, _emberMetal.addObserver)(obj2, 'foo.bar', observer2);
(0, _emberMetal.addObserver)({ foo: foo }, 'foo.bar', function () {
count3++;
(0, _emberMetal.removeObserver)(obj1, 'foo.bar', observer1);
(0, _emberMetal.removeObserver)(obj2, 'foo.bar', observer2);
(0, _emberMetal.removeObserver)(obj4, 'foo.bar', observer4);
});
(0, _emberMetal.addObserver)(obj4, 'foo.bar', observer4);
set(foo, 'bar', 'baz');
equal(count1, 1, 'observer1 fired');
equal(count2, 1, 'observer2 fired');
equal(count3, 1, 'observer3 fired');
equal(count4, 0, 'observer4 did not fire');
});
(0, _internalTestHelpers.testBoth)('removing an chain before observer on change should not fail', function (get, set) {
var foo = { bar: 'bar' };
var obj1 = { foo: foo };
var obj2 = { foo: foo };
var obj4 = { foo: foo };
var count1 = 0;
var count2 = 0;
var count3 = 0;
var count4 = 0;
function observer1() {
count1++;
}
function observer2() {
count2++;
}
function observer4() {
count4++;
}
(0, _emberMetal._addBeforeObserver)(obj1, 'foo.bar', observer1);
(0, _emberMetal._addBeforeObserver)(obj2, 'foo.bar', observer2);
(0, _emberMetal._addBeforeObserver)({ foo: foo }, 'foo.bar', function () {
count3++;
(0, _emberMetal._removeBeforeObserver)(obj1, 'foo.bar', observer1);
(0, _emberMetal._removeBeforeObserver)(obj2, 'foo.bar', observer2);
(0, _emberMetal._removeBeforeObserver)(obj4, 'foo.bar', observer4);
});
(0, _emberMetal._addBeforeObserver)(obj4, 'foo.bar', observer4);
set(foo, 'bar', 'baz');
equal(count1, 1, 'observer1 fired');
equal(count2, 1, 'observer2 fired');
equal(count3, 1, 'observer3 fired');
equal(count4, 0, 'observer4 did not fire');
});
(0, _internalTestHelpers.testBoth)('suspending an observer should not fire during callback', function (get, set) {
var obj = {};
var target = void 0,
otherTarget = void 0;
target = {
values: [],
method: function () {
this.values.push(get(obj, 'foo'));
}
};
otherTarget = {
values: [],
method: function () {
this.values.push(get(obj, 'foo'));
}
};
(0, _emberMetal.addObserver)(obj, 'foo', target, target.method);
(0, _emberMetal.addObserver)(obj, 'foo', otherTarget, otherTarget.method);
set(obj, 'foo', '1');
equal((0, _emberMetal._suspendObserver)(obj, 'foo', target, target.method, function () {
/*jshint validthis:true */
equal(this, target);
set(obj, 'foo', '2');
return 'result';
}), 'result');
set(obj, 'foo', '3');
deepEqual(target.values, ['1', '3'], 'should invoke');
deepEqual(otherTarget.values, ['1', '2', '3'], 'should invoke');
});
(0, _internalTestHelpers.testBoth)('suspending an observer should not defer change notifications during callback', function (get, set) {
var obj = {};
var target = void 0,
otherTarget = void 0;
target = {
values: [],
method: function () {
this.values.push(get(obj, 'foo'));
}
};
otherTarget = {
values: [],
method: function () {
this.values.push(get(obj, 'foo'));
}
};
(0, _emberMetal.addObserver)(obj, 'foo', target, target.method);
(0, _emberMetal.addObserver)(obj, 'foo', otherTarget, otherTarget.method);
set(obj, 'foo', '1');
(0, _emberMetal.beginPropertyChanges)();
equal((0, _emberMetal._suspendObserver)(obj, 'foo', target, target.method, function () {
/*jshint validthis:true */
equal(this, target);
set(obj, 'foo', '2');
return 'result';
}), 'result');
(0, _emberMetal.endPropertyChanges)();
set(obj, 'foo', '3');
deepEqual(target.values, ['1', '3'], 'should invoke');
deepEqual(otherTarget.values, ['1', '2', '3'], 'should invoke');
});
(0, _internalTestHelpers.testBoth)('suspending observers should not fire during callback', function (get, set) {
var obj = {};
var target = void 0,
otherTarget = void 0;
target = {
values: [],
method: function () {
this.values.push(get(obj, 'foo'));
}
};
otherTarget = {
values: [],
method: function () {
this.values.push(get(obj, 'foo'));
}
};
(0, _emberMetal.addObserver)(obj, 'foo', target, target.method);
(0, _emberMetal.addObserver)(obj, 'foo', otherTarget, otherTarget.method);
set(obj, 'foo', '1');
equal((0, _emberMetal._suspendObservers)(obj, ['foo'], target, target.method, function () {
/*jshint validthis:true */
equal(this, target);
set(obj, 'foo', '2');
return 'result';
}), 'result');
set(obj, 'foo', '3');
deepEqual(target.values, ['1', '3'], 'should invoke');
deepEqual(otherTarget.values, ['1', '2', '3'], 'should invoke');
});
(0, _internalTestHelpers.testBoth)('suspending observers should not defer change notifications during callback', function (get, set) {
var obj = {};
var target = void 0,
otherTarget = void 0;
target = {
values: [],
method: function () {
this.values.push(get(obj, 'foo'));
}
};
otherTarget = {
values: [],
method: function () {
this.values.push(get(obj, 'foo'));
}
};
(0, _emberMetal.addObserver)(obj, 'foo', target, target.method);
(0, _emberMetal.addObserver)(obj, 'foo', otherTarget, otherTarget.method);
set(obj, 'foo', '1');
(0, _emberMetal.beginPropertyChanges)();
equal((0, _emberMetal._suspendObservers)(obj, ['foo'], target, target.method, function () {
/*jshint validthis:true */
equal(this, target);
set(obj, 'foo', '2');
return 'result';
}), 'result');
(0, _emberMetal.endPropertyChanges)();
set(obj, 'foo', '3');
deepEqual(target.values, ['1', '3'], 'should invoke');
deepEqual(otherTarget.values, ['1', '2', '3'], 'should invoke');
});
(0, _internalTestHelpers.testBoth)('deferring property change notifications', function (get, set) {
var obj = { foo: 'foo' };
var fooCount = 0;
(0, _emberMetal.addObserver)(obj, 'foo', function () {
fooCount++;
});
(0, _emberMetal.beginPropertyChanges)(obj);
set(obj, 'foo', 'BIFF');
set(obj, 'foo', 'BAZ');
(0, _emberMetal.endPropertyChanges)(obj);
equal(fooCount, 1, 'foo should have fired once');
});
(0, _internalTestHelpers.testBoth)('deferring property change notifications safely despite exceptions', function (get, set) {
var obj = { foo: 'foo' };
var fooCount = 0;
var exc = new Error('Something unexpected happened!');
expect(2);
(0, _emberMetal.addObserver)(obj, 'foo', function () {
fooCount++;
});
try {
(0, _emberMetal.changeProperties)(function () {
set(obj, 'foo', 'BIFF');
set(obj, 'foo', 'BAZ');
throw exc;
});
} catch (err) {
if (err !== exc) {
throw err;
}
}
equal(fooCount, 1, 'foo should have fired once');
(0, _emberMetal.changeProperties)(function () {
set(obj, 'foo', 'BIFF2');
set(obj, 'foo', 'BAZ2');
});
equal(fooCount, 2, 'foo should have fired again once');
});
(0, _internalTestHelpers.testBoth)('deferring property change notifications will not defer before observers', function (get, set) {
var obj = { foo: 'foo' };
var fooCount = 0;
(0, _emberMetal._addBeforeObserver)(obj, 'foo', function () {
fooCount++;
});
(0, _emberMetal.beginPropertyChanges)(obj);
set(obj, 'foo', 'BIFF');
equal(fooCount, 1, 'should fire before observer immediately');
set(obj, 'foo', 'BAZ');
(0, _emberMetal.endPropertyChanges)(obj);
equal(fooCount, 1, 'should not fire before observer twice');
});
(0, _internalTestHelpers.testBoth)('addObserver should propagate through prototype', function (get, set) {
var obj = { foo: 'foo', count: 0 };
var obj2 = void 0;
(0, _emberMetal.addObserver)(obj, 'foo', function () {
this.count++;
});
obj2 = Object.create(obj);
set(obj2, 'foo', 'bar');
equal(obj2.count, 1, 'should have invoked observer on inherited');
equal(obj.count, 0, 'should not have invoked observer on parent');
obj2.count = 0;
set(obj, 'foo', 'baz');
equal(obj.count, 1, 'should have invoked observer on parent');
equal(obj2.count, 0, 'should not have invoked observer on inherited');
});
(0, _internalTestHelpers.testBoth)('addObserver should respect targets with methods', function (get, set) {
var observed = { foo: 'foo' };
var target1 = {
count: 0,
didChange: function (obj, keyName) {
var value = get(obj, keyName);
equal(this, target1, 'should invoke with this');
equal(obj, observed, 'param1 should be observed object');
equal(keyName, 'foo', 'param2 should be keyName');
equal(value, 'BAZ', 'param3 should new value');
this.count++;
}
};
var target2 = {
count: 0,
didChange: function (obj, keyName) {
var value = get(obj, keyName);
equal(this, target2, 'should invoke with this');
equal(obj, observed, 'param1 should be observed object');
equal(keyName, 'foo', 'param2 should be keyName');
equal(value, 'BAZ', 'param3 should new value');
this.count++;
}
};
(0, _emberMetal.addObserver)(observed, 'foo', target1, 'didChange');
(0, _emberMetal.addObserver)(observed, 'foo', target2, target2.didChange);
set(observed, 'foo', 'BAZ');
equal(target1.count, 1, 'target1 observer should have fired');
equal(target2.count, 1, 'target2 observer should have fired');
});
(0, _internalTestHelpers.testBoth)('addObserver should allow multiple objects to observe a property', function (get, set) {
var observed = { foo: 'foo' };
var target1 = {
count: 0,
didChange: function () {
this.count++;
}
};
var target2 = {
count: 0,
didChange: function () {
this.count++;
}
};
(0, _emberMetal.addObserver)(observed, 'foo', target1, 'didChange');
(0, _emberMetal.addObserver)(observed, 'foo', target2, 'didChange');
set(observed, 'foo', 'BAZ');
equal(target1.count, 1, 'target1 observer should have fired');
equal(target2.count, 1, 'target2 observer should have fired');
});
// ..........................................................
// REMOVE OBSERVER
//
QUnit.module('removeObserver');
(0, _internalTestHelpers.testBoth)('removing observer should stop firing', function (get, set) {
var obj = {};
var count = 0;
function F() {
count++;
}
(0, _emberMetal.addObserver)(obj, 'foo', F);
set(obj, 'foo', 'bar');
equal(count, 1, 'should have invoked observer');
(0, _emberMetal.removeObserver)(obj, 'foo', F);
set(obj, 'foo', 'baz');
equal(count, 1, 'removed observer shouldn\'t fire');
});
(0, _internalTestHelpers.testBoth)('local observers can be removed', function (get, set) {
var barObserved = 0;
var MyMixin = _emberMetal.Mixin.create({
foo1: (0, _emberMetal.observer)('bar', function () {
barObserved++;
}),
foo2: (0, _emberMetal.observer)('bar', function () {
barObserved++;
})
});
var obj = {};
MyMixin.apply(obj);
set(obj, 'bar', 'HI!');
equal(barObserved, 2, 'precond - observers should be fired');
(0, _emberMetal.removeObserver)(obj, 'bar', null, 'foo1');
barObserved = 0;
set(obj, 'bar', 'HI AGAIN!');
equal(barObserved, 1, 'removed observers should not be called');
});
(0, _internalTestHelpers.testBoth)('removeObserver should respect targets with methods', function (get, set) {
var observed = { foo: 'foo' };
var target1 = {
count: 0,
didChange: function () {
this.count++;
}
};
var target2 = {
count: 0,
didChange: function () {
this.count++;
}
};
(0, _emberMetal.addObserver)(observed, 'foo', target1, 'didChange');
(0, _emberMetal.addObserver)(observed, 'foo', target2, target2.didChange);
set(observed, 'foo', 'BAZ');
equal(target1.count, 1, 'target1 observer should have fired');
equal(target2.count, 1, 'target2 observer should have fired');
(0, _emberMetal.removeObserver)(observed, 'foo', target1, 'didChange');
(0, _emberMetal.removeObserver)(observed, 'foo', target2, target2.didChange);
target1.count = target2.count = 0;
set(observed, 'foo', 'BAZ');
equal(target1.count, 0, 'target1 observer should not fire again');
equal(target2.count, 0, 'target2 observer should not fire again');
});
// ..........................................................
// BEFORE OBSERVER
//
QUnit.module('_addBeforeObserver');
(0, _internalTestHelpers.testBoth)('observer should fire before a property is modified', function (get, set) {
var obj = { foo: 'foo' };
var count = 0;
(0, _emberMetal._addBeforeObserver)(obj, 'foo', function () {
equal(get(obj, 'foo'), 'foo', 'should invoke before value changed');
count++;
});
set(obj, 'foo', 'bar');
equal(count, 1, 'should have invoked observer');
});
(0, _internalTestHelpers.testBoth)('observer should fire before dependent property is modified', function (get, set) {
var obj = { bar: 'bar' };
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {
return get(this, 'bar').toUpperCase();
}).property('bar'));
get(obj, 'foo');
var count = 0;
(0, _emberMetal._addBeforeObserver)(obj, 'foo', function () {
equal(get(obj, 'foo'), 'BAR', 'should have invoked after prop change');
count++;
});
set(obj, 'bar', 'baz');
equal(count, 1, 'should have invoked observer');
});
(0, _internalTestHelpers.testBoth)('before observer watching multiple properties via brace expansion should fire when properties change', function (get, set) {
var obj = {};
var count = 0;
(0, _emberMetal.mixin)(obj, {
fooAndBarWatcher: (0, _emberMetal._beforeObserver)('{foo,bar}', function () {
count++;
})
});
set(obj, 'foo', 'foo');
equal(count, 1, 'observer specified via brace expansion invoked on property change');
set(obj, 'bar', 'bar');
equal(count, 2, 'observer specified via brace expansion invoked on property change');
set(obj, 'baz', 'baz');
equal(count, 2, 'observer not invoked on unspecified property');
});
(0, _internalTestHelpers.testBoth)('before observer watching multiple properties via brace expansion should fire when dependent property changes', function (get, set) {
var obj = { baz: 'Initial' };
var count = 0;
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)(function () {
return get(this, 'bar').toLowerCase();
}).property('bar'));
(0, _emberMetal.defineProperty)(obj, 'bar', (0, _emberMetal.computed)(function () {
return get(this, 'baz').toUpperCase();
}).property('baz'));
(0, _emberMetal.mixin)(obj, {
fooAndBarWatcher: (0, _emberMetal._beforeObserver)('{foo,bar}', function () {
count++;
})
});
get(obj, 'foo');
set(obj, 'baz', 'Baz');
// fire once for foo, once for bar
equal(count, 2, 'observer specified via brace expansion invoked on dependent property change');
set(obj, 'quux', 'Quux');
equal(count, 2, 'observer not fired on unspecified property');
});
(0, _internalTestHelpers.testBoth)('_addBeforeObserver should propagate through prototype', function (get, set) {
var obj = { foo: 'foo', count: 0 };
var obj2 = void 0;
(0, _emberMetal._addBeforeObserver)(obj, 'foo', function () {
this.count++;
});
obj2 = Object.create(obj);
set(obj2, 'foo', 'bar');
equal(obj2.count, 1, 'should have invoked observer on inherited');
equal(obj.count, 0, 'should not have invoked observer on parent');
obj2.count = 0;
set(obj, 'foo', 'baz');
equal(obj.count, 1, 'should have invoked observer on parent');
equal(obj2.count, 0, 'should not have invoked observer on inherited');
});
(0, _internalTestHelpers.testBoth)('_addBeforeObserver should respect targets with methods', function (get, set) {
var observed = { foo: 'foo' };
var target1 = {
count: 0,
willChange: function (obj, keyName) {
var value = get(obj, keyName);
equal(this, target1, 'should invoke with this');
equal(obj, observed, 'param1 should be observed object');
equal(keyName, 'foo', 'param2 should be keyName');
equal(value, 'foo', 'param3 should old value');
this.count++;
}
};
var target2 = {
count: 0,
willChange: function (obj, keyName) {
var value = get(obj, keyName);
equal(this, target2, 'should invoke with this');
equal(obj, observed, 'param1 should be observed object');
equal(keyName, 'foo', 'param2 should be keyName');
equal(value, 'foo', 'param3 should old value');
this.count++;
}
};
(0, _emberMetal._addBeforeObserver)(observed, 'foo', target1, 'willChange');
(0, _emberMetal._addBeforeObserver)(observed, 'foo', target2, target2.willChange);
set(observed, 'foo', 'BAZ');
equal(target1.count, 1, 'target1 observer should have fired');
equal(target2.count, 1, 'target2 observer should have fired');
});
// ..........................................................
// CHAINED OBSERVERS
//
var obj = void 0,
count = void 0;
QUnit.module('addObserver - dependentkey with chained properties', {
setup: function () {
obj = {
foo: {
bar: {
baz: {
biff: 'BIFF'
}
}
},
Capital: {
foo: {
bar: {
baz: {
biff: 'BIFF'
}
}
}
}
};
count = 0;
},
teardown: function () {
obj = count = null;
}
});
(0, _internalTestHelpers.testBoth)('depending on a chain with a computed property', function (get, set) {
(0, _emberMetal.defineProperty)(obj, 'computed', (0, _emberMetal.computed)(function () {
return { foo: 'bar' };
}));
var changed = 0;
(0, _emberMetal.addObserver)(obj, 'computed.foo', function () {
changed++;
});
equal((0, _emberMetal.cacheFor)(obj, 'computed'), undefined, 'addObserver should not compute CP');
set(obj, 'computed.foo', 'baz');
equal(changed, 1, 'should fire observer');
});
(0, _internalTestHelpers.testBoth)('depending on a simple chain', function (get, set) {
var val = void 0;
(0, _emberMetal.addObserver)(obj, 'foo.bar.baz.biff', function (target, key) {
val = get(target, key);
count++;
});
set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
equal(val, 'BUZZ');
equal(count, 1);
set(get(obj, 'foo.bar'), 'baz', { biff: 'BLARG' });
equal(val, 'BLARG');
equal(count, 2);
set(get(obj, 'foo'), 'bar', { baz: { biff: 'BOOM' } });
equal(val, 'BOOM');
equal(count, 3);
set(obj, 'foo', { bar: { baz: { biff: 'BLARG' } } });
equal(val, 'BLARG');
equal(count, 4);
set(get(obj, 'foo.bar.baz'), 'biff', 'BUZZ');
equal(val, 'BUZZ');
equal(count, 5);
var foo = get(obj, 'foo');
set(obj, 'foo', 'BOO');
equal(val, undefined);
equal(count, 6);
set(foo.bar.baz, 'biff', 'BOOM');
equal(count, 6, 'should be not have invoked observer');
});
(0, _internalTestHelpers.testBoth)('depending on a chain with a capitalized first key', function (get, set) {
var val = void 0;
(0, _emberMetal.addObserver)(obj, 'Capital.foo.bar.baz.biff', function (target, key) {
val = get(obj, key);
count++;
});
set(get(obj, 'Capital.foo.bar.baz'), 'biff', 'BUZZ');
equal(val, 'BUZZ');
equal(count, 1);
set(get(obj, 'Capital.foo.bar'), 'baz', { biff: 'BLARG' });
equal(val, 'BLARG');
equal(count, 2);
set(get(obj, 'Capital.foo'), 'bar', { baz: { biff: 'BOOM' } });
equal(val, 'BOOM');
equal(count, 3);
set(obj, 'Capital.foo', { bar: { baz: { biff: 'BLARG' } } });
equal(val, 'BLARG');
equal(count, 4);
set(get(obj, 'Capital.foo.bar.baz'), 'biff', 'BUZZ');
equal(val, 'BUZZ');
equal(count, 5);
var foo = get(obj, 'foo');
set(obj, 'Capital.foo', 'BOO');
equal(val, undefined);
equal(count, 6);
set(foo.bar.baz, 'biff', 'BOOM');
equal(count, 6, 'should be not have invoked observer');
});
QUnit.module('_removeBeforeObserver');
// ..........................................................
// SETTING IDENTICAL VALUES
//
QUnit.module('props/observer_test - setting identical values');
(0, _internalTestHelpers.testBoth)('setting simple prop should not trigger', function (get, set) {
var obj = { foo: 'bar' };
var count = 0;
(0, _emberMetal.addObserver)(obj, 'foo', function () {
count++;
});
set(obj, 'foo', 'bar');
equal(count, 0, 'should not trigger observer');
set(obj, 'foo', 'baz');
equal(count, 1, 'should trigger observer');
set(obj, 'foo', 'baz');
equal(count, 1, 'should not trigger observer again');
});
// The issue here is when a computed property is directly set with a value, then has a
// dependent key change (which triggers a cache expiration and recomputation), observers will
// not be fired if the CP setter is called with the last set value.
(0, _internalTestHelpers.testBoth)('setting a cached computed property whose value has changed should trigger', function (get, set) {
var obj = {};
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({
get: function () {
return get(this, 'baz');
},
set: function (key, value) {
return value;
}
}).property('baz'));
var count = 0;
(0, _emberMetal.addObserver)(obj, 'foo', function () {
count++;
});
set(obj, 'foo', 'bar');
equal(count, 1);
equal(get(obj, 'foo'), 'bar');
set(obj, 'baz', 'qux');
equal(count, 2);
equal(get(obj, 'foo'), 'qux');
get(obj, 'foo');
set(obj, 'foo', 'bar');
equal(count, 3);
equal(get(obj, 'foo'), 'bar');
});
QUnit.module('Ember.immediateObserver (Deprecated)');
(0, _internalTestHelpers.testBoth)('immediate observers should fire synchronously', function (get, set) {
expectDeprecation(/Usage of `Ember.immediateObserver` is deprecated, use `Ember.observer` instead./);
var obj = {};
var observerCalled = 0;
var mixin = void 0;
// explicitly create a run loop so we do not inadvertently
// trigger deferred behavior
(0, _emberMetal.run)(function () {
mixin = _emberMetal.Mixin.create({
fooDidChange: (0, _emberMetal._immediateObserver)('foo', function () {
observerCalled++;
equal(get(this, 'foo'), 'barbaz', 'newly set value is immediately available');
})
});
mixin.apply(obj);
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({
get: function () {
return 'yes hello this is foo';
},
set: function (key, value) {
return value;
}
}));
equal(get(obj, 'foo'), 'yes hello this is foo', 'precond - computed property returns a value');
equal(observerCalled, 0, 'observer has not yet been called');
set(obj, 'foo', 'barbaz');
equal(observerCalled, 1, 'observer was called once');
});
});
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) {
(0, _internalTestHelpers.testBoth)('immediate observers added declaratively via brace expansion fire synchronously', function (get, set) {
var obj = {};
var observerCalled = 0;
var mixin = void 0;
// explicitly create a run loop so we do not inadvertently
// trigger deferred behavior
(0, _emberMetal.run)(function () {
expectDeprecation(function () {
mixin = _emberMetal.Mixin.create({
fooDidChange: function () {
observerCalled++;
equal(get(this, 'foo'), 'barbaz', 'newly set value is immediately available');
}.observesImmediately('{foo,bar}')
});
}, /Function#observesImmediately is deprecated. Use Function#observes instead/);
mixin.apply(obj);
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({
get: function () {
return 'yes hello this is foo';
},
set: function (key, value) {
return value;
}
}));
equal(get(obj, 'foo'), 'yes hello this is foo', 'precond - computed property returns a value');
equal(observerCalled, 0, 'observer has not yet been called');
set(obj, 'foo', 'barbaz');
equal(observerCalled, 1, 'observer was called once');
});
});
}
(0, _internalTestHelpers.testBoth)('immediate observers watching multiple properties via brace expansion fire synchronously', function (get, set) {
expectDeprecation(/Usage of `Ember.immediateObserver` is deprecated, use `Ember.observer` instead./);
var obj = {};
var observerCalled = 0;
var mixin = void 0;
// explicitly create a run loop so we do not inadvertently
// trigger deferred behavior
(0, _emberMetal.run)(function () {
mixin = _emberMetal.Mixin.create({
fooDidChange: (0, _emberMetal._immediateObserver)('{foo,bar}', function () {
observerCalled++;
equal(get(this, 'foo'), 'barbaz', 'newly set value is immediately available');
})
});
mixin.apply(obj);
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({
get: function () {
return 'yes hello this is foo';
},
set: function (key, value) {
return value;
}
}));
equal(get(obj, 'foo'), 'yes hello this is foo', 'precond - computed property returns a value');
equal(observerCalled, 0, 'observer has not yet been called');
set(obj, 'foo', 'barbaz');
equal(observerCalled, 1, 'observer was called once');
});
});
(0, _internalTestHelpers.testBoth)('immediate observers are for internal properties only', function () {
expectDeprecation(/Usage of `Ember.immediateObserver` is deprecated, use `Ember.observer` instead./);
expectAssertion(function () {
(0, _emberMetal._immediateObserver)('foo.bar', function () {
return this;
});
}, 'Immediate observers must observe internal properties only, not properties on other objects.');
});
QUnit.module('changeProperties');
(0, _internalTestHelpers.testBoth)('observers added/removed during changeProperties should do the right thing.', function (get, set) {
var obj = {
foo: 0
};
function Observer() {
this.willChangeCount = 0;
this.didChangeCount = 0;
}
Observer.prototype = {
add: function () {
(0, _emberMetal._addBeforeObserver)(obj, 'foo', this, 'willChange');
(0, _emberMetal.addObserver)(obj, 'foo', this, 'didChange');
},
remove: function () {
(0, _emberMetal._removeBeforeObserver)(obj, 'foo', this, 'willChange');
(0, _emberMetal.removeObserver)(obj, 'foo', this, 'didChange');
},
willChange: function () {
this.willChangeCount++;
},
didChange: function () {
this.didChangeCount++;
}
};
var addedBeforeFirstChangeObserver = new Observer();
var addedAfterFirstChangeObserver = new Observer();
var addedAfterLastChangeObserver = new Observer();
var removedBeforeFirstChangeObserver = new Observer();
var removedBeforeLastChangeObserver = new Observer();
var removedAfterLastChangeObserver = new Observer();
removedBeforeFirstChangeObserver.add();
removedBeforeLastChangeObserver.add();
removedAfterLastChangeObserver.add();
(0, _emberMetal.changeProperties)(function () {
removedBeforeFirstChangeObserver.remove();
addedBeforeFirstChangeObserver.add();
set(obj, 'foo', 1);
equal(addedBeforeFirstChangeObserver.willChangeCount, 1, '_addBeforeObserver called before the first change invoked immediately');
equal(addedBeforeFirstChangeObserver.didChangeCount, 0, 'addObserver called before the first change is deferred');
addedAfterFirstChangeObserver.add();
removedBeforeLastChangeObserver.remove();
set(obj, 'foo', 2);
equal(addedAfterFirstChangeObserver.willChangeCount, 1, '_addBeforeObserver called after the first change invoked immediately');
equal(addedAfterFirstChangeObserver.didChangeCount, 0, 'addObserver called after the first change is deferred');
addedAfterLastChangeObserver.add();
removedAfterLastChangeObserver.remove();
});
equal(removedBeforeFirstChangeObserver.willChangeCount, 0, '_removeBeforeObserver called before the first change sees none');
equal(removedBeforeFirstChangeObserver.didChangeCount, 0, 'removeObserver called before the first change sees none');
equal(addedBeforeFirstChangeObserver.willChangeCount, 1, '_addBeforeObserver called before the first change sees only 1');
equal(addedBeforeFirstChangeObserver.didChangeCount, 1, 'addObserver called before the first change sees only 1');
equal(addedAfterFirstChangeObserver.willChangeCount, 1, '_addBeforeObserver called after the first change sees 1');
equal(addedAfterFirstChangeObserver.didChangeCount, 1, 'addObserver called after the first change sees 1');
equal(addedAfterLastChangeObserver.willChangeCount, 0, '_addBeforeObserver called after the last change sees none');
equal(addedAfterLastChangeObserver.didChangeCount, 0, 'addObserver called after the last change sees none');
equal(removedBeforeLastChangeObserver.willChangeCount, 1, '_removeBeforeObserver called before the last change still sees 1');
equal(removedBeforeLastChangeObserver.didChangeCount, 1, 'removeObserver called before the last change still sees 1');
equal(removedAfterLastChangeObserver.willChangeCount, 1, '_removeBeforeObserver called after the last change still sees 1');
equal(removedAfterLastChangeObserver.didChangeCount, 1, 'removeObserver called after the last change still sees 1');
});
QUnit.module('Keys behavior with observers');
(0, _internalTestHelpers.testBoth)('should not leak properties on the prototype', function () {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
(0, _emberMetal.addObserver)(beer, 'type', K);
deepEqual(Object.keys(beer), []);
(0, _emberMetal.removeObserver)(beer, 'type', K);
});
(0, _internalTestHelpers.testBoth)('observing a non existent property', function (get, set) {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
(0, _emberMetal.addObserver)(beer, 'brand', K);
deepEqual(Object.keys(beer), []);
set(beer, 'brand', 'Corona');
deepEqual(Object.keys(beer), ['brand']);
(0, _emberMetal.removeObserver)(beer, 'brand', K);
});
(0, _internalTestHelpers.testBoth)('with observers switched on and off', function () {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
(0, _emberMetal.addObserver)(beer, 'type', K);
(0, _emberMetal.removeObserver)(beer, 'type', K);
deepEqual(Object.keys(beer), []);
});
(0, _internalTestHelpers.testBoth)('observers switched on and off with setter in between', function (get, set) {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
(0, _emberMetal.addObserver)(beer, 'type', K);
set(beer, 'type', 'ale');
(0, _emberMetal.removeObserver)(beer, 'type', K);
deepEqual(Object.keys(beer), ['type']);
});
(0, _internalTestHelpers.testBoth)('observer switched on and off and then setter', function (get, set) {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
(0, _emberMetal.addObserver)(beer, 'type', K);
(0, _emberMetal.removeObserver)(beer, 'type', K);
set(beer, 'type', 'ale');
deepEqual(Object.keys(beer), ['type']);
});
(0, _internalTestHelpers.testBoth)('observers switched on and off with setter in between (observed property is not shadowing)', function (get, set) {
function Beer() {}
var beer = new Beer();
set(beer, 'type', 'ale');
deepEqual(Object.keys(beer), ['type'], 'only set');
var otherBeer = new Beer();
(0, _emberMetal.addObserver)(otherBeer, 'type', K);
set(otherBeer, 'type', 'ale');
deepEqual(Object.keys(otherBeer), ['type'], 'addObserver -> set');
var yetAnotherBeer = new Beer();
(0, _emberMetal.addObserver)(yetAnotherBeer, 'type', K);
set(yetAnotherBeer, 'type', 'ale');
(0, _emberMetal.removeObserver)(beer, 'type', K);
deepEqual(Object.keys(yetAnotherBeer), ['type'], 'addObserver -> set -> removeObserver');
var itsMyLastBeer = new Beer();
set(itsMyLastBeer, 'type', 'ale');
(0, _emberMetal.removeObserver)(beer, 'type', K);
deepEqual(Object.keys(itsMyLastBeer), ['type'], 'set -> removeObserver');
});
(0, _internalTestHelpers.testBoth)('observers switched on and off with setter in between (observed property is shadowing one on the prototype)', function (get, set) {
function Beer() {}
Beer.prototype.type = 'ipa';
var beer = new Beer();
set(beer, 'type', 'ale');
deepEqual(Object.keys(beer), ['type'], 'after set');
var otherBeer = new Beer();
(0, _emberMetal.addObserver)(otherBeer, 'type', K);
set(otherBeer, 'type', 'ale');
deepEqual(Object.keys(otherBeer), ['type'], 'addObserver -> set');
var yetAnotherBeer = new Beer();
(0, _emberMetal.addObserver)(yetAnotherBeer, 'type', K);
set(yetAnotherBeer, 'type', 'ale');
(0, _emberMetal.removeObserver)(beer, 'type', K);
deepEqual(Object.keys(yetAnotherBeer), ['type'], 'addObserver -> set -> removeObserver');
var itsMyLastBeer = new Beer();
set(itsMyLastBeer, 'type', 'ale');
(0, _emberMetal.removeObserver)(beer, 'type', K);
deepEqual(Object.keys(itsMyLastBeer), ['type'], 'set -> removeObserver');
});
});
enifed('ember-metal/tests/performance_test', ['ember-metal'], function (_emberMetal) {
'use strict';
/*
This test file is designed to capture performance regressions related to
deferred computation. Things like run loops, computed properties, and bindings
should run the minimum amount of times to achieve best performance, so any
bugs that cause them to get evaluated more than necessary should be put here.
*/
QUnit.module('Computed Properties - Number of times evaluated');
QUnit.test('computed properties that depend on multiple properties should run only once per run loop', function () {
var obj = { a: 'a', b: 'b', c: 'c' };
var cpCount = 0;
var obsCount = 0;
(0, _emberMetal.defineProperty)(obj, 'abc', (0, _emberMetal.computed)(function (key) {
cpCount++;
return 'computed ' + key;
}).property('a', 'b', 'c'));
(0, _emberMetal.get)(obj, 'abc');
cpCount = 0;
(0, _emberMetal.addObserver)(obj, 'abc', function () {
obsCount++;
});
(0, _emberMetal.beginPropertyChanges)();
(0, _emberMetal.set)(obj, 'a', 'aa');
(0, _emberMetal.set)(obj, 'b', 'bb');
(0, _emberMetal.set)(obj, 'c', 'cc');
(0, _emberMetal.endPropertyChanges)();
(0, _emberMetal.get)(obj, 'abc');
equal(cpCount, 1, 'The computed property is only invoked once');
equal(obsCount, 1, 'The observer is only invoked once');
});
QUnit.test('computed properties are not executed if they are the last segment of an observer chain pain', function () {
var foo = { bar: { baz: {} } };
var count = 0;
(0, _emberMetal.defineProperty)(foo.bar.baz, 'bam', (0, _emberMetal.computed)(function () {
count++;
}));
(0, _emberMetal.addObserver)(foo, 'bar.baz.bam', function () {});
(0, _emberMetal.propertyDidChange)((0, _emberMetal.get)(foo, 'bar.baz'), 'bam');
equal(count, 0, 'should not have recomputed property');
});
});
enifed('ember-metal/tests/properties_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.defineProperty');
QUnit.test('toString', function () {
var obj = {};
(0, _emberMetal.defineProperty)(obj, 'toString', undefined, function () {
return 'FOO';
});
equal(obj.toString(), 'FOO', 'should replace toString');
});
QUnit.test('for data properties, didDefineProperty hook should be called if implemented', function () {
expect(2);
(0, _emberMetal.defineProperty)({
didDefineProperty: function (obj, keyName, value) {
equal(keyName, 'foo', 'key name should be foo');
equal(value, 'bar', 'value should be bar');
}
}, 'foo', undefined, 'bar');
});
QUnit.test('for computed properties, didDefineProperty hook should be called if implemented', function () {
expect(2);
var computedProperty = (0, _emberMetal.computed)(function () {
return this;
});
(0, _emberMetal.defineProperty)({
didDefineProperty: function (obj, keyName, value) {
equal(keyName, 'foo', 'key name should be foo');
strictEqual(value, computedProperty, 'value should be passed as computed property');
}
}, 'foo', computedProperty);
});
QUnit.test('for descriptor properties, didDefineProperty hook should be called if implemented', function () {
expect(2);
var descriptor = {
writable: true,
configurable: false,
enumerable: true,
value: 42
};
(0, _emberMetal.defineProperty)({
didDefineProperty: function (obj, keyName, value) {
equal(keyName, 'answer', 'key name should be answer');
strictEqual(value, descriptor, 'value should be passed as descriptor');
}
}, 'answer', descriptor);
});
QUnit.module('Ember.deprecateProperty');
QUnit.test('enables access to deprecated property and returns the value of the new property', function () {
expect(3);
var obj = { foo: 'bar' };
(0, _emberMetal.deprecateProperty)(obj, 'baz', 'foo');
expectDeprecation();
equal(obj.baz, obj.foo, 'baz and foo are equal');
obj.foo = 'blammo';
equal(obj.baz, obj.foo, 'baz and foo are equal');
});
QUnit.test('deprecatedKey is not enumerable', function () {
expect(2);
var obj = { foo: 'bar', blammo: 'whammy' };
(0, _emberMetal.deprecateProperty)(obj, 'baz', 'foo');
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
notEqual(prop, 'baz');
}
}
});
QUnit.test('enables setter to deprecated property and updates the value of the new property', function () {
expect(3);
var obj = { foo: 'bar' };
(0, _emberMetal.deprecateProperty)(obj, 'baz', 'foo');
expectDeprecation();
obj.baz = 'bloop';
equal(obj.foo, 'bloop', 'updating baz updates foo');
equal(obj.baz, obj.foo, 'baz and foo are equal');
});
});
enifed('ember-metal/tests/property_did_change_hook', ['internal-test-helpers', 'ember-metal'], function (_internalTestHelpers, _emberMetal) {
'use strict';
QUnit.module('PROPERTY_DID_CHANGE');
(0, _internalTestHelpers.testBoth)('alias and cp', function (get, set) {
var _obj;
var counts = {};
var obj = (_obj = {
child: {}
}, _obj[_emberMetal.PROPERTY_DID_CHANGE] = function (keyName) {
counts[keyName] = (counts[keyName] || 0) + 1;
}, _obj);
(0, _emberMetal.defineProperty)(obj, 'cost', (0, _emberMetal.alias)('child.cost'));
(0, _emberMetal.defineProperty)(obj, 'tax', (0, _emberMetal.alias)('child.tax'));
(0, _emberMetal.defineProperty)(obj, 'total', (0, _emberMetal.computed)('cost', 'tax', {
get: function () {
return get(this, 'cost') + get(this, 'tax');
}
}));
ok(!(0, _emberMetal.isWatching)(obj, 'child.cost'), 'precond alias target `child.cost` is not watched');
equal(get(obj, 'cost'), undefined);
// this is how PROPERTY_DID_CHANGE will get notified
ok((0, _emberMetal.isWatching)(obj, 'child.cost'), 'alias target `child.cost` is watched after consumption');
ok(!(0, _emberMetal.isWatching)(obj, 'child.tax'), 'precond alias target `child.tax` is not watched');
equal(get(obj, 'tax'), undefined);
// this is how PROPERTY_DID_CHANGE will get notified
ok((0, _emberMetal.isWatching)(obj, 'child.tax'), 'alias target `child.cost` is watched after consumption');
// increments the watching count on the alias itself to 1
ok(isNaN(get(obj, 'total')), 'total is initialized');
// decrements the watching count on the alias itself to 0
set(obj, 'child', {
cost: 399.00,
tax: 32.93
});
// this should have called PROPERTY_DID_CHANGE for all of them
equal(counts['cost'], 1, 'PROPERTY_DID_CHANGE called with cost');
equal(counts['tax'], 1, 'PROPERTY_DID_CHANGE called with tax');
equal(counts['total'], 1, 'PROPERTY_DID_CHANGE called with total');
// we should still have a dependency installed
ok((0, _emberMetal.isWatching)(obj, 'child.cost'), 'watching child.cost');
ok((0, _emberMetal.isWatching)(obj, 'child.tax'), 'watching child.tax');
set(obj, 'child', {
cost: 100.00,
tax: 10.00
});
equal(counts['cost'], 2, 'PROPERTY_DID_CHANGE called with cost');
equal(counts['tax'], 2, 'PROPERTY_DID_CHANGE called with tax');
equal(counts['total'], 1, 'PROPERTY_DID_CHANGE called with total');
});
});
enifed('ember-metal/tests/run_loop/add_queue_test', ['ember-metal'], function (_emberMetal) {
'use strict';
var originalQueues = _emberMetal.run.queues;
var queues = void 0;
QUnit.module('system/run_loop/add_queue_test', {
setup: function () {
_emberMetal.run.queues = queues = ['blork', 'bleep'];
},
teardown: function () {
_emberMetal.run.queues = originalQueues;
}
});
QUnit.test('adds a queue after a specified one', function () {
_emberMetal.run._addQueue('testeroo', 'blork');
equal(queues.indexOf('testeroo'), 1, 'new queue was added after specified queue');
});
QUnit.test('does not add the queue if it already exists', function () {
_emberMetal.run._addQueue('testeroo', 'blork');
_emberMetal.run._addQueue('testeroo', 'blork');
equal(queues.length, 3, 'queue was not added twice');
});
});
enifed('ember-metal/tests/run_loop/debounce_test', ['ember-metal'], function (_emberMetal) {
'use strict';
var originalDebounce = _emberMetal.run.backburner.debounce;
var wasCalled = false;
QUnit.module('Ember.run.debounce', {
setup: function () {
_emberMetal.run.backburner.debounce = function () {
wasCalled = true;
};
},
teardown: function () {
_emberMetal.run.backburner.debounce = originalDebounce;
}
});
QUnit.test('Ember.run.debounce uses Backburner.debounce', function () {
_emberMetal.run.debounce(function () {});
ok(wasCalled, 'Ember.run.debounce used');
});
});
enifed('ember-metal/tests/run_loop/later_test', ['ember-metal'], function (_emberMetal) {
'use strict';
var originalSetTimeout = window.setTimeout;
var originalDateValueOf = Date.prototype.valueOf;
var originalPlatform = _emberMetal.run.backburner._platform;
function wait(callback, maxWaitCount) {
maxWaitCount = (0, _emberMetal.isNone)(maxWaitCount) ? 100 : maxWaitCount;
originalSetTimeout(function () {
if (maxWaitCount > 0 && (_emberMetal.run.hasScheduledTimers() || _emberMetal.run.currentRunLoop)) {
wait(callback, maxWaitCount - 1);
return;
}
callback();
}, 10);
}
// Synchronous "sleep". This simulates work being done
// after run.later was called but before the run loop
// has flushed. In previous versions, this would have
// caused the run.later callback to have run from
// within the run loop flush, since by the time the
// run loop has to flush, it would have considered
// the timer already expired.
function pauseUntil(time) {
// jscs:disable
while (+new Date() < time) {} /* do nothing - sleeping */
// jscs:enable
}
QUnit.module('run.later', {
teardown: function () {
_emberMetal.run.backburner._platform = originalPlatform;
window.setTimeout = originalSetTimeout;
Date.prototype.valueOf = originalDateValueOf;
}
});
asyncTest('should invoke after specified period of time - function only', function () {
var invoked = false;
(0, _emberMetal.run)(function () {
_emberMetal.run.later(function () {
return invoked = true;
}, 100);
});
wait(function () {
QUnit.start();
equal(invoked, true, 'should have invoked later item');
});
});
asyncTest('should invoke after specified period of time - target/method', function () {
var obj = { invoked: false };
(0, _emberMetal.run)(function () {
_emberMetal.run.later(obj, function () {
this.invoked = true;
}, 100);
});
wait(function () {
QUnit.start();
equal(obj.invoked, true, 'should have invoked later item');
});
});
asyncTest('should invoke after specified period of time - target/method/args', function () {
var obj = { invoked: 0 };
(0, _emberMetal.run)(function () {
_emberMetal.run.later(obj, function (amt) {
this.invoked += amt;
}, 10, 100);
});
wait(function () {
QUnit.start();
equal(obj.invoked, 10, 'should have invoked later item');
});
});
asyncTest('should always invoke within a separate runloop', function () {
var obj = { invoked: 0 };
var firstRunLoop = void 0,
secondRunLoop = void 0;
(0, _emberMetal.run)(function () {
firstRunLoop = _emberMetal.run.currentRunLoop;
_emberMetal.run.later(obj, function (amt) {
this.invoked += amt;
secondRunLoop = _emberMetal.run.currentRunLoop;
}, 10, 1);
pauseUntil(+new Date() + 100);
});
ok(firstRunLoop, 'first run loop captured');
ok(!_emberMetal.run.currentRunLoop, 'shouldn\'t be in a run loop after flush');
equal(obj.invoked, 0, 'shouldn\'t have invoked later item yet');
wait(function () {
QUnit.start();
equal(obj.invoked, 10, 'should have invoked later item');
ok(secondRunLoop, 'second run loop took place');
ok(secondRunLoop !== firstRunLoop, 'two different run loops took place');
});
});
// Our current implementation doesn't allow us to correctly enforce this ordering.
// We should probably implement a queue to provide this guarantee.
// See https://github.com/emberjs/ember.js/issues/3526 for more information.
// asyncTest('callback order', function() {
// let array = [];
// function fn(val) { array.push(val); }
// run(function() {
// run.later(this, fn, 4, 5);
// run.later(this, fn, 1, 1);
// run.later(this, fn, 5, 10);
// run.later(this, fn, 2, 3);
// run.later(this, fn, 3, 3);
// });
// deepEqual(array, []);
// wait(function() {
// QUnit.start();
// deepEqual(array, [1,2,3,4,5], 'callbacks were called in expected order');
// });
// });
// Out current implementation doesn't allow us to properly enforce what is tested here.
// We should probably fix it, but it's not technically a bug right now.
// See https://github.com/emberjs/ember.js/issues/3522 for more information.
// asyncTest('callbacks coalesce into same run loop if expiring at the same time', function() {
// let array = [];
// function fn(val) { array.push(run.currentRunLoop); }
// run(function() {
// // Force +new Date to return the same result while scheduling
// // run.later timers. Otherwise: non-determinism!
// let now = +new Date();
// Date.prototype.valueOf = function() { return now; };
// run.later(this, fn, 10);
// run.later(this, fn, 200);
// run.later(this, fn, 200);
// Date.prototype.valueOf = originalDateValueOf;
// });
// deepEqual(array, []);
// wait(function() {
// QUnit.start();
// equal(array.length, 3, 'all callbacks called');
// ok(array[0] !== array[1], 'first two callbacks have different run loops');
// ok(array[0], 'first runloop present');
// ok(array[1], 'second runloop present');
// equal(array[1], array[2], 'last two callbacks got the same run loop');
// });
// });
asyncTest('inception calls to run.later should run callbacks in separate run loops', function () {
var runLoop = void 0,
finished = void 0;
(0, _emberMetal.run)(function () {
runLoop = _emberMetal.run.currentRunLoop;
ok(runLoop);
_emberMetal.run.later(function () {
ok(_emberMetal.run.currentRunLoop && _emberMetal.run.currentRunLoop !== runLoop, 'first later callback has own run loop');
runLoop = _emberMetal.run.currentRunLoop;
_emberMetal.run.later(function () {
ok(_emberMetal.run.currentRunLoop && _emberMetal.run.currentRunLoop !== runLoop, 'second later callback has own run loop');
finished = true;
}, 40);
}, 40);
});
wait(function () {
QUnit.start();
ok(finished, 'all .later callbacks run');
});
});
asyncTest('setTimeout should never run with a negative wait', function () {
// Rationale: The old run loop code was susceptible to an occasional
// bug where invokeLaterTimers would be scheduled with a setTimeout
// with a negative wait. Modern browsers normalize this to 0, but
// older browsers (IE <= 8) break with a negative wait, which
// happens when an expired timer callback takes a while to run,
// which is what we simulate here.
var newSetTimeoutUsed = void 0;
_emberMetal.run.backburner._platform = {
setTimeout: function () {
var wait = arguments[arguments.length - 1];
newSetTimeoutUsed = true;
ok(!isNaN(wait) && wait >= 0, 'wait is a non-negative number');
return originalPlatform.setTimeout.apply(originalPlatform, arguments);
}
};
var count = 0;
(0, _emberMetal.run)(function () {
_emberMetal.run.later(function () {
count++;
// This will get run first. Waste some time.
// This is intended to break invokeLaterTimers code by taking a
// long enough time that other timers should technically expire. It's
// fine that they're not called in this run loop; just need to
// make sure that invokeLaterTimers doesn't end up scheduling
// a negative setTimeout.
pauseUntil(+new Date() + 60);
}, 1);
_emberMetal.run.later(function () {
equal(count, 1, 'callbacks called in order');
}, 50);
});
wait(function () {
QUnit.start();
ok(newSetTimeoutUsed, 'stub setTimeout was used');
});
});
});
enifed('ember-metal/tests/run_loop/next_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('run.next');
asyncTest('should invoke immediately on next timeout', function () {
var invoked = false;
(0, _emberMetal.run)(function () {
return _emberMetal.run.next(function () {
return invoked = true;
});
});
equal(invoked, false, 'should not have invoked yet');
setTimeout(function () {
QUnit.start();
equal(invoked, true, 'should have invoked later item');
}, 20);
});
asyncTest('callback should be called from within separate loop', function () {
var firstRunLoop = void 0,
secondRunLoop = void 0;
(0, _emberMetal.run)(function () {
firstRunLoop = _emberMetal.run.currentRunLoop;
_emberMetal.run.next(function () {
return secondRunLoop = _emberMetal.run.currentRunLoop;
});
});
setTimeout(function () {
QUnit.start();
ok(secondRunLoop, 'callback was called from within run loop');
ok(firstRunLoop && secondRunLoop !== firstRunLoop, 'two separate run loops were invoked');
}, 20);
});
asyncTest('multiple calls to run.next share coalesce callbacks into same run loop', function () {
var secondRunLoop = void 0,
thirdRunLoop = void 0;
(0, _emberMetal.run)(function () {
_emberMetal.run.next(function () {
return secondRunLoop = _emberMetal.run.currentRunLoop;
});
_emberMetal.run.next(function () {
return thirdRunLoop = _emberMetal.run.currentRunLoop;
});
});
setTimeout(function () {
QUnit.start();
ok(secondRunLoop && secondRunLoop === thirdRunLoop, 'callbacks coalesced into same run loop');
}, 20);
});
});
enifed('ember-metal/tests/run_loop/once_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('system/run_loop/once_test');
QUnit.test('calling invokeOnce more than once invokes only once', function () {
var count = 0;
(0, _emberMetal.run)(function () {
function F() {
count++;
}
_emberMetal.run.once(F);
_emberMetal.run.once(F);
_emberMetal.run.once(F);
});
equal(count, 1, 'should have invoked once');
});
QUnit.test('should differentiate based on target', function () {
var A = { count: 0 };
var B = { count: 0 };
(0, _emberMetal.run)(function () {
function F() {
this.count++;
}
_emberMetal.run.once(A, F);
_emberMetal.run.once(B, F);
_emberMetal.run.once(A, F);
_emberMetal.run.once(B, F);
});
equal(A.count, 1, 'should have invoked once on A');
equal(B.count, 1, 'should have invoked once on B');
});
QUnit.test('should ignore other arguments - replacing previous ones', function () {
var A = { count: 0 };
var B = { count: 0 };
(0, _emberMetal.run)(function () {
function F(amt) {
this.count += amt;
}
_emberMetal.run.once(A, F, 10);
_emberMetal.run.once(B, F, 20);
_emberMetal.run.once(A, F, 30);
_emberMetal.run.once(B, F, 40);
});
equal(A.count, 30, 'should have invoked once on A');
equal(B.count, 40, 'should have invoked once on B');
});
QUnit.test('should be inside of a runloop when running', function () {
(0, _emberMetal.run)(function () {
_emberMetal.run.once(function () {
return ok(!!_emberMetal.run.currentRunLoop, 'should have a runloop');
});
});
});
});
enifed('ember-metal/tests/run_loop/onerror_test', ['ember-metal', 'ember-debug'], function (_emberMetal, _emberDebug) {
'use strict';
QUnit.module('system/run_loop/onerror_test');
QUnit.test('With Ember.onerror undefined, errors in Ember.run are thrown', function () {
var thrown = new Error('Boom!');
var original = (0, _emberMetal.getOnerror)();
var caught = void 0;
(0, _emberMetal.setOnerror)(undefined);
try {
(0, _emberMetal.run)(function () {
throw thrown;
});
} catch (error) {
caught = error;
} finally {
(0, _emberMetal.setOnerror)(original);
}
deepEqual(caught, thrown);
});
QUnit.test('With Ember.onerror set, errors in Ember.run are caught', function () {
var thrown = new Error('Boom!');
var original = (0, _emberMetal.getOnerror)();
var originalDispatchOverride = (0, _emberMetal.getDispatchOverride)();
var originalIsTesting = (0, _emberDebug.isTesting)();
var caught = void 0;
(0, _emberMetal.setOnerror)(function (error) {
caught = error;
});
(0, _emberMetal.setDispatchOverride)(null);
(0, _emberDebug.setTesting)(false);
try {
(0, _emberMetal.run)(function () {
throw thrown;
});
} finally {
(0, _emberMetal.setOnerror)(original);
(0, _emberMetal.setDispatchOverride)(originalDispatchOverride);
(0, _emberDebug.setTesting)(originalIsTesting);
}
deepEqual(caught, thrown);
});
});
enifed('ember-metal/tests/run_loop/run_bind_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('system/run_loop/run_bind_test');
QUnit.test('Ember.run.bind builds a run-loop wrapped callback handler', function () {
expect(3);
var obj = {
value: 0,
increment: function (increment) {
ok(_emberMetal.run.currentRunLoop, 'expected a run-loop');
return this.value += increment;
}
};
var proxiedFunction = _emberMetal.run.bind(obj, obj.increment, 1);
equal(proxiedFunction(), 1);
equal(obj.value, 1);
});
QUnit.test('Ember.run.bind keeps the async callback arguments', function () {
expect(4);
function asyncCallback(increment, increment2, increment3) {
ok(_emberMetal.run.currentRunLoop, 'expected a run-loop');
equal(increment, 1);
equal(increment2, 2);
equal(increment3, 3);
}
(function (fn) {
fn(2, 3);
})(_emberMetal.run.bind(asyncCallback, asyncCallback, 1));
});
});
enifed('ember-metal/tests/run_loop/run_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('system/run_loop/run_test');
QUnit.test('Ember.run invokes passed function, returning value', function () {
var obj = {
foo: function () {
return [this.bar, 'FOO'];
},
bar: 'BAR',
checkArgs: function (arg1, arg2) {
return [arg1, this.bar, arg2];
}
};
equal((0, _emberMetal.run)(function () {
return 'FOO';
}), 'FOO', 'pass function only');
deepEqual((0, _emberMetal.run)(obj, obj.foo), ['BAR', 'FOO'], 'pass obj and obj.method');
deepEqual((0, _emberMetal.run)(obj, 'foo'), ['BAR', 'FOO'], 'pass obj and "method"');
deepEqual((0, _emberMetal.run)(obj, obj.checkArgs, 'hello', 'world'), ['hello', 'BAR', 'world'], 'pass obj, obj.method, and extra arguments');
});
});
enifed('ember-metal/tests/run_loop/schedule_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('system/run_loop/schedule_test');
QUnit.test('scheduling item in queue should defer until finished', function () {
var cnt = 0;
(0, _emberMetal.run)(function () {
_emberMetal.run.schedule('actions', function () {
return cnt++;
});
_emberMetal.run.schedule('actions', function () {
return cnt++;
});
equal(cnt, 0, 'should not run action yet');
});
equal(cnt, 2, 'should flush actions now');
});
QUnit.test('a scheduled item can be canceled', function (assert) {
var hasRan = false;
(0, _emberMetal.run)(function () {
var cancelId = _emberMetal.run.schedule('actions', function () {
return hasRan = true;
});
_emberMetal.run.cancel(cancelId);
});
assert.notOk(hasRan, 'should not have ran callback run');
});
QUnit.test('nested runs should queue each phase independently', function () {
var cnt = 0;
(0, _emberMetal.run)(function () {
_emberMetal.run.schedule('actions', function () {
return cnt++;
});
equal(cnt, 0, 'should not run action yet');
(0, _emberMetal.run)(function () {
_emberMetal.run.schedule('actions', function () {
return cnt++;
});
});
equal(cnt, 1, 'should not run action yet');
});
equal(cnt, 2, 'should flush actions now');
});
QUnit.test('prior queues should be flushed before moving on to next queue', function () {
var order = [];
(0, _emberMetal.run)(function () {
var runLoop = _emberMetal.run.currentRunLoop;
ok(runLoop, 'run loop present');
_emberMetal.run.schedule('sync', function () {
order.push('sync');
equal(runLoop, _emberMetal.run.currentRunLoop, 'same run loop used');
});
_emberMetal.run.schedule('actions', function () {
order.push('actions');
equal(runLoop, _emberMetal.run.currentRunLoop, 'same run loop used');
_emberMetal.run.schedule('actions', function () {
order.push('actions');
equal(runLoop, _emberMetal.run.currentRunLoop, 'same run loop used');
});
_emberMetal.run.schedule('sync', function () {
order.push('sync');
equal(runLoop, _emberMetal.run.currentRunLoop, 'same run loop used');
});
});
_emberMetal.run.schedule('destroy', function () {
order.push('destroy');
equal(runLoop, _emberMetal.run.currentRunLoop, 'same run loop used');
});
});
deepEqual(order, ['sync', 'actions', 'sync', 'actions', 'destroy']);
});
QUnit.test('makes sure it does not trigger an autorun during testing', function () {
expectAssertion(function () {
return _emberMetal.run.schedule('actions', function () {});
}, /wrap any code with asynchronous side-effects in a run/);
// make sure not just the first violation is asserted.
expectAssertion(function () {
return _emberMetal.run.schedule('actions', function () {});
}, /wrap any code with asynchronous side-effects in a run/);
});
});
enifed('ember-metal/tests/run_loop/sync_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('system/run_loop/sync_test');
QUnit.test('sync() will immediately flush the sync queue only', function () {
var cnt = 0;
(0, _emberMetal.run)(function () {
function cntup() {
cnt++;
}
function syncfunc() {
if (++cnt < 5) {
_emberMetal.run.schedule('sync', syncfunc);
}
_emberMetal.run.schedule('actions', cntup);
}
syncfunc();
equal(cnt, 1, 'should not run action yet');
_emberMetal.run.sync();
equal(cnt, 5, 'should have run sync queue continuously');
});
equal(cnt, 10, 'should flush actions now too');
});
QUnit.test('calling sync() outside a run loop does not cause an error', function () {
expect(0);
_emberMetal.run.sync();
});
});
enifed('ember-metal/tests/run_loop/unwind_test', ['ember-metal', 'ember-debug'], function (_emberMetal, _emberDebug) {
'use strict';
QUnit.module('system/run_loop/unwind_test');
QUnit.test('RunLoop unwinds despite unhandled exception', function () {
var initialRunLoop = _emberMetal.run.currentRunLoop;
throws(function () {
(0, _emberMetal.run)(function () {
_emberMetal.run.schedule('actions', function () {
throw new _emberDebug.Error('boom!');
});
});
}, Error, 'boom!');
// The real danger at this point is that calls to autorun will stick
// tasks into the already-dead runloop, which will never get
// flushed. I can't easily demonstrate this in a unit test because
// autorun explicitly doesn't work in test mode. - ef4
equal(_emberMetal.run.currentRunLoop, initialRunLoop, 'Previous run loop should be cleaned up despite exception');
// Prevent a failure in this test from breaking subsequent tests.
_emberMetal.run.currentRunLoop = initialRunLoop;
});
QUnit.test('run unwinds despite unhandled exception', function () {
var initialRunLoop = _emberMetal.run.currentRunLoop;
throws(function () {
(0, _emberMetal.run)(function () {
throw new _emberDebug.Error('boom!');
});
}, _emberDebug.Error, 'boom!');
equal(_emberMetal.run.currentRunLoop, initialRunLoop, 'Previous run loop should be cleaned up despite exception');
// Prevent a failure in this test from breaking subsequent tests.
_emberMetal.run.currentRunLoop = initialRunLoop;
});
});
enifed('ember-metal/tests/set_properties_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.setProperties');
QUnit.test('supports setting multiple attributes at once', function () {
deepEqual((0, _emberMetal.setProperties)(null, null), null, 'noop for null properties and null object');
deepEqual((0, _emberMetal.setProperties)(undefined, undefined), undefined, 'noop for undefined properties and undefined object');
deepEqual((0, _emberMetal.setProperties)({}), undefined, 'noop for no properties');
deepEqual((0, _emberMetal.setProperties)({}, undefined), undefined, 'noop for undefined');
deepEqual((0, _emberMetal.setProperties)({}, null), null, 'noop for null');
deepEqual((0, _emberMetal.setProperties)({}, NaN), NaN, 'noop for NaN');
deepEqual((0, _emberMetal.setProperties)({}, {}), {}, 'meh');
deepEqual((0, _emberMetal.setProperties)({}, { foo: 1 }), { foo: 1 }, 'Set a single property');
deepEqual((0, _emberMetal.setProperties)({}, { foo: 1, bar: 1 }), { foo: 1, bar: 1 }, 'Set multiple properties');
deepEqual((0, _emberMetal.setProperties)({ foo: 2, baz: 2 }, { foo: 1 }), { foo: 1 }, 'Set one of multiple properties');
deepEqual((0, _emberMetal.setProperties)({ foo: 2, baz: 2 }, { bar: 2 }), {
bar: 2
}, 'Set an additional, previously unset property');
});
});
enifed('ember-metal/tests/watching/is_watching_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('isWatching');
function testObserver(setup, teardown) {
var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'key';
var obj = {};
function fn() {}
equal((0, _emberMetal.isWatching)(obj, key), false, 'precond - isWatching is false by default');
setup(obj, key, fn);
equal((0, _emberMetal.isWatching)(obj, key), true, 'isWatching is true when observers are added');
teardown(obj, key, fn);
equal((0, _emberMetal.isWatching)(obj, key), false, 'isWatching is false after observers are removed');
}
QUnit.test('isWatching is true for regular local observers', function () {
testObserver(function (obj, key, fn) {
_emberMetal.Mixin.create({
didChange: (0, _emberMetal.observer)(key, fn)
}).apply(obj);
}, function (obj, key, fn) {
return (0, _emberMetal.removeObserver)(obj, key, obj, fn);
});
});
QUnit.test('isWatching is true for nonlocal observers', function () {
testObserver(function (obj, key, fn) {
(0, _emberMetal.addObserver)(obj, key, obj, fn);
}, function (obj, key, fn) {
return (0, _emberMetal.removeObserver)(obj, key, obj, fn);
});
});
QUnit.test('isWatching is true for chained observers', function () {
testObserver(function (obj, key, fn) {
(0, _emberMetal.addObserver)(obj, key + '.bar', obj, fn);
}, function (obj, key, fn) {
(0, _emberMetal.removeObserver)(obj, key + '.bar', obj, fn);
});
});
QUnit.test('isWatching is true for computed properties', function () {
testObserver(function (obj, key, fn) {
(0, _emberMetal.defineProperty)(obj, 'computed', (0, _emberMetal.computed)(fn).property(key));
(0, _emberMetal.get)(obj, 'computed');
}, function (obj) {
return (0, _emberMetal.defineProperty)(obj, 'computed', null);
});
});
QUnit.test('isWatching is true for chained computed properties', function () {
testObserver(function (obj, key, fn) {
(0, _emberMetal.defineProperty)(obj, 'computed', (0, _emberMetal.computed)(fn).property(key + '.bar'));
(0, _emberMetal.get)(obj, 'computed');
}, function (obj) {
return (0, _emberMetal.defineProperty)(obj, 'computed', null);
});
});
// can't watch length on Array - it is special...
// But you should be able to watch a length property of an object
QUnit.test('isWatching is true for \'length\' property on object', function () {
testObserver(function (obj, key, fn) {
(0, _emberMetal.defineProperty)(obj, 'length', null, '26.2 miles');
(0, _emberMetal.addObserver)(obj, 'length', obj, fn);
}, function (obj, key, fn) {
return (0, _emberMetal.removeObserver)(obj, 'length', obj, fn);
}, 'length');
});
});
enifed('ember-metal/tests/watching/unwatch_test', ['internal-test-helpers', 'ember-metal'], function (_internalTestHelpers, _emberMetal) {
'use strict';
var willCount = void 0,
didCount = void 0;
QUnit.module('unwatch', {
setup: function () {
willCount = didCount = 0;
}
});
function addListeners(obj, keyPath) {
(0, _emberMetal.addListener)(obj, keyPath + ':before', function () {
return willCount++;
});
(0, _emberMetal.addListener)(obj, keyPath + ':change', function () {
return didCount++;
});
}
(0, _internalTestHelpers.testBoth)('unwatching a computed property - regular get/set', function (get, set) {
var obj = {};
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({
get: function () {
return this.__foo;
},
set: function (keyName, value) {
this.__foo = value;
return this.__foo;
}
}));
addListeners(obj, 'foo');
(0, _emberMetal.watch)(obj, 'foo');
set(obj, 'foo', 'bar');
equal(willCount, 1, 'should have invoked willCount');
equal(didCount, 1, 'should have invoked didCount');
(0, _emberMetal.unwatch)(obj, 'foo');
willCount = didCount = 0;
set(obj, 'foo', 'BAZ');
equal(willCount, 0, 'should NOT have invoked willCount');
equal(didCount, 0, 'should NOT have invoked didCount');
});
(0, _internalTestHelpers.testBoth)('unwatching a regular property - regular get/set', function (get, set) {
var obj = { foo: 'BIFF' };
addListeners(obj, 'foo');
(0, _emberMetal.watch)(obj, 'foo');
set(obj, 'foo', 'bar');
equal(willCount, 1, 'should have invoked willCount');
equal(didCount, 1, 'should have invoked didCount');
(0, _emberMetal.unwatch)(obj, 'foo');
willCount = didCount = 0;
set(obj, 'foo', 'BAZ');
equal(willCount, 0, 'should NOT have invoked willCount');
equal(didCount, 0, 'should NOT have invoked didCount');
});
QUnit.test('unwatching should be nested', function () {
var obj = { foo: 'BIFF' };
addListeners(obj, 'foo');
(0, _emberMetal.watch)(obj, 'foo');
(0, _emberMetal.watch)(obj, 'foo');
(0, _emberMetal.set)(obj, 'foo', 'bar');
equal(willCount, 1, 'should have invoked willCount');
equal(didCount, 1, 'should have invoked didCount');
(0, _emberMetal.unwatch)(obj, 'foo');
willCount = didCount = 0;
(0, _emberMetal.set)(obj, 'foo', 'BAZ');
equal(willCount, 1, 'should NOT have invoked willCount');
equal(didCount, 1, 'should NOT have invoked didCount');
(0, _emberMetal.unwatch)(obj, 'foo');
willCount = didCount = 0;
(0, _emberMetal.set)(obj, 'foo', 'BAZ');
equal(willCount, 0, 'should NOT have invoked willCount');
equal(didCount, 0, 'should NOT have invoked didCount');
});
(0, _internalTestHelpers.testBoth)('unwatching "length" property on an object', function (get, set) {
var obj = { foo: 'RUN' };
addListeners(obj, 'length');
// Can watch length when it is undefined
(0, _emberMetal.watch)(obj, 'length');
set(obj, 'length', '10k');
equal(willCount, 1, 'should have invoked willCount');
equal(didCount, 1, 'should have invoked didCount');
// Should stop watching despite length now being defined (making object 'array-like')
(0, _emberMetal.unwatch)(obj, 'length');
willCount = didCount = 0;
set(obj, 'length', '5k');
equal(willCount, 0, 'should NOT have invoked willCount');
equal(didCount, 0, 'should NOT have invoked didCount');
});
(0, _internalTestHelpers.testBoth)('unwatching should not destroy non MANDATORY_SETTER descriptor', function () {
var obj = { get foo() {
return 'RUN';
} };
equal(obj.foo, 'RUN', 'obj.foo');
(0, _emberMetal.watch)(obj, 'foo');
equal(obj.foo, 'RUN', 'obj.foo after watch');
(0, _emberMetal.unwatch)(obj, 'foo');
equal(obj.foo, 'RUN', 'obj.foo after unwatch');
});
});
enifed('ember-metal/tests/watching/watch_test', ['ember-environment', 'ember-metal', 'internal-test-helpers'], function (_emberEnvironment, _emberMetal, _internalTestHelpers) {
'use strict';
var willCount = void 0,
didCount = void 0,
willKeys = void 0,
didKeys = void 0,
originalLookup = void 0;
QUnit.module('watch', {
setup: function () {
willCount = didCount = 0;
willKeys = [];
didKeys = [];
originalLookup = _emberEnvironment.context.lookup;
_emberEnvironment.context.lookup = {};
},
teardown: function () {
_emberEnvironment.context.lookup = originalLookup;
}
});
function addListeners(obj, keyPath) {
(0, _emberMetal.addListener)(obj, keyPath + ':before', function () {
willCount++;
willKeys.push(keyPath);
});
(0, _emberMetal.addListener)(obj, keyPath + ':change', function () {
didCount++;
didKeys.push(keyPath);
});
}
(0, _internalTestHelpers.testBoth)('watching a computed property', function (get, set) {
var obj = {};
(0, _emberMetal.defineProperty)(obj, 'foo', (0, _emberMetal.computed)({
get: function () {
return this.__foo;
},
set: function (keyName, value) {
if (value !== undefined) {
this.__foo = value;
}
return this.__foo;
}
}));
addListeners(obj, 'foo');
(0, _emberMetal.watch)(obj, 'foo');
set(obj, 'foo', 'bar');
equal(willCount, 1, 'should have invoked willCount');
equal(didCount, 1, 'should have invoked didCount');
});
(0, _internalTestHelpers.testBoth)('watching a regular defined property', function (get, set) {
var obj = { foo: 'baz' };
addListeners(obj, 'foo');
(0, _emberMetal.watch)(obj, 'foo');
equal(get(obj, 'foo'), 'baz', 'should have original prop');
set(obj, 'foo', 'bar');
equal(willCount, 1, 'should have invoked willCount');
equal(didCount, 1, 'should have invoked didCount');
equal(get(obj, 'foo'), 'bar', 'should get new value');
equal(obj.foo, 'bar', 'property should be accessible on obj');
});
(0, _internalTestHelpers.testBoth)('watching a regular undefined property', function (get, set) {
var obj = {};
addListeners(obj, 'foo');
(0, _emberMetal.watch)(obj, 'foo');
equal('foo' in obj, false, 'precond undefined');
set(obj, 'foo', 'bar');
equal(willCount, 1, 'should have invoked willCount');
equal(didCount, 1, 'should have invoked didCount');
equal(get(obj, 'foo'), 'bar', 'should get new value');
equal(obj.foo, 'bar', 'property should be accessible on obj');
});
(0, _internalTestHelpers.testBoth)('watches should inherit', function (get, set) {
var obj = { foo: 'baz' };
var objB = Object.create(obj);
addListeners(obj, 'foo');
(0, _emberMetal.watch)(obj, 'foo');
equal(get(obj, 'foo'), 'baz', 'should have original prop');
set(obj, 'foo', 'bar');
set(objB, 'foo', 'baz');
equal(willCount, 2, 'should have invoked willCount once only');
equal(didCount, 2, 'should have invoked didCount once only');
});
QUnit.test('watching an object THEN defining it should work also', function () {
var obj = {};
addListeners(obj, 'foo');
(0, _emberMetal.watch)(obj, 'foo');
(0, _emberMetal.defineProperty)(obj, 'foo');
(0, _emberMetal.set)(obj, 'foo', 'bar');
equal((0, _emberMetal.get)(obj, 'foo'), 'bar', 'should have set');
equal(willCount, 1, 'should have invoked willChange once');
equal(didCount, 1, 'should have invoked didChange once');
});
QUnit.test('watching a chain then defining the property', function () {
var obj = {};
var foo = { bar: 'bar' };
addListeners(obj, 'foo.bar');
addListeners(foo, 'bar');
(0, _emberMetal.watch)(obj, 'foo.bar');
(0, _emberMetal.defineProperty)(obj, 'foo', undefined, foo);
(0, _emberMetal.set)(foo, 'bar', 'baz');
deepEqual(willKeys, ['foo.bar', 'bar'], 'should have invoked willChange with bar, foo.bar');
deepEqual(didKeys, ['foo.bar', 'bar'], 'should have invoked didChange with bar, foo.bar');
equal(willCount, 2, 'should have invoked willChange twice');
equal(didCount, 2, 'should have invoked didChange twice');
});
QUnit.test('watching a chain then defining the nested property', function () {
var bar = {};
var obj = { foo: bar };
var baz = { baz: 'baz' };
addListeners(obj, 'foo.bar.baz');
addListeners(baz, 'baz');
(0, _emberMetal.watch)(obj, 'foo.bar.baz');
(0, _emberMetal.defineProperty)(bar, 'bar', undefined, baz);
(0, _emberMetal.set)(baz, 'baz', 'BOO');
deepEqual(willKeys, ['foo.bar.baz', 'baz'], 'should have invoked willChange with bar, foo.bar');
deepEqual(didKeys, ['foo.bar.baz', 'baz'], 'should have invoked didChange with bar, foo.bar');
equal(willCount, 2, 'should have invoked willChange twice');
equal(didCount, 2, 'should have invoked didChange twice');
});
(0, _internalTestHelpers.testBoth)('watching an object value then unwatching should restore old value', function (get) {
var obj = { foo: { bar: { baz: { biff: 'BIFF' } } } };
addListeners(obj, 'foo.bar.baz.biff');
(0, _emberMetal.watch)(obj, 'foo.bar.baz.biff');
var foo = get(obj, 'foo');
equal(get(get(get(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist');
(0, _emberMetal.unwatch)(obj, 'foo.bar.baz.biff');
equal(get(get(get(foo, 'bar'), 'baz'), 'biff'), 'BIFF', 'biff should exist');
});
QUnit.test('when watching another object, destroy should remove chain watchers from the other object', function () {
var objA = {};
var objB = { foo: 'bar' };
objA.b = objB;
addListeners(objA, 'b.foo');
(0, _emberMetal.watch)(objA, 'b.foo');
var meta_objB = (0, _emberMetal.meta)(objB);
var chainNode = (0, _emberMetal.meta)(objA).readableChains()._chains.b._chains.foo;
equal(meta_objB.peekWatching('foo'), 1, 'should be watching foo');
equal(meta_objB.readableChainWatchers().has('foo', chainNode), true, 'should have chain watcher');
(0, _emberMetal.destroy)(objA);
equal(meta_objB.peekWatching('foo'), 0, 'should not be watching foo');
equal(meta_objB.readableChainWatchers().has('foo', chainNode), false, 'should not have chain watcher');
});
// TESTS for length property
(0, _internalTestHelpers.testBoth)('watching "length" property on an object', function (get, set) {
var obj = { length: '26.2 miles' };
addListeners(obj, 'length');
(0, _emberMetal.watch)(obj, 'length');
equal(get(obj, 'length'), '26.2 miles', 'should have original prop');
set(obj, 'length', '10k');
equal(willCount, 1, 'should have invoked willCount');
equal(didCount, 1, 'should have invoked didCount');
equal(get(obj, 'length'), '10k', 'should get new value');
equal(obj.length, '10k', 'property should be accessible on obj');
});
(0, _internalTestHelpers.testBoth)('watching "length" property on an array', function (get, set) {
var arr = [];
addListeners(arr, 'length');
(0, _emberMetal.watch)(arr, 'length');
equal(get(arr, 'length'), 0, 'should have original prop');
set(arr, 'length', '10');
equal(willCount, 1, 'should NOT have invoked willCount');
equal(didCount, 1, 'should NOT have invoked didCount');
equal(get(arr, 'length'), 10, 'should get new value');
equal(arr.length, 10, 'property should be accessible on arr');
});
(0, _internalTestHelpers.testBoth)('watch + ES5 getter', function (get) {
var parent = { b: 1 };
var child = {
get b() {
return parent.b;
}
};
equal(parent.b, 1, 'parent.b should be 1');
equal(child.b, 1, 'child.b should be 1');
equal(get(child, 'b'), 1, 'Ember.get(child, "b") should be 1');
(0, _emberMetal.watch)(child, 'b');
equal(parent.b, 1, 'parent.b should be 1 (after watch)');
equal(child.b, 1, 'child.b should be 1 (after watch)');
equal(get(child, 'b'), 1, 'Ember.get(child, "b") should be 1 (after watch)');
});
(0, _internalTestHelpers.testBoth)('watch + Ember.set + no-descriptor', function (get, set) {
var child = {};
equal(child.b, undefined, 'child.b ');
equal(get(child, 'b'), undefined, 'Ember.get(child, "b")');
(0, _emberMetal.watch)(child, 'b');
set(child, 'b', 1);
equal(child.b, 1, 'child.b (after watch)');
equal(get(child, 'b'), 1, 'Ember.get(child, "b") (after watch)');
});
});
enifed('ember-metal/tests/weak_map_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('Ember.WeakMap');
QUnit.test('has weakMap like qualities', function (assert) {
var map = new _emberMetal.WeakMap();
var map2 = new _emberMetal.WeakMap();
var a = {};
var b = {};
var c = {};
assert.strictEqual(map.get(a), undefined);
assert.strictEqual(map.get(b), undefined);
assert.strictEqual(map.get(c), undefined);
assert.strictEqual(map2.get(a), undefined);
assert.strictEqual(map2.get(b), undefined);
assert.strictEqual(map2.get(c), undefined);
assert.strictEqual(map.set(a, 1), map, 'map.set should return itself');
assert.strictEqual(map.get(a), 1);
assert.strictEqual(map.set(b, undefined), map);
assert.strictEqual(map.set(a, 2), map);
assert.strictEqual(map.get(a), 2);
assert.strictEqual(map.set(b, undefined), map);
assert.strictEqual(map2.get(a), undefined);
assert.strictEqual(map2.get(b), undefined);
assert.strictEqual(map2.get(c), undefined);
assert.strictEqual(map.set(c, 1), map);
assert.strictEqual(map.get(c), 1);
assert.strictEqual(map.get(a), 2);
assert.strictEqual(map.get(b), undefined);
assert.strictEqual(map2.set(a, 3), map2);
assert.strictEqual(map2.set(b, 4), map2);
assert.strictEqual(map2.set(c, 5), map2);
assert.strictEqual(map2.get(a), 3);
assert.strictEqual(map2.get(b), 4);
assert.strictEqual(map2.get(c), 5);
assert.strictEqual(map.get(c), 1);
assert.strictEqual(map.get(a), 2);
assert.strictEqual(map.get(b), undefined);
});
QUnit.test('WeakMap constructor requres new', function (assert) {
var expectedError = new TypeError('Constructor WeakMap requires \'new\'');
assert.throws(function () {
// jshint newcap: false
(0, _emberMetal.WeakMap)();
}, expectedError);
});
QUnit.test('constructing a WeakMap with an invalid iterator throws an error', function (assert) {
var expectedError = new TypeError('The weak map constructor polyfill only supports an array argument');
assert.throws(function () {
new _emberMetal.WeakMap({ a: 1 });
}, expectedError);
});
QUnit.test('constructing a WeakMap with a valid iterator inserts the entries', function (assert) {
var a = {};
var b = {};
var c = {};
var map = new _emberMetal.WeakMap([[a, 1], [b, 2], [c, 3]]);
assert.strictEqual(map.get(a), 1);
assert.strictEqual(map.get(b), 2);
assert.strictEqual(map.get(c), 3);
});
QUnit.test('that error is thrown when using a primitive key', function (assert) {
var expectedError = new TypeError('Invalid value used as weak map key');
var map = new _emberMetal.WeakMap();
assert.throws(function () {
return map.set('a', 1);
}, expectedError);
assert.throws(function () {
return map.set(1, 1);
}, expectedError);
assert.throws(function () {
return map.set(true, 1);
}, expectedError);
assert.throws(function () {
return map.set(null, 1);
}, expectedError);
assert.throws(function () {
return map.set(undefined, 1);
}, expectedError);
});
QUnit.test('that .has and .delete work as expected', function (assert) {
var map = new _emberMetal.WeakMap();
var a = {};
var foo = { id: 1, name: 'My file', progress: 0 };
assert.strictEqual(map.set(a, foo), map);
assert.strictEqual(map.get(a), foo);
assert.strictEqual(map.has(a), true);
assert.strictEqual(map.has({}), false);
assert.strictEqual(map.delete(a), true);
assert.strictEqual(map.has(a), false);
assert.strictEqual(map.delete(a), false);
assert.strictEqual(map.set(a, undefined), map);
assert.strictEqual(map.has(a), true);
assert.strictEqual(map.delete(a), true);
assert.strictEqual(map.delete(a), false);
assert.strictEqual(map.has(a), false);
});
QUnit.test('that .toString works as expected', function (assert) {
var map = new _emberMetal.WeakMap();
assert.strictEqual(map.toString(), '[object WeakMap]');
});
});
enifed('ember-routing/tests/ext/controller_test', ['ember-utils', 'internal-test-helpers', 'ember-runtime'], function (_emberUtils, _internalTestHelpers, _emberRuntime) {
'use strict';
QUnit.module('ember-routing/ext/controller');
QUnit.test('transitionToRoute considers an engine\'s mountPoint', function () {
expect(4);
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var controller = _emberRuntime.Controller.create({ target: {
transitionTo: function (route) {
return route;
}
} });
(0, _emberUtils.setOwner)(controller, engineInstance);
strictEqual(controller.transitionToRoute('application'), 'foo.bar.application', 'properly prefixes application route');
strictEqual(controller.transitionToRoute('posts'), 'foo.bar.posts', 'properly prefixes child routes');
throws(function () {
return controller.transitionToRoute('/posts');
}, 'throws when trying to use a url');
var queryParams = {};
strictEqual(controller.transitionToRoute(queryParams), queryParams, 'passes query param only transitions through');
});
});
enifed('ember-routing/tests/location/auto_location_test', ['ember-utils', 'ember-environment', 'ember-metal', 'ember-routing/location/auto_location', 'ember-routing/location/history_location', 'ember-routing/location/hash_location', 'ember-routing/location/none_location', 'internal-test-helpers'], function (_emberUtils, _emberEnvironment, _emberMetal, _auto_location, _history_location, _hash_location, _none_location, _internalTestHelpers) {
'use strict';
function mockBrowserLocation(overrides) {
return (0, _emberUtils.assign)({
href: 'http://test.com/',
pathname: '/',
hash: '',
search: '',
replace: function () {
ok(false, 'location.replace should not be called during testing');
}
}, overrides);
}
function mockBrowserHistory(overrides) {
return (0, _emberUtils.assign)({
pushState: function () {
ok(false, 'history.pushState should not be called during testing');
},
replaceState: function () {
ok(false, 'history.replaceState should not be called during testing');
}
}, overrides);
}
function createLocation(location, history) {
var _AutoLocation$create;
var owner = (0, _internalTestHelpers.buildOwner)();
owner.register('location:history', _history_location.default);
owner.register('location:hash', _hash_location.default);
owner.register('location:none', _none_location.default);
var autolocation = _auto_location.default.create((_AutoLocation$create = {}, _AutoLocation$create[_emberUtils.OWNER] = owner, _AutoLocation$create.location = location, _AutoLocation$create.history = history, _AutoLocation$create.global = {}, _AutoLocation$create));
return autolocation;
}
var location = void 0;
QUnit.module('Ember.AutoLocation', {
teardown: function () {
if (location) {
(0, _emberMetal.run)(location, 'destroy');
}
}
});
QUnit.test('AutoLocation should have the `global`', function (assert) {
var location = _auto_location.default.create();
assert.ok(location.global, 'has a global defined');
assert.strictEqual(location.global, _emberEnvironment.environment.window, 'has the environments window global');
});
QUnit.test('AutoLocation should return concrete implementation\'s value for `getURL`', function () {
expect(1);
var browserLocation = mockBrowserLocation();
var browserHistory = mockBrowserHistory();
location = createLocation(browserLocation, browserHistory);
location.detect();
var concreteImplementation = (0, _emberMetal.get)(location, 'concreteImplementation');
concreteImplementation.getURL = function () {
return '/lincoln/park';
};
equal(location.getURL(), '/lincoln/park');
});
QUnit.test('AutoLocation should use a HistoryLocation instance when pushStates is supported', function () {
expect(1);
var browserLocation = mockBrowserLocation();
var browserHistory = mockBrowserHistory();
location = createLocation(browserLocation, browserHistory);
location.detect();
ok((0, _emberMetal.get)(location, 'concreteImplementation') instanceof _history_location.default);
});
QUnit.test('AutoLocation should use a HashLocation instance when pushStates are not supported, but hashchange events are and the URL is already in the HashLocation format', function () {
expect(1);
var browserLocation = mockBrowserLocation({
hash: '#/testd'
});
location = createLocation(browserLocation);
location.global = {
onhashchange: function () {}
};
location.detect();
ok((0, _emberMetal.get)(location, 'concreteImplementation') instanceof _hash_location.default);
});
QUnit.test('AutoLocation should use a NoneLocation instance when neither history nor hashchange are supported.', function () {
expect(1);
location = createLocation(mockBrowserLocation());
location.detect();
ok((0, _emberMetal.get)(location, 'concreteImplementation') instanceof _none_location.default);
});
QUnit.test('AutoLocation should use an index path (i.e. \'/\') without any location.hash as OK for HashLocation', function () {
expect(1);
var browserLocation = mockBrowserLocation({
href: 'http://test.com/',
pathname: '/',
hash: '',
search: '',
replace: function () {
ok(false, 'location.replace should not be called');
}
});
location = createLocation(browserLocation);
location.global = {
onhashchange: function () {}
};
location.detect();
ok((0, _emberMetal.get)(location, 'concreteImplementation') instanceof _hash_location.default, 'uses a HashLocation');
});
QUnit.test('AutoLocation should transform the URL for hashchange-only browsers viewing a HistoryLocation-formatted path', function () {
expect(3);
var browserLocation = mockBrowserLocation({
hash: '',
hostname: 'test.com',
href: 'http://test.com/test',
pathname: '/test',
protocol: 'http:',
port: '',
search: '',
replace: function (path) {
equal(path, 'http://test.com/#/test', 'location.replace should be called with normalized HashLocation path');
}
});
var location = createLocation(browserLocation);
location.global = {
onhashchange: function () {}
};
location.detect();
ok((0, _emberMetal.get)(location, 'concreteImplementation') instanceof _none_location.default, 'NoneLocation should be used while we attempt to location.replace()');
equal((0, _emberMetal.get)(location, 'cancelRouterSetup'), true, 'cancelRouterSetup should be set so the router knows.');
});
QUnit.test('AutoLocation should replace the URL for pushState-supported browsers viewing a HashLocation-formatted url', function () {
expect(2);
var browserLocation = mockBrowserLocation({
hash: '#/test',
hostname: 'test.com',
href: 'http://test.com/#/test',
pathname: '/',
protocol: 'http:',
port: '',
search: ''
});
var browserHistory = mockBrowserHistory({
replaceState: function (state, title, path) {
equal(path, '/test', 'history.replaceState should be called with normalized HistoryLocation url');
}
});
var location = createLocation(browserLocation, browserHistory);
location.detect();
ok((0, _emberMetal.get)(location, 'concreteImplementation'), _history_location.default);
});
QUnit.test('AutoLocation requires any rootURL given to end in a trailing forward slash', function () {
expect(3);
var browserLocation = mockBrowserLocation();
var expectedMsg = /rootURL must end with a trailing forward slash e.g. "\/app\/"/;
location = createLocation(browserLocation);
location.rootURL = 'app';
expectAssertion(function () {
location.detect();
}, expectedMsg);
location.rootURL = '/app';
expectAssertion(function () {
location.detect();
}, expectedMsg);
// Note the trailing whitespace
location.rootURL = '/app/ ';
expectAssertion(function () {
location.detect();
}, expectedMsg);
});
QUnit.test('AutoLocation provides its rootURL to the concreteImplementation', function () {
expect(1);
var browserLocation = mockBrowserLocation({
pathname: '/some/subdir/derp'
});
var browserHistory = mockBrowserHistory();
location = createLocation(browserLocation, browserHistory);
location.rootURL = '/some/subdir/';
location.detect();
var concreteLocation = (0, _emberMetal.get)(location, 'concreteImplementation');
equal(location.rootURL, concreteLocation.rootURL);
});
QUnit.test('getHistoryPath() should return a normalized, HistoryLocation-supported path', function () {
expect(3);
var browserLocation = mockBrowserLocation({
href: 'http://test.com/app/about?foo=bar#foo',
pathname: '/app/about',
search: '?foo=bar',
hash: '#foo'
});
equal((0, _auto_location.getHistoryPath)('/app/', browserLocation), '/app/about?foo=bar#foo', 'URLs already in HistoryLocation form should come out the same');
browserLocation = mockBrowserLocation({
href: 'http://test.com/app/#/about?foo=bar#foo',
pathname: '/app/',
search: '',
hash: '#/about?foo=bar#foo'
});
equal((0, _auto_location.getHistoryPath)('/app/', browserLocation), '/app/about?foo=bar#foo', 'HashLocation formed URLs should be normalized');
browserLocation = mockBrowserLocation({
href: 'http://test.com/app/#about?foo=bar#foo',
pathname: '/app/',
search: '',
hash: '#about?foo=bar#foo'
});
equal((0, _auto_location.getHistoryPath)('/app', browserLocation), '/app/#about?foo=bar#foo', 'URLs with a hash not following #/ convention shouldn\'t be normalized as a route');
});
QUnit.test('getHashPath() should return a normalized, HashLocation-supported path', function () {
expect(3);
var browserLocation = mockBrowserLocation({
href: 'http://test.com/app/#/about?foo=bar#foo',
pathname: '/app/',
search: '',
hash: '#/about?foo=bar#foo'
});
equal((0, _auto_location.getHashPath)('/app/', browserLocation), '/app/#/about?foo=bar#foo', 'URLs already in HistoryLocation form should come out the same');
browserLocation = mockBrowserLocation({
href: 'http://test.com/app/about?foo=bar#foo',
pathname: '/app/about',
search: '?foo=bar',
hash: '#foo'
});
equal((0, _auto_location.getHashPath)('/app/', browserLocation), '/app/#/about?foo=bar#foo', 'HistoryLocation formed URLs should be normalized');
browserLocation = mockBrowserLocation({
href: 'http://test.com/app/#about?foo=bar#foo',
pathname: '/app/',
search: '',
hash: '#about?foo=bar#foo'
});
equal((0, _auto_location.getHashPath)('/app/', browserLocation), '/app/#/#about?foo=bar#foo', 'URLs with a hash not following #/ convention shouldn\'t be normalized as a route');
});
});
enifed('ember-routing/tests/location/hash_location_test', ['ember-metal', 'ember-routing/location/hash_location'], function (_emberMetal, _hash_location) {
'use strict';
var HashTestLocation = void 0,
location = void 0;
function createLocation(options) {
if (!options) {
options = {};
}
location = HashTestLocation.create(options);
}
function mockBrowserLocation(path) {
// This is a neat trick to auto-magically extract the hostname from any
// url by letting the browser do the work ;)
var tmp = document.createElement('a');
tmp.href = path;
var protocol = !tmp.protocol || tmp.protocol === ':' ? 'http' : tmp.protocol;
var pathname = tmp.pathname.match(/^\//) ? tmp.pathname : '/' + tmp.pathname;
return {
hash: tmp.hash,
host: tmp.host || 'localhost',
hostname: tmp.hostname || 'localhost',
href: tmp.href,
pathname: pathname,
port: tmp.port || '',
protocol: protocol,
search: tmp.search
};
}
function triggerHashchange() {
var event = document.createEvent('HTMLEvents');
event.initEvent('hashchange', true, false);
window.dispatchEvent(event);
}
QUnit.module('Ember.HashLocation', {
setup: function () {
HashTestLocation = _hash_location.default.extend({
_location: {
href: 'http://test.com/',
pathname: '/',
hash: '',
search: '',
replace: function () {
ok(false, 'location.replace should not be called during testing');
}
}
});
},
teardown: function () {
(0, _emberMetal.run)(function () {
if (location) {
location.destroy();
}
});
}
});
QUnit.test('HashLocation.getURL() returns the current url', function () {
expect(1);
createLocation({
_location: mockBrowserLocation('/#/foo/bar')
});
equal(location.getURL(), '/foo/bar');
});
QUnit.test('HashLocation.getURL() includes extra hashes', function () {
expect(1);
createLocation({
_location: mockBrowserLocation('/#/foo#bar#car')
});
equal(location.getURL(), '/foo#bar#car');
});
QUnit.test('HashLocation.getURL() assumes location.hash without #/ prefix is not a route path', function () {
expect(1);
createLocation({
_location: mockBrowserLocation('/#foo#bar')
});
equal(location.getURL(), '/#foo#bar');
});
QUnit.test('HashLocation.getURL() returns a normal forward slash when there is no location.hash', function () {
expect(1);
createLocation({
_location: mockBrowserLocation('/')
});
equal(location.getURL(), '/');
});
QUnit.test('HashLocation.setURL() correctly sets the url', function () {
expect(2);
createLocation();
location.setURL('/bar');
equal((0, _emberMetal.get)(location, 'location.hash'), '/bar');
equal((0, _emberMetal.get)(location, 'lastSetURL'), '/bar');
});
QUnit.test('HashLocation.replaceURL() correctly replaces to the path with a page reload', function () {
expect(2);
createLocation({
_location: {
replace: function (path) {
equal(path, '#/foo');
}
}
});
location.replaceURL('/foo');
equal((0, _emberMetal.get)(location, 'lastSetURL'), '/foo');
});
QUnit.test('HashLocation.onUpdateURL callback executes as expected', function () {
expect(1);
createLocation({
_location: mockBrowserLocation('/#/foo/bar')
});
location.onUpdateURL(function (param) {
equal(param, '/foo/bar', 'path is passed as param');
});
triggerHashchange();
});
QUnit.test('HashLocation.onUpdateURL doesn\'t execute callback if lastSetURL === path', function () {
expect(0);
createLocation({
_location: {
href: '/#/foo/bar'
},
lastSetURL: '/foo/bar'
});
location.onUpdateURL(function () {
ok(false, 'callback should not be called');
});
triggerHashchange();
});
QUnit.test('HashLocation.formatURL() prepends a # to the provided string', function () {
expect(1);
createLocation();
equal(location.formatURL('/foo#bar'), '#/foo#bar');
});
QUnit.test('HashLocation.willDestroy() cleans up hashchange event listener', function () {
expect(1);
createLocation();
location.onUpdateURL(function () {
ok(true, 'should invoke callback once');
});
triggerHashchange();
(0, _emberMetal.run)(location, 'destroy');
location = null;
triggerHashchange();
});
});
enifed('ember-routing/tests/location/history_location_test', ['ember-metal', 'ember-routing/location/history_location'], function (_emberMetal, _history_location) {
'use strict';
var FakeHistory = void 0,
HistoryTestLocation = void 0,
location = void 0;
function createLocation(options) {
if (!options) {
options = {};
}
location = HistoryTestLocation.create(options);
}
function mockBrowserLocation(path) {
// This is a neat trick to auto-magically extract the hostname from any
// url by letting the browser do the work ;)
var tmp = document.createElement('a');
tmp.href = path;
var protocol = !tmp.protocol || tmp.protocol === ':' ? 'http' : tmp.protocol;
var pathname = tmp.pathname.match(/^\//) ? tmp.pathname : '/' + tmp.pathname;
return {
hash: tmp.hash,
host: tmp.host || 'localhost',
hostname: tmp.hostname || 'localhost',
href: tmp.href,
pathname: pathname,
port: tmp.port || '',
protocol: protocol,
search: tmp.search
};
}
QUnit.module('Ember.HistoryLocation', {
setup: function () {
FakeHistory = {
state: null,
_states: [],
replaceState: function (state) {
this.state = state;
this._states[0] = state;
},
pushState: function (state) {
this.state = state;
this._states.unshift(state);
}
};
HistoryTestLocation = _history_location.default.extend({
history: FakeHistory
});
},
teardown: function () {
(0, _emberMetal.run)(function () {
if (location) {
location.destroy();
}
});
}
});
QUnit.test('HistoryLocation initState does not get fired on init', function () {
expect(1);
HistoryTestLocation.reopen({
init: function () {
ok(true, 'init was called');
this._super.apply(this, arguments);
},
initState: function () {
ok(false, 'initState() should not be called automatically');
}
});
createLocation();
});
QUnit.test('webkit doesn\'t fire popstate on page load', function () {
expect(1);
HistoryTestLocation.reopen({
initState: function () {
this._super.apply(this, arguments);
// these two should be equal to be able
// to successfully detect webkit initial popstate
equal(this._previousURL, this.getURL());
}
});
createLocation();
location.initState();
});
QUnit.test('base URL is removed when retrieving the current pathname', function () {
expect(1);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'location', mockBrowserLocation('/base/foo/bar'));
(0, _emberMetal.set)(this, 'baseURL', '/base/');
},
initState: function () {
this._super.apply(this, arguments);
equal(this.getURL(), '/foo/bar');
}
});
createLocation();
location.initState();
});
QUnit.test('base URL is preserved when moving around', function () {
expect(2);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'location', mockBrowserLocation('/base/foo/bar'));
(0, _emberMetal.set)(this, 'baseURL', '/base/');
}
});
createLocation();
location.initState();
location.setURL('/one/two');
equal(location._historyState.path, '/base/one/two');
ok(location._historyState.uuid);
});
QUnit.test('setURL continues to set even with a null state (iframes may set this)', function () {
expect(2);
createLocation();
location.initState();
FakeHistory.pushState(null);
location.setURL('/three/four');
equal(location._historyState.path, '/three/four');
ok(location._historyState.uuid);
});
QUnit.test('replaceURL continues to set even with a null state (iframes may set this)', function () {
expect(2);
createLocation();
location.initState();
FakeHistory.pushState(null);
location.replaceURL('/three/four');
equal(location._historyState.path, '/three/four');
ok(location._historyState.uuid);
});
QUnit.test('HistoryLocation.getURL() returns the current url, excluding both rootURL and baseURL', function () {
expect(1);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'location', mockBrowserLocation('/base/foo/bar'));
(0, _emberMetal.set)(this, 'rootURL', '/app/');
(0, _emberMetal.set)(this, 'baseURL', '/base/');
}
});
createLocation();
equal(location.getURL(), '/foo/bar');
});
QUnit.test('HistoryLocation.getURL() returns the current url, does not remove rootURL if its not at start of url', function () {
expect(1);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'location', mockBrowserLocation('/foo/bar/baz'));
(0, _emberMetal.set)(this, 'rootURL', '/bar/');
}
});
createLocation();
equal(location.getURL(), '/foo/bar/baz');
});
QUnit.test('HistoryLocation.getURL() will not remove the rootURL when only a partial match', function () {
expect(1);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'location', mockBrowserLocation('/bars/baz'));
(0, _emberMetal.set)(this, 'rootURL', '/bar/');
}
});
createLocation();
equal(location.getURL(), '/bars/baz');
});
QUnit.test('HistoryLocation.getURL() returns the current url, does not remove baseURL if its not at start of url', function () {
expect(1);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'location', mockBrowserLocation('/foo/bar/baz'));
(0, _emberMetal.set)(this, 'baseURL', '/bar/');
}
});
createLocation();
equal(location.getURL(), '/foo/bar/baz');
});
QUnit.test('HistoryLocation.getURL() will not remove the baseURL when only a partial match', function () {
expect(1);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'location', mockBrowserLocation('/bars/baz'));
(0, _emberMetal.set)(this, 'baseURL', '/bar/');
}
});
createLocation();
equal(location.getURL(), '/bars/baz');
});
QUnit.test('HistoryLocation.getURL() includes location.search', function () {
expect(1);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'location', mockBrowserLocation('/foo/bar?time=morphin'));
}
});
createLocation();
equal(location.getURL(), '/foo/bar?time=morphin');
});
QUnit.test('HistoryLocation.getURL() includes location.hash', function () {
expect(1);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'location', mockBrowserLocation('/foo/bar#pink-power-ranger'));
}
});
createLocation();
equal(location.getURL(), '/foo/bar#pink-power-ranger');
});
QUnit.test('HistoryLocation.getURL() includes location.hash and location.search', function () {
expect(1);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'location', mockBrowserLocation('/foo/bar?time=morphin#pink-power-ranger'));
}
});
createLocation();
equal(location.getURL(), '/foo/bar?time=morphin#pink-power-ranger');
});
QUnit.test('HistoryLocation.getURL() drops duplicate slashes', function () {
expect(1);
HistoryTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
var location = mockBrowserLocation('//');
location.pathname = '//'; // mockBrowserLocation does not allow for `//`, so force it
(0, _emberMetal.set)(this, 'location', location);
}
});
createLocation();
equal(location.getURL(), '/');
});
});
enifed('ember-routing/tests/location/none_location_test', ['ember-metal', 'ember-routing/location/none_location'], function (_emberMetal, _none_location) {
'use strict';
var NoneTestLocation = void 0,
location = void 0;
function createLocation(options) {
if (!options) {
options = {};
}
location = NoneTestLocation.create(options);
}
QUnit.module('Ember.NoneLocation', {
setup: function () {
NoneTestLocation = _none_location.default.extend({});
},
teardown: function () {
(0, _emberMetal.run)(function () {
if (location) {
location.destroy();
}
});
}
});
QUnit.test('NoneLocation.formatURL() returns the current url always appending rootURL', function () {
expect(1);
NoneTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'rootURL', '/en/');
}
});
createLocation();
equal(location.formatURL('/foo/bar'), '/en/foo/bar');
});
QUnit.test('NoneLocation.getURL() returns the current path minus rootURL', function () {
expect(1);
NoneTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'rootURL', '/foo/');
(0, _emberMetal.set)(this, 'path', '/foo/bar');
}
});
createLocation();
equal(location.getURL(), '/bar');
});
QUnit.test('NoneLocation.getURL() will remove the rootURL only from the beginning of a url', function () {
expect(1);
NoneTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'rootURL', '/bar/');
(0, _emberMetal.set)(this, 'path', '/foo/bar/baz');
}
});
createLocation();
equal(location.getURL(), '/foo/bar/baz');
});
QUnit.test('NoneLocation.getURL() will not remove the rootURL when only a partial match', function () {
expect(1);
NoneTestLocation.reopen({
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'rootURL', '/bar/');
(0, _emberMetal.set)(this, 'path', '/bars/baz');
}
});
createLocation();
equal(location.getURL(), '/bars/baz');
});
});
enifed('ember-routing/tests/location/util_test', ['ember-utils', 'ember-routing/location/util'], function (_emberUtils, _util) {
'use strict';
function mockBrowserLocation(overrides) {
return (0, _emberUtils.assign)({
href: 'http://test.com/',
pathname: '/',
hash: '',
search: '',
replace: function () {
ok(false, 'location.replace should not be called during testing');
}
}, overrides);
}
QUnit.module('Location Utilities');
QUnit.test('replacePath cannot be used to redirect to a different origin', function () {
expect(1);
var expectedURL = void 0;
expectedURL = 'http://emberjs.com:1337//google.com';
(0, _util.replacePath)({
protocol: 'http:',
hostname: 'emberjs.com',
port: '1337',
replace: function (url) {
equal(url, expectedURL);
}
}, '//google.com');
});
QUnit.test('getPath() should normalize location.pathname, making sure it always returns a leading slash', function () {
expect(2);
var location = mockBrowserLocation({ pathname: 'test' });
equal((0, _util.getPath)(location), '/test', 'When there is no leading slash, one is added.');
location = mockBrowserLocation({ pathname: '/test' });
equal((0, _util.getPath)(location), '/test', 'When a leading slash is already there, it isn\'t added again');
});
QUnit.test('getQuery() should return location.search as-is', function () {
expect(1);
var location = mockBrowserLocation({ search: '?foo=bar' });
equal((0, _util.getQuery)(location), '?foo=bar');
});
QUnit.test('getFullPath() should return full pathname including query and hash', function () {
expect(1);
var location = mockBrowserLocation({
href: 'http://test.com/about?foo=bar#foo',
pathname: '/about',
search: '?foo=bar',
hash: '#foo'
});
equal((0, _util.getFullPath)(location), '/about?foo=bar#foo');
});
QUnit.test('Feature-Detecting onhashchange', function () {
equal((0, _util.supportsHashChange)(undefined, {
onhashchange: function () {}
}), true, 'When not in IE, use onhashchange existence as evidence of the feature');
equal((0, _util.supportsHashChange)(undefined, {}), false, 'When not in IE, use onhashchange absence as evidence of the feature absence');
equal((0, _util.supportsHashChange)(7, {
onhashchange: function () {}
}), false, 'When in IE7 compatibility mode, never report existence of the feature');
equal((0, _util.supportsHashChange)(8, {
onhashchange: function () {}
}), true, 'When in IE8+, use onhashchange existence as evidence of the feature');
});
// jscs:disable
QUnit.test("Feature-detecting the history API", function () {
equal((0, _util.supportsHistory)("", { pushState: true }), true, "returns true if not Android Gingerbread and history.pushState exists");
equal((0, _util.supportsHistory)("", {}), false, "returns false if history.pushState doesn't exist");
equal((0, _util.supportsHistory)("", undefined), false, "returns false if history doesn't exist");
equal((0, _util.supportsHistory)("Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", { pushState: true }), false, "returns false if Android 2.x stock browser (not Chrome) claiming to support pushState");
equal((0, _util.supportsHistory)("Mozilla/5.0 (Linux; U; Android 4.0.3; nl-nl; GT-N7000 Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", { pushState: true }), false, "returns false for Android 4.0.x stock browser (not Chrome) claiming to support pushState");
equal((0, _util.supportsHistory)("Mozilla/5.0 (Linux; U; Android 20.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", { pushState: true }), true, "returns true if Android version begins with 2, but is greater than 2");
equal((0, _util.supportsHistory)("Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19", { pushState: true }), true, "returns true for Chrome (not stock browser) on Android 4.0.x");
// Windows Phone UA and History API: https://github.com/Modernizr/Modernizr/issues/1471
equal((0, _util.supportsHistory)("Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Virtual) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537", { pushState: true }), true, "returns true for Windows Phone 8.1 with misleading user agent string");
});
// jscs:enable
});
enifed('ember-routing/tests/system/cache_test', ['ember-routing/system/cache'], function (_cache) {
'use strict';
QUnit.module('BucketCache', {
setup: function () {
this.cache = _cache.default.create();
}
});
QUnit.test('has - returns false when bucket is not in cache', function (assert) {
assert.strictEqual(this.cache.has('foo'), false);
assert.strictEqual(this.cache.has('constructor'), false);
});
QUnit.test('has - returns true when bucket is in cache', function (assert) {
var token = {};
this.cache.stash('foo', 'bar', token);
this.cache.stash('constructor', 'bar', token);
assert.strictEqual(this.cache.has('foo'), true);
assert.strictEqual(this.cache.has('constructor'), true);
});
QUnit.test('lookup - returns stashed value if key does exist in bucket', function (assert) {
var token = {};
this.cache.stash('foo', 'bar', token);
assert.strictEqual(this.cache.lookup('foo', 'bar', {}), token);
});
QUnit.test('lookup - returns default value if key does not exist in bucket', function (assert) {
var defaultValue = {};
this.cache.stash('foo', 'bar', {});
assert.strictEqual(this.cache.lookup('foo', 'boo', defaultValue), defaultValue);
assert.strictEqual(this.cache.lookup('foo', 'constructor', defaultValue), defaultValue);
});
QUnit.test('lookup - returns default value if bucket does not exist', function (assert) {
var defaultValue = {};
assert.strictEqual(this.cache.lookup('boo', 'bar', defaultValue), defaultValue);
assert.strictEqual(this.cache.lookup('constructor', 'bar', defaultValue), defaultValue);
});
});
enifed('ember-routing/tests/system/controller_for_test', ['ember-babel', 'ember-runtime', 'ember-routing/system/controller_for', 'ember-routing/system/generate_controller', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _controller_for, _generate_controller, _internalTestHelpers) {
'use strict';
(0, _internalTestHelpers.moduleFor)('Ember.controllerFor', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test controllerFor should lookup for registered controllers'] = function (assert) {
var _this2 = this;
this.add('controller:app', _emberRuntime.Controller.extend());
return this.visit('/').then(function () {
var appInstance = _this2.applicationInstance;
var appController = appInstance.lookup('controller:app');
var controller = (0, _controller_for.default)(appInstance, 'app');
assert.equal(appController, controller, 'should find app controller');
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
(0, _internalTestHelpers.moduleFor)('Ember.generateController', function (_ApplicationTestCase2) {
(0, _emberBabel.inherits)(_class2, _ApplicationTestCase2);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase2.apply(this, arguments));
}
_class2.prototype['@test generateController should return Ember.Controller'] = function (assert) {
var _this4 = this;
return this.visit('/').then(function () {
var controller = (0, _generate_controller.default)(_this4.applicationInstance, 'home');
assert.ok(controller instanceof _emberRuntime.Controller, 'should return controller');
});
};
_class2.prototype['@test generateController should return controller:basic if resolved'] = function (assert) {
var _this5 = this;
var BasicController = _emberRuntime.Controller.extend();
this.add('controller:basic', BasicController);
return this.visit('/').then(function () {
var controller = (0, _generate_controller.default)(_this5.applicationInstance, 'home');
assert.ok(controller instanceof BasicController, 'should return controller');
});
};
_class2.prototype['@test generateController should return controller:basic if registered'] = function (assert) {
var _this6 = this;
var BasicController = _emberRuntime.Controller.extend();
this.application.register('controller:basic', BasicController);
return this.visit('/').then(function () {
var controller = (0, _generate_controller.default)(_this6.applicationInstance, 'home');
assert.ok(controller instanceof BasicController, 'should return base class of controller');
});
};
return _class2;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed('ember-routing/tests/system/dsl_test', ['ember-utils', 'ember-routing/system/router', 'internal-test-helpers'], function (_emberUtils, _router, _internalTestHelpers) {
'use strict';
var Router = void 0;
function setup() {
Router = _router.default.extend();
}
function teardown() {
Router = null;
}
QUnit.module('Ember Router DSL', {
setup: setup,
teardown: teardown
});
QUnit.test('should fail when using a reserved route name', function () {
expectDeprecation('this.resource() is deprecated. Use this.route(\'name\', { resetNamespace: true }, function () {}) instead.');
var reservedNames = ['array', 'basic', 'object', 'application'];
expect(reservedNames.length * 2 + 1);
reservedNames.forEach(function (reservedName) {
expectAssertion(function () {
Router = _router.default.extend();
Router.map(function () {
this.route(reservedName);
});
var router = Router.create();
router._initRouterJs();
}, '\'' + reservedName + '\' cannot be used as a route name.');
expectAssertion(function () {
Router = _router.default.extend();
Router.map(function () {
this.resource(reservedName);
});
var router = Router.create();
router._initRouterJs();
}, '\'' + reservedName + '\' cannot be used as a route name.');
});
});
QUnit.test('should reset namespace if nested with resource', function () {
expectDeprecation('this.resource() is deprecated. Use this.route(\'name\', { resetNamespace: true }, function () {}) instead.');
Router = Router.map(function () {
this.resource('bleep', function () {
this.resource('bloop', function () {
this.resource('blork');
});
});
});
var router = Router.create();
router._initRouterJs();
ok(router._routerMicrolib.recognizer.names['bleep'], 'nested resources do not contain parent name');
ok(router._routerMicrolib.recognizer.names['bloop'], 'nested resources do not contain parent name');
ok(router._routerMicrolib.recognizer.names['blork'], 'nested resources do not contain parent name');
});
QUnit.test('should retain resource namespace if nested with routes', function () {
Router = Router.map(function () {
this.route('bleep', function () {
this.route('bloop', function () {
this.route('blork');
});
});
});
var router = Router.create();
router._initRouterJs();
ok(router._routerMicrolib.recognizer.names['bleep'], 'parent name was used as base of nested routes');
ok(router._routerMicrolib.recognizer.names['bleep.bloop'], 'parent name was used as base of nested routes');
ok(router._routerMicrolib.recognizer.names['bleep.bloop.blork'], 'parent name was used as base of nested routes');
});
QUnit.test('should add loading and error routes if _isRouterMapResult is true', function () {
Router.map(function () {
this.route('blork');
});
var router = Router.create({
_hasModuleBasedResolver: function () {
return true;
}
});
router._initRouterJs();
ok(router._routerMicrolib.recognizer.names['blork'], 'main route was created');
ok(router._routerMicrolib.recognizer.names['blork_loading'], 'loading route was added');
ok(router._routerMicrolib.recognizer.names['blork_error'], 'error route was added');
});
QUnit.test('should not add loading and error routes if _isRouterMapResult is false', function () {
Router.map(function () {
this.route('blork');
});
var router = Router.create();
router._initRouterJs(false);
ok(router._routerMicrolib.recognizer.names['blork'], 'main route was created');
ok(!router._routerMicrolib.recognizer.names['blork_loading'], 'loading route was not added');
ok(!router._routerMicrolib.recognizer.names['blork_error'], 'error route was not added');
});
QUnit.test('should reset namespace of loading and error routes for routes with resetNamespace', function () {
Router.map(function () {
this.route('blork', function () {
this.route('blorp');
this.route('bleep', { resetNamespace: true });
});
});
var router = Router.create({
_hasModuleBasedResolver: function () {
return true;
}
});
router._initRouterJs();
ok(router._routerMicrolib.recognizer.names['blork.blorp'], 'nested route was created');
ok(router._routerMicrolib.recognizer.names['blork.blorp_loading'], 'nested loading route was added');
ok(router._routerMicrolib.recognizer.names['blork.blorp_error'], 'nested error route was added');
ok(router._routerMicrolib.recognizer.names['bleep'], 'reset route was created');
ok(router._routerMicrolib.recognizer.names['bleep_loading'], 'reset loading route was added');
ok(router._routerMicrolib.recognizer.names['bleep_error'], 'reset error route was added');
ok(!router._routerMicrolib.recognizer.names['blork.bleep'], 'nested reset route was not created');
ok(!router._routerMicrolib.recognizer.names['blork.bleep_loading'], 'nested reset loading route was not added');
ok(!router._routerMicrolib.recognizer.names['blork.bleep_error'], 'nested reset error route was not added');
});
QUnit.test('should throw an error when defining a route serializer outside an engine', function () {
Router.map(function () {
var _this = this;
throws(function () {
_this.route('posts', { serialize: function () {} });
}, /Defining a route serializer on route 'posts' outside an Engine is not allowed/);
});
Router.create()._initRouterJs();
});
QUnit.module('Ember Router DSL with engines', {
setup: setup,
teardown: teardown
});
QUnit.test('should allow mounting of engines', function (assert) {
assert.expect(3);
Router = Router.map(function () {
this.route('bleep', function () {
this.route('bloop', function () {
this.mount('chat');
});
});
});
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: { routable: true }
});
var router = Router.create();
(0, _emberUtils.setOwner)(router, engineInstance);
router._initRouterJs();
assert.ok(router._routerMicrolib.recognizer.names['bleep'], 'parent name was used as base of nested routes');
assert.ok(router._routerMicrolib.recognizer.names['bleep.bloop'], 'parent name was used as base of nested routes');
assert.ok(router._routerMicrolib.recognizer.names['bleep.bloop.chat'], 'parent name was used as base of mounted engine');
});
QUnit.test('should allow mounting of engines at a custom path', function (assert) {
assert.expect(1);
Router = Router.map(function () {
this.route('bleep', function () {
this.route('bloop', function () {
this.mount('chat', { path: 'custom-chat' });
});
});
});
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: { routable: true }
});
var router = Router.create();
(0, _emberUtils.setOwner)(router, engineInstance);
router._initRouterJs();
assert.deepEqual(router._routerMicrolib.recognizer.names['bleep.bloop.chat'].segments.slice(1, 4).map(function (s) {
return s.value;
}), ['bleep', 'bloop', 'custom-chat'], 'segments are properly associated with mounted engine');
});
QUnit.test('should allow aliasing of engine names with `as`', function (assert) {
assert.expect(1);
Router = Router.map(function () {
this.route('bleep', function () {
this.route('bloop', function () {
this.mount('chat', { as: 'blork' });
});
});
});
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: { routable: true }
});
var router = Router.create();
(0, _emberUtils.setOwner)(router, engineInstance);
router._initRouterJs();
assert.deepEqual(router._routerMicrolib.recognizer.names['bleep.bloop.blork'].segments.slice(1, 4).map(function (s) {
return s.value;
}), ['bleep', 'bloop', 'blork'], 'segments are properly associated with mounted engine with aliased name');
});
QUnit.test('should add loading and error routes to a mount if _isRouterMapResult is true', function () {
Router.map(function () {
this.mount('chat');
});
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: { routable: true }
});
var router = Router.create({
_hasModuleBasedResolver: function () {
return true;
}
});
(0, _emberUtils.setOwner)(router, engineInstance);
router._initRouterJs();
ok(router._routerMicrolib.recognizer.names['chat'], 'main route was created');
ok(router._routerMicrolib.recognizer.names['chat_loading'], 'loading route was added');
ok(router._routerMicrolib.recognizer.names['chat_error'], 'error route was added');
});
QUnit.test('should add loading and error routes to a mount alias if _isRouterMapResult is true', function () {
Router.map(function () {
this.mount('chat', { as: 'shoutbox' });
});
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: { routable: true }
});
var router = Router.create({
_hasModuleBasedResolver: function () {
return true;
}
});
(0, _emberUtils.setOwner)(router, engineInstance);
router._initRouterJs();
ok(router._routerMicrolib.recognizer.names['shoutbox'], 'main route was created');
ok(router._routerMicrolib.recognizer.names['shoutbox_loading'], 'loading route was added');
ok(router._routerMicrolib.recognizer.names['shoutbox_error'], 'error route was added');
});
QUnit.test('should not add loading and error routes to a mount if _isRouterMapResult is false', function () {
Router.map(function () {
this.mount('chat');
});
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: { routable: true }
});
var router = Router.create();
(0, _emberUtils.setOwner)(router, engineInstance);
router._initRouterJs(false);
ok(router._routerMicrolib.recognizer.names['chat'], 'main route was created');
ok(!router._routerMicrolib.recognizer.names['chat_loading'], 'loading route was not added');
ok(!router._routerMicrolib.recognizer.names['chat_error'], 'error route was not added');
});
QUnit.test('should reset namespace of loading and error routes for mounts with resetNamespace', function () {
Router.map(function () {
this.route('news', function () {
this.mount('chat');
this.mount('blog', { resetNamespace: true });
});
});
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: { routable: true }
});
var router = Router.create({
_hasModuleBasedResolver: function () {
return true;
}
});
(0, _emberUtils.setOwner)(router, engineInstance);
router._initRouterJs();
ok(router._routerMicrolib.recognizer.names['news.chat'], 'nested route was created');
ok(router._routerMicrolib.recognizer.names['news.chat_loading'], 'nested loading route was added');
ok(router._routerMicrolib.recognizer.names['news.chat_error'], 'nested error route was added');
ok(router._routerMicrolib.recognizer.names['blog'], 'reset route was created');
ok(router._routerMicrolib.recognizer.names['blog_loading'], 'reset loading route was added');
ok(router._routerMicrolib.recognizer.names['blog_error'], 'reset error route was added');
ok(!router._routerMicrolib.recognizer.names['news.blog'], 'nested reset route was not created');
ok(!router._routerMicrolib.recognizer.names['news.blog_loading'], 'nested reset loading route was not added');
ok(!router._routerMicrolib.recognizer.names['news.blog_error'], 'nested reset error route was not added');
});
});
enifed('ember-routing/tests/system/route_test', ['ember-utils', 'internal-test-helpers', 'ember-runtime', 'ember-routing/system/route'], function (_emberUtils, _internalTestHelpers, _emberRuntime, _route) {
'use strict';
var route = void 0,
routeOne = void 0,
routeTwo = void 0,
lookupHash = void 0;
function setup() {
route = _route.default.create();
}
function teardown() {
(0, _internalTestHelpers.runDestroy)(route);
}
QUnit.module('Ember.Route', {
setup: setup,
teardown: teardown
});
QUnit.test('default store utilizes the container to acquire the model factory', function () {
expect(4);
var Post = _emberRuntime.Object.extend();
var post = {};
Post.reopenClass({
find: function () {
return post;
}
});
(0, _emberUtils.setOwner)(route, (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
hasRegistration: function () {
return true;
},
factoryFor: function (fullName) {
equal(fullName, 'model:post', 'correct factory was looked up');
return {
class: Post,
create: function () {
return Post.create();
}
};
}
}
}));
route.set('_qp', null);
equal(route.model({ post_id: 1 }), post);
equal(route.findModel('post', 1), post, '#findModel returns the correct post');
});
QUnit.test('\'store\' can be injected by data persistence frameworks', function () {
expect(8);
(0, _internalTestHelpers.runDestroy)(route);
var owner = (0, _internalTestHelpers.buildOwner)();
var post = {
id: 1
};
var Store = _emberRuntime.Object.extend({
find: function (type, value) {
ok(true, 'injected model was called');
equal(type, 'post', 'correct type was called');
equal(value, 1, 'correct value was called');
return post;
}
});
owner.register('route:index', _route.default);
owner.register('store:main', Store);
owner.inject('route', 'store', 'store:main');
route = owner.lookup('route:index');
equal(route.model({ post_id: 1 }), post, '#model returns the correct post');
equal(route.findModel('post', 1), post, '#findModel returns the correct post');
});
QUnit.test('assert if \'store.find\' method is not found', function () {
expect(1);
(0, _internalTestHelpers.runDestroy)(route);
var owner = (0, _internalTestHelpers.buildOwner)();
var Post = _emberRuntime.Object.extend();
owner.register('route:index', _route.default);
owner.register('model:post', Post);
route = owner.lookup('route:index');
expectAssertion(function () {
route.findModel('post', 1);
}, 'Post has no method `find`.');
});
QUnit.test('asserts if model class is not found', function () {
expect(1);
(0, _internalTestHelpers.runDestroy)(route);
var owner = (0, _internalTestHelpers.buildOwner)();
owner.register('route:index', _route.default);
route = owner.lookup('route:index');
expectAssertion(function () {
route.model({ post_id: 1 });
}, /You used the dynamic segment post_id in your route undefined, but .Post did not exist and you did not override your route\'s `model` hook./);
});
QUnit.test('\'store\' does not need to be injected', function () {
expect(1);
(0, _internalTestHelpers.runDestroy)(route);
var owner = (0, _internalTestHelpers.buildOwner)();
owner.register('route:index', _route.default);
route = owner.lookup('route:index');
ignoreAssertion(function () {
route.model({ post_id: 1 });
});
ok(true, 'no error was raised');
});
QUnit.test('modelFor doesn\'t require the router', function () {
expect(1);
var owner = (0, _internalTestHelpers.buildOwner)();
(0, _emberUtils.setOwner)(route, owner);
var foo = { name: 'foo' };
var FooRoute = _route.default.extend({
currentModel: foo
});
owner.register('route:foo', FooRoute);
strictEqual(route.modelFor('foo'), foo);
});
QUnit.test('.send just calls an action if the router is absent', function () {
expect(7);
var route = _route.default.extend({
actions: {
returnsTrue: function (foo, bar) {
equal(foo, 1);
equal(bar, 2);
equal(this, route);
return true;
},
returnsFalse: function () {
ok(true, 'returnsFalse was called');
return false;
}
}
}).create();
equal(true, route.send('returnsTrue', 1, 2));
equal(false, route.send('returnsFalse'));
equal(undefined, route.send('nonexistent', 1, 2, 3));
});
QUnit.test('.send just calls an action if the routers internal router property is absent', function () {
expect(7);
var route = _route.default.extend({
router: {},
actions: {
returnsTrue: function (foo, bar) {
equal(foo, 1);
equal(bar, 2);
equal(this, route);
return true;
},
returnsFalse: function () {
ok(true, 'returnsFalse was called');
return false;
}
}
}).create();
equal(true, route.send('returnsTrue', 1, 2));
equal(false, route.send('returnsFalse'));
equal(undefined, route.send('nonexistent', 1, 2, 3));
});
QUnit.test('can access `actions` hash via `_actions` [DEPRECATED]', function () {
expect(2);
var route = _route.default.extend({
actions: {
foo: function () {
ok(true, 'called foo action');
}
}
}).create();
expectDeprecation(function () {
route._actions.foo();
}, 'Usage of `_actions` is deprecated, use `actions` instead.');
});
QUnit.test('actions in both `_actions` and `actions` results in an assertion', function () {
expectAssertion(function () {
_route.default.extend({
_actions: {},
actions: {}
}).create();
}, 'Specifying `_actions` and `actions` in the same mixin is not supported.');
});
QUnit.test('actions added via `_actions` can be used [DEPRECATED]', function () {
expect(3);
var route = void 0;
expectDeprecation(function () {
route = _route.default.extend({
_actions: {
bar: function () {
ok(true, 'called bar action');
}
}
}, {
actions: {
foo: function () {
ok(true, 'called foo action');
}
}
}).create();
}, 'Specifying actions in `_actions` is deprecated, please use `actions` instead.');
route.send('foo');
route.send('bar');
});
QUnit.module('Ember.Route serialize', {
setup: setup,
teardown: teardown
});
QUnit.test('returns the models properties if params does not include *_id', function () {
deepEqual(route.serialize({ id: 2, firstName: 'Ned', lastName: 'Ryerson' }, ['firstName', 'lastName']), { firstName: 'Ned', lastName: 'Ryerson' }, 'serialized correctly');
});
QUnit.test('returns model.id if params include *_id', function () {
deepEqual(route.serialize({ id: 2 }, ['post_id']), { post_id: 2 }, 'serialized correctly');
});
QUnit.test('returns checks for existence of model.post_id before trying model.id', function () {
deepEqual(route.serialize({ post_id: 3 }, ['post_id']), { post_id: 3 }, 'serialized correctly');
});
QUnit.test('returns undefined if model is not set', function () {
equal(route.serialize(undefined, ['post_id']), undefined, 'serialized correctly');
});
QUnit.module('Ember.Route interaction', {
setup: function () {
var owner = {
lookup: function (fullName) {
return lookupHash[fullName];
}
};
routeOne = _route.default.create({ routeName: 'one' });
routeTwo = _route.default.create({ routeName: 'two' });
(0, _emberUtils.setOwner)(routeOne, owner);
(0, _emberUtils.setOwner)(routeTwo, owner);
lookupHash = {
'route:one': routeOne,
'route:two': routeTwo
};
},
teardown: function () {
(0, _internalTestHelpers.runDestroy)(routeOne);
(0, _internalTestHelpers.runDestroy)(routeTwo);
}
});
QUnit.test('controllerFor uses route\'s controllerName if specified', function () {
var testController = {};
lookupHash['controller:test'] = testController;
routeOne.controllerName = 'test';
equal(routeTwo.controllerFor('one'), testController);
});
QUnit.module('Route injected properties');
QUnit.test('services can be injected into routes', function () {
var owner = (0, _internalTestHelpers.buildOwner)();
owner.register('route:application', _route.default.extend({
authService: _emberRuntime.inject.service('auth')
}));
owner.register('service:auth', _emberRuntime.Service.extend());
var appRoute = owner.lookup('route:application');
var authService = owner.lookup('service:auth');
equal(authService, appRoute.get('authService'), 'service.auth is injected');
});
QUnit.module('Ember.Route with engines');
QUnit.test('paramsFor considers an engine\'s mountPoint', function (assert) {
expect(2);
var router = {
_deserializeQueryParams: function () {},
_routerMicrolib: {
state: {
handlerInfos: [{ name: 'posts' }],
params: {
'foo.bar': { a: 'b' },
'foo.bar.posts': { c: 'd' }
}
}
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar',
lookup: function (name) {
if (name === 'route:posts') {
return postsRoute;
} else if (name === 'route:application') {
return applicationRoute;
}
}
}
});
var applicationRoute = _route.default.create({ router: router, routeName: 'application', fullRouteName: 'foo.bar' });
var postsRoute = _route.default.create({ router: router, routeName: 'posts', fullRouteName: 'foo.bar.posts' });
var route = _route.default.create({ router: router });
(0, _emberUtils.setOwner)(applicationRoute, engineInstance);
(0, _emberUtils.setOwner)(postsRoute, engineInstance);
(0, _emberUtils.setOwner)(route, engineInstance);
assert.deepEqual(route.paramsFor('application'), { a: 'b' }, 'params match for root `application` route in engine');
assert.deepEqual(route.paramsFor('posts'), { c: 'd' }, 'params match for `posts` route in engine');
});
QUnit.test('modelFor considers an engine\'s mountPoint', function () {
expect(2);
var applicationModel = { id: '1' };
var postsModel = { id: '2' };
var router = {
_routerMicrolib: {
activeTransition: {
resolvedModels: {
'foo.bar': applicationModel,
'foo.bar.posts': postsModel
}
}
}
};
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar',
lookup: function (name) {
if (name === 'route:posts') {
return postsRoute;
} else if (name === 'route:application') {
return applicationRoute;
}
}
}
});
var applicationRoute = _route.default.create({ router: router, routeName: 'application' });
var postsRoute = _route.default.create({ router: router, routeName: 'posts' });
var route = _route.default.create({ router: router });
(0, _emberUtils.setOwner)(applicationRoute, engineInstance);
(0, _emberUtils.setOwner)(postsRoute, engineInstance);
(0, _emberUtils.setOwner)(route, engineInstance);
strictEqual(route.modelFor('application'), applicationModel);
strictEqual(route.modelFor('posts'), postsModel);
});
QUnit.test('transitionTo considers an engine\'s mountPoint', function () {
expect(4);
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var route = _route.default.create({ router: {
transitionTo: function (route) {
return route;
}
} });
(0, _emberUtils.setOwner)(route, engineInstance);
strictEqual(route.transitionTo('application'), 'foo.bar.application', 'properly prefixes application route');
strictEqual(route.transitionTo('posts'), 'foo.bar.posts', 'properly prefixes child routes');
throws(function () {
return route.transitionTo('/posts');
}, 'throws when trying to use a url');
var queryParams = {};
strictEqual(route.transitionTo(queryParams), queryParams, 'passes query param only transitions through');
});
QUnit.test('intermediateTransitionTo considers an engine\'s mountPoint', function () {
expect(4);
var lastRoute = void 0;
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var route = _route.default.create({ router: {
intermediateTransitionTo: function (route) {
lastRoute = route;
}
} });
(0, _emberUtils.setOwner)(route, engineInstance);
route.intermediateTransitionTo('application');
strictEqual(lastRoute, 'foo.bar.application', 'properly prefixes application route');
route.intermediateTransitionTo('posts');
strictEqual(lastRoute, 'foo.bar.posts', 'properly prefixes child routes');
throws(function () {
return route.intermediateTransitionTo('/posts');
}, 'throws when trying to use a url');
var queryParams = {};
route.intermediateTransitionTo(queryParams);
strictEqual(lastRoute, queryParams, 'passes query param only transitions through');
});
QUnit.test('replaceWith considers an engine\'s mountPoint', function () {
expect(4);
var engineInstance = (0, _internalTestHelpers.buildOwner)({
ownerOptions: {
routable: true,
mountPoint: 'foo.bar'
}
});
var route = _route.default.create({ router: {
replaceWith: function (route) {
return route;
}
} });
(0, _emberUtils.setOwner)(route, engineInstance);
strictEqual(route.replaceWith('application'), 'foo.bar.application', 'properly prefixes application route');
strictEqual(route.replaceWith('posts'), 'foo.bar.posts', 'properly prefixes child routes');
throws(function () {
return route.replaceWith('/posts');
}, 'throws when trying to use a url');
var queryParams = {};
strictEqual(route.replaceWith(queryParams), queryParams, 'passes query param only transitions through');
});
});
enifed('ember-routing/tests/system/router_test', ['ember-utils', 'ember-routing/location/hash_location', 'ember-routing/location/history_location', 'ember-routing/location/auto_location', 'ember-routing/location/none_location', 'ember-routing/system/router', 'internal-test-helpers'], function (_emberUtils, _hash_location, _history_location, _auto_location, _none_location, _router, _internalTestHelpers) {
'use strict';
var owner = void 0;
function createRouter(settings) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var CustomRouter = _router.default.extend();
var router = CustomRouter.create(settings);
if (!options.skipOwner) {
(0, _emberUtils.setOwner)(router, owner);
}
if (!options.disableSetup) {
router.setupRouter();
}
return router;
}
QUnit.module('Ember Router', {
setup: function () {
owner = (0, _internalTestHelpers.buildOwner)();
//register the HashLocation (the default)
owner.register('location:hash', _hash_location.default);
owner.register('location:history', _history_location.default);
owner.register('location:auto', _auto_location.default);
owner.register('location:none', _none_location.default);
},
teardown: function () {
(0, _internalTestHelpers.runDestroy)(owner);
owner = null;
}
});
QUnit.test('can create a router without an owner', function () {
createRouter(null, { disableSetup: true, skipOwner: true });
ok(true, 'no errors were thrown when creating without a container');
});
QUnit.test('should not create a router.js instance upon init', function () {
var router = createRouter(null, { disableSetup: true });
ok(!router._routerMicrolib);
});
QUnit.test('should not reify location until setupRouter is called', function () {
var router = createRouter(null, { disableSetup: true });
equal(typeof router.location, 'string', 'location is specified as a string');
router.setupRouter();
equal(typeof router.location, 'object', 'location is reified into an object');
});
QUnit.test('should destroy its location upon destroying the routers owner.', function () {
var router = createRouter();
var location = router.get('location');
(0, _internalTestHelpers.runDestroy)(owner);
ok(location.isDestroyed, 'location should be destroyed');
});
QUnit.test('should instantiate its location with its `rootURL`', function () {
var router = createRouter({
rootURL: '/rootdir/'
});
var location = router.get('location');
equal(location.get('rootURL'), '/rootdir/');
});
QUnit.test('replacePath should be called with the right path', function () {
expect(1);
var location = owner.lookup('location:auto');
location.location = {
href: 'http://test.com/rootdir/welcome',
origin: 'http://test.com',
pathname: '/rootdir/welcome',
hash: '',
search: '',
replace: function (url) {
equal(url, 'http://test.com/rootdir/#/welcome');
}
};
location.global = {
onhashchange: function () {}
};
location.history = null;
createRouter({
location: 'auto',
rootURL: '/rootdir/'
});
});
QUnit.test('Ember.Router._routePath should consume identical prefixes', function () {
createRouter();
expect(8);
function routePath() {
var handlerInfos = Array.prototype.slice.call(arguments).map(function (s) {
return { name: s };
});
handlerInfos.unshift({ name: 'ignored' });
return _router.default._routePath(handlerInfos);
}
equal(routePath('foo'), 'foo');
equal(routePath('foo', 'bar', 'baz'), 'foo.bar.baz');
equal(routePath('foo', 'foo.bar'), 'foo.bar');
equal(routePath('foo', 'foo.bar', 'foo.bar.baz'), 'foo.bar.baz');
equal(routePath('foo', 'foo.bar', 'foo.bar.baz.wow'), 'foo.bar.baz.wow');
equal(routePath('foo', 'foo.bar.baz.wow'), 'foo.bar.baz.wow');
equal(routePath('foo.bar', 'bar.baz.wow'), 'foo.bar.baz.wow');
// This makes no sense, not trying to handle it, just
// making sure it doesn't go boom.
equal(routePath('foo.bar.baz', 'foo'), 'foo.bar.baz.foo');
});
QUnit.test('Router should cancel routing setup when the Location class says so via cancelRouterSetup', function () {
expect(0);
var router = void 0;
owner.register('location:fake', {
cancelRouterSetup: true,
create: function () {
return this;
}
});
router = createRouter({
location: 'fake',
_setupRouter: function () {
ok(false, '_setupRouter should not be called');
}
});
router.startRouting();
});
QUnit.test('AutoLocation should replace the url when it\'s not in the preferred format', function () {
expect(1);
var location = owner.lookup('location:auto');
location.location = {
href: 'http://test.com/rootdir/welcome',
origin: 'http://test.com',
pathname: '/rootdir/welcome',
hash: '',
search: '',
replace: function (url) {
equal(url, 'http://test.com/rootdir/#/welcome');
}
};
location.history = null;
location.global = {
onhashchange: function () {}
};
createRouter({
location: 'auto',
rootURL: '/rootdir/'
});
});
QUnit.test('Router#handleURL should remove any #hashes before doing URL transition', function () {
expect(2);
var router = createRouter({
_doURLTransition: function (routerJsMethod, url) {
equal(routerJsMethod, 'handleURL');
equal(url, '/foo/bar?time=morphin');
}
});
router.handleURL('/foo/bar?time=morphin#pink-power-ranger');
});
QUnit.test('Router#triggerEvent allows actions to bubble when returning true', function (assert) {
assert.expect(2);
(0, _router.triggerEvent)([{
name: 'application',
handler: {
actions: {
loading: function () {
assert.ok(false, 'loading not handled by application route');
}
}
}
}, {
name: 'about',
handler: {
actions: {
loading: function () {
assert.ok(true, 'loading handled by about route');
return false;
}
}
}
}, {
name: 'about.me',
handler: {
actions: {
loading: function () {
assert.ok(true, 'loading handled by about.me route');
return true;
}
}
}
}], false, ['loading']);
});
QUnit.test('Router#triggerEvent ignores handlers that have not loaded yet', function (assert) {
assert.expect(1);
var handlerInfos = [{
name: 'about',
handler: {
actions: {
loading: function () {
assert.ok(true, 'loading handled by about route');
}
}
}
}, {
name: 'about.me',
handler: undefined
}];
(0, _router.triggerEvent)(handlerInfos, false, ['loading']);
});
QUnit.test('Router#router deprecates when called', function (assert) {
assert.expect(2);
var router = createRouter();
expectDeprecation(function () {
assert.equal(router.router, router._routerMicrolib);
}, 'Usage of `router` is deprecated, use `_routerMicrolib` instead.');
});
QUnit.test('Router#_routerMicrolib can be used without deprecation', function (assert) {
assert.expect(1);
var router = createRouter();
assert.ok(router._routerMicrolib, 'Router._routerMicrolib can be used without deprecation');
});
});
enifed('ember-routing/tests/utils_test', ['ember-routing/utils'], function (_utils) {
'use strict';
QUnit.module('Routing query parameter utils - normalizeControllerQueryParams');
QUnit.test('converts array style into verbose object style', function () {
var paramName = 'foo';
var normalized = (0, _utils.normalizeControllerQueryParams)([paramName]);
ok(normalized[paramName], 'turns the query param name into key');
equal(normalized[paramName].as, null, 'includes a blank alias in \'as\' key');
equal(normalized[paramName].scope, 'model', 'defaults scope to model');
});
QUnit.test('converts object style [{foo: \'an_alias\'}]', function () {
var paramName = 'foo';
var normalized = (0, _utils.normalizeControllerQueryParams)([{ 'foo': 'an_alias' }]);
ok(normalized[paramName], 'retains the query param name as key');
equal(normalized[paramName].as, 'an_alias', 'includes the provided alias in \'as\' key');
equal(normalized[paramName].scope, 'model', 'defaults scope to model');
});
QUnit.test('retains maximally verbose object style [{foo: {as: \'foo\'}}]', function () {
var paramName = 'foo';
var normalized = (0, _utils.normalizeControllerQueryParams)([{ 'foo': { as: 'an_alias' } }]);
ok(normalized[paramName], 'retains the query param name as key');
equal(normalized[paramName].as, 'an_alias', 'includes the provided alias in \'as\' key');
equal(normalized[paramName].scope, 'model', 'defaults scope to model');
});
});
enifed('ember-runtime/tests/computed/computed_macros_test', ['ember-metal', 'ember-runtime/computed/computed_macros', 'internal-test-helpers', 'ember-runtime/system/object', 'ember-runtime/system/native_array'], function (_emberMetal, _computed_macros, _internalTestHelpers, _object, _native_array) {
'use strict';
QUnit.module('CP macros');
(0, _internalTestHelpers.testBoth)('Ember.computed.empty', function (get, set) {
var obj = _object.default.extend({
bestLannister: null,
lannisters: null,
bestLannisterUnspecified: (0, _computed_macros.empty)('bestLannister'),
noLannistersKnown: (0, _computed_macros.empty)('lannisters')
}).create({
lannisters: (0, _native_array.A)()
});
equal(get(obj, 'bestLannisterUnspecified'), true, 'bestLannister initially empty');
equal(get(obj, 'noLannistersKnown'), true, 'lannisters initially empty');
get(obj, 'lannisters').pushObject('Tyrion');
set(obj, 'bestLannister', 'Tyrion');
equal(get(obj, 'bestLannisterUnspecified'), false, 'empty respects strings');
equal(get(obj, 'noLannistersKnown'), false, 'empty respects array mutations');
});
(0, _internalTestHelpers.testBoth)('Ember.computed.notEmpty', function (get, set) {
var obj = _object.default.extend({
bestLannister: null,
lannisters: null,
bestLannisterSpecified: (0, _computed_macros.notEmpty)('bestLannister'),
LannistersKnown: (0, _computed_macros.notEmpty)('lannisters')
}).create({
lannisters: (0, _native_array.A)()
});
equal(get(obj, 'bestLannisterSpecified'), false, 'bestLannister initially empty');
equal(get(obj, 'LannistersKnown'), false, 'lannisters initially empty');
get(obj, 'lannisters').pushObject('Tyrion');
set(obj, 'bestLannister', 'Tyrion');
equal(get(obj, 'bestLannisterSpecified'), true, 'empty respects strings');
equal(get(obj, 'LannistersKnown'), true, 'empty respects array mutations');
});
(0, _internalTestHelpers.testBoth)('computed.not', function (get) {
var obj = { foo: true };
(0, _emberMetal.defineProperty)(obj, 'notFoo', (0, _computed_macros.not)('foo'));
equal(get(obj, 'notFoo'), false);
obj = { foo: { bar: true } };
(0, _emberMetal.defineProperty)(obj, 'notFoo', (0, _computed_macros.not)('foo.bar'));
equal(get(obj, 'notFoo'), false);
});
(0, _internalTestHelpers.testBoth)('computed.empty', function (get, set) {
var obj = { foo: [], bar: undefined, baz: null, quz: '' };
(0, _emberMetal.defineProperty)(obj, 'fooEmpty', (0, _computed_macros.empty)('foo'));
(0, _emberMetal.defineProperty)(obj, 'barEmpty', (0, _computed_macros.empty)('bar'));
(0, _emberMetal.defineProperty)(obj, 'bazEmpty', (0, _computed_macros.empty)('baz'));
(0, _emberMetal.defineProperty)(obj, 'quzEmpty', (0, _computed_macros.empty)('quz'));
equal(get(obj, 'fooEmpty'), true);
set(obj, 'foo', [1]);
equal(get(obj, 'fooEmpty'), false);
equal(get(obj, 'barEmpty'), true);
equal(get(obj, 'bazEmpty'), true);
equal(get(obj, 'quzEmpty'), true);
set(obj, 'quz', 'asdf');
equal(get(obj, 'quzEmpty'), false);
});
(0, _internalTestHelpers.testBoth)('computed.bool', function (get) {
var obj = {
foo: function () {},
bar: 'asdf', baz: null, quz: false };
(0, _emberMetal.defineProperty)(obj, 'fooBool', (0, _computed_macros.bool)('foo'));
(0, _emberMetal.defineProperty)(obj, 'barBool', (0, _computed_macros.bool)('bar'));
(0, _emberMetal.defineProperty)(obj, 'bazBool', (0, _computed_macros.bool)('baz'));
(0, _emberMetal.defineProperty)(obj, 'quzBool', (0, _computed_macros.bool)('quz'));
equal(get(obj, 'fooBool'), true);
equal(get(obj, 'barBool'), true);
equal(get(obj, 'bazBool'), false);
equal(get(obj, 'quzBool'), false);
});
(0, _internalTestHelpers.testBoth)('computed.alias', function (get, set) {
var obj = { bar: 'asdf', baz: null, quz: false };
(0, _emberMetal.defineProperty)(obj, 'bay', (0, _emberMetal.computed)(function () {
return 'apple';
}));
(0, _emberMetal.defineProperty)(obj, 'barAlias', (0, _emberMetal.alias)('bar'));
(0, _emberMetal.defineProperty)(obj, 'bazAlias', (0, _emberMetal.alias)('baz'));
(0, _emberMetal.defineProperty)(obj, 'quzAlias', (0, _emberMetal.alias)('quz'));
(0, _emberMetal.defineProperty)(obj, 'bayAlias', (0, _emberMetal.alias)('bay'));
equal(get(obj, 'barAlias'), 'asdf');
equal(get(obj, 'bazAlias'), null);
equal(get(obj, 'quzAlias'), false);
equal(get(obj, 'bayAlias'), 'apple');
set(obj, 'barAlias', 'newBar');
set(obj, 'bazAlias', 'newBaz');
set(obj, 'quzAlias', null);
equal(get(obj, 'barAlias'), 'newBar');
equal(get(obj, 'bazAlias'), 'newBaz');
equal(get(obj, 'quzAlias'), null);
equal(get(obj, 'bar'), 'newBar');
equal(get(obj, 'baz'), 'newBaz');
equal(get(obj, 'quz'), null);
});
(0, _internalTestHelpers.testBoth)('computed.alias set', function (get, set) {
var obj = {};
var constantValue = 'always `a`';
(0, _emberMetal.defineProperty)(obj, 'original', (0, _emberMetal.computed)({
get: function () {
return constantValue;
},
set: function () {
return constantValue;
}
}));
(0, _emberMetal.defineProperty)(obj, 'aliased', (0, _emberMetal.alias)('original'));
equal(get(obj, 'original'), constantValue);
equal(get(obj, 'aliased'), constantValue);
set(obj, 'aliased', 'should not set to this value');
equal(get(obj, 'original'), constantValue);
equal(get(obj, 'aliased'), constantValue);
});
(0, _internalTestHelpers.testBoth)('computed.match', function (get, set) {
var obj = { name: 'Paul' };
(0, _emberMetal.defineProperty)(obj, 'isPaul', (0, _computed_macros.match)('name', /Paul/));
equal(get(obj, 'isPaul'), true, 'is Paul');
set(obj, 'name', 'Pierre');
equal(get(obj, 'isPaul'), false, 'is not Paul anymore');
});
(0, _internalTestHelpers.testBoth)('computed.notEmpty', function (get, set) {
var obj = { items: [1] };
(0, _emberMetal.defineProperty)(obj, 'hasItems', (0, _computed_macros.notEmpty)('items'));
equal(get(obj, 'hasItems'), true, 'is not empty');
set(obj, 'items', []);
equal(get(obj, 'hasItems'), false, 'is empty');
});
(0, _internalTestHelpers.testBoth)('computed.equal', function (get, set) {
var obj = { name: 'Paul' };
(0, _emberMetal.defineProperty)(obj, 'isPaul', (0, _computed_macros.equal)('name', 'Paul'));
equal(get(obj, 'isPaul'), true, 'is Paul');
set(obj, 'name', 'Pierre');
equal(get(obj, 'isPaul'), false, 'is not Paul anymore');
});
(0, _internalTestHelpers.testBoth)('computed.gt', function (get, set) {
var obj = { number: 2 };
(0, _emberMetal.defineProperty)(obj, 'isGreaterThenOne', (0, _computed_macros.gt)('number', 1));
equal(get(obj, 'isGreaterThenOne'), true, 'is gt');
set(obj, 'number', 1);
equal(get(obj, 'isGreaterThenOne'), false, 'is not gt');
set(obj, 'number', 0);
equal(get(obj, 'isGreaterThenOne'), false, 'is not gt');
});
(0, _internalTestHelpers.testBoth)('computed.gte', function (get, set) {
var obj = { number: 2 };
(0, _emberMetal.defineProperty)(obj, 'isGreaterOrEqualThenOne', (0, _computed_macros.gte)('number', 1));
equal(get(obj, 'isGreaterOrEqualThenOne'), true, 'is gte');
set(obj, 'number', 1);
equal(get(obj, 'isGreaterOrEqualThenOne'), true, 'is gte');
set(obj, 'number', 0);
equal(get(obj, 'isGreaterOrEqualThenOne'), false, 'is not gte');
});
(0, _internalTestHelpers.testBoth)('computed.lt', function (get, set) {
var obj = { number: 0 };
(0, _emberMetal.defineProperty)(obj, 'isLesserThenOne', (0, _computed_macros.lt)('number', 1));
equal(get(obj, 'isLesserThenOne'), true, 'is lt');
set(obj, 'number', 1);
equal(get(obj, 'isLesserThenOne'), false, 'is not lt');
set(obj, 'number', 2);
equal(get(obj, 'isLesserThenOne'), false, 'is not lt');
});
(0, _internalTestHelpers.testBoth)('computed.lte', function (get, set) {
var obj = { number: 0 };
(0, _emberMetal.defineProperty)(obj, 'isLesserOrEqualThenOne', (0, _computed_macros.lte)('number', 1));
equal(get(obj, 'isLesserOrEqualThenOne'), true, 'is lte');
set(obj, 'number', 1);
equal(get(obj, 'isLesserOrEqualThenOne'), true, 'is lte');
set(obj, 'number', 2);
equal(get(obj, 'isLesserOrEqualThenOne'), false, 'is not lte');
});
(0, _internalTestHelpers.testBoth)('computed.and two properties', function (get, set) {
var obj = { one: true, two: true };
(0, _emberMetal.defineProperty)(obj, 'oneAndTwo', (0, _computed_macros.and)('one', 'two'));
equal(get(obj, 'oneAndTwo'), true, 'one and two');
set(obj, 'one', false);
equal(get(obj, 'oneAndTwo'), false, 'one and not two');
set(obj, 'one', null);
set(obj, 'two', 'Yes');
equal(get(obj, 'oneAndTwo'), null, 'returns falsy value as in &&');
set(obj, 'one', true);
set(obj, 'two', 2);
equal(get(obj, 'oneAndTwo'), 2, 'returns truthy value as in &&');
});
(0, _internalTestHelpers.testBoth)('computed.and three properties', function (get, set) {
var obj = { one: true, two: true, three: true };
(0, _emberMetal.defineProperty)(obj, 'oneTwoThree', (0, _computed_macros.and)('one', 'two', 'three'));
equal(get(obj, 'oneTwoThree'), true, 'one and two and three');
set(obj, 'one', false);
equal(get(obj, 'oneTwoThree'), false, 'one and not two and not three');
set(obj, 'one', true);
set(obj, 'two', 2);
set(obj, 'three', 3);
equal(get(obj, 'oneTwoThree'), 3, 'returns truthy value as in &&');
});
(0, _internalTestHelpers.testBoth)('computed.and expand properties', function (get, set) {
var obj = { one: true, two: true, three: true };
(0, _emberMetal.defineProperty)(obj, 'oneTwoThree', (0, _computed_macros.and)('{one,two,three}'));
equal(get(obj, 'oneTwoThree'), true, 'one and two and three');
set(obj, 'one', false);
equal(get(obj, 'oneTwoThree'), false, 'one and not two and not three');
set(obj, 'one', true);
set(obj, 'two', 2);
set(obj, 'three', 3);
equal(get(obj, 'oneTwoThree'), 3, 'returns truthy value as in &&');
});
(0, _internalTestHelpers.testBoth)('computed.or two properties', function (get, set) {
var obj = { one: true, two: true };
(0, _emberMetal.defineProperty)(obj, 'oneOrTwo', (0, _computed_macros.or)('one', 'two'));
equal(get(obj, 'oneOrTwo'), true, 'one or two');
set(obj, 'one', false);
equal(get(obj, 'oneOrTwo'), true, 'one or two');
set(obj, 'two', false);
equal(get(obj, 'oneOrTwo'), false, 'nor one nor two');
set(obj, 'two', null);
equal(get(obj, 'oneOrTwo'), null, 'returns last falsy value as in ||');
set(obj, 'two', true);
equal(get(obj, 'oneOrTwo'), true, 'one or two');
set(obj, 'one', 1);
equal(get(obj, 'oneOrTwo'), 1, 'returns truthy value as in ||');
});
(0, _internalTestHelpers.testBoth)('computed.or three properties', function (get, set) {
var obj = { one: true, two: true, three: true };
(0, _emberMetal.defineProperty)(obj, 'oneTwoThree', (0, _computed_macros.or)('one', 'two', 'three'));
equal(get(obj, 'oneTwoThree'), true, 'one or two or three');
set(obj, 'one', false);
equal(get(obj, 'oneTwoThree'), true, 'one or two or three');
set(obj, 'two', false);
equal(get(obj, 'oneTwoThree'), true, 'one or two or three');
set(obj, 'three', false);
equal(get(obj, 'oneTwoThree'), false, 'one or two or three');
set(obj, 'three', null);
equal(get(obj, 'oneTwoThree'), null, 'returns last falsy value as in ||');
set(obj, 'two', true);
equal(get(obj, 'oneTwoThree'), true, 'one or two or three');
set(obj, 'one', 1);
equal(get(obj, 'oneTwoThree'), 1, 'returns truthy value as in ||');
});
(0, _internalTestHelpers.testBoth)('computed.or expand properties', function (get, set) {
var obj = { one: true, two: true, three: true };
(0, _emberMetal.defineProperty)(obj, 'oneTwoThree', (0, _computed_macros.or)('{one,two,three}'));
equal(get(obj, 'oneTwoThree'), true, 'one or two or three');
set(obj, 'one', false);
equal(get(obj, 'oneTwoThree'), true, 'one or two or three');
set(obj, 'two', false);
equal(get(obj, 'oneTwoThree'), true, 'one or two or three');
set(obj, 'three', false);
equal(get(obj, 'oneTwoThree'), false, 'one or two or three');
set(obj, 'three', null);
equal(get(obj, 'oneTwoThree'), null, 'returns last falsy value as in ||');
set(obj, 'two', true);
equal(get(obj, 'oneTwoThree'), true, 'one or two or three');
set(obj, 'one', 1);
equal(get(obj, 'oneTwoThree'), 1, 'returns truthy value as in ||');
});
(0, _internalTestHelpers.testBoth)('computed.or and computed.and warn about dependent keys with spaces', function () {
var obj = { one: true, two: true };
expectAssertion(function () {
(0, _emberMetal.defineProperty)(obj, 'oneOrTwo', (0, _computed_macros.or)('one', 'two three'));
}, /Dependent keys passed to Ember\.computed\.or\(\) can't have spaces\./);
expectAssertion(function () {
(0, _emberMetal.defineProperty)(obj, 'oneAndTwo', (0, _computed_macros.and)('one', 'two three'));
}, /Dependent keys passed to Ember\.computed\.and\(\) can't have spaces\./);
});
(0, _internalTestHelpers.testBoth)('computed.oneWay', function (get, set) {
var obj = {
firstName: 'Teddy',
lastName: 'Zeenny'
};
(0, _emberMetal.defineProperty)(obj, 'nickName', (0, _computed_macros.oneWay)('firstName'));
equal(get(obj, 'firstName'), 'Teddy');
equal(get(obj, 'lastName'), 'Zeenny');
equal(get(obj, 'nickName'), 'Teddy');
set(obj, 'nickName', 'TeddyBear');
equal(get(obj, 'firstName'), 'Teddy');
equal(get(obj, 'lastName'), 'Zeenny');
equal(get(obj, 'nickName'), 'TeddyBear');
set(obj, 'firstName', 'TEDDDDDDDDYYY');
equal(get(obj, 'nickName'), 'TeddyBear');
});
(0, _internalTestHelpers.testBoth)('computed.readOnly', function (get, set) {
var obj = {
firstName: 'Teddy',
lastName: 'Zeenny'
};
(0, _emberMetal.defineProperty)(obj, 'nickName', (0, _computed_macros.readOnly)('firstName'));
equal(get(obj, 'firstName'), 'Teddy');
equal(get(obj, 'lastName'), 'Zeenny');
equal(get(obj, 'nickName'), 'Teddy');
throws(function () {
set(obj, 'nickName', 'TeddyBear');
}, / /);
equal(get(obj, 'firstName'), 'Teddy');
equal(get(obj, 'lastName'), 'Zeenny');
equal(get(obj, 'nickName'), 'Teddy');
set(obj, 'firstName', 'TEDDDDDDDDYYY');
equal(get(obj, 'nickName'), 'TEDDDDDDDDYYY');
});
(0, _internalTestHelpers.testBoth)('computed.deprecatingAlias', function (get, set) {
var obj = { bar: 'asdf', baz: null, quz: false };
(0, _emberMetal.defineProperty)(obj, 'bay', (0, _emberMetal.computed)(function () {
return 'apple';
}));
(0, _emberMetal.defineProperty)(obj, 'barAlias', (0, _computed_macros.deprecatingAlias)('bar'));
(0, _emberMetal.defineProperty)(obj, 'bazAlias', (0, _computed_macros.deprecatingAlias)('baz'));
(0, _emberMetal.defineProperty)(obj, 'quzAlias', (0, _computed_macros.deprecatingAlias)('quz'));
(0, _emberMetal.defineProperty)(obj, 'bayAlias', (0, _computed_macros.deprecatingAlias)('bay'));
expectDeprecation(function () {
equal(get(obj, 'barAlias'), 'asdf');
}, 'Usage of `barAlias` is deprecated, use `bar` instead.');
expectDeprecation(function () {
equal(get(obj, 'bazAlias'), null);
}, 'Usage of `bazAlias` is deprecated, use `baz` instead.');
expectDeprecation(function () {
equal(get(obj, 'quzAlias'), false);
}, 'Usage of `quzAlias` is deprecated, use `quz` instead.');
expectDeprecation(function () {
equal(get(obj, 'bayAlias'), 'apple');
}, 'Usage of `bayAlias` is deprecated, use `bay` instead.');
expectDeprecation(function () {
set(obj, 'barAlias', 'newBar');
}, 'Usage of `barAlias` is deprecated, use `bar` instead.');
expectDeprecation(function () {
set(obj, 'bazAlias', 'newBaz');
}, 'Usage of `bazAlias` is deprecated, use `baz` instead.');
expectDeprecation(function () {
set(obj, 'quzAlias', null);
}, 'Usage of `quzAlias` is deprecated, use `quz` instead.');
equal(get(obj, 'barAlias'), 'newBar');
equal(get(obj, 'bazAlias'), 'newBaz');
equal(get(obj, 'quzAlias'), null);
equal(get(obj, 'bar'), 'newBar');
equal(get(obj, 'baz'), 'newBaz');
equal(get(obj, 'quz'), null);
});
});
enifed('ember-runtime/tests/computed/reduce_computed_macros_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object', 'ember-runtime/system/object_proxy', 'ember-runtime/computed/reduce_computed_macros', 'ember-runtime/utils', 'ember-runtime/system/native_array', 'ember-runtime/mixins/mutable_array'], function (_emberMetal, _internalTestHelpers, _object, _object_proxy, _reduce_computed_macros, _utils, _native_array, _mutable_array) {
'use strict';
var obj = void 0;
QUnit.module('map', {
setup: function () {
obj = _object.default.extend({
mapped: (0, _reduce_computed_macros.map)('array.@each.v', function (item) {
return item.v;
}),
mappedObjects: (0, _reduce_computed_macros.map)('arrayObjects.@each.v', function (item) {
return { name: item.v.name };
})
}).create({
arrayObjects: (0, _native_array.A)([{ v: { name: 'Robert' } }, { v: { name: 'Leanna' } }]),
array: (0, _native_array.A)([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('map is readOnly', function () {
QUnit.throws(function () {
obj.set('mapped', 1);
}, /Cannot set read-only property "mapped" on object:/);
});
QUnit.test('it maps simple properties', function () {
deepEqual(obj.get('mapped'), [1, 3, 2, 1]);
obj.get('array').pushObject({ v: 5 });
deepEqual(obj.get('mapped'), [1, 3, 2, 1, 5]);
(0, _mutable_array.removeAt)(obj.get('array'), 3);
deepEqual(obj.get('mapped'), [1, 3, 2, 5]);
});
QUnit.test('it maps simple unshifted properties', function () {
var array = (0, _native_array.A)();
obj = _object.default.extend({
mapped: (0, _reduce_computed_macros.map)('array', function (item) {
return item.toUpperCase();
})
}).create({
array: array
});
array.unshiftObject('c');
array.unshiftObject('b');
array.unshiftObject('a');
array.popObject();
deepEqual(obj.get('mapped'), ['A', 'B'], 'properties unshifted in sequence are mapped correctly');
});
QUnit.test('it has the correct `this`', function () {
obj = _object.default.extend({
mapped: (0, _reduce_computed_macros.map)('array', function (item) {
equal(this, obj, 'should have correct context');
return this.upperCase(item);
}),
upperCase: function (string) {
return string.toUpperCase();
}
}).create({
array: ['a', 'b', 'c']
});
deepEqual(obj.get('mapped'), ['A', 'B', 'C'], 'properties unshifted in sequence are mapped correctly');
});
QUnit.test('it passes the index to the callback', function () {
obj = _object.default.extend({
mapped: (0, _reduce_computed_macros.map)('array', function (item, index) {
return index;
})
}).create({
array: ['a', 'b', 'c']
});
deepEqual(obj.get('mapped'), [0, 1, 2], 'index is passed to callback correctly');
});
QUnit.test('it maps objects', function () {
deepEqual(obj.get('mappedObjects'), [{ name: 'Robert' }, { name: 'Leanna' }]);
obj.get('arrayObjects').pushObject({
v: { name: 'Eddard' }
});
deepEqual(obj.get('mappedObjects'), [{ name: 'Robert' }, { name: 'Leanna' }, { name: 'Eddard' }]);
(0, _mutable_array.removeAt)(obj.get('arrayObjects'), 1);
deepEqual(obj.get('mappedObjects'), [{ name: 'Robert' }, { name: 'Eddard' }]);
(0, _emberMetal.set)(obj.get('arrayObjects')[0], 'v', { name: 'Stannis' });
deepEqual(obj.get('mappedObjects'), [{ name: 'Stannis' }, { name: 'Eddard' }]);
});
QUnit.test('it maps unshifted objects with property observers', function () {
var array = (0, _native_array.A)();
var cObj = { v: 'c' };
obj = _object.default.extend({
mapped: (0, _reduce_computed_macros.map)('array.@each.v', function (item) {
return (0, _emberMetal.get)(item, 'v').toUpperCase();
})
}).create({
array: array
});
array.unshiftObject(cObj);
array.unshiftObject({ v: 'b' });
array.unshiftObject({ v: 'a' });
(0, _emberMetal.set)(cObj, 'v', 'd');
deepEqual(array.mapBy('v'), ['a', 'b', 'd'], 'precond - unmapped array is correct');
deepEqual(obj.get('mapped'), ['A', 'B', 'D'], 'properties unshifted in sequence are mapped correctly');
});
QUnit.module('mapBy', {
setup: function () {
obj = _object.default.extend({
mapped: (0, _reduce_computed_macros.mapBy)('array', 'v')
}).create({
array: (0, _native_array.A)([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('mapBy is readOnly', function () {
QUnit.throws(function () {
obj.set('mapped', 1);
}, /Cannot set read-only property "mapped" on object:/);
});
QUnit.test('it maps properties', function () {
deepEqual(obj.get('mapped'), [1, 3, 2, 1]);
obj.get('array').pushObject({ v: 5 });
deepEqual(obj.get('mapped'), [1, 3, 2, 1, 5]);
(0, _mutable_array.removeAt)(obj.get('array'), 3);
deepEqual(obj.get('mapped'), [1, 3, 2, 5]);
});
QUnit.test('it is observable', function () {
var calls = 0;
deepEqual(obj.get('mapped'), [1, 3, 2, 1]);
(0, _emberMetal.addObserver)(obj, 'mapped.@each', function () {
return calls++;
});
obj.get('array').pushObject({ v: 5 });
equal(calls, 1, 'mapBy is observable');
});
QUnit.module('filter', {
setup: function () {
obj = _object.default.extend({
filtered: (0, _reduce_computed_macros.filter)('array', function (item) {
return item % 2 === 0;
})
}).create({
array: (0, _native_array.A)([1, 2, 3, 4, 5, 6, 7, 8])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('filter is readOnly', function () {
QUnit.throws(function () {
obj.set('filtered', 1);
}, /Cannot set read-only property "filtered" on object:/);
});
QUnit.test('it filters according to the specified filter function', function () {
deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'filter filters by the specified function');
});
QUnit.test('it passes the index to the callback', function () {
obj = _object.default.extend({
filtered: (0, _reduce_computed_macros.filter)('array', function (item, index) {
return index === 1;
})
}).create({
array: ['a', 'b', 'c']
});
deepEqual((0, _emberMetal.get)(obj, 'filtered'), ['b'], 'index is passed to callback correctly');
});
QUnit.test('it has the correct `this`', function () {
obj = _object.default.extend({
filtered: (0, _reduce_computed_macros.filter)('array', function (item, index) {
equal(this, obj);
return this.isOne(index);
}),
isOne: function (value) {
return value === 1;
}
}).create({
array: ['a', 'b', 'c']
});
deepEqual((0, _emberMetal.get)(obj, 'filtered'), ['b'], 'index is passed to callback correctly');
});
QUnit.test('it passes the array to the callback', function () {
obj = _object.default.extend({
filtered: (0, _reduce_computed_macros.filter)('array', function (item, index, array) {
return index === (0, _emberMetal.get)(array, 'length') - 2;
})
}).create({
array: (0, _native_array.A)(['a', 'b', 'c'])
});
deepEqual(obj.get('filtered'), ['b'], 'array is passed to callback correctly');
});
QUnit.test('it caches properly', function () {
var array = obj.get('array');
var filtered = obj.get('filtered');
ok(filtered === obj.get('filtered'));
array.addObject(11);
var newFiltered = obj.get('filtered');
ok(filtered !== newFiltered);
ok(obj.get('filtered') === newFiltered);
});
QUnit.test('it updates as the array is modified', function () {
var array = obj.get('array');
deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'precond - filtered array is initially correct');
array.addObject(11);
deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'objects not passing the filter are not added');
array.addObject(12);
deepEqual(obj.get('filtered'), [2, 4, 6, 8, 12], 'objects passing the filter are added');
array.removeObject(3);
array.removeObject(4);
deepEqual(obj.get('filtered'), [2, 6, 8, 12], 'objects removed from the dependent array are removed from the computed array');
});
QUnit.test('the dependent array can be cleared one at a time', function () {
var array = (0, _emberMetal.get)(obj, 'array');
deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'precond - filtered array is initially correct');
// clear 1-8 but in a random order
array.removeObject(3);
array.removeObject(1);
array.removeObject(2);
array.removeObject(4);
array.removeObject(8);
array.removeObject(6);
array.removeObject(5);
array.removeObject(7);
deepEqual(obj.get('filtered'), [], 'filtered array cleared correctly');
});
QUnit.test('the dependent array can be `clear`ed directly (#3272)', function () {
deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'precond - filtered array is initially correct');
obj.get('array').clear();
deepEqual(obj.get('filtered'), [], 'filtered array cleared correctly');
});
QUnit.test('it updates as the array is replaced', function () {
deepEqual(obj.get('filtered'), [2, 4, 6, 8], 'precond - filtered array is initially correct');
obj.set('array', [20, 21, 22, 23, 24]);
deepEqual(obj.get('filtered'), [20, 22, 24], 'computed array is updated when array is changed');
});
QUnit.module('filterBy', {
setup: function () {
obj = _object.default.extend({
a1s: (0, _reduce_computed_macros.filterBy)('array', 'a', 1),
as: (0, _reduce_computed_macros.filterBy)('array', 'a'),
bs: (0, _reduce_computed_macros.filterBy)('array', 'b')
}).create({
array: (0, _native_array.A)([{ name: 'one', a: 1, b: false }, { name: 'two', a: 2, b: false }, { name: 'three', a: 1, b: true }, { name: 'four', b: true }])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('filterBy is readOnly', function () {
QUnit.throws(function () {
obj.set('as', 1);
}, /Cannot set read-only property "as" on object:/);
});
QUnit.test('properties can be filtered by truthiness', function () {
deepEqual(obj.get('as').mapBy('name'), ['one', 'two', 'three'], 'properties can be filtered by existence');
deepEqual(obj.get('bs').mapBy('name'), ['three', 'four'], 'booleans can be filtered');
(0, _emberMetal.set)(obj.get('array')[0], 'a', undefined);
(0, _emberMetal.set)(obj.get('array')[3], 'a', true);
(0, _emberMetal.set)(obj.get('array')[0], 'b', true);
(0, _emberMetal.set)(obj.get('array')[3], 'b', false);
deepEqual(obj.get('as').mapBy('name'), ['two', 'three', 'four'], 'arrays computed by filter property respond to property changes');
deepEqual(obj.get('bs').mapBy('name'), ['one', 'three'], 'arrays computed by filtered property respond to property changes');
obj.get('array').pushObject({ name: 'five', a: 6, b: true });
deepEqual(obj.get('as').mapBy('name'), ['two', 'three', 'four', 'five'], 'arrays computed by filter property respond to added objects');
deepEqual(obj.get('bs').mapBy('name'), ['one', 'three', 'five'], 'arrays computed by filtered property respond to added objects');
obj.get('array').popObject();
deepEqual(obj.get('as').mapBy('name'), ['two', 'three', 'four'], 'arrays computed by filter property respond to removed objects');
deepEqual(obj.get('bs').mapBy('name'), ['one', 'three'], 'arrays computed by filtered property respond to removed objects');
obj.set('array', [{ name: 'six', a: 12, b: true }]);
deepEqual(obj.get('as').mapBy('name'), ['six'], 'arrays computed by filter property respond to array changes');
deepEqual(obj.get('bs').mapBy('name'), ['six'], 'arrays computed by filtered property respond to array changes');
});
QUnit.test('properties can be filtered by values', function () {
deepEqual(obj.get('a1s').mapBy('name'), ['one', 'three'], 'properties can be filtered by matching value');
obj.get('array').pushObject({ name: 'five', a: 1 });
deepEqual(obj.get('a1s').mapBy('name'), ['one', 'three', 'five'], 'arrays computed by matching value respond to added objects');
obj.get('array').popObject();
deepEqual(obj.get('a1s').mapBy('name'), ['one', 'three'], 'arrays computed by matching value respond to removed objects');
(0, _emberMetal.set)(obj.get('array')[1], 'a', 1);
(0, _emberMetal.set)(obj.get('array')[2], 'a', 2);
deepEqual(obj.get('a1s').mapBy('name'), ['one', 'two'], 'arrays computed by matching value respond to modified properties');
});
QUnit.test('properties values can be replaced', function () {
obj = _object.default.extend({
a1s: (0, _reduce_computed_macros.filterBy)('array', 'a', 1),
a1bs: (0, _reduce_computed_macros.filterBy)('a1s', 'b')
}).create({
array: []
});
deepEqual(obj.get('a1bs').mapBy('name'), [], 'properties can be filtered by matching value');
(0, _emberMetal.set)(obj, 'array', [{ name: 'item1', a: 1, b: true }]);
deepEqual(obj.get('a1bs').mapBy('name'), ['item1'], 'properties can be filtered by matching value');
});
[['uniq', _reduce_computed_macros.uniq], ['union', _reduce_computed_macros.union]].forEach(function (tuple) {
var name = tuple[0],
macro = tuple[1];
QUnit.module('computed.' + name, {
setup: function () {
obj = _object.default.extend({
union: macro('array', 'array2', 'array3')
}).create({
array: (0, _native_array.A)([1, 2, 3, 4, 5, 6]),
array2: (0, _native_array.A)([4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9]),
array3: (0, _native_array.A)([1, 8, 10])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test(name + ' is readOnly', function () {
QUnit.throws(function () {
obj.set('union', 1);
}, /Cannot set read-only property "union" on object:/);
});
QUnit.test('does not include duplicates', function () {
var array = obj.get('array');
var array2 = obj.get('array2');
deepEqual(obj.get('union').sort(function (x, y) {
return x - y;
}), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], name + ' does not include duplicates');
array.pushObject(8);
deepEqual(obj.get('union').sort(function (x, y) {
return x - y;
}), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], name + ' does not add existing items');
array.pushObject(11);
deepEqual(obj.get('union').sort(function (x, y) {
return x - y;
}), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], name + ' adds new items');
(0, _mutable_array.removeAt)(array2, 6); // remove 7
deepEqual(obj.get('union').sort(function (x, y) {
return x - y;
}), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], name + ' does not remove items that are still in the dependent array');
array2.removeObject(7);
deepEqual(obj.get('union').sort(function (x, y) {
return x - y;
}), [1, 2, 3, 4, 5, 6, 8, 9, 10, 11], name + ' removes items when their last instance is gone');
});
QUnit.test('has set-union semantics', function () {
var array = obj.get('array');
deepEqual(obj.get('union').sort(function (x, y) {
return x - y;
}), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], name + ' is initially correct');
array.removeObject(6);
deepEqual(obj.get('union').sort(function (x, y) {
return x - y;
}), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'objects are not removed if they exist in other dependent arrays');
array.clear();
deepEqual(obj.get('union').sort(function (x, y) {
return x - y;
}), [1, 4, 5, 6, 7, 8, 9, 10], 'objects are removed when they are no longer in any dependent array');
});
});
QUnit.module('computed.uniqBy', {
setup: function () {
obj = _object.default.extend({
list: null,
uniqueById: (0, _reduce_computed_macros.uniqBy)('list', 'id')
}).create({
list: (0, _native_array.A)([{ id: 1, value: 'one' }, { id: 2, value: 'two' }, { id: 1, value: 'one' }])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('uniqBy is readOnly', function () {
QUnit.throws(function () {
obj.set('uniqueById', 1);
}, /Cannot set read-only property "uniqueById" on object:/);
});
QUnit.test('does not include duplicates', function () {
deepEqual(obj.get('uniqueById'), [{ id: 1, value: 'one' }, { id: 2, value: 'two' }]);
});
QUnit.test('it does not share state among instances', function () {
var MyObject = _object.default.extend({
list: [],
uniqueByName: (0, _reduce_computed_macros.uniqBy)('list', 'name')
});
var a = MyObject.create({ list: [{ name: 'bob' }, { name: 'mitch' }, { name: 'mitch' }] });
var b = MyObject.create({ list: [{ name: 'warren' }, { name: 'mitch' }] });
deepEqual(a.get('uniqueByName'), [{ name: 'bob' }, { name: 'mitch' }]);
// Making sure that 'mitch' appears
deepEqual(b.get('uniqueByName'), [{ name: 'warren' }, { name: 'mitch' }]);
});
QUnit.test('it handles changes to the dependent array', function () {
obj.get('list').pushObject({ id: 3, value: 'three' });
deepEqual(obj.get('uniqueById'), [{ id: 1, value: 'one' }, { id: 2, value: 'two' }, { id: 3, value: 'three' }], 'The list includes three');
obj.get('list').pushObject({ id: 3, value: 'three' });
deepEqual(obj.get('uniqueById'), [{ id: 1, value: 'one' }, { id: 2, value: 'two' }, { id: 3, value: 'three' }], 'The list does not include a duplicate three');
});
QUnit.test('it returns an empty array when computed on a non-array', function () {
var MyObject = _object.default.extend({
list: null,
uniq: (0, _reduce_computed_macros.uniqBy)('list', 'name')
});
var a = MyObject.create({ list: 'not an array' });
deepEqual(a.get('uniq'), []);
});
QUnit.module('computed.intersect', {
setup: function () {
obj = _object.default.extend({
intersection: (0, _reduce_computed_macros.intersect)('array', 'array2', 'array3')
}).create({
array: (0, _native_array.A)([1, 2, 3, 4, 5, 6]),
array2: (0, _native_array.A)([3, 3, 3, 4, 5]),
array3: (0, _native_array.A)([3, 5, 6, 7, 8])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('intersect is readOnly', function () {
QUnit.throws(function () {
obj.set('intersection', 1);
}, /Cannot set read-only property "intersection" on object:/);
});
QUnit.test('it has set-intersection semantics', function () {
var array2 = obj.get('array2');
var array3 = obj.get('array3');
deepEqual(obj.get('intersection').sort(function (x, y) {
return x - y;
}), [3, 5], 'intersection is initially correct');
array2.shiftObject();
deepEqual(obj.get('intersection').sort(function (x, y) {
return x - y;
}), [3, 5], 'objects are not removed when they are still in all dependent arrays');
array2.shiftObject();
deepEqual(obj.get('intersection').sort(function (x, y) {
return x - y;
}), [3, 5], 'objects are not removed when they are still in all dependent arrays');
array2.shiftObject();
deepEqual(obj.get('intersection'), [5], 'objects are removed once they are gone from all dependent arrays');
array2.pushObject(1);
deepEqual(obj.get('intersection'), [5], 'objects are not added as long as they are missing from any dependent array');
array3.pushObject(1);
deepEqual(obj.get('intersection').sort(function (x, y) {
return x - y;
}), [1, 5], 'objects added once they belong to all dependent arrays');
});
QUnit.module('setDiff', {
setup: function () {
obj = _object.default.extend({
diff: (0, _reduce_computed_macros.setDiff)('array', 'array2')
}).create({
array: (0, _native_array.A)([1, 2, 3, 4, 5, 6, 7]),
array2: (0, _native_array.A)([3, 4, 5, 10])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('setDiff is readOnly', function () {
QUnit.throws(function () {
obj.set('diff', 1);
}, /Cannot set read-only property "diff" on object:/);
});
QUnit.test('it throws an error if given fewer or more than two dependent properties', function () {
throws(function () {
_object.default.extend({
diff: (0, _reduce_computed_macros.setDiff)('array')
}).create({
array: (0, _native_array.A)([1, 2, 3, 4, 5, 6, 7]),
array2: (0, _native_array.A)([3, 4, 5])
});
}, /requires exactly two dependent arrays/, 'setDiff requires two dependent arrays');
throws(function () {
_object.default.extend({
diff: (0, _reduce_computed_macros.setDiff)('array', 'array2', 'array3')
}).create({
array: (0, _native_array.A)([1, 2, 3, 4, 5, 6, 7]),
array2: (0, _native_array.A)([3, 4, 5]),
array3: (0, _native_array.A)([7])
});
}, /requires exactly two dependent arrays/, 'setDiff requires two dependent arrays');
});
QUnit.test('it has set-diff semantics', function () {
var array1 = obj.get('array');
var array2 = obj.get('array2');
deepEqual(obj.get('diff').sort(function (x, y) {
return x - y;
}), [1, 2, 6, 7], 'set-diff is initially correct');
array2.popObject();
deepEqual(obj.get('diff').sort(function (x, y) {
return x - y;
}), [1, 2, 6, 7], 'removing objects from the remove set has no effect if the object is not in the keep set');
array2.shiftObject();
deepEqual(obj.get('diff').sort(function (x, y) {
return x - y;
}), [1, 2, 3, 6, 7], 'removing objects from the remove set adds them if they\'re in the keep set');
array1.removeObject(3);
deepEqual(obj.get('diff').sort(function (x, y) {
return x - y;
}), [1, 2, 6, 7], 'removing objects from the keep array removes them from the computed array');
array1.pushObject(5);
deepEqual(obj.get('diff').sort(function (x, y) {
return x - y;
}), [1, 2, 6, 7], 'objects added to the keep array that are in the remove array are not added to the computed array');
array1.pushObject(22);
deepEqual(obj.get('diff').sort(function (x, y) {
return x - y;
}), [1, 2, 6, 7, 22], 'objects added to the keep array not in the remove array are added to the computed array');
});
function commonSortTests() {
QUnit.test('arrays are initially sorted', function () {
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'array is initially sorted');
});
QUnit.test('default sort order is correct', function () {
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'array is initially sorted');
});
QUnit.test('changing the dependent array updates the sorted array', function () {
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
obj.set('items', [{ fname: 'Roose', lname: 'Bolton' }, { fname: 'Theon', lname: 'Greyjoy' }, { fname: 'Ramsey', lname: 'Bolton' }, { fname: 'Stannis', lname: 'Baratheon' }]);
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Stannis', 'Ramsey', 'Roose', 'Theon'], 'changing dependent array updates sorted array');
});
QUnit.test('adding to the dependent array updates the sorted array', function () {
var items = obj.get('items');
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
items.pushObject({
fname: 'Tyrion',
lname: 'Lannister'
});
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb'], 'Adding to the dependent array updates the sorted array');
});
QUnit.test('removing from the dependent array updates the sorted array', function () {
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
obj.get('items').popObject();
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Robb'], 'Removing from the dependent array updates the sorted array');
});
QUnit.test('distinct items may be sort-equal, although their relative order will not be guaranteed', function () {
// We recreate jaime and "Cersei" here only for test stability: we want
// their guid-ordering to be deterministic
var jaimeInDisguise = {
fname: 'Cersei',
lname: 'Lannister',
age: 34
};
var items = obj.get('items');
items.replace(0, 1, {
fname: 'Jaime',
lname: 'Lannister',
age: 34
});
items.replace(1, 1, jaimeInDisguise);
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
(0, _emberMetal.set)(jaimeInDisguise, 'fname', 'Jaime');
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Jaime', 'Jaime', 'Bran', 'Robb'], 'sorted array is updated');
(0, _emberMetal.set)(jaimeInDisguise, 'fname', 'Cersei');
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'sorted array is updated');
});
QUnit.test('guid sort-order fallback with a search proxy is not confused by non-search ObjectProxys', function () {
var tyrion = {
fname: 'Tyrion',
lname: 'Lannister'
};
var tyrionInDisguise = _object_proxy.default.create({
fname: 'Yollo',
lname: '',
content: tyrion
});
var items = obj.get('items');
items.pushObject(tyrion);
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb']);
items.pushObject(tyrionInDisguise);
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Yollo', 'Cersei', 'Jaime', 'Tyrion', 'Bran', 'Robb']);
});
}
QUnit.module('sort - sortProperties', {
setup: function () {
obj = _object.default.extend({
sortedItems: (0, _reduce_computed_macros.sort)('items', 'itemSorting')
}).create({
itemSorting: (0, _native_array.A)(['lname', 'fname']),
items: (0, _native_array.A)([{ fname: 'Jaime', lname: 'Lannister', age: 34 }, { fname: 'Cersei', lname: 'Lannister', age: 34 }, { fname: 'Robb', lname: 'Stark', age: 16 }, { fname: 'Bran', lname: 'Stark', age: 8 }])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('sort is readOnly', function () {
QUnit.throws(function () {
obj.set('sortedItems', 1);
}, /Cannot set read-only property "sortedItems" on object:/);
});
commonSortTests();
QUnit.test('updating sort properties detaches observers for old sort properties', function () {
var objectToRemove = obj.get('items')[3];
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
obj.set('itemSorting', (0, _native_array.A)(['fname:desc']));
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Robb', 'Jaime', 'Cersei', 'Bran'], 'after updating sort properties array is updated');
obj.get('items').removeObject(objectToRemove);
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Robb', 'Jaime', 'Cersei'], 'after removing item array is updated');
(0, _emberMetal.set)(objectToRemove, 'lname', 'Updated-Stark');
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Robb', 'Jaime', 'Cersei'], 'after changing removed item array is not updated');
});
QUnit.test('updating sort properties updates the sorted array', function () {
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
obj.set('itemSorting', (0, _native_array.A)(['fname:desc']));
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Robb', 'Jaime', 'Cersei', 'Bran'], 'after updating sort properties array is updated');
});
QUnit.test('updating sort properties invalidates the sorted array', function () {
var sortProps = obj.get('itemSorting');
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
sortProps.clear();
sortProps.pushObject('fname');
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Bran', 'Cersei', 'Jaime', 'Robb'], 'after updating sort properties array is updated');
});
QUnit.test('updating new sort properties invalidates the sorted array', function () {
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
obj.set('itemSorting', (0, _native_array.A)(['age:desc', 'fname:asc']));
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Robb', 'Bran'], 'precond - array is correct after item sorting is changed');
(0, _emberMetal.set)(obj.get('items')[1], 'age', 29);
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Jaime', 'Cersei', 'Robb', 'Bran'], 'after updating sort properties array is updated');
});
QUnit.test('sort direction defaults to ascending', function () {
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb']);
});
QUnit.test('sort direction defaults to ascending (with sort property change)', function () {
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
obj.set('itemSorting', (0, _native_array.A)(['fname']));
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Bran', 'Cersei', 'Jaime', 'Robb'], 'sort direction defaults to ascending');
});
QUnit.test('updating an item\'s sort properties updates the sorted array', function () {
var tyrionInDisguise = obj.get('items')[1];
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
(0, _emberMetal.set)(tyrionInDisguise, 'fname', 'Tyrion');
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Jaime', 'Tyrion', 'Bran', 'Robb'], 'updating an item\'s sort properties updates the sorted array');
});
QUnit.test('updating several of an item\'s sort properties updated the sorted array', function () {
var sansaInDisguise = obj.get('items')[1];
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
(0, _emberMetal.setProperties)(sansaInDisguise, {
fname: 'Sansa',
lname: 'Stark'
});
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Jaime', 'Bran', 'Robb', 'Sansa'], 'updating an item\'s sort properties updates the sorted array');
});
QUnit.test('updating an item\'s sort properties does not error when binary search does a self compare (#3273)', function () {
var jaime = {
name: 'Jaime',
status: 1
};
var cersei = {
name: 'Cersei',
status: 2
};
var obj = _object.default.extend({
sortProps: ['status'],
sortedPeople: (0, _reduce_computed_macros.sort)('people', 'sortProps')
}).create({
people: [jaime, cersei]
});
deepEqual(obj.get('sortedPeople'), [jaime, cersei], 'precond - array is initially sorted');
(0, _emberMetal.set)(cersei, 'status', 3);
deepEqual(obj.get('sortedPeople'), [jaime, cersei], 'array is sorted correctly');
(0, _emberMetal.set)(cersei, 'status', 2);
deepEqual(obj.get('sortedPeople'), [jaime, cersei], 'array is sorted correctly');
});
QUnit.test('array observers do not leak', function () {
var sortProps = (0, _native_array.A)(['name']);
var jaime = _object.default.extend({
sortedPeople: (0, _reduce_computed_macros.sort)('sisters', 'sortProps'),
sortProps: sortProps
}).create({
sisters: [{ name: 'Jane' }, { name: 'Daria' }]
});
jaime.get('sortedPeople');
(0, _emberMetal.run)(jaime, 'destroy');
try {
sortProps.pushObject({
name: 'Anna'
});
ok(true);
} catch (e) {
ok(false, e);
}
});
QUnit.test('property paths in sort properties update the sorted array', function () {
var jaime = {
relatedObj: { status: 1, firstName: 'Jaime', lastName: 'Lannister' }
};
var cersei = {
relatedObj: { status: 2, firstName: 'Cersei', lastName: 'Lannister' }
};
var sansa = _object.default.create({
relatedObj: { status: 3, firstName: 'Sansa', lastName: 'Stark' }
});
var obj = _object.default.extend({
sortProps: ['relatedObj.status'],
sortedPeople: (0, _reduce_computed_macros.sort)('people', 'sortProps')
}).create({
people: [jaime, cersei, sansa]
});
deepEqual(obj.get('sortedPeople'), [jaime, cersei, sansa], 'precond - array is initially sorted');
(0, _emberMetal.set)(cersei, 'status', 3);
deepEqual(obj.get('sortedPeople'), [jaime, cersei, sansa], 'array is sorted correctly');
(0, _emberMetal.set)(cersei, 'status', 1);
deepEqual(obj.get('sortedPeople'), [jaime, cersei, sansa], 'array is sorted correctly');
sansa.set('status', 1);
deepEqual(obj.get('sortedPeople'), [jaime, cersei, sansa], 'array is sorted correctly');
obj.set('sortProps', ['relatedObj.firstName']);
deepEqual(obj.get('sortedPeople'), [cersei, jaime, sansa], 'array is sorted correctly');
});
QUnit.test('if the dependentKey is neither an array nor object, it will return an empty array', function () {
(0, _emberMetal.set)(obj, 'items', null);
ok((0, _utils.isArray)(obj.get('sortedItems')), 'returns an empty arrays');
(0, _emberMetal.set)(obj, 'array', undefined);
ok((0, _utils.isArray)(obj.get('sortedItems')), 'returns an empty arrays');
(0, _emberMetal.set)(obj, 'array', 'not an array');
ok((0, _utils.isArray)(obj.get('sortedItems')), 'returns an empty arrays');
});
function sortByLnameFname(a, b) {
var lna = (0, _emberMetal.get)(a, 'lname');
var lnb = (0, _emberMetal.get)(b, 'lname');
if (lna !== lnb) {
return lna > lnb ? 1 : -1;
}
return sortByFnameAsc(a, b);
}
function sortByFnameAsc(a, b) {
var fna = (0, _emberMetal.get)(a, 'fname');
var fnb = (0, _emberMetal.get)(b, 'fname');
if (fna === fnb) {
return 0;
}
return fna > fnb ? 1 : -1;
}
QUnit.module('sort - sort function', {
setup: function () {
obj = _object.default.extend({
sortedItems: (0, _reduce_computed_macros.sort)('items.@each.fname', sortByLnameFname)
}).create({
items: (0, _native_array.A)([{ fname: 'Jaime', lname: 'Lannister', age: 34 }, { fname: 'Cersei', lname: 'Lannister', age: 34 }, { fname: 'Robb', lname: 'Stark', age: 16 }, { fname: 'Bran', lname: 'Stark', age: 8 }])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('sort has correct `this`', function () {
var obj = _object.default.extend({
sortedItems: (0, _reduce_computed_macros.sort)('items.@each.fname', function (a, b) {
equal(this, obj, 'expected the object to be `this`');
return this.sortByLastName(a, b);
}),
sortByLastName: function (a, b) {
return sortByFnameAsc(a, b);
}
}).create({
items: (0, _native_array.A)([{ fname: 'Jaime', lname: 'Lannister', age: 34 }, { fname: 'Cersei', lname: 'Lannister', age: 34 }, { fname: 'Robb', lname: 'Stark', age: 16 }, { fname: 'Bran', lname: 'Stark', age: 8 }])
});
obj.get('sortedItems');
});
QUnit.test('sort (with function) is readOnly', function () {
QUnit.throws(function () {
obj.set('sortedItems', 1);
}, /Cannot set read-only property "sortedItems" on object:/);
});
commonSortTests();
QUnit.test('changing item properties specified via @each triggers a resort of the modified item', function () {
var items = (0, _emberMetal.get)(obj, 'items');
var tyrionInDisguise = items[1];
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
(0, _emberMetal.set)(tyrionInDisguise, 'fname', 'Tyrion');
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Jaime', 'Tyrion', 'Bran', 'Robb'], 'updating a specified property on an item resorts it');
});
QUnit.test('changing item properties not specified via @each does not trigger a resort', function () {
var items = obj.get('items');
var cersei = items[1];
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'precond - array is initially sorted');
(0, _emberMetal.set)(cersei, 'lname', 'Stark'); // plot twist! (possibly not canon)
// The array has become unsorted. If your sort function is sensitive to
// properties, they *must* be specified as dependent item property keys or
// we'll be doing binary searches on unsorted arrays.
deepEqual(obj.get('sortedItems').mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], 'updating an unspecified property on an item does not resort it');
});
QUnit.module('sort - stability', {
setup: function () {
obj = _object.default.extend({
sortProps: ['count', 'name'],
sortedItems: (0, _reduce_computed_macros.sort)('items', 'sortProps')
}).create({
items: [{ name: 'A', count: 1, thing: 4 }, { name: 'B', count: 1, thing: 3 }, { name: 'C', count: 1, thing: 2 }, { name: 'D', count: 1, thing: 4 }]
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('sorts correctly as only one property changes', function () {
deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'initial');
(0, _emberMetal.set)(obj.get('items')[3], 'count', 2);
deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'final');
});
var klass = void 0;
QUnit.module('sort - concurrency', {
setup: function () {
klass = _object.default.extend({
sortProps: ['count'],
sortedItems: (0, _reduce_computed_macros.sort)('items', 'sortProps'),
customSortedItems: (0, _reduce_computed_macros.sort)('items.@each.count', function (a, b) {
return a.count - b.count;
})
});
obj = klass.create({
items: (0, _native_array.A)([{ name: 'A', count: 1, thing: 4, id: 1 }, { name: 'B', count: 2, thing: 3, id: 2 }, { name: 'C', count: 3, thing: 2, id: 3 }, { name: 'D', count: 4, thing: 1, id: 4 }])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('sorts correctly after mutation to the sort properties', function () {
var sorted = obj.get('sortedItems');
deepEqual(sorted.mapBy('name'), ['A', 'B', 'C', 'D'], 'initial');
(0, _emberMetal.set)(obj.get('items')[1], 'count', 5);
(0, _emberMetal.set)(obj.get('items')[2], 'count', 6);
deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final');
});
QUnit.test('sort correctly after mutation to the sort', function () {
deepEqual(obj.get('customSortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'initial');
(0, _emberMetal.set)(obj.get('items')[1], 'count', 5);
(0, _emberMetal.set)(obj.get('items')[2], 'count', 6);
deepEqual(obj.get('customSortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final');
deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final');
});
QUnit.test('sort correctly on multiple instances of the same class', function () {
var obj2 = klass.create({
items: (0, _native_array.A)([{ name: 'W', count: 23, thing: 4 }, { name: 'X', count: 24, thing: 3 }, { name: 'Y', count: 25, thing: 2 }, { name: 'Z', count: 26, thing: 1 }])
});
deepEqual(obj2.get('sortedItems').mapBy('name'), ['W', 'X', 'Y', 'Z'], 'initial');
deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'initial');
(0, _emberMetal.set)(obj.get('items')[1], 'count', 5);
(0, _emberMetal.set)(obj.get('items')[2], 'count', 6);
(0, _emberMetal.set)(obj2.get('items')[1], 'count', 27);
(0, _emberMetal.set)(obj2.get('items')[2], 'count', 28);
deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'final');
deepEqual(obj2.get('sortedItems').mapBy('name'), ['W', 'Z', 'X', 'Y'], 'final');
obj.set('sortProps', ['thing']);
deepEqual(obj.get('sortedItems').mapBy('name'), ['D', 'C', 'B', 'A'], 'final');
obj2.notifyPropertyChange('sortedItems'); // invalidate to flush, to get DK refreshed
obj2.get('sortedItems'); // flush to get updated DK
obj2.set('items.firstObject.count', 9999);
deepEqual(obj2.get('sortedItems').mapBy('name'), ['Z', 'X', 'Y', 'W'], 'final');
});
QUnit.test('sort correctly when multiple sorts are chained on the same instance of a class', function () {
var obj2 = klass.extend({
items: (0, _emberMetal.computed)('sibling.sortedItems.[]', function () {
return this.get('sibling.sortedItems');
}),
asdf: (0, _emberMetal.observer)('sibling.sortedItems.[]', function () {
this.get('sibling.sortedItems');
})
}).create({
sibling: obj
});
/*
┌───────────┐ ┌────────────┐
│sortedProps│ │sortedProps2│
└───────────┘ └────────────┘
▲ ▲
│ ╔═══════════╗ │
│─ ─ ─ ─ ─ ─ ─ ▶║ CP (sort) ║◀─ ─ ─ ─ ─ ─ ─ ┤
│ ╚═══════════╝ │
│ │
┌───────────┐ ┏━━━━━━━━━━━┓ ┏━━━━━━━━━━━━┓
│ │ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ ┃ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ ┃
│ items │◀── items.@each.count │◀──┃sortedItems┃◀─── items.@each.count │◀───┃sortedItems2┃
│ │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ ┃ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┃ ┃
└───────────┘ ┗━━━━━━━━━━━┛ ┗━━━━━━━━━━━━┛
*/
deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'obj.sortedItems.name should be sorted alpha');
deepEqual(obj2.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'obj2.sortedItems.name should be sorted alpha');
(0, _emberMetal.set)(obj.get('items')[1], 'count', 5);
(0, _emberMetal.set)(obj.get('items')[2], 'count', 6);
deepEqual(obj.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'obj.sortedItems.name should now have changed');
deepEqual(obj2.get('sortedItems').mapBy('name'), ['A', 'D', 'B', 'C'], 'obj2.sortedItems.name should still mirror sortedItems2');
obj.set('sortProps', ['thing']);
obj2.set('sortProps', ['id']);
deepEqual(obj2.get('sortedItems').mapBy('name'), ['A', 'B', 'C', 'D'], 'we now sort obj2 by id, so we expect a b c d');
deepEqual(obj.get('sortedItems').mapBy('name'), ['D', 'C', 'B', 'A'], 'we now sort obj by thing');
});
QUnit.module('max', {
setup: function () {
obj = _object.default.extend({
max: (0, _reduce_computed_macros.max)('items')
}).create({
items: (0, _native_array.A)([1, 2, 3])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('max is readOnly', function () {
QUnit.throws(function () {
obj.set('max', 1);
}, /Cannot set read-only property "max" on object:/);
});
QUnit.test('max tracks the max number as objects are added', function () {
equal(obj.get('max'), 3, 'precond - max is initially correct');
var items = obj.get('items');
items.pushObject(5);
equal(obj.get('max'), 5, 'max updates when a larger number is added');
items.pushObject(2);
equal(obj.get('max'), 5, 'max does not update when a smaller number is added');
});
QUnit.test('max recomputes when the current max is removed', function () {
equal(obj.get('max'), 3, 'precond - max is initially correct');
obj.get('items').removeObject(2);
equal(obj.get('max'), 3, 'max is unchanged when a non-max item is removed');
obj.get('items').removeObject(3);
equal(obj.get('max'), 1, 'max is recomputed when the current max is removed');
});
QUnit.module('min', {
setup: function () {
obj = _object.default.extend({
min: (0, _reduce_computed_macros.min)('items')
}).create({
items: (0, _native_array.A)([1, 2, 3])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('min is readOnly', function () {
QUnit.throws(function () {
obj.set('min', 1);
}, /Cannot set read-only property "min" on object:/);
});
QUnit.test('min tracks the min number as objects are added', function () {
equal(obj.get('min'), 1, 'precond - min is initially correct');
obj.get('items').pushObject(-2);
equal(obj.get('min'), -2, 'min updates when a smaller number is added');
obj.get('items').pushObject(2);
equal(obj.get('min'), -2, 'min does not update when a larger number is added');
});
QUnit.test('min recomputes when the current min is removed', function () {
var items = obj.get('items');
equal(obj.get('min'), 1, 'precond - min is initially correct');
items.removeObject(2);
equal(obj.get('min'), 1, 'min is unchanged when a non-min item is removed');
items.removeObject(1);
equal(obj.get('min'), 3, 'min is recomputed when the current min is removed');
});
QUnit.module('Ember.arrayComputed - mixed sugar', {
setup: function () {
obj = _object.default.extend({
lannisters: (0, _reduce_computed_macros.filterBy)('items', 'lname', 'Lannister'),
lannisterSorting: (0, _native_array.A)(['fname']),
sortedLannisters: (0, _reduce_computed_macros.sort)('lannisters', 'lannisterSorting'),
starks: (0, _reduce_computed_macros.filterBy)('items', 'lname', 'Stark'),
starkAges: (0, _reduce_computed_macros.mapBy)('starks', 'age'),
oldestStarkAge: (0, _reduce_computed_macros.max)('starkAges')
}).create({
items: (0, _native_array.A)([{ fname: 'Jaime', lname: 'Lannister', age: 34 }, { fname: 'Cersei', lname: 'Lannister', age: 34 }, { fname: 'Robb', lname: 'Stark', age: 16 }, { fname: 'Bran', lname: 'Stark', age: 8 }])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('filtering and sorting can be combined', function () {
var items = obj.get('items');
deepEqual(obj.get('sortedLannisters').mapBy('fname'), ['Cersei', 'Jaime'], 'precond - array is initially filtered and sorted');
items.pushObject({ fname: 'Tywin', lname: 'Lannister' });
items.pushObject({ fname: 'Lyanna', lname: 'Stark' });
items.pushObject({ fname: 'Gerion', lname: 'Lannister' });
deepEqual(obj.get('sortedLannisters').mapBy('fname'), ['Cersei', 'Gerion', 'Jaime', 'Tywin'], 'updates propagate to array');
});
QUnit.test('filtering, sorting and reduce (max) can be combined', function () {
var items = obj.get('items');
equal(16, obj.get('oldestStarkAge'), 'precond - end of chain is initially correct');
items.pushObject({ fname: 'Rickon', lname: 'Stark', age: 5 });
equal(16, obj.get('oldestStarkAge'), 'chain is updated correctly');
items.pushObject({ fname: 'Eddard', lname: 'Stark', age: 35 });
equal(35, obj.get('oldestStarkAge'), 'chain is updated correctly');
});
function todo(name, priority) {
return _object.default.create({ name: name, priority: priority });
}
function priorityComparator(todoA, todoB) {
var pa = parseInt((0, _emberMetal.get)(todoA, 'priority'), 10);
var pb = parseInt((0, _emberMetal.get)(todoB, 'priority'), 10);
return pa - pb;
}
function evenPriorities(todo) {
var p = parseInt((0, _emberMetal.get)(todo, 'priority'), 10);
return p % 2 === 0;
}
QUnit.module('Ember.arrayComputed - chains', {
setup: function () {
obj = _object.default.extend({
sorted: (0, _reduce_computed_macros.sort)('todos.@each.priority', priorityComparator),
filtered: (0, _reduce_computed_macros.filter)('sorted.@each.priority', evenPriorities)
}).create({
todos: (0, _native_array.A)([todo('E', 4), todo('D', 3), todo('C', 2), todo('B', 1), todo('A', 0)])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('it can filter and sort when both depend on the same item property', function () {
deepEqual(obj.get('todos').mapBy('name'), ['E', 'D', 'C', 'B', 'A'], 'precond - todos initially correct');
deepEqual(obj.get('sorted').mapBy('name'), ['A', 'B', 'C', 'D', 'E'], 'precond - sorted initially correct');
deepEqual(obj.get('filtered').mapBy('name'), ['A', 'C', 'E'], 'precond - filtered initially correct');
(0, _emberMetal.set)(obj.get('todos')[1], 'priority', 6);
deepEqual(obj.get('todos').mapBy('name'), ['E', 'D', 'C', 'B', 'A'], 'precond - todos remain correct');
deepEqual(obj.get('sorted').mapBy('name'), ['A', 'B', 'C', 'E', 'D'], 'precond - sorted updated correctly');
deepEqual(obj.get('filtered').mapBy('name'), ['A', 'C', 'E', 'D'], 'filtered updated correctly');
});
var userFnCalls = void 0;
QUnit.module('Chaining array and reduced CPs', {
setup: function () {
userFnCalls = 0;
obj = _object.default.extend({
mapped: (0, _reduce_computed_macros.mapBy)('array', 'v'),
max: (0, _reduce_computed_macros.max)('mapped'),
maxDidChange: (0, _emberMetal.observer)('max', function () {
return userFnCalls++;
})
}).create({
array: (0, _native_array.A)([{ v: 1 }, { v: 3 }, { v: 2 }, { v: 1 }])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('it computes interdependent array computed properties', function () {
equal(obj.get('max'), 3, 'sanity - it properly computes the maximum value');
var calls = 0;
(0, _emberMetal.addObserver)(obj, 'max', function () {
return calls++;
});
obj.get('array').pushObject({ v: 5 });
equal(obj.get('max'), 5, 'maximum value is updated correctly');
equal(userFnCalls, 1, 'object defined observers fire');
equal(calls, 1, 'runtime created observers fire');
});
QUnit.module('sum', {
setup: function () {
obj = _object.default.extend({
total: (0, _reduce_computed_macros.sum)('array')
}).create({
array: (0, _native_array.A)([1, 2, 3])
});
},
teardown: function () {
(0, _emberMetal.run)(obj, 'destroy');
}
});
QUnit.test('sum is readOnly', function () {
QUnit.throws(function () {
obj.set('total', 1);
}, /Cannot set read-only property "total" on object:/);
});
QUnit.test('sums the values in the dependentKey', function () {
equal(obj.get('total'), 6, 'sums the values');
});
QUnit.test('if the dependentKey is neither an array nor object, it will return `0`', function () {
(0, _emberMetal.set)(obj, 'array', null);
equal((0, _emberMetal.get)(obj, 'total'), 0, 'returns 0');
(0, _emberMetal.set)(obj, 'array', undefined);
equal((0, _emberMetal.get)(obj, 'total'), 0, 'returns 0');
(0, _emberMetal.set)(obj, 'array', 'not an array');
equal((0, _emberMetal.get)(obj, 'total'), 0, 'returns 0');
});
QUnit.test('updates when array is modified', function () {
obj.get('array').pushObject(1);
equal(obj.get('total'), 7, 'recomputed when elements are added');
obj.get('array').popObject();
equal(obj.get('total'), 6, 'recomputes when elements are removed');
});
QUnit.module('collect');
(0, _internalTestHelpers.testBoth)('works', function (get, set) {
var obj = { one: 'foo', two: 'bar', three: null };
(0, _emberMetal.defineProperty)(obj, 'all', (0, _reduce_computed_macros.collect)('one', 'two', 'three', 'four'));
deepEqual(get(obj, 'all'), ['foo', 'bar', null, null], 'have all of them');
set(obj, 'four', true);
deepEqual(get(obj, 'all'), ['foo', 'bar', null, true], 'have all of them');
var a = [];
set(obj, 'one', 0);
set(obj, 'three', a);
deepEqual(get(obj, 'all'), [0, 'bar', a, true], 'have all of them');
});
});
enifed('ember-runtime/tests/controllers/controller_test', ['ember-runtime/controllers/controller', 'ember-runtime/system/service', 'ember-metal', 'ember-runtime/system/object', 'ember-runtime/inject', 'internal-test-helpers'], function (_controller, _service, _emberMetal, _object, _inject, _internalTestHelpers) {
'use strict';
/* global EmberDev */
QUnit.module('Controller event handling');
QUnit.test('can access `actions` hash via `_actions` [DEPRECATED]', function () {
expect(2);
var controller = _controller.default.extend({
actions: {
foo: function () {
ok(true, 'called foo action');
}
}
}).create();
expectDeprecation(function () {
controller._actions.foo();
}, 'Usage of `_actions` is deprecated, use `actions` instead.');
});
QUnit.test('Action can be handled by a function on actions object', function () {
expect(1);
var TestController = _controller.default.extend({
actions: {
poke: function () {
ok(true, 'poked');
}
}
});
var controller = TestController.create();
controller.send('poke');
});
QUnit.test('A handled action can be bubbled to the target for continued processing', function () {
expect(2);
var TestController = _controller.default.extend({
actions: {
poke: function () {
ok(true, 'poked 1');
return true;
}
}
});
var controller = TestController.create({
target: _controller.default.extend({
actions: {
poke: function () {
ok(true, 'poked 2');
}
}
}).create()
});
controller.send('poke');
});
QUnit.test('Action can be handled by a superclass\' actions object', function () {
expect(4);
var SuperController = _controller.default.extend({
actions: {
foo: function () {
ok(true, 'foo');
},
bar: function (msg) {
equal(msg, 'HELLO');
}
}
});
var BarControllerMixin = _emberMetal.Mixin.create({
actions: {
bar: function (msg) {
equal(msg, 'HELLO');
this._super(msg);
}
}
});
var IndexController = SuperController.extend(BarControllerMixin, {
actions: {
baz: function () {
ok(true, 'baz');
}
}
});
var controller = IndexController.create({});
controller.send('foo');
controller.send('bar', 'HELLO');
controller.send('baz');
});
QUnit.module('Controller deprecations');
QUnit.module('Controller Content -> Model Alias');
QUnit.test('`model` is aliased as `content`', function () {
expect(1);
var controller = _controller.default.extend({
model: 'foo-bar'
}).create();
equal(controller.get('content'), 'foo-bar', 'content is an alias of model');
});
QUnit.test('`content` is moved to `model` when `model` is unset', function () {
expect(2);
var controller = void 0;
ignoreDeprecation(function () {
controller = _controller.default.extend({
content: 'foo-bar'
}).create();
});
equal(controller.get('model'), 'foo-bar', 'model is set properly');
equal(controller.get('content'), 'foo-bar', 'content is set properly');
});
QUnit.test('specifying `content` (without `model` specified) results in deprecation', function () {
expect(1);
expectDeprecation(function () {
_controller.default.extend({
content: 'foo-bar'
}).create();
}, 'Do not specify `content` on a Controller, use `model` instead.');
});
QUnit.test('specifying `content` (with `model` specified) does not result in deprecation', function () {
expect(3);
expectNoDeprecation();
var controller = _controller.default.extend({
content: 'foo-bar',
model: 'blammo'
}).create();
equal((0, _emberMetal.get)(controller, 'content'), 'foo-bar');
equal((0, _emberMetal.get)(controller, 'model'), 'blammo');
});
QUnit.module('Controller injected properties');
if (!EmberDev.runningProdBuild) {
QUnit.test('defining a controller on a non-controller should fail assertion', function () {
expectAssertion(function () {
var owner = (0, _internalTestHelpers.buildOwner)();
var AnObject = _object.default.extend({
foo: _inject.default.controller('bar')
});
owner.register('foo:main', AnObject);
expectDeprecation(function () {
owner._lookupFactory('foo:main');
}, /Using "_lookupFactory" is deprecated. Please use container.factoryFor instead./);
}, /Defining an injected controller property on a non-controller is not allowed./);
});
}
QUnit.test('controllers can be injected into controllers', function () {
var owner = (0, _internalTestHelpers.buildOwner)();
owner.register('controller:post', _controller.default.extend({
postsController: _inject.default.controller('posts')
}));
owner.register('controller:posts', _controller.default.extend());
var postController = owner.lookup('controller:post');
var postsController = owner.lookup('controller:posts');
equal(postsController, postController.get('postsController'), 'controller.posts is injected');
});
QUnit.test('services can be injected into controllers', function () {
var owner = (0, _internalTestHelpers.buildOwner)();
owner.register('controller:application', _controller.default.extend({
authService: _inject.default.service('auth')
}));
owner.register('service:auth', _service.default.extend());
var appController = owner.lookup('controller:application');
var authService = owner.lookup('service:auth');
equal(authService, appController.get('authService'), 'service.auth is injected');
});
});
enifed('ember-runtime/tests/core/compare_test', ['ember-runtime/utils', 'ember-runtime/system/object', 'ember-runtime/compare', 'ember-runtime/mixins/comparable'], function (_utils, _object, _compare, _comparable) {
'use strict';
var data = [];
var Comp = _object.default.extend(_comparable.default);
Comp.reopenClass({
compare: function (obj) {
return obj.get('val');
}
});
QUnit.module('Ember.compare()', {
setup: function () {
data[0] = null;
data[1] = false;
data[2] = true;
data[3] = -12;
data[4] = 3.5;
data[5] = 'a string';
data[6] = 'another string';
data[7] = 'last string';
data[8] = [1, 2];
data[9] = [1, 2, 3];
data[10] = [1, 3];
data[11] = { a: 'hash' };
data[12] = _object.default.create();
data[13] = function (a) {
return a;
};
data[14] = new Date('2012/01/01');
data[15] = new Date('2012/06/06');
}
});
QUnit.test('ordering should work', function () {
var suspect = void 0,
comparable = void 0,
failureMessage = void 0,
suspectIndex = void 0,
comparableIndex = void 0;
for (suspectIndex = 0; suspectIndex < data.length; suspectIndex++) {
suspect = data[suspectIndex];
equal((0, _compare.default)(suspect, suspect), 0, suspectIndex + ' should equal itself');
for (comparableIndex = suspectIndex + 1; comparableIndex < data.length; comparableIndex++) {
comparable = data[comparableIndex];
failureMessage = 'data[' + suspectIndex + '] (' + (0, _utils.typeOf)(suspect) + ') should be smaller than data[' + comparableIndex + '] (' + (0, _utils.typeOf)(comparable) + ')';
equal((0, _compare.default)(suspect, comparable), -1, failureMessage);
}
}
});
QUnit.test('comparables should return values in the range of -1, 0, 1', function () {
var negOne = Comp.create({
val: -1
});
var zero = Comp.create({
val: 0
});
var one = Comp.create({
val: 1
});
equal((0, _compare.default)(negOne, 'a'), -1, 'First item comparable - returns -1 (not negated)');
equal((0, _compare.default)(zero, 'b'), 0, 'First item comparable - returns 0 (not negated)');
equal((0, _compare.default)(one, 'c'), 1, 'First item comparable - returns 1 (not negated)');
equal((0, _compare.default)('a', negOne), 1, 'Second item comparable - returns -1 (negated)');
equal((0, _compare.default)('b', zero), 0, 'Second item comparable - returns 0 (negated)');
equal((0, _compare.default)('c', one), -1, 'Second item comparable - returns 1 (negated)');
});
});
enifed('ember-runtime/tests/core/copy_test', ['ember-runtime/copy'], function (_copy) {
'use strict';
QUnit.module('Ember Copy Method');
QUnit.test('Ember.copy null', function () {
equal((0, _copy.default)({ field: null }, true).field, null, 'null should still be null');
});
QUnit.test('Ember.copy date', function () {
var date = new Date(2014, 7, 22);
var dateCopy = (0, _copy.default)(date);
equal(date.getTime(), dateCopy.getTime(), 'dates should be equivalent');
});
QUnit.test('Ember.copy null prototype object', function () {
var obj = Object.create(null);
obj.foo = 'bar';
equal((0, _copy.default)(obj).foo, 'bar', 'bar should still be bar');
});
QUnit.test('Ember.copy Array', function () {
var array = [1, null, new Date(2015, 9, 9), 'four'];
var arrayCopy = (0, _copy.default)(array);
deepEqual(array, arrayCopy, 'array content cloned successfully in new array');
});
});
enifed('ember-runtime/tests/core/isEqual_test', ['ember-runtime/is-equal'], function (_isEqual) {
'use strict';
QUnit.module('isEqual');
QUnit.test('undefined and null', function () {
ok((0, _isEqual.default)(undefined, undefined), 'undefined is equal to undefined');
ok(!(0, _isEqual.default)(undefined, null), 'undefined is not equal to null');
ok((0, _isEqual.default)(null, null), 'null is equal to null');
ok(!(0, _isEqual.default)(null, undefined), 'null is not equal to undefined');
});
QUnit.test('strings should be equal', function () {
ok(!(0, _isEqual.default)('Hello', 'Hi'), 'different Strings are unequal');
ok((0, _isEqual.default)('Hello', 'Hello'), 'same Strings are equal');
});
QUnit.test('numericals should be equal', function () {
ok((0, _isEqual.default)(24, 24), 'same numbers are equal');
ok(!(0, _isEqual.default)(24, 21), 'different numbers are inequal');
});
QUnit.test('dates should be equal', function () {
ok((0, _isEqual.default)(new Date(1985, 7, 22), new Date(1985, 7, 22)), 'same dates are equal');
ok(!(0, _isEqual.default)(new Date(2014, 7, 22), new Date(1985, 7, 22)), 'different dates are not equal');
});
QUnit.test('array should be equal', function () {
// NOTE: We don't test for array contents -- that would be too expensive.
ok(!(0, _isEqual.default)([1, 2], [1, 2]), 'two array instances with the same values should not be equal');
ok(!(0, _isEqual.default)([1, 2], [1]), 'two array instances with different values should not be equal');
});
QUnit.test('first object implements isEqual should use it', function () {
ok((0, _isEqual.default)({
isEqual: function () {
return true;
}
}, null), 'should return true always');
var obj = {
isEqual: function () {
return false;
}
};
equal((0, _isEqual.default)(obj, obj), false, 'should return false because isEqual returns false');
});
});
enifed('ember-runtime/tests/core/is_array_test', ['ember-runtime/utils', 'ember-runtime/system/native_array', 'ember-runtime/system/array_proxy', 'ember-environment'], function (_utils, _native_array, _array_proxy, _emberEnvironment) {
'use strict';
QUnit.module('Ember Type Checking');
var global = undefined;
QUnit.test('Ember.isArray', function () {
var arrayProxy = _array_proxy.default.create({ content: (0, _native_array.A)() });
equal((0, _utils.isArray)([1, 2, 3]), true, '[1,2,3]');
equal((0, _utils.isArray)(23), false, '23');
equal((0, _utils.isArray)(['Hello', 'Hi']), true, '["Hello", "Hi"]');
equal((0, _utils.isArray)('Hello'), false, '"Hello"');
equal((0, _utils.isArray)({}), false, '{}');
equal((0, _utils.isArray)({ length: 12 }), true, '{ length: 12 }');
equal((0, _utils.isArray)({ length: 'yes' }), false, '{ length: "yes" }');
equal((0, _utils.isArray)(global), false, 'global');
equal((0, _utils.isArray)(function () {}), false, 'function() {}');
equal((0, _utils.isArray)(arrayProxy), true, '[]');
});
if (_emberEnvironment.environment.window && typeof _emberEnvironment.environment.window.FileList === 'function') {
QUnit.test('Ember.isArray(fileList)', function () {
var fileListElement = document.createElement('input');
fileListElement.type = 'file';
var fileList = fileListElement.files;
equal((0, _utils.isArray)(fileList), false, 'fileList');
});
}
});
enifed('ember-runtime/tests/core/is_empty_test', ['ember-metal', 'ember-runtime/system/array_proxy', 'ember-runtime/system/native_array'], function (_emberMetal, _array_proxy, _native_array) {
'use strict';
QUnit.module('Ember.isEmpty');
QUnit.test('Ember.isEmpty', function () {
var arrayProxy = _array_proxy.default.create({ content: (0, _native_array.A)() });
equal(true, (0, _emberMetal.isEmpty)(arrayProxy), 'for an ArrayProxy that has empty content');
});
});
enifed('ember-runtime/tests/core/type_of_test', ['ember-runtime/utils', 'ember-runtime/system/object', 'ember-environment'], function (_utils, _object, _emberEnvironment) {
'use strict';
QUnit.module('Ember Type Checking');
QUnit.test('Ember.typeOf', function () {
var MockedDate = function () {};
MockedDate.prototype = new Date();
var mockedDate = new MockedDate();
var date = new Date();
var error = new Error('boum');
var instance = _object.default.create({
method: function () {}
});
equal((0, _utils.typeOf)(), 'undefined', 'undefined');
equal((0, _utils.typeOf)(null), 'null', 'null');
equal((0, _utils.typeOf)('Cyril'), 'string', 'Cyril');
equal((0, _utils.typeOf)(101), 'number', '101');
equal((0, _utils.typeOf)(true), 'boolean', 'true');
equal((0, _utils.typeOf)([1, 2, 90]), 'array', '[1,2,90]');
equal((0, _utils.typeOf)(/abc/), 'regexp', '/abc/');
equal((0, _utils.typeOf)(date), 'date', 'new Date()');
equal((0, _utils.typeOf)(mockedDate), 'date', 'mocked date');
equal((0, _utils.typeOf)(error), 'error', 'error');
equal((0, _utils.typeOf)({ a: 'b' }), 'object', 'object');
equal((0, _utils.typeOf)(undefined), 'undefined', 'item of type undefined');
equal((0, _utils.typeOf)(null), 'null', 'item of type null');
equal((0, _utils.typeOf)([1, 2, 3]), 'array', 'item of type array');
equal((0, _utils.typeOf)({}), 'object', 'item of type object');
equal((0, _utils.typeOf)(instance), 'instance', 'item of type instance');
equal((0, _utils.typeOf)(instance.method), 'function', 'item of type function');
equal((0, _utils.typeOf)(_object.default.extend()), 'class', 'item of type class');
equal((0, _utils.typeOf)(new Error()), 'error', 'item of type error');
});
if (_emberEnvironment.environment.window && typeof _emberEnvironment.environment.window.FileList === 'function') {
QUnit.test('Ember.typeOf(fileList)', function () {
var fileListElement = document.createElement('input');
fileListElement.type = 'file';
var fileList = fileListElement.files;
equal((0, _utils.typeOf)(fileList), 'filelist', 'item of type filelist');
});
}
});
enifed('ember-runtime/tests/ext/function_test', ['ember-environment', 'ember-metal', 'internal-test-helpers', 'ember-runtime/system/object', 'ember-runtime/mixins/evented'], function (_emberEnvironment, _emberMetal, _internalTestHelpers, _object, _evented) {
'use strict';
QUnit.module('Function.prototype.observes() helper');
(0, _internalTestHelpers.testBoth)('global observer helper takes multiple params', function (get, set) {
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) {
ok('undefined' === typeof Function.prototype.observes, 'Function.prototype helper disabled');
return;
}
var MyMixin = _emberMetal.Mixin.create({
count: 0,
foo: function () {
set(this, 'count', get(this, 'count') + 1);
}.observes('bar', 'baz')
});
var obj = (0, _emberMetal.mixin)({}, MyMixin);
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj, 'bar', 'BAZ');
set(obj, 'baz', 'BAZ');
equal(get(obj, 'count'), 2, 'should invoke observer after change');
});
QUnit.module('Function.prototype.on() helper');
(0, _internalTestHelpers.testBoth)('sets up an event listener, and can trigger the function on multiple events', function (get, set) {
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) {
ok('undefined' === typeof Function.prototype.on, 'Function.prototype helper disabled');
return;
}
var MyMixin = _emberMetal.Mixin.create({
count: 0,
foo: function () {
set(this, 'count', get(this, 'count') + 1);
}.on('bar', 'baz')
});
var obj = (0, _emberMetal.mixin)({}, _evented.default, MyMixin);
equal(get(obj, 'count'), 0, 'should not invoke listener immediately');
obj.trigger('bar');
obj.trigger('baz');
equal(get(obj, 'count'), 2, 'should invoke listeners when events trigger');
});
(0, _internalTestHelpers.testBoth)('can be chained with observes', function (get, set) {
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) {
ok('Function.prototype helper disabled');
return;
}
var MyMixin = _emberMetal.Mixin.create({
count: 0,
bay: 'bay',
foo: function () {
set(this, 'count', get(this, 'count') + 1);
}.observes('bay').on('bar')
});
var obj = (0, _emberMetal.mixin)({}, _evented.default, MyMixin);
equal(get(obj, 'count'), 0, 'should not invoke listener immediately');
set(obj, 'bay', 'BAY');
obj.trigger('bar');
equal(get(obj, 'count'), 2, 'should invoke observer and listener');
});
QUnit.module('Function.prototype.property() helper');
(0, _internalTestHelpers.testBoth)('sets up a ComputedProperty', function (get, set) {
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.Function) {
ok('undefined' === typeof Function.prototype.property, 'Function.prototype helper disabled');
return;
}
var MyClass = _object.default.extend({
firstName: null,
lastName: null,
fullName: function () {
return get(this, 'firstName') + ' ' + get(this, 'lastName');
}.property('firstName', 'lastName')
});
var obj = MyClass.create({ firstName: 'Fred', lastName: 'Flinstone' });
equal(get(obj, 'fullName'), 'Fred Flinstone', 'should return the computed value');
set(obj, 'firstName', 'Wilma');
equal(get(obj, 'fullName'), 'Wilma Flinstone', 'should return the new computed value');
set(obj, 'lastName', '');
equal(get(obj, 'fullName'), 'Wilma ', 'should return the new computed value');
});
});
enifed('ember-runtime/tests/ext/mixin_test', ['ember-metal'], function (_emberMetal) {
'use strict';
QUnit.module('system/mixin/binding_test');
QUnit.test('Defining a property ending in Binding should setup binding when applied', function () {
var MyMixin = _emberMetal.Mixin.create({
fooBinding: 'bar.baz'
});
var obj = { bar: { baz: 'BIFF' } };
(0, _emberMetal.run)(function () {
var deprecationMessage = /`Ember.Binding` is deprecated/;
expectDeprecation(function () {
MyMixin.apply(obj);
}, deprecationMessage);
});
ok((0, _emberMetal.get)(obj, 'fooBinding') instanceof _emberMetal.Binding, 'should be a binding object');
equal((0, _emberMetal.get)(obj, 'foo'), 'BIFF', 'binding should be created and synced');
});
QUnit.test('Defining a property ending in Binding should apply to prototype children', function () {
var MyMixin = (0, _emberMetal.run)(function () {
return _emberMetal.Mixin.create({
fooBinding: 'bar.baz'
});
});
var obj = { bar: { baz: 'BIFF' } };
(0, _emberMetal.run)(function () {
var deprecationMessage = /`Ember.Binding` is deprecated/;
expectDeprecation(function () {
MyMixin.apply(obj);
}, deprecationMessage);
});
var obj2 = Object.create(obj);
(0, _emberMetal.run)(function () {
return (0, _emberMetal.set)((0, _emberMetal.get)(obj2, 'bar'), 'baz', 'BARG');
});
ok((0, _emberMetal.get)(obj2, 'fooBinding') instanceof _emberMetal.Binding, 'should be a binding object');
equal((0, _emberMetal.get)(obj2, 'foo'), 'BARG', 'binding should be created and synced');
});
});
enifed('ember-runtime/tests/ext/rsvp_test', ['ember-metal', 'ember-runtime/ext/rsvp', 'ember-debug'], function (_emberMetal, _rsvp, _emberDebug) {
'use strict';
var ORIGINAL_ONERROR = (0, _emberMetal.getOnerror)();
QUnit.module('Ember.RSVP', {
teardown: function () {
(0, _emberMetal.setOnerror)(ORIGINAL_ONERROR);
}
});
QUnit.test('Ensure that errors thrown from within a promise are sent to the console', function () {
var error = new Error('Error thrown in a promise for testing purposes.');
try {
(0, _emberMetal.run)(function () {
new _rsvp.default.Promise(function () {
throw error;
});
});
ok(false, 'expected assertion to be thrown');
} catch (e) {
equal(e, error, 'error was re-thrown');
}
});
QUnit.test('TransitionAborted errors are not re-thrown', function () {
expect(1);
(0, _emberMetal.run)(_rsvp.default, 'reject', { name: 'TransitionAborted' });
ok(true, 'did not throw an error when dealing with TransitionAborted');
});
QUnit.test('Can reject with non-Error object', function () {
var wasEmberTesting = (0, _emberDebug.isTesting)();
(0, _emberDebug.setTesting)(false);
expect(1);
try {
(0, _emberMetal.run)(_rsvp.default, 'reject', 'foo');
} catch (e) {
ok(false, 'should not throw');
} finally {
(0, _emberDebug.setTesting)(wasEmberTesting);
}
ok(true);
});
QUnit.test('Can reject with no arguments', function () {
var wasEmberTesting = (0, _emberDebug.isTesting)();
(0, _emberDebug.setTesting)(false);
expect(1);
try {
(0, _emberMetal.run)(_rsvp.default, 'reject');
} catch (e) {
ok(false, 'should not throw');
} finally {
(0, _emberDebug.setTesting)(wasEmberTesting);
}
ok(true);
});
QUnit.test('rejections like jqXHR which have errorThrown property work', function () {
expect(2);
var wasEmberTesting = (0, _emberDebug.isTesting)(),
actualError,
jqXHR;
var wasOnError = (0, _emberMetal.getOnerror)();
try {
(0, _emberDebug.setTesting)(false);
(0, _emberMetal.setOnerror)(function (error) {
equal(error, actualError, 'expected the real error on the jqXHR');
equal(error.__reason_with_error_thrown__, jqXHR, 'also retains a helpful reference to the rejection reason');
});
actualError = new Error('OMG what really happened');
jqXHR = {
errorThrown: actualError
};
(0, _emberMetal.run)(_rsvp.default, 'reject', jqXHR);
} finally {
(0, _emberMetal.setOnerror)(wasOnError);
(0, _emberDebug.setTesting)(wasEmberTesting);
}
});
QUnit.test('rejections where the errorThrown is a string should wrap the sting in an error object', function () {
expect(2);
var wasEmberTesting = (0, _emberDebug.isTesting)(),
actualError,
jqXHR;
var wasOnError = (0, _emberMetal.getOnerror)();
try {
(0, _emberDebug.setTesting)(false);
(0, _emberMetal.setOnerror)(function (error) {
equal(error.message, actualError, 'expected the real error on the jqXHR');
equal(error.__reason_with_error_thrown__, jqXHR, 'also retains a helpful reference to the rejection reason');
});
actualError = 'OMG what really happened';
jqXHR = {
errorThrown: actualError
};
(0, _emberMetal.run)(_rsvp.default, 'reject', jqXHR);
} finally {
(0, _emberMetal.setOnerror)(wasOnError);
(0, _emberDebug.setTesting)(wasEmberTesting);
}
});
QUnit.test('rejections can be serialized to JSON', function (assert) {
expect(2);
var wasEmberTesting = (0, _emberDebug.isTesting)(),
jqXHR;
var wasOnError = (0, _emberMetal.getOnerror)();
try {
(0, _emberDebug.setTesting)(false);
(0, _emberMetal.setOnerror)(function (error) {
assert.equal(error.message, 'a fail');
assert.ok(JSON.stringify(error), 'Error can be serialized');
});
jqXHR = {
errorThrown: new Error('a fail')
};
(0, _emberMetal.run)(_rsvp.default, 'reject', jqXHR);
} finally {
(0, _emberMetal.setOnerror)(wasOnError);
(0, _emberDebug.setTesting)(wasEmberTesting);
}
});
var reason = 'i failed';
QUnit.module('Ember.test: rejection assertions');
function ajax() {
return _rsvp.default.Promise(function (resolve) {
QUnit.stop();
setTimeout(function () {
QUnit.start();
resolve();
}, 0); // fake true / foreign async
});
}
QUnit.test('unambigiously unhandled rejection', function () {
QUnit.throws(function () {
(0, _emberMetal.run)(function () {
_rsvp.default.Promise.reject(reason);
}); // something is funky, we should likely assert
}, reason);
});
QUnit.test('sync handled', function () {
(0, _emberMetal.run)(function () {
_rsvp.default.Promise.reject(reason).catch(function () {});
}); // handled, we shouldn't need to assert.
ok(true, 'reached end of test');
});
QUnit.test('handled within the same micro-task (via Ember.RVP.Promise)', function () {
(0, _emberMetal.run)(function () {
var rejection = _rsvp.default.Promise.reject(reason);
_rsvp.default.Promise.resolve(1).then(function () {
return rejection.catch(function () {});
});
}); // handled, we shouldn't need to assert.
ok(true, 'reached end of test');
});
QUnit.test('handled within the same micro-task (via direct run-loop)', function () {
(0, _emberMetal.run)(function () {
var rejection = _rsvp.default.Promise.reject(reason);
_emberMetal.run.schedule('afterRender', function () {
return rejection.catch(function () {});
});
}); // handled, we shouldn't need to assert.
ok(true, 'reached end of test');
});
QUnit.test('handled in the next microTask queue flush (run.next)', function () {
expect(2);
QUnit.throws(function () {
(0, _emberMetal.run)(function () {
var rejection = _rsvp.default.Promise.reject(reason);
QUnit.stop();
_emberMetal.run.next(function () {
QUnit.start();
rejection.catch(function () {});
ok(true, 'reached end of test');
});
});
}, reason);
// a promise rejection survived a full flush of the run-loop without being handled
// this is very likely an issue.
});
QUnit.test('handled in the same microTask Queue flush do to data locality', function () {
// an ambiguous scenario, this may or may not assert
// it depends on the locality of `user#1`
var store = {
find: function () {
return _rsvp.default.Promise.resolve(1);
}
};
(0, _emberMetal.run)(function () {
var rejection = _rsvp.default.Promise.reject(reason);
store.find('user', 1).then(function () {
return rejection.catch(function () {});
});
});
ok(true, 'reached end of test');
});
QUnit.test('handled in a different microTask Queue flush do to data locality', function () {
// an ambiguous scenario, this may or may not assert
// it depends on the locality of `user#1`
var store = {
find: function () {
return ajax();
}
};
QUnit.throws(function () {
(0, _emberMetal.run)(function () {
var rejection = _rsvp.default.Promise.reject(reason);
store.find('user', 1).then(function () {
rejection.catch(function () {});
ok(true, 'reached end of test');
});
});
}, reason);
});
QUnit.test('handled in the next microTask queue flush (ajax example)', function () {
QUnit.throws(function () {
(0, _emberMetal.run)(function () {
var rejection = _rsvp.default.Promise.reject(reason);
ajax('/something/').then(function () {
rejection.catch(function () {});
ok(true, 'reached end of test');
});
});
}, reason);
});
});
enifed('ember-runtime/tests/inject_test', ['ember-metal', 'ember-runtime/inject', 'ember-runtime/system/object', 'internal-test-helpers'], function (_emberMetal, _inject, _object, _internalTestHelpers) {
'use strict';
QUnit.module('inject'); /* global EmberDev */
QUnit.test('calling `inject` directly should error', function () {
expectAssertion(function () {
(0, _inject.default)('foo');
}, /Injected properties must be created through helpers/);
});
if (!EmberDev.runningProdBuild) {
// this check is done via an assertion which is stripped from
// production builds
QUnit.test('injection type validation is run when first looked up', function () {
(0, _inject.createInjectionHelper)('foo', function () {
ok(true, 'should call validation method');
});
var owner = (0, _internalTestHelpers.buildOwner)();
var AnObject = _object.default.extend({
bar: _inject.default.foo(),
baz: _inject.default.foo()
});
owner.register('foo:main', AnObject);
expect(2);
expectDeprecation(function () {
owner._lookupFactory('foo:main');
}, /Using "_lookupFactory" is deprecated. Please use container.factoryFor instead./);
});
QUnit.test('attempting to inject a nonexistent container key should error', function () {
var owner = (0, _internalTestHelpers.buildOwner)();
var AnObject = _object.default.extend({
foo: new _emberMetal.InjectedProperty('bar', 'baz')
});
owner.register('foo:main', AnObject);
throws(function () {
owner.lookup('foo:main');
}, /Attempting to inject an unknown injection: 'bar:baz'/);
});
}
QUnit.test('factories should return a list of lazy injection full names', function () {
var AnObject = _object.default.extend({
foo: new _emberMetal.InjectedProperty('foo', 'bar'),
bar: new _emberMetal.InjectedProperty('quux')
});
deepEqual(AnObject._lazyInjections(), { 'foo': 'foo:bar', 'bar': 'quux:bar' }, 'should return injected container keys');
});
});
enifed('ember-runtime/tests/legacy_1x/mixins/observable/chained_test', ['ember-metal', 'ember-runtime/system/object', 'ember-runtime/system/native_array'], function (_emberMetal, _object, _native_array) {
'use strict';
/*
NOTE: This test is adapted from the 1.x series of unit tests. The tests
are the same except for places where we intend to break the API we instead
validate that we warn the developer appropriately.
CHANGES FROM 1.6:
* changed obj.set() and obj.get() to Ember.set() and Ember.get()
* changed obj.addObserver() to addObserver()
*/
QUnit.module('Ember.Observable - Observing with @each');
QUnit.test('chained observers on enumerable properties are triggered when the observed property of any item changes', function () {
var family = _object.default.create({ momma: null });
var momma = _object.default.create({ children: [] });
var child1 = _object.default.create({ name: 'Bartholomew' });
var child2 = _object.default.create({ name: 'Agnes' });
var child3 = _object.default.create({ name: 'Dan' });
var child4 = _object.default.create({ name: 'Nancy' });
(0, _emberMetal.set)(family, 'momma', momma);
(0, _emberMetal.set)(momma, 'children', (0, _native_array.A)([child1, child2, child3]));
var observerFiredCount = 0;
(0, _emberMetal.addObserver)(family, 'momma.children.@each.name', this, function () {
observerFiredCount++;
});
observerFiredCount = 0;
(0, _emberMetal.run)(function () {
return (0, _emberMetal.get)(momma, 'children').setEach('name', 'Juan');
});
equal(observerFiredCount, 3, 'observer fired after changing child names');
observerFiredCount = 0;
(0, _emberMetal.run)(function () {
return (0, _emberMetal.get)(momma, 'children').pushObject(child4);
});
equal(observerFiredCount, 1, 'observer fired after adding a new item');
observerFiredCount = 0;
(0, _emberMetal.run)(function () {
return (0, _emberMetal.set)(child4, 'name', 'Herbert');
});
equal(observerFiredCount, 1, 'observer fired after changing property on new object');
(0, _emberMetal.set)(momma, 'children', []);
observerFiredCount = 0;
(0, _emberMetal.run)(function () {
return (0, _emberMetal.set)(child1, 'name', 'Hanna');
});
equal(observerFiredCount, 0, 'observer did not fire after removing changing property on a removed object');
});
});
enifed('ember-runtime/tests/legacy_1x/mixins/observable/observable_test', ['ember-environment', 'ember-metal', 'ember-runtime/system/string', 'ember-runtime/system/object', 'ember-runtime/mixins/observable', 'ember-runtime/system/native_array'], function (_emberEnvironment, _emberMetal, _string, _object, _observable, _native_array) {
'use strict';
/*
NOTE: This test is adapted from the 1.x series of unit tests. The tests
are the same except for places where we intend to break the API we instead
validate that we warn the developer appropriately.
CHANGES FROM 1.6:
* Added ObservableObject which applies the Ember.Observable mixin.
* Changed reference to Ember.T_FUNCTION to 'function'
* Changed all references to sc_super to this._super(...arguments)
* Changed Ember.objectForPropertyPath() to Ember.getPath()
* Removed allPropertiesDidChange test - no longer supported
* Changed test that uses 'ObjectE' as path to 'objectE' to reflect new
rule on using capital letters for property paths.
* Removed test passing context to addObserver. context param is no longer
supported.
* Changed calls to Ember.Binding.flushPendingChanges() -> run.sync()
* removed test in observer around line 862 that expected key/value to be
the last item in the chained path. Should be root and chained path
*/
// ========================================================================
// Ember.Observable Tests
// ========================================================================
var object, ObjectC, ObjectD, objectA, objectB, lookup;
var ObservableObject = _object.default.extend(_observable.default);
var originalLookup = _emberEnvironment.context.lookup;
// ..........................................................
// GET()
//
QUnit.module('object.get()', {
setup: function () {
object = ObservableObject.extend(_observable.default, {
computed: (0, _emberMetal.computed)(function () {
return 'value';
}).volatile(),
method: function () {
return 'value';
},
unknownProperty: function (key) {
this.lastUnknownProperty = key;
return 'unknown';
}
}).create({
normal: 'value',
numberVal: 24,
toggleVal: true,
nullProperty: null
});
}
});
QUnit.test('should get normal properties', function () {
equal(object.get('normal'), 'value');
});
QUnit.test('should call computed properties and return their result', function () {
equal(object.get('computed'), 'value');
});
QUnit.test('should return the function for a non-computed property', function () {
var value = object.get('method');
equal(typeof value, 'function');
});
QUnit.test('should return null when property value is null', function () {
equal(object.get('nullProperty'), null);
});
QUnit.test('should call unknownProperty when value is undefined', function () {
equal(object.get('unknown'), 'unknown');
equal(object.lastUnknownProperty, 'unknown');
});
// ..........................................................
// Ember.GET()
//
QUnit.module('Ember.get()', {
setup: function () {
objectA = ObservableObject.extend({
computed: (0, _emberMetal.computed)(function () {
return 'value';
}).volatile(),
method: function () {
return 'value';
},
unknownProperty: function (key) {
this.lastUnknownProperty = key;
return 'unknown';
}
}).create({
normal: 'value',
numberVal: 24,
toggleVal: true,
nullProperty: null
});
objectB = {
normal: 'value',
nullProperty: null
};
}
});
QUnit.test('should get normal properties on Ember.Observable', function () {
equal((0, _emberMetal.get)(objectA, 'normal'), 'value');
});
QUnit.test('should call computed properties on Ember.Observable and return their result', function () {
equal((0, _emberMetal.get)(objectA, 'computed'), 'value');
});
QUnit.test('should return the function for a non-computed property on Ember.Observable', function () {
var value = (0, _emberMetal.get)(objectA, 'method');
equal(typeof value, 'function');
});
QUnit.test('should return null when property value is null on Ember.Observable', function () {
equal((0, _emberMetal.get)(objectA, 'nullProperty'), null);
});
QUnit.test('should call unknownProperty when value is undefined on Ember.Observable', function () {
equal((0, _emberMetal.get)(objectA, 'unknown'), 'unknown');
equal(objectA.lastUnknownProperty, 'unknown');
});
QUnit.test('should get normal properties on standard objects', function () {
equal((0, _emberMetal.get)(objectB, 'normal'), 'value');
});
QUnit.test('should return null when property is null on standard objects', function () {
equal((0, _emberMetal.get)(objectB, 'nullProperty'), null);
});
/*
QUnit.test("raise if the provided object is null", function() {
throws(function() {
get(null, 'key');
});
});
*/
QUnit.test('raise if the provided object is undefined', function () {
expectAssertion(function () {
(0, _emberMetal.get)(undefined, 'key');
}, /Cannot call get with 'key' on an undefined object/i);
});
QUnit.module('Ember.get() with paths');
QUnit.test('should return a property at a given path relative to the passed object', function () {
var foo = ObservableObject.create({
bar: ObservableObject.extend({
baz: (0, _emberMetal.computed)(function () {
return 'blargh';
}).volatile()
}).create()
});
equal((0, _emberMetal.get)(foo, 'bar.baz'), 'blargh');
});
QUnit.test('should return a property at a given path relative to the passed object - JavaScript hash', function () {
equal((0, _emberMetal.get)({
bar: {
baz: 'blargh'
}
}, 'bar.baz'), 'blargh');
});
// ..........................................................
// SET()
//
QUnit.module('object.set()', {
setup: function () {
object = ObservableObject.extend({
computed: (0, _emberMetal.computed)({
get: function () {
return this._computed;
},
set: function (key, value) {
this._computed = value;
return this._computed;
}
}).volatile(),
method: function (key, value) {
if (value !== undefined) {
this._method = value;
}
return this._method;
},
unknownProperty: function () {
return this._unknown;
},
setUnknownProperty: function (key, value) {
this._unknown = value;
return this._unknown;
},
// normal property
normal: 'value',
// computed property
_computed: 'computed',
// method, but not a property
_method: 'method',
// null property
nullProperty: null,
// unknown property
_unknown: 'unknown'
}).create();
}
});
QUnit.test('should change normal properties and return the value', function () {
var ret = object.set('normal', 'changed');
equal(object.get('normal'), 'changed');
equal(ret, 'changed');
});
QUnit.test('should call computed properties passing value and return the value', function () {
var ret = object.set('computed', 'changed');
equal(object.get('_computed'), 'changed');
equal(ret, 'changed');
});
QUnit.test('should change normal properties when passing undefined', function () {
var ret = object.set('normal', undefined);
equal(object.get('normal'), undefined);
equal(ret, undefined);
});
QUnit.test('should replace the function for a non-computed property and return the value', function () {
var ret = object.set('method', 'changed');
equal(object.get('_method'), 'method'); // make sure this was NOT run
ok(typeof object.get('method') !== 'function');
equal(ret, 'changed');
});
QUnit.test('should replace prover when property value is null', function () {
var ret = object.set('nullProperty', 'changed');
equal(object.get('nullProperty'), 'changed');
equal(ret, 'changed');
});
QUnit.test('should call unknownProperty with value when property is undefined', function () {
var ret = object.set('unknown', 'changed');
equal(object.get('_unknown'), 'changed');
equal(ret, 'changed');
});
// ..........................................................
// COMPUTED PROPERTIES
//
QUnit.module('Computed properties', {
setup: function () {
lookup = _emberEnvironment.context.lookup = {};
object = ObservableObject.extend({
computed: (0, _emberMetal.computed)({
get: function () {
this.computedCalls.push('getter-called');
return 'computed';
},
set: function (key, value) {
this.computedCalls.push(value);
}
}).volatile(),
computedCached: (0, _emberMetal.computed)({
get: function () {
this.computedCachedCalls.push('getter-called');
return 'computedCached';
},
set: function (key, value) {
this.computedCachedCalls.push(value);
}
}),
dependent: (0, _emberMetal.computed)({
get: function () {
this.dependentCalls.push('getter-called');
return 'dependent';
},
set: function (key, value) {
this.dependentCalls.push(value);
}
}).property('changer').volatile(),
dependentFront: (0, _emberMetal.computed)('changer', {
get: function () {
this.dependentFrontCalls.push('getter-called');
return 'dependentFront';
},
set: function (key, value) {
this.dependentFrontCalls.push(value);
}
}).volatile(),
dependentCached: (0, _emberMetal.computed)({
get: function () {
this.dependentCachedCalls.push('getter-called!');
return 'dependentCached';
},
set: function (key, value) {
this.dependentCachedCalls.push(value);
}
}).property('changer'),
inc: (0, _emberMetal.computed)('changer', function () {
return this.incCallCount++;
}),
nestedInc: (0, _emberMetal.computed)(function () {
(0, _emberMetal.get)(this, 'inc');
return this.nestedIncCallCount++;
}).property('inc'),
isOn: (0, _emberMetal.computed)({
get: function () {
return this.get('state') === 'on';
},
set: function () {
this.set('state', 'on');
return this.get('state') === 'on';
}
}).property('state').volatile(),
isOff: (0, _emberMetal.computed)({
get: function () {
return this.get('state') === 'off';
},
set: function () {
this.set('state', 'off');
return this.get('state') === 'off';
}
}).property('state').volatile()
}).create({
computedCalls: [],
computedCachedCalls: [],
changer: 'foo',
dependentCalls: [],
dependentFrontCalls: [],
dependentCachedCalls: [],
incCallCount: 0,
nestedIncCallCount: 0,
state: 'on'
});
},
teardown: function () {
_emberEnvironment.context.lookup = originalLookup;
}
});
QUnit.test('getting values should call function return value', function () {
// get each property twice. Verify return.
var keys = (0, _string.w)('computed computedCached dependent dependentFront dependentCached');
keys.forEach(function (key) {
equal(object.get(key), key, 'Try #1: object.get(' + key + ') should run function');
equal(object.get(key), key, 'Try #2: object.get(' + key + ') should run function');
});
// verify each call count. cached should only be called once
(0, _string.w)('computedCalls dependentFrontCalls dependentCalls').forEach(function (key) {
equal(object[key].length, 2, 'non-cached property ' + key + ' should be called 2x');
});
(0, _string.w)('computedCachedCalls dependentCachedCalls').forEach(function (key) {
equal(object[key].length, 1, 'non-cached property ' + key + ' should be called 1x');
});
});
QUnit.test('setting values should call function return value', function () {
// get each property twice. Verify return.
var keys = (0, _string.w)('computed dependent dependentFront computedCached dependentCached');
var values = (0, _string.w)('value1 value2');
keys.forEach(function (key) {
equal(object.set(key, values[0]), values[0], 'Try #1: object.set(' + key + ', ' + values[0] + ') should run function');
equal(object.set(key, values[1]), values[1], 'Try #2: object.set(' + key + ', ' + values[1] + ') should run function');
equal(object.set(key, values[1]), values[1], 'Try #3: object.set(' + key + ', ' + values[1] + ') should not run function since it is setting same value as before');
});
// verify each call count. cached should only be called once
keys.forEach(function (key) {
var calls = object[key + 'Calls'];
var idx, expectedLength;
// Cached properties first check their cached value before setting the
// property. Other properties blindly call set.
expectedLength = 3;
equal(calls.length, expectedLength, 'set(' + key + ') should be called the right amount of times');
for (idx = 0; idx < 2; idx++) {
equal(calls[idx], values[idx], 'call #' + (idx + 1) + ' to set(' + key + ') should have passed value ' + values[idx]);
}
});
});
QUnit.test('notify change should clear cache', function () {
// call get several times to collect call count
object.get('computedCached'); // should run func
object.get('computedCached'); // should not run func
object.propertyWillChange('computedCached').propertyDidChange('computedCached');
object.get('computedCached'); // should run again
equal(object.computedCachedCalls.length, 2, 'should have invoked method 2x');
});
QUnit.test('change dependent should clear cache', function () {
// call get several times to collect call count
var ret1 = object.get('inc'); // should run func
equal(object.get('inc'), ret1, 'multiple calls should not run cached prop');
object.set('changer', 'bar');
equal(object.get('inc'), ret1 + 1, 'should increment after dependent key changes'); // should run again
});
QUnit.test('just notifying change of dependent should clear cache', function () {
// call get several times to collect call count
var ret1 = object.get('inc'); // should run func
equal(object.get('inc'), ret1, 'multiple calls should not run cached prop');
object.notifyPropertyChange('changer');
equal(object.get('inc'), ret1 + 1, 'should increment after dependent key changes'); // should run again
});
QUnit.test('changing dependent should clear nested cache', function () {
// call get several times to collect call count
var ret1 = object.get('nestedInc'); // should run func
equal(object.get('nestedInc'), ret1, 'multiple calls should not run cached prop');
object.set('changer', 'bar');
equal(object.get('nestedInc'), ret1 + 1, 'should increment after dependent key changes'); // should run again
});
QUnit.test('just notifying change of dependent should clear nested cache', function () {
// call get several times to collect call count
var ret1 = object.get('nestedInc'); // should run func
equal(object.get('nestedInc'), ret1, 'multiple calls should not run cached prop');
object.notifyPropertyChange('changer');
equal(object.get('nestedInc'), ret1 + 1, 'should increment after dependent key changes'); // should run again
});
// This verifies a specific bug encountered where observers for computed
// properties would fire before their prop caches were cleared.
QUnit.test('change dependent should clear cache when observers of dependent are called', function () {
// call get several times to collect call count
var ret1 = object.get('inc'); // should run func
equal(object.get('inc'), ret1, 'multiple calls should not run cached prop');
// add observer to verify change...
object.addObserver('inc', this, function () {
equal(object.get('inc'), ret1 + 1, 'should increment after dependent key changes'); // should run again
});
// now run
object.set('changer', 'bar');
});
QUnit.test('setting one of two computed properties that depend on a third property should clear the kvo cache', function () {
// we have to call set twice to fill up the cache
object.set('isOff', true);
object.set('isOn', true);
// setting isOff to true should clear the kvo cache
object.set('isOff', true);
equal(object.get('isOff'), true, 'object.isOff should be true');
equal(object.get('isOn'), false, 'object.isOn should be false');
});
QUnit.test('dependent keys should be able to be specified as property paths', function () {
var depObj = ObservableObject.extend({
menuPrice: (0, _emberMetal.computed)(function () {
return this.get('menu.price');
}).property('menu.price')
}).create({
menu: ObservableObject.create({
price: 5
})
});
equal(depObj.get('menuPrice'), 5, 'precond - initial value returns 5');
depObj.set('menu.price', 6);
equal(depObj.get('menuPrice'), 6, 'cache is properly invalidated after nested property changes');
});
QUnit.test('nested dependent keys should propagate after they update', function () {
var bindObj;
(0, _emberMetal.run)(function () {
lookup.DepObj = ObservableObject.extend({
price: (0, _emberMetal.computed)(function () {
return this.get('restaurant.menu.price');
}).property('restaurant.menu.price')
}).create({
restaurant: ObservableObject.create({
menu: ObservableObject.create({
price: 5
})
})
});
expectDeprecation(function () {
bindObj = ObservableObject.extend({
priceBinding: 'DepObj.price'
}).create();
}, /`Ember.Binding` is deprecated/);
});
equal(bindObj.get('price'), 5, 'precond - binding propagates');
(0, _emberMetal.run)(function () {
lookup.DepObj.set('restaurant.menu.price', 10);
});
equal(bindObj.get('price'), 10, 'binding propagates after a nested dependent keys updates');
(0, _emberMetal.run)(function () {
lookup.DepObj.set('restaurant.menu', ObservableObject.create({
price: 15
}));
});
equal(bindObj.get('price'), 15, 'binding propagates after a middle dependent keys updates');
});
QUnit.test('cacheable nested dependent keys should clear after their dependencies update', function () {
ok(true);
var DepObj;
(0, _emberMetal.run)(function () {
lookup.DepObj = DepObj = ObservableObject.extend({
price: (0, _emberMetal.computed)('restaurant.menu.price', function () {
return this.get('restaurant.menu.price');
})
}).create({
restaurant: ObservableObject.create({
menu: ObservableObject.create({
price: 5
})
})
});
});
equal(DepObj.get('price'), 5, 'precond - computed property is correct');
(0, _emberMetal.run)(function () {
DepObj.set('restaurant.menu.price', 10);
});
equal(DepObj.get('price'), 10, 'cacheable computed properties are invalidated even if no run loop occurred');
(0, _emberMetal.run)(function () {
DepObj.set('restaurant.menu.price', 20);
});
equal(DepObj.get('price'), 20, 'cacheable computed properties are invalidated after a second get before a run loop');
equal(DepObj.get('price'), 20, 'precond - computed properties remain correct after a run loop');
(0, _emberMetal.run)(function () {
DepObj.set('restaurant.menu', ObservableObject.create({
price: 15
}));
});
equal(DepObj.get('price'), 15, 'cacheable computed properties are invalidated after a middle property changes');
(0, _emberMetal.run)(function () {
DepObj.set('restaurant.menu', ObservableObject.create({
price: 25
}));
});
equal(DepObj.get('price'), 25, 'cacheable computed properties are invalidated after a middle property changes again, before a run loop');
});
// ..........................................................
// OBSERVABLE OBJECTS
//
QUnit.module('Observable objects & object properties ', {
setup: function () {
object = ObservableObject.extend({
getEach: function () {
var keys = ['normal', 'abnormal'],
idx;
var ret = [];
for (idx = 0; idx < keys.length; idx++) {
ret[ret.length] = this.get(keys[idx]);
}
return ret;
},
newObserver: function () {
this.abnormal = 'changedValueObserved';
},
testObserver: (0, _emberMetal.observer)('normal', function () {
this.abnormal = 'removedObserver';
}),
testArrayObserver: (0, _emberMetal.observer)('normalArray.[]', function () {
this.abnormal = 'notifiedObserver';
})
}).create({
normal: 'value',
abnormal: 'zeroValue',
numberVal: 24,
toggleVal: true,
observedProperty: 'beingWatched',
testRemove: 'observerToBeRemoved',
normalArray: (0, _native_array.A)([1, 2, 3, 4, 5])
});
}
});
QUnit.test('incrementProperty and decrementProperty', function () {
var newValue = object.incrementProperty('numberVal');
equal(25, newValue, 'numerical value incremented');
object.numberVal = 24;
newValue = object.decrementProperty('numberVal');
equal(23, newValue, 'numerical value decremented');
object.numberVal = 25;
newValue = object.incrementProperty('numberVal', 5);
equal(30, newValue, 'numerical value incremented by specified increment');
object.numberVal = 25;
newValue = object.incrementProperty('numberVal', -5);
equal(20, newValue, 'minus numerical value incremented by specified increment');
object.numberVal = 25;
newValue = object.incrementProperty('numberVal', 0);
equal(25, newValue, 'zero numerical value incremented by specified increment');
expectAssertion(function () {
newValue = object.incrementProperty('numberVal', 0 - void 0); // Increment by NaN
}, /Must pass a numeric value to incrementProperty/i);
expectAssertion(function () {
newValue = object.incrementProperty('numberVal', 'Ember'); // Increment by non-numeric String
}, /Must pass a numeric value to incrementProperty/i);
expectAssertion(function () {
newValue = object.incrementProperty('numberVal', 1 / 0); // Increment by Infinity
}, /Must pass a numeric value to incrementProperty/i);
equal(25, newValue, 'Attempting to increment by non-numeric values should not increment value');
object.numberVal = 25;
newValue = object.decrementProperty('numberVal', 5);
equal(20, newValue, 'numerical value decremented by specified increment');
object.numberVal = 25;
newValue = object.decrementProperty('numberVal', -5);
equal(30, newValue, 'minus numerical value decremented by specified increment');
object.numberVal = 25;
newValue = object.decrementProperty('numberVal', 0);
equal(25, newValue, 'zero numerical value decremented by specified increment');
expectAssertion(function () {
newValue = object.decrementProperty('numberVal', 0 - void 0); // Decrement by NaN
}, /Must pass a numeric value to decrementProperty/i);
expectAssertion(function () {
newValue = object.decrementProperty('numberVal', 'Ember'); // Decrement by non-numeric String
}, /Must pass a numeric value to decrementProperty/i);
expectAssertion(function () {
newValue = object.decrementProperty('numberVal', 1 / 0); // Decrement by Infinity
}, /Must pass a numeric value to decrementProperty/i);
equal(25, newValue, 'Attempting to decrement by non-numeric values should not decrement value');
});
QUnit.test('toggle function, should be boolean', function () {
equal(object.toggleProperty('toggleVal', true, false), object.get('toggleVal'));
equal(object.toggleProperty('toggleVal', true, false), object.get('toggleVal'));
equal(object.toggleProperty('toggleVal', undefined, undefined), object.get('toggleVal'));
});
QUnit.test('should notify array observer when array changes', function () {
(0, _emberMetal.get)(object, 'normalArray').replace(0, 0, 6);
equal(object.abnormal, 'notifiedObserver', 'observer should be notified');
});
QUnit.module('object.addObserver()', {
setup: function () {
ObjectC = ObservableObject.create({
objectE: ObservableObject.create({
propertyVal: 'chainedProperty'
}),
normal: 'value',
normal1: 'zeroValue',
normal2: 'dependentValue',
incrementor: 10,
action: function () {
this.normal1 = 'newZeroValue';
},
observeOnceAction: function () {
this.incrementor = this.incrementor + 1;
},
chainedObserver: function () {
this.normal2 = 'chainedPropertyObserved';
}
});
}
});
QUnit.test('should register an observer for a property', function () {
ObjectC.addObserver('normal', ObjectC, 'action');
ObjectC.set('normal', 'newValue');
equal(ObjectC.normal1, 'newZeroValue');
});
QUnit.test('should register an observer for a property - Special case of chained property', function () {
ObjectC.addObserver('objectE.propertyVal', ObjectC, 'chainedObserver');
ObjectC.objectE.set('propertyVal', 'chainedPropertyValue');
equal('chainedPropertyObserved', ObjectC.normal2);
ObjectC.normal2 = 'dependentValue';
ObjectC.set('objectE', '');
equal('chainedPropertyObserved', ObjectC.normal2);
});
QUnit.module('object.removeObserver()', {
setup: function () {
ObjectD = ObservableObject.create({
objectF: ObservableObject.create({
propertyVal: 'chainedProperty'
}),
normal: 'value',
normal1: 'zeroValue',
normal2: 'dependentValue',
ArrayKeys: ['normal', 'normal1'],
addAction: function () {
this.normal1 = 'newZeroValue';
},
removeAction: function () {
this.normal2 = 'newDependentValue';
},
removeChainedObserver: function () {
this.normal2 = 'chainedPropertyObserved';
},
observableValue: 'hello world',
observer1: function () {
// Just an observer
},
observer2: function () {
this.removeObserver('observableValue', null, 'observer1');
this.removeObserver('observableValue', null, 'observer2');
this.hasObserverFor('observableValue'); // Tickle 'getMembers()'
this.removeObserver('observableValue', null, 'observer3');
},
observer3: function () {
// Just an observer
}
});
}
});
QUnit.test('should unregister an observer for a property', function () {
ObjectD.addObserver('normal', ObjectD, 'addAction');
ObjectD.set('normal', 'newValue');
equal(ObjectD.normal1, 'newZeroValue');
ObjectD.set('normal1', 'zeroValue');
ObjectD.removeObserver('normal', ObjectD, 'addAction');
ObjectD.set('normal', 'newValue');
equal(ObjectD.normal1, 'zeroValue');
});
QUnit.test('should unregister an observer for a property - special case when key has a \'.\' in it.', function () {
ObjectD.addObserver('objectF.propertyVal', ObjectD, 'removeChainedObserver');
ObjectD.objectF.set('propertyVal', 'chainedPropertyValue');
ObjectD.removeObserver('objectF.propertyVal', ObjectD, 'removeChainedObserver');
ObjectD.normal2 = 'dependentValue';
ObjectD.objectF.set('propertyVal', 'removedPropertyValue');
equal('dependentValue', ObjectD.normal2);
ObjectD.set('objectF', '');
equal('dependentValue', ObjectD.normal2);
});
QUnit.test('removing an observer inside of an observer shouldn’t cause any problems', function () {
// The observable system should be protected against clients removing
// observers in the middle of observer notification.
var encounteredError = false;
try {
ObjectD.addObserver('observableValue', null, 'observer1');
ObjectD.addObserver('observableValue', null, 'observer2');
ObjectD.addObserver('observableValue', null, 'observer3');
(0, _emberMetal.run)(function () {
ObjectD.set('observableValue', 'hi world');
});
} catch (e) {
encounteredError = true;
}
equal(encounteredError, false);
});
QUnit.module('Bind function', {
setup: function () {
objectA = ObservableObject.create({
name: 'Sproutcore',
location: 'Timbaktu'
});
objectB = ObservableObject.create({
normal: 'value',
computed: function () {
this.normal = 'newValue';
}
});
lookup = _emberEnvironment.context.lookup = {
'Namespace': {
objectA: objectA,
objectB: objectB
}
};
},
teardown: function () {
_emberEnvironment.context.lookup = originalLookup;
}
});
QUnit.test('should bind property with method parameter as undefined', function () {
// creating binding
(0, _emberMetal.run)(function () {
expectDeprecation(function () {
objectA.bind('name', 'Namespace.objectB.normal', undefined);
}, /`Ember.Binding` is deprecated/);
});
// now make a change to see if the binding triggers.
(0, _emberMetal.run)(function () {
objectB.set('normal', 'changedValue');
});
// support new-style bindings if available
equal('changedValue', objectA.get('name'), 'objectA.name is bound');
});
// ..........................................................
// SPECIAL CASES
//
QUnit.test('changing chained observer object to null should not raise exception', function () {
var obj = ObservableObject.create({
foo: ObservableObject.create({
bar: ObservableObject.create({ bat: 'BAT' })
})
});
var callCount = 0;
obj.foo.addObserver('bar.bat', obj, function () {
callCount++;
});
(0, _emberMetal.run)(function () {
obj.foo.set('bar', null);
});
equal(callCount, 1, 'changing bar should trigger observer');
expect(1);
});
});
enifed('ember-runtime/tests/legacy_1x/mixins/observable/observersForKey_test', ['ember-metal', 'ember-runtime/system/object', 'ember-runtime/mixins/observable'], function (_emberMetal, _object, _observable) {
'use strict';
var ObservableObject = _object.default.extend(_observable.default);
// ..........................................................
// GET()
//
/*
NOTE: This test is adapted from the 1.x series of unit tests. The tests
are the same except for places where we intend to break the API we instead
validate that we warn the developer appropriately.
CHANGES FROM 1.6:
* Create ObservableObject which includes Ember.Observable
*/
// ========================================================================
// Ember.Observable Tests
// ========================================================================
QUnit.module('object.observesForKey()');
QUnit.test('should get observers', function () {
var o1 = ObservableObject.create({ foo: 100 });
var o2 = ObservableObject.create({
func: function () {}
});
var o3 = ObservableObject.create({
func: function () {}
});
var observers = null;
equal((0, _emberMetal.get)(o1.observersForKey('foo'), 'length'), 0, 'o1.observersForKey should return empty array');
o1.addObserver('foo', o2, o2.func);
o1.addObserver('foo', o3, o3.func);
observers = o1.observersForKey('foo');
equal((0, _emberMetal.get)(observers, 'length'), 2, 'o2.observersForKey should return an array with length 2');
equal(observers[0][0], o2, 'first item in observers array should be o2');
equal(observers[1][0], o3, 'second item in observers array should be o3');
});
});
enifed('ember-runtime/tests/legacy_1x/mixins/observable/propertyChanges_test', ['ember-runtime/system/object', 'ember-runtime/mixins/observable', 'ember-metal'], function (_object, _observable, _emberMetal) {
'use strict';
var ObservableObject = _object.default.extend(_observable.default); /*
NOTE: This test is adapted from the 1.x series of unit tests. The tests
are the same except for places where we intend to break the API we instead
validate that we warn the developer appropriately.
CHANGES FROM 1.6:
* Create ObservableObject which includes Ember.Observable
* Remove test that tests internal _kvo_changeLevel property. This is an
implementation detail.
* Remove test for allPropertiesDidChange
* Removed star observer test. no longer supported
* Removed property revision test. no longer supported
*/
// ========================================================================
// Ember.Observable Tests
// ========================================================================
var ObjectA = void 0;
QUnit.module('object.propertyChanges', {
setup: function () {
ObjectA = ObservableObject.extend({
action: (0, _emberMetal.observer)('foo', function () {
this.set('prop', 'changedPropValue');
}),
notifyAction: (0, _emberMetal.observer)('newFoo', function () {
this.set('newProp', 'changedNewPropValue');
}),
notifyAllAction: (0, _emberMetal.observer)('prop', function () {
this.set('newFoo', 'changedNewFooValue');
}),
starObserver: function (target, key) {
this.starProp = key;
}
}).create({
starProp: null,
foo: 'fooValue',
prop: 'propValue',
newFoo: 'newFooValue',
newProp: 'newPropValue'
});
}
});
QUnit.test('should observe the changes within the nested begin / end property changes', function () {
//start the outer nest
ObjectA.beginPropertyChanges();
// Inner nest
ObjectA.beginPropertyChanges();
ObjectA.set('foo', 'changeFooValue');
equal(ObjectA.prop, 'propValue');
ObjectA.endPropertyChanges();
//end inner nest
ObjectA.set('prop', 'changePropValue');
equal(ObjectA.newFoo, 'newFooValue');
//close the outer nest
ObjectA.endPropertyChanges();
equal(ObjectA.prop, 'changedPropValue');
equal(ObjectA.newFoo, 'changedNewFooValue');
});
QUnit.test('should observe the changes within the begin and end property changes', function () {
ObjectA.beginPropertyChanges();
ObjectA.set('foo', 'changeFooValue');
equal(ObjectA.prop, 'propValue');
ObjectA.endPropertyChanges();
equal(ObjectA.prop, 'changedPropValue');
});
QUnit.test('should indicate that the property of an object has just changed', function () {
// indicate that property of foo will change to its subscribers
ObjectA.propertyWillChange('foo');
//Value of the prop is unchanged yet as this will be changed when foo changes
equal(ObjectA.prop, 'propValue');
//change the value of foo.
ObjectA.set('foo', 'changeFooValue');
// Indicate the subscribers of foo that the value has just changed
ObjectA.propertyDidChange('foo', null);
// Values of prop has just changed
equal(ObjectA.prop, 'changedPropValue');
});
QUnit.test('should notify that the property of an object has changed', function () {
// Notify to its subscriber that the values of 'newFoo' will be changed. In this
// case the observer is "newProp". Therefore this will call the notifyAction function
// and value of "newProp" will be changed.
ObjectA.notifyPropertyChange('newFoo', 'fooValue');
//value of newProp changed.
equal(ObjectA.newProp, 'changedNewPropValue');
});
QUnit.test('should invalidate function property cache when notifyPropertyChange is called', function () {
var a = ObservableObject.extend({
b: (0, _emberMetal.computed)({
get: function () {
return this._b;
},
set: function (key, value) {
this._b = value;
return this;
}
}).volatile()
}).create({
_b: null
});
a.set('b', 'foo');
equal(a.get('b'), 'foo', 'should have set the correct value for property b');
a._b = 'bar';
a.notifyPropertyChange('b');
a.set('b', 'foo');
equal(a.get('b'), 'foo', 'should have invalidated the cache so that the newly set value is actually set');
});
});
enifed('ember-runtime/tests/legacy_1x/system/binding_test', ['ember-environment', 'ember-metal', 'ember-runtime/system/object'], function (_emberEnvironment, _emberMetal, _object) {
'use strict';
/*
NOTE: This test is adapted from the 1.x series of unit tests. The tests
are the same except for places where we intend to break the API we instead
validate that we warn the developer appropriately.
CHANGES FROM 1.6:
* All calls to run.sync() were changed to
run.sync()
* Bindings no longer accept a root object as their second param. Instead
our test binding objects were put under a single object they could
originate from.
* tests that inspected internal properties were removed.
* converted foo.get/foo.set to use get/Ember.set
* Removed tests for Binding.isConnected. Since binding instances are now
shared this property no longer makes sense.
* Changed call calls for obj.bind(...) to bind(obj, ...);
* Changed all calls to sc_super() to this._super(...arguments)
* Changed all calls to disconnect() to pass the root object.
* removed calls to Binding.destroy() as that method is no longer useful
(or defined)
* changed use of T_STRING to 'string'
*/
// ========================================================================
// Binding Tests
// ========================================================================
var TestNamespace = void 0,
fromObject = void 0,
toObject = void 0,
binding = void 0,
Bon1 = void 0,
bon2 = void 0,
root = void 0; // global variables
var originalLookup = _emberEnvironment.context.lookup;
var lookup = void 0;
QUnit.module('basic object binding', {
setup: function () {
fromObject = _object.default.create({ value: 'start' });
toObject = _object.default.create({ value: 'end' });
root = { fromObject: fromObject, toObject: toObject };
(0, _emberMetal.run)(function () {
expectDeprecation(function () {
binding = (0, _emberMetal.bind)(root, 'toObject.value', 'fromObject.value');
}, /`Ember\.Binding` is deprecated./);
});
}
});
QUnit.test('binding should have synced on connect', function () {
equal((0, _emberMetal.get)(toObject, 'value'), 'start', 'toObject.value should match fromObject.value');
});
QUnit.test('fromObject change should propagate to toObject only after flush', function () {
(0, _emberMetal.run)(function () {
(0, _emberMetal.set)(fromObject, 'value', 'change');
equal((0, _emberMetal.get)(toObject, 'value'), 'start');
});
equal((0, _emberMetal.get)(toObject, 'value'), 'change');
});
QUnit.test('toObject change should propagate to fromObject only after flush', function () {
(0, _emberMetal.run)(function () {
(0, _emberMetal.set)(toObject, 'value', 'change');
equal((0, _emberMetal.get)(fromObject, 'value'), 'start');
});
equal((0, _emberMetal.get)(fromObject, 'value'), 'change');
});
QUnit.test('deferred observing during bindings', function () {
// setup special binding
fromObject = _object.default.create({
value1: 'value1',
value2: 'value2'
});
toObject = _object.default.extend({
observer: (0, _emberMetal.observer)('value1', 'value2', function () {
equal((0, _emberMetal.get)(this, 'value1'), 'CHANGED', 'value1 when observer fires');
equal((0, _emberMetal.get)(this, 'value2'), 'CHANGED', 'value2 when observer fires');
this.callCount++;
})
}).create({
value1: 'value1',
value2: 'value2',
callCount: 0
});
var root = { fromObject: fromObject, toObject: toObject };
(0, _emberMetal.run)(function () {
expectDeprecation(function () {
(0, _emberMetal.bind)(root, 'toObject.value1', 'fromObject.value1');
}, /`Ember\.Binding` is deprecated./);
expectDeprecation(function () {
(0, _emberMetal.bind)(root, 'toObject.value2', 'fromObject.value2');
}, /`Ember\.Binding` is deprecated./);
// change both value1 + value2, then flush bindings. observer should only
// fire after bindings are done flushing.
(0, _emberMetal.set)(fromObject, 'value1', 'CHANGED');
(0, _emberMetal.set)(fromObject, 'value2', 'CHANGED');
});
equal(toObject.callCount, 2, 'should call observer twice');
});
QUnit.test('binding disconnection actually works', function () {
binding.disconnect(root);
(0, _emberMetal.run)(function () {
(0, _emberMetal.set)(fromObject, 'value', 'change');
});
equal((0, _emberMetal.get)(toObject, 'value'), 'start');
});
var first = void 0,
second = void 0,
third = void 0; // global variables
// ..........................................................
// chained binding
//
QUnit.module('chained binding', {
setup: function () {
(0, _emberMetal.run)(function () {
first = _object.default.create({ output: 'first' });
second = _object.default.extend({
inputDidChange: (0, _emberMetal.observer)('input', function () {
(0, _emberMetal.set)(this, 'output', (0, _emberMetal.get)(this, 'input'));
})
}).create({
input: 'second',
output: 'second'
});
third = _object.default.create({ input: 'third' });
root = { first: first, second: second, third: third };
expectDeprecation(function () {
(0, _emberMetal.bind)(root, 'second.input', 'first.output');
}, /`Ember\.Binding` is deprecated./);
expectDeprecation(function () {
(0, _emberMetal.bind)(root, 'second.output', 'third.input');
}, /`Ember\.Binding` is deprecated./);
});
},
teardown: function () {
_emberMetal.run.cancelTimers();
}
});
QUnit.test('changing first output should propagate to third after flush', function () {
(0, _emberMetal.run)(function () {
(0, _emberMetal.set)(first, 'output', 'change');
equal('change', (0, _emberMetal.get)(first, 'output'), 'first.output');
ok('change' !== (0, _emberMetal.get)(third, 'input'), 'third.input');
});
equal('change', (0, _emberMetal.get)(first, 'output'), 'first.output');
equal('change', (0, _emberMetal.get)(second, 'input'), 'second.input');
equal('change', (0, _emberMetal.get)(second, 'output'), 'second.output');
equal('change', (0, _emberMetal.get)(third, 'input'), 'third.input');
});
// ..........................................................
// Custom Binding
//
QUnit.module('Custom Binding', {
setup: function () {
_emberEnvironment.context.lookup = lookup = {};
Bon1 = _object.default.extend({
value1: 'hi',
value2: 83,
array1: []
});
bon2 = _object.default.create({
val1: 'hello',
val2: 25,
arr: [1, 2, 3, 4]
});
_emberEnvironment.context.lookup['TestNamespace'] = TestNamespace = {
bon2: bon2,
Bon1: Bon1
};
},
teardown: function () {
_emberEnvironment.context.lookup = originalLookup;
Bon1 = bon2 = TestNamespace = null;
_emberMetal.run.cancelTimers();
}
});
QUnit.test('two bindings to the same value should sync in the order they are initialized', function () {
_emberMetal.run.begin();
var a = _object.default.create({
foo: 'bar'
});
var b = _object.default.extend({
C: _object.default.extend({
foo: 'bee',
fooBinding: 'owner.foo'
}),
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'c', this.C.create({ owner: this }));
}
});
expectDeprecation(function () {
b = b.create({
foo: 'baz',
fooBinding: 'a.foo',
a: a
});
}, /`Ember\.Binding` is deprecated./);
_emberMetal.run.end();
equal((0, _emberMetal.get)(a, 'foo'), 'bar', 'a.foo should not change');
equal((0, _emberMetal.get)(b, 'foo'), 'bar', 'a.foo should propagate up to b.foo');
equal((0, _emberMetal.get)(b.c, 'foo'), 'bar', 'a.foo should propagate up to b.c.foo');
});
// ..........................................................
// propertyNameBinding with longhand
//
QUnit.module('propertyNameBinding with longhand', {
setup: function () {
_emberEnvironment.context.lookup = lookup = {};
lookup['TestNamespace'] = TestNamespace = {};
(0, _emberMetal.run)(function () {
TestNamespace.fromObject = _object.default.create({
value: 'originalValue'
});
expectDeprecation(function () {
TestNamespace.toObject = _object.default.extend({
valueBinding: _emberMetal.Binding.from('TestNamespace.fromObject.value'),
relativeBinding: _emberMetal.Binding.from('localValue')
}).create({
localValue: 'originalLocal'
});
}, /`Ember\.Binding` is deprecated./);
});
},
teardown: function () {
TestNamespace = undefined;
_emberEnvironment.context.lookup = originalLookup;
}
});
QUnit.test('works with full path', function () {
(0, _emberMetal.run)(function () {
return (0, _emberMetal.set)(TestNamespace.fromObject, 'value', 'updatedValue');
});
equal((0, _emberMetal.get)(TestNamespace.toObject, 'value'), 'updatedValue');
(0, _emberMetal.run)(function () {
return (0, _emberMetal.set)(TestNamespace.fromObject, 'value', 'newerValue');
});
equal((0, _emberMetal.get)(TestNamespace.toObject, 'value'), 'newerValue');
});
QUnit.test('works with local path', function () {
(0, _emberMetal.run)(function () {
return (0, _emberMetal.set)(TestNamespace.toObject, 'localValue', 'updatedValue');
});
equal((0, _emberMetal.get)(TestNamespace.toObject, 'relative'), 'updatedValue');
(0, _emberMetal.run)(function () {
return (0, _emberMetal.set)(TestNamespace.toObject, 'localValue', 'newerValue');
});
equal((0, _emberMetal.get)(TestNamespace.toObject, 'relative'), 'newerValue');
});
});
enifed('ember-runtime/tests/legacy_1x/system/object/base_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) {
'use strict';
/*
NOTE: This test is adapted from the 1.x series of unit tests. The tests
are the same except for places where we intend to break the API we instead
validate that we warn the developer appropriately.
CHANGES FROM 1.6:
* Changed get(obj, ) and set(obj, ) to Ember.get() and Ember.set()
* Removed obj.instanceOf() and obj.kindOf() tests. use obj instanceof Foo
instead
* Removed respondsTo() and tryToPerform() tests. Can be brought back in a
utils package.
* Removed destroy() test. You can impl yourself but not built in
* Changed Class.subclassOf() test to Class.detect()
* Remove broken test for 'superclass' property.
* Removed obj.didChangeFor()
*/
// ========================================================================
// EmberObject Base Tests
// ========================================================================
var obj = void 0,
obj1 = void 0; // global variables
QUnit.module('A new EmberObject instance', {
setup: function () {
obj = _object.default.create({
foo: 'bar',
total: 12345,
aMethodThatExists: function () {},
aMethodThatReturnsTrue: function () {
return true;
},
aMethodThatReturnsFoobar: function () {
return 'Foobar';
},
aMethodThatReturnsFalse: function () {
return false;
}
});
},
teardown: function () {
obj = undefined;
}
});
QUnit.test('Should return its properties when requested using EmberObject#get', function () {
equal((0, _emberMetal.get)(obj, 'foo'), 'bar');
equal((0, _emberMetal.get)(obj, 'total'), 12345);
});
QUnit.test('Should allow changing of those properties by calling EmberObject#set', function () {
equal((0, _emberMetal.get)(obj, 'foo'), 'bar');
equal((0, _emberMetal.get)(obj, 'total'), 12345);
(0, _emberMetal.set)(obj, 'foo', 'Chunky Bacon');
(0, _emberMetal.set)(obj, 'total', 12);
equal((0, _emberMetal.get)(obj, 'foo'), 'Chunky Bacon');
equal((0, _emberMetal.get)(obj, 'total'), 12);
});
QUnit.module('EmberObject superclass and subclasses', {
setup: function () {
obj = _object.default.extend({
method1: function () {
return 'hello';
}
});
obj1 = obj.extend();
},
teardown: function () {
obj = undefined;
obj1 = undefined;
}
});
QUnit.test('Checking the detect() function on an object and its subclass', function () {
equal(obj.detect(obj1), true);
equal(obj1.detect(obj), false);
});
QUnit.test('Checking the detectInstance() function on an object and its subclass', function () {
ok(_object.default.detectInstance(obj.create()));
ok(obj.detectInstance(obj.create()));
});
});
enifed('ember-runtime/tests/legacy_1x/system/object/bindings_test', ['ember-environment', 'ember-metal', 'ember-runtime/system/object'], function (_emberEnvironment, _emberMetal, _object) {
'use strict';
/*
NOTE: This test is adapted from the 1.x series of unit tests. The tests
are the same except for places where we intend to break the API we instead
validate that we warn the developer appropriately.
CHANGES FROM 1.6:
* changed Ember.Bending.flushPendingChanges() -> run.sync();
* changes obj.set() and obj.get() to Ember.set() and Ember.get()
* Fixed an actual bug in unit tests around line 133
* fixed 'bindings should disconnect on destroy' test to use destroy.
*/
// ========================================================================
// EmberObject bindings Tests
// ========================================================================
var originalLookup = _emberEnvironment.context.lookup;
var testObject = void 0,
fromObject = void 0,
TestObject = void 0;
var TestNamespace = void 0,
lookup = void 0;
QUnit.module('bind() method', {
setup: function () {
_emberEnvironment.context.lookup = lookup = {};
testObject = _object.default.create({
foo: 'bar',
bar: 'foo',
extraObject: null
});
fromObject = _object.default.create({
bar: 'foo',
extraObject: null
});
lookup['TestNamespace'] = TestNamespace = {
fromObject: fromObject,
testObject: testObject
};
},
teardown: function () {
testObject = fromObject = null;
_emberEnvironment.context.lookup = originalLookup;
}
});
QUnit.test('bind(TestNamespace.fromObject.bar) should follow absolute path', function () {
(0, _emberMetal.run)(function () {
expectDeprecation(function () {
// create binding
testObject.bind('foo', 'TestNamespace.fromObject.bar');
}, /`Ember.Binding` is deprecated/);
// now make a change to see if the binding triggers.
(0, _emberMetal.set)(fromObject, 'bar', 'changedValue');
});
equal('changedValue', (0, _emberMetal.get)(testObject, 'foo'), 'testObject.foo');
});
QUnit.test('bind(.bar) should bind to relative path', function () {
(0, _emberMetal.run)(function () {
expectDeprecation(function () {
// create binding
testObject.bind('foo', 'bar');
}, /`Ember.Binding` is deprecated/);
// now make a change to see if the binding triggers.
(0, _emberMetal.set)(testObject, 'bar', 'changedValue');
});
equal('changedValue', (0, _emberMetal.get)(testObject, 'foo'), 'testObject.foo');
});
QUnit.module('fooBinding method', {
setup: function () {
_emberEnvironment.context.lookup = lookup = {};
TestObject = _object.default.extend({
foo: 'bar',
bar: 'foo',
extraObject: null
});
fromObject = _object.default.create({
bar: 'foo',
extraObject: null
});
lookup['TestNamespace'] = TestNamespace = {
fromObject: fromObject,
testObject: TestObject
};
},
teardown: function () {
_emberEnvironment.context.lookup = originalLookup;
TestObject = fromObject = null;
// delete TestNamespace;
}
});
var deprecationMessage = /`Ember.Binding` is deprecated/;
QUnit.test('fooBinding: TestNamespace.fromObject.bar should follow absolute path', function () {
(0, _emberMetal.run)(function () {
expectDeprecation(function () {
// create binding
testObject = TestObject.extend({
fooBinding: 'TestNamespace.fromObject.bar'
}).create();
}, deprecationMessage);
// now make a change to see if the binding triggers.
(0, _emberMetal.set)(fromObject, 'bar', 'changedValue');
});
equal('changedValue', (0, _emberMetal.get)(testObject, 'foo'), 'testObject.foo');
});
QUnit.test('fooBinding: .bar should bind to relative path', function () {
(0, _emberMetal.run)(function () {
expectDeprecation(function () {
// create binding
testObject = TestObject.extend({
fooBinding: 'bar'
}).create();
}, deprecationMessage);
// now make a change to see if the binding triggers.
(0, _emberMetal.set)(testObject, 'bar', 'changedValue');
});
equal('changedValue', (0, _emberMetal.get)(testObject, 'foo'), 'testObject.foo');
});
QUnit.test('fooBinding: should disconnect bindings when destroyed', function () {
(0, _emberMetal.run)(function () {
expectDeprecation(function () {
// create binding
testObject = TestObject.extend({
fooBinding: 'TestNamespace.fromObject.bar'
}).create();
}, deprecationMessage);
(0, _emberMetal.set)(TestNamespace.fromObject, 'bar', 'BAZ');
});
equal((0, _emberMetal.get)(testObject, 'foo'), 'BAZ', 'binding should have synced');
(0, _emberMetal.run)(function () {
return testObject.destroy();
});
(0, _emberMetal.run)(function () {
return (0, _emberMetal.set)(TestNamespace.fromObject, 'bar', 'BIFF');
});
ok((0, _emberMetal.get)(testObject, 'foo') !== 'bar', 'binding should not have synced');
});
});
enifed('ember-runtime/tests/legacy_1x/system/object/concatenated_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) {
'use strict';
/*
NOTE: This test is adapted from the 1.x series of unit tests. The tests
are the same except for places where we intend to break the API we instead
validate that we warn the developer appropriately.
CHANGES FROM 1.6:
* changed get(obj, ) and set(obj, ) to Ember.get() and Ember.set()
* converted uses of obj.isEqual() to use deepEqual() test since isEqual is not
always defined
*/
function K() {
return this;
}
var klass = void 0;
QUnit.module('EmberObject Concatenated Properties', {
setup: function () {
klass = _object.default.extend({
concatenatedProperties: ['values', 'functions'],
values: ['a', 'b', 'c'],
functions: [K]
});
}
});
QUnit.test('concatenates instances', function () {
var obj = klass.create({
values: ['d', 'e', 'f']
});
var values = (0, _emberMetal.get)(obj, 'values');
var expected = ['a', 'b', 'c', 'd', 'e', 'f'];
deepEqual(values, expected, 'should concatenate values property (expected: ' + expected + ', got: ' + values + ')');
});
QUnit.test('concatenates subclasses', function () {
var subKlass = klass.extend({
values: ['d', 'e', 'f']
});
var obj = subKlass.create();
var values = (0, _emberMetal.get)(obj, 'values');
var expected = ['a', 'b', 'c', 'd', 'e', 'f'];
deepEqual(values, expected, 'should concatenate values property (expected: ' + expected + ', got: ' + values + ')');
});
QUnit.test('concatenates reopen', function () {
klass.reopen({
values: ['d', 'e', 'f']
});
var obj = klass.create();
var values = (0, _emberMetal.get)(obj, 'values');
var expected = ['a', 'b', 'c', 'd', 'e', 'f'];
deepEqual(values, expected, 'should concatenate values property (expected: ' + expected + ', got: ' + values + ')');
});
QUnit.test('concatenates mixin', function () {
var subKlass = klass.extend({
values: ['d', 'e']
}, {
values: ['f']
});
var obj = subKlass.create();
var values = (0, _emberMetal.get)(obj, 'values');
var expected = ['a', 'b', 'c', 'd', 'e', 'f'];
deepEqual(values, expected, 'should concatenate values property (expected: ' + expected + ', got: ' + values + ')');
});
QUnit.test('concatenates reopen, subclass, and instance', function () {
klass.reopen({ values: ['d'] });
var subKlass = klass.extend({ values: ['e'] });
var obj = subKlass.create({ values: ['f'] });
var values = (0, _emberMetal.get)(obj, 'values');
var expected = ['a', 'b', 'c', 'd', 'e', 'f'];
deepEqual(values, expected, 'should concatenate values property (expected: ' + expected + ', got: ' + values + ')');
});
QUnit.test('concatenates subclasses when the values are functions', function () {
var subKlass = klass.extend({
functions: K
});
var obj = subKlass.create();
var values = (0, _emberMetal.get)(obj, 'functions');
var expected = [K, K];
deepEqual(values, expected, 'should concatenate functions property (expected: ' + expected + ', got: ' + values + ')');
});
});
enifed('ember-runtime/tests/legacy_1x/system/run_loop_test', ['ember-metal', 'ember-runtime/mixins/observable', 'ember-runtime/system/object'], function (_emberMetal, _observable, _object) {
'use strict';
/*
NOTE: This test is adapted from the 1.x series of unit tests. The tests
are the same except for places where we intend to break the API we instead
validate that we warn the developer appropriately.
CHANGES FROM 1.6:
* Updated the API usage for setting up and syncing Binding since these
are not the APIs this file is testing.
* Disabled a call to invokeOnce() around line 127 because it appeared to be
broken anyway. I don't think it ever even worked.
*/
var MyApp = void 0;
QUnit.module('System:run_loop() - chained binding', {
setup: function () {
MyApp = {};
MyApp.first = _object.default.extend(_observable.default).create({
output: 'MyApp.first'
});
MyApp.second = _object.default.extend(_observable.default, {
inputDidChange: (0, _emberMetal.observer)('input', function () {
this.set('output', this.get('input'));
})
}).create({
input: 'MyApp.second',
output: 'MyApp.second'
});
MyApp.third = _object.default.extend(_observable.default).create({
input: 'MyApp.third'
});
}
});
var deprecationMessage = /`Ember.Binding` is deprecated/;
QUnit.test('Should propagate bindings after the RunLoop completes (using Ember.RunLoop)', function () {
(0, _emberMetal.run)(function () {
//Binding of output of MyApp.first object to input of MyApp.second object
expectDeprecation(function () {
_emberMetal.Binding.from('first.output').to('second.input').connect(MyApp);
}, deprecationMessage);
//Binding of output of MyApp.second object to input of MyApp.third object
expectDeprecation(function () {
_emberMetal.Binding.from('second.output').to('third.input').connect(MyApp);
}, deprecationMessage);
});
(0, _emberMetal.run)(function () {
// Based on the above binding if you change the output of MyApp.first
// object it should change the all the variable of
// MyApp.first,MyApp.second and MyApp.third object
MyApp.first.set('output', 'change');
//Changes the output of the MyApp.first object
equal(MyApp.first.get('output'), 'change');
//since binding has not taken into effect the value still remains as change.
equal(MyApp.second.get('output'), 'MyApp.first');
}); // allows bindings to trigger...
//Value of the output variable changed to 'change'
equal(MyApp.first.get('output'), 'change');
//Since binding triggered after the end loop the value changed to 'change'.
equal(MyApp.second.get('output'), 'change');
});
QUnit.test('Should propagate bindings after the RunLoop completes', function () {
(0, _emberMetal.run)(function () {
//Binding of output of MyApp.first object to input of MyApp.second object
expectDeprecation(function () {
_emberMetal.Binding.from('first.output').to('second.input').connect(MyApp);
}, deprecationMessage);
//Binding of output of MyApp.second object to input of MyApp.third object
expectDeprecation(function () {
_emberMetal.Binding.from('second.output').to('third.input').connect(MyApp);
}, deprecationMessage);
});
(0, _emberMetal.run)(function () {
//Based on the above binding if you change the output of MyApp.first object it should
//change the all the variable of MyApp.first,MyApp.second and MyApp.third object
MyApp.first.set('output', 'change');
//Changes the output of the MyApp.first object
equal(MyApp.first.get('output'), 'change');
//since binding has not taken into effect the value still remains as change.
equal(MyApp.second.get('output'), 'MyApp.first');
});
//Value of the output variable changed to 'change'
equal(MyApp.first.get('output'), 'change');
//Since binding triggered after the end loop the value changed to 'change'.
equal(MyApp.second.get('output'), 'change');
});
});
enifed('ember-runtime/tests/main_test', ['ember-runtime/index'], function (_index) {
'use strict';
QUnit.module('ember-runtime/main');
QUnit.test('Ember.computed.collect', function () {
var MyObj = _index.Object.extend({
props: (0, _index.collect)('foo', 'bar', 'baz')
});
var myObj = MyObj.create({
foo: 3,
bar: 5,
baz: 'asdf'
});
var propsValue = myObj.get('props');
deepEqual(propsValue, [3, 5, 'asdf']);
});
});
enifed('ember-runtime/tests/mixins/array_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/tests/suites/array', 'ember-runtime/system/object', 'ember-runtime/mixins/array', 'ember-runtime/system/native_array'], function (_emberMetal, _internalTestHelpers, _array, _object, _array2, _native_array) {
'use strict';
/*
Implement a basic fake mutable array. This validates that any non-native
enumerable can impl this API.
*/
var TestArray = _object.default.extend(_array2.default, {
_content: null,
init: function () {
var ary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
this._content = ary;
},
addObject: function (obj) {
var idx = this._content.length;
(0, _array2.arrayContentWillChange)(this, idx, 0, 1);
this._content.push(obj);
(0, _array2.arrayContentDidChange)(this, idx, 0, 1);
},
removeFirst: function () {
(0, _array2.arrayContentWillChange)(this, 0, 1, 0);
this._content.shift();
(0, _array2.arrayContentDidChange)(this, 0, 1, 0);
},
objectAt: function (idx) {
return this._content[idx];
},
length: (0, _emberMetal.computed)(function () {
return this._content.length;
})
});
_array.ArrayTests.extend({
name: 'Basic Mutable Array',
newObject: function (ary) {
ary = ary ? ary.slice() : this.newFixture(3);
return new TestArray(ary);
},
mutate: function (obj) {
obj.addObject(this.getFixture(1)[0]);
},
toArray: function (obj) {
return obj.slice();
}
}).run();
QUnit.test('the return value of slice has Ember.Array applied', function () {
var x = _object.default.extend(_array2.default).create({
length: 0
});
var y = x.slice(1);
equal(_array2.default.detect(y), true, 'mixin should be applied');
});
QUnit.test('slice supports negative index arguments', function () {
var testArray = new TestArray([1, 2, 3, 4]);
deepEqual(testArray.slice(-2), [3, 4], 'slice(-2)');
deepEqual(testArray.slice(-2, -1), [3], 'slice(-2, -1');
deepEqual(testArray.slice(-2, -2), [], 'slice(-2, -2)');
deepEqual(testArray.slice(-1, -2), [], 'slice(-1, -2)');
deepEqual(testArray.slice(-4, 1), [1], 'slice(-4, 1)');
deepEqual(testArray.slice(-4, 5), [1, 2, 3, 4], 'slice(-4, 5)');
deepEqual(testArray.slice(-4), [1, 2, 3, 4], 'slice(-4)');
deepEqual(testArray.slice(0, -1), [1, 2, 3], 'slice(0, -1)');
deepEqual(testArray.slice(0, -4), [], 'slice(0, -4)');
deepEqual(testArray.slice(0, -3), [1], 'slice(0, -3)');
});
// ..........................................................
// CONTENT DID CHANGE
//
var DummyArray = _object.default.extend(_array2.default, {
nextObject: function () {},
length: 0,
objectAt: function (idx) {
return 'ITEM-' + idx;
}
});
var obj = void 0,
observer = void 0;
// ..........................................................
// NOTIFY ARRAY OBSERVERS
//
QUnit.module('mixins/array/arrayContent[Will|Did]Change');
QUnit.test('should notify observers of []', function () {
obj = DummyArray.extend({
enumerablePropertyDidChange: (0, _emberMetal.observer)('[]', function () {
this._count++;
})
}).create({
_count: 0
});
equal(obj._count, 0, 'should not have invoked yet');
(0, _array2.arrayContentWillChange)(obj, 0, 1, 1);
(0, _array2.arrayContentDidChange)(obj, 0, 1, 1);
equal(obj._count, 1, 'should have invoked');
});
// ..........................................................
// NOTIFY CHANGES TO LENGTH
//
QUnit.module('notify observers of length', {
setup: function () {
obj = DummyArray.extend({
lengthDidChange: (0, _emberMetal.observer)('length', function () {
this._after++;
})
}).create({
_after: 0
});
equal(obj._after, 0, 'should not have fired yet');
},
teardown: function () {
obj = null;
}
});
QUnit.test('should notify observers when call with no params', function () {
(0, _array2.arrayContentWillChange)(obj);
equal(obj._after, 0);
(0, _array2.arrayContentDidChange)(obj);
equal(obj._after, 1);
});
// API variation that included items only
QUnit.test('should not notify when passed lengths are same', function () {
(0, _array2.arrayContentWillChange)(obj, 0, 1, 1);
equal(obj._after, 0);
(0, _array2.arrayContentDidChange)(obj, 0, 1, 1);
equal(obj._after, 0);
});
QUnit.test('should notify when passed lengths are different', function () {
(0, _array2.arrayContentWillChange)(obj, 0, 1, 2);
equal(obj._after, 0);
(0, _array2.arrayContentDidChange)(obj, 0, 1, 2);
equal(obj._after, 1);
});
// ..........................................................
// NOTIFY ARRAY OBSERVER
//
QUnit.module('notify array observers', {
setup: function () {
obj = DummyArray.create();
observer = _object.default.extend({
arrayWillChange: function () {
equal(this._before, null); // should only call once
this._before = Array.prototype.slice.call(arguments);
},
arrayDidChange: function () {
equal(this._after, null); // should only call once
this._after = Array.prototype.slice.call(arguments);
}
}).create({
_before: null,
_after: null
});
(0, _array2.addArrayObserver)(obj, observer);
},
teardown: function () {
obj = observer = null;
}
});
QUnit.test('should notify enumerable observers when called with no params', function () {
(0, _array2.arrayContentWillChange)(obj);
deepEqual(observer._before, [obj, 0, -1, -1]);
(0, _array2.arrayContentDidChange)(obj);
deepEqual(observer._after, [obj, 0, -1, -1]);
});
// API variation that included items only
QUnit.test('should notify when called with same length items', function () {
(0, _array2.arrayContentWillChange)(obj, 0, 1, 1);
deepEqual(observer._before, [obj, 0, 1, 1]);
(0, _array2.arrayContentDidChange)(obj, 0, 1, 1);
deepEqual(observer._after, [obj, 0, 1, 1]);
});
QUnit.test('should notify when called with diff length items', function () {
(0, _array2.arrayContentWillChange)(obj, 0, 2, 1);
deepEqual(observer._before, [obj, 0, 2, 1]);
(0, _array2.arrayContentDidChange)(obj, 0, 2, 1);
deepEqual(observer._after, [obj, 0, 2, 1]);
});
QUnit.test('removing enumerable observer should disable', function () {
(0, _array2.removeArrayObserver)(obj, observer);
(0, _array2.arrayContentWillChange)(obj);
deepEqual(observer._before, null);
(0, _array2.arrayContentDidChange)(obj);
deepEqual(observer._after, null);
});
// ..........................................................
// NOTIFY ENUMERABLE OBSERVER
//
QUnit.module('notify enumerable observers as well', {
setup: function () {
obj = DummyArray.create();
observer = _object.default.extend({
enumerableWillChange: function () {
equal(this._before, null); // should only call once
this._before = Array.prototype.slice.call(arguments);
},
enumerableDidChange: function () {
equal(this._after, null); // should only call once
this._after = Array.prototype.slice.call(arguments);
}
}).create({
_before: null,
_after: null
});
obj.addEnumerableObserver(observer);
},
teardown: function () {
obj = observer = null;
}
});
QUnit.test('should notify enumerable observers when called with no params', function () {
(0, _array2.arrayContentWillChange)(obj);
deepEqual(observer._before, [obj, null, null], 'before');
(0, _array2.arrayContentDidChange)(obj);
deepEqual(observer._after, [obj, null, null], 'after');
});
// API variation that included items only
QUnit.test('should notify when called with same length items', function () {
(0, _array2.arrayContentWillChange)(obj, 0, 1, 1);
deepEqual(observer._before, [obj, ['ITEM-0'], 1], 'before');
(0, _array2.arrayContentDidChange)(obj, 0, 1, 1);
deepEqual(observer._after, [obj, 1, ['ITEM-0']], 'after');
});
QUnit.test('should notify when called with diff length items', function () {
(0, _array2.arrayContentWillChange)(obj, 0, 2, 1);
deepEqual(observer._before, [obj, ['ITEM-0', 'ITEM-1'], 1], 'before');
(0, _array2.arrayContentDidChange)(obj, 0, 2, 1);
deepEqual(observer._after, [obj, 2, ['ITEM-0']], 'after');
});
QUnit.test('removing enumerable observer should disable', function () {
obj.removeEnumerableObserver(observer);
(0, _array2.arrayContentWillChange)(obj);
deepEqual(observer._before, null, 'before');
(0, _array2.arrayContentDidChange)(obj);
deepEqual(observer._after, null, 'after');
});
// ..........................................................
// @each
//
var ary = void 0;
QUnit.module('EmberArray.@each support', {
setup: function () {
ary = new TestArray([{ isDone: true, desc: 'Todo 1' }, { isDone: false, desc: 'Todo 2' }, { isDone: true, desc: 'Todo 3' }, { isDone: false, desc: 'Todo 4' }]);
},
teardown: function () {
ary = null;
}
});
QUnit.test('adding an object should notify (@each.isDone)', function () {
var called = 0;
var observerObject = _object.default.create({
wasCalled: function () {
called++;
}
});
(0, _emberMetal.addObserver)(ary, '@each.isDone', observerObject, 'wasCalled');
ary.addObject(_object.default.create({
desc: 'foo',
isDone: false
}));
equal(called, 1, 'calls observer when object is pushed');
});
QUnit.test('@each is readOnly', function () {
expect(1);
throws(function () {
(0, _emberMetal.set)(ary, '@each', 'foo');
}, /Cannot set read-only property "@each"/);
});
QUnit.test('using @each to observe arrays that does not return objects raise error', function () {
var called = 0;
var observerObject = _object.default.create({
wasCalled: function () {
called++;
}
});
ary = TestArray.create({
objectAt: function (idx) {
return (0, _emberMetal.get)(this._content[idx], 'desc');
}
});
(0, _emberMetal.addObserver)(ary, '@each.isDone', observerObject, 'wasCalled');
expectAssertion(function () {
ary.addObject(_object.default.create({
desc: 'foo',
isDone: false
}));
}, /When using @each to observe the array/);
equal(called, 0, 'not calls observer when object is pushed');
});
QUnit.test('modifying the array should also indicate the isDone prop itself has changed', function () {
// NOTE: we never actually get the '@each.isDone' property here. This is
// important because it tests the case where we don't have an isDone
// EachArray materialized but just want to know when the property has
// changed.
var each = (0, _emberMetal.get)(ary, '@each');
var count = 0;
(0, _emberMetal.addObserver)(each, 'isDone', function () {
return count++;
});
count = 0;
var item = (0, _array2.objectAt)(ary, 2);
(0, _emberMetal.set)(item, 'isDone', !(0, _emberMetal.get)(item, 'isDone'));
equal(count, 1, '@each.isDone should have notified');
});
QUnit.test('`objectAt` returns correct object', function () {
var arr = ['first', 'second', 'third', 'fourth'];
equal((0, _array2.objectAt)(arr, 2), 'third');
equal((0, _array2.objectAt)(arr, 4), undefined);
});
(0, _internalTestHelpers.testBoth)('should be clear caches for computed properties that have dependent keys on arrays that are changed after object initialization', function (get, set) {
var obj = _object.default.extend({
init: function () {
this._super.apply(this, arguments);
set(this, 'resources', (0, _native_array.A)());
},
common: (0, _emberMetal.computed)('resources.@each.common', function () {
return get((0, _array2.objectAt)(get(this, 'resources'), 0), 'common');
})
}).create();
get(obj, 'resources').pushObject(_object.default.create({ common: 'HI!' }));
equal('HI!', get(obj, 'common'));
set((0, _array2.objectAt)(get(obj, 'resources'), 0), 'common', 'BYE!');
equal('BYE!', get(obj, 'common'));
});
(0, _internalTestHelpers.testBoth)('observers that contain @each in the path should fire only once the first time they are accessed', function (get, set) {
var count = 0;
var obj = _object.default.extend({
init: function () {
this._super.apply(this, arguments);
// Observer does not fire on init
set(this, 'resources', (0, _native_array.A)());
},
commonDidChange: (0, _emberMetal.observer)('resources.@each.common', function () {
return count++;
})
}).create();
// Observer fires second time when new object is added
get(obj, 'resources').pushObject(_object.default.create({ common: 'HI!' }));
// Observer fires third time when property on an object is changed
set((0, _array2.objectAt)(get(obj, 'resources'), 0), 'common', 'BYE!');
equal(count, 2, 'observers should only be called once');
});
});
enifed('ember-runtime/tests/mixins/comparable_test', ['ember-metal', 'ember-runtime/system/object', 'ember-runtime/compare', 'ember-runtime/mixins/comparable'], function (_emberMetal, _object, _compare, _comparable) {
'use strict';
var Rectangle = _object.default.extend(_comparable.default, {
length: 0,
width: 0,
area: function () {
return (0, _emberMetal.get)(this, 'length') * (0, _emberMetal.get)(this, 'width');
},
compare: function (a, b) {
return (0, _compare.default)(a.area(), b.area());
}
});
var r1 = void 0,
r2 = void 0;
QUnit.module('Comparable', {
setup: function () {
r1 = Rectangle.create({ length: 6, width: 12 });
r2 = Rectangle.create({ length: 6, width: 13 });
}
});
QUnit.test('should be comparable and return the correct result', function () {
equal(_comparable.default.detect(r1), true);
equal((0, _compare.default)(r1, r1), 0);
equal((0, _compare.default)(r1, r2), -1);
equal((0, _compare.default)(r2, r1), 1);
});
});
enifed('ember-runtime/tests/mixins/container_proxy_test', ['ember-utils', 'container', 'ember-runtime/mixins/container_proxy', 'ember-runtime/system/object'], function (_emberUtils, _container, _container_proxy, _object) {
'use strict';
QUnit.module('ember-runtime/mixins/container_proxy', {
setup: function () {
this.Owner = _object.default.extend(_container_proxy.default);
this.instance = this.Owner.create();
var registry = new _container.Registry();
this.instance.__container__ = new _container.Container(registry, {
owner: this.instance
});
}
});
QUnit.test('provides ownerInjection helper method', function (assert) {
var result = this.instance.ownerInjection();
assert.equal(result[_emberUtils.OWNER], this.instance, 'returns an object with the OWNER symbol');
});
});
enifed('ember-runtime/tests/mixins/copyable_test', ['ember-utils', 'ember-runtime/tests/suites/copyable', 'ember-runtime/mixins/copyable', 'ember-runtime/mixins/freezable', 'ember-runtime/system/object', 'ember-metal'], function (_emberUtils, _copyable, _copyable2, _freezable, _object, _emberMetal) {
'use strict';
QUnit.module('Ember.Copyable.frozenCopy');
QUnit.test('should be deprecated', function () {
expectDeprecation('`frozenCopy` is deprecated, use `Object.freeze` instead.');
var Obj = _object.default.extend(_freezable.Freezable, _copyable2.default, {
copy: function () {
return Obj.create();
}
});
Obj.create().frozenCopy();
});
var CopyableObject = _object.default.extend(_copyable2.default, {
id: null,
init: function () {
this._super.apply(this, arguments);
(0, _emberMetal.set)(this, 'id', (0, _emberUtils.generateGuid)());
},
copy: function () {
var ret = new CopyableObject();
(0, _emberMetal.set)(ret, 'id', (0, _emberMetal.get)(this, 'id'));
return ret;
}
});
_copyable.default.extend({
name: 'Copyable Basic Test',
newObject: function () {
return new CopyableObject();
},
isEqual: function (a, b) {
if (!(a instanceof CopyableObject) || !(b instanceof CopyableObject)) {
return false;
}
return (0, _emberMetal.get)(a, 'id') === (0, _emberMetal.get)(b, 'id');
}
}).run();
});
enifed('ember-runtime/tests/mixins/enumerable_test', ['ember-runtime/tests/suites/enumerable', 'ember-runtime/system/object', 'ember-runtime/mixins/enumerable', 'ember-runtime/mixins/array', 'ember-runtime/system/native_array', 'ember-metal'], function (_enumerable, _object, _enumerable2, _array, _native_array, _emberMetal) {
'use strict';
function K() {
return this;
}
/*
Implement a basic fake enumerable. This validates that any non-native
enumerable can impl this API.
*/
var TestEnumerable = _object.default.extend(_enumerable2.default, {
_content: null,
init: function () {
var ary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
this._content = ary;
},
addObject: function (obj) {
if (this._content.indexOf(obj) >= 0) {
return this;
}
this._content.push(obj);
this.enumerableContentDidChange();
},
nextObject: function (idx) {
return idx >= (0, _emberMetal.get)(this, 'length') ? undefined : this._content[idx];
},
length: (0, _emberMetal.computed)(function () {
return this._content.length;
}),
slice: function () {
return this._content.slice();
}
});
_enumerable.default.extend({
name: 'Basic Enumerable',
newObject: function (ary) {
ary = ary ? ary.slice() : this.newFixture(3);
return new TestEnumerable(ary);
},
mutate: function (obj) {
obj.addObject(obj._content.length + 1);
},
toArray: function (obj) {
return obj.slice();
}
}).run();
QUnit.module('Ember.Enumerable');
QUnit.test('should apply Ember.Array to return value of map', function () {
var x = _object.default.extend(_enumerable2.default).create();
var y = x.map(K);
equal(_array.default.detect(y), true, 'should have mixin applied');
});
QUnit.test('should apply Ember.Array to return value of filter', function () {
var x = _object.default.extend(_enumerable2.default).create();
var y = x.filter(K);
equal(_array.default.detect(y), true, 'should have mixin applied');
});
QUnit.test('should apply Ember.Array to return value of invoke', function () {
var x = _object.default.extend(_enumerable2.default).create();
var y = x.invoke(K);
equal(_array.default.detect(y), true, 'should have mixin applied');
});
QUnit.test('should apply Ember.Array to return value of toArray', function () {
var x = _object.default.extend(_enumerable2.default).create();
var y = x.toArray(K);
equal(_array.default.detect(y), true, 'should have mixin applied');
});
QUnit.test('should apply Ember.Array to return value of without', function () {
var X = _object.default.extend(_enumerable2.default, {
contains: function () {
return true;
},
includes: function () {
return true;
}
});
var x = X.create();
var y = x.without(K);
equal(_array.default.detect(y), true, 'should have mixin applied');
});
QUnit.test('should apply Ember.Array to return value of uniq', function () {
var x = _object.default.extend(_enumerable2.default).create();
var y = x.uniq(K);
equal(_array.default.detect(y), true, 'should have mixin applied');
});
QUnit.test('any', function () {
var kittens = (0, _native_array.A)([{
color: 'white'
}, {
color: 'black'
}, {
color: 'white'
}]);
var foundWhite = kittens.any(function (kitten) {
return kitten.color === 'white';
});
var foundWhite2 = kittens.isAny('color', 'white');
equal(foundWhite, true);
equal(foundWhite2, true);
});
QUnit.test('any with NaN', function () {
var numbers = (0, _native_array.A)([1, 2, NaN, 4]);
var hasNaN = numbers.any(function (n) {
return isNaN(n);
});
equal(hasNaN, true, 'works when matching NaN');
});
QUnit.test('every', function () {
var allColorsKittens = (0, _native_array.A)([{
color: 'white'
}, {
color: 'black'
}, {
color: 'white'
}]);
var allWhiteKittens = (0, _native_array.A)([{
color: 'white'
}, {
color: 'white'
}, {
color: 'white'
}]);
var allWhite = false;
var whiteKittenPredicate = function (kitten) {
return kitten.color === 'white';
};
allWhite = allColorsKittens.every(whiteKittenPredicate);
equal(allWhite, false);
allWhite = allWhiteKittens.every(whiteKittenPredicate);
equal(allWhite, true);
allWhite = allColorsKittens.isEvery('color', 'white');
equal(allWhite, false);
allWhite = allWhiteKittens.isEvery('color', 'white');
equal(allWhite, true);
});
QUnit.test('should throw an error passing a second argument to includes', function () {
var x = _object.default.extend(_enumerable2.default).create();
equal(x.includes('any'), false);
expectAssertion(function () {
x.includes('any', 1);
}, /Enumerable#includes cannot accept a second argument "startAt" as enumerable items are unordered./);
});
// ..........................................................
// CONTENT DID CHANGE
//
var DummyEnum = _object.default.extend(_enumerable2.default, {
nextObject: function () {},
length: 0
});
var obj = void 0,
observer = void 0;
// ..........................................................
// NOTIFY ENUMERABLE PROPERTY
//
QUnit.module('mixins/enumerable/enumerableContentDidChange');
QUnit.test('should notify observers of []', function () {
var obj = _object.default.extend(_enumerable2.default, {
nextObject: function () {},
// avoid exceptions
enumerablePropertyDidChange: (0, _emberMetal.observer)('[]', function () {
this._count++;
})
}).create({
_count: 0
});
equal(obj._count, 0, 'should not have invoked yet');
obj.enumerableContentWillChange();
obj.enumerableContentDidChange();
equal(obj._count, 1, 'should have invoked');
});
// ..........................................................
// NOTIFY CHANGES TO LENGTH
//
QUnit.module('notify observers of length', {
setup: function () {
obj = DummyEnum.extend({
lengthDidChange: (0, _emberMetal.observer)('length', function () {
this._after++;
})
}).create({
_after: 0
});
equal(obj._after, 0, 'should not have fired yet');
},
teardown: function () {
obj = null;
}
});
QUnit.test('should notify observers when call with no params', function () {
obj.enumerableContentWillChange();
equal(obj._after, 0);
obj.enumerableContentDidChange();
equal(obj._after, 1);
});
// API variation that included items only
QUnit.test('should not notify when passed arrays of same length', function () {
var added = ['foo'];
var removed = ['bar'];
obj.enumerableContentWillChange(removed, added);
equal(obj._after, 0);
obj.enumerableContentDidChange(removed, added);
equal(obj._after, 0);
});
QUnit.test('should notify when passed arrays of different length', function () {
var added = ['foo'];
var removed = ['bar', 'baz'];
obj.enumerableContentWillChange(removed, added);
equal(obj._after, 0);
obj.enumerableContentDidChange(removed, added);
equal(obj._after, 1);
});
// API variation passes indexes only
QUnit.test('should not notify when passed with indexes', function () {
obj.enumerableContentWillChange(1, 1);
equal(obj._after, 0);
obj.enumerableContentDidChange(1, 1);
equal(obj._after, 0);
});
QUnit.test('should notify when passed old index API with delta', function () {
obj.enumerableContentWillChange(1, 2);
equal(obj._after, 0);
obj.enumerableContentDidChange(1, 2);
equal(obj._after, 1);
});
// ..........................................................
// NOTIFY ENUMERABLE OBSERVER
//
QUnit.module('notify enumerable observers', {
setup: function () {
obj = DummyEnum.create();
observer = _object.default.extend({
enumerableWillChange: function () {
equal(this._before, null); // should only call once
this._before = Array.prototype.slice.call(arguments);
},
enumerableDidChange: function () {
equal(this._after, null); // should only call once
this._after = Array.prototype.slice.call(arguments);
}
}).create({
_before: null,
_after: null
});
obj.addEnumerableObserver(observer);
},
teardown: function () {
obj = observer = null;
}
});
QUnit.test('should notify enumerable observers when called with no params', function () {
obj.enumerableContentWillChange();
deepEqual(observer._before, [obj, null, null]);
obj.enumerableContentDidChange();
deepEqual(observer._after, [obj, null, null]);
});
// API variation that included items only
QUnit.test('should notify when called with same length items', function () {
var added = ['foo'];
var removed = ['bar'];
obj.enumerableContentWillChange(removed, added);
deepEqual(observer._before, [obj, removed, added]);
obj.enumerableContentDidChange(removed, added);
deepEqual(observer._after, [obj, removed, added]);
});
QUnit.test('should notify when called with diff length items', function () {
var added = ['foo', 'baz'];
var removed = ['bar'];
obj.enumerableContentWillChange(removed, added);
deepEqual(observer._before, [obj, removed, added]);
obj.enumerableContentDidChange(removed, added);
deepEqual(observer._after, [obj, removed, added]);
});
QUnit.test('should not notify when passed with indexes only', function () {
obj.enumerableContentWillChange(1, 2);
deepEqual(observer._before, [obj, 1, 2]);
obj.enumerableContentDidChange(1, 2);
deepEqual(observer._after, [obj, 1, 2]);
});
QUnit.test('removing enumerable observer should disable', function () {
obj.removeEnumerableObserver(observer);
obj.enumerableContentWillChange();
deepEqual(observer._before, null);
obj.enumerableContentDidChange();
deepEqual(observer._after, null);
});
});
enifed('ember-runtime/tests/mixins/freezable_test', ['ember-runtime/system/object', 'ember-runtime/mixins/freezable'], function (_object, _freezable) {
'use strict';
QUnit.module('Ember.Freezable');
QUnit.test('should be deprecated', function () {
expectDeprecation('`Ember.Freezable` is deprecated, use `Object.freeze` instead.');
_object.default.extend(_freezable.Freezable).create();
});
});
enifed('ember-runtime/tests/mixins/mutable_array_test', ['ember-metal', 'ember-runtime/tests/suites/mutable_array', 'ember-runtime/mixins/mutable_array', 'ember-runtime/system/object', 'ember-runtime/system/native_array', 'ember-runtime/mixins/array'], function (_emberMetal, _mutable_array, _mutable_array2, _object, _native_array, _array) {
'use strict';
/*
Implement a basic fake mutable array. This validates that any non-native
enumerable can impl this API.
*/
var TestMutableArray = _object.default.extend(_mutable_array2.default, {
_content: null,
init: function () {
var ary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
this._content = (0, _native_array.A)(ary);
},
replace: function (idx, amt, objects) {
var args = objects ? objects.slice() : [];
var removeAmt = amt;
var addAmt = args.length;
(0, _array.arrayContentWillChange)(this, idx, removeAmt, addAmt);
args.unshift(amt);
args.unshift(idx);
this._content.splice.apply(this._content, args);
(0, _array.arrayContentDidChange)(this, idx, removeAmt, addAmt);
return this;
},
objectAt: function (idx) {
return this._content[idx];
},
length: (0, _emberMetal.computed)(function () {
return this._content.length;
}),
slice: function () {
return this._content.slice();
}
});
_mutable_array.default.extend({
name: 'Basic Mutable Array',
newObject: function (ary) {
ary = ary ? ary.slice() : this.newFixture(3);
return new TestMutableArray(ary);
},
mutate: function (obj) {
obj.addObject(this.getFixture(1)[0]);
},
toArray: function (obj) {
return obj.slice();
}
}).run();
});
enifed('ember-runtime/tests/mixins/mutable_enumerable_test', ['ember-runtime/tests/suites/mutable_enumerable', 'ember-runtime/mixins/mutable_enumerable', 'ember-runtime/system/object', 'ember-metal'], function (_mutable_enumerable, _mutable_enumerable2, _object, _emberMetal) {
'use strict';
/*
Implement a basic fake mutable array. This validates that any non-native
enumerable can impl this API.
*/
var TestMutableEnumerable = _object.default.extend(_mutable_enumerable2.default, {
_content: null,
addObject: function (obj) {
if (this._content.indexOf(obj) >= 0) {
return this;
}
this.enumerableContentWillChange(null, [obj]);
this._content.push(obj);
this.enumerableContentDidChange(null, [obj]);
},
removeObject: function (obj) {
var idx = this._content.indexOf(obj);
if (idx < 0) {
return this;
}
this.enumerableContentWillChange([obj], null);
this._content.splice(idx, 1);
this.enumerableContentDidChange([obj], null);
return this;
},
init: function (ary) {
this._content = ary || [];
},
nextObject: function (idx) {
return idx >= (0, _emberMetal.get)(this, 'length') ? undefined : this._content[idx];
},
length: (0, _emberMetal.computed)(function () {
return this._content.length;
}),
slice: function () {
return this._content.slice();
}
});
_mutable_enumerable.default.extend({
name: 'Basic Mutable Array',
newObject: function (ary) {
ary = ary ? ary.slice() : this.newFixture(3);
return new TestMutableEnumerable(ary);
},
mutate: function (obj) {
obj.addObject(this.getFixture(1)[0]);
},
toArray: function (obj) {
return obj.slice();
}
}).run();
});
enifed('ember-runtime/tests/mixins/observable_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object'], function (_emberMetal, _internalTestHelpers, _object) {
'use strict';
QUnit.module('mixins/observable');
QUnit.test('should be able to use getProperties to get a POJO of provided keys', function () {
var obj = _object.default.create({
firstName: 'Steve',
lastName: 'Jobs',
companyName: 'Apple, Inc.'
});
var pojo = obj.getProperties('firstName', 'lastName');
equal('Steve', pojo.firstName);
equal('Jobs', pojo.lastName);
});
QUnit.test('should be able to use getProperties with array parameter to get a POJO of provided keys', function () {
var obj = _object.default.create({
firstName: 'Steve',
lastName: 'Jobs',
companyName: 'Apple, Inc.'
});
var pojo = obj.getProperties(['firstName', 'lastName']);
equal('Steve', pojo.firstName);
equal('Jobs', pojo.lastName);
});
QUnit.test('should be able to use setProperties to set multiple properties at once', function () {
var obj = _object.default.create({
firstName: 'Steve',
lastName: 'Jobs',
companyName: 'Apple, Inc.'
});
obj.setProperties({ firstName: 'Tim', lastName: 'Cook' });
equal('Tim', obj.get('firstName'));
equal('Cook', obj.get('lastName'));
});
(0, _internalTestHelpers.testBoth)('calling setProperties completes safely despite exceptions', function () {
var exc = new Error('Something unexpected happened!');
var obj = _object.default.extend({
companyName: (0, _emberMetal.computed)({
get: function () {
return 'Apple, Inc.';
},
set: function () {
throw exc;
}
})
}).create({
firstName: 'Steve',
lastName: 'Jobs'
});
var firstNameChangedCount = 0;
(0, _emberMetal.addObserver)(obj, 'firstName', function () {
return firstNameChangedCount++;
});
try {
obj.setProperties({
firstName: 'Tim',
lastName: 'Cook',
companyName: 'Fruit Co., Inc.'
});
} catch (err) {
if (err !== exc) {
throw err;
}
}
equal(firstNameChangedCount, 1, 'firstName should have fired once');
});
(0, _internalTestHelpers.testBoth)('should be able to retrieve cached values of computed properties without invoking the computed property', function (get) {
var obj = _object.default.extend({
foo: (0, _emberMetal.computed)(function () {
return 'foo';
})
}).create({
bar: 'bar'
});
equal(obj.cacheFor('foo'), undefined, 'should return undefined if no value has been cached');
get(obj, 'foo');
equal(get(obj, 'foo'), 'foo', 'precond - should cache the value');
equal(obj.cacheFor('foo'), 'foo', 'should return the cached value after it is invoked');
equal(obj.cacheFor('bar'), undefined, 'returns undefined if the value is not a computed property');
});
QUnit.test('incrementProperty should work even if value is number in string', function () {
var obj = _object.default.create({
age: '24'
});
obj.incrementProperty('age');
equal(25, obj.get('age'));
});
});
enifed('ember-runtime/tests/mixins/promise_proxy_test', ['ember-metal', 'ember-runtime/system/object_proxy', 'ember-runtime/mixins/promise_proxy', 'ember-runtime/ext/rsvp', 'rsvp'], function (_emberMetal, _object_proxy, _promise_proxy, _rsvp, _rsvp2) {
'use strict';
var ObjectPromiseProxy = void 0;
QUnit.test('present on ember namespace', function () {
ok(_promise_proxy.default, 'expected PromiseProxyMixin to exist');
});
QUnit.module('Ember.PromiseProxy - ObjectProxy', {
setup: function () {
ObjectPromiseProxy = _object_proxy.default.extend(_promise_proxy.default);
},
teardown: function () {
_rsvp2.on('error', _rsvp.onerrorDefault);
}
});
QUnit.test('no promise, invoking then should raise', function () {
var proxy = ObjectPromiseProxy.create();
throws(function () {
proxy.then(function () {
return this;
}, function () {
return this;
});
}, new RegExp('PromiseProxy\'s promise must be set'));
});
QUnit.test('fulfillment', function () {
var value = {
firstName: 'stef',
lastName: 'penner'
};
var deferred = _rsvp2.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
var didFulfillCount = 0;
var didRejectCount = 0;
proxy.then(function () {
return didFulfillCount++;
}, function () {
return didRejectCount++;
});
equal((0, _emberMetal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content');
equal((0, _emberMetal.get)(proxy, 'reason'), undefined, 'expects the proxy to have no reason');
equal((0, _emberMetal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading');
equal((0, _emberMetal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled');
equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
equal(didFulfillCount, 0, 'should not yet have been fulfilled');
equal(didRejectCount, 0, 'should not yet have been rejected');
(0, _emberMetal.run)(deferred, 'resolve', value);
equal(didFulfillCount, 1, 'should have been fulfilled');
equal(didRejectCount, 0, 'should not have been rejected');
equal((0, _emberMetal.get)(proxy, 'content'), value, 'expects the proxy to have content');
equal((0, _emberMetal.get)(proxy, 'reason'), undefined, 'expects the proxy to still have no reason');
equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is no longer loading');
equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
equal((0, _emberMetal.get)(proxy, 'isFulfilled'), true, 'expects the proxy to indicate that it is fulfilled');
(0, _emberMetal.run)(deferred, 'resolve', value);
equal(didFulfillCount, 1, 'should still have been only fulfilled once');
equal(didRejectCount, 0, 'should still not have been rejected');
(0, _emberMetal.run)(deferred, 'reject', value);
equal(didFulfillCount, 1, 'should still have been only fulfilled once');
equal(didRejectCount, 0, 'should still not have been rejected');
equal((0, _emberMetal.get)(proxy, 'content'), value, 'expects the proxy to have still have same content');
equal((0, _emberMetal.get)(proxy, 'reason'), undefined, 'expects the proxy still to have no reason');
equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is no longer loading');
equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
equal((0, _emberMetal.get)(proxy, 'isFulfilled'), true, 'expects the proxy to indicate that it is fulfilled');
// rest of the promise semantics are tested in directly in RSVP
});
QUnit.test('rejection', function () {
var reason = new Error('failure');
var deferred = _rsvp2.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
var didFulfillCount = 0;
var didRejectCount = 0;
proxy.then(function () {
return didFulfillCount++;
}, function () {
return didRejectCount++;
});
equal((0, _emberMetal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content');
equal((0, _emberMetal.get)(proxy, 'reason'), undefined, 'expects the proxy to have no reason');
equal((0, _emberMetal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading');
equal((0, _emberMetal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled');
equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
equal(didFulfillCount, 0, 'should not yet have been fulfilled');
equal(didRejectCount, 0, 'should not yet have been rejected');
(0, _emberMetal.run)(deferred, 'reject', reason);
equal(didFulfillCount, 0, 'should not yet have been fulfilled');
equal(didRejectCount, 1, 'should have been rejected');
equal((0, _emberMetal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content');
equal((0, _emberMetal.get)(proxy, 'reason'), reason, 'expects the proxy to have a reason');
equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is not longer loading');
equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
equal((0, _emberMetal.get)(proxy, 'isRejected'), true, 'expects the proxy to indicate that it is rejected');
equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
(0, _emberMetal.run)(deferred, 'reject', reason);
equal(didFulfillCount, 0, 'should stll not yet have been fulfilled');
equal(didRejectCount, 1, 'should still remain rejected');
(0, _emberMetal.run)(deferred, 'resolve', 1);
equal(didFulfillCount, 0, 'should stll not yet have been fulfilled');
equal(didRejectCount, 1, 'should still remain rejected');
equal((0, _emberMetal.get)(proxy, 'content'), undefined, 'expects the proxy to have no content');
equal((0, _emberMetal.get)(proxy, 'reason'), reason, 'expects the proxy to have a reason');
equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is not longer loading');
equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
equal((0, _emberMetal.get)(proxy, 'isRejected'), true, 'expects the proxy to indicate that it is rejected');
equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
});
QUnit.test('unhandled rejects still propagate to RSVP.on(\'error\', ...) ', function () {
expect(1);
_rsvp2.on('error', onerror);
_rsvp2.off('error', _rsvp.onerrorDefault);
var expectedReason = new Error('failure');
var deferred = _rsvp2.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.get('promise');
function onerror(reason) {
equal(reason, expectedReason, 'expected reason');
}
_rsvp2.on('error', onerror);
_rsvp2.off('error', _rsvp.onerrorDefault);
(0, _emberMetal.run)(deferred, 'reject', expectedReason);
_rsvp2.on('error', _rsvp.onerrorDefault);
_rsvp2.off('error', onerror);
(0, _emberMetal.run)(deferred, 'reject', expectedReason);
_rsvp2.on('error', _rsvp.onerrorDefault);
_rsvp2.off('error', onerror);
});
QUnit.test('should work with promise inheritance', function () {
function PromiseSubclass() {
_rsvp2.Promise.apply(this, arguments);
}
PromiseSubclass.prototype = Object.create(_rsvp2.Promise.prototype);
PromiseSubclass.prototype.constructor = PromiseSubclass;
PromiseSubclass.cast = _rsvp2.Promise.cast;
var proxy = ObjectPromiseProxy.create({
promise: new PromiseSubclass(function () {})
});
ok(proxy.then() instanceof PromiseSubclass, 'promise proxy respected inheritance');
});
QUnit.test('should reset isFulfilled and isRejected when promise is reset', function () {
var deferred = _rsvp.default.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
equal((0, _emberMetal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading');
equal((0, _emberMetal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled');
equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
(0, _emberMetal.run)(deferred, 'resolve');
equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is no longer loading');
equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
equal((0, _emberMetal.get)(proxy, 'isFulfilled'), true, 'expects the proxy to indicate that it is fulfilled');
var anotherDeferred = _rsvp.default.defer();
proxy.set('promise', anotherDeferred.promise);
equal((0, _emberMetal.get)(proxy, 'isPending'), true, 'expects the proxy to indicate that it is loading');
equal((0, _emberMetal.get)(proxy, 'isSettled'), false, 'expects the proxy to indicate that it is not settled');
equal((0, _emberMetal.get)(proxy, 'isRejected'), false, 'expects the proxy to indicate that it is not rejected');
equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
(0, _emberMetal.run)(anotherDeferred, 'reject');
equal((0, _emberMetal.get)(proxy, 'isPending'), false, 'expects the proxy to indicate that it is not longer loading');
equal((0, _emberMetal.get)(proxy, 'isSettled'), true, 'expects the proxy to indicate that it is settled');
equal((0, _emberMetal.get)(proxy, 'isRejected'), true, 'expects the proxy to indicate that it is rejected');
equal((0, _emberMetal.get)(proxy, 'isFulfilled'), false, 'expects the proxy to indicate that it is not fulfilled');
});
QUnit.test('should have content when isFulfilled is set', function () {
var deferred = _rsvp.default.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.addObserver('isFulfilled', function () {
return equal((0, _emberMetal.get)(proxy, 'content'), true);
});
(0, _emberMetal.run)(deferred, 'resolve', true);
});
QUnit.test('should have reason when isRejected is set', function () {
var error = new Error('Y U REJECT?!?');
var deferred = _rsvp.default.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.addObserver('isRejected', function () {
return equal((0, _emberMetal.get)(proxy, 'reason'), error);
});
try {
(0, _emberMetal.run)(deferred, 'reject', error);
} catch (e) {
equal(e, error);
}
});
QUnit.test('should not error if promise is resolved after proxy has been destroyed', function () {
var deferred = _rsvp.default.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.then(function () {}, function () {});
(0, _emberMetal.run)(proxy, 'destroy');
(0, _emberMetal.run)(deferred, 'resolve', true);
ok(true, 'resolving the promise after the proxy has been destroyed does not raise an error');
});
QUnit.test('should not error if promise is rejected after proxy has been destroyed', function () {
var deferred = _rsvp.default.defer();
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.then(function () {}, function () {});
(0, _emberMetal.run)(proxy, 'destroy');
(0, _emberMetal.run)(deferred, 'reject', 'some reason');
ok(true, 'rejecting the promise after the proxy has been destroyed does not raise an error');
});
QUnit.test('promise chain is not broken if promised is resolved after proxy has been destroyed', function () {
var deferred = _rsvp.default.defer();
var expectedValue = {};
var receivedValue = void 0;
var didResolveCount = 0;
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.then(function (value) {
receivedValue = value;
didResolveCount++;
}, function () {});
(0, _emberMetal.run)(proxy, 'destroy');
(0, _emberMetal.run)(deferred, 'resolve', expectedValue);
equal(didResolveCount, 1, 'callback called');
equal(receivedValue, expectedValue, 'passed value is the value the promise was resolved with');
});
QUnit.test('promise chain is not broken if promised is rejected after proxy has been destroyed', function () {
var deferred = _rsvp.default.defer();
var expectedReason = 'some reason';
var receivedReason = void 0;
var didRejectCount = 0;
var proxy = ObjectPromiseProxy.create({
promise: deferred.promise
});
proxy.then(function () {}, function (reason) {
receivedReason = reason;
didRejectCount++;
});
(0, _emberMetal.run)(proxy, 'destroy');
(0, _emberMetal.run)(deferred, 'reject', expectedReason);
equal(didRejectCount, 1, 'callback called');
equal(receivedReason, expectedReason, 'passed reason is the reason the promise was rejected for');
});
});
enifed('ember-runtime/tests/mixins/target_action_support_test', ['ember-environment', 'ember-runtime/system/object', 'ember-runtime/mixins/target_action_support'], function (_emberEnvironment, _object, _target_action_support) {
'use strict';
var originalLookup = _emberEnvironment.context.lookup;
var lookup = void 0;
QUnit.module('TargetActionSupport', {
setup: function () {
_emberEnvironment.context.lookup = lookup = {};
},
teardown: function () {
_emberEnvironment.context.lookup = originalLookup;
}
});
QUnit.test('it should return false if no target or action are specified', function () {
expect(1);
var obj = _object.default.extend(_target_action_support.default).create();
ok(false === obj.triggerAction(), 'no target or action was specified');
});
QUnit.test('it should support actions specified as strings', function () {
expect(2);
var obj = _object.default.extend(_target_action_support.default).create({
target: _object.default.create({
anEvent: function () {
ok(true, 'anEvent method was called');
}
}),
action: 'anEvent'
});
ok(true === obj.triggerAction(), 'a valid target and action were specified');
});
QUnit.test('it should invoke the send() method on objects that implement it', function () {
expect(3);
var obj = _object.default.extend(_target_action_support.default).create({
target: _object.default.create({
send: function (evt, context) {
equal(evt, 'anEvent', 'send() method was invoked with correct event name');
equal(context, obj, 'send() method was invoked with correct context');
}
}),
action: 'anEvent'
});
ok(true === obj.triggerAction(), 'a valid target and action were specified');
});
QUnit.test('it should find targets specified using a property path', function () {
expect(2);
var Test = {};
lookup.Test = Test;
Test.targetObj = _object.default.create({
anEvent: function () {
ok(true, 'anEvent method was called on global object');
}
});
var myObj = _object.default.extend(_target_action_support.default).create({
target: 'Test.targetObj',
action: 'anEvent'
});
ok(true === myObj.triggerAction(), 'a valid target and action were specified');
});
QUnit.test('it should use an actionContext object specified as a property on the object', function () {
expect(2);
var obj = _object.default.extend(_target_action_support.default).create({
action: 'anEvent',
actionContext: {},
target: _object.default.create({
anEvent: function (ctx) {
ok(obj.actionContext === ctx, 'anEvent method was called with the expected context');
}
})
});
ok(true === obj.triggerAction(), 'a valid target and action were specified');
});
QUnit.test('it should find an actionContext specified as a property path', function () {
expect(2);
var Test = {};
lookup.Test = Test;
Test.aContext = {};
var obj = _object.default.extend(_target_action_support.default).create({
action: 'anEvent',
actionContext: 'Test.aContext',
target: _object.default.create({
anEvent: function (ctx) {
ok(Test.aContext === ctx, 'anEvent method was called with the expected context');
}
})
});
ok(true === obj.triggerAction(), 'a valid target and action were specified');
});
QUnit.test('it should use the target specified in the argument', function () {
expect(2);
var targetObj = _object.default.create({
anEvent: function () {
ok(true, 'anEvent method was called');
}
});
var obj = _object.default.extend(_target_action_support.default).create({
action: 'anEvent'
});
ok(true === obj.triggerAction({ target: targetObj }), 'a valid target and action were specified');
});
QUnit.test('it should use the action specified in the argument', function () {
expect(2);
var obj = _object.default.extend(_target_action_support.default).create({
target: _object.default.create({
anEvent: function () {
ok(true, 'anEvent method was called');
}
})
});
ok(true === obj.triggerAction({ action: 'anEvent' }), 'a valid target and action were specified');
});
QUnit.test('it should use the actionContext specified in the argument', function () {
expect(2);
var context = {};
var obj = _object.default.extend(_target_action_support.default).create({
target: _object.default.create({
anEvent: function (ctx) {
ok(context === ctx, 'anEvent method was called with the expected context');
}
}),
action: 'anEvent'
});
ok(true === obj.triggerAction({ actionContext: context }), 'a valid target and action were specified');
});
QUnit.test('it should allow multiple arguments from actionContext', function () {
expect(3);
var param1 = 'someParam';
var param2 = 'someOtherParam';
var obj = _object.default.extend(_target_action_support.default).create({
target: _object.default.create({
anEvent: function (first, second) {
ok(first === param1, 'anEvent method was called with the expected first argument');
ok(second === param2, 'anEvent method was called with the expected second argument');
}
}),
action: 'anEvent'
});
ok(true === obj.triggerAction({ actionContext: [param1, param2] }), 'a valid target and action were specified');
});
QUnit.test('it should use a null value specified in the actionContext argument', function () {
expect(2);
var obj = _object.default.extend(_target_action_support.default).create({
target: _object.default.create({
anEvent: function (ctx) {
ok(null === ctx, 'anEvent method was called with the expected context (null)');
}
}),
action: 'anEvent'
});
ok(true === obj.triggerAction({ actionContext: null }), 'a valid target and action were specified');
});
});
enifed('ember-runtime/tests/suites/array', ['exports', 'ember-runtime/tests/suites/enumerable', 'ember-runtime/tests/suites/array/indexOf', 'ember-runtime/tests/suites/array/lastIndexOf', 'ember-runtime/tests/suites/array/objectAt', 'ember-runtime/tests/suites/array/includes', 'ember-runtime/mixins/array'], function (exports, _enumerable, _indexOf, _lastIndexOf, _objectAt, _includes, _array) {
'use strict';
exports.ObserverClass = exports.ArrayTests = undefined;
var ObserverClass = _enumerable.ObserverClass.extend({
observeArray: function (obj) {
(0, _array.addArrayObserver)(obj, this);
return this;
},
stopObserveArray: function (obj) {
(0, _array.removeArrayObserver)(obj, this);
return this;
},
arrayWillChange: function () {
equal(this._before, null, 'should only call once');
this._before = Array.prototype.slice.call(arguments);
},
arrayDidChange: function () {
equal(this._after, null, 'should only call once');
this._after = Array.prototype.slice.call(arguments);
}
});
var ArrayTests = _enumerable.EnumerableTests.extend({
observerClass: ObserverClass
});
ArrayTests.ObserverClass = ObserverClass;
ArrayTests.importModuleTests(_indexOf.default);
ArrayTests.importModuleTests(_lastIndexOf.default);
ArrayTests.importModuleTests(_objectAt.default);
ArrayTests.importModuleTests(_includes.default);
exports.ArrayTests = ArrayTests;
exports.ObserverClass = ObserverClass;
});
enifed('ember-runtime/tests/suites/array/includes', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('includes');
suite.test('includes returns correct value if startAt is positive', function () {
var data = this.newFixture(3);
var obj = this.newObject(data);
equal(obj.includes(data[1], 1), true, 'should return true if included');
equal(obj.includes(data[0], 1), false, 'should return false if not included');
});
suite.test('includes returns correct value if startAt is negative', function () {
var data = this.newFixture(3);
var obj = this.newObject(data);
equal(obj.includes(data[1], -2), true, 'should return true if included');
equal(obj.includes(data[0], -2), false, 'should return false if not included');
});
suite.test('includes returns true if startAt + length is still negative', function () {
var data = this.newFixture(1);
var obj = this.newObject(data);
equal(obj.includes(data[0], -2), true, 'should return true if included');
equal(obj.includes(this.newFixture(1), -2), false, 'should return false if not included');
});
suite.test('includes returns false if startAt out of bounds', function () {
var data = this.newFixture(1);
var obj = this.newObject(data);
equal(obj.includes(data[0], 2), false, 'should return false if startAt >= length');
equal(obj.includes(this.newFixture(1), 2), false, 'should return false if startAt >= length');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/array/indexOf', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('indexOf');
suite.test('should return index of object', function () {
var expected = this.newFixture(3),
idx;
var obj = this.newObject(expected);
for (idx = 0; idx < 3; idx++) {
equal(obj.indexOf(expected[idx]), idx, 'obj.indexOf(' + expected[idx] + ') should match idx');
}
});
suite.test('should return -1 when requesting object not in index', function () {
var obj = this.newObject(this.newFixture(3));
equal(obj.indexOf({}), -1, 'obj.indexOf(foo) should be < 0');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/array/lastIndexOf', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('lastIndexOf');
suite.test('should return index of object\'s last occurrence', function () {
var expected = this.newFixture(3),
idx;
var obj = this.newObject(expected);
for (idx = 0; idx < 3; idx++) {
equal(obj.lastIndexOf(expected[idx]), idx, 'obj.lastIndexOf(' + expected[idx] + ') should match idx');
}
});
suite.test('should return index of object\'s last occurrence even startAt search location is equal to length', function () {
var expected = this.newFixture(3),
idx;
var obj = this.newObject(expected);
var len = 3;
for (idx = 0; idx < len; idx++) {
equal(obj.lastIndexOf(expected[idx], len), idx, 'obj.lastIndexOfs(' + expected[idx] + ') should match idx');
}
});
suite.test('should return index of object\'s last occurrence even startAt search location is greater than length', function () {
var expected = this.newFixture(3),
idx;
var obj = this.newObject(expected);
var len = 3;
for (idx = 0; idx < len; idx++) {
equal(obj.lastIndexOf(expected[idx], len + 1), idx, 'obj.lastIndexOf(' + expected[idx] + ') should match idx');
}
});
suite.test('should return -1 when no match is found', function () {
var obj = this.newObject(this.newFixture(3));
equal(obj.lastIndexOf({}), -1, 'obj.lastIndexOf(foo) should be -1');
});
suite.test('should return -1 when no match is found even startAt search location is equal to length', function () {
var obj = this.newObject(this.newFixture(3));
equal(obj.lastIndexOf({}, obj.length), -1, 'obj.lastIndexOf(foo) should be -1');
});
suite.test('should return -1 when no match is found even startAt search location is greater than length', function () {
var obj = this.newObject(this.newFixture(3));
equal(obj.lastIndexOf({}, obj.length + 1), -1, 'obj.lastIndexOf(foo) should be -1');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/array/objectAt', ['exports', 'ember-runtime/tests/suites/suite', 'ember-runtime/mixins/array'], function (exports, _suite, _array) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('objectAt');
suite.test('should return object at specified index', function () {
var expected = this.newFixture(3),
idx;
var obj = this.newObject(expected);
var len = expected.length;
for (idx = 0; idx < len; idx++) {
equal((0, _array.objectAt)(obj, idx), expected[idx], 'obj.objectAt(' + idx + ') should match');
}
});
suite.test('should return undefined when requesting objects beyond index', function () {
var obj = void 0;
obj = this.newObject(this.newFixture(3));
equal((0, _array.objectAt)(obj, 5), undefined, 'should return undefined for obj.objectAt(5) when len = 3');
obj = this.newObject([]);
equal((0, _array.objectAt)(obj, 0), undefined, 'should return undefined for obj.objectAt(0) when len = 0');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/copyable', ['exports', 'ember-runtime/tests/suites/suite', 'ember-runtime/tests/suites/copyable/copy', 'ember-runtime/tests/suites/copyable/frozenCopy'], function (exports, _suite, _copy, _frozenCopy) {
'use strict';
var CopyableTests = _suite.Suite.extend({
/*
__Required.__ You must implement this method to apply this mixin.
Must be able to create a new object for testing.
@returns {Object} object
*/
newObject: null,
/*
__Required.__ You must implement this method to apply this mixin.
Compares the two passed in objects. Returns true if the two objects
are logically equivalent.
@param {Object} a
First object
@param {Object} b
Second object
@returns {Boolean}
*/
isEqual: null,
/*
Set this to true if you expect the objects you test to be freezable.
The suite will verify that your objects actually match this. (i.e. if
you say you can't test freezable it will verify that your objects really
aren't freezable.)
@type Boolean
*/
shouldBeFreezable: false
});
CopyableTests.importModuleTests(_copy.default);
CopyableTests.importModuleTests(_frozenCopy.default);
exports.default = CopyableTests;
});
enifed('ember-runtime/tests/suites/copyable/copy', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('copy');
suite.test('should return an equivalent copy', function () {
var obj = this.newObject();
var copy = obj.copy();
ok(this.isEqual(obj, copy), 'old object and new object should be equivalent');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/copyable/frozenCopy', ['exports', 'ember-runtime/tests/suites/suite', 'ember-runtime/mixins/freezable', 'ember-metal'], function (exports, _suite, _freezable, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('frozenCopy');
suite.test('frozen objects should return same instance', function () {
var obj = void 0,
copy = void 0;
obj = this.newObject();
if ((0, _emberMetal.get)(this, 'shouldBeFreezable')) {
expectDeprecation('`frozenCopy` is deprecated, use Object.freeze instead.');
ok(!_freezable.Freezable || _freezable.Freezable.detect(obj), 'object should be freezable');
copy = obj.frozenCopy();
ok(this.isEqual(obj, copy), 'new copy should be equal');
ok((0, _emberMetal.get)(copy, 'isFrozen'), 'returned value should be frozen');
copy = obj.freeze().frozenCopy();
equal(copy, obj, 'returns frozen object should be same');
ok((0, _emberMetal.get)(copy, 'isFrozen'), 'returned object should be frozen');
} else {
ok(!_freezable.Freezable || !_freezable.Freezable.detect(obj), 'object should not be freezable');
}
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable', ['exports', 'ember-utils', 'ember-runtime/tests/suites/suite', 'ember-runtime/system/object', 'ember-metal', 'ember-runtime/tests/suites/enumerable/any', 'ember-runtime/tests/suites/enumerable/is_any', 'ember-runtime/tests/suites/enumerable/compact', 'ember-runtime/tests/suites/enumerable/contains', 'ember-runtime/tests/suites/enumerable/includes', 'ember-runtime/tests/suites/enumerable/every', 'ember-runtime/tests/suites/enumerable/filter', 'ember-runtime/tests/suites/enumerable/find', 'ember-runtime/tests/suites/enumerable/firstObject', 'ember-runtime/tests/suites/enumerable/forEach', 'ember-runtime/tests/suites/enumerable/mapBy', 'ember-runtime/tests/suites/enumerable/invoke', 'ember-runtime/tests/suites/enumerable/lastObject', 'ember-runtime/tests/suites/enumerable/map', 'ember-runtime/tests/suites/enumerable/reduce', 'ember-runtime/tests/suites/enumerable/reject', 'ember-runtime/tests/suites/enumerable/sortBy', 'ember-runtime/tests/suites/enumerable/toArray', 'ember-runtime/tests/suites/enumerable/uniq', 'ember-runtime/tests/suites/enumerable/uniqBy', 'ember-runtime/tests/suites/enumerable/without'], function (exports, _emberUtils, _suite, _object, _emberMetal, _any, _is_any, _compact, _contains, _includes, _every, _filter, _find, _firstObject, _forEach, _mapBy, _invoke, _lastObject, _map, _reduce, _reject, _sortBy, _toArray, _uniq, _uniqBy, _without) {
'use strict';
exports.ObserverClass = exports.EnumerableTests = undefined;
var ObserverClass = _object.default.extend({
_keysBefore: null,
_keys: null,
_values: null,
_before: null,
_after: null,
isEnabled: true,
init: function () {
this._super.apply(this, arguments);
this.reset();
},
propertyWillChange: function (target, key) {
if (this._keysBefore[key] === undefined) {
this._keysBefore[key] = 0;
}
this._keysBefore[key]++;
},
propertyDidChange: function (target, key, value) {
if (this._keys[key] === undefined) {
this._keys[key] = 0;
}
this._keys[key]++;
this._values[key] = value;
},
reset: function () {
this._keysBefore = {};
this._keys = {};
this._values = {};
this._before = null;
this._after = null;
return this;
},
observeBefore: function (obj) {
var keys = Array.prototype.slice.call(arguments, 1);
var loc = keys.length;
while (--loc >= 0) {
(0, _emberMetal._addBeforeObserver)(obj, keys[loc], this, 'propertyWillChange');
}
return this;
},
observe: function (obj) {
var keys, loc;
if (obj.addObserver) {
keys = Array.prototype.slice.call(arguments, 1);
loc = keys.length;
while (--loc >= 0) {
obj.addObserver(keys[loc], this, 'propertyDidChange');
}
} else {
this.isEnabled = false;
}
return this;
},
validate: function (key, value) {
if (!this.isEnabled) {
return true;
}
if (!this._keys[key]) {
return false;
}
if (arguments.length > 1) {
return this._values[key] === value;
} else {
return true;
}
},
timesCalledBefore: function (key) {
return this._keysBefore[key] || 0;
},
timesCalled: function (key) {
return this._keys[key] || 0;
},
observeEnumerable: function (obj) {
obj.addEnumerableObserver(this);
return this;
},
stopObserveEnumerable: function (obj) {
obj.removeEnumerableObserver(this);
return this;
},
enumerableWillChange: function () {
equal(this._before, null, 'should only call once');
this._before = Array.prototype.slice.call(arguments);
},
enumerableDidChange: function () {
equal(this._after, null, 'should only call once');
this._after = Array.prototype.slice.call(arguments);
}
});
var EnumerableTests = _suite.Suite.extend({
/*
__Required.__ You must implement this method to apply this mixin.
Implement to return a new enumerable object for testing. Should accept
either no parameters, a single number (indicating the desired length of
the collection) or an array of objects.
@param {Array} content
An array of items to include in the enumerable optionally.
@returns {Ember.Enumerable} a new enumerable
*/
newObject: null,
newFixture: function (cnt) {
var ret = [];
while (--cnt >= 0) {
ret.push((0, _emberUtils.generateGuid)());
}
return ret;
},
newObjectsFixture: function (cnt) {
var ret = [];
var item = void 0;
while (--cnt >= 0) {
item = {};
(0, _emberUtils.guidFor)(item);
ret.push(item);
}
return ret;
},
/*
__Required.__ You must implement this method to apply this mixin.
Implement accept an instance of the enumerable and return an array
containing the objects in the enumerable. This is used only for testing
so performance is not important.
@param {Ember.Enumerable} enumerable
The enumerable to convert.
@returns {Array} array of items
*/
toArray: null,
mutate: function () {},
/*
Becomes true when you define a new mutate() method, indicating that
mutation tests should run. This is calculated automatically.
@type Boolean
*/
canTestMutation: (0, _emberMetal.computed)(function () {
return this.mutate !== EnumerableTests.prototype.mutate;
}),
run: function () {},
newObserver: function () {
var ret = (0, _emberMetal.get)(this, 'observerClass').create();
if (arguments.length > 0) {
ret.observeBefore.apply(ret, arguments);
}
if (arguments.length > 0) {
ret.observe.apply(ret, arguments);
}
return ret;
},
observerClass: ObserverClass
});
EnumerableTests.importModuleTests(_any.default);
EnumerableTests.importModuleTests(_is_any.default);
EnumerableTests.importModuleTests(_compact.default);
EnumerableTests.importModuleTests(_contains.default);
EnumerableTests.importModuleTests(_every.default);
EnumerableTests.importModuleTests(_filter.default);
EnumerableTests.importModuleTests(_find.default);
EnumerableTests.importModuleTests(_firstObject.default);
EnumerableTests.importModuleTests(_forEach.default);
EnumerableTests.importModuleTests(_mapBy.default);
EnumerableTests.importModuleTests(_invoke.default);
EnumerableTests.importModuleTests(_lastObject.default);
EnumerableTests.importModuleTests(_map.default);
EnumerableTests.importModuleTests(_reduce.default);
EnumerableTests.importModuleTests(_reject.default);
EnumerableTests.importModuleTests(_sortBy.default);
EnumerableTests.importModuleTests(_toArray.default);
EnumerableTests.importModuleTests(_uniq.default);
EnumerableTests.importModuleTests(_uniqBy.default);
EnumerableTests.importModuleTests(_includes.default);
EnumerableTests.importModuleTests(_without.default);
exports.default = EnumerableTests;
exports.EnumerableTests = EnumerableTests;
exports.ObserverClass = ObserverClass;
});
enifed('ember-runtime/tests/suites/enumerable/any', ['exports', 'ember-runtime/tests/suites/suite', 'ember-runtime/system/native_array'], function (exports, _suite, _native_array) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
// ..........................................................
// any()
//
suite.module('any');
suite.test('any should should invoke callback on each item as long as you return false', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
var found = [];
var result = void 0;
result = obj.any(function (i) {
found.push(i);
return false;
});
equal(result, false, 'return value of obj.any');
deepEqual(found, ary, 'items passed during any() should match');
});
suite.test('any should stop invoking when you return true', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
var cnt = ary.length - 2;
var exp = cnt;
var found = [];
var result = void 0;
result = obj.any(function (i) {
found.push(i);
return --cnt <= 0;
});
equal(result, true, 'return value of obj.any');
equal(found.length, exp, 'should invoke proper number of times');
deepEqual(found, ary.slice(0, -2), 'items passed during any() should match');
});
suite.test('any should return true if any object matches the callback', function () {
var obj = (0, _native_array.A)([0, 1, 2]);
var result = void 0;
result = obj.any(function (i) {
return !!i;
});
equal(result, true, 'return value of obj.any');
});
suite.test('any should return false if no object matches the callback', function () {
var obj = (0, _native_array.A)([0, null, false]);
var result = void 0;
result = obj.any(function (i) {
return !!i;
});
equal(result, false, 'return value of obj.any');
});
suite.test('any should produce correct results even if the matching element is undefined', function () {
var obj = (0, _native_array.A)([undefined]);
var result = void 0;
result = obj.any(function () {
return true;
});
equal(result, true, 'return value of obj.any');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/compact', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('compact');
suite.test('removes null and undefined values from enumerable', function () {
var obj = this.newObject([null, 1, false, '', undefined, 0, null]);
var ary = obj.compact();
deepEqual(ary, [1, false, '', 0]);
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/contains', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('contains');
suite.test('contains returns true if item is in enumerable', function () {
var data = this.newFixture(3);
var obj = this.newObject(data);
expectDeprecation('`Enumerable#contains` is deprecated, use `Enumerable#includes` instead.');
equal(obj.contains(data[1]), true, 'should return true if contained');
});
suite.test('contains returns false if item is not in enumerable', function () {
var data = this.newFixture(1);
var obj = this.newObject(this.newFixture(3));
expectDeprecation('`Enumerable#contains` is deprecated, use `Enumerable#includes` instead.');
equal(obj.contains(data[0]), false, 'should return false if not contained');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/every', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
// ..........................................................
// every()
//
suite.module('every');
suite.test('every should should invoke callback on each item as long as you return true', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
var found = [];
var result = void 0;
result = obj.every(function (i) {
found.push(i);
return true;
});
equal(result, true, 'return value of obj.every');
deepEqual(found, ary, 'items passed during every() should match');
});
suite.test('every should stop invoking when you return false', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
var cnt = ary.length - 2;
var exp = cnt;
var found = [];
var result = void 0;
result = obj.every(function (i) {
found.push(i);
return --cnt > 0;
});
equal(result, false, 'return value of obj.every');
equal(found.length, exp, 'should invoke proper number of times');
deepEqual(found, ary.slice(0, -2), 'items passed during every() should match');
});
// ..........................................................
// isEvery()
//
suite.module('isEvery');
suite.test('should return true of every property matches', function () {
var obj = this.newObject([{ foo: 'foo', bar: 'BAZ' }, _object.default.create({ foo: 'foo', bar: 'bar' })]);
equal(obj.isEvery('foo', 'foo'), true, 'isEvery(foo)');
equal(obj.isEvery('bar', 'bar'), false, 'isEvery(bar)');
});
suite.test('should return true of every property is true', function () {
var obj = this.newObject([{ foo: 'foo', bar: true }, _object.default.create({ foo: 'bar', bar: false })]);
// different values - all eval to true
equal(obj.isEvery('foo'), true, 'isEvery(foo)');
equal(obj.isEvery('bar'), false, 'isEvery(bar)');
});
suite.test('should return true if every property matches null', function () {
var obj = this.newObject([{ foo: null, bar: 'BAZ' }, _object.default.create({ foo: null, bar: null })]);
equal(obj.isEvery('foo', null), true, 'isEvery(\'foo\', null)');
equal(obj.isEvery('bar', null), false, 'isEvery(\'bar\', null)');
});
suite.test('should return true if every property is undefined', function () {
var obj = this.newObject([{ foo: undefined, bar: 'BAZ' }, _object.default.create({ bar: undefined })]);
equal(obj.isEvery('foo', undefined), true, 'isEvery(\'foo\', undefined)');
equal(obj.isEvery('bar', undefined), false, 'isEvery(\'bar\', undefined)');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/filter', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
// ..........................................................
// filter()
//
suite.module('filter');
suite.test('filter should invoke on each item', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
var cnt = ary.length - 2;
var found = [];
var result = void 0;
// return true on all but the last two
result = obj.filter(function (i) {
found.push(i);
return --cnt >= 0;
});
deepEqual(found, ary, 'should have invoked on each item');
deepEqual(result, ary.slice(0, -2), 'filtered array should exclude items');
});
// ..........................................................
// filterBy()
//
suite.module('filterBy');
suite.test('should filter based on object', function () {
var obj = void 0,
ary = void 0;
ary = [{ foo: 'foo', bar: 'BAZ' }, _object.default.create({ foo: 'foo', bar: 'bar' })];
obj = this.newObject(ary);
deepEqual(obj.filterBy('foo', 'foo'), ary, 'filterBy(foo)');
deepEqual(obj.filterBy('bar', 'bar'), [ary[1]], 'filterBy(bar)');
});
suite.test('should include in result if property is true', function () {
var obj = void 0,
ary = void 0;
ary = [{ foo: 'foo', bar: true }, _object.default.create({ foo: 'bar', bar: false })];
obj = this.newObject(ary);
// different values - all eval to true
deepEqual(obj.filterBy('foo'), ary, 'filterBy(foo)');
deepEqual(obj.filterBy('bar'), [ary[0]], 'filterBy(bar)');
});
suite.test('should filter on second argument if provided', function () {
var obj = void 0,
ary = void 0;
ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 2 }), { name: 'obj3', foo: 2 }, _object.default.create({ name: 'obj4', foo: 3 })];
obj = this.newObject(ary);
deepEqual(obj.filterBy('foo', 3), [ary[0], ary[3]], 'filterBy(\'foo\', 3)\')');
});
suite.test('should correctly filter null second argument', function () {
var obj = void 0,
ary = void 0;
ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: null }), { name: 'obj3', foo: null }, _object.default.create({ name: 'obj4', foo: 3 })];
obj = this.newObject(ary);
deepEqual(obj.filterBy('foo', null), [ary[1], ary[2]], 'filterBy(\'foo\', 3)\')');
});
suite.test('should not return all objects on undefined second argument', function () {
var obj = void 0,
ary = void 0;
ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 2 })];
obj = this.newObject(ary);
deepEqual(obj.filterBy('foo', undefined), [], 'filterBy(\'foo\', 3)\')');
});
suite.test('should correctly filter explicit undefined second argument', function () {
var obj = void 0,
ary = void 0;
ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 3 }), { name: 'obj3', foo: undefined }, _object.default.create({ name: 'obj4', foo: undefined }), { name: 'obj5' }, _object.default.create({ name: 'obj6' })];
obj = this.newObject(ary);
deepEqual(obj.filterBy('foo', undefined), ary.slice(2), 'filterBy(\'foo\', 3)\')');
});
suite.test('should not match undefined properties without second argument', function () {
var obj = void 0,
ary = void 0;
ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 3 }), { name: 'obj3', foo: undefined }, _object.default.create({ name: 'obj4', foo: undefined }), { name: 'obj5' }, _object.default.create({ name: 'obj6' })];
obj = this.newObject(ary);
deepEqual(obj.filterBy('foo'), ary.slice(0, 2), 'filterBy(\'foo\', 3)\')');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/find', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
// ..........................................................
// find()
//
suite.module('find');
suite.test('find should invoke callback on each item as long as you return false', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
var found = [];
var result = void 0;
result = obj.find(function (i) {
found.push(i);
return false;
});
equal(result, undefined, 'return value of obj.find');
deepEqual(found, ary, 'items passed during find() should match');
});
suite.test('every should stop invoking when you return true', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
var cnt = ary.length - 2;
var exp = cnt;
var found = [];
var result = void 0;
result = obj.find(function (i) {
found.push(i);
return --cnt >= 0;
});
equal(result, ary[exp - 1], 'return value of obj.find');
equal(found.length, exp, 'should invoke proper number of times');
deepEqual(found, ary.slice(0, -2), 'items passed during find() should match');
});
// ..........................................................
// findBy()
//
suite.module('findBy');
suite.test('should return first object of property matches', function () {
var ary = void 0,
obj = void 0;
ary = [{ foo: 'foo', bar: 'BAZ' }, _object.default.create({ foo: 'foo', bar: 'bar' })];
obj = this.newObject(ary);
equal(obj.findBy('foo', 'foo'), ary[0], 'findBy(foo)');
equal(obj.findBy('bar', 'bar'), ary[1], 'findBy(bar)');
});
suite.test('should return first object with truthy prop', function () {
var ary = void 0,
obj = void 0;
ary = [{ foo: 'foo', bar: false }, _object.default.create({ foo: 'bar', bar: true })];
obj = this.newObject(ary);
// different values - all eval to true
equal(obj.findBy('foo'), ary[0], 'findBy(foo)');
equal(obj.findBy('bar'), ary[1], 'findBy(bar)');
});
suite.test('should return first null property match', function () {
var ary = void 0,
obj = void 0;
ary = [{ foo: null, bar: 'BAZ' }, _object.default.create({ foo: null, bar: null })];
obj = this.newObject(ary);
equal(obj.findBy('foo', null), ary[0], 'findBy(\'foo\', null)');
equal(obj.findBy('bar', null), ary[1], 'findBy(\'bar\', null)');
});
suite.test('should return first undefined property match', function () {
var ary = void 0,
obj = void 0;
ary = [{ foo: undefined, bar: 'BAZ' }, _object.default.create({})];
obj = this.newObject(ary);
equal(obj.findBy('foo', undefined), ary[0], 'findBy(\'foo\', undefined)');
equal(obj.findBy('bar', undefined), ary[1], 'findBy(\'bar\', undefined)');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/firstObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('firstObject');
suite.test('returns first item in enumerable', function () {
var obj = this.newObject();
equal((0, _emberMetal.get)(obj, 'firstObject'), this.toArray(obj)[0]);
});
suite.test('returns undefined if enumerable is empty', function () {
var obj = this.newObject([]);
equal((0, _emberMetal.get)(obj, 'firstObject'), undefined);
});
suite.test('can not be set', function () {
var obj = this.newObject([]);
equal((0, _emberMetal.get)(obj, 'firstObject'), this.toArray(obj)[0]);
throws(function () {
(0, _emberMetal.set)(obj, 'firstObject', 'foo!');
}, /Cannot set read-only property "firstObject" on object/);
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/forEach', ['exports', 'ember-utils', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _emberUtils, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('forEach');
suite.test('forEach should iterate over list', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
var found = [];
obj.forEach(function (i) {
return found.push(i);
});
deepEqual(found, ary, 'items passed during forEach should match');
});
suite.test('forEach should iterate over list after mutation', function () {
if ((0, _emberMetal.get)(this, 'canTestMutation')) {
expect(0);
return;
}
var obj = this.newObject();
var ary = this.toArray(obj);
var found = [];
obj.forEach(function (i) {
return found.push(i);
});
deepEqual(found, ary, 'items passed during forEach should match');
this.mutate(obj);
ary = this.toArray(obj);
found = [];
obj.forEach(function (i) {
return found.push(i);
});
deepEqual(found, ary, 'items passed during forEach should match');
});
suite.test('2nd target parameter', function () {
var _this = this;
var obj = this.newObject();
var target = this;
obj.forEach(function () {
// ES6TODO: When transpiled we will end up with "use strict" which disables automatically binding to the global context.
// Therefore, the following test can never pass in strict mode unless we modify the `map` function implementation to
// use `Ember.lookup` if target is not specified.
//
// equal(guidFor(this), guidFor(global), 'should pass the global object as this if no context');
});
obj.forEach(function () {
equal((0, _emberUtils.guidFor)(_this), (0, _emberUtils.guidFor)(target), 'should pass target as this if context');
}, target);
});
suite.test('callback params', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
var loc = 0;
obj.forEach(function (item, idx, enumerable) {
equal(item, ary[loc], 'item param');
equal(idx, loc, 'idx param');
equal((0, _emberUtils.guidFor)(enumerable), (0, _emberUtils.guidFor)(obj), 'enumerable param');
loc++;
});
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/includes', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('includes');
suite.test('includes returns true if item is in enumerable', function () {
var data = this.newFixture(1);
var obj = this.newObject([].concat(data, [NaN, undefined, null]));
equal(obj.includes(data[0]), true, 'should return true if included');
equal(obj.includes(NaN), true, 'should return true if NaN included');
equal(obj.includes(undefined), true, 'should return true if undefined included');
equal(obj.includes(null), true, 'should return true if null included');
});
suite.test('includes returns false if item is not in enumerable', function () {
var data = this.newFixture(1);
var obj = this.newObject([].concat(this.newFixture(3), [null]));
equal(obj.includes(data[0]), false, 'should return false if not included');
equal(obj.includes(undefined), false, 'should return false if undefined not included but null is included');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/invoke', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('invoke');
suite.test('invoke should call on each object that implements', function () {
var cnt = void 0,
ary = void 0,
obj = void 0;
function F(amt) {
cnt += amt === undefined ? 1 : amt;
}
cnt = 0;
ary = [{ foo: F }, _object.default.create({ foo: F }),
// NOTE: does not impl foo - invoke should just skip
_object.default.create({ bar: F }), { foo: F }];
obj = this.newObject(ary);
obj.invoke('foo');
equal(cnt, 3, 'should have invoked 3 times');
cnt = 0;
obj.invoke('foo', 2);
equal(cnt, 6, 'should have invoked 3 times, passing param');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/is_any', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
// ..........................................................
// isAny()
//
suite.module('isAny');
suite.test('should return true of any property matches', function () {
var obj = this.newObject([{ foo: 'foo', bar: 'BAZ' }, _object.default.create({ foo: 'foo', bar: 'bar' })]);
equal(obj.isAny('foo', 'foo'), true, 'isAny(foo)');
equal(obj.isAny('bar', 'bar'), true, 'isAny(bar)');
equal(obj.isAny('bar', 'BIFF'), false, 'isAny(BIFF)');
});
suite.test('should return true of any property is true', function () {
var obj = this.newObject([{ foo: 'foo', bar: true }, _object.default.create({ foo: 'bar', bar: false })]);
// different values - all eval to true
equal(obj.isAny('foo'), true, 'isAny(foo)');
equal(obj.isAny('bar'), true, 'isAny(bar)');
equal(obj.isAny('BIFF'), false, 'isAny(biff)');
});
suite.test('should return true if any property matches null', function () {
var obj = this.newObject([{ foo: null, bar: 'bar' }, _object.default.create({ foo: 'foo', bar: null })]);
equal(obj.isAny('foo', null), true, 'isAny(\'foo\', null)');
equal(obj.isAny('bar', null), true, 'isAny(\'bar\', null)');
});
suite.test('should return true if any property is undefined', function () {
var obj = this.newObject([{ foo: undefined, bar: 'bar' }, _object.default.create({ foo: 'foo' })]);
equal(obj.isAny('foo', undefined), true, 'isAny(\'foo\', undefined)');
equal(obj.isAny('bar', undefined), true, 'isAny(\'bar\', undefined)');
});
suite.test('should not match undefined properties without second argument', function () {
var obj = this.newObject([{ foo: undefined }, _object.default.create({})]);
equal(obj.isAny('foo'), false, 'isAny(\'foo\', undefined)');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/lastObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('lastObject');
suite.test('returns last item in enumerable', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
equal((0, _emberMetal.get)(obj, 'lastObject'), ary[ary.length - 1]);
});
suite.test('returns undefined if enumerable is empty', function () {
var obj = this.newObject([]);
equal((0, _emberMetal.get)(obj, 'lastObject'), undefined);
});
suite.test('can not be set', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
equal((0, _emberMetal.get)(obj, 'lastObject'), ary[ary.length - 1]);
throws(function () {
(0, _emberMetal.set)(obj, 'lastObject', 'foo!');
}, /Cannot set read-only property "lastObject" on object/);
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/map', ['exports', 'ember-utils', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _emberUtils, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('map');
var mapFunc = function (item) {
return item ? item.toString() : null;
};
suite.test('map should iterate over list', function () {
var obj = this.newObject();
var ary = this.toArray(obj).map(mapFunc);
var found = [];
found = obj.map(mapFunc);
deepEqual(found, ary, 'mapped arrays should match');
});
suite.test('map should iterate over list after mutation', function () {
if ((0, _emberMetal.get)(this, 'canTestMutation')) {
expect(0);
return;
}
var obj = this.newObject();
var ary = this.toArray(obj).map(mapFunc);
var found = void 0;
found = obj.map(mapFunc);
deepEqual(found, ary, 'items passed during forEach should match');
this.mutate(obj);
ary = this.toArray(obj).map(mapFunc);
found = obj.map(mapFunc);
deepEqual(found, ary, 'items passed during forEach should match');
});
suite.test('2nd target parameter', function () {
var _this = this;
var obj = this.newObject();
var target = this;
obj.map(function () {
// ES6TODO: When transpiled we will end up with "use strict" which disables automatically binding to the global context.
// Therefore, the following test can never pass in strict mode unless we modify the `map` function implementation to
// use `Ember.lookup` if target is not specified.
//
// equal(guidFor(this), guidFor(global), 'should pass the global object as this if no context');
});
obj.map(function () {
equal((0, _emberUtils.guidFor)(_this), (0, _emberUtils.guidFor)(target), 'should pass target as this if context');
}, target);
});
suite.test('callback params', function () {
var obj = this.newObject();
var ary = this.toArray(obj);
var loc = 0;
obj.map(function (item, idx, enumerable) {
equal(item, ary[loc], 'item param');
equal(idx, loc, 'idx param');
equal((0, _emberUtils.guidFor)(enumerable), (0, _emberUtils.guidFor)(obj), 'enumerable param');
loc++;
});
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/mapBy', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('mapBy');
suite.test('get value of each property', function () {
var obj = this.newObject([{ a: 1 }, { a: 2 }]);
equal(obj.mapBy('a').join(''), '12');
});
suite.test('should work also through getEach alias', function () {
var obj = this.newObject([{ a: 1 }, { a: 2 }]);
equal(obj.getEach('a').join(''), '12');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/reduce', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('reduce');
suite.test('collects a summary value from an enumeration', function () {
var obj = this.newObject([1, 2, 3]);
var res = obj.reduce(function (previousValue, item) {
return previousValue + item;
}, 0);
equal(res, 6);
});
suite.test('passes index of item to callback', function () {
var obj = this.newObject([1, 2, 3]);
var res = obj.reduce(function (previousValue, item, index) {
return previousValue + index;
}, 0);
equal(res, 3);
});
suite.test('passes enumerable object to callback', function () {
var obj = this.newObject([1, 2, 3]);
var res = obj.reduce(function (previousValue, item, index, enumerable) {
return enumerable;
}, 0);
equal(res, obj);
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/reject', ['exports', 'ember-runtime/system/object', 'ember-runtime/tests/suites/suite'], function (exports, _object, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
// ..........................................................
// reject()
//
suite.module('reject');
suite.test('should reject any item that does not meet the condition', function () {
var obj = this.newObject([1, 2, 3, 4]);
var result = void 0;
result = obj.reject(function (i) {
return i < 3;
});
deepEqual(result, [3, 4], 'reject the correct items');
});
suite.test('should be the inverse of filter', function () {
var obj = this.newObject([1, 2, 3, 4]);
var isEven = function (i) {
return i % 2 === 0;
};
var filtered = void 0,
rejected = void 0;
filtered = obj.filter(isEven);
rejected = obj.reject(isEven);
deepEqual(filtered, [2, 4], 'filtered evens');
deepEqual(rejected, [1, 3], 'rejected evens');
});
// ..........................................................
// rejectBy()
//
suite.module('rejectBy');
suite.test('should reject based on object', function () {
var obj = void 0,
ary = void 0;
ary = [{ foo: 'foo', bar: 'BAZ' }, _object.default.create({ foo: 'foo', bar: 'bar' })];
obj = this.newObject(ary);
deepEqual(obj.rejectBy('foo', 'foo'), [], 'rejectBy(foo)');
deepEqual(obj.rejectBy('bar', 'bar'), [ary[0]], 'rejectBy(bar)');
});
suite.test('should include in result if property is false', function () {
var obj = void 0,
ary = void 0;
ary = [{ foo: false, bar: true }, _object.default.create({ foo: false, bar: false })];
obj = this.newObject(ary);
deepEqual(obj.rejectBy('foo'), ary, 'rejectBy(foo)');
deepEqual(obj.rejectBy('bar'), [ary[1]], 'rejectBy(bar)');
});
suite.test('should reject on second argument if provided', function () {
var obj = void 0,
ary = void 0;
ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 2 }), { name: 'obj3', foo: 2 }, _object.default.create({ name: 'obj4', foo: 3 })];
obj = this.newObject(ary);
deepEqual(obj.rejectBy('foo', 3), [ary[1], ary[2]], 'rejectBy(\'foo\', 3)\')');
});
suite.test('should correctly reject null second argument', function () {
var obj = void 0,
ary = void 0;
ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: null }), { name: 'obj3', foo: null }, _object.default.create({ name: 'obj4', foo: 3 })];
obj = this.newObject(ary);
deepEqual(obj.rejectBy('foo', null), [ary[0], ary[3]], 'rejectBy(\'foo\', null)\')');
});
suite.test('should correctly reject undefined second argument', function () {
var obj = void 0,
ary = void 0;
ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 2 })];
obj = this.newObject(ary);
deepEqual(obj.rejectBy('bar', undefined), [], 'rejectBy(\'bar\', undefined)\')');
});
suite.test('should correctly reject explicit undefined second argument', function () {
var obj = void 0,
ary = void 0;
ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 3 }), { name: 'obj3', foo: undefined }, _object.default.create({ name: 'obj4', foo: undefined }), { name: 'obj5' }, _object.default.create({ name: 'obj6' })];
obj = this.newObject(ary);
deepEqual(obj.rejectBy('foo', undefined), ary.slice(0, 2), 'rejectBy(\'foo\', undefined)\')');
});
suite.test('should match undefined, null, or false properties without second argument', function () {
var obj = void 0,
ary = void 0;
ary = [{ name: 'obj1', foo: 3 }, _object.default.create({ name: 'obj2', foo: 3 }), { name: 'obj3', foo: undefined }, _object.default.create({ name: 'obj4', foo: undefined }), { name: 'obj5' }, _object.default.create({ name: 'obj6' }), { name: 'obj7', foo: null }, _object.default.create({ name: 'obj8', foo: null }), { name: 'obj9', foo: false }, _object.default.create({ name: 'obj10', foo: false })];
obj = this.newObject(ary);
deepEqual(obj.rejectBy('foo'), ary.slice(2), 'rejectBy(\'foo\')\')');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/sortBy', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('sortBy');
suite.test('sort by value of property', function () {
var obj = this.newObject([{ a: 2 }, { a: 1 }]);
var sorted = obj.sortBy('a');
equal((0, _emberMetal.get)(sorted[0], 'a'), 1);
equal((0, _emberMetal.get)(sorted[1], 'a'), 2);
});
suite.test('supports multiple propertyNames', function () {
var obj = this.newObject([{ a: 1, b: 2 }, { a: 1, b: 1 }]);
var sorted = obj.sortBy('a', 'b');
equal((0, _emberMetal.get)(sorted[0], 'b'), 1);
equal((0, _emberMetal.get)(sorted[1], 'b'), 2);
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/toArray', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('toArray');
suite.test('toArray should convert to an array', function () {
var obj = this.newObject();
deepEqual(obj.toArray(), this.toArray(obj));
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/uniq', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('uniq');
suite.test('should return new instance with duplicates removed', function () {
var before = void 0,
after = void 0,
obj = void 0,
ret = void 0;
after = this.newFixture(3);
before = [after[0], after[1], after[2], after[1], after[0]];
obj = this.newObject(before);
before = obj.toArray(); // in case of set before will be different...
ret = obj.uniq();
deepEqual(this.toArray(ret), after, 'should have removed item');
deepEqual(this.toArray(obj), before, 'should not have changed original');
});
suite.test('should return duplicate of same content if no duplicates found', function () {
var obj = void 0,
ret = void 0;
obj = this.newObject(this.newFixture(3));
ret = obj.uniq(void 0);
ok(ret !== obj, 'should not be same object');
deepEqual(this.toArray(ret), this.toArray(obj), 'should be the same content');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/uniqBy', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('uniqBy');
suite.test('should return new instance with duplicates removed', function () {
var numbers = this.newObject([{ id: 1, value: 'one' }, { id: 2, value: 'two' }, { id: 1, value: 'one' }]);
deepEqual(numbers.uniqBy('id'), [{ id: 1, value: 'one' }, { id: 2, value: 'two' }]);
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/enumerable/without', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('without');
suite.test('should return new instance with item removed', function () {
var before = void 0,
after = void 0,
obj = void 0,
ret = void 0;
before = this.newFixture(3);
after = [before[0], before[2]];
obj = this.newObject(before);
ret = obj.without(before[1]);
deepEqual(this.toArray(ret), after, 'should have removed item');
deepEqual(this.toArray(obj), before, 'should not have changed original');
});
suite.test('should remove NaN value', function () {
var before = void 0,
after = void 0,
obj = void 0,
ret = void 0;
before = [].concat(this.newFixture(2), [NaN]);
after = [before[0], before[1]];
obj = this.newObject(before);
ret = obj.without(NaN);
deepEqual(this.toArray(ret), after, 'should have removed item');
});
suite.test('should return same instance if object not found', function () {
var item = void 0,
obj = void 0,
ret = void 0;
item = this.newFixture(1)[0];
obj = this.newObject(this.newFixture(3));
ret = obj.without(item);
equal(ret, obj, 'should be same instance');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array', ['exports', 'ember-runtime/tests/suites/array', 'ember-runtime/tests/suites/mutable_array/insertAt', 'ember-runtime/tests/suites/mutable_array/popObject', 'ember-runtime/tests/suites/mutable_array/pushObject', 'ember-runtime/tests/suites/mutable_array/pushObjects', 'ember-runtime/tests/suites/mutable_array/removeAt', 'ember-runtime/tests/suites/mutable_array/replace', 'ember-runtime/tests/suites/mutable_array/shiftObject', 'ember-runtime/tests/suites/mutable_array/unshiftObject', 'ember-runtime/tests/suites/mutable_array/reverseObjects'], function (exports, _array, _insertAt, _popObject, _pushObject, _pushObjects, _removeAt, _replace, _shiftObject, _unshiftObject, _reverseObjects) {
'use strict';
var MutableArrayTests = _array.ArrayTests.extend();
MutableArrayTests.importModuleTests(_insertAt.default);
MutableArrayTests.importModuleTests(_popObject.default);
MutableArrayTests.importModuleTests(_pushObject.default);
MutableArrayTests.importModuleTests(_pushObjects.default);
MutableArrayTests.importModuleTests(_removeAt.default);
MutableArrayTests.importModuleTests(_replace.default);
MutableArrayTests.importModuleTests(_shiftObject.default);
MutableArrayTests.importModuleTests(_unshiftObject.default);
MutableArrayTests.importModuleTests(_reverseObjects.default);
exports.default = MutableArrayTests;
});
enifed('ember-runtime/tests/suites/mutable_array/addObject', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite'], function (exports, _emberMetal, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('addObject');
suite.test('should return receiver', function () {
var before = this.newFixture(3);
var obj = this.newObject(before);
equal(obj.addObject(before[1]), obj, 'should return receiver');
});
suite.test('[A,B].addObject(C) => [A,B,C] + notify', function () {
var before = this.newFixture(2);
var item = this.newFixture(1)[0];
var after = [before[0], before[1], item];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.addObject(item);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
}
});
suite.test('[A,B,C].addObject(A) => [A,B,C] + NO notify', function () {
var before = this.newFixture(3);
var after = before;
var item = before[0];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.addObject(item); // note: item in set
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.validate('[]'), false, 'should NOT have notified []');
equal(observer.validate('@each'), false, 'should NOT have notified @each');
equal(observer.validate('length'), false, 'should NOT have notified length');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
}
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/clear', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite'], function (exports, _emberMetal, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('clear');
suite.test('[].clear() => [] + notify', function () {
var after = [];
var obj = this.newObject([]);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal(obj.clear(), obj, 'return self');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.validate('[]'), false, 'should NOT have notified [] once');
equal(observer.validate('@each'), false, 'should NOT have notified @each once');
equal(observer.validate('length'), false, 'should NOT have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
});
suite.test('[X].clear() => [] + notify', function () {
var obj, before, after, observer;
before = this.newFixture(1);
after = [];
obj = this.newObject(before);
observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal(obj.clear(), obj, 'return self');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/insertAt', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('insertAt');
suite.test('[].insertAt(0, X) => [X] + notify', function () {
var after = this.newFixture(1);
var obj = this.newObject([]);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.insertAt(0, after[0]);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once');
equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once');
equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once');
equal(observer.timesCalledBefore('firstObject'), 1, 'should have notified firstObject will change once');
equal(observer.timesCalledBefore('lastObject'), 1, 'should have notified lastObject will change once');
equal(observer.timesCalled('[]'), 1, 'should have notified [] did change once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each did change once');
equal(observer.timesCalled('length'), 1, 'should have notified length did change once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject did change once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject did change once');
});
suite.test('[].insertAt(200,X) => OUT_OF_RANGE_EXCEPTION exception', function () {
var obj = this.newObject([]);
var that = this;
throws(function () {
return obj.insertAt(200, that.newFixture(1)[0]);
}, Error);
});
suite.test('[A].insertAt(0, X) => [X,A] + notify', function () {
var item = this.newFixture(1)[0];
var before = this.newFixture(1);
var after = [item, before[0]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.insertAt(0, item);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once');
equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once');
equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once');
equal(observer.timesCalledBefore('firstObject'), 1, 'should have notified firstObject will change once');
equal(observer.timesCalledBefore('lastObject'), 0, 'should NOT have notified lastObject will change once');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
});
suite.test('[A].insertAt(1, X) => [A,X] + notify', function () {
var item = this.newFixture(1)[0];
var before = this.newFixture(1);
var after = [before[0], item];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.insertAt(1, item);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once');
equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once');
equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once');
equal(observer.timesCalledBefore('firstObject'), 0, 'should NOT have notified firstObject will change once');
equal(observer.timesCalledBefore('lastObject'), 1, 'should have notified lastObject will change once');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
});
suite.test('[A].insertAt(200,X) => OUT_OF_RANGE exception', function () {
var obj = this.newObject(this.newFixture(1));
var that = this;
throws(function () {
return obj.insertAt(200, that.newFixture(1)[0]);
}, Error);
});
suite.test('[A,B,C].insertAt(0,X) => [X,A,B,C] + notify', function () {
var item = this.newFixture(1)[0];
var before = this.newFixture(3);
var after = [item, before[0], before[1], before[2]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.insertAt(0, item);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once');
equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once');
equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once');
equal(observer.timesCalledBefore('firstObject'), 1, 'should have notified firstObject will change once');
equal(observer.timesCalledBefore('lastObject'), 0, 'should NOT have notified lastObject will change once');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
});
suite.test('[A,B,C].insertAt(1,X) => [A,X,B,C] + notify', function () {
var item = this.newFixture(1)[0];
var before = this.newFixture(3);
var after = [before[0], item, before[1], before[2]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.insertAt(1, item);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once');
equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once');
equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once');
equal(observer.timesCalledBefore('firstObject'), 0, 'should NOT have notified firstObject will change once');
equal(observer.timesCalledBefore('lastObject'), 0, 'should NOT have notified lastObject will change once');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
});
suite.test('[A,B,C].insertAt(3,X) => [A,B,C,X] + notify', function () {
var item = this.newFixture(1)[0];
var before = this.newFixture(3);
var after = [before[0], before[1], before[2], item];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.insertAt(3, item);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalledBefore('[]'), 1, 'should have notified [] will change once');
equal(observer.timesCalledBefore('@each'), 0, 'should not have notified @each will change once');
equal(observer.timesCalledBefore('length'), 1, 'should have notified length will change once');
equal(observer.timesCalledBefore('firstObject'), 0, 'should NOT have notified firstObject will change once');
equal(observer.timesCalledBefore('lastObject'), 1, 'should have notified lastObject will change once');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/popObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('popObject');
suite.test('[].popObject() => [] + returns undefined + NO notify', function () {
var obj = this.newObject([]);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal(obj.popObject(), undefined, 'popObject results');
deepEqual(this.toArray(obj), [], 'post item results');
equal(observer.validate('[]'), false, 'should NOT have notified []');
equal(observer.validate('@each'), false, 'should NOT have notified @each');
equal(observer.validate('length'), false, 'should NOT have notified length');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
});
suite.test('[X].popObject() => [] + notify', function () {
var before = this.newFixture(1);
var after = [];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
var ret = obj.popObject();
equal(ret, before[0], 'return object');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
});
suite.test('[A,B,C].popObject() => [A,B] + notify', function () {
var before = this.newFixture(3);
var after = [before[0], before[1]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
var ret = obj.popObject();
equal(ret, before[2], 'return object');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/pushObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('pushObject');
suite.test('returns pushed object', function () {
var exp = this.newFixture(1)[0];
var obj = this.newObject([]);
equal(obj.pushObject(exp), exp, 'should return pushed object');
});
suite.test('[].pushObject(X) => [X] + notify', function () {
var after = this.newFixture(1);
var obj = this.newObject([]);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.pushObject(after[0]);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
});
suite.test('[A,B,C].pushObject(X) => [A,B,C,X] + notify', function () {
var before = this.newFixture(3);
var item = this.newFixture(1)[0];
var after = [before[0], before[1], before[2], item];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.pushObject(item);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/pushObjects', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('pushObjects');
suite.test('should raise exception if not Ember.Enumerable is passed to pushObjects', function () {
var obj = this.newObject([]);
throws(function () {
return obj.pushObjects('string');
});
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/removeAt', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal', 'ember-runtime/mixins/mutable_array'], function (exports, _suite, _emberMetal, _mutable_array) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('removeAt');
suite.test('removeAt([X], 0) => [] + notify', function () {
var before = this.newFixture(1);
var after = [];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal((0, _mutable_array.removeAt)(obj, 0), obj, 'return self');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
});
suite.test('removeAt([], 200) => OUT_OF_RANGE_EXCEPTION exception', function () {
var obj = this.newObject([]);
throws(function () {
return (0, _mutable_array.removeAt)(obj, 200);
}, Error);
});
suite.test('removeAt([A,B], 0) => [B] + notify', function () {
var before = this.newFixture(2);
var after = [before[1]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal((0, _mutable_array.removeAt)(obj, 0), obj, 'return self');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
});
suite.test('removeAt([A,B], 1) => [A] + notify', function () {
var before = this.newFixture(2);
var after = [before[0]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal((0, _mutable_array.removeAt)(obj, 1), obj, 'return self');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
});
suite.test('removeAt([A,B,C], 1) => [A,C] + notify', function () {
var before = this.newFixture(3);
var after = [before[0], before[2]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal((0, _mutable_array.removeAt)(obj, 1), obj, 'return self');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
});
suite.test('removeAt([A,B,C,D], 1,2) => [A,D] + notify', function () {
var before = this.newFixture(4);
var after = [before[0], before[3]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal((0, _mutable_array.removeAt)(obj, 1, 2), obj, 'return self');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
});
suite.test('[A,B,C,D].removeAt(1,2) => [A,D] + notify', function () {
var obj, before, after, observer;
before = this.newFixture(4);
after = [before[0], before[3]];
obj = this.newObject(before);
observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal(obj.removeAt(1, 2), obj, 'return self');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/removeObject', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite'], function (exports, _emberMetal, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('removeObject');
suite.test('should return receiver', function () {
var before = this.newFixture(3);
var obj = this.newObject(before);
equal(obj.removeObject(before[1]), obj, 'should return receiver');
});
suite.test('[A,B,C].removeObject(B) => [A,C] + notify', function () {
var before = this.newFixture(3);
var after = [before[0], before[2]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.removeObject(before[1]);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
}
});
suite.test('[A,B,C].removeObject(D) => [A,B,C]', function () {
var before = this.newFixture(3);
var after = before;
var item = this.newFixture(1)[0];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.removeObject(item); // note: item not in set
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.validate('[]'), false, 'should NOT have notified []');
equal(observer.validate('@each'), false, 'should NOT have notified @each');
equal(observer.validate('length'), false, 'should NOT have notified length');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
}
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/replace', ['exports', 'ember-runtime/tests/suites/suite'], function (exports, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('replace');
suite.test('[].replace(0,0,\'X\') => [\'X\'] + notify', function () {
var exp = this.newFixture(1);
var obj = this.newObject([]);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.replace(0, 0, exp);
deepEqual(this.toArray(obj), exp, 'post item results');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
});
suite.test('[].replace(0,0,"X") => ["X"] + avoid calling objectAt and notifying fistObject/lastObject when not in cache', function () {
var obj, exp, observer;
var called = 0;
exp = this.newFixture(1);
obj = this.newObject([]);
obj.objectAt = function () {
called++;
};
observer = this.newObserver(obj, 'firstObject', 'lastObject');
obj.replace(0, 0, exp);
equal(called, 0, 'should NOT have called objectAt upon replace when firstObject/lastObject are not cached');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject since not cached');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject since not cached');
});
suite.test('[A,B,C,D].replace(1,2,X) => [A,X,D] + notify', function () {
var before = this.newFixture(4);
var replace = this.newFixture(1);
var after = [before[0], replace[0], before[3]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.replace(1, 2, replace);
deepEqual(this.toArray(obj), after, 'post item results');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
});
suite.test('[A,B,C,D].replace(1,2,[X,Y]) => [A,X,Y,D] + notify', function () {
var before = this.newFixture(4);
var replace = this.newFixture(2);
var after = [before[0], replace[0], replace[1], before[3]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.replace(1, 2, replace);
deepEqual(this.toArray(obj), after, 'post item results');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.validate('length'), false, 'should NOT have notified length');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
});
suite.test('[A,B].replace(1,0,[X,Y]) => [A,X,Y,B] + notify', function () {
var before = this.newFixture(2);
var replace = this.newFixture(2);
var after = [before[0], replace[0], replace[1], before[1]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.replace(1, 0, replace);
deepEqual(this.toArray(obj), after, 'post item results');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
});
suite.test('[A,B,C,D].replace(2,2) => [A,B] + notify', function () {
var before = this.newFixture(4);
var after = [before[0], before[1]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.replace(2, 2);
deepEqual(this.toArray(obj), after, 'post item results');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
});
suite.test('Adding object should notify enumerable observer', function () {
var fixtures = this.newFixture(4);
var obj = this.newObject(fixtures);
var observer = this.newObserver(obj).observeEnumerable(obj);
var item = this.newFixture(1)[0];
obj.replace(2, 2, [item]);
deepEqual(observer._before, [obj, [fixtures[2], fixtures[3]], 1], 'before');
deepEqual(observer._after, [obj, 2, [item]], 'after');
});
suite.test('Adding object should notify array observer', function () {
var fixtures = this.newFixture(4);
var obj = this.newObject(fixtures);
var observer = this.newObserver(obj).observeArray(obj);
var item = this.newFixture(1)[0];
obj.replace(2, 2, [item]);
deepEqual(observer._before, [obj, 2, 2, 1], 'before');
deepEqual(observer._after, [obj, 2, 2, 1], 'after');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/reverseObjects', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('reverseObjects');
suite.test('[A,B,C].reverseObjects() => [] + notify', function () {
var before = this.newFixture(3);
var after = [before[2], before[1], before[0]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal(obj.reverseObjects(), obj, 'return self');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 0, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/setObjects', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite'], function (exports, _emberMetal, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('setObjects');
suite.test('[A,B,C].setObjects([]) = > [] + notify', function () {
var before = this.newFixture(3);
var after = [];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal(obj.setObjects(after), obj, 'return self');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
});
suite.test('[A,B,C].setObjects([D, E, F, G]) = > [D, E, F, G] + notify', function () {
var before = this.newFixture(3);
var after = this.newFixture(4);
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal(obj.setObjects(after), obj, 'return self');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/shiftObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('shiftObject');
suite.test('[].shiftObject() => [] + returns undefined + NO notify', function () {
var after = [];
var obj = this.newObject([]);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal(obj.shiftObject(), undefined);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.validate('[]', undefined, 1), false, 'should NOT have notified [] once');
equal(observer.validate('@each', undefined, 1), false, 'should NOT have notified @each once');
equal(observer.validate('length', undefined, 1), false, 'should NOT have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
});
suite.test('[X].shiftObject() => [] + notify', function () {
var before = this.newFixture(1);
var after = [];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal(obj.shiftObject(), before[0], 'should return object');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
});
suite.test('[A,B,C].shiftObject() => [B,C] + notify', function () {
var before = this.newFixture(3);
var after = [before[1], before[2]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
equal(obj.shiftObject(), before[0], 'should return object');
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject once');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/unshiftObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('unshiftObject');
suite.test('returns unshifted object', function () {
var obj = this.newObject([]);
var item = this.newFixture(1)[0];
equal(obj.unshiftObject(item), item, 'should return unshifted object');
});
suite.test('[].unshiftObject(X) => [X] + notify', function () {
var item = this.newFixture(1)[0];
var after = [item];
var obj = this.newObject([]);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.unshiftObject(item);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
});
suite.test('[A,B,C].unshiftObject(X) => [X,A,B,C] + notify', function () {
var before = this.newFixture(3);
var item = this.newFixture(1)[0];
var after = [item, before[0], before[1], before[2]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.unshiftObject(item);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
});
suite.test('[A,B,C].unshiftObject(A) => [A,A,B,C] + notify', function () {
var before = this.newFixture(3);
var item = before[0]; // note same object as current head. should end up twice
var after = [item, before[0], before[1], before[2]];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.unshiftObject(item);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_array/unshiftObjects', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite'], function (exports, _emberMetal, _suite) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('unshiftObjects');
suite.test('returns receiver', function () {
var obj = this.newObject([]);
var items = this.newFixture(3);
equal(obj.unshiftObjects(items), obj, 'should return receiver');
});
suite.test('[].unshiftObjects([A,B,C]) => [A,B,C] + notify', function () {
var items = this.newFixture(3);
var obj = this.newObject([]);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.unshiftObjects(items);
deepEqual(this.toArray(obj), items, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), items.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
});
suite.test('[A,B,C].unshiftObjects([X,Y]) => [X,Y,A,B,C] + notify', function () {
var before = this.newFixture(3);
var items = this.newFixture(2);
var after = items.concat(before);
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.unshiftObjects(items);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
});
suite.test('[A,B,C].unshiftObjects([A,B]) => [A,B,A,B,C] + notify', function () {
var before = this.newFixture(3);
var items = [before[0], before[1]]; // note same object as current head. should end up twice
var after = items.concat(before);
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', '@each', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); /* Prime the cache */
obj.unshiftObjects(items);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('@each'), 0, 'should not have notified @each once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_enumerable', ['exports', 'ember-runtime/tests/suites/enumerable', 'ember-runtime/tests/suites/mutable_enumerable/addObject', 'ember-runtime/tests/suites/mutable_enumerable/removeObject', 'ember-runtime/tests/suites/mutable_enumerable/removeObjects'], function (exports, _enumerable, _addObject, _removeObject, _removeObjects) {
'use strict';
var MutableEnumerableTests = _enumerable.EnumerableTests.extend();
MutableEnumerableTests.importModuleTests(_addObject.default);
MutableEnumerableTests.importModuleTests(_removeObject.default);
MutableEnumerableTests.importModuleTests(_removeObjects.default);
exports.default = MutableEnumerableTests;
});
enifed('ember-runtime/tests/suites/mutable_enumerable/addObject', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal'], function (exports, _suite, _emberMetal) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('addObject');
suite.test('should return receiver', function () {
var before = this.newFixture(3);
var obj = this.newObject(before);
equal(obj.addObject(before[1]), obj, 'should return receiver');
});
suite.test('[A,B].addObject(C) => [A,B,C] + notify', function () {
var before = this.newFixture(2);
var item = this.newFixture(1)[0];
var after = [before[0], before[1], item];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
(0, _emberMetal.get)(obj, 'firstObject');
(0, _emberMetal.get)(obj, 'lastObject');
obj.addObject(item);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject once');
// This gets called since MutableEnumerable is naive about changes
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject once');
}
});
suite.test('[A,B,C].addObject(A) => [A,B,C] + NO notify', function () {
var before = this.newFixture(3);
var after = before;
var item = before[0];
var obj = this.newObject(before);
var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
obj.addObject(item); // note: item in set
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.validate('[]'), false, 'should NOT have notified []');
equal(observer.validate('length'), false, 'should NOT have notified length');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
});
suite.test('Adding object should notify enumerable observer', function () {
var obj = this.newObject(this.newFixture(3));
var observer = this.newObserver(obj).observeEnumerable(obj);
var item = this.newFixture(1)[0];
obj.addObject(item);
deepEqual(observer._before, [obj, null, [item]]);
deepEqual(observer._after, [obj, null, [item]]);
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_enumerable/removeObject', ['exports', 'ember-metal', 'ember-runtime/tests/suites/suite', 'ember-runtime/system/native_array'], function (exports, _emberMetal, _suite, _native_array) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('removeObject');
suite.test('should return receiver', function () {
var before = this.newFixture(3);
var obj = this.newObject(before);
equal(obj.removeObject(before[1]), obj, 'should return receiver');
});
suite.test('[A,B,C].removeObject(B) => [A,C] + notify', function () {
var before = (0, _native_array.A)(this.newFixture(3));
var after = [before[0], before[2]];
var obj = before;
var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); // Prime the cache
obj.removeObject(before[1]);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
});
suite.test('[A,B,C].removeObject(D) => [A,B,C]', function () {
var before = (0, _native_array.A)(this.newFixture(3));
var after = before;
var item = this.newFixture(1)[0];
var obj = before;
var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); // Prime the cache
obj.removeObject(item); // Note: item not in set
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.validate('[]'), false, 'should NOT have notified []');
equal(observer.validate('length'), false, 'should NOT have notified length');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
});
suite.test('Removing object should notify enumerable observer', function () {
var fixtures = this.newFixture(3);
var obj = this.newObject(fixtures);
var observer = this.newObserver(obj).observeEnumerable(obj);
var item = fixtures[1];
obj.removeObject(item);
deepEqual(observer._before, [obj, [item], null]);
deepEqual(observer._after, [obj, [item], null]);
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/mutable_enumerable/removeObjects', ['exports', 'ember-runtime/tests/suites/suite', 'ember-metal', 'ember-runtime/system/native_array'], function (exports, _suite, _emberMetal, _native_array) {
'use strict';
var suite = _suite.SuiteModuleBuilder.create();
suite.module('removeObjects');
suite.test('should return receiver', function () {
var before = (0, _native_array.A)(this.newFixture(3));
var obj = before;
equal(obj.removeObjects(before[1]), obj, 'should return receiver');
});
suite.test('[A,B,C].removeObjects([B]) => [A,C] + notify', function () {
var before = (0, _native_array.A)(this.newFixture(3));
var after = [before[0], before[2]];
var obj = before;
var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); // Prime the cache
obj.removeObjects([before[1]]);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
});
suite.test('[{A},{B},{C}].removeObjects([{B}]) => [{A},{C}] + notify', function () {
var before = (0, _native_array.A)(this.newObjectsFixture(3));
var after = [before[0], before[2]];
var obj = before;
var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); // Prime the cache
obj.removeObjects([before[1]]);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
});
suite.test('[A,B,C].removeObjects([A,B]) => [C] + notify', function () {
var before = (0, _native_array.A)(this.newFixture(3));
var after = [before[2]];
var obj = before;
var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); // Prime the cache
obj.removeObjects([before[0], before[1]]);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
});
suite.test('[{A},{B},{C}].removeObjects([{A},{B}]) => [{C}] + notify', function () {
var before = (0, _native_array.A)(this.newObjectsFixture(3));
var after = [before[2]];
var obj = before;
var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); // Prime the cache
obj.removeObjects([before[0], before[1]]);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
});
suite.test('[A,B,C].removeObjects([A,B,C]) => [] + notify', function () {
var before = (0, _native_array.A)(this.newFixture(3));
var after = [];
var obj = before;
var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); // Prime the cache
obj.removeObjects([before[0], before[1], before[2]]);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
equal(observer.timesCalled('lastObject'), 1, 'should have notified lastObject');
}
});
suite.test('[{A},{B},{C}].removeObjects([{A},{B},{C}]) => [] + notify', function () {
var before = (0, _native_array.A)(this.newObjectsFixture(3));
var after = [];
var obj = before;
var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); // Prime the cache
obj.removeObjects(before);
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.timesCalled('[]'), 1, 'should have notified [] once');
equal(observer.timesCalled('length'), 1, 'should have notified length once');
equal(observer.timesCalled('firstObject'), 1, 'should have notified firstObject');
equal(observer.validate('lastObject'), 1, 'should have notified lastObject');
}
});
suite.test('[A,B,C].removeObjects([D]) => [A,B,C]', function () {
var before = (0, _native_array.A)(this.newFixture(3));
var after = before;
var item = this.newFixture(1)[0];
var obj = before;
var observer = this.newObserver(obj, '[]', 'length', 'firstObject', 'lastObject');
obj.getProperties('firstObject', 'lastObject'); // Prime the cache
obj.removeObjects([item]); // Note: item not in set
deepEqual(this.toArray(obj), after, 'post item results');
equal((0, _emberMetal.get)(obj, 'length'), after.length, 'length');
if (observer.isEnabled) {
equal(observer.validate('[]'), false, 'should NOT have notified []');
equal(observer.validate('length'), false, 'should NOT have notified length');
equal(observer.validate('firstObject'), false, 'should NOT have notified firstObject');
equal(observer.validate('lastObject'), false, 'should NOT have notified lastObject');
}
});
suite.test('Removing objects should notify enumerable observer', function () {
var fixtures = this.newFixture(3);
var obj = this.newObject(fixtures);
var observer = this.newObserver(obj).observeEnumerable(obj);
var item = fixtures[1];
obj.removeObjects([item]);
deepEqual(observer._before, [obj, [item], null]);
deepEqual(observer._after, [obj, [item], null]);
});
exports.default = suite;
});
enifed('ember-runtime/tests/suites/suite', ['exports', 'ember-utils', 'ember-runtime/system/object', 'ember-metal'], function (exports, _emberUtils, _object, _emberMetal) {
'use strict';
exports.Suite = exports.SuiteModuleBuilder = undefined;
/*
@class
A Suite can be used to define a reusable set of unit tests that can be
applied to any object. Suites are most useful for defining tests that
work against a mixin or plugin API. Developers implementing objects that
use the mixin or support the API can then run these tests against their
own code to verify compliance.
To define a suite, you need to define the tests themselves as well as a
callback API implementers can use to tie your tests to their specific class.
## Defining a Callback API
To define the callback API, just extend this class and add your properties
or methods that must be provided.
## Defining Unit Tests
To add unit tests, use the suite.module() or suite.test() methods instead
of a regular module() or test() method when defining your tests. This will
add the tests to the suite.
## Using a Suite
To use a Suite to test your own objects, extend the suite subclass and
define any required methods. Then call run() on the new subclass. This
will create an instance of your class and then defining the unit tests.
@extends Ember.Object
@private
*/
var Suite = _object.default.extend({
/*
__Required.__ You must implement this method to apply this mixin.
Define a name for these tests - all modules are prefixed w/ it.
@type String
*/
name: null,
run: function () {}
});
Suite.reopenClass({
plan: null,
run: function () {
var C = this;
return new C().run();
},
module: function (desc, opts) {
if (!opts) {
opts = {};
}
var setup = opts.setup;
var teardown = opts.teardown;
this.reopen({
run: function () {
this._super.apply(this, arguments);
var title = (0, _emberMetal.get)(this, 'name') + ': ' + desc;
var ctx = this;
QUnit.module(title, {
setup: function () {
if (setup) {
setup.call(ctx);
}
},
teardown: function () {
if (teardown) {
teardown.call(ctx);
}
}
});
}
});
},
test: function (name, func) {
this.reopen({
run: function () {
this._super.apply(this, arguments);
var ctx = this;
if (!func) {
QUnit.test(name); // output warning
} else {
QUnit.test(name, function () {
return func.call(ctx);
});
}
}
});
},
same: function (actual, exp, message) {
actual = actual && actual.map ? actual.map(function (x) {
return (0, _emberUtils.guidFor)(x);
}) : actual;
exp = exp && exp.map ? exp.map(function (x) {
return (0, _emberUtils.guidFor)(x);
}) : exp;
return deepEqual(actual, exp, message);
},
notest: function () {},
importModuleTests: function (builder) {
var _this = this;
this.module(builder._module);
builder._tests.forEach(function (descAndFunc) {
_this.test.apply(_this, descAndFunc);
});
}
});
var SuiteModuleBuilder = _object.default.extend({
_module: null,
_tests: null,
init: function () {
this._tests = [];
},
module: function (name) {
this._module = name;
},
test: function (name, func) {
this._tests.push([name, func]);
}
});
exports.SuiteModuleBuilder = SuiteModuleBuilder;
exports.Suite = Suite;
exports.default = Suite;
});
enifed('ember-runtime/tests/system/application/base_test', ['ember-runtime/system/namespace', 'ember-runtime/system/application'], function (_namespace, _application) {
'use strict';
QUnit.module('Ember.Application');
QUnit.test('Ember.Application should be a subclass of Ember.Namespace', function () {
ok(_namespace.default.detect(_application.default), 'Ember.Application subclass of Ember.Namespace');
});
});
enifed('ember-runtime/tests/system/array_proxy/arranged_content_test', ['ember-metal', 'ember-runtime/system/array_proxy', 'ember-runtime/system/native_array', 'ember-runtime/mixins/array'], function (_emberMetal, _array_proxy, _native_array, _array) {
'use strict';
var array = void 0;
QUnit.module('ArrayProxy - arrangedContent', {
setup: function () {
(0, _emberMetal.run)(function () {
array = _array_proxy.default.extend({
arrangedContent: (0, _emberMetal.computed)('content.[]', function () {
var content = this.get('content');
return content && (0, _native_array.A)(content.slice().sort(function (a, b) {
if (a == null) {
a = -1;
}
if (b == null) {
b = -1;
}
return b - a;
}));
})
}).create({
content: (0, _native_array.A)([1, 2, 4, 5])
});
});
},
teardown: function () {
(0, _emberMetal.run)(function () {
return array.destroy();
});
}
});
QUnit.test('addObject - adds to end of \'content\' if not present', function () {
(0, _emberMetal.run)(function () {
return array.addObject(3);
});
deepEqual(array.get('content'), [1, 2, 4, 5, 3], 'adds to end of content');
deepEqual(array.get('arrangedContent'), [5, 4, 3, 2, 1], 'arrangedContent stays sorted');
(0, _emberMetal.run)(function () {
return array.addObject(1);
});
deepEqual(array.get('content'), [1, 2, 4, 5, 3], 'does not add existing number to content');
});
QUnit.test('addObjects - adds to end of \'content\' if not present', function () {
(0, _emberMetal.run)(function () {
return array.addObjects([1, 3, 6]);
});
deepEqual(array.get('content'), [1, 2, 4, 5, 3, 6], 'adds to end of content');
deepEqual(array.get('arrangedContent'), [6, 5, 4, 3, 2, 1], 'arrangedContent stays sorted');
});
QUnit.test('compact - returns arrangedContent without nulls and undefined', function () {
(0, _emberMetal.run)(function () {
return array.set('content', (0, _native_array.A)([1, 3, null, 2, undefined]));
});
deepEqual(array.compact(), [3, 2, 1]);
});
QUnit.test('indexOf - returns index of object in arrangedContent', function () {
equal(array.indexOf(4), 1, 'returns arranged index');
});
QUnit.test('insertAt - raises, indeterminate behavior', function () {
throws(function () {
return (0, _emberMetal.run)(function () {
return array.insertAt(2, 3);
});
});
});
QUnit.test('lastIndexOf - returns last index of object in arrangedContent', function () {
(0, _emberMetal.run)(function () {
return array.pushObject(4);
});
equal(array.lastIndexOf(4), 2, 'returns last arranged index');
});
QUnit.test('nextObject - returns object at index in arrangedContent', function () {
equal(array.nextObject(1), 4, 'returns object at index');
});
QUnit.test('objectAt - returns object at index in arrangedContent', function () {
equal((0, _array.objectAt)(array, 1), 4, 'returns object at index');
});
// Not sure if we need a specific test for it, since it's internal
QUnit.test('objectAtContent - returns object at index in arrangedContent', function () {
equal(array.objectAtContent(1), 4, 'returns object at index');
});
QUnit.test('objectsAt - returns objects at indices in arrangedContent', function () {
deepEqual(array.objectsAt([0, 2, 4]), [5, 2, undefined], 'returns objects at indices');
});
QUnit.test('popObject - removes last object in arrangedContent', function () {
var popped = void 0;
(0, _emberMetal.run)(function () {
return popped = array.popObject();
});
equal(popped, 1, 'returns last object');
deepEqual(array.get('content'), [2, 4, 5], 'removes from content');
});
QUnit.test('pushObject - adds to end of content even if it already exists', function () {
(0, _emberMetal.run)(function () {
return array.pushObject(1);
});
deepEqual(array.get('content'), [1, 2, 4, 5, 1], 'adds to end of content');
});
QUnit.test('pushObjects - adds multiple to end of content even if it already exists', function () {
(0, _emberMetal.run)(function () {
return array.pushObjects([1, 2, 4]);
});
deepEqual(array.get('content'), [1, 2, 4, 5, 1, 2, 4], 'adds to end of content');
});
QUnit.test('removeAt - removes from index in arrangedContent', function () {
(0, _emberMetal.run)(function () {
return array.removeAt(1, 2);
});
deepEqual(array.get('content'), [1, 5]);
});
QUnit.test('removeObject - removes object from content', function () {
(0, _emberMetal.run)(function () {
return array.removeObject(2);
});
deepEqual(array.get('content'), [1, 4, 5]);
});
QUnit.test('removeObjects - removes objects from content', function () {
(0, _emberMetal.run)(function () {
return array.removeObjects([2, 4, 6]);
});
deepEqual(array.get('content'), [1, 5]);
});
QUnit.test('replace - raises, indeterminate behavior', function () {
throws(function () {
return (0, _emberMetal.run)(function () {
return array.replace(1, 2, [3]);
});
});
});
QUnit.test('replaceContent - does a standard array replace on content', function () {
(0, _emberMetal.run)(function () {
return array.replaceContent(1, 2, [3]);
});
deepEqual(array.get('content'), [1, 3, 5]);
});
QUnit.test('reverseObjects - raises, use Sortable#sortAscending', function () {
throws(function () {
return (0, _emberMetal.run)(function () {
return array.reverseObjects();
});
});
});
QUnit.test('setObjects - replaces entire content', function () {
(0, _emberMetal.run)(function () {
return array.setObjects([6, 7, 8]);
});
deepEqual(array.get('content'), [6, 7, 8], 'replaces content');
});
QUnit.test('shiftObject - removes from start of arrangedContent', function () {
var shifted = (0, _emberMetal.run)(function () {
return array.shiftObject();
});
equal(shifted, 5, 'returns first object');
deepEqual(array.get('content'), [1, 2, 4], 'removes object from content');
});
QUnit.test('slice - returns a slice of the arrangedContent', function () {
deepEqual(array.slice(1, 3), [4, 2], 'returns sliced arrangedContent');
});
QUnit.test('toArray - returns copy of arrangedContent', function () {
deepEqual(array.toArray(), [5, 4, 2, 1]);
});
QUnit.test('unshiftObject - adds to start of content', function () {
(0, _emberMetal.run)(function () {
return array.unshiftObject(6);
});
deepEqual(array.get('content'), [6, 1, 2, 4, 5], 'adds to start of content');
});
QUnit.test('unshiftObjects - adds to start of content', function () {
(0, _emberMetal.run)(function () {
array.unshiftObjects([6, 7]);
});
deepEqual(array.get('content'), [6, 7, 1, 2, 4, 5], 'adds to start of content');
});
QUnit.test('without - returns arrangedContent without object', function () {
deepEqual(array.without(2), [5, 4, 1], 'returns arranged without object');
});
QUnit.test('lastObject - returns last arranged object', function () {
equal(array.get('lastObject'), 1, 'returns last arranged object');
});
QUnit.test('firstObject - returns first arranged object', function () {
equal(array.get('firstObject'), 5, 'returns first arranged object');
});
QUnit.module('ArrayProxy - arrangedContent matching content', {
setup: function () {
(0, _emberMetal.run)(function () {
array = _array_proxy.default.create({
content: (0, _native_array.A)([1, 2, 4, 5])
});
});
},
teardown: function () {
(0, _emberMetal.run)(function () {
array.destroy();
});
}
});
QUnit.test('insertAt - inserts object at specified index', function () {
(0, _emberMetal.run)(function () {
array.insertAt(2, 3);
});
deepEqual(array.get('content'), [1, 2, 3, 4, 5]);
});
QUnit.test('replace - does a standard array replace', function () {
(0, _emberMetal.run)(function () {
array.replace(1, 2, [3]);
});
deepEqual(array.get('content'), [1, 3, 5]);
});
QUnit.test('reverseObjects - reverses content', function () {
(0, _emberMetal.run)(function () {
array.reverseObjects();
});
deepEqual(array.get('content'), [5, 4, 2, 1]);
});
QUnit.module('ArrayProxy - arrangedContent with transforms', {
setup: function () {
(0, _emberMetal.run)(function () {
array = _array_proxy.default.extend({
arrangedContent: (0, _emberMetal.computed)(function () {
var content = this.get('content');
return content && (0, _native_array.A)(content.slice().sort(function (a, b) {
if (a == null) {
a = -1;
}
if (b == null) {
b = -1;
}
return b - a;
}));
}).property('content.[]'),
objectAtContent: function (idx) {
var obj = (0, _array.objectAt)(this.get('arrangedContent'), idx);
return obj && obj.toString();
}
}).create({
content: (0, _native_array.A)([1, 2, 4, 5])
});
});
},
teardown: function () {
(0, _emberMetal.run)(function () {
array.destroy();
});
}
});
QUnit.test('indexOf - returns index of object in arrangedContent', function () {
equal(array.indexOf('4'), 1, 'returns arranged index');
});
QUnit.test('lastIndexOf - returns last index of object in arrangedContent', function () {
(0, _emberMetal.run)(function () {
array.pushObject(4);
});
equal(array.lastIndexOf('4'), 2, 'returns last arranged index');
});
QUnit.test('nextObject - returns object at index in arrangedContent', function () {
equal(array.nextObject(1), '4', 'returns object at index');
});
QUnit.test('objectAt - returns object at index in arrangedContent', function () {
equal((0, _array.objectAt)(array, 1), '4', 'returns object at index');
});
// Not sure if we need a specific test for it, since it's internal
QUnit.test('objectAtContent - returns object at index in arrangedContent', function () {
equal(array.objectAtContent(1), '4', 'returns object at index');
});
QUnit.test('objectsAt - returns objects at indices in arrangedContent', function () {
deepEqual(array.objectsAt([0, 2, 4]), ['5', '2', undefined], 'returns objects at indices');
});
QUnit.test('popObject - removes last object in arrangedContent', function () {
var popped = void 0;
(0, _emberMetal.run)(function () {
popped = array.popObject();
});
equal(popped, '1', 'returns last object');
deepEqual(array.get('content'), [2, 4, 5], 'removes from content');
});
QUnit.test('removeObject - removes object from content', function () {
(0, _emberMetal.run)(function () {
array.removeObject('2');
});
deepEqual(array.get('content'), [1, 4, 5]);
});
QUnit.test('removeObjects - removes objects from content', function () {
(0, _emberMetal.run)(function () {
array.removeObjects(['2', '4', '6']);
});
deepEqual(array.get('content'), [1, 5]);
});
QUnit.test('shiftObject - removes from start of arrangedContent', function () {
var shifted = void 0;
(0, _emberMetal.run)(function () {
shifted = array.shiftObject();
});
equal(shifted, '5', 'returns first object');
deepEqual(array.get('content'), [1, 2, 4], 'removes object from content');
});
QUnit.test('slice - returns a slice of the arrangedContent', function () {
deepEqual(array.slice(1, 3), ['4', '2'], 'returns sliced arrangedContent');
});
QUnit.test('toArray - returns copy of arrangedContent', function () {
deepEqual(array.toArray(), ['5', '4', '2', '1']);
});
QUnit.test('without - returns arrangedContent without object', function () {
deepEqual(array.without('2'), ['5', '4', '1'], 'returns arranged without object');
});
QUnit.test('lastObject - returns last arranged object', function () {
equal(array.get('lastObject'), '1', 'returns last arranged object');
});
QUnit.test('firstObject - returns first arranged object', function () {
equal(array.get('firstObject'), '5', 'returns first arranged object');
});
QUnit.test('arrangedContentArray{Will,Did}Change are called when the arranged content changes', function () {
// The behaviour covered by this test may change in the future if we decide
// that built-in array methods are not overridable.
var willChangeCallCount = 0;
var didChangeCallCount = 0;
var content = (0, _native_array.A)([1, 2, 3]);
_array_proxy.default.extend({
arrangedContentArrayWillChange: function () {
willChangeCallCount++;
this._super.apply(this, arguments);
},
arrangedContentArrayDidChange: function () {
didChangeCallCount++;
this._super.apply(this, arguments);
}
}).create({ content: content });
equal(willChangeCallCount, 0);
equal(didChangeCallCount, 0);
content.pushObject(4);
content.pushObject(5);
equal(willChangeCallCount, 2);
equal(didChangeCallCount, 2);
});
});
enifed('ember-runtime/tests/system/array_proxy/content_change_test', ['ember-metal', 'ember-runtime/computed/computed_macros', 'ember-runtime/system/array_proxy', 'ember-runtime/system/native_array'], function (_emberMetal, _computed_macros, _array_proxy, _native_array) {
'use strict';
QUnit.module('ArrayProxy - content change');
QUnit.test('should update length for null content', function () {
var proxy = _array_proxy.default.create({
content: (0, _native_array.A)([1, 2, 3])
});
equal(proxy.get('length'), 3, 'precond - length is 3');
proxy.set('content', null);
equal(proxy.get('length'), 0, 'length updates');
});
QUnit.test('should update length for null content when there is a computed property watching length', function () {
var proxy = _array_proxy.default.extend({
isEmpty: (0, _computed_macros.not)('length')
}).create({
content: (0, _native_array.A)([1, 2, 3])
});
equal(proxy.get('length'), 3, 'precond - length is 3');
// Consume computed property that depends on length
proxy.get('isEmpty');
// update content
proxy.set('content', null);
equal(proxy.get('length'), 0, 'length updates');
});
QUnit.test('The `arrangedContentWillChange` method is invoked before `content` is changed.', function () {
var callCount = 0;
var expectedLength = void 0;
var proxy = _array_proxy.default.extend({
arrangedContentWillChange: function () {
equal(this.get('arrangedContent.length'), expectedLength, 'hook should be invoked before array has changed');
callCount++;
}
}).create({ content: (0, _native_array.A)([1, 2, 3]) });
proxy.pushObject(4);
equal(callCount, 0, 'pushing content onto the array doesn\'t trigger it');
proxy.get('content').pushObject(5);
equal(callCount, 0, 'pushing content onto the content array doesn\'t trigger it');
expectedLength = 5;
proxy.set('content', (0, _native_array.A)(['a', 'b']));
equal(callCount, 1, 'replacing the content array triggers the hook');
});
QUnit.test('The `arrangedContentDidChange` method is invoked after `content` is changed.', function () {
var callCount = 0;
var expectedLength = void 0;
var proxy = _array_proxy.default.extend({
arrangedContentDidChange: function () {
equal(this.get('arrangedContent.length'), expectedLength, 'hook should be invoked after array has changed');
callCount++;
}
}).create({
content: (0, _native_array.A)([1, 2, 3])
});
equal(callCount, 0, 'hook is not called after creating the object');
proxy.pushObject(4);
equal(callCount, 0, 'pushing content onto the array doesn\'t trigger it');
proxy.get('content').pushObject(5);
equal(callCount, 0, 'pushing content onto the content array doesn\'t trigger it');
expectedLength = 2;
proxy.set('content', (0, _native_array.A)(['a', 'b']));
equal(callCount, 1, 'replacing the content array triggers the hook');
});
QUnit.test('The ArrayProxy doesn\'t explode when assigned a destroyed object', function () {
var proxy1 = _array_proxy.default.create();
var proxy2 = _array_proxy.default.create();
(0, _emberMetal.run)(function () {
return proxy1.destroy();
});
(0, _emberMetal.set)(proxy2, 'content', proxy1);
ok(true, 'No exception was raised');
});
QUnit.test('arrayContent{Will,Did}Change are called when the content changes', function () {
// The behaviour covered by this test may change in the future if we decide
// that built-in array methods are not overridable.
var willChangeCallCount = 0;
var didChangeCallCount = 0;
var content = (0, _native_array.A)([1, 2, 3]);
_array_proxy.default.extend({
arrayContentWillChange: function () {
willChangeCallCount++;
this._super.apply(this, arguments);
},
arrayContentDidChange: function () {
didChangeCallCount++;
this._super.apply(this, arguments);
}
}).create({ content: content });
equal(willChangeCallCount, 0);
equal(didChangeCallCount, 0);
content.pushObject(4);
content.pushObject(5);
equal(willChangeCallCount, 2);
equal(didChangeCallCount, 2);
});
});
enifed('ember-runtime/tests/system/array_proxy/content_update_test', ['ember-metal', 'ember-runtime/system/array_proxy', 'ember-runtime/system/native_array'], function (_emberMetal, _array_proxy, _native_array) {
'use strict';
QUnit.module('Ember.ArrayProxy - content update');
QUnit.test('The `contentArrayDidChange` method is invoked after `content` is updated.', function () {
var observerCalled = false;
var proxy = _array_proxy.default.extend({
arrangedContent: (0, _emberMetal.computed)('content', function () {
return (0, _native_array.A)(this.get('content').slice());
}),
contentArrayDidChange: function (array, idx, removedCount, addedCount) {
observerCalled = true;
return this._super(array, idx, removedCount, addedCount);
}
}).create({
content: (0, _native_array.A)()
});
proxy.pushObject(1);
ok(observerCalled, 'contentArrayDidChange is invoked');
});
});
enifed('ember-runtime/tests/system/array_proxy/length_test', ['ember-runtime/system/array_proxy', 'ember-runtime/system/object', 'ember-metal', 'ember-runtime/system/native_array'], function (_array_proxy, _object, _emberMetal, _native_array) {
'use strict';
QUnit.module('Ember.ArrayProxy - content change (length)');
QUnit.test('array proxy + aliasedProperty complex test', function () {
var aCalled = void 0,
bCalled = void 0,
cCalled = void 0,
dCalled = void 0,
eCalled = void 0;
aCalled = bCalled = cCalled = dCalled = eCalled = 0;
var obj = _object.default.extend({
colors: _emberMetal.computed.reads('model'),
length: _emberMetal.computed.reads('colors.length'),
a: (0, _emberMetal.observer)('length', function () {
return aCalled++;
}),
b: (0, _emberMetal.observer)('colors.length', function () {
return bCalled++;
}),
c: (0, _emberMetal.observer)('colors.content.length', function () {
return cCalled++;
}),
d: (0, _emberMetal.observer)('colors.[]', function () {
return dCalled++;
}),
e: (0, _emberMetal.observer)('colors.content.[]', function () {
return eCalled++;
})
}).create();
obj.set('model', _array_proxy.default.create({
content: (0, _native_array.A)(['red', 'yellow', 'blue'])
}));
equal(obj.get('colors.content.length'), 3);
equal(obj.get('colors.length'), 3);
equal(obj.get('length'), 3);
equal(aCalled, 1, 'expected observer `length` to be called ONCE');
equal(bCalled, 1, 'expected observer `colors.length` to be called ONCE');
equal(cCalled, 1, 'expected observer `colors.content.length` to be called ONCE');
equal(dCalled, 1, 'expected observer `colors.[]` to be called ONCE');
equal(eCalled, 1, 'expected observer `colors.content.[]` to be called ONCE');
obj.get('colors').pushObjects(['green', 'red']);
equal(obj.get('colors.content.length'), 5);
equal(obj.get('colors.length'), 5);
equal(obj.get('length'), 5);
equal(aCalled, 2, 'expected observer `length` to be called TWICE');
equal(bCalled, 2, 'expected observer `colors.length` to be called TWICE');
equal(cCalled, 2, 'expected observer `colors.content.length` to be called TWICE');
equal(dCalled, 2, 'expected observer `colors.[]` to be called TWICE');
equal(eCalled, 2, 'expected observer `colors.content.[]` to be called TWICE');
});
});
enifed('ember-runtime/tests/system/array_proxy/suite_test', ['ember-runtime/tests/suites/mutable_array', 'ember-runtime/system/array_proxy', 'ember-metal', 'ember-runtime/system/native_array'], function (_mutable_array, _array_proxy, _emberMetal, _native_array) {
'use strict';
_mutable_array.default.extend({
name: 'Ember.ArrayProxy',
newObject: function (ary) {
var ret = ary ? ary.slice() : this.newFixture(3);
return _array_proxy.default.create({ content: (0, _native_array.A)(ret) });
},
mutate: function (obj) {
obj.pushObject((0, _emberMetal.get)(obj, 'length') + 1);
},
toArray: function (obj) {
return obj.toArray ? obj.toArray() : obj.slice();
}
}).run();
});
enifed('ember-runtime/tests/system/array_proxy/watching_and_listening_test', ['ember-metal', 'ember-runtime/system/array_proxy', 'ember-runtime/system/native_array'], function (_emberMetal, _array_proxy, _native_array) {
'use strict';
function sortedListenersFor(obj, eventName) {
return (0, _emberMetal.listenersFor)(obj, eventName).sort(function (listener1, listener2) {
return listener1[1] > listener2[1] ? -1 : 1;
});
}
QUnit.module('ArrayProxy - watching and listening');
QUnit.test('setting \'content\' adds listeners correctly', function () {
var content = (0, _native_array.A)();
var proxy = _array_proxy.default.create();
deepEqual(sortedListenersFor(content, '@array:before'), []);
deepEqual(sortedListenersFor(content, '@array:change'), []);
proxy.set('content', content);
deepEqual(sortedListenersFor(content, '@array:before'), [[proxy, 'contentArrayWillChange'], [proxy, 'arrangedContentArrayWillChange']]);
deepEqual(sortedListenersFor(content, '@array:change'), [[proxy, 'contentArrayDidChange'], [proxy, 'arrangedContentArrayDidChange']]);
});
QUnit.test('changing \'content\' adds and removes listeners correctly', function () {
var content1 = (0, _native_array.A)();
var content2 = (0, _native_array.A)();
var proxy = _array_proxy.default.create({ content: content1 });
deepEqual(sortedListenersFor(content1, '@array:before'), [[proxy, 'contentArrayWillChange'], [proxy, 'arrangedContentArrayWillChange']]);
deepEqual(sortedListenersFor(content1, '@array:change'), [[proxy, 'contentArrayDidChange'], [proxy, 'arrangedContentArrayDidChange']]);
proxy.set('content', content2);
deepEqual(sortedListenersFor(content1, '@array:before'), []);
deepEqual(sortedListenersFor(content1, '@array:change'), []);
deepEqual(sortedListenersFor(content2, '@array:before'), [[proxy, 'contentArrayWillChange'], [proxy, 'arrangedContentArrayWillChange']]);
deepEqual(sortedListenersFor(content2, '@array:change'), [[proxy, 'contentArrayDidChange'], [proxy, 'arrangedContentArrayDidChange']]);
});
QUnit.test('regression test for https://github.com/emberjs/ember.js/issues/12475', function () {
var item1a = { id: 1 };
var item1b = { id: 2 };
var item1c = { id: 3 };
var content1 = (0, _native_array.A)([item1a, item1b, item1c]);
var proxy = _array_proxy.default.create({ content: content1 });
var obj = { proxy: proxy };
(0, _emberMetal.defineProperty)(obj, 'ids', (0, _emberMetal.computed)('proxy.@each.id', function () {
return (0, _emberMetal.get)(this, 'proxy').mapBy('id');
}));
// These manually added observers are to simulate the observers added by the
// rendering process in a template like:
//
// {{#each items as |item|}}
// {{item.id}}
// {{/each}}
(0, _emberMetal.addObserver)(item1a, 'id', function () {});
(0, _emberMetal.addObserver)(item1b, 'id', function () {});
(0, _emberMetal.addObserver)(item1c, 'id', function () {});
// The EachProxy has not yet been consumed. Only the manually added
// observers are watching.
equal((0, _emberMetal.watcherCount)(item1a, 'id'), 1);
equal((0, _emberMetal.watcherCount)(item1b, 'id'), 1);
equal((0, _emberMetal.watcherCount)(item1c, 'id'), 1);
// Consume the each proxy. This causes the EachProxy to add two observers
// per item: one for "before" events and one for "after" events.
deepEqual((0, _emberMetal.get)(obj, 'ids'), [1, 2, 3]);
// For each item, the two each proxy observers and one manual added observer
// are watching.
equal((0, _emberMetal.watcherCount)(item1a, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item1b, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item1c, 'id'), 3);
// This should be a no-op because observers do not fire if the value
// 1. is an object and 2. is the same as the old value.
proxy.set('content', content1);
equal((0, _emberMetal.watcherCount)(item1a, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item1b, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item1c, 'id'), 3);
// This is repeated to catch the regression. It should still be a no-op.
proxy.set('content', content1);
equal((0, _emberMetal.watcherCount)(item1a, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item1b, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item1c, 'id'), 3);
// Set the content to a new array with completely different items and
// repeat the process.
var item2a = { id: 4 };
var item2b = { id: 5 };
var item2c = { id: 6 };
var content2 = (0, _native_array.A)([item2a, item2b, item2c]);
(0, _emberMetal.addObserver)(item2a, 'id', function () {});
(0, _emberMetal.addObserver)(item2b, 'id', function () {});
(0, _emberMetal.addObserver)(item2c, 'id', function () {});
proxy.set('content', content2);
deepEqual((0, _emberMetal.get)(obj, 'ids'), [4, 5, 6]);
equal((0, _emberMetal.watcherCount)(item2a, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item2b, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item2c, 'id'), 3);
// Ensure that the observers added by the EachProxy on all items in the
// first content array have been torn down.
equal((0, _emberMetal.watcherCount)(item1a, 'id'), 1);
equal((0, _emberMetal.watcherCount)(item1b, 'id'), 1);
equal((0, _emberMetal.watcherCount)(item1c, 'id'), 1);
proxy.set('content', content2);
equal((0, _emberMetal.watcherCount)(item2a, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item2b, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item2c, 'id'), 3);
proxy.set('content', content2);
equal((0, _emberMetal.watcherCount)(item2a, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item2b, 'id'), 3);
equal((0, _emberMetal.watcherCount)(item2c, 'id'), 3);
});
});
enifed('ember-runtime/tests/system/core_object_test', ['ember-runtime/system/core_object', 'ember-metal'], function (_core_object, _emberMetal) {
'use strict';
QUnit.module('Ember.CoreObject');
QUnit.test('works with new (one arg)', function () {
var obj = new _core_object.default({
firstName: 'Stef',
lastName: 'Penner'
});
equal(obj.firstName, 'Stef');
equal(obj.lastName, 'Penner');
});
QUnit.test('works with new (> 1 arg)', function () {
var obj = new _core_object.default({
firstName: 'Stef',
lastName: 'Penner'
}, {
other: 'name'
});
equal(obj.firstName, 'Stef');
equal(obj.lastName, 'Penner');
equal(obj.other, undefined); // doesn't support multiple pojo' to the constructor
});
QUnit.test('toString should be not be added as a property when calling toString()', function () {
var obj = new _core_object.default({
firstName: 'Foo',
lastName: 'Bar'
});
obj.toString();
notOk(obj.hasOwnProperty('toString'), 'Calling toString() should not create a toString class property');
});
QUnit.test('[POST_INIT] invoked during construction', function () {
var _CoreObject$extend;
var callCount = 0;
var Obj = _core_object.default.extend((_CoreObject$extend = {}, _CoreObject$extend[_core_object.POST_INIT] = function () {
callCount++;
}, _CoreObject$extend));
equal(callCount, 0);
Obj.create();
equal(callCount, 1);
});
QUnit.test('[POST_INIT] invoked before finishChains', function () {
var _CoreObject$extend2;
var callCount = 0;
var Obj = _core_object.default.extend((_CoreObject$extend2 = {}, _CoreObject$extend2[_core_object.POST_INIT] = function () {
(0, _emberMetal.set)(this, 'hi', 1);
}, _CoreObject$extend2.hiDidChange = (0, _emberMetal.observer)('hi', function () {
callCount++;
}), _CoreObject$extend2));
equal(callCount, 0);
var obj = Obj.create();
equal(callCount, 0);
(0, _emberMetal.set)(obj, 'hi', 2);
equal(callCount, 1);
});
});
enifed('ember-runtime/tests/system/lazy_load_test', ['ember-metal', 'ember-runtime/system/lazy_load'], function (_emberMetal, _lazy_load) {
'use strict';
QUnit.module('Lazy Loading', {
teardown: function () {
var keys = Object.keys(_lazy_load._loaded),
i;
for (i = 0; i < keys.length; i++) {
delete _lazy_load._loaded[keys[i]];
}
}
});
QUnit.test('if a load hook is registered, it is executed when runLoadHooks are exected', function () {
var count = 0;
(0, _emberMetal.run)(function () {
(0, _lazy_load.onLoad)('__test_hook__', function (object) {
count += object;
});
});
(0, _emberMetal.run)(function () {
(0, _lazy_load.runLoadHooks)('__test_hook__', 1);
});
equal(count, 1, 'the object was passed into the load hook');
});
QUnit.test('if runLoadHooks was already run, it executes newly added hooks immediately', function () {
var count = 0;
(0, _emberMetal.run)(function () {
(0, _lazy_load.onLoad)('__test_hook__', function (object) {
return count += object;
});
});
(0, _emberMetal.run)(function () {
return (0, _lazy_load.runLoadHooks)('__test_hook__', 1);
});
count = 0;
(0, _emberMetal.run)(function () {
(0, _lazy_load.onLoad)('__test_hook__', function (object) {
return count += object;
});
});
equal(count, 1, 'the original object was passed into the load hook');
});
QUnit.test('hooks in ENV.EMBER_LOAD_HOOKS[\'hookName\'] get executed', function () {
// Note that the necessary code to perform this test is run before
// the Ember lib is loaded in tests/index.html
(0, _emberMetal.run)(function () {
(0, _lazy_load.runLoadHooks)('__before_ember_test_hook__', 1);
});
equal(window.ENV.__test_hook_count__, 1, 'the object was passed into the load hook');
});
if (typeof window === 'object' && typeof window.dispatchEvent === 'function' && typeof CustomEvent === 'function') {
QUnit.test('load hooks trigger a custom event', function () {
var eventObject = 'super duper awesome events';
window.addEventListener('__test_hook_for_events__', function (e) {
ok(true, 'custom event was fired');
equal(e.detail, eventObject, 'event details are provided properly');
});
(0, _emberMetal.run)(function () {
(0, _lazy_load.runLoadHooks)('__test_hook_for_events__', eventObject);
});
});
}
});
enifed('ember-runtime/tests/system/namespace/base_test', ['ember-environment', 'ember-metal', 'ember-runtime/system/object', 'ember-runtime/system/namespace'], function (_emberEnvironment, _emberMetal, _object, _namespace) {
'use strict';
var originalLookup = _emberEnvironment.context.lookup;
var lookup = void 0;
QUnit.module('Namespace', {
setup: function () {
(0, _namespace.setSearchDisabled)(false);
lookup = _emberEnvironment.context.lookup = {};
},
teardown: function () {
(0, _namespace.setSearchDisabled)(false);
for (var prop in lookup) {
if (lookup[prop]) {
(0, _emberMetal.run)(lookup[prop], 'destroy');
}
}
_emberEnvironment.context.lookup = originalLookup;
}
});
QUnit.test('Namespace should be a subclass of EmberObject', function () {
ok(_object.default.detect(_namespace.default));
});
QUnit.test('Namespace should be duck typed', function () {
ok((0, _emberMetal.get)(_namespace.default.create(), 'isNamespace'), 'isNamespace property is true');
});
QUnit.test('Namespace is found and named', function () {
var nsA = lookup.NamespaceA = _namespace.default.create();
equal(nsA.toString(), 'NamespaceA', 'namespaces should have a name if they are on lookup');
var nsB = lookup.NamespaceB = _namespace.default.create();
equal(nsB.toString(), 'NamespaceB', 'namespaces work if created after the first namespace processing pass');
});
QUnit.test('Classes under an Namespace are properly named', function () {
var nsA = lookup.NamespaceA = _namespace.default.create();
nsA.Foo = _object.default.extend();
equal(nsA.Foo.toString(), 'NamespaceA.Foo', 'Classes pick up their parent namespace');
nsA.Bar = _object.default.extend();
equal(nsA.Bar.toString(), 'NamespaceA.Bar', 'New Classes get the naming treatment too');
var nsB = lookup.NamespaceB = _namespace.default.create();
nsB.Foo = _object.default.extend();
equal(nsB.Foo.toString(), 'NamespaceB.Foo', 'Classes in new namespaces get the naming treatment');
});
//test("Classes under Ember are properly named", function() {
// // ES6TODO: This test does not work reliably when running independent package build with Broccoli config.
// Ember.TestObject = EmberObject.extend({});
// equal(Ember.TestObject.toString(), "Ember.TestObject", "class under Ember is given a string representation");
//});
QUnit.test('Lowercase namespaces are no longer supported', function () {
var nsC = lookup.namespaceC = _namespace.default.create();
equal(nsC.toString(), undefined);
});
QUnit.test('A namespace can be assigned a custom name', function () {
var nsA = _namespace.default.create({
name: 'NamespaceA'
});
var nsB = lookup.NamespaceB = _namespace.default.create({
name: 'CustomNamespaceB'
});
nsA.Foo = _object.default.extend();
nsB.Foo = _object.default.extend();
equal(nsA.Foo.toString(), 'NamespaceA.Foo', 'The namespace\'s name is used when the namespace is not in the lookup object');
equal(nsB.Foo.toString(), 'CustomNamespaceB.Foo', 'The namespace\'s name is used when the namespace is in the lookup object');
});
QUnit.test('Calling namespace.nameClasses() eagerly names all classes', function () {
(0, _namespace.setSearchDisabled)(true);
var namespace = lookup.NS = _namespace.default.create();
namespace.ClassA = _object.default.extend();
namespace.ClassB = _object.default.extend();
_namespace.default.processAll();
equal(namespace.ClassA.toString(), 'NS.ClassA');
equal(namespace.ClassB.toString(), 'NS.ClassB');
});
QUnit.test('A namespace can be looked up by its name', function () {
var NS = lookup.NS = _namespace.default.create();
var UI = lookup.UI = _namespace.default.create();
var CF = lookup.CF = _namespace.default.create();
equal(_namespace.default.byName('NS'), NS);
equal(_namespace.default.byName('UI'), UI);
equal(_namespace.default.byName('CF'), CF);
});
QUnit.test('A nested namespace can be looked up by its name', function () {
var UI = lookup.UI = _namespace.default.create();
UI.Nav = _namespace.default.create();
equal(_namespace.default.byName('UI.Nav'), UI.Nav);
});
QUnit.test('Destroying a namespace before caching lookup removes it from the list of namespaces', function () {
var CF = lookup.CF = _namespace.default.create();
(0, _emberMetal.run)(CF, 'destroy');
equal(_namespace.default.byName('CF'), undefined, 'namespace can not be found after destroyed');
});
QUnit.test('Destroying a namespace after looking up removes it from the list of namespaces', function () {
var CF = lookup.CF = _namespace.default.create();
equal(_namespace.default.byName('CF'), CF, 'precondition - namespace can be looked up by name');
(0, _emberMetal.run)(CF, 'destroy');
equal(_namespace.default.byName('CF'), undefined, 'namespace can not be found after destroyed');
});
});
enifed('ember-runtime/tests/system/native_array/a_test', ['ember-runtime/mixins/array', 'ember-runtime/system/native_array'], function (_array, _native_array) {
'use strict';
QUnit.module('Ember.A');
QUnit.test('Ember.A', function () {
deepEqual((0, _native_array.A)([1, 2]), [1, 2], 'array values were not be modified');
deepEqual((0, _native_array.A)(), [], 'returned an array with no arguments');
deepEqual((0, _native_array.A)(null), [], 'returned an array with a null argument');
ok(_array.default.detect((0, _native_array.A)()), 'returned an ember array');
ok(_array.default.detect((0, _native_array.A)([1, 2])), 'returned an ember array');
});
});
enifed('ember-runtime/tests/system/native_array/copyable_suite_test', ['ember-utils', 'ember-runtime/system/native_array', 'ember-runtime/tests/suites/copyable'], function (_emberUtils, _native_array, _copyable) {
'use strict';
_copyable.default.extend({
name: 'NativeArray Copyable',
newObject: function () {
return (0, _native_array.A)([(0, _emberUtils.generateGuid)()]);
},
isEqual: function (a, b) {
if (!(a instanceof Array)) {
return false;
}
if (!(b instanceof Array)) {
return false;
}
if (a.length !== b.length) {
return false;
}
return a[0] === b[0];
},
shouldBeFreezable: false
}).run();
QUnit.module('NativeArray Copyable');
QUnit.test('deep copy is respected', function () {
var array = (0, _native_array.A)([{ id: 1 }, { id: 2 }, { id: 3 }]);
var copiedArray = array.copy(true);
deepEqual(copiedArray, array, 'copied array is equivalent');
ok(copiedArray[0] !== array[0], 'objects inside should be unique');
});
});
enifed('ember-runtime/tests/system/native_array/suite_test', ['ember-runtime/system/native_array', 'ember-runtime/tests/suites/mutable_array'], function (_native_array, _mutable_array) {
'use strict';
_mutable_array.default.extend({
name: 'Native Array',
newObject: function (ary) {
return (0, _native_array.A)(ary ? ary.slice() : this.newFixture(3));
},
mutate: function (obj) {
obj.pushObject(obj.length + 1);
},
toArray: function (obj) {
return obj.slice(); // make a copy.
}
}).run();
});
enifed('ember-runtime/tests/system/object/computed_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object'], function (_emberMetal, _internalTestHelpers, _object) {
'use strict';
function K() {
return this;
}
QUnit.module('EmberObject computed property');
(0, _internalTestHelpers.testWithDefault)('computed property on instance', function (get) {
var MyClass = _object.default.extend({
foo: (0, _emberMetal.computed)(function () {
return 'FOO';
})
});
equal(get(new MyClass(), 'foo'), 'FOO');
});
(0, _internalTestHelpers.testWithDefault)('computed property on subclass', function (get) {
var MyClass = _object.default.extend({
foo: (0, _emberMetal.computed)(function () {
return 'FOO';
})
});
var Subclass = MyClass.extend({
foo: (0, _emberMetal.computed)(function () {
return 'BAR';
})
});
equal(get(new Subclass(), 'foo'), 'BAR');
});
(0, _internalTestHelpers.testWithDefault)('replacing computed property with regular val', function (get) {
var MyClass = _object.default.extend({
foo: (0, _emberMetal.computed)(function () {
return 'FOO';
})
});
var Subclass = MyClass.extend({
foo: 'BAR'
});
equal(get(new Subclass(), 'foo'), 'BAR');
});
(0, _internalTestHelpers.testWithDefault)('complex depndent keys', function (get, set) {
var MyClass = _object.default.extend({
init: function () {
this._super.apply(this, arguments);
set(this, 'bar', { baz: 'BIFF' });
},
count: 0,
foo: (0, _emberMetal.computed)(function () {
set(this, 'count', get(this, 'count') + 1);
return (0, _emberMetal.get)(get(this, 'bar'), 'baz') + ' ' + get(this, 'count');
}).property('bar.baz')
});
var Subclass = MyClass.extend({
count: 20
});
var obj1 = new MyClass();
var obj2 = new Subclass();
equal(get(obj1, 'foo'), 'BIFF 1');
equal(get(obj2, 'foo'), 'BIFF 21');
set(get(obj1, 'bar'), 'baz', 'BLARG');
equal(get(obj1, 'foo'), 'BLARG 2');
equal(get(obj2, 'foo'), 'BIFF 21');
set(get(obj2, 'bar'), 'baz', 'BOOM');
equal(get(obj1, 'foo'), 'BLARG 2');
equal(get(obj2, 'foo'), 'BOOM 22');
});
(0, _internalTestHelpers.testWithDefault)('complex dependent keys changing complex dependent keys', function (get, set) {
var MyClass = _object.default.extend({
init: function () {
this._super.apply(this, arguments);
set(this, 'bar', { baz: 'BIFF' });
},
count: 0,
foo: (0, _emberMetal.computed)(function () {
set(this, 'count', get(this, 'count') + 1);
return (0, _emberMetal.get)(get(this, 'bar'), 'baz') + ' ' + get(this, 'count');
}).property('bar.baz')
});
var Subclass = MyClass.extend({
init: function () {
this._super.apply(this, arguments);
set(this, 'bar2', { baz: 'BIFF2' });
},
count: 0,
foo: (0, _emberMetal.computed)(function () {
set(this, 'count', get(this, 'count') + 1);
return (0, _emberMetal.get)(get(this, 'bar2'), 'baz') + ' ' + get(this, 'count');
}).property('bar2.baz')
});
var obj2 = new Subclass();
equal(get(obj2, 'foo'), 'BIFF2 1');
set(get(obj2, 'bar'), 'baz', 'BLARG');
equal(get(obj2, 'foo'), 'BIFF2 1', 'should not invalidate property');
set(get(obj2, 'bar2'), 'baz', 'BLARG');
equal(get(obj2, 'foo'), 'BLARG 2', 'should invalidate property');
});
QUnit.test('can retrieve metadata for a computed property', function () {
var MyClass = _object.default.extend({
computedProperty: (0, _emberMetal.computed)(function () {}).meta({ key: 'keyValue' })
});
equal((0, _emberMetal.get)(MyClass.metaForProperty('computedProperty'), 'key'), 'keyValue', 'metadata saved on the computed property can be retrieved');
var ClassWithNoMetadata = _object.default.extend({
computedProperty: (0, _emberMetal.computed)(function () {}).volatile(),
staticProperty: 12
});
equal(typeof ClassWithNoMetadata.metaForProperty('computedProperty'), 'object', 'returns empty hash if no metadata has been saved');
expectAssertion(function () {
ClassWithNoMetadata.metaForProperty('nonexistentProperty');
}, 'metaForProperty() could not find a computed property with key \'nonexistentProperty\'.');
expectAssertion(function () {
ClassWithNoMetadata.metaForProperty('staticProperty');
}, 'metaForProperty() could not find a computed property with key \'staticProperty\'.');
});
QUnit.test('can iterate over a list of computed properties for a class', function () {
var MyClass = _object.default.extend({
foo: (0, _emberMetal.computed)(function () {}),
fooDidChange: (0, _emberMetal.observer)('foo', function () {}),
bar: (0, _emberMetal.computed)(function () {}),
qux: (0, _emberMetal.alias)('foo')
});
var SubClass = MyClass.extend({
baz: (0, _emberMetal.computed)(function () {})
});
SubClass.reopen({
bat: (0, _emberMetal.computed)(function () {}).meta({ iAmBat: true })
});
var list = [];
MyClass.eachComputedProperty(function (name) {
list.push(name);
});
deepEqual(list.sort(), ['bar', 'foo', 'qux'], 'watched and unwatched computed properties are iterated');
list = [];
SubClass.eachComputedProperty(function (name, meta) {
list.push(name);
if (name === 'bat') {
deepEqual(meta, { iAmBat: true });
} else {
deepEqual(meta, {});
}
});
deepEqual(list.sort(), ['bar', 'bat', 'baz', 'foo', 'qux'], 'all inherited properties are included');
});
QUnit.test('list of properties updates when an additional property is added (such cache busting)', function () {
var MyClass = _object.default.extend({
foo: (0, _emberMetal.computed)(K),
fooDidChange: (0, _emberMetal.observer)('foo', function () {}),
bar: (0, _emberMetal.computed)(K)
});
var list = [];
MyClass.eachComputedProperty(function (name) {
list.push(name);
});
deepEqual(list.sort(), ['bar', 'foo'].sort(), 'expected two computed properties');
MyClass.reopen({
baz: (0, _emberMetal.computed)(K)
});
MyClass.create(); // force apply mixins
list = [];
MyClass.eachComputedProperty(function (name) {
list.push(name);
});
deepEqual(list.sort(), ['bar', 'foo', 'baz'].sort(), 'expected three computed properties');
});
QUnit.test('Calling _super in call outside the immediate function of a CP getter works', function () {
var MyClass = _object.default.extend({
foo: (0, _emberMetal.computed)(function () {
return 'FOO';
})
});
var SubClass = MyClass.extend({
foo: function (callback) {
return (0, _emberMetal.computed)(function () {
return callback.call(this);
});
}(function () {
return this._super();
})
});
ok((0, _emberMetal.get)(SubClass.create(), 'foo'), 'FOO', 'super value is fetched');
});
QUnit.test('Calling _super in apply outside the immediate function of a CP getter works', function () {
var MyClass = _object.default.extend({
foo: (0, _emberMetal.computed)(function () {
return 'FOO';
})
});
var SubClass = MyClass.extend({
foo: function (callback) {
return (0, _emberMetal.computed)(function () {
return callback.apply(this);
});
}(function () {
return this._super();
})
});
ok((0, _emberMetal.get)(SubClass.create(), 'foo'), 'FOO', 'super value is fetched');
});
});
enifed('ember-runtime/tests/system/object/create_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) {
'use strict';
QUnit.module('EmberObject.create', {});
QUnit.test('simple properties are set', function () {
var o = _object.default.create({ ohai: 'there' });
equal(o.get('ohai'), 'there');
});
QUnit.test('calls computed property setters', function () {
var MyClass = _object.default.extend({
foo: (0, _emberMetal.computed)({
get: function () {
return 'this is not the value you\'re looking for';
},
set: function (key, value) {
return value;
}
})
});
var o = MyClass.create({ foo: 'bar' });
equal(o.get('foo'), 'bar');
});
QUnit.test('allows bindings to be defined', function () {
var obj = void 0;
var deprecationMessage = /`Ember.Binding` is deprecated/;
expectDeprecation(function () {
obj = _object.default.create({
foo: 'foo',
barBinding: 'foo'
});
}, deprecationMessage);
equal(obj.get('bar'), 'foo', 'The binding value is correct');
});
QUnit.test('calls setUnknownProperty if defined', function () {
var setUnknownPropertyCalled = false;
var MyClass = _object.default.extend({
setUnknownProperty: function () {
setUnknownPropertyCalled = true;
}
});
MyClass.create({ foo: 'bar' });
ok(setUnknownPropertyCalled, 'setUnknownProperty was called');
});
QUnit.test('throws if you try to define a computed property', function () {
expectAssertion(function () {
_object.default.create({
foo: (0, _emberMetal.computed)(function () {})
});
}, 'Ember.Object.create no longer supports defining computed properties. Define computed properties using extend() or reopen() before calling create().');
});
QUnit.test('throws if you try to call _super in a method', function () {
expectAssertion(function () {
_object.default.create({
foo: function () {
this._super.apply(this, arguments);
}
});
}, 'Ember.Object.create no longer supports defining methods that call _super.');
});
QUnit.test('throws if you try to \'mixin\' a definition', function () {
var myMixin = _emberMetal.Mixin.create({
adder: function (arg1, arg2) {
return arg1 + arg2;
}
});
expectAssertion(function () {
_object.default.create(myMixin);
}, 'Ember.Object.create no longer supports mixing in other definitions, use .extend & .create separately instead.');
});
// This test is for IE8.
QUnit.test('property name is the same as own prototype property', function () {
var MyClass = _object.default.extend({
toString: function () {
return 'MyClass';
}
});
equal(MyClass.create().toString(), 'MyClass', 'should inherit property from the arguments of `EmberObject.create`');
});
QUnit.test('inherits properties from passed in EmberObject', function () {
var baseObj = _object.default.create({ foo: 'bar' });
var secondaryObj = _object.default.create(baseObj);
equal(secondaryObj.foo, baseObj.foo, 'Em.O.create inherits properties from EmberObject parameter');
});
QUnit.test('throws if you try to pass anything a string as a parameter', function () {
throws(function () {
return _object.default.create('some-string');
}, 'EmberObject.create only accepts an objects.');
});
QUnit.test('EmberObject.create can take undefined as a parameter', function () {
var o = _object.default.create(undefined);
deepEqual(_object.default.create(), o);
});
QUnit.test('EmberObject.create can take null as a parameter', function () {
var o = _object.default.create(null);
deepEqual(_object.default.create(), o);
});
QUnit.test('EmberObject.create avoids allocating a binding map when not necessary', function () {
var o = _object.default.create();
var m = (0, _emberMetal.meta)(o);
ok(!m.peekBindings(), 'A binding map is not allocated');
});
});
enifed('ember-runtime/tests/system/object/destroy_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object'], function (_emberMetal, _internalTestHelpers, _object) {
'use strict';
QUnit.module('ember-runtime/system/object/destroy_test');
(0, _internalTestHelpers.testBoth)('should schedule objects to be destroyed at the end of the run loop', function (get) {
var obj = _object.default.create();
var meta = void 0;
(0, _emberMetal.run)(function () {
obj.destroy();
meta = (0, _emberMetal.peekMeta)(obj);
ok(meta, 'meta is not destroyed immediately');
ok(get(obj, 'isDestroying'), 'object is marked as destroying immediately');
ok(!get(obj, 'isDestroyed'), 'object is not destroyed immediately');
});
meta = (0, _emberMetal.peekMeta)(obj);
ok(get(obj, 'isDestroyed'), 'object is destroyed after run loop finishes');
});
QUnit.test('observers should not fire after an object has been destroyed', function () {
var count = 0;
var obj = _object.default.extend({
fooDidChange: (0, _emberMetal.observer)('foo', function () {
count++;
})
}).create();
obj.set('foo', 'bar');
equal(count, 1, 'observer was fired once');
(0, _emberMetal.run)(function () {
(0, _emberMetal.beginPropertyChanges)();
obj.set('foo', 'quux');
obj.destroy();
(0, _emberMetal.endPropertyChanges)();
});
equal(count, 1, 'observer was not called after object was destroyed');
});
QUnit.test('destroyed objects should not see each others changes during teardown but a long lived object should', function () {
var shouldChange = 0;
var shouldNotChange = 0;
var objs = {};
var A = _object.default.extend({
objs: objs,
isAlive: true,
willDestroy: function () {
this.set('isAlive', false);
},
bDidChange: (0, _emberMetal.observer)('objs.b.isAlive', function () {
shouldNotChange++;
}),
cDidChange: (0, _emberMetal.observer)('objs.c.isAlive', function () {
shouldNotChange++;
})
});
var B = _object.default.extend({
objs: objs,
isAlive: true,
willDestroy: function () {
this.set('isAlive', false);
},
aDidChange: (0, _emberMetal.observer)('objs.a.isAlive', function () {
shouldNotChange++;
}),
cDidChange: (0, _emberMetal.observer)('objs.c.isAlive', function () {
shouldNotChange++;
})
});
var C = _object.default.extend({
objs: objs,
isAlive: true,
willDestroy: function () {
this.set('isAlive', false);
},
aDidChange: (0, _emberMetal.observer)('objs.a.isAlive', function () {
shouldNotChange++;
}),
bDidChange: (0, _emberMetal.observer)('objs.b.isAlive', function () {
shouldNotChange++;
})
});
var LongLivedObject = _object.default.extend({
objs: objs,
isAliveDidChange: (0, _emberMetal.observer)('objs.a.isAlive', function () {
shouldChange++;
})
});
objs.a = new A();
objs.b = new B();
objs.c = new C();
new LongLivedObject();
(0, _emberMetal.run)(function () {
var keys = Object.keys(objs),
i;
for (i = 0; i < keys.length; i++) {
objs[keys[i]].destroy();
}
});
equal(shouldNotChange, 0, 'destroyed graph objs should not see change in willDestroy');
equal(shouldChange, 1, 'long lived should see change in willDestroy');
});
QUnit.test('bindings should be synced when are updated in the willDestroy hook', function () {
var bar = _object.default.create({
value: false,
willDestroy: function () {
this.set('value', true);
}
});
var foo = _object.default.create({
value: null,
bar: bar
});
(0, _emberMetal.run)(function () {
var deprecationMessage = /`Ember.Binding` is deprecated/;
expectDeprecation(function () {
(0, _emberMetal.bind)(foo, 'value', 'bar.value');
}, deprecationMessage);
});
ok(bar.get('value') === false, 'the initial value has been bound');
(0, _emberMetal.run)(function () {
return bar.destroy();
});
ok(foo.get('value'), 'foo is synced when the binding is updated in the willDestroy hook');
});
});
enifed('ember-runtime/tests/system/object/detectInstance_test', ['ember-runtime/system/object'], function (_object) {
'use strict';
QUnit.module('system/object/detectInstance');
QUnit.test('detectInstance detects instances correctly', function () {
var A = _object.default.extend();
var B = A.extend();
var C = A.extend();
var o = _object.default.create();
var a = A.create();
var b = B.create();
var c = C.create();
ok(_object.default.detectInstance(o), 'o is an instance of EmberObject');
ok(_object.default.detectInstance(a), 'a is an instance of EmberObject');
ok(_object.default.detectInstance(b), 'b is an instance of EmberObject');
ok(_object.default.detectInstance(c), 'c is an instance of EmberObject');
ok(!A.detectInstance(o), 'o is not an instance of A');
ok(A.detectInstance(a), 'a is an instance of A');
ok(A.detectInstance(b), 'b is an instance of A');
ok(A.detectInstance(c), 'c is an instance of A');
ok(!B.detectInstance(o), 'o is not an instance of B');
ok(!B.detectInstance(a), 'a is not an instance of B');
ok(B.detectInstance(b), 'b is an instance of B');
ok(!B.detectInstance(c), 'c is not an instance of B');
ok(!C.detectInstance(o), 'o is not an instance of C');
ok(!C.detectInstance(a), 'a is not an instance of C');
ok(!C.detectInstance(b), 'b is not an instance of C');
ok(C.detectInstance(c), 'c is an instance of C');
});
});
enifed('ember-runtime/tests/system/object/detect_test', ['ember-runtime/system/object'], function (_object) {
'use strict';
QUnit.module('system/object/detect');
QUnit.test('detect detects classes correctly', function () {
var A = _object.default.extend();
var B = A.extend();
var C = A.extend();
ok(_object.default.detect(_object.default), 'EmberObject is an EmberObject class');
ok(_object.default.detect(A), 'A is an EmberObject class');
ok(_object.default.detect(B), 'B is an EmberObject class');
ok(_object.default.detect(C), 'C is an EmberObject class');
ok(!A.detect(_object.default), 'EmberObject is not an A class');
ok(A.detect(A), 'A is an A class');
ok(A.detect(B), 'B is an A class');
ok(A.detect(C), 'C is an A class');
ok(!B.detect(_object.default), 'EmberObject is not a B class');
ok(!B.detect(A), 'A is not a B class');
ok(B.detect(B), 'B is a B class');
ok(!B.detect(C), 'C is not a B class');
ok(!C.detect(_object.default), 'EmberObject is not a C class');
ok(!C.detect(A), 'A is not a C class');
ok(!C.detect(B), 'B is not a C class');
ok(C.detect(C), 'C is a C class');
});
});
enifed('ember-runtime/tests/system/object/es-compatibility-test', ['ember-babel', 'ember-runtime/system/object', 'ember-metal'], function (_emberBabel, _object, _emberMetal) {
'use strict';
QUnit.module('EmberObject ES Compatibility');
QUnit.test('extending an Ember.Object', function (assert) {
var calls = [];
var MyObject = function (_EmberObject) {
(0, _emberBabel.inherits)(MyObject, _EmberObject);
function MyObject() {
calls.push('constructor');
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject.apply(this, arguments));
_this.postInitProperty = 'post-init-property';
return _this;
}
MyObject.prototype.init = function () {
var _EmberObject$prototyp;
calls.push('init');
(_EmberObject$prototyp = _EmberObject.prototype.init).call.apply(_EmberObject$prototyp, [this].concat(Array.prototype.slice.call(arguments)));
this.initProperty = 'init-property';
};
return MyObject;
}(_object.default);
var myObject = MyObject.create({ passedProperty: 'passed-property' });
assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (create)');
assert.equal(myObject.postInitProperty, 'post-init-property', 'constructor property available on instance (create)');
assert.equal(myObject.initProperty, 'init-property', 'init property available on instance (create)');
assert.equal(myObject.passedProperty, 'passed-property', 'passed property available on instance (create)');
calls = [];
myObject = new MyObject({ passedProperty: 'passed-property' });
assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (new)');
assert.equal(myObject.postInitProperty, 'post-init-property', 'constructor property available on instance (new)');
assert.equal(myObject.initProperty, 'init-property', 'init property available on instance (new)');
assert.equal(myObject.passedProperty, 'passed-property', 'passed property available on instance (new)');
});
QUnit.test('using super', function (assert) {
var calls = [];
var SuperSuperObject = _object.default.extend({
method: function () {
calls.push('super-super-method');
}
});
var SuperObject = SuperSuperObject.extend({
method: function () {
this._super();
calls.push('super-method');
}
});
var MyObject = function (_SuperObject) {
(0, _emberBabel.inherits)(MyObject, _SuperObject);
function MyObject() {
return (0, _emberBabel.possibleConstructorReturn)(this, _SuperObject.apply(this, arguments));
}
MyObject.prototype.method = function () {
_SuperObject.prototype.method.call(this);
calls.push('method');
};
return MyObject;
}(SuperObject);
var myObject = new MyObject();
myObject.method();
assert.deepEqual(calls, ['super-super-method', 'super-method', 'method'], 'chain of prototype methods called with super');
});
QUnit.test('using mixins', function (assert) {
var Mixin1 = _emberMetal.Mixin.create({
property1: 'data-1'
});
var Mixin2 = _emberMetal.Mixin.create({
property2: 'data-2'
});
var MyObject = function (_EmberObject$extend) {
(0, _emberBabel.inherits)(MyObject, _EmberObject$extend);
function MyObject() {
return (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject$extend.apply(this, arguments));
}
return MyObject;
}(_object.default.extend(Mixin1, Mixin2));
var myObject = new MyObject();
assert.equal(myObject.property1, 'data-1', 'includes the first mixin');
assert.equal(myObject.property2, 'data-2', 'includes the second mixin');
});
QUnit.test('using instanceof', function (assert) {
var MyObject = function (_EmberObject2) {
(0, _emberBabel.inherits)(MyObject, _EmberObject2);
function MyObject() {
return (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject2.apply(this, arguments));
}
return MyObject;
}(_object.default);
var myObject1 = MyObject.create();
var myObject2 = new MyObject();
assert.ok(myObject1 instanceof MyObject);
assert.ok(myObject1 instanceof _object.default);
assert.ok(myObject2 instanceof MyObject);
assert.ok(myObject2 instanceof _object.default);
});
QUnit.test('extending an ES subclass of EmberObject', function (assert) {
var calls = [];
var SubEmberObject = function (_EmberObject3) {
(0, _emberBabel.inherits)(SubEmberObject, _EmberObject3);
function SubEmberObject() {
calls.push('constructor');
return (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject3.apply(this, arguments));
}
SubEmberObject.prototype.init = function () {
var _EmberObject3$prototy;
calls.push('init');
(_EmberObject3$prototy = _EmberObject3.prototype.init).call.apply(_EmberObject3$prototy, [this].concat(Array.prototype.slice.call(arguments)));
};
return SubEmberObject;
}(_object.default);
var MyObject = function (_SubEmberObject) {
(0, _emberBabel.inherits)(MyObject, _SubEmberObject);
function MyObject() {
return (0, _emberBabel.possibleConstructorReturn)(this, _SubEmberObject.apply(this, arguments));
}
return MyObject;
}(SubEmberObject);
MyObject.create();
assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (create)');
calls = [];
new MyObject();
assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (new)');
});
// TODO: Needs to be fixed. Currently only `init` is called.
QUnit.skip('calling extend on an ES subclass of EmberObject', function (assert) {
var calls = [];
var SubEmberObject = function (_EmberObject4) {
(0, _emberBabel.inherits)(SubEmberObject, _EmberObject4);
function SubEmberObject() {
calls.push('constructor');
return (0, _emberBabel.possibleConstructorReturn)(this, _EmberObject4.apply(this, arguments));
}
SubEmberObject.prototype.init = function () {
var _EmberObject4$prototy;
calls.push('init');
(_EmberObject4$prototy = _EmberObject4.prototype.init).call.apply(_EmberObject4$prototy, [this].concat(Array.prototype.slice.call(arguments)));
};
return SubEmberObject;
}(_object.default);
var MyObject = SubEmberObject.extend({});
MyObject.create();
assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (create)');
calls = [];
new MyObject();
assert.deepEqual(calls, ['constructor', 'init'], 'constructor then init called (new)');
});
});
enifed('ember-runtime/tests/system/object/events_test', ['ember-runtime/system/object', 'ember-runtime/mixins/evented'], function (_object, _evented) {
'use strict';
QUnit.module('Object events');
QUnit.test('a listener can be added to an object', function () {
var count = 0;
var obj = _object.default.extend(_evented.default).create();
obj.on('event!', function () {
count++;
});
obj.trigger('event!');
equal(count, 1, 'the event was triggered');
obj.trigger('event!');
equal(count, 2, 'the event was triggered');
});
QUnit.test('a listener can be added and removed automatically the first time it is triggered', function () {
var count = 0;
var obj = _object.default.extend(_evented.default).create();
obj.one('event!', function () {
count++;
});
obj.trigger('event!');
equal(count, 1, 'the event was triggered');
obj.trigger('event!');
equal(count, 1, 'the event was not triggered again');
});
QUnit.test('triggering an event can have arguments', function () {
var self = void 0,
args = void 0;
var obj = _object.default.extend(_evented.default).create();
obj.on('event!', function () {
args = [].slice.call(arguments);
self = this;
});
obj.trigger('event!', 'foo', 'bar');
deepEqual(args, ['foo', 'bar']);
equal(self, obj);
});
QUnit.test('a listener can be added and removed automatically and have arguments', function () {
var self = void 0,
args = void 0;
var count = 0;
var obj = _object.default.extend(_evented.default).create();
obj.one('event!', function () {
args = [].slice.call(arguments);
self = this;
count++;
});
obj.trigger('event!', 'foo', 'bar');
deepEqual(args, ['foo', 'bar']);
equal(self, obj);
equal(count, 1, 'the event is triggered once');
obj.trigger('event!', 'baz', 'bat');
deepEqual(args, ['foo', 'bar']);
equal(count, 1, 'the event was not triggered again');
equal(self, obj);
});
QUnit.test('binding an event can specify a different target', function () {
var self = void 0,
args = void 0;
var obj = _object.default.extend(_evented.default).create();
var target = {};
obj.on('event!', target, function () {
args = [].slice.call(arguments);
self = this;
});
obj.trigger('event!', 'foo', 'bar');
deepEqual(args, ['foo', 'bar']);
equal(self, target);
});
QUnit.test('a listener registered with one can take method as string and can be added with different target', function () {
var count = 0;
var target = {};
target.fn = function () {
count++;
};
var obj = _object.default.extend(_evented.default).create();
obj.one('event!', target, 'fn');
obj.trigger('event!');
equal(count, 1, 'the event was triggered');
obj.trigger('event!');
equal(count, 1, 'the event was not triggered again');
});
QUnit.test('a listener registered with one can be removed with off', function () {
var obj = _object.default.extend(_evented.default, {
F: function () {}
}).create();
var F = function () {};
obj.one('event!', F);
obj.one('event!', obj, 'F');
equal(obj.has('event!'), true, 'has events');
obj.off('event!', F);
obj.off('event!', obj, 'F');
equal(obj.has('event!'), false, 'has no more events');
});
QUnit.test('adding and removing listeners should be chainable', function () {
var obj = _object.default.extend(_evented.default).create();
var F = function () {};
var ret = obj.on('event!', F);
equal(ret, obj, '#on returns self');
ret = obj.off('event!', F);
equal(ret, obj, '#off returns self');
ret = obj.one('event!', F);
equal(ret, obj, '#one returns self');
});
});
enifed('ember-runtime/tests/system/object/extend_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) {
'use strict';
QUnit.module('EmberObject.extend');
QUnit.test('Basic extend', function () {
var SomeClass = _object.default.extend({ foo: 'BAR' });
ok(SomeClass.isClass, 'A class has isClass of true');
var obj = new SomeClass();
equal(obj.foo, 'BAR');
});
QUnit.test('Sub-subclass', function () {
var SomeClass = _object.default.extend({ foo: 'BAR' });
var AnotherClass = SomeClass.extend({ bar: 'FOO' });
var obj = new AnotherClass();
equal(obj.foo, 'BAR');
equal(obj.bar, 'FOO');
});
QUnit.test('Overriding a method several layers deep', function () {
var SomeClass = _object.default.extend({
fooCnt: 0,
foo: function () {
this.fooCnt++;
},
barCnt: 0,
bar: function () {
this.barCnt++;
}
});
var AnotherClass = SomeClass.extend({
barCnt: 0,
bar: function () {
this.barCnt++;
this._super.apply(this, arguments);
}
});
var FinalClass = AnotherClass.extend({
fooCnt: 0,
foo: function () {
this.fooCnt++;
this._super.apply(this, arguments);
}
});
var obj = new FinalClass();
obj.foo();
obj.bar();
equal(obj.fooCnt, 2, 'should invoke both');
equal(obj.barCnt, 2, 'should invoke both');
// Try overriding on create also
obj = FinalClass.extend({
foo: function () {
this.fooCnt++;
this._super.apply(this, arguments);
}
}).create();
obj.foo();
obj.bar();
equal(obj.fooCnt, 3, 'should invoke final as well');
equal(obj.barCnt, 2, 'should invoke both');
});
QUnit.test('With concatenatedProperties', function () {
var SomeClass = _object.default.extend({ things: 'foo', concatenatedProperties: ['things'] });
var AnotherClass = SomeClass.extend({ things: 'bar' });
var YetAnotherClass = SomeClass.extend({ things: 'baz' });
var some = new SomeClass();
var another = new AnotherClass();
var yetAnother = new YetAnotherClass();
deepEqual(some.get('things'), ['foo'], 'base class should have just its value');
deepEqual(another.get('things'), ['foo', 'bar'], 'subclass should have base class\' and its own');
deepEqual(yetAnother.get('things'), ['foo', 'baz'], 'subclass should have base class\' and its own');
});
QUnit.test('With concatenatedProperties class properties', function () {
var SomeClass = _object.default.extend();
SomeClass.reopenClass({
concatenatedProperties: ['things'],
things: 'foo'
});
var AnotherClass = SomeClass.extend();
AnotherClass.reopenClass({ things: 'bar' });
var YetAnotherClass = SomeClass.extend();
YetAnotherClass.reopenClass({ things: 'baz' });
var some = new SomeClass();
var another = new AnotherClass();
var yetAnother = new YetAnotherClass();
deepEqual((0, _emberMetal.get)(some.constructor, 'things'), ['foo'], 'base class should have just its value');
deepEqual((0, _emberMetal.get)(another.constructor, 'things'), ['foo', 'bar'], 'subclass should have base class\' and its own');
deepEqual((0, _emberMetal.get)(yetAnother.constructor, 'things'), ['foo', 'baz'], 'subclass should have base class\' and its own');
});
});
enifed('ember-runtime/tests/system/object/observer_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object'], function (_emberMetal, _internalTestHelpers, _object) {
'use strict';
QUnit.module('EmberObject observer');
(0, _internalTestHelpers.testBoth)('observer on class', function (get, set) {
var MyClass = _object.default.extend({
count: 0,
foo: (0, _emberMetal.observer)('bar', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj = new MyClass();
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj, 'bar', 'BAZ');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('observer on subclass', function (get, set) {
var MyClass = _object.default.extend({
count: 0,
foo: (0, _emberMetal.observer)('bar', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var Subclass = MyClass.extend({
foo: (0, _emberMetal.observer)('baz', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj = new Subclass();
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj, 'bar', 'BAZ');
equal(get(obj, 'count'), 0, 'should not invoke observer after change');
set(obj, 'baz', 'BAZ');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('observer on instance', function (get, set) {
var obj = _object.default.extend({
foo: (0, _emberMetal.observer)('bar', function () {
set(this, 'count', get(this, 'count') + 1);
})
}).create({
count: 0
});
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj, 'bar', 'BAZ');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('observer on instance overriding class', function (get, set) {
var MyClass = _object.default.extend({
count: 0,
foo: (0, _emberMetal.observer)('bar', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj = MyClass.extend({
foo: (0, _emberMetal.observer)('baz', function () {
// <-- change property we observe
set(this, 'count', get(this, 'count') + 1);
})
}).create();
equal(get(obj, 'count'), 0, 'should not invoke observer immediately');
set(obj, 'bar', 'BAZ');
equal(get(obj, 'count'), 0, 'should not invoke observer after change');
set(obj, 'baz', 'BAZ');
equal(get(obj, 'count'), 1, 'should invoke observer after change');
});
(0, _internalTestHelpers.testBoth)('observer should not fire after being destroyed', function (get, set) {
var obj = _object.default.extend({
count: 0,
foo: (0, _emberMetal.observer)('bar', function () {
set(this, 'count', get(this, 'count') + 1);
})
}).create();
equal(get(obj, 'count'), 0, 'precond - should not invoke observer immediately');
(0, _emberMetal.run)(function () {
return obj.destroy();
});
expectAssertion(function () {
set(obj, 'bar', 'BAZ');
}, 'calling set on destroyed object: ' + obj + '.bar = BAZ');
equal(get(obj, 'count'), 0, 'should not invoke observer after change');
});
// ..........................................................
// COMPLEX PROPERTIES
//
(0, _internalTestHelpers.testBoth)('chain observer on class', function (get, set) {
var MyClass = _object.default.extend({
count: 0,
foo: (0, _emberMetal.observer)('bar.baz', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj1 = MyClass.create({
bar: { baz: 'biff' }
});
var obj2 = MyClass.create({
bar: { baz: 'biff2' }
});
equal(get(obj1, 'count'), 0, 'should not invoke yet');
equal(get(obj2, 'count'), 0, 'should not invoke yet');
set(get(obj1, 'bar'), 'baz', 'BIFF1');
equal(get(obj1, 'count'), 1, 'should invoke observer on obj1');
equal(get(obj2, 'count'), 0, 'should not invoke yet');
set(get(obj2, 'bar'), 'baz', 'BIFF2');
equal(get(obj1, 'count'), 1, 'should not invoke again');
equal(get(obj2, 'count'), 1, 'should invoke observer on obj2');
});
(0, _internalTestHelpers.testBoth)('chain observer on class', function (get, set) {
var MyClass = _object.default.extend({
count: 0,
foo: (0, _emberMetal.observer)('bar.baz', function () {
set(this, 'count', get(this, 'count') + 1);
})
});
var obj1 = MyClass.extend().create({
bar: { baz: 'biff' }
});
var obj2 = MyClass.extend({
foo: (0, _emberMetal.observer)('bar2.baz', function () {
set(this, 'count', get(this, 'count') + 1);
})
}).create({
bar: { baz: 'biff2' },
bar2: { baz: 'biff3' }
});
equal(get(obj1, 'count'), 0, 'should not invoke yet');
equal(get(obj2, 'count'), 0, 'should not invoke yet');
set(get(obj1, 'bar'), 'baz', 'BIFF1');
equal(get(obj1, 'count'), 1, 'should invoke observer on obj1');
equal(get(obj2, 'count'), 0, 'should not invoke yet');
set(get(obj2, 'bar'), 'baz', 'BIFF2');
equal(get(obj1, 'count'), 1, 'should not invoke again');
equal(get(obj2, 'count'), 0, 'should not invoke yet');
set(get(obj2, 'bar2'), 'baz', 'BIFF3');
equal(get(obj1, 'count'), 1, 'should not invoke again');
equal(get(obj2, 'count'), 1, 'should invoke observer on obj2');
});
(0, _internalTestHelpers.testBoth)('chain observer on class that has a reference to an uninitialized object will finish chains that reference it', function () {
var changed = false;
var ChildClass = _object.default.extend({
parent: null,
parentOneTwoDidChange: (0, _emberMetal.observer)('parent.one.two', function () {
changed = true;
})
});
var ParentClass = _object.default.extend({
one: {
two: 'old'
},
init: function () {
this.child = ChildClass.create({
parent: this
});
}
});
var parent = new ParentClass();
equal(changed, false, 'precond');
parent.set('one.two', 'new');
equal(changed, true, 'child should have been notified of change to path');
parent.set('one', { two: 'newer' });
equal(changed, true, 'child should have been notified of change to path');
});
});
enifed('ember-runtime/tests/system/object/reopenClass_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) {
'use strict';
QUnit.module('system/object/reopenClass');
QUnit.test('adds new properties to subclass', function () {
var Subclass = _object.default.extend();
Subclass.reopenClass({
foo: function () {
return 'FOO';
},
bar: 'BAR'
});
equal(Subclass.foo(), 'FOO', 'Adds method');
equal((0, _emberMetal.get)(Subclass, 'bar'), 'BAR', 'Adds property');
});
QUnit.test('class properties inherited by subclasses', function () {
var Subclass = _object.default.extend();
Subclass.reopenClass({
foo: function () {
return 'FOO';
},
bar: 'BAR'
});
var SubSub = Subclass.extend();
equal(SubSub.foo(), 'FOO', 'Adds method');
equal((0, _emberMetal.get)(SubSub, 'bar'), 'BAR', 'Adds property');
});
});
enifed('ember-runtime/tests/system/object/reopen_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) {
'use strict';
QUnit.module('system/core_object/reopen');
QUnit.test('adds new properties to subclass instance', function () {
var Subclass = _object.default.extend();
Subclass.reopen({
foo: function () {
return 'FOO';
},
bar: 'BAR'
});
equal(new Subclass().foo(), 'FOO', 'Adds method');
equal((0, _emberMetal.get)(new Subclass(), 'bar'), 'BAR', 'Adds property');
});
QUnit.test('reopened properties inherited by subclasses', function () {
var Subclass = _object.default.extend();
var SubSub = Subclass.extend();
Subclass.reopen({
foo: function () {
return 'FOO';
},
bar: 'BAR'
});
equal(new SubSub().foo(), 'FOO', 'Adds method');
equal((0, _emberMetal.get)(new SubSub(), 'bar'), 'BAR', 'Adds property');
});
QUnit.test('allows reopening already instantiated classes', function () {
var Subclass = _object.default.extend();
Subclass.create();
Subclass.reopen({
trololol: true
});
equal(Subclass.create().get('trololol'), true, 'reopen works');
});
});
enifed('ember-runtime/tests/system/object/strict-mode-test', ['ember-runtime/system/object'], function (_object) {
'use strict';
QUnit.module('strict mode tests');
QUnit.test('__superWrapper does not throw errors in strict mode', function () {
var Foo = _object.default.extend({
blah: function () {
return 'foo';
}
});
var Bar = Foo.extend({
blah: function () {
return 'bar';
},
callBlah: function () {
var blah = this.blah;
return blah();
}
});
var bar = Bar.create();
equal(bar.callBlah(), 'bar', 'can call local function without call/apply');
});
});
enifed('ember-runtime/tests/system/object/subclasses_test', ['ember-metal', 'ember-runtime/system/object'], function (_emberMetal, _object) {
'use strict';
QUnit.module('system/object/subclasses');
QUnit.test('chains should copy forward to subclasses when prototype created', function () {
var ObjectWithChains = void 0,
objWithChains = void 0,
SubWithChains = void 0,
SubSub = void 0,
subSub = void 0;
(0, _emberMetal.run)(function () {
ObjectWithChains = _object.default.extend({
obj: {
a: 'a',
hi: 'hi'
},
aBinding: 'obj.a' // add chain
});
var deprecationMessage = /`Ember.Binding` is deprecated/;
expectDeprecation(function () {
// realize prototype
objWithChains = ObjectWithChains.create();
}, deprecationMessage);
// should not copy chains from parent yet
SubWithChains = ObjectWithChains.extend({
hiBinding: 'obj.hi', // add chain
hello: (0, _emberMetal.computed)(function () {
return this.get('obj.hi') + ' world';
}).property('hi'), // observe chain
greetingBinding: 'hello'
});
SubSub = SubWithChains.extend();
expectDeprecation(function () {
// should realize prototypes and copy forward chains
subSub = SubSub.create();
}, deprecationMessage);
});
equal(subSub.get('greeting'), 'hi world');
(0, _emberMetal.run)(function () {
return objWithChains.set('obj.hi', 'hello');
});
equal(subSub.get('greeting'), 'hello world');
});
});
enifed('ember-runtime/tests/system/object/toString_test', ['ember-utils', 'ember-environment', 'ember-runtime/system/object', 'ember-runtime/system/namespace'], function (_emberUtils, _emberEnvironment, _object, _namespace) {
'use strict';
var originalLookup = _emberEnvironment.context.lookup;
var lookup = void 0;
QUnit.module('system/object/toString', {
setup: function () {
_emberEnvironment.context.lookup = lookup = {};
},
teardown: function () {
_emberEnvironment.context.lookup = originalLookup;
}
});
QUnit.test('NAME_KEY slot is present on Class', function () {
ok(_object.default.extend().hasOwnProperty(_emberUtils.NAME_KEY), 'Ember Class\'s have a NAME_KEY slot');
});
QUnit.test('toString() returns the same value if called twice', function () {
var Foo = _namespace.default.create();
Foo.toString = function () {
return 'Foo';
};
Foo.Bar = _object.default.extend();
equal(Foo.Bar.toString(), 'Foo.Bar');
equal(Foo.Bar.toString(), 'Foo.Bar');
var obj = Foo.Bar.create();
equal(obj.toString(), '');
equal(obj.toString(), '');
equal(Foo.Bar.toString(), 'Foo.Bar');
});
QUnit.test('toString on a class returns a useful value when nested in a namespace', function () {
var obj = void 0;
var Foo = _namespace.default.create();
Foo.toString = function () {
return 'Foo';
};
Foo.Bar = _object.default.extend();
equal(Foo.Bar.toString(), 'Foo.Bar');
obj = Foo.Bar.create();
equal(obj.toString(), '');
Foo.Baz = Foo.Bar.extend();
equal(Foo.Baz.toString(), 'Foo.Baz');
obj = Foo.Baz.create();
equal(obj.toString(), '');
obj = Foo.Bar.create();
equal(obj.toString(), '');
});
QUnit.test('toString on a namespace finds the namespace in lookup', function () {
var Foo = lookup.Foo = _namespace.default.create();
equal(Foo.toString(), 'Foo');
});
QUnit.test('toString on a namespace finds the namespace in lookup', function () {
var Foo = lookup.Foo = _namespace.default.create();
var obj = void 0;
Foo.Bar = _object.default.extend();
equal(Foo.Bar.toString(), 'Foo.Bar');
obj = Foo.Bar.create();
equal(obj.toString(), '');
});
QUnit.test('toString on a namespace falls back to modulePrefix, if defined', function () {
var Foo = _namespace.default.create({ modulePrefix: 'foo' });
equal(Foo.toString(), 'foo');
});
QUnit.test('toString includes toStringExtension if defined', function () {
var Foo = _object.default.extend({
toStringExtension: function () {
return 'fooey';
}
});
var foo = Foo.create();
var Bar = _object.default.extend({});
var bar = Bar.create();
// simulate these classes being defined on a Namespace
Foo[_emberUtils.NAME_KEY] = 'Foo';
Bar[_emberUtils.NAME_KEY] = 'Bar';
equal(bar.toString(), '', 'does not include toStringExtension part');
equal(foo.toString(), '', 'Includes toStringExtension result');
});
});
enifed('ember-runtime/tests/system/object_proxy_test', ['ember-metal', 'internal-test-helpers', 'ember-runtime/system/object_proxy'], function (_emberMetal, _internalTestHelpers, _object_proxy) {
'use strict';
QUnit.module('ObjectProxy');
(0, _internalTestHelpers.testBoth)('should not proxy properties passed to create', function (get) {
var Proxy = _object_proxy.default.extend({
cp: (0, _emberMetal.computed)({
get: function () {
return this._cp;
},
set: function (key, value) {
this._cp = value;
return this._cp;
}
})
});
var proxy = Proxy.create({
prop: 'Foo',
cp: 'Bar'
});
equal(get(proxy, 'prop'), 'Foo', 'should not have tried to proxy set');
equal(proxy._cp, 'Bar', 'should use CP setter');
});
(0, _internalTestHelpers.testBoth)('should proxy properties to content', function (get, set) {
var content = {
firstName: 'Tom',
lastName: 'Dale',
unknownProperty: function (key) {
return key + ' unknown';
}
};
var proxy = _object_proxy.default.create();
equal(get(proxy, 'firstName'), undefined, 'get on proxy without content should return undefined');
expectAssertion(function () {
set(proxy, 'firstName', 'Foo');
}, /Cannot delegate set\('firstName', Foo\) to the 'content'/i);
set(proxy, 'content', content);
equal(get(proxy, 'firstName'), 'Tom', 'get on proxy with content should forward to content');
equal(get(proxy, 'lastName'), 'Dale', 'get on proxy with content should forward to content');
equal(get(proxy, 'foo'), 'foo unknown', 'get on proxy with content should forward to content');
set(proxy, 'lastName', 'Huda');
equal(get(content, 'lastName'), 'Huda', 'content should have new value from set on proxy');
equal(get(proxy, 'lastName'), 'Huda', 'proxy should have new value from set on proxy');
set(proxy, 'content', { firstName: 'Yehuda', lastName: 'Katz' });
equal(get(proxy, 'firstName'), 'Yehuda', 'proxy should reflect updated content');
equal(get(proxy, 'lastName'), 'Katz', 'proxy should reflect updated content');
});
(0, _internalTestHelpers.testBoth)('should work with watched properties', function (get, set) {
var content1 = { firstName: 'Tom', lastName: 'Dale' };
var content2 = { firstName: 'Yehuda', lastName: 'Katz' };
var count = 0;
var last = void 0;
var Proxy = _object_proxy.default.extend({
fullName: (0, _emberMetal.computed)(function () {
var firstName = this.get('firstName');
var lastName = this.get('lastName');
if (firstName && lastName) {
return firstName + ' ' + lastName;
}
return firstName || lastName;
}).property('firstName', 'lastName')
});
var proxy = Proxy.create();
(0, _emberMetal.addObserver)(proxy, 'fullName', function () {
last = get(proxy, 'fullName');
count++;
});
// proxy without content returns undefined
equal(get(proxy, 'fullName'), undefined);
// setting content causes all watched properties to change
set(proxy, 'content', content1);
// both dependent keys changed
equal(count, 2);
equal(last, 'Tom Dale');
// setting property in content causes proxy property to change
set(content1, 'lastName', 'Huda');
equal(count, 3);
equal(last, 'Tom Huda');
// replacing content causes all watched properties to change
set(proxy, 'content', content2);
// both dependent keys changed
equal(count, 5);
equal(last, 'Yehuda Katz');
// content1 is no longer watched
ok(!(0, _emberMetal.isWatching)(content1, 'firstName'), 'not watching firstName');
ok(!(0, _emberMetal.isWatching)(content1, 'lastName'), 'not watching lastName');
// setting property in new content
set(content2, 'firstName', 'Tomhuda');
equal(last, 'Tomhuda Katz');
equal(count, 6);
// setting property in proxy syncs with new content
set(proxy, 'lastName', 'Katzdale');
equal(count, 7);
equal(last, 'Tomhuda Katzdale');
equal(get(content2, 'firstName'), 'Tomhuda');
equal(get(content2, 'lastName'), 'Katzdale');
});
QUnit.test('set and get should work with paths', function () {
var proxy = _object_proxy.default.create({ content: { foo: { bar: 'baz' } } });
var count = 0;
proxy.set('foo.bar', 'hello');
equal(proxy.get('foo.bar'), 'hello');
equal(proxy.get('content.foo.bar'), 'hello');
proxy.addObserver('foo.bar', function () {
count++;
});
proxy.set('foo.bar', 'bye');
equal(count, 1);
equal(proxy.get('foo.bar'), 'bye');
equal(proxy.get('content.foo.bar'), 'bye');
});
(0, _internalTestHelpers.testBoth)('should transition between watched and unwatched strategies', function (get, set) {
var content = { foo: 'foo' };
var proxy = _object_proxy.default.create({ content: content });
var count = 0;
function observer() {
count++;
}
equal(get(proxy, 'foo'), 'foo');
set(content, 'foo', 'bar');
equal(get(proxy, 'foo'), 'bar');
set(proxy, 'foo', 'foo');
equal(get(content, 'foo'), 'foo');
equal(get(proxy, 'foo'), 'foo');
(0, _emberMetal.addObserver)(proxy, 'foo', observer);
equal(count, 0);
equal(get(proxy, 'foo'), 'foo');
set(content, 'foo', 'bar');
equal(count, 1);
equal(get(proxy, 'foo'), 'bar');
set(proxy, 'foo', 'foo');
equal(count, 2);
equal(get(content, 'foo'), 'foo');
equal(get(proxy, 'foo'), 'foo');
(0, _emberMetal.removeObserver)(proxy, 'foo', observer);
set(content, 'foo', 'bar');
equal(get(proxy, 'foo'), 'bar');
set(proxy, 'foo', 'foo');
equal(get(content, 'foo'), 'foo');
equal(get(proxy, 'foo'), 'foo');
});
(0, _internalTestHelpers.testBoth)('setting `undefined` to a proxied content property should override its existing value', function (get, set) {
var proxyObject = _object_proxy.default.create({
content: {
prop: 'emberjs'
}
});
set(proxyObject, 'prop', undefined);
equal(get(proxyObject, 'prop'), undefined, 'sets the `undefined` value to the proxied content');
});
});
enifed('ember-runtime/tests/system/string/camelize_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) {
'use strict';
QUnit.module('EmberStringUtils.camelize');
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
QUnit.test('String.prototype.camelize is not modified without EXTEND_PROTOTYPES', function () {
ok('undefined' === typeof String.prototype.camelize, 'String.prototype helper disabled');
});
}
QUnit.test('camelize normal string', function () {
deepEqual((0, _string.camelize)('my favorite items'), 'myFavoriteItems');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('my favorite items'.camelize(), 'myFavoriteItems');
}
});
QUnit.test('camelize capitalized string', function () {
deepEqual((0, _string.camelize)('I Love Ramen'), 'iLoveRamen');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('I Love Ramen'.camelize(), 'iLoveRamen');
}
});
QUnit.test('camelize dasherized string', function () {
deepEqual((0, _string.camelize)('css-class-name'), 'cssClassName');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('css-class-name'.camelize(), 'cssClassName');
}
});
QUnit.test('camelize underscored string', function () {
deepEqual((0, _string.camelize)('action_name'), 'actionName');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('action_name'.camelize(), 'actionName');
}
});
QUnit.test('camelize dot notation string', function () {
deepEqual((0, _string.camelize)('action.name'), 'actionName');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('action.name'.camelize(), 'actionName');
}
});
QUnit.test('does nothing with camelcased string', function () {
deepEqual((0, _string.camelize)('innerHTML'), 'innerHTML');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('innerHTML'.camelize(), 'innerHTML');
}
});
QUnit.test('camelize namespaced classified string', function () {
deepEqual((0, _string.camelize)('PrivateDocs/OwnerInvoice'), 'privateDocs/ownerInvoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('PrivateDocs/OwnerInvoice'.camelize(), 'privateDocs/ownerInvoice');
}
});
QUnit.test('camelize namespaced underscored string', function () {
deepEqual((0, _string.camelize)('private_docs/owner_invoice'), 'privateDocs/ownerInvoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('private_docs/owner_invoice'.camelize(), 'privateDocs/ownerInvoice');
}
});
QUnit.test('camelize namespaced dasherized string', function () {
deepEqual((0, _string.camelize)('private-docs/owner-invoice'), 'privateDocs/ownerInvoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('private-docs/owner-invoice'.camelize(), 'privateDocs/ownerInvoice');
}
});
});
enifed('ember-runtime/tests/system/string/capitalize_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) {
'use strict';
QUnit.module('EmberStringUtils.capitalize');
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
QUnit.test('String.prototype.capitalize is not modified without EXTEND_PROTOTYPES', function () {
ok('undefined' === typeof String.prototype.capitalize, 'String.prototype helper disabled');
});
}
QUnit.test('capitalize normal string', function () {
deepEqual((0, _string.capitalize)('my favorite items'), 'My favorite items');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('my favorite items'.capitalize(), 'My favorite items');
}
});
QUnit.test('capitalize dasherized string', function () {
deepEqual((0, _string.capitalize)('css-class-name'), 'Css-class-name');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('css-class-name'.capitalize(), 'Css-class-name');
}
});
QUnit.test('capitalize underscored string', function () {
deepEqual((0, _string.capitalize)('action_name'), 'Action_name');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('action_name'.capitalize(), 'Action_name');
}
});
QUnit.test('capitalize camelcased string', function () {
deepEqual((0, _string.capitalize)('innerHTML'), 'InnerHTML');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('innerHTML'.capitalize(), 'InnerHTML');
}
});
QUnit.test('does nothing with capitalized string', function () {
deepEqual((0, _string.capitalize)('Capitalized string'), 'Capitalized string');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('Capitalized string'.capitalize(), 'Capitalized string');
}
});
QUnit.test('capitalize namespaced camelized string', function () {
deepEqual((0, _string.capitalize)('privateDocs/ownerInvoice'), 'PrivateDocs/OwnerInvoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('privateDocs/ownerInvoice'.capitalize(), 'PrivateDocs/OwnerInvoice');
}
});
QUnit.test('capitalize namespaced underscored string', function () {
deepEqual((0, _string.capitalize)('private_docs/owner_invoice'), 'Private_docs/Owner_invoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('private_docs/owner_invoice'.capitalize(), 'Private_docs/Owner_invoice');
}
});
QUnit.test('capitalize namespaced dasherized string', function () {
deepEqual((0, _string.capitalize)('private-docs/owner-invoice'), 'Private-docs/Owner-invoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('private-docs/owner-invoice'.capitalize(), 'Private-docs/Owner-invoice');
}
});
});
enifed('ember-runtime/tests/system/string/classify_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) {
'use strict';
QUnit.module('EmberStringUtils.classify');
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
QUnit.test('String.prototype.classify is not modified without EXTEND_PROTOTYPES', function () {
ok('undefined' === typeof String.prototype.classify, 'String.prototype helper disabled');
});
}
function test(given, expected, description) {
QUnit.test(description, function () {
deepEqual((0, _string.classify)(given), expected);
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual(given.classify(), expected);
}
});
}
test('my favorite items', 'MyFavoriteItems', 'classify normal string');
test('css-class-name', 'CssClassName', 'classify dasherized string');
test('action_name', 'ActionName', 'classify underscored string');
test('privateDocs/ownerInvoice', 'PrivateDocs/OwnerInvoice', 'classify namespaced camelized string');
test('private_docs/owner_invoice', 'PrivateDocs/OwnerInvoice', 'classify namespaced underscored string');
test('private-docs/owner-invoice', 'PrivateDocs/OwnerInvoice', 'classify namespaced dasherized string');
test('-view-registry', '_ViewRegistry', 'classify prefixed dasherized string');
test('components/-text-field', 'Components/_TextField', 'classify namespaced prefixed dasherized string');
test('_Foo_Bar', '_FooBar', 'classify underscore-prefixed underscored string');
test('_Foo-Bar', '_FooBar', 'classify underscore-prefixed dasherized string');
test('_foo/_bar', '_Foo/_Bar', 'classify underscore-prefixed-namespaced underscore-prefixed string');
test('-foo/_bar', '_Foo/_Bar', 'classify dash-prefixed-namespaced underscore-prefixed string');
test('-foo/-bar', '_Foo/_Bar', 'classify dash-prefixed-namespaced dash-prefixed string');
test('InnerHTML', 'InnerHTML', 'does nothing with classified string');
test('_FooBar', '_FooBar', 'does nothing with classified prefixed string');
});
enifed('ember-runtime/tests/system/string/dasherize_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) {
'use strict';
QUnit.module('EmberStringUtils.dasherize');
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
QUnit.test('String.prototype.dasherize is not modified without EXTEND_PROTOTYPES', function () {
ok('undefined' === typeof String.prototype.dasherize, 'String.prototype helper disabled');
});
}
QUnit.test('dasherize normal string', function () {
deepEqual((0, _string.dasherize)('my favorite items'), 'my-favorite-items');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('my favorite items'.dasherize(), 'my-favorite-items');
}
});
QUnit.test('does nothing with dasherized string', function () {
deepEqual((0, _string.dasherize)('css-class-name'), 'css-class-name');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('css-class-name'.dasherize(), 'css-class-name');
}
});
QUnit.test('dasherize underscored string', function () {
deepEqual((0, _string.dasherize)('action_name'), 'action-name');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('action_name'.dasherize(), 'action-name');
}
});
QUnit.test('dasherize camelcased string', function () {
deepEqual((0, _string.dasherize)('innerHTML'), 'inner-html');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('innerHTML'.dasherize(), 'inner-html');
}
});
QUnit.test('dasherize string that is the property name of Object.prototype', function () {
deepEqual((0, _string.dasherize)('toString'), 'to-string');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('toString'.dasherize(), 'to-string');
}
});
QUnit.test('dasherize namespaced classified string', function () {
deepEqual((0, _string.dasherize)('PrivateDocs/OwnerInvoice'), 'private-docs/owner-invoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('PrivateDocs/OwnerInvoice'.dasherize(), 'private-docs/owner-invoice');
}
});
QUnit.test('dasherize namespaced camelized string', function () {
deepEqual((0, _string.dasherize)('privateDocs/ownerInvoice'), 'private-docs/owner-invoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('privateDocs/ownerInvoice'.dasherize(), 'private-docs/owner-invoice');
}
});
QUnit.test('dasherize namespaced underscored string', function () {
deepEqual((0, _string.dasherize)('private_docs/owner_invoice'), 'private-docs/owner-invoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('private_docs/owner_invoice'.dasherize(), 'private-docs/owner-invoice');
}
});
});
enifed('ember-runtime/tests/system/string/decamelize_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) {
'use strict';
QUnit.module('EmberStringUtils.decamelize');
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
QUnit.test('String.prototype.decamelize is not modified without EXTEND_PROTOTYPES', function () {
ok('undefined' === typeof String.prototype.decamelize, 'String.prototype helper disabled');
});
}
QUnit.test('does nothing with normal string', function () {
deepEqual((0, _string.decamelize)('my favorite items'), 'my favorite items');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('my favorite items'.decamelize(), 'my favorite items');
}
});
QUnit.test('does nothing with dasherized string', function () {
deepEqual((0, _string.decamelize)('css-class-name'), 'css-class-name');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('css-class-name'.decamelize(), 'css-class-name');
}
});
QUnit.test('does nothing with underscored string', function () {
deepEqual((0, _string.decamelize)('action_name'), 'action_name');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('action_name'.decamelize(), 'action_name');
}
});
QUnit.test('converts a camelized string into all lower case separated by underscores.', function () {
deepEqual((0, _string.decamelize)('innerHTML'), 'inner_html');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('innerHTML'.decamelize(), 'inner_html');
}
});
QUnit.test('decamelizes strings with numbers', function () {
deepEqual((0, _string.decamelize)('size160Url'), 'size160_url');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('size160Url'.decamelize(), 'size160_url');
}
});
QUnit.test('decamelize namespaced classified string', function () {
deepEqual((0, _string.decamelize)('PrivateDocs/OwnerInvoice'), 'private_docs/owner_invoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('PrivateDocs/OwnerInvoice'.decamelize(), 'private_docs/owner_invoice');
}
});
QUnit.test('decamelize namespaced camelized string', function () {
deepEqual((0, _string.decamelize)('privateDocs/ownerInvoice'), 'private_docs/owner_invoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('privateDocs/ownerInvoice'.decamelize(), 'private_docs/owner_invoice');
}
});
});
enifed('ember-runtime/tests/system/string/fmt_string_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) {
'use strict';
QUnit.module('EmberStringUtils.fmt');
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
QUnit.test('String.prototype.fmt is not modified without EXTEND_PROTOTYPES', function () {
ok('undefined' === typeof String.prototype.fmt, 'String.prototype helper disabled');
});
}
QUnit.test('\'Hello %@ %@\'.fmt(\'John\', \'Doe\') => \'Hello John Doe\'', function () {
expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.');
equal((0, _string.fmt)('Hello %@ %@', ['John', 'Doe']), 'Hello John Doe');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
equal('Hello %@ %@'.fmt('John', 'Doe'), 'Hello John Doe');
}
});
QUnit.test('\'Hello %@2 %@1\'.fmt(\'John\', \'Doe\') => \'Hello Doe John\'', function () {
expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.');
equal((0, _string.fmt)('Hello %@2 %@1', ['John', 'Doe']), 'Hello Doe John');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
equal('Hello %@2 %@1'.fmt('John', 'Doe'), 'Hello Doe John');
}
});
QUnit.test('\'%@08 %@07 %@06 %@05 %@04 %@03 %@02 %@01\'.fmt(\'One\', \'Two\', \'Three\', \'Four\', \'Five\', \'Six\', \'Seven\', \'Eight\') => \'Eight Seven Six Five Four Three Two One\'', function () {
expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.');
equal((0, _string.fmt)('%@08 %@07 %@06 %@05 %@04 %@03 %@02 %@01', ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight']), 'Eight Seven Six Five Four Three Two One');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
equal('%@08 %@07 %@06 %@05 %@04 %@03 %@02 %@01'.fmt('One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight'), 'Eight Seven Six Five Four Three Two One');
}
});
QUnit.test('\'data: %@\'.fmt({ id: 3 }) => \'data: {id: 3}\'', function () {
expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.');
equal((0, _string.fmt)('data: %@', [{ id: 3 }]), 'data: {id: 3}');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
equal('data: %@'.fmt({ id: 3 }), 'data: {id: 3}');
}
});
QUnit.test('works with argument form', function () {
expectDeprecation('Ember.String.fmt is deprecated, use ES6 template strings instead.');
equal((0, _string.fmt)('%@', 'John'), 'John');
equal((0, _string.fmt)('%@ %@', ['John'], 'Doe'), '[John] Doe');
});
});
enifed('ember-runtime/tests/system/string/loc_test', ['ember-metal', 'ember-environment', 'ember-runtime/system/string'], function (_emberMetal, _emberEnvironment, _string) {
'use strict';
// ES6TODO Ember.STRINGS
var oldString = void 0;
QUnit.module('EmberStringUtils.loc', {
setup: function () {
oldString = _emberMetal.default.STRINGS;
_emberMetal.default.STRINGS = {
'_Hello World': 'Bonjour le monde',
'_Hello %@': 'Bonjour %@',
'_Hello %@ %@': 'Bonjour %@ %@',
'_Hello %@# %@#': 'Bonjour %@2 %@1'
};
},
teardown: function () {
_emberMetal.default.STRINGS = oldString;
}
});
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
QUnit.test('String.prototype.loc is not available without EXTEND_PROTOTYPES', function () {
ok('undefined' === typeof String.prototype.loc, 'String.prototype helper disabled');
});
}
QUnit.test('\'_Hello World\'.loc() => \'Bonjour le monde\'', function () {
equal((0, _string.loc)('_Hello World'), 'Bonjour le monde');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
equal('_Hello World'.loc(), 'Bonjour le monde');
}
});
QUnit.test('\'_Hello %@ %@\'.loc(\'John\', \'Doe\') => \'Bonjour John Doe\'', function () {
equal((0, _string.loc)('_Hello %@ %@', ['John', 'Doe']), 'Bonjour John Doe');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
equal('_Hello %@ %@'.loc('John', 'Doe'), 'Bonjour John Doe');
}
});
QUnit.test('\'_Hello %@# %@#\'.loc(\'John\', \'Doe\') => \'Bonjour Doe John\'', function () {
equal((0, _string.loc)('_Hello %@# %@#', ['John', 'Doe']), 'Bonjour Doe John');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
equal('_Hello %@# %@#'.loc('John', 'Doe'), 'Bonjour Doe John');
}
});
QUnit.test('\'_Not In Strings\'.loc() => \'_Not In Strings\'', function () {
equal((0, _string.loc)('_Not In Strings'), '_Not In Strings');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
equal('_Not In Strings'.loc(), '_Not In Strings');
}
});
QUnit.test('works with argument form', function () {
equal((0, _string.loc)('_Hello %@', 'John'), 'Bonjour John');
equal((0, _string.loc)('_Hello %@ %@', ['John'], 'Doe'), 'Bonjour [John] Doe');
});
});
enifed('ember-runtime/tests/system/string/underscore_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) {
'use strict';
QUnit.module('EmberStringUtils.underscore');
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
QUnit.test('String.prototype.underscore is not available without EXTEND_PROTOTYPES', function () {
ok('undefined' === typeof String.prototype.underscore, 'String.prototype helper disabled');
});
}
QUnit.test('with normal string', function () {
deepEqual((0, _string.underscore)('my favorite items'), 'my_favorite_items');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('my favorite items'.underscore(), 'my_favorite_items');
}
});
QUnit.test('with dasherized string', function () {
deepEqual((0, _string.underscore)('css-class-name'), 'css_class_name');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('css-class-name'.underscore(), 'css_class_name');
}
});
QUnit.test('does nothing with underscored string', function () {
deepEqual((0, _string.underscore)('action_name'), 'action_name');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('action_name'.underscore(), 'action_name');
}
});
QUnit.test('with camelcased string', function () {
deepEqual((0, _string.underscore)('innerHTML'), 'inner_html');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('innerHTML'.underscore(), 'inner_html');
}
});
QUnit.test('underscore namespaced classified string', function () {
deepEqual((0, _string.underscore)('PrivateDocs/OwnerInvoice'), 'private_docs/owner_invoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('PrivateDocs/OwnerInvoice'.underscore(), 'private_docs/owner_invoice');
}
});
QUnit.test('underscore namespaced camelized string', function () {
deepEqual((0, _string.underscore)('privateDocs/ownerInvoice'), 'private_docs/owner_invoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('privateDocs/ownerInvoice'.underscore(), 'private_docs/owner_invoice');
}
});
QUnit.test('underscore namespaced dasherized string', function () {
deepEqual((0, _string.underscore)('private-docs/owner-invoice'), 'private_docs/owner_invoice');
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('private-docs/owner-invoice'.underscore(), 'private_docs/owner_invoice');
}
});
});
enifed('ember-runtime/tests/system/string/w_test', ['ember-environment', 'ember-runtime/system/string'], function (_emberEnvironment, _string) {
'use strict';
QUnit.module('EmberStringUtils.w');
if (!_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
QUnit.test('String.prototype.w is not available without EXTEND_PROTOTYPES', function () {
ok('undefined' === typeof String.prototype.w, 'String.prototype helper disabled');
});
}
QUnit.test('\'one two three\'.w() => [\'one\',\'two\',\'three\']', function () {
deepEqual((0, _string.w)('one two three'), ['one', 'two', 'three']);
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('one two three'.w(), ['one', 'two', 'three']);
}
});
QUnit.test('\'one two three\'.w() with extra spaces between words => [\'one\',\'two\',\'three\']', function () {
deepEqual((0, _string.w)('one two three'), ['one', 'two', 'three']);
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('one two three'.w(), ['one', 'two', 'three']);
}
});
QUnit.test('\'one two three\'.w() with tabs', function () {
deepEqual((0, _string.w)('one\ttwo three'), ['one', 'two', 'three']);
if (_emberEnvironment.ENV.EXTEND_PROTOTYPES.String) {
deepEqual('one\ttwo three'.w(), ['one', 'two', 'three']);
}
});
});
enifed('ember-template-compiler/compat', ['ember-metal', 'ember-template-compiler/system/precompile', 'ember-template-compiler/system/compile', 'ember-template-compiler/system/compile-options'], function (_emberMetal, _precompile, _compile, _compileOptions) {
'use strict';
var EmberHandlebars = _emberMetal.default.Handlebars = _emberMetal.default.Handlebars || {}; // reexports
var EmberHTMLBars = _emberMetal.default.HTMLBars = _emberMetal.default.HTMLBars || {};
EmberHTMLBars.precompile = EmberHandlebars.precompile = _precompile.default;
EmberHTMLBars.compile = EmberHandlebars.compile = _compile.default;
EmberHTMLBars.registerPlugin = _compileOptions.registerPlugin;
});
enifed('ember-template-compiler/index', ['exports', 'ember-template-compiler/system/precompile', 'ember-template-compiler/system/compile', 'ember-template-compiler/system/compile-options', 'ember-template-compiler/plugins', 'ember-metal', 'ember/features', 'ember-environment', 'ember/version', 'ember-template-compiler/compat', 'ember-template-compiler/system/bootstrap'], function (exports, _precompile, _compile, _compileOptions, _plugins, _emberMetal, _features, _emberEnvironment, _version) {
'use strict';
exports.defaultPlugins = exports.registerPlugin = exports.compileOptions = exports.compile = exports.precompile = exports._Ember = undefined;
Object.defineProperty(exports, 'precompile', {
enumerable: true,
get: function () {
return _precompile.default;
}
});
Object.defineProperty(exports, 'compile', {
enumerable: true,
get: function () {
return _compile.default;
}
});
Object.defineProperty(exports, 'compileOptions', {
enumerable: true,
get: function () {
return _compileOptions.default;
}
});
Object.defineProperty(exports, 'registerPlugin', {
enumerable: true,
get: function () {
return _compileOptions.registerPlugin;
}
});
Object.defineProperty(exports, 'defaultPlugins', {
enumerable: true,
get: function () {
return _plugins.default;
}
});
// private API used by ember-cli-htmlbars to setup ENV and FEATURES
if (!_emberMetal.default.ENV) {
_emberMetal.default.ENV = _emberEnvironment.ENV;
}
if (!_emberMetal.default.FEATURES) {
_emberMetal.default.FEATURES = _features.FEATURES;
}
if (!_emberMetal.default.VERSION) {
_emberMetal.default.VERSION = _version.default;
}
exports._Ember = _emberMetal.default;
});
enifed('ember-template-compiler/plugins/assert-reserved-named-arguments', ['exports', 'ember-debug', 'ember-template-compiler/system/calculate-location-display'], function (exports, _emberDebug, _calculateLocationDisplay) {
'use strict';
exports.default = AssertReservedNamedArguments;
function AssertReservedNamedArguments(options) {
this.syntax = null;
this.options = options;
}
AssertReservedNamedArguments.prototype.transform = function AssertReservedNamedArguments_transform(ast) {
var moduleName = this.options.meta.moduleName;
this.syntax.traverse(ast, {
PathExpression: function (node) {
if (node.original[0] === '@') {
(true && (0, _emberDebug.assert)(assertMessage(moduleName, node)));
}
}
});
return ast;
};
function assertMessage(moduleName, node) {
var path = node.original;
var source = (0, _calculateLocationDisplay.default)(moduleName, node.loc);
return '\'' + path + '\' is not a valid path. ' + source;
}
});
enifed('ember-template-compiler/plugins/deprecate-render-model', ['exports', 'ember-debug', 'ember-template-compiler/system/calculate-location-display'], function (exports, _emberDebug, _calculateLocationDisplay) {
'use strict';
exports.default = DeprecateRenderModel;
function DeprecateRenderModel(options) {
this.syntax = null;
this.options = options;
}
DeprecateRenderModel.prototype.transform = function DeprecateRenderModel_transform(ast) {
var moduleName = this.options.meta.moduleName;
var walker = new this.syntax.Walker();
walker.visit(ast, function (node) {
if (!validate(node)) {
return;
}
each(node.params, function (param) {
if (param.type !== 'PathExpression') {
return;
}
(true && !(false) && (0, _emberDebug.deprecate)(deprecationMessage(moduleName, node, param), false, {
id: 'ember-template-compiler.deprecate-render-model',
until: '3.0.0',
url: 'http://emberjs.com/deprecations/v2.x#toc_model-param-in-code-render-code-helper'
}));
});
});
return ast;
};
function validate(node) {
return node.type === 'MustacheStatement' && node.path.original === 'render' && node.params.length > 1;
}
function each(list, callback) {
for (var i = 0, l = list.length; i < l; i++) {
callback(list[i]);
}
}
function deprecationMessage(moduleName, node, param) {
var sourceInformation = (0, _calculateLocationDisplay.default)(moduleName, node.loc);
var componentName = node.params[0].original;
var modelName = param.original;
var original = '{{render "' + componentName + '" ' + modelName + '}}';
var preferred = '{{' + componentName + ' model=' + modelName + '}}';
return 'Please refactor `' + original + '` to a component and invoke via' + (' `' + preferred + '`. ' + sourceInformation);
}
});
enifed('ember-template-compiler/plugins/deprecate-render', ['exports', 'ember-debug', 'ember-template-compiler/system/calculate-location-display'], function (exports, _emberDebug, _calculateLocationDisplay) {
'use strict';
exports.default = DeprecateRender;
function DeprecateRender(options) {
this.syntax = null;
this.options = options;
}
DeprecateRender.prototype.transform = function DeprecateRender_transform(ast) {
var moduleName = this.options.meta.moduleName;
var walker = new this.syntax.Walker();
walker.visit(ast, function (node) {
if (!validate(node)) {
return;
}
each(node.params, function (param) {
if (param.type !== 'StringLiteral') {
return;
}
(true && !(false) && (0, _emberDebug.deprecate)(deprecationMessage(moduleName, node), false, {
id: 'ember-template-compiler.deprecate-render',
until: '3.0.0',
url: 'http://emberjs.com/deprecations/v2.x#toc_code-render-code-helper'
}));
});
});
return ast;
};
function validate(node) {
return node.type === 'MustacheStatement' && node.path.original === 'render' && node.params.length === 1;
}
function each(list, callback) {
for (var i = 0, l = list.length; i < l; i++) {
callback(list[i]);
}
}
function deprecationMessage(moduleName, node) {
var sourceInformation = (0, _calculateLocationDisplay.default)(moduleName, node.loc);
var componentName = node.params[0].original;
var original = '{{render "' + componentName + '"}}';
var preferred = '{{' + componentName + '}}';
return 'Please refactor `' + original + '` to a component and invoke via' + (' `' + preferred + '`. ' + sourceInformation);
}
});
enifed('ember-template-compiler/plugins/index', ['exports', 'ember-template-compiler/plugins/transform-old-binding-syntax', 'ember-template-compiler/plugins/transform-item-class', 'ember-template-compiler/plugins/transform-angle-bracket-components', 'ember-template-compiler/plugins/transform-input-on-to-onEvent', 'ember-template-compiler/plugins/transform-top-level-components', 'ember-template-compiler/plugins/transform-inline-link-to', 'ember-template-compiler/plugins/transform-old-class-binding-syntax', 'ember-template-compiler/plugins/transform-quoted-bindings-into-just-bindings', 'ember-template-compiler/plugins/deprecate-render-model', 'ember-template-compiler/plugins/deprecate-render', 'ember-template-compiler/plugins/assert-reserved-named-arguments', 'ember-template-compiler/plugins/transform-action-syntax', 'ember-template-compiler/plugins/transform-input-type-syntax', 'ember-template-compiler/plugins/transform-attrs-into-args', 'ember-template-compiler/plugins/transform-each-in-into-each', 'ember-template-compiler/plugins/transform-has-block-syntax', 'ember-template-compiler/plugins/transform-dot-component-invocation'], function (exports, _transformOldBindingSyntax, _transformItemClass, _transformAngleBracketComponents, _transformInputOnToOnEvent, _transformTopLevelComponents, _transformInlineLinkTo, _transformOldClassBindingSyntax, _transformQuotedBindingsIntoJustBindings, _deprecateRenderModel, _deprecateRender, _assertReservedNamedArguments, _transformActionSyntax, _transformInputTypeSyntax, _transformAttrsIntoArgs, _transformEachInIntoEach, _transformHasBlockSyntax, _transformDotComponentInvocation) {
'use strict';
exports.default = Object.freeze([_transformDotComponentInvocation.default, _transformOldBindingSyntax.default, _transformItemClass.default, _transformAngleBracketComponents.default, _transformInputOnToOnEvent.default, _transformTopLevelComponents.default, _transformInlineLinkTo.default, _transformOldClassBindingSyntax.default, _transformQuotedBindingsIntoJustBindings.default, _deprecateRenderModel.default, _deprecateRender.default, _assertReservedNamedArguments.default, _transformActionSyntax.default, _transformInputTypeSyntax.default, _transformAttrsIntoArgs.default, _transformEachInIntoEach.default, _transformHasBlockSyntax.default]);
});
enifed('ember-template-compiler/plugins/transform-action-syntax', ['exports'], function (exports) {
'use strict';
exports.default = TransformActionSyntax;
/**
@module ember
@submodule ember-glimmer
*/
/**
A Glimmer2 AST transformation that replaces all instances of
```handlebars
```
with
```handlebars
```
@private
@class TransformActionSyntax
*/
function TransformActionSyntax() {
// set later within Glimmer2 to the syntax package
this.syntax = null;
}
/**
@private
@method transform
@param {AST} ast The AST to be transformed.
*/
TransformActionSyntax.prototype.transform = function TransformActionSyntax_transform(ast) {
var _syntax = this.syntax,
traverse = _syntax.traverse,
b = _syntax.builders;
traverse(ast, {
ElementModifierStatement: function (node) {
if (isAction(node)) {
insertThisAsFirstParam(node, b);
}
},
MustacheStatement: function (node) {
if (isAction(node)) {
insertThisAsFirstParam(node, b);
}
},
SubExpression: function (node) {
if (isAction(node)) {
insertThisAsFirstParam(node, b);
}
}
});
return ast;
};
function isAction(node) {
return node.path.original === 'action';
}
function insertThisAsFirstParam(node, builders) {
node.params.unshift(builders.path('this'));
}
});
enifed('ember-template-compiler/plugins/transform-angle-bracket-components', ['exports'], function (exports) {
'use strict';
exports.default = TransformAngleBracketComponents;
function TransformAngleBracketComponents() {
// set later within HTMLBars to the syntax package
this.syntax = null;
}
/**
@private
@method transform
@param {AST} ast The AST to be transformed.
*/
TransformAngleBracketComponents.prototype.transform = function TransformAngleBracketComponents_transform(ast) {
var walker = new this.syntax.Walker();
walker.visit(ast, function (node) {
if (!validate(node)) {
return;
}
node.tag = '<' + node.tag + '>';
});
return ast;
};
function validate(node) {
return node.type === 'ComponentNode';
}
});
enifed('ember-template-compiler/plugins/transform-attrs-into-args', ['exports'], function (exports) {
'use strict';
exports.default = TransformAttrsToProps;
/**
@module ember
@submodule ember-glimmer
*/
/**
A Glimmer2 AST transformation that replaces all instances of
```handlebars
{{attrs.foo.bar}}
```
to
```handlebars
{{@foo.bar}}
```
as well as `{{#if attrs.foo}}`, `{{deeply (nested attrs.foobar.baz)}}` etc
@private
@class TransformAttrsToProps
*/
function TransformAttrsToProps() {
// set later within Glimmer2 to the syntax package
this.syntax = null;
}
function isAttrs(node, symbols) {
var name = node.parts[0];
if (symbols.indexOf(name) !== -1) {
return false;
}
if (name === 'attrs') {
return true;
}
if (name === null && node.parts[1] === 'attrs') {
node.parts.shift();
node.original = node.original.slice(5);
return true;
}
return false;
}
/**
@private
@method transform
@param {AST} ast The AST to be transformed.
*/
TransformAttrsToProps.prototype.transform = function TransformAttrsToProps_transform(ast) {
var _syntax = this.syntax,
traverse = _syntax.traverse,
b = _syntax.builders;
var stack = [[]];
traverse(ast, {
Program: {
enter: function (node) {
var parent = stack[stack.length - 1];
stack.push(parent.concat(node.blockParams));
},
exit: function (node) {
stack.pop();
}
},
PathExpression: function (node) {
if (isAttrs(node, stack[stack.length - 1])) {
var path = b.path(node.original.substr(6));
path.original = '@' + path.original;
path.data = true;
return path;
}
}
});
return ast;
};
});
enifed('ember-template-compiler/plugins/transform-dot-component-invocation', ['exports'], function (exports) {
'use strict';
exports.default = TransFormDotComponentInvocation;
/**
Transforms dot invocation of closure components to be wrapped
with the component helper. This allows for a more static invocation
of the component.
```handlebars
{{#my-component as |comps|}}
{{comp.dropdown isOpen=false}}
{{/my-component}}
```
with
```handlebars
{{#my-component as |comps|}}
{{component comp.dropdown isOpen=false}}
{{/my-component}}
```
and
```handlebars
{{#my-component as |comps|}}
{{comp.dropdown isOpen}}
{{/my-component}}
```
with
```handlebars
{{#my-component as |comps|}}
{{component comp.dropdown isOpen}}
{{/my-component}}
```
and
```handlebars
{{#my-component as |comps|}}
{{#comp.dropdown}}Open{{/comp.dropdown}}
{{/my-component}}
```
with
```handlebars
{{#my-component as |comps|}}
{{#component comp.dropdown}}Open{{/component}}
{{/my-component}}
```
@private
@class TransFormDotComponentInvocation
*/
function TransFormDotComponentInvocation() {
// set later within Glimmer2 to the syntax package
this.syntax = null;
}
TransFormDotComponentInvocation.prototype = {
_isMulipartPath: function (path) {
return path.parts.length > 1;
},
_isInlineInvocation: function (path, params, hash) {
if (this._isMulipartPath(path)) {
if (params.length > 0 || hash.pairs.length > 0) {
return true;
}
}
return false;
},
_wrapInComponent: function (node, builder) {
var component = node.path;
var componentHelper = builder.path('component');
node.path = componentHelper;
node.params.unshift(component);
},
transform: function (ast) {
var _this = this;
var _syntax = this.syntax,
traverse = _syntax.traverse,
b = _syntax.builders;
traverse(ast, {
MustacheStatement: function (node) {
if (_this._isInlineInvocation(node.path, node.params, node.hash)) {
_this._wrapInComponent(node, b);
}
},
BlockStatement: function (node) {
if (_this._isMulipartPath(node.path)) {
_this._wrapInComponent(node, b);
}
}
});
return ast;
}
};
});
enifed('ember-template-compiler/plugins/transform-each-in-into-each', ['exports'], function (exports) {
'use strict';
exports.default = TransformEachInIntoEach;
/**
@module ember
@submodule ember-glimmer
*/
/**
A Glimmer2 AST transformation that replaces all instances of
```handlebars
{{#each-in iterableThing as |key value|}}
```
with
```handlebars
{{#each (-each-in iterableThing) as |key value|}}
```
@private
@class TransformHasBlockSyntax
*/
function TransformEachInIntoEach() {
// set later within Glimmer2 to the syntax package
this.syntax = null;
}
/**
@private
@method transform
@param {AST} ast The AST to be transformed.
*/
TransformEachInIntoEach.prototype.transform = function TransformEachInIntoEach_transform(ast) {
var _syntax = this.syntax,
traverse = _syntax.traverse,
b = _syntax.builders;
traverse(ast, {
BlockStatement: function (node) {
if (node.path.original === 'each-in') {
node.params[0] = b.sexpr(b.path('-each-in'), [node.params[0]]);
return b.block(b.path('each'), node.params, node.hash, node.program, node.inverse, node.loc);
}
}
});
return ast;
};
});
enifed('ember-template-compiler/plugins/transform-has-block-syntax', ['exports'], function (exports) {
'use strict';
exports.default = TransformHasBlockSyntax;
/**
@module ember
@submodule ember-glimmer
*/
/**
A Glimmer2 AST transformation that replaces all instances of
```handlebars
{{hasBlock}}
```
with
```handlebars
{{has-block}}
```
@private
@class TransformHasBlockSyntax
*/
function TransformHasBlockSyntax() {
// set later within Glimmer2 to the syntax package
this.syntax = null;
}
var TRANSFORMATIONS = {
hasBlock: 'has-block',
hasBlockParams: 'has-block-params'
};
/**
@private
@method transform
@param {AST} ast The AST to be transformed.
*/
TransformHasBlockSyntax.prototype.transform = function TransformHasBlockSyntax_transform(ast) {
var _syntax = this.syntax,
traverse = _syntax.traverse,
b = _syntax.builders;
traverse(ast, {
PathExpression: function (node) {
if (TRANSFORMATIONS[node.original]) {
return b.sexpr(b.path(TRANSFORMATIONS[node.original]));
}
},
MustacheStatement: function (node) {
if (TRANSFORMATIONS[node.path.original]) {
return b.mustache(b.path(TRANSFORMATIONS[node.path.original]), node.params, node.hash, null, node.loc);
}
},
SubExpression: function (node) {
if (TRANSFORMATIONS[node.path.original]) {
return b.sexpr(b.path(TRANSFORMATIONS[node.path.original]), node.params, node.hash);
}
}
});
return ast;
};
});
enifed('ember-template-compiler/plugins/transform-inline-link-to', ['exports'], function (exports) {
'use strict';
exports.default = TransformInlineLinkTo;
function TransformInlineLinkTo(options) {
this.options = options;
this.syntax = null;
}
TransformInlineLinkTo.prototype.transform = function TransformInlineLinkTo_transform(ast) {
var _syntax = this.syntax,
traverse = _syntax.traverse,
b = _syntax.builders;
function buildProgram(content, loc) {
return b.program([buildStatement(content, loc)], null, loc);
}
function buildStatement(content, loc) {
switch (content.type) {
case 'PathExpression':
return b.mustache(content, null, null, null, loc);
case 'SubExpression':
return b.mustache(content.path, content.params, content.hash, null, loc);
// The default case handles literals.
default:
return b.text('' + content.value, loc);
}
}
function unsafeHtml(expr) {
return b.sexpr('-html-safe', [expr]);
}
traverse(ast, {
MustacheStatement: function (node) {
if (node.path.original === 'link-to') {
var content = node.escaped ? node.params[0] : unsafeHtml(node.params[0]);
return b.block('link-to', node.params.slice(1), node.hash, buildProgram(content, node.loc), null, node.loc);
}
}
});
return ast;
};
});
enifed('ember-template-compiler/plugins/transform-input-on-to-onEvent', ['exports', 'ember-debug', 'ember-template-compiler/system/calculate-location-display'], function (exports, _emberDebug, _calculateLocationDisplay) {
'use strict';
exports.default = TransformInputOnToOnEvent;
/**
@module ember
@submodule ember-htmlbars
*/
/**
An HTMLBars AST transformation that replaces all instances of
```handlebars
{{input on="enter" action="doStuff"}}
{{input on="key-press" action="doStuff"}}
```
with
```handlebars
{{input enter="doStuff"}}
{{input key-press="doStuff"}}
```
@private
@class TransformInputOnToOnEvent
*/
function TransformInputOnToOnEvent() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
// set later within HTMLBars to the syntax package
this.syntax = null;
this.options = options;
}
/**
@private
@method transform
@param {AST} ast The AST to be transformed.
*/
TransformInputOnToOnEvent.prototype.transform = function TransformInputOnToOnEvent_transform(ast) {
var pluginContext = this;
var b = pluginContext.syntax.builders;
var walker = new pluginContext.syntax.Walker();
var moduleName = pluginContext.options.meta.moduleName;
walker.visit(ast, function (node) {
if (pluginContext.validate(node)) {
var action = hashPairForKey(node.hash, 'action');
var on = hashPairForKey(node.hash, 'on');
var onEvent = hashPairForKey(node.hash, 'onEvent');
var normalizedOn = on || onEvent;
var moduleInfo = (0, _calculateLocationDisplay.default)(moduleName, node.loc);
if (normalizedOn && normalizedOn.value.type !== 'StringLiteral') {
(true && !(false) && (0, _emberDebug.deprecate)('Using a dynamic value for \'#{normalizedOn.key}=\' with the \'{{input}}\' helper ' + moduleInfo + 'is deprecated.', false, { id: 'ember-template-compiler.transform-input-on-to-onEvent.dynamic-value', until: '3.0.0' }));
normalizedOn.key = 'onEvent';
return; // exit early, as we cannot transform further
}
removeFromHash(node.hash, normalizedOn);
removeFromHash(node.hash, action);
if (!action) {
(true && !(false) && (0, _emberDebug.deprecate)('Using \'{{input ' + normalizedOn.key + '="' + normalizedOn.value.value + '" ...}}\' without specifying an action ' + moduleInfo + 'will do nothing.', false, { id: 'ember-template-compiler.transform-input-on-to-onEvent.no-action', until: '3.0.0' }));
return; // exit early, if no action was available there is nothing to do
}
var specifiedOn = normalizedOn ? normalizedOn.key + '="' + normalizedOn.value.value + '" ' : '';
if (normalizedOn && normalizedOn.value.value === 'keyPress') {
// using `keyPress` in the root of the component will
// clobber the keyPress event handler
normalizedOn.value.value = 'key-press';
}
var expected = (normalizedOn ? normalizedOn.value.value : 'enter') + '="' + action.value.original + '"';
(true && !(false) && (0, _emberDebug.deprecate)('Using \'{{input ' + specifiedOn + 'action="' + action.value.original + '"}}\' ' + moduleInfo + 'is deprecated. Please use \'{{input ' + expected + '}}\' instead.', false, { id: 'ember-template-compiler.transform-input-on-to-onEvent.normalized-on', until: '3.0.0' }));
if (!normalizedOn) {
normalizedOn = b.pair('onEvent', b.string('enter'));
}
node.hash.pairs.push(b.pair(normalizedOn.value.value, action.value));
}
});
return ast;
};
TransformInputOnToOnEvent.prototype.validate = function TransformWithAsToHash_validate(node) {
return node.type === 'MustacheStatement' && node.path.original === 'input' && (hashPairForKey(node.hash, 'action') || hashPairForKey(node.hash, 'on') || hashPairForKey(node.hash, 'onEvent'));
};
function hashPairForKey(hash, key) {
for (var i = 0; i < hash.pairs.length; i++) {
var pair = hash.pairs[i];
if (pair.key === key) {
return pair;
}
}
return false;
}
function removeFromHash(hash, pairToRemove) {
var newPairs = [];
for (var i = 0; i < hash.pairs.length; i++) {
var pair = hash.pairs[i];
if (pair !== pairToRemove) {
newPairs.push(pair);
}
}
hash.pairs = newPairs;
}
});
enifed('ember-template-compiler/plugins/transform-input-type-syntax', ['exports'], function (exports) {
'use strict';
exports.default = TransformInputTypeSyntax;
/**
@module ember
@submodule ember-glimmer
*/
/**
A Glimmer2 AST transformation that replaces all instances of
```handlebars
{{input type=boundType}}
```
with
```handlebars
{{input (-input-type boundType) type=boundType}}
```
Note that the type parameters is not removed as the -input-type helpers
is only used to select the component class. The component still needs
the type parameter to function.
@private
@class TransformInputTypeSyntax
*/
function TransformInputTypeSyntax() {
// set later within Glimmer2 to the syntax package
this.syntax = null;
}
/**
@private
@method transform
@param {AST} ast The AST to be transformed.
*/
TransformInputTypeSyntax.prototype.transform = function TransformInputTypeSyntax_transform(ast) {
var _syntax = this.syntax,
traverse = _syntax.traverse,
b = _syntax.builders;
traverse(ast, {
MustacheStatement: function (node) {
if (isInput(node)) {
insertTypeHelperParameter(node, b);
}
}
});
return ast;
};
function isInput(node) {
return node.path.original === 'input';
}
function insertTypeHelperParameter(node, builders) {
var pairs = node.hash.pairs;
var pair = null;
for (var i = 0; i < pairs.length; i++) {
if (pairs[i].key === 'type') {
pair = pairs[i];
break;
}
}
if (pair && pair.value.type !== 'StringLiteral') {
node.params.unshift(builders.sexpr('-input-type', [pair.value], null, pair.loc));
}
}
});
enifed('ember-template-compiler/plugins/transform-item-class', ['exports'], function (exports) {
'use strict';
exports.default = TransformItemClass;
function TransformItemClass() {
this.syntax = null;
}
TransformItemClass.prototype.transform = function TransformItemClass_transform(ast) {
var b = this.syntax.builders;
var walker = new this.syntax.Walker();
walker.visit(ast, function (node) {
if (!validate(node)) {
return;
}
for (var i = 0; i < node.hash.pairs.length; i++) {
var pair = node.hash.pairs[i];
var key = pair.key,
value = pair.value;
if (key !== 'itemClass') {
return;
}
if (value.type === 'StringLiteral') {
return;
}
var propName = value.original;
var params = [value];
var sexprParams = [b.string(propName), b.path(propName)];
params.push(b.sexpr(b.string('-normalize-class'), sexprParams));
var sexpr = b.sexpr(b.string('if'), params);
pair.value = sexpr;
}
});
return ast;
};
function validate(node) {
return (node.type === 'BlockStatement' || node.type === 'MustacheStatement') && node.path.original === 'collection';
}
});
enifed('ember-template-compiler/plugins/transform-old-binding-syntax', ['exports', 'ember-debug', 'ember-template-compiler/system/calculate-location-display'], function (exports, _emberDebug, _calculateLocationDisplay) {
'use strict';
exports.default = TransformOldBindingSyntax;
function TransformOldBindingSyntax(options) {
this.syntax = null;
this.options = options;
}
TransformOldBindingSyntax.prototype.transform = function TransformOldBindingSyntax_transform(ast) {
var moduleName = this.options.meta.moduleName;
var b = this.syntax.builders;
var walker = new this.syntax.Walker();
walker.visit(ast, function (node) {
if (!validate(node)) {
return;
}
for (var i = 0; i < node.hash.pairs.length; i++) {
var pair = node.hash.pairs[i];
var key = pair.key,
value = pair.value;
var sourceInformation = (0, _calculateLocationDisplay.default)(moduleName, pair.loc);
if (key === 'classBinding') {
return;
}
(true && (0, _emberDebug.assert)('Setting \'attributeBindings\' via template helpers is not allowed ' + sourceInformation, key !== 'attributeBindings'));
if (key.substr(-7) === 'Binding') {
var newKey = key.slice(0, -7);
(true && !(false) && (0, _emberDebug.deprecate)('You\'re using legacy binding syntax: ' + key + '=' + exprToString(value) + ' ' + sourceInformation + '. Please replace with ' + newKey + '=' + value.original, false, { id: 'ember-template-compiler.transform-old-binding-syntax', until: '3.0.0' }));
pair.key = newKey;
if (value.type === 'StringLiteral') {
pair.value = b.path(value.original);
}
}
}
});
return ast;
};
function validate(node) {
return node.type === 'BlockStatement' || node.type === 'MustacheStatement';
}
function exprToString(expr) {
switch (expr.type) {
case 'StringLiteral':
return '"' + expr.original + '"';
case 'PathExpression':
return expr.original;
}
}
});
enifed('ember-template-compiler/plugins/transform-old-class-binding-syntax', ['exports'], function (exports) {
'use strict';
exports.default = TransformOldClassBindingSyntax;
function TransformOldClassBindingSyntax(options) {
this.syntax = null;
this.options = options;
}
TransformOldClassBindingSyntax.prototype.transform = function TransformOldClassBindingSyntax_transform(ast) {
var b = this.syntax.builders;
var walker = new this.syntax.Walker();
walker.visit(ast, function (node) {
if (!validate(node)) {
return;
}
var allOfTheMicrosyntaxes = [];
var allOfTheMicrosyntaxIndexes = [];
var classPair = void 0;
each(node.hash.pairs, function (pair, index) {
var key = pair.key;
if (key === 'classBinding' || key === 'classNameBindings') {
allOfTheMicrosyntaxIndexes.push(index);
allOfTheMicrosyntaxes.push(pair);
} else if (key === 'class') {
classPair = pair;
}
});
if (allOfTheMicrosyntaxes.length === 0) {
return;
}
var classValue = [];
if (classPair) {
classValue.push(classPair.value);
classValue.push(b.string(' '));
} else {
classPair = b.pair('class', null);
node.hash.pairs.push(classPair);
}
each(allOfTheMicrosyntaxIndexes, function (index) {
node.hash.pairs.splice(index, 1);
});
each(allOfTheMicrosyntaxes, function (_ref) {
var value = _ref.value,
loc = _ref.loc;
var sexprs = [];
// TODO: add helpful deprecation when both `classNames` and `classNameBindings` can
// be removed.
if (value.type === 'StringLiteral') {
var microsyntax = parseMicrosyntax(value.original);
buildSexprs(microsyntax, sexprs, b);
classValue.push.apply(classValue, sexprs);
}
});
var hash = b.hash();
classPair.value = b.sexpr(b.path('concat'), classValue, hash);
});
return ast;
};
function buildSexprs(microsyntax, sexprs, b) {
for (var i = 0; i < microsyntax.length; i++) {
var _microsyntax$i = microsyntax[i],
propName = _microsyntax$i[0],
activeClass = _microsyntax$i[1],
inactiveClass = _microsyntax$i[2];
var sexpr = void 0;
// :my-class-name microsyntax for static values
if (propName === '') {
sexpr = b.string(activeClass);
} else {
var params = [b.path(propName)];
if (activeClass || activeClass === '') {
params.push(b.string(activeClass));
} else {
var sexprParams = [b.string(propName), b.path(propName)];
var hash = b.hash();
if (activeClass !== undefined) {
hash.pairs.push(b.pair('activeClass', b.string(activeClass)));
}
if (inactiveClass !== undefined) {
hash.pairs.push(b.pair('inactiveClass', b.string(inactiveClass)));
}
params.push(b.sexpr(b.path('-normalize-class'), sexprParams, hash));
}
if (inactiveClass || inactiveClass === '') {
params.push(b.string(inactiveClass));
}
sexpr = b.sexpr(b.path('if'), params);
}
sexprs.push(sexpr);
sexprs.push(b.string(' '));
}
}
function validate(node) {
return node.type === 'BlockStatement' || node.type === 'MustacheStatement';
}
function each(list, callback) {
for (var i = 0; i < list.length; i++) {
callback(list[i], i);
}
}
function parseMicrosyntax(string) {
var segments = string.split(' ');
for (var i = 0; i < segments.length; i++) {
segments[i] = segments[i].split(':');
}
return segments;
}
});
enifed('ember-template-compiler/plugins/transform-quoted-bindings-into-just-bindings', ['exports'], function (exports) {
'use strict';
exports.default = TransformQuotedBindingsIntoJustBindings;
function TransformQuotedBindingsIntoJustBindings() {
// set later within HTMLBars to the syntax package
this.syntax = null;
}
/**
@private
@method transform
@param {AST} ast The AST to be transformed.
*/
TransformQuotedBindingsIntoJustBindings.prototype.transform = function TransformQuotedBindingsIntoJustBindings_transform(ast) {
var walker = new this.syntax.Walker();
walker.visit(ast, function (node) {
if (!validate(node)) {
return;
}
var styleAttr = getStyleAttr(node);
if (!validStyleAttr(styleAttr)) {
return;
}
styleAttr.value = styleAttr.value.parts[0];
});
return ast;
};
function validate(node) {
return node.type === 'ElementNode';
}
function validStyleAttr(attr) {
if (!attr) {
return false;
}
var value = attr.value;
if (!value || value.type !== 'ConcatStatement' || value.parts.length !== 1) {
return false;
}
var onlyPart = value.parts[0];
return onlyPart.type === 'MustacheStatement';
}
function getStyleAttr(node) {
var attributes = node.attributes;
for (var i = 0; i < attributes.length; i++) {
if (attributes[i].name === 'style') {
return attributes[i];
}
}
}
});
enifed('ember-template-compiler/plugins/transform-top-level-components', ['exports'], function (exports) {
'use strict';
exports.default = TransformTopLevelComponents;
function TransformTopLevelComponents() {
// set later within HTMLBars to the syntax package
this.syntax = null;
}
/**
@private
@method transform
@param {AST} The AST to be transformed.
*/
TransformTopLevelComponents.prototype.transform = function TransformTopLevelComponents_transform(ast) {
hasSingleComponentNode(ast, function (component) {
component.tag = '@' + component.tag;
component.isStatic = true;
});
return ast;
};
function hasSingleComponentNode(program, componentCallback) {
var loc = program.loc,
body = program.body;
if (!loc || loc.start.line !== 1 || loc.start.column !== 0) {
return;
}
var lastComponentNode = void 0;
var nodeCount = 0;
for (var i = 0; i < body.length; i++) {
var curr = body[i];
// text node with whitespace only
if (curr.type === 'TextNode' && /^[\s]*$/.test(curr.chars)) {
continue;
}
// has multiple root elements if we've been here before
if (nodeCount++ > 0) {
return false;
}
if (curr.type === 'ComponentNode' || curr.type === 'ElementNode') {
lastComponentNode = curr;
}
}
if (!lastComponentNode) {
return;
}
if (lastComponentNode.type === 'ComponentNode') {
componentCallback(lastComponentNode);
}
}
});
enifed('ember-template-compiler/system/bootstrap', ['exports', 'ember-debug', 'ember-template-compiler/system/compile'], function (exports, _emberDebug, _compile) {
'use strict';
/**
Find templates stored in the head tag as script tags and make them available
to `Ember.CoreView` in the global `Ember.TEMPLATES` object.
Script tags with `text/x-handlebars` will be compiled
with Ember's template compiler and are suitable for use as a view's template.
@private
@method bootstrap
@for Ember.HTMLBars
@static
@param ctx
*/
/**
@module ember
@submodule ember-templates
*/
function bootstrap(_ref) {
var context = _ref.context,
hasTemplate = _ref.hasTemplate,
setTemplate = _ref.setTemplate;
if (!context) {
context = document;
}
var selector = 'script[type="text/x-handlebars"]';
var elements = context.querySelectorAll(selector);
for (var i = 0; i < elements.length; i++) {
var script = elements[i];
// Get the name of the script
// First look for data-template-name attribute, then fall back to its
// id if no name is found.
var templateName = script.getAttribute('data-template-name') || script.getAttribute('id') || 'application';
var template = void 0;
template = (0, _compile.default)(script.innerHTML, {
moduleName: templateName
});
// Check if template of same name already exists.
if (hasTemplate(templateName)) {
throw new _emberDebug.Error('Template named "' + templateName + '" already exists.');
}
// For templates which have a name, we save them and then remove them from the DOM.
setTemplate(templateName, template);
// Remove script tag from DOM.
script.parentNode.removeChild(script);
}
}
exports.default = bootstrap;
});
enifed('ember-template-compiler/system/calculate-location-display', ['exports'], function (exports) {
'use strict';
exports.default = calculateLocationDisplay;
function calculateLocationDisplay(moduleName) {
var loc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _ref = loc.start || {},
column = _ref.column,
line = _ref.line;
var moduleInfo = '';
if (moduleName) {
moduleInfo += '\'' + moduleName + '\' ';
}
if (line !== undefined && column !== undefined) {
if (moduleName) {
// only prepend @ if the moduleName was present
moduleInfo += '@ ';
}
moduleInfo += 'L' + line + ':C' + column;
}
if (moduleInfo) {
moduleInfo = '(' + moduleInfo + ') ';
}
return moduleInfo;
}
});
enifed('ember-template-compiler/system/compile-options', ['exports', 'ember-utils', 'ember-template-compiler/plugins'], function (exports, _emberUtils, _plugins) {
'use strict';
exports.default = compileOptions;
exports.registerPlugin = registerPlugin;
exports.removePlugin = removePlugin;
var USER_PLUGINS = [];
function compileOptions(_options) {
var options = (0, _emberUtils.assign)({ meta: {} }, _options);
// move `moduleName` into `meta` property
if (options.moduleName) {
var meta = options.meta;
meta.moduleName = options.moduleName;
}
if (!options.plugins) {
options.plugins = { ast: [].concat(USER_PLUGINS, _plugins.default) };
} else {
var potententialPugins = [].concat(USER_PLUGINS, _plugins.default);
var pluginsToAdd = potententialPugins.filter(function (plugin) {
return options.plugins.ast.indexOf(plugin) === -1;
});
options.plugins.ast = options.plugins.ast.slice().concat(pluginsToAdd);
}
return options;
}
function registerPlugin(type, PluginClass) {
if (type !== 'ast') {
throw new Error('Attempting to register ' + PluginClass + ' as "' + type + '" which is not a valid Glimmer plugin type.');
}
if (USER_PLUGINS.indexOf(PluginClass) === -1) {
USER_PLUGINS = [PluginClass].concat(USER_PLUGINS);
}
}
function removePlugin(type, PluginClass) {
if (type !== 'ast') {
throw new Error('Attempting to unregister ' + PluginClass + ' as "' + type + '" which is not a valid Glimmer plugin type.');
}
USER_PLUGINS = USER_PLUGINS.filter(function (plugin) {
return plugin !== PluginClass;
});
}
});
enifed('ember-template-compiler/system/compile', ['exports', 'require', 'ember-template-compiler/system/precompile'], function (exports, _require2, _precompile) {
'use strict';
exports.default = compile;
/**
@module ember
@submodule ember-template-compiler
*/
var template = void 0;
/**
Uses HTMLBars `compile` function to process a string into a compiled template.
This is not present in production builds.
@private
@method compile
@param {String} templateString This is the string to be compiled by HTMLBars.
@param {Object} options This is an options hash to augment the compiler options.
*/
function compile(templateString, options) {
if (!template && (0, _require2.has)('ember-glimmer')) {
template = (0, _require2.default)('ember-glimmer').template;
}
if (!template) {
throw new Error('Cannot call `compile` with only the template compiler loaded. Please load `ember.debug.js` or `ember.prod.js` prior to calling `compile`.');
}
var precompiledTemplateString = (0, _precompile.default)(templateString, options);
var templateJS = new Function('return ' + precompiledTemplateString)();
return template(templateJS);
}
});
enifed('ember-template-compiler/system/precompile', ['exports', 'ember-template-compiler/system/compile-options', 'require'], function (exports, _compileOptions, _require2) {
'use strict';
exports.default = precompile;
/**
@module ember
@submodule ember-template-compiler
*/
var glimmerPrecompile = void 0;
/**
Uses HTMLBars `compile` function to process a string into a compiled template string.
The returned string must be passed through `Ember.HTMLBars.template`.
This is not present in production builds.
@private
@method precompile
@param {String} templateString This is the string to be compiled by HTMLBars.
*/
function precompile(templateString, options) {
if (!glimmerPrecompile && (0, _require2.has)('@glimmer/compiler')) {
glimmerPrecompile = (0, _require2.default)('@glimmer/compiler').precompile;
}
if (!glimmerPrecompile) {
throw new Error('Cannot call `compile` without the template compiler loaded. Please load `ember-template-compiler.js` prior to calling `compile`.');
}
return glimmerPrecompile(templateString, (0, _compileOptions.default)(options));
}
});
enifed('ember-template-compiler/tests/plugins/assert-reserved-named-arguments-test', ['ember-template-compiler/index'], function (_index) {
'use strict';
QUnit.module('ember-template-compiler: assert-reserved-named-arguments');
QUnit.test('Paths beginning with @ are not valid', function () {
expect(3);
expectAssertion(function () {
(0, _index.compile)('{{@foo}}', {
moduleName: 'baz/foo-bar'
});
}, '\'@foo\' is not a valid path. (\'baz/foo-bar\' @ L1:C2) ');
expectAssertion(function () {
(0, _index.compile)('{{#if @foo}}Yup{{/if}}', {
moduleName: 'baz/foo-bar'
});
}, '\'@foo\' is not a valid path. (\'baz/foo-bar\' @ L1:C6) ');
expectAssertion(function () {
(0, _index.compile)('{{input type=(if @foo "bar" "baz")}}', {
moduleName: 'baz/foo-bar'
});
}, '\'@foo\' is not a valid path. (\'baz/foo-bar\' @ L1:C17) ');
});
});
enifed('ember-template-compiler/tests/plugins/deprecate-render-model-test', ['ember-template-compiler/index'], function (_index) {
'use strict';
QUnit.module('ember-template-compiler: deprecate-model-render');
QUnit.test('Using `{{render` with model provides a deprecation', function () {
expect(1);
expectDeprecation(function () {
(0, _index.compile)('{{render "foo-bar" coolModel}}', {
moduleName: 'baz/foo-bar'
});
}, 'Please refactor `{{render "foo-bar" coolModel}}` to a component and' + ' invoke via `{{foo-bar model=coolModel}}`. (\'baz/foo-bar\' @ L1:C0) ');
});
});
enifed('ember-template-compiler/tests/plugins/deprecate-render-test', ['ember-template-compiler/index'], function (_index) {
'use strict';
QUnit.module('ember-template-compiler: deprecate-render');
QUnit.test('Using `{{render` without a model provides a deprecation', function () {
expect(1);
expectDeprecation(function () {
(0, _index.compile)('{{render "foo-bar"}}', {
moduleName: 'baz/foo-bar'
});
}, 'Please refactor `{{render "foo-bar"}}` to a component and' + ' invoke via `{{foo-bar}}`. (\'baz/foo-bar\' @ L1:C0) ');
});
});
enifed('ember-template-compiler/tests/plugins/transform-dot-component-invocation-test', ['ember-template-compiler/index'], function (_index) {
'use strict';
QUnit.module('ember-template-compiler: transforms dot component invocation');
QUnit.test('Does not throw a compiler error for path components', function (assert) {
assert.expect(1);
['{{this.modal open}}', '{{this.modal isOpen=true}}', '{{#this.modal}}Woot{{/this.modal}}', '{{c.modal open}}', '{{c.modal isOpen=true}}', '{{#c.modal}}Woot{{/c.modal}}', '{{#my-component as |c|}}{{c.a name="Chad"}}{{/my-component}}', '{{#my-component as |c|}}{{c.a "Chad"}}{{/my-component}}', '{{#my-component as |c|}}{{#c.a}}{{/c.a}}{{/my-component}}'].forEach(function (layout, i) {
(0, _index.compile)(layout, { moduleName: 'example-' + i });
});
assert.ok(true);
});
});
enifed('ember-template-compiler/tests/plugins/transform-inline-link-to-test', ['ember-template-compiler/index'], function (_index) {
'use strict';
QUnit.module('ember-template-compiler: assert-no-view-and-controller-paths without legacy view support');
QUnit.test('Can transform an inline {{link-to}} without error', function () {
expect(0);
(0, _index.compile)('{{link-to \'foo\' \'index\'}}', {
moduleName: 'foo/bar/baz'
});
});
});
enifed('ember-template-compiler/tests/plugins/transform-input-on-test', ['ember-template-compiler/index'], function (_index) {
'use strict';
QUnit.module('ember-template-compiler: transform-input-on');
QUnit.test('Using `action` without `on` provides a deprecation', function () {
expect(1);
expectDeprecation(function () {
(0, _index.compile)('{{input action="foo"}}', {
moduleName: 'foo/bar/baz'
});
}, 'Using \'{{input action="foo"}}\' (\'foo/bar/baz\' @ L1:C0) is deprecated. Please use \'{{input enter="foo"}}\' instead.');
});
QUnit.test('Using `action` with `on` provides a deprecation', function () {
expect(1);
expectDeprecation(function () {
(0, _index.compile)('{{input on="focus-in" action="foo"}}', {
moduleName: 'foo/bar/baz'
});
}, 'Using \'{{input on="focus-in" action="foo"}}\' (\'foo/bar/baz\' @ L1:C0) is deprecated. Please use \'{{input focus-in="foo"}}\' instead.');
});
QUnit.test('Using `on=\'keyPress\'` does not clobber `keyPress`', function () {
expect(1);
expectDeprecation(function () {
(0, _index.compile)('{{input on="keyPress" action="foo"}}', {
moduleName: 'foo/bar/baz'
});
}, 'Using \'{{input on="keyPress" action="foo"}}\' (\'foo/bar/baz\' @ L1:C0) is deprecated. Please use \'{{input key-press="foo"}}\' instead.');
});
QUnit.test('Using `on=\'foo\'` without `action=\'asdf\'` raises specific deprecation', function () {
expect(1);
expectDeprecation(function () {
(0, _index.compile)('{{input on="asdf"}}', {
moduleName: 'foo/bar/baz'
});
}, 'Using \'{{input on="asdf" ...}}\' without specifying an action (\'foo/bar/baz\' @ L1:C0) will do nothing.');
});
});
enifed('ember-template-compiler/tests/plugins/transform-input-type-syntax-test', ['ember-template-compiler/index'], function (_index) {
'use strict';
QUnit.module('ember-template-compiler: input type syntax');
QUnit.test('Can compile an {{input}} helper that has a sub-expression value as its type', function () {
expect(0);
(0, _index.compile)('{{input type=(if true \'password\' \'text\')}}');
});
QUnit.test('Can compile an {{input}} helper with a string literal type', function () {
expect(0);
(0, _index.compile)('{{input type=\'text\'}}');
});
QUnit.test('Can compile an {{input}} helper with a type stored in a var', function () {
expect(0);
(0, _index.compile)('{{input type=_type}}');
});
});
enifed('ember-template-compiler/tests/system/bootstrap-test', ['ember-metal', 'ember-views', 'ember-glimmer', 'ember-template-compiler/system/bootstrap', 'internal-test-helpers'], function (_emberMetal, _emberViews, _emberGlimmer, _bootstrap, _internalTestHelpers) {
'use strict';
var trim = _emberViews.jQuery.trim;
var component = void 0,
fixture = void 0;
function checkTemplate(templateName) {
(0, _emberMetal.run)(function () {
return (0, _bootstrap.default)({ context: fixture, hasTemplate: _emberGlimmer.hasTemplate, setTemplate: _emberGlimmer.setTemplate });
});
var template = (0, _emberGlimmer.getTemplate)(templateName);
ok(template, 'template is available on Ember.TEMPLATES');
equal((0, _emberViews.jQuery)('#qunit-fixture script').length, 0, 'script removed');
var owner = (0, _internalTestHelpers.buildOwner)();
owner.register('template:-top-level', template);
owner.register('component:-top-level', _emberGlimmer.Component.extend({
layoutName: '-top-level',
firstName: 'Tobias',
drug: 'teamocil'
}));
component = owner.lookup('component:-top-level');
(0, _internalTestHelpers.runAppend)(component);
equal((0, _emberViews.jQuery)('#qunit-fixture').text().trim(), 'Tobias takes teamocil', 'template works');
(0, _internalTestHelpers.runDestroy)(component);
}
QUnit.module('ember-templates: bootstrap', {
setup: function () {
fixture = document.getElementById('qunit-fixture');
},
teardown: function () {
(0, _emberGlimmer.setTemplates)({});
(0, _internalTestHelpers.runDestroy)(component);
}
});
QUnit.test('template with data-template-name should add a new template to Ember.TEMPLATES', function () {
(0, _emberViews.jQuery)('#qunit-fixture').html('');
checkTemplate('funkyTemplate');
});
QUnit.test('template with id instead of data-template-name should add a new template to Ember.TEMPLATES', function () {
(0, _emberViews.jQuery)('#qunit-fixture').html('');
checkTemplate('funkyTemplate');
});
QUnit.test('template without data-template-name or id should default to application', function () {
(0, _emberViews.jQuery)('#qunit-fixture').html('');
checkTemplate('application');
});
if (typeof Handlebars === 'object') {
QUnit.test('template with type text/x-raw-handlebars should be parsed', function () {
(0, _emberViews.jQuery)('#qunit-fixture').html('');
(0, _emberMetal.run)(function () {
return (0, _bootstrap.default)({ context: fixture, hasTemplate: _emberGlimmer.hasTemplate, setTemplate: _emberGlimmer.setTemplate });
});
var template = (0, _emberGlimmer.getTemplate)('funkyTemplate');
ok(template, 'template with name funkyTemplate available');
// This won't even work with Ember templates
equal(trim(template({ name: 'Tobias' })), 'Tobias');
});
}
QUnit.test('duplicated default application templates should throw exception', function () {
(0, _emberViews.jQuery)('#qunit-fixture').html('');
throws(function () {
return (0, _bootstrap.default)({ context: fixture, hasTemplate: _emberGlimmer.hasTemplate, setTemplate: _emberGlimmer.setTemplate });
}, /Template named "[^"]+" already exists\./, 'duplicate templates should not be allowed');
});
QUnit.test('default application template and id application template present should throw exception', function () {
(0, _emberViews.jQuery)('#qunit-fixture').html('');
throws(function () {
return (0, _bootstrap.default)({ context: fixture, hasTemplate: _emberGlimmer.hasTemplate, setTemplate: _emberGlimmer.setTemplate });
}, /Template named "[^"]+" already exists\./, 'duplicate templates should not be allowed');
});
QUnit.test('default application template and data-template-name application template present should throw exception', function () {
(0, _emberViews.jQuery)('#qunit-fixture').html('');
throws(function () {
return (0, _bootstrap.default)({ context: fixture, hasTemplate: _emberGlimmer.hasTemplate, setTemplate: _emberGlimmer.setTemplate });
}, /Template named "[^"]+" already exists\./, 'duplicate templates should not be allowed');
});
QUnit.test('duplicated template id should throw exception', function () {
(0, _emberViews.jQuery)('#qunit-fixture').html('');
throws(function () {
return (0, _bootstrap.default)({ context: fixture, hasTemplate: _emberGlimmer.hasTemplate, setTemplate: _emberGlimmer.setTemplate });
}, /Template named "[^"]+" already exists\./, 'duplicate templates should not be allowed');
});
QUnit.test('duplicated template data-template-name should throw exception', function () {
(0, _emberViews.jQuery)('#qunit-fixture').html('');
throws(function () {
return (0, _bootstrap.default)({ context: fixture, hasTemplate: _emberGlimmer.hasTemplate, setTemplate: _emberGlimmer.setTemplate });
}, /Template named "[^"]+" already exists\./, 'duplicate templates should not be allowed');
});
});
enifed('ember-template-compiler/tests/system/compile_options_test', ['ember-template-compiler/index'], function (_index) {
'use strict';
QUnit.module('ember-template-compiler: default compile options');
QUnit.test('default options are a new copy', function () {
notEqual((0, _index.compileOptions)(), (0, _index.compileOptions)());
});
QUnit.test('has default AST plugins', function (assert) {
assert.expect(_index.defaultPlugins.length);
var plugins = (0, _index.compileOptions)().plugins.ast,
i,
plugin;
for (i = 0; i < _index.defaultPlugins.length; i++) {
plugin = _index.defaultPlugins[i];
assert.ok(plugins.indexOf(plugin) > -1, 'includes ' + plugin);
}
});
});
enifed('ember-testing/tests/acceptance_test', ['ember-metal', 'ember-views', 'ember-testing/test', 'ember-testing/adapters/qunit', 'ember-application', 'ember-routing', 'ember-template-compiler', 'ember-runtime', 'ember-glimmer', 'ember-testing/initializers'], function (_emberMetal, _emberViews, _test, _qunit, _emberApplication, _emberRouting, _emberTemplateCompiler, _emberRuntime, _emberGlimmer) {
'use strict';
//ES6TODO: we need {{link-to}} and {{outlet}} to exist here
var App, find, click, fillIn, currentRoute, currentURL, visit, originalAdapter, andThen, indexHitCount; // ensure the initializer is setup
QUnit.module('ember-testing Acceptance', {
setup: function () {
(0, _emberViews.jQuery)('').appendTo('head');
(0, _emberViews.jQuery)('').appendTo('body');
originalAdapter = _test.default.adapter;
(0, _emberMetal.run)(function () {
indexHitCount = 0;
App = _emberApplication.Application.create({
rootElement: '#ember-testing'
});
App.Router.map(function () {
this.route('posts');
this.route('comments');
this.route('abort_transition');
this.route('redirect');
});
App.IndexRoute = _emberRouting.Route.extend({
model: function () {
indexHitCount += 1;
}
});
App.PostsRoute = _emberRouting.Route.extend({
renderTemplate: function () {
currentRoute = 'posts';
this._super.apply(this, arguments);
}
});
(0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)(''));
App.CommentsRoute = _emberRouting.Route.extend({
renderTemplate: function () {
currentRoute = 'comments';
this._super.apply(this, arguments);
}
});
(0, _emberGlimmer.setTemplate)('comments', (0, _emberTemplateCompiler.compile)('{{input type="text"}}
'));
App.AbortTransitionRoute = _emberRouting.Route.extend({
beforeModel: function (transition) {
transition.abort();
}
});
App.RedirectRoute = _emberRouting.Route.extend({
beforeModel: function () {
this.transitionTo('comments');
}
});
App.setupForTesting();
});
_test.default.registerAsyncHelper('slowHelper', function () {
return new _emberRuntime.RSVP.Promise(function (resolve) {
setTimeout(resolve, 10);
});
});
App.injectTestHelpers();
find = window.find;
click = window.click;
fillIn = window.fillIn;
visit = window.visit;
andThen = window.andThen;
currentURL = window.currentURL;
},
teardown: function () {
_test.default.unregisterHelper('slowHelper');
(0, _emberGlimmer.setTemplates)({});
(0, _emberViews.jQuery)('#ember-testing-container, #ember-testing').remove();
(0, _emberMetal.run)(App, App.destroy);
App = null;
_test.default.adapter = originalAdapter;
indexHitCount = 0;
}
});
QUnit.test('helpers can be chained with then', function () {
expect(6);
currentRoute = 'index';
visit('/posts').then(function () {
equal(currentRoute, 'posts', 'Successfully visited posts route');
equal(currentURL(), '/posts', 'posts URL is correct');
return click('a:contains("Comments")');
}).then(function () {
equal(currentRoute, 'comments', 'visit chained with click');
return fillIn('.ember-text-field', 'yeah');
}).then(function () {
equal((0, _emberViews.jQuery)('.ember-text-field').val(), 'yeah', 'chained with fillIn');
return fillIn('.ember-text-field', '#ember-testing-container', 'context working');
}).then(function () {
equal((0, _emberViews.jQuery)('.ember-text-field').val(), 'context working', 'chained with fillIn');
return click('.does-not-exist');
}).then(null, function (e) {
equal(e.message, 'Element .does-not-exist not found.', 'Non-existent click exception caught');
});
});
// Keep this for backwards compatibility
QUnit.test('helpers can be chained to each other', function () {
expect(7);
currentRoute = 'index';
visit('/posts').click('a:first', '#comments-link').fillIn('.ember-text-field', 'hello').then(function () {
equal(currentRoute, 'comments', 'Successfully visited comments route');
equal(currentURL(), '/comments', 'Comments URL is correct');
equal((0, _emberViews.jQuery)('.ember-text-field').val(), 'hello', 'Fillin successfully works');
find('.ember-text-field').one('keypress', function (e) {
equal(e.keyCode, 13, 'keyevent chained with correct keyCode.');
equal(e.which, 13, 'keyevent chained with correct which.');
});
}).keyEvent('.ember-text-field', 'keypress', 13).visit('/posts').then(function () {
equal(currentRoute, 'posts', 'Thens can also be chained to helpers');
equal(currentURL(), '/posts', 'URL is set correct on chained helpers');
});
});
QUnit.test('helpers don\'t need to be chained', function () {
expect(5);
currentRoute = 'index';
visit('/posts');
click('a:first', '#comments-link');
fillIn('.ember-text-field', 'hello');
andThen(function () {
equal(currentRoute, 'comments', 'Successfully visited comments route');
equal(currentURL(), '/comments', 'Comments URL is correct');
equal(find('.ember-text-field').val(), 'hello', 'Fillin successfully works');
});
visit('/posts');
andThen(function () {
equal(currentRoute, 'posts');
equal(currentURL(), '/posts');
});
});
QUnit.test('Nested async helpers', function () {
expect(5);
currentRoute = 'index';
visit('/posts');
andThen(function () {
click('a:first', '#comments-link');
fillIn('.ember-text-field', 'hello');
});
andThen(function () {
equal(currentRoute, 'comments', 'Successfully visited comments route');
equal(currentURL(), '/comments', 'Comments URL is correct');
equal(find('.ember-text-field').val(), 'hello', 'Fillin successfully works');
});
visit('/posts');
andThen(function () {
equal(currentRoute, 'posts');
equal(currentURL(), '/posts');
});
});
QUnit.test('Multiple nested async helpers', function () {
expect(3);
visit('/posts');
andThen(function () {
click('a:first', '#comments-link');
fillIn('.ember-text-field', 'hello');
fillIn('.ember-text-field', 'goodbye');
});
andThen(function () {
equal(find('.ember-text-field').val(), 'goodbye', 'Fillin successfully works');
equal(currentRoute, 'comments', 'Successfully visited comments route');
equal(currentURL(), '/comments', 'Comments URL is correct');
});
});
QUnit.test('Helpers nested in thens', function () {
expect(5);
currentRoute = 'index';
visit('/posts').then(function () {
click('a:first', '#comments-link');
});
andThen(function () {
fillIn('.ember-text-field', 'hello');
});
andThen(function () {
equal(currentRoute, 'comments', 'Successfully visited comments route');
equal(currentURL(), '/comments', 'Comments URL is correct');
equal(find('.ember-text-field').val(), 'hello', 'Fillin successfully works');
});
visit('/posts');
andThen(function () {
equal(currentRoute, 'posts');
equal(currentURL(), '/posts', 'Posts URL is correct');
});
});
QUnit.test('Aborted transitions are not logged via Ember.Test.adapter#exception', function () {
expect(0);
_test.default.adapter = _qunit.default.create({
exception: function () {
ok(false, 'aborted transitions are not logged');
}
});
visit('/abort_transition');
});
QUnit.test('Unhandled exceptions are logged via Ember.Test.adapter#exception', function () {
expect(2);
var asyncHandled;
_test.default.adapter = _qunit.default.create({
exception: function (error) {
equal(error.message, 'Element .does-not-exist not found.', 'Exception successfully caught and passed to Ember.Test.adapter.exception');
asyncHandled['catch'](function () {}); // handle the rejection so it doesn't leak later.
}
});
visit('/posts');
click('.invalid-element').then(null, function (error) {
equal(error.message, 'Element .invalid-element not found.', 'Exception successfully handled in the rejection handler');
});
asyncHandled = click('.does-not-exist');
});
QUnit.test('Unhandled exceptions in `andThen` are logged via Ember.Test.adapter#exception', function () {
expect(1);
_test.default.adapter = _qunit.default.create({
exception: function (error) {
equal(error.message, 'Catch me', 'Exception successfully caught and passed to Ember.Test.adapter.exception');
}
});
visit('/posts');
andThen(function () {
throw new Error('Catch me');
});
});
QUnit.test('should not start routing on the root URL when visiting another', function () {
expect(4);
visit('/posts');
andThen(function () {
ok(find('#comments-link'), 'found comments-link');
equal(currentRoute, 'posts', 'Successfully visited posts route');
equal(currentURL(), '/posts', 'Posts URL is correct');
equal(indexHitCount, 0, 'should not hit index route when visiting another route');
});
});
QUnit.test('only enters the index route once when visiting /', function () {
expect(1);
visit('/');
andThen(function () {
equal(indexHitCount, 1, 'should hit index once when visiting /');
});
});
QUnit.test('test must not finish while asyncHelpers are pending', function () {
expect(2);
var async = 0;
var innerRan = false;
_test.default.adapter = _qunit.default.extend({
asyncStart: function () {
async++;
this._super();
},
asyncEnd: function () {
async--;
this._super();
}
}).create();
App.testHelpers.slowHelper();
andThen(function () {
innerRan = true;
});
equal(innerRan, false, 'should not have run yet');
ok(async > 0, 'should have told the adapter to pause');
if (async === 0) {
// If we failed the test, prevent zalgo from escaping and breaking
// our other tests.
_test.default.adapter.asyncStart();
_test.default.resolve().then(function () {
_test.default.adapter.asyncEnd();
});
}
});
QUnit.test('visiting a URL that causes another transition should yield the correct URL', function () {
expect(1);
visit('/redirect');
andThen(function () {
equal(currentURL(), '/comments', 'Redirected to Comments URL');
});
});
QUnit.test('visiting a URL and then visiting a second URL with a transition should yield the correct URL', function () {
expect(2);
visit('/posts');
andThen(function () {
equal(currentURL(), '/posts', 'First visited URL is correct');
});
visit('/redirect');
andThen(function () {
equal(currentURL(), '/comments', 'Redirected to Comments URL');
});
});
QUnit.module('ember-testing Acceptance – teardown');
QUnit.test('that the setup/teardown happens correct', function () {
expect(2);
(0, _emberViews.jQuery)('').appendTo('head');
(0, _emberViews.jQuery)('').appendTo('body');
(0, _emberMetal.run)(function () {
indexHitCount = 0;
App = _emberApplication.Application.create({
rootElement: '#ember-testing'
});
});
App.injectTestHelpers();
(0, _emberViews.jQuery)('#ember-testing-container, #ember-testing').remove();
ok(typeof _test.default.Promise.prototype.click === 'function');
(0, _emberMetal.run)(App, App.destroy);
equal(_test.default.Promise.prototype.click, undefined);
App = null;
_test.default.adapter = originalAdapter;
indexHitCount = 0;
});
});
enifed('ember-testing/tests/adapters/adapter_test', ['ember-metal', 'ember-testing/adapters/adapter'], function (_emberMetal, _adapter) {
'use strict';
var adapter;
QUnit.module('ember-testing Adapter', {
setup: function () {
adapter = new _adapter.default();
},
teardown: function () {
(0, _emberMetal.run)(adapter, adapter.destroy);
}
});
// Can't test these this way anymore since we have nothing to compare to
// test("asyncStart is a noop", function() {
// equal(adapter.asyncStart, K);
// });
// test("asyncEnd is a noop", function() {
// equal(adapter.asyncEnd, K);
// });
QUnit.test('exception throws', function () {
var error = 'Hai';
var thrown;
try {
adapter.exception(error);
} catch (e) {
thrown = e;
}
equal(thrown, error);
});
});
enifed('ember-testing/tests/adapters/qunit_test', ['ember-metal', 'ember-testing/adapters/qunit'], function (_emberMetal, _qunit) {
'use strict';
var adapter;
QUnit.module('ember-testing QUnitAdapter', {
setup: function () {
adapter = new _qunit.default();
},
teardown: function () {
(0, _emberMetal.run)(adapter, adapter.destroy);
}
});
QUnit.test('asyncStart calls stop', function () {
var originalStop = QUnit.stop;
try {
QUnit.stop = function () {
ok(true, 'stop called');
};
adapter.asyncStart();
} finally {
QUnit.stop = originalStop;
}
});
QUnit.test('asyncEnd calls start', function () {
var originalStart = QUnit.start;
try {
QUnit.start = function () {
ok(true, 'start called');
};
adapter.asyncEnd();
} finally {
QUnit.start = originalStart;
}
});
QUnit.test('exception causes a failing assertion', function () {
var originalOk = window.ok;
try {
window.ok = function (val, msg) {
originalOk(!val, 'ok is called with false');
originalOk(msg, '{err: "hai"}');
};
adapter.exception({ err: 'hai' });
} finally {
window.ok = originalOk;
}
});
});
enifed('ember-testing/tests/adapters_test', ['ember-metal', 'ember-testing/test', 'ember-testing/adapters/adapter', 'ember-testing/adapters/qunit', 'ember-application'], function (_emberMetal, _test, _adapter, _qunit, _emberApplication) {
'use strict';
var App, originalAdapter, originalQUnit;
QUnit.module('ember-testing Adapters', {
setup: function () {
originalAdapter = _test.default.adapter;
originalQUnit = window.QUnit;
},
teardown: function () {
if (App) {
(0, _emberMetal.run)(App, App.destroy);
App.removeTestHelpers();
App = null;
}
_test.default.adapter = originalAdapter;
window.QUnit = originalQUnit;
}
});
QUnit.test('Setting a test adapter manually', function () {
expect(1);
var CustomAdapter = _adapter.default.extend({
asyncStart: function () {
ok(true, 'Correct adapter was used');
}
});
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
_test.default.adapter = CustomAdapter.create();
App.setupForTesting();
});
_test.default.adapter.asyncStart();
});
QUnit.test('QUnitAdapter is used by default (if QUnit is available)', function () {
expect(1);
_test.default.adapter = null;
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
});
ok(_test.default.adapter instanceof _qunit.default);
});
QUnit.test('Adapter is used by default (if QUnit is not available)', function () {
expect(2);
delete window.QUnit;
_test.default.adapter = null;
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
});
ok(_test.default.adapter instanceof _adapter.default);
ok(!(_test.default.adapter instanceof _qunit.default));
});
QUnit.test('With Ember.Test.adapter set, errors in Ember.run are caught', function () {
var thrown = new Error('Boom!');
var caught = void 0;
_test.default.adapter = _qunit.default.create({
exception: function (error) {
caught = error;
}
});
(0, _emberMetal.run)(function () {
throw thrown;
});
deepEqual(caught, thrown);
});
});
enifed('ember-testing/tests/ext/rsvp_test', ['ember-testing/ext/rsvp', 'ember-testing/test/adapter', 'ember-metal', 'ember-debug'], function (_rsvp, _adapter, _emberMetal, _emberDebug) {
'use strict';
var originalTestAdapter = (0, _adapter.getAdapter)();
var originalTestingFlag = (0, _emberDebug.isTesting)();
var asyncStarted = 0;
var asyncEnded = 0;
QUnit.module('ember-testing RSVP', {
setup: function () {
(0, _emberDebug.setTesting)(true);
(0, _adapter.setAdapter)({
asyncStart: function () {
asyncStarted++;
QUnit.stop();
},
asyncEnd: function () {
asyncEnded++;
QUnit.start();
}
});
},
teardown: function () {
asyncStarted = 0;
asyncEnded = 0;
(0, _adapter.setAdapter)(originalTestAdapter);
(0, _emberDebug.setTesting)(originalTestingFlag);
}
});
QUnit.test('given `Ember.testing = true`, correctly informs the test suite about async steps', function () {
expect(19);
ok(!_emberMetal.run.currentRunLoop, 'expect no run-loop');
(0, _emberDebug.setTesting)(true);
equal(asyncStarted, 0);
equal(asyncEnded, 0);
var user = _rsvp.default.Promise.resolve({
name: 'tomster'
});
equal(asyncStarted, 0);
equal(asyncEnded, 0);
user.then(function (user) {
equal(asyncStarted, 1);
equal(asyncEnded, 1);
equal(user.name, 'tomster');
return _rsvp.default.Promise.resolve(1).then(function () {
equal(asyncStarted, 1);
equal(asyncEnded, 1);
});
}).then(function () {
equal(asyncStarted, 1);
equal(asyncEnded, 1);
return new _rsvp.default.Promise(function (resolve) {
QUnit.stop(); // raw async, we must inform the test framework manually
setTimeout(function () {
QUnit.start(); // raw async, we must inform the test framework manually
equal(asyncStarted, 1);
equal(asyncEnded, 1);
resolve({
name: 'async tomster'
});
equal(asyncStarted, 2);
equal(asyncEnded, 1);
}, 0);
});
}).then(function (user) {
equal(user.name, 'async tomster');
equal(asyncStarted, 2);
equal(asyncEnded, 2);
});
});
});
enifed('ember-testing/tests/helper_registration_test', ['ember-metal', 'ember-testing/test', 'ember-application'], function (_emberMetal, _test, _emberApplication) {
'use strict';
var App, appBooted, helperContainer;
function registerHelper() {
_test.default.registerHelper('boot', function (app) {
(0, _emberMetal.run)(app, app.advanceReadiness);
appBooted = true;
return app.testHelpers.wait();
});
}
function unregisterHelper() {
_test.default.unregisterHelper('boot');
}
var originalAdapter = _test.default.adapter;
function setupApp() {
appBooted = false;
helperContainer = {};
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
App.injectTestHelpers(helperContainer);
});
}
function destroyApp() {
if (App) {
(0, _emberMetal.run)(App, 'destroy');
App = null;
}
}
QUnit.module('Test - registerHelper/unregisterHelper', {
teardown: function () {
_test.default.adapter = originalAdapter;
destroyApp();
}
});
QUnit.test('Helper gets registered', function () {
expect(2);
registerHelper();
setupApp();
ok(App.testHelpers.boot);
ok(helperContainer.boot);
});
QUnit.test('Helper is ran when called', function (assert) {
var done = assert.async();
assert.expect(1);
registerHelper();
setupApp();
App.testHelpers.boot().then(function () {
assert.ok(appBooted);
}).finally(done);
});
QUnit.test('Helper can be unregistered', function () {
expect(4);
registerHelper();
setupApp();
ok(App.testHelpers.boot);
ok(helperContainer.boot);
unregisterHelper();
setupApp();
ok(!App.testHelpers.boot, 'once unregistered the helper is not added to App.testHelpers');
ok(!helperContainer.boot, 'once unregistered the helper is not added to the helperContainer');
});
});
enifed('ember-testing/tests/helpers_test', ['ember-routing', 'ember-runtime', 'ember-metal', 'ember-views', 'ember-glimmer', 'ember-testing/test', 'ember-testing/setup_for_testing', 'ember-application', 'ember-template-compiler', 'ember-testing/test/pending_requests', 'ember-testing/test/adapter', 'ember-testing/test/waiters', 'ember-testing/helpers', 'ember-testing/initializers'], function (_emberRouting, _emberRuntime, _emberMetal, _emberViews, _emberGlimmer, _test, _setup_for_testing, _emberApplication, _emberTemplateCompiler, _pending_requests, _adapter, _waiters) {
'use strict';
// ensure the initializer is setup
var App; // ensure that the helpers are loaded
var originalAdapter = (0, _adapter.getAdapter)();
function cleanup() {
// Teardown setupForTesting
(0, _adapter.setAdapter)(originalAdapter);
(0, _emberMetal.run)(function () {
(0, _emberViews.jQuery)(document).off('ajaxSend');
(0, _emberViews.jQuery)(document).off('ajaxComplete');
});
(0, _pending_requests.clearPendingRequests)();
// Test.waiters = null;
// Other cleanup
if (App) {
(0, _emberMetal.run)(App, App.destroy);
App.removeTestHelpers();
App = null;
}
(0, _emberGlimmer.setTemplates)({});
}
function assertHelpers(application, helperContainer, expected) {
if (!helperContainer) {
helperContainer = window;
}
if (expected === undefined) {
expected = true;
}
function checkHelperPresent(helper, expected) {
var presentInHelperContainer = !!helperContainer[helper];
var presentInTestHelpers = !!application.testHelpers[helper];
ok(presentInHelperContainer === expected, 'Expected \'' + helper + '\' to be present in the helper container (defaults to window).');
ok(presentInTestHelpers === expected, 'Expected \'' + helper + '\' to be present in App.testHelpers.');
}
checkHelperPresent('visit', expected);
checkHelperPresent('click', expected);
checkHelperPresent('keyEvent', expected);
checkHelperPresent('fillIn', expected);
checkHelperPresent('wait', expected);
checkHelperPresent('triggerEvent', expected);
}
function assertNoHelpers(application, helperContainer) {
assertHelpers(application, helperContainer, false);
}
function currentRouteName(app) {
return app.testHelpers.currentRouteName();
}
function currentPath(app) {
return app.testHelpers.currentPath();
}
function currentURL(app) {
return app.testHelpers.currentURL();
}
function setupApp() {
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
App.injectTestHelpers();
});
}
QUnit.module('ember-testing: Helper setup', {
setup: function () {
cleanup();
},
teardown: function () {
cleanup();
}
});
function registerHelper() {
_test.default.registerHelper('LeakyMcLeakLeak', function () {});
}
QUnit.test('Ember.Application#injectTestHelpers/#removeTestHelpers', function () {
App = (0, _emberMetal.run)(_emberApplication.Application, _emberApplication.Application.create);
assertNoHelpers(App);
registerHelper();
App.injectTestHelpers();
assertHelpers(App);
ok(_test.default.Promise.prototype.LeakyMcLeakLeak, 'helper in question SHOULD be present');
App.removeTestHelpers();
assertNoHelpers(App);
equal(_test.default.Promise.prototype.LeakyMcLeakLeak, undefined, 'should NOT leak test promise extensions');
});
QUnit.test('Ember.Application#setupForTesting', function () {
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
});
equal(App.__container__.lookup('router:main').location, 'none');
});
QUnit.test('Ember.Application.setupForTesting sets the application to `testing`.', function () {
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
});
equal(App.testing, true, 'Application instance is set to testing.');
});
QUnit.test('Ember.Application.setupForTesting leaves the system in a deferred state.', function () {
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
});
equal(App._readinessDeferrals, 1, 'App is in deferred state after setupForTesting.');
});
QUnit.test('App.reset() after Application.setupForTesting leaves the system in a deferred state.', function () {
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
});
equal(App._readinessDeferrals, 1, 'App is in deferred state after setupForTesting.');
App.reset();
equal(App._readinessDeferrals, 1, 'App is in deferred state after setupForTesting.');
});
QUnit.test('Ember.Application#setupForTesting attaches ajax listeners', function () {
var documentEvents = _emberViews.jQuery._data(document, 'events');
if (!documentEvents) {
documentEvents = {};
}
ok(documentEvents['ajaxSend'] === undefined, 'there are no ajaxSend listers setup prior to calling injectTestHelpers');
ok(documentEvents['ajaxComplete'] === undefined, 'there are no ajaxComplete listers setup prior to calling injectTestHelpers');
(0, _emberMetal.run)(function () {
(0, _setup_for_testing.default)();
});
documentEvents = _emberViews.jQuery._data(document, 'events');
equal(documentEvents['ajaxSend'].length, 1, 'calling injectTestHelpers registers an ajaxSend handler');
equal(documentEvents['ajaxComplete'].length, 1, 'calling injectTestHelpers registers an ajaxComplete handler');
});
QUnit.test('Ember.Application#setupForTesting attaches ajax listeners only once', function () {
var documentEvents = _emberViews.jQuery._data(document, 'events');
if (!documentEvents) {
documentEvents = {};
}
ok(documentEvents['ajaxSend'] === undefined, 'there are no ajaxSend listeners setup prior to calling injectTestHelpers');
ok(documentEvents['ajaxComplete'] === undefined, 'there are no ajaxComplete listeners setup prior to calling injectTestHelpers');
(0, _emberMetal.run)(function () {
(0, _setup_for_testing.default)();
});
(0, _emberMetal.run)(function () {
(0, _setup_for_testing.default)();
});
documentEvents = _emberViews.jQuery._data(document, 'events');
equal(documentEvents['ajaxSend'].length, 1, 'calling injectTestHelpers registers an ajaxSend handler');
equal(documentEvents['ajaxComplete'].length, 1, 'calling injectTestHelpers registers an ajaxComplete handler');
});
QUnit.test('Ember.Application#injectTestHelpers calls callbacks registered with onInjectHelpers', function () {
var injected = 0;
_test.default.onInjectHelpers(function () {
injected++;
});
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
});
equal(injected, 0, 'onInjectHelpers are not called before injectTestHelpers');
App.injectTestHelpers();
equal(injected, 1, 'onInjectHelpers are called after injectTestHelpers');
});
QUnit.test('Ember.Application#injectTestHelpers adds helpers to provided object.', function () {
var helpers = {};
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
});
App.injectTestHelpers(helpers);
assertHelpers(App, helpers);
App.removeTestHelpers();
assertNoHelpers(App, helpers);
});
QUnit.test('Ember.Application#removeTestHelpers resets the helperContainer\'s original values', function () {
var helpers = { visit: 'snazzleflabber' };
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
});
App.injectTestHelpers(helpers);
ok(helpers.visit !== 'snazzleflabber', 'helper added to container');
App.removeTestHelpers();
ok(helpers.visit === 'snazzleflabber', 'original value added back to container');
});
QUnit.module('ember-testing: Helper methods', {
setup: function () {
setupApp();
},
teardown: function () {
cleanup();
}
});
QUnit.test('`wait` respects registerWaiters', function (assert) {
assert.expect(3);
var done = assert.async();
var counter = 0;
function waiter() {
return ++counter > 2;
}
var other = 0;
function otherWaiter() {
return ++other > 2;
}
(0, _emberMetal.run)(App, App.advanceReadiness);
(0, _waiters.registerWaiter)(waiter);
(0, _waiters.registerWaiter)(otherWaiter);
App.testHelpers.wait().then(function () {
equal(waiter(), true, 'should not resolve until our waiter is ready');
(0, _waiters.unregisterWaiter)(waiter);
counter = 0;
return App.testHelpers.wait();
}).then(function () {
equal(counter, 0, 'unregistered waiter was not checked');
equal(otherWaiter(), true, 'other waiter is still registered');
}).finally(function () {
(0, _waiters.unregisterWaiter)(otherWaiter);
done();
});
});
QUnit.test('`visit` advances readiness.', function () {
expect(2);
equal(App._readinessDeferrals, 1, 'App is in deferred state after setupForTesting.');
return App.testHelpers.visit('/').then(function () {
equal(App._readinessDeferrals, 0, 'App\'s readiness was advanced by visit.');
});
});
QUnit.test('`wait` helper can be passed a resolution value', function () {
expect(4);
var promise, wait;
promise = new _emberRuntime.RSVP.Promise(function (resolve) {
(0, _emberMetal.run)(null, resolve, 'promise');
});
(0, _emberMetal.run)(App, App.advanceReadiness);
wait = App.testHelpers.wait;
return wait('text').then(function (val) {
equal(val, 'text', 'can resolve to a string');
return wait(1);
}).then(function (val) {
equal(val, 1, 'can resolve to an integer');
return wait({ age: 10 });
}).then(function (val) {
deepEqual(val, { age: 10 }, 'can resolve to an object');
return wait(promise);
}).then(function (val) {
equal(val, 'promise', 'can resolve to a promise resolution value');
});
});
QUnit.test('`click` triggers appropriate events in order', function () {
expect(5);
var click, wait, events;
App.IndexWrapperComponent = _emberGlimmer.Component.extend({
classNames: 'index-wrapper',
didInsertElement: function () {
this.$().on('mousedown focusin mouseup click', function (e) {
events.push(e.type);
});
}
});
App.XCheckboxComponent = _emberGlimmer.Component.extend({
tagName: 'input',
attributeBindings: ['type'],
type: 'checkbox',
click: function () {
events.push('click:' + this.get('checked'));
},
change: function () {
events.push('change:' + this.get('checked'));
}
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#index-wrapper}}{{input type="text"}} {{x-checkbox type="checkbox"}} {{textarea}}
{{/index-wrapper}}'));
(0, _emberMetal.run)(App, App.advanceReadiness);
click = App.testHelpers.click;
wait = App.testHelpers.wait;
return wait().then(function () {
events = [];
return click('.index-wrapper');
}).then(function () {
deepEqual(events, ['mousedown', 'mouseup', 'click'], 'fires events in order');
}).then(function () {
events = [];
return click('.index-wrapper input[type=text]');
}).then(function () {
deepEqual(events, ['mousedown', 'focusin', 'mouseup', 'click'], 'fires focus events on inputs');
}).then(function () {
events = [];
return click('.index-wrapper textarea');
}).then(function () {
deepEqual(events, ['mousedown', 'focusin', 'mouseup', 'click'], 'fires focus events on textareas');
}).then(function () {
events = [];
return click('.index-wrapper div');
}).then(function () {
deepEqual(events, ['mousedown', 'focusin', 'mouseup', 'click'], 'fires focus events on contenteditable');
}).then(function () {
events = [];
return click('.index-wrapper input[type=checkbox]');
}).then(function () {
// i.e. mousedown, mouseup, change:true, click, click:true
// Firefox differs so we can't assert the exact ordering here.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=843554.
equal(events.length, 5, 'fires click and change on checkboxes');
});
});
QUnit.test('`click` triggers native events with simulated X/Y coordinates', function () {
expect(15);
var click, wait, events;
App.IndexWrapperComponent = _emberGlimmer.Component.extend({
classNames: 'index-wrapper',
didInsertElement: function () {
var pushEvent = function (e) {
return events.push(e);
};
this.element.addEventListener('mousedown', pushEvent);
this.element.addEventListener('mouseup', pushEvent);
this.element.addEventListener('click', pushEvent);
}
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#index-wrapper}}some text{{/index-wrapper}}'));
(0, _emberMetal.run)(App, App.advanceReadiness);
click = App.testHelpers.click;
wait = App.testHelpers.wait;
return wait().then(function () {
events = [];
return click('.index-wrapper');
}).then(function () {
events.forEach(function (e) {
ok(e instanceof window.Event, 'The event is an instance of MouseEvent');
ok(typeof e.screenX === 'number' && e.screenX > 0, 'screenX is correct');
ok(typeof e.screenY === 'number' && e.screenY > 0, 'screenY is correct');
ok(typeof e.clientX === 'number' && e.clientX > 0, 'clientX is correct');
ok(typeof e.clientY === 'number' && e.clientY > 0, 'clientY is correct');
});
});
});
QUnit.test('`triggerEvent` with mouseenter triggers native events with simulated X/Y coordinates', function () {
expect(5);
var triggerEvent, wait, evt;
App.IndexWrapperComponent = _emberGlimmer.Component.extend({
classNames: 'index-wrapper',
didInsertElement: function () {
this.element.addEventListener('mouseenter', function (e) {
return evt = e;
});
}
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#index-wrapper}}some text{{/index-wrapper}}'));
(0, _emberMetal.run)(App, App.advanceReadiness);
triggerEvent = App.testHelpers.triggerEvent;
wait = App.testHelpers.wait;
return wait().then(function () {
return triggerEvent('.index-wrapper', 'mouseenter');
}).then(function () {
ok(evt instanceof window.Event, 'The event is an instance of MouseEvent');
ok(typeof evt.screenX === 'number' && evt.screenX > 0, 'screenX is correct');
ok(typeof evt.screenY === 'number' && evt.screenY > 0, 'screenY is correct');
ok(typeof evt.clientX === 'number' && evt.clientX > 0, 'clientX is correct');
ok(typeof evt.clientY === 'number' && evt.clientY > 0, 'clientY is correct');
});
});
QUnit.test('`wait` waits for outstanding timers', function () {
expect(1);
var wait_done = false;
(0, _emberMetal.run)(App, App.advanceReadiness);
_emberMetal.run.later(this, function () {
wait_done = true;
}, 500);
return App.testHelpers.wait().then(function () {
equal(wait_done, true, 'should wait for the timer to be fired.');
});
});
QUnit.test('`wait` respects registerWaiters with optional context', function () {
expect(3);
var obj = {
counter: 0,
ready: function () {
return ++this.counter > 2;
}
};
var other = 0;
function otherWaiter() {
return ++other > 2;
}
(0, _emberMetal.run)(App, App.advanceReadiness);
(0, _waiters.registerWaiter)(obj, obj.ready);
(0, _waiters.registerWaiter)(otherWaiter);
return App.testHelpers.wait().then(function () {
equal(obj.ready(), true, 'should not resolve until our waiter is ready');
(0, _waiters.unregisterWaiter)(obj, obj.ready);
obj.counter = 0;
return App.testHelpers.wait();
}).then(function () {
equal(obj.counter, 0, 'the unregistered waiter should still be at 0');
equal(otherWaiter(), true, 'other waiter should still be registered');
}).finally(function () {
(0, _waiters.unregisterWaiter)(otherWaiter);
});
});
QUnit.test('`wait` does not error if routing has not begun', function () {
expect(1);
return App.testHelpers.wait().then(function () {
ok(true, 'should not error without `visit`');
});
});
QUnit.test('`triggerEvent accepts an optional options hash without context', function () {
expect(3);
var triggerEvent, wait, event;
App.IndexWrapperComponent = _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$('.input').on('keydown change', function (e) {
event = e;
});
}
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{index-wrapper}}'));
(0, _emberGlimmer.setTemplate)('components/index-wrapper', (0, _emberTemplateCompiler.compile)('{{input type="text" id="scope" class="input"}}'));
(0, _emberMetal.run)(App, App.advanceReadiness);
triggerEvent = App.testHelpers.triggerEvent;
wait = App.testHelpers.wait;
return wait().then(function () {
return triggerEvent('.input', 'keydown', { keyCode: 13 });
}).then(function () {
equal(event.keyCode, 13, 'options were passed');
equal(event.type, 'keydown', 'correct event was triggered');
equal(event.target.getAttribute('id'), 'scope', 'triggered on the correct element');
});
});
QUnit.test('`triggerEvent can limit searching for a selector to a scope', function () {
expect(2);
var triggerEvent, wait, event;
App.IndexWrapperComponent = _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$('.input').on('blur change', function (e) {
event = e;
});
}
});
(0, _emberGlimmer.setTemplate)('components/index-wrapper', (0, _emberTemplateCompiler.compile)('{{input type="text" id="outside-scope" class="input"}}{{input type="text" id="inside-scope" class="input"}}
'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{index-wrapper}}'));
(0, _emberMetal.run)(App, App.advanceReadiness);
triggerEvent = App.testHelpers.triggerEvent;
wait = App.testHelpers.wait;
return wait().then(function () {
return triggerEvent('.input', '#limited', 'blur');
}).then(function () {
equal(event.type, 'blur', 'correct event was triggered');
equal(event.target.getAttribute('id'), 'inside-scope', 'triggered on the correct element');
});
});
QUnit.test('`triggerEvent` can be used to trigger arbitrary events', function () {
expect(2);
var triggerEvent, wait, event;
App.IndexWrapperComponent = _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$('#foo').on('blur change', function (e) {
event = e;
});
}
});
(0, _emberGlimmer.setTemplate)('components/index-wrapper', (0, _emberTemplateCompiler.compile)('{{input type="text" id="foo"}}'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{index-wrapper}}'));
(0, _emberMetal.run)(App, App.advanceReadiness);
triggerEvent = App.testHelpers.triggerEvent;
wait = App.testHelpers.wait;
return wait().then(function () {
return triggerEvent('#foo', 'blur');
}).then(function () {
equal(event.type, 'blur', 'correct event was triggered');
equal(event.target.getAttribute('id'), 'foo', 'triggered on the correct element');
});
});
QUnit.test('`fillIn` takes context into consideration', function () {
expect(2);
var fillIn, find, visit, andThen;
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{input type="text" id="first" class="current"}}
{{input type="text" id="second" class="current"}}'));
(0, _emberMetal.run)(App, App.advanceReadiness);
fillIn = App.testHelpers.fillIn;
find = App.testHelpers.find;
visit = App.testHelpers.visit;
andThen = App.testHelpers.andThen;
visit('/');
fillIn('.current', '#parent', 'current value');
return andThen(function () {
equal(find('#first').val(), 'current value');
equal(find('#second').val(), '');
});
});
QUnit.test('`fillIn` focuses on the element', function () {
expect(2);
var fillIn, find, visit, andThen, wait;
App.ApplicationRoute = _emberRouting.Route.extend({
actions: {
wasFocused: function () {
ok(true, 'focusIn event was triggered');
}
}
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{input type="text" id="first" focus-in="wasFocused"}}
'));
(0, _emberMetal.run)(App, App.advanceReadiness);
fillIn = App.testHelpers.fillIn;
find = App.testHelpers.find;
visit = App.testHelpers.visit;
andThen = App.testHelpers.andThen;
wait = App.testHelpers.wait;
visit('/');
fillIn('#first', 'current value');
andThen(function () {
equal(find('#first').val(), 'current value');
});
return wait();
});
QUnit.test('`fillIn` fires `input` and `change` events in the proper order', function () {
expect(1);
var fillIn, visit, andThen, wait;
var events = [];
App.IndexController = _emberRuntime.Controller.extend({
actions: {
oninputHandler: function (e) {
events.push(e.type);
},
onchangeHandler: function (e) {
events.push(e.type);
}
}
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)(' '));
(0, _emberMetal.run)(App, App.advanceReadiness);
fillIn = App.testHelpers.fillIn;
visit = App.testHelpers.visit;
andThen = App.testHelpers.andThen;
wait = App.testHelpers.wait;
visit('/');
fillIn('#first', 'current value');
andThen(function () {
deepEqual(events, ['input', 'change'], '`input` and `change` events are fired in the proper order');
});
return wait();
});
QUnit.test('`fillIn` only sets the value in the first matched element', function () {
var fillIn = void 0,
find = void 0,
visit = void 0,
andThen = void 0,
wait = void 0;
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)(' '));
(0, _emberMetal.run)(App, App.advanceReadiness);
fillIn = App.testHelpers.fillIn;
find = App.testHelpers.find;
visit = App.testHelpers.visit;
andThen = App.testHelpers.andThen;
wait = App.testHelpers.wait;
visit('/');
fillIn('input.in-test', 'new value');
andThen(function () {
equal(find('#first').val(), 'new value');
equal(find('#second').val(), '');
});
return wait();
});
QUnit.test('`triggerEvent accepts an optional options hash and context', function () {
expect(3);
var triggerEvent, wait, event;
App.IndexWrapperComponent = _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$('.input').on('keydown change', function (e) {
event = e;
});
}
});
(0, _emberGlimmer.setTemplate)('components/index-wrapper', (0, _emberTemplateCompiler.compile)('{{input type="text" id="outside-scope" class="input"}}{{input type="text" id="inside-scope" class="input"}}
'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{index-wrapper}}'));
(0, _emberMetal.run)(App, App.advanceReadiness);
triggerEvent = App.testHelpers.triggerEvent;
wait = App.testHelpers.wait;
return wait().then(function () {
return triggerEvent('.input', '#limited', 'keydown', { keyCode: 13 });
}).then(function () {
equal(event.keyCode, 13, 'options were passed');
equal(event.type, 'keydown', 'correct event was triggered');
equal(event.target.getAttribute('id'), 'inside-scope', 'triggered on the correct element');
});
});
QUnit.module('ember-testing debugging helpers', {
setup: function () {
setupApp();
(0, _emberMetal.run)(function () {
App.Router = _emberRouting.Router.extend({
location: 'none'
});
});
(0, _emberMetal.run)(App, 'advanceReadiness');
},
teardown: function () {
cleanup();
}
});
QUnit.test('pauseTest pauses', function () {
expect(1);
function fakeAdapterAsyncStart() {
ok(true, 'Async start should be called after waiting for other helpers');
}
App.testHelpers.andThen(function () {
_test.default.adapter.asyncStart = fakeAdapterAsyncStart;
});
App.testHelpers.pauseTest();
});
QUnit.test('resumeTest resumes paused tests', function () {
expect(1);
var pausePromise = App.testHelpers.pauseTest();
setTimeout(function () {
return App.testHelpers.resumeTest();
}, 0);
return pausePromise.then(function () {
return ok(true, 'pauseTest promise was resolved');
});
});
QUnit.test('resumeTest throws if nothing to resume', function () {
expect(1);
throws(function () {
return App.testHelpers.resumeTest();
}, /Testing has not been paused. There is nothing to resume./);
});
QUnit.module('ember-testing routing helpers', {
setup: function () {
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.setupForTesting();
App.injectTestHelpers();
App.Router = _emberRouting.Router.extend({
location: 'none'
});
App.Router.map(function () {
this.route('posts', { resetNamespace: true }, function () {
this.route('new');
});
});
});
(0, _emberMetal.run)(App, 'advanceReadiness');
},
teardown: function () {
cleanup();
}
});
QUnit.test('currentRouteName for \'/\'', function () {
expect(3);
return App.testHelpers.visit('/').then(function () {
equal(App.testHelpers.currentRouteName(), 'index', 'should equal \'index\'.');
equal(App.testHelpers.currentPath(), 'index', 'should equal \'index\'.');
equal(App.testHelpers.currentURL(), '/', 'should equal \'/\'.');
});
});
QUnit.test('currentRouteName for \'/posts\'', function () {
expect(3);
return App.testHelpers.visit('/posts').then(function () {
equal(App.testHelpers.currentRouteName(), 'posts.index', 'should equal \'posts.index\'.');
equal(App.testHelpers.currentPath(), 'posts.index', 'should equal \'posts.index\'.');
equal(App.testHelpers.currentURL(), '/posts', 'should equal \'/posts\'.');
});
});
QUnit.test('currentRouteName for \'/posts/new\'', function () {
expect(3);
return App.testHelpers.visit('/posts/new').then(function () {
equal(App.testHelpers.currentRouteName(), 'posts.new', 'should equal \'posts.new\'.');
equal(App.testHelpers.currentPath(), 'posts.new', 'should equal \'posts.new\'.');
equal(App.testHelpers.currentURL(), '/posts/new', 'should equal \'/posts/new\'.');
});
});
QUnit.module('ember-testing pendingRequests', {
setup: function () {
setupApp();
},
teardown: function () {
cleanup();
}
});
QUnit.test('pendingRequests is maintained for ajaxSend and ajaxComplete events', function () {
equal((0, _pending_requests.pendingRequests)(), 0);
var xhr = { some: 'xhr' };
(0, _emberViews.jQuery)(document).trigger('ajaxSend', xhr);
equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests was incremented');
(0, _emberViews.jQuery)(document).trigger('ajaxComplete', xhr);
equal((0, _pending_requests.pendingRequests)(), 0, 'Ember.Test.pendingRequests was decremented');
});
QUnit.test('pendingRequests is ignores ajaxComplete events from past setupForTesting calls', function () {
equal((0, _pending_requests.pendingRequests)(), 0);
var xhr = { some: 'xhr' };
(0, _emberViews.jQuery)(document).trigger('ajaxSend', xhr);
equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests was incremented');
(0, _emberMetal.run)(function () {
(0, _setup_for_testing.default)();
});
equal((0, _pending_requests.pendingRequests)(), 0, 'Ember.Test.pendingRequests was reset');
(0, _emberViews.jQuery)(document).trigger('ajaxSend', { some: 'more xhr' });
equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests was incremented');
(0, _emberViews.jQuery)(document).trigger('ajaxComplete', xhr);
equal((0, _pending_requests.pendingRequests)(), 1, 'Ember.Test.pendingRequests is not impressed with your unexpected complete');
});
QUnit.test('pendingRequests is reset by setupForTesting', function () {
(0, _pending_requests.incrementPendingRequests)();
(0, _emberMetal.run)(function () {
(0, _setup_for_testing.default)();
});
equal((0, _pending_requests.pendingRequests)(), 0, 'pendingRequests is reset');
});
QUnit.module('ember-testing async router', {
setup: function () {
cleanup();
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create();
App.Router = _emberRouting.Router.extend({
location: 'none'
});
App.Router.map(function () {
this.route('user', { resetNamespace: true }, function () {
this.route('profile');
this.route('edit');
});
});
App.UserRoute = _emberRouting.Route.extend({
model: function () {
return resolveLater();
}
});
App.UserProfileRoute = _emberRouting.Route.extend({
beforeModel: function () {
var self = this;
return resolveLater().then(function () {
self.transitionTo('user.edit');
});
}
});
// Emulates a long-running unscheduled async operation.
function resolveLater() {
var promise;
(0, _emberMetal.run)(function () {
promise = new _emberRuntime.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.
setTimeout(function () {
(0, _emberMetal.run)(function () {
resolve(_emberRuntime.Object.create({ firstName: 'Tom' }));
});
}, 20);
});
});
return promise;
}
App.setupForTesting();
});
App.injectTestHelpers();
(0, _emberMetal.run)(App, 'advanceReadiness');
},
teardown: function () {
cleanup();
}
});
QUnit.test('currentRouteName for \'/user\'', function () {
expect(4);
return App.testHelpers.visit('/user').then(function () {
equal(currentRouteName(App), 'user.index', 'should equal \'user.index\'.');
equal(currentPath(App), 'user.index', 'should equal \'user.index\'.');
equal(currentURL(App), '/user', 'should equal \'/user\'.');
equal(App.__container__.lookup('route:user').get('controller.model.firstName'), 'Tom', 'should equal \'Tom\'.');
});
});
QUnit.test('currentRouteName for \'/user/profile\'', function () {
expect(4);
return App.testHelpers.visit('/user/profile').then(function () {
equal(currentRouteName(App), 'user.edit', 'should equal \'user.edit\'.');
equal(currentPath(App), 'user.edit', 'should equal \'user.edit\'.');
equal(currentURL(App), '/user/edit', 'should equal \'/user/edit\'.');
equal(App.__container__.lookup('route:user').get('controller.model.firstName'), 'Tom', 'should equal \'Tom\'.');
});
});
var originalVisitHelper, originalFindHelper, originalWaitHelper;
QUnit.module('can override built-in helpers', {
setup: function () {
originalVisitHelper = _test.default._helpers.visit;
originalFindHelper = _test.default._helpers.find;
originalWaitHelper = _test.default._helpers.wait;
(0, _emberViews.jQuery)('').appendTo('head');
(0, _emberViews.jQuery)('').appendTo('body');
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create({
rootElement: '#ember-testing'
});
App.setupForTesting();
});
},
teardown: function () {
cleanup();
_test.default._helpers.visit = originalVisitHelper;
_test.default._helpers.find = originalFindHelper;
_test.default._helpers.wait = originalWaitHelper;
}
});
QUnit.test('can override visit helper', function () {
expect(1);
_test.default.registerHelper('visit', function () {
ok(true, 'custom visit helper was called');
});
App.injectTestHelpers();
return App.testHelpers.visit();
});
QUnit.test('can override find helper', function () {
expect(1);
_test.default.registerHelper('find', function () {
ok(true, 'custom find helper was called');
return ['not empty array'];
});
App.injectTestHelpers();
return App.testHelpers.findWithAssert('.who-cares');
});
});
enifed('ember-testing/tests/integration_test', ['ember-metal', 'ember-runtime', 'ember-views', 'ember-testing/test', 'ember-routing', 'ember-application', 'ember-template-compiler', 'ember-glimmer'], function (_emberMetal, _emberRuntime, _emberViews, _test, _emberRouting, _emberApplication, _emberTemplateCompiler, _emberGlimmer) {
'use strict';
var App, find, visit;
var originalAdapter = _test.default.adapter;
QUnit.module('ember-testing Integration', {
setup: function () {
(0, _emberViews.jQuery)('').appendTo('body');
(0, _emberMetal.run)(function () {
(0, _emberGlimmer.setTemplate)('people', (0, _emberTemplateCompiler.compile)('{{#each model as |person|}}
{{person.firstName}}
{{/each}}
'));
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
App = _emberApplication.Application.create({
rootElement: '#ember-testing'
});
App.Router.map(function () {
this.route('people', { path: '/' });
});
App.PeopleRoute = _emberRouting.Route.extend({
model: function () {
return App.Person.find();
}
});
App.PeopleController = _emberRuntime.Controller.extend({});
App.Person = _emberRuntime.Object.extend({
firstName: ''
});
App.Person.reopenClass({
find: function () {
return (0, _emberRuntime.A)();
}
});
App.setupForTesting();
});
(0, _emberMetal.run)(function () {
App.reset();
});
App.injectTestHelpers();
find = window.find;
visit = window.visit;
},
teardown: function () {
App.removeTestHelpers();
(0, _emberGlimmer.setTemplates)({});
(0, _emberViews.jQuery)('#ember-testing-container, #ember-testing').remove();
(0, _emberMetal.run)(App, App.destroy);
App = null;
_test.default.adapter = originalAdapter;
}
});
QUnit.test('template is bound to empty array of people', function () {
App.Person.find = function () {
return (0, _emberRuntime.A)();
};
(0, _emberMetal.run)(App, 'advanceReadiness');
visit('/').then(function () {
var rows = find('.name').length;
equal(rows, 0, 'successfully stubbed an empty array of people');
});
});
QUnit.test('template is bound to array of 2 people', function () {
App.Person.find = function () {
var people = (0, _emberRuntime.A)();
var first = App.Person.create({ firstName: 'x' });
var last = App.Person.create({ firstName: 'y' });
(0, _emberMetal.run)(people, people.pushObject, first);
(0, _emberMetal.run)(people, people.pushObject, last);
return people;
};
(0, _emberMetal.run)(App, 'advanceReadiness');
visit('/').then(function () {
var rows = find('.name').length;
equal(rows, 2, 'successfully stubbed a non empty array of people');
});
});
QUnit.test('template is again bound to empty array of people', function () {
App.Person.find = function () {
return (0, _emberRuntime.A)();
};
(0, _emberMetal.run)(App, 'advanceReadiness');
visit('/').then(function () {
var rows = find('.name').length;
equal(rows, 0, 'successfully stubbed another empty array of people');
});
});
QUnit.test('`visit` can be called without advancedReadiness.', function () {
App.Person.find = function () {
return (0, _emberRuntime.A)();
};
visit('/').then(function () {
var rows = find('.name').length;
equal(rows, 0, 'stubbed an empty array of people without calling advancedReadiness.');
});
});
});
enifed('ember-testing/tests/reexports_test', ['ember', 'internal-test-helpers'], function (_ember, _internalTestHelpers) {
'use strict';
QUnit.module('ember-testing reexports');
[
// 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;
}
QUnit.test('Ember.' + path + ' exports correctly', function (assert) {
(0, _internalTestHelpers.confirmExport)(_ember.default, assert, path, moduleId, exportName);
});
});
});
enifed('ember-testing/tests/simple_setup', ['ember-metal', 'ember-views'], function (_emberMetal, _emberViews) {
'use strict';
var App;
QUnit.module('Simple Testing Setup', {
teardown: function () {
if (App) {
App.removeTestHelpers();
(0, _emberViews.jQuery)('#ember-testing-container, #ember-testing').remove();
(0, _emberMetal.run)(App, 'destroy');
App = null;
}
}
});
});
enifed('ember-testing/tests/test/waiters-test', ['ember-testing/test/waiters'], function (_waiters) {
'use strict';
var Waiters = function () {
function Waiters() {
this._waiters = [];
}
Waiters.prototype.add = function () {
this._waiters.push([].concat(Array.prototype.slice.call(arguments)));
};
Waiters.prototype.register = function () {
this.forEach(function () {
_waiters.registerWaiter.apply(undefined, arguments);
});
};
Waiters.prototype.unregister = function () {
this.forEach(function () {
_waiters.unregisterWaiter.apply(undefined, arguments);
});
};
Waiters.prototype.forEach = function (callback) {
var i, args;
for (i = 0; i < this._waiters.length; i++) {
args = this._waiters[i];
callback.apply(undefined, args);
}
};
Waiters.prototype.check = function () {
this.register();
var result = (0, _waiters.checkWaiters)();
this.unregister();
return result;
};
return Waiters;
}();
QUnit.module('ember-testing: waiters', {
setup: function () {
this.waiters = new Waiters();
},
teardown: function () {
this.waiters.unregister();
}
});
QUnit.test('registering a waiter', function (assert) {
assert.expect(2);
this.waiters.add({ foo: true }, 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();
});
QUnit.test('unregistering a waiter', function (assert) {
assert.expect(2);
this.waiters.add({ foo: true }, 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)();
});
QUnit.test('checkWaiters returns false if all waiters return true', function (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');
});
QUnit.test('checkWaiters returns true if any waiters return false', function (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');
});
QUnit.test('checkWaiters short circuits after first falsey waiter', function (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');
});
QUnit.test('generateDeprecatedWaitersArray provides deprecated access to waiters array', function (assert) {
var waiter1 = function () {};
var waiter2 = function () {};
this.waiters.add(waiter1);
this.waiters.add(waiter2);
this.waiters.register();
var waiters = void 0;
expectDeprecation(function () {
waiters = (0, _waiters.generateDeprecatedWaitersArray)();
}, /Usage of `Ember.Test.waiters` is deprecated/);
assert.deepEqual(waiters, [[null, waiter1], [null, waiter2]]);
});
});
enifed('ember-utils/tests/assign_test', ['ember-utils'], function (_emberUtils) {
'use strict';
QUnit.module('Ember.assign');
QUnit.test('merging objects', function () {
var trgt = { a: 1 };
var src1 = { b: 2 };
var src2 = { c: 3 };
(0, _emberUtils.assignPolyfill)(trgt, src1, src2);
deepEqual(trgt, { a: 1, b: 2, c: 3 }, 'assign copies values from one or more source objects to a target object');
deepEqual(src1, { b: 2 }, 'assign does not change source object 1');
deepEqual(src2, { c: 3 }, 'assign does not change source object 2');
});
QUnit.test('merging objects with same property', function () {
var trgt = { a: 1, b: 1 };
(0, _emberUtils.assignPolyfill)(trgt, { a: 2, b: 2 }, { a: 3 });
deepEqual(trgt, { a: 3, b: 2 }, 'properties are overwritten by other objects that have the same properties later in the parameters order');
});
QUnit.test('null', function () {
var trgt = { a: 1 };
(0, _emberUtils.assignPolyfill)(trgt, null);
deepEqual(trgt, { a: 1 }, 'null as a source parameter is ignored');
});
QUnit.test('undefined', function () {
var trgt = { a: 1 };
(0, _emberUtils.assignPolyfill)(trgt, null);
deepEqual(trgt, { a: 1 }, 'undefined as a source parameter is ignored');
});
});
enifed('ember-utils/tests/can_invoke_test', ['ember-utils'], function (_emberUtils) {
'use strict';
var obj = void 0;
QUnit.module('Ember.canInvoke', {
setup: function () {
obj = {
foobar: 'foobar',
aMethodThatExists: function () {}
};
},
teardown: function () {
obj = undefined;
}
});
QUnit.test('should return false if the object doesn\'t exist', function () {
equal((0, _emberUtils.canInvoke)(undefined, 'aMethodThatDoesNotExist'), false);
});
QUnit.test('should return true if the method exists on the object', function () {
equal((0, _emberUtils.canInvoke)(obj, 'aMethodThatExists'), true);
});
QUnit.test('should return false if the method doesn\'t exist on the object', function () {
equal((0, _emberUtils.canInvoke)(obj, 'aMethodThatDoesNotExist'), false);
});
QUnit.test('should return false if the property exists on the object but is a non-function', function () {
equal((0, _emberUtils.canInvoke)(obj, 'foobar'), false);
});
});
enifed('ember-utils/tests/checkHasSuper_test', ['ember-environment', 'ember-utils'], function (_emberEnvironment, _emberUtils) {
'use strict';
QUnit.module('checkHasSuper');
// Only run this test on browsers that we are certain should have function
// source available. This allows the test suite to continue to pass on other
// platforms that correctly (for them) fall back to the "always wrap" code.
if (_emberEnvironment.environment.isPhantom || _emberEnvironment.environment.isChrome || _emberEnvironment.environment.isFirefox) {
QUnit.test('does not super wrap needlessly [GH #12462]', function (assert) {
assert.notOk((0, _emberUtils.checkHasSuper)(function () {}), 'empty function does not have super');
});
}
});
enifed('ember-utils/tests/generate_guid_test', ['ember-utils'], function (_emberUtils) {
'use strict';
QUnit.module('Ember.generateGuid');
QUnit.test('Prefix', function () {
ok((0, _emberUtils.generateGuid)({}, 'tyrell').indexOf('tyrell') > -1, 'guid can be prefixed');
});
});
enifed('ember-utils/tests/guid_for_test', ['ember-utils'], function (_emberUtils) {
'use strict';
QUnit.module('guidFor');
function sameGuid(a, b, message) {
equal((0, _emberUtils.guidFor)(a), (0, _emberUtils.guidFor)(b), message);
}
function diffGuid(a, b, message) {
ok((0, _emberUtils.guidFor)(a) !== (0, _emberUtils.guidFor)(b), message);
}
function nanGuid(obj) {
ok(isNaN(parseInt((0, _emberUtils.guidFor)(obj), 0)), 'guids for ' + typeof obj + 'don\'t parse to numbers');
}
QUnit.test('Object', function () {
var a = {};
sameGuid(a, a, 'same object always yields same guid');
diffGuid(a, {}, 'different objects yield different guids');
nanGuid(a);
});
QUnit.test('strings', function () {
var a = 'string A';
sameGuid(a, a, 'same string always yields same guid');
sameGuid(a, 'string A', 'identical strings always yield the same guid');
diffGuid(a, 'String B', 'different strings yield different guids');
nanGuid(a);
});
QUnit.test('numbers', function () {
var a = 23;
sameGuid(a, a, 'same numbers always yields same guid');
sameGuid(a, 23, 'identical numbers always yield the same guid');
diffGuid(a, 34, 'different numbers yield different guids');
nanGuid(a);
});
QUnit.test('numbers', function () {
var a = true;
var b = false;
sameGuid(a, a, 'same booleans always yields same guid');
sameGuid(a, true, 'identical booleans always yield the same guid');
diffGuid(a, b, 'different boolean yield different guids');
nanGuid(a);
nanGuid(b);
});
QUnit.test('null and undefined', function () {
var a = null;
var b = void 0;
sameGuid(a, a, 'null always returns the same guid');
sameGuid(b, b, 'undefined always returns the same guid');
sameGuid(a, null, 'different nulls return the same guid');
diffGuid(a, b, 'null and undefined return different guids');
nanGuid(a);
nanGuid(b);
});
QUnit.test('arrays', function () {
var a = ['a', 'b', 'c'];
sameGuid(a, a, 'same instance always yields same guid');
diffGuid(a, ['a', 'b', 'c'], 'identical arrays always yield the same guid');
diffGuid(a, ['1', '2', '3'], 'different arrays yield different guids');
nanGuid(a);
});
});
enifed('ember-utils/tests/inspect_test', ['ember-utils'], function (_emberUtils) {
'use strict';
// Symbol is not defined on pre-ES2015 runtimes, so this let's us safely test
// for it's existence (where a simple `if (Symbol)` would ReferenceError)
var HAS_NATIVE_SYMBOL = typeof Symbol === 'function';
QUnit.module('Ember.inspect');
QUnit.test('strings', function () {
equal((0, _emberUtils.inspect)('foo'), 'foo');
});
QUnit.test('numbers', function () {
equal((0, _emberUtils.inspect)(2.6), '2.6');
});
QUnit.test('null', function () {
equal((0, _emberUtils.inspect)(null), 'null');
});
QUnit.test('undefined', function () {
equal((0, _emberUtils.inspect)(undefined), 'undefined');
});
QUnit.test('true', function () {
equal((0, _emberUtils.inspect)(true), 'true');
});
QUnit.test('false', function () {
equal((0, _emberUtils.inspect)(false), 'false');
});
QUnit.test('object', function () {
equal((0, _emberUtils.inspect)({}), '{}');
equal((0, _emberUtils.inspect)({ foo: 'bar' }), '{foo: bar}');
equal((0, _emberUtils.inspect)({
foo: function () {
return this;
}
}), '{foo: function() { ... }}');
});
QUnit.test('objects without a prototype', function () {
var prototypelessObj = Object.create(null);
equal((0, _emberUtils.inspect)({ foo: prototypelessObj }), '{foo: [object Object]}');
});
QUnit.test('array', function () {
equal((0, _emberUtils.inspect)([1, 2, 3]), '[1,2,3]');
});
QUnit.test('regexp', function () {
equal((0, _emberUtils.inspect)(/regexp/), '/regexp/');
});
QUnit.test('date', function () {
var inspected = (0, _emberUtils.inspect)(new Date('Sat Apr 30 2011 13:24:11'));
ok(inspected.match(/Sat Apr 30/), 'The inspected date has its date');
ok(inspected.match(/2011/), 'The inspected date has its year');
ok(inspected.match(/13:24:11/), 'The inspected date has its time');
});
QUnit.test('inspect outputs the toString() representation of Symbols', function () {
var symbol;
if (HAS_NATIVE_SYMBOL) {
symbol = Symbol('test');
equal((0, _emberUtils.inspect)(symbol), 'Symbol(test)');
} else {
expect(0);
}
});
});
enifed('ember-utils/tests/make_array_test', ['ember-utils'], function (_emberUtils) {
'use strict';
QUnit.module('Ember.makeArray');
QUnit.test('undefined', function () {
deepEqual((0, _emberUtils.makeArray)(), []);
deepEqual((0, _emberUtils.makeArray)(undefined), []);
});
QUnit.test('null', function () {
deepEqual((0, _emberUtils.makeArray)(null), []);
});
QUnit.test('string', function () {
deepEqual((0, _emberUtils.makeArray)('lindsay'), ['lindsay']);
});
QUnit.test('number', function () {
deepEqual((0, _emberUtils.makeArray)(0), [0]);
deepEqual((0, _emberUtils.makeArray)(1), [1]);
});
QUnit.test('array', function () {
deepEqual((0, _emberUtils.makeArray)([1, 2, 42]), [1, 2, 42]);
});
QUnit.test('true', function () {
deepEqual((0, _emberUtils.makeArray)(true), [true]);
});
QUnit.test('false', function () {
deepEqual((0, _emberUtils.makeArray)(false), [false]);
});
QUnit.test('object', function () {
deepEqual((0, _emberUtils.makeArray)({}), [{}]);
});
});
enifed('ember-utils/tests/to-string-test', ['ember-utils'], function (_emberUtils) {
'use strict';
QUnit.module('ember-utils toString');
QUnit.test('toString uses an object\'s toString method when available', function () {
strictEqual((0, _emberUtils.toString)({
toString: function () {
return 'bob';
}
}), 'bob');
});
QUnit.test('toString falls back to Object.prototype.toString', function () {
var obj = Object.create(null);
strictEqual((0, _emberUtils.toString)(obj), {}.toString());
});
QUnit.test('toString does not fail when called on Arrays with objects without toString method', function () {
var obj = Object.create(null);
strictEqual((0, _emberUtils.toString)([obj, 2]), {}.toString() + ',2');
});
});
enifed('ember-utils/tests/try_invoke_test', ['ember-utils'], function (_emberUtils) {
'use strict';
var obj = void 0;
QUnit.module('Ember.tryInvoke', {
setup: function () {
obj = {
aMethodThatExists: function () {
return true;
},
aMethodThatTakesArguments: function (arg1, arg2) {
return arg1 === arg2;
}
};
},
teardown: function () {
obj = undefined;
}
});
QUnit.test('should return undefined when the object doesn\'t exist', function () {
equal((0, _emberUtils.tryInvoke)(undefined, 'aMethodThatDoesNotExist'), undefined);
});
QUnit.test('should return undefined when asked to perform a method that doesn\'t exist on the object', function () {
equal((0, _emberUtils.tryInvoke)(obj, 'aMethodThatDoesNotExist'), undefined);
});
QUnit.test('should return what the method returns when asked to perform a method that exists on the object', function () {
equal((0, _emberUtils.tryInvoke)(obj, 'aMethodThatExists'), true);
});
QUnit.test('should return what the method returns when asked to perform a method that takes arguments and exists on the object', function () {
equal((0, _emberUtils.tryInvoke)(obj, 'aMethodThatTakesArguments', [true, true]), true);
});
});
enifed('ember/tests/application_lifecycle_test', ['ember-application', 'ember-routing', 'ember-metal', 'ember-glimmer', 'ember-views', 'ember-template-compiler'], function (_emberApplication, _emberRouting, _emberMetal, _emberGlimmer, _emberViews, _emberTemplateCompiler) {
'use strict';
var App = void 0,
TEMPLATES = void 0,
appInstance = void 0,
router = void 0;
function setupApp(klass) {
(0, _emberMetal.run)(function () {
App = klass.create({
rootElement: '#qunit-fixture'
});
App.Router = App.Router.extend({
location: 'none'
});
App.deferReadiness();
appInstance = App.__deprecatedInstance__;
});
}
QUnit.module('Application Lifecycle', {
setup: function () {
TEMPLATES = (0, _emberGlimmer.getTemplates)();
setupApp(_emberApplication.Application.extend());
},
teardown: function () {
router = null;
(0, _emberMetal.run)(App, 'destroy');
(0, _emberGlimmer.setTemplates)({});
}
});
function handleURL(path) {
router = appInstance.lookup('router:main');
return (0, _emberMetal.run)(function () {
return router.handleURL(path).then(function (value) {
ok(true, 'url: `' + path + '` was handled');
return value;
}, function (reason) {
ok(false, reason);
throw reason;
});
});
}
QUnit.test('Resetting the application allows controller properties to be set when a route deactivates', function () {
App.Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
setupController: function () {
this.controllerFor('home').set('selectedMenuItem', 'home');
},
deactivate: function () {
this.controllerFor('home').set('selectedMenuItem', null);
}
});
App.ApplicationRoute = _emberRouting.Route.extend({
setupController: function () {
this.controllerFor('application').set('selectedMenuItem', 'home');
},
deactivate: function () {
this.controllerFor('application').set('selectedMenuItem', null);
}
});
appInstance.lookup('router:main');
(0, _emberMetal.run)(App, 'advanceReadiness');
handleURL('/');
equal((0, _emberRouting.controllerFor)(appInstance, 'home').get('selectedMenuItem'), 'home');
equal((0, _emberRouting.controllerFor)(appInstance, 'application').get('selectedMenuItem'), 'home');
App.reset();
equal((0, _emberRouting.controllerFor)(appInstance, 'home').get('selectedMenuItem'), null);
equal((0, _emberRouting.controllerFor)(appInstance, 'application').get('selectedMenuItem'), null);
});
QUnit.test('Destroying the application resets the router before the appInstance is destroyed', function () {
App.Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
setupController: function () {
this.controllerFor('home').set('selectedMenuItem', 'home');
},
deactivate: function () {
this.controllerFor('home').set('selectedMenuItem', null);
}
});
App.ApplicationRoute = _emberRouting.Route.extend({
setupController: function () {
this.controllerFor('application').set('selectedMenuItem', 'home');
},
deactivate: function () {
this.controllerFor('application').set('selectedMenuItem', null);
}
});
appInstance.lookup('router:main');
(0, _emberMetal.run)(App, 'advanceReadiness');
handleURL('/');
equal((0, _emberRouting.controllerFor)(appInstance, 'home').get('selectedMenuItem'), 'home');
equal((0, _emberRouting.controllerFor)(appInstance, 'application').get('selectedMenuItem'), 'home');
(0, _emberMetal.run)(App, 'destroy');
equal((0, _emberRouting.controllerFor)(appInstance, 'home').get('selectedMenuItem'), null);
equal((0, _emberRouting.controllerFor)(appInstance, 'application').get('selectedMenuItem'), null);
});
QUnit.test('Destroying a route after the router does create an undestroyed `toplevelView`', function () {
App.Router.map(function () {
this.route('home', { path: '/' });
});
(0, _emberGlimmer.setTemplates)({
index: (0, _emberTemplateCompiler.compile)('Index!'),
application: (0, _emberTemplateCompiler.compile)('Application! {{outlet}}')
});
App.IndexRoute = _emberRouting.Route.extend();
(0, _emberMetal.run)(App, 'advanceReadiness');
handleURL('/');
var router = appInstance.lookup('router:main');
var route = appInstance.lookup('route:index');
(0, _emberMetal.run)(router, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was cleared');
(0, _emberMetal.run)(route, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was not reinitialized');
(0, _emberMetal.run)(App, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was not reinitialized');
});
QUnit.test('initializers can augment an applications customEvents hash', function (assert) {
assert.expect(1);
(0, _emberMetal.run)(App, 'destroy');
var ApplicationSubclass = _emberApplication.Application.extend();
ApplicationSubclass.initializer({
name: 'customize-things',
initialize: function (application) {
application.customEvents = {
wowza: 'wowza'
};
}
});
setupApp(ApplicationSubclass);
App.FooBarComponent = _emberGlimmer.Component.extend({
wowza: function () {
assert.ok(true, 'fired the event!');
}
});
TEMPLATES['application'] = (0, _emberTemplateCompiler.compile)('{{foo-bar}}');
TEMPLATES['components/foo-bar'] = (0, _emberTemplateCompiler.compile)('
');
(0, _emberMetal.run)(App, 'advanceReadiness');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#wowza-thingy').trigger('wowza');
});
});
QUnit.test('instanceInitializers can augment an the customEvents hash', function (assert) {
assert.expect(1);
(0, _emberMetal.run)(App, 'destroy');
var ApplicationSubclass = _emberApplication.Application.extend();
ApplicationSubclass.instanceInitializer({
name: 'customize-things',
initialize: function (application) {
application.customEvents = {
herky: 'jerky'
};
}
});
setupApp(ApplicationSubclass);
App.FooBarComponent = _emberGlimmer.Component.extend({
jerky: function () {
assert.ok(true, 'fired the event!');
}
});
TEMPLATES['application'] = (0, _emberTemplateCompiler.compile)('{{foo-bar}}');
TEMPLATES['components/foo-bar'] = (0, _emberTemplateCompiler.compile)('
');
(0, _emberMetal.run)(App, 'advanceReadiness');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#herky-thingy').trigger('herky');
});
});
});
enifed('ember/tests/component_registration_test', ['ember-runtime', 'ember-metal', 'ember-application', 'ember-routing', 'ember-template-compiler', 'ember-glimmer', 'ember-views'], function (_emberRuntime, _emberMetal, _emberApplication, _emberRouting, _emberTemplateCompiler, _emberGlimmer, _emberViews) {
'use strict';
var App = void 0,
appInstance = void 0;
function prepare() {
(0, _emberGlimmer.setTemplate)('components/expand-it', (0, _emberTemplateCompiler.compile)('hello {{yield}}
'));
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('Hello world {{#expand-it}}world{{/expand-it}}'));
}
function cleanup() {
(0, _emberMetal.run)(function () {
try {
if (App) {
App.destroy();
}
App = appInstance = null;
} finally {
(0, _emberGlimmer.setTemplates)({});
}
});
}
QUnit.module('Application Lifecycle - Component Registration', {
setup: prepare,
teardown: cleanup
});
function boot(callback) {
var startURL = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '/';
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create({
name: 'App',
rootElement: '#qunit-fixture'
});
App.deferReadiness();
App.Router = _emberRouting.Router.extend({
location: 'none'
});
appInstance = App.__deprecatedInstance__;
if (callback) {
callback();
}
});
var router = appInstance.lookup('router:main');
(0, _emberMetal.run)(App, 'advanceReadiness');
(0, _emberMetal.run)(function () {
return router.handleURL(startURL);
});
}
QUnit.test('The helper becomes the body of the component', function () {
boot();
equal((0, _emberViews.jQuery)('div.ember-view > div.ember-view', '#qunit-fixture').text(), 'hello world', 'The component is composed correctly');
});
QUnit.test('If a component is registered, it is used', function () {
boot(function () {
appInstance.register('component:expand-it', _emberGlimmer.Component.extend({
classNames: 'testing123'
}));
});
equal((0, _emberViews.jQuery)('div.testing123', '#qunit-fixture').text(), 'hello world', 'The component is composed correctly');
});
QUnit.test('Late-registered components can be rendered with custom `layout` property', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('there goes {{my-hero}}
'));
boot(function () {
appInstance.register('component:my-hero', _emberGlimmer.Component.extend({
classNames: 'testing123',
layout: (0, _emberTemplateCompiler.compile)('watch him as he GOES')
}));
});
equal((0, _emberViews.jQuery)('#wrapper').text(), 'there goes watch him as he GOES', 'The component is composed correctly');
});
QUnit.test('Late-registered components can be rendered with template registered on the container', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('hello world {{sally-rutherford}}-{{#sally-rutherford}}!!!{{/sally-rutherford}}
'));
boot(function () {
appInstance.register('template:components/sally-rutherford', (0, _emberTemplateCompiler.compile)('funkytowny{{yield}}'));
appInstance.register('component:sally-rutherford', _emberGlimmer.Component);
});
equal((0, _emberViews.jQuery)('#wrapper').text(), 'hello world funkytowny-funkytowny!!!', 'The component is composed correctly');
});
QUnit.test('Late-registered components can be rendered with ONLY the template registered on the container', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('hello world {{borf-snorlax}}-{{#borf-snorlax}}!!!{{/borf-snorlax}}
'));
boot(function () {
appInstance.register('template:components/borf-snorlax', (0, _emberTemplateCompiler.compile)('goodfreakingTIMES{{yield}}'));
});
equal((0, _emberViews.jQuery)('#wrapper').text(), 'hello world goodfreakingTIMES-goodfreakingTIMES!!!', 'The component is composed correctly');
});
QUnit.test('Assigning layoutName to a component should setup the template as a layout', function () {
expect(1);
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{#my-component}}{{text}}{{/my-component}}
'));
(0, _emberGlimmer.setTemplate)('foo-bar-baz', (0, _emberTemplateCompiler.compile)('{{text}}-{{yield}}'));
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend({
text: 'inner',
layoutName: 'foo-bar-baz'
}));
});
equal((0, _emberViews.jQuery)('#wrapper').text(), 'inner-outer', 'The component is composed correctly');
});
QUnit.test('Assigning layoutName and layout to a component should use the `layout` value', function () {
expect(1);
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{#my-component}}{{text}}{{/my-component}}
'));
(0, _emberGlimmer.setTemplate)('foo-bar-baz', (0, _emberTemplateCompiler.compile)('No way!'));
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend({
text: 'inner',
layoutName: 'foo-bar-baz',
layout: (0, _emberTemplateCompiler.compile)('{{text}}-{{yield}}')
}));
});
equal((0, _emberViews.jQuery)('#wrapper').text(), 'inner-outer', 'The component is composed correctly');
});
QUnit.test('Assigning defaultLayout to a component should set it up as a layout if no layout was found [DEPRECATED]', function () {
expect(2);
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{#my-component}}{{text}}{{/my-component}}
'));
expectDeprecation(function () {
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend({
text: 'inner',
defaultLayout: (0, _emberTemplateCompiler.compile)('{{text}}-{{yield}}')
}));
});
}, /Specifying `defaultLayout` to .+ is deprecated\./);
equal((0, _emberViews.jQuery)('#wrapper').text(), 'inner-outer', 'The component is composed correctly');
});
QUnit.test('Assigning defaultLayout to a component should set it up as a layout if layout was found [DEPRECATED]', function () {
expect(2);
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{#my-component}}{{text}}{{/my-component}}
'));
(0, _emberGlimmer.setTemplate)('components/my-component', (0, _emberTemplateCompiler.compile)('{{text}}-{{yield}}'));
expectDeprecation(function () {
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend({
text: 'inner',
defaultLayout: (0, _emberTemplateCompiler.compile)('should not see this!')
}));
});
}, /Specifying `defaultLayout` to .+ is deprecated\./);
equal((0, _emberViews.jQuery)('#wrapper').text(), 'inner-outer', 'The component is composed correctly');
});
QUnit.test('Using name of component that does not exist', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{#no-good}} {{/no-good}}
'));
expectAssertion(function () {
return boot();
}, /.* named "no-good" .*/);
});
QUnit.module('Application Lifecycle - Component Context', {
setup: prepare,
teardown: cleanup
});
QUnit.test('Components with a block should have the proper content when a template is provided', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{#my-component}}{{text}}{{/my-component}}
'));
(0, _emberGlimmer.setTemplate)('components/my-component', (0, _emberTemplateCompiler.compile)('{{text}}-{{yield}}'));
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend({
text: 'inner'
}));
});
equal((0, _emberViews.jQuery)('#wrapper').text(), 'inner-outer', 'The component is composed correctly');
});
QUnit.test('Components with a block should yield the proper content without a template provided', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{#my-component}}{{text}}{{/my-component}}
'));
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend({
text: 'inner'
}));
});
equal((0, _emberViews.jQuery)('#wrapper').text(), 'outer', 'The component is composed correctly');
});
QUnit.test('Components without a block should have the proper content when a template is provided', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{my-component}}
'));
(0, _emberGlimmer.setTemplate)('components/my-component', (0, _emberTemplateCompiler.compile)('{{text}}'));
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend({
text: 'inner'
}));
});
equal((0, _emberViews.jQuery)('#wrapper').text(), 'inner', 'The component is composed correctly');
});
QUnit.test('Components without a block should have the proper content', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{my-component}}
'));
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
'text': 'outer'
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$().html('Some text inserted by jQuery');
}
}));
});
equal((0, _emberViews.jQuery)('#wrapper').text(), 'Some text inserted by jQuery', 'The component is composed correctly');
});
// The test following this one is the non-deprecated version
QUnit.test('properties of a component without a template should not collide with internal structures [DEPRECATED]', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{my-component data=foo}}
'));
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
'text': 'outer',
'foo': 'Some text inserted by jQuery'
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend({
didInsertElement: function () {
this.$().html(this.get('data'));
}
}));
});
equal((0, _emberViews.jQuery)('#wrapper').text(), 'Some text inserted by jQuery', 'The component is composed correctly');
});
QUnit.test('attrs property of a component without a template should not collide with internal structures', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{my-component attrs=foo}}
'));
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
'text': 'outer',
'foo': 'Some text inserted by jQuery'
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend({
didInsertElement: function () {
// FIXME: I'm unsure if this is even the right way to access attrs
this.$().html(this.get('attrs.attrs.value'));
}
}));
});
equal((0, _emberViews.jQuery)('#wrapper').text(), 'Some text inserted by jQuery', 'The component is composed correctly');
});
QUnit.test('Components trigger actions in the parents context when called from within a block', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{#my-component}}
Fizzbuzz {{/my-component}}
'));
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
actions: {
fizzbuzz: function () {
ok(true, 'action triggered on parent');
}
}
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend());
});
(0, _emberMetal.run)(function () {
(0, _emberViews.jQuery)('#fizzbuzz', '#wrapper').click();
});
});
QUnit.test('Components trigger actions in the components context when called from within its template', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{#my-component}}{{text}}{{/my-component}}
'));
(0, _emberGlimmer.setTemplate)('components/my-component', (0, _emberTemplateCompiler.compile)('Fizzbuzz '));
boot(function () {
appInstance.register('controller:application', _emberRuntime.Controller.extend({
actions: {
fizzbuzz: function () {
ok(false, 'action triggered on the wrong context');
}
}
}));
appInstance.register('component:my-component', _emberGlimmer.Component.extend({
actions: {
fizzbuzz: function () {
ok(true, 'action triggered on component');
}
}
}));
});
(0, _emberViews.jQuery)('#fizzbuzz', '#wrapper').click();
});
});
enifed('ember/tests/controller_test', ['ember-babel', 'ember-runtime', 'internal-test-helpers', 'ember-glimmer'], function (_emberBabel, _emberRuntime, _internalTestHelpers, _emberGlimmer) {
'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', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test Actions inside an outlet go to the associated controller'] = function (assert) {
var _this2 = this;
this.add('controller:index', _emberRuntime.Controller.extend({
actions: {
componentAction: function () {
assert.ok(true, 'controller received the action');
}
}
}));
this.addComponent('component-with-action', {
ComponentClass: _emberGlimmer.Component.extend({
classNames: ['component-with-action'],
click: function () {
this.sendAction();
}
})
});
this.addTemplate('index', '{{component-with-action action="componentAction"}}');
return this.visit('/').then(function () {
_this2.runTask(function () {
return _this2.$('.component-with-action').click();
});
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed('ember/tests/global-api-test', ['ember-metal', 'ember-runtime'], function (_emberMetal, _emberRuntime) {
'use strict';
QUnit.module('Global API Tests');
function confirmExport(property, internal) {
QUnit.test('confirm ' + property + ' is exported', function () {
var theExport = (0, _emberMetal.get)(window, property);
ok(theExport + ' is exported');
if (internal !== undefined) {
equal(theExport, internal, theExport + ' is exported properly');
}
});
}
confirmExport('Ember.DefaultResolver');
confirmExport('Ember.generateController');
confirmExport('Ember.Helper');
confirmExport('Ember.Helper.helper');
confirmExport('Ember.isArray', _emberRuntime.isArray);
});
enifed('ember/tests/helpers/helper_registration_test', ['ember-babel', 'internal-test-helpers', 'ember-runtime', 'ember-glimmer'], function (_emberBabel, _internalTestHelpers, _emberRuntime, _emberGlimmer) {
'use strict';
(0, _internalTestHelpers.moduleFor)('Application Lifecycle - Helper Registration', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test Unbound dashed helpers registered on the container can be late-invoked'] = function (assert) {
var _this2 = this;
this.addTemplate('application', '{{x-borf}} {{x-borf \'YES\'}}
');
var myHelper = (0, _emberGlimmer.helper)(function (params) {
return params[0] || 'BORF';
});
this.application.register('helper:x-borf', myHelper);
return this.visit('/').then(function () {
assert.equal(_this2.$('#wrapper').text(), 'BORF YES', 'The helper was invoked from the container');
});
};
_class.prototype['@test Bound helpers registered on the container can be late-invoked'] = function (assert) {
var _this3 = this;
this.addTemplate('application', '{{x-reverse}} {{x-reverse foo}}
');
this.add('controller:application', _emberRuntime.Controller.extend({
foo: 'alex'
}));
this.application.register('helper:x-reverse', (0, _emberGlimmer.helper)(function (_ref) {
var value = _ref[0];
return value ? value.split('').reverse().join('') : '--';
}));
return this.visit('/').then(function () {
assert.equal(_this3.$('#wrapper').text(), '-- xela', 'The bound helper was invoked from the container');
});
};
_class.prototype['@test Undashed helpers registered on the container can be invoked'] = function (assert) {
var _this4 = this;
this.addTemplate('application', '{{omg}}|{{yorp \'boo\'}}|{{yorp \'ya\'}}
');
this.application.register('helper:omg', (0, _emberGlimmer.helper)(function () {
return 'OMG';
}));
this.application.register('helper:yorp', (0, _emberGlimmer.helper)(function (_ref2) {
var value = _ref2[0];
return value;
}));
return this.visit('/').then(function () {
assert.equal(_this4.$('#wrapper').text(), 'OMG|boo|ya', 'The helper was invoked from the container');
});
};
_class.prototype['@test Helpers can receive injections'] = function (assert) {
this.addTemplate('application', '{{full-name}}
');
var serviceCalled = false;
this.add('service:name-builder', _emberRuntime.Service.extend({
build: function () {
serviceCalled = true;
}
}));
this.add('helper:full-name', _emberGlimmer.Helper.extend({
nameBuilder: _emberRuntime.inject.service('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-console', 'ember-runtime', 'ember-metal', 'ember-routing', 'ember-application', 'ember-views', 'ember-template-compiler', 'ember-glimmer', 'ember-debug'], function (_emberConsole, _emberRuntime, _emberMetal, _emberRouting, _emberApplication, _emberViews, _emberTemplateCompiler, _emberGlimmer) {
'use strict';
var Router = void 0,
App = void 0,
router = void 0,
appInstance = void 0;
function bootApplication() {
router = appInstance.lookup('router:main');
(0, _emberMetal.run)(App, 'advanceReadiness');
}
// IE includes the host name
function normalizeUrl(url) {
return url.replace(/https?:\/\/[^\/]+/, '');
}
function shouldNotBeActive(selector) {
checkActive(selector, false);
}
function shouldBeActive(selector) {
checkActive(selector, true);
}
function checkActive(selector, active) {
var classList = (0, _emberViews.jQuery)(selector, '#qunit-fixture')[0].className;
equal(classList.indexOf('active') > -1, active, selector + ' active should be ' + active.toString());
}
var updateCount = void 0,
replaceCount = void 0;
function sharedSetup() {
App = _emberApplication.Application.create({
name: 'App',
rootElement: '#qunit-fixture'
});
App.deferReadiness();
updateCount = replaceCount = 0;
App.Router.reopen({
location: _emberRouting.NoneLocation.create({
setURL: function (path) {
updateCount++;
(0, _emberMetal.set)(this, 'path', path);
},
replaceURL: function (path) {
replaceCount++;
(0, _emberMetal.set)(this, 'path', path);
}
})
});
Router = App.Router;
appInstance = App.__deprecatedInstance__;
}
QUnit.module('The {{link-to}} helper', {
setup: function () {
(0, _emberMetal.run)(function () {
sharedSetup();
(0, _emberGlimmer.setTemplate)('app', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Home {{#link-to \'about\' id=\'about-link\'}}About{{/link-to}}{{#link-to \'index\' id=\'self-link\'}}Self{{/link-to}}'));
(0, _emberGlimmer.setTemplate)('about', (0, _emberTemplateCompiler.compile)('About {{#link-to \'index\' id=\'home-link\'}}Home{{/link-to}}{{#link-to \'about\' id=\'self-link\'}}Self{{/link-to}}'));
(0, _emberGlimmer.setTemplate)('item', (0, _emberTemplateCompiler.compile)('Item {{model.name}}
{{#link-to \'index\' id=\'home-link\'}}Home{{/link-to}}'));
appInstance.unregister('router:main');
appInstance.register('router:main', Router);
});
},
teardown: function () {
(0, _emberMetal.run)(function () {
return App.destroy();
});
(0, _emberGlimmer.setTemplates)({});
(0, _emberMetal.instrumentationReset)();
}
});
QUnit.test('The {{link-to}} helper moves into the named route', function () {
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal((0, _emberViews.jQuery)('h3:contains(Home)', '#qunit-fixture').length, 1, 'The home template was rendered');
equal((0, _emberViews.jQuery)('#self-link.active', '#qunit-fixture').length, 1, 'The self-link was rendered with active class');
equal((0, _emberViews.jQuery)('#about-link:not(.active)', '#qunit-fixture').length, 1, 'The other link was rendered without active class');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-link', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('h3:contains(About)', '#qunit-fixture').length, 1, 'The about template was rendered');
equal((0, _emberViews.jQuery)('#self-link.active', '#qunit-fixture').length, 1, 'The self-link was rendered with active class');
equal((0, _emberViews.jQuery)('#home-link:not(.active)', '#qunit-fixture').length, 1, 'The other link was rendered without active class');
});
QUnit.test('The {{link-to}} helper supports URL replacement', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Home {{#link-to \'about\' id=\'about-link\' replace=true}}About{{/link-to}}'));
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal(updateCount, 0, 'precond: setURL has not been called');
equal(replaceCount, 0, 'precond: replaceURL has not been called');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-link', '#qunit-fixture').click();
});
equal(updateCount, 0, 'setURL should not be called');
equal(replaceCount, 1, 'replaceURL should be called once');
});
QUnit.test('The {{link-to}} helper supports URL replacement via replace=boundTruthyThing', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Home {{#link-to \'about\' id=\'about-link\' replace=boundTruthyThing}}About{{/link-to}}'));
App.IndexController = _emberRuntime.Controller.extend({
boundTruthyThing: true
});
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal(updateCount, 0, 'precond: setURL has not been called');
equal(replaceCount, 0, 'precond: replaceURL has not been called');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-link', '#qunit-fixture').click();
});
equal(updateCount, 0, 'setURL should not be called');
equal(replaceCount, 1, 'replaceURL should be called once');
});
QUnit.test('The {{link-to}} helper supports setting replace=boundFalseyThing', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Home {{#link-to \'about\' id=\'about-link\' replace=boundFalseyThing}}About{{/link-to}}'));
App.IndexController = _emberRuntime.Controller.extend({
boundFalseyThing: false
});
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal(updateCount, 0, 'precond: setURL has not been called');
equal(replaceCount, 0, 'precond: replaceURL has not been called');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-link', '#qunit-fixture').click();
});
equal(updateCount, 1, 'setURL should be called');
equal(replaceCount, 0, 'replaceURL should not be called');
});
// jscs:disable
QUnit.test("the {{link-to}} helper doesn't add an href when the tagName isn't 'a'", function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to \'about\' id=\'about-link\' tagName=\'div\'}}About{{/link-to}}'));
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal((0, _emberViews.jQuery)('#about-link').attr('href'), undefined, 'there is no href attribute');
});
QUnit.test("the {{link-to}} applies a 'disabled' class when disabled", function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('\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 '));
App.IndexController = _emberRuntime.Controller.extend({
shouldDisable: true,
dynamicDisabledWhen: 'shouldDisable'
});
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal((0, _emberViews.jQuery)('#about-link-static.disabled', '#qunit-fixture').length, 1, 'The static link is disabled when its disabledWhen is true');
equal((0, _emberViews.jQuery)('#about-link-dynamic.disabled', '#qunit-fixture').length, 1, 'The dynamic link is disabled when its disabledWhen is true');
(0, _emberMetal.run)(function () {
return (0, _emberMetal.set)(appInstance.lookup('controller:index'), 'dynamicDisabledWhen', false);
});
equal((0, _emberViews.jQuery)('#about-link-dynamic.disabled', '#qunit-fixture').length, 0, 'The dynamic link is re-enabled when its disabledWhen becomes false');
});
QUnit.test("the {{link-to}} doesn't apply a 'disabled' class if disabledWhen is not provided", function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to "about" id="about-link"}}About{{/link-to}}'));
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
ok(!(0, _emberViews.jQuery)('#about-link', '#qunit-fixture').hasClass('disabled'), 'The link is not disabled if disabledWhen not provided');
});
QUnit.test('the {{link-to}} helper supports a custom disabledClass', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to "about" id="about-link" disabledWhen=true disabledClass="do-not-want"}}About{{/link-to}}'));
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal((0, _emberViews.jQuery)('#about-link.do-not-want', '#qunit-fixture').length, 1, 'The link can apply a custom disabled class');
});
QUnit.test('the {{link-to}} helper supports a custom disabledClass set via bound param', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to "about" id="about-link" disabledWhen=true disabledClass=disabledClass}}About{{/link-to}}'));
Router.map(function () {
this.route('about');
});
App.IndexController = _emberRuntime.Controller.extend({
disabledClass: 'do-not-want'
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal((0, _emberViews.jQuery)('#about-link.do-not-want', '#qunit-fixture').length, 1, 'The link can apply a custom disabled class via bound param');
});
QUnit.test('the {{link-to}} helper does not respond to clicks when disabled', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to "about" id="about-link" disabledWhen=true}}About{{/link-to}}'));
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-link', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('h3:contains(About)', '#qunit-fixture').length, 0, 'Transitioning did not occur');
});
QUnit.test('the {{link-to}} helper responds to clicks according to its disabledWhen bound param', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to "about" id="about-link" disabledWhen=disabledWhen}}About{{/link-to}}'));
Router.map(function () {
this.route('about');
});
App.IndexController = _emberRuntime.Controller.extend({
disabledWhen: true
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-link', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('h3:contains(About)', '#qunit-fixture').length, 0, 'Transitioning did not occur');
(0, _emberMetal.run)(function () {
return (0, _emberMetal.set)(appInstance.lookup('controller:index'), 'disabledWhen', false);
});
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-link', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('h3:contains(About)', '#qunit-fixture').length, 1, 'Transitioning did occur when disabledWhen became false');
});
QUnit.test('The {{link-to}} helper supports a custom activeClass', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("Home {{#link-to 'about' id='about-link'}}About{{/link-to}}{{#link-to 'index' id='self-link' activeClass='zomg-active'}}Self{{/link-to}}"));
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal((0, _emberViews.jQuery)('h3:contains(Home)', '#qunit-fixture').length, 1, 'The home template was rendered');
equal((0, _emberViews.jQuery)('#self-link.zomg-active', '#qunit-fixture').length, 1, 'The self-link was rendered with active class');
equal((0, _emberViews.jQuery)('#about-link:not(.active)', '#qunit-fixture').length, 1, 'The other link was rendered without active class');
});
QUnit.test('The {{link-to}} helper supports a custom activeClass from a bound param', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Home {{#link-to \'about\' id=\'about-link\'}}About{{/link-to}}{{#link-to \'index\' id=\'self-link\' activeClass=activeClass}}Self{{/link-to}}'));
Router.map(function () {
this.route('about');
});
App.IndexController = _emberRuntime.Controller.extend({
activeClass: 'zomg-active'
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal((0, _emberViews.jQuery)('h3:contains(Home)', '#qunit-fixture').length, 1, 'The home template was rendered');
equal((0, _emberViews.jQuery)('#self-link.zomg-active', '#qunit-fixture').length, 1, 'The self-link was rendered with active class');
equal((0, _emberViews.jQuery)('#about-link:not(.active)', '#qunit-fixture').length, 1, 'The other link was rendered without active class');
});
QUnit.test("The {{link-to}} helper supports 'classNameBindings' with custom values [GH #11699]", function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Home {{#link-to \'about\' id=\'about-link\' classNameBindings=\'foo:foo-is-true:foo-is-false\'}}About{{/link-to}}'));
Router.map(function () {
this.route('about');
});
App.IndexController = _emberRuntime.Controller.extend({
foo: false
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal((0, _emberViews.jQuery)('#about-link.foo-is-false', '#qunit-fixture').length, 1, 'The about-link was rendered with the falsy class');
var controller = appInstance.lookup('controller:index');
(0, _emberMetal.run)(function () {
return controller.set('foo', true);
});
equal((0, _emberViews.jQuery)('#about-link.foo-is-true', '#qunit-fixture').length, 1, 'The about-link was rendered with the truthy class after toggling the property');
});
QUnit.test('The {{link-to}} helper supports leaving off .index for nested routes', function () {
Router.map(function () {
this.route('about', function () {
this.route('item');
});
});
(0, _emberGlimmer.setTemplate)('about', (0, _emberTemplateCompiler.compile)('About {{outlet}}'));
(0, _emberGlimmer.setTemplate)('about/index', (0, _emberTemplateCompiler.compile)("Index
"));
(0, _emberGlimmer.setTemplate)('about/item', (0, _emberTemplateCompiler.compile)("{{#link-to 'about'}}About{{/link-to}}
"));
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/about/item');
equal(normalizeUrl((0, _emberViews.jQuery)('#item a', '#qunit-fixture').attr('href')), '/about');
});
QUnit.test('The {{link-to}} helper supports currentWhen (DEPRECATED)', function () {
expectDeprecation('Usage of `currentWhen` is deprecated, use `current-when` instead.');
Router.map(function () {
this.route('index', { path: '/' }, function () {
this.route('about');
});
this.route('item');
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Home {{outlet}}'));
(0, _emberGlimmer.setTemplate)('index/about', (0, _emberTemplateCompiler.compile)("{{#link-to 'item' id='other-link' currentWhen='index'}}ITEM{{/link-to}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/about');
});
equal((0, _emberViews.jQuery)('#other-link.active', '#qunit-fixture').length, 1, 'The link is active since current-when is a parent route');
});
QUnit.test('The {{link-to}} helper supports custom, nested, current-when', function () {
Router.map(function () {
this.route('index', { path: '/' }, function () {
this.route('about');
});
this.route('item');
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Home {{outlet}}'));
(0, _emberGlimmer.setTemplate)('index/about', (0, _emberTemplateCompiler.compile)("{{#link-to 'item' id='other-link' current-when='index'}}ITEM{{/link-to}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/about');
});
equal((0, _emberViews.jQuery)('#other-link.active', '#qunit-fixture').length, 1, 'The link is active since current-when is a parent route');
});
QUnit.test('The {{link-to}} helper does not disregard current-when when it is given explicitly for a route', function () {
Router.map(function () {
this.route('index', { path: '/' }, function () {
this.route('about');
});
this.route('items', function () {
this.route('item');
});
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Home {{outlet}}'));
(0, _emberGlimmer.setTemplate)('index/about', (0, _emberTemplateCompiler.compile)("{{#link-to 'items' id='other-link' current-when='index'}}ITEM{{/link-to}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/about');
});
equal((0, _emberViews.jQuery)('#other-link.active', '#qunit-fixture').length, 1, 'The link is active when current-when is given for explicitly for a route');
});
QUnit.test('The {{link-to}} helper does not disregard current-when when it is set via a bound param', function () {
Router.map(function () {
this.route('index', { path: '/' }, function () {
this.route('about');
});
this.route('items', function () {
this.route('item');
});
});
App.IndexAboutController = _emberRuntime.Controller.extend({
currentWhen: 'index'
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Home {{outlet}}'));
(0, _emberGlimmer.setTemplate)('index/about', (0, _emberTemplateCompiler.compile)("{{#link-to 'items' id='other-link' current-when=currentWhen}}ITEM{{/link-to}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/about');
});
equal((0, _emberViews.jQuery)('#other-link.active', '#qunit-fixture').length, 1, 'The link is active when current-when is given for explicitly for a route');
});
QUnit.test('The {{link-to}} helper supports multiple current-when routes', function () {
Router.map(function () {
this.route('index', { path: '/' }, function () {
this.route('about');
});
this.route('item');
this.route('foo');
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Home {{outlet}}'));
(0, _emberGlimmer.setTemplate)('index/about', (0, _emberTemplateCompiler.compile)("{{#link-to 'item' id='link1' current-when='item index'}}ITEM{{/link-to}}"));
(0, _emberGlimmer.setTemplate)('item', (0, _emberTemplateCompiler.compile)("{{#link-to 'item' id='link2' current-when='item index'}}ITEM{{/link-to}}"));
(0, _emberGlimmer.setTemplate)('foo', (0, _emberTemplateCompiler.compile)("{{#link-to 'item' id='link3' current-when='item index'}}ITEM{{/link-to}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/about');
});
equal((0, _emberViews.jQuery)('#link1.active', '#qunit-fixture').length, 1, 'The link is active since current-when contains the parent route');
(0, _emberMetal.run)(function () {
return router.handleURL('/item');
});
equal((0, _emberViews.jQuery)('#link2.active', '#qunit-fixture').length, 1, 'The link is active since you are on the active route');
(0, _emberMetal.run)(function () {
return router.handleURL('/foo');
});
equal((0, _emberViews.jQuery)('#link3.active', '#qunit-fixture').length, 0, 'The link is not active since current-when does not contain the active route');
});
QUnit.test('The {{link-to}} helper defaults to bubbling', function () {
(0, _emberGlimmer.setTemplate)('about', (0, _emberTemplateCompiler.compile)("{{#link-to 'about.contact' id='about-contact'}}About{{/link-to}}
{{outlet}}"));
(0, _emberGlimmer.setTemplate)('about/contact', (0, _emberTemplateCompiler.compile)(""));
Router.map(function () {
this.route('about', function () {
this.route('contact');
});
});
var hidden = 0;
App.AboutRoute = _emberRouting.Route.extend({
actions: {
hide: function () {
hidden++;
}
}
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/about');
});
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-contact', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('#contact', '#qunit-fixture').text(), 'Contact', 'precond - the link worked');
equal(hidden, 1, 'The link bubbles');
});
QUnit.test('The {{link-to}} helper supports bubbles=false', function () {
(0, _emberGlimmer.setTemplate)('about', (0, _emberTemplateCompiler.compile)("{{#link-to 'about.contact' id='about-contact' bubbles=false}}About{{/link-to}}
{{outlet}}"));
(0, _emberGlimmer.setTemplate)('about/contact', (0, _emberTemplateCompiler.compile)(""));
Router.map(function () {
this.route('about', function () {
this.route('contact');
});
});
var hidden = 0;
App.AboutRoute = _emberRouting.Route.extend({
actions: {
hide: function () {
hidden++;
}
}
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/about');
});
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-contact', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('#contact', '#qunit-fixture').text(), 'Contact', 'precond - the link worked');
equal(hidden, 0, "The link didn't bubble");
});
QUnit.test('The {{link-to}} helper supports bubbles=boundFalseyThing', function () {
(0, _emberGlimmer.setTemplate)('about', (0, _emberTemplateCompiler.compile)("{{#link-to 'about.contact' id='about-contact' bubbles=boundFalseyThing}}About{{/link-to}}
{{outlet}}"));
(0, _emberGlimmer.setTemplate)('about/contact', (0, _emberTemplateCompiler.compile)(""));
App.AboutController = _emberRuntime.Controller.extend({
boundFalseyThing: false
});
Router.map(function () {
this.route('about', function () {
this.route('contact');
});
});
var hidden = 0;
App.AboutRoute = _emberRouting.Route.extend({
actions: {
hide: function () {
hidden++;
}
}
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/about');
});
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-contact', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('#contact', '#qunit-fixture').text(), 'Contact', 'precond - the link worked');
equal(hidden, 0, "The link didn't bubble");
});
QUnit.test('The {{link-to}} helper moves into the named route with context', function () {
Router.map(function () {
this.route('about');
this.route('item', { path: '/item/:id' });
});
(0, _emberGlimmer.setTemplate)('about', (0, _emberTemplateCompiler.compile)("List {{#each model as |person|}}{{#link-to 'item' person}}{{person.name}}{{/link-to}} {{/each}} {{#link-to 'index' id='home-link'}}Home{{/link-to}}"));
App.AboutRoute = _emberRouting.Route.extend({
model: function () {
return (0, _emberRuntime.A)([{ id: 'yehuda', name: 'Yehuda Katz' }, { id: 'tom', name: 'Tom Dale' }, { id: 'erik', name: 'Erik Brynroflsson' }]);
}
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/about');
});
equal((0, _emberViews.jQuery)('h3:contains(List)', '#qunit-fixture').length, 1, 'The home template was rendered');
equal(normalizeUrl((0, _emberViews.jQuery)('#home-link').attr('href')), '/', 'The home link points back at /');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('li a:contains(Yehuda)', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('h3:contains(Item)', '#qunit-fixture').length, 1, 'The item template was rendered');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'Yehuda Katz', 'The name is correct');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#home-link').click();
});
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-link').click();
});
equal(normalizeUrl((0, _emberViews.jQuery)('li a:contains(Yehuda)').attr('href')), '/item/yehuda');
equal(normalizeUrl((0, _emberViews.jQuery)('li a:contains(Tom)').attr('href')), '/item/tom');
equal(normalizeUrl((0, _emberViews.jQuery)('li a:contains(Erik)').attr('href')), '/item/erik');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('li a:contains(Erik)', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('h3:contains(Item)', '#qunit-fixture').length, 1, 'The item template was rendered');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'Erik Brynroflsson', 'The name is correct');
});
QUnit.test('The {{link-to}} helper binds some anchor html tag common attributes', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("Home {{#link-to 'index' id='self-link' title='title-attr' rel='rel-attr' tabindex='-1'}}Self{{/link-to}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
var link = (0, _emberViews.jQuery)('#self-link', '#qunit-fixture');
equal(link.attr('title'), 'title-attr', 'The self-link contains title attribute');
equal(link.attr('rel'), 'rel-attr', 'The self-link contains rel attribute');
equal(link.attr('tabindex'), '-1', 'The self-link contains tabindex attribute');
});
QUnit.test('The {{link-to}} helper supports `target` attribute', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("Home {{#link-to 'index' id='self-link' target='_blank'}}Self{{/link-to}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
var link = (0, _emberViews.jQuery)('#self-link', '#qunit-fixture');
equal(link.attr('target'), '_blank', 'The self-link contains `target` attribute');
});
QUnit.test('The {{link-to}} helper supports `target` attribute specified as a bound param', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("Home {{#link-to 'index' id='self-link' target=boundLinkTarget}}Self{{/link-to}}"));
App.IndexController = _emberRuntime.Controller.extend({
boundLinkTarget: '_blank'
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
var link = (0, _emberViews.jQuery)('#self-link', '#qunit-fixture');
equal(link.attr('target'), '_blank', 'The self-link contains `target` attribute');
});
QUnit.test('The {{link-to}} helper does not call preventDefault if `target` attribute is provided', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("Home {{#link-to 'index' id='self-link' target='_blank'}}Self{{/link-to}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
var event = _emberViews.jQuery.Event('click');
(0, _emberViews.jQuery)('#self-link', '#qunit-fixture').trigger(event);
equal(event.isDefaultPrevented(), false, 'should not preventDefault when target attribute is specified');
});
QUnit.test('The {{link-to}} helper should preventDefault when `target = _self`', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("Home {{#link-to 'index' id='self-link' target='_self'}}Self{{/link-to}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
var event = _emberViews.jQuery.Event('click');
(0, _emberViews.jQuery)('#self-link', '#qunit-fixture').trigger(event);
equal(event.isDefaultPrevented(), true, 'should preventDefault when target attribute is `_self`');
});
QUnit.test('The {{link-to}} helper should not transition if target is not equal to _self or empty', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("{{#link-to 'about' id='about-link' replace=true target='_blank'}}About{{/link-to}}"));
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#about-link', '#qunit-fixture').click();
});
notEqual(appInstance.lookup('controller:application').get('currentRouteName'), 'about', 'link-to should not transition if target is not equal to _self or empty');
});
QUnit.test('The {{link-to}} helper accepts string/numeric arguments', function () {
Router.map(function () {
this.route('filter', { path: '/filters/:filter' });
this.route('post', { path: '/post/:post_id' });
this.route('repo', { path: '/repo/:owner/:name' });
});
App.FilterController = _emberRuntime.Controller.extend({
filter: 'unpopular',
repo: _emberRuntime.Object.create({ owner: 'ember', name: 'ember.js' }),
post_id: 123
});
(0, _emberGlimmer.setTemplate)('filter', (0, _emberTemplateCompiler.compile)('{{filter}}
{{#link-to "filter" "unpopular" id="link"}}Unpopular{{/link-to}}{{#link-to "filter" filter id="path-link"}}Unpopular{{/link-to}}{{#link-to "post" post_id id="post-path-link"}}Post{{/link-to}}{{#link-to "post" 123 id="post-number-link"}}Post{{/link-to}}{{#link-to "repo" repo id="repo-object-link"}}Repo{{/link-to}}'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)(' '));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/filters/popular');
});
equal(normalizeUrl((0, _emberViews.jQuery)('#link', '#qunit-fixture').attr('href')), '/filters/unpopular');
equal(normalizeUrl((0, _emberViews.jQuery)('#path-link', '#qunit-fixture').attr('href')), '/filters/unpopular');
equal(normalizeUrl((0, _emberViews.jQuery)('#post-path-link', '#qunit-fixture').attr('href')), '/post/123');
equal(normalizeUrl((0, _emberViews.jQuery)('#post-number-link', '#qunit-fixture').attr('href')), '/post/123');
equal(normalizeUrl((0, _emberViews.jQuery)('#repo-object-link', '#qunit-fixture').attr('href')), '/repo/ember/ember.js');
});
QUnit.test("Issue 4201 - Shorthand for route.index shouldn't throw errors about context arguments", function () {
expect(2);
Router.map(function () {
this.route('lobby', function () {
this.route('index', { path: ':lobby_id' });
this.route('list');
});
});
App.LobbyIndexRoute = _emberRouting.Route.extend({
model: function (params) {
equal(params.lobby_id, 'foobar');
return params.lobby_id;
}
});
(0, _emberGlimmer.setTemplate)('lobby/index', (0, _emberTemplateCompiler.compile)("{{#link-to 'lobby' 'foobar' id='lobby-link'}}Lobby{{/link-to}}"));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)(''));
(0, _emberGlimmer.setTemplate)('lobby/list', (0, _emberTemplateCompiler.compile)("{{#link-to 'lobby' 'foobar' id='lobby-link'}}Lobby{{/link-to}}"));
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/lobby/list');
(0, _emberMetal.run)((0, _emberViews.jQuery)('#lobby-link'), 'click');
shouldBeActive('#lobby-link');
});
QUnit.test('Quoteless route param performs property lookup', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("{{#link-to 'index' id='string-link'}}string{{/link-to}}{{#link-to foo id='path-link'}}path{{/link-to}}"));
function assertEquality(href) {
equal(normalizeUrl((0, _emberViews.jQuery)('#string-link', '#qunit-fixture').attr('href')), '/');
equal(normalizeUrl((0, _emberViews.jQuery)('#path-link', '#qunit-fixture').attr('href')), href);
}
App.IndexController = _emberRuntime.Controller.extend({
foo: 'index'
});
App.Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/');
assertEquality('/');
var controller = appInstance.lookup('controller:index');
(0, _emberMetal.run)(function () {
return controller.set('foo', 'about');
});
assertEquality('/about');
});
QUnit.test('link-to with null/undefined dynamic parameters are put in a loading state', function () {
expect(19);
var oldWarn = _emberConsole.default.warn;
var warnCalled = false;
_emberConsole.default.warn = function () {
warnCalled = true;
};
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("{{#link-to destinationRoute routeContext loadingClass='i-am-loading' id='context-link'}}string{{/link-to}}{{#link-to secondRoute loadingClass=loadingClass id='static-link'}}string{{/link-to}}"));
var thing = _emberRuntime.Object.create({ id: 123 });
App.IndexController = _emberRuntime.Controller.extend({
destinationRoute: null,
routeContext: null,
loadingClass: 'i-am-loading'
});
App.AboutRoute = _emberRouting.Route.extend({
activate: function () {
ok(true, 'About was entered');
}
});
App.Router.map(function () {
this.route('thing', { path: '/thing/:thing_id' });
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/');
function assertLinkStatus($link, url) {
if (url) {
equal(normalizeUrl($link.attr('href')), url, 'loaded link-to has expected href');
ok(!$link.hasClass('i-am-loading'), 'loaded linkComponent has no loadingClass');
} else {
equal(normalizeUrl($link.attr('href')), '#', "unloaded link-to has href='#'");
ok($link.hasClass('i-am-loading'), 'loading linkComponent has loadingClass');
}
}
var $contextLink = (0, _emberViews.jQuery)('#context-link', '#qunit-fixture');
var $staticLink = (0, _emberViews.jQuery)('#static-link', '#qunit-fixture');
var controller = appInstance.lookup('controller:index');
assertLinkStatus($contextLink);
assertLinkStatus($staticLink);
(0, _emberMetal.run)(function () {
warnCalled = false;
$contextLink.click();
ok(warnCalled, 'Logger.warn was called from clicking loading link');
});
// Set the destinationRoute (context is still null).
(0, _emberMetal.run)(controller, 'set', 'destinationRoute', 'thing');
assertLinkStatus($contextLink);
// Set the routeContext to an id
(0, _emberMetal.run)(controller, 'set', 'routeContext', '456');
assertLinkStatus($contextLink, '/thing/456');
// Test that 0 isn't interpreted as falsy.
(0, _emberMetal.run)(controller, 'set', 'routeContext', 0);
assertLinkStatus($contextLink, '/thing/0');
// Set the routeContext to an object
(0, _emberMetal.run)(controller, 'set', 'routeContext', thing);
assertLinkStatus($contextLink, '/thing/123');
// Set the destinationRoute back to null.
(0, _emberMetal.run)(controller, 'set', 'destinationRoute', null);
assertLinkStatus($contextLink);
(0, _emberMetal.run)(function () {
warnCalled = false;
$staticLink.click();
ok(warnCalled, 'Logger.warn was called from clicking loading link');
});
(0, _emberMetal.run)(controller, 'set', 'secondRoute', 'about');
assertLinkStatus($staticLink, '/about');
// Click the now-active link
(0, _emberMetal.run)($staticLink, 'click');
_emberConsole.default.warn = oldWarn;
});
QUnit.test('The {{link-to}} helper refreshes href element when one of params changes', function () {
Router.map(function () {
this.route('post', { path: '/posts/:post_id' });
});
var post = _emberRuntime.Object.create({ id: '1' });
var secondPost = _emberRuntime.Object.create({ id: '2' });
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to "post" post id="post"}}post{{/link-to}}'));
App.IndexController = _emberRuntime.Controller.extend();
var indexController = appInstance.lookup('controller:index');
(0, _emberMetal.run)(function () {
return indexController.set('post', post);
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
equal(normalizeUrl((0, _emberViews.jQuery)('#post', '#qunit-fixture').attr('href')), '/posts/1', 'precond - Link has rendered href attr properly');
(0, _emberMetal.run)(function () {
return indexController.set('post', secondPost);
});
equal((0, _emberViews.jQuery)('#post', '#qunit-fixture').attr('href'), '/posts/2', 'href attr was updated after one of the params had been changed');
(0, _emberMetal.run)(function () {
return indexController.set('post', null);
});
equal((0, _emberViews.jQuery)('#post', '#qunit-fixture').attr('href'), '#', 'href attr becomes # when one of the arguments in nullified');
});
QUnit.test('The {{link-to}} helper is active when a route is active', function () {
Router.map(function () {
this.route('about', function () {
this.route('item');
});
});
(0, _emberGlimmer.setTemplate)('about', (0, _emberTemplateCompiler.compile)("{{#link-to 'about' id='about-link'}}About{{/link-to}} {{#link-to 'about.item' id='item-link'}}Item{{/link-to}} {{outlet}}
"));
(0, _emberGlimmer.setTemplate)('about/item', (0, _emberTemplateCompiler.compile)(' '));
(0, _emberGlimmer.setTemplate)('about/index', (0, _emberTemplateCompiler.compile)(' '));
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/about');
equal((0, _emberViews.jQuery)('#about-link.active', '#qunit-fixture').length, 1, 'The about route link is active');
equal((0, _emberViews.jQuery)('#item-link.active', '#qunit-fixture').length, 0, 'The item route link is inactive');
(0, _emberMetal.run)(router, 'handleURL', '/about/item');
equal((0, _emberViews.jQuery)('#about-link.active', '#qunit-fixture').length, 1, 'The about route link is active');
equal((0, _emberViews.jQuery)('#item-link.active', '#qunit-fixture').length, 1, 'The item route link is active');
});
QUnit.test("The {{link-to}} helper works in an #each'd array of string route names", function () {
Router.map(function () {
this.route('foo');
this.route('bar');
this.route('rar');
});
App.IndexController = _emberRuntime.Controller.extend({
routeNames: (0, _emberRuntime.A)(['foo', 'bar', 'rar']),
route1: 'bar',
route2: 'foo'
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#each routeNames as |routeName|}}{{#link-to routeName}}{{routeName}}{{/link-to}}{{/each}}{{#each routeNames as |r|}}{{#link-to r}}{{r}}{{/link-to}}{{/each}}{{#link-to route1}}a{{/link-to}}{{#link-to route2}}b{{/link-to}}'));
bootApplication();
function linksEqual($links, expected) {
equal($links.length, expected.length, 'Has correct number of links');
var idx = void 0,
href;
for (idx = 0; idx < $links.length; idx++) {
href = (0, _emberViews.jQuery)($links[idx]).attr('href');
// Old IE includes the whole hostname as well
equal(href.slice(-expected[idx].length), expected[idx], 'Expected link to be \'' + expected[idx] + '\', but was \'' + href + '\'');
}
}
linksEqual((0, _emberViews.jQuery)('a', '#qunit-fixture'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/bar', '/foo']);
var indexController = appInstance.lookup('controller:index');
(0, _emberMetal.run)(indexController, 'set', 'route1', 'rar');
linksEqual((0, _emberViews.jQuery)('a', '#qunit-fixture'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/rar', '/foo']);
(0, _emberMetal.run)(indexController.routeNames, 'shiftObject');
linksEqual((0, _emberViews.jQuery)('a', '#qunit-fixture'), ['/bar', '/rar', '/bar', '/rar', '/rar', '/foo']);
});
QUnit.test('The non-block form {{link-to}} helper moves into the named route', function () {
expect(3);
Router.map(function () {
this.route('contact');
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("Home {{link-to 'Contact us' 'contact' id='contact-link'}}{{#link-to 'index' id='self-link'}}Self{{/link-to}}"));
(0, _emberGlimmer.setTemplate)('contact', (0, _emberTemplateCompiler.compile)("Contact {{link-to 'Home' 'index' id='home-link'}}{{link-to 'Self' 'contact' id='self-link'}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#contact-link', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('h3:contains(Contact)', '#qunit-fixture').length, 1, 'The contact template was rendered');
equal((0, _emberViews.jQuery)('#self-link.active', '#qunit-fixture').length, 1, 'The self-link was rendered with active class');
equal((0, _emberViews.jQuery)('#home-link:not(.active)', '#qunit-fixture').length, 1, 'The other link was rendered without active class');
});
QUnit.test('The non-block form {{link-to}} helper updates the link text when it is a binding', function () {
expect(8);
Router.map(function () {
this.route('contact');
});
App.IndexController = _emberRuntime.Controller.extend({
contactName: 'Jane'
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("Home {{link-to contactName 'contact' id='contact-link'}}{{#link-to 'index' id='self-link'}}Self{{/link-to}}"));
(0, _emberGlimmer.setTemplate)('contact', (0, _emberTemplateCompiler.compile)("Contact {{link-to 'Home' 'index' id='home-link'}}{{link-to 'Self' 'contact' id='self-link'}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
var controller = appInstance.lookup('controller:index');
equal((0, _emberViews.jQuery)('#contact-link:contains(Jane)', '#qunit-fixture').length, 1, 'The link title is correctly resolved');
(0, _emberMetal.run)(function () {
return controller.set('contactName', 'Joe');
});
equal((0, _emberViews.jQuery)('#contact-link:contains(Joe)', '#qunit-fixture').length, 1, 'The link title is correctly updated when the bound property changes');
(0, _emberMetal.run)(function () {
return controller.set('contactName', 'Robert');
});
equal((0, _emberViews.jQuery)('#contact-link:contains(Robert)', '#qunit-fixture').length, 1, 'The link title is correctly updated when the bound property changes a second time');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#contact-link', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('h3:contains(Contact)', '#qunit-fixture').length, 1, 'The contact template was rendered');
equal((0, _emberViews.jQuery)('#self-link.active', '#qunit-fixture').length, 1, 'The self-link was rendered with active class');
equal((0, _emberViews.jQuery)('#home-link:not(.active)', '#qunit-fixture').length, 1, 'The other link was rendered without active class');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#home-link', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('h3:contains(Home)', '#qunit-fixture').length, 1, 'The index template was rendered');
equal((0, _emberViews.jQuery)('#contact-link:contains(Robert)', '#qunit-fixture').length, 1, 'The link title is correctly updated when the route changes');
});
QUnit.test('The non-block form {{link-to}} helper moves into the named route with context', function () {
expect(5);
Router.map(function () {
this.route('item', { path: '/item/:id' });
});
App.IndexRoute = _emberRouting.Route.extend({
model: function () {
return (0, _emberRuntime.A)([{ id: 'yehuda', name: 'Yehuda Katz' }, { id: 'tom', name: 'Tom Dale' }, { id: 'erik', name: 'Erik Brynroflsson' }]);
}
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("Home {{#each model as |person|}}{{link-to person.name 'item' person}} {{/each}} "));
(0, _emberGlimmer.setTemplate)('item', (0, _emberTemplateCompiler.compile)("Item {{model.name}}
{{#link-to 'index' id='home-link'}}Home{{/link-to}}"));
bootApplication();
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('li a:contains(Yehuda)', '#qunit-fixture').click();
});
equal((0, _emberViews.jQuery)('h3:contains(Item)', '#qunit-fixture').length, 1, 'The item template was rendered');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'Yehuda Katz', 'The name is correct');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#home-link').click();
});
equal(normalizeUrl((0, _emberViews.jQuery)('li a:contains(Yehuda)').attr('href')), '/item/yehuda');
equal(normalizeUrl((0, _emberViews.jQuery)('li a:contains(Tom)').attr('href')), '/item/tom');
equal(normalizeUrl((0, _emberViews.jQuery)('li a:contains(Erik)').attr('href')), '/item/erik');
});
QUnit.test('The non-block form {{link-to}} performs property lookup', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("{{link-to 'string' 'index' id='string-link'}}{{link-to path foo id='path-link'}}"));
function assertEquality(href) {
equal(normalizeUrl((0, _emberViews.jQuery)('#string-link', '#qunit-fixture').attr('href')), '/');
equal(normalizeUrl((0, _emberViews.jQuery)('#path-link', '#qunit-fixture').attr('href')), href);
}
App.IndexController = _emberRuntime.Controller.extend({
foo: 'index'
});
App.Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/');
assertEquality('/');
var controller = appInstance.lookup('controller:index');
(0, _emberMetal.run)(function () {
return controller.set('foo', 'about');
});
assertEquality('/about');
});
QUnit.test('The non-block form {{link-to}} protects against XSS', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)("{{link-to display 'index' id='link'}}"));
App.ApplicationController = _emberRuntime.Controller.extend({
display: 'blahzorz'
});
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/');
var controller = appInstance.lookup('controller:application');
equal((0, _emberViews.jQuery)('#link', '#qunit-fixture').text(), 'blahzorz');
(0, _emberMetal.run)(function () {
return controller.set('display', 'BLAMMO ');
});
equal((0, _emberViews.jQuery)('#link', '#qunit-fixture').text(), 'BLAMMO ');
equal((0, _emberViews.jQuery)('b', '#qunit-fixture').length, 0);
});
QUnit.test('the {{link-to}} helper calls preventDefault', function () {
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/');
var event = _emberViews.jQuery.Event('click');
(0, _emberViews.jQuery)('#about-link', '#qunit-fixture').trigger(event);
equal(event.isDefaultPrevented(), true, 'should preventDefault');
});
QUnit.test('the {{link-to}} helper does not call preventDefault if `preventDefault=false` is passed as an option', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("{{#link-to 'about' id='about-link' preventDefault=false}}About{{/link-to}}"));
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/');
var event = _emberViews.jQuery.Event('click');
(0, _emberViews.jQuery)('#about-link', '#qunit-fixture').trigger(event);
equal(event.isDefaultPrevented(), false, 'should not preventDefault');
});
QUnit.test('the {{link-to}} helper does not call preventDefault if `preventDefault=boundFalseyThing` is passed as an option', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("{{#link-to 'about' id='about-link' preventDefault=boundFalseyThing}}About{{/link-to}}"));
App.IndexController = _emberRuntime.Controller.extend({
boundFalseyThing: false
});
Router.map(function () {
this.route('about');
});
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/');
var event = _emberViews.jQuery.Event('click');
(0, _emberViews.jQuery)('#about-link', '#qunit-fixture').trigger(event);
equal(event.isDefaultPrevented(), false, 'should not preventDefault');
});
QUnit.test('the {{link-to}} helper throws a useful error if you invoke it wrong', function () {
expect(1);
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)("{{#link-to 'post'}}Post{{/link-to}}"));
Router.map(function () {
this.route('post', { path: 'post/:post_id' });
});
QUnit.throws(function () {
bootApplication();
}, /(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`)/);
});
QUnit.test('the {{link-to}} helper does not throw an error if its route has exited', function () {
expect(0);
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)("{{#link-to 'index' id='home-link'}}Home{{/link-to}}{{#link-to 'post' defaultPost id='default-post-link'}}Default Post{{/link-to}}{{#if currentPost}}{{#link-to 'post' currentPost id='current-post-link'}}Current Post{{/link-to}}{{/if}}"));
App.ApplicationController = _emberRuntime.Controller.extend({
defaultPost: { id: 1 },
postController: _emberRuntime.inject.controller('post'),
currentPost: (0, _emberMetal.alias)('postController.model')
});
App.PostController = _emberRuntime.Controller.extend();
App.PostRoute = _emberRouting.Route.extend({
model: function () {
return { id: 2 };
},
serialize: function (model) {
return { post_id: model.id };
}
});
Router.map(function () {
this.route('post', { path: 'post/:post_id' });
});
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/');
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#default-post-link', '#qunit-fixture').click();
});
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#home-link', '#qunit-fixture').click();
});
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#current-post-link', '#qunit-fixture').click();
});
(0, _emberMetal.run)(function () {
return (0, _emberViews.jQuery)('#home-link', '#qunit-fixture').click();
});
});
QUnit.test('{{link-to}} active property respects changing parent route context', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)("{{link-to 'OMG' 'things' 'omg' id='omg-link'}} " + "{{link-to 'LOL' 'things' 'lol' id='lol-link'}} "));
Router.map(function () {
this.route('things', { path: '/things/:name' }, function () {
this.route('other');
});
});
bootApplication();
(0, _emberMetal.run)(router, 'handleURL', '/things/omg');
shouldBeActive('#omg-link');
shouldNotBeActive('#lol-link');
(0, _emberMetal.run)(router, 'handleURL', '/things/omg/other');
shouldBeActive('#omg-link');
shouldNotBeActive('#lol-link');
});
QUnit.test('{{link-to}} populates href with default query param values even without query-params object', function () {
App.IndexController = _emberRuntime.Controller.extend({
queryParams: ['foo'],
foo: '123'
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("{{#link-to 'index' id='the-link'}}Index{{/link-to}}"));
bootApplication();
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/', 'link has right href');
});
QUnit.test('{{link-to}} populates href with default query param values with empty query-params object', function () {
App.IndexController = _emberRuntime.Controller.extend({
queryParams: ['foo'],
foo: '123'
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)("{{#link-to 'index' (query-params) id='the-link'}}Index{{/link-to}}"));
bootApplication();
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/', 'link has right href');
});
QUnit.test('{{link-to}} with only query-params and a block updates when route changes', function () {
Router.map(function () {
this.route('about');
});
App.ApplicationController = _emberRuntime.Controller.extend({
queryParams: ['foo', 'bar'],
foo: '123',
bar: 'yes'
});
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{#link-to (query-params foo=\'456\' bar=\'NAW\') id=\'the-link\'}}Index{{/link-to}}'));
bootApplication();
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/?bar=NAW&foo=456', 'link has right href');
(0, _emberMetal.run)(function () {
return router.handleURL('/about');
});
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/about?bar=NAW&foo=456', 'link has right href');
});
QUnit.test('Block-less {{link-to}} with only query-params updates when route changes', function () {
Router.map(function () {
this.route('about');
});
App.ApplicationController = _emberRuntime.Controller.extend({
queryParams: ['foo', 'bar'],
foo: '123',
bar: 'yes'
});
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{link-to "Index" (query-params foo=\'456\' bar=\'NAW\') id=\'the-link\'}}'));
bootApplication();
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/?bar=NAW&foo=456', 'link has right href');
(0, _emberMetal.run)(function () {
return router.handleURL('/about');
});
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/about?bar=NAW&foo=456', 'link has right href');
});
QUnit.test('The {{link-to}} helper can use dynamic params', function () {
Router.map(function () {
this.route('foo', { path: 'foo/:some/:thing' });
this.route('bar', { path: 'bar/:some/:thing/:else' });
});
var controller = void 0;
App.IndexController = _emberRuntime.Controller.extend({
init: function () {
this._super.apply(this, arguments);
controller = this;
this.dynamicLinkParams = ['foo', 'one', 'two'];
}
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('\n Home \n\n {{#link-to params=dynamicLinkParams id="dynamic-link"}}Dynamic{{/link-to}}\n '));
bootApplication();
(0, _emberMetal.run)(function () {
return router.handleURL('/');
});
var link = (0, _emberViews.jQuery)('#dynamic-link', '#qunit-fixture');
equal(link.attr('href'), '/foo/one/two');
(0, _emberMetal.run)(function () {
controller.set('dynamicLinkParams', ['bar', 'one', 'two', 'three']);
});
equal(link.attr('href'), '/bar/one/two/three');
});
QUnit.test('GJ: {{link-to}} to a parent root model hook which performs a `transitionTo` has correct active class #13256', function () {
expect(1);
Router.map(function () {
this.route('parent', function () {
this.route('child');
});
});
App.ParentRoute = _emberRouting.Route.extend({
afterModel: function () {
this.transitionTo('parent.child');
}
});
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('\n {{link-to \'Parent\' \'parent\' id=\'parent-link\'}}\n '));
bootApplication();
(0, _emberMetal.run)((0, _emberViews.jQuery)('#parent-link'), 'click');
shouldBeActive('#parent-link');
});
});
enifed('ember/tests/helpers/link_to_test/link_to_transitioning_classes_test', ['ember-runtime', 'ember-routing', 'ember-metal', 'ember-template-compiler', 'ember-application', 'ember-views', 'ember-glimmer'], function (_emberRuntime, _emberRouting, _emberMetal, _emberTemplateCompiler, _emberApplication, _emberViews, _emberGlimmer) {
'use strict';
var Router = void 0,
App = void 0,
registry = void 0,
container = void 0;
var aboutDefer = void 0,
otherDefer = void 0;
function bootApplication() {
container.lookup('router:main');
(0, _emberMetal.run)(App, 'advanceReadiness');
}
function assertHasClass(className) {
var i = 1,
$a,
shouldHaveClass;
while (i < arguments.length) {
$a = arguments[i];
shouldHaveClass = arguments[i + 1];
equal($a.hasClass(className), shouldHaveClass, $a.attr('id') + ' should ' + (shouldHaveClass ? '' : 'not ') + 'have class ' + className);
i += 2;
}
}
var updateCount = void 0,
replaceCount = void 0;
function sharedSetup() {
App = _emberApplication.Application.create({
name: 'App',
rootElement: '#qunit-fixture'
});
App.deferReadiness();
updateCount = replaceCount = 0;
App.Router.reopen({
location: _emberRouting.NoneLocation.create({
setURL: function (path) {
updateCount++;
(0, _emberMetal.set)(this, 'path', path);
},
replaceURL: function (path) {
replaceCount++;
(0, _emberMetal.set)(this, 'path', path);
}
})
});
Router = App.Router;
registry = App.__registry__;
container = App.__container__;
}
function sharedTeardown() {
(0, _emberMetal.run)(function () {
return App.destroy();
});
(0, _emberGlimmer.setTemplates)({});
}
QUnit.module('The {{link-to}} helper: .transitioning-in .transitioning-out CSS classes', {
setup: function () {
(0, _emberMetal.run)(function () {
sharedSetup();
registry.unregister('router:main');
registry.register('router:main', Router);
Router.map(function () {
this.route('about');
this.route('other');
});
App.AboutRoute = _emberRouting.Route.extend({
model: function () {
aboutDefer = _emberRuntime.RSVP.defer();
return aboutDefer.promise;
}
});
App.OtherRoute = _emberRouting.Route.extend({
model: function () {
otherDefer = _emberRuntime.RSVP.defer();
return otherDefer.promise;
}
});
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}{{link-to \'Index\' \'index\' id=\'index-link\'}}{{link-to \'About\' \'about\' id=\'about-link\'}}{{link-to \'Other\' \'other\' id=\'other-link\'}}'));
});
},
teardown: function () {
sharedTeardown();
aboutDefer = null;
}
});
QUnit.test('while a transition is underway', function () {
expect(18);
bootApplication();
var $index = (0, _emberViews.jQuery)('#index-link');
var $about = (0, _emberViews.jQuery)('#about-link');
var $other = (0, _emberViews.jQuery)('#other-link');
(0, _emberMetal.run)($about, 'click');
assertHasClass('active', $index, true, $about, false, $other, false);
assertHasClass('ember-transitioning-in', $index, false, $about, true, $other, false);
assertHasClass('ember-transitioning-out', $index, true, $about, false, $other, false);
(0, _emberMetal.run)(aboutDefer, 'resolve');
assertHasClass('active', $index, false, $about, true, $other, false);
assertHasClass('ember-transitioning-in', $index, false, $about, false, $other, false);
assertHasClass('ember-transitioning-out', $index, false, $about, false, $other, false);
});
QUnit.test('while a transition is underway with nested link-to\'s', function () {
expect(54);
Router.map(function () {
this.route('parent-route', function () {
this.route('about');
this.route('other');
});
});
App.ParentRouteAboutRoute = _emberRouting.Route.extend({
model: function () {
aboutDefer = _emberRuntime.RSVP.defer();
return aboutDefer.promise;
}
});
App.ParentRouteOtherRoute = _emberRouting.Route.extend({
model: function () {
otherDefer = _emberRuntime.RSVP.defer();
return otherDefer.promise;
}
});
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('\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 '));
bootApplication();
var $index = (0, _emberViews.jQuery)('#index-link');
var $about = (0, _emberViews.jQuery)('#about-link');
var $other = (0, _emberViews.jQuery)('#other-link');
(0, _emberMetal.run)($about, 'click');
assertHasClass('active', $index, true, $about, false, $other, false);
assertHasClass('ember-transitioning-in', $index, false, $about, true, $other, false);
assertHasClass('ember-transitioning-out', $index, true, $about, false, $other, false);
(0, _emberMetal.run)(aboutDefer, 'resolve');
assertHasClass('active', $index, false, $about, true, $other, false);
assertHasClass('ember-transitioning-in', $index, false, $about, false, $other, false);
assertHasClass('ember-transitioning-out', $index, false, $about, false, $other, false);
(0, _emberMetal.run)($other, 'click');
assertHasClass('active', $index, false, $about, true, $other, false);
assertHasClass('ember-transitioning-in', $index, false, $about, false, $other, true);
assertHasClass('ember-transitioning-out', $index, false, $about, true, $other, false);
(0, _emberMetal.run)(otherDefer, 'resolve');
assertHasClass('active', $index, false, $about, false, $other, true);
assertHasClass('ember-transitioning-in', $index, false, $about, false, $other, false);
assertHasClass('ember-transitioning-out', $index, false, $about, false, $other, false);
(0, _emberMetal.run)($about, 'click');
assertHasClass('active', $index, false, $about, false, $other, true);
assertHasClass('ember-transitioning-in', $index, false, $about, true, $other, false);
assertHasClass('ember-transitioning-out', $index, false, $about, false, $other, true);
(0, _emberMetal.run)(aboutDefer, 'resolve');
assertHasClass('active', $index, false, $about, true, $other, false);
assertHasClass('ember-transitioning-in', $index, false, $about, false, $other, false);
assertHasClass('ember-transitioning-out', $index, false, $about, false, $other, false);
});
});
enifed('ember/tests/helpers/link_to_test/link_to_with_query_params_test', ['ember-metal', 'ember-runtime', 'ember-routing', 'ember-template-compiler', 'ember-application', 'ember-views', 'ember-glimmer'], function (_emberMetal, _emberRuntime, _emberRouting, _emberTemplateCompiler, _emberApplication, _emberViews, _emberGlimmer) {
'use strict';
var Router = void 0,
App = void 0,
router = void 0,
registry = void 0,
container = void 0;
function bootApplication() {
router = container.lookup('router:main');
(0, _emberMetal.run)(App, 'advanceReadiness');
}
function shouldNotBeActive(selector) {
checkActive(selector, false);
}
function shouldBeActive(selector) {
checkActive(selector, true);
}
function checkActive(selector, active) {
var classList = (0, _emberViews.jQuery)(selector, '#qunit-fixture')[0].className;
equal(classList.indexOf('active') > -1, active, selector + ' active should be ' + active.toString());
}
var updateCount = void 0,
replaceCount = void 0;
function sharedSetup() {
App = _emberApplication.Application.create({
name: 'App',
rootElement: '#qunit-fixture'
});
App.deferReadiness();
updateCount = replaceCount = 0;
App.Router.reopen({
location: _emberRouting.NoneLocation.create({
setURL: function (path) {
updateCount++;
(0, _emberMetal.set)(this, 'path', path);
},
replaceURL: function (path) {
replaceCount++;
(0, _emberMetal.set)(this, 'path', path);
}
})
});
Router = App.Router;
registry = App.__registry__;
container = App.__container__;
}
QUnit.module('The {{link-to}} helper: invoking with query params', {
setup: function () {
(0, _emberMetal.run)(function () {
sharedSetup();
App.IndexController = _emberRuntime.Controller.extend({
queryParams: ['foo', 'bar', 'abool'],
foo: '123',
bar: 'abc',
boundThing: 'OMG',
abool: true
});
App.AboutController = _emberRuntime.Controller.extend({
queryParams: ['baz', 'bat'],
baz: 'alex',
bat: 'borf'
});
registry.unregister('router:main');
registry.register('router:main', Router);
});
},
teardown: function () {
(0, _emberMetal.run)(function () {
return App.destroy();
});
(0, _emberGlimmer.setTemplates)({});
}
});
QUnit.test('doesn\'t update controller QP properties on current route when invoked', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to \'index\' id=\'the-link\'}}Index{{/link-to}}'));
bootApplication();
(0, _emberMetal.run)((0, _emberViews.jQuery)('#the-link'), 'click');
var indexController = container.lookup('controller:index');
deepEqual(indexController.getProperties('foo', 'bar'), { foo: '123', bar: 'abc' }, 'controller QP properties not');
});
QUnit.test('doesn\'t update controller QP properties on current route when invoked (empty query-params obj)', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to \'index\' (query-params) id=\'the-link\'}}Index{{/link-to}}'));
bootApplication();
(0, _emberMetal.run)((0, _emberViews.jQuery)('#the-link'), 'click');
var indexController = container.lookup('controller:index');
deepEqual(indexController.getProperties('foo', 'bar'), { foo: '123', bar: 'abc' }, 'controller QP properties not');
});
QUnit.test('link-to with no params throws', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to id=\'the-link\'}}Index{{/link-to}}'));
expectAssertion(function () {
return bootApplication();
}, /one or more/);
});
QUnit.test('doesn\'t update controller QP properties on current route when invoked (empty query-params obj, inferred route)', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to (query-params) id=\'the-link\'}}Index{{/link-to}}'));
bootApplication();
(0, _emberMetal.run)((0, _emberViews.jQuery)('#the-link'), 'click');
var indexController = container.lookup('controller:index');
deepEqual(indexController.getProperties('foo', 'bar'), { foo: '123', bar: 'abc' }, 'controller QP properties not');
});
QUnit.test('updates controller QP properties on current route when invoked', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to \'index\' (query-params foo=\'456\') id=\'the-link\'}}Index{{/link-to}}'));
bootApplication();
(0, _emberMetal.run)((0, _emberViews.jQuery)('#the-link'), 'click');
var indexController = container.lookup('controller:index');
deepEqual(indexController.getProperties('foo', 'bar'), { foo: '456', bar: 'abc' }, 'controller QP properties updated');
});
QUnit.test('updates controller QP properties on current route when invoked (inferred route)', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to (query-params foo=\'456\') id=\'the-link\'}}Index{{/link-to}}'));
bootApplication();
(0, _emberMetal.run)((0, _emberViews.jQuery)('#the-link'), 'click');
var indexController = container.lookup('controller:index');
deepEqual(indexController.getProperties('foo', 'bar'), { foo: '456', bar: 'abc' }, 'controller QP properties updated');
});
QUnit.test('updates controller QP properties on other route after transitioning to that route', function () {
Router.map(function () {
this.route('about');
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to \'about\' (query-params baz=\'lol\') id=\'the-link\'}}About{{/link-to}}'));
bootApplication();
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/about?baz=lol');
(0, _emberMetal.run)((0, _emberViews.jQuery)('#the-link'), 'click');
var aboutController = container.lookup('controller:about');
deepEqual(aboutController.getProperties('baz', 'bat'), { baz: 'lol', bat: 'borf' }, 'about controller QP properties updated');
equal(container.lookup('controller:application').get('currentPath'), 'about');
});
QUnit.test('supplied QP properties can be bound', function () {
var indexController = container.lookup('controller:index');
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to (query-params foo=boundThing) id=\'the-link\'}}Index{{/link-to}}'));
bootApplication();
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/?foo=OMG');
(0, _emberMetal.run)(indexController, 'set', 'boundThing', 'ASL');
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/?foo=ASL');
});
QUnit.test('supplied QP properties can be bound (booleans)', function () {
var indexController = container.lookup('controller:index');
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to (query-params abool=boundThing) id=\'the-link\'}}Index{{/link-to}}'));
bootApplication();
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/?abool=OMG');
(0, _emberMetal.run)(indexController, 'set', 'boundThing', false);
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/?abool=false');
(0, _emberMetal.run)((0, _emberViews.jQuery)('#the-link'), 'click');
deepEqual(indexController.getProperties('foo', 'bar', 'abool'), { foo: '123', bar: 'abc', abool: false });
});
QUnit.test('href updates when unsupplied controller QP props change', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#link-to (query-params foo=\'lol\') id=\'the-link\'}}Index{{/link-to}}'));
bootApplication();
var indexController = container.lookup('controller:index');
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/?foo=lol');
(0, _emberMetal.run)(indexController, 'set', 'bar', 'BORF');
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/?bar=BORF&foo=lol');
(0, _emberMetal.run)(indexController, 'set', 'foo', 'YEAH');
equal((0, _emberViews.jQuery)('#the-link').attr('href'), '/?bar=BORF&foo=lol');
});
QUnit.test('The {{link-to}} with only query params always transitions to the current route with the query params applied', function () {
// Test harness for bug #12033
(0, _emberGlimmer.setTemplate)('cars', (0, _emberTemplateCompiler.compile)('\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 '));
(0, _emberGlimmer.setTemplate)('cars/create', (0, _emberTemplateCompiler.compile)('{{#link-to \'cars\' id=\'close-link\'}}Close create form{{/link-to}}'));
Router.map(function () {
this.route('cars', function () {
this.route('create');
});
});
App.CarsController = _emberRuntime.Controller.extend({
queryParams: ['page'],
page: 1
});
bootApplication();
var carsController = container.lookup('controller:cars');
(0, _emberMetal.run)(function () {
return router.handleURL('/cars/create');
});
(0, _emberMetal.run)(function () {
equal(router.currentRouteName, 'cars.create');
(0, _emberViews.jQuery)('#close-link').click();
});
(0, _emberMetal.run)(function () {
equal(router.currentRouteName, 'cars.index');
equal(router.get('url'), '/cars');
equal(carsController.get('page'), 1, 'The page query-param is 1');
(0, _emberViews.jQuery)('#page2-link').click();
});
(0, _emberMetal.run)(function () {
equal(router.currentRouteName, 'cars.index', 'The active route is still cars');
equal(router.get('url'), '/cars?page=2', 'The url has been updated');
equal(carsController.get('page'), 2, 'The query params have been updated');
});
});
QUnit.test('The {{link-to}} applies activeClass when query params are not changed', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('\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 '));
(0, _emberGlimmer.setTemplate)('search', (0, _emberTemplateCompiler.compile)('\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 '));
(0, _emberGlimmer.setTemplate)('search/results', (0, _emberTemplateCompiler.compile)('\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 '));
Router.map(function () {
this.route('search', function () {
this.route('results');
});
});
App.SearchController = _emberRuntime.Controller.extend({
queryParams: ['search', 'archive'],
search: '',
archive: false
});
App.SearchResultsController = _emberRuntime.Controller.extend({
queryParams: ['sort', 'showDetails'],
sort: 'title',
showDetails: true
});
bootApplication();
//Basic tests
shouldNotBeActive('#cat-link');
shouldNotBeActive('#dog-link');
(0, _emberMetal.run)(router, 'handleURL', '/?foo=cat');
shouldBeActive('#cat-link');
shouldNotBeActive('#dog-link');
(0, _emberMetal.run)(router, 'handleURL', '/?foo=dog');
shouldBeActive('#dog-link');
shouldNotBeActive('#cat-link');
shouldBeActive('#change-nothing');
//Multiple params
(0, _emberMetal.run)(function () {
return router.handleURL('/search?search=same');
});
shouldBeActive('#same-search');
shouldNotBeActive('#change-search');
shouldNotBeActive('#same-search-add-archive');
shouldNotBeActive('#only-add-archive');
shouldNotBeActive('#remove-one');
(0, _emberMetal.run)(function () {
return router.handleURL('/search?search=same&archive=true');
});
shouldBeActive('#both-same');
shouldNotBeActive('#change-one');
//Nested Controllers
(0, _emberMetal.run)(function () {
// Note: this is kind of a strange case; sort's default value is 'title',
// so this URL shouldn't have been generated in the first place, but
// we should also be able to gracefully handle these cases.
router.handleURL('/search/results?search=same&sort=title&showDetails=true');
});
//shouldBeActive('#same-sort-child-only');
shouldBeActive('#same-search-parent-only');
shouldNotBeActive('#change-search-parent-only');
shouldBeActive('#same-search-same-sort-child-and-parent');
shouldNotBeActive('#same-search-different-sort-child-and-parent');
shouldNotBeActive('#change-search-same-sort-child-and-parent');
});
QUnit.test('The {{link-to}} applies active class when query-param is number', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('\n {{#link-to (query-params page=pageNumber) id=\'page-link\'}}Index{{/link-to}}\n '));
App.IndexController = _emberRuntime.Controller.extend({
queryParams: ['page'],
page: 1,
pageNumber: 5
});
bootApplication();
shouldNotBeActive('#page-link');
(0, _emberMetal.run)(router, 'handleURL', '/?page=5');
shouldBeActive('#page-link');
});
QUnit.test('The {{link-to}} applies active class when query-param is array', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('\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 '));
App.IndexController = _emberRuntime.Controller.extend({
queryParams: ['pages'],
pages: [],
pagesArray: [1, 2],
biggerArray: [1, 2, 3],
emptyArray: []
});
bootApplication();
shouldNotBeActive('#array-link');
(0, _emberMetal.run)(router, 'handleURL', '/?pages=%5B1%2C2%5D');
shouldBeActive('#array-link');
shouldNotBeActive('#bigger-link');
shouldNotBeActive('#empty-link');
(0, _emberMetal.run)(router, 'handleURL', '/?pages=%5B2%2C1%5D');
shouldNotBeActive('#array-link');
shouldNotBeActive('#bigger-link');
shouldNotBeActive('#empty-link');
(0, _emberMetal.run)(router, 'handleURL', '/?pages=%5B1%2C2%2C3%5D');
shouldBeActive('#bigger-link');
shouldNotBeActive('#array-link');
shouldNotBeActive('#empty-link');
});
QUnit.test('The {{link-to}} helper applies active class to parent route', function () {
App.Router.map(function () {
this.route('parent', function () {
this.route('child');
});
});
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('\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 '));
App.ParentChildController = _emberRuntime.Controller.extend({
queryParams: ['foo'],
foo: 'bar'
});
bootApplication();
shouldNotBeActive('#parent-link');
shouldNotBeActive('#parent-child-link');
shouldNotBeActive('#parent-link-qp');
(0, _emberMetal.run)(router, 'handleURL', '/parent/child?foo=dog');
shouldBeActive('#parent-link');
shouldNotBeActive('#parent-link-qp');
});
QUnit.test('The {{link-to}} helper disregards query-params in activeness computation when current-when specified', function () {
App.Router.map(function () {
this.route('parent');
});
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('\n {{#link-to \'parent\' (query-params page=1) current-when=\'parent\' id=\'app-link\'}}Parent{{/link-to}} {{outlet}}\n '));
(0, _emberGlimmer.setTemplate)('parent', (0, _emberTemplateCompiler.compile)('\n {{#link-to \'parent\' (query-params page=1) current-when=\'parent\' id=\'parent-link\'}}Parent{{/link-to}} {{outlet}}\n '));
App.ParentController = _emberRuntime.Controller.extend({
queryParams: ['page'],
page: 1
});
bootApplication();
equal((0, _emberViews.jQuery)('#app-link').attr('href'), '/parent');
shouldNotBeActive('#app-link');
(0, _emberMetal.run)(router, 'handleURL', '/parent?page=2');
equal((0, _emberViews.jQuery)('#app-link').attr('href'), '/parent');
shouldBeActive('#app-link');
equal((0, _emberViews.jQuery)('#parent-link').attr('href'), '/parent');
shouldBeActive('#parent-link');
var parentController = container.lookup('controller:parent');
equal(parentController.get('page'), 2);
(0, _emberMetal.run)(parentController, 'set', 'page', 3);
equal(router.get('location.path'), '/parent?page=3');
shouldBeActive('#app-link');
shouldBeActive('#parent-link');
(0, _emberViews.jQuery)('#app-link').click();
equal(router.get('location.path'), '/parent');
});
QUnit.test('link-to default query params while in active transition regression test', function () {
App.Router.map(function () {
this.route('foos');
this.route('bars');
});
var foos = _emberRuntime.RSVP.defer();
var bars = _emberRuntime.RSVP.defer();
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('\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 '));
App.FoosController = _emberRuntime.Controller.extend({
queryParams: ['status'],
baz: false
});
App.FoosRoute = _emberRouting.Route.extend({
model: function () {
return foos.promise;
}
});
App.BarsController = _emberRuntime.Controller.extend({
queryParams: ['status'],
quux: false
});
App.BarsRoute = _emberRouting.Route.extend({
model: function () {
return bars.promise;
}
});
bootApplication();
equal((0, _emberViews.jQuery)('#foos-link').attr('href'), '/foos');
equal((0, _emberViews.jQuery)('#baz-foos-link').attr('href'), '/foos?baz=true');
equal((0, _emberViews.jQuery)('#bars-link').attr('href'), '/bars?quux=true');
equal(router.get('location.path'), '');
shouldNotBeActive('#foos-link');
shouldNotBeActive('#baz-foos-link');
shouldNotBeActive('#bars-link');
(0, _emberMetal.run)((0, _emberViews.jQuery)('#bars-link'), 'click');
shouldNotBeActive('#bars-link');
(0, _emberMetal.run)((0, _emberViews.jQuery)('#foos-link'), 'click');
shouldNotBeActive('#foos-link');
(0, _emberMetal.run)(foos, 'resolve');
equal(router.get('location.path'), '/foos');
shouldBeActive('#foos-link');
});
});
enifed('ember/tests/homepage_example_test', ['ember-babel', 'ember-routing', 'ember-metal', 'ember-runtime', 'internal-test-helpers'], function (_emberBabel, _emberRouting, _emberMetal, _emberRuntime, _internalTestHelpers) {
'use strict';
(0, _internalTestHelpers.moduleFor)('The example renders correctly', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test Render index template into application outlet'] = function (assert) {
var _this2 = this;
this.addTemplate('application', '{{outlet}}');
this.addTemplate('index', 'People {{#each model as |person|}}Hello, {{person.fullName}} ! {{/each}} ');
var Person = _emberRuntime.Object.extend({
firstName: null,
lastName: null,
fullName: (0, _emberMetal.computed)('firstName', 'lastName', function () {
return this.get('firstName') + ' ' + this.get('lastName');
})
});
this.add('route:index', _emberRouting.Route.extend({
model: function () {
return (0, _emberRuntime.A)([Person.create({ firstName: 'Tom', lastName: 'Dale' }), Person.create({ firstName: 'Yehuda', lastName: 'Katz' })]);
}
}));
return this.visit('/').then(function () {
var $ = _this2.$();
assert.equal($.find('h1:contains(People)').length, 1);
assert.equal($.find('li').length, 2);
assert.equal($.find('li:nth-of-type(1)').text(), 'Hello, Tom Dale!');
assert.equal($.find('li:nth-of-type(2)').text(), 'Hello, Yehuda Katz!');
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed('ember/tests/integration/multiple-app-test', ['ember-metal', 'ember-template-compiler', 'ember-application', 'ember-glimmer', 'ember-views'], function (_emberMetal, _emberTemplateCompiler, _emberApplication, _emberGlimmer, _emberViews) {
'use strict';
var App1 = void 0,
App2 = void 0,
actions = void 0;
function startApp(rootElement) {
var application = void 0;
(0, _emberMetal.run)(function () {
application = _emberApplication.Application.create({
rootElement: rootElement
});
application.deferReadiness();
application.Router.reopen({
location: 'none'
});
var registry = application.__registry__;
registry.register('component:special-button', _emberGlimmer.Component.extend({
actions: {
doStuff: function () {
actions.push(rootElement);
}
}
}));
registry.register('template:application', (0, _emberTemplateCompiler.compile)('{{outlet}}', { moduleName: 'application' }));
registry.register('template:index', (0, _emberTemplateCompiler.compile)('Node 1 {{special-button}}', { moduleName: 'index' }));
registry.register('template:components/special-button', (0, _emberTemplateCompiler.compile)('Button ', { moduleName: 'components/special-button' }));
});
return application;
}
function handleURL(application, path) {
var router = application.__container__.lookup('router:main');
return (0, _emberMetal.run)(router, 'handleURL', path);
}
QUnit.module('View Integration', {
setup: function () {
actions = [];
(0, _emberViews.jQuery)('#qunit-fixture').html('
');
App1 = startApp('#app-1');
App2 = startApp('#app-2');
},
teardown: function () {
(0, _emberMetal.run)(App1, 'destroy');
(0, _emberMetal.run)(App2, 'destroy');
App1 = App2 = null;
}
});
QUnit.test('booting multiple applications can properly handle events', function (assert) {
(0, _emberMetal.run)(App1, 'advanceReadiness');
(0, _emberMetal.run)(App2, 'advanceReadiness');
handleURL(App1, '/');
handleURL(App2, '/');
(0, _emberViews.jQuery)('#app-2 .do-stuff').click();
(0, _emberViews.jQuery)('#app-1 .do-stuff').click();
assert.deepEqual(actions, ['#app-2', '#app-1']);
});
});
enifed('ember/tests/reexports_test', ['ember/index', 'internal-test-helpers'], function (_index, _internalTestHelpers) {
'use strict';
QUnit.module('ember reexports');
[
// ember-utils
['getOwner', 'ember-utils', 'getOwner'], ['setOwner', 'ember-utils', 'setOwner'], ['assign', 'ember-utils'], ['GUID_KEY', 'ember-utils'], ['uuid', 'ember-utils'], ['generateGuid', 'ember-utils'], ['guidFor', 'ember-utils'], ['inspect', 'ember-utils'], ['makeArray', 'ember-utils'], ['canInvoke', 'ember-utils'], ['tryInvoke', 'ember-utils'], ['wrap', 'ember-utils'], ['applyStr', 'ember-utils'],
// ember-environment
// ['ENV', 'ember-environment', 'ENV'], TODO: fix this, its failing because we are hitting the getter
// container
['Registry', 'container', 'Registry'], ['Container', 'container', 'Container'],
// ember-metal
['computed', 'ember-metal'], ['computed.alias', 'ember-metal', 'alias'], ['ComputedProperty', 'ember-metal'], ['cacheFor', 'ember-metal'], ['deprecateFunc', 'ember-debug'], ['assert', 'ember-debug'], ['warn', 'ember-debug'], ['debug', 'ember-debug'], ['runInDebug', 'ember-debug'], ['merge', 'ember-metal'], ['instrument', 'ember-metal'], ['Instrumentation.instrument', 'ember-metal', 'instrument'], ['Instrumentation.subscribe', 'ember-metal', 'instrumentationSubscribe'], ['Instrumentation.unsubscribe', 'ember-metal', 'instrumentationUnsubscribe'], ['Instrumentation.reset', 'ember-metal', 'instrumentationReset'], ['testing', 'ember-debug', { get: 'isTesting', set: 'setTesting' }], ['onerror', 'ember-metal', { get: 'getOnerror', set: 'setOnerror' }],
// ['create'], TODO: figure out what to do here
// ['keys'], TODO: figure out what to do here
['FEATURES', 'ember/features'], ['FEATURES.isEnabled', 'ember-debug', 'isFeatureEnabled'], ['Error', 'ember-debug'], ['META_DESC', 'ember-metal'], ['meta', 'ember-metal'], ['get', 'ember-metal'], ['set', 'ember-metal'], ['_getPath', 'ember-metal'], ['getWithDefault', 'ember-metal'], ['trySet', 'ember-metal'], ['_Cache', 'ember-metal', 'Cache'], ['on', 'ember-metal'], ['addListener', 'ember-metal'], ['removeListener', 'ember-metal'], ['_suspendListener', 'ember-metal', 'suspendListener'], ['_suspendListeners', 'ember-metal', 'suspendListeners'], ['sendEvent', 'ember-metal'], ['hasListeners', 'ember-metal'], ['watchedEvents', 'ember-metal'], ['listenersFor', 'ember-metal'], ['accumulateListeners', 'ember-metal'], ['isNone', 'ember-metal'], ['isEmpty', 'ember-metal'], ['isBlank', 'ember-metal'], ['isPresent', 'ember-metal'], ['_Backburner', 'backburner', 'default'], ['run', 'ember-metal'], ['_ObserverSet', 'ember-metal', 'ObserverSet'], ['propertyWillChange', 'ember-metal'], ['propertyDidChange', 'ember-metal'], ['overrideChains', 'ember-metal'], ['beginPropertyChanges', 'ember-metal'], ['beginPropertyChanges', 'ember-metal'], ['endPropertyChanges', 'ember-metal'], ['changeProperties', 'ember-metal'], ['defineProperty', 'ember-metal'], ['watchKey', 'ember-metal'], ['unwatchKey', 'ember-metal'], ['removeChainWatcher', 'ember-metal'], ['_ChainNode', 'ember-metal', 'ChainNode'], ['finishChains', 'ember-metal'], ['watchPath', 'ember-metal'], ['unwatchPath', 'ember-metal'], ['watch', 'ember-metal'], ['isWatching', 'ember-metal'], ['unwatch', 'ember-metal'], ['destroy', 'ember-metal'], ['libraries', 'ember-metal'], ['OrderedSet', 'ember-metal'], ['Map', 'ember-metal'], ['MapWithDefault', 'ember-metal'], ['getProperties', 'ember-metal'], ['setProperties', 'ember-metal'], ['expandProperties', 'ember-metal'], ['NAME_KEY', 'ember-utils'], ['addObserver', 'ember-metal'], ['observersFor', 'ember-metal'], ['removeObserver', 'ember-metal'], ['_suspendObserver', 'ember-metal'], ['_suspendObservers', 'ember-metal'], ['required', 'ember-metal'], ['aliasMethod', 'ember-metal'], ['observer', 'ember-metal'], ['immediateObserver', 'ember-metal', '_immediateObserver'], ['mixin', 'ember-metal'], ['Mixin', 'ember-metal'], ['bind', 'ember-metal'], ['Binding', 'ember-metal'], ['isGlobalPath', 'ember-metal'],
// ember-views
['$', 'ember-views', 'jQuery'], ['ViewUtils.isSimpleClick', 'ember-views', 'isSimpleClick'], ['ViewUtils.getViewElement', 'ember-views', 'getViewElement'], ['ViewUtils.getViewBounds', 'ember-views', 'getViewBounds'], ['ViewUtils.getViewClientRects', 'ember-views', 'getViewClientRects'], ['ViewUtils.getViewBoundingClientRect', 'ember-views', 'getViewBoundingClientRect'], ['ViewUtils.getRootViews', 'ember-views', 'getRootViews'], ['ViewUtils.getChildViews', 'ember-views', 'getChildViews'], ['TextSupport', 'ember-views'], ['ComponentLookup', 'ember-views'], ['EventDispatcher', 'ember-views'],
// ember-glimmer
['Component', 'ember-glimmer', 'Component'], ['Helper', 'ember-glimmer', 'Helper'], ['Helper.helper', 'ember-glimmer', 'helper'], ['Checkbox', 'ember-glimmer', 'Checkbox'], ['LinkComponent', 'ember-glimmer', 'LinkComponent'], ['TextArea', 'ember-glimmer', 'TextArea'], ['TextField', 'ember-glimmer', 'TextField'], ['TEMPLATES', 'ember-glimmer', { get: 'getTemplates', set: 'setTemplates' }], ['Handlebars.template', 'ember-glimmer', 'template'], ['Handlebars.SafeString', 'ember-glimmer', { get: '_getSafeString' }], ['Handlebars.Utils.escapeExpression', 'ember-glimmer', 'escapeExpression'], ['String.htmlSafe', 'ember-glimmer', 'htmlSafe'],
// ember-runtime
['_RegistryProxyMixin', 'ember-runtime', 'RegistryProxyMixin'], ['_ContainerProxyMixin', 'ember-runtime', 'ContainerProxyMixin'], ['Object', 'ember-runtime'], ['String', 'ember-runtime'], ['compare', 'ember-runtime'], ['copy', 'ember-runtime'], ['isEqual', 'ember-runtime'], ['inject', 'ember-runtime'], ['Array', 'ember-runtime'], ['Comparable', 'ember-runtime'], ['Namespace', 'ember-runtime'], ['Enumerable', 'ember-runtime'], ['ArrayProxy', 'ember-runtime'], ['ObjectProxy', 'ember-runtime'], ['ActionHandler', 'ember-runtime'], ['CoreObject', 'ember-runtime'], ['NativeArray', 'ember-runtime'], ['Copyable', 'ember-runtime'], ['Freezable', 'ember-runtime'], ['FROZEN_ERROR', 'ember-runtime'], ['MutableEnumerable', 'ember-runtime'], ['MutableArray', 'ember-runtime'], ['TargetActionSupport', 'ember-runtime'], ['Evented', 'ember-runtime'], ['PromiseProxyMixin', 'ember-runtime'], ['Observable', 'ember-runtime'], ['typeOf', 'ember-runtime'], ['isArray', 'ember-runtime'], ['Object', 'ember-runtime'], ['onLoad', 'ember-runtime'], ['runLoadHooks', 'ember-runtime'], ['Controller', 'ember-runtime'], ['ControllerMixin', 'ember-runtime'], ['Service', 'ember-runtime'], ['_ProxyMixin', 'ember-runtime'], ['RSVP', 'ember-runtime'], ['STRINGS', 'ember-runtime', { get: 'getStrings', set: 'setStrings' }], ['BOOTED', 'ember-runtime', { get: 'isNamespaceSearchDisabled', set: 'setNamespaceSearchDisabled' }],
// ember-routing
['Location', 'ember-routing'], ['AutoLocation', 'ember-routing'], ['HashLocation', 'ember-routing'], ['HistoryLocation', 'ember-routing'], ['NoneLocation', 'ember-routing'], ['controllerFor', 'ember-routing'], ['generateControllerFactory', 'ember-routing'], ['generateController', 'ember-routing'], ['RouterDSL', 'ember-routing'], ['Router', 'ember-routing'], ['Route', 'ember-routing'],
// ember-application
['Application', 'ember-application'], ['ApplicationInstance', 'ember-application'], ['Engine', 'ember-application'], ['EngineInstance', 'ember-application'], ['Resolver', 'ember-application'], ['DefaultResolver', 'ember-application', 'Resolver'],
// ember-extension-support
['DataAdapter', 'ember-extension-support'], ['ContainerDebugAdapter', 'ember-extension-support']].forEach(function (reexport) {
var path = reexport[0],
moduleId = reexport[1],
exportName = reexport[2];
// default path === exportName if none present
if (!exportName) {
exportName = path;
}
QUnit.test('Ember.' + path + ' exports correctly', function (assert) {
(0, _internalTestHelpers.confirmExport)(_index.default, assert, path, moduleId, exportName);
});
});
QUnit.test('Ember.String.isHTMLSafe exports correctly', function (assert) {
(0, _internalTestHelpers.confirmExport)(_index.default, assert, 'String.isHTMLSafe', 'ember-glimmer', 'isHTMLSafe');
});
});
enifed('ember/tests/routing/basic_test', ['ember-utils', 'ember-console', 'ember-runtime', 'ember-routing', 'ember-metal', 'ember-glimmer', 'ember-views', 'ember-template-compiler', 'ember-application', 'router'], function (_emberUtils, _emberConsole, _emberRuntime, _emberRouting, _emberMetal, _emberGlimmer, _emberViews, _emberTemplateCompiler, _emberApplication, _router) {
'use strict';
var trim = _emberViews.jQuery.trim;
var Router = void 0,
App = void 0,
router = void 0,
registry = void 0,
container = void 0,
originalLoggerError = void 0;
function bootApplication() {
router = container.lookup('router:main');
(0, _emberMetal.run)(App, 'advanceReadiness');
}
function handleURL(path) {
return (0, _emberMetal.run)(function () {
return router.handleURL(path).then(function (value) {
ok(true, 'url: `' + path + '` was handled');
return value;
}, function (reason) {
ok(false, 'failed to visit:`' + path + '` reason: `' + QUnit.jsDump.parse(reason));
throw reason;
});
});
}
function handleURLAborts(path) {
(0, _emberMetal.run)(function () {
router.handleURL(path).then(function () {
ok(false, 'url: `' + path + '` was NOT to be handled');
}, function (reason) {
ok(reason && reason.message === 'TransitionAborted', 'url: `' + path + '` was to be aborted');
});
});
}
function handleURLRejectsWith(path, expectedReason) {
(0, _emberMetal.run)(function () {
router.handleURL(path).then(function () {
ok(false, 'expected handleURLing: `' + path + '` to fail');
}, function (reason) {
equal(reason, expectedReason);
});
});
}
QUnit.module('Basic Routing', {
setup: function () {
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create({
name: 'App',
rootElement: '#qunit-fixture'
});
App.deferReadiness();
App.Router.reopen({
location: 'none'
});
Router = App.Router;
App.LoadingRoute = _emberRouting.Route.extend({});
registry = App.__registry__;
container = App.__container__;
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('Hours '));
(0, _emberGlimmer.setTemplate)('homepage', (0, _emberTemplateCompiler.compile)('Megatroll {{model.home}}
'));
(0, _emberGlimmer.setTemplate)('camelot', (0, _emberTemplateCompiler.compile)(''));
originalLoggerError = _emberConsole.default.error;
});
},
teardown: function () {
(0, _emberMetal.run)(function () {
App.destroy();
App = null;
(0, _emberGlimmer.setTemplates)({});
_emberConsole.default.error = originalLoggerError;
});
}
});
QUnit.test('warn on URLs not included in the route set', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
bootApplication();
expectAssertion(function () {
return (0, _emberMetal.run)(function () {
return router.handleURL('/what-is-this-i-dont-even');
});
}, 'The URL \'/what-is-this-i-dont-even\' did not match any routes in your application');
});
QUnit.test('The Homepage', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({});
var currentPath = void 0;
App.ApplicationController = _emberRuntime.Controller.extend({
currentPathDidChange: (0, _emberMetal.observer)('currentPath', function () {
currentPath = (0, _emberMetal.get)(this, 'currentPath');
})
});
bootApplication();
equal(currentPath, 'home');
equal((0, _emberViews.jQuery)('h3:contains(Hours)', '#qunit-fixture').length, 1, 'The home template was rendered');
});
QUnit.test('The Home page and the Camelot page with multiple Router.map calls', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
Router.map(function () {
this.route('camelot', { path: '/camelot' });
});
App.HomeRoute = _emberRouting.Route.extend({});
App.CamelotRoute = _emberRouting.Route.extend({});
var currentPath = void 0;
App.ApplicationController = _emberRuntime.Controller.extend({
currentPathDidChange: (0, _emberMetal.observer)('currentPath', function () {
currentPath = (0, _emberMetal.get)(this, 'currentPath');
})
});
App.CamelotController = _emberRuntime.Controller.extend({
currentPathDidChange: (0, _emberMetal.observer)('currentPath', function () {
currentPath = (0, _emberMetal.get)(this, 'currentPath');
})
});
bootApplication();
handleURL('/camelot');
equal(currentPath, 'camelot');
equal((0, _emberViews.jQuery)('h3:contains(silly)', '#qunit-fixture').length, 1, 'The camelot template was rendered');
handleURL('/');
equal(currentPath, 'home');
equal((0, _emberViews.jQuery)('h3:contains(Hours)', '#qunit-fixture').length, 1, 'The home template was rendered');
});
QUnit.test('The Homepage with explicit template name in renderTemplate', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render('homepage');
}
});
bootApplication();
equal((0, _emberViews.jQuery)('h3:contains(Megatroll)', '#qunit-fixture').length, 1, 'The homepage template was rendered');
});
QUnit.test('An alternate template will pull in an alternate controller', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render('homepage');
}
});
App.HomepageController = _emberRuntime.Controller.extend({
model: {
home: 'Comes from homepage'
}
});
bootApplication();
equal((0, _emberViews.jQuery)('h3:contains(Megatroll) + p:contains(Comes from homepage)', '#qunit-fixture').length, 1, 'The homepage template was rendered');
});
QUnit.test('An alternate template will pull in an alternate controller instead of controllerName', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
controllerName: 'foo',
renderTemplate: function () {
this.render('homepage');
}
});
App.FooController = _emberRuntime.Controller.extend({
model: {
home: 'Comes from Foo'
}
});
App.HomepageController = _emberRuntime.Controller.extend({
model: {
home: 'Comes from homepage'
}
});
bootApplication();
equal((0, _emberViews.jQuery)('h3:contains(Megatroll) + p:contains(Comes from homepage)', '#qunit-fixture').length, 1, 'The homepage template was rendered');
});
QUnit.test('The template will pull in an alternate controller via key/value', function () {
Router.map(function () {
this.route('homepage', { path: '/' });
});
App.HomepageRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render({ controller: 'home' });
}
});
App.HomeController = _emberRuntime.Controller.extend({
model: {
home: 'Comes from home.'
}
});
bootApplication();
equal((0, _emberViews.jQuery)('h3:contains(Megatroll) + p:contains(Comes from home.)', '#qunit-fixture').length, 1, 'The homepage template was rendered from data from the HomeController');
});
QUnit.test('The Homepage with explicit template name in renderTemplate and controller', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeController = _emberRuntime.Controller.extend({
model: {
home: 'YES I AM HOME'
}
});
App.HomeRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render('homepage');
}
});
bootApplication();
equal((0, _emberViews.jQuery)('h3:contains(Megatroll) + p:contains(YES I AM HOME)', '#qunit-fixture').length, 1, 'The homepage template was rendered');
});
QUnit.test('Model passed via renderTemplate model is set as controller\'s model', function () {
(0, _emberGlimmer.setTemplate)('bio', (0, _emberTemplateCompiler.compile)('{{model.name}}
'));
App.BioController = _emberRuntime.Controller.extend();
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render('bio', {
model: { name: 'emberjs' }
});
}
});
bootApplication();
equal((0, _emberViews.jQuery)('p:contains(emberjs)', '#qunit-fixture').length, 1, 'Passed model was set as controllers model');
});
QUnit.test('render uses templateName from route', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
(0, _emberGlimmer.setTemplate)('the_real_home_template', (0, _emberTemplateCompiler.compile)('THIS IS THE REAL HOME
'));
App.HomeController = _emberRuntime.Controller.extend();
App.HomeRoute = _emberRouting.Route.extend({
templateName: 'the_real_home_template'
});
bootApplication();
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'THIS IS THE REAL HOME', 'The homepage template was rendered');
});
QUnit.test('defining templateName allows other templates to be rendered', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
(0, _emberGlimmer.setTemplate)('alert', (0, _emberTemplateCompiler.compile)('Invader!
'));
(0, _emberGlimmer.setTemplate)('the_real_home_template', (0, _emberTemplateCompiler.compile)('THIS IS THE REAL HOME
{{outlet \'alert\'}}'));
App.HomeController = _emberRuntime.Controller.extend();
App.HomeRoute = _emberRouting.Route.extend({
templateName: 'the_real_home_template',
actions: {
showAlert: function () {
this.render('alert', {
into: 'home',
outlet: 'alert'
});
}
}
});
bootApplication();
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'THIS IS THE REAL HOME', 'The homepage template was rendered');
(0, _emberMetal.run)(function () {
return router.send('showAlert');
});
equal((0, _emberViews.jQuery)('.alert-box', '#qunit-fixture').text(), 'Invader!', 'Template for alert was render into outlet');
});
QUnit.test('templateName is still used when calling render with no name and options', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
(0, _emberGlimmer.setTemplate)('alert', (0, _emberTemplateCompiler.compile)('Invader!
'));
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('THIS IS THE REAL HOME
{{outlet \'alert\'}}'));
App.HomeRoute = _emberRouting.Route.extend({
templateName: 'alert',
renderTemplate: function () {
this.render({});
}
});
bootApplication();
equal((0, _emberViews.jQuery)('.alert-box', '#qunit-fixture').text(), 'Invader!', 'default templateName was rendered into outlet');
});
QUnit.test('The Homepage with a `setupController` hook', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
setupController: function (controller) {
(0, _emberMetal.set)(controller, 'hours', (0, _emberRuntime.A)(['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm']));
}
});
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('{{#each hours as |entry|}}{{entry}} {{/each}} '));
bootApplication();
equal((0, _emberViews.jQuery)('ul li', '#qunit-fixture').eq(2).text(), 'Sunday: Noon to 6pm', 'The template was rendered with the hours context');
});
QUnit.test('The route controller is still set when overriding the setupController hook', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
setupController: function () {
// no-op
// importantly, we are not calling this._super here
}
});
registry.register('controller:home', _emberRuntime.Controller.extend());
bootApplication();
deepEqual(container.lookup('route:home').controller, container.lookup('controller:home'), 'route controller is the home controller');
});
QUnit.test('The route controller can be specified via controllerName', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('{{myValue}}
'));
App.HomeRoute = _emberRouting.Route.extend({
controllerName: 'myController'
});
registry.register('controller:myController', _emberRuntime.Controller.extend({
myValue: 'foo'
}));
bootApplication();
deepEqual(container.lookup('route:home').controller, container.lookup('controller:myController'), 'route controller is set by controllerName');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'foo', 'The homepage template was rendered with data from the custom controller');
});
QUnit.test('The route controller specified via controllerName is used in render', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
(0, _emberGlimmer.setTemplate)('alternative_home', (0, _emberTemplateCompiler.compile)('alternative home: {{myValue}}
'));
App.HomeRoute = _emberRouting.Route.extend({
controllerName: 'myController',
renderTemplate: function () {
this.render('alternative_home');
}
});
registry.register('controller:myController', _emberRuntime.Controller.extend({
myValue: 'foo'
}));
bootApplication();
deepEqual(container.lookup('route:home').controller, container.lookup('controller:myController'), 'route controller is set by controllerName');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'alternative home: foo', 'The homepage template was rendered with data from the custom controller');
});
QUnit.test('The route controller specified via controllerName is used in render even when a controller with the routeName is available', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('home: {{myValue}}
'));
App.HomeRoute = _emberRouting.Route.extend({
controllerName: 'myController'
});
registry.register('controller:home', _emberRuntime.Controller.extend({
myValue: 'home'
}));
registry.register('controller:myController', _emberRuntime.Controller.extend({
myValue: 'myController'
}));
bootApplication();
deepEqual(container.lookup('route:home').controller, container.lookup('controller:myController'), 'route controller is set by controllerName');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'home: myController', 'The homepage template was rendered with data from the custom controller');
});
QUnit.test('The Homepage with a `setupController` hook modifying other controllers', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
setupController: function () {
(0, _emberMetal.set)(this.controllerFor('home'), 'hours', (0, _emberRuntime.A)(['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm']));
}
});
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('{{#each hours as |entry|}}{{entry}} {{/each}} '));
bootApplication();
equal((0, _emberViews.jQuery)('ul li', '#qunit-fixture').eq(2).text(), 'Sunday: Noon to 6pm', 'The template was rendered with the hours context');
});
QUnit.test('The Homepage with a computed context that does not get overridden', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeController = _emberRuntime.Controller.extend({
model: (0, _emberMetal.computed)(function () {
return (0, _emberRuntime.A)(['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm']);
})
});
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('{{#each model as |passage|}}{{passage}} {{/each}} '));
bootApplication();
equal((0, _emberViews.jQuery)('ul li', '#qunit-fixture').eq(2).text(), 'Sunday: Noon to 6pm', 'The template was rendered with the context intact');
});
QUnit.test('The Homepage getting its controller context via model', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
model: function () {
return (0, _emberRuntime.A)(['Monday through Friday: 9am to 5pm', 'Saturday: Noon to Midnight', 'Sunday: Noon to 6pm']);
},
setupController: function (controller, model) {
equal(this.controllerFor('home'), controller);
(0, _emberMetal.set)(this.controllerFor('home'), 'hours', model);
}
});
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('{{#each hours as |entry|}}{{entry}} {{/each}} '));
bootApplication();
equal((0, _emberViews.jQuery)('ul li', '#qunit-fixture').eq(2).text(), 'Sunday: Noon to 6pm', 'The template was rendered with the hours context');
});
QUnit.test('The Specials Page getting its controller context by deserializing the params hash', function () {
Router.map(function () {
this.route('home', { path: '/' });
this.route('special', { path: '/specials/:menu_item_id' });
});
App.SpecialRoute = _emberRouting.Route.extend({
model: function (params) {
return _emberRuntime.Object.create({
menuItemId: params.menu_item_id
});
},
setupController: function (controller, model) {
(0, _emberMetal.set)(controller, 'model', model);
}
});
(0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('{{model.menuItemId}}
'));
bootApplication();
registry.register('controller:special', _emberRuntime.Controller.extend());
handleURL('/specials/1');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), '1', 'The model was used to render the template');
});
QUnit.test('The Specials Page defaults to looking models up via `find`', function () {
Router.map(function () {
this.route('home', { path: '/' });
this.route('special', { path: '/specials/:menu_item_id' });
});
App.MenuItem = _emberRuntime.Object.extend();
App.MenuItem.reopenClass({
find: function (id) {
return App.MenuItem.create({
id: id
});
}
});
App.SpecialRoute = _emberRouting.Route.extend({
setupController: function (controller, model) {
(0, _emberMetal.set)(controller, 'model', model);
}
});
(0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('{{model.id}}
'));
bootApplication();
registry.register('controller:special', _emberRuntime.Controller.extend());
handleURL('/specials/1');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), '1', 'The model was used to render the template');
});
QUnit.test('The Special Page returning a promise puts the app into a loading state until the promise is resolved', function () {
Router.map(function () {
this.route('home', { path: '/' });
this.route('special', { path: '/specials/:menu_item_id' });
});
var menuItem = void 0,
resolve = void 0;
App.MenuItem = _emberRuntime.Object.extend();
App.MenuItem.reopenClass({
find: function (id) {
menuItem = App.MenuItem.create({ id: id });
return new _emberRuntime.RSVP.Promise(function (res) {
resolve = res;
});
}
});
App.LoadingRoute = _emberRouting.Route.extend({});
App.SpecialRoute = _emberRouting.Route.extend({
setupController: function (controller, model) {
(0, _emberMetal.set)(controller, 'model', model);
}
});
(0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('{{model.id}}
'));
(0, _emberGlimmer.setTemplate)('loading', (0, _emberTemplateCompiler.compile)('LOADING!
'));
bootApplication();
registry.register('controller:special', _emberRuntime.Controller.extend());
handleURL('/specials/1');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'LOADING!', 'The app is in the loading state');
(0, _emberMetal.run)(function () {
return resolve(menuItem);
});
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), '1', 'The app is now in the specials state');
});
QUnit.test('The loading state doesn\'t get entered for promises that resolve on the same run loop', function () {
Router.map(function () {
this.route('home', { path: '/' });
this.route('special', { path: '/specials/:menu_item_id' });
});
App.MenuItem = _emberRuntime.Object.extend();
App.MenuItem.reopenClass({
find: function (id) {
return { id: id };
}
});
App.LoadingRoute = _emberRouting.Route.extend({
enter: function () {
ok(false, 'LoadingRoute shouldn\'t have been entered.');
}
});
App.SpecialRoute = _emberRouting.Route.extend({
setupController: function (controller, model) {
(0, _emberMetal.set)(controller, 'model', model);
}
});
(0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('{{model.id}}
'));
(0, _emberGlimmer.setTemplate)('loading', (0, _emberTemplateCompiler.compile)('LOADING!
'));
bootApplication();
registry.register('controller:special', _emberRuntime.Controller.extend());
handleURL('/specials/1');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), '1', 'The app is now in the specials state');
});
/*
asyncTest("The Special page returning an error fires the error hook on SpecialRoute", function() {
Router.map(function() {
this.route("home", { path: "/" });
this.route("special", { path: "/specials/:menu_item_id" });
});
let menuItem;
App.MenuItem = Ember.Object.extend();
App.MenuItem.reopenClass({
find: function(id) {
menuItem = App.MenuItem.create({ id: id });
run.later(function() { menuItem.resolve(menuItem); }, 1);
return menuItem;
}
});
App.SpecialRoute = Route.extend({
setup: function() {
throw 'Setup error';
},
actions: {
error: function(reason) {
equal(reason, 'Setup error');
QUnit.start();
}
}
});
bootApplication();
handleURLRejectsWith('/specials/1', 'Setup error');
});
*/
QUnit.test('The Special page returning an error invokes SpecialRoute\'s error handler', function () {
Router.map(function () {
this.route('home', { path: '/' });
this.route('special', { path: '/specials/:menu_item_id' });
});
var menuItem = void 0,
promise = void 0,
resolve = void 0;
App.MenuItem = _emberRuntime.Object.extend();
App.MenuItem.reopenClass({
find: function (id) {
menuItem = App.MenuItem.create({ id: id });
promise = new _emberRuntime.RSVP.Promise(function (res) {
resolve = res;
});
return promise;
}
});
App.SpecialRoute = _emberRouting.Route.extend({
setup: function () {
throw 'Setup error';
},
actions: {
error: function (reason) {
equal(reason, 'Setup error', 'SpecialRoute#error received the error thrown from setup');
return true;
}
}
});
bootApplication();
handleURLRejectsWith('/specials/1', 'Setup error');
(0, _emberMetal.run)(function () {
return resolve(menuItem);
});
});
var testOverridableErrorHandler = function (handlersName) {
expect(2);
Router.map(function () {
this.route('home', { path: '/' });
this.route('special', { path: '/specials/:menu_item_id' });
});
var menuItem = void 0,
resolve = void 0;
App.MenuItem = _emberRuntime.Object.extend();
App.MenuItem.reopenClass({
find: function (id) {
menuItem = App.MenuItem.create({ id: id });
return new _emberRuntime.RSVP.Promise(function (res) {
resolve = res;
});
}
});
var attrs = {};
attrs[handlersName] = {
error: function (reason) {
equal(reason, 'Setup error', 'error was correctly passed to custom ApplicationRoute handler');
return true;
}
};
App.ApplicationRoute = _emberRouting.Route.extend(attrs);
App.SpecialRoute = _emberRouting.Route.extend({
setup: function () {
throw 'Setup error';
}
});
bootApplication();
handleURLRejectsWith('/specials/1', 'Setup error');
(0, _emberMetal.run)(function () {
return resolve(menuItem);
});
};
QUnit.test('ApplicationRoute\'s default error handler can be overridden', function () {
testOverridableErrorHandler('actions');
});
QUnit.asyncTest('Moving from one page to another triggers the correct callbacks', function () {
expect(3);
Router.map(function () {
this.route('home', { path: '/' });
this.route('special', { path: '/specials/:menu_item_id' });
});
App.MenuItem = _emberRuntime.Object.extend();
App.SpecialRoute = _emberRouting.Route.extend({
setupController: function (controller, model) {
(0, _emberMetal.set)(controller, 'model', model);
}
});
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('Home '));
(0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('{{model.id}}
'));
bootApplication();
registry.register('controller:special', _emberRuntime.Controller.extend());
var transition = handleURL('/');
(0, _emberMetal.run)(function () {
transition.then(function () {
equal((0, _emberViews.jQuery)('h3', '#qunit-fixture').text(), 'Home', 'The app is now in the initial state');
var promiseContext = App.MenuItem.create({ id: 1 });
_emberMetal.run.later(function () {
return _emberRuntime.RSVP.resolve(promiseContext);
}, 1);
return router.transitionTo('special', promiseContext);
}).then(function () {
deepEqual(router.location.path, '/specials/1');
QUnit.start();
});
});
});
QUnit.asyncTest('Nested callbacks are not exited when moving to siblings', function () {
Router.map(function () {
this.route('root', { path: '/' }, function () {
this.route('special', { path: '/specials/:menu_item_id', resetNamespace: true });
});
});
App.RootRoute = _emberRouting.Route.extend({
model: function () {
rootModel++;
return this._super.apply(this, arguments);
},
setupController: function () {
rootSetup++;
},
renderTemplate: function () {
rootRender++;
},
serialize: function () {
rootSerialize++;
return this._super.apply(this, arguments);
}
});
var currentPath = void 0;
App.ApplicationController = _emberRuntime.Controller.extend({
currentPathDidChange: (0, _emberMetal.observer)('currentPath', function () {
currentPath = (0, _emberMetal.get)(this, 'currentPath');
})
});
var menuItem = void 0;
App.MenuItem = _emberRuntime.Object.extend();
App.MenuItem.reopenClass({
find: function (id) {
menuItem = App.MenuItem.create({ id: id });
return menuItem;
}
});
App.LoadingRoute = _emberRouting.Route.extend({});
App.HomeRoute = _emberRouting.Route.extend({});
App.SpecialRoute = _emberRouting.Route.extend({
setupController: function (controller, model) {
(0, _emberMetal.set)(controller, 'model', model);
}
});
(0, _emberGlimmer.setTemplate)('root/index', (0, _emberTemplateCompiler.compile)('Home '));
(0, _emberGlimmer.setTemplate)('special', (0, _emberTemplateCompiler.compile)('{{model.id}}
'));
(0, _emberGlimmer.setTemplate)('loading', (0, _emberTemplateCompiler.compile)('LOADING!
'));
var rootSetup = 0;
var rootRender = 0;
var rootModel = 0;
var rootSerialize = 0;
bootApplication();
registry.register('controller:special', _emberRuntime.Controller.extend());
equal((0, _emberViews.jQuery)('h3', '#qunit-fixture').text(), 'Home', 'The app is now in the initial state');
equal(rootSetup, 1, 'The root setup was triggered');
equal(rootRender, 1, 'The root render was triggered');
equal(rootSerialize, 0, 'The root serialize was not called');
equal(rootModel, 1, 'The root model was called');
router = container.lookup('router:main');
(0, _emberMetal.run)(function () {
var menuItem = App.MenuItem.create({ id: 1 });
_emberMetal.run.later(function () {
return _emberRuntime.RSVP.resolve(menuItem);
}, 1);
router.transitionTo('special', menuItem).then(function () {
equal(rootSetup, 1, 'The root setup was not triggered again');
equal(rootRender, 1, 'The root render was not triggered again');
equal(rootSerialize, 0, 'The root serialize was not called');
// TODO: Should this be changed?
equal(rootModel, 1, 'The root model was called again');
deepEqual(router.location.path, '/specials/1');
equal(currentPath, 'root.special');
QUnit.start();
});
});
});
QUnit.asyncTest('Events are triggered on the controller if a matching action name is implemented', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
var model = { name: 'Tom Dale' };
var stateIsNotCalled = true;
App.HomeRoute = _emberRouting.Route.extend({
model: function () {
return model;
},
actions: {
showStuff: function () {
stateIsNotCalled = false;
}
}
});
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('{{name}} '));
var controller = _emberRuntime.Controller.extend({
actions: {
showStuff: function (context) {
ok(stateIsNotCalled, 'an event on the state is not triggered');
deepEqual(context, { name: 'Tom Dale' }, 'an event with context is passed');
QUnit.start();
}
}
});
registry.register('controller:home', controller);
bootApplication();
(0, _emberViews.jQuery)('#qunit-fixture a').click();
});
QUnit.asyncTest('Events are triggered on the current state when defined in `actions` object', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
var model = { name: 'Tom Dale' };
App.HomeRoute = _emberRouting.Route.extend({
model: function () {
return model;
},
actions: {
showStuff: function (obj) {
ok(this instanceof App.HomeRoute, 'the handler is an App.HomeRoute');
// Using Ember.copy removes any private Ember vars which older IE would be confused by
deepEqual((0, _emberRuntime.copy)(obj, true), { name: 'Tom Dale' }, 'the context is correct');
QUnit.start();
}
}
});
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('{{model.name}} '));
bootApplication();
(0, _emberViews.jQuery)('#qunit-fixture a').click();
});
QUnit.asyncTest('Events defined in `actions` object are triggered on the current state when routes are nested', function () {
Router.map(function () {
this.route('root', { path: '/' }, function () {
this.route('index', { path: '/' });
});
});
var model = { name: 'Tom Dale' };
App.RootRoute = _emberRouting.Route.extend({
actions: {
showStuff: function (obj) {
ok(this instanceof App.RootRoute, 'the handler is an App.HomeRoute');
// Using Ember.copy removes any private Ember vars which older IE would be confused by
deepEqual((0, _emberRuntime.copy)(obj, true), { name: 'Tom Dale' }, 'the context is correct');
QUnit.start();
}
}
});
App.RootIndexRoute = _emberRouting.Route.extend({
model: function () {
return model;
}
});
(0, _emberGlimmer.setTemplate)('root/index', (0, _emberTemplateCompiler.compile)('{{model.name}} '));
bootApplication();
(0, _emberViews.jQuery)('#qunit-fixture a').click();
});
QUnit.test('Events can be handled by inherited event handlers', function () {
expect(4);
App.SuperRoute = _emberRouting.Route.extend({
actions: {
foo: function () {
ok(true, 'foo');
},
bar: function (msg) {
equal(msg, 'HELLO');
}
}
});
App.RouteMixin = _emberMetal.Mixin.create({
actions: {
bar: function (msg) {
equal(msg, 'HELLO');
this._super(msg);
}
}
});
App.IndexRoute = App.SuperRoute.extend(App.RouteMixin, {
actions: {
baz: function () {
ok(true, 'baz');
}
}
});
bootApplication();
router.send('foo');
router.send('bar', 'HELLO');
router.send('baz');
});
QUnit.asyncTest('Actions are not triggered on the controller if a matching action name is implemented as a method', function () {
Router.map(function () {
this.route('home', { path: '/' });
});
var model = { name: 'Tom Dale' };
var stateIsNotCalled = true;
App.HomeRoute = _emberRouting.Route.extend({
model: function () {
return model;
},
actions: {
showStuff: function (context) {
ok(stateIsNotCalled, 'an event on the state is not triggered');
deepEqual(context, { name: 'Tom Dale' }, 'an event with context is passed');
QUnit.start();
}
}
});
(0, _emberGlimmer.setTemplate)('home', (0, _emberTemplateCompiler.compile)('{{name}} '));
var controller = _emberRuntime.Controller.extend({
showStuff: function () {
stateIsNotCalled = false;
ok(stateIsNotCalled, 'an event on the state is not triggered');
}
});
registry.register('controller:home', controller);
bootApplication();
(0, _emberViews.jQuery)('#qunit-fixture a').click();
});
QUnit.asyncTest('actions can be triggered with multiple arguments', function () {
Router.map(function () {
this.route('root', { path: '/' }, function () {
this.route('index', { path: '/' });
});
});
App.RootRoute = _emberRouting.Route.extend({
actions: {
showStuff: function (obj1, obj2) {
ok(this instanceof App.RootRoute, 'the handler is an App.HomeRoute');
// Using Ember.copy removes any private Ember vars which older IE would be confused by
deepEqual((0, _emberRuntime.copy)(obj1, true), { name: 'Tilde' }, 'the first context is correct');
deepEqual((0, _emberRuntime.copy)(obj2, true), { name: 'Tom Dale' }, 'the second context is correct');
QUnit.start();
}
}
});
App.RootIndexController = _emberRuntime.Controller.extend({
model1: { name: 'Tilde' },
model2: { name: 'Tom Dale' }
});
(0, _emberGlimmer.setTemplate)('root/index', (0, _emberTemplateCompiler.compile)('{{model1.name}} '));
bootApplication();
(0, _emberViews.jQuery)('#qunit-fixture a').click();
});
QUnit.test('transitioning multiple times in a single run loop only sets the URL once', function () {
Router.map(function () {
this.route('root', { path: '/' });
this.route('foo');
this.route('bar');
});
bootApplication();
var urlSetCount = 0;
router.get('location').setURL = function (path) {
urlSetCount++;
(0, _emberMetal.set)(this, 'path', path);
};
equal(urlSetCount, 0);
(0, _emberMetal.run)(function () {
router.transitionTo('foo');
router.transitionTo('bar');
});
equal(urlSetCount, 1);
equal(router.get('location').getURL(), '/bar');
});
QUnit.test('navigating away triggers a url property change', function () {
expect(3);
Router.map(function () {
this.route('root', { path: '/' });
this.route('foo', { path: '/foo' });
this.route('bar', { path: '/bar' });
});
bootApplication();
(0, _emberMetal.run)(function () {
(0, _emberMetal.addObserver)(router, 'url', function () {
ok(true, 'url change event was fired');
});
});
['foo', 'bar', '/foo'].forEach(function (destination) {
return (0, _emberMetal.run)(router, 'transitionTo', destination);
});
});
QUnit.test('using replaceWith calls location.replaceURL if available', function () {
var setCount = 0;
var replaceCount = 0;
Router.reopen({
location: _emberRouting.NoneLocation.create({
setURL: function (path) {
setCount++;
(0, _emberMetal.set)(this, 'path', path);
},
replaceURL: function (path) {
replaceCount++;
(0, _emberMetal.set)(this, 'path', path);
}
})
});
Router.map(function () {
this.route('root', { path: '/' });
this.route('foo');
});
bootApplication();
equal(setCount, 0);
equal(replaceCount, 0);
(0, _emberMetal.run)(function () {
return router.replaceWith('foo');
});
equal(setCount, 0, 'should not call setURL');
equal(replaceCount, 1, 'should call replaceURL once');
equal(router.get('location').getURL(), '/foo');
});
QUnit.test('using replaceWith calls setURL if location.replaceURL is not defined', function () {
var setCount = 0;
Router.reopen({
location: _emberRouting.NoneLocation.create({
setURL: function (path) {
setCount++;
(0, _emberMetal.set)(this, 'path', path);
}
})
});
Router.map(function () {
this.route('root', { path: '/' });
this.route('foo');
});
bootApplication();
equal(setCount, 0);
(0, _emberMetal.run)(function () {
return router.replaceWith('foo');
});
equal(setCount, 1, 'should call setURL once');
equal(router.get('location').getURL(), '/foo');
});
QUnit.test('Route inherits model from parent route', function () {
expect(9);
Router.map(function () {
this.route('the_post', { path: '/posts/:post_id' }, function () {
this.route('comments');
this.route('shares', { path: '/shares/:share_id', resetNamespace: true }, function () {
this.route('share');
});
});
});
var posts = {
1: {},
2: {},
3: {}
};
var shares = {
1: {},
2: {},
3: {}
};
App.ThePostRoute = _emberRouting.Route.extend({
model: function (params) {
return posts[params.post_id];
}
});
App.ThePostCommentsRoute = _emberRouting.Route.extend({
afterModel: function (post) {
var parent_model = this.modelFor('thePost');
equal(post, parent_model);
}
});
App.SharesRoute = _emberRouting.Route.extend({
model: function (params) {
return shares[params.share_id];
}
});
App.SharesShareRoute = _emberRouting.Route.extend({
afterModel: function (share) {
var parent_model = this.modelFor('shares');
equal(share, parent_model);
}
});
bootApplication();
handleURL('/posts/1/comments');
handleURL('/posts/1/shares/1');
handleURL('/posts/2/comments');
handleURL('/posts/2/shares/2');
handleURL('/posts/3/comments');
handleURL('/posts/3/shares/3');
});
QUnit.test('Routes with { resetNamespace: true } inherits model from parent route', function () {
expect(6);
Router.map(function () {
this.route('the_post', { path: '/posts/:post_id' }, function () {
this.route('comments', { resetNamespace: true }, function () {});
});
});
var posts = {
1: {},
2: {},
3: {}
};
App.ThePostRoute = _emberRouting.Route.extend({
model: function (params) {
return posts[params.post_id];
}
});
App.CommentsRoute = _emberRouting.Route.extend({
afterModel: function (post) {
var parent_model = this.modelFor('thePost');
equal(post, parent_model);
}
});
bootApplication();
handleURL('/posts/1/comments');
handleURL('/posts/2/comments');
handleURL('/posts/3/comments');
});
QUnit.test('It is possible to get the model from a parent route', function () {
expect(9);
Router.map(function () {
this.route('the_post', { path: '/posts/:post_id' }, function () {
this.route('comments', { resetNamespace: true });
});
});
var post1 = {};
var post2 = {};
var post3 = {};
var currentPost = void 0;
var posts = {
1: post1,
2: post2,
3: post3
};
App.ThePostRoute = _emberRouting.Route.extend({
model: function (params) {
return posts[params.post_id];
}
});
App.CommentsRoute = _emberRouting.Route.extend({
model: function () {
// Allow both underscore / camelCase format.
equal(this.modelFor('thePost'), currentPost);
equal(this.modelFor('the_post'), currentPost);
}
});
bootApplication();
currentPost = post1;
handleURL('/posts/1/comments');
currentPost = post2;
handleURL('/posts/2/comments');
currentPost = post3;
handleURL('/posts/3/comments');
});
QUnit.test('A redirection hook is provided', function () {
Router.map(function () {
this.route('choose', { path: '/' });
this.route('home');
});
var chooseFollowed = 0;
var destination = void 0;
App.ChooseRoute = _emberRouting.Route.extend({
redirect: function () {
if (destination) {
this.transitionTo(destination);
}
},
setupController: function () {
chooseFollowed++;
}
});
destination = 'home';
bootApplication();
equal(chooseFollowed, 0, 'The choose route wasn\'t entered since a transition occurred');
equal((0, _emberViews.jQuery)('h3:contains(Hours)', '#qunit-fixture').length, 1, 'The home template was rendered');
equal((0, _emberUtils.getOwner)(router).lookup('controller:application').get('currentPath'), 'home');
});
QUnit.test('Redirecting from the middle of a route aborts the remainder of the routes', function () {
expect(3);
Router.map(function () {
this.route('home');
this.route('foo', function () {
this.route('bar', { resetNamespace: true }, function () {
this.route('baz');
});
});
});
App.BarRoute = _emberRouting.Route.extend({
redirect: function () {
this.transitionTo('home');
},
setupController: function () {
ok(false, 'Should transition before setupController');
}
});
App.BarBazRoute = _emberRouting.Route.extend({
enter: function () {
ok(false, 'Should abort transition getting to next route');
}
});
bootApplication();
handleURLAborts('/foo/bar/baz');
equal((0, _emberUtils.getOwner)(router).lookup('controller:application').get('currentPath'), 'home');
equal(router.get('location').getURL(), '/home');
});
QUnit.test('Redirecting to the current target in the middle of a route does not abort initial routing', function () {
expect(5);
Router.map(function () {
this.route('home');
this.route('foo', function () {
this.route('bar', { resetNamespace: true }, function () {
this.route('baz');
});
});
});
var successCount = 0;
App.BarRoute = _emberRouting.Route.extend({
redirect: function () {
this.transitionTo('bar.baz').then(function () {
successCount++;
});
},
setupController: function () {
ok(true, 'Should still invoke bar\'s setupController');
}
});
App.BarBazRoute = _emberRouting.Route.extend({
setupController: function () {
ok(true, 'Should still invoke bar.baz\'s setupController');
}
});
bootApplication();
handleURL('/foo/bar/baz');
equal((0, _emberUtils.getOwner)(router).lookup('controller:application').get('currentPath'), 'foo.bar.baz');
equal(successCount, 1, 'transitionTo success handler was called once');
});
QUnit.test('Redirecting to the current target with a different context aborts the remainder of the routes', function () {
expect(4);
Router.map(function () {
this.route('home');
this.route('foo', function () {
this.route('bar', { path: 'bar/:id', resetNamespace: true }, function () {
this.route('baz');
});
});
});
var model = { id: 2 };
var count = 0;
App.BarRoute = _emberRouting.Route.extend({
afterModel: function () {
if (count++ > 10) {
ok(false, 'infinite loop');
} else {
this.transitionTo('bar.baz', model);
}
}
});
App.BarBazRoute = _emberRouting.Route.extend({
setupController: function () {
ok(true, 'Should still invoke setupController');
}
});
bootApplication();
handleURLAborts('/foo/bar/1/baz');
equal((0, _emberUtils.getOwner)(router).lookup('controller:application').get('currentPath'), 'foo.bar.baz');
equal(router.get('location').getURL(), '/foo/bar/2/baz');
});
QUnit.test('Transitioning from a parent event does not prevent currentPath from being set', function () {
Router.map(function () {
this.route('foo', function () {
this.route('bar', { resetNamespace: true }, function () {
this.route('baz');
});
this.route('qux');
});
});
App.FooRoute = _emberRouting.Route.extend({
actions: {
goToQux: function () {
this.transitionTo('foo.qux');
}
}
});
bootApplication();
var applicationController = (0, _emberUtils.getOwner)(router).lookup('controller:application');
handleURL('/foo/bar/baz');
equal(applicationController.get('currentPath'), 'foo.bar.baz');
(0, _emberMetal.run)(function () {
return router.send('goToQux');
});
equal(applicationController.get('currentPath'), 'foo.qux');
equal(router.get('location').getURL(), '/foo/qux');
});
QUnit.test('Generated names can be customized when providing routes with dot notation', function () {
expect(4);
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Index
'));
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('Home {{outlet}}
'));
(0, _emberGlimmer.setTemplate)('foo', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('bar', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('bar/baz', (0, _emberTemplateCompiler.compile)('{{name}}Bottom!
'));
Router.map(function () {
this.route('foo', { path: '/top' }, function () {
this.route('bar', { path: '/middle', resetNamespace: true }, function () {
this.route('baz', { path: '/bottom' });
});
});
});
App.FooRoute = _emberRouting.Route.extend({
renderTemplate: function () {
ok(true, 'FooBarRoute was called');
return this._super.apply(this, arguments);
}
});
App.BarBazRoute = _emberRouting.Route.extend({
renderTemplate: function () {
ok(true, 'BarBazRoute was called');
return this._super.apply(this, arguments);
}
});
App.BarController = _emberRuntime.Controller.extend({
name: 'Bar'
});
App.BarBazController = _emberRuntime.Controller.extend({
name: 'BarBaz'
});
bootApplication();
handleURL('/top/middle/bottom');
equal((0, _emberViews.jQuery)('.main .middle .bottom p', '#qunit-fixture').text(), 'BarBazBottom!', 'The templates were rendered into their appropriate parents');
});
QUnit.test('Child routes render into their parent route\'s template by default', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Index
'));
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('Home {{outlet}}
'));
(0, _emberGlimmer.setTemplate)('top', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('middle', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('middle/bottom', (0, _emberTemplateCompiler.compile)('Bottom!
'));
Router.map(function () {
this.route('top', function () {
this.route('middle', { resetNamespace: true }, function () {
this.route('bottom');
});
});
});
bootApplication();
handleURL('/top/middle/bottom');
equal((0, _emberViews.jQuery)('.main .middle .bottom p', '#qunit-fixture').text(), 'Bottom!', 'The templates were rendered into their appropriate parents');
});
QUnit.test('Child routes render into specified template', function () {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Index
'));
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('Home {{outlet}}
'));
(0, _emberGlimmer.setTemplate)('top', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('middle', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('middle/bottom', (0, _emberTemplateCompiler.compile)('Bottom!
'));
Router.map(function () {
this.route('top', function () {
this.route('middle', { resetNamespace: true }, function () {
this.route('bottom');
});
});
});
App.MiddleBottomRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render('middle/bottom', { into: 'top' });
}
});
bootApplication();
handleURL('/top/middle/bottom');
equal((0, _emberViews.jQuery)('.main .middle .bottom p', '#qunit-fixture').length, 0, 'should not render into the middle template');
equal((0, _emberViews.jQuery)('.main .middle > p', '#qunit-fixture').text(), 'Bottom!', 'The template was rendered into the top template');
});
QUnit.test('Rendering into specified template with slash notation', function () {
(0, _emberGlimmer.setTemplate)('person/profile', (0, _emberTemplateCompiler.compile)('profile {{outlet}}'));
(0, _emberGlimmer.setTemplate)('person/details', (0, _emberTemplateCompiler.compile)('details!'));
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render('person/profile');
this.render('person/details', { into: 'person/profile' });
}
});
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture:contains(profile details!)').length, 1, 'The templates were rendered');
});
QUnit.test('Parent route context change', function () {
var editCount = 0;
var editedPostIds = (0, _emberRuntime.A)();
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('post', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('post/index', (0, _emberTemplateCompiler.compile)('showing'));
(0, _emberGlimmer.setTemplate)('post/edit', (0, _emberTemplateCompiler.compile)('editing'));
Router.map(function () {
this.route('posts', function () {
this.route('post', { path: '/:postId', resetNamespace: true }, function () {
this.route('edit');
});
});
});
App.PostsRoute = _emberRouting.Route.extend({
actions: {
showPost: function (context) {
this.transitionTo('post', context);
}
}
});
App.PostRoute = _emberRouting.Route.extend({
model: function (params) {
return { id: params.postId };
},
serialize: function (model) {
return { postId: model.id };
},
actions: {
editPost: function () {
this.transitionTo('post.edit');
}
}
});
App.PostEditRoute = _emberRouting.Route.extend({
model: function () {
var postId = this.modelFor('post').id;
editedPostIds.push(postId);
return null;
},
setup: function () {
this._super.apply(this, arguments);
editCount++;
}
});
bootApplication();
handleURL('/posts/1');
(0, _emberMetal.run)(function () {
return router.send('editPost');
});
(0, _emberMetal.run)(function () {
return router.send('showPost', { id: '2' });
});
(0, _emberMetal.run)(function () {
return router.send('editPost');
});
equal(editCount, 2, 'set up the edit route twice without failure');
deepEqual(editedPostIds, ['1', '2'], 'modelFor posts.post returns the right context');
});
QUnit.test('Router accounts for rootURL on page load when using history location', function () {
var rootURL = window.location.pathname + '/app';
var postsTemplateRendered = false;
var setHistory = void 0,
HistoryTestLocation = void 0;
setHistory = function (obj, path) {
obj.set('history', { state: { path: path } });
};
// Create new implementation that extends HistoryLocation
// and set current location to rootURL + '/posts'
HistoryTestLocation = _emberRouting.HistoryLocation.extend({
initState: function () {
var path = rootURL + '/posts';
setHistory(this, path);
this.set('location', {
pathname: path,
href: 'http://localhost/' + path
});
},
replaceState: function (path) {
setHistory(this, path);
},
pushState: function (path) {
setHistory(this, path);
}
});
registry.register('location:historyTest', HistoryTestLocation);
Router.reopen({
location: 'historyTest',
rootURL: rootURL
});
Router.map(function () {
this.route('posts', { path: '/posts' });
});
App.PostsRoute = _emberRouting.Route.extend({
model: function () {},
renderTemplate: function () {
postsTemplateRendered = true;
}
});
bootApplication();
ok(postsTemplateRendered, 'Posts route successfully stripped from rootURL');
});
QUnit.test('The rootURL is passed properly to the location implementation', function () {
expect(1);
var rootURL = '/blahzorz';
var HistoryTestLocation = void 0;
HistoryTestLocation = _emberRouting.HistoryLocation.extend({
rootURL: 'this is not the URL you are looking for',
initState: function () {
equal(this.get('rootURL'), rootURL);
}
});
registry.register('location:history-test', HistoryTestLocation);
Router.reopen({
location: 'history-test',
rootURL: rootURL,
_doURLTransition: function () {}
});
bootApplication();
});
QUnit.test('Only use route rendered into main outlet for default into property on child', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet \'menu\'}}{{outlet}}'));
(0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('posts/index', (0, _emberTemplateCompiler.compile)('postsIndex
'));
(0, _emberGlimmer.setTemplate)('posts/menu', (0, _emberTemplateCompiler.compile)(''));
Router.map(function () {
this.route('posts', function () {});
});
App.PostsRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render();
this.render('posts/menu', {
into: 'application',
outlet: 'menu'
});
}
});
bootApplication();
handleURL('/posts');
equal((0, _emberViews.jQuery)('div.posts-menu:contains(postsMenu)', '#qunit-fixture').length, 1, 'The posts/menu template was rendered');
equal((0, _emberViews.jQuery)('p.posts-index:contains(postsIndex)', '#qunit-fixture').length, 1, 'The posts/index template was rendered');
});
QUnit.test('Generating a URL should not affect currentModel', function () {
Router.map(function () {
this.route('post', { path: '/posts/:post_id' });
});
var posts = {
1: { id: 1 },
2: { id: 2 }
};
App.PostRoute = _emberRouting.Route.extend({
model: function (params) {
return posts[params.post_id];
}
});
bootApplication();
handleURL('/posts/1');
var route = container.lookup('route:post');
equal(route.modelFor('post'), posts[1]);
var url = router.generate('post', posts[2]);
equal(url, '/posts/2');
equal(route.modelFor('post'), posts[1]);
});
QUnit.test('Generated route should be an instance of App.Route if provided', function () {
var generatedRoute = void 0;
Router.map(function () {
this.route('posts');
});
App.Route = _emberRouting.Route.extend();
bootApplication();
handleURL('/posts');
generatedRoute = container.lookup('route:posts');
ok(generatedRoute instanceof App.Route, 'should extend the correct route');
});
QUnit.test('Nested index route is not overriden by parent\'s implicit index route', function () {
Router.map(function () {
this.route('posts', function () {
this.route('index', { path: ':category' });
});
});
bootApplication();
(0, _emberMetal.run)(function () {
return router.transitionTo('posts', { category: 'emberjs' });
});
deepEqual(router.location.path, '/posts/emberjs');
});
QUnit.test('Application template does not duplicate when re-rendered', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('I Render Once {{outlet}}'));
Router.map(function () {
this.route('posts');
});
App.ApplicationRoute = _emberRouting.Route.extend({
model: function () {
return (0, _emberRuntime.A)();
}
});
bootApplication();
// should cause application template to re-render
handleURL('/posts');
equal((0, _emberViews.jQuery)('h3:contains(I Render Once)').length, 1);
});
QUnit.test('Child routes should render inside the application template if the application template causes a redirect', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('App {{outlet}}'));
(0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('posts'));
Router.map(function () {
this.route('posts');
this.route('photos');
});
App.ApplicationRoute = _emberRouting.Route.extend({
afterModel: function () {
this.transitionTo('posts');
}
});
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture > div').text(), 'App posts');
});
QUnit.test('The template is not re-rendered when the route\'s context changes', function () {
Router.map(function () {
this.route('page', { path: '/page/:name' });
});
App.PageRoute = _emberRouting.Route.extend({
model: function (params) {
return _emberRuntime.Object.create({ name: params.name });
}
});
var insertionCount = 0;
App.FooBarComponent = _emberGlimmer.Component.extend({
didInsertElement: function () {
insertionCount += 1;
}
});
(0, _emberGlimmer.setTemplate)('page', (0, _emberTemplateCompiler.compile)('{{model.name}}{{foo-bar}}
'));
bootApplication();
handleURL('/page/first');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'first');
equal(insertionCount, 1);
handleURL('/page/second');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'second');
equal(insertionCount, 1, 'view should have inserted only once');
(0, _emberMetal.run)(function () {
return router.transitionTo('page', _emberRuntime.Object.create({ name: 'third' }));
});
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'third');
equal(insertionCount, 1, 'view should still have inserted only once');
});
QUnit.test('The template is not re-rendered when two routes present the exact same template & controller', function () {
Router.map(function () {
this.route('first');
this.route('second');
this.route('third');
this.route('fourth');
});
// Note add a component to test insertion
var insertionCount = 0;
App.XInputComponent = _emberGlimmer.Component.extend({
didInsertElement: function () {
insertionCount += 1;
}
});
App.SharedRoute = _emberRouting.Route.extend({
setupController: function () {
this.controllerFor('shared').set('message', 'This is the ' + this.routeName + ' message');
},
renderTemplate: function () {
this.render('shared', { controller: 'shared' });
}
});
App.FirstRoute = App.SharedRoute.extend();
App.SecondRoute = App.SharedRoute.extend();
App.ThirdRoute = App.SharedRoute.extend();
App.FourthRoute = App.SharedRoute.extend();
App.SharedController = _emberRuntime.Controller.extend();
(0, _emberGlimmer.setTemplate)('shared', (0, _emberTemplateCompiler.compile)('{{message}}{{x-input}}
'));
bootApplication();
handleURL('/first');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'This is the first message');
equal(insertionCount, 1, 'expected one assertion');
// Transition by URL
handleURL('/second');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'This is the second message');
equal(insertionCount, 1, 'expected one assertion');
// Then transition directly by route name
(0, _emberMetal.run)(function () {
router.transitionTo('third').then(function () {
ok(true, 'expected transition');
}, function (reason) {
ok(false, 'unexpected transition failure: ', QUnit.jsDump.parse(reason));
});
});
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'This is the third message');
equal(insertionCount, 1, 'expected one assertion');
// Lastly transition to a different view, with the same controller and template
handleURL('/fourth');
equal(insertionCount, 1, 'expected one assertion');
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'This is the fourth message');
});
QUnit.test('ApplicationRoute with model does not proxy the currentPath', function () {
var model = {};
var currentPath = void 0;
App.ApplicationRoute = _emberRouting.Route.extend({
model: function () {
return model;
}
});
App.ApplicationController = _emberRuntime.Controller.extend({
currentPathDidChange: (0, _emberMetal.observer)('currentPath', function () {
currentPath = (0, _emberMetal.get)(this, 'currentPath');
})
});
bootApplication();
equal(currentPath, 'index', 'currentPath is index');
equal('currentPath' in model, false, 'should have defined currentPath on controller');
});
QUnit.test('Promises encountered on app load put app into loading state until resolved', function () {
expect(2);
var deferred = _emberRuntime.RSVP.defer();
App.IndexRoute = _emberRouting.Route.extend({
model: function () {
return deferred.promise;
}
});
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('INDEX
'));
(0, _emberGlimmer.setTemplate)('loading', (0, _emberTemplateCompiler.compile)('LOADING
'));
bootApplication();
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'LOADING', 'The loading state is displaying.');
(0, _emberMetal.run)(deferred.resolve);
equal((0, _emberViews.jQuery)('p', '#qunit-fixture').text(), 'INDEX', 'The index route is display.');
});
QUnit.test('Route should tear down multiple outlets', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet \'menu\'}}{{outlet}}{{outlet \'footer\'}}'));
(0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('users', (0, _emberTemplateCompiler.compile)('users'));
(0, _emberGlimmer.setTemplate)('posts/index', (0, _emberTemplateCompiler.compile)('postsIndex
'));
(0, _emberGlimmer.setTemplate)('posts/menu', (0, _emberTemplateCompiler.compile)(''));
(0, _emberGlimmer.setTemplate)('posts/footer', (0, _emberTemplateCompiler.compile)(''));
Router.map(function () {
this.route('posts', function () {});
this.route('users', function () {});
});
App.PostsRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render('posts/menu', {
into: 'application',
outlet: 'menu'
});
this.render();
this.render('posts/footer', {
into: 'application',
outlet: 'footer'
});
}
});
bootApplication();
handleURL('/posts');
equal((0, _emberViews.jQuery)('div.posts-menu:contains(postsMenu)', '#qunit-fixture').length, 1, 'The posts/menu template was rendered');
equal((0, _emberViews.jQuery)('p.posts-index:contains(postsIndex)', '#qunit-fixture').length, 1, 'The posts/index template was rendered');
equal((0, _emberViews.jQuery)('div.posts-footer:contains(postsFooter)', '#qunit-fixture').length, 1, 'The posts/footer template was rendered');
handleURL('/users');
equal((0, _emberViews.jQuery)('div.posts-menu:contains(postsMenu)', '#qunit-fixture').length, 0, 'The posts/menu template was removed');
equal((0, _emberViews.jQuery)('p.posts-index:contains(postsIndex)', '#qunit-fixture').length, 0, 'The posts/index template was removed');
equal((0, _emberViews.jQuery)('div.posts-footer:contains(postsFooter)', '#qunit-fixture').length, 0, 'The posts/footer template was removed');
});
QUnit.test('Route will assert if you try to explicitly render {into: ...} a missing template', function () {
expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./);
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render({ into: 'nonexistent' });
}
});
expectAssertion(function () {
return bootApplication();
}, 'You attempted to render into \'nonexistent\' but it was not found');
});
QUnit.test('Route supports clearing outlet explicitly', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}{{outlet \'modal\'}}'));
(0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('users', (0, _emberTemplateCompiler.compile)('users'));
(0, _emberGlimmer.setTemplate)('posts/index', (0, _emberTemplateCompiler.compile)('postsIndex {{outlet}}
'));
(0, _emberGlimmer.setTemplate)('posts/modal', (0, _emberTemplateCompiler.compile)('postsModal
'));
(0, _emberGlimmer.setTemplate)('posts/extra', (0, _emberTemplateCompiler.compile)(''));
Router.map(function () {
this.route('posts', function () {});
this.route('users', function () {});
});
App.PostsRoute = _emberRouting.Route.extend({
actions: {
showModal: function () {
this.render('posts/modal', {
into: 'application',
outlet: 'modal'
});
},
hideModal: function () {
this.disconnectOutlet({ outlet: 'modal', parentView: 'application' });
}
}
});
App.PostsIndexRoute = _emberRouting.Route.extend({
actions: {
showExtra: function () {
this.render('posts/extra', {
into: 'posts/index'
});
},
hideExtra: function () {
this.disconnectOutlet({ parentView: 'posts/index' });
}
}
});
bootApplication();
handleURL('/posts');
equal((0, _emberViews.jQuery)('div.posts-index:contains(postsIndex)', '#qunit-fixture').length, 1, 'The posts/index template was rendered');
(0, _emberMetal.run)(function () {
return router.send('showModal');
});
equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 1, 'The posts/modal template was rendered');
(0, _emberMetal.run)(function () {
return router.send('showExtra');
});
equal((0, _emberViews.jQuery)('div.posts-extra:contains(postsExtra)', '#qunit-fixture').length, 1, 'The posts/extra template was rendered');
(0, _emberMetal.run)(function () {
return router.send('hideModal');
});
equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 0, 'The posts/modal template was removed');
(0, _emberMetal.run)(function () {
return router.send('hideExtra');
});
equal((0, _emberViews.jQuery)('div.posts-extra:contains(postsExtra)', '#qunit-fixture').length, 0, 'The posts/extra template was removed');
(0, _emberMetal.run)(function () {
router.send('showModal');
});
equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 1, 'The posts/modal template was rendered');
(0, _emberMetal.run)(function () {
router.send('showExtra');
});
equal((0, _emberViews.jQuery)('div.posts-extra:contains(postsExtra)', '#qunit-fixture').length, 1, 'The posts/extra template was rendered');
handleURL('/users');
equal((0, _emberViews.jQuery)('div.posts-index:contains(postsIndex)', '#qunit-fixture').length, 0, 'The posts/index template was removed');
equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 0, 'The posts/modal template was removed');
equal((0, _emberViews.jQuery)('div.posts-extra:contains(postsExtra)', '#qunit-fixture').length, 0, 'The posts/extra template was removed');
});
QUnit.test('Route supports clearing outlet using string parameter', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}{{outlet \'modal\'}}'));
(0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('users', (0, _emberTemplateCompiler.compile)('users'));
(0, _emberGlimmer.setTemplate)('posts/index', (0, _emberTemplateCompiler.compile)('postsIndex {{outlet}}
'));
(0, _emberGlimmer.setTemplate)('posts/modal', (0, _emberTemplateCompiler.compile)('postsModal
'));
Router.map(function () {
this.route('posts', function () {});
this.route('users', function () {});
});
App.PostsRoute = _emberRouting.Route.extend({
actions: {
showModal: function () {
this.render('posts/modal', {
into: 'application',
outlet: 'modal'
});
},
hideModal: function () {
this.disconnectOutlet('modal');
}
}
});
bootApplication();
handleURL('/posts');
equal((0, _emberViews.jQuery)('div.posts-index:contains(postsIndex)', '#qunit-fixture').length, 1, 'The posts/index template was rendered');
(0, _emberMetal.run)(function () {
return router.send('showModal');
});
equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 1, 'The posts/modal template was rendered');
(0, _emberMetal.run)(function () {
return router.send('hideModal');
});
equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 0, 'The posts/modal template was removed');
handleURL('/users');
equal((0, _emberViews.jQuery)('div.posts-index:contains(postsIndex)', '#qunit-fixture').length, 0, 'The posts/index template was removed');
equal((0, _emberViews.jQuery)('div.posts-modal:contains(postsModal)', '#qunit-fixture').length, 0, 'The posts/modal template was removed');
});
QUnit.test('Route silently fails when cleaning an outlet from an inactive view', function () {
expect(1); // handleURL
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('{{outlet \'modal\'}}'));
(0, _emberGlimmer.setTemplate)('modal', (0, _emberTemplateCompiler.compile)('A Yo.'));
Router.map(function () {
this.route('posts');
});
App.PostsRoute = _emberRouting.Route.extend({
actions: {
hideSelf: function () {
this.disconnectOutlet({ outlet: 'main', parentView: 'application' });
},
showModal: function () {
this.render('modal', { into: 'posts', outlet: 'modal' });
},
hideModal: function () {
this.disconnectOutlet({ outlet: 'modal', parentView: 'posts' });
}
}
});
bootApplication();
handleURL('/posts');
(0, _emberMetal.run)(function () {
return router.send('showModal');
});
(0, _emberMetal.run)(function () {
return router.send('hideSelf');
});
(0, _emberMetal.run)(function () {
return router.send('hideModal');
});
});
QUnit.test('Router `willTransition` hook passes in cancellable transition', function () {
// Should hit willTransition 3 times, once for the initial route, and then 2 more times
// for the two handleURL calls below
expect(3);
Router.map(function () {
this.route('nork');
this.route('about');
});
Router.reopen({
init: function () {
this._super();
this.on('willTransition', this.testWillTransitionHook);
},
testWillTransitionHook: function (transition, url) {
ok(true, 'willTransition was called ' + url);
transition.abort();
}
});
App.LoadingRoute = _emberRouting.Route.extend({
activate: function () {
ok(false, 'LoadingRoute was not entered');
}
});
App.NorkRoute = _emberRouting.Route.extend({
activate: function () {
ok(false, 'NorkRoute was not entered');
}
});
App.AboutRoute = _emberRouting.Route.extend({
activate: function () {
ok(false, 'AboutRoute was not entered');
}
});
bootApplication();
// Attempted transitions out of index should abort.
(0, _emberMetal.run)(router, 'handleURL', '/nork');
(0, _emberMetal.run)(router, 'handleURL', '/about');
});
QUnit.test('Aborting/redirecting the transition in `willTransition` prevents LoadingRoute from being entered', function () {
expect(8);
Router.map(function () {
this.route('nork');
this.route('about');
});
var redirect = false;
App.IndexRoute = _emberRouting.Route.extend({
actions: {
willTransition: function (transition) {
ok(true, 'willTransition was called');
if (redirect) {
// router.js won't refire `willTransition` for this redirect
this.transitionTo('about');
} else {
transition.abort();
}
}
}
});
var deferred = null;
App.LoadingRoute = _emberRouting.Route.extend({
activate: function () {
ok(deferred, 'LoadingRoute should be entered at this time');
},
deactivate: function () {
ok(true, 'LoadingRoute was exited');
}
});
App.NorkRoute = _emberRouting.Route.extend({
activate: function () {
ok(true, 'NorkRoute was entered');
}
});
App.AboutRoute = _emberRouting.Route.extend({
activate: function () {
ok(true, 'AboutRoute was entered');
},
model: function () {
if (deferred) {
return deferred.promise;
}
}
});
bootApplication();
// Attempted transitions out of index should abort.
(0, _emberMetal.run)(router, 'transitionTo', 'nork');
(0, _emberMetal.run)(router, 'handleURL', '/nork');
// Attempted transitions out of index should redirect to about
redirect = true;
(0, _emberMetal.run)(router, 'transitionTo', 'nork');
(0, _emberMetal.run)(router, 'transitionTo', 'index');
// Redirected transitions out of index to a route with a
// promise model should pause the transition and
// activate LoadingRoute
deferred = _emberRuntime.RSVP.defer();
(0, _emberMetal.run)(router, 'transitionTo', 'nork');
(0, _emberMetal.run)(deferred.resolve);
});
QUnit.test('`didTransition` event fires on the router', function () {
expect(3);
Router.map(function () {
this.route('nork');
});
router = container.lookup('router:main');
router.one('didTransition', function () {
ok(true, 'didTransition fired on initial routing');
});
bootApplication();
router.one('didTransition', function () {
ok(true, 'didTransition fired on the router');
equal(router.get('url'), '/nork', 'The url property is updated by the time didTransition fires');
});
(0, _emberMetal.run)(router, 'transitionTo', 'nork');
});
QUnit.test('`didTransition` can be reopened', function () {
expect(1);
Router.map(function () {
this.route('nork');
});
Router.reopen({
didTransition: function () {
this._super.apply(this, arguments);
ok(true, 'reopened didTransition was called');
}
});
bootApplication();
});
QUnit.test('`activate` event fires on the route', function () {
expect(2);
var eventFired = 0;
Router.map(function () {
this.route('nork');
});
App.NorkRoute = _emberRouting.Route.extend({
init: function () {
this._super.apply(this, arguments);
this.on('activate', function () {
equal(++eventFired, 1, 'activate event is fired once');
});
},
activate: function () {
ok(true, 'activate hook is called');
}
});
bootApplication();
(0, _emberMetal.run)(router, 'transitionTo', 'nork');
});
QUnit.test('`deactivate` event fires on the route', function () {
expect(2);
var eventFired = 0;
Router.map(function () {
this.route('nork');
this.route('dork');
});
App.NorkRoute = _emberRouting.Route.extend({
init: function () {
this._super.apply(this, arguments);
this.on('deactivate', function () {
equal(++eventFired, 1, 'deactivate event is fired once');
});
},
deactivate: function () {
ok(true, 'deactivate hook is called');
}
});
bootApplication();
(0, _emberMetal.run)(router, 'transitionTo', 'nork');
(0, _emberMetal.run)(router, 'transitionTo', 'dork');
});
QUnit.test('Actions can be handled by inherited action handlers', function () {
expect(4);
App.SuperRoute = _emberRouting.Route.extend({
actions: {
foo: function () {
ok(true, 'foo');
},
bar: function (msg) {
equal(msg, 'HELLO');
}
}
});
App.RouteMixin = _emberMetal.Mixin.create({
actions: {
bar: function (msg) {
equal(msg, 'HELLO');
this._super(msg);
}
}
});
App.IndexRoute = App.SuperRoute.extend(App.RouteMixin, {
actions: {
baz: function () {
ok(true, 'baz');
}
}
});
bootApplication();
router.send('foo');
router.send('bar', 'HELLO');
router.send('baz');
});
QUnit.test('transitionTo returns Transition when passed a route name', function () {
expect(1);
Router.map(function () {
this.route('root', { path: '/' });
this.route('bar');
});
bootApplication();
var transition = (0, _emberMetal.run)(function () {
return router.transitionTo('bar');
});
equal(transition instanceof _router.Transition, true);
});
QUnit.test('transitionTo returns Transition when passed a url', function () {
expect(1);
Router.map(function () {
this.route('root', { path: '/' });
this.route('bar', function () {
this.route('baz');
});
});
bootApplication();
var transition = (0, _emberMetal.run)(function () {
return router.transitionTo('/bar/baz');
});
equal(transition instanceof _router.Transition, true);
});
QUnit.test('currentRouteName is a property installed on ApplicationController that can be used in transitionTo', function () {
expect(24);
Router.map(function () {
this.route('be', function () {
this.route('excellent', { resetNamespace: true }, function () {
this.route('to', { resetNamespace: true }, function () {
this.route('each', { resetNamespace: true }, function () {
this.route('other');
});
});
});
});
});
bootApplication();
var appController = (0, _emberUtils.getOwner)(router).lookup('controller:application');
function transitionAndCheck(path, expectedPath, expectedRouteName) {
if (path) {
(0, _emberMetal.run)(router, 'transitionTo', path);
}
equal(appController.get('currentPath'), expectedPath);
equal(appController.get('currentRouteName'), expectedRouteName);
}
transitionAndCheck(null, 'index', 'index');
transitionAndCheck('/be', 'be.index', 'be.index');
transitionAndCheck('/be/excellent', 'be.excellent.index', 'excellent.index');
transitionAndCheck('/be/excellent/to', 'be.excellent.to.index', 'to.index');
transitionAndCheck('/be/excellent/to/each', 'be.excellent.to.each.index', 'each.index');
transitionAndCheck('/be/excellent/to/each/other', 'be.excellent.to.each.other', 'each.other');
transitionAndCheck('index', 'index', 'index');
transitionAndCheck('be', 'be.index', 'be.index');
transitionAndCheck('excellent', 'be.excellent.index', 'excellent.index');
transitionAndCheck('to.index', 'be.excellent.to.index', 'to.index');
transitionAndCheck('each', 'be.excellent.to.each.index', 'each.index');
transitionAndCheck('each.other', 'be.excellent.to.each.other', 'each.other');
});
QUnit.test('Route model hook finds the same model as a manual find', function () {
var Post = void 0;
App.Post = _emberRuntime.Object.extend();
App.Post.reopenClass({
find: function () {
Post = this;
return {};
}
});
Router.map(function () {
this.route('post', { path: '/post/:post_id' });
});
bootApplication();
handleURL('/post/1');
equal(App.Post, Post);
});
QUnit.test('Routes can refresh themselves causing their model hooks to be re-run', function () {
Router.map(function () {
this.route('parent', { path: '/parent/:parent_id' }, function () {
this.route('child');
});
});
var appcount = 0;
App.ApplicationRoute = _emberRouting.Route.extend({
model: function () {
++appcount;
}
});
var parentcount = 0;
App.ParentRoute = _emberRouting.Route.extend({
model: function (params) {
equal(params.parent_id, '123');
++parentcount;
},
actions: {
refreshParent: function () {
this.refresh();
}
}
});
var childcount = 0;
App.ParentChildRoute = _emberRouting.Route.extend({
model: function () {
++childcount;
}
});
bootApplication();
equal(appcount, 1);
equal(parentcount, 0);
equal(childcount, 0);
(0, _emberMetal.run)(router, 'transitionTo', 'parent.child', '123');
equal(appcount, 1);
equal(parentcount, 1);
equal(childcount, 1);
(0, _emberMetal.run)(router, 'send', 'refreshParent');
equal(appcount, 1);
equal(parentcount, 2);
equal(childcount, 2);
});
QUnit.test('Specifying non-existent controller name in route#render throws', function () {
expect(1);
Router.map(function () {
this.route('home', { path: '/' });
});
App.HomeRoute = _emberRouting.Route.extend({
renderTemplate: function () {
try {
this.render('homepage', { controller: 'stefanpenneristhemanforme' });
} catch (e) {
equal(e.message, 'You passed `controller: \'stefanpenneristhemanforme\'` into the `render` method, but no such controller could be found.');
}
}
});
bootApplication();
});
QUnit.test('Redirecting with null model doesn\'t error out', function () {
Router.map(function () {
this.route('home', { path: '/' });
this.route('about', { path: '/about/:hurhurhur' });
});
App.AboutRoute = _emberRouting.Route.extend({
serialize: function (model) {
if (model === null) {
return { hurhurhur: 'TreeklesMcGeekles' };
}
}
});
App.HomeRoute = _emberRouting.Route.extend({
beforeModel: function () {
this.transitionTo('about', null);
}
});
bootApplication();
equal(router.get('location.path'), '/about/TreeklesMcGeekles');
});
QUnit.test('rejecting the model hooks promise with a non-error prints the `message` property', function () {
expect(5);
var rejectedMessage = 'OMG!! SOOOOOO BAD!!!!';
var rejectedStack = 'Yeah, buddy: stack gets printed too.';
Router.map(function () {
this.route('yippie', { path: '/' });
});
_emberConsole.default.error = function (initialMessage, errorMessage, errorStack) {
equal(initialMessage, 'Error while processing route: yippie', 'a message with the current route name is printed');
equal(errorMessage, rejectedMessage, 'the rejected reason\'s message property is logged');
equal(errorStack, rejectedStack, 'the rejected reason\'s stack property is logged');
};
App.YippieRoute = _emberRouting.Route.extend({
model: function () {
return _emberRuntime.RSVP.reject({ message: rejectedMessage, stack: rejectedStack });
}
});
throws(function () {
bootApplication();
}, function (err) {
equal(err.message, rejectedMessage);
return true;
}, 'expected an exception');
});
QUnit.test('rejecting the model hooks promise with an error with `errorThrown` property prints `errorThrown.message` property', function () {
expect(5);
var rejectedMessage = 'OMG!! SOOOOOO BAD!!!!';
var rejectedStack = 'Yeah, buddy: stack gets printed too.';
Router.map(function () {
this.route('yippie', { path: '/' });
});
_emberConsole.default.error = function (initialMessage, errorMessage, errorStack) {
equal(initialMessage, 'Error while processing route: yippie', 'a message with the current route name is printed');
equal(errorMessage, rejectedMessage, 'the rejected reason\'s message property is logged');
equal(errorStack, rejectedStack, 'the rejected reason\'s stack property is logged');
};
App.YippieRoute = _emberRouting.Route.extend({
model: function () {
return _emberRuntime.RSVP.reject({
errorThrown: { message: rejectedMessage, stack: rejectedStack }
});
}
});
throws(function () {
return bootApplication();
}, function (err) {
equal(err.message, rejectedMessage);
return true;
}, 'expected an exception');
});
QUnit.test('rejecting the model hooks promise with no reason still logs error', function () {
Router.map(function () {
this.route('wowzers', { path: '/' });
});
_emberConsole.default.error = function (initialMessage) {
equal(initialMessage, 'Error while processing route: wowzers', 'a message with the current route name is printed');
};
App.WowzersRoute = _emberRouting.Route.extend({
model: function () {
return _emberRuntime.RSVP.reject();
}
});
bootApplication();
});
QUnit.test('rejecting the model hooks promise with a string shows a good error', function () {
expect(3);
var originalLoggerError = _emberConsole.default.error;
var rejectedMessage = 'Supercalifragilisticexpialidocious';
Router.map(function () {
this.route('yondo', { path: '/' });
});
_emberConsole.default.error = function (initialMessage, errorMessage) {
equal(initialMessage, 'Error while processing route: yondo', 'a message with the current route name is printed');
equal(errorMessage, rejectedMessage, 'the rejected reason\'s message property is logged');
};
App.YondoRoute = _emberRouting.Route.extend({
model: function () {
return _emberRuntime.RSVP.reject(rejectedMessage);
}
});
throws(function () {
return bootApplication();
}, rejectedMessage, 'expected an exception');
_emberConsole.default.error = originalLoggerError;
});
QUnit.test('willLeave, willChangeContext, willChangeModel actions don\'t fire unless feature flag enabled', function () {
expect(1);
App.Router.map(function () {
this.route('about');
});
function shouldNotFire() {
ok(false, 'this action shouldn\'t have been received');
}
App.IndexRoute = _emberRouting.Route.extend({
actions: {
willChangeModel: shouldNotFire,
willChangeContext: shouldNotFire,
willLeave: shouldNotFire
}
});
App.AboutRoute = _emberRouting.Route.extend({
setupController: function () {
ok(true, 'about route was entered');
}
});
bootApplication();
(0, _emberMetal.run)(router, 'transitionTo', 'about');
});
QUnit.test('Errors in transitionTo within redirect hook are logged', function () {
expect(4);
var actual = [];
Router.map(function () {
this.route('yondo', { path: '/' });
this.route('stink-bomb');
});
App.YondoRoute = _emberRouting.Route.extend({
redirect: function () {
this.transitionTo('stink-bomb', { something: 'goes boom' });
}
});
_emberConsole.default.error = function () {
// push the arguments onto an array so we can detect if the error gets logged twice
actual.push(arguments);
};
throws(function () {
return bootApplication();
}, /More context objects were passed/);
equal(actual.length, 1, 'the error is only logged once');
equal(actual[0][0], 'Error while processing route: yondo', 'source route is printed');
ok(actual[0][1].match(/More context objects were passed than there are dynamic segments for the route: stink-bomb/), 'the error is printed');
});
QUnit.test('Errors in transition show error template if available', function () {
(0, _emberGlimmer.setTemplate)('error', (0, _emberTemplateCompiler.compile)('Error!
'));
Router.map(function () {
this.route('yondo', { path: '/' });
this.route('stink-bomb');
});
App.YondoRoute = _emberRouting.Route.extend({
redirect: function () {
this.transitionTo('stink-bomb', { something: 'goes boom' });
}
});
throws(function () {
return bootApplication();
}, /More context objects were passed/);
equal((0, _emberViews.jQuery)('#error').length, 1, 'Error template was rendered.');
});
QUnit.test('Route#resetController gets fired when changing models and exiting routes', function () {
expect(4);
Router.map(function () {
this.route('a', function () {
this.route('b', { path: '/b/:id', resetNamespace: true }, function () {});
this.route('c', { path: '/c/:id', resetNamespace: true }, function () {});
});
this.route('out');
});
var calls = [];
var SpyRoute = _emberRouting.Route.extend({
setupController: function () {
calls.push(['setup', this.routeName]);
},
resetController: function () {
calls.push(['reset', this.routeName]);
}
});
App.ARoute = SpyRoute.extend();
App.BRoute = SpyRoute.extend();
App.CRoute = SpyRoute.extend();
App.OutRoute = SpyRoute.extend();
bootApplication();
deepEqual(calls, []);
(0, _emberMetal.run)(router, 'transitionTo', 'b', 'b-1');
deepEqual(calls, [['setup', 'a'], ['setup', 'b']]);
calls.length = 0;
(0, _emberMetal.run)(router, 'transitionTo', 'c', 'c-1');
deepEqual(calls, [['reset', 'b'], ['setup', 'c']]);
calls.length = 0;
(0, _emberMetal.run)(router, 'transitionTo', 'out');
deepEqual(calls, [['reset', 'c'], ['reset', 'a'], ['setup', 'out']]);
});
QUnit.test('Exception during initialization of non-initial route is not swallowed', function () {
Router.map(function () {
this.route('boom');
});
App.BoomRoute = _emberRouting.Route.extend({
init: function () {
throw new Error('boom!');
}
});
bootApplication();
throws(function () {
return (0, _emberMetal.run)(router, 'transitionTo', 'boom');
}, /\bboom\b/);
});
QUnit.test('Exception during load of non-initial route is not swallowed', function () {
Router.map(function () {
this.route('boom');
});
var lookup = container.lookup;
container.lookup = function () {
if (arguments[0] === 'route:boom') {
throw new Error('boom!');
}
return lookup.apply(this, arguments);
};
App.BoomRoute = _emberRouting.Route.extend({
init: function () {
throw new Error('boom!');
}
});
bootApplication();
throws(function () {
return (0, _emberMetal.run)(router, 'transitionTo', 'boom');
});
});
QUnit.test('Exception during initialization of initial route is not swallowed', function () {
Router.map(function () {
this.route('boom', { path: '/' });
});
App.BoomRoute = _emberRouting.Route.extend({
init: function () {
throw new Error('boom!');
}
});
throws(function () {
return bootApplication();
}, /\bboom\b/);
});
QUnit.test('Exception during load of initial route is not swallowed', function () {
Router.map(function () {
this.route('boom', { path: '/' });
});
var lookup = container.lookup;
container.lookup = function () {
if (arguments[0] === 'route:boom') {
throw new Error('boom!');
}
return lookup.apply(this, arguments);
};
App.BoomRoute = _emberRouting.Route.extend({
init: function () {
throw new Error('boom!');
}
});
throws(function () {
return bootApplication();
}, /\bboom\b/);
});
QUnit.test('{{outlet}} works when created after initial render', function () {
(0, _emberGlimmer.setTemplate)('sample', (0, _emberTemplateCompiler.compile)('Hi{{#if showTheThing}}{{outlet}}{{/if}}Bye'));
(0, _emberGlimmer.setTemplate)('sample/inner', (0, _emberTemplateCompiler.compile)('Yay'));
(0, _emberGlimmer.setTemplate)('sample/inner2', (0, _emberTemplateCompiler.compile)('Boo'));
Router.map(function () {
this.route('sample', { path: '/' }, function () {
this.route('inner', { path: '/' });
this.route('inner2', { path: '/2' });
});
});
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'HiBye', 'initial render');
(0, _emberMetal.run)(function () {
return container.lookup('controller:sample').set('showTheThing', true);
});
equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'HiYayBye', 'second render');
handleURL('/2');
equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'HiBooBye', 'third render');
});
QUnit.test('Can render into a named outlet at the top level', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('A-{{outlet}}-B-{{outlet "other"}}-C'));
(0, _emberGlimmer.setTemplate)('modal', (0, _emberTemplateCompiler.compile)('Hello world'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('The index'));
registry.register('route:application', _emberRouting.Route.extend({
renderTemplate: function () {
this.render();
this.render('modal', {
into: 'application',
outlet: 'other'
});
}
}));
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A-The index-B-Hello world-C', 'initial render');
});
QUnit.test('Can disconnect a named outlet at the top level', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('A-{{outlet}}-B-{{outlet "other"}}-C'));
(0, _emberGlimmer.setTemplate)('modal', (0, _emberTemplateCompiler.compile)('Hello world'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('The index'));
registry.register('route:application', _emberRouting.Route.extend({
renderTemplate: function () {
this.render();
this.render('modal', {
into: 'application',
outlet: 'other'
});
},
actions: {
banish: function () {
this.disconnectOutlet({
parentView: 'application',
outlet: 'other'
});
}
}
}));
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A-The index-B-Hello world-C', 'initial render');
(0, _emberMetal.run)(router, 'send', 'banish');
equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A-The index-B--C', 'second render');
});
QUnit.test('Can render into a named outlet at the top level, with empty main outlet', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('A-{{outlet}}-B-{{outlet "other"}}-C'));
(0, _emberGlimmer.setTemplate)('modal', (0, _emberTemplateCompiler.compile)('Hello world'));
Router.map(function () {
this.route('hasNoTemplate', { path: '/' });
});
registry.register('route:application', _emberRouting.Route.extend({
renderTemplate: function () {
this.render();
this.render('modal', {
into: 'application',
outlet: 'other'
});
}
}));
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A--B-Hello world-C', 'initial render');
});
QUnit.test('Can render into a named outlet at the top level, later', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('A-{{outlet}}-B-{{outlet "other"}}-C'));
(0, _emberGlimmer.setTemplate)('modal', (0, _emberTemplateCompiler.compile)('Hello world'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('The index'));
registry.register('route:application', _emberRouting.Route.extend({
actions: {
launch: function () {
this.render('modal', {
into: 'application',
outlet: 'other'
});
}
}
}));
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A-The index-B--C', 'initial render');
(0, _emberMetal.run)(router, 'send', 'launch');
equal((0, _emberViews.jQuery)('#qunit-fixture').text(), 'A-The index-B-Hello world-C', 'second render');
});
QUnit.test('Can render routes with no \'main\' outlet and their children', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet "app"}}
'));
(0, _emberGlimmer.setTemplate)('app', (0, _emberTemplateCompiler.compile)('{{outlet "common"}}
{{outlet "sub"}}
'));
(0, _emberGlimmer.setTemplate)('common', (0, _emberTemplateCompiler.compile)('
'));
(0, _emberGlimmer.setTemplate)('sub', (0, _emberTemplateCompiler.compile)('
'));
Router.map(function () {
this.route('app', { path: '/app' }, function () {
this.route('sub', { path: '/sub', resetNamespace: true });
});
});
App.AppRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render('app', {
outlet: 'app',
into: 'application'
});
this.render('common', {
outlet: 'common',
into: 'app'
});
}
});
App.SubRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render('sub', {
outlet: 'sub',
into: 'app'
});
}
});
bootApplication();
handleURL('/app');
equal((0, _emberViews.jQuery)('#app-common #common').length, 1, 'Finds common while viewing /app');
handleURL('/app/sub');
equal((0, _emberViews.jQuery)('#app-common #common').length, 1, 'Finds common while viewing /app/sub');
equal((0, _emberViews.jQuery)('#app-sub #sub').length, 1, 'Finds sub while viewing /app/sub');
});
QUnit.test('Tolerates stacked renders', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}{{outlet "modal"}}'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('hi'));
(0, _emberGlimmer.setTemplate)('layer', (0, _emberTemplateCompiler.compile)('layer'));
App.ApplicationRoute = _emberRouting.Route.extend({
actions: {
openLayer: function () {
this.render('layer', {
into: 'application',
outlet: 'modal'
});
},
close: function () {
this.disconnectOutlet({
outlet: 'modal',
parentView: 'application'
});
}
}
});
bootApplication();
equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hi');
(0, _emberMetal.run)(router, 'send', 'openLayer');
equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hilayer');
(0, _emberMetal.run)(router, 'send', 'openLayer');
equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hilayer');
(0, _emberMetal.run)(router, 'send', 'close');
equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hi');
});
QUnit.test('Renders child into parent with non-default template name', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('exports/root', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('exports/index', (0, _emberTemplateCompiler.compile)('
'));
Router.map(function () {
this.route('root', function () {});
});
App.RootRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render('exports/root');
}
});
App.RootIndexRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render('exports/index');
}
});
bootApplication();
handleURL('/root');
equal((0, _emberViews.jQuery)('#qunit-fixture .a .b .c').length, 1);
});
QUnit.test('Allows any route to disconnectOutlet another route\'s templates', function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}{{outlet "modal"}}'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('hi'));
(0, _emberGlimmer.setTemplate)('layer', (0, _emberTemplateCompiler.compile)('layer'));
App.ApplicationRoute = _emberRouting.Route.extend({
actions: {
openLayer: function () {
this.render('layer', {
into: 'application',
outlet: 'modal'
});
}
}
});
App.IndexRoute = _emberRouting.Route.extend({
actions: {
close: function () {
this.disconnectOutlet({
parentView: 'application',
outlet: 'modal'
});
}
}
});
bootApplication();
equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hi');
(0, _emberMetal.run)(router, 'send', 'openLayer');
equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hilayer');
(0, _emberMetal.run)(router, 'send', 'close');
equal(trim((0, _emberViews.jQuery)('#qunit-fixture').text()), 'hi');
});
QUnit.test('Can this.render({into:...}) the render helper', function () {
expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./);
expectDeprecation(function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}'));
}, /Please refactor [\w\{\}"` ]+ to a component/);
(0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)(''));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('other'));
(0, _emberGlimmer.setTemplate)('bar', (0, _emberTemplateCompiler.compile)('bar'));
App.IndexRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render({ into: 'sidebar' });
},
actions: {
changeToBar: function () {
this.disconnectOutlet({
parentView: 'sidebar',
outlet: 'main'
});
this.render('bar', { into: 'sidebar' });
}
}
});
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar').text(), 'other');
(0, _emberMetal.run)(router, 'send', 'changeToBar');
equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar').text(), 'bar');
});
QUnit.test('Can disconnect from the render helper', function () {
expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./);
expectDeprecation(function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}'));
}, /Please refactor [\w\{\}"` ]+ to a component/);
(0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)(''));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('other'));
App.IndexRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render({ into: 'sidebar' });
},
actions: {
disconnect: function () {
this.disconnectOutlet({
parentView: 'sidebar',
outlet: 'main'
});
}
}
});
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar').text(), 'other');
(0, _emberMetal.run)(router, 'send', 'disconnect');
equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar').text(), '');
});
QUnit.test('Can this.render({into:...}) the render helper\'s children', function () {
expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./);
expectDeprecation(function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}'));
}, /Please refactor [\w\{\}"` ]+ to a component/);
(0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)(''));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('other', (0, _emberTemplateCompiler.compile)('other'));
(0, _emberGlimmer.setTemplate)('bar', (0, _emberTemplateCompiler.compile)('bar'));
App.IndexRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render({ into: 'sidebar' });
this.render('other', { into: 'index' });
},
actions: {
changeToBar: function () {
this.disconnectOutlet({
parentView: 'index',
outlet: 'main'
});
this.render('bar', { into: 'index' });
}
}
});
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar .index').text(), 'other');
(0, _emberMetal.run)(router, 'send', 'changeToBar');
equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar .index').text(), 'bar');
});
QUnit.test('Can disconnect from the render helper\'s children', function () {
expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./);
expectDeprecation(function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}'));
}, /Please refactor [\w\{\}"` ]+ to a component/);
(0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)(''));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('other', (0, _emberTemplateCompiler.compile)('other'));
App.IndexRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render({ into: 'sidebar' });
this.render('other', { into: 'index' });
},
actions: {
disconnect: function () {
this.disconnectOutlet({
parentView: 'index',
outlet: 'main'
});
}
}
});
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar .index').text(), 'other');
(0, _emberMetal.run)(router, 'send', 'disconnect');
equal((0, _emberViews.jQuery)('#qunit-fixture .sidebar .index').text(), '');
});
QUnit.test('Can this.render({into:...}) nested render helpers', function () {
expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./);
expectDeprecation(function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}'));
}, /Please refactor [\w\{\}"` ]+ to a component/);
expectDeprecation(function () {
(0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)(''));
}, /Please refactor [\w\{\}"` ]+ to a component/);
(0, _emberGlimmer.setTemplate)('cart', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('other'));
(0, _emberGlimmer.setTemplate)('baz', (0, _emberTemplateCompiler.compile)('baz'));
App.IndexRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render({ into: 'cart' });
},
actions: {
changeToBaz: function () {
this.disconnectOutlet({
parentView: 'cart',
outlet: 'main'
});
this.render('baz', { into: 'cart' });
}
}
});
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture .cart').text(), 'other');
(0, _emberMetal.run)(router, 'send', 'changeToBaz');
equal((0, _emberViews.jQuery)('#qunit-fixture .cart').text(), 'baz');
});
QUnit.test('Can disconnect from nested render helpers', function () {
expectDeprecation(/Rendering into a {{render}} helper that resolves to an {{outlet}} is deprecated./);
expectDeprecation(function () {
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{render "sidebar"}}'));
}, /Please refactor [\w\{\}"` ]+ to a component/);
expectDeprecation(function () {
(0, _emberGlimmer.setTemplate)('sidebar', (0, _emberTemplateCompiler.compile)(''));
}, /Please refactor [\w\{\}"` ]+ to a component/);
(0, _emberGlimmer.setTemplate)('cart', (0, _emberTemplateCompiler.compile)('{{outlet}}
'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('other'));
App.IndexRoute = _emberRouting.Route.extend({
renderTemplate: function () {
this.render({ into: 'cart' });
},
actions: {
disconnect: function () {
this.disconnectOutlet({
parentView: 'cart',
outlet: 'main'
});
}
}
});
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture .cart').text(), 'other');
(0, _emberMetal.run)(router, 'send', 'disconnect');
equal((0, _emberViews.jQuery)('#qunit-fixture .cart').text(), '');
});
QUnit.test('Components inside an outlet have their didInsertElement hook invoked when the route is displayed', function (assert) {
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('{{#if showFirst}}{{my-component}}{{else}}{{other-component}}{{/if}}'));
var myComponentCounter = 0;
var otherComponentCounter = 0;
var indexController = void 0;
App.IndexController = _emberRuntime.Controller.extend({
showFirst: true
});
App.IndexRoute = _emberRouting.Route.extend({
setupController: function (controller) {
indexController = controller;
}
});
App.MyComponentComponent = _emberGlimmer.Component.extend({
didInsertElement: function () {
myComponentCounter++;
}
});
App.OtherComponentComponent = _emberGlimmer.Component.extend({
didInsertElement: function () {
otherComponentCounter++;
}
});
bootApplication();
assert.strictEqual(myComponentCounter, 1, 'didInsertElement invoked on displayed component');
assert.strictEqual(otherComponentCounter, 0, 'didInsertElement not invoked on displayed component');
(0, _emberMetal.run)(function () {
return indexController.set('showFirst', false);
});
assert.strictEqual(myComponentCounter, 1, 'didInsertElement not invoked on displayed component');
assert.strictEqual(otherComponentCounter, 1, 'didInsertElement invoked on displayed component');
});
QUnit.test('Doesnt swallow exception thrown from willTransition', function () {
expect(1);
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('index'));
(0, _emberGlimmer.setTemplate)('other', (0, _emberTemplateCompiler.compile)('other'));
Router.map(function () {
this.route('other', function () {});
});
App.IndexRoute = _emberRouting.Route.extend({
actions: {
willTransition: function () {
throw new Error('boom');
}
}
});
bootApplication();
throws(function () {
(0, _emberMetal.run)(function () {
return router.handleURL('/other');
});
}, /boom/, 'expected an exception but none was thrown');
});
QUnit.test('Exception if outlet name is undefined in render and disconnectOutlet', function () {
App.ApplicationRoute = _emberRouting.Route.extend({
actions: {
showModal: function () {
this.render({
outlet: undefined,
parentView: 'application'
});
},
hideModal: function () {
this.disconnectOutlet({
outlet: undefined,
parentView: 'application'
});
}
}
});
bootApplication();
throws(function () {
(0, _emberMetal.run)(function () {
return router.send('showModal');
});
}, /You passed undefined as the outlet name/);
throws(function () {
(0, _emberMetal.run)(function () {
return router.send('hideModal');
});
}, /You passed undefined as the outlet name/);
});
QUnit.test('Route serializers work for Engines', function () {
expect(2);
// Register engine
var BlogEngine = _emberApplication.Engine.extend();
registry.register('engine:blog', BlogEngine);
// Register engine route map
var postSerialize = function (params) {
ok(true, 'serialize hook runs');
return {
post_id: params.id
};
};
registry.register('route-map:blog', function () {
this.route('post', { path: '/post/:post_id', serialize: postSerialize });
});
Router.map(function () {
this.mount('blog');
});
bootApplication();
equal(router._routerMicrolib.generate('blog.post', { id: '13' }), '/blog/post/13', 'url is generated properly');
});
QUnit.test('Defining a Route#serialize method in an Engine throws an error', function () {
expect(1);
// Register engine
var BlogEngine = _emberApplication.Engine.extend();
registry.register('engine:blog', BlogEngine);
// Register engine route map
registry.register('route-map:blog', function () {
this.route('post');
});
Router.map(function () {
this.mount('blog');
});
bootApplication();
var PostRoute = _emberRouting.Route.extend({
serialize: function () {}
});
container.lookup('engine:blog').register('route:post', PostRoute);
throws(function () {
return router.transitionTo('blog.post');
}, /Defining a custom serialize method on an Engine route is not supported/);
});
QUnit.test('App.destroy does not leave undestroyed views after clearing engines', function () {
expect(4);
var engineInstance = void 0;
// Register engine
var BlogEngine = _emberApplication.Engine.extend();
registry.register('engine:blog', BlogEngine);
var EngineIndexRoute = _emberRouting.Route.extend({
init: function () {
this._super.apply(this, arguments);
engineInstance = (0, _emberUtils.getOwner)(this);
}
});
// Register engine route map
registry.register('route-map:blog', function () {
this.route('post');
});
Router.map(function () {
this.mount('blog');
});
bootApplication();
var engine = container.lookup('engine:blog');
engine.register('route:index', EngineIndexRoute);
engine.register('template:index', (0, _emberTemplateCompiler.compile)('Engine Post!'));
handleURL('/blog');
var route = engineInstance.lookup('route:index');
(0, _emberMetal.run)(router, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was cleared');
(0, _emberMetal.run)(route, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was not reinitialized');
(0, _emberMetal.run)(App, 'destroy');
equal(router._toplevelView, null, 'the toplevelView was not reinitialized');
});
});
enifed('ember/tests/routing/query_params_test', ['ember-babel', 'ember-runtime', 'ember-metal', 'ember-routing', 'ember-views', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberMetal, _emberRouting, _emberViews, _internalTestHelpers) {
'use strict';
(0, _internalTestHelpers.moduleFor)('Query Params - main', function (_QueryParamTestCase) {
(0, _emberBabel.inherits)(_class, _QueryParamTestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments));
}
_class.prototype.refreshModelWhileLoadingTest = function (loadingReturn) {
var _actions,
_this2 = this;
var assert = this.assert;
assert.expect(9);
var appModelCount = 0;
var promiseResolve = void 0;
this.add('route:application', _emberRouting.Route.extend({
queryParams: {
appomg: {
defaultValue: 'applol'
}
},
model: function () {
appModelCount++;
}
}));
this.setSingleQPController('index', 'omg', undefined, {
omg: undefined
});
var actionName = typeof loadingReturn !== 'undefined' ? 'loading' : 'ignore';
var indexModelCount = 0;
this.add('route:index', _emberRouting.Route.extend({
queryParams: {
omg: {
refreshModel: true
}
},
actions: (_actions = {}, _actions[actionName] = function () {
return loadingReturn;
}, _actions),
model: function (params) {
indexModelCount++;
if (indexModelCount === 2) {
assert.deepEqual(params, { omg: 'lex' });
return new _emberRuntime.RSVP.Promise(function (resolve) {
promiseResolve = resolve;
});
} else if (indexModelCount === 3) {
assert.deepEqual(params, { omg: 'hello' }, 'Model hook reruns even if the previous one didn\'t finish');
}
}
}));
return this.visit('/').then(function () {
assert.equal(appModelCount, 1, 'appModelCount is 1');
assert.equal(indexModelCount, 1);
var indexController = _this2.getController('index');
_this2.setAndFlush(indexController, 'omg', 'lex');
assert.equal(appModelCount, 1, 'appModelCount is 1');
assert.equal(indexModelCount, 2);
_this2.setAndFlush(indexController, 'omg', 'hello');
assert.equal(appModelCount, 1, 'appModelCount is 1');
assert.equal(indexModelCount, 3);
(0, _emberMetal.run)(function () {
promiseResolve();
});
assert.equal((0, _emberMetal.get)(indexController, 'omg'), 'hello', 'At the end last value prevails');
});
};
_class.prototype['@test No replaceURL occurs on startup because default values don\'t show up in URL'] = function (assert) {
assert.expect(1);
this.setSingleQPController('index');
return this.visitAndAssert('/');
};
_class.prototype['@test Calling transitionTo does not lose query params already on the activeTransition'] = function (assert) {
var _this3 = this;
assert.expect(2);
this.router.map(function () {
this.route('parent', function () {
this.route('child');
this.route('sibling');
});
});
this.add('route:parent.child', _emberRouting.Route.extend({
afterModel: function () {
this.transitionTo('parent.sibling');
}
}));
this.setSingleQPController('parent');
return this.visit('/parent/child?foo=lol').then(function () {
_this3.assertCurrentPath('/parent/sibling?foo=lol', 'redirected to the sibling route, instead of child route');
assert.equal(_this3.getController('parent').get('foo'), 'lol', 'controller has value from the active transition');
});
};
_class.prototype['@test Single query params can be set on the controller and reflected in the url'] = function (assert) {
var _this4 = this;
assert.expect(3);
this.router.map(function () {
this.route('home', { path: '/' });
});
this.setSingleQPController('home');
return this.visitAndAssert('/').then(function () {
var controller = _this4.getController('home');
_this4.setAndFlush(controller, 'foo', '456');
_this4.assertCurrentPath('/?foo=456');
_this4.setAndFlush(controller, 'foo', '987');
_this4.assertCurrentPath('/?foo=987');
});
};
_class.prototype['@test Query params can map to different url keys configured on the controller'] = function (assert) {
var _this5 = this;
assert.expect(6);
this.add('controller:index', _emberRuntime.Controller.extend({
queryParams: [{ foo: 'other_foo', bar: { as: 'other_bar' } }],
foo: 'FOO',
bar: 'BAR'
}));
return this.visitAndAssert('/').then(function () {
var controller = _this5.getController('index');
_this5.setAndFlush(controller, 'foo', 'LEX');
_this5.assertCurrentPath('/?other_foo=LEX', 'QP mapped correctly without \'as\'');
_this5.setAndFlush(controller, 'foo', 'WOO');
_this5.assertCurrentPath('/?other_foo=WOO', 'QP updated correctly without \'as\'');
_this5.transitionTo('/?other_foo=NAW');
assert.equal(controller.get('foo'), 'NAW', 'QP managed correctly on URL transition');
_this5.setAndFlush(controller, 'bar', 'NERK');
_this5.assertCurrentPath('/?other_bar=NERK&other_foo=NAW', 'QP mapped correctly with \'as\'');
_this5.setAndFlush(controller, 'bar', 'NUKE');
_this5.assertCurrentPath('/?other_bar=NUKE&other_foo=NAW', 'QP updated correctly with \'as\'');
});
};
_class.prototype['@test Routes have a private overridable serializeQueryParamKey hook'] = function (assert) {
var _this6 = this;
assert.expect(2);
this.add('route:index', _emberRouting.Route.extend({
serializeQueryParamKey: _emberRuntime.String.dasherize
}));
this.setSingleQPController('index', 'funTimes', '');
return this.visitAndAssert('/').then(function () {
var controller = _this6.getController('index');
_this6.setAndFlush(controller, 'funTimes', 'woot');
_this6.assertCurrentPath('/?fun-times=woot');
});
};
_class.prototype['@test Can override inherited QP behavior by specifying queryParams as a computed property'] = function (assert) {
var _this7 = this;
assert.expect(3);
this.setSingleQPController('index', 'a', 0, {
queryParams: (0, _emberMetal.computed)(function () {
return ['c'];
}),
c: true
});
return this.visitAndAssert('/').then(function () {
var indexController = _this7.getController('index');
_this7.setAndFlush(indexController, 'a', 1);
_this7.assertCurrentPath('/', 'QP did not update due to being overriden');
_this7.setAndFlush(indexController, 'c', false);
_this7.assertCurrentPath('/?c=false', 'QP updated with overriden param');
});
};
_class.prototype['@test Can concatenate inherited QP behavior by specifying queryParams as an array'] = function (assert) {
var _this8 = this;
assert.expect(3);
this.setSingleQPController('index', 'a', 0, {
queryParams: ['c'],
c: true
});
return this.visitAndAssert('/').then(function () {
var indexController = _this8.getController('index');
_this8.setAndFlush(indexController, 'a', 1);
_this8.assertCurrentPath('/?a=1', 'Inherited QP did update');
_this8.setAndFlush(indexController, 'c', false);
_this8.assertCurrentPath('/?a=1&c=false', 'New QP did update');
});
};
_class.prototype['@test model hooks receives query params'] = function (assert) {
assert.expect(2);
this.setSingleQPController('index');
this.add('route:index', _emberRouting.Route.extend({
model: function (params) {
assert.deepEqual(params, { foo: 'bar' });
}
}));
return this.visitAndAssert('/');
};
_class.prototype['@test model hooks receives query params with dynamic segment params'] = function (assert) {
assert.expect(2);
this.router.map(function () {
this.route('index', { path: '/:id' });
});
this.setSingleQPController('index');
this.add('route:index', _emberRouting.Route.extend({
model: function (params) {
assert.deepEqual(params, { foo: 'bar', id: 'baz' });
}
}));
return this.visitAndAssert('/baz');
};
_class.prototype['@test model hooks receives query params (overridden by incoming url value)'] = function (assert) {
assert.expect(2);
this.router.map(function () {
this.route('index', { path: '/:id' });
});
this.setSingleQPController('index');
this.add('route:index', _emberRouting.Route.extend({
model: function (params) {
assert.deepEqual(params, { foo: 'baz', id: 'boo' });
}
}));
return this.visitAndAssert('/boo?foo=baz');
};
_class.prototype['@test error is thrown if dynamic segment and query param have same name'] = function (assert) {
var _this9 = this;
assert.expect(1);
this.router.map(function () {
this.route('index', { path: '/:foo' });
});
this.setSingleQPController('index');
expectAssertion(function () {
_this9.visitAndAssert('/boo?foo=baz');
}, 'The route \'index\' has both a dynamic segment and query param with name \'foo\'. Please rename one to avoid collisions.');
};
_class.prototype['@test query params have been set by the time setupController is called'] = function (assert) {
assert.expect(2);
this.setSingleQPController('application');
this.add('route:application', _emberRouting.Route.extend({
setupController: function (controller) {
assert.equal(controller.get('foo'), 'YEAH', 'controller\'s foo QP property set before setupController called');
}
}));
return this.visitAndAssert('/?foo=YEAH');
};
_class.prototype['@test mapped query params have been set by the time setupController is called'] = function (assert) {
assert.expect(2);
this.setSingleQPController('application', { faz: 'foo' });
this.add('route:application', _emberRouting.Route.extend({
setupController: function (controller) {
assert.equal(controller.get('faz'), 'YEAH', 'controller\'s foo QP property set before setupController called');
}
}));
return this.visitAndAssert('/?foo=YEAH');
};
_class.prototype['@test Route#paramsFor fetches query params with default value'] = function (assert) {
assert.expect(2);
this.router.map(function () {
this.route('index', { path: '/:something' });
});
this.setSingleQPController('index');
this.add('route:index', _emberRouting.Route.extend({
model: function () {
assert.deepEqual(this.paramsFor('index'), { something: 'baz', foo: 'bar' }, 'could retrieve params for index');
}
}));
return this.visitAndAssert('/baz');
};
_class.prototype['@test Route#paramsFor fetches query params with non-default value'] = function (assert) {
assert.expect(2);
this.router.map(function () {
this.route('index', { path: '/:something' });
});
this.setSingleQPController('index');
this.add('route:index', _emberRouting.Route.extend({
model: function () {
assert.deepEqual(this.paramsFor('index'), { something: 'baz', foo: 'boo' }, 'could retrieve params for index');
}
}));
return this.visitAndAssert('/baz?foo=boo');
};
_class.prototype['@test Route#paramsFor fetches default falsy query params'] = function (assert) {
assert.expect(2);
this.router.map(function () {
this.route('index', { path: '/:something' });
});
this.setSingleQPController('index', 'foo', false);
this.add('route:index', _emberRouting.Route.extend({
model: function () {
assert.deepEqual(this.paramsFor('index'), { something: 'baz', foo: false }, 'could retrieve params for index');
}
}));
return this.visitAndAssert('/baz');
};
_class.prototype['@test Route#paramsFor fetches non-default falsy query params'] = function (assert) {
assert.expect(2);
this.router.map(function () {
this.route('index', { path: '/:something' });
});
this.setSingleQPController('index', 'foo', true);
this.add('route:index', _emberRouting.Route.extend({
model: function () {
assert.deepEqual(this.paramsFor('index'), { something: 'baz', foo: false }, 'could retrieve params for index');
}
}));
return this.visitAndAssert('/baz?foo=false');
};
_class.prototype['@test model hook can query prefix-less application params'] = function (assert) {
assert.expect(4);
this.setSingleQPController('application', 'appomg', 'applol');
this.setSingleQPController('index', 'omg', 'lol');
this.add('route:application', _emberRouting.Route.extend({
model: function (params) {
assert.deepEqual(params, { appomg: 'applol' });
}
}));
this.add('route:index', _emberRouting.Route.extend({
model: function (params) {
assert.deepEqual(params, { omg: 'lol' });
assert.deepEqual(this.paramsFor('application'), { appomg: 'applol' });
}
}));
return this.visitAndAssert('/');
};
_class.prototype['@test model hook can query prefix-less application params (overridden by incoming url value)'] = function (assert) {
assert.expect(4);
this.setSingleQPController('application', 'appomg', 'applol');
this.setSingleQPController('index', 'omg', 'lol');
this.add('route:application', _emberRouting.Route.extend({
model: function (params) {
assert.deepEqual(params, { appomg: 'appyes' });
}
}));
this.add('route:index', _emberRouting.Route.extend({
model: function (params) {
assert.deepEqual(params, { omg: 'yes' });
assert.deepEqual(this.paramsFor('application'), { appomg: 'appyes' });
}
}));
return this.visitAndAssert('/?appomg=appyes&omg=yes');
};
_class.prototype['@test can opt into full transition by setting refreshModel in route queryParams'] = function (assert) {
var _this10 = this;
assert.expect(7);
this.setSingleQPController('application', 'appomg', 'applol');
this.setSingleQPController('index', 'omg', 'lol');
var appModelCount = 0;
this.add('route:application', _emberRouting.Route.extend({
model: function () {
appModelCount++;
}
}));
var indexModelCount = 0;
this.add('route:index', _emberRouting.Route.extend({
queryParams: {
omg: {
refreshModel: true
}
},
model: function (params) {
indexModelCount++;
if (indexModelCount === 1) {
assert.deepEqual(params, { omg: 'lol' }, 'params are correct on first pass');
} else if (indexModelCount === 2) {
assert.deepEqual(params, { omg: 'lex' }, 'params are correct on second pass');
}
}
}));
return this.visitAndAssert('/').then(function () {
assert.equal(appModelCount, 1, 'app model hook ran');
assert.equal(indexModelCount, 1, 'index model hook ran');
var indexController = _this10.getController('index');
_this10.setAndFlush(indexController, 'omg', 'lex');
assert.equal(appModelCount, 1, 'app model hook did not run again');
assert.equal(indexModelCount, 2, 'index model hook ran again due to refreshModel');
});
};
_class.prototype['@test refreshModel and replace work together'] = function (assert) {
var _this11 = this;
assert.expect(8);
this.setSingleQPController('application', 'appomg', 'applol');
this.setSingleQPController('index', 'omg', 'lol');
var appModelCount = 0;
this.add('route:application', _emberRouting.Route.extend({
model: function () {
appModelCount++;
}
}));
var indexModelCount = 0;
this.add('route:index', _emberRouting.Route.extend({
queryParams: {
omg: {
refreshModel: true,
replace: true
}
},
model: function (params) {
indexModelCount++;
if (indexModelCount === 1) {
assert.deepEqual(params, { omg: 'lol' }, 'params are correct on first pass');
} else if (indexModelCount === 2) {
assert.deepEqual(params, { omg: 'lex' }, 'params are correct on second pass');
}
}
}));
return this.visitAndAssert('/').then(function () {
assert.equal(appModelCount, 1, 'app model hook ran');
assert.equal(indexModelCount, 1, 'index model hook ran');
var indexController = _this11.getController('index');
_this11.expectedReplaceURL = '/?omg=lex';
_this11.setAndFlush(indexController, 'omg', 'lex');
assert.equal(appModelCount, 1, 'app model hook did not run again');
assert.equal(indexModelCount, 2, 'index model hook ran again due to refreshModel');
});
};
_class.prototype['@test multiple QP value changes only cause a single model refresh'] = function (assert) {
var _this12 = this;
assert.expect(2);
this.setSingleQPController('index', 'alex', 'lol');
this.setSingleQPController('index', 'steely', 'lel');
var refreshCount = 0;
this.add('route:index', _emberRouting.Route.extend({
queryParams: {
alex: {
refreshModel: true
},
steely: {
refreshModel: true
}
},
refresh: function () {
refreshCount++;
}
}));
return this.visitAndAssert('/').then(function () {
var indexController = _this12.getController('index');
(0, _emberMetal.run)(indexController, 'setProperties', { alex: 'fran', steely: 'david' });
assert.equal(refreshCount, 1, 'index refresh hook only run once');
});
};
_class.prototype['@test refreshModel does not cause a second transition during app boot '] = function (assert) {
assert.expect(1);
this.setSingleQPController('application', 'appomg', 'applol');
this.setSingleQPController('index', 'omg', 'lol');
this.add('route:index', _emberRouting.Route.extend({
queryParams: {
omg: {
refreshModel: true
}
},
refresh: function () {
assert.ok(false);
}
}));
return this.visitAndAssert('/?appomg=hello&omg=world');
};
_class.prototype['@test queryParams are updated when a controller property is set and the route is refreshed. Issue #13263 '] = function (assert) {
var _this13 = this;
this.addTemplate('application', 'Increment {{foo}} {{outlet}}');
this.setSingleQPController('application', 'foo', 1, {
actions: {
increment: function () {
this.incrementProperty('foo');
this.send('refreshRoute');
}
}
});
this.add('route:application', _emberRouting.Route.extend({
actions: {
refreshRoute: function () {
this.refresh();
}
}
}));
return this.visitAndAssert('/').then(function () {
assert.equal((0, _emberViews.jQuery)('#test-value').text().trim(), '1');
(0, _emberMetal.run)((0, _emberViews.jQuery)('#test-button'), 'click');
assert.equal((0, _emberViews.jQuery)('#test-value').text().trim(), '2');
_this13.assertCurrentPath('/?foo=2');
(0, _emberMetal.run)((0, _emberViews.jQuery)('#test-button'), 'click');
assert.equal((0, _emberViews.jQuery)('#test-value').text().trim(), '3');
_this13.assertCurrentPath('/?foo=3');
});
};
_class.prototype['@test Use Ember.get to retrieve query params \'refreshModel\' configuration'] = function (assert) {
var _this14 = this;
assert.expect(7);
this.setSingleQPController('application', 'appomg', 'applol');
this.setSingleQPController('index', 'omg', 'lol');
var appModelCount = 0;
this.add('route:application', _emberRouting.Route.extend({
model: function () {
appModelCount++;
}
}));
var indexModelCount = 0;
this.add('route:index', _emberRouting.Route.extend({
queryParams: _emberRuntime.Object.create({
unknownProperty: function () {
return { refreshModel: true };
}
}),
model: function (params) {
indexModelCount++;
if (indexModelCount === 1) {
assert.deepEqual(params, { omg: 'lol' });
} else if (indexModelCount === 2) {
assert.deepEqual(params, { omg: 'lex' });
}
}
}));
return this.visitAndAssert('/').then(function () {
assert.equal(appModelCount, 1);
assert.equal(indexModelCount, 1);
var indexController = _this14.getController('index');
_this14.setAndFlush(indexController, 'omg', 'lex');
assert.equal(appModelCount, 1);
assert.equal(indexModelCount, 2);
});
};
_class.prototype['@test can use refreshModel even with URL changes that remove QPs from address bar'] = function (assert) {
var _this15 = this;
assert.expect(4);
this.setSingleQPController('index', 'omg', 'lol');
var indexModelCount = 0;
this.add('route:index', _emberRouting.Route.extend({
queryParams: {
omg: {
refreshModel: true
}
},
model: function (params) {
indexModelCount++;
var data = void 0;
if (indexModelCount === 1) {
data = 'foo';
} else if (indexModelCount === 2) {
data = 'lol';
}
assert.deepEqual(params, { omg: data }, 'index#model receives right data');
}
}));
return this.visitAndAssert('/?omg=foo').then(function () {
_this15.transitionTo('/');
var indexController = _this15.getController('index');
assert.equal(indexController.get('omg'), 'lol');
});
};
_class.prototype['@test can opt into a replace query by specifying replace:true in the Route config hash'] = function (assert) {
var _this16 = this;
assert.expect(2);
this.setSingleQPController('application', 'alex', 'matchneer');
this.add('route:application', _emberRouting.Route.extend({
queryParams: {
alex: {
replace: true
}
}
}));
return this.visitAndAssert('/').then(function () {
var appController = _this16.getController('application');
_this16.expectedReplaceURL = '/?alex=wallace';
_this16.setAndFlush(appController, 'alex', 'wallace');
});
};
_class.prototype['@test Route query params config can be configured using property name instead of URL key'] = function (assert) {
var _this17 = this;
assert.expect(2);
this.add('controller:application', _emberRuntime.Controller.extend({
queryParams: [{ commitBy: 'commit_by' }]
}));
this.add('route:application', _emberRouting.Route.extend({
queryParams: {
commitBy: {
replace: true
}
}
}));
return this.visitAndAssert('/').then(function () {
var appController = _this17.getController('application');
_this17.expectedReplaceURL = '/?commit_by=igor_seb';
_this17.setAndFlush(appController, 'commitBy', 'igor_seb');
});
};
_class.prototype['@test An explicit replace:false on a changed QP always wins and causes a pushState'] = function (assert) {
var _this18 = this;
assert.expect(3);
this.add('controller:application', _emberRuntime.Controller.extend({
queryParams: ['alex', 'steely'],
alex: 'matchneer',
steely: 'dan'
}));
this.add('route:application', _emberRouting.Route.extend({
queryParams: {
alex: {
replace: true
},
steely: {
replace: false
}
}
}));
return this.visit('/').then(function () {
var appController = _this18.getController('application');
_this18.expectedPushURL = '/?alex=wallace&steely=jan';
(0, _emberMetal.run)(appController, 'setProperties', { alex: 'wallace', steely: 'jan' });
_this18.expectedPushURL = '/?alex=wallace&steely=fran';
(0, _emberMetal.run)(appController, 'setProperties', { steely: 'fran' });
_this18.expectedReplaceURL = '/?alex=sriracha&steely=fran';
(0, _emberMetal.run)(appController, 'setProperties', { alex: 'sriracha' });
});
};
_class.prototype['@test can opt into full transition by setting refreshModel in route queryParams when transitioning from child to parent'] = function (assert) {
this.addTemplate('parent', '{{outlet}}');
this.addTemplate('parent.child', '{{link-to \'Parent\' \'parent\' (query-params foo=\'change\') id=\'parent-link\'}}');
this.router.map(function () {
this.route('parent', function () {
this.route('child');
});
});
var parentModelCount = 0;
this.add('route:parent', _emberRouting.Route.extend({
model: function () {
parentModelCount++;
},
queryParams: {
foo: {
refreshModel: true
}
}
}));
this.setSingleQPController('parent', 'foo', 'abc');
return this.visit('/parent/child?foo=lol').then(function () {
assert.equal(parentModelCount, 1);
(0, _emberMetal.run)((0, _emberViews.jQuery)('#parent-link'), 'click');
assert.equal(parentModelCount, 2);
});
};
_class.prototype['@test Use Ember.get to retrieve query params \'replace\' configuration'] = function (assert) {
var _this19 = this;
assert.expect(2);
this.setSingleQPController('application', 'alex', 'matchneer');
this.add('route:application', _emberRouting.Route.extend({
queryParams: _emberRuntime.Object.create({
unknownProperty: function () {
// We are simulating all qps requiring refresh
return { replace: true };
}
})
}));
return this.visitAndAssert('/').then(function () {
var appController = _this19.getController('application');
_this19.expectedReplaceURL = '/?alex=wallace';
_this19.setAndFlush(appController, 'alex', 'wallace');
});
};
_class.prototype['@test can override incoming QP values in setupController'] = function (assert) {
var _this20 = this;
assert.expect(3);
this.router.map(function () {
this.route('about');
});
this.setSingleQPController('index', 'omg', 'lol');
this.add('route:index', _emberRouting.Route.extend({
setupController: function (controller) {
assert.ok(true, 'setupController called');
controller.set('omg', 'OVERRIDE');
},
actions: {
queryParamsDidChange: function () {
assert.ok(false, 'queryParamsDidChange shouldn\'t fire');
}
}
}));
return this.visitAndAssert('/about').then(function () {
_this20.transitionTo('index');
_this20.assertCurrentPath('/?omg=OVERRIDE');
});
};
_class.prototype['@test can override incoming QP array values in setupController'] = function (assert) {
var _this21 = this;
assert.expect(3);
this.router.map(function () {
this.route('about');
});
this.setSingleQPController('index', 'omg', ['lol']);
this.add('route:index', _emberRouting.Route.extend({
setupController: function (controller) {
assert.ok(true, 'setupController called');
controller.set('omg', ['OVERRIDE']);
},
actions: {
queryParamsDidChange: function () {
assert.ok(false, 'queryParamsDidChange shouldn\'t fire');
}
}
}));
return this.visitAndAssert('/about').then(function () {
_this21.transitionTo('index');
_this21.assertCurrentPath('/?omg=' + encodeURIComponent(JSON.stringify(['OVERRIDE'])));
});
};
_class.prototype['@test URL transitions that remove QPs still register as QP changes'] = function (assert) {
var _this22 = this;
assert.expect(2);
this.setSingleQPController('index', 'omg', 'lol');
return this.visit('/?omg=borf').then(function () {
var indexController = _this22.getController('index');
assert.equal(indexController.get('omg'), 'borf');
_this22.transitionTo('/');
assert.equal(indexController.get('omg'), 'lol');
});
};
_class.prototype['@test Subresource naming style is supported'] = function (assert) {
var _this23 = this;
assert.expect(5);
this.router.map(function () {
this.route('abc.def', { path: '/abcdef' }, function () {
this.route('zoo');
});
});
this.addTemplate('application', '{{link-to \'A\' \'abc.def\' (query-params foo=\'123\') id=\'one\'}}{{link-to \'B\' \'abc.def.zoo\' (query-params foo=\'123\' bar=\'456\') id=\'two\'}}{{outlet}}');
this.setSingleQPController('abc.def', 'foo', 'lol');
this.setSingleQPController('abc.def.zoo', 'bar', 'haha');
return this.visitAndAssert('/').then(function () {
assert.equal((0, _emberViews.jQuery)('#one').attr('href'), '/abcdef?foo=123');
assert.equal((0, _emberViews.jQuery)('#two').attr('href'), '/abcdef/zoo?bar=456&foo=123');
(0, _emberMetal.run)((0, _emberViews.jQuery)('#one'), 'click');
_this23.assertCurrentPath('/abcdef?foo=123');
(0, _emberMetal.run)((0, _emberViews.jQuery)('#two'), 'click');
_this23.assertCurrentPath('/abcdef/zoo?bar=456&foo=123');
});
};
_class.prototype['@test transitionTo supports query params'] = function () {
var _this24 = this;
this.setSingleQPController('index', 'foo', 'lol');
return this.visitAndAssert('/').then(function () {
_this24.transitionTo({ queryParams: { foo: 'borf' } });
_this24.assertCurrentPath('/?foo=borf', 'shorthand supported');
_this24.transitionTo({ queryParams: { 'index:foo': 'blaf' } });
_this24.assertCurrentPath('/?foo=blaf', 'longform supported');
_this24.transitionTo({ queryParams: { 'index:foo': false } });
_this24.assertCurrentPath('/?foo=false', 'longform supported (bool)');
_this24.transitionTo({ queryParams: { foo: false } });
_this24.assertCurrentPath('/?foo=false', 'shorhand supported (bool)');
});
};
_class.prototype['@test transitionTo supports query params (multiple)'] = function () {
var _this25 = this;
this.add('controller:index', _emberRuntime.Controller.extend({
queryParams: ['foo', 'bar'],
foo: 'lol',
bar: 'wat'
}));
return this.visitAndAssert('/').then(function () {
_this25.transitionTo({ queryParams: { foo: 'borf' } });
_this25.assertCurrentPath('/?foo=borf', 'shorthand supported');
_this25.transitionTo({ queryParams: { 'index:foo': 'blaf' } });
_this25.assertCurrentPath('/?foo=blaf', 'longform supported');
_this25.transitionTo({ queryParams: { 'index:foo': false } });
_this25.assertCurrentPath('/?foo=false', 'longform supported (bool)');
_this25.transitionTo({ queryParams: { foo: false } });
_this25.assertCurrentPath('/?foo=false', 'shorhand supported (bool)');
});
};
_class.prototype['@test setting controller QP to empty string doesn\'t generate null in URL'] = function (assert) {
var _this26 = this;
assert.expect(1);
this.setSingleQPController('index', 'foo', '123');
return this.visit('/').then(function () {
var controller = _this26.getController('index');
_this26.expectedPushURL = '/?foo=';
_this26.setAndFlush(controller, 'foo', '');
});
};
_class.prototype['@test setting QP to empty string doesn\'t generate null in URL'] = function (assert) {
var _this27 = this;
assert.expect(1);
this.add('route:index', _emberRouting.Route.extend({
queryParams: {
foo: {
defaultValue: '123'
}
}
}));
return this.visit('/').then(function () {
var controller = _this27.getController('index');
_this27.expectedPushURL = '/?foo=';
_this27.setAndFlush(controller, 'foo', '');
});
};
_class.prototype['@test A default boolean value deserializes QPs as booleans rather than strings'] = function (assert) {
var _this28 = this;
assert.expect(3);
this.setSingleQPController('index', 'foo', false);
this.add('route:index', _emberRouting.Route.extend({
model: function (params) {
assert.equal(params.foo, true, 'model hook received foo as boolean true');
}
}));
return this.visit('/?foo=true').then(function () {
var controller = _this28.getController('index');
assert.equal(controller.get('foo'), true);
_this28.transitionTo('/?foo=false');
assert.equal(controller.get('foo'), false);
});
};
_class.prototype['@test Query param without value are empty string'] = function (assert) {
var _this29 = this;
assert.expect(1);
this.add('controller:index', _emberRuntime.Controller.extend({
queryParams: ['foo'],
foo: ''
}));
return this.visit('/?foo=').then(function () {
var controller = _this29.getController('index');
assert.equal(controller.get('foo'), '');
});
};
_class.prototype['@test Array query params can be set'] = function (assert) {
var _this30 = this;
assert.expect(2);
this.router.map(function () {
this.route('home', { path: '/' });
});
this.setSingleQPController('home', 'foo', []);
return this.visit('/').then(function () {
var controller = _this30.getController('home');
_this30.setAndFlush(controller, 'foo', [1, 2]);
_this30.assertCurrentPath('/?foo=%5B1%2C2%5D');
_this30.setAndFlush(controller, 'foo', [3, 4]);
_this30.assertCurrentPath('/?foo=%5B3%2C4%5D');
});
};
_class.prototype['@test (de)serialization: arrays'] = function (assert) {
var _this31 = this;
assert.expect(4);
this.setSingleQPController('index', 'foo', [1]);
return this.visitAndAssert('/').then(function () {
_this31.transitionTo({ queryParams: { foo: [2, 3] } });
_this31.assertCurrentPath('/?foo=%5B2%2C3%5D', 'shorthand supported');
_this31.transitionTo({ queryParams: { 'index:foo': [4, 5] } });
_this31.assertCurrentPath('/?foo=%5B4%2C5%5D', 'longform supported');
_this31.transitionTo({ queryParams: { foo: [] } });
_this31.assertCurrentPath('/?foo=%5B%5D', 'longform supported');
});
};
_class.prototype['@test Url with array query param sets controller property to array'] = function (assert) {
var _this32 = this;
assert.expect(1);
this.setSingleQPController('index', 'foo', '');
return this.visit('/?foo[]=1&foo[]=2&foo[]=3').then(function () {
var controller = _this32.getController('index');
assert.deepEqual(controller.get('foo'), ['1', '2', '3']);
});
};
_class.prototype['@test Array query params can be pushed/popped'] = function (assert) {
var _this33 = this;
assert.expect(17);
this.router.map(function () {
this.route('home', { path: '/' });
});
this.setSingleQPController('home', 'foo', (0, _emberRuntime.A)());
return this.visitAndAssert('/').then(function () {
var controller = _this33.getController('home');
(0, _emberMetal.run)(controller.foo, 'pushObject', 1);
_this33.assertCurrentPath('/?foo=%5B1%5D');
assert.deepEqual(controller.foo, [1]);
(0, _emberMetal.run)(controller.foo, 'popObject');
_this33.assertCurrentPath('/');
assert.deepEqual(controller.foo, []);
(0, _emberMetal.run)(controller.foo, 'pushObject', 1);
_this33.assertCurrentPath('/?foo=%5B1%5D');
assert.deepEqual(controller.foo, [1]);
(0, _emberMetal.run)(controller.foo, 'popObject');
_this33.assertCurrentPath('/');
assert.deepEqual(controller.foo, []);
(0, _emberMetal.run)(controller.foo, 'pushObject', 1);
_this33.assertCurrentPath('/?foo=%5B1%5D');
assert.deepEqual(controller.foo, [1]);
(0, _emberMetal.run)(controller.foo, 'pushObject', 2);
_this33.assertCurrentPath('/?foo=%5B1%2C2%5D');
assert.deepEqual(controller.foo, [1, 2]);
(0, _emberMetal.run)(controller.foo, 'popObject');
_this33.assertCurrentPath('/?foo=%5B1%5D');
assert.deepEqual(controller.foo, [1]);
(0, _emberMetal.run)(controller.foo, 'unshiftObject', 'lol');
_this33.assertCurrentPath('/?foo=%5B%22lol%22%2C1%5D');
assert.deepEqual(controller.foo, ['lol', 1]);
});
};
_class.prototype['@test Overwriting with array with same content shouldn\'t refire update'] = function (assert) {
var _this34 = this;
assert.expect(4);
this.router.map(function () {
this.route('home', { path: '/' });
});
var modelCount = 0;
this.add('route:home', _emberRouting.Route.extend({
model: function () {
modelCount++;
}
}));
this.setSingleQPController('home', 'foo', (0, _emberRuntime.A)([1]));
return this.visitAndAssert('/').then(function () {
assert.equal(modelCount, 1);
var controller = _this34.getController('home');
_this34.setAndFlush(controller, 'model', (0, _emberRuntime.A)([1]));
assert.equal(modelCount, 1);
_this34.assertCurrentPath('/');
});
};
_class.prototype['@test Defaulting to params hash as the model should not result in that params object being watched'] = function (assert) {
var _this35 = this;
assert.expect(1);
this.router.map(function () {
this.route('other');
});
// This causes the params hash, which is returned as a route's
// model if no other model could be resolved given the provided
// params (and no custom model hook was defined), to be watched,
// unless we return a copy of the params hash.
this.setSingleQPController('application', 'woot', 'wat');
this.add('route:other', _emberRouting.Route.extend({
model: function (p, trans) {
var m = (0, _emberMetal.meta)(trans.params.application);
assert.ok(!m.peekWatching('woot'), 'A meta object isn\'t constructed for this params POJO');
}
}));
return this.visit('/').then(function () {
_this35.transitionTo('other');
});
};
_class.prototype['@test A child of a resource route still defaults to parent route\'s model even if the child route has a query param'] = function (assert) {
assert.expect(2);
this.setSingleQPController('index', 'woot', undefined, {
woot: undefined
});
this.add('route:application', _emberRouting.Route.extend({
model: function () {
return { woot: true };
}
}));
this.add('route:index', _emberRouting.Route.extend({
setupController: function (controller, model) {
assert.deepEqual(model, { woot: true }, 'index route inherited model route from parent route');
}
}));
return this.visitAndAssert('/');
};
_class.prototype['@test opting into replace does not affect transitions between routes'] = function (assert) {
var _this36 = this;
assert.expect(5);
this.addTemplate('application', '{{link-to \'Foo\' \'foo\' id=\'foo-link\'}}{{link-to \'Bar\' \'bar\' id=\'bar-no-qp-link\'}}{{link-to \'Bar\' \'bar\' (query-params raytiley=\'isthebest\') id=\'bar-link\'}}{{outlet}}');
this.router.map(function () {
this.route('foo');
this.route('bar');
});
this.setSingleQPController('bar', 'raytiley', 'israd');
this.add('route:bar', _emberRouting.Route.extend({
queryParams: {
raytiley: {
replace: true
}
}
}));
return this.visit('/').then(function () {
var controller = _this36.getController('bar');
_this36.expectedPushURL = '/foo';
(0, _emberMetal.run)((0, _emberViews.jQuery)('#foo-link'), 'click');
_this36.expectedPushURL = '/bar';
(0, _emberMetal.run)((0, _emberViews.jQuery)('#bar-no-qp-link'), 'click');
_this36.expectedReplaceURL = '/bar?raytiley=woot';
_this36.setAndFlush(controller, 'raytiley', 'woot');
_this36.expectedPushURL = '/foo';
(0, _emberMetal.run)((0, _emberViews.jQuery)('#foo-link'), 'click');
_this36.expectedPushURL = '/bar?raytiley=isthebest';
(0, _emberMetal.run)((0, _emberViews.jQuery)('#bar-link'), 'click');
});
};
_class.prototype['@test undefined isn\'t serialized or deserialized into a string'] = function (assert) {
var _this37 = this;
assert.expect(4);
this.router.map(function () {
this.route('example');
});
this.addTemplate('application', '{{link-to \'Example\' \'example\' (query-params foo=undefined) id=\'the-link\'}}');
this.setSingleQPController('example', 'foo', undefined, {
foo: undefined
});
this.add('route:example', _emberRouting.Route.extend({
model: function (params) {
assert.deepEqual(params, { foo: undefined });
}
}));
return this.visitAndAssert('/').then(function () {
assert.equal(_this37.$('#the-link').attr('href'), '/example', 'renders without undefined qp serialized');
return _this37.transitionTo('example', { queryParams: { foo: undefined } }).then(function () {
_this37.assertCurrentPath('/example');
});
});
};
_class.prototype['@test when refreshModel is true and loading hook is undefined, model hook will rerun when QPs change even if previous did not finish'] = function () {
return this.refreshModelWhileLoadingTest();
};
_class.prototype['@test when refreshModel is true and loading hook returns false, model hook will rerun when QPs change even if previous did not finish'] = function () {
return this.refreshModelWhileLoadingTest(false);
};
_class.prototype['@test when refreshModel is true and loading hook returns true, model hook will rerun when QPs change even if previous did not finish'] = function () {
return this.refreshModelWhileLoadingTest(true);
};
_class.prototype['@test warn user that Route\'s queryParams configuration must be an Object, not an Array'] = function (assert) {
var _this38 = this;
assert.expect(1);
this.add('route:application', _emberRouting.Route.extend({
queryParams: [{ commitBy: { replace: true } }]
}));
expectAssertion(function () {
_this38.visit('/');
}, 'You passed in `[{"commitBy":{"replace":true}}]` as the value for `queryParams` but `queryParams` cannot be an Array');
};
_class.prototype['@test handle route names that clash with Object.prototype properties'] = function (assert) {
var _this39 = this;
assert.expect(1);
this.router.map(function () {
this.route('constructor');
});
this.add('route:constructor', _emberRouting.Route.extend({
queryParams: {
foo: {
defaultValue: '123'
}
}
}));
return this.visit('/').then(function () {
_this39.transitionTo('constructor', { queryParams: { foo: '999' } });
var controller = _this39.getController('constructor');
assert.equal((0, _emberMetal.get)(controller, 'foo'), '999');
});
};
return _class;
}(_internalTestHelpers.QueryParamTestCase));
});
enifed('ember/tests/routing/query_params_test/model_dependent_state_with_query_params_test', ['ember-babel', 'ember-runtime', 'ember-routing', 'ember-metal', 'ember-views', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberRouting, _emberMetal, _emberViews, _internalTestHelpers) {
'use strict';
var ModelDependentQPTestCase = function (_QueryParamTestCase) {
(0, _emberBabel.inherits)(ModelDependentQPTestCase, _QueryParamTestCase);
function ModelDependentQPTestCase() {
return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments));
}
ModelDependentQPTestCase.prototype.boot = function () {
this.setupApplication();
return this.visitApplication();
};
ModelDependentQPTestCase.prototype.teardown = function () {
var _QueryParamTestCase$p;
(_QueryParamTestCase$p = _QueryParamTestCase.prototype.teardown).call.apply(_QueryParamTestCase$p, [this].concat(Array.prototype.slice.call(arguments)));
this.assert.ok(!this.expectedModelHookParams, 'there should be no pending expectation of expected model hook params');
};
ModelDependentQPTestCase.prototype.reopenController = function (name, options) {
this.application.resolveRegistration('controller:' + name).reopen(options);
};
ModelDependentQPTestCase.prototype.reopenRoute = function (name, options) {
this.application.resolveRegistration('route:' + name).reopen(options);
};
ModelDependentQPTestCase.prototype.queryParamsStickyTest1 = function (urlPrefix) {
var _this2 = this;
var assert = this.assert;
assert.expect(14);
return this.boot().then(function () {
(0, _emberMetal.run)(_this2.$link1, 'click');
_this2.assertCurrentPath(urlPrefix + '/a-1');
_this2.setAndFlush(_this2.controller, 'q', 'lol');
assert.equal(_this2.$link1.attr('href'), urlPrefix + '/a-1?q=lol');
assert.equal(_this2.$link2.attr('href'), urlPrefix + '/a-2');
assert.equal(_this2.$link3.attr('href'), urlPrefix + '/a-3');
(0, _emberMetal.run)(_this2.$link2, 'click');
assert.equal(_this2.controller.get('q'), 'wat');
assert.equal(_this2.controller.get('z'), 0);
assert.deepEqual(_this2.controller.get('model'), { id: 'a-2' });
assert.equal(_this2.$link1.attr('href'), urlPrefix + '/a-1?q=lol');
assert.equal(_this2.$link2.attr('href'), urlPrefix + '/a-2');
assert.equal(_this2.$link3.attr('href'), urlPrefix + '/a-3');
});
};
ModelDependentQPTestCase.prototype.queryParamsStickyTest2 = function (urlPrefix) {
var _this3 = this;
var assert = this.assert;
assert.expect(24);
return this.boot().then(function () {
_this3.expectedModelHookParams = { id: 'a-1', q: 'lol', z: 0 };
_this3.transitionTo(urlPrefix + '/a-1?q=lol');
assert.deepEqual(_this3.controller.get('model'), { id: 'a-1' });
assert.equal(_this3.controller.get('q'), 'lol');
assert.equal(_this3.controller.get('z'), 0);
assert.equal(_this3.$link1.attr('href'), urlPrefix + '/a-1?q=lol');
assert.equal(_this3.$link2.attr('href'), urlPrefix + '/a-2');
assert.equal(_this3.$link3.attr('href'), urlPrefix + '/a-3');
_this3.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 0 };
_this3.transitionTo(urlPrefix + '/a-2?q=lol');
assert.deepEqual(_this3.controller.get('model'), { id: 'a-2' }, 'controller\'s model changed to a-2');
assert.equal(_this3.controller.get('q'), 'lol');
assert.equal(_this3.controller.get('z'), 0);
assert.equal(_this3.$link1.attr('href'), urlPrefix + '/a-1?q=lol');
assert.equal(_this3.$link2.attr('href'), urlPrefix + '/a-2?q=lol');
assert.equal(_this3.$link3.attr('href'), urlPrefix + '/a-3');
_this3.expectedModelHookParams = { id: 'a-3', q: 'lol', z: 123 };
_this3.transitionTo(urlPrefix + '/a-3?q=lol&z=123');
assert.equal(_this3.controller.get('q'), 'lol');
assert.equal(_this3.controller.get('z'), 123);
assert.equal(_this3.$link1.attr('href'), urlPrefix + '/a-1?q=lol');
assert.equal(_this3.$link2.attr('href'), urlPrefix + '/a-2?q=lol');
assert.equal(_this3.$link3.attr('href'), urlPrefix + '/a-3?q=lol&z=123');
});
};
ModelDependentQPTestCase.prototype.queryParamsStickyTest3 = function (urlPrefix, articleLookup) {
var _this4 = this;
var assert = this.assert;
assert.expect(32);
this.addTemplate('application', '{{#each articles as |a|}} {{link-to \'Article\' \'' + articleLookup + '\' a.id id=a.id}} {{/each}}');
return this.boot().then(function () {
_this4.expectedModelHookParams = { id: 'a-1', q: 'wat', z: 0 };
_this4.transitionTo(articleLookup, 'a-1');
assert.deepEqual(_this4.controller.get('model'), { id: 'a-1' });
assert.equal(_this4.controller.get('q'), 'wat');
assert.equal(_this4.controller.get('z'), 0);
assert.equal(_this4.$link1.attr('href'), urlPrefix + '/a-1');
assert.equal(_this4.$link2.attr('href'), urlPrefix + '/a-2');
assert.equal(_this4.$link3.attr('href'), urlPrefix + '/a-3');
_this4.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 0 };
_this4.transitionTo(articleLookup, 'a-2', { queryParams: { q: 'lol' } });
assert.deepEqual(_this4.controller.get('model'), { id: 'a-2' });
assert.equal(_this4.controller.get('q'), 'lol');
assert.equal(_this4.controller.get('z'), 0);
assert.equal(_this4.$link1.attr('href'), urlPrefix + '/a-1');
assert.equal(_this4.$link2.attr('href'), urlPrefix + '/a-2?q=lol');
assert.equal(_this4.$link3.attr('href'), urlPrefix + '/a-3');
_this4.expectedModelHookParams = { id: 'a-3', q: 'hay', z: 0 };
_this4.transitionTo(articleLookup, 'a-3', { queryParams: { q: 'hay' } });
assert.deepEqual(_this4.controller.get('model'), { id: 'a-3' });
assert.equal(_this4.controller.get('q'), 'hay');
assert.equal(_this4.controller.get('z'), 0);
assert.equal(_this4.$link1.attr('href'), urlPrefix + '/a-1');
assert.equal(_this4.$link2.attr('href'), urlPrefix + '/a-2?q=lol');
assert.equal(_this4.$link3.attr('href'), urlPrefix + '/a-3?q=hay');
_this4.expectedModelHookParams = { id: 'a-2', q: 'lol', z: 1 };
_this4.transitionTo(articleLookup, 'a-2', { queryParams: { z: 1 } });
assert.deepEqual(_this4.controller.get('model'), { id: 'a-2' });
assert.equal(_this4.controller.get('q'), 'lol');
assert.equal(_this4.controller.get('z'), 1);
assert.equal(_this4.$link1.attr('href'), urlPrefix + '/a-1');
assert.equal(_this4.$link2.attr('href'), urlPrefix + '/a-2?q=lol&z=1');
assert.equal(_this4.$link3.attr('href'), urlPrefix + '/a-3?q=hay');
});
};
ModelDependentQPTestCase.prototype.queryParamsStickyTest4 = function (urlPrefix, articleLookup) {
var _this5 = this;
var assert = this.assert;
assert.expect(24);
this.setupApplication();
this.reopenController(articleLookup, {
queryParams: { q: { scope: 'controller' } }
});
return this.visitApplication().then(function () {
(0, _emberMetal.run)(_this5.$link1, 'click');
_this5.assertCurrentPath(urlPrefix + '/a-1');
_this5.setAndFlush(_this5.controller, 'q', 'lol');
assert.equal(_this5.$link1.attr('href'), urlPrefix + '/a-1?q=lol');
assert.equal(_this5.$link2.attr('href'), urlPrefix + '/a-2?q=lol');
assert.equal(_this5.$link3.attr('href'), urlPrefix + '/a-3?q=lol');
(0, _emberMetal.run)(_this5.$link2, 'click');
assert.equal(_this5.controller.get('q'), 'lol');
assert.equal(_this5.controller.get('z'), 0);
assert.deepEqual(_this5.controller.get('model'), { id: 'a-2' });
assert.equal(_this5.$link1.attr('href'), urlPrefix + '/a-1?q=lol');
assert.equal(_this5.$link2.attr('href'), urlPrefix + '/a-2?q=lol');
assert.equal(_this5.$link3.attr('href'), urlPrefix + '/a-3?q=lol');
_this5.expectedModelHookParams = { id: 'a-3', q: 'haha', z: 123 };
_this5.transitionTo(urlPrefix + '/a-3?q=haha&z=123');
assert.deepEqual(_this5.controller.get('model'), { id: 'a-3' });
assert.equal(_this5.controller.get('q'), 'haha');
assert.equal(_this5.controller.get('z'), 123);
assert.equal(_this5.$link1.attr('href'), urlPrefix + '/a-1?q=haha');
assert.equal(_this5.$link2.attr('href'), urlPrefix + '/a-2?q=haha');
assert.equal(_this5.$link3.attr('href'), urlPrefix + '/a-3?q=haha&z=123');
_this5.setAndFlush(_this5.controller, 'q', 'woot');
assert.equal(_this5.$link1.attr('href'), urlPrefix + '/a-1?q=woot');
assert.equal(_this5.$link2.attr('href'), urlPrefix + '/a-2?q=woot');
assert.equal(_this5.$link3.attr('href'), urlPrefix + '/a-3?q=woot&z=123');
});
};
ModelDependentQPTestCase.prototype.queryParamsStickyTest5 = function (urlPrefix, commentsLookupKey) {
var _this6 = this;
var assert = this.assert;
assert.expect(12);
return this.boot().then(function () {
_this6.transitionTo(commentsLookupKey, 'a-1');
var commentsCtrl = _this6.getController(commentsLookupKey);
assert.equal(commentsCtrl.get('page'), 1);
_this6.assertCurrentPath(urlPrefix + '/a-1/comments');
_this6.setAndFlush(commentsCtrl, 'page', 2);
_this6.assertCurrentPath(urlPrefix + '/a-1/comments?page=2');
_this6.setAndFlush(commentsCtrl, 'page', 3);
_this6.assertCurrentPath(urlPrefix + '/a-1/comments?page=3');
_this6.transitionTo(commentsLookupKey, 'a-2');
assert.equal(commentsCtrl.get('page'), 1);
_this6.assertCurrentPath(urlPrefix + '/a-2/comments');
_this6.transitionTo(commentsLookupKey, 'a-1');
assert.equal(commentsCtrl.get('page'), 3);
_this6.assertCurrentPath(urlPrefix + '/a-1/comments?page=3');
});
};
ModelDependentQPTestCase.prototype.queryParamsStickyTest6 = function (urlPrefix, articleLookup, commentsLookup) {
var _this7 = this;
var assert = this.assert;
assert.expect(13);
this.setupApplication();
this.reopenRoute(articleLookup, {
resetController: function (controller, isExiting) {
this.controllerFor(commentsLookup).set('page', 1);
if (isExiting) {
controller.set('q', 'imdone');
}
}
});
this.addTemplate('about', '{{link-to \'A\' \'' + commentsLookup + '\' \'a-1\' id=\'one\'}} {{link-to \'B\' \'' + commentsLookup + '\' \'a-2\' id=\'two\'}}');
return this.visitApplication().then(function () {
_this7.transitionTo(commentsLookup, 'a-1');
var commentsCtrl = _this7.getController(commentsLookup);
assert.equal(commentsCtrl.get('page'), 1);
_this7.assertCurrentPath(urlPrefix + '/a-1/comments');
_this7.setAndFlush(commentsCtrl, 'page', 2);
_this7.assertCurrentPath(urlPrefix + '/a-1/comments?page=2');
_this7.transitionTo(commentsLookup, 'a-2');
assert.equal(commentsCtrl.get('page'), 1);
assert.equal(_this7.controller.get('q'), 'wat');
_this7.transitionTo(commentsLookup, 'a-1');
_this7.assertCurrentPath(urlPrefix + '/a-1/comments');
assert.equal(commentsCtrl.get('page'), 1);
_this7.transitionTo('about');
assert.equal((0, _emberViews.jQuery)('#one').attr('href'), urlPrefix + '/a-1/comments?q=imdone');
assert.equal((0, _emberViews.jQuery)('#two').attr('href'), urlPrefix + '/a-2/comments');
});
};
return ModelDependentQPTestCase;
}(_internalTestHelpers.QueryParamTestCase);
(0, _internalTestHelpers.moduleFor)('Query Params - model-dependent state', function (_ModelDependentQPTest) {
(0, _emberBabel.inherits)(_class, _ModelDependentQPTest);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _ModelDependentQPTest.apply(this, arguments));
}
_class.prototype.setupApplication = function () {
this.router.map(function () {
this.route('article', { path: '/a/:id' }, function () {
this.route('comments', { resetNamespace: true });
});
this.route('about');
});
var articles = (0, _emberRuntime.A)([{ id: 'a-1' }, { id: 'a-2' }, { id: 'a-3' }]);
this.add('controller:application', _emberRuntime.Controller.extend({
articles: articles
}));
var self = this;
var assert = this.assert;
this.add('route:article', _emberRouting.Route.extend({
model: function (params) {
if (self.expectedModelHookParams) {
assert.deepEqual(params, self.expectedModelHookParams, 'the ArticleRoute model hook received the expected merged dynamic segment + query params hash');
self.expectedModelHookParams = null;
}
return articles.findBy('id', params.id);
}
}));
this.add('controller:article', _emberRuntime.Controller.extend({
queryParams: ['q', 'z'],
q: 'wat',
z: 0
}));
this.add('controller:comments', _emberRuntime.Controller.extend({
queryParams: 'page',
page: 1
}));
this.addTemplate('application', '{{#each articles as |a|}} 1{{link-to \'Article\' \'article\' a id=a.id}} {{/each}} {{outlet}}');
};
_class.prototype.visitApplication = function () {
var _this9 = this;
return this.visit('/').then(function () {
var assert = _this9.assert;
_this9.$link1 = (0, _emberViews.jQuery)('#a-1');
_this9.$link2 = (0, _emberViews.jQuery)('#a-2');
_this9.$link3 = (0, _emberViews.jQuery)('#a-3');
assert.equal(_this9.$link1.attr('href'), '/a/a-1');
assert.equal(_this9.$link2.attr('href'), '/a/a-2');
assert.equal(_this9.$link3.attr('href'), '/a/a-3');
_this9.controller = _this9.getController('article');
});
};
_class.prototype['@test query params have \'model\' stickiness by default'] = function () {
return this.queryParamsStickyTest1('/a');
};
_class.prototype['@test query params have \'model\' stickiness by default (url changes)'] = function () {
return this.queryParamsStickyTest2('/a');
};
_class.prototype['@test query params have \'model\' stickiness by default (params-based transitions)'] = function () {
return this.queryParamsStickyTest3('/a', 'article');
};
_class.prototype['@test \'controller\' stickiness shares QP state between models'] = function () {
return this.queryParamsStickyTest4('/a', 'article');
};
_class.prototype['@test \'model\' stickiness is scoped to current or first dynamic parent route'] = function () {
return this.queryParamsStickyTest5('/a', 'comments');
};
_class.prototype['@test can reset query params using the resetController hook'] = function () {
return this.queryParamsStickyTest6('/a', 'article', 'comments');
};
return _class;
}(ModelDependentQPTestCase));
(0, _internalTestHelpers.moduleFor)('Query Params - model-dependent state (nested)', function (_ModelDependentQPTest2) {
(0, _emberBabel.inherits)(_class2, _ModelDependentQPTest2);
function _class2() {
return (0, _emberBabel.possibleConstructorReturn)(this, _ModelDependentQPTest2.apply(this, arguments));
}
_class2.prototype.setupApplication = function () {
this.router.map(function () {
this.route('site', function () {
this.route('article', { path: '/a/:id' }, function () {
this.route('comments');
});
});
this.route('about');
});
var site_articles = (0, _emberRuntime.A)([{ id: 'a-1' }, { id: 'a-2' }, { id: 'a-3' }]);
this.add('controller:application', _emberRuntime.Controller.extend({
articles: site_articles
}));
var self = this;
var assert = this.assert;
this.add('route:site.article', _emberRouting.Route.extend({
model: function (params) {
if (self.expectedModelHookParams) {
assert.deepEqual(params, self.expectedModelHookParams, 'the ArticleRoute model hook received the expected merged dynamic segment + query params hash');
self.expectedModelHookParams = null;
}
return site_articles.findBy('id', params.id);
}
}));
this.add('controller:site.article', _emberRuntime.Controller.extend({
queryParams: ['q', 'z'],
q: 'wat',
z: 0
}));
this.add('controller:site.article.comments', _emberRuntime.Controller.extend({
queryParams: 'page',
page: 1
}));
this.addTemplate('application', '{{#each articles as |a|}} {{link-to \'Article\' \'site.article\' a id=a.id}} {{/each}} {{outlet}}');
};
_class2.prototype.visitApplication = function () {
var _this11 = this;
return this.visit('/').then(function () {
var assert = _this11.assert;
_this11.$link1 = (0, _emberViews.jQuery)('#a-1');
_this11.$link2 = (0, _emberViews.jQuery)('#a-2');
_this11.$link3 = (0, _emberViews.jQuery)('#a-3');
assert.equal(_this11.$link1.attr('href'), '/site/a/a-1');
assert.equal(_this11.$link2.attr('href'), '/site/a/a-2');
assert.equal(_this11.$link3.attr('href'), '/site/a/a-3');
_this11.controller = _this11.getController('site.article');
});
};
_class2.prototype['@test query params have \'model\' stickiness by default'] = function () {
return this.queryParamsStickyTest1('/site/a');
};
_class2.prototype['@test query params have \'model\' stickiness by default (url changes)'] = function () {
return this.queryParamsStickyTest2('/site/a');
};
_class2.prototype['@test query params have \'model\' stickiness by default (params-based transitions)'] = function () {
return this.queryParamsStickyTest3('/site/a', 'site.article');
};
_class2.prototype['@test \'controller\' stickiness shares QP state between models'] = function () {
return this.queryParamsStickyTest4('/site/a', 'site.article');
};
_class2.prototype['@test \'model\' stickiness is scoped to current or first dynamic parent route'] = function () {
return this.queryParamsStickyTest5('/site/a', 'site.article.comments');
};
_class2.prototype['@test can reset query params using the resetController hook'] = function () {
return this.queryParamsStickyTest6('/site/a', 'site.article', 'site.article.comments');
};
return _class2;
}(ModelDependentQPTestCase));
(0, _internalTestHelpers.moduleFor)('Query Params - model-dependent state (nested & more than 1 dynamic segment)', function (_ModelDependentQPTest3) {
(0, _emberBabel.inherits)(_class3, _ModelDependentQPTest3);
function _class3() {
return (0, _emberBabel.possibleConstructorReturn)(this, _ModelDependentQPTest3.apply(this, arguments));
}
_class3.prototype.setupApplication = function () {
this.router.map(function () {
this.route('site', { path: '/site/:site_id' }, function () {
this.route('article', { path: '/a/:article_id' }, function () {
this.route('comments');
});
});
});
var sites = (0, _emberRuntime.A)([{ id: 's-1' }, { id: 's-2' }, { id: 's-3' }]);
var site_articles = (0, _emberRuntime.A)([{ id: 'a-1' }, { id: 'a-2' }, { id: 'a-3' }]);
this.add('controller:application', _emberRuntime.Controller.extend({
siteArticles: site_articles,
sites: sites,
allSitesAllArticles: (0, _emberMetal.computed)({
get: function () {
var ret = [];
var siteArticles = this.siteArticles;
var sites = this.sites;
sites.forEach(function (site) {
ret = ret.concat(siteArticles.map(function (article) {
return { id: site.id + '-' + article.id, site_id: site.id, article_id: article.id };
}));
});
return ret;
}
})
}));
var self = this;
var assert = this.assert;
this.add('route:site', _emberRouting.Route.extend({
model: function (params) {
if (self.expectedSiteModelHookParams) {
assert.deepEqual(params, self.expectedSiteModelHookParams, 'the SiteRoute model hook received the expected merged dynamic segment + query params hash');
self.expectedSiteModelHookParams = null;
}
return sites.findBy('id', params.site_id);
}
}));
this.add('route:site.article', _emberRouting.Route.extend({
model: function (params) {
if (self.expectedArticleModelHookParams) {
assert.deepEqual(params, self.expectedArticleModelHookParams, 'the SiteArticleRoute model hook received the expected merged dynamic segment + query params hash');
self.expectedArticleModelHookParams = null;
}
return site_articles.findBy('id', params.article_id);
}
}));
this.add('controller:site', _emberRuntime.Controller.extend({
queryParams: ['country'],
country: 'au'
}));
this.add('controller:site.article', _emberRuntime.Controller.extend({
queryParams: ['q', 'z'],
q: 'wat',
z: 0
}));
this.add('controller:site.article.comments', _emberRuntime.Controller.extend({
queryParams: ['page'],
page: 1
}));
this.addTemplate('application', '{{#each allSitesAllArticles as |a|}} {{#link-to \'site.article\' a.site_id a.article_id id=a.id}}Article [{{a.site_id}}] [{{a.article_id}}]{{/link-to}} {{/each}} {{outlet}}');
};
_class3.prototype.visitApplication = function () {
var _this13 = this;
return this.visit('/').then(function () {
var assert = _this13.assert;
_this13.links = {};
_this13.links['s-1-a-1'] = (0, _emberViews.jQuery)('#s-1-a-1');
_this13.links['s-1-a-2'] = (0, _emberViews.jQuery)('#s-1-a-2');
_this13.links['s-1-a-3'] = (0, _emberViews.jQuery)('#s-1-a-3');
_this13.links['s-2-a-1'] = (0, _emberViews.jQuery)('#s-2-a-1');
_this13.links['s-2-a-2'] = (0, _emberViews.jQuery)('#s-2-a-2');
_this13.links['s-2-a-3'] = (0, _emberViews.jQuery)('#s-2-a-3');
_this13.links['s-3-a-1'] = (0, _emberViews.jQuery)('#s-3-a-1');
_this13.links['s-3-a-2'] = (0, _emberViews.jQuery)('#s-3-a-2');
_this13.links['s-3-a-3'] = (0, _emberViews.jQuery)('#s-3-a-3');
assert.equal(_this13.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1');
assert.equal(_this13.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2');
assert.equal(_this13.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3');
assert.equal(_this13.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1');
assert.equal(_this13.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2');
assert.equal(_this13.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3');
assert.equal(_this13.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1');
assert.equal(_this13.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2');
assert.equal(_this13.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3');
_this13.site_controller = _this13.getController('site');
_this13.article_controller = _this13.getController('site.article');
});
};
_class3.prototype['@test query params have \'model\' stickiness by default'] = function (assert) {
var _this14 = this;
assert.expect(59);
return this.boot().then(function () {
(0, _emberMetal.run)(_this14.links['s-1-a-1'], 'click');
assert.deepEqual(_this14.site_controller.get('model'), { id: 's-1' });
assert.deepEqual(_this14.article_controller.get('model'), { id: 'a-1' });
_this14.assertCurrentPath('/site/s-1/a/a-1');
_this14.setAndFlush(_this14.article_controller, 'q', 'lol');
assert.equal(_this14.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol');
assert.equal(_this14.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2');
assert.equal(_this14.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3');
assert.equal(_this14.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?q=lol');
assert.equal(_this14.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2');
assert.equal(_this14.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3');
assert.equal(_this14.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol');
assert.equal(_this14.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2');
assert.equal(_this14.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3');
_this14.setAndFlush(_this14.site_controller, 'country', 'us');
assert.equal(_this14.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?country=us&q=lol');
assert.equal(_this14.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?country=us');
assert.equal(_this14.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?country=us');
assert.equal(_this14.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?q=lol');
assert.equal(_this14.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2');
assert.equal(_this14.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3');
assert.equal(_this14.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol');
assert.equal(_this14.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2');
assert.equal(_this14.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3');
(0, _emberMetal.run)(_this14.links['s-1-a-2'], 'click');
assert.equal(_this14.site_controller.get('country'), 'us');
assert.equal(_this14.article_controller.get('q'), 'wat');
assert.equal(_this14.article_controller.get('z'), 0);
assert.deepEqual(_this14.site_controller.get('model'), { id: 's-1' });
assert.deepEqual(_this14.article_controller.get('model'), { id: 'a-2' });
assert.equal(_this14.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?country=us&q=lol');
assert.equal(_this14.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?country=us');
assert.equal(_this14.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?country=us');
assert.equal(_this14.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?q=lol');
assert.equal(_this14.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2');
assert.equal(_this14.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3');
assert.equal(_this14.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol');
assert.equal(_this14.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2');
assert.equal(_this14.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3');
(0, _emberMetal.run)(_this14.links['s-2-a-2'], 'click');
assert.equal(_this14.site_controller.get('country'), 'au');
assert.equal(_this14.article_controller.get('q'), 'wat');
assert.equal(_this14.article_controller.get('z'), 0);
assert.deepEqual(_this14.site_controller.get('model'), { id: 's-2' });
assert.deepEqual(_this14.article_controller.get('model'), { id: 'a-2' });
assert.equal(_this14.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?country=us&q=lol');
assert.equal(_this14.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?country=us');
assert.equal(_this14.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?country=us');
assert.equal(_this14.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?q=lol');
assert.equal(_this14.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2');
assert.equal(_this14.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3');
assert.equal(_this14.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol');
assert.equal(_this14.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2');
assert.equal(_this14.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3');
});
};
_class3.prototype['@test query params have \'model\' stickiness by default (url changes)'] = function (assert) {
var _this15 = this;
assert.expect(88);
return this.boot().then(function () {
_this15.expectedSiteModelHookParams = { site_id: 's-1', country: 'au' };
_this15.expectedArticleModelHookParams = { article_id: 'a-1', q: 'lol', z: 0 };
_this15.transitionTo('/site/s-1/a/a-1?q=lol');
assert.deepEqual(_this15.site_controller.get('model'), { id: 's-1' }, 'site controller\'s model is s-1');
assert.deepEqual(_this15.article_controller.get('model'), { id: 'a-1' }, 'article controller\'s model is a-1');
assert.equal(_this15.site_controller.get('country'), 'au');
assert.equal(_this15.article_controller.get('q'), 'lol');
assert.equal(_this15.article_controller.get('z'), 0);
assert.equal(_this15.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol');
assert.equal(_this15.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2');
assert.equal(_this15.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3');
assert.equal(_this15.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?q=lol');
assert.equal(_this15.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2');
assert.equal(_this15.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3');
assert.equal(_this15.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol');
assert.equal(_this15.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2');
assert.equal(_this15.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3');
_this15.expectedSiteModelHookParams = { site_id: 's-2', country: 'us' };
_this15.expectedArticleModelHookParams = { article_id: 'a-1', q: 'lol', z: 0 };
_this15.transitionTo('/site/s-2/a/a-1?country=us&q=lol');
assert.deepEqual(_this15.site_controller.get('model'), { id: 's-2' }, 'site controller\'s model is s-2');
assert.deepEqual(_this15.article_controller.get('model'), { id: 'a-1' }, 'article controller\'s model is a-1');
assert.equal(_this15.site_controller.get('country'), 'us');
assert.equal(_this15.article_controller.get('q'), 'lol');
assert.equal(_this15.article_controller.get('z'), 0);
assert.equal(_this15.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol');
assert.equal(_this15.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2');
assert.equal(_this15.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3');
assert.equal(_this15.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=lol');
assert.equal(_this15.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us');
assert.equal(_this15.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us');
assert.equal(_this15.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol');
assert.equal(_this15.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2');
assert.equal(_this15.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3');
_this15.expectedSiteModelHookParams = { site_id: 's-2', country: 'us' };
_this15.expectedArticleModelHookParams = { article_id: 'a-2', q: 'lol', z: 0 };
_this15.transitionTo('/site/s-2/a/a-2?country=us&q=lol');
assert.deepEqual(_this15.site_controller.get('model'), { id: 's-2' }, 'site controller\'s model is s-2');
assert.deepEqual(_this15.article_controller.get('model'), { id: 'a-2' }, 'article controller\'s model is a-2');
assert.equal(_this15.site_controller.get('country'), 'us');
assert.equal(_this15.article_controller.get('q'), 'lol');
assert.equal(_this15.article_controller.get('z'), 0);
assert.equal(_this15.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol');
assert.equal(_this15.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol');
assert.equal(_this15.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3');
assert.equal(_this15.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=lol');
assert.equal(_this15.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol');
assert.equal(_this15.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us');
assert.equal(_this15.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol');
assert.equal(_this15.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol');
assert.equal(_this15.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3');
_this15.expectedSiteModelHookParams = { site_id: 's-2', country: 'us' };
_this15.expectedArticleModelHookParams = { article_id: 'a-3', q: 'lol', z: 123 };
_this15.transitionTo('/site/s-2/a/a-3?country=us&q=lol&z=123');
assert.deepEqual(_this15.site_controller.get('model'), { id: 's-2' }, 'site controller\'s model is s-2');
assert.deepEqual(_this15.article_controller.get('model'), { id: 'a-3' }, 'article controller\'s model is a-3');
assert.equal(_this15.site_controller.get('country'), 'us');
assert.equal(_this15.article_controller.get('q'), 'lol');
assert.equal(_this15.article_controller.get('z'), 123);
assert.equal(_this15.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol');
assert.equal(_this15.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol');
assert.equal(_this15.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=lol&z=123');
assert.equal(_this15.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=lol');
assert.equal(_this15.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol');
assert.equal(_this15.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us&q=lol&z=123');
assert.equal(_this15.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=lol');
assert.equal(_this15.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol');
assert.equal(_this15.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?q=lol&z=123');
_this15.expectedSiteModelHookParams = { site_id: 's-3', country: 'nz' };
_this15.expectedArticleModelHookParams = { article_id: 'a-3', q: 'lol', z: 123 };
_this15.transitionTo('/site/s-3/a/a-3?country=nz&q=lol&z=123');
assert.deepEqual(_this15.site_controller.get('model'), { id: 's-3' }, 'site controller\'s model is s-3');
assert.deepEqual(_this15.article_controller.get('model'), { id: 'a-3' }, 'article controller\'s model is a-3');
assert.equal(_this15.site_controller.get('country'), 'nz');
assert.equal(_this15.article_controller.get('q'), 'lol');
assert.equal(_this15.article_controller.get('z'), 123);
assert.equal(_this15.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=lol');
assert.equal(_this15.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol');
assert.equal(_this15.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=lol&z=123');
assert.equal(_this15.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=lol');
assert.equal(_this15.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol');
assert.equal(_this15.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us&q=lol&z=123');
assert.equal(_this15.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?country=nz&q=lol');
assert.equal(_this15.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?country=nz&q=lol');
assert.equal(_this15.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?country=nz&q=lol&z=123');
});
};
_class3.prototype['@test query params have \'model\' stickiness by default (params-based transitions)'] = function (assert) {
var _this16 = this;
assert.expect(118);
return this.boot().then(function () {
_this16.expectedSiteModelHookParams = { site_id: 's-1', country: 'au' };
_this16.expectedArticleModelHookParams = { article_id: 'a-1', q: 'wat', z: 0 };
_this16.transitionTo('site.article', 's-1', 'a-1');
assert.deepEqual(_this16.site_controller.get('model'), { id: 's-1' });
assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-1' });
assert.equal(_this16.site_controller.get('country'), 'au');
assert.equal(_this16.article_controller.get('q'), 'wat');
assert.equal(_this16.article_controller.get('z'), 0);
assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1');
assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2');
assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3');
assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1');
assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2');
assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3');
assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1');
assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2');
assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3');
_this16.expectedSiteModelHookParams = { site_id: 's-1', country: 'au' };
_this16.expectedArticleModelHookParams = { article_id: 'a-2', q: 'lol', z: 0 };
_this16.transitionTo('site.article', 's-1', 'a-2', { queryParams: { q: 'lol' } });
assert.deepEqual(_this16.site_controller.get('model'), { id: 's-1' });
assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-2' });
assert.equal(_this16.site_controller.get('country'), 'au');
assert.equal(_this16.article_controller.get('q'), 'lol');
assert.equal(_this16.article_controller.get('z'), 0);
assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1');
assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol');
assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3');
assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1');
assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?q=lol');
assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3');
assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1');
assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol');
assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3');
_this16.expectedSiteModelHookParams = { site_id: 's-1', country: 'au' };
_this16.expectedArticleModelHookParams = { article_id: 'a-3', q: 'hay', z: 0 };
_this16.transitionTo('site.article', 's-1', 'a-3', { queryParams: { q: 'hay' } });
assert.deepEqual(_this16.site_controller.get('model'), { id: 's-1' });
assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-3' });
assert.equal(_this16.site_controller.get('country'), 'au');
assert.equal(_this16.article_controller.get('q'), 'hay');
assert.equal(_this16.article_controller.get('z'), 0);
assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1');
assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol');
assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=hay');
assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1');
assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?q=lol');
assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?q=hay');
assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1');
assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol');
assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?q=hay');
_this16.expectedSiteModelHookParams = { site_id: 's-1', country: 'au' };
_this16.expectedArticleModelHookParams = { article_id: 'a-2', q: 'lol', z: 1 };
_this16.transitionTo('site.article', 's-1', 'a-2', { queryParams: { z: 1 } });
assert.deepEqual(_this16.site_controller.get('model'), { id: 's-1' });
assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-2' });
assert.equal(_this16.site_controller.get('country'), 'au');
assert.equal(_this16.article_controller.get('q'), 'lol');
assert.equal(_this16.article_controller.get('z'), 1);
assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1');
assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol&z=1');
assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=hay');
assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1');
assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?q=lol&z=1');
assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?q=hay');
assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1');
assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol&z=1');
assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?q=hay');
_this16.expectedSiteModelHookParams = { site_id: 's-2', country: 'us' };
_this16.expectedArticleModelHookParams = { article_id: 'a-2', q: 'lol', z: 1 };
_this16.transitionTo('site.article', 's-2', 'a-2', { queryParams: { country: 'us' } });
assert.deepEqual(_this16.site_controller.get('model'), { id: 's-2' });
assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-2' });
assert.equal(_this16.site_controller.get('country'), 'us');
assert.equal(_this16.article_controller.get('q'), 'lol');
assert.equal(_this16.article_controller.get('z'), 1);
assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1');
assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol&z=1');
assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=hay');
assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us');
assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol&z=1');
assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us&q=hay');
assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1');
assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol&z=1');
assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?q=hay');
_this16.expectedSiteModelHookParams = { site_id: 's-2', country: 'us' };
_this16.expectedArticleModelHookParams = { article_id: 'a-1', q: 'yeah', z: 0 };
_this16.transitionTo('site.article', 's-2', 'a-1', { queryParams: { q: 'yeah' } });
assert.deepEqual(_this16.site_controller.get('model'), { id: 's-2' });
assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-1' });
assert.equal(_this16.site_controller.get('country'), 'us');
assert.equal(_this16.article_controller.get('q'), 'yeah');
assert.equal(_this16.article_controller.get('z'), 0);
assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=yeah');
assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol&z=1');
assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=hay');
assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=yeah');
assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol&z=1');
assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us&q=hay');
assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?q=yeah');
assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?q=lol&z=1');
assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?q=hay');
_this16.expectedSiteModelHookParams = { site_id: 's-3', country: 'nz' };
_this16.expectedArticleModelHookParams = { article_id: 'a-3', q: 'hay', z: 3 };
_this16.transitionTo('site.article', 's-3', 'a-3', { queryParams: { country: 'nz', z: 3 } });
assert.deepEqual(_this16.site_controller.get('model'), { id: 's-3' });
assert.deepEqual(_this16.article_controller.get('model'), { id: 'a-3' });
assert.equal(_this16.site_controller.get('country'), 'nz');
assert.equal(_this16.article_controller.get('q'), 'hay');
assert.equal(_this16.article_controller.get('z'), 3);
assert.equal(_this16.links['s-1-a-1'].attr('href'), '/site/s-1/a/a-1?q=yeah');
assert.equal(_this16.links['s-1-a-2'].attr('href'), '/site/s-1/a/a-2?q=lol&z=1');
assert.equal(_this16.links['s-1-a-3'].attr('href'), '/site/s-1/a/a-3?q=hay&z=3');
assert.equal(_this16.links['s-2-a-1'].attr('href'), '/site/s-2/a/a-1?country=us&q=yeah');
assert.equal(_this16.links['s-2-a-2'].attr('href'), '/site/s-2/a/a-2?country=us&q=lol&z=1');
assert.equal(_this16.links['s-2-a-3'].attr('href'), '/site/s-2/a/a-3?country=us&q=hay&z=3');
assert.equal(_this16.links['s-3-a-1'].attr('href'), '/site/s-3/a/a-1?country=nz&q=yeah');
assert.equal(_this16.links['s-3-a-2'].attr('href'), '/site/s-3/a/a-2?country=nz&q=lol&z=1');
assert.equal(_this16.links['s-3-a-3'].attr('href'), '/site/s-3/a/a-3?country=nz&q=hay&z=3');
});
};
return _class3;
}(ModelDependentQPTestCase));
});
enifed('ember/tests/routing/query_params_test/overlapping_query_params_test', ['ember-babel', 'ember-runtime', 'ember-routing', 'ember-metal', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberRouting, _emberMetal, _internalTestHelpers) {
'use strict';
(0, _internalTestHelpers.moduleFor)('Query Params - overlapping query param property names', function (_QueryParamTestCase) {
(0, _emberBabel.inherits)(_class, _QueryParamTestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments));
}
_class.prototype.setupBase = function () {
this.router.map(function () {
this.route('parent', function () {
this.route('child');
});
});
return this.visit('/parent/child');
};
_class.prototype['@test can remap same-named qp props'] = function (assert) {
var _this2 = this;
assert.expect(7);
this.setMappedQPController('parent');
this.setMappedQPController('parent.child', 'page', 'childPage');
return this.setupBase().then(function () {
_this2.assertCurrentPath('/parent/child');
var parentController = _this2.getController('parent');
var parentChildController = _this2.getController('parent.child');
_this2.setAndFlush(parentController, 'page', 2);
_this2.assertCurrentPath('/parent/child?parentPage=2');
_this2.setAndFlush(parentController, 'page', 1);
_this2.assertCurrentPath('/parent/child');
_this2.setAndFlush(parentChildController, 'page', 2);
_this2.assertCurrentPath('/parent/child?childPage=2');
_this2.setAndFlush(parentChildController, 'page', 1);
_this2.assertCurrentPath('/parent/child');
(0, _emberMetal.run)(function () {
parentController.set('page', 2);
parentChildController.set('page', 2);
});
_this2.assertCurrentPath('/parent/child?childPage=2&parentPage=2');
(0, _emberMetal.run)(function () {
parentController.set('page', 1);
parentChildController.set('page', 1);
});
_this2.assertCurrentPath('/parent/child');
});
};
_class.prototype['@test query params can be either controller property or url key'] = function (assert) {
var _this3 = this;
assert.expect(3);
this.setMappedQPController('parent');
return this.setupBase().then(function () {
_this3.assertCurrentPath('/parent/child');
_this3.transitionTo('parent.child', { queryParams: { page: 2 } });
_this3.assertCurrentPath('/parent/child?parentPage=2');
_this3.transitionTo('parent.child', { queryParams: { parentPage: 3 } });
_this3.assertCurrentPath('/parent/child?parentPage=3');
});
};
_class.prototype['@test query param matching a url key and controller property'] = function (assert) {
var _this4 = this;
assert.expect(3);
this.setMappedQPController('parent', 'page', 'parentPage');
this.setMappedQPController('parent.child', 'index', 'page');
return this.setupBase().then(function () {
_this4.transitionTo('parent.child', { queryParams: { page: 2 } });
_this4.assertCurrentPath('/parent/child?parentPage=2');
_this4.transitionTo('parent.child', { queryParams: { parentPage: 3 } });
_this4.assertCurrentPath('/parent/child?parentPage=3');
_this4.transitionTo('parent.child', { queryParams: { index: 2, page: 2 } });
_this4.assertCurrentPath('/parent/child?page=2&parentPage=2');
});
};
_class.prototype['@test query param matching same property on two controllers use the urlKey higher in the chain'] = function (assert) {
var _this5 = this;
assert.expect(4);
this.setMappedQPController('parent', 'page', 'parentPage');
this.setMappedQPController('parent.child', 'page', 'childPage');
return this.setupBase().then(function () {
_this5.transitionTo('parent.child', { queryParams: { page: 2 } });
_this5.assertCurrentPath('/parent/child?parentPage=2');
_this5.transitionTo('parent.child', { queryParams: { parentPage: 3 } });
_this5.assertCurrentPath('/parent/child?parentPage=3');
_this5.transitionTo('parent.child', { queryParams: { childPage: 2, page: 2 } });
_this5.assertCurrentPath('/parent/child?childPage=2&parentPage=2');
_this5.transitionTo('parent.child', { queryParams: { childPage: 3, parentPage: 4 } });
_this5.assertCurrentPath('/parent/child?childPage=3&parentPage=4');
});
};
_class.prototype['@test query params does not error when a query parameter exists for route instances that share a controller'] = function (assert) {
var _this6 = this;
assert.expect(1);
var parentController = _emberRuntime.Controller.extend({
queryParams: { page: 'page' }
});
this.add('controller:parent', parentController);
this.add('route:parent.child', _emberRouting.Route.extend({ controllerName: 'parent' }));
return this.setupBase('/parent').then(function () {
_this6.transitionTo('parent.child', { queryParams: { page: 2 } });
_this6.assertCurrentPath('/parent/child?page=2');
});
};
_class.prototype['@test query params in the same route hierarchy with the same url key get auto-scoped'] = function (assert) {
var _this7 = this;
assert.expect(1);
this.setMappedQPController('parent');
this.setMappedQPController('parent.child');
expectAssertion(function () {
_this7.setupBase();
}, 'You\'re not allowed to have more than one controller property map to the same query param key, but both `parent:page` and `parent.child:page` map to `parentPage`. You can fix this by mapping one of the controller properties to a different query param key via the `as` config option, e.g. `page: { as: \'other-page\' }`');
};
_class.prototype['@test Support shared but overridable mixin pattern'] = function (assert) {
var _this8 = this;
assert.expect(7);
var HasPage = _emberMetal.Mixin.create({
queryParams: 'page',
page: 1
});
this.add('controller:parent', _emberRuntime.Controller.extend(HasPage, {
queryParams: { page: 'yespage' }
}));
this.add('controller:parent.child', _emberRuntime.Controller.extend(HasPage));
return this.setupBase().then(function () {
_this8.assertCurrentPath('/parent/child');
var parentController = _this8.getController('parent');
var parentChildController = _this8.getController('parent.child');
_this8.setAndFlush(parentChildController, 'page', 2);
_this8.assertCurrentPath('/parent/child?page=2');
assert.equal(parentController.get('page'), 1);
assert.equal(parentChildController.get('page'), 2);
_this8.setAndFlush(parentController, 'page', 2);
_this8.assertCurrentPath('/parent/child?page=2&yespage=2');
assert.equal(parentController.get('page'), 2);
assert.equal(parentChildController.get('page'), 2);
});
};
return _class;
}(_internalTestHelpers.QueryParamTestCase));
});
enifed('ember/tests/routing/query_params_test/query_param_async_get_handler_test', ['ember-babel', 'ember-metal', 'ember-runtime', 'ember-routing', 'internal-test-helpers'], function (_emberBabel, _emberMetal, _emberRuntime, _emberRouting, _internalTestHelpers) {
'use strict';
// These tests mimic what happens with lazily loaded Engines.
(0, _internalTestHelpers.moduleFor)('Query Params - async get handler', function (_QueryParamTestCase) {
(0, _emberBabel.inherits)(_class, _QueryParamTestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments));
}
_class.prototype['@test can render a link to an asynchronously loaded route without fetching the route'] = function (assert) {
var _this2 = this;
assert.expect(4);
this.router.map(function () {
this.route('post', { path: '/post/:id' });
});
this.setSingleQPController('post');
(function () {
_this2.addTemplate('application', '\n {{link-to \'Post\' \'post\' 1337 (query-params foo=\'bar\') class=\'post-link\'}}\n {{link-to \'Post\' \'post\' 7331 (query-params foo=\'boo\') class=\'post-link\'}}\n {{outlet}}\n ');
})();
return this.visitAndAssert('/').then(function () {
assert.equal(_this2.$('.post-link').eq(0).attr('href'), '/post/1337?foo=bar', 'renders correctly with default QP value');
assert.equal(_this2.$('.post-link').eq(1).attr('href'), '/post/7331?foo=boo', 'renders correctly with non-default QP value');
assert.deepEqual(_this2.fetchedHandlers, ['application', 'index'], 'only fetched the handlers for the route we\'re on');
});
};
_class.prototype['@test can transitionTo to an asynchronously loaded route with simple query params'] = function (assert) {
var _this3 = this;
assert.expect(6);
this.router.map(function () {
this.route('post', { path: '/post/:id' });
this.route('posts');
});
this.setSingleQPController('post');
var postController = void 0;
return this.visitAndAssert('/').then(function () {
postController = _this3.getController('post');
return _this3.transitionTo('posts').then(function () {
_this3.assertCurrentPath('/posts');
});
}).then(function () {
return _this3.transitionTo('post', 1337, { queryParams: { foo: 'boo' } }).then(function () {
assert.equal(postController.get('foo'), 'boo', 'simple QP is correctly set on controller');
_this3.assertCurrentPath('/post/1337?foo=boo');
});
}).then(function () {
return _this3.transitionTo('post', 1337, { queryParams: { foo: 'bar' } }).then(function () {
assert.equal(postController.get('foo'), 'bar', 'simple QP is correctly set with default value');
_this3.assertCurrentPath('/post/1337');
});
});
};
_class.prototype['@test can transitionTo to an asynchronously loaded route with array query params'] = function (assert) {
var _this4 = this;
assert.expect(5);
this.router.map(function () {
this.route('post', { path: '/post/:id' });
});
this.setSingleQPController('post', 'comments', []);
var postController = void 0;
return this.visitAndAssert('/').then(function () {
postController = _this4.getController('post');
return _this4.transitionTo('post', 1337, { queryParams: { comments: [1, 2] } }).then(function () {
assert.deepEqual(postController.get('comments'), [1, 2], 'array QP is correctly set with default value');
_this4.assertCurrentPath('/post/1337?comments=%5B1%2C2%5D');
});
}).then(function () {
return _this4.transitionTo('post', 1338).then(function () {
assert.deepEqual(postController.get('comments'), [], 'array QP is correctly set on controller');
_this4.assertCurrentPath('/post/1338');
});
});
};
_class.prototype['@test can transitionTo to an asynchronously loaded route with mapped query params'] = function (assert) {
var _this5 = this;
assert.expect(7);
this.router.map(function () {
this.route('post', { path: '/post/:id' }, function () {
this.route('index', { path: '/' });
});
});
this.setSingleQPController('post');
this.setMappedQPController('post.index', 'comment', 'note');
var postController = void 0;
var postIndexController = void 0;
return this.visitAndAssert('/').then(function () {
postController = _this5.getController('post');
postIndexController = _this5.getController('post.index');
return _this5.transitionTo('post.index', 1337, { queryParams: { note: 6, foo: 'boo' } }).then(function () {
assert.equal(postController.get('foo'), 'boo', 'simple QP is correctly set on controller');
assert.equal(postIndexController.get('comment'), 6, 'mapped QP is correctly set on controller');
_this5.assertCurrentPath('/post/1337?foo=boo¬e=6');
});
}).then(function () {
return _this5.transitionTo('post', 1337, { queryParams: { foo: 'bar' } }).then(function () {
assert.equal(postController.get('foo'), 'bar', 'simple QP is correctly set with default value');
assert.equal(postIndexController.get('comment'), 6, 'mapped QP retains value scoped to model');
_this5.assertCurrentPath('/post/1337?note=6');
});
});
};
_class.prototype['@test can transitionTo with a URL'] = function (assert) {
var _this6 = this;
assert.expect(7);
this.router.map(function () {
this.route('post', { path: '/post/:id' }, function () {
this.route('index', { path: '/' });
});
});
this.setSingleQPController('post');
this.setMappedQPController('post.index', 'comment', 'note');
var postController = void 0;
var postIndexController = void 0;
return this.visitAndAssert('/').then(function () {
postController = _this6.getController('post');
postIndexController = _this6.getController('post.index');
return _this6.transitionTo('/post/1337?foo=boo¬e=6').then(function () {
assert.equal(postController.get('foo'), 'boo', 'simple QP is correctly deserialized on controller');
assert.equal(postIndexController.get('comment'), 6, 'mapped QP is correctly deserialized on controller');
_this6.assertCurrentPath('/post/1337?foo=boo¬e=6');
});
}).then(function () {
return _this6.transitionTo('/post/1337?note=6').then(function () {
assert.equal(postController.get('foo'), 'bar', 'simple QP is correctly deserialized with default value');
assert.equal(postIndexController.get('comment'), 6, 'mapped QP retains value scoped to model');
_this6.assertCurrentPath('/post/1337?note=6');
});
});
};
_class.prototype['@test undefined isn\'t serialized or deserialized into a string'] = function (assert) {
var _this7 = this;
assert.expect(4);
this.router.map(function () {
this.route('example');
});
this.addTemplate('application', '{{link-to \'Example\' \'example\' (query-params foo=undefined) id=\'the-link\'}}');
this.setSingleQPController('example', 'foo', undefined, {
foo: undefined
});
this.add('route:example', _emberRouting.Route.extend({
model: function (params) {
assert.deepEqual(params, { foo: undefined });
}
}));
return this.visitAndAssert('/').then(function () {
assert.equal(_this7.$('#the-link').attr('href'), '/example', 'renders without undefined qp serialized');
return _this7.transitionTo('example', { queryParams: { foo: undefined } }).then(function () {
_this7.assertCurrentPath('/example');
});
});
};
(0, _emberBabel.createClass)(_class, [{
key: 'routerOptions',
get: function () {
var fetchedHandlers = this.fetchedHandlers = [];
return {
location: 'test',
init: function () {
this._super.apply(this, arguments);
this._seenHandlers = Object.create(null);
this._handlerPromises = Object.create(null);
},
_getQPMeta: function (handlerInfo) {
var handler = this._seenHandlers[handlerInfo.name];
if (handler) {
return (0, _emberMetal.get)(handler, '_qp');
}
},
_getHandlerFunction: function () {
var getHandler = this._super.apply(this, arguments);
var handlerPromises = this._handlerPromises;
var seenHandlers = this._seenHandlers;
return function (routeName) {
fetchedHandlers.push(routeName);
// Cache the returns so we don't have more than one Promise for a
// given handler.
return handlerPromises[routeName] || (handlerPromises[routeName] = new _emberRuntime.RSVP.Promise(function (resolve) {
setTimeout(function () {
var handler = getHandler(routeName);
seenHandlers[routeName] = handler;
resolve(handler);
}, 10);
}));
};
}
};
}
}]);
return _class;
}(_internalTestHelpers.QueryParamTestCase));
});
enifed('ember/tests/routing/query_params_test/query_params_paramless_link_to_test', ['ember-babel', 'ember-runtime', 'ember-views', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _emberViews, _internalTestHelpers) {
'use strict';
(0, _internalTestHelpers.moduleFor)('Query Params - paramless link-to', function (_QueryParamTestCase) {
(0, _emberBabel.inherits)(_class, _QueryParamTestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments));
}
_class.prototype.testParamlessLinks = function (assert, routeName) {
assert.expect(1);
this.addTemplate(routeName, '{{link-to \'index\' \'index\' id=\'index-link\'}}');
this.add('controller:' + routeName, _emberRuntime.Controller.extend({
queryParams: ['foo'],
foo: 'wat'
}));
return this.visit('/?foo=YEAH').then(function () {
assert.equal((0, _emberViews.jQuery)('#index-link').attr('href'), '/?foo=YEAH');
});
};
_class.prototype['@test param-less links in an app booted with query params in the URL don\'t reset the query params: application'] = function (assert) {
return this.testParamlessLinks(assert, 'application');
};
_class.prototype['@test param-less links in an app booted with query params in the URL don\'t reset the query params: index'] = function (assert) {
return this.testParamlessLinks(assert, 'index');
};
return _class;
}(_internalTestHelpers.QueryParamTestCase));
});
enifed('ember/tests/routing/query_params_test/shared_state_test', ['ember-babel', 'ember-runtime', 'ember', 'ember-metal', 'ember-views', 'internal-test-helpers'], function (_emberBabel, _emberRuntime, _ember, _emberMetal, _emberViews, _internalTestHelpers) {
'use strict';
(0, _internalTestHelpers.moduleFor)('Query Params - shared service state', function (_QueryParamTestCase) {
(0, _emberBabel.inherits)(_class, _QueryParamTestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _QueryParamTestCase.apply(this, arguments));
}
_class.prototype.boot = function () {
this.setupApplication();
return this.visitApplication();
};
_class.prototype.setupApplication = function () {
this.router.map(function () {
this.route('home', { path: '/' });
this.route('dashboard');
});
this.add('service:filters', _emberRuntime.Service.extend({
shared: true
}));
this.add('controller:home', _emberRuntime.Controller.extend({
filters: _ember.default.inject.service()
}));
this.add('controller:dashboard', _emberRuntime.Controller.extend({
filters: _ember.default.inject.service(),
queryParams: [{ 'filters.shared': 'shared' }]
}));
this.addTemplate('application', '{{link-to \'Home\' \'home\' }} {{outlet}}
');
this.addTemplate('home', '{{link-to \'Dashboard\' \'dashboard\' }}{{input type="checkbox" id=\'filters-checkbox\' checked=(mut filters.shared) }}');
this.addTemplate('dashboard', '{{link-to \'Home\' \'home\' }}');
};
_class.prototype.visitApplication = function () {
return this.visit('/');
};
_class.prototype['@test can modify shared state before transition'] = function (assert) {
var _this2 = this;
assert.expect(1);
return this.boot().then(function () {
_this2.$input = (0, _emberViews.jQuery)('#filters-checkbox');
// click the checkbox once to set filters.shared to false
(0, _emberMetal.run)(_this2.$input, 'click');
return _this2.visit('/dashboard').then(function () {
assert.ok(true, 'expecting navigating to dashboard to succeed');
});
});
};
_class.prototype['@test can modify shared state back to the default value before transition'] = function (assert) {
var _this3 = this;
assert.expect(1);
return this.boot().then(function () {
_this3.$input = (0, _emberViews.jQuery)('#filters-checkbox');
// click the checkbox twice to set filters.shared to false and back to true
(0, _emberMetal.run)(_this3.$input, 'click');
(0, _emberMetal.run)(_this3.$input, 'click');
return _this3.visit('/dashboard').then(function () {
assert.ok(true, 'expecting navigating to dashboard to succeed');
});
});
};
return _class;
}(_internalTestHelpers.QueryParamTestCase));
});
enifed('ember/tests/routing/router_map_test', ['ember-babel', 'internal-test-helpers', 'ember-metal', 'ember-routing'], function (_emberBabel, _internalTestHelpers, _emberMetal, _emberRouting) {
'use strict';
(0, _internalTestHelpers.moduleFor)('Router.map', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test Router.map returns an Ember Router class'] = function (assert) {
assert.expect(1);
var ret = this.router.map(function () {
this.route('hello');
});
assert.ok(_emberRouting.Router.detect(ret));
};
_class.prototype['@test Router.map can be called multiple times'] = function (assert) {
var _this2 = this;
assert.expect(2);
this.addTemplate('hello', 'Hello!');
this.addTemplate('goodbye', 'Goodbye!');
this.router.map(function () {
this.route('hello');
});
this.router.map(function () {
this.route('goodbye');
});
return (0, _emberMetal.run)(function () {
return _this2.visit('/hello').then(function () {
_this2.assertText('Hello!');
}).then(function () {
return _this2.visit('/goodbye');
}).then(function () {
_this2.assertText('Goodbye!');
});
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed('ember/tests/routing/router_service_test/basic_test', ['ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers'], function () {
'use strict';
});
enifed('ember/tests/routing/router_service_test/currenturl_lifecycle_test', ['ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers'], function () {
'use strict';
});
enifed('ember/tests/routing/router_service_test/replaceWith_test', ['ember-routing', 'internal-test-helpers', 'router'], function () {
'use strict';
});
enifed('ember/tests/routing/router_service_test/transitionTo_test', ['ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers', 'router'], function () {
'use strict';
});
enifed('ember/tests/routing/router_service_test/urlFor_test', ['ember-runtime', 'ember-glimmer', 'ember-routing', 'ember-metal', 'internal-test-helpers'], function (_emberRuntime) {
'use strict';
});
enifed('ember/tests/routing/substates_test', ['ember-runtime', 'ember-routing', 'ember-metal', 'ember-template-compiler', 'ember-application', 'ember-views', 'ember-glimmer'], function (_emberRuntime, _emberRouting, _emberMetal, _emberTemplateCompiler, _emberApplication, _emberViews, _emberGlimmer) {
'use strict';
var Router = void 0,
App = void 0,
templates = void 0,
router = void 0,
container = void 0,
counter = void 0;
function step(expectedValue, description) {
equal(counter, expectedValue, 'Step ' + expectedValue + ': ' + description);
counter++;
}
function bootApplication(startingURL) {
for (var name in templates) {
(0, _emberGlimmer.setTemplate)(name, (0, _emberTemplateCompiler.compile)(templates[name]));
}
if (startingURL) {
_emberRouting.NoneLocation.reopen({
path: startingURL
});
}
startingURL = startingURL || '';
router = container.lookup('router:main');
(0, _emberMetal.run)(App, 'advanceReadiness');
}
QUnit.module('Loading/Error Substates', {
setup: function () {
counter = 1;
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create({
name: 'App',
rootElement: '#qunit-fixture',
// fake a modules resolver
Resolver: _emberApplication.Resolver.extend({ moduleBasedResolver: true })
});
App.deferReadiness();
App.Router.reopen({
location: 'none'
});
Router = App.Router;
container = App.__container__;
templates = {
application: '{{outlet}}
',
index: 'INDEX',
loading: 'LOADING',
bro: 'BRO',
sis: 'SIS'
};
});
},
teardown: function () {
(0, _emberMetal.run)(function () {
App.destroy();
App = null;
(0, _emberGlimmer.setTemplates)({});
});
_emberRouting.NoneLocation.reopen({
path: ''
});
}
});
QUnit.test('Slow promise from a child route of application enters nested loading state', function () {
var broDeferred = _emberRuntime.RSVP.defer();
Router.map(function () {
this.route('bro');
});
App.ApplicationRoute = _emberRouting.Route.extend({
setupController: function () {
step(2, 'ApplicationRoute#setup');
}
});
App.BroRoute = _emberRouting.Route.extend({
model: function () {
step(1, 'BroRoute#model');
return broDeferred.promise;
}
});
bootApplication('/bro');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'LOADING', 'The Loading template is nested in application template\'s outlet');
(0, _emberMetal.run)(broDeferred, 'resolve', {});
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'BRO', 'bro template has loaded and replaced loading template');
});
QUnit.test('Slow promises waterfall on startup', function () {
expect(7);
var grandmaDeferred = _emberRuntime.RSVP.defer();
var sallyDeferred = _emberRuntime.RSVP.defer();
Router.map(function () {
this.route('grandma', function () {
this.route('mom', { resetNamespace: true }, function () {
this.route('sally');
});
});
});
templates.grandma = 'GRANDMA {{outlet}}';
templates.mom = 'MOM {{outlet}}';
templates['mom/loading'] = 'MOMLOADING';
templates['mom/sally'] = 'SALLY';
App.GrandmaRoute = _emberRouting.Route.extend({
model: function () {
step(1, 'GrandmaRoute#model');
return grandmaDeferred.promise;
}
});
App.MomRoute = _emberRouting.Route.extend({
model: function () {
step(2, 'Mom#model');
return {};
}
});
App.MomSallyRoute = _emberRouting.Route.extend({
model: function () {
step(3, 'SallyRoute#model');
return sallyDeferred.promise;
},
setupController: function () {
step(4, 'SallyRoute#setupController');
}
});
bootApplication('/grandma/mom/sally');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'LOADING', 'The Loading template is nested in application template\'s outlet');
(0, _emberMetal.run)(grandmaDeferred, 'resolve', {});
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA MOM MOMLOADING', 'Mom\'s child loading route is displayed due to sally\'s slow promise');
(0, _emberMetal.run)(sallyDeferred, 'resolve', {});
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA MOM SALLY', 'Sally template displayed');
});
QUnit.test('ApplicationRoute#currentPath reflects loading state path', function () {
expect(4);
var momDeferred = _emberRuntime.RSVP.defer();
Router.map(function () {
this.route('grandma', function () {
this.route('mom');
});
});
templates.grandma = 'GRANDMA {{outlet}}';
templates['grandma/loading'] = 'GRANDMALOADING';
templates['grandma/mom'] = 'MOM';
App.GrandmaMomRoute = _emberRouting.Route.extend({
model: function () {
return momDeferred.promise;
}
});
bootApplication('/grandma/mom');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA GRANDMALOADING');
var appController = container.lookup('controller:application');
equal(appController.get('currentPath'), 'grandma.loading', 'currentPath reflects loading state');
(0, _emberMetal.run)(momDeferred, 'resolve', {});
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA MOM');
equal(appController.get('currentPath'), 'grandma.mom', 'currentPath reflects final state');
});
QUnit.test('Slow promises returned from ApplicationRoute#model don\'t enter LoadingRoute', function () {
expect(2);
var appDeferred = _emberRuntime.RSVP.defer();
App.ApplicationRoute = _emberRouting.Route.extend({
model: function () {
return appDeferred.promise;
}
});
App.LoadingRoute = _emberRouting.Route.extend({
setupController: function () {
ok(false, 'shouldn\'t get here');
}
});
bootApplication();
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), '', 'nothing has been rendered yet');
(0, _emberMetal.run)(appDeferred, 'resolve', {});
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX');
});
QUnit.test('Don\'t enter loading route unless either route or template defined', function () {
delete templates.loading;
expect(2);
var indexDeferred = _emberRuntime.RSVP.defer();
App.ApplicationController = _emberRuntime.Controller.extend();
App.IndexRoute = _emberRouting.Route.extend({
model: function () {
return indexDeferred.promise;
}
});
bootApplication();
var appController = container.lookup('controller:application');
ok(appController.get('currentPath') !== 'loading', 'loading state not entered');
(0, _emberMetal.run)(indexDeferred, 'resolve', {});
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX');
});
QUnit.test('Enter loading route if only LoadingRoute defined', function () {
delete templates.loading;
expect(4);
var indexDeferred = _emberRuntime.RSVP.defer();
App.IndexRoute = _emberRouting.Route.extend({
model: function () {
step(1, 'IndexRoute#model');
return indexDeferred.promise;
}
});
App.LoadingRoute = _emberRouting.Route.extend({
setupController: function () {
step(2, 'LoadingRoute#setupController');
}
});
bootApplication();
var appController = container.lookup('controller:application');
equal(appController.get('currentPath'), 'loading', 'loading state entered');
(0, _emberMetal.run)(indexDeferred, 'resolve', {});
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX');
});
QUnit.test('Enter child loading state of pivot route', function () {
expect(4);
var deferred = _emberRuntime.RSVP.defer();
Router.map(function () {
this.route('grandma', function () {
this.route('mom', { resetNamespace: true }, function () {
this.route('sally');
});
this.route('smells');
});
});
templates['grandma/loading'] = 'GMONEYLOADING';
App.ApplicationController = _emberRuntime.Controller.extend();
App.MomSallyRoute = _emberRouting.Route.extend({
setupController: function () {
step(1, 'SallyRoute#setupController');
}
});
App.GrandmaSmellsRoute = _emberRouting.Route.extend({
model: function () {
return deferred.promise;
}
});
bootApplication('/grandma/mom/sally');
var appController = container.lookup('controller:application');
equal(appController.get('currentPath'), 'grandma.mom.sally', 'Initial route fully loaded');
(0, _emberMetal.run)(router, 'transitionTo', 'grandma.smells');
equal(appController.get('currentPath'), 'grandma.loading', 'in pivot route\'s child loading state');
(0, _emberMetal.run)(deferred, 'resolve', {});
equal(appController.get('currentPath'), 'grandma.smells', 'Finished transition');
});
QUnit.test('Loading actions bubble to root, but don\'t enter substates above pivot', function () {
expect(6);
delete templates.loading;
var sallyDeferred = _emberRuntime.RSVP.defer();
var smellsDeferred = _emberRuntime.RSVP.defer();
Router.map(function () {
this.route('grandma', function () {
this.route('mom', { resetNamespace: true }, function () {
this.route('sally');
});
this.route('smells');
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
App.ApplicationRoute = _emberRouting.Route.extend({
actions: {
loading: function () {
ok(true, 'loading action received on ApplicationRoute');
}
}
});
App.MomSallyRoute = _emberRouting.Route.extend({
model: function () {
return sallyDeferred.promise;
}
});
App.GrandmaSmellsRoute = _emberRouting.Route.extend({
model: function () {
return smellsDeferred.promise;
}
});
bootApplication('/grandma/mom/sally');
var appController = container.lookup('controller:application');
ok(!appController.get('currentPath'), 'Initial route fully loaded');
(0, _emberMetal.run)(sallyDeferred, 'resolve', {});
equal(appController.get('currentPath'), 'grandma.mom.sally', 'transition completed');
(0, _emberMetal.run)(router, 'transitionTo', 'grandma.smells');
equal(appController.get('currentPath'), 'grandma.mom.sally', 'still in initial state because the only loading state is above the pivot route');
(0, _emberMetal.run)(smellsDeferred, 'resolve', {});
equal(appController.get('currentPath'), 'grandma.smells', 'Finished transition');
});
QUnit.test('Default error event moves into nested route', function () {
expect(6);
templates['grandma'] = 'GRANDMA {{outlet}}';
templates['grandma/error'] = 'ERROR: {{model.msg}}';
Router.map(function () {
this.route('grandma', function () {
this.route('mom', { resetNamespace: true }, function () {
this.route('sally');
});
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
App.MomSallyRoute = _emberRouting.Route.extend({
model: function () {
step(1, 'MomSallyRoute#model');
return _emberRuntime.RSVP.reject({
msg: 'did it broke?'
});
},
actions: {
error: function () {
step(2, 'MomSallyRoute#actions.error');
return true;
}
}
});
throws(function () {
bootApplication('/grandma/mom/sally');
}, function (err) {
return err.msg === 'did it broke?';
});
step(3, 'App finished booting');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA ERROR: did it broke?', 'error bubbles');
var appController = container.lookup('controller:application');
equal(appController.get('currentPath'), 'grandma.error', 'Initial route fully loaded');
});
QUnit.test('Error events that aren\'t bubbled don\t throw application assertions', function () {
expect(2);
templates['grandma'] = 'GRANDMA {{outlet}}';
Router.map(function () {
this.route('grandma', function () {
this.route('mom', { resetNamespace: true }, function () {
this.route('sally');
});
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
App.MomSallyRoute = _emberRouting.Route.extend({
model: function () {
step(1, 'MomSallyRoute#model');
return _emberRuntime.RSVP.reject({
msg: 'did it broke?'
});
},
actions: {
error: function (err) {
equal(err.msg, 'did it broke?');
return false;
}
}
});
bootApplication('/grandma/mom/sally');
});
QUnit.test('Non-bubbled errors that re-throw aren\'t swallowed', function () {
expect(2);
templates['grandma'] = 'GRANDMA {{outlet}}';
Router.map(function () {
this.route('grandma', function () {
this.route('mom', { resetNamespace: true }, function () {
this.route('sally');
});
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
App.MomSallyRoute = _emberRouting.Route.extend({
model: function () {
step(1, 'MomSallyRoute#model');
return _emberRuntime.RSVP.reject({
msg: 'did it broke?'
});
},
actions: {
error: function (err) {
// returns undefined which is falsey
throw err;
}
}
});
throws(function () {
bootApplication('/grandma/mom/sally');
}, function (err) {
return err.msg === 'did it broke?';
});
});
QUnit.test('Handled errors that re-throw aren\'t swallowed', function () {
expect(4);
var handledError = void 0;
templates['grandma'] = 'GRANDMA {{outlet}}';
Router.map(function () {
this.route('grandma', function () {
this.route('mom', { resetNamespace: true }, function () {
this.route('sally');
this.route('this-route-throws');
});
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
App.MomSallyRoute = _emberRouting.Route.extend({
model: function () {
step(1, 'MomSallyRoute#model');
return _emberRuntime.RSVP.reject({
msg: 'did it broke?'
});
},
actions: {
error: function (err) {
step(2, 'MomSallyRoute#error');
handledError = err;
this.transitionTo('mom.this-route-throws');
// Marks error as handled
return false;
}
}
});
App.MomThisRouteThrowsRoute = _emberRouting.Route.extend({
model: function () {
step(3, 'MomThisRouteThrows#model');
throw handledError;
}
});
throws(function () {
bootApplication('/grandma/mom/sally');
}, function (err) {
return err.msg === 'did it broke?';
});
});
QUnit.test('Handled errors that bubble can be handled at a higher level', function () {
expect(4);
var handledError = void 0;
templates['grandma'] = 'GRANDMA {{outlet}}';
Router.map(function () {
this.route('grandma', function () {
this.route('mom', { resetNamespace: true }, function () {
this.route('sally');
});
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
App.MomRoute = _emberRouting.Route.extend({
actions: {
error: function (err) {
step(3, 'MomRoute#error');
equal(err, handledError, 'error handled and rebubbled is handleable at higher route');
}
}
});
App.MomSallyRoute = _emberRouting.Route.extend({
model: function () {
step(1, 'MomSallyRoute#model');
return _emberRuntime.RSVP.reject({
msg: 'did it broke?'
});
},
actions: {
error: function (err) {
step(2, 'MomSallyRoute#error');
handledError = err;
return true;
}
}
});
bootApplication('/grandma/mom/sally');
});
QUnit.test('errors that are bubbled are thrown at a higher level if not handled', function () {
expect(3);
templates['grandma'] = 'GRANDMA {{outlet}}';
Router.map(function () {
this.route('grandma', function () {
this.route('mom', { resetNamespace: true }, function () {
this.route('sally');
});
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
App.MomSallyRoute = _emberRouting.Route.extend({
model: function () {
step(1, 'MomSallyRoute#model');
return _emberRuntime.RSVP.reject({
msg: 'did it broke?'
});
},
actions: {
error: function () {
step(2, 'MomSallyRoute#error');
return true;
}
}
});
throws(function () {
bootApplication('/grandma/mom/sally');
}, function (err) {
return err.msg === 'did it broke?';
}, 'Correct error was thrown');
});
QUnit.test('Handled errors that are thrown through rejection aren\'t swallowed', function () {
expect(4);
var handledError = void 0;
templates['grandma'] = 'GRANDMA {{outlet}}';
Router.map(function () {
this.route('grandma', function () {
this.route('mom', { resetNamespace: true }, function () {
this.route('sally');
this.route('this-route-throws');
});
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
App.MomSallyRoute = _emberRouting.Route.extend({
model: function () {
step(1, 'MomSallyRoute#model');
return _emberRuntime.RSVP.reject({
msg: 'did it broke?'
});
},
actions: {
error: function (err) {
step(2, 'MomSallyRoute#error');
handledError = err;
this.transitionTo('mom.this-route-throws');
// Marks error as handled
return false;
}
}
});
App.MomThisRouteThrowsRoute = _emberRouting.Route.extend({
model: function () {
step(3, 'MomThisRouteThrows#model');
return _emberRuntime.RSVP.reject(handledError);
}
});
throws(function () {
bootApplication('/grandma/mom/sally');
}, function (err) {
return err.msg === 'did it broke?';
});
});
QUnit.test('Setting a query param during a slow transition should work', function () {
var deferred = _emberRuntime.RSVP.defer();
Router.map(function () {
this.route('grandma', { path: '/grandma/:seg' }, function () {});
});
templates['grandma/loading'] = 'GMONEYLOADING';
App.ApplicationController = _emberRuntime.Controller.extend();
App.IndexRoute = _emberRouting.Route.extend({
beforeModel: function () {
this.transitionTo('grandma', 1);
}
});
App.GrandmaRoute = _emberRouting.Route.extend({
queryParams: {
test: { defaultValue: 1 }
}
});
App.GrandmaIndexRoute = _emberRouting.Route.extend({
model: function () {
return deferred.promise;
}
});
bootApplication('/');
var appController = container.lookup('controller:application');
var grandmaController = container.lookup('controller:grandma');
equal(appController.get('currentPath'), 'grandma.loading', 'Initial route should be loading');
(0, _emberMetal.run)(function () {
grandmaController.set('test', 3);
});
equal(appController.get('currentPath'), 'grandma.loading', 'Route should still be loading');
equal(grandmaController.get('test'), 3, 'Controller query param value should have changed');
(0, _emberMetal.run)(deferred, 'resolve', {});
equal(appController.get('currentPath'), 'grandma.index', 'Transition should be complete');
});
QUnit.test('Slow promises returned from ApplicationRoute#model enter ApplicationLoadingRoute if present', function () {
expect(2);
var appDeferred = _emberRuntime.RSVP.defer();
App.ApplicationRoute = _emberRouting.Route.extend({
model: function () {
return appDeferred.promise;
}
});
var loadingRouteEntered = false;
App.ApplicationLoadingRoute = _emberRouting.Route.extend({
setupController: function () {
loadingRouteEntered = true;
}
});
bootApplication();
ok(loadingRouteEntered, 'ApplicationLoadingRoute was entered');
(0, _emberMetal.run)(appDeferred, 'resolve', {});
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX');
});
QUnit.test('Slow promises returned from ApplicationRoute#model enter application_loading if template present', function () {
expect(3);
templates['application_loading'] = 'TOPLEVEL LOADING
';
var appDeferred = _emberRuntime.RSVP.defer();
App.ApplicationRoute = _emberRouting.Route.extend({
model: function () {
return appDeferred.promise;
}
});
bootApplication();
equal((0, _emberViews.jQuery)('#qunit-fixture #toplevel-loading').text(), 'TOPLEVEL LOADING');
(0, _emberMetal.run)(appDeferred, 'resolve', {});
equal((0, _emberViews.jQuery)('#toplevel-loading', '#qunit-fixture').length, 0, 'top-level loading View has been entirely removed from DOM');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX');
});
QUnit.test('Default error event moves into nested route, prioritizing more specifically named error route', function () {
expect(6);
templates['grandma'] = 'GRANDMA {{outlet}}';
templates['grandma/error'] = 'ERROR: {{model.msg}}';
templates['mom_error'] = 'MOM ERROR: {{model.msg}}';
Router.map(function () {
this.route('grandma', function () {
this.route('mom', { resetNamespace: true }, function () {
this.route('sally');
});
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
App.MomSallyRoute = _emberRouting.Route.extend({
model: function () {
step(1, 'MomSallyRoute#model');
return _emberRuntime.RSVP.reject({
msg: 'did it broke?'
});
},
actions: {
error: function () {
step(2, 'MomSallyRoute#actions.error');
return true;
}
}
});
throws(function () {
bootApplication('/grandma/mom/sally');
}, function (err) {
return err.msg === 'did it broke?';
});
step(3, 'App finished booting');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'GRANDMA MOM ERROR: did it broke?', 'the more specifically-named mom error substate was entered over the other error route');
var appController = container.lookup('controller:application');
equal(appController.get('currentPath'), 'grandma.mom_error', 'Initial route fully loaded');
});
QUnit.test('Prioritized substate entry works with preserved-namespace nested routes', function () {
expect(2);
templates['foo/bar_loading'] = 'FOOBAR LOADING';
templates['foo/bar/index'] = 'YAY';
Router.map(function () {
this.route('foo', function () {
this.route('bar', { path: '/bar' }, function () {});
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
var deferred = _emberRuntime.RSVP.defer();
App.FooBarRoute = _emberRouting.Route.extend({
model: function () {
return deferred.promise;
}
});
bootApplication('/foo/bar');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'FOOBAR LOADING', 'foo.bar_loading was entered (as opposed to something like foo/foo/bar_loading)');
(0, _emberMetal.run)(deferred, 'resolve');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'YAY');
});
QUnit.test('Prioritized substate entry works with reset-namespace nested routes', function () {
expect(2);
templates['bar_loading'] = 'BAR LOADING';
templates['bar/index'] = 'YAY';
Router.map(function () {
this.route('foo', function () {
this.route('bar', { path: '/bar', resetNamespace: true }, function () {});
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
var deferred = _emberRuntime.RSVP.defer();
App.BarRoute = _emberRouting.Route.extend({
model: function () {
return deferred.promise;
}
});
bootApplication('/foo/bar');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'BAR LOADING', 'foo.bar_loading was entered (as opposed to something like foo/foo/bar_loading)');
(0, _emberMetal.run)(deferred, 'resolve');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'YAY');
});
QUnit.test('Prioritized loading substate entry works with preserved-namespace nested routes', function () {
expect(2);
templates['foo/bar_loading'] = 'FOOBAR LOADING';
templates['foo/bar'] = 'YAY';
Router.map(function () {
this.route('foo', function () {
this.route('bar');
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
var deferred = _emberRuntime.RSVP.defer();
App.FooBarRoute = _emberRouting.Route.extend({
model: function () {
return deferred.promise;
}
});
bootApplication('/foo/bar');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'FOOBAR LOADING', 'foo.bar_loading was entered (as opposed to something like foo/foo/bar_loading)');
(0, _emberMetal.run)(deferred, 'resolve');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'YAY');
});
QUnit.test('Prioritized error substate entry works with preserved-namespace nested routes', function () {
expect(2);
templates['foo/bar_error'] = 'FOOBAR ERROR: {{model.msg}}';
templates['foo/bar'] = 'YAY';
Router.map(function () {
this.route('foo', function () {
this.route('bar');
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
App.FooBarRoute = _emberRouting.Route.extend({
model: function () {
return _emberRuntime.RSVP.reject({
msg: 'did it broke?'
});
}
});
throws(function () {
bootApplication('/foo/bar');
}, function (err) {
return err.msg === 'did it broke?';
});
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'FOOBAR ERROR: did it broke?', 'foo.bar_error was entered (as opposed to something like foo/foo/bar_error)');
});
QUnit.test('Prioritized loading substate entry works with auto-generated index routes', function () {
expect(2);
templates['foo/index_loading'] = 'FOO LOADING';
templates['foo/index'] = 'YAY';
templates['foo'] = '{{outlet}}';
Router.map(function () {
this.route('foo', function () {
this.route('bar');
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
var deferred = _emberRuntime.RSVP.defer();
App.FooIndexRoute = _emberRouting.Route.extend({
model: function () {
return deferred.promise;
}
});
App.FooRoute = _emberRouting.Route.extend({
model: function () {
return true;
}
});
bootApplication('/foo');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'FOO LOADING', 'foo.index_loading was entered');
(0, _emberMetal.run)(deferred, 'resolve');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'YAY');
});
QUnit.test('Prioritized error substate entry works with auto-generated index routes', function () {
expect(2);
templates['foo/index_error'] = 'FOO ERROR: {{model.msg}}';
templates['foo/index'] = 'YAY';
templates['foo'] = '{{outlet}}';
Router.map(function () {
this.route('foo', function () {
this.route('bar');
});
});
App.ApplicationController = _emberRuntime.Controller.extend();
App.FooIndexRoute = _emberRouting.Route.extend({
model: function () {
return _emberRuntime.RSVP.reject({
msg: 'did it broke?'
});
}
});
App.FooRoute = _emberRouting.Route.extend({
model: function () {
return true;
}
});
throws(function () {
return bootApplication('/foo');
}, function (err) {
return err.msg === 'did it broke?';
});
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'FOO ERROR: did it broke?', 'foo.index_error was entered');
});
QUnit.test('Rejected promises returned from ApplicationRoute transition into top-level application_error', function () {
expect(3);
templates['application_error'] = 'TOPLEVEL ERROR: {{model.msg}}
';
var reject = true;
App.ApplicationRoute = _emberRouting.Route.extend({
model: function () {
if (reject) {
return _emberRuntime.RSVP.reject({ msg: 'BAD NEWS BEARS' });
} else {
return {};
}
}
});
throws(function () {
return bootApplication();
}, function (err) {
return err.msg === 'BAD NEWS BEARS';
});
equal((0, _emberViews.jQuery)('#toplevel-error', '#qunit-fixture').text(), 'TOPLEVEL ERROR: BAD NEWS BEARS');
reject = false;
(0, _emberMetal.run)(router, 'transitionTo', 'index');
equal((0, _emberViews.jQuery)('#app', '#qunit-fixture').text(), 'INDEX');
});
});
enifed('ember/tests/routing/toplevel_dom_test', ['ember-babel', 'internal-test-helpers'], function (_emberBabel, _internalTestHelpers) {
'use strict';
(0, _internalTestHelpers.moduleFor)('Top Level DOM Structure', function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(_class, _ApplicationTestCase);
function _class() {
return (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.apply(this, arguments));
}
_class.prototype['@test Topmost template always get an element'] = function (assert) {
var _this2 = this;
this.addTemplate('application', 'hello world');
return this.visit('/').then(function () {
assert.equal(_this2.$('> .ember-view').text(), 'hello world');
});
};
return _class;
}(_internalTestHelpers.ApplicationTestCase));
});
enifed('ember/tests/view_instrumentation_test', ['ember-metal', 'ember-views', 'ember-application', 'ember-template-compiler', 'ember-glimmer'], function (_emberMetal, _emberViews, _emberApplication, _emberTemplateCompiler, _emberGlimmer) {
'use strict';
var App = void 0,
$fixture = void 0;
function setupExample() {
// setup templates
(0, _emberGlimmer.setTemplate)('application', (0, _emberTemplateCompiler.compile)('{{outlet}}'));
(0, _emberGlimmer.setTemplate)('index', (0, _emberTemplateCompiler.compile)('Index '));
(0, _emberGlimmer.setTemplate)('posts', (0, _emberTemplateCompiler.compile)('Posts '));
App.Router.map(function () {
this.route('posts');
});
}
function handleURL(path) {
var router = App.__container__.lookup('router:main');
return (0, _emberMetal.run)(router, 'handleURL', path);
}
QUnit.module('View Instrumentation', {
setup: function () {
(0, _emberMetal.run)(function () {
App = _emberApplication.Application.create({
rootElement: '#qunit-fixture'
});
App.deferReadiness();
App.Router.reopen({
location: 'none'
});
});
$fixture = (0, _emberViews.jQuery)('#qunit-fixture');
setupExample();
},
teardown: function () {
(0, _emberMetal.instrumentationReset)();
(0, _emberMetal.run)(App, 'destroy');
App = null;
(0, _emberGlimmer.setTemplates)({});
}
});
QUnit.test('Nodes without view instances are instrumented', function (assert) {
var called = false;
(0, _emberMetal.instrumentationSubscribe)('render', {
before: function () {
called = true;
},
after: function () {}
});
(0, _emberMetal.run)(App, 'advanceReadiness');
assert.equal($fixture.text(), 'Index', 'It rendered the right template');
assert.ok(called, 'Instrumentation called on first render');
called = false;
handleURL('/posts');
assert.equal($fixture.text(), 'Posts', 'It rendered the right template');
assert.ok(called, 'instrumentation called on transition to non-view backed route');
});
});
enifed('internal-test-helpers/apply-mixins', ['exports', 'ember-utils'], function (exports, _emberUtils) {
'use strict';
exports.default = function (TestClass) {
var _len, mixins, _key;
for (_len = arguments.length, mixins = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
mixins[_key - 1] = arguments[_key];
}
mixins.forEach(function (mixinOrGenerator) {
var mixin = void 0,
generator;
if (isGenerator(mixinOrGenerator)) {
generator = mixinOrGenerator;
mixin = {};
generator.cases.forEach(function (value, idx) {
(0, _emberUtils.assign)(mixin, generator.generate(value, idx));
});
} else {
mixin = mixinOrGenerator;
}
(0, _emberUtils.assign)(TestClass.prototype, mixin);
});
return TestClass;
};
function isGenerator(mixin) {
return Array.isArray(mixin.cases) && typeof mixin.generate === 'function';
}
});
enifed('internal-test-helpers/build-owner', ['exports', 'container', 'ember-routing', 'ember-application', 'ember-runtime'], function (exports, _container, _emberRouting, _emberApplication, _emberRuntime) {
'use strict';
exports.default = function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var ownerOptions = options.ownerOptions || {};
var resolver = options.resolver;
var bootOptions = options.bootOptions || {};
var Owner = _emberRuntime.Object.extend(_emberRuntime.RegistryProxyMixin, _emberRuntime.ContainerProxyMixin);
var namespace = _emberRuntime.Object.create({
Resolver: {
create: function () {
return resolver;
}
}
});
var fallbackRegistry = _emberApplication.Application.buildRegistry(namespace);
fallbackRegistry.register('router:main', _emberRouting.Router);
var registry = new _container.Registry({
fallback: fallbackRegistry
});
_emberApplication.ApplicationInstance.setupRegistry(registry, bootOptions);
var owner = Owner.create({
__registry__: registry,
__container__: null
}, ownerOptions);
var container = registry.container({ owner: owner });
owner.__container__ = container;
return owner;
};
});
enifed('internal-test-helpers/confirm-export', ['exports', 'require'], function (exports, _require2) {
'use strict';
exports.default = function (Ember, assert, path, moduleId, exportName) {
var desc = getDescriptor(Ember, path);
assert.ok(desc, 'the property exists on the global');
var mod = (0, _require2.default)(moduleId);
if (typeof exportName === 'string') {
assert.equal(desc.value, mod[exportName], 'Ember.' + path + ' is exported correctly');
assert.notEqual(mod[exportName], undefined, 'Ember.' + path + ' is not `undefined`');
} else {
assert.equal(desc.get, mod[exportName.get], 'Ember.' + path + ' getter is exported correctly');
assert.notEqual(desc.get, undefined, 'Ember.' + path + ' getter is not undefined');
if (exportName.set) {
assert.equal(desc.set, mod[exportName.set], 'Ember.' + path + ' setter is exported correctly');
assert.notEqual(desc.set, undefined, 'Ember.' + path + ' setter is not undefined');
}
}
};
function getDescriptor(obj, path) {
var parts = path.split('.'),
i,
part;
var value = obj;
for (i = 0; i < parts.length - 1; i++) {
part = parts[i];
value = value[part];
if (!value) {
return undefined;
}
}
var last = parts[parts.length - 1];
return Object.getOwnPropertyDescriptor(value, last);
}
});
enifed('internal-test-helpers/equal-inner-html', ['exports'], function (exports) {
'use strict';
exports.default = function (fragment, html) {
var actualHTML = normalizeInnerHTML(fragment.innerHTML);
QUnit.push(actualHTML === html, actualHTML, html);
};
// detect side-effects of cloning svg elements in IE9-11
var ieSVGInnerHTML = function () {
if (!document.createElementNS) {
return false;
}
var div = document.createElement('div');
var node = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
div.appendChild(node);
var clone = div.cloneNode(true);
return clone.innerHTML === ' ';
}();
function normalizeInnerHTML(actualHTML) {
if (ieSVGInnerHTML) {
// Replace ` ` with ` `, etc.
// drop namespace attribute
// replace self-closing elements
actualHTML = actualHTML.replace(/ xmlns="[^"]+"/, '').replace(/<([^ >]+) [^\/>]*\/>/gi, function (tag, tagName) {
return tag.slice(0, tag.length - 3) + '>' + tagName + '>';
});
}
return actualHTML;
}
});
enifed('internal-test-helpers/equal-tokens', ['exports', 'simple-html-tokenizer'], function (exports, _simpleHtmlTokenizer) {
'use strict';
exports.default = function (actualContainer, expectedHTML) {
var message = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var actual = generateTokens(actualContainer);
var expected = generateTokens(expectedHTML);
normalizeTokens(actual.tokens);
normalizeTokens(expected.tokens);
var equiv = QUnit.equiv(actual.tokens, expected.tokens);
if (equiv && expected.html !== actual.html) {
deepEqual(actual.tokens, expected.tokens, message);
} else {
QUnit.push(QUnit.equiv(actual.tokens, expected.tokens), actual.html, expected.html, message);
}
};
function generateTokens(containerOrHTML) {
if (typeof containerOrHTML === 'string') {
return {
tokens: (0, _simpleHtmlTokenizer.tokenize)(containerOrHTML),
html: containerOrHTML
};
} else {
return {
tokens: (0, _simpleHtmlTokenizer.tokenize)(containerOrHTML.innerHTML),
html: containerOrHTML.innerHTML
};
}
}
function normalizeTokens(tokens) {
tokens.forEach(function (token) {
if (token.type === 'StartTag') {
token.attributes = token.attributes.sort(function (a, b) {
if (a[0] > b[0]) {
return 1;
}
if (a[0] < b[0]) {
return -1;
}
return 0;
});
}
});
}
});
enifed('internal-test-helpers/factory', ['exports'], function (exports) {
'use strict';
exports.default = function () {
/*jshint validthis: true */
function Klass(options) {
setProperties(this, options);
this._guid = guids++;
this.isDestroyed = false;
}
Klass.prototype.constructor = Klass;
Klass.prototype.destroy = function () {
this.isDestroyed = true;
};
Klass.prototype.toString = function () {
return '';
};
Klass.create = create;
Klass.extend = extend;
Klass.reopen = extend;
Klass.reopenClass = reopenClass;
return Klass;
function create(options) {
return new this.prototype.constructor(options);
}
function reopenClass(options) {
setProperties(this, options);
}
function extend(options) {
function Child(options) {
Klass.call(this, options);
}
var Parent = this;
Child.prototype = new Parent();
Child.prototype.constructor = Child;
setProperties(Child, Klass);
setProperties(Child.prototype, options);
Child.create = create;
Child.extend = extend;
Child.reopen = extend;
Child.reopenClass = reopenClass;
return Child;
}
};
function setProperties(object, properties) {
for (var key in properties) {
if (properties.hasOwnProperty(key)) {
object[key] = properties[key];
}
}
}
var guids = 0;
});
enifed('internal-test-helpers/index', ['exports', 'internal-test-helpers/factory', 'internal-test-helpers/build-owner', 'internal-test-helpers/confirm-export', 'internal-test-helpers/equal-inner-html', 'internal-test-helpers/equal-tokens', 'internal-test-helpers/module-for', 'internal-test-helpers/strip', 'internal-test-helpers/apply-mixins', 'internal-test-helpers/matchers', 'internal-test-helpers/run', 'internal-test-helpers/test-groups', 'internal-test-helpers/test-cases/abstract', 'internal-test-helpers/test-cases/abstract-application', 'internal-test-helpers/test-cases/application', 'internal-test-helpers/test-cases/query-param', 'internal-test-helpers/test-cases/abstract-rendering', 'internal-test-helpers/test-cases/rendering', 'internal-test-helpers/test-cases/router', 'internal-test-helpers/test-cases/autoboot-application', 'internal-test-helpers/test-resolver'], function (exports, _factory, _buildOwner, _confirmExport, _equalInnerHtml, _equalTokens, _moduleFor, _strip, _applyMixins, _matchers, _run, _testGroups, _abstract, _abstractApplication, _application, _queryParam, _abstractRendering, _rendering, _router, _autobootApplication, _testResolver) {
'use strict';
Object.defineProperty(exports, 'factory', {
enumerable: true,
get: function () {
return _factory.default;
}
});
Object.defineProperty(exports, 'buildOwner', {
enumerable: true,
get: function () {
return _buildOwner.default;
}
});
Object.defineProperty(exports, 'confirmExport', {
enumerable: true,
get: function () {
return _confirmExport.default;
}
});
Object.defineProperty(exports, 'equalInnerHTML', {
enumerable: true,
get: function () {
return _equalInnerHtml.default;
}
});
Object.defineProperty(exports, 'equalTokens', {
enumerable: true,
get: function () {
return _equalTokens.default;
}
});
Object.defineProperty(exports, 'moduleFor', {
enumerable: true,
get: function () {
return _moduleFor.default;
}
});
Object.defineProperty(exports, 'strip', {
enumerable: true,
get: function () {
return _strip.default;
}
});
Object.defineProperty(exports, 'applyMixins', {
enumerable: true,
get: function () {
return _applyMixins.default;
}
});
Object.defineProperty(exports, 'equalsElement', {
enumerable: true,
get: function () {
return _matchers.equalsElement;
}
});
Object.defineProperty(exports, 'classes', {
enumerable: true,
get: function () {
return _matchers.classes;
}
});
Object.defineProperty(exports, 'styles', {
enumerable: true,
get: function () {
return _matchers.styles;
}
});
Object.defineProperty(exports, 'regex', {
enumerable: true,
get: function () {
return _matchers.regex;
}
});
Object.defineProperty(exports, 'runAppend', {
enumerable: true,
get: function () {
return _run.runAppend;
}
});
Object.defineProperty(exports, 'runDestroy', {
enumerable: true,
get: function () {
return _run.runDestroy;
}
});
Object.defineProperty(exports, 'testBoth', {
enumerable: true,
get: function () {
return _testGroups.testBoth;
}
});
Object.defineProperty(exports, 'testWithDefault', {
enumerable: true,
get: function () {
return _testGroups.testWithDefault;
}
});
Object.defineProperty(exports, 'AbstractTestCase', {
enumerable: true,
get: function () {
return _abstract.default;
}
});
Object.defineProperty(exports, 'AbstractApplicationTestCase', {
enumerable: true,
get: function () {
return _abstractApplication.default;
}
});
Object.defineProperty(exports, 'ApplicationTestCase', {
enumerable: true,
get: function () {
return _application.default;
}
});
Object.defineProperty(exports, 'QueryParamTestCase', {
enumerable: true,
get: function () {
return _queryParam.default;
}
});
Object.defineProperty(exports, 'AbstractRenderingTestCase', {
enumerable: true,
get: function () {
return _abstractRendering.default;
}
});
Object.defineProperty(exports, 'RenderingTestCase', {
enumerable: true,
get: function () {
return _rendering.default;
}
});
Object.defineProperty(exports, 'RouterTestCase', {
enumerable: true,
get: function () {
return _router.default;
}
});
Object.defineProperty(exports, 'AutobootApplicationTestCase', {
enumerable: true,
get: function () {
return _autobootApplication.default;
}
});
Object.defineProperty(exports, 'TestResolver', {
enumerable: true,
get: function () {
return _testResolver.default;
}
});
Object.defineProperty(exports, 'ModuleBasedTestResolver', {
enumerable: true,
get: function () {
return _testResolver.ModuleBasedResolver;
}
});
});
enifed('internal-test-helpers/matchers', ['exports'], function (exports) {
'use strict';
exports.regex = function (r) {
var _ref2;
return _ref2 = {}, _ref2[MATCHER_BRAND] = true, _ref2.match = function (v) {
return r.test(v);
}, _ref2.expected = function () {
return r.toString();
}, _ref2.message = function () {
return 'should match ' + this.expected();
}, _ref2;
};
exports.classes = function (expected) {
var _ref3;
return _ref3 = {}, _ref3[MATCHER_BRAND] = true, _ref3.match = function (actual) {
actual = actual.trim();
return actual && expected.split(/\s+/).sort().join(' ') === actual.trim().split(/\s+/).sort().join(' ');
}, _ref3.expected = function () {
return expected;
}, _ref3.message = function () {
return 'should match ' + this.expected();
}, _ref3;
};
exports.styles = function (expected) {
var _ref4;
return _ref4 = {}, _ref4[MATCHER_BRAND] = true, _ref4.match = function (actual) {
// coerce `null` or `undefined` to an empty string
// needed for matching empty styles on IE9 - IE11
actual = actual || '';
actual = actual.trim();
return expected.split(';').map(function (s) {
return s.trim();
}).filter(function (s) {
return s;
}).sort().join('; ') === actual.split(';').map(function (s) {
return s.trim();
}).filter(function (s) {
return s;
}).sort().join('; ');
}, _ref4.expected = function () {
return expected;
}, _ref4.message = function () {
return 'should match ' + this.expected();
}, _ref4;
};
exports.equalsElement = function (element, tagName, attributes, content) {
QUnit.push(element.tagName === tagName.toUpperCase(), element.tagName.toLowerCase(), tagName, 'expect tagName to be ' + tagName);
var expectedAttrs = {},
expected,
matcher,
i,
l;
var expectedCount = 0;
for (var name in attributes) {
expected = attributes[name];
if (expected !== null) {
expectedCount++;
}
matcher = isMatcher(expected) ? expected : equalsAttr(expected);
expectedAttrs[name] = matcher;
QUnit.push(expectedAttrs[name].match(element.getAttribute(name)), element.getAttribute(name), matcher.expected(), 'Element\'s ' + name + ' attribute ' + matcher.message());
}
var actualAttributes = {};
for (i = 0, l = element.attributes.length; i < l; i++) {
actualAttributes[element.attributes[i].name] = element.attributes[i].value;
}
if (!(element instanceof HTMLElement)) {
QUnit.push(element instanceof HTMLElement, null, null, 'Element must be an HTML Element, not an SVG Element');
} else {
QUnit.push(element.attributes.length === expectedCount || !attributes, element.attributes.length, expectedCount, 'Expected ' + expectedCount + ' attributes; got ' + element.outerHTML);
if (content !== null) {
QUnit.push(element.innerHTML === content, element.innerHTML, content, 'The element had \'' + content + '\' as its content');
}
}
};
var HTMLElement = window.HTMLElement;
var MATCHER_BRAND = '3d4ef194-13be-4ccf-8dc7-862eea02c93e';
function isMatcher(obj) {
return typeof obj === 'object' && obj !== null && MATCHER_BRAND in obj;
}
function equalsAttr(expected) {
var _ref;
return _ref = {}, _ref[MATCHER_BRAND] = true, _ref.match = function (actual) {
return expected === actual;
}, _ref.expected = function () {
return expected;
}, _ref.message = function () {
return 'should equal ' + this.expected();
}, _ref;
}
});
enifed('internal-test-helpers/module-for', ['exports', 'internal-test-helpers/apply-mixins'], function (exports, _applyMixins) {
'use strict';
exports.default = function (description, TestClass) {
var context = void 0,
_len,
mixins,
_key;
QUnit.module(description, {
setup: function () {
context = new TestClass();
},
teardown: function () {
context.teardown();
}
});
for (_len = arguments.length, mixins = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
mixins[_key - 2] = arguments[_key];
}
(0, _applyMixins.default)(TestClass, mixins);
var proto = TestClass.prototype;
while (proto !== Object.prototype) {
Object.keys(proto).forEach(generateTest);
proto = Object.getPrototypeOf(proto);
}
function generateTest(name) {
if (name.indexOf('@test ') === 0) {
QUnit.test(name.slice(5), function (assert) {
return context[name](assert);
});
} else if (name.indexOf('@skip ') === 0) {
QUnit.skip(name.slice(5), function (assert) {
return context[name](assert);
});
}
}
};
});
enifed('internal-test-helpers/run', ['exports', 'ember-metal'], function (exports, _emberMetal) {
'use strict';
exports.runAppend = function (view) {
(0, _emberMetal.run)(view, 'appendTo', '#qunit-fixture');
};
exports.runDestroy = function (toDestroy) {
if (toDestroy) {
(0, _emberMetal.run)(toDestroy, 'destroy');
}
};
});
enifed('internal-test-helpers/strip', ['exports'], function (exports) {
'use strict';
exports.default = function (_ref) {
for (_len = arguments.length, values = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
values[_key - 1] = arguments[_key];
}
var strings = _ref.slice(0),
_len,
values,
_key;
var str = strings.map(function (string, index) {
var interpolated = values[index];
return string + (interpolated !== undefined ? interpolated : '');
}).join('');
return str.split('\n').map(function (s) {
return s.trim();
}).join('');
};
});
enifed('internal-test-helpers/test-cases/abstract-application', ['exports', 'ember-babel', 'ember-metal', 'ember-views', 'ember-application', 'ember-routing', 'ember-template-compiler', 'internal-test-helpers/test-cases/abstract', 'internal-test-helpers/test-resolver', 'internal-test-helpers/run'], function (exports, _emberBabel, _emberMetal, _emberViews, _emberApplication, _emberRouting, _emberTemplateCompiler, _abstract, _testResolver, _run) {
'use strict';
var AbstractApplicationTestCase = function (_AbstractTestCase) {
(0, _emberBabel.inherits)(AbstractApplicationTestCase, _AbstractTestCase);
function AbstractApplicationTestCase() {
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AbstractTestCase.call(this));
_this.element = (0, _emberViews.jQuery)('#qunit-fixture')[0];
var applicationOptions = _this.applicationOptions;
_this.application = (0, _emberMetal.run)(_emberApplication.Application, 'create', applicationOptions);
_this.resolver = applicationOptions.Resolver.lastInstance;
if (_this.resolver) {
_this.resolver.add('router:main', _emberRouting.Router.extend(_this.routerOptions));
}
_this.applicationInstance = null;
return _this;
}
AbstractApplicationTestCase.prototype.teardown = function () {
(0, _run.runDestroy)(this.applicationInstance);
(0, _run.runDestroy)(this.application);
};
AbstractApplicationTestCase.prototype.visit = function (url, options) {
var _this2 = this;
var applicationInstance = this.applicationInstance;
if (applicationInstance) {
return (0, _emberMetal.run)(applicationInstance, 'visit', url, options);
} else {
return (0, _emberMetal.run)(this.application, 'visit', url, options).then(function (instance) {
_this2.applicationInstance = instance;
});
}
};
AbstractApplicationTestCase.prototype.transitionTo = function () {
return _emberMetal.run.apply(undefined, [this.appRouter, 'transitionTo'].concat(Array.prototype.slice.call(arguments)));
};
AbstractApplicationTestCase.prototype.compile = function () {
return _emberTemplateCompiler.compile.apply(undefined, arguments);
};
AbstractApplicationTestCase.prototype.add = function (specifier, factory) {
this.resolver.add(specifier, factory);
};
AbstractApplicationTestCase.prototype.addTemplate = function (templateName, templateString) {
this.resolver.add('template:' + templateName, this.compile(templateString, {
moduleName: templateName
}));
};
AbstractApplicationTestCase.prototype.addComponent = function (name, _ref) {
var _ref$ComponentClass = _ref.ComponentClass,
ComponentClass = _ref$ComponentClass === undefined ? null : _ref$ComponentClass,
_ref$template = _ref.template,
template = _ref$template === undefined ? null : _ref$template;
if (ComponentClass) {
this.resolver.add('component:' + name, ComponentClass);
}
if (typeof template === 'string') {
this.resolver.add('template:components/' + name, this.compile(template, {
moduleName: 'components/' + name
}));
}
};
(0, _emberBabel.createClass)(AbstractApplicationTestCase, [{
key: 'applicationOptions',
get: function () {
return {
rootElement: '#qunit-fixture',
autoboot: false,
Resolver: _testResolver.ModuleBasedResolver
};
}
}, {
key: 'routerOptions',
get: function () {
return {
location: 'none'
};
}
}, {
key: 'router',
get: function () {
return this.application.resolveRegistration('router:main');
}
}, {
key: 'appRouter',
get: function () {
return this.applicationInstance.lookup('router:main');
}
}]);
return AbstractApplicationTestCase;
}(_abstract.default);
exports.default = AbstractApplicationTestCase;
});
enifed('internal-test-helpers/test-cases/abstract-rendering', ['exports', 'ember-babel', 'ember-utils', 'ember-template-compiler', 'ember-views', 'ember-glimmer', 'internal-test-helpers/test-cases/abstract', 'internal-test-helpers/build-owner', 'internal-test-helpers/run'], function (exports, _emberBabel, _emberUtils, _emberTemplateCompiler, _emberViews, _emberGlimmer, _abstract, _buildOwner, _run) {
'use strict';
var TextNode = window.Text;
var AbstractRenderingTestCase = function (_AbstractTestCase) {
(0, _emberBabel.inherits)(AbstractRenderingTestCase, _AbstractTestCase);
function AbstractRenderingTestCase() {
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AbstractTestCase.call(this));
var owner = _this.owner = (0, _buildOwner.default)({
ownerOptions: _this.getOwnerOptions(),
bootOptions: _this.getBootOptions(),
resolver: _this.getResolver()
});
_this.renderer = _this.owner.lookup('renderer:-dom');
_this.element = (0, _emberViews.jQuery)('#qunit-fixture')[0];
_this.component = null;
owner.register('event_dispatcher:main', _emberViews.EventDispatcher);
owner.inject('event_dispatcher:main', '_viewRegistry', '-view-registry:main');
owner.lookup('event_dispatcher:main').setup(_this.getCustomDispatcherEvents(), _this.element);
return _this;
}
AbstractRenderingTestCase.prototype.compile = function () {
return _emberTemplateCompiler.compile.apply(undefined, arguments);
};
AbstractRenderingTestCase.prototype.getCustomDispatcherEvents = function () {
return {};
};
AbstractRenderingTestCase.prototype.getOwnerOptions = function () {};
AbstractRenderingTestCase.prototype.getBootOptions = function () {};
AbstractRenderingTestCase.prototype.getResolver = function () {};
AbstractRenderingTestCase.prototype.teardown = function () {
if (this.component) {
(0, _run.runDestroy)(this.component);
}
if (this.owner) {
(0, _run.runDestroy)(this.owner);
}
};
AbstractRenderingTestCase.prototype.render = function (templateStr) {
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var owner = this.owner;
owner.register('template:-top-level', this.compile(templateStr, {
moduleName: '-top-level'
}));
var attrs = (0, _emberUtils.assign)({}, context, {
tagName: '',
layoutName: '-top-level'
});
owner.register('component:-top-level', _emberGlimmer.Component.extend(attrs));
this.component = owner.lookup('component:-top-level');
(0, _run.runAppend)(this.component);
};
AbstractRenderingTestCase.prototype.rerender = function () {
this.component.rerender();
};
AbstractRenderingTestCase.prototype.registerHelper = function (name, funcOrClassBody) {
var type = typeof funcOrClassBody;
if (type === 'function') {
this.owner.register('helper:' + name, (0, _emberGlimmer.helper)(funcOrClassBody));
} else if (type === 'object' && type !== null) {
this.owner.register('helper:' + name, _emberGlimmer.Helper.extend(funcOrClassBody));
} else {
throw new Error('Cannot register ' + funcOrClassBody + ' as a helper');
}
};
AbstractRenderingTestCase.prototype.registerPartial = function (name, template) {
var owner = this.env.owner || this.owner,
moduleName;
if (typeof template === 'string') {
moduleName = 'template:' + name;
owner.register(moduleName, this.compile(template, { moduleName: moduleName }));
}
};
AbstractRenderingTestCase.prototype.registerComponent = function (name, _ref) {
var _ref$ComponentClass = _ref.ComponentClass,
ComponentClass = _ref$ComponentClass === undefined ? null : _ref$ComponentClass,
_ref$template = _ref.template,
template = _ref$template === undefined ? null : _ref$template;
var owner = this.owner;
if (ComponentClass) {
owner.register('component:' + name, ComponentClass);
}
if (typeof template === 'string') {
owner.register('template:components/' + name, this.compile(template, {
moduleName: 'components/' + name
}));
}
};
AbstractRenderingTestCase.prototype.registerTemplate = function (name, template) {
var owner = this.owner;
if (typeof template === 'string') {
owner.register('template:' + name, this.compile(template, {
moduleName: name
}));
} else {
throw new Error('Registered template "' + name + '" must be a string');
}
};
AbstractRenderingTestCase.prototype.registerService = function (name, klass) {
this.owner.register('service:' + name, klass);
};
AbstractRenderingTestCase.prototype.assertTextNode = function (node, text) {
if (!(node instanceof TextNode)) {
throw new Error('Expecting a text node, but got ' + node);
}
this.assert.strictEqual(node.textContent, text, 'node.textContent');
};
(0, _emberBabel.createClass)(AbstractRenderingTestCase, [{
key: 'context',
get: function () {
return this.component;
}
}]);
return AbstractRenderingTestCase;
}(_abstract.default);
exports.default = AbstractRenderingTestCase;
});
enifed('internal-test-helpers/test-cases/abstract', ['exports', 'ember-babel', 'ember-utils', 'ember-metal', 'ember-views', 'internal-test-helpers/equal-inner-html', 'internal-test-helpers/equal-tokens', 'internal-test-helpers/matchers'], function (exports, _emberBabel, _emberUtils, _emberMetal, _emberViews, _equalInnerHtml, _equalTokens, _matchers) {
'use strict';
var TextNode = window.Text;
var HTMLElement = window.HTMLElement;
var Comment = window.Comment;
function isMarker(node) {
if (node instanceof Comment && node.textContent === '') {
return true;
}
if (node instanceof TextNode && node.textContent === '') {
return true;
}
return false;
}
var AbstractTestCase = function () {
function AbstractTestCase() {
this.element = null;
this.snapshot = null;
this.assert = QUnit.config.current.assert;
}
AbstractTestCase.prototype.teardown = function () {};
AbstractTestCase.prototype.runTask = function (callback) {
(0, _emberMetal.run)(callback);
};
AbstractTestCase.prototype.runTaskNext = function (callback) {
_emberMetal.run.next(callback);
};
AbstractTestCase.prototype.nthChild = function (n) {
var i = 0;
var node = this.element.firstChild;
while (node) {
if (!isMarker(node)) {
i++;
}
if (i > n) {
break;
} else {
node = node.nextSibling;
}
}
return node;
};
AbstractTestCase.prototype.$ = function (sel) {
return sel ? (0, _emberViews.jQuery)(sel, this.element) : (0, _emberViews.jQuery)(this.element);
};
AbstractTestCase.prototype.textValue = function () {
return this.$().text();
};
AbstractTestCase.prototype.takeSnapshot = function () {
var snapshot = this.snapshot = [];
var node = this.element.firstChild;
while (node) {
if (!isMarker(node)) {
snapshot.push(node);
}
node = node.nextSibling;
}
return snapshot;
};
AbstractTestCase.prototype.assertText = function (text) {
this.assert.strictEqual(this.textValue(), text, '#qunit-fixture content should be: `' + text + '`');
};
AbstractTestCase.prototype.assertInnerHTML = function (html) {
(0, _equalInnerHtml.default)(this.element, html);
};
AbstractTestCase.prototype.assertHTML = function (html) {
(0, _equalTokens.default)(this.element, html, '#qunit-fixture content should be: `' + html + '`');
};
AbstractTestCase.prototype.assertElement = function (node, _ref) {
var _ref$ElementType = _ref.ElementType,
ElementType = _ref$ElementType === undefined ? HTMLElement : _ref$ElementType,
tagName = _ref.tagName,
_ref$attrs = _ref.attrs,
attrs = _ref$attrs === undefined ? null : _ref$attrs,
_ref$content = _ref.content,
content = _ref$content === undefined ? null : _ref$content;
if (!(node instanceof ElementType)) {
throw new Error('Expecting a ' + ElementType.name + ', but got ' + node);
}
(0, _matchers.equalsElement)(node, tagName, attrs, content);
};
AbstractTestCase.prototype.assertComponentElement = function (node, _ref2) {
var _ref2$ElementType = _ref2.ElementType,
ElementType = _ref2$ElementType === undefined ? HTMLElement : _ref2$ElementType,
_ref2$tagName = _ref2.tagName,
tagName = _ref2$tagName === undefined ? 'div' : _ref2$tagName,
_ref2$attrs = _ref2.attrs,
attrs = _ref2$attrs === undefined ? null : _ref2$attrs,
_ref2$content = _ref2.content,
content = _ref2$content === undefined ? null : _ref2$content;
attrs = (0, _emberUtils.assign)({}, { id: (0, _matchers.regex)(/^ember\d*$/), class: (0, _matchers.classes)('ember-view') }, attrs || {});
this.assertElement(node, { ElementType: ElementType, tagName: tagName, attrs: attrs, content: content });
};
AbstractTestCase.prototype.assertSameNode = function (actual, expected) {
this.assert.strictEqual(actual, expected, 'DOM node stability');
};
AbstractTestCase.prototype.assertInvariants = function (oldSnapshot, newSnapshot) {
var i;
oldSnapshot = oldSnapshot || this.snapshot;
newSnapshot = newSnapshot || this.takeSnapshot();
this.assert.strictEqual(newSnapshot.length, oldSnapshot.length, 'Same number of nodes');
for (i = 0; i < oldSnapshot.length; i++) {
this.assertSameNode(newSnapshot[i], oldSnapshot[i]);
}
};
AbstractTestCase.prototype.assertPartialInvariants = function (start, end) {
this.assertInvariants(this.snapshot, this.takeSnapshot().slice(start, end));
};
AbstractTestCase.prototype.assertStableRerender = function () {
var _this = this;
this.takeSnapshot();
this.runTask(function () {
return _this.rerender();
});
this.assertInvariants();
};
(0, _emberBabel.createClass)(AbstractTestCase, [{
key: 'firstChild',
get: function () {
return this.nthChild(0);
}
}, {
key: 'nodesCount',
get: function () {
var count = 0;
var node = this.element.firstChild;
while (node) {
if (!isMarker(node)) {
count++;
}
node = node.nextSibling;
}
return count;
}
}]);
return AbstractTestCase;
}();
exports.default = AbstractTestCase;
});
enifed('internal-test-helpers/test-cases/application', ['exports', 'ember-babel', 'internal-test-helpers/test-cases/abstract-application'], function (exports, _emberBabel, _abstractApplication) {
'use strict';
var ApplicationTestCase = function (_AbstractApplicationT) {
(0, _emberBabel.inherits)(ApplicationTestCase, _AbstractApplicationT);
function ApplicationTestCase() {
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractApplicationT.apply(this, arguments));
}
return ApplicationTestCase;
}(_abstractApplication.default);
exports.default = ApplicationTestCase;
});
enifed('internal-test-helpers/test-cases/autoboot-application', ['exports', 'ember-babel', 'internal-test-helpers/test-cases/abstract', 'internal-test-helpers/test-resolver', 'ember-application', 'ember-utils', 'internal-test-helpers/run'], function (exports, _emberBabel, _abstract, _testResolver, _emberApplication, _emberUtils, _run) {
'use strict';
var AutobootApplicationTestCase = function (_AbstractTestCase) {
(0, _emberBabel.inherits)(AutobootApplicationTestCase, _AbstractTestCase);
function AutobootApplicationTestCase() {
return (0, _emberBabel.possibleConstructorReturn)(this, _AbstractTestCase.apply(this, arguments));
}
AutobootApplicationTestCase.prototype.teardown = function () {
(0, _run.runDestroy)(this.application);
_AbstractTestCase.prototype.teardown.call(this);
};
AutobootApplicationTestCase.prototype.createApplication = function (options) {
var MyApplication = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _emberApplication.Application;
var myOptions = (0, _emberUtils.assign)({
rootElement: '#qunit-fixture',
Resolver: _testResolver.default
}, options);
var application = this.application = MyApplication.create(myOptions);
this.resolver = myOptions.Resolver.lastInstance;
return application;
};
AutobootApplicationTestCase.prototype.add = function (specifier, factory) {
this.resolver.add(specifier, factory);
};
AutobootApplicationTestCase.prototype.addTemplate = function (templateName, templateString) {
this.resolver.addTemplate(templateName, templateString);
};
return AutobootApplicationTestCase;
}(_abstract.default);
exports.default = AutobootApplicationTestCase;
});
enifed('internal-test-helpers/test-cases/query-param', ['exports', 'ember-babel', 'ember-runtime', 'ember-routing', 'ember-metal', 'internal-test-helpers/test-cases/application'], function (exports, _emberBabel, _emberRuntime, _emberRouting, _emberMetal, _application) {
'use strict';
var QueryParamTestCase = function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(QueryParamTestCase, _ApplicationTestCase);
function QueryParamTestCase() {
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this));
var testCase = _this;
testCase.expectedPushURL = null;
testCase.expectedReplaceURL = null;
_this.add('location:test', _emberRouting.NoneLocation.extend({
setURL: function (path) {
if (testCase.expectedReplaceURL) {
testCase.assert.ok(false, 'pushState occurred but a replaceState was expected');
}
if (testCase.expectedPushURL) {
testCase.assert.equal(path, testCase.expectedPushURL, 'an expected pushState occurred');
testCase.expectedPushURL = null;
}
this.set('path', path);
},
replaceURL: function (path) {
if (testCase.expectedPushURL) {
testCase.assert.ok(false, 'replaceState occurred but a pushState was expected');
}
if (testCase.expectedReplaceURL) {
testCase.assert.equal(path, testCase.expectedReplaceURL, 'an expected replaceState occurred');
testCase.expectedReplaceURL = null;
}
this.set('path', path);
}
}));
return _this;
}
QueryParamTestCase.prototype.visitAndAssert = function (path) {
var _this2 = this;
return this.visit.apply(this, arguments).then(function () {
_this2.assertCurrentPath(path);
});
};
QueryParamTestCase.prototype.getController = function (name) {
return this.applicationInstance.lookup('controller:' + name);
};
QueryParamTestCase.prototype.getRoute = function (name) {
return this.applicationInstance.lookup('route:' + name);
};
QueryParamTestCase.prototype.setAndFlush = function (obj, prop, value) {
return (0, _emberMetal.run)(obj, 'set', prop, value);
};
QueryParamTestCase.prototype.assertCurrentPath = function (path) {
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'current path equals \'' + path + '\'';
this.assert.equal(this.appRouter.get('location.path'), path, message);
};
QueryParamTestCase.prototype.setSingleQPController = function (routeName) {
var param = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'foo';
var _Controller$extend;
var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'bar';
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
this.add('controller:' + routeName, _emberRuntime.Controller.extend((_Controller$extend = {
queryParams: [param]
}, _Controller$extend[param] = defaultValue, _Controller$extend), options));
};
QueryParamTestCase.prototype.setMappedQPController = function (routeName) {
var prop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'page';
var urlKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'parentPage';
var _queryParams, _Controller$extend2;
var defaultValue = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
this.add('controller:' + routeName, _emberRuntime.Controller.extend((_Controller$extend2 = {
queryParams: (_queryParams = {}, _queryParams[prop] = urlKey, _queryParams)
}, _Controller$extend2[prop] = defaultValue, _Controller$extend2), options));
};
(0, _emberBabel.createClass)(QueryParamTestCase, [{
key: 'routerOptions',
get: function () {
return {
location: 'test'
};
}
}]);
return QueryParamTestCase;
}(_application.default);
exports.default = QueryParamTestCase;
});
enifed('internal-test-helpers/test-cases/rendering', ['exports', 'ember-babel', 'ember-views', 'internal-test-helpers/test-cases/abstract-rendering'], function (exports, _emberBabel, _emberViews, _abstractRendering) {
'use strict';
var RenderingTestCase = function (_AbstractRenderingTes) {
(0, _emberBabel.inherits)(RenderingTestCase, _AbstractRenderingTes);
function RenderingTestCase() {
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _AbstractRenderingTes.call(this));
var owner = _this.owner;
_this.env = owner.lookup('service:-glimmer-environment');
owner.register('component-lookup:main', _emberViews.ComponentLookup);
owner.registerOptionsForType('helper', { instantiate: false });
owner.registerOptionsForType('component', { singleton: false });
return _this;
}
return RenderingTestCase;
}(_abstractRendering.default);
exports.default = RenderingTestCase;
});
enifed('internal-test-helpers/test-cases/router', ['exports', 'ember-babel', 'internal-test-helpers/test-cases/application'], function (exports, _emberBabel, _application) {
'use strict';
var RouterTestCase = function (_ApplicationTestCase) {
(0, _emberBabel.inherits)(RouterTestCase, _ApplicationTestCase);
function RouterTestCase() {
var _this = (0, _emberBabel.possibleConstructorReturn)(this, _ApplicationTestCase.call(this));
_this.router.map(function () {
this.route('parent', { path: '/' }, function () {
this.route('child');
this.route('sister');
this.route('brother');
});
this.route('dynamic', { path: '/dynamic/:dynamic_id' });
});
return _this;
}
(0, _emberBabel.createClass)(RouterTestCase, [{
key: 'routerService',
get: function () {
return this.applicationInstance.lookup('service:router');
}
}]);
return RouterTestCase;
}(_application.default);
exports.default = RouterTestCase;
});
enifed('internal-test-helpers/test-groups', ['exports', 'ember-environment', 'ember-metal'], function (exports, _emberEnvironment, _emberMetal) {
'use strict';
exports.testBoth =
// used by unit tests to test both accessor mode and non-accessor mode
function (testname, callback) {
function emberget(x, y) {
return (0, _emberMetal.get)(x, y);
}
function emberset(x, y, z) {
return (0, _emberMetal.set)(x, y, z);
}
function aget(x, y) {
return x[y];
}
function aset(x, y, z) {
return x[y] = z;
}
QUnit.test(testname + ' using getFromEmberMetal()/Ember.set()', function () {
callback(emberget, emberset);
});
QUnit.test(testname + ' using accessors', function () {
if (_emberEnvironment.ENV.USES_ACCESSORS) {
callback(aget, aset);
} else {
ok('SKIPPING ACCESSORS');
}
});
};
exports.testWithDefault = function (testname, callback) {
function emberget(x, y) {
return (0, _emberMetal.get)(x, y);
}
function embergetwithdefault(x, y, z) {
return (0, _emberMetal.getWithDefault)(x, y, z);
}
function getwithdefault(x, y, z) {
return x.getWithDefault(y, z);
}
function emberset(x, y, z) {
return (0, _emberMetal.set)(x, y, z);
}
function aget(x, y) {
return x[y];
}
function aset(x, y, z) {
return x[y] = z;
}
QUnit.test(testname + ' using obj.get()', function () {
callback(emberget, emberset);
});
QUnit.test(testname + ' using obj.getWithDefault()', function () {
callback(getwithdefault, emberset);
});
QUnit.test(testname + ' using getFromEmberMetal()', function () {
callback(emberget, emberset);
});
QUnit.test(testname + ' using Ember.getWithDefault()', function () {
callback(embergetwithdefault, emberset);
});
QUnit.test(testname + ' using accessors', function () {
if (_emberEnvironment.ENV.USES_ACCESSORS) {
callback(aget, aset);
} else {
ok('SKIPPING ACCESSORS');
}
});
};
});
enifed('internal-test-helpers/test-resolver', ['exports', 'ember-babel', 'ember-template-compiler'], function (exports, _emberBabel, _emberTemplateCompiler) {
'use strict';
exports.ModuleBasedResolver = undefined;
var Resolver = function () {
function Resolver() {
this._registered = {};
this.constructor.lastInstance = this;
}
Resolver.prototype.resolve = function (specifier) {
return this._registered[specifier];
};
Resolver.prototype.add = function (specifier, factory) {
if (specifier.indexOf(':') === -1) {
throw new Error('Specifiers added to the resolver must be in the format of type:name');
}
return this._registered[specifier] = factory;
};
Resolver.prototype.addTemplate = function (templateName, template) {
var templateType = typeof template;
if (templateType !== 'string') {
throw new Error('You called addTemplate for "' + templateName + '" with a template argument of type of \'' + templateType + '\'. addTemplate expects an argument of an uncompiled template as a string.');
}
return this._registered['template:' + templateName] = (0, _emberTemplateCompiler.compile)(template, {
moduleName: templateName
});
};
Resolver.create = function () {
return new this();
};
return Resolver;
}();
exports.default = Resolver;
var ModuleBasedResolver = function (_Resolver) {
(0, _emberBabel.inherits)(ModuleBasedResolver, _Resolver);
function ModuleBasedResolver() {
return (0, _emberBabel.possibleConstructorReturn)(this, _Resolver.apply(this, arguments));
}
(0, _emberBabel.createClass)(ModuleBasedResolver, [{
key: 'moduleBasedResolver',
get: function () {
return true;
}
}]);
return ModuleBasedResolver;
}(Resolver);
exports.ModuleBasedResolver = ModuleBasedResolver;
});
enifed('internal-test-helpers/tests/index-test', [], function () {
'use strict';
QUnit.module('internal-test-helpers');
QUnit.test('module present', function (assert) {
assert.ok(true, 'each package needs at least one test to be able to run through `npm test`');
});
});
enifed('node-module', ['exports'], function(_exports) {
var IS_NODE = typeof module === 'object' && typeof module.require === 'function';
if (IS_NODE) {
_exports.require = module.require;
_exports.module = module;
_exports.IS_NODE = IS_NODE
} else {
_exports.require = null;
_exports.module = null;
_exports.IS_NODE = IS_NODE
}
});
enifed("simple-html-tokenizer", ["exports"], function (exports) {
"use strict";
var namedCharRefs = {
Aacute: "Á", aacute: "á", Abreve: "Ă", abreve: "ă", ac: "∾", acd: "∿", acE: "∾̳", Acirc: "Â", acirc: "â", acute: "´", Acy: "А", acy: "а", AElig: "Æ", aelig: "æ", af: "\u2061", Afr: "𝔄", afr: "𝔞", Agrave: "À", agrave: "à", alefsym: "ℵ", aleph: "ℵ", Alpha: "Α", alpha: "α", Amacr: "Ā", amacr: "ā", amalg: "⨿", AMP: "&", amp: "&", And: "⩓", and: "∧", andand: "⩕", andd: "⩜", andslope: "⩘", andv: "⩚", ang: "∠", ange: "⦤", angle: "∠", angmsd: "∡", angmsdaa: "⦨", angmsdab: "⦩", angmsdac: "⦪", angmsdad: "⦫", angmsdae: "⦬", angmsdaf: "⦭", angmsdag: "⦮", angmsdah: "⦯", angrt: "∟", angrtvb: "⊾", angrtvbd: "⦝", angsph: "∢", angst: "Å", angzarr: "⍼", Aogon: "Ą", aogon: "ą", Aopf: "𝔸", aopf: "𝕒", ap: "≈", apacir: "⩯", apE: "⩰", ape: "≊", apid: "≋", apos: "'", ApplyFunction: "\u2061", approx: "≈", approxeq: "≊", Aring: "Å", aring: "å", Ascr: "𝒜", ascr: "𝒶", Assign: "≔", ast: "*", asymp: "≈", asympeq: "≍", Atilde: "Ã", atilde: "ã", Auml: "Ä", auml: "ä", awconint: "∳", awint: "⨑", backcong: "≌", backepsilon: "϶", backprime: "‵", backsim: "∽", backsimeq: "⋍", Backslash: "∖", Barv: "⫧", barvee: "⊽", Barwed: "⌆", barwed: "⌅", barwedge: "⌅", bbrk: "⎵", bbrktbrk: "⎶", bcong: "≌", Bcy: "Б", bcy: "б", bdquo: "„", becaus: "∵", Because: "∵", because: "∵", bemptyv: "⦰", bepsi: "϶", bernou: "ℬ", Bernoullis: "ℬ", Beta: "Β", beta: "β", beth: "ℶ", between: "≬", Bfr: "𝔅", bfr: "𝔟", bigcap: "⋂", bigcirc: "◯", bigcup: "⋃", bigodot: "⨀", bigoplus: "⨁", bigotimes: "⨂", bigsqcup: "⨆", bigstar: "★", bigtriangledown: "▽", bigtriangleup: "△", biguplus: "⨄", bigvee: "⋁", bigwedge: "⋀", bkarow: "⤍", blacklozenge: "⧫", blacksquare: "▪", blacktriangle: "▴", blacktriangledown: "▾", blacktriangleleft: "◂", blacktriangleright: "▸", blank: "␣", blk12: "▒", blk14: "░", blk34: "▓", block: "█", bne: "=⃥", bnequiv: "≡⃥", bNot: "⫭", bnot: "⌐", Bopf: "𝔹", bopf: "𝕓", bot: "⊥", bottom: "⊥", bowtie: "⋈", boxbox: "⧉", boxDL: "╗", boxDl: "╖", boxdL: "╕", boxdl: "┐", boxDR: "╔", boxDr: "╓", boxdR: "╒", boxdr: "┌", boxH: "═", boxh: "─", boxHD: "╦", boxHd: "╤", boxhD: "╥", boxhd: "┬", boxHU: "╩", boxHu: "╧", boxhU: "╨", boxhu: "┴", boxminus: "⊟", boxplus: "⊞", boxtimes: "⊠", boxUL: "╝", boxUl: "╜", boxuL: "╛", boxul: "┘", boxUR: "╚", boxUr: "╙", boxuR: "╘", boxur: "└", boxV: "║", boxv: "│", boxVH: "╬", boxVh: "╫", boxvH: "╪", boxvh: "┼", boxVL: "╣", boxVl: "╢", boxvL: "╡", boxvl: "┤", boxVR: "╠", boxVr: "╟", boxvR: "╞", boxvr: "├", bprime: "‵", Breve: "˘", breve: "˘", brvbar: "¦", Bscr: "ℬ", bscr: "𝒷", bsemi: "⁏", bsim: "∽", bsime: "⋍", bsol: "\\", bsolb: "⧅", bsolhsub: "⟈", bull: "•", bullet: "•", bump: "≎", bumpE: "⪮", bumpe: "≏", Bumpeq: "≎", bumpeq: "≏", Cacute: "Ć", cacute: "ć", Cap: "⋒", cap: "∩", capand: "⩄", capbrcup: "⩉", capcap: "⩋", capcup: "⩇", capdot: "⩀", CapitalDifferentialD: "ⅅ", caps: "∩︀", caret: "⁁", caron: "ˇ", Cayleys: "ℭ", ccaps: "⩍", Ccaron: "Č", ccaron: "č", Ccedil: "Ç", ccedil: "ç", Ccirc: "Ĉ", ccirc: "ĉ", Cconint: "∰", ccups: "⩌", ccupssm: "⩐", Cdot: "Ċ", cdot: "ċ", cedil: "¸", Cedilla: "¸", cemptyv: "⦲", cent: "¢", CenterDot: "·", centerdot: "·", Cfr: "ℭ", cfr: "𝔠", CHcy: "Ч", chcy: "ч", check: "✓", checkmark: "✓", Chi: "Χ", chi: "χ", cir: "○", circ: "ˆ", circeq: "≗", circlearrowleft: "↺", circlearrowright: "↻", circledast: "⊛", circledcirc: "⊚", circleddash: "⊝", CircleDot: "⊙", circledR: "®", circledS: "Ⓢ", CircleMinus: "⊖", CirclePlus: "⊕", CircleTimes: "⊗", cirE: "⧃", cire: "≗", cirfnint: "⨐", cirmid: "⫯", cirscir: "⧂", ClockwiseContourIntegral: "∲", CloseCurlyDoubleQuote: "”", CloseCurlyQuote: "’", clubs: "♣", clubsuit: "♣", Colon: "∷", colon: ":", Colone: "⩴", colone: "≔", coloneq: "≔", comma: ",", commat: "@", comp: "∁", compfn: "∘", complement: "∁", complexes: "ℂ", cong: "≅", congdot: "⩭", Congruent: "≡", Conint: "∯", conint: "∮", ContourIntegral: "∮", Copf: "ℂ", copf: "𝕔", coprod: "∐", Coproduct: "∐", COPY: "©", copy: "©", copysr: "℗", CounterClockwiseContourIntegral: "∳", crarr: "↵", Cross: "⨯", cross: "✗", Cscr: "𝒞", cscr: "𝒸", csub: "⫏", csube: "⫑", csup: "⫐", csupe: "⫒", ctdot: "⋯", cudarrl: "⤸", cudarrr: "⤵", cuepr: "⋞", cuesc: "⋟", cularr: "↶", cularrp: "⤽", Cup: "⋓", cup: "∪", cupbrcap: "⩈", CupCap: "≍", cupcap: "⩆", cupcup: "⩊", cupdot: "⊍", cupor: "⩅", cups: "∪︀", curarr: "↷", curarrm: "⤼", curlyeqprec: "⋞", curlyeqsucc: "⋟", curlyvee: "⋎", curlywedge: "⋏", curren: "¤", curvearrowleft: "↶", curvearrowright: "↷", cuvee: "⋎", cuwed: "⋏", cwconint: "∲", cwint: "∱", cylcty: "⌭", Dagger: "‡", dagger: "†", daleth: "ℸ", Darr: "↡", dArr: "⇓", darr: "↓", dash: "‐", Dashv: "⫤", dashv: "⊣", dbkarow: "⤏", dblac: "˝", Dcaron: "Ď", dcaron: "ď", Dcy: "Д", dcy: "д", DD: "ⅅ", dd: "ⅆ", ddagger: "‡", ddarr: "⇊", DDotrahd: "⤑", ddotseq: "⩷", deg: "°", Del: "∇", Delta: "Δ", delta: "δ", demptyv: "⦱", dfisht: "⥿", Dfr: "𝔇", dfr: "𝔡", dHar: "⥥", dharl: "⇃", dharr: "⇂", DiacriticalAcute: "´", DiacriticalDot: "˙", DiacriticalDoubleAcute: "˝", DiacriticalGrave: "`", DiacriticalTilde: "˜", diam: "⋄", Diamond: "⋄", diamond: "⋄", diamondsuit: "♦", diams: "♦", die: "¨", DifferentialD: "ⅆ", digamma: "ϝ", disin: "⋲", div: "÷", divide: "÷", divideontimes: "⋇", divonx: "⋇", DJcy: "Ђ", djcy: "ђ", dlcorn: "⌞", dlcrop: "⌍", dollar: "$", Dopf: "𝔻", dopf: "𝕕", Dot: "¨", dot: "˙", DotDot: "⃜", doteq: "≐", doteqdot: "≑", DotEqual: "≐", dotminus: "∸", dotplus: "∔", dotsquare: "⊡", doublebarwedge: "⌆", DoubleContourIntegral: "∯", DoubleDot: "¨", DoubleDownArrow: "⇓", DoubleLeftArrow: "⇐", DoubleLeftRightArrow: "⇔", DoubleLeftTee: "⫤", DoubleLongLeftArrow: "⟸", DoubleLongLeftRightArrow: "⟺", DoubleLongRightArrow: "⟹", DoubleRightArrow: "⇒", DoubleRightTee: "⊨", DoubleUpArrow: "⇑", DoubleUpDownArrow: "⇕", DoubleVerticalBar: "∥", DownArrow: "↓", Downarrow: "⇓", downarrow: "↓", DownArrowBar: "⤓", DownArrowUpArrow: "⇵", DownBreve: "̑", downdownarrows: "⇊", downharpoonleft: "⇃", downharpoonright: "⇂", DownLeftRightVector: "⥐", DownLeftTeeVector: "⥞", DownLeftVector: "↽", DownLeftVectorBar: "⥖", DownRightTeeVector: "⥟", DownRightVector: "⇁", DownRightVectorBar: "⥗", DownTee: "⊤", DownTeeArrow: "↧", drbkarow: "⤐", drcorn: "⌟", drcrop: "⌌", Dscr: "𝒟", dscr: "𝒹", DScy: "Ѕ", dscy: "ѕ", dsol: "⧶", Dstrok: "Đ", dstrok: "đ", dtdot: "⋱", dtri: "▿", dtrif: "▾", duarr: "⇵", duhar: "⥯", dwangle: "⦦", DZcy: "Џ", dzcy: "џ", dzigrarr: "⟿", Eacute: "É", eacute: "é", easter: "⩮", Ecaron: "Ě", ecaron: "ě", ecir: "≖", Ecirc: "Ê", ecirc: "ê", ecolon: "≕", Ecy: "Э", ecy: "э", eDDot: "⩷", Edot: "Ė", eDot: "≑", edot: "ė", ee: "ⅇ", efDot: "≒", Efr: "𝔈", efr: "𝔢", eg: "⪚", Egrave: "È", egrave: "è", egs: "⪖", egsdot: "⪘", el: "⪙", Element: "∈", elinters: "⏧", ell: "ℓ", els: "⪕", elsdot: "⪗", Emacr: "Ē", emacr: "ē", empty: "∅", emptyset: "∅", EmptySmallSquare: "◻", emptyv: "∅", EmptyVerySmallSquare: "▫", emsp: " ", emsp13: " ", emsp14: " ", ENG: "Ŋ", eng: "ŋ", ensp: " ", Eogon: "Ę", eogon: "ę", Eopf: "𝔼", eopf: "𝕖", epar: "⋕", eparsl: "⧣", eplus: "⩱", epsi: "ε", Epsilon: "Ε", epsilon: "ε", epsiv: "ϵ", eqcirc: "≖", eqcolon: "≕", eqsim: "≂", eqslantgtr: "⪖", eqslantless: "⪕", Equal: "⩵", equals: "=", EqualTilde: "≂", equest: "≟", Equilibrium: "⇌", equiv: "≡", equivDD: "⩸", eqvparsl: "⧥", erarr: "⥱", erDot: "≓", Escr: "ℰ", escr: "ℯ", esdot: "≐", Esim: "⩳", esim: "≂", Eta: "Η", eta: "η", ETH: "Ð", eth: "ð", Euml: "Ë", euml: "ë", euro: "€", excl: "!", exist: "∃", Exists: "∃", expectation: "ℰ", ExponentialE: "ⅇ", exponentiale: "ⅇ", fallingdotseq: "≒", Fcy: "Ф", fcy: "ф", female: "♀", ffilig: "ffi", fflig: "ff", ffllig: "ffl", Ffr: "𝔉", ffr: "𝔣", filig: "fi", FilledSmallSquare: "◼", FilledVerySmallSquare: "▪", fjlig: "fj", flat: "♭", fllig: "fl", fltns: "▱", fnof: "ƒ", Fopf: "𝔽", fopf: "𝕗", ForAll: "∀", forall: "∀", fork: "⋔", forkv: "⫙", Fouriertrf: "ℱ", fpartint: "⨍", frac12: "½", frac13: "⅓", frac14: "¼", frac15: "⅕", frac16: "⅙", frac18: "⅛", frac23: "⅔", frac25: "⅖", frac34: "¾", frac35: "⅗", frac38: "⅜", frac45: "⅘", frac56: "⅚", frac58: "⅝", frac78: "⅞", frasl: "⁄", frown: "⌢", Fscr: "ℱ", fscr: "𝒻", gacute: "ǵ", Gamma: "Γ", gamma: "γ", Gammad: "Ϝ", gammad: "ϝ", gap: "⪆", Gbreve: "Ğ", gbreve: "ğ", Gcedil: "Ģ", Gcirc: "Ĝ", gcirc: "ĝ", Gcy: "Г", gcy: "г", Gdot: "Ġ", gdot: "ġ", gE: "≧", ge: "≥", gEl: "⪌", gel: "⋛", geq: "≥", geqq: "≧", geqslant: "⩾", ges: "⩾", gescc: "⪩", gesdot: "⪀", gesdoto: "⪂", gesdotol: "⪄", gesl: "⋛︀", gesles: "⪔", Gfr: "𝔊", gfr: "𝔤", Gg: "⋙", gg: "≫", ggg: "⋙", gimel: "ℷ", GJcy: "Ѓ", gjcy: "ѓ", gl: "≷", gla: "⪥", glE: "⪒", glj: "⪤", gnap: "⪊", gnapprox: "⪊", gnE: "≩", gne: "⪈", gneq: "⪈", gneqq: "≩", gnsim: "⋧", Gopf: "𝔾", gopf: "𝕘", grave: "`", GreaterEqual: "≥", GreaterEqualLess: "⋛", GreaterFullEqual: "≧", GreaterGreater: "⪢", GreaterLess: "≷", GreaterSlantEqual: "⩾", GreaterTilde: "≳", Gscr: "𝒢", gscr: "ℊ", gsim: "≳", gsime: "⪎", gsiml: "⪐", GT: ">", Gt: "≫", gt: ">", gtcc: "⪧", gtcir: "⩺", gtdot: "⋗", gtlPar: "⦕", gtquest: "⩼", gtrapprox: "⪆", gtrarr: "⥸", gtrdot: "⋗", gtreqless: "⋛", gtreqqless: "⪌", gtrless: "≷", gtrsim: "≳", gvertneqq: "≩︀", gvnE: "≩︀", Hacek: "ˇ", hairsp: " ", half: "½", hamilt: "ℋ", HARDcy: "Ъ", hardcy: "ъ", hArr: "⇔", harr: "↔", harrcir: "⥈", harrw: "↭", Hat: "^", hbar: "ℏ", Hcirc: "Ĥ", hcirc: "ĥ", hearts: "♥", heartsuit: "♥", hellip: "…", hercon: "⊹", Hfr: "ℌ", hfr: "𝔥", HilbertSpace: "ℋ", hksearow: "⤥", hkswarow: "⤦", hoarr: "⇿", homtht: "∻", hookleftarrow: "↩", hookrightarrow: "↪", Hopf: "ℍ", hopf: "𝕙", horbar: "―", HorizontalLine: "─", Hscr: "ℋ", hscr: "𝒽", hslash: "ℏ", Hstrok: "Ħ", hstrok: "ħ", HumpDownHump: "≎", HumpEqual: "≏", hybull: "⁃", hyphen: "‐", Iacute: "Í", iacute: "í", ic: "\u2063", Icirc: "Î", icirc: "î", Icy: "И", icy: "и", Idot: "İ", IEcy: "Е", iecy: "е", iexcl: "¡", iff: "⇔", Ifr: "ℑ", ifr: "𝔦", Igrave: "Ì", igrave: "ì", ii: "ⅈ", iiiint: "⨌", iiint: "∭", iinfin: "⧜", iiota: "℩", IJlig: "IJ", ijlig: "ij", Im: "ℑ", Imacr: "Ī", imacr: "ī", image: "ℑ", ImaginaryI: "ⅈ", imagline: "ℐ", imagpart: "ℑ", imath: "ı", imof: "⊷", imped: "Ƶ", Implies: "⇒", in: "∈", incare: "℅", infin: "∞", infintie: "⧝", inodot: "ı", Int: "∬", int: "∫", intcal: "⊺", integers: "ℤ", Integral: "∫", intercal: "⊺", Intersection: "⋂", intlarhk: "⨗", intprod: "⨼", InvisibleComma: "\u2063", InvisibleTimes: "\u2062", IOcy: "Ё", iocy: "ё", Iogon: "Į", iogon: "į", Iopf: "𝕀", iopf: "𝕚", Iota: "Ι", iota: "ι", iprod: "⨼", iquest: "¿", Iscr: "ℐ", iscr: "𝒾", isin: "∈", isindot: "⋵", isinE: "⋹", isins: "⋴", isinsv: "⋳", isinv: "∈", it: "\u2062", Itilde: "Ĩ", itilde: "ĩ", Iukcy: "І", iukcy: "і", Iuml: "Ï", iuml: "ï", Jcirc: "Ĵ", jcirc: "ĵ", Jcy: "Й", jcy: "й", Jfr: "𝔍", jfr: "𝔧", jmath: "ȷ", Jopf: "𝕁", jopf: "𝕛", Jscr: "𝒥", jscr: "𝒿", Jsercy: "Ј", jsercy: "ј", Jukcy: "Є", jukcy: "є", Kappa: "Κ", kappa: "κ", kappav: "ϰ", Kcedil: "Ķ", kcedil: "ķ", Kcy: "К", kcy: "к", Kfr: "𝔎", kfr: "𝔨", kgreen: "ĸ", KHcy: "Х", khcy: "х", KJcy: "Ќ", kjcy: "ќ", Kopf: "𝕂", kopf: "𝕜", Kscr: "𝒦", kscr: "𝓀", lAarr: "⇚", Lacute: "Ĺ", lacute: "ĺ", laemptyv: "⦴", lagran: "ℒ", Lambda: "Λ", lambda: "λ", Lang: "⟪", lang: "⟨", langd: "⦑", langle: "⟨", lap: "⪅", Laplacetrf: "ℒ", laquo: "«", Larr: "↞", lArr: "⇐", larr: "←", larrb: "⇤", larrbfs: "⤟", larrfs: "⤝", larrhk: "↩", larrlp: "↫", larrpl: "⤹", larrsim: "⥳", larrtl: "↢", lat: "⪫", lAtail: "⤛", latail: "⤙", late: "⪭", lates: "⪭︀", lBarr: "⤎", lbarr: "⤌", lbbrk: "❲", lbrace: "{", lbrack: "[", lbrke: "⦋", lbrksld: "⦏", lbrkslu: "⦍", Lcaron: "Ľ", lcaron: "ľ", Lcedil: "Ļ", lcedil: "ļ", lceil: "⌈", lcub: "{", Lcy: "Л", lcy: "л", ldca: "⤶", ldquo: "“", ldquor: "„", ldrdhar: "⥧", ldrushar: "⥋", ldsh: "↲", lE: "≦", le: "≤", LeftAngleBracket: "⟨", LeftArrow: "←", Leftarrow: "⇐", leftarrow: "←", LeftArrowBar: "⇤", LeftArrowRightArrow: "⇆", leftarrowtail: "↢", LeftCeiling: "⌈", LeftDoubleBracket: "⟦", LeftDownTeeVector: "⥡", LeftDownVector: "⇃", LeftDownVectorBar: "⥙", LeftFloor: "⌊", leftharpoondown: "↽", leftharpoonup: "↼", leftleftarrows: "⇇", LeftRightArrow: "↔", Leftrightarrow: "⇔", leftrightarrow: "↔", leftrightarrows: "⇆", leftrightharpoons: "⇋", leftrightsquigarrow: "↭", LeftRightVector: "⥎", LeftTee: "⊣", LeftTeeArrow: "↤", LeftTeeVector: "⥚", leftthreetimes: "⋋", LeftTriangle: "⊲", LeftTriangleBar: "⧏", LeftTriangleEqual: "⊴", LeftUpDownVector: "⥑", LeftUpTeeVector: "⥠", LeftUpVector: "↿", LeftUpVectorBar: "⥘", LeftVector: "↼", LeftVectorBar: "⥒", lEg: "⪋", leg: "⋚", leq: "≤", leqq: "≦", leqslant: "⩽", les: "⩽", lescc: "⪨", lesdot: "⩿", lesdoto: "⪁", lesdotor: "⪃", lesg: "⋚︀", lesges: "⪓", lessapprox: "⪅", lessdot: "⋖", lesseqgtr: "⋚", lesseqqgtr: "⪋", LessEqualGreater: "⋚", LessFullEqual: "≦", LessGreater: "≶", lessgtr: "≶", LessLess: "⪡", lesssim: "≲", LessSlantEqual: "⩽", LessTilde: "≲", lfisht: "⥼", lfloor: "⌊", Lfr: "𝔏", lfr: "𝔩", lg: "≶", lgE: "⪑", lHar: "⥢", lhard: "↽", lharu: "↼", lharul: "⥪", lhblk: "▄", LJcy: "Љ", ljcy: "љ", Ll: "⋘", ll: "≪", llarr: "⇇", llcorner: "⌞", Lleftarrow: "⇚", llhard: "⥫", lltri: "◺", Lmidot: "Ŀ", lmidot: "ŀ", lmoust: "⎰", lmoustache: "⎰", lnap: "⪉", lnapprox: "⪉", lnE: "≨", lne: "⪇", lneq: "⪇", lneqq: "≨", lnsim: "⋦", loang: "⟬", loarr: "⇽", lobrk: "⟦", LongLeftArrow: "⟵", Longleftarrow: "⟸", longleftarrow: "⟵", LongLeftRightArrow: "⟷", Longleftrightarrow: "⟺", longleftrightarrow: "⟷", longmapsto: "⟼", LongRightArrow: "⟶", Longrightarrow: "⟹", longrightarrow: "⟶", looparrowleft: "↫", looparrowright: "↬", lopar: "⦅", Lopf: "𝕃", lopf: "𝕝", loplus: "⨭", lotimes: "⨴", lowast: "∗", lowbar: "_", LowerLeftArrow: "↙", LowerRightArrow: "↘", loz: "◊", lozenge: "◊", lozf: "⧫", lpar: "(", lparlt: "⦓", lrarr: "⇆", lrcorner: "⌟", lrhar: "⇋", lrhard: "⥭", lrm: "\u200e", lrtri: "⊿", lsaquo: "‹", Lscr: "ℒ", lscr: "𝓁", Lsh: "↰", lsh: "↰", lsim: "≲", lsime: "⪍", lsimg: "⪏", lsqb: "[", lsquo: "‘", lsquor: "‚", Lstrok: "Ł", lstrok: "ł", LT: "<", Lt: "≪", lt: "<", ltcc: "⪦", ltcir: "⩹", ltdot: "⋖", lthree: "⋋", ltimes: "⋉", ltlarr: "⥶", ltquest: "⩻", ltri: "◃", ltrie: "⊴", ltrif: "◂", ltrPar: "⦖", lurdshar: "⥊", luruhar: "⥦", lvertneqq: "≨︀", lvnE: "≨︀", macr: "¯", male: "♂", malt: "✠", maltese: "✠", Map: "⤅", map: "↦", mapsto: "↦", mapstodown: "↧", mapstoleft: "↤", mapstoup: "↥", marker: "▮", mcomma: "⨩", Mcy: "М", mcy: "м", mdash: "—", mDDot: "∺", measuredangle: "∡", MediumSpace: " ", Mellintrf: "ℳ", Mfr: "𝔐", mfr: "𝔪", mho: "℧", micro: "µ", mid: "∣", midast: "*", midcir: "⫰", middot: "·", minus: "−", minusb: "⊟", minusd: "∸", minusdu: "⨪", MinusPlus: "∓", mlcp: "⫛", mldr: "…", mnplus: "∓", models: "⊧", Mopf: "𝕄", mopf: "𝕞", mp: "∓", Mscr: "ℳ", mscr: "𝓂", mstpos: "∾", Mu: "Μ", mu: "μ", multimap: "⊸", mumap: "⊸", nabla: "∇", Nacute: "Ń", nacute: "ń", nang: "∠⃒", nap: "≉", napE: "⩰̸", napid: "≋̸", napos: "ʼn", napprox: "≉", natur: "♮", natural: "♮", naturals: "ℕ", nbsp: " ", nbump: "≎̸", nbumpe: "≏̸", ncap: "⩃", Ncaron: "Ň", ncaron: "ň", Ncedil: "Ņ", ncedil: "ņ", ncong: "≇", ncongdot: "⩭̸", ncup: "⩂", Ncy: "Н", ncy: "н", ndash: "–", ne: "≠", nearhk: "⤤", neArr: "⇗", nearr: "↗", nearrow: "↗", nedot: "≐̸", NegativeMediumSpace: "", NegativeThickSpace: "", NegativeThinSpace: "", NegativeVeryThinSpace: "", nequiv: "≢", nesear: "⤨", nesim: "≂̸", NestedGreaterGreater: "≫", NestedLessLess: "≪", NewLine: "\u000a", nexist: "∄", nexists: "∄", Nfr: "𝔑", nfr: "𝔫", ngE: "≧̸", nge: "≱", ngeq: "≱", ngeqq: "≧̸", ngeqslant: "⩾̸", nges: "⩾̸", nGg: "⋙̸", ngsim: "≵", nGt: "≫⃒", ngt: "≯", ngtr: "≯", nGtv: "≫̸", nhArr: "⇎", nharr: "↮", nhpar: "⫲", ni: "∋", nis: "⋼", nisd: "⋺", niv: "∋", NJcy: "Њ", njcy: "њ", nlArr: "⇍", nlarr: "↚", nldr: "‥", nlE: "≦̸", nle: "≰", nLeftarrow: "⇍", nleftarrow: "↚", nLeftrightarrow: "⇎", nleftrightarrow: "↮", nleq: "≰", nleqq: "≦̸", nleqslant: "⩽̸", nles: "⩽̸", nless: "≮", nLl: "⋘̸", nlsim: "≴", nLt: "≪⃒", nlt: "≮", nltri: "⋪", nltrie: "⋬", nLtv: "≪̸", nmid: "∤", NoBreak: "\u2060", NonBreakingSpace: " ", Nopf: "ℕ", nopf: "𝕟", Not: "⫬", not: "¬", NotCongruent: "≢", NotCupCap: "≭", NotDoubleVerticalBar: "∦", NotElement: "∉", NotEqual: "≠", NotEqualTilde: "≂̸", NotExists: "∄", NotGreater: "≯", NotGreaterEqual: "≱", NotGreaterFullEqual: "≧̸", NotGreaterGreater: "≫̸", NotGreaterLess: "≹", NotGreaterSlantEqual: "⩾̸", NotGreaterTilde: "≵", NotHumpDownHump: "≎̸", NotHumpEqual: "≏̸", notin: "∉", notindot: "⋵̸", notinE: "⋹̸", notinva: "∉", notinvb: "⋷", notinvc: "⋶", NotLeftTriangle: "⋪", NotLeftTriangleBar: "⧏̸", NotLeftTriangleEqual: "⋬", NotLess: "≮", NotLessEqual: "≰", NotLessGreater: "≸", NotLessLess: "≪̸", NotLessSlantEqual: "⩽̸", NotLessTilde: "≴", NotNestedGreaterGreater: "⪢̸", NotNestedLessLess: "⪡̸", notni: "∌", notniva: "∌", notnivb: "⋾", notnivc: "⋽", NotPrecedes: "⊀", NotPrecedesEqual: "⪯̸", NotPrecedesSlantEqual: "⋠", NotReverseElement: "∌", NotRightTriangle: "⋫", NotRightTriangleBar: "⧐̸", NotRightTriangleEqual: "⋭", NotSquareSubset: "⊏̸", NotSquareSubsetEqual: "⋢", NotSquareSuperset: "⊐̸", NotSquareSupersetEqual: "⋣", NotSubset: "⊂⃒", NotSubsetEqual: "⊈", NotSucceeds: "⊁", NotSucceedsEqual: "⪰̸", NotSucceedsSlantEqual: "⋡", NotSucceedsTilde: "≿̸", NotSuperset: "⊃⃒", NotSupersetEqual: "⊉", NotTilde: "≁", NotTildeEqual: "≄", NotTildeFullEqual: "≇", NotTildeTilde: "≉", NotVerticalBar: "∤", npar: "∦", nparallel: "∦", nparsl: "⫽⃥", npart: "∂̸", npolint: "⨔", npr: "⊀", nprcue: "⋠", npre: "⪯̸", nprec: "⊀", npreceq: "⪯̸", nrArr: "⇏", nrarr: "↛", nrarrc: "⤳̸", nrarrw: "↝̸", nRightarrow: "⇏", nrightarrow: "↛", nrtri: "⋫", nrtrie: "⋭", nsc: "⊁", nsccue: "⋡", nsce: "⪰̸", Nscr: "𝒩", nscr: "𝓃", nshortmid: "∤", nshortparallel: "∦", nsim: "≁", nsime: "≄", nsimeq: "≄", nsmid: "∤", nspar: "∦", nsqsube: "⋢", nsqsupe: "⋣", nsub: "⊄", nsubE: "⫅̸", nsube: "⊈", nsubset: "⊂⃒", nsubseteq: "⊈", nsubseteqq: "⫅̸", nsucc: "⊁", nsucceq: "⪰̸", nsup: "⊅", nsupE: "⫆̸", nsupe: "⊉", nsupset: "⊃⃒", nsupseteq: "⊉", nsupseteqq: "⫆̸", ntgl: "≹", Ntilde: "Ñ", ntilde: "ñ", ntlg: "≸", ntriangleleft: "⋪", ntrianglelefteq: "⋬", ntriangleright: "⋫", ntrianglerighteq: "⋭", Nu: "Ν", nu: "ν", num: "#", numero: "№", numsp: " ", nvap: "≍⃒", nVDash: "⊯", nVdash: "⊮", nvDash: "⊭", nvdash: "⊬", nvge: "≥⃒", nvgt: ">⃒", nvHarr: "⤄", nvinfin: "⧞", nvlArr: "⤂", nvle: "≤⃒", nvlt: "<⃒", nvltrie: "⊴⃒", nvrArr: "⤃", nvrtrie: "⊵⃒", nvsim: "∼⃒", nwarhk: "⤣", nwArr: "⇖", nwarr: "↖", nwarrow: "↖", nwnear: "⤧", Oacute: "Ó", oacute: "ó", oast: "⊛", ocir: "⊚", Ocirc: "Ô", ocirc: "ô", Ocy: "О", ocy: "о", odash: "⊝", Odblac: "Ő", odblac: "ő", odiv: "⨸", odot: "⊙", odsold: "⦼", OElig: "Œ", oelig: "œ", ofcir: "⦿", Ofr: "𝔒", ofr: "𝔬", ogon: "˛", Ograve: "Ò", ograve: "ò", ogt: "⧁", ohbar: "⦵", ohm: "Ω", oint: "∮", olarr: "↺", olcir: "⦾", olcross: "⦻", oline: "‾", olt: "⧀", Omacr: "Ō", omacr: "ō", Omega: "Ω", omega: "ω", Omicron: "Ο", omicron: "ο", omid: "⦶", ominus: "⊖", Oopf: "𝕆", oopf: "𝕠", opar: "⦷", OpenCurlyDoubleQuote: "“", OpenCurlyQuote: "‘", operp: "⦹", oplus: "⊕", Or: "⩔", or: "∨", orarr: "↻", ord: "⩝", order: "ℴ", orderof: "ℴ", ordf: "ª", ordm: "º", origof: "⊶", oror: "⩖", orslope: "⩗", orv: "⩛", oS: "Ⓢ", Oscr: "𝒪", oscr: "ℴ", Oslash: "Ø", oslash: "ø", osol: "⊘", Otilde: "Õ", otilde: "õ", Otimes: "⨷", otimes: "⊗", otimesas: "⨶", Ouml: "Ö", ouml: "ö", ovbar: "⌽", OverBar: "‾", OverBrace: "⏞", OverBracket: "⎴", OverParenthesis: "⏜", par: "∥", para: "¶", parallel: "∥", parsim: "⫳", parsl: "⫽", part: "∂", PartialD: "∂", Pcy: "П", pcy: "п", percnt: "%", period: ".", permil: "‰", perp: "⊥", pertenk: "‱", Pfr: "𝔓", pfr: "𝔭", Phi: "Φ", phi: "φ", phiv: "ϕ", phmmat: "ℳ", phone: "☎", Pi: "Π", pi: "π", pitchfork: "⋔", piv: "ϖ", planck: "ℏ", planckh: "ℎ", plankv: "ℏ", plus: "+", plusacir: "⨣", plusb: "⊞", pluscir: "⨢", plusdo: "∔", plusdu: "⨥", pluse: "⩲", PlusMinus: "±", plusmn: "±", plussim: "⨦", plustwo: "⨧", pm: "±", Poincareplane: "ℌ", pointint: "⨕", Popf: "ℙ", popf: "𝕡", pound: "£", Pr: "⪻", pr: "≺", prap: "⪷", prcue: "≼", prE: "⪳", pre: "⪯", prec: "≺", precapprox: "⪷", preccurlyeq: "≼", Precedes: "≺", PrecedesEqual: "⪯", PrecedesSlantEqual: "≼", PrecedesTilde: "≾", preceq: "⪯", precnapprox: "⪹", precneqq: "⪵", precnsim: "⋨", precsim: "≾", Prime: "″", prime: "′", primes: "ℙ", prnap: "⪹", prnE: "⪵", prnsim: "⋨", prod: "∏", Product: "∏", profalar: "⌮", profline: "⌒", profsurf: "⌓", prop: "∝", Proportion: "∷", Proportional: "∝", propto: "∝", prsim: "≾", prurel: "⊰", Pscr: "𝒫", pscr: "𝓅", Psi: "Ψ", psi: "ψ", puncsp: " ", Qfr: "𝔔", qfr: "𝔮", qint: "⨌", Qopf: "ℚ", qopf: "𝕢", qprime: "⁗", Qscr: "𝒬", qscr: "𝓆", quaternions: "ℍ", quatint: "⨖", quest: "?", questeq: "≟", QUOT: "\"", quot: "\"", rAarr: "⇛", race: "∽̱", Racute: "Ŕ", racute: "ŕ", radic: "√", raemptyv: "⦳", Rang: "⟫", rang: "⟩", rangd: "⦒", range: "⦥", rangle: "⟩", raquo: "»", Rarr: "↠", rArr: "⇒", rarr: "→", rarrap: "⥵", rarrb: "⇥", rarrbfs: "⤠", rarrc: "⤳", rarrfs: "⤞", rarrhk: "↪", rarrlp: "↬", rarrpl: "⥅", rarrsim: "⥴", Rarrtl: "⤖", rarrtl: "↣", rarrw: "↝", rAtail: "⤜", ratail: "⤚", ratio: "∶", rationals: "ℚ", RBarr: "⤐", rBarr: "⤏", rbarr: "⤍", rbbrk: "❳", rbrace: "}", rbrack: "]", rbrke: "⦌", rbrksld: "⦎", rbrkslu: "⦐", Rcaron: "Ř", rcaron: "ř", Rcedil: "Ŗ", rcedil: "ŗ", rceil: "⌉", rcub: "}", Rcy: "Р", rcy: "р", rdca: "⤷", rdldhar: "⥩", rdquo: "”", rdquor: "”", rdsh: "↳", Re: "ℜ", real: "ℜ", realine: "ℛ", realpart: "ℜ", reals: "ℝ", rect: "▭", REG: "®", reg: "®", ReverseElement: "∋", ReverseEquilibrium: "⇋", ReverseUpEquilibrium: "⥯", rfisht: "⥽", rfloor: "⌋", Rfr: "ℜ", rfr: "𝔯", rHar: "⥤", rhard: "⇁", rharu: "⇀", rharul: "⥬", Rho: "Ρ", rho: "ρ", rhov: "ϱ", RightAngleBracket: "⟩", RightArrow: "→", Rightarrow: "⇒", rightarrow: "→", RightArrowBar: "⇥", RightArrowLeftArrow: "⇄", rightarrowtail: "↣", RightCeiling: "⌉", RightDoubleBracket: "⟧", RightDownTeeVector: "⥝", RightDownVector: "⇂", RightDownVectorBar: "⥕", RightFloor: "⌋", rightharpoondown: "⇁", rightharpoonup: "⇀", rightleftarrows: "⇄", rightleftharpoons: "⇌", rightrightarrows: "⇉", rightsquigarrow: "↝", RightTee: "⊢", RightTeeArrow: "↦", RightTeeVector: "⥛", rightthreetimes: "⋌", RightTriangle: "⊳", RightTriangleBar: "⧐", RightTriangleEqual: "⊵", RightUpDownVector: "⥏", RightUpTeeVector: "⥜", RightUpVector: "↾", RightUpVectorBar: "⥔", RightVector: "⇀", RightVectorBar: "⥓", ring: "˚", risingdotseq: "≓", rlarr: "⇄", rlhar: "⇌", rlm: "\u200f", rmoust: "⎱", rmoustache: "⎱", rnmid: "⫮", roang: "⟭", roarr: "⇾", robrk: "⟧", ropar: "⦆", Ropf: "ℝ", ropf: "𝕣", roplus: "⨮", rotimes: "⨵", RoundImplies: "⥰", rpar: ")", rpargt: "⦔", rppolint: "⨒", rrarr: "⇉", Rrightarrow: "⇛", rsaquo: "›", Rscr: "ℛ", rscr: "𝓇", Rsh: "↱", rsh: "↱", rsqb: "]", rsquo: "’", rsquor: "’", rthree: "⋌", rtimes: "⋊", rtri: "▹", rtrie: "⊵", rtrif: "▸", rtriltri: "⧎", RuleDelayed: "⧴", ruluhar: "⥨", rx: "℞", Sacute: "Ś", sacute: "ś", sbquo: "‚", Sc: "⪼", sc: "≻", scap: "⪸", Scaron: "Š", scaron: "š", sccue: "≽", scE: "⪴", sce: "⪰", Scedil: "Ş", scedil: "ş", Scirc: "Ŝ", scirc: "ŝ", scnap: "⪺", scnE: "⪶", scnsim: "⋩", scpolint: "⨓", scsim: "≿", Scy: "С", scy: "с", sdot: "⋅", sdotb: "⊡", sdote: "⩦", searhk: "⤥", seArr: "⇘", searr: "↘", searrow: "↘", sect: "§", semi: ";", seswar: "⤩", setminus: "∖", setmn: "∖", sext: "✶", Sfr: "𝔖", sfr: "𝔰", sfrown: "⌢", sharp: "♯", SHCHcy: "Щ", shchcy: "щ", SHcy: "Ш", shcy: "ш", ShortDownArrow: "↓", ShortLeftArrow: "←", shortmid: "∣", shortparallel: "∥", ShortRightArrow: "→", ShortUpArrow: "↑", shy: "\u00ad", Sigma: "Σ", sigma: "σ", sigmaf: "ς", sigmav: "ς", sim: "∼", simdot: "⩪", sime: "≃", simeq: "≃", simg: "⪞", simgE: "⪠", siml: "⪝", simlE: "⪟", simne: "≆", simplus: "⨤", simrarr: "⥲", slarr: "←", SmallCircle: "∘", smallsetminus: "∖", smashp: "⨳", smeparsl: "⧤", smid: "∣", smile: "⌣", smt: "⪪", smte: "⪬", smtes: "⪬︀", SOFTcy: "Ь", softcy: "ь", sol: "/", solb: "⧄", solbar: "⌿", Sopf: "𝕊", sopf: "𝕤", spades: "♠", spadesuit: "♠", spar: "∥", sqcap: "⊓", sqcaps: "⊓︀", sqcup: "⊔", sqcups: "⊔︀", Sqrt: "√", sqsub: "⊏", sqsube: "⊑", sqsubset: "⊏", sqsubseteq: "⊑", sqsup: "⊐", sqsupe: "⊒", sqsupset: "⊐", sqsupseteq: "⊒", squ: "□", Square: "□", square: "□", SquareIntersection: "⊓", SquareSubset: "⊏", SquareSubsetEqual: "⊑", SquareSuperset: "⊐", SquareSupersetEqual: "⊒", SquareUnion: "⊔", squarf: "▪", squf: "▪", srarr: "→", Sscr: "𝒮", sscr: "𝓈", ssetmn: "∖", ssmile: "⌣", sstarf: "⋆", Star: "⋆", star: "☆", starf: "★", straightepsilon: "ϵ", straightphi: "ϕ", strns: "¯", Sub: "⋐", sub: "⊂", subdot: "⪽", subE: "⫅", sube: "⊆", subedot: "⫃", submult: "⫁", subnE: "⫋", subne: "⊊", subplus: "⪿", subrarr: "⥹", Subset: "⋐", subset: "⊂", subseteq: "⊆", subseteqq: "⫅", SubsetEqual: "⊆", subsetneq: "⊊", subsetneqq: "⫋", subsim: "⫇", subsub: "⫕", subsup: "⫓", succ: "≻", succapprox: "⪸", succcurlyeq: "≽", Succeeds: "≻", SucceedsEqual: "⪰", SucceedsSlantEqual: "≽", SucceedsTilde: "≿", succeq: "⪰", succnapprox: "⪺", succneqq: "⪶", succnsim: "⋩", succsim: "≿", SuchThat: "∋", Sum: "∑", sum: "∑", sung: "♪", Sup: "⋑", sup: "⊃", sup1: "¹", sup2: "²", sup3: "³", supdot: "⪾", supdsub: "⫘", supE: "⫆", supe: "⊇", supedot: "⫄", Superset: "⊃", SupersetEqual: "⊇", suphsol: "⟉", suphsub: "⫗", suplarr: "⥻", supmult: "⫂", supnE: "⫌", supne: "⊋", supplus: "⫀", Supset: "⋑", supset: "⊃", supseteq: "⊇", supseteqq: "⫆", supsetneq: "⊋", supsetneqq: "⫌", supsim: "⫈", supsub: "⫔", supsup: "⫖", swarhk: "⤦", swArr: "⇙", swarr: "↙", swarrow: "↙", swnwar: "⤪", szlig: "ß", Tab: "\u0009", target: "⌖", Tau: "Τ", tau: "τ", tbrk: "⎴", Tcaron: "Ť", tcaron: "ť", Tcedil: "Ţ", tcedil: "ţ", Tcy: "Т", tcy: "т", tdot: "⃛", telrec: "⌕", Tfr: "𝔗", tfr: "𝔱", there4: "∴", Therefore: "∴", therefore: "∴", Theta: "Θ", theta: "θ", thetasym: "ϑ", thetav: "ϑ", thickapprox: "≈", thicksim: "∼", ThickSpace: " ", thinsp: " ", ThinSpace: " ", thkap: "≈", thksim: "∼", THORN: "Þ", thorn: "þ", Tilde: "∼", tilde: "˜", TildeEqual: "≃", TildeFullEqual: "≅", TildeTilde: "≈", times: "×", timesb: "⊠", timesbar: "⨱", timesd: "⨰", tint: "∭", toea: "⤨", top: "⊤", topbot: "⌶", topcir: "⫱", Topf: "𝕋", topf: "𝕥", topfork: "⫚", tosa: "⤩", tprime: "‴", TRADE: "™", trade: "™", triangle: "▵", triangledown: "▿", triangleleft: "◃", trianglelefteq: "⊴", triangleq: "≜", triangleright: "▹", trianglerighteq: "⊵", tridot: "◬", trie: "≜", triminus: "⨺", TripleDot: "⃛", triplus: "⨹", trisb: "⧍", tritime: "⨻", trpezium: "⏢", Tscr: "𝒯", tscr: "𝓉", TScy: "Ц", tscy: "ц", TSHcy: "Ћ", tshcy: "ћ", Tstrok: "Ŧ", tstrok: "ŧ", twixt: "≬", twoheadleftarrow: "↞", twoheadrightarrow: "↠", Uacute: "Ú", uacute: "ú", Uarr: "↟", uArr: "⇑", uarr: "↑", Uarrocir: "⥉", Ubrcy: "Ў", ubrcy: "ў", Ubreve: "Ŭ", ubreve: "ŭ", Ucirc: "Û", ucirc: "û", Ucy: "У", ucy: "у", udarr: "⇅", Udblac: "Ű", udblac: "ű", udhar: "⥮", ufisht: "⥾", Ufr: "𝔘", ufr: "𝔲", Ugrave: "Ù", ugrave: "ù", uHar: "⥣", uharl: "↿", uharr: "↾", uhblk: "▀", ulcorn: "⌜", ulcorner: "⌜", ulcrop: "⌏", ultri: "◸", Umacr: "Ū", umacr: "ū", uml: "¨", UnderBar: "_", UnderBrace: "⏟", UnderBracket: "⎵", UnderParenthesis: "⏝", Union: "⋃", UnionPlus: "⊎", Uogon: "Ų", uogon: "ų", Uopf: "𝕌", uopf: "𝕦", UpArrow: "↑", Uparrow: "⇑", uparrow: "↑", UpArrowBar: "⤒", UpArrowDownArrow: "⇅", UpDownArrow: "↕", Updownarrow: "⇕", updownarrow: "↕", UpEquilibrium: "⥮", upharpoonleft: "↿", upharpoonright: "↾", uplus: "⊎", UpperLeftArrow: "↖", UpperRightArrow: "↗", Upsi: "ϒ", upsi: "υ", upsih: "ϒ", Upsilon: "Υ", upsilon: "υ", UpTee: "⊥", UpTeeArrow: "↥", upuparrows: "⇈", urcorn: "⌝", urcorner: "⌝", urcrop: "⌎", Uring: "Ů", uring: "ů", urtri: "◹", Uscr: "𝒰", uscr: "𝓊", utdot: "⋰", Utilde: "Ũ", utilde: "ũ", utri: "▵", utrif: "▴", uuarr: "⇈", Uuml: "Ü", uuml: "ü", uwangle: "⦧", vangrt: "⦜", varepsilon: "ϵ", varkappa: "ϰ", varnothing: "∅", varphi: "ϕ", varpi: "ϖ", varpropto: "∝", vArr: "⇕", varr: "↕", varrho: "ϱ", varsigma: "ς", varsubsetneq: "⊊︀", varsubsetneqq: "⫋︀", varsupsetneq: "⊋︀", varsupsetneqq: "⫌︀", vartheta: "ϑ", vartriangleleft: "⊲", vartriangleright: "⊳", Vbar: "⫫", vBar: "⫨", vBarv: "⫩", Vcy: "В", vcy: "в", VDash: "⊫", Vdash: "⊩", vDash: "⊨", vdash: "⊢", Vdashl: "⫦", Vee: "⋁", vee: "∨", veebar: "⊻", veeeq: "≚", vellip: "⋮", Verbar: "‖", verbar: "|", Vert: "‖", vert: "|", VerticalBar: "∣", VerticalLine: "|", VerticalSeparator: "❘", VerticalTilde: "≀", VeryThinSpace: " ", Vfr: "𝔙", vfr: "𝔳", vltri: "⊲", vnsub: "⊂⃒", vnsup: "⊃⃒", Vopf: "𝕍", vopf: "𝕧", vprop: "∝", vrtri: "⊳", Vscr: "𝒱", vscr: "𝓋", vsubnE: "⫋︀", vsubne: "⊊︀", vsupnE: "⫌︀", vsupne: "⊋︀", Vvdash: "⊪", vzigzag: "⦚", Wcirc: "Ŵ", wcirc: "ŵ", wedbar: "⩟", Wedge: "⋀", wedge: "∧", wedgeq: "≙", weierp: "℘", Wfr: "𝔚", wfr: "𝔴", Wopf: "𝕎", wopf: "𝕨", wp: "℘", wr: "≀", wreath: "≀", Wscr: "𝒲", wscr: "𝓌", xcap: "⋂", xcirc: "◯", xcup: "⋃", xdtri: "▽", Xfr: "𝔛", xfr: "𝔵", xhArr: "⟺", xharr: "⟷", Xi: "Ξ", xi: "ξ", xlArr: "⟸", xlarr: "⟵", xmap: "⟼", xnis: "⋻", xodot: "⨀", Xopf: "𝕏", xopf: "𝕩", xoplus: "⨁", xotime: "⨂", xrArr: "⟹", xrarr: "⟶", Xscr: "𝒳", xscr: "𝓍", xsqcup: "⨆", xuplus: "⨄", xutri: "△", xvee: "⋁", xwedge: "⋀", Yacute: "Ý", yacute: "ý", YAcy: "Я", yacy: "я", Ycirc: "Ŷ", ycirc: "ŷ", Ycy: "Ы", ycy: "ы", yen: "¥", Yfr: "𝔜", yfr: "𝔶", YIcy: "Ї", yicy: "ї", Yopf: "𝕐", yopf: "𝕪", Yscr: "𝒴", yscr: "𝓎", YUcy: "Ю", yucy: "ю", Yuml: "Ÿ", yuml: "ÿ", Zacute: "Ź", zacute: "ź", Zcaron: "Ž", zcaron: "ž", Zcy: "З", zcy: "з", Zdot: "Ż", zdot: "ż", zeetrf: "ℨ", ZeroWidthSpace: "", Zeta: "Ζ", zeta: "ζ", Zfr: "ℨ", zfr: "𝔷", ZHcy: "Ж", zhcy: "ж", zigrarr: "⇝", Zopf: "ℤ", zopf: "𝕫", Zscr: "𝒵", zscr: "𝓏", zwj: "\u200d", zwnj: "\u200c"
};
var HEXCHARCODE = /^#[xX]([A-Fa-f0-9]+)$/;
var CHARCODE = /^#([0-9]+)$/;
var NAMED = /^([A-Za-z0-9]+)$/;
var EntityParser = function () {
function EntityParser(named) {
this.named = named;
}
EntityParser.prototype.parse = function (entity) {
if (!entity) {
return;
}
var matches = entity.match(HEXCHARCODE);
if (matches) {
return String.fromCharCode(parseInt(matches[1], 16));
}
matches = entity.match(CHARCODE);
if (matches) {
return String.fromCharCode(parseInt(matches[1], 10));
}
matches = entity.match(NAMED);
if (matches) {
return this.named[matches[1]];
}
};
return EntityParser;
}();
var WSP = /[\t\n\f ]/;
var ALPHA = /[A-Za-z]/;
var CRLF = /\r\n?/g;
function isSpace(char) {
return WSP.test(char);
}
function isAlpha(char) {
return ALPHA.test(char);
}
function preprocessInput(input) {
return input.replace(CRLF, "\n");
}
var EventedTokenizer = function () {
function EventedTokenizer(delegate, entityParser) {
this.delegate = delegate;
this.entityParser = entityParser;
this.state = null;
this.input = null;
this.index = -1;
this.tagLine = -1;
this.tagColumn = -1;
this.line = -1;
this.column = -1;
this.states = {
beforeData: function () {
var char = this.peek();
if (char === "<") {
this.state = 'tagOpen';
this.markTagStart();
this.consume();
} else {
this.state = 'data';
this.delegate.beginData();
}
},
data: function () {
var char = this.peek();
if (char === "<") {
this.delegate.finishData();
this.state = 'tagOpen';
this.markTagStart();
this.consume();
} else if (char === "&") {
this.consume();
this.delegate.appendToData(this.consumeCharRef() || "&");
} else {
this.consume();
this.delegate.appendToData(char);
}
},
tagOpen: function () {
var char = this.consume();
if (char === "!") {
this.state = 'markupDeclaration';
} else if (char === "/") {
this.state = 'endTagOpen';
} else if (isAlpha(char)) {
this.state = 'tagName';
this.delegate.beginStartTag();
this.delegate.appendToTagName(char.toLowerCase());
}
},
markupDeclaration: function () {
var char = this.consume();
if (char === "-" && this.input.charAt(this.index) === "-") {
this.consume();
this.state = 'commentStart';
this.delegate.beginComment();
}
},
commentStart: function () {
var char = this.consume();
if (char === "-") {
this.state = 'commentStartDash';
} else if (char === ">") {
this.delegate.finishComment();
this.state = 'beforeData';
} else {
this.delegate.appendToCommentData(char);
this.state = 'comment';
}
},
commentStartDash: function () {
var char = this.consume();
if (char === "-") {
this.state = 'commentEnd';
} else if (char === ">") {
this.delegate.finishComment();
this.state = 'beforeData';
} else {
this.delegate.appendToCommentData("-");
this.state = 'comment';
}
},
comment: function () {
var char = this.consume();
if (char === "-") {
this.state = 'commentEndDash';
} else {
this.delegate.appendToCommentData(char);
}
},
commentEndDash: function () {
var char = this.consume();
if (char === "-") {
this.state = 'commentEnd';
} else {
this.delegate.appendToCommentData("-" + char);
this.state = 'comment';
}
},
commentEnd: function () {
var char = this.consume();
if (char === ">") {
this.delegate.finishComment();
this.state = 'beforeData';
} else {
this.delegate.appendToCommentData("--" + char);
this.state = 'comment';
}
},
tagName: function () {
var char = this.consume();
if (isSpace(char)) {
this.state = 'beforeAttributeName';
} else if (char === "/") {
this.state = 'selfClosingStartTag';
} else if (char === ">") {
this.delegate.finishTag();
this.state = 'beforeData';
} else {
this.delegate.appendToTagName(char);
}
},
beforeAttributeName: function () {
var char = this.peek();
if (isSpace(char)) {
this.consume();
return;
} else if (char === "/") {
this.state = 'selfClosingStartTag';
this.consume();
} else if (char === ">") {
this.consume();
this.delegate.finishTag();
this.state = 'beforeData';
} else if (char === '=') {
this.delegate.reportSyntaxError("attribute name cannot start with equals sign");
this.state = 'attributeName';
this.delegate.beginAttribute();
this.consume();
this.delegate.appendToAttributeName(char);
} else {
this.state = 'attributeName';
this.delegate.beginAttribute();
}
},
attributeName: function () {
var char = this.peek();
if (isSpace(char)) {
this.state = 'afterAttributeName';
this.consume();
} else if (char === "/") {
this.delegate.beginAttributeValue(false);
this.delegate.finishAttributeValue();
this.consume();
this.state = 'selfClosingStartTag';
} else if (char === "=") {
this.state = 'beforeAttributeValue';
this.consume();
} else if (char === ">") {
this.delegate.beginAttributeValue(false);
this.delegate.finishAttributeValue();
this.consume();
this.delegate.finishTag();
this.state = 'beforeData';
} else if (char === '"' || char === "'" || char === '<') {
this.delegate.reportSyntaxError(char + " is not a valid character within attribute names");
this.consume();
this.delegate.appendToAttributeName(char);
} else {
this.consume();
this.delegate.appendToAttributeName(char);
}
},
afterAttributeName: function () {
var char = this.peek();
if (isSpace(char)) {
this.consume();
return;
} else if (char === "/") {
this.delegate.beginAttributeValue(false);
this.delegate.finishAttributeValue();
this.consume();
this.state = 'selfClosingStartTag';
} else if (char === "=") {
this.consume();
this.state = 'beforeAttributeValue';
} else if (char === ">") {
this.delegate.beginAttributeValue(false);
this.delegate.finishAttributeValue();
this.consume();
this.delegate.finishTag();
this.state = 'beforeData';
} else {
this.delegate.beginAttributeValue(false);
this.delegate.finishAttributeValue();
this.consume();
this.state = 'attributeName';
this.delegate.beginAttribute();
this.delegate.appendToAttributeName(char);
}
},
beforeAttributeValue: function () {
var char = this.peek();
if (isSpace(char)) {
this.consume();
} else if (char === '"') {
this.state = 'attributeValueDoubleQuoted';
this.delegate.beginAttributeValue(true);
this.consume();
} else if (char === "'") {
this.state = 'attributeValueSingleQuoted';
this.delegate.beginAttributeValue(true);
this.consume();
} else if (char === ">") {
this.delegate.beginAttributeValue(false);
this.delegate.finishAttributeValue();
this.consume();
this.delegate.finishTag();
this.state = 'beforeData';
} else {
this.state = 'attributeValueUnquoted';
this.delegate.beginAttributeValue(false);
this.consume();
this.delegate.appendToAttributeValue(char);
}
},
attributeValueDoubleQuoted: function () {
var char = this.consume();
if (char === '"') {
this.delegate.finishAttributeValue();
this.state = 'afterAttributeValueQuoted';
} else if (char === "&") {
this.delegate.appendToAttributeValue(this.consumeCharRef('"') || "&");
} else {
this.delegate.appendToAttributeValue(char);
}
},
attributeValueSingleQuoted: function () {
var char = this.consume();
if (char === "'") {
this.delegate.finishAttributeValue();
this.state = 'afterAttributeValueQuoted';
} else if (char === "&") {
this.delegate.appendToAttributeValue(this.consumeCharRef("'") || "&");
} else {
this.delegate.appendToAttributeValue(char);
}
},
attributeValueUnquoted: function () {
var char = this.peek();
if (isSpace(char)) {
this.delegate.finishAttributeValue();
this.consume();
this.state = 'beforeAttributeName';
} else if (char === "&") {
this.consume();
this.delegate.appendToAttributeValue(this.consumeCharRef(">") || "&");
} else if (char === ">") {
this.delegate.finishAttributeValue();
this.consume();
this.delegate.finishTag();
this.state = 'beforeData';
} else {
this.consume();
this.delegate.appendToAttributeValue(char);
}
},
afterAttributeValueQuoted: function () {
var char = this.peek();
if (isSpace(char)) {
this.consume();
this.state = 'beforeAttributeName';
} else if (char === "/") {
this.consume();
this.state = 'selfClosingStartTag';
} else if (char === ">") {
this.consume();
this.delegate.finishTag();
this.state = 'beforeData';
} else {
this.state = 'beforeAttributeName';
}
},
selfClosingStartTag: function () {
var char = this.peek();
if (char === ">") {
this.consume();
this.delegate.markTagAsSelfClosing();
this.delegate.finishTag();
this.state = 'beforeData';
} else {
this.state = 'beforeAttributeName';
}
},
endTagOpen: function () {
var char = this.consume();
if (isAlpha(char)) {
this.state = 'tagName';
this.delegate.beginEndTag();
this.delegate.appendToTagName(char.toLowerCase());
}
}
};
this.reset();
}
EventedTokenizer.prototype.reset = function () {
this.state = 'beforeData';
this.input = '';
this.index = 0;
this.line = 1;
this.column = 0;
this.tagLine = -1;
this.tagColumn = -1;
this.delegate.reset();
};
EventedTokenizer.prototype.tokenize = function (input) {
this.reset();
this.tokenizePart(input);
this.tokenizeEOF();
};
EventedTokenizer.prototype.tokenizePart = function (input) {
this.input += preprocessInput(input);
while (this.index < this.input.length) {
this.states[this.state].call(this);
}
};
EventedTokenizer.prototype.tokenizeEOF = function () {
this.flushData();
};
EventedTokenizer.prototype.flushData = function () {
if (this.state === 'data') {
this.delegate.finishData();
this.state = 'beforeData';
}
};
EventedTokenizer.prototype.peek = function () {
return this.input.charAt(this.index);
};
EventedTokenizer.prototype.consume = function () {
var char = this.peek();
this.index++;
if (char === "\n") {
this.line++;
this.column = 0;
} else {
this.column++;
}
return char;
};
EventedTokenizer.prototype.consumeCharRef = function () {
var endIndex = this.input.indexOf(';', this.index);
if (endIndex === -1) {
return;
}
var entity = this.input.slice(this.index, endIndex);
var chars = this.entityParser.parse(entity);
if (chars) {
var count = entity.length;
// consume the entity chars
while (count) {
this.consume();
count--;
}
// consume the `;`
this.consume();
return chars;
}
};
EventedTokenizer.prototype.markTagStart = function () {
// these properties to be removed in next major bump
this.tagLine = this.line;
this.tagColumn = this.column;
if (this.delegate.tagOpen) {
this.delegate.tagOpen();
}
};
return EventedTokenizer;
}();
var Tokenizer = function () {
function Tokenizer(entityParser, options) {
if (options === void 0) {
options = {};
}
this.options = options;
this.token = null;
this.startLine = 1;
this.startColumn = 0;
this.tokens = [];
this.currentAttribute = null;
this.tokenizer = new EventedTokenizer(this, entityParser);
}
Tokenizer.prototype.tokenize = function (input) {
this.tokens = [];
this.tokenizer.tokenize(input);
return this.tokens;
};
Tokenizer.prototype.tokenizePart = function (input) {
this.tokens = [];
this.tokenizer.tokenizePart(input);
return this.tokens;
};
Tokenizer.prototype.tokenizeEOF = function () {
this.tokens = [];
this.tokenizer.tokenizeEOF();
return this.tokens[0];
};
Tokenizer.prototype.reset = function () {
this.token = null;
this.startLine = 1;
this.startColumn = 0;
};
Tokenizer.prototype.addLocInfo = function () {
if (this.options.loc) {
this.token.loc = {
start: {
line: this.startLine,
column: this.startColumn
},
end: {
line: this.tokenizer.line,
column: this.tokenizer.column
}
};
}
this.startLine = this.tokenizer.line;
this.startColumn = this.tokenizer.column;
};
// Data
Tokenizer.prototype.beginData = function () {
this.token = {
type: 'Chars',
chars: ''
};
this.tokens.push(this.token);
};
Tokenizer.prototype.appendToData = function (char) {
this.token.chars += char;
};
Tokenizer.prototype.finishData = function () {
this.addLocInfo();
};
// Comment
Tokenizer.prototype.beginComment = function () {
this.token = {
type: 'Comment',
chars: ''
};
this.tokens.push(this.token);
};
Tokenizer.prototype.appendToCommentData = function (char) {
this.token.chars += char;
};
Tokenizer.prototype.finishComment = function () {
this.addLocInfo();
};
// Tags - basic
Tokenizer.prototype.beginStartTag = function () {
this.token = {
type: 'StartTag',
tagName: '',
attributes: [],
selfClosing: false
};
this.tokens.push(this.token);
};
Tokenizer.prototype.beginEndTag = function () {
this.token = {
type: 'EndTag',
tagName: ''
};
this.tokens.push(this.token);
};
Tokenizer.prototype.finishTag = function () {
this.addLocInfo();
};
Tokenizer.prototype.markTagAsSelfClosing = function () {
this.token.selfClosing = true;
};
// Tags - name
Tokenizer.prototype.appendToTagName = function (char) {
this.token.tagName += char;
};
// Tags - attributes
Tokenizer.prototype.beginAttribute = function () {
this.currentAttribute = ["", "", null];
this.token.attributes.push(this.currentAttribute);
};
Tokenizer.prototype.appendToAttributeName = function (char) {
this.currentAttribute[0] += char;
};
Tokenizer.prototype.beginAttributeValue = function (isQuoted) {
this.currentAttribute[2] = isQuoted;
};
Tokenizer.prototype.appendToAttributeValue = function (char) {
this.currentAttribute[1] = this.currentAttribute[1] || "";
this.currentAttribute[1] += char;
};
Tokenizer.prototype.finishAttributeValue = function () {};
Tokenizer.prototype.reportSyntaxError = function (message) {
this.token.syntaxError = message;
};
return Tokenizer;
}();
function tokenize(input, options) {
var tokenizer = new Tokenizer(new EntityParser(namedCharRefs), options);
return tokenizer.tokenize(input);
}
exports.HTML5NamedCharRefs = namedCharRefs;
exports.EntityParser = EntityParser;
exports.EventedTokenizer = EventedTokenizer;
exports.Tokenizer = Tokenizer;
exports.tokenize = tokenize;
});
}());
//# sourceMappingURL=ember-tests.prod.map